
#ifndef _FMA_H_
#define _FMA_H_

#ifndef __ENEMIES_H__
#include "enemies.h"
#endif

/*
typedef struct 
{
	short values[4];
}FOURSHORTS;
*/

//#define		OTHERPROC	3	/* states are no/yes/otherproc */

#define	NOTARGET	0
#define	TARGET		1
#define	NOUPDATE	2
#define	CAM_CUT		3

#define	CAM_VECTOR	1
//#define	CAM_FACING	2
//#define	CAM_CLOSE	3


#define	DEFAULTTURNRATE		128

// flags
#define	STOPMOVEFACE	(1<<0)

#define	NOFADE		0
#define	FADEUP		1
#define	FADEDOWN	2


//#define	TEXTWITHXA		1
//#define	TEXTWITHOUTXA	2

#define	TEXTWITHOUTXA		1
#define	TEXTWITHXAWAITING	2 
#define	TEXTWITHXAPLAYING	3

typedef	struct
{
	int		fade;			// flag to keep track of fade state
	int		breakFlag;		// flag for interuption state
	int		timeToJumpTo;	// time to skip to if interuptions are on
	int		holdFrameFlag;	// hold until key pressed
	int		planOn;			// are we displaying a plan?

	int		fadeStatus;
	int		fadeAmount;

	int		XAplaying;
	int		XAstarted;
	int		menuChoice;
	int		menuOn;
	int		menuOnTime;
	int		testSelection;
	int		breakOverideCount;
	int		playing;
//	int		planFadeOn;		// are we fading in to plan?
//	int		planFadeOff;	// are we fading from plan
//	int		planFadeOffTime;// when to start fading 
//	int		planFadeCount;
//	int		animSpeeds[20];
}FMASTATUS;

extern	FMASTATUS	fmaStatus;

typedef struct
{
	int		action;			// what we're going to do
	int		startTime;		// when it starts
	int		endTime;		// when it ends
	int		targetNum;		// use if given a vector for reference
	VECTOR	targetPos;		// use if given an object for reference
	int		targetType;		// 0 = use targetPos else use target num
	int		animChange;		// 0 = anim not changing else anim change required
	int		animSegment;	// new anim segment (if required}
	int		spare1;			// remove later if not used
	int		spare2;			// remove later if not used
}FMADATA;


typedef	struct
{
	FMADATA*		data;
	// need the actor/enemy structs here
	ACTOR*			actor;
	ANIM_ANIMATION*	anim;
	ENEMY*			enemy;
	VECTOR			pos;
	VECTOR			oldPos;
	int				startTime;
	int				timeLen;
	unsigned long	crc;	// 0=camera 1=general instructions
	int				tracking;
	int				trackNum;
	int				oldTrackNum;
	int				spare1;
	int				spare2;
	int				numCommands;
	int				flags;
}FMAOBJECT;

enum	// Colours for use with text
{
	WHITE,
	LBLUE,
	BLUE,
	YELLOW,
	GREEN,
	ORANGE,
	MAX_COLOURS
};


typedef	struct
{
	int			numObjects;
	FMAOBJECT*	object;
}FMACTRL;

// the reset for this needs to be done at game start/load
//extern	char	act1FmaStatus[MAX_ACT1_FMAS];
#define	FMA_PLAYED		1
#define FMA_NOTPLAYED	0


#define	FMA_ACT1	0
#define	FMA_ACT2	1
#define	FMA_ACT4	2

#define	A4_EGGROOM_SPECIAL_CASE	10
#define A4_GARDEN_SPECIAL_CASE_G	11
#define A4_GARDEN_SPECIAL_CASE_R	12
#define	A2_HOUSEXT_SPECIAL_CASE		13
#define A2_TOOLEXT_SPECIAL_CASE		14

#define	A4_KITCHEN_SPECIAL_CASE		15
#define A4_PIEBARN_SPECIAL_CASE		16

