1 /* $Id: object.h,v 5.23 2002/05/13 20:38:27 bertg Exp $
2  *
3  * XPilot, a multiplayer gravity war game.  Copyright (C) 1991-2001 by
4  *
5  *      Bj�rn Stabell        <bjoern@xpilot.org>
6  *      Ken Ronny Schouten   <ken@xpilot.org>
7  *      Bert Gijsbers        <bert@xpilot.org>
8  *      Dick Balaska         <dick@xpilot.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 
25 #ifndef	OBJECT_H
26 #define	OBJECT_H
27 
28 #ifndef SERVERCONST_H
29 /* need MAX_TANKS */
30 #include "serverconst.h"
31 #endif
32 #ifndef KEYS_H
33 /* need NUM_KEYS */
34 #include "keys.h"
35 #endif
36 #ifndef BIT_H
37 /* need BITV_DECL */
38 #include "bit.h"
39 #endif
40 #ifndef DRAW_H
41 /* need shipobj */
42 #include "draw.h"
43 #endif
44 #ifndef ITEM_H
45 /* need NUM_ITEMS */
46 #include "item.h"
47 #endif
48 #ifndef CLICK_H
49 /* need CLICK */
50 #include "click.h"
51 #endif
52 
53 #ifdef _WINDOWS
54 #include "NT/winNet.h"
55 #endif
56 
57 /*
58  * Different types of objects, including player.
59  * Robots and tanks are players but have an additional type_ext field.
60  * Smart missile, heatseeker and torpedoe can be merged into missile.
61  * ECM doesn't really need an object type.
62  */
63 #define OBJ_PLAYER		(1U<<0)
64 #define OBJ_DEBRIS		(1U<<1)
65 #define OBJ_SPARK		(1U<<2)
66 #define OBJ_BALL		(1U<<3)
67 #define OBJ_SHOT		(1U<<4)
68 #define OBJ_SMART_SHOT		(1U<<5)
69 #define OBJ_MINE		(1U<<6)
70 #define OBJ_TORPEDO		(1U<<7)
71 #define OBJ_HEAT_SHOT		(1U<<8)
72 #define OBJ_PULSE		(1U<<9)
73 #define OBJ_ITEM		(1U<<10)
74 #define OBJ_WRECKAGE		(1U<<11)
75 #define OBJ_ASTEROID		(1U<<12)
76 #define	OBJ_CANNON_SHOT		(1U<<13)
77 
78 /*
79  * Some object types are overloaded.
80  * These bits are set in the player->type_ext field.
81  */
82 #define OBJ_EXT_TANK		(1U<<1)
83 #define OBJ_EXT_ROBOT		(1U<<2)
84 
85 /* macro's to query the type of player. */
86 #define IS_TANK_IND(ind)	IS_TANK_PTR(Players[ind])
87 #define IS_ROBOT_IND(ind)	IS_ROBOT_PTR(Players[ind])
88 #define IS_HUMAN_IND(ind)	IS_HUMAN_PTR(Players[ind])
89 #define IS_TANK_PTR(pl)		(BIT((pl)->type_ext,OBJ_EXT_TANK)==OBJ_EXT_TANK)
90 #define IS_ROBOT_PTR(pl)	(BIT((pl)->type_ext,OBJ_EXT_ROBOT)==OBJ_EXT_ROBOT)
91 #define IS_HUMAN_PTR(pl)	(!BIT((pl)->type_ext,OBJ_EXT_TANK|OBJ_EXT_ROBOT))
92 
93 
94 /*
95  * Different types of attributes a player can have.
96  * These are the bits of the player->have and player->used fields.
97  */
98 #define HAS_EMERGENCY_THRUST	(1U<<30)
99 #define HAS_AUTOPILOT		(1U<<29)
100 #define HAS_TRACTOR_BEAM	(1U<<28)
101 #define HAS_LASER		(1U<<27)
102 #define HAS_CLOAKING_DEVICE	(1U<<26)
103 #define HAS_SHIELD		(1U<<25)
104 #define HAS_REFUEL		(1U<<24)
105 #define HAS_REPAIR		(1U<<23)
106 #define HAS_COMPASS		(1U<<22)
107 #define HAS_AFTERBURNER		(1U<<21)
108 #define HAS_CONNECTOR		(1U<<20)
109 #define HAS_EMERGENCY_SHIELD	(1U<<19)
110 #define HAS_DEFLECTOR		(1U<<18)
111 #define HAS_PHASING_DEVICE	(1U<<17)
112 #define HAS_MIRROR		(1U<<16)
113 #define HAS_ARMOR		(1U<<15)
114 #define HAS_SHOT		(1U<<4)
115 #define HAS_BALL		(1U<<3)
116 
117 
118 /*
119  * Weapons modifiers.
120  */
121 typedef struct {
122     unsigned int	nuclear	:2;	/* N  modifier */
123     unsigned int	warhead	:2;	/* CI modifier */
124     unsigned int	velocity:2;	/* V# modifier */
125     unsigned int	mini	:2;	/* X# modifier */
126     unsigned int	spread	:2;	/* Z# modifier */
127     unsigned int	power	:2;	/* B# modifier */
128     unsigned int	laser	:2;	/* LS LB modifier */
129     unsigned int	spare	:2;	/* padding for alignment */
130 } modifiers;
131 
132 #define CLEAR_MODS(mods)	memset(&(mods), 0, sizeof(modifiers))
133 
134 #define MODS_NUCLEAR_MAX	2	/* - N FN */
135 #define NUCLEAR			(1U<<0)
136 #define FULLNUCLEAR		(1U<<1)
137 
138 #define MODS_WARHEAD_MAX	3	/* - C I CI */
139 #define CLUSTER			(1U<<0)
140 #define IMPLOSION		(1U<<1)
141 
142 #define MODS_VELOCITY_MAX	3	/* - V1 V2 V3 */
143 #define MODS_MINI_MAX		3	/* - X2 X3 X4 */
144 #define MODS_SPREAD_MAX		3	/* - Z1 Z2 Z3 */
145 #define MODS_POWER_MAX		3	/* - B1 B2 B3 */
146 
147 #define MODS_LASER_MAX		2	/* - LS LB */
148 #define STUN			(1U<<0)
149 #define BLIND			(1U<<1)
150 
151 #define LOCK_NONE		0x00	/* No lock */
152 #define LOCK_PLAYER		0x01	/* Locked on player */
153 #define LOCK_VISIBLE		0x02	/* Lock information was on HUD */
154 					/* computed just before frame shown */
155 					/* and client input checked */
156 #define LOCKBANK_MAX		4	/* Maximum number of locks in bank */
157 
158 #define NOT_CONNECTED		(-1)
159 
160 /*
161  * Object position is non-modifiable, except at one place.
162  *
163  * NB: position in pixels used to be a float.
164  */
165 typedef const struct _objposition objposition;
166 struct _objposition {
167     int		cx, cy;			/* object position in clicks. */
168     int		x, y;			/* object position in pixels. */
169     int		bx, by;			/* object position in blocks. */
170 };
171 #define OBJ_X_IN_CLICKS(obj)	((obj)->pos.cx)
172 #define OBJ_Y_IN_CLICKS(obj)	((obj)->pos.cy)
173 #define OBJ_X_IN_PIXELS(obj)	((obj)->pos.x)
174 #define OBJ_Y_IN_PIXELS(obj)	((obj)->pos.y)
175 #define OBJ_X_IN_BLOCKS(obj)	((obj)->pos.bx)
176 #define OBJ_Y_IN_BLOCKS(obj)	((obj)->pos.by)
177 
178 
179 /*
180  * Node within a Cell list.
181  */
182 typedef struct _cell_node cell_node;
183 struct _cell_node {
184     cell_node		*next;
185     cell_node		*prev;
186 };
187 
188 
189 #define OBJECT_BASE	\
190     short		id;		/* For shots => id of player */	\
191     unsigned short	team;		/* Team of player or cannon */	\
192     objposition		pos;		/* World coordinates */		\
193     ipos		prevpos;	/* previous position */		\
194     vector		vel;		/* speed in x,y */		\
195     vector		acc;		/* acceleration in x,y */	\
196     DFLOAT		mass;		/* mass in unigrams */		\
197     long		life;		/* No of ticks left to live */	\
198     long		status;		/* gravity, etc. */		\
199     int			type;		/* one bit of OBJ_XXX */	\
200     int			count;		/* Misc timings */		\
201     modifiers		mods;		/* Modifiers to this object */	\
202     u_byte		color;		/* Color of object */		\
203     u_byte		missile_dir;	/* missile direction */	\
204 /* up to here all object types are the same as all player types. */
205 
206 #define OBJECT_EXTEND	\
207     cell_node		cell;		/* node in cell linked list */	\
208     long		info;		/* Miscellaneous info */	\
209     long		fuselife;	/* fuse duration ticks */	\
210     int			pl_range;	/* distance for collision */	\
211     int			pl_radius;	/* distance for hit */		\
212 /* up to here all object types are the same. */
213 
214 
215 /*
216  * Generic object
217  */
218 typedef struct _object object;
219 struct _object {
220 
221     OBJECT_BASE
222 
223     OBJECT_EXTEND
224 
225 #ifdef __cplusplus
_object_object226 			_object() {}
227 #endif
228 
229 #define OBJ_IND(ind)	(Obj[(ind)])
230 #define OBJ_PTR(ptr)	((object *)(ptr))
231 };
232 
233 
234 /*
235  * Mine object
236  */
237 typedef struct _mineobject mineobject;
238 struct _mineobject {
239 
240     OBJECT_BASE
241 
242     OBJECT_EXTEND
243 
244     int 		owner;		/* Who's object is this ? */
245     DFLOAT		ecm_range;	/* Range from last ecm center */
246     int			spread_left;	/* how much spread time left */
247 
248 #ifdef __cplusplus
_mineobject_mineobject249 			_mineobject() {}
250 #endif
251 
252 #define MINE_IND(ind)	((mineobject *)Obj[(ind)])
253 #define MINE_PTR(ptr)	((mineobject *)(ptr))
254 };
255 
256 
257 #define MISSILE_EXTEND		\
258     DFLOAT		max_speed;	/* speed limitation */		\
259     DFLOAT		turnspeed;	/* how fast to turn */
260 /* up to here all missiles types are the same. */
261 
262 /*
263  * Generic missile object
264  */
265 typedef struct _missileobject missileobject;
266 struct _missileobject {
267 
268     OBJECT_BASE
269 
270     OBJECT_EXTEND
271 
272     MISSILE_EXTEND
273 
274 #ifdef __cplusplus
_missileobject_missileobject275 			_missileobject() {}
276 #endif
277 
278 #define MISSILE_IND(ind)	((missileobject *)Obj[(ind)])
279 #define MISSILE_PTR(ptr)	((missileobject *)(ptr))
280 };
281 
282 
283 /*
284  * Smart missile is a generic missile with extras.
285  */
286 typedef struct _smartobject smartobject;
287 struct _smartobject {
288 
289     OBJECT_BASE
290 
291     OBJECT_EXTEND
292 
293     MISSILE_EXTEND
294 
295     int			new_info;	/* smart re-lock id */
296     DFLOAT		ecm_range;	/* Range from last ecm center */
297 
298 #ifdef __cplusplus
_smartobject_smartobject299 			_smartobject() {}
300 #endif
301 
302 #define SMART_IND(ind)	((smartobject *)Obj[(ind)])
303 #define SMART_PTR(ptr)	((smartobject *)(ptr))
304 };
305 
306 
307 /*
308  * Torpedo is a generic missile with extras
309  */
310 typedef struct _torpobject torpobject;
311 struct _torpobject {
312 
313     OBJECT_BASE
314 
315     OBJECT_EXTEND
316 
317     MISSILE_EXTEND
318 
319     int			spread_left;	/* how much spread time left */
320 
321 #ifdef __cplusplus
_torpobject_torpobject322 			_torpobject() {}
323 #endif
324 
325 #define TORP_IND(ind)	((torpobject *)Obj[(ind)])
326 #define TORP_PTR(ptr)	((torpobject *)(ptr))
327 };
328 
329 
330 /*
331  * The ball object.
332  */
333 typedef struct _ballobject ballobject;
334 struct _ballobject {
335 
336     OBJECT_BASE
337 
338     OBJECT_EXTEND
339 
340     int 		owner;		/* Who's object is this ? */
341     int			treasure;	/* treasure for ball */
342     DFLOAT		length;		/* distance ball to player */
343 
344 #ifdef __cplusplus
_ballobject_ballobject345 			_ballobject() {}
346 #endif
347 
348 #define BALL_IND(ind)	((ballobject *)Obj[(ind)])
349 #define BALL_PTR(obj)	((ballobject *)(obj))
350 };
351 
352 
353 /*
354  * Object with a wireframe representation.
355  */
356 typedef struct _wireobject wireobject;
357 struct _wireobject {
358 
359     OBJECT_BASE
360 
361     OBJECT_EXTEND
362 
363     DFLOAT		turnspeed;	/* how fast to turn */
364 
365     u_byte		size;		/* Size of object (wreckage) */
366     u_byte		rotation;	/* Rotation direction */
367 
368 #ifdef __cplusplus
_wireobject_wireobject369 			_wireobject() {}
370 #endif
371 
372 #define WIRE_IND(ind)	((wireobject *)Obj[(ind)])
373 #define WIRE_PTR(obj)	((wireobject *)(obj))
374 };
375 
376 
377 /*
378  * Any object type should be part of this union.
379  */
380 typedef union _anyobject anyobject;
381 union _anyobject {
382     object		obj;
383     ballobject		ball;
384     mineobject		mine;
385     missileobject	missile;
386     smartobject		smart;
387     torpobject		torp;
388     wireobject		wireobj;
389 };
390 
391 
392 /*
393  * Fuel structure, used by player
394  */
395 typedef struct {
396     long	sum;			/* Sum of fuel in all tanks */
397     long	max;			/* How much fuel can you take? */
398     int		current;		/* Number of currently used tank */
399     int		num_tanks;		/* Number of tanks */
400     long	tank[1 + MAX_TANKS];	/* main fixed tank + extra tanks. */
401     long	l1;			/* Fuel critical level */
402     long	l2;			/* Fuel warning level */
403     long	l3;			/* Fuel notify level */
404 } pl_fuel_t;
405 
406 struct _visibility {
407     int		canSee;
408     long	lastChange;
409 };
410 
411 #define MAX_PLAYER_ECMS		8	/* Maximum simultaneous per player */
412 typedef struct {
413     int		size;
414     position	pos;
415     int		id;
416 } ecm_t;
417 
418 /*
419  * Structure holding the info for one pulse of a laser.
420  */
421 typedef struct {
422     position		pos;
423     int			dir;
424     int			len;
425     int			life;
426     int			id;
427     unsigned short	team;
428     modifiers		mods;
429     bool		refl;
430 } pulse_t;
431 
432 /*
433  * Transporter info.
434  */
435 typedef struct {
436     position	pos;
437     int		target;
438     int		id;
439     int		count;
440 } trans_t;
441 
442 /*
443  * Shove-information.
444  *
445  * This is for keeping a record of the last N times the player was shoved,
446  * for assigning wall-smash-blame, where N=MAX_RECORDED_SHOVES.
447  */
448 #define MAX_RECORDED_SHOVES 4
449 
450 typedef struct {
451     int		pusher_id;
452     int		time;
453 } shove_t;
454 
455 struct robot_data;
456 
457 /* IMPORTANT
458  *
459  * This is the player structure, the first part MUST be similar to object_t,
460  * this makes it possible to use the same basic operations on both of them
461  * (mainly used in update.c).
462  */
463 typedef struct player player;
464 struct player {
465 
466     OBJECT_BASE
467 
468     /* up to here the player type should be the same as an object. */
469 
470     int		type_ext;		/* extended type info (tank, robot) */
471 
472     DFLOAT	turnspeed;		/* How fast player acc-turns */
473     DFLOAT	velocity;		/* Absolute speed */
474 
475     int		kills;			/* Number of kills this round */
476     int		deaths;			/* Number of deaths this round */
477 
478     long	used;			/** Items you use **/
479     long	have;			/** Items you have **/
480 
481     int		shield_time;		/* Shields if no playerShielding */
482     pl_fuel_t	fuel;			/* ship tanks and the stored fuel */
483     DFLOAT	emptymass;		/* Mass of empty ship */
484     DFLOAT	float_dir;		/* Direction, in float var */
485     DFLOAT	turnresistance;		/* How much is lost in % */
486     DFLOAT	turnvel;		/* Current velocity of turn (right) */
487     DFLOAT	oldturnvel;		/* Last velocity of turn (right) */
488     DFLOAT	turnacc;		/* Current acceleration of turn */
489     DFLOAT	score;			/* Current score of player */
490     DFLOAT	prev_score;		/* Last score that has been updated */
491     int		prev_life;		/* Last life that has been updated */
492     shipobj	*ship;			/* wire model of ship shape */
493     DFLOAT	power;			/* Force of thrust */
494     DFLOAT	power_s;		/* Saved power fiks */
495     DFLOAT	turnspeed_s;		/* Saved turnspeed */
496     DFLOAT	turnresistance_s;	/* Saved (see above) */
497     DFLOAT	sensor_range;		/* Range of sensors (radar) */
498     int		shots;			/* Number of active shots by player */
499     int		missile_rack;		/* Next missile rack to be active */
500 
501     int		num_pulses;		/* Number of laser pulses in the air. */
502 
503     int		emergency_thrust_left;	/* how much emergency thrust left */
504     int		emergency_thrust_max;	/* maximum time left */
505     int		emergency_shield_left;	/* how much emergency shield left */
506     int		emergency_shield_max;	/* maximum time left */
507     int		phasing_left;		/* how much time left */
508     int		phasing_max;		/* maximum time left */
509 
510     int		item[NUM_ITEMS];	/* for each item type how many */
511     int		lose_item;		/* which item to drop */
512     int		lose_item_state;	/* lose item key state, 2=up,1=down */
513 
514     DFLOAT	auto_power_s;		/* autopilot saves of current */
515 					/* power, turnspeed and */
516     DFLOAT	auto_turnspeed_s;	/* turnresistance settings. Restored */
517     DFLOAT	auto_turnresistance_s;	/* when autopilot turned off */
518     modifiers	modbank[NUM_MODBANKS];	/* useful modifier settings */
519     bool	tractor_is_pressor;	/* on if tractor is pressor */
520     int		shot_max;		/* Maximum number of shots active */
521     long	shot_time;		/* Time of last shot fired by player */
522     int		repair_target;		/* Repairing this target */
523     int		fs;			/* Connected to fuel station fs */
524     int		check;			/* Next check point to pass */
525     int		prev_check;		/* Previous check point for score */
526     int		time;			/* The time a player has used */
527     int		round;			/* Number of rounds player have done */
528     int		prev_round;		/* Previous rounds value for score */
529     int		best_lap;		/* Players best lap time */
530     int		last_lap;		/* Time on last pass */
531     int		last_lap_time;		/* What was your last pass? */
532     int		last_check_dir;		/* player dir at last checkpoint */
533     long	last_wall_touch;	/* last time player touched a wall */
534 
535     int		home_base;		/* Num of home base */
536     struct {
537 	int	    tagged;		/* Flag, what is tagged? */
538 	int	    pl_id;		/* Tagging player id */
539 	DFLOAT	    distance;		/* Distance to object */
540     } lock;
541     int		lockbank[LOCKBANK_MAX]; /* Saved player locks */
542 
543     u_byte	dir;			/* Direction of acceleration */
544     u_byte	unused1;		/* padding for alignment */
545     char	mychar;			/* Special char for player */
546     char	prev_mychar;		/* Special char for player */
547     char	name[MAX_CHARS];	/* Nick-name of player */
548     char	realname[MAX_CHARS];	/* Real name of player */
549     char	hostname[MAX_CHARS];	/* Hostname of client player uses */
550     unsigned short	pseudo_team;	/* Which team for detaching tanks */
551     int		alliance;		/* Member of which alliance? */
552     int		prev_alliance;		/* prev. alliance for score */
553     int		invite;			/* Invitation for alliance */
554     ballobject	*ball;
555 
556     /*
557      * Pointer to robot private data (dynamically allocated).
558      * Only used in robot code.
559      */
560     struct robot_data	*robot_data_ptr;
561 
562     /*
563      * A record of who's been pushing me (a circular buffer).
564      */
565     shove_t     shove_record[MAX_RECORDED_SHOVES];
566     int         shove_next;
567 
568     struct _visibility *visibility;
569 
570     int		updateVisibility, forceVisible, damaged;
571     int		wormDrawCount, wormHoleHit, wormHoleDest;
572     int		stunned;
573 
574     int		last_target_update;	/* index of last updated target */
575     int		last_cannon_update;	/* index of last updated cannon */
576     int		last_fuel_update;	/* index of last updated fuel */
577     int		last_wormhole_update;	/* index of last updated wormhole */
578 
579     int		ecmcount;		/* number of active ecms */
580 
581     int		conn;			/* connection index, -1 if robot */
582     unsigned	version;		/* XPilot version number of client */
583 
584     BITV_DECL(last_keyv, NUM_KEYS);	/* Keyboard state */
585     BITV_DECL(prev_keyv, NUM_KEYS);	/* Keyboard state */
586 
587     long	frame_last_busy;	/* When player touched keyboard. */
588 
589     void	*audio;			/* audio private data */
590 
591     int		player_fps;		/* FPS that this player can do */
592     int		player_round;		/* Divisor for player FPS calculation */
593     int		player_count;		/* Player's current frame count */
594 
595     int		isowner;		/* If player started this server. */
596     int		isoperator;		/* If player has operator privileges. */
597 
598 #ifdef __cplusplus
playerplayer599 		player() {}
600 #endif
601 };
602 
603 #endif
604