From 0f12364c95e93bb39903603fb7c62dba737bc4b1 Mon Sep 17 00:00:00 2001 From: gyboth Date: Thu, 19 May 2005 19:43:22 +0000 Subject: [PATCH] "Career values." --- src/game.c | 5 +++- src/live_game.c | 24 +++++++++++---- src/player.c | 13 +++++---- src/player.h | 12 +------- src/player_struct.h | 16 ++++++++++ src/treeview.c | 1 + src/treeview_helper.c | 52 +++++++++++++++++++++++++++++++-- src/treeview_helper.h | 3 ++ src/xml_loadsave_teams.c | 15 ++++++++-- support_files/bygfoot_user.conf | 4 +-- 10 files changed, 114 insertions(+), 31 deletions(-) diff --git a/src/game.c b/src/game.c index e1733485..df4427cd 100644 --- a/src/game.c +++ b/src/game.c @@ -263,8 +263,11 @@ game_initialize(Fixture *fix) if(j < 11) { if(g_array_index(fix->teams[i]->players, Player, j).cskill > 0) + { player_games_goals_set(&g_array_index(fix->teams[i]->players, Player, j), fix->clid, - PLAYER_VALUE_GAMES, 1, TRUE); + PLAYER_VALUE_GAMES, 1); + g_array_index(fix->teams[i]->players, Player, j).career[PLAYER_VALUE_GAMES]++; + } g_array_index(fix->teams[i]->players, Player, j).participation = TRUE; } diff --git a/src/live_game.c b/src/live_game.c index 035a6fe7..bdb44806 100644 --- a/src/live_game.c +++ b/src/live_game.c @@ -323,8 +323,11 @@ live_game_event_foul(void) live_game_event_injury(!foul_team, fouled_player, TRUE); } else if(type == LIVE_GAME_EVENT_FOUL_YELLOW) + { player_card_set(player_of_id_team(tm[foul_team], foul_player), match->fix->clid, PLAYER_VALUE_CARD_YELLOW, 1, TRUE); + player_of_id_team(tm[foul_team], foul_player)->career[PLAYER_VALUE_CARD_YELLOW]++; + } if(last_unit.area == LIVE_GAME_UNIT_AREA_ATTACK && foul_team != last_unit.possession) @@ -794,6 +797,8 @@ live_game_event_send_off(gint team, gint player, gboolean second_yellow) else player_card_set(player_of_id_team(tm[team], player), match->fix->clid, PLAYER_VALUE_CARD_RED, game_player_get_ban_duration(), FALSE); + + player_of_id_team(tm[team], player)->career[PLAYER_VALUE_CARD_RED]++; if(team_is_user(tm[team]) != -1) { @@ -863,7 +868,8 @@ live_game_event_substitution(gint team_number, gint sub_in, gint sub_out) if(player_of_id_team(tm[team_number], sub_in)->cskill > 0) { player_games_goals_set(player_of_id_team(tm[team_number], sub_in), - match->fix->clid, PLAYER_VALUE_GAMES, 1, TRUE); + match->fix->clid, PLAYER_VALUE_GAMES, 1); + player_of_id_team(tm[team_number], sub_in)->career[PLAYER_VALUE_GAMES]++; player_of_id_team(tm[team_number], sub_in)->participation = TRUE; } @@ -941,7 +947,10 @@ live_game_event_duel(void) const_float("float_live_game_score_team_exponent")); if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES) - player_games_goals_set(attacker, match->fix->clid, PLAYER_VALUE_SHOTS, 1, TRUE); + { + player_games_goals_set(attacker, match->fix->clid, PLAYER_VALUE_SHOTS, 1); + attacker->career[PLAYER_VALUE_SHOTS]++; + } if(rndom < scoring_prob) { @@ -951,8 +960,10 @@ live_game_event_duel(void) if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES) { - player_games_goals_set(attacker, match->fix->clid, PLAYER_VALUE_GOALS, 1, TRUE); - player_games_goals_set(goalie, match->fix->clid, PLAYER_VALUE_GOALS, 1, TRUE); + player_games_goals_set(attacker, match->fix->clid, PLAYER_VALUE_GOALS, 1); + player_games_goals_set(goalie, match->fix->clid, PLAYER_VALUE_GOALS, 1); + attacker->career[PLAYER_VALUE_GOALS]++; + goalie->career[PLAYER_VALUE_GOALS]++; } } else @@ -961,7 +972,10 @@ live_game_event_duel(void) if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES && (new.event.type == LIVE_GAME_EVENT_SAVE || new.event.type == LIVE_GAME_EVENT_GOAL)) - player_games_goals_set(goalie, match->fix->clid, PLAYER_VALUE_SHOTS, 1, TRUE); + { + player_games_goals_set(goalie, match->fix->clid, PLAYER_VALUE_SHOTS, 1); + goalie->career[PLAYER_VALUE_SHOTS]++; + } g_array_append_val(unis, new); diff --git a/src/player.c b/src/player.c index c6d631b8..c4c9af68 100644 --- a/src/player.c +++ b/src/player.c @@ -18,6 +18,7 @@ Player player_new(Team *tm, gfloat average_skill, gboolean new_id) { + gint i; gfloat skill_factor = math_rnd(1 - const_float("float_player_average_skill_variance"), 1 + const_float("float_player_average_skill_variance")); @@ -64,6 +65,9 @@ player_new(Team *tm, gfloat average_skill, gboolean new_id) new.cards = g_array_new(FALSE, FALSE, sizeof(PlayerCard)); new.games_goals = g_array_new(FALSE, FALSE, sizeof(PlayerGamesGoals)); + for(i=0;igames_goals, PlayerGamesGoals, i).shots; - if(diff) - *games_goals_value += value; - else - *games_goals_value = value; + *games_goals_value += value; if(*games_goals_value < 0) { @@ -817,7 +818,7 @@ player_games_goals_set(Player *pl, gint clid, gint type, gint value, gboolean di g_array_append_val(pl->games_goals, new); - player_games_goals_set(pl, clid, type, value, diff); + player_games_goals_set(pl, clid, type, value); } /** Update skill and lsu of a user player. diff --git a/src/player.h b/src/player.h index d32b1d3c..3830ccc5 100644 --- a/src/player.h +++ b/src/player.h @@ -13,16 +13,6 @@ enum PlayerCompareAttrib PLAYER_COMPARE_ATTRIBUTE_END }; -enum PlayerValue -{ - PLAYER_VALUE_CARD_YELLOW = 0, - PLAYER_VALUE_CARD_RED, - PLAYER_VALUE_GAMES, - PLAYER_VALUE_GOALS, - PLAYER_VALUE_SHOTS, - PLAYER_VALUE_END -}; - Player player_new(Team *tm, gfloat average_skill, gboolean new_id); @@ -93,7 +83,7 @@ void player_card_set(Player *pl, gint clid, gint card_type, gint value, gboolean diff); void -player_games_goals_set(Player *pl, gint clid, gint type, gint value, gboolean diff); +player_games_goals_set(Player *pl, gint clid, gint type, gint value); gint player_games_goals_get(const Player *pl, gint clid, gint type); diff --git a/src/player_struct.h b/src/player_struct.h index 9b1e2c8d..409981b1 100644 --- a/src/player_struct.h +++ b/src/player_struct.h @@ -64,6 +64,18 @@ enum PlayerInjury PLAYER_INJURY_END }; +/** Enum for different player data. */ +enum PlayerValue +{ + PLAYER_VALUE_GAMES = 0, + PLAYER_VALUE_GOALS, + PLAYER_VALUE_SHOTS, + PLAYER_VALUE_CARD_YELLOW, + PLAYER_VALUE_CARD_RED, + PLAYER_VALUE_END +}; + + /** Representation of a player. @see #PlayerAttributes @@ -103,6 +115,9 @@ typedef struct @see PlayerCard*/ GArray *cards; + /** Career goals, games etc. */ + gint career[PLAYER_VALUE_END]; + /** Pointer to the player's team. */ Team *team; } Player; @@ -148,6 +163,7 @@ enum PlayerInfoAttributeValue PLAYER_INFO_ATTRIBUTE_GAMES_GOALS, PLAYER_INFO_ATTRIBUTE_YELLOW_CARDS, PLAYER_INFO_ATTRIBUTE_BANNED, + PLAYER_INFO_ATTRIBUTE_CAREER, PLAYER_INFO_ATTRIBUTE_OFFERS, PLAYER_INFO_ATTRIBUTE_END }; diff --git a/src/treeview.c b/src/treeview.c index b63eb50f..ad169f97 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -1850,6 +1850,7 @@ treeview_create_player_info(const Player *pl) _("Games/Goals\n"), _("Yellow cards (limit)\n"), _("Banned\n"), + _("Career values"), _("New contract\noffers")}; for(i=0;icards); break; + case PLAYER_INFO_ATTRIBUTE_CAREER: + treeview_helper_player_info_career_to_cell(renderer, pl); + break; case PLAYER_INFO_ATTRIBUTE_OFFERS: if(pl->offers > 0) g_object_set(renderer, "text", _("Player doesn't negotiate anymore"), NULL); @@ -707,6 +707,52 @@ treeview_helper_player_ext_info_to_cell(GtkTreeViewColumn *col, } } +void +treeview_helper_player_info_career_to_cell(GtkCellRenderer *renderer, const Player *pl) +{ + gint i; + gfloat goals_game = 0, + shot_perc = 0; + gchar *titles[PLAYER_VALUE_END] = + {_("Games"), + _("Goals"), + _("Shots"), + _("Yellows"), + _("Reds")}; + gchar buf[SMALL], buf2[SMALL], format[SMALL]; + + strcpy(buf, ""); + for(i=0;icareer[i]); + strcat(buf, buf2); + } + + if(pl->career[PLAYER_VALUE_GAMES] > 0) + goals_game = (gfloat)pl->career[PLAYER_VALUE_GOALS] / + (gfloat)pl->career[PLAYER_VALUE_GAMES]; + + if(pl->pos == PLAYER_POS_GOALIE) + { + strcpy(format, "\nGoals/Game %.1f Save %% %.1f"); + if(pl->career[PLAYER_VALUE_SHOTS] > 0) + shot_perc = 100 - ((gfloat)pl->career[PLAYER_VALUE_GOALS] * 100 / + (gfloat)pl->career[PLAYER_VALUE_SHOTS]); + } + else + { + strcpy(format, "\nGoals/Game %.1f Shot %% %.1f"); + if(pl->career[PLAYER_VALUE_SHOTS] > 0) + shot_perc = (gfloat)pl->career[PLAYER_VALUE_GOALS] * 100 / + (gfloat)pl->career[PLAYER_VALUE_SHOTS]; + } + + sprintf(buf2, format, goals_game, shot_perc); + strcat(buf, buf2); + + g_object_set(renderer, "text", buf, NULL); +} + void treeview_helper_player_info_banned_to_cell(GtkCellRenderer *renderer, const GArray *cards) { diff --git a/src/treeview_helper.h b/src/treeview_helper.h index 5692cafa..98097523 100644 --- a/src/treeview_helper.h +++ b/src/treeview_helper.h @@ -132,6 +132,9 @@ treeview_helper_player_info_yellow_to_cell(GtkCellRenderer *renderer, const GArr void treeview_helper_player_info_banned_to_cell(GtkCellRenderer *renderer, const GArray *cards); +void +treeview_helper_player_info_career_to_cell(GtkCellRenderer *renderer, const Player *pl); + gchar* treeview_helper_get_user_history_icon(gint history_type); diff --git a/src/xml_loadsave_teams.c b/src/xml_loadsave_teams.c index 76d04982..223bc8e1 100644 --- a/src/xml_loadsave_teams.c +++ b/src/xml_loadsave_teams.c @@ -48,10 +48,11 @@ enum TAG_TEAM_PLAYER_CARD_CLID, TAG_TEAM_PLAYER_CARD_YELLOW, TAG_TEAM_PLAYER_CARD_RED, + TAG_TEAM_PLAYER_CAREER, TAG_END }; -gint state, etalidx; +gint state, etalidx, careeridx; GArray *teams_array; Team new_team; Player new_player; @@ -89,7 +90,7 @@ xml_loadsave_teams_start_element (GMarkupParseContext *context, else if(tag == TAG_TEAM_PLAYER) { new_player = player_new(&new_team, 80, FALSE); - etalidx = 0; + etalidx = careeridx = 0; } if(!valid_tag) @@ -150,11 +151,14 @@ xml_loadsave_teams_end_element (GMarkupParseContext *context, tag == TAG_TEAM_PLAYER_CONTRACT || tag == TAG_TEAM_PLAYER_PARTICIPATION || tag == TAG_TEAM_PLAYER_GAMES_GOAL || + tag == TAG_TEAM_PLAYER_CAREER || tag == TAG_TEAM_PLAYER_CARD) { state = TAG_TEAM_PLAYER; if(tag == TAG_TEAM_PLAYER_ETAL) etalidx++; + else if(tag == TAG_TEAM_PLAYER_CAREER) + careeridx++; else if(tag == TAG_TEAM_PLAYER_CARD) g_array_append_val(new_player.cards, new_card); else if(tag == TAG_TEAM_PLAYER_GAMES_GOAL) @@ -267,6 +271,8 @@ xml_loadsave_teams_text (GMarkupParseContext *context, new_card.yellow = int_value; else if(state == TAG_TEAM_PLAYER_CARD_RED) new_card.red = int_value; + else if(state == TAG_TEAM_PLAYER_CAREER) + new_player.career[careeridx] = int_value; } void @@ -389,6 +395,9 @@ xml_loadsave_teams_write_player(FILE *fil, const Player *pl) for(i=0;i<4;i++) xml_write_float(fil, pl->etal[i], TAG_TEAM_PLAYER_ETAL, I3); + for(i=0;icareer[i], TAG_TEAM_PLAYER_CAREER, I2); + for(i=0;igames_goals->len;i++) { fprintf(fil, "%s<_%d>\n", I2, TAG_TEAM_PLAYER_GAMES_GOAL); @@ -417,7 +426,7 @@ xml_loadsave_teams_write_player(FILE *fil, const Player *pl) TAG_TEAM_PLAYER_CARD_RED, I3); fprintf(fil, "%s\n", I2, TAG_TEAM_PLAYER_CARD); - } + } fprintf(fil, "%s\n", I1, TAG_TEAM_PLAYER); } diff --git a/support_files/bygfoot_user.conf b/support_files/bygfoot_user.conf index 3be45bff..e6df3f9d 100644 --- a/support_files/bygfoot_user.conf +++ b/support_files/bygfoot_user.conf @@ -4,9 +4,9 @@ # Most of these options are uncommented because their meaning # is rather clear if you take a look at the options window in the game. -int_opt_user_show_live_game 1 +int_opt_user_show_live_game 0 int_opt_user_live_game_speed 0 -int_opt_user_live_game_verbosity 3 +int_opt_user_live_game_verbosity 5 int_opt_user_show_tendency_bar 1 int_opt_user_pause_injury 1 int_opt_user_pause_red 1