mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
bugfix for crashing when referencing destroyed units
This commit is contained in:
@@ -275,21 +275,20 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Unit::attack(Order order){
|
||||
if(orders[0].targets[0].unit){
|
||||
bool unitFound = false;
|
||||
vector<Unit*> units;
|
||||
|
||||
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);
|
||||
for(Player *pl : Game::getSingleton()->getPlayers()){
|
||||
vector<Unit*> un = pl->getUnits();
|
||||
units.insert(units.end(), un.begin(), un.end());
|
||||
}
|
||||
|
||||
for(Order::Target &target : orders[0].targets)
|
||||
if(target.unit){
|
||||
if(find(units.begin(), units.end(), target.unit) != units.end())
|
||||
break;
|
||||
|
||||
removeOrder(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::setOrder(Order order) {
|
||||
|
||||
@@ -271,7 +271,11 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Vehicle::attack(Order order){
|
||||
int prevNumOrders = orders.size();
|
||||
Unit::attack(order);
|
||||
int currNumOrders = orders.size();
|
||||
|
||||
if(prevNumOrders != currNumOrders) return;
|
||||
|
||||
Order::Target target = order.targets[0];
|
||||
Vector3 targVec = (target.unit ? target.unit->getPos() : target.pos) - pos;
|
||||
|
||||
Reference in New Issue
Block a user