4
Bygfoot Football Manager -- a small and simple GTK2-based
5
football management game.
7
http://bygfoot.sourceforge.net
9
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
11
This program is free software; you can redistribute it and/or
12
modify it under the terms of the GNU General Public License
13
as published by the Free Software Foundation; either version 2
14
of the License, or (at your option) any later version.
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2
27
#include "finance.h"
3
28
#include "fixture.h"
39
64
style_factor = (gfloat)tm[i]->style * const_float("float_game_style_factor");
41
66
team_values[i][GAME_TEAM_VALUE_GOALIE] =
42
game_get_player_contribution(player_of_idx_team(tm[i], 0), FALSE) *
43
(1 + home_advantage * (i == 0)) *
44
(1 + const_float("float_player_boost_skill_effect") * tm[i]->boost);
67
game_get_player_contribution(player_of_idx_team(tm[i], 0), FALSE, TRUE) *
68
(1 + home_advantage * (i == 0));
48
team_values[i][GAME_TEAM_VALUE_ATTACK] +=
49
game_get_player_contribution(player_of_idx_team(tm[i], j), GAME_TEAM_VALUE_ATTACK);
50
team_values[i][GAME_TEAM_VALUE_MIDFIELD] +=
51
game_get_player_contribution(player_of_idx_team(tm[i], j), GAME_TEAM_VALUE_MIDFIELD);
52
team_values[i][GAME_TEAM_VALUE_DEFEND] +=
53
game_get_player_contribution(player_of_idx_team(tm[i], j), GAME_TEAM_VALUE_DEFEND);
71
if(player_of_idx_team(tm[i], j)->cskill > 0)
73
team_values[i][GAME_TEAM_VALUE_ATTACK] +=
74
game_get_player_contribution(player_of_idx_team(tm[i], j),
75
GAME_TEAM_VALUE_ATTACK, TRUE);
76
team_values[i][GAME_TEAM_VALUE_MIDFIELD] +=
77
game_get_player_contribution(player_of_idx_team(tm[i], j),
78
GAME_TEAM_VALUE_MIDFIELD, TRUE);
79
team_values[i][GAME_TEAM_VALUE_DEFEND] +=
80
game_get_player_contribution(player_of_idx_team(tm[i], j),
81
GAME_TEAM_VALUE_DEFEND, TRUE);
56
84
for(j=GAME_TEAM_VALUE_DEFEND;j<GAME_TEAM_VALUE_DEFEND + 3;j++)
57
85
team_values[i][j] *=
58
((1 + home_advantage * (i == 0)) *
59
(1 + const_float("float_player_boost_skill_effect") * tm[i]->boost));
86
((1 + home_advantage * (i == 0)));
61
88
team_values[i][GAME_TEAM_VALUE_DEFEND] *= (1 - style_factor);
62
89
team_values[i][GAME_TEAM_VALUE_ATTACK] *= (1 + style_factor);
66
93
/** Return the contribution of a player to the attack, midfield or defend.
67
94
@param pl The player.
68
95
@param type Whether we have defend, midfield or attack value.
96
@param special Whether to count special influence like boost and
69
98
@return The player's contribution depending on position and
72
game_get_player_contribution(const Player *pl, gint type)
101
game_get_player_contribution(const Player *pl, gint type, gboolean special)
74
103
/** How the cskill of field players get weighted for the team values in
75
104
a match. Rows are player position, columns value type.
85
114
const_float("float_player_team_weight_forward_midfield"),
86
115
const_float("float_player_team_weight_forward_attack")}};
88
return player_get_game_skill(pl, FALSE) *
89
player_weights[pl->cpos - 1][type - GAME_TEAM_VALUE_DEFEND] *
90
(1 + (gfloat)pl->streak * const_float("float_player_streak_influence_skill"));
117
return player_get_game_skill(pl, FALSE, special) *
118
player_weights[pl->cpos - 1][type - GAME_TEAM_VALUE_DEFEND];
93
121
/** Return a random attacking or defending player
130
158
else if(player_type == GAME_PLAYER_TYPE_PENALTY)
131
159
return game_get_penalty_taker(tm, last_penalty);
134
g_warning("game_get_player: unknown player type %d\n", player_type);
135
main_exit_program(EXIT_INT_NOT_FOUND, NULL);
161
main_exit_program(EXIT_INT_NOT_FOUND,
162
"game_get_player: unknown player type %d\n", player_type);
138
164
game_get_player_probs(tm->players, probs, weights, skills);
156
182
g_warning("game_get_player: All players injured or banned, apparently.\n");
157
printf("%s %s player list:\n", league_cup_get_name_string(tm->clid), tm->name);
183
g_print("%s %s player list:\n", league_cup_get_name_string(tm->clid), tm->name);
158
184
for(i=0;i<tm->players->len;i++)
161
printf("prob %.3f ", probs[i]);
162
printf("%d %20s health %d cskill %.2f\n", i, player_of_idx_team(tm, i)->name,
187
g_print("prob %.3f ", probs[i]);
188
g_print("%d %20s health %d cskill %.2f\n", i, player_of_idx_team(tm, i)->name,
163
189
player_of_idx_team(tm, i)->health, player_of_idx_team(tm, i)->cskill);
185
211
probs[0] = (skills) ?
186
player_get_game_skill(&g_array_index(players, Player, 1), FALSE) *
212
player_get_game_skill(&g_array_index(players, Player, 1), FALSE, TRUE) *
187
213
weights[g_array_index(players, Player, 1).cpos - 1] :
188
214
weights[g_array_index(players, Player, 1).cpos - 1] *
189
215
(g_array_index(players, Player, 1).cskill != 0);
197
223
probs[i] = probs[i - 1] +
199
player_get_game_skill(&g_array_index(players, Player, i + 1), FALSE) *
225
player_get_game_skill(&g_array_index(players, Player, i + 1), FALSE, TRUE) *
200
226
weights[g_array_index(players, Player, i + 1).cpos - 1] :
201
227
weights[g_array_index(players, Player, i + 1).cpos - 1] *
202
228
(g_array_index(players, Player, i + 1).cskill != 0));
643
670
if(g_array_index(tm->players, Player, i).cskill > 0)
644
671
g_ptr_array_add(substitutes, &g_array_index(tm->players, Player, i));
673
if(substitutes->len == 0)
675
g_ptr_array_free(substitutes, TRUE);
676
g_warning("game_substitute_player: no suitable substitutes found (all injured/banned?)");
646
680
g_ptr_array_sort_with_data(substitutes,
647
681
(GCompareDataFunc)player_compare_substitute_func,
648
682
GINT_TO_POINTER(player_of_idx_team(tm,
660
694
substitute = ((Player*)g_ptr_array_index(substitutes, 0))->id;
662
player_streak_add_to_prob(
663
&g_array_index(tm->players, Player, player_number),
664
const_float("float_player_streak_add_sub_out"));
666
player_streak_add_to_prob((Player*)g_ptr_array_index(substitutes, 0),
667
const_float("float_player_streak_add_sub_in"));
669
696
player_swap(tm, player_number, tm, player_id_index(tm, substitute));
671
698
g_ptr_array_free(substitutes, TRUE);
787
814
if(g_array_index(tm->players, Player, i).cskill > 0)
788
815
g_ptr_array_add(substitutes, player_of_idx_team(tm, i));
817
if(substitutes->len == 0)
819
g_ptr_array_free(substitutes, TRUE);
820
g_warning("game_substitute_player_send_off: no suitable substitutes found (all injured/banned?)");
790
825
if(num_forw == 0 && MAX(num_def, num_mid) > 2)
791
826
position = PLAYER_POS_FORWARD;
832
868
@param live_game_stats Pointer to the live game.
833
869
@param live_game_unit The live game unit. */
835
game_update_stats(gpointer live_game, gconstpointer live_game_unit)
871
game_update_stats(LiveGame *lg, const LiveGameUnit *unit)
838
LiveGameStats *stats = &((LiveGame*)live_game)->stats;
839
const LiveGameUnit *unit = (const LiveGameUnit*)live_game_unit;
874
LiveGameStats *stats = &lg->stats;
841
876
if(unit->minute != -1)
842
877
stats->values[unit->possession][LIVE_GAME_STAT_VALUE_POSSESSION]++;
861
896
if(unit->event.type == LIVE_GAME_EVENT_FOUL_YELLOW)
863
898
stats->values[unit->event.team][LIVE_GAME_STAT_VALUE_CARDS]++;
864
game_update_stats_player(live_game, live_game_unit);
899
game_update_stats_player(lg, unit);
867
902
else if(unit->event.type == LIVE_GAME_EVENT_SEND_OFF)
869
904
stats->values[unit->event.team][LIVE_GAME_STAT_VALUE_REDS]++;
870
game_update_stats_player(live_game, live_game_unit);
905
game_update_stats_player(lg, unit);
872
907
else if(unit->event.type == LIVE_GAME_EVENT_GOAL ||
873
908
unit->event.type == LIVE_GAME_EVENT_OWN_GOAL)
891
926
@param player The player id.
892
927
@param type The type of the stat. */
894
game_update_stats_player(gpointer live_game, gconstpointer live_game_unit)
929
game_update_stats_player(LiveGame *lg, const LiveGameUnit *unit)
897
932
gchar buf[SMALL], buf2[SMALL];
898
LiveGameStats *stats = &((LiveGame*)live_game)->stats;
899
const LiveGameUnit *unit = (const LiveGameUnit*)live_game_unit;
933
LiveGameStats *stats = &lg->stats;
900
934
gint minute = live_game_unit_get_minute(unit), array_index = -1;
901
935
gboolean own_goal;
902
936
gint team = unit->event.team,
903
937
player = unit->event.player,
904
938
player2 = unit->event.player2;
905
const Team *tm[2] = {((LiveGame*)live_game)->fix->teams[0],
906
((LiveGame*)live_game)->fix->teams[1]};
939
const Team *tm[2] = {lg->fix->teams[0],
907
941
GPtrArray *players = NULL;
909
943
if(unit->event.type == LIVE_GAME_EVENT_GOAL ||
1005
1034
teams = cup_get_teams_sorted(cup);
1007
1036
if(team_is_user((Team*)g_ptr_array_index(teams, 0)) != -1)
1008
1038
user_history_add(&usr(team_is_user((Team*)g_ptr_array_index(teams, 0))),
1009
USER_HISTORY_WIN_FINAL, ((Team*)g_ptr_array_index(teams, 0))->id,
1010
fix->clid, fix->round,((Team*)g_ptr_array_index(teams, 1))->name);
1039
USER_HISTORY_WIN_FINAL,
1040
((Team*)g_ptr_array_index(teams, 0))->name,
1041
league_cup_get_name_string(fix->clid),
1042
((Team*)g_ptr_array_index(teams, 1))->name, NULL);
1043
user_add_cup_success(&usr(team_is_user((Team*)g_ptr_array_index(teams, 0))),
1044
cup, fix->round, USER_HISTORY_WIN_FINAL);
1011
1046
else if(team_is_user((Team*)g_ptr_array_index(teams, 1)) != -1)
1012
1048
user_history_add(&usr(team_is_user((Team*)g_ptr_array_index(teams, 1))),
1013
USER_HISTORY_LOSE_FINAL, ((Team*)g_ptr_array_index(teams, 1))->id,
1014
fix->clid, fix->round,((Team*)g_ptr_array_index(teams, 0))->name);
1049
USER_HISTORY_LOSE_FINAL,
1050
((Team*)g_ptr_array_index(teams, 1))->name,
1051
league_cup_get_name_string(fix->clid),
1052
((Team*)g_ptr_array_index(teams, 0))->name, NULL);
1053
user_add_cup_success(&usr(team_is_user((Team*)g_ptr_array_index(teams, 1))),
1054
cup, fix->round, USER_HISTORY_LOSE_FINAL);
1015
1056
g_ptr_array_free(teams, TRUE);
1017
1058
else if(fixture_user_team_involved(fix) != -1)
1018
user_history_add(&usr(fixture_user_team_involved(fix)), USER_HISTORY_REACH_CUP_ROUND,
1019
usr(fixture_user_team_involved(fix)).team_id,
1020
fix->clid, fix->round, "");
1060
cup_get_round_name(cup_from_clid(fix->clid), fix->round, buf);
1061
sprintf(buf2, "%d", fix->round + 1);
1063
user_history_add(&usr(fixture_user_team_involved(fix)),
1064
USER_HISTORY_REACH_CUP_ROUND,
1065
usr(fixture_user_team_involved(fix)).tm->name,
1066
league_cup_get_name_string(fix->clid),
1068
user_add_cup_success(&usr(fixture_user_team_involved(fix)),
1069
cup, fix->round, USER_HISTORY_REACH_CUP_ROUND);
1023
1073
/** Reduce stadium capacity and safety after a stadium event.