Magic-constent elimination (use an enum instead.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 1 Nov 2004 00:43:25 +0000 (00:43 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 1 Nov 2004 00:43:25 +0000 (00:43 +0000)
moving.c
planets.c
setup.c
sst.h

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