1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-02-20 13:30:41 +01:00

League stats partly done.

This commit is contained in:
gyboth 2005-04-29 19:48:02 +00:00
parent b0f55c810f
commit ccd5f173c8
27 changed files with 900 additions and 364 deletions

View File

@ -69,7 +69,7 @@
<accelerator key="l" modifiers="GDK_CONTROL_MASK | GDK_SHIFT_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image299">
<widget class="GtkImage" id="image303">
<property name="visible">True</property>
<property name="stock">gtk-open</property>
<property name="icon_size">1</property>
@ -137,7 +137,7 @@
<accelerator key="p" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image300">
<widget class="GtkImage" id="image304">
<property name="visible">True</property>
<property name="stock">gtk-preferences</property>
<property name="icon_size">1</property>
@ -239,11 +239,17 @@
</child>
<child>
<widget class="GtkMenuItem" id="players">
<widget class="GtkSeparatorMenuItem" id="trennlinie13">
<property name="visible">True</property>
<property name="label" translatable="yes">Players</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menu_league_stats">
<property name="visible">True</property>
<property name="label" translatable="yes">League stats</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_players_activate" last_modification_time="Fri, 25 Mar 2005 19:10:36 GMT"/>
<signal name="activate" handler="on_menu_league_stats_activate" last_modification_time="Thu, 28 Apr 2005 17:31:46 GMT"/>
</widget>
</child>
@ -688,7 +694,7 @@
<accelerator key="F9" modifiers="0" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image301">
<widget class="GtkImage" id="image305">
<property name="visible">True</property>
<property name="stock">gtk-go-forward</property>
<property name="icon_size">1</property>
@ -710,7 +716,7 @@
<accelerator key="F8" modifiers="0" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image302">
<widget class="GtkImage" id="image306">
<property name="visible">True</property>
<property name="stock">gtk-go-back</property>
<property name="icon_size">1</property>
@ -732,7 +738,7 @@
<accelerator key="F12" modifiers="0" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image303">
<widget class="GtkImage" id="image307">
<property name="visible">True</property>
<property name="stock">gtk-justify-fill</property>
<property name="icon_size">1</property>

View File

@ -20,7 +20,7 @@ bygfoot_SOURCES = \
game_gui.c file.h callbacks.h file.h game_gui.h gui.h league.h live_game.h maths.h misc.h option.h treeview.h support.h team.h user.h variables.h window.h \
gui.c gui.h misc.h support.h variables.h window.h \
interface.c callbacks.h interface.h support.h \
league.c cup.h league.h maths.h option.h player.h user.h table.h team.h variables.h \
league.c cup.h league.h maths.h option.h player.h stat.h table.h team.h user.h variables.h \
live_game.c fixture.h free.h game.h game_gui.h live_game.h maths.h misc_callback_func.h option.h player.h support.h team.h treeview.h user.h variables.h window.h \
load_save.c callbacks.h file.h game_gui.h gui.h load_save.h option.h support.h user.h variables.h xml_loadsave_misc.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_transfers.h xml_loadsave_users.h xml.h \
main.c cup_struct.h misc_callbacks.h file.h free.h league_struct.h live_game.h main.h transfer_struct.h variables.h window.h \
@ -37,7 +37,8 @@ bygfoot_SOURCES = \
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 fixture.h free.h game_gui.h league.h maths.h misc.h option.h player.h team.h user.h \
start_end.c cup.h file.h finance.h fixture.h free.h game_gui.h gui.h league.h load_save.h live_game.h main.h maths.h option.h start_end.h table.h team.h transfer.h user.h variables.h xml_name.h \
start_end.c cup.h file.h finance.h fixture.h free.h game_gui.h gui.h league.h load_save.h live_game.h main.h maths.h option.h start_end.h stat.h table.h team.h transfer.h user.h variables.h xml_name.h \
stat.c free.h option.h player.h stat.h table_struct.h team.h variables.h \
support.c support.h \
table.c cup.h league.h table.h variables.h \
team.c cup.h fixture.h game.h game_gui.h league.h maths.h misc.h option.h player.h team.h transfer.h user.h \

View File

@ -113,18 +113,6 @@ callback_player_clicked(gint idx, GdkEventButton *event)
}
}
/*d*/
/* gint i; */
/* printf("\n"); */
/* for(i=0;i<current_user.tm->players->len;i++) */
/* printf("%06d %s\n", g_array_index(current_user.tm->players, Player, i).id, */
/* g_array_index(current_user.tm->players, Player, i).name->str); */
/* for(i=0;i<current_user.tm->players->len;i++) */
/* printf("%d %s %d\n", i, */
/* g_array_index(current_user.tm->players, Player, i).name->str, */
/* g_array_index(current_user.tm->players, Player, i).id); */
setsav0;
}
@ -200,6 +188,8 @@ callback_show_tables(gint type)
while(clid >= ID_CUP_START && cup_has_tables(clid) == -1)
clid = league_cup_get_previous_clid(clid);
}
else
g_warning("callback_show_tables: unknown type %d \n", type);
stat1 = clid;
@ -389,6 +379,9 @@ callback_show_player_list(gint type)
switch(type)
{
default:
g_warning("callback_show_player_list: unknown type %d \n", type);
break;
case SHOW_CURRENT:
stat1 = current_user.tm->clid;
break;
@ -431,6 +424,9 @@ callback_show_fixtures_week(gint type)
{
switch(type)
{
default:
g_warning("callback_show_fixtures_week: unknown type %d \n", type);
break;
case SHOW_CURRENT:
if(week == 1 && week_round == 1)
{
@ -458,3 +454,31 @@ callback_show_fixtures_week(gint type)
treeview_show_fixtures_week(stat1, stat2);
}
/** Show a page with the information in the league stats
structure. */
void
callback_show_league_stats(gint type)
{
switch(type)
{
default:
g_warning("callback_show_league_stats: unknown type %d \n", type);
break;
case SHOW_CURRENT:
stat1 = current_user.tm->clid;
break;
case SHOW_NEXT_LEAGUE:
stat1 = league_cup_get_next_clid(stat1);
while(stat1 >= ID_CUP_START)
stat1 = league_cup_get_next_clid(stat1);
break;
case SHOW_PREVIOUS_LEAGUE:
stat1 = league_cup_get_previous_clid(stat1);
while(stat1 >= ID_CUP_START)
stat1 = league_cup_get_previous_clid(stat1);
break;
}
treeview_show_league_stats(stat1);
}

View File

@ -45,4 +45,7 @@ callback_show_last_match_stats(void);
void
callback_show_fixtures_week(gint type);
void
callback_show_league_stats(gint type);
#endif

View File

@ -264,6 +264,9 @@ on_button_cl_back_clicked (GtkButton *button,
case STATUS_SHOW_PLAYER_LIST:
callback_show_player_list(SHOW_PREVIOUS_LEAGUE);
break;
case STATUS_SHOW_LEAGUE_STATS:
callback_show_league_stats(SHOW_PREVIOUS_LEAGUE);
break;
}
}
@ -286,6 +289,9 @@ on_button_cl_forward_clicked (GtkButton *button,
case STATUS_SHOW_PLAYER_LIST:
callback_show_player_list(SHOW_NEXT_LEAGUE);
break;
case STATUS_SHOW_LEAGUE_STATS:
callback_show_league_stats(SHOW_NEXT_LEAGUE);
break;
}
}
@ -330,10 +336,13 @@ on_menu_tables_activate (GtkMenuItem *menuitem,
void
on_players_activate (GtkMenuItem *menuitem,
gpointer user_data)
on_menu_league_stats_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
stat0 = STATUS_SHOW_LEAGUE_STATS;
callback_show_league_stats(SHOW_CURRENT);
gui_set_arrows();
}

View File

@ -90,10 +90,6 @@ void
on_menu_tables_activate (GtkMenuItem *menuitem,
gpointer user_data);
void
on_players_activate (GtkMenuItem *menuitem,
gpointer user_data);
void
on_menu_season_history_activate (GtkMenuItem *menuitem,
gpointer user_data);
@ -256,4 +252,8 @@ void
on_menu_reset_players_activate (GtkMenuItem *menuitem,
gpointer user_data);
void
on_menu_league_stats_activate (GtkMenuItem *menuitem,
gpointer user_data);
#endif

View File

@ -84,6 +84,8 @@ enum Status0Value
STATUS_TRANSFER_OFFER,
STATUS_CUSTOM_STRUCTURE,
STATUS_SHOW_LEAGUE_RESULTS,
STATUS_SHOW_LEAGUE_STATS,
STATUS_SHOW_SEASON_HISTORY,
STATUS_CONTRACT_OFFER,
STATUS_SHOW_PLAYER_LIST,
STATUS_FIRE_PLAYER,

View File

@ -211,8 +211,33 @@ free_league(League *league)
free_g_array(&league->fixtures);
free_league_stats(&league->stats);
}
/** Free the league stats. */
void
free_league_stats(LeagueStat *stats)
{
gint i;
for(i=0;i<stats->teams_off->len;i++)
g_string_free(g_array_index(stats->teams_off, Stat, i).value_string, TRUE);
free_g_array(&stats->teams_off);
for(i=0;i<stats->teams_def->len;i++)
g_string_free(g_array_index(stats->teams_def, Stat, i).value_string, TRUE);
free_g_array(&stats->teams_def);
for(i=0;i<stats->player_scorers->len;i++)
g_string_free(g_array_index(stats->player_scorers, Stat, i).value_string, TRUE);
free_g_array(&stats->player_scorers);
for(i=0;i<stats->player_goalies->len;i++)
g_string_free(g_array_index(stats->player_goalies, Stat, i).value_string, TRUE);
free_g_array(&stats->player_goalies);
}
/** Free a table. */
void
free_table(Table *table)

View File

@ -78,4 +78,7 @@ free_support_dirs(void);
void
free_table(Table *table);
void
free_league_stats(LeagueStat *stats);
#endif

View File

@ -120,6 +120,7 @@ gui_set_arrows(void)
stat0 == STATUS_SHOW_FIXTURES_WEEK)
gui_set_arrow_pair(1, TRUE);
else if(stat0 == STATUS_SHOW_TABLES ||
stat0 == STATUS_SHOW_PLAYER_LIST)
stat0 == STATUS_SHOW_PLAYER_LIST ||
stat0 == STATUS_SHOW_LEAGUE_STATS)
gui_set_arrow_pair(0, TRUE);
}

View File

@ -38,7 +38,7 @@ create_main_window (void)
GtkWidget *menu_new;
GtkWidget *menu_open;
GtkWidget *menu_load_last_save;
GtkWidget *image299;
GtkWidget *image303;
GtkWidget *menu_save;
GtkWidget *menu_save_as;
GtkWidget *trennlinie1;
@ -46,7 +46,7 @@ create_main_window (void)
GtkWidget *menu_options;
GtkWidget *menu_options_menu;
GtkWidget *menu_preferences;
GtkWidget *image300;
GtkWidget *image304;
GtkWidget *trennlinie7;
GtkWidget *menu_job_offers;
GtkWidget *menu_live_game;
@ -57,7 +57,8 @@ create_main_window (void)
GtkWidget *menu_fixtures;
GtkWidget *menu_tables;
GtkWidget *menu_my_league_results;
GtkWidget *players;
GtkWidget *trennlinie13;
GtkWidget *menu_league_stats;
GtkWidget *menu_season_history;
GtkWidget *menu_team;
GtkWidget *menu_team_menu;
@ -113,11 +114,11 @@ create_main_window (void)
GtkWidget *menu_user_show_history;
GtkWidget *trennlinie9;
GtkWidget *menu_next_user;
GtkWidget *image301;
GtkWidget *image305;
GtkWidget *menu_previous_user;
GtkWidget *image302;
GtkWidget *image306;
GtkWidget *menu_manage_users;
GtkWidget *image303;
GtkWidget *image307;
GtkWidget *menu_finances_stadium;
GtkWidget *menu_finances_stadium_menu;
GtkWidget *menu_show_finances;
@ -249,9 +250,9 @@ create_main_window (void)
GDK_l, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
GTK_ACCEL_VISIBLE);
image299 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU);
gtk_widget_show (image299);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_load_last_save), image299);
image303 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU);
gtk_widget_show (image303);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_load_last_save), image303);
menu_save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
gtk_widget_show (menu_save);
@ -284,9 +285,9 @@ create_main_window (void)
GDK_p, GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE);
image300 = gtk_image_new_from_stock ("gtk-preferences", GTK_ICON_SIZE_MENU);
gtk_widget_show (image300);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_preferences), image300);
image304 = gtk_image_new_from_stock ("gtk-preferences", GTK_ICON_SIZE_MENU);
gtk_widget_show (image304);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_preferences), image304);
trennlinie7 = gtk_separator_menu_item_new ();
gtk_widget_show (trennlinie7);
@ -339,9 +340,14 @@ create_main_window (void)
gtk_widget_show (menu_my_league_results);
gtk_container_add (GTK_CONTAINER (menu_figures_menu), menu_my_league_results);
players = gtk_menu_item_new_with_mnemonic (_("Players"));
gtk_widget_show (players);
gtk_container_add (GTK_CONTAINER (menu_figures_menu), players);
trennlinie13 = gtk_separator_menu_item_new ();
gtk_widget_show (trennlinie13);
gtk_container_add (GTK_CONTAINER (menu_figures_menu), trennlinie13);
gtk_widget_set_sensitive (trennlinie13, FALSE);
menu_league_stats = gtk_menu_item_new_with_mnemonic (_("League stats"));
gtk_widget_show (menu_league_stats);
gtk_container_add (GTK_CONTAINER (menu_figures_menu), menu_league_stats);
menu_season_history = gtk_menu_item_new_with_mnemonic (_("Season history"));
gtk_widget_show (menu_season_history);
@ -590,9 +596,9 @@ create_main_window (void)
GDK_F9, 0,
GTK_ACCEL_VISIBLE);
image301 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_MENU);
gtk_widget_show (image301);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_next_user), image301);
image305 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_MENU);
gtk_widget_show (image305);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_next_user), image305);
menu_previous_user = gtk_image_menu_item_new_with_mnemonic (_("Previous user"));
gtk_widget_show (menu_previous_user);
@ -601,9 +607,9 @@ create_main_window (void)
GDK_F8, 0,
GTK_ACCEL_VISIBLE);
image302 = gtk_image_new_from_stock ("gtk-go-back", GTK_ICON_SIZE_MENU);
gtk_widget_show (image302);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_previous_user), image302);
image306 = gtk_image_new_from_stock ("gtk-go-back", GTK_ICON_SIZE_MENU);
gtk_widget_show (image306);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_previous_user), image306);
menu_manage_users = gtk_image_menu_item_new_with_mnemonic (_("Manage users"));
gtk_widget_show (menu_manage_users);
@ -612,9 +618,9 @@ create_main_window (void)
GDK_F12, 0,
GTK_ACCEL_VISIBLE);
image303 = gtk_image_new_from_stock ("gtk-justify-fill", GTK_ICON_SIZE_MENU);
gtk_widget_show (image303);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_manage_users), image303);
image307 = gtk_image_new_from_stock ("gtk-justify-fill", GTK_ICON_SIZE_MENU);
gtk_widget_show (image307);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_manage_users), image307);
menu_finances_stadium = gtk_menu_item_new_with_mnemonic (_("FinStad"));
gtk_widget_show (menu_finances_stadium);
@ -1076,8 +1082,8 @@ create_main_window (void)
g_signal_connect ((gpointer) menu_my_league_results, "activate",
G_CALLBACK (on_menu_my_league_results_activate),
NULL);
g_signal_connect ((gpointer) players, "activate",
G_CALLBACK (on_players_activate),
g_signal_connect ((gpointer) menu_league_stats, "activate",
G_CALLBACK (on_menu_league_stats_activate),
NULL);
g_signal_connect ((gpointer) menu_season_history, "activate",
G_CALLBACK (on_menu_season_history_activate),
@ -1254,7 +1260,7 @@ create_main_window (void)
GLADE_HOOKUP_OBJECT (main_window, menu_new, "menu_new");
GLADE_HOOKUP_OBJECT (main_window, menu_open, "menu_open");
GLADE_HOOKUP_OBJECT (main_window, menu_load_last_save, "menu_load_last_save");
GLADE_HOOKUP_OBJECT (main_window, image299, "image299");
GLADE_HOOKUP_OBJECT (main_window, image303, "image303");
GLADE_HOOKUP_OBJECT (main_window, menu_save, "menu_save");
GLADE_HOOKUP_OBJECT (main_window, menu_save_as, "menu_save_as");
GLADE_HOOKUP_OBJECT (main_window, trennlinie1, "trennlinie1");
@ -1262,7 +1268,7 @@ create_main_window (void)
GLADE_HOOKUP_OBJECT (main_window, menu_options, "menu_options");
GLADE_HOOKUP_OBJECT (main_window, menu_options_menu, "menu_options_menu");
GLADE_HOOKUP_OBJECT (main_window, menu_preferences, "menu_preferences");
GLADE_HOOKUP_OBJECT (main_window, image300, "image300");
GLADE_HOOKUP_OBJECT (main_window, image304, "image304");
GLADE_HOOKUP_OBJECT (main_window, trennlinie7, "trennlinie7");
GLADE_HOOKUP_OBJECT (main_window, menu_job_offers, "menu_job_offers");
GLADE_HOOKUP_OBJECT (main_window, menu_live_game, "menu_live_game");
@ -1273,7 +1279,8 @@ create_main_window (void)
GLADE_HOOKUP_OBJECT (main_window, menu_fixtures, "menu_fixtures");
GLADE_HOOKUP_OBJECT (main_window, menu_tables, "menu_tables");
GLADE_HOOKUP_OBJECT (main_window, menu_my_league_results, "menu_my_league_results");
GLADE_HOOKUP_OBJECT (main_window, players, "players");
GLADE_HOOKUP_OBJECT (main_window, trennlinie13, "trennlinie13");
GLADE_HOOKUP_OBJECT (main_window, menu_league_stats, "menu_league_stats");
GLADE_HOOKUP_OBJECT (main_window, menu_season_history, "menu_season_history");
GLADE_HOOKUP_OBJECT (main_window, menu_team, "menu_team");
GLADE_HOOKUP_OBJECT (main_window, menu_team_menu, "menu_team_menu");
@ -1325,11 +1332,11 @@ create_main_window (void)
GLADE_HOOKUP_OBJECT (main_window, menu_user_show_history, "menu_user_show_history");
GLADE_HOOKUP_OBJECT (main_window, trennlinie9, "trennlinie9");
GLADE_HOOKUP_OBJECT (main_window, menu_next_user, "menu_next_user");
GLADE_HOOKUP_OBJECT (main_window, image301, "image301");
GLADE_HOOKUP_OBJECT (main_window, image305, "image305");
GLADE_HOOKUP_OBJECT (main_window, menu_previous_user, "menu_previous_user");
GLADE_HOOKUP_OBJECT (main_window, image302, "image302");
GLADE_HOOKUP_OBJECT (main_window, image306, "image306");
GLADE_HOOKUP_OBJECT (main_window, menu_manage_users, "menu_manage_users");
GLADE_HOOKUP_OBJECT (main_window, image303, "image303");
GLADE_HOOKUP_OBJECT (main_window, image307, "image307");
GLADE_HOOKUP_OBJECT (main_window, menu_finances_stadium, "menu_finances_stadium");
GLADE_HOOKUP_OBJECT (main_window, menu_finances_stadium_menu, "menu_finances_stadium_menu");
GLADE_HOOKUP_OBJECT (main_window, menu_show_finances, "menu_show_finances");

View File

@ -3,9 +3,10 @@
#include "maths.h"
#include "option.h"
#include "player.h"
#include "user.h"
#include "stat.h"
#include "table.h"
#include "team.h"
#include "user.h"
#include "variables.h"
/**
@ -43,6 +44,12 @@ league_new(gboolean new_id)
new.first_week = new.week_gap = 1;
new.yellow_red = 1000;
new.stats.clid = new.id;
new.stats.teams_off = g_array_new(FALSE, FALSE, sizeof(Stat));
new.stats.teams_def = g_array_new(FALSE, FALSE, sizeof(Stat));
new.stats.player_scorers = g_array_new(FALSE, FALSE, sizeof(Stat));
new.stats.player_goalies = g_array_new(FALSE, FALSE, sizeof(Stat));
return new;
}

View File

@ -2,8 +2,9 @@
#define LEAGUE_STRUCT_H
#include "bygfoot.h"
#include "table_struct.h"
#include "cup_struct.h"
#include "stat_struct.h"
#include "table_struct.h"
enum PromRelType
{
@ -81,6 +82,8 @@ typedef struct
Table table;
/** The fixtures of a season for the league. */
GArray *fixtures;
/** The current league statistics. */
LeagueStat stats;
} League;
#endif

View File

@ -309,10 +309,12 @@ player_all_cards(const Player *pl)
gint
player_compare_func(gconstpointer a, gconstpointer b, gpointer data)
{
gint type = GPOINTER_TO_INT(data) % 100;
const Player *pl1 = (GPOINTER_TO_INT(data) < 100) ?
gint data_int = ABS(GPOINTER_TO_INT(data));
gint data_int2 = GPOINTER_TO_INT(data);
gint type = data_int % 100;
const Player *pl1 = (data_int < 100) ?
*(const Player**)a : (const Player*)a;
const Player *pl2 = (GPOINTER_TO_INT(data) < 100) ?
const Player *pl2 = (data_int < 100) ?
*(const Player**)b : (const Player*)b;
gint return_value = 0;
@ -335,10 +337,26 @@ player_compare_func(gconstpointer a, gconstpointer b, gpointer data)
return_value = misc_int_compare(pl2->pos, pl1->pos);
else
return_value = 0;
/* return_value = */
/* misc_float_compare(player_get_game_skill(pl1, TRUE), */
/* player_get_game_skill(pl2, TRUE)); */
}
else if(type == PLAYER_COMPARE_ATTRIBUTE_LEAGUE_GOALS)
{
gint goals1 = player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_GOALS),
games1 = player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_GAMES),
shots1 = player_games_goals_get(pl1, pl1->team->clid, PLAYER_VALUE_SHOTS),
goals2 = player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_GOALS),
games2 = player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_GAMES),
shots2 = player_games_goals_get(pl2, pl2->team->clid, PLAYER_VALUE_SHOTS);
if(goals1 != goals2)
return_value = misc_int_compare(goals1, goals2);
else if(games1 != games2)
return_value = misc_int_compare(games2, games1);
else
return_value = misc_int_compare(shots2, shots1);
}
if(data_int2 != 0)
return_value *= (data_int / data_int2);
return return_value;
}

