diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index e959ab1..9419eb3 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -228,6 +228,7 @@ Game::Game() : StateObject() doScreenTrans = false; noSceneTransitionFadeout = false; fullTilesetReload = false; + highestLoadedEntityID = 0; } Game::~Game() @@ -943,7 +944,7 @@ EntitySaveData *Game::getEntitySaveDataForEntity(Entity *e) int Game::findUnusedEntityID(bool temporary) const { const int inc = temporary ? -1 : 1; - int id = 0; + int id = temporary ? 0 : highestLoadedEntityID + 1; // never touch entity IDs that were in use in the map xml retry: id += inc; FOR_ENTITIES(i) @@ -1845,9 +1846,11 @@ bool Game::loadSceneXML(std::string scene) void Game::spawnEntities(const EntitySaveData *sav, size_t n) { std::vector conflicting, usable; + int highest = 0; for(size_t i = 0; i < n; ++i) { const EntitySaveData& es = sav[i]; + highest = std::max(es.id, highest); // check for ID conflicts int id = es.id; @@ -1870,6 +1873,8 @@ void Game::spawnEntities(const EntitySaveData *sav, size_t n) conflicting.push_back(i); } + highestLoadedEntityID = highest; + { std::ostringstream os; os << "Game::spawnEntities: Spawning " << usable.size() << " entities"; @@ -1888,7 +1893,7 @@ void Game::spawnEntities(const EntitySaveData *sav, size_t n) } // spawn and renumber the rest - int lastid = 0; + int lastid = highest; for(size_t i = 0; i < conflicting.size(); ++i) { // find an unused ID diff --git a/Aquaria/Game.h b/Aquaria/Game.h index 729ba1b..5cb2298 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -422,6 +422,7 @@ public: void onContinuityReset(); protected: + unsigned highestLoadedEntityID; void toggleHelpScreen(bool on, const std::string &label=""); void onToggleHelpScreen();