Show the world's UTF-8 names in the Modern console
club_text/player_text replace the console's utf8(g.club_name(..)) and utf8(g.player_name(..)); in openbmh_modern_cli they give the world's names (players with first names), in openbmh_cli the engine's names as before. The Modern session resolves the matchday results with the world's club names. The live match keeps a pointer to the session state type, so the names are read from the full Modern state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ce79697b20
commit
3dbaea294a
11 files changed
+57
-31
No files matched your search
@@ -28,7 +28,7 @@ Auch der JSON-Modus (`--json`, Befehle `new`, `kickoff`, `save`, `load`, …) un
|
||||
## Grenzen
|
||||
|
||||
- Nur deutsche Vereine sind wählbar (0.3); die Zusatz-Reiter der Auswahl (Amateure) und Auslandsvereine werden abgelehnt.
|
||||
- Die Konsole zeigt die Namen der Engine (Großbuchstaben, Einzelbyte-Zeichensatz); UTF-8-Namen, Vornamen, Almanach und Spielstatistik liefert die Engine über `ModernSession::read` für die neue Oberfläche.
|
||||
- Namen: Meldungen, Ergebnisse, Spielerlisten und Angebote zeigen die UTF-8-Namen der Welt (Spieler mit Vornamen; `club_text`/`player_text` in der Konsole). Paarungen, Ligatabelle und weitere Ansichten aus den Projektionen der Classic-Oberfläche zeigen noch die Engine-Namen (Großbuchstaben). Almanach und Spielstatistik liefert die Engine über `ModernSession::read` für die neue Oberfläche.
|
||||
- Spielstände sind Modern-Spielstände (`.obs`, nennen ihre Welt); sie laden nur mit derselben Welt.
|
||||
|
||||
## Technik
|
||||
|
||||
@@ -62,6 +62,26 @@ std::string utf8(std::string_view text) {
|
||||
return ui::original_to_utf8(text);
|
||||
}
|
||||
|
||||
std::string club_text(const GameState& g, int team) {
|
||||
#ifdef OPENBMH_MODERN_SESSION
|
||||
const auto& m = static_cast<const app::SessionState&>(g);
|
||||
if (team >= 0 && size_t(team) < m.world_club_name.size() && !m.world_club_name[size_t(team)].empty())
|
||||
return m.world_club_name[size_t(team)];
|
||||
#endif
|
||||
return utf8(g.club_name(team));
|
||||
}
|
||||
|
||||
std::string player_text(const GameState& g, int player) {
|
||||
#ifdef OPENBMH_MODERN_SESSION
|
||||
const auto& m = static_cast<const app::SessionState&>(g);
|
||||
if (player >= 0 && size_t(player) < m.player_last.size() && !m.player_last[size_t(player)].empty()) {
|
||||
const std::string& first = size_t(player) < m.player_first.size() ? m.player_first[size_t(player)] : std::string();
|
||||
return first.empty() ? m.player_last[size_t(player)] : first + " " + m.player_last[size_t(player)];
|
||||
}
|
||||
#endif
|
||||
return utf8(g.player_name(player));
|
||||
}
|
||||
|
||||
std::string fold(std::string s) {
|
||||
s = lower(std::move(s));
|
||||
// UTF-8 Ä Ö Ü (C3 84, C3 96, C3 9C) -> ä ö ü (C3 A4, C3 B6, C3 BC)
|
||||
|
||||
@@ -54,6 +54,11 @@ std::string fold(std::string s);
|
||||
// ("M]NCHEN"), some already convert (cup draw names, results). The original encoding has no
|
||||
// bytes above 0x7f, so a string with such bytes is taken as UTF-8 already.
|
||||
std::string utf8(std::string_view text);
|
||||
// The UTF-8 name of a club / player for the console. Classic: the engine's name (utf8 above).
|
||||
// Modern (openbmh_modern_cli): the world's names, players with first name, when the world has
|
||||
// them. `g` must be the session's state (app::SessionState), not a sliced copy.
|
||||
std::string club_text(const GameState& g, int team);
|
||||
std::string player_text(const GameState& g, int player);
|
||||
// "2027-07-01" (the concept's date type)
|
||||
std::string date_text(int day, int month, int year);
|
||||
// Money as whole euros without separators (01-grundlagen 2.1)
|
||||
|
||||
@@ -64,7 +64,7 @@ void Console::register_friendly_commands() {
|
||||
if (q.status != FriendlyQuoteStatus::quoted) fail("E_RULE", "no friendly possible against this club");
|
||||
friendly_quote_ = q;
|
||||
const GameState& g = session_->state();
|
||||
emit('+', utf8(g.club_name(q.home_team)) + " - " + utf8(g.club_name(q.away_team)) + ", costs " + money(q.cost) +
|
||||
emit('+', club_text(g, q.home_team) + " - " + club_text(g, q.away_team) + ", costs " + money(q.cost) +
|
||||
(q.payer_manager >= 0 ? " (paid by player " + std::to_string(q.payer_manager + 1) + ")" : "") +
|
||||
(q.opponent_manager >= 0 ? ", player " + std::to_string(q.opponent_manager + 1) + " must agree" : "") +
|
||||
"; ListFreeDates, SetFriendlyDate(YYYY-MM-DD)");
|
||||
|
||||
@@ -108,7 +108,7 @@ void Console::register_info_commands() {
|
||||
if (found.empty()) fail("E_BAD_ARGUMENT", "no club named \"" + reference + "\" in the leagues");
|
||||
std::string candidates;
|
||||
for (size_t i = 0; i < found.size() && i < 8; ++i)
|
||||
candidates += (i ? ", " : "") + utf8(session_->state().club_name(found[i])) + " = club:" + std::to_string(found[i]);
|
||||
candidates += (i ? ", " : "") + club_text(session_->state(), found[i]) + " = club:" + std::to_string(found[i]);
|
||||
fail("E_AMBIGUOUS", "\"" + reference + "\" fits several clubs: " + candidates);
|
||||
};
|
||||
auto show_team = [this] {
|
||||
|
||||
@@ -66,7 +66,7 @@ struct Console::EngineRun {
|
||||
int minute = 0;
|
||||
MatchEngine* engine = nullptr;
|
||||
std::vector<MatchGroup>* groups = nullptr;
|
||||
GameState* state = nullptr;
|
||||
app::SessionState* state = nullptr; // the session state (Modern: ModernState)
|
||||
bool intro_shown = false;
|
||||
|
||||
// the clock: minutes to run before the next pause, or a minute to run to
|
||||
@@ -216,7 +216,7 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
|
||||
const int player = int(state.squad_slots[squad.first + size_t(row)] & 0x0fff);
|
||||
if (player == 0x0fff || size_t(player) >= state.players.size())
|
||||
throw std::runtime_error("contract expiry: missing player");
|
||||
const std::string player_name = utf8(state.player_name(player));
|
||||
const std::string player_name = player_text(state, player);
|
||||
const app::SessionState before = state; // the whole state (Modern carries more)
|
||||
const WatcomRandom before_random = random;
|
||||
|
||||
@@ -314,14 +314,14 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
|
||||
if (!notice.empty()) run->notices.push_back(notice);
|
||||
return -1;
|
||||
}
|
||||
std::string text = (notice.empty() ? std::string() : notice + " ") + "Offers for " + utf8(g.player_name(view.player)) + ":";
|
||||
std::string text = (notice.empty() ? std::string() : notice + " ") + "Offers for " + player_text(g, view.player) + ":";
|
||||
std::vector<std::string> options;
|
||||
std::vector<int> slots;
|
||||
for (const auto& o : view.offers) {
|
||||
if (!o.present) continue;
|
||||
options.push_back("Accept" + std::to_string(options.size() + 1));
|
||||
slots.push_back(o.bid_index);
|
||||
text += " " + options.back() + " = " + (o.loan ? "loan to " : "sell to ") + utf8(g.club_name(o.buyer)) + " for " + std::to_string(o.fee) + " (" +
|
||||
text += " " + options.back() + " = " + (o.loan ? "loan to " : "sell to ") + club_text(g, o.buyer) + " for " + std::to_string(o.fee) + " (" +
|
||||
std::to_string(o.monthly_salary) + " monthly" + (o.loan ? ", loan" : "") + ");";
|
||||
}
|
||||
options.push_back("Decline");
|
||||
@@ -335,7 +335,7 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
|
||||
// relay it at the next thread handoff instead of silently dropping it.
|
||||
session_->set_transfer_decision_observer([this, run](const TransferDecisionEvent& event) {
|
||||
const auto& g = session_->state();
|
||||
const std::string player = utf8(g.player_name(event.offers.player));
|
||||
const std::string player = player_text(g, event.offers.player);
|
||||
if (event.kind == TransferDecisionEventKind::last_week) {
|
||||
run->notices.push_back(player + utf8(message_text(g, event.result_text_address)));
|
||||
return;
|
||||
@@ -349,7 +349,7 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
|
||||
for (const auto& offer : event.offers.offers) {
|
||||
if (!offer.present) continue;
|
||||
const bool accepted = event.accepted && offer.bid_index == event.selected_bid_index;
|
||||
run->notices.push_back(player + ": " + utf8(g.club_name(offer.buyer)) + ": " +
|
||||
run->notices.push_back(player + ": " + club_text(g, offer.buyer) + ": " +
|
||||
utf8(message_text(g, accepted ? ::bmh::layout::IncomingTransfer_RenderAtElapsed_TextPointer3 : ::bmh::layout::IncomingTransfer_RenderAtElapsed_TextPointer4)));
|
||||
if (accepted) break;
|
||||
}
|
||||
@@ -360,10 +360,10 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
|
||||
for (const auto& offer : event.offers.offers) {
|
||||
if (!offer.present || (event.accepted && offer.bid_index == event.selected_bid_index)) continue;
|
||||
if (g.manager_of(offer.buyer) < 0) continue;
|
||||
std::string line = player + ": the bid of " + utf8(g.club_name(offer.buyer)) + " was not accepted";
|
||||
std::string line = player + ": the bid of " + club_text(g, offer.buyer) + " was not accepted";
|
||||
for (const auto& winner : event.offers.offers)
|
||||
if (event.accepted && winner.present && winner.bid_index == event.selected_bid_index)
|
||||
line += " - he signs for " + utf8(g.club_name(winner.buyer));
|
||||
line += " - he signs for " + club_text(g, winner.buyer);
|
||||
run->notices.push_back(line);
|
||||
}
|
||||
});
|
||||
@@ -397,15 +397,15 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
|
||||
}
|
||||
static const char* const kGroups[4] = {"1st division", "2nd division", "3rd divisions", "4th division"};
|
||||
std::string up, down;
|
||||
for (size_t i = 0; i < e.count && i < e.promoted.size(); ++i) up += (up.empty() ? "" : ", ") + utf8(g.club_name(e.promoted[i]));
|
||||
for (size_t i = 0; i < e.count && i < e.relegated.size(); ++i) down += (down.empty() ? "" : ", ") + utf8(g.club_name(e.relegated[i]));
|
||||
for (size_t i = 0; i < e.count && i < e.promoted.size(); ++i) up += (up.empty() ? "" : ", ") + club_text(g, e.promoted[i]);
|
||||
for (size_t i = 0; i < e.count && i < e.relegated.size(); ++i) down += (down.empty() ? "" : ", ") + club_text(g, e.relegated[i]);
|
||||
run->notices.push_back(std::string(kGroups[std::clamp(e.group, 0, 3)]) + ": relegated " + down + "; promoted " + up);
|
||||
});
|
||||
session_->set_season_cup_draw([run](const GameState& g, const SeasonCupDrawEvent& e) {
|
||||
if (e.phase != SeasonCupDrawPhase::draw) return;
|
||||
std::string pairs;
|
||||
for (size_t i = 0; i + 1 < e.participants.size() && i + 1 < e.count; i += 2)
|
||||
pairs += (pairs.empty() ? "" : "; ") + utf8(g.club_name(e.participants[i])) + " - " + utf8(g.club_name(e.participants[i + 1]));
|
||||
pairs += (pairs.empty() ? "" : "; ") + club_text(g, e.participants[i]) + " - " + club_text(g, e.participants[i + 1]);
|
||||
run->notices.push_back("cup draw (competition " + std::to_string(e.competition) + ", round " + std::to_string(e.round + 1) + "): " + pairs);
|
||||
});
|
||||
session_->set_live_minute([run](int minute, MatchEngine& engine, std::vector<MatchGroup>& groups, GameState& g) {
|
||||
@@ -430,7 +430,7 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
|
||||
run->minute = minute;
|
||||
run->engine = &engine;
|
||||
run->groups = &groups;
|
||||
run->state = &g;
|
||||
run->state = &static_cast<app::SessionState&>(g); // the session state behind the hook
|
||||
run->engine_turn = false;
|
||||
run->cv.notify_all();
|
||||
run->cv.wait(lock, [run] { return run->engine_turn; });
|
||||
@@ -675,8 +675,8 @@ void Console::show_match_pause() {
|
||||
}
|
||||
std::string text = utf8(e.text);
|
||||
if (e.what == Show::Substitution && run->state && e.player >= 0 && e.player < 0xfff && e.other >= 0 && e.other < 0xfff)
|
||||
text = utf8(run->state->player_name(e.other)) + " for " + utf8(run->state->player_name(e.player));
|
||||
if (text.empty() && run->state && e.player >= 0 && e.player < 0xfff) text = utf8(run->state->player_name(e.player));
|
||||
text = player_text(*run->state, e.other) + " for " + player_text(*run->state, e.player);
|
||||
if (text.empty() && run->state && e.player >= 0 && e.player < 0xfff) text = player_text(*run->state, e.player);
|
||||
Json::Object data{{"kind", int(e.what)}, {"group", int(e.group)}, {"match", int(e.match)}, {"side", int(e.side)},
|
||||
{"team", int(e.team)}, {"player", int(e.player)}, {"other", int(e.other)}};
|
||||
emit('~', std::to_string(e.minute) + "' [match " + std::to_string(e.group) + "." + std::to_string(e.match) + "] " + what + text,
|
||||
@@ -747,7 +747,7 @@ void Console::register_match_commands() {
|
||||
for (size_t row = 0; row < range.count; ++row) {
|
||||
const uint16_t slot = run.state->squad_slots.at(range.first + row);
|
||||
if ((slot & 0x0fff) == 0x0fff || !(slot & 0xc000)) continue;
|
||||
refs.push_back({int(row), slot & 0x0fff, utf8(run.state->player_name(slot & 0x0fff))});
|
||||
refs.push_back({int(row), slot & 0x0fff, player_text(*run.state, slot & 0x0fff)});
|
||||
}
|
||||
return refs;
|
||||
};
|
||||
@@ -790,7 +790,7 @@ void Console::register_match_commands() {
|
||||
// the SDL live tactics screen does).
|
||||
auto live_tactics = [this, paused](int manager) {
|
||||
EngineRun& run = paused();
|
||||
GameState view = *run.state;
|
||||
app::SessionState view = *run.state;
|
||||
if (view.memory.has(::bmh::layout::ActiveManager)) view.memory.set8(::bmh::layout::ActiveManager, uint8_t(manager));
|
||||
return ui::tactics_from_game(view, exe_, revision_);
|
||||
};
|
||||
@@ -861,7 +861,7 @@ void Console::register_match_commands() {
|
||||
require_engine(false, "live position", why);
|
||||
};
|
||||
// the projection of the paused match for the manager (as the SDL live line-up)
|
||||
GameState view = *run.state;
|
||||
app::SessionState view = *run.state;
|
||||
if (view.memory.has(::bmh::layout::ActiveManager)) view.memory.set8(::bmh::layout::ActiveManager, uint8_t(manager));
|
||||
ui::PreparationState p = ui::preparation_from_game(view, exe_, revision_);
|
||||
p.lineup.in_match = true;
|
||||
|
||||
@@ -41,7 +41,7 @@ void Console::register_reschedule_commands() {
|
||||
const GameState& g = session_->state();
|
||||
std::vector<std::vector<std::string>> rows;
|
||||
for (const LeagueMatchRef& m : reschedulable_matches(g, manager()))
|
||||
rows.push_back({day_text(m.day), std::to_string(m.round + 1), utf8(g.club_name(m.away))});
|
||||
rows.push_back({day_text(m.day), std::to_string(m.round + 1), club_text(g, m.away)});
|
||||
if (rows.empty()) emit('i', "no home league match can be moved");
|
||||
emit_table({"Date", "Matchday", "Opponent"}, rows);
|
||||
});
|
||||
@@ -62,7 +62,7 @@ void Console::register_reschedule_commands() {
|
||||
const GameState& g = session_->state();
|
||||
std::vector<std::vector<std::string>> rows;
|
||||
for (const LeagueMatchRef& m : moved_matches(g, manager()))
|
||||
rows.push_back({day_text(m.day), std::to_string(m.round + 1), utf8(g.club_name(m.home)), utf8(g.club_name(m.away))});
|
||||
rows.push_back({day_text(m.day), std::to_string(m.round + 1), club_text(g, m.home), club_text(g, m.away)});
|
||||
if (rows.empty()) emit('i', "no moved match");
|
||||
emit_table({"Date", "Matchday", "Home", "Away"}, rows);
|
||||
});
|
||||
@@ -72,7 +72,7 @@ void Console::register_reschedule_commands() {
|
||||
for (const LeagueMatchRef& m : moved_matches(g, manager())) {
|
||||
if (day_text(m.day) != v.text("game")) continue;
|
||||
app::RescheduleActions(*session_).undo_console(manager(), m.day, revision_);
|
||||
emit('+', utf8(g.club_name(m.home)) + " - " + utf8(g.club_name(m.away)) + " back on matchday " + std::to_string(m.round + 1));
|
||||
emit('+', club_text(g, m.home) + " - " + club_text(g, m.away) + " back on matchday " + std::to_string(m.round + 1));
|
||||
return;
|
||||
}
|
||||
fail("E_RULE", "no moved match on " + v.text("game") + " (ListMovedGames)");
|
||||
@@ -92,7 +92,7 @@ void Console::register_reschedule_commands() {
|
||||
default: fail("E_RULE", "the match cannot be moved");
|
||||
}
|
||||
const GameState& g = session_->state();
|
||||
emit('+', utf8(g.club_name(m.home)) + " - " + utf8(g.club_name(m.away)) + " moved from " + day_text(m.day) + " to " +
|
||||
emit('+', club_text(g, m.home) + " - " + club_text(g, m.away) + " moved from " + day_text(m.day) + " to " +
|
||||
day_text(target));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ void Console::install_hooks() {
|
||||
} else if (event.phase == SeasonCupDrawPhase::overview && view.group_stage) {
|
||||
std::vector<std::vector<std::string>> rows;
|
||||
for (const auto& r : view.group_rows)
|
||||
rows.push_back({std::to_string(r.rank), utf8(state.club_name(r.runtime_id))});
|
||||
rows.push_back({std::to_string(r.rank), club_text(state, r.runtime_id)});
|
||||
const std::string caption = title + (view.group_caption.empty() ? "" : " " + utf8(view.group_caption));
|
||||
pending_info_.push_back([this, caption, rows] {
|
||||
set_window("Info.CupDraw", 0);
|
||||
|
||||
@@ -231,7 +231,7 @@ void Console::register_advice_commands() {
|
||||
std::sort(strengths.rbegin(), strengths.rend());
|
||||
int sum = 0, n = 0;
|
||||
for (; n < 11 && n < int(strengths.size()); ++n) sum += strengths[size_t(n)];
|
||||
rows.push_back({std::to_string(m + 1), utf8(g.club_name(team)), league_name, rank, points, games, std::to_string(balance),
|
||||
rows.push_back({std::to_string(m + 1), club_text(g, team), league_name, rank, points, games, std::to_string(balance),
|
||||
n ? std::to_string(sum / n) : "-"});
|
||||
}
|
||||
emit_table({"Manager", "Club", "League", "Place", "Points", "Games", "Balance", "Best11"}, rows);
|
||||
|
||||
@@ -380,7 +380,7 @@ void Console::register_transfer_commands() {
|
||||
const GameState& g = services.state();
|
||||
const Player& p = g.players.at(size_t(selection.player_id));
|
||||
emit_table({"Player", "Value"},
|
||||
{{"name", utf8(g.player_name(selection.player_id))},
|
||||
{{"name", player_text(g, selection.player_id)},
|
||||
{"position", text(kPositionNames + p.position())},
|
||||
{"age", std::to_string(p.age())},
|
||||
{"condition", std::to_string(p.condition())},
|
||||
@@ -434,10 +434,10 @@ void Console::register_transfer_commands() {
|
||||
const int p = g.squad_slots.at(s) & 0xfff;
|
||||
if (p == 0xfff) continue;
|
||||
const Player& pl = g.players.at(size_t(p));
|
||||
rows.push_back({"id:" + std::to_string(p), utf8(g.player_name(p)), text(kPositionNames + pl.position()), std::to_string(pl.age()),
|
||||
rows.push_back({"id:" + std::to_string(p), player_text(g, p), text(kPositionNames + pl.position()), std::to_string(pl.age()),
|
||||
std::to_string(pl.strength(true))});
|
||||
}
|
||||
emit('i', utf8(g.club_name(team)));
|
||||
emit('i', club_text(g, team));
|
||||
emit_table({"Id", "Player", "Pos", "Age", "Str"}, rows);
|
||||
});
|
||||
add({"Transfer.Poach", "PoachPlayer", {player}, "the offer to a player of another club (decided at once)", true},
|
||||
|
||||
@@ -4468,8 +4468,9 @@ TurnAdvanceResult ModernSession::dispatch_kickoff(const ui::DeskRequest& request
|
||||
// transition. The result view must keep the identities of the played event.
|
||||
std::vector<std::string> names;
|
||||
names.reserve(g_.club_ids.size());
|
||||
for (size_t team = 0; team < g_.club_ids.size(); ++team)
|
||||
names.push_back(ui::original_to_utf8(g_.club_name(int(team))));
|
||||
for (size_t team = 0; team < g_.club_ids.size(); ++team) // a Modern world's UTF-8 names first
|
||||
names.push_back(team < g_.world_club_name.size() && !g_.world_club_name[team].empty()
|
||||
? g_.world_club_name[team] : ui::original_to_utf8(g_.club_name(int(team))));
|
||||
const bool had_results = turn_driver_.last_results.valid;
|
||||
const uint32_t previous_result_date = turn_driver_.last_results.date;
|
||||
const uint32_t previous_day = g_.date;
|
||||
|
||||
Reference in new issue
Block a user