Classes:BasicArmorBonus

From ZDoom Wiki
Jump to navigation Jump to search
Note: Wait! Stop! You do not need to copy this actor's code into your project! Here's why:
  1. This actor is already defined in GZDoom, there's no reason to define it again.
  2. In fact, trying to define an actor with the same name will cause an error (because it already exists).
  3. If you want to make your own version of this actor, use inheritance.
  4. Definitions for existing actors are put on the wiki for reference purpose only.
Basic armor bonus
Actor type Internal Game MiniZDoomLogoIcon.png (ZDoom)
DoomEd Number None Class Name BasicArmorBonus


Classes: InventoryArmorBasicArmorBonus
 →ArmorBonus


BasicArmorBonus are armor items that add points to the player's current armor. The base class BasicArmorBonus is never used directly. It is always the base class for predefined items (like Doom's armor bonus) or for items defined in DECORATE.

The purpose of this class is to increase the player's current armor. To do this, upon being picked up, BasicArmorBonus finds an instance of the BasicArmor class in the player's inventory and increases its amount, without modifying any other values (such as savePercent, icon or others) that determine the actual effectiveness of the armor. In practical terms, this means that BasicArmorBonus adds to existing armor without modifying it, and doesn't give any armor on its own. The only exception is when the player doesn't have any armor yet: only in this case will BasicArmorBonus utilize its own SavePercent value and "give" the player some armor.

BasicArmorBonus sets the INVENTORY.ALWAYSPICKUP flag by default, but it can be unset, so that your armor bonuses don't get picked up if the player already has the maximum aount of armor.

BasicArmorBonus also uses the INVENTORY.AUTOACTIVATE flag, bcause its main behavior is tied to its Use override. Unsetting this flag will let the bonuses be placed in the player's inventory so that they can be used manually later.

Using in DECORATE and ZScript

BasicArmorBonus uses the basic Inventory properties to define their behavior as inventory items. They also define a few new properties to define their behavior as armor.

  • Armor.SavePercent percentage
The percentage of dealt damage that the armor absorbs.
Percentage is specified as a floating point value between 0.0 and 100.0 which is converted internally to a floating point value between 0.0 and 1.0
  • Armor.MaxSaveAmount amount
Sets the maximum amount of armor you can reach by picking up this item.
  • Armor.SaveAmount amount
The amount of armor that this item gives.
  • Armor.MaxBonus amount
The amount of armor you obtain additionally to your save amount value.
  • Armor.MaxBonusMax amount
The maximum additional save amount you can obtain with the armor.

Examples

ZScript

class DoubleArmorBonus : BasicArmorBonus
{
  Default
  {
    Armor.MaxSaveAmount 250;
    Armor.SavePercent 50;
    Armor.SaveAmount 2;
    Inventory.Icon "ABO2A0";
  }
  States
  {
  Spawn:
    ABO2 AB 3;
    ABO2 C 6;
    ABO2 B 3;
    loop;
  }
}

DECORATE (deprecated)

BasicMaxArmorBonus (Skulltag Imported)

actor MaxArmorBonus : BasicArmorBonus 2015
{
  spawnid 176
  radius 20
  height 16
  inventory.pickupmessage "Picked up a max armor bonus."
  inventory.icon "ARM1A0"
  armor.savepercent 33.33333
  armor.saveamount 1
  armor.maxsaveamount 200
  armor.maxbonus 1
  armor.maxbonusmax 50
  +COUNTITEM
  +INVENTORY.ALWAYSPICKUP
  states
  {
  Spawn:
    BON2 ABCDCB 6
    loop
  }
}

ZScript definition

Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub.
class BasicArmorBonus : Armor 
{
	double SavePercent;	// The default, for when you don't already have armor
	int MaxSaveAmount;
	int MaxAbsorb;
	int MaxFullAbsorb;
	int SaveAmount;
	int BonusCount;
	int BonusMax;
	
