RuneI
Class ActorGenerator

source: c:\runehov\RuneI\Classes\ActorGenerator.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Keypoint
         |
         +--RuneI.ActorGenerator
Direct Known Subclasses:None

class ActorGenerator
extends Engine.Keypoint

//============================================================================= // ActorGenerator. //=============================================================================
Variables
 class ActorClass[4]
 float ActorProbability[4]
 class AdjustedClass[4]
           Multiplayer, if false the object will not respawn
 float AdjustedProbability[4]
           Multiplayer, if false the object will not respawn
 int ClassCount
           Multiplayer, if false the object will not respawn
 enum DLYType
           Multiplayer, if false the object will not respawn
 float DelayAlways
           Multiplayer, if false the object will not respawn
 float DelayRandom
           Multiplayer, if false the object will not respawn
 float DirectionWeight
           Multiplayer, if false the object will not respawn
 float DirectionWeightRandom
           Multiplayer, if false the object will not respawn
 byte QuantityAlways
           Multiplayer, if false the object will not respawn
 byte QuantityRandom
           Multiplayer, if false the object will not respawn
 name SpawnOrders
           Multiplayer, if false the object will not respawn
 name SpawnOrdersTag
           Multiplayer, if false the object will not respawn
 name SpawnWithAlertOrders
           Multiplayer, if false the object will not respawn
 name SpawnWithAlertOrdersTag
           Multiplayer, if false the object will not respawn
 float SpawnWithDrawScale
           Multiplayer, if false the object will not respawn
 name SpawnWithEvent
           Multiplayer, if false the object will not respawn
 int SpawnWithHealth
           Multiplayer, if false the object will not respawn
 float SpawnWithHuntDistance
           Multiplayer, if false the object will not respawn
 class SpawnWithShield
           Multiplayer, if false the object will not respawn
 name SpawnWithTag
           Multiplayer, if false the object will not respawn
 name SpawnWithTriggerOrders
           Multiplayer, if false the object will not respawn
 name SpawnWithTriggerOrdersTag
           Multiplayer, if false the object will not respawn
 class SpawnWithWeapon
           Multiplayer, if false the object will not respawn
 Pawn TEventInstigator
           Multiplayer, if false the object will not respawn
 Actor TOther
           Multiplayer, if false the object will not respawn
 int TotalActorCount
           Multiplayer, if false the object will not respawn
 bool bInitiallyActive
           Multiplayer, if false the object will not respawn
 bool bLoopForever
           Multiplayer, if false the object will not respawn
 bool bMoveWhenUnreachable
           For trialpit beast
 bool bRandomPosition
 bool bRespawn
           Multiplayer, if false the object will not respawn
 bool bSpawnWithNoShield
           Multiplayer, if false the object will not respawn
 bool bSpawnWithNoWeapon
           Multiplayer, if false the object will not respawn
 bool bTriggerCreations

States
GenerateActors, Waiting

Function Summary
 void BeginPlay()
     
// FUNCTIONS ------------------------------------------------------------------
 void SpawnNewActor()


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


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



Source Code


