UnrealI
Class Cannon

source: e:\games\UnrealTournament\UnrealI\Classes\Cannon.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Decoration
         |
         +--UnrealI.Cannon
Direct Known Subclasses:HugeCannon

class Cannon
extends Engine.Decoration

//============================================================================= // Cannon. //=============================================================================
Variables
 sound ActivateSound
           How far down to drop spawning of projectile
 float DeactivateDistance
           How far away Instigator must be to deactivate Cannon
 float Drop
           How far down to drop spawning of projectile
 sound ExplodeSound
           How far down to drop spawning of projectile
 sound FireSound
           How far down to drop spawning of projectile
 float Health
           How far down to drop spawning of projectile
 float SampleTime
           How often we sample Instigator's location
 int ShotsFired
           How far down to drop spawning of projectile
 int TrackingRate
           How fast Cannon tracks Instigator
 Actor a
           How far down to drop spawning of projectile
 bool bShoot
           How far down to drop spawning of projectile
 Actor cTarget
           How far down to drop spawning of projectile

States
DeActivate, ActivateCannon

Function Summary
 void Shoot()
 void TakeDamage(int NDamage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)
     
// To resolve error 'virtual function 'shoot' not found'
 void Trigger(Actor Other, Pawn EventInstigator)


State DeActivate Function Summary


State ActivateCannon Function Summary
 void Shoot()
 void Timer()
 void Trigger(Actor Other, Pawn EventInstigator)



Source Code


