for (vector<Animation *>::const_iterator i(animations.begin()), end(animations.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<Sprite *>::const_iterator i(sprites.begin()), end(sprites.end()); i != end; ++i) {
+ delete *i;
+ }
}
map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
if (i != parsedDefinitions.end()) {
if (i->second.IsCompatible(HERO)) {
- return &heroes[i->second.index];
+ return heroes[i->second.index];
} else {
throw Error("cannot cast " + i->second.dfn->TypeName() + " to Hero");
}
map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
if (i != parsedDefinitions.end()) {
if (i->second.IsCompatible(MONSTER)) {
- return &monsters[i->second.index];
+ return monsters[i->second.index];
} else {
throw Error("cannot cast " + i->second.dfn->TypeName() + " to Monster");
}
map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
if (i != parsedDefinitions.end()) {
if (i->second.IsCompatible(SPRITE)) {
- return &sprites[i->second.index];
+ return sprites[i->second.index];
} else {
throw Error("cannot cast " + i->second.dfn->TypeName() + " to Sprite");
}
void Interpreter::ReadObject(const Definition &dfn) {
if (dfn.TypeName() == "Hero") {
- heroes.push_back(Hero());
- ReadHero(heroes.back(), *dfn.GetProperties());
- parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, HERO, heroes.size() - 1)));
+ Hero *hero(new Hero);
+ int index(heroes.size());
+ heroes.push_back(hero);
+ ReadHero(*hero, *dfn.GetProperties());
+ parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, HERO, index)));
} else if (dfn.TypeName() == "Monster") {
- monsters.push_back(Monster());
- ReadMonster(monsters.back(), *dfn.GetProperties());
- parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, MONSTER, monsters.size() - 1)));
+ Monster *monster(new Monster);
+ int index(monsters.size());
+ monsters.push_back(monster);
+ ReadMonster(*monster, *dfn.GetProperties());
+ parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, MONSTER, index)));
} else if (dfn.TypeName() == "Sprite") {
+ Sprite *sprite(new Sprite);
int index(sprites.size());
- sprites.push_back(Sprite());
- ReadSprite(sprites.back(), *dfn.GetProperties());
+ sprites.push_back(sprite);
+ ReadSprite(*sprite, *dfn.GetProperties());
parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPRITE, index)));
} else {
throw Error("unhandled object type: " + dfn.TypeName());