mirror of https://github.com/tstellar/bygfoot.git
Use cup history for self-referential cups
This commit is contained in:
parent
30d96e9952
commit
ac4d0fc546
24
src/cup.c
24
src/cup.c
|
@ -309,7 +309,7 @@ cup_get_choose_team_league_cup(const CupChooseTeam *ct,
|
|||
cup round. If necessary, teams are generated and stored in the teams
|
||||
array of the cup round. */
|
||||
void
|
||||
cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, gboolean preload)
|
||||
cup_get_team_pointers(Cup *cup, gint round, gboolean preload)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("cup_get_team_pointers\n");
|
||||
|
@ -333,7 +333,7 @@ cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, gboolean pr
|
|||
if(cup_choose_team_should_generate(choose_team))
|
||||
cup_load_choose_team_generate(cup, cup_round, choose_team);
|
||||
else
|
||||
cup_load_choose_team(cup, teams, teams_sorted, choose_team);
|
||||
cup_load_choose_team(cup, teams, choose_team);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, gboolean pr
|
|||
/** Get the pointers to the teams (already generated, in one of the leagues or cups)
|
||||
specified in the chooseteam. Add them to the 'teams' pointer array. */
|
||||
void
|
||||
cup_load_choose_team(Cup *cup, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct)
|
||||
cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("cup_load_choose_team\n");
|
||||
|
@ -376,7 +376,7 @@ cup_load_choose_team(Cup *cup, GPtrArray *teams, GPtrArray *teams_sorted, const
|
|||
if(cup_temp == NULL)
|
||||
cup_load_choose_team_from_league(cup, league, teams, ct);
|
||||
else
|
||||
cup_load_choose_team_from_cup(cup, cup_temp, teams, teams_sorted, ct);
|
||||
cup_load_choose_team_from_cup(cup, cup_temp, teams, ct);
|
||||
|
||||
if(debug > 80)
|
||||
for(i=debug_num;i<teams->len;i++)
|
||||
|
@ -384,7 +384,7 @@ cup_load_choose_team(Cup *cup, GPtrArray *teams, GPtrArray *teams_sorted, const
|
|||
}
|
||||
|
||||
void
|
||||
cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct)
|
||||
cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, const CupChooseTeam *ct)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("cup_load_choose_team_from_cup\n");
|
||||
|
@ -427,7 +427,7 @@ cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, G
|
|||
|
||||
if(number_of_teams != ct->number_of_teams) {
|
||||
if (ct->next)
|
||||
return cup_load_choose_team(cup, teams, teams_sorted, ct->next);
|
||||
return cup_load_choose_team(cup, teams, ct->next);
|
||||
|
||||
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
|
||||
"cup_load_choose_team_from_cup (2): not enough teams found in league 0 for chooseteam %s (%d; required: %d) in cup %s (group %d)\n",
|
||||
|
@ -439,7 +439,7 @@ cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, G
|
|||
{
|
||||
/* Self-referential cup or no? */
|
||||
cup_teams_sorted = (cup == cup_temp) ?
|
||||
teams_sorted :
|
||||
cup_get_last_season_results(cup) :
|
||||
cup_get_teams_sorted(cup_temp);
|
||||
|
||||
start = cup_choose_team_compute_start_idx(ct);
|
||||
|
@ -467,7 +467,7 @@ cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, G
|
|||
if(ct->number_of_teams != -1 &&
|
||||
number_of_teams != ct->number_of_teams) {
|
||||
if (ct->next)
|
||||
return cup_load_choose_team(cup, teams, teams_sorted, ct->next);
|
||||
return cup_load_choose_team(cup, teams, ct->next);
|
||||
if (ct->optional)
|
||||
return;
|
||||
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
|
||||
|
@ -1422,3 +1422,11 @@ query_cup_hidden(const Cup *cup)
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/** @return a GPtrArray with Team* sorted by their ranking in last seasons's
|
||||
* cup. */
|
||||
GPtrArray *
|
||||
cup_get_last_season_results(const Cup *cup)
|
||||
{
|
||||
return g_ptr_array_index(cup->history, cup->history->len - 1);
|
||||
}
|
||||
|
|
|
@ -47,13 +47,13 @@ void
|
|||
cup_reset(Cup *cup);
|
||||
|
||||
void
|
||||
cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, gboolean preload);
|
||||
cup_get_team_pointers(Cup *cup, gint round, gboolean preload);
|
||||
|
||||
void
|
||||
cup_load_choose_team_generate(Cup *cup, CupRound *cup_round, const CupChooseTeam *ct);
|
||||
|
||||
void
|
||||
cup_load_choose_team(Cup *cup, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct);
|
||||
cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct);
|
||||
|
||||
void
|
||||
cup_load_choose_team_from_league(Cup *cup, const League *league,
|
||||
|
@ -61,7 +61,7 @@ cup_load_choose_team_from_league(Cup *cup, const League *league,
|
|||
|
||||
void
|
||||
cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_team, GPtrArray *teams,
|
||||
GPtrArray *teams_sorted, const CupChooseTeam *ct);
|
||||
const CupChooseTeam *ct);
|
||||
|
||||
gint
|
||||
cup_get_first_week_of_cup_round(Cup *cup, gint cup_round, gboolean with_delay);
|
||||
|
@ -145,4 +145,7 @@ query_cup_self_referential(const Cup *cup);
|
|||
gboolean
|
||||
query_cup_hidden(const Cup *cup);
|
||||
|
||||
GPtrArray *
|
||||
cup_get_last_season_results(const Cup *cup);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -114,12 +114,6 @@ fixture_write_cup_fixtures(Cup *cup)
|
|||
#endif
|
||||
|
||||
gint i;
|
||||
GPtrArray *teams_sorted = NULL;
|
||||
|
||||
/* Store the order of teams in case the cup
|
||||
uses teams from its previous incarnation (previous season). */
|
||||
if(query_cup_self_referential(cup))
|
||||
teams_sorted = cup_get_teams_sorted(cup);
|
||||
|
||||
cup_reset(cup);
|
||||
|
||||
|
@ -129,10 +123,7 @@ fixture_write_cup_fixtures(Cup *cup)
|
|||
* the higher rounds first.
|
||||
*/
|
||||
for(i=cup->rounds->len - 1; i >=0;i--)
|
||||
cup_get_team_pointers(cup, i, teams_sorted, TRUE);
|
||||
|
||||
if(teams_sorted != NULL)
|
||||
g_ptr_array_free(teams_sorted, TRUE);
|
||||
cup_get_team_pointers(cup, i, TRUE);
|
||||
|
||||
if(g_array_index(cup->rounds, CupRound, 0).round_robin_number_of_groups > 0)
|
||||
fixture_write_cup_round_robin(
|
||||
|
@ -193,7 +184,7 @@ fixture_update(Cup *cup)
|
|||
}
|
||||
|
||||
new_round = &g_array_index(cup->rounds, CupRound, round + 1);
|
||||
cup_get_team_pointers(cup, round + 1, NULL, FALSE);
|
||||
cup_get_team_pointers(cup, round + 1, FALSE);
|
||||
|
||||
for(i=0;i<new_round->team_ptrs->len;i++)
|
||||
g_ptr_array_add(teams, g_ptr_array_index(new_round->team_ptrs, i));
|
||||
|
|
|
@ -170,8 +170,11 @@ start_new_season(void)
|
|||
|
||||
/* Deal with cups that have to take place before promotion/relegation. */
|
||||
for(i=cps->len - 1; i >= 0; i--)
|
||||
if(cp(i).add_week == -1)
|
||||
if(cp(i).add_week == -1) {
|
||||
/* Reset cup to save its history. */
|
||||
cup_reset(&cp(i));
|
||||
fixture_write_cup_fixtures(&cp(i));
|
||||
}
|
||||
|
||||
if(season > 1)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue