From: Eric S. Raymond Date: Thu, 15 Jun 2017 16:18:37 +0000 (-0400) Subject: Magic-numnber elimination. X-Git-Tag: 1.1~293 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=14486d67d447afc40a3c57362a9e37324992452f;p=open-adventure.git Magic-numnber elimination. --- diff --git a/actions.c b/actions.c index 6cd73b5..e88773e 100644 --- a/actions.c +++ b/actions.c @@ -183,7 +183,7 @@ static int blast(void) if (HERE(ROD2)) game.bonus=135; RSPEAK(game.bonus); - score(0); + score(endgame); 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. */ { if (YES(input,REALLY_QUIT,OK_MAN,OK_MAN)) - score(1); + score(quitgame); return GO_CLEAROBJ; } @@ -949,7 +949,7 @@ static int throw(FILE *cmdin, long verb, token_t obj) static int vscore(void) /* Score. Call scoring routine but tell it to return. */ { - score(-1); + score(scoregame); return GO_CLEAROBJ; } diff --git a/advent.h b/advent.h index 327c717..6ddbbbe 100644 --- a/advent.h +++ b/advent.h @@ -108,10 +108,12 @@ extern bool MAPLIN(FILE *); extern void TYPE(void); extern void DATIME(long*, long*); +enum termination {endgame, quitgame, scoregame}; + extern void set_seed(long); extern unsigned long get_next_lcg_value(void); extern long randrange(long); -extern void score(long); +extern void score(enum termination); extern int saveresume(FILE *, bool); /* diff --git a/main.c b/main.c index 1c1b299..3d4962a 100644 --- a/main.c +++ b/main.c @@ -49,7 +49,6 @@ bool editline = true; bool prompt = true; extern void initialise(); -extern void score(long); extern int action(FILE *, long, long, long); void sig_handler(int signo) @@ -141,7 +140,7 @@ int main(int argc, char *argv[]) break; } /* show score and exit */ - score(1); + score(quitgame); } 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 * death and exit. */ RSPEAK(DEATH_CLOSING); - score(0); + score(endgame); } else { /* FIXME: Arithmetic on message numbers */ if (!YES(cmdin,WATCH_IT+game.numdie*2,WHICH_WAY+game.numdie*2,OK_MAN)) - score(0); + score(endgame); if (game.numdie == MAXDIE) - score(0); + score(endgame); game.place[WATER]=0; game.place[OIL]=0; if (TOTING(LAMP)) @@ -1107,7 +1106,7 @@ static bool do_command(FILE *cmdin) case GO_DWARFWAKE: /* Oh dear, he's disturbed the dwarves. */ RSPEAK(DWARVES_AWAKEN); - score(0); + score(endgame); return true; default: BUG(99); diff --git a/score.c b/score.c index d49eff8..734ea19 100644 --- a/score.c +++ b/score.c @@ -7,8 +7,8 @@ * scoring and wrap-up */ -void score(long mode) -/* mode is <0 if scoring, >0 if quitting, =0 if died or won */ +void score(enum termination mode) +/* mode is 'report' if scoring, 'quit' if quitting, 'end' if died or won */ { 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). */ score += (MAXDIE-game.numdie)*10; mxscor += MAXDIE*10; - if(mode == 0)score += 4; + if(mode == endgame) + score += 4; mxscor += 4; if(game.dflag != 0)score += 25; mxscor += 25; @@ -93,7 +94,7 @@ void score(long mode) score=score-game.trnluz-game.saved; /* Return to score command if that's where we came from. */ - if(mode < 0) { + if(mode == scoregame) { SETPRM(1,score,mxscor); SETPRM(3,game.turns,game.turns); RSPEAK(GARNERED_POINTS);