From 5795ffa948c6e39a624c4fc7773a99afb87579e1 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 27 Nov 2012 12:28:27 +0100 Subject: [PATCH] made HeroGroup data-only --- src/common/Hero.cpp | 15 ++++++++++ src/common/Hero.h | 5 ++++ src/common/HeroGroup.h | 64 ----------------------------------------- src/common/Item.cpp | 2 ++ src/common/Item.h | 6 ++-- src/common/Spell.cpp | 10 +++++-- src/common/Spell.h | 6 ++-- src/common/fwd.h | 1 - test-data/constants.l2h | 10 +++++++ test-data/constants.l2s | 10 +++++++ test-data/items.l2s | 60 +++++++++++++++++++++++++------------- test-data/test.l2s | 4 +++ 12 files changed, 98 insertions(+), 95 deletions(-) delete mode 100644 src/common/HeroGroup.h diff --git a/src/common/Hero.cpp b/src/common/Hero.cpp index 8222e12..ab73a6b 100644 --- a/src/common/Hero.cpp +++ b/src/common/Hero.cpp @@ -7,6 +7,8 @@ #include "Hero.h" +#include "Item.h" +#include "Spell.h" #include "../graphics/Animation.h" #include "../graphics/Sprite.h" #include "../loader/Interpreter.h" @@ -36,6 +38,8 @@ Hero::Hero() , levelLadder(0) , numLevels(0) +, useMask(0) + , weapon(0) , armor(0) , shield(0) @@ -76,6 +80,15 @@ int Hero::NextLevel() const { } +bool Hero::CanEquip(const Item &item) const { + return useMask & item.HeroMask(); +} + +bool Hero::CanInvoke(const Spell &spell) const { + return useMask & spell.HeroMask(); +} + + void Hero::CreateTypeDescription() { Hero h; @@ -96,6 +109,8 @@ void Hero::CreateTypeDescription() { td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID)); td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetReferenced().SetAggregate()); + td.AddField("useMask", FieldDescription(((char *)&h.useMask) - ((char *)&h), Interpreter::NUMBER_ID)); + td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for battle scenes")); td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for physical attacks")); td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for magical attacks")); diff --git a/src/common/Hero.h b/src/common/Hero.h index 70d21f2..dcbc782 100644 --- a/src/common/Hero.h +++ b/src/common/Hero.h @@ -50,6 +50,9 @@ public: int Experience() const { return experience; } int NextLevel() const; + bool CanEquip(const Item &) const; + bool CanInvoke(const Spell &) const; + Item *Weapon() { return weapon; } Item *Armor() { return armor; } Item *Shield() { return shield; } @@ -119,6 +122,8 @@ private: int *levelLadder; int numLevels; + int useMask; + Item *weapon; Item *armor; Item *shield; diff --git a/src/common/HeroGroup.h b/src/common/HeroGroup.h deleted file mode 100644 index ef6fd25..0000000 --- a/src/common/HeroGroup.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * HeroGroup.h - * - * Created on: Aug 10, 2012 - * Author: holy - */ - -#ifndef COMMON_HEROGROUP_H_ -#define COMMON_HEROGROUP_H_ - -#include - -namespace common { - -class HeroGroup { - -public: - HeroGroup() : members(NOBODY) { } - -public: - bool HasMaxim() const { return members & MAXIM; } - bool HasSelan() const { return members & SELAN; } - bool HasGuy() const { return members & GUY; } - bool HasArtea() const { return members & ARTEA; } - bool HasTia() const { return members & TIA; } - bool HasDekar() const { return members & DEKAR; } - bool HasLexis() const { return members & LEXIS; } - - void AddMaxim() { members |= MAXIM; } - void AddSelan() { members |= SELAN; } - void AddGuy() { members |= GUY; } - void AddArtea() { members |= ARTEA; } - void AddTia() { members |= TIA; } - void AddDekar() { members |= DEKAR; } - void AddLexis() { members |= LEXIS; } - void AddAll() { members = (MAXIM | SELAN | GUY | ARTEA | TIA | DEKAR | LEXIS); } - - void RemoveMaxim() { members &= ~MAXIM; } - void RemoveSelan() { members &= ~SELAN; } - void RemoveGuy() { members &= ~GUY; } - void RemoveArtea() { members &= ~ARTEA; } - void RemoveTia() { members &= ~TIA; } - void RemoveDekar() { members &= ~DEKAR; } - void RemoveLexis() { members &= ~LEXIS; } - void RemoveAll() { members = NOBODY; } - -public: - enum { - NOBODY = 0, - MAXIM = 1, - SELAN = 2, - GUY = 4, - ARTEA = 8, - TIA = 16, - DEKAR = 32, - LEXIS = 64, - }; - Uint8 members; - -}; - -} - -#endif /* COMMON_HEROGROUP_H_ */ diff --git a/src/common/Item.cpp b/src/common/Item.cpp index 259c4b5..955f48c 100644 --- a/src/common/Item.cpp +++ b/src/common/Item.cpp @@ -33,6 +33,7 @@ Item::Item() , properties(0) , equipability(0) +, heroMask(0) , mostUseful(false) , cursed(false) @@ -66,6 +67,7 @@ void Item::CreateTypeDescription() { td.AddField("ikari", FieldDescription(((char *)&i.ikari) - ((char *)&i), Ikari::TYPE_ID).SetReferenced().SetDescription("ikari attack of the item (sensible only for equipment)")); td.AddField("attackanimation", FieldDescription(((char *)&i.attackAnimation) - ((char *)&i), Animation::TYPE_ID).SetReferenced().SetDescription("animation that is run when the item is used for attacking")); td.AddField("equipability", FieldDescription(((char *)&i.equipability) - ((char *)&i), Interpreter::NUMBER_ID).SetDescription("how this item can be equipped")); + td.AddField("heroMask", FieldDescription(((char *)&i.heroMask) - ((char *)&i), Interpreter::NUMBER_ID).SetDescription("which heroes may equip this item")); } void Item::Construct(void *data) { diff --git a/src/common/Item.h b/src/common/Item.h index 7e757ff..bd8e7a9 100644 --- a/src/common/Item.h +++ b/src/common/Item.h @@ -9,7 +9,6 @@ #define COMMON_ITEM_H_ #include "fwd.h" -#include "HeroGroup.h" #include "TargetingMode.h" #include "../graphics/fwd.h" @@ -61,8 +60,7 @@ public: bool CanEquipRing() const { return equipability & EQUIPPABLE_RING; } bool CanEquipJewel() const { return equipability & EQUIPPABLE_JEWEL; } - HeroGroup &EquipableBy() { return equipableBy; } - const HeroGroup &EquipableBy() const { return equipableBy; } + int HeroMask() const { return heroMask; } bool HasEffectOnStatusScreen() const { return properties & PROPERTY_HAS_EFFECT_STATUS; } bool HasEffectInBattle() const { return properties & PROPERTY_HAS_EFFECT_BATTLE; } @@ -132,7 +130,7 @@ private: TargetingMode targettingMode; int equipability; - HeroGroup equipableBy; + int heroMask; // TODO: turn these back into bits as soon as fields are implemented in the loader bool mostUseful; diff --git a/src/common/Spell.cpp b/src/common/Spell.cpp index 33979ca..1b4142b 100644 --- a/src/common/Spell.cpp +++ b/src/common/Spell.cpp @@ -18,7 +18,12 @@ using loader::TypeDescription; namespace common { Spell::Spell() -: name(""), value(0), cost(0), status(false), battle(false) { +: name("") +, value(0) +, cost(0) +, heroMask(0) +, status(false) +, battle(false) { } @@ -38,8 +43,9 @@ void Spell::CreateTypeDescription() { td.SetSize(sizeof(Spell)); td.AddField("name", FieldDescription(((char *)&s.name) - ((char *)&s), Interpreter::STRING_ID).SetReferenced().SetDescription("the spell's name")); - td.AddField("cost", FieldDescription(((char *)&s.cost) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("Amount of magic points needed and deducted for invocation")); + td.AddField("cost", FieldDescription(((char *)&s.cost) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("amount of magic points needed and deducted for invocation")); td.AddField("targets", FieldDescription(((char *)&s.targetingMode) - ((char *)&s), TargetingMode::TYPE_ID).SetDescription("how target selection is to be performed")); + td.AddField("heroMask", FieldDescription(((char *)&s.heroMask) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("which heroes can invoke this spell")); td.AddField("status", FieldDescription(((char *)&s.status) - ((char *)&s), Interpreter::BOOLEAN_ID).SetDescription("if the spell can be used at the status screen")); td.AddField("battle", FieldDescription(((char *)&s.battle) - ((char *)&s), Interpreter::BOOLEAN_ID).SetDescription("if the spell can be used in battle")); } diff --git a/src/common/Spell.h b/src/common/Spell.h index e9befa9..f300197 100644 --- a/src/common/Spell.h +++ b/src/common/Spell.h @@ -8,7 +8,6 @@ #ifndef COMMON_SPELL_H_ #define COMMON_SPELL_H_ -#include "HeroGroup.h" #include "TargetingMode.h" namespace common { @@ -32,8 +31,7 @@ public: TargetingMode &GetTargetingMode() { return targetingMode; } const TargetingMode &GetTargetingMode() const { return targetingMode; } - HeroGroup &UsableBy() { return usableBy; } - const HeroGroup &UsableBy() const { return usableBy; } + int HeroMask() const { return heroMask; } static bool Less(const Spell *, const Spell *); @@ -53,7 +51,7 @@ private: int cost; TargetingMode targetingMode; - HeroGroup usableBy; + int heroMask; bool status; bool battle; diff --git a/src/common/fwd.h b/src/common/fwd.h index 1cd0671..3dc6438 100644 --- a/src/common/fwd.h +++ b/src/common/fwd.h @@ -13,7 +13,6 @@ namespace common { struct GameConfig; struct GameState; class Hero; -class HeroGroup; class Ikari; class Inventory; class Item; diff --git a/test-data/constants.l2h b/test-data/constants.l2h index d761fb8..fea7abf 100644 --- a/test-data/constants.l2h +++ b/test-data/constants.l2h @@ -6,6 +6,16 @@ Number all Number single Number multiple +// Hero masks +Number maskMaxim +Number maskSelan +Number maskGuy +Number maskArtea +Number maskDekar +Number maskTia +Number maskLexis +Number maskAll + // Ikari Boolean magical Boolean physical diff --git a/test-data/constants.l2s b/test-data/constants.l2s index 11d5db5..47dcb9a 100644 --- a/test-data/constants.l2s +++ b/test-data/constants.l2s @@ -6,6 +6,16 @@ export Number all 0 export Number multiple 1 export Number single 2 +// Hero masks +export Number maskMaxim 1 +export Number maskSelan 2 +export Number maskGuy 4 +export Number maskArtea 8 +export Number maskDekar 16 +export Number maskTia 32 +export Number maskLexis 64 +export Number maskAll 127 + // Ikari export Boolean magical false export Boolean physical true diff --git a/test-data/items.l2s b/test-data/items.l2s index d80b542..231aa3f 100644 --- a/test-data/items.l2s +++ b/test-data/items.l2s @@ -85,7 +85,8 @@ export Item eagleRockItem { name: "Eagle rock", menuicon: jewelIcon, ikari: diveIkari, - equipability: jewel + equipability: jewel, + heroMask: maskAll } export Item escapeItem { name: "Escape", @@ -96,13 +97,15 @@ export Item evilJewelItem { name: "Evil jewel", menuicon: jewelIcon, ikari: gloomyIkari, - equipability: jewel + equipability: jewel, + heroMask: maskAll } export Item ghostRingItem { name: "Ghost ring", menuicon: ringIcon, ikari: destroyIkari, - equipability: ring + equipability: ring, + heroMask: maskAll } export Item hiPotionItem { name: "Hi-Potion", @@ -118,31 +121,36 @@ export Item holyCapItem { name: "Holy cap", menuicon: helmetIcon, ikari: vulnerableIkari, - equipability: helmet + equipability: helmet, + heroMask: 42 // Selan, Artea, Tia } export Item holyRobeItem { name: "Holy robe", menuicon: armorIcon, ikari: crisisCureIkari, - equipability: armor + equipability: armor, + heroMask: 42 // Selan, Artea, Tia } export Item holyShieldItem { name: "Holy shield", menuicon: shieldIcon, ikari: lightGuardIkari, - equipability: shield + equipability: shield, + heroMask: 21 // Maxim, Guy, Dekar } export Item krakenRockItem { name: "Kraken rock", menuicon: jewelIcon, ikari: tenLeggerIkari, - equipability: jewel + equipability: jewel, + heroMask: maskAll } export Item legendHelmItem { name: "Legend helm", menuicon: helmetIcon, ikari: boomerangIkari, - equipability: helmet + equipability: helmet, + heroMask: 21 // Maxim, Guy, Dekar } export Item lizardBlowItem { name: "Lizard blow", @@ -152,7 +160,8 @@ export Item lizardBlowItem { faction: enemy, mode: single }, - equipability: weapon + equipability: weapon, + heroMask: maskAll } export Item magicJarItem { name: "Magic jar", @@ -168,7 +177,8 @@ export Item megaShieldItem { name: "Mega shield", menuicon: shieldIcon, ikari: ironBarrierIkari, - equipability: shield + equipability: shield, + heroMask: 20 // Guy, Dekar } export Item powerPotionItem { name: "Power potion", @@ -180,13 +190,15 @@ export Item powerRingItem { name: "Power ring", menuicon: ringIcon, ikari: trickIkari, - equipability: ring + equipability: ring, + heroMask: maskAll } export Item rocketRingItem { name: "Rocket ring", menuicon: ringIcon, ikari: fakeIkari, - equipability: ring + equipability: ring, + heroMask: maskAll } export Item sleepBallItem { name: "Sleep ball", @@ -202,7 +214,8 @@ export Item sProRingItem { name: "S-pro ring", menuicon: ringIcon, ikari: courageIkari, - equipability: ring + equipability: ring, + heroMask: maskAll } export Item zircoAxItem { name: "Zirco ax", @@ -212,32 +225,37 @@ export Item zircoAxItem { faction: enemy, mode: single }, - equipability: weapon + equipability: weapon, + heroMask: 20 // Guy, Dekar } export Item zircoGlovesItem { name: "Zirco gloves", menuicon: shieldIcon, ikari: forcefieldIkari, - equipability: shield + equipability: shield, + heroMask: 106 // Selan, Artea, Tia, Lexis } export Item zircoHelmetItem { name: "Zirco helmet", menuicon: helmetIcon, ikari: slowIkari, - equipability: helmet + equipability: helmet, + heroMask: 21 // Maxim, Guy, Dekar } export Item zirconArmorItem { name: "Zircon armor", menuicon: armorIcon, battle: false, ikari: magicCureIkari, - equipability: armor + equipability: armor, + heroMask: 21 // Maxim, Guy, Dekar } export Item zirconPlateItem { name: "Zircon plate", menuicon: armorIcon, ikari: suddenCureIkari, - equipability: armor + equipability: armor, + heroMask: 74 // Selan, Artea, Lexis } export Item zircoSwordItem { name: "Zirco sword", @@ -249,7 +267,8 @@ export Item zircoSwordItem { }, ikari: firestormIkari, attackanimation: swordAttackAnimation, - equipability: weapon + equipability: weapon, + heroMask: maskMaxim } export Item zircoWhipItem { name: "Zirco whip", @@ -259,5 +278,6 @@ export Item zircoWhipItem { mode: single }, ikari: thundershriekIkari, - equipability: weapon + equipability: weapon, + heroMask: 34 // Selan, Tia } diff --git a/test-data/test.l2s b/test-data/test.l2s index 1267b9f..5f4fe2c 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -91,6 +91,7 @@ export Hero maxim { ladder: [ 10 ], + useMask: maskMaxim, attackAnimation: ComplexAnimation { sprite: maximSprite, frametime: frameTime, @@ -180,6 +181,7 @@ export Hero selan { gut: 80, mgr: 13 }, + useMask: maskSelan, attackAnimation: ComplexAnimation { sprite: selanSprite, frametime: frameTime, @@ -263,6 +265,7 @@ export Hero guy { gut: 90, mgr: 8 }, + useMask: maskGuy, attackAnimation: ComplexAnimation { sprite: guySprite, frametime: frameTime, @@ -328,6 +331,7 @@ export Hero dekar { gut: 100, mgr: 5 }, + useMask: maskDekar, attackAnimation: ComplexAnimation { sprite: dekarSprite, frametime: frameTime, -- 2.39.2