Botpack
Class CTFFlag

source: e:\games\UnrealTournament\Botpack\Classes\CTFFlag.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Decoration
         |
         +--Botpack.CTFFlag
Direct Known Subclasses:GoldFlag, GreenFlag, RedFlag

class CTFFlag
extends Engine.Decoration

//============================================================================= // CTFFlag. //=============================================================================
Variables
 Pawn Holder
           for bot AI
 FlagBase HomeBase
           for bot AI
 byte Team
 bool bHeld
           for bot AI
 bool bHome
 bool bKnownLocation
           for bot AI

States
Home, Held, Dropped

Function Summary
 void Drop(vector newVel)
 void Landed(vector HitNormall)
 Actor Position()
 void PostBeginPlay()
 void SendHome()
 void SetHolderLighting()


State Home Function Summary
 void EndState()
 void BeginState()
 void Touch(Actor Other)
 void Timer()


State Held Function Summary
 void EndState()
 void BeginState()
 void Timer()


State Dropped Function Summary
 void EndState()
 void BeginState()
 void Touch(Actor Other)
 void Timer()
 void ZoneChange(ZoneInfo NewZone)
 void TakeDamage(int NDamage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)



Source Code


00001	//=============================================================================
00002	// CTFFlag.
00003	//=============================================================================
00004	class CTFFlag extends Decoration;
00005	
00006	#exec MESH IMPORT MESH=pflag ANIVFILE=MODELS\pflag_a.3d DATAFILE=MODELS\pflag_d.3d X=0 Y=0 Z=0 ZEROTEX=1
00007	#exec MESH ORIGIN MESH=pflag X=400 Y=0 Z=0 YAW=128
00008	
00009	#exec MESH SEQUENCE MESH=pflag SEQ=All   STARTFRAME=0 NUMFRAMES=133
00010	#exec MESH SEQUENCE MESH=pflag SEQ=pflag STARTFRAME=0 NUMFRAMES=133
00011	
00012	#exec TEXTURE IMPORT NAME=JpflagB FILE=MODELS\N-Flag-B.PCX GROUP=Skins FLAGS=2 // twosided
00013	#exec TEXTURE IMPORT NAME=JpflagR FILE=MODELS\N-Flag-R.PCX GROUP=Skins FLAGS=2 // twosided
00014	
00015	#exec MESHMAP NEW   MESHMAP=pflag MESH=pflag
00016	#exec MESHMAP SCALE MESHMAP=pflag X=0.1 Y=0.1 Z=0.2
00017	
00018	#exec MESHMAP SETTEXTURE MESHMAP=pflag NUM=0 TEXTURE=JpflagB
00019	
00020	var byte	 	 Team;      	
00021	var bool bHome;
00022	var bool bKnownLocation; //for bot AI
00023	var bool bHeld;
00024	var Pawn		Holder;
00025	var FlagBase	HomeBase;
00026	
00027	replication
00028	{
00029		reliable if ( Role == ROLE_Authority )
00030			Team, bHome, bHeld;
00031	}
00032	
00033	function PostBeginPlay()
00034	{
00035		Super.PostBeginPlay();
00036		LoopAnim('pflag');
00037	}
00038	
00039	function Actor Position()
00040	{
00041		if ( bHeld )
00042			return Holder;
00043	
00044		return self;
00045	}
00046	
00047	event FellOutOfWorld()
00048	{
00049		SendHome();
00050	}
00051		
00052	function SendHome()
00053	{
00054		local Pawn aPawn;
00055	
00056		if ( Holder != None )
00057		{
00058			Holder.AmbientGlow = Holder.Default.AmbientGlow;
00059			Holder.LightType = LT_None;
00060			Holder.PlayerReplicationInfo.HasFlag = None;
00061			if ( Holder.Inventory != None )
00062				Holder.Inventory.SetOwnerDisplay();
00063			Holder = None;
00064		}
00065		GotoState('Home');
00066		SetPhysics(PHYS_None);
00067		bCollideWorld = false;
00068		SetLocation(HomeBase.Location);
00069		SetRotation(HomeBase.Rotation);
00070		SetBase(None);
00071		SetCollision(true,false,false);
00072		For (aPawn = Level.PawnList; aPawn!=None; aPawn=aPawn.nextPawn )
00073			if ( aPawn.MoveTarget == self )
00074				aPawn.MoveTimer = -1.0;
00075	}
00076		
00077	function Landed(vector HitNormall)
00078	{
00079		local rotator NewRot;
00080	
00081		NewRot = Rot(16384,0,0);
00082		NewRot.Yaw = Rotation.Yaw;
00083		SetRotation(NewRot);
00084	}
00085	
00086	function Drop(vector newVel)
00087	{
00088		local Pawn OldHolder;
00089		local vector X,Y,Z;
00090		local bool bHolderPainZone;
00091	
00092		BroadcastLocalizedMessage( class'CTFMessage', 2, Holder.PlayerReplicationInfo, None, CTFGame(Level.Game).Teams[Team] );
00093		if (Level.Game.WorldLog != None)
00094			Level.Game.WorldLog.LogSpecialEvent("flag_dropped", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
00095		if (Level.Game.LocalLog != None)
00096			Level.Game.LocalLog.LogSpecialEvent("flag_dropped", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
00097	
00098		RotationRate.Yaw = Rand(200000) - 100000;
00099		RotationRate.Pitch = Rand(200000 - Abs(RotationRate.Yaw)) - 0.5 * (200000 - Abs(RotationRate.Yaw));
00100		Velocity = (0.2 + FRand()) * (newVel + 400 * FRand() * VRand());
00101		If (Region.Zone.bWaterZone)
00102			Velocity *= 0.5;
00103		OldHolder = Holder;
00104		Holder.PlayerReplicationInfo.HasFlag = None;
00105		Holder.AmbientGlow = Holder.Default.AmbientGlow;
00106		LightType = LT_Steady;
00107		Holder.LightType = LT_None;
00108		bHolderPainZone = (Holder.Region.Zone.bPainZone && (Holder.Region.Zone.DamagePerSec > 0));
00109		bHolderPainZone = bHolderPainZone || (Holder.FootRegion.Zone.bPainZone && (Holder.FootRegion.Zone.DamagePerSec > 0));
00110		if ( Holder.Inventory != None )
00111			Holder.Inventory.SetOwnerDisplay();
00112		Holder = None;
00113	
00114		GetAxes(OldHolder.Rotation, X,Y,Z);
00115		SetRotation(rotator(-1 * X));
00116		bCollideWorld = true;
00117		SetCollisionSize(0.5 * Default.CollisionRadius, CollisionHeight);
00118	 	if ( !SetLocation(OldHolder.Location - 2 * OldHolder.CollisionRadius * X + OldHolder.CollisionHeight * vect(0,0,0.5)) 
00119			&& !SetLocation(OldHolder.Location) )
00120		{
00121			SetCollisionSize(0.8 * OldHolder.CollisionRadius, FMin(CollisionHeight, 0.8 * OldHolder.CollisionHeight));
00122			if ( !SetLocation(OldHolder.Location) )
00123			{
00124				SendHome();
00125				return;
00126			}
00127		}
00128	
00129		SetPhysics(PHYS_Falling);
00130		SetBase(None);
00131		SetCollision(true, false, false);
00132		GotoState('Dropped');
00133		if ( bHolderPainZone )
00134			Timer();
00135	}
00136	
00137	function SetHolderLighting()
00138	{
00139		Holder.AmbientGlow = 254;
00140		LightType = LT_None;
00141		Holder.LightEffect=LE_NonIncidence;
00142		Holder.LightBrightness=255;
00143		Holder.LightHue=LightHue;
00144		Holder.LightRadius=6;
00145		Holder.LightSaturation=LightSaturation;
00146		Holder.LightType=LT_Steady;
00147	}
00148		
00149	state Dropped
00150	{
00151		function TakeDamage( int NDamage, Pawn instigatedBy, Vector hitlocation, 
00152							Vector momentum, name damageType)
00153		{
00154			if ( Region.Zone.bPainZone && (Region.Zone.DamagePerSec > 0) )
00155				timer();
00156		}
00157	
00158		singular function ZoneChange( ZoneInfo NewZone )
00159		{
00160			Super.ZoneChange(NewZone);
00161			if ( NewZone.bPainZone && (NewZone.DamagePerSec > 0) )
00162				timer();
00163		}
00164	
00165		function Timer()
00166		{
00167			SendHome();
00168			BroadcastLocalizedMessage( class'CTFMessage', 3, None, None, CTFGame(Level.Game).Teams[Team] );
00169			if (Level.Game.WorldLog != None)
00170				Level.Game.WorldLog.LogSpecialEvent("flag_returned_timeout", CTFGame(Level.Game).Teams[Team].TeamIndex);
00171			if (Level.Game.LocalLog != None)
00172				Level.Game.LocalLog.LogSpecialEvent("flag_returned_timeout", CTFGame(Level.Game).Teams[Team].TeamIndex);
00173		}
00174	
00175		function Touch(Actor Other)
00176		{
00177			local CTFFlag aFlag;
00178			local Pawn aPawn;
00179			local NavigationPoint N;
00180			local int num, i;
00181	
00182			aPawn = Pawn(Other);
00183			if ( (aPawn != None) && aPawn.bIsPlayer && (aPawn.Health > 0)
00184				&& !aPawn.IsInState('FeigningDeath') )
00185			{
00186				aPawn.MoveTimer = -1;
00187				if ( aPawn.PlayerReplicationInfo.Team == Team )
00188				{
00189					// returned flag
00190					CTFGame(Level.Game).ScoreFlag(aPawn, self);
00191					SendHome();
00192					return;
00193				}
00194				else
00195				{
00196					Holder = aPawn;
00197					Holder.PlayerReplicationInfo.HasFlag = self;
00198					SetHolderLighting();
00199					if ( Holder.IsA('Bot') )
00200					{
00201						Bot(Holder).AlternatePath = None;
00202						Holder.SendTeamMessage(None, 'OTHER', 2, 10);
00203					}
00204					else if ( Holder.IsA('TournamentPlayer') && TournamentPlayer(Holder).bAutoTaunt )
00205						Holder.SendTeamMessage(None, 'OTHER', 2, 10);
00206				}
00207				BroadcastLocalizedMessage( class'CTFMessage', 4, Holder.PlayerReplicationInfo, None, CTFGame(Level.Game).Teams[Team] );
00208				if (Level.Game.WorldLog != None)
00209					Level.Game.WorldLog.LogSpecialEvent("flag_pickedup", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
00210				if (Level.Game.LocalLog != None)
00211					Level.Game.LocalLog.LogSpecialEvent("flag_pickedup", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
00212				GotoState('Held');
00213			}
00214		}
00215	
00216		function BeginState()
00217		{
00218			LightEffect = LE_NonIncidence;
00219			SetTimer(25.0, false);
00220			bCollideWorld = true;
00221			bKnownLocation = false;
00222			bHidden = false;
00223		}
00224	
00225		function EndState()
00226		{
00227			bHidden = true;
00228		}
00229	
00230	Begin:
00231		if ( Region.Zone.bPainZone && (Region.Zone.DamagePerSec > 0) )
00232			timer();
00233	
00234	}
00235	
00236	state Held
00237	{
00238		event FellOutOfWorld()
00239		{
00240		}
00241	
00242		function Timer()
00243		{
00244			if ( Holder == None )
00245				SendHome();
00246		}
00247	
00248		function BeginState()
00249		{
00250			bHeld = true;
00251			bCollideWorld = false;
00252			bKnownLocation = false;
00253			HomeBase.PlayAlarm();
00254			SetPhysics(PHYS_None);
00255			SetCollision(false, false, false);
00256			SetTimer(10.0, true);
00257		}
00258	
00259		function EndState()
00260		{
00261			bHeld = false;
00262		}
00263	}		
00264	
00265	auto state Home
00266	{
00267		function Timer()
00268		{
00269			if ( VSize(Location - HomeBase.Location) > 10 )
00270			{
00271				SendHome();
00272				BroadcastLocalizedMessage( class'CTFMessage', 5, None, None, CTFGame(Level.Game).Teams[Team] );
00273			}
00274		}
00275	
00276		function Touch(Actor Other)
00277		{
00278			local CTFFlag aFlag;
00279			local Pawn aPawn;
00280			local NavigationPoint N;
00281			local int i;
00282			local float totalweight, selection, PartialWeight;
00283			local Bot B;
00284	
00285			aPawn = Pawn(Other);
00286			if ( (aPawn != None) && aPawn.bIsPlayer && (aPawn.Health > 0) )
00287			{
00288				// check if scored capture
00289				if ( aPawn.PlayerReplicationInfo.Team == Team )
00290				{
00291					if ( aPawn.PlayerReplicationInfo.HasFlag != None )
00292					{
00293						//Score!
00294						aFlag = CTFFlag(aPawn.PlayerReplicationInfo.HasFlag);
00295						CTFGame(Level.Game).ScoreFlag(aPawn, aFlag);
00296						aFlag.SendHome();
00297					}
00298				}
00299				else
00300				{
00301					Holder = aPawn;
00302					Holder.MoveTimer = -1;
00303					Holder.PlayerReplicationInfo.HasFlag = self;
00304					Holder.MakeNoise(2.0);
00305					SetHolderLighting();
00306					B = Bot(Holder);
00307					if ( B != None )
00308					{
00309						B.AlternatePath = None;
00310						if ( FRand() < 0.5 )
00311						{
00312							for ( N=Level.NavigationPointList; N!=None; N=N.nextNavigationPoint )
00313								if ( N.IsA('AlternatePath') && (AlternatePath(N).bTwoWay || (AlternatePath(N).team == Holder.PlayerReplicationInfo.team)) )
00314								{
00315									if ( AlternatePath(N).bTwoWay && (AlternatePath(N).team != Holder.PlayerReplicationInfo.team) )
00316										TotalWeight += 4000;
00317									TotalWeight += AlternatePath(N).SelectionWeight;
00318								}
00319							selection = TotalWeight * FRand();
00320							for ( N=Level.NavigationPointList; N!=None; N=N.nextNavigationPoint )
00321								if ( N.IsA('AlternatePath') && (AlternatePath(N).bTwoWay ||(AlternatePath(N).team == Holder.PlayerReplicationInfo.team)) )
00322								{
00323									B.AlternatePath = AlternatePath(N);
00324									if ( AlternatePath(N).bTwoWay && (AlternatePath(N).team != Holder.PlayerReplicationInfo.team) )
00325									{
00326										PartialWeight += 4000;
00327									}
00328									PartialWeight += AlternatePath(N).SelectionWeight;
00329									if ( PartialWeight > selection )
00330										break;
00331								}
00332						}
00333						B.SendTeamMessage(None, 'OTHER', 2, 10);
00334					}
00335					else if ( Holder.IsA('TournamentPlayer') && TournamentPlayer(Holder).bAutoTaunt )
00336						Holder.SendTeamMessage(None, 'OTHER', 2, 10);
00337	
00338					if (Level.Game.WorldLog != None)
00339						Level.Game.WorldLog.LogSpecialEvent("flag_taken", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
00340					if (Level.Game.LocalLog != None)
00341						Level.Game.LocalLog.LogSpecialEvent("flag_taken", Holder.PlayerReplicationInfo.PlayerID, CTFGame(Level.Game).Teams[Team].TeamIndex);
00342					BroadcastLocalizedMessage( class'CTFMessage', 6, Holder.PlayerReplicationInfo, None, CTFGame(Level.Game).Teams[Team] );
00343					GotoState('Held');
00344				}
00345			}
00346		}
00347	
00348		function BeginState()
00349		{
00350			bHome = true;
00351			bCollideWorld = false;
00352			bKnownLocation = true;
00353			if ( HomeBase != None ) // will be none when flag is created
00354			{
00355				HomeBase.bHidden = false;
00356				HomeBase.AmbientSound = None;
00357			}
00358			SetTimer(1.0, true);
00359			SetCollisionSize(Default.CollisionRadius, Default.CollisionHeight);
00360		}
00361	
00362		function EndState()
00363		{
00364			bHome = false;
00365			HomeBase.bHidden = true;
00366			SetTimer(0.0, false);
00367		}
00368	}
00369	
00370	defaultproperties
00371	{
00372	     bHome=True
00373	     bStatic=False
00374	     bHidden=True
00375	     bAlwaysRelevant=True
00376	     bStasis=False
00377	     DrawType=DT_Mesh
00378	     Style=STY_Masked
00379	     Skin=Texture'Botpack.Skins.JpflagB'
00380	     Mesh=LodMesh'Botpack.pflag'
00381	     DrawScale=0.600000
00382	     PrePivot=(X=2.000000)
00383	     bUnlit=True
00384	     CollisionRadius=48.000000
00385	     CollisionHeight=30.000000
00386	     bCollideActors=True
00387	     bCollideWorld=True
00388	     LightType=LT_Steady
00389	     LightEffect=LE_NonIncidence
00390	     LightBrightness=255
00391	     LightHue=170
00392	     LightRadius=6
00393	     bFixedRotationDir=True
00394	     Mass=30.000000
00395	     Buoyancy=20.000000
00396	     RotationRate=(Pitch=30000,Roll=30000)
00397	     NetPriority=3.000000
00398	}

End Source Code