effect delete restored

This commit is contained in:
Henrique 2011-08-17 02:04:45 -03:00
parent 16a187b014
commit 8b2bceaef3
5 changed files with 61 additions and 1 deletions

View File

@ -17,7 +17,7 @@ void Effect::draw(int x, int y)
if(g_platform.getTicks() - m_lastTicks > 75) {
const ThingAttributes& attributes = getAttributes();
if(m_animation+1 == attributes.animcount) {
//g_dispatcher.addEvent(std::bind(&Map::removeThing, &g_map, asThing()));
g_dispatcher.addEvent(std::bind(&Map::removeThingByPtr, &g_map, asThing()));
m_finished = true;
}
else

View File

@ -56,6 +56,9 @@ void Map::draw(int x, int y)
void Map::addThing(ThingPtr thing, uint8 stackpos)
{
if(!thing)
return;
TilePtr& tile = m_tiles[thing->getPosition()];
if(!tile) {
tile = TilePtr(new Tile());
@ -82,6 +85,16 @@ void Map::removeThing(const Position& pos, uint8 stackpos)
}
}
void Map::removeThingByPtr(ThingPtr thing)
{
if(!thing)
return;
if(TilePtr& tile = m_tiles[thing->getPosition()]) {
tile->removeThingByPtr(thing);
}
}
void Map::clean()
{
m_tiles.clear();

View File

@ -13,6 +13,7 @@ public:
void addThing(ThingPtr thing, uint8 stackpos = 0);
ThingPtr getThing(const Position& pos, uint8 stackpos);
void removeThing(const Position& pos, uint8 stackpos);
void removeThingByPtr(ThingPtr thing);
void clean();
void cleanTile(const Position& pos);

View File

@ -99,6 +99,51 @@ void Tile::removeThing(uint8 stackpos)
logDebug("Invalid stackpos.");
}
void Tile::removeThingByPtr(ThingPtr thing)
{
// Items
if(thing->asItem()) {
const ThingAttributes& thingAttributes = thing->getAttributes();
if(!thingAttributes.alwaysOnTop) {
for(auto it = m_itemsBottom.begin(), end = m_itemsBottom.end(); it != end; ++it) {
if(*it == thing) {
m_itemsBottom.erase(it);
break;
}
}
}
else {
for(auto it = m_itemsTop.begin(), end = m_itemsTop.end(); it != end; ++it) {
if(*it == thing) {
m_itemsTop.erase(it);
break;
}
}
}
}
// Creatures
else if(thing->asCreature()) {
for(auto it = m_creatures.begin(), end = m_creatures.end(); it != end; ++it) {
if(*it == thing) {
m_creatures.erase(it);
break;
}
}
}
// Effects
else if(thing->asEffect()) {
for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it) {
if(*it == thing) {
m_effects.erase(it);
break;
}
}
}
}
void Tile::clean()
{
for(const ThingPtr& thing : m_creatures)

View File

@ -14,6 +14,7 @@ public:
void addThing(ThingPtr thing, uint8 stackpos);
ThingPtr getThing(uint8 stackpos);
void removeThing(uint8 stackpos);
void removeThingByPtr(ThingPtr thing);
void clean();