- added an invlaid value check to the units field

This commit is contained in:
Mark Vejvoda 2010-12-12 00:46:13 +00:00
parent 1984c61386
commit 8918b11320
2 changed files with 9 additions and 5 deletions

View File

@ -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);

View File

@ -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;