Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

game.h

Go to the documentation of this file.
00001 /* Interface between game parameters and the rest of Xconq.
00002    Copyright (C) 1992-1996, 1998-2000 Stanley T. Shebs.
00003 
00004 Xconq is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2, or (at your option)
00007 any later version.  See the file COPYING.  */
00008 
00016 /* Numbers guaranteed to be invalid types in each category.  Should be
00017  * careful that these don't overflow anything.
00018  */
00019 
00023 #define NONUTYPE (-1)
00024 
00027 #define NONMTYPE (-1)
00028 
00032 #define NONTTYPE (-1)
00033 
00038 #define BACKTTYPE (-2)                                  
00039 
00043 #define NONATYPE (-1)
00044 
00048 #define DONE (-2)
00049 
00054 #define NOADVANCE (-3)
00055 
00059 typedef enum {
00060   UTYP = 0, 
00061   MTYP = 1, 
00062   TTYP = 2, 
00063   ATYP = 3  
00064 } Typetype;
00065 
00069 enum terrain_subtype {
00070     cellsubtype = 0,       
00071     bordersubtype = 1,     
00072     connectionsubtype = 2, 
00073     coatingsubtype = 3     
00074 };
00075 
00076 /* Ultimate limits on values in properties. */
00077 
00079 #define PROPLO -32768
00080 
00081 #define PROPHI 32767
00082 
00083 /* Ultimate limits on values in tables. */
00084 
00086 #define TABLO -32768
00087 
00088 #define TABHI 32767
00089 
00091 #define TABINT      0
00092 
00093 #define TABDICE1    1
00094 
00095 #define TABDICE2    2
00096 
00097 /* Ultimate limits on values of globals. */
00098 
00100 #define VARLO -2000000000
00101 
00102 #define VARHI 2000000000
00103 
00104 #include "lisp.h"
00105 
00111 typedef struct propertydefn {
00112     char *name;                                 
00113     int (*intgetter)(int);                      
00114     char *(*strgetter)(int);            
00115     Obj *(*objgetter)(int);             
00116     short offset;                               
00117     char *doc;                                  
00118     short dflt;                                 
00119     char *dfltstr;                              
00120     short lo;                                           
00121     short hi;                                   
00122 } PropertyDefn;
00123 
00128 typedef struct tabledefn {
00129     char *name;                                 
00130     int (*getter)(int, int);            
00131     char *doc;                                  
00132     short **table;                              
00133     short dflt;                                 
00134     short lo;                                           
00135     short hi;                                   
00136     char index1;                                
00137     char index2;                                
00138     char valtype;                               
00139 } TableDefn;
00140 
00146 typedef struct vardefn {
00147     char *name;                                 
00148     int   (*intgetter)(void);           
00149     char *(*strgetter)(void);           
00150     Obj  *(*objgetter)(void);           
00151     void (*intsetter)(int);             
00152     void (*strsetter)(char *);          
00153     void (*objsetter)(Obj *);           
00154     char *doc;                                  
00155     int dflt;                                           
00156     char *dfltstr;                              
00157     Obj *(*dfltfn)(void);                       /*<! function to return default value if object type */
00158     int lo;                                             
00159     int hi;                                             
00160 } VarDefn;
00161 
00163 extern short numutypes;
00165 extern short nummtypes;
00167 extern short numttypes;
00169 extern short numatypes;
00170 
00171 #undef  DEF_UPROP_I
00172 #define DEF_UPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
00173     short SLOT; 
00174 #undef  DEF_UPROP_S
00175 #define DEF_UPROP_S(name,fname,doc,SLOT,dflt)  \
00176     char *SLOT; 
00177 #undef  DEF_UPROP_L
00178 #define DEF_UPROP_L(name,fname,doc,SLOT)  \
00179     Obj *SLOT;  
00189 typedef struct utype {
00190 
00191 #include "utype.def"
00192 
00193 } Utype;
00194 
00195 #undef  DEF_MPROP_I
00196 #define DEF_MPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
00197     short SLOT;
00198 #undef  DEF_MPROP_S
00199 #define DEF_MPROP_S(name,fname,doc,SLOT,dflt)  \
00200     char *SLOT;
00201 #undef  DEF_MPROP_L
00202 #define DEF_MPROP_L(name,fname,doc,SLOT)  \
00203     Obj *SLOT;
00204 
00209 typedef struct mtype {
00210 
00211 #include "mtype.def"
00212 
00213 } Mtype;
00214 
00215 
00216 #undef  DEF_TPROP_I
00217 #define DEF_TPROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
00218     short SLOT;
00219 #undef  DEF_TPROP_S
00220 #define DEF_TPROP_S(name,fname,doc,SLOT,dflt)  \
00221     char *SLOT;
00222 #undef  DEF_TPROP_L
00223 #define DEF_TPROP_L(name,fname,doc,SLOT)  \
00224     Obj *SLOT;
00225 
00230 typedef struct ttype {
00231 
00232 #include "ttype.def"
00233 
00234 } Ttype;
00235 
00236 #undef  DEF_APROP_I
00237 #define DEF_APROP_I(name,fname,doc,SLOT,lo,dflt,hi)  \
00238     short SLOT;
00239 #undef  DEF_APROP_S
00240 #define DEF_APROP_S(name,fname,doc,SLOT,dflt)  \
00241     char *SLOT;
00242 #undef  DEF_APROP_L
00243 #define DEF_APROP_L(name,fname,doc,SLOT)  \
00244     Obj *SLOT;
00245 
00250 typedef struct atype {
00251 
00252 #include "atype.def"
00253 
00254 } Atype;
00255 
00256 #undef  DEF_VAR_I
00257 #define DEF_VAR_I(name,fname,setfname,doc,VAR,lo,dflt,hi)  \
00258     int VAR;
00259 #undef  DEF_VAR_S
00260 #define DEF_VAR_S(name,fname,setfname,doc,VAR,dflt)  \
00261     char *VAR;
00262 #undef  DEF_VAR_L
00263 #define DEF_VAR_L(name,fname,setfname,doc,VAR,dflt)  \
00264     Obj *VAR;
00265 
00269 typedef struct a_globals {
00270 
00271 #include "gvar.def"
00272 
00273 } Globals;
00274 
00275 /* Declarations of the functions accessing and setting type properties. */
00276 
00277 #undef  DEF_UPROP_I
00278 #define DEF_UPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME(int u);
00279 #undef  DEF_UPROP_S
00280 #define DEF_UPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME(int u);
00281 #undef  DEF_UPROP_L
00282 #define DEF_UPROP_L(name,FNAME,doc,slot)  Obj *FNAME(int u);
00283 
00284 #include "utype.def"
00285 
00286 #undef  DEF_MPROP_I
00287 #define DEF_MPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME(int m);
00288 #undef  DEF_MPROP_S
00289 #define DEF_MPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME(int m);
00290 #undef  DEF_MPROP_L
00291 #define DEF_MPROP_L(name,FNAME,doc,slot)  Obj *FNAME(int m);
00292 
00293 #include "mtype.def"
00294 
00295 #undef  DEF_TPROP_I
00296 #define DEF_TPROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME(int t);
00297 #undef  DEF_TPROP_S
00298 #define DEF_TPROP_S(name,FNAME,doc,slot,dflt)  char *FNAME(int t);
00299 #undef  DEF_TPROP_L
00300 #define DEF_TPROP_L(name,FNAME,doc,slot)  Obj *FNAME(int t);
00301 
00302 #include "ttype.def"
00303 
00304 #undef  DEF_APROP_I
00305 #define DEF_APROP_I(name,FNAME,doc,slot,lo,dflt,hi)  int FNAME(int a);
00306 #undef  DEF_APROP_S
00307 #define DEF_APROP_S(name,FNAME,doc,slot,dflt)  char *FNAME(int a);
00308 #undef  DEF_APROP_L
00309 #define DEF_APROP_L(name,FNAME,doc,slot)  Obj *FNAME(int a);
00310 
00311 #include "atype.def"
00312 
00313 #undef  DEF_VAR_I
00314 #define DEF_VAR_I(str,FNAME,SETFNAME,doc,var,lo,dflt,hi)  \
00315   int FNAME(void); 
00316 #undef  DEF_VAR_S
00317 #define DEF_VAR_S(str,FNAME,SETFNAME,doc,var,dflt)  \
00318   char *FNAME(void);
00319 #undef  DEF_VAR_L
00320 #define DEF_VAR_L(str,FNAME,SETFNAME,doc,var,dflt)  \
00321   Obj *FNAME(void);
00322 
00323 #include "gvar.def"
00324 
00325 #undef  DEF_VAR_I
00326 #define DEF_VAR_I(str,FNAME,SETFNAME,doc,var,lo,dflt,hi)  \
00327   void SETFNAME(int val);
00328 #undef  DEF_VAR_S
00329 #define DEF_VAR_S(str,FNAME,SETFNAME,doc,var,dflt)  \
00330   void SETFNAME(char *val);
00331 #undef  DEF_VAR_L
00332 #define DEF_VAR_L(str,FNAME,SETFNAME,doc,var,dflt)  \
00333   void SETFNAME(Obj *val);
00334 
00335 #include "gvar.def"
00336 
00337 /* Declarations of table accessor functions and the globals
00338    for constant and filled-in tables. */
00339 
00340 #undef  DEF_UU_TABLE
00341 #define DEF_UU_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00342   int FNAME(int u1, int u2);
00343 
00344 #undef  DEF_UM_TABLE
00345 #define DEF_UM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00346   int FNAME(int u, int m);
00347 
00348 #undef  DEF_UT_TABLE
00349 #define DEF_UT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00350   int FNAME(int u, int t);
00351 
00352 #undef  DEF_TM_TABLE
00353 #define DEF_TM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00354   int FNAME(int t, int m);
00355 
00356 #undef  DEF_TT_TABLE
00357 #define DEF_TT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00358   int FNAME(int t1, int t2);
00359 
00360 #undef  DEF_MM_TABLE
00361 #define DEF_MM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00362   int FNAME(int m1, int m2);
00363 
00364 #undef  DEF_UA_TABLE
00365 #define DEF_UA_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00366   int FNAME(int u, int a);  
00367 
00368 #undef  DEF_AM_TABLE
00369 #define DEF_AM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00370   int FNAME(int a, int m);  
00371 
00372 #undef  DEF_AA_TABLE
00373 #define DEF_AA_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00374   int FNAME(int a1, int a2);  
00375 
00376 #include "table.def"
00377 
00378 #undef  DEF_UU_TABLE
00379 #define DEF_UU_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00380   extern short *TABLE, CNST;
00381 
00382 #undef  DEF_UM_TABLE
00383 #define DEF_UM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00384   extern short *TABLE, CNST;
00385 
00386 #undef  DEF_UT_TABLE
00387 #define DEF_UT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00388   extern short *TABLE, CNST;
00389 
00390 #undef  DEF_TM_TABLE
00391 #define DEF_TM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00392   extern short *TABLE, CNST;
00393 
00394 #undef  DEF_TT_TABLE
00395 #define DEF_TT_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00396   extern short *TABLE, CNST;
00397 
00398 #undef  DEF_MM_TABLE
00399 #define DEF_MM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00400   extern short *TABLE, CNST;
00401 
00402 #undef  DEF_UA_TABLE
00403 #define DEF_UA_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00404   extern short *TABLE, CNST;
00405 
00406 #undef  DEF_AM_TABLE
00407 #define DEF_AM_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00408   extern short *TABLE, CNST;
00409 
00410 #undef  DEF_AA_TABLE
00411 #define DEF_AA_TABLE(name,FNAME,doc,TABLE,CNST,lo,dflt,hi,valtype)  \
00412   extern short *TABLE, CNST;
00413 
00414 #include "table.def"
00415 
00416 /* Declarations of the globals description structures. */
00417 
00419 extern Globals globals;
00420 
00422 extern Utype *utypes;
00423 
00425 extern Mtype *mtypes;
00426 
00428 extern Ttype *ttypes;
00429 
00431 extern Atype *atypes;
00432 
00434 extern PropertyDefn utypedefns[];
00435 
00437 extern PropertyDefn mtypedefns[];
00438 
00440 extern PropertyDefn ttypedefns[];
00441 
00443 extern PropertyDefn atypedefns[];
00444 
00446 extern TableDefn tabledefns[];
00447 
00449 extern VarDefn vardefns[];
00450 
00451 /* Macros for iterating over types. */
00452 
00458 #define for_all_unit_types(v)      for (v = 0; v < numutypes; ++v)
00459 
00465 #define for_all_material_types(v)  for (v = 0; v < nummtypes; ++v)
00466 
00472 #define for_all_terrain_types(v)   for (v = 0; v < numttypes; ++v)
00473 
00479 #define for_all_advance_types(v)   for (v = 0; v < numatypes; ++v)
00480 
00487 #define for_all_aux_terrain_types(t)    \
00488   for ((t) = first_auxt_type; (t) >= 0; (t) = next_auxt_type[(t)])
00489 
00496 #define for_all_border_types(t)  \
00497   for ((t) = first_bord_type; (t) >= 0; (t) = next_bord_type[(t)])
00498 
00505 #define for_all_connection_types(t)  \
00506   for ((t) = first_conn_type; (t) >= 0; (t) = next_conn_type[(t)])
00507 
00508 /* Macros encapsulating things about units. */
00509 
00516 #define checku(x) if ((x) < 0 || (x) >= numutypes) utype_error(x);
00517 
00524 #define checkm(x) if ((x) < 0 || (x) >= nummtypes) mtype_error(x);
00525 
00532 #define checkt(x) if ((x) < 0 || (x) >= numttypes) ttype_error(x);
00533 
00540 #define checka(x) if ((x) < 0 || (x) >= numatypes) atype_error(x);
00541 
00542 /* Fix eventually. */
00543 
00544 /* (should say u_... or ..._type ?) */
00545 
00556 #define actor(u) (u_acp(u) > 0)
00557 
00568 #define mobile(u) (u_speed(u) > 0)
00569 
00571 
00575 #define u_mobile(u) (0 < mp_per_turn_max(u))
00576 
00584 #define u_hp(u) (u_hp_max(u))
00585 
00587 extern int could_be_on(int u, int t);
00588 
00602 #define could_live_on(u,t)  \
00603    (could_be_on(u, t) && !ut_vanishes_on(u, t) && !ut_wrecks_on(u, t))
00604 
00618 #define could_carry(u1,u2)  \
00619   (uu_capacity_x(u1, u2) > 0 || uu_size(u2, u1) <= u_capacity(u1))
00620 
00631 #define could_develop(u1,u2) (uu_acp_to_develop(u1, u2) > 0)
00632 
00633 /* These need actual units rather than types. */
00634 
00646 #define impassable(u, x, y) (!could_be_on((u)->type, terrain_at((x), (y))))
00647 
00657 #define isbase(u) (u_is_base((u)->type))
00658 
00668 #define base_builder(u) (u_is_base_builder((u)->type))
00669 
00679 #define istransport(u) (u_is_transport((u)->type))
00680 
00690 #define t_is_cell(t) (t_subtype(t) == cellsubtype)
00691 
00701 #define t_is_border(t) (t_subtype(t) == bordersubtype)
00702 
00712 #define t_is_connection(t) (t_subtype(t) == connectionsubtype)
00713 
00723 #define t_is_coating(t) (t_subtype(t) == coatingsubtype)
00724 
00735 #define is_unit_type(u) ((u) >= 0 && (u) < numutypes)
00736 
00747 #define is_material_type(m) ((m) >= 0 && (m) < nummtypes)
00748 
00759 #define is_terrain_type(t) ((t) >= 0 && (t) < numttypes)
00760 
00771 #define is_advance_type(a) ((a) >= 0 && (a) < numatypes)
00772 
00774 extern short canaddutype;
00776 extern short canaddmtype;
00778 extern short canaddttype;
00780 extern short canaddatype;
00781 
00783 extern short tmputype;
00785 extern short tmpmtype;
00787 extern short tmpttype;
00789 extern short tmpatype;
00790 
00792 extern int numcelltypes;
00794 extern int numbordtypes;
00796 extern int numconntypes;
00798 extern int numcoattypes;
00799 
00801 extern short first_auxt_type;
00803 extern short *next_auxt_type;
00805 extern short first_bord_type;
00807 extern short *next_bord_type;
00809 extern short first_conn_type;
00811 extern short *next_conn_type;
00812 
00814 extern int *tmp_u_array;
00816 extern int *tmp_u2_array;
00818 extern int *tmp_t_array;
00820 extern int *tmp_m_array;
00822 extern int *tmp_a_array;
00823 
00825 extern int **tmp_uu_array;
00826 
00827 extern void utype_error(int u);
00828 extern void mtype_error(int m);
00829 extern void ttype_error(int t);
00830 extern void atype_error(int s);
00831 
00832 extern void init_types(void);
00833 extern void init_globals(void);
00834 extern int create_unit_type(void);
00835 extern int create_material_type(void);
00836 extern int create_terrain_type(void);
00837 extern int create_advance_type(void);
00838 extern void default_unit_type(int x);
00839 extern void default_material_type(int x);
00840 extern void default_terrain_type(int x);
00841 extern void default_advance_type(int x);
00842 
00843 extern void allocate_table(int tbl, int reset);
00844 extern int numtypes_from_index_type(int x);
00845 extern char *index_type_name(int x);
00846 
00847 extern void disallow_more_unit_types(void);
00848 extern void disallow_more_terrain_types(void);
00849 extern void disallow_more_material_types(void);
00850 extern void disallow_more_advance_types(void);
00851 extern void count_terrain_subtypes(void);
00852 
00853 /* Accessors for table, property, and global defaults. */
00854 
00856 extern int table_default(int (*getter)(int, int));
00858 extern short uprop_i_default(int (*intgetter)(int));
00860 extern char *uprop_s_default(char *(*strgetter)(int));
00862 extern Obj *uprop_l_default(Obj *(*objgetter)(int));
00864 extern short tprop_i_default(int (*intgetter)(int));
00866 extern char *tprop_s_default(char *(*strgetter)(int));
00868 extern Obj *tprop_l_default(Obj *(*objgetter)(int));
00870 extern short mprop_i_default(int (*intgetter)(int));
00872 extern char *mprop_s_default(char *(*strgetter)(int));
00874 extern Obj *mprop_l_default(Obj *(*objgetter)(int));
00876 extern short aprop_i_default(int (*intgetter)(int));
00878 extern char *aprop_s_default(char *(*strgetter)(int));
00880 extern Obj *aprop_l_default(Obj *(*objgetter)(int));
00882 extern int gvar_i_default(int (*intgetter)(void));
00884 extern char *gvar_s_default(char *(*strgetter)(void));
00886 extern Obj *gvar_l_default(Obj *(*objgetter)(void));
00887 
00888 extern Obj * g_synth_methods_default(void);

Generated on Sat Sep 17 10:28:52 2005 for XconqKernel by doxygen 1.3.6