Working but unpolished refactor of bigwords().
This commit is contained in:
parent
73608b6307
commit
0e540429b0
4 changed files with 72 additions and 46 deletions
57
actions.c
57
actions.c
|
@ -178,28 +178,23 @@ static int attack(struct command_t *command)
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bigwords(token_t foo)
|
static int bigwords(long id)
|
||||||
/* FEE FIE FOE FOO (AND FUM). Advance to next state if given in proper order.
|
/* FEE FIE FOE FOO (AND FUM). Advance to next state if given in proper order.
|
||||||
* Look up foo in special section of vocab to determine which word we've got.
|
* Look up foo in special section of vocab to determine which word we've got.
|
||||||
* Last word zips the eggs back to the giant room (unless already there). */
|
* Last word zips the eggs back to the giant room (unless already there). */
|
||||||
{
|
{
|
||||||
char word[TOKLEN + 1];
|
if ((game.foobar == WORD_EMPTY && id == ACTION_WORD(FEE)) ||
|
||||||
packed_to_token(foo, word);
|
(game.foobar == ACTION_WORD(FEE) && id == ACTION_WORD(FIE)) ||
|
||||||
int k = (int) get_special_vocab_id(word);
|
(game.foobar == ACTION_WORD(FIE) && id == ACTION_WORD(FOE)) ||
|
||||||
if (game.foobar != 1 - k) {
|
(game.foobar == ACTION_WORD(FOE) && id == ACTION_WORD(FOO)) ||
|
||||||
if (game.foobar != 0 && game.loc == LOC_GIANTROOM) {
|
(game.foobar == ACTION_WORD(FOE) && id == ACTION_WORD(FUM)))
|
||||||
rspeak( START_OVER);
|
{
|
||||||
} else {
|
game.foobar = id;
|
||||||
rspeak(NOTHING_HAPPENS);
|
if ((id != ACTION_WORD(FOO)) && (id != ACTION_WORD(FUM))) {
|
||||||
}
|
|
||||||
return GO_CLEAROBJ;
|
|
||||||
} else {
|
|
||||||
game.foobar = k;
|
|
||||||
if (k != 4) {
|
|
||||||
rspeak(OK_MAN);
|
rspeak(OK_MAN);
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
}
|
}
|
||||||
game.foobar = 0;
|
game.foobar = WORD_EMPTY;
|
||||||
if (game.place[EGGS] == objects[EGGS].plac ||
|
if (game.place[EGGS] == objects[EGGS].plac ||
|
||||||
(TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
|
(TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
|
||||||
rspeak(NOTHING_HAPPENS);
|
rspeak(NOTHING_HAPPENS);
|
||||||
|
@ -209,7 +204,7 @@ static int bigwords(token_t foo)
|
||||||
* crossing. */
|
* crossing. */
|
||||||
if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
|
if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
|
||||||
game.prop[TROLL] = TROLL_PAIDONCE;
|
game.prop[TROLL] = TROLL_PAIDONCE;
|
||||||
k = EGGS_DONE;
|
int k = EGGS_DONE;
|
||||||
if (HERE(EGGS))
|
if (HERE(EGGS))
|
||||||
k = EGGS_VANISHED;
|
k = EGGS_VANISHED;
|
||||||
if (game.loc == objects[EGGS].plac)
|
if (game.loc == objects[EGGS].plac)
|
||||||
|
@ -219,6 +214,16 @@ static int bigwords(token_t foo)
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (game.loc == LOC_GIANTROOM) {
|
||||||
|
rspeak( START_OVER);
|
||||||
|
} else {
|
||||||
|
rspeak(NOTHING_HAPPENS);
|
||||||
|
}
|
||||||
|
game.foobar = WORD_EMPTY;
|
||||||
|
return GO_CLEAROBJ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void blast(void)
|
static void blast(void)
|
||||||
|
@ -1115,7 +1120,11 @@ static int say(struct command_t *command)
|
||||||
if (wd == MOTION_WORD(XYZZY) ||
|
if (wd == MOTION_WORD(XYZZY) ||
|
||||||
wd == MOTION_WORD(PLUGH) ||
|
wd == MOTION_WORD(PLUGH) ||
|
||||||
wd == MOTION_WORD(PLOVER) ||
|
wd == MOTION_WORD(PLOVER) ||
|
||||||
wd == ACTION_WORD(GIANTWORDS) ||
|
wd == ACTION_WORD(FEE) ||
|
||||||
|
wd == ACTION_WORD(FIE) ||
|
||||||
|
wd == ACTION_WORD(FOE) ||
|
||||||
|
wd == ACTION_WORD(FOO) ||
|
||||||
|
wd == ACTION_WORD(FUM) ||
|
||||||
wd == ACTION_WORD(PART)) {
|
wd == ACTION_WORD(PART)) {
|
||||||
/* FIXME: scribbles on the interpreter's command block */
|
/* FIXME: scribbles on the interpreter's command block */
|
||||||
wordclear(&command->wd2);
|
wordclear(&command->wd2);
|
||||||
|
@ -1376,8 +1385,12 @@ int action(struct command_t *command)
|
||||||
case SCORE:
|
case SCORE:
|
||||||
score(scoregame);
|
score(scoregame);
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
case GIANTWORDS:
|
case FEE:
|
||||||
return bigwords(command->wd1);
|
case FIE:
|
||||||
|
case FOE:
|
||||||
|
case FOO:
|
||||||
|
case FUM:
|
||||||
|
return bigwords(command->id1);
|
||||||
case BRIEF:
|
case BRIEF:
|
||||||
return brief();
|
return brief();
|
||||||
case READ:
|
case READ:
|
||||||
|
@ -1464,7 +1477,11 @@ int action(struct command_t *command)
|
||||||
rspeak(actions[command->verb].message);
|
rspeak(actions[command->verb].message);
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
}
|
}
|
||||||
case GIANTWORDS: {
|
case FEE:
|
||||||
|
case FIE:
|
||||||
|
case FOE:
|
||||||
|
case FOO:
|
||||||
|
case FUM: {
|
||||||
rspeak(actions[command->verb].message);
|
rspeak(actions[command->verb].message);
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -351,9 +351,21 @@ actions: !!omap
|
||||||
- SCORE:
|
- SCORE:
|
||||||
message: HUH_MAN
|
message: HUH_MAN
|
||||||
words: ['score']
|
words: ['score']
|
||||||
- GIANTWORDS:
|
- FEE:
|
||||||
message: NOT_KNOWHOW
|
message: NOT_KNOWHOW
|
||||||
words: ['fee', 'fie', 'foe', 'foo', 'fum']
|
words: ['fee']
|
||||||
|
- FIE:
|
||||||
|
message: NOT_KNOWHOW
|
||||||
|
words: ['fie']
|
||||||
|
- FOE:
|
||||||
|
message: NOT_KNOWHOW
|
||||||
|
words: ['foe']
|
||||||
|
- FOO:
|
||||||
|
message: NOT_KNOWHOW
|
||||||
|
words: ['foo']
|
||||||
|
- FUM:
|
||||||
|
message: NOT_KNOWHOW
|
||||||
|
words: ['fum']
|
||||||
- BRIEF:
|
- BRIEF:
|
||||||
message: ON_WHAT
|
message: ON_WHAT
|
||||||
words: ['brief']
|
words: ['brief']
|
||||||
|
|
1
init.c
1
init.c
|
@ -36,6 +36,7 @@ struct game_t game = {
|
||||||
.newloc = LOC_START,
|
.newloc = LOC_START,
|
||||||
.loc = LOC_START,
|
.loc = LOC_START,
|
||||||
.limit = GAMELIMIT,
|
.limit = GAMELIMIT,
|
||||||
|
.foobar = WORD_EMPTY,
|
||||||
|
|
||||||
/* Initialize our LCG PRNG with parameters tested against
|
/* Initialize our LCG PRNG with parameters tested against
|
||||||
* Knuth vol. 2. by the original authors */
|
* Knuth vol. 2. by the original authors */
|
||||||
|
|
4
main.c
4
main.c
|
@ -1065,11 +1065,7 @@ L2600:
|
||||||
command.id1 = get_vocab_id(word1);
|
command.id1 = get_vocab_id(word1);
|
||||||
command.id2 = get_vocab_id(word2);
|
command.id2 = get_vocab_id(word2);
|
||||||
|
|
||||||
/* Every input, check "game.foobar" flag. If zero, nothing's
|
|
||||||
* going on. If pos, make neg. If neg, he skipped a word,
|
|
||||||
* so make it zero. */
|
|
||||||
L2607:
|
L2607:
|
||||||
game.foobar = (game.foobar > 0 ? -game.foobar : 0);
|
|
||||||
++game.turns;
|
++game.turns;
|
||||||
|
|
||||||
/* If a turn threshold has been met, apply penalties and tell
|
/* If a turn threshold has been met, apply penalties and tell
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue