Damage Reduction

Moderator: GZDoom Developers

Post Reply
Sir Cyril Fudgelot
Posts: 16
Joined: Wed Mar 24, 2010 11:34 pm
Location: Dead on the field of Caramel.

Damage Reduction

Post by Sir Cyril Fudgelot »

I was very grateful when damage factors were added, but I have always wanted a different method of handling damage resistance based more on D&D or GURPS based damage reduction, where a flat amount of damage was subtracted from the total before other effects. After looking through the code, I think this would be simple to do.

In info.cpp:

Code: Select all

void FActorInfo::SetDamageReduction(FName type, fixed_t factor)
{
    if (DamageReductions == NULL)
    {
        DamageReductions = new DmgReductions;
    }
    DamageReductions->Insert(type, factor);
}
In info.h:

Code: Select all

struct DmgReductions : public TMap<FName, int>
{
    int *CheckFactor(FName type);
};
Inside the definition of FActorInfo:

Code: Select all

void SetDamageReduction(FName type, fixed_t factor);
DmgReductions *DamageReductions;
In ABasicArmor::AbsorbDamage, directly after the check for whether an attack absorbs armor but before the definition of "full":

Code: Select all

const int* reduction = NULL;
DmgReductions *dr = PClass::FindClass(ArmorType)->ActorInfo->DamageReductions;
if (dr != NULL && dr->CountUsed() != 0)
{
    reduction = dr->CheckFactor(damageType);
    if (reduction != NULL)
    {
        damage = newdamage = damage-reduction;
        if (damage < 0)
        {
            damage = newdamage = 0;
        }
    }
}
I think that would do it. Before assessing the save amount, you subtract damage from the incoming attack equal to the damage reduction given the damage type, and use the "reduced" damage to determine armor damage and so forth. The problem is, I'm not sure where to go to find the code for the decorate parser, so I don't know how to create armor to test it with. Is this enough to be considered a feature request? If not, could you point me to the relevant source files?

Thanks. I understand similar effects could be achieved (and indeed have been) with more cumbersome ACS or decorate workarounds, but it seemed so easy to implement at the source level I thought I'd ask here.

Thanks! I've put more hours into enjoying doom than any other game ever!
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: Damage Reduction

Post by Gez »

Sir Cyril Fudgelot wrote:The problem is, I'm not sure where to go to find the code for the decorate parser, so I don't know how to create armor to test it with.
Look in thingdef_properties.cpp. You should use the DEFINE_PROPERTY(name, parameters, class) macro, based on the many examples in that file. The parameters are declared as single letters, look at ParsePropertyParams() in thingdef_parse.cpp for their list and explanation.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: Damage Reduction

Post by Xaser »

I'm still tickled that Sir Cyril Fudgelot officially adopted his auto-generated royal nomenclature. :P
Sir Cyril Fudgelot
Posts: 16
Joined: Wed Mar 24, 2010 11:34 pm
Location: Dead on the field of Caramel.

Re: Damage Reduction

Post by Sir Cyril Fudgelot »

Gez wrote:Look in thingdef_properties.cpp. You should use the DEFINE_PROPERTY(name, parameters, class) macro, based on the many examples in that file. The parameters are declared as single letters, look at ParsePropertyParams() in thingdef_parse.cpp for their list and explanation.
Perfect. I'll look there. I looked over other code submissions, and noticed they were in patch format. If I get it working, I'll update my original post. I found a wonderful guide to building ZDoom on the wiki; I'm glad I looked there first before asking about it.
Xaser wrote:I'm still tickled that Sir Cyril Fudgelot officially adopted his auto-generated royal nomenclature.
Yeah, well... I'm actually in self-imposed exile after a particularly immature action on these forums caused me profound embarrassment. I still wanted to post that bug report, though, and found I could do so without registering, so I went with it. Your story tickled my fancy, so I figured it was as suitable an appellation as any, and decided (when I found another bug to report) that I might as well stick with it so you would all know the same person reported both bugs. Besides, I've always disliked trying to come up with proper nouns.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Damage Reduction

Post by Graf Zahl »

Please repost this as a ready to use patch file, this looks incomplete.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Damage Reduction

Post by Graf Zahl »

OK, one month has passed without response, off this goes...
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”