+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<SDL_Surface *>::const_iterator i(images.begin()), end(images.end()); i != end; ++i) {
+ SDL_FreeSurface(*i);
+ }
+ for (vector<Monster *>::const_iterator i(monsters.begin()), end(monsters.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<SimpleAnimation *>::const_iterator i(simpleAnimations.begin()), end(simpleAnimations.end()); i != end; ++i) {
+ delete *i;
+ }
+ for (vector<Sprite *>::const_iterator i(sprites.begin()), end(sprites.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);
+ }
+}
+
+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);
+ }
+}
+
+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);
+ }
+}
+
+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);
+ }
+}
+
+