Commit 7ded83be authored by Gerhard Stein's avatar Gerhard Stein

improved Save/Load Game algorithm a bit more (more stable now)

parent 22c92dda
......@@ -301,7 +301,9 @@ void CMapLoaderGalaxy::spawnFoes(CMap &Map)
{
for(size_t x=0 ; x<width ; x++)
{
addFoe(Map, *data_ptr++, x<<CSF, y<<CSF);
CGalaxySpriteObject *pNewfoe = addFoe(Map, *data_ptr++, x<<CSF, y<<CSF);
if(pNewfoe)
m_ObjectPtr.push_back(pNewfoe);
}
}
......@@ -360,7 +362,7 @@ const unsigned int DIVE_SUIT = 35;
/**
* @brief Loads a foe given by the coordiantes
*/
void CMapLoaderGalaxy::addFoe(CMap &Map, word foe, size_t x, size_t y)
CGalaxySpriteObject* CMapLoaderGalaxy::addFoe(CMap &Map, word foe, size_t x, size_t y)
{
CGalaxySpriteObject *p_newfoe = NULL;
VectorD2<Uint32> Location(x,y);
......@@ -509,8 +511,8 @@ void CMapLoaderGalaxy::addFoe(CMap &Map, word foe, size_t x, size_t y)
break;
}
if(p_newfoe)
m_ObjectPtr.push_back(p_newfoe);
return p_newfoe;
}
}
......@@ -33,7 +33,7 @@ public:
bool gotoSignature(std::ifstream &MapFile);
bool loadMap(CMap &Map, Uint8 level);
void spawnFoes(CMap &Map);
void addFoe(CMap &Map, word foe, size_t x, size_t y);
CGalaxySpriteObject* addFoe(CMap &Map, word foe, size_t x, size_t y);
private:
void unpackPlaneData(std::ifstream &MapFile,
......
......@@ -240,31 +240,32 @@ bool CMapPlayGalaxy::operator<<(CSaveGameController &savedGame)
savedGame.decodeData(x);
savedGame.decodeData(y);
MapLoader.addFoe(mMap, foeID, x, y);
CGalaxySpriteObject &obj = *(mObjectPtr.back().get());
savedGame.decodeData( obj.dead );
savedGame.decodeData( obj.onscreen );
savedGame.decodeData( obj.hasbeenonscreen );
savedGame.decodeData( obj.exists );
savedGame.decodeData( obj.blockedd );
savedGame.decodeData( obj.blockedu );
savedGame.decodeData( obj.blockedl );
savedGame.decodeData( obj.blockedr );
savedGame.decodeData( obj.mHealthPoints );
savedGame.decodeData( obj.canbezapped );
savedGame.decodeData( obj.cansupportplayer );
savedGame.decodeData( obj.inhibitfall );
savedGame.decodeData( obj.honorPriority );
savedGame.decodeData( obj.sprite );
CGalaxySpriteObject *pNewfoe = MapLoader.addFoe(mMap, foeID, x, y);
// TODO: Be careful here is a bad Null Pointer inside that structure
if(pNewfoe == NULL)
pNewfoe = new CGalaxySpriteObject(&mMap, foeID, x, y);
savedGame.decodeData( pNewfoe->dead );
savedGame.decodeData( pNewfoe->onscreen );
savedGame.decodeData( pNewfoe->hasbeenonscreen );
savedGame.decodeData( pNewfoe->exists );
savedGame.decodeData( pNewfoe->blockedd );
savedGame.decodeData( pNewfoe->blockedu );
savedGame.decodeData( pNewfoe->blockedl );
savedGame.decodeData( pNewfoe->blockedr );
savedGame.decodeData( pNewfoe->mHealthPoints );
savedGame.decodeData( pNewfoe->canbezapped );
savedGame.decodeData( pNewfoe->cansupportplayer );
savedGame.decodeData( pNewfoe->inhibitfall );
savedGame.decodeData( pNewfoe->honorPriority );
savedGame.decodeData( pNewfoe->sprite );
savedGame.decodeData( actionNumber );
obj.setActionForce(actionNumber);
// remove non existing objects, we don't need them
if(!obj.exists)
mObjectPtr.pop_back();
pNewfoe->setActionForce(actionNumber);
if(pNewfoe->exists)
mObjectPtr.push_back(pNewfoe);
}
// Save the map_data as it is left
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment