// Bunch of code imported from DoomPawns
class Grenade_SmokeEffectB extends Grenade_SmokeEffectA;

#exec mesh import mesh=MrCloud anivfile=Models\MrCloud_a.3d datafile=Models\MrCloud_d.3d x=0 y=0 z=0 mlod=0
#exec mesh origin mesh=MrCloud x=0 y=0 z=0 YAW=-64 PITCH=0 ROLL=0
#exec mesh sequence mesh=MrCloud seq=All startframe=0 numframes=1

#exec meshmap new meshmap=MrCloud mesh=MrCloud
#exec meshmap scale meshmap=MrCloud x=0.5000 y=0.5000 z=1.0000

#exec TEXTURE IMPORT NAME=SmokeTex1 FILE=Textures\SmokeEffects\SmokeTex1.bmp
#exec MESHMAP SETTEXTURE MESHMAP=MrCloud NUM=0 TEXTURE=SmokeTex1

var PlayerPawn LocalPlayer;

var Player LastReply;
var vector LastCamPos;
var float LastTimeStamp;
var Player RenderObject;
var rotator TheNewRot;

replication
{
   reliable if (Role == ROLE_Authority)
   	TheNewRot;
}

simulated function PostBeginPlay()
{
	if (FRand() < 0.5)
   	RotationRate.Roll = Rand(200);
   else
   	RotationRate.Roll = Rand(200) * -1;
}

simulated function Tick(float DeltaTime)
{
	local float F;


	RenderObject = GetPlayerOwner(Self);
	if(RenderObject != none)
		if(RenderObject.Actor==None)
			Return;
   ScaleGlow = 2 * LifeSpan;
   if(Drawscale <= 2.2)
   	DrawScale += 0.0030;
	if(RenderObject != none)
		TheNewRot = rotator(RenderObject.Actor.location - Location);
	TheNewRot.Roll = Rotation.Roll;
	SetRotation(TheNewRot);
}

Static function Player GetPlayerOwner(Actor Checker)
{
	local PlayerPawn PP;
	local Pawn P;

	if(Default.LastReply!=None)
		Return Default.LastReply;
	if(Checker.Level.NetMode==NM_Client)
	{
		ForEach Checker.AllActors(class'PlayerPawn',PP)
		{
			if(PP.Player!=None && PP.Player.Console!=None)
			{
				Default.LastReply = PP.Player;
				Return PP.Player;
			}
		}
	}
	else
	{
		For(P=Checker.Level.PawnList; P!=None; P=P.NextPawn)
		{
			if(P.IsA('PlayerPawn') && PlayerPawn(P).Player!=None && PlayerPawn(P).Player.Console!=None)
			{
				Default.LastReply = PlayerPawn(P).Player;
				Return PlayerPawn(P).Player;
			}
		}
	}
}

defaultproperties
{
	Physics=PHYS_Rotating
	bFixedRotationDir=True
   EffectSound1=None
   DrawType=DT_Mesh
   Style=STY_Translucent
   Mesh=Mesh'MrCloud'
   Texture=Texture'SmokeTex1'
}
