| 132 | } |
| 133 | |
| 134 | sp<Facility> findCurrentResearchFacility(sp<GameState> state, AgentType::Role role, |
| 135 | FacilityType::Capacity capacity) |
| 136 | { |
| 137 | sp<Facility> lab; |
| 138 | for (auto &a : state->current_city->cityViewSelectedAgents) |
| 139 | { |
| 140 | if (a && a->type->role == role) |
| 141 | { |
| 142 | state->current_base = a->homeBuilding->base; |
| 143 | if (a->assigned_to_lab) |
| 144 | { |
| 145 | auto thisRef = StateRef<Agent>{state.get(), a}; |
| 146 | for (auto &fac : state->current_base->facilities) |
| 147 | { |
| 148 | if (!fac->lab) |
| 149 | { |
| 150 | continue; |
| 151 | } |
| 152 | auto it = std::find(fac->lab->assigned_agents.begin(), |
| 153 | fac->lab->assigned_agents.end(), thisRef); |
| 154 | if (it != fac->lab->assigned_agents.end()) |
| 155 | { |
| 156 | lab = fac; |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | for (auto &f : state->current_base->facilities) |
| 164 | { |
| 165 | if (f->type->capacityType == capacity) |
| 166 | { |
| 167 | lab = f; |
| 168 | break; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | if (lab == nullptr) |
| 176 | { |
| 177 | for (auto &base : state->player_bases) |
| 178 | { |
| 179 | for (auto &facility : base.second->facilities) |
| 180 | { |
| 181 | if (facility->type->capacityType == capacity) |
| 182 | { |
| 183 | lab = facility; |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | if (lab) |
| 188 | break; |
| 189 | } |
| 190 | } |
| 191 | return lab; |