#include "game.h"
#include "invdata.h"
/************** Temporary **************/
//extern char GF_filenames[][64];
//extern sint16 GF_frontend[];
//extern sint16 GF_level1[];
/************** Temporary **************/

void SetCutsceneTrack( int track );
/****************** Globals ******************/
uint32	GF_ScriptVersion = 0;
sint32	GF_LaraStartAnim = 0;
sint16	GF_SunsetEnabled = 0;
sint16	GF_DeadlyWater = 0;
sint16	GF_NoFloor = 0;
sint16	GF_RemoveWeapons = 0;
sint16	GF_RemoveAmmo = 0;
sint16	GF_NumSecrets = 3;
sint16	GF_CDtracks[16] = {2};
uint16	GF_Cutscene_Orientation = 0x4000;
char	GF_Kill2Complete = 0;
char	GF_StartGame = 0;
char	GF_Playing_Story = 0;
char	GF_Add2InvItems[ADDINV_NUMBEROF];
char	GF_SecretInvItems[ADDINV_NUMBEROF];
#ifdef PSX_VERSION
sint16	GF_LoadingPic = -1;
#endif
/****************** Locals *******************/
sint32	GF_InterpretSequence( sint16 *ptr, int type, int seq_type );

#ifdef GAMEDEBUG
	#ifdef PC_VERSION
		#define Logit(s) Log(LT_Info,s)
		#define Logit2(s,a) Log(LT_Info,s,a);
	#else
		#define Logit(args...) printf(args);printf("\n")
		#define Logit2(args...) printf(args);printf("\n")
	#endif
#else
	#ifdef PC_VERSION
		#define Logit(s)
		#define Logit2(s,a)
	#else
		#define Logit(args...)
		#define Logit2(args...)
	#endif
#endif

/*********************************************************
		Load in GameFlow Data and Initialise
*********************************************************/
int		GF_LoadScriptFile(char *fname)
{
	GF_SunsetEnabled = 0;
	if (!S_LoadGameFlow( fname ) )
		return(0);

#ifdef DEMOVERSION
	if (!gameflow.demoversion)
		while(1);
#endif

#ifdef ALWAYS_ENABLE_DOZY_CHEAT
	gameflow.dozy_cheat_enabled = 1;
#endif
#ifdef CHEAT_ENABLE
	gameflow.cheat_enable = 1;
#endif
#ifdef PLAY_ANY_LEVEL
	gameflow.play_any_level = 1;
#endif
#ifdef NO_GYM
	gameflow.gym_enabled = 0;
#endif
	// TODO: Make this part of loaded in data
	gameflow.stats_track = 41;
//	gameflow.firstOption = STARTDEMO|2;//EXIT_TO_TITLE;	// First option to do (usually EXIT_TO_TITLE)

	/*   Initialise Inventory Strings */
	icompass_option.itemText = GF_GameStrings[GT_STOPWATCH];
	igun_option.itemText = GF_GameStrings[GT_PISTOLS];
	iflare_option.itemText = GF_GameStrings[GT_FLARE];
	ishotgun_option.itemText = GF_GameStrings[GT_SHOTGUN];
	imagnum_option.itemText = GF_GameStrings[GT_AUTOPISTOLS];
	iuzi_option.itemText = GF_GameStrings[GT_UZIS];
	iharpoon_option.itemText = GF_GameStrings[GT_HARPOON];
	im16_option.itemText = GF_GameStrings[GT_M16];
	irocket_option.itemText = GF_GameStrings[GT_ROCKETLAUNCHER];
	igunammo_option.itemText = GF_GameStrings[GT_PISTOLCLIPS];
	isgunammo_option.itemText = GF_GameStrings[GT_SHOTGUNSHELLS];
	imagammo_option.itemText = GF_GameStrings[GT_AUTOPISTOLCLIPS];
	iuziammo_option.itemText = GF_GameStrings[GT_UZICLIPS];
	iharpoonammo_option.itemText = GF_GameStrings[GT_HARPOONBOLTS];
	im16ammo_option.itemText = GF_GameStrings[GT_M16CLIPS];
	irocketammo_option.itemText = GF_GameStrings[GT_ROCKETS];

	imedi_option.itemText = GF_GameStrings[GT_SMALLMEDI];
	ibigmedi_option.itemText = GF_GameStrings[GT_LARGEMEDI];
	ipickup1_option.itemText = GF_GameStrings[GT_PICKUP];
	ipickup2_option.itemText = GF_GameStrings[GT_PICKUP];
	ipuzzle1_option.itemText = GF_GameStrings[GT_PUZZLE];
	ipuzzle2_option.itemText = GF_GameStrings[GT_PUZZLE];
	ipuzzle3_option.itemText = GF_GameStrings[GT_PUZZLE];
	ipuzzle4_option.itemText = GF_GameStrings[GT_PUZZLE];
	ikey1_option.itemText = GF_GameStrings[GT_KEY];
	ikey2_option.itemText = GF_GameStrings[GT_KEY];
	ikey3_option.itemText = GF_GameStrings[GT_KEY];
	ikey4_option.itemText = GF_GameStrings[GT_KEY];
	ipassport_option.itemText = GF_GameStrings[GT_GAME];
#ifdef PC_VERSION
	idetail_option.itemText = GF_PCStrings[PCSTR_DETAILLEVEL];
	isound_option.itemText = GF_PCStrings[PCSTR_SOUND];
	icontrol_option.itemText = GF_PCStrings[PCSTR_CONTROLS];
//	igamma_option.itemText = GF_PCStrings[PCSTR_GAMMA];
#else
	idetail_option.itemText = GF_PSXStrings[PSSTR_DETAILLEVEL];
	isound_option.itemText = GF_PSXStrings[PSSTR_SOUND];
	icontrol_option.itemText = GF_PSXStrings[PSSTR_CONTROLS];
//	igamma_option.itemText = GF_PSXStrings[PSSTR_GAMMA];
#endif
	iphoto_option.itemText = GF_GameStrings[GT_GYM];
	SetRequesterHeading(&Load_Game_Requester, GF_GameStrings[GT_SELECTLEVEL],R_CENTRE,NULL,0);
	SetRequesterHeading(&Level_Select_Requester, GF_GameStrings[GT_SELECTLEVEL],R_CENTRE,NULL,0);

#ifdef PSX_VERSION
	init_game_malloc();									// Reset Malloc Tables
#endif
	Logit("GF: Schedule successfully initiallised!\n");

	return(1);
}
void ShowThis( char *string, int frames );

