From: Eric S. Raymond Date: Thu, 28 Sep 2006 08:01:45 +0000 (+0000) Subject: Clean up nasty FORTRAN-style if statements. X-Git-Tag: 2.0~192 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=9ae916e9144e84ef1de4a86ea73a45a2bc4cc1be;p=super-star-trek.git Clean up nasty FORTRAN-style if statements. E.g., with the body on the same line as the guard. They're bad style and make the code hard to read, and I got fed up, --- diff --git a/src/ai.c b/src/ai.c index 80465ba..99024df 100644 --- a/src/ai.c +++ b/src/ai.c @@ -17,12 +17,15 @@ static bool tryexit(coord look, int ienm, int loccom, bool irun) /* avoid intruding on another commander's territory */ if (ienm == IHC) { for_commanders(n) - if (same(game.state.kcmdr[n],iq)) return false; + if (same(game.state.kcmdr[n],iq)) + return false; /* refuse to leave if currently attacking starbase */ - if (same(game.battle, game.quadrant)) return false; + if (same(game.battle, game.quadrant)) + return false; } /* don't leave if over 1000 units of energy */ - if (game.kpower[loccom] > 1000.) return false; + if (game.kpower[loccom] > 1000.0) + return false; } /* print escape message and move out of quadrant. We know this if either short or long range sensors are working */ @@ -40,7 +43,8 @@ static bool tryexit(coord look, int ienm, int loccom, bool irun) game.kdist[loccom] = game.kdist[game.nenhere]; game.klhere--; game.nenhere--; - if (game.condition != docked) newcnd(); + if (game.condition != docked) + newcnd(); /* Handle global matters related to escape */ game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--; game.state.galaxy[iq.x][iq.y].klingons++; @@ -157,9 +161,11 @@ static void movebaddy(coord com, int loccom, feature ienm) if (idebug) proutn("=== MOTION = %d, FORCES = %1.2f, ", motion, forces); /* don't move if no motion */ - if (motion==0) return; + if (motion==0) + return; /* Limit motion according to skill */ - if (abs(motion) > game.skill) motion = (motion < 0) ? -game.skill : game.skill; + if (abs(motion) > game.skill) + motion = (motion < 0) ? -game.skill : game.skill; } /* calculate preferred number of steps */ nsteps = motion < 0 ? -motion : motion; @@ -172,10 +178,14 @@ static void movebaddy(coord com, int loccom, feature ienm) /* Compute preferred values of delta X and Y */ mx = game.sector.x - com.x; my = game.sector.y - com.y; - if (2.0 * abs(mx) < abs(my)) mx = 0; - if (2.0 * abs(my) < abs(game.sector.x-com.x)) my = 0; - if (mx != 0) mx = mx*motion < 0 ? -1 : 1; - if (my != 0) my = my*motion < 0 ? -1 : 1; + if (2.0 * abs(mx) < abs(my)) + mx = 0; + if (2.0 * abs(my) < abs(game.sector.x-com.x)) + my = 0; + if (mx != 0) + mx = mx*motion < 0 ? -1 : 1; + if (my != 0) + my = my*motion < 0 ? -1 : 1; next = com; /* main move loop */ for (ll = 0; ll < nsteps; ll++) { @@ -192,14 +202,16 @@ static void movebaddy(coord com, int loccom, feature ienm) if (look.x < 1 || look.x > QUADSIZE) { if (motion < 0 && tryexit(look, ienm, loccom, irun)) return; - if (krawlx == mx || my == 0) break; + if (krawlx == mx || my == 0) + break; look.x = next.x + krawlx; krawlx = -krawlx; } else if (look.y < 1 || look.y > QUADSIZE) { if (motion < 0 && tryexit(look, ienm, loccom, irun)) return; - if (krawly == my || mx == 0) break; + if (krawly == my || mx == 0) + break; look.y = next.y + krawly; krawly = -krawly; } @@ -218,16 +230,19 @@ static void movebaddy(coord com, int loccom, feature ienm) look.y = next.y + krawly; krawly = -krawly; } - else break; /* we have failed */ + else + break; /* we have failed */ } - else success = true; + else + success = true; } if (success) { next = look; if (idebug) proutn(cramlc(neither, next)); } - else break; /* done early */ + else + break; /* done early */ } if (idebug) @@ -243,8 +258,10 @@ static void movebaddy(coord com, int loccom, feature ienm) proutn("***"); cramen(ienm); proutn(_(" from %s"), cramlc(2, com)); - if (game.kdist[loccom] < dist1) proutn(_(" advances to ")); - else proutn(_(" retreats to ")); + if (game.kdist[loccom] < dist1) + proutn(_(" advances to ")); + else + proutn(_(" retreats to ")); prout(cramlc(sector, next)); } } @@ -256,7 +273,8 @@ void movcom(void) coord w; int i; - if (idebug) prout("== MOVCOM"); + if (idebug) + prout("== MOVCOM"); /* Figure out which Klingon is the commander (or Supercommander) and do move */ @@ -304,7 +322,8 @@ static bool movescom(coord iq, bool flag, bool *ipage) if (same(game.state.baseq[i], iq)) return true; } - if (game.justin && !game.iscate) return true; + if (game.justin && !game.iscate) + return true; /* do the move */ game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].klingons--; game.state.kscmdr = iq; @@ -317,7 +336,8 @@ static bool movescom(coord iq, bool flag, bool *ipage) game.ientesc = false; unschedule(FSCDBAS); for_local_enemies(i) - if (game.quad[game.ks[i].x][game.ks[i].y] == IHS) break; + if (game.quad[game.ks[i].x][game.ks[i].y] == IHS) + break; game.quad[game.ks[i].x][game.ks[i].y] = IHDOT; game.ks[i] = game.ks[game.nenhere]; game.kdist[i] = game.kdist[game.nenhere]; @@ -325,7 +345,8 @@ static bool movescom(coord iq, bool flag, bool *ipage) game.kpower[i] = game.kpower[game.nenhere]; game.klhere--; game.nenhere--; - if (game.condition!=docked) newcnd(); + if (game.condition!=docked) + newcnd(); sortkl(); } /* check for a helpful planet */ @@ -336,7 +357,8 @@ static bool movescom(coord iq, bool flag, bool *ipage) DESTROY(&game.state.plnets[i]); game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].planet = NOPLANET; if (!damaged(DRADIO) || game.condition == docked) { - if (!*ipage) pause_game(true); + if (!*ipage) + pause_game(true); *ipage = true; prout(_("Lt. Uhura- \"Captain, Starfleet Intelligence reports")); proutn(_(" a planet in ")); @@ -359,7 +381,8 @@ void scom(bool *ipage) double bdist[BASEMAX+1]; bool flag; - if (idebug) prout("== SCOM"); + if (idebug) + prout("== SCOM"); /* Decide on being active or passive */ flag = ((NKILLC+NKILLK)/(game.state.date+0.01-game.indate) < 0.1*game.skill*(game.skill+1.0) || @@ -437,10 +460,14 @@ void scom(bool *ipage) ideltay = ibq.y - game.state.kscmdr.y; } /* 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; + 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 */ iq.x = game.state.kscmdr.x + ideltax; @@ -491,7 +518,8 @@ void scom(bool *ipage) if (damaged(DRADIO) && game.condition != docked) return; /* no warning */ game.iseenit = true; - if (!*ipage) pause_game(true); + if (!*ipage) + pause_game(true); *ipage = true; proutn(_("Lt. Uhura- \"Captain, the starbase in ")); proutn(cramlc(quadrant, game.state.kscmdr)); @@ -499,9 +527,11 @@ void scom(bool *ipage) prout(_(" reports that it is under attack from the Klingon Super-commander.")); proutn(_(" It can survive until stardate %d.\""), (int)scheduled(FSCDBAS)); - if (!game.resting) return; + if (!game.resting) + return; prout(_("Mr. Spock- \"Captain, shall we cancel the rest period?\"")); - if (ja() == false) return; + if (ja() == false) + return; game.resting = false; game.optime = 0.0; /* actually finished */ return; @@ -514,7 +544,8 @@ void scom(bool *ipage) (damaged(DRADIO) && game.condition != docked) || !game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].charted)) return; - if (!*ipage) pause_game(true); + if (!*ipage) + pause_game(true); *ipage = true; prout(_("Lt. Uhura- \"Captain, Starfleet Intelligence reports")); proutn(_(" the Super-commander is in ")); @@ -528,7 +559,8 @@ void movetho(void) { int idx, idy, im, i; /* Move the Tholian */ - if (!game.ithere || game.justin) return; + if (!game.ithere || game.justin) + return; if (game.tholian.x == 1 && game.tholian.y == 1) { idx = 1; idy = QUADSIZE; @@ -549,7 +581,8 @@ void movetho(void) } /* Do nothing if we are blocked */ - if (game.quad[idx][idy]!= IHDOT && game.quad[idx][idy]!= IHWEB) return; + if (game.quad[idx][idy]!= IHDOT && game.quad[idx][idy]!= IHWEB) + return; game.quad[game.tholian.x][game.tholian.y] = IHWEB; if (game.tholian.x != idx) { @@ -557,7 +590,8 @@ void movetho(void) im = fabs((double)idx - game.tholian.x)/((double)idx - game.tholian.x); while (game.tholian.x != idx) { game.tholian.x += im; - if (game.quad[game.tholian.x][game.tholian.y]==IHDOT) game.quad[game.tholian.x][game.tholian.y] = IHWEB; + if (game.quad[game.tholian.x][game.tholian.y]==IHDOT) + game.quad[game.tholian.x][game.tholian.y] = IHWEB; } } else if (game.tholian.y != idy) { @@ -565,7 +599,8 @@ void movetho(void) im = fabs((double)idy - game.tholian.y)/((double)idy - game.tholian.y); while (game.tholian.y != idy) { game.tholian.y += im; - if (game.quad[game.tholian.x][game.tholian.y]==IHDOT) game.quad[game.tholian.x][game.tholian.y] = IHWEB; + if (game.quad[game.tholian.x][game.tholian.y]==IHDOT) + game.quad[game.tholian.x][game.tholian.y] = IHWEB; } } game.quad[game.tholian.x][game.tholian.y] = IHT; @@ -573,10 +608,14 @@ void movetho(void) /* check to see if all holes plugged */ for_sectors(i) { - if (game.quad[1][i]!=IHWEB && game.quad[1][i]!=IHT) return; - if (game.quad[QUADSIZE][i]!=IHWEB && game.quad[QUADSIZE][i]!=IHT) return; - if (game.quad[i][1]!=IHWEB && game.quad[i][1]!=IHT) return; - if (game.quad[i][QUADSIZE]!=IHWEB && game.quad[i][QUADSIZE]!=IHT) return; + if (game.quad[1][i]!=IHWEB && game.quad[1][i]!=IHT) + return; + if (game.quad[QUADSIZE][i]!=IHWEB && game.quad[QUADSIZE][i]!=IHT) + return; + if (game.quad[i][1]!=IHWEB && game.quad[i][1]!=IHT) + return; + if (game.quad[i][QUADSIZE]!=IHWEB && game.quad[i][QUADSIZE]!=IHT) + return; } /* All plugged up -- Tholian splits */ game.quad[game.tholian.x][game.tholian.y]=IHWEB; diff --git a/src/battle.c b/src/battle.c index 76bbe0c..387bfa9 100644 --- a/src/battle.c +++ b/src/battle.c @@ -39,7 +39,8 @@ void doshield(bool raise) } else if (game.shldup) { proutn(_("Shields are up. Do you want them down? ")); - if (ja() == true) action = SHDN; + if (ja() == true) + action = SHDN; else { chew(); return; @@ -47,7 +48,8 @@ void doshield(bool raise) } else { proutn(_("Shields are down. Do you want them up? ")); - if (ja() == true) action = SHUP; + if (ja() == true) + action = SHUP; else { chew(); return; @@ -63,7 +65,8 @@ void doshield(bool raise) } game.shldup = true; game.shldchg = true; - if (game.condition != docked) game.energy -= 50.0; + if (game.condition != docked) + game.energy -= 50.0; prout(_("Shields raised.")); if (game.energy <= 0) { skip(1); @@ -89,7 +92,8 @@ void doshield(bool raise) proutn(_("Energy to transfer to shields- ")); } chew(); - if (aaitem==0) return; + if (aaitem==0) + return; if (aaitem > game.energy) { prout(_("Insufficient ship energy.")); return; @@ -208,7 +212,8 @@ void ram(bool ibumpd, feature ienm, coord w) } proutn(ibumpd ? _(" rammed by ") : _(" rams ")); crmena(false, ienm, sector, w); - if (ibumpd) proutn(_(" (original position)")); + if (ibumpd) + proutn(_(" (original position)")); skip(1); deadkl(w, ienm, game.sector); proutn("***"); @@ -238,7 +243,8 @@ void ram(bool ibumpd, feature ienm, coord w) pause_game(true); dreprt(); } - else finish(FWON); + else + finish(FWON); return; } @@ -257,7 +263,8 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) w.x = w.y = jw.x = jw.y = 0; bigger = fabs(deltax); - if (fabs(deltay) > bigger) bigger = fabs(deltay); + if (fabs(deltay) > bigger) + bigger = fabs(deltay); deltax /= bigger; deltay /= bigger; if (!damaged(DSRSENS) || game.condition==docked) @@ -270,10 +277,12 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) w.x = x + 0.5; y += deltay; w.y = y + 0.5; - if (!VALID_SECTOR(w.x, w.y)) break; + if (!VALID_SECTOR(w.x, w.y)) + break; iquad=game.quad[w.x][w.y]; tracktorpedo(w, l, i, n, iquad); - if (iquad==IHDOT) continue; + if (iquad==IHDOT) + continue; /* hit something */ setwnd(message_window); if (damaged(DSRSENS) && !game.condition==docked) @@ -294,12 +303,14 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) 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)); + if (fabs(cos(ang)) > temp) + temp = fabs(cos(ang)); xx = -sin(ang)/temp; yy = cos(ang)/temp; jw.x=w.x+xx+0.5; jw.y=w.y+yy+0.5; - if (!VALID_SECTOR(jw.x, jw.y)) return; + if (!VALID_SECTOR(jw.x, jw.y)) + return; if (game.quad[jw.x][jw.y]==IHBLANK) { finish(FHOLE); return; @@ -331,7 +342,8 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) h1 = 700.0 + 100.0*Rand() - 1000.0 * distance(w, in) * fabs(sin(bullseye-angle)); h1 = fabs(h1); - if (kp < h1) h1 = kp; + if (kp < h1) + h1 = kp; game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1); if (game.kpower[ll] == 0) { deadkl(w, iquad, w); @@ -341,7 +353,8 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) /* If enemy damaged but not destroyed, try to displace */ ang = angle + 2.5*(Rand()-0.5); temp = fabs(sin(ang)); - if (fabs(cos(ang)) > temp) temp = fabs(cos(ang)); + if (fabs(cos(ang)) > temp) + temp = fabs(cos(ang)); xx = -sin(ang)/temp; yy = cos(ang)/temp; jw.x=w.x+xx+0.5; @@ -505,7 +518,8 @@ static void fry(double hit) int ktr=1, loop1, loop2, j, cdam[NDEVICES]; /* a critical hit occured */ - if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return; + if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) + return; ncrit = 1.0 + hit/(500.0+100.0*Rand()); proutn(_("***CRITICAL HIT--")); @@ -521,7 +535,8 @@ static void fry(double hit) game.damage[j] += extradm; if (loop1 > 0) { for (loop2 = 0; loop2 < loop1 && j != cdam[loop2]; loop2++) ; - if (loop2 < loop1) continue; + if (loop2 < loop1) + continue; ktr += 1; if (ktr==3) skip(1); proutn(_(" and ")); @@ -572,7 +587,8 @@ void attack(bool torps_ok) /* set up partial hits if attack happens during shield status change */ pfac = 1.0/game.inshld; - if (game.shldchg) chgfac = 0.25+0.5*Rand(); + if (game.shldchg) + chgfac = 0.25+0.5*Rand(); skip(1); @@ -585,11 +601,14 @@ void attack(bool torps_ok) /* compute hit strength and diminish shield power */ r = Rand(); /* Increase chance of photon torpedos if docked or enemy energy low */ - if (game.condition == docked) r *= 0.25; - if (game.kpower[loop] < 500) r *= 0.25; + if (game.condition == docked) + r *= 0.25; + if (game.kpower[loop] < 500) + r *= 0.25; jay = game.ks[loop]; iquad = game.quad[jay.x][jay.y]; - if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue; + if (iquad==IHT || (iquad==IHQUEST && !iqengry)) + continue; /* different enemies have different probabilities of throwing a torp */ usephasers = !torps_ok || \ (iquad == IHK && r > 0.0005) || @@ -621,16 +640,19 @@ void attack(bool torps_ok) finish(FWON); /* Klingons did themselves in! */ if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone) return; /* Supernova or finished */ - if (hit == 0) continue; + if (hit == 0) + continue; } /* incoming phaser or torpedo, shields may dissipate it */ if (game.shldup || game.shldchg || game.condition==docked) { /* shields will take hits */ double absorb, hitsh, propor = pfac*game.shield*(game.condition==docked ? 2.1 : 1.0); - if (propor < 0.1) propor = 0.1; + if (propor < 0.1) + propor = 0.1; hitsh = propor*chgfac*hit+1.0; absorb = 0.8*hitsh; - if (absorb > game.shield) absorb = game.shield; + if (absorb > game.shield) + absorb = game.shield; game.shield -= absorb; hit -= hitsh; /* taking a hit blasts us out of a starbase dock */ @@ -653,7 +675,8 @@ void attack(bool torps_ok) } skip(1); /* Decide if hit is critical */ - if (hit > hitmax) hitmax = hit; + if (hit > hitmax) + hitmax = hit; hittot += hit; fry(hit); game.energy -= hit; @@ -665,7 +688,8 @@ void attack(bool torps_ok) } if (!attempt && game.condition == docked) prout(_("***Enemies decide against attacking your ship.")); - if (!atackd) return; + if (!atackd) + return; percent = 100.0*pfac*game.shield+0.5; if (!ihurt) { /* Shields fully protect ship */ @@ -675,9 +699,12 @@ void attack(bool torps_ok) /* Print message if starship suffered hit(s) */ skip(1); proutn(_("Energy left %2d shields "), (int)game.energy); - if (game.shldup) proutn(_("up ")); - else if (!damaged(DSHIELD)) proutn(_("down ")); - else proutn(_("damaged, ")); + if (game.shldup) + proutn(_("up ")); + else if (!damaged(DSHIELD)) + proutn(_("down ")); + else + proutn(_("damaged, ")); } prout(_("%d%%, torpedoes left %d"), percent, game.torps); /* Check if anyone was hurt */ @@ -759,7 +786,8 @@ void deadkl(coord w, feature type, coord mv) /* For each kind of enemy, finish message to player */ prout(_(" destroyed.")); game.quad[w.x][w.y] = IHDOT; - if (KLINGREM==0) return; + if (KLINGREM==0) + return; game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom); @@ -767,7 +795,8 @@ void deadkl(coord w, feature type, coord mv) if (is_scheduled(FCDBAS) && same(game.battle, game.quadrant) && type==IHC) unschedule(FCDBAS); for_local_enemies(i) - if (same(game.ks[i], w)) break; + if (same(game.ks[i], w)) + break; game.nenhere--; if (i <= game.nenhere) { for (j=i; j<=game.nenhere; j++) { @@ -848,7 +877,8 @@ void photon(void) key = IHEOL; return; } - if (n <= game.torps) break; + if (n <= game.torps) + break; chew(); key = IHEOL; } @@ -879,7 +909,8 @@ void photon(void) return; } targ[i][2] = aaitem; - if (targetcheck(targ[i][1], targ[i][2], &course[i])) return; + if (targetcheck(targ[i][1], targ[i][2], &course[i])) + return; } chew(); if (i == 1 && key == IHEOL) { @@ -899,13 +930,15 @@ void photon(void) } targ[i][2] = aaitem; chew(); - if (targetcheck(targ[i][1], targ[i][2], &course[i])) return; + if (targetcheck(targ[i][1], targ[i][2], &course[i])) + return; } } game.ididit = true; /* Loop for moving torpedoes */ for (i = 1; i <= n; i++) { - if (game.condition != docked) game.torps--; + if (game.condition != docked) + game.torps--; r = (Rand()+Rand())*0.5 -0.5; if (fabs(r) >= 0.47) { /* misfire! */ @@ -913,7 +946,8 @@ void photon(void) if (n>1) { prouts(_("***TORPEDO NUMBER %d MISFIRES"), i); } - else prouts(_("***TORPEDO MISFIRES.")); + else + prouts(_("***TORPEDO MISFIRES.")); skip(1); if (i < n) prout(_(" Remainder of burst aborted.")); @@ -929,7 +963,8 @@ void photon(void) if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) return; } - if (KLINGREM==0) finish(FWON); + if (KLINGREM==0) + finish(FWON); } @@ -1108,7 +1143,8 @@ void phasers(void) chew(); proutn(_("Units to fire= ")); key = scan(); - if (key!=IHREAL) return; + if (key!=IHREAL) + return; rpow = aaitem; if (rpow > (ifast?game.energy-200:game.energy)) { proutn(_("Energy available= %.2f"), @@ -1127,7 +1163,8 @@ void phasers(void) } if (ifast) { game.energy -= 200; /* Go and do it! */ - if (checkshctrl(rpow)) return; + if (checkshctrl(rpow)) + return; } chew(); game.energy -= rpow; @@ -1137,23 +1174,28 @@ void phasers(void) powrem = rpow; for_local_enemies(i) { hits[i] = 0.0; - if (powrem <= 0) continue; + if (powrem <= 0) + continue; 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; - if (powrem <= 0 && temp < hits[i]) hits[i] = temp; - if (powrem <= 0) over = 0.0; + if (powrem <= 0 && temp < hits[i]) + hits[i] = temp; + if (powrem <= 0) + over = 0.0; extra += over; } - if (powrem > 0.0) extra += powrem; + if (powrem > 0.0) + extra += powrem; hittem(hits); game.ididit = true; } if (extra > 0 && !game.alldone) { if (game.ithere) { proutn(_("*** Tholian web absorbs ")); - if (game.nenhere>0) proutn(_("excess ")); + if (game.nenhere>0) + proutn(_("excess ")); prout(_("phaser energy.")); } else { @@ -1205,8 +1247,10 @@ void phasers(void) (1.01+0.05*Rand()) + 1.0; kz = k; proutn("("); - if (!damaged(DCOMPTR)) proutn("%d", irec); - else proutn("??"); + if (!damaged(DCOMPTR)) + proutn("%d", irec); + else + proutn("??"); proutn(") "); proutn(_("units to fire at ")); crmena(false, ienm, sector, aim); @@ -1257,7 +1301,8 @@ void phasers(void) chew(); if (ifast) { game.energy -= 200.0; - if (checkshctrl(rpow)) return; + if (checkshctrl(rpow)) + return; } hittem(hits); game.ididit = true; @@ -1294,12 +1339,14 @@ void hittem(double *hits) skip(1); for (; k <= nenhr2; k++, kk++) { - if ((wham = hits[k])==0) continue; + if ((wham = hits[k])==0) + continue; dustfac = 0.9 + 0.01*Rand(); 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]; w = game.ks[kk]; @@ -1311,13 +1358,16 @@ void hittem(double *hits) else proutn(_("Very small hit on ")); ienm = game.quad[w.x][w.y]; - if (ienm==IHQUEST) iqengry = true; + if (ienm==IHQUEST) + iqengry = true; crmena(false,ienm,sector,w); skip(1); if (kpow == 0) { deadkl(w, ienm, w); - if (KLINGREM==0) finish(FWON); - if (game.alldone) return; + if (KLINGREM==0) + finish(FWON); + if (game.alldone) + return; kk--; /* don't do the increment */ } else /* decide whether or not to emasculate klingon */ diff --git a/src/events.c b/src/events.c index b934b8d..3a93a84 100644 --- a/src/events.c +++ b/src/events.c @@ -97,7 +97,8 @@ void events(void) for (;;) { /* Select earliest extraneous event, evcode==0 if no events */ evcode = FSPY; - if (game.alldone) return; + if (game.alldone) + return; datemin = fintim; for (l = 1; l < NEVENTS; l++) if (game.future[l].date < datemin) { @@ -127,11 +128,13 @@ void events(void) return; } game.lsupres -= xtime; - if (game.damage[DLIFSUP] <= xtime) game.lsupres = game.inlsr; + if (game.damage[DLIFSUP] <= xtime) + game.lsupres = game.inlsr; } /* Fix devices */ repair = xtime; - if (game.condition == docked) repair /= game.docfac; + if (game.condition == docked) + repair /= game.docfac; /* Don't fix Deathray here */ for (l=0; l 0.0 && l != DDRAY) @@ -153,11 +156,13 @@ void events(void) game.optime -= xtime; switch (evcode) { case FSNOVA: /* Supernova */ - if (!ipage) pause_game(true); + if (!ipage) + pause_game(true); ipage=true; snova(false, NULL); schedule(FSNOVA, expran(0.5*game.intime)); - if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) return; + if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) + return; break; case FSPY: /* Check with spy to see if S.C. should tractor beam */ if (game.state.nscrem == 0 || @@ -174,7 +179,8 @@ void events(void) yank = distance(game.state.kscmdr, game.quadrant); /********* fall through to FTBEAM code ***********/ } - else return; + else + return; case FTBEAM: /* Tractor beam */ if (evcode==FTBEAM) { if (game.state.remcom == 0) { @@ -192,7 +198,8 @@ void events(void) } /* tractor beaming cases merge here */ yank = sqrt(yank); - if (!ipage) pause_game(true); + if (!ipage) + pause_game(true); ipage=true; game.optime = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */ ictbeam = true; @@ -202,7 +209,8 @@ void events(void) prout(_(" caught in long range tractor beam--")); /* If Kirk & Co. screwing around on planet, handle */ atover(true); /* atover(true) is Grab */ - if (game.alldone) return; + if (game.alldone) + return; if (game.icraft) { /* Caught in Galileo? */ finish(FSTRACTOR); return; @@ -239,14 +247,17 @@ void events(void) doshield(true); /* raise shields */ game.shldchg=false; } - else prout(_("(Shields not currently useable.)")); + else + prout(_("(Shields not currently useable.)")); } newqad(false); /* Adjust finish time to time of tractor beaming */ fintim = game.state.date+game.optime; attack(false); - if (game.state.remcom <= 0) unschedule(FTBEAM); - else schedule(FTBEAM, game.optime+expran(1.5*game.intime/game.state.remcom)); + if (game.state.remcom <= 0) + unschedule(FTBEAM); + else + schedule(FTBEAM, game.optime+expran(1.5*game.intime/game.state.remcom)); break; case FSNAP: /* Snapshot of the universe (for time warp) */ game.snapsht = game.state; @@ -269,7 +280,8 @@ void events(void) i = 1; break; } - if (i == 1) break; + if (i == 1) + break; } if (j>game.state.rembase) { /* no match found -- try later */ @@ -287,7 +299,8 @@ void events(void) if (!damaged(DRADIO) && game.condition != docked) break; /* No warning :-( */ game.iseenit = true; - if (!ipage) pause_game(true); + if (!ipage) + pause_game(true); ipage = true; skip(1); proutn(_("Lt. Uhura- \"Captain, the starbase in ")); @@ -335,7 +348,8 @@ void events(void) else if (game.state.rembase != 1 && (!damaged(DRADIO) || game.condition == docked)) { /* Get word via subspace radio */ - if (!ipage) pause_game(true); + if (!ipage) + pause_game(true); ipage = true; skip(1); prout(_("Lt. Uhura- \"Captain, Starfleet Command reports that")); @@ -344,7 +358,8 @@ void events(void) prout(_(" has been destroyed by")); if (game.isatb == 2) prout(_("the Klingon Super-Commander")); - else prout(_("a Klingon Commander")); + else + prout(_("a Klingon Commander")); game.state.chart[game.battle.x][game.battle.y].starbase = false; } /* Remove Starbase from galaxy */ @@ -380,7 +395,8 @@ void events(void) game.state.galaxy[game.probec.x][game.probec.y].supernova) { // Left galaxy or ran into supernova if (!damaged(DRADIO) || game.condition == docked) { - if (!ipage) pause_game(true); + if (!ipage) + pause_game(true); ipage = true; skip(1); proutn(_("Lt. Uhura- \"The deep space probe ")); @@ -394,7 +410,8 @@ void events(void) break; } if (!damaged(DRADIO) || game.condition == docked) { - if (!ipage) pause_game(true); + if (!ipage) + pause_game(true); ipage = true; skip(1); proutn(_("Lt. Uhura- \"The deep space probe is now in ")); @@ -553,7 +570,8 @@ void wait(void) game.ididit = false; for (;;) { key = scan(); - if (key != IHEOL) break; + if (key != IHEOL) + break; proutn(_("How long? ")); } chew(); @@ -562,17 +580,20 @@ void wait(void) return; } origTime = delay = aaitem; - if (delay <= 0.0) return; + if (delay <= 0.0) + return; if (delay >= game.state.remtime || game.nenhere != 0) { proutn(_("Are you sure? ")); - if (ja() == false) return; + if (ja() == false) + return; } /* Alternate resting periods (events) with attacks */ game.resting = true; do { - if (delay <= 0) game.resting = false; + if (delay <= 0) + game.resting = false; if (!game.resting) { prout(_("%d stardates left."), (int)game.state.remtime); return; @@ -581,14 +602,18 @@ void wait(void) if (game.nenhere) { double rtime = 1.0 + Rand(); - if (rtime < temp) temp = rtime; + if (rtime < temp) + temp = rtime; game.optime = temp; } - if (game.optime < delay) attack(false); - if (game.alldone) return; + if (game.optime < delay) + attack(false); + if (game.alldone) + return; events(); game.ididit = true; - if (game.alldone) return; + if (game.alldone) + return; delay -= temp; /* Repair Deathray if long rest at starbase */ if (origTime-delay >= 9.99 && game.condition == docked) @@ -641,10 +666,12 @@ void nova(coord nov) for (mm = bot; mm <= top; mm++) for (nn = 1; nn <= 3; nn++) /* nn,j represents coordinates around current */ for (j = 1; j <= 3; j++) { - if (j==2 && nn== 2) continue; + if (j==2 && nn== 2) + continue; scratch.x = hits[mm][1]+nn-2; scratch.y = hits[mm][2]+j-2; - if (!VALID_SECTOR(scratch.y, scratch.x)) continue; + if (!VALID_SECTOR(scratch.y, scratch.x)) + continue; iquad = game.quad[scratch.x][scratch.y]; switch (iquad) { // case IHDOT: /* Empty space ends reaction @@ -701,7 +728,8 @@ void nova(coord nov) case IHF: prout(_("***Starship buffeted by nova.")); if (game.shldup) { - if (game.shield >= 2000.0) game.shield -= 2000.0; + if (game.shield >= 2000.0) + game.shield -= 2000.0; else { double diff = 2000.0 - game.shield; game.energy -= diff; @@ -711,7 +739,8 @@ void nova(coord nov) game.damage[DSHIELD] += 0.005*game.damfac*Rand()*diff; } } - else game.energy -= 2000.0; + else + game.energy -= 2000.0; if (game.energy <= 0) { finish(FNOVA); return; @@ -728,7 +757,8 @@ void nova(coord nov) case IHS: case IHR: for_local_enemies(ll) - if (same(game.ks[ll], scratch)) break; + if (same(game.ks[ll], scratch)) + break; game.kpower[ll] -= 800.0; /* If firepower is lost, die */ if (game.kpower[ll] <= 0.0) { deadkl(scratch, iquad, scratch); @@ -776,11 +806,15 @@ void nova(coord nov) /* Starship affected by nova -- kick it away. */ game.dist = kount*0.1; - if (icx) icx = (icx < 0 ? -1 : 1); - if (icy) icy = (icy < 0 ? -1 : 1); + if (icx) + icx = (icx < 0 ? -1 : 1); + if (icy) + icy = (icy < 0 ? -1 : 1); game.direc = course[3*(icx+1)+icy+2]; - if (game.direc == 0.0) game.dist = 0.0; - if (game.dist == 0.0) return; + if (game.direc == 0.0) + game.dist = 0.0; + if (game.dist == 0.0) + return; game.optime = 10.0*game.dist/16.0; skip(1); prout(_("Force of nova displaces starship.")); @@ -813,9 +847,11 @@ void snova(bool induced, coord *w) for_quadrants(nq.x) { for_quadrants(nq.y) { num -= game.state.galaxy[nq.x][nq.y].stars; - if (num <= 0) break; + if (num <= 0) + break; } - if (num <=0) break; + if (num <=0) + break; } if (idebug) { proutn("=== Super nova here?"); @@ -841,10 +877,12 @@ void snova(bool induced, coord *w) for_sectors(ns.y) { if (game.quad[ns.x][ns.y]==IHSTAR) { num--; - if (num==0) break; + if (num==0) + break; } } - if (num==0) break; + if (num==0) + break; } skip(1); @@ -878,7 +916,8 @@ void snova(bool induced, coord *w) invalidate(game.state.kcmdr[game.state.remcom]); game.state.remcom--; kldead--; - if (game.state.remcom==0) unschedule(FTBEAM); + if (game.state.remcom==0) + unschedule(FTBEAM); break; } } @@ -919,13 +958,15 @@ void snova(bool induced, coord *w) /* If supernova destroys last Klingons give special message */ if (KLINGREM==0 && !same(nq, game.quadrant)) { skip(2); - if (!induced) prout(_("Lucky you!")); + if (!induced) + prout(_("Lucky you!")); proutn(_("A supernova in %s has just destroyed the last Klingons."), cramlc(quadrant, nq)); finish(FWON); return; } /* if some Klingons remain, continue or die in supernova */ - if (game.alldone) finish(FSNOVAED); + if (game.alldone) + finish(FSNOVAED); return; } diff --git a/src/finish.c b/src/finish.c index a014e6c..c59bd8e 100644 --- a/src/finish.c +++ b/src/finish.c @@ -50,7 +50,8 @@ void selfdestruct(void) void kaboom(void) { stars(); - if (game.ship==IHE) prouts("***"); + if (game.ship==IHE) + prouts("***"); prouts(_("********* Entropy of ")); crmshp(); prouts(_(" maximized *********")); @@ -91,9 +92,12 @@ void finish(FINTYPE ifin) double badpt; badpt = 5.0*game.state.starkl + game.casual + 10.0*game.state.nplankl + 45.*game.nhelp+100.*game.state.basekl+3.*game.abandoned; - if (game.ship == IHF) badpt += 100.0; - else if (game.ship == 0) badpt += 200.0; - if (badpt < 100.0) badpt = 0.0; // Close enough! + if (game.ship == IHF) + badpt += 100.0; + else if (game.ship == 0) + badpt += 200.0; + if (badpt < 100.0) + badpt = 0.0; // Close enough! if (game.state.date-game.indate < 5.0 || // killsPerDate >= RateMax KLINGKILLED/(game.state.date-game.indate) >= @@ -154,7 +158,8 @@ void finish(FINTYPE ifin) prout(_("LIVE LONG AND PROSPER.")); } score(); - if (igotit) plaque(); + if (igotit) + plaque(); return; case FDEPLETE: // Federation Resources Depleted prout(_("Your time has run out and the Federation has been")); @@ -286,8 +291,10 @@ void finish(FINTYPE ifin) prout(_("Your last crew member has died.")); break; } - if (game.ship==IHF) game.ship= 0; - else if (game.ship == IHE) game.ship = IHF; + if (game.ship==IHF) + game.ship= 0; + else if (game.ship == IHE) + game.ship = IHF; game.alive = false; if (KLINGREM != 0) { double goodies = game.state.remres/game.inresor; @@ -323,19 +330,26 @@ void score(void) int ithperd, iwon, klship; iskill = game.skill; - if ((timused == 0 || KLINGREM != 0) && timused < 5.0) timused = 5.0; + if ((timused == 0 || KLINGREM != 0) && timused < 5.0) + timused = 5.0; perdate = KLINGKILLED/timused; ithperd = 500*perdate + 0.5; iwon = 0; - if (game.gamewon) iwon = 100*game.skill; - if (game.ship == IHE) klship = 0; - else if (game.ship == IHF) klship = 1; - else klship = 2; - if (!game.gamewon) game.state.nromrem = 0; // None captured if no win + if (game.gamewon) + iwon = 100*game.skill; + if (game.ship == IHE) + klship = 0; + else if (game.ship == IHF) + klship = 1; + else + klship = 2; + if (!game.gamewon) + game.state.nromrem = 0; // None captured if no win iscore = 10*NKILLK + 50*NKILLC + ithperd + iwon - 100*game.state.basekl - 100*klship - 45*game.nhelp -5*game.state.starkl - game.casual + 20*NKILLROM + 200*NKILLSC - 10*game.state.nplankl - 300*game.state.nworldkl + game.state.nromrem; - if (!game.alive) iscore -= 200; + if (!game.alive) + iscore -= 200; skip(2); prout(_("Your score --")); if (NKILLROM) @@ -408,7 +422,6 @@ void plaque(void) char winner[128]; skip(2); - while (fp == NULL) { proutn(_("File or device name for your plaque: ")); cgetline(winner, sizeof(winner)); diff --git a/src/moving.c b/src/moving.c index 8495cd0..44a4945 100644 --- a/src/moving.c +++ b/src/moving.c @@ -64,7 +64,8 @@ void imove(bool novapush) */ if (game.skill > SKILL_GOOD && game.klhere > 0 && !game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) attack(false); - if (game.alldone) return; + if (game.alldone) + return; } /* compute final position -- new quadrant and sector */ x = QUADSIZE*(game.quadrant.x-1)+game.sector.x; @@ -91,7 +92,8 @@ void imove(bool novapush) w.y = (GALSIZE*QUADSIZE*2)+1 - w.y; kink = 1; } - if (kink) kinks = 1; + if (kink) + kinks = 1; } while (kink); if (kinks) { @@ -116,7 +118,8 @@ void imove(bool novapush) prout(_("Entering %s."), cramlc(quadrant, game.quadrant)); game.quad[game.sector.x][game.sector.y] = game.ship; newqad(false); - if (game.skill>SKILL_NOVICE) attack(false); + if (game.skill>SKILL_NOVICE) + attack(false); return; } iquad = game.quad[w.x][w.y]; @@ -225,9 +228,11 @@ void dock(bool verbose) return; } game.condition = docked; - if (verbose) prout(_("Docked.")); + if (verbose) + prout(_("Docked.")); game.ididit = true; - if (game.energy < game.inenrg) game.energy = game.inenrg; + if (game.energy < game.inenrg) + game.energy = game.inenrg; game.shield = game.inshld; game.torps = game.intorps; game.lsupres = game.inlsr; @@ -387,7 +392,8 @@ static void getcd(bool isprobe, int akey) cramlc(sector, incr)); } } - else prout(_("Ensign Chekov- \"Course laid in, Captain.\"")); + else + prout(_("Ensign Chekov- \"Course laid in, Captain.\"")); } deltax = icolq - game.quadrant.y + 0.1*(incr.x-game.sector.y); deltay = game.quadrant.x - irowq + 0.1*(game.sector.x-incr.y); @@ -423,7 +429,8 @@ static void getcd(bool isprobe, int akey) } game.dist = sqrt(deltax*deltax + deltay*deltay); game.direc = atan2(deltax, deltay)*1.90985932; - if (game.direc < 0.0) game.direc += 12.0; + if (game.direc < 0.0) + game.direc += 12.0; chew(); return; } @@ -445,7 +452,8 @@ void impuls(void) if (game.energy > 30.0) { getcd(false, 0); - if (game.direc == -1.0) return; + if (game.direc == -1.0) + return; power = 20.0 + 100.0*game.dist; } else @@ -473,16 +481,19 @@ void impuls(void) prout(_("First Officer Spock- \"Captain, our speed under impulse")); prout(_("power is only 0.95 sectors per stardate. Are you sure")); proutn(_("we dare spend the time?\" ")); - if (ja() == false) return; + if (ja() == false) + return; } /* Activate impulse engines and pay the cost */ imove(false); game.ididit = true; - if (game.alldone) return; + if (game.alldone) + return; power = 20.0 + 100.0*game.dist; game.energy -= power; game.optime = game.dist/0.095; - if (game.energy <= 0) finish(FNRG); + if (game.energy <= 0) + finish(FNRG); return; } @@ -512,7 +523,8 @@ void warp(bool timewarp) /* Read in course and distance */ getcd(false, 0); - if (game.direc == -1.0) return; + if (game.direc == -1.0) + return; /* Make sure starship has enough energy for the trip */ power = (game.dist+0.05)*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1); @@ -564,11 +576,13 @@ void warp(bool timewarp) game.dist = Rand()*game.dist; } /* Decide if time warp will occur */ - if (0.5*game.dist*pow(7.0,game.warpfac-10.0) > Rand()) twarp = true; + if (0.5*game.dist*pow(7.0,game.warpfac-10.0) > Rand()) + twarp = true; if (idebug && game.warpfac==10 && !twarp) { blooey = false; proutn("=== Force time warp? "); - if (ja() == true) twarp = true; + if (ja() == true) + twarp = true; } if (blooey || twarp) { /* If time warp or engine damage, check path */ @@ -593,7 +607,8 @@ void warp(bool timewarp) ix = x + 0.5; y += deltay; iy = y +0.5; - if (!VALID_SECTOR(ix, iy)) break; + if (!VALID_SECTOR(ix, iy)) + break; if (game.quad[ix][iy] != IHDOT) { blooey = false; twarp = false; @@ -605,11 +620,14 @@ void warp(bool timewarp) /* Activate Warp Engines and pay the cost */ imove(false); - if (game.alldone) return; + if (game.alldone) + return; game.energy -= game.dist*game.warpfac*game.warpfac*game.warpfac*(game.shldup+1); - if (game.energy <= 0) finish(FNRG); + if (game.energy <= 0) + finish(FNRG); game.optime = 10.0*game.dist/game.wfacsq; - if (twarp) timwrp(); + if (twarp) + timwrp(); if (blooey) { game.damage[DWARPEN] = game.damfac*(3.0*Rand()+1.0); skip(1); @@ -711,11 +729,14 @@ void atover(bool igrab) } } } - if (igrab) return; + if (igrab) + return; /* Check to see if captain in shuttle craft */ - if (game.icraft) finish(FSTRACTOR); - if (game.alldone) return; + if (game.icraft) + finish(FSTRACTOR); + if (game.alldone) + return; /* Inform captain of attempt to reach safety */ skip(1); @@ -748,7 +769,8 @@ void atover(bool igrab) power = 0.75*game.energy; game.dist = power/(game.warpfac*game.warpfac*game.warpfac*(game.shldup+1)); distreq = 1.4142+Rand(); - if (distreq < game.dist) game.dist = distreq; + if (distreq < game.dist) + game.dist = distreq; game.optime = 10.0*game.dist/game.wfacsq; game.direc = 12.0*Rand(); /* How dumb! */ game.justin = false; @@ -756,7 +778,8 @@ void atover(bool igrab) warp(true); if (!game.justin) { /* This is bad news, we didn't leave quadrant. */ - if (game.alldone) return; + if (game.alldone) + return; skip(1); prout(_("Insufficient energy to leave quadrant.")); finish(FSNOVAED); @@ -789,7 +812,8 @@ void timwrp() /* next snapshot will be sooner */ schedule(FSNAP, expran(0.25*game.state.remtime)); - if (game.state.nscrem) schedule(FSCMOVE, 0.2777); + if (game.state.nscrem) + schedule(FSCMOVE, 0.2777); game.isatb = 0; unschedule(FCDBAS); unschedule(FSCDBAS); @@ -869,7 +893,8 @@ void probe(void) /* slow mode, so let Kirk know how many probes there are left */ prout(game.nprobes==1 ? _("%d probe left.") : _("%d probes left."), game.nprobes); proutn(_("Are you sure you want to fire a probe? ")); - if (ja() == false) return; + if (ja() == false) + return; } game.isarmed = false; @@ -882,7 +907,8 @@ void probe(void) game.isarmed = ja(); } getcd(true, key); - if (game.direc == -1.0) return; + if (game.direc == -1.0) + return; game.nprobes--; angle = ((15.0 - game.direc) * 0.5235988); game.probeinx = -sin(angle); @@ -1011,7 +1037,8 @@ void mayday(void) } textcolor(RED); warble(); - if (Rand() > probf) break; + if (Rand() > probf) + break; prout(_("fails.")); delay(500); textcolor(DEFAULT); @@ -1150,7 +1177,8 @@ void abandn(void) prout(_("Starfleet puts you in command of another ship,")); prout(_("the Faerie Queene, which is antiquated but,")); prout(_("still useable.")); - if (game.icrystl) prout(_("The dilithium crystals have been moved.")); + if (game.icrystl) + prout(_("The dilithium crystals have been moved.")); game.imine = false; game.iscraft = offship; /* Galileo disappears */ /* Resupply ship */ diff --git a/src/planets.c b/src/planets.c index df9efcc..2a68878 100644 --- a/src/planets.c +++ b/src/planets.c @@ -33,13 +33,15 @@ void preport(void) proutn(_(" class ")); proutn(classes[game.state.plnets[i].pclass]); proutn(" "); - if (game.state.plnets[i].crystals != present) proutn(_("no ")); + if (game.state.plnets[i].crystals != present) + proutn(_("no ")); prout(_("dilithium crystals present.")); if (game.state.plnets[i].known==shuttle_down) prout(_(" Shuttle Craft Galileo on surface.")); } } - if (!iknow) prout(_("No information available.")); + if (!iknow) + prout(_("No information available.")); } void orbit(void) @@ -64,7 +66,8 @@ void orbit(void) game.optime = 0.02+0.03*Rand(); prout(_("Helmsman Sulu- \"Entering standard orbit, Sir.\"")); newcnd(); - if (consumeTime()) return; + if (consumeTime()) + return; game.height = (1400.0+7200.0*Rand()); prout(_("Sulu- \"Entered orbit at altitude %.2f kilometers.\""), game.height); game.inorbit = true; @@ -93,9 +96,11 @@ void sensor(void) if (game.state.plnets[game.iplnet].known==shuttle_down) prout(_(" Sensors show Galileo still on surface.")); proutn(_(" Readings indicate")); - if (game.state.plnets[game.iplnet].crystals != present) proutn(_(" no")); + if (game.state.plnets[game.iplnet].crystals != present) + proutn(_(" no")); prout(_(" dilithium crystals present.\"")); - if (game.state.plnets[game.iplnet].known == unknown) game.state.plnets[game.iplnet].known = known; + if (game.state.plnets[game.iplnet].known == unknown) + game.state.plnets[game.iplnet].known = known; } } @@ -109,7 +114,8 @@ void beam(void) if (!damaged(DSHUTTL) && (game.state.plnets[game.iplnet].known==shuttle_down || game.iscraft == onship)) { skip(1); proutn(_("Spock- \"May I suggest the shuttle craft, Sir?\" ")); - if (ja() == true) shuttle(); + if (ja() == true) + shuttle(); } return; } @@ -217,7 +223,8 @@ void mine(void) return; } game.optime = (0.1+0.2*Rand())*game.state.plnets[game.iplnet].pclass; - if (consumeTime()) return; + if (consumeTime()) + return; prout(_("Mining operation complete.")); game.state.plnets[game.iplnet].crystals = mined; game.imine = game.ididit = true; @@ -345,7 +352,8 @@ void shuttle(void) prout(_(" boards Galileo and swoops toward planet surface.")); game.iscraft = offship; skip(1); - if (consumeTime()) return; + if (consumeTime()) + return; game.state.plnets[game.iplnet].known=shuttle_down; prout(_("Trip complete.")); return; @@ -360,7 +368,8 @@ void shuttle(void) game.icraft = true; skip(1); game.landed = false; - if (consumeTime()) return; + if (consumeTime()) + return; game.iscraft = onship; game.icraft = false; if (game.imine) { @@ -382,7 +391,8 @@ void shuttle(void) skip(1); game.icraft = true; game.iscraft = offship; - if (consumeTime()) return; + if (consumeTime()) + return; game.state.plnets[game.iplnet].known = shuttle_down; game.landed = true; game.icraft = false; @@ -414,7 +424,8 @@ void deathray(void) prout(_("Spock- \"Captain, the 'Experimental Death Ray'")); prout(_(" is highly unpredictible. Considering the alternatives,")); proutn(_(" are you sure this is wise?\" ")); - if (ja() == false) return; + if (ja() == false) + return; prout(_("Spock- \"Acknowledged.\"")); skip(1); game.ididit = true; @@ -438,7 +449,8 @@ void deathray(void) while (game.nenhere > 0) deadkl(game.ks[1], game.quad[game.ks[1].x][game.ks[1].y],game.ks[1]); prout(_("Ensign Chekov- \"Congratulations, Captain!\"")); - if (KLINGREM == 0) finish(FWON); + if (KLINGREM == 0) + finish(FWON); if ((game.options & OPTION_PLAIN) == 0) { prout(_("Spock- \"Captain, I believe the `Experimental Death Ray'")); if (Rand() <= 0.05) { @@ -489,7 +501,8 @@ void deathray(void) prout(_(" Mr. Sulu.")); for_sectors(i) for_sectors(j) - if (game.quad[i][j] == IHDOT) game.quad[i][j] = IHQUEST; + if (game.quad[i][j] == IHDOT) + game.quad[i][j] = IHQUEST; prout(_(" Captain, our quadrant is now infested with")); prouts(_(" - - - - - - *THINGS*.")); skip(1); diff --git a/src/reports.c b/src/reports.c index a33e0ba..93a525d 100644 --- a/src/reports.c +++ b/src/reports.c @@ -55,40 +55,53 @@ void report(void) skip(1); prout(_("You %s a %s%s %s game."), game.alldone? _("were playing") : _("are playing"), s1, s2, s3); - if (game.skill>SKILL_GOOD && game.thawed && !game.alldone) prout(_("No plaque is allowed.")); - if (game.tourn) prout(_("This is tournament game %d."), game.tourn); + if (game.skill>SKILL_GOOD && game.thawed && !game.alldone) + prout(_("No plaque is allowed.")); + if (game.tourn) + prout(_("This is tournament game %d."), game.tourn); prout(_("Your secret password is \"%s\""),game.passwd); proutn(_("%d of %d Klingons have been killed"), KLINGKILLED, INKLINGTOT); - if (NKILLC) prout(_(", including %d Commander%s."), NKILLC, NKILLC==1?"":_("s")); - else if (NKILLK + NKILLSC > 0) prout(_(", but no Commanders.")); - else prout("."); - if (game.skill > SKILL_FAIR) prout(_("The Super Commander has %sbeen destroyed."), - game.state.nscrem?_("not "):""); + if (NKILLC) + prout(_(", including %d Commander%s."), NKILLC, NKILLC==1?"":_("s")); + else if (NKILLK + NKILLSC > 0) + prout(_(", but no Commanders.")); + else + prout("."); + if (game.skill > SKILL_FAIR) + prout(_("The Super Commander has %sbeen destroyed."), + game.state.nscrem?_("not "):""); if (game.state.rembase != game.inbase) { proutn(_("There ")); - if (game.inbase-game.state.rembase==1) proutn(_("has been 1 base")); + if (game.inbase-game.state.rembase==1) + proutn(_("has been 1 base")); else { proutn(_("have been %d bases"), game.inbase-game.state.rembase); } prout(_(" destroyed, %d remaining."), game.state.rembase); } - else prout(_("There are %d bases."), game.inbase); + else + prout(_("There are %d bases."), game.inbase); if (!damaged(DRADIO) || game.condition == docked || game.iseenit) { /* Don't report this if not seen and either the radio is dead or not at base! */ attakreport(false); game.iseenit = true; } - if (game.casual) prout(_("%d casualt%s suffered so far."), - game.casual, game.casual==1? "y" : "ies"); - if (game.nhelp) prout(_("There were %d call%s for help."), - game.nhelp, game.nhelp==1 ? "" : _("s")); + if (game.casual) + prout(_("%d casualt%s suffered so far."), + game.casual, game.casual==1? "y" : "ies"); + if (game.nhelp) + prout(_("There were %d call%s for help."), + game.nhelp, game.nhelp==1 ? "" : _("s")); if (game.ship == IHE) { proutn(_("You have ")); - if (game.nprobes) proutn("%d", game.nprobes); - else proutn(_("no")); + if (game.nprobes) + proutn("%d", game.nprobes); + else + proutn(_("no")); proutn(_(" deep space probe")); - if (game.nprobes!=1) proutn(_("s")); + if (game.nprobes!=1) + proutn(_("s")); prout("."); } if ((!damaged(DRADIO) || game.condition == docked) @@ -173,7 +186,8 @@ void dreprt(void) game.docfac*game.damage[i]+0.005); } } - if (!jdam) prout(_("All devices functional.")); + if (!jdam) + prout(_("All devices functional.")); } void rechart(void) @@ -232,7 +246,8 @@ void chart(void) proutn(" "); } proutn(" |"); - if (iw1.x) w2.x = 1; - else w2.x=QUADSIZE; - if (game.quadrant.x>w1.y) w2.y = 1; - else w2.y=QUADSIZE; + if (game.quadrant.y>w1.x) + w2.x = 1; + else + w2.x=QUADSIZE; + if (game.quadrant.x>w1.y) + w2.y = 1; + else + w2.y=QUADSIZE; } if (!VALID_QUADRANT(w1.x, w1.y) || !VALID_SECTOR(w2.x, w2.y)) { @@ -451,7 +473,8 @@ void eta(void) square(w1.x-game.quadrant.x+0.1*(w2.x-game.sector.x))); wfl = false; - if (prompt) prout(_("Answer \"no\" if you don't know the value:")); + if (prompt) + prout(_("Answer \"no\" if you don't know the value:")); for (;;) { chew(); proutn(_("Time or arrival date? ")); @@ -464,7 +487,8 @@ void eta(void) chew(); return; } - if (twarp < 1.0) twarp = 1.0; + if (twarp < 1.0) + twarp = 1.0; break; } chew(); @@ -487,7 +511,8 @@ void eta(void) if (tpower >= game.energy) { prout(_("Insufficient energy, sir.")); if (!game.shldup || tpower > game.energy*2.0) { - if (!wfl) return; + if (!wfl) + return; proutn(_("New warp factor to try? ")); if (scan() == IHREAL) { wfl = true; diff --git a/src/setup.c b/src/setup.c index aef792a..8963b6c 100644 --- a/src/setup.c +++ b/src/setup.c @@ -296,7 +296,8 @@ void setup(bool needprompt) do { double r = Rand(); int klump = (1.0 - r*r)*klumper; - if (klump > krem) klump = krem; + if (klump > krem) + klump = krem; krem -= klump; do w = randplace(GALSIZE); while (game.state.galaxy[w.x][w.y].supernova || @@ -389,7 +390,8 @@ void setup(bool needprompt) skip(1); prout(_("%d Klingons."), INKLINGTOT); prout(_("An unknown number of Romulans.")); - if (game.state.nscrem) prout(_("And one (GULP) Super-Commander.")); + if (game.state.nscrem) + prout(_("And one (GULP) Super-Commander.")); prout(_("%d stardates."),(int)game.intime); proutn(_("%d starbases in "), game.inbase); } @@ -404,11 +406,14 @@ void setup(bool needprompt) proutn(cramlc(sector, game.sector)); skip(2); prout(_("Good Luck!")); - if (game.state.nscrem) prout(_(" YOU'LL NEED IT.")); + if (game.state.nscrem) + prout(_(" YOU'LL NEED IT.")); waitfor(); newqad(false); - if (game.nenhere-iqhere-game.ithere) game.shldup = true; - if (game.neutz) attack(false); // bad luck to start in a Romulan Neutral Zone + if (game.nenhere-iqhere-game.ithere) + game.shldup = true; + if (game.neutz) // bad luck to start in a Romulan Neutral Zone + attack(false); } bool choose(bool needprompt) @@ -437,15 +442,19 @@ bool choose(bool needprompt) break; } if (isit("saved") || isit("frozen")) { - if (thaw()) continue; + if (thaw()) + continue; chew(); - if (*game.passwd==0) continue; - if (!game.alldone) game.thawed = 1; // No plaque if not finished + if (*game.passwd==0) + continue; + if (!game.alldone) + game.thawed = true; // No plaque if not finished report(); waitfor(); return true; } - if (isit("regular")) break; + if (isit("regular")) + break; proutn(_("What is \"")); proutn(citem); prout("\"?"); @@ -453,14 +462,22 @@ bool choose(bool needprompt) } while (game.length==0 || game.skill==SKILL_NONE) { if (scan() == IHALPHA) { - if (isit("short")) game.length = 1; - else if (isit("medium")) game.length = 2; - else if (isit("long")) game.length = 4; - else if (isit("novice")) game.skill = SKILL_NOVICE; - else if (isit("fair")) game.skill = SKILL_FAIR; - else if (isit("good")) game.skill = SKILL_GOOD; - else if (isit("expert")) game.skill = SKILL_EXPERT; - else if (isit("emeritus")) game.skill = SKILL_EMERITUS; + if (isit("short")) + game.length = 1; + else if (isit("medium")) + game.length = 2; + else if (isit("long")) + game.length = 4; + else if (isit("novice")) + game.skill = SKILL_NOVICE; + else if (isit("fair")) + game.skill = SKILL_FAIR; + else if (isit("good")) + game.skill = SKILL_GOOD; + else if (isit("expert")) + game.skill = SKILL_EXPERT; + else if (isit("emeritus")) + game.skill = SKILL_EMERITUS; else { proutn(_("What is \"")); proutn(citem); @@ -469,8 +486,10 @@ bool choose(bool needprompt) } else { chew(); - if (game.length==0) proutn(_("Would you like a Short, Medium, or Long game? ")); - else if (game.skill == SKILL_NONE) proutn(_("Are you a Novice, Fair, Good, Expert, or Emeritus player? ")); + if (game.length==0) + proutn(_("Would you like a Short, Medium, or Long game? ")); + else if (game.skill == SKILL_NONE) + proutn(_("Are you a Novice, Fair, Good, Expert, or Emeritus player? ")); } } // Choose game options -- added by ESR for SST2K @@ -538,10 +557,12 @@ void newcnd(void) /* update our alert status */ { game.condition = green; - if (game.energy < 1000.0) game.condition = yellow; + if (game.energy < 1000.0) + game.condition = yellow; if (game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons || game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans) game.condition = red; - if (!game.alive) game.condition=dead; + if (!game.alive) + game.condition=dead; } coord newkling(int i) @@ -697,10 +718,14 @@ void newqad(bool shutup) distance(game.sector, game.tholian); game.kpower[game.nenhere] = Rand()*400.0 +100.0 +25.0*game.skill; /* Reserve unocupied corners */ - if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X'; - if (game.quad[1][QUADSIZE]==IHDOT) game.quad[1][QUADSIZE] = 'X'; - if (game.quad[QUADSIZE][1]==IHDOT) game.quad[QUADSIZE][1] = 'X'; - if (game.quad[QUADSIZE][QUADSIZE]==IHDOT) game.quad[QUADSIZE][QUADSIZE] = 'X'; + if (game.quad[1][1]==IHDOT) + game.quad[1][1] = 'X'; + if (game.quad[1][QUADSIZE]==IHDOT) + game.quad[1][QUADSIZE] = 'X'; + if (game.quad[QUADSIZE][1]==IHDOT) + game.quad[QUADSIZE][1] = 'X'; + if (game.quad[QUADSIZE][QUADSIZE]==IHDOT) + game.quad[QUADSIZE][QUADSIZE] = 'X'; } } @@ -713,10 +738,14 @@ void newqad(bool shutup) // Take out X's in corners if Tholian present if (game.ithere) { - if (game.quad[1][1]=='X') game.quad[1][1] = IHDOT; - if (game.quad[1][QUADSIZE]=='X') game.quad[1][QUADSIZE] = IHDOT; - if (game.quad[QUADSIZE][1]=='X') game.quad[QUADSIZE][1] = IHDOT; - if (game.quad[QUADSIZE][QUADSIZE]=='X') game.quad[QUADSIZE][QUADSIZE] = IHDOT; + if (game.quad[1][1]=='X') + game.quad[1][1] = IHDOT; + if (game.quad[1][QUADSIZE]=='X') + game.quad[1][QUADSIZE] = IHDOT; + if (game.quad[QUADSIZE][1]=='X') + game.quad[QUADSIZE][1] = IHDOT; + if (game.quad[QUADSIZE][QUADSIZE]=='X') + game.quad[QUADSIZE][QUADSIZE] = IHDOT; } } @@ -729,7 +758,8 @@ void sortkl(void) // The author liked bubble sort. So we will use it. :-( - if (game.nenhere-iqhere-game.ithere < 2) return; + if (game.nenhere-iqhere-game.ithere < 2) + return; do { sw = false; @@ -764,11 +794,13 @@ void setpassword(void) proutn(_("Please type in a secret password- ")); scan(); strcpy(game.passwd, citem); - if (*game.passwd != 0) break; + if (*game.passwd != 0) + break; } } else { int i; - for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25)); + for(i=0;i<3;i++) + game.passwd[i]=(char)(97+(int)(Rand()*25)); game.passwd[3]=0; } } diff --git a/src/sst.c b/src/sst.c index d0d5d05..a0d732d 100644 --- a/src/sst.c +++ b/src/sst.c @@ -318,14 +318,16 @@ static void helpme(void) key = scan(); } setwnd(message_window); - if (key == IHEOL) return; + if (key == IHEOL) + return; for (i = 0; i < NUMCOMMANDS; i++) { if (ACCEPT(i) && strcasecmp(commands[i].name, citem)==0) { i = commands[i].value; break; } } - if (i != NUMCOMMANDS) break; + if (i != NUMCOMMANDS) + break; skip(1); listCommands(); key = IHEOL; @@ -446,11 +448,13 @@ static void makemoves(void) break; case PHASERS: // phasers phasers(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case TORPEDO: // photons photon(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case MOVE: // move warp(false); @@ -464,7 +468,8 @@ static void makemoves(void) break; case DOCK: // dock dock(true); - if (game.ididit) attack(false); + if (game.ididit) + attack(false); break; case DAMAGES: // damages dreprt(); @@ -477,7 +482,8 @@ static void makemoves(void) break; case REST: // rest wait(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case WARP: // warp setwrp(); @@ -490,22 +496,26 @@ static void makemoves(void) break; case ORBIT: // orbit orbit(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case TRANSPORT: // transport "beam" beam(); break; case MINE: // mine mine(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case CRYSTALS: // crystals usecrystals(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case SHUTTLE: // shuttle shuttle(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case PLANETS: // Planet list preport(); @@ -526,7 +536,8 @@ static void makemoves(void) break; case PROBE: probe(); // Launch probe - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case ABANDON: // Abandon Ship abandn(); @@ -542,14 +553,16 @@ static void makemoves(void) break; case DEATHRAY: // Try a desparation measure deathray(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case DEBUGCMD: // What do we want for debug??? debugme(); break; case MAYDAY: // Call for help mayday(); - if (game.ididit) hitme = true; + if (game.ididit) + hitme = true; break; case QUIT: game.alldone = true; // quit the game @@ -581,7 +594,8 @@ static void makemoves(void) } if (hitme && !game.justin) { attack(true); - if (game.alldone) break; + if (game.alldone) + break; if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova) { // went NOVA! atover(false); hitme = true; @@ -590,9 +604,11 @@ static void makemoves(void) } break; } - if (game.alldone) break; + if (game.alldone) + break; } - if (idebug) prout("=== Ending"); + if (idebug) + prout("=== Ending"); } @@ -613,11 +629,11 @@ int main(int argc, char **argv) replayfp = fopen(optarg, "r"); if (replayfp == NULL) { fprintf(stderr, "sst: can't open replay file %s\n", optarg); - exit(1); + exit(1); } if (fscanf(replayfp, "seed %d\n", &seed) != 1) { fprintf(stderr, "sst: replay file %s is ill-formed\n", optarg); - exit(1); + exit(1); } /* FALL THROUGH */ case 't': @@ -656,7 +672,8 @@ int main(int argc, char **argv) score(); game.alldone = false; } - else makemoves(); + else + makemoves(); skip(1); stars(); skip(1); @@ -669,7 +686,8 @@ int main(int argc, char **argv) } } proutn(_("Do you want to play again? ")); - if (!ja()) break; + if (!ja()) + break; } skip(1); prout(_("May the Great Bird of the Galaxy roost upon your home planet.")); @@ -706,8 +724,10 @@ char *cramlc(enum loctype key, coord w) { static char buf[32]; buf[0] = '\0'; - if (key == quadrant) strcpy(buf, _("Quadrant ")); - else if (key == sector) strcpy(buf, _("Sector ")); + if (key == quadrant) + strcpy(buf, _("Quadrant ")); + else if (key == sector) + strcpy(buf, _("Sector ")); sprintf(buf+strlen(buf), "%d - %d", w.x, w.y); return buf; } @@ -715,7 +735,8 @@ char *cramlc(enum loctype key, coord w) void crmena(bool stars, feature enemy, enum loctype key, coord w) /* print an enemy and his location */ { - if (stars) proutn("***"); + if (stars) + proutn("***"); cramen(enemy); proutn(_(" at ")); proutn(cramlc(key, w)); @@ -820,7 +841,8 @@ int scan(void) // Treat as alpha cp = citem; while (*linep && *linep!=' ') { - if ((cp - citem) < 9) *cp++ = tolower(*linep); + if ((cp - citem) < 9) + *cp++ = tolower(*linep); linep++; } *cp = 0; @@ -834,8 +856,10 @@ bool ja(void) for(;;) { scan(); chew(); - if (*citem == 'y') return true; - if (*citem == 'n') return false; + if (*citem == 'y') + return true; + if (*citem == 'n') + return false; proutn(_("Please answer with \"y\" or \"n\": ")); } } @@ -859,7 +883,8 @@ void debugme(void) { proutn("Reset levels? "); if (ja() == true) { - if (game.energy < game.inenrg) game.energy = game.inenrg; + if (game.energy < game.inenrg) + game.energy = game.inenrg; game.shield = game.inshld; game.torps = game.intorps; game.lsupres = game.inlsr; @@ -874,8 +899,10 @@ void debugme(void) proutn("Toggle debug flag? "); if (ja() == true) { idebug = !idebug; - if (idebug) prout("Debug output ON"); - else prout("Debug output OFF"); + if (idebug) + prout("Debug output ON"); + else + prout("Debug output OFF"); } proutn("Cause selective damage? "); if (ja() == true) { diff --git a/src/sst.py b/src/sst.py index 5d69d91..477c05a 100644 --- a/src/sst.py +++ b/src/sst.py @@ -7,7 +7,7 @@ radically different -- the Python code makes heavy use of objects. Note that the game.quad, game.snap.galaxy and game.snap.chart members are not actually arrays but dictioaries indixed by coord tuples. Be setting -the hash of a coord exual to the hash of a literal tuple containing its +the hash of a coord equal to the hash of a literal tuple containing its coordinate data, we ensure these can be indexed both ways. """ @@ -61,13 +61,14 @@ class coord: return "%d - %d" % (self.x, self.y) class feature: - "A feature in the current quadrant (ship, star, black hole, etc)." + "A feature in the current quadrant (ship, star, black hole, base, etc)." def __init__(self): self.type = None # name of feature type self.sector = None # sector location def distance(self): return self.sector.distance(game.sector) def __str__(self): + "This will be overridden by subclasses." return self.name[0] def sectormove(self, dest): "Move this feature within the current quadrant." @@ -76,15 +77,14 @@ class feature: game.quad[dest] = self self.sector = dest -empty = None # Value of empty space in game.quad - class ship(feature): - "An enemy ship in the current quadrant." - def __init__(self): + "A starship, frindly or enemy." + def __init__(self, type, power): feature.__init__(self) - self.type = None # klingon, romulan, commander, - # supercommander, tholian - self.power = None # power + self.type = type # klingon, romulan, commander, + # supercommander, tholian, + # enterprise, faerie queene. + self.power = power # power if self.type in ("Klingon", "Commander", "Super-Commander"): game.remkl += 1 elif self.type == "Romulan": @@ -95,6 +95,16 @@ class ship(feature): elif self.type == "Romulan": game.romrem -= 1 +class space(feature): + "Empty space. Has no state, just knows how to identify iself." + def __str__(self): + return '*' + +class star(feature): + "A star. Has no state, just knows how to identify iself." + def __str__(self): + return '*' + class planet(feature): "A planet. May be inhabited or not, may hold dilithium crystals or not." def __init(self): @@ -103,32 +113,24 @@ class planet(feature): self.crystals = None # "absent", "present", or "mined" self.inhabited = False self.known = "unknown" # Other values: "known" and "shuttle down" + game.state.planets.append(self) + def __del__(self): + game.state.planets.remove(self) def __str__(self): if self.inhabited: return '@' else: return 'P' -class star(feature): - "A star. Has no state, just knows how to identify iself." - def __init(self): - feature.__init__(self) - def __str__(self): - return '*' - class web(feature): "A bit of Tholian web. Has no state, just knows how to identify iself." - def __init(self): - feature.__init__(self) def __str__(self): return '*' class blackhole(feature): "A black hole. Has no hair, just knows how to identify iself." - def __init(self): - feature.__init__(self) def __str__(self): - return '*' + return ' ' class starbase(feature): "Starbases also have no features, just a location." @@ -140,8 +142,6 @@ class starbase(feature): game.state.bases.remove(self) def __str__(self): return 'B' - def __del__(self): - feature.__del__(self) class quadrant: def __init__(self): @@ -180,9 +180,8 @@ class snapshot: self.starkl = None # destroyed stars self.basekl = None # destroyed bases self.nromrem = None # Romulans remaining - self.nplankl = None # destroyed uninhabited planets - self.nworldkl = None # destroyed inhabited planets - self.plnets = []; # List of planets known + self.nplankl = None # destroyed uninhabited planets self.nworldkl = None # destroyed inhabited planets + self.planets = []; # List of planets known self.date = None # stardate self.remres = None # remaining resources self. remtime = None # remaining time @@ -571,10 +570,10 @@ def movescom(ship, avoid): game.state.kscmdr = iq game.state.galaxy[game.state.kscmdr].klingons += 1 # check for a helpful planet in the destination quadrant - for planet in game.state.plnets: + for planet in game.state.planets: if planet.location == game.state.kscmdr and planet.crystals=="present": # destroy the planet - game.state.plnets.remove(planet) + del planet if communicating(): if not ipage: pause_game(True) @@ -596,12 +595,12 @@ def scom(): passive = ((NKILLC+NKILLK)/(game.state.date+0.01-game.indate) < 0.1*game.skill*(game.skill+1.0) \ or (game.state.date-game.indate) < 3.0) if not game.iscate and passive: - # compute move away from Enterprise - idelta = game.state.kscmdr - game.quadrant + # coxmpute move away from Enterprise + delta = game.state.kscmdr - game.quadrant if distance(game.state.kscmdr) > 2.0: # circulate in space - idelta,x = game.state.kscmdr.y-game.quadrant.y - idelta,y = game.quadrant.x-game.state.kscmdr.x + delta.x = game.state.kscmdr.y-game.quadrant.y + delta.y = game.quadrant.x-game.state.kscmdr.x else: if len(game.state.bases): unschedule("FSCMOVE") @@ -627,16 +626,16 @@ def scom(): if len(nearest) == 0: return # Nothing suitable -- wait until next time # decide how to move toward base - idelta = ibq - game.state.kscmdr + delta = ibq - game.state.kscmdr # maximum movement is 1 quadrant in either or both axis delta = delta.sgn() # try moving in both x and y directions - iq = game.state.kscmdr + idelta + iq = game.state.kscmdr + delta if movescom(iq, passive): # failed -- try some other maneuvers - if ideltax==0 or ideltay==0: + if delta.x==0 or delta.y==0: # attempt angle move - if ideltax != 0: + if delta.x != 0: iq.y = game.state.kscmdr.y + 1 if movescom(iq, passive): iq.y = game.state.kscmdr.y - 1 @@ -650,7 +649,7 @@ def scom(): # try moving just in x or y iq.y = game.state.kscmdr.y if movescom(iq, passive): - iq.y = game.state.kscmdr.y + ideltay + iq.y = game.state.kscmdr.y + delta.y iq.x = game.state.kscmdr.x movescom(iq, passive) # check for a base @@ -720,7 +719,7 @@ def movetho(void): game.tholian = None return # Do nothing if we are blocked - if game.quad[next] != empty and not isinstance(game.quad[next]. web): + if not (isinstance(game.quad[next], space) or isinstance(game.quad[next], web)): return # Now place some web im = (next - game.tholian.location).sgn() @@ -728,13 +727,13 @@ def movetho(void): # move in x axis while game.tholian.location.x != next.x: game.tholian.location.x += im.x - if game.quad[game.tholian.location] == empty: + if isinstance(game.quad[game.tholian.location], space): game.quad[game.tholian.location] = web() elif game.tholian.y != next.y: # move in y axis while game.tholian.y != next.y: game.tholian.y += im.y - if game.quad[game.tholian.location] == empty: + if isinstance(game.quad[game.tholian.location], space): game.quad[game.tholian.location] = web() # web is done, move ship game.tholian.movesector(next) diff --git a/src/sstlinux.c b/src/sstlinux.c index 3c2ebbe..422c305 100644 --- a/src/sstlinux.c +++ b/src/sstlinux.c @@ -14,14 +14,17 @@ static int fd = 0; void sound(unsigned int freq) { #ifdef HAVE_LINUX_KD_H - if(fd==0) fd=open("/dev/console", O_RDONLY); - if(fd>0) ioctl(fd, KDMKTONE, 1193180/freq + (0xFFFF<<16)); + if (fd==0) + fd=open("/dev/console", O_RDONLY); + if (fd>0) + ioctl(fd, KDMKTONE, 1193180/freq + (0xFFFF<<16)); #endif } void nosound(void) { #ifdef HAVE_LINUX_KD_H - if(fd>0) ioctl(fd, KDMKTONE, 0); + if(fd>0) + ioctl(fd, KDMKTONE, 0); #endif }