1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2024-12-30 00:41:07 +01:00
bygfoot/src/live_game.c

1495 lines
50 KiB
C
Raw Normal View History

#include "enums.h"
2005-01-09 21:21:22 +01:00
#include "fixture.h"
#include "free.h"
2005-01-24 19:01:55 +01:00
#include "game_gui.h"
2005-01-09 21:21:22 +01:00
#include "live_game.h"
#include "maths.h"
#include "misc_callback_func.h"
#include "option.h"
2005-01-09 21:21:22 +01:00
#include "player.h"
#include "table.h"
2005-01-09 21:21:22 +01:00
#include "team.h"
#include "treeview.h"
#include "user.h"
2005-01-09 21:21:22 +01:00
#include "variables.h"
#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. */
#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-08 09:25:46 +01:00
live_game_reset(fix);
2005-03-09 14:10:28 +01:00
game_initialize(fix);
}
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
do
{
live_game_create_unit();
2005-01-09 21:21:22 +01:00
live_game_evaluate_unit(&last_unit);
}
while(last_unit.event.type != LIVE_GAME_EVENT_END_MATCH &&
stat0 != STATUS_LIVE_GAME_PAUSE);
2005-01-09 21:21:22 +01:00
if(stat0 != STATUS_LIVE_GAME_PAUSE)
{
2005-01-09 21:21:22 +01:00
live_game_create_stats();
2005-03-08 09:25:46 +01:00
if(query_fixture_has_tables(fix))
table_update(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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_create_unit\n");
if(unis->len == 0)
2005-01-09 21:21:22 +01:00
{
live_game_create_start_unit();
return;
}
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);
new.event.commentary = g_string_new("dummy commentary");
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
2005-01-24 19:01:55 +01:00
new.area = last_unit.area;
new.result[0] = last_unit.result[0];
new.result[1] = last_unit.result[1];
2005-01-09 21:21:22 +01:00
if(query_live_game_event_is_break(new.minute, new.time))
{
new.event.type = live_game_get_break();
new.possession = last_unit.possession;
g_array_append_val(unis, new);
2005-01-09 21:21:22 +01:00
return;
}
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);
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 =
1 - powf((gfloat)tm0->stadium.safety / 100,
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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_fill_new_unit\n");
2005-03-09 14:10:28 +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") *
(tm[0]->boost != 0 || tm[1]->boost != 0)));
foul_event_prob = const_float("float_live_game_foul") *
(1 + (tm[0]->boost + tm[1]->boost) * const_float("float_team_boost_foul_factor"));
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)
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-01-09 21:21:22 +01:00
stadium_event && !match->stadium_event)
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-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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_create_start_unit\n");
2005-01-09 21:21:22 +01:00
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
/*d*/
new.event.commentary = g_string_new("Match's started.");
new.minute = 1;
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;
new.result[0] = new.result[1] = 0;
2005-01-09 21:21:22 +01:00
new.event.type = LIVE_GAME_EVENT_START_MATCH;
new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = new.possession;
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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_evaluate_unit type %d\n", type);
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);
else if(type == LIVE_GAME_EVENT_START_MATCH)
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_unit);
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-08 09:25:46 +01:00
live_game_generate_commentary(&last_unit);
if(type != LIVE_GAME_EVENT_END_MATCH && show &&
option_int("int_opt_user_pause_break", usr(fixture_user_team_involved(match->fix)).options))
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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_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))
{
foul_team = last_unit.event.values[LIVE_GAME_EVENT_VALUE_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];
else
fouled_player = last_unit.event.values[LIVE_GAME_EVENT_VALUE_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] =
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
{
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] =
game_get_player(tm[!last_unit.possession],
2005-01-24 19:01:55 +01:00
last_unit.area, 0, -1, FALSE);
2005-03-09 14:10:28 +01:00
foul_player = last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
game_get_player(tm[last_unit.possession],
last_unit.area, 0, -1, FALSE);
}
2005-01-09 21:21:22 +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;
else if(rndom < const_float("float_live_game_foul_red"))
2005-01-09 21:21:22 +01:00
type = LIVE_GAME_EVENT_FOUL_RED;
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-08 09:25:46 +01:00
live_game_generate_commentary(&last_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)
game_player_card(match->fix->clid, player_of_id(tm[foul_team], foul_player),
FALSE, FALSE);
2005-01-09 21:21:22 +01:00
2005-03-09 14:10:28 +01:00
if(last_unit.area == LIVE_GAME_UNIT_AREA_ATTACK && foul_team ==
last_unit.possession)
2005-01-24 19:01:55 +01:00
{
rndom = math_rnd(0, 1);
if(rndom < const_float("float_live_game_penalty_prob"))
2005-01-24 19:01:55 +01:00
live_game_event_penalty();
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-03-09 14:10:28 +01:00
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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_event_lost_possession\n");
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
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
if(uni(unis->len - 2).event.type == LIVE_GAME_EVENT_GENERAL)
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
2005-01-09 21:21:22 +01:00
else
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
game_get_player(tm[!last_unit.possession],
uni(unis->len - 2).area, 0, -1, FALSE);
2005-01-24 19:01:55 +01:00
2005-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("## pls %d %d\n",
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER],
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]);
2005-01-09 21:21:22 +01:00
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_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-01-09 21:21:22 +01:00
new.event.commentary = g_string_new("injury");
g_array_append_val(unis, new);
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
player;
last_unit.event.values[LIVE_GAME_EVENT_VALUE_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
if(math_rnd(0, 1) < const_float("float_live_game_injury_is_temp"))
2005-01-09 21:21:22 +01:00
last_unit.event.type = LIVE_GAME_EVENT_TEMP_INJURY;
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_unit);
2005-01-09 21:21:22 +01:00
2005-03-08 09:25:46 +01:00
if(last_unit.event.type == LIVE_GAME_EVENT_INJURY)
{
2005-03-09 14:10:28 +01:00
game_player_injury(player_of_id(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER]));
if(match->subs_left[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]] > 0)
2005-03-08 09:25:46 +01:00
{
2005-03-09 14:10:28 +01:00
if(show &&
team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]) != -1 &&
option_int("int_opt_user_pause_injury",
usr(team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]])).options) &&
!option_int("int_opt_user_auto_sub",
usr(team_is_user(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]])).options))
misc_callback_pause_live_game();
else if(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->players->len > 11)
{
old_structure = tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->structure;
live_game_event_substitution(
last_unit.event.values[LIVE_GAME_EVENT_VALUE_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]);
match->subs_left[last_unit.event.values[LIVE_GAME_EVENT_VALUE_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],
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)
{
gfloat rndom = math_rnd(0, 1);
2005-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_event_stadium\n");
if(rndom < const_float("float_live_game_stadium_event_fire"))
2005-01-09 21:21:22 +01:00
last_unit.event.type = LIVE_GAME_EVENT_STADIUM_FIRE;
else if(rndom < const_float("float_live_game_stadium_event_riots"))
2005-01-09 21:21:22 +01:00
last_unit.event.type = LIVE_GAME_EVENT_STADIUM_RIOTS;
else if(rndom < const_float("float_live_game_stadium_event_breakdown"))
2005-01-09 21:21:22 +01:00
last_unit.event.type = LIVE_GAME_EVENT_STADIUM_BREAKDOWN;
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_unit);
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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_event_scoring_chance\n");
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;
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
2005-01-24 19:01:55 +01:00
game_get_player(tm[!last_unit.possession], last_unit.area, 0, -1, FALSE);
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
{
if(uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1 &&
math_rnd(0, 1) < const_float("float_live_game_player_in_poss_shoots"))
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
2005-01-09 21:21:22 +01:00
else
{
if(uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1)
2005-01-09 21:21:22 +01:00
{
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
2005-01-24 19:01:55 +01:00
game_get_player(tm[last_unit.possession], last_unit.area, 0,
uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER],
2005-01-24 19:01:55 +01:00
TRUE);
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
2005-01-09 21:21:22 +01:00
}
else
{
last_unit.event.values[LIVE_GAME_EVENT_VALUE_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
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
2005-01-24 19:01:55 +01:00
game_get_player(tm[last_unit.possession], last_unit.area, 0,
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER], TRUE);
2005-01-09 21:21:22 +01:00
}
}
}
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_unit);
2005-01-09 21:21:22 +01:00
live_game_event_duel();
}
/** Calculate a penalty event. */
void
live_game_event_penalty(void)
{
LiveGameUnit new;
2005-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_event_penalty\n");
2005-01-09 21:21:22 +01:00
if(last_unit.time != LIVE_GAME_UNIT_TIME_PENALTIES)
{
new = last_unit;
new.minute = -1;
new.event.type = LIVE_GAME_EVENT_PENALTY;
new.event.commentary = g_string_new("penalty");
g_array_append_val(unis, new);
}
2005-01-09 21:21:22 +01:00
if(last_unit.time == LIVE_GAME_UNIT_TIME_PENALTIES)
{
if(uni(unis->len - 2).event.type == LIVE_GAME_EVENT_PENALTIES)
2005-01-09 21:21:22 +01:00
{
last_unit.possession = math_rndi(0, 1);
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
game_get_player(tm[last_unit.possession],
GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE);
2005-01-09 21:21:22 +01:00
}
else if(uni(unis->len - 4).event.type == LIVE_GAME_EVENT_PENALTIES)
2005-01-09 21:21:22 +01:00
{
last_unit.possession = !uni(unis->len - 3).possession;
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
game_get_player(tm[last_unit.possession],
GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE);
2005-01-09 21:21:22 +01:00
}
else
{
last_unit.possession = !uni(unis->len - 3).possession;
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
game_get_player(tm[last_unit.possession],
2005-01-09 21:21:22 +01:00
GAME_PLAYER_TYPE_PENALTY,
uni(unis->len - 4).event.values[LIVE_GAME_EVENT_VALUE_PLAYER], -1, FALSE);
2005-01-09 21:21:22 +01:00
}
}
else
{
last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] =
last_unit.possession;
if(team_is_user(tm[last_unit.possession]) != -1 &&
option_int("int_opt_user_penalty_shooter",
usr(team_is_user(tm[last_unit.possession])).options) != -1)
2005-01-09 21:21:22 +01:00
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
option_int("int_opt_user_penalty_shooter",
usr(team_is_user(tm[last_unit.possession])).options);
2005-01-09 21:21:22 +01:00
else
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_PENALTY, -1, -1, FALSE);
2005-01-09 21:21:22 +01:00
}
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_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;
new.event.type = LIVE_GAME_EVENT_GENERAL;
new.event.commentary = g_string_new("general");
new.result[0] = last_unit.result[0];
new.result[1] = last_unit.result[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) &&
math_rnd(0, 1) < const_float("float_live_game_possession_after_post")))
2005-01-09 21:21:22 +01:00
{
2005-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("##### last type: %d\n", last_unit.event.type);
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 ||
last_unit.event.type == LIVE_GAME_EVENT_MISSED ||
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
g_warning("live_game_event_general: unknown event type: %d\n",
last_unit.event.type);
2005-01-09 21:21:22 +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-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("+++ general %d %d\n",
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER],
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]);
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_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)
{
gint *pl1 = &last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
gint *pl2 = &last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2];
gint old_pl1 =
2005-03-08 09:25:46 +01:00
uni(unis->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
gint type = uni(unis->len - 2).event.type;
2005-01-24 19:01:55 +01:00
2005-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_event_general_get_players\n");
*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);
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-01-24 19:01:55 +01:00
*pl2 = old_pl1;
*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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_event_free_kick\n");
2005-01-09 21:21:22 +01:00
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
new.minute = -1;
new.event.type = LIVE_GAME_EVENT_FREE_KICK;
new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] =
new.possession;
new.event.commentary = g_string_new("freekick");
if(team_is_user(tm[new.possession]) != -1 &&
option_int("int_opt_user_penalty_shooter",
usr(team_is_user(tm[last_unit.possession])).options) != -1)
2005-01-09 21:21:22 +01:00
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
option_int("int_opt_user_penalty_shooter",
usr(team_is_user(tm[last_unit.possession])).options);
2005-01-09 21:21:22 +01:00
else
new.event.values[LIVE_GAME_EVENT_VALUE_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
g_array_append_val(unis, new);
2005-01-09 21:21:22 +01:00
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_event_send_off\n");
2005-01-09 21:21:22 +01:00
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
new.minute = -1;
new.event.type = LIVE_GAME_EVENT_SEND_OFF;
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = player;
2005-01-24 19:01:55 +01:00
new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = team;
2005-01-09 21:21:22 +01:00
new.event.commentary = g_string_new("send off");
g_array_append_val(unis, new);
2005-01-09 21:21:22 +01:00
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_unit);
2005-03-09 14:10:28 +01:00
game_player_card(match->fix->clid, player_of_id(tm[team], player), TRUE, second_yellow);
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 &&
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))
misc_callback_pause_live_game();
else if(tm[team]->players->len > 11)
{
game_substitute_player_send_off(tm[team], player_id_index(tm[team], player),
&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-03-09 14:10:28 +01:00
else
{
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);
new.event.commentary = g_string_new("dummy commentary");
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;
2005-03-09 14:10:28 +01:00
if(player_of_id(tm[team_number], sub_in)->cskill > 0)
game_player_increase(match->fix->clid, player_of_id(tm[team_number], sub_in),
GAME_PLAYER_INCREASE_GAMES);
2005-03-08 09:25:46 +01:00
g_array_append_val(unis, new);
live_game_generate_commentary(&last_unit);
}
/** 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);
new.event.commentary = g_string_new("dummy commentary");
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.type = event_type;
g_array_append_val(unis, new);
live_game_generate_commentary(&last_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-03-08 09:25:46 +01:00
if(opt_int("int_opt_debug"))
2005-01-24 19:01:55 +01:00
printf("live_game_event_duel\n");
2005-01-09 21:21:22 +01:00
new.minute = -1;
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
2005-01-09 21:21:22 +01:00
new.event.commentary = g_string_new("duel");
2005-03-08 09:25:46 +01:00
attacker = player_of_id(tm[new.possession],
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER]);
2005-01-09 21:21:22 +01:00
goalie = player_of(tm[!new.possession], 0);
2005-03-08 09:25:46 +01:00
duel_factor = (((gfloat)attacker->cskill * powf((gfloat)attacker->fitness / 10000,
const_float("float_player_fitness_exponent"))) /
2005-03-08 09:25:46 +01:00
((gfloat)goalie->cskill * powf((gfloat)goalie->fitness / 10000,
const_float("float_player_fitness_exponent"))));
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)
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)
scoring_prob = const_float("float_live_game_score_free_kick") * duel_factor;
2005-01-09 21:21:22 +01:00
else
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] /
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-03-09 14:10:28 +01:00
game_player_increase(match->fix->clid, attacker, GAME_PLAYER_INCREASE_SHOTS);
game_player_increase(match->fix->clid, goalie, GAME_PLAYER_INCREASE_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]++;
new.result[res_idx1]++;
2005-03-08 09:25:46 +01:00
if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES)
{
2005-03-09 14:10:28 +01:00
game_player_increase(match->fix->clid, attacker, GAME_PLAYER_INCREASE_GOALS);
game_player_increase(match->fix->clid, goalie, GAME_PLAYER_INCREASE_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);
g_array_append_val(unis, new);
2005-01-09 21:21:22 +01:00
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(&last_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;
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 &&
uni(i).event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] == player)
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;
if(fixture_user_team_involved(match->fix) != -1 && opt_int("int_opt_debug"))
printf("## time %d min %d\n", time, minute);
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 >
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 >
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};
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)
pen_attempted[uni(i).possession]++;
2005-01-09 21:21:22 +01:00
}
else
break;
if(pen_attempted[0] + pen_attempted[1] >= 10)
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;
}
/** 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;
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;
for(i=unis->len - 1; i >= 0; i--)
2005-01-09 21:21:22 +01:00
if(&uni(i) == unit)
break;
if(i == -1)
g_warning("live_game_unit_get_minute: reached end of unis array.\n");
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;
}
/** Free the live game variable before we begin a new live game.
@param fix The fixture we'll show. */
void
live_game_reset(Fixture *fix)
{
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);
if(show && window.live == NULL)
window.live = window_create(WINDOW_LIVE);
2005-01-09 21:21:22 +01:00
free_live_game(match);
unis = g_array_new(FALSE, FALSE, sizeof(LiveGameUnit));
2005-01-09 21:21:22 +01:00
match->fix = fix;
match->subs_left[0] = match->subs_left[1] = 3;
match->stadium_event = FALSE;
if(fix->home_advantage)
match->home_advantage =
math_rnd(const_float("float_game_home_advantage_lower"),
const_float("float_game_home_advantage_upper"));
2005-01-09 21:21:22 +01:00
}
/** Generate commentary for the live game event in the unit
and show the unit in the live game window.
2005-01-09 21:21:22 +01:00
@param unit The unit we comment. */
void
2005-03-08 09:25:46 +01:00
live_game_generate_commentary(LiveGameUnit *unit)
2005-01-09 21:21:22 +01:00
{
GString *commentary = unit->event.commentary;
switch(unit->event.type)
{
2005-03-08 09:25:46 +01:00
default:
g_warning("live_game_generate_commentary: unknown event type %d\n",
unit->event.type);
break;
2005-01-24 19:01:55 +01:00
case LIVE_GAME_EVENT_GENERAL:
2005-01-09 21:21:22 +01:00
if(unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1 &&
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] != -1)
g_string_printf(commentary, "general, %s passes to %s",
player_of_id(tm[unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])->name->str,
player_of_id(tm[unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
else if(unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1)
g_string_printf(commentary, "%s has the ball.",
player_of_id(tm[unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
else
g_string_printf(commentary, "match's getting boring");
break;
case LIVE_GAME_EVENT_START_MATCH:
g_string_printf(commentary, "Match started.");
break;
case LIVE_GAME_EVENT_HALF_TIME:
g_string_printf(commentary, "Half time.");
break;
case LIVE_GAME_EVENT_EXTRA_TIME:
g_string_printf(commentary, "Extra time.");
break;
case LIVE_GAME_EVENT_END_MATCH:
g_string_printf(commentary, "Match is over!");
break;
case LIVE_GAME_EVENT_LOST_POSSESSION:
g_string_printf(commentary, "%s loses ball to %s.",
player_of_id(tm[!unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])->name->str,
player_of_id(tm[unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_SCORING_CHANCE:
g_string_printf(commentary, "scoring chance by %s",
player_of_id(tm[unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_PENALTY:
g_string_printf(commentary, "%s shoots penalty",
player_of_id(tm[unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_FREE_KICK:
g_string_printf(commentary, "%s shoots free kick",
player_of_id(tm[unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_GOAL:
g_string_printf(commentary, "Goal!");
break;
case LIVE_GAME_EVENT_OWN_GOAL:
g_string_printf(commentary, "Oh no! %s scored an own goal!",
player_of_id(tm[!unit->possession],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_MISSED:
g_string_printf(commentary, "Missed!");
break;
case LIVE_GAME_EVENT_SAVE:
g_string_printf(commentary, "Save!");
break;
case LIVE_GAME_EVENT_POST:
g_string_printf(commentary, "Post!");
break;
case LIVE_GAME_EVENT_CROSS_BAR:
g_string_printf(commentary, "Cross bar!");
break;
case LIVE_GAME_EVENT_FOUL:
g_string_printf(commentary, "%s fouls %s.",
2005-03-09 14:10:28 +01:00
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])->name->str,
2005-03-09 14:10:28 +01:00
player_of_id(tm[!unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_FOUL_RED:
g_string_printf(commentary, "%s fouls %s; he gets a red card!",
2005-03-09 14:10:28 +01:00
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])->name->str,
2005-03-09 14:10:28 +01:00
player_of_id(tm[!unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_FOUL_RED_INJURY:
g_string_printf(commentary, "%s fouls %s; he gets a red card and %s is injured!",
2005-03-09 14:10:28 +01:00
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])->name->str,
2005-03-09 14:10:28 +01:00
player_of_id(tm[!unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str,
2005-03-09 14:10:28 +01:00
player_of_id(tm[!unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_FOUL_YELLOW:
g_string_printf(commentary, "%s fouls %s; he gets a yellow card.",
2005-03-09 14:10:28 +01:00
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])->name->str,
2005-03-09 14:10:28 +01:00
player_of_id(tm[!unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_SEND_OFF:
g_string_printf(commentary, "%s is sent off.",
2005-03-09 14:10:28 +01:00
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_INJURY:
g_string_printf(commentary, "%s is injured.",
2005-03-08 09:25:46 +01:00
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_TEMP_INJURY:
g_string_printf(commentary, "%s is injured but he can continue to play.",
2005-03-08 09:25:46 +01:00
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
2005-01-09 21:21:22 +01:00
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str);
break;
case LIVE_GAME_EVENT_PENALTIES:
g_string_printf(commentary, "Penalty shoot-out!");
break;
case LIVE_GAME_EVENT_STADIUM_BREAKDOWN:
g_string_printf(commentary, "There's a breakdown in the stadium");
break;
case LIVE_GAME_EVENT_STADIUM_FIRE:
g_string_printf(commentary, "There's a fire in the stadium.");
break;
case LIVE_GAME_EVENT_STADIUM_RIOTS:
g_string_printf(commentary, "There are riots in the stadium.");
break;
2005-03-08 09:25:46 +01:00
case LIVE_GAME_EVENT_SUBSTITUTION:
g_string_printf(commentary, "%s substitutes %s for %s.",
tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->name->str,
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER])->name->str,
player_of_id(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
unit->event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])->name->str);
break;
case LIVE_GAME_EVENT_STRUCTURE_CHANGE:
g_string_printf(commentary, "%s changes structure to %d.",
tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->name->str,
tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->structure);
break;
case LIVE_GAME_EVENT_STYLE_CHANGE:
g_string_printf(commentary, "%s changes style to %s.",
tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->name->str,
team_style_to_char(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->style));
break;
case LIVE_GAME_EVENT_BOOST_CHANGE:
2005-03-09 14:10:28 +01:00
if(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->boost == 1)
2005-03-08 09:25:46 +01:00
g_string_printf(commentary, "%s changes boost to ON.",
tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->name->str);
2005-03-09 14:10:28 +01:00
else if(tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->boost == 0)
g_string_printf(commentary, "%s changes (anti-)boost to OFF.",
2005-03-08 09:25:46 +01:00
tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->name->str);
2005-03-09 14:10:28 +01:00
else
g_string_printf(commentary, "%s changes anti-boost to ON.",
tm[unit->event.values[LIVE_GAME_EVENT_VALUE_TEAM]]->name->str);
2005-01-09 21:21:22 +01:00
}
2005-03-08 09:25:46 +01:00
if(show)
game_gui_live_game_show_unit(unit);
2005-01-09 21:21:22 +01:00
}
/** Assemble some stats like ball possession or shots
on goal. @see #LiveGameStats */
void
live_game_create_stats(void)
{
gint i, possession[2] = {0, 0};
LiveGameStats *stat = &match->stats;
for(i=0;i<LIVE_GAME_STAT_VALUE_END;i++)
stat->values[0][i] =
stat->values[1][i] = 0;
2005-01-09 21:21:22 +01:00
stat->values[0][LIVE_GAME_STAT_VALUE_GOALS] =
math_sum_int_array(match->fix->result[0], 2);
stat->values[1][LIVE_GAME_STAT_VALUE_GOALS] =
math_sum_int_array(match->fix->result[1], 2);
for(i=0;i<unis->len;i++)
2005-01-09 21:21:22 +01:00
{
if(uni(i).minute != -1)
possession[uni(i).possession]++;
if(uni(i).event.type == LIVE_GAME_EVENT_SCORING_CHANCE ||
uni(i).event.type == LIVE_GAME_EVENT_FREE_KICK)
stat->values[uni(i).possession][LIVE_GAME_STAT_VALUE_SHOTS]++;
else if(uni(i).event.type == LIVE_GAME_EVENT_PENALTY &&
uni(i).time != LIVE_GAME_UNIT_TIME_PENALTIES)
stat->values[uni(i).possession][LIVE_GAME_STAT_VALUE_PENALTIES]++;
else if(uni(i).event.type == LIVE_GAME_EVENT_INJURY ||
uni(i).event.type == LIVE_GAME_EVENT_TEMP_INJURY)
stat->values[uni(i).possession][LIVE_GAME_STAT_VALUE_INJURIES]++;
else if(uni(i).event.type == LIVE_GAME_EVENT_FOUL ||
uni(i).event.type == LIVE_GAME_EVENT_FOUL_YELLOW ||
uni(i).event.type == LIVE_GAME_EVENT_FOUL_RED ||
uni(i).event.type == LIVE_GAME_EVENT_FOUL_RED_INJURY)
{
stat->values[!uni(i).possession][LIVE_GAME_STAT_VALUE_FOULS]++;
if(uni(i).event.type == LIVE_GAME_EVENT_FOUL_YELLOW)
stat->values[!uni(i).possession][LIVE_GAME_STAT_VALUE_CARDS]++;
}
else if(uni(i).event.type == LIVE_GAME_EVENT_SEND_OFF)
stat->values[!uni(i).possession][LIVE_GAME_STAT_VALUE_REDS]++;
}
stat->values[0][LIVE_GAME_STAT_VALUE_POSSESSION] =
(gint)rint((gfloat)possession[0] / (gfloat)(possession[0] + possession[1]) * 100);
stat->values[1][LIVE_GAME_STAT_VALUE_POSSESSION] =
100 - stat->values[0][LIVE_GAME_STAT_VALUE_POSSESSION];
/*d*/
/* printf("goals\t %d \t %d\n", stat->values[0][LIVE_GAME_STAT_VALUE_GOALS], */
/* stat->values[1][LIVE_GAME_STAT_VALUE_GOALS]); */
/* printf("shots\t %d \t %d\n", stat->values[0][LIVE_GAME_STAT_VALUE_SHOTS], */
/* stat->values[1][LIVE_GAME_STAT_VALUE_SHOTS]); */
/* printf("poss\t %d%% \t %d%%\n", stat->values[0][LIVE_GAME_STAT_VALUE_POSSESSION], */
/* stat->values[1][LIVE_GAME_STAT_VALUE_POSSESSION]); */
/* printf("pen.\t %d \t %d\n", stat->values[0][LIVE_GAME_STAT_VALUE_PENALTIES], */
/* stat->values[1][LIVE_GAME_STAT_VALUE_PENALTIES]); */
/* printf("fouls\t %d \t %d\n", stat->values[0][LIVE_GAME_STAT_VALUE_FOULS], */
/* stat->values[1][LIVE_GAME_STAT_VALUE_FOULS]); */
/* printf("cards\t %d \t %d\n", stat->values[0][LIVE_GAME_STAT_VALUE_CARDS], */
/* stat->values[1][LIVE_GAME_STAT_VALUE_CARDS]); */
/* printf("reds\t %d \t %d\n", stat->values[0][LIVE_GAME_STAT_VALUE_REDS], */
/* stat->values[1][LIVE_GAME_STAT_VALUE_REDS]); */
/* printf("inj.\t %d \t %d\n", stat->values[0][LIVE_GAME_STAT_VALUE_INJURIES], */
/* stat->values[1][LIVE_GAME_STAT_VALUE_INJURIES]); */
2005-01-09 21:21:22 +01:00
}
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] =
{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;
}
/** 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-03-09 14:10:28 +01:00
fitness_factor = (player_of(tm[j], 0)->fitness < 0.025) ?
40 : 1 / ((gfloat)player_of(tm[j], 0)->fitness / 10000);
probs[j * 11] = goalie_factor * fitness_factor *
(player_of(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
{
fitness_factor = (player_of(tm[j], i)->fitness < 0.025) ?
40 : 1 / ((gfloat)player_of(tm[j], i)->fitness / 10000);
probs[i + j * 11] = probs[i + j * 11 - 1] + (1 - goalie_factor) * fitness_factor *
(player_of(tm[j], i)->cskill != 0) * (1 + tm[j]->boost * boost_factor);
}
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])
{
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
player_of(tm[0], 0)->id;
last_unit.event.values[LIVE_GAME_EVENT_VALUE_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] =
player_of(tm[(i > 10)], i % 11)->id;
last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = (i > 10);
}
}
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]);
}
}
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)
live_game_event_team_change(i, LIVE_GAME_EVENT_STYLE_CHANGE);
if(tm[i]->boost != usr(stat2).live_game.team_state[i].boost)
live_game_event_team_change(i, LIVE_GAME_EVENT_BOOST_CHANGE);
}
live_game_calculate_fixture(usr(stat2).live_game.fix);
}