Engine
Class Spewer

source: c:\runehov\Engine\Classes\Spewer.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.ParticleSystem
         |
         +--Engine.Spewer
Direct Known Subclasses:FireSpewer, MechFireSpewer, MechSteamSpewer, SteamSpewer

class Spewer
extends Engine.ParticleSystem

//============================================================================= // Spewer. //=============================================================================
Variables
 byte AStart
 float ActiveDurationMax
 float ActiveDurationMin
 float DormantDurationMax
 float DormantDurationMin
 enum ESpewerMode
 float ExpandDuration
 float ForceDelta
 float GSpewTime
 float GStateTime
 SpewerMotion MotionPitch
 SpewerMotion MotionYaw
 byte PCount
 float PhaseDelay
 int SPAlphaStart
 int SPMaxParticles
 rotator SPStartRotation
 float ShrinkDuration
 float SpewerDamage
 name SpewerDamageType
 float SpewerForceMax
 float SpewerForceMin
 float SpewerLength
 float SpewerRadius
 bool bAutoStart
 bool bSpewerStopped

States
EmissionPhaseDelay, EmissionLull, EmissionEnd, EmissionContinuous, EmissionBegin, CheckAutoStart

Function Summary
 void CommenceSpewing()
     
//-----------------------------------------------------------------------------
// CommenceSpewing.
//-----------------------------------------------------------------------------
 float FixAngle(float a)
     
//-----------------------------------------------------------------------------
// FixAngle.
//-----------------------------------------------------------------------------
 float GetActiveDuration()
     
//-----------------------------------------------------------------------------
// GetActiveDuration.
//-----------------------------------------------------------------------------
 float GetDormantDuration()
     
//-----------------------------------------------------------------------------
// GetDormantDuration.
//-----------------------------------------------------------------------------
 void InjureNearbyActors()
     
//-----------------------------------------------------------------------------
// InjureNearbyActors.
//-----------------------------------------------------------------------------
 void MotionTick(float deltaTime)
     
//-----------------------------------------------------------------------------
// MotionTick.
//-----------------------------------------------------------------------------
 void PostBeginPlay()
     
//-----------------------------------------------------------------------------
// PostBeginPlay.
//-----------------------------------------------------------------------------
 void Trigger(Actor other, Pawn eventInstigator)
     
//-----------------------------------------------------------------------------
// Trigger.
//-----------------------------------------------------------------------------


State EmissionPhaseDelay Function Summary
 void Trigger(Actor other, Pawn eventInstigator)


State EmissionLull Function Summary
 void Trigger(Actor other, Pawn eventInstigator)


State EmissionEnd Function Summary
 void Trigger(Actor other, Pawn eventInstigator)


State EmissionContinuous Function Summary
 void Trigger(Actor other, Pawn eventInstigator)


State EmissionBegin Function Summary
 void Trigger(Actor other, Pawn eventInstigator)


State CheckAutoStart Function Summary



Source Code


