RuneI
Class TreeGrow

source: c:\runehov\RuneI\Classes\TreeGrow.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.ParticleSystem
         |
         +--RuneI.BeamSystem
            |
            +--RuneI.TreePt
               |
               +--RuneI.TreeGrow
Direct Known Subclasses:None

class TreeGrow
extends RuneI.TreePt

//============================================================================= // TreeGrow. //=============================================================================
Variables
 float BlossomRate
           Drawscale units per second of blossom growth
 int ComplexityOrder
           max branches from a parent [1..5]
 int Fertility
           inherited fertility, when this reaches 0, tree dies
 int Generation
           inherited fertility, when this reaches 0, tree dies
 float GrowthRate
           Units per second of branch growth
 float MatureBranchLength
           Max length for branches before sprouting
 bool bPreGrow
           Grow to full size before gameplay starts

States
PreGrowing, Growing, Seed

Function Summary
 void Sprout()
     
// A point spawns a new bud


State PreGrowing Function Summary


State Growing Function Summary
 void EndState()
 void BeginState()
 void Tick(float DeltaTime)


State Seed Function Summary
 void Trigger(Actor Other, Pawn EventInstigator)
 void BeginState()



Source Code


00001	//=============================================================================
00002	// TreeGrow.
00003	//=============================================================================
00004	class TreeGrow extends TreePt;
00005	
00006	
00007	var() bool bPreGrow;				// Grow to full size before gameplay starts
00008	var() float GrowthRate;				// Units per second of branch growth
00009	var() float BlossomRate;			// Drawscale units per second of blossom growth
00010	var() float MatureBranchLength;		// Max length for branches before sprouting
00011	var() int ComplexityOrder;			// max branches from a parent [1..5]
00012	var() int Fertility;				// inherited fertility, when this reaches 0, tree dies
00013	var int Generation;
00014	
00015	//--------------------------------------------------------
00016	// Functions
00017	//--------------------------------------------------------
00018	
00019	
00020	// A point spawns a new bud
00021	function Sprout()
00022	{
00023		local TreeGrow child;
00024		local int i,numbranches,PortionOfFertility;
00025	
00026		if (Fertility <= 0)
00027			return;
00028	
00029		if (Generation < 2)
00030			numbranches = 1;
00031		else
00032			numbranches = int(RandRange(2, ComplexityOrder));
00033	
00034		PortionOfFertility = Fertility / numbranches;
00035		for (i=0; i<numbranches; i++)
00036		{
00037			child = Spawn(class'TreeGrow',,,Location);
00038			child.Parent = self;
00039			child.GravDir = Normal(VRand()+vect(0,0,1));
00040			child.BranchLength = 1;
00041			child.Target = self;
00042			child.bPreGrow = bPreGrow;
00043			child.Generation = Generation + 1;
00044			if (Generation > 1)
00045			{	// Not root
00046				child.bAffectsParent=True;
00047			}
00048			child.Fertility = PortionOfFertility;
00049	
00050			if (child.bPreGrow)
00051				child.GotoState('PreGrowing');
00052			else
00053				child.GotoState('Growing');
00054			DrawType=DT_ParticleSystem;		// Whither from blossum to normal branch
00055			bLeaf = false;
00056		}
00057	}
00058	
00059	
00060	
00061	//--------------------------------------------------------
00062	// States
00063	//--------------------------------------------------------
00064	
00065	// These used to grow trees (move to subclass)
00066	auto State Seed
00067	{
00068		ignores Tick;
00069	
00070		function BeginState()
00071		{
00072			if (bPreGrow)
00073				GotoState('PreGrowing');
00074		}
00075	
00076		function Trigger(actor Other, Pawn EventInstigator)
00077		{
00078			GotoState('Growing');
00079		}
00080	
00081	Begin:
00082	}
00083	
00084	
00085	State Growing
00086	{
00087		function Tick(float DeltaTime)
00088		{
00089			local TreePt point;
00090	
00091			if (DrawScale < 1.0)
00092			{	// Grow blossoms
00093				DrawScale += BlossomRate*DeltaTime;
00094			}
00095	
00096			if (BranchLength < MatureBranchLength)
00097			{	// Grow branches
00098				BranchLength += GrowthRate*DeltaTime;
00099			}
00100			else
00101			{
00102				Sprout();
00103				GotoState('Active');
00104			}
00105	
00106			if (bLeaf)
00107			{
00108				point = self;
00109				while (point != None)
00110				{
00111					ApplySwing(point.Parent, point, DeltaTime);
00112					point = point.Parent;
00113				}
00114			}
00115		}
00116		
00117		function BeginState()
00118		{
00119			if (Parent==None)
00120			{	// Root
00121				DrawType = DT_None;
00122				DrawScale = 1.0;
00123				BranchLength = MatureBranchLength;
00124				Sprout();
00125				GotoState('Active');
00126			}
00127			else
00128			{
00129				SetPhysics(PHYS_PROJECTILE);
00130			}
00131		}
00132	
00133		function EndState()
00134		{
00135		}
00136	
00137	Begin:
00138	
00139	}
00140	
00141	
00142	State PreGrowing
00143	{
00144		ignores Tick;
00145	
00146	Begin:
00147		DrawScale = 1.0;
00148		BranchLength = MatureBranchLength;
00149		Sprout();
00150		Velocity=vect(0,0,1);	// Disallow going inactive immediately
00151		GotoState('Active');
00152	}
00153	
00154	defaultproperties
00155	{
00156	     GrowthRate=50.000000
00157	     BlossomRate=0.500000
00158	     MatureBranchLength=40.000000
00159	     ComplexityOrder=2
00160	     Fertility=5
00161	     bAffectsParent=False
00162	     BranchLength=1.000000
00163	     ParticleCount=6
00164	     ParticleTexture(0)=Texture'RuneFX.bark2'
00165	     NumConPts=2
00166	     BeamThickness=2.000000
00167	     Physics=PHYS_None
00168	     DrawType=DT_SkeletalMesh
00169	     DrawScale=0.100000
00170	     Skeletal=SkelModel'objects.Leaf'
00171	}

End Source Code