From db921c3fb7f7da4db52a0109c678dcac1d5c56e0 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Mon, 29 Apr 2013 23:05:56 +0000 Subject: [PATCH] attack enemy units even if you missed them and only hit the map cell. --- source/glest_game/graphics/renderer.cpp | 6 ++---- source/glest_game/gui/gui.cpp | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index c525f3da..c073a669 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -7535,13 +7535,11 @@ vector Renderer::renderUnitsFast(bool renderingShadows, bool colorPickin visibleUnitIndex < qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) { Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; - if(renderOnlyBuildings==true && unit->getType()->hasCommandClass(ccMove)) - { + if(renderOnlyBuildings==true && unit->getType()->hasSkillClass(scMove)){ continue; } - if(renderOnlyBuildings==false && !unit->getType()->hasCommandClass(ccMove)) - { + if(renderOnlyBuildings==false && !unit->getType()->hasSkillClass(scMove)){ continue; } diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index fccee4be..bf47a4b4 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -1217,6 +1217,29 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t validPosObjWorld= true; posObjWorld= targetPos; + // lets check for enemy units on this cell we might not have correctly hit with our click + // if we find an enemy unit on the cell we use it as target. + if(world->getMap()->getCell(targetPos)->getUnit(fLand) != NULL) { + Unit* unitOnCell=world->getMap()->getCell(targetPos)->getUnit(fLand); + Faction *unitFaction= unitOnCell->getFaction(); + const Faction *myFaction=world->getThisFaction(); + bool cannotSeeUnit = (unitOnCell->getType()->hasCellMap() == true && + unitOnCell->getType()->getAllowEmptyCellMap() == true && + unitOnCell->getType()->hasEmptyCellMap() == true); + + if(cannotSeeUnit == false && unitFaction->isAlly( myFaction)==false){ + bool visible=world->getMap()->getSurfaceCell(Map::toSurfCoords(targetPos))->isVisible(world->getThisTeamIndex()); + if(visible){ + // we found an enemy unit! this is our target. + targetUnit= unitOnCell; + targetPos= targetUnit->getPosNotThreadSafe(); + highlightedUnitId=targetUnit->getId(); + getHighlightedUnit()->resetHighlight(); + return true; + } + } + } + if(world->getMap()->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource() != NULL) { highlightedResourceObjectPos=Map::toSurfCoords(targetPos);