diff --git a/src/Makefile.am b/src/Makefile.am index 1e6de6da..564b869d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,7 +48,7 @@ bygfoot_SOURCES = \ window.c file.h finance.h free.h game_gui.h gui.h interface.h main.h misc_interface.h misc2_interface.h option.h support.h user.h window.h \ xml.c cup.h file.h free.h gui.h league.h misc.h support.h table.h transfer_struct.h user.h variables.h xml.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_teams.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_transfers.h xml_loadsave_users.h \ xml_loadsave_misc.c cup.h file.h misc.h variables.h xml.h xml_loadsave_misc.h xml_loadsave_cup.h xml_loadsave_league.h \ - xml_loadsave_cup.c cup.h file.h misc.h team.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_teams.h \ + xml_loadsave_cup.c cup.h file.h misc.h table.h team.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_teams.h \ xml_loadsave_fixtures.c file.h fixture.h misc.h team.h xml.h xml_loadsave_fixtures.h \ xml_loadsave_league.c file.h league.h misc.h xml.h xml_loadsave_fixtures.h xml_loadsave_league.h xml_loadsave_table.h xml_loadsave_teams.h \ xml_loadsave_live_game.c cup.h file.h fixture.h league.h live_game.h misc.h variables.h xml.h xml_loadsave_live_game.h \ diff --git a/src/callback_func.c b/src/callback_func.c index 0f40b846..e907f21c 100644 --- a/src/callback_func.c +++ b/src/callback_func.c @@ -196,13 +196,13 @@ callback_show_tables(gint type) else if(type == SHOW_NEXT_LEAGUE) { clid = league_cup_get_next_clid(stat1); - while(clid >= ID_CUP_START && cup_from_clid(clid)->tables->len == 0) + while(clid >= ID_CUP_START && cup_has_tables(clid) == -1) clid = league_cup_get_next_clid(clid); } else if(type == SHOW_PREVIOUS_LEAGUE) { clid = league_cup_get_previous_clid(stat1); - while(clid >= ID_CUP_START && cup_from_clid(clid)->tables->len == 0) + while(clid >= ID_CUP_START && cup_has_tables(clid) == -1) clid = league_cup_get_previous_clid(clid); } diff --git a/src/cup.c b/src/cup.c index 64ae1539..ab2cb2b1 100644 --- a/src/cup.c +++ b/src/cup.c @@ -37,7 +37,6 @@ cup_new(gboolean new_id) new.rounds = g_array_new(FALSE, FALSE, sizeof(CupRound)); new.teams = g_array_new(FALSE, FALSE, sizeof(Team)); new.user_teams = g_ptr_array_new(); - new.tables = g_array_new(FALSE, FALSE, sizeof(Table)); new.fixtures = g_array_new(FALSE, FALSE, sizeof(Fixture)); new.bye = NULL; @@ -73,6 +72,7 @@ cup_round_new(void) new.round_robin_number_of_groups = 0; new.round_robin_number_of_advance = -1; new.round_robin_number_of_best_advance = 0; + new.tables = g_array_new(FALSE, FALSE, sizeof(Table)); return new; } @@ -458,7 +458,7 @@ cup_get_teams_sorted(const Cup *cup) g_ptr_array_add(teams, team_of_id(g_array_index(cup->fixtures, Fixture, i).team_ids[j])); } - g_ptr_array_sort_with_data(teams, cup_compare_success, (gpointer)cup->fixtures); + g_ptr_array_sort_with_data(teams, cup_compare_success, (gpointer)cup); g_array_free(team_ids, TRUE); @@ -470,7 +470,9 @@ cup_get_teams_sorted(const Cup *cup) gint cup_compare_success(gconstpointer a, gconstpointer b, gpointer data) { - const GArray *fixtures = (GArray*)data; + const Cup *cup = (const Cup*)data; + const CupRound *cupround = NULL; + const GArray *fixtures = cup->fixtures; const Team *team1 = *(const Team**)a; const Team *team2 = *(const Team**)b; const Fixture *last_fix = &g_array_index(fixtures, Fixture, fixtures->len - 1); @@ -478,13 +480,20 @@ cup_compare_success(gconstpointer a, gconstpointer b, gpointer data) round_reached2 = cup_get_round_reached(team2, fixtures); gint return_value = 0; - if(round_reached1 < round_reached2) + if(team1 == team2) + return_value = 0; + else if(round_reached1 < round_reached2) return_value = 1; else if(round_reached1 > round_reached2) return_value = -1; else { - if(round_reached1 != last_fix->round) + cupround = &g_array_index(cup->rounds, CupRound, round_reached1); + + if(cupround->tables->len > 0) + return_value = + cup_compare_success_tables(team1, team2, cup, round_reached1); + else if(round_reached1 != last_fix->round) return_value = 0; else { @@ -498,6 +507,34 @@ cup_compare_success(gconstpointer a, gconstpointer b, gpointer data) return return_value; } +/** Compare two teams in cup tables. */ +gint +cup_compare_success_tables(const Team *tm1, const Team *tm2, const Cup *cup, gint round) +{ + gint i, j; + gint return_value = 0; + const CupRound *cupround = &g_array_index(cup->rounds, CupRound, round); + const TableElement *elem1 = NULL, *elem2 = NULL; + + if(team_get_cup_rank(tm1, cupround) > team_get_cup_rank(tm2, cupround)) + return_value = 1; + else if(team_get_cup_rank(tm1, cupround) < team_get_cup_rank(tm2, cupround)) + return_value = -1; + else + { + for(i=0;itables->len;i++) + for(j=0;jtables, Table, i).elements->len;j++) + if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm1) + elem1 = &g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j); + else if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm2) + elem2 = &g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j); + + return_value = table_element_compare_func(elem1, elem2, GINT_TO_POINTER(cup->id)); + } + + return return_value; +} + /** Return the cup round that the team reached in the cup. @param fixtures The fixtures array of the cup. */ gint @@ -674,7 +711,7 @@ cup_round_name(const Fixture *fix, gchar *buf) cup_get_round_name(cup, fix->round, buf); - if(cup_round->home_away) + if(cup_round->home_away && cup_round->round_robin_number_of_groups == 0) { if(fix->second_leg) strcat(buf, " -- Second leg"); @@ -764,3 +801,20 @@ query_cup_supercup_begins(const Cup *supercup) return TRUE; } + +/** Find out whether the cup contains tables + that can be displayed. Returns -1 if false + and the number of the cup round with tables + otherwise. */ +gint +cup_has_tables(gint clid) +{ + const Cup *cup = cup_from_clid(clid); + gint i; + + for(i=cup->rounds->len - 1; i>=0; i--) + if(g_array_index(cup->rounds, CupRound, i).tables->len > 0) + return i; + + return -1; +} diff --git a/src/cup.h b/src/cup.h index 87e831d3..e4716e55 100644 --- a/src/cup.h +++ b/src/cup.h @@ -7,6 +7,8 @@ #include "league_struct.h" #define query_cup_is_prom(clid) (clid >= ID_PROM_CUP_START && clid < ID_SUPERCUP_START) +#define cup_get_last_tables_round(clid) &g_array_index(cup_from_clid(clid)->rounds, CupRound, cup_has_tables(clid)) +#define cup_get_last_tables(clid) g_array_index(cup_from_clid(clid)->rounds, CupRound, cup_has_tables(clid)).tables Cup cup_new(gboolean new_id); @@ -47,6 +49,9 @@ cup_round_name(const Fixture *fix, gchar *buf); GPtrArray* cup_get_teams_sorted(const Cup *cup); +gint +cup_compare_success_tables(const Team *tm1, const Team *tm2, const Cup *cup, gint round); + GPtrArray* cup_get_teams_from_names(GPtrArray *team_names); @@ -72,4 +77,7 @@ cup_get_last_week_from_first(const Cup *cup, gint first_week); void cup_get_round_name(const Cup *cup, gint round, gchar *buf); +gint +cup_has_tables(gint clid); + #endif diff --git a/src/cup_struct.h b/src/cup_struct.h index f2e8096b..20e2cb13 100644 --- a/src/cup_struct.h +++ b/src/cup_struct.h @@ -38,6 +38,8 @@ typedef struct and additionally the best 3 from all the groups. Default: 0. */ gint round_robin_number_of_best_advance; + /** The round robin tables (in case there is a round robin). */ + GArray *tables; } CupRound; @@ -112,8 +114,6 @@ typedef struct GArray *teams; /** Pointers to the teams from the leagues that participate. */ GPtrArray *user_teams; - /** An array of tables for round robin groups. */ - GArray *tables; /** The fixtures of a season for the cup. */ GArray *fixtures; } Cup; diff --git a/src/fixture.c b/src/fixture.c index ce15f076..fca288b7 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -62,18 +62,15 @@ fixture_write_cup_fixtures(Cup *cup) g_array_free(cup->fixtures, TRUE); cup->fixtures = g_array_new(FALSE, FALSE, sizeof(Fixture)); - if(g_array_index(cup->rounds, CupRound, 0). - round_robin_number_of_groups > 0) - fixture_write_cup_round_robin(cup, 0, NULL); + if(cup->type == CUP_TYPE_INTERNATIONAL) + teams = cup_get_team_pointers(cup); else - { - if(cup->type == CUP_TYPE_INTERNATIONAL) - teams = cup_get_team_pointers(cup); - else - teams = cup_get_choose_teams_pointers(cup); + teams = cup_get_choose_teams_pointers(cup); + if(g_array_index(cup->rounds, CupRound, 0).round_robin_number_of_groups > 0) + fixture_write_cup_round_robin(cup, 0, teams); + else fixture_write_knockout_round(cup, 0, teams); - } } /** Update the fixtures for the given cup. @@ -185,16 +182,18 @@ fixture_get_round_robin_advance(const Cup *cup, gint round) const CupRound *cupround = &g_array_index(cup->rounds, CupRound, round); GArray *best_advance = g_array_new(FALSE, FALSE, sizeof(TableElement)); - for(i=0;itables->len;i++) - for(j=0;jtables, Table, i).elements->len;j++) + for(i=0;itables->len;i++) + for(j=0;jtables, Table, i).elements->len;j++) + { if(j < cupround->round_robin_number_of_advance) g_ptr_array_add(array, g_array_index( - g_array_index(cup->tables, Table, i).elements, + g_array_index(cupround->tables, Table, i).elements, TableElement, j).team); else g_array_append_val(best_advance, - g_array_index(g_array_index(cup->tables, Table, i).elements, + g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j)); + } g_array_sort_with_data(best_advance, (GCompareDataFunc)table_element_compare_func, @@ -203,6 +202,8 @@ fixture_get_round_robin_advance(const Cup *cup, gint round) for(i=0;iround_robin_number_of_best_advance;i++) g_ptr_array_add(array, g_array_index(best_advance, TableElement, i).team); + g_array_free(best_advance, TRUE); + return array; } @@ -280,14 +281,13 @@ void fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams) { gint i, j; - gint number_of_groups = - g_array_index(cup->rounds, CupRound, cup_round).round_robin_number_of_groups; - GPtrArray *teams_group[number_of_groups]; + CupRound *cupround = &g_array_index(cup->rounds, CupRound, cup_round); + gint number_of_groups = cupround->round_robin_number_of_groups; + GPtrArray *teams_group = NULL; Table new_table; TableElement new_table_element; - if(teams == NULL) - teams = misc_randomise_g_pointer_array(cup_get_team_pointers(cup)); + teams = misc_randomise_g_pointer_array(teams); if(teams->len % number_of_groups != 0) { @@ -298,7 +298,11 @@ fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams) main_exit_program(EXIT_FIXTURE_WRITE_ERROR, NULL); } - free_cup_tables(cup->tables, TRUE); + for(i=0;itables->len;i++) + free_table(&g_array_index(cupround->tables, Table, i)); + + g_array_free(cupround->tables, TRUE); + cupround->tables = g_array_new(FALSE, FALSE, sizeof(Table)); for(i=0;ilen / number_of_groups;j++) { - g_ptr_array_add(teams_group[i], g_ptr_array_index(teams, j + i * number_of_groups)); + g_ptr_array_add(teams_group, g_ptr_array_index(teams, j + i * number_of_groups)); new_table_element = table_element_new((Team*)g_ptr_array_index(teams, j + i * number_of_groups)); g_array_append_val(new_table.elements, new_table_element); } - g_array_append_val(cup->tables, new_table); + g_array_append_val(cupround->tables, new_table); + + fixture_write_round_robin((gpointer)cup, cup_round, teams_group); - fixture_write_round_robin((gpointer)cup, cup_round, teams_group[i]); } + g_ptr_array_free(teams, TRUE); + cup->next_fixture_update_week = (cup_round < cup->rounds->len - 1) ? g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number : -1; cup->next_fixture_update_week_round = (cup_round < cup->rounds->len - 1) ? g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_round_number : -1; + } /** Write round robin fixtures for the teams in the array. @@ -396,6 +404,8 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, GPtrArray *teams) first_week + (len - 1 + i) * week_gap, fixture_get_free_round(first_week + (len - 1 + i) * week_gap, clid), clid, cup_round, 0, home_advantage, FALSE, FALSE); + + g_ptr_array_free(teams, TRUE); } /** Write one matchday of round robin games. @@ -488,6 +498,8 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams) g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number : -1; cup->next_fixture_update_week_round = (cup_round < cup->rounds->len - 1 || round->replay > 0) ? g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_round_number : -1; + + g_ptr_array_free(teams, TRUE); } /** Write a fixture and append it to a fixture array. @@ -632,8 +644,7 @@ gboolean query_fixture_has_tables(const Fixture *fix) { return (fix->clid < ID_CUP_START || - g_array_index(cup_from_clid(fix->clid)->rounds, CupRound, fix->round). - round_robin_number_of_groups != 0); + cup_has_tables(fix->clid) == fix->round); } /** Find out whether there were games in the specified league diff --git a/src/free.c b/src/free.c index 756d2099..c8161b4f 100644 --- a/src/free.c +++ b/src/free.c @@ -310,7 +310,7 @@ free_cups_array(GArray **cups, gboolean reset) void free_cup(Cup *cup) { - gint i; + gint i, j; GString **strings[4] = {&cup->name, &cup->short_name, @@ -323,6 +323,11 @@ free_cup(Cup *cup) for(i=0;i<4;i++) free_g_string(strings[i]); + for(i=0;irounds->len;i++) + if(g_array_index(cup->rounds, CupRound, i).round_robin_number_of_groups > 0) + for(j=0;jrounds, CupRound, i).tables->len;j++) + free_table(&g_array_index(g_array_index(cup->rounds, CupRound, i).tables, Table, j)); + if(cup->choose_teams != NULL) for(i=0;ichoose_teams->len;i++) free_cup_choose_team(&g_array_index(cup->choose_teams, CupChooseTeam, i)); @@ -337,32 +342,6 @@ free_cup(Cup *cup) free_g_ptr_array(&cup->bye); free_g_ptr_array(&cup->user_teams); - - free_cup_tables(cup->tables, FALSE); -} - -/** Free the memory occupied by the cup tables. - @param tables The array containing the tables. */ -void -free_cup_tables(GArray *tables, gboolean reset) -{ - gint i; - - if(tables == NULL) - { - if(reset) - tables = g_array_new(FALSE, FALSE, sizeof(Table)); - - return; - } - - for(i=0;ilen;i++) - free_table(&g_array_index(tables, Table, i)); - - free_g_array(&tables); - - if(reset) - tables = g_array_new(FALSE, FALSE, sizeof(Table)); } /** diff --git a/src/game.c b/src/game.c index 365c2e4c..510574ca 100644 --- a/src/game.c +++ b/src/game.c @@ -320,7 +320,7 @@ game_assign_attendance(Fixture *fix) tm[0]->stadium.capacity); if(fix->clid < ID_CUP_START && - team_rank(tm[1], fix->clid) < + team_get_league_rank(tm[1]) < (gint)rint((gfloat)league_from_clid(fix->clid)->teams->len * const_float("float_game_stadium_attendance_rank_percentage"))) factor *= const_float("float_game_stadium_attendance_rank_factor"); diff --git a/src/game_gui.c b/src/game_gui.c index 9f73d435..f3a8f540 100644 --- a/src/game_gui.c +++ b/src/game_gui.c @@ -195,7 +195,7 @@ game_gui_set_main_window_header(void) gtk_label_set_text(label_money, buf); gui_label_set_text_from_int(label_rank, - team_rank(current_user.tm, current_user.tm->clid), FALSE); + team_get_league_rank(current_user.tm), FALSE); gtk_label_set_text(label_team, current_user.tm->name->str); gtk_label_set_text(label_league, league_from_clid(current_user.tm->clid)->name->str); @@ -470,7 +470,7 @@ game_gui_show_job_offer(Team *team, gint type) gtk_label_set_text(label_text2, buf2); gtk_label_set_text(label_name, team->name->str); gtk_label_set_text(label_league, league_from_clid(team->clid)->name->str); - gui_label_set_text_from_int(label_rank, team_rank(team, team->clid), FALSE); + gui_label_set_text_from_int(label_rank, team_get_league_rank(team), FALSE); misc_print_grouped_int(math_round_integer(team->stadium.capacity * math_rndi(const_int("int_initial_money_lower"), const_int("int_initial_money_upper")), 2), diff --git a/src/league.c b/src/league.c index 2cf1381d..8a0c84bd 100644 --- a/src/league.c +++ b/src/league.c @@ -471,7 +471,7 @@ query_league_prom_games_begin(const League *league) gboolean proceed = FALSE; for(i=0;iprom_rel.prom_games_cup.choose_teams->len;i++) - { + { for(j=0;jlen;j++) if(strcmp(lig(j).sid->str, g_array_index(league->prom_rel.prom_games_cup.choose_teams, diff --git a/src/start_end.c b/src/start_end.c index c9a9f26e..20b817f1 100644 --- a/src/start_end.c +++ b/src/start_end.c @@ -66,6 +66,11 @@ start_new_season(void) /*todo: nullify, promotion/relegation*/ if(season > 1) { + for(i=0;ilen;i++) + user_history_add(&usr(i), USER_HISTORY_END_SEASON, + usr(i).team_id, usr(i).tm->clid, + team_get_league_rank(usr(i).tm), ""); + start_new_season_team_movements(); for(i=0;ilen;i++) @@ -253,14 +258,14 @@ end_week_round_sort_tables(void) GINT_TO_POINTER(lig(i).id)); for(i=0;ilen;i++) - if(acp(i)->tables != NULL && acp(i)->tables->len != 0 && - query_fixture_in_week_round(acp(i)->id, week, week_round) && + if(query_fixture_in_week_round(acp(i)->id, week, week_round) && g_array_index(acp(i)->fixtures, Fixture, acp(i)->fixtures->len - 1).round == - g_array_index(acp(i)->tables, Table, 0).round) - for(j=0;jtables->len;j++) - g_array_sort_with_data(g_array_index(acp(i)->tables, Table, j).elements, - (GCompareDataFunc)table_element_compare_func, - GINT_TO_POINTER(acp(i)->id)); + cup_has_tables(acp(i)->id)) + for(j=0;jid)->len;j++) + g_array_sort_with_data( + g_array_index(cup_get_last_tables(acp(i)->id), Table, j).elements, + (GCompareDataFunc)table_element_compare_func, + GINT_TO_POINTER(acp(i)->id)); } /** Update cup fixtures. */ @@ -285,7 +290,12 @@ end_week_round_update_fixtures(void) fixture_write_cup_fixtures(&lig(i).prom_rel.prom_games_cup); g_ptr_array_add(acps, &lig(i).prom_rel.prom_games_cup); } - + else if(week == (lig(i).teams->len - 1) * 2 && week_round == 1 && + team_is_user(g_array_index(lig(i).table.elements, TableElement, 0).team) != -1) + user_history_add(&usr(team_is_user(g_array_index(lig(i).table.elements, TableElement, 0).team)), + USER_HISTORY_CHAMPION, g_array_index(lig(i).table.elements, TableElement, 0).team_id, + lig(i).id, -1, ""); + for(i=0;ilen;i++) { if(query_cup_supercup_begins(&scp(i))) diff --git a/src/table.c b/src/table.c index da69cf12..f1b8e0e6 100644 --- a/src/table.c +++ b/src/table.c @@ -94,9 +94,10 @@ table_update_get_elements(TableElement **elements, const Fixture *fix) } } else - for(i=0;iclid)->tables->len;i++) + for(i=0;iclid)->len;i++) { - table = &g_array_index(cup_from_clid(fix->clid)->tables, Table, i); + table = &g_array_index(cup_get_last_tables(fix->clid), Table, i); + if(elements[0] == NULL || elements[1] == NULL) for(j=0;jelements->len;j++) { @@ -134,7 +135,7 @@ table_element_compare_func(gconstpointer a, if(clid < ID_CUP_START) cup_round = -1; else - cup_round = g_array_index(cup_from_clid(clid)->tables, Table, 0).round; + cup_round = cup_has_tables(clid); /*todo use misc_int_compare*/ if(element1->values[TABLE_PTS] > element2->values[TABLE_PTS]) @@ -175,7 +176,7 @@ table_element_compare_func(gconstpointer a, } if(fix[0] == NULL || fix[1] == NULL) - value = -1; + value = 0; else { if(fix[0]->result[0][0] + fix[1]->result[1][0] > diff --git a/src/team.c b/src/team.c index 8adcd8d2..7a649e9e 100644 --- a/src/team.c +++ b/src/team.c @@ -450,33 +450,36 @@ team_get_average_skill(const Team *tm, gboolean cskill) return (counter > 0) ? sum / (gfloat)counter : 0; } -/** Return the rank of the team. - @param tm The team we examine. - @param clid The league or cup we browse the table of. */ +/** Return the rank of the team in the league tables. */ gint -team_rank(const Team *tm, gint clid) +team_get_league_rank(const Team *tm) +{ + gint i; + GArray *elements = league_from_clid(tm->clid)->table.elements; + + for(i=0;ilen;i++) + if(g_array_index(elements, TableElement, i).team == tm) + return i + 1; + + g_warning("team_get_league_rank: no rank found for team %s in league %s. \n", + tm->name->str, league_cup_get_name_string(tm->clid)); + return -1; +} + +/** Return the rank of the team in the round robin stage. */ +gint +team_get_cup_rank(const Team *tm, const CupRound *cupround) { gint i, j; - GArray *elements = NULL; - if(clid < ID_CUP_START) + for(i=0;itables->len;i++) { - elements = league_from_clid(clid)->table.elements; - for(i=0;ilen;i++) - if(g_array_index(elements, TableElement, i).team == tm) - return i + 1; - } - else - { - for(i=0;itables->len;i++) - { - elements = g_array_index(cup_from_clid(clid)->tables, Table, i).elements; - for(j=0;jlen;j++) - if(g_array_index(elements, TableElement, j).team == tm) - return j + 1; - } + for(j=0;jtables, Table, i).elements->len;j++) + if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm) + return j + 1; } + g_warning("team_get_cup_rank: no rank found for team %s. \n ", tm->name->str); return -1; } @@ -780,7 +783,7 @@ team_compare_func(gconstpointer a, gconstpointer b, gpointer data) if(type == TEAM_COMPARE_LEAGUE_RANK) { if(tm1->clid == tm2->clid) - return_value = misc_int_compare(team_rank(tm2, tm2->clid), team_rank(tm1, tm1->clid)); + return_value = misc_int_compare(team_get_league_rank(tm2), team_get_league_rank(tm1)); else return_value = misc_int_compare( league_cup_get_index_from_clid(tm2->clid), diff --git a/src/team.h b/src/team.h index 3996b5c1..bdd686af 100644 --- a/src/team.h +++ b/src/team.h @@ -73,7 +73,10 @@ gint team_is_user(const Team *tm); gint -team_rank(const Team *tm, gint clid); +team_get_cup_rank(const Team *tm, const CupRound *cupround); + +gint +team_get_league_rank(const Team *tm); void team_change_structure(Team *tm, gint new_structure); diff --git a/src/treeview.c b/src/treeview.c index a368111a..e31a777d 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -863,7 +863,7 @@ treeview_create_fixtures_header(const Fixture *fix, GtkListStore *liststore, gbo void treeview_create_fixture(const Fixture *fix, GtkListStore *liststore) { - gint i; + gint i, rank; GtkTreeIter iter; GdkPixbuf *symbol[2] = {NULL, NULL}; gchar buf_result[SMALL], buf[3][SMALL]; @@ -896,10 +896,16 @@ treeview_create_fixture(const Fixture *fix, GtkListStore *liststore) fixture_result_to_buf(fix, buf_result); for(i=0;i<2;i++) - if(team_rank(fix->teams[i], fix->clid) != -1) + if(query_fixture_has_tables(fix)) + { + if(fix->clid < ID_CUP_START) + rank = team_get_league_rank(fix->teams[i]); + else + rank = team_get_cup_rank(fix->teams[i], cup_get_last_tables_round(fix->clid)); + sprintf(buf[i], "%s [%d]", - colour_bg, colour_fg, fix->teams[i]->name->str, - team_rank(fix->teams[i], fix->clid)); + colour_bg, colour_fg, fix->teams[i]->name->str, rank); + } else if(fix->clid >= ID_CUP_START && cup_from_clid(fix->clid)->type == CUP_TYPE_NATIONAL) sprintf(buf[i], "%s (%d)", @@ -1067,6 +1073,7 @@ treeview_create_single_table(GtkListStore *liststore, const Table *table, gint n gtk_list_store_append(liststore, &iter); elem = &g_array_index(table->elements, TableElement, i); + if(table->clid >= ID_CUP_START) symbol = treeview_helper_pixbuf_from_filename(elem->team->symbol->str); @@ -1105,7 +1112,6 @@ GtkTreeModel* treeview_create_table(gint clid) { gint i; - GArray *tables = NULL; GtkListStore *liststore = gtk_list_store_new(11, GDK_TYPE_PIXBUF, @@ -1119,15 +1125,15 @@ treeview_create_table(gint clid) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - + if(clid < ID_CUP_START) treeview_create_single_table(liststore, &league_from_clid(clid)->table, -1); else { - tables = cup_from_clid(clid)->tables; - for(i=0;ilen;i++) - treeview_create_single_table(liststore, &g_array_index(tables, Table, i), i + 1); + for(i=0;ilen;i++) + treeview_create_single_table(liststore, + &g_array_index(cup_get_last_tables(clid), Table, i), i + 1); } return GTK_TREE_MODEL(liststore); @@ -1543,7 +1549,7 @@ treeview_create_next_opponent(void) if(opp->clid < ID_CUP_START) { - sprintf(buf, "%d (%s)", team_rank(opp, opp->clid), league_from_clid(opp->clid)->name->str); + sprintf(buf, "%d (%s)", team_get_league_rank(opp), league_cup_get_name_string(opp->clid)); gtk_list_store_append(liststore, &iter); gtk_list_store_set(liststore, &iter, 0, _("Rank"), 1, buf, -1); } diff --git a/src/treeview_helper.c b/src/treeview_helper.c index 8850519b..504dc70a 100644 --- a/src/treeview_helper.c +++ b/src/treeview_helper.c @@ -255,6 +255,8 @@ treeview_helper_get_user_history_icon(gint history_type) return const_str("string_treeview_helper_user_history_symbol_relegated"); case USER_HISTORY_REACH_CUP_ROUND: return const_str("string_treeview_helper_user_history_symbol_reach_cup_round"); + case USER_HISTORY_CHAMPION: + return const_str("string_treeview_helper_user_history_symbol_champion"); } return NULL; diff --git a/src/user.c b/src/user.c index 8f4eabd8..470077ad 100644 --- a/src/user.c +++ b/src/user.c @@ -427,6 +427,7 @@ void user_change_team(User *user, Team *tm) { gint i; + user->tm = tm; user->team_id = tm->id; @@ -528,7 +529,6 @@ user_history_add(User *user, gint type, gint team_id, his->season = season; his->week = week; - /*todo: check for old cup comp */ his->type = type; his->team_id = team_id; his->value1 = value1; @@ -552,7 +552,7 @@ void user_history_to_string(const UserHistory *history, gchar *buf) { gchar buf2[SMALL]; - + switch(history->type) { default: @@ -610,5 +610,9 @@ user_history_to_string(const UserHistory *history, gchar *buf) history->value2 + 1, league_cup_get_name_string(history->value1)); break; + case USER_HISTORY_CHAMPION: + sprintf(buf, "You are champion of the %s!", + league_cup_get_name_string(history->value1)); + break; } } diff --git a/src/user_struct.h b/src/user_struct.h index 62aedac4..4e1eb3fe 100644 --- a/src/user_struct.h +++ b/src/user_struct.h @@ -128,6 +128,7 @@ enum UserHistoryType USER_HISTORY_WIN_FINAL, USER_HISTORY_LOSE_FINAL, USER_HISTORY_REACH_CUP_ROUND, + USER_HISTORY_CHAMPION, USER_HISTORY_END }; diff --git a/src/xml.c b/src/xml.c index 6ceed004..172a6694 100644 --- a/src/xml.c +++ b/src/xml.c @@ -153,9 +153,9 @@ xml_load_cups(const gchar *dirname, const gchar *basename) void xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename, const GPtrArray *dir_contents) { - gint i; - gchar buf[SMALL]; + gint i, j; Table new_table; + gchar buf[SMALL]; gchar *prefix = g_strndup(basename, strlen(basename) - 4); Cup *local_cup = cup; @@ -188,20 +188,19 @@ xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename, const GPtrAr sprintf(buf, "%s/%s_fixtures.xml", dirname, prefix); xml_loadsave_fixtures_read(buf, local_cup->fixtures); - for(i=0;ilen;i++) - { - if(g_str_has_prefix(((GString*)g_ptr_array_index(dir_contents, i))->str, - prefix) && - query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, - "_table")) + for(i=0;irounds->len;i++) + for(j=0;jlen;j++) { - new_table = table_new(); - sprintf(buf, "%s/%s", dirname, - ((GString*)g_ptr_array_index(dir_contents, i))->str); - xml_loadsave_table_read(buf, &new_table); - g_array_append_val(local_cup->tables, new_table); + sprintf(buf, "%s_round_%02d_table", prefix, i); + if(g_str_has_prefix(((GString*)g_ptr_array_index(dir_contents, j))->str, + buf)) + { + sprintf(buf, "%s/%s", dirname, ((GString*)g_ptr_array_index(dir_contents, j))->str); + new_table = table_new(); + xml_loadsave_table_read(buf, &new_table); + g_array_append_val(g_array_index(local_cup->rounds, CupRound, i).tables, new_table); + } } - } g_free(prefix); } diff --git a/src/xml_cup.c b/src/xml_cup.c index 70794c98..ab585394 100644 --- a/src/xml_cup.c +++ b/src/xml_cup.c @@ -359,14 +359,6 @@ xml_cup_read(const gchar *cup_name, GArray *cups) misc_print_error(&error, TRUE); } - if(g_array_index(new_cup.rounds, CupRound, new_cup.rounds->len - 1). - round_robin_number_of_groups != 0) - { - sprintf(buf, "xml_cup_read: last cup round of cup %s is round robin which is forbidden.\n", - new_cup.name->str); - main_exit_program(EXIT_CUP_LAST_ROUND, buf); - } - if(cups == cps) new_cup.id = cup_id_new; else if(cups == scps) diff --git a/src/xml_loadsave_cup.c b/src/xml_loadsave_cup.c index 23f151c3..f0949cc3 100644 --- a/src/xml_loadsave_cup.c +++ b/src/xml_loadsave_cup.c @@ -1,6 +1,7 @@ #include "cup.h" #include "file.h" #include "misc.h" +#include "table.h" #include "team.h" #include "xml.h" #include "xml_loadsave_cup.h" @@ -263,12 +264,6 @@ xml_loadsave_cup_write(const gchar *prefix, const Cup *cup) gchar buf[SMALL]; FILE *fil = NULL; - for(i=0;itables->len;i++) - { - sprintf(buf, "%s___cup_%d_table_%02d.xml", prefix, cup->id, i); - xml_loadsave_table_write(buf, &g_array_index(cup->tables, Table, i)); - } - sprintf(buf, "%s___cup_%d_fixtures.xml", prefix, cup->id); xml_loadsave_fixtures_write(buf, cup->fixtures); @@ -317,8 +312,7 @@ xml_loadsave_cup_write(const gchar *prefix, const Cup *cup) &g_array_index(cup->choose_teams, CupChooseTeam, i)); for(i=0;irounds->len;i++) - xml_loadsave_cup_write_round(fil, - &g_array_index(cup->rounds, CupRound, i)); + xml_loadsave_cup_write_round(fil, prefix, cup, i); if(cup->bye != NULL) { @@ -355,8 +349,12 @@ xml_loadsave_cup_write_choose_team(FILE *fil, const CupChooseTeam *choose_team) } void -xml_loadsave_cup_write_round(FILE *fil, const CupRound *cup_round) +xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gint round) { + gint i; + gchar buf[SMALL]; + const CupRound *cup_round = &g_array_index(cup->rounds, CupRound, round); + fprintf(fil, "<_%d>\n", TAG_CUP_ROUND); xml_write_int(fil, cup_round->home_away, @@ -373,4 +371,10 @@ xml_loadsave_cup_write_round(FILE *fil, const CupRound *cup_round) TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE, I1); fprintf(fil, "\n", TAG_CUP_ROUND); + + for(i=0;itables->len;i++) + { + sprintf(buf, "%s___cup_%d_round_%02d_table_%02d.xml", prefix, cup->id, round, i); + xml_loadsave_table_write(buf, &g_array_index(cup_round->tables, Table, i)); + } } diff --git a/src/xml_loadsave_cup.h b/src/xml_loadsave_cup.h index 79bada2e..097b785c 100644 --- a/src/xml_loadsave_cup.h +++ b/src/xml_loadsave_cup.h @@ -11,7 +11,7 @@ void xml_loadsave_cup_write(const gchar *prefix, const Cup *cup); void -xml_loadsave_cup_write_round(FILE *fil, const CupRound *cup_round); +xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gint round); void xml_loadsave_cup_write_choose_team(FILE *fil, const CupChooseTeam *choose_team); diff --git a/support_files/bygfoot.conf b/support_files/bygfoot.conf index 4313e887..ace4118f 100644 --- a/support_files/bygfoot.conf +++ b/support_files/bygfoot.conf @@ -21,7 +21,7 @@ int_opt_player_precision 0 int_opt_live_game_player_list_refresh 48 # whether some debugging info's shown (in the console) -int_opt_debug 60 +int_opt_debug 0 string_opt_player_names_file player_names.xml string_opt_constants_file bygfoot_constants diff --git a/support_files/bygfoot_constants b/support_files/bygfoot_constants index 60b073e3..08c92ca0 100644 --- a/support_files/bygfoot_constants +++ b/support_files/bygfoot_constants @@ -774,3 +774,4 @@ string_treeview_helper_user_history_symbol_reach_cup_round string_treeview_helper_user_history_symbol_job_offer_accepted string_treeview_helper_user_history_symbol_promoted string_treeview_helper_user_history_symbol_relegated +string_treeview_helper_user_history_symbol_champion diff --git a/support_files/definitions/belgium/cup_belgium.xml b/support_files/definitions/belgium/cup_belgium.xml index 53331ff3..ffa6e7ea 100644 --- a/support_files/definitions/belgium/cup_belgium.xml +++ b/support_files/definitions/belgium/cup_belgium.xml @@ -5,10 +5,27 @@ belgium national 3 - 38 - 2 + 35 + 3 + 0 + + + + 0 + + + + 0 + + + + 0 + + + + 0 @@ -18,18 +35,8 @@ - - - - - - - - - - - - + 0 + 1 diff --git a/support_files/definitions/belgium/cup_belgium_prom_games.xml b/support_files/definitions/belgium/cup_belgium_prom_games.xml index 2feb73d2..219ca01d 100644 --- a/support_files/definitions/belgium/cup_belgium_prom_games.xml +++ b/support_files/definitions/belgium/cup_belgium_prom_games.xml @@ -8,11 +8,7 @@ 1 - 2 - - - 0 - 1 + 1 diff --git a/support_files/definitions/belgium/league_belgium3a.xml b/support_files/definitions/belgium/league_belgium3a.xml index 28f75ae2..6b73d410 100644 --- a/support_files/definitions/belgium/league_belgium3a.xml +++ b/support_files/definitions/belgium/league_belgium3a.xml @@ -30,11 +30,6 @@ promotion - - - - - diff --git a/support_files/definitions/belgium/league_belgium3b.xml b/support_files/definitions/belgium/league_belgium3b.xml index 8d0a30fc..d4130353 100644 --- a/support_files/definitions/belgium/league_belgium3b.xml +++ b/support_files/definitions/belgium/league_belgium3b.xml @@ -30,10 +30,6 @@ promotion - - - - diff --git a/support_files/definitions/belgium/league_belgium4d.xml b/support_files/definitions/belgium/league_belgium4d.xml index bd5553a3..87682424 100644 --- a/support_files/definitions/belgium/league_belgium4d.xml +++ b/support_files/definitions/belgium/league_belgium4d.xml @@ -1,6 +1,6 @@ belgium4d - Vierde klasse D + Vierde klasse D 4de kl. D flag_be.png 1