Magic-number elimination.

This commit is contained in:
Eric S. Raymond 2017-06-28 11:45:53 -04:00
parent eb89cd5b4e
commit f5719f1aba
3 changed files with 106 additions and 104 deletions

148
actions.c
View file

@ -1041,7 +1041,7 @@ int action(FILE *input, struct command_t *command)
} else if (command->obj == ROD && HERE(ROD2)) { } else if (command->obj == ROD && HERE(ROD2)) {
command->obj = ROD2; command->obj = ROD2;
/* FALL THROUGH */; /* FALL THROUGH */;
} else if ((command->verb == FIND || command->verb == INVENT) && command->wd2 <= 0) } else if ((command->verb == FIND || command->verb == INVENTORY) && command->wd2 <= 0)
/* FALL THROUGH */; /* FALL THROUGH */;
else { else {
rspeak(NO_SEE, command->wd1, command->wd1x); rspeak(NO_SEE, command->wd1, command->wd1x);
@ -1061,180 +1061,182 @@ int action(FILE *input, struct command_t *command)
if (command->verb == SAY)command->obj = command->wd2; if (command->verb == SAY)command->obj = command->wd2;
if (command->obj == 0 || command->obj == INTRANSITIVE) { if (command->obj == 0 || command->obj == INTRANSITIVE) {
/* Analyse an intransitive verb (ie, no object given yet). */ /* Analyse an intransitive verb (ie, no object given yet). */
switch (command->verb - 1) { switch (command->verb) {
case 0: /* CARRY */ case CARRY:
return vcarry(command->verb, INTRANSITIVE); return vcarry(command->verb, INTRANSITIVE);
case 1: /* DROP */ case DROP:
return GO_UNKNOWN; return GO_UNKNOWN;
case 2: /* SAY */ case SAY:
return GO_UNKNOWN; return GO_UNKNOWN;
case 3: /* UNLOC */ case UNLOCK:
return lock(command->verb, INTRANSITIVE); return lock(command->verb, INTRANSITIVE);
case 4: { /* NOTHI */ case NOTHING: {
rspeak(OK_MAN); rspeak(OK_MAN);
return (GO_CLEAROBJ); return (GO_CLEAROBJ);
} }
case 5: /* LOCK */ case LOCK:
return lock(command->verb, INTRANSITIVE); return lock(command->verb, INTRANSITIVE);
case 6: /* LIGHT */ case LIGHT:
return light(command->verb, INTRANSITIVE); return light(command->verb, INTRANSITIVE);
case 7: /* EXTIN */ case EXTINGUISH:
return extinguish(command->verb, INTRANSITIVE); return extinguish(command->verb, INTRANSITIVE);
case 8: /* WAVE */ case WAVE:
return GO_UNKNOWN; return GO_UNKNOWN;
case 9: /* CALM */ case TAME:
return GO_UNKNOWN; return GO_UNKNOWN;
case 10: { /* WALK */ case GO: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 11: /* ATTAC */ case ATTACK:
return attack(input, command); return attack(input, command);
case 12: /* POUR */ case POUR:
return pour(command->verb, command->obj); return pour(command->verb, command->obj);
case 13: /* EAT */ case EAT:
return eat(command->verb, INTRANSITIVE); return eat(command->verb, INTRANSITIVE);
case 14: /* DRINK */ case DRINK:
return drink(command->verb, command->obj); return drink(command->verb, command->obj);
case 15: /* RUB */ case RUB:
return GO_UNKNOWN; return GO_UNKNOWN;
case 16: /* TOSS */ case THROW:
return GO_UNKNOWN; return GO_UNKNOWN;
case 17: /* QUIT */ case QUIT:
return quit(); return quit();
case 18: /* FIND */ case FIND:
return GO_UNKNOWN; return GO_UNKNOWN;
case 19: /* INVEN */ case INVENTORY:
return inven(); return inven();
case 20: /* FEED */ case FEED:
return GO_UNKNOWN; return GO_UNKNOWN;
case 21: /* FILL */ case FILL:
return fill(command->verb, command->obj); return fill(command->verb, command->obj);
case 22: /* BLAST */ case BLAST:
blast(); blast();
return GO_CLEAROBJ; return GO_CLEAROBJ;
case 23: /* SCOR */ case SCORE:
score(scoregame); score(scoregame);
return GO_CLEAROBJ; return GO_CLEAROBJ;
case 24: /* FOO */ case GIANTWORDS:
return bigwords(command->wd1); return bigwords(command->wd1);
case 25: /* BRIEF */ case BRIEF:
return brief(); return brief();
case 26: /* READ */ case READ:
command->obj = INTRANSITIVE; command->obj = INTRANSITIVE;
return read(*command); return read(*command);
case 27: /* BREAK */ case BREAK:
return GO_UNKNOWN; return GO_UNKNOWN;
case 28: /* WAKE */ case WAKE:
return GO_UNKNOWN; return GO_UNKNOWN;
case 29: /* SUSP */ case SAVE:
return suspend(); return suspend();
case 30: /* RESU */ case RESUME:
return resume(); return resume();
case 31: /* FLY */ case FLY:
return fly(command->verb, INTRANSITIVE); return fly(command->verb, INTRANSITIVE);
case 32: /* LISTE */ case LISTEN:
return listen(); return listen();
case 33: /* ZZZZ */ case PART:
return reservoir(); return reservoir();
default:
BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST);
} }
BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST);
} }
/* FALLTHRU */ /* FALLTHRU */
case transitive: case transitive:
/* Analyse a transitive verb. */ /* Analyse a transitive verb. */
switch (command->verb - 1) { switch (command->verb) {
case 0: /* CARRY */ case CARRY:
return vcarry(command->verb, command->obj); return vcarry(command->verb, command->obj);
case 1: /* DROP */ case DROP:
return discard(command->verb, command->obj, false); return discard(command->verb, command->obj, false);
case 2: /* SAY */ case SAY:
return say(command); return say(command);
case 3: /* UNLOC */ case UNLOCK:
return lock(command->verb, command->obj); return lock(command->verb, command->obj);
case 4: { /* NOTHI */ case NOTHING: {
rspeak(OK_MAN); rspeak(OK_MAN);
return (GO_CLEAROBJ); return (GO_CLEAROBJ);
} }
case 5: /* LOCK */ case LOCK:
return lock(command->verb, command->obj); return lock(command->verb, command->obj);
case 6: /* LIGHT */ case LIGHT:
return light(command->verb, command->obj); return light(command->verb, command->obj);
case 7: /* EXTI */ case EXTINGUISH:
return extinguish(command->verb, command->obj); return extinguish(command->verb, command->obj);
case 8: /* WAVE */ case WAVE:
return wave(command->verb, command->obj); return wave(command->verb, command->obj);
case 9: { /* CALM */ case TAME: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 10: { /* WALK */ case GO: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 11: /* ATTAC */ case ATTACK:
return attack(input, command); return attack(input, command);
case 12: /* POUR */ case POUR:
return pour(command->verb, command->obj); return pour(command->verb, command->obj);
case 13: /* EAT */ case EAT:
return eat(command->verb, command->obj); return eat(command->verb, command->obj);
case 14: /* DRINK */ case DRINK:
return drink(command->verb, command->obj); return drink(command->verb, command->obj);
case 15: /* RUB */ case RUB:
return rub(command->verb, command->obj); return rub(command->verb, command->obj);
case 16: /* TOSS */ case THROW:
return throw(input, command); return throw(input, command);
case 17: { /* QUIT */ case QUIT: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 18: /* FIND */ case FIND:
return find(command->verb, command->obj); return find(command->verb, command->obj);
case 19: /* INVEN */ case INVENTORY:
return find(command->verb, command->obj); return find(command->verb, command->obj);
case 20: /* FEED */ case FEED:
return feed(command->verb, command->obj); return feed(command->verb, command->obj);
case 21: /* FILL */ case FILL:
return fill(command->verb, command->obj); return fill(command->verb, command->obj);
case 22: /* BLAST */ case BLAST:
blast(); blast();
return GO_CLEAROBJ; return GO_CLEAROBJ;
case 23: { /* SCOR */ case SCORE: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 24: { /* FOO */ case GIANTWORDS: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 25: { /* BRIEF */ case BRIEF: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 26: /* READ */ case READ:
return read(*command); return read(*command);
case 27: /* BREAK */ case BREAK:
return vbreak(command->verb, command->obj); return vbreak(command->verb, command->obj);
case 28: /* WAKE */ case WAKE:
return wake(command->verb, command->obj); return wake(command->verb, command->obj);
case 29: { /* SUSP */ case SAVE: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 30: { /* RESU */ case RESUME: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 31: /* FLY */ case FLY:
return fly(command->verb, command->obj); return fly(command->verb, command->obj);
case 32: { /* LISTE */ case LISTEN: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
case 33: /* ZZZZ */ case PART:
return reservoir(); return reservoir();
} default:
BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST);
}
case unknown: case unknown:
/* Unknown verb, couldn't deduce object - might need hint */ /* Unknown verb, couldn't deduce object - might need hint */
rspeak(WHAT_DO, command->wd1, command->wd1x); rspeak(WHAT_DO, command->wd1, command->wd1x);

View file

@ -506,106 +506,106 @@ actions: !!omap
- ACT_0: - ACT_0:
message: !!null message: !!null
words: !!null words: !!null
- ACT_1: - CARRY:
message: ALREADY_CARRYING message: ALREADY_CARRYING
words: ['carry', 'take', 'keep', 'catch', 'steal', 'captu', 'get', 'tote', 'snarf'] words: ['carry', 'take', 'keep', 'catch', 'steal', 'captu', 'get', 'tote', 'snarf']
- ACT_2: - DROP:
message: ARENT_CARRYING message: ARENT_CARRYING
words: ['drop', 'relea', 'free', 'disca', 'dump'] words: ['drop', 'relea', 'free', 'disca', 'dump']
- SAY: - SAY:
message: NO_MESSAGE message: NO_MESSAGE
words: ['say', 'chant', 'sing', 'utter', 'mumbl'] words: ['say', 'chant', 'sing', 'utter', 'mumbl']
- ACT_4: - UNLOCK:
message: NOT_LOCKABLE message: NOT_LOCKABLE
words: ['unloc', 'open'] words: ['unloc', 'open']
- ACT_5: - NOTHING:
message: NO_MESSAGE message: NO_MESSAGE
words: ['nothi'] words: ['nothi']
- LOCK: - LOCK:
message: NOT_LOCKABLE message: NOT_LOCKABLE
words: ['lock', 'close'] words: ['lock', 'close']
- ACT_7: - LIGHT:
message: DONT_UNDERSTAND message: DONT_UNDERSTAND
words: ['light', 'on'] words: ['light', 'on']
- ACT_8: - EXTINGUISH:
message: DONT_UNDERSTAND message: DONT_UNDERSTAND
words: ['extin', 'off'] words: ['extin', 'off']
- ACT_9: - WAVE:
message: NOTHING_HAPPENS message: NOTHING_HAPPENS
words: ['wave', 'shake', 'swing'] words: ['wave', 'shake', 'swing']
- ACT_10: - TAME:
message: AM_GAME message: AM_GAME
words: ['calm', 'placa', 'tame'] words: ['calm', 'placa', 'tame']
- ACT_11: - GO:
message: WHERE_QUERY message: WHERE_QUERY
words: ['walk', 'run', 'trave', 'go', 'proce', 'conti', 'explo', 'follo', 'turn'] words: ['walk', 'run', 'trave', 'go', 'proce', 'conti', 'explo', 'follo', 'turn']
- ACT_12: - ATTACK:
message: RIDICULOUS_ATTEMPT message: RIDICULOUS_ATTEMPT
words: ['attac', 'kill', 'fight', 'hit', 'strik', 'slay'] words: ['attac', 'kill', 'fight', 'hit', 'strik', 'slay']
- ACT_13: - POUR:
message: ARENT_CARRYING message: ARENT_CARRYING
words: ['pour'] words: ['pour']
- ACT_14: - EAT:
message: RIDICULOUS_ATTEMPT message: RIDICULOUS_ATTEMPT
words: ['eat', 'devou'] words: ['eat', 'devou']
- ACT_15: - DRINK:
message: STREAM_WATER message: STREAM_WATER
words: ['drink'] words: ['drink']
- ACT_16: - RUB:
message: RUB_NOGO message: RUB_NOGO
words: ['rub'] words: ['rub']
- THROW: - THROW:
message: ARENT_CARRYING message: ARENT_CARRYING
words: ['throw', 'toss'] words: ['throw', 'toss']
- ACT_18: - QUIT:
message: HUH_MAN message: HUH_MAN
words: ['quit'] words: ['quit']
- FIND: - FIND:
message: NEARBY message: NEARBY
words: ['find', 'where'] words: ['find', 'where']
- INVENT: - INVENTORY:
message: NEARBY message: NEARBY
words: ['inven'] words: ['inven']
- ACT_21: - FEED:
message: NO_EDIBLES message: NO_EDIBLES
words: ['feed'] words: ['feed']
- ACT_22: - FILL:
message: CANT_FILL message: CANT_FILL
words: ['fill'] words: ['fill']
- ACT_23: - BLAST:
message: REQUIRES_DYNAMITE message: REQUIRES_DYNAMITE
words: ['blast', 'deton', 'ignit', 'blowu'] words: ['blast', 'deton', 'ignit', 'blowu']
- ACT_24: - SCORE:
message: HUH_MAN message: HUH_MAN
words: ['score'] words: ['score']
- ACT_25: - GIANTWORDS:
message: NOT_KNOWHOW message: NOT_KNOWHOW
words: ['fee', 'fie', 'foe', 'foo', 'fum'] words: ['fee', 'fie', 'foe', 'foo', 'fum']
- ACT_26: - BRIEF:
message: ON_WHAT message: ON_WHAT
words: ['brief'] words: ['brief']
- ACT_27: - READ:
message: DONT_UNDERSTAND message: DONT_UNDERSTAND
words: ['read', 'perus'] words: ['read', 'perus']
- ACT_28: - BREAK:
message: BEYOND_POWER message: BEYOND_POWER
words: ['break', 'shatt', 'smash'] words: ['break', 'shatt', 'smash']
- ACT_29: - WAKE:
message: RIDICULOUS_ATTEMPT message: RIDICULOUS_ATTEMPT
words: ['wake', 'distu'] words: ['wake', 'distu']
- ACT_30: - SAVE:
message: HUH_MAN message: HUH_MAN
words: ['suspe', 'pause', 'save'] words: ['suspe', 'pause', 'save']
- ACT_31: - RESUME:
message: HUH_MAN message: HUH_MAN
words: ['resum', 'resta'] words: ['resum', 'resta']
- ACT_32: - FLY:
message: AM_GAME message: AM_GAME
words: ['fly'] words: ['fly']
- ACT_33: - LISTEN:
message: DONT_UNDERSTAND message: DONT_UNDERSTAND
words: ['liste'] words: ['liste']
- ACT_34: - PART:
message: NOTHING_HAPPENS message: NOTHING_HAPPENS
words: ['z''zzz'] words: ['z''zzz']
- ACT_35: - ACT_35:

2
main.c
View file

@ -598,7 +598,7 @@ static bool playermove(token_t verb, int motion)
if (motion == 29 || motion == 30)spk = BAD_DIRECTION; if (motion == 29 || motion == 30)spk = BAD_DIRECTION;
if (motion == 7 || motion == 36 || motion == 37)spk = UNSURE_FACING; if (motion == 7 || motion == 36 || motion == 37)spk = UNSURE_FACING;
if (motion == 11 || motion == 19)spk = NO_INOUT_HERE; if (motion == 11 || motion == 19)spk = NO_INOUT_HERE;
if (verb == FIND || verb == INVENT)spk = NEARBY; if (verb == FIND || verb == INVENTORY)spk = NEARBY;
if (motion == 62 || motion == 65)spk = NOTHING_HAPPENS; if (motion == 62 || motion == 65)spk = NOTHING_HAPPENS;
if (motion == 17)spk = WHICH_WAY; if (motion == 17)spk = WHICH_WAY;
rspeak(spk); rspeak(spk);