]> git.localhorst.tv Git - l2e.git/commitdiff
converted equipment from explicit members to array
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 27 Nov 2012 11:57:03 +0000 (12:57 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 27 Nov 2012 11:57:03 +0000 (12:57 +0100)
src/battle/Hero.h
src/common/Hero.cpp
src/common/Hero.h
src/common/Item.h
src/main.cpp
src/menu/EquipMenu.cpp
src/menu/StatusMenu.cpp

index d719288b376f2e687e64c5f5924c204483d696a4..1ec41406a6bb17347fc8228f423c6e7e215bca9e 100644 (file)
@@ -54,26 +54,26 @@ public:
        common::Stats &GetStats() { return stats; }
        const common::Stats &GetStats() const { return stats; }
 
-       common::Item *Weapon() { return master->Weapon(); }
-       common::Item *Armor() { return master->Armor(); }
-       common::Item *Shield() { return master->Shield(); }
-       common::Item *Helmet() { return master->Helmet(); }
-       common::Item *Ring() { return master->Ring(); }
-       common::Item *Jewel() { return master->Jewel(); }
-
-       const common::Item *Weapon() const { return master->Weapon(); }
-       const common::Item *Armor() const { return master->Armor(); }
-       const common::Item *Shield() const { return master->Shield(); }
-       const common::Item *Helmet() const { return master->Helmet(); }
-       const common::Item *Ring() const { return master->Ring(); }
-       const common::Item *Jewel() const { return master->Jewel(); }
-
-       bool HasWeapon() const { return master->HasWeapon(); }
-       bool HasArmor() const { return master->HasArmor(); }
-       bool HasShield() const { return master->HasShield(); }
-       bool HasHelmet() const { return master->HasHelmet(); }
-       bool HasRing() const { return master->HasRing(); }
-       bool HasJewel() const { return master->HasJewel(); }
+       common::Item *Weapon() { return master->Equipment(common::Hero::EQUIP_WEAPON); }
+       common::Item *Armor() { return master->Equipment(common::Hero::EQUIP_ARMOR); }
+       common::Item *Shield() { return master->Equipment(common::Hero::EQUIP_SHIELD); }
+       common::Item *Helmet() { return master->Equipment(common::Hero::EQUIP_HELMET); }
+       common::Item *Ring() { return master->Equipment(common::Hero::EQUIP_RING); }
+       common::Item *Jewel() { return master->Equipment(common::Hero::EQUIP_JEWEL); }
+
+       const common::Item *Weapon() const { return master->Equipment(common::Hero::EQUIP_WEAPON); }
+       const common::Item *Armor() const { return master->Equipment(common::Hero::EQUIP_ARMOR); }
+       const common::Item *Shield() const { return master->Equipment(common::Hero::EQUIP_SHIELD); }
+       const common::Item *Helmet() const { return master->Equipment(common::Hero::EQUIP_HELMET); }
+       const common::Item *Ring() const { return master->Equipment(common::Hero::EQUIP_RING); }
+       const common::Item *Jewel() const { return master->Equipment(common::Hero::EQUIP_JEWEL); }
+
+       bool HasWeapon() const { return master->Equipped(common::Hero::EQUIP_WEAPON); }
+       bool HasArmor() const { return master->Equipped(common::Hero::EQUIP_ARMOR); }
+       bool HasShield() const { return master->Equipped(common::Hero::EQUIP_SHIELD); }
+       bool HasHelmet() const { return master->Equipped(common::Hero::EQUIP_HELMET); }
+       bool HasRing() const { return master->Equipped(common::Hero::EQUIP_RING); }
+       bool HasJewel() const { return master->Equipped(common::Hero::EQUIP_JEWEL); }
 
        graphics::AnimationRunner &GetAnimation() { return animation; }
        const graphics::AnimationRunner &GetAnimation() const { return animation; }
index ab73a6be70d3ee91fbc003d4918342ebba28638c..7150af0a35b8c0528058d5c845794875c4483c18 100644 (file)
 #include "../loader/TypeDescription.h"
 #include "../map/Entity.h"
 
+#include <cstring>
+
 using graphics::Animation;
 using graphics::Sprite;
 using loader::FieldDescription;
 using loader::Interpreter;
 using loader::TypeDescription;
 using map::Entity;
+using std::memset;
+
 
 namespace common {
 
@@ -40,18 +44,11 @@ Hero::Hero()
 
 , useMask(0)
 
-, weapon(0)
-, armor(0)
-, shield(0)
-, helmet(0)
-, ring(0)
-, jewel(0)
-
 , battleSprite(0)
 , meleeAnimation(0)
 , attackAnimation(0)
 , spellAnimation(0) {
-
+       memset(equipment, 0, sizeof(equipment));
 }
 
 
index dcbc7827547604a8f3a34a4541a51361e251a429..f61d0ee95507b5ae009e25ea31ccd28d3469de63 100644 (file)
@@ -27,6 +27,16 @@ public:
        ~Hero() { }
 
 public:
+       enum EquipSlot {
+               EQUIP_WEAPON,
+               EQUIP_ARMOR,
+               EQUIP_SHIELD,
+               EQUIP_HELMET,
+               EQUIP_RING,
+               EQUIP_JEWEL,
+               EQUIP_COUNT,
+       };
+
        const char *Name() const { return name; }
 
        Uint16 MaxHealth() const { return maxHealth; }
@@ -53,33 +63,11 @@ public:
        bool CanEquip(const Item &) const;
        bool CanInvoke(const Spell &) const;
 
-       Item *Weapon() { return weapon; }
-       Item *Armor() { return armor; }
-       Item *Shield() { return shield; }
-       Item *Helmet() { return helmet; }
-       Item *Ring() { return ring; }
-       Item *Jewel() { return jewel; }
-
-       const Item *Weapon() const { return weapon; }
-       const Item *Armor() const { return armor; }
-       const Item *Shield() const { return shield; }
-       const Item *Helmet() const { return helmet; }
-       const Item *Ring() const { return ring; }
-       const Item *Jewel() const { return jewel; }
-
-       bool HasWeapon() const { return weapon; }
-       bool HasArmor() const { return armor; }
-       bool HasShield() const { return shield; }
-       bool HasHelmet() const { return helmet; }
-       bool HasRing() const { return ring; }
-       bool HasJewel() const { return jewel; }
-
-       void RemoveWeapon() { weapon = 0; }
-       void RemoveArmor() { armor = 0; }
-       void RemoveShield() { shield = 0; }
-       void RemoveHelmet() { helmet = 0; }
-       void RemoveRing() { ring = 0; }
-       void RemoveJewel() { jewel = 0; }
+       Item *Equipment(EquipSlot i) { return equipment[i]; }
+       const Item *Equipment(EquipSlot i) const { return equipment[i]; }
+       bool Equipped(EquipSlot i) const { return equipment[i]; }
+       void RemoveEquipment(EquipSlot i) { equipment[i] = 0; }
+       void SetEquipment(EquipSlot i, Item *item) { equipment[i] = item; }
 
        std::vector<const Spell *> &Spells() { return spells; }
        const std::vector<const Spell *> &Spells() const { return spells; }
@@ -98,13 +86,6 @@ public:
 
 // temporary setters
 public:
-       void SetWeapon(common::Item *i) { weapon = i; }
-       void SetArmor(common::Item *i) { armor = i; }
-       void SetShield(common::Item *i) { shield = i; }
-       void SetHelmet(common::Item *i) { helmet = i; }
-       void SetRing(common::Item *i) { ring = i; }
-       void SetJewel(common::Item *i) { jewel = i; }
-
        void AddSpell(Spell *s) { spells.push_back(s); }
 
 private:
@@ -124,12 +105,7 @@ private:
 
        int useMask;
 
-       Item *weapon;
-       Item *armor;
-       Item *shield;
-       Item *helmet;
-       Item *ring;
-       Item *jewel;
+       Item *equipment[EQUIP_COUNT];
 
        // TODO: vector does not seem to be a good choice
        std::vector<const Spell *> spells;
index bd8e7a999e720875e09e3b5a277671da9942b263..06c0f83588d9ca8e9bc4d95dfc29a7a9f8f98a27 100644 (file)
@@ -9,6 +9,7 @@
 #define COMMON_ITEM_H_
 
 #include "fwd.h"
+#include "Hero.h"
 #include "TargetingMode.h"
 #include "../graphics/fwd.h"
 
@@ -92,12 +93,12 @@ public:
 private:
        enum Equipable {
                EQUIPPABLE_NONE = 0,
-               EQUIPPABLE_WEAPON = 1,
-               EQUIPPABLE_ARMOR = 2,
-               EQUIPPABLE_SHIELD = 4,
-               EQUIPPABLE_HELMET = 8,
-               EQUIPPABLE_RING = 16,
-               EQUIPPABLE_JEWEL = 32,
+               EQUIPPABLE_WEAPON = 1 << Hero::EQUIP_WEAPON,
+               EQUIPPABLE_ARMOR = 1 << Hero::EQUIP_ARMOR,
+               EQUIPPABLE_SHIELD = 1 << Hero::EQUIP_SHIELD,
+               EQUIPPABLE_HELMET = 1 << Hero::EQUIP_HELMET,
+               EQUIPPABLE_RING = 1 << Hero::EQUIP_RING,
+               EQUIPPABLE_JEWEL = 1 << Hero::EQUIP_JEWEL,
        };
        enum Property {
                PROPERTY_HAS_EFFECT_STATUS = 1,
index f78e7f7d74373f5fb3a812c6a3fbfca5255cccf1..08547d6088a3ab529dcac49b3334d2fd1f7f0eba 100644 (file)
@@ -64,6 +64,7 @@ using battle::Monster;
 using battle::PartyLayout;
 using common::GameConfig;
 using common::GameState;
+using common::Hero;
 using common::Spell;
 using geometry::Vector;
 using graphics::Texture;
@@ -236,34 +237,34 @@ int main(int argc, char **argv) {
                gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
                gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
 
-               gameState.heroes[0].SetWeapon(caster.GetItem("zircoSwordItem"));
-               gameState.heroes[0].SetArmor(caster.GetItem("zirconArmorItem"));
-               gameState.heroes[0].SetShield(caster.GetItem("holyShieldItem"));
-               gameState.heroes[0].SetHelmet(caster.GetItem("legendHelmItem"));
-               gameState.heroes[0].SetRing(caster.GetItem("sProRingItem"));
-               gameState.heroes[0].SetJewel(caster.GetItem("evilJewelItem"));
-
-//             gameState.heroes[1].SetWeapon(cst.GetItem("zircoWhipItem"));
-               gameState.heroes[1].SetArmor(caster.GetItem("zirconPlateItem"));
-               gameState.heroes[1].SetShield(caster.GetItem("zircoGlovesItem"));
-               gameState.heroes[1].SetHelmet(caster.GetItem("holyCapItem"));
-               gameState.heroes[1].SetRing(caster.GetItem("ghostRingItem"));
-               gameState.heroes[1].SetJewel(caster.GetItem("eagleRockItem"));
-
-//             gameState.heroes[2].SetWeapon(cst.GetItem("zircoAxItem"));
-               gameState.heroes[2].SetArmor(caster.GetItem("zirconArmorItem"));
-               gameState.heroes[2].SetShield(caster.GetItem("megaShieldItem"));
-               gameState.heroes[2].SetHelmet(caster.GetItem("zircoHelmetItem"));
-               gameState.heroes[2].SetRing(caster.GetItem("powerRingItem"));
-               gameState.heroes[2].SetJewel(caster.GetItem("evilJewelItem"));
+               gameState.heroes[0].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoSwordItem"));
+               gameState.heroes[0].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
+               gameState.heroes[0].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("holyShieldItem"));
+               gameState.heroes[0].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("legendHelmItem"));
+               gameState.heroes[0].SetEquipment(Hero::EQUIP_RING, caster.GetItem("sProRingItem"));
+               gameState.heroes[0].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
+
+//             gameState.heroes[1].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoWhipItem"));
+               gameState.heroes[1].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconPlateItem"));
+               gameState.heroes[1].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
+               gameState.heroes[1].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
+               gameState.heroes[1].SetEquipment(Hero::EQUIP_RING, caster.GetItem("ghostRingItem"));
+               gameState.heroes[1].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("eagleRockItem"));
+
+//             gameState.heroes[2].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoAxItem"));
+               gameState.heroes[2].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
+               gameState.heroes[2].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("megaShieldItem"));
+               gameState.heroes[2].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("zircoHelmetItem"));
+               gameState.heroes[2].SetEquipment(Hero::EQUIP_RING, caster.GetItem("powerRingItem"));
+               gameState.heroes[2].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
 
                // NOTE: this is actually Artea equipment
