When giving default orders we must respect cellmap of target unit

We need to respect cellmaps by searching for a cell which is really occupied.
This fixes an issue that new workers do not start with autorepair. It happens
 typically with round building were top left cell map is empty. Now order is given
to a place which is really occupied by the unit(building) to repair.
This commit is contained in:
titiger 2016-11-11 01:34:28 +01:00
parent d65dc5e9e9
commit 7b47f5edb1
1 changed files with 13 additions and 0 deletions

View File

@ -1185,6 +1185,19 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
if(uc.empty() == false){
targetUnit= getRelevantObjectFromSelection(&uc);
targetPos= targetUnit->getPosNotThreadSafe();
// we need to respect cellmaps. Searching for a cell which is really occupied
int size=targetUnit->getType()->getSize();
bool foundUnit=false;
for ( int x= 0;x<size;++x){
for ( int y= 0;y<size;++y){
if(world->getMap()->getCell(Vec2i(targetPos.x+x,targetPos.y+y))->getUnit(targetUnit->getType()->getField())==targetUnit){
targetPos=Vec2i(targetPos.x+x,targetPos.y+y);
foundUnit=true;
break;
}
}
if(foundUnit) break;
}
highlightedUnitId=targetUnit->getId();
getHighlightedUnit()->resetHighlight();
return true;