	property prefix: Armor;
	property MaxSaveAmount: MaxSaveAmount;
	property SaveAmount : SaveAmount;
	property SavePercent: SavePercent;
	property MaxAbsorb: MaxAbsorb;
	property MaxFullAbsorb: MaxFullAbsorb;
	property MaxBonus: BonusCount;
	property MaxBonusMax: BonusMax;

	Default
	{
		+Inventory.AUTOACTIVATE
		+Inventory.ALWAYSPICKUP
		Inventory.MaxAmount 0;
		Armor.SavePercent 33.335;
	}
	
	//===========================================================================
	//
	// ABasicArmorBonus :: CreateCopy
	//
	//===========================================================================

	override Inventory CreateCopy (Actor other)
	{
		let copy = BasicArmorBonus(Super.CreateCopy (other));
		copy.SavePercent = SavePercent;
		copy.SaveAmount = SaveAmount;
		copy.MaxSaveAmount = MaxSaveAmount;
		copy.BonusCount = BonusCount;
		copy.BonusMax = BonusMax;
		copy.MaxAbsorb = MaxAbsorb;
		copy.MaxFullAbsorb = MaxFullAbsorb;

		return copy;
	}

	//===========================================================================
	//
	// ABasicArmorBonus :: Use
	//
	// Tries to add to the amount of BasicArmor a player has.
	//
	//===========================================================================

	override bool Use (bool pickup)
	{
		let armor = BasicArmor(Owner.FindInventory("BasicArmor"));
		bool result = false;

		// This should really never happen but let's be prepared for a broken inventory.
		if (armor == null)
		{
			armor = BasicArmor(Spawn("BasicArmor"));
			armor.BecomeItem ();
			armor.Amount = 0;
			armor.MaxAmount = MaxSaveAmount;
			Owner.AddInventory (armor);
		}

		if (BonusCount > 0 && armor.BonusCount < BonusMax)
		{
			armor.BonusCount = min(armor.BonusCount + BonusCount, BonusMax);
			result = true;
		}

		int saveAmount = min(GetSaveAmount(), MaxSaveAmount);

		if (saveAmount <= 0)
		{ // If it can't give you anything, it's as good as used.
			return BonusCount > 0 ? result : true;
		}

		// If you already have more armor than this item can give you, you can't
		// use it.
		if (armor.Amount >= MaxSaveAmount + armor.BonusCount)
		{
			return result;
		}

		if (armor.Amount <= 0)
		{ // Should never be less than 0, but might as well check anyway
			armor.Amount = 0;
			armor.Icon = Icon;
			armor.SavePercent = clamp(SavePercent, 0, 100) / 100;
			armor.MaxAbsorb = MaxAbsorb;
			armor.ArmorType = GetClassName();
			armor.MaxFullAbsorb = MaxFullAbsorb;
			armor.ActualSaveAmount = MaxSaveAmount;
		}

		armor.Amount = min(armor.Amount + saveAmount, MaxSaveAmount + armor.BonusCount);
		armor.MaxAmount = max(armor.MaxAmount, MaxSaveAmount);
		return true;
	}

	
	override void SetGiveAmount(Actor receiver, int amount, bool bycheat)
	{
		SaveAmount *= amount;
	}

	int GetSaveAmount ()
	{
		return !bIgnoreSkill ? int(SaveAmount * G_SkillPropertyFloat(SKILLP_ArmorFactor)) : SaveAmount;
	}
}

DECORATE definition

Note: This is legacy code, kept for archival purposes only. DECORATE is deprecated in GZDoom and is completely superseded by ZScript. GZDoom internally uses the ZScript definition above.
ACTOR BasicArmorBonus : Armor native
{
  +INVENTORY.AUTOACTIVATE
  +INVENTORY.ALWAYSPICKUP
  Inventory.MaxAmount 0
  Armor.SavePercent 33.335
}