/*********************************************************
		Handle a Call for a Sequence
*********************************************************/
sint32		GF_DoFrontEndSequence( )
{
	sint32 option;

	option = GF_InterpretSequence(GF_frontendSequence, IL_NORMAL, 1);

	if (option==EXITGAME)
		return(1);
	return(0);		// OK
}


void ShowThis( char *string, int frames )
{

}


sint16 FirstFMV[]={ GFE_PLAYFMV, 1, GFE_END_SEQ};

sint32	GF_DoStorySoFar( int level )
{
	int	i;

	GF_Playing_Story = 1;

	if (GF_InterpretSequence( FirstFMV, IL_STORY_SO_FAR, 0)==EXIT_TO_TITLE)
		return(1);
	for (i=0;i<(level-1);i++)
	{
		if (GF_DoLevelSequence( i+1, IL_STORY_SO_FAR )==EXIT_TO_TITLE)
			return(1);
	}
	GF_DoLevelSequence( level, IL_STORY_SO_FAR_MIDLEVEL );
	GF_Playing_Story = 0;

	return(1);
}


sint32	GF_DoLevelSequence( int level, int type )
{
	sint16 *ptr;
	sint32 option;

	do
	{
		if (level>gameflow.num_levels-1)
		{
			Log(LT_Info,"GF:	ERROR level(%d)	> actual levels(%d)",level,gameflow.num_levels-1);
			title_loaded = 0;
			return(EXIT_TO_TITLE);
		}
		ptr = GF_level_sequence_list[level];
		option = GF_InterpretSequence( ptr, type, 0);
		level++;
		if (gameflow.singlelevel>=0)
			return(option);
	}while ( (option&~0xff)==LEVELCOMPLETE );

	return(option);
}

