//=============================================================================
// BubbleGenerator.
//=============================================================================
class BubbleGenerator expands Decoration;

#exec Texture Import File=models\bubble1.pcx  Name=S_bubble1 Mips=Off Flags=2

var class BubbleType[5];
var float variance;
var() float GenerationRate;  // 0 to 1
var() float Size;            // 0 to 1
var() float NumBubbles;
var int i;

Auto state Active
{

function Timer()
{
	local vector X,Y,Z;
	local bubble b;

	i++;
	if (i>NumBubbles) UnTouch(None);
	if ( Pawn(Owner) != None )
	{
		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
		b = bubble(Spawn(BubbleType[int(FRand()*4+0.5)], Owner, '', Location
			+ (FRand()*8-4) * X - (FRand()*8-4) * Y));
	}
	else
		b = bubble(Spawn(BubbleType[int(FRand()*4+0.5)], self));

	Variance = FRand()*Size/3+Size/3;
	b.DrawScale = Variance;
	b.buoyancy = b.mass + variance*2;
	if (FRand()<0.1) {
		if (FRand()<0.3) SetTimer(FRand()*GenerationRate/5+GenerationRate/5,True);
		else SetTimer(FRand()*GenerationRate/2+GenerationRate/2,True);
	}
}

function Trigger( actor Other, pawn EventInstigator )
{
	SetTimer(FRand()*GenerationRate/2+GenerationRate/2,True);
	i=0;
}

function Touch( actor Other)
{
	SetTimer(FRand()*GenerationRate/2+GenerationRate/2,True);
	i=0;
}

function UnTouch( actor Other)
{
	SetTimer(0.0, False);
}


Begin:
	bHidden = True;
	if (GenerationRate > 1.0) GenerationRate = 1.0;
	if (GenerationRate < 0.03) GenerationRate = 0.03;
	if (Size > 1.0) Size = 1.0;
	if (Size < 0.03) Size = 0.03;	
}

