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; }
#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 {
, 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));
}
~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; }
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; }
// 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:
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;
#define COMMON_ITEM_H_
#include "fwd.h"
+#include "Hero.h"
#include "TargetingMode.h"
#include "../graphics/fwd.h"
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,
using battle::PartyLayout;
using common::GameConfig;
using common::GameState;
+using common::Hero;
using common::Spell;
using geometry::Vector;
using graphics::Texture;
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);
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();
}
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 {