00001	//=============================================================================
00002	// Spewer.
00003	//=============================================================================
00004	class Spewer expands ParticleSystem
00005		abstract;
00006	
00007	#exec Texture Import File=Textures\Spewer.pcx Name=S_Spewer Mips=Off Flags=2
00008	
00009	// EDITABLE INSTANCE VARIABLES ////////////////////////////////////////////////
00010	
00011	var() bool		bAutoStart;
00012	var() float		DormantDurationMax;
00013	var() float		DormantDurationMin;
00014	var() float		ActiveDurationMax;
00015	var() float		ActiveDurationMin;
00016	var() float		SpewerDamage;
00017	var() float		SpewerRadius;
00018	var() float		SpewerLength;
00019	var() float		SpewerForceMin;
00020	var() float		SpewerForceMax;
00021	var() float		ExpandDuration;
00022	var() float		ShrinkDuration;
00023	var() float		PhaseDelay;
00024	var() name		SpewerDamageType;
00025	
00026	struct SpewerMotion
00027	{
00028		var() float MotMagnitude;
00029		var() float MotSpeed;
00030		var() enum ESpewerMotion
00031		{
00032			SPM_Steady,
00033			SPM_Swirl,
00034			SPM_Wave
00035		} MotType;
00036	};
00037	
00038	var() SpewerMotion MotionYaw;
00039	var() SpewerMotion MotionPitch;
00040	
00041	var() enum ESpewerMode
00042	{
00043		SPWM_SingleSurge,		// Spew once when triggered.
00044		SPWM_Constant,			// Constant spewing.  Requires a Trigger message
00045								// to stop.
00046		SPWM_Periodic			// Erupts at regular intervals of time (defined
00047								// by the duration vars).  Requires a Trigger
00048								// message to stop.
00049	} SpewerMode;
00050	
00051	// INSTANCE VARIABLES /////////////////////////////////////////////////////////
00052	
00053	var float	GStateTime;
00054	var float	GSpewTime;
00055	var bool	bSpewerStopped;
00056	var rotator	SPStartRotation;
00057	var int		SPMaxParticles;
00058	var int		SPAlphaStart;
00059	var float	ForceDelta;
00060	var byte	PCount;
00061	var byte	AStart;
00062	
00063	// FUNCTIONS //////////////////////////////////////////////////////////////////
00064	
00065	//-----------------------------------------------------------------------------
00066	// PostBeginPlay.
00067	//-----------------------------------------------------------------------------
00068	function PostBeginPlay()
00069	{
00070		super.PostBeginPlay();
00071		SPStartRotation = Rotation;
00072		SPMaxParticles = ParticleCount;
00073		SPAlphaStart = AlphaStart;
00074		ForceDelta = abs(SpewerForceMax - SpewerForceMin);
00075		bDirectional = false;	// Required for particles' velocity to behave
00076								// correctly.
00077	}
00078	
00079	//-----------------------------------------------------------------------------
00080	// CommenceSpewing.
00081	//-----------------------------------------------------------------------------
00082	function CommenceSpewing()
00083	{
00084		bSpewerStopped = false;
00085		if(PhaseDelay > 0)
00086			GotoState('EmissionPhaseDelay');
00087		else
00088			GotoState('EmissionBegin');
00089	}
00090	
00091	//-----------------------------------------------------------------------------
00092	// Trigger.
00093	//-----------------------------------------------------------------------------
00094	function Trigger(actor other, pawn eventInstigator)
00095	{
00096		CommenceSpewing();
00097	}
00098	
00099	//-----------------------------------------------------------------------------
00100	// GetDormantDuration.
00101	//-----------------------------------------------------------------------------
00102	function float GetDormantDuration()
00103	{
00104		return FMin(DormantDurationMin, DormantDurationMax)
00105			+ Abs(DormantDurationMax-DormantDurationMin)*FRand();
00106	}
00107	
00108	//-----------------------------------------------------------------------------
00109	// GetActiveDuration.
00110	//-----------------------------------------------------------------------------
00111	function float GetActiveDuration()
00112	{
00113		return FMin(ActiveDurationMin, ActiveDurationMax)
00114			+ Abs(ActiveDurationMax-ActiveDurationMin)*FRand();
00115	}
00116	
00117	//-----------------------------------------------------------------------------
00118	// FixAngle.
00119	//-----------------------------------------------------------------------------
00120	function float FixAngle(float a)
00121	{
00122		while(a > 32768)
00123			a -= 65536;
00124		while(a < -32768)
00125			a += 65536;
00126		return a;
00127	}
00128	
00129	//-----------------------------------------------------------------------------
00130	// MotionTick.
00131	//-----------------------------------------------------------------------------
00132	function MotionTick(float deltaTime)
00133	{
00134		local rotator r;
00135		local vector aX, aY, aZ;
00136	
00137		r = Rotation;
00138		switch(MotionYaw.MotType)
00139		{
00140		case SPM_Swirl:
00141			r.Yaw += (MotionYaw.MotSpeed * ANGLE_90) * deltaTime;
00142			break;
00143		case SPM_Wave:
00144			r.Yaw = SPStartRotation.Yaw
00145				+ sin(GSpewTime*4*MotionYaw.MotSpeed)
00146				* ANGLE_45*MotionYaw.MotMagnitude;
00147			break;
00148		}
00149		switch(MotionPitch.MotType)
00150		{
00151		case SPM_Swirl:
00152			r.Pitch += (MotionPitch.MotSpeed * ANGLE_90) * deltaTime;
00153			break;
00154		case SPM_Wave:
00155			r.Pitch = SPStartRotation.Pitch
00156				+ sin(GSpewTime*4*MotionPitch.MotSpeed)
00157				* ANGLE_45*MotionPitch.MotMagnitude;
00158			break;
00159		}
00160		//r.Yaw = FixAngle(r.Yaw);
00161		//r.Pitch = FixAngle(r.Pitch);
00162		SetRotation(r);
00163	
00164		VelocityMax = vector(r)*(SpewerForceMin + ForceDelta*FRand());
00165		VelocityMin = VelocityMax;
00166	}
00167	
00168	//-----------------------------------------------------------------------------
00169	// InjureNearbyActors.
00170	//-----------------------------------------------------------------------------
00171	function InjureNearbyActors()
00172	{
00173		local actor a;
00174		local vector hitLoc, hitNorm;
00175		local vector extent;
00176		
00177		extent.x = SpewerRadius;
00178		extent.y = SpewerRadius;
00179		extent.z = SpewerRadius;
00180		foreach TraceActors(class'actor', a, hitLoc, hitNorm,
00181			Location + vector(Rotation) * SpewerLength, Location, extent, false)
00182		{
00183			a.JointDamaged(SpewerDamage, None, a.Location, vect(0, 0, 0), SpewerDamageType, 0);
00184		}
00185	}
00186	
00187	// STATES /////////////////////////////////////////////////////////////////////
00188	
00189	//-----------------------------------------------------------------------------
00190	// CheckAutoStart.
00191	//-----------------------------------------------------------------------------
00192	auto state CheckAutoStart
00193	{
00194	begin:
00195		bHidden = true;
00196		AlphaStart = 0;
00197		SoundVolume = 0;
00198		if(bAutoStart)
00199			CommenceSpewing();
00200		else
00201			GotoState('');
00202	}
00203	
00204	//-----------------------------------------------------------------------------
00205	// EmissionBegin.
00206	//-----------------------------------------------------------------------------
00207	state EmissionBegin
00208	{
00209		function Trigger(actor other, pawn eventInstigator)
00210		{
00211			if(SpewerMode != SPWM_SingleSurge)
00212				bSpewerStopped = true;
00213		}
00214	
00215		event BeginState()
00216		{
00217			GStateTime = 0.0;
00218			GSpewTime = 0.0;
00219			bHidden = false;
00220		}
00221	
00222		event Tick(float deltaTime)
00223		{
00224			GStateTime += deltaTime;
00225			GSpewTime += deltaTime;
00226			MotionTick(deltaTime);
00227	
00228			PCount = 1+GStateTime*(SPMaxParticles/ExpandDuration);
00229			AStart = GStateTime*(SPAlphaStart/ExpandDuration);
00230			ParticleCount = Clamp(PCount, 1, SPMaxParticles);
00231			AlphaStart = Clamp(AStart, 0, SPAlphaStart);
00232			SoundVolume = Clamp(GStateTime*(160/ExpandDuration), 0, 128);
00233			if(GStateTime >= ExpandDuration)
00234			{
00235				ParticleCount = SPMaxParticles;
00236				if(bSpewerStopped == true)
00237					GotoState('EmissionEnd');
00238				else
00239					GotoState('EmissionContinuous');
00240			}
00241		}
00242	
00243	begin:
00244	}
00245	
00246	//-----------------------------------------------------------------------------
00247	// EmissionContinuous.
00248	//-----------------------------------------------------------------------------
00249	state EmissionContinuous
00250	{
00251		event BeginState()
00252		{
00253			GStateTime = 0.0;
00254			SetTimer(0.25, true);
00255		}
00256	
00257		function Trigger(actor other, pawn eventInstigator)
00258		{
00259			if(SpewerMode != SPWM_SingleSurge)
00260			{
00261				bSpewerStopped = true;
00262				GotoState('EmissionEnd');
00263			}
00264		}
00265	
00266		event Tick(float deltaTime)
00267		{
00268			GStateTime += deltaTime;
00269			GSpewTime += deltaTime;
00270			MotionTick(deltaTime);
00271		}
00272	
00273		event Timer()
00274		{
00275			InjureNearbyActors();
00276		}
00277	
00278	begin:
00279		if(SpewerMode != SPWM_Constant)
00280		{
00281			Sleep(GetActiveDuration());
00282			GotoState('EmissionEnd');
00283		}
00284	}
00285	
00286	//-----------------------------------------------------------------------------
00287	// EmissionEnd.
00288	//-----------------------------------------------------------------------------
00289	state EmissionEnd
00290	{
00291		event BeginState()
00292		{
00293			GStateTime = 0.0;
00294		}
00295	
00296		function Trigger(actor other, pawn eventInstigator)
00297		{
00298			if(SpewerMode != SPWM_SingleSurge)
00299				bSpewerStopped = true;
00300		}
00301	
00302		event Tick(float deltaTime)
00303		{
00304			GStateTime += deltaTime;
00305			GSpewTime += deltaTime;
00306			MotionTick(deltaTime);
00307	
00308			PCount = SPMaxParticles - GStateTime*(SPMaxParticles/ShrinkDuration);
00309			AStart = SPAlphaStart - GStateTime*(SPAlphaStart/ShrinkDuration);
00310			ParticleCount = Clamp(PCount, 1, SPMaxParticles);
00311			AlphaStart = Clamp(AStart, 0, SPAlphaStart);
00312			SoundVolume = Clamp(128 - GStateTime*(128/ShrinkDuration), 0, 128);
00313			if(GStateTime >= ShrinkDuration)
00314			{
00315				AlphaStart = 0;
00316				ParticleCount = 1;
00317				if(SpewerMode == SPWM_Periodic && bSpewerStopped == false)
00318					GotoState('EmissionLull');
00319				else
00320					GotoState('');
00321			}
00322		}
00323	
00324	begin:
00325	}
00326	
00327	//-----------------------------------------------------------------------------
00328	// EmissionLull.
00329	//-----------------------------------------------------------------------------
00330	state EmissionLull
00331	{
00332		event BeginState()
00333		{
00334			bHidden = true;
00335		}
00336	
00337		function Trigger(actor other, pawn eventInstigator)
00338		{
00339			GotoState('');
00340		}
00341	
00342	begin:
00343		Sleep(GetDormantDuration());
00344		GotoState('EmissionBegin');
00345	}
00346	
00347	//-----------------------------------------------------------------------------
00348	// EmissionPhaseDelay.
00349	//-----------------------------------------------------------------------------
00350	state EmissionPhaseDelay
00351	{
00352		function Trigger(actor other, pawn eventInstigator)
00353		{
00354			GotoState('');
00355		}
00356	
00357	begin:
00358		Sleep(PhaseDelay);
00359		GotoState('EmissionBegin');
00360	}
00361	
00362	//-----------------------------------------------------------------------------
00363	// Debug.
00364	//-----------------------------------------------------------------------------
00365	simulated function Debug(Canvas canvas, int mode)
00366	{
00367		Super.Debug(canvas, mode);
00368		Canvas.DrawText("   VelocityMax: " $ VelocityMax);
00369		Canvas.CurY -= 8;
00370		Canvas.DrawText("        pcount: " $ pcount);
00371		Canvas.CurY -= 8;
00372		Canvas.DrawText("        astart: " $ astart);
00373		Canvas.CurY -= 8;
00374		
00375		Canvas.DrawLine3D(Location, Location + vector(Rotation) * SpewerLength, 255, 0, 0);
00376	}
00377	
00378	defaultproperties
00379	{
00380	     bForceRender=True
00381	     Texture=Texture'Engine.S_Spewer'
00382	}

End Source Code