
#ifndef __LIGHTS_H__
#define __LIGHTS_H__


// ENUMS ---------------------------------------------------------------------------------------------

enum EXLIGHT_ANIM_TYPE
{
	EXLIGHT_ANIM_NONE,
	EXLIGHT_ANIM_SWITCH_TO,
	EXLIGHT_ANIM_SWITCH_FROM,
	EXLIGHT_ANIM_RANDOM,
	EXLIGHT_ANIM_PULSE_TO,
	EXLIGHT_ANIM_PULSE_FROM,

	EXLIGHT_NUM_ANIMS
};


// STRUCTS ---------------------------------------------------------------------------------------------

typedef struct _EXLIGHT_RGB
{
	ULONG	r, g, b;

} EXLIGHT_RGB;
/*
typedef struct RGBCD
{
	unsigned char b;
	unsigned char g;
	unsigned char r;
} RGBCD;
*/

typedef struct
{
	int x;
	int y;
	int z;
}TPOINT;
typedef struct
{
	int x;
	int y;
	int z;
}TVECTOR;

// Shadow & character shading are one & the same, in 
#define LIGHTFLAG_BOX		1
#define LIGHTFLAG_SHADOW	2
#define LIGHTFLAG_SHADE		4
#define LIGHTFLAG_DISABLED	8
#define LIGHTFLAG_MESHSWAP	16
#define LIGHTFLAG_CONE		32
#define LIGHTFLAG_ALERT		64
#define LIGHTFLAG_MOBILE	128

typedef struct
{
	int vx;
	int vy;
	int vz;
	int wait;
}LIGHT_MOVEPOINT;
typedef struct {
	int n_points;

	int waitTimer;
	int accel;
	int speed;
	int maxspeed;
	int point;

	LIGHT_MOVEPOINT *points;	// convert from integer to pointer postload, remember

}LIGHT_MOBILESTR;

typedef struct _EXLIGHT_TYPE
{
	TPOINT			pos;
	RGBCD			col, basecol1, basecol2;
//	ULONG			range;
	int				range;	// not unsigned, coz we want to check against -ve it

	ULONG			type:8;
	ULONG			speed:8;
	ULONG			offset:8;
	ULONG			infinite:1;
	ULONG			pad:7;

	struct _EXLIGHT_TYPE	*next;

	char			flags;
	char			n_meshswaps;
	char			shadow_darkness;
	char			spot_size;	// normally 1/4 of distance (as a 4096'd), but if we use 512 instead, then the default = 16
	int				tag;

	TPOINT			boxsize;


	int				*meshswaps;	// which ends up being either an array of landscape instances, or a pointer to a light_mobilestr

} EXLIGHT_TYPE;


typedef struct _EXLIGHT_DATA_TYPE
{
	EXLIGHT_RGB		ambient;

	EXLIGHT_TYPE	root;	// dummy root for light linked list.

//	TPOINT			Drej_Light[3];
//	TVECTOR			Drej_LightVel[3];

	TextureType		*lightsrc;
	TextureType		*shadow;


	char			alertcheck;
	char			dummy[3];

	int				shadow_width;

} EXLIGHT_DATA_TYPE;

extern EXLIGHT_TYPE *triggering_light;

// FUNCTIONS ---------------------------------------------------------------------------------------------

// SL: basic functions:
void EXLIGHT_Initialise(void);
void EXLIGHT_PostBFF(void);
void EXLIGHT_Shutdown(void);
void EXLIGHT_Update(void);

// SL: other stuff:
void EXLIGHT_DebugDrawLights(void);
EXLIGHT_TYPE *EXLIGHT_AddLight(void);
void EXLIGHT_MergeLights(EXLIGHT_TYPE *list);

// note - doesn't FREE it, just removes it from the list
void EXLIGHT_RemoveLight(EXLIGHT_TYPE *light);


// SL: actor lighting...
void EXLIGHT_SetupActorLights(ACTOR *actor);
void EXLIGHT_SetupActorLightsAlert(ACTOR *actor);
void EXLIGHT_SetupDefaultActorLights(void);

// Full on Scott Lambster shadows
void EXLIGHT_DrawShadow(ACTOR *actor);

// Stick a simple ellipse shadow under the actor. Front distance, Back distance, Width. 200,-200,200 gives an oval 0 0 200 gives round.
void EXLIGHT_SimpleShadow(ACTOR *actor, int f, int b, int w);

// CPW: my light stuff
EXLIGHT_TYPE *EXLIGHT_GetNearest(VECTOR *pPos);

// EXTERNS ---------------------------------------------------------------------------------------------

extern int EXLIGHT_shadow_width;	// 80

// SL: the light system struct
extern EXLIGHT_DATA_TYPE	*EXLIGHT_Data;

EXLIGHT_TYPE *EXLIGHT_FindLight(int tag);
void EXLIGHT_AlertLight(EXLIGHT_TYPE *light, int enable);
void EXLIGHT_EnableLight(EXLIGHT_TYPE *light, int enable);
int EXLIGHT_IsLightEnabled(EXLIGHT_TYPE *light);
void EXLIGHT_SetAmbient(unsigned int bgr);


#endif

