//=============================================================================
// MagmaBurst.
//=============================================================================
class MagmaBurst expands Rockslide;
    
// Spawns off a number of Magma elements, which all die out
// within a random amount of time.  This code modified from 
// Sparks.  MZM
								// Reasonable defaults
var() int      MinSpawnedAtOnce;	// 1
var() int      MaxSpawnedAtOnce;	// 3
var() float    MinSpawnSpeed;		// 200
var() float    MaxSpawnSpeed;		// 300
var() float    MinBurnTime;		// 0.4
var() float    MaxBurnTime;		// 1.0
var() float    MinBrightness;		// 0.7	(values can only go from 0.0 -> 1.0)
var() float    MaxBrightness;		// 1.0    "							   "
var() Rotation SpawnCenterDir;
var() int      AngularDeviation;	// approx. 0x2000 -> 8192

function MoreMagma () 
{
	local vector    SpawnLoc;
	local Magma 	   TempMagma;
	local FlameBall TempFlame;
	local Rotation  SpawnDir;

	SpawnLoc = Location - (CubeDimensions*0.5);
	SpawnLoc.X += FRand()*CubeDimensions.X;
	SpawnLoc.Y += FRand()*CubeDimensions.Y;
	SpawnLoc.Z += FRand()*CubeDimensions.Z;

	// Time to generate another Magma Rock.
	TempMagma = Spawn (class 'Magma', , '', SpawnLoc);
	
	// Spawn a lava burst as the magma flies out
	TempFlame = Spawn (class 'FlameBall', , '', SpawnLoc);

	SpawnDir = SpawnCenterDir;
	SpawnDir.Pitch += -AngularDeviation + Rand(AngularDeviation*2);
	SpawnDir.Yaw   += -AngularDeviation + Rand(AngularDeviation*2);
	TempMagma.SetRotation(SpawnDir);
	TempMagma.RotationRate = Rotation(VRand());
	TempMagma.Speed    = (MinSpawnSpeed + 
	                       FRand()*(MaxSpawnSpeed-MinSpawnSpeed));

	TempMagma.BurnTime = MinBurnTime + FRand()*(MaxBurnTime-MinBurnTime);

	// 0=dark  1=bright
	TempMagma.InitialBrightness = MinBrightness + 
			     			     FRand()*(MaxBrightness-MinBrightness);

	TempMagma.DrawScale = (MaxScaleFactor-MinScaleFactor)*FRand()+MinScaleFactor;
}


state() Active 
{
	function MakeRock()
	{
		local int i, NumSpawnedNow;

		NumSpawnedNow = Rand(MaxSpawnedAtOnce-MinSpawnedAtOnce+1)+MinSpawnedAtOnce;
		for (i=0; i<NumSpawnedNow; i++)
			MoreMagma();
	}
}


auto state() Triggered 
{
	function Trigger (actor Other, pawn EventInstigator) 
	{
		GotoState ('Active');
	}
}

