/* 
	PScript by Peter Pon
	
	scene21
*/
#include "..\PScriptLib\Def.h"

#include "..\PScriptLib\box.pst"
#include "..\PScriptLib\desk.pst"
#include "..\PScriptLib\chair.pst"
#include "..\PScriptLib\jug.pst"

int DeathMatch = 1;
int TeamDeathMatch = 5;
int GameMod;

int EventEnter = 200;
int EventExit = 201;
int EventDeath = 202;

int g_CharacterArena[17];
int g_ArenaCharacters[16];
int g_TeamAArenaCharacters[16];
int g_TeamBArenaCharacters[16];

Scene_OnInit()
{
	InitBoxes(g_iNumBoxes);
	InitBBoxes(g_iNumBBoxes);
	InitChairs(g_iNumChairs);
	InitDeskes(g_iNumDeskes);
	InitJugs(g_iNumJugs);
	GameMod = GameCallBack("mod", 0);
	int i;
	string itemname;
	for (i=0; i<16; i=i+1)
	{
		g_CharacterArena[i] = -1;
		g_ArenaCharacters[i] = 0;
		g_TeamAArenaCharacters[i] = 0;
		g_TeamBArenaCharacters[i] = 0;
		
		MakeString(itemname, "D_tpEC", i+1);
		SetSceneItem(itemname, "name", "machine");
		SetSceneItem(itemname, "attribute", "collision", 0);
		SetSceneItem(itemname, "attribute", "interactive", 1);

		MakeString(itemname, "D_tpEC", i+17);
		SetSceneItem(itemname, "name", "machine");
		SetSceneItem(itemname, "attribute", "collision", 0);
		SetSceneItem(itemname, "attribute", "interactive", 1);
	}
	
	for (i=0; i<8; i=i+1)
	{
		MakeString(itemname, "D_tpAC", i+1);
		SetSceneItem(itemname, "name", "machine");
		SetSceneItem(itemname, "attribute", "collision", 0);

		MakeString(itemname, "D_tpAC", i+9);
		SetSceneItem(itemname, "name", "machine");
		SetSceneItem(itemname, "attribute", "collision", 0);
		
		MakeString(itemname, "D_tpBC", i+1);
		SetSceneItem(itemname, "name", "machine");
		SetSceneItem(itemname, "attribute", "collision", 0);

		MakeString(itemname, "D_tpBC", i+9);
		SetSceneItem(itemname, "name", "machine");
		SetSceneItem(itemname, "attribute", "collision", 0);
	}
}

Scene_OnCharacterEvent(int id, int event)
{
	int i;
	int arena;
	int team;
	Output("Character:", id, "event:", event);
	
	if ( event==EventExit || event==EventDeath )
	{
		if ( GameMod==DeathMatch )
		{
			arena = g_CharacterArena[id];
			if ( arena!=-1 )
			{
				g_ArenaCharacters[arena] = g_ArenaCharacters[arena] - 1;
			}
			g_CharacterArena[id] = -1;
		}
		if ( GameMod==TeamDeathMatch )
		{
			arena = g_CharacterArena[id];
			team = GetTeam(id);
			if ( arena!=-1 )
			{
				if ( team==1 )
				{
					g_TeamAArenaCharacters[arena] = g_TeamAArenaCharacters[arena] - 1;
				}
				if ( team==2 )
				{
					g_TeamBArenaCharacters[arena] = g_TeamBArenaCharacters[arena] - 1;
				}
			}
			g_CharacterArena[id] = -1;
		}
	}		
}

TransferToArena(int characterid, int tpid)
{
	string arenaname;
	int arena = tpid/2;
	Output("arena characters", g_ArenaCharacters[arena]);
	if ( g_ArenaCharacters[arena]<2 && g_CharacterArena[characterid] != arena )
	{
		g_ArenaCharacters[arena]=g_ArenaCharacters[arena]+1;
		g_CharacterArena[characterid] = arena;
		MakeString(arenaname, "D_tpED", tpid+1);
		Misc("transfer", characterid, arenaname);
		Output("transfer", characterid, "to", tpid);
	}
}

