MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / closeScreen

Method closeScreen

game/ui/base/recruitscreen.cpp:568–669  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

566}
567
568void 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,

Callers 1

attemptCloseScreenMethod · 0.95

Calls 4

trFunction · 0.85
stageQueueCommandMethod · 0.80
getPlayerMethod · 0.80
getUsageMethod · 0.80

Tested by

no test coverage detected