| 513 | } |
| 514 | |
| 515 | void Organisation::updateHirableAgents(GameState &state) |
| 516 | { |
| 517 | if (hirableAgentTypes.empty()) |
| 518 | { |
| 519 | return; |
| 520 | } |
| 521 | StateRef<Building> hireeLocation; |
| 522 | if (state.getCivilian().id == id) |
| 523 | { |
| 524 | std::vector<StateRef<Building>> buildingsWithoutBases; |
| 525 | for (auto &b : state.cities["CITYMAP_HUMAN"]->buildings) |
| 526 | { |
| 527 | if (!b.second->base_layout) |
| 528 | buildingsWithoutBases.emplace_back(&state, b.second); |
| 529 | } |
| 530 | if (buildingsWithoutBases.empty()) |
| 531 | { |
| 532 | LogError("Cannot spawn new hirable agent - No building without base?"); |
| 533 | } |
| 534 | hireeLocation = pickRandom(state.rng, buildingsWithoutBases); |
| 535 | } |
| 536 | else |
| 537 | { |
| 538 | if (buildings.empty()) |
| 539 | { |
| 540 | return; |
| 541 | } |
| 542 | hireeLocation = pickRandom(state.rng, buildings); |
| 543 | } |
| 544 | std::set<sp<Agent>> agentsToRemove; |
| 545 | for (auto &a : state.agents) |
| 546 | { |
| 547 | if (a.second->owner.id == id && |
| 548 | hirableAgentTypes.find(a.second->type) != hirableAgentTypes.end()) |
| 549 | { |
| 550 | if (randBoundsExclusive(state.rng, 0, 100) < CHANGE_HIREE_GONE) |
| 551 | { |
| 552 | agentsToRemove.insert(a.second); |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | for (auto &a : agentsToRemove) |
| 557 | { |
| 558 | a->die(state, true); |
| 559 | a->handleDeath(state); |
| 560 | } |
| 561 | for (auto &entry : hirableAgentTypes) |
| 562 | { |
| 563 | int newAgents = randBoundsInclusive(state.rng, entry.second.first, entry.second.second); |
| 564 | for (int i = 0; i < newAgents; i++) |
| 565 | { |
| 566 | auto a = state.agent_generator.createAgent(state, {&state, id}, entry.first); |
| 567 | // Strip them of default equipment |
| 568 | while (!a->equipment.empty()) |
| 569 | { |
| 570 | a->removeEquipment(state, a->equipment.front()); |
| 571 | } |
| 572 | a->homeBuilding = hireeLocation; |
no test coverage detected