The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall

UE2:TeamVehicleFactory

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
UE2 SVehicleFactory >> Actor >> TeamVehicleFactory (custom)


This custom actor really duplicates much of the functionality of the ONSVehicleFactory subclasses, but the big feature is that nearly any vehicle class can be spawned. Although this actor cannot display the selected vehicle class in the editor, it does offer added controls that mappers for VCTF or other vehicle gametypes might want.

Features

  • The ability to spawn random vehicles from a list of vehicle classes
  • The ability to spawn nearly any vehicle class in gametypes that allow vehicles
  • The ability to trigger PreSpawn and (Post)Spawn events
  • The option to allow the vehicle to spawn over and crush other actors
  • The option to use this as either a triggerable or an automatic (timed) vehicle factory.
  • Greater control over spawn timing

Notes

  • If you use a TeamVehicleFactory "as is" in your custom map, please credit me in the readme file of the map. (SuperApe)
  • You have to supply spawning effects and sounds, via ScriptedTrigger, Emitter and the like. This is meant to allow flexibilty in the ways you want vehicles to spawn. An example VCTF map posted on this UP Forum thread gives my suggestion for spawning particles and sound. (It appears similar to pickup spawning.)
  • With bAutoSpawn on and without a PreSpawnTime of around 2 seconds, you run the risk of spawning a vehicle before headlights can be properly spawned at map start. Subsequent vehicles after map start will spawn headlights normally.
  • Turrets that are spawned automatically get an AIController. They are auto turrets; firing at enemies, or if set to neutral (team 255), firing at any non-neutral controlled pawn it detects.
  • The AS Spacefighters are spawned with a minimum velocity that makes them impractical to use. However, a custom launcher for these is easy to make with a TryToDrive() function.
  • This has a slightly larger bBlocked check radius than ONSVehicleFactory. ( 1.33 : 1.25 )

Properties

Main

int TeamNum 
Team Number to be set on spawn. 0= red, 1= blue, 255= neutral / none
bool bPlayerControl 
Only player instigators can trigger.
bool bAutoSpawn 
Will spawn at regular intervals. The triggering ability is disabled.
int RespawnTime 
Interval to wait before AutoSpawning.
name PreSpawnEvent 
Event to trigger before spawn.
int PreSpawnTime 
Time before spawn to trigger event. Will begin event this many seconds before the factory is set to AutoSpawn.
name SpawnEvent 
Event to trigger after spawn. A post spawn event.
bool bCrushable 
Allow spawning over colliding actors. Note: Turrets will normally spawn in collision with other actors, spawned vehicles will generally move out of the way.
int RetrySpawnTime 
Interval to wait if bBlocked.
bool bRandomFlip 
Neutral vehicles may face backwards.
bool bRandomSpawn 
Will spawn random vehicle class.
struct class<Vehicle> SpawnedVehicle 
Selected random vehicle class.
array<SpawnedVehicle> RandomVehicles 
List for random vehicle spawn.

Hidden

bool bWaiting 
Waiting to spawn.
int FactoryTime 
Time last spawn. (in Level.TimeSeconds)
bool bPreSpawn 
Should trigger PreSpawnEvent next.

Code

</span><div class="hidden">//==================================================================================
// TeamVehicleFactory.
// Spawn any Vehicle or Turret, set Team, pre & post spawn Events, timing, and more.
// Glenn 'SuperApe' Storm -- June 2004 -- Updated: July 2005
//==================================================================================
class TeamVehicleFactory extends SVehicleFactory
	placeable;
 
var()	int			TeamNum ;			// 0= red, 1= blue, 255= neutral / none
var()	bool		bPlayerControl ; 	// Only player instigators can trigger
 
var()	bool		bAutoSpawn ;		// Will spawn at regular intervals
var()	int			RespawnTime ;		// Interval to wait before AutoSpawning
 
var		bool		bWaiting ;			// About to spawn
var		int			FactoryTime	;		// Time last spawn
 
var()	name		PreSpawnEvent ;		// Event to trigger before spawn
var()	int			PreSpawnTime ; 		// Time before spawn to trigger event
var		bool		bPreSpawn ;			// Should trigger PreSpawnEvent next
var()	name		SpawnEvent ;		// Event to trigger after spawn
 
var()	bool		bCrushable ;		// Allow spawning over colliding actors
var()	int			RetrySpawnTime ;	// Interval to wait if bBlocked
 
var()	bool		bRandomFlip ;		// Neutral vehicles may face backwards
 
