Move a few prototypes and static'ed a few functions
[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 JUGGLE(long);
98 extern void MOVE(long,long);
99 extern long PUT(long,long,long);
100 extern void CARRY(long,long);
101 extern void DROP(long,long);
102 extern long ATDWRF(long);
103 extern long SETBIT(long);
104 extern bool TSTBIT(long,int);
105 extern long RNDVOC(long,long);
106 extern void BUG(long) __attribute__((noreturn));
107 extern bool MAPLIN(FILE *);
108 extern void TYPE(void);
109 extern void DATIME(long*, long*);
110
111 enum termination {endgame, quitgame, scoregame};
112
113 extern void set_seed(long);
114 extern unsigned long get_next_lcg_value(void);
115 extern long randrange(long);
116 extern void score(enum termination);
117 extern int suspend(FILE *);
118 extern int resume(FILE *);
119 extern int restore(FILE *);
120
121 /*
122  *  MOD(N,M)    = Arithmetic modulus
123  *  AT(OBJ)     = true if on either side of two-placed object
124  *  CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
125  *  DARK(LOC)   = true if location "LOC" is dark
126  *  FORCED(LOC) = true if LOC moves without asking for input (COND=2)
127  *  FOREST(LOC) = true if LOC is part of the forest
128  *  GSTONE(OBJ) = true if OBJ is a gemstone
129  *  HERE(OBJ)   = true if the OBJ is at "LOC" (or is being carried)
130  *  LIQUID()    = object number of liquid in bottle
131  *  LIQLOC(LOC) = object number of liquid (if any) at LOC
132  *  PCT(N)      = true N% of the time (N integer from 0 to 100)
133  *  TOTING(OBJ) = true if the OBJ is being carried */
134
135 #define DESTROY(N)      MOVE(N, NOWHERE)
136 #define MOD(N,M)        ((N) % (M))
137 #define TOTING(OBJ)     (game.place[OBJ] == CARRIED)
138 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
139 #define HERE(OBJ)       (AT(OBJ) || TOTING(OBJ))
140 #define LIQ2(PBOTL)     ((1-(PBOTL))*WATER+((PBOTL)/2)*(WATER+OIL))
141 #define LIQUID()        (LIQ2(game.prop[BOTTLE]<0 ? -1-game.prop[BOTTLE] : game.prop[BOTTLE]))
142 #define LIQLOC(LOC)     (LIQ2((MOD(COND[LOC]/2*2,8)-5)*MOD(COND[LOC]/4,2)+1))
143 #define CNDBIT(L,N)     (TSTBIT(COND[L],N))
144 #define FORCED(LOC)     (COND[LOC] == 2)
145 #define DARK(DUMMY)     ((!CNDBIT(game.loc,LIGHT)) && (game.prop[LAMP] == 0 || !HERE(LAMP)))
146 #define PCT(N)          (randrange(100) < (N))
147 #define GSTONE(OBJ)     ((OBJ) == EMRALD || (OBJ) == RUBY || (OBJ) == AMBER || (OBJ) == SAPPH)
148 #define FOREST(LOC)     ((LOC) >= LOC_FOREST1 && (LOC) <= LOC_FOREST22)
149 #define VOCWRD(LETTRS,SECT)     (VOCAB(MAKEWD(LETTRS),SECT))
150 #define SPECIAL(LOC)    ((LOC) > SPECIALBASE)
151
152 /*  The following two functions were added to fix a bug (game.clock1 decremented
153  *  while in forest).  They should probably be replaced by using another
154  *  "cond" bit.  For now, however, a quick fix...  OUTSID(LOC) is true if
155  *  LOC is outside, INDEEP(LOC) is true if LOC is "deep" in the cave (hall
156  *  of mists or deeper).  Note special kludges for "Foof!" locs. */
157
158 #define OUTSID(LOC)     ((LOC) <= LOC_GRATE || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == LOC_FOOF2 || (LOC) == LOC_FOOF4)
159 #define INDEEP(LOC)     ((LOC) >= LOC_MISTHALL && !OUTSID(LOC) && (LOC) != LOC_FOOF1)
160
161 /* vocabulary items */ 
162 extern long AMBER, ATTACK, AXE, BACK, BATTER, BEAR,
163    BIRD, BLOOD, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST,
164    CLAM, COINS, DOOR, DPRSSN, DRAGON, DWARF, EGGS,
165    EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOD, GRATE, HINT, INVENT,
166    JADE, KEYS, KNIFE, LAMP, LOCK, LOOK, MAGZIN, MESSAG, MIRROR, NUGGET, NUL,
167    OGRE, OIL, OYSTER, PANIC, PEARL, PILLOW, PLANT, PLANT2, PYRAM,
168    RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAY, SIGN, SNAKE,
169    STEPS, STICK, STREAM, THROW, TRIDNT, TROLL, TROLL2,
170    URN, VASE, VEND, VOLCAN, WATER;
171
172 enum speechpart {unknown, intransitive, transitive};
173
174 void initialise(void);
175 int action(FILE *input, enum speechpart part, long verb, token_t obj);
176
177 /* Phase codes for action returns. 
178  * These were at one time FORTRAN line numbers.
179  * The values don't matter, but perturb their order at your peril.
180  */
181 #define GO_TERMINATE    2
182 #define GO_MOVE         8
183 #define GO_TOP          2000
184 #define GO_CLEAROBJ     2012
185 #define GO_CHECKHINT    2600
186 #define GO_CHECKFOO     2607
187 #define GO_CLOSEJUMP    2610
188 #define GO_DIRECTION    2620
189 #define GO_LOOKUP       2630
190 #define GO_WORD2        2800
191 #define GO_SPECIALS     1900
192 #define GO_UNKNOWN      8000
193 #define GO_ACTION       40000
194 #define GO_DWARFWAKE    19000
195
196 /* Symbols for cond bits */
197 #define LIGHT   0       /* Light */
198 #define OILY    1       /* If bit 2 is on: on for oil, off for water */
199 #define FLUID   2       /* Liquid asset, see bit 1 */
200 #define NOARRR  3       /* Pirate doesn't go here unless following player */
201 #define NOBACK  4       /* Cannot use "back" to move away */
202 /* Bits past 10 indicate areas of interest to "hint" routines */
203 #define HBASE   10      /* Base for location hint bitss */
204 #define HCAVE   11      /* Trying to get into cave */
205 #define HBIRD   12      /* Trying to catch bird */
206 #define HSNAKE  13      /* Trying to deal with snake */
207 #define HMAZE   14      /* Lost in maze */
208 #define HDARK   15      /* Pondering dark room */
209 #define HWITT   16      /* At Witt's End */
210 #define HCLIFF  17      /* Cliff with urn */
211 #define HWOODS  18      /* Lost in forest */
212 #define HOGRE   19      /* Trying to deal with ogre */
213 #define HJADE   20      /* Found all treasures except jade */
214
215 /* Special object statuses in game.place - can also be a location number (> 0) */
216 #define CARRIED         -1      /* Player is toting it */
217 #define NOWHERE 0       /* It's destroyed */
218
219 /* hack to ignore GCC Unused Result */
220 #define IGNORE(r) do{if (r){}}while(0)
221
222 /* end */
223