Piece of code

Mar 26, 2008, 7:22 pm
#1
Joined: Feb 28, 2008
Occupation: Web developper
Location: Paris
Posts: 38
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 ()
Mar 26, 2008, 7:31 pm
#2
Joined: Mar 14, 2008
Posts: 62
Have you ever heard of a program called "Diff"
Mar 27, 2008, 10:22 am
#3
Joined: Mar 25, 2008
Posts: 9
If it's not needed other changes from the CVS version could you make me a patch?
Mar 27, 2008, 11:39 am
#4
Joined: Feb 28, 2008
Occupation: Web developper
Location: Paris
Posts: 38
Here for you nukes, added it to my first message. Nice people always get what they want
Jump to