class StickyMine expands Projectile;

#exec MESH IMPORT MESH=StickyMine ANIVFILE=MODELS\StickyMine_a.3d DATAFILE=MODELS\StickyMine_d.3d X=0 Y=0 Z=0
#exec MESH LODPARAMS MESH=StickyMine STRENGTH=0.25
#exec MESH ORIGIN MESH=StickyMine X=0 Y=0 Z=0 PITCH=64

#exec MESH SEQUENCE MESH=StickyMine SEQ=All STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=StickyMine SEQ=Still STARTFRAME=0 NUMFRAMES=1

#exec MESHMAP NEW MESHMAP=StickyMine MESH=StickyMine
#exec MESHMAP SCALE MESHMAP=StickyMine X=0.04 Y=0.04 Z=0.08

#exec TEXTURE IMPORT NAME=Sk_StickyMine FILE=SKINS\Sk_StickyMine.bmp GROUP=Skins FLAGS=2 LODSET=2
#exec MESHMAP SETTEXTURE MESHMAP=StickyMine NUM=1 TEXTURE=Sk_StickyMine

#exec OBJ LOAD FILE=..\Sounds\Activates.uax


var vector initialDir;
var() float SensorRadius, SensorHeight;
var bool HasT;
var MineTarget MT;

var int Kickback;
var float Splasher, MoreDamage;
var bool HealthGiver;

replication
{
	// Things the server should send to the client.
	reliable if(Role==ROLE_Authority)
		Kickback, MoreDamage, HealthGiver, Splasher;
}


simulated function PostBeginPlay()
{
	Super.PostBeginPlay();
	Velocity = Vector(Rotation) * Speed;     
	initialDir = Velocity;
	Velocity.z += 200; 
	initialDir = Velocity;
	HasT = False;
}


simulated function ZoneChange( Zoneinfo NewZone )
	{
		local waterring w;
		
		if (!NewZone.bWaterZone) Return;

		if ( Level.NetMode != NM_DedicatedServer )
		{
			w = Spawn(class'WaterRing',,,,rot(16384,0,0));
			w.DrawScale = 0.2;
			w.RemoteRole = ROLE_None;
		}		
		Velocity=0.6*Velocity;
	}


function ProcessTouch (Actor Other, Vector HitLocation)
{
	if ( !Other.IsA('Projectile') && !Other.IsA('Pawn') && !HasT && Other.Tag != 'NoMines' && !Other.IsA('MineTarget'))
		Landed(Normal(-Velocity));

	if ((Other.Instigator == Instigator || Other.Owner == Instigator) && !Other.IsA('TranslocatorTarget') && !Other.IsA('Pawn'))
		return;
	else if (Other.IsA('Pawn'))
	{
		if (Pawn(Other).PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team && Level.Game.IsA('TeamGamePlus') && !Level.Game.IsA('MonsterHunt'))
			return;
	}

	if (!Level.Game.IsA('DeathMatchPlus') && Other.IsA('Pawn'))
	{
		if (Pawn(Other) == Instigator)
			return;
		else if (Pawn(Other).IsA('ScriptedPawn') && Instigator.IsA('ScriptedPawn'))
		{
			if (ScriptedPawn(Pawn(Other)).TeamTag == ScriptedPawn(Instigator).TeamTag && ScriptedPawn(Pawn(Other)).TeamTag != '')
				return;
		}
		else if (Instigator.IsA('PlayerPawn') && (Pawn(Other).AttitudeToPlayer == ATTITUDE_Friendly || Pawn(Other).AttitudeToPlayer == ATTITUDE_Follow))
			return;
	}

	if (Other.Tag == 'IsFriend')
		return;
	
	If ( Other.Tag != ('NoProxy') && (Other.IsA('Pawn') || Other.IsA('Vehicle') || Other.IsA('StrangeShell') || 
	Other.IsA('WarShell') || Other.IsA('TranslocatorTarget') || Other.IsA('IceBase') || Other.IsA('DumbDoll') || Other.IsA('MegaIce') || Other.IsA('Carcass') || Other.IsA('DumbRocket')) && (Other != instigator) && 
	( ( Other.Instigator.PlayerReplicationInfo.Team != Instigator.PlayerReplicationInfo.Team && Level.Game.IsA('TeamGamePlus')) || 
	!Level.Game.IsA('TeamGamePlus')) && !Level.Game.IsA('MonsterHunt') || Other.IsA('ScriptedPawn'))
		BlowUp(Location);
	else if( Other.IsA('ScriptedPawn') || Other.IsA('TranslocatorTarget'))
			BlowUp(Location);
}


