| 1706 | } |
| 1707 | |
| 1708 | StateRef<Building> Vehicle::getServiceDestination(GameState &state) |
| 1709 | { |
| 1710 | bool cargoArrived = false; |
| 1711 | bool bioArrived = false; |
| 1712 | bool recoveryArrived = false; |
| 1713 | bool transferArrived = false; |
| 1714 | std::set<StateRef<Organisation>> suppliers; |
| 1715 | StateRef<Building> destination; |
| 1716 | |
| 1717 | // Step 01: Find first cargo destination and remove arrived cargo |
| 1718 | for (auto it = cargo.begin(); it != cargo.end();) |
| 1719 | { |
| 1720 | if (it->destination == currentBuilding) |
| 1721 | { |
| 1722 | it->arrive(state, cargoArrived, bioArrived, recoveryArrived, transferArrived, |
| 1723 | suppliers); |
| 1724 | it = cargo.erase(it); |
| 1725 | } |
| 1726 | else |
| 1727 | { |
| 1728 | // Only force-ferry non-loot cargoes |
| 1729 | if (it->count != 0 && !destination && it->originalOwner) |
| 1730 | { |
| 1731 | destination = it->destination; |
| 1732 | } |
| 1733 | it++; |
| 1734 | } |
| 1735 | } |
| 1736 | // Step 02: Find first agent destination and remove arrived agents |
| 1737 | std::list<StateRef<Agent>> agentsToRemove; |
| 1738 | for (auto a : currentAgents) |
| 1739 | { |
| 1740 | // Remove agents if wounded and this is their home base |
| 1741 | if (a->modified_stats.health < a->current_stats.health && |
| 1742 | a->homeBuilding == currentBuilding) |
| 1743 | { |
| 1744 | agentsToRemove.push_back(a); |
| 1745 | } |
| 1746 | // Skip agents that are just on this craft without a mission |
| 1747 | if (a->missions.empty() || |
| 1748 | a->missions.front().type != AgentMission::MissionType::AwaitPickup) |
| 1749 | { |
| 1750 | continue; |
| 1751 | } |
| 1752 | if (a->missions.front().targetBuilding == currentBuilding) |
| 1753 | { |
| 1754 | agentsToRemove.push_back(a); |
| 1755 | continue; |
| 1756 | } |
| 1757 | if (!destination) |
| 1758 | { |
| 1759 | destination = a->missions.front().targetBuilding; |
| 1760 | } |
| 1761 | } |
| 1762 | for (auto &a : agentsToRemove) |
| 1763 | { |
| 1764 | a->enterBuilding(state, currentBuilding); |
| 1765 | } |