View File

@ -9,6 +9,7 @@ enum PlayerCompareAttrib
{
PLAYER_COMPARE_ATTRIBUTE_GAME_SKILL = 0,
PLAYER_COMPARE_ATTRIBUTE_POS,
PLAYER_COMPARE_ATTRIBUTE_LEAGUE_GOALS,
PLAYER_COMPARE_ATTRIBUTE_END
};

View File

@ -12,6 +12,7 @@
#include "maths.h"
#include "option.h"
#include "start_end.h"
#include "stat.h"
#include "table.h"
#include "team.h"
#include "transfer.h"
@ -40,7 +41,7 @@ WeekFunc start_week_funcs[] =
{start_week_update_users, start_week_update_user_teams,
start_week_update_user_finances, transfer_update, NULL};
WeekFunc end_week_funcs[] = {NULL};
WeekFunc end_week_funcs[] = {stat_update_leagues};
/** Generate the teams etc. */
void
@ -183,6 +184,8 @@ end_week_round(void)
if(new_week)
{
end_week();
if(query_start_end_season_end())
{
season++;
@ -360,6 +363,19 @@ start_week(void)
}
}
/** Finish a week. */
void
end_week(void)
{
WeekFunc *end_func = end_week_funcs;
while(*end_func != NULL)
{
(*end_func)();
end_func++;
}
}
/** Age increase etc. of players.
CPU teams get updated at the end of their matches
(to avoid cup teams getting updated too often). */

