Magic-numnber elimination.

This commit is contained in:
Eric S. Raymond 2017-06-15 12:18:37 -04:00
parent a86c67c2ab
commit 14486d67d4
4 changed files with 16 additions and 14 deletions

View file

@ -183,7 +183,7 @@ static int blast(void)
if (HERE(ROD2)) if (HERE(ROD2))
game.bonus=135; game.bonus=135;
RSPEAK(game.bonus); RSPEAK(game.bonus);
score(0); score(endgame);
return GO_CLEAROBJ; /* pacify compiler - we never get here */ return GO_CLEAROBJ; /* pacify compiler - we never get here */
} }
@ -777,7 +777,7 @@ static int quit(FILE *input)
/* Quit. Intransitive only. Verify intent and exit if that's what he wants. */ /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
{ {
if (YES(input,REALLY_QUIT,OK_MAN,OK_MAN)) if (YES(input,REALLY_QUIT,OK_MAN,OK_MAN))
score(1); score(quitgame);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
@ -949,7 +949,7 @@ static int throw(FILE *cmdin, long verb, token_t obj)
static int vscore(void) static int vscore(void)
/* Score. Call scoring routine but tell it to return. */ /* Score. Call scoring routine but tell it to return. */
{ {
score(-1); score(scoregame);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }

View file

@ -108,10 +108,12 @@ extern bool MAPLIN(FILE *);
extern void TYPE(void); extern void TYPE(void);
extern void DATIME(long*, long*); extern void DATIME(long*, long*);
enum termination {endgame, quitgame, scoregame};
extern void set_seed(long); extern void set_seed(long);
extern unsigned long get_next_lcg_value(void); extern unsigned long get_next_lcg_value(void);
extern long randrange(long); extern long randrange(long);
extern void score(long); extern void score(enum termination);
extern int saveresume(FILE *, bool); extern int saveresume(FILE *, bool);
/* /*

11
main.c
View file

@ -49,7 +49,6 @@ bool editline = true;
bool prompt = true; bool prompt = true;
extern void initialise(); extern void initialise();
extern void score(long);
extern int action(FILE *, long, long, long); extern int action(FILE *, long, long, long);
void sig_handler(int signo) void sig_handler(int signo)
@ -141,7 +140,7 @@ int main(int argc, char *argv[])
break; break;
} }
/* show score and exit */ /* show score and exit */
score(1); score(quitgame);
} }
static bool fallback_handler(char *buf) static bool fallback_handler(char *buf)
@ -475,13 +474,13 @@ static void croak(FILE *cmdin)
/* He died during closing time. No resurrection. Tally up a /* He died during closing time. No resurrection. Tally up a
* death and exit. */ * death and exit. */
RSPEAK(DEATH_CLOSING); RSPEAK(DEATH_CLOSING);
score(0); score(endgame);
} else { } else {
/* FIXME: Arithmetic on message numbers */ /* FIXME: Arithmetic on message numbers */
if (!YES(cmdin,WATCH_IT+game.numdie*2,WHICH_WAY+game.numdie*2,OK_MAN)) if (!YES(cmdin,WATCH_IT+game.numdie*2,WHICH_WAY+game.numdie*2,OK_MAN))
score(0); score(endgame);
if (game.numdie == MAXDIE) if (game.numdie == MAXDIE)
score(0); score(endgame);
game.place[WATER]=0; game.place[WATER]=0;
game.place[OIL]=0; game.place[OIL]=0;
if (TOTING(LAMP)) if (TOTING(LAMP))
@ -1107,7 +1106,7 @@ static bool do_command(FILE *cmdin)
case GO_DWARFWAKE: case GO_DWARFWAKE:
/* Oh dear, he's disturbed the dwarves. */ /* Oh dear, he's disturbed the dwarves. */
RSPEAK(DWARVES_AWAKEN); RSPEAK(DWARVES_AWAKEN);
score(0); score(endgame);
return true; return true;
default: default:
BUG(99); BUG(99);

View file

@ -7,8 +7,8 @@
* scoring and wrap-up * scoring and wrap-up
*/ */
void score(long mode) void score(enum termination mode)
/* mode is <0 if scoring, >0 if quitting, =0 if died or won */ /* mode is 'report' if scoring, 'quit' if quitting, 'end' if died or won */
{ {
long score = 0, mxscor = 0; long score = 0, mxscor = 0;
@ -54,7 +54,8 @@ void score(long mode)
* mundane exits or 133, 134, 135 if he blew it (so to speak). */ * mundane exits or 133, 134, 135 if he blew it (so to speak). */
score += (MAXDIE-game.numdie)*10; score += (MAXDIE-game.numdie)*10;
mxscor += MAXDIE*10; mxscor += MAXDIE*10;
if(mode == 0)score += 4; if(mode == endgame)
score += 4;
mxscor += 4; mxscor += 4;
if(game.dflag != 0)score += 25; if(game.dflag != 0)score += 25;
mxscor += 25; mxscor += 25;
@ -93,7 +94,7 @@ void score(long mode)
score=score-game.trnluz-game.saved; score=score-game.trnluz-game.saved;
/* Return to score command if that's where we came from. */ /* Return to score command if that's where we came from. */
if(mode < 0) { if(mode == scoregame) {
SETPRM(1,score,mxscor); SETPRM(1,score,mxscor);
SETPRM(3,game.turns,game.turns); SETPRM(3,game.turns,game.turns);
RSPEAK(GARNERED_POINTS); RSPEAK(GARNERED_POINTS);