## Engine
Class Armor

source: C:\XIII\Engine\Classes\Armor.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Inventory
             |
             +--Engine.Armor

Direct Known Subclasses:Casque, GiletMk1

class Armor
extends Engine.Inventory

    //-----------------------------------------------------------
    //
    //-----------------------------------------------------------

Variables
`int` | `ArmorAbsorption` Percent of damage item absorbs 0-100.
`name` | `BoneToAttach` bone to attach the armor
`enum` | `DamageLocations` Percent of damage item absorbs 0-100.
`Pawn.DamageLocations` | `ProtectedArea` Percent of damage item absorbs 0-100.

Function Summary
`simulated` | `AttachArmorToPawn(Pawn P)`
    //_____________________________________________________________________________
`simulated` | `ClientSetUpArmor(Pawn Other)`
    //_____________________________________________________________________________
`void` | `GiveTo(Pawn Other)`
    //_____________________________________________________________________________
`bool` | `HandlePickupQuery(Pickup Item)`
    //_____________________________________________________________________________
`void` | `PickupFunction(Pawn Other)`
    //_____________________________________________________________________________
`void` | `Transfer(Pawn Other)`
    //_____________________________________________________________________________

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class Armor extends Inventory
    00005	  native
    00006	  abstract;
    00007
    00008	var() int ArmorAbsorption;                // Percent of damage item absorbs 0-100.
    00009	/*
    00010	var() enum DamageLocations
    00011	{
    00012	    LOC_Head,
    00013	    LOC_Body,
    00014	} ProtectedArea;                          // Area protezcted by the armor
    00015	*/
    00016	var() Pawn.DamageLocations ProtectedArea;
    00017
    00018	var() name BoneToAttach;                  // bone to attach the armor
    00019
    00020	//_____________________________________________________________________________
    00021	// Network replication.
    00022	replication
    00023	{
    00024	  // Things the server should send to the client.
    00025	  reliable if( Role==ROLE_Authority )
    00026	    ClientSetUpArmor;
    00027	}
    00028
    00029	//_____________________________________________________________________________
    00030	function PickupFunction(Pawn Other)
    00031	{
    00032	    Super.PickupFunction(Other);
    00033	    AttachArmorToPawn(Other);
    00034	}
    00035
    00036	//_____________________________________________________________________________
    00037	function bool HandlePickupQuery( Pickup Item )
    00038	{
    00039		if (Item.InventoryType == class)
    00040		{
    00041	        if( Item.IsA('MarioArmorAndMedKitPickUp') )
    00042	            Charge = 100;
    00043	        else
    00044	            Charge = Min(Default.Charge, Charge + ArmorPickup(Item).ProtectionLevel);
    00045
    00046			Item.AnnouncePickup(Pawn(Owner));
    00047			return true;
    00048		}
    00049		if ( Inventory == None )
    00050			return false;
    00051
    00052		return Inventory.HandlePickupQuery(Item);
    00053	}
    00054
    00055	//_____________________________________________________________________________
    00056	function Transfer( pawn Other )
    00057	{
    00058	    Super.Transfer(Other);
    00059	    if ( PickupClass != none )
    00060	    {
    00061	      Other.PlaySound(PickupClass.default.PickupSound);
    00062	      Other.ReceiveLocalizedMessage( PickupClass.default.MessageClass, 0, None, None, PickupClass );
    00063	    }
    00064	}
    00065
    00066	//_____________________________________________________________________________
    00067	function GiveTo( pawn Other )
    00068	{
    00069	    local Armor A;
    00070
    00071	    DetachFromPawn(Pawn(Owner));
    00072	    A = Armor(Other.FindInventoryType(class));
    00073	    if ( A == none )
    00074	    { // GiveTo
    00075	      Super.GiveTo(other);
    00076	      AttachArmorToPawn(Other);
    00077	      if ( ProtectedArea == LOC_Head )
    00078	        Other.Helm = self;
    00079	      else if ( ProtectedArea == LOC_Body )
    00080	        Other.Vest = self;
    00081	      ClientSetUpArmor(Other);
    00082	    }
    00083	    else
    00084	    { // Just get charges
    00085			  A.Charge = Min(A.Default.Charge, A.Charge + class<ArmorPickup>(PickupClass).default.ProtectionLevel);
    00086			  Destroy();
    00087	    }
    00088	}
    00089
    00090	//_____________________________________________________________________________
    00091	simulated function ClientSetUpArmor(Pawn Other)
    00092	{
    00093	    if (Other != none)
    00094	    {
    00095	//      Log(self@"ClientSetUpArmor for"@other);
    00096	      if ( ProtectedArea == LOC_Head )
    00097	        Other.Helm = self;
    00098	      else if ( ProtectedArea == LOC_Body )
    00099	        Other.Vest = self;
    00100	      Instigator = Other;
    00101	    }
    00102	    else
    00103	      SetTimer2(1.0, true);
    00104	}
    00105
    00106	//_____________________________________________________________________________
    00107	// Wait for pawn replication
    00108	simulated event Timer2()
    00109	{
    00110	    if ( Instigator != none )
    00111	    {
    00112	      if ( ProtectedArea == LOC_Head )
    00113	        Instigator.Helm = self;
    00114	      else if ( ProtectedArea == LOC_Body )
    00115	        Instigator.Vest = self;
    00116	      SetTimer2(0.0, false);
    00117	    }
    00118	    else if ( Pawn(Owner) != none )
    00119	    {
    00120	      if ( ProtectedArea == LOC_Head )
    00121	        Pawn(Owner).Helm = self;
    00122	      else if ( ProtectedArea == LOC_Body )
    00123	        Pawn(Owner).Vest = self;
    00124	      SetTimer2(0.0, false);
    00125	      Instigator = Pawn(Owner);
    00126	    }
    00127	}
    00128
    00129	//_____________________________________________________________________________
    00130	simulated function AttachArmorToPawn(Pawn P)
    00131	{
    00132		local name BoneName;
    00133
    00134		if ( ThirdPersonActor == None )
    00135		{
    00136			ThirdPersonActor = Spawn(AttachmentClass,Owner);
    00137			InventoryAttachment(ThirdPersonActor).InitFor(self);
    00138		}
    00139		BoneName = BoneToAttach;
    00140		if ( BoneName == '' )
    00141		{
    00142			ThirdPersonActor.SetLocation(P.Location);
    00143			ThirdPersonActor.SetBase(P);
    00144		}
    00145		else
    00146			P.AttachToBone(ThirdPersonActor,BoneName);
    00147
    00148		ThirdPersonActor.SetRelativeLocation(ThirdPersonRelativeLocation);
    00149		ThirdPersonActor.SetRelativeRotation(ThirdPersonRelativeRotation);
    00150	}
    00151
    00152	//_____________________________________________________________________________
    00153	// ELR Check if the armor should absorb damages with it's protectedarea
    00154	// Server function
    00155	function int ArmorAbsorbDamage(int Damage, class<DamageType> DamageType, vector HitLocation)
    00156	{
    00157	    local int ArmorDamage;
    00158
    00159	    if ( HitLocation.X == ProtectedArea )
    00160	    {
    00161	      //      Log(self@"ArmorAbsorbDamage charge="$Charge);
    00162	      ArmorDamage = (Damage * ArmorAbsorption) / 100;
    00163	      if( ArmorDamage >= Charge )
    00164	        ArmorDamage = Charge;
    00165
    00166	      Charge -= ArmorDamage;
    00167	      //      Log("    New charge="$Charge);
    00168	      if (Charge == 0)
    00169	      {
    00170	        if ( Pawn(Owner).Helm == self )
    00171	          Pawn(Owner).Helm = none;;
    00172	        if ( Pawn(Owner).Vest == self )
    00173	          Pawn(Owner).Vest = none;;
    00174	        /*
    00175	        if ( ProtectedArea == LOC_Head )
    00176	        Pawn(Owner).Helm = none;
    00177	        else if ( ProtectedArea == LOC_Body )
    00178	        Pawn(Owner).Vest = none;
    00179	        */
    00180	        Destroy();
    00181	      }
    00182	      return (Damage - ArmorDamage);
    00183	    }
    00184	    return Damage;
    00185	}
    00186
    00187	simulated event Destroyed()
    00188	{
    00189	    Super.Destroyed();
    00190	    //Log("ARMOR Destroyed for Instigator="@Instigator@"Owner="$Owner);
    00191	    if ( Instigator != none )
    00192	    {
    00193	      if ( ProtectedArea == LOC_Head )
    00194	        Instigator.Helm = none;
    00195	      else if ( ProtectedArea == LOC_Body )
    00196	        Instigator.Vest = none;
    00197	    }
    00198	}
    00199
    00200	defaultproperties
    00201	{
    00202	     bReplicateInstigator=True
    00203	}

End Source Code