Modern: the traffic access has four stages

The Modern interface shows four stages for the traffic access, the original
has three. A Modern world (WorldLayout::traffic_stages = 4) keeps the
condition byte in steps of 64 (64, 128, 192, 255) and offers a build up to
stage 3; every stage weighs as one original stage. New careers convert the
original start table, older Modern saves are converted on load
(traffic_scale). Classic data keeps three stages; the Classic equivalence is
unchanged. Also: the live ticker takes the matches from the desk day on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 09:53:31 +01:00
1 parent fda4b72967
commit 0046ab90d0
18 files changed
+154 -16

No files matched your search

+2 -2
View File
@@ -54,9 +54,9 @@ jobs:
- name: Configure without game data
run: cmake -S . -B build-engine -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENBMH_BUILD_EDITOR=OFF -DBMH_DATA=
- name: Compile the Modern console, simulator and engine tests
run: cmake --build build-engine --target openbmh_modern_cli modern_season_sim modern_world_info modern_camp_tests modern_almanac_tests modern_toto_tests modern_calendar_tests --parallel 2
run: cmake --build build-engine --target openbmh_modern_cli modern_season_sim modern_world_info modern_camp_tests modern_almanac_tests modern_toto_tests modern_calendar_tests modern_traffic_tests --parallel 2
- name: Run the data-free Modern engine tests
run: ctest --test-dir build-engine -R "^modern_(camp|almanac|toto|calendar)_tests$" --output-on-failure --output-junit modern-engine-results.xml
run: ctest --test-dir build-engine -R "^modern_(camp|almanac|toto|calendar|traffic)_tests$" --output-on-failure --output-junit modern-engine-results.xml
- name: Upload test report
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+3
View File
@@ -1220,6 +1220,9 @@ add_executable(modern_toto_tests tests/modern_toto_tests.cpp)
target_link_libraries(modern_toto_tests PRIVATE bmh_season_modern)
add_test(NAME modern_toto_tests COMMAND modern_toto_tests)
add_executable(modern_traffic_tests tests/modern_traffic_tests.cpp)
target_link_libraries(modern_traffic_tests PRIVATE bmh_season_modern)
add_test(NAME modern_traffic_tests COMMAND modern_traffic_tests)
add_executable(modern_calendar_tests tests/modern_calendar_tests.cpp)
target_link_libraries(modern_calendar_tests PRIVATE bmh_season_modern)
add_test(NAME modern_calendar_tests COMMAND modern_calendar_tests)
+9
View File
@@ -115,6 +115,15 @@ Ergebnis: keine Prüfverletzung, keine Fehler bei Verträgen, Werbung und Lagern
Keine Regeländerung nötig.
## Stadion: Verkehrsanbindung mit vier Stufen
Die Modern-Oberfläche zeigt für die Verkehrsanbindung vier Ausbaustufen, das Original hat drei (Zustandsbyte in Schritten von 0x55: 85, 170, 255; Angebot unter 171). In einer Modern-Welt (`WorldLayout::traffic_stages = 4`) gilt deshalb (`src/modern/game/traffic.hpp`, 27.10.2026):
- Schritte von 64: Stufe 1–4 bei 64, 128, 192, 255; ein Ausbau wird bis Stufe 3 angeboten. Jeder Ausbau kostet wie im Original (Grundpreis 2,5 Mio. €, 45 Tage).
- Jede Stufe wirkt wie eine Original-Stufe (Einnahmen je Zuschauer, Monatseinnahmen, Zuschauerstufe von 25.000); die vierte Stufe ist ein zusätzlicher Schritt.
- Neue Karrieren starten mit der Stufe der Original-Starttabelle; ältere Modern-Spielstände werden beim Laden in die neue Skala umgerechnet (`traffic_scale` in `state/modern.json`).
- Mit Classic-Daten bleibt es bei drei Stufen (Gleichheitstest unverändert). Test: `modern_traffic_tests`.
## Offen
- Langläufe mit einem aktiven Manager (Transfers, Aufstellung), sobald die Konsole oder die UI das automatisiert erlaubt.
- Spieler in den Pools (vereinslos) aus dem Datensatz behalten ihre Rohwerte; der Datensatz 1.3 hat keine.
+1 -1
View File
@@ -33,7 +33,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
| `training` | Bälle je Spielertyp und Trainingsbereich (1–3) mit den Grenzen, je Spieler Intensität und Schwerpunkt, ob das Training eingerichtet ist, Automatik-Bits |
| `contracts` | je Spieler Restlaufzeit, Monatsgehalt, Versicherung, Prämien; das offene Angebot (`quote`: ID, Spieler, Monatsforderung für 1–4 Jahre, Höchstgehalt 200.000 €) |
| `advertising` | 14 Banden (`ad:board/<n>`), Trikot (`ad:shirt`), TV-Rechte (`ad:tv`) je mit Vertrag (Sponsor, Monatsbetrag, Restmonate, Verlängerung, Option) und den offenen Angeboten (`offer:ad-<Platz>-<Nr.>`, Sponsor, Betrag, Banden, Monate, `allowed`); die drei Budgets (Merchandising, Presse, Fanarbeit) mit Stand, Höchstbetrag, Lieferwochen; die Finanzvorschau des Originals |
| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` 0–3, sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) |
| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` und `maxStage`: Classic 3, Modern-Welt 4; sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) |
| `transfer` | die Transferliste (`listing:<n>`: Spieler, Alter, Position, Stärke, Verkäufer, Ablöseforderung, Gehaltsreferenz pro Jahr, Gehaltsforderung in %, Zahl der Angebote, eigene Listung, eigenes Gebot), der eigene Kader (gelistet oder nicht), Kontostand, Kreditrahmen |
| `toto` | der Tippschein ([Toto](toto.md)): `open` (elf Spiele), Spiele, Einsatz und Kosten (`Money`), Spalten, Regeln, letzte Abrechnung |
| `sponsor` | das Exklusiv-Sponsor-Angebot aus einem Trainingslager und ein vorgemerkter Vertrag (`monthly` als `Money`; `asset: null`, siehe [Trainingslager](trainingslager.md)) |
+5 -1
View File
@@ -12,6 +12,7 @@
#include <limits>
#include "app/window_actions.hpp"
#include "game/world_layout.hpp"
#include "cli/console/console.hpp"
#include "cli/console/detail.hpp"
#include "game/bank_credit.hpp"
@@ -324,7 +325,10 @@ void Console::register_money_commands() {
// condition byte to the next multiple of 85 (85, 170, 255; ageing lowers it), and an
// offer exists below 171. The other objects are built once.
std::string state = s.level[o] != 0 ? "built" : "-";
if (o == 0 && s.level[0] != 0) state = "stage " + std::to_string((s.level[0] - 1) / 85 + 1) + " of 3";
if (o == 0 && s.level[0] != 0) { // three stages in steps of 85; a Modern world: four in steps of 64
const int stages = bmh::world_layout().traffic_stages, step = stages == 4 ? 64 : 85;
state = "stage " + std::to_string((s.level[0] - 1) / step + 1) + " of " + std::to_string(stages);
}
rows.push_back({std::to_string(o), text(kPeripheryNames + int(o)), building ? "building" : state,
std::to_string(s.days[o])});
}
+3
View File
@@ -42,6 +42,9 @@ struct WorldLayout {
// national_start: team no_team() + n at national_start + (n - 1) * national_slots). Classic: none,
// the national teams play without players.
uint32_t national_start = 0, national_slots = 0;
// Stages of the traffic access (periphery object 0): Classic 3 (condition byte in steps of
// 0x55), a Modern world 4 (steps of 64; the Modern interface shows four).
int traffic_stages = 3;
int first_amateur() const { return league_teams; }
int first_foreign_cup() const { return league_teams + amateur_teams; }
+11 -3
View File
@@ -654,6 +654,13 @@ ModernSession::ModernSession(const std::filesystem::path &data, uint32_t watcom_
// saves from before the national squads end at the reserve: the national squads
// start empty (those teams play with their drawn rating until the next nomination)
if (g_.squad_slots.size() < world_layout().total_slots) g_.squad_slots.resize(world_layout().total_slots, 0x0fff);
// saves from before the four traffic stages keep the original's scale: convert each
// manager record's traffic access byte to its stage in the new scale
if (modern::four_traffic_stages() && g_.traffic_scale != 64) {
for (size_t rec = 0; rec + 0xb0c <= g_.manager_records.size(); rec += 0xb0c)
g_.manager_records[rec] = modern::traffic_from_original(g_.manager_records[rec]);
g_.traffic_scale = 64;
}
rand_ = saved.random;
game_ = saved.game;
native.emplace();
@@ -4320,6 +4327,7 @@ bool ModernSession::finish(ui::CareerInitializationResult& result, std::string&
// Both UI projections must reflect the freshly initialized driver cursor.
// Reuse its prepared groups; these projections do not prepare an event or draw RNG.
modern::ensure_ui_identities(g_); // career and manager ids of the interface contract
if (modern::four_traffic_stages()) g_.traffic_scale = 64; // the start built the traffic access in that scale
result.desktop = desktop_projection(1);
result.preparation = preparation_projection(1);
for (size_t m = 0; m < managers_.size(); ++m)
@@ -8387,7 +8395,7 @@ bool ModernSession::dispatch_stadium(const ui::StadiumRequest& supplied_request,
request.object >= 14 || !plain(request.object)) return invalid("invalid_periphery_offer");
const size_t object = size_t(request.object);
const uint8_t level = g_.manager_records[record + object];
if (g_.manager_records[record + 0x1e + object] != 0 || (object == 0 ? level >= 0xab : level != 0))
if (g_.manager_records[record + 0x1e + object] != 0 || (object == 0 ? !modern::traffic_buildable(level) : level != 0))
return invalid("periphery_unavailable");
const int32_t price = modern::periphery_offer(g_, request.object, game_);
if (price <= 0) return invalid("invalid_periphery_price");
@@ -8403,7 +8411,7 @@ bool ModernSession::dispatch_stadium(const ui::StadiumRequest& supplied_request,
if (request.kind == ui::StadiumRequestKind::build_periphery) {
const size_t object = size_t(request.object);
const uint8_t level = g_.manager_records[record + object];
if (g_.manager_records[record + 0x1e + object] != 0 || (object == 0 ? level >= 0xab : level != 0))
if (g_.manager_records[record + 0x1e + object] != 0 || (object == 0 ? !modern::traffic_buildable(level) : level != 0))
return invalid("periphery_unavailable");
// ConstructionPricePercent consumes this genuine JA even when PayConstruction's
// payment fails. The Source presenter runs before the quote
@@ -8924,7 +8932,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
for (size_t o = 0; o < 14; ++o) {
const int level = st.level[o];
O row{{"id", "periphery:" + std::to_string(o)}, {"name", text(720 + o)}, {"constructionDays", int(st.days[o])}};
if (o == 0) row["stage"] = level == 0 ? 0 : (level - 1) / 85 + 1, row["maxStage"] = 3;
if (o == 0) row["stage"] = modern::traffic_stage(level), row["maxStage"] = world_layout().traffic_stages;
else row["built"] = level != 0;
periphery.push_back(std::move(row));
}
+1
View File
@@ -4,6 +4,7 @@
#include "modern/content/projections.hpp"
#include "modern/content/statistics.hpp"
#include "modern/content/ui_contract.hpp"
#include "modern/game/traffic.hpp"
#include "modern/content/world_expand.hpp"
// The engine side of the UI's career handoff (src/ui/flow.hpp, ENGINE_BINDING.md).
//
+1
View File
@@ -142,6 +142,7 @@ WorldLayout modern_layout(int league_clubs, int german_clubs) {
// no_team, filled on the international days from the players of its nationality
w.national_start = w.pool_end + w.no_team_slots + 54;
w.national_slots = kSquadSlots;
w.traffic_stages = 4; // the four stages of the Modern interface (modern/game/traffic.hpp)
w.total_slots = w.national_start + uint32_t(w.national_teams - 1) * w.national_slots;
return w;
}
+3 -1
View File
@@ -138,7 +138,8 @@ void save_world_career(const std::filesystem::path& path, const World& world, co
{"exclusive_sponsors", sponsors_json(state.exclusive_sponsors)},
{"career_id", state.career_id},
{"manager_ids", strings(state.manager_ids)},
{"manager_serial", int64_t(state.manager_serial)}});
{"manager_serial", int64_t(state.manager_serial)},
{"traffic_scale", int64_t(state.traffic_scale)}});
// The almanac: finished seasons unchanged, the running one encoded now.
for (const auto& [name, bytes] : state.almanac.finished) docs[name] = bytes;
if (state.almanac.current.season >= 0) docs["history/current.bin"] = encode_almanac_season(state.almanac.current);
@@ -193,6 +194,7 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
out.state.career_id = str(get(modern, "career_id"));
out.state.manager_ids = strings(get(modern, "manager_ids"));
out.state.manager_serial = uint32_t(num(get(modern, "manager_serial")));
if (o->count("traffic_scale")) out.state.traffic_scale = uint8_t(num(get(modern, "traffic_scale")));
}
for (const auto& [name, bytes] : docs) {
if (!name.starts_with("history/season-")) continue;
+2 -1
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "modern/game/traffic.hpp"
#include "modern/game/modern_state.hpp"
#include "modern/game/environment.hpp"
#include "modern/game/balance_plan.hpp"
@@ -50,7 +51,7 @@ int32_t wrap(int64_t v) { return int32_t(uint32_t(uint64_t(v))); }
// Add32: the level of a facility (facility 0: its size step)
uint32_t facility_level(const ModernState& g, int m, int k) {
const uint8_t v = rec8(g, m, size_t(k));
return k == 0 ? uint32_t((v - 1) / 0x55 + 1) & 0xff : 1;
return k == 0 ? uint32_t(traffic_stage(v)) & 0xff : 1; // the traffic access by its stage (traffic.hpp)
}
// DailyInterest2(0): the interest of one day without booking it - negative is income
+2 -1
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "modern/game/traffic.hpp"
#include "modern/game/modern_state.hpp"
#include "modern/game/career.hpp"
@@ -446,7 +447,7 @@ void build_stadium(ModernState& g, const LeImage& exe, int m, int league, int mo
const uint8_t level = mode == 1 ? 3 : exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField + uint32_t(i + league * 0x17));
if (i == 0x10 || i == 0x11 || level == 0) continue;
if (i == 0) {
rec[0] = uint8_t(exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField + uint32_t(league * 0x17)) + (mode == 1 ? 0x55 : 0));
rec[0] = traffic_from_original(uint8_t(exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField + uint32_t(league * 0x17)) + (mode == 1 ? 0x55 : 0)));
} else {
rec[i] = uint8_t(rand.range(exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField2 + uint32_t(i * 5)), exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField3 + uint32_t(i * 5))) << 2);
}
+3 -2
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "modern/game/traffic.hpp"
#include "modern/game/modern_state.hpp"
#include "modern/game/matchday_setup.hpp"
#include "game/trace.hpp"
@@ -108,7 +109,7 @@ int32_t catering_income(const ModernState& g, int manager, int32_t spectators, W
for (int k = 0; k < 14; k++) {
const uint8_t v = g.manager_records.at(rec + size_t(k));
if (v == 0) continue;
const uint32_t level = k == 0 ? uint32_t((v - 1) / 0x55 + 1) & 0xFF : 1; // Add32
const uint32_t level = k == 0 ? uint32_t(traffic_stage(v)) & 0xFF : 1; // Add32 (traffic.hpp)
sum += kPerVisitor[k] * uint32_t(spectators) * level / 100;
}
if (sum != 0) sum = uint32_t(rand.range(0x55, 0x73)) * sum / 100;
@@ -724,7 +725,7 @@ int attendance(ModernState& g, int home, int away, int bits, int temperature, in
for (int k = 0; k < 10; k++) {
const int v = r8(size_t(k));
// MatchdaySetupRuntimeField6[0] is overwritten with the step of the stadium size
const int32_t step = k == 0 ? int32_t(v / 0x55 * 25000) : kStadiumSteps[k];
const int32_t step = k == 0 ? int32_t(traffic_full_stages(v) * 25000) : kStadiumSteps[k];
if (step < n && (v == 0 || k == 0)) n -= n / rand.range(10, 20);
}
const int wet = int(uint32_t(100 - covered) * uint32_t(uint8_t(rain)) * 8) / 100;
+3
View File
@@ -82,6 +82,9 @@ struct ModernState : GameState {
std::string career_id;
std::vector<std::string> manager_ids;
uint32_t manager_serial = 0;
// The scale of the traffic access bytes (traffic.hpp): 0 the original's (steps of 0x55), 64 the
// four stages of a Modern world. Older Modern saves are converted when loaded.
uint8_t traffic_scale = 0;
// Players whose age the data set gives (birth date); the others carry a placeholder the
// career start replaces as in the original. Needed only while a career starts (not saved).
std::vector<bool> world_age_known;
+2 -1
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "modern/game/traffic.hpp"
#include "modern/game/modern_state.hpp"
#include "modern/game/environment.hpp"
#include "modern/game/month.hpp"
@@ -531,7 +532,7 @@ int32_t monthly_income(ModernState& g, int m) {
for (int k = 0; k < 6; k++) {
const uint8_t v = r.at(rec + size_t(k));
if (v == 0) continue;
const int level = k == 0 ? ((v - 1) / 0x55 + 1) & 0xFF : 1; // Add32
const int level = k == 0 ? traffic_stage(v) & 0xFF : 1; // Add32 (traffic.hpp)
sum += level * kFacilityIncome[k];
}
add32(r, rec + 0x86c, sum);
+51
View File
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// The traffic access (Verkehrsanbindung, stadium periphery object 0, manager record +0x00):
// the only periphery object with stages. Its condition byte grows by one stage per finished
// build and sinks with the stadium's ageing; a stage counts while the byte is above the stage
// below it.
//
// The original has three stages in steps of 0x55 (85, 170, 255; a new build is offered below
// 0xab). A Modern world has four, as the Modern interface shows them: steps of 64 (64, 128,
// 192, 255; a build is offered below 193). Every stage weighs as much as one original stage
// (income per visitor, monthly income, the attendance step). Classic data in the Modern core
// keeps the original three (WorldLayout::traffic_stages).
#include <algorithm>
#include <cstdint>
#include "game/world_layout.hpp"
namespace bmh::modern {
inline bool four_traffic_stages() { return world_layout().traffic_stages == 4; }
inline int traffic_step() { return four_traffic_stages() ? 64 : 0x55; }
// The stage of a condition byte, 0 = none (the original's Add32 level).
inline int traffic_stage(int v) { return v <= 0 ? 0 : (v - 1) / traffic_step() + 1; }
// The completed stages (MatchdaySetup's size step: the original's v / 0x55; 255 is stage 4).
inline int traffic_full_stages(int v) {
if (!four_traffic_stages()) return v / 0x55;
return v >= 255 ? 4 : v / 64;
}
// Whether the building firm offers another stage.
inline bool traffic_buildable(int v) { return v < (four_traffic_stages() ? 3 * 64 + 1 : 0xab); }
// The condition byte after a finished build: the next full stage.
inline uint8_t traffic_after_build(int v) {
const int step = traffic_step();
return uint8_t(std::min(255, (v == 0 ? 1 : (v - 1) / step + 2) * step));
}
// The original's value of a stage boundary (the ageing message at each boundary).
inline bool traffic_stage_boundary(int v) { return v % traffic_step() == 0; }
// A condition byte of the original's scale (start tables, older Modern saves) in this world's scale.
inline uint8_t traffic_from_original(int v) {
if (!four_traffic_stages() || v == 0) return uint8_t(v);
return uint8_t(std::min(255, ((v - 1) / 0x55 + 1) * 64));
}
} // namespace bmh::modern
+4 -3
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "modern/game/traffic.hpp"
#include "modern/game/modern_state.hpp"
#include "modern/game/weekly.hpp"
#include "modern/game/club_player_detail.hpp"
@@ -171,7 +172,7 @@ int facility_rating(ModernState& g, int manager, int* second, WatcomRandom* rand
const uint8_t v = rec.b(size_t(i));
if (v == 0) continue;
int level;
if (i < 0xe || i == 0x10 || i == 0x11) level = i == 0 ? (v - 1) / 0x55 + 1 : 1;
if (i < 0xe || i == 0x10 || i == 0x11) level = i == 0 ? traffic_stage(v) : 1;
else level = rec.b(size_t(i) + 0x2e) & 7;
sum += (level & 0xFF) * kFacility[i * 5];
}
@@ -365,7 +366,7 @@ void facility_ageing(ModernState& g, int manager, GameRandom& game, WatcomRandom
if (weeks == 0 && rec.b(size_t(i)) != 0 && rec.b(0x1e + size_t(i)) == 0) {
uint8_t& v = rec.b(size_t(i));
v--;
if ((i == 0 && v % 0x55 == 0) || rec.b(0x1e + size_t(i)) + v == 0) {
if ((i == 0 && traffic_stage_boundary(v)) || rec.b(0x1e + size_t(i)) + v == 0) {
if (i < 0xe) {
message = true;
} else if (i < 0x16) {
@@ -388,7 +389,7 @@ void facility_ageing(ModernState& g, int manager, GameRandom& game, WatcomRandom
uint8_t& build = rec.b(0x1e + size_t(i));
if (build != 0 && --build == 0) {
uint8_t& v = rec.b(size_t(i));
if (i == 0) v = uint8_t((v == 0 ? 1 : (v - 1) / 0x55 + 2) * 0x55);
if (i == 0) v = traffic_after_build(v);
else v = uint8_t(rand.range(kFacility[i * 5 + 2], kFacility[i * 5 + 3]) << 2);
if (i > 0xd) {
rec.b(0x2e + size_t(i)) = uint8_t((rec.b(0x2e + size_t(i)) >> 4) & 7);
+48
View File
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-3.0-only
// The traffic access stages (modern/game/traffic.hpp): the original's three in steps of 0x55,
// a Modern world's four in steps of 64, and the conversion of the original's scale.
#include <cstdio>
#include "game/world_layout.hpp"
#include "modern/game/traffic.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;
}
}
} // namespace
int main() {
// Classic: 0 -> 85 -> 170 -> 255, a build is offered below 0xab
set_world_layout(classic_world_layout());
check(traffic_after_build(0) == 85 && traffic_after_build(85) == 170 && traffic_after_build(170) == 255, "classic builds");
check(traffic_buildable(170) && !traffic_buildable(255), "classic offer limit");
check(traffic_stage(85) == 1 && traffic_stage(170) == 2 && traffic_stage(255) == 3 && traffic_stage(84) == 1, "classic stages");
check(traffic_full_stages(255) == 3 && traffic_full_stages(169) == 1, "classic size steps");
check(traffic_from_original(170) == 170, "classic keeps its scale");
// a Modern world: 0 -> 64 -> 128 -> 192 -> 255, a build is offered below 193
WorldLayout modern = classic_world_layout();
modern.traffic_stages = 4;
set_world_layout(modern);
check(traffic_after_build(0) == 64 && traffic_after_build(64) == 128 && traffic_after_build(128) == 192 &&
traffic_after_build(192) == 255, "four builds");
check(traffic_buildable(192) && !traffic_buildable(255), "fourth stage offered, then no more");
check(traffic_stage(64) == 1 && traffic_stage(128) == 2 && traffic_stage(192) == 3 && traffic_stage(255) == 4, "four stages");
check(traffic_stage(63) == 1 && traffic_stage(191) == 3, "aged values keep their stage");
check(traffic_full_stages(255) == 4 && traffic_full_stages(192) == 3 && traffic_full_stages(191) == 2, "size steps");
check(traffic_stage_boundary(128) && !traffic_stage_boundary(127), "ageing message at a stage boundary");
check(traffic_from_original(85) == 64 && traffic_from_original(170) == 128 && traffic_from_original(255) == 192 &&
traffic_from_original(0) == 0 && traffic_from_original(150) == 128, "the original's stages in the new scale");
set_world_layout(classic_world_layout());
if (failures == 0) std::printf("modern traffic tests passed\n");
return failures == 0 ? 0 : 1;
}