Abolish funcs.h.
[open-adventure.git] / advent.h
1 #include <stdio.h>
2 #include <stdbool.h>
3
4 #include "sizes.h"
5
6 #define LINESIZE        100
7 #define NDWARVES        6
8 #define PIRATE          NDWARVES        /* must be NDWARVES-1 when zero-origin */
9 #define DALTLC          18              /* alternate dwarf location; low room */
10 #define MINTRS          50
11 #define MAXTRS          79
12 #define MAXPARMS        25
13 #define INVLIMIT        7
14
15 typedef struct lcg_state
16 {
17   unsigned long a, c, m, x;
18 } lcg_state;
19
20 typedef long token_t;   /* word token - someday this will be char[TOKLEN+1] */
21 typedef long vocab_t;   /* index into a vocabulary array */
22
23 struct game_t {
24     long abbnum;
25     long blklin;
26     long bonus;
27     long chloc;
28     long chloc2;
29     long clock1;
30     long clock2;
31     long clshnt;
32     long closed;
33     long closng;
34     long conds;
35     long detail;
36     long dflag;
37     long dkill;
38     long dtotal;
39     long foobar;
40     long holdng;
41     long iwest;
42     long knfloc;
43     long limit;
44     long lmwarn;
45     long loc;
46     long newloc;
47     long novice;
48     long numdie;
49     long oldloc;
50     long oldlc2;
51     long oldobj;
52     long panic;
53     long saved;
54     long setup;
55     long tally;
56     long thresh;
57     long trndex;
58     long trnluz;
59     long turns;
60     long wzdark;
61     long zzword;
62     long abbrev[LOCSIZ+1];
63     long atloc[LOCSIZ+1];
64     long dseen[NDWARVES+1];
65     long dloc[NDWARVES+1];
66     long odloc[NDWARVES+1];
67     long fixed[NOBJECTS+1];
68     long link[NOBJECTS*2 + 1];
69     long place[NOBJECTS+1];
70     long hinted[HNTSIZ+1];
71     long hintlc[HNTSIZ+1];
72     long prop[NOBJECTS+1];
73 };
74
75 extern struct game_t game;
76
77 extern long LNLENG, LNPOSN, PARMS[];
78 extern char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[], MAP2[];
79 extern FILE *logfp;
80 extern bool oldstyle;
81 extern lcg_state lcgstate;
82
83 /* b is not needed for POSIX but harmless */
84 #define READ_MODE "rb"
85 #define WRITE_MODE "wb"
86
87 extern void SPEAK(vocab_t);
88 extern void PSPEAK(vocab_t,int);
89 extern void RSPEAK(vocab_t);
90 extern void SETPRM(long,long,long);
91
92 extern bool fGETIN(FILE *,token_t*,token_t*,token_t*,token_t*);
93 #define GETIN(input,WORD1,WORD1X,WORD2,WORD2X) fGETIN(input,&WORD1,&WORD1X,&WORD2,&WORD2X)
94
95 extern long YES(FILE *,vocab_t,vocab_t,vocab_t);
96 extern long GETTXT(bool,bool,bool);
97 extern token_t MAKEWD(long);
98
99 extern void fPUTTXT(token_t,long*,long);
100 #define PUTTXT(WORD,STATE,CASE) fPUTTXT(WORD,&STATE,CASE)
101
102 extern void SHFTXT(long,long);
103 extern void TYPE0(void);
104
105 extern void fSAVWDS(long*,long*,long*,long*,long*,long*,long*);
106 #define SAVWDS(W1,W2,W3,W4,W5,W6,W7) fSAVWDS(&W1,&W2,&W3,&W4,&W5,&W6,&W7)
107 extern void fSAVARR(long*,long);
108 #define SAVARR(ARR,N) fSAVARR(ARR,N)
109 extern void fSAVWRD(long,long*);
110 #define SAVWRD(OP,WORD) fSAVWRD(OP,&WORD)
111
112 extern long VOCAB(long,long);
113 extern void DSTROY(long);
114 extern void JUGGLE(long);
115 extern void MOVE(long,long);
116 extern long PUT(long,long,long);
117 extern void CARRY(long,long);
118 extern void DROP(long,long);
119 extern long ATDWRF(long);
120 extern long SETBIT(long);
121 extern bool TSTBIT(long,int);
122 extern long RNDVOC(long,long);
123 extern void BUG(long);
124 extern void MAPLIN(FILE *);
125 extern void TYPE(void);
126 extern void MPINIT(void);
127
128 extern void fSAVEIO(long,long,long*);
129 #define SAVEIO(OP,IN,ARR) fSAVEIO(OP,IN,ARR)
130 extern void DATIME(long*, long*);
131
132 extern long MOD(long,long);
133
134 extern void set_seed(long);
135 extern unsigned long get_next_lcg_value(void);
136 extern long randrange(long);
137 extern void score(long);
138 extern int carry(long);
139 extern int discard(long, bool);
140 extern int attack(FILE *, long, long);
141 extern int throw(FILE *, long, long);
142 extern int feed(long);
143 extern int fill(long);
144
145 /*  Statement functions
146  *
147  *  AT(OBJ)     = true if on either side of two-placed object
148  *  CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
149  *  DARK(DUMMY) = true if location "LOC" is dark
150  *  FORCED(LOC) = true if LOC moves without asking for input (COND=2)
151  *  FOREST(LOC)  = true if LOC is part of the forest
152  *  GSTONE(OBJ)  = true if OBJ is a gemstone
153  *  HERE(OBJ)   = true if the OBJ is at "LOC" (or is being carried)
154  *  LIQ(DUMMY)  = object number of liquid in bottle
155  *  LIQLOC(LOC) = object number of liquid (if any) at LOC
156  *  PCT(N)       = true N% of the time (N integer from 0 to 100)
157  *  TOTING(OBJ) = true if the OBJ is being carried */
158
159 #define TOTING(OBJ)     (game.place[OBJ] == -1)
160 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
161 #define HERE(OBJ)       (AT(OBJ) || TOTING(OBJ))
162 #define LIQ2(PBOTL)     ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
163 #define LIQ(DUMMY)      (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
164 #define LIQLOC(LOC)     (LIQ2((MOD(COND[LOC]/2*2,8)-5)*MOD(COND[LOC]/4,2)+1))
165 #define CNDBIT(L,N)     (TSTBIT(COND[L],N))
166 #define FORCED(LOC)     (COND[LOC] == 2)
167 #define DARK(DUMMY)     ((!CNDBIT(game.loc,0)) && (game.prop[LAMP] == 0 || !HERE(LAMP)))
168 #define PCT(N)  (randrange(100) < (N))
169 #define GSTONE(OBJ)     ((OBJ) == EMRALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
170 #define FOREST(LOC)     ((LOC) >= 145 && (LOC) <= 166)
171 #define VOCWRD(LETTRS,SECT)     (VOCAB(MAKEWD(LETTRS),SECT))
172
173 /*  The following two functions were added to fix a bug (game.clock1 decremented
174  *  while in forest).  They should probably be replaced by using another
175  *  "cond" bit.  For now, however, a quick fix...  OUTSID(LOC) is true if
176  *  LOC is outside, INDEEP(LOC) is true if LOC is "deep" in the cave (hall
177  *  of mists or deeper).  Note special kludges for "Foof!" locs. */
178
179 #define OUTSID(LOC)     ((LOC) <= 8 || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == 180 || (LOC) == 182)
180 #define INDEEP(LOC)     ((LOC) >= 15 && !OUTSID(LOC) && (LOC) != 179)
181
182 /* vocabulary items */ 
183 extern long AMBER, ATTACK, AXE, BACK, BATTER, BEAR,
184    BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST,
185    CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS,
186    EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, INVENT,
187    JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGZIN, MESSAG, MIRROR, NUGGET, NUL,
188    OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAM,
189    RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SECT, SIGN, SNAKE,
190    STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2,
191    URN, VASE, VEND, VOLCAN, WATER;
192 /* evrything else */
193 extern long I, J, K, L, SPK, V1, V2, VRSION, WD1, WD1X, WD2, WD2X;
194