From: Eric S. Raymond Date: Tue, 19 Sep 2006 23:56:55 +0000 (+0000) Subject: Clean up more booleans. X-Git-Tag: 2.0~223 X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=commitdiff_plain;h=ad1478c7cc24b761592a1e355015b44b243aeeda Clean up more booleans. --- diff --git a/src/ai.c b/src/ai.c index e524a8e..6fc7908 100644 --- a/src/ai.c +++ b/src/ai.c @@ -45,14 +45,13 @@ static bool tryexit(int lookx, int looky, int ienm, int loccom, int irun) game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--; game.state.galaxy[iq.x][iq.y].klingons++; if (ienm==IHS) { - game.ishere=0; - game.iscate=0; - game.ientesc=0; - game.isatb=0; + game.ishere = false; + game.iscate = 0; + game.ientesc = false; + game.isatb = 0; schedule(FSCMOVE, 0.2777); unschedule(FSCDBAS); - game.state.kscmdr.x=iq.x; - game.state.kscmdr.y=iq.y; + game.state.kscmdr=iq; } else { for_commanders(n) { @@ -317,8 +316,8 @@ static bool movescom(coord iq, bool flag, bool *ipage) /* SC has scooted, Remove him from current quadrant */ game.iscate=0; game.isatb=0; - game.ishere=0; - game.ientesc=0; + game.ishere = false; + game.ientesc = false; unschedule(FSCDBAS); for_local_enemies(i) if (game.quad[game.ks[i].x][game.ks[i].y] == IHS) break; @@ -535,7 +534,7 @@ void movetho(void) int idx, idy, im, i; coord dummy; /* Move the Tholian */ - if (game.ithere==0 || game.justin == 1) return; + if (!game.ithere || game.justin) return; if (game.tholian.x == 1 && game.tholian.y == 1) { idx = 1; idy = QUADSIZE; @@ -551,7 +550,7 @@ void movetho(void) } else { /* something is wrong! */ - game.ithere = 0; + game.ithere = false; return; } @@ -590,7 +589,8 @@ void movetho(void) dropin(IHBLANK, &dummy); crmena(true, IHT, sector, game.tholian); prout(_(" completes web.")); - game.ithere = game.tholian.x = game.tholian.y = 0; + game.ithere = false; + game.tholian.x = game.tholian.y = 0; game.nenhere--; return; } diff --git a/src/battle.c b/src/battle.c index 08a8b16..dba9f29 100644 --- a/src/battle.c +++ b/src/battle.c @@ -181,13 +181,14 @@ void ram(bool ibumpd, int ienm, coord w) void torpedo(double course, double r, int inx, int iny, double *hit, int i, int n) /* let a photon torpedo fly */ { - int l, iquad=0, jx=0, jy=0, shoved=0, ll; - + int l, iquad=0, jx=0, jy=0, ll; + bool shoved = false; double ac=course + 0.25*r; double angle = (15.0-ac)*0.5235988; double bullseye = (15.0 - course)*0.5235988; double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger; double ang, temp, xx, yy, kp, h1; + struct quadrant *q = &game.state.galaxy[game.quadrant.x][game.quadrant.y]; coord w; w.x = w.y = 0; @@ -245,7 +246,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int i, int game.sector.x = jx; game.sector.y = jy; crmshp(); - shoved = 1; + shoved = true; break; case IHC: /* Hit a commander */ @@ -298,22 +299,21 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int i, int proutn(_(" damaged--")); game.ks[ll].x = jx; game.ks[ll].y = jy; - shoved = 1; + shoved = true; break; case IHB: /* Hit a base */ skip(1); prout(_("***STARBASE DESTROYED..")); for_starbases(ll) { - if (game.state.baseq[ll].x==game.quadrant.x && game.state.baseq[ll].y==game.quadrant.y) { - game.state.baseq[ll].x=game.state.baseq[game.state.rembase].x; - game.state.baseq[ll].y=game.state.baseq[game.state.rembase].y; + if (same(game.state.baseq[ll], game.quadrant)) { + game.state.baseq[ll]=game.state.baseq[game.state.rembase]; break; } } game.quad[w.x][w.y]=IHDOT; game.state.rembase--; game.base.x=game.base.y=0; - game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase--; + q->starbase--; game.state.chart[game.quadrant.x][game.quadrant.y].starbase--; game.state.basekl++; newcnd(); @@ -322,7 +322,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int i, int crmena(true, iquad, sector, w); prout(_(" destroyed.")); game.state.nplankl++; - game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET; + q->planet = NOPLANET; DESTROY(&game.state.plnets[game.iplnet]); game.iplnet = 0; game.plnet.x = game.plnet.y = 0; @@ -336,7 +336,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int i, int crmena(true, iquad, sector, w); prout(_(" destroyed.")); game.state.nworldkl++; - game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET; + q->planet = NOPLANET; DESTROY(&game.state.plnets[game.iplnet]); game.iplnet = 0; game.plnet.x = game.plnet.y = 0; @@ -373,8 +373,8 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int i, int * you can shove the Thingy and piss it off. * It then becomes an enemy and may fire at you. */ - iqengry=1; - shoved=1; + iqengry = true; + shoved = true; } return; case IHBLANK: /* Black hole */ @@ -393,7 +393,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int i, int h1 = fabs(h1); if (h1 >= 600) { game.quad[w.x][w.y] = IHDOT; - game.ithere = 0; + game.ithere = false; game.tholian.x = game.tholian.y = 0; deadkl(w, iquad, w.x, w.y); return; @@ -406,7 +406,8 @@ void torpedo(double course, double r, int inx, int iny, double *hit, int i, int } prout(_(" disappears.")); game.quad[w.x][w.y] = IHWEB; - game.ithere = game.tholian.x = game.tholian.y = 0; + game.ithere = false; + game.tholian.x = game.tholian.y = 0; game.nenhere--; { coord dummy; @@ -498,7 +499,7 @@ void attack(bool torps_ok) return; } if ((((game.comhere || game.ishere) && !game.justin) || game.skill == SKILL_EMERITUS) && torps_ok) movcom(); - if (game.nenhere==0 || (game.nenhere==1 && iqhere && iqengry==0)) return; + if (game.nenhere==0 || (game.nenhere==1 && iqhere && !iqengry)) return; pfac = 1.0/game.inshld; if (game.shldchg == 1) chgfac = 0.25+0.5*Rand(); skip(1); @@ -510,8 +511,7 @@ void attack(bool torps_ok) /* Increase chance of photon torpedos if docked or enemy energy low */ if (game.condit == IHDOCKED) r *= 0.25; if (game.kpower[loop] < 500) r *= 0.25; - jay.x = game.ks[loop].x; - jay.y = game.ks[loop].y; + jay = game.ks[loop]; iquad = game.quad[jay.x][jay.y]; if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue; itflag = (iquad == IHK && r > 0.0005) || !torps_ok || @@ -641,11 +641,12 @@ void deadkl(coord w, int type, int ixx, int iyy) } else if (type == IHT) { /* Killed a Tholian */ - game.ithere = 0; + game.ithere = false; } else if (type == IHQUEST) { /* Killed a Thingy */ - iqhere=iqengry=thing.x=thing.y=0; + iqhere = iqengry = false; + thing.x =thing.y = 0; } else { /* Some type of a Klingon */ @@ -669,7 +670,8 @@ void deadkl(coord w, int type, int ixx, int iyy) break; case IHS: game.state.nscrem--; - game.ishere = game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = game.iscate = 0; + game.ishere = false; + game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = game.iscate = 0; unschedule(FSCMOVE); unschedule(FSCDBAS); break; @@ -731,7 +733,8 @@ void photon(void) { double targ[4][3], course[4]; double r, dummy; - int key, n, i, osuabor; + int key, n, i; + bool osuabor; game.ididit = false; @@ -824,7 +827,7 @@ void photon(void) } game.ididit = true; /* Loop for moving torpedoes */ - osuabor = 0; + osuabor = false; for (i = 1; i <= n && !osuabor; i++) { if (game.condit != IHDOCKED) game.torps--; r = (Rand()+Rand())*0.5 -0.5; @@ -838,7 +841,7 @@ void photon(void) skip(1); if (i < n) prout(_(" Remainder of burst aborted.")); - osuabor=1; + osuabor = true; if (Rand() <= 0.2) { prout(_("***Photon tubes damaged by misfire.")); game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand()); @@ -868,7 +871,7 @@ static void overheat(double rpow) } } -static int checkshctrl(double rpow) +static bool checkshctrl(double rpow) /* check shield control */ { double hit; @@ -877,7 +880,7 @@ static int checkshctrl(double rpow) skip(1); if (Rand() < .998) { prout(_("Shields lowered.")); - return 0; + return false; } /* Something bad has happened */ prouts(_("***RED ALERT! RED ALERT!")); @@ -890,7 +893,7 @@ static int checkshctrl(double rpow) skip(1); stars(); finish(FPHASER); - return 1; + return true; } prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\"")); skip(2); @@ -909,7 +912,7 @@ static int checkshctrl(double rpow) prout(_("Phaser energy dispersed by shields.")); prout(_("Enemy unaffected.")); overheat(rpow); - return 1; + return true; } @@ -918,13 +921,13 @@ void phasers(void) { double hits[21], rpow=0, extra, powrem, over, temp; int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */ - int ifast=0, no=0, ipoop=1, msgflag = 1; + bool ifast = false, no = false, ipoop = true, msgflag = true; enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET; int key=0; skip(1); /* SR sensors and Computer */ - if (damaged(DSRSENS) || damaged(DCOMPTR)) ipoop = 0; + if (damaged(DSRSENS) || damaged(DCOMPTR)) ipoop = false; if (game.condit == IHDOCKED) { prout(_("Phasers can't be fired through base shields.")); chew(); @@ -947,7 +950,7 @@ void phasers(void) return; } prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\"")); - ifast = 1; + ifast = true; } /* Original code so convoluted, I re-did it all */ @@ -978,7 +981,7 @@ void phasers(void) } } else if (isit("no")) { - no = 1; + no = true; } else { huh(); @@ -1011,7 +1014,7 @@ void phasers(void) switch (automode) { case AUTOMATIC: if (key == IHALPHA && isit("no")) { - no = 1; + no = true; key = scan(); } if (key != IHREAL && game.nenhere != 0) { @@ -1044,7 +1047,7 @@ void phasers(void) return; } if ((key=scan()) == IHALPHA && isit("no")) { - no = 1; + no = true; } if (ifast) { game.energy -= 200; /* Go and do it! */ @@ -1071,7 +1074,7 @@ void phasers(void) hittem(hits); game.ididit = true; } - if (extra > 0 && game.alldone == 0) { + if (extra > 0 && !game.alldone) { if (game.ithere) { proutn(_("*** Tholian web absorbs ")); if (game.nenhere>0) proutn(_("excess ")); @@ -1106,7 +1109,7 @@ void phasers(void) proutn(_("Energy available= %.2f"), game.energy-.006-(ifast?200:0)); skip(1); - msgflag = 0; + msgflag = false; rpow = 0.0; } if (damaged(DSRSENS) && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) && @@ -1145,7 +1148,7 @@ void phasers(void) } if (key == IHEOL) { if (k==1) { /* Let me say I'm baffled by this */ - msgflag = 1; + msgflag = true; } continue; } @@ -1172,7 +1175,7 @@ void phasers(void) return; } if (key == IHALPHA && isit("no")) { - no = 1; + no = true; } game.energy -= rpow; chew(); @@ -1232,7 +1235,7 @@ void hittem(double *hits) else proutn(_("Very small hit on ")); ienm = game.quad[w.x][w.y]; - if (ienm==IHQUEST) iqengry=1; + if (ienm==IHQUEST) iqengry = true; crmena(false,ienm,sector,w); skip(1); if (kpow == 0) { diff --git a/src/events.c b/src/events.c index d4eac3f..95a3c44 100644 --- a/src/events.c +++ b/src/events.c @@ -60,9 +60,9 @@ static bool cancelrest(void) void events(void) /* run through the event queue looking for things to do */ { - int istract=0, evcode, i=0, j, k, l; + int evcode, i=0, j, k, l; double fintim = game.state.date + game.optime, datemin, xtime, repair, yank=0; - bool radio_was_broken, ictbeam = false, ipage = false; + bool radio_was_broken, ictbeam = false, ipage = false, istract = false; struct quadrant *pdest, *q; coord w, hold; event *ev, *ev2; @@ -160,7 +160,7 @@ void events(void) break; case FSPY: /* Check with spy to see if S.C. should tractor beam */ if (game.state.nscrem == 0 || - ictbeam+istract > 0 || + ictbeam || istract || game.condit==IHDOCKED || game.isatb==1 || game.iscate==1) return; if (game.ientesc || (game.energy < 2000 && game.torps < 4 && game.shield < 1250) || @@ -169,7 +169,7 @@ void events(void) (game.energy < 2500 || damaged(DPHASER)) && (game.torps < 5 || damaged(DPHOTON)))) { /* Tractor-beam her! */ - istract=1; + istract = true; yank = square(game.state.kscmdr.x-game.quadrant.x) + square(game.state.kscmdr.y-game.quadrant.y); /********* fall through to FTBEAM code ***********/ } @@ -202,7 +202,7 @@ void events(void) /* If Kirk & Co. screwing around on planet, handle */ atover(true); /* atover(true) is Grab */ if (game.alldone) return; - if (game.icraft == 1) { /* Caught in Galileo? */ + if (game.icraft) { /* Caught in Galileo? */ finish(FSTRACTOR); return; } @@ -363,9 +363,9 @@ void events(void) break; case FSCMOVE: /* Supercommander moves */ schedule(FSCMOVE, 0.2777); - if (game.ientesc+istract==0 && - game.isatb != 1 && - (game.iscate != 1 || !game.justin)) scom(&ipage); + if (!game.ientesc && !istract && game.isatb != 1 && + (game.iscate != 1 || !game.justin)) + scom(&ipage); break; case FDSPROB: /* Move deep space probe */ schedule(FDSPROB, 0.01); diff --git a/src/planets.c b/src/planets.c index 2eed37c..fd10f67 100644 --- a/src/planets.c +++ b/src/planets.c @@ -357,12 +357,12 @@ void shuttle(void) skip(1); prout(_("The short hop begins . . .")); game.state.plnets[game.iplnet].known=known; - game.icraft = 1; + game.icraft = true; skip(1); game.landed = -1; if (consumeTime()) return; game.iscraft = 1; - game.icraft = 0; + game.icraft = false; if (game.imine) { game.icrystl = 1; game.cryprob = 0.05; @@ -380,12 +380,12 @@ void shuttle(void) skip(1); prouts(_("The hangar doors open; the trip begins.")); skip(1); - game.icraft = 1; + game.icraft = true; game.iscraft = 0; if (consumeTime()) return; game.state.plnets[game.iplnet].known = shuttle_down; game.landed = 1; - game.icraft = 0; + game.icraft = false; prout(_("Trip complete")); return; } diff --git a/src/reports.c b/src/reports.c index d8f31c6..7ea7c17 100644 --- a/src/reports.c +++ b/src/reports.c @@ -323,9 +323,9 @@ static void status(int req) break; case 10: if (game.options & OPTION_WORLDS) { - int here = game.state.galaxy[game.quadrant.x][game.quadrant.y].planet; - if (here != NOPLANET && game.state.plnets[here].inhabited != UNINHABITED) - proutn(_("Major system %s"), systemname(here)); + int plnet = game.state.galaxy[game.quadrant.x][game.quadrant.y].planet; + if (plnet != NOPLANET && game.state.plnets[plnet].inhabited != UNINHABITED) + proutn(_("Major system %s"), systemname(plnet)); else proutn(_("Sector is uninhabited")); } diff --git a/src/setup.c b/src/setup.c index 600afc4..d464616 100644 --- a/src/setup.c +++ b/src/setup.c @@ -253,8 +253,8 @@ void setup(bool needprompt) game.battle.x = game.battle.y = 0; game.state.date = game.indate = 100.0*(int)(31.0*Rand()+20.0); game.nkinks = game.nhelp = game.casual = game.abandoned = 0; - game.resting = game.imine = false; - game.isatb = game.iscate = game.icrystl = game.icraft = game.state.nplankl = 0; + game.resting = game.imine = game.icraft = false; + game.isatb = game.iscate = game.icrystl = game.state.nplankl = 0; game.state.starkl = game.state.basekl = 0; game.iscraft = 1; game.landed = -1; @@ -595,7 +595,7 @@ void newqad(bool shutup) { int i, j; coord w; - struct quadrant *here; + struct quadrant *q; game.iattak = 1; game.justin = true; @@ -603,39 +603,39 @@ void newqad(bool shutup) game.klhere = 0; game.comhere = 0; game.plnet.x = game.plnet.y = 0; - game.ishere = 0; + game.ishere = false; game.irhere = 0; game.iplnet = 0; game.nenhere = 0; game.neutz = false; game.inorbit = false; game.landed = -1; - game.ientesc = 0; - game.ithere = 0; - iqhere=0; - iqengry=0; + game.ientesc = false; + game.ithere = false; + iqhere = false; + iqengry = false; game.iseenit = 0; if (game.iscate) { // Attempt to escape Super-commander, so tbeam back! game.iscate = 0; - game.ientesc = 1; + game.ientesc = true; } // Clear quadrant for_sectors(i) for_sectors(j) game.quad[i][j] = IHDOT; - here = &game.state.galaxy[game.quadrant.x][game.quadrant.y]; + q = &game.state.galaxy[game.quadrant.x][game.quadrant.y]; // cope with supernova - if (here->supernova) + if (q->supernova) return; - game.klhere = here->klingons; - game.irhere = here->romulans; + game.klhere = q->klingons; + game.irhere = q->romulans; game.nenhere = game.klhere + game.irhere; // Position Starship game.quad[game.sector.x][game.sector.y] = game.ship; - if (here->klingons) { + if (q->klingons) { // Position ordinary Klingons for (i = 1; i <= game.klhere; i++) newkling(i, &w); @@ -654,7 +654,7 @@ void newqad(bool shutup) game.quad[game.ks[1].x][game.ks[1].y] = IHS; game.kpower[1] = 1175.0 + 400.0*Rand() + 125.0*game.skill; game.iscate = game.state.remkl>1; - game.ishere = 1; + game.ishere = true; } } // Put in Romulans if needed @@ -665,13 +665,13 @@ void newqad(bool shutup) game.kpower[i] = Rand()*400.0 + 450.0 + 50.0*game.skill; } // If quadrant needs a starbase, put it in - if (here->starbase) + if (q->starbase) dropin(IHB, &game.base); // If quadrant needs a planet, put it in - if (here->planet != NOPLANET) { - game.iplnet = here->planet; - if (game.state.plnets[here->planet].inhabited == UNINHABITED) + if (q->planet != NOPLANET) { + game.iplnet = q->planet; + if (game.state.plnets[q->planet].inhabited == UNINHABITED) dropin(IHP, &game.plnet); else dropin(IHW, &game.plnet); @@ -679,11 +679,11 @@ void newqad(bool shutup) // Check for game.condition newcnd(); // And finally the stars - for (i = 1; i <= here->stars; i++) + for (i = 1; i <= q->stars; i++) dropin(IHSTAR, &w); // Check for RNZ - if (game.irhere > 0 && game.klhere == 0 && (here->planet == NOPLANET || game.state.plnets[here->planet].inhabited == UNINHABITED)) { + if (game.irhere > 0 && game.klhere == 0 && (q->planet == NOPLANET || game.state.plnets[q->planet].inhabited == UNINHABITED)) { game.neutz = 1; if (!damaged(DRADIO)) { skip(1); @@ -725,7 +725,7 @@ void newqad(bool shutup) game.tholian.y = Rand() > 0.5 ? QUADSIZE : 1; } while (game.quad[game.tholian.x][game.tholian.y] != IHDOT); game.quad[game.tholian.x][game.tholian.y] = IHT; - game.ithere = 1; + game.ithere = true; game.nenhere++; game.ks[game.nenhere].x = game.tholian.x; game.ks[game.nenhere].y = game.tholian.y; diff --git a/src/sst.c b/src/sst.c index 6d440f9..16199e6 100644 --- a/src/sst.c +++ b/src/sst.c @@ -175,7 +175,7 @@ static char line[128], *linep = line; struct game game; coord thing; -int iqhere, iqengry; +bool iqhere, iqengry; int iscore, iskill; // Common PLAQ double aaitem; double perdate; diff --git a/src/sst.h b/src/sst.h index a1b8b5e..1c40d1b 100644 --- a/src/sst.h +++ b/src/sst.h @@ -210,7 +210,11 @@ struct game { alive, // we are alive (not killed) justin, // just entered quadrant shldup, // shields are up + ishere, // super-commander in quadrant + ientesc, // attempted escape from supercommander + ithere, // Tholian is here resting, // rest time + icraft, // Kirk in Galileo alldone, // game is now finished neutz, // Romulan Neutral Zone isarmed, // probe is armed @@ -240,17 +244,13 @@ struct game { iplnet, // planet # in quadrant inplan, // initial planets nenhere, // number of enemies in quadrant - ishere, // super-commander in quandrant irhere, // Romulans in quadrant - icraft, // Kirk in Galileo - ientesc, // attempted escape from supercommander iscraft, // =1 if craft on ship, -1 if removed from game isatb, // =1 if super commander is attacking base iscate, // super commander is here iattak, // attack recursion elimination (was cracks[4]) icrystl, // dilithium crystals aboard tourn, // tournament number - ithere, // Tholian is here iseenit, // seen base attack report proben, // number of moves for probe nprobes; // number of probes available @@ -292,7 +292,7 @@ extern FILE *logfp, *replayfp; /* the Space Thingy's global state should *not* be saved! */ extern coord thing; -extern int iqhere, iqengry; +extern bool iqhere, iqengry; typedef enum {FWON, FDEPLETE, FLIFESUP, FNRG, FBATTLE, FNEG3, FNOVA, FSNOVAED, FABANDN, FDILITHIUM,