1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-02-07 15:18:41 +01:00

Added won/lost/drawn display in match preview.

This commit is contained in:
gyboth 2009-02-21 16:43:53 +00:00
parent 88ce988b8d
commit dd7c288da9
10 changed files with 104 additions and 25 deletions

View File

@ -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");

View File

@ -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 *

View File

@ -493,7 +493,7 @@ league_season_start(League *league)
for(i=0;i<league->teams->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 =

View File

@ -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 <ctype.h>
#include "callbacks.h"
#include "file.h"
@ -401,8 +402,20 @@ load_save_autosave(void)
void
load_save_write_autosave_name(gchar *filename)
{
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, usr(0).tm->name, season, week);
usr(0).name, country.name, teamname, season, week);
}
/** Try to load a savegame given on the command line. */

View File

@ -138,7 +138,7 @@ start_new_season(void)
{
for(i=0;i<users->len;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),

View File

@ -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);
}

View File

@ -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);

View File

@ -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,11 +1882,19 @@ 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);
}

View File

@ -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);

View File

@ -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") *