diff --git a/bygfoot_misc.glade b/bygfoot_misc.glade index 1dbe90db..c131cf3c 100644 --- a/bygfoot_misc.glade +++ b/bygfoot_misc.glade @@ -1820,7 +1820,7 @@ GTK_UPDATE_ALWAYS False False - 1 0 10000 1 100 10 + 0 0 10000 1 100 10 @@ -1861,7 +1861,7 @@ True - label97 + 0 False False GTK_JUSTIFY_LEFT @@ -1903,7 +1903,7 @@ True - label99 + 0 False False GTK_JUSTIFY_LEFT @@ -1973,7 +1973,7 @@ GTK_UPDATE_ALWAYS False False - 1 0 100 1 5 10 + 0 0 100 1 5 10 @@ -2014,7 +2014,7 @@ True - label98 + 0 False False GTK_JUSTIFY_LEFT @@ -2056,7 +2056,7 @@ True - label100 + 0 False False GTK_JUSTIFY_LEFT diff --git a/src/Makefile.am b/src/Makefile.am index 890cd5df..2cb911b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,7 +33,7 @@ bygfoot_SOURCES = \ misc2_callback_func.c file.h finance.h game_gui.h maths.h misc2_callback_func.h option.h player.h support.h team.h treeview.h transfer.h user.h window.h \ misc2_interface.c misc2_interface.h misc2_callbacks.h support.h \ option.c option.h variables.h \ - option_gui.c file.h callbacks.h option_gui.h option.h support.h user.h variables.h \ + option_gui.c file.h game_gui.h callbacks.h option_gui.h option.h support.h user.h variables.h \ options_callbacks.c file.h options_callbacks.h options_interface.h option_gui.h support.h user.h variables.h window.h \ options_interface.c options_interface.h options_callbacks.h support.h \ player.c cup.h free.h game_gui.h league.h maths.h misc.h option.h player.h team.h user.h \ diff --git a/src/cup.c b/src/cup.c index 00996de0..c544c1af 100644 --- a/src/cup.c +++ b/src/cup.c @@ -3,6 +3,7 @@ #include "main.h" #include "maths.h" #include "misc.h" +#include "table.h" #include "team.h" #include "variables.h" #include "xml_league.h" @@ -111,6 +112,8 @@ cup_load_choose_teams(Cup *cup) GArray *leagues = NULL; GPtrArray *sids = NULL; + free_teams_array(&cup->teams, TRUE); + for(i=0;ichoose_teams->len;i++) { choose_team = &g_array_index(cup->choose_teams, CupChooseTeam, i); @@ -178,7 +181,7 @@ cup_load_choose_teams(Cup *cup) g_array_remove_index(teams, j); free_g_string_array(&sids); - free_teams_array(&teams); + free_teams_array(&teams, FALSE); } for(i=0;iteams->len;i++) @@ -203,6 +206,11 @@ cup_load_choose_team_user(Cup *cup) sscanf(choose_team->sid->str, "%[^0-9]%d", type, &number); + if(strcmp(type, "league") != 0 && + strcmp(type, "cup") != 0) + cup_choose_team_abort(cup, choose_team, TRUE); + + /** Teams from a league. */ if(strcmp(type, "league") == 0) { if(ligs->len < number || @@ -211,9 +219,11 @@ cup_load_choose_team_user(Cup *cup) for(i = choose_team->start_idx - 1; i <= choose_team->end_idx - 1; i++) { - if(!query_is_in_international_cups(&g_array_index(lig(number - 1).teams, Team, i))) + if(!query_is_in_international_cups( + g_array_index(lig(number - 1).table.elements, TableElement, i).team)) { - g_ptr_array_add(cup->user_teams, (gpointer)&g_array_index(lig(number - 1).teams, Team, i)); + g_ptr_array_add(cup->user_teams, + g_array_index(lig(number - 1).table.elements, TableElement, i).team); number_of_teams++; } @@ -227,40 +237,41 @@ cup_load_choose_team_user(Cup *cup) return; } - if(strcmp(type, "cup") == 0) + /** Teams from a cup; special case: in the first season, + we load random teams from the first league. */ + if(season == 1) { - if(season == 1) + if(lig(0).teams->len < choose_team->number_of_teams) + cup_choose_team_abort(cup, choose_team, TRUE); + + gint permutation[lig(0).teams->len]; + math_generate_permutation(permutation, 0, lig(0).teams->len - 1); + + for(i = choose_team->start_idx - 1; i <= choose_team->end_idx - 1; i++) { - if(lig(0).teams->len < choose_team->number_of_teams) - cup_choose_team_abort(cup, choose_team, TRUE); - - gint permutation[lig(0).teams->len]; - math_generate_permutation(permutation, 0, lig(0).teams->len - 1); - - for(i = choose_team->start_idx - 1; i <= choose_team->end_idx - 1; i++) + if(!query_is_in_international_cups( + &g_array_index(lig(number - 1).teams, + Team, permutation[i - choose_team->start_idx + 1]))) { - if(!query_is_in_international_cups( - &g_array_index(lig(number - 1).teams, - Team, permutation[i - choose_team->start_idx + 1]))) - { - g_ptr_array_add(cup->user_teams, - (gpointer)&g_array_index(lig(number - 1).teams, - Team, permutation[i - choose_team->start_idx + 1])); - number_of_teams++; - } - - if(number_of_teams == choose_team->number_of_teams) - break; + g_ptr_array_add(cup->user_teams, + (gpointer)&g_array_index(lig(number - 1).teams, + Team, permutation[i - choose_team->start_idx + 1])); + number_of_teams++; } - - if(number_of_teams != choose_team->number_of_teams) - cup_choose_team_abort(cup, choose_team, TRUE); - - return; + + if(number_of_teams == choose_team->number_of_teams) + break; } + + if(number_of_teams != choose_team->number_of_teams) + cup_choose_team_abort(cup, choose_team, TRUE); - /** todo: load teams from a cup */ + return; } + + /** Teams from a cup: normal case. We sort the teams that + participated in the cup. */ + } /** Print an error and exit the program if there's a problem loading diff --git a/src/fixture.c b/src/fixture.c index d6605a07..f1efe896 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -20,6 +20,7 @@ fixture_new(void) new.replay_number = 0; new.week_number = new.week_round_number = -1; new.teams[0] = new.teams[1] = NULL; + new.team_names[0] = new.team_names[1] = NULL; for(i=0;i<3;i++) new.result[0][i] = new.result[1][i] = 0; @@ -42,6 +43,8 @@ fixture_write_league_fixtures(League *league) teams = team_get_pointers_from_array(league->teams); + free_fixtures_array(league->fixtures, TRUE); + fixture_write_round_robin((gpointer)league, -1, teams); } @@ -53,6 +56,8 @@ fixture_write_cup_fixtures(Cup *cup) { GPtrArray *teams = NULL; + free_fixtures_array(cup->fixtures, TRUE); + if(g_array_index(cup->rounds, CupRound, 0). round_robin_number_of_groups > 0) fixture_write_cup_round_robin(cup, 0, NULL); @@ -300,8 +305,7 @@ 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); - cup->tables = g_array_new(FALSE, FALSE, sizeof(Table)); + free_cup_tables(cup->tables, TRUE); for(i=0;iname->str); + new.team_names[1] = g_string_new(away_team->name->str); + for(i=0;i<3;i++) new.result[0][i] = new.result[1][i] = 0; diff --git a/src/fixture_struct.h b/src/fixture_struct.h index 4d7462f9..cabb20c1 100644 --- a/src/fixture_struct.h +++ b/src/fixture_struct.h @@ -18,6 +18,9 @@ typedef struct gint week_number, week_round_number; /** The teams involved. */ Team *teams[2]; + /** Names of the teams. Needed when the team + pointers get invalid (e.g. after promotion/relegation) */ + GString *team_names[2]; /** The number of goals for each team in regulation, extra time and penalty shoot-out. */ gint result[2][3]; diff --git a/src/free.c b/src/free.c index f3a6a25c..23f93373 100644 --- a/src/free.c +++ b/src/free.c @@ -195,28 +195,35 @@ free_league(League *league) free_g_string(strings[i]); if(league->teams != NULL) - free_teams_array(&league->teams); + free_teams_array(&league->teams, FALSE); for(i=0;i<3;i++) free_g_array(arrays[i]); - free_g_array(&league->fixtures); + free_fixtures_array(&league->fixtures, FALSE); } /** Free the memory occupied by a teams array. @param teams The pointer to the array we free. */ void -free_teams_array(GArray **teams) +free_teams_array(GArray **teams, gboolean reset) { gint i; if(*teams == NULL) + { + if(reset) + *teams = g_array_new(FALSE, FALSE, sizeof(Team)); return; + } for(i=0;i<(*teams)->len;i++) free_team(&g_array_index(*teams, Team, i)); free_g_array(teams); + + if(reset) + *teams = g_array_new(FALSE, FALSE, sizeof(Team)); } /** @@ -289,10 +296,9 @@ free_cup(Cup *cup) &cup->short_name, &cup->symbol, &cup->sid}; - GArray **arrays[3] = + GArray **arrays[2] = {&cup->choose_teams, - &cup->rounds, - &cup->teams}; + &cup->rounds}; for(i=0;i<4;i++) free_g_string(strings[i]); @@ -302,30 +308,58 @@ free_cup(Cup *cup) free_cup_choose_team(&g_array_index(cup->choose_teams, CupChooseTeam, i)); free_cup_choose_team(&cup->choose_team_user); - if(cup->teams != NULL) - for(i=0;iteams->len;i++) - free_team(&g_array_index(cup->teams, Team, i)); + free_teams_array(&cup->teams, FALSE); - for(i=0;i<3;i++) + for(i=0;i<2;i++) free_g_array(arrays[i]); - free_g_array(&cup->fixtures); + free_fixtures_array(&cup->fixtures, FALSE); free_g_ptr_array(&cup->bye); free_g_ptr_array(&cup->user_teams); - free_cup_tables(cup->tables); + free_cup_tables(cup->tables, FALSE); +} + +/** Free an array of fixtures. */ +void +free_fixtures_array(GArray **fixtures, gboolean reset) +{ + gint i; + + if(*fixtures == NULL) + { + if(reset) + *fixtures = g_array_new(FALSE, FALSE, sizeof(Fixture)); + return; + } + + for(i=0;i<*fixtures->len;i++) + { + g_string_free(g_array_index(*fixtures, Fixture, i).team_names[0], TRUE); + g_string_free(g_array_index(*fixtures, Fixture, i).team_names[1], TRUE); + } + + free_g_array(fixtures); + + if(reset) + *fixtures = g_array_new(FALSE, FALSE, sizeof(Fixture)); } /** Free the memory occupied by the cup tables. @param tables The array containing the tables. */ void -free_cup_tables(GArray *tables) +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++) { @@ -334,6 +368,9 @@ free_cup_tables(GArray *tables) } free_g_array(&tables); + + if(reset) + tables = g_array_new(FALSE, FALSE, sizeof(Table)); } /** diff --git a/src/free.h b/src/free.h index 3386845c..f765a4cb 100644 --- a/src/free.h +++ b/src/free.h @@ -37,7 +37,7 @@ void free_league(League *league); void -free_teams_array(GArray **teams); +free_teams_array(GArray **teams, gboolean reset); void free_team(Team *team); @@ -49,7 +49,7 @@ void free_cup(Cup *cup); void -free_cup_tables(GArray *tables); +free_cup_tables(GArray *tables, gboolean reset); void free_cup_choose_team(CupChooseTeam *cup_choose_team); @@ -75,4 +75,7 @@ free_event(Event *event); void free_support_dirs(void); +void +free_fixtures_array(GArray **fixtures, gboolean reset); + #endif diff --git a/src/live_game.c b/src/live_game.c index 043fd7fe..cb9b4285 100644 --- a/src/live_game.c +++ b/src/live_game.c @@ -413,10 +413,11 @@ live_game_event_injury(gint team, gint player, gboolean create_new) { if(show && team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]) != -1 && - option_int("int_opt_user_pause_injury", - &usr(team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]])).options) && - !option_int("int_opt_user_auto_sub", - &usr(team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]])).options)) + ((option_int("int_opt_user_pause_injury", + &usr(team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]])).options) && + !option_int("int_opt_user_auto_sub", + &usr(team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]])).options)) || + tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->players->len == 11)) misc_callback_pause_live_game(); else if(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->players->len > 11) { @@ -790,10 +791,11 @@ live_game_event_send_off(gint team, gint player, gboolean second_yellow) if(match->subs_left[team] > 0) { if(show && team_is_user(tm[team]) != -1 && - option_int("int_opt_user_pause_red", - &usr(team_is_user(tm[team])).options) && - !option_int("int_opt_user_auto_sub", - &usr(team_is_user(tm[team])).options)) + ((option_int("int_opt_user_pause_red", + &usr(team_is_user(tm[team])).options) && + !option_int("int_opt_user_auto_sub", + &usr(team_is_user(tm[team])).options)) || + tm[team]->players->len == 1)) misc_callback_pause_live_game(); else if(tm[team]->players->len > 11) { diff --git a/src/misc_interface.c b/src/misc_interface.c index 2166f363..2569f41c 100644 --- a/src/misc_interface.c +++ b/src/misc_interface.c @@ -1068,7 +1068,7 @@ create_window_stadium (void) gtk_box_pack_start (GTK_BOX (vbox44), label91, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label91), GTK_JUSTIFY_LEFT); - spinbutton_capacity_adj = gtk_adjustment_new (1, 0, 10000, 1, 100, 10); + spinbutton_capacity_adj = gtk_adjustment_new (0, 0, 10000, 1, 100, 10); spinbutton_capacity = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_capacity_adj), 1, 0); gtk_widget_show (spinbutton_capacity); gtk_box_pack_start (GTK_BOX (vbox44), spinbutton_capacity, FALSE, FALSE, 0); @@ -1083,7 +1083,7 @@ create_window_stadium (void) gtk_box_pack_start (GTK_BOX (vbox46), label93, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label93), GTK_JUSTIFY_LEFT); - label_costs_capacity = gtk_label_new (_("label97")); + label_costs_capacity = gtk_label_new (_("0")); gtk_widget_show (label_costs_capacity); gtk_box_pack_start (GTK_BOX (vbox46), label_costs_capacity, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label_costs_capacity), GTK_JUSTIFY_LEFT); @@ -1093,7 +1093,7 @@ create_window_stadium (void) gtk_box_pack_start (GTK_BOX (vbox46), label95, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label95), GTK_JUSTIFY_LEFT); - label_duration_capacity = gtk_label_new (_("label99")); + label_duration_capacity = gtk_label_new (_("0")); gtk_widget_show (label_duration_capacity); gtk_box_pack_start (GTK_BOX (vbox46), label_duration_capacity, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label_duration_capacity), GTK_JUSTIFY_LEFT); @@ -1107,7 +1107,7 @@ create_window_stadium (void) gtk_box_pack_start (GTK_BOX (vbox45), label92, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label92), GTK_JUSTIFY_LEFT); - spinbutton_safety_adj = gtk_adjustment_new (1, 0, 100, 1, 5, 10); + spinbutton_safety_adj = gtk_adjustment_new (0, 0, 100, 1, 5, 10); spinbutton_safety = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_safety_adj), 1, 0); gtk_widget_show (spinbutton_safety); gtk_box_pack_start (GTK_BOX (vbox45), spinbutton_safety, FALSE, FALSE, 0); @@ -1122,7 +1122,7 @@ create_window_stadium (void) gtk_box_pack_start (GTK_BOX (vbox47), label94, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label94), GTK_JUSTIFY_LEFT); - label_costs_safety = gtk_label_new (_("label98")); + label_costs_safety = gtk_label_new (_("0")); gtk_widget_show (label_costs_safety); gtk_box_pack_start (GTK_BOX (vbox47), label_costs_safety, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label_costs_safety), GTK_JUSTIFY_LEFT); @@ -1132,7 +1132,7 @@ create_window_stadium (void) gtk_box_pack_start (GTK_BOX (vbox47), label96, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label96), GTK_JUSTIFY_LEFT); - label_duration_safety = gtk_label_new (_("label100")); + label_duration_safety = gtk_label_new (_("0")); gtk_widget_show (label_duration_safety); gtk_box_pack_start (GTK_BOX (vbox47), label_duration_safety, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label_duration_safety), GTK_JUSTIFY_LEFT); diff --git a/src/option_gui.c b/src/option_gui.c index 1a9d69b0..ecb41c6d 100644 --- a/src/option_gui.c +++ b/src/option_gui.c @@ -1,5 +1,6 @@ #include "callbacks.h" #include "file.h" +#include "game_gui.h" #include "option.h" #include "option_gui.h" #include "support.h" @@ -397,4 +398,6 @@ option_gui_write_options(void) strcmp(gtk_entry_get_text(entry_widgets[i]), opt_str("string_opt_font_name")) != 0) on_button_back_to_main_clicked(NULL, NULL); } + + game_gui_write_check_items(); } diff --git a/src/start_end.c b/src/start_end.c index 951333d0..35bf4c24 100644 --- a/src/start_end.c +++ b/src/start_end.c @@ -58,6 +58,8 @@ start_new_season(void) { gint i; + week = week_round = 1; + xml_name_read(opt_str("string_opt_player_names_file"), 1000); start_load_cup_teams(); @@ -75,7 +77,7 @@ start_write_variables(void) { gint i; - season = week = week_round = 1; + season = 1; cur_user = 0; /*d*/ diff --git a/src/treeview.c b/src/treeview.c index 90af68e5..96a68838 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -1634,7 +1634,7 @@ treeview_create_stadium_summary(GtkListStore *liststore) gtk_list_store_set(liststore, &iter, 0, _("Stadium capacity"), 1, buf, 2, "", -1); gtk_list_store_append(liststore, &iter); - sprintf(buf, "%.0f", current_user.tm->stadium.safety * 100); + sprintf(buf, "%.0f%%", current_user.tm->stadium.safety * 100); gtk_list_store_set(liststore, &iter, 0, _("Stadium safety"), 1, buf, 2, "", -1); if(current_user.counters[COUNT_USER_STADIUM_CAPACITY] + diff --git a/src/window.c b/src/window.c index e1651f0b..b60c46ea 100644 --- a/src/window.c +++ b/src/window.c @@ -129,10 +129,7 @@ window_show_stadium(void) gchar buf[SMALL]; const Team *tm = current_user.tm; GtkLabel *label_capacity, - *label_costs_capacity, *label_costs_safety, - *label_duration_capacity, *label_duration_safety, *label_stadium_status, *label_average_attendance; - GtkSpinButton *spinbutton_capacity, *spinbutton_safety; GtkProgressBar *progressbar_safety, *progressbar_average_attendance; gfloat average_attendance_perc = 0; @@ -140,38 +137,16 @@ window_show_stadium(void) window_create(WINDOW_STADIUM); label_capacity = GTK_LABEL(lookup_widget(window.stadium, "label_capacity")); - label_costs_capacity = GTK_LABEL(lookup_widget(window.stadium, "label_costs_capacity")); - label_costs_safety = GTK_LABEL(lookup_widget(window.stadium, "label_costs_safety")); - label_duration_capacity = GTK_LABEL(lookup_widget(window.stadium, "label_duration_capacity")); - label_duration_safety = GTK_LABEL(lookup_widget(window.stadium, "label_duration_safety")); label_stadium_status = GTK_LABEL(lookup_widget(window.stadium, "label_stadium_status")); label_average_attendance = GTK_LABEL(lookup_widget(window.stadium, "label_average_attendance")); - spinbutton_capacity = GTK_SPIN_BUTTON(lookup_widget(window.stadium, "spinbutton_capacity")); - spinbutton_safety = GTK_SPIN_BUTTON(lookup_widget(window.stadium, "spinbutton_safety")); - progressbar_safety = GTK_PROGRESS_BAR(lookup_widget(window.stadium, "progressbar_safety")); progressbar_average_attendance = GTK_PROGRESS_BAR(lookup_widget(window.stadium, "progressbar_average_attendance")); gui_label_set_text_from_int(label_capacity, tm->stadium.capacity, FALSE); - gui_label_set_text_from_int(label_costs_capacity, - (gint)rint(finance_wage_unit(tm) * - const_float("float_stadium_improvement_wage_unit_factor_seats")), - FALSE); - gui_label_set_text_from_int(label_costs_safety, - (gint)rint(finance_wage_unit(tm) * - (const_float("float_stadium_improvement_wage_unit_factor_safety") / - 100)), FALSE); - gui_label_set_text_from_int(label_duration_capacity, 1, FALSE); - gui_label_set_text_from_int(label_duration_safety, 1, FALSE); gui_label_set_text_from_int(label_average_attendance, tm->stadium.average_attendance, FALSE); - gtk_spin_button_set_value(spinbutton_capacity, - (gdouble)const_int("int_stadium_improvement_base_seats")); - gtk_spin_button_set_value(spinbutton_safety, - const_float("float_stadium_improvement_base_safety") * 100); - if(tm->stadium.games > 0) average_attendance_perc = (gfloat)(tm->stadium.average_attendance * tm->stadium.games) /