From: Eric S. Raymond Date: Wed, 20 Sep 2006 05:18:07 +0000 (+0000) Subject: More boolean-chasing and coord applications. X-Git-Tag: 2.0~219 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=c0682ebb9ae828d035d59892a65e1849d85963b7;p=super-star-trek.git More boolean-chasing and coord applications. --- diff --git a/src/ai.c b/src/ai.c index 889aafe..1fd1b9b 100644 --- a/src/ai.c +++ b/src/ai.c @@ -1,19 +1,19 @@ #include "sst.h" -static bool tryexit(int lookx, int looky, int ienm, int loccom, int irun) +static bool tryexit(coord look, int ienm, int loccom, bool irun) /* a bad guy attempts to bug out */ { int n; coord iq; - iq.x = game.quadrant.x+(lookx+(QUADSIZE-1))/QUADSIZE - 1; - iq.y = game.quadrant.y+(looky+(QUADSIZE-1))/QUADSIZE - 1; + iq.x = game.quadrant.x+(look.x+(QUADSIZE-1))/QUADSIZE - 1; + iq.y = game.quadrant.y+(look.y+(QUADSIZE-1))/QUADSIZE - 1; if (!VALID_QUADRANT(iq.x,iq.y) || game.state.galaxy[iq.x][iq.y].supernova || game.state.galaxy[iq.x][iq.y].klingons > 8) return false; /* no can do -- neg energy, supernovae, or >8 Klingons */ if (ienm == IHR) return false; /* Romulans cannot escape! */ - if (irun == 0) { + if (!irun) { /* avoid intruding on another commander's territory */ if (ienm == IHC) { for_commanders(n) @@ -60,7 +60,7 @@ static bool tryexit(int lookx, int looky, int ienm, int loccom, int irun) break; } } - game.comhere = 0; + game.comhere = false; } return true; /* success */ } @@ -69,11 +69,10 @@ static bool tryexit(int lookx, int looky, int ienm, int loccom, int irun) static void movebaddy(coord com, int loccom, int ienm) /* tactical movement for the bad guys */ { - int motion, mdist, nsteps, mx, my, lookx, looky, ll; - coord next; - int irun = 0; + int motion, mdist, nsteps, mx, my, ll; + coord next, look; int krawlx, krawly; - bool success; + bool success, irun = false; int attempts; /* This should probably be just game.comhere + game.ishere */ int nbaddys = game.skill >= SKILL_EXPERT ? @@ -87,7 +86,7 @@ static void movebaddy(coord com, int loccom, int ienm) /* If SC, check with spy to see if should hi-tail it */ if (ienm==IHS && (game.kpower[loccom] <= 500.0 || (game.condit==IHDOCKED && !damaged(DPHOTON)))) { - irun = 1; + irun = true; motion = -QUADSIZE; } else { @@ -183,40 +182,40 @@ static void movebaddy(coord com, int loccom, int ienm) if (idebug) proutn(" %d", ll+1); /* Check if preferred position available */ - lookx = next.x + mx; - looky = next.y + my; + look.x = next.x + mx; + look.y = next.y + my; krawlx = mx < 0 ? 1 : -1; krawly = my < 0 ? 1 : -1; success = false; attempts = 0; /* Settle mysterious hang problem */ while (attempts++ < 20 && !success) { - if (lookx < 1 || lookx > QUADSIZE) { - if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun)) + if (look.x < 1 || look.x > QUADSIZE) { + if (motion < 0 && tryexit(look, ienm, loccom, irun)) return; if (krawlx == mx || my == 0) break; - lookx = next.x + krawlx; + look.x = next.x + krawlx; krawlx = -krawlx; } - else if (looky < 1 || looky > QUADSIZE) { - if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun)) + else if (look.y < 1 || look.y > QUADSIZE) { + if (motion < 0 && tryexit(look, ienm, loccom, irun)) return; if (krawly == my || mx == 0) break; - looky = next.y + krawly; + look.y = next.y + krawly; krawly = -krawly; } - else if ((game.options & OPTION_RAMMING) && game.quad[lookx][looky] != IHDOT) { + else if ((game.options & OPTION_RAMMING) && game.quad[look.x][look.y] != IHDOT) { /* See if we should ram ship */ - if (game.quad[lookx][looky] == game.ship && + if (game.quad[look.x][look.y] == game.ship && (ienm == IHC || ienm == IHS)) { ram(true, ienm, com); return; } if (krawlx != mx && my != 0) { - lookx = next.x + krawlx; + look.x = next.x + krawlx; krawlx = -krawlx; } else if (krawly != my && mx != 0) { - looky = next.y + krawly; + look.y = next.y + krawly; krawly = -krawly; } else break; /* we have failed */ @@ -224,8 +223,7 @@ static void movebaddy(coord com, int loccom, int ienm) else success = true; } if (success) { - next.x = lookx; - next.y = looky; + next = look; if (idebug) proutn(cramlc(neither, next)); } @@ -237,10 +235,9 @@ static void movebaddy(coord com, int loccom, int ienm) /* Put commander in place within same quadrant */ game.quad[com.x][com.y] = IHDOT; game.quad[next.x][next.y] = ienm; - if (next.x != com.x || next.y != com.y) { + if (!same(next, com)) { /* it moved */ - game.ks[loccom].x = next.x; - game.ks[loccom].y = next.y; + game.ks[loccom] = next; game.kdist[loccom] = game.kavgd[loccom] = distance(game.sector, next); if (!damaged(DSRSENS) || game.condit == IHDOCKED) { proutn("***"); @@ -485,14 +482,14 @@ void scom(bool *ipage) if (same(ibq, game.state.kscmdr) && same(game.state.kscmdr, game.battle)) { /* attack the base */ if (flag) return; /* no, don't attack base! */ - game.iseenit = 0; + game.iseenit = false; game.isatb = 1; schedule(FSCDBAS, 1.0 +2.0*Rand()); if (is_scheduled(FCDBAS)) postpone(FSCDBAS, scheduled(FCDBAS)-game.state.date); if (damaged(DRADIO) && game.condit != IHDOCKED) return; /* no warning */ - game.iseenit = 1; + game.iseenit = true; if (*ipage == 0) pause_game(1); *ipage=1; proutn(_("Lt. Uhura- \"Captain, the starbase in ")); @@ -586,7 +583,6 @@ void movetho(void) crmena(true, IHT, sector, game.tholian); prout(_(" completes web.")); game.ithere = false; - game.tholian.x = game.tholian.y = 0; game.nenhere--; return; } diff --git a/src/battle.c b/src/battle.c index 69abfaa..ca77cd4 100644 --- a/src/battle.c +++ b/src/battle.c @@ -390,7 +390,6 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) if (h1 >= 600) { game.quad[w.x][w.y] = IHDOT; game.ithere = false; - game.tholian.x = game.tholian.y = 0; deadkl(w, iquad, w); return; } @@ -403,7 +402,6 @@ void torpedo(double course, double r, coord in, double *hit, int i, int n) prout(_(" disappears.")); game.quad[w.x][w.y] = IHWEB; game.ithere = false; - game.tholian.x = game.tholian.y = 0; game.nenhere--; dropin(IHBLANK); return; @@ -488,7 +486,7 @@ void attack(bool torps_ok) if (game.ithere) movetho(); if (game.neutz) { /* The one chance not to be attacked */ - game.neutz = 0; + game.neutz = false; return; } if ((((game.comhere || game.ishere) && !game.justin) || game.skill == SKILL_EMERITUS) && torps_ok) movcom(); @@ -645,7 +643,7 @@ void deadkl(coord w, int type, coord mv) game.klhere--; switch (type) { case IHC: - game.comhere = 0; + game.comhere = false; for_commanders (i) if (game.state.kcmdr[i].x==game.quadrant.x && game.state.kcmdr[i].y==game.quadrant.y) break; game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom]; diff --git a/src/events.c b/src/events.c index 8fed80a..20decb9 100644 --- a/src/events.c +++ b/src/events.c @@ -141,9 +141,9 @@ void events(void) prout(_("Lt. Uhura- \"Captain, the sub-space radio is working and")); prout(_(" surveillance reports are coming in.")); skip(1); - if (game.iseenit==0) { + if (!game.iseenit) { attakreport(false); - game.iseenit = 1; + game.iseenit = true; } rechart(); prout(_(" The star chart is now up to date.\"")); @@ -283,10 +283,10 @@ void events(void) if (game.isatb) /* extra time if SC already attacking */ postpone(FCDBAS, scheduled(FSCDBAS)-game.state.date); game.future[FBATTAK].date = game.future[FCDBAS].date + expran(0.3*game.intime); - game.iseenit = 0; + game.iseenit = false; if (!damaged(DRADIO) && game.condit != IHDOCKED) break; /* No warning :-( */ - game.iseenit = 1; + game.iseenit = true; if (!ipage) pause_game(1); ipage = true; skip(1); diff --git a/src/finish.c b/src/finish.c index ac21d07..95c7d97 100644 --- a/src/finish.c +++ b/src/finish.c @@ -142,7 +142,7 @@ void finish(FINTYPE ifin) proutn(_("Do you want your Commodore Emeritus Citation printed? ")); chew(); if (ja() == true) { - igotit = 1; + igotit = true; } } } @@ -152,7 +152,7 @@ void finish(FINTYPE ifin) prout(_("LIVE LONG AND PROSPER.")); } score(); - if (igotit != 0) plaque(); + if (igotit) plaque(); return; case FDEPLETE: // Federation Resources Depleted prout(_("Your time has run out and the Federation has been")); diff --git a/src/moving.c b/src/moving.c index 11142a3..e7e90af 100644 --- a/src/moving.c +++ b/src/moving.c @@ -233,11 +233,11 @@ void dock(bool verbose) game.lsupres = game.inlsr; game.state.crew = FULLCREW; if (!damaged(DRADIO) && - (is_scheduled(FCDBAS) || game.isatb == 1) && game.iseenit == 0) { + (is_scheduled(FCDBAS) || game.isatb == 1) && !game.iseenit) { /* get attack report from base */ prout(_("Lt. Uhura- \"Captain, an important message from the starbase:\"")); attakreport(false); - game.iseenit = 1; + game.iseenit = true; } } @@ -774,7 +774,8 @@ void atover(bool igrab) void timwrp() /* let's do the time warp again */ { - int l, gotit; + int l; + bool gotit; prout(_("***TIME WARP ENTERED.")); if (game.state.snap && Rand() < 0.5) { /* Go back in time */ @@ -798,10 +799,10 @@ void timwrp() /* Make sure Galileo is consistant -- Snapshot may have been taken when on planet, which would give us two Galileos! */ - gotit = 0; + gotit = false; for (l = 0; l < game.inplan; l++) { if (game.state.plnets[l].known == shuttle_down) { - gotit = 1; + gotit = true; if (game.iscraft==1 && game.ship==IHE) { prout(_("Checkov- \"Security reports the Galileo has disappeared, Sir!")); game.iscraft = 0; @@ -810,7 +811,7 @@ void timwrp() } /* Likewise, if in the original time the Galileo was abandoned, but was on ship earlier, it would have vanished -- lets restore it */ - if (game.iscraft==0 && gotit==0 && game.damage[DSHUTTL] >= 0.0) { + if (game.iscraft==0 && !gotit && game.damage[DSHUTTL] >= 0.0) { prout(_("Checkov- \"Security reports the Galileo has reappeared in the dock!\"")); game.iscraft = 1; } diff --git a/src/reports.c b/src/reports.c index 57297f5..ac41cd8 100644 --- a/src/reports.c +++ b/src/reports.c @@ -75,7 +75,7 @@ void report(void) /* Don't report this if not seen and either the radio is dead or not at base! */ attakreport(false); - game.iseenit = 1; + game.iseenit = true; } if (game.casual) prout(_("%d casualt%s suffered so far."), game.casual, game.casual==1? "y" : "ies"); diff --git a/src/setup.c b/src/setup.c index f6a0ae1..aa55bbe 100644 --- a/src/setup.c +++ b/src/setup.c @@ -607,7 +607,7 @@ void newqad(bool shutup) game.justin = true; game.base.x = game.base.y = 0; game.klhere = 0; - game.comhere = 0; + game.comhere = false; game.plnet.x = game.plnet.y = 0; game.ishere = false; game.irhere = 0; @@ -620,7 +620,7 @@ void newqad(bool shutup) game.ithere = false; iqhere = false; iqengry = false; - game.iseenit = 0; + game.iseenit = false; if (game.iscate) { // Attempt to escape Super-commander, so tbeam back! game.iscate = 0; @@ -654,7 +654,7 @@ void newqad(bool shutup) if (i <= game.state.remcom) { game.quad[w.x][w.y] = IHC; game.kpower[game.klhere] = 950.0+400.0*Rand()+50.0*game.skill; - game.comhere = 1; + game.comhere = true; } // If we need a super-commander, promote a Klingon @@ -692,7 +692,7 @@ void newqad(bool shutup) // Check for RNZ if (game.irhere > 0 && game.klhere == 0 && (q->planet == NOPLANET || game.state.plnets[q->planet].inhabited == UNINHABITED)) { - game.neutz = 1; + game.neutz = true; if (!damaged(DRADIO)) { skip(1); prout("LT. Uhura- \"Captain, an urgent message."); @@ -735,8 +735,7 @@ void newqad(bool shutup) game.quad[game.tholian.x][game.tholian.y] = IHT; game.ithere = true; game.nenhere++; - game.ks[game.nenhere].x = game.tholian.x; - game.ks[game.nenhere].y = game.tholian.y; + game.ks[game.nenhere] = game.tholian; game.kdist[game.nenhere] = game.kavgd[game.nenhere] = distance(game.sector, game.tholian); game.kpower[game.nenhere] = Rand()*400.0 +100.0 +25.0*game.skill; diff --git a/src/sst.c b/src/sst.c index cef3f7a..ba9bef7 100644 --- a/src/sst.c +++ b/src/sst.c @@ -403,7 +403,7 @@ static void makemoves(void) drawmaps(1); for(;;) { /* get a command */ hitme = false; - game.justin = 0; + game.justin = false; game.optime = 0.0; i = -1; chew(); diff --git a/src/sst.h b/src/sst.h index 9aaf5a5..211f63c 100644 --- a/src/sst.h +++ b/src/sst.h @@ -212,6 +212,7 @@ struct game { alive, // we are alive (not killed) justin, // just entered quadrant shldup, // shields are up + comhere, // commander here ishere, // super-commander in quadrant ientesc, // attempted escape from supercommander ithere, // Tholian is here @@ -223,6 +224,7 @@ struct game { inorbit, // orbiting a planet imine, // mining icrystl, // dilithium crystals aboard + iseenit, // seen base attack report thawed; // thawed game int inkling, // initial number of klingons inbase, // initial number of bases @@ -238,7 +240,6 @@ struct game { length, // length of game skill, // skill level klhere, // klingons here - comhere, // commanders here casual, // causalties nhelp, // calls for help nkinks, // count of energy-barrier crossings @@ -253,7 +254,6 @@ struct game { iscate, // super commander is here iattak, // attack recursion elimination (was cracks[4]) tourn, // tournament number - iseenit, // seen base attack report proben, // number of moves for probe nprobes; // number of probes available double inresor, // initial resources