Magic-number elimination for dragon and rug.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 1 Jul 2017 13:58:45 +0000 (09:58 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 1 Jul 2017 14:01:39 +0000 (10:01 -0400)
actions.c
adventure.yaml

index e3768d91af9f4567e3186f188b239e9ca7b6fd92..567d67ad66621cb1ef9c8dffa2306f96c0db7f8d 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -121,9 +121,9 @@ static int attack(struct command_t *command)
             command->wd1 = token_to_packed("N");
             return GO_CHECKFOO;
         }
             command->wd1 = token_to_packed("N");
             return GO_CHECKFOO;
         }
-        pspeak(DRAGON, look, 3);
-        game.prop[DRAGON] = 1;
-        game.prop[RUG] = 0;
+        state_change(DRAGON, DRAGON_DEAD);
+        game.prop[RUG] = RUG_FLOOR;
+       /* FIXME: Arithmentic on location values */
         int k = (objects[DRAGON].plac + objects[DRAGON].fixd) / 2;
         move(DRAGON + NOBJECTS, -1);
         move(RUG + NOBJECTS, 0);
         int k = (objects[DRAGON].plac + objects[DRAGON].fixd) / 2;
         move(DRAGON + NOBJECTS, -1);
         move(RUG + NOBJECTS, 0);
@@ -284,7 +284,7 @@ static int vcarry(token_t verb, token_t obj)
         spk = DOUGHNUT_HOLES;
     if (obj == BLOOD)
         spk = FEW_DROPS;
         spk = DOUGHNUT_HOLES;
     if (obj == BLOOD)
         spk = FEW_DROPS;
-    if (obj == RUG && game.prop[RUG] == 2)
+    if (obj == RUG && game.prop[RUG] == RUG_HOVER)
         spk = RUG_HOVERS;
     if (obj == SIGN)
         spk = HAND_PASSTHROUGH;
         spk = RUG_HOVERS;
     if (obj == SIGN)
         spk = HAND_PASSTHROUGH;
@@ -410,8 +410,8 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
             rspeak(GEM_FITS);
             game.prop[obj] = 1;
             game.prop[CAVITY] = CAVITY_FULL;
             rspeak(GEM_FITS);
             game.prop[obj] = 1;
             game.prop[CAVITY] = CAVITY_FULL;
-            if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != 2) || (obj == RUBY &&
-                              game.prop[RUG] == 2))) {
+            if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) || (obj == RUBY &&
+                              game.prop[RUG] == RUG_HOVER))) {
                 spk = RUG_RISES;
                 if (TOTING(RUG))
                     spk = RUG_WIGGLES;
                 spk = RUG_RISES;
                 if (TOTING(RUG))
                     spk = RUG_WIGGLES;
@@ -419,6 +419,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
                     spk = RUG_SETTLES;
                 rspeak(spk);
                 if (spk != RUG_WIGGLES) {
                     spk = RUG_SETTLES;
                 rspeak(spk);
                 if (spk != RUG_WIGGLES) {
+                   /* FIXME: Arithmetic on state numbers */
                     int k = 2 - game.prop[RUG];
                     game.prop[RUG] = k;
                     if (k == 2)
                     int k = 2 - game.prop[RUG];
                     game.prop[RUG] = k;
                     if (k == 2)
@@ -485,13 +486,12 @@ static int drink(token_t verb, token_t obj)
             game.place[WATER] = LOC_NOWHERE;
             spk = BOTTLE_EMPTY;
         }
             game.place[WATER] = LOC_NOWHERE;
             spk = BOTTLE_EMPTY;
         }
+       rspeak(spk);
     } else {
         DESTROY(BLOOD);
     } else {
         DESTROY(BLOOD);
-        game.prop[DRAGON] = 2;
+        state_change(DRAGON, DRAGON_BLOODLESS);
         game.blooded = true;
         game.blooded = true;
-        spk = HEAD_BUZZES;
     }
     }
-    rspeak(spk);
     return GO_CLEAROBJ;
 }
 
     return GO_CLEAROBJ;
 }
 
