From e9aff2568f200be6cf47ec0bd945902a636bbd71 Mon Sep 17 00:00:00 2001 From: NHOrus Date: Mon, 19 Jun 2017 20:13:50 +0300 Subject: [PATCH] Even less magic --- actions.c | 69 +++++++++++++++++++++++------------------------ advent.h | 73 +++++++++++++++++++++++++------------------------- adventure.yaml | 2 +- dungeon.c | 4 +-- init.c | 2 +- main.c | 21 ++++++++------- misc.c | 6 ++--- 7 files changed, 89 insertions(+), 88 deletions(-) diff --git a/actions.c b/actions.c index 05b9224..cc252b5 100644 --- a/actions.c +++ b/actions.c @@ -134,7 +134,7 @@ static int bigwords(long foo) } else { /* Bring back troll if we steal the eggs back from him before * crossing. */ - if (game.place[EGGS] == 0 && game.place[TROLL] == 0 && game.prop[TROLL] == 0) + if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == 0) game.prop[TROLL] = 1; k = 2; if (HERE(EGGS))k = 1; @@ -389,7 +389,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it) int k = LIQUID(); if (k == obj)obj = BOTTLE; if (obj == BOTTLE && k != 0) - game.place[k] = NOWHERE; + game.place[k] = LOC_NOWHERE; if (obj == CAGE && game.prop[BIRD] == 1)DROP(BIRD, game.loc); DROP(obj, game.loc); if (obj != BIRD) return GO_CLEAROBJ; @@ -409,7 +409,7 @@ static int drink(token_t verb, token_t obj) if (obj != 0 && obj != WATER)spk = RIDICULOUS_ATTEMPT; if (spk != RIDICULOUS_ATTEMPT && LIQUID() == WATER && HERE(BOTTLE)) { game.prop[BOTTLE] = 1; - game.place[WATER] = NOWHERE; + game.place[WATER] = LOC_NOWHERE; spk = BOTTLE_EMPTY; } } else { @@ -539,7 +539,7 @@ int fill(token_t verb, token_t obj) RSPEAK(spk); return GO_CLEAROBJ; } - game.place[k] = NOWHERE; + game.place[k] = LOC_NOWHERE; game.prop[BOTTLE] = 1; if (k == OIL)game.prop[URN] = 1; spk = WATER_URN + game.prop[URN]; @@ -764,7 +764,7 @@ static int pour(token_t verb, token_t obj) if (HERE(URN) && game.prop[URN] == 0) return fill(verb, URN); game.prop[BOTTLE] = 1; - game.place[obj] = NOWHERE; + game.place[obj] = LOC_NOWHERE; spk = GROUND_WET; if (!(AT(PLANT) || AT(DOOR))) { RSPEAK(spk); @@ -800,7 +800,6 @@ static int quit(void) static int read(token_t verb, token_t obj) /* Read. Print stuff based on objtxt. Oyster (?) is special case. */ { - int spk = ACTSPK[verb]; if (obj == INTRANSITIVE) { obj = 0; for (int i = 1; i <= NOBJECTS; i++) { @@ -816,7 +815,7 @@ static int read(token_t verb, token_t obj) return GO_CLEAROBJ; } if (OBJTXT[obj] == 0 || game.prop[obj] < 0) { - RSPEAK(spk); + RSPEAK(ACTSPK[verb]); return GO_CLEAROBJ; } if (obj == OYSTER && !game.clshnt) { @@ -891,7 +890,7 @@ static int throw_support(long spk) return GO_MOVE; } -static int throw(FILE *cmdin, long verb, token_t obj) +static int throw (FILE *cmdin, long verb, token_t obj) /* Throw. Same as discard unless axe. Then same as attack except * ignore bird, and if dwarf is present then one might be killed. * (Only way to do so!) Axe also special for dragon, bear, and @@ -923,34 +922,34 @@ static int throw(FILE *cmdin, long verb, token_t obj) if (obj != AXE) return (discard(verb, obj, false)); else { - int i = ATDWRF(game.loc); - if (i <= 0) { - if (AT(DRAGON) && game.prop[DRAGON] == 0) - return throw_support(DRAGON_SCALES); - if (AT(TROLL)) - return throw_support(TROLL_RETURNS); - else if (AT(OGRE)) - return throw_support(OGRE_DODGE); - else if (HERE(BEAR) && game.prop[BEAR] == 0) { - /* This'll teach him to throw the axe at the bear! */ - DROP(AXE, game.loc); - game.fixed[AXE] = -1; - game.prop[AXE] = 1; - JUGGLE(BEAR); - RSPEAK(AXE_LOST); - return GO_CLEAROBJ; - } - return (attack(cmdin, verb, 0)); - } + int i = ATDWRF(game.loc); + if (i <= 0) { + if (AT(DRAGON) && game.prop[DRAGON] == 0) + return throw_support(DRAGON_SCALES); + if (AT(TROLL)) + return throw_support(TROLL_RETURNS); + else if (AT(OGRE)) + return throw_support(OGRE_DODGE); + else if (HERE(BEAR) && game.prop[BEAR] == 0) { + /* This'll teach him to throw the axe at the bear! */ + DROP(AXE, game.loc); + game.fixed[AXE] = -1; + game.prop[AXE] = 1; + JUGGLE(BEAR); + RSPEAK(AXE_LOST); + return GO_CLEAROBJ; + } + return (attack(cmdin, verb, 0)); + } - if (randrange(NDWARVES + 1) < game.dflag) { - return throw_support(DWARF_DODGES); - } else { - game.dseen[i] = false; - game.dloc[i] = 0; - return throw_support((++game.dkill == 1) - ? DWARF_SMOKE : KILLED_DWARF); - } + if (randrange(NDWARVES + 1) < game.dflag) { + return throw_support(DWARF_DODGES); + } else { + game.dseen[i] = false; + game.dloc[i] = 0; + return throw_support((++game.dkill == 1) + ? DWARF_SMOKE : KILLED_DWARF); + } } } diff --git a/advent.h b/advent.h index e89b2ad..f578eb0 100644 --- a/advent.h +++ b/advent.h @@ -14,6 +14,8 @@ #define INVLIMIT 7 /* inverntory limit (# of objects) */ #define INTRANSITIVE -1 /* illegal object number */ #define SPECIALBASE 300 /* base number of special rooms */ +#define GAMELIMIT 330 /* base limit of turns */ +#define NOVICELIMIT 1000 /* limit of turns for novice */ #define WARNTIME 30 /* late game starts at game.limit-this */ #define PANICTIME 15 /* time left after closing */ #define BATTERYLIFE 2500 /* turn limit increment from batteries */ @@ -60,23 +62,23 @@ struct game_t { long turns; long wzdark; long zzword; - long abbrev[LOCSIZ+1]; - long atloc[LOCSIZ+1]; - long dseen[NDWARVES+1]; - long dloc[NDWARVES+1]; - long odloc[NDWARVES+1]; - long fixed[NOBJECTS+1]; - long link[NOBJECTS*2 + 1]; - long place[NOBJECTS+1]; - long hinted[HNTSIZ+1]; - long hintlc[HNTSIZ+1]; - long prop[NOBJECTS+1]; + long abbrev[LOCSIZ + 1]; + long atloc[LOCSIZ + 1]; + long dseen[NDWARVES + 1]; + long dloc[NDWARVES + 1]; + long odloc[NDWARVES + 1]; + long fixed[NOBJECTS + 1]; + long link[NOBJECTS * 2 + 1]; + long place[NOBJECTS + 1]; + long hinted[HNTSIZ + 1]; + long hintlc[HNTSIZ + 1]; + long prop[NOBJECTS + 1]; }; extern struct game_t game; extern long LNLENG, LNPOSN, PARMS[]; -extern char rawbuf[LINESIZE], INLINE[LINESIZE+1]; +extern char rawbuf[LINESIZE], INLINE[LINESIZE + 1]; extern const char ascii_to_advent[]; extern const char advent_to_ascii[]; extern FILE *logfp; @@ -89,25 +91,25 @@ extern void* xmalloc(size_t size); extern char* xstrdup(const char*); extern void packed_to_token(long, char token[]); extern void speak(const char*); -extern void PSPEAK(vocab_t,int); +extern void PSPEAK(vocab_t, int); extern void RSPEAK(vocab_t); -extern void SETPRM(long,long,long); -extern bool GETIN(FILE *,token_t*,token_t*,token_t*,token_t*); +extern void SETPRM(long, long, long); +extern bool GETIN(FILE *, token_t*, token_t*, token_t*, token_t*); extern void echo_input(FILE*, char*, char*); extern char* get_input(void); extern bool YES(const char*, const char*, const char*); -extern long GETTXT(bool,bool,bool); +extern long GETTXT(bool, bool, bool); extern token_t MAKEWD(long); -extern long VOCAB(long,long); +extern long VOCAB(long, long); extern void JUGGLE(long); -extern void MOVE(long,long); -extern long PUT(long,long,long); -extern void CARRY(long,long); -extern void DROP(long,long); +extern void MOVE(long, long); +extern long PUT(long, long, long); +extern void CARRY(long, long); +extern void DROP(long, long); extern long ATDWRF(long); extern long SETBIT(long); -extern bool TSTBIT(long,int); -extern long RNDVOC(long,long); +extern bool TSTBIT(long, int); +extern long RNDVOC(long, long); extern bool MAPLIN(FILE *); extern void DATIME(long*, long*); @@ -136,7 +138,7 @@ extern int restore(FILE *); * PCT(N) = true N% of the time (N integer from 0 to 100) * TOTING(OBJ) = true if the OBJ is being carried */ -#define DESTROY(N) MOVE(N, NOWHERE) +#define DESTROY(N) MOVE(N, LOC_NOWHERE) #define MOD(N,M) ((N) % (M)) #define TOTING(OBJ) (game.place[OBJ] == CARRIED) #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc) @@ -162,23 +164,23 @@ extern int restore(FILE *); #define OUTSID(LOC) ((LOC) <= LOC_GRATE || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == LOC_FOOF2 || (LOC) == LOC_FOOF4) #define INDEEP(LOC) ((LOC) >= LOC_MISTHALL && !OUTSID(LOC) && (LOC) != LOC_FOOF1) -/* vocabulary items */ +/* vocabulary items */ extern long AMBER, ATTACK, AXE, BACK, BATTERY, BEAR, - BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, - CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS, - EMERALD, ENTER, ENTRNC, FIND, FISSURE, FOOD, GRATE, HINT, INVENT, - JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGAZINE, MESSAG, MIRROR, NUGGET, NUL, - OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAMID, - RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SIGN, SNAKE, - STEPS, STICK, STREAM, THROW, TRIDENT, TROLL, TROLL2, - URN, VASE, VEND, VOLCANO, WATER; + BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, + CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS, + EMERALD, ENTER, ENTRNC, FIND, FISSURE, FOOD, GRATE, HINT, INVENT, + JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGAZINE, MESSAG, MIRROR, NUGGET, NUL, + OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAMID, + RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SIGN, SNAKE, + STEPS, STICK, STREAM, THROW, TRIDENT, TROLL, TROLL2, + URN, VASE, VEND, VOLCANO, WATER; enum speechpart {unknown, intransitive, transitive}; void initialise(void); int action(FILE *input, enum speechpart part, long verb, token_t obj); -/* Phase codes for action returns. +/* Phase codes for action returns. * These were at one time FORTRAN line numbers. * The values don't matter, but perturb their order at your peril. */ @@ -203,7 +205,7 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj); #define NOARRR 3 /* Pirate doesn't go here unless following player */ #define NOBACK 4 /* Cannot use "back" to move away */ /* Bits past 10 indicate areas of interest to "hint" routines */ -#define HBASE 10 /* Base for location hint bitss */ +#define HBASE 10 /* Base for location hint bits */ #define HCAVE 11 /* Trying to get into cave */ #define HBIRD 12 /* Trying to catch bird */ #define HSNAKE 13 /* Trying to deal with snake */ @@ -217,7 +219,6 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj); /* Special object statuses in game.place - can also be a location number (> 0) */ #define CARRIED -1 /* Player is toting it */ -#define NOWHERE 0 /* It's destroyed */ /* hack to ignore GCC Unused Result */ #define IGNORE(r) do{if (r){}}while(0) diff --git a/adventure.yaml b/adventure.yaml index a1abc62..567fb04 100644 --- a/adventure.yaml +++ b/adventure.yaml @@ -1,5 +1,5 @@ locations: !!omap -- LOC_0: +- LOC_NOWHERE: description: long: !!null short: !!null diff --git a/dungeon.c b/dungeon.c index 9aeda54..0ffebe1 100644 --- a/dungeon.c +++ b/dungeon.c @@ -547,8 +547,8 @@ static void write_file(FILE* header_file) void bug(enum bugtype num, const char *error_string) { - fprintf(stderr, "Fatal error %d, %s.\n", num, error_string); - exit(EXIT_FAILURE); + fprintf(stderr, "Fatal error %d, %s.\n", num, error_string); + exit(EXIT_FAILURE); } int main(void) diff --git a/init.c b/init.c index c0bd560..79284d6 100644 --- a/init.c +++ b/init.c @@ -176,7 +176,7 @@ void initialise(void) printf("Initialising...\n"); for (int i = 1; i <= NOBJECTS; i++) { - game.place[i] = NOWHERE; + game.place[i] = LOC_NOWHERE; game.prop[i] = 0; game.link[i + NOBJECTS] = game.link[i] = 0; } diff --git a/main.c b/main.c index 7a17921..c7c58e3 100644 --- a/main.c +++ b/main.c @@ -78,11 +78,11 @@ int main(int argc, char *argv[]) /* Options. */ #ifndef ADVENT_NOSAVE - char* opts = "l:or:s"; - char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [-s] \n"; + const char* opts = "l:or:s"; + const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [-s] \n"; #else - char* opts = "l:os"; - char* usage = "Usage: %s [-l logfilename] [-o] [-s] \n"; + const char* opts = "l:os"; + const char* usage = "Usage: %s [-l logfilename] [-o] [-s] \n"; #endif while ((ch = getopt(argc, argv, opts)) != EOF) { switch (ch) { @@ -157,10 +157,11 @@ int main(int argc, char *argv[]) game.zzword = RNDVOC(3, 0); game.newloc = LOC_START; game.loc = LOC_START; - game.limit = 330; + game.limit = GAMELIMIT; if (!rfp) { game.novice = YES(arbitrary_messages[WELCOME_YOU], arbitrary_messages[CAVE_NEARBY], arbitrary_messages[NO_MESSAGE]); - if (game.novice)game.limit = 1000; + if (game.novice) + game.limit = NOVICELIMIT; } else { restore(rfp); } @@ -295,7 +296,7 @@ static bool spotted_by_pirate(int i) /* The pirate's spotted him. He leaves him alone once we've * found chest. K counts if a treasure is here. If not, and * tally=1 for an unseen chest, let the pirate be spotted. Note - * that game.place[CHEST] = NOWHERE might mean that he's thrown + * that game.place[CHEST] = LOC_NOWHERE might mean that he's thrown * it to the troll, but in that case he's seen the chest * (game.prop=0). */ if (game.loc == game.chloc || game.prop[CHEST] >= 0) @@ -316,7 +317,7 @@ static bool spotted_by_pirate(int i) } } /* Force chest placement before player finds last treasure */ - if (game.tally == 1 && snarfed == 0 && game.place[CHEST] == NOWHERE && HERE(LAMP) && game.prop[LAMP] == 1) { + if (game.tally == 1 && snarfed == 0 && game.place[CHEST] == LOC_NOWHERE && HERE(LAMP) && game.prop[LAMP] == 1) { RSPEAK(PIRATE_SPOTTED); movechest = true; } @@ -512,7 +513,7 @@ static void croak(void) } else if (game.numdie == maximum_deaths || !YES(query, yes_response, arbitrary_messages[OK_MAN])) terminate(endgame); else { - game.place[WATER] = game.place[OIL] = NOWHERE; + game.place[WATER] = game.place[OIL] = LOC_NOWHERE; if (TOTING(LAMP)) game.prop[LAMP] = 0; for (int j = 1; j <= NOBJECTS; j++) { @@ -878,7 +879,7 @@ static void lampcheck(void) if (!game.lmwarn && HERE(LAMP)) { game.lmwarn = true; int spk = GET_BATTERIES; - if (game.place[BATTERY] == NOWHERE)spk = LAMP_DIM; + if (game.place[BATTERY] == LOC_NOWHERE)spk = LAMP_DIM; if (game.prop[BATTERY] == 1)spk = MISSING_BATTERYIES; RSPEAK(spk); } diff --git a/misc.c b/misc.c index 33ec95b..ee2ac25 100644 --- a/misc.c +++ b/misc.c @@ -417,7 +417,7 @@ void MOVE(long object, long where) from = game.fixed[object - NOBJECTS]; else from = game.place[object]; - if (from != NOWHERE && from != CARRIED && !SPECIAL(from)) + if (from != LOC_NOWHERE && from != CARRIED && !SPECIAL(from)) CARRY(object, from); DROP(object, where); } @@ -660,8 +660,8 @@ void DATIME(long* d, long* t) void bug(enum bugtype num, const char *error_string) { - fprintf(stderr, "Fatal error %d, %s.\n", num, error_string); - exit(EXIT_FAILURE); + fprintf(stderr, "Fatal error %d, %s.\n", num, error_string); + exit(EXIT_FAILURE); } /* end */ -- 2.31.1