Botpack
Class TeamCannon

source: e:\games\UnrealTournament\Botpack\Classes\TeamCannon.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Pawn
         |
         +--Botpack.StationaryPawn
            |
            +--Botpack.TeamCannon
Direct Known Subclasses:MinigunCannon

class TeamCannon
extends Botpack.StationaryPawn

//============================================================================= // TeamCannon. //=============================================================================
Variables
 sound ActivateSound
 sound DeActivateSound
 float Drop
           How far down to drop spawning of projectile
 sound FireSound
 Actor GunBase
           How far down to drop spawning of projectile
 int MyTeam
           How far down to drop spawning of projectile
 PreKillMessage, PostKillMessage
           How far down to drop spawning of projectile
 Class ProjectileType
           How far down to drop spawning of projectile
 float SampleTime
           How often we sample Instigator's location
 rotator StartingRotation
           How far down to drop spawning of projectile
 int TrackingRate
           How fast Cannon tracks Instigator
 bool bLeadTarget
           How far down to drop spawning of projectile
 bool bShoot
           How far down to drop spawning of projectile

States
GameEnded, TrackWarhead, ActiveCannon, DamagedState, DeActivated, Idle

Function Summary
 void ActivateComplete()
 
simulated
Destroyed()
 string KillMessage(name damageType, Pawn Other)
 Name PickAnim()
 void PlayActivate()
 void PlayDeactivate()
 void PostBeginPlay()
 bool SameTeamAs(int TeamNum)
 void SetTeam(int TeamNum)
 void Shoot()
 
simulated
SpawnBase()
 void StartDeactivate()
 void TakeDamage(int NDamage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)
 
simulated
Tick(float DeltaTime)
 void Trigger(Actor Other, Pawn EventInstigator)


State GameEnded Function Summary
 void BeginState()


State TrackWarhead Function Summary
 void FindEnemy()
 void Timer()


State ActiveCannon Function Summary
 void BeginState()
 void Timer()
 void Killed(Pawn Killer, Pawn Other, name damageType)
 void EnemyNotVisible()


State DamagedState Function Summary


State DeActivated Function Summary


State Idle Function Summary
 void BeginState()
 void SeePlayer(Actor SeenPlayer)



Source Code


