+Interpreter::~Interpreter() {
+ for (vector<battle::Resources *>::const_iterator i(battleResources.begin()), end(battleResources.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<ComplexAnimation *>::const_iterator i(complexAnimations.begin()), end(complexAnimations.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<Font *>::const_iterator i(fonts.begin()), end(fonts.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<Frame *>::const_iterator i(frames.begin()), end(frames.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<graphics::MenuProperties *>::const_iterator i(menuProperties.begin()), end(menuProperties.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<Monster *>::const_iterator i(monsters.begin()), end(monsters.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<PartyLayout *>::const_iterator i(partyLayouts.begin()), end(partyLayouts.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<SimpleAnimation *>::const_iterator i(simpleAnimations.begin()), end(simpleAnimations.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<Spell *>::const_iterator i(spells.begin()), end(spells.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<Sprite *>::const_iterator i(sprites.begin()), end(sprites.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<const char *>::const_iterator i(strings.begin()), end(strings.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<TargetingMode *>::const_iterator i(targetingModes.begin()), end(targetingModes.end()); i != end; ++i) {
+ delete *i;
+ }
+}
+
+
+Animation *Interpreter::GetAnimation(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == COMPLEX_ANIMATION) {
+ return complexAnimations[i->second.index];
+ } else if (i->second.type == SIMPLE_ANIMATION) {
+ return simpleAnimations[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Animation");
+ }
+ } else {
+ throw Error("access to undefined Animation " + name);
+ }
+}
+
+battle::Resources *Interpreter::GetBattleResources(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == BATTLE_RESOURCES) {
+ return battleResources[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to BattleResources");
+ }
+ } else {
+ throw Error("access to undefined BattleResources " + name);
+ }
+}
+
+bool Interpreter::GetBoolean(const std::string &name) const {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == BOOLEAN) {
+ return booleans[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Boolean");
+ }
+ } else {
+ throw Error("access to undefined Boolean " + name);
+ }
+}
+
+const Color &Interpreter::GetColor(const std::string &name) const {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == COLOR) {
+ return colors[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Color");
+ }
+ } else {
+ throw Error("access to undefined Color " + name);
+ }
+}
+
+Font *Interpreter::GetFont(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == FONT) {
+ return fonts[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Font");
+ }
+ } else {
+ throw Error("access to undefined Font " + name);
+ }
+}
+
+Frame *Interpreter::GetFrame(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == FRAME) {
+ return frames[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Frame");
+ }
+ } else {
+ throw Error("access to undefined Frame " + name);
+ }
+}
+
+Gauge *Interpreter::GetGauge(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == GAUGE) {
+ return gauges[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Gauge");
+ }
+ } else {
+ throw Error("access to undefined Gauge " + name);
+ }
+}
+
+Hero *Interpreter::GetHero(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == HERO) {
+ return heroes[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Hero");
+ }
+ } else {
+ throw Error("access to undefined Hero " + 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);
+ }
+}
+
+graphics::MenuProperties *Interpreter::GetMenuProperties(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == MENU_PROPERTIES) {
+ return menuProperties[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to MenuProperties");
+ }
+ } else {
+ throw Error("access to undefined MenuProperties " + name);
+ }
+}
+
+Monster *Interpreter::GetMonster(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == MONSTER) {
+ return monsters[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Monster");
+ }
+ } else {
+ throw Error("access to undefined Monster " + name);
+ }
+}
+
+int Interpreter::GetNumber(const std::string &name) const {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == NUMBER) {
+ return numbers[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Number");
+ }
+ } else {
+ throw Error("access to undefined Number " + name);
+ }
+}
+
+PartyLayout *Interpreter::GetPartyLayout(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == PARTY_LAYOUT) {
+ return partyLayouts[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to PartyLayout");
+ }
+ } else {
+ throw Error("access to undefined PartyLayout " + name);
+ }
+}
+
+const char *Interpreter::GetPath(const std::string &name) const {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == PATH) {
+ return strings[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Path");
+ }
+ } else {
+ throw Error("access to undefined Path " + name);
+ }
+}
+
+Spell *Interpreter::GetSpell(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == SPELL) {
+ return spells[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Spell");
+ }
+ } else {
+ throw Error("access to undefined Spell " + name);
+ }
+}
+
+Sprite *Interpreter::GetSprite(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == SPRITE) {
+ return sprites[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Sprite");
+ }
+ } else {
+ throw Error("access to undefined Sprite " + name);
+ }
+}
+
+const char *Interpreter::GetString(const std::string &name) const {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ // TODO: enable path to string casting some time
+ if (i->second.type == STRING /* || i->second.type == PATH */) {
+ return strings[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to String");
+ }
+ } else {
+ throw Error("access to undefined String " + name);
+ }
+}
+
+TargetingMode *Interpreter::GetTargetingMode(const std::string &name) {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == TARGETING_MODE) {
+ return targetingModes[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to TargetingMode");
+ }
+ } else {
+ throw Error("access to undefined TargetingMode " + name);
+ }
+}
+
+Vector<int> Interpreter::GetVector(const std::string &name) const {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == VECTOR) {
+ return vectors[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Vector");
+ }
+ } else {
+ throw Error("access to undefined Vector " + name);
+ }
+}
+
+