Limited cleanup
This commit is contained in:
parent
37373c5277
commit
898348911f
9 changed files with 87 additions and 91 deletions
2
Makefile
2
Makefile
|
@ -74,7 +74,7 @@ newdb.c newdb.h: newdungeon.py adventure.yaml
|
|||
python3 newdungeon.py
|
||||
|
||||
linenoise.o: linenoise/linenoise.h
|
||||
$(CC) -c linenoise/linenoise.c
|
||||
$(CC) $(CCFLAGS) -c linenoise/linenoise.c
|
||||
|
||||
dungeon: dungeon.o common.o
|
||||
$(CC) $(CCFLAGS) -o $@ dungeon.o common.o
|
||||
|
|
40
actions.c
40
actions.c
|
@ -14,7 +14,7 @@ static int attack(FILE *input, struct command_t *command)
|
|||
{
|
||||
vocab_t verb = command->verb;
|
||||
vocab_t obj = command->obj;
|
||||
int spk = actions[verb].message;
|
||||
long spk = actions[verb].message;
|
||||
if (obj == 0 || obj == INTRANSITIVE) {
|
||||
if (atdwrf(game.loc) > 0)
|
||||
obj = DWARF;
|
||||
|
@ -44,7 +44,7 @@ static int attack(FILE *input, struct command_t *command)
|
|||
DESTROY(BIRD);
|
||||
spk = BIRD_DEAD;
|
||||
} else if (obj == VEND) {
|
||||
bool blocking = (game.prop[VEND] == VEND_BLOCKS);
|
||||
bool blocking = (game.prop[VEND] == VEND_BLOCKS);
|
||||
game.prop[VEND] = blocking ? VEND_UNBLOCKS : VEND_BLOCKS;
|
||||
rspeak(blocking ? MACHINE_SWINGOUT : MACHINE_SWINGBACK);
|
||||
return GO_CLEAROBJ;
|
||||
|
@ -246,7 +246,7 @@ static int vcarry(token_t verb, token_t obj)
|
|||
return (fill(verb, BOTTLE));
|
||||
else {
|
||||
if (game.prop[BOTTLE] != EMPTY_BOTTLE)
|
||||
spk = BOTTLE_FULL;
|
||||
spk = BOTTLE_FULL;
|
||||
if (!TOTING(BOTTLE))spk = NO_CONTAINER;
|
||||
rspeak(spk);
|
||||
return GO_CLEAROBJ;
|
||||
|
@ -385,12 +385,12 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
|
|||
if (obj == BOTTLE && k != 0)
|
||||
game.place[k] = LOC_NOWHERE;
|
||||
if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED)
|
||||
drop(BIRD, game.loc);
|
||||
drop(BIRD, game.loc);
|
||||
drop(obj, game.loc);
|
||||
if (obj != BIRD) return GO_CLEAROBJ;
|
||||
game.prop[BIRD] = BIRD_UNCAGED;
|
||||
if (FOREST(game.loc))
|
||||
game.prop[BIRD] = BIRD_FOREST_UNCAGED;
|
||||
game.prop[BIRD] = BIRD_FOREST_UNCAGED;
|
||||
return GO_CLEAROBJ;
|
||||
}
|
||||
|
||||
|
@ -447,7 +447,7 @@ static int extinguish(token_t verb, int obj)
|
|||
int spk = actions[verb].message;
|
||||
if (obj == INTRANSITIVE) {
|
||||
if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
|
||||
obj = LAMP;
|
||||
obj = LAMP;
|
||||
if (HERE(URN) && game.prop[URN] == 2)obj = obj * NOBJECTS + URN;
|
||||
if (obj == INTRANSITIVE || obj == 0 || obj > NOBJECTS) return GO_UNKNOWN;
|
||||
}
|
||||
|
@ -554,7 +554,7 @@ int fill(token_t verb, token_t obj)
|
|||
if (LIQUID() != 0)
|
||||
spk = BOTTLE_FULL;
|
||||
if (spk == BOTTLED_WATER) {
|
||||
/* FIXME: Arithmetic on property values */
|
||||
/* FIXME: Arithmetic on property values */
|
||||
game.prop[BOTTLE] = MOD(conditions[game.loc], 4) / 2 * 2;
|
||||
k = LIQUID();
|
||||
if (TOTING(BOTTLE))
|
||||
|
@ -640,7 +640,7 @@ static int light(token_t verb, token_t obj)
|
|||
int spk = actions[verb].message;
|
||||
if (obj == INTRANSITIVE) {
|
||||
if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0)
|
||||
obj = LAMP;
|
||||
obj = LAMP;
|
||||
if (HERE(URN) && game.prop[URN] == 1)obj = obj * NOBJECTS + URN;
|
||||
if (obj == INTRANSITIVE || obj == 0 || obj > NOBJECTS) return GO_UNKNOWN;
|
||||
}
|
||||
|
@ -681,20 +681,20 @@ static int listen(void)
|
|||
if (k != SILENT) {
|
||||
rspeak(k);
|
||||
if (locations[game.loc].loud)
|
||||
return GO_CLEAROBJ;
|
||||
else
|
||||
spk = NO_MESSAGE;
|
||||
return GO_CLEAROBJ;
|
||||
else
|
||||
spk = NO_MESSAGE;
|
||||
}
|
||||
for (int i = 1; i <= NOBJECTS; i++) {
|
||||
if (!HERE(i) || objects[i].sounds[0] == NULL || game.prop[i] < 0)
|
||||
continue;
|
||||
int mi = game.prop[i];
|
||||
if (i == BIRD)
|
||||
mi += 3 * game.blooded;
|
||||
int mi = game.prop[i];
|
||||
if (i == BIRD)
|
||||
mi += 3 * game.blooded;
|
||||
pspeak(i, hear, mi, game.zzword);
|
||||
spk = NO_MESSAGE;
|
||||
/* FIXME: Magic number, sensitive to bird state logic */
|
||||
if (i == BIRD && game.prop[i] == 5)
|
||||
/* FIXME: Magic number, sensitive to bird state logic */
|
||||
if (i == BIRD && game.prop[i] == 5)
|
||||
DESTROY(BIRD);
|
||||
}
|
||||
rspeak(spk);
|
||||
|
@ -976,7 +976,7 @@ static int wave(token_t verb, token_t obj)
|
|||
}
|
||||
/* FIXME: Arithemetic on proprty values */
|
||||
if (HERE(BIRD))
|
||||
spk = FREE_FLY + MOD(game.prop[BIRD], 2);
|
||||
spk = FREE_FLY + MOD(game.prop[BIRD], 2);
|
||||
if (spk == FREE_FLY && game.loc == game.place[STEPS] && game.prop[JADE] < 0) {
|
||||
drop(JADE, game.loc);
|
||||
game.prop[JADE] = 0;
|
||||
|
@ -1057,7 +1057,7 @@ int action(FILE *input, struct command_t *command)
|
|||
switch (command->part) {
|
||||
case intransitive:
|
||||
if (command->wd2 > 0 && command->verb != SAY)
|
||||
return GO_WORD2;
|
||||
return GO_WORD2;
|
||||
if (command->verb == SAY)command->obj = command->wd2;
|
||||
if (command->obj == 0 || command->obj == INTRANSITIVE) {
|
||||
/* Analyse an intransitive verb (ie, no object given yet). */
|
||||
|
@ -1121,7 +1121,7 @@ int action(FILE *input, struct command_t *command)
|
|||
case 25: /* BRIEF */
|
||||
return brief();
|
||||
case 26: /* READ */
|
||||
command->obj = INTRANSITIVE;
|
||||
command->obj = INTRANSITIVE;
|
||||
return read(*command);
|
||||
case 27: /* BREAK */
|
||||
return GO_UNKNOWN;
|
||||
|
@ -1183,7 +1183,7 @@ int action(FILE *input, struct command_t *command)
|
|||
case 15: /* RUB */
|
||||
return rub(command->verb, command->obj);
|
||||
case 16: /* TOSS */
|
||||
return throw(input, command);
|
||||
return throw (input, command);
|
||||
case 17: { /* QUIT */
|
||||
rspeak(spk);
|
||||
return GO_CLEAROBJ;
|
||||
|
|
3
cheat.c
3
cheat.c
|
@ -40,8 +40,7 @@ int main(int argc, char *argv[])
|
|||
game.saved = 1;
|
||||
|
||||
fp = fopen("cheat_numdie.adv", WRITE_MODE);
|
||||
if (fp == NULL)
|
||||
{
|
||||
if (fp == NULL) {
|
||||
printf("Can't open file. Exiting.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
|
28
dungeon.c
28
dungeon.c
|
@ -198,7 +198,7 @@ static long GETNUM(FILE *source)
|
|||
* scanned). If we're at the end of the line or encounter an illegal
|
||||
* character (not a digit, hyphen, or blank), we return 0. */
|
||||
|
||||
long DIGIT, GETNUM, sign;
|
||||
long GETNUM, sign;
|
||||
|
||||
if (source != NULL) MAPLIN(source);
|
||||
GETNUM = 0;
|
||||
|
@ -215,7 +215,7 @@ static long GETNUM(FILE *source)
|
|||
LNPOSN = LNPOSN + 1;
|
||||
}
|
||||
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0)) {
|
||||
DIGIT = INLINE[LNPOSN] - 64;
|
||||
long DIGIT = INLINE[LNPOSN] - 64;
|
||||
if (DIGIT < 0 || DIGIT > 9) {
|
||||
GETNUM = 0;
|
||||
break;
|
||||
|
@ -233,13 +233,13 @@ static long GETNUM(FILE *source)
|
|||
static void read_messages(FILE* database)
|
||||
{
|
||||
while (true) {
|
||||
do {
|
||||
if (NULL == fgets(INLINE + 1, sizeof(INLINE) - 1, database)) {
|
||||
printf("Failed fgets()\n");
|
||||
}
|
||||
} while (!feof(database) && INLINE[1] == '#');
|
||||
if (strncmp(INLINE + 1, "-1\n", 3) == 0)
|
||||
break;
|
||||
do {
|
||||
if (NULL == fgets(INLINE + 1, sizeof(INLINE) - 1, database)) {
|
||||
printf("Failed fgets()\n");
|
||||
}
|
||||
} while (!feof(database) && INLINE[1] == '#');
|
||||
if (strncmp(INLINE + 1, "-1\n", 3) == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ static void read_initial_locations(FILE* database)
|
|||
{
|
||||
long OBJ;
|
||||
while ((OBJ = GETNUM(database)) != -1) {
|
||||
/* all done from YAML now */
|
||||
/* all done from YAML now */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +298,7 @@ static void read_action_verb_message_nr(FILE* database)
|
|||
{
|
||||
long verb;
|
||||
while ((verb = GETNUM(database)) != -1) {
|
||||
/* now declared in YAML */
|
||||
/* now declared in YAML */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ static void read_conditions(FILE* database)
|
|||
while ((K = GETNUM(database)) != -1) {
|
||||
long loc;
|
||||
while ((loc = GETNUM(NULL)) != 0) {
|
||||
continue; /* COND is no longer used */
|
||||
continue; /* COND is no longer used */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ static void read_hints(FILE* database)
|
|||
long K;
|
||||
while ((K = GETNUM(database)) != -1) {
|
||||
for (int I = 1; I <= 4; I++) {
|
||||
/* consume - actual array-building now done in YAML. */
|
||||
/* consume - actual array-building now done in YAML. */
|
||||
GETNUM(NULL);
|
||||
} /* end loop */
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ static void read_sound_text(FILE* database)
|
|||
{
|
||||
long K;
|
||||
while ((K = GETNUM(database)) != -1) {
|
||||
/* this stuff is in YAML now */
|
||||
/* this stuff is in YAML now */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
init.c
12
init.c
|
@ -26,7 +26,7 @@ void initialise(void)
|
|||
if (!(locations[i].description.big == 0 || TKEY[i] == 0)) {
|
||||
int k = TKEY[i];
|
||||
if (MOD(labs(TRAVEL[k]), 1000) == 1)
|
||||
conditions[i] |= (1 << COND_FORCED);
|
||||
conditions[i] |= (1 << COND_FORCED);
|
||||
}
|
||||
game.atloc[i] = 0;
|
||||
}
|
||||
|
@ -57,11 +57,11 @@ void initialise(void)
|
|||
* not yet found, so we know when to close the cave. */
|
||||
game.tally = 0;
|
||||
for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
|
||||
if (objects[treasure].is_treasure) {
|
||||
if (objects[treasure].inventory != 0)
|
||||
game.prop[treasure] = -1;
|
||||
game.tally = game.tally - game.prop[treasure];
|
||||
}
|
||||
if (objects[treasure].is_treasure) {
|
||||
if (objects[treasure].inventory != 0)
|
||||
game.prop[treasure] = -1;
|
||||
game.tally = game.tally - game.prop[treasure];
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear the hint stuff. game.hintlc[i] is how long he's been at LOC
|
||||
|
|
38
main.c
38
main.c
|
@ -291,8 +291,8 @@ static bool spotted_by_pirate(int i)
|
|||
int snarfed = 0;
|
||||
bool movechest = false, robplayer = false;
|
||||
for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
|
||||
if (!objects[treasure].is_treasure)
|
||||
continue;
|
||||
if (!objects[treasure].is_treasure)
|
||||
continue;
|
||||
/* Pirate won't take pyramid from plover room or dark
|
||||
* room (too easy!). */
|
||||
if (treasure == PYRAMID && (game.loc == objects[PYRAMID].plac || game.loc == objects[EMERALD].plac)) {
|
||||
|
@ -326,9 +326,9 @@ static bool spotted_by_pirate(int i)
|
|||
}
|
||||
if (robplayer) {
|
||||
rspeak(PIRATE_POUNCES);
|
||||
for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
|
||||
if (!objects[treasure].is_treasure)
|
||||
continue;
|
||||
for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
|
||||
if (!objects[treasure].is_treasure)
|
||||
continue;
|
||||
if (!(treasure == PYRAMID && (game.loc == objects[PYRAMID].plac || game.loc == objects[EMERALD].plac))) {
|
||||
if (AT(treasure) && game.fixed[treasure] == 0)
|
||||
carry(treasure, game.loc);
|
||||
|
@ -409,7 +409,7 @@ static bool dwarfmove(void)
|
|||
kk = TKEY[game.dloc[i]];
|
||||
if (kk != 0)
|
||||
do {
|
||||
game.newloc = T_DESTINATION(TRAVEL[kk]);
|
||||
game.newloc = T_DESTINATION(TRAVEL[kk]);
|
||||
/* Have we avoided a dwarf encounter? */
|
||||
bool avoided = (SPECIAL(game.newloc) ||
|
||||
!INDEEP(game.newloc) ||
|
||||
|
@ -559,8 +559,8 @@ static bool playermove(token_t verb, int motion)
|
|||
++kk; /* go to next travel entry for this location */
|
||||
continue;
|
||||
}
|
||||
/* we've reached the end of travel entries for game.loc */
|
||||
kk = k2;
|
||||
/* we've reached the end of travel entries for game.loc */
|
||||
kk = k2;
|
||||
if (kk == 0) {
|
||||
rspeak(NOT_CONNECTED);
|
||||
return true;
|
||||
|
@ -693,7 +693,7 @@ static bool playermove(token_t verb, int motion)
|
|||
* and block him. (standard travel entries check for
|
||||
* game.prop(TROLL)=0.) Special stuff for bear. */
|
||||
if (game.prop[TROLL] == 1) {
|
||||
pspeak(TROLL,look, 1);
|
||||
pspeak(TROLL, look, 1);
|
||||
game.prop[TROLL] = 0;
|
||||
move(TROLL2, 0);
|
||||
move(TROLL2 + NOBJECTS, 0);
|
||||
|
@ -872,7 +872,7 @@ static void lampcheck(void)
|
|||
int spk = GET_BATTERIES;
|
||||
if (game.place[BATTERY] == LOC_NOWHERE)spk = LAMP_DIM;
|
||||
if (game.prop[BATTERY] == DEAD_BATTERIES)
|
||||
spk = MISSING_BATTERIES;
|
||||
spk = MISSING_BATTERIES;
|
||||
rspeak(spk);
|
||||
}
|
||||
}
|
||||
|
@ -1027,16 +1027,14 @@ L2607:
|
|||
game.foobar = (game.foobar > 0 ? -game.foobar : 0);
|
||||
++game.turns;
|
||||
|
||||
/* If a turn threshold has been met, apply penalties and tell
|
||||
* the player about it. */
|
||||
for (int i = 0; i < NTHRESHOLDS; ++i)
|
||||
{
|
||||
if (game.turns == turn_thresholds[i].threshold + 1)
|
||||
{
|
||||
game.trnluz += turn_thresholds[i].point_loss;
|
||||
speak(turn_thresholds[i].message);
|
||||
}
|
||||
}
|
||||
/* If a turn threshold has been met, apply penalties and tell
|
||||
* the player about it. */
|
||||
for (int i = 0; i < NTHRESHOLDS; ++i) {
|
||||
if (game.turns == turn_thresholds[i].threshold + 1) {
|
||||
game.trnluz += turn_thresholds[i].point_loss;
|
||||
speak(turn_thresholds[i].message);
|
||||
}
|
||||
}
|
||||
|
||||
if (command.verb == SAY && command.wd2 > 0)
|
||||
command.verb = 0;
|
||||
|
|
39
misc.c
39
misc.c
|
@ -43,13 +43,12 @@ void packed_to_token(long packed, char token[6])
|
|||
|
||||
void token_to_packed(char token[6], long* packed)
|
||||
{
|
||||
*packed = 0;
|
||||
for (size_t i = 0; i < 5; ++i)
|
||||
{
|
||||
if (token[4 - i] == '\0')
|
||||
continue;
|
||||
char mapped = ascii_to_advent[(int) token[4 - i]];
|
||||
*packed |= (mapped << (6 * i));
|
||||
*packed = 0;
|
||||
for (size_t i = 0; i < 5; ++i) {
|
||||
if (token[4 - i] == '\0')
|
||||
continue;
|
||||
char mapped = ascii_to_advent[(int) token[4 - i]];
|
||||
*packed |= (mapped << (6 * i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,8 +100,8 @@ void vspeak(const char* msg, va_list ap)
|
|||
size--;
|
||||
} else {
|
||||
long arg = va_arg(ap, long);
|
||||
if (arg == -1)
|
||||
arg = 0;
|
||||
if (arg == -1)
|
||||
arg = 0;
|
||||
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.
|
||||
if (msg[i] == 'd') {
|
||||
|
@ -173,16 +172,16 @@ void pspeak(vocab_t msg, enum speaktype mode, int skip, ...)
|
|||
switch (mode) {
|
||||
case touch:
|
||||
vspeak(objects[msg].inventory, ap);
|
||||
break;
|
||||
break;
|
||||
case look:
|
||||
vspeak(objects[msg].longs[skip], ap);
|
||||
break;
|
||||
break;
|
||||
case hear:
|
||||
vspeak(objects[msg].sounds[skip], ap);
|
||||
break;
|
||||
break;
|
||||
case study:
|
||||
vspeak(objects[msg].texts[skip], ap);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
@ -266,7 +265,7 @@ char* get_input()
|
|||
}
|
||||
|
||||
if (input == NULL) // Got EOF; return with it.
|
||||
return(input);
|
||||
return (input);
|
||||
else if (input[0] == '#') // Ignore comments.
|
||||
continue;
|
||||
else // We have a 'normal' line; leave the loop.
|
||||
|
@ -298,12 +297,12 @@ bool yes(const char* question, const char* yes_response, const char* no_response
|
|||
speak(question);
|
||||
|
||||
reply = get_input();
|
||||
if (reply == NULL) {
|
||||
linenoiseFree(reply);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
if (reply == NULL) {
|
||||
linenoiseFree(reply);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
char* firstword = (char*) xmalloc(strlen(reply)+1);
|
||||
char* firstword = (char*) xmalloc(strlen(reply) + 1);
|
||||
sscanf(reply, "%s", firstword);
|
||||
|
||||
for (int i = 0; i < (int)strlen(firstword); ++i)
|
||||
|
@ -538,7 +537,7 @@ long atdwrf(long where)
|
|||
long setbit(long bit)
|
||||
/* Returns 2**bit for use in constructing bit-masks. */
|
||||
{
|
||||
return (1 << bit);
|
||||
return (1L << bit);
|
||||
}
|
||||
|
||||
bool tstbit(long mask, int bit)
|
||||
|
|
|
@ -28,7 +28,7 @@ struct save_t {
|
|||
struct save_t save;
|
||||
|
||||
int savefile(FILE *fp)
|
||||
/* Save game to file. No input or output from user. */
|
||||
/* Save game to file. No input or output from user. */
|
||||
{
|
||||
long i, k;
|
||||
datime(&i, &k);
|
||||
|
@ -38,7 +38,7 @@ int savefile(FILE *fp)
|
|||
save.version = VRSION;
|
||||
memcpy(&save.game, &game, sizeof(struct game_t));
|
||||
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Suspend and resume */
|
||||
|
|
4
score.c
4
score.c
|
@ -38,8 +38,8 @@ long score(enum termination mode)
|
|||
* Give the poor guy 2 points just for finding each treasure. */
|
||||
mxscor = 0;
|
||||
for (int i = 1; i <= NOBJECTS; i++) {
|
||||
if (!objects[i].is_treasure)
|
||||
continue;
|
||||
if (!objects[i].is_treasure)
|
||||
continue;
|
||||
if (objects[i].inventory != 0) {
|
||||
long k = 12;
|
||||
if (i == CHEST)k = 14;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue