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 <noreply@anthropic.com>
This commit is contained in:
1 parent
1732a2477b
commit
bd20960f90
3 files changed
+42
-1
No files matched your search
@@ -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<std::string> seen;
|
||||
for (const auto &e : live_.fixture().at("frames").back().at("events")) seen.insert(e.at("id").get<std::string>());
|
||||
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<std::string>()) || 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<int>() : 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<std::string>();
|
||||
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"));
|
||||
|
||||
Reference in new issue
Block a user