| 4029 | } |
| 4030 | |
| 4031 | void CityView::updateSelectedUnits() |
| 4032 | { |
| 4033 | auto o = state->getPlayer(); |
| 4034 | bool foundOwned = false; |
| 4035 | bool foundOwnedVehicle = false; |
| 4036 | // Vehicles |
| 4037 | { |
| 4038 | auto it = state->current_city->cityViewSelectedVehicles.begin(); |
| 4039 | while (it != state->current_city->cityViewSelectedVehicles.end()) |
| 4040 | { |
| 4041 | auto v = *it; |
| 4042 | if (!v || v->isDead() || v->city != state->current_city) |
| 4043 | { |
| 4044 | it = state->current_city->cityViewSelectedVehicles.erase(it); |
| 4045 | } |
| 4046 | else |
| 4047 | { |
| 4048 | if (v->owner == o) |
| 4049 | { |
| 4050 | foundOwned = true; |
| 4051 | foundOwnedVehicle = true; |
| 4052 | } |
| 4053 | it++; |
| 4054 | } |
| 4055 | } |
| 4056 | } |
| 4057 | // Agents |
| 4058 | { |
| 4059 | auto it = state->current_city->cityViewSelectedAgents.begin(); |
| 4060 | while (it != state->current_city->cityViewSelectedAgents.end()) |
| 4061 | { |
| 4062 | auto a = *it; |
| 4063 | if (!a || a->isDead()) |
| 4064 | { |
| 4065 | it = state->current_city->cityViewSelectedAgents.erase(it); |
| 4066 | } |
| 4067 | else |
| 4068 | { |
| 4069 | if (a->owner == o) |
| 4070 | { |
| 4071 | foundOwned = true; |
| 4072 | } |
| 4073 | it++; |
| 4074 | } |
| 4075 | } |
| 4076 | } |
| 4077 | if (!foundOwned && selectionState != CitySelectionState::Normal) |
| 4078 | { |
| 4079 | setSelectionState(CitySelectionState::Normal); |
| 4080 | } |
| 4081 | if (activeTab != uiTabs[1]) |
| 4082 | { |
| 4083 | foundOwnedVehicle = false; |
| 4084 | } |
| 4085 | if (!foundOwnedVehicle && selectionState == CitySelectionState::ManualControl) |
| 4086 | { |
| 4087 | setSelectionState(CitySelectionState::Normal); |
| 4088 | } |