MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / selectAgent

Method selectAgent

game/ui/general/aequipscreen.cpp:708–783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706}
707
708void 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);

Callers

nothing calls this directly

Calls 6

emptyMethod · 0.80
endMethod · 0.80
insertMethod · 0.80
beginMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected