/******************************************************************************************
	CRTEST PS   (c) 1999-2001 ISL

	fireworks.h:			Fireworks subgame code
******************************************************************************************/


#ifndef __FIREWORKS_H__
#define __FIREWORKS_H__

#include "global.h"
#include "collide.h"
#include "loadsnd.h"

#define	FIREWORKS_MOVESTATE_UP		1
#define	FIREWORKS_MOVESTATE_DOWN	2
#define	FIREWORKS_MOVESTATE_LEFT	4
#define	FIREWORKS_MOVESTATE_RIGHT	8


#define FW_NUM_DRONES  4
//#define FW_NUM_ROCKETS 6
//#define FW_NUM_FLAPS   1

enum
{
	FW_STATE_FADEIN,
	FW_STATE_RUNNING,
	FW_STATE_INTRO,
	FW_STATE_BRONZE_SUCCESS,
	FW_STATE_SILVER_SUCCESS,
	FW_STATE_GOLD_SUCCESS,

	FW_STATE_FAIL,
	FW_STATE_FINISH,
	FW_STATE_FADEOUT,
};



enum
{
	FW_DRONE_INACTIVE,
	FW_DRONE_JUMPINGON,
	FW_DRONE_JUMPINGOFF,
	FW_DRONE_ONDEVICE,
	FW_DRONE_LAUNCHING,
	FW_DRONE_FLYING,
	FW_DRONE_SPLATTING,
	FW_DRONE_BOUNCING,
	FW_DRONE_CRASHING,
	FW_DRONE_LANDING,
	FW_DRONE_RUNAWAY,
	FW_DRONE_STUMBLEAWAY,
};


enum 
{
	FW_FLAP_DOOR,
	FW_FLAP_WINDOW_LEFT,
	FW_FLAP_WINDOW_RIGHT,
	FW_FLAP_ROOF_RIGHT,
	FW_FLAP_ROOF_LEFT,
	FW_FLAP_TYRE,
	FW_NUM_FLAPS,
};

enum
{
	FW_FLAP_STATE_OPEN,
	FW_FLAP_STATE_CLOSED,
};


enum
{
	FW_COLL_NONE,
	FW_COLL_SPLAT,
	FW_COLL_BOUNCE,
	FW_COLL_WINDOW,
};

typedef struct
{
	int state;
	VECTOR vel;
	int	yRotAim;
	int xRotAim;

	int flap;
	int rocket;

	VECTOR target;

	COLLDATA collision;

	PSIMODEL *model;
	ACTOR *actor;


	PSIMODEL *backPackModel;
	ACTOR *backPackActor;

	int weeSample;

}fireDrone;


//typedef struct
//{
//	int drone;
//	PSIMODEL *model;
//	ACTOR *actor;
//}fireRockets;



typedef struct
{
	int throughCount;
	int state;
	int type;
	VECTOR pos;

	long count;

	PSIMODEL *model;
	ACTOR *actor;

}fireFlap;

#define FW_NUMSPARKS 40
#define FW_SPARK_NUM_FRAMES 3

typedef struct
{
	VECTOR pos[FW_NUMSPARKS];
	VECTOR vel[FW_NUMSPARKS];

	int lifetime[FW_NUMSPARKS];
	unsigned long colour[FW_NUMSPARKS];
	TextureType *texture[FW_SPARK_NUM_FRAMES];				

	short scale[FW_NUMSPARKS];
	short newSparkNum;
	short oldestSpark;
	short active;
}FIREWORK_SPARKS;




typedef struct
{
	int	state;

	int camXRotSpeed, camYRotSpeed, camXRot, camYRot;

	fireDrone drones[FW_NUM_DRONES];
	fireFlap  flaps[FW_NUM_FLAPS];
	
	
//	int nextRocket;

	short drone;
	short nextDrone;
	short flyingDrone;
	short lastFlap;

	PSIMODEL *troughModel;
	ACTOR *troughActor;
	

	FIREWORK_SPARKS sparks;

	long frameCount;
	long cameraCount;
	int countdown;
	int numChickensSaved;


	SfxSampleType *pSamples[NUM_FIREWORKS_SAMPLES];
	int windChannel;
	int flashCount;

	TextureType *wick;
	TextureType *flash;

//	ACTOR * flyActor, * walkOffActors[5];
//	PSIMODEL * chickenModels[3];
}FIREWORK_DATA;



void fwMoveVertTowardsCamera2D(VERT *vert, int dist);
void fireworksStart();
void fireworksDronesUpdate();
void fireworksDraw(void);
void fireworksEnd(void);
void fireworksControls(void);
void fwLaunchDrone();
void fireworksUpdateCamera();
//int getWorldPosOfBone(ACTOR* actor, char *bone, VECTOR *res);
void fireworksFlapsUpdate();
int fireworksCollision(fireDrone *drone);
//void fireWorksDrawSky();
void fireworksDrawEffects();
void fireworksUpdateEffects();
void fireworksAddEffect(fireDrone *drone);
//void fwPrintChickenCount();
void fwDrawBronzeSuccess();
void fwDrawSilverSuccess();
void fwDrawGoldSuccess();

void fwDrawIntro();
void fwDrawFail();
void fwMakeDroneMoveAway();
void fwMoveActorTowardsCamera(ACTOR* actor, int dist);
int fwFindWhichFlap(VECTOR *pos);
void fireworksFree();
void fireworksReset();
void fireworksRestart();
void fireworksExit();

void fireworksUpdateAnims();


#endif	