]> git.localhorst.tv Git - l2e.git/commitdiff
added interpretation of Ikari and Item
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 1 Sep 2012 13:55:26 +0000 (15:55 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 1 Sep 2012 13:55:26 +0000 (15:55 +0200)
src/loader/Interpreter.cpp
src/loader/Interpreter.h

index 4416f9b267ccd91ea922b48b883d88e08f978af6..7c26aaafded4ae6ad86929521e1bc5ebc9fe3e26 100644 (file)
@@ -11,6 +11,8 @@
 #include "../battle/Hero.h"
 #include "../battle/Monster.h"
 #include "../battle/PartyLayout.h"
+#include "../common/Ikari.h"
+#include "../common/Item.h"
 #include "../common/Spell.h"
 #include "../common/TargetingMode.h"
 #include "../graphics/ComplexAnimation.h"
@@ -28,6 +30,8 @@ using battle::Hero;
 using battle::Monster;
 using battle::PartyLayout;
 using battle::Stats;
+using common::Ikari;
+using common::Item;
 using common::Spell;
 using common::TargetingMode;
 using graphics::Animation;
@@ -50,9 +54,6 @@ Interpreter::~Interpreter() {
        for (vector<ComplexAnimation *>::const_iterator i(complexAnimations.begin()), end(complexAnimations.end()); i != end; ++i) {
                delete *i;
        }
-       for (vector<Hero *>::const_iterator i(heroes.begin()), end(heroes.end()); i != end; ++i) {
-               delete *i;
-       }
        for (vector<Font *>::const_iterator i(fonts.begin()), end(fonts.end()); i != end; ++i) {
                delete *i;
        }
@@ -62,9 +63,18 @@ Interpreter::~Interpreter() {
        for (vector<Gauge *>::const_iterator i(gauges.begin()), end(gauges.end()); i != end; ++i) {
                delete *i;
        }
+       for (vector<Hero *>::const_iterator i(heroes.begin()), end(heroes.end()); i != end; ++i) {
+               delete *i;
+       }
+       for (vector<Ikari *>::const_iterator i(ikaris.begin()), end(ikaris.end()); i != end; ++i) {
+               delete *i;
+       }
        for (vector<SDL_Surface *>::const_iterator i(images.begin()), end(images.end()); i != end; ++i) {
                SDL_FreeSurface(*i);
        }
+       for (vector<Item *>::const_iterator i(items.begin()), end(items.end()); i != end; ++i) {
+               delete *i;
+       }
        for (vector<Monster *>::const_iterator i(monsters.begin()), end(monsters.end()); i != end; ++i) {
                delete *i;
        }
@@ -169,6 +179,32 @@ Hero *Interpreter::GetHero(const std::string &name) {
        }
 }
 
+Ikari *Interpreter::GetIkari(const std::string &name) {
+       map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+       if (i != parsedDefinitions.end()) {
+               if (i->second.type == IKARI) {
+                       return ikaris[i->second.index];
+               } else {
+                       throw Error("cannot cast " + i->second.dfn->TypeName() + " to Ikari");
+               }
+       } else {
+               throw Error("access to undefined Ikari " + name);
+       }
+}
+
+Item *Interpreter::GetItem(const std::string &name) {
+       map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+       if (i != parsedDefinitions.end()) {
+               if (i->second.type == ITEM) {
+                       return items[i->second.index];
+               } else {
+                       throw Error("cannot cast " + i->second.dfn->TypeName() + " to Item");
+               }
+       } else {
+               throw Error("access to undefined Item " + name);
+       }
+}
+
 Monster *Interpreter::GetMonster(const std::string &name) {
        map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
        if (i != parsedDefinitions.end()) {
@@ -392,6 +428,28 @@ Gauge *Interpreter::GetGauge(const Value &v) {
        }
 }
 
+Hero *Interpreter::GetHero(const Value &v) {
+       if (v.IsLiteral()) {
+               Hero *h(new Hero);
+               ReadHero(*h, *v.GetLiteral().GetProperties());
+               return h;
+       } else {
+               ReadDefinition(source.GetDefinition(v.GetIdentifier()));
+               return GetHero(v.GetIdentifier());
+       }
+}
+
+Ikari *Interpreter::GetIkari(const Value &v) {
+       if (v.IsLiteral()) {
+               Ikari *i(new Ikari);
+               ReadIkari(*i, *v.GetLiteral().GetProperties());
+               return i;
+       } else {
+               ReadDefinition(source.GetDefinition(v.GetIdentifier()));
+               return GetIkari(v.GetIdentifier());
+       }
+}
+
 SDL_Surface *Interpreter::GetImage(const Value &v) {
        const char *file(GetString(v));
        SDL_Surface *image(IMG_Load(file));
@@ -399,6 +457,17 @@ SDL_Surface *Interpreter::GetImage(const Value &v) {
        return image;
 }
 
+Item *Interpreter::GetItem(const Value &v) {
+       if (v.IsLiteral()) {
+               Item *i(new Item);
+               ReadItem(*i, *v.GetLiteral().GetProperties());
+               return i;
+       } else {
+               ReadDefinition(source.GetDefinition(v.GetIdentifier()));
+               return GetItem(v.GetIdentifier());
+       }
+}
+
 int Interpreter::GetNumber(const Value &v) {
        if (v.IsLiteral()) {
                return v.GetLiteral().GetNumber();
@@ -526,6 +595,18 @@ void Interpreter::ReadObject(const Definition &dfn) {
                heroes.push_back(hero);
                ReadHero(*hero, *dfn.GetProperties());
                parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, HERO, index)));
+       } else if (dfn.TypeName() == "Ikari") {
+               Ikari *ikari(new Ikari);
+               int index(ikaris.size());
+               ikaris.push_back(ikari);
+               ReadIkari(*ikari, *dfn.GetProperties());
+               parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, IKARI, index)));
+       } else if (dfn.TypeName() == "Item") {
+               Item *item(new Item);
+               int index(items.size());
+               items.push_back(item);
+               ReadItem(*item, *dfn.GetProperties());
+               parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, ITEM, index)));
        } else if (dfn.TypeName() == "Monster") {
                Monster *monster(new Monster);
                int index(monsters.size());
@@ -655,6 +736,50 @@ void Interpreter::ReadGauge(Gauge &g, const PropertyList &props) {
        }
 }
 
