From: Daniel Karbach Date: Sat, 1 Sep 2012 13:55:26 +0000 (+0200) Subject: added interpretation of Ikari and Item X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=b5056c2d3079c0143ed2c8f52cb5b2290a642aa7;p=l2e.git added interpretation of Ikari and Item --- diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 4416f9b..7c26aaa 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -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::const_iterator i(complexAnimations.begin()), end(complexAnimations.end()); i != end; ++i) { delete *i; } - for (vector::const_iterator i(heroes.begin()), end(heroes.end()); i != end; ++i) { - delete *i; - } for (vector::const_iterator i(fonts.begin()), end(fonts.end()); i != end; ++i) { delete *i; } @@ -62,9 +63,18 @@ Interpreter::~Interpreter() { for (vector::const_iterator i(gauges.begin()), end(gauges.end()); i != end; ++i) { delete *i; } + for (vector::const_iterator i(heroes.begin()), end(heroes.end()); i != end; ++i) { + delete *i; + } + for (vector::const_iterator i(ikaris.begin()), end(ikaris.end()); i != end; ++i) { + delete *i; + } for (vector::const_iterator i(images.begin()), end(images.end()); i != end; ++i) { SDL_FreeSurface(*i); } + for (vector::const_iterator i(items.begin()), end(items.end()); i != end; ++i) { + delete *i; + } for (vector::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::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::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::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") { diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 93a6e36..ffbad42 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -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 &Frames() const { return frames; } const std::vector &Gauges() const { return gauges; } const std::vector &Heroes() const { return heroes; } + const std::vector &Ikaris() const { return ikaris; } const std::vector &Images() const { return images; } + const std::vector &Items() const { return items; } const std::vector &Monsters() const { return monsters; } const std::vector &Numbers() const { return numbers; } const std::vector &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 frames; std::vector gauges; std::vector heroes; + std::vector ikaris; std::vector images; + std::vector items; std::vector monsters; std::vector numbers; std::vector partyLayouts;