/*********************************************************
		Perform a Sequence of events
*********************************************************/
sint32	GF_InterpretSequence( sint16 *ptr, int type, int seq_type)
{
	sint32 ret_val;
	int	i;
	sint32 option=EXIT_TO_TITLE;
	sint16 level;
	sint16 ntracks = 0;
	char	string[80];

	Logit("GF: NEW SEQUENCE...");
	GF_CDtracks[0] = 2;
	GF_LaraStartAnim = GF_SunsetEnabled = GF_DeadlyWater = GF_NoFloor = 0;
	GF_RemoveWeapons = GF_RemoveAmmo = GF_Kill2Complete = 0;
	GF_Cutscene_Orientation = 0x4000;
	GF_NumSecrets = 3;

	for (i=0;i<ADDINV_NUMBEROF;i++)
		GF_Add2InvItems[i]=0;
	for (i=0;i<ADDINV_NUMBEROF;i++)
		GF_SecretInvItems[i]=0;


#ifdef PSX_VERSION
	GF_LoadingPic = -1;
#endif

	while( *ptr!=GFE_END_SEQ )
	{
		switch(*ptr)
		{
			case GFE_STARTLEVEL:
				level = *(ptr+1);
				if ( level<=gameflow.num_levels )
				{
					if (type==IL_STORY_SO_FAR)
					{
						ptr+=2;
						continue;
					}
					if (type==IL_STORY_SO_FAR_MIDLEVEL)
						return(EXIT_TO_TITLE);

					Logit2("GF:	STARTLEVEL: '%s'", GF_levelfilenames[level] );
					option = StartGame( level, type );
					GF_StartGame = 0;

//					if (gameflow.singlelevel>=0)
//						return(EXITGAME);

					if (type==IL_SAVED)
						type=IL_NORMAL;
					if ( (option&~0xff) != LEVELCOMPLETE )
					{
//						Logit2("GF: SEQ STOPPED 0x%x",option);
						return(option);
					}

				}
				else
				{
					Logit2("GF:	INVALID LEVEL: %d", level );
					sprintf(string, "INVALID LEVEL %d", level);
//					ShowThis(string, 30*1);
					option = EXIT_TO_TITLE;
				}
				ptr += 2;
				break;

			case GFE_DEMOPLAY:
				if (type!=IL_SAVED && type!=IL_STORY_SO_FAR && type!=IL_STORY_SO_FAR_MIDLEVEL)
				{
					Logit2("GF:	DEMO: '%s'", GF_levelfilenames[*(ptr+1)] );
					option = StartDemo(*(ptr+1));
					return(option);
//					option = EXIT_TO_TITLE;
				}
				ptr += 2;
				break;

			case GFE_CUTANGLE:
				if (type!=IL_SAVED)
				{
					Logit2("GF:	CUT ANGLE: %d", *(ptr+1) );
					GF_Cutscene_Orientation=*(ptr+1);
				}
				ptr+=2;
				break;

			case GFE_CUTSCENE:
				if (type!=IL_SAVED)
				{
					Logit2("GF:	CUTSCENE: '%s'", GF_cutscenefilenames[*(ptr+1)] );
					sprintf(string, "CUTSCENE %d %s", *(ptr+1), GF_cutscenefilenames[*(ptr+1)]);
#ifdef PLAY_CUTSCENES
					level =(sint16) CurrentLevel;
					ret_val = StartCinematic(*(ptr+1));
					CurrentLevel = level;
					if (ret_val==2 && (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL))
						return(EXIT_TO_TITLE);
#ifdef PC_VERSION
					if (ret_val==3)
						return EXITGAME;
#endif
#endif
//					ShowThis(string, 30*1);
				}
				ptr += 2;
				break;

			case GFE_PLAYFMV:
				if (type!=IL_SAVED)
				{
					Logit2("GF:	FMV: '%s'", GF_fmvfilenames[*(ptr+1)] );
					//sprintf(string, "FMV %d %s", *(ptr+1), GF_fmvfilenames[*(ptr+1)]);
					//ShowThis(string, 30*1);
#ifdef PLAY_FMV
#ifdef PSX_VERSION
					ret_val = S_PlayFMV(*(ptr+1),0);
					if (ret_val==2 && (seq_type==1 || type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL))
						return(EXIT_TO_TITLE);
#else
					// use double FMV player for intro sequence (which is two FMV sequences back to back)
					if (*(ptr+2) == GFE_PLAYFMV)
					{
						if (S_IntroFMV(GF_fmvfilenames[*(ptr+1)], GF_fmvfilenames[*(ptr+3)]))
							return EXITGAME;
						ptr += 2;
					}
					else
						if (S_PlayFMV(GF_fmvfilenames[*(ptr+1)],*(ptr+1)))
							return EXITGAME;
#endif
#endif
				}
				ptr += 2;
				break;

			case GFE_LEVCOMPLETE:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr++;
					continue;
				}
				Logit2("GF:	LEVELCOMPLETE: '%s'", GF_levelfilenames[CurrentLevel] );
				if (LevelStats(CurrentLevel))
					return(EXIT_TO_TITLE);
				option = STARTGAME|(CurrentLevel+1);
				ptr++;
				break;

			case GFE_GAMECOMPLETE:
				Logit("GF:	GAMECOMPLETE");
				DisplayCredits();
				if (GameStats(CurrentLevel))	// allow for psx reset
					return(EXIT_TO_TITLE);
#ifdef PSX_VERSION
				GF_DoFrontEndSequence();
#if defined(JAPAN)
	S_ShowPicture( GF_titlefilenames[GFT_COPYRIGHTSPIC_JAP], 3*30, 0 );
#elif defined(NTSC)
	S_ShowPicture( GF_titlefilenames[GFT_COPYRIGHTSPIC_US], 3*30, 0 );
#else
	S_ShowPicture( GF_titlefilenames[GFT_COPYRIGHTSPIC], 3*30, 0 );
#endif
#endif
				option = EXIT_TO_TITLE;
				ptr++;
				break;

			case GFE_PICTURE:
				if (type!=IL_SAVED) //???
				{
					Logit2("GF:	PICTURE: '%s'", GF_picfilenames[*(ptr+1)]);
					sprintf(string, "PICTURE %s", GF_picfilenames[*(ptr+1)]);
#ifdef PSX_VERSION
					ret_val = S_ShowPicture( GF_picfilenames[*(ptr+1)], 3*30, 1 );
#else
					ShowThis(string, 30*5);
//					S_DisplayPicture( GF_picfilenames[*(ptr+1)],false );
//					ScreenDump();
//					FadeToPal( 60, game_palette );
//					FadeWait();
#endif
				}
				ptr += 2;
				break;

			case GFE_JUMPTO_SEQ:
				Logit2("GF:	JUMP TO SEQUENCE %d", *(ptr+1) );
				sprintf(string, "JUMPSEQ %d", *(ptr+1));
//				ShowThis(string, 30*1);
				ptr+=2;
				break;

			case GFE_LIST_START:
				Logit("GF:	LIST_START >>>");
				ptr++;
				break;

			case GFE_LIST_END:
				Logit("GF:	LIST_END <<<<<");
				ptr++;
				break;

			case GFE_SETTRACK:
				Logit2("GF:	SET CD TRACK %d", *(ptr+1));
				GF_CDtracks[ntracks] = *(ptr+1);
				SetCutsceneTrack(*(ptr+1));
				ntracks++;
				ptr+=2;
				break;

			case GFE_SUNSET:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr++;
					continue;
				}
				Logit("GF:	SUNSET ENABLED");
				GF_SunsetEnabled = 1;
				ptr++;
				break;

			case GFE_DEADLY_WATER:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr++;
					continue;
				}
				Logit("GF:	DEADLY WATER");
				GF_DeadlyWater = 1;
				ptr++;
				break;

			case GFE_NOFLOOR:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr+=2;
					continue;
				}
				Logit2("GF:	NO FLOOR %d", *(ptr+1));
				GF_NoFloor = *(ptr+1);
				ptr+=2;
				break;

			case GFE_STARTANIM:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr+=2;
					continue;
				}
				Logit2("GF:	LARA START ANIM %d", *(ptr+1));
				GF_LaraStartAnim = *(ptr+1);
				ptr+=2;
				break;

			case GFE_NUMSECRETS:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr+=2;
					continue;
				}
				Logit2("GF:	NUMBER OF SECRETS: %d", *(ptr+1));
				GF_NumSecrets = *(ptr+1);
				ptr+=2;
				break;


			case GFE_ADD2INV:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr+=2;
					continue;
				}
				if (*(ptr+1)<1000)
				{
						Logit2("GF:	SECRET BONUS: %s", GF_inv_types[*(ptr+1)]);
						GF_SecretInvItems[*(ptr+1)]++;
				}
				else
				{
					if (type!=IL_SAVED)
					{
						Logit2("GF:	START INVENTORY WITH %s", GF_inv_types[*(ptr+1)-1000]);
						GF_Add2InvItems[*(ptr+1)-1000]++;
					}
				}
				ptr+=2;
				break;


			case GFE_REMOVE_WEAPONS:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr++;
					continue;
				}
				if (type!=IL_SAVED) //???
				{
					Logit("GF:	REMOVE WEAPONS");
					GF_RemoveWeapons = 1;
				}
				ptr++;
				break;

			case GFE_REMOVE_AMMO:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr++;
					continue;
				}
				if (type!=IL_SAVED) //???
				{
					Logit("GF:	REMOVE AMMO");
					GF_RemoveAmmo = 1;
				}
				ptr++;
				break;


			case GFE_KILL2COMPLETE:
				if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
				{
					ptr++;
					continue;
				}
				Logit("GF:	REMOVE WEAPONS");
				GF_Kill2Complete = 1;
				ptr++;
				break;


			case GFE_LOADINGPIC:
