diff --git a/src/cup.c b/src/cup.c index 7ca77f43..52e067a0 100644 --- a/src/cup.c +++ b/src/cup.c @@ -105,6 +105,9 @@ cup_round_new(void) new.round_robin_number_of_groups = 0; new.round_robin_number_of_advance = 0; new.round_robin_number_of_best_advance = 0; + new.two_match_weeks[0] = g_array_new(FALSE, FALSE, sizeof(gint)); + new.two_match_weeks[1] = g_array_new(FALSE, FALSE, sizeof(gint)); + new.two_match_week = FALSE; new.tables = g_array_new(FALSE, FALSE, sizeof(Table)); new.choose_teams = g_array_new(FALSE, FALSE, sizeof(CupChooseTeam)); new.teams = g_array_new(FALSE, FALSE, sizeof(Team)); @@ -719,9 +722,6 @@ cup_get_first_week_of_cup_round(Cup *cup, gint cup_round) return cup_get_first_week_of_cup_round(cup, cup_round); } -/* main_exit_program(EXIT_FIRST_WEEK_ERROR, */ -/* "cup_get_first_week_of_cup_round: first week of cup %s cup round %d is not positive (%d).\nPlease lower the week gap or set a later last week.\n", */ -/* cup->name, cup_round, week_number); */ return week_number; } @@ -746,9 +746,11 @@ cup_get_last_week_from_first(const Cup *cup, gint first_week) gint cup_get_matchdays_in_cup_round(const Cup *cup, gint round) { + gint i; const CupRound *cup_round = &g_array_index(cup->rounds, CupRound, round); gint number_of_teams = -1; gint number_of_matchdays = -1; + gint diff; if(cup_round->round_robin_number_of_groups > 0) { @@ -761,11 +763,18 @@ cup_get_matchdays_in_cup_round(const Cup *cup, gint round) else number_of_matchdays = number_of_teams; - if (g_array_index(cup->rounds, CupRound, round).home_away) + if (cup_round->home_away) number_of_matchdays *= 2; + + for(i=0;itwo_match_weeks[0]->len;i++) + { + diff = g_array_index(cup_round->two_match_weeks[1], gint, i) - + g_array_index(cup_round->two_match_weeks[0], gint, i); + number_of_matchdays -= ((diff + diff % 2) / 2); + } } - else if(g_array_index(cup->rounds, CupRound, round).home_away) - number_of_matchdays = 2; + else if(cup_round->home_away) + number_of_matchdays = 2 - cup_round->two_match_week; else number_of_matchdays = 1; diff --git a/src/cup_struct.h b/src/cup_struct.h index 8ef9629f..a192d53b 100644 --- a/src/cup_struct.h +++ b/src/cup_struct.h @@ -68,6 +68,13 @@ typedef struct the value is negative) with respect to the previous cup round and the week gap. Default: 0. */ gint delay; + /** Here we store intervals of fixtures during which + there should be two matches in a week instead of one. + This is only relevant in round robin rounds. */ + GArray *two_match_weeks[2]; + /** Whether the two matches of a home/away round are + played in one week. */ + gboolean two_match_week; /** The teams that got loaded for this cup round. Mostly this only happens in the first round. */ GArray *teams; diff --git a/src/file.c b/src/file.c index 3921a62b..ceb508b2 100644 --- a/src/file.c +++ b/src/file.c @@ -55,6 +55,13 @@ file_add_support_directory_recursive (const gchar *directo if(newdir == NULL) return; + /* Ignore .svn directories */ + if(g_strrstr(directory, ".svn")) + { + g_dir_close(newdir); + return; + } + add_pixmap_directory(directory); support_directories = g_list_prepend (support_directories, g_strdup (directory)); @@ -250,7 +257,8 @@ file_check_home_dir_get_definition_dir(const gchar *dirname, const gchar *basena sprintf(buf, "%s%s%s", dirname, G_DIR_SEPARATOR_S, (gchar*)g_ptr_array_index(dir_contents, i)); - if(g_file_test(buf, G_FILE_TEST_IS_DIR)) + if(g_file_test(buf, G_FILE_TEST_IS_DIR) && + !g_strrstr(buf, ".svn")) { sprintf(buf2, "%s%s%s", basename, G_DIR_SEPARATOR_S, (gchar*)g_ptr_array_index(dir_contents, i)); diff --git a/src/fixture.c b/src/fixture.c index 747bae7a..f26436e8 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -403,6 +403,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, Cup *cup = NULL; gint len = teams->len; GArray *fixtures = NULL; + GArray **two_match_weeks; Team team_temp; gboolean odd_fixtures = FALSE; @@ -412,6 +413,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, { league = (League*)league_cup; fixtures = league->fixtures; + two_match_weeks = league->two_match_weeks; clid = league->id; first_week = (fixtures->len == 0) ? league->first_week : g_array_index(fixtures, Fixture, fixtures->len - 1).week_number + @@ -426,6 +428,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, first_week = cup_get_first_week_of_cup_round(cup, cup_round); week_gap = cup->week_gap; fixtures = cup->fixtures; + two_match_weeks = g_array_index(cup->rounds, CupRound, cup_round).two_match_weeks; clid = cup->id; home_advantage = (!g_array_index(cup->rounds, CupRound, cup_round).neutral); rr_break = week_gap; @@ -450,7 +453,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, week_number = first_week; for(i=0;i 0 && !query_league_matchday_in_two_match_week(league, i + 1)) + if(i > 0 && !query_league_cup_matchday_in_two_match_week(two_match_weeks, i + 1)) week_number += week_gap; fixture_write_round_robin_matchday(fixtures, cup_round, teams, i, @@ -463,7 +466,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, week_number += rr_break; for(i = 0; i < len - 1; i++) { - if(i > 0 && !query_league_matchday_in_two_match_week(league, len + i)) + if(i > 0 && !query_league_cup_matchday_in_two_match_week(two_match_weeks, len + i)) week_number += week_gap; week_round_number = @@ -544,7 +547,7 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams) { gint i, len = teams->len; gint first_week = cup_get_first_week_of_cup_round(cup, cup_round); - gint week_round_number; + gint week_number, week_round_number; CupRound *round = &g_array_index(cup->rounds, CupRound, cup_round); gint bye_len = (round->byes == -1) ? math_get_bye_len(len) : round->byes; @@ -592,12 +595,13 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams) if(round->home_away) { + week_number = (round->two_match_week) ? + first_week : first_week + cup->week_gap; week_round_number = - fixture_get_free_round(first_week + cup->week_gap, teams, -1, -1); + fixture_get_free_round(week_number, teams, -1, -1); for(i=0; i<=(teams->len - 2) / 2; i++) fixture_write(cup->fixtures, (Team*)g_ptr_array_index(teams, 2 * i + 1), - (Team*)g_ptr_array_index(teams, 2 * i), - first_week + cup->week_gap, + (Team*)g_ptr_array_index(teams, 2 * i), week_number, week_round_number, cup->id, cup_round, 0, !round->neutral, TRUE, TRUE); } diff --git a/src/free.c b/src/free.c index 8d286d2d..dd768e73 100644 --- a/src/free.c +++ b/src/free.c @@ -492,6 +492,10 @@ free_cup(Cup *cup) free_gchar_ptr(cup->sid); for(i=0;irounds->len;i++) + { + free_g_array(&g_array_index(cup->rounds, CupRound, i).two_match_weeks[0]); + free_g_array(&g_array_index(cup->rounds, CupRound, i).two_match_weeks[1]); + if(g_array_index(cup->rounds, CupRound, i).round_robin_number_of_groups > 0) { for(j=0;jrounds, CupRound, i).tables->len;j++) @@ -505,6 +509,7 @@ free_cup(Cup *cup) free_teams_array(&g_array_index(cup->rounds, CupRound, i).teams, FALSE); g_ptr_array_free(g_array_index(cup->rounds, CupRound, i).team_ptrs, TRUE); } + } free_g_array(&cup->rounds); free_g_array(&cup->fixtures); diff --git a/src/league.c b/src/league.c index d8e99301..7d64aec9 100644 --- a/src/league.c +++ b/src/league.c @@ -858,18 +858,15 @@ query_leagues_active_in_country(void) /** Find out whether a given matchday should occur in the same week as the one before or a full week later. */ gboolean -query_league_matchday_in_two_match_week(const League *league, gint matchday) +query_league_cup_matchday_in_two_match_week(GArray **two_match_weeks, gint matchday) { gint i; - if(league == NULL) - return FALSE; - - for(i=0;itwo_match_weeks[0]->len;i++) + for(i=0;ilen;i++) { - if(g_array_index(league->two_match_weeks[0], gint, i) < matchday && - matchday <= g_array_index(league->two_match_weeks[1], gint, i) && - (matchday - g_array_index(league->two_match_weeks[0], gint, i)) % 2 == 1) + if(g_array_index(two_match_weeks[0], gint, i) < matchday && + matchday <= g_array_index(two_match_weeks[1], gint, i) && + (matchday - g_array_index(two_match_weeks[0], gint, i)) % 2 == 1) return TRUE; } diff --git a/src/league.h b/src/league.h index 69462aaf..60ca1cf3 100644 --- a/src/league.h +++ b/src/league.h @@ -134,6 +134,6 @@ gboolean query_leagues_active_in_country(void); gboolean -query_league_matchday_in_two_match_week(const League *league, gint matchday); +query_league_cup_matchday_in_two_match_week(GArray **two_match_weeks, gint matchday); #endif diff --git a/src/xml_cup.c b/src/xml_cup.c index 12578936..dff0cad6 100644 --- a/src/xml_cup.c +++ b/src/xml_cup.c @@ -58,6 +58,9 @@ #define TAG_CUP_ROUND_NUMBER_OF_GROUPS "number_of_groups" #define TAG_CUP_ROUND_NUMBER_OF_ADVANCE "number_of_advance" #define TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE "number_of_best_advance" +#define TAG_CUP_ROUND_TWO_MATCH_WEEK_START "two_match_week_start" +#define TAG_CUP_ROUND_TWO_MATCH_WEEK_END "two_match_week_end" +#define TAG_CUP_ROUND_TWO_MATCH_WEEK "two_match_week" #define TAG_CHOOSE_TEAMS "choose_teams" #define TAG_CHOOSE_TEAM "choose_team" #define TAG_CHOOSE_TEAM_SID "choose_team_sid" @@ -96,6 +99,9 @@ enum XmlCupStates STATE_CUP_ROUND_NUMBER_OF_GROUPS, STATE_CUP_ROUND_NUMBER_OF_ADVANCE, STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE, + STATE_CUP_ROUND_TWO_MATCH_WEEK_START, + STATE_CUP_ROUND_TWO_MATCH_WEEK_END, + STATE_CUP_ROUND_TWO_MATCH_WEEK, STATE_CHOOSE_TEAMS, STATE_CHOOSE_TEAM, STATE_CHOOSE_TEAM_SID, @@ -185,6 +191,12 @@ xml_cup_read_start_element (GMarkupParseContext *context, state = STATE_CUP_ROUND_NUMBER_OF_ADVANCE; else if(strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) == 0) state = STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE; + else if(strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_START) == 0) + state = STATE_CUP_ROUND_TWO_MATCH_WEEK_START; + else if(strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_END) == 0) + state = STATE_CUP_ROUND_TWO_MATCH_WEEK_END; + else if(strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK) == 0) + state = STATE_CUP_ROUND_TWO_MATCH_WEEK; else if(strcmp(element_name, TAG_CHOOSE_TEAMS) == 0) state = STATE_CHOOSE_TEAMS; else if(strcmp(element_name, TAG_CHOOSE_TEAM) == 0) @@ -246,6 +258,9 @@ xml_cup_read_end_element (GMarkupParseContext *context, strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_GROUPS) == 0 || strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_ADVANCE) == 0 || strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) == 0 || + strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_START) == 0 || + strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_END) == 0 || + strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK) == 0 || strcmp(element_name, TAG_CUP_ROUND_NEW_TEAMS) == 0 || strcmp(element_name, TAG_CUP_ROUND_BYES) == 0 || strcmp(element_name, TAG_CHOOSE_TEAMS) == 0) @@ -333,6 +348,12 @@ xml_cup_read_text (GMarkupParseContext *context, new_round.round_robin_number_of_advance = int_value; else if(state == STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) new_round.round_robin_number_of_best_advance = int_value; + else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK_START) + g_array_append_val(new_round.two_match_weeks[0], int_value); + else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK_END) + g_array_append_val(new_round.two_match_weeks[1], int_value); + else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK) + new_round.two_match_week = int_value; else if(state == STATE_CHOOSE_TEAM_SID) misc_string_assign(&new_choose_team.sid, buf); else if(state == STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS) diff --git a/src/xml_loadsave_cup.c b/src/xml_loadsave_cup.c index efb15c49..bfa99cef 100644 --- a/src/xml_loadsave_cup.c +++ b/src/xml_loadsave_cup.c @@ -62,6 +62,9 @@ enum TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE, + TAG_CUP_ROUND_TWO_MATCH_WEEK_START, + TAG_CUP_ROUND_TWO_MATCH_WEEK_END, + TAG_CUP_ROUND_TWO_MATCH_WEEK, TAG_CUP_TEAM_ID_BYE, TAG_CUP_TEAM_NAME, TAG_CUP_NEXT_FIXTURE_UPDATE_WEEK, @@ -166,7 +169,10 @@ xml_loadsave_cup_end_element (GMarkupParseContext *context, tag == TAG_CUP_ROUND_RANDOMISE_TEAMS || tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS || tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE || - tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE) + tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE || + tag == TAG_CUP_ROUND_TWO_MATCH_WEEK_START || + tag == TAG_CUP_ROUND_TWO_MATCH_WEEK_END || + tag == TAG_CUP_ROUND_TWO_MATCH_WEEK) state = TAG_CUP_ROUND; else if(tag != TAG_CUP) g_warning("xml_loadsave_cup_end_element: unknown tag: %s; I'm in state %d\n", @@ -276,6 +282,12 @@ xml_loadsave_cup_text (GMarkupParseContext *context, new_round.round_robin_number_of_advance = int_value; else if(state == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE) new_round.round_robin_number_of_best_advance = int_value; + else if(state == TAG_CUP_ROUND_TWO_MATCH_WEEK_START) + g_array_append_val(new_round.two_match_weeks[0], int_value); + else if(state == TAG_CUP_ROUND_TWO_MATCH_WEEK_END) + g_array_append_val(new_round.two_match_weeks[1], int_value); + else if(state == TAG_CUP_ROUND_TWO_MATCH_WEEK) + new_round.two_match_week = int_value; } void @@ -410,6 +422,16 @@ xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gin TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE, I1); xml_write_int(fil, cup_round->round_robin_number_of_best_advance, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE, I1); + xml_write_int(fil, cup_round->two_match_week, + TAG_CUP_ROUND_TWO_MATCH_WEEK, I1); + + for(i=0;itwo_match_weeks[0]->len;i++) + { + xml_write_int(fil, g_array_index(cup_round->two_match_weeks[0], gint, i), + TAG_CUP_ROUND_TWO_MATCH_WEEK_START, I1); + xml_write_int(fil, g_array_index(cup_round->two_match_weeks[0], gint, i), + TAG_CUP_ROUND_TWO_MATCH_WEEK_END, I1); + } for(i=0;itables->len;i++) {