-//             gameState.heroes[3].SetWeapon(cst.GetItem("lizardBlowItem"));
-               gameState.heroes[3].SetArmor(caster.GetItem("holyRobeItem"));
-               gameState.heroes[3].SetShield(caster.GetItem("zircoGlovesItem"));
-               gameState.heroes[3].SetHelmet(caster.GetItem("holyCapItem"));
-               gameState.heroes[3].SetRing(caster.GetItem("rocketRingItem"));
-               gameState.heroes[3].SetJewel(caster.GetItem("krakenRockItem"));
+//             gameState.heroes[3].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("lizardBlowItem"));
+               gameState.heroes[3].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("holyRobeItem"));
+               gameState.heroes[3].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
+               gameState.heroes[3].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
+               gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem"));
+               gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem"));
 
                gameState.heroes[0].MapEntity().Position() = Vector<float>(64, 128);
 
index bfc262430023643d5051c97a974103a2b799680f..df924b18a024ade156e66fdc6784c2184665b9df 100644 (file)
@@ -246,119 +246,40 @@ const Hero &EquipMenu::GetHero() const {
 
 void EquipMenu::LoadEquipment() {
        equipmentMenu.Clear();
-       if (GetHero().HasWeapon()) {
-               equipmentMenu.Add(GetHero().Weapon()->Name(), GetHero().Weapon(), true, GetHero().Weapon()->MenuIcon());
-       } else {
-               equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
-       }
-       if (GetHero().HasArmor()) {
-               equipmentMenu.Add(GetHero().Armor()->Name(), GetHero().Armor(), true, GetHero().Armor()->MenuIcon());
-       } else {
-               equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
-       }
-       if (GetHero().HasShield()) {
-               equipmentMenu.Add(GetHero().Shield()->Name(), GetHero().Shield(), true, GetHero().Shield()->MenuIcon());
-       } else {
-               equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
-       }
-       if (GetHero().HasHelmet()) {
-               equipmentMenu.Add(GetHero().Helmet()->Name(), GetHero().Helmet(), true, GetHero().Helmet()->MenuIcon());
-       } else {
-               equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
-       }
-       if (GetHero().HasRing()) {
-               equipmentMenu.Add(GetHero().Ring()->Name(), GetHero().Ring(), true, GetHero().Ring()->MenuIcon());
-       } else {
-               equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
-       }
-       if (GetHero().HasJewel()) {
-               equipmentMenu.Add(GetHero().Jewel()->Name(), GetHero().Jewel(), true, GetHero().Jewel()->MenuIcon());
-       } else {
-               equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
+       for (int i = 0; i < Hero::EQUIP_COUNT; ++i) {
+               if (GetHero().Equipped(Hero::EquipSlot(i))) {
+                       const Item *item(GetHero().Equipment(Hero::EquipSlot(i)));
+                       equipmentMenu.Add(item->Name(), item, true, item->MenuIcon());
+               } else {
+                       equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
+               }
        }
 }
 
 void EquipMenu::RemoveAllEquipment() {
        Inventory &inv(parent->Game().state->inventory);
-       if (GetHero().HasWeapon() && inv.Add(GetHero().Weapon(), 1)) {
-               GetHero().RemoveWeapon();
-       }
-       if (GetHero().HasArmor() && inv.Add(GetHero().Armor(), 1)) {
-               GetHero().RemoveArmor();
-       }
-       if (GetHero().HasShield() && inv.Add(GetHero().Shield(), 1)) {
-               GetHero().RemoveShield();
-       }
-       if (GetHero().HasHelmet() && inv.Add(GetHero().Helmet(), 1)) {
-               GetHero().RemoveHelmet();
-       }
-       if (GetHero().HasRing() && inv.Add(GetHero().Ring(), 1)) {
-               GetHero().RemoveRing();
-       }
-       if (GetHero().HasJewel() && inv.Add(GetHero().Jewel(), 1)) {
-               GetHero().RemoveJewel();
+       for (int i = 0; i < Hero::EQUIP_COUNT; ++i) {
+               if (GetHero().Equipped(Hero::EquipSlot(i))
+                               && inv.Add(GetHero().Equipment(Hero::EquipSlot(i)), 1)) {
+                       GetHero().RemoveEquipment(Hero::EquipSlot(i));
+               }
        }
        LoadEquipment();
 }
 
 void EquipMenu::RemoveItem() {
        Inventory &inv(parent->Game().state->inventory);
-       switch (equipmentMenu.SelectedIndex()) {
-               case 0:
-                       if (GetHero().HasWeapon() && inv.Add(GetHero().Weapon(), 1)) {
-                               GetHero().RemoveWeapon();
-                       }
-                       break;
-               case 1:
-                       if (GetHero().HasArmor() && inv.Add(GetHero().Armor(), 1)) {
-                               GetHero().RemoveArmor();
-                       }
-                       break;
-               case 2:
-                       if (GetHero().HasShield() && inv.Add(GetHero().Shield(), 1)) {
-                               GetHero().RemoveShield();
-                       }
-                       break;
-               case 3:
-                       if (GetHero().HasHelmet() && inv.Add(GetHero().Helmet(), 1)) {
-                               GetHero().RemoveHelmet();
-                       }
-                       break;
-               case 4:
-                       if (GetHero().HasRing() && inv.Add(GetHero().Ring(), 1)) {
-                               GetHero().RemoveRing();
-                       }
-                       break;
-               case 5:
-                       if (GetHero().HasJewel() && inv.Add(GetHero().Jewel(), 1)) {
-                               GetHero().RemoveJewel();
-                       }
-                       break;
+       Hero::EquipSlot slot = Hero::EquipSlot(equipmentMenu.SelectedIndex());
+
+       if (GetHero().Equipped(slot) && inv.Add(GetHero().Equipment(slot), 1)) {
+               GetHero().RemoveEquipment(slot);
        }
+
        LoadEquipment();
 }
 
 void EquipMenu::DropItem() {
-       switch (equipmentMenu.SelectedIndex()) {
-               case 0:
-                       GetHero().RemoveWeapon();
-                       break;
-               case 1:
-                       GetHero().RemoveArmor();
-                       break;
-               case 2:
-                       GetHero().RemoveShield();
-                       break;
-               case 3:
-                       GetHero().RemoveHelmet();
-                       break;
-               case 4:
-                       GetHero().RemoveRing();
-                       break;
-               case 5:
-                       GetHero().RemoveJewel();
-                       break;
-       }
+       GetHero().RemoveEquipment(Hero::EquipSlot(equipmentMenu.SelectedIndex()));
        LoadEquipment();
 }
 
index 3a9b38f3489f58fc0b282c8e9108e948afb8d536..be6774388729afdad4bf3ee6eb1f7e63e29e08c0 100644 (file)
@@ -178,22 +178,10 @@ void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector<int> &offset)
        Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
 
        Vector<int> position(offset);
-       RenderEquipmentLine(hero.Weapon(), screen, position);
-
-       position += lineBreak;
-       RenderEquipmentLine(hero.Armor(), screen, position);
-
-       position += lineBreak;
-       RenderEquipmentLine(hero.Shield(), screen, position);
-
-       position += lineBreak;
-       RenderEquipmentLine(hero.Helmet(), screen, position);
-
-       position += lineBreak;
-       RenderEquipmentLine(hero.Ring(), screen, position);
-
-       position += lineBreak;
-       RenderEquipmentLine(hero.Jewel(), screen, position);
+       for (int i = 0; i < Hero::EQUIP_COUNT; ++i) {
+               RenderEquipmentLine(hero.Equipment(Hero::EquipSlot(i)), screen, position);
+               position += lineBreak;
+       }
 }
 
 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {