diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index aff61b3f28f..4c66e96285c 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -58,16 +58,24 @@ void Spare::store(Sprite *spr) { _container.insert_at(_container.size(), spr); } -void Spare::dispose(Sprite *spr) { - warning("STUB: Spare::Dispose()"); +void Spare::update(Sprite *spr) { + Sprite *sp = locate(spr->_ref); + if (sp == nullptr) + store(spr); +} +void Spare::dispose(Sprite *spr) { if (spr) { _vm->_vga->_showQ->remove(spr); - - for (int i = 0; i < _container.size(); i++) { - if (spr == _container[i]) { - _container.remove_at(i); + update(spr->contract()); + if (spr->_ref / 10 != 14) { // IIRC if it's == 14, it's the sprite of a Hero. No idea yet why it shouldn't be deleted then. + for (int i = 0; i < _container.size(); i++) { + if (spr == _container[i]) { + _container.remove_at(i); + } } + + delete spr; } } } diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 54683b9c65b..6e8f8c59877 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -41,6 +41,7 @@ public: void store(Sprite *spr); Sprite *locate(int ref); void takeCave(int ref); // Note that it takes the ref of the sprite now, not the number of the scene, like the original! + void update(Sprite *spr); void dispose(Sprite *spr); void dispose(int ref); void dispose();