Fix to Gitlab issue #32. Now SEED and WASTE are in adventure.yaml

NOTE: the tests are all updated because now, like every other action,
SEED and WASTE have a \n before their output, as they correctly use
SPEAK
This commit is contained in:
Aaron Traas 2017-07-21 09:52:19 -04:00
parent ef236aea3b
commit 5337e00725
84 changed files with 174 additions and 32 deletions

View file

@ -1244,6 +1244,26 @@ static int wake(verb_t verb, obj_t obj)
}
}
static int seed(verb_t verb, const char *arg)
/* Set seed */
{
long seed = atol(arg);
speak(actions[verb].message, arg);
set_seed(seed);
--game.turns;
return GO_TOP;
}
static int waste(verb_t verb, turn_t turns)
/* Burn turns */
{
game.limit -= turns;
char newlim[1024];
sprintf(newlim, "%ld", (long)game.limit);
speak(actions[verb].message, newlim);
return GO_TOP;
}
static int wave(verb_t verb, obj_t obj)
/* Wave. No effect unless waving rod at fissure or at bird. */
{
@ -1430,6 +1450,10 @@ int action(struct command_t *command)
return listen();
case PART:
return reservoir();
case SEED:
case WASTE:
rspeak(NUMERIC_REQUIRED);
return GO_TOP;
default: // LCOV_EXCL_LINE
BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
}
@ -1531,6 +1555,10 @@ int action(struct command_t *command)
}
case PART:
return reservoir();
case SEED:
return seed(command->verb, command->raw2);
case WASTE:
return waste(command->verb, (turn_t)atol(command->raw2));
default: // LCOV_EXCL_LINE
BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
}

View file

@ -87,7 +87,7 @@ enum termination {endgame, quitgame, scoregame};
enum speechpart {unknown, intransitive, transitive};
enum wordtype {NO_WORD_TYPE, MOTION, OBJECT, ACTION, SPECIAL};
enum wordtype {NO_WORD_TYPE, MOTION, OBJECT, ACTION, SPECIAL, NUMERIC};
typedef enum scorebonus {none, splatter, defeat, victory} score_t;

View file

@ -3015,6 +3015,8 @@ arbitrary_messages: !!omap
- GO_UNNEEDED: |-
You don't have to say "go" every time; just specify a direction or, if
it's nearby, name the place to which you wish to move.
- NUMERIC_REQUIRED:
This command requires a numeric argument.
classes:
- threshold: 0
@ -3878,6 +3880,12 @@ actions: !!omap
- PART:
message: *nothing_happens
words: ['z''zzz']
- SEED:
message: 'Seed set to %s'
words: ['seed']
- WASTE:
message: 'Game limit is now %s'
words: ['waste']
- ACT_UNKNOWN:
message: *huh_man
words: !!null

30
main.c
View file

@ -133,28 +133,6 @@ int main(int argc, char *argv[])
terminate(quitgame);
}
static bool fallback_handler(struct command_t command)
/* fallback handler for commands not handled by FORTRANish parser */
{
long sv;
turn_t turnlimit;
char buf[DIM(command.raw1) + DIM(command.raw2) + 1];
sprintf(buf, "%s %s", command.raw1, command.raw2);
if (sscanf(buf, "seed %ld", &sv) == 1) {
set_seed(sv);
printf("Seed set to %ld\n", sv);
// autogenerated, so don't charge user time for it.
--game.turns;
return true;
} else if (sscanf(buf, "waste %ld", &turnlimit) == 1) {
game.limit -= turnlimit;
printf("Game limit is now %ld\n", game.limit);
return true;
}
return false;
}
/* Check if this loc is eligible for any hints. If been here long
* enough, display. Ignore "HINTS" < 4 (special stuff, see database
* notes). */
@ -1136,8 +1114,6 @@ Lookup:
rspeak(GO_UNNEEDED);
}
if (command.id1 == WORD_NOT_FOUND) {
if (fallback_handler(command))
continue;
/* Gee, I don't understand. */
sspeak(DONT_KNOW, command.raw1);
goto Lclearobj;
@ -1152,12 +1128,16 @@ Lookup:
command.obj = command.id1;
break;
case ACTION:
command.part = intransitive;
if(command.type2 == NUMERIC)
command.part = transitive;
else
command.part = intransitive;
command.verb = command.id1;
break;
case SPECIAL:
speak(specials[command.id1].message);
goto Lclearobj;
case NUMERIC:
default: // LCOV_EXCL_LINE
BUG(VOCABULARY_TYPE_N_OVER_1000_NOT_BETWEEN_0_AND_3); // LCOV_EXCL_LINE
}