+void Interpreter::ReadIkari(Ikari &ikari, const PropertyList &props) {
+       for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
+               if (i->first == "name") {
+                       ikari.SetName(GetString(*i->second));
+               } else if (i->first == "cost") {
+                       ikari.SetCost(GetNumber(*i->second));
+               } else if (i->first == "targets") {
+                       ikari.GetTargetingMode() = *GetTargetingMode(*i->second);
+               } else if (i->first == "magical") {
+                       if (GetBoolean(*i->second)) {
+                               ikari.SetMagical();
+                       }
+               } else if (i->first == "physical") {
+                       if (GetBoolean(*i->second)) {
+                               ikari.SetPhysical();
+                       }
+               } else {
+                       throw Error("unknown Ikari property: " + i->first);
+               }
+       }
+}
+
+void Interpreter::ReadItem(Item &item, const PropertyList &props) {
+       for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
+               if (i->first == "name") {
+                       item.SetName(GetString(*i->second));
+               } else if (i->first == "menuicon") {
+                       item.SetMenuIcon(GetSprite(*i->second));
+               } else if (i->first == "battle") {
+                       if (GetBoolean(*i->second)) {
+                               item.SetUsableInBattle();
+                       }
+               } else if (i->first == "targets") {
+                       item.GetTargetingMode() = *GetTargetingMode(*i->second);
+               } else if (i->first == "ikari") {
+                       item.SetIkari(GetIkari(*i->second));
+               } else if (i->first == "attackanimation") {
+                       item.SetAttackAnimation(GetAnimation(*i->second));
+               } else {
+                       throw Error("unknown Item property: " + i->first);
+               }
+       }
+}
+
 void Interpreter::ReadHero(Hero &h, const PropertyList &props) {
        for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
                if (i->first == "name") {
index 93a6e36227b576cc95744a80b4eb9522885e8a10..ffbad42e1a6ef1e2897305c55a04ad3090e38832 100644 (file)
@@ -25,6 +25,8 @@ namespace battle {
 }
 
 namespace common {
+       class Ikari;
+       class Item;
        class Spell;
        class TargetingMode;
 }
@@ -70,6 +72,8 @@ public:
        graphics::Frame *GetFrame(const std::string &name);
        graphics::Gauge *GetGauge(const std::string &name);
        battle::Hero *GetHero(const std::string &name);
+       common::Ikari *GetIkari(const std::string &name);
+       common::Item *GetItem(const std::string &name);
        battle::Monster *GetMonster(const std::string &name);
        int GetNumber(const std::string &name) const;
        battle::PartyLayout *GetPartyLayout(const std::string &name);
@@ -86,7 +90,9 @@ public:
        const std::vector<graphics::Frame *> &Frames() const { return frames; }
        const std::vector<graphics::Gauge *> &Gauges() const { return gauges; }
        const std::vector<battle::Hero *> &Heroes() const { return heroes; }
+       const std::vector<common::Ikari *> &Ikaris() const { return ikaris; }
        const std::vector<SDL_Surface *> &Images() const { return images; }
+       const std::vector<common::Item *> &Items() const { return items; }
        const std::vector<battle::Monster *> &Monsters() const { return monsters; }
        const std::vector<int> &Numbers() const { return numbers; }
        const std::vector<battle::PartyLayout *> &PartyLayouts() const { return partyLayouts; }
@@ -107,7 +113,10 @@ private:
        graphics::Font *GetFont(const Value &);
        graphics::Frame *GetFrame(const Value &);
        graphics::Gauge *GetGauge(const Value &);
+       battle::Hero *GetHero(const Value &);
+       common::Ikari *GetIkari(const Value &);
        SDL_Surface *GetImage(const Value &);
+       common::Item *GetItem(const Value &);
        int GetNumber(const Value &);
        battle::PartyLayout *GetPartyLayout(const Value &);
        const PropertyList *GetPropertyList(const Value &);
@@ -125,6 +134,8 @@ private:
        void ReadFrame(graphics::Frame &, const PropertyList &);
        void ReadGauge(graphics::Gauge &, const PropertyList &);
        void ReadHero(battle::Hero &, const PropertyList &);
+       void ReadIkari(common::Ikari &, const PropertyList &);
+       void ReadItem(common::Item &, const PropertyList &);
        void ReadMonster(battle::Monster &, const PropertyList &);
        void ReadPartyLayout(battle::PartyLayout &, const PropertyList &);
        void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &);
@@ -142,7 +153,9 @@ private:
                FRAME,
                GAUGE,
                HERO,
+               IKARI,
                IMAGE,
+               ITEM,
                MONSTER,
                NUMBER,
                PARTY_LAYOUT,
@@ -170,7 +183,9 @@ private:
        std::vector<graphics::Frame *> frames;
        std::vector<graphics::Gauge *> gauges;
        std::vector<battle::Hero *> heroes;
+       std::vector<common::Ikari *> ikaris;
        std::vector<SDL_Surface *> images;
+       std::vector<common::Item *> items;
        std::vector<battle::Monster *> monsters;
        std::vector<int> numbers;
        std::vector<battle::PartyLayout *> partyLayouts;