The FORTRAN-derived longs were semantically ints. Make it so.
Note. because we used fixed-length declrations in the right places, this shouldn't break saves. (Besides being right, this will someday make a port to Go a touch easier, if we decide to do that.)
This commit is contained in:
parent
b8c9cf90d8
commit
81af59974b
7 changed files with 56 additions and 56 deletions
62
advent.h
62
advent.h
|
@ -119,15 +119,15 @@ typedef enum {
|
||||||
GO_DWARFWAKE,
|
GO_DWARFWAKE,
|
||||||
} phase_codes_t;
|
} phase_codes_t;
|
||||||
|
|
||||||
typedef long vocab_t; // index into a vocabulary array */
|
typedef int vocab_t; // index into a vocabulary array */
|
||||||
typedef long verb_t; // index into an actions array */
|
typedef int verb_t; // index into an actions array */
|
||||||
typedef long obj_t; // index into the object array */
|
typedef int obj_t; // index into the object array */
|
||||||
typedef long loc_t; // index into the locations array */
|
typedef int loc_t; // index into the locations array */
|
||||||
typedef long turn_t; // turn counter or threshold */
|
typedef int turn_t; // turn counter or threshold */
|
||||||
|
|
||||||
struct game_t {
|
struct game_t {
|
||||||
int32_t lcg_x;
|
int32_t lcg_x;
|
||||||
long abbnum; // How often to print long descriptions
|
int abbnum; // How often to print int descriptions
|
||||||
score_t bonus; // What kind of finishing bonus we are getting
|
score_t bonus; // What kind of finishing bonus we are getting
|
||||||
loc_t chloc; // pirate chest location
|
loc_t chloc; // pirate chest location
|
||||||
loc_t chloc2; // pirate chest alternate location
|
loc_t chloc2; // pirate chest alternate location
|
||||||
|
@ -141,8 +141,8 @@ struct game_t {
|
||||||
bool panic; // has player found out he's trapped?
|
bool panic; // has player found out he's trapped?
|
||||||
bool wzdark; // whether the loc he's leaving was dark
|
bool wzdark; // whether the loc he's leaving was dark
|
||||||
bool blooded; // has player drunk of dragon's blood?
|
bool blooded; // has player drunk of dragon's blood?
|
||||||
long conds; // min value for cond[loc] if loc has any hints
|
int conds; // min value for cond[loc] if loc has any hints
|
||||||
long detail; // level of detail in descriptions
|
int detail; // level of detail in descriptions
|
||||||
|
|
||||||
/* dflag controls the level of activation of dwarves:
|
/* dflag controls the level of activation of dwarves:
|
||||||
* 0 No dwarf stuff yet (wait until reaches Hall Of Mists)
|
* 0 No dwarf stuff yet (wait until reaches Hall Of Mists)
|
||||||
|
@ -150,15 +150,15 @@ struct game_t {
|
||||||
* 2 Met first dwarf, others start moving, no knives thrown yet
|
* 2 Met first dwarf, others start moving, no knives thrown yet
|
||||||
* 3 A knife has been thrown (first set always misses)
|
* 3 A knife has been thrown (first set always misses)
|
||||||
* 3+ Dwarves are mad (increases their accuracy) */
|
* 3+ Dwarves are mad (increases their accuracy) */
|
||||||
long dflag;
|
int dflag;
|
||||||
|
|
||||||
long dkill; // dwarves killed
|
int dkill; // dwarves killed
|
||||||
long dtotal; // total dwarves (including pirate) in loc
|
int dtotal; // total dwarves (including pirate) in loc
|
||||||
long foobar; // progress in saying "FEE FIE FOE FOO".
|
int foobar; // progress in saying "FEE FIE FOE FOO".
|
||||||
long holdng; // number of objects being carried
|
int holdng; // number of objects being carried
|
||||||
long igo; // # uses of "go" instead of a direction
|
int igo; // # uses of "go" instead of a direction
|
||||||
long iwest; // # times he's said "west" instead of "w"
|
int iwest; // # times he's said "west" instead of "w"
|
||||||
long knfloc; // knife location; 0 if none, -1 after caveat
|
int knfloc; // knife location; 0 if none, -1 after caveat
|
||||||
turn_t limit; // lifetime of lamp
|
turn_t limit; // lifetime of lamp
|
||||||
loc_t loc; // where player is now
|
loc_t loc; // where player is now
|
||||||
loc_t newloc; // where player is going
|
loc_t newloc; // where player is going
|
||||||
|
@ -166,24 +166,24 @@ struct game_t {
|
||||||
loc_t oldloc; // where player was
|
loc_t oldloc; // where player was
|
||||||
loc_t oldlc2; // where player was two moves ago
|
loc_t oldlc2; // where player was two moves ago
|
||||||
obj_t oldobj; // last object player handled
|
obj_t oldobj; // last object player handled
|
||||||
long saved; // point penalty for saves
|
int saved; // point penalty for saves
|
||||||
long tally; // count of treasures gained
|
int tally; // count of treasures gained
|
||||||
long thresh; // current threshold for endgame scoring tier
|
int thresh; // current threshold for endgame scoring tier
|
||||||
turn_t trndex; // FIXME: not used, remove on next format bump
|
turn_t trndex; // FIXME: not used, remove on next format bump
|
||||||
turn_t trnluz; // # points lost so far due to turns used
|
turn_t trnluz; // # points lost so far due to turns used
|
||||||
turn_t turns; // counts commands given (ignores yes/no)
|
turn_t turns; // counts commands given (ignores yes/no)
|
||||||
char zzword[TOKLEN + 1]; // randomly generated magic word from bird
|
char zzword[TOKLEN + 1]; // randomly generated magic word from bird
|
||||||
long abbrev[NLOCATIONS + 1]; // has location been seen?
|
int abbrev[NLOCATIONS + 1]; // has location been seen?
|
||||||
long atloc[NLOCATIONS + 1]; // head of object linked list per location
|
int atloc[NLOCATIONS + 1]; // head of object linked list per location
|
||||||
long dseen[NDWARVES + 1]; // true if dwarf has seen him
|
int dseen[NDWARVES + 1]; // true if dwarf has seen him
|
||||||
loc_t dloc[NDWARVES + 1]; // location of dwarves, initially hard-wired in
|
loc_t dloc[NDWARVES + 1]; // location of dwarves, initially hard-wired in
|
||||||
loc_t odloc[NDWARVES + 1]; // prior loc of each dwarf, initially garbage
|
loc_t odloc[NDWARVES + 1]; // prior loc of each dwarf, initially garbage
|
||||||
loc_t fixed[NOBJECTS + 1]; // fixed location of object (if not IS_FREE)
|
loc_t fixed[NOBJECTS + 1]; // fixed location of object (if not IS_FREE)
|
||||||
obj_t link[NOBJECTS * 2 + 1]; // object-list links
|
obj_t link[NOBJECTS * 2 + 1];// object-list links
|
||||||
loc_t place[NOBJECTS + 1]; // location of object
|
loc_t place[NOBJECTS + 1]; // location of object
|
||||||
long hinted[NHINTS]; // hinted[i] = true iff hint i has been used.
|
int hinted[NHINTS]; // hinted[i] = true iff hint i has been used.
|
||||||
long hintlc[NHINTS]; // hintlc[i] = how long at LOC with cond bit i
|
int hintlc[NHINTS]; // hintlc[i] = how int at LOC with cond bit i
|
||||||
long prop[NOBJECTS + 1]; // object state array */
|
int prop[NOBJECTS + 1]; // object state array */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -226,21 +226,21 @@ extern bool silent_yes(void);
|
||||||
extern bool yes(const char*, const char*, const char*);
|
extern bool yes(const char*, const char*, const char*);
|
||||||
extern void juggle(obj_t);
|
extern void juggle(obj_t);
|
||||||
extern void move(obj_t, loc_t);
|
extern void move(obj_t, loc_t);
|
||||||
extern loc_t put(obj_t, long, long);
|
extern loc_t put(obj_t, int, int);
|
||||||
extern void carry(obj_t, loc_t);
|
extern void carry(obj_t, loc_t);
|
||||||
extern void drop(obj_t, loc_t);
|
extern void drop(obj_t, loc_t);
|
||||||
extern int atdwrf(loc_t);
|
extern int atdwrf(loc_t);
|
||||||
extern long setbit(int);
|
extern int setbit(int);
|
||||||
extern bool tstbit(long, int);
|
extern bool tstbit(int, int);
|
||||||
extern void set_seed(int32_t);
|
extern void set_seed(int32_t);
|
||||||
extern int32_t randrange(int32_t);
|
extern int32_t randrange(int32_t);
|
||||||
extern long score(enum termination);
|
extern int score(enum termination);
|
||||||
extern void terminate(enum termination) __attribute__((noreturn));
|
extern void terminate(enum termination) __attribute__((noreturn));
|
||||||
extern int savefile(FILE *, int32_t);
|
extern int savefile(FILE *, int32_t);
|
||||||
extern int suspend(void);
|
extern int suspend(void);
|
||||||
extern int resume(void);
|
extern int resume(void);
|
||||||
extern int restore(FILE *);
|
extern int restore(FILE *);
|
||||||
extern long initialise(void);
|
extern int initialise(void);
|
||||||
extern phase_codes_t action(command_t);
|
extern phase_codes_t action(command_t);
|
||||||
extern void state_change(obj_t, int);
|
extern void state_change(obj_t, int);
|
||||||
extern bool is_valid(struct game_t);
|
extern bool is_valid(struct game_t);
|
||||||
|
|
10
cheat.c
10
cheat.c
|
@ -43,19 +43,19 @@ int main(int argc, char *argv[])
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'd':
|
case 'd':
|
||||||
game.numdie = (turn_t)atoi(optarg);
|
game.numdie = (turn_t)atoi(optarg);
|
||||||
printf("cheat: game.numdie = %ld\n", game.numdie);
|
printf("cheat: game.numdie = %d\n", game.numdie);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
game.limit = (turn_t)atoi(optarg);
|
game.limit = (turn_t)atoi(optarg);
|
||||||
printf("cheat: game.limit = %ld\n", game.limit);
|
printf("cheat: game.limit = %d\n", game.limit);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
game.saved = (long)atoi(optarg);
|
game.saved = (int)atoi(optarg);
|
||||||
printf("cheat: game.saved = %ld\n", game.saved);
|
printf("cheat: game.saved = %d\n", game.saved);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
game.turns = (turn_t)atoi(optarg);
|
game.turns = (turn_t)atoi(optarg);
|
||||||
printf("cheat: game.turns = %ld\n", game.turns);
|
printf("cheat: game.turns = %d\n", game.turns);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
version = atoi(optarg);
|
version = atoi(optarg);
|
||||||
|
|
4
init.c
4
init.c
|
@ -43,13 +43,13 @@ struct game_t game = {
|
||||||
.foobar = WORD_EMPTY,
|
.foobar = WORD_EMPTY,
|
||||||
};
|
};
|
||||||
|
|
||||||
long initialise(void)
|
int initialise(void)
|
||||||
{
|
{
|
||||||
if (settings.oldstyle)
|
if (settings.oldstyle)
|
||||||
printf("Initialising...\n");
|
printf("Initialising...\n");
|
||||||
|
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
long seedval = (long)rand();
|
int seedval = (int)rand();
|
||||||
set_seed(seedval);
|
set_seed(seedval);
|
||||||
|
|
||||||
for (int i = 1; i <= NOBJECTS; i++) {
|
for (int i = 1; i <= NOBJECTS; i++) {
|
||||||
|
|
12
main.c
12
main.c
|
@ -96,7 +96,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize game variables */
|
/* Initialize game variables */
|
||||||
long seedval = initialise();
|
int seedval = initialise();
|
||||||
|
|
||||||
#ifndef ADVENT_NOSAVE
|
#ifndef ADVENT_NOSAVE
|
||||||
if (!rfp) {
|
if (!rfp) {
|
||||||
|
@ -113,7 +113,7 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (settings.logfp)
|
if (settings.logfp)
|
||||||
fprintf(settings.logfp, "seed %ld\n", seedval);
|
fprintf(settings.logfp, "seed %d\n", seedval);
|
||||||
|
|
||||||
/* interpret commands until EOF or interrupt */
|
/* interpret commands until EOF or interrupt */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -129,7 +129,7 @@ int main(int argc, char *argv[])
|
||||||
terminate(quitgame);
|
terminate(quitgame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if this loc is eligible for any hints. If been here long
|
/* Check if this loc is eligible for any hints. If been here int
|
||||||
* enough, display. Ignore "HINTS" < 4 (special stuff, see database
|
* enough, display. Ignore "HINTS" < 4 (special stuff, see database
|
||||||
* notes). */
|
* notes). */
|
||||||
static void checkhints(void)
|
static void checkhints(void)
|
||||||
|
@ -141,7 +141,7 @@ static void checkhints(void)
|
||||||
if (!CNDBIT(game.loc, hint + 1 + COND_HBASE))
|
if (!CNDBIT(game.loc, hint + 1 + COND_HBASE))
|
||||||
game.hintlc[hint] = -1;
|
game.hintlc[hint] = -1;
|
||||||
++game.hintlc[hint];
|
++game.hintlc[hint];
|
||||||
/* Come here if he's been long enough at required loc(s) for some
|
/* Come here if he's been int enough at required loc(s) for some
|
||||||
* unused hint. */
|
* unused hint. */
|
||||||
if (game.hintlc[hint] >= hints[hint].turns) {
|
if (game.hintlc[hint] >= hints[hint].turns) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -653,8 +653,8 @@ static void playermove(int motion)
|
||||||
for (;;) { /* L12 loop */
|
for (;;) { /* L12 loop */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
enum condtype_t condtype = travel[travel_entry].condtype;
|
enum condtype_t condtype = travel[travel_entry].condtype;
|
||||||
long condarg1 = travel[travel_entry].condarg1;
|
int condarg1 = travel[travel_entry].condarg1;
|
||||||
long condarg2 = travel[travel_entry].condarg2;
|
int condarg2 = travel[travel_entry].condarg2;
|
||||||
if (condtype < cond_not) {
|
if (condtype < cond_not) {
|
||||||
/* YAML N and [pct N] conditionals */
|
/* YAML N and [pct N] conditionals */
|
||||||
if (condtype == cond_goto || condtype == cond_pct) {
|
if (condtype == cond_goto || condtype == cond_pct) {
|
||||||
|
|
14
misc.c
14
misc.c
|
@ -483,7 +483,7 @@ static void tokenize(char* raw, command_t *cmd)
|
||||||
|
|
||||||
/* Bound prefix on the %s would be needed to prevent buffer
|
/* Bound prefix on the %s would be needed to prevent buffer
|
||||||
* overflow. but we shortstop this more simply by making each
|
* overflow. but we shortstop this more simply by making each
|
||||||
* raw-input buffer as long as the entire input buffer. */
|
* raw-input buffer as int as the entire input buffer. */
|
||||||
sscanf(raw, "%s%s", cmd->word[0].raw, cmd->word[1].raw);
|
sscanf(raw, "%s%s", cmd->word[0].raw, cmd->word[1].raw);
|
||||||
|
|
||||||
/* (ESR) In oldstyle mode, simulate the uppercasing and truncating
|
/* (ESR) In oldstyle mode, simulate the uppercasing and truncating
|
||||||
|
@ -544,7 +544,7 @@ bool get_command_input(command_t *command)
|
||||||
const char *types[] = {"NO_WORD_TYPE", "MOTION", "OBJECT", "ACTION", "NUMERIC"};
|
const char *types[] = {"NO_WORD_TYPE", "MOTION", "OBJECT", "ACTION", "NUMERIC"};
|
||||||
/* needs to stay synced with enum speechpart */
|
/* needs to stay synced with enum speechpart */
|
||||||
const char *roles[] = {"unknown", "intransitive", "transitive"};
|
const char *roles[] = {"unknown", "intransitive", "transitive"};
|
||||||
printf("Command: role = %s type1 = %s, id1 = %ld, type2 = %s, id2 = %ld\n",
|
printf("Command: role = %s type1 = %s, id1 = %d, type2 = %s, id2 = %d\n",
|
||||||
roles[command->part],
|
roles[command->part],
|
||||||
types[command->word[0].type],
|
types[command->word[0].type],
|
||||||
command->word[0].id,
|
command->word[0].id,
|
||||||
|
@ -597,7 +597,7 @@ void move(obj_t object, loc_t where)
|
||||||
drop(object, where);
|
drop(object, where);
|
||||||
}
|
}
|
||||||
|
|
||||||
loc_t put(obj_t object, loc_t where, long pval)
|
loc_t put(obj_t object, loc_t where, int pval)
|
||||||
/* put() is the same as move(), except it returns a value used to set up the
|
/* put() is the same as move(), except it returns a value used to set up the
|
||||||
* negated game.prop values for the repository objects. */
|
* negated game.prop values for the repository objects. */
|
||||||
{
|
{
|
||||||
|
@ -610,7 +610,7 @@ void carry(obj_t object, loc_t where)
|
||||||
* location. Incr holdng unless it was already being toted. If object>NOBJECTS
|
* location. Incr holdng unless it was already being toted. If object>NOBJECTS
|
||||||
* (moving "fixed" second loc), don't change game.place or game.holdng. */
|
* (moving "fixed" second loc), don't change game.place or game.holdng. */
|
||||||
{
|
{
|
||||||
long temp;
|
int temp;
|
||||||
|
|
||||||
if (object <= NOBJECTS) {
|
if (object <= NOBJECTS) {
|
||||||
if (game.place[object] == CARRIED)
|
if (game.place[object] == CARRIED)
|
||||||
|
@ -667,7 +667,7 @@ int atdwrf(loc_t where)
|
||||||
if (game.dflag < 2)
|
if (game.dflag < 2)
|
||||||
return at;
|
return at;
|
||||||
at = -1;
|
at = -1;
|
||||||
for (long i = 1; i <= NDWARVES - 1; i++) {
|
for (int 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)
|
||||||
|
@ -679,13 +679,13 @@ int atdwrf(loc_t where)
|
||||||
/* Utility routines (setbit, tstbit, set_seed, get_next_lcg_value,
|
/* Utility routines (setbit, tstbit, set_seed, get_next_lcg_value,
|
||||||
* randrange) */
|
* randrange) */
|
||||||
|
|
||||||
long setbit(int bit)
|
int setbit(int bit)
|
||||||
/* Returns 2**bit for use in constructing bit-masks. */
|
/* Returns 2**bit for use in constructing bit-masks. */
|
||||||
{
|
{
|
||||||
return (1L << bit);
|
return (1L << bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tstbit(long mask, int bit)
|
bool tstbit(int mask, int bit)
|
||||||
/* Returns true if the specified bit is set in the mask. */
|
/* Returns true if the specified bit is set in the mask. */
|
||||||
{
|
{
|
||||||
return (mask & (1 << bit)) != 0;
|
return (mask & (1 << bit)) != 0;
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
/*
|
/*
|
||||||
* If you change the first three members, the resume function may not properly
|
* If you change the first three members, the resume function may not properly
|
||||||
* reject saves from older versions. Yes, this glues us to a hardware-
|
* reject saves from older versions. Yes, this glues us to a hardware-
|
||||||
* dependent length of long. Later members can change, but bump the version
|
* dependent length of int. Later members can change, but bump the version
|
||||||
* when you do that.
|
* when you do that.
|
||||||
*/
|
*/
|
||||||
struct save_t {
|
struct save_t {
|
||||||
|
@ -190,7 +190,7 @@ bool is_valid(struct game_t valgame)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Recalculate tally, throw the towel if in disagreement */
|
/* Recalculate tally, throw the towel if in disagreement */
|
||||||
long temp_tally = 0;
|
int temp_tally = 0;
|
||||||
for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
|
for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
|
||||||
if (objects[treasure].is_treasure) {
|
if (objects[treasure].is_treasure) {
|
||||||
if (valgame.prop[treasure] == STATE_NOTFOUND) {
|
if (valgame.prop[treasure] == STATE_NOTFOUND) {
|
||||||
|
|
6
score.c
6
score.c
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
static int mxscor; /* ugh..the price for having score() not exit. */
|
static int mxscor; /* ugh..the price for having score() not exit. */
|
||||||
|
|
||||||
long score(enum termination mode)
|
int score(enum termination mode)
|
||||||
/* mode is 'scoregame' if scoring, 'quitgame' if quitting, 'endgame' if died
|
/* mode is 'scoregame' if scoring, 'quitgame' if quitting, 'endgame' if died
|
||||||
* or won */
|
* or won */
|
||||||
{
|
{
|
||||||
|
@ -116,14 +116,14 @@ long score(enum termination mode)
|
||||||
void terminate(enum termination mode)
|
void terminate(enum termination mode)
|
||||||
/* End of game. Let's tell him all about it. */
|
/* End of game. Let's tell him all about it. */
|
||||||
{
|
{
|
||||||
long points = score(mode);
|
int points = score(mode);
|
||||||
|
|
||||||
if (points + game.trnluz + 1 >= mxscor && game.trnluz != 0)
|
if (points + game.trnluz + 1 >= mxscor && game.trnluz != 0)
|
||||||
rspeak(TOOK_LONG);
|
rspeak(TOOK_LONG);
|
||||||
if (points + game.saved + 1 >= mxscor && game.saved != 0)
|
if (points + game.saved + 1 >= mxscor && game.saved != 0)
|
||||||
rspeak(WITHOUT_SUSPENDS);
|
rspeak(WITHOUT_SUSPENDS);
|
||||||
rspeak(TOTAL_SCORE, points, mxscor, game.turns, game.turns);
|
rspeak(TOTAL_SCORE, points, mxscor, game.turns, game.turns);
|
||||||
for (int i = 1; i <= (long)NCLASSES; i++) {
|
for (int i = 1; i <= (int)NCLASSES; i++) {
|
||||||
if (classes[i].threshold >= points) {
|
if (classes[i].threshold >= points) {
|
||||||
speak(classes[i].message);
|
speak(classes[i].message);
|
||||||
i = classes[i].threshold + 1 - points;
|
i = classes[i].threshold + 1 - points;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue