home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Xconq 7.1.0 / src / xconq-7.1.0 / kernel / game.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-07  |  10.5 KB  |  380 lines  |  [TEXT/R*ch]

  1. /* Interface between game parameters and the rest of Xconq.
  2.    Copyright (C) 1992, 1993, 1994 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. /* This file defines the structures that are filled in with type info,
  10.    one for each type, plus the declarations for all functions and variables. */
  11.  
  12. /* Numbers guaranteed to be invalid types in each category.  Should be
  13.    careful that these don't overflow anything. */
  14.  
  15. #define NONUTYPE (MAXUTYPES)
  16. #define NONMTYPE (MAXMTYPES)
  17. #define NONTTYPE (MAXTTYPES)
  18.  
  19. /* Indices for each category of types. */
  20.  
  21. typedef enum {
  22.   UTYP = 0,
  23.   MTYP = 1,
  24.   TTYP = 2
  25. } Typetype;
  26.  
  27. /* The four roles for terrain. */
  28.  
  29. enum terrain_subtype {
  30.     cellsubtype = 0,
  31.     bordersubtype = 1,
  32.     connectionsubtype = 2,
  33.     coatingsubtype = 3
  34. };
  35.  
  36. /* Ultimate limits on values in properties. */
  37.  
  38. #define PROPLO -32768
  39. #define PROPHI 32767
  40.  
  41. /* Ultimate limits on values in tables. */
  42.  
  43. #define TABLO -32768
  44. #define TABHI 32767
  45.  
  46. /* Ultimate limits on values of globals. */
  47.  
  48. #define VARLO -2000000000
  49. #define VARHI 2000000000
  50.  
  51. /* If a specialized Xconq is being compiled, use the specialized .h
  52.    instead of the general one.  All of the general game parameter
  53.    machinery should go away and be replaced by either constant
  54.    defaults or precalculated tables/formulas. */
  55.  
  56. #ifdef SPECIAL
  57.  
  58. #include "special.h"
  59.  
  60. #else
  61.  
  62. #include "lisp.h"
  63.  
  64. /* This is the structure representing info about a property
  65.    of a type, such as a unit type's maximum speed. */
  66.  
  67. typedef struct propertydefn {
  68.     char *name;
  69.     int (*intgetter) PARAMS ((int));
  70.     char *(*strgetter) PARAMS ((int));
  71.     Obj *(*objgetter) PARAMS ((int));
  72.     short offset;
  73.     char *doc;
  74.     short dflt;
  75.     char *dfltstr;
  76.     void (*dlftfn) PARAMS ((void));
  77.     short lo, hi;
  78. } PropertyDefn;
  79.  
  80. /* This is the structure with info about a table. */
  81.  
  82. typedef struct tabledefn {
  83.     char *name;            /* name of the table */
  84.     int (*getter) PARAMS ((int, int));  /* accessor function */
  85.     char *doc;            /* documentation string */
  86.     short **table;        /* pointer to table itself */
  87.     short *cnst;        /* pointer to constant value, if table is constant */
  88.     short dflt;            /* default value of entries */
  89.     short lo, hi;        /* bounds of table value */
  90.     char index1, index2;    /* type of row and column indices */
  91. } TableDefn;
  92.  
  93. /* This is the structure with info about a global variable. */
  94.  
  95. typedef struct vardefn {
  96.     char *name;            /* name of the global */
  97.     int   (*intgetter) PARAMS ((void));  /* accessor if integer type */
  98.     char *(*strgetter) PARAMS ((void));  /* accessor if string type */
  99.     Obj  *(*objgetter) PARAMS ((void));  /* accessor if object type */
  100.     void (*intsetter) PARAMS ((int));  /* setter if integer type */
  101.     void (*strsetter) PARAMS ((char *));  /* setter if string type */
  102.     void (*objsetter) PARAMS ((Obj *));  /* setter if object type */
  103.     char *doc;            /* documentation string */
  104.     int dflt;            /* default value if integer type */
  105.     char *dfltstr;        /* default value if string type */
  106.     void (*dfltfn) PARAMS ((void));  /* default value if object type */
  107.     int lo, hi;            /* bounds of integer value */
  108. } VarDefn;
  109.  
  110. extern short numutypes;
  111. extern short nummtypes;
  112. extern short numttypes;
  113.  
  114. typedef struct utype {
  115.  
  116. #undef  DEF_UPROP_I
  117. #define DEF_UPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
  118.     short SLOT;
  119. #undef  DEF_UPROP_S
  120. #define DEF_UPROP_S(name,fname,doc,SLOT,dflt)  \
  121.     char *SLOT;
  122. #undef  DEF_UPROP_L
  123. #define DEF_UPROP_L(name,fname,doc,SLOT)  \
  124.     Obj *SLOT;
  125.  
  126. #include "utype.def"
  127.  
  128. } Utype;
  129.  
  130. /* Definition of material types. */
  131.  
  132. typedef struct mtype {
  133.  
  134. #undef  DEF_MPROP_I
  135. #define DEF_MPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
  136.     short SLOT;
  137. #undef  DEF_MPROP_S
  138. #define DEF_MPROP_S(name,fname,doc,SLOT,dflt)  \
  139.     char *SLOT;
  140. #undef  DEF_MPROP_L
  141. #define DEF_MPROP_L(name,fname,doc,SLOT)  \
  142.     Obj *SLOT;
  143.  
  144. #include "mtype.def"
  145.  
  146. } Mtype;
  147.  
  148. /* Definition of terrain types. */
  149.  
  150. typedef struct ttype {
  151.  
  152. #undef  DEF_TPROP_I
  153. #define DEF_TPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
  154.     short SLOT;
  155. #undef  DEF_TPROP_S
  156. #define DEF_TPROP_S(name,fname,doc,SLOT,dflt)  \
  157.     char *SLOT;
  158. #undef  DEF_TPROP_L
  159. #define DEF_TPROP_L(name,fname,doc,SLOT)  \
  160.     Obj *SLOT;
  161.  
  162. #include "ttype.def"
  163.  
  164. } Ttype;
  165.  
  166. /* The global data. */
  167.  
  168. typedef struct a_globals {
  169.  
  170. #undef  DEF_VAR_I
  171. #define DEF_VAR_I(name,fname,setfname,doc,VAR,lo,dflt,hi)  \
  172.     int VAR;
  173. #undef  DEF_VAR_S
  174. #define DEF_VAR_S(name,fname,setfname,doc,VAR,dflt)  \
  175.     char *VAR;
  176. #undef  DEF_VAR_L
  177. #define DEF_VAR_L(name,fname,setfname,doc,VAR,dflt)  \
  178.     Obj *VAR;
  179.  
  180. #include "gvar.def"
  181.  
  182. } Globals;
  183.  
  184. /* Declarations of the functions accessing and setting type properties. */
  185.  
  186. #undef  DEF_UPROP_I
  187. #define DEF_UPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME PARAMS ((int u));
  188. #undef  DEF_UPROP_S
  189. #define DEF_UPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME PARAMS ((int u));
  190. #undef  DEF_UPROP_L
  191. #define DEF_UPROP_L(name,FNAME,doc,slot)  Obj *FNAME PARAMS ((int u));
  192.  
  193. #include "utype.def"
  194.  
  195. #undef  DEF_MPROP_I
  196. #define DEF_MPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME PARAMS ((int m));
  197. #undef  DEF_MPROP_S
  198. #define DEF_MPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME PARAMS ((int m));
  199. #undef  DEF_MPROP_L
  200. #define DEF_MPROP_L(name,FNAME,doc,slot)  Obj *FNAME PARAMS ((int m));
  201.  
  202. #include "mtype.def"
  203.  
  204. #undef  DEF_TPROP_I
  205. #define DEF_TPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME PARAMS ((int t));
  206. #undef  DEF_TPROP_S
  207. #define DEF_TPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME PARAMS ((int t));
  208. #undef  DEF_TPROP_L
  209. #define DEF_TPROP_L(name,FNAME,doc,slot)  Obj *FNAME PARAMS ((int t));
  210.  
  211. #include "ttype.def"
  212.  
  213. #undef  DEF_VAR_I
  214. #define DEF_VAR_I(str,FNAME,SETFNAME,doc,var,lo,dflt,hi)  \
  215.   int FNAME PARAMS ((void));  \
  216.   void SETFNAME PARAMS ((int val));
  217. #undef  DEF_VAR_S
  218. #define DEF_VAR_S(str,FNAME,SETFNAME,doc,var,dflt)  \
  219.   char *FNAME PARAMS ((void));  \
  220.   void SETFNAME PARAMS ((char *val));
  221. #undef  DEF_VAR_L
  222. #define DEF_VAR_L(str,FNAME,SETFNAME,doc,var,dflt)  \
  223.   Obj *FNAME PARAMS ((void));  \
  224.   void SETFNAME PARAMS ((Obj *val));
  225.  
  226. #include "gvar.def"
  227.  
  228. /* Declarations of table accessor functions and the globals
  229.    for constant and filled-in tables. */
  230.  
  231. #undef  DEF_UU_TABLE
  232. #define DEF_UU_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  233.   int FNAME PARAMS ((int u1, int u2));  \
  234.   extern short *TABLE, CNST;
  235. #undef  DEF_UM_TABLE
  236. #define DEF_UM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  237.   int FNAME PARAMS ((int u, int m));  \
  238.   extern short *TABLE, CNST;
  239. #undef  DEF_UT_TABLE
  240. #define DEF_UT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  241.   int FNAME PARAMS ((int u, int t));  \
  242.   extern short *TABLE, CNST;
  243. #undef  DEF_TM_TABLE
  244. #define DEF_TM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  245.   int FNAME PARAMS ((int t, int m));  \
  246.   extern short *TABLE, CNST;
  247. #undef  DEF_TT_TABLE
  248. #define DEF_TT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  249.   int FNAME PARAMS ((int t1, int t2));  \
  250.   extern short *TABLE, CNST;
  251. #undef  DEF_MM_TABLE
  252. #define DEF_MM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi)  \
  253.   int FNAME PARAMS ((int m1, int m2));  \
  254.   extern short *TABLE, CNST;
  255.  
  256. #include "table.def"
  257.  
  258. /* Declarations of the globals description structures. */
  259.  
  260. extern Globals globals;
  261.  
  262. extern Utype *utypes;
  263.  
  264. extern Mtype *mtypes;
  265.  
  266. extern Ttype *ttypes;
  267.  
  268. extern PropertyDefn utypedefns[];
  269.  
  270. extern PropertyDefn mtypedefns[];
  271.  
  272. extern PropertyDefn ttypedefns[];
  273.  
  274. extern TableDefn tabledefns[];
  275.  
  276. extern VarDefn vardefns[];
  277.  
  278. #endif /* SPECIAL */
  279.  
  280. /* The following definitions are valid for both general and specialized
  281.    games. */
  282.  
  283. /* Macros for iterating over types. */
  284.  
  285. #define for_all_unit_types(v)      for (v = 0; v < numutypes; ++v)
  286.  
  287. #define for_all_material_types(v)  for (v = 0; v < nummtypes; ++v)
  288.  
  289. #define for_all_terrain_types(v)   for (v = 0; v < numttypes; ++v)
  290.  
  291. #define for_all_possible_unit_types(v)      for (v = 0; v < MAXUTYPES; ++v)
  292.  
  293. #define for_all_possible_material_types(v)  for (v = 0; v < MAXMTYPES; ++v)
  294.  
  295. #define for_all_possible_terrain_types(v)   for (v = 0; v < MAXTTYPES; ++v)
  296.  
  297. /* Macros encapsulating things about units. */
  298.  
  299. #define checku(x) if ((x) < 0 || (x) >= numutypes) utype_error(x);
  300.  
  301. #define checkm(x) if ((x) < 0 || (x) >= nummtypes) mtype_error(x);
  302.  
  303. #define checkt(x) if ((x) < 0 || (x) >= numttypes) ttype_error(x);
  304.  
  305. /* Fix eventually. */
  306.  
  307. /* (should say u_... or ..._type ?) */
  308.  
  309. #define actor(u) (u_acp(u) > 0)
  310.  
  311. #define mobile(u) (u_speed(u) > 0)
  312.  
  313. #define u_hp(u) (u_hp_max(u))
  314.  
  315. #define could_be_on(u,t)  \
  316.   ((ut_capacity_x(u, t) > 0 || ut_size(u, t) <= t_capacity(t)))
  317.  
  318. #define could_live_on(u,t)  \
  319.    (could_be_on(u, t) && !ut_vanishes_on(u, t) && !ut_wrecks_on(u, t))
  320.  
  321. #define could_carry(u1,u2)  \
  322.   (uu_capacity_x(u1, u2) > 0 || uu_size(u2, u1) <= u_capacity(u1))
  323.  
  324. #define could_create(u1,u2) (uu_acp_to_create(u1, u2) > 0)
  325.  
  326. #define could_repair(u1, u2) (uu_repair(u1, u2) > 0)
  327.  
  328. #define could_hit(u1,u2) (uu_hit(u1, u2) > 0 || uu_fire_hit(u1, u2) > 0)
  329.  
  330. /* These need actual units rather than types. */
  331.  
  332. #define impassable(u, x, y) (!could_be_on((u)->type, terrain_at((x), (y))))
  333.  
  334. #define isbase(u) (u_is_base((u)->type))
  335.  
  336. #define base_builder(u) (u_is_base_builder((u)->type))
  337.  
  338. #define istransport(u) (u_is_transport((u)->type))
  339.  
  340. #define t_is_cell(t) (t_subtype(t) == cellsubtype)
  341.  
  342. #define t_is_border(t) (t_subtype(t) == bordersubtype)
  343.  
  344. #define t_is_connection(t) (t_subtype(t) == connectionsubtype)
  345.  
  346. #define t_is_coating(t) (t_subtype(t) == coatingsubtype)
  347.  
  348. #define is_unit_type(u) ((u) >= 0 && (u) < numutypes)
  349.  
  350. #define is_material_type(m) ((m) >= 0 && (m) < nummtypes)
  351.  
  352. #define is_terrain_type(t) ((t) >= 0 && (t) < numttypes)
  353.  
  354. extern short canaddutype;
  355. extern short canaddmtype;
  356. extern short canaddttype;
  357.  
  358. extern short tmputype;
  359. extern short tmpmtype;
  360. extern short tmpttype;
  361.  
  362. extern void utype_error  PARAMS ((int u));
  363. extern void mtype_error  PARAMS ((int m));
  364. extern void ttype_error  PARAMS ((int t));
  365. extern void init_types PARAMS ((void));
  366. extern void init_globals PARAMS ((void));
  367. extern void default_unit_type PARAMS ((int x));
  368. extern void default_material_type PARAMS ((int x));
  369. extern void default_terrain_type PARAMS ((int x));
  370. extern char *index_type_name();
  371. extern void allocate_table PARAMS ((int tbl, int reset));
  372. extern int numtypes_from_index_type PARAMS ((int x));
  373. extern char *index_type_name PARAMS ((int x));
  374.  
  375. extern void set_g_synth_methods_default PARAMS ((void));
  376. extern void set_g_side_lib_default PARAMS ((void));
  377. extern Obj *get_u_extension PARAMS ((int u, char *name, Obj *dflt));
  378. extern Obj *get_m_extension PARAMS ((int m, char *name, Obj *dflt));
  379. extern Obj *get_t_extension PARAMS ((int t, char *name, Obj *dflt));
  380.