var()	bool					bRandomSpawn ;		// Spawn random vehicle class
struct SpawnedVehicle
{
	var()	class<Vehicle>		SpawnVehicle;		// Selected random vehicle class
};
var()	array<SpawnedVehicle>	RandomVehicles ; 	// List for random vehicle spawn
 
 
simulated function PostBeginPlay()
{
	Super.PostBeginPlay();
 
	if ( bAutoSpawn )
		bWaiting = true;
		bPreSpawn = true;
		if ( RespawnTime > 0 )
			FactoryTime = Level.TimeSeconds - RespawnTime + PreSpawnTime;
		else
			FactoryTime = Level.TimeSeconds - PreSpawnTime;
}
 
simulated event Trigger( Actor Other, Pawn EventInstigator )
{
	if ( bAutoSpawn )
		// bAutoSpawn overrides Trigger
		return;
 
	if ( !EventInstigator.IsA('UnrealPawn') && bPlayerControl )
		return;
 
	if ( VehicleCount >= MaxVehicleCount )
		return;
 
 
	if ( VehicleClass == None || ( bRandomSpawn && RandomVehicles.length > 0 ) )
	{
		Log("TeamVehicleFactory:"@self@"has no VehicleClass");
		return;
	}
 
	bWaiting = true;
	bPreSpawn = true;
	if ( RespawnTime > 0 )
		FactoryTime = Level.TimeSeconds - RespawnTime + PreSpawnTime;
	else
		FactoryTime = Level.TimeSeconds - PreSpawnTime;
}
 
simulated function SpawnItNow()
{
	local 	Vehicle		CreatedVehicle;
	local	bool		bBlocked;
	local	Pawn		P;
	local	float		SV;
 
	bBlocked = false;
 
	if ( VehicleClass != None || ( bRandomSpawn && RandomVehicles.length > 0 ) )
	{
		if ( bRandomSpawn && RandomVehicles.length > 0 )
			VehicleClass = RandomVehicles[ int( FRand() * RandomVehicles.length ) ].SpawnVehicle;
 	    foreach CollidingActors(class'Pawn', P, VehicleClass.default.CollisionRadius * 1.33)
			bBlocked = true;
	}
	else
	{
		Log("TeamVehicleFactory:"@self@"has no VehicleClass");
		return;
	}
 
    if ( bBlocked && !bCrushable )
	{
		bWaiting = true;
		bPreSpawn = true;
		if ( RespawnTime > 0 )
			FactoryTime = Level.TimeSeconds - RespawnTime + RetrySpawnTime + PreSpawnTime;
		else
			FactoryTime = Level.TimeSeconds - RetrySpawnTime + PreSpawnTime;
		return;
	}
    else
		{
			if ( TeamNum == 255 )
 
			{
				if ( bRandomFlip && Rand(2) == 1 )
					CreatedVehicle = spawn(VehicleClass, , , Location, Rotation + rot(0,32768,0));
				else
					CreatedVehicle = spawn(VehicleClass, , , Location, Rotation);
				// Unlock neutral vehicles
				CreatedVehicle.bTeamLocked = false;
			}
			else
				CreatedVehicle = spawn(VehicleClass, , , Location, Rotation);
			if ( CreatedVehicle != None )
			{
				VehicleCount++;
				CreatedVehicle.Event = Tag;
				CreatedVehicle.ParentFactory = self;
				CreatedVehicle.SetTeamNum(TeamNum);
				TriggerEvent(SpawnEvent, self, None);				
			}
		}
}
 
event VehicleDestroyed(Vehicle V)
{
	Super.VehicleDestroyed(V);
 
	if ( bAutoSpawn )
	{
		bWaiting = true;
		bPreSpawn = true;
		FactoryTime = Level.TimeSeconds;
	}
}
 
simulated function Tick(float DeltaTime)
{
	if ( bWaiting )
	{
		if ( Level.TimeSeconds - FactoryTime < RespawnTime - PreSpawnTime )
			return;
 
		if ( VehicleCount < MaxVehicleCount )
			if ( !bPreSpawn )
			{		
				if ( Level.TimeSeconds - FactoryTime >= RespawnTime )
				{
					bWaiting = false;
					FactoryTime = Level.TimeSeconds;
					SpawnItNow();
				}
			}
			else
			{
				bPreSpawn = false;
				TriggerEvent(PreSpawnEvent, self, None);
			}
	}
}
 
simulated function Reset()
{
    local Vehicle V;
 
    if ( VehicleCount > 0 )
        forEach AllActors ( class 'Vehicle', V )
            if ( V.ParentFactory == self )
                V.Destroy();
 
    Super.Reset();
}

External Links

  • Mapping for VCTF – A thread on UnrealPlayground that includes a test map using this actor and suggested spawn EFX.

Related Topics