From dd7c288da958cdce4f5c71ae90a3aaa42d4cc936 Mon Sep 17 00:00:00 2001 From: gyboth Date: Sat, 21 Feb 2009 16:43:53 +0000 Subject: [PATCH] Added won/lost/drawn display in match preview. --- src/game.c | 2 +- src/game_gui.c | 21 +++++++++++++----- src/league.c | 2 +- src/load_save.c | 17 ++++++++++++-- src/start_end.c | 2 +- src/team.c | 59 ++++++++++++++++++++++++++++++++++++++++++------- src/team.h | 5 ++++- src/treeview.c | 17 +++++++++++--- src/treeview2.c | 2 +- src/user.c | 2 +- 10 files changed, 104 insertions(+), 25 deletions(-) diff --git a/src/game.c b/src/game.c index 8968dfbb..9717a273 100644 --- a/src/game.c +++ b/src/game.c @@ -365,7 +365,7 @@ game_assign_attendance(Fixture *fix) tm[0]->stadium.capacity); if(fix->clid < ID_CUP_START && - team_get_league_rank(tm[1]) < + team_get_league_rank(tm[1], fix->clid) < (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 108a02d8..37920ae3 100644 --- a/src/game_gui.c +++ b/src/game_gui.c @@ -284,12 +284,12 @@ game_gui_set_main_window_header(void) *label_money= GTK_LABEL(lookup_widget(window.main, "label_money")); GtkWidget *menu_users[2] = {lookup_widget(window.main, "menu_next_user"), lookup_widget(window.main, "menu_previous_user")}; + const Fixture *fix = team_get_fixture(current_user.tm, FALSE); gtk_label_set_text(label_user, current_user.name); gui_label_set_text_from_int(label_season, season, FALSE); gui_label_set_text_from_int(label_week, week, FALSE); gui_label_set_text_from_int(label_round, week_round, FALSE); - gui_label_set_text_from_int(label_rank, week_round, FALSE); if(!sett_int("int_opt_disable_finances")) { @@ -302,7 +302,19 @@ game_gui_set_main_window_header(void) gtk_widget_hide(GTK_WIDGET(lookup_widget(window.main, "label34"))); } - rank = team_get_league_rank(current_user.tm); + gtk_label_set_text(label_team, current_user.tm->name); + + if(fix == NULL) + { + rank = team_get_league_rank(current_user.tm, -1); + gtk_label_set_text(label_league, league_cup_get_name_string(current_user.tm->clid)); + } + else + { + rank = team_get_league_rank(current_user.tm, fix->clid); + gtk_label_set_text(label_league, league_cup_get_name_string(fix->clid)); + } + if(rank != 0) gui_label_set_text_from_int(label_rank, rank, FALSE); else @@ -311,9 +323,6 @@ game_gui_set_main_window_header(void) gtk_widget_hide(lookup_widget(window.main, "label29")); } - gtk_label_set_text(label_team, current_user.tm->name); - gtk_label_set_text(label_league, league_cup_get_name_string(current_user.tm->clid)); - for(i=0;i<2;i++) gtk_widget_set_sensitive(menu_users[i], (users->len > 1)); @@ -822,7 +831,7 @@ game_gui_show_job_offer(Team *team, Job *job, gint type) if(job == NULL || job->type == JOB_TYPE_NATIONAL) gui_label_set_text_from_int(label_rank, - team_get_league_rank(tm), FALSE); + team_get_league_rank(tm, -1), FALSE); misc_print_grouped_int( math_round_integer(tm->stadium.capacity * diff --git a/src/league.c b/src/league.c index 622a6406..8f16027b 100644 --- a/src/league.c +++ b/src/league.c @@ -493,7 +493,7 @@ league_season_start(League *league) for(i=0;iteams->len;i++) { team_is_top = - (team_get_league_rank(&g_array_index(league->teams, Team, i)) <= + (team_get_league_rank(&g_array_index(league->teams, Team, i), -1) <= user_champ_best_teams_limit && idx == 0 && user_champ); team_change_factor = diff --git a/src/load_save.c b/src/load_save.c index 5f51edae..5a464692 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -22,6 +22,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include "callbacks.h" #include "file.h" @@ -401,8 +402,20 @@ load_save_autosave(void) void load_save_write_autosave_name(gchar *filename) { - sprintf(filename, "autosave_%s_%s_%s_S%02d_W%02d", - usr(0).name, country.name, usr(0).tm->name, season, week); + gchar teamname[SMALL]; + gint i = 0; + + while(usr(0).tm->name[i] != '\0') + { + teamname[i] = (isspace(usr(0).tm->name[i]) == 0) ? + usr(0).tm->name[i] : '_'; + i++; + } + + teamname[i] = '\0'; + + sprintf(filename, "autosave_%s_%s_%s_S%02d_W%02d", + usr(0).name, country.name, teamname, season, week); } /** Try to load a savegame given on the command line. */ diff --git a/src/start_end.c b/src/start_end.c index 04e5d7b2..4d3295b3 100644 --- a/src/start_end.c +++ b/src/start_end.c @@ -138,7 +138,7 @@ start_new_season(void) { for(i=0;ilen;i++) { - sprintf(buf, "%d", team_get_league_rank(usr(i).tm)); + sprintf(buf, "%d", team_get_league_rank(usr(i).tm, -1)); user_history_add(&usr(i), USER_HISTORY_END_SEASON, usr(i).tm->name, league_cup_get_name_string(usr(i).tm->clid), diff --git a/src/team.c b/src/team.c index 0872f1c2..8b833369 100644 --- a/src/team.c +++ b/src/team.c @@ -446,27 +446,32 @@ team_get_average_talent(const Team *tm) /** Return the rank of the team in the league tables. */ gint -team_get_league_rank(const Team *tm) +team_get_league_rank(const Team *tm, gint clid) { #ifdef DEBUG printf("team_get_league_rank\n"); #endif - gint i, clid = team_get_table_clid(tm), rank = 0; + gint i, clid_local, rank = 0; GArray *elements = NULL; - if(clid < ID_CUP_START) + clid_local = (clid == -1) ? team_get_table_clid(tm) : clid; + + if(clid_local < ID_CUP_START) { - if(!query_league_active(league_from_clid(clid))) + if(!query_league_active(league_from_clid(clid_local))) return 0; - elements = league_table(league_from_clid(tm->clid))->elements; + elements = league_table(league_from_clid(clid_local))->elements; } else { + if(cup_has_tables(clid_local) == -1) + return 0; + rank = team_get_cup_rank( - tm, &g_array_index(cup_from_clid(clid)->rounds, CupRound, - cup_has_tables(clid)), FALSE); + tm, &g_array_index(cup_from_clid(clid_local)->rounds, CupRound, + cup_has_tables(clid_local)), FALSE); return (rank == -1) ? 0 : rank; } @@ -799,7 +804,8 @@ 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_get_league_rank(tm2), team_get_league_rank(tm1)); + return_value = misc_int_compare(team_get_league_rank(tm2, -1), + team_get_league_rank(tm1, -1)); else return_value = misc_int_compare(league_from_clid(tm2->clid)->layer, league_from_clid(tm1->clid)->layer); @@ -1364,3 +1370,40 @@ team_get_table_clid(const Team *tm) return tm->clid; } + +/** Write a won/lost/draw, gf:ga stat about the team's results in the + specified competition into the string. */ +void +team_write_overall_results(const Team *tm, gint clid, gchar *results) +{ + gint i, idx; + gint won, lost, drawn, gf, ga; + const GArray *fixtures = league_cup_get_fixtures(clid); + const Fixture *fix; + + won = lost = drawn = gf = ga = 0; + + for(i = 0; i < fixtures->len; i++) + { + fix = &g_array_index(fixtures, Fixture, i); + if(fix->attendance == -1) + break; + + if(fix->teams[0] != tm && fix->teams[1] != tm) + continue; + else + idx = (fix->teams[0] != tm); + + if(fix->result[0][0] == fix->result[1][0]) + drawn++; + else if(fix->result[idx][0] > fix->result[!idx][0]) + won++; + else + lost++; + + gf += fix->result[idx][0]; + ga += fix->result[!idx][0]; + } + + sprintf(results, "%d-%d-%d, %d:%d", won, lost, drawn, gf, ga); +} diff --git a/src/team.h b/src/team.h index 9275befb..4ec7ef25 100644 --- a/src/team.h +++ b/src/team.h @@ -83,7 +83,7 @@ gint team_get_cup_rank(const Team *tm, const CupRound *cupround, gboolean abort); gint -team_get_league_rank(const Team *tm); +team_get_league_rank(const Team *tm, gint clid); void team_change_structure(Team *tm, gint new_structure); @@ -136,6 +136,9 @@ team_get_table_value(const Team *tm, gint type); void team_write_results(const Team *tm, gchar *result_buf, gchar *goals_buf); +void +team_write_overall_results(const Team *tm, gint clid, gchar *results); + void team_write_own_results(const Team *tm, gchar *buf, gboolean sort, gboolean cup_matches); diff --git a/src/treeview.c b/src/treeview.c index 9513f4bc..b62c720f 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -1072,7 +1072,7 @@ treeview_create_fixture(const Fixture *fix, GtkListStore *ls) if(query_fixture_has_tables(fix)) { if(fix->clid < ID_CUP_START) - rank = team_get_league_rank(fix->teams[i]); + rank = team_get_league_rank(fix->teams[i], fix->clid); else rank = team_get_cup_rank(fix->teams[i], cup_get_last_tables_round(fix->clid), TRUE); @@ -1796,6 +1796,7 @@ treeview_create_next_opponent(void) fix->teams[fix->teams[0] == current_user.tm]; GtkListStore *ls = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); GtkTreeIter iter; + gint rank; if(opp == NULL) return NULL; @@ -1839,9 +1840,11 @@ treeview_create_next_opponent(void) gtk_list_store_append(ls, &iter); gtk_list_store_set(ls, &iter, 0, _("Team"), 1, opp->name, -1); - if(opp->clid < ID_CUP_START) + rank = team_get_league_rank(opp, fix->clid); + if(rank != 0) { - sprintf(buf, "%d (%s)", team_get_league_rank(opp), league_cup_get_name_string(opp->clid)); + sprintf(buf, "%d (%s)", rank, + league_cup_get_name_string(fix->clid)); gtk_list_store_append(ls, &iter); gtk_list_store_set(ls, &iter, 0, _("Rank"), 1, buf, -1); } @@ -1879,10 +1882,18 @@ treeview_create_next_opponent(void) gtk_list_store_append(ls, &iter); gtk_list_store_set(ls, &iter, 0, _("Goals"), 1, buf2, -1); + team_write_overall_results(opp, fix->clid, buf); + gtk_list_store_append(ls, &iter); + gtk_list_store_set(ls, &iter, 0, _("Overall results"), 1, buf, -1); + team_write_own_results(opp, buf, FALSE, TRUE); gtk_list_store_append(ls, &iter); /* The user's results against a specific team. */ gtk_list_store_set(ls, &iter, 0, _("Your results"), 1, buf, -1); + + team_write_overall_results(current_user.tm, fix->clid, buf); + gtk_list_store_append(ls, &iter); + gtk_list_store_set(ls, &iter, 0, _("Your overall results"), 1, buf, -1); return GTK_TREE_MODEL(ls); } diff --git a/src/treeview2.c b/src/treeview2.c index c3a49700..7e6577d3 100644 --- a/src/treeview2.c +++ b/src/treeview2.c @@ -352,7 +352,7 @@ treeview2_create_bets(GtkListStore *ls) if(query_fixture_has_tables(fix)) { if(fix->clid < ID_CUP_START) - rank = team_get_league_rank(fix->teams[j]); + rank = team_get_league_rank(fix->teams[j], fix->clid); else rank = team_get_cup_rank(fix->teams[j], cup_get_last_tables_round(fix->clid), TRUE); diff --git a/src/user.c b/src/user.c index 9eea0386..3a8241f0 100644 --- a/src/user.c +++ b/src/user.c @@ -407,7 +407,7 @@ user_weekly_update_counters(User *user) printf("user_weekly_update_counters\n"); #endif - gint rank = team_get_league_rank(user->tm); + gint rank = team_get_league_rank(user->tm, -1); gint teamslen = ((GArray*)(league_cup_get_teams(user->tm->clid)))->len; gint rank_bounds[2] = {(gint)rint(const_float("float_user_success_table_bound_upper") *