++changes;
}
}
- if (changes >= 2)
+ if (changes >= 2) {
return GO_UNKNOWN;
+ }
}
if (obj == BIRD) {
drop(BLOOD, LOC_SECRET5);
for (obj_t i = 1; i <= NOBJECTS; i++) {
if (game.objects[i].place == objects[DRAGON].plac ||
- game.objects[i].place == objects[DRAGON].fixd)
+ game.objects[i].place == objects[DRAGON].fixd) {
move(i, LOC_SECRET5);
+ }
}
game.loc = LOC_SECRET5;
return GO_MOVE;
* before crossing. */
if (game.objects[EGGS].place == LOC_NOWHERE &&
game.objects[TROLL].place == LOC_NOWHERE &&
- game.objects[TROLL].prop == TROLL_UNPAID)
+ game.objects[TROLL].prop == TROLL_UNPAID) {
game.objects[TROLL].prop = TROLL_PAIDONCE;
+ }
if (HERE(EGGS)) {
pspeak(EGGS, look, true, EGGS_VANISHED);
} else if (game.loc == objects[EGGS].plac) {
static void blast(void) {
/* Blast. No effect unless you've got dynamite, which is a neat trick!
*/
- if (PROP_IS_NOTFOUND(ROD2) || !game.closed)
+ if (PROP_IS_NOTFOUND(ROD2) || !game.closed) {
rspeak(REQUIRES_DYNAMITE);
- else {
+ } else {
if (HERE(ROD2)) {
game.bonus = splatter;
rspeak(SPLATTER_MESSAGE);
}
case VASE:
if (game.objects[VASE].prop == VASE_WHOLE) {
- if (TOTING(VASE))
+ if (TOTING(VASE)) {
drop(VASE, game.loc);
+ }
state_change(VASE, VASE_BROKEN);
game.objects[VASE].fixed = IS_FIXED;
break;
}
game.objects[CHAIN].prop = CHAIN_HEAP;
game.objects[CHAIN].fixed = IS_FREE;
- if (game.objects[BEAR].prop != BEAR_DEAD)
+ if (game.objects[BEAR].prop != BEAR_DEAD) {
game.objects[BEAR].prop = CONTENTED_BEAR;
+ }
switch (game.objects[BEAR].prop) {
// LCOV_EXCL_START
game.objects[CHAIN].prop = CHAIN_FIXED;
- if (TOTING(CHAIN))
+ if (TOTING(CHAIN)) {
drop(CHAIN, game.loc);
+ }
game.objects[CHAIN].fixed = IS_FIXED;
rspeak(CHAIN_LOCKED);
*/
switch (obj) {
case INTRANSITIVE:
- if (!HERE(FOOD))
+ if (!HERE(FOOD)) {
return GO_UNKNOWN;
+ }
/* FALLTHRU */
case FOOD:
DESTROY(FOOD);
speak(actions[verb].message);
return GO_CLEAROBJ;
}
- if (obj == INTRANSITIVE && !HERE(BOTTLE))
+ if (obj == INTRANSITIVE && !HERE(BOTTLE)) {
return GO_UNKNOWN;
+ }
if (HERE(URN) && game.objects[URN].prop != URN_EMPTY) {
rspeak(URN_NOPOUR);
* burden. */
bool empty = true;
for (obj_t i = 1; i <= NOBJECTS; i++) {
- if (i == BEAR || !TOTING(i))
+ if (i == BEAR || !TOTING(i)) {
continue;
+ }
if (empty) {
rspeak(NOW_HOLDING);
empty = false;
}
pspeak(i, touch, false, -1);
}
- if (TOTING(BEAR))
+ if (TOTING(BEAR)) {
rspeak(TAME_BEAR);
- if (empty)
+ }
+ if (empty) {
rspeak(NO_CARRY);
+ }
return GO_CLEAROBJ;
}
obj = URN;
selects++;
}
- if (selects != 1)
+ if (selects != 1) {
return GO_UNKNOWN;
+ }
}
switch (obj) {
state_change(RESER, game.objects[RESER].prop == WATERS_PARTED
? WATERS_UNPARTED
: WATERS_PARTED);
- if (AT(RESER))
+ if (AT(RESER)) {
return GO_CLEAROBJ;
- else {
+ } else {
game.oldlc2 = game.loc;
game.newloc = LOC_NOWHERE;
rspeak(NOT_BRIGHT);
} else {
if (atdwrf(game.loc) <= 0) {
if (AT(DRAGON) &&
- game.objects[DRAGON].prop == DRAGON_BARS)
+ game.objects[DRAGON].prop == DRAGON_BARS) {
return throw_support(DRAGON_SCALES);
+ }
if (AT(TROLL)) {
return throw_support(TROLL_RETURNS);
}
: FREE_FLY);
return GO_CLEAROBJ;
}
- if (HERE(BIRD))
+ if (HERE(BIRD)) {
rspeak((game.objects[BIRD].prop == BIRD_CAGED)
? CAGE_FLY
: FREE_FLY);
+ }
state_change(FISSURE, game.objects[FISSURE].prop == BRIDGED
? UNBRIDGED
/* dflag controls the level of activation of dwarves:
* 0 No dwarf stuff yet (wait until reaches Hall Of Mists)
* 1 Reached Hall Of Mists, but hasn't met first dwarf
- * 2 Met first dwarf, others start moving, no knives thrown
- *yet 3 A knife has been thrown (first set always misses) 3+
- *Dwarves are mad (increases their accuracy) */
+ * 2 Met 1t dwarf, others start moving, no knives thrown yet
+ * 3 A knife has been thrown (first set always misses) 3+
+ * Dwarves are mad (increases their accuracy) */
int32_t dflag;
int32_t dkill; // dwarves killed
};
int initialise(void) {
- if (settings.oldstyle)
+ if (settings.oldstyle) {
printf("Initialising...\n");
+ }
srand(time(NULL));
int seedval = (int)rand();
// exclude from coverage analysis because it requires interactivity to test
static void sig_handler(int signo) {
if (signo == SIGINT) {
- if (settings.logfp != NULL)
+ if (settings.logfp != NULL) {
fflush(settings.logfp);
+ }
}
#if defined ADVENT_AUTOSAVE
NO_OBJECT &&
game.locs[game.oldlc2].atloc ==
NO_OBJECT &&
- game.holdng > 1)
+ game.holdng > 1) {
break;
+ }
game.hints[hint].lc = 0;
return;
case 4: /* dark */
game.locs[game.oldloc].atloc ==
NO_OBJECT &&
game.locs[game.oldlc2].atloc ==
- NO_OBJECT)
+ NO_OBJECT) {
break;
+ }
return;
case 8: /* ogre */
i = atdwrf(game.loc);
/* Dwarf activity level ratchets up */
if (game.dflag == 0) {
- if (INDEEP(game.loc))
+ if (INDEEP(game.loc)) {
game.dflag = 1;
+ }
return true;
}
/* Fill tk array with all the places this dwarf might go. */
unsigned int j = 1;
kk = tkey[game.dwarves[i].loc];
- if (kk != 0)
+ if (kk != 0) {
do {
enum desttype_t desttype = travel[kk].desttype;
game.newloc = travel[kk].destval;
/* Have we avoided a dwarf encounter? */
- if (desttype != dest_goto)
+ if (desttype != dest_goto) {
continue;
- else if (!INDEEP(game.newloc))
+ } else if (!INDEEP(game.newloc)) {
continue;
- else if (game.newloc == game.dwarves[i].oldloc)
+ } else if (game.newloc ==
+ game.dwarves[i].oldloc) {
continue;
- else if (j > 1 && game.newloc == tk[j - 1])
+ } else if (j > 1 && game.newloc == tk[j - 1]) {
continue;
- else if (j >= DIM(tk) - 1)
+ } else if (j >= DIM(tk) - 1) {
/* This can't actually happen. */
continue; // LCOV_EXCL_LINE
- else if (game.newloc == game.dwarves[i].loc)
+ } else if (game.newloc == game.dwarves[i].loc) {
continue;
- else if (FORCED(game.newloc))
+ } else if (FORCED(game.newloc)) {
continue;
- else if (i == PIRATE &&
- CNDBIT(game.newloc, COND_NOARRR))
+ } else if (i == PIRATE &&
+ CNDBIT(game.newloc, COND_NOARRR)) {
continue;
- else if (travel[kk].nodwarves)
+ } else if (travel[kk].nodwarves) {
continue;
+ }
tk[j++] = game.newloc;
} while (!travel[kk++].stop);
+ }
tk[j] = game.dwarves[i].oldloc;
if (j >= 2) {
--j;
* where he died. */
game.objects[WATER].place = game.objects[OIL].place =
LOC_NOWHERE;
- if (TOTING(LAMP))
+ if (TOTING(LAMP)) {
game.objects[LAMP].prop = LAMP_DARK;
+ }
for (int j = 1; j <= NOBJECTS; j++) {
int i = NOBJECTS + 1 - j;
if (TOTING(i)) {
const char *msg = locations[game.loc].description.small;
if (MOD(game.locs[game.loc].abbrev, game.abbnum) == 0 ||
- msg == NO_MESSAGE)
+ msg == NO_MESSAGE) {
msg = locations[game.loc].description.big;
+ }
if (!FORCED(game.loc) && DARK(game.loc)) {
msg = arbitrary_messages[PITCH_DARK];
speak(msg);
- if (game.loc == LOC_Y2 && PCT(25) && !game.closng)
+ if (game.loc == LOC_Y2 && PCT(25) && !game.closng) {
rspeak(SAYS_PLUGH);
+ }
}
static bool traveleq(int a, int b) {
* forced-motion. te_tmp saves entry -> forced loc -> previous
* loc. */
motion = game.oldloc;
- if (FORCED(motion))
+ if (FORCED(motion)) {
motion = game.oldlc2;
+ }
game.oldlc2 = game.oldloc;
game.oldloc = game.loc;
if (CNDBIT(game.loc, COND_NOBACK)) {
if (desttype == dest_goto) {
if (FORCED(scratchloc) &&
travel[tkey[scratchloc]].destval ==
- motion)
+ motion) {
te_tmp = travel_entry;
+ }
}
if (!travel[travel_entry].stop) {
++travel_entry; /* go to next travel
* indexes the beginning of the motion entries for here (game.loc). */
for (;;) {
if ((travel[travel_entry].motion == HERE) ||
- travel[travel_entry].motion == motion)
+ travel[travel_entry].motion == motion) {
break;
+ }
if (travel[travel_entry].stop) {
/* Couldn't find an entry matching the motion word
* passed in. Various messages depending on word given.
if (condtype == cond_goto ||
condtype == cond_pct) {
if (condarg1 == 0 ||
- PCT(condarg1))
+ PCT(condarg1)) {
break;
+ }
/* else fall through */
}
/* YAML [with OBJ] clause */
else if (TOTING(condarg1) ||
(condtype == cond_with &&
- AT(condarg1)))
+ AT(condarg1))) {
break;
+ }
/* else fall through to check [not OBJ
* STATE] */
} else if (game.objects[condarg1].prop !=
* Skip to next non-matching destination */
int te_tmp = travel_entry;
do {
- if (travel[te_tmp].stop)
+ if (travel[te_tmp].stop) {
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
+ }
++te_tmp;
} while (traveleq(travel_entry, te_tmp));
travel_entry = te_tmp;
{
int te_tmp = travel_entry;
do {
- if (travel[te_tmp].stop)
+ if (travel[te_tmp]
+ .stop) {
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
+ }
++te_tmp;
} while (traveleq(travel_entry,
te_tmp));
objects[TROLL].fixd -
game.loc;
if (game.objects[TROLL].prop ==
- TROLL_UNPAID)
+ TROLL_UNPAID) {
game.objects[TROLL]
.prop =
TROLL_PAIDONCE;
+ }
if (!TOTING(BEAR)) {
return;
}
game.clock1 = -1;
game.closng = true;
return game.closed;
- } else if (game.clock1 < 0)
+ } else if (game.clock1 < 0) {
--game.clock2;
+ }
if (game.clock2 == 0) {
/* Once he's panicked, and clock2 has run out, we come here
* to set up the storage room. The room has two locs,
/* If no word type is given for the first word, we assume it's a
* motion. */
- if (command->word[0].type == NO_WORD_TYPE)
+ if (command->word[0].type == NO_WORD_TYPE) {
command->word[0].type = MOTION;
+ }
command->state = PREPROCESSED;
return true;
}
for (size_t i = 1; i <= NOBJECTS; i++) {
if (TOTING(i) && (PROP_IS_NOTFOUND(i) ||
- PROP_IS_STASHED(i)))
+ PROP_IS_STASHED(i))) {
game.objects[i].prop =
PROP_STASHED(i);
+ }
}
}
game.novice = yes_or_no(arbitrary_messages[WELCOME_YOU],
arbitrary_messages[CAVE_NEARBY],
arbitrary_messages[NO_MESSAGE]);
- if (game.novice)
+ if (game.novice) {
game.limit = NOVICELIMIT;
+ }
#endif
if (settings.logfp) {
int count = 0;
int inblanks = true;
- for (char *s = str; *s; s++)
+ for (char *s = str; *s; s++) {
if (inblanks) {
if (strchr(delims, *s) == 0) {
++count;
inblanks = true;
}
}
+ }
return (count);
}
static char *get_input(void) {
// Set up the prompt
char input_prompt[] = PROMPT;
- if (!settings.prompt)
+ if (!settings.prompt) {
input_prompt[0] = '\0';
+ }
// Print a blank line
printf("\n");
for (;;) {
input = myreadline(input_prompt);
- if (input == NULL) // Got EOF; return with it.
+ if (input == NULL) { // Got EOF; return with it.
return (input);
+ }
if (input[0] == '#') { // Ignore comments.
free(input);
continue;
add_history(input);
- if (!isatty(0))
+ if (!isatty(0)) {
echo_input(stdout, input_prompt, input);
+ }
- if (settings.logfp)
+ if (settings.logfp) {
echo_input(settings.logfp, "", input);
+ }
return (input);
}
free(reply);
- for (int i = 0; i < (int)strlen(firstword); ++i)
+ for (int i = 0; i < (int)strlen(firstword); ++i) {
firstword[i] = tolower(firstword[i]);
+ }
int yes = strncmp("yes", firstword, sizeof("yes") - 1);
int y = strncmp("y", firstword, sizeof("y") - 1);
} else if (no == 0 || n == 0) {
outcome = false;
break;
- } else
+ } else {
rspeak(PLEASE_ANSWER);
+ }
}
return (outcome);
}
speak(no_response);
outcome = false;
break;
- } else
+ } else {
rspeak(PLEASE_ANSWER);
+ }
}
return (outcome);
TOKLEN) == 0 &&
(strlen(word) > 1 ||
strchr(ignore, word[0]) == NULL ||
- !settings.oldstyle))
+ !settings.oldstyle)) {
return (i);
+ }
}
}
// If execution reaches here, we didn't find the word.
// removed
for (int j = 0; j < objects[i].words.n; ++j) {
if (strncasecmp(word, objects[i].words.strs[j],
- TOKLEN) == 0)
+ TOKLEN) == 0) {
return (i);
+ }
}
}
// If execution reaches here, we didn't find the word.
for (;;) {
input = get_input();
- if (input == NULL)
+ if (input == NULL) {
return false;
+ }
if (word_count(input) > 2) {
rspeak(TWO_WORDS);
free(input);
*
* Possibly this check should be skipped whwn oldstyle is on.
*/
- if (object != BIRD)
+ if (object != BIRD) {
++game.holdng;
+ }
}
if (game.locs[where].atloc == object) {
game.locs[where].atloc = game.link[object];
if (object > NOBJECTS) {
game.objects[object - NOBJECTS].fixed = where;
} else {
- if (game.objects[object].place == CARRIED)
- if (object != BIRD)
+ if (game.objects[object].place == CARRIED) {
+ if (object != BIRD) {
/* The bird has to be weightless. This ugly
* hack (and the corresponding code in the carry
* function) brought to you by the fact that
* the right thing happen.
*/
--game.holdng;
+ }
+ }
game.objects[object].place = where;
}
if (where == LOC_NOWHERE || where == CARRIED) {
while (fp == NULL) {
char *name = myreadline("\nFile name: ");
- if (name == NULL)
+ if (name == NULL) {
return GO_TOP;
+ }
name = strip(name);
- if (strlen(name) == 0)
+ if (strlen(name) == 0) {
return GO_TOP; // LCOV_EXCL_LINE
+ }
fp = fopen(name, READ_MODE);
if (fp == NULL) {
printf("Can't open file %s, try again.\n", name);