| 1785 | } |
| 1786 | |
| 1787 | void 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 | } |
nothing calls this directly
no test coverage detected