- code cleanup

This commit is contained in:
Mark Vejvoda 2010-12-19 03:30:17 +00:00
parent 3e83cb54f7
commit 1c51b6c21d

View File

@ -156,7 +156,6 @@ Vec2i Map::getStartLocation(int locationIndex) const {
}
void Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
struct MapFileHeader{
int32 version;
int32 maxPlayers;
@ -399,7 +398,6 @@ bool Map::isFreeCellOrHasUnit(const Vec2i &pos, Field field, const Unit *unit) c
}
bool Map::isAproxFreeCell(const Vec2i &pos, Field field, int teamIndex) const {
if(isInside(pos)) {
const SurfaceCell *sc= getSurfaceCell(toSurfCoords(pos));
@ -422,7 +420,6 @@ bool Map::isFreeCells(const Vec2i & pos, int size, Field field) const {
Vec2i testPos(i,j);
if(isFreeCell(testPos, field) == false) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] isFreeCell will return false, testPos = %s, field = %d, getCell(testPos)->isFree(field) = %d, getSurfaceCell(toSurfCoords(testPos))->isFree() = %d, getDeepSubmerged(getCell(testPos)) = %d\n",__FILE__,__FUNCTION__,__LINE__,testPos.getString().c_str(),field,getCell(testPos)->isFree(field),getSurfaceCell(toSurfCoords(testPos))->isFree(),getDeepSubmerged(getCell(testPos)));
return false;
}
}
@ -433,7 +430,7 @@ bool Map::isFreeCells(const Vec2i & pos, int size, Field field) const {
bool Map::isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Unit *unit) const {
for(int i=pos.x; i<pos.x+size; ++i) {
for(int j=pos.y; j<pos.y+size; ++j) {
if(!isFreeCellOrHasUnit(Vec2i(i,j), field, unit)){
if(isFreeCellOrHasUnit(Vec2i(i,j), field, unit) == false) {
return false;
}
}
@ -444,7 +441,7 @@ bool Map::isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Un
bool Map::isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamIndex) const {
for(int i=pos.x; i<pos.x+size; ++i) {
for(int j=pos.y; j<pos.y+size; ++j) {
if(!isAproxFreeCell(Vec2i(i, j), field, teamIndex)){
if(isAproxFreeCell(Vec2i(i, j), field, teamIndex) == false) {
return false;
}
}
@ -457,14 +454,15 @@ bool Map::canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalD
for (int y=0; y < ut->getSize(); ++y) {
for (int x=0; x < ut->getSize(); ++x) {
if (ut->getCellMapCell(x, y, facing)) {
if (!isFreeCell(pos + Vec2i(x, y), field)) {
if (isFreeCell(pos + Vec2i(x, y), field) == false) {
return false;
}
}
}
}
return true;
} else {
}
else {
return isFreeCells(pos, ut->getSize(), field);
}
}
@ -811,7 +809,6 @@ bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,
//put a units into the cells
void Map::putUnitCells(Unit *unit, const Vec2i &pos) {
assert(unit != NULL);
if(unit == NULL) {
throw runtime_error("ut == NULL");
@ -829,24 +826,25 @@ void Map::putUnitCells(Unit *unit, const Vec2i &pos) {
}
if( ut->hasCellMap() == false || ut->getCellMapCell(i, j, unit->getModelFacing())) {
// NOT SURE UNDER WHAT CONDITIONS THIS COULD HAPPEN?
//assert(getCell(currPos)->getUnit(unit->getCurrField()) == NULL || getCell(currPos)->getUnit(unit->getCurrField()) == unit);
if(getCell(currPos)->getUnit(unit->getCurrField()) != NULL &&
getCell(currPos)->getUnit(unit->getCurrField()) != unit) {
// If unit tries to move into a cell where another unit resides
// cancel the move command
if(unit->getCurrSkill() != NULL &&
unit->getCurrSkill()->getClass() == scMove) {
canPutInCell = false;
unit->setCurrSkill(scStop);
unit->finishCommand();
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] POSSIBLE 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] POSSIBLE 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());
}
// If the unit trying to move into the cell is not in the moving state
// it is likely being created or morphed so we will will log the error
else {
canPutInCell = false;
// throw runtime_error("getCell(currPos)->getUnit(unit->getCurrField()) != NULL");
@ -868,7 +866,10 @@ void Map::putUnitCells(Unit *unit, const Vec2i &pos) {
ut->hasEmptyCellMap() == true) {
getCell(currPos)->setUnitWithEmptyCellMap(unit->getCurrField(), unit);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currPos = %s unit = %s\n",__FILE__,__FUNCTION__,__LINE__,currPos.getString().c_str(),unit->toString().c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currPos = %s unit = %s\n",
__FILE__,__FUNCTION__,__LINE__,
currPos.getString().c_str(),
unit->toString().c_str());
}
}
}
@ -917,7 +918,10 @@ void Map::clearUnitCells(Unit *unit, const Vec2i &pos) {
ut->hasEmptyCellMap() == true) {
getCell(currPos)->setUnitWithEmptyCellMap(unit->getCurrField(), NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currPos = %s unit = %s\n",__FILE__,__FUNCTION__,__LINE__,currPos.getString().c_str(),unit->toString().c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currPos = %s unit = %s\n",
__FILE__,__FUNCTION__,__LINE__,
currPos.getString().c_str(),
unit->toString().c_str());
}
}
}