TransferFromArena(int characterid, int tpid)
{
	string arenaname;
	int arena = tpid/2;

	if ( g_ArenaCharacters[arena]==1 && g_CharacterArena[characterid] == arena)
	{
		g_ArenaCharacters[arena]=g_ArenaCharacters[arena]-1;
		g_CharacterArena[characterid] = -1;
		MakeString(arenaname, "D_tpED", tpid+17);
		Misc("transfer", characterid, arenaname);
		Output("transfer", characterid, "from", tpid);
	}
}

TeamATransferToArena(int characterid, int arena)
{
	string arenaname;
	int team;
	team = GetTeam(characterid);
	if ( team==1 && g_TeamAArenaCharacters[arena]==0 )
	{
		g_TeamAArenaCharacters[arena] = 1;
		g_CharacterArena[characterid] = arena;
		MakeString(arenaname, "D_tpAD", arena+1);
		Misc("transfer", characterid, arenaname);
		Output("transfer", characterid, "to", arena);
	}
}

TeamATransferFromArena(int characterid, int arena)
{
	string arenaname;
	int team;
	team = GetTeam(characterid);
	if ( team==1 && g_TeamAArenaCharacters[arena]==1 && g_TeamBArenaCharacters[arena]==0 )
	{
		g_TeamAArenaCharacters[arena] = 0;
		g_CharacterArena[characterid] = -1;
		MakeString(arenaname, "D_tpAD", arena+9);
		Misc("transfer", characterid, arenaname);
		Output("transfer", characterid, "from", arena);
	}
}

TeamBTransferToArena(int characterid, int arena)
{
	string arenaname;
	int team;
	team = GetTeam(characterid);
	if ( team==2 && g_TeamBArenaCharacters[arena]==0 )
	{
		g_TeamBArenaCharacters[arena] = 1;
		g_CharacterArena[characterid] = arena;
		MakeString(arenaname, "D_tpBD", arena+1);
		Misc("transfer", characterid, arenaname);
		Output("transfer", characterid, "to", arena);
	}
}

TeamBTransferFromArena(int characterid, int arena)
{
	string arenaname;
	int team;
	team = GetTeam(characterid);
	if ( team==2 && g_TeamBArenaCharacters[arena]==1 && g_TeamAArenaCharacters[arena]==0 )
	{
		g_TeamBArenaCharacters[arena] = 0;
		g_CharacterArena[characterid] = -1;
		MakeString(arenaname, "D_tpBD", arena+9);
		Misc("transfer", characterid, arenaname);
		Output("transfer", characterid, "from", arena);
	}
}

D_tpEC01_OnTouch(int id, int characterid)
{
	Output("EC01 Touched");
	TransferToArena(characterid, 0);
}

D_tpEC02_OnTouch(int id, int characterid)
{
	Output("EC02 Touched");
	TransferToArena(characterid, 1);
}

D_tpEC03_OnTouch(int id, int characterid)
{
	Output("EC03 Touched");
	TransferToArena(characterid, 2);
}

D_tpEC04_OnTouch(int id, int characterid)
{
	Output("EC04 Touched");
	TransferToArena(characterid, 3);
}

D_tpEC05_OnTouch(int id, int characterid)
{
	Output("EC05 Touched");
	TransferToArena(characterid, 4);
}

D_tpEC06_OnTouch(int id, int characterid)
{
	Output("EC06 Touched");
	TransferToArena(characterid, 5);
}

D_tpEC07_OnTouch(int id, int characterid)
{
	Output("EC07 Touched");
	TransferToArena(characterid, 6);
}

D_tpEC08_OnTouch(int id, int characterid)
{
	Output("EC08 Touched");
	TransferToArena(characterid, 7);
}

D_tpEC09_OnTouch(int id, int characterid)
{
	Output("EC09 Touched");
	TransferToArena(characterid, 8);
}

D_tpEC10_OnTouch(int id, int characterid)
{
	Output("EC10 Touched");
	TransferToArena(characterid, 9);
}

