removing attack order once the target unit is destroyed

This commit is contained in:
devZoGok
2023-11-05 17:08:29 +02:00
parent 464abc1c00
commit d996ffff3d
5 changed files with 34 additions and 14 deletions
+18
View File
@@ -248,6 +248,24 @@ namespace battleship{
}
}
void Unit::attack(Order order){
if(orders[0].targets[0].unit){
bool unitFound = false;
for(Player *pl : Game::getSingleton()->getPlayers()){
vector<Unit*> units = pl->getUnits();
if(find(units.begin(), units.end(), orders[0].targets[0].unit) != units.end()){
unitFound = true;
break;
}
}
if(!unitFound)
removeOrder(0);
}
}
void Unit::setOrder(Order order) {
while (!orders.empty())
removeOrder(0);