From 9d67ab30bd3b2db9bf85e55da402998435b30eff Mon Sep 17 00:00:00 2001 From: gyboth Date: Sun, 11 Jan 2009 14:51:12 +0000 Subject: [PATCH] Fixed the horses problem. --- src/cup.c | 47 ++++++++++++++++--- src/cup.h | 13 +++-- src/fixture.c | 32 +++++++++++-- src/fixture.h | 3 ++ src/start_end.c | 24 ++-------- src/table.c | 12 +++++ src/table.h | 3 ++ src/xml_loadsave_leagues_cups.c | 23 ++------- support_files/bygfoot_constants | 2 +- .../europe/austria/cup_austria_cup.xml | 20 ++++---- 10 files changed, 116 insertions(+), 63 deletions(-) diff --git a/src/cup.c b/src/cup.c index c4eb6c4a..2025d1f6 100644 --- a/src/cup.c +++ b/src/cup.c @@ -277,7 +277,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, gboolean preload) +cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, gboolean preload) { #ifdef DEBUG printf("cup_get_team_pointers\n"); @@ -301,7 +301,7 @@ cup_get_team_pointers(Cup *cup, gint round, gboolean preload) &g_array_index(cup_round->choose_teams, CupChooseTeam, i)); else cup_load_choose_team( - cup, teams, + cup, teams, teams_sorted, &g_array_index(cup_round->choose_teams, CupChooseTeam, i)); } @@ -330,7 +330,7 @@ cup_get_team_pointers(Cup *cup, gint round, gboolean preload) /** 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, const CupChooseTeam *ct) +cup_load_choose_team(Cup *cup, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct) { #ifdef DEBUG printf("cup_load_choose_team\n"); @@ -350,7 +350,7 @@ cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct) 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, ct); + cup_load_choose_team_from_cup(cup, cup_temp, teams, teams_sorted, ct); if(debug > 80) for(i=debug_num;ilen;i++) @@ -358,7 +358,7 @@ cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct) } void -cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, const CupChooseTeam *ct) +cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct) { #ifdef DEBUG printf("cup_load_choose_team_from_cup\n"); @@ -410,7 +410,10 @@ cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, c } else { - cup_teams_sorted = cup_get_teams_sorted(cup_temp); + /* Self-referential cup or no? */ + cup_teams_sorted = (cup == cup_temp) ? + teams_sorted : + cup_get_teams_sorted(cup_temp); if(ct->number_of_teams == -1) { @@ -439,7 +442,8 @@ cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, c } } - g_ptr_array_free(cup_teams_sorted, TRUE); + if(cup != cup_temp) + g_ptr_array_free(cup_teams_sorted, TRUE); if(ct->number_of_teams != -1 && number_of_teams != ct->number_of_teams) @@ -1303,3 +1307,32 @@ cup_round_check_waits(const CupRound *cup_round) return FALSE; } + +/** Find out whether the cup chooses teams from itself + (e.g. the defending champion from last season). */ +gboolean +query_cup_self_referential(const Cup *cup) +{ + gint i, j; + + for(i = 0; i < cup->rounds->len; i++) + for(j = 0; j < g_array_index(cup->rounds, CupRound, i).choose_teams->len; j++) + if(strcmp(g_array_index(g_array_index(cup->rounds, CupRound, i).choose_teams, CupChooseTeam, j).sid, cup->sid) == 0) + return TRUE; + + return FALSE; +} + +/** Find out if the cup is part of the array of + cups that are displayed in the game. */ +gboolean +query_cup_hidden(const Cup *cup) +{ + gint i; + + for(i = 0; i < acps->len; i++) + if(acp(i) == cup) + return FALSE; + + return TRUE; +} diff --git a/src/cup.h b/src/cup.h index 5a4c5c48..a30930d3 100644 --- a/src/cup.h +++ b/src/cup.h @@ -47,20 +47,21 @@ void cup_reset(Cup *cup); void -cup_get_team_pointers(Cup *cup, gint round, gboolean preload); +cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, 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, const CupChooseTeam *ct); +cup_load_choose_team(Cup *cup, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct); void cup_load_choose_team_from_league(Cup *cup, const League *league, GPtrArray *teams, const CupChooseTeam *ct); void -cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_team, GPtrArray *teams, const CupChooseTeam *ct); +cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_team, GPtrArray *teams, + GPtrArray *teams_sorted, const CupChooseTeam *ct); gint cup_get_first_week_of_cup_round(Cup *cup, gint cup_round, gboolean with_delay); @@ -132,4 +133,10 @@ cup_check_fixtures(const Cup *cup); gboolean cup_round_check_waits(const CupRound *cup_round); +gboolean +query_cup_self_referential(const Cup *cup); + +gboolean +query_cup_hidden(const Cup *cup); + #endif diff --git a/src/fixture.c b/src/fixture.c index 70be8cda..f71e6a60 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -112,9 +112,20 @@ 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); for(i=0;irounds->len;i++) - cup_get_team_pointers(cup, i, TRUE); + cup_get_team_pointers(cup, i, teams_sorted, TRUE); + + if(teams_sorted != NULL) + g_ptr_array_free(teams_sorted, TRUE); if(g_array_index(cup->rounds, CupRound, 0).round_robin_number_of_groups > 0) fixture_write_cup_round_robin( @@ -175,7 +186,7 @@ fixture_update(Cup *cup) } new_round = &g_array_index(cup->rounds, CupRound, round + 1); - cup_get_team_pointers(cup, round + 1, FALSE); + cup_get_team_pointers(cup, round + 1, NULL, FALSE); for(i=0;iteam_ptrs->len;i++) g_ptr_array_add(teams, g_ptr_array_index(new_round->team_ptrs, i)); @@ -547,8 +558,8 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, } /* Special rule for cups that have to wait for other cups. */ - if(cup_round != -1 && first_week < week + 1) - first_week = week + 1; + if(cup_round != -1 && first_week < week) + first_week = week; /* first half of fixtures */ week_number = league_cup_get_week_with_break(clid, first_week); @@ -1798,3 +1809,16 @@ fixture_get_cup_round_name(const Fixture *fix, gchar *buf) strcat(buf, _(" -- Replay matches")); } +/* Reset the team pointers from the team ids in the fixtures. */ +void +fixture_refresh_team_pointers(GArray *fixtures) +{ + gint i, j; + + for(i = 0; i < fixtures->len; i++) + { + for(j = 0; j < 2; j++) + g_array_index(fixtures, Fixture, i).teams[j] = + team_of_id(g_array_index(fixtures, Fixture, i).team_ids[j]); + } +} diff --git a/src/fixture.h b/src/fixture.h index d15c4ea6..dd5d135a 100644 --- a/src/fixture.h +++ b/src/fixture.h @@ -174,4 +174,7 @@ fixtures_condense(GArray *fixtures); void fixture_get_cup_round_name(const Fixture *fix, gchar *buf); +void +fixture_refresh_team_pointers(GArray *fixtures); + #endif diff --git a/src/start_end.c b/src/start_end.c index 4c8c5089..dd513591 100644 --- a/src/start_end.c +++ b/src/start_end.c @@ -132,10 +132,7 @@ 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) - { - cup_reset(&cp(i)); fixture_write_cup_fixtures(&cp(i)); - } if(season > 1) { @@ -181,25 +178,12 @@ start_new_season(void) needed for the international cups. */ for(i=cps->len - 1; i >= 0; i--) { - if(cp(i).add_week >= 0) - { - cup_reset(&cp(i)); - - if(cp(i).add_week == 0) - fixture_write_cup_fixtures(&cp(i)); - } + if(cp(i).add_week == 0) + fixture_write_cup_fixtures(&cp(i)); /* Reset team pointers using the stored ids (pointers might have changed because of prom/rel). */ else if(cp(i).add_week == -1) - { - for(j=0;jlen;j++) - { - g_array_index(cp(i).fixtures, Fixture, j).teams[0] = - team_of_id(g_array_index(cp(i).fixtures, Fixture, j).team_ids[0]); - g_array_index(cp(i).fixtures, Fixture, j).teams[1] = - team_of_id(g_array_index(cp(i).fixtures, Fixture, j).team_ids[1]); - } - } + fixture_refresh_team_pointers(cp(i).fixtures); } for(i = acps->len - 1; i >= 0; i--) @@ -513,7 +497,7 @@ end_week_round_update_fixtures(void) for(i=0;ilen;i++) { if(cp(i).add_week == 1000 && - cp(i).fixtures->len == 0 && + query_cup_hidden(&cp(i)) && query_cup_begins(&cp(i))) { cp(i).last_week = cup_get_last_week_from_first(&cp(i), week + 1); diff --git a/src/table.c b/src/table.c index 726ea9a0..7fe6b10a 100644 --- a/src/table.c +++ b/src/table.c @@ -27,6 +27,7 @@ #include "league.h" #include "misc.h" #include "table.h" +#include "team.h" #include "variables.h" /** Return a newly allocated empty table. */ @@ -317,3 +318,14 @@ table_copy(const Table *table) return new_table; } + +/** Refresh the team pointers in the table from the team ids. */ +void +table_refresh_team_pointers(Table *table) +{ + gint i; + + for(i = 0; i < table->elements->len; i++) + g_array_index(table->elements, TableElement, i).team = + team_of_id(g_array_index(table->elements, TableElement, i).team_id); +} diff --git a/src/table.h b/src/table.h index b37aab2e..20a2ab9d 100644 --- a/src/table.h +++ b/src/table.h @@ -53,5 +53,8 @@ query_tables_in_country(void); Table table_copy(const Table *table); +void +table_refresh_team_pointers(Table *table); + #endif diff --git a/src/xml_loadsave_leagues_cups.c b/src/xml_loadsave_leagues_cups.c index ae8114ce..57e9e1aa 100644 --- a/src/xml_loadsave_leagues_cups.c +++ b/src/xml_loadsave_leagues_cups.c @@ -215,21 +215,16 @@ xml_loadsave_leagues_cups_adjust_team_ptrs(void) for(i = 0; i < ligs->len; i++) { - for(j = 0; j < lig(i).fixtures->len; j++) - { - for(k = 0; k < 2; k++) - g_array_index(lig(i).fixtures, Fixture, j).teams[k] = - team_of_id(g_array_index(lig(i).fixtures, Fixture, j).team_ids[k]); - } + fixture_refresh_team_pointers(lig(i).fixtures); for(j = 0; j < lig(i).tables->len; j++) - for(k = 0; k < g_array_index(lig(i).tables, Table, j).elements->len; k++) - g_array_index(g_array_index(lig(i).tables, Table, j).elements, TableElement, k).team = - team_of_id(g_array_index(g_array_index(lig(i).tables, Table, j).elements, TableElement, k).team_id); + table_refresh_team_pointers(&g_array_index(lig(i).tables, Table, j)); } for(i = 0; i < cps->len; i++) { + fixture_refresh_team_pointers(cp(i).fixtures); + for(j = 0; j < cp(i).rounds->len; j++) { team_ptrs = g_ptr_array_new(); @@ -240,15 +235,7 @@ xml_loadsave_leagues_cups_adjust_team_ptrs(void) g_array_index(cp(i).rounds, CupRound, j).team_ptrs = team_ptrs; for(k = 0; k < g_array_index(cp(i).rounds, CupRound, j).tables->len; k++) - for(l = 0; l < g_array_index(g_array_index(cp(i).rounds, CupRound, j).tables, Table, k).elements->len; l++) - g_array_index(g_array_index(g_array_index(cp(i).rounds, CupRound, j).tables, Table, k).elements, TableElement, l).team = - team_of_id(g_array_index(g_array_index(g_array_index(cp(i).rounds, CupRound, j).tables, Table, k).elements, TableElement, l).team_id); - } - - for(j = 0; j < cp(i).fixtures->len; j++) - { - for(k = 0; k < 2; k++) - g_array_index(cp(i).fixtures, Fixture, j).teams[k] = team_of_id(g_array_index(cp(i).fixtures, Fixture, j).team_ids[k]); + table_refresh_team_pointers(&g_array_index(g_array_index(cp(i).rounds, CupRound, j).tables, Table, k)); } } } diff --git a/support_files/bygfoot_constants b/support_files/bygfoot_constants index dd957537..f75919b2 100644 --- a/support_files/bygfoot_constants +++ b/support_files/bygfoot_constants @@ -1004,4 +1004,4 @@ int_news_repetition_min_check_number 3 int_news_repetition_max_check_number 10 # how many news articles to keep in memory -int_news_history_length 50 +int_news_history_length 100 diff --git a/support_files/definitions/europe/austria/cup_austria_cup.xml b/support_files/definitions/europe/austria/cup_austria_cup.xml index ded2c7c7..4789c512 100644 --- a/support_files/definitions/europe/austria/cup_austria_cup.xml +++ b/support_files/definitions/europe/austria/cup_austria_cup.xml @@ -114,26 +114,26 @@ -18 - 0 + 0 -18 - 0 + 0 - - - austria_cup - 1 - 1 - 1 - - + + + + + + + + -15