View File

@ -57,4 +57,7 @@ query_start_end_season_end(void);
void
start_new_season_team_movements(void);
void
end_week(void);
#endif

112
src/stat.c Normal file
View File

@ -0,0 +1,112 @@
#include "free.h"
#include "option.h"
#include "player.h"
#include "stat.h"
#include "table_struct.h"
#include "team.h"
#include "variables.h"
/** Update the league stats. */
void
stat_update_leagues(void)
{
gint i;
for(i=0;i<ligs->len;i++)
if(lig(i).first_week - 1 + (lig(i).teams->len - 1) * 2 * lig(i).week_gap >= week)
{
free_league_stats(&lig(i).stats);
lig(i).stats.teams_off = stat_update_league_teams(lig(i).teams, TEAM_COMPARE_OFFENSIVE);
lig(i).stats.teams_def = stat_update_league_teams(lig(i).teams, TEAM_COMPARE_DEFENSE);
stat_update_league_players(&lig(i));
}
}
/** Update the league player stats. */
void
stat_update_league_players(League *league)
{
gint i, j;
GPtrArray *players_sorted[2] = {g_ptr_array_new(),
g_ptr_array_new()};
GArray *players[2] = {g_array_new(FALSE, FALSE, sizeof(Stat)),
g_array_new(FALSE, FALSE, sizeof(Stat))};
Player *pl = NULL;
gint maxlen = const_int("int_stat_players_len");
Stat new_stat;
for(i=0;i<league->teams->len;i++)
for(j=0;j<g_array_index(league->teams, Team, i).players->len;j++)
{
pl = &g_array_index(g_array_index(league->teams, Team, i).players, Player, j);
if(pl->pos != PLAYER_POS_GOALIE)
g_ptr_array_add(players_sorted[0], pl);
else if(player_games_goals_get(pl, pl->team->clid, PLAYER_VALUE_GAMES) >=
const_float("float_stat_goalie_percentage") *
(gfloat)team_get_table_value(pl->team, TABLE_PLAYED))
g_ptr_array_add(players_sorted[1], pl);
}
g_ptr_array_sort_with_data(players_sorted[0], player_compare_func,
GINT_TO_POINTER(PLAYER_COMPARE_ATTRIBUTE_LEAGUE_GOALS));
g_ptr_array_sort_with_data(players_sorted[1], player_compare_func,
GINT_TO_POINTER(-PLAYER_COMPARE_ATTRIBUTE_LEAGUE_GOALS));
maxlen = MIN(maxlen, players_sorted[0]->len);
maxlen = MIN(maxlen, players_sorted[1]->len);
for(i=0;i<2;i++)
for(j=0;j<maxlen;j++)
{
pl = (Player*)g_ptr_array_index(players_sorted[i], j);
new_stat.tm = pl->team;
new_stat.team_id = pl->team->id;
new_stat.value_string = g_string_new(pl->name->str);
new_stat.value1 =
player_games_goals_get(pl, pl->team->clid, PLAYER_VALUE_GOALS);
new_stat.value2 =
player_games_goals_get(pl, pl->team->clid, PLAYER_VALUE_GAMES);
new_stat.value3 =
player_games_goals_get(pl, pl->team->clid, PLAYER_VALUE_SHOTS);
g_array_append_val(players[i], new_stat);
}
league->stats.player_scorers = players[0];
league->stats.player_goalies = players[1];
}
/** Update the stats of the league. */
GArray*
stat_update_league_teams(const GArray *teams_array, gint compare_type)
{
gint i;
GArray *stats = g_array_new(FALSE, FALSE, sizeof(Stat));
GPtrArray *teams = g_ptr_array_new();
Stat new_stat;
gint maxlen = const_int("int_stat_teams_len");
maxlen = MIN(maxlen, teams_array->len);
for(i=0;i<teams_array->len;i++)
g_ptr_array_add(teams, &g_array_index(teams_array, Team, i));
g_ptr_array_sort_with_data(teams, team_compare_func, GINT_TO_POINTER(compare_type));
for(i=0;i<maxlen;i++)
{
new_stat.tm = (Team*)g_ptr_array_index(teams, i);
new_stat.team_id = ((Team*)g_ptr_array_index(teams, i))->id;
new_stat.value1 = team_get_table_value(new_stat.tm, TABLE_GF);
new_stat.value2 = team_get_table_value(new_stat.tm, TABLE_GA);
new_stat.value3 = -1;
new_stat.value_string = g_string_new("");
g_array_append_val(stats, new_stat);
}
g_ptr_array_free(teams, TRUE);
return stats;
}

