From 4481151c5b3611362e082e4db157a0b0071cd272 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 13 Mar 2012 23:51:39 +0000 Subject: [PATCH] - check if unit is dead when loading game and do NOT set cell map for dead unit --- source/glest_game/type_instances/faction.cpp | 19 +++++++++++++++++++ source/glest_game/type_instances/unit.cpp | 12 ++++++++---- source/glest_game/world/unit_updater.cpp | 3 +++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index a91c541e..973b9a43 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -1922,6 +1922,25 @@ void Faction::loadGame(const XmlNode *rootNode, int factionIndex,GameSettings *s } upgradeManager.loadGame(factionNode,this); + + // ControlType control; + control = static_cast(factionNode->getAttribute("control")->getIntValue()); + // Texture2D *texture; + // FactionType *factionType; + //factionNode->addAttribute("factiontype",factionType->getName(), mapTagReplacements); + // int index; + //factionNode->addAttribute("index",intToStr(index), mapTagReplacements); + // int teamIndex; + //factionNode->addAttribute("teamIndex",intToStr(teamIndex), mapTagReplacements); + teamIndex = factionNode->getAttribute("teamIndex")->getIntValue(); + // int startLocationIndex; + startLocationIndex = factionNode->getAttribute("startLocationIndex")->getIntValue(); + // bool thisFaction; + thisFaction = factionNode->getAttribute("thisFaction")->getIntValue(); + // bool factionDisconnectHandled; + + // RandomGen random; + random.setLastNumber(factionNode->getAttribute("random")->getIntValue()); } } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 6fc5356d..69292a91 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -3661,7 +3661,9 @@ void Unit::saveGame(XmlNode *rootNode) { // std::vector currentAttackBoostEffects; for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { UnitAttackBoostEffect *uabe= currentAttackBoostEffects[i]; - uabe->saveGame(unitNode); + if(uabe != NULL) { + uabe->saveGame(unitNode); + } } // Mutex *mutexCommands; @@ -3707,9 +3709,6 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * //Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing); Unit *result = new Unit(newUnitId, newpath, newUnitPos, ut, faction, world->getMapPtr(), newModelFacing); - world->getMapPtr()->putUnitCells(result, newUnitPos); - //result->born(); - result->lastRotation = unitNode->getAttribute("lastRotation")->getFloatValue(); result->targetRotation = unitNode->getAttribute("targetRotation")->getFloatValue(); result->rotation = unitNode->getAttribute("rotation")->getFloatValue(); @@ -3964,6 +3963,11 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // CauseOfDeathType causeOfDeath; result->causeOfDeath = static_cast(unitNode->getAttribute("causeOfDeath")->getIntValue()); + if(result->alive) { + world->getMapPtr()->putUnitCells(result, newUnitPos); + //result->born(); + } + return result; } diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 1c11750a..0ad1fe09 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -2028,6 +2028,9 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac if(ast == NULL) { throw runtime_error("ast == NULL"); } + if(attacked == NULL) { + throw runtime_error("attacked == NULL"); + } //get vars float damage = ast->getTotalAttackStrength(attacker->getTotalUpgrade());