#define	A1_COOP1_SPECIAL_CASE		17

#define	A1_GARDEN_SPECIAL_CASE		18

enum	// These are all the fma's for act1
{
	SCENE1001,
	SCENE1002,
	SCENE1003,
	SCENE1004,
	SCENE1005,
	SCENE1006,
	SCENE1007,
	SCENE1008,	//new
	SCENE1010,
	SCENE1011,
	SCENE1012,
	SCENE1013,
	SCENE1014,
	SCENE1015,
	MAX_ACT1_FMAS
};

enum	// Act2 fma's
{
	// hut17
	SCENE2001,
	SCENE2002,
	SCENE2003,
	SCENE2004,
	SCENE2005,
	SCENE2006,
	SCENE2007,
	SCENE2008,
	SCENE2009,
	// workhut1
	SCENE2019,
	SCENE2020,
	SCENE2021,
	SCENE2022,
	SCENE2023,
	SCENE2024,
	SCENE2030,
	SCENE2031,
	SCENE2032,
	SCENE2033,
	SCENE2034,
	SCENE2035,
	//workhut2
	SCENE2040,
	SCENE2041,
	SCENE2042,
	SCENE2043,
	SCENE2044,
	SCENE2045,
	SCENE2046,
	SCENE2047,
	SCENE2048,
	SCENE2049,
	SCENE2050,
	SCENE2051,
	//workhut3
	SCENE2070,
	SCENE2071,
	SCENE2074,
	SCENE2075,
	SCENE2076,
	SCENE2077,
	SCENE2078,
	SCENE2079,
	// Rocky/Ginger interactions 
	SCENE8001,
	SCENE8002,
	SCENE8003,
	SCENE8004,
	SCENE8005,
	SCENE8006,
	SCENE8007,
	SCENE8008,
	SCENE8009,
	SCENE8010,
	SCENE8011,
	SCENE8012,
	SCENE8013,
	SCENE8014,
	SCENE8015,
	MAX_ACT2_FMAS
};

enum
{
	SCENE4001,
	SCENE4002,
	SCENE4003,
	SCENE4004,
	SCENE4005,
	SCENE4006,
	SCENE4007,
	SCENE4008,
	SCENE4009,
	SCENE4019,
	SCENE4020,
	SCENE4021,
	SCENE4022,
	SCENE4040,
	SCENE4041,
	SCENE4042,
	SCENE4043,
	SCENE4044,
	SCENE4045,
	SCENE4046,
	SCENE4047,
	SCENE4048,
	SCENE4049,
	SCENE4050,
	SCENE4051,
	SCENE4052,
	SCENE4053,
	SCENE4060,
	SCENE4061,
	SCENE4062,
	SCENE4063,
	SCENE4064,
	SCENE4065,
	SCENE4066,
	SCENE4067,
	SCENE4068,
	SCENE4069,
	SCENE4070,
	SCENE4071,
	SCENE4080,
	SCENE4081,
	SCENE4082,
	SCENE4083,
	SCENE4084,
	SCENE4085,
	SCENE4086,
	SCENE4087,
	SCENE4088,
	SCENE4089,
	SCENE4090,
	SCENE4091,
	SCENE4092,
	SCENE4093,

	SCENE4200,	// kitchen fma's
	SCENE4201,
	SCENE4202,
	SCENE4203,
	SCENE4210,
	SCENE4211,
	SCENE4212,
	SCENE4213,
	SCENE4214,
	SCENE4215,
	SCENE4216,
	SCENE4217,
	SCENE4218,
	SCENE4219,
	SCENE4220,
	SCENE4250,
	SCENE4251,
	SCENE4252,
	SCENE4253,
	SCENE4260,
	SCENE4261,
	SCENE4262,
	SCENE4263,
	SCENE4264,
	SCENE4265,
	SCENE4266,
	SCENE4267,
	SCENE4268,
	SCENE4269,
	SCENE4270,