16
src/stat.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef STAT_H
#define STAT_H
#include "bygfoot.h"
#include "stat_struct.h"
GArray*
stat_update_league_teams(const GArray *teams, gint compare_type);
void
stat_update_leagues(void);
void
stat_update_league_players(League *league);
#endif

25
src/stat_struct.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef STAT_STRUCT_H
#define STAT_STRUCT_H
/** A statistics element holding some
string and integer values. */
typedef struct
{
Team *tm;
gint team_id;
gint value1, value2, value3;
GString *value_string;
} Stat;
/** A structure holding some stat arrays about a league. */
typedef struct
{
/** The league id. */
gint clid;
/** Best offensive and defensive teams. */
GArray *teams_off, *teams_def;
/** Best goal getters and goalies. */
GArray *player_scorers, *player_goalies;
} LeagueStat;
#endif

View File

@ -769,6 +769,35 @@ team_update_user_team_week_roundly(Team *tm)
player_update_week_roundly(tm, i);
}
/** Return a value from the league table element going with the team.
@param type The type of the value. */
gint
team_get_table_value(const Team *tm, gint type)
{
gint i;
const GArray *elements = NULL;
if(tm->clid >= ID_CUP_START)
{
g_warning("team_get_table_value: team is not a league team: %s \n", tm->name->str);
return -1;
}
elements = league_from_clid(tm->clid)->table.elements;
for(i=0;i<elements->len;i++)
if(g_array_index(elements, TableElement, i).team_id == tm->id)
break;
if(i == elements->len)
{
g_warning("team_get_table_value: table entry not found for team %s \n", tm->name->str);
return -1;
}
return g_array_index(elements, TableElement, i).values[type];
}
/** Compare function for team arrays or pointer arrays. */
gint
team_compare_func(gconstpointer a, gconstpointer b, gpointer data)
@ -789,8 +818,44 @@ team_compare_func(gconstpointer a, gconstpointer b, gpointer data)
league_cup_get_index_from_clid(tm2->clid),
league_cup_get_index_from_clid(tm1->clid));
}
else if(type == TEAM_COMPARE_OFFENSIVE)
{
gint gf1 = team_get_table_value(tm1, TABLE_GF),
gf2 = team_get_table_value(tm2, TABLE_GF),
ga1 = team_get_table_value(tm1, TABLE_GA),
ga2 = team_get_table_value(tm2, TABLE_GA);
if(gf1 > gf2)
return_value = -1;
else if(gf1 < gf2)
return_value = 1;
else if(ga1 < ga2)
return_value = -1;
else if(ga1 > ga2)
return_value = 1;
else
return_value = 0;
}
else if(type == TEAM_COMPARE_DEFENSE)
{
gint gf1 = team_get_table_value(tm1, TABLE_GF),
gf2 = team_get_table_value(tm2, TABLE_GF),
ga1 = team_get_table_value(tm1, TABLE_GA),
ga2 = team_get_table_value(tm2, TABLE_GA);
if(ga1 > ga2)
return_value = 1;
else if(ga1 < ga2)
return_value = -1;
else if(gf1 > gf2)
return_value = -1;
else if(gf1 < gf2)
return_value = 1;
else
return_value = 0;
}
else if(type == TEAM_COMPARE_UNSORTED)
return 0;
return_value = 0;
return return_value;
}

