Skip to content

Commit

Permalink
fix(mechanics): Improve handling of orders when the selected escort i…
Browse files Browse the repository at this point in the history
…s destroyed (endless-sky#10459)

- After a player ship has finished exploding, it is no longer considered "selected" and so will no longer block orders to the wider fleet.
- If orders are issued while all selected ships are exploding, a new message indicating that they cannot follow orders will be used, instead of the normal message indicating that orders have been issued.
  • Loading branch information
TomGoodIdea authored Sep 14, 2024
1 parent f44f6a0 commit 36c4e56
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
25 changes: 21 additions & 4 deletions source/AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4832,25 +4832,42 @@ void AI::IssueOrders(const Orders &newOrders, const string &description)

// Figure out what ships we are giving orders to.
vector<const Ship *> ships;
size_t destroyedCount = 0;
if(player.SelectedShips().empty())
{
for(const shared_ptr<Ship> &it : player.Ships())
if(it.get() != player.Flagship() && !it->IsParked())
ships.push_back(it.get());
who = ships.size() > 1 ? "Your fleet is " : "Your escort is ";
{
if(it->IsDestroyed())
++destroyedCount;
else
ships.push_back(it.get());
}
who = (ships.empty() ? destroyedCount : ships.size()) > 1
? "Your fleet is " : "Your escort is ";
}
else
{
for(const weak_ptr<Ship> &it : player.SelectedShips())
{
shared_ptr<Ship> ship = it.lock();
if(ship)
if(!ship)
continue;
if(ship->IsDestroyed())
++destroyedCount;
else
ships.push_back(ship.get());
}
who = ships.size() > 1 ? "The selected escorts are " : "The selected escort is ";
who = (ships.empty() ? destroyedCount : ships.size()) > 1
? "The selected escorts are " : "The selected escort is ";
}
if(ships.empty())
{
if(destroyedCount)
Messages::Add(who + "destroyed and unable to execute your orders.",
Messages::Importance::High);
return;
}

Point centerOfGravity;
bool isMoveOrder = (newOrders.HasMoveTo());
Expand Down
3 changes: 3 additions & 0 deletions source/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,9 @@ void Engine::MoveShip(const shared_ptr<Ship> &ship)
for(const auto &bay : ship->Bays())
if(bay.ship)
eventQueue.emplace_back(nullptr, bay.ship, ShipEvent::DESTROY);
// If this is a player ship, make sure it's no longer selected.
if(ship->IsYours())
player.DeselectShip(ship.get());
}
return;
}
Expand Down
12 changes: 12 additions & 0 deletions source/PlayerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2777,6 +2777,18 @@ void PlayerInfo::SelectShip(const Ship *ship, bool hasShift)



void PlayerInfo::DeselectShip(const Ship *ship)
{
for(auto it = selectedShips.begin(); it != selectedShips.end(); ++it)
if(it->lock().get() == ship)
{
selectedShips.erase(it);
return;
}
}



void PlayerInfo::SelectGroup(int group, bool hasShift)
{
int bit = (1 << group);
Expand Down
1 change: 1 addition & 0 deletions source/PlayerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class PlayerInfo {
bool SelectShips(const Rectangle &box, bool hasShift);
bool SelectShips(const std::vector<const Ship *> &stack, bool hasShift);
void SelectShip(const Ship *ship, bool hasShift);
void DeselectShip(const Ship *ship);
void SelectGroup(int group, bool hasShift);
void SetGroup(int group, const std::set<Ship *> *newShips = nullptr);
std::set<Ship *> GetGroup(int group);
Expand Down

0 comments on commit 36c4e56

Please sign in to comment.