simulated function Landed( vector HitNormal )
{
	SetRotation(rotator(-HitNormal));
	SetPhysics(PHYS_None);
	SetCollisionSize( SensorRadius * FMax(1.0, Splasher), SensorHeight * FMax(1.0, Splasher));
	HasT = True;
	PlaySound(Sound'Activates.Beeps.mactiv60',,12.0,,300);

	MT = Spawn(Class'MineTarget', Self);
}



simulated function HitWall (vector HitNormal, actor Wall)
{
	if (!Wall.IsA('Mover'))
		Landed( HitNormal);
	else
		BlowUp(Location);
}


function BlowUp(vector HitLocation)
{
        HurtRadiusX(Damage * FMax(1.0,MoreDamage), 128 * FMax(1.0, Splasher), MyDamageType, MomentumTransfer * (KickBack + 1), HitLocation);

	Spawn(ExplosionDecal,,,,rot(16384,0,0));
	Spawn(Class'StickyExpl');
	Spawn(Class'SmkRing');
        
	MakeNoise(1.5);

	Destroy();
}


simulated function Destroyed()
{
	if (MT != None)
		MT.Destroy();

	Super.Destroyed();
}


//Special HurtRadius - With Health giving implementation
//******************************************************************************************************************
function HurtRadiusX( float DamageAmount, float DamageRadius, name DamageName, float Momentum, vector HitLocation )
{
    local actor Victims;
    local float damageScale, dist;
    local vector dir;
    local Pawn P;
    
    if( bHurtEntry )
        return;

    bHurtEntry = true;
    foreach VisibleCollidingActors( class 'Actor', Victims, DamageRadius, HitLocation )
    {
	if (HealthGiver && Victims.IsA('Pawn'))
	{
		dir = Victims.Location - HitLocation;
		dist = FMax(1,VSize(dir));
		dir = dir/dist; 
		damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);

		P = Pawn(Victims);
		If (((P.PlayerReplicationInfo.Team == Instigator.PlayerReplicationInfo.Team && Level.Game.IsA('TeamGamePlus') && !Level.Game.IsA('MonsterHunt')) ||
		(Level.Game.IsA('MonsterHunt') && !P.IsA('ScriptedPawn')) || P==Instigator) && 
		P.Health < Class'NWMutator'.default.MaxHealth)
		{
			P.Health += damageScale * DamageAmount * FMax(1.0,MoreDamage);
			if (P.Health > Class'NWMutator'.default.MaxHealth)
				P.Health = Class'NWMutator'.default.MaxHealth;
		}
		else
		{
        	if( Victims != self )
        	{
         	   Victims.TakeDamage(
                	damageScale * DamageAmount,
                	Instigator, 
			Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
			(damageScale * Momentum * dir),
			DamageName
			);
        	}
	}
		
	}
	else
	{
        if( Victims != self )
        {
            dir = Victims.Location - HitLocation;
            dist = FMax(1,VSize(dir));
            dir = dir/dist; 
            damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);
            Victims.TakeDamage
            (
                damageScale * DamageAmount,
                Instigator, 
                Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
                (damageScale * Momentum * dir),
                DamageName
            );
        }
	}
    }

    bHurtEntry = false;
}
//******************************************************************************************************************


defaultproperties
{
	DrawType=DT_Mesh
	Mesh=StickyMine
	bBounce=True
	RemoteRole=ROLE_SimulatedProxy
	Damage=40.000000
	MaxSpeed=2000.000000
	MomentumTransfer=75000
	MyDamageType=Exploded
	speed=1200.000000
	DrawScale=1.000000
	ExplosionDecal=Class'MineDecal'
	bNetTemporary=False
	SensorRadius=64.000000
	SensorHeight=64.000000
	Physics=PHYS_Falling
	Mass=100.000000
	LifeSpan=0.000000
}
