/****************************************************************************
*
* COLLIDE.H
*
* PROGRAMMER : Chris
*    VERSION : 00.00
*    CREATED : 01/06/98
*   MODIFIED : 01/06/98
*       TABS : 5
*
* DESCRIPTION
*	Header file for COLLIDE.C
*
*****************************************************************************/

#ifndef _COLLIDE_H
#define _COLLIDE_H

/*---------------------------------------------------------------------------
 *	Import Headers
\*--------------------------------------------------------------------------*/

//PHD_3DPOS
//PHD_ANGLE
//PHD_VECTOR

#ifdef PSX_VERSION
#include "../spec_psx/typedefs.h"
#include "../spec_psx/3d_gen.h"
#else
//#include "..\specific\stypes.h"
#endif

#include "items.h"
#include "room.h"

/*---------------------------------------------------------------------------
 *	Constants
\*--------------------------------------------------------------------------*/

#define DRAWN		0x20		// For clearing bodies.
#define SWONESHOT	0x40		// For switches.
#define ATONESHOT	0x80		// For anti-triggers.
#define ONESHOT	0x100
#define CODE_BITS	0x3e00
#define REVERSE	0x4000
#define NOT_VISIBLE	ONESHOT
#define KILLED_ITEM	(-0x8000)
#define CLEAR_BODY	KILLED_ITEM

#define MAX_CD_TRACKS 128
#define MAX_SECRETS 16

#define MAX_DYNAMICS 10

#define NO_BAD_POS (-NO_HEIGHT)
#define NO_BAD_NEG 	NO_HEIGHT

enum	headings {
	NORTH,
	EAST,
	SOUTH,
	WEST
};

enum height_types {
	WALL,
	SMALL_SLOPE,
	BIG_SLOPE,
	DIAGONAL,
	SPLIT_TRI
};

#define COLL_NONE		0
#define COLL_FRONT		1	// Solid Wall in Front
#define COLL_LEFT		2	// Solid Wall to LHS
#define COLL_RIGHT		4	// Solid Wall to RHS
#define COLL_TOP		8	// MidPoint Ceiling
#define COLL_TOPFRONT	16	// MidPoint at Front
#define COLL_CLAMP		32	// MidPoint Ceiling and Floor BAD!!!

/*---------------------------------------------------------------------------
 *	Type Definitions
\*--------------------------------------------------------------------------*/

typedef struct {
	sint32 mid_floor;			// relative floor and ceiling heights at midpoint
	sint32 mid_ceiling;
	sint32 mid_type;
	sint32 front_floor;			// relative floor and ceiling heights at front
	sint32 front_ceiling;
	sint32 front_type;
	sint32 left_floor;			// relative floor and ceiling heights at front/left side
	sint32 left_ceiling;
	sint32 left_type;
	sint32 right_floor;			// relative floor and ceiling heights at front/right side
	sint32 right_ceiling;
	sint32 right_type;
	sint32 left_floor2;			// relative floor and ceiling heights at front/left side
	sint32 left_ceiling2;
	sint32 left_type2;
	sint32 right_floor2;		// relative floor and ceiling heights at front/right side
	sint32 right_ceiling2;
	sint32 right_type2;
	sint32 radius;				// INPUT Collision Radius...
	sint32 bad_pos,bad_neg;		// INPUT Relative Heights We want to Collide against...
	sint32 bad_ceiling;			// INPUT Relative Bad Ceiling Height...
	PHD_VECTOR shift;			// Shift/Push Values..
	PHD_VECTOR old;			// INPUT Old Positions
	sint16 old_anim_state;		// INPUT old animation
	sint16 old_anim_number;
	sint16 old_frame_number;
	sint16 facing;				// INPUT Angle we are Moving...
	sint16 quadrant;			// Quadrant we are moving ( Not necessarily facing! )
	sint16 coll_type;			// Type of Collision
	sint16 *trigger;			// Trigger info index
	signed char tilt_x, tilt_z;	// Type of Tilt of Floor
	char	hit_by_baddie;           // Flag to indicate Lara has been hit by a Baddie
	char hit_static;			// Flag to indicate Lara has collided with a Static object
	uint16 slopes_are_walls:2;	// Treat big slopesUp as walls
	uint16 slopes_are_pits:1;	// Treat big slopesDown as pits
	uint16 lava_is_pit:1;		// Treat Lava as Bad place to go onto
	uint16 enable_baddie_push:1;	// Baddies Can push Lara
	uint16 enable_spaz:1;		// Spaz animations are enabled
	uint16 hit_ceiling:1;		// Has Lara hit ceiling? (For up jump only).
} COLL_INFO;

/*---------------------------------------------------------------------------
 *	Prototypes
\*--------------------------------------------------------------------------*/

extern int height_type,tiltxoff,tiltyoff;

extern void GetCollisionInfo(COLL_INFO *info, sint32 xpos, sint32 ypos, sint32 zpos, sint16 room_number, sint32 objheight);
extern void GetNearByRooms(sint32 x, sint32 y, sint32 z, sint32 r, sint32 h, sint16 room_number);
extern void GetNewRoom(sint32 x, sint32 y, sint32 z, sint16 room_number);
extern sint16 GetTiltType(FLOOR_INFO *floor, sint32 x, sint32 y, sint32 z);

extern sint32 FindGridShift(sint32 src, sint32 dst);
extern sint32 FindGridShift2(sint32 src, sint32 dst);
extern void ShiftItem(ITEM_INFO *item, COLL_INFO *coll);
extern int Move3DPosTo3DPos(PHD_3DPOS *srcpos, PHD_3DPOS *destpos, int velocity, PHD_ANGLE angadd);

extern int CollideStaticObjects(COLL_INFO *coll, sint32 x, sint32 y, sint32 z, sint16 room_number, sint32 hite);
extern void CreatureCollision(sint16 item_num, ITEM_INFO *laraitem, COLL_INFO *coll);
extern void ObjectCollision(sint16 item_num, ITEM_INFO *laraitem, COLL_INFO *coll);
extern void TrapCollision(sint16 item_num, ITEM_INFO *laraitem, COLL_INFO *coll);
extern void DoorCollision(sint16 item_num, ITEM_INFO *laraitem, COLL_INFO *coll);
extern void AIPickupCollision(sint16 item_num, ITEM_INFO *laraitem, COLL_INFO *coll);

extern void UpdateLaraRoom(ITEM_INFO *item, int height);
extern void LaraBaddieCollision(ITEM_INFO *litem, COLL_INFO *coll);
extern void ItemPushLara(ITEM_INFO *item, ITEM_INFO *laraitem, COLL_INFO *coll, int spazon, int bigpush);
extern int TestLaraPosition(sint16 *bounds, ITEM_INFO *item, ITEM_INFO *laraitem);
extern void AlignLaraPosition(PHD_VECTOR *vec, ITEM_INFO *item, ITEM_INFO *laraitem);
extern int MoveLaraPosition(PHD_VECTOR *vec, ITEM_INFO *item, ITEM_INFO *laraitem);

extern int TestBoundsCollide(ITEM_INFO *item, ITEM_INFO *laraitem, sint32 radius);
extern int TestSpriteCollide(ITEM_INFO *item, ITEM_INFO *laraitem, sint32 radius);

extern void EffectSpaz(ITEM_INFO *laraitem, COLL_INFO *coll);

#endif
