class IceBase expands Decoration;

#exec MESH IMPORT MESH=IceBase ANIVFILE=MODELS\IceBase_a.3d DATAFILE=MODELS\IceBase_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=IceBase STRENGTH=0
#exec MESH ORIGIN MESH=IceBase X=0 Y=0 Z=-16

#exec MESH SEQUENCE MESH=IceBase SEQ=All STARTFRAME=0 NUMFRAMES=3
#exec MESH SEQUENCE MESH=IceBase SEQ=Shrink STARTFRAME=0 NUMFRAMES=2 RATE=1.0
#exec MESH SEQUENCE MESH=IceBase SEQ=Grow STARTFRAME=1 NUMFRAMES=2 RATE=4.0

#exec MESHMAP NEW MESHMAP=IceBase MESH=IceBase
#exec MESHMAP SCALE MESHMAP=IceBase X=0.2 Y=0.2 Z=0.3

var bool bEndLife;
var() bool bDestructable;
var() int IceHealth;

simulated function PostBeginPlay()
{
	PlayAnim('Grow', 1.0);
	PlaySound(Sound'WaterFreeze',, 10.0);
	SetTimer(0.3, True);
	Super.PostBeginPlay();
}


function Bump( actor Other )
{
    local float speed, oldZ;
    if( bPushable && (Pawn(Other)!=None) && (Other.Mass > 40) && Level.NetMode == NM_StandAlone)
    {
        bBobbing = false;
        oldZ = Velocity.Z;
        speed = VSize(Other.Velocity);
        Velocity = Other.Velocity * FMin(120.0, 20 + speed)/speed;
        if ( Physics == PHYS_None ) {
            Velocity.Z = 25;
            if (!bPushSoundPlaying) PlaySound(PushSound, SLOT_Misc,0.25);
            bPushSoundPlaying = True;          
        }
        else
            Velocity.Z = oldZ;
        SetPhysics(PHYS_Falling);
        Instigator = Pawn(Other);
    }
}

function TakeDamage( int NDamage, Pawn instigatedBy, Vector hitlocation, vector momentum, name damageType )
{
	if (DamageType != 'Freezed')
		IceHealth -= NDamage;

	If ((IceHealth <= 0 || DamageType == 'Burned') && bDestructable)
	{
		ReleaseFragEffect(class'FragmentIce', Texture'Ice', Momentum, DrawScale * 1.5, 8);
		PlaySound(Sound'IceHit',, 30.0);

		Instigator = InstigatedBy;

		if (Instigator != None)
			MakeNoise(1.0);
	}
}




simulated function Timer()
{
local Actor A;
local bool bSomething;
	
	if (Level.NetMode == NM_StandAlone)
	{
	ForEach VisibleCollidingActors(Class'Actor', A, CollisionRadius, Location + (CollisionHeight + CollisionRadius) * vect(0,0,1))
		{
			If (A != Self && A.Base == Self)
			{
				bSomething = True;
				Mass = Default.Mass + A.Mass;
			}
		}

		if (!bSomething)
		{
			Mass = Default.Mass;
		}
	}
	else
	{
		SetPhysics(PHYS_None);
		SetTimer(0.1, False);
		RemoteRole = ROLE_DumbProxy;
	}

	if (Region.Zone.DamageType == 'Burned')
		Destroy();
}

simulated function Tick( float DeltaTime)
{
	if (LifeSpan <= 1 && !bEndLife)
	{
		bEndLife = True;
		PlayAnim('Shrink', 1.0);
		RemoteRole = ROLE_SimulatedProxy;
	}

	if(LifeSpan <= 1)
		ScaleGlow = LifeSpan * Default.ScaleGlow;
}


simulated function ReleaseFragEffect(class<fragment> FragType, texture FragSkin, vector Momentum, float DSize, int NumFrags) 
{
	local int i;
	local actor A, Toucher;
	local Fragment s;

	for (i=0 ; i<NumFrags ; i++) 
	{
		s = Spawn( FragType, Owner);
		s.CalcVelocity(Momentum/100,0);
		s.Skin = FragSkin;
		s.Texture = FragSkin;
		s.DrawScale = DSize*0.5+0.7*DSize*FRand();
		s.Style = STY_Translucent;
		s.bMeshEnviroMap = True;
	}

	Destroy();
}

defaultproperties
{
	DrawType=DT_Mesh
	Mesh=IceBase
	RemoteRole=ROLE_SimulatedProxy
	Style=STY_Translucent
	bMeshEnviroMap=True
	Texture=Ice
	ScaleGlow=2.000000
	CollisionHeight=39.000000
	CollisionRadius=120.000000
	bBlockPlayers=True
	bBlockActors=True
	bCollideWorld=True
	bCollideActors=True
	bProjTarget=True
	DrawScale=1.000000
	bNetTemporary=False
	LifeSpan=20.000000
	Mass=150.000000
	Buoyancy=250.000000
	bStatic=False
	bStasis=False
	Physics=PHYS_Falling
	bPushable=True
	bFixedRotationDir=True
	bGameRelevant=True
	bDestructable=True
	IceHealth=30
}
