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.
3
28
#include "fixture.h"
217
241
for(i=0;i<cup_round->choose_teams->len;i++)
218
242
if(g_array_index(cup_round->choose_teams, CupChooseTeam, i).generate)
219
cup_load_choose_team_generate(cup, cup_round,
220
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
243
cup_load_choose_team_generate(
245
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
222
cup_load_choose_team(cup, teams,
223
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
247
cup_load_choose_team(
249
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
225
251
if(cup_round->teams->len > 0)
226
252
while(teams->len + cup_round->teams->len > cup_round->new_teams)
232
258
for(i=0;i<cup_round->teams->len;i++)
234
team_generate_players_stadium(&g_array_index(cup_round->teams, Team, i));
260
team_generate_players_stadium(&g_array_index(cup_round->teams, Team, i), 0);
235
261
g_ptr_array_add(cup->teams, &g_array_index(cup_round->teams, Team, i));
236
262
g_ptr_array_add(teams, &g_array_index(cup_round->teams, Team, i));
240
266
for(i=0;i<teams->len;i++)
241
printf("cup_get_team_pointers: %d %s \n", i, ((Team*)g_ptr_array_index(teams, i))->name);
267
g_print("cup_get_team_pointers: %d %s (%d) %s\n", i,
268
((Team*)g_ptr_array_index(teams, i))->name,
269
((Team*)g_ptr_array_index(teams, i))->clid,
244
273
/** Get the pointers to the teams (already generated, in one of the leagues or cups)
316
345
if(ct->number_of_teams != -1 &&
317
346
number_of_teams != ct->number_of_teams)
319
g_warning("cup_load_choose_team (1): not enough teams (that don't participate in international cups yet) found in chooseteam %s for cup %s (%d specified, %d found) cup group %d.\n ",
320
ct->sid, cup->name, ct->number_of_teams, number_of_teams, cup->group);
321
main_exit_program(EXIT_CHOOSE_TEAM_ERROR, NULL);
347
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
348
"cup_load_choose_team (1): not enough teams (that don't participate in international cups yet) found in chooseteam %s for cup %s (%d specified, %d found) cup group %d.\n ",
349
ct->sid, cup->name, ct->number_of_teams,
350
number_of_teams, cup->group);
326
354
if(season == 1 && cup->add_week == 0)
328
356
if(lig(0).teams->len < ct->number_of_teams)
330
g_warning("cup_load_choose_team: not enough teams in league 0 for chooseteam %s (%d; required: %d) in cup %s\n",
331
ct->sid, lig(0).teams->len, ct->number_of_teams, cup->name);
332
main_exit_program(EXIT_CHOOSE_TEAM_ERROR, NULL);
357
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
358
"cup_load_choose_team: not enough teams in league 0 for chooseteam %s (%d; required: %d) in cup %s\n",
359
ct->sid, lig(0).teams->len,
360
ct->number_of_teams, cup->name);
335
362
gint permutation[lig(0).teams->len];
336
363
math_generate_permutation(permutation, 0, lig(0).teams->len - 1);
356
383
if(number_of_teams != ct->number_of_teams)
358
g_warning("cup_load_choose_team (2): not enough teams found in league 0 for chooseteam %s (%d; required: %d) in cup %s (group %d)\n",
359
ct->sid, number_of_teams, ct->number_of_teams, cup->name, cup->group);
360
main_exit_program(EXIT_CHOOSE_TEAM_ERROR, NULL);
384
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
385
"cup_load_choose_team (2): not enough teams found in league 0 for chooseteam %s (%d; required: %d) in cup %s (group %d)\n",
386
ct->sid, number_of_teams,
387
ct->number_of_teams, cup->name, cup->group);
395
421
if(ct->number_of_teams != -1 &&
396
422
number_of_teams != ct->number_of_teams)
398
g_warning("cup_load_choose_team(3): not enough teams (that don't participate in international cups yet) found in chooseteam %s for cup %s (%d specified, %d found) cup group %d.\n ",
399
ct->sid, cup->name, ct->number_of_teams, number_of_teams, cup->group);
400
main_exit_program(EXIT_CHOOSE_TEAM_ERROR, NULL);
423
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
424
"cup_load_choose_team(3): not enough teams (that don't participate in international cups yet) found in chooseteam %s for cup %s (%d specified, %d found) cup group %d.\n ",
426
ct->number_of_teams, number_of_teams, cup->group);
406
431
for(i=debug_num;i<teams->len;i++)
407
printf("cup_load_choose_team: %d %s \n", i, ((Team*)g_ptr_array_index(teams, i))->name);
432
g_print("cup_load_choose_team: %d %s \n", i, ((Team*)g_ptr_array_index(teams, i))->name);
410
435
/** Load the teams specified in the chooseteam from a non-country league. */
472
497
if(teams_local->len < end_idx)
474
g_warning("cup_load_choose_team_generate: not enough teams (%d) in chooseteam %s in cup %s (%d are specified) \n",
475
teams_local->len, ct->sid, cup->name, end_idx);
477
499
free_teams_array(&teams_local, FALSE);
478
main_exit_program(EXIT_CHOOSE_TEAM_ERROR, NULL);
500
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
501
"cup_load_choose_team_generate: not enough teams (%d) in chooseteam %s in cup %s (%d are specified) \n",
502
teams_local->len, ct->sid,
481
506
for(j = 0; j < end_idx; j++)
497
522
if(((ct->number_of_teams != -1 && number_of_teams != ct->number_of_teams) ||
498
523
(ct->number_of_teams == -1 && number_of_teams != teams_local->len)) &&
499
524
teams_local->len > 0)
501
g_warning("cup_load_choose_team_generate: not enough teams (that don't participate in international cups yet) found in chooseteam %s for cup %s (%d specified, %d found).\n ", ct->sid, cup->name, ct->number_of_teams, number_of_teams);
502
main_exit_program(EXIT_CHOOSE_TEAM_ERROR, NULL);
525
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
526
"cup_load_choose_team_generate: not enough teams (that don't participate in international cups yet) found in chooseteam %s for cup %s (%d specified, %d found).\n ",
528
ct->number_of_teams, number_of_teams);
505
530
for(j=teams_local->len - 1; j>=0;j--)
506
531
if(query_team_is_in_cup(&g_array_index(teams_local, Team, j), cup))
507
532
g_array_remove_index(teams_local, j);
668
693
cup_get_matchdays_in_cup_round(cup, cup_round) * cup->week_gap;
670
695
if(week_number <= 0)
672
g_warning("cup_get_first_week_of_cup_round: first week of cup %s cup round %d is not positive (%d).\nPlease lower the week gap or set a later last week.\n", cup->name, cup_round, week_number);
673
main_exit_program(EXIT_FIRST_WEEK_ERROR, NULL);
696
main_exit_program(EXIT_FIRST_WEEK_ERROR,
697
"cup_get_first_week_of_cup_round: first week of cup %s cup round %d is not positive (%d).\nPlease lower the week gap or set a later last week.\n",
698
cup->name, cup_round, week_number);
676
700
return week_number;
703
727
if(cup_round->round_robin_number_of_groups > 0)
705
729
number_of_teams = cup_round_get_number_of_teams(cup, round);
730
number_of_teams += cup_round->round_robin_number_of_groups - 1;
731
number_of_teams /= cup_round->round_robin_number_of_groups;
732
/* Now, number_of_teams = number of teams in largest group */
733
if (number_of_teams % 2 == 0)
734
number_of_matchdays = number_of_teams - 1;
736
number_of_matchdays = number_of_teams;
707
if(number_of_teams % cup_round->round_robin_number_of_groups == 0)
708
number_of_matchdays =
709
((number_of_teams / cup_round->round_robin_number_of_groups) - 1) * 2;
711
number_of_matchdays =
713
(number_of_teams % cup_round->round_robin_number_of_groups)) /
714
cup_round->round_robin_number_of_groups) * 2;
738
if (g_array_index(cup->rounds, CupRound, round).home_away)
739
number_of_matchdays *= 2;
716
741
else if(g_array_index(cup->rounds, CupRound, round).home_away)
717
742
number_of_matchdays = 2;
950
973
query_cup_begins(const Cup *cup)
953
976
const League *league = NULL;
954
977
const Cup *cup_temp = NULL;
955
gboolean proceed = FALSE;
956
const CupRound *cup_round = &g_array_index(cup->rounds, CupRound, 0);
958
for(i=0;i<cup_round->choose_teams->len;i++)
959
if(!g_array_index(cup_round->choose_teams,CupChooseTeam, i).generate)
962
cup_get_choose_team_league_cup(
963
&g_array_index(cup_round->choose_teams,
964
CupChooseTeam, i), &league, &cup_temp);
966
if((cup_temp == NULL &&
968
(g_array_index(league->fixtures, Fixture,
969
league->fixtures->len - 1).week_number == week &&
970
g_array_index(league->fixtures, Fixture,
971
league->fixtures->len - 1).week_round_number == week_round))) ||
973
(cup_temp->fixtures->len > 0 &&
974
g_array_index(cup_temp->fixtures, Fixture,
975
cup_temp->fixtures->len - 1).week_number == week &&
976
g_array_index(cup_temp->fixtures, Fixture,
977
cup_temp->fixtures->len - 1).week_round_number == week_round)))
984
for(i=0;i<cup_round->choose_teams->len;i++)
985
if(!g_array_index(cup_round->choose_teams,CupChooseTeam, i).generate)
987
cup_get_choose_team_league_cup(
988
&g_array_index(cup_round->choose_teams,
989
CupChooseTeam, i), &league, &cup_temp);
990
if((cup_temp == NULL &&
992
g_array_index(league->fixtures, Fixture,
993
league->fixtures->len - 1).attendance == -1)) ||
995
(cup_temp->fixtures->len == 0 ||
996
(cup_temp->fixtures->len > 0 &&
997
g_array_index(cup_temp->fixtures, Fixture,
998
cup_temp->fixtures->len - 1).attendance == -1))))
978
const CupRound *cup_round = NULL;
980
for(j=0;j<cup->rounds->len;j++)
982
cup_round = &g_array_index(cup->rounds, CupRound, j);
984
for(i=0;i<cup_round->choose_teams->len;i++)
985
if(!g_array_index(cup_round->choose_teams,CupChooseTeam, i).generate)
987
cup_get_choose_team_league_cup(
988
&g_array_index(cup_round->choose_teams,
989
CupChooseTeam, i), &league, &cup_temp);
991
if((cup_temp == NULL &&
993
g_array_index(league->fixtures, Fixture,
994
league->fixtures->len - 1).attendance == -1) ||
996
((cup_temp->fixtures->len > 0 &&
997
g_array_index(cup_temp->fixtures, Fixture,
998
cup_temp->fixtures->len - 1).attendance == -1) ||
999
cup_temp->fixtures->len == 0)))