From 8918b11320d40e04e451a7d3c4e82b0890695eb3 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 12 Dec 2010 00:46:13 +0000 Subject: [PATCH] - added an invlaid value check to the units field --- source/glest_game/world/map.cpp | 6 +++++- source/glest_game/world/map.h | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 74977c74..672e1884 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -833,7 +833,11 @@ void Map::putUnitCells(Unit *unit, const Vec2i &pos) { assert(getCell(currPos)->getUnit(unit->getCurrField()) == NULL); if(getCell(currPos)->getUnit(unit->getCurrField()) != NULL) { // throw runtime_error("getCell(currPos)->getUnit(unit->getCurrField()) != NULL"); - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR [getCell(currPos)->getUnit(unit->getCurrField()) != NULL] currPos [%s] unit [%s] cell unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,currPos.getString().c_str(),unit->toString().c_str(),getCell(currPos)->getUnit(unit->getCurrField())->toString().c_str()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR [getCell(currPos)->getUnit(unit->getCurrField()) != NULL] currPos [%s] unit [%s] cell unit [%s]\n", + __FILE__,__FUNCTION__,__LINE__, + currPos.getString().c_str(), + unit->toString().c_str(), + getCell(currPos)->getUnit(unit->getCurrField())->toString().c_str()); } getCell(currPos)->setUnit(unit->getCurrField(), unit); diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index 77215e85..a7c97909 100755 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -59,12 +59,12 @@ public: Cell(); //get - Unit *getUnit(int field) const {return units[field];} - Unit *getUnitWithEmptyCellMap(int field) const {return unitsWithEmptyCellMap[field];} + Unit *getUnit(int field) const { if(field >= fieldCount) { throw runtime_error("Invalid field value" + intToStr(field));} return units[field];} + Unit *getUnitWithEmptyCellMap(int field) const { if(field >= fieldCount) { throw runtime_error("Invalid field value" + intToStr(field));} return unitsWithEmptyCellMap[field];} float getHeight() const {return height;} - void setUnit(int field, Unit *unit) {units[field]= unit;} - void setUnitWithEmptyCellMap(int field, Unit *unit) {unitsWithEmptyCellMap[field]= unit;} + void setUnit(int field, Unit *unit) { if(field >= fieldCount) { throw runtime_error("Invalid field value" + intToStr(field));} units[field]= unit;} + void setUnitWithEmptyCellMap(int field, Unit *unit) { if(field >= fieldCount) { throw runtime_error("Invalid field value" + intToStr(field));} unitsWithEmptyCellMap[field]= unit;} void setHeight(float height) {this->height= height;} bool isFree(Field field) const;