class XJumpPad expands Triggers;

//Model import
#exec mesh import mesh=XJumpPad anivfile=Models\WildCardBaseM_a.3d datafile=Models\WildCardBaseM_d.3d x=0 y=0 z=0 MLOD=1 LODSTYLE=0
#exec mesh origin mesh=XJumpPad x=0 y=0 z=0 PITCH=-64
#exec mesh sequence mesh=XJumpPad seq=All startframe=0 numframes=1

#exec meshmap new meshmap=XJumpPad mesh=XJumpPad
#exec meshmap scale meshmap=XJumpPad x=0.15 y=0.15 z=0.3

//Skins import
#exec TEXTURE IMPORT NAME=XJumpPad FILE=SKINS\WildCardBaseT.pcx GROUP=Skins FLAGS=2
#exec MESHMAP SETTEXTURE MESHMAP=XJumpPad NUM=0 TEXTURE=WildCardBaseT

//Additional textures import
#exec TEXTURE IMPORT NAME=RedStreak FILE=JParticles\RedStreak.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=RedGrid FILE=JParticles\RedGrid.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=BlueStreak FILE=JParticles\BlueStreak.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=BlueGrid FILE=JParticles\BlueGrid.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=GreenStreak FILE=JParticles\GreenStreak.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=GreenGrid FILE=JParticles\GreenGrid.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=PurpleStreak FILE=JParticles\PurpleStreak.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=PurpleGrid FILE=JParticles\PurpleGrid.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=OrangeStreak FILE=JParticles\OrangeStreak.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=OrangeGrid FILE=JParticles\OrangeGrid.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=WhiteStreak FILE=JParticles\WhiteStreak.bmp GROUP=Particles FLAGS=2
#exec TEXTURE IMPORT NAME=WhiteGrid FILE=JParticles\WhiteGrid.bmp GROUP=Particles FLAGS=2


var float TCountA, TCountB;

var enum EParticleColor
{
	PCLR_Red,
	PCLR_Blue,
	PCLR_Green,
	PCLR_Yellow,
	PCLR_Purple,
	PCLR_Orange,
	PCLR_White
} PT;

var() EParticleColor ParticlesColor;

var() float JumpForce;
var() bool UseAbsoluteVel;
var() vector AbsoluteVel;

var() bool EnableJump;
var() bool bDecorative;

var() sound KickSound;

function Tick(float DeltaTime)
{
local vector X, Y, Z;
local int rX, rY;
local JPadEmitPrtc JStreak;
local JPadEmitGrid JGrid;
local byte j;

	if (EnableJump)
	{

	TCountA += DeltaTime;
	TCountB += DeltaTime;

	if (TCountA >= 0.15)
	{
		TCountA = 0;

		GetAxes(Rotation, X, Y, Z);
		
		For (j=0; j<4; j++)
		{

		rX = (Rand(57) - 28) * DrawScale;
		rY = (Rand(57) - 28) * DrawScale;

		if (!UseAbsoluteVel)
		{
			JStreak = Spawn(Class'JPadEmitPrtc',,, Location + rX*Z + rY*Y + 4*X, Rotation);
			JStreak.Velocity = vector(Rotation) * FRand() * 160 * DrawScale;
		}
		else
		{
			JStreak = Spawn(Class'JPadEmitPrtc',,, Location + rX*Z + rY*Y + 4*X, rotator(AbsoluteVel));
			JStreak.Velocity = Normal(AbsoluteVel) * FRand() * 160 * DrawScale;
		}

		JStreak.DrawScale = DrawScale;

		if (ParticlesColor == PCLR_Red)
			JStreak.MultiSkins[1] = Texture'RedStreak';
		else if (ParticlesColor == PCLR_Blue)
			JStreak.MultiSkins[1] = Texture'BlueStreak';
		else if (ParticlesColor == PCLR_Green)
			JStreak.MultiSkins[1] = Texture'GreenStreak';
		else if (ParticlesColor == PCLR_Purple)
			JStreak.MultiSkins[1] = Texture'PurpleStreak';
		else if (ParticlesColor == PCLR_Orange)
			JStreak.MultiSkins[1] = Texture'OrangeStreak';
		else if (ParticlesColor == PCLR_White)
			JStreak.MultiSkins[1] = Texture'WhiteStreak';

		}
	}

	if (TCountB >= 0.25)
	{
		TCountB = 0;

		GetAxes(Rotation, X, Y, Z);
		JGrid = Spawn(Class'JPadEmitGrid',,, Location + 4*X);
		
		if (!UseAbsoluteVel)
			JGrid.Velocity = vector(Rotation) * 50 * DrawScale;
		else
			JGrid.Velocity = Normal(AbsoluteVel) * 50 * DrawScale;

		JGrid.DrawScale = DrawScale;

		if (ParticlesColor == PCLR_Red)
			JGrid.MultiSkins[1] = Texture'RedGrid';
		else if (ParticlesColor == PCLR_Blue)
			JGrid.MultiSkins[1] = Texture'BlueGrid';
		else if (ParticlesColor == PCLR_Green)
			JGrid.MultiSkins[1] = Texture'GreenGrid';
		else if (ParticlesColor == PCLR_Purple)
			JGrid.MultiSkins[1] = Texture'PurpleGrid';
		else if (ParticlesColor == PCLR_Orange)
			JGrid.MultiSkins[1] = Texture'OrangeGrid';
		else if (ParticlesColor == PCLR_White)
			JGrid.MultiSkins[1] = Texture'WhiteGrid';
	}

	}
}

function Trigger( actor Other, pawn EventInstigator )
{
	EnableJump = !EnableJump;
}


simulated function Touch( actor Other )
{
    local Actor A;


	if (!bDecorative && EnableJump)
	{

    if ( !Other.IsA('Pawn') )
        return;
    PendingTouch = Other.PendingTouch;
    Other.PendingTouch = self;
    if( Event != '' )
        foreach AllActors( class 'Actor', A, Event )
            A.Trigger( Other, Other.Instigator );
	}
}

simulated function PostTouch( actor Other )
{
    local bool bWasFalling;
    local vector Push;
    local float PMag;
	local vector KickVelocity;


	if (!bDecorative && EnableJump)
	{

    bWasFalling = ( Other.Physics == PHYS_Falling );
    Push.Z = -1 * Other.Velocity.Z;

	if (!UseAbsoluteVel)
		KickVelocity = vector(Rotation) * JumpForce;
	else
		KickVelocity = AbsoluteVel;

    Push += KickVelocity;

    if ( Other.IsA('Bot') )
    {
        if ( bWasFalling )
            Bot(Other).bJumpOffPawn = true;
        Bot(Other).SetFall();
    }

    Other.SetPhysics(PHYS_Falling);
    Other.Velocity += Push;

	MakeSound(Other);

	}
}

function MakeSound(actor Other)
{
	if (KickSound != None)
		Other.PlaySound(KickSound);
}



defaultproperties
{
	DrawType=DT_Mesh
	Mesh=XJumpPad
	RemoteRole=ROLE_SimulatedProxy
	bStatic=false
	bHidden=False
	DrawScale=1.000000
	ParticlesColor=PCLR_Yellow
	EnableJump=True
	KickSound=Sound'BootJmp'
}
