/**********************************************************************

	Title :			Ship Types Header File
	Filename :		ship.h
	Author :		Thomas Szirtes
	Revision :		1.0

	Notes :			Contains structures and definition relating to ship
					objects

	Copyright :		(C) SEGA Europe 1998

  **********************************************************************/

#ifndef	_SHIP_H_INC
#define _SHIP_H_INC

#include	<ninja.h>
#include	"ftypes.h"

/*
 *		DEFINE SCRIPTING MACRO LANGUAGE
 */
#define	Script				Uint8

#define cmdGOTO			0x01
#define cmdPOSITION		0x02
#define cmdWAITFOR		0x03
#define cmdWAITUNTIL	0x04
#define cmdORBIT		0x05
#define cmdLAND			0x06
#define cmdFOLLOW		0x07
#define cmdEND			0x00
#define cmdHEADING		0x08
#define cmdALTITUDE		0x09
#define cmdLAUNCH		0x0A

#define szeCOORD		0x02
#define szeVECTOR		0x0C
#define szeBYTE			0x01
#define szeTIME			0x01

#define SCRIPT_ERROR	0xffff

#define	DONE			0
#define LONGtoBYTE(x)	((Uint8)(x)),((Uint8)(x>>8)),((Uint8)(x>>16)),((Uint8)(x>>24))
#define	SCRIPT(x)		Script x[]=
#define START			{ 
#define	END				cmdEND};
#define POSITION(p)		cmdPOSITION,p,
#define GOTO(p)			cmdGOTO,p,
#define WAITFOR(t)		cmdWAITFOR,t,
#define WAITUNTIL(t)	cmdWAITUNTIL,t,
#define ORBIT			cmdORBIT,
#define LAND			cmdLAND,
#define LAUNCH			cmdLAUNCH,
#define FOLLOW(t)		cmdFOLLOW,t,
#define HEADING(t)		cmdHEADING,t,
#define ALTITUDE(t)		cmdALTITUDE,t,
#define MAP(i,j)		i,j
#define ANGLE(t)		(t>>1)
#define TAG(t)			t
#define TIME(t)			t



/*
 *		General Ship Flags
 */

#define SHIP_FLAG_USER                  0x0001
#define SHIP_FLAG_VIEW                  0x0002
#define SHIP_FLAG_SHIELDDOWN			0x0004
#define SHIP_FLAG_DISABLE               0x0008
#define SHIP_FLAG_HIT                   0x0010


/*
 *		Ship AI types	-	 not all implemented 
 */
/* TYPE_DISTANCE	Ship only to be viewed in distance does not interact with scenery */
/* TYPE_SCRIPT		Ship follows script - limited interaction with user */
/* TYPE_INDEPENDANT Ship is free to react with scenery and other ships (limited) */
/* TYPE_INERT		Ship does not move - but reacts to collisions */

#define		SHIPAI_TYPE_SCRIPT			0x0001
#define		SHIPAI_TYPE_INDEPENDANT		0x0002
#define		SHIPAI_TYPE_DISTANCE		0x0003
#define		SHIPAI_TYPE_INERT			0x0004


/*
 *		SHIP Modes 
 */

#define		SHIPAI_MODE_STOP			0x0000
#define		SHIPAI_MODE_TRAVEL			0x0001
#define		SHIPAI_MODE_WAIT			0x0002
#define		SHIPAI_MODE_LAND			0x0003
#define		SHIPAI_MODE_LAUNCH			0x0004
#define		SHIPAI_MODE_FOLLOW			0x0005
#define		SHIPAI_MODE_TRANSPORT		0x0006


/*
 *		Structure Definitions
 */

/*------------------------------------------------------------ 
 * SHIP PHYSICS ATTRIBUTES 
 * This contains information on how the ship physics  
 *------------------------------------------------------------*/