	SCENE4400,	// tunnel fma's
	SCENE4401,
	SCENE4402,
	SCENE4403,
	SCENE4410,
	SCENE4411,
	SCENE4412,
	SCENE4413,
	SCENE4414,
	SCENE4415,
	SCENE4416,
	SCENE4417,
	SCENE4418,
	SCENE4419,
	SCENE4420,
	SCENE4450,
	SCENE4451,
	SCENE4452,
	SCENE4453,
	SCENE4460,
	SCENE4461,
	SCENE4462,
	SCENE4463,
	SCENE4464,
	SCENE4465,
	SCENE4466,
	SCENE4467,
	SCENE4468,
	SCENE4469,
	SCENE4470,

	SCENE4300,	// piebarn fma's
	SCENE4301,
	SCENE4302,
	SCENE4303,
	SCENE4310,
	SCENE4311,
	SCENE4312,
	SCENE4313,
	SCENE4314,
	SCENE4315,
	SCENE4316,
	SCENE4317,
	SCENE4318,
	SCENE4319,
	SCENE4320,
	MAX_ACT4_FMAS
};





typedef struct
{
	int		playedFlag;	// set to played/not yet been played
	int		playedTime;	// time which scene was played
}FMAPLAYEDSTATUS;

extern	FMAPLAYEDSTATUS	A1fmaStatus[MAX_ACT1_FMAS];
extern	FMAPLAYEDSTATUS	A2fmaStatus[MAX_ACT2_FMAS];
extern	FMAPLAYEDSTATUS	A4fmaStatus[MAX_ACT4_FMAS];

enum	// Commands for FMA objects
{
	CMD_MOVE_TO,
	CMD_ANIM,
//	CMD_TALK_TO,
	CMD_TARGET_OBJECT,
	CMD_TARGET_POS,
	CMD_CAM_CIRCLE,
	CMD_CAM_CUTTO,
	CMD_FACE_ANGLE,
	CMD_FACE_TO,
	CMD_JUMP_TO,
	MAX_ACTIONS
};

enum	// Commands for FMA in general
{
	CMD_FADE_UP,
	CMD_FADE_DOWN,
	CMD_BREAK_ON,
	CMD_BREAK_OFF,
	CMD_CONVERSATION,
	CMD_SOUND,
	CMD_HOLD,
	CMD_PLAN,
	CMD_EXIT,
	CMD_MUSIC,
	MAX_COMMAND_ACTIONS
};

enum	// used to match levels up
{
	A1_HUT17_FMA,
	A1_WORKHUT1_FMA,
	A2_HUT17_FMA,
	A2_WORKHUT1_FMA,
	A2_WORKHUT2_FMA,
	A2_WORKHUT3_FMA,
	A4_HUT17_FMA,
	A4_WORKHUT1_FMA,
	A4_WORKHUT2_FMA,
	A4_WORKHUT3_FMA,
	A4_WORKHUT4_FMA,
	A4_EGGHUT_FMA,
	A4_KITCHEN_FMA,
	A4_PIEBARN_FMA,
	A4_TUNNEL_FMA,
	A4_CONSTRUCT_FMA,
	A4_FLYMACHINE_FMA,
	TL_HUT17FMA_FMA,	// for test only
	TL_KITCHEN_FMA,
	TL_PIEBARN_FMA,
	TL_TUNNEL_FMA,
	TL_GARDEN_FMA,
	TL_WORKHUT1_FMA,
	TL_WORKHUT2_FMA,
	TL_WORKHUT3_FMA,
	TL_WORKHUT4_FMA,
	TL_COOP1_FMA,
	TL_COOP2_FMA,
	TL_HOUSEXT_FMA,
	TL_TOOLEXT_FMA,
	TL_LOUNGE_FMA,
	MAX_LEVELS_FMA
};


