Comment cleanup, semantic types, information hiding.
This commit is contained in:
parent
b27f767cc6
commit
a3c159660b
5 changed files with 26 additions and 36 deletions
|
@ -273,7 +273,7 @@ static int vbreak(verb_t verb, obj_t obj)
|
|||
}
|
||||
|
||||
static int brief(void)
|
||||
/* Brief. Intransitive only. Suppress long descriptions after first time. */
|
||||
/* Brief. Intransitive only. Suppress full descriptions after first time. */
|
||||
{
|
||||
game.abbnum = 10000;
|
||||
game.detail = 3;
|
||||
|
@ -418,8 +418,8 @@ static int chain(verb_t verb)
|
|||
switch (game.prop[BEAR]) {
|
||||
// LCOV_EXCL_START
|
||||
case BEAR_DEAD:
|
||||
/* Can't be reached as long as the only way for the bear to die
|
||||
* is from a bridge collapse. Leave in in case this changes, but
|
||||
/* Can't be reached until the bear can die in some way other
|
||||
* than a bridge collapse. Leave in in case this changes, but
|
||||
* exclude from coverage testing. */
|
||||
game.fixed[BEAR] = IS_FIXED;
|
||||
break;
|
||||
|
|
9
advent.h
9
advent.h
|
@ -202,7 +202,6 @@ extern struct game_t game;
|
|||
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(int msg, ...);
|
||||
extern void pspeak(vocab_t, enum speaktype, int, bool, ...);
|
||||
|
@ -215,12 +214,10 @@ extern void move(obj_t, loc_t);
|
|||
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);
|
||||
extern long setbit(long);
|
||||
extern int atdwrf(loc_t);
|
||||
extern long setbit(int);
|
||||
extern bool tstbit(long, int);
|
||||
extern void make_zzword(char*);
|
||||
extern void set_seed(long);
|
||||
extern unsigned long get_next_lcg_value(void);
|
||||
extern long randrange(long);
|
||||
extern long score(enum termination);
|
||||
extern void terminate(enum termination) __attribute__((noreturn));
|
||||
|
@ -230,7 +227,7 @@ extern int resume(void);
|
|||
extern int restore(FILE *);
|
||||
extern long initialise(void);
|
||||
extern int action(struct command_t *command);
|
||||
extern void state_change(obj_t, long);
|
||||
extern void state_change(obj_t, int);
|
||||
|
||||
|
||||
void bug(enum bugtype, const char *) __attribute__((__noreturn__));
|
||||
|
|
7
main.c
7
main.c
|
@ -137,6 +137,7 @@ static bool fallback_handler(struct command_t command)
|
|||
/* fallback handler for commands not handled by FORTRANish parser */
|
||||
{
|
||||
long sv;
|
||||
turn_t turnlimit;
|
||||
char buf[DIM(command.raw1) + DIM(command.raw2) + 1];
|
||||
sprintf(buf, "%s %s", command.raw1, command.raw2);
|
||||
|
||||
|
@ -146,8 +147,8 @@ static bool fallback_handler(struct command_t command)
|
|||
// autogenerated, so don't charge user time for it.
|
||||
--game.turns;
|
||||
return true;
|
||||
} else if (sscanf(buf, "waste %ld", &sv) == 1) {
|
||||
game.limit -= sv;
|
||||
} else if (sscanf(buf, "waste %ld", &turnlimit) == 1) {
|
||||
game.limit -= turnlimit;
|
||||
printf("Game limit is now %ld\n", game.limit);
|
||||
return true;
|
||||
}
|
||||
|
@ -670,7 +671,7 @@ static void playermove( int motion)
|
|||
|
||||
/* We arrive here on conditional failure.
|
||||
* Skip to next non-matching destination */
|
||||
long te_tmp = travel_entry;
|
||||
int te_tmp = travel_entry;
|
||||
do {
|
||||
if (travel[te_tmp].stop)
|
||||
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
|
||||
|
|
38
misc.c
38
misc.c
|
@ -64,10 +64,7 @@ static void vspeak(const char* msg, bool blank, va_list ap)
|
|||
}
|
||||
} else {
|
||||
i++;
|
||||
// Integer specifier. In order to accommodate the fact
|
||||
// that PARMS can have both legitimate integers *and*
|
||||
// packed tokens, stringify everything. Future work may
|
||||
// eliminate the need for this.
|
||||
// Integer specifier.
|
||||
if (msg[i] == 'd') {
|
||||
long arg = va_arg(ap, long);
|
||||
int ret = snprintf(renderp, size, "%ld", arg);
|
||||
|
@ -134,7 +131,7 @@ void sspeak(const int msg, ...)
|
|||
void pspeak(vocab_t msg, enum speaktype mode, int skip, bool blank, ...)
|
||||
/* Find the skip+1st message from msg and print it. Modes are:
|
||||
* feel = for inventory, what you can touch
|
||||
* look = the long description for the state the object is in
|
||||
* look = the full description for the state the object is in
|
||||
* listen = the sound for the state the object is in
|
||||
* study = text on the object. */
|
||||
{
|
||||
|
@ -459,7 +456,7 @@ static void tokenize(char* raw, struct command_t *cmd)
|
|||
|
||||
/* Bound prefix on the %s would be needed to prevent buffer
|
||||
* overflow. but we shortstop this more simply by making each
|
||||
* raw-input buffer as long as the enrire inout buffer. */
|
||||
* raw-input buffer as long as the entire input buffer. */
|
||||
sscanf(raw, "%s%s", cmd->raw1, cmd->raw2);
|
||||
|
||||
/* (ESR) In oldstyle mode, simulate the uppercasing and truncating
|
||||
|
@ -484,7 +481,7 @@ static void tokenize(char* raw, struct command_t *cmd)
|
|||
cmd->raw2[i] = toupper(cmd->raw2[i]);
|
||||
}
|
||||
|
||||
/* populate command with parsed vocab metadata */
|
||||
/* populate command with parsed vocabulary metadata */
|
||||
get_vocab_metadata(cmd->raw1, &(cmd->id1), &(cmd->type1));
|
||||
get_vocab_metadata(cmd->raw2, &(cmd->id2), &(cmd->type2));
|
||||
}
|
||||
|
@ -597,16 +594,16 @@ void drop(obj_t object, loc_t where)
|
|||
game.atloc[where] = object;
|
||||
}
|
||||
|
||||
long atdwrf(loc_t where)
|
||||
int atdwrf(loc_t where)
|
||||
/* Return the index of first dwarf at the given location, zero if no dwarf is
|
||||
* there (or if dwarves not active yet), -1 if all dwarves are dead. Ignore
|
||||
* the pirate (6th dwarf). */
|
||||
{
|
||||
long at;
|
||||
int at;
|
||||
|
||||
at = 0;
|
||||
if (game.dflag < 2)
|
||||
return (at);
|
||||
return at;
|
||||
at = -1;
|
||||
for (long i = 1; i <= NDWARVES - 1; i++) {
|
||||
if (game.dloc[i] == where)
|
||||
|
@ -614,13 +611,13 @@ long atdwrf(loc_t where)
|
|||
if (game.dloc[i] != 0)
|
||||
at = 0;
|
||||
}
|
||||
return (at);
|
||||
return at;
|
||||
}
|
||||
|
||||
/* Utility routines (setbit, tstbit, set_seed, get_next_lcg_value,
|
||||
* randrange) */
|
||||
|
||||
long setbit(long bit)
|
||||
long setbit(int bit)
|
||||
/* Returns 2**bit for use in constructing bit-masks. */
|
||||
{
|
||||
return (1L << bit);
|
||||
|
@ -638,7 +635,11 @@ void set_seed(long seedval)
|
|||
game.lcg_x = (unsigned long) seedval % game.lcg_m;
|
||||
|
||||
// once seed is set, we need to generate the Z`ZZZ word
|
||||
make_zzword(game.zzword);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
game.zzword[i] = 'A' + randrange(26);
|
||||
}
|
||||
game.zzword[1] = '\''; // force second char to apostrophe
|
||||
game.zzword[5] = '\0';
|
||||
}
|
||||
|
||||
unsigned long get_next_lcg_value(void)
|
||||
|
@ -655,15 +656,6 @@ long randrange(long range)
|
|||
return range * get_next_lcg_value() / game.lcg_m;
|
||||
}
|
||||
|
||||
void make_zzword(char zzword[TOKLEN + 1])
|
||||
{
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
zzword[i] = 'A' + randrange(26);
|
||||
}
|
||||
zzword[1] = '\''; // force second char to apostrophe
|
||||
zzword[5] = '\0';
|
||||
}
|
||||
|
||||
// LCOV_EXCL_START
|
||||
void bug(enum bugtype num, const char *error_string)
|
||||
{
|
||||
|
@ -674,7 +666,7 @@ void bug(enum bugtype num, const char *error_string)
|
|||
|
||||
/* end */
|
||||
|
||||
void state_change(obj_t obj, long state)
|
||||
void state_change(obj_t obj, int state)
|
||||
/* Object must have a change-message list for this to be useful; only some do */
|
||||
{
|
||||
game.prop[obj] = state;
|
||||
|
|
2
score.c
2
score.c
|
@ -120,7 +120,7 @@ void terminate(enum termination mode)
|
|||
if (points + game.saved + 1 >= mxscor && game.saved != 0)
|
||||
rspeak(WITHOUT_SUSPENDS);
|
||||
rspeak(TOTAL_SCORE, points, mxscor, game.turns, game.turns);
|
||||
for (long i = 1; i <= (long)NCLASSES; i++) {
|
||||
for (int i = 1; i <= (long)NCLASSES; i++) {
|
||||
if (classes[i].threshold >= points) {
|
||||
speak(classes[i].message);
|
||||
i = classes[i].threshold + 1 - points;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue