## Engine
Class Powerups

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

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

Direct Known Subclasses:XIIIDocuments, XIIIItems, XIIISkill, XIIIThingsToSave

class Powerups
extends Engine.Inventory

    //=============================================================================
    // Powerup items - activatable inventory.
    //=============================================================================

Variables
`ActivateSound,` | `DeActivateSound` Messages shown when powerup charge runs out
`String` | `ExpireMessage` Messages shown when powerup charge runs out
`int` | `NumCopies`
`bool` | `bActivatable` Whether item can be activated/deactivated (if true, must auto activate)
`bool` | `bAutoActivate` automatically activated when picked up
`bool` | `bCanHaveMultipleCopies` if player can possess more than one of this

States
Activated

Function Summary
`void` | `Activate()`
    //
    // Toggle Activation of selected Item.
    //
`void` | `FireEffect()`
`string` | `GetLocalString(optional int, optional PlayerReplicationInfo, optional PlayerReplicationInfo)`
`bool` | `HandlePickupQuery(Pickup Item)`
    //
    // Advanced function which lets existing items in a pawn's inventory
    // prevent the pawn from picking something up. Return true to abort pickup
    // or if item handles the pickup
`void` | `PickupFunction(Pawn Other)`
`Powerups` | `SelectNext()`
    //
    // Select first activatable item.
    //
`float` | `UseCharge(float Amount)`
`void` | `UsedUp()`
    //
    // This is called when a usable inventory item has used up it's charge.
    //

State Activated Function Summary
`void` | `Activate()`
`void` | `EndState()`
`void` | `BeginState()`

Source Code

    00001	//=============================================================================
    00002	// Powerup items - activatable inventory.
    00003	//=============================================================================
    00004	class Powerups extends Inventory
    00005		abstract
    00006		native
    00007		nativereplication;
    00008
    00009	var travel int NumCopies;
    00010	var() bool bCanHaveMultipleCopies;     // if player can possess more than one of this
    00011	var() bool bAutoActivate;			   // automatically activated when picked up
    00012	var() bool        bActivatable;       // Whether item can be activated/deactivated (if true, must auto activate)
    00013	var	travel bool   bActive;			  // Whether item is currently activated.
    00014	var() String ExpireMessage; // Messages shown when powerup charge runs out
    00015
    00016	var() sound ActivateSound, DeActivateSound;
    00017
    00018	replication
    00019	{
    00020		// Things the server should send to the client.
    00021		reliable if( bNetOwner && bNetDirty && (Role==ROLE_Authority) )
    00022			NumCopies, bActivatable, bActive;
    00023	}
    00024
    00025	event TravelPreAccept()
    00026	{
    00027		Super.TravelPreAccept();
    00028		if( bActive )
    00029			Activate();
    00030	}
    00031
    00032	function PickupFunction(Pawn Other)
    00033	{
    00034		Super.PickupFunction(Other);
    00035
    00036		if (bActivatable && Other.SelectedItem==None)
    00037			Other.SelectedItem=self;
    00038		if (bActivatable && bAutoActivate && Other.bAutoActivate)
    00039			Activate();
    00040	}
    00041
    00042	//
    00043	// Select first activatable item.
    00044	//
    00045	function Powerups SelectNext()
    00046	{
    00047		if ( bActivatable )
    00048			return self;
    00049
    00050		if ( Inventory != None )
    00051			return Inventory.SelectNext();
    00052		else
    00053			return None;
    00054	}
    00055
    00056	//
    00057	// Toggle Activation of selected Item.
    00058	//
    00059	function Activate()
    00060	{
    00061		if( bActivatable )
    00062		{
    00063			if (Level.Game.StatLog != None)
    00064				Level.Game.StatLog.LogItemActivate(Self, Pawn(Owner));
    00065
    00066			GoToState('Activated');
    00067		}
    00068	}
    00069
    00070	//
    00071	// Advanced function which lets existing items in a pawn's inventory
    00072	// prevent the pawn from picking something up. Return true to abort pickup
    00073	// or if item handles the pickup
    00074	function bool HandlePickupQuery( Pickup Item )
    00075	{
    00076		if (item.InventoryType == class)
    00077		{
    00078			if (bCanHaveMultipleCopies)
    00079				NumCopies++;
    00080			else if ( bDisplayableInv )
    00081			{
    00082				if ( Item.Inventory != None )
    00083					Charge = Max(Charge, Item.Inventory.Charge);
    00084				else
    00085					Charge = Max(Charge, Item.InventoryType.Default.Charge);
    00086			}
    00087			else
    00088				return false;
    00089
    00090			Item.AnnouncePickup(Pawn(Owner));
    00091			return true;
    00092		}
    00093		if ( Inventory == None )
    00094			return false;
    00095
    00096		return Inventory.HandlePickupQuery(Item);
    00097	}
    00098
    00099	function float UseCharge(float Amount);
    00100	function FireEffect();
    00101
    00102	//
    00103	// This is called when a usable inventory item has used up it's charge.
    00104	//
    00105	function UsedUp()
    00106	{
    00107		if ( Pawn(Owner) != None )
    00108		{
    00109			bActivatable = false;
    00110			Pawn(Owner).NextItem();
    00111			if (Pawn(Owner).SelectedItem == Self)
    00112			{
    00113				Pawn(Owner).NextItem();
    00114				if (Pawn(Owner).SelectedItem == Self)
    00115					Pawn(Owner).SelectedItem=None;
    00116			}
    00117			if (Level.Game.StatLog != None)
    00118				Level.Game.StatLog.LogItemDeactivate(Self, Pawn(Owner));
    00119			Instigator.ReceiveLocalizedMessage( MessageClass, 0, None, None, Self.Class );
    00120		}
    00121		Owner.PlaySound(DeactivateSound);
    00122		Destroy();
    00123	}
    00124
    00125	static function string GetLocalString(
    00126		optional int Switch,
    00127		optional PlayerReplicationInfo RelatedPRI_1,
    00128		optional PlayerReplicationInfo RelatedPRI_2
    00129		)
    00130	{
    00131		return Default.ExpireMessage;
    00132	}
    00133
    00134
    00135	//=============================================================================
    00136	// Active state: this inventory item is armed and ready to rock!
    00137
    00138	state Activated
    00139	{
    00140		function BeginState()
    00141		{
    00142			bActive = true;
    00143		}
    00144
    00145		function EndState()
    00146		{
    00147			bActive = false;
    00148		}
    00149
    00150		function Activate()
    00151		{
    00152			if ( (Pawn(Owner) != None) && Pawn(Owner).bAutoActivate
    00153				&& bAutoActivate && (Charge>0) )
    00154					return;
    00155
    00156			Global.Activate();
    00157		}
    00158	}
    00159
    00160	defaultproperties
    00161	{
    00162	}

End Source Code