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

Method closeScreen

game/ui/base/buyandsellscreen.cpp:100–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100void BuyAndSellScreen::closeScreen()
101{
102 auto player = state->getPlayer();
103
104 // Step 01: Check funds
105 {
106 if (player->balance + moneyDelta < 0)
107 {
108 fw().stageQueueCommand({StageCmd::Command::PUSH,
109 mksp<MessageBox>(tr("Funds exceeded"),
110 tr("Order limited by your available funds."),
111 MessageBox::ButtonOptions::Ok)});
112 return;
113 }
114 }
115
116 // Step 02: Check accommodation of different sorts
117 {
118 std::array<int, MAX_BASES> vecCargoDelta;
119 std::array<bool, MAX_BASES> vecChanged;
120 vecCargoDelta.fill(0);
121 vecChanged.fill(false);
122
123 // Find all delta and mark all that have any changes
124 for (auto &l : transactionControls)
125 {
126 for (auto &c : l.second)
127 {
128 if (!c->getLinked() || c->getLinked()->front().lock() == c)
129 {
130 int i = 0;
131 for ([[maybe_unused]] const auto &b : state->player_bases)
132 {
133 int cargoDelta = c->getCargoDelta(i);
134 if (cargoDelta)
135 {
136 vecCargoDelta[i] += cargoDelta;
137 vecChanged[i] = true;
138 }
139 i++;
140 }
141 }
142 }
143 }
144
145 // Check every base, find first bad one
146 int i = 0;
147 StateRef<Base> bad_base;
148 for (auto &b : state->player_bases)
149 {
150 if ((vecChanged[i] || forceLimits) && vecCargoDelta[i] > 0 &&
151 b.second->getUsage(*state, FacilityType::Capacity::Stores, vecCargoDelta[i]) > 100)
152 {
153 bad_base = b.second->building->base;
154 break;
155 }
156 i++;
157 }

Callers

nothing calls this directly

Calls 15

trFunction · 0.85
formatFunction · 0.85
getPlayerMethod · 0.80
stageQueueCommandMethod · 0.80
getCargoDeltaMethod · 0.80
getUsageMethod · 0.80
shipmentsFromMethod · 0.80
insertMethod · 0.80
emptyMethod · 0.80
canPurchaseFromMethod · 0.80
getBoolMethod · 0.80
forcedCloseScreenMethod · 0.80

Tested by

no test coverage detected