| 566 | } |
| 567 | |
| 568 | void RecruitScreen::closeScreen(bool confirmed) |
| 569 | { |
| 570 | if (!confirmed) |
| 571 | { |
| 572 | fw().stageQueueCommand({StageCmd::Command::POP}); |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | // Step 01 : Calculate money and lq deltas |
| 577 | int moneyDelta = 0; |
| 578 | std::vector<int> vecLqDelta; |
| 579 | vecLqDelta.resize(8); |
| 580 | |
| 581 | auto player = state->getPlayer(); |
| 582 | std::map<UString, int> bases; |
| 583 | int index = 0; |
| 584 | for (auto &b : state->player_bases) |
| 585 | { |
| 586 | bases[b.first] = index; |
| 587 | index++; |
| 588 | } |
| 589 | |
| 590 | // Hirees and transfers |
| 591 | for (int i = 0; i < 8; i++) |
| 592 | { |
| 593 | for (auto &a : agentLists[i]) |
| 594 | { |
| 595 | auto agent = a->getData<Agent>(); |
| 596 | // Hired |
| 597 | if (agent->owner != player) |
| 598 | { |
| 599 | vecLqDelta[i]++; |
| 600 | moneyDelta -= state->agent_salary.at(agent->type->role); |
| 601 | } |
| 602 | // Moved away from his base to this base |
| 603 | else if (bases[agent->homeBuilding->base.id] != i) |
| 604 | { |
| 605 | vecLqDelta[bases[agent->homeBuilding->base.id]]--; |
| 606 | vecLqDelta[i]++; |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | // Fired |
| 611 | for (auto &a : agentLists[8]) |
| 612 | { |
| 613 | auto agent = a->getData<Agent>(); |
| 614 | if (agent->owner == player) |
| 615 | { |
| 616 | vecLqDelta[bases[agent->homeBuilding->base.id]]--; |
| 617 | moneyDelta -= state->agent_fired_penalty.at(agent->type->role); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | // Step 02: Insufficient funds? |
| 622 | if (player->balance + moneyDelta < 0) |
| 623 | { |
| 624 | fw().stageQueueCommand( |
| 625 | {StageCmd::Command::PUSH, |
no test coverage detected