typedef struct {
	Float		max_ship_velocity;			/* maximum ship velocity */
	Float		min_ship_velocity;			/* minimum ship velocity */
	Float		max_ship_accel;				/* maximum ship acceleration */
	Float		max_ship_deaccel;			/* maximum ship deacceleration */
	Float		max_ship_yaw;				/* maximum ship yaw */
	Float		max_ship_pitch;				/* maximum ship pitch */
	Float		response_yaw;				/* responsiveness yaw */
	Float		response_pitch;				/* responsiveness pitch */
} ATTRSHIP;


/*------------------------------------------------------------ 
 * MOVE OBJECT 
 * This is a generic object that flys ship like around. 
 * This could be any space ship or the user - this means 
 * I can generalize the movement parts of my code = less work 
 *------------------------------------------------------------*/
typedef struct
{
	NJS_POINT3	position;				/* current position */
	NJS_POINT3	projected;				/* projected position */
	NJS_VECTOR	direction;				/* current direction */
	NJS_VECTOR	olddir;					/* old direction */

	NJS_VECTOR	velocity;				/* current forward velocity */
	Float		yaw;					/* current yaw */
	Float		pitch;					/* current pitch */
	Float		velmag;					/* magnitude of velocity */

	Float		vel_yaw;				/* current yaw */
	Float		vel_pitch;				/* current yaw */

	Float		acceleration;			/* current forward acceleration applied */
	Float		torque_yaw;				/* amount of yaw being applied */
	Float		torque_pitch;			/* amount of pitch being applied */
	
	Float		roll;					/* current roll - generated */
} MOVESHIP;


/*------------------------------------------------------------ 
 * SHIP ARTIFICAL INTELLEGENCE 
 *  contains data for concept,navigator and driver AI layers
 *------------------------------------------------------------*/
typedef struct {
	Uint16		type;				/* define type					(global) */
	
	GRIDPOS		destination;		/* destination grid position	(concept -> navigator) */

	Angle		heading;			/* desired heading				(navigator -> driver) */
	Sint16		altitude;			/* desired altitude				(navigator -> driver) */
	Sint16		speed;				/* desired speed				(navigator -> driver) */

	Uint16		mode;				/* current mode					(concept) */
	Uint16		timI;				/* internal timer				(internal communication) */
	Uint16		timU;				/* user timer					(internal communication) */

	struct {
		Uint16		index;			/* script flags */
		Script		*data;			/* script */
	} script;
} SHIPAI;


/*------------------------------------------------------------
 * SHIP 
 * This contains general information on ship 
 *------------------------------------------------------------*/
typedef struct {
	Uint16		type;				/* Ship type identifier */
	Uint16		state;				/* Ship state indentifier */
	Uint16		shield;				/* Ship shield count */
	Uint16		shield_anim;		/* Ship anim */
	Uint16		weapon;				/* Ship weapon count */
	Uint8		reload;				/* Ship reload time */
	Uint8		fire_count;			/* Ship fire counter */
	Uint16		flags;				/* Ship flags */
	Uint16		misc_count;
	Float		exhaust;			/* heh why not? */
	Float		radius;				/* radius for sheild */
	GRIDPOS		current;			/* current grid position */
	SHIPAI		ai;					/* Ship artifical intellegence */
	MOVESHIP	move;				/* information on ship movement	 (global) */
	ATTRSHIP	*attr;				/* attributes of ship handling	 (global) */
	NJS_OBJECT	*obj;				/* pointer to ship object data */
	NJS_TEXLIST	*tex;				/* pointer to ship texture list */
	NJS_OBJECT	*loobj;				/* pointer to ship low detail object data */
	NJS_TEXLIST	*lotex;				/* pointer to ship low detail texture list */
	Uint8		next_ship;			/* used for display optomization */
} SHIP;


/*------------------------------------------------------------
 * FIRE 
 * This data on lazer fire 
 *------------------------------------------------------------*/
typedef	struct {
	NJS_POINT3	pos;				/* position of fire */
	NJS_VECTOR	dir;				/* direction of fire */
	Uint16		life;				/* current life time of fire */
	Uint16		flag;				/* flags */
} FIRE;

#endif