00001	//=============================================================================
00002	// TeamCannon.
00003	//=============================================================================
00004	class TeamCannon extends StationaryPawn;
00005	
00006	#exec MESH IMPORT MESH=cdgunmainM ANIVFILE=MODELS\cdgunmain_a.3D DATAFILE=MODELS\cdgunmain_d.3D X=0 Y=0 Z=0
00007	#exec MESH ORIGIN MESH=cdgunmainM X=0 Y=150 Z=0 PITCH=0 YAW=-64 ROLL=-64
00008	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=All    STARTFRAME=0   NUMFRAMES=44
00009	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=Error  STARTFRAME=0   NUMFRAMES=2
00010	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=Activate   STARTFRAME=2   NUMFRAMES=18
00011	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=Fire1  STARTFRAME=21   NUMFRAMES=4
00012	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=Fire2  STARTFRAME=25   NUMFRAMES=4
00013	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=Fire3  STARTFRAME=29   NUMFRAMES=4
00014	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=Fire4  STARTFRAME=33   NUMFRAMES=4
00015	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=Fire5  STARTFRAME=37   NUMFRAMES=4
00016	#exec MESH SEQUENCE MESH=cdgunmainM SEQ=Fire6  STARTFRAME=41   NUMFRAMES=4
00017	#exec TEXTURE IMPORT NAME=jcdgunmain FILE=MODELS\cdgunmain.pcx GROUP=Skins 
00018	#exec MESHMAP SCALE MESHMAP=cdgunmainM X=0.08 Y=0.08 Z=0.16
00019	#exec MESHMAP SETTEXTURE MESHMAP=cdgunmainM NUM=1 TEXTURE=jcdgunmain
00020	
00021	var() sound FireSound;
00022	var() sound ActivateSound;
00023	var() sound DeActivateSound;
00024	var float SampleTime; 			// How often we sample Instigator's location
00025	var int   TrackingRate;			// How fast Cannon tracks Instigator
00026	var float Drop;					// How far down to drop spawning of projectile
00027	var() bool bLeadTarget;
00028	var bool bShoot; 
00029	var() Class<Projectile> ProjectileType;
00030	var rotator StartingRotation;
00031	var() int MyTeam;
00032	var Actor GunBase;
00033	var() localized string PreKillMessage, PostKillMessage;
00034	
00035	function PostBeginPlay()
00036	{
00037		SpawnBase();
00038		Super.PostBeginPlay();
00039		StartingRotation = Rotation;
00040	}
00041	
00042	function string KillMessage( name damageType, pawn Other )
00043	{
00044		return (PreKillMessage@Other.PlayerReplicationInfo.PlayerName@PostKillMessage);
00045	}
00046	
00047	simulated function Destroyed()
00048	{
00049		Super.Destroyed();
00050		if ( GunBase != None )
00051			GunBase.Destroy();
00052	}
00053	
00054	simulated function Tick(float DeltaTime)
00055	{
00056		if ( GunBase == None )
00057			SpawnBase();
00058		Disable('Tick');
00059	}
00060	
00061	simulated function SpawnBase()
00062	{
00063		GunBase = Spawn(class'CeilingGunBase', self);
00064	}
00065	
00066	function SetTeam(int TeamNum)
00067	{
00068		MyTeam = TeamNum;
00069	}
00070	
00071	function bool SameTeamAs(int TeamNum)
00072	{
00073		return (MyTeam == TeamNum);
00074	}
00075	
00076	function TakeDamage( int NDamage, Pawn instigatedBy, Vector hitlocation, 
00077						Vector momentum, name damageType)
00078	{
00079		MakeNoise(1.0);
00080		Health -= NDamage;
00081		if (Health <0) 
00082		{
00083			PlaySound(DeActivateSound, SLOT_None,5.0);
00084			NextState = 'Idle';
00085			Enemy = None;
00086			Spawn(class'UT_BlackSmoke');
00087			GotoState('DamagedState');
00088		}
00089		else if ( instigatedBy == None )
00090			return;
00091		else if ( (Enemy == None) && (!instigatedBy.bIsPlayer || !Level.Game.bTeamGame || !SameTeamAs(instigatedBy.PlayerReplicationInfo.Team)) )
00092		{	
00093			Enemy = instigatedBy;
00094			GotoState('ActiveCannon');
00095		}
00096	}
00097	
00098	function Trigger( actor Other, pawn EventInstigator )
00099	{
00100		GotoState('DeActivated');
00101	}
00102	
00103	function StartDeactivate()
00104	{
00105		SetPhysics(PHYS_Rotating);
00106		DesiredRotation = StartingRotation;
00107	}
00108	
00109	function PlayDeactivate()
00110	{
00111		PlaySound(ActivateSound, SLOT_None,5.0);
00112		TweenAnim('Activate', 1.5);
00113	}
00114	
00115	function PlayActivate()
00116	{
00117		PlayAnim(AnimSequence);
00118		PlaySound(ActivateSound, SLOT_None, 2.0);
00119	}
00120	
00121	function ActivateComplete();
00122	
00123	function Name PickAnim()
00124	{
00125		if (DesiredRotation.Pitch < -13400 )
00126		{
00127			Drop = 35;
00128			return 'Fire6';
00129		}
00130		else if (DesiredRotation.Pitch < -10600 ) 
00131		{
00132			Drop = 30;
00133			return 'Fire5';
00134		}
00135		else if (DesiredRotation.Pitch < -7400 ) 
00136		{
00137			Drop = 25;
00138			return 'Fire4';
00139		}
00140		else if (DesiredRotation.Pitch < -4200 ) 
00141		{
00142			Drop = 20;
00143			return 'Fire3';
00144		}
00145		else if (DesiredRotation.Pitch < -1000 ) 
00146		{
00147			Drop = 15;
00148			return 'Fire2';
00149		}
00150		else 
00151		{
00152			Drop = 10;
00153			return 'Fire1';
00154		}
00155	}
00156		
00157	function Shoot()
00158	{
00159		local Vector FireSpot, ProjStart;
00160		local Projectile p;
00161	
00162		if (DesiredRotation.Pitch < -20000) Return;
00163		PlaySound(FireSound, SLOT_None,5.0);
00164		PlayAnim(PickAnim());
00165	
00166		ProjStart = Location+Vector(DesiredRotation)*100 - Vect(0,0,1)*Drop;
00167		if ( bLeadTarget )
00168		{
00169			FireSpot = Target.Location + FMin(1, 0.7 + 0.6 * FRand()) * (Target.Velocity * VSize(Target.Location - ProjStart)/ProjectileType.Default.Speed);
00170			if ( !FastTrace(FireSpot, ProjStart) )
00171				FireSpot = 0.5 * (FireSpot + Target.Location);
00172			DesiredRotation = Rotator(FireSpot - ProjStart);
00173		}
00174		p = Spawn (ProjectileType,,,ProjStart,DesiredRotation);
00175		if ( DeathMatchPlus(Level.Game).bNoviceMode )
00176			P.Damage *= (0.4 + 0.15 * Level.game.Difficulty);
00177		if ( Target.IsA('WarShell') )
00178			p.speed *= 2;
00179		bShoot=False;
00180		SetTimer(0.05,True);
00181	}	
00182	
00183	auto state Idle
00184	{
00185		ignores EnemyNotVisible;
00186	
00187		function SeePlayer(Actor SeenPlayer)
00188		{
00189	        if ( SeenPlayer.bCollideActors 
00190				&& ((Pawn(SeenPlayer).PlayerReplicationInfo.Team != MyTeam) || !Level.Game.bTeamGame) )
00191			{
00192				Enemy = Pawn(SeenPlayer);
00193				GotoState('ActiveCannon');
00194			}
00195		}
00196	
00197		function BeginState()
00198		{
00199			Enemy = None;
00200		}
00201	
00202	Begin:
00203		TweenAnim(AnimSequence, 0.25);
00204		Sleep(5.0);
00205		StartDeactivate();
00206		Sleep(0.0);
00207		PlayDeactivate();
00208		Sleep(2.0);
00209		SetPhysics(PHYS_None);
00210	}
00211	
00212	state DeActivated
00213	{
00214		ignores SeePlayer, EnemyNotVisible, TakeDamage;
00215	
00216	Begin:
00217		Health = -1; 
00218		Enemy = None;
00219		StartDeactivate();
00220		Sleep(0.0);
00221		PlayDeactivate();
00222		FinishAnim();
00223		Sleep(6.0);
00224		SetPhysics(PHYS_None);
00225	}
00226	
00227	state DamagedState
00228	{
00229		ignores TakeDamage, SeePlayer, EnemyNotVisible;
00230	
00231	Begin:
00232		Enemy = None;
00233		StartDeactivate();
00234		Sleep(0.0);
00235		PlayDeactivate();
00236		FinishAnim();
00237		Spawn(class'UT_BlackSmoke');
00238		Sleep(1.0);
00239		Spawn(class'UT_BlackSmoke');
00240		Sleep(1.0);
00241		Spawn(class'UT_BlackSmoke');
00242		Sleep(13.0);
00243		Health = Default.Health;
00244		GotoState(NextState);
00245	}
00246	
00247	state ActiveCannon
00248	{
00249		ignores SeePlayer;
00250	
00251		function EnemyNotVisible()
00252		{
00253			local Pawn P;
00254	
00255			Enemy = None;
00256			for ( P=Level.PawnList; P!=None; P=P.NextPawn )
00257	               if ( P.bCollideActors && P.bIsPlayer && (!Level.Game.bTeamGame || !SameTeamAs(P.PlayerReplicationInfo.Team))
00258					&& (P.Health > 0) && !P.IsA('TeamCannon')
00259					&& LineOfSightTo(P) )
00260				{
00261					Enemy = P;
00262					return;
00263				}
00264			GotoState('Idle');
00265		}
00266		
00267		function Killed(pawn Killer, pawn Other, name damageType)
00268		{
00269			if ( Other == Enemy )
00270				EnemyNotVisible();
00271		}
00272	
00273		function Timer()
00274		{
00275			local Pawn P;
00276	
00277			DesiredRotation = rotator(Enemy.Location - Location);
00278			DesiredRotation.Yaw = DesiredRotation.Yaw & 65535;
00279			if ( bShoot && (DesiredRotation.Pitch < 2000)
00280				&& ((Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) < 1000)
00281				|| (Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) > 64535)) )
00282				Shoot();
00283			else 
00284			{
00285				TweenAnim(PickAnim(), 0.25);
00286				bShoot=True;			
00287				SetTimer(SampleTime,True);
00288			}
00289		}
00290	
00291		function BeginState()
00292		{
00293			Target = Enemy;
00294		}
00295	
00296	Begin:
00297		Disable('Timer');
00298		FinishAnim();
00299		PlayActivate();
00300		FinishAnim();
00301		ActivateComplete();
00302		Enable('Timer');
00303		SetTimer(SampleTime,True);
00304		RotationRate.Yaw = TrackingRate;
00305		SetPhysics(PHYS_Rotating);
00306		bShoot=True;
00307	
00308	FaceEnemy:
00309		TurnToward(Enemy);
00310		Goto('FaceEnemy');
00311	}
00312	
00313	
00314	state TrackWarhead
00315	{
00316		ignores SeePlayer, EnemyNotVisible;
00317	
00318		function Timer()
00319		{
00320			local Pawn P;
00321	
00322			if ( (Target == None) || Target.bDeleteme )
00323			{
00324				FindEnemy();
00325				return;
00326			}
00327	
00328			DesiredRotation = rotator(Target.Location - Location);
00329			DesiredRotation.Yaw = DesiredRotation.Yaw & 65535;
00330			if ( bShoot && (DesiredRotation.Pitch < 2000)
00331				&& ((Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) < 2000)
00332				|| (Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) > 63535)) )
00333				Shoot();
00334			else 
00335			{
00336				TweenAnim(PickAnim(), 0.25);
00337				bShoot=True;			
00338			}
00339			SetTimer(SampleTime,True);
00340		}
00341		
00342		function FindEnemy()
00343		{
00344			local Pawn P;
00345	
00346			Target = None;
00347			Enemy = None;
00348			for ( P=Level.PawnList; P!=None; P=P.NextPawn )
00349	            if ( P.bCollideActors && P.bIsPlayer && ((P.PlayerReplicationInfo.Team != MyTeam) || !Level.Game.bTeamGame)
00350					&& (P.Health > 0) && !P.IsA('TeamCannon') && LineOfSightTo(P) )
00351				{
00352					Enemy = P;
00353					GotoState('ActiveCannon');
00354				}
00355			GotoState('Idle');
00356		}
00357	
00358	Begin:
00359		Disable('Timer');
00360		FinishAnim();
00361		PlayActivate();
00362		FinishAnim();
00363		ActivateComplete();
00364		Enable('Timer');
00365		SetTimer(SampleTime,True);
00366		RotationRate.Yaw = TrackingRate;
00367		SetPhysics(PHYS_Rotating);
00368		bShoot=True;
00369	
00370	FaceEnemy:
00371		if ( (Target == None) || Target.bDeleteme )
00372			FindEnemy();
00373		TurnToward(Target);
00374		Goto('FaceEnemy');
00375	}
00376	
00377	
00378	state GameEnded
00379	{
00380	ignores SeePlayer, HearNoise, KilledBy, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, Falling, TakeDamage, WarnTarget, Died;
00381	
00382		function BeginState()
00383		{
00384			Destroy();
00385		}
00386	}
00387	
00388	defaultproperties
00389	{
00390	     FireSound=Sound'UnrealI.Cannon.CannonShot'
00391	     ActivateSound=Sound'UnrealI.Cannon.CannonActivate'
00392	     SampleTime=0.330000
00393	     TrackingRate=25000
00394	     Drop=60.000000
00395	     ProjectileType=Class'Botpack.CannonShot'
00396	     PostKillMessage="was killed by an automatic cannon!"
00397	     SightRadius=3000.000000
00398	     FovAngle=90.000000
00399	     Health=220
00400	     MenuName="automatic cannon!"
00401	     NameArticle="an "
00402	     RemoteRole=ROLE_SimulatedProxy
00403	     AnimSequence=Activate
00404	     Mesh=LodMesh'Botpack.cdgunmainM'
00405	     CollisionRadius=28.000000
00406	     RotationRate=(Yaw=25000)
00407	}

End Source Code