@@ -673,7 +673,7 @@ static int fly(token_t verb, token_t obj)
 {
     int spk = actions[verb].message;
     if (obj == INTRANSITIVE) {
 {
     int spk = actions[verb].message;
     if (obj == INTRANSITIVE) {
-        if (game.prop[RUG] != 2)
+        if (game.prop[RUG] != RUG_HOVER)
             spk = RUG_NOTHING2;
         if (!HERE(RUG))
             spk = FLAP_ARMS;
             spk = RUG_NOTHING2;
         if (!HERE(RUG))
             spk = FLAP_ARMS;
@@ -689,12 +689,13 @@ static int fly(token_t verb, token_t obj)
         return GO_CLEAROBJ;
     }
     spk = RUG_NOTHING1;
         return GO_CLEAROBJ;
     }
     spk = RUG_NOTHING1;
-    if (game.prop[RUG] != 2) {
+    if (game.prop[RUG] != RUG_HOVER) {
         rspeak(spk);
         return GO_CLEAROBJ;
     }
     game.oldlc2 = game.oldloc;
     game.oldloc = game.loc;
         rspeak(spk);
         return GO_CLEAROBJ;
     }
     game.oldlc2 = game.oldloc;
     game.oldloc = game.loc;
+    /* FIXME: Arithmetic on location values */
     game.newloc = game.place[RUG] + game.fixed[RUG] - game.loc;
     spk = RUG_GOES;
     if (game.prop[SAPPH] >= 0)
     game.newloc = game.place[RUG] + game.fixed[RUG] - game.loc;
     spk = RUG_GOES;
     if (game.prop[SAPPH] >= 0)
index ed482e2208793c23fc5fcf88975e63b77b1416ec..943b78f204ade66a218e393afec99c93089abda3 100644 (file)
@@ -1425,7 +1425,7 @@ locations: !!omap
     conditions: {DEEP: true}
     travel: [
       {verbs: ['D', 'SLAB'], action: [goto, LOC_SLAB]},
     conditions: {DEEP: true}
     travel: [
       {verbs: ['D', 'SLAB'], action: [goto, LOC_SLAB]},
-      {verbs: ['SOUTH'], cond: [not, DRAGON, DRAGON_BLOCKS],
+      {verbs: ['SOUTH'], cond: [not, DRAGON, DRAGON_BARS],
                          action: [goto, LOC_SECRET5]},
       {verbs: ['SOUTH'], action: [goto, LOC_SECRET4]},
       {verbs: ['NORTH'], action: [goto, LOC_MIRRORCANYON]},
                          action: [goto, LOC_SECRET5]},
       {verbs: ['SOUTH'], action: [goto, LOC_SECRET4]},
       {verbs: ['NORTH'], action: [goto, LOC_MIRRORCANYON]},
@@ -1483,7 +1483,7 @@ locations: !!omap
     conditions: {DEEP: true}
     travel: [
       {verbs: ['EAST'], action: [goto, LOC_KINGHALL]},
     conditions: {DEEP: true}
     travel: [
       {verbs: ['EAST'], action: [goto, LOC_KINGHALL]},
-      {verbs: ['WEST'], cond: [not, DRAGON, DRAGON_BLOCKS], action: [goto, LOC_SECRET5]},
+      {verbs: ['WEST'], cond: [not, DRAGON, DRAGON_BARS], action: [goto, LOC_SECRET5]},
       {verbs: ['WEST'], action: [goto, LOC_SECRET6]},
       {verbs: ['D'], action: [goto, LOC_WIDEPLACE]},
     ]
       {verbs: ['WEST'], action: [goto, LOC_SECRET6]},
       {verbs: ['D'], action: [goto, LOC_WIDEPLACE]},
     ]
@@ -3125,7 +3125,6 @@ arbitrary_messages:  !!omap
 - TOTAL_ROAR: 'The roaring is so loud that it drowns out all other sound.'
 - BIRD_CRAP: 'The bird eyes you suspiciously and flutters away.  A moment later you\nfeel something wet land on your head, but upon looking up you can see\nno sign of the culprit.'
 - FEW_DROPS: 'There are only a few drops--not enough to carry.'
 - TOTAL_ROAR: 'The roaring is so loud that it drowns out all other sound.'
 - BIRD_CRAP: 'The bird eyes you suspiciously and flutters away.  A moment later you\nfeel something wet land on your head, but upon looking up you can see\nno sign of the culprit.'
 - FEW_DROPS: 'There are only a few drops--not enough to carry.'
-- HEAD_BUZZES: 'Your head buzzes strangely for a moment.'
 - NOT_BRIGHT: '(Uh, y''know, that wasn''t very bright.)'
 - TOOK_LONG: 'It''s a pity you took so long about it.'
 - UPSTREAM_DOWNSTREAM: 'Upstream or downstream?'
 - NOT_BRIGHT: '(Uh, y''know, that wasn''t very bright.)'
 - TOOK_LONG: 'It''s a pity you took so long about it.'
 - UPSTREAM_DOWNSTREAM: 'Upstream or downstream?'
@@ -3443,10 +3442,15 @@ objects: !!omap
     locations: [LOC_SECRET4, LOC_SECRET6]
     immovable: true
     descriptions:
     locations: [LOC_SECRET4, LOC_SECRET6]
     immovable: true
     descriptions:
-    - [DRAGON_BLOCKS, 'A huge green fierce dragon bars the way!']
-    - 'The blood-specked body of a huge green dead dragon lies to one side.'
-    - 'The body of a huge green dead dragon is lying off to one side.'
-    - 'Congratulations!  You have just vanquished a dragon with your bare\nhands!  (Unbelievable, isn''t it?)'
+    - [DRAGON_BARS, 'A huge green fierce dragon bars the way!']
+    - [DRAGON_DEAD, 'The blood-specked body of a huge green dead dragon lies to one side.']
+    - [DRAGON_BLOODLESS, 'The body of a huge green dead dragon is lying off to one side.']
+    changes:
+    - ''
+    - |-
+        Congratulations!  You have just vanquished a dragon with your bare
+        hands!  (Unbelievable, isn't it?)
+    - 'Your head buzzes strangely for a moment.'
     sounds:
     - 'The dragon''s ominous hissing does not bode well for you.'
     - 'The dragon is, not surprisingly, silent.'
     sounds:
     - 'The dragon''s ominous hissing does not bode well for you.'
     - 'The dragon is, not surprisingly, silent.'
@@ -3703,9 +3707,9 @@ objects: !!omap
     immovable: true
     treasure: true
     descriptions:
     immovable: true
     treasure: true
     descriptions:
-    - 'There is a persian rug spread out on the floor!'
-    - 'The dragon is sprawled out on a persian rug!!'
-    - 'There is a persian rug here, hovering in mid-air!'
+    - [RUG_FLOOR, 'There is a persian rug spread out on the floor!']
+    - [RUG_DRAGON, 'The dragon is sprawled out on a persian rug!!']
+    - [RUG_HOVER, 'There is a persian rug here, hovering in mid-air!']
 - OBJ_63:
     words: ['spice']
     inventory: 'Rare spices'
 - OBJ_63:
     words: ['spice']
     inventory: 'Rare spices'