#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"
using battle::Monster;
using battle::PartyLayout;
using battle::Stats;
+using common::Ikari;
+using common::Item;
using common::Spell;
using common::TargetingMode;
using graphics::Animation;
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;
}
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;
}
}
}
+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()) {
}
}
+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));
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();
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());
}
}
+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") {
}
namespace common {
+ class Ikari;
+ class Item;
class Spell;
class TargetingMode;
}
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);
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; }
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 &);
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 &);
FRAME,
GAUGE,
HERO,
+ IKARI,
IMAGE,
+ ITEM,
MONSTER,
NUMBER,
PARTY_LAYOUT,
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;