Bind league tables strengths and live profiles to engine reads (by Codex)
This commit is contained in:
1 parent
f9e8719b2d
commit
1c35698dbe
24 files changed
+463
-20
No files matched your search
@@ -314,6 +314,61 @@ J squad_data(const ModernState& g, const UiContext& c, int team, const std::stri
|
||||
return O{{"kind", "squad"}, {"team", team_ref(g, team, today)}, {"players", std::move(players)}};
|
||||
}
|
||||
|
||||
J report_league(const ModernState& g, int league, int own) {
|
||||
const int first=league_first_team(league), count=kLeagueSizes[league];
|
||||
const World* world=current_world();
|
||||
const WorldClub* club=world?world->club(team_id(g,first)):nullptr;
|
||||
A members;
|
||||
for(int i=0;i<count;++i)members.push_back(team_id(g,first+i));
|
||||
return O{{"id",size_t(league)<g.world_league_id.size()&&!g.world_league_id[size_t(league)].empty()?g.world_league_id[size_t(league)]:"league:"+std::to_string(league)},
|
||||
{"name",size_t(league)<g.world_league_name.size()&&!g.world_league_name[size_t(league)].empty()?g.world_league_name[size_t(league)]:"Liga "+std::to_string(league+1)},
|
||||
{"nationId",club&&!club->nation.empty()?J(club->nation):J(nullptr)},
|
||||
{"members",std::move(members)},{"clubCount",count},{"matchdays",league_matchdays(league)},
|
||||
{"played",size_t(league)<g.league_rounds.size()?int(g.league_rounds[size_t(league)]):0},
|
||||
{"own",own>=first&&own<first+count}};
|
||||
}
|
||||
|
||||
J league_report_data(const ModernState& g,int league,int filter,const std::string& today) {
|
||||
const int first=league_first_team(league), count=kLeagueSizes[league], half=count-1;
|
||||
const int played=size_t(league)<g.league_rounds.size()?g.league_rounds[size_t(league)]:0;
|
||||
const int from=filter==2?half:0, until=filter==1?std::min(played,half):played;
|
||||
const int flags=4|(filter==3?1:filter==4?2:3);
|
||||
auto table=compute_league_table(g,league,from,until,flags,1);
|
||||
bool any=false;for(int i=0;i<count;++i)any|=table.games(i)>0;
|
||||
if(!any)sort_table(table,0); // A not-yet-played half still has unique Source ranks.
|
||||
A rows,strengths;
|
||||
for(int i=0;i<count;++i) {
|
||||
const int team=first+i;
|
||||
std::string form;int form_points=0;
|
||||
for(int n=0;n<8;++n) {
|
||||
const int code=int(table.form[size_t(i)]>>(3*n)&7);
|
||||
if(!code)break;
|
||||
const int outcome=code&3;const char symbol=outcome==3?'S':outcome==2?'U':outcome==1?'N':'-';
|
||||
form.insert(form.begin(),symbol);form_points+=outcome==3?3:outcome==2?1:0;
|
||||
}
|
||||
const int games=table.games(i),wins=table.wins[size_t(i)],loss=table.defeats[size_t(i)];
|
||||
rows.push_back(O{{"team",team_ref(g,team,today)},{"original",i},{"rank",table.rank(i)+1},{"played",games},{"wins",wins},
|
||||
{"draw",std::max(0,games-wins-loss)},{"loss",loss},{"gf",int(table.goals_for[size_t(i)])},{"ga",int(table.goals_against[size_t(i)])},
|
||||
{"diff",int(table.goals_for[size_t(i)])-int(table.goals_against[size_t(i)])},{"points",int(table.points[size_t(i)])},{"form",form_points},{"form_text",form}});
|
||||
int positions[4]={};
|
||||
if(fields_players(g,team)) {
|
||||
const auto range=squad_range(team);
|
||||
for(size_t s=range.first;s<range.first+range.count&&s<g.squad_slots.size();++s) {
|
||||
const int player=g.squad_slots[s]&0xfff;
|
||||
if(player!=0xfff&&size_t(player)<g.players.size())++positions[g.players[size_t(player)].position()];
|
||||
}
|
||||
}
|
||||
O row{{"team",team_ref(g,team,today)},{"original",i},{"basis","squad"}};
|
||||
const char* keys[4]={"keeper","defence","midfield","attack"};
|
||||
int total=0;
|
||||
for(int p=0;p<4;++p){total+=positions[p];row[keys[p]]=positions[p]?J(team_average(g,team,uint16_t(0xf|(0x10<<p))).value):J(nullptr);}
|
||||
row["strength"]=total?J(team_average(g,team,0xff).value):J(nullptr);
|
||||
strengths.push_back(std::move(row));
|
||||
}
|
||||
return O{{"kind","league-report"},{"leagueId",size_t(league)<g.world_league_id.size()&&!g.world_league_id[size_t(league)].empty()?g.world_league_id[size_t(league)]:"league:"+std::to_string(league)},
|
||||
{"filter",filter},{"table",std::move(rows)},{"strengths",std::move(strengths)},{"zones",nullptr}};
|
||||
}
|
||||
|
||||
// The training camps (docs/new_engine/trainingslager.md): catalogue, the price for the own
|
||||
// squad (base price + 5000 per player, no random draw: a binding quote), focus and bookings.
|
||||
J camps_data(const ModernState& g, const UiContext& c, const std::string& revision) {
|
||||
@@ -428,6 +483,17 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req
|
||||
if (kind == "session") return snapshot(request_id, std::move(m), session_data(g, c));
|
||||
if (kind == "desktop") return snapshot(request_id, std::move(m), desktop_data(g, c, today));
|
||||
if (kind == "camps") return snapshot(request_id, std::move(m), camps_data(g, c, std::to_string(c.state_revision)));
|
||||
if(kind=="report-index") {
|
||||
A leagues;for(int l=0;l<kLeagueCount;++l)leagues.push_back(report_league(g,l,team_of(g,c.manager)));
|
||||
return snapshot(request_id,std::move(m),O{{"kind","report-index"},{"leagues",std::move(leagues)}});
|
||||
}
|
||||
if(kind=="league-report") {
|
||||
const std::string id=text_field(request,"leagueId");int league=-1;
|
||||
for(int l=0;l<kLeagueCount;++l)if(*std::get<O>(report_league(g,l,-1).value).at("id").string()==id){league=l;break;}
|
||||
const auto* f=field(request,"filter");const auto* value=f?f->integer():nullptr;
|
||||
if(league<0||!value||*value<0||*value>4)return failure(request_id,"invalid_report_request","Liga oder Tabellenfilter ist nicht verfügbar.",c.state_revision);
|
||||
return snapshot(request_id,std::move(m),league_report_data(g,league,int(*value),today));
|
||||
}
|
||||
if (kind == "almanac") {
|
||||
const J* query = field(request, "query");
|
||||
if (!query || !query->object())
|
||||
|
||||
Reference in new issue
Block a user