From e770ef07efa0dd9a6fb912a18a53f06c0a7ae9b0 Mon Sep 17 00:00:00 2001 From: gyboth Date: Thu, 19 May 2005 18:13:14 +0000 Subject: [PATCH] "Live game corrections." --- bygfoot_misc.glade | 1 + src/game.c | 16 +-- src/lg_commentary.c | 86 +++++++-------- src/live_game.c | 204 +++++++++++++++++------------------ src/live_game_struct.h | 16 +-- src/misc_callbacks.c | 25 +++++ src/misc_callbacks.h | 7 +- src/misc_interface.c | 3 + src/xml_loadsave_live_game.c | 41 ++++--- 9 files changed, 213 insertions(+), 186 deletions(-) diff --git a/bygfoot_misc.glade b/bygfoot_misc.glade index 54b6810f..a3ab3c4d 100644 --- a/bygfoot_misc.glade +++ b/bygfoot_misc.glade @@ -1349,6 +1349,7 @@ False 0 -10 20 1 10 10 + 1 diff --git a/src/game.c b/src/game.c index a7b0ddcb..e1733485 100644 --- a/src/game.c +++ b/src/game.c @@ -767,7 +767,7 @@ game_update_stats(gpointer live_game, gconstpointer live_game_unit) stats->values[unit->possession][LIVE_GAME_STAT_VALUE_PENALTIES]++; else if(unit->event.type == LIVE_GAME_EVENT_INJURY) { - stats->values[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]][LIVE_GAME_STAT_VALUE_INJURIES]++; + stats->values[unit->event.team][LIVE_GAME_STAT_VALUE_INJURIES]++; game_update_stats_player(live_game, live_game_unit); } else if(unit->event.type == LIVE_GAME_EVENT_FOUL || @@ -775,16 +775,16 @@ game_update_stats(gpointer live_game, gconstpointer live_game_unit) unit->event.type == LIVE_GAME_EVENT_FOUL_RED || unit->event.type == LIVE_GAME_EVENT_FOUL_RED_INJURY) { - stats->values[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]][LIVE_GAME_STAT_VALUE_FOULS]++; + stats->values[unit->event.team][LIVE_GAME_STAT_VALUE_FOULS]++; if(unit->event.type == LIVE_GAME_EVENT_FOUL_YELLOW) { - stats->values[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]][LIVE_GAME_STAT_VALUE_CARDS]++; + stats->values[unit->event.team][LIVE_GAME_STAT_VALUE_CARDS]++; game_update_stats_player(live_game, live_game_unit); } } else if(unit->event.type == LIVE_GAME_EVENT_SEND_OFF) { - stats->values[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]][LIVE_GAME_STAT_VALUE_REDS]++; + stats->values[unit->event.team][LIVE_GAME_STAT_VALUE_REDS]++; game_update_stats_player(live_game, live_game_unit); } else if(unit->event.type == LIVE_GAME_EVENT_GOAL || @@ -792,7 +792,7 @@ game_update_stats(gpointer live_game, gconstpointer live_game_unit) { if(live_game_unit_before(unit, -1)->event.type != LIVE_GAME_EVENT_PENALTY && unit->event.type != LIVE_GAME_EVENT_OWN_GOAL) - stats->values[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]][LIVE_GAME_STAT_VALUE_GOALS_REGULAR]++; + stats->values[unit->event.team][LIVE_GAME_STAT_VALUE_GOALS_REGULAR]++; game_update_stats_player(live_game, live_game_unit); } @@ -817,9 +817,9 @@ game_update_stats_player(gpointer live_game, gconstpointer live_game_unit) const LiveGameUnit *unit = (const LiveGameUnit*)live_game_unit; gint minute = live_game_unit_get_minute(unit), array_index = -1; gboolean own_goal; - gint team = unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM], - player = unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER], - player2 = unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]; + gint team = unit->event.team, + player = unit->event.player, + player2 = unit->event.player2; const Team *tm[2] = {((LiveGame*)live_game)->fix->teams[0], ((LiveGame*)live_game)->fix->teams[1]}; GString *new = NULL; diff --git a/src/lg_commentary.c b/src/lg_commentary.c index e8a0f4f0..3cc024f1 100644 --- a/src/lg_commentary.c +++ b/src/lg_commentary.c @@ -344,16 +344,16 @@ lg_commentary_set_strings(gchar *strings[][2], const LiveGameUnit *unit, const F fix->teams[(unit->result[0] < unit->result[1])]->name->str; strings[LG_TOKEN_TEAM][0] = const_str("string_lg_commentary_token_team"); - strings[LG_TOKEN_TEAM][1] = (unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM] == -1) ? - NULL : fix->teams[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->name->str; + strings[LG_TOKEN_TEAM][1] = (unit->event.team == -1) ? + NULL : fix->teams[unit->event.team]->name->str; strings[LG_TOKEN_PLAYER1][0] = const_str("string_lg_commentary_token_player1"); - strings[LG_TOKEN_PLAYER1][1] = (unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER] == -1) ? - NULL : lg_commentary_get_player_name(unit, fix, LIVE_GAME_EVENT_VALUE_PLAYER); + strings[LG_TOKEN_PLAYER1][1] = (unit->event.player == -1) ? + NULL : lg_commentary_get_player_name(unit, fix, FALSE); strings[LG_TOKEN_PLAYER2][0] = const_str("string_lg_commentary_token_player2"); - strings[LG_TOKEN_PLAYER2][1] = (unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] == -1) ? - NULL : lg_commentary_get_player_name(unit, fix, LIVE_GAME_EVENT_VALUE_PLAYER2); + strings[LG_TOKEN_PLAYER2][1] = (unit->event.player2 == -1) ? + NULL : lg_commentary_get_player_name(unit, fix, TRUE); strings[LG_TOKEN_ATTENDANCE][0] = const_str("string_lg_commentary_token_attendance"); misc_print_grouped_int(fix->attendance, buf, FALSE); @@ -374,38 +374,34 @@ lg_commentary_set_strings(gchar *strings[][2], const LiveGameUnit *unit, const F /** Return the name of a player involved in the unit (or NULL). @param player Which player we look for. */ gchar* -lg_commentary_get_player_name(const LiveGameUnit *unit, const Fixture *fix, gint player) +lg_commentary_get_player_name(const LiveGameUnit *unit, const Fixture *fix, gboolean player2) { gchar *return_value = NULL; if(unit->event.type == LIVE_GAME_EVENT_GENERAL) - return_value = + return_value = (player2) ? player_of_id_team(fix->teams[unit->possession], - unit->event.values[player])->name->str; + unit->event.player2)->name->str : + player_of_id_team(fix->teams[unit->possession], + unit->event.player)->name->str; else if(unit->event.type == LIVE_GAME_EVENT_LOST_POSSESSION) { - if(player == LIVE_GAME_EVENT_VALUE_PLAYER) - return_value = - player_of_id_team(fix->teams[unit->possession], - unit->event.values[player])->name->str; - else - return_value = - player_of_id_team(fix->teams[!unit->possession], - unit->event.values[player])->name->str; + return_value = (player2) ? + player_of_id_team(fix->teams[!unit->possession], + unit->event.player2)->name->str: + player_of_id_team(fix->teams[unit->possession], + unit->event.player)->name->str; } else if(unit->event.type == LIVE_GAME_EVENT_SCORING_CHANCE || unit->event.type == LIVE_GAME_EVENT_HEADER || unit->event.type == LIVE_GAME_EVENT_PENALTY || unit->event.type == LIVE_GAME_EVENT_FREE_KICK) - { - if(player == LIVE_GAME_EVENT_VALUE_PLAYER) - return_value = - player_of_id_team(fix->teams[unit->possession], - unit->event.values[player])->name->str; - else - return_value = - player_of_id_team(fix->teams[unit->possession], - unit->event.values[player])->name->str; + { + return_value = (player2) ? + player_of_id_team(fix->teams[unit->possession], + unit->event.player2)->name->str : + player_of_id_team(fix->teams[unit->possession], + unit->event.player)->name->str; } else if(unit->event.type == LIVE_GAME_EVENT_GOAL || unit->event.type == LIVE_GAME_EVENT_MISSED || @@ -413,40 +409,36 @@ lg_commentary_get_player_name(const LiveGameUnit *unit, const Fixture *fix, gint unit->event.type == LIVE_GAME_EVENT_POST || unit->event.type == LIVE_GAME_EVENT_CROSS_BAR) { - if(player == LIVE_GAME_EVENT_VALUE_PLAYER) - return_value = - player_of_id_team(fix->teams[unit->possession], - unit->event.values[player])->name->str; - else - return_value = - player_of_id_team(fix->teams[!unit->possession], - unit->event.values[player])->name->str; + return_value = (player2) ? + player_of_id_team(fix->teams[!unit->possession], + unit->event.player2)->name->str : + player_of_id_team(fix->teams[unit->possession], + unit->event.player)->name->str; } else if(unit->event.type == LIVE_GAME_EVENT_OWN_GOAL) return_value = player_of_id_team(fix->teams[!unit->possession], - unit->event.values[player])->name->str; + unit->event.player)->name->str; else if(unit->event.type == LIVE_GAME_EVENT_FOUL || unit->event.type == LIVE_GAME_EVENT_FOUL_RED || unit->event.type == LIVE_GAME_EVENT_FOUL_RED_INJURY || unit->event.type == LIVE_GAME_EVENT_FOUL_YELLOW) { - if(player == LIVE_GAME_EVENT_VALUE_PLAYER) - return_value = - player_of_id_team(fix->teams[!unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]], - unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str; - else - return_value = - player_of_id_team(fix->teams[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]], - unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])->name->str; + return_value = (player2) ? + player_of_id_team(fix->teams[unit->event.team], + unit->event.player2)->name->str : + player_of_id_team(fix->teams[!unit->event.team], + unit->event.player)->name->str; } else if(unit->event.type == LIVE_GAME_EVENT_SEND_OFF || unit->event.type == LIVE_GAME_EVENT_INJURY || unit->event.type == LIVE_GAME_EVENT_TEMP_INJURY || unit->event.type == LIVE_GAME_EVENT_SUBSTITUTION) - return_value = - player_of_id_team(fix->teams[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]], - unit->event.values[player])->name->str; + return_value = (player2) ? + player_of_id_team(fix->teams[unit->event.team], + unit->event.player2)->name->str : + player_of_id_team(fix->teams[unit->event.team], + unit->event.player)->name->str; else g_warning("lg_commentary_get_player_name: unknown event type %d\n", unit->event.type); @@ -467,7 +459,7 @@ lg_commentary_get_extra_data(const LiveGameUnit *unit, const Fixture *fix) break; case LIVE_GAME_EVENT_STRUCTURE_CHANGE: sprintf(buf, "%d", - fix->teams[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->structure); + fix->teams[unit->event.team]->structure); break; case LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND: strcpy(buf, "ALL OUT DEFEND"); diff --git a/src/live_game.c b/src/live_game.c index 7f47448f..035a6fe7 100644 --- a/src/live_game.c +++ b/src/live_game.c @@ -99,9 +99,9 @@ live_game_create_unit(void) new.minute = live_game_get_minute(); new.time = live_game_get_time(&last_unit); new.event.commentary = NULL; - new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1; + new.event.team = + new.event.player = + new.event.player2 = -1; new.area = last_unit.area; new.result[0] = last_unit.result[0]; new.result[1] = last_unit.result[1]; @@ -201,8 +201,8 @@ live_game_create_start_unit(void) if(debug > 100 && fixture_user_team_involved(match->fix) != -1) printf("\t\tlive_game_create_start_unit\n"); - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1; + new.event.player = + new.event.player2 = -1; new.event.commentary = NULL; new.minute = 0; @@ -213,7 +213,7 @@ live_game_create_start_unit(void) new.result[0] = new.result[1] = 0; new.event.type = LIVE_GAME_EVENT_START_MATCH; - new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = new.possession; + new.event.team = new.possession; g_array_append_val(unis, new); } @@ -275,26 +275,26 @@ live_game_event_foul(void) game_get_foul_possession_factor( tm[last_unit.possession]->boost, tm[!last_unit.possession]->boost)) { - foul_team = last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = !last_unit.possession; + foul_team = last_unit.event.team = !last_unit.possession; if(uni(unis->len - 2).event.type == LIVE_GAME_EVENT_GENERAL) - fouled_player = last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = - uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]; + fouled_player = last_unit.event.player = + uni(unis->len - 2).event.player; else - fouled_player = last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + fouled_player = last_unit.event.player = game_get_player(tm[last_unit.possession], last_unit.area, 0, -1, FALSE); - foul_player = last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = + foul_player = last_unit.event.player2 = game_get_player(tm[!last_unit.possession], last_unit.area, 0, -1, FALSE); } else { - foul_team = last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = last_unit.possession; - fouled_player = last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + foul_team = last_unit.event.team = last_unit.possession; + fouled_player = last_unit.event.player = game_get_player(tm[!last_unit.possession], last_unit.area, 0, -1, FALSE); - foul_player = last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = + foul_player = last_unit.event.player2 = game_get_player(tm[last_unit.possession], last_unit.area, 0, -1, FALSE); } @@ -347,15 +347,15 @@ live_game_event_lost_possession(void) { if(debug > 100 && fixture_user_team_involved(match->fix) != -1) printf("\t\tlive_game_event_lost_possession\n"); - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = game_get_player(tm[last_unit.possession], last_unit.area, 0, -1, TRUE); if(uni(unis->len - 2).event.type == LIVE_GAME_EVENT_GENERAL) - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = - uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]; + last_unit.event.player2 = + uni(unis->len - 2).event.player; else - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = + last_unit.event.player2 = game_get_player(tm[!last_unit.possession], uni(unis->len - 2).area, 0, -1, FALSE); @@ -383,9 +383,9 @@ live_game_event_injury(gint team, gint player, gboolean create_new) new = last_unit; new.event.commentary = NULL; g_array_append_val(unis, new); - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = player; - last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = + last_unit.event.team = team; } else @@ -399,11 +399,11 @@ live_game_event_injury(gint team, gint player, gboolean create_new) last_unit.event.type = LIVE_GAME_EVENT_TEMP_INJURY; if(debug < 50 || - team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]) == -1) - player_of_id_team(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]], - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->fitness = - MAX(0, player_of_id_team(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]], - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->fitness - + team_is_user(tm[last_unit.event.team]) == -1) + player_of_id_team(tm[last_unit.event.team], + last_unit.event.player)->fitness = + MAX(0, player_of_id_team(tm[last_unit.event.team], + last_unit.event.player)->fitness - math_rnd(const_float("float_live_game_temp_injury_fitness_decrease_lower"), const_float("float_live_game_temp_injury_fitness_decrease_upper"))); } @@ -411,39 +411,39 @@ live_game_event_injury(gint team, gint player, gboolean create_new) live_game_finish_unit(); if(debug >= 50 && - team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]) != -1) + team_is_user(tm[last_unit.event.team]) != -1) return; if(last_unit.event.type == LIVE_GAME_EVENT_INJURY) { - game_player_injury(player_of_id_team(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]], - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER])); + game_player_injury(player_of_id_team(tm[last_unit.event.team], + last_unit.event.player)); - if(match->subs_left[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]] > 0) + if(match->subs_left[last_unit.event.team] > 0) { if(show && - team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]) != -1 && + team_is_user(tm[last_unit.event.team]) != -1 && ((option_int("int_opt_user_pause_injury", - &usr(team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]])).options) && + &usr(team_is_user(tm[last_unit.event.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)) + &usr(team_is_user(tm[last_unit.event.team])).options)) || + tm[last_unit.event.team]->players->len == 11)) misc_callback_pause_live_game(); - else if(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->players->len > 11) + else if(tm[last_unit.event.team]->players->len > 11) { - old_structure = tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->structure; + old_structure = tm[last_unit.event.team]->structure; live_game_event_substitution( - last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM], + last_unit.event.team, game_substitute_player( - tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]], - player_id_index(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]], - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER])), - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER]); + tm[last_unit.event.team], + player_id_index(tm[last_unit.event.team], + last_unit.event.player)), + last_unit.event.player); - match->subs_left[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]--; + match->subs_left[last_unit.event.team]--; - if(old_structure != tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->structure) - live_game_event_team_change(last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM], + if(old_structure != tm[last_unit.event.team]->structure) + live_game_event_team_change(last_unit.event.team, LIVE_GAME_EVENT_STRUCTURE_CHANGE); } } @@ -503,42 +503,42 @@ live_game_event_scoring_chance(void) if(math_rnd(0, 1) < const_float("float_live_game_scoring_chance_is_own_goal")) { last_unit.event.type = LIVE_GAME_EVENT_OWN_GOAL; - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = game_get_player(tm[!last_unit.possession], GAME_PLAYER_TYPE_DEFEND, 0, -1, FALSE); - last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = !last_unit.possession; + last_unit.event.team = !last_unit.possession; match->fix->result[last_unit.possession][res_idx]++; last_unit.result[last_unit.possession]++; } else { - if(uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1 && + if(uni(unis->len - 2).event.player != -1 && math_rnd(0, 1) < const_float("float_live_game_player_in_poss_shoots") && - player_id_team(uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]) == + player_id_team(uni(unis->len - 2).event.player) == tm[last_unit.possession]) - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = - uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]; + last_unit.event.player = + uni(unis->len - 2).event.player; else { - if(uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1 && - player_id_team(uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]) == + if(uni(unis->len - 2).event.player != -1 && + player_id_team(uni(unis->len - 2).event.player) == tm[last_unit.possession]) { - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = game_get_player(tm[last_unit.possession], last_unit.area, 0, - uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER], + uni(unis->len - 2).event.player, TRUE); - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = - uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]; + last_unit.event.player2 = + uni(unis->len - 2).event.player; } else { - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = game_get_player(tm[last_unit.possession], last_unit.area, 0, -1, TRUE); - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = + last_unit.event.player2 = game_get_player(tm[last_unit.possession], last_unit.area, 0, - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER], TRUE); + last_unit.event.player, TRUE); } } @@ -571,43 +571,43 @@ live_game_event_penalty(void) g_array_append_val(unis, new); } - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = - last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = -1; + last_unit.event.player2 = + last_unit.event.team = -1; if(last_unit.time == LIVE_GAME_UNIT_TIME_PENALTIES) { if(uni(unis->len - 2).event.type == LIVE_GAME_EVENT_PENALTIES) { last_unit.possession = math_rndi(0, 1); - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE); } else if(uni(unis->len - 4).event.type == LIVE_GAME_EVENT_PENALTIES) { last_unit.possession = !uni(unis->len - 3).possession; - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE); } else { last_unit.possession = !uni(unis->len - 3).possession; - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_PENALTY, - uni(unis->len - 4).event.values[LIVE_GAME_EVENT_VALUE_PLAYER], -1, FALSE); + uni(unis->len - 4).event.player, -1, FALSE); } } else { - last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = + last_unit.event.team = last_unit.possession; - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = game_get_default_penalty_shooter(tm[last_unit.possession]); - if(last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] == -1) - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + if(last_unit.event.player == -1) + last_unit.event.player = game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE); } @@ -633,7 +633,7 @@ live_game_event_general(gboolean create_new) new.event.commentary = NULL; new.result[0] = last_unit.result[0]; new.result[1] = last_unit.result[1]; - new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = -1; + new.event.team = -1; if(last_unit.event.type == LIVE_GAME_EVENT_GENERAL || last_unit.event.type == LIVE_GAME_EVENT_START_MATCH || @@ -697,10 +697,10 @@ live_game_event_general(gboolean create_new) void live_game_event_general_get_players(void) { - gint *pl1 = &last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER]; - gint *pl2 = &last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]; + gint *pl1 = &last_unit.event.player; + gint *pl2 = &last_unit.event.player2; gint old_pl1 = - uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]; + uni(unis->len - 2).event.player; gint type = uni(unis->len - 2).event.type; if(debug > 100 && fixture_user_team_involved(match->fix) != -1) @@ -738,21 +738,21 @@ live_game_event_free_kick(void) if(debug > 100 && fixture_user_team_involved(match->fix) != -1) printf("\t\tlive_game_event_free_kick\n"); - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1; + new.event.player = + new.event.player2 = -1; new.minute = -1; new.event.type = LIVE_GAME_EVENT_FREE_KICK; - new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = + new.event.team = new.possession; new.event.commentary = NULL; - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + new.event.player = game_get_default_penalty_shooter(tm[new.possession]); - if(new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] == -1) - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + if(new.event.player == -1) + new.event.player = game_get_player(tm[new.possession], new.area, 0, -1, TRUE); g_array_append_val(unis, new); @@ -771,14 +771,14 @@ live_game_event_send_off(gint team, gint player, gboolean second_yellow) if(debug > 100 && fixture_user_team_involved(match->fix) != -1) printf("\t\tlive_game_event_send_off\n"); - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1; + new.event.player = + new.event.player2 = -1; new.minute = -1; new.event.type = LIVE_GAME_EVENT_SEND_OFF; - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = player; - new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = team; + new.event.player = player; + new.event.team = team; new.event.commentary = NULL; g_array_append_val(unis, new); @@ -855,9 +855,9 @@ live_game_event_substitution(gint team_number, gint sub_in, gint sub_out) new.event.commentary = NULL; new.event.type = LIVE_GAME_EVENT_SUBSTITUTION; - new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = team_number; - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = sub_in; - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = sub_out; + new.event.team = team_number; + new.event.player = sub_in; + new.event.player2 = sub_out; if(player_of_id_team(tm[team_number], sub_in)->cskill > 0) @@ -884,9 +884,9 @@ live_game_event_team_change(gint team_number, gint event_type) new.time = live_game_get_time(&last_unit); new.event.commentary = NULL; - new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = team_number; - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1; + new.event.team = team_number; + new.event.player = + new.event.player2 = -1; new.event.type = event_type; g_array_append_val(unis, new); @@ -909,14 +909,14 @@ live_game_event_duel(void) printf("\t\tlive_game_event_duel\n"); new.minute = -1; - new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = new.possession; + new.event.team = new.possession; new.event.commentary = NULL; attacker = player_of_id_team(tm[new.possession], - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER]); + new.event.player); goalie = player_of_idx_team(tm[!new.possession], 0); - new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = goalie->id; + new.event.player2 = goalie->id; duel_factor = player_get_game_skill(attacker, FALSE) / player_get_game_skill(goalie, FALSE); @@ -984,7 +984,7 @@ query_live_game_second_yellow(gint team, gint player) for(i=0;ilen - 1;i++) if(uni(i).event.type == LIVE_GAME_EVENT_FOUL_YELLOW && uni(i).possession != team && - uni(i).event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] == player) + uni(i).event.player2 == player) return TRUE; return FALSE; @@ -1247,9 +1247,9 @@ live_game_finish_unit(void) if(debug > 100 && fixture_user_team_involved(match->fix) != -1) printf("OOOO1 idx %d type %d poss %d team %d pl %d %d\n", unis->len - 1, - unit->event.type, unit->possession, unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM], - unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER], - unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]); + unit->event.type, unit->possession, unit->event.team, + unit->event.player, + unit->event.player2); if(unit->minute != -1 && unit->time != LIVE_GAME_UNIT_TIME_PENALTIES && fixture_user_team_involved(match->fix) != -1) @@ -1283,9 +1283,9 @@ live_game_finish_unit(void) if(debug > 100 && fixture_user_team_involved(match->fix) != -1) printf("OOOO idx %d type %d poss %d team %d pl %d %d\n", unis->len - 1, - unit->event.type, unit->possession, unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM], - unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER], - unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]); + unit->event.type, unit->possession, unit->event.team, + unit->event.player, + unit->event.player2); } /** Find a random player (influenced by fitness) who gets @@ -1323,17 +1323,17 @@ live_game_injury_get_player(void) if(rndom < probs[0]) { - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = player_of_idx_team(tm0, 0)->id; - last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = 0; + last_unit.event.team = 0; } else for(i=1;i<22;i++) if(probs[i - 1] <= rndom && rndom < probs[i]) { - last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = + last_unit.event.player = player_of_idx_team(tm[(i > 10)], i % 11)->id; - last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = (i > 10); + last_unit.event.team = (i > 10); } } diff --git a/src/live_game_struct.h b/src/live_game_struct.h index b2c468ee..b7014880 100644 --- a/src/live_game_struct.h +++ b/src/live_game_struct.h @@ -55,16 +55,6 @@ enum LiveGameEventType LIVE_GAME_EVENT_END }; -/** Indices for the int_values in the - #LiveGameEvent struct. */ -enum LiveGameEventValue -{ - LIVE_GAME_EVENT_VALUE_TEAM = 0, - LIVE_GAME_EVENT_VALUE_PLAYER, - LIVE_GAME_EVENT_VALUE_PLAYER2, - LIVE_GAME_EVENT_VALUE_END -}; - enum LiveGameUnitArea { LIVE_GAME_UNIT_AREA_DEFEND = 0, @@ -137,9 +127,9 @@ typedef struct /** Verbosity value. The lower the more important the event. */ gint verbosity; - /** @see #LiveGameEventValue1 - @see #LiveGameEventValue2 */ - gint values[LIVE_GAME_EVENT_VALUE_END]; + /** Information about a team and two players + involved in the event. */ + gint team, player, player2; /** The commentary for the event. */ GString *commentary; diff --git a/src/misc_callbacks.c b/src/misc_callbacks.c index 86657626..c55e4600 100644 --- a/src/misc_callbacks.c +++ b/src/misc_callbacks.c @@ -327,3 +327,28 @@ on_combo_country_changed (GtkComboBox *combobox, misc_callback_show_team_list(GTK_WIDGET(combobox), buf); g_free(buf); } + +gboolean +on_spinbutton_speed_button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) +{ + if(event->button == 3) + { + if(option_int("int_opt_user_live_game_speed", &usr(stat2).options) == -10) + option_set_int("int_opt_user_live_game_speed", &usr(stat2).options, 20); + else if(option_int("int_opt_user_live_game_speed", &usr(stat2).options) == 20) + option_set_int("int_opt_user_live_game_speed", &usr(stat2).options, 0); + else + option_set_int("int_opt_user_live_game_speed", &usr(stat2).options, -10); + + gtk_spin_button_set_value( + GTK_SPIN_BUTTON(lookup_widget(window.live, "spinbutton_speed")), + (gdouble)option_int("int_opt_user_live_game_speed", &usr(stat2).options)); + + return TRUE; + } + + return FALSE; +} + diff --git a/src/misc_callbacks.h b/src/misc_callbacks.h index e6fb65ed..452b5be5 100644 --- a/src/misc_callbacks.h +++ b/src/misc_callbacks.h @@ -122,8 +122,13 @@ on_window_stadium_delete_event (GtkWidget *widget, void on_combo_country_changed (GtkComboBox *combobox, gpointer user_data); -#endif void on_spinbutton_verbosity_value_changed (GtkSpinButton *spinbutton, gpointer user_data); + +gboolean +on_spinbutton_speed_button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data); +#endif diff --git a/src/misc_interface.c b/src/misc_interface.c index 47780704..84d7d97b 100644 --- a/src/misc_interface.c +++ b/src/misc_interface.c @@ -773,6 +773,9 @@ create_window_live (void) g_signal_connect ((gpointer) spinbutton_speed, "value_changed", G_CALLBACK (on_spinbutton_speed_value_changed), NULL); + g_signal_connect ((gpointer) spinbutton_speed, "button_press_event", + G_CALLBACK (on_spinbutton_speed_button_press_event), + NULL); g_signal_connect ((gpointer) spinbutton_verbosity, "value_changed", G_CALLBACK (on_spinbutton_verbosity_value_changed), NULL); diff --git a/src/xml_loadsave_live_game.c b/src/xml_loadsave_live_game.c index 2d5512f4..673b7455 100644 --- a/src/xml_loadsave_live_game.c +++ b/src/xml_loadsave_live_game.c @@ -22,8 +22,11 @@ enum TAG_LIVE_GAME_UNIT_RESULT, TAG_LIVE_GAME_UNIT_EVENT, TAG_LIVE_GAME_UNIT_EVENT_TYPE, - TAG_LIVE_GAME_UNIT_EVENT_VALUE, + TAG_LIVE_GAME_UNIT_EVENT_TEAM, + TAG_LIVE_GAME_UNIT_EVENT_PLAYER, + TAG_LIVE_GAME_UNIT_EVENT_PLAYER2, TAG_LIVE_GAME_UNIT_EVENT_COMMENTARY, + TAG_LIVE_GAME_UNIT_EVENT_VERBOSITY, TAG_LIVE_GAME_STAT, TAG_LIVE_GAME_STAT_POSSESSION, TAG_LIVE_GAME_STAT_VALUES, @@ -103,13 +106,12 @@ xml_loadsave_live_game_end_element (GMarkupParseContext *context, unitidx++; } else if(tag == TAG_LIVE_GAME_UNIT_EVENT_TYPE || - tag == TAG_LIVE_GAME_UNIT_EVENT_VALUE || + tag == TAG_LIVE_GAME_UNIT_EVENT_TEAM || + tag == TAG_LIVE_GAME_UNIT_EVENT_PLAYER || + tag == TAG_LIVE_GAME_UNIT_EVENT_PLAYER2 || + tag == TAG_LIVE_GAME_UNIT_EVENT_VERBOSITY || tag == TAG_LIVE_GAME_UNIT_EVENT_COMMENTARY) - { state = TAG_LIVE_GAME_UNIT_EVENT; - if(tag == TAG_LIVE_GAME_UNIT_EVENT_VALUE) - unitidx++; - } else if(tag == TAG_LIVE_GAME_STAT_POSSESSION || tag == TAG_LIVE_GAME_STAT_PLAYERS || tag == TAG_LIVE_GAME_STAT_VALUES) @@ -178,10 +180,16 @@ xml_loadsave_live_game_text (GMarkupParseContext *context, new_unit.result[unitidx] = int_value; else if(state == TAG_LIVE_GAME_UNIT_EVENT_TYPE) new_unit.event.type = int_value; - else if(state == TAG_LIVE_GAME_UNIT_EVENT_VALUE) - new_unit.event.values[unitidx] = int_value; + else if(state == TAG_LIVE_GAME_UNIT_EVENT_TEAM) + new_unit.event.team = int_value; + else if(state == TAG_LIVE_GAME_UNIT_EVENT_PLAYER) + new_unit.event.player = int_value; + else if(state == TAG_LIVE_GAME_UNIT_EVENT_PLAYER2) + new_unit.event.player2 = int_value; else if(state == TAG_LIVE_GAME_UNIT_EVENT_COMMENTARY) new_unit.event.commentary = g_string_new(buf); + else if(state == TAG_LIVE_GAME_UNIT_EVENT_VERBOSITY) + new_unit.event.verbosity = int_value; else if(state == TAG_LIVE_GAME_STAT_POSSESSION) lgame->stats.possession = int_value; else if(state == TAG_LIVE_GAME_STAT_VALUE) @@ -260,8 +268,6 @@ xml_loadsave_live_game_write(const gchar *filename, const LiveGame *live_game) void xml_loadsave_live_game_write_unit(FILE *fil, const LiveGameUnit *unit) { - gint i; - fprintf(fil, "<_%d>\n", TAG_LIVE_GAME_UNIT); xml_write_int(fil, unit->possession, @@ -279,16 +285,21 @@ xml_loadsave_live_game_write_unit(FILE *fil, const LiveGameUnit *unit) fprintf(fil, "%s<_%d>\n", I1, TAG_LIVE_GAME_UNIT_EVENT); - xml_write_int(fil, - unit->event.type, + xml_write_int(fil, unit->event.type, TAG_LIVE_GAME_UNIT_EVENT_TYPE, I2); + xml_write_int(fil, unit->event.verbosity, + TAG_LIVE_GAME_UNIT_EVENT_VERBOSITY, I2); xml_write_g_string(fil, unit->event.commentary, TAG_LIVE_GAME_UNIT_EVENT_COMMENTARY, I2); - for(i=0;ievent.values[i], - TAG_LIVE_GAME_UNIT_EVENT_VALUE, I2); + xml_write_int(fil, unit->event.team, + TAG_LIVE_GAME_UNIT_EVENT_TEAM, I2); + xml_write_int(fil, unit->event.player, + TAG_LIVE_GAME_UNIT_EVENT_PLAYER, I2); + xml_write_int(fil, unit->event.player2, + TAG_LIVE_GAME_UNIT_EVENT_PLAYER2, I2); + fprintf(fil, "%s\n", I1, TAG_LIVE_GAME_UNIT_EVENT); fprintf(fil, "\n", TAG_LIVE_GAME_UNIT);