void DreamGenContext::autosetwalk() { al = data.byte(kManspath); if (data.byte(kFinaldest) == al) return; const RoomPaths *roomsPaths = getroomspaths(); checkdest(roomsPaths); data.word(kLinestartx) = roomsPaths->nodes[data.byte(kManspath)].x - 12; data.word(kLinestarty) = roomsPaths->nodes[data.byte(kManspath)].y - 12; data.word(kLineendx) = roomsPaths->nodes[data.byte(kDestination)].x - 12; data.word(kLineendy) = roomsPaths->nodes[data.byte(kDestination)].y - 12; bresenhams(); if (data.byte(kLinedirection) != 0) { data.byte(kLinepointer) = data.byte(kLinelength) - 1; data.byte(kLinedirection) = 1; return; } data.byte(kLinepointer) = 0; }
void scom(int *ipage) { int i, i2, j, ideltax, ideltay, ibqx, ibqy, sx, sy, ifindit, iwhichb; int iqx, iqy; int basetbl[6]; double bdist[6]; int flag; #ifdef DEBUG if (idebug) prout("SCOM"); #endif /* Decide on being active or passive */ flag = ((d.killc+d.killk)/(d.date+0.01-indate) < 0.1*skill*(skill+1.0) || (d.date-indate) < 3.0); if (iscate==0 && flag) { /* compute move away from Enterprise */ ideltax = d.isx-quadx; ideltay = d.isy-quady; if (sqrt(ideltax*(double)ideltax+ideltay*(double)ideltay) > 2.0) { /* circulate in space */ ideltax = d.isy-quady; ideltay = quadx-d.isx; } } else { /* compute distances to starbases */ if (d.rembase <= 0) { /* nothing left to do */ future[FSCMOVE] = 1e30; return; } sx = d.isx; sy = d.isy; for (i = 1; i <= d.rembase; i++) { basetbl[i] = i; ibqx = d.baseqx[i]; ibqy = d.baseqy[i]; bdist[i] = sqrt(square(ibqx-sx) + square(ibqy-sy)); } if (d.rembase > 1) { /* sort into nearest first order */ int iswitch; do { iswitch = 0; for (i=1; i < d.rembase-1; i++) { if (bdist[i] > bdist[i+1]) { int ti = basetbl[i]; double t = bdist[i]; bdist[i] = bdist[i+1]; bdist[i+1] = t; basetbl[i] = basetbl[i+1]; basetbl[i+1] =ti; iswitch = 1; } } } while (iswitch); } /* look for nearest base without a commander, no Enterprise, and without too many Klingons, and not already under attack. */ ifindit = iwhichb = 0; for (i2 = 1; i2 <= d.rembase; i2++) { i = basetbl[i2]; /* bug in original had it not finding nearest*/ ibqx = d.baseqx[i]; ibqy = d.baseqy[i]; if ((ibqx == quadx && ibqy == quady) || (ibqx == batx && ibqy == baty) || d.galaxy[ibqx][ibqy] > 899) continue; /* if there is a commander, an no other base is appropriate, we will take the one with the commander */ for (j = 1; j <= d.remcom; j++) { if (ibqx==d.cx[j] && ibqy==d.cy[j] && ifindit!= 2) { ifindit = 2; iwhichb = i; break; } } if (j > d.remcom) { /* no commander -- use this one */ ifindit = 1; iwhichb = i; break; } } if (ifindit==0) return; /* Nothing suitable -- wait until next time*/ ibqx = d.baseqx[iwhichb]; ibqy = d.baseqy[iwhichb]; /* decide how to move toward base */ ideltax = ibqx - d.isx; ideltay = ibqy - d.isy; } /* Maximum movement is 1 quadrant in either or both axis */ if (ideltax > 1) ideltax = 1; if (ideltax < -1) ideltax = -1; if (ideltay > 1) ideltay = 1; if (ideltay < -1) ideltay = -1; /* try moving in both x and y directions */ iqx = d.isx + ideltax; iqy = d.isy + ideltax; if (checkdest(iqx, iqy, flag, ipage)) { /* failed -- try some other maneuvers */ if (ideltax==0 || ideltay==0) { /* attempt angle move */ if (ideltax != 0) { iqy = d.isy + 1; if (checkdest(iqx, iqy, flag, ipage)) { iqy = d.isy - 1; checkdest(iqx, iqy, flag, ipage); } } else { iqx = d.isx + 1; if (checkdest(iqx, iqy, flag, ipage)) { iqx = d.isx - 1; checkdest(iqx, iqy, flag, ipage); } } } else { /* try moving just in x or y */ iqy = d.isy; if (checkdest(iqx, iqy, flag, ipage)) { iqy = d.isy + ideltay; iqx = d.isx; checkdest(iqx, iqy, flag, ipage); } } } /* check for a base */ if (d.rembase == 0) { future[FSCMOVE] = 1e30; } else for (i=1; i<=d.rembase; i++) { ibqx = d.baseqx[i]; ibqy = d.baseqy[i]; if (ibqx==d.isx && ibqy == d.isy && d.isx != batx && d.isy != baty) { /* attack the base */ if (flag) return; /* no, don't attack base! */ iseenit = 0; isatb=1; future[FSCDBAS] = d.date + 1.0 +2.0*Rand(); if (batx != 0) future[FSCDBAS] += future[FCDBAS]-d.date; if (damage[DRADIO] > 0 && condit != IHDOCKED) return; /* no warning */ iseenit = 1; if (*ipage == 0) pause(1); *ipage=1; proutn("Lt. Uhura- \"Captain, the starbase in"); cramlc(1, d.isx, d.isy); skip(1); prout(" reports that it is under attack from the Klingon Super-commander."); proutn(" It can survive until stardate "); cramf(future[FSCDBAS], 0, 1); prout(" .\""); if (resting==0) return; prout("Mr. Spock- \"Captain, shall we cancel the rest period?\""); if (ja()==0) return; resting = 0; Time = 0.0; /* actually finished */ return; } } /* Check for intelligence report */ if ( #ifdef DEBUG idebug==0 && #endif (Rand() > 0.2 || (damage[DRADIO] > 0.0 && condit != IHDOCKED) || starch[d.isx][d.isy] > 0)) return; if (*ipage==0) pause(1); *ipage = 1; prout("Lt. Uhura- \"Captain, Starfleet Intelligence reports"); proutn(" the Super-commander is in"); cramlc(1, d.isx, d.isy); prout(".\""); return; }