// SPDX-License-Identifier: GPL-3.0-only // International marketing (docs/new_engine/vermarktung.md) on a synthetic manager: the budget, // how the reach builds up and falls, what it brings by league, and a month that cannot be paid. #include #include "modern/game/marketing.hpp" using namespace bmh; using namespace bmh::modern; namespace { int failures = 0; void check(bool ok, const char* what) { if (!ok) { std::fprintf(stderr, "FAIL: %s\n", what); ++failures; } } int32_t cash(const ModernState& g) { return int32_t(uint32_t(g.manager_records[0x314]) | uint32_t(g.manager_records[0x315]) << 8 | uint32_t(g.manager_records[0x316]) << 16 | uint32_t(g.manager_records[0x317]) << 24); } void set_cash(ModernState& g, int32_t euros) { for (int i = 0; i < 4; ++i) g.manager_records[0x314 + size_t(i)] = uint8_t(uint32_t(euros) >> (8 * i)); } // Manager 0 runs club `team` with a prestige of 50 and ten million in the account. ModernState world(int team = 0) { ModernState g; g.level = 2; g.manager_teams = {int16_t(team)}; g.manager_records.assign(5 * 0xb0c, 0); g.manager_records[0x211] = 50; set_cash(g, 10000000); return g; } } // namespace int main() { check(marketing_target(0) == 0 && marketing_target(100000) == 200 && marketing_target(500000) == 1000 && marketing_target(900000) == 1000, "a point of reach for every 500 euros, a thousand at most"); { ModernState g = world(); check(set_marketing_budget(g, 0, 200000) && g.marketing.at(0).budget == 200000, "the budget is set"); check(!set_marketing_budget(g, 0, -1000) && !set_marketing_budget(g, 0, 501000) && !set_marketing_budget(g, 0, 1500) && !set_marketing_budget(g, 1, 1000) && g.marketing.at(0).budget == 200000, "a negative, too high or uneven budget and a missing manager are refused"); // first league, prestige 50: 1600 euros a point, the full reach counts as half its points check(marketing_income(g, 0, 0) == 0 && marketing_income(g, 0, 200) == 180 * 1600 && marketing_income(g, 0, 1000) == 500 * 1600, "income by reach: every further point is worth less"); check(marketing_income(world(20), 0, 200) == 180 * 700 && marketing_income(world(60), 0, 200) == 180 * 120, "lower leagues earn much less"); ModernState famous = world(); famous.manager_records[0x211] = 100; check(marketing_income(famous, 0, 200) == 180 * 1600 * 140 / 100, "prestige raises the income"); const int32_t before = cash(g); marketing_month(g); // target 400: the first month brings a sixth of the way (66 points) check(g.marketing[0].reach == 66 && cash(g) == before - 200000 + marketing_income(g, 0, 66), "the first month: budget paid, a sixth of the way, first income"); int months = 1; while (g.marketing[0].reach < 400 && months < 60) marketing_month(g), ++months; check(g.marketing[0].reach == 400 && months > 10 && months < 40, "the reach arrives at what the budget holds after a year or two"); const int32_t steady = cash(g); marketing_month(g); check(cash(g) - steady == marketing_income(g, 0, 400) - 200000 && cash(g) > steady, "at the target the marketing pays more than it costs in the first league"); check(set_marketing_budget(g, 0, 0), "the budget is cut"); marketing_month(g); check(g.marketing[0].reach == 300, "without budget the reach falls by a quarter"); while (g.marketing[0].reach > 0) marketing_month(g); const int32_t empty = cash(g); marketing_month(g); check(cash(g) == empty, "no budget, no reach: nothing is booked"); } // a month the account cannot bear counts as one without budget { ModernState g = world(); set_marketing_budget(g, 0, 300000); g.marketing[0].reach = 400; set_cash(g, 1000); marketing_month(g); check(g.marketing[0].reach == 300 && cash(g) == 1000 + marketing_income(g, 0, 300), "unpaid month: the reach falls, the account is not charged"); } if (failures) return 1; std::puts("modern_marketing_tests: ok"); return 0; }