typedef struct
{
	//int 	numBlocks;
	//int		numLines;
	char*			block[3];
	char*			line[3] [6];
	int				startBlockTime[3];
	int				endBlockTime[3];
	int				endLineTime[3] [6];
	int				lineLen[3] [6];
	unsigned long	colour[3];
}TEXTCTRL;



#define BFF_FMAINFO_ID (('F'<<0) | ('M'<<8) | ('A'<<16) | (1<<24))

typedef struct tagFMAINFO
{
	unsigned long id;		// Standard BFF header
	unsigned long len;
	unsigned long crc;
	unsigned long numScripts;
	unsigned long scriptCrc[50];
	//unsigned long	*fmaStart[10];	// point to the start of each fma sequence
	FMACTRL	*fmaStart[50];
}FMAINFO;

extern 	FMAINFO*	fmaInfo;

/*
enum	// names for conversion
{
	OBJECT1,
	OBJECT2,
	MAX_OBJECTS
};
*/

void	FMAtestCycle(void);
void	FMAtest(void); 
int		getToken(char* out,char* in);
int		addMove(int	object,int cmdNum,char *string);

//void	loadFMA(void);
void	setupModels(void);

void	processCmd(FMAOBJECT* object,FMADATA* data);
void	processGeneralCmd(FMAOBJECT* object,FMADATA* data);
void	processMove(FMAOBJECT* object,FMADATA* data);

void	processJump(FMAOBJECT* object,FMADATA* data);

void	processAnim(FMAOBJECT* object,FMADATA* data);
void	processTargetObj(FMAOBJECT* object,FMADATA* data);
void	processCamCircle(FMAOBJECT* object,FMADATA* data);
void	processCamCutTo(FMAOBJECT* object,FMADATA* data);
void	processFaceAngle(FMAOBJECT* object,FMADATA* data);
void	proccessObjectAngles();
void	processFaceObject(FMAOBJECT* object,FMADATA* data);
void	processFadeDown(FMAOBJECT* object,FMADATA* data);
void	processFadeUp(FMAOBJECT* object,FMADATA* data);

void	processCamTarget(FMAOBJECT* object,FMADATA* data);

void	processMusic(FMAOBJECT* object,FMADATA* data);

void	drawOverlayPloys(void);
void	holdFade(void);
void	jumpToFrame(void);
void	processConversation(FMAOBJECT* object,FMADATA* data);
void	processSound(FMAOBJECT* object,FMADATA* data);
void	processPlan(FMAOBJECT* object,FMADATA* data);
void	processExit(FMAOBJECT* object,FMADATA* data);
void	textDisplay(void);
void	fmaLinkBFF( FMAINFO *work);
void	startFMA(char *name);
void	FMAsequenceHandeler(char *leafname);

void	FMAplayCheck(int	xState);


void	a1Hut17FmaChecks(int	xState);
void	a1Workhut1FmaChecks(int	xState);

void	a2Hut17FmaChecks(int	xState);

void	a2HousextFmaChecks(int	xState);
void	a2ToolextFmaChecks(int	xState);

void	a2Workhut1FmaChecks(int	xState);
void	a2Workhut2FmaChecks(int	xState);
void	a2Workhut3FmaChecks(int	xState);

void	a4Hut17FmaChecks(int	xState);
void	a4Workhut1FmaChecks(int	xState);
void	a4Workhut2FmaChecks(int	xState);
void	a4Workhut3FmaChecks(int	xState);
void	a4Workhut4FmaChecks(int	xState);

void	a4KitchenFmaChecks(int xState);
void	a4PiebarnFmaChecks(int xState);
void	a4TunnelFmaChecks(int xState);

void	specialMenuAct2(void);
void	specialMenuAct4(void);

void	FMAselectionTest(void);
void	FMAtestMenuCycle(void);
void	FMAtestMenuDraw(void);

void	resetFma(void);

#endif

