From 609159ad6d62af90cdbf97cbb09fffabde87a026 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 20 Jul 2017 18:49:08 -0400 Subject: [PATCH] Abolish as many undifferentiated long variables as possible. Simple counter become ints. --- actions.c | 8 ++++---- advent.h | 11 ++++++----- cheat.c | 10 +++++----- main.c | 6 +++--- misc.c | 10 +++++----- score.c | 8 ++++---- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/actions.c b/actions.c index ca243b6..eeec3ea 100644 --- a/actions.c +++ b/actions.c @@ -176,7 +176,7 @@ static int attack(struct command_t *command) return GO_CLEAROBJ; } -static int bigwords(long id) +static int bigwords(vocab_t id) /* FEE FIE FOE FOO (AND FUM). Advance to next state if given in proper order. * Look up foo in special section of vocab to determine which word we've got. * Last word zips the eggs back to the giant room (unless already there). */ @@ -910,7 +910,7 @@ static int light(verb_t verb, obj_t obj) static int listen(void) /* Listen. Intransitive only. Print stuff based on object sound proprties. */ { - long sound = locations[game.loc].sound; + vocab_t sound = locations[game.loc].sound; if (sound != SILENT) { rspeak(sound); if (!locations[game.loc].loud) @@ -1163,7 +1163,7 @@ static int say(struct command_t *command) return GO_CLEAROBJ; } -static int throw_support(long spk) +static int throw_support(vocab_t spk) { rspeak(spk); drop(AXE, game.loc); @@ -1221,7 +1221,7 @@ static int throw (struct command_t *command) if (randrange(NDWARVES + 1) < game.dflag) { return throw_support(DWARF_DODGES); } else { - long i = atdwrf(game.loc); + int i = atdwrf(game.loc); game.dseen[i] = false; game.dloc[i] = LOC_NOWHERE; return throw_support((++game.dkill == 1) ? diff --git a/advent.h b/advent.h index 8ef8736..80f9eaa 100644 --- a/advent.h +++ b/advent.h @@ -114,6 +114,7 @@ typedef long vocab_t; // index into a vocabulary array */ typedef long verb_t; // index into an actions array */ typedef long obj_t; // index into the object array */ typedef long loc_t; // index into the locations array */ +typedef long turn_t; // turn counter or threshold */ struct game_t { unsigned long lcg_a, lcg_c, lcg_m, lcg_x; @@ -157,9 +158,9 @@ struct game_t { long saved; // point penalty for saves long tally; // count of treasures gained long thresh; // current threshold for endgame scoring tier - long trndex; // FIXME: not used, remove on next format bump - long trnluz; // # points lost so far due to turns used - long turns; // counts commands given (ignores yes/no) + turn_t trndex; // FIXME: not used, remove on next format bump + turn_t trnluz; // # points lost so far due to turns used + turn_t turns; // counts commands given (ignores yes/no) bool wzdark; // whether the loc he's leaving was dark char zzword[TOKLEN + 1]; // randomly generated magic word from bird bool blooded; // has player drunk of dragon's blood? @@ -203,7 +204,7 @@ extern struct settings_t settings; extern bool get_command_input(struct command_t *); extern void wordclear(token_t *); extern void speak(const char*, ...); -extern void sspeak(long msg, ...); +extern void sspeak(int msg, ...); extern void pspeak(vocab_t, enum speaktype, int, bool, ...); extern void rspeak(vocab_t, ...); extern void echo_input(FILE*, const char*, const char*); @@ -211,7 +212,7 @@ extern bool silent_yes(void); extern bool yes(const char*, const char*, const char*); extern void juggle(obj_t); extern void move(obj_t, loc_t); -extern long put(obj_t, long, long); +extern loc_t put(obj_t, long, long); extern void carry(obj_t, loc_t); extern void drop(obj_t, loc_t); extern long atdwrf(loc_t); diff --git a/cheat.c b/cheat.c index b07b102..96ef4c3 100644 --- a/cheat.c +++ b/cheat.c @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) { int ch; char *savefilename = NULL; - long version = 0; + int version = 0; FILE *fp = NULL; // Initialize game variables @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) printf("cheat: game.numdie = %ld\n", game.numdie); break; case 'l': - game.limit = (long)atoi(optarg); + game.limit = (turn_t)atoi(optarg); printf("cheat: game.limit = %ld\n", game.limit); break; case 's': @@ -50,12 +50,12 @@ int main(int argc, char *argv[]) printf("cheat: game.saved = %ld\n", game.saved); break; case 't': - game.turns = (long)atoi(optarg); + game.turns = (turn_t)atoi(optarg); printf("cheat: game.turns = %ld\n", game.turns); break; case 'v': - version = (long)atoi(optarg); - printf("cheat: version = %ld\n", version); + version = atoi(optarg); + printf("cheat: version = %d\n", version); break; case 'o': savefilename = optarg; diff --git a/main.c b/main.c index 4d5f6a9..a42fe3e 100644 --- a/main.c +++ b/main.c @@ -318,7 +318,7 @@ static bool dwarfmove(void) /* Dwarves move. Return true if player survives, false if he dies. */ { int kk, stick, attack; - long tk[21]; + loc_t tk[21]; /* Dwarf stuff. See earlier comments for description of * variables. Remember sixth dwarf is pirate and is thus @@ -508,7 +508,7 @@ static void croak(void) } } -static bool traveleq(long a, long b) +static bool traveleq(int a, int b) /* Are two travel entries equal for purposes of skip after failed condition? */ { return (travel[a].condtype == travel[b].condtype) @@ -947,7 +947,7 @@ static void listobjects(void) if (!DARK(game.loc)) { ++game.abbrev[game.loc]; for (int i = game.atloc[game.loc]; i != 0; i = game.link[i]) { - long obj = i; + obj_t obj = i; if (obj > NOBJECTS) obj = obj - NOBJECTS; if (obj == STEPS && TOTING(NUGGET)) diff --git a/misc.c b/misc.c index 6f4aa49..8f273e9 100644 --- a/misc.c +++ b/misc.c @@ -121,7 +121,7 @@ void speak(const char* msg, ...) va_end(ap); } -void sspeak(const long msg, ...) +void sspeak(const int msg, ...) { va_list ap; va_start(ap, msg); @@ -402,7 +402,7 @@ static int get_special_vocab_id(const char* word) return (WORD_NOT_FOUND); } -static void get_vocab_metadata(const char* word, long* id, enum wordtype* type) +static void get_vocab_metadata(const char* word, vocab_t* id, enum wordtype* type) { /* Check for an empty string */ if (strncmp(word, "", sizeof("")) == 0) { @@ -411,7 +411,7 @@ static void get_vocab_metadata(const char* word, long* id, enum wordtype* type) return; } - long ref_num; + vocab_t ref_num; ref_num = get_motion_vocab_id(word); if (ref_num != WORD_NOT_FOUND) { @@ -535,7 +535,7 @@ void move(obj_t object, loc_t where) * pick up objects which are not at any loc, since carry wants to * remove objects from game.atloc chains. */ { - long from; + loc_t from; if (object > NOBJECTS) from = game.fixed[object - NOBJECTS]; @@ -547,7 +547,7 @@ void move(obj_t object, loc_t where) drop(object, where); } -long put(obj_t object, loc_t where, long pval) +loc_t put(obj_t object, loc_t where, long pval) /* put() is the same as move(), except it returns a value used to set up the * negated game.prop values for the repository objects. */ { diff --git a/score.c b/score.c index 8bd3cce..ba7d98b 100644 --- a/score.c +++ b/score.c @@ -6,13 +6,13 @@ * scoring and wrap-up */ -static long mxscor; /* ugh..the price for having score() not exit. */ +static int mxscor; /* ugh..the price for having score() not exit. */ long score(enum termination mode) /* mode is 'scoregame' if scoring, 'quitgame' if quitting, 'endgame' if died * or won */ { - long score = 0; + int score = 0; /* The present scoring algorithm is as follows: * Objective: Points: Present total possible: @@ -40,7 +40,7 @@ long score(enum termination mode) if (!objects[i].is_treasure) continue; if (objects[i].inventory != 0) { - long k = 12; + int k = 12; if (i == CHEST) k = 14; if (i > CHEST) @@ -92,7 +92,7 @@ long score(enum termination mode) mxscor += 2; /* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */ - for (long i = 0; i < NHINTS; i++) { + for (int i = 0; i < NHINTS; i++) { if (game.hinted[i]) score = score - hints[i].penalty; } -- 2.31.1