2005-10-20 17:45:00 +02:00
|
|
|
/*
|
2005-11-26 17:52:51 +01:00
|
|
|
start_end.c
|
|
|
|
|
2005-10-20 17:45:00 +02:00
|
|
|
Bygfoot Football Manager -- a small and simple GTK2-based
|
|
|
|
football management game.
|
|
|
|
|
|
|
|
http://bygfoot.sourceforge.net
|
|
|
|
|
|
|
|
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2005-10-27 23:10:15 +02:00
|
|
|
#include "bet.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "cup.h"
|
2005-01-09 21:21:22 +01:00
|
|
|
#include "file.h"
|
2005-03-16 21:48:25 +01:00
|
|
|
#include "finance.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "fixture.h"
|
2005-04-13 15:01:59 +02:00
|
|
|
#include "free.h"
|
2005-03-16 21:48:25 +01:00
|
|
|
#include "game_gui.h"
|
2005-03-10 21:59:39 +01:00
|
|
|
#include "gui.h"
|
2005-12-01 12:50:54 +01:00
|
|
|
#include "job.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "league.h"
|
2005-03-03 13:46:48 +01:00
|
|
|
#include "live_game.h"
|
2005-04-07 18:44:33 +02:00
|
|
|
#include "load_save.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "main.h"
|
|
|
|
#include "maths.h"
|
2005-05-06 18:35:19 +02:00
|
|
|
#include "misc.h"
|
2005-06-01 20:19:02 +02:00
|
|
|
#include "name.h"
|
2005-04-06 00:10:18 +02:00
|
|
|
#include "option.h"
|
2006-01-10 22:26:51 +01:00
|
|
|
#include "player.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "start_end.h"
|
2005-04-29 21:48:02 +02:00
|
|
|
#include "stat.h"
|
2005-03-03 13:46:48 +01:00
|
|
|
#include "table.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "team.h"
|
|
|
|
#include "transfer.h"
|
2005-03-03 13:46:48 +01:00
|
|
|
#include "user.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "variables.h"
|
|
|
|
#include "xml_name.h"
|
2005-07-08 11:26:00 +02:00
|
|
|
#include "youth_academy.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
/** Prototype of a function called at the start or
|
|
|
|
end of a week round. */
|
|
|
|
typedef void(*WeekFunc)(void);
|
|
|
|
|
|
|
|
/** Array of functions called when a week round
|
|
|
|
is ended. */
|
|
|
|
WeekFunc end_week_round_funcs[] =
|
2005-04-13 15:01:59 +02:00
|
|
|
{end_week_round_results, end_week_round_sort_tables,
|
2005-03-03 13:46:48 +01:00
|
|
|
end_week_round_update_fixtures, NULL};
|
|
|
|
|
|
|
|
/** Array of functions called when a week round
|
|
|
|
is started. */
|
|
|
|
WeekFunc start_week_round_funcs[] =
|
2005-10-27 23:10:15 +02:00
|
|
|
{start_week_round_update_teams, bet_update, NULL};
|
2005-03-03 13:46:48 +01:00
|
|
|
|
|
|
|
/** Array of functions called when a week
|
|
|
|
is started. */
|
2005-03-16 21:48:25 +01:00
|
|
|
WeekFunc start_week_funcs[] =
|
2005-05-25 18:58:31 +02:00
|
|
|
{start_week_add_cups, start_week_update_users,
|
2005-10-24 22:50:48 +02:00
|
|
|
start_week_update_teams, start_week_update_user_finances,
|
2005-12-01 12:50:54 +01:00
|
|
|
youth_academy_update_weekly, transfer_update, job_update, NULL};
|
2005-03-13 16:46:15 +01:00
|
|
|
|
2005-05-25 19:58:04 +02:00
|
|
|
WeekFunc end_week_funcs[] = {stat_update_leagues, end_week_hide_cups, NULL};
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2004-12-30 17:48:19 +01:00
|
|
|
/** Generate the teams etc. */
|
|
|
|
void
|
|
|
|
start_new_game(void)
|
|
|
|
{
|
2005-01-09 21:21:22 +01:00
|
|
|
start_write_variables();
|
2005-10-24 22:50:48 +02:00
|
|
|
|
2004-12-30 17:48:19 +01:00
|
|
|
start_generate_league_teams();
|
|
|
|
start_new_season();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Make new fixtures, nullify things etc. */
|
|
|
|
void
|
|
|
|
start_new_season(void)
|
|
|
|
{
|
2005-06-23 17:37:44 +02:00
|
|
|
gint i, j;
|
2005-12-01 12:50:54 +01:00
|
|
|
gchar buf[SMALL];
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-04-10 18:34:27 +02:00
|
|
|
week = week_round = 1;
|
2005-06-23 17:37:44 +02:00
|
|
|
free_names(TRUE);
|
|
|
|
stat5 = STATUS_GENERATE_TEAMS;
|
|
|
|
|
|
|
|
for(i = acps->len - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
g_ptr_array_free(acp(i)->team_names, TRUE);
|
|
|
|
acp(i)->team_names = g_ptr_array_new();
|
|
|
|
|
|
|
|
if(acp(i)->add_week > 0)
|
|
|
|
g_ptr_array_remove_index(acps, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=cps->len - 1; i >= 0; i--)
|
|
|
|
if(cp(i).add_week == -1)
|
|
|
|
{
|
|
|
|
cup_reset(&cp(i));
|
|
|
|
fixture_write_cup_fixtures(&cp(i));
|
|
|
|
}
|
2005-04-10 18:34:27 +02:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(season > 1)
|
2005-04-15 15:55:59 +02:00
|
|
|
{
|
2005-04-22 17:17:39 +02:00
|
|
|
for(i=0;i<users->len;i++)
|
2005-12-01 12:50:54 +01:00
|
|
|
{
|
|
|
|
sprintf(buf, "%d", team_get_league_rank(usr(i).tm));
|
2005-04-22 17:17:39 +02:00
|
|
|
user_history_add(&usr(i), USER_HISTORY_END_SEASON,
|
2005-12-01 12:50:54 +01:00
|
|
|
usr(i).tm->name,
|
|
|
|
league_cup_get_name_string(usr(i).tm->clid),
|
|
|
|
buf, NULL);
|
|
|
|
}
|
2005-04-22 17:17:39 +02:00
|
|
|
|
2005-06-23 11:22:37 +02:00
|
|
|
start_new_season_league_changes();
|
2005-04-13 15:01:59 +02:00
|
|
|
|
2005-04-15 15:55:59 +02:00
|
|
|
for(i=0;i<users->len;i++)
|
2005-05-02 16:39:30 +02:00
|
|
|
{
|
2005-04-15 15:55:59 +02:00
|
|
|
usr(i).tm = team_of_id(usr(i).team_id);
|
2005-07-08 11:26:00 +02:00
|
|
|
|
|
|
|
usr(i).youth_academy.tm = usr(i).tm;
|
|
|
|
for(j=0;j<usr(i).youth_academy.players->len;j++)
|
2006-01-10 22:26:51 +01:00
|
|
|
{
|
2005-07-08 11:26:00 +02:00
|
|
|
g_array_index(usr(i).youth_academy.players, Player, j).team = usr(i).tm;
|
2006-01-10 22:26:51 +01:00
|
|
|
player_season_start(
|
|
|
|
&g_array_index(usr(i).youth_academy.players, Player, j), 0);
|
|
|
|
}
|
2005-07-08 11:26:00 +02:00
|
|
|
|
2005-05-02 16:39:30 +02:00
|
|
|
live_game_reset(&usr(i).live_game, NULL, TRUE);
|
|
|
|
}
|
2006-01-10 22:26:51 +01:00
|
|
|
|
|
|
|
start_new_season_reset_ids();
|
2005-04-15 15:55:59 +02:00
|
|
|
}
|
2005-05-06 18:35:19 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for(i=0;i<cps->len;i++)
|
2005-06-23 17:37:44 +02:00
|
|
|
if(cp(i).add_week <= 0)
|
2005-05-06 18:35:19 +02:00
|
|
|
g_ptr_array_add(acps, &cp(i));
|
|
|
|
}
|
|
|
|
|
2005-05-28 17:13:40 +02:00
|
|
|
for(i=0;i<ligs->len;i++)
|
2005-09-19 23:13:36 +02:00
|
|
|
if(lig(i).active)
|
|
|
|
fixture_write_league_fixtures(&lig(i));
|
2005-05-28 17:13:40 +02:00
|
|
|
|
2005-05-06 18:35:19 +02:00
|
|
|
for(i=cps->len - 1; i >= 0; i--)
|
2005-12-01 12:50:54 +01:00
|
|
|
{
|
2005-06-23 23:53:57 +02:00
|
|
|
if(cp(i).add_week >= 0)
|
2005-06-23 17:37:44 +02:00
|
|
|
{
|
|
|
|
cup_reset(&cp(i));
|
2005-06-23 23:53:57 +02:00
|
|
|
|
|
|
|
if(cp(i).add_week == 0)
|
|
|
|
fixture_write_cup_fixtures(&cp(i));
|
2005-06-23 17:37:44 +02:00
|
|
|
}
|
|
|
|
else if(cp(i).add_week == -1)
|
|
|
|
{
|
|
|
|
for(j=0;j<cp(i).fixtures->len;j++)
|
|
|
|
{
|
|
|
|
g_array_index(cp(i).fixtures, Fixture, j).teams[0] =
|
|
|
|
team_of_id(g_array_index(cp(i).fixtures, Fixture, j).team_ids[0]);
|
|
|
|
g_array_index(cp(i).fixtures, Fixture, j).teams[1] =
|
|
|
|
team_of_id(g_array_index(cp(i).fixtures, Fixture, j).team_ids[1]);
|
|
|
|
}
|
|
|
|
}
|
2005-12-01 12:50:54 +01:00
|
|
|
}
|
2005-06-23 17:37:44 +02:00
|
|
|
|
2005-06-01 20:19:02 +02:00
|
|
|
stat5 = -1;
|
2005-04-24 12:17:20 +02:00
|
|
|
|
2005-06-01 20:19:02 +02:00
|
|
|
for(i=0;i<name_lists->len;i++)
|
|
|
|
name_shorten_list(&nli(i));
|
2005-10-27 23:10:15 +02:00
|
|
|
|
|
|
|
if(season == 1)
|
|
|
|
bet_update();
|
2004-12-30 17:48:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Fill some global variables with default values at the
|
|
|
|
beginning of a new game. */
|
|
|
|
void
|
|
|
|
start_write_variables(void)
|
|
|
|
{
|
2005-01-09 21:21:22 +01:00
|
|
|
gint i;
|
|
|
|
|
2005-04-10 18:34:27 +02:00
|
|
|
season = 1;
|
2005-03-18 23:03:23 +01:00
|
|
|
cur_user = 0;
|
2005-04-10 13:13:19 +02:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
for(i=0;i<users->len;i++)
|
|
|
|
file_load_user_conf_file(&usr(i));
|
2004-12-30 17:48:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Generate the teams in the leagues. */
|
|
|
|
void
|
|
|
|
start_generate_league_teams(void)
|
|
|
|
{
|
|
|
|
gint i, j;
|
|
|
|
|
2005-06-01 20:19:02 +02:00
|
|
|
stat5 = STATUS_GENERATE_TEAMS;
|
|
|
|
|
2004-12-30 17:48:19 +01:00
|
|
|
if(ligs->len == 0)
|
2005-01-09 21:21:22 +01:00
|
|
|
main_exit_program(EXIT_NO_LEAGUES,
|
2005-10-24 22:50:48 +02:00
|
|
|
"start_generate_league_teams: no leagues found. There must be at least one league in the game.\n");
|
2004-12-30 17:48:19 +01:00
|
|
|
|
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
for(j=0;j<lig(i).teams->len;j++)
|
2005-12-01 12:50:54 +01:00
|
|
|
team_generate_players_stadium(&g_array_index(lig(i).teams, Team, j), 0);
|
2005-06-01 20:19:02 +02:00
|
|
|
|
|
|
|
stat5 = -1;
|
2004-12-30 17:48:19 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 22:26:51 +01:00
|
|
|
/** Reset the cup and league ids to the smallest possible
|
|
|
|
value to avoid an overflow (gotta admit, the id system
|
|
|
|
isn't perfect). */
|
|
|
|
void
|
|
|
|
start_new_season_reset_ids(void)
|
|
|
|
{
|
|
|
|
gint i, max;
|
|
|
|
|
|
|
|
max = -1;
|
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
if(lig(i).id > max)
|
|
|
|
max = lig(i).id;
|
|
|
|
|
|
|
|
counters[COUNT_LEAGUE_ID] = max + 1;
|
|
|
|
|
|
|
|
max = -1;
|
|
|
|
for(i=0;i<cps->len;i++)
|
|
|
|
if(cp(i).id > max)
|
|
|
|
max = cp(i).id;
|
|
|
|
|
|
|
|
counters[COUNT_CUP_ID] = max + 1;
|
|
|
|
}
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
/** End a week round. */
|
|
|
|
void
|
|
|
|
end_week_round(void)
|
|
|
|
{
|
2006-01-07 21:01:03 +01:00
|
|
|
gint i = 0;
|
2005-03-03 13:46:48 +01:00
|
|
|
gboolean new_week = TRUE;
|
|
|
|
WeekFunc *end_func = end_week_round_funcs;
|
|
|
|
|
2005-06-04 12:28:49 +02:00
|
|
|
if(debug > 100)
|
2005-12-14 15:05:59 +01:00
|
|
|
g_print("End w %d r %d \n", week, week_round);
|
2005-06-04 12:28:49 +02:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
while(*end_func != NULL)
|
|
|
|
{
|
|
|
|
(*end_func)();
|
|
|
|
end_func++;
|
|
|
|
}
|
|
|
|
|
|
|
|
week_round++;
|
|
|
|
|
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
if(query_fixture_in_week_round(lig(i).id, week, week_round))
|
|
|
|
{
|
|
|
|
new_week = FALSE;
|
|
|
|
break;
|
2004-12-30 17:48:19 +01:00
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-04-14 21:07:25 +02:00
|
|
|
for(i=0;i<acps->len;i++)
|
|
|
|
if(query_fixture_in_week_round(acp(i)->id, week, week_round))
|
2005-03-03 13:46:48 +01:00
|
|
|
{
|
|
|
|
new_week = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(new_week)
|
|
|
|
{
|
2005-04-29 21:48:02 +02:00
|
|
|
end_week();
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
if(query_start_end_season_end())
|
|
|
|
{
|
2005-05-01 12:16:14 +02:00
|
|
|
end_season();
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
season++;
|
|
|
|
week = 1;
|
2005-05-01 12:16:14 +02:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
start_new_season();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
week++;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
week_round = 1;
|
2005-03-03 13:46:48 +01:00
|
|
|
start_week();
|
|
|
|
}
|
|
|
|
|
|
|
|
start_week_round();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate the match results of a week round. */
|
|
|
|
void
|
|
|
|
end_week_round_results(void)
|
|
|
|
{
|
2005-03-14 18:47:27 +01:00
|
|
|
gint i, j, done = 0;
|
|
|
|
gchar buf[SMALL], buf2[SMALL];
|
|
|
|
gfloat num_matches =
|
|
|
|
(gfloat)fixture_get_number_of_matches(week, week_round);
|
2005-04-09 21:18:28 +02:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
for(i=0;i<ligs->len;i++)
|
2005-11-02 22:04:19 +01:00
|
|
|
{
|
2005-06-04 12:28:49 +02:00
|
|
|
for(j=0;j<lig(i).fixtures->len;j++)
|
|
|
|
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 &&
|
|
|
|
g_array_index(lig(i).fixtures, Fixture, j).attendance == -1)
|
|
|
|
{
|
|
|
|
live_game_calculate_fixture(&g_array_index(lig(i).fixtures, Fixture, j));
|
|
|
|
|
|
|
|
done++;
|
2006-01-07 21:01:03 +01:00
|
|
|
fixture_result_to_buf(&g_array_index(lig(i).fixtures, Fixture, j),
|
|
|
|
buf, FALSE);
|
2005-06-04 12:28:49 +02:00
|
|
|
sprintf(buf2, "%s %s %s",
|
2005-10-09 11:35:44 +02:00
|
|
|
g_array_index(lig(i).fixtures, Fixture, j).teams[0]->name,
|
2005-06-04 12:28:49 +02:00
|
|
|
buf,
|
2005-10-09 11:35:44 +02:00
|
|
|
g_array_index(lig(i).fixtures, Fixture, j).teams[1]->name);
|
2005-11-02 22:04:19 +01:00
|
|
|
gui_show_progress((gfloat)done / num_matches, buf2,
|
|
|
|
PIC_TYPE_MATCHPIC);
|
|
|
|
|
2005-06-04 12:28:49 +02:00
|
|
|
if(debug > 120)
|
2005-12-14 15:05:59 +01:00
|
|
|
g_print("%s \n", buf2);
|
2005-06-04 12:28:49 +02:00
|
|
|
}
|
2005-11-02 22:04:19 +01:00
|
|
|
}
|
2005-04-13 15:01:59 +02:00
|
|
|
|
2005-04-14 21:07:25 +02:00
|
|
|
for(i=0;i<acps->len;i++)
|
2005-05-21 11:18:25 +02:00
|
|
|
for(j=0;j<acp(i)->fixtures->len;j++)
|
2005-04-13 15:01:59 +02:00
|
|
|
{
|
2005-05-21 11:18:25 +02:00
|
|
|
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 &&
|
|
|
|
g_array_index(acp(i)->fixtures, Fixture, j).attendance == -1)
|
2005-04-13 15:01:59 +02:00
|
|
|
{
|
2005-05-21 11:18:25 +02:00
|
|
|
live_game_calculate_fixture(&g_array_index(acp(i)->fixtures, Fixture, j));
|
|
|
|
|
|
|
|
done++;
|
2006-01-07 21:01:03 +01:00
|
|
|
fixture_result_to_buf(&g_array_index(acp(i)->fixtures, Fixture, j),
|
|
|
|
buf, FALSE);
|
2005-05-21 11:18:25 +02:00
|
|
|
sprintf(buf2, "%s %s %s",
|
2005-10-09 11:35:44 +02:00
|
|
|
g_array_index(acp(i)->fixtures, Fixture, j).teams[0]->name,
|
2005-05-21 11:18:25 +02:00
|
|
|
buf,
|
2005-10-09 11:35:44 +02:00
|
|
|
g_array_index(acp(i)->fixtures, Fixture, j).teams[1]->name);
|
2005-11-02 22:04:19 +01:00
|
|
|
gui_show_progress((gfloat)done / num_matches, buf2,
|
|
|
|
PIC_TYPE_MATCHPIC);
|
2005-06-04 12:28:49 +02:00
|
|
|
if(debug > 120)
|
2005-12-14 15:05:59 +01:00
|
|
|
g_print("%s \n", buf2);
|
2005-04-13 15:01:59 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-13 22:10:19 +01:00
|
|
|
|
2005-11-02 22:04:19 +01:00
|
|
|
gui_show_progress(-1, "", PIC_TYPE_MATCHPIC);
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort league and cup tables. */
|
|
|
|
void
|
|
|
|
end_week_round_sort_tables(void)
|
|
|
|
{
|
2005-05-02 16:39:30 +02:00
|
|
|
gint i, j, k;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
if(query_fixture_in_week_round(lig(i).id, week, week_round))
|
2005-05-02 16:39:30 +02:00
|
|
|
{
|
|
|
|
for(j=0;j<lig(i).table.elements->len;j++)
|
|
|
|
g_array_index(lig(i).table.elements, TableElement, j).old_rank = j;
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
g_array_sort_with_data(lig(i).table.elements,
|
|
|
|
(GCompareDataFunc)table_element_compare_func,
|
|
|
|
GINT_TO_POINTER(lig(i).id));
|
2005-05-02 16:39:30 +02:00
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-04-14 21:07:25 +02:00
|
|
|
for(i=0;i<acps->len;i++)
|
2005-04-22 17:17:39 +02:00
|
|
|
if(query_fixture_in_week_round(acp(i)->id, week, week_round) &&
|
2005-04-14 21:07:25 +02:00
|
|
|
g_array_index(acp(i)->fixtures, Fixture, acp(i)->fixtures->len - 1).round ==
|
2005-04-22 17:17:39 +02:00
|
|
|
cup_has_tables(acp(i)->id))
|
|
|
|
for(j=0;j<cup_get_last_tables(acp(i)->id)->len;j++)
|
2005-05-02 16:39:30 +02:00
|
|
|
{
|
|
|
|
for(k=0;k<g_array_index(cup_get_last_tables(acp(i)->id), Table, j).elements->len;k++)
|
2006-01-07 21:01:03 +01:00
|
|
|
g_array_index(
|
|
|
|
g_array_index(cup_get_last_tables(acp(i)->id), Table, j).elements,
|
|
|
|
TableElement, k).old_rank = k;
|
2005-05-02 16:39:30 +02:00
|
|
|
|
2005-04-22 17:17:39 +02:00
|
|
|
g_array_sort_with_data(
|
|
|
|
g_array_index(cup_get_last_tables(acp(i)->id), Table, j).elements,
|
|
|
|
(GCompareDataFunc)table_element_compare_func,
|
|
|
|
GINT_TO_POINTER(acp(i)->id));
|
2005-05-02 16:39:30 +02:00
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Update cup fixtures. */
|
|
|
|
void
|
|
|
|
end_week_round_update_fixtures(void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2005-04-14 21:07:25 +02:00
|
|
|
for(i=0;i<acps->len;i++)
|
|
|
|
if(acp(i)->next_fixture_update_week == week &&
|
|
|
|
acp(i)->next_fixture_update_week_round == week_round)
|
|
|
|
fixture_update(acp(i));
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
for(i=0;i<ligs->len;i++)
|
2006-05-07 18:32:52 +02:00
|
|
|
if(lig(i).active && week ==
|
|
|
|
g_array_index(
|
2005-09-19 23:13:36 +02:00
|
|
|
lig(i).fixtures, Fixture, lig(i).fixtures->len - 1).week_number &&
|
|
|
|
week_round == 1 &&
|
2005-05-06 18:35:19 +02:00
|
|
|
team_is_user(g_array_index(lig(i).table.elements, TableElement, 0).team) != -1)
|
2005-04-22 17:17:39 +02:00
|
|
|
user_history_add(&usr(team_is_user(g_array_index(lig(i).table.elements, TableElement, 0).team)),
|
2005-12-01 12:50:54 +01:00
|
|
|
USER_HISTORY_CHAMPION,
|
|
|
|
g_array_index(lig(i).table.elements,
|
|
|
|
TableElement, 0).team->name,
|
|
|
|
league_cup_get_name_string(lig(i).id),
|
|
|
|
NULL, NULL);
|
2005-05-18 18:00:49 +02:00
|
|
|
|
2005-05-06 18:35:19 +02:00
|
|
|
for(i=0;i<cps->len;i++)
|
2005-09-27 14:18:46 +02:00
|
|
|
{
|
2005-06-03 09:45:09 +02:00
|
|
|
if(cp(i).add_week == 1000 &&
|
|
|
|
cp(i).fixtures->len == 0 &&
|
|
|
|
query_cup_begins(&cp(i)))
|
2005-05-06 18:35:19 +02:00
|
|
|
{
|
|
|
|
cp(i).last_week = cup_get_last_week_from_first(&cp(i), week + 1);
|
|
|
|
fixture_write_cup_fixtures(&cp(i));
|
|
|
|
g_ptr_array_add(acps, &cp(i));
|
2005-04-14 21:07:25 +02:00
|
|
|
}
|
2005-09-27 14:18:46 +02:00
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Start a new week round. */
|
|
|
|
void
|
|
|
|
start_week_round(void)
|
|
|
|
{
|
|
|
|
WeekFunc *start_func = start_week_round_funcs;
|
|
|
|
|
2005-06-04 12:28:49 +02:00
|
|
|
if(debug > 100)
|
2005-12-14 15:05:59 +01:00
|
|
|
g_print("Start w %d r %d \n", week, week_round);
|
2005-06-04 12:28:49 +02:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
while(*start_func != NULL)
|
|
|
|
{
|
|
|
|
(*start_func)();
|
|
|
|
start_func++;
|
|
|
|
}
|
2005-03-13 16:46:15 +01:00
|
|
|
|
2005-05-21 11:18:25 +02:00
|
|
|
if(!query_start_end_season_end() &&
|
|
|
|
opt_int("int_opt_skip") &&
|
|
|
|
!query_user_games_this_week_round() &&
|
2005-04-15 15:55:59 +02:00
|
|
|
((week_round == 1 &&
|
|
|
|
!query_user_games_in_week_round(week - 1, fixture_get_last_week_round(week - 1))) ||
|
|
|
|
(week_round > 1 &&
|
|
|
|
!query_user_games_in_week_round(week, week_round - 1))))
|
2005-03-16 21:48:25 +01:00
|
|
|
end_week_round();
|
2005-03-18 23:03:23 +01:00
|
|
|
else
|
|
|
|
{
|
2005-04-14 21:07:25 +02:00
|
|
|
cur_user = 0;
|
|
|
|
game_gui_show_main();
|
|
|
|
|
2005-05-28 16:34:14 +02:00
|
|
|
user_event_show_next();
|
2005-03-18 23:03:23 +01:00
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Start a new week. */
|
|
|
|
void
|
|
|
|
start_week(void)
|
|
|
|
{
|
|
|
|
WeekFunc *start_func = start_week_funcs;
|
|
|
|
|
|
|
|
while(*start_func != NULL)
|
|
|
|
{
|
|
|
|
(*start_func)();
|
|
|
|
start_func++;
|
|
|
|
}
|
2004-12-30 17:48:19 +01:00
|
|
|
}
|
2005-03-13 16:46:15 +01:00
|
|
|
|
2005-04-29 21:48:02 +02:00
|
|
|
/** Finish a week. */
|
|
|
|
void
|
|
|
|
end_week(void)
|
|
|
|
{
|
|
|
|
WeekFunc *end_func = end_week_funcs;
|
|
|
|
|
|
|
|
while(*end_func != NULL)
|
|
|
|
{
|
|
|
|
(*end_func)();
|
|
|
|
end_func++;
|
|
|
|
}
|
2005-05-09 19:06:11 +02:00
|
|
|
|
2005-06-04 12:28:49 +02:00
|
|
|
if(debug > 150)
|
2005-05-09 19:06:11 +02:00
|
|
|
stat_show_av_league_goals();
|
2005-04-29 21:48:02 +02:00
|
|
|
}
|
|
|
|
|
2005-05-25 19:58:04 +02:00
|
|
|
/** Hide some not-so-important cups that
|
|
|
|
are already finished. */
|
|
|
|
void
|
|
|
|
end_week_hide_cups(void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for(i=acps->len - 1; i >= 0; i--)
|
|
|
|
if(query_cup_hide(acp(i)->id) &&
|
|
|
|
g_array_index(acp(i)->fixtures, Fixture, acp(i)->fixtures->len - 1).attendance > 0)
|
|
|
|
g_ptr_array_remove_index(acps, i);
|
|
|
|
}
|
|
|
|
|
2005-05-06 18:35:19 +02:00
|
|
|
/** Add the cups that begin later in the season to the acps array. */
|
|
|
|
void
|
|
|
|
start_week_add_cups(void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for(i=0;i<cps->len;i++)
|
|
|
|
if(cp(i).add_week == week)
|
|
|
|
{
|
|
|
|
g_ptr_array_add(acps, &cp(i));
|
2007-02-23 10:16:02 +01:00
|
|
|
fixture_write_cup_fixtures(&cp(i));
|
2005-05-06 18:35:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-14 10:29:39 +01:00
|
|
|
/** Age increase etc. of players.
|
2005-03-13 16:46:15 +01:00
|
|
|
CPU teams get updated at the end of their matches
|
|
|
|
(to avoid cup teams getting updated too often). */
|
|
|
|
void
|
2005-10-24 22:50:48 +02:00
|
|
|
start_week_update_teams(void)
|
2005-03-13 16:46:15 +01:00
|
|
|
{
|
2005-10-24 22:50:48 +02:00
|
|
|
gint i, j;
|
2005-03-13 16:46:15 +01:00
|
|
|
|
2005-10-24 22:50:48 +02:00
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
for(j=0;j<lig(i).teams->len;j++)
|
|
|
|
team_update_team_weekly(&g_array_index(lig(i).teams, Team, j));
|
|
|
|
|
|
|
|
for(i=0;i<cps->len;i++)
|
|
|
|
for(j=0;j<cp(i).teams->len;j++)
|
|
|
|
team_update_team_weekly((Team*)g_ptr_array_index(cp(i).teams, j));
|
2005-03-13 16:46:15 +01:00
|
|
|
}
|
2005-03-14 10:29:39 +01:00
|
|
|
|
|
|
|
/** Do some things at the beginning of each new round for
|
|
|
|
the user teams. */
|
|
|
|
void
|
2005-10-24 22:50:48 +02:00
|
|
|
start_week_round_update_teams(void)
|
2005-03-14 10:29:39 +01:00
|
|
|
{
|
2005-10-24 22:50:48 +02:00
|
|
|
gint i, j;
|
2005-03-14 10:29:39 +01:00
|
|
|
|
2005-10-24 22:50:48 +02:00
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
for(j=0;j<lig(i).teams->len;j++)
|
|
|
|
team_update_team_week_roundly(&g_array_index(lig(i).teams, Team, j));
|
|
|
|
|
|
|
|
for(i=0;i<cps->len;i++)
|
|
|
|
for(j=0;j<cp(i).teams->len;j++)
|
|
|
|
team_update_team_week_roundly((Team*)g_ptr_array_index(cp(i).teams, j));
|
2005-03-14 10:29:39 +01:00
|
|
|
}
|
2005-03-16 21:48:25 +01:00
|
|
|
|
|
|
|
/** Deduce wages etc. */
|
|
|
|
void
|
|
|
|
start_week_update_user_finances(void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2005-09-19 23:13:36 +02:00
|
|
|
if(sett_int("int_opt_disable_finances"))
|
|
|
|
return;
|
|
|
|
|
2005-03-16 21:48:25 +01:00
|
|
|
for(i=0;i<users->len;i++)
|
|
|
|
finance_update_user_weekly(&usr(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Some general user update. */
|
|
|
|
void
|
|
|
|
start_week_update_users(void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for(i=0;i<users->len;i++)
|
|
|
|
{
|
|
|
|
if(usr(i).scout >= 100)
|
|
|
|
usr(i).scout = math_get_place(usr(i).scout, 2);
|
|
|
|
|
|
|
|
if(usr(i).physio >= 100)
|
|
|
|
usr(i).physio = math_get_place(usr(i).physio, 2);
|
2005-03-17 21:26:01 +01:00
|
|
|
|
2005-07-08 11:26:00 +02:00
|
|
|
if(usr(i).youth_academy.coach >= 100)
|
|
|
|
usr(i).youth_academy.coach = math_get_place(usr(i).youth_academy.coach, 2);
|
|
|
|
|
2005-03-17 21:26:01 +01:00
|
|
|
user_weekly_update_counters(&usr(i));
|
2005-03-16 21:48:25 +01:00
|
|
|
}
|
|
|
|
}
|
2005-04-07 18:44:33 +02:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
/** Check whether the season has ended. */
|
|
|
|
gboolean
|
|
|
|
query_start_end_season_end(void)
|
|
|
|
{
|
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
for(j=0;j<lig(i).fixtures->len;j++)
|
2005-05-21 11:18:25 +02:00
|
|
|
if(g_array_index(lig(i).fixtures, Fixture, j).week_number > week - 1)
|
2005-04-13 15:01:59 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2005-04-14 21:07:25 +02:00
|
|
|
for(i=0;i<acps->len;i++)
|
|
|
|
for(j=0;j<acp(i)->fixtures->len;j++)
|
2005-05-21 11:18:25 +02:00
|
|
|
if(g_array_index(acp(i)->fixtures, Fixture, j).week_number > week - 1)
|
2005-04-13 15:01:59 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Manage promotions and relegations at the beginning of a new season. */
|
2005-04-07 18:44:33 +02:00
|
|
|
void
|
2005-06-23 11:22:37 +02:00
|
|
|
start_new_season_league_changes(void)
|
2005-04-07 18:44:33 +02:00
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
gint i, j, k;
|
2005-08-14 21:03:11 +02:00
|
|
|
gint league_size[ligs->len];
|
2005-04-13 15:01:59 +02:00
|
|
|
GArray *team_movements = g_array_new(FALSE, FALSE, sizeof(TeamMove));
|
|
|
|
|
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
league_get_team_movements(&lig(i), team_movements);
|
|
|
|
|
2005-08-14 21:03:11 +02:00
|
|
|
for(i=0;i<ligs->len;i++)
|
|
|
|
league_size[i] = lig(i).teams->len;
|
|
|
|
|
2005-06-25 16:09:37 +02:00
|
|
|
for(i=0;i<team_movements->len;i++)
|
2005-08-14 21:03:11 +02:00
|
|
|
league_remove_team_with_id(
|
|
|
|
league_from_clid(g_array_index(team_movements, TeamMove, i).tm.clid),
|
|
|
|
g_array_index(team_movements, TeamMove, i).tm.id);
|
|
|
|
|
|
|
|
league_team_movements_destinations(team_movements, league_size);
|
2005-06-25 16:09:37 +02:00
|
|
|
|
2005-06-23 11:22:37 +02:00
|
|
|
for(i = team_movements->len - 1; i >= 0; i--)
|
2005-12-01 12:50:54 +01:00
|
|
|
if(g_array_index(team_movements, TeamMove, i).prom_rel_type ==
|
|
|
|
PROM_REL_RELEGATION)
|
2005-08-14 21:03:11 +02:00
|
|
|
g_array_prepend_val(
|
|
|
|
lig(g_array_index(
|
2005-12-01 12:50:54 +01:00
|
|
|
g_array_index(team_movements, TeamMove, i).dest_idcs,
|
|
|
|
gint, 0)).teams,
|
2005-08-14 21:03:11 +02:00
|
|
|
g_array_index(team_movements, TeamMove, i).tm);
|
2005-06-22 17:07:34 +02:00
|
|
|
|
2005-06-23 11:22:37 +02:00
|
|
|
for(i=1;i<team_movements->len;i++)
|
2005-12-01 12:50:54 +01:00
|
|
|
if(g_array_index(team_movements, TeamMove, i).prom_rel_type !=
|
|
|
|
PROM_REL_RELEGATION)
|
2005-08-14 21:03:11 +02:00
|
|
|
g_array_append_val(
|
|
|
|
lig(g_array_index(
|
2005-12-01 12:50:54 +01:00
|
|
|
g_array_index(team_movements, TeamMove, i).dest_idcs,
|
|
|
|
gint, 0)).teams,
|
2005-08-14 21:03:11 +02:00
|
|
|
g_array_index(team_movements, TeamMove, i).tm);
|
2005-06-23 11:22:37 +02:00
|
|
|
|
2005-08-14 21:03:11 +02:00
|
|
|
for(i=0;i<team_movements->len;i++)
|
|
|
|
g_array_free(g_array_index(team_movements, TeamMove, i).dest_idcs, TRUE);
|
2005-04-13 15:01:59 +02:00
|
|
|
g_array_free(team_movements, TRUE);
|
2005-04-14 21:07:25 +02:00
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
for(i=0;i<ligs->len;i++)
|
2005-06-23 11:22:37 +02:00
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
for(j=0;j<lig(i).teams->len;j++)
|
|
|
|
{
|
|
|
|
g_array_index(lig(i).teams, Team, j).clid = lig(i).id;
|
|
|
|
for(k=0;k<g_array_index(lig(i).teams, Team, j).players->len;k++)
|
2005-12-01 12:50:54 +01:00
|
|
|
g_array_index(g_array_index(lig(i).teams, Team, j).players,
|
|
|
|
Player, k).team =
|
2005-04-13 15:01:59 +02:00
|
|
|
&g_array_index(lig(i).teams, Team, j);
|
|
|
|
}
|
2005-06-23 11:22:37 +02:00
|
|
|
|
|
|
|
league_season_start(&lig(i));
|
|
|
|
}
|
2005-04-07 18:44:33 +02:00
|
|
|
}
|
2005-05-01 12:16:14 +02:00
|
|
|
|
2005-08-14 21:03:11 +02:00
|
|
|
|
2005-05-01 12:16:14 +02:00
|
|
|
/** End a season (store stats etc.) */
|
|
|
|
void
|
|
|
|
end_season(void)
|
|
|
|
{
|
|
|
|
stat_create_season_stat();
|
|
|
|
}
|