mirror of https://github.com/tstellar/bygfoot.git
Updated the default team implementation
This commit is contained in:
parent
474a1b9c72
commit
ca195b5e51
|
@ -55,22 +55,25 @@ callback_show_next_live_game(void)
|
|||
#endif
|
||||
|
||||
gint i, j;
|
||||
gint user_team_involved;
|
||||
|
||||
for(i=0;i<users->len;i++) {
|
||||
usr(i).counters[COUNT_USER_TOOK_TURN] = 0;
|
||||
// Store the player order before the live match this process is
|
||||
// repeated so check first if it hasn't been done yet
|
||||
if (usr(i).default_team->len==0 && option_int("int_opt_user_store_restore_default_team",
|
||||
&usr(i).options)) {
|
||||
store_default_team(&usr(i));
|
||||
}
|
||||
}
|
||||
|
||||
counters[COUNT_NEWS_SHOWN] =
|
||||
counters[COUNT_NEW_NEWS] = 0;
|
||||
|
||||
for(i=0;i<ligs->len;i++)
|
||||
for(j=0;j<lig(i).fixtures->len;j++)
|
||||
for(i=0;i<ligs->len;i++) {
|
||||
for(j=0;j<lig(i).fixtures->len;j++) {
|
||||
// Store the player order before the live match: get the team that is involved, if it's a user team
|
||||
// and that user has the option to always store the default team checked, store it
|
||||
user_team_involved = fixture_user_team_involved(&g_array_index(lig(i).fixtures, Fixture, j));
|
||||
if (user_team_involved!=-1 && option_int("int_opt_user_store_restore_default_team",
|
||||
&usr(user_team_involved).options)) {
|
||||
store_default_team(&usr(user_team_involved));
|
||||
}
|
||||
|
||||
if(g_array_index(lig(i).fixtures, Fixture, j).week_number == week &&
|
||||
g_array_index(lig(i).fixtures, Fixture, j).week_round_number == week_round &&
|
||||
fixture_user_team_involved(&g_array_index(lig(i).fixtures, Fixture, j)) != -1 &&
|
||||
|
@ -83,9 +86,20 @@ callback_show_next_live_game(void)
|
|||
&usr(fixture_user_team_involved(&g_array_index(lig(i).fixtures, Fixture, j))).live_game);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<acps->len;i++) {
|
||||
for(j=0;j<acp(i)->fixtures->len;j++) {
|
||||
// Store the player order before the live match: get the team that is involved, if it's a user team
|
||||
// and that user has the option to always store the default team checked, store it
|
||||
user_team_involved = fixture_user_team_involved(&g_array_index(acp(i)->fixtures, Fixture, j));
|
||||
|
||||
if (user_team_involved!=-1 && option_int("int_opt_user_store_restore_default_team",
|
||||
&usr(user_team_involved).options)) {
|
||||
store_default_team(&usr(user_team_involved));
|
||||
}
|
||||
|
||||
for(i=0;i<acps->len;i++)
|
||||
for(j=0;j<acp(i)->fixtures->len;j++)
|
||||
if(g_array_index(acp(i)->fixtures, Fixture, j).week_number == week &&
|
||||
g_array_index(acp(i)->fixtures, Fixture, j).week_round_number == week_round &&
|
||||
fixture_user_team_involved(&g_array_index(acp(i)->fixtures, Fixture, j)) != -1 &&
|
||||
|
@ -98,6 +112,8 @@ callback_show_next_live_game(void)
|
|||
&usr(fixture_user_team_involved(&g_array_index(acp(i)->fixtures, Fixture, j))).live_game);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window_destroy(&window.live);
|
||||
|
||||
|
|
|
@ -744,7 +744,7 @@ game_substitute_player(Team *tm, gint player_number)
|
|||
|
||||
substitute = ((Player*)g_ptr_array_index(substitutes, 0))->id;
|
||||
|
||||
player_swap(tm, player_number, tm, player_id_index(tm, substitute));
|
||||
player_swap(tm, player_number, tm, player_id_index(tm, substitute,TRUE));
|
||||
|
||||
g_ptr_array_free(substitutes, TRUE);
|
||||
|
||||
|
@ -894,8 +894,8 @@ game_substitute_player_send_off(gint clid, Team *tm, gint player_number,
|
|||
GINT_TO_POINTER(position));
|
||||
|
||||
*substitute = ((Player*)g_ptr_array_index(substitutes, 0))->id;
|
||||
player_swap(tm, player_id_index(tm, *to_substitute),
|
||||
tm, player_id_index(tm, *substitute));
|
||||
player_swap(tm, player_id_index(tm, *to_substitute, TRUE),
|
||||
tm, player_id_index(tm, *substitute, TRUE));
|
||||
|
||||
g_ptr_array_free(substitutes, TRUE);
|
||||
|
||||
|
@ -1235,7 +1235,7 @@ game_get_default_penalty_shooter(const Team *tm)
|
|||
&usr(team_is_user(tm)).options)) != NULL &&
|
||||
player_id_index(tm,
|
||||
option_int("int_opt_user_penalty_shooter",
|
||||
&usr(team_is_user(tm)).options)) < 11 &&
|
||||
&usr(team_is_user(tm)).options), TRUE) < 11 &&
|
||||
player_of_id_team(tm,
|
||||
option_int("int_opt_user_penalty_shooter",
|
||||
&usr(team_is_user(tm)).options))->cskill != 0)
|
||||
|
|
|
@ -552,7 +552,7 @@ live_game_event_injury(gint team, gint player, gboolean create_new)
|
|||
{
|
||||
sub_in = game_substitute_player(tms[last_unit.event.team],
|
||||
player_id_index(tms[last_unit.event.team],
|
||||
last_unit.event.player));
|
||||
last_unit.event.player, TRUE));
|
||||
if(sub_in != -1)
|
||||
{
|
||||
old_structure = tms[last_unit.event.team]->structure;
|
||||
|
@ -1008,7 +1008,7 @@ live_game_event_send_off(gint team, gint player, gboolean second_yellow)
|
|||
else if(tms[team]->players->len > 11)
|
||||
{
|
||||
game_substitute_player_send_off(match->fix->clid,
|
||||
tms[team], player_id_index(tms[team], player),
|
||||
tms[team], player_id_index(tms[team], player, TRUE),
|
||||
&to_substitute, &substitute);
|
||||
|
||||
if(to_substitute != -1)
|
||||
|
|
|
@ -84,7 +84,7 @@ misc2_callback_transfer_user_player(void)
|
|||
player_of_idx_team(new_team, new_team->players->len - 1)->wage =
|
||||
transoff(stat2, 0).wage;
|
||||
g_array_remove_index(current_user.tm->players,
|
||||
player_id_index(current_user.tm, trans(stat2).id));
|
||||
player_id_index(current_user.tm, trans(stat2).id, TRUE));
|
||||
transfer_remove_player(stat2);
|
||||
}
|
||||
else
|
||||
|
@ -104,7 +104,7 @@ misc2_callback_transfer_user_player(void)
|
|||
{
|
||||
current_user.money += transoff(stat2, 0).fee;
|
||||
current_user.money_in[1][MON_IN_TRANSFERS] += transoff(stat2, 0).fee;
|
||||
player_remove_from_team(current_user.tm, player_id_index(current_user.tm, trans(stat2).id));
|
||||
player_remove_from_team(current_user.tm, player_id_index(current_user.tm, trans(stat2).id, TRUE));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
23
src/player.c
23
src/player.c
|
@ -334,9 +334,10 @@ player_assign_wage(const Player *pl)
|
|||
his id.
|
||||
@param tm The team.
|
||||
@param player_id The player's id.
|
||||
@param stopWhenPlayerNotFound Should we stop when we don't find the player
|
||||
@return The array index or -1. */
|
||||
gint
|
||||
player_id_index(const Team *tm, gint player_id)
|
||||
player_id_index(const Team *tm, gint player_id, gboolean stopWhenPlayerNotFound)
|
||||
{
|
||||
gint i;
|
||||
|
||||
|
@ -344,9 +345,11 @@ player_id_index(const Team *tm, gint player_id)
|
|||
if(g_array_index(tm->players, Player, i).id == player_id)
|
||||
return i;
|
||||
|
||||
main_exit_program(EXIT_INT_NOT_FOUND,
|
||||
if (stopWhenPlayerNotFound) {
|
||||
main_exit_program(EXIT_INT_NOT_FOUND,
|
||||
"player_id_index: didn't find player with id %d of team %s\n",
|
||||
player_id, tm->name);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -480,13 +483,13 @@ player_compare_func(gconstpointer a, gconstpointer b, gpointer data)
|
|||
player_get_game_skill(pl2, FALSE, TRUE));
|
||||
else if(type == PLAYER_COMPARE_ATTRIBUTE_POS)
|
||||
{
|
||||
if(MIN(player_id_index(pl1->team, pl1->id),
|
||||
player_id_index(pl2->team, pl2->id)) < 11 &&
|
||||
MAX(player_id_index(pl1->team, pl1->id),
|
||||
player_id_index(pl2->team, pl2->id)) >= 11)
|
||||
if(MIN(player_id_index(pl1->team, pl1->id, TRUE),
|
||||
player_id_index(pl2->team, pl2->id, TRUE)) < 11 &&
|
||||
MAX(player_id_index(pl1->team, pl1->id, TRUE),
|
||||
player_id_index(pl2->team, pl2->id, TRUE)) >= 11)
|
||||
return_value =
|
||||
(player_id_index(pl1->team, pl1->id) >
|
||||
player_id_index(pl2->team, pl2->id)) ?
|
||||
(player_id_index(pl1->team, pl1->id, TRUE) >
|
||||
player_id_index(pl2->team, pl2->id, TRUE)) ?
|
||||
1 : -1;
|
||||
else if(pl1->cskill == 0)
|
||||
return_value = (pl2->cskill == 0) ? 0 : 1;
|
||||
|
@ -1265,7 +1268,7 @@ player_remove_contract(Player *pl)
|
|||
if(debug < 50)
|
||||
user_event_add(user_from_team(pl->team), EVENT_TYPE_PLAYER_LEFT, -1, -1, NULL,
|
||||
pl->name, NULL);
|
||||
player_remove_from_team(pl->team, player_id_index(pl->team, pl->id));
|
||||
player_remove_from_team(pl->team, player_id_index(pl->team, pl->id, TRUE));
|
||||
}
|
||||
|
||||
/** Remove a player from a team.
|
||||
|
@ -1347,7 +1350,7 @@ player_replace_by_new(Player *pl, gboolean free_player)
|
|||
#endif
|
||||
|
||||
Team *tm = pl->team;
|
||||
gint idx = player_id_index(tm, pl->id);
|
||||
gint idx = player_id_index(tm, pl->id, TRUE);
|
||||
Player new = player_new(tm, team_get_average_talent(tm), FALSE);
|
||||
|
||||
new.name = name_get(pl->team->names_file);
|
||||
|
|
|
@ -101,7 +101,7 @@ gboolean
|
|||
player_substitution_good_structure(gint old_structure, gint old_pos, gint player_pos);
|
||||
|
||||
gint
|
||||
player_id_index(const Team *tm, gint player_id);
|
||||
player_id_index(const Team *tm, gint player_id, gboolean stopWhenPlayerNotFound);
|
||||
|
||||
gfloat
|
||||
player_get_game_skill(const Player *pl, gboolean skill, gboolean special);
|
||||
|
|
|
@ -654,8 +654,8 @@ strategy_live_game_apply_action(LiveGame *match, gint team_idx,
|
|||
|
||||
if(sub_in_id > 0 && sub_out_id > 0)
|
||||
{
|
||||
player_swap(tm, player_id_index(tm, sub_out_id),
|
||||
tm, player_id_index(tm, sub_in_id));
|
||||
player_swap(tm, player_id_index(tm, sub_out_id, TRUE),
|
||||
tm, player_id_index(tm, sub_in_id, TRUE));
|
||||
|
||||
team_change_structure(tm, team_find_appropriate_structure(tm));
|
||||
team_rearrange(tm);
|
||||
|
|
12
src/user.c
12
src/user.c
|
@ -634,7 +634,7 @@ user_event_show_next(void)
|
|||
player_replace_by_new(player_of_id_team(event->user->tm, event->value1), TRUE);
|
||||
}
|
||||
else
|
||||
player_remove_from_team(event->user->tm, player_id_index(event->user->tm, event->value1));
|
||||
player_remove_from_team(event->user->tm, player_id_index(event->user->tm, event->value1, TRUE));
|
||||
treeview_show_user_player_list();
|
||||
game_gui_show_warning(buf,NULL);
|
||||
break;
|
||||
|
@ -1340,12 +1340,18 @@ restore_default_team(User *user)
|
|||
printf("restore_player_order\n");
|
||||
#endif
|
||||
|
||||
gint i, player1, player2;
|
||||
gint i, player1, player2, player1_index, player2_index;
|
||||
for (i=0;i<user->tm->players->len; i++){
|
||||
player1 = g_array_index(user->default_team, gint, i);
|
||||
player2 = g_array_index(user->tm->players, Player, i).id;
|
||||
if (player1 != player2) {
|
||||
player_swap(user->tm,player_id_index(user->tm,player1), user->tm, player_id_index(user->tm,player2));
|
||||
// We don't want to stop because a player has been romoved from your team
|
||||
player1_index = player_id_index(user->tm,player1, FALSE);
|
||||
player2_index = player_id_index(user->tm,player2, FALSE);
|
||||
if (player1_index==-1 || player2_index==-1) {
|
||||
return;
|
||||
}
|
||||
player_swap(user->tm,player1_index, user->tm, player2_index);
|
||||
}
|
||||
}
|
||||
team_change_structure(user->tm, user->default_structure);
|
||||
|
|
Loading…
Reference in New Issue