mirror of https://github.com/tstellar/bygfoot.git
Live game changes.
This commit is contained in:
parent
e5e095480b
commit
343d720a56
94
src/game.c
94
src/game.c
|
@ -8,17 +8,14 @@
|
|||
/** Influence in % of the game style towards more attack.
|
||||
@see game_get_values() */
|
||||
#define CONSTANT_GAME_STYLE_FACTOR 0.075
|
||||
/** How much a defender's worth when the team's defending or attacking.
|
||||
|
||||
/** How the cskill of field players get weighted for the team values in
|
||||
a match. Rows are player position, columns value type.
|
||||
@see game_get_player_contribution() */
|
||||
#define CONSTANT_GAME_PLAYER_WEIGHT_DEFENDER_DEFEND 1
|
||||
#define CONSTANT_GAME_PLAYER_WEIGHT_DEFENDER_ATTACK 0.25
|
||||
/** How much a forward's worth when the team's defending or attacking.
|
||||
@see game_get_player_contribution() */
|
||||
#define CONSTANT_GAME_PLAYER_WEIGHT_FORWARD_DEFEND 0.2
|
||||
#define CONSTANT_GAME_PLAYER_WEIGHT_FORWARD_ATTACK 1.3
|
||||
/** How much a midfielder is worth both attacking and defending.
|
||||
@see game_get_player_contribution() */
|
||||
#define CONSTANT_GAME_PLAYER_WEIGHT_MIDFIELDER 0.625
|
||||
gfloat player_weights[3][3] =
|
||||
{{1, 0.4, 0.25},
|
||||
{0.625, 1, 0.625},
|
||||
{0.2, 0.6, 1.3}};
|
||||
|
||||
/** Calculate attacking, defending and goalie values for the two teams
|
||||
of a fixture.
|
||||
|
@ -35,6 +32,7 @@ game_get_values(const Fixture *fix, gfloat team_values[][GAME_TEAM_VALUE_END],
|
|||
Team *tm[2] = {fix->teams[0], fix->teams[1]};
|
||||
gfloat style_factor;
|
||||
|
||||
/*d*/
|
||||
printf("\nhome %.2f\n", home_advantage);
|
||||
for(i=0;i<2;i++)
|
||||
{
|
||||
|
@ -51,9 +49,11 @@ game_get_values(const Fixture *fix, gfloat team_values[][GAME_TEAM_VALUE_END],
|
|||
for(j=1;j<11;j++)
|
||||
{
|
||||
team_values[i][GAME_TEAM_VALUE_ATTACK] +=
|
||||
game_get_player_contribution(player_of(tm[i], j), TRUE);
|
||||
game_get_player_contribution(player_of(tm[i], j), GAME_TEAM_VALUE_ATTACK);
|
||||
team_values[i][GAME_TEAM_VALUE_MIDFIELD] +=
|
||||
game_get_player_contribution(player_of(tm[i], j), GAME_TEAM_VALUE_MIDFIELD);
|
||||
team_values[i][GAME_TEAM_VALUE_DEFEND] +=
|
||||
game_get_player_contribution(player_of(tm[i], j), FALSE);
|
||||
game_get_player_contribution(player_of(tm[i], j), GAME_TEAM_VALUE_DEFEND);
|
||||
}
|
||||
|
||||
team_values[i][GAME_TEAM_VALUE_ATTACK] *=
|
||||
|
@ -63,28 +63,26 @@ game_get_values(const Fixture *fix, gfloat team_values[][GAME_TEAM_VALUE_END],
|
|||
((1 - style_factor) * (1 + home_advantage * (i == 0)) *
|
||||
(1 + CONSTANT_PLAYER_BOOST_SKILL_EFFECT * (tm[i] == my_team && options[OPT_BOOL_BOOST] == 1)));
|
||||
|
||||
printf("%s attack %.1f defend %.1f\n", tm[i]->name->str, team_values[i][GAME_TEAM_VALUE_ATTACK],
|
||||
/*d*/
|
||||
printf("%s attack %.1f midf %.1f defend %.1f\n",
|
||||
tm[i]->name->str,
|
||||
team_values[i][GAME_TEAM_VALUE_ATTACK],
|
||||
team_values[i][GAME_TEAM_VALUE_MIDFIELD],
|
||||
team_values[i][GAME_TEAM_VALUE_DEFEND]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Return the contribution of a player to the attack, defend or
|
||||
goalie value of his team.
|
||||
/** Return the contribution of a player to the attack, midfield or defend.
|
||||
@param pl The player.
|
||||
@param attack Whether we have attack or defend value.
|
||||
@param type Whether we have defend, midfield or attack value.
|
||||
@return The player's contribution depending on position and
|
||||
fitness. */
|
||||
gfloat
|
||||
game_get_player_contribution(const Player *pl, gboolean attack)
|
||||
game_get_player_contribution(const Player *pl, gint type)
|
||||
{
|
||||
gfloat weights[4] =
|
||||
{1,
|
||||
(attack) ? CONSTANT_GAME_PLAYER_WEIGHT_DEFENDER_ATTACK : CONSTANT_GAME_PLAYER_WEIGHT_DEFENDER_DEFEND,
|
||||
CONSTANT_GAME_PLAYER_WEIGHT_MIDFIELDER,
|
||||
(attack) ? CONSTANT_GAME_PLAYER_WEIGHT_FORWARD_ATTACK : CONSTANT_GAME_PLAYER_WEIGHT_FORWARD_DEFEND};
|
||||
|
||||
return (gfloat)(pl->cskill * powf((gfloat)pl->fitness / 100, CONSTANT_GAME_PLAYER_FITNESS_EXPONENT) *
|
||||
weights[pl->pos]);
|
||||
return (gfloat)(pl->cskill * powf((gfloat)pl->fitness / 100,
|
||||
CONSTANT_GAME_PLAYER_FITNESS_EXPONENT) *
|
||||
player_weights[pl->cpos - 1][type - GAME_TEAM_VALUE_DEFEND]);
|
||||
}
|
||||
|
||||
/** Return a random attacking or defending player
|
||||
|
@ -94,28 +92,31 @@ game_get_player_contribution(const Player *pl, gboolean attack)
|
|||
or would like to have a penalty shooting player.
|
||||
@param number_of_penalty Which penalty has to be taken (1st, 2nd etc.)
|
||||
@param not_this_one A player to exclude.
|
||||
@param skills Whether to weight with skills, too.
|
||||
@return A player index. */
|
||||
gint
|
||||
game_get_player(const Team *tm, gint player_type, gint number_of_penalty, gint not_this_one)
|
||||
game_get_player(const Team *tm, gint player_type,
|
||||
gint number_of_penalty, gint not_this_one,
|
||||
gboolean skills)
|
||||
{
|
||||
gint i, player = not_this_one;
|
||||
gfloat weights[3];
|
||||
gfloat probs[10];
|
||||
gfloat rndom;
|
||||
|
||||
if(player_type == GAME_PLAYER_TYPE_ATTACKER)
|
||||
if(player_type == GAME_PLAYER_TYPE_ATTACK)
|
||||
{
|
||||
weights[0] = 0.25;
|
||||
weights[1] = 0.5;
|
||||
weights[2] = 1;
|
||||
}
|
||||
else if(player_type == GAME_PLAYER_TYPE_ATTACKING)
|
||||
else if(player_type == GAME_PLAYER_TYPE_MIDFIELD)
|
||||
{
|
||||
weights[0] = 0.5;
|
||||
weights[1] = 1;
|
||||
weights[2] = 1;
|
||||
weights[2] = 0.5;
|
||||
}
|
||||
else if(player_type == GAME_PLAYER_TYPE_DEFENDER)
|
||||
else if(player_type == GAME_PLAYER_TYPE_DEFEND)
|
||||
{
|
||||
weights[0] = 1;
|
||||
weights[1] = 0.5;
|
||||
|
@ -124,16 +125,17 @@ game_get_player(const Team *tm, gint player_type, gint number_of_penalty, gint n
|
|||
else if(player_type == GAME_PLAYER_TYPE_INJURY)
|
||||
weights[0] = -1;
|
||||
else if(player_type == GAME_PLAYER_TYPE_PENALTY)
|
||||
return 10;
|
||||
/*d*/
|
||||
return player_of(tm, 10)->id;
|
||||
|
||||
game_get_player_probs(tm->players, probs, weights);
|
||||
game_get_player_probs(tm->players, probs, weights, skills);
|
||||
|
||||
while(player == not_this_one)
|
||||
{
|
||||
rndom = math_rnd(0, probs[9]);
|
||||
|
||||
if(rndom < probs[0])
|
||||
player = player_of(tm, 0)->id;
|
||||
player = player_of(tm, 1)->id;
|
||||
else
|
||||
for(i=1;i<10;i++)
|
||||
if(rndom < probs[i] && rndom > probs[i - 1])
|
||||
|
@ -143,8 +145,15 @@ game_get_player(const Team *tm, gint player_type, gint number_of_penalty, gint n
|
|||
return player;
|
||||
}
|
||||
|
||||
/** Write the probabilities for field players being picked
|
||||
(e.g. a random defender, or a player who gets injured) into
|
||||
the float array. Depends on skill mostly.
|
||||
@param players Player array.
|
||||
@param probs Array with probabilities that gets filled.
|
||||
@param weights How to weight the players depending on their position.
|
||||
@param skills Whether to weight with skills, too. */
|
||||
void
|
||||
game_get_player_probs(GArray *players, gfloat *probs, gfloat *weights)
|
||||
game_get_player_probs(GArray *players, gfloat *probs, gfloat *weights, gboolean skills)
|
||||
{
|
||||
gint i;
|
||||
|
||||
|
@ -153,12 +162,17 @@ game_get_player_probs(GArray *players, gfloat *probs, gfloat *weights)
|
|||
probs[i] = 1;
|
||||
else
|
||||
{
|
||||
probs[0] = (gfloat)g_array_index(players, Player, 1).cskill *
|
||||
powf((gfloat)g_array_index(players, Player, 1).fitness, CONSTANT_GAME_PLAYER_FITNESS_EXPONENT) *
|
||||
weights[g_array_index(players, Player, 0).pos - 1];
|
||||
probs[0] = (skills) ? (gfloat)g_array_index(players, Player, 1).cskill *
|
||||
powf((gfloat)g_array_index(players, Player, 1).fitness,
|
||||
CONSTANT_GAME_PLAYER_FITNESS_EXPONENT) *
|
||||
weights[g_array_index(players, Player, 1).pos - 1] :
|
||||
weights[g_array_index(players, Player, 1).pos - 1];
|
||||
for(i=1;i<10;i++)
|
||||
probs[i] = probs[i - 1] + (gfloat)g_array_index(players, Player, i + 1).cskill *
|
||||
powf((gfloat)g_array_index(players, Player, i + 1).fitness, CONSTANT_GAME_PLAYER_FITNESS_EXPONENT) *
|
||||
weights[g_array_index(players, Player, i + 1).pos - 1];;
|
||||
probs[i] = probs[i - 1] +
|
||||
((skills) ? (gfloat)g_array_index(players, Player, i + 1).cskill *
|
||||
powf((gfloat)g_array_index(players, Player, i + 1).fitness,
|
||||
CONSTANT_GAME_PLAYER_FITNESS_EXPONENT) *
|
||||
weights[g_array_index(players, Player, i + 1).pos - 1] :
|
||||
weights[g_array_index(players, Player, i + 1).pos - 1]);
|
||||
}
|
||||
}
|
||||
|
|
17
src/game.h
17
src/game.h
|
@ -17,8 +17,9 @@
|
|||
@see game_get_values() */
|
||||
enum GameTeamValue
|
||||
{
|
||||
GAME_TEAM_VALUE_ATTACK = 0,
|
||||
GAME_TEAM_VALUE_DEFEND,
|
||||
GAME_TEAM_VALUE_DEFEND = 0,
|
||||
GAME_TEAM_VALUE_MIDFIELD,
|
||||
GAME_TEAM_VALUE_ATTACK,
|
||||
GAME_TEAM_VALUE_GOALIE,
|
||||
GAME_TEAM_VALUE_END
|
||||
};
|
||||
|
@ -26,9 +27,9 @@ enum GameTeamValue
|
|||
/** Player types. @see game_get_player() */
|
||||
enum GamePlayerType
|
||||
{
|
||||
GAME_PLAYER_TYPE_ATTACKER = 0,
|
||||
GAME_PLAYER_TYPE_ATTACKING,
|
||||
GAME_PLAYER_TYPE_DEFENDER,
|
||||
GAME_PLAYER_TYPE_ATTACK = 0,
|
||||
GAME_PLAYER_TYPE_MIDFIELD,
|
||||
GAME_PLAYER_TYPE_DEFEND,
|
||||
GAME_PLAYER_TYPE_PENALTY,
|
||||
GAME_PLAYER_TYPE_INJURY,
|
||||
GAME_PLAYER_TYPE_END
|
||||
|
@ -42,9 +43,11 @@ gfloat
|
|||
game_get_player_contribution(const Player *pl, gboolean attack);
|
||||
|
||||
gint
|
||||
game_get_player(const Team *tm, gint player_type, gint number_of_penalty, gint not_this_one);
|
||||
game_get_player(const Team *tm, gint player_type,
|
||||
gint number_of_penalty, gint not_this_one,
|
||||
gboolean skills);
|
||||
|
||||
void
|
||||
game_get_player_probs(GArray *players, gfloat *probs, gfloat *weights);
|
||||
game_get_player_probs(GArray *players, gfloat *probs, gfloat *weights, gboolean skills);
|
||||
|
||||
#endif
|
||||
|
|
111
src/game_gui.c
111
src/game_gui.c
|
@ -0,0 +1,111 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "game_gui.h"
|
||||
#include "treeview.h"
|
||||
#include "support.h"
|
||||
#include "window.h"
|
||||
|
||||
/** Constants determining the live game area scale
|
||||
behaviour. */
|
||||
#define CONSTANT_GAME_GUI_LIVE_GAME_SCALE_ATTACK 0.3
|
||||
#define CONSTANT_GAME_GUI_LIVE_GAME_SCALE_CHANCE 0.45
|
||||
#define CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE 10.0
|
||||
#define CONSTANT_GAME_GUI_LIVE_GAME_SCALE_CHANCE_COLOR "orange"
|
||||
#define CONSTANT_GAME_GUI_LIVE_GAME_SCALE_GOAL_COLOR "red"
|
||||
#define CONSTANT_GAME_GUI_LIVE_GAME_SCALE_MISS_COLOR "lightgreen"
|
||||
|
||||
/** Show the live game in the live game window.
|
||||
@param unit The current unit we show. */
|
||||
void
|
||||
game_gui_live_game_show_unit(const LiveGameUnit *unit)
|
||||
{
|
||||
GtkProgressBar *progress_bar;
|
||||
|
||||
if(live_game.window == NULL)
|
||||
{
|
||||
live_game.window = window_create(WINDOW_LIVE);
|
||||
treeview_live_game_show_initial_commentary(unit);
|
||||
|
||||
gtk_range_set_range(
|
||||
GTK_RANGE(lookup_widget(live_game.window, "hscale_area")), 0,
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE);
|
||||
}
|
||||
else
|
||||
treeview_live_game_show_commentary(unit);
|
||||
|
||||
treeview_live_game_show_result(unit);
|
||||
|
||||
game_gui_live_game_set_hscale(unit,
|
||||
GTK_HSCALE(lookup_widget(live_game.window, "hscale_area")));
|
||||
|
||||
progress_bar = GTK_PROGRESS_BAR(lookup_widget(live_game.window, "progressbar_live"));
|
||||
gtk_progress_bar_set_fraction(progress_bar, (gfloat)live_game_unit_get_minute(unit) / 120);
|
||||
usleep(500500 + options[OPT_LIVE_SPEED] * 50000);
|
||||
while(gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
|
||||
if(unit->event.type == LIVE_GAME_EVENT_END_MATCH)
|
||||
gtk_widget_set_sensitive(lookup_widget(live_game.window, "button_live_close"), TRUE);
|
||||
|
||||
}
|
||||
|
||||
/** Set the area scale position and color in the live game window.
|
||||
@param unit The current unit.
|
||||
@param hscale The scale widget. */
|
||||
void
|
||||
game_gui_live_game_set_hscale(const LiveGameUnit *unit, GtkHScale *hscale)
|
||||
{
|
||||
GdkColor color;
|
||||
|
||||
gtk_widget_modify_bg(GTK_WIDGET(hscale), GTK_STATE_NORMAL, NULL);
|
||||
|
||||
if(unit->area == LIVE_GAME_UNIT_AREA_MIDFIELD)
|
||||
gtk_range_set_value(GTK_RANGE(hscale),
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE / 2);
|
||||
else if(unit->event.type == LIVE_GAME_EVENT_GOAL)
|
||||
{
|
||||
gdk_color_parse(CONSTANT_GAME_GUI_LIVE_GAME_SCALE_GOAL_COLOR, &color);
|
||||
gtk_widget_modify_bg(GTK_WIDGET(hscale), GTK_STATE_NORMAL, &color);
|
||||
|
||||
gtk_range_set_value(GTK_RANGE(hscale),
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE * (unit->possession == 0));
|
||||
}
|
||||
else if(unit->event.type == LIVE_GAME_EVENT_SCORING_CHANCE ||
|
||||
unit->event.type == LIVE_GAME_EVENT_PENALTY ||
|
||||
unit->event.type == LIVE_GAME_EVENT_FREE_KICK)
|
||||
{
|
||||
gdk_color_parse(CONSTANT_GAME_GUI_LIVE_GAME_SCALE_CHANCE_COLOR, &color);
|
||||
gtk_widget_modify_bg(GTK_WIDGET(hscale), GTK_STATE_NORMAL, &color);
|
||||
|
||||
gtk_range_set_value(GTK_RANGE(hscale),
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE / 2 +
|
||||
(CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE *
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_CHANCE *
|
||||
((unit->possession == 0) ? 1 : -1)));
|
||||
}
|
||||
else if(unit->event.type == LIVE_GAME_EVENT_POST ||
|
||||
unit->event.type == LIVE_GAME_EVENT_MISSED ||
|
||||
unit->event.type == LIVE_GAME_EVENT_SAVE ||
|
||||
unit->event.type == LIVE_GAME_EVENT_CROSS_BAR)
|
||||
{
|
||||
gdk_color_parse(CONSTANT_GAME_GUI_LIVE_GAME_SCALE_MISS_COLOR, &color);
|
||||
gtk_widget_modify_bg(GTK_WIDGET(hscale), GTK_STATE_NORMAL, &color);
|
||||
}
|
||||
else if(unit->area == LIVE_GAME_UNIT_AREA_ATTACK)
|
||||
gtk_range_set_value(GTK_RANGE(hscale),
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE / 2 +
|
||||
(CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE *
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_ATTACK *
|
||||
((unit->possession == 0) ? 1 : -1)));
|
||||
else if(unit->area == LIVE_GAME_UNIT_AREA_DEFEND)
|
||||
gtk_range_set_value(GTK_RANGE(hscale),
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE / 2 +
|
||||
(CONSTANT_GAME_GUI_LIVE_GAME_SCALE_RANGE *
|
||||
CONSTANT_GAME_GUI_LIVE_GAME_SCALE_ATTACK *
|
||||
((unit->possession == 0) ? -1 : 1)));
|
||||
else
|
||||
g_warning("game_gui_live_game_set_hscale: don't know what to do!\n");
|
||||
|
||||
if(debug)
|
||||
printf("***** area %d value %.1f\n", unit->area, gtk_range_get_value(GTK_RANGE(hscale)));
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef GAME_GUI_H
|
||||
#define GAME_GUI_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "live_game.h"
|
||||
#include "variables.h"
|
||||
|
||||
void
|
||||
game_gui_live_game_show_unit(const LiveGameUnit *unit);
|
||||
|
||||
void
|
||||
game_gui_live_game_set_hscale(const LiveGameUnit *unit, GtkHScale *hscale);
|
||||
|
||||
#endif
|
539
src/live_game.c
539
src/live_game.c
|
@ -1,5 +1,6 @@
|
|||
#include "fixture.h"
|
||||
#include "free.h"
|
||||
#include "game_gui.h"
|
||||
#include "live_game.h"
|
||||
#include "maths.h"
|
||||
#include "player.h"
|
||||
|
@ -7,64 +8,43 @@
|
|||
#include "treeview.h"
|
||||
#include "variables.h"
|
||||
|
||||
/** The smaller this number, the smaller the probability of
|
||||
many extra minutes after 90 or 45 minutes. */
|
||||
#define CONSTANT_LIVE_GAME_BREAK_BASE 0.6
|
||||
/** The bigger this number, the faster the probability of
|
||||
yet another additional minute after the 45th minute decays. */
|
||||
#define CONSTANT_LIVE_GAME_45_BREAK_EXPONENT_FACTOR 1.3
|
||||
/** The bigger this number, the faster the probability of
|
||||
yet another additional minute after the 90th minute decays. */
|
||||
#define CONSTANT_LIVE_GAME_90_BREAK_EXPONENT_FACTOR 0.7
|
||||
/** The probability that the team that shot on the goal stays
|
||||
in possession after a post or cross-bar hit. */
|
||||
#define CONSTANT_LIVE_GAME_POSSESSION_AFTER_POST 0.3
|
||||
|
||||
/** Constants determining the type of a LiveGameEvent.
|
||||
@see live_game_create_event_type() */
|
||||
|
||||
/** Base probability that the ball gets from defending area
|
||||
to midfield area. */
|
||||
#define CONSTANT_LIVE_GAME_AREA_DEF_MID 0.5
|
||||
/** Influence of attack/defend values on the base probability; the lower
|
||||
the smaller the influence. */
|
||||
#define CONSTANT_LIVE_GAME_AREA_DEF_MID_TEAM_EXPONENT 0.5
|
||||
|
||||
/** Base probability that the ball gets from midfield area
|
||||
to attack area or back to defend area. */
|
||||
#define CONSTANT_LIVE_GAME_AREA_MID_ATT 0.5
|
||||
#define CONSTANT_LIVE_GAME_AREA_MID_DEF 0.3
|
||||
/** Influence of attack/defend values on the base probability; the lower
|
||||
the smaller the influence. */
|
||||
#define CONSTANT_LIVE_GAME_AREA_MID_TEAM_EXPONENT 1
|
||||
|
||||
/** Base probability that the ball gets from attacking area
|
||||
to midfield area. */
|
||||
#define CONSTANT_LIVE_GAME_AREA_ATT_MID 0.3
|
||||
/** Influence of attack/defend values on the base probability; the lower
|
||||
the smaller the influence. */
|
||||
#define CONSTANT_LIVE_GAME_AREA_ATT_MID_TEAM_EXPONENT 0.5
|
||||
|
||||
/** Base probability of a general event (no foul, no injury, no goal etc.) */
|
||||
#define CONSTANT_LIVE_GAME_EVENT_GENERAL 0.5
|
||||
|
||||
/** Foul probabilities. */
|
||||
#define CONSTANT_LIVE_GAME_FOUL (20.0 / 90.0 * CONSTANT_LIVE_GAME_EVENT_GENERAL)
|
||||
#define CONSTANT_LIVE_GAME_FOUL_RED_INJURY 0.05
|
||||
#define CONSTANT_LIVE_GAME_FOUL_RED 0.08
|
||||
#define CONSTANT_LIVE_GAME_FOUL_YELLOW 0.23
|
||||
|
||||
/** Injury probabilities. */
|
||||
#define CONSTANT_LIVE_GAME_INJURY (3.0 / 90 * CONSTANT_LIVE_GAME_EVENT_GENERAL)
|
||||
#define CONSTANT_LIVE_GAME_INJURY_FIELD_PLAYER 0.8
|
||||
#define CONSTANT_LIVE_GAME_INJURY_IS_TEMP 0.7
|
||||
|
||||
/** Probability that a scoring chance is an own goal. */
|
||||
#define CONSTANT_LIVE_GAME_SCORING_CHANCE_IS_OWN_GOAL 0.01
|
||||
|
||||
/** Probability of a free kick after a foul. */
|
||||
#define CONSTANT_LIVE_GAME_FREE_KICK_PROB 0.15
|
||||
|
||||
/** Probability of a penalty after a foul. */
|
||||
#define CONSTANT_LIVE_GAME_PENALTY_PROB 0.05
|
||||
|
||||
/** Probability that a scoring chance is a header. */
|
||||
#define CONSTANT_LIVE_GAME_SCORING_CHANCE_IS_HEADER 0.35
|
||||
|
||||
/** Constants for stadium events. */
|
||||
#define CONSTANT_LIVE_GAME_STADIUM_EVENT_EXPONENT (0.1 * CONSTANT_LIVE_GAME_EVENT_GENERAL)
|
||||
#define CONSTANT_LIVE_GAME_STADIUM_EVENT_FIRE 0.2
|
||||
#define CONSTANT_LIVE_GAME_STADIUM_EVENT_RIOTS 0.5
|
||||
#define CONSTANT_LIVE_GAME_STADIUM_EVENT_BREAKDOWN 1.0
|
||||
|
||||
/** Base probability for possession change. */
|
||||
#define CONSTANT_LIVE_GAME_POSSESSION_CHANGES 0.2
|
||||
/** Influence of attack/defense values on the possession change. */
|
||||
#define CONSTANT_LIVE_GAME_POSSESSION_TEAM_EXPONENT 4
|
||||
/** Influence of the team values on the possession change. */
|
||||
#define CONSTANT_LIVE_GAME_POSSESSION_TEAM_EXPONENT 2
|
||||
|
||||
/** Probability of NOT having a scoring chance after one
|
||||
possession. With each possession the probability gets smaller. */
|
||||
#define CONSTANT_LIVE_GAME_SCORING_CHANCE 0.75
|
||||
/** Influence of team attack/defend values on the probability to get
|
||||
a scoring chance. */
|
||||
#define CONSTANT_LIVE_GAME_SCORING_CHANCE_EXPONENT 1.25
|
||||
/** Base prob for a scoring chance if a team is attacking. */
|
||||
#define CONSTANT_LIVE_GAME_SCORING_CHANCE 0.2
|
||||
/** Team values influence on the scoring chance. */
|
||||
#define CONSTANT_LIVE_GAME_SCORING_CHANCE_TEAM_EXPONENT 1
|
||||
|
||||
/** Probability that it's the player in possession who
|
||||
has the scoring chance. */
|
||||
|
@ -81,6 +61,53 @@
|
|||
/** Influence of the team attacking/defending values on the probability to score. */
|
||||
#define CONSTANT_LIVE_GAME_SCORE_TEAM_EXPONENT 0.7
|
||||
|
||||
/** The smaller this number, the smaller the probability of
|
||||
many stopping minutes after 90 or 45 minutes. */
|
||||
#define CONSTANT_LIVE_GAME_BREAK_BASE 0.6
|
||||
/** The bigger this number, the faster the probability of
|
||||
yet another additional minute after the 45th minute decays. */
|
||||
#define CONSTANT_LIVE_GAME_45_BREAK_EXPONENT_FACTOR 1.3
|
||||
/** The bigger this number, the faster the probability of
|
||||
yet another additional minute after the 90th minute decays. */
|
||||
#define CONSTANT_LIVE_GAME_90_BREAK_EXPONENT_FACTOR 0.7
|
||||
/** The probability that the team that shot on the goal stays
|
||||
in possession after a post or cross-bar hit. */
|
||||
#define CONSTANT_LIVE_GAME_POSSESSION_AFTER_POST 0.3
|
||||
|
||||
/** Probability that there is a passing event after a special event.
|
||||
@see live_game_event_general() */
|
||||
#define CONSTANT_LIVE_GAME_GENERAL_EVENT_SECOND_PLAYER 0.5
|
||||
|
||||
/** Constants for stadium events. */
|
||||
#define CONSTANT_LIVE_GAME_STADIUM_EVENT_EXPONENT (0.1 * CONSTANT_LIVE_GAME_EVENT_GENERAL)
|
||||
#define CONSTANT_LIVE_GAME_STADIUM_EVENT_FIRE 0.2
|
||||
#define CONSTANT_LIVE_GAME_STADIUM_EVENT_RIOTS 0.5
|
||||
#define CONSTANT_LIVE_GAME_STADIUM_EVENT_BREAKDOWN 1.0
|
||||
|
||||
/** Foul probabilities. */
|
||||
#define CONSTANT_LIVE_GAME_FOUL (20.0 / 90.0 * CONSTANT_LIVE_GAME_EVENT_GENERAL)
|
||||
#define CONSTANT_LIVE_GAME_FOUL_RED_INJURY 0.05
|
||||
#define CONSTANT_LIVE_GAME_FOUL_RED 0.08
|
||||
#define CONSTANT_LIVE_GAME_FOUL_YELLOW 0.23
|
||||
|
||||
/** Injury probabilities. */
|
||||
#define CONSTANT_LIVE_GAME_INJURY (3.0 / 90 * CONSTANT_LIVE_GAME_EVENT_GENERAL)
|
||||
#define CONSTANT_LIVE_GAME_INJURY_GOALIE_FACTOR 0.2
|
||||
#define CONSTANT_LIVE_GAME_INJURY_IS_TEMP 0.7
|
||||
|
||||
/** Probability that a scoring chance is an own goal. */
|
||||
#define CONSTANT_LIVE_GAME_SCORING_CHANCE_IS_OWN_GOAL 0.01
|
||||
|
||||
/** Probability of a free kick after a foul. */
|
||||
#define CONSTANT_LIVE_GAME_FREE_KICK_PROB 0.15
|
||||
|
||||
/** Probability of a penalty after a foul. */
|
||||
#define CONSTANT_LIVE_GAME_PENALTY_PROB 0.05
|
||||
|
||||
/** Probability that a scoring chance is a header. */
|
||||
#define CONSTANT_LIVE_GAME_SCORING_CHANCE_IS_HEADER 0.35
|
||||
|
||||
|
||||
/** The live game we calculate. */
|
||||
LiveGame *match;
|
||||
/** Whether the events are actually shown or not. */
|
||||
|
@ -111,7 +138,8 @@ live_game_calculate_fixture(Fixture *fix)
|
|||
live_game_evaluate_unit(&last_unit);
|
||||
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
}
|
||||
while(last_unit.event.type != LIVE_GAME_EVENT_END_MATCH);
|
||||
|
||||
|
@ -126,6 +154,8 @@ live_game_create_unit(void)
|
|||
{
|
||||
LiveGameUnit new;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_create_unit\n");
|
||||
if(units->len == 0)
|
||||
{
|
||||
live_game_create_start_unit();
|
||||
|
@ -143,14 +173,14 @@ live_game_create_unit(void)
|
|||
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;
|
||||
new.area = last_unit.area;
|
||||
|
||||
if(query_live_game_event_is_break(new.minute, new.time))
|
||||
{
|
||||
new.event.type = live_game_get_break();
|
||||
new.possession = last_unit.possession;
|
||||
new.possession_time = last_unit.possession_time;
|
||||
live_game_generate_commentary(&new);
|
||||
g_array_append_val(units, new);
|
||||
g_array_append_val(units, new);
|
||||
return;
|
||||
}
|
||||
else if(last_unit.time == LIVE_GAME_UNIT_TIME_PENALTIES)
|
||||
|
@ -171,21 +201,22 @@ live_game_fill_new_unit(LiveGameUnit *new)
|
|||
gfloat stadium_event =
|
||||
1 - powf((gfloat)tm0->stadium.safety / 100,
|
||||
CONSTANT_LIVE_GAME_STADIUM_EVENT_EXPONENT);
|
||||
gfloat possession_change, scoring_chance;
|
||||
gfloat possession_change, scoring_chance = 0;
|
||||
|
||||
possession_change = (CONSTANT_LIVE_GAME_POSSESSION_CHANGES *
|
||||
powf(match->team_values[!old->possession][GAME_TEAM_VALUE_DEFEND] /
|
||||
match->team_values[old->possession][GAME_TEAM_VALUE_ATTACK],
|
||||
CONSTANT_LIVE_GAME_POSSESSION_TEAM_EXPONENT)) * CONSTANT_LIVE_GAME_EVENT_GENERAL;
|
||||
|
||||
scoring_chance = (1 - powf(CONSTANT_LIVE_GAME_SCORING_CHANCE,
|
||||
old->possession_time *
|
||||
powf(match->team_values[old->possession][GAME_TEAM_VALUE_ATTACK] /
|
||||
match->team_values[!old->possession][GAME_TEAM_VALUE_DEFEND],
|
||||
CONSTANT_LIVE_GAME_SCORING_CHANCE_EXPONENT))) * CONSTANT_LIVE_GAME_EVENT_GENERAL;
|
||||
if(debug)
|
||||
printf("live_game_fill_new_unit\n");
|
||||
possession_change = CONSTANT_LIVE_GAME_EVENT_GENERAL *
|
||||
CONSTANT_LIVE_GAME_POSSESSION_CHANGES /
|
||||
live_game_pit_teams(old, CONSTANT_LIVE_GAME_POSSESSION_TEAM_EXPONENT);
|
||||
|
||||
new->possession = old->possession;
|
||||
new->possession_time = old->possession_time;
|
||||
|
||||
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 = CONSTANT_LIVE_GAME_SCORING_CHANCE *
|
||||
live_game_pit_teams(new, CONSTANT_LIVE_GAME_SCORING_CHANCE_TEAM_EXPONENT);
|
||||
|
||||
if(rndom < CONSTANT_LIVE_GAME_FOUL)
|
||||
new->event.type = LIVE_GAME_EVENT_FOUL;
|
||||
|
@ -202,7 +233,10 @@ live_game_fill_new_unit(LiveGameUnit *new)
|
|||
{
|
||||
new->event.type = LIVE_GAME_EVENT_LOST_POSSESSION;
|
||||
new->possession = !old->possession;
|
||||
new->possession_time = 1;
|
||||
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;
|
||||
}
|
||||
else if(rndom < CONSTANT_LIVE_GAME_FOUL +
|
||||
CONSTANT_LIVE_GAME_INJURY +
|
||||
|
@ -219,6 +253,8 @@ live_game_create_start_unit(void)
|
|||
{
|
||||
LiveGameUnit new;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_create_start_unit\n");
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
|
||||
|
||||
|
@ -228,7 +264,7 @@ live_game_create_start_unit(void)
|
|||
new.minute = 1;
|
||||
new.time = LIVE_GAME_UNIT_TIME_FIRST_HALF;
|
||||
new.possession = math_rndi(0, 1);
|
||||
new.possession_time = 1;
|
||||
new.area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
||||
match->started_game = new.possession;
|
||||
|
||||
new.event.type = LIVE_GAME_EVENT_START_MATCH;
|
||||
|
@ -246,12 +282,14 @@ live_game_evaluate_unit(LiveGameUnit *unit)
|
|||
{
|
||||
gint type = unit->event.type;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_evaluate_unit type %d\n", type);
|
||||
if(type == LIVE_GAME_EVENT_FOUL)
|
||||
live_game_event_foul(TRUE);
|
||||
else if(type == LIVE_GAME_EVENT_LOST_POSSESSION)
|
||||
live_game_event_lost_possession();
|
||||
else if(type == LIVE_GAME_EVENT_INJURY)
|
||||
live_game_event_injury(-1, FALSE);
|
||||
live_game_event_injury(-1, -1, FALSE);
|
||||
else if(type == LIVE_GAME_EVENT_STADIUM)
|
||||
live_game_event_stadium();
|
||||
else if(type == LIVE_GAME_EVENT_SCORING_CHANCE)
|
||||
|
@ -267,11 +305,14 @@ live_game_evaluate_unit(LiveGameUnit *unit)
|
|||
{
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
if(type != LIVE_GAME_EVENT_PENALTIES)
|
||||
live_game_event_general(TRUE);
|
||||
}
|
||||
else if(type != LIVE_GAME_EVENT_END_MATCH)
|
||||
g_warning("live_game_evaluate_unit: unknown event type %d\n",
|
||||
type);
|
||||
}
|
||||
|
||||
/** Calculate a foul event.
|
||||
|
@ -283,17 +324,19 @@ live_game_event_foul(gboolean general)
|
|||
gfloat rndom = math_rnd(0, 1);
|
||||
gint type;
|
||||
|
||||
if(units->len != 1)
|
||||
if(debug)
|
||||
printf("live_game_event_foul\n");
|
||||
if(uni(units->len - 2).event.type == LIVE_GAME_EVENT_GENERAL)
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
|
||||
else
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.possession],
|
||||
GAME_PLAYER_TYPE_ATTACKING, 0, -1);
|
||||
last_unit.area, 0, -1, FALSE);
|
||||
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
|
||||
game_get_player(tm[!last_unit.possession],
|
||||
GAME_PLAYER_TYPE_DEFENDER, 0, -1);
|
||||
last_unit.area, 0, -1, FALSE);
|
||||
|
||||
if(rndom < CONSTANT_LIVE_GAME_FOUL_RED_INJURY)
|
||||
type = LIVE_GAME_EVENT_FOUL_RED_INJURY;
|
||||
|
@ -308,7 +351,7 @@ live_game_event_foul(gboolean general)
|
|||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
if(type == LIVE_GAME_EVENT_FOUL_RED ||
|
||||
type == LIVE_GAME_EVENT_FOUL_RED_INJURY ||
|
||||
|
@ -316,17 +359,23 @@ live_game_event_foul(gboolean general)
|
|||
query_live_game_second_yellow(!last_unit.possession,
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2])))
|
||||
{
|
||||
live_game_event_send_off(last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]);
|
||||
live_game_event_send_off(!last_unit.possession,
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]);
|
||||
if(type == LIVE_GAME_EVENT_FOUL_RED_INJURY)
|
||||
live_game_event_injury(uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER], TRUE);
|
||||
live_game_event_injury(last_unit.possession,
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER], TRUE);
|
||||
}
|
||||
|
||||
rndom = math_rnd(0, 1);
|
||||
|
||||
if(rndom < CONSTANT_LIVE_GAME_PENALTY_PROB)
|
||||
live_game_event_penalty();
|
||||
else if(rndom < CONSTANT_LIVE_GAME_FREE_KICK_PROB)
|
||||
live_game_event_free_kick();
|
||||
if(last_unit.area == LIVE_GAME_UNIT_AREA_ATTACK)
|
||||
{
|
||||
rndom = math_rnd(0, 1);
|
||||
if(rndom < CONSTANT_LIVE_GAME_PENALTY_PROB)
|
||||
live_game_event_penalty();
|
||||
else if(rndom < CONSTANT_LIVE_GAME_FREE_KICK_PROB)
|
||||
live_game_event_free_kick();
|
||||
else
|
||||
live_game_event_general(TRUE);
|
||||
}
|
||||
else
|
||||
live_game_event_general(TRUE);
|
||||
}
|
||||
|
@ -335,77 +384,67 @@ live_game_event_foul(gboolean general)
|
|||
void
|
||||
live_game_event_lost_possession(void)
|
||||
{
|
||||
if(debug)
|
||||
printf("live_game_event_lost_possession\n");
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.possession],
|
||||
GAME_PLAYER_TYPE_DEFENDER, 0, -1);
|
||||
last_unit.area, 0, -1, TRUE);
|
||||
|
||||
if(uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1)
|
||||
if(uni(units->len - 2).event.type == LIVE_GAME_EVENT_GENERAL)
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
|
||||
else
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
|
||||
game_get_player(tm[!last_unit.possession],
|
||||
GAME_PLAYER_TYPE_ATTACKING, 0, -1);
|
||||
uni(units->len - 2).area, 0, -1, FALSE);
|
||||
|
||||
if(debug)
|
||||
printf("## pls %d %d\n",
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER],
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]);
|
||||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
live_game_event_general(TRUE);
|
||||
}
|
||||
|
||||
/** Calculate an injury event.
|
||||
@param team The team the player is from.
|
||||
@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
|
||||
live_game_event_injury(gint player, gboolean create_new)
|
||||
live_game_event_injury(gint team, gint player, gboolean create_new)
|
||||
{
|
||||
LiveGameUnit new;
|
||||
gint team;
|
||||
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_event_injury\n");
|
||||
if(create_new)
|
||||
{
|
||||
new.possession = last_unit.possession;
|
||||
new.possession_time = last_unit.possession_time;
|
||||
new.minute = -1;
|
||||
new.time = last_unit.time;
|
||||
new.event.type = LIVE_GAME_EVENT_INJURY;
|
||||
new = last_unit;
|
||||
new.event.commentary = g_string_new("injury");
|
||||
g_array_append_val(units, new);
|
||||
}
|
||||
|
||||
if(player != -1)
|
||||
{
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
player;
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] =
|
||||
last_unit.possession;
|
||||
team;
|
||||
}
|
||||
else
|
||||
{
|
||||
team = math_rndi(0, 1);
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM] =
|
||||
team;
|
||||
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[team], GAME_PLAYER_TYPE_INJURY, 0, -1);
|
||||
|
||||
if(math_rnd(0, 1) > CONSTANT_LIVE_GAME_INJURY_FIELD_PLAYER &&
|
||||
player_of(tm[team], 0)->cskill != 0)
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = 0;
|
||||
}
|
||||
live_game_event_injury_get_player();
|
||||
|
||||
last_unit.minute = -1;
|
||||
last_unit.event.type = LIVE_GAME_EVENT_INJURY;
|
||||
|
||||
if(math_rnd(0, 1) < CONSTANT_LIVE_GAME_INJURY_IS_TEMP)
|
||||
last_unit.event.type = LIVE_GAME_EVENT_TEMP_INJURY;
|
||||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
/*d*/
|
||||
live_game_event_general(TRUE);
|
||||
|
@ -417,6 +456,8 @@ live_game_event_stadium(void)
|
|||
{
|
||||
gfloat rndom = math_rnd(0, 1);
|
||||
|
||||
if(debug)
|
||||
printf("live_game_event_stadium\n");
|
||||
if(rndom < CONSTANT_LIVE_GAME_STADIUM_EVENT_FIRE)
|
||||
last_unit.event.type = LIVE_GAME_EVENT_STADIUM_FIRE;
|
||||
else if(rndom < CONSTANT_LIVE_GAME_STADIUM_EVENT_RIOTS)
|
||||
|
@ -426,7 +467,7 @@ live_game_event_stadium(void)
|
|||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
live_game_event_general(TRUE);
|
||||
}
|
||||
|
@ -435,31 +476,28 @@ live_game_event_stadium(void)
|
|||
void
|
||||
live_game_event_scoring_chance(void)
|
||||
{
|
||||
if(debug)
|
||||
printf("live_game_event_scoring_chance\n");
|
||||
if(math_rnd(0, 1) < CONSTANT_LIVE_GAME_SCORING_CHANCE_IS_OWN_GOAL)
|
||||
{
|
||||
last_unit.event.type = LIVE_GAME_EVENT_OWN_GOAL;
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[!last_unit.possession], GAME_PLAYER_TYPE_DEFENDER, 0, -1);
|
||||
game_get_player(tm[!last_unit.possession], last_unit.area, 0, -1, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1 &&
|
||||
math_rnd(0, 1) < CONSTANT_LIVE_GAME_PLAYER_IN_POSS_SHOOTS)
|
||||
{
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
|
||||
|
||||
if(uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] != -1)
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER2];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1)
|
||||
{
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_ATTACKER, 0,
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]);
|
||||
game_get_player(tm[last_unit.possession], last_unit.area, 0,
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER],
|
||||
TRUE);
|
||||
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
|
||||
|
@ -467,18 +505,18 @@ live_game_event_scoring_chance(void)
|
|||
else
|
||||
{
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_ATTACKER, 0, -1);
|
||||
game_get_player(tm[last_unit.possession], last_unit.area, 0, -1, TRUE);
|
||||
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
|
||||
game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_ATTACKING, 0,
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER]);
|
||||
game_get_player(tm[last_unit.possession], last_unit.area, 0,
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER], TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
live_game_event_duel();
|
||||
}
|
||||
|
@ -489,10 +527,10 @@ live_game_event_penalty(void)
|
|||
{
|
||||
LiveGameUnit new;
|
||||
|
||||
new.possession = last_unit.possession;
|
||||
new.possession_time = last_unit.possession_time;
|
||||
if(debug)
|
||||
printf("live_game_event_penalty\n");
|
||||
new = last_unit;
|
||||
new.minute = -1;
|
||||
new.time = last_unit.time;
|
||||
new.event.type = LIVE_GAME_EVENT_PENALTY;
|
||||
new.event.commentary = g_string_new("penalty");
|
||||
|
||||
|
@ -506,7 +544,7 @@ live_game_event_penalty(void)
|
|||
math_rndi(0, 1);
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
|
||||
GAME_PLAYER_TYPE_PENALTY, 0, -1);
|
||||
GAME_PLAYER_TYPE_PENALTY, 0, -1, FALSE);
|
||||
}
|
||||
else if(uni(units->len - 4).event.type == LIVE_GAME_EVENT_PENALTIES)
|
||||
{
|
||||
|
@ -514,7 +552,7 @@ live_game_event_penalty(void)
|
|||
!uni(units->len - 3).event.values[LIVE_GAME_EVENT_VALUE_TEAM];
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
|
||||
GAME_PLAYER_TYPE_PENALTY, 0, -1);
|
||||
GAME_PLAYER_TYPE_PENALTY, 0, -1, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -523,7 +561,7 @@ live_game_event_penalty(void)
|
|||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.event.values[LIVE_GAME_EVENT_VALUE_TEAM]],
|
||||
GAME_PLAYER_TYPE_PENALTY,
|
||||
-uni(units->len - 4).event.values[LIVE_GAME_EVENT_VALUE_PLAYER], -1);
|
||||
-uni(units->len - 4).event.values[LIVE_GAME_EVENT_VALUE_PLAYER], -1, FALSE);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -537,12 +575,12 @@ live_game_event_penalty(void)
|
|||
options[OPT_PENALTY_SHOOTER];
|
||||
else
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_PENALTY, 0, -1);
|
||||
game_get_player(tm[last_unit.possession], GAME_PLAYER_TYPE_PENALTY, 0, -1, FALSE);
|
||||
}
|
||||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
live_game_event_duel();
|
||||
}
|
||||
|
@ -552,9 +590,10 @@ live_game_event_penalty(void)
|
|||
void
|
||||
live_game_event_general(gboolean create_new)
|
||||
{
|
||||
gfloat rndom = math_rnd(0, 1);
|
||||
LiveGameUnit new;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_event_general\n");
|
||||
if(create_new)
|
||||
{
|
||||
new.minute = live_game_get_minute();
|
||||
|
@ -565,8 +604,6 @@ live_game_event_general(gboolean create_new)
|
|||
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_FOUL_RED ||
|
||||
last_unit.event.type == LIVE_GAME_EVENT_FOUL_RED_INJURY ||
|
||||
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 ||
|
||||
|
@ -576,10 +613,13 @@ live_game_event_general(gboolean create_new)
|
|||
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) &&
|
||||
rndom < CONSTANT_LIVE_GAME_POSSESSION_AFTER_POST))
|
||||
math_rnd(0, 1) < CONSTANT_LIVE_GAME_POSSESSION_AFTER_POST))
|
||||
{
|
||||
if(debug)
|
||||
printf("##### last type: %d\n", last_unit.event.type);
|
||||
new.possession = last_unit.possession;
|
||||
new.possession_time = last_unit.possession_time + 1;
|
||||
new.area = (last_unit.event.type == LIVE_GAME_EVENT_GENERAL) ?
|
||||
live_game_get_area(&last_unit) : last_unit.area;
|
||||
}
|
||||
else if(last_unit.event.type == LIVE_GAME_EVENT_GOAL ||
|
||||
last_unit.event.type == LIVE_GAME_EVENT_OWN_GOAL ||
|
||||
|
@ -589,20 +629,27 @@ live_game_event_general(gboolean create_new)
|
|||
last_unit.event.type == LIVE_GAME_EVENT_CROSS_BAR)
|
||||
{
|
||||
new.possession = !last_unit.possession;
|
||||
new.possession_time = 1;
|
||||
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;
|
||||
}
|
||||
else if(last_unit.event.type == LIVE_GAME_EVENT_HALF_TIME)
|
||||
{
|
||||
new.possession = !match->started_game;
|
||||
new.possession_time = 1;
|
||||
new.time = LIVE_GAME_UNIT_TIME_SECOND_HALF;
|
||||
new.area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
||||
}
|
||||
else if(last_unit.event.type == LIVE_GAME_EVENT_EXTRA_TIME)
|
||||
{
|
||||
new.possession = math_rndi(0, 1);
|
||||
new.possession_time = 1;
|
||||
new.time = LIVE_GAME_UNIT_TIME_EXTRA_TIME;
|
||||
new.area = LIVE_GAME_UNIT_AREA_MIDFIELD;
|
||||
}
|
||||
else
|
||||
g_warning("live_game_event_general: unknown event type: %d\n",
|
||||
last_unit.event.type);
|
||||
|
||||
new.event.type = LIVE_GAME_EVENT_GENERAL;
|
||||
new.event.commentary = g_string_new("general");
|
||||
|
@ -610,47 +657,67 @@ live_game_event_general(gboolean create_new)
|
|||
g_array_append_val(units, new);
|
||||
}
|
||||
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
|
||||
live_game_event_general_get_players();
|
||||
|
||||
if(last_unit.possession_time == 1)
|
||||
if(debug)
|
||||
printf("+++ general %d %d\n",
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER],
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2]);
|
||||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
}
|
||||
|
||||
/** 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 =
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER],
|
||||
old_pl2 =
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER2];
|
||||
gint type = uni(units->len - 2).event.type;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_event_general_get_players\n");
|
||||
*pl1 = *pl2 = -1;
|
||||
|
||||
if(type == LIVE_GAME_EVENT_LOST_POSSESSION)
|
||||
{
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.possession],
|
||||
GAME_PLAYER_TYPE_DEFENDER, 0, -1);
|
||||
*pl1 = old_pl2;
|
||||
*pl2 = game_get_player(tm[last_unit.possession],
|
||||
last_unit.area, 0, *pl1,
|
||||
TRUE);
|
||||
}
|
||||
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) < CONSTANT_LIVE_GAME_GENERAL_EVENT_SECOND_PLAYER)
|
||||
*pl2 = game_get_player(tm[last_unit.possession],
|
||||
last_unit.area, 0, *pl1, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[last_unit.possession],
|
||||
GAME_PLAYER_TYPE_ATTACKING, 0,
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER]);
|
||||
if(uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER] != -1)
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
|
||||
uni(units->len - 2).event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
|
||||
else
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] =
|
||||
game_get_player(tm[last_unit.possession],
|
||||
GAME_PLAYER_TYPE_ATTACKING, 0,
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER]);
|
||||
*pl2 = old_pl1;
|
||||
*pl1 = game_get_player(tm[last_unit.possession],
|
||||
last_unit.area, 0, *pl2, TRUE);
|
||||
}
|
||||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
}
|
||||
|
||||
/** Calculate a free kick event. */
|
||||
void
|
||||
live_game_event_free_kick(void)
|
||||
{
|
||||
LiveGameUnit new;
|
||||
LiveGameUnit new = last_unit;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_event_free_kick\n");
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
|
||||
|
||||
new.possession = last_unit.possession;
|
||||
new.possession_time = last_unit.possession_time;
|
||||
new.minute = -1;
|
||||
new.time = last_unit.time;
|
||||
|
||||
new.event.type = LIVE_GAME_EVENT_FREE_KICK;
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] =
|
||||
|
@ -662,40 +729,40 @@ live_game_event_free_kick(void)
|
|||
options[OPT_PENALTY_SHOOTER];
|
||||
else
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
game_get_player(tm[new.possession], GAME_PLAYER_TYPE_ATTACKING, 0, -1);
|
||||
game_get_player(tm[new.possession], new.area, 0, -1, TRUE);
|
||||
|
||||
g_array_append_val(units, new);
|
||||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
live_game_event_duel();
|
||||
}
|
||||
|
||||
/** Calculate a send-off event. */
|
||||
void
|
||||
live_game_event_send_off(gint player)
|
||||
live_game_event_send_off(gint team, gint player)
|
||||
{
|
||||
LiveGameUnit new;
|
||||
LiveGameUnit new = last_unit;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_event_send_off\n");
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
|
||||
|
||||
new.possession = last_unit.possession;
|
||||
new.possession_time = last_unit.possession_time;
|
||||
new.minute = -1;
|
||||
new.time = last_unit.time;
|
||||
|
||||
new.event.type = LIVE_GAME_EVENT_SEND_OFF;
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] = player;
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_TEAM] = team;
|
||||
new.event.commentary = g_string_new("send off");
|
||||
|
||||
g_array_append_val(units, new);
|
||||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
}
|
||||
|
||||
|
||||
|
@ -706,17 +773,16 @@ live_game_event_duel(void)
|
|||
gfloat rndom = math_rnd(0, 1);
|
||||
gfloat scoring_prob;
|
||||
gfloat duel_factor;
|
||||
LiveGameUnit new;
|
||||
LiveGameUnit new = last_unit;
|
||||
Player *attacker, *goalie;
|
||||
gint fix_idx1, fix_idx2;
|
||||
gint res_idx1, res_idx2;
|
||||
|
||||
if(debug)
|
||||
printf("live_game_event_duel\n");
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER2] = -1;
|
||||
|
||||
new.possession = last_unit.possession;
|
||||
new.possession_time = last_unit.possession_time;
|
||||
new.minute = -1;
|
||||
new.time = last_unit.time;
|
||||
|
||||
new.event.values[LIVE_GAME_EVENT_VALUE_PLAYER] =
|
||||
last_unit.event.values[LIVE_GAME_EVENT_VALUE_PLAYER];
|
||||
|
@ -730,13 +796,13 @@ live_game_event_duel(void)
|
|||
CONSTANT_GAME_PLAYER_FITNESS_EXPONENT)) /
|
||||
((gfloat)goalie->cskill * powf((gfloat)goalie->fitness / 100,
|
||||
CONSTANT_GAME_PLAYER_FITNESS_EXPONENT)));
|
||||
fix_idx1 = new.possession;
|
||||
res_idx1 = new.possession;
|
||||
if(new.time == LIVE_GAME_UNIT_TIME_PENALTIES)
|
||||
fix_idx2 = 2;
|
||||
res_idx2 = 2;
|
||||
else if(new.time == LIVE_GAME_UNIT_TIME_EXTRA_TIME)
|
||||
fix_idx2 = 1;
|
||||
res_idx2 = 1;
|
||||
else
|
||||
fix_idx2 = 0;
|
||||
res_idx2 = 0;
|
||||
|
||||
if(last_unit.event.type == LIVE_GAME_EVENT_PENALTY)
|
||||
scoring_prob = CONSTANT_LIVE_GAME_SCORE_PENALTY * duel_factor;
|
||||
|
@ -752,7 +818,7 @@ live_game_event_duel(void)
|
|||
if(rndom < scoring_prob)
|
||||
{
|
||||
new.event.type = LIVE_GAME_EVENT_GOAL;
|
||||
match->fix->result[fix_idx1][fix_idx2]++;
|
||||
match->fix->result[res_idx1][res_idx2]++;
|
||||
}
|
||||
else
|
||||
new.event.type = math_gauss_disti(LIVE_GAME_EVENT_POST, LIVE_GAME_EVENT_CROSS_BAR);
|
||||
|
@ -761,7 +827,7 @@ live_game_event_duel(void)
|
|||
|
||||
live_game_generate_commentary(&last_unit);
|
||||
if(show)
|
||||
treeview_live_game_show_game_unit(&last_unit);
|
||||
game_gui_live_game_show_unit(&last_unit);
|
||||
|
||||
if(last_unit.time != LIVE_GAME_UNIT_TIME_PENALTIES)
|
||||
live_game_event_general(TRUE);
|
||||
|
@ -972,7 +1038,7 @@ live_game_generate_commentary(LiveGameUnit *unit)
|
|||
|
||||
switch(unit->event.type)
|
||||
{
|
||||
default:
|
||||
case LIVE_GAME_EVENT_GENERAL:
|
||||
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",
|
||||
|
@ -1166,3 +1232,102 @@ live_game_create_stats(void)
|
|||
printf("inj.\t %d \t %d\n", stat->values[0][LIVE_GAME_STAT_VALUE_INJURIES],
|
||||
stat->values[1][LIVE_GAME_STAT_VALUE_INJURIES]);
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
/*d*/
|
||||
gint i;
|
||||
gint new_area = unit->area;
|
||||
gfloat rndom = math_rnd(0, 1);
|
||||
gfloat probs[4] =
|
||||
{CONSTANT_LIVE_GAME_AREA_DEF_MID *
|
||||
live_game_pit_teams(unit, CONSTANT_LIVE_GAME_AREA_DEF_MID_TEAM_EXPONENT),
|
||||
CONSTANT_LIVE_GAME_AREA_MID_ATT *
|
||||
live_game_pit_teams(unit, CONSTANT_LIVE_GAME_AREA_MID_TEAM_EXPONENT),
|
||||
CONSTANT_LIVE_GAME_AREA_MID_DEF /
|
||||
live_game_pit_teams(unit, CONSTANT_LIVE_GAME_AREA_MID_TEAM_EXPONENT),
|
||||
CONSTANT_LIVE_GAME_AREA_ATT_MID /
|
||||
live_game_pit_teams(unit, CONSTANT_LIVE_GAME_AREA_ATT_MID_TEAM_EXPONENT)};
|
||||
|
||||
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;
|
||||
|
||||
if(debug)
|
||||
printf("**** new area %d\n", new_area);
|
||||
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
|
||||
live_game_event_injury_get_player(void)
|
||||
{
|
||||
gint i, j;
|
||||
gfloat probs[22];
|
||||
gfloat rndom;
|
||||
|
||||
for(j=0;j<2;j++)
|
||||
{
|
||||
probs[j * 11] = CONSTANT_LIVE_GAME_INJURY_GOALIE_FACTOR *
|
||||
(gfloat)(100 - player_of(tm[j], 0)->fitness) *
|
||||
(player_of(tm[j], 0)->cskill != 0);
|
||||
for(i=1;i<11;i++)
|
||||
probs[i + j * 11] = probs[i + j * 11 - 1] +
|
||||
(gfloat)(100 - player_of(tm[j], i)->fitness) *
|
||||
(player_of(tm[j], i)->cskill != 0);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ void
|
|||
live_game_event_lost_possession(void);
|
||||
|
||||
void
|
||||
live_game_event_injury(gint player, gboolean create_new);
|
||||
live_game_event_injury(gint team, gint player, gboolean create_new);
|
||||
|
||||
void
|
||||
live_game_event_stadium(void);
|
||||
|
@ -55,11 +55,14 @@ live_game_event_penalty();
|
|||
void
|
||||
live_game_event_general(gboolean create_new);
|
||||
|
||||
void
|
||||
live_game_event_general_get_players(void);
|
||||
|
||||
void
|
||||
live_game_event_free_kick(void);
|
||||
|
||||
void
|
||||
live_game_event_send_off(gint player);
|
||||
live_game_event_send_off(gint team, gint player);
|
||||
|
||||
void
|
||||
live_game_generate_commentary(LiveGameUnit *unit);
|
||||
|
@ -79,4 +82,13 @@ live_game_unit_get_minute(const LiveGameUnit *unit);
|
|||
void
|
||||
live_game_create_stats(void);
|
||||
|
||||
gint
|
||||
live_game_get_area(const LiveGameUnit *unit);
|
||||
|
||||
gfloat
|
||||
live_game_pit_teams(const LiveGameUnit *unit, gfloat exponent);
|
||||
|
||||
void
|
||||
live_game_event_injury_get_player(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -97,6 +97,14 @@ enum LiveGameStatValue
|
|||
LIVE_GAME_STAT_VALUE_END
|
||||
};
|
||||
|
||||
enum LiveGameUnitArea
|
||||
{
|
||||
LIVE_GAME_UNIT_AREA_DEFEND = GAME_PLAYER_TYPE_DEFEND,
|
||||
LIVE_GAME_UNIT_AREA_MIDFIELD = GAME_PLAYER_TYPE_MIDFIELD,
|
||||
LIVE_GAME_UNIT_AREA_ATTACK = GAME_PLAYER_TYPE_ATTACK,
|
||||
LIVE_GAME_UNIT_AREA_END
|
||||
};
|
||||
|
||||
/** Some stats for a live game like ball possession,
|
||||
shots on goal etc. */
|
||||
typedef struct
|
||||
|
@ -124,9 +132,10 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
/** Tells us which of the teams is in possession
|
||||
of the ball and how long already. This is used
|
||||
to calculate the probability of a scoring chance. */
|
||||
gint possession, possession_time;
|
||||
of the ball. */
|
||||
gint possession;
|
||||
/** The area of the pitch the ball is currently in. */
|
||||
gint area;
|
||||
/** Which minute of the game and which part of
|
||||
the game. If 'minute' is -1 we have an event
|
||||
like a substitution that doesn't count as a
|
||||
|
|
|
@ -119,7 +119,6 @@ create_window_startup (void)
|
|||
label4 = gtk_label_new (_("Start in"));
|
||||
gtk_widget_show (label4);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), label4, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label4), GTK_JUSTIFY_LEFT);
|
||||
gtk_misc_set_alignment (GTK_MISC (label4), 0.05, 0.5);
|
||||
|
||||
eventbox1 = gtk_event_box_new ();
|
||||
|
@ -165,7 +164,6 @@ create_window_startup (void)
|
|||
label69 = gtk_label_new (_("Choose country"));
|
||||
gtk_widget_show (label69);
|
||||
gtk_box_pack_start (GTK_BOX (vbox34), label69, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label69), GTK_JUSTIFY_LEFT);
|
||||
gtk_misc_set_alignment (GTK_MISC (label69), 0.05, 0.5);
|
||||
gtk_misc_set_padding (GTK_MISC (label69), 0, 5);
|
||||
|
||||
|
@ -207,7 +205,6 @@ create_window_startup (void)
|
|||
label70 = gtk_label_new_with_mnemonic (_("Select a country file"));
|
||||
gtk_widget_show (label70);
|
||||
gtk_box_pack_start (GTK_BOX (hbox45), label70, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label70), GTK_JUSTIFY_LEFT);
|
||||
|
||||
hseparator12 = gtk_hseparator_new ();
|
||||
gtk_widget_show (hseparator12);
|
||||
|
@ -267,7 +264,6 @@ create_window_startup (void)
|
|||
label71 = gtk_label_new_with_mnemonic (_("Start Bygfoot Team Editor"));
|
||||
gtk_widget_show (label71);
|
||||
gtk_box_pack_start (GTK_BOX (hbox47), label71, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label71), GTK_JUSTIFY_LEFT);
|
||||
|
||||
hbox3 = gtk_hbox_new (FALSE, 0);
|
||||
gtk_widget_show (hbox3);
|
||||
|
@ -297,7 +293,6 @@ create_window_startup (void)
|
|||
label1 = gtk_label_new_with_mnemonic (_("OK"));
|
||||
gtk_widget_show (label1);
|
||||
gtk_box_pack_start (GTK_BOX (hbox4), label1, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT);
|
||||
|
||||
team_selection_cancel = gtk_button_new ();
|
||||
gtk_widget_show (team_selection_cancel);
|
||||
|
@ -323,7 +318,6 @@ create_window_startup (void)
|
|||
label2 = gtk_label_new_with_mnemonic (_("Cancel"));
|
||||
gtk_widget_show (label2);
|
||||
gtk_box_pack_start (GTK_BOX (hbox5), label2, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_LEFT);
|
||||
|
||||
team_selection_load = gtk_button_new ();
|
||||
gtk_widget_show (team_selection_load);
|
||||
|
@ -349,7 +343,6 @@ create_window_startup (void)
|
|||
label5 = gtk_label_new_with_mnemonic (_("Load game"));
|
||||
gtk_widget_show (label5);
|
||||
gtk_box_pack_start (GTK_BOX (hbox6), label5, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label5), GTK_JUSTIFY_LEFT);
|
||||
|
||||
g_signal_connect ((gpointer) window_startup, "delete_event",
|
||||
G_CALLBACK (on_team_selection_cancel_clicked),
|
||||
|
@ -502,7 +495,6 @@ create_popup_window (void)
|
|||
label_popup_status = gtk_label_new (_("-1"));
|
||||
gtk_widget_show (label_popup_status);
|
||||
gtk_box_pack_start (GTK_BOX (hbox16), label_popup_status, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label_popup_status), GTK_JUSTIFY_LEFT);
|
||||
gtk_misc_set_padding (GTK_MISC (label_popup_status), 29, 0);
|
||||
|
||||
vseparator12 = gtk_vseparator_new ();
|
||||
|
@ -512,7 +504,6 @@ create_popup_window (void)
|
|||
label_popup_status2 = gtk_label_new (_("-1"));
|
||||
gtk_widget_show (label_popup_status2);
|
||||
gtk_box_pack_start (GTK_BOX (hbox16), label_popup_status2, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label_popup_status2), GTK_JUSTIFY_LEFT);
|
||||
gtk_misc_set_padding (GTK_MISC (label_popup_status2), 22, 0);
|
||||
|
||||
vseparator13 = gtk_vseparator_new ();
|
||||
|
@ -522,7 +513,6 @@ create_popup_window (void)
|
|||
label_popup_status3 = gtk_label_new (_("-1"));
|
||||
gtk_widget_show (label_popup_status3);
|
||||
gtk_box_pack_start (GTK_BOX (hbox16), label_popup_status3, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label_popup_status3), GTK_JUSTIFY_LEFT);
|
||||
gtk_misc_set_padding (GTK_MISC (label_popup_status3), 23, 0);
|
||||
|
||||
hbox20 = gtk_hbox_new (FALSE, 0);
|
||||
|
@ -540,7 +530,6 @@ create_popup_window (void)
|
|||
label_popup_text = gtk_label_new (_("label23"));
|
||||
gtk_widget_show (label_popup_text);
|
||||
gtk_box_pack_start (GTK_BOX (vbox12), label_popup_text, FALSE, FALSE, 10);
|
||||
gtk_label_set_justify (GTK_LABEL (label_popup_text), GTK_JUSTIFY_LEFT);
|
||||
gtk_label_set_line_wrap (GTK_LABEL (label_popup_text), TRUE);
|
||||
gtk_misc_set_padding (GTK_MISC (label_popup_text), 0, 6);
|
||||
|
||||
|
@ -586,7 +575,6 @@ create_popup_window (void)
|
|||
label50 = gtk_label_new_with_mnemonic (_("OK"));
|
||||
gtk_widget_show (label50);
|
||||
gtk_box_pack_start (GTK_BOX (hbox30), label50, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label50), GTK_JUSTIFY_LEFT);
|
||||
|
||||
button_popup_cancel = gtk_button_new ();
|
||||
gtk_box_pack_start (GTK_BOX (hbox17), button_popup_cancel, TRUE, TRUE, 0);
|
||||
|
@ -611,7 +599,6 @@ create_popup_window (void)
|
|||
label51 = gtk_label_new_with_mnemonic (_("Cancel"));
|
||||
gtk_widget_show (label51);
|
||||
gtk_box_pack_start (GTK_BOX (hbox31), label51, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label51), GTK_JUSTIFY_LEFT);
|
||||
|
||||
button_popup_close = gtk_button_new ();
|
||||
gtk_box_pack_start (GTK_BOX (hbox17), button_popup_close, TRUE, TRUE, 0);
|
||||
|
@ -632,7 +619,6 @@ create_popup_window (void)
|
|||
label52 = gtk_label_new_with_mnemonic (_("Close"));
|
||||
gtk_widget_show (label52);
|
||||
gtk_box_pack_start (GTK_BOX (hbox32), label52, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label52), GTK_JUSTIFY_LEFT);
|
||||
|
||||
button8 = gtk_button_new_with_mnemonic (_("button8"));
|
||||
gtk_box_pack_start (GTK_BOX (hbox17), button8, TRUE, TRUE, 0);
|
||||
|
@ -720,6 +706,7 @@ create_fsel_window (void)
|
|||
fsel_window = gtk_file_selection_new (_("Choose file"));
|
||||
gtk_container_set_border_width (GTK_CONTAINER (fsel_window), 10);
|
||||
gtk_window_set_position (GTK_WINDOW (fsel_window), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_type_hint (GTK_WINDOW (fsel_window), GDK_WINDOW_TYPE_HINT_DIALOG);
|
||||
|
||||
button_fsel_ok = GTK_FILE_SELECTION (fsel_window)->ok_button;
|
||||
gtk_widget_show (button_fsel_ok);
|
||||
|
@ -770,6 +757,7 @@ create_font_sel_window (void)
|
|||
font_sel_window = gtk_font_selection_dialog_new (_("Select font"));
|
||||
gtk_container_set_border_width (GTK_CONTAINER (font_sel_window), 6);
|
||||
gtk_window_set_position (GTK_WINDOW (font_sel_window), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_type_hint (GTK_WINDOW (font_sel_window), GDK_WINDOW_TYPE_HINT_DIALOG);
|
||||
|
||||
button_font_sel_ok = GTK_FONT_SELECTION_DIALOG (font_sel_window)->ok_button;
|
||||
gtk_widget_show (button_font_sel_ok);
|
||||
|
@ -821,6 +809,7 @@ create_window_live (void)
|
|||
GtkWidget *vbox38;
|
||||
GtkWidget *scrolledwindow8;
|
||||
GtkWidget *treeview_result;
|
||||
GtkWidget *hscale_area;
|
||||
GtkWidget *scrolledwindow9;
|
||||
GtkWidget *treeview_commentary;
|
||||
GtkWidget *hbox48;
|
||||
|
@ -859,7 +848,7 @@ create_window_live (void)
|
|||
gtk_widget_show (hruler_live);
|
||||
gtk_box_pack_start (GTK_BOX (vbox36), hruler_live, FALSE, TRUE, 0);
|
||||
gtk_widget_set_sensitive (hruler_live, FALSE);
|
||||
gtk_ruler_set_range (GTK_RULER (hruler_live), 0, 120, 66.5753, 120);
|
||||
gtk_ruler_set_range (GTK_RULER (hruler_live), 0, 120, 41.3699, 120);
|
||||
|
||||
hbox50 = gtk_hbox_new (FALSE, 3);
|
||||
gtk_widget_show (hbox50);
|
||||
|
@ -880,6 +869,11 @@ create_window_live (void)
|
|||
gtk_container_add (GTK_CONTAINER (scrolledwindow8), treeview_result);
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview_result), FALSE);
|
||||
|
||||
hscale_area = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (5, 0, 10, 0, 0, 0)));
|
||||
gtk_widget_show (hscale_area);
|
||||
gtk_box_pack_start (GTK_BOX (vbox38), hscale_area, FALSE, TRUE, 0);
|
||||
gtk_scale_set_draw_value (GTK_SCALE (hscale_area), FALSE);
|
||||
|
||||
scrolledwindow9 = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolledwindow9);
|
||||
gtk_box_pack_start (GTK_BOX (vbox38), scrolledwindow9, TRUE, TRUE, 0);
|
||||
|
@ -916,7 +910,6 @@ create_window_live (void)
|
|||
label72 = gtk_label_new_with_mnemonic (_("Pause"));
|
||||
gtk_widget_show (label72);
|
||||
gtk_box_pack_start (GTK_BOX (hbox51), label72, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label72), GTK_JUSTIFY_LEFT);
|
||||
|
||||
button_resume = gtk_button_new ();
|
||||
gtk_box_pack_start (GTK_BOX (hbox48), button_resume, FALSE, FALSE, 0);
|
||||
|
@ -936,7 +929,6 @@ create_window_live (void)
|
|||
label73 = gtk_label_new_with_mnemonic (_("Resume"));
|
||||
gtk_widget_show (label73);
|
||||
gtk_box_pack_start (GTK_BOX (hbox52), label73, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label73), GTK_JUSTIFY_LEFT);
|
||||
|
||||
button_live_close = gtk_button_new_from_stock ("gtk-close");
|
||||
gtk_widget_show (button_live_close);
|
||||
|
@ -974,6 +966,7 @@ create_window_live (void)
|
|||
GLADE_HOOKUP_OBJECT (window_live, vbox38, "vbox38");
|
||||
GLADE_HOOKUP_OBJECT (window_live, scrolledwindow8, "scrolledwindow8");
|
||||
GLADE_HOOKUP_OBJECT (window_live, treeview_result, "treeview_result");
|
||||
GLADE_HOOKUP_OBJECT (window_live, hscale_area, "hscale_area");
|
||||
GLADE_HOOKUP_OBJECT (window_live, scrolledwindow9, "scrolledwindow9");
|
||||
GLADE_HOOKUP_OBJECT (window_live, treeview_commentary, "treeview_commentary");
|
||||
GLADE_HOOKUP_OBJECT (window_live, hbox48, "hbox48");
|
||||
|
@ -1066,7 +1059,6 @@ create_help_window (void)
|
|||
label59 = gtk_label_new_with_mnemonic (_("Close"));
|
||||
gtk_widget_show (label59);
|
||||
gtk_box_pack_start (GTK_BOX (hbox40), label59, FALSE, FALSE, 0);
|
||||
gtk_label_set_justify (GTK_LABEL (label59), GTK_JUSTIFY_LEFT);
|
||||
|
||||
g_signal_connect ((gpointer) button_help_close, "clicked",
|
||||
G_CALLBACK (on_button_help_close_clicked),
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
/** Kinda hard to explain.
|
||||
@see team_generate_players()
|
||||
@see player_generate() */
|
||||
#define CONSTANT_TEAM_SKILL_VARIANCE 0.2//0.075
|
||||
#define CONSTANT_TEAM_SKILL_VARIANCE 0.2//0.075/*d*/
|
||||
|
||||
/**
|
||||
Generate a team with default values, e.g.
|
||||
|
|
|
@ -457,33 +457,6 @@ treeview_show_user_player_list(gint player_list)
|
|||
player_list_attributes[(player_list != 1)], TRUE);
|
||||
}
|
||||
|
||||
/** Show a live game unit in the live game window.
|
||||
@param unit The unit we show. */
|
||||
void
|
||||
treeview_live_game_show_game_unit(const LiveGameUnit *unit)
|
||||
{
|
||||
GtkProgressBar *progress_bar;
|
||||
|
||||
if(live_game.window == NULL)
|
||||
{
|
||||
live_game.window = window_create(WINDOW_LIVE);
|
||||
treeview_live_game_show_initial_commentary(unit);
|
||||
}
|
||||
else
|
||||
treeview_live_game_show_commentary(unit);
|
||||
|
||||
treeview_live_game_show_result(unit);
|
||||
|
||||
progress_bar = GTK_PROGRESS_BAR(lookup_widget(live_game.window, "progressbar_live"));
|
||||
gtk_progress_bar_set_fraction(progress_bar, (gfloat)live_game_unit_get_minute(unit) / 120);
|
||||
usleep(500500 + options[OPT_LIVE_SPEED] * 50000);
|
||||
while(gtk_events_pending())
|
||||
gtk_main_iteration();
|
||||
|
||||
if(unit->event.type == LIVE_GAME_EVENT_END_MATCH)
|
||||
gtk_widget_set_sensitive(lookup_widget(live_game.window, "button_live_close"), TRUE);
|
||||
}
|
||||
|
||||
/** Show the commentary and the minute belonging to the unit.
|
||||
@param unit The #LiveGameUnit we show. */
|
||||
void
|
||||
|
|
|
@ -45,9 +45,6 @@ treeview_show_player_list(GtkTreeView *treeview, GPtrArray *players, PlayerListA
|
|||
void
|
||||
treeview_show_user_player_list(gint player_list);
|
||||
|
||||
void
|
||||
treeview_live_game_show_game_unit(const LiveGameUnit *unit);
|
||||
|
||||
void
|
||||
treeview_live_game_show_commentary(const LiveGameUnit *unit);
|
||||
|
||||
|
|
Loading…
Reference in New Issue