| 706 | } |
| 707 | |
| 708 | void AEquipScreen::selectAgent(sp<Agent> agent, bool inverse, bool additive) |
| 709 | { |
| 710 | auto firstAgent = selectedAgents.empty() ? nullptr : selectedAgents.front(); |
| 711 | bool fullUpdate = !isInVicinity(agent) && !inverse; |
| 712 | std::set<sp<Agent>> agentsToUpdate; |
| 713 | auto pos = std::find(selectedAgents.begin(), selectedAgents.end(), agent); |
| 714 | // Can't deselect last |
| 715 | if (inverse && selectedAgents.size() <= 1) |
| 716 | { |
| 717 | return; |
| 718 | } |
| 719 | // Can't additive if not in vicinity or in battle |
| 720 | if (additive && (!isInVicinity(agent) || (agent->unit && agent->unit->tileObject))) |
| 721 | { |
| 722 | additive = false; |
| 723 | } |
| 724 | if (inverse) |
| 725 | { |
| 726 | // Agent in selection => remove |
| 727 | if (pos != selectedAgents.end()) |
| 728 | { |
| 729 | agentsToUpdate.insert(agent); |
| 730 | selectedAgents.erase(pos); |
| 731 | } |
| 732 | } |
| 733 | else |
| 734 | { |
| 735 | // Agent not selected |
| 736 | if (pos == selectedAgents.end()) |
| 737 | { |
| 738 | // If additive add |
| 739 | if (additive) |
| 740 | { |
| 741 | selectedAgents.push_front(agent); |
| 742 | for (auto &a : selectedAgents) |
| 743 | { |
| 744 | agentsToUpdate.insert(a); |
| 745 | } |
| 746 | } |
| 747 | else |
| 748 | { |
| 749 | // Agent not in selection => replace selection with agent |
| 750 | for (auto &a : selectedAgents) |
| 751 | { |
| 752 | agentsToUpdate.insert(a); |
| 753 | } |
| 754 | selectedAgents.clear(); |
| 755 | selectedAgents.push_back(agent); |
| 756 | agentsToUpdate.insert(agent); |
| 757 | } |
| 758 | } |
| 759 | // Agent is selected |
| 760 | else |
| 761 | { |
| 762 | if (agent != firstAgent) |
| 763 | { |
| 764 | selectedAgents.erase(pos); |
| 765 | selectedAgents.push_front(agent); |