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

Method updateSelectedUnits

game/ui/tileview/battleview.cpp:1787–1845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1785}
1786
1787void BattleView::updateSelectedUnits()
1788{
1789 if (activeTab == notMyTurnTab)
1790 {
1791 resetPathPreview();
1792 resetAttackCost();
1793 return;
1794 }
1795 auto prevLSU = lastSelectedUnit;
1796 auto it = battle.battleViewSelectedUnits.begin();
1797 auto o = battle.currentPlayer;
1798 while (it != battle.battleViewSelectedUnits.end())
1799 {
1800 auto u = *it;
1801 if (!u || u->isDead() || u->isUnconscious() || u->owner != o || u->retreated ||
1802 u->moraleState != MoraleState::Normal)
1803 {
1804 it = battle.battleViewSelectedUnits.erase(it);
1805 }
1806 else
1807 {
1808 it++;
1809 }
1810 }
1811 lastSelectedUnit =
1812 battle.battleViewSelectedUnits.empty() ? nullptr : battle.battleViewSelectedUnits.front();
1813
1814 // Cancel stuff that cancels on unit change
1815 if (prevLSU != lastSelectedUnit)
1816 {
1817 if (selectionState == BattleSelectionState::ThrowLeft ||
1818 selectionState == BattleSelectionState::ThrowRight)
1819 {
1820 selectionState = BattleSelectionState::Normal;
1821 }
1822 }
1823 if (prevLSU != lastSelectedUnit || !lastSelectedUnit)
1824 {
1825 resetPathPreview();
1826 resetAttackCost();
1827 setSelectedTab(mainTab);
1828 }
1829 else
1830 {
1831 auto p = lastSelectedUnit->tileObject->getOwningTile()->position;
1832 auto f = lastSelectedUnit->goalFacing;
1833 if (lastSelectedUnitPosition != p)
1834 {
1835 resetPathPreview();
1836 resetAttackCost();
1837 }
1838 if (lastSelectedUnitFacing != f)
1839 {
1840 resetAttackCost();
1841 }
1842 lastSelectedUnitPosition = p;
1843 lastSelectedUnitFacing = f;
1844 }

Callers

nothing calls this directly

Calls 6

endMethod · 0.80
isUnconsciousMethod · 0.80
emptyMethod · 0.80
getOwningTileMethod · 0.80
beginMethod · 0.45
isDeadMethod · 0.45

Tested by

no test coverage detected