From 62254685d5508e22484cded1c1dc057657d027ab Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 17 Mar 2012 20:59:03 +0000 Subject: [PATCH] - fixed saved / load game to restore terrain --- source/glest_game/world/map.cpp | 16 ++++++++++++++-- source/glest_game/world/map.h | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index c435b2d6..9efa55ea 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -188,6 +188,13 @@ void SurfaceCell::deleteResource() { object= NULL; } +void SurfaceCell::setHeight(float height, bool cellChangedFromOriginalMapLoadValue) { + vertex.y= height; + if(cellChangedFromOriginalMapLoadValue == true) { + this->cellChangedFromOriginalMapLoad = true; + } +} + bool SurfaceCell::decAmount(int value) { cellChangedFromOriginalMapLoad = true; @@ -220,7 +227,7 @@ void SurfaceCell::saveGame(XmlNode *rootNode,int index) const { // //geometry // Vec3f vertex; - //surfaceCellNode->addAttribute("vertex",vertex.getString(), mapTagReplacements); + surfaceCellNode->addAttribute("vertex",vertex.getString(), mapTagReplacements); // Vec3f normal; //surfaceCellNode->addAttribute("normal",normal.getString(), mapTagReplacements); // Vec3f color; @@ -272,6 +279,11 @@ void SurfaceCell::saveGame(XmlNode *rootNode,int index) const { void SurfaceCell::loadGame(const XmlNode *rootNode, int index, World *world) { if(rootNode->hasChild("SurfaceCell" + intToStr(index)) == true) { const XmlNode *surfaceCellNode = rootNode->getChild("SurfaceCell" + intToStr(index)); + + if(surfaceCellNode->hasAttribute("vertex") == true) { + vertex = Vec3f::strToVec3(surfaceCellNode->getAttribute("vertex")->getValue()); + } + //int visibleCount = cellNode->getChildCount(); XmlNode *objectNode = surfaceCellNode->getChild("Object"); if(objectNode->hasAttribute("isDeleted") == true) { @@ -1641,7 +1653,7 @@ void Map::flatternTerrain(const Unit *unit){ SurfaceCell *sc= getSurfaceCell(toSurfCoords(pos)); //we change height if pos is inside world, if its free or ocupied by the currenty building if(sc->getObject() == NULL && (c->getUnit(fLand)==NULL || c->getUnit(fLand)==unit)) { - sc->setHeight(refHeight); + sc->setHeight(refHeight,true); } } } diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index 8eb912e1..8985a799 100644 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -130,7 +130,7 @@ public: //set void setVertex(const Vec3f &vertex) {this->vertex= vertex;} - void setHeight(float height) {vertex.y= height;} + void setHeight(float height, bool cellChangedFromOriginalMapLoadValue=false); void setNormal(const Vec3f &normal) {this->normal= normal;} void setColor(const Vec3f &color) {this->color= color;} void setSurfaceType(int surfaceType) {this->surfaceType= surfaceType;}