home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume4 / xconq5 / part15 / unit.h < prev    next >
C/C++ Source or Header  |  1988-07-01  |  6KB  |  162 lines

  1. /* Copyright (c) 1987, 1988  Stanley T. Shebs, University of Utah. */
  2. /* This program may be used, copied, modified, and redistributed freely */
  3. /* for noncommercial purposes, so long as this notice remains intact. */
  4.  
  5. /* RCS $Header: unit.h,v 1.1 88/06/21 12:29:48 shebs Exp $ */
  6.  
  7. /* Definitions about units and their orders. */
  8.  
  9. #define NOTHING (MAXUTYPES+1)  /* A number guaranteed to be a non-unit. */
  10.  
  11. /* Unit order types.  Each type has a letter, name, short name, and some */
  12. /* parameter types that guide how the order will be input. */
  13.  
  14. #define NUMORDERTYPES 8
  15.  
  16. #define NONE     0
  17. #define AWAKE    1
  18. #define SENTRY   2
  19. #define MOVEDIR  3
  20. #define MOVETO   4
  21. #define EDGE     5
  22. #define FOLLOW   6
  23. #define PATROL   7
  24.  
  25. #define ORDERNAMES \
  26.   { "None", "Awake", "Sentry", "Dir Move", "Move to", \
  27.     "Follow Edge", "Follow Leader", "Patrol" }
  28.  
  29. /* Types of arguments that orders can have. */
  30.  
  31. #define NOARG     0
  32. #define DIR       1
  33. #define POS       2
  34. #define LEADER    3
  35. #define WAYPOINTS 4
  36.  
  37. #define ORDERARGS \
  38.   { NOARG, NOARG, NOARG, DIR, POS, DIR, LEADER, WAYPOINTS }
  39.  
  40. #define ORDERARGNAMES \
  41.   { "no args", "no args", "no args", "direction", \
  42.     "destination", "direction", "unit", "waypoints" }
  43.  
  44. /* Number of points possible in order parameters.  If actual number not */
  45. /* implicit in order type, then will need a count field somewhere. */
  46.  
  47. #define NUMWPS 2
  48.  
  49. /* Bit-encoded flags that specify's units behavior when under orders. */
  50.  
  51. #define ENEMYWAKE     0x01
  52. #define NEUTRALWAKE   0x02
  53. #define SUPPLYWAKE    0x04
  54. #define ATTACKUNIT    0x08
  55. #define SHORTESTPATH  0x10
  56.  
  57. #define ALLFLAGS      0x1f
  58.  
  59. #define NORMAL  ALLFLAGS
  60.  
  61. /* tiny hack structure */
  62.  
  63. typedef struct a_pt {
  64.     short x, y;
  65. } Pt;
  66.  
  67. /* Definition of an "order", which is the means by which a unit keeps */
  68. /* track of what it should do.  Needs the encapsulation because orders */
  69. /* show up in both units and in collections of standing orders. */
  70.  
  71. typedef struct a_order {
  72.     short type;               /* type of order (awake, random, etc) */
  73.     short rept;               /* number to repeat order */
  74.     short flags;              /* bit vector of special flags */
  75.     union {
  76.     short dir;            /* a direction */
  77.     struct a_unit *leader;  /* pointer to a leader unit */
  78.     Pt pt[NUMWPS];        /* small array of coordinates */
  79.     } p;                      /* parameters of an order */
  80. } Order;
  81.  
  82. /* A standing order is actually an array with an order for each unit type. */
  83. /* The structure is allocated only when a standing order is given. */
  84.  
  85. typedef struct s_order {
  86.     Order *orders[MAXUTYPES];
  87. } StandingOrder;
  88.  
  89. /* This structure should be small, because there may be many of them. */
  90. /* On the other hand, changing shorts to chars would entail fiddling with */
  91. /* mapfile code, so beware. */
  92.  
  93. typedef struct a_unit {
  94.     /* Level 1 detail */
  95.     short type;                /* type (army, ship, etc) */
  96.     char *name;                /* the name, if given */
  97.     short x, y;                /* position of unit on map */
  98.     struct a_side *side;       /* whose side this unit is on */
  99.     /* Level 2 detail */
  100.     short id;                  /* truly unique id number */
  101.     short number;              /* semi-unique id number */
  102.     struct a_side *trueside;   /* whose side this unit is really on */
  103.     short hp;                  /* how much more damage it can take */
  104.     short quality;             /* "veteran-ness" */
  105.     short morale;              /* how happy our guys are */
  106.     short fatigue;             /* how tired they are */
  107.     short product;             /* type of unit this unit is producing */
  108.     short schedule;            /* when the unit will be done */
  109.     short built;               /* how many units of current type made so far */
  110.     struct a_unit *transport;  /* pointer to transporter if any */
  111.     short supply[MAXRTYPES];   /* how much supply we're carrying */
  112.     /* Level 3 detail */
  113.     short group;               /* group to which unit belongs (machine) */
  114.     short goal;                /* personal goal of unit */
  115.     short gx, gy;              /* current goal position */
  116.     short movesleft;           /* how many moves left in this turn */
  117.     short actualmoves;         /* hexes actually covered this turn */
  118.     short lastdir;             /* last direction of move */
  119.     short awake;               /* true if unit temporarily awake */
  120.     Order orders;              /* current orders being carried out */
  121.     StandingOrder *standing;   /* pointer to collection of standing orders */
  122.     /* Never saved */
  123.     struct a_unit *occupant;   /* pointer to first unit being carried */
  124.     struct a_unit *nexthere;   /* pointer to fellow occupant */
  125.     struct a_unit *next;       /* next unit in list of all units */
  126. } Unit;
  127.  
  128. /* Some convenient macros. */
  129.  
  130. #define for_all_units(v) for (v = unitlist; v != NULL; v = v->next)
  131.  
  132. #define for_all_occupants(u1,u2) \
  133.   for (u2 = u1->occupant; u2 != NULL; u2 = u2->nexthere)
  134.  
  135. #define alive(u) ((u)->hp > 0)
  136.  
  137. #define cripple(u) ((u)->hp < utypes[(u)->type].crippled)
  138.  
  139. #define neutral(u) ((u)->side == NULL)
  140.  
  141. #define producing(u) ((u)->product != NOTHING)
  142.  
  143. #define busy(u) (producing(u) || (u)->schedule > 0)
  144.  
  145. #define idled(u) (utypes[(u)->type].maker && !busy(u))
  146.  
  147. #define mobile(u) (utypes[u].speed > 0)
  148.  
  149. #define could_occupy(u,t) (could_move(u,t))
  150.  
  151. /* Unit variables. */
  152.  
  153. extern Unit *unitlist, *tmpunit;
  154. extern Unit *create_unit(), *read_basic_unit(), *random_start_unit();
  155. extern Unit *find_unit();
  156.  
  157. extern int numunits, orderargs[];
  158.  
  159. extern char *ordernames[];
  160. extern char *random_unit_name(), *unit_handle(), *short_unit_handle();
  161. extern char *make_unit_name(), *order_desig();
  162.