Fix some screwy formatting of conditionals...

...probably by the original FOTRAN-to-C translator.
This commit is contained in:
Eric S. Raymond 2023-04-06 21:29:39 -04:00
parent 2f60504e07
commit 829c13d1d5
4 changed files with 28 additions and 61 deletions

View file

@ -243,8 +243,7 @@ static phase_codes_t bigwords(vocab_t id)
static void blast(void) static void blast(void)
/* Blast. No effect unless you've got dynamite, which is a neat trick! */ /* Blast. No effect unless you've got dynamite, which is a neat trick! */
{ {
if (game.prop[ROD2] == STATE_NOTFOUND || if (game.prop[ROD2] == STATE_NOTFOUND || !game.closed)
!game.closed)
rspeak(REQUIRES_DYNAMITE); rspeak(REQUIRES_DYNAMITE);
else { else {
if (HERE(ROD2)) { if (HERE(ROD2)) {
@ -355,10 +354,8 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj)
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
if (obj == WATER || if (obj == WATER || obj == OIL) {
obj == OIL) { if (!HERE(BOTTLE) || LIQUID() != obj) {
if (!HERE(BOTTLE) ||
LIQUID() != obj) {
if (!TOTING(BOTTLE)) { if (!TOTING(BOTTLE)) {
rspeak(NO_CONTAINER); rspeak(NO_CONTAINER);
return GO_CLEAROBJ; return GO_CLEAROBJ;
@ -394,8 +391,7 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj)
} }
game.prop[BIRD] = BIRD_CAGED; game.prop[BIRD] = BIRD_CAGED;
} }
if ((obj == BIRD || if ((obj == BIRD || obj == CAGE) &&
obj == CAGE) &&
(game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) { (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) {
/* expression maps BIRD to CAGE and CAGE to BIRD */ /* expression maps BIRD to CAGE and CAGE to BIRD */
carry(BIRD + CAGE - obj, game.loc); carry(BIRD + CAGE - obj, game.loc);
@ -815,10 +811,8 @@ static phase_codes_t find(verb_t verb, obj_t obj)
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
if (AT(obj) || if (AT(obj) || (LIQUID() == obj && AT(BOTTLE)) ||
(LIQUID() == obj && AT(BOTTLE)) || obj == LIQLOC(game.loc) || (obj == DWARF && atdwrf(game.loc) > 0)) {
obj == LIQLOC(game.loc) ||
(obj == DWARF && atdwrf(game.loc) > 0)) {
rspeak(YOU_HAVEIT); rspeak(YOU_HAVEIT);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
@ -876,8 +870,7 @@ static phase_codes_t inven(void)
{ {
bool empty = true; bool empty = true;
for (obj_t i = 1; i <= NOBJECTS; i++) { for (obj_t i = 1; i <= NOBJECTS; i++) {
if (i == BEAR || if (i == BEAR || !TOTING(i))
!TOTING(i))
continue; continue;
if (empty) { if (empty) {
rspeak(NOW_HOLDING); rspeak(NOW_HOLDING);
@ -942,9 +935,7 @@ static phase_codes_t listen(void)
soundlatch = true; soundlatch = true;
} }
for (obj_t i = 1; i <= NOBJECTS; i++) { for (obj_t i = 1; i <= NOBJECTS; i++) {
if (!HERE(i) || if (!HERE(i) || objects[i].sounds[0] == NULL || game.prop[i] < 0)
objects[i].sounds[0] == NULL ||
game.prop[i] < 0)
continue; continue;
int mi = game.prop[i]; int mi = game.prop[i];
/* (ESR) Some unpleasant magic on object states here. Ideally /* (ESR) Some unpleasant magic on object states here. Ideally
@ -1054,9 +1045,8 @@ static phase_codes_t pour(verb_t verb, obj_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. */
{ {
if (obj == BOTTLE || if (obj == BOTTLE || obj == INTRANSITIVE)
obj == INTRANSITIVE) obj = LIQUID();
obj = LIQUID();
if (obj == NO_OBJECT) if (obj == NO_OBJECT)
return GO_UNKNOWN; return GO_UNKNOWN;
if (!TOTING(obj)) { if (!TOTING(obj)) {
@ -1072,8 +1062,7 @@ static phase_codes_t pour(verb_t verb, obj_t obj)
return fill(verb, URN); return fill(verb, URN);
game.prop[BOTTLE] = EMPTY_BOTTLE; game.prop[BOTTLE] = EMPTY_BOTTLE;
game.place[obj] = LOC_NOWHERE; game.place[obj] = LOC_NOWHERE;
if (!(AT(PLANT) || if (!(AT(PLANT) || AT(DOOR))) {
AT(DOOR))) {
rspeak(GROUND_WET); rspeak(GROUND_WET);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
@ -1112,9 +1101,7 @@ static phase_codes_t read(command_t command)
if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0) if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0)
command.obj = command.obj * NOBJECTS + i; command.obj = command.obj * NOBJECTS + i;
} }
if (command.obj > NOBJECTS || if (command.obj > NOBJECTS || command.obj == NO_OBJECT || DARK(game.loc))
command.obj == NO_OBJECT ||
DARK(game.loc))
return GO_UNKNOWN; return GO_UNKNOWN;
} }
@ -1270,8 +1257,7 @@ static phase_codes_t throwit(command_t command)
static phase_codes_t wake(verb_t verb, obj_t obj) static phase_codes_t wake(verb_t verb, obj_t obj)
/* Wake. Only use is to disturb the dwarves. */ /* Wake. Only use is to disturb the dwarves. */
{ {
if (obj != DWARF || if (obj != DWARF || !game.closed) {
!game.closed) {
speak(actions[verb].message); speak(actions[verb].message);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} else { } else {
@ -1301,11 +1287,7 @@ static phase_codes_t waste(verb_t verb, turn_t turns)
static phase_codes_t wave(verb_t verb, obj_t obj) static phase_codes_t wave(verb_t verb, obj_t obj)
/* Wave. No effect unless waving rod at fissure or at bird. */ /* Wave. No effect unless waving rod at fissure or at bird. */
{ {
if (obj != ROD || if (obj != ROD || !TOTING(obj) || (!HERE(BIRD) && (game.closng || !AT(FISSURE)))) {
!TOTING(obj) ||
(!HERE(BIRD) &&
(game.closng ||
!AT(FISSURE)))) {
speak(((!TOTING(obj)) && (obj != ROD || speak(((!TOTING(obj)) && (obj != ROD ||
!TOTING(ROD2))) ? !TOTING(ROD2))) ?
arbitrary_messages[ARENT_CARRYING] : arbitrary_messages[ARENT_CARRYING] :
@ -1326,8 +1308,7 @@ static phase_codes_t wave(verb_t verb, obj_t obj)
FREE_FLY); FREE_FLY);
return GO_DWARFWAKE; return GO_DWARFWAKE;
} }
if (game.closng || if (game.closng || !AT(FISSURE)) {
!AT(FISSURE)) {
rspeak((game.prop[BIRD] == BIRD_CAGED) ? rspeak((game.prop[BIRD] == BIRD_CAGED) ?
CAGE_FLY : CAGE_FLY :
FREE_FLY); FREE_FLY);
@ -1406,8 +1387,7 @@ phase_codes_t action(command_t command)
* will do here. We're preventing interpretation as an intransitive * will do here. We're preventing interpretation as an intransitive
* verb when the word is unknown. */ * verb when the word is unknown. */
command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT; command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
if (command.obj == NO_OBJECT || if (command.obj == NO_OBJECT || command.obj == INTRANSITIVE) {
command.obj == INTRANSITIVE) {
/* Analyse an intransitive verb (ie, no object given yet). */ /* Analyse an intransitive verb (ie, no object given yet). */
switch (command.verb) { switch (command.verb) {
case CARRY: case CARRY:

3
init.c
View file

@ -57,8 +57,7 @@ int initialise(void)
} }
for (int i = 1; i <= NLOCATIONS; i++) { for (int i = 1; i <= NLOCATIONS; i++) {
if (!(locations[i].description.big == 0 || if (!(locations[i].description.big == 0 || tkey[i] == 0)) {
tkey[i] == 0)) {
int k = tkey[i]; int k = tkey[i];
if (travel[k].motion == HERE) if (travel[k].motion == HERE)
conditions[i] |= (1 << COND_FORCED); conditions[i] |= (1 << COND_FORCED);

25
main.c
View file

@ -199,8 +199,7 @@ static bool spotted_by_pirate(int i)
* that game.place[CHEST] = LOC_NOWHERE might mean that he's thrown * that game.place[CHEST] = LOC_NOWHERE might mean that he's thrown
* it to the troll, but in that case he's seen the chest * it to the troll, but in that case he's seen the chest
* (game.prop[CHEST] == STATE_FOUND). */ * (game.prop[CHEST] == STATE_FOUND). */
if (game.loc == game.chloc || if (game.loc == game.chloc || game.prop[CHEST] != STATE_NOTFOUND)
game.prop[CHEST] != STATE_NOTFOUND)
return true; return true;
int snarfed = 0; int snarfed = 0;
bool movechest = false, robplayer = false; bool movechest = false, robplayer = false;
@ -213,8 +212,7 @@ static bool spotted_by_pirate(int i)
game.loc == objects[EMERALD].plac)) { game.loc == objects[EMERALD].plac)) {
continue; continue;
} }
if (TOTING(treasure) || if (TOTING(treasure) || HERE(treasure))
HERE(treasure))
++snarfed; ++snarfed;
if (TOTING(treasure)) { if (TOTING(treasure)) {
movechest = true; movechest = true;
@ -276,9 +274,7 @@ static bool dwarfmove(void)
* steal return toll, and dwarves can't meet the bear. Also * steal return toll, and dwarves can't meet the bear. Also
* means dwarves won't follow him into dead end in maze, but * means dwarves won't follow him into dead end in maze, but
* c'est la vie. They'll wait for him outside the dead end. */ * c'est la vie. They'll wait for him outside the dead end. */
if (game.loc == LOC_NOWHERE || if (game.loc == LOC_NOWHERE || FORCED(game.loc) || CNDBIT(game.newloc, COND_NOARRR))
FORCED(game.loc) ||
CNDBIT(game.newloc, COND_NOARRR))
return true; return true;
/* Dwarf activity level ratchets up */ /* Dwarf activity level ratchets up */
@ -293,8 +289,7 @@ static bool dwarfmove(void)
* replace him with the alternate. */ * replace him with the alternate. */
if (game.dflag == 1) { if (game.dflag == 1) {
if (!INDEEP(game.loc) || if (!INDEEP(game.loc) ||
(PCT(95) && (!CNDBIT(game.loc, COND_NOBACK) || (PCT(95) && (!CNDBIT(game.loc, COND_NOBACK) || PCT(85))))
PCT(85))))
return true; return true;
game.dflag = 2; game.dflag = 2;
for (int i = 1; i <= 2; i++) { for (int i = 1; i <= 2; i++) {
@ -571,8 +566,7 @@ static void playermove(int motion)
/* Look for a way to fulfil the motion verb passed in - travel_entry indexes /* Look for a way to fulfil the motion verb passed in - travel_entry indexes
* the beginning of the motion entries for here (game.loc). */ * the beginning of the motion entries for here (game.loc). */
for (;;) { for (;;) {
if ((travel[travel_entry].motion == HERE) || if ((travel[travel_entry].motion == HERE) || travel[travel_entry].motion == motion)
travel[travel_entry].motion == motion)
break; break;
if (travel[travel_entry].stop) { if (travel[travel_entry].stop) {
/* Couldn't find an entry matching the motion word passed /* Couldn't find an entry matching the motion word passed
@ -626,14 +620,12 @@ static void playermove(int motion)
if (condtype < cond_not) { if (condtype < cond_not) {
/* YAML N and [pct N] conditionals */ /* YAML N and [pct N] conditionals */
if (condtype == cond_goto || condtype == cond_pct) { if (condtype == cond_goto || condtype == cond_pct) {
if (condarg1 == 0 || if (condarg1 == 0 || PCT(condarg1))
PCT(condarg1))
break; break;
/* else fall through */ /* else fall through */
} }
/* YAML [with OBJ] clause */ /* YAML [with OBJ] clause */
else if (TOTING(condarg1) || else if (TOTING(condarg1) || (condtype == cond_with && AT(condarg1)))
(condtype == cond_with && AT(condarg1)))
break; break;
/* else fall through to check [not OBJ STATE] */ /* else fall through to check [not OBJ STATE] */
} else if (game.prop[condarg1] != condarg2) } else if (game.prop[condarg1] != condarg2)
@ -672,8 +664,7 @@ static void playermove(int motion)
game.newloc = (game.loc == LOC_PLOVER) game.newloc = (game.loc == LOC_PLOVER)
? LOC_ALCOVE ? LOC_ALCOVE
: LOC_PLOVER; : LOC_PLOVER;
if (game.holdng > 1 || if (game.holdng > 1 || (game.holdng == 1 && !TOTING(EMERALD))) {
(game.holdng == 1 && !TOTING(EMERALD))) {
game.newloc = game.loc; game.newloc = game.loc;
rspeak(MUST_DROP); rspeak(MUST_DROP);
} }

9
misc.c
View file

@ -335,13 +335,11 @@ bool yes_or_no(const char* question, const char* yes_response, const char* no_re
free(firstword); free(firstword);
if (yes == 0 || if (yes == 0 || y == 0) {
y == 0) {
speak(yes_response); speak(yes_response);
outcome = true; outcome = true;
break; break;
} else if (no == 0 || } else if (no == 0 || n == 0) {
n == 0) {
speak(no_response); speak(no_response);
outcome = false; outcome = false;
break; break;
@ -656,8 +654,7 @@ void drop(obj_t object, loc_t where)
--game.holdng; --game.holdng;
game.place[object] = where; game.place[object] = where;
} }
if (where == LOC_NOWHERE || if (where == LOC_NOWHERE || where == CARRIED)
where == CARRIED)
return; return;
game.link[object] = game.atloc[where]; game.link[object] = game.atloc[where];
game.atloc[where] = object; game.atloc[where] = object;