/*********************************************************************************************/
/*                                                                                           */
/* Machine Specific Code Header File                                                         */
/*                                                                                           */
/*********************************************************************************************/

/* This line allows "specific.h" to be the only file included in machine specific files */
#include "../game/anim.h"
#include "../game/game.h"

#ifndef SPECIFIC_H
#define SPECIFIC_H

#ifdef __cplusplus
extern "C" {
#endif

/***** defines *****/

#define LANGUAGE 0
//#define CD_LOAD

#define SECRET_BONUS
#define LOGFILE

#define GAMEDEBUG
//#define SCREEN_SHOT // allow screen shots to be taken

// want CD_LOAD and !GAMEDEBUG and !NOFMV
//#define DEMO     // alters behaviour for CD demo stuff
//#define NOFMV
//#define PCGAMER
//#define DUDE_DEMO

//#define USE_INVENTORY_TAG		// temporary!!! Shows text on title page
//#define NO_GYM


//#define CHEAT_ENABLE
//#define PLAY_ANY_LEVEL
#define ALWAYS_ENABLE_DOZY_CHEAT

// always required on PC; but defined so that PSX can try doing it too
#define FULL_SAVE
#ifdef GAMEDEBUG
	//#define ALWAYS_ENABLE_DOZY_CHEAT // Un-comment this to allow 'DOZY' cheat
	//#define SAVE_CINI
	//#define PLAY_ANY_LEVEL
	#define CHEAT_ENABLE
	//#define USE_PC_SAVE
	#define PLAY_CUTSCENES
	#define PLAY_FMV
	#define VERSION_EXPIRES
#else
	#define PLAY_FMV
	#define PLAY_CUTSCENES
	#define USE_PC_SAVE
   //#define NO_FLY_CHEAT		// Un-comment this to disable 'C' & 'D' key cheats. Even disables gameflow from enabling it! Over-ridden by defining ALWAYS_ENABLE_DOZY_CHEAT
#endif

// E3 demo; no GAMEDEBUG, disables CheatMode
//#define E3_DEMO
//#define AUTHORISATION_CHECK

//#define USE_CRASH_TELL
#ifdef USE_CRASH_TELL
#define	CRASH_TELL(f,l)	Log( LT_Info, "%s L:%d",f,l )
#else
#define CRASH_TELL(f,l)
#endif


#if defined(GAMEDEBUG)
typedef struct level_info {
	int hit_points;
	int health, health_used;
	int ammo, ammo_used;
} LEVEL_INFO;

extern LEVEL_INFO level;
#endif

/*** macros 'n' stuff ***/
#define rawkey(A) (keymap[A] & 0x80)
#define S_GOURAUD_COL(a,b,c,S) ((512-S)<<4)
#define PcPrint		Print      // TEMP
#define PsxPrint

/*** globals (all in a mess at the moment) ***/
extern int			wibble_light[WIBBLE_SIZE][32];

extern int			game_closedown;

extern SETUP 		game_setup;			// BIG dryness
extern uint8		water_palette[];
extern int 			wet;

extern int			mode_lock;

extern long*		handles;
extern char			cd_drive;

extern sint16*		aranges;
extern sint16*		mesh_base;

extern int			game_paused;
extern sint32		input;
extern int			iconfig;
extern int			joy_fire, joy_x, joy_y;
extern unsigned char keymap[];

extern int			hires_flag, game_hires, detail_level;
extern double		screen_sizer, game_sizer;

extern char*		kname[];
extern sint16		layout[2][15];
extern int			conflict[];

extern uint8		game_palette[];
extern int			sound_active;

extern uint8		GabPicturePalette[768];

//#ifdef LOGFILE
//#include <stdio.h>		// DRY!
//extern FILE*		logfile;
//#endif
#include <stdio.h>		// DRY!

extern	char*		malloc_buffer;
extern	int			script_malloc_size;
extern	int			malloc_size;
extern	int			malloc_free,malloc_used;
extern	char*		malloc_ptr;

enum game_malloc_types
	{
	TEMP_ALLOC,
	TEXTURE_PAGES,
	MESH_POINTERS,
	MESHES,
	ANIMS,
	STRUCTS,
	RANGES,
	COMMANDS,
	BONES,
	FRAMES,
	ROOM_TEXTURES,
	ROOM_INFOS,
	ROOM_MESH,
	ROOM_DOOR,
	ROOM_FLOOR,
	ROOM_LIGHTS,
	ROOM_STATIC_MESH_INFOS,
	FLOOR_DATA,
	ITEMS,
	CAMERAS,
	SOUND_FX,
	BOXES,
	OVERLAPS,
	GROUNDZONE,
	FLYZONE,
	ANIMATING_TEXTURE_RANGES,
	CINEMATIC_FRAMES,
	LOADDEMO_BUFFER,
	SAVEDEMO_BUFFER,
	CINEMATIC_EFFECTS,
	MUMMY_HEAD_TURN,
	EXTRA_DOOR_STUFF,
	EFFECTS_ARRAY,
	CREATURE_DATA,
	CREATURE_LOT,
	SAMPLEINFOS,
	SAMPLES,
	SAMPLEOFFSETS,
	ROLLINGBALL_STUFF,
	SKIDOO_STUFF,
	LOAD_PICCY_BUFFER,
	FMV_BUFFERS,
	POLYGON_BUFFERS,
	ORDER_TABLES,
	CLUTS,
	TEXTURE_INFOS,
	SPRITE_INFOS,
	NUM_MALLOC_TYPES
	};

/***** function prototypes ***/

/*** file.cpp ***/
int			S_LoadTitle				(void);
int 		S_LoadLevelFile			( char *fname, int level_number, int type);
void 		S_UnloadLevelFile		(void);
void		S_AdjustTexelCoordinates(void);
int			S_ReloadLevelGraphics	(int tPalDPQ,int tTPages);
int			S_LoadCinematic			(int level_number);
int			S_FrontEndCheck			(void* data,int size);
int			S_LoadGame				(void* data,int size,int slot);
int			S_SaveGame				(void* data,int size,int slot);
int			S_LoadGameFlow			( char *filename );

/*** frontend.cpp ***/
SG_COL 		S_COLOUR				(int R,int G,int B);
void		S_DrawScreenLine		(sint32 sx,sint32 sy,sint32 z,sint32 w,sint32 h,sint32 col,uint16 *grdptr,uint16 flags);
void		S_DrawLine( sint32 x1, sint32 y1, sint32 z, sint32 x2, sint32 y2, sint32 col, uint16 *grdptr, uint16 flags);
void		S_DrawScreenBox			(sint32 sx,sint32 sy,sint32 z,sint32 w,sint32 h,sint32 col,uint16 *grdptr,uint16 flags);
void		S_DrawScreenFBox		(sint32 sx,sint32 sy,sint32 z,sint32 w,sint32 h,sint32 col,uint16 *grdptr,uint16 flags);
void		S_SetBackgroundGamma	(sint16 gamma);
void		S_SetGamma				(sint16 gamma);
void		S_FadeInInventory		(int fade);
void		S_FadeOutInventory		(int fade);
void		S_FinishInventory		(void);
void		S_InitLoadDemo			(int levelnum);
void		S_InitSaveDemo			(void);
void		S_SaveDemoData			(int levelnum);
void		S_FadeToBlack			(void);
void		S_NoFade				(void);
void		S_LoadingScreen			(int level_number);
void		S_Wait					(int nframes, int anykey);
int		S_PlayFMV				(char *fname, int sequence);
int		S_IntroFMV				(char *movie1, char *movie2);

/*** init.cpp ***/
int			S_InitialiseSystem		(void);
void 		S_ExitSystem			(char* exit_message);
void		S_SeedRandom			(void);
void		*game_malloc			(int size,int type);	// not S_ ...
void		game_free				(int size,int type);
void		show_game_malloc_totals	(void);

/*** input.cpp ***/
int			S_UpdateInput			(void);

/*** main.cpp ***/
void		S_CopyScreenToBuffer	(void);
void		S_CopyBufferToScreen	(void);

/*** output.cpp ***/
#define SIPL_DONT_CLEAR_SCREEN 0
#define SIPL_CLEAR_SCREEN 1
void		S_InitialisePolyList	(int tClearScreen);
sint32		S_DumpScreen			(void);
void		S_ClearScreen			(void);
void		S_InitialiseScreen		(int type);
void		S_InsertRoom			(sint16* objptr, int outside);
void		S_InsertBackground		(sint16* objptr);
void		S_InsertInvBgnd(sint16 *objptr);
void		S_OutputPolyList		(void);
int			S_GetObjectBounds		(sint16* bptr);
void		S_PrintShadow			(sint16 size,sint16* bptr,ITEM_INFO* iptr,int unknown);
void		S_CalculateLight(sint32 x, sint32 y, sint32 z, sint16 room_number, ITEM_LIGHT *itemlight);
void		S_CalculateStaticLight  (sint16 adder);
void		S_CalculateStaticMeshLight(int x, int y, int z, int shade, int shadeB, ROOM_INFO *r);
void		S_LightRoom				(ROOM_INFO* r);
void		S_PrintObjectOutline	(sint16* bptr,sint16 color);
void		S_DrawHealthBar			(int percent);
void		S_DrawAirBar			(int percent);
void		S_InsertBackPolygon		(sint32 min_x,sint32 min_y,sint32 max_x,sint32 max_y,int colour);
void		S_AnimateTextures		(int nframes);
void		S_DrawLighteningSegment	(sint32 x1,sint32 y1,sint32 z1,sint32 x2,sint32 y2,sint32 z2,sint32 width);
void		S_SetupBelowWater		(int underwater);
void		S_SetupAboveWater		(int underwater);
void		S_DisplayPicture		(char* filename,int tRemapToGamePalette);
void		S_DontDisplayPicture	(void);
void		S_ConvertPicture		(void);
void		S_DrawSparks(void);
void		S_CalculateLightLara(sint32 x, sint32 y, sint32 z, sint16 room_number);
void		TriggerDynamic(long x, long y, long z,long falloff, long r, long g, long b);
void		ClearDynamics();


/*** smain.cpp ***/
void		S_SaveSettings			(void);
void		S_LoadSettings			(void);

/*** specific.cpp ***/
#define		ERR_SOUND_NOT_ENABLED	(-3)
#define		ERR_SOUND_FAILED		(-2)
#define		ERR_SOUND_NO_FREE_SLOTS	(-1)

sint32		S_SoundPlaySample(int nSample,uint16 wVol,int nPitch,sint16 wPan);
sint32		S_SoundPlaySampleLooped(int nSample,uint16 wVol,int nPitch,sint16 wPan);
sint32		S_SoundSampleIsPlaying(sint32 handle);
void 		S_SoundStopAllSamples(void);
void	 	S_SoundStopSample(sint32 handle);
void		S_SoundSetPanAndVolume(sint32 handle, sint16 wPan, uint16 newvol);
void		S_SoundSetPitch(sint32 handle,int nPitch);
void		S_SoundSetMasterVolume(int nVolume);

void		S_CDPlay				(sint16 track,int mode);
void		S_CDLoop				(void);
void		S_CDStop				(void);
void		S_CDPause				(void);
void		S_CDRestart				(void);
int		S_StartSyncedAudio		(int num);
void		S_UpdateSyncedAudio		(void);
void		S_CDVolume				(int volume);
int		S_CDGetLoc				(void);

void SetCutsceneTrack( int track );
void SetCutscene( int cut );
void SetCutsceneAngle( int angle );


/***** naughty PC specific stuff *****/
#ifdef PC_VERSION

/*** output.cpp ***/
void S_SavePicture(void);

/*** display.cpp ***/
void 		TempVideoAdjust			(int hires,double sizer);

/*** smain.cpp ***/
void		CheckCheatMode			();

/*** time.cpp ***/
void		TIME_Reset();

#endif


#ifdef __cplusplus
}
#endif

#endif	// SPECIFIC_H
