Name another magic number.
[open-adventure.git] / advent.h
1 #include <stdio.h>
2 #include <stdbool.h>
3
4 #include "common.h"
5
6 #define LINESIZE        100
7 #define NDWARVES        6
8 #define PIRATE          NDWARVES        /* must be NDWARVES-1 when zero-origin */
9 #define DALTLC          LOC_NUGGET      /* alternate dwarf location */
10 #define MINTRS          50
11 #define MAXTRS          79
12 #define MAXPARMS        25
13 #define INVLIMIT        7
14 #define INTRANSITIVE    -1              /* illegal object number */
15 #define SPECIALBASE     300             /* base number of special rooms */
16 #define WARNTIME        30              /* late game starts at game.limit-this */
17
18 typedef long token_t;   /* word token - someday this will be char[TOKLEN+1] */
19 typedef long vocab_t;   /* index into a vocabulary array */
20
21 struct game_t {
22     unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
23     long abbnum;
24     long blklin;
25     long bonus;
26     long chloc;
27     long chloc2;
28     long clock1;
29     long clock2;
30     long clshnt;
31     long closed;
32     long closng;
33     long conds;
34     long detail;
35     long dflag;
36     long dkill;
37     long dtotal;
38     long foobar;
39     long holdng;
40     long iwest;
41     long knfloc;
42     long limit;
43     long lmwarn;
44     long loc;
45     long newloc;
46     long novice;
47     long numdie;
48     long oldloc;
49     long oldlc2;
50     long oldobj;
51     long panic;
52     long saved;
53     long tally;
54     long thresh;
55     long trndex;
56     long trnluz;
57     long turns;
58     long wzdark;
59     long zzword;
60     long abbrev[LOCSIZ+1];
61     long atloc[LOCSIZ+1];
62     long dseen[NDWARVES+1];
63     long dloc[NDWARVES+1];
64     long odloc[NDWARVES+1];
65     long fixed[NOBJECTS+1];
66     long link[NOBJECTS*2 + 1];
67     long place[NOBJECTS+1];
68     long hinted[HNTSIZ+1];
69     long hintlc[HNTSIZ+1];
70     long prop[NOBJECTS+1];
71 };
72
73 extern struct game_t game;
74
75 extern long LNLENG, LNPOSN, PARMS[];
76 extern char rawbuf[LINESIZE], INLINE[LINESIZE+1];
77 extern const char ascii_to_advent[];
78 extern const char advent_to_ascii[];
79 extern FILE *logfp;
80 extern bool oldstyle, editline, prompt;
81
82 /* b is not needed for POSIX but harmless */
83 #define READ_MODE "rb"
84 #define WRITE_MODE "wb"
85 extern char* xstrdup(const char*);
86 extern void packed_to_token(long, char token[]);
87 extern void newspeak(char*);
88 extern void PSPEAK(vocab_t,int);
89 extern void RSPEAK(vocab_t);
90 extern void SETPRM(long,long,long);
91 extern bool GETIN(FILE *,token_t*,token_t*,token_t*,token_t*);
92 extern long YES(FILE *,vocab_t,vocab_t,vocab_t);
93 extern long GETTXT(bool,bool,bool);
94 extern token_t MAKEWD(long);
95 extern void TYPE0(void);
96 extern long VOCAB(long,long);
97 extern void DSTROY(long);
98 extern void JUGGLE(long);
99 extern void MOVE(long,long);
100 extern long PUT(long,long,long);
101 extern void CARRY(long,long);
102 extern void DROP(long,long);
103 extern long ATDWRF(long);
104 extern long SETBIT(long);
105 extern bool TSTBIT(long,int);
106 extern long RNDVOC(long,long);
107 extern void BUG(long) __attribute__((noreturn));
108 extern bool MAPLIN(FILE *);
109 extern void TYPE(void);
110 extern void DATIME(long*, long*);
111
112 enum termination {endgame, quitgame, scoregame};
113
114 extern void set_seed(long);
115 extern unsigned long get_next_lcg_value(void);
116 extern long randrange(long);
117 extern void score(enum termination);
118 extern int saveresume(FILE *, bool);
119
120 /*
121  *  MOD(N,M)    = Arithmetic modulus
122  *  AT(OBJ)     = true if on either side of two-placed object
123  *  CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
124  *  DARK(LOC)   = true if location "LOC" is dark
125  *  FORCED(LOC) = true if LOC moves without asking for input (COND=2)
126  *  FOREST(LOC) = true if LOC is part of the forest
127  *  GSTONE(OBJ) = true if OBJ is a gemstone
128  *  HERE(OBJ)   = true if the OBJ is at "LOC" (or is being carried)
129  *  LIQUID()    = object number of liquid in bottle
130  *  LIQLOC(LOC) = object number of liquid (if any) at LOC
131  *  PCT(N)      = true N% of the time (N integer from 0 to 100)
132  *  TOTING(OBJ) = true if the OBJ is being carried */
133
134 #define MOD(N,M)        ((N) % (M))
135 #define TOTING(OBJ)     (game.place[OBJ] == -1)
136 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
137 #define HERE(OBJ)       (AT(OBJ) || TOTING(OBJ))
138 #define LIQ2(PBOTL)     ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
139 #define LIQUID()        (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
140 #define LIQLOC(LOC)     (LIQ2((MOD(COND[LOC]/2*2,8)-5)*MOD(COND[LOC]/4,2)+1))
141 #define CNDBIT(L,N)     (TSTBIT(COND[L],N))
142 #define FORCED(LOC)     (COND[LOC] == 2)
143 #define DARK(DUMMY)     ((!CNDBIT(game.loc,LIGHT)) && (game.prop[LAMP] == 0 || !HERE(LAMP)))
144 #define PCT(N)  (randrange(100) < (N))
145 #define GSTONE(OBJ)     ((OBJ) == EMRALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
146 #define FOREST(LOC)     ((LOC) >= LOC_FOREST1 && (LOC) <= LOC_FOREST22)
147 #define VOCWRD(LETTRS,SECT)     (VOCAB(MAKEWD(LETTRS),SECT))
148 #define SPECIAL(LOC)    ((LOC) > SPECIALBASE)
149
150 /*  The following two functions were added to fix a bug (game.clock1 decremented
151  *  while in forest).  They should probably be replaced by using another
152  *  "cond" bit.  For now, however, a quick fix...  OUTSID(LOC) is true if
153  *  LOC is outside, INDEEP(LOC) is true if LOC is "deep" in the cave (hall
154  *  of mists or deeper).  Note special kludges for "Foof!" locs. */
155
156 #define OUTSID(LOC)     ((LOC) <= LOC_GRATE || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == LOC_FOOF2 || (LOC) == LOC_FOOF4)
157 #define INDEEP(LOC)     ((LOC) >= LOC_MISTHALL && !OUTSID(LOC) && (LOC) != LOC_FOOF1)
158
159 /* vocabulary items */ 
160 extern long AMBER, ATTACK, AXE, BACK, BATTER, BEAR,
161    BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST,
162    CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS,
163    EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, INVENT,
164    JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGZIN, MESSAG, MIRROR, NUGGET, NUL,
165    OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAM,
166    RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SIGN, SNAKE,
167    STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2,
168    URN, VASE, VEND, VOLCAN, WATER;
169
170 enum speechpart {unknown, intransitive, transitive};
171
172 /* Phase codes for action returns. 
173  * These were at one time FORTRAN line numbers.
174  * The values don't matter, but perturb their order at your peril.
175  */
176 #define GO_TERMINATE    2
177 #define GO_MOVE         8
178 #define GO_TOP          2000
179 #define GO_CLEAROBJ     2012
180 #define GO_CHECKHINT    2600
181 #define GO_CHECKFOO     2607
182 #define GO_CLOSEJUMP    2610
183 #define GO_DIRECTION    2620
184 #define GO_LOOKUP       2630
185 #define GO_WORD2        2800
186 #define GO_SPECIALS     1900
187 #define GO_UNKNOWN      8000
188 #define GO_ACTION       40000
189 #define GO_DWARFWAKE    19000
190
191 /* Symbols for cond bits */
192 #define LIGHT   0       /* Light */
193 #define OILY    1       /* If bit 2 is on: on for oil, off for water */
194 #define FLUID   2       /* Liquid asset, see bit 1 */
195 #define NOARRR  3       /* Pirate doesn't go here unless following player */
196 #define NOBACK  4       /* Cannot use "back" to move away */
197 /* Bits past 10 indicate areas of interest to "hint" routines */
198 #define HBASE   10      /* Base for location hint bitss */
199 #define HCAVE   11      /* Trying to get into cave */
200 #define HBIRD   12      /* Trying to catch bird */
201 #define HSNAKE  13      /* Trying to deal with snake */
202 #define HMAZE   14      /* Lost in maze */
203 #define HDARK   15      /* Pondering dark room */
204 #define HWITT   16      /* At Witt's End */
205 #define HCLIFF  17      /* Cliff with urn */
206 #define HWOODS  18      /* Lost in forest */
207 #define HOGRE   19      /* Trying to deal with ogre */
208 #define HJADE   20      /* Found all treasures except jade */
209
210 /* hack to ignore GCC Unused Result */
211 #define IGNORE(r) do{if (r){}}while(0)
212
213 /* end */
214