31
misc.c
View file

@ -399,6 +399,30 @@ static int get_special_vocab_id(const char* word)
return (WORD_NOT_FOUND);
}
static bool is_valid_int(const char *str)
/* Returns true if the string passed in is represents a valid integer,
* that could then be parsed by atoi() */
{
// Handle negative number
if (*str == '-')
++str;
// Handle empty string or just "-"
if (!*str)
return false;
// Check for non-digit chars in the rest of the stirng.
while (*str)
{
if (!isdigit(*str))
return false;
else
++str;
}
return true;
}
static void get_vocab_metadata(const char* word, vocab_t* id, enum wordtype* type)
{
/* Check for an empty string */
@ -445,6 +469,13 @@ static void get_vocab_metadata(const char* word, vocab_t* id, enum wordtype* typ
return;
}
// Check words that are actually numbers.
if (is_valid_int(word)) {
*id = WORD_EMPTY;
*type = NUMERIC;
return;
}
*id = WORD_NOT_FOUND;
*type = NO_WORD_TYPE;
return;

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.
@ -2512,6 +2513,7 @@ Brass lantern
Dwarf's axe
> waste 2443
Game limit is now 30
You're in Hall of Mists.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1071883378
Seed set to 1071883378
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495951709
Seed set to 1495951709
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495774850
Seed set to 1495774850
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 18084731
Seed set to 18084731
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495951709
Seed set to 1495951709
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1494912171
Seed set to 1494912171
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 383847
Seed set to 383847
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 25508795
Seed set to 25508795
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 25508795
Seed set to 25508795
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495951709
Seed set to 1495951709
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495774850
Seed set to 1495774850
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1951269982
Seed set to 1951269982
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495951709
Seed set to 1495951709
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.

View file

@ -32,6 +32,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.
@ -72,6 +73,20 @@ Sorry, but I no longer seem to remember how it was you got here.
You're in front of building.
> seed
This command requires a numeric argument.
You're in front of building.
> waste
This command requires a numeric argument.
You are standing at the end of a road before a small brick building.
Around you is a forest. A small stream flows out of the building and
down a gully.
> eat grate
I see no grate here.
@ -236,9 +251,7 @@ Blasting requires dynamite.
> building
You are standing at the end of a road before a small brick building.
Around you is a forest. A small stream flows out of the building and
down a gully.
You're in front of building.
> cave
@ -597,7 +610,7 @@ Okay, "boo".
> score
You have garnered 27 out of a possible 430 points, using 113 turns.
You have garnered 27 out of a possible 430 points, using 115 turns.
> z
@ -605,7 +618,7 @@ OK
> score
You have garnered 27 out of a possible 430 points, using 115 turns.
You have garnered 27 out of a possible 430 points, using 117 turns.
> quit keys
@ -654,7 +667,7 @@ Do you really want to quit now?
OK
You scored 27 out of a possible 430, using 123 turns.
You scored 27 out of a possible 430, using 125 turns.
You are obviously a rank amateur. Better luck next time.

View file

@ -13,6 +13,8 @@ say rub
say grate
_
back
seed
waste
eat grate
eat building
in

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495951709
Seed set to 1495951709
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1071883378
Seed set to 1071883378
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 25508795
Seed set to 25508795
You're in front of building.

View file

@ -8,11 +8,13 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 437547289
Seed set to 437547289
You're in front of building.
> seed 1071883378
Seed set to 1071883378
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1837473132
Seed set to 1837473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1830473132
Seed set to 1830473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 780351908
Seed set to 780351908
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495951709
Seed set to 1495951709
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1495774850
Seed set to 1495774850
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1240742801
Seed set to 1240742801
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1240742801
Seed set to 1240742801
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1240742801
Seed set to 1240742801
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.
@ -1274,6 +1275,7 @@ You're in Shell Room.
There is an enormous clam here with its shell tightly closed.
> seed 1635997320
Seed set to 1635997320
You're in Shell Room.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1951269982
Seed set to 1951269982
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1071883378
Seed set to 1071883378
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1951269982
Seed set to 1951269982
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1838473132
Seed set to 1838473132
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 183847312
Seed set to 183847312
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 694608006
Seed set to 694608006
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1071883378
Seed set to 1071883378
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 1635997320
Seed set to 1635997320
You're in front of building.

View file

@ -8,6 +8,7 @@ Around you is a forest. A small stream flows out of the building and
down a gully.
> seed 2099333241
Seed set to 2099333241
You're in front of building.