home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xconq55.zip / xc5.5 / side.h < prev    next >
C/C++ Source or Header  |  1992-02-15  |  13KB  |  299 lines

  1. /* Copyright (c) 1987, 1988  Stanley T. Shebs. */
  2. /* This program may be used, copied, modified, and redistributed freely */
  3. /* for noncommercial purposes, so long as this notice remains intact. */
  4.  
  5. /* Definitions about sides need terrain.h, unit.h, map.h */
  6.  
  7. /* Modes governing the interpretation of input. */
  8.  
  9. #define WEDGED    0
  10. #define MOVE      1
  11. #define SURVEY    2
  12.  
  13. /* These are 7-char strings (except for the first) so hiliting works right. */
  14.  
  15. #define MODENAMES { "       ", "  Move ", " Survey" }
  16.  
  17. /* Reasons for gains and losses of units. */
  18.  
  19. #define NUMREASONS 14
  20.  
  21. #define FIRSTUNIT   0
  22. #define PRODUCED    1
  23. #define CAPTURE     2
  24. #define DUMMYREAS   3
  25. #define COMBAT      4
  26. #define PRISONER    5
  27. #define GARRISON    6
  28. #define DISASTER    7
  29. #define STARVATION  8
  30. #define DISBAND     9
  31. #define SURRENDER  10
  32. #define VICTOR     11
  33. #define ENDOFWORLD 12
  34. #define GIFT       13
  35.  
  36. #define REASONNAMES \
  37.   { "Ini", "Pro", "Cap", "   ", "Cbt", "Pri", "Gar", "Acc", "Sup", "Dis", \
  38.     "Sur", "Win", "End", "Gift" }
  39.  
  40. /* Input request results - tells what came back as answer to a request. */
  41.  
  42. #define GARBAGE  0
  43. #define KEYBOARD 1
  44. #define MAPPOS   2
  45. #define UNITTYPE 3
  46. #define SCROLLUP 4
  47. #define SCROLLDOWN 5
  48.  
  49. /* Color display modes. */
  50.  
  51. #define NUMSHOWMODES 4
  52.  
  53. #define FULLHEX   0
  54. #define BORDERHEX 1
  55. #define TERRICONS 2
  56. #define BOTHICONS 3
  57.  
  58. /* Attitude boundaries of one side with respect to another. */
  59.  
  60. #define ENEMY   (-100)
  61. #define NEUTRAL     0
  62. #define ALLY      100
  63.  
  64. /* Possible ideologies of a machine player - determines general behavior. */
  65. /* Very crude - really more for color than anything else. */
  66.  
  67. #define EXPANSIONIST 0
  68. #define ISOLATIONIST 1
  69. #define FASCIST      2
  70. #define FANATICAL    3
  71. #define DEMOCRATIC   4
  72.  
  73. /* An area of control is a block that is treated as a single */
  74. /* location. All information on the whole area is combined so that the */
  75. /* machine can do some planning.  */
  76.  
  77. typedef struct a_control_area {
  78.   short enemy_strength;   /* Estimate of enemy unit strength */
  79.   short enemy_seen_recently; /* How many enemy have we seen in last */
  80.                  /* turn. */
  81.   short units_lost;       /* How many units have we lost here. */
  82.               /* Weighted average of last few turns. */
  83.   short capturers_approaching; /* number of units comming to capture bases */
  84.   short capture_time;     /* When do we expect to have capturers here */
  85.   short safe_area;        /* do we really need to move units here */
  86. } Control_area;
  87.                  
  88. typedef unsigned short viewdata;
  89.  
  90. /* Each xconq player is a "side" - more or less one country.  A side may or */
  91. /* may not be played by a person, and may or may not have a display attached */
  92. /* to it.  Each side has a different view of the world.  Zillions of slots */
  93. /* are needed because each side needs to keep its own interaction/display */
  94. /* data - a side is almost like a full-blown process... */
  95.  
  96. typedef struct a_side {
  97.     /* Level 1 detail */
  98.     char *name;               /* name used for display */
  99.     /* Level 2 detail */
  100.     short ideology;           /* what kind of people are on this side */
  101.     short attitude[MAXSIDES];   /* war/peace/ally status of other sides */
  102.     short counts[MAXUTYPES];  /* array of numbers for identifying units */
  103.     /* Level 3 detail */
  104.     viewdata *view;      /* pointer to array of view info */
  105. #ifdef LARGE
  106.     short *viewtimestamp;     /* indicates when we last looked at this hex */
  107.     viewdata *prevview;  /* what we saw before what we see now. */
  108. #endif
  109.     /* Level 4 detail */
  110.     char *host;               /* which host is this side attached to */
  111.     short humanp;             /* is this side played by a person? */
  112.     short lost;               /* true if this side was knocked out */
  113.     short cx, cy;             /* current center of player's focus */
  114.     struct a_unit *markunit;  /* unit being remembered for later use */
  115.     short timeleft;           /* seconds left for this side to play */
  116.     short timetaken;          /* seconds played by this side */
  117.     short timedout;           /* true when clock has run out for this side */
  118.     short itertime;           /* length of order repetition */
  119.     short graphical;          /* if true, use bar graphs for unit info */
  120.     short bonw;               /* true if display is black-on-white */
  121.     short showmode;           /* one of four color display modes */
  122.     /* Statistics */
  123.     short balance[MAXUTYPES][NUMREASONS];  /* what happened to units */
  124.     short atkstats[MAXUTYPES][MAXUTYPES];  /* how many attacks */
  125.     short hitstats[MAXUTYPES][MAXUTYPES];  /* how many hits */
  126.     /* Never saved */
  127.     struct a_unit *unithead;  /* all units on the side */
  128.     short mode;               /* player's mode (move/survey) */
  129.     short curx, cury;         /* current spot being looked at */
  130.     struct a_unit *curunit;   /* unit under cursor */
  131.     struct a_unit *movunit;   /* unit being moved currently */
  132.     struct a_unit *last_unit; /* last unit moved */
  133.     short more_units;        /* TRUE if more units to more this turn */
  134.     short directorder;        /* true if order has just been given */
  135.     short *coverage;          /* indicates how many looking at this hex */
  136.     short units[MAXUTYPES];   /* cached count of units */
  137.     short resources[MAXRTYPES];  /* cached count of resources */
  138.     short building[MAXUTYPES];  /* cached count of units being built */
  139.     long lasttime;            /* when clock started counting down again */
  140.     short followaction;       /* move to where a change has occured */
  141.     /* machine player */
  142.     long plan;                /* all the machine's strategy and tactics */
  143.     struct a_unit *unitlist[MAXUTYPES];   /* lists to help mplay efficiency */
  144.     short unitlistcount[MAXUTYPES];  /* counts of above lists */
  145.     int numunits;             /* number of units the side has */
  146.     /* Higher level control information for machine */
  147.     Control_area *areas;
  148.     /* input hacking */
  149.     bool reqactive;           /* true if request made but yet unfulfilled */
  150.     int (*reqhandler)();      /* function to call to process fulfilled req */
  151.     int reqtype;              /* what sort of response was made to req */
  152.     char reqch;               /* keyboard char */
  153.     int reqx, reqy;           /* map coordinates */
  154.     int requtype;             /* unit type number */
  155.     /* Random input data slots - could be merged/simplified? */
  156.     struct a_side *reqoside;
  157.     struct a_unit *requnit;
  158.     struct a_unit *tmpcurunit;  /* saved value of curunit */
  159.     int reqvalue, reqvalue2;
  160.     int reqstrbeg, reqcurstr;  /* data about string under construction */
  161.     char *reqdeflt;           /* A default string */
  162.     int tmpcurx, tmpcury;     /* saved values of curx,cury */
  163.     int reqposx, reqposy;     /* accumulator for position reading */
  164.     char ustr[MAXUTYPES];     /* used in composing unit type hints */
  165.     int uvec[MAXUTYPES];      /* vector of allowed unit types to input */
  166.     int bvec[MAXUTYPES];      /* bit vector of allowed unit types to input */
  167.     /* Machinery for standing orders */
  168.     bool teach;               /* true when only setting a standing order */
  169.     struct a_unit *sounit;    /* unit that stores standing order for occs */
  170.     int soutype;              /* unit type that will get standing orders */
  171.     struct a_order *tmporder; /* holding place for orders */
  172.     /* Constructed during display init */
  173.     short monochrome;         /* obvious */
  174.     short nw, nh;             /* length and number of notice lines */
  175.     short vw, vh;             /* viewport width and height in hexes */
  176.     short vw2, vh2;           /* 1/2 (rounded down) of above values */
  177.     short vw_odd;             /* 1 if vw is odd */
  178.     short sw;                 /* number of chars in side listing */
  179.     short fw, fh;             /* dimensions of text font (in pixels) */
  180.     short hfw, hfh;           /* dimensions of help text font (in pixels) */
  181.     short hw, hh;             /* dimensions of general icon font (in pixels) */
  182.     short hch;                /* center-to-center distance between hexes */
  183.     short uw, uh;             /* dimensions of unit font/bitmaps (in pixels) */
  184.     short mm;                 /* magnification of world hexes (in pixels) */
  185.     short bd, margin;         /* spacing around things */
  186.     short tlh, blh, trh, brh; /* heights of top and bottom parts of display */
  187.     short rw, lw;             /* widths of right and left parts of display */
  188.     short mw, mh;             /* main window width and height */
  189.     /* Working variables for the display */
  190.     short vcx, vcy;           /* center hex in the viewport */
  191.     short lastvcx, lastvcy;   /* last center hex (-1,-1 initially) */
  192.     short lastx, lasty;       /* last current x and y (-1,-1 initially) */
  193.     char *noticebuf[MAXNOTES];  /* data for the notice area */
  194.     char promptbuf[BUFSIZE];  /* current prompt + input str on display */
  195.     short bottom_note;       /* bottom note being displayed. */
  196.     short reqchange;          /* something has changed requiring us to update
  197.                  our cursor. */
  198.     short redisplay_ok;       /* Process redisplay events */
  199.     /* Keep track of units that have died.  Flush them at the end of the */
  200.     /* players turn.  Player is reponsible for keeping track of units he kills. */
  201.     struct a_unit *deadunits; /* list of units killed in last turn. */
  202.     struct a_unit *curdeadunit; /* Dead unit we are looking at. */
  203.     /* All the colors used - filled in by display init */
  204.     long bdcolor;             /* color for borders */
  205.     long bgcolor;             /* background color */
  206.     long fgcolor;             /* foreground (text) color */
  207.     long owncolor;            /* color for us (usually black) */
  208.     long altcolor;            /* another color for us (usually blue) */
  209.     long enemycolor;          /* color for them (usually red) */
  210.     long neutcolor;           /* color for fencesitters (usually gray) */
  211.     long graycolor;           /* color for graying out (usually gray) */
  212.     long diffcolor;           /* unusual/distinct color (usually maroon) */
  213.     long goodcolor;           /* color for OKness (usually green) */
  214.     long badcolor;            /* color for none-OKness (usually red) */
  215.     long hexcolor[MAXTTYPES]; /* the color of each terrain type */
  216.     long main;                /* main window */
  217.     long help;                /* help window */
  218.     long msg;                 /* places for notices/warnings */
  219.     long info;                /* details about a unit */
  220.     long prompt;              /* where prompts and input are */
  221.     long map;                 /* detailed map of vicinity */
  222.     long sides;               /* list of sides and their status */
  223.     long timemode;            /* turn number and mode */
  224.     long clock;               /* chess clock display */
  225.     long state;               /* status of units on side */
  226.     long world;               /* display of entire world */
  227.     long display;             /* side's specific display structure */
  228.     long rmdatabase;          /* resource database */
  229.     /* Filled during side creation */
  230.     struct a_side *next;      /* pointer to next in list */
  231.     int startbeeptime;        /* beep at start of turn if this many */
  232.                   /* seconds past */
  233.     int laststarttime;        /* The physical time when the turn last */
  234.                   /* started a turn */ 
  235. } Side;
  236.  
  237. /* Some convenient macros. */
  238.  
  239. #define humanside(x) ((x) != NULL && (x)->humanp)
  240.  
  241. /* Iteration over all sides. */
  242.  
  243. #define for_all_sides(v) for (v = sidelist; v != NULL; v = v->next)
  244.  
  245. /* Manipulation of bytes encoding views of things. */
  246. /* Types 254, 255 reserved for "seen but unoccupied" and "unseen". */
  247.  
  248. #define buildview(s,t) (((s)<<8)|(t))
  249.  
  250.  
  251. #define vside(v) ((short)(((v)>>8) & 0x0ff))
  252. /* #define vside(v) ((v).side) */
  253. #define vtype(v) ((short)((v) & 0xff))
  254. /* #define vtype(v) ((v).utype) */
  255. #define vside_neutral(v) ((vside(v) == vside(buildview(MAXSIDES,0))))
  256.  
  257.  
  258. #define UNSEEN (MAXUTYPES)
  259. #define EMPTY  (MAXUTYPES+1)
  260.  
  261. #define side_view(s,x,y) (((s)->view)[world.width*(y)+(x)])
  262.  
  263. extern void set_side_view();
  264.  
  265. #define cover(s,x,y) (((s)->coverage)[world.width*(y)+(x)])
  266.  
  267. #define set_cover(s,x,y,v) (((s)->coverage)[world.width*(y)+(x)] = (v))
  268.  
  269. #define add_cover(s,x,y,v) (((s)->coverage)[world.width*(y)+(x)] += (v))
  270.  
  271. #ifdef PREVVIEW
  272. #define side_view_timestamp(s,x,y) (((s)->viewtimestamp)[world.width*(y)+(x)])
  273.  
  274. #define side_view_age(s,x,y) \
  275.             ((cover(s,x,y) > 0) ? 0 : \
  276.          (global.time - (((s)->viewtimestamp)[world.width*(y)+(x)])))
  277.  
  278. #define side_prevview(s,x,y) (((s)->prevview)[world.width*(y)+(x)])
  279. #endif
  280.  
  281. #define area_index(x,y) (((y) / AREA_SIZE) * areas_wide + (x) / AREA_SIZE)
  282.  
  283.  
  284. /* Side variables. */
  285.  
  286. extern Side neutral_placeholder;
  287. extern Side *sidelist, *curside, *tmpside;
  288. extern Side *create_side(), *side_n(), *read_basic_side();
  289.  
  290. extern int numgivens, numhumans, numsides;
  291.  
  292. extern char *hosts[];
  293. extern char *random_side_name();
  294.  
  295. extern bool humans[];
  296.  
  297. extern short areas_wide;      /* number of areas in x direction */
  298. extern short areas_high;      /* number of areas in y direction */
  299.