|
1 | 1 | (function () { |
2 | 2 | const STORAGE_KEY = "aggs-operations-state-v4"; |
3 | 3 | const TRADE_V4_FORMULA_VERSION = "trade2028"; |
4 | | - const TRADE_V4_FISCAL_BALANCE_VERSION = "pre-v4-balance-20260604"; |
5 | | - const PRE_TRADE_V4_BUDGET_BALANCE_TARGETS = { |
6 | | - "astoria": 6281, |
7 | | - "baathist_republic_of_volgastan": -10231, |
8 | | - "baechong_democratic_republic": -193, |
9 | | - "benera_navine": 291, |
10 | | - "bingtau_kingdom": 94, |
11 | | - "butonian_state": 2, |
12 | | - "crovian_national_union": -165, |
13 | | - "democratic_republic_of_suzuharu": 2154, |
14 | | - "dracoist_malonia": 1066, |
15 | | - "duchy_of_hoogeveen": 1026, |
16 | | - "duchy_of_ledostrov": -342, |
17 | | - "empire_of_hanazuki": -2, |
18 | | - "empire_of_hyeosu": 3497, |
19 | | - "empire_of_khalindar": 7734, |
20 | | - "federated_syndicates_of_veszprem": -1669, |
21 | | - "federation_of_vinterholm": -838, |
22 | | - "fengu_people_s_federation": 3, |
23 | | - "fuji_shogunate": 133, |
24 | | - "hyelean_republic": -47, |
25 | | - "imperial_dynasty_of_saochai": 1108, |
26 | | - "imperial_rhovland": 2367, |
27 | | - "imperial_suomi": 2986, |
28 | | - "judas_democratic_republic": 1084, |
29 | | - "karkalnadag_kingdom": 345, |
30 | | - "khalari_emirates": -675, |
31 | | - "kingdom_of_lunaria": 850, |
32 | | - "kolkenlennan_empire": 3997, |
33 | | - "mumoon_hamed_sultunate": 58, |
34 | | - "okudan_empire": -6639, |
35 | | - "orinian_empire": 10414, |
36 | | - "pdr_of_hoshigoru": -1370, |
37 | | - "people_s_federation_of_xanaqu": 7059, |
38 | | - "people_s_republic_of_mariposa": 41, |
39 | | - "republic_of_aurendale": 10719, |
40 | | - "republic_of_belcanto": -4298, |
41 | | - "republic_of_borealyan": 309, |
42 | | - "republic_of_calblanca": 531, |
43 | | - "republic_of_perzam": 128, |
44 | | - "republic_of_pestera": -5175, |
45 | | - "republic_of_shangri_la": 20, |
46 | | - "serranova_military_junta": 68, |
47 | | - "solara": 2236, |
48 | | - "templar_of_saxonia": 55, |
49 | | - "theorin_commonwealth": -398, |
50 | | - "tsardom_of_nogoyev": -537, |
51 | | - "vesperan_federation": -2157, |
52 | | - "vinraarabeise_people_s_republic": 377, |
53 | | - "vorkutangrad": 719, |
54 | | - "xaojin_heavenly_kingdom": 91, |
55 | | - "zhensanovian_commonwealth": -8330 |
56 | | - }; |
57 | 4 |
|
58 | 5 | const HEALTH_GROWTH = { Depression: -3, Recession: -2, Slowdown: -1, Recovery: 1, Expansion: 2, Prosperity: 3 }; |
59 | 6 | const HEALTH_DEMOGRAPHICS = { |
|
203 | 150 | return Number(number(value, 0).toFixed(2)); |
204 | 151 | } |
205 | 152 |
|
206 | | - function budgetBalanceMigrationTarget(national = {}) { |
207 | | - const storedBalance = number(national.budgetBalance, null); |
208 | | - if (Number.isFinite(storedBalance)) return roundCurrency(storedBalance); |
209 | | - return roundCurrency(number(national.budgetCapacity, 0) - number(national.budgetExpenditure, 0)); |
210 | | - } |
211 | | - |
212 | | - function tradeV4FiscalBalanceTarget(id, national = {}) { |
213 | | - const preTradeV4Target = number(PRE_TRADE_V4_BUDGET_BALANCE_TARGETS[id], null); |
214 | | - if (Number.isFinite(preTradeV4Target)) return roundCurrency(preTradeV4Target); |
215 | | - return budgetBalanceMigrationTarget(national); |
216 | | - } |
217 | | - |
218 | | - function hasPreTradeV4BudgetBalanceTarget(id) { |
219 | | - return Number.isFinite(number(PRE_TRADE_V4_BUDGET_BALANCE_TARGETS[id], null)); |
220 | | - } |
221 | | - |
222 | | - function captureTradeV4BudgetBalanceTargets(data, previousTradeFormulaVersion) { |
223 | | - if (previousTradeFormulaVersion === TRADE_V4_FORMULA_VERSION || data.meta.tradeV4BudgetBalanceTargets) return; |
224 | | - const nationalRows = data.national && typeof data.national === "object" && !Array.isArray(data.national) |
225 | | - ? data.national |
226 | | - : {}; |
227 | | - const targets = Object.fromEntries( |
228 | | - Object.entries(nationalRows) |
229 | | - .map(([id, national]) => [id, budgetBalanceMigrationTarget(national)]) |
230 | | - .filter(([, target]) => Number.isFinite(target)) |
231 | | - ); |
232 | | - if (Object.keys(targets).length) data.meta.tradeV4BudgetBalanceTargets = targets; |
233 | | - } |
234 | | - |
235 | | - function captureTradeV4FiscalBalanceTargets(data, previousTradeFormulaVersion) { |
236 | | - if (data.meta.tradeV4FiscalBalanceVersion === TRADE_V4_FISCAL_BALANCE_VERSION || data.meta.tradeV4BudgetBalanceTargets) return; |
237 | | - if (previousTradeFormulaVersion !== TRADE_V4_FORMULA_VERSION) return; |
238 | | - const nationalRows = data.national && typeof data.national === "object" && !Array.isArray(data.national) |
239 | | - ? data.national |
240 | | - : {}; |
241 | | - const targets = Object.fromEntries( |
242 | | - Object.entries(nationalRows) |
243 | | - .map(([id, national]) => [id, tradeV4FiscalBalanceTarget(id, national)]) |
244 | | - .filter(([, target]) => Number.isFinite(target)) |
245 | | - ); |
246 | | - if (!Object.keys(targets).length) return; |
247 | | - const exactTargets = Object.fromEntries(Object.keys(targets).filter((id) => hasPreTradeV4BudgetBalanceTarget(id)).map((id) => [id, true])); |
248 | | - data.meta.tradeV4BudgetBalanceTargets = targets; |
249 | | - data.meta.tradeV4BudgetBalanceTargetMode = "normalize"; |
250 | | - data.meta.tradeV4BudgetBalanceExactTargets = exactTargets; |
251 | | - } |
252 | | - |
253 | 153 | function ensureState(data = {}) { |
254 | 154 | data.meta = data.meta || {}; |
255 | | - const previousTradeFormulaVersion = data.meta.tradeFormulaVersion; |
256 | 155 | data.meta.title = data.meta.title || "AG-GS Global Ledger"; |
257 | 156 | data.meta.currentYear = number(data.meta.currentYear, 2021); |
258 | 157 | data.meta.worldEconomicHealth = data.meta.worldEconomicHealth || "Expansion"; |
|
271 | 170 | ["populationColumns", "equipmentCosts", "eraMultipliers", "costAdditionModifiers", "costReductionModifiers"].forEach((key) => { |
272 | 171 | data[key] = Array.isArray(data[key]) ? data[key] : []; |
273 | 172 | }); |
274 | | - captureTradeV4BudgetBalanceTargets(data, previousTradeFormulaVersion); |
275 | | - captureTradeV4FiscalBalanceTargets(data, previousTradeFormulaVersion); |
276 | 173 | data.meta.tradeFormulaVersion = TRADE_V4_FORMULA_VERSION; |
277 | 174 | data.tradeNetwork = data.tradeNetwork && typeof data.tradeNetwork === "object" && !Array.isArray(data.tradeNetwork) ? data.tradeNetwork : {}; |
278 | 175 | data.tradeNetwork.targetedTariffs = data.tradeNetwork.targetedTariffs && typeof data.tradeNetwork.targetedTariffs === "object" && !Array.isArray(data.tradeNetwork.targetedTariffs) |
|
334 | 231 | return true; |
335 | 232 | } |
336 | 233 |
|
337 | | - function hasTradeV4BudgetBalanceTargets(data) { |
338 | | - const targets = data.meta?.tradeV4BudgetBalanceTargets; |
339 | | - return Boolean(targets && typeof targets === "object" && !Array.isArray(targets) && Object.keys(targets).length); |
340 | | - } |
341 | | - |
342 | 234 | function recalculationSignature(data) { |
343 | 235 | return Object.keys(data.national || {}) |
344 | 236 | .sort() |
|
857 | 749 |
|
858 | 750 | function recalculateAll(data, options = {}) { |
859 | 751 | ensureTradeV4State(data); |
860 | | - if (hasTradeV4BudgetBalanceTargets(data)) { |
861 | | - const migrationOptions = { ...options, keepTradeV4BudgetBalanceTargets: true }; |
862 | | - let previousSignature = ""; |
863 | | - for (let attempt = 0; attempt < 8; attempt++) { |
864 | | - recalculateTrade(data, options); |
865 | | - recalculateBudgets(data, migrationOptions); |
866 | | - const nextSignature = recalculationSignature(data); |
867 | | - if (attempt > 0 && nextSignature === previousSignature) break; |
868 | | - previousSignature = nextSignature; |
869 | | - } |
870 | | - delete data.meta.tradeV4BudgetBalanceTargets; |
871 | | - delete data.meta.tradeV4BudgetBalanceTargetMode; |
872 | | - delete data.meta.tradeV4BudgetBalanceExactTargets; |
873 | | - data.meta.tradeV4FiscalBalanceVersion = TRADE_V4_FISCAL_BALANCE_VERSION; |
874 | | - return data; |
875 | | - } |
876 | 752 | let previousSignature = ""; |
877 | 753 | for (let attempt = 0; attempt < 8; attempt++) { |
878 | 754 | recalculateTrade(data, options); |
|
0 commit comments