From: Eric S. Raymond Date: Wed, 28 Jun 2017 15:45:53 +0000 (-0400) Subject: Magic-number elimination. X-Git-Tag: 1.1~54 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=f5719f1abaab6728c098756c2441d21801b4b6a3;p=open-adventure.git Magic-number elimination. --- diff --git a/actions.c b/actions.c index 5bb9555..d2eb46b 100644 --- a/actions.c +++ b/actions.c @@ -1041,7 +1041,7 @@ int action(FILE *input, struct command_t *command) } else if (command->obj == ROD && HERE(ROD2)) { command->obj = ROD2; /* 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 */; else { 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->obj == 0 || command->obj == INTRANSITIVE) { /* Analyse an intransitive verb (ie, no object given yet). */ - switch (command->verb - 1) { - case 0: /* CARRY */ + switch (command->verb) { + case CARRY: return vcarry(command->verb, INTRANSITIVE); - case 1: /* DROP */ + case DROP: return GO_UNKNOWN; - case 2: /* SAY */ + case SAY: return GO_UNKNOWN; - case 3: /* UNLOC */ + case UNLOCK: return lock(command->verb, INTRANSITIVE); - case 4: { /* NOTHI */ + case NOTHING: { rspeak(OK_MAN); return (GO_CLEAROBJ); } - case 5: /* LOCK */ + case LOCK: return lock(command->verb, INTRANSITIVE); - case 6: /* LIGHT */ + case LIGHT: return light(command->verb, INTRANSITIVE); - case 7: /* EXTIN */ + case EXTINGUISH: return extinguish(command->verb, INTRANSITIVE); - case 8: /* WAVE */ + case WAVE: return GO_UNKNOWN; - case 9: /* CALM */ + case TAME: return GO_UNKNOWN; - case 10: { /* WALK */ + case GO: { rspeak(spk); return GO_CLEAROBJ; } - case 11: /* ATTAC */ + case ATTACK: return attack(input, command); - case 12: /* POUR */ + case POUR: return pour(command->verb, command->obj); - case 13: /* EAT */ + case EAT: return eat(command->verb, INTRANSITIVE); - case 14: /* DRINK */ + case DRINK: return drink(command->verb, command->obj); - case 15: /* RUB */ + case RUB: return GO_UNKNOWN; - case 16: /* TOSS */ + case THROW: return GO_UNKNOWN; - case 17: /* QUIT */ + case QUIT: return quit(); - case 18: /* FIND */ + case FIND: return GO_UNKNOWN; - case 19: /* INVEN */ + case INVENTORY: return inven(); - case 20: /* FEED */ + case FEED: return GO_UNKNOWN; - case 21: /* FILL */ + case FILL: return fill(command->verb, command->obj); - case 22: /* BLAST */ + case BLAST: blast(); return GO_CLEAROBJ; - case 23: /* SCOR */ + case SCORE: score(scoregame); return GO_CLEAROBJ; - case 24: /* FOO */ + case GIANTWORDS: return bigwords(command->wd1); - case 25: /* BRIEF */ + case BRIEF: return brief(); - case 26: /* READ */ + case READ: command->obj = INTRANSITIVE; return read(*command); - case 27: /* BREAK */ + case BREAK: return GO_UNKNOWN; - case 28: /* WAKE */ + case WAKE: return GO_UNKNOWN; - case 29: /* SUSP */ + case SAVE: return suspend(); - case 30: /* RESU */ + case RESUME: return resume(); - case 31: /* FLY */ + case FLY: return fly(command->verb, INTRANSITIVE); - case 32: /* LISTE */ + case LISTEN: return listen(); - case 33: /* ZZZZ */ + case PART: return reservoir(); + default: + BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); } - BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); } /* FALLTHRU */ case transitive: /* Analyse a transitive verb. */ - switch (command->verb - 1) { - case 0: /* CARRY */ + switch (command->verb) { + case CARRY: return vcarry(command->verb, command->obj); - case 1: /* DROP */ + case DROP: return discard(command->verb, command->obj, false); - case 2: /* SAY */ + case SAY: return say(command); - case 3: /* UNLOC */ + case UNLOCK: return lock(command->verb, command->obj); - case 4: { /* NOTHI */ + case NOTHING: { rspeak(OK_MAN); return (GO_CLEAROBJ); } - case 5: /* LOCK */ + case LOCK: return lock(command->verb, command->obj); - case 6: /* LIGHT */ + case LIGHT: return light(command->verb, command->obj); - case 7: /* EXTI */ + case EXTINGUISH: return extinguish(command->verb, command->obj); - case 8: /* WAVE */ + case WAVE: return wave(command->verb, command->obj); - case 9: { /* CALM */ + case TAME: { rspeak(spk); return GO_CLEAROBJ; } - case 10: { /* WALK */ + case GO: { rspeak(spk); return GO_CLEAROBJ; } - case 11: /* ATTAC */ + case ATTACK: return attack(input, command); - case 12: /* POUR */ + case POUR: return pour(command->verb, command->obj); - case 13: /* EAT */ + case EAT: return eat(command->verb, command->obj); - case 14: /* DRINK */ + case DRINK: return drink(command->verb, command->obj); - case 15: /* RUB */ + case RUB: return rub(command->verb, command->obj); - case 16: /* TOSS */ + case THROW: return throw(input, command); - case 17: { /* QUIT */ + case QUIT: { rspeak(spk); return GO_CLEAROBJ; } - case 18: /* FIND */ + case FIND: return find(command->verb, command->obj); - case 19: /* INVEN */ + case INVENTORY: return find(command->verb, command->obj); - case 20: /* FEED */ + case FEED: return feed(command->verb, command->obj); - case 21: /* FILL */ + case FILL: return fill(command->verb, command->obj); - case 22: /* BLAST */ + case BLAST: blast(); return GO_CLEAROBJ; - case 23: { /* SCOR */ + case SCORE: { rspeak(spk); return GO_CLEAROBJ; } - case 24: { /* FOO */ + case GIANTWORDS: { rspeak(spk); return GO_CLEAROBJ; } - case 25: { /* BRIEF */ + case BRIEF: { rspeak(spk); return GO_CLEAROBJ; } - case 26: /* READ */ + case READ: return read(*command); - case 27: /* BREAK */ + case BREAK: return vbreak(command->verb, command->obj); - case 28: /* WAKE */ + case WAKE: return wake(command->verb, command->obj); - case 29: { /* SUSP */ + case SAVE: { rspeak(spk); return GO_CLEAROBJ; } - case 30: { /* RESU */ + case RESUME: { rspeak(spk); return GO_CLEAROBJ; } - case 31: /* FLY */ + case FLY: return fly(command->verb, command->obj); - case 32: { /* LISTE */ + case LISTEN: { rspeak(spk); return GO_CLEAROBJ; } - case 33: /* ZZZZ */ + case PART: return reservoir(); - } + default: BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); + } case unknown: /* Unknown verb, couldn't deduce object - might need hint */ rspeak(WHAT_DO, command->wd1, command->wd1x); diff --git a/adventure.yaml b/adventure.yaml index 7f79d90..5e18f75 100644 --- a/adventure.yaml +++ b/adventure.yaml @@ -506,106 +506,106 @@ actions: !!omap - ACT_0: message: !!null words: !!null -- ACT_1: +- CARRY: message: ALREADY_CARRYING words: ['carry', 'take', 'keep', 'catch', 'steal', 'captu', 'get', 'tote', 'snarf'] -- ACT_2: +- DROP: message: ARENT_CARRYING words: ['drop', 'relea', 'free', 'disca', 'dump'] - SAY: message: NO_MESSAGE words: ['say', 'chant', 'sing', 'utter', 'mumbl'] -- ACT_4: +- UNLOCK: message: NOT_LOCKABLE words: ['unloc', 'open'] -- ACT_5: +- NOTHING: message: NO_MESSAGE words: ['nothi'] - LOCK: message: NOT_LOCKABLE words: ['lock', 'close'] -- ACT_7: +- LIGHT: message: DONT_UNDERSTAND words: ['light', 'on'] -- ACT_8: +- EXTINGUISH: message: DONT_UNDERSTAND words: ['extin', 'off'] -- ACT_9: +- WAVE: message: NOTHING_HAPPENS words: ['wave', 'shake', 'swing'] -- ACT_10: +- TAME: message: AM_GAME words: ['calm', 'placa', 'tame'] -- ACT_11: +- GO: message: WHERE_QUERY words: ['walk', 'run', 'trave', 'go', 'proce', 'conti', 'explo', 'follo', 'turn'] -- ACT_12: +- ATTACK: message: RIDICULOUS_ATTEMPT words: ['attac', 'kill', 'fight', 'hit', 'strik', 'slay'] -- ACT_13: +- POUR: message: ARENT_CARRYING words: ['pour'] -- ACT_14: +- EAT: message: RIDICULOUS_ATTEMPT words: ['eat', 'devou'] -- ACT_15: +- DRINK: message: STREAM_WATER words: ['drink'] -- ACT_16: +- RUB: message: RUB_NOGO words: ['rub'] - THROW: message: ARENT_CARRYING words: ['throw', 'toss'] -- ACT_18: +- QUIT: message: HUH_MAN words: ['quit'] - FIND: message: NEARBY words: ['find', 'where'] -- INVENT: +- INVENTORY: message: NEARBY words: ['inven'] -- ACT_21: +- FEED: message: NO_EDIBLES words: ['feed'] -- ACT_22: +- FILL: message: CANT_FILL words: ['fill'] -- ACT_23: +- BLAST: message: REQUIRES_DYNAMITE words: ['blast', 'deton', 'ignit', 'blowu'] -- ACT_24: +- SCORE: message: HUH_MAN words: ['score'] -- ACT_25: +- GIANTWORDS: message: NOT_KNOWHOW words: ['fee', 'fie', 'foe', 'foo', 'fum'] -- ACT_26: +- BRIEF: message: ON_WHAT words: ['brief'] -- ACT_27: +- READ: message: DONT_UNDERSTAND words: ['read', 'perus'] -- ACT_28: +- BREAK: message: BEYOND_POWER words: ['break', 'shatt', 'smash'] -- ACT_29: +- WAKE: message: RIDICULOUS_ATTEMPT words: ['wake', 'distu'] -- ACT_30: +- SAVE: message: HUH_MAN words: ['suspe', 'pause', 'save'] -- ACT_31: +- RESUME: message: HUH_MAN words: ['resum', 'resta'] -- ACT_32: +- FLY: message: AM_GAME words: ['fly'] -- ACT_33: +- LISTEN: message: DONT_UNDERSTAND words: ['liste'] -- ACT_34: +- PART: message: NOTHING_HAPPENS words: ['z''zzz'] - ACT_35: diff --git a/main.c b/main.c index 3d3a8fb..a36ffce 100644 --- a/main.c +++ b/main.c @@ -598,7 +598,7 @@ static bool playermove(token_t verb, int motion) if (motion == 29 || motion == 30)spk = BAD_DIRECTION; if (motion == 7 || motion == 36 || motion == 37)spk = UNSURE_FACING; 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 == 17)spk = WHICH_WAY; rspeak(spk);