From: NHOrus Date: Thu, 15 Jun 2017 13:16:21 +0000 (+0300) Subject: Localizing variables X-Git-Tag: 1.1~297 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=f1f7cfd4e95d7c7e0022a320e6979403fc0a096b;p=open-adventure.git Localizing variables --- diff --git a/actions.c b/actions.c index a69dbc5..0256bd1 100644 --- a/actions.c +++ b/actions.c @@ -21,9 +21,9 @@ static int attack(FILE *input, long verb, token_t obj) * enemies, or no enemies but 2 others. */ { int spk = ACTSPK[verb]; - int i = ATDWRF(game.loc); + int d = ATDWRF(game.loc); if (obj == 0) { - if (i > 0) + if (d > 0) obj=DWARF; if (HERE(SNAKE))obj=obj*NOBJECTS+SNAKE; if (AT(DRAGON) && game.prop[DRAGON] == 0)obj=obj*NOBJECTS+DRAGON; @@ -66,12 +66,12 @@ static int attack(FILE *input, long verb, token_t obj) if (obj == DRAGON)spk=ALREADY_DEAD; if (obj == TROLL)spk=ROCKY_TROLL; if (obj == OGRE)spk=OGRE_DOFGE; - if (obj == OGRE && i > 0) { + if (obj == OGRE && d > 0) { RSPEAK(spk); RSPEAK(KNIFE_THROWN); DSTROY(OGRE); int k=0; - for (i=1; i < PIRATE; i++) { + for (int i=1; i < PIRATE; i++) { if (game.dloc[i] == game.loc) { ++k; game.dloc[i] = LOC_61; @@ -604,13 +604,12 @@ static int fly(token_t verb, token_t obj) RSPEAK(spk); return GO_TERMINATE; } - + static int inven(token_t obj) /* Inventory. If object, treat same as find. Else report on current burden. */ { - int i; int spk=NO_CARRY; - for (i=1; i<=NOBJECTS; i++) { + for (int i=1; i<=NOBJECTS; i++) { if (i == BEAR || !TOTING(i)) continue; if (spk == NO_CARRY) @@ -661,13 +660,13 @@ int light(token_t verb, token_t obj) return GO_TOP; else return GO_CLEAROBJ; - } + } } static int listen(void) /* Listen. Intransitive only. Print stuff based on objsnd/locsnd. */ { - int i, k; + int k; int spk=ALL_SILENT; k=LOCSND[game.loc]; if (k != 0) { @@ -676,7 +675,7 @@ static int listen(void) spk=ARB_0; } SETPRM(1,game.zzword,0); - for (i=1; i<=NOBJECTS; i++) { + for (int i=1; i<=NOBJECTS; i++) { if (!HERE(i) || OBJSND[i] == 0 || game.prop[i] < 0) continue; PSPEAK(i,OBJSND[i]+game.prop[i]); diff --git a/dungeon.c b/dungeon.c index 9719b94..dfc5b1c 100644 --- a/dungeon.c +++ b/dungeon.c @@ -21,9 +21,6 @@ #include #include -/* hard limit, will be propagated to database.h */ -#define NOBJECTS 100 - // Global variables for use in functions below that can gradually disappear as code is cleaned up static long LNLENG; static long LNPOSN; @@ -149,7 +146,6 @@ static void BUG(long NUM) { } static void MAPLIN(FILE *OPENED) { - size_t i; /* Read a line of input, from the specified input source, * translate the chars to integers in the range 0-126 and store * them in the common array "INLINE". Integer values are as follows: @@ -183,7 +179,7 @@ static void MAPLIN(FILE *OPENED) { while (!feof(OPENED) && INLINE[1] == '#'); LNLENG = 0; - for (i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i) + for (size_t i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i) { char val = INLINE[i]; INLINE[i] = ascii_to_advent[(unsigned)val]; @@ -529,8 +525,8 @@ static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, lo static void write_file(FILE* header_file) { - int i, MAXDIE; - for (i=0; i<=4; i++) { + int MAXDIE; + for (int i=0; i<=4; i++) { long x = 2*i+81; if(RTEXT[x] != 0) MAXDIE=i+1; diff --git a/init.c b/init.c index 3782710..5b1558c 100644 --- a/init.c +++ b/init.c @@ -172,20 +172,19 @@ void initialise(void) { - int i, k; if (oldstyle) printf("Initialising...\n"); - for (i=1; i<=NOBJECTS; i++) { + for (int i=1; i<=NOBJECTS; i++) { game.place[i]=0; game.prop[i]=0; game.link[i+NOBJECTS]=game.link[i]=0; } - for (i=1; i<=LOCSIZ; i++) { + for (int i=1; i<=LOCSIZ; i++) { game.abbrev[i]=0; if (!(locations[i].description.big == 0 || KEY[i] == 0)) { - k=KEY[i]; + int k=KEY[i]; if(MOD(labs(TRAVEL[k]),1000) == 1)COND[i]=2; } game.atloc[i]=0; @@ -198,16 +197,16 @@ void initialise(void) * This also sets up "game.place" and "fixed" as copies of "PLAC" and * "FIXD". Also, since two-placed objects are typically best * described last, we'll drop them first. */ - for (i=1; i<=NOBJECTS; i++) { - k=NOBJECTS + 1 - i; + for (int i=1; i<=NOBJECTS; i++) { + int k=NOBJECTS + 1 - i; if(FIXD[k] > 0) { DROP(k+NOBJECTS,FIXD[k]); DROP(k,PLAC[k]); } } - for (i=1; i<=NOBJECTS; i++) { - k=NOBJECTS + 1 - i; + for (int i=1; i<=NOBJECTS; i++) { + int k=NOBJECTS + 1 - i; game.fixed[k]=FIXD[k]; if(PLAC[k] != 0 && FIXD[k] <= 0) DROP(k,PLAC[k]); @@ -218,7 +217,7 @@ void initialise(void) * they are described. game.tally keeps track of how many are * not yet found, so we know when to close the cave. */ game.tally=0; - for (i=MINTRS; i<=MAXTRS; i++) { + for (int i=MINTRS; i<=MAXTRS; i++) { if(object_descriptions[i].inventory != 0) game.prop[i]= -1; game.tally=game.tally-game.prop[i]; @@ -227,7 +226,7 @@ void initialise(void) /* Clear the hint stuff. game.hintlc[i] is how long he's been at LOC * with cond bit i. game.hinted[i] is true iff hint i has been * used. */ - for (i=1; i<=HNTMAX; i++) { + for (int i=1; i<=HNTMAX; i++) { game.hinted[i]=false; game.hintlc[i]=0; } @@ -326,7 +325,7 @@ void initialise(void) * loc stored in game.chloc2. */ game.chloc = LOC_114; game.chloc2 = LOC_140; - for (i=1; i<=NDWARVES; i++) { + for (int i=1; i<=NDWARVES; i++) { game.dseen[i]=false; } game.dflag=0; diff --git a/main.c b/main.c index 5e8045f..802f7e0 100644 --- a/main.c +++ b/main.c @@ -176,7 +176,7 @@ static void checkhints(FILE *cmdin) ++game.hintlc[hint]; /* Come here if he's been long enough at required loc(s) for some * unused hint. */ - if (game.hintlc[hint] >= HINTS[hint][1]) + if (game.hintlc[hint] >= HINTS[hint][1]) { int i; diff --git a/misc.c b/misc.c index 445740b..b0f24b8 100644 --- a/misc.c +++ b/misc.c @@ -105,9 +105,9 @@ void newspeak(char* msg) { copy[i + 1] = 's'; packed_to_token(PARMS[pi], parameters[pi]); - for (int i = 0; i < strlen(parameters[pi]); ++i) + for (int j = 0; j < strlen(parameters[pi]); ++j) { - parameters[pi][i] = tolower(parameters[pi][i]); + parameters[pi][j] = tolower(parameters[pi][j]); } } @@ -116,9 +116,9 @@ void newspeak(char* msg) { copy[i + 1] = 's'; packed_to_token(PARMS[pi], parameters[pi]); - for (int i = 0; i < strlen(parameters[pi]); ++i) + for (int j = 0; j < strlen(parameters[pi]); ++j) { - parameters[pi][i] = tolower(parameters[pi][i]); + parameters[pi][j] = tolower(parameters[pi][j]); } parameters[pi][0] = toupper(parameters[pi][0]); } @@ -316,16 +316,16 @@ long VOCAB(long id, long init) * (Thus "STEPS", which is a motion verb as well as an object, may be located * as an object.) And it also means the KTAB value is taken modulo 1000. */ { - long i, lexeme; + long lexeme; - for (i=1; i<=TABSIZ; i++) { + for (long i=1; i<=TABSIZ; i++) { if (KTAB[i] == -1) { lexeme= -1; if (init < 0) return(lexeme); BUG(5); } - if (init >= 0 && KTAB[i]/1000 != init) + if (init >= 0 && KTAB[i]/1000 != init) continue; if (ATAB[i] == id) { lexeme=KTAB[i]; @@ -427,13 +427,13 @@ long ATDWRF(long where) * there (or if dwarves not active yet), -1 if all dwarves are dead. Ignore * the pirate (6th dwarf). */ { - long at, i; + long at; at =0; if (game.dflag < 2) return(at); at = -1; - for (i=1; i<=NDWARVES-1; i++) { + for (long i=1; i<=NDWARVES-1; i++) { if (game.dloc[i] == where) return i; if (game.dloc[i] != 0) diff --git a/score.c b/score.c index 3f8d6a2..d49eff8 100644 --- a/score.c +++ b/score.c @@ -10,7 +10,7 @@ void score(long mode) /* mode is <0 if scoring, >0 if quitting, =0 if died or won */ { - long i, k, score = 0, mxscor = 0; + long score = 0, mxscor = 0; /* The present scoring algorithm is as follows: * Objective: Points: Present total possible: @@ -33,9 +33,9 @@ void score(long mode) /* First tally up the treasures. Must be in building and not broken. * Give the poor guy 2 points just for finding each treasure. */ - for (i=MINTRS; i<=MAXTRS; i++) { + for (long i=MINTRS; i<=MAXTRS; i++) { if(object_descriptions[i].inventory != 0) { - k=12; + long k=12; if(i == CHEST)k=14; if(i > CHEST)k=16; if(game.prop[i] >= 0) @@ -82,7 +82,7 @@ void score(long mode) mxscor += 2; /* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */ - for (i=1; i<=HNTMAX; i++) { + for (long i=1; i<=HNTMAX; i++) { if(game.hinted[i]) score=score-HINTS[i][2]; } @@ -108,7 +108,7 @@ void score(long mode) SETPRM(1,score,mxscor); SETPRM(3,game.turns,game.turns); RSPEAK(TOTAL_SCORE); - for (i=1; i<=CLSSES; i++) { + for (long i=1; i<=CLSSES; i++) { if(CVAL[i] >= score) { newspeak(class_messages[i]); i=CVAL[i]+1-score;