00001	//=============================================================================
00002	// ActorGenerator.
00003	//=============================================================================
00004	class ActorGenerator expands Keypoint;
00005	
00006	//
00007	// To do:
00008	//
00009	// - Apply DLYType to Sleep (and expand enum DLYType)
00010	// - Implement "initial rotation" direction velocity
00011	// - Tweak values for direction weights
00012	//
00013	
00014	// EDITABLE INSTANCE VARIABLES ------------------------------------------------
00015	
00016	var() class<actor>	ActorClass[4];
00017	var() float			ActorProbability[4];
00018	var() bool			bRandomPosition;
00019	var() bool			bTriggerCreations;
00020	var() bool			bMoveWhenUnreachable;	// For trialpit beast
00021	var() bool			bRespawn;		// Multiplayer, if false the object will not respawn
00022	var() float			DelayAlways;
00023	var() float			DelayRandom;
00024	var() name			SpawnOrders;
00025	var() name			SpawnOrdersTag;
00026	var() enum DLYType
00027	{
00028		DLY_STEADY,
00029		DLY_INCREASE,
00030		DLY_DECREASE
00031	} DelayType;
00032	var() float			DirectionWeight;
00033	var() float			DirectionWeightRandom;
00034	var() byte			QuantityAlways;
00035	var() byte			QuantityRandom;
00036	var() bool			bLoopForever;
00037	var() bool			bInitiallyActive;
00038	var() name			SpawnWithEvent;
00039	var() name			SpawnWithTag;
00040	var() class<Weapon>	SpawnWithWeapon;
00041	var() class<Shield>	SpawnWithShield;
00042	var() int			SpawnWithHealth;
00043	var() float			SpawnWithDrawScale;
00044	var() float			SpawnWithHuntDistance;
00045	var() bool			bSpawnWithNoWeapon;
00046	var() bool			bSpawnWithNoShield;
00047	var() name			SpawnWithTriggerOrders;
00048	var() name			SpawnWithTriggerOrdersTag;
00049	var() name			SpawnWithAlertOrders;
00050	var() name			SpawnWithAlertOrdersTag;
00051	//var() class<Sark>	ZombieSarkClass; // Type of Sark that zombies will transform into
00052	
00053	
00054	// INSTANCE VARIABLES ---------------------------------------------------------
00055	
00056	var int TotalActorCount;
00057	var actor TOther;
00058	var pawn TEventInstigator;
00059	var class<actor> AdjustedClass[4];
00060	var float AdjustedProbability[4];
00061	var int ClassCount;
00062	
00063	// FUNCTIONS ------------------------------------------------------------------
00064	
00065	function BeginPlay()
00066	{
00067		local int i;
00068		local float totalProb;
00069	
00070		totalProb = 0.0;
00071		ClassCount = 0;
00072		for(i = 0; i < 4; i++)
00073		{
00074			if(ActorClass[i] == None || ActorProbability[i] ~= 0.0)
00075				continue;
00076			AdjustedClass[ClassCount] = ActorClass[i];
00077			totalProb += ActorProbability[i];
00078			AdjustedProbability[ClassCount] = totalProb;
00079			ClassCount++;
00080		}
00081		if(ClassCount > 0)
00082			for(i = 0; i < ClassCount; i++)
00083				AdjustedProbability[i] /= totalProb;
00084	}
00085	
00086	
00087	function SpawnNewActor()
00088	{
00089		local actor newActor;
00090		local vector newLocation;
00091		local vector X,Y,Z;
00092	
00093		newActor = Spawn(GenRandClass());
00094		if(newActor == None)
00095			return;
00096	
00097		newLocation = Location;
00098		if(bRandomPosition)
00099		{
00100			newLocation.x += FRand()*CollisionRadius*2 - CollisionRadius;
00101			newLocation.y += FRand()*CollisionRadius*2 - CollisionRadius;
00102			newLocation.z += FRand()*CollisionHeight*2 - CollisionHeight;
00103		}
00104		newActor.SetLocation(newLocation);
00105	
00106		if (DirectionWeightRandom != 0)
00107		{
00108			newActor.Velocity = VRand()*100*DirectionWeightRandom;
00109			newActor.Velocity.z = 0;
00110		}
00111		else
00112		{
00113			GetAxes(Rotation, X,Y,Z);
00114			newActor.Velocity = X*DirectionWeight;
00115		}
00116	
00117		if (SpawnWithEvent != '')
00118			newActor.Event = SpawnWithEvent;
00119		if (SpawnWithTag != '')
00120			newActor.Tag = SpawnWithTag;
00121	
00122		newActor.DrawScale *= SpawnWithDrawScale;
00123	
00124		if (ScriptPawn(newActor) != None)
00125		{
00126			if (SpawnOrders != '')
00127				ScriptPawn(newActor).Orders = SpawnOrders;
00128	
00129			if (SpawnOrdersTag != '')
00130				ScriptPawn(newActor).OrdersTag = SpawnOrdersTag;
00131	
00132			if (SpawnWithTriggerOrders != '')
00133				ScriptPawn(newActor).TriggerOrders = SpawnWithTriggerOrders;
00134	
00135			if (SpawnWithTriggerOrdersTag != '')
00136				ScriptPawn(newActor).TriggerOrdersTag = SpawnWithTriggerOrdersTag;
00137	
00138			if (SpawnWithAlertOrders != '')
00139				ScriptPawn(newActor).AlertOrders = SpawnWithAlertOrders;
00140	
00141			if (SpawnWithAlertOrdersTag != '')
00142				ScriptPawn(newActor).AlertOrdersTag = SpawnWithAlertOrdersTag;
00143	
00144			if(bSpawnWithNoWeapon)
00145				ScriptPawn(newActor).StartWeapon = None;			
00146			else if(SpawnWithWeapon != None)
00147				ScriptPawn(newActor).StartWeapon = SpawnWithWeapon;
00148	
00149			if(bSpawnWithNoShield)
00150				ScriptPawn(newActor).StartShield = None;			
00151			else if(SpawnWithShield != None)
00152				ScriptPawn(newActor).StartShield = SpawnWithShield;
00153	
00154			if (SpawnWithHealth != 0)
00155				ScriptPawn(newActor).Health = SpawnWithHealth;
00156	
00157			if (SpawnWithHuntDistance != 0)
00158				ScriptPawn(newActor).HuntDistance = SpawnWithHuntDistance;
00159	
00160	/* No longer able to select type of sark a zombie will turn into.  They always transform into Spawn
00161			// For zombies, set the Sark type that this zombie can transform into
00162			if(newActor.IsA('Zombie') && ZombieSarkClass != None)
00163			{
00164				Zombie(newActor).SarkClass = ZombieSarkClass;
00165			}
00166	*/
00167			// Set up whether the scriptpawn should stand still when the enemy is unreachable
00168			ScriptPawn(newActor).bMoveWhenUnreachable = bMoveWhenUnreachable;
00169		}
00170	
00171		if(Inventory(newActor) != None && !bRespawn)
00172		{ // If bRespawn if false, then don't allow the actor to respawn in multiplayer
00173			Inventory(newActor).RespawnTime = 0;
00174		}
00175	
00176		if(bTriggerCreations)
00177			newActor.Trigger(TOther, TEventInstigator);
00178	}
00179	
00180	function class<Actor> GenRandClass()
00181	{
00182		local float p;
00183		local int i;
00184	
00185		p = FRand();
00186		for(i = 0; i < ClassCount; i++)
00187			if(p < AdjustedProbability[i])
00188				return AdjustedClass[i];
00189	
00190		return None;
00191	}
00192	
00193	// STATES ---------------------------------------------------------------------
00194	
00195	auto state Waiting
00196	{
00197		function BeginState()
00198		{
00199			if (bInitiallyActive)
00200			{
00201				bInitiallyActive = false;
00202				Trigger(self, None);
00203			}
00204		}
00205	
00206		function Trigger(actor other, pawn eventInstigator)
00207		{
00208			if(ClassCount > 0)
00209			{
00210				TOther = other;
00211				TEventInstigator = eventInstigator;
00212				GotoState('GenerateActors');
00213			}
00214		}
00215	
00216	}
00217	
00218	
00219	state GenerateActors
00220	{
00221		function BeginState()
00222		{
00223			TotalActorCount = QuantityAlways + Rand(QuantityRandom+1);
00224		}
00225	
00226		function Trigger(actor other, pawn eventInstigator)
00227		{
00228			GotoState('Waiting');
00229		}
00230	
00231	begin:
00232		while(TotalActorCount > 0 || bLoopForever)
00233		{
00234			SpawnNewActor();
00235			Sleep(DelayAlways + FRand()*DelayRandom);
00236			TotalActorCount--;
00237		}
00238		GotoState('Waiting');
00239	}
00240	
00241	defaultproperties
00242	{
00243	     bRespawn=True
00244	     SpawnWithDrawScale=1.000000
00245	     bStatic=False
00246	     bDirectional=True
00247	     CollisionRadius=32.000000
00248	     CollisionHeight=8.000000
00249	}

End Source Code