2005-05-28 16:34:14 +02:00
|
|
|
#include "callbacks.h"
|
2005-01-09 21:21:22 +01:00
|
|
|
#include "fixture.h"
|
|
|
|
#include "free.h"
|
2005-03-10 21:59:39 +01:00
|
|
|
#include "game.h"
|
2005-01-24 19:01:55 +01:00
|
|
|
#include "game_gui.h"
|
2005-05-18 18:00:49 +02:00
|
|
|
#include "lg_commentary.h"
|
2005-01-09 21:21:22 +01:00
|
|
|
#include "live_game.h"
|
2005-06-15 21:13:35 +02:00
|
|
|
#include "main.h"
|
2005-01-09 21:21:22 +01:00
|
|
|
#include "maths.h"
|
2005-03-03 13:46:48 +01:00
|
|
|
#include "misc_callback_func.h"
|
|
|
|
#include "option.h"
|
2005-01-09 21:21:22 +01:00
|
|
|
#include "player.h"
|
2005-03-11 13:17:48 +01:00
|
|
|
#include "support.h"
|
2005-01-09 21:21:22 +01:00
|
|
|
#include "team.h"
|
|
|
|
#include "treeview.h"
|
2005-03-03 13:46:48 +01:00
|
|
|
#include "user.h"
|
2005-01-09 21:21:22 +01:00
|
|
|
#include "variables.h"
|
2005-03-03 13:46:48 +01:00
|
|
|
#include "window.h"
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
/** The live game we calculate. */
|
|
|
|
LiveGame *match;
|
|
|
|
/** Whether the events are actually shown or not. */
|
|
|
|
gboolean show;
|
|
|
|
|
2005-03-09 14:10:28 +01:00
|
|
|
/** Convenience abbrevs. */
|
2005-03-03 13:46:48 +01:00
|
|
|
#define unis match->units
|
|
|
|
#define uni(i) g_array_index(unis, LiveGameUnit, i)
|
|
|
|
#define last_unit uni(unis->len - 1)
|
2005-01-09 21:21:22 +01:00
|
|
|
#define tm match->fix->teams
|
|
|
|
#define tm0 match->fix->teams[0]
|
|
|
|
#define tm1 match->fix->teams[1]
|
|
|
|
|
|
|
|
/** Calculate the result of a fixture using
|
|
|
|
the live game variable.
|
|
|
|
@param fix The fixture we calculate.
|
|
|
|
@see live_game_create_unit(), live_game_evaluate_unit(),
|
|
|
|
treeview_live_game_show_game_unit() */
|
|
|
|
void
|
|
|
|
live_game_calculate_fixture(Fixture *fix)
|
|
|
|
{
|
2005-03-08 09:25:46 +01:00
|
|
|
if(stat0 != STATUS_LIVE_GAME_PAUSE)
|
2005-03-03 13:46:48 +01:00
|
|
|
{
|
2005-04-04 12:36:04 +02:00
|
|
|
match = (fixture_user_team_involved(fix) != -1) ?
|
|
|
|
&usr(fixture_user_team_involved(fix)).live_game : &live_game_temp;
|
|
|
|
show = (fixture_user_team_involved(fix) != -1 &&
|
|
|
|
option_int("int_opt_user_show_live_game",
|
|
|
|
&usr(fixture_user_team_involved(fix)).options));
|
|
|
|
|
|
|
|
stat2 = fixture_user_team_involved(fix);
|
2005-05-26 11:07:56 +02:00
|
|
|
statp = match;
|
2005-04-04 12:36:04 +02:00
|
|
|
|
2005-06-05 12:39:29 +02:00
|
|
|
live_game_reset(match, fix, TRUE);
|
|
|
|
|
2005-05-28 16:34:14 +02:00
|
|
|
if(show)
|
|
|
|
{
|
|
|
|
cur_user = stat2;
|
|
|
|
on_button_back_to_main_clicked(NULL, NULL);
|
|
|
|
|
|
|
|
if(window.live == NULL)
|
|
|
|
window.live = window_create(WINDOW_LIVE);
|
|
|
|
else
|
|
|
|
window_live_set_spinbuttons();
|
|
|
|
}
|
2005-04-04 12:36:04 +02:00
|
|
|
|
2005-03-09 14:10:28 +01:00
|
|
|
game_initialize(fix);
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
stat0 = STATUS_SHOW_LIVE_GAME;
|
2005-03-08 09:25:46 +01:00
|
|
|
|
|
|
|
game_get_values(match->fix, match->team_values,
|
|
|
|
match->home_advantage);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 80 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\n\nlive_game_calculate_fixture\n%04d %s %s %04d\n\n",
|
|
|
|
tm0->id, tm0->name->str, tm1->name->str, tm1->id);
|
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
do
|
|
|
|
{
|
2005-03-03 13:46:48 +01:00
|
|
|
live_game_create_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
live_game_evaluate_unit(&last_unit);
|
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
while(last_unit.event.type != LIVE_GAME_EVENT_END_MATCH &&
|
|
|
|
stat0 != STATUS_LIVE_GAME_PAUSE);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-05-01 12:16:14 +02:00
|
|
|
if(last_unit.event.type == LIVE_GAME_EVENT_END_MATCH)
|
2005-03-13 16:46:15 +01:00
|
|
|
game_post_match(fix);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Create a game unit for the live game.
|
|
|
|
@see #LiveGameUnit, #LiveGame, live_game_fill_new_unit() */
|
|
|
|
void
|
|
|
|
live_game_create_unit(void)
|
|
|
|
{
|
|
|
|
LiveGameUnit new;
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_create_unit\n");
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(unis->len == 0)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
|
|
|
live_game_create_start_unit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(uni(unis->len - 1).event.type == LIVE_GAME_EVENT_END_MATCH)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
|
|
|
g_warning("live_game_create_unit: called after end of match.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new.minute = live_game_get_minute();
|
|
|
|
new.time = live_game_get_time(&last_unit);
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.team =
|
|
|
|
new.event.player =
|
|
|
|
new.event.player2 = -1;
|
2005-01-24 19:01:55 +01:00
|
|
|
new.area = last_unit.area;
|
2005-03-03 13:46:48 +01:00
|
|
|
new.result[0] = last_unit.result[0];
|
|
|
|
new.result[1] = last_unit.result[1];
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-10 11:19:38 +02:00
|
|
|
if(last_unit.event.type == LIVE_GAME_EVENT_HALF_TIME ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_EXTRA_TIME)
|
|
|
|
{
|
|
|
|
live_game_event_general(TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(query_live_game_event_is_break(new.minute, new.time))
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
|
|
|
new.event.type = live_game_get_break();
|
|
|
|
new.possession = last_unit.possession;
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_append_val(unis, new);
|
2005-01-09 21:21:22 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
else if(new.time == LIVE_GAME_UNIT_TIME_PENALTIES)
|
2005-01-09 21:21:22 +01:00
|
|
|
new.event.type = LIVE_GAME_EVENT_PENALTY;
|
|
|
|
else
|
|
|
|
live_game_fill_new_unit(&new);
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_append_val(unis, new);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Fill in a new unit depending on the team values and the constants from above.
|
|
|
|
@param new The unit to fill in. */
|
|
|
|
void
|
|
|
|
live_game_fill_new_unit(LiveGameUnit *new)
|
|
|
|
{
|
|
|
|
LiveGameUnit *old = &last_unit;
|
|
|
|
gfloat rndom = math_rnd(0, 1);
|
|
|
|
gfloat stadium_event =
|
2005-03-17 21:26:01 +01:00
|
|
|
1 - powf(tm0->stadium.safety,
|
2005-03-03 13:46:48 +01:00
|
|
|
const_float("float_live_game_stadium_event_exponent"));
|
2005-03-09 14:10:28 +01:00
|
|
|
gfloat possession_change, scoring_chance = 0,
|
|
|
|
injury_event_prob, foul_event_prob;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_fill_new_unit\n");
|
2005-03-09 14:10:28 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
possession_change = const_float("float_live_game_event_general") *
|
|
|
|
const_float("float_live_game_possession_changes") /
|
|
|
|
live_game_pit_teams(old, const_float("float_live_game_possession_team_exponent"));
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-09 14:10:28 +01:00
|
|
|
injury_event_prob = const_float("float_live_game_injury") *
|
|
|
|
(1 + (const_float("float_player_boost_injury_effect") *
|
2005-03-16 21:48:25 +01:00
|
|
|
(tm0->boost != 0 || tm1->boost != 0)));
|
2005-03-09 14:10:28 +01:00
|
|
|
|
|
|
|
foul_event_prob = const_float("float_live_game_foul") *
|
2005-03-16 21:48:25 +01:00
|
|
|
(1 + (tm0->boost + tm1->boost) * const_float("float_team_boost_foul_factor"));
|
2005-03-09 14:10:28 +01:00
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
new->possession = old->possession;
|
2005-01-24 19:01:55 +01:00
|
|
|
|
|
|
|
if(old->event.type == LIVE_GAME_EVENT_GENERAL)
|
|
|
|
new->area = live_game_get_area(new);
|
|
|
|
|
|
|
|
if(new->area == LIVE_GAME_UNIT_AREA_ATTACK)
|
2005-03-03 13:46:48 +01:00
|
|
|
scoring_chance = const_float("float_live_game_scoring_chance") *
|
|
|
|
live_game_pit_teams(new, const_float("float_live_game_scoring_chance_team_exponent"));
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-09 14:10:28 +01:00
|
|
|
if(rndom < foul_event_prob)
|
2005-01-09 21:21:22 +01:00
|
|
|
new->event.type = LIVE_GAME_EVENT_FOUL;
|
2005-03-09 14:10:28 +01:00
|
|
|
else if(rndom < foul_event_prob +
|
|
|
|
injury_event_prob)
|
2005-01-09 21:21:22 +01:00
|
|
|
new->event.type = LIVE_GAME_EVENT_INJURY;
|
2005-03-09 14:10:28 +01:00
|
|
|
else if(rndom < foul_event_prob +
|
|
|
|
injury_event_prob +
|
2005-03-19 21:04:08 +01:00
|
|
|
stadium_event && match->stadium_event == -1)
|
2005-01-09 21:21:22 +01:00
|
|
|
new->event.type = LIVE_GAME_EVENT_STADIUM;
|
2005-03-09 14:10:28 +01:00
|
|
|
else if(rndom < foul_event_prob +
|
|
|
|
injury_event_prob +
|
2005-01-09 21:21:22 +01:00
|
|
|
stadium_event + possession_change)
|
|
|
|
{
|
|
|
|
new->event.type = LIVE_GAME_EVENT_LOST_POSSESSION;
|
|
|
|
new->possession = !old->possession;
|
2005-01-24 19:01:55 +01:00
|
|
|
if(new->area == LIVE_GAME_UNIT_AREA_ATTACK)
|
|
|
|
new->area = LIVE_GAME_UNIT_AREA_DEFEND;
|
|
|
|
else if(new->area == LIVE_GAME_UNIT_AREA_DEFEND)
|
|
|
|
new->area = LIVE_GAME_UNIT_AREA_ATTACK;
|
2005-04-13 15:01:59 +02:00
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
2005-03-09 14:10:28 +01:00
|
|
|
else if(rndom < foul_event_prob +
|
|
|
|
injury_event_prob +
|
2005-01-09 21:21:22 +01:00
|
|
|
stadium_event + possession_change +
|
|
|
|
scoring_chance)
|
|
|
|
new->event.type = LIVE_GAME_EVENT_SCORING_CHANCE;
|
|
|
|
else
|
|
|
|
new->event.type = LIVE_GAME_EVENT_GENERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Create the first unit of a match. */
|
|
|
|
void
|
|
|
|
live_game_create_start_unit(void)
|
|
|
|
{
|
|
|
|
LiveGameUnit new;
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_create_start_unit\n");
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.player =
|
|
|
|
new.event.player2 = -1;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-05-14 15:46:11 +02:00
|
|
|
new.minute = 0;
|
2005-01-09 21:21:22 +01:00
|
|
|
new.time = LIVE_GAME_UNIT_TIME_FIRST_HALF;
|
|
|
|
new.possession = math_rndi(0, 1);
|
2005-01-24 19:01:55 +01:00
|
|
|
new.area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
2005-01-09 21:21:22 +01:00
|
|
|
match->started_game = new.possession;
|
2005-03-03 13:46:48 +01:00
|
|
|
new.result[0] = new.result[1] = 0;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
new.event.type = LIVE_GAME_EVENT_START_MATCH;
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.team = new.possession;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_append_val(unis, new);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Evaluate a live game unit. This means we find out what happens
|
|
|
|
after the unit, depending on its type.
|
|
|
|
@param unit The unit we evaluate.
|
|
|
|
@see The live_game_event* functions. */
|
|
|
|
void
|
|
|
|
live_game_evaluate_unit(LiveGameUnit *unit)
|
|
|
|
{
|
|
|
|
gint type = unit->event.type;
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_evaluate_unit\n");
|
2005-01-09 21:21:22 +01:00
|
|
|
if(type == LIVE_GAME_EVENT_FOUL)
|
2005-03-08 09:25:46 +01:00
|
|
|
live_game_event_foul();
|
2005-01-09 21:21:22 +01:00
|
|
|
else if(type == LIVE_GAME_EVENT_LOST_POSSESSION)
|
|
|
|
live_game_event_lost_possession();
|
|
|
|
else if(type == LIVE_GAME_EVENT_INJURY)
|
2005-01-24 19:01:55 +01:00
|
|
|
live_game_event_injury(-1, -1, FALSE);
|
2005-01-09 21:21:22 +01:00
|
|
|
else if(type == LIVE_GAME_EVENT_STADIUM)
|
|
|
|
live_game_event_stadium();
|
|
|
|
else if(type == LIVE_GAME_EVENT_SCORING_CHANCE)
|
|
|
|
live_game_event_scoring_chance();
|
|
|
|
else if(type == LIVE_GAME_EVENT_PENALTY)
|
|
|
|
live_game_event_penalty();
|
|
|
|
else if(type == LIVE_GAME_EVENT_GENERAL)
|
|
|
|
live_game_event_general(FALSE);
|
2005-03-03 13:46:48 +01:00
|
|
|
else if(type == LIVE_GAME_EVENT_START_MATCH)
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-03-03 13:46:48 +01:00
|
|
|
else if(type == LIVE_GAME_EVENT_HALF_TIME ||
|
2005-01-09 21:21:22 +01:00
|
|
|
type == LIVE_GAME_EVENT_EXTRA_TIME ||
|
2005-03-08 09:25:46 +01:00
|
|
|
type == LIVE_GAME_EVENT_PENALTIES ||
|
|
|
|
type == LIVE_GAME_EVENT_END_MATCH)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-03-08 09:25:46 +01:00
|
|
|
if(type != LIVE_GAME_EVENT_END_MATCH && show &&
|
2005-03-23 20:03:26 +01:00
|
|
|
option_int("int_opt_user_pause_break", &usr(fixture_user_team_involved(match->fix)).options))
|
2005-03-03 13:46:48 +01:00
|
|
|
misc_callback_pause_live_game();
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
2005-01-24 19:01:55 +01:00
|
|
|
else if(type != LIVE_GAME_EVENT_END_MATCH)
|
|
|
|
g_warning("live_game_evaluate_unit: unknown event type %d\n",
|
|
|
|
type);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate a foul event.
|
|
|
|
@param general Whether to create a general event after
|
|
|
|
showing this one. @see live_game_event_general() */
|
|
|
|
void
|
2005-03-08 09:25:46 +01:00
|
|
|
live_game_event_foul(void)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
|
|
|
gfloat rndom = math_rnd(0, 1);
|
2005-03-09 14:10:28 +01:00
|
|
|
gint type, fouled_player, foul_player, foul_team;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_foul\n");
|
2005-03-09 14:10:28 +01:00
|
|
|
if(math_rnd(0, 1) > const_float("float_live_game_foul_by_possession") *
|
|
|
|
game_get_foul_possession_factor(
|
|
|
|
tm[last_unit.possession]->boost, tm[!last_unit.possession]->boost))
|
2005-04-13 15:01:59 +02:00
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
foul_team = last_unit.event.team = !last_unit.possession;
|
2005-03-09 14:10:28 +01:00
|
|
|
if(uni(unis->len - 2).event.type == LIVE_GAME_EVENT_GENERAL)
|
2005-05-19 20:13:14 +02:00
|
|
|
fouled_player = last_unit.event.player =
|
|
|
|
uni(unis->len - 2).event.player;
|
2005-03-09 14:10:28 +01:00
|
|
|
else
|
2005-05-19 20:13:14 +02:00
|
|
|
fouled_player = last_unit.event.player =
|
2005-03-09 14:10:28 +01:00
|
|
|
game_get_player(tm[last_unit.possession],
|
|
|
|
last_unit.area, 0, -1, FALSE);
|
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
foul_player = last_unit.event.player2 =
|
2005-03-09 14:10:28 +01:00
|
|
|
game_get_player(tm[!last_unit.possession],
|
|
|
|
last_unit.area, 0, -1, FALSE);
|
|
|
|
}
|
2005-01-09 21:21:22 +01:00
|
|
|
else
|
2005-03-09 14:10:28 +01:00
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
foul_team = last_unit.event.team = last_unit.possession;
|
|
|
|
fouled_player = last_unit.event.player =
|
2005-03-09 14:10:28 +01:00
|
|
|
game_get_player(tm[!last_unit.possession],
|
2005-01-24 19:01:55 +01:00
|
|
|
last_unit.area, 0, -1, FALSE);
|
2005-05-19 20:13:14 +02:00
|
|
|
foul_player = last_unit.event.player2 =
|
2005-03-09 14:10:28 +01:00
|
|
|
game_get_player(tm[last_unit.possession],
|
|
|
|
last_unit.area, 0, -1, FALSE);
|
|
|
|
}
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(rndom < const_float("float_live_game_foul_red_injury"))
|
2005-01-09 21:21:22 +01:00
|
|
|
type = LIVE_GAME_EVENT_FOUL_RED_INJURY;
|
2005-03-03 13:46:48 +01:00
|
|
|
else if(rndom < const_float("float_live_game_foul_red"))
|
2005-01-09 21:21:22 +01:00
|
|
|
type = LIVE_GAME_EVENT_FOUL_RED;
|
2005-03-03 13:46:48 +01:00
|
|
|
else if(rndom < const_float("float_live_game_foul_yellow"))
|
2005-01-09 21:21:22 +01:00
|
|
|
type = LIVE_GAME_EVENT_FOUL_YELLOW;
|
|
|
|
else
|
|
|
|
type = LIVE_GAME_EVENT_FOUL;
|
|
|
|
|
|
|
|
last_unit.event.type = type;
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
if(type == LIVE_GAME_EVENT_FOUL_RED ||
|
|
|
|
type == LIVE_GAME_EVENT_FOUL_RED_INJURY ||
|
|
|
|
(type == LIVE_GAME_EVENT_FOUL_YELLOW &&
|
2005-03-09 14:10:28 +01:00
|
|
|
query_live_game_second_yellow(foul_team, foul_player)))
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
2005-03-09 14:10:28 +01:00
|
|
|
live_game_event_send_off(foul_team, foul_player,
|
|
|
|
query_live_game_second_yellow(foul_team, foul_player));
|
2005-01-09 21:21:22 +01:00
|
|
|
if(type == LIVE_GAME_EVENT_FOUL_RED_INJURY)
|
2005-03-09 14:10:28 +01:00
|
|
|
live_game_event_injury(!foul_team, fouled_player, TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
2005-03-09 14:10:28 +01:00
|
|
|
else if(type == LIVE_GAME_EVENT_FOUL_YELLOW)
|
2005-05-19 21:43:22 +02:00
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
player_card_set(player_of_id_team(tm[foul_team], foul_player),
|
2005-03-13 16:46:15 +01:00
|
|
|
match->fix->clid, PLAYER_VALUE_CARD_YELLOW, 1, TRUE);
|
2005-05-19 21:43:22 +02:00
|
|
|
player_of_id_team(tm[foul_team], foul_player)->career[PLAYER_VALUE_CARD_YELLOW]++;
|
|
|
|
}
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(last_unit.area == LIVE_GAME_UNIT_AREA_ATTACK && foul_team !=
|
2005-03-09 14:10:28 +01:00
|
|
|
last_unit.possession)
|
2005-01-24 19:01:55 +01:00
|
|
|
{
|
|
|
|
rndom = math_rnd(0, 1);
|
2005-03-03 13:46:48 +01:00
|
|
|
if(rndom < const_float("float_live_game_penalty_prob"))
|
2005-01-24 19:01:55 +01:00
|
|
|
live_game_event_penalty();
|
2005-03-03 13:46:48 +01:00
|
|
|
else if(rndom < const_float("float_live_game_free_kick_prob"))
|
2005-01-24 19:01:55 +01:00
|
|
|
live_game_event_free_kick();
|
2005-04-13 15:01:59 +02:00
|
|
|
else
|
|
|
|
last_unit.possession = !foul_team;
|
2005-01-24 19:01:55 +01:00
|
|
|
}
|
2005-04-13 15:01:59 +02:00
|
|
|
else
|
|
|
|
last_unit.possession = !foul_team;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate a lost possession event. */
|
|
|
|
void
|
|
|
|
live_game_event_lost_possession(void)
|
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_lost_possession\n");
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-01-09 21:21:22 +01:00
|
|
|
game_get_player(tm[last_unit.possession],
|
2005-01-24 19:01:55 +01:00
|
|
|
last_unit.area, 0, -1, TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(uni(unis->len - 2).event.type == LIVE_GAME_EVENT_GENERAL)
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player2 =
|
|
|
|
uni(unis->len - 2).event.player;
|
2005-01-09 21:21:22 +01:00
|
|
|
else
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player2 =
|
2005-01-09 21:21:22 +01:00
|
|
|
game_get_player(tm[!last_unit.possession],
|
2005-03-03 13:46:48 +01:00
|
|
|
uni(unis->len - 2).area, 0, -1, FALSE);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
live_game_event_general(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate an injury event.
|
2005-01-24 19:01:55 +01:00
|
|
|
@param team The team the player is from.
|
2005-01-09 21:21:22 +01:00
|
|
|
@param player The player that's injured, or -1 if we have to
|
|
|
|
choose a random one.
|
|
|
|
@param create_new Whether to put the event into a new unit instead of
|
|
|
|
the last one. */
|
|
|
|
void
|
2005-01-24 19:01:55 +01:00
|
|
|
live_game_event_injury(gint team, gint player, gboolean create_new)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
|
|
|
LiveGameUnit new;
|
2005-03-08 09:25:46 +01:00
|
|
|
gint old_structure = -1;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_injury\n");
|
2005-01-09 21:21:22 +01:00
|
|
|
if(create_new)
|
|
|
|
{
|
2005-01-24 19:01:55 +01:00
|
|
|
new = last_unit;
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_append_val(unis, new);
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-01-09 21:21:22 +01:00
|
|
|
player;
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.team =
|
2005-01-24 19:01:55 +01:00
|
|
|
team;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else
|
2005-03-08 09:25:46 +01:00
|
|
|
live_game_injury_get_player();
|
2005-01-24 19:01:55 +01:00
|
|
|
|
|
|
|
last_unit.minute = -1;
|
|
|
|
last_unit.event.type = LIVE_GAME_EVENT_INJURY;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(math_rnd(0, 1) < const_float("float_live_game_injury_is_temp"))
|
2005-03-10 21:59:39 +01:00
|
|
|
{
|
2005-01-09 21:21:22 +01:00
|
|
|
last_unit.event.type = LIVE_GAME_EVENT_TEMP_INJURY;
|
2005-04-13 15:01:59 +02:00
|
|
|
|
|
|
|
if(debug < 50 ||
|
2005-05-19 20:13:14 +02:00
|
|
|
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 -
|
2005-04-13 15:01:59 +02:00
|
|
|
math_rnd(const_float("float_live_game_temp_injury_fitness_decrease_lower"),
|
|
|
|
const_float("float_live_game_temp_injury_fitness_decrease_upper")));
|
2005-03-10 21:59:39 +01:00
|
|
|
}
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug >= 50 &&
|
2005-05-19 20:13:14 +02:00
|
|
|
team_is_user(tm[last_unit.event.team]) != -1)
|
2005-04-13 15:01:59 +02:00
|
|
|
return;
|
|
|
|
|
2005-03-08 09:25:46 +01:00
|
|
|
if(last_unit.event.type == LIVE_GAME_EVENT_INJURY)
|
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
game_player_injury(player_of_id_team(tm[last_unit.event.team],
|
|
|
|
last_unit.event.player));
|
2005-03-09 14:10:28 +01:00
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
if(match->subs_left[last_unit.event.team] > 0)
|
2005-03-08 09:25:46 +01:00
|
|
|
{
|
2005-03-09 14:10:28 +01:00
|
|
|
if(show &&
|
2005-05-19 20:13:14 +02:00
|
|
|
team_is_user(tm[last_unit.event.team]) != -1 &&
|
2005-04-10 18:34:27 +02:00
|
|
|
((option_int("int_opt_user_pause_injury",
|
2005-05-19 20:13:14 +02:00
|
|
|
&usr(team_is_user(tm[last_unit.event.team])).options) &&
|
2005-04-10 18:34:27 +02:00
|
|
|
!option_int("int_opt_user_auto_sub",
|
2005-05-19 20:13:14 +02:00
|
|
|
&usr(team_is_user(tm[last_unit.event.team])).options)) ||
|
|
|
|
tm[last_unit.event.team]->players->len == 11))
|
2005-03-09 14:10:28 +01:00
|
|
|
misc_callback_pause_live_game();
|
2005-05-19 20:13:14 +02:00
|
|
|
else if(tm[last_unit.event.team]->players->len > 11)
|
2005-03-09 14:10:28 +01:00
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
old_structure = tm[last_unit.event.team]->structure;
|
2005-03-09 14:10:28 +01:00
|
|
|
live_game_event_substitution(
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.team,
|
2005-03-09 14:10:28 +01:00
|
|
|
game_substitute_player(
|
2005-05-19 20:13:14 +02:00
|
|
|
tm[last_unit.event.team],
|
|
|
|
player_id_index(tm[last_unit.event.team],
|
|
|
|
last_unit.event.player)),
|
|
|
|
last_unit.event.player);
|
2005-03-09 14:10:28 +01:00
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
match->subs_left[last_unit.event.team]--;
|
2005-03-09 14:10:28 +01:00
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
if(old_structure != tm[last_unit.event.team]->structure)
|
|
|
|
live_game_event_team_change(last_unit.event.team,
|
2005-03-09 14:10:28 +01:00
|
|
|
LIVE_GAME_EVENT_STRUCTURE_CHANGE);
|
|
|
|
}
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-09 14:10:28 +01:00
|
|
|
|
|
|
|
game_get_values(match->fix, match->team_values,
|
|
|
|
match->home_advantage);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate a stadium event. */
|
|
|
|
void
|
|
|
|
live_game_event_stadium(void)
|
|
|
|
{
|
2005-03-16 21:48:25 +01:00
|
|
|
gint i;
|
2005-01-09 21:21:22 +01:00
|
|
|
gfloat rndom = math_rnd(0, 1);
|
2005-03-16 21:48:25 +01:00
|
|
|
gfloat probs[3] =
|
|
|
|
{const_float("float_live_game_stadium_event_breakdown"),
|
|
|
|
const_float("float_live_game_stadium_event_riots"),
|
|
|
|
const_float("float_live_game_stadium_event_fire")};
|
|
|
|
|
|
|
|
for(i=1;i<3;i++)
|
|
|
|
probs[i] += probs[i - 1];
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_stadium\n");
|
2005-03-16 21:48:25 +01:00
|
|
|
if(rndom <= probs[0])
|
2005-01-09 21:21:22 +01:00
|
|
|
last_unit.event.type = LIVE_GAME_EVENT_STADIUM_BREAKDOWN;
|
2005-03-16 21:48:25 +01:00
|
|
|
else if(rndom <= probs[1])
|
|
|
|
last_unit.event.type = LIVE_GAME_EVENT_STADIUM_RIOTS;
|
|
|
|
else if(rndom <= probs[2])
|
|
|
|
last_unit.event.type = LIVE_GAME_EVENT_STADIUM_FIRE;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-05-09 22:00:49 +02:00
|
|
|
if(team_is_user(tm0) != -1 && debug < 50)
|
2005-03-16 21:48:25 +01:00
|
|
|
game_stadium_event(&tm0->stadium, last_unit.event.type);
|
|
|
|
|
2005-03-19 21:04:08 +01:00
|
|
|
match->stadium_event = last_unit.event.type;
|
2005-03-16 21:48:25 +01:00
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
live_game_event_general(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate a scoring chance event. */
|
|
|
|
void
|
|
|
|
live_game_event_scoring_chance(void)
|
|
|
|
{
|
2005-03-09 14:10:28 +01:00
|
|
|
gint res_idx = -1;
|
|
|
|
|
|
|
|
if(last_unit.time == LIVE_GAME_UNIT_TIME_EXTRA_TIME)
|
|
|
|
res_idx = 1;
|
|
|
|
else
|
|
|
|
res_idx = 0;
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_scoring_chance\n");
|
2005-03-10 21:59:39 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(math_rnd(0, 1) < const_float("float_live_game_scoring_chance_is_own_goal"))
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
|
|
|
last_unit.event.type = LIVE_GAME_EVENT_OWN_GOAL;
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-03-10 21:59:39 +01:00
|
|
|
game_get_player(tm[!last_unit.possession], GAME_PLAYER_TYPE_DEFEND, 0, -1, FALSE);
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.team = !last_unit.possession;
|
2005-03-09 14:10:28 +01:00
|
|
|
match->fix->result[last_unit.possession][res_idx]++;
|
|
|
|
last_unit.result[last_unit.possession]++;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
if(uni(unis->len - 2).event.player != -1 &&
|
2005-04-13 15:01:59 +02:00
|
|
|
math_rnd(0, 1) < const_float("float_live_game_player_in_poss_shoots") &&
|
2005-06-04 22:22:22 +02:00
|
|
|
query_player_id_in_team(uni(unis->len - 2).event.player,
|
|
|
|
tm[last_unit.possession]))
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
|
|
|
uni(unis->len - 2).event.player;
|
2005-01-09 21:21:22 +01:00
|
|
|
else
|
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
if(uni(unis->len - 2).event.player != -1 &&
|
2005-06-04 22:22:22 +02:00
|
|
|
query_player_id_in_team(uni(unis->len - 2).event.player,
|
|
|
|
tm[last_unit.possession]))
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-01-24 19:01:55 +01:00
|
|
|
game_get_player(tm[last_unit.possession], last_unit.area, 0,
|
2005-05-19 20:13:14 +02:00
|
|
|
uni(unis->len - 2).event.player,
|
2005-01-24 19:01:55 +01:00
|
|
|
TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player2 =
|
|
|
|
uni(unis->len - 2).event.player;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-01-24 19:01:55 +01:00
|
|
|
game_get_player(tm[last_unit.possession], last_unit.area, 0, -1, TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player2 =
|
2005-01-24 19:01:55 +01:00
|
|
|
game_get_player(tm[last_unit.possession], last_unit.area, 0,
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player, TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
}
|
2005-05-09 16:00:43 +02:00
|
|
|
|
|
|
|
if(math_rnd(0, 1) < const_float("float_live_game_scoring_chance_is_header"))
|
|
|
|
last_unit.event.type = LIVE_GAME_EVENT_HEADER;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-10 21:59:39 +01:00
|
|
|
if(last_unit.event.type != LIVE_GAME_EVENT_OWN_GOAL)
|
|
|
|
live_game_event_duel();
|
2005-05-26 11:07:56 +02:00
|
|
|
else
|
|
|
|
live_game_event_general(TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate a penalty event. */
|
|
|
|
void
|
|
|
|
live_game_event_penalty(void)
|
|
|
|
{
|
|
|
|
LiveGameUnit new;
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_penalty\n");
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(last_unit.time != LIVE_GAME_UNIT_TIME_PENALTIES)
|
|
|
|
{
|
|
|
|
new = last_unit;
|
|
|
|
new.minute = -1;
|
|
|
|
new.event.type = LIVE_GAME_EVENT_PENALTY;
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
|
|
|
g_array_append_val(unis, new);
|
|
|
|
}
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player2 =
|
|
|
|
last_unit.event.team = -1;
|
2005-05-18 18:00:49 +02:00
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
if(last_unit.time == LIVE_GAME_UNIT_TIME_PENALTIES)
|
|
|
|
{
|
2005-03-03 13:46:48 +01:00
|
|
|
if(uni(unis->len - 2).event.type == LIVE_GAME_EVENT_PENALTIES)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
2005-03-03 13:46:48 +01:00
|
|
|
last_unit.possession = math_rndi(0, 1);
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-03-03 13:46:48 +01:00
|
|
|
game_get_player(tm[last_unit.possession],
|
|
|
|
GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
else if(uni(unis->len - 4).event.type == LIVE_GAME_EVENT_PENALTIES)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
2005-03-03 13:46:48 +01:00
|
|
|
last_unit.possession = !uni(unis->len - 3).possession;
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-03-03 13:46:48 +01:00
|
|
|
game_get_player(tm[last_unit.possession],
|
|
|
|
GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-03 13:46:48 +01:00
|
|
|
last_unit.possession = !uni(unis->len - 3).possession;
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-03-03 13:46:48 +01:00
|
|
|
game_get_player(tm[last_unit.possession],
|
2005-01-09 21:21:22 +01:00
|
|
|
GAME_PLAYER_TYPE_PENALTY,
|
2005-05-19 20:13:14 +02:00
|
|
|
uni(unis->len - 4).event.player, -1, FALSE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.team =
|
2005-01-09 21:21:22 +01:00
|
|
|
last_unit.possession;
|
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-05-18 18:00:49 +02:00
|
|
|
game_get_default_penalty_shooter(tm[last_unit.possession]);
|
2005-05-19 20:13:14 +02:00
|
|
|
if(last_unit.event.player == -1)
|
|
|
|
last_unit.event.player =
|
2005-03-03 13:46:48 +01:00
|
|
|
game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
live_game_event_duel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate a general event.
|
|
|
|
@param create_new Whether we create a new unit for the event. */
|
|
|
|
void
|
|
|
|
live_game_event_general(gboolean create_new)
|
|
|
|
{
|
|
|
|
LiveGameUnit new;
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_general\n");
|
2005-01-09 21:21:22 +01:00
|
|
|
if(create_new)
|
|
|
|
{
|
|
|
|
new.minute = live_game_get_minute();
|
|
|
|
new.time = last_unit.time;
|
2005-03-03 13:46:48 +01:00
|
|
|
new.event.type = LIVE_GAME_EVENT_GENERAL;
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-03-03 13:46:48 +01:00
|
|
|
new.result[0] = last_unit.result[0];
|
|
|
|
new.result[1] = last_unit.result[1];
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.team = -1;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
if(last_unit.event.type == LIVE_GAME_EVENT_GENERAL ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_START_MATCH ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_LOST_POSSESSION ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_FOUL ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_FOUL_YELLOW ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_SEND_OFF ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_INJURY ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_TEMP_INJURY ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_STADIUM ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_STADIUM_BREAKDOWN ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_STADIUM_FIRE ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_STADIUM_RIOTS ||
|
|
|
|
((last_unit.event.type == LIVE_GAME_EVENT_POST ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_CROSS_BAR) &&
|
2005-03-03 13:46:48 +01:00
|
|
|
math_rnd(0, 1) < const_float("float_live_game_possession_after_post")))
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
|
|
|
new.possession = last_unit.possession;
|
2005-01-24 19:01:55 +01:00
|
|
|
new.area = (last_unit.event.type == LIVE_GAME_EVENT_GENERAL) ?
|
|
|
|
live_game_get_area(&last_unit) : last_unit.area;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else if(last_unit.event.type == LIVE_GAME_EVENT_GOAL ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_OWN_GOAL ||
|
2005-06-26 13:42:01 +02:00
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_MISS ||
|
2005-01-09 21:21:22 +01:00
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_SAVE ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_POST ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_CROSS_BAR)
|
|
|
|
{
|
|
|
|
new.possession = !last_unit.possession;
|
2005-01-24 19:01:55 +01:00
|
|
|
if(last_unit.event.type == LIVE_GAME_EVENT_GOAL ||
|
|
|
|
last_unit.event.type == LIVE_GAME_EVENT_OWN_GOAL)
|
|
|
|
new.area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
|
|
|
else
|
|
|
|
new.area = LIVE_GAME_UNIT_AREA_DEFEND;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else if(last_unit.event.type == LIVE_GAME_EVENT_HALF_TIME)
|
|
|
|
{
|
|
|
|
new.possession = !match->started_game;
|
|
|
|
new.time = LIVE_GAME_UNIT_TIME_SECOND_HALF;
|
2005-01-24 19:01:55 +01:00
|
|
|
new.area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else if(last_unit.event.type == LIVE_GAME_EVENT_EXTRA_TIME)
|
|
|
|
{
|
|
|
|
new.possession = math_rndi(0, 1);
|
|
|
|
new.time = LIVE_GAME_UNIT_TIME_EXTRA_TIME;
|
2005-01-24 19:01:55 +01:00
|
|
|
new.area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
2005-01-24 19:01:55 +01:00
|
|
|
else
|
2005-06-17 14:57:05 +02:00
|
|
|
{
|
2005-01-24 19:01:55 +01:00
|
|
|
g_warning("live_game_event_general: unknown event type: %d\n",
|
|
|
|
last_unit.event.type);
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_INT_NOT_FOUND, NULL);
|
|
|
|
}
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_append_val(unis, new);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
2005-01-24 19:01:55 +01:00
|
|
|
live_game_event_general_get_players();
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-24 19:01:55 +01:00
|
|
|
}
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-01-24 19:01:55 +01:00
|
|
|
/** Fill in the players values in a general unit. */
|
|
|
|
void
|
|
|
|
live_game_event_general_get_players(void)
|
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
gint *pl1 = &last_unit.event.player;
|
|
|
|
gint *pl2 = &last_unit.event.player2;
|
2005-01-24 19:01:55 +01:00
|
|
|
gint old_pl1 =
|
2005-05-19 20:13:14 +02:00
|
|
|
uni(unis->len - 2).event.player;
|
2005-03-03 13:46:48 +01:00
|
|
|
gint type = uni(unis->len - 2).event.type;
|
2005-01-24 19:01:55 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_general_get_players\n");
|
2005-01-24 19:01:55 +01:00
|
|
|
*pl1 = *pl2 = -1;
|
|
|
|
|
|
|
|
if(type == LIVE_GAME_EVENT_LOST_POSSESSION)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
2005-03-08 09:25:46 +01:00
|
|
|
*pl1 = game_get_player(tm[last_unit.possession],
|
2005-01-24 19:01:55 +01:00
|
|
|
last_unit.area, 0, *pl1,
|
|
|
|
TRUE);
|
2005-03-08 09:25:46 +01:00
|
|
|
*pl2 = old_pl1;
|
2005-01-24 19:01:55 +01:00
|
|
|
}
|
|
|
|
else if(type != LIVE_GAME_EVENT_GENERAL)
|
|
|
|
{
|
|
|
|
*pl1 = game_get_player(tm[last_unit.possession],
|
|
|
|
last_unit.area, 0, -1, TRUE);
|
2005-03-03 13:46:48 +01:00
|
|
|
if(math_rnd(0, 1) < const_float("float_live_game_general_event_second_player"))
|
2005-01-24 19:01:55 +01:00
|
|
|
*pl2 = game_get_player(tm[last_unit.possession],
|
|
|
|
last_unit.area, 0, *pl1, TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-04 22:22:22 +02:00
|
|
|
*pl2 = query_player_id_in_team(old_pl1, tm[last_unit.possession]) ? old_pl1 : -1;
|
2005-01-24 19:01:55 +01:00
|
|
|
*pl1 = game_get_player(tm[last_unit.possession],
|
|
|
|
last_unit.area, 0, *pl2, TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate a free kick event. */
|
|
|
|
void
|
|
|
|
live_game_event_free_kick(void)
|
|
|
|
{
|
2005-01-24 19:01:55 +01:00
|
|
|
LiveGameUnit new = last_unit;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_free_kick\n");
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.player =
|
|
|
|
new.event.player2 = -1;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
new.minute = -1;
|
|
|
|
|
|
|
|
new.event.type = LIVE_GAME_EVENT_FREE_KICK;
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.team =
|
2005-01-09 21:21:22 +01:00
|
|
|
new.possession;
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.player =
|
2005-05-18 18:00:49 +02:00
|
|
|
game_get_default_penalty_shooter(tm[new.possession]);
|
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
if(new.event.player == -1)
|
|
|
|
new.event.player =
|
2005-01-24 19:01:55 +01:00
|
|
|
game_get_player(tm[new.possession], new.area, 0, -1, TRUE);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_append_val(unis, new);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
live_game_event_duel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate a send-off event. */
|
|
|
|
void
|
2005-03-09 14:10:28 +01:00
|
|
|
live_game_event_send_off(gint team, gint player, gboolean second_yellow)
|
2005-01-09 21:21:22 +01:00
|
|
|
{
|
2005-01-24 19:01:55 +01:00
|
|
|
LiveGameUnit new = last_unit;
|
2005-03-09 14:10:28 +01:00
|
|
|
gint substitute = -1, to_substitute = -1;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_send_off\n");
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.player =
|
|
|
|
new.event.player2 = -1;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
new.minute = -1;
|
|
|
|
|
|
|
|
new.event.type = LIVE_GAME_EVENT_SEND_OFF;
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.player = player;
|
|
|
|
new.event.team = team;
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_append_val(unis, new);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-03-08 09:25:46 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug >= 50 && team_is_user(tm[team]) != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
player_of_id_team(tm[team], player)->cskill = 0;
|
2005-03-10 21:59:39 +01:00
|
|
|
if(second_yellow)
|
2005-04-13 15:01:59 +02:00
|
|
|
player_card_set(player_of_id_team(tm[team], player), match->fix->clid, PLAYER_VALUE_CARD_RED, 2, FALSE);
|
2005-03-10 21:59:39 +01:00
|
|
|
else
|
2005-04-13 15:01:59 +02:00
|
|
|
player_card_set(player_of_id_team(tm[team], player), match->fix->clid, PLAYER_VALUE_CARD_RED,
|
2005-03-10 21:59:39 +01:00
|
|
|
game_player_get_ban_duration(), FALSE);
|
2005-05-19 21:43:22 +02:00
|
|
|
|
|
|
|
player_of_id_team(tm[team], player)->career[PLAYER_VALUE_CARD_RED]++;
|
2005-03-09 14:10:28 +01:00
|
|
|
|
2005-05-09 22:00:49 +02:00
|
|
|
if(team_is_user(tm[team]) != -1)
|
|
|
|
{
|
|
|
|
tm[team]->structure = team_find_appropriate_structure(tm[team]);
|
|
|
|
team_rearrange(tm[team]);
|
|
|
|
live_game_event_team_change(team, LIVE_GAME_EVENT_STRUCTURE_CHANGE);
|
|
|
|
}
|
|
|
|
|
2005-03-09 14:10:28 +01:00
|
|
|
if(match->subs_left[team] > 0)
|
2005-03-08 09:25:46 +01:00
|
|
|
{
|
2005-03-09 14:10:28 +01:00
|
|
|
if(show && team_is_user(tm[team]) != -1 &&
|
2005-04-10 18:34:27 +02:00
|
|
|
((option_int("int_opt_user_pause_red",
|
|
|
|
&usr(team_is_user(tm[team])).options) &&
|
|
|
|
!option_int("int_opt_user_auto_sub",
|
|
|
|
&usr(team_is_user(tm[team])).options)) ||
|
|
|
|
tm[team]->players->len == 1))
|
2005-03-09 14:10:28 +01:00
|
|
|
misc_callback_pause_live_game();
|
|
|
|
else if(tm[team]->players->len > 11)
|
|
|
|
{
|
2005-05-16 16:44:13 +02:00
|
|
|
game_substitute_player_send_off(match->fix->clid,
|
|
|
|
tm[team], player_id_index(tm[team], player),
|
2005-03-09 14:10:28 +01:00
|
|
|
&to_substitute, &substitute);
|
2005-03-08 09:25:46 +01:00
|
|
|
|
2005-03-09 14:10:28 +01:00
|
|
|
if(to_substitute != -1)
|
|
|
|
{
|
|
|
|
live_game_event_substitution(team, substitute, to_substitute);
|
|
|
|
match->subs_left[team]--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tm[team]->structure = team_find_appropriate_structure(tm[team]);
|
|
|
|
team_rearrange(tm[team]);
|
|
|
|
}
|
2005-03-08 09:25:46 +01:00
|
|
|
live_game_event_team_change(team, LIVE_GAME_EVENT_STRUCTURE_CHANGE);
|
2005-03-09 14:10:28 +01:00
|
|
|
}
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
2005-05-09 22:00:49 +02:00
|
|
|
else if(team_is_user(tm[team]) == -1)
|
2005-03-09 14:10:28 +01:00
|
|
|
{
|
|
|
|
tm[team]->structure = team_find_appropriate_structure(tm[team]);
|
|
|
|
team_rearrange(tm[team]);
|
|
|
|
live_game_event_team_change(team, LIVE_GAME_EVENT_STRUCTURE_CHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
game_get_values(match->fix, match->team_values,
|
|
|
|
match->home_advantage);
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Show a substitution event.
|
|
|
|
@param team_number The team that substitutes.
|
|
|
|
@param sub_in The id of the player who moves into the team.
|
|
|
|
@param sub_out The id of the player who gets replaced. */
|
|
|
|
void
|
|
|
|
live_game_event_substitution(gint team_number, gint sub_in, gint sub_out)
|
|
|
|
{
|
|
|
|
LiveGameUnit new = last_unit;
|
|
|
|
|
|
|
|
new.minute = -1;
|
|
|
|
new.time = live_game_get_time(&last_unit);
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-03-08 09:25:46 +01:00
|
|
|
|
|
|
|
new.event.type = LIVE_GAME_EVENT_SUBSTITUTION;
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.team = team_number;
|
|
|
|
new.event.player = sub_in;
|
|
|
|
new.event.player2 = sub_out;
|
2005-03-08 09:25:46 +01:00
|
|
|
|
2005-03-09 14:10:28 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(player_of_id_team(tm[team_number], sub_in)->cskill > 0)
|
2005-03-13 16:46:15 +01:00
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
player_games_goals_set(player_of_id_team(tm[team_number], sub_in),
|
2005-05-19 21:43:22 +02:00
|
|
|
match->fix->clid, PLAYER_VALUE_GAMES, 1);
|
|
|
|
player_of_id_team(tm[team_number], sub_in)->career[PLAYER_VALUE_GAMES]++;
|
2005-04-13 15:01:59 +02:00
|
|
|
player_of_id_team(tm[team_number], sub_in)->participation = TRUE;
|
2005-03-13 16:46:15 +01:00
|
|
|
}
|
2005-03-09 14:10:28 +01:00
|
|
|
|
2005-03-08 09:25:46 +01:00
|
|
|
g_array_append_val(unis, new);
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Show a team change event, e.g. structure change.
|
|
|
|
@param team_number The index of the team.
|
|
|
|
@param event_type The event type. */
|
|
|
|
void
|
|
|
|
live_game_event_team_change(gint team_number, gint event_type)
|
|
|
|
{
|
|
|
|
LiveGameUnit new = last_unit;
|
|
|
|
|
|
|
|
new.minute = -1;
|
|
|
|
new.time = live_game_get_time(&last_unit);
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-03-08 09:25:46 +01:00
|
|
|
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.team = team_number;
|
|
|
|
new.event.player =
|
|
|
|
new.event.player2 = -1;
|
2005-03-08 09:25:46 +01:00
|
|
|
new.event.type = event_type;
|
|
|
|
|
|
|
|
g_array_append_val(unis, new);
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate whether a player who tries to score succeeds. */
|
|
|
|
void
|
|
|
|
live_game_event_duel(void)
|
|
|
|
{
|
|
|
|
gfloat rndom = math_rnd(0, 1);
|
|
|
|
gfloat scoring_prob;
|
|
|
|
gfloat duel_factor;
|
2005-01-24 19:01:55 +01:00
|
|
|
LiveGameUnit new = last_unit;
|
2005-01-09 21:21:22 +01:00
|
|
|
Player *attacker, *goalie;
|
2005-01-24 19:01:55 +01:00
|
|
|
gint res_idx1, res_idx2;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_event_duel\n");
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
new.minute = -1;
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.team = new.possession;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-05-18 18:00:49 +02:00
|
|
|
new.event.commentary = NULL;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
attacker = player_of_id_team(tm[new.possession],
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.player);
|
2005-04-13 15:01:59 +02:00
|
|
|
goalie = player_of_idx_team(tm[!new.possession], 0);
|
2005-05-19 20:13:14 +02:00
|
|
|
new.event.player2 = goalie->id;
|
2005-05-18 18:00:49 +02:00
|
|
|
|
2005-03-13 16:46:15 +01:00
|
|
|
duel_factor = player_get_game_skill(attacker, FALSE) /
|
|
|
|
player_get_game_skill(goalie, FALSE);
|
|
|
|
|
2005-01-24 19:01:55 +01:00
|
|
|
res_idx1 = new.possession;
|
2005-01-09 21:21:22 +01:00
|
|
|
if(new.time == LIVE_GAME_UNIT_TIME_PENALTIES)
|
2005-01-24 19:01:55 +01:00
|
|
|
res_idx2 = 2;
|
2005-01-09 21:21:22 +01:00
|
|
|
else if(new.time == LIVE_GAME_UNIT_TIME_EXTRA_TIME)
|
2005-01-24 19:01:55 +01:00
|
|
|
res_idx2 = 1;
|
2005-01-09 21:21:22 +01:00
|
|
|
else
|
2005-01-24 19:01:55 +01:00
|
|
|
res_idx2 = 0;
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
if(last_unit.event.type == LIVE_GAME_EVENT_PENALTY)
|
2005-03-03 13:46:48 +01:00
|
|
|
scoring_prob = const_float("float_live_game_score_penalty") * duel_factor;
|
2005-01-09 21:21:22 +01:00
|
|
|
else if(last_unit.event.type == LIVE_GAME_EVENT_FREE_KICK)
|
2005-03-03 13:46:48 +01:00
|
|
|
scoring_prob = const_float("float_live_game_score_free_kick") * duel_factor;
|
2005-01-09 21:21:22 +01:00
|
|
|
else
|
2005-03-03 13:46:48 +01:00
|
|
|
scoring_prob = const_float("float_live_game_score_base_prob") *
|
|
|
|
powf(duel_factor, const_float("float_live_game_score_duel_exponent")) *
|
2005-01-09 21:21:22 +01:00
|
|
|
powf(match->team_values[new.possession][GAME_TEAM_VALUE_ATTACK] /
|
2005-03-03 13:46:48 +01:00
|
|
|
match->team_values[!new.possession][GAME_TEAM_VALUE_DEFEND],
|
|
|
|
const_float("float_live_game_score_team_exponent"));
|
|
|
|
|
2005-03-08 09:25:46 +01:00
|
|
|
if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES)
|
2005-05-19 21:43:22 +02:00
|
|
|
{
|
|
|
|
player_games_goals_set(attacker, match->fix->clid, PLAYER_VALUE_SHOTS, 1);
|
|
|
|
attacker->career[PLAYER_VALUE_SHOTS]++;
|
|
|
|
}
|
2005-03-08 09:25:46 +01:00
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
if(rndom < scoring_prob)
|
|
|
|
{
|
|
|
|
new.event.type = LIVE_GAME_EVENT_GOAL;
|
2005-01-24 19:01:55 +01:00
|
|
|
match->fix->result[res_idx1][res_idx2]++;
|
2005-03-03 13:46:48 +01:00
|
|
|
new.result[res_idx1]++;
|
2005-03-08 09:25:46 +01:00
|
|
|
|
|
|
|
if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES)
|
|
|
|
{
|
2005-05-19 21:43:22 +02:00
|
|
|
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]++;
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
new.event.type = math_gauss_disti(LIVE_GAME_EVENT_POST, LIVE_GAME_EVENT_CROSS_BAR);
|
|
|
|
|
2005-04-30 15:57:58 +02:00
|
|
|
if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES &&
|
|
|
|
(new.event.type == LIVE_GAME_EVENT_SAVE ||
|
|
|
|
new.event.type == LIVE_GAME_EVENT_GOAL))
|
2005-05-19 21:43:22 +02:00
|
|
|
{
|
|
|
|
player_games_goals_set(goalie, match->fix->clid, PLAYER_VALUE_SHOTS, 1);
|
|
|
|
goalie->career[PLAYER_VALUE_SHOTS]++;
|
|
|
|
}
|
2005-04-30 15:57:58 +02:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_append_val(unis, new);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
live_game_finish_unit();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
if(last_unit.time != LIVE_GAME_UNIT_TIME_PENALTIES)
|
|
|
|
live_game_event_general(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Find out whether the specified player already has a yellow card
|
|
|
|
in this game.
|
|
|
|
@param team The team index, 0 or 1.
|
|
|
|
@param player The player index.
|
|
|
|
@return TRUE or FALSE. */
|
|
|
|
gboolean
|
|
|
|
query_live_game_second_yellow(gint team, gint player)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
for(i=0;i<unis->len - 1;i++)
|
2005-01-09 21:21:22 +01:00
|
|
|
if(uni(i).event.type == LIVE_GAME_EVENT_FOUL_YELLOW &&
|
|
|
|
uni(i).possession != team &&
|
2005-05-19 20:13:14 +02:00
|
|
|
uni(i).event.player2 == player)
|
2005-01-09 21:21:22 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/** Find out whether there should be a half-time break
|
|
|
|
or extra time break or so.
|
|
|
|
@param minute The minute of the #LiveGameUnit we want to find
|
|
|
|
the break event for.
|
|
|
|
@param time The #LiveGameUnitTime of the #LiveGameUnit we want to find
|
|
|
|
the break event for.
|
|
|
|
@return TRUE if we have a break, FALSE otherwise. */
|
|
|
|
gboolean
|
|
|
|
query_live_game_event_is_break(gint minute, gint time)
|
|
|
|
{
|
|
|
|
gfloat rndom;
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
if(time == LIVE_GAME_UNIT_TIME_EXTRA_TIME)
|
|
|
|
return (minute >= 120);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
if(time == LIVE_GAME_UNIT_TIME_PENALTIES)
|
|
|
|
return query_live_game_penalties_over();
|
|
|
|
|
|
|
|
rndom = math_rnd(0, 1);
|
|
|
|
|
|
|
|
if(time == LIVE_GAME_UNIT_TIME_FIRST_HALF)
|
|
|
|
return (minute >= 45 && rndom >
|
2005-03-03 13:46:48 +01:00
|
|
|
powf(const_float("float_live_game_break_base"),
|
|
|
|
(gfloat)(minute - 44) *
|
|
|
|
const_float("float_live_game_45_break_exponent_factor")));
|
2005-01-09 21:21:22 +01:00
|
|
|
else
|
|
|
|
return (minute >= 90 && rndom >
|
2005-03-03 13:46:48 +01:00
|
|
|
powf(const_float("float_live_game_break_base"),
|
|
|
|
(gfloat)(minute - 89) *
|
|
|
|
const_float("float_live_game_90_break_exponent_factor")));
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Find out whether the final result of the penalties is
|
|
|
|
already reached.
|
|
|
|
@return TRUE if the penalties are over,
|
|
|
|
FALSE otherwise. */
|
|
|
|
gboolean
|
|
|
|
query_live_game_penalties_over(void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gint pen_attempted[2] = {0, 0};
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
for(i=unis->len - 1; i > 0; i--)
|
2005-01-09 21:21:22 +01:00
|
|
|
if(uni(i).time == LIVE_GAME_UNIT_TIME_PENALTIES)
|
|
|
|
{
|
|
|
|
if(uni(i).event.type == LIVE_GAME_EVENT_PENALTY)
|
2005-03-03 13:46:48 +01:00
|
|
|
pen_attempted[uni(i).possession]++;
|
2005-01-09 21:21:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(pen_attempted[0] + pen_attempted[1] >= 10)
|
2005-03-03 13:46:48 +01:00
|
|
|
return (match->fix->result[0][2] != match->fix->result[1][2] &&
|
|
|
|
pen_attempted[0] == pen_attempted[1]);
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
(match->fix->result[0][2] - match->fix->result[1][2] > 5 - pen_attempted[1] ||
|
|
|
|
match->fix->result[1][2] - match->fix->result[0][2] > 5 - pen_attempted[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return a #LiveGameUnitTime depending on the time
|
|
|
|
of the last unit.
|
|
|
|
@return A new #LiveGameUnitTime. */
|
|
|
|
gint
|
|
|
|
live_game_get_break(void)
|
|
|
|
{
|
|
|
|
gint type;
|
|
|
|
|
|
|
|
if(last_unit.time == LIVE_GAME_UNIT_TIME_FIRST_HALF)
|
|
|
|
type = LIVE_GAME_EVENT_HALF_TIME;
|
|
|
|
else if(last_unit.time == LIVE_GAME_UNIT_TIME_SECOND_HALF)
|
|
|
|
{
|
|
|
|
if(query_fixture_is_draw(match->fix))
|
|
|
|
type = LIVE_GAME_EVENT_EXTRA_TIME;
|
|
|
|
else
|
|
|
|
type = LIVE_GAME_EVENT_END_MATCH;
|
|
|
|
}
|
|
|
|
else if(last_unit.time == LIVE_GAME_UNIT_TIME_EXTRA_TIME)
|
|
|
|
{
|
|
|
|
if(query_fixture_is_draw(match->fix))
|
|
|
|
type = LIVE_GAME_EVENT_PENALTIES;
|
|
|
|
else
|
|
|
|
type = LIVE_GAME_EVENT_END_MATCH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
type = LIVE_GAME_EVENT_END_MATCH;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the time for the unit depending of time and
|
|
|
|
event of the last one.
|
|
|
|
@param unit The unit before the one we create.
|
|
|
|
@return A #LiveGameUnitTime */
|
|
|
|
gint
|
|
|
|
live_game_get_time(const LiveGameUnit *unit)
|
|
|
|
{
|
|
|
|
gint time;
|
|
|
|
|
|
|
|
if(unit->event.type == LIVE_GAME_EVENT_HALF_TIME)
|
|
|
|
time = LIVE_GAME_UNIT_TIME_SECOND_HALF;
|
|
|
|
else if(unit->event.type == LIVE_GAME_EVENT_EXTRA_TIME)
|
|
|
|
time = LIVE_GAME_UNIT_TIME_EXTRA_TIME;
|
|
|
|
else if(unit->event.type == LIVE_GAME_EVENT_PENALTIES)
|
|
|
|
time = LIVE_GAME_UNIT_TIME_PENALTIES;
|
|
|
|
else
|
|
|
|
time = unit->time;
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
/** Return the minute for the next game unit.
|
2005-01-09 21:21:22 +01:00
|
|
|
@return A new minute for a LiveGameUnit. */
|
|
|
|
gint
|
|
|
|
live_game_get_minute(void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if(last_unit.event.type == LIVE_GAME_EVENT_HALF_TIME)
|
|
|
|
return 46;
|
|
|
|
else if(last_unit.event.type == LIVE_GAME_EVENT_EXTRA_TIME)
|
|
|
|
return 91;
|
|
|
|
else if(last_unit.event.type == LIVE_GAME_EVENT_PENALTIES ||
|
|
|
|
last_unit.time == LIVE_GAME_UNIT_TIME_PENALTIES)
|
|
|
|
return 120;
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
for(i=unis->len - 1; i>=0; i--)
|
2005-01-09 21:21:22 +01:00
|
|
|
if(uni(i).minute != -1)
|
|
|
|
return uni(i).minute + 1;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the minute of the unit (ie. look up the last unit
|
|
|
|
with a 'normal' minute value if minute = -1).
|
|
|
|
@param unit The unit we examine.
|
|
|
|
@return A minute between 1 and 120. */
|
|
|
|
gint
|
|
|
|
live_game_unit_get_minute(const LiveGameUnit *unit)
|
|
|
|
{
|
|
|
|
gint i, j;
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
for(i=unis->len - 1; i >= 0; i--)
|
2005-01-09 21:21:22 +01:00
|
|
|
if(&uni(i) == unit)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(i == -1)
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_INT_NOT_FOUND,
|
|
|
|
"live_game_unit_get_minute: reached end of units array.");
|
2005-01-09 21:21:22 +01:00
|
|
|
else
|
|
|
|
for(j=i;j>=0;j--)
|
|
|
|
if(uni(j).minute != -1)
|
|
|
|
return uni(j).minute;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-03-11 13:17:48 +01:00
|
|
|
/** Return the unit before or after the specified one.
|
|
|
|
@param unit The unit specified.
|
|
|
|
@param gap How many units to skip. */
|
|
|
|
LiveGameUnit*
|
|
|
|
live_game_unit_before(const LiveGameUnit* unit, gint gap)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2005-03-27 19:59:57 +02:00
|
|
|
if(gap > 0)
|
2005-03-11 13:17:48 +01:00
|
|
|
{
|
|
|
|
for(i=unis->len - 1;i>=0;i--)
|
|
|
|
if(&uni(i) == unit)
|
|
|
|
{
|
|
|
|
if(i - gap > 0)
|
|
|
|
return &uni(i - gap);
|
|
|
|
else
|
|
|
|
g_warning("live_game_unit_before: no unit found for gap %d\n", gap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(i=unis->len - 1;i>=0;i--)
|
|
|
|
if(&uni(i) == unit)
|
|
|
|
{
|
2005-03-27 19:59:57 +02:00
|
|
|
if(i + gap < unis->len - 1)
|
2005-03-11 13:17:48 +01:00
|
|
|
return &uni(i + gap);
|
|
|
|
else
|
|
|
|
g_warning("live_game_unit_before: no unit found for gap %d\n", gap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_POINTER_NOT_FOUND, NULL);
|
2005-06-15 21:13:35 +02:00
|
|
|
|
2005-03-11 13:17:48 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-24 19:01:55 +01:00
|
|
|
/** Calculate which area the ball is going to be in in
|
|
|
|
the next unit.
|
|
|
|
@param unit The previous unit.
|
|
|
|
@return An area, defend, midfield or attack. */
|
|
|
|
gint
|
|
|
|
live_game_get_area(const LiveGameUnit *unit)
|
|
|
|
{
|
|
|
|
gint new_area = unit->area;
|
|
|
|
gfloat rndom = math_rnd(0, 1);
|
|
|
|
gfloat probs[4] =
|
2005-03-03 13:46:48 +01:00
|
|
|
{const_float("float_live_game_area_def_mid") *
|
|
|
|
live_game_pit_teams(unit, const_float("float_live_game_area_def_mid_team_exponent")),
|
|
|
|
const_float("float_live_game_area_mid_att") *
|
|
|
|
live_game_pit_teams(unit, const_float("float_live_game_area_mid_team_exponent")),
|
|
|
|
const_float("float_live_game_area_mid_def") /
|
|
|
|
live_game_pit_teams(unit, const_float("float_live_game_area_mid_team_exponent")),
|
|
|
|
const_float("float_live_game_area_att_mid") /
|
|
|
|
live_game_pit_teams(unit, const_float("float_live_game_area_att_mid_team_exponent"))};
|
2005-01-24 19:01:55 +01:00
|
|
|
|
|
|
|
if(unit->area == LIVE_GAME_UNIT_AREA_DEFEND && rndom < probs[0])
|
|
|
|
new_area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
|
|
|
else if(unit->area == LIVE_GAME_UNIT_AREA_MIDFIELD)
|
|
|
|
{
|
|
|
|
if(rndom < probs[1])
|
|
|
|
new_area = LIVE_GAME_UNIT_AREA_ATTACK;
|
|
|
|
else if(rndom < probs[1] + probs[2])
|
|
|
|
new_area = LIVE_GAME_UNIT_AREA_DEFEND;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if(rndom < probs[3])
|
|
|
|
new_area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
|
|
|
|
|
|
|
return new_area;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the team values factor weighted with the given exponent
|
|
|
|
and depending on the pitch area.
|
|
|
|
@param unit The unit we calculate the value for.
|
|
|
|
@param exponent The weighting exponent. */
|
|
|
|
gfloat
|
|
|
|
live_game_pit_teams(const LiveGameUnit *unit, gfloat exponent)
|
|
|
|
{
|
|
|
|
gfloat factor;
|
|
|
|
|
|
|
|
if(unit->area == LIVE_GAME_UNIT_AREA_DEFEND)
|
|
|
|
factor = powf(match->team_values[unit->possession][GAME_TEAM_VALUE_DEFEND] /
|
|
|
|
match->team_values[!unit->possession][GAME_TEAM_VALUE_ATTACK], exponent);
|
|
|
|
else if(unit->area == LIVE_GAME_UNIT_AREA_MIDFIELD)
|
|
|
|
factor = powf(match->team_values[unit->possession][GAME_TEAM_VALUE_MIDFIELD] /
|
|
|
|
match->team_values[!unit->possession][GAME_TEAM_VALUE_MIDFIELD], exponent);
|
|
|
|
else
|
|
|
|
factor = powf(match->team_values[unit->possession][GAME_TEAM_VALUE_ATTACK] /
|
|
|
|
match->team_values[!unit->possession][GAME_TEAM_VALUE_DEFEND], exponent);
|
|
|
|
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
/** Some polishing of the latest unit. Write commentary etc. */
|
|
|
|
void
|
|
|
|
live_game_finish_unit(void)
|
|
|
|
{
|
|
|
|
LiveGameUnit *unit = &last_unit;
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug > 100 && fixture_user_team_involved(match->fix) != -1)
|
|
|
|
printf("\t\tlive_game_finish_unit\n");
|
|
|
|
|
2005-05-18 18:00:49 +02:00
|
|
|
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,
|
2005-05-19 20:13:14 +02:00
|
|
|
unit->event.type, unit->possession, unit->event.team,
|
|
|
|
unit->event.player,
|
|
|
|
unit->event.player2);
|
2005-05-18 18:00:49 +02:00
|
|
|
|
2005-03-10 21:59:39 +01:00
|
|
|
if(unit->minute != -1 && unit->time != LIVE_GAME_UNIT_TIME_PENALTIES &&
|
|
|
|
fixture_user_team_involved(match->fix) != -1)
|
2005-03-09 15:02:49 +01:00
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
if(debug < 50)
|
|
|
|
game_decrease_fitness(match->fix);
|
2005-03-13 16:46:15 +01:00
|
|
|
game_get_values(match->fix, match->team_values,
|
|
|
|
match->home_advantage);
|
2005-03-18 23:03:23 +01:00
|
|
|
if(stat2 == cur_user && show &&
|
2005-03-23 20:03:26 +01:00
|
|
|
unit->minute % opt_int("int_opt_live_game_player_list_refresh") == 0)
|
2005-03-24 21:22:44 +01:00
|
|
|
treeview_show_user_player_list();
|
2005-03-09 15:02:49 +01:00
|
|
|
}
|
|
|
|
|
2005-03-11 13:17:48 +01:00
|
|
|
if(fixture_user_team_involved(match->fix) != -1)
|
|
|
|
{
|
|
|
|
if(unit->time != LIVE_GAME_UNIT_TIME_PENALTIES)
|
|
|
|
{
|
|
|
|
game_update_stats(match, unit);
|
2005-03-13 16:46:15 +01:00
|
|
|
if(show)
|
|
|
|
treeview_show_game_stats(GTK_TREE_VIEW(lookup_widget(window.live, "treeview_stats")),
|
|
|
|
match);
|
2005-03-11 13:17:48 +01:00
|
|
|
}
|
|
|
|
|
2005-05-18 18:00:49 +02:00
|
|
|
lg_commentary_generate(unit, match->fix);
|
2005-05-19 10:31:47 +02:00
|
|
|
|
|
|
|
unit->event.verbosity = live_game_event_get_verbosity(unit->event.type);
|
2005-03-11 13:17:48 +01:00
|
|
|
}
|
|
|
|
|
2005-03-09 15:02:49 +01:00
|
|
|
if(show)
|
|
|
|
game_gui_live_game_show_unit(unit);
|
2005-04-13 15:01:59 +02:00
|
|
|
|
|
|
|
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,
|
2005-05-19 20:13:14 +02:00
|
|
|
unit->event.type, unit->possession, unit->event.team,
|
|
|
|
unit->event.player,
|
|
|
|
unit->event.player2);
|
2005-03-09 15:02:49 +01:00
|
|
|
}
|
|
|
|
|
2005-01-24 19:01:55 +01:00
|
|
|
/** Find a random player (influenced by fitness) who gets
|
|
|
|
injured. */
|
|
|
|
void
|
2005-03-08 09:25:46 +01:00
|
|
|
live_game_injury_get_player(void)
|
2005-01-24 19:01:55 +01:00
|
|
|
{
|
|
|
|
gint i, j;
|
|
|
|
gfloat probs[22];
|
2005-03-09 14:10:28 +01:00
|
|
|
gfloat rndom, fitness_factor;
|
|
|
|
gfloat goalie_factor =
|
|
|
|
const_float("float_live_game_injury_goalie_factor");
|
|
|
|
gfloat boost_factor =
|
|
|
|
const_float("float_player_boost_injury_effect");
|
2005-01-24 19:01:55 +01:00
|
|
|
|
|
|
|
for(j=0;j<2;j++)
|
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
fitness_factor = (player_of_idx_team(tm[j], 0)->fitness < 0.025) ?
|
|
|
|
40 : 1 / player_of_idx_team(tm[j], 0)->fitness;
|
2005-03-09 14:10:28 +01:00
|
|
|
probs[j * 11] = goalie_factor * fitness_factor *
|
2005-04-13 15:01:59 +02:00
|
|
|
(player_of_idx_team(tm[j], 0)->cskill != 0) * (1 + tm[j]->boost * boost_factor);
|
2005-03-08 09:25:46 +01:00
|
|
|
if(j == 1)
|
|
|
|
probs[11] += probs[10];
|
|
|
|
|
2005-01-24 19:01:55 +01:00
|
|
|
for(i=1;i<11;i++)
|
2005-03-09 14:10:28 +01:00
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
fitness_factor = (player_of_idx_team(tm[j], i)->fitness < 0.025) ?
|
|
|
|
40 : 1 / ((gfloat)player_of_idx_team(tm[j], i)->fitness);
|
2005-03-09 14:10:28 +01:00
|
|
|
probs[i + j * 11] = probs[i + j * 11 - 1] + (1 - goalie_factor) * fitness_factor *
|
2005-04-13 15:01:59 +02:00
|
|
|
(player_of_idx_team(tm[j], i)->cskill != 0) * (1 + tm[j]->boost * boost_factor);
|
2005-03-09 14:10:28 +01:00
|
|
|
}
|
2005-01-24 19:01:55 +01:00
|
|
|
}
|
2005-03-08 09:25:46 +01:00
|
|
|
|
2005-01-24 19:01:55 +01:00
|
|
|
rndom = math_rnd(0, probs[21]);
|
|
|
|
|
|
|
|
if(rndom < probs[0])
|
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-04-13 15:01:59 +02:00
|
|
|
player_of_idx_team(tm0, 0)->id;
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.team = 0;
|
2005-01-24 19:01:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
for(i=1;i<22;i++)
|
|
|
|
if(probs[i - 1] <= rndom && rndom < probs[i])
|
|
|
|
{
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.player =
|
2005-04-13 15:01:59 +02:00
|
|
|
player_of_idx_team(tm[(i > 10)], i % 11)->id;
|
2005-05-19 20:13:14 +02:00
|
|
|
last_unit.event.team = (i > 10);
|
2005-01-24 19:01:55 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-08 09:25:46 +01:00
|
|
|
|
|
|
|
/** Resume a live game. Show team changes. */
|
|
|
|
void
|
|
|
|
live_game_resume(void)
|
|
|
|
{
|
|
|
|
gint i, j;
|
|
|
|
gint subs_in[3],
|
|
|
|
subs_out[3];
|
|
|
|
|
|
|
|
match = &usr(stat2).live_game;
|
|
|
|
|
|
|
|
for(i=0;i<2;i++)
|
|
|
|
{
|
|
|
|
game_get_subs(i, subs_in, subs_out);
|
|
|
|
for(j=0;j<3;j++)
|
|
|
|
{
|
|
|
|
if(subs_in[j] != -1)
|
|
|
|
{
|
|
|
|
usr(stat2).live_game.subs_left[i]--;
|
|
|
|
live_game_event_substitution(i, subs_in[j], subs_out[j]);
|
2005-03-13 16:46:15 +01:00
|
|
|
}
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(tm[i]->structure != usr(stat2).live_game.team_state[i].structure)
|
|
|
|
live_game_event_team_change(i, LIVE_GAME_EVENT_STRUCTURE_CHANGE);
|
|
|
|
|
|
|
|
if(tm[i]->style != usr(stat2).live_game.team_state[i].style)
|
2005-03-10 21:59:39 +01:00
|
|
|
live_game_event_team_change(i, LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND +
|
|
|
|
tm[i]->style + 2);
|
2005-03-08 09:25:46 +01:00
|
|
|
|
|
|
|
if(tm[i]->boost != usr(stat2).live_game.team_state[i].boost)
|
2005-03-10 21:59:39 +01:00
|
|
|
live_game_event_team_change(i, LIVE_GAME_EVENT_BOOST_CHANGE_ANTI +
|
|
|
|
tm[i]->boost + 1);
|
2005-03-08 09:25:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
live_game_calculate_fixture(usr(stat2).live_game.fix);
|
|
|
|
}
|
|
|
|
|
2005-03-11 18:18:51 +01:00
|
|
|
|
|
|
|
/** Set the match variable to the live game.
|
|
|
|
@param live_game The live game 'match' will point to. */
|
|
|
|
void
|
|
|
|
live_game_set_match(LiveGame *live_game)
|
|
|
|
{
|
|
|
|
match = live_game;
|
|
|
|
}
|
2005-04-04 12:36:04 +02:00
|
|
|
|
|
|
|
/** Reset the live game variable before we begin a new live game.
|
|
|
|
@param live_game The pointer to the live game.
|
|
|
|
@param fix The fixture we'll show.
|
|
|
|
@param free Whether or not to free the variable before resetting. */
|
|
|
|
void
|
|
|
|
live_game_reset(LiveGame *live_game, Fixture *fix, gboolean free_variable)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if(free_variable)
|
|
|
|
free_live_game(live_game);
|
|
|
|
|
|
|
|
live_game->units = g_array_new(FALSE, FALSE, sizeof(LiveGameUnit));
|
|
|
|
|
|
|
|
for(i=0;i<LIVE_GAME_STAT_ARRAY_END;i++)
|
|
|
|
{
|
|
|
|
live_game->stats.players[0][i] = g_ptr_array_new();
|
|
|
|
live_game->stats.players[1][i] = g_ptr_array_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<LIVE_GAME_STAT_VALUE_END;i++)
|
|
|
|
live_game->stats.values[0][i] =
|
|
|
|
live_game->stats.values[1][i] = 0;
|
|
|
|
|
|
|
|
live_game->fix = fix;
|
2005-05-31 16:42:20 +02:00
|
|
|
live_game->fix_id = (fix != NULL) ? fix->id : -1;
|
2005-04-09 21:18:28 +02:00
|
|
|
|
2005-04-04 12:36:04 +02:00
|
|
|
live_game->subs_left[0] = live_game->subs_left[1] = 3;
|
|
|
|
live_game->stadium_event = -1;
|
|
|
|
|
|
|
|
if(fix != NULL && fix->home_advantage)
|
|
|
|
live_game->home_advantage =
|
|
|
|
math_rnd(const_float("float_game_home_advantage_lower"),
|
|
|
|
const_float("float_game_home_advantage_upper"));
|
|
|
|
else
|
|
|
|
live_game->home_advantage = 0;
|
|
|
|
}
|
2005-05-19 10:31:47 +02:00
|
|
|
|
|
|
|
/** Determine verbosity level depending on the event type. */
|
|
|
|
gint
|
|
|
|
live_game_event_get_verbosity(gint event_type)
|
|
|
|
{
|
2005-06-17 14:57:05 +02:00
|
|
|
gint return_value = -1;
|
2005-05-19 10:31:47 +02:00
|
|
|
|
|
|
|
if(event_type == LIVE_GAME_EVENT_START_MATCH ||
|
|
|
|
event_type == LIVE_GAME_EVENT_HALF_TIME ||
|
|
|
|
event_type == LIVE_GAME_EVENT_EXTRA_TIME ||
|
|
|
|
event_type == LIVE_GAME_EVENT_END_MATCH ||
|
|
|
|
event_type == LIVE_GAME_EVENT_PENALTIES ||
|
|
|
|
event_type == LIVE_GAME_EVENT_GOAL ||
|
|
|
|
event_type == LIVE_GAME_EVENT_OWN_GOAL)
|
|
|
|
return_value = 0;
|
|
|
|
else if(event_type == LIVE_GAME_EVENT_PENALTY ||
|
|
|
|
event_type == LIVE_GAME_EVENT_SCORING_CHANCE ||
|
|
|
|
event_type == LIVE_GAME_EVENT_HEADER ||
|
|
|
|
event_type == LIVE_GAME_EVENT_FREE_KICK ||
|
|
|
|
event_type == LIVE_GAME_EVENT_POST ||
|
2005-06-26 13:42:01 +02:00
|
|
|
event_type == LIVE_GAME_EVENT_MISS ||
|
2005-05-19 10:31:47 +02:00
|
|
|
event_type == LIVE_GAME_EVENT_CROSS_BAR ||
|
|
|
|
event_type == LIVE_GAME_EVENT_SAVE)
|
|
|
|
return_value = 1;
|
|
|
|
else if(event_type == LIVE_GAME_EVENT_SEND_OFF ||
|
|
|
|
event_type == LIVE_GAME_EVENT_INJURY)
|
|
|
|
return_value = 2;
|
|
|
|
else if(event_type == LIVE_GAME_EVENT_FOUL_RED ||
|
|
|
|
event_type == LIVE_GAME_EVENT_FOUL_YELLOW ||
|
|
|
|
event_type == LIVE_GAME_EVENT_FOUL_RED_INJURY)
|
|
|
|
return_value = 3;
|
|
|
|
else if(event_type == LIVE_GAME_EVENT_FOUL ||
|
|
|
|
event_type == LIVE_GAME_EVENT_TEMP_INJURY ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STADIUM_RIOTS ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STADIUM_BREAKDOWN ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STADIUM_FIRE ||
|
|
|
|
event_type == LIVE_GAME_EVENT_LOST_POSSESSION)
|
|
|
|
return_value = 4;
|
|
|
|
else if(event_type == LIVE_GAME_EVENT_SUBSTITUTION ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STRUCTURE_CHANGE ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_DEFEND ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_BALANCED ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ATTACK ||
|
|
|
|
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_ATTACK ||
|
|
|
|
event_type == LIVE_GAME_EVENT_BOOST_CHANGE_ANTI ||
|
|
|
|
event_type == LIVE_GAME_EVENT_BOOST_CHANGE_OFF ||
|
|
|
|
event_type == LIVE_GAME_EVENT_BOOST_CHANGE_ON)
|
|
|
|
return_value = 5;
|
|
|
|
else if(event_type == LIVE_GAME_EVENT_GENERAL)
|
|
|
|
return_value = 6;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning("live_game_event_get_verbosity: unknown event type %d \n",
|
|
|
|
event_type);
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_INT_NOT_FOUND, NULL);
|
2005-05-19 10:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|