//=============================================================================
// sgPlatform 4th gen
// New platform prototype for 4th gen siege
// Made by Higor
//=============================================================================
class sgPlatform expands sgBuilding;

var sgBuildingCH TCH;
var float BaseEnergy;

var pawn rPlayers[16];
var int iP;

var Info EXMPlugin;

replication
{
	reliable if ( bNetInitial && Role==ROLE_Authority )
		TCH;
}

event PostBeginPlay()
{
	SetLocation(Location-vect(0,0,20));
	super.PostBeginPlay();
}

simulated event PostNetBeginPlay()
{
	local info I;
	SetLocation(Location-vect(0,0,2));
	Super.PostNetBeginPlay();
	if ( TCH != none )
		TCH.MyBuild = self;
	ForEach AllActors (class'Info', I, 'EXM')
		if ( I.IsA('EXM_Master') )
		{
			EXMPlugin = I;
			break;
		}
}


simulated function FinishBuilding()
{
	Super.FinishBuilding();
	if ( (Level.NetMode != NM_Client) && (TCH == None) )
	{
		TCH=Spawn(class'sgBuildingCH',Self,'',Location,Rotation);
		TCH.Setup( Self, 60, 15, vect(0,0,0), 1);
	}

	BaseEnergy = MaxEnergy;
	Texture = None;
	if (myFX!=None)
	{
		myFX.AmbientGlow=5;
		myFX.ScaleGlow=1.5;
	}
}

simulated function Destruct( optional pawn instigatedBy)
{
	local Pawn p;

	foreach VisibleCollidingActors(class'Pawn', p, 95)
		if ( p.bIsPlayer && (p.Health > 0) && (p.PlayerReplicationInfo != None) )
			p.TakeDamage((Grade/2)+1 , instigator, vect(10,10,0), vect(10,10,0), 'sgSpecial');

	Super(sgBuilding).Destruct( instigatedBy);
}

function Upgraded()
{
	local float percent, scale;

	percent = Energy/BaseEnergy;
	MaxEnergy = BaseEnergy * (1 + Grade/5);
	Energy = percent * MaxEnergy;
}

// Bring the building back to normal
function BackToNormal()
{
	Super.BackToNormal();
	LightType=LT_None;
	Texture=None;
}

simulated event TakeDamage( int dam, Pawn instBy, Vector hitLoc, Vector mom, name dmgType )
{
	local float PistonCharge;
	local vector aVec;
	Super.TakeDamage( dam, instBy, hitLoc, mom, dmgType);
	//PISTON!
	if ( (instBy != none) && (dmgType == 'impact') && (ImpactHammer(instBy.Weapon) != none) )
	{
		PistonCharge = dam;
		PistonCharge /= 60;
		aVec = instBy.Velocity;
		instBy.TakeDamage(36.0 / (Grade+1.0), instBy, hitLoc, -69000.0 * PistonCharge * vector(instBy.ViewRotation), 'impact');
		if ( EXMPlugin != none )
		{
			EXMPlugin.SetPropertyText("bNewEvent","1");
			EXMPlugin.SetPropertyText("NewEventType","1");
			EXMPlugin.SetPropertyText("NewFixedVelocity",string(instBy.Velocity - aVec) );
			EXMPlugin.Trigger( self, instBy);
		}
	}
}
/*
simulated function CollisionJump( Pawn Other)
{
	if ( (PlayerPawn(Other) != none) && (Other.Role == ROLE_AutonomousProxy) && PlayerPawn(Other).bCanTeleport && !PlayerPawn(Other).bUpdating && (EXMPlugin != none) )
	{
		EXMPlugin.SetPropertyText("bNewEvent","1");
		EXMPlugin.SetPropertyText("NewFixedVelocity",string( Other.Velocity) );
		EXMPlugin.Trigger( self, Other);
	}
}
*/

function AlterNetRate()
{
	if ( Energy < MaxEnergy )
		NetUpdateFrequency = 10;
	else
		NetUpdateFrequency = 8;
}


defaultproperties
{
     BuildingName="Platform"
     BuildCost=200
     UpgradeCost=20
     BuildTime=5.000000
     MaxEnergy=2000.000000
     SpriteScale=1.000000
     Model=LodMesh'Botpack.DiscStud'
     SkinRedTeam=Texture'PlatformSkinT0'
     SkinBlueTeam=Texture'PlatformSkinT1'
     SpriteRedTeam=Texture'PlatformSpriteT0'
     SpriteBlueTeam=Texture'PlatformSpriteT1'
     DSofMFX=4.000000
     SkinGreenTeam=Texture'PlatformSkinT2'
     SkinYellowTeam=Texture'PlatformSkinT3'
     SpriteGreenTeam=Texture'PlatformSpriteT2'
     SpriteYellowTeam=Texture'PlatformSpriteT3'
     MFXrotX=(Yaw=10000)
     MultiSkins(0)=Texture'PlatformSpriteT0'
     MultiSkins(1)=Texture'PlatformSpriteT1'
     MultiSkins(2)=Texture'PlatformSpriteT2'
     MultiSkins(3)=Texture'PlatformSpriteT3'
     CollisionRadius=61.000000
     CollisionHeight=17.000000
     BuildDistance=50
     bStandable=True
     GUI_Icon=Texture'GUI_Platform'
}
