projects
/
open-adventure.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Implement and document state-changes messages in YAML.
[open-adventure.git]
/
actions.c
diff --git
a/actions.c
b/actions.c
index 5bb95553bc21937c348c5088ef32e143dca58558..c79a66680da59b391e06b7967eb1a7defb15f6c1 100644
(file)
--- a/
actions.c
+++ b/
actions.c
@@
-6,6
+6,12
@@
static int fill(token_t, token_t);
static int fill(token_t, token_t);
+static void state_change(long obj, long state)
+{
+ game.prop[obj] = state;
+ pspeak(obj, change, state);
+}
+
static int attack(FILE *input, struct command_t *command)
/* Attack. Assume target if unambiguous. "Throw" also links here.
* Attackable objects fall into two categories: enemies (snake,
static int attack(FILE *input, struct command_t *command)
/* Attack. Assume target if unambiguous. "Throw" also links here.
* Attackable objects fall into two categories: enemies (snake,
@@
-14,7
+20,7
@@
static int attack(FILE *input, struct command_t *command)
{
vocab_t verb = command->verb;
vocab_t obj = command->obj;
{
vocab_t verb = command->verb;
vocab_t obj = command->obj;
-
int
spk = actions[verb].message;
+
long
spk = actions[verb].message;
if (obj == 0 || obj == INTRANSITIVE) {
if (atdwrf(game.loc) > 0)
obj = DWARF;
if (obj == 0 || obj == INTRANSITIVE) {
if (atdwrf(game.loc) > 0)
obj = DWARF;
@@
-456,8
+462,7
@@
static int extinguish(token_t verb, int obj)
game.prop[URN] = game.prop[URN] / 2;
spk = URN_DARK;
} else if (obj == LAMP) {
game.prop[URN] = game.prop[URN] / 2;
spk = URN_DARK;
} else if (obj == LAMP) {
- game.prop[LAMP] = LAMP_DARK;
- rspeak(LAMP_OFF);
+ state_change(LAMP, LAMP_DARK);
spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE;
} else if (obj == DRAGON || obj == VOLCANO)
spk = BEYOND_POWER;
spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE;
} else if (obj == DRAGON || obj == VOLCANO)
spk = BEYOND_POWER;
@@
-663,8
+668,7
@@
static int light(token_t verb, token_t obj)
rspeak(spk);
return GO_CLEAROBJ;
}
rspeak(spk);
return GO_CLEAROBJ;
}
- game.prop[LAMP] = LAMP_BRIGHT;
- rspeak(LAMP_ON);
+ state_change(LAMP, LAMP_BRIGHT);
if (game.wzdark)
return GO_TOP;
else
if (game.wzdark)
return GO_TOP;
else
@@
-737,8
+741,8
@@
static int lock(token_t verb, token_t obj)
if (!game.panic)game.clock2 = PANICTIME;
game.panic = true;
} else {
if (!game.panic)game.clock2 = PANICTIME;
game.panic = true;
} else {
-
game.prop[GRATE] = (verb == LOCK) ? GRATE_CLOSED : GRATE_OPEN
;
-
spk = game.prop[GRATE] ? GRATE_UNLOCKED : GRATE_LOCKED
;
+
state_change(GRATE, (verb == LOCK) ? GRATE_CLOSED : GRATE_OPEN)
;
+
return GO_CLEAROBJ
;
}
}
}
}
}
}
@@
-1041,7
+1045,7
@@
int action(FILE *input, struct command_t *command)
} else if (command->obj == ROD && HERE(ROD2)) {
command->obj = ROD2;
/* FALL THROUGH */;
} 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 == INVENT
ORY
) && command->wd2 <= 0)
/* FALL THROUGH */;
else {
rspeak(NO_SEE, command->wd1, command->wd1x);
/* FALL THROUGH */;
else {
rspeak(NO_SEE, command->wd1, command->wd1x);
@@
-1061,185
+1065,187
@@
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). */
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);
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);
return (GO_CLEAROBJ);
}
rspeak(OK_MAN);
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);
return GO_CLEAROBJ;
}
rspeak(spk);
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();
return GO_CLEAROBJ;
blast();
return GO_CLEAROBJ;
- case
23: /* SCOR */
+ case
SCORE:
score(scoregame);
return GO_CLEAROBJ;
score(scoregame);
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;
return read(*command);
command->obj = INTRANSITIVE;
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); // LCOV_EXCL_LINE
}
}
- BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST);
}
/* FALLTHRU */
case transitive:
/* Analyse a transitive verb. */
}
/* 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);
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);
return (GO_CLEAROBJ);
}
rspeak(OK_MAN);
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);
return GO_CLEAROBJ;
}
rspeak(spk);
return GO_CLEAROBJ;
}
- case 10: { /* WALK */
+ case GO: {
rspeak(spk);
return GO_CLEAROBJ;
}
rspeak(spk);
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);
return GO_CLEAROBJ;
}
rspeak(spk);
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();
return GO_CLEAROBJ;
blast();
return GO_CLEAROBJ;
- case
23: { /* SCOR */
+ case
SCORE: {
rspeak(spk);
return GO_CLEAROBJ;
}
rspeak(spk);
return GO_CLEAROBJ;
}
- case
24: { /* FOO */
+ case
GIANTWORDS: {
rspeak(spk);
return GO_CLEAROBJ;
}
rspeak(spk);
return GO_CLEAROBJ;
}
- case
25: { /* BRIEF */
+ case
BRIEF: {
rspeak(spk);
return GO_CLEAROBJ;
}
rspeak(spk);
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);
return GO_CLEAROBJ;
}
rspeak(spk);
return GO_CLEAROBJ;
}
- case
30: { /* RESU */
+ case
RESUME: {
rspeak(spk);
return GO_CLEAROBJ;
}
rspeak(spk);
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);
return GO_CLEAROBJ;
}
rspeak(spk);
return GO_CLEAROBJ;
}
- case 33: /* ZZZZ */
+ case PART:
return reservoir();
return reservoir();
- }
- BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST);
+ default:
+ BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
+ }
case unknown:
/* Unknown verb, couldn't deduce object - might need hint */
rspeak(WHAT_DO, command->wd1, command->wd1x);
return GO_CHECKHINT;
default:
case unknown:
/* Unknown verb, couldn't deduce object - might need hint */
rspeak(WHAT_DO, command->wd1, command->wd1x);
return GO_CHECKHINT;
default:
- BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN);
+ BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN);
// LCOV_EXCL_LINE
}
}
}
}