#if defined(PSX_VERSION)
#if defined(GAMEDEBUG)
				printf("GF:	LOADING PIC '%s'\n", GF_picfilenames[*(ptr+1)]);
#endif
				GF_LoadingPic = *(ptr+1);
#endif
				ptr+=2;
				break;

			default:
				Logit2("GF:	ERROR: UNKNOWN COMMAND IN SEQUENCE %d\n", *ptr );
				return(EXITGAME);
		}
	}
	Logit("GF: END SEQUENCE\n");
#ifdef PSX_VERSION
	GF_LoadingPic = -1;
#endif
	if (type==IL_STORY_SO_FAR || type==IL_STORY_SO_FAR_MIDLEVEL)
		return(0);
	return(option); // Success!
}

#define MT_START	0
#define MT_SECRET	1

void GF_ModifyInventory( int level, int type )
{
	int	i;
	START_INFO *start = &savegame.start[level];

	// Add Pistols
	if (!start->got_pistols && GF_Add2InvItems[ADDINV_PISTOLS])
	{
		start->got_pistols = 1;
		Inv_AddItem( GUN_ITEM );
	}

	// Add Shotgun and/or Ammo
	if (Inv_RequestItem(SHOTGUN_ITEM))
	{
		if (type==MT_START)
		{
			lara.shotgun.ammo += GF_Add2InvItems[ADDINV_SHOTGUN_AMMO] * SHOTGUN_AMMO_QTY;
		}
		else
		{
			lara.shotgun.ammo += GF_SecretInvItems[ADDINV_SHOTGUN_AMMO] * SHOTGUN_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_SHOTGUN_AMMO];i++)
				AddDisplayPickup( SG_AMMO_ITEM );
		}
	}
	else if ((type==MT_START && GF_Add2InvItems[ADDINV_SHOTGUN]) || (type==MT_SECRET && GF_SecretInvItems[ADDINV_SHOTGUN]))
	{
		start->got_shotgun = 1;
		Inv_AddItem( SHOTGUN_ITEM );
		if (type==MT_START)
		{
			lara.shotgun.ammo += GF_Add2InvItems[ADDINV_SHOTGUN_AMMO] * SHOTGUN_AMMO_QTY;
		}
		else
		{
			AddDisplayPickup( SHOTGUN_ITEM );
			lara.shotgun.ammo += GF_SecretInvItems[ADDINV_SHOTGUN_AMMO] * SHOTGUN_AMMO_QTY;
		}
	}
	else
	{
		if (type==MT_START)
		{
			for (i=0;i<GF_Add2InvItems[ADDINV_SHOTGUN_AMMO];i++)
				Inv_AddItem( SG_AMMO_ITEM );
		}
		else
		{
			for (i=0;i<GF_SecretInvItems[ADDINV_SHOTGUN_AMMO];i++)
			{
				AddDisplayPickup( SG_AMMO_ITEM );
				Inv_AddItem( SG_AMMO_ITEM );
			}
		}
	}

	// Add Magnums and/or Ammo
	if (Inv_RequestItem(MAGNUM_ITEM))
	{
		if (type==MT_START)
			lara.magnums.ammo += GF_Add2InvItems[ADDINV_AUTOPISTOLS_AMMO] * MAGNUM_AMMO_QTY;
		else
		{
			lara.magnums.ammo += GF_SecretInvItems[ADDINV_AUTOPISTOLS_AMMO] * MAGNUM_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_AUTOPISTOLS_AMMO];i++)
				AddDisplayPickup( MAG_AMMO_ITEM );
		}
	}
	else if ((type==MT_START && GF_Add2InvItems[ADDINV_AUTOPISTOLS]) || (type==MT_SECRET && GF_SecretInvItems[ADDINV_AUTOPISTOLS]))
	{
		start->got_magnums = 1;
		Inv_AddItem( MAGNUM_ITEM );
		if (type==MT_START)
			lara.magnums.ammo += GF_Add2InvItems[ADDINV_AUTOPISTOLS_AMMO] * MAGNUM_AMMO_QTY;
		else
		{
			AddDisplayPickup( MAGNUM_ITEM );
			lara.magnums.ammo += GF_Add2InvItems[ADDINV_AUTOPISTOLS_AMMO] * MAGNUM_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_AUTOPISTOLS];i++)
				AddDisplayPickup( MAG_AMMO_ITEM );
		}
	}
	else
	{
		if (type==MT_START)
		{
			for (i=0;i<GF_Add2InvItems[ADDINV_AUTOPISTOLS_AMMO];i++)
				Inv_AddItem( MAG_AMMO_ITEM );
		}
		else
		{
			for (i=0;i<GF_SecretInvItems[ADDINV_AUTOPISTOLS_AMMO];i++)
			{
				Inv_AddItem( MAG_AMMO_ITEM );
				AddDisplayPickup( MAG_AMMO_ITEM );
			}
		}
	}

	// Add Uzis and/or Ammo
	if (Inv_RequestItem( UZI_ITEM ))
	{
		if (type==MT_START)
			lara.uzis.ammo += GF_Add2InvItems[ADDINV_UZI_AMMO] * UZI_AMMO_QTY;
		else
		{
			lara.uzis.ammo += GF_SecretInvItems[ADDINV_UZI_AMMO] * UZI_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_UZI_AMMO];i++)
				AddDisplayPickup( UZI_AMMO_ITEM );
		}
	}
	else if ((type==MT_START && GF_Add2InvItems[ADDINV_UZIS]) || (type==MT_SECRET && GF_SecretInvItems[ADDINV_UZIS]))
	{
		start->got_uzis = 1;
		Inv_AddItem( UZI_ITEM );
		if (type==MT_START)
			lara.uzis.ammo += GF_Add2InvItems[ADDINV_UZI_AMMO] * UZI_AMMO_QTY;
		else
		{
		 	AddDisplayPickup( UZI_ITEM );
			lara.uzis.ammo += GF_SecretInvItems[ADDINV_UZI_AMMO] * UZI_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_UZI_AMMO];i++)
			 	AddDisplayPickup( UZI_AMMO_ITEM );
		}
	}
	else
	{
		if (type==MT_START)
		{
			for (i=0;i<GF_Add2InvItems[ADDINV_UZI_AMMO];i++)
				Inv_AddItem( UZI_AMMO_ITEM );
		}
		else
		{
			for (i=0;i<GF_SecretInvItems[ADDINV_UZI_AMMO];i++)
			{
				Inv_AddItem( UZI_AMMO_ITEM );
			 	AddDisplayPickup( UZI_AMMO_ITEM );
			}
		}
	}

	// Add Harpoon and/or Ammo
	if (Inv_RequestItem( HARPOON_ITEM ))
	{
		if (type==MT_START)
			lara.harpoon.ammo += GF_Add2InvItems[ADDINV_HARPOON_AMMO] * HARPOON_AMMO_QTY;
		else
		{
			lara.harpoon.ammo += GF_SecretInvItems[ADDINV_HARPOON_AMMO] * HARPOON_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_HARPOON_AMMO];i++)
			 	AddDisplayPickup( HARPOON_AMMO_ITEM );
		}
	}
	else if ((type==MT_START && GF_Add2InvItems[ADDINV_HARPOON]) || (type==MT_SECRET && GF_SecretInvItems[ADDINV_HARPOON]))
	{
		start->got_harpoon = 1;
		Inv_AddItem( HARPOON_ITEM );
		if (type==MT_START)
			lara.harpoon.ammo += GF_Add2InvItems[ADDINV_HARPOON_AMMO] * HARPOON_AMMO_QTY;
		else
		{
		 	AddDisplayPickup( HARPOON_ITEM );
			lara.harpoon.ammo += GF_SecretInvItems[ADDINV_HARPOON_AMMO] * HARPOON_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_HARPOON_AMMO];i++)
			 	AddDisplayPickup( HARPOON_AMMO_ITEM );
		}
	}
	else
	{
		if (type==MT_START)
		{
			for (i=0;i<GF_Add2InvItems[ADDINV_HARPOON_AMMO];i++)
				Inv_AddItem( HARPOON_AMMO_ITEM );
		}
		else
		{
			for (i=0;i<GF_SecretInvItems[ADDINV_HARPOON_AMMO];i++)
			{
				Inv_AddItem( HARPOON_AMMO_ITEM );
			 	AddDisplayPickup( HARPOON_AMMO_ITEM );
			}
		}
	}

	// Add M16 and/or Ammo
	if (Inv_RequestItem(M16_ITEM))
	{
		if (type==MT_START)
			lara.m16.ammo += GF_Add2InvItems[ADDINV_M16_AMMO] * M16_AMMO_QTY;
		else
		{
			lara.m16.ammo += GF_SecretInvItems[ADDINV_M16_AMMO] * M16_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_M16_AMMO];i++)
			 	AddDisplayPickup( M16_AMMO_ITEM );
		}
	}
	else if ((type==MT_START && GF_Add2InvItems[ADDINV_M16]) || (type==MT_SECRET && GF_SecretInvItems[ADDINV_M16]))
	{
		start->got_m16 = 1;
		Inv_AddItem( M16_ITEM );
		if (type==MT_START)
			lara.m16.ammo += GF_Add2InvItems[ADDINV_M16_AMMO] * M16_AMMO_QTY;
		else
		{
		  	AddDisplayPickup( M16_ITEM );
			lara.m16.ammo += GF_SecretInvItems[ADDINV_M16_AMMO] * M16_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_M16_AMMO];i++)
			 	AddDisplayPickup( M16_AMMO_ITEM );
		}
	}
	else
	{
		if (type==MT_START)
		{
			for (i=0;i<GF_Add2InvItems[ADDINV_M16_AMMO];i++)
				Inv_AddItem( M16_AMMO_ITEM );
		}
		else
		{
			for (i=0;i<GF_SecretInvItems[ADDINV_M16_AMMO];i++)
			{
				Inv_AddItem( M16_AMMO_ITEM );
			 	AddDisplayPickup( M16_AMMO_ITEM );
			}
		}
	}

	// Add Rocket Launcher and/or Ammo
	if (Inv_RequestItem(ROCKET_GUN_ITEM))
	{
		if (type==MT_START)
			lara.rocket.ammo += GF_Add2InvItems[ADDINV_ROCKET_AMMO] * ROCKET_AMMO_QTY;
		else
		{
			lara.rocket.ammo += GF_SecretInvItems[ADDINV_ROCKET_AMMO] * ROCKET_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_ROCKET_AMMO];i++)
			{
				AddDisplayPickup( ROCKET_AMMO_ITEM );
			}
		}
	}
	else if ((type==MT_START && GF_Add2InvItems[ADDINV_ROCKET]) || (type==MT_SECRET && GF_SecretInvItems[ADDINV_ROCKET]))
	{
		start->got_rocket = 1;
		Inv_AddItem( ROCKET_GUN_ITEM );
		if (type==MT_START)
			lara.rocket.ammo += GF_Add2InvItems[ADDINV_ROCKET_AMMO] * ROCKET_AMMO_QTY;
		else
		{
			AddDisplayPickup( ROCKET_GUN_ITEM );
			lara.rocket.ammo += GF_SecretInvItems[ADDINV_ROCKET_AMMO] * ROCKET_AMMO_QTY;
			for (i=0;i<GF_SecretInvItems[ADDINV_ROCKET_AMMO];i++)
				AddDisplayPickup( ROCKET_AMMO_ITEM );
		}
	}
	else
	{
		if (type==MT_START)
		{
			for (i=0;i<GF_Add2InvItems[ADDINV_ROCKET_AMMO];i++)
				Inv_AddItem( ROCKET_AMMO_ITEM );
		}
		else
		{
			for (i=0;i<GF_SecretInvItems[ADDINV_ROCKET_AMMO];i++)
			{
				Inv_AddItem( ROCKET_AMMO_ITEM );
				AddDisplayPickup( ROCKET_AMMO_ITEM );
			}
		}
	}

	if (type==MT_START)
	{
		// Flares/Medis
		for (i=0;i<GF_Add2InvItems[ADDINV_FLARES];i++)
			Inv_AddItem( FLARE_ITEM );
		for (i=0;i<GF_Add2InvItems[ADDINV_MEDI];i++)
			Inv_AddItem( MEDI_ITEM );
		for (i=0;i<GF_Add2InvItems[ADDINV_BIGMEDI];i++)
			Inv_AddItem( BIGMEDI_ITEM );

		// Pickups
		for (i=0;i<GF_Add2InvItems[ADDINV_PICKUP1];i++)
			Inv_AddItem( PICKUP_ITEM1 );
		for (i=0;i<GF_Add2InvItems[ADDINV_PICKUP2];i++)
			Inv_AddItem( PICKUP_ITEM2 );

		for (i=0;i<GF_Add2InvItems[ADDINV_PUZZLE1];i++)
			Inv_AddItem( PUZZLE_ITEM1 );
		for (i=0;i<GF_Add2InvItems[ADDINV_PUZZLE2];i++)
			Inv_AddItem( PUZZLE_ITEM2 );
		for (i=0;i<GF_Add2InvItems[ADDINV_PUZZLE3];i++)
			Inv_AddItem( PUZZLE_ITEM3 );
		for (i=0;i<GF_Add2InvItems[ADDINV_PUZZLE4];i++)
			Inv_AddItem( PUZZLE_ITEM4 );

		for (i=0;i<GF_Add2InvItems[ADDINV_KEY1];i++)
			Inv_AddItem( KEY_ITEM1 );
		for (i=0;i<GF_Add2InvItems[ADDINV_KEY2];i++)
			Inv_AddItem( KEY_ITEM2 );
		for (i=0;i<GF_Add2InvItems[ADDINV_KEY3];i++)
			Inv_AddItem( KEY_ITEM3 );
		for (i=0;i<GF_Add2InvItems[ADDINV_KEY4];i++)
			Inv_AddItem( KEY_ITEM4 );

		//	Clear list
		for (i=0;i<ADDINV_NUMBEROF;i++)
			GF_Add2InvItems[i]=0;
	}
	else
	{
		// Flares/Medis
		for (i=0;i<GF_SecretInvItems[ADDINV_FLARES];i++)
		{
			Inv_AddItem( FLARE_ITEM );
			AddDisplayPickup( FLARE_ITEM );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_MEDI];i++)
		{
			Inv_AddItem( MEDI_ITEM );
			AddDisplayPickup( MEDI_ITEM );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_BIGMEDI];i++)
		{
			Inv_AddItem( BIGMEDI_ITEM );
			AddDisplayPickup( BIGMEDI_ITEM );
		}

		// Pickups
		for (i=0;i<GF_SecretInvItems[ADDINV_PICKUP1];i++)
		{
			Inv_AddItem( PICKUP_ITEM1 );
			AddDisplayPickup( PICKUP_ITEM1 );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_PICKUP2];i++)
		{
			Inv_AddItem( PICKUP_ITEM2 );
			AddDisplayPickup( PICKUP_ITEM2 );
		}

		for (i=0;i<GF_SecretInvItems[ADDINV_PUZZLE1];i++)
		{
			Inv_AddItem( PUZZLE_ITEM1 );
			AddDisplayPickup( PUZZLE_ITEM1 );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_PUZZLE2];i++)
		{
			Inv_AddItem( PUZZLE_ITEM2 );
			AddDisplayPickup( PUZZLE_ITEM2 );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_PUZZLE3];i++)
		{
			Inv_AddItem( PUZZLE_ITEM3 );
			AddDisplayPickup( PUZZLE_ITEM3 );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_PUZZLE4];i++)
		{
			Inv_AddItem( PUZZLE_ITEM4 );
			AddDisplayPickup( PUZZLE_ITEM4 );
		}

		for (i=0;i<GF_SecretInvItems[ADDINV_KEY1];i++)
		{
			Inv_AddItem( KEY_ITEM1 );
			AddDisplayPickup( KEY_ITEM1 );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_KEY2];i++)
		{
			Inv_AddItem( KEY_ITEM2 );
			AddDisplayPickup( KEY_ITEM2 );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_KEY3];i++)
		{
			Inv_AddItem( KEY_ITEM3 );
			AddDisplayPickup( KEY_ITEM3 );
		}
		for (i=0;i<GF_SecretInvItems[ADDINV_KEY4];i++)
		{
			Inv_AddItem( KEY_ITEM4 );
			AddDisplayPickup( KEY_ITEM4 );
		}

		//	Clear list
		for (i=0;i<ADDINV_NUMBEROF;i++)
			GF_SecretInvItems[i]=0;
	}
}
