1 /* struct.h for the client of an xtrek socket protocol.
2  *
3  * Most of the unneeded stuff in the structures has been thrown away.
4  *
5  */
6 #include "copyright.h"
7 
8 #ifndef _h_struct
9 #define _h_struct
10 
11 struct distress
12   {
13     unsigned char sender;
14     unsigned char dam, shld, arms, wtmp, etmp, fuelp, sts;
15     unsigned char wtmpflag, etempflag, cloakflag, distype, macroflag;
16     unsigned char close_pl, close_en, tclose_pl, tclose_en, pre_app, i;
17     unsigned char close_j, close_fr, tclose_j, tclose_fr;
18     unsigned char cclist[6];			 /* allow us some day to cc a
19 						  * message up to 5 people */
20     /* sending this to the server allows the server to do the cc action */
21     /* otherwise it would have to be the client ... less BW this way */
22     char    preappend[80];			 /* text which we pre or append */
23   };
24 
25 struct dmacro_list
26   {
27     unsigned char c;
28     char   *name;
29     char   *macro;
30   };
31 
32 struct status
33   {
34     unsigned char tourn;			 /* Tournament mode? */
35     /* These stats only updated during tournament mode */
36     unsigned int armsbomb, planets, kills, losses, time;
37     /* Use LONG for this, so it never wraps */
38     unsigned LONG timeprod;
39   };
40 
41 enum dist_type
42   {
43     /* help me do series */
44     take = 1, ogg, bomb, space_control,
45     save_planet,
46     base_ogg,
47     help1, help2,
48 
49     /* doing series */
50     escorting, ogging, bombing, controlling,
51     asw,
52     asbomb,
53     doing1, doing2,
54 
55     /* other info series */
56     free_beer,					 /* ie. player x is totally
57 						  * hosed now */
58     no_gas,					 /* ie. player x has no gas */
59     crippled,					 /* ie. player x is way hurt
60 						  * but may have gas */
61     pickup,					 /* player x picked up armies
62 						  */
63     pop,					 /* there was a pop somewhere
64 						  */
65     carrying,					 /* I am carrying */
66     other1, other2,
67 
68     /* just a generic distress call */
69     generic
70 
71 #ifdef RCM
72     ,rcm
73 #endif
74   };
75 
76 /* The General distress has format:
77  *
78  * byte1: 00yzzzzz where zzzzz is dist_type, and y is 1 if this is a more
79  * complicated macro and not just a simple distress (a simple distress will
80  * ONLY send ship info like shields, armies, status, location, etc.). I guess
81  * y=1 can be for !    future expansion.
82  *
83  * byte2: 1fff ffff - f = percentage fuel remaining (0-100) byte3: 1ddd dddd - %
84  * damage byte4: 1sss ssss - % shields remaining byte5: 1eee eeee - % etemp
85  * byte6: 1www wwww - % wtemp byte7: 100a aaaa - armies carried byte8: (lsb
86  * of me->p_status) & 0x80 byte9: 1ppp pppp - planet closest to me byte10:
87  * 1eee eeee - enemy closest to me byte11: 1ppp pppp - planet closest to
88  * target byte12: 1eee eeee - enemy closest to target byte13: 1ttt tttt -
89  * tclose_j byte14: 1jjj jjjj - close_j byte15: 1fff ffff - tclose_fr byte16:
90  * 1ccc cccc - close_fr byte17+: cc list (each player to cc this message to
91  * is 11pp ppp) cc list is terminated by 0x80 (pre-pend) or 0100 0000
92  * (append) ) byte18++: the text to pre or append .. depending on termination
93  * above. text is null terminated and the last thing in this distress */
94 
95 /* The following defines are for gameup field in SP_GENERIC_32 'b' */
96 #define GU_GAMEOK 0x1
97 #define GU_UNSAFE 0x1			/* not currently safe due idle */
98 #define GU_PRACTICE 0x2			/* Basepractice robot is present */
99 /* also set by INL robot during a pause, in pre-game, or post-game */
100 #define GU_CHAOS 0x4
101 /* also set by INL robot in post-game */
102 #define GU_PAUSED 0x8
103 #define GU_INROBOT 0x10			/* INL robot is present	*/
104 #define GU_NEWBIE 0x20			/* Newbie robot is present */
105 #define GU_PRET 0x40			/* Pre-t robot is present */
106 #define GU_BOT_IN_GAME 0x80		/* Pre-t robot + bots are present */
107 #define GU_CONQUER 0x100		/* conquest parade in progress	*/
108 #define GU_PUCK 0x200			/* Hockey robot is present */
109 #define GU_DOG 0x400			/* Dogfight robot is present */
110 #define GU_INL_DRAFTING 0x800           /* INL draft pre-game is in progress */
111 #define GU_INL_DRAFTED 0x1000           /* INL draft game is in progress */
112 
113 #define PFREE 0
114 #define POUTFIT 1
115 #define PALIVE 2
116 #define PEXPLODE 3
117 #define PDEAD 4
118 #define POBSERV 5
119 
120 #define PFSHIELD	0x0001
121 #define PFREPAIR	0x0002
122 #define PFBOMB		0x0004
123 #define PFORBIT		0x0008
124 #define PFCLOAK		0x0010
125 #define PFWEP		0x0020
126 #define PFENG		0x0040
127 #define PFROBOT		0x0080
128 #define PFBEAMUP	0x0100
129 #define PFBEAMDOWN	0x0200
130 #define PFSELFDEST	0x0400
131 #define PFGREEN		0x0800
132 #define PFYELLOW	0x1000
133 #define PFRED		0x2000
134 #define PFPLOCK		0x4000			 /* Locked on a player */
135 #define PFPLLOCK	0x8000			 /* Locked on a planet */
136 #define PFCOPILOT	0x10000			 /* Allow copilots */
137 #define PFWAR		0x20000			 /* computer reprogramming
138 						  * for war */
139 #define PFPRACTR	0x40000			 /* practice type robot (no
140 						  * kills) */
141 #define PFDOCK          0x80000			 /* true if docked to a
142 						  * starbase */
143 #define PFREFIT         0x100000		 /* true if about to refit */
144 #define PFREFITTING	0x200000		 /* true if currently
145 						  * refitting */
146 #define PFTRACT  	0x400000		 /* tractor beam activated */
147 #define PFPRESS  	0x800000		 /* pressor beam activated */
148 #define PFDOCKOK	0x1000000		 /* docking permission */
149 #define PFOBSERV	0x8000000		 /* observer */
150 
151 #define KQUIT		0x01			 /* Player quit */
152 #define KTORP		0x02			 /* killed by torp */
153 #define KPHASER		0x03			 /* killed by phaser */
154 #define KPLANET		0x04			 /* killed by planet */
155 #define KSHIP		0x05			 /* killed by other ship */
156 #define KDAEMON		0x06			 /* killed by dying daemon */
157 #define KWINNER		0x07			 /* killed by a winner */
158 #define KGHOST		0x08			 /* killed because a ghost */
159 #define KGENOCIDE	0x09			 /* killed by genocide */
160 #define KPROVIDENCE	0x0a			 /* killed by a hacker */
161 #define KPLASMA         0x0b			 /* killed by a plasma * *
162 						  * torpedo */
163 #define TOURNEND	0x0c			 /* tournament game ended */
164 #define KOVER		0x0d			 /* game over  */
165 #define TOURNSTART	0x0e			 /* tournament game starting */
166 #define KBADBIN		0x0f			 /* bad binary */
167 /* requires feature F_why_dead_2 aka WHY_DEAD_2 */
168 #define KTORP2          0x10            /* killed by detted torps */
169 #define KSHIP2          0x11            /* chain-reaction explosions */
170 #define KPLASMA2        0x12            /* killed by zapped plasma */
171 
172 #define NUM_TYPES 8
173 #define SCOUT 0
174 #define DESTROYER 1
175 #define CRUISER 2
176 #define BATTLESHIP 3
177 #define ASSAULT 4
178 #define STARBASE 5
179 #define SGALAXY	6
180 #define ATT	7
181 
182 struct ship
183   {
184     short   s_phaserdamage;
185     int     s_maxspeed;
186     int     s_maxfuel;
187     int     s_maxshield;
188     int     s_maxdamage;
189     int     s_maxegntemp;
190     int     s_maxwpntemp;
191     short   s_maxarmies;
192     short   s_width;
193     short   s_height;
194     short   s_type;
195     int     s_torpspeed;
196   };
197 
198 struct stats
199   {
200     double  st_maxkills;			 /* max kills ever */
201     int     st_kills;				 /* how many kills */
202     int     st_losses;				 /* times killed */
203     int     st_armsbomb;			 /* armies bombed */
204     int     st_planets;				 /* planets conquered */
205     int     st_ticks;				 /* Ticks I've been in game */
206     int     st_tkills;				 /* Kills in tournament play */
207     int     st_tlosses;				 /* Losses in tournament play */
208     int     st_tarmsbomb;			 /* Tournament armies bombed */
209     int     st_tplanets;			 /* Tournament planets
210 						  * conquered */
211     int     st_tticks;				 /* Tournament ticks */
212     /* SB stats are entirely separate */
213     int     st_sbkills;				 /* Kills as starbase */
214     int     st_sblosses;			 /* Losses as starbase */
215     int     st_sbticks;				 /* Time as starbase */
216     double  st_sbmaxkills;			 /* Max kills as starbase */
217     LONG    st_lastlogin;			 /* Last time this player was
218 						  * played */
219     int     st_flags;				 /* Misc option flags */
220 
221 #ifdef MOUSE_AS_SHIFT
222     unsigned char st_keymap[480];		 /* keymap for this player */
223 #else
224     unsigned char st_keymap[96];		 /* keymap for this player */
225 #endif
226     int     st_rank;				 /* Ranking of the player */
227   };
228 
229 #define ST_MAPMODE      1
230 #define ST_NAMEMODE     2
231 #define ST_SHOWSHIELDS  4
232 #define ST_KEEPPEACE    8
233 #define ST_SHOWLOCAL    16			 /* two bits for these two */
234 #define ST_SHOWGLOBAL   64
235 
236 struct player
237   {
238     int     p_no;
239     int     p_updates;				 /* Number of updates ship
240 						  * has survived */
241     int     p_status;				 /* Player status */
242     unsigned int p_flags;			 /* Player flags */
243     char    p_name[16];
244     char    p_login[16];
245     char    p_monitor[16];			 /* Monitor being played on */
246     char    p_mapchars[2];			 /* Cache for map window
247 						  * image */
248     struct ship p_ship;				 /* Personal ship statistics */
249     int     p_x;
250     int     p_y;
251     unsigned char p_dir;			 /* Real direction */
252     unsigned char p_desdir;			 /* desired direction */
253     int     p_subdir;				 /* fraction direction change
254 						  */
255     int     p_speed;				 /* Real speed */
256     short   p_desspeed;				 /* Desired speed */
257     int     p_subspeed;				 /* Fractional speed */
258     short   p_team;				 /* Team I'm on */
259     int     p_damage;				 /* Current damage */
260     int     p_subdamage;			 /* Fractional damage repair */
261     int     p_shield;				 /* Current shield power */
262     int     p_subshield;			 /* Fractional shield
263 						  * recharge */
264     short   p_cloakphase;			 /* Drawing stage of cloaking
265 						  * engage/disengage. */
266     short   p_ntorp;				 /* Number of torps flying */
267     short   p_nplasmatorp;			 /* Number of plasma torps
268 						  * active */
269     char    p_hostile;				 /* Who my torps will hurt */
270     char    p_swar;				 /* Who am I at sticky war
271 						  * with */
272     float   p_kills;				 /* Enemies killed */
273     short   p_planet;				 /* Planet orbiting or locked
274 						  * onto */
275     short   pl_orbit;				 /* planet being orbited */
276     short   p_playerl;				 /* Player locked onto */
277 
278 #ifdef ARMY_SLIDER
279     int     p_armies;				 /* XXX: for stats */
280 #else
281     short   p_armies;
282 #endif						 /* ARMY_SLIDER */
283     int     p_fuel;
284     short   p_explode;				 /* Keeps track of final
285 						  * explosion */
286     int     p_etemp;
287     short   p_etime;
288     int     p_wtemp;
289     short   p_wtime;
290     short   p_whydead;				 /* Tells you why you died */
291     short   p_whodead;				 /* Tells you who killed you */
292     struct stats p_stats;			 /* player statistics */
293     short   p_genoplanets;			 /* planets taken since last
294 						  * genocide */
295     short   p_genoarmsbomb;			 /* armies bombed since last
296 						  * genocide */
297     short   p_planets;				 /* planets taken this game */
298     short   p_armsbomb;				 /* armies bombed this game */
299     int     p_docked;				 /* If starbase, # docked to,
300 						  * else pno base host */
301     int     p_port[4];				 /* If starbase, pno of ship
302 						  * docked to that port,
303 						  * else p_port[0] = port
304 						  * # docked to on host.
305 						  */
306     short   p_tractor;				 /* What player is in tractor
307 						  * lock */
308     int     p_pos;				 /* My position in the player
309 						  * file */
310     short   p_repair_time;			 /* seconds */
311   };
312 
313 struct statentry
314   {
315     char    name[16], password[16];
316     struct stats stats;
317   };
318 
319 /* Torpedo states */
320 
321 #define TFREE 0
322 #define TMOVE 1
323 #define TEXPLODE 2
324 #define TDET 3
325 #define TOFF 4
326 #define TSTRAIGHT 5				 /* Non-wobbling torp */
327 
328 
329 struct torp
330   {
331     unsigned char t_status;			 /* State information */
332     short   t_owner;
333     char    t_war;				 /* enemies */
334     int     t_x;
335     int     t_y;
336     short   t_fuse;				 /* Life left in current *
337 						  * state */
338     unsigned char t_updateFuse;			 /* Updates before torp will
339 						  * expire */
340     unsigned char t_dir;			 /* direction */
341   };
342 
343 
344 /* Plasma Torpedo states */
345 
346 #define PTFREE 0
347 #define PTMOVE 1
348 #define PTEXPLODE 2
349 #define PTDET 3
350 
351 struct plasmatorp
352   {
353     unsigned char pt_status;			 /* State information */
354     char    pt_war;				 /* enemies */
355     short   pt_owner;
356     short   pt_fuse;				 /* Life left in current * *
357 						  * state */
358     short   pt_updateFuse;			 /* Time till expiry */
359     int     pt_x;
360     int     pt_y;
361   };
362 
363 #define PHFREE 0x00
364 #define PHHIT  0x01				 /* When it hits a person */
365 #define PHMISS 0x02
366 #define PHHIT2 0x04				 /* When it hits a photon */
367 
368 struct phaser
369   {
370     unsigned char ph_status;			 /* What it's up to */
371     unsigned char ph_dir;			 /* direction */
372     short   ph_target;				 /* Who's being hit (for * *
373 						  * drawing) */
374     short   ph_updateFuse;			 /* Time till expiry */
375     short   ph_fuse;				 /* Life left for drawing */
376     int     ph_x, ph_y;				 /* For when it hits a torp */
377 #ifdef SOUND
378     int     sound_phaser;			 /* yet to play the sound */
379 #endif
380   };
381 
382 
383 #ifdef RSA
384 struct rsa_key
385   {
386     unsigned char client_type[KEY_SIZE];
387     unsigned char architecture[KEY_SIZE];
388     unsigned char global[KEY_SIZE];
389     unsigned char public[KEY_SIZE];
390   };
391 
392 #endif
393 
394 /* An important note concerning planets:  The game assumes that the planets
395  * are in a 'known' order.  Ten planets per team, the first being the home
396  * planet. */
397 
398 /* the lower bits represent the original owning team */
399 #define PLREPAIR 0x010
400 #define PLFUEL 0x020
401 #define PLAGRI 0x040
402 #define PLREDRAW 0x080				 /* Player close for redraw */
403 #define PLHOME 0x100				 /* home planet for a given
404 						  * team */
405 #define PLCOUP 0x200				 /* Coup has occured */
406 #define PLCHEAP 0x400				 /* Planet was taken from
407 						  * undefended team */
408 #define PLCORE 0x800
409 #define PLCLEAR 0x1000
410 
411 struct planet
412   {
413     int     pl_no;
414     int     pl_flags;				 /* State information */
415     int     pl_owner;
416     int     pl_x;
417     int     pl_y;
418     char    pl_name[16];
419     int     pl_namelen;				 /* Cuts back on strlen's */
420     int     pl_armies;
421     int     pl_info;				 /* Teams which have info on
422 						  * planets */
423     int     pl_deadtime;			 /* Time before planet will
424 						  * support life */
425     int     pl_couptime;			 /* Time before coup may take
426 						  * place */
427   };
428 
429 #define MVALID 0x01
430 #define MGOD   0x10
431 #define MMOO   0x12
432 
433 #ifdef TOOLS
434 #define MTOOLS 0x14
435 #endif
436 
437 /* order flags by importance (0x100 - 0x400) */
438 /* restructuring of message flags to squeeze them all into 1 byte - jmn */
439 /* hopefully quasi-back-compatible: MVALID, MINDIV, MTEAM, MALL, MGOD use up
440  * 5 bits. this leaves us 3 bits. since the server only checks for those
441  * flags when deciding message related things and since each of the above
442  * cases only has 1 flag on at a time we can overlap the meanings of the
443  * flags */
444 
445 #define MINDIV 0x02
446 /* these go with MINDIV flag */
447 
448 #ifdef STDBG
449 #define MDBG   0x20
450 #endif
451 
452 #define MCONFIG 0x40				 /* config messages from * *
453 						  * server */
454 #define MDIST 0x60				 /* flag distress type * *
455 						  * messages properly */
456 
457 #ifdef MULTILINE_MACROS
458 #define MMACRO 0x80
459 #endif
460 
461 #define MTEAM  0x04
462 /* these go with MTEAM flag */
463 #define MTAKE  0x20
464 #define MDEST  0x40
465 #define MBOMB  0x60
466 #define MCOUP1 0x80
467 #define MCOUP2 0xA0
468 #define MDISTR 0xC0				 /* flag distress type
469 						  * messages */
470 
471 #define MALL   0x08
472 /* these go with MALL flag */
473 #define MGENO  0x20				 /* MGENO is not used in INL
474 						  * server but beLONGs
475 						  * here  */
476 #define MCONQ  0x20				 /* not enought bits to
477 						  * distinguish MCONQ/MGENO :-( */
478 #define MKILLA 0x40
479 #define MKILLP 0x60
480 #define MKILL  0x80
481 #define MLEAVE 0xA0
482 #define MJOIN  0xC0
483 #define MGHOST 0xE0
484 /* MMASK not used in INL server */
485 
486 #define MWHOMSK  0x1f				 /* mask with this to find
487 						  * who msg to */
488 #define MWHATMSK 0xe0				 /* mask with this to find
489 						  * what message about */
490 
491 /* old flags...
492  * #define MVALID 0x01
493  * #define MINDIV 0x02
494  * #define MTEAM  0x04
495  * #define MALL   0x08
496  * #define MGOD   0x10
497  *
498  * #define MGENO  0x100            order these by importance (0x100 - 0x400)
499  * #define MCONQ  0x110
500  * #define MTAKE  0x120
501  * #define MDEST  0x130
502  * #define MKILLA 0x200
503  * #define MBOMB  0x210
504  * #define MKILLP 0x220
505  * #define MKILL  0x230
506  * #define MLEAVE 0x300
507  * #define MJOIN  0x310
508  * #define MGHOST 0x320
509  * #define MCOUP1 0x330
510  * #define MCOUP2 0x340
511  * end of old flags  */
512 
513 
514 
515 struct message
516   {
517     int     m_no;
518     int     m_flags;
519     int     m_time;
520     int     m_recpt;
521     char    m_data[80];
522   };
523 
524 /* message control structure */
525 
526 struct mctl
527   {
528     int     mc_current;
529   };
530 
531 /* This is a structure used for objects returned by mouse pointing */
532 
533 #define PLANETTYPE 0x1
534 #define PLAYERTYPE 0x2
535 
536 struct obtype
537   {
538     int     o_type;
539     int     o_num;
540   };
541 
542 struct rank
543 {
544     float hours, ratings, offense;
545     char *name, *cname;
546 };
547 
548 struct context
549 {
550     short         gameup;                  /* server status flags           */
551     unsigned char tournament_teams;        /* what teams are involved       */
552     unsigned char tournament_age;          /* duration of t-mode so far     */
553     char          tournament_age_units;    /* units for above, see s2du     */
554     unsigned char tournament_remain;       /* remaining INL game time       */
555     char          tournament_remain_units; /* units for above, see s2du     */
556     unsigned char starbase_remain;         /* starbase reconstruction, mins */
557     unsigned char team_remain;             /* team surrender time, seconds  */
558 };
559 
560 struct memory
561   {
562     struct player players[MAXPLAYER];
563     struct torp torps[MAXPLAYER * MAXTORP];
564     struct plasmatorp plasmatorps[MAXPLAYER * MAXPLASMA];
565     struct status status[1];
566     struct planet planets[MAXPLANETS];
567     struct phaser phasers[MAXPLAYER];
568     struct mctl mctl[1];
569     struct message messages[MAXMESSAGE];
570     struct ship shipvals[NUM_TYPES];
571     struct context context[1];
572   };
573 
574 struct plupdate
575   {
576     int     plu_update;
577     int     plu_x, plu_y;
578   };
579 
580 struct macro_list
581   {
582     int     type;
583     unsigned char key;
584     char    who;
585     char   *string;
586   };
587 
588 /******************************************************************************/
589 /***                   Distress structure definitions                       ***/
590 /***                                                                        ***/
591 /***  The LOW_DISTRESS, MID_DISTRESS, and HIGH_DISTRESS are all used to     ***/
592 /***  index the correct items within the DISTRESS_BLOCK's item array.  The  ***/
593 /***  distress block contains a minimum and maximum value for each item, a  ***/
594 /***  flag to indicate whether the distress on this value is active or not, ***/
595 /***  and three single character pointers for different severity levels.    ***/
596 /******************************************************************************/
597 
598 #define DIST_LOW            ( 0 )
599 #define DIST_MID            ( 1 )
600 #define DIST_HIGH           ( 2 )
601 
602 #define DIST_SHIELDS        ( 0 )
603 #define DIST_DAMAGE         ( 1 )
604 #define DIST_WTEMP          ( 2 )
605 #define DIST_ETEMP          ( 3 )
606 #define DIST_ARMYS          ( 4 )
607 #define DIST_FUEL           ( 5 )
608 
609 typedef struct distress_block
610   {
611     int     min, max;
612     int     on;
613     char   *item[3];
614   }
615 
616 DISTRESS_DESC;
617 
618 struct distress_list
619   {						 /* need one for ships and *
620 						  * * one for SBs */
621     DISTRESS_DESC problem[6];
622   };
623 
624 #ifdef HOCKEY_LINES
625 struct s_line
626   {
627     int     begin_x, begin_y;			 /* Start point of the line */
628     int     end_x, end_y;			 /* End point of the line   */
629     W_Color color;				 /* The color of the line   */
630     int     orientation;			 /* Horizontal or Vertical? */
631     int    *flag;				 /* Should line be drawn?   */
632   };
633 
634 #endif /* HOCKEY_LINES */
635 
636 struct shipdef
637   {
638     char   *name;
639     char   *rcfile;
640     unsigned char *keymap;
641     unsigned char *buttonmap;
642     unsigned char *ckeymap;
643   };
644 
645 #ifdef TOOLS
646 struct key_list
647   {
648     unsigned char dest;
649     char   *name;
650   };
651 
652 #endif
653 
654 #endif /* _h_struct */
655