Wire Section 8 YAML to runtime.
This commit is contained in:
parent
3025388932
commit
b626371b6c
3 changed files with 37 additions and 27 deletions
38
actions.c
38
actions.c
|
@ -14,7 +14,7 @@ static int attack(FILE *input, struct command_t *command)
|
||||||
{
|
{
|
||||||
vocab_t verb = command->verb;
|
vocab_t verb = command->verb;
|
||||||
vocab_t obj = command->obj;
|
vocab_t obj = command->obj;
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == 0 || obj == INTRANSITIVE) {
|
if (obj == 0 || obj == INTRANSITIVE) {
|
||||||
if (ATDWRF(game.loc) > 0)
|
if (ATDWRF(game.loc) > 0)
|
||||||
obj = DWARF;
|
obj = DWARF;
|
||||||
|
@ -177,7 +177,7 @@ static void blast(void)
|
||||||
static int vbreak(token_t verb, token_t obj)
|
static int vbreak(token_t verb, token_t obj)
|
||||||
/* Break. Only works for mirror in repository and, of course, the vase. */
|
/* Break. Only works for mirror in repository and, of course, the vase. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == MIRROR)spk = TOO_FAR;
|
if (obj == MIRROR)spk = TOO_FAR;
|
||||||
if (obj == VASE && game.prop[VASE] == 0) {
|
if (obj == VASE && game.prop[VASE] == 0) {
|
||||||
if (TOTING(VASE))DROP(VASE, game.loc);
|
if (TOTING(VASE))DROP(VASE, game.loc);
|
||||||
|
@ -323,7 +323,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
|
||||||
* bird (might attack snake or dragon) and cage (might contain bird) and vase.
|
* bird (might attack snake or dragon) and cage (might contain bird) and vase.
|
||||||
* Drop coins at vending machine for extra batteries. */
|
* Drop coins at vending machine for extra batteries. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (!just_do_it) {
|
if (!just_do_it) {
|
||||||
if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj = ROD2;
|
if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj = ROD2;
|
||||||
if (!TOTING(obj)) {
|
if (!TOTING(obj)) {
|
||||||
|
@ -398,7 +398,7 @@ static int drink(token_t verb, token_t obj)
|
||||||
/* Drink. If no object, assume water and look for it here. If water is in
|
/* Drink. If no object, assume water and look for it here. If water is in
|
||||||
* the bottle, drink that, else must be at a water loc, so drink stream. */
|
* the bottle, drink that, else must be at a water loc, so drink stream. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == 0 && LIQLOC(game.loc) != WATER && (LIQUID() != WATER || !HERE(BOTTLE)))
|
if (obj == 0 && LIQLOC(game.loc) != WATER && (LIQUID() != WATER || !HERE(BOTTLE)))
|
||||||
return GO_UNKNOWN;
|
return GO_UNKNOWN;
|
||||||
if (obj != BLOOD) {
|
if (obj != BLOOD) {
|
||||||
|
@ -422,7 +422,7 @@ static int eat(token_t verb, token_t obj)
|
||||||
/* Eat. Intransitive: assume food if present, else ask what. Transitive: food
|
/* Eat. Intransitive: assume food if present, else ask what. Transitive: food
|
||||||
* ok, some things lose appetite, rest are ridiculous. */
|
* ok, some things lose appetite, rest are ridiculous. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == INTRANSITIVE) {
|
if (obj == INTRANSITIVE) {
|
||||||
if (!HERE(FOOD))
|
if (!HERE(FOOD))
|
||||||
return GO_UNKNOWN;
|
return GO_UNKNOWN;
|
||||||
|
@ -444,7 +444,7 @@ static int eat(token_t verb, token_t obj)
|
||||||
static int extinguish(token_t verb, int obj)
|
static int extinguish(token_t verb, int obj)
|
||||||
/* Extinguish. Lamp, urn, dragon/volcano (nice try). */
|
/* Extinguish. Lamp, urn, dragon/volcano (nice try). */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == INTRANSITIVE) {
|
if (obj == INTRANSITIVE) {
|
||||||
if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
|
if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
|
||||||
obj = LAMP;
|
obj = LAMP;
|
||||||
|
@ -469,7 +469,7 @@ static int feed(token_t verb, token_t obj)
|
||||||
/* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
|
/* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
|
||||||
* mad. Bear, special. */
|
* mad. Bear, special. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == BIRD) {
|
if (obj == BIRD) {
|
||||||
rspeak(BIRD_PINING);
|
rspeak(BIRD_PINING);
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
|
@ -511,7 +511,7 @@ int fill(token_t verb, token_t obj)
|
||||||
* is nasty.) */
|
* is nasty.) */
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == VASE) {
|
if (obj == VASE) {
|
||||||
spk = ARENT_CARRYING;
|
spk = ARENT_CARRYING;
|
||||||
if (LIQLOC(game.loc) == 0)spk = FILL_INVALID;
|
if (LIQLOC(game.loc) == 0)spk = FILL_INVALID;
|
||||||
|
@ -569,7 +569,7 @@ int fill(token_t verb, token_t obj)
|
||||||
static int find(token_t verb, token_t obj)
|
static int find(token_t verb, token_t obj)
|
||||||
/* Find. Might be carrying it, or it might be here. Else give caveat. */
|
/* Find. Might be carrying it, or it might be here. Else give caveat. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (AT(obj) ||
|
if (AT(obj) ||
|
||||||
(LIQUID() == obj && AT(BOTTLE)) ||
|
(LIQUID() == obj && AT(BOTTLE)) ||
|
||||||
obj == LIQLOC(game.loc) ||
|
obj == LIQLOC(game.loc) ||
|
||||||
|
@ -584,7 +584,7 @@ static int find(token_t verb, token_t obj)
|
||||||
static int fly(token_t verb, token_t obj)
|
static int fly(token_t verb, token_t obj)
|
||||||
/* Fly. Snide remarks unless hovering rug is here. */
|
/* Fly. Snide remarks unless hovering rug is here. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == INTRANSITIVE) {
|
if (obj == INTRANSITIVE) {
|
||||||
if (game.prop[RUG] != 2)spk = RUG_NOTHING2;
|
if (game.prop[RUG] != 2)spk = RUG_NOTHING2;
|
||||||
if (!HERE(RUG))spk = FLAP_ARMS;
|
if (!HERE(RUG))spk = FLAP_ARMS;
|
||||||
|
@ -637,7 +637,7 @@ static int inven(void)
|
||||||
static int light(token_t verb, token_t obj)
|
static int light(token_t verb, token_t obj)
|
||||||
/* Light. Applicable only to lamp and urn. */
|
/* Light. Applicable only to lamp and urn. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == INTRANSITIVE) {
|
if (obj == INTRANSITIVE) {
|
||||||
if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0)
|
if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0)
|
||||||
obj = LAMP;
|
obj = LAMP;
|
||||||
|
@ -704,7 +704,7 @@ static int listen(void)
|
||||||
static int lock(token_t verb, token_t obj)
|
static int lock(token_t verb, token_t obj)
|
||||||
/* Lock, unlock, no object given. Assume various things if present. */
|
/* Lock, unlock, no object given. Assume various things if present. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == INTRANSITIVE) {
|
if (obj == INTRANSITIVE) {
|
||||||
spk = NOTHING_LOCKED;
|
spk = NOTHING_LOCKED;
|
||||||
if (HERE(CLAM))obj = CLAM;
|
if (HERE(CLAM))obj = CLAM;
|
||||||
|
@ -750,7 +750,7 @@ static int pour(token_t verb, token_t obj)
|
||||||
/* Pour. If no object, or object is bottle, assume contents of bottle.
|
/* Pour. If no object, or object is bottle, assume contents of bottle.
|
||||||
* special tests for pouring water or oil on plant or rusty door. */
|
* special tests for pouring water or oil on plant or rusty door. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj == BOTTLE || obj == 0)obj = LIQUID();
|
if (obj == BOTTLE || obj == 0)obj = LIQUID();
|
||||||
if (obj == 0) return GO_UNKNOWN;
|
if (obj == 0) return GO_UNKNOWN;
|
||||||
if (!TOTING(obj)) {
|
if (!TOTING(obj)) {
|
||||||
|
@ -816,7 +816,7 @@ static int read(struct command_t command)
|
||||||
} else if (command.obj == OYSTER && !game.clshnt && game.closed) {
|
} else if (command.obj == OYSTER && !game.clshnt && game.closed) {
|
||||||
game.clshnt = YES(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
|
game.clshnt = YES(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
|
||||||
} else if (object_descriptions[command.obj].texts[0] == NULL || game.prop[command.obj] < 0) {
|
} else if (object_descriptions[command.obj].texts[0] == NULL || game.prop[command.obj] < 0) {
|
||||||
rspeak(ACTSPK[command.verb]);
|
rspeak(actspk[command.verb]);
|
||||||
} else
|
} else
|
||||||
pspeak(command.obj, study, game.prop[command.obj]);
|
pspeak(command.obj, study, game.prop[command.obj]);
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
|
@ -845,7 +845,7 @@ static int reservoir(void)
|
||||||
static int rub(token_t verb, token_t obj)
|
static int rub(token_t verb, token_t obj)
|
||||||
/* Rub. Yields various snide remarks except for lit urn. */
|
/* Rub. Yields various snide remarks except for lit urn. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if (obj != LAMP)
|
if (obj != LAMP)
|
||||||
spk = PECULIAR_NOTHING;
|
spk = PECULIAR_NOTHING;
|
||||||
if (obj == URN && game.prop[URN] == 2) {
|
if (obj == URN && game.prop[URN] == 2) {
|
||||||
|
@ -893,7 +893,7 @@ static int throw (FILE *cmdin, struct command_t *command)
|
||||||
* (Only way to do so!) Axe also special for dragon, bear, and
|
* (Only way to do so!) Axe also special for dragon, bear, and
|
||||||
* troll. Treasures special for troll. */
|
* troll. Treasures special for troll. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[command->verb];
|
int spk = actspk[command->verb];
|
||||||
if (TOTING(ROD2) && command->obj == ROD && !TOTING(ROD))command->obj = ROD2;
|
if (TOTING(ROD2) && command->obj == ROD && !TOTING(ROD))command->obj = ROD2;
|
||||||
if (!TOTING(command->obj)) {
|
if (!TOTING(command->obj)) {
|
||||||
rspeak(spk);
|
rspeak(spk);
|
||||||
|
@ -955,7 +955,7 @@ static int wake(token_t verb, token_t obj)
|
||||||
/* Wake. Only use is to disturb the dwarves. */
|
/* Wake. Only use is to disturb the dwarves. */
|
||||||
{
|
{
|
||||||
if (obj != DWARF || !game.closed) {
|
if (obj != DWARF || !game.closed) {
|
||||||
rspeak(ACTSPK[verb]);
|
rspeak(actspk[verb]);
|
||||||
return GO_CLEAROBJ;
|
return GO_CLEAROBJ;
|
||||||
} else {
|
} else {
|
||||||
rspeak(PROD_DWARF);
|
rspeak(PROD_DWARF);
|
||||||
|
@ -966,7 +966,7 @@ static int wake(token_t verb, token_t obj)
|
||||||
static int wave(token_t verb, token_t obj)
|
static int wave(token_t verb, token_t obj)
|
||||||
/* Wave. No effect unless waving rod at fissure or at bird. */
|
/* Wave. No effect unless waving rod at fissure or at bird. */
|
||||||
{
|
{
|
||||||
int spk = ACTSPK[verb];
|
int spk = actspk[verb];
|
||||||
if ((!TOTING(obj)) && (obj != ROD || !TOTING(ROD2)))spk = ARENT_CARRYING;
|
if ((!TOTING(obj)) && (obj != ROD || !TOTING(ROD2)))spk = ARENT_CARRYING;
|
||||||
if (obj != ROD ||
|
if (obj != ROD ||
|
||||||
!TOTING(obj) ||
|
!TOTING(obj) ||
|
||||||
|
@ -1005,7 +1005,7 @@ int action(FILE *input, struct command_t *command)
|
||||||
* unless verb is "say", which snarfs arbitrary second word.
|
* unless verb is "say", which snarfs arbitrary second word.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
token_t spk = ACTSPK[command->verb];
|
token_t spk = actspk[command->verb];
|
||||||
|
|
||||||
if (command->part == unknown) {
|
if (command->part == unknown) {
|
||||||
/* Analyse an object word. See if the thing is here, whether
|
/* Analyse an object word. See if the thing is here, whether
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
* 12600 words of message text (LINES, LINSIZ).
|
* 12600 words of message text (LINES, LINSIZ).
|
||||||
* 885 travel options (TRAVEL, TRVSIZ).
|
* 885 travel options (TRAVEL, TRVSIZ).
|
||||||
* 330 vocabulary words (KTAB, ATAB, TABSIZ).
|
* 330 vocabulary words (KTAB, ATAB, TABSIZ).
|
||||||
* 35 "action" verbs (ACTSPK, VRBSIZ).
|
|
||||||
* There are also limits which cannot be exceeded due to the structure of
|
* There are also limits which cannot be exceeded due to the structure of
|
||||||
* the database. (E.G., The vocabulary uses n/1000 to determine word type,
|
* the database. (E.G., The vocabulary uses n/1000 to determine word type,
|
||||||
* so there can't be more than 1000 words.) These upper limits are:
|
* so there can't be more than 1000 words.) These upper limits are:
|
||||||
|
@ -60,8 +59,6 @@
|
||||||
* or "attack"). Else, if M=3, the word is a special case verb (such as
|
* or "attack"). Else, if M=3, the word is a special case verb (such as
|
||||||
* "dig") and N % 1000 is an index into section 6. Objects from 50 to
|
* "dig") and N % 1000 is an index into section 6. Objects from 50 to
|
||||||
* (currently, anyway) 79 are considered treasures (for pirate, closeout).
|
* (currently, anyway) 79 are considered treasures (for pirate, closeout).
|
||||||
* Section 8: Action defaults. Each line contains an "action-verb" number and
|
|
||||||
* the index (in section 6) of the default message for the verb.
|
|
||||||
* Section 0: End of database.
|
* Section 0: End of database.
|
||||||
*
|
*
|
||||||
* Other sections are obsolete and ignored */
|
* Other sections are obsolete and ignored */
|
||||||
|
@ -99,7 +96,6 @@ long LINES[LINSIZ + 1];
|
||||||
long TRAVEL[TRVSIZ + 1];
|
long TRAVEL[TRVSIZ + 1];
|
||||||
long KTAB[TABSIZ + 1];
|
long KTAB[TABSIZ + 1];
|
||||||
long ATAB[TABSIZ + 1];
|
long ATAB[TABSIZ + 1];
|
||||||
long ACTSPK[VRBSIZ + 1];
|
|
||||||
|
|
||||||
static long GETTXT(long SKIP, long ONEWRD, long UPPER)
|
static long GETTXT(long SKIP, long ONEWRD, long UPPER)
|
||||||
{
|
{
|
||||||
|
@ -297,12 +293,12 @@ static void read_initial_locations(FILE* database)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read default message numbers for action verbs, store in ACTSPK. */
|
/* Read default message numbers for action verbs. */
|
||||||
static void read_action_verb_message_nr(FILE* database)
|
static void read_action_verb_message_nr(FILE* database)
|
||||||
{
|
{
|
||||||
long verb;
|
long verb;
|
||||||
while ((verb = GETNUM(database)) != -1) {
|
while ((verb = GETNUM(database)) != -1) {
|
||||||
ACTSPK[verb] = GETNUM(NULL);
|
/* now declared in YAML */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,7 +461,6 @@ static void write_file(FILE* header_file)
|
||||||
write_1d(header_file, TRAVEL, TRVSIZ + 1, "TRAVEL");
|
write_1d(header_file, TRAVEL, TRVSIZ + 1, "TRAVEL");
|
||||||
write_1d(header_file, KTAB, TABSIZ + 1, "KTAB");
|
write_1d(header_file, KTAB, TABSIZ + 1, "KTAB");
|
||||||
write_1d(header_file, ATAB, TABSIZ + 1, "ATAB");
|
write_1d(header_file, ATAB, TABSIZ + 1, "ATAB");
|
||||||
write_1d(header_file, ACTSPK, VRBSIZ + 1, "ACTSPK");
|
|
||||||
|
|
||||||
fprintf(header_file, "#undef LOCATION\n");
|
fprintf(header_file, "#undef LOCATION\n");
|
||||||
fprintf(header_file, "#undef INITIALIZE\n");
|
fprintf(header_file, "#undef INITIALIZE\n");
|
||||||
|
|
|
@ -103,13 +103,15 @@ extern const obituary_t obituaries[];
|
||||||
extern const hint_t hints[];
|
extern const hint_t hints[];
|
||||||
extern long conditions[];
|
extern long conditions[];
|
||||||
extern const vocabulary_t vocabulary[];
|
extern const vocabulary_t vocabulary[];
|
||||||
|
extern const long actspk[];
|
||||||
|
|
||||||
#define NLOCATIONS {}
|
#define NLOCATIONS {}
|
||||||
#define NOBJECTS {}
|
#define NOBJECTS {}
|
||||||
#define NHINTS {}
|
#define NHINTS {}
|
||||||
#define NCLASSES {}
|
#define NCLASSES {}
|
||||||
#define NDEATHS {}
|
#define NDEATHS {}
|
||||||
#define NTHRESHOLDS {}
|
#define NTHRESHOLDS {}
|
||||||
|
#define NVERBS {}
|
||||||
|
|
||||||
enum arbitrary_messages_refs {{
|
enum arbitrary_messages_refs {{
|
||||||
{}
|
{}
|
||||||
|
@ -170,6 +172,11 @@ const vocabulary_t vocabulary[] = {{
|
||||||
{}
|
{}
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
const long actspk[] = {{
|
||||||
|
NO_MESSAGE,
|
||||||
|
{}
|
||||||
|
}};
|
||||||
|
|
||||||
/* end */
|
/* end */
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -404,6 +411,12 @@ def get_vocabulary(vocabulary):
|
||||||
voc_str = voc_str[:-1] # trim trailing newline
|
voc_str = voc_str[:-1] # trim trailing newline
|
||||||
return voc_str
|
return voc_str
|
||||||
|
|
||||||
|
def get_actspk(actspk):
|
||||||
|
res = ""
|
||||||
|
for (i, word) in actspk.items():
|
||||||
|
res += " %s,\n" % word
|
||||||
|
return res
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
with open(yaml_name, "r") as f:
|
with open(yaml_name, "r") as f:
|
||||||
db = yaml.load(f)
|
db = yaml.load(f)
|
||||||
|
@ -421,6 +434,7 @@ if __name__ == "__main__":
|
||||||
get_hints(db["hints"], db["arbitrary_messages"]),
|
get_hints(db["hints"], db["arbitrary_messages"]),
|
||||||
get_condbits(db["locations"]),
|
get_condbits(db["locations"]),
|
||||||
get_vocabulary(db["vocabulary"]),
|
get_vocabulary(db["vocabulary"]),
|
||||||
|
get_actspk(db["actspk"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
h = h_template.format(
|
h = h_template.format(
|
||||||
|
@ -430,6 +444,7 @@ if __name__ == "__main__":
|
||||||
len(db["classes"]),
|
len(db["classes"]),
|
||||||
len(db["obituaries"]),
|
len(db["obituaries"]),
|
||||||
len(db["turn_thresholds"]),
|
len(db["turn_thresholds"]),
|
||||||
|
len(db["actspk"]),
|
||||||
get_refs(db["arbitrary_messages"]),
|
get_refs(db["arbitrary_messages"]),
|
||||||
get_refs(db["locations"]),
|
get_refs(db["locations"]),
|
||||||
get_refs(db["object_descriptions"]),
|
get_refs(db["object_descriptions"]),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue