RuneI
Class BeamSystem

source: c:\runehov\RuneI\Classes\BeamSystem.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.ParticleSystem
         |
         +--RuneI.BeamSystem
Direct Known Subclasses:Beam, BeamChain, BeamRope, BeamVine, Chain, DarkDwarfConcentrator, DarkDwarfLightning, DarkDwarfLightning2, Electricity, LightningSwordBeam, Rope, SonicBeam, TreePt

class BeamSystem
extends Engine.ParticleSystem

//============================================================================= // BeamSystem. //=============================================================================
Variables
 float BeamTime


Function Summary
 
simulated
Debug(Canvas canvas, int mode)
 void PostBeginPlay()
     
/*
 void PreBeginPlay()
     
//=============================================================================
//
// PreBeginPlay
//
// Sets up the ParticleCount to be equivalent to NumConPts * 3
//=============================================================================
 void SpawnBeamDebris()
     
//=============================================================================
//
// SpawnBeamDebris
//
//=============================================================================
 void SystemInit()
     
//=============================================================================
//
// SystemInit
//
// Called when the particle system is initialize IF bEventSystemInit is true
//=============================================================================

 void Timer()



Source Code


00001	//=============================================================================
00002	// BeamSystem.
00003	//=============================================================================
00004	class BeamSystem expands ParticleSystem;
00005	
00006	var float BeamTime;
00007	var(ParticleSystem) name TargetTag;
00008	
00009	//=============================================================================
00010	//
00011	// PreBeginPlay
00012	//
00013	// Sets up the ParticleCount to be equivalent to NumConPts * 3
00014	//=============================================================================
00015	
00016	function PreBeginPlay()
00017	{
00018		local actor A;
00019		local int i;
00020	
00021		Super.PreBeginPlay();
00022	
00023		ParticleCount = NumConPts * 3;
00024	
00025		if (TargetTag != '')
00026		{
00027			foreach AllActors(class'actor', A, TargetTag)
00028			{
00029				Target = A;
00030			}
00031		}
00032	
00033		for(i = 0; i < NumConPts; i++)
00034			ConnectionPoint[i] = Location;
00035	
00036		SetTimer(5 + FRand()*2, false);
00037	}
00038	
00039	function Timer()
00040	{
00041		// Hack - Beams must go through render code once before going to stasis
00042		bStasis=true;
00043	}
00044	
00045	/*
00046	function PostBeginPlay()
00047	{
00048		local int x, y, z;
00049	
00050		// DEBUG:  Print a warning if any ropes are spawned outside the world
00051		if(Region.ZoneNumber == 0)
00052		{
00053			x = self.Location.x; // truncate
00054			y = self.Location.y; // truncate
00055			z = self.Location.z; // truncate
00056			SLog("WARNING:  BeamSystem ["$self$"] Out of World @ ("$x$","$y$","$z$")");
00057		}
00058	}
00059	*/
00060	
00061	//=============================================================================
00062	//
00063	// SpawnBeamDebris
00064	//
00065	//=============================================================================
00066	
00067	function SpawnBeamDebris()
00068	{
00069		local int i, j;
00070		local vector v;
00071		local Debris D;
00072		local vector loc;
00073	
00074		if(Target == None)
00075		{
00076			return;
00077		}
00078		
00079		if(TargetJointIndex == 0)
00080		{	
00081			v = Target.Location - Location;
00082		}
00083		else
00084		{
00085			v = Target.GetJointPos(TargetJointIndex) - Location;
00086		}
00087	
00088		for(i = 0; i < NumConPts; i++)
00089		{
00090			for(j = 0; j < 5; j++)
00091			{
00092				loc = ConnectionPoint[i] + VRand() * 4;
00093				D = Spawn(class'DebrisStone',,, loc);
00094				if(D != None)
00095				{
00096					D.SetSize(0.15);
00097					D.SetTexture(ParticleTexture[0]);
00098					D.SetMomentum(VRand() * 3.5);
00099				}
00100			}
00101		}
00102	}
00103	
00104	/* This is done in C++ code, but could be overridden if necessary -- cjr
00105	//=============================================================================
00106	//
00107	// SystemInit
00108	//
00109	// Called when the particle system is initialize IF bEventSystemInit is true
00110	//=============================================================================
00111	
00112	function SystemInit()
00113	{
00114		local int i;
00115		local float alpha;
00116		local int temp;
00117		
00118		alpha = float(AlphaStart) / 255.0;
00119		for(i = 0; i < ParticleCount; i++)
00120		{
00121			ParticleArray[i].Valid = true;
00122			ParticleArray[i].Style = Style;
00123			ParticleArray[i].Velocity = vect(0, 0, 0);
00124			ParticleArray[i].Alpha.X = alpha;
00125			ParticleArray[i].Alpha.Y = alpha;
00126			ParticleArray[i].Alpha.Z = alpha;
00127			ParticleArray[i].Location = Location;
00128			ParticleArray[i].XScale = 1.0;
00129			ParticleArray[i].YScale = 1.0;
00130			ParticleArray[i].TextureIndex = 0;
00131			ParticleArray[i].LifeSpan = -1;
00132		}
00133	
00134		for(i = 0; i < NumConPts; i++)
00135		{
00136			temp = i * 3;
00137			ParticleArray[temp].U0 = 0;		
00138			ParticleArray[temp].V0 = 0;		
00139			ParticleArray[temp].U1 = 0.33;		
00140			ParticleArray[temp].V1 = 1;
00141	
00142			temp++;
00143			ParticleArray[temp].U0 = 0.33;
00144			ParticleArray[temp].V0 = 0;
00145			ParticleArray[temp].U1 = 0.66;
00146			ParticleArray[temp].V1 = 1;
00147	
00148			temp++;
00149			ParticleArray[temp].U0 = 0.66;
00150			ParticleArray[temp].V0 = 0;
00151			ParticleArray[temp].U1 = 1;
00152			ParticleArray[temp].V1 = 1;
00153		}
00154	
00155		IsLoaded = true;
00156	}
00157	*/
00158	
00159	//=============================================================================
00160	//
00161	// SystemTick
00162	//
00163	// Called when the particle system is ticked IF bEventSystemTick is true
00164	//=============================================================================
00165	
00166	event SystemTick(float DeltaSeconds)
00167	{
00168		local int i;
00169		local float amp;
00170		local vector v;
00171		local vector X, Y, Z;
00172		local float dist;
00173			
00174		if(Target == None)
00175		{
00176			return;
00177		}
00178		
00179		BeamTime += DeltaSeconds;
00180	
00181		if(TargetJointIndex == 0)
00182		{	
00183			v = Target.Location - Location;
00184		}
00185		else
00186		{
00187			v = Target.GetJointPos(TargetJointIndex) - Location;
00188		}
00189		
00190		dist = VSize(v) * 0.03;
00191		GetAxes(rotator(v), X, Y, Z);
00192		
00193		for(i = 0; i < NumConPts; i++)
00194		{
00195			if(i < NumConPts / 2)
00196			{
00197				amp = dist * float(i) / NumConPts;
00198			}
00199			else
00200			{
00201				amp = dist * float(NumConPts - i) / NumConPts;
00202			}
00203			
00204			ConnectionOffset[i] = Z * amp * sin(BeamTime * 20 + i * 0.5)
00205				+ Y * amp * 2 * sin(BeamTime * 15 + i * 0.5);
00206		}
00207	}
00208	
00209	simulated function Debug(Canvas canvas, int mode)
00210	{
00211		local vector offset;
00212		local int i;
00213	
00214		Super.Debug(canvas, mode);
00215	
00216		Canvas.DrawText("BeamSystem:");
00217		Canvas.CurY -= 8;
00218		Canvas.DrawText(" Target:"@Target);
00219		Canvas.CurY -= 8;
00220		
00221		// Locations of rope
00222		for(i = 0; i < NumConPts; i++)
00223		{
00224			Canvas.DrawLine3D(ConnectionPoint[i] + vect(10, 0, 0), ConnectionPoint[i] + vect(-10, 0, 0), 0, 255, 0);
00225			Canvas.DrawLine3D(ConnectionPoint[i] + vect(0, 10, 0), ConnectionPoint[i] + vect(0, -10, 0), 0, 255, 0);	
00226			Canvas.DrawLine3D(ConnectionPoint[i] + vect(0, 0, 10), ConnectionPoint[i] + vect(0, 0, -10), 0, 255, 0);
00227		}
00228	}
00229	
00230	defaultproperties
00231	{
00232	     bSpriteInEditor=True
00233	     ParticleCount=60
00234	     ParticleTexture(0)=FireTexture'RuneFX.MyTex1'
00235	     ParticleType=PART_Beam
00236	     ParticleSpriteType=PSPRITE_QuadUV
00237	     AlphaStart=255
00238	     AlphaEnd=255
00239	     NumConPts=20
00240	     BeamThickness=5.000000
00241	     bEventSystemTick=True
00242	     bStasis=False
00243	     bForceRender=True
00244	     bComplexOcclusion=True
00245	}

End Source Code