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

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

int g_bBridge01Alive;
int g_bBridge02Alive;
int g_iBridge01HP;
int g_iBridge02HP;

Scene_OnLoad()
{
	int i;
	string name;
	
	
        SetSceneItem("Z_Yyxdtwp01", "name", "machine");
        SetSceneItem("Z_Yyxdtwp01", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp14", "name", "machine");
        SetSceneItem("Z_Yyxdtwp14", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp15", "name", "machine");
        SetSceneItem("Z_Yyxdtwp15", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp02", "name", "machine");
        SetSceneItem("Z_Yyxdtwp02", "attribute", "collision", 1);
       

        SetSceneItem("Z_Yyxdtwp03", "name", "machine");
        SetSceneItem("Z_Yyxdtwp03", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp04", "name", "machine");
        SetSceneItem("Z_Yyxdtwp04", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp05", "name", "machine");
        SetSceneItem("Z_Yyxdtwp05", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp06", "name", "machine");
        SetSceneItem("Z_Yyxdtwp06", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp07", "name", "machine");
        SetSceneItem("Z_Yyxdtwp07", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp08", "name", "machine");
        SetSceneItem("Z_Yyxdtwp08", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp09", "name", "machine");
        SetSceneItem("Z_Yyxdtwp09", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp10", "name", "machine");
        SetSceneItem("Z_Yyxdtwp10", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp11", "name", "machine");
        SetSceneItem("Z_Yyxdtwp11", "attribute", "collision", 1);
 
        SetSceneItem("Z_Yyxdtwp12", "name", "machine");
        SetSceneItem("Z_Yyxdtwp12", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp13", "name", "machine");
        SetSceneItem("Z_Yyxdtwp13", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp16", "name", "machine");
        SetSceneItem("Z_Yyxdtwp16", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp17", "name", "machine");
        SetSceneItem("Z_Yyxdtwp17", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp18", "name", "machine");
        SetSceneItem("Z_Yyxdtwp18", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp19", "name", "machine");
        SetSceneItem("Z_Yyxdtwp19", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp20", "name", "machine");
        SetSceneItem("Z_Yyxdtwp20", "attribute", "collision", 1);

        SetSceneItem("D_bridge01", "name", "machine");
	SetSceneItem("D_bridge01", "attribute", "collision", 1);
	SetSceneItem("D_bridge01", "attribute", "damagevalue", 300);

        SetSceneItem("Z_Yyxdtwp21", "name", "machine");
        SetSceneItem("Z_Yyxdtwp21", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp22", "name", "machine");
        SetSceneItem("Z_Yyxdtwp22", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp23", "name", "machine");
        SetSceneItem("Z_Yyxdtwp23", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp24", "name", "machine");
        SetSceneItem("Z_Yyxdtwp24", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp25", "name", "machine");
        SetSceneItem("Z_Yyxdtwp25", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp26", "name", "machine");
        SetSceneItem("Z_Yyxdtwp26", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp27", "name", "machine");
        SetSceneItem("Z_Yyxdtwp27", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp28", "name", "machine");
        SetSceneItem("Z_Yyxdtwp28", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp29", "name", "machine");
        SetSceneItem("Z_Yyxdtwp29", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp30", "name", "machine");
        SetSceneItem("Z_Yyxdtwp30", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp31", "name", "machine");
        SetSceneItem("Z_Yyxdtwp31", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp32", "name", "machine");
        SetSceneItem("Z_Yyxdtwp32", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp33", "name", "machine");
        SetSceneItem("Z_Yyxdtwp33", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp34", "name", "machine");
        SetSceneItem("Z_Yyxdtwp34", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp35", "name", "machine");
        SetSceneItem("Z_Yyxdtwp35", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp36", "name", "machine");
        SetSceneItem("Z_Yyxdtwp36", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp37", "name", "machine");
        SetSceneItem("Z_Yyxdtwp37", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp38", "name", "machine");
        SetSceneItem("Z_Yyxdtwp38", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp39", "name", "machine");
        SetSceneItem("Z_Yyxdtwp39", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp40", "name", "machine");
        SetSceneItem("Z_Yyxdtwp40", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp41", "name", "machine");
        SetSceneItem("Z_Yyxdtwp41", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp42", "name", "machine");
        SetSceneItem("Z_Yyxdtwp42", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp43", "name", "machine");
        SetSceneItem("Z_Yyxdtwp43", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp44", "name", "machine");
        SetSceneItem("Z_Yyxdtwp44", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp45", "name", "machine");
        SetSceneItem("Z_Yyxdtwp45", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp46", "name", "machine");
        SetSceneItem("Z_Yyxdtwp46", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp47", "name", "machine");
        SetSceneItem("Z_Yyxdtwp47", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp48", "name", "machine");
        SetSceneItem("Z_Yyxdtwp48", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp49", "name", "machine");
        SetSceneItem("Z_Yyxdtwp49", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp50", "name", "machine");
        SetSceneItem("Z_Yyxdtwp50", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp51", "name", "machine");
        SetSceneItem("Z_Yyxdtwp51", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp52", "name", "machine");
        SetSceneItem("Z_Yyxdtwp52", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp53", "name", "machine");
        SetSceneItem("Z_Yyxdtwp53", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp54", "name", "machine");
        SetSceneItem("Z_Yyxdtwp54", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp55", "name", "machine");
        SetSceneItem("Z_Yyxdtwp55", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp56", "name", "machine");
        SetSceneItem("Z_Yyxdtwp56", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp57", "name", "machine");
        SetSceneItem("Z_Yyxdtwp57", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp58", "name", "machine");
        SetSceneItem("Z_Yyxdtwp58", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp59", "name", "machine");
        SetSceneItem("Z_Yyxdtwp59", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp60", "name", "machine");
        SetSceneItem("Z_Yyxdtwp60", "attribute", "collision", 1);

        SetSceneItem("Z_Yyxdtwp61", "name", "machine");
        SetSceneItem("Z_Yyxdtwp61", "attribute", "collision", 1);


	SetSceneItem("D_bridge02", "name", "machine");
	SetSceneItem("D_bridge02", "attribute", "collision", 1);
	SetSceneItem("D_bridge02", "attribute", "damagevalue", 300);
}

Scene_OnInit()
{
	int i;
	string name;

	g_bBridge01Alive = 1;
	g_iBridge01HP = g_iLevel13BridgeHP;
	g_bBridge02Alive = 1;
	g_iBridge02HP = g_iLevel13BridgeHP;

	SetSceneItem("D_bridge01", "attribute", "active", 1);
	SetSceneItem("D_bridge01", "attribute", "damage", 0);
	SetSceneItem("D_bridge01", "pose", 0, 0);
	SetSceneItem("D_bridge02", "attribute", "active", 1);
	SetSceneItem("D_bridge02", "attribute", "damage", 0);
	SetSceneItem("D_bridge02", "pose", 0, 0);

	SetSceneItem("D_itbridge01", "attribute", "active", 0);
	SetSceneItem("D_itbridge01", "attribute", "interactive", 0);
	SetSceneItem("D_itbridge02", "attribute", "active", 0);
	SetSceneItem("D_itbridge02", "attribute", "interactive", 0);
      
        SetSceneItem("Z_Yyxdtwp01", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp02", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp03", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp04", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp05", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp06", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp07", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp08", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp09", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp10", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp11", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp12", "attribute", "damage", 1);
        SetSceneItem("Z_Yyxdtwp13", "attribute", "damage", 1);

        InitBoxes(g_iNumBoxes);
	InitBBoxes(g_iNumBBoxes);
	InitChairs(g_iNumChairs);
	InitDeskes(g_iNumDeskes);
	InitJugs(g_iNumJugs);
	
}

D_bridge01_OnAttack(int id, int characterid, int damage)
{
	if ( g_bBridge01Alive )
	{
		g_iBridge01HP = g_iBridge01HP - damage;
		Output("Bridge 01", g_iBridge01HP);
		if ( g_iBridge01HP <= 0 )
		{
			int pose = GetSceneItem(id, "pose");
			if ( pose==2 )
			{
				return 0;
			}
			
			NetEvent(1);
			CreateEffect(id, "BridgBRK");
			SetSceneItem(id, "pose", 2, 0);
			SetSceneItem(id, "attribute", "damage", 1);
			SetSceneItem("D_itbridge01", "attribute", "active", 1);
			SetSceneItem("D_itbridge01", "attribute", "interactive", 1);
			NetEvent(0);
		}
		else
		{
			int state = GetSceneItem(id, "state");
			if ( state==3 )
			{
				NetEvent(1);
				CreateEffect(id, "BridgHIT");
				SetSceneItem(id, "pose", 1, 0);
				NetEvent(0);
			}
		}
	}
}

D_bridge01_OnIdle(int id)
{
	if ( g_bBridge01Alive )
	{
		int pose = GetSceneItem(id, "pose");
		if ( pose!=2 )
		{
			return 0;
		}
		int state = GetSceneItem(id, "state");
		if ( state==3 )
		{
			g_bBridge01Alive = 0;
			NetEvent(1);
			SetSceneItem(id, "attribute", "damage", 0);
			SetSceneItem(id, "attribute", "active", 0);
			NetEvent(0);
		}
	}
}

D_bridge02_OnAttack(int id, int characterid, int damage)
{
	if ( g_bBridge02Alive )
	{
		g_iBridge02HP = g_iBridge02HP - damage;
		Output("Bridge 02", g_iBridge02HP);
		if ( g_iBridge02HP <= 0 )
		{
			int pose = GetSceneItem(id, "pose");
			if ( pose==2 )
			{
				return 0;
			}

			NetEvent(1);
			CreateEffect(id, "BridgBRK");
			SetSceneItem(id, "pose", 2, 0);
			SetSceneItem(id, "attribute", "damage", 1);
			SetSceneItem("D_itbridge02", "attribute", "active", 1);
			SetSceneItem("D_itbridge02", "attribute", "interactive", 1);
			NetEvent(0);
		}
		else
		{
			int state = GetSceneItem(id, "state");
			if ( state==3 )
			{
				NetEvent(1);
				CreateEffect(id, "BridgHIT");
				SetSceneItem(id, "pose", 1, 0);
				NetEvent(0);
			}
		}
	}
}

D_bridge02_OnIdle(int id)
{
	if ( g_bBridge02Alive )
	{
		int pose = GetSceneItem(id, "pose");
		if ( pose!=2 )
		{
			return 0;
		}
		int state = GetSceneItem(id, "state");
		if ( state==3 )
		{
			g_bBridge02Alive = 0;
			NetEvent(1);
			SetSceneItem(id, "attribute", "damage", 0);
			SetSceneItem(id, "attribute", "active", 0);
			NetEvent(0);
		}
	}
}