
/*
 * Copyright (c) 1991    Jon Wesener 
 * Gaming Software
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting
 * documentation.  No representations are made about the
 * suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 *
 */

#ident	"@(#)server.h	1.20 :/usr/key/jojow/X/src/guts/SCCS/s.server.h 3/19/91 10:16:09 "

/* server.h - server specific includes */
#include "tank.h"


/* DEFS */

/* screen object speeds */
#define TANKPRI		4
#define HEATPRI		3
#define SHELLPRI	1
#define EXPLPRI		4
#define MINEPRI		2
#define BONUSPRI	3
#define STATUPD		40

#define MAXNM		40
#define MAXBUF		512

#define MAXSHELLF	4
#define MAXSHELL	(MAXSHELLF * MAXTANK)

#define MAXMINEF	10
#define MAXMINE		(MAXMINEF * MAXTANK)

#define MAXHEATF	3
#define MAXHEAT		(MAXHEATF * MAXTANK)

#define MAXEXPL		130
#define MAXHBMISS	100
#define MAXPOW		30
#define HEATLIFE	20
#define MAXBON		5

#define CSAFE		0x40

#define TSAFECNT	60


/* field items */
#define FWALL		'#'
#define FSPACE		' '
#define FTANK		'T'
#define FMINE		'M'
#define FPOW		'P'
#define FBON		'B'


/* server state flags */
#define SSCUDFRC	0x2
#define SSTUDFRC	0x4

#define TIMESTEP	40000L

struct bon {
	char	b_x;
	char	b_y;				/* position */
	struct bon *b_next;			/* chain */
};
typedef struct bon bon_t;

struct pow {
	char	p_x;
	char	p_y;				/* position */
	char	p_val;				/* amount of energy */
	struct pow *p_next;			/* chain */
};
typedef struct pow pow_t;

struct expl {
	char	e_x;
	char	e_y;				/* position */
	char	e_pri;				/* priority */
	char	e_frm;				/* expl frame */
	char	e_size;				/* size of explosion */
	struct expl		*e_next;	/* chain */
};
typedef struct expl expl_t;

struct mine {
	char	m_x;
	char	m_y;				/* position */
	char	m_id;				/* mine id */
	struct mine		*m_next;	/* chain */
	struct tank		*m_own;		/* owner (leash?) */
};
typedef struct mine mine_t;

struct heat {
	char	h_x;
	char	h_y;				/* position */
	char	h_dir;				/* direction shell is moving */
	char	h_pri;				/* shell speed/priority */
	char	h_life;				/* max distance */
	struct heat		*h_next;	/* chain */
	struct tank		*h_own;		/* owner (leash?) */
};
typedef struct heat heat_t;

struct shell {
	char	s_x;
	char	s_y;				/* position */
	char	s_dir;				/* direction shell is moving */
	char	s_pri;				/* shell speed/priority */
	struct shell	*s_next;	/* chain */
	struct tank		*s_own;		/* owner (leash?) */
};
typedef struct shell shell_t;

struct tank {
	int		t_state;			/* tank state */
#define TSCUD		0x1
#define THRTBEAT	0x2
#define TVALID		0x4
#define TEXP		0x8
#define TSAFE		0x10
#define TCLOAK		0x40
#define TMINE		0x100
	int		t_kills;			/* Number of kills */
	int		t_dead;				/* Number of times killed */
	int		t_wait;				/* time to wait for explosion */
	int		t_energy;			/* players energy count */
	int		t_damage;			/* allowable damage */
	char	t_id;				/* id number */
	char	t_x;
	char	t_y;				/* position */
	char	t_dir;				/* direction tank is facing */
	char	t_cmd;				/* players requested command */
	char	t_shellf;			/* number of shells fired */
	char	t_minef;			/* number of mines fired */
	char	t_heatf;			/* number of heats fired */
	char	t_safe;				/* period of time tank is safe */
	char	t_pri;				/* tank speed/priority */
	char	t_regpri;			/* damage regen priority */
	char	t_hbmiss;			/* Number of missed heart beats */
	char	t_hbxs;				/* Number of heart beats/period */
	char	t_name[MAXNM];		/* players name and host */
	char	t_msgb[MAXBUF];		/* reply message buffer */
	char	*t_msg;				/* pointer to reply message */
	struct tank	*t_next;		/* chain */
};
typedef struct tank tank_t;

#define TANKSAFE(tp)	((tp)->t_state & (TSAFE|TEXP))
#define TANKHID(tp)		((tp)->t_state & (TSAFE|TEXP|TCLOAK))


#if SERVER

/* EXTERNALS */
tank_t tanks[MAXTANK];
heat_t heats[MAXHEAT];
shell_t shells[MAXSHELL];
mine_t mines[MAXMINE];
expl_t expls[MAXEXPL];
pow_t pows[MAXPOW];
bon_t bons[MAXBON];
tank_t *Tfree, *Tvalid;
shell_t *Svalid, *Sfree;
mine_t *Mvalid, *Mfree;
heat_t *Hvalid, *Hfree;
expl_t *Evalid, *Efree;
pow_t *Pvalid, *Pfree;
bon_t *Bvalid, *Bfree;
char field[MAZE_XL][MAZE_YL];
void *fpts[MAZE_XL][MAZE_YL];
int Servstate;
int Totenergy;
int Bonfrm = 0;

int Cloakcost = 3;
int Shellcost = 1;
int Shelldmg = 10;
int Minecost = 5;
int Minedmg = 20;
int Heatcost = 15;
int Heatdmg = 10;
int Tenergy = 100;
int Energypt = 300;
int Tdamage = 100;
int Tmaxenergy = 300;
int Regenpri = 80;
int Regenamt = 3;

#else

extern tank_t tanks[MAXTANK];
extern heat_t heats[MAXHEAT];
extern shell_t shells[MAXSHELL];
extern mine_t mines[MAXMINE];
extern expl_t expls[MAXEXPL];
extern pow_t pows[MAXPOW];
extern bon_t bons[MAXBON];
extern tank_t *Tfree, *Tvalid;
extern shell_t *Svalid, *Sfree;
extern mine_t *Mvalid, *Mfree;
extern heat_t *Hvalid, *Hfree;
extern expl_t *Evalid, *Efree;
extern pow_t *Pvalid, *Pfree;
extern bon_t *Bvalid, *Bfree;
extern char field[MAZE_XL][MAZE_YL];
extern void *fpts[MAZE_XL][MAZE_YL];
extern int Servstate;
extern int Totenergy;
extern int Bonfrm;

extern int Cloakcost;
extern int Shellcost;
extern int Shelldmg;
extern int Minecost;
extern int Minedmg;
extern int Heatcost;
extern int Heatdmg;
extern int Tenergy;
extern int Energypt;
extern int Tdamage;
extern int Tmaxenergy;
extern int Regenpri;
extern int Regenamt;

#endif /* SERVER */

#ifndef NULL
#define NULL	0
#endif /* NULL */

extern char *sprintf();
extern long random();
