Piece of code

https://attnam.com/topics/Piece-of-code

The Cathedral of Attnam > Other Coding

#1 Mar 26, 2008, 7:22 pm Hide

Planplan

Here a small piece of code I made to allow Helmet, Cloak, Body Armor and Belt to add Arm Strength, Dexterity, Leg Strength and Agility. It's maybe a bit dirty, but it work.
The enchant bonus is divised by 2, because the bonus value is added to each arm or leg. A +1 Dexterity bonus will add +0.5 Dexterity to each arm so (could be invisible for a +1 item so, unless you're Dexterity is already a bit trained).
---------- bodypart.h ----------

ITEM(bodypart, item)
{
 public:
  ...
  item* GetExternalHelmet() const;
  item* GetExternalBelt() const;
  ...
};

ITEM(arm, bodypart)
{
 public:
  ...
  void ApplyStrengthBonus(item*);
  void ApplyDexterityBonus(item*);
  ...
};

ITEM(leg, bodypart)
{
 public:
  ...
  void ApplyStrengthBonus(item*);
  void ApplyAgilityBonus(item*);
  ...
};


---------- bodypart.cpp ----------

item* bodypart::GetExternalHelmet() const { return GetHumanoidMaster()->GetHelmet(); }
item* bodypart::GetExternalBelt() const { return GetHumanoidMaster()->GetBelt(); }


void arm::CalculateAttributeBonuses()
{
  ...
  if(Master)
  {
    ...
    ApplyStrengthBonus(GetExternalHelmet());
    ApplyStrengthBonus(GetExternalCloak());
    ApplyStrengthBonus(GetExternalBodyArmor());
    ApplyStrengthBonus(GetExternalBelt());
    ApplyDexterityBonus(GetExternalHelmet());
    ApplyDexterityBonus(GetExternalCloak());
    ApplyDexterityBonus(GetExternalBodyArmor());
    ApplyDexterityBonus(GetExternalBelt());
  }
}

void leg::CalculateAttributeBonuses()
{
  ...
  if(Master)
  {
    ...
    ApplyStrengthBonus(GetExternalHelmet());
    ApplyStrengthBonus(GetExternalCloak());
    ApplyStrengthBonus(GetExternalBodyArmor());
    ApplyStrengthBonus(GetExternalBelt());
    ApplyAgilityBonus(GetExternalHelmet());
    ApplyAgilityBonus(GetExternalCloak());
    ApplyAgilityBonus(GetExternalBodyArmor());
    ApplyAgilityBonus(GetExternalBelt());
  }
}


void arm::ApplyStrengthBonus(item* Item)
{
  if(Item && Item->AffectsArmStrength())
    StrengthBonus += Item->GetEnchantment() / 2;
}

void arm::ApplyDexterityBonus(item* Item)
{
  if(Item && Item->AffectsDexterity())
    DexterityBonus += Item->GetEnchantment() / 2;
}

void leg::ApplyStrengthBonus(item* Item)
{
  if(Item && Item->AffectsLegStrength())
    StrengthBonus += Item->GetEnchantment() / 2;
}

void leg::ApplyAgilityBonus(item* Item)
{
  if(Item && Item->AffectsAgility())
    AgilityBonus += Item->GetEnchantment() / 2;
}
Tell me if you encounter bugs, I'll edit this code, and feel free to post your own.
Attached files
enchant.zip ()
#2 Mar 26, 2008, 7:31 pm Hide

Dumb Shit

Have you ever heard of a program called "Diff"
#3 Mar 27, 2008, 10:22 am Hide

nukes

If it's not needed other changes from the CVS version could you make me a patch?
#4 Mar 27, 2008, 11:39 am Hide

Planplan

Here for you nukes, added it to my first message. Nice people always get what they want