From bd20960f90387116fb155d488b89ffc7f04498a0 Mon Sep 17 00:00:00 2001 From: Weyoune Date: Sat, 14 Nov 2026 12:01:17 +0100 Subject: [PATCH] Offer only the tactics the match engine reads; suggest a change after an own injury In a live match the tactics board shows the attitude and the commitment with what they do; the play-pattern items have no effect on a match and are not offered there. When an own starter is injured the match stops and the strongest bench player of his position is offered as the change. Co-Authored-By: Claude Fable 5.2 --- src/modern/ui/engine_live.cpp | 2 ++ src/modern/ui/live_controls.inc | 36 ++++++++++++++++++++++++++++++++- src/modern/ui/live_screens.inc | 5 +++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/modern/ui/engine_live.cpp b/src/modern/ui/engine_live.cpp index 049b223..1b77c52 100644 --- a/src/modern/ui/engine_live.cpp +++ b/src/modern/ui/engine_live.cpp @@ -128,6 +128,7 @@ Json engine_live_fixture(const Json &recording, const Json &bundle) { const auto &p = *at->second; rows.push_back({{"id", id}, {"name", p.at("player").at("name")}, {"slot", rows.size()}, {"strength", metric(p, "strength")}, {"condition", metric(p, "condition")}, + {"position", p.at("player").value("positions", Json::array()).empty() ? Json() : p.at("player").at("positions").front()}, {"caps", nullptr}, {"international_goals", nullptr}}); }; for (const auto &id : order) add(id); @@ -260,6 +261,7 @@ Json engine_live_roster(const Json &bundle) { const auto &p = *at->second; rows.push_back({{"id", id}, {"name", p.at("player").at("name")}, {"slot", rows.size()}, {"strength", metric(p, "strength")}, {"condition", metric(p, "condition")}, + {"position", p.at("player").value("positions", Json::array()).empty() ? Json() : p.at("player").at("positions").front()}, {"caps", nullptr}, {"international_goals", nullptr}}); }; for (const auto &id : order) add(id); diff --git a/src/modern/ui/live_controls.inc b/src/modern/ui/live_controls.inc index c5c9abf..7a0e36e 100644 --- a/src/modern/ui/live_controls.inc +++ b/src/modern/ui/live_controls.inc @@ -148,7 +148,41 @@ void App::engine_live_poll() { if (standing) { if (accepted || kind != "live.step") { const auto fixture = engine_live_progress(live_.fixture(), state, engine_data_, engine_live_roster_); - if (fixture.value("ok", false)) live_.follow(fixture); + if (fixture.value("ok", false)) { + std::set seen; + for (const auto &e : live_.fixture().at("frames").back().at("events")) seen.insert(e.at("id").get()); + live_.follow(fixture); + // An own starter is injured: the match stops and the nearest change is offered - the + // strongest bench player of his position, else the strongest on the bench. + try { + const auto owner = live_owner(); + const auto &match = live_match_by_id(live_.fixture().at("matches"), owner.at("match_id")); + const std::string own_side = match.at("home").at("id") == owner.at("team").at("id") ? "home" : "away"; + for (const auto &e : live_.fixture().at("frames").back().at("events")) { + if (seen.contains(e.at("id").get()) || e.value("kind", std::string()) != "injury" || + e.at("match_id") != match.at("id") || e.at("side") != own_side || !e.at("player").is_object() || !live_dialog_.empty()) continue; + const std::string hurt = e.at("player").value("id", std::string()); + size_t out = engine_live_roster_.size(); + for (size_t i = 0; i < engine_live_roster_.size() && i < 11; ++i) if (engine_live_roster_[i].at("id") == hurt) out = i; + if (out >= 11) continue; + int best = -1, best_same = -1; + const auto strength = [&](size_t i) { const auto &v = engine_live_roster_[i].at("strength"); return v.is_number_integer() ? v.get() : 0; }; + for (size_t i = 11; i < engine_live_roster_.size() && i < 16; ++i) { + if (best < 0 || strength(i) > strength(size_t(best))) best = int(i); + if (engine_live_roster_[i].value("position", Json()) == engine_live_roster_[out].value("position", Json()) && + (best_same < 0 || strength(i) > strength(size_t(best_same)))) best_same = int(i); + } + const int in = best_same >= 0 ? best_same : best; + if (in < 0) continue; + live_resume_speed_ = live_.speed(); live_.speed(0); + live_dialog_ = "lineup"; live_dialog_draft_ = Json::object(); + live_out_ = hurt; live_in_ = engine_live_roster_[size_t(in)].at("id").get(); + live_feedback_ = e.at("player").value("name", std::string("Ein Spieler")) + " ist verletzt."; + std::fprintf(stderr, "live: substitution offered after an injury: %s for %s%c", live_in_.c_str(), live_out_.c_str(), char(10)); + focus_after_render_ = "live-dialog-apply"; + } + } catch (const std::exception &) {} + } } else { live_.speed(0); live_feedback_ = "Der Spieltag steht: " + response.value("code", std::string("live_step_refused")); diff --git a/src/modern/ui/live_screens.inc b/src/modern/ui/live_screens.inc index b21216c..32ed8cb 100644 --- a/src/modern/ui/live_screens.inc +++ b/src/modern/ui/live_screens.inc @@ -112,9 +112,13 @@ std::string App::live_detail(const Json &owner, const Json &frame) { } if (live_tab_ == "tactics" && live_.running() && engine_live_tactics_.size() == 8) { std::string out = "

" + live_text("Taktik in diesem Spiel") + "

"; + // the match engine reads the attitude (item 0) and the commitment (item 7); the play + // patterns between them have no effect on a match and are not offered here for (size_t i = 0; i < engine_live_tactics_.size(); ++i) + if (i == 0 || i == 7) out += "
" + live_text(engine_live_tactics_[i].at("label").get()) + live_text(i == 0 && engine_live_assistant_ ? std::string("Assistent passt an") : live_tactic_value(i, engine_live_tactics_[i].at("value").get(), engine_live_tactics_[i].at("max").get())) + "
"; + out += "

" + live_text("Offensiver heißt mehr eigene Chancen und mehr Chancen für den Gegner. Mehr Einsatz bringt Druck nach vorn, aber auch mehr Karten und Verletzungen.") + "

"; return out + btn("live-intervene-tactics", "Taktik ändern", "", "id=\"live-tactics-edit\"") + "
"; } if (live_tab_ == "tactics" && recorded) @@ -177,6 +181,7 @@ std::string App::live_dialog_markup(const Json &owner) { const bool engine_board = live_.running() && engine_live_tactics_.size() == 8; const auto &values = engine_board ? live_dialog_draft_.at("values") : live_dialog_draft_.at("tactics").at("values"); for (size_t i = 0; i < names.size(); ++i) + if (!engine_board || i == 0 || i == 7) body += "
" + live_text(engine_board ? engine_live_tactics_[i].at("label").get() : std::string(names[i])) + btn("live-tactic-cycle", engine_board ? live_tactic_value(i, values[i].get(), engine_live_tactics_[i].at("max").get()) : "Wert " + std::to_string(values[i].get()), "", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"") + "
"; } body += "
" + btn("live-dialog-cancel", "Abbrechen", "", "id=\"live-dialog-cancel\"") +