View File

@ -12,6 +12,8 @@ enum TeamCompare
TEAM_COMPARE_LEAGUE_RANK = 0,
TEAM_COMPARE_UNSORTED,
TEAM_COMPARE_AV_SKILL,
TEAM_COMPARE_OFFENSIVE,
TEAM_COMPARE_DEFENSE,
TEAM_COMPARE_END
};
@ -138,4 +140,7 @@ query_team_plays(const Team *tm, gint week_number, gint week_round_number);
Team*
team_get_from_name(const gchar *name);
gint
team_get_table_value(const Team *tm, gint type);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -183,4 +183,13 @@ treeview_set_up_user_history(GtkTreeView *treeview);
GtkTreeModel*
treeview_create_user_history(void);
void
treeview_show_league_stats(gint clid);
void
treeview_set_up_league_stats(GtkTreeView *treeview);
void
treeview_create_league_stats(GtkListStore *liststore, const League *league);
#endif

View File

@ -288,6 +288,31 @@ treeview_helper_pixbuf_from_filename(gchar *filename)
return symbol;
}
/** Unref an object if non-null (mostly it's a pixbuf added to a treeview).*/
void
treeview_helper_unref(GObject *object)
{
if(object == NULL)
return;
g_object_unref(object);
}
/** Insert an icon into the liststore at the given iter and
column.
@param icon_name The filename of the icon. */
void
treeview_helper_insert_icon(GtkListStore *ls, GtkTreeIter *iter, gint column_nr,
gchar *icon_name)
{
GdkPixbuf *symbol = treeview_helper_pixbuf_from_filename(icon_name);
gtk_list_store_set(ls, iter, column_nr, symbol, -1);
treeview_helper_unref(G_OBJECT(symbol));
}
/** Function comparing two teams in a team list treeview. */
gint
treeview_helper_team_compare(GtkTreeModel *model,
@ -309,7 +334,7 @@ treeview_helper_team_compare(GtkTreeModel *model,
break;
case TEAM_COMPARE_AV_SKILL:
return_value = misc_float_compare(team_get_average_skill(tm1, FALSE),
team_get_average_skill(tm2, FALSE));
team_get_average_skill(tm2, FALSE));
break;
}
@ -416,7 +441,7 @@ treeview_helper_get_table_element_colour_cups(const League *league, gint idx, gc
@param user Whether to take into account user colours. */
void
treeview_helper_get_table_element_colours(const Table *table, gint idx, gchar *colour_fg,
gchar *colour_bg, gboolean user)
gchar *colour_bg, gboolean user)
{
gint i;
const TableElement *elem = &g_array_index(table->elements, TableElement, idx);
@ -476,6 +501,28 @@ treeview_helper_get_table_element_colours(const Table *table, gint idx, gchar *c
}
}
/** Set the char pointers to the constant determining the background and foreground
colours of user entries in treeviews if the team is a user team. */
void
treeview_helper_set_user_colours(const Team *tm, gchar **colour_bg, gchar **colour_fg)
{
if(tm == current_user.tm)
{
*colour_fg = const_str("string_treeview_current_user_fg");
*colour_bg = const_str("string_treeview_current_user_bg");
}
else if(team_is_user(tm) != -1)
{
*colour_fg = const_str("string_treeview_user_fg");
*colour_bg = const_str("string_treeview_user_bg");
}
else
{
*colour_fg = const_str("string_treeview_helper_color_default_foreground");
*colour_bg = const_str("string_treeview_helper_color_default_background");
}
}
/** Determine the attributes shown in the player list depending on the scout
quality. */

