X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=battle.c;h=dd102aa8e250464188ddcaf3ad3ae46eb3e642c7;hp=1f043c61d9700a1dcbccf7ce35ac1dde23e6deec;hb=cf91699c89b88f76dcf63c60624635184e8cb7eb;hpb=48763357ef69f0b711fc332b13e2170ab914d881 diff --git a/battle.c b/battle.c index 1f043c6..dd102aa 100644 --- a/battle.c +++ b/battle.c @@ -124,6 +124,7 @@ void doshield(int i) { shield += aaitem; energy -= aaitem; return; + case NONE:; /* avoid gcc warning */ } } @@ -142,6 +143,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) { case IHC: type = 2.0; break; case IHS: type = 2.5; break; case IHT: type = 0.5; break; + case IHQUEST: type = 4.0; break; } proutn(ibumpd ? " rammed by " : " rams "); crmena(0, ienm, 2, ix, iy); @@ -152,11 +154,9 @@ void ram(int ibumpd, int ienm, int ix, int iy) { crmshp(); prout(" heavily damaged."); icas = 10.0+20.0*Rand(); - proutn("***Sickbay reports "); - crami(icas, 1); - prout(" casualties."); + prout("***Sickbay reports %d casualties", icas); casual += icas; - for (l=1; l <= ndevice; l++) { + for (l=1; l <= NDEVICES; l++) { if (l == DDRAY) continue; // Don't damage deathray if (game.damage[l] < 0) continue; extradm = (10.0*type*Rand()+1.0)*damfac; @@ -164,7 +164,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) { } shldup = 0; if (game.state.remkl) { - pause(2); + pause_game(2); dreprt(); } else finish(FWON); @@ -193,10 +193,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { iy = y + 0.5; if (iy < 1 || iy > 10) break; if (l==4 || l==9) skip(1); - cramf(x, 0, 1); - proutn(" - "); - cramf(y, 0, 1); - proutn(" "); + proutn("%d - %d ", (int)x, (int)y); iquad=game.quad[ix][iy]; if (iquad==IHDOT) continue; /* hit something */ @@ -214,7 +211,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { *hit = fabs(*hit); newcnd(); /* undock */ /* We may be displaced. */ - if (landed==1) return; /* Cheat if on a planet */ + if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */ ang = angle + 2.5*(Rand()-0.5); temp = fabs(sin(ang)); if (fabs(cos(ang)) > temp) temp = fabs(cos(ang)); @@ -284,12 +281,13 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" damaged but not destroyed."); return; } - prout(" damaged--"); + proutn(" damaged--"); game.kx[ll] = jx; game.ky[ll] = jy; shoved = 1; break; case IHB: /* Hit a base */ + skip(1); prout("***STARBASE DESTROYED.."); if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0; for (ll=1; ll<=game.state.rembase; ll++) { @@ -311,7 +309,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" destroyed."); game.state.nplankl++; game.state.newstuf[quadx][quady] -= 1; - game.state.plnets[iplnet] = nulplanet; + DESTROY(&game.state.plnets[iplnet]); iplnet = 0; plnetx = plnety = 0; game.quad[ix][iy] = IHDOT; @@ -329,16 +327,25 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" unaffected by photon blast."); return; case IHQUEST: /* Hit a thingy */ + if (Rand()>0.7) { // Used to be certain death skip(1); prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"); skip(1); prouts(" HACK! HACK! HACK! *CHOKE!* "); skip(1); proutn("Mr. Spock-"); - prouts(" \"Facinating!\""); + prouts(" \"Fascinating!\""); skip(1); - game.quad[ix][iy] = IHDOT; - return; + deadkl(ix, iy, iquad, ix, iy); + } else { + /* + * Stas Sergeev added the possibility that + * you can shove the Thingy. + */ + iqengry=1; + shoved=1; + } + return; case IHBLANK: /* Black hole */ skip(1); crmena(1, IHBLANK, 2, ix, iy); @@ -349,8 +356,6 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout("***Torpedo absorbed by Tholian web."); return; case IHT: /* Hit a Tholian */ - skip(1); - crmena(1, IHT, 2, ix, iy); h1 = 700.0 + 100.0*Rand() - 1000.0*sqrt(square(ix-inx)+square(iy-iny))* fabs(sin(bullseye-angle)); @@ -362,6 +367,8 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { ithx = ithy = 0; return; } + skip(1); + crmena(1, IHT, 2, ix, iy); if (Rand() > 0.05) { prout(" survives photon blast."); return; @@ -369,6 +376,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" disappears."); game.quad[ix][iy] = IHWEB; ithere = ithx = ithy = 0; + nenhere--; { int dum, my; dropin(IHBLANK, &dum, &my); @@ -387,9 +395,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { if (shoved) { game.quad[jx][jy]=iquad; game.quad[ix][iy]=IHDOT; - proutn(" displaced by blast to"); - cramlc(2, jx, jy); - skip(1); + prout(" displaced by blast to %s ", cramlc(sector, jx, jy)); for (ll=1; ll<=nenhere; ll++) game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll])); sortkl(); @@ -402,7 +408,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { static void fry(double hit) { double ncrit, extradm; - int ktr=1, l, ll, j, cdam[6], crptr; + int ktr=1, l, ll, j, cdam[NDEVICES+1], crptr; /* a critical hit occured */ if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return; @@ -410,9 +416,9 @@ static void fry(double hit) { ncrit = 1.0 + hit/(500.0+100.0*Rand()); proutn("***CRITICAL HIT--"); /* Select devices and cause damage */ - for (l = 1; l <= ncrit; l++) { + for (l = 1; l <= ncrit && l <= NDEVICES; l++) { do { - j = ndevice*Rand()+1.0; + j = NDEVICES*Rand()+1.0; /* Cheat to prevent shuttle damage unless on ship */ } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) || j == DDRAY); @@ -454,8 +460,8 @@ void attack(int k) { neutz = 0; return; } - if (((comhere || ishere) && (justin == 0)) || skill == 5) movcom(); - if (nenhere==0) return; + if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom(); + if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return; pfac = 1.0/inshld; if (shldchg == 1) chgfac = 0.25+0.5*Rand(); skip(1); @@ -470,10 +476,12 @@ void attack(int k) { jx = game.kx[l]; jy = game.ky[l]; iquad = game.quad[jx][jy]; + if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue; itflag = (iquad == IHK && r > 0.0005) || k == 0 || (iquad==IHC && r > 0.015) || (iquad==IHR && r > 0.3) || - (iquad==IHS && r > 0.07); + (iquad==IHS && r > 0.07) || + (iquad==IHQUEST && r > 0.05); if (itflag) { /* Enemy uses phasers */ if (condit == IHDOCKED) continue; /* Don't waste the effort! */ @@ -491,7 +499,7 @@ void attack(int k) { crmena(0, iquad, i, jx, jy); } attempt = 1; - prout("--"); + prout(" "); r = (Rand()+Rand())*0.5 -0.5; r += 0.002*game.kpower[l]*r; torpedo(course, r, jx, jy, &hit); @@ -500,9 +508,9 @@ void attack(int k) { alldone) return; /* Supernova or finished */ if (hit == 0) continue; } - if (shldup != 0 || shldchg != 0) { + if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) { /* shields will take hits */ - double absorb, hitsh, propor = pfac*shield; + double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0); if(propor < 0.1) propor = 0.1; hitsh = propor*chgfac*hit+1.0; atackd=1; @@ -517,8 +525,7 @@ void attack(int k) { shields were down for some strange reason. This doesn't make any sense, so I've fixed it */ ihurt = 1; - cramf(hit, 0, 2); - proutn(" unit hit"); + proutn("%d unit hit", (int)hit); if ((game.damage[DSRSENS] > 0 && itflag) || skill <= 2) { proutn(" on the "); crmshp(); @@ -532,7 +539,7 @@ void attack(int k) { if (hit > hitmax) hitmax = hit; hittot += hit; fry(hit); - printf("Hit %g energy %g\n", hit, energy); + prout("Hit %g energy %g", hit, energy); energy -= hit; } if (energy <= 0) { @@ -551,25 +558,18 @@ void attack(int k) { else { /* Print message if starship suffered hit(s) */ skip(1); - proutn("Energy left "); - cramf(energy, 0, 2); - proutn(" shields "); - if (shldup) proutn("up, "); - else if (game.damage[DSHIELD] == 0) proutn("down, "); + proutn("Energy left %2d shields ", (int)energy); + if (shldup) proutn("up "); + else if (game.damage[DSHIELD] == 0) proutn("down "); else proutn("damaged, "); } - crami(percent, 1); - proutn("% torpedoes left "); - crami(torps, 1); - skip(1); + prout("%d%%, torpedoes left %d", percent, torps); /* Check if anyone was hurt */ if (hitmax >= 200 || hittot >= 500) { int icas= hittot*Rand()*0.015; if (icas >= 2) { skip(1); - proutn("Mc Coy- \"Sickbay to bridge. We suffered "); - crami(icas, 1); - prout(" casualties"); + prout("Mc Coy- \"Sickbay to bridge. We suffered %d casualties", icas); prout(" in that last attack.\""); casual += icas; } @@ -599,6 +599,10 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) { /* Killed a Tholian */ ithere = 0; } + else if (type == IHQUEST) { + /* Killed a Thingy */ + iqhere=iqengry=thingx=thingy=0; + } else { /* Some type of a Klingon */ game.state.galaxy[quadx][quady] -= 100; @@ -637,10 +641,9 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) { game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom); - if (type == IHT) return; - /* Remove enemy ship from arrays describing local conditions */ - + if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC) + game.future[FCDBAS] = 1e30; for (i=1; i<=nenhere; i++) if (game.kx[i]==ix && game.ky[i]==iy) break; nenhere--; @@ -673,7 +676,7 @@ static int targetcheck(double x, double y, double *course) { skip(1); prout("Spock- \"Bridge to sickbay. Dr. McCoy,"); prout(" I recommend an immediate review of"); - prout(" the Captain's psychological profile."); + prout(" the Captain's psychological profile.\""); chew(); return 1; } @@ -705,8 +708,7 @@ void photon(void) { return; } else if (key == IHEOL) { - crami(torps,1); - prout(" torpedoes left."); + prout("%d torpedoes left.", torps); proutn("Number of torpedoes to fire- "); key = scan(); } @@ -720,6 +722,7 @@ void photon(void) { chew(); prout("Maximum of 3 torpedoes per burst."); key = IHEOL; + return; } if (n <= torps) break; chew(); @@ -758,9 +761,7 @@ void photon(void) { if (i == 1 && key == IHEOL) { /* prompt for each one */ for (i = 1; i <= n; i++) { - proutn("Target sector for torpedo number"); - crami(i, 2); - proutn("- "); + proutn("Target sector for torpedo number %d- ", i); key = scan(); if (key != IHREAL) { huh(); @@ -787,9 +788,7 @@ void photon(void) { /* misfire! */ r = (Rand()+1.2) * r; if (n>1) { - prouts("***TORPEDO NUMBER"); - crami(i, 2); - prouts(" MISFIRES."); + prouts("***TORPEDO NUMBER %d MISFIRES", i); } else prouts("***TORPEDO MISFIRES."); skip(1); @@ -805,9 +804,7 @@ void photon(void) { if (shldup != 0 || condit == IHDOCKED) r *= 1.0 + 0.0001*shield; if (n != 1) { skip(1); - proutn("Track for torpedo number"); - crami(i, 2); - proutn("- "); + proutn("Track for torpedo number %d- ", i); } else { skip(1); @@ -862,9 +859,7 @@ static int checkshctrl(double rpow) { if (icas) { skip(1); prout("McCoy to bridge- \"Severe radiation burns, Jim."); - proutn(" "); - crami(icas, 1); - prout(" casualties so far.\""); + prout(" %d casualties so far.\"", icas); casual -= icas; } skip(1); @@ -880,7 +875,7 @@ void phasers(void) { int kz = 0, k=1, i; /* Cheating inhibitor */ int ifast=0, no=0, ipoop=1, msgflag = 1; enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET; - int key; + int key=0; skip(1); /* SR sensors and Computer */ @@ -977,9 +972,7 @@ void phasers(void) { key = scan(); } if (key != IHREAL && nenhere != 0) { - proutn("Phasers locked on target. Energy available ="); - cramf(ifast?energy-200.0:energy,1,2); - skip(1); + prout("Phasers locked on target. Energy available: %.2f", ifast?energy-200.0:energy); } do { while (key != IHREAL) { @@ -989,8 +982,8 @@ void phasers(void) { } rpow = aaitem; if (rpow >= (ifast?energy-200:energy)) { - proutn("Energy available= "); - cramf(ifast?energy-200:energy, 1,2); + proutn("Energy available= %.2f", + ifast?energy-200:energy); skip(1); key = IHEOL; } @@ -1017,7 +1010,7 @@ void phasers(void) { for (i = 1; i <= nenhere; i++) { hits[i] = 0.0; if (powrem <= 0) continue; - hits[i] = fabs(game.kpower[i])/(phasefac*pow(0.90,game.kdist[i])); + hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i])); over = (0.01 + 0.05*Rand())*hits[i]; temp = powrem; powrem -= hits[i] + over; @@ -1035,8 +1028,7 @@ void phasers(void) { prout("phaser energy."); } else { - cramf(extra, 0, 2); - prout(" expended on empty space."); + prout("%d expended on empty space.", (int)extra); } } break; @@ -1061,8 +1053,8 @@ void phasers(void) { int ii = game.kx[k], jj = game.ky[k]; int ienm = game.quad[ii][jj]; if (msgflag) { - proutn("Energy available= "); - cramf(energy-.006-(ifast?200:0), 0, 2); + proutn("Energy available= %.2f", + energy-.006-(ifast?200:0)); skip(1); msgflag = 0; rpow = 0.0; @@ -1080,12 +1072,10 @@ void phasers(void) { if (key == IHEOL) { chew(); if (ipoop && k > kz) { - int irec=(fabs(game.kpower[k])/(phasefac*pow(0.9,game.kdist[k])))* + int irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))* (1.01+0.05*Rand()) + 1.0; kz = k; - proutn("("); - crami(irec, 1); - proutn(") "); + proutn("(%d)", irec); } proutn("units to fire at "); crmena(0, ienm, 2, ii, jj); @@ -1110,7 +1100,6 @@ void phasers(void) { } if (aaitem < 0) { /* abort out */ - ididit = 0; chew(); return; } @@ -1135,7 +1124,7 @@ void phasers(void) { chew(); return; } - if (key == IHALPHA & isit("no")) { + if (key == IHALPHA && isit("no")) { no = 1; } energy -= rpow; @@ -1179,18 +1168,18 @@ void hittem(double *hits) { hit = wham*pow(dustfac,game.kdist[kk]); kpini = game.kpower[kk]; kp = fabs(kpini); - if (phasefac*hit < kp) kp = phasefac*hit; + if (PHASEFAC*hit < kp) kp = PHASEFAC*hit; game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp); kpow = game.kpower[kk]; ii = game.kx[kk]; jj = game.ky[kk]; if (hit > 0.005) { - cramf(hit, 0, 2); - proutn(" unit hit on "); + proutn("%d unit hit on ", (int)hit); } else proutn("Very small hit on "); ienm = game.quad[ii][jj]; + if (ienm==IHQUEST) iqengry=1; crmena(0,ienm,2,ii,jj); skip(1); if (kpow == 0) { @@ -1202,9 +1191,8 @@ void hittem(double *hits) { else /* decide whether or not to emasculate klingon */ if (kpow > 0 && Rand() >= 0.9 && kpow <= ((0.4 + 0.4*Rand())*kpini)) { - proutn("***Mr. Spock- \"Captain, the vessel at"); - cramlc(2,ii,jj); - skip(1); + prout("***Mr. Spock- \"Captain, the vessel at ", + cramlc(sector,ii,jj)); prout(" has just lost its firepower.\""); game.kpower[kk] = -kpow; }