Magic-number elimination.

This commit is contained in:
Eric S. Raymond 2017-06-28 17:07:15 -04:00
parent 1ed8126912
commit b5260417dd
3 changed files with 37 additions and 24 deletions

View file

@ -28,7 +28,8 @@ static int attack(FILE *input, struct command_t *command)
if (AT(DRAGON) && game.prop[DRAGON] == 0)obj = obj * NOBJECTS + DRAGON; if (AT(DRAGON) && game.prop[DRAGON] == 0)obj = obj * NOBJECTS + DRAGON;
if (AT(TROLL))obj = obj * NOBJECTS + TROLL; if (AT(TROLL))obj = obj * NOBJECTS + TROLL;
if (AT(OGRE))obj = obj * NOBJECTS + OGRE; if (AT(OGRE))obj = obj * NOBJECTS + OGRE;
if (HERE(BEAR) && game.prop[BEAR] == 0)obj = obj * NOBJECTS + BEAR; if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR)
obj = obj * NOBJECTS + BEAR;
if (obj > NOBJECTS) return GO_UNKNOWN; if (obj > NOBJECTS) return GO_UNKNOWN;
if (obj == 0) { if (obj == 0) {
/* Can't attack bird or machine by throwing axe. */ /* Can't attack bird or machine by throwing axe. */
@ -50,9 +51,8 @@ static int attack(FILE *input, struct command_t *command)
DESTROY(BIRD); DESTROY(BIRD);
spk = BIRD_DEAD; spk = BIRD_DEAD;
} else if (obj == VEND) { } else if (obj == VEND) {
bool blocking = (game.prop[VEND] == VEND_BLOCKS); state_change(VEND,
game.prop[VEND] = blocking ? VEND_UNBLOCKS : VEND_BLOCKS; game.prop[VEND]==VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
rspeak(blocking ? MACHINE_SWINGOUT : MACHINE_SWINGBACK);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
@ -230,8 +230,10 @@ static int vcarry(token_t verb, token_t obj)
} }
spk = YOU_JOKING; spk = YOU_JOKING;
if (obj == PLANT && game.prop[PLANT] <= 0)spk = DEEP_ROOTS; if (obj == PLANT && game.prop[PLANT] <= 0)spk = DEEP_ROOTS;
if (obj == BEAR && game.prop[BEAR] == 1)spk = BEAR_CHAINED; if (obj == BEAR && game.prop[BEAR] == SITTING_BEAR)
if (obj == CHAIN && game.prop[BEAR] != 0)spk = STILL_LOCKED; spk = BEAR_CHAINED;
if (obj == CHAIN && game.prop[BEAR] != UNTAMED_BEAR)
spk = STILL_LOCKED;
if (obj == URN)spk = URN_NOBUDGE; if (obj == URN)spk = URN_NOBUDGE;
if (obj == CAVITY)spk = DOUGHNUT_HOLES; if (obj == CAVITY)spk = DOUGHNUT_HOLES;
if (obj == BLOOD)spk = FEW_DROPS; if (obj == BLOOD)spk = FEW_DROPS;
@ -298,26 +300,33 @@ static int chain(token_t verb)
int spk; int spk;
if (verb != LOCK) { if (verb != LOCK) {
spk = CHAIN_UNLOCKED; spk = CHAIN_UNLOCKED;
if (game.prop[BEAR] == 0)spk = BEAR_BLOCKS; if (game.prop[BEAR] == UNTAMED_BEAR)
if (game.prop[CHAIN] == 0)spk = ALREADY_UNLOCKED; spk = BEAR_BLOCKS;
if (game.prop[CHAIN] == 0)
spk = ALREADY_UNLOCKED;
if (spk != CHAIN_UNLOCKED) { if (spk != CHAIN_UNLOCKED) {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
game.prop[CHAIN] = 0; game.prop[CHAIN] = 0;
game.fixed[CHAIN] = 0; game.fixed[CHAIN] = 0;
if (game.prop[BEAR] != 3)game.prop[BEAR] = 2; if (game.prop[BEAR] != BEAR_DEAD)
game.prop[BEAR] = CONTENTED_BEAR;
/* FIXME: Arithmetic on state numbers */
game.fixed[BEAR] = 2 - game.prop[BEAR]; game.fixed[BEAR] = 2 - game.prop[BEAR];
} else { } else {
spk = CHAIN_LOCKED; spk = CHAIN_LOCKED;
if (game.prop[CHAIN] != 0)spk = ALREADY_LOCKED; if (game.prop[CHAIN] != 0)
if (game.loc != objects[CHAIN].plac)spk = NO_LOCKSITE; spk = ALREADY_LOCKED;
if (game.loc != objects[CHAIN].plac)
spk = NO_LOCKSITE;
if (spk != CHAIN_LOCKED) { if (spk != CHAIN_LOCKED) {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
game.prop[CHAIN] = 2; game.prop[CHAIN] = 2;
if (TOTING(CHAIN))drop(CHAIN, game.loc); if (TOTING(CHAIN))
drop(CHAIN, game.loc);
game.fixed[CHAIN] = -1; game.fixed[CHAIN] = -1;
} }
rspeak(spk); rspeak(spk);
@ -492,11 +501,13 @@ static int feed(token_t verb, token_t obj)
spk = REALLY_MAD; spk = REALLY_MAD;
} }
} else if (obj == BEAR) { } else if (obj == BEAR) {
if (game.prop[BEAR] == 0)spk = NOTHING_EDIBLE; if (game.prop[BEAR] == UNTAMED_BEAR)
if (game.prop[BEAR] == 3)spk = RIDICULOUS_ATTEMPT; spk = NOTHING_EDIBLE;
if (game.prop[BEAR] == BEAR_DEAD)
spk = RIDICULOUS_ATTEMPT;
if (HERE(FOOD)) { if (HERE(FOOD)) {
DESTROY(FOOD); DESTROY(FOOD);
game.prop[BEAR] = 1; game.prop[BEAR] = SITTING_BEAR;
game.fixed[AXE] = 0; game.fixed[AXE] = 0;
game.prop[AXE] = 0; game.prop[AXE] = 0;
spk = BEAR_TAMED; spk = BEAR_TAMED;
@ -931,7 +942,7 @@ static int throw (FILE *cmdin, struct command_t *command)
return throw_support(TROLL_RETURNS); return throw_support(TROLL_RETURNS);
else if (AT(OGRE)) else if (AT(OGRE))
return throw_support(OGRE_DODGE); return throw_support(OGRE_DODGE);
else if (HERE(BEAR) && game.prop[BEAR] == 0) { else if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) {
/* This'll teach him to throw the axe at the bear! */ /* This'll teach him to throw the axe at the bear! */
drop(AXE, game.loc); drop(AXE, game.loc);
game.fixed[AXE] = -1; game.fixed[AXE] = -1;

View file

@ -2969,8 +2969,6 @@ arbitrary_messages: !!omap
- ADVENTURE_NEWS: 'Open Adventure is an author-approved open-source release of\nVersion 2.5 with, as yet, no gameplay changes.\nVersion 2.5 was essentially the same as Version II; the cave and the\nhazards therein are unchanged, and top score is still 430 points.\nThere are a few more hints, especially for some of the more obscure\npuzzles. There are a few minor bugfixes and cosmetic changes. You\ncan now save a game and resume it at once (formerly you had to wait a\nwhile first), but it now costs you a few points each time you save the\ngame. Saved games are now stored in much smaller files than before.' - ADVENTURE_NEWS: 'Open Adventure is an author-approved open-source release of\nVersion 2.5 with, as yet, no gameplay changes.\nVersion 2.5 was essentially the same as Version II; the cave and the\nhazards therein are unchanged, and top score is still 430 points.\nThere are a few more hints, especially for some of the more obscure\npuzzles. There are a few minor bugfixes and cosmetic changes. You\ncan now save a game and resume it at once (formerly you had to wait a\nwhile first), but it now costs you a few points each time you save the\ngame. Saved games are now stored in much smaller files than before.'
- GO_UNNEEDED: 'You don''t have to say "go" every time; just specify a direction or, if\nit''s nearby, name the place to which you wish to move.' - GO_UNNEEDED: 'You don''t have to say "go" every time; just specify a direction or, if\nit''s nearby, name the place to which you wish to move.'
- ARB_279: !!null - ARB_279: !!null
- MACHINE_SWINGOUT: 'As you strike the vending machine, it pivots backward along with a\nsection of wall, revealing a dark passage leading south.'
- MACHINE_SWINGBACK: 'The vending machine swings back to block the passage.'
classes: classes:
- threshold: 0 - threshold: 0
@ -3295,10 +3293,10 @@ objects: !!omap
locations: LOC_BARRENROOM locations: LOC_BARRENROOM
immovable: true immovable: true
descriptions: descriptions:
- 'There is a ferocious cave bear eying you from the far end of the room!' - [UNTAMED_BEAR, 'There is a ferocious cave bear eying you from the far end of the room!']
- 'There is a gentle cave bear sitting placidly in one corner.' - [SITTING_BEAR, 'There is a gentle cave bear sitting placidly in one corner.']
- 'There is a contented-looking bear wandering about nearby.' - [CONTENTED_BEAR, 'There is a contented-looking bear wandering about nearby.']
- '' # dead - [BEAR_DEAD, '']
- MESSAG: - MESSAG:
words: ['messa'] words: ['messa']
inventory: '*message in second maze' inventory: '*message in second maze'
@ -3322,6 +3320,9 @@ objects: !!omap
descriptions: descriptions:
- [VEND_BLOCKS, 'There is a massive and somewhat battered vending machine here. The\ninstructions on it read: "Drop coins here to receive fresh batteries."'] - [VEND_BLOCKS, 'There is a massive and somewhat battered vending machine here. The\ninstructions on it read: "Drop coins here to receive fresh batteries."']
- [VEND_UNBLOCKS, 'There is a massive vending machine here, swung back to reveal a\nsouthward passage.'] - [VEND_UNBLOCKS, 'There is a massive vending machine here, swung back to reveal a\nsouthward passage.']
changes:
- 'The vending machine swings back to block the passage.'
- 'As you strike the vending machine, it pivots backward along with a\nsection of wall, revealing a dark passage leading south.'
texts: texts:
- '"Drop coins here to receive fresh batteries."' - '"Drop coins here to receive fresh batteries."'
- '"Drop coins here to receive fresh batteries."' - '"Drop coins here to receive fresh batteries."'

5
main.c
View file

@ -717,7 +717,7 @@ static bool playermove(token_t verb, int motion)
game.prop[TROLL] = 2; game.prop[TROLL] = 2;
drop(BEAR, game.newloc); drop(BEAR, game.newloc);
game.fixed[BEAR] = -1; game.fixed[BEAR] = -1;
game.prop[BEAR] = 3; game.prop[BEAR] = BEAR_DEAD;
game.oldlc2 = game.newloc; game.oldlc2 = game.newloc;
croak(); croak();
return true; return true;
@ -780,7 +780,8 @@ static bool closecheck(void)
move(TROLL2, objects[TROLL].plac); move(TROLL2, objects[TROLL].plac);
move(TROLL2 + NOBJECTS, objects[TROLL].fixd); move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
juggle(CHASM); juggle(CHASM);
if (game.prop[BEAR] != 3)DESTROY(BEAR); if (game.prop[BEAR] != BEAR_DEAD)
DESTROY(BEAR);
game.prop[CHAIN] = 0; game.prop[CHAIN] = 0;
game.fixed[CHAIN] = 0; game.fixed[CHAIN] = 0;
game.prop[AXE] = 0; game.prop[AXE] = 0;