00001	//=============================================================================
00002	// Cannon.
00003	//=============================================================================
00004	class Cannon extends Decoration;
00005	
00006	#exec MESH IMPORT MESH=CannonM ANIVFILE=MODELS\cannon_a.3D DATAFILE=MODELS\cannon_d.3D X=0 Y=0 Z=0
00007	#exec MESH ORIGIN MESH=CannonM X=0 Y=270 Z=0 YAW=-64 ROLL=-64
00008	#exec MESH SEQUENCE MESH=CannonM SEQ=All  STARTFRAME=0  NUMFRAMES=20
00009	#exec MESH SEQUENCE MESH=CannonM SEQ=Activate STARTFRAME=0   NUMFRAMES=10
00010	#exec MESH SEQUENCE MESH=CannonM SEQ=Angle0  STARTFRAME=10  NUMFRAMES=1
00011	#exec MESH SEQUENCE MESH=CannonM SEQ=Angle1  STARTFRAME=11  NUMFRAMES=1
00012	#exec MESH SEQUENCE MESH=CannonM SEQ=Angle2  STARTFRAME=12  NUMFRAMES=1
00013	#exec MESH SEQUENCE MESH=CannonM SEQ=Angle3  STARTFRAME=13  NUMFRAMES=1
00014	#exec MESH SEQUENCE MESH=CannonM SEQ=Angle4  STARTFRAME=14  NUMFRAMES=1
00015	#exec MESH SEQUENCE MESH=CannonM SEQ=FAngle0  STARTFRAME=15  NUMFRAMES=1
00016	#exec MESH SEQUENCE MESH=CannonM SEQ=FAngle1  STARTFRAME=16  NUMFRAMES=1
00017	#exec MESH SEQUENCE MESH=CannonM SEQ=FAngle2  STARTFRAME=17  NUMFRAMES=1
00018	#exec MESH SEQUENCE MESH=CannonM SEQ=FAngle3  STARTFRAME=18  NUMFRAMES=1
00019	#exec MESH SEQUENCE MESH=CannonM SEQ=FAngle4 STARTFRAME=19  NUMFRAMES=1
00020	#exec TEXTURE IMPORT NAME=JCannon1 FILE=MODELS\cannon.PCX GROUP=Skins
00021	#exec OBJ LOAD FILE=..\UnrealShare\Textures\fireeffect13.utx PACKAGE=UNREALI.Effect13
00022	#exec MESHMAP SCALE MESHMAP=CannonM X=0.2 Y=0.2 Z=0.4
00023	#exec MESHMAP SETTEXTURE MESHMAP=CannonM NUM=0 TEXTURE=Unreali.Effect13.FireEffect13
00024	#exec MESHMAP SETTEXTURE MESHMAP=CannonM NUM=1 TEXTURE=JCannon1
00025	
00026	#exec AUDIO IMPORT FILE="Sounds\Cannon\turshot1.wav" NAME="CannonShot" GROUP="Cannon" 
00027	#exec AUDIO IMPORT FILE="Sounds\Cannon\turdrop1.wav" NAME="CannonActivate" GROUP="Cannon" 
00028	#exec AUDIO IMPORT FILE="Sounds\Cannon\turExpl.wav" NAME="CannonExplode" GROUP="Cannon" 
00029	
00030	var() float DeactivateDistance;	// How far away Instigator must be to deactivate Cannon
00031	var() float SampleTime; 			// How often we sample Instigator's location
00032	var() int   TrackingRate;			// How fast Cannon tracks Instigator
00033	var() float Drop;					// How far down to drop spawning of projectile
00034	var() float Health;
00035	var() sound FireSound;
00036	var() sound ActivateSound;
00037	var() sound ExplodeSound;
00038	var actor cTarget;
00039	var bool bShoot; 
00040	var int ShotsFired;
00041	var actor a;
00042	
00043	function Shoot() {}   // To resolve error 'virtual function 'shoot' not found'
00044	
00045	function TakeDamage( int NDamage, Pawn instigatedBy, Vector hitlocation, 
00046						Vector momentum, name damageType)
00047	{
00048		Instigator = InstigatedBy;
00049		if (Health<0) Return;
00050		if ( Instigator != None )
00051			MakeNoise(1.0);
00052		Health -= NDamage;
00053		if (Health <0) {
00054			PlaySound(ExplodeSound, SLOT_None,5.0);	
00055			skinnedFrag(class'Fragment1',texture'JCannon1', Momentum,1.0,17);	
00056			Destroy();
00057		}
00058	}
00059	
00060	
00061	function Trigger( actor Other, pawn EventInstigator )
00062	{
00063		cTarget    = Other;
00064		Instigator = EventInstigator;
00065		GotoState( 'ActivateCannon');
00066	}
00067	
00068	state ActivateCannon
00069	{
00070		function Trigger( actor Other, pawn EventInstigator ) {}
00071	
00072		function Timer()
00073		{
00074	
00075			if (VSize(cTarget.Location - Location) > DeactivateDistance) GoToState('Deactivate');
00076			if (Pawn(cTarget)!=None && Pawn(cTarget).Health>0 || cTarget==None) GoToState('Deactivate');
00077			DesiredRotation = rotator(cTarget.Location - Location + Vect(0,0,1)*Drop);
00078			DesiredRotation.Yaw = DesiredRotation.Yaw & 65535;
00079			if (Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) < 1000
00080				&& DesiredRotation.Pitch < 1000 && bShoot)	Shoot();
00081			else if (Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) > 64535 
00082				&& DesiredRotation.Pitch < 1000 && bShoot)	Shoot();
00083			else {
00084				if (DesiredRotation.Pitch < -6000 ) TweenAnim('Angle4', 0.25);
00085				else if (DesiredRotation.Pitch < -4000 ) TweenAnim('Angle3', 0.25);
00086				else if (DesiredRotation.Pitch < -2000 ) TweenAnim('Angle2', 0.25);
00087				else if (DesiredRotation.Pitch < -500 ) TweenAnim('Angle1', 0.25);
00088				else TweenAnim('Angle0', 0.25);		
00089				bShoot=True;			
00090			}
00091			bRotateToDesired = True;
00092			SetTimer(SampleTime,True);
00093		}
00094		
00095		function Shoot()
00096		{
00097			if (DesiredRotation.Pitch < -10000) Return;
00098			PlaySound(FireSound, SLOT_None,5.0);
00099			if (DesiredRotation.Pitch < -6000 ) PlayAnim('FAngle4',5.0);
00100			else if (DesiredRotation.Pitch < -4000 ) PlayAnim('FAngle3',5.0);
00101			else if (DesiredRotation.Pitch < -2000 ) PlayAnim('FAngle2',5.0);
00102			else if (DesiredRotation.Pitch < -500 ) PlayAnim('FAngle1',5.0);
00103			else PlayAnim('FAngle0',5.0);
00104			Spawn (class'CannonBolt',,,Location+Vector(DesiredRotation)*100 - Vect(0,0,1)*Drop,DesiredRotation);
00105			bShoot=False;
00106			SetTimer(0.05,True);
00107		}
00108	
00109	Begin:
00110		PlayAnim('Activate',0.5);
00111		PlaySound(ActivateSound, SLOT_None, 2.0);
00112		FinishAnim();
00113		SetTimer(SampleTime,True);
00114		RotationRate.Yaw = TrackingRate;
00115		SetPhysics(PHYS_Rotating);
00116		bShoot=True;
00117	}
00118	
00119	state DeActivate
00120	{
00121	Begin:
00122		TweenAnim('Activate',3.0);
00123		if (Event!='')
00124			foreach AllActors( class 'Actor', A, Event )
00125				A.Trigger( Self, Pawn(cTarget) );
00126		
00127	}
00128	
00129	defaultproperties
00130	{
00131	     DeactivateDistance=2000.000000
00132	     SampleTime=0.300000
00133	     TrackingRate=10000
00134	     Drop=60.000000
00135	     Health=100.000000
00136	     FireSound=Sound'UnrealI.Cannon.CannonShot'
00137	     ActivateSound=Sound'UnrealI.Cannon.CannonActivate'
00138	     ExplodeSound=Sound'UnrealI.Cannon.CannonExplode'
00139	     bStatic=False
00140	     DrawType=DT_Mesh
00141	     Mesh=LodMesh'UnrealI.CannonM'
00142	     CollisionRadius=44.000000
00143	     CollisionHeight=44.000000
00144	     bCollideActors=True
00145	     bCollideWorld=True
00146	     bProjTarget=True
00147	     RotationRate=(Yaw=50000)
00148	}

End Source Code