Flag: Applying Damagefactors before armor calculations

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

Flag: Applying Damagefactors before armor calculations

Postby Major Cooke » Tue Feb 11, 2020 10:27 am

The idea behind this is simple: if a flag (say +ARMOR.PREFACTOR) is used, the armor will apply damagefactors first before reducing armor amounts. I've seen many mods that have armor like this:

Code: Select allExpand view
ACTOR LegendaryArmor : RedArmor //16701
{
//$Category Powerups/LCA
//$Sprite LEGAA0
//$Title "Legendary Armor"
   +INVENTORY.BIGPOWERUP
    +NOTIMEFREEZE
   Scale 1.2
   +DONTTHRUST
   DamageFactor "PDTBFG", 0.10
   DamageFactor "PDTBFGTracer", 0.10
   DamageFactor "Cyber10K", 0.01
   DamageFactor "Legendary", 0.10
   DamageFactor "Legendary1", 0.10
   DamageFactor "LegendaryGuru", 0.10
   DamageFactor "BFGSplash", 0.35
   DamageFactor "BFGSpray", 0.35
   DamageFactor "Explosion", 0.5
   DamageFactor "Plasma", 0.5
   DamageFactor 0.5
   Inventory.Pickupmessage "Legendary Armor. You won't die so easily"
   Inventory.Icon "LEGAA0"
   Inventory.PickupSound "legendaryarmor/pickup"
   Armor.SavePercent 100
   Armor.SaveAmount 500


But sadly these don't do anything since the armor absorbs all the damage first.

Making this submission would be easy, except for one thing: where to add the flag, and I'm still trying to figure out where to transfer the flag upon picking it up.

If you're wondering why I am not handling a lot of these things on my mod's end, it's because the armor system is... complicated.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Flag: Applying Damagefactors before armor calculations

Postby Apeirogon » Sun Feb 16, 2020 2:40 pm

Major Cooke wrote:If you're wondering why I am not handling a lot of these things on my mod's end, it's because the armor system is... complicated.

Is it?

https://github.com/coelckers/gzdoom/blo ... or.zs#L202
is a line where armors damage factor are applies, so just move this block from the end of a function to the beginning in you "base_mod name_armor" class, like
Code: Select allExpand view
   override void AbsorbDamage (int damage, Name damageType, out int newdamage)
   {

      // Once the armor has absorbed its part of the damage, then apply its damage factor, if any, to the player
      if ((damage > 0) && (ArmorType != 'None')) // BasicArmor is not going to have any damage factor, so skip it.
      {
         newdamage = ApplyDamageFactors(ArmorType, damageType, damage, damage);
         damage = newdamage;//since next it use 'damage' variable
      }

      int saved;

      if (!DamageTypeDefinition.IgnoreArmor(damageType))
      {
         int full = MAX(0, MaxFullAbsorb - AbsorbCount);
         
         if (damage < full)
         {
            saved = damage;
         }
         else
         {
            saved = full + int((damage - full) * SavePercent);
            if (MaxAbsorb > 0 && saved + AbsorbCount > MaxAbsorb)
            {
               saved = MAX(0,  MaxAbsorb - AbsorbCount);
            }
         }

         if (Amount < saved)
         {
            saved = Amount;
         }
         newdamage -= saved;
         Amount -= saved;
         AbsorbCount += saved;
         if (Amount == 0)
         {
            // The armor has become useless
            SavePercent = 0;
            ArmorType = 'None'; // Not NAME_BasicArmor.
            // Now see if the player has some more armor in their inventory
            // and use it if so. As in Strife, the best armor is used up first.
            BasicArmorPickup best = null;
            Inventory probe = Owner.Inv;
            while (probe != null)
            {
               let inInv = BasicArmorPickup(probe);
               if (inInv != null)
               {
                  if (best == null || best.SavePercent < inInv.SavePercent)
                  {
                     best = inInv;
                  }
               }
               probe = probe.Inv;
            }
            if (best != null)
            {
               Owner.UseInventory (best);
            }
         }
         damage = newdamage;
      }

   }
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Flag: Applying Damagefactors before armor calculations

Postby Major Cooke » Sun Feb 16, 2020 8:33 pm

The problem is, the system is set up to find a direct BasicArmor instead of subclasses.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Flag: Applying Damagefactors before armor calculations

Postby Apeirogon » Mon Feb 17, 2020 3:24 pm

"Universal" mod which should work with other mods!?
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017


Return to Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests