Localizing variables

This commit is contained in:
NHOrus 2017-06-15 16:16:21 +03:00
parent e5f9c4fbea
commit f1f7cfd4e9
6 changed files with 37 additions and 43 deletions

View file

@ -21,9 +21,9 @@ static int attack(FILE *input, long verb, token_t obj)
* enemies, or no enemies but 2 others. */ * enemies, or no enemies but 2 others. */
{ {
int spk = ACTSPK[verb]; int spk = ACTSPK[verb];
int i = ATDWRF(game.loc); int d = ATDWRF(game.loc);
if (obj == 0) { if (obj == 0) {
if (i > 0) if (d > 0)
obj=DWARF; obj=DWARF;
if (HERE(SNAKE))obj=obj*NOBJECTS+SNAKE; if (HERE(SNAKE))obj=obj*NOBJECTS+SNAKE;
if (AT(DRAGON) && game.prop[DRAGON] == 0)obj=obj*NOBJECTS+DRAGON; 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 == DRAGON)spk=ALREADY_DEAD;
if (obj == TROLL)spk=ROCKY_TROLL; if (obj == TROLL)spk=ROCKY_TROLL;
if (obj == OGRE)spk=OGRE_DOFGE; if (obj == OGRE)spk=OGRE_DOFGE;
if (obj == OGRE && i > 0) { if (obj == OGRE && d > 0) {
RSPEAK(spk); RSPEAK(spk);
RSPEAK(KNIFE_THROWN); RSPEAK(KNIFE_THROWN);
DSTROY(OGRE); DSTROY(OGRE);
int k=0; int k=0;
for (i=1; i < PIRATE; i++) { for (int i=1; i < PIRATE; i++) {
if (game.dloc[i] == game.loc) { if (game.dloc[i] == game.loc) {
++k; ++k;
game.dloc[i] = LOC_61; game.dloc[i] = LOC_61;
@ -608,9 +608,8 @@ static int fly(token_t verb, token_t obj)
static int inven(token_t obj) static int inven(token_t obj)
/* Inventory. If object, treat same as find. Else report on current burden. */ /* Inventory. If object, treat same as find. Else report on current burden. */
{ {
int i;
int spk=NO_CARRY; int spk=NO_CARRY;
for (i=1; i<=NOBJECTS; i++) { for (int i=1; i<=NOBJECTS; i++) {
if (i == BEAR || !TOTING(i)) if (i == BEAR || !TOTING(i))
continue; continue;
if (spk == NO_CARRY) if (spk == NO_CARRY)
@ -667,7 +666,7 @@ int light(token_t verb, token_t obj)
static int listen(void) static int listen(void)
/* Listen. Intransitive only. Print stuff based on objsnd/locsnd. */ /* Listen. Intransitive only. Print stuff based on objsnd/locsnd. */
{ {
int i, k; int k;
int spk=ALL_SILENT; int spk=ALL_SILENT;
k=LOCSND[game.loc]; k=LOCSND[game.loc];
if (k != 0) { if (k != 0) {
@ -676,7 +675,7 @@ static int listen(void)
spk=ARB_0; spk=ARB_0;
} }
SETPRM(1,game.zzword,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) if (!HERE(i) || OBJSND[i] == 0 || game.prop[i] < 0)
continue; continue;
PSPEAK(i,OBJSND[i]+game.prop[i]); PSPEAK(i,OBJSND[i]+game.prop[i]);

View file

@ -21,9 +21,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
/* 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 // Global variables for use in functions below that can gradually disappear as code is cleaned up
static long LNLENG; static long LNLENG;
static long LNPOSN; static long LNPOSN;
@ -149,7 +146,6 @@ static void BUG(long NUM) {
} }
static void MAPLIN(FILE *OPENED) { static void MAPLIN(FILE *OPENED) {
size_t i;
/* Read a line of input, from the specified input source, /* Read a line of input, from the specified input source,
* translate the chars to integers in the range 0-126 and store * translate the chars to integers in the range 0-126 and store
* them in the common array "INLINE". Integer values are as follows: * 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] == '#'); while (!feof(OPENED) && INLINE[1] == '#');
LNLENG = 0; 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]; char val = INLINE[i];
INLINE[i] = ascii_to_advent[(unsigned)val]; 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) static void write_file(FILE* header_file)
{ {
int i, MAXDIE; int MAXDIE;
for (i=0; i<=4; i++) { for (int i=0; i<=4; i++) {
long x = 2*i+81; long x = 2*i+81;
if(RTEXT[x] != 0) if(RTEXT[x] != 0)
MAXDIE=i+1; MAXDIE=i+1;

21
init.c
View file

@ -172,20 +172,19 @@
void initialise(void) void initialise(void)
{ {
int i, k;
if (oldstyle) if (oldstyle)
printf("Initialising...\n"); printf("Initialising...\n");
for (i=1; i<=NOBJECTS; i++) { for (int i=1; i<=NOBJECTS; i++) {
game.place[i]=0; game.place[i]=0;
game.prop[i]=0; game.prop[i]=0;
game.link[i+NOBJECTS]=game.link[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; game.abbrev[i]=0;
if (!(locations[i].description.big == 0 || KEY[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; if(MOD(labs(TRAVEL[k]),1000) == 1)COND[i]=2;
} }
game.atloc[i]=0; game.atloc[i]=0;
@ -198,16 +197,16 @@ void initialise(void)
* This also sets up "game.place" and "fixed" as copies of "PLAC" and * This also sets up "game.place" and "fixed" as copies of "PLAC" and
* "FIXD". Also, since two-placed objects are typically best * "FIXD". Also, since two-placed objects are typically best
* described last, we'll drop them first. */ * described last, we'll drop them first. */
for (i=1; i<=NOBJECTS; i++) { for (int i=1; i<=NOBJECTS; i++) {
k=NOBJECTS + 1 - i; int k=NOBJECTS + 1 - i;
if(FIXD[k] > 0) { if(FIXD[k] > 0) {
DROP(k+NOBJECTS,FIXD[k]); DROP(k+NOBJECTS,FIXD[k]);
DROP(k,PLAC[k]); DROP(k,PLAC[k]);
} }
} }
for (i=1; i<=NOBJECTS; i++) { for (int i=1; i<=NOBJECTS; i++) {
k=NOBJECTS + 1 - i; int k=NOBJECTS + 1 - i;
game.fixed[k]=FIXD[k]; game.fixed[k]=FIXD[k];
if(PLAC[k] != 0 && FIXD[k] <= 0) if(PLAC[k] != 0 && FIXD[k] <= 0)
DROP(k,PLAC[k]); DROP(k,PLAC[k]);
@ -218,7 +217,7 @@ void initialise(void)
* they are described. game.tally keeps track of how many are * they are described. game.tally keeps track of how many are
* not yet found, so we know when to close the cave. */ * not yet found, so we know when to close the cave. */
game.tally=0; game.tally=0;
for (i=MINTRS; i<=MAXTRS; i++) { for (int i=MINTRS; i<=MAXTRS; i++) {
if(object_descriptions[i].inventory != 0) if(object_descriptions[i].inventory != 0)
game.prop[i]= -1; game.prop[i]= -1;
game.tally=game.tally-game.prop[i]; 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 /* 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 * with cond bit i. game.hinted[i] is true iff hint i has been
* used. */ * used. */
for (i=1; i<=HNTMAX; i++) { for (int i=1; i<=HNTMAX; i++) {
game.hinted[i]=false; game.hinted[i]=false;
game.hintlc[i]=0; game.hintlc[i]=0;
} }
@ -326,7 +325,7 @@ void initialise(void)
* loc stored in game.chloc2. */ * loc stored in game.chloc2. */
game.chloc = LOC_114; game.chloc = LOC_114;
game.chloc2 = LOC_140; game.chloc2 = LOC_140;
for (i=1; i<=NDWARVES; i++) { for (int i=1; i<=NDWARVES; i++) {
game.dseen[i]=false; game.dseen[i]=false;
} }
game.dflag=0; game.dflag=0;

16
misc.c
View file

@ -105,9 +105,9 @@ void newspeak(char* msg)
{ {
copy[i + 1] = 's'; copy[i + 1] = 's';
packed_to_token(PARMS[pi], parameters[pi]); 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'; copy[i + 1] = 's';
packed_to_token(PARMS[pi], parameters[pi]); 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]); parameters[pi][0] = toupper(parameters[pi][0]);
} }
@ -316,9 +316,9 @@ long VOCAB(long id, long init)
* (Thus "STEPS", which is a motion verb as well as an object, may be located * (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. */ * 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) { if (KTAB[i] == -1) {
lexeme= -1; lexeme= -1;
if (init < 0) if (init < 0)
@ -427,13 +427,13 @@ long ATDWRF(long where)
* there (or if dwarves not active yet), -1 if all dwarves are dead. Ignore * there (or if dwarves not active yet), -1 if all dwarves are dead. Ignore
* the pirate (6th dwarf). */ * the pirate (6th dwarf). */
{ {
long at, i; long at;
at =0; at =0;
if (game.dflag < 2) if (game.dflag < 2)
return(at); return(at);
at = -1; at = -1;
for (i=1; i<=NDWARVES-1; i++) { for (long i=1; i<=NDWARVES-1; i++) {
if (game.dloc[i] == where) if (game.dloc[i] == where)
return i; return i;
if (game.dloc[i] != 0) if (game.dloc[i] != 0)

10
score.c
View file

@ -10,7 +10,7 @@
void score(long mode) void score(long mode)
/* mode is <0 if scoring, >0 if quitting, =0 if died or won */ /* 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: /* The present scoring algorithm is as follows:
* Objective: Points: Present total possible: * 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. /* First tally up the treasures. Must be in building and not broken.
* Give the poor guy 2 points just for finding each treasure. */ * 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) { if(object_descriptions[i].inventory != 0) {
k=12; long k=12;
if(i == CHEST)k=14; if(i == CHEST)k=14;
if(i > CHEST)k=16; if(i > CHEST)k=16;
if(game.prop[i] >= 0) if(game.prop[i] >= 0)
@ -82,7 +82,7 @@ void score(long mode)
mxscor += 2; mxscor += 2;
/* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */ /* 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]) if(game.hinted[i])
score=score-HINTS[i][2]; score=score-HINTS[i][2];
} }
@ -108,7 +108,7 @@ void score(long mode)
SETPRM(1,score,mxscor); SETPRM(1,score,mxscor);
SETPRM(3,game.turns,game.turns); SETPRM(3,game.turns,game.turns);
RSPEAK(TOTAL_SCORE); RSPEAK(TOTAL_SCORE);
for (i=1; i<=CLSSES; i++) { for (long i=1; i<=CLSSES; i++) {
if(CVAL[i] >= score) { if(CVAL[i] >= score) {
newspeak(class_messages[i]); newspeak(class_messages[i]);
i=CVAL[i]+1-score; i=CVAL[i]+1-score;