1 /* Interface between game parameters and the rest of Xconq.
2    Copyright (C) 1992-1996, 1998-2000 Stanley T. Shebs.
3 
4 Xconq is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.  See the file COPYING.  */
8 
9 /*! \file kernel/game.h
10  * \brief Interface between game parameters and the rest of Xconq.
11  *
12  * This file defines the structures that are filled in with type info,
13  * one for each type, plus the declarations for all functions and variables.
14  */
15 
16 /* Numbers guaranteed to be invalid types in each category.  Should be
17  * careful that these don't overflow anything.
18  */
19 
20 /*! \brief Non unit.
21  *
22  * Guaranteed not to be a Unit type. */
23 #define NONUTYPE (-1)
24 /*! \brief Non Material.
25  *
26  * Guaranteed not to be a Material type. */
27 #define NONMTYPE (-1)
28 
29 /*! \brief Non terrain.
30  *
31  * Guaranteed not to be a Terrain type. Used in interfaces for unseen terrain. */
32 #define NONTTYPE (-1)
33 
34 /*! \brief Bogus window background terrain.
35  *
36  * Used in interfaces for bogus terrain outside the map when redrawing the
37 window background. */
38 #define BACKTTYPE (-2)
39 
40 /*! \brief non advance.
41  *
42  * Guaranteed not to be an Advance type. */
43 #define NONATYPE (-1)
44 
45 /*! \brief Advance complete.
46  *
47  * Used in advances code, must not overlap with NONATYPE. */
48 #define DONE (-2)
49 
50 /*! \brief No advance.
51  *
52  * Used in advances code, must not overlap with NONATYPE, and
53  * presumably with DONE, as well. */
54 #define NOADVANCE (-3)
55 
56 /*! \brief Type of types.
57  *
58  * Indices for each category of types. */
59 typedef enum {
60   UTYP = 0, /*!< Unit */
61   MTYP = 1, /*!< Material */
62   TTYP = 2, /*!< Terrain */
63   ATYP = 3  /*!< Advance */
64 } Typetype;
65 
66 /*! \brief Terrain subtypes.
67  *
68  * The four roles for Terrain. */
69 enum terrain_subtype {
70     cellsubtype = 0,       /*!< Cell */
71     bordersubtype = 1,     /*!< Border */
72     connectionsubtype = 2, /*!< Connection */
73     coatingsubtype = 3     /*!< Coating */
74 };
75 
76 /* Ultimate limits on values in properties. */
77 
78 /*! \brief Low property value limit. */
79 #define PROPLO -32768
80 /*! \brief High property value limit. */
81 #define PROPHI 32767
82 
83 /* Ultimate limits on values in tables. */
84 
85 /*! \brief Low value in table. */
86 #define TABLO -32768
87 /*! \brief High value in table */
88 #define TABHI 32767
89 
90 /*! \brief Integer table. ??? */
91 #define TABINT 0
92 /*1 \brief Dice table.  ??? */
93 #define TABDICE 1
94 
95 /* Ultimate limits on values of globals. */
96 
97 /*! \brief Low value for globals. */
98 #define VARLO -2000000000
99 /*! \brief High value for globals. */
100 #define VARHI 2000000000
101 
102 #include "lisp.h"
103 
104 /*! \brief Property definition.
105  *
106  * This is the structure representing info about a property
107  * of a type, such as a unit type's maximum speed.
108  * */
109 typedef struct propertydefn {
110     char *name;                 		/*!< name */
111     int (*intgetter)(int);      		/*!< function to get n'th integer property */
112     char *(*strgetter)(int);    	/*!< function to get n'th string property */
113     Obj *(*objgetter)(int);		/*!< function to get n'th \Object property */
114     short offset;               		/*!< offset (to what ?) */
115     char *doc;                  		/*!< documentation */
116     short dflt;                 		/*!< default ? */
117     char *dfltstr;              		/*!< default string ? */
118     short lo;                   			/*!< low limit */
119     short hi;                   		/*!< high limit */
120 } PropertyDefn;
121 
122 /*! \brief Table definition.
123  *
124  * This is the structure with info about a table.
125  */
126 typedef struct tabledefn {
127     char *name;                 		/*!< name of the table */
128     int (*getter)(int, int);    	/*!< accessor function */
129     char *doc;                  		/*!< documentation string */
130     short **table;              		/*!< pointer to table itself */
131     short dflt;                 		/*!< default value of entries */
132     short lo;                   			/*!< lower bound of table values */
133     short hi;                   		/*!< upper bound of table values */
134     char index1;                		/*!< type of row indices */
135     char index2;                		/*!< type of column indices */
136     char valtype;               		/*!< type of data in table */
137 } TableDefn;
138 
139 /*! \brief Global Variables definition.
140  *
141  * This is the structure with that contains global access definitions
142  * and variables.
143  */
144 typedef struct vardefn {
145     char *name;                 		/*!< name of the global */
146     int   (*intgetter)(void);   	/*!< accessor if integer type */
147     char *(*strgetter)(void);   	/*!< accessor if string type */
148     Obj  *(*objgetter)(void);   	/*!< accessor if \Object type */
149     void (*intsetter)(int);     	/*!< setter if integer type */
150     void (*strsetter)(char *);  	/*!< setter if string type */
151     void (*objsetter)(Obj *);   	/*!< setter if object type */
152     char *doc;                  		/*!< documentation string */
153     int dflt;                   			/*!< default value if integer type */
154     char *dfltstr;              		/*!< default value if string type */
155     Obj *(*dfltfn)(void);       		/*<! function to return default value if object type */
156     int lo;                     			/*!< lower bound of integer value. */
157     int hi;                     			/*!< upper bound of integer value */
158 } VarDefn;
159 
160 /*! \brief Number of Unit types. */
161 extern short numutypes;
162 /*! \brief Number of Material types */
163 extern short nummtypes;
164 /*! \brief Number of Terrain types */
165 extern short numttypes;
166 /*! \brief Number of Advance types. */
167 extern short numatypes;
168 
169 #undef  DEF_UPROP_I
170 #define DEF_UPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
171     short SLOT; /*!< doc */
172 #undef  DEF_UPROP_S
173 #define DEF_UPROP_S(name,fname,doc,SLOT,dflt)  \
174     char *SLOT; /*!< doc */
175 #undef  DEF_UPROP_L
176 #define DEF_UPROP_L(name,fname,doc,SLOT)  \
177     Obj *SLOT;  /*!< doc */
178 
179 /*! \brief Unit Type Property Value.
180  *
181  * Define Unit type structure.  Each unit type property may be
182  * a short, a string, or a lisp object which is repeated
183  * for each unit type. It is used to return GDL property
184  * values.
185  *
186  */
187 typedef struct utype {
188 
189 #include "utype.def"
190 
191 } Utype;
192 
193 #undef  DEF_MPROP_I
194 #define DEF_MPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
195     short SLOT;
196 #undef  DEF_MPROP_S
197 #define DEF_MPROP_S(name,fname,doc,SLOT,dflt)  \
198     char *SLOT;
199 #undef  DEF_MPROP_L
200 #define DEF_MPROP_L(name,fname,doc,SLOT)  \
201     Obj *SLOT;
202 
203 /*! \brief Material type properties.
204  *
205  * Definition of Material type properties. Each material type
206  * property may be a short, a string, or a lisp object.  */
207 typedef struct mtype {
208 
209 #include "mtype.def"
210 
211 } Mtype;
212 
213 
214 #undef  DEF_TPROP_I
215 #define DEF_TPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
216     short SLOT;
217 #undef  DEF_TPROP_S
218 #define DEF_TPROP_S(name,fname,doc,SLOT,dflt)  \
219     char *SLOT;
220 #undef  DEF_TPROP_L
221 #define DEF_TPROP_L(name,fname,doc,SLOT)  \
222     Obj *SLOT;
223 
224 /*! \brief Terrain type properties.
225  *
226  * Definition of Terrain type properties. Each terrain type property
227  * can be a short, a string, or a lisp object. */
228 typedef struct ttype {
229 
230 #include "ttype.def"
231 
232 } Ttype;
233 
234 #undef  DEF_APROP_I
235 #define DEF_APROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
236     short SLOT;
237 #undef  DEF_APROP_S
238 #define DEF_APROP_S(name,fname,doc,SLOT,dflt)  \
239     char *SLOT;
240 #undef  DEF_APROP_L
241 #define DEF_APROP_L(name,fname,doc,SLOT)  \
242     Obj *SLOT;
243 
244 /*! \brief Advance type properties.
245  *
246  * Definition of Advance type properties. Each Advance type property
247  * may be a short, a string, or a lisp object. */
248 typedef struct atype {
249 
250 #include "atype.def"
251 
252 } Atype;
253 
254 #undef  DEF_VAR_I
255 #define DEF_VAR_I(name,fname,setfname,doc,VAR,lo,dflt,hi)  \
256     int VAR;
257 #undef  DEF_VAR_S
258 #define DEF_VAR_S(name,fname,setfname,doc,VAR,dflt)  \
259     char *VAR;
260 #undef  DEF_VAR_L
261 #define DEF_VAR_L(name,fname,setfname,doc,VAR,dflt)  \
262     Obj *VAR;
263 
264 /*! \brief Global data structure.
265  *
266  * The global data can be an int, a string, or a lisp object. */
267 typedef struct a_globals {
268 
269 #include "gvar.def"
270 
271 } Globals;
272 
273 /* Declarations of the functions accessing and setting type properties. */
274 
275 #undef  DEF_UPROP_I
276 #define DEF_UPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME(int u);
277 #undef  DEF_UPROP_S
278 #define DEF_UPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME(int u);
279 #undef  DEF_UPROP_L
280 #define DEF_UPROP_L(name,FNAME,doc,slot)  Obj *FNAME(int u);
281 
282 #include "utype.def"
283 
284 #undef  DEF_MPROP_I
285 #define DEF_MPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME(int m);
286 #undef  DEF_MPROP_S
287 #define DEF_MPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME(int m);
288 #undef  DEF_MPROP_L
289 #define DEF_MPROP_L(name,FNAME,doc,slot)  Obj *FNAME(int m);
290 
291 #include "mtype.def"
292 
293 #undef  DEF_TPROP_I
294 #define DEF_TPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME(int t);
295 #undef  DEF_TPROP_S
296 #define DEF_TPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME(int t);
297 #undef  DEF_TPROP_L
298 #define DEF_TPROP_L(name,FNAME,doc,slot)  Obj *FNAME(int t);
299 
300 #include "ttype.def"
301 
302 #undef  DEF_APROP_I
303 #define DEF_APROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME(int a);
304 #undef  DEF_APROP_S
305 #define DEF_APROP_S(name,FNAME,doc,slot,dflt)  char *FNAME(int a);
306 #undef  DEF_APROP_L
307 #define DEF_APROP_L(name,FNAME,doc,slot)  Obj *FNAME(int a);
308 
309 #include "atype.def"
310 
311 #undef  DEF_VAR_I
312 #define DEF_VAR_I(str,FNAME,SETFNAME,doc,var,lo,dflt,hi)  \
313   int FNAME(void);
314 #undef  DEF_VAR_S
315 #define DEF_VAR_S(str,FNAME,SETFNAME,doc,var,dflt)  \
316   char *FNAME(void);
317 #undef  DEF_VAR_L
318 #define DEF_VAR_L(str,FNAME,SETFNAME,doc,var,dflt)  \
319   Obj *FNAME(void);
320 
321 #include "gvar.def"
322 
323 #undef  DEF_VAR_I
324 #define DEF_VAR_I(str,FNAME,SETFNAME,doc,var,lo,dflt,hi)  \
325   void SETFNAME(int val);
326 #undef  DEF_VAR_S
327 #define DEF_VAR_S(str,FNAME,SETFNAME,doc,var,dflt)  \
328   void SETFNAME(char *val);
329 #undef  DEF_VAR_L
330 #define DEF_VAR_L(str,FNAME,SETFNAME,doc,var,dflt)  \
331   void SETFNAME(Obj *val);
332 
333 #include "gvar.def"
334 
335 /* Declarations of table accessor functions and the globals
336    for constant and filled-in tables. */
337 
338 #undef  DEF_UU_TABLE
339 #define DEF_UU_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
340   int FNAME(int u1, int u2);
341 
342 #undef  DEF_UM_TABLE
343 #define DEF_UM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
344   int FNAME(int u, int m);
345 
346 #undef  DEF_UT_TABLE
347 #define DEF_UT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
348   int FNAME(int u, int t);
349 
350 #undef  DEF_TM_TABLE
351 #define DEF_TM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
352   int FNAME(int t, int m);
353 
354 #undef  DEF_TT_TABLE
355 #define DEF_TT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
356   int FNAME(int t1, int t2);
357 
358 #undef  DEF_MM_TABLE
359 #define DEF_MM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
360   int FNAME(int m1, int m2);
361 
362 #undef  DEF_UA_TABLE
363 #define DEF_UA_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
364   int FNAME(int u, int a);
365 
366 #undef  DEF_AM_TABLE
367 #define DEF_AM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
368   int FNAME(int a, int m);
369 
370 #undef  DEF_AA_TABLE
371 #define DEF_AA_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
372   int FNAME(int a1, int a2);
373 
374 #include "table.def"
375 
376 #undef  DEF_UU_TABLE
377 #define DEF_UU_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
378   extern short *TABLE, CNST;
379 
380 #undef  DEF_UM_TABLE
381 #define DEF_UM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
382   extern short *TABLE, CNST;
383 
384 #undef  DEF_UT_TABLE
385 #define DEF_UT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
386   extern short *TABLE, CNST;
387 
388 #undef  DEF_TM_TABLE
389 #define DEF_TM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
390   extern short *TABLE, CNST;
391 
392 #undef  DEF_TT_TABLE
393 #define DEF_TT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
394   extern short *TABLE, CNST;
395 
396 #undef  DEF_MM_TABLE
397 #define DEF_MM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
398   extern short *TABLE, CNST;
399 
400 #undef  DEF_UA_TABLE
401 #define DEF_UA_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
402   extern short *TABLE, CNST;
403 
404 #undef  DEF_AM_TABLE
405 #define DEF_AM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
406   extern short *TABLE, CNST;
407 
408 #undef  DEF_AA_TABLE
409 #define DEF_AA_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
410   extern short *TABLE, CNST;
411 
412 #include "table.def"
413 
414 /* Declarations of the globals description structures. */
415 
416 /*! \brief \ref a_globals "Global" data variable. */
417 extern Globals globals;
418 
419 /*! \brief Unit type properties. */
420 extern Utype *utypes;
421 
422 /*! \brief Material type properties. */
423 extern Mtype *mtypes;
424 
425 /*! \brief Terrain type properties. */
426 extern Ttype *ttypes;
427 
428 /*! \brief Advance type properties. */
429 extern Atype *atypes;
430 
431 /*! \brief Array of Unit type property definitions. */
432 extern PropertyDefn utypedefns[];
433 
434 /*! \brief Array of Material type property definitions. */
435 extern PropertyDefn mtypedefns[];
436 
437 /*! \brief Array of Terrain type property definitions. */
438 extern PropertyDefn ttypedefns[];
439 
440 /*! \brief Array of Advance type property definitions. */
441 extern PropertyDefn atypedefns[];
442 
443 /*! \brief Array of table definitions. */
444 extern TableDefn tabledefns[];
445 
446 /*! \brief Array of variable definitions. */
447 extern VarDefn vardefns[];
448 
449 /* Macros for iterating over types. */
450 
451 /*! \brief Iterate all Unit types.
452  *
453  * For header to iterate through all Unit types defined.
454  * \param v is the Unit type iteration variable.
455  */
456 #define for_all_unit_types(v)      for (v = 0; v < numutypes; ++v)
457 
458 /*! \brief Iterate all Material types.
459  *
460  * For header to iterate through all Material types.
461  * \param v is the Material type iteration variable.
462  */
463 #define for_all_material_types(v)  for (v = 0; v < nummtypes; ++v)
464 
465 /*! \brief Iterate through all Terrain types.
466  *
467  * For header to iterate through all Terrain types.
468  * \param v is the Terran iteration variable.
469  */
470 #define for_all_terrain_types(v)   for (v = 0; v < numttypes; ++v)
471 
472 /*! \brief Iterate through all Advance types.
473  *
474  * For header to iterate through all Advance types.
475  * \param v is the Advance iteration variable.
476  */
477 #define for_all_advance_types(v)   for (v = 0; v < numatypes; ++v)
478 
479 /*! \brief Iterate through aux terrain types.
480  *
481  * Iterate over aux terrain types by using cached array
482  * linking each type to the next.
483  * \param t is the Terrain iteration variable.
484  */
485 #define for_all_aux_terrain_types(t)    \
486   for ((t) = first_auxt_type; (t) >= 0; (t) = next_auxt_type[(t)])
487 
488 /*! \brief Iterate through borders.
489  *
490  * Iterate over border types by using a cached array
491  * linking each type to the next.
492  * \param t is the Terrain iteration variable.
493  */
494 #define for_all_border_types(t)  \
495   for ((t) = first_bord_type; (t) >= 0; (t) = next_bord_type[(t)])
496 
497 /*! \brief Iterate through connections.
498  *
499  * Iterate over connection types by using a cached array
500  * linking each type to the next.
501  * \param t is the Terrain iteration variable.
502  */
503 #define for_all_connection_types(t)  \
504   for ((t) = first_conn_type; (t) >= 0; (t) = next_conn_type[(t)])
505 
506 /* Macros encapsulating things about units. */
507 
508 /*! \brief Check Unit type range.
509  *
510  * If the Unit is out of range, call utype_error().
511  * \see numutypes, utype_error.
512  * \param x is the Unit type.
513  */
514 #define checku(x) if ((x) < 0 || (x) >= numutypes) utype_error(x);
515 
516 /*! \brief Check Material type range.
517  *
518  * If the Material type is out of range, call mtype_error().
519  * \see nummtypes, mtype_error.
520  * \param x is the Terrain type.
521  */
522 #define checkm(x) if ((x) < 0 || (x) >= nummtypes) mtype_error(x);
523 
524 /*! \brief Check Terrain type range.
525  *
526  * If the Terrain type is out of range, call ttype_error().
527  * \see numttypes, ttype_error.
528  * \param x is the Terrain type.
529  */
530 #define checkt(x) if ((x) < 0 || (x) >= numttypes) ttype_error(x);
531 
532 /*! \brief Check Advance type range.
533  *
534  * If the Advance type is out of range, call atype_error().
535  * \see numatypes, atype_error.
536  * \param x is the Advance type.
537  */
538 #define checka(x) if ((x) < 0 || (x) >= numatypes) atype_error(x);
539 
540 /* Fix eventually. */
541 
542 /* (should say u_... or ..._type ?) */
543 
544 /*! \brief Is actor?
545  *
546  * Is the Unit ACP greater than 0?
547  * \see u_acp.
548  * \todo reanme to u_actor or actor_type?
549  * \param u is a Unit type.
550  * \return
551  *    - FALSE if the ACP of the \Unit is less than 1,
552  *    - TRUE otherwise.
553  */
554 #define actor(u) (u_acp(u) > 0)
555 
556 /*! \brief Is mobile?
557  *
558  * Is the Unit capable of moving?
559  * \see u_speed.
560  * \todo rename to u_mobile or moble_type?
561  * \param u is a Unit type.
562  * \return
563  *    - TRUE if the Unit type's speed is greater than 0;
564  *    - FALSE otherwise.
565  */
566 #define mobile(u) (u_speed(u) > 0)
567 
568 //! Is utype mobile?
569 /*!
570     \todo Consider ACP-less or ACP-indep movement. Materials are then the
571 	    limiting factor and so this macro will no longer suffice.
572 */
573 #define u_mobile(u) (0 < mp_per_turn_max(u))
574 
575 /*! \brief Unit hit points.
576  *
577  * Get the Unit type's maximum hit points.
578  * \see u_hp_max.
579  * \param u is unit type.
580  * \return the maximum hit points for the unit.
581  */
582 #define u_hp(u) (u_hp_max(u))
583 
584 //! Could u be on t?
585 extern int could_be_on(int u, int t);
586 
587 /*! \brief Can Unit survive on Terrain?
588  *
589  * Check to see if a Unit type can live on a Terrain type.
590  * \see cold_be_on, ut_vanishes_on, ut_wrecks_on.
591  * \param u is the Unit type.
592  * \param t is the Terrain type.
593  * \return
594  *   - TRUE if
595  *     - the Unit type can be on the Terrain type, and
596  *     - the Unit type won't vanish on the Terrain type, and
597  *     - the Unit type won't wreck on the Terrain type;
598  *   - FALsE otherwise.
599  */
600 #define could_live_on(u,t)  \
601    (could_be_on(u, t) && !ut_vanishes_on(u, t) && !ut_wrecks_on(u, t))
602 
603 /*! \brief Unit could carry Unit?
604  *
605  * Check to see if a Unit type may carry another Unit type.
606  * \see uu_capacity_x, uu_size, u_capacity.
607  * \param u1 is the transport Unit type.
608  * \param u2 is the passenger Unit type.
609  * \returns
610  *   - TRUE if
611  *     - the transport can explictly carry the passenger, or
612  *     - the size of the passenger on the transport is less than
613  *       the transport's capacity;
614  *   - FALSE otherwise.
615  */
616 #define could_carry(u1,u2)  \
617   (uu_capacity_x(u1, u2) > 0 || uu_size(u2, u1) <= u_capacity(u1))
618 
619 /*! \brief Unit could develop Unit?
620  *
621  * Check to see a Unit type can develop a Unit type.
622  * \see uu_acp_to_develop.
623  * \param u1 is the developing Unit type.
624  * \param u2 is the developed Unit type.
625  * \return
626  *   - TRUE if possible;
627  *   - FALSE otherwise.
628  */
629 #define could_develop(u1,u2) (uu_acp_to_develop(u1, u2) > 0)
630 
631 /* These need actual units rather than types. */
632 
633 /*! \brief Impassable?
634  *
635  * Can \ref a_unit "unit" pass the Terrain at the cell?
636  * \see could_be_on, terrain_at.
637  * \param u is a pointer to a Unit.
638  * \param x is the x-coordinate of the cell.
639  * \param y is the y-coordinate of the cell.
640  * \return
641  *   - TRUE if the Unit type could not be on the Terrain type at (x,y);
642  *   - FALSE otherwise.
643  */
644 #define impassable(u, x, y) (!could_be_on((u)->type, terrain_at((x), (y))))
645 
646 /*! \brief Is the Unit a base?
647  *
648  * Check to see the the type of the Unit is a base.
649  * \see u_is_base.
650  * \param u is a pointer to a Unit.
651  * \return
652  *   - TRUE if the type of the \Unit is a base type;
653  *   - FALSE otherwise.
654  */
655 #define isbase(u) (u_is_base((u)->type))
656 
657 /*! \brief Is the Unit a base builder?
658  *
659  * Check to see the the type of the Unit is a base builder.
660  * \see u_is_base_builder.
661  * \param u is a pointer to a Unit.
662  * \return
663  *   - TRUE if the type of the \Unit is a base builder type;
664  *   - FALSE otherwise.
665  */
666 #define base_builder(u) (u_is_base_builder((u)->type))
667 
668 /*! \brief Is the Unit a transport?
669  *
670  * Check to see the the type of the Unit is a transport.
671  * \see u_is_transport.
672  * \param u is a pointer to a Unit.
673  * \return
674  *   - TRUE if the type of the \Unit is a transport type;
675  *   - FALSE otherwise.
676  */
677 #define istransport(u) (u_is_transport((u)->type))
678 
679 /*! \brief Is the Terrain a cell?
680  *
681  * Check to see the Terrain subtype is a cell.
682  * \see t_subtype, cellsubtype.
683  * \param t is a Terrain type.
684  * \return
685  *   - TRUE if the Terrain's subtype is cell.
686  *   - FALSE otherwise.
687  */
688 #define t_is_cell(t) (t_subtype(t) == cellsubtype)
689 
690 /*! \brief Is the Terrain a border?
691  *
692  * Check to see the Terrain subtype is a border.
693  * \see t_subtype, bordersubtype.
694  * \param t is a Terrain type.
695  * \return
696  *   - TRUE if the Terrain's subtype is border.
697  *   - FALSE otherwise.
698  */
699 #define t_is_border(t) (t_subtype(t) == bordersubtype)
700 
701 /*! \brief Is the Terrain a connection?
702  *
703  * Check to see the Terrain subtype is a connection.
704  * \see t_subtype, connectionsubtype.
705  * \param t is a Terrain type.
706  * \return
707  *   - TRUE if the Terrain's subtype is connection.
708  *   - FALSE otherwise.
709  */
710 #define t_is_connection(t) (t_subtype(t) == connectionsubtype)
711 
712 /*! \brief Is the Terrain a coating?
713  *
714  * Check to see the Terrain subtype is a coating.
715  * \see t_subtype, coatingsubtype.
716  * \param t is a Terrain type.
717  * \return
718  *   - TRUE if the Terrain's subtype is coating.
719  *   - FALSE otherwise.
720  */
721 #define t_is_coating(t) (t_subtype(t) == coatingsubtype)
722 
723 /*! \brief Is the Unit type valid?
724  *
725  * Check to see if the Unit type is within the range of
726  * Unit types.
727  * \see numutypes.
728  * \param u is the Unit type.
729  * \return
730  *   - TRUE if the Unit type is withing range;
731  *   - FALSE, otherwise.
732  */
733 #define is_unit_type(u) ((u) >= 0 && (u) < numutypes)
734 
735 /*! \brief Is the Material type valid?
736  *
737  * Check to see if the Material type is within the range of
738  * Material types.
739  * \see nummtypes.
740  * \param m is the Material type.
741  * \return
742  *   - TRUE if the Material type is within range;
743  *   - FALSE, otherwise.
744  */
745 #define is_material_type(m) ((m) >= 0 && (m) < nummtypes)
746 
747 /*! \brief Is the Terrain type valid?
748  *
749  * Check to see if the Terrain type is within the range of
750  * Terrain types.
751  * \see numttypes.
752  * \param t is the Terrain type.
753  * \return
754  *   - TRUE if the Terrain type is within range;
755  *   - FALSE, otherwise.
756  */
757 #define is_terrain_type(t) ((t) >= 0 && (t) < numttypes)
758 
759 /*! \brief Is the Advance type valid?
760  *
761  * Check to see if the Advance type is within the range of
762  * Advance types.
763  * \see numatypes.
764  * \param a is the Advance type.
765  * \return
766  *   - TRUE if the Advance type is within range;
767  *   - FALSE, otherwise.
768  */
769 #define is_advance_type(a) ((a) >= 0 && (a) < numatypes)
770 
771 /*! \brief Can add Unit type flag. */
772 extern short canaddutype;
773 /*! \brief Can add Material type flag. */
774 extern short canaddmtype;
775 /*! \brief Can add Terrain type flag. */
776 extern short canaddttype;
777 /*! \brief Can add Advance type flag. */
778 extern short canaddatype;
779 
780 /*! \brief Temporary Unit type. */
781 extern short tmputype;
782 /*! \brief Temporary Material type. */
783 extern short tmpmtype;
784 /*! \brief Temporary Terrain type. */
785 extern short tmpttype;
786 /*! \brief Temporary Advance type. */
787 extern short tmpatype;
788 
789 /*! \brief Number of cell types. */
790 extern int numcelltypes;
791 /*! \brief Number of border types. */
792 extern int numbordtypes;
793 /*! \brief Number of connection types. */
794 extern int numconntypes;
795 /*! \brief Number of coating types. */
796 extern int numcoattypes;
797 
798 /*! \brief Head of aux terrain type list. */
799 extern short first_auxt_type;
800 /*! \brief Next aux terrain type in list. */
801 extern short *next_auxt_type;
802 /*! \brief Head of border type list. */
803 extern short first_bord_type;
804 /*! \brief Next border type in list. */
805 extern short *next_bord_type;
806 /*! \brief Head of connection type list. */
807 extern short first_conn_type;
808 /*! \brief Next connection type in list. */
809 extern short *next_conn_type;
810 
811 /*! \brief Tempoary Unit type array. */
812 extern int *tmp_u_array;
813 //! More utype scratch space.
814 extern int *tmp_u2_array;
815 /*! \brief Tempoary Terrain type array. */
816 extern int *tmp_t_array;
817 /*! \brief Tempoary Material type array. */
818 extern int *tmp_m_array;
819 /*! \brief Tempoary Advance type array. */
820 extern int *tmp_a_array;
821 
822 //! Scratch space in the likeness of a TableUU.
823 extern int **tmp_uu_array;
824 
825 extern void utype_error(int u);
826 extern void mtype_error(int m);
827 extern void ttype_error(int t);
828 extern void atype_error(int s);
829 
830 extern void init_types(void);
831 extern void init_globals(void);
832 extern int create_unit_type(void);
833 extern int create_material_type(void);
834 extern int create_terrain_type(void);
835 extern int create_advance_type(void);
836 extern void default_unit_type(int x);
837 extern void default_material_type(int x);
838 extern void default_terrain_type(int x);
839 extern void default_advance_type(int x);
840 
841 extern void allocate_table(int tbl, int reset);
842 extern int numtypes_from_index_type(int x);
843 extern char *index_type_name(int x);
844 
845 extern void disallow_more_unit_types(void);
846 extern void disallow_more_terrain_types(void);
847 extern void disallow_more_material_types(void);
848 extern void disallow_more_advance_types(void);
849 extern void count_terrain_subtypes(void);
850 
851 /* Accessors for table, property, and global defaults. */
852 
853 //! Default value for table.
854 extern int table_default(int (*getter)(int, int));
855 //! Default value for integer uprop.
856 extern short uprop_i_default(int (*intgetter)(int));
857 //! Default value for string uprop.
858 extern char *uprop_s_default(char *(*strgetter)(int));
859 //! Default value for Lisp uprop.
860 extern Obj *uprop_l_default(Obj *(*objgetter)(int));
861 //! Default value for integer tprop.
862 extern short tprop_i_default(int (*intgetter)(int));
863 //! Default value for string tprop.
864 extern char *tprop_s_default(char *(*strgetter)(int));
865 //! Default value for Lisp tprop.
866 extern Obj *tprop_l_default(Obj *(*objgetter)(int));
867 //! Default value for integer mprop.
868 extern short mprop_i_default(int (*intgetter)(int));
869 //! Default value for string mprop.
870 extern char *mprop_s_default(char *(*strgetter)(int));
871 //! Default value for Lisp mprop.
872 extern Obj *mprop_l_default(Obj *(*objgetter)(int));
873 //! Default value for integer aprop.
874 extern short aprop_i_default(int (*intgetter)(int));
875 //! Default value for string aprop.
876 extern char *aprop_s_default(char *(*strgetter)(int));
877 //! Default value for Lisp aprop.
878 extern Obj *aprop_l_default(Obj *(*objgetter)(int));
879 //! Default value for integer gvar.
880 extern int gvar_i_default(int (*intgetter)(void));
881 //! Default value for string gvar.
882 extern char *gvar_s_default(char *(*strgetter)(void));
883 //! Default value for Lisp gvar.
884 extern Obj *gvar_l_default(Obj *(*objgetter)(void));
885 
886 extern Obj * g_synth_methods_default(void);
887