From 0175344caaadc9a7c80c17834f8b21b490a102a1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 29 Jan 2024 12:14:56 -0500 Subject: [PATCH] 1TBS reflow, the bracening. --- actions.c | 50 +++++++++++++++++++------------ advent.h | 6 ++-- init.c | 3 +- main.c | 83 +++++++++++++++++++++++++++++++++------------------- misc.c | 42 +++++++++++++++++--------- saveresume.c | 6 ++-- 6 files changed, 122 insertions(+), 68 deletions(-) diff --git a/actions.c b/actions.c index 97e5a48..31a09c8 100644 --- a/actions.c +++ b/actions.c @@ -66,8 +66,9 @@ static phase_codes_t attack(command_t command) { ++changes; } } - if (changes >= 2) + if (changes >= 2) { return GO_UNKNOWN; + } } if (obj == BIRD) { @@ -128,8 +129,9 @@ static phase_codes_t attack(command_t command) { 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; @@ -215,8 +217,9 @@ static phase_codes_t bigwords(vocab_t id) { * 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) { @@ -243,9 +246,9 @@ static phase_codes_t bigwords(vocab_t id) { 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); @@ -274,8 +277,9 @@ static phase_codes_t vbreak(verb_t verb, obj_t obj) { } 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; @@ -435,8 +439,9 @@ static int chain(verb_t verb) { } 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 @@ -465,8 +470,9 @@ static int chain(verb_t verb) { 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); @@ -622,8 +628,9 @@ static phase_codes_t eat(verb_t verb, obj_t obj) { */ switch (obj) { case INTRANSITIVE: - if (!HERE(FOOD)) + if (!HERE(FOOD)) { return GO_UNKNOWN; + } /* FALLTHRU */ case FOOD: DESTROY(FOOD); @@ -797,8 +804,9 @@ phase_codes_t fill(verb_t verb, obj_t obj) { 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); @@ -891,18 +899,21 @@ static phase_codes_t inven(void) { * 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; } @@ -919,8 +930,9 @@ static phase_codes_t light(verb_t verb, obj_t obj) { obj = URN; selects++; } - if (selects != 1) + if (selects != 1) { return GO_UNKNOWN; + } } switch (obj) { @@ -1181,9 +1193,9 @@ static phase_codes_t reservoir(void) { 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); @@ -1266,8 +1278,9 @@ static phase_codes_t throwit(command_t command) { } 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); } @@ -1357,10 +1370,11 @@ static phase_codes_t wave(verb_t verb, obj_t obj) { : 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 diff --git a/advent.h b/advent.h index b263645..2a23eb9 100644 --- a/advent.h +++ b/advent.h @@ -221,9 +221,9 @@ struct game_t { /* 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 diff --git a/init.c b/init.c index d00255d..e413fff 100644 --- a/init.c +++ b/init.c @@ -27,8 +27,9 @@ struct game_t game = { }; int initialise(void) { - if (settings.oldstyle) + if (settings.oldstyle) { printf("Initialising...\n"); + } srand(time(NULL)); int seedval = (int)rand(); diff --git a/main.c b/main.c index cff0780..7f5d8a1 100644 --- a/main.c +++ b/main.c @@ -31,8 +31,9 @@ void autosave(void) { // 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 @@ -145,8 +146,9 @@ static void checkhints(void) { 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 */ @@ -170,8 +172,9 @@ static void checkhints(void) { 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); @@ -323,8 +326,9 @@ static bool dwarfmove(void) { /* Dwarf activity level ratchets up */ if (game.dflag == 0) { - if (INDEEP(game.loc)) + if (INDEEP(game.loc)) { game.dflag = 1; + } return true; } @@ -373,33 +377,36 @@ static bool dwarfmove(void) { /* 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; @@ -502,8 +509,9 @@ static void croak(void) { * 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)) { @@ -521,8 +529,9 @@ static void describe_location(void) { 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]; @@ -534,8 +543,9 @@ static void describe_location(void) { 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) { @@ -569,8 +579,9 @@ static void playermove(int motion) { * 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)) { @@ -591,8 +602,9 @@ static void playermove(int motion) { 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 @@ -641,8 +653,9 @@ static void playermove(int motion) { * 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. @@ -699,15 +712,17 @@ static void playermove(int motion) { 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 != @@ -719,8 +734,9 @@ static void playermove(int motion) { * 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; @@ -771,8 +787,10 @@ static void playermove(int motion) { { 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)); @@ -814,10 +832,11 @@ static void playermove(int motion) { objects[TROLL].fixd - game.loc; if (game.objects[TROLL].prop == - TROLL_UNPAID) + TROLL_UNPAID) { game.objects[TROLL] .prop = TROLL_PAIDONCE; + } if (!TOTING(BEAR)) { return; } @@ -962,8 +981,9 @@ static bool closecheck(void) { 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, @@ -1159,8 +1179,9 @@ static bool preprocess_command(command_t *command) { /* 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; @@ -1252,9 +1273,10 @@ static bool do_command(void) { } 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); + } } } @@ -1534,8 +1556,9 @@ int main(int argc, char *argv[]) { 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) { diff --git a/misc.c b/misc.c index ad110d9..9e90d05 100644 --- a/misc.c +++ b/misc.c @@ -195,7 +195,7 @@ static int word_count(char *str) { 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; @@ -206,6 +206,7 @@ static int word_count(char *str) { inblanks = true; } } + } return (count); } @@ -213,8 +214,9 @@ static int word_count(char *str) { 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"); @@ -223,8 +225,9 @@ static char *get_input(void) { 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; @@ -238,11 +241,13 @@ static char *get_input(void) { 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); } @@ -270,8 +275,9 @@ bool silent_yes_or_no(void) { 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); @@ -286,8 +292,9 @@ bool silent_yes_or_no(void) { } else if (no == 0 || n == 0) { outcome = false; break; - } else + } else { rspeak(PLEASE_ANSWER); + } } return (outcome); } @@ -340,8 +347,9 @@ bool yes_or_no(const char *question, const char *yes_response, speak(no_response); outcome = false; break; - } else + } else { rspeak(PLEASE_ANSWER); + } } return (outcome); @@ -357,8 +365,9 @@ static int get_motion_vocab_id(const char *word) { 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. @@ -372,8 +381,9 @@ static int get_object_vocab_id(const char *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. @@ -529,8 +539,9 @@ bool get_command_input(command_t *command) { for (;;) { input = get_input(); - if (input == NULL) + if (input == NULL) { return false; + } if (word_count(input) > 2) { rspeak(TWO_WORDS); free(input); @@ -637,8 +648,9 @@ void carry(obj_t object, loc_t where) { * * 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]; @@ -658,8 +670,8 @@ void drop(obj_t object, loc_t where) { 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 @@ -668,6 +680,8 @@ void drop(obj_t object, loc_t where) { * the right thing happen. */ --game.holdng; + } + } game.objects[object].place = where; } if (where == LOC_NOWHERE || where == CARRIED) { diff --git a/saveresume.c b/saveresume.c index ea30e4d..9822b76 100644 --- a/saveresume.c +++ b/saveresume.c @@ -127,11 +127,13 @@ int resume(void) { 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); -- 2.31.1