attack enemy units even if you missed them and only hit the map cell.

This commit is contained in:
Titus Tscharntke 2013-04-29 23:05:56 +00:00
parent 45a1fcdf4e
commit db921c3fb7
2 changed files with 25 additions and 4 deletions

View File

@ -7535,13 +7535,11 @@ vector<Unit *> 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;
}

View File

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