/*********************************************************************************************/
/*                                                                                           */
/* Main Game Code Header File                                                                */
/*                                                                                           */
/*********************************************************************************************/

#ifndef MAIN_H
#define MAIN_H

#define ANDREWH 0
#define GAV 1
#define JASON 2
#define RICHARD 3
#define NUM_CODERS 4

#ifdef __cplusplus
extern "C" {
#endif

// GAMEDEBUG DEFINES
#if defined(PSX_VERSION)
//#define PRINT_DRAWN_ROOMS
//#define PRINT_POLY_COUNT
#endif


#ifdef PSX_VERSION
#include "../spec_psx/stypes.h"
#else
#include "../specific/stypes.h"
#endif

#include "types.h"


#ifdef PSX_VERSION
#define wsprintf(format...)	sprintf(format)
#else	// frig it so we don't have to include windows.h
__declspec(dllimport) int __cdecl wsprintfA(char*,const char*,...);
#define wsprintf  wsprintfA
#endif

#ifdef PC_VERSION
#ifndef DONT_DEFINE_DBLOG
#ifdef DBLOG
void __cdecl DB_Log(char* format,...);
#define Log DB_Log
#else
#define Log 0&&
#endif
#endif
#endif

//enum {GAMEMODE_NOT_IN_GAME,GAMEMODE_IN_GAME,GAMEMODE_IN_DEMO};

/******************************* GLOBAL VARIABLES *************************************/

extern int				GnGameMode;
extern int 				level_complete;
extern int				chunky_flag;
extern int				flipeffect, fliptimer;

/* Cinema Stuff */
extern sint16			cine_loaded;
extern sint16			playing_full_cutscene;
extern int				cutscene_play;
/* Room information */
extern int				number_draw_rooms;
extern sint16			draw_rooms[];
extern sint16 			number_rooms;
extern ROOM_INFO 	  	*room;
extern sint16		  	*floor_data;

extern int level_items;

/* Flipped map stuff */
extern int flipmap[], flip_status;

/* CD trigger flags */
extern sint16 cd_flags[], cdtrack;

/* Object definitions and animation data variables (defined in draw.c) */
extern OBJECT_INFO 	objects[];
extern STATIC_INFO   static_objects[];
extern ANIM_STRUCT  *anims;
extern CHANGE_STRUCT	*changes;
extern RANGE_STRUCT *ranges;
extern sint16 	 	 **meshes;
extern sint16		  *frames;
extern sint32 	     *bones;
extern sint16		  *commands;

extern ITEM_INFO	  *items;

/* GetHeight sets trigger index for TestTriggers to use */
extern sint16		  *trigger_index;

/* Counts amount of time User hasnt pressed input */
extern	int			noinput_count;

/* Camera */
extern CAMERA_INFO 	camera;

/* Sound effects */
extern int number_sound_effects;
extern OBJECT_VECTOR *sound_effects;

/* Items.c */
extern	sint16		next_item_free;
extern	sint16		next_item_active;
extern	FX_INFO		*effects;
extern	sint16		next_fx_free;
extern	sint16		next_fx_active;

/* Inventory stuff */
extern  sint16 Inventory_Active;

/* Demo stuff */
extern	int		democount;
extern	uint32	*demoptr;
extern	int		demo_level;
extern	int	demo_loaded;

/* Health stuff */
extern	TEXTSTRING	*ammotext;

/* Dynamic lighting stuff */
extern int number_dynamics;
extern LIGHT_INFO dynamic[];
extern int sunset;

/* Sound stuff */
#define MAX_SAMPLES 					370					// Max number of sound fx types availabe

extern int sound_active;
extern	SAMPLE_INFO* sample_infos;
extern	sint16	sample_lut[];
extern	int		num_sample_infos;
extern	int		num_samples;                // Number of Samples

/******************************** FUNCTION PROTOTYPES ****************************************/

/* Machine specific function prototypes */
#ifdef PSX_VERSION
#include "../spec_psx/specific.h"
#else
#include "../specific/specific.h"
#endif

#ifdef GAMEDEBUG
extern	sint32 debug_ints[];
extern char message_str1[], message_str2[], message_str3[];
#endif

/************************************ MAIN.C ************************************************/

/* Need some variable in here so that C++ can see them correctly */
extern char exit_message[];

int		LetsDoSomething				(void);
sint32	StartGame					( int level_number,int type );
int 	InitialiseTitle				(void);
sint32	GameLoop					(int demo_mode);
sint32	TitlePage					(void);
sint32	GetRandomDraw				(void);
void	SeedRandomDraw				(sint32 seed);
sint32	GetRandomControl			(void);
void	SeedRandomControl			(sint32 seed);
sint32 DoDemoSequence( int level_number );

/* DRAW.C */
void AddDynamicLight(sint32 x, sint32 y, sint32 z, sint32 intensity, sint32 falloff);

/* CONTROL.C */
sint32	ControlPhase			(sint32 nframes, int demo_mode);

void		DummyControl			(sint16 item_number);


int ClipTarget(GAME_VECTOR *start, GAME_VECTOR *target);
void		AnimateItem				(ITEM_INFO *item);
int		GetChange				(ITEM_INFO *item, ANIM_STRUCT *anim);
void 		TranslateItem			(ITEM_INFO *item, sint32 x, sint32 y, sint32 z);

FLOOR_INFO *GetFloor				(sint32 x, sint32 y, sint32 z, sint16 *room_number);

sint32 	GetHeight				(FLOOR_INFO *floor, sint32 x, sint32 y, sint32 z);
sint32 	GetWaterHeight			(sint32 x, sint32 y, sint32 z, sint16 room_number);
sint32 	GetCeiling				(FLOOR_INFO *floor, sint32 x, sint32 y, sint32 z);
sint16   GetDoor				(FLOOR_INFO *floor);

void	TestTriggers			(sint16 *data, int heavy);
int 	TriggerActive			(ITEM_INFO *item);
void	TriggerCDTrack			( sint16 value, sint16 flags, sint16 type );
void	TriggerNormalCDTrack	( sint16 value, sint16 flags, sint16 type );

int		LOS					(GAME_VECTOR *start, GAME_VECTOR *target);
int		xLOS					(GAME_VECTOR *start, GAME_VECTOR *target);
int		zLOS					(GAME_VECTOR *start, GAME_VECTOR *target);
int		ObjectOnLOS			(GAME_VECTOR *start, GAME_VECTOR *target);
void		SmashItem			(sint16 item_number, int weapon_type); // currently in 'larafire'

void	FlipMap					(void);
void	RemoveRoomFlipItems		(ROOM_INFO *r);
void	AddRoomFlipItems		(ROOM_INFO *r);


/* OPTION.C */
sint32	GetOption				(void);
void		M_RoomVisited			(sint32 room_number); // OPTION.C

/* CAMERA.C */
void		InitialiseCamera		(void);
void		CalculateCamera		(void);
void		MoveCamera				(GAME_VECTOR *ideal, int speed);
void		ChaseCamera				(ITEM_INFO *item);
void		CombatCamera			(ITEM_INFO *item);
void 		LookCamera				(ITEM_INFO *item);
void 		ViewPosition			(ITEM_INFO *item, GAME_VECTOR *ideal );
void		FixedCamera				(void);

/* SETUP.C */
int			InitialiseLevel		(int level_number, int type);
void		InitialiseGameFlags	( void );
void 		InitialiseLevelFlags	(void);
void		InitialiseObjects	(void);
int 		InitialiseItems		(void);
void		InitialiseRooms		(void);

/* TITLE.C */
sint32	TitleSequence			(void);

/* DEMO.C */
sint32	StartDemo( int demo_level );
void	LoadLaraDemoPos( void );
void	SaveLaraDemoPos( void );
void	DemoGameLoop(void);
int	ControlPhaseDemo(sint32 nframes);
void	GetDemoInput( void );
sint32	StartSaveDemo( int level );
void	SaveDemoData( void );

/* EFFECTS.C */
void SoundEffects(void);

/* HAIR.C */
void InitialiseHair(void);
void HairControl( int in_cutscene );
void DrawHair(void);

/* HEALTH.C */
void DisplayModeInfo(char* szString);

/* SOUND.C */
void	SOUND_Init(void);
void	SOUND_SetMasterVolume(int nVolume);
int		SoundEffect(int nSFX,PHD_3DPOS *pPos,int flags);
void	StopSoundEffect(int nSFX);
void	SOUND_EndScene(void);
void	SOUND_Stop(void);

/* EFFECT2.c */

#include 	"..\game\effect2.h"

/* -------- Chris's Controller Stuff */

#ifdef PSX_VERSION

#define ANALOG_CONTROL

#ifdef ANALOG_CONTROL
#define VIBRATE(a, l, s, d, len)	SetupPadVibration(0, a, l, s, d, len)
#define RUMBLE(a, l, s, d, len)	SetupPadVibration(1, a, l, s, d, len)
#else
#define VIBRATE(a, l, s, d, len)
#define RUMBLE(a, l, s, d, len)
#endif

extern void SetupPadVibration(sint16, sint16, sint16, sint16, sint16, sint16);

/* -------- PC */

#else

#define VIBRATE(a, l, s, d, len)
#define RUMBLE(a, l, s, d, len)

#endif








#ifdef __cplusplus
}
#endif

#endif