View File

@ -12,6 +12,13 @@ treeview_helper_select_row(GtkTreeView *treeview, GdkEventButton *event);
GdkPixbuf*
treeview_helper_pixbuf_from_filename(gchar *filename);
void
treeview_helper_unref(GObject *object);
void
treeview_helper_insert_icon(GtkListStore *ls, GtkTreeIter *iter, gint column_nr,
gchar *icon_name);
GtkCellRenderer*
treeview_helper_cell_renderer_text_new(void);
@ -34,6 +41,9 @@ void
treeview_helper_get_table_element_colours(const Table *table, gint idx, gchar *colour_fg,
gchar *colour_bg, gboolean user);
void
treeview_helper_set_user_colours(const Team *tm, gchar **colour_bg, gchar **colour_fg);
gboolean
treeview_helper_get_table_element_colour_cups(const League *league, gint idx, gchar *colour_bg);

View File

@ -193,6 +193,15 @@ float_player_max_skill 990000
int_initial_money_lower 80
int_initial_money_upper 110
# how many teams and players there
# are in the league statistics
int_stat_teams_len 3
int_stat_players_len 5
# percentage of team matches a goalie has to participate
# in to get counted in the best goalies statistics
float_stat_goalie_percentage 4000
# below and above which percentages of ranks
# in the league table the user's success counter
# gets incremented or decremented
@ -726,6 +735,12 @@ string_treeview_helper_live_game_result_attributes weight='bold' size='large'
# colour indicating ball possession during a live game
string_live_game_possession_color darkblue
# icons for the league stats view
string_treeview_league_stats_off_teams style_all_atk.png
string_treeview_league_stats_def_teams style_all_def.png
string_treeview_league_stats_scorers scoring_chance.png
string_treeview_league_stats_goalies save.png
# default background and foreground in treeviews
string_treeview_helper_color_default_background white
string_treeview_helper_color_default_foreground black