diff --git a/src/cup.c b/src/cup.c index 3251afcf..0d9042f0 100644 --- a/src/cup.c +++ b/src/cup.c @@ -100,6 +100,7 @@ cup_choose_team_new(void) new.generate = FALSE; new.skip_group_check = FALSE; new.from_table = 0; + new.preload = TRUE; return new; } @@ -259,7 +260,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) +cup_get_team_pointers(Cup *cup, gint round, gboolean preload) { #ifdef DEBUG printf("cup_get_team_pointers\n"); @@ -272,19 +273,18 @@ cup_get_team_pointers(Cup *cup, gint round) if(debug > 60) g_print("cup_get_team_pointers %s round %d\n", cup->name, round); - if(teams->len > 0) - g_warning("cup_get_team_pointers: round %d in cup %s has non-empty team pointers array.", - round, cup->name); - for(i=0;ichoose_teams->len;i++) - if(g_array_index(cup_round->choose_teams, CupChooseTeam, i).generate) - cup_load_choose_team_generate( - cup, cup_round, - &g_array_index(cup_round->choose_teams, CupChooseTeam, i)); - else - cup_load_choose_team( - cup, teams, - &g_array_index(cup_round->choose_teams, CupChooseTeam, i)); + if(g_array_index(cup_round->choose_teams, CupChooseTeam, i).preload == preload) + { + if(g_array_index(cup_round->choose_teams, CupChooseTeam, i).generate) + cup_load_choose_team_generate( + cup, cup_round, + &g_array_index(cup_round->choose_teams, CupChooseTeam, i)); + else + cup_load_choose_team( + cup, teams, + &g_array_index(cup_round->choose_teams, CupChooseTeam, i)); + } if(cup_round->teams->len > 0) while(teams->len + cup_round->teams->len > cup_round->new_teams) diff --git a/src/cup.h b/src/cup.h index c0674018..60b18720 100644 --- a/src/cup.h +++ b/src/cup.h @@ -47,7 +47,7 @@ void cup_reset(Cup *cup); void -cup_get_team_pointers(Cup *cup, gint round); +cup_get_team_pointers(Cup *cup, gint round, gboolean preload); void cup_load_choose_team_generate(Cup *cup, CupRound *cup_round, const CupChooseTeam *ct); diff --git a/src/cup_struct.h b/src/cup_struct.h index bfd21e04..cae1b2b2 100644 --- a/src/cup_struct.h +++ b/src/cup_struct.h @@ -138,6 +138,11 @@ typedef struct /** Whether to skip the checking if a team participates in other of the same cup groupcups. */ gboolean skip_group_check; + /** Whether to load the choose_team when the cup fixtures for the + first cup round are written or only when the cup round the choose_team + belongs to is scheduled. Default: TRUE. */ + gboolean preload; + } CupChooseTeam; /** Structure representing a cup. */ diff --git a/src/fixture.c b/src/fixture.c index f4203590..7089e0ea 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -113,7 +113,8 @@ fixture_write_cup_fixtures(Cup *cup) gint i; - cup_get_team_pointers(cup, 0); + for(i=0;irounds->len;i++) + 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( @@ -174,7 +175,7 @@ fixture_update(Cup *cup) } new_round = &g_array_index(cup->rounds, CupRound, round + 1); - cup_get_team_pointers(cup, round + 1); + cup_get_team_pointers(cup, round + 1, FALSE); for(i=0;iteam_ptrs->len;i++) g_ptr_array_add(teams, g_ptr_array_index(new_round->team_ptrs, i)); @@ -305,7 +306,9 @@ fixture_winner_of(const Fixture *fix, gboolean team_id) cupround = &g_array_index(cup_from_clid(fix->clid)->rounds, CupRound, fix->round); - if(cupround->replay != 0 || !cupround->home_away) + if(cupround->replay != 0 || + !cupround->home_away || + cupround->round_robin_number_of_groups > 0) winner_idx = (math_sum_int_array(&(fix->result[0][0]), 3) < math_sum_int_array(&(fix->result[1][0]), 3)); else @@ -964,12 +967,14 @@ fixture_get_first_leg(const Fixture *fix, gboolean silent) gint i; Fixture *first_leg = NULL; + const GArray *fixtures = cup_from_clid(fix->clid)->fixtures; - for(i=0;iclid)->fixtures->len;i++) - if(g_array_index(cup_from_clid(fix->clid)->fixtures, Fixture, i).round == fix->round && - g_array_index(cup_from_clid(fix->clid)->fixtures, Fixture, i).team_ids[0] == fix->team_ids[1] && - g_array_index(cup_from_clid(fix->clid)->fixtures, Fixture, i).team_ids[1] == fix->team_ids[0]) - first_leg = &g_array_index(cup_from_clid(fix->clid)->fixtures, Fixture, i); + if(g_array_index(cup_from_clid(fix->clid)->rounds, CupRound, fix->round).round_robin_number_of_groups == 0) + for(i=0;ilen;i++) + if(g_array_index(fixtures, Fixture, i).round == fix->round && + g_array_index(fixtures, Fixture, i).team_ids[0] == fix->team_ids[1] && + g_array_index(fixtures, Fixture, i).team_ids[1] == fix->team_ids[0]) + first_leg = &g_array_index(fixtures, Fixture, i); if(first_leg == NULL && !silent) g_warning("fixture_get_first_leg: didn't find first leg match; cup %s round %d\n", diff --git a/src/league_struct.h b/src/league_struct.h index 341404e4..cb0c129f 100644 --- a/src/league_struct.h +++ b/src/league_struct.h @@ -52,7 +52,7 @@ typedef struct } PromRelElement; /** - An element representing promotion/relegation games. + An struct representing promotion/relegation games. */ typedef struct { diff --git a/src/xml_cup.c b/src/xml_cup.c index ae63f9e6..1746e5c4 100644 --- a/src/xml_cup.c +++ b/src/xml_cup.c @@ -69,6 +69,7 @@ #define TAG_CHOOSE_TEAM_GENERATE "generate" #define TAG_CHOOSE_TEAM_SKIP_GROUP_CHECK "skip_group_check" #define TAG_CHOOSE_TEAM_FROM_TABLE "from_table" +#define TAG_CHOOSE_TEAM_PRELOAD "preload" #define ATT_NAME_CUP_ROUND_WAIT_ROUND "round" @@ -118,6 +119,7 @@ enum XmlCupStates STATE_CHOOSE_TEAM_GENERATE, STATE_CHOOSE_TEAM_SKIP_GROUP_CHECK, STATE_CHOOSE_TEAM_FROM_TABLE, + STATE_CHOOSE_TEAM_PRELOAD, STATE_END }; @@ -257,6 +259,8 @@ xml_cup_read_start_element (GMarkupParseContext *context, state = STATE_CHOOSE_TEAM_SKIP_GROUP_CHECK; else if(strcmp(element_name, TAG_CHOOSE_TEAM_FROM_TABLE) == 0) state = STATE_CHOOSE_TEAM_FROM_TABLE; + else if(strcmp(element_name, TAG_CHOOSE_TEAM_PRELOAD) == 0) + state = STATE_CHOOSE_TEAM_PRELOAD; else g_warning("xml_cup_read_start_element: unknown tag: %s; I'm in state %d\n", element_name, state); @@ -339,6 +343,7 @@ xml_cup_read_end_element (GMarkupParseContext *context, strcmp(element_name, TAG_CHOOSE_TEAM_RANDOMLY) == 0 || strcmp(element_name, TAG_CHOOSE_TEAM_SKIP_GROUP_CHECK) == 0 || strcmp(element_name, TAG_CHOOSE_TEAM_FROM_TABLE) == 0 || + strcmp(element_name, TAG_CHOOSE_TEAM_PRELOAD) == 0 || strcmp(element_name, TAG_CHOOSE_TEAM_GENERATE) == 0) state = STATE_CHOOSE_TEAM; else if(strcmp(element_name, TAG_CUP) != 0) @@ -446,6 +451,8 @@ xml_cup_read_text (GMarkupParseContext *context, new_choose_team.skip_group_check = int_value; else if(state == STATE_CHOOSE_TEAM_FROM_TABLE) new_choose_team.from_table = int_value; + else if(state == STATE_CHOOSE_TEAM_PRELOAD) + new_choose_team.preload = int_value; } /** diff --git a/src/xml_loadsave_cup.c b/src/xml_loadsave_cup.c index 8830b9df..45a26f07 100644 --- a/src/xml_loadsave_cup.c +++ b/src/xml_loadsave_cup.c @@ -50,6 +50,7 @@ enum TAG_CUP_CHOOSE_TEAM_GENERATE, TAG_CUP_CHOOSE_TEAM_SKIP_GROUP_CHECK, TAG_CUP_CHOOSE_TEAM_FROM_TABLE, + TAG_CUP_CHOOSE_TEAM_PRELOAD, TAG_CUP_ROUND, TAG_CUP_ROUND_NEW_TEAMS, TAG_CUP_ROUND_BYES, @@ -174,6 +175,7 @@ xml_loadsave_cup_end_element (GMarkupParseContext *context, tag == TAG_CUP_CHOOSE_TEAM_GENERATE || tag == TAG_CUP_CHOOSE_TEAM_SKIP_GROUP_CHECK || tag == TAG_CUP_CHOOSE_TEAM_FROM_TABLE || + tag == TAG_CUP_CHOOSE_TEAM_PRELOAD || tag == TAG_CUP_CHOOSE_TEAM_RANDOMLY) state = TAG_CUP_CHOOSE_TEAM; else if(tag == TAG_CUP_ROUND_HOME_AWAY || @@ -280,6 +282,8 @@ xml_loadsave_cup_text (GMarkupParseContext *context, new_choose_team.skip_group_check = int_value; else if(state == TAG_CUP_CHOOSE_TEAM_FROM_TABLE) new_choose_team.from_table = int_value; + else if(state == TAG_CUP_CHOOSE_TEAM_PRELOAD) + new_choose_team.preload = int_value; else if(state == TAG_CUP_ROUND_HOME_AWAY) new_round.home_away = int_value; else if(state == TAG_CUP_ROUND_NEW_TEAMS) @@ -562,6 +566,8 @@ xml_loadsave_cup_write_choose_team(FILE *fil, const CupChooseTeam *choose_team) TAG_CUP_CHOOSE_TEAM_SKIP_GROUP_CHECK, I2); xml_write_int(fil, choose_team->from_table, TAG_CUP_CHOOSE_TEAM_FROM_TABLE, I2); + xml_write_int(fil, choose_team->preload, + TAG_CUP_CHOOSE_TEAM_PRELOAD, I2); fprintf(fil, "%s\n", I1, TAG_CUP_CHOOSE_TEAM); }