D_tpEC11_OnTouch(int id, int characterid)
{
	Output("EC11 Touched");
	TransferToArena(characterid, 10);
}

D_tpEC12_OnTouch(int id, int characterid)
{
	Output("EC12 Touched");
	TransferToArena(characterid, 11);
}

D_tpEC13_OnTouch(int id, int characterid)
{
	Output("EC13 Touched");
	TransferToArena(characterid, 12);
}

D_tpEC14_OnTouch(int id, int characterid)
{
	Output("EC14 Touched");
	TransferToArena(characterid, 13);
}

D_tpEC15_OnTouch(int id, int characterid)
{
	Output("EC15 Touched");
	TransferToArena(characterid, 14);
}

D_tpEC16_OnTouch(int id, int characterid)
{
	Output("EC16 Touched");
	TransferToArena(characterid, 15);
}

D_tpEC17_OnTouch(int id, int characterid)
{
	Output("EC17 Touched");
	TransferFromArena(characterid, 0);
}

D_tpEC18_OnTouch(int id, int characterid)
{
	Output("EC18 Touched");
	TransferFromArena(characterid, 1);
}

D_tpEC19_OnTouch(int id, int characterid)
{
	Output("EC19 Touched");
	TransferFromArena(characterid, 2);
}

D_tpEC20_OnTouch(int id, int characterid)
{
	Output("EC20 Touched");
	TransferFromArena(characterid, 3);
}

D_tpEC21_OnTouch(int id, int characterid)
{
	Output("EC21 Touched");
	TransferFromArena(characterid, 4);
}

D_tpEC22_OnTouch(int id, int characterid)
{
	Output("EC22 Touched");
	TransferFromArena(characterid, 5);
}

D_tpEC23_OnTouch(int id, int characterid)
{
	Output("EC23 Touched");
	TransferFromArena(characterid, 6);
}

D_tpEC24_OnTouch(int id, int characterid)
{
	Output("EC24 Touched");
	TransferFromArena(characterid, 7);
}

D_tpEC25_OnTouch(int id, int characterid)
{
	Output("EC25 Touched");
	TransferFromArena(characterid, 8);
}

D_tpEC26_OnTouch(int id, int characterid)
{
	Output("EC26 Touched");
	TransferFromArena(characterid, 9);
}

D_tpEC27_OnTouch(int id, int characterid)
{
	Output("EC27 Touched");
	TransferFromArena(characterid, 10);
}

D_tpEC28_OnTouch(int id, int characterid)
{
	Output("EC28 Touched");
	TransferFromArena(characterid, 11);
}

D_tpEC29_OnTouch(int id, int characterid)
{
	Output("EC29 Touched");
	TransferFromArena(characterid, 12);
}

D_tpEC30_OnTouch(int id, int characterid)
{
	Output("EC30 Touched");
	TransferFromArena(characterid, 13);
}

D_tpEC31_OnTouch(int id, int characterid)
{
	Output("EC31 Touched");
	TransferFromArena(characterid, 14);
}

D_tpEC32_OnTouch(int id, int characterid)
{
	Output("EC32 Touched");
	TransferFromArena(characterid, 15);
}

D_tpAC01_OnTouch(int id, int characterid)
{
	Output("AC01 Touched");
	TeamATransferToArena(characterid, 0);
}

D_tpAC02_OnTouch(int id, int characterid)
{
	Output("AC02 Touched");
	TeamATransferToArena(characterid, 1);
}

D_tpAC03_OnTouch(int id, int characterid)
{
	Output("AC03 Touched");
	TeamATransferToArena(characterid, 2);
}

D_tpAC04_OnTouch(int id, int characterid)
{
	Output("AC04 Touched");
	TeamATransferToArena(characterid, 3);
}

D_tpAC05_OnTouch(int id, int characterid)
{
	Output("AC05 Touched");
	TeamATransferToArena(characterid, 4);
}

D_tpAC06_OnTouch(int id, int characterid)
{
	Output("AC06 Touched");
	TeamATransferToArena(characterid, 5);
}

D_tpAC07_OnTouch(int id, int characterid)
{
	Output("AC07 Touched");
	TeamATransferToArena(characterid, 6);
}

D_tpAC08_OnTouch(int id, int characterid)
{
	Output("AC08 Touched");
	TeamATransferToArena(characterid, 7);
}

D_tpAC09_OnTouch(int id, int characterid)
{
	Output("AC09 Touched");
	TeamATransferFromArena(characterid, 0);
}

D_tpAC10_OnTouch(int id, int characterid)
{
	Output("AC10 Touched");
	TeamATransferFromArena(characterid, 1);
}

D_tpAC11_OnTouch(int id, int characterid)
{
	Output("AC11 Touched");
	TeamATransferFromArena(characterid, 2);
}

D_tpAC12_OnTouch(int id, int characterid)
{
	Output("AC12 Touched");
	TeamATransferFromArena(characterid, 3);
}

D_tpAC13_OnTouch(int id, int characterid)
{
	Output("AC13 Touched");
	TeamATransferFromArena(characterid, 4);
}

D_tpAC14_OnTouch(int id, int characterid)
{
	Output("AC14 Touched");
	TeamATransferFromArena(characterid, 5);
}

D_tpAC15_OnTouch(int id, int characterid)
{
	Output("AC15 Touched");
	TeamATransferFromArena(characterid, 6);
}

D_tpAC16_OnTouch(int id, int characterid)
{
	Output("AC16 Touched");
	TeamATransferFromArena(characterid, 7);
}

D_tpBC01_OnTouch(int id, int characterid)
{
	Output("BC01 Touched by", characterid);
	TeamBTransferToArena(characterid, 0);
}

D_tpBC02_OnTouch(int id, int characterid)
{
	Output("BC02 Touched by", characterid);
	TeamBTransferToArena(characterid, 1);
}

D_tpBC03_OnTouch(int id, int characterid)
{
	Output("BC03 Touched by", characterid);
	TeamBTransferToArena(characterid, 2);
}

D_tpBC04_OnTouch(int id, int characterid)
{
	Output("BC04 Touched by", characterid);
	TeamBTransferToArena(characterid, 3);
}

D_tpBC05_OnTouch(int id, int characterid)
{
	Output("BC05 Touched by", characterid);
	TeamBTransferToArena(characterid, 4);
}

D_tpBC06_OnTouch(int id, int characterid)
{
	Output("BC06 Touched by", characterid);
	TeamBTransferToArena(characterid, 5);
}

D_tpBC07_OnTouch(int id, int characterid)
{
	Output("BC07 Touched by", characterid);
	TeamBTransferToArena(characterid, 6);
}

D_tpBC08_OnTouch(int id, int characterid)
{
	Output("BC08 Touched by", characterid);
	TeamBTransferToArena(characterid, 7);
}

D_tpBC09_OnTouch(int id, int characterid)
{
	Output("BC09 Touched by", characterid);
	TeamBTransferFromArena(characterid, 0);
}

D_tpBC10_OnTouch(int id, int characterid)
{
	Output("BC10 Touched by", characterid);
	TeamBTransferFromArena(characterid, 1);
}

D_tpBC11_OnTouch(int id, int characterid)
{
	Output("BC11 Touched by", characterid);
	TeamBTransferFromArena(characterid, 2);
}

D_tpBC12_OnTouch(int id, int characterid)
{
	Output("BC12 Touched by", characterid);
	TeamBTransferFromArena(characterid, 3);
}

D_tpBC13_OnTouch(int id, int characterid)
{
	Output("BC13 Touched by", characterid);
	TeamBTransferFromArena(characterid, 4);
}

D_tpBC14_OnTouch(int id, int characterid)
{
	Output("BC14 Touched by", characterid);
	TeamBTransferFromArena(characterid, 5);
}

D_tpBC15_OnTouch(int id, int characterid)
{
	Output("BC15 Touched by", characterid);
	TeamBTransferFromArena(characterid, 6);
}

D_tpBC16_OnTouch(int id, int characterid)
{
	Output("BC16 Touched by", characterid);
	TeamBTransferFromArena(characterid, 7);
}

