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

Method attemptCloseScreen

game/ui/base/recruitscreen.cpp:427–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425}
426
427void RecruitScreen::attemptCloseScreen()
428{
429 auto player = state->getPlayer();
430 std::map<UString, int> bases;
431 int index = 0;
432 for (auto &b : state->player_bases)
433 {
434 bases[b.first] = index;
435 index++;
436 }
437
438 int hired = 0;
439 int transferred = 0;
440 for (int i = 0; i < 8; i++)
441 {
442 for (auto &a : agentLists[i])
443 {
444 auto agent = a->getData<Agent>();
445 if (agent->owner != player)
446 {
447 hired++;
448 }
449 else if (bases[agent->homeBuilding->base.id] != i)
450 {
451 transferred++;
452 }
453 }
454 }
455
456 int fired = 0;
457 for (auto &a : agentLists[8])
458 {
459 if (a->getData<Agent>()->owner == player)
460 {
461 auto agent = a->getData<Agent>();
462 if (agent->owner == player)
463 {
464 fired++;
465 }
466 }
467 }
468
469 if (hired != 0 || fired != 0 || transferred != 0)
470 {
471 UString message =
472 format("%d %s\n%d %s", hired, tr("unit(s) hired"), fired, tr("unit(s) fired."));
473 if (transferred > 0)
474 {
475 message = format("%s\n(%d %s)", message, transferred, tr("units(s) transferred"));
476 }
477 fw().stageQueueCommand(
478 {StageCmd::Command::PUSH,
479 mksp<MessageBox>(
480 tr("Confirm Orders"), message, MessageBox::ButtonOptions::YesNoCancel,
481 [this] { this->closeScreen(true); }, [this] { this->closeScreen(); })});
482 }
483 else
484 {

Callers

nothing calls this directly

Calls 5

closeScreenMethod · 0.95
formatFunction · 0.85
trFunction · 0.85
getPlayerMethod · 0.80
stageQueueCommandMethod · 0.80

Tested by

no test coverage detected