Engine
Class Shield

source: c:\runehov\Engine\Classes\Shield.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Inventory
         |
         +--Engine.Shield
Direct Known Subclasses:DarkShield, DwarfBattleShield, DwarfWoodShield, GoblinShield, MagicShield, VikingShield, VikingShield2, WaterloggedShield, SarkBallShield

class Shield
extends Engine.Inventory

//============================================================================= // Shield. //=============================================================================
Variables
 int Health
 int Rating
 bool bBreakable
 bool bMadeDropSound

States
Bashing, Smashed, Drop, Active, Idle, BeingPickedUp, Pickup

Function Summary
 void DestroyEffect()
     
//-----------------------------------------------------------------------------
//
// DestroyEffect
//
// Used when shield is destroyed
//-----------------------------------------------------------------------------
 int GetUsePriority()
     
//============================================================================
//
// GetUsePriority
//
// Returns the priority of the weapon, lower is better
//============================================================================
 bool JointDamaged(int Damage, Pawn EventInstigator, vector HitLoc, vector Momentum, name DamageType, int joint)
 EMatterType MatterForJoint(int joint)
     
//============================================================
//
// MatterForJoint
//
// Returns what kind of material joint is associated with
//============================================================
 Inventory SpawnCopy(Pawn Other)
     
//=============================================================================
//
// SpawnCopy
//
// Either give this inventory to player Other, or spawn a copy
// and give it to the player Other, setting up original to be respawned.
// Also add Ammo to Other's inventory if it doesn't already exist
//
//=============================================================================


State Bashing Function Summary
 void PlayHitSound(name DamageType)
     
//=============================================================================
//
// Sound Functions
//
//=============================================================================
 void DropFrom(vector StartLocation)
     
//=============================================================================
//
// DropFrom
//
//=============================================================================
 void Tick()
     
	{
		local actor a;
		local vector hitLoc, hitNorm;
		local vector extent;

		extent.x = 10;
		extent.y = 10;
		extent.z = 10;

		foreach TraceActors(class'actor', a, hitLoc, hitNorm,
			Location + vector(Owner.Rotation) * 80,, extent)
		{
			a.JointDamaged(2, Owner, hitLoc, vect(0, 0, 0), 'blunt', 0);
		}
	}

	
 void BashActors()
     
//-----------------------------------------------------------------------------

	
 void EndState()
     
	{
		Enable('Tick');
	}

	
 void BeginState()
     
{
	


State Smashed Function Summary
 void BeginState()


State Drop Function Summary
 void Touch(Actor Other)
     
	{
		if(Other.IsA('Pawn'))
		{
			if(Pawn(Other).Health > 0 && Pawn(Other).CanPickUp(self))
			{
				SetOwner(Other);
				GotoState('BeingPickedUp');
			}
		}
	}
*/
 void Touch(Actor Other)
     
/*	
 void HitWall(vector HitNormal, Actor HitActor)
 void Landed(vector HitNormal, Actor HitActor)
 void EndState()
 void BeginState()


State Active Function Summary
 void EndState()
 void BeginState()


State Idle Function Summary


State BeingPickedUp Function Summary
 void BeginState()
     
{
	ignores JointDamaged;

	


State Pickup Function Summary
 void Touch(Actor Other)
 void EndState()
 void BeginState()



Source Code


00001	//=============================================================================
00002	// Shield.
00003	//=============================================================================
00004	class Shield expands Inventory
00005		abstract;
00006	
00007	var() int Health;
00008	var() int Rating;
00009	var(Sounds) sound DestroyedSound;
00010	var bool bMadeDropSound;
00011	var bool bBreakable;
00012	
00013	replication
00014	{
00015		reliable if (Role==ROLE_Authority)
00016			Health;
00017	}
00018	
00019	//============================================================
00020	//
00021	// MatterForJoint
00022	//
00023	// Returns what kind of material joint is associated with
00024	//============================================================
00025	function EMatterType MatterForJoint(int joint)
00026	{
00027		return MATTER_SHIELD;
00028	}
00029	
00030	//-----------------------------------------------------------------------------
00031	//
00032	// DestroyEffect
00033	//
00034	// Used when shield is destroyed
00035	//-----------------------------------------------------------------------------
00036	function DestroyEffect()
00037	{
00038	}
00039	
00040	//============================================================================
00041	//
00042	// GetUsePriority
00043	//
00044	// Returns the priority of the weapon, lower is better
00045	//============================================================================
00046	
00047	function int GetUsePriority()
00048	{
00049		return(2);
00050	}
00051	
00052	//=============================================================================
00053	//
00054	// SpawnCopy
00055	//
00056	// Either give this inventory to player Other, or spawn a copy
00057	// and give it to the player Other, setting up original to be respawned.
00058	// Also add Ammo to Other's inventory if it doesn't already exist
00059	//
00060	//=============================================================================
00061	
00062	function inventory SpawnCopy( pawn Other )
00063	{
00064		local inventory Copy;
00065		if( Level.Game.ShouldRespawn(self) )
00066		{
00067			Copy = spawn(Class,Other,,,rot(0,0,0));
00068			if (Copy == None)
00069				log(name@"cannot be spawned in spawncopy");
00070			Copy.Tag           = Tag;
00071			Copy.Event         = Event;
00072			GotoState('Sleeping');
00073		}
00074		else
00075			Copy = self;
00076	
00077		Copy.bTossedOut = true;
00078		Copy.RespawnTime = 0.0;
00079		Copy.GiveTo( Other );
00080		Copy.bHidden = false; // BecomeItem in Inventory automatically hides the item
00081		return Copy;
00082	}
00083	
00084	
00085	
00086	function bool JointDamaged(int Damage, Pawn EventInstigator, vector HitLoc, vector Momentum, name DamageType, int joint)
00087	{
00088		local vector AdjMomentum;
00089		local Pawn P;
00090	
00091		PlayHitSound(DamageType);
00092	
00093		if (bBreakable)
00094		{
00095			if (Pawn(Owner)!=None && PlayerPawn(Owner)==None && FRand()*Level.Game.Difficulty < 0.2)
00096			{	// Pawns drop shields once in a while on easier skill levels
00097				Pawn(Owner).DropShield();
00098				return false;
00099			}
00100				
00101			Health -= Damage * 0.6;
00102		}
00103	
00104		// Apply momentum to the shield owner (TODO:  Scale by a percentage?)
00105		// NOTE:  This code is duplicated in Shield.Idle state, as well as in Pawn
00106		if(Owner != None)
00107		{
00108			AdjMomentum = momentum / Owner.Mass;
00109			if(Owner.Mass < VSize(AdjMomentum) && Owner.Velocity.Z <= 0)
00110			{			
00111				AdjMomentum.Z += (VSize(AdjMomentum) - Owner.Mass) * 0.5;
00112			}
00113	
00114			P = Pawn(Owner);
00115			P.AddVelocity(AdjMomentum);
00116	
00117	/* CJR TEST -- Recoil animation when hit in the shield
00118			if(P.CanGotoPainState() && Health > 0)
00119			{ // Recoil from being hit in the shield
00120				P.NextState = P.GetStateName();
00121				P.PlayAnim('h3_defendPain', 1.0, 0.01);
00122				P.GotoState('Pain');
00123			}
00124	*/
00125		}
00126	
00127		if(Health <= 0)
00128		{
00129			GotoState('Smashed');
00130			return(true);
00131		}
00132	
00133		return(false);
00134	}
00135	
00136	//=============================================================================
00137	//
00138	// TravelPostAccept
00139	//
00140	//=============================================================================
00141	
00142	event TravelPostAccept()
00143	{
00144		local PlayerPawn P;
00145		local int joint;
00146	
00147		Super.TravelPostAccept();
00148	
00149		if(Pawn(Owner) == None)
00150		{
00151			return;
00152		}
00153	
00154		if(self == Pawn(Owner).Shield)
00155		{
00156			joint = Owner.JointNamed(Pawn(Owner).ShieldJoint);
00157			Owner.AttachActorToJoint(self, joint);
00158			GotoState('Idle');
00159		}
00160	}
00161	
00162	
00163	//-----------------------------------------------------------------------------
00164	//
00165	// State Pickup
00166	//
00167	// Sitting on the ground waiting to be picked up
00168	//-----------------------------------------------------------------------------
00169	
00170	auto state Pickup
00171	{
00172		ignores JointDamaged;
00173	
00174		function BeginState()
00175		{
00176			bSweepable=false;
00177			BecomePickup();
00178			bCollideWorld = true;
00179			if (bTossedOut && bExpireWhenTossed)	// If not a placed item, expire after some time
00180				LifeSpan=ExpireTime;
00181		}
00182		
00183		function EndState()
00184		{
00185			bSweepable=Default.bSweepable;
00186			BecomeItem();
00187			bCollideWorld = false;
00188			LifeSpan=0;				// Disallow expire, since someone picked me up
00189		}
00190		
00191		function Touch(Actor Other)
00192		{
00193			local inventory Copy;
00194	
00195			if(Other.IsA('Pawn'))
00196			{
00197				if(Pawn(Other).Health > 0 && Pawn(Other).CanPickUp(self))
00198				{
00199					if (Level.Game.LocalLog != None)
00200						Level.Game.LocalLog.LogPickup(Self, Pawn(Other));
00201					if (Level.Game.WorldLog != None)
00202						Level.Game.WorldLog.LogPickup(Self, Pawn(Other));
00203					Copy = SpawnCopy(Pawn(Other));
00204	
00205					if(PickupMessageClass == None)
00206						Pawn(Other).ClientMessage(PickupMessage, 'Pickup');
00207					else
00208						Pawn(Other).ReceiveLocalizedMessage( PickupMessageClass, 0, None, None, Self.Class);
00209	
00210					Copy.PlaySound (PickupSound);
00211					if ( Level.Game.Difficulty > 1 )
00212						Other.MakeNoise(0.1 * Level.Game.Difficulty);
00213					Pawn(Other).AcquireInventory(Copy);
00214					Copy.GotoState('Idle');
00215				}
00216			}
00217		}
00218		
00219	begin:
00220		AmbientGlow = 0;
00221		SkelMesh = Default.SkelMesh;
00222	}
00223	
00224	//-----------------------------------------------------------------------------
00225	//
00226	// State BeingPickedUp
00227	//
00228	// About to be picked up by another actor
00229	//
00230	//-----------------------------------------------------------------------------
00231	/*
00232	state BeingPickedUp
00233	{
00234		ignores JointDamaged;
00235	
00236		function BeginState()
00237		{
00238			Pawn(Owner).AcquireInventory(self);
00239			GotoState('Idle');
00240		}
00241		
00242	begin:
00243	}
00244	*/
00245	
00246	//-----------------------------------------------------------------------------
00247	//
00248	// State Idle
00249	//
00250	// Idle in the actor's hand, waiting to be used (not currently used)
00251	//-----------------------------------------------------------------------------
00252	state Idle
00253	{
00254	
00255	begin:
00256	}
00257	
00258	//-----------------------------------------------------------------------------
00259	//
00260	// State Active
00261	//
00262	// Active and absorbing damage
00263	//-----------------------------------------------------------------------------
00264	
00265	state Active
00266	{
00267		function BeginState()
00268		{
00269			SetPhysics(PHYS_None);
00270		}
00271		
00272		function EndState()
00273		{
00274		}
00275	
00276	begin:
00277	}
00278	
00279	
00280	//-----------------------------------------------------------------------------
00281	//
00282	// State Drop
00283	//
00284	// Was dropped
00285	//-----------------------------------------------------------------------------
00286	
00287	state Drop
00288	{
00289		ignores JointDamaged;
00290	
00291		function BeginState()
00292		{
00293			SetPhysics(PHYS_Falling);
00294			SetCollision(true, false, false);
00295			bCollideWorld = true;
00296			bBounce = true;
00297			bFixedRotationDir = true;
00298			DesiredRotation.Yaw = Rotation.Yaw + Rand(2000) - 1000;
00299			RotationRate.Yaw = 60000;
00300			DesiredRotation.Pitch = Rotation.Pitch + Rand(2000) - 1000;
00301			RotationRate.Pitch = 60000;
00302			bMadeDropSound = false;
00303		}
00304		
00305		function EndState()
00306		{
00307			bBounce = false;
00308			SetCollision(false, false, false);
00309			bCollideWorld = false;
00310			bBounce = false;		
00311			bFixedRotationDir = false;
00312		}
00313		
00314		function Landed(vector HitNormal, actor HitActor)
00315		{
00316			HitWall(HitNormal, HitActor);
00317		}
00318		
00319		function HitWall(vector HitNormal, actor HitActor)
00320		{
00321			local float speed;
00322	
00323			if (!bMadeDropSound && !Region.Zone.bWaterZone)
00324			{
00325				bMadeDropSound=true;
00326				PlaySound(DropSound, SLOT_Interact);
00327				MakeNoise(1.0);
00328			}
00329	
00330			speed = VSize(velocity);
00331			if((HitNormal.Z > 0.8) && (speed < 60))
00332			{
00333				if(DesiredRotation.Roll ~= Rotation.Roll
00334					&& DesiredRotation.Pitch ~= Rotation.Pitch)
00335				{
00336					SetPhysics(PHYS_None);
00337					bBounce = false;
00338					bFixedRotationDir = false;
00339				
00340					GotoState('Pickup');
00341				}
00342				else
00343				{
00344					DesiredRotation.Roll = 0;
00345					DesiredRotation.Pitch = 32768;
00346					RotationRate.Roll = 60000;
00347					RotationRate.Pitch = 80000;
00348					bRotateToDesired = true;
00349					bFixedRotationDir = false;
00350	
00351					Velocity.Z = 60;
00352				}
00353			}
00354			else
00355			{			
00356				SetPhysics(PHYS_Falling);
00357				RotationRate.Yaw = VSize(Velocity) * 150;
00358				RotationRate.Pitch = VSize(Velocity) * 100;
00359				
00360				Velocity = 0.7 * (Velocity - 2 * HitNormal * (Velocity Dot HitNormal));
00361				DesiredRotation = rotator(HitNormal);
00362			}
00363		}
00364	
00365	/*	function Touch(Actor Other)
00366		{
00367			if(Other.IsA('Pawn'))
00368			{
00369				if(Pawn(Other).Health > 0 && Pawn(Other).CanPickUp(self))
00370				{
00371					SetOwner(Other);
00372					GotoState('BeingPickedUp');
00373				}
00374			}
00375		}
00376	*/
00377	
00378		function Touch(Actor Other)
00379		{
00380			local inventory Copy;
00381	
00382			if(Other.IsA('Pawn'))
00383			{
00384				if(Pawn(Other).Health > 0 && Pawn(Other).CanPickUp(self))
00385				{
00386					if (Level.Game.LocalLog != None)
00387						Level.Game.LocalLog.LogPickup(Self, Pawn(Other));
00388					if (Level.Game.WorldLog != None)
00389						Level.Game.WorldLog.LogPickup(Self, Pawn(Other));
00390					Copy = SpawnCopy(Pawn(Other));
00391	
00392					if(PickupMessageClass == None)
00393						Pawn(Other).ClientMessage(PickupMessage, 'Pickup');
00394					else
00395						Pawn(Other).ReceiveLocalizedMessage( PickupMessageClass, 0, None, None, Self.Class);
00396	
00397					Copy.PlaySound (PickupSound);
00398					if ( Level.Game.Difficulty > 1 )
00399						Other.MakeNoise(0.1 * Level.Game.Difficulty);
00400					Pawn(Other).AcquireInventory(Copy);
00401	
00402					if(!Pawn(Other).IsInState('PlayerSwimming'))
00403						Copy.GotoState('Active');
00404				}
00405			}
00406		}
00407	
00408	}
00409	
00410	//-----------------------------------------------------------------------------
00411	//
00412	// State Smashed
00413	//
00414	// Shield was destroyed
00415	//-----------------------------------------------------------------------------
00416	
00417	state Smashed
00418	{
00419		ignores JointDamaged;
00420	
00421		function BeginState()
00422		{
00423			local int joint;
00424			local Pawn ThePawn;
00425	
00426			ThePawn = Pawn(Owner);
00427			if (ThePawn != None)
00428			{
00429				joint = ThePawn.JointNamed(ThePawn.ShieldJoint);
00430				if (joint != 0)
00431				{
00432					ThePawn.DetachActorFromJoint(joint);
00433					ThePawn.DeleteInventory(self);
00434				}
00435			}
00436	
00437			DestroyEffect();
00438			PlaySound(DestroyedSound, SLOT_Pain);
00439			Destroy(); // remove self!
00440		}
00441	
00442	begin:
00443	}
00444	
00445	//-----------------------------------------------------------------------------
00446	//
00447	// State Bashing
00448	//
00449	// Shield is bashing anything in front of it
00450	//-----------------------------------------------------------------------------
00451	/*
00452	state Bashing
00453	{
00454		function BeginState()
00455		{
00456			Enable('Tick');
00457		}
00458	
00459		function EndState()
00460		{
00461			Disable('Tick');
00462		}
00463	
00464		//-----------------------------------------------------------------------------
00465		//
00466		// BashActors
00467		//
00468		//-----------------------------------------------------------------------------
00469	
00470		function BashActors()
00471		{
00472			local actor a;
00473			local vector hitLoc, hitNorm;
00474			local vector extent;
00475	
00476			extent.x = 10;
00477			extent.y = 10;
00478			extent.z = 10;
00479	
00480			foreach TraceActors(class'actor', a, hitLoc, hitNorm,
00481				Location + vector(Owner.Rotation) * 80,, extent)
00482			{
00483				a.JointDamaged(2, Owner, hitLoc, vect(0, 0, 0), 'blunt', 0);
00484			}
00485		}
00486	
00487		function Tick()
00488		{
00489			BashActors
00490			
00491		}
00492	
00493	begin:
00494	}
00495	*/
00496	//=============================================================================
00497	//
00498	// DropFrom
00499	//
00500	//=============================================================================
00501	
00502	function DropFrom(vector StartLocation)
00503	{
00504		if(!SetLocation(StartLocation))
00505		{
00506			return;
00507		}
00508			
00509		SetPhysics(PHYS_Falling);
00510		SetCollision( true, false, false );
00511		bCollideWorld = true;
00512	//	SetOwner(None);
00513		
00514		GotoState('Pickup');
00515	}
00516	
00517	
00518	
00519	//=============================================================================
00520	//
00521	// Sound Functions
00522	//
00523	//=============================================================================
00524	function PlayHitSound(name DamageType)
00525	{
00526	}
00527	
00528	
00529	simulated function Debug(canvas Canvas, int mode)
00530	{
00531		Super.Debug(Canvas, mode);
00532	
00533		Canvas.DrawText("Shield:");
00534		Canvas.CurY -= 8;
00535		Canvas.DrawText(" Health: "@Health);
00536		Canvas.CurY -= 8;
00537	}
00538	
00539	defaultproperties
00540	{
00541	     bBreakable=True
00542	     RespawnTime=30.000000
00543	     Buoyancy=4.000000
00544	}

End Source Code