From 77fb1b6d15c459f7ef62f4b05a75c247d8b2474d Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 22 Feb 2011 23:59:21 +0000 Subject: [PATCH] - bugfix for building units at edges of maps --- source/glest_game/graphics/renderer.cpp | 3 +-- source/glest_game/world/map.cpp | 26 ++++++++++++++---------- source/glest_game/world/unit_updater.cpp | 4 +--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index a9c8ef71..7798427e 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -803,8 +803,7 @@ void Renderer::renderMouse3d() { glTranslatef(pos3f.x+offset, pos3f.y, pos3f.z+offset); //choose color - //if(map->isFreeCells(pos, building->getSize(), fLand)){ - if(map->isFreeCells(pos + Vec2i(building->getSize()/2, building->getSize()/2), building->getSize(), fLand)){ + if(map->isFreeCells(pos, building->getSize(), fLand)){ color= Vec4f(1.f, 1.f, 1.f, 0.5f); } else { diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index fcce5fa4..f32813f1 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -147,9 +147,8 @@ int Map::getCellArraySize() const { Cell *Map::getCell(int x, int y) const { int arrayIndex = y * w + x; if(arrayIndex >= getCellArraySize()) { - - abort(); - //throw runtime_error("arrayIndex >= getCellArraySize(), arrayIndex = " + intToStr(arrayIndex) + " w = " + intToStr(w) + " h = " + intToStr(h)); + //abort(); + throw runtime_error("arrayIndex >= getCellArraySize(), arrayIndex = " + intToStr(arrayIndex) + " w = " + intToStr(w) + " h = " + intToStr(h)); } else if(cells == NULL) { throw runtime_error("cells == NULL"); @@ -437,10 +436,13 @@ bool Map::isFreeCells(const Vec2i & pos, int size, Field field) const { for(int i=pos.x; iisFree(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; + + printf("Could not build at [%s] isInside(testPos) = %d isInsideSurface(toSurfCoords(testPos)) = %d isFreeCell(testPos, field) = %d\n",testPos.getString().c_str(),isInside(testPos),isInsideSurface(toSurfCoords(testPos)),isFreeCell(testPos, field)); + return false; } } } @@ -1044,11 +1046,13 @@ void Map::flatternTerrain(const Unit *unit){ for(int i=-1; i<=unit->getType()->getSize(); ++i){ for(int j=-1; j<=unit->getType()->getSize(); ++j){ Vec2i pos= unit->getPos()+Vec2i(i, j); - Cell *c= getCell(pos); - SurfaceCell *sc= getSurfaceCell(toSurfCoords(pos)); - //we change height if pos is inside world, if its free or ocupied by the currenty building - if(isInside(pos) && sc->getObject()==NULL && (c->getUnit(fLand)==NULL || c->getUnit(fLand)==unit)){ - sc->setHeight(refHeight); + if(isInside(pos) && isInsideSurface(toSurfCoords(pos))) { + Cell *c= getCell(pos); + 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); + } } } } diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 3f683b63..5775381e 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -574,9 +574,7 @@ void UnitUpdater::updateBuild(Unit *unit) { switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] tsArrived about to call map->isFreeCells() for command->getPos() = %s, ut->getSize() = %d\n",__FILE__,__FUNCTION__,__LINE__,command->getPos().getString().c_str(),ut->getSize()); - //canOccupyCell = map->isFreeCells(command->getPos(), ut->getSize(), fLand); - //!!!return pos + Vec2i(type->getSize()/2, type->getSize()/2); - canOccupyCell = map->isFreeCells(command->getPos() + Vec2i(ut->getSize()/2, ut->getSize()/2), ut->getSize(), fLand); + canOccupyCell = map->isFreeCells(command->getPos(), ut->getSize(), fLand); break; case pfRoutePlanner: canOccupyCell = map->canOccupy(command->getPos(), ut->getField(), ut, command->getFacing());