From: Eric S. Raymond Date: Mon, 1 Nov 2004 00:43:25 +0000 (+0000) Subject: Magic-constent elimination (use an enum instead. X-Git-Tag: 2.0~452 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=02f05de93d48d0147cfffbb8e55ca7776ca09797;p=super-star-trek.git Magic-constent elimination (use an enum instead. --- diff --git a/moving.c b/moving.c index 2fdefb6..26011bf 100644 --- a/moving.c +++ b/moving.c @@ -765,7 +765,7 @@ void timwrp() { when on planet, which would give us two Galileos! */ gotit = 0; for (l = 1; l <= inplan; l++) { - if (game.state.plnets[l].known == 2) { + if (game.state.plnets[l].known == shuttle_down) { gotit = 1; if (iscraft==1 && ship==IHE) { prout("Checkov- \"Security reports the Galileo has disappeared, Sir!"); diff --git a/planets.c b/planets.c index b95761f..a98235f 100644 --- a/planets.c +++ b/planets.c @@ -32,14 +32,14 @@ void preport(void) { prout("Spock- \"Planet report follows, Captain.\""); skip(1); for (i = 1; i <= inplan; i++) { - if (game.state.plnets[i].known + if (game.state.plnets[i].known != unknown #ifdef DEBUG || ( idebug && game.state.plnets[i].x !=0) #endif ) { iknow = 1; #ifdef DEBUG - if (idebug && game.state.plnets[i].known==0) proutn("(Unknown) "); + if (idebug && game.state.plnets[i].known==unknown) proutn("(Unknown) "); #endif cramlc(1, game.state.plnets[i].x, game.state.plnets[i].y); proutn(" class "); @@ -47,7 +47,7 @@ void preport(void) { proutn(" "); if (game.state.plnets[i].crystals == 0) proutn("no "); prout("dilithium crystals present."); - if (game.state.plnets[i].known==2) + if (game.state.plnets[i].known==shuttle_down) prout(" Shuttle Craft Galileo on surface."); } } @@ -104,12 +104,12 @@ void sensor(void) { proutn(" is of class "); proutn(classes[game.state.plnets[iplnet].pclass]); prout("."); - if (game.state.plnets[iplnet].known==2) + if (game.state.plnets[iplnet].known==shuttle_down) prout(" Sensors show Galileo still on surface."); proutn(" Readings indicate"); if (game.state.plnets[iplnet].crystals == 0) proutn(" no"); prout(" dilithium crystals present.\""); - if (game.state.plnets[iplnet].known == 0) game.state.plnets[iplnet].known = 1; + if (game.state.plnets[iplnet].known == unknown) game.state.plnets[iplnet].known = known; return; } @@ -118,7 +118,7 @@ void beam(void) { skip(1); if (game.damage[DTRANSP] != 0) { prout("Transporter damaged."); - if (game.damage[DSHUTTL]==0 && (game.state.plnets[iplnet].known==2 || iscraft == 1)) { + if (game.damage[DSHUTTL]==0 && (game.state.plnets[iplnet].known==shuttle_down || iscraft == 1)) { skip(1); prout("Spock- \"May I suggest the shuttle craft, Sir?\" "); if (ja() != 0) shuttle(); @@ -134,7 +134,7 @@ void beam(void) { prout("Impossible to transport through shields."); return; } - if (game.state.plnets[iplnet].known==0) { + if (game.state.plnets[iplnet].known==unknown) { prout("Spock- \"Captain, we have no information on this planet"); prout(" and Starfleet Regulations clearly state that in this situation"); prout(" you may not go down.\""); @@ -142,7 +142,7 @@ void beam(void) { } if (landed==1) { /* Coming from planet */ - if (game.state.plnets[iplnet].known==2) { + if (game.state.plnets[iplnet].known==shuttle_down) { proutn("Spock- \"Wouldn't you rather take the Galileo?\" "); if (ja() != 0) { chew(); @@ -188,7 +188,7 @@ void beam(void) { skip(2); prout("Transport complete."); landed = -landed; - if (landed==1 && game.state.plnets[iplnet].known==2) { + if (landed==1 && game.state.plnets[iplnet].known==shuttle_down) { prout("The shuttle craft Galileo is here!"); } if (landed!=1 && imine==1) { @@ -287,7 +287,7 @@ void shuttle(void) { ididit = 0; if(game.damage[DSHUTTL] != 0.0) { if (game.damage[DSHUTTL] == -1.0) { - if (inorbit && game.state.plnets[iplnet].known == 2) + if (inorbit && game.state.plnets[iplnet].known == shuttle_down) prout("Ye Faerie Queene has no shuttle craft bay to dock it at."); else prout("Ye Faerie Queene had no shuttle craft."); @@ -302,11 +302,11 @@ void shuttle(void) { prout(" not in standard orbit."); return; } - if ((game.state.plnets[iplnet].known != 2) && iscraft != 1) { + if ((game.state.plnets[iplnet].known != shuttle_down) && iscraft != 1) { prout("Shuttle craft not currently available."); return; } - if (landed==-1 && game.state.plnets[iplnet].known==2) { + if (landed==-1 && game.state.plnets[iplnet].known==shuttle_down) { prout("You will have to beam down to retrieve the shuttle craft."); return; } @@ -314,7 +314,7 @@ void shuttle(void) { prout("Shuttle craft cannot pass through shields."); return; } - if (game.state.plnets[iplnet].known==0) { + if (game.state.plnets[iplnet].known==unknown) { prout("Spock- \"Captain, we have no information on this planet"); prout(" and Starfleet Regulations clearly state that in this situation"); prout(" you may not fly down.\""); @@ -351,7 +351,7 @@ void shuttle(void) { iscraft = 0; skip(1); if (consumeTime()) return; - game.state.plnets[iplnet].known=2; + game.state.plnets[iplnet].known=shuttle_down; prout("Trip complete."); return; } @@ -361,7 +361,7 @@ void shuttle(void) { prout("shuttle craft for the trip back to the Enterprise."); skip(1); prout("The short hop begins . . ."); - game.state.plnets[iplnet].known=1; + game.state.plnets[iplnet].known=known; icraft = 1; skip(1); landed = -1; @@ -388,7 +388,7 @@ void shuttle(void) { icraft = 1; iscraft = 0; if (consumeTime()) return; - game.state.plnets[iplnet].known = 2; + game.state.plnets[iplnet].known = shuttle_down; landed = 1; icraft = 0; prout("Trip complete"); diff --git a/setup.c b/setup.c index 9b5ac42..6b24e06 100644 --- a/setup.c +++ b/setup.c @@ -306,7 +306,7 @@ void setup(void) { game.state.plnets[i].y = iy; game.state.plnets[i].pclass = Rand()*3.0 + 1.0; // Planet class M N or O game.state.plnets[i].crystals = 1.5*Rand(); // 1 in 3 chance of crystals - game.state.plnets[i].known = 0; + game.state.plnets[i].known = unknown; } // Locate Romulans for (i = 1; i <= game.state.nromrem; i++) { diff --git a/sst.h b/sst.h index c93fbc5..5617ae3 100644 --- a/sst.h +++ b/sst.h @@ -16,11 +16,11 @@ #define NEVENTS (8) typedef struct { - int x; /* Quadrant location of planet */ - int y; - int pclass; /* class M, N, or O (1, 2, or 3) */ - int crystals; /* has crystals */ - int known; /* =1 contents known, =2 shuttle on this planet */ + int x; /* Quadrant location of planet */ + int y; + int pclass; /* class M, N, or O (1, 2, or 3) */ + int crystals; /* has crystals */ + enum {unknown, known, shuttle_down} known; } planet; typedef struct { @@ -54,7 +54,7 @@ typedef struct { // original names. Gee, I could have done this with the d structure, // but I just didn't think of it back when I started. -EXTERN struct foo2 { +EXTERN struct { snapshot state; snapshot snapsht; char quad[11][11]; // contents of our quadrant