1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-02-20 21:40:45 +01:00

Fixed the horses problem.

This commit is contained in:
gyboth 2009-01-11 14:51:12 +00:00
parent 760bd79239
commit 9d67ab30bd
10 changed files with 116 additions and 63 deletions

View File

@ -277,7 +277,7 @@ cup_get_choose_team_league_cup(const CupChooseTeam *ct,
cup round. If necessary, teams are generated and stored in the teams
array of the cup round. */
void
cup_get_team_pointers(Cup *cup, gint round, gboolean preload)
cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, gboolean preload)
{
#ifdef DEBUG
printf("cup_get_team_pointers\n");
@ -301,7 +301,7 @@ cup_get_team_pointers(Cup *cup, gint round, gboolean preload)
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
else
cup_load_choose_team(
cup, teams,
cup, teams, teams_sorted,
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
}
@ -330,7 +330,7 @@ cup_get_team_pointers(Cup *cup, gint round, gboolean preload)
/** Get the pointers to the teams (already generated, in one of the leagues or cups)
specified in the chooseteam. Add them to the 'teams' pointer array. */
void
cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct)
cup_load_choose_team(Cup *cup, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct)
{
#ifdef DEBUG
printf("cup_load_choose_team\n");
@ -350,7 +350,7 @@ cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct)
if(cup_temp == NULL)
cup_load_choose_team_from_league(cup, league, teams, ct);
else
cup_load_choose_team_from_cup(cup, cup_temp, teams, ct);
cup_load_choose_team_from_cup(cup, cup_temp, teams, teams_sorted, ct);
if(debug > 80)
for(i=debug_num;i<teams->len;i++)
@ -358,7 +358,7 @@ cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct)
}
void
cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, const CupChooseTeam *ct)
cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct)
{
#ifdef DEBUG
printf("cup_load_choose_team_from_cup\n");
@ -410,7 +410,10 @@ cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, c
}
else
{
cup_teams_sorted = cup_get_teams_sorted(cup_temp);
/* Self-referential cup or no? */
cup_teams_sorted = (cup == cup_temp) ?
teams_sorted :
cup_get_teams_sorted(cup_temp);
if(ct->number_of_teams == -1)
{
@ -439,7 +442,8 @@ cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, c
}
}
g_ptr_array_free(cup_teams_sorted, TRUE);
if(cup != cup_temp)
g_ptr_array_free(cup_teams_sorted, TRUE);
if(ct->number_of_teams != -1 &&
number_of_teams != ct->number_of_teams)
@ -1303,3 +1307,32 @@ cup_round_check_waits(const CupRound *cup_round)
return FALSE;
}
/** Find out whether the cup chooses teams from itself
(e.g. the defending champion from last season). */
gboolean
query_cup_self_referential(const Cup *cup)
{
gint i, j;
for(i = 0; i < cup->rounds->len; i++)
for(j = 0; j < g_array_index(cup->rounds, CupRound, i).choose_teams->len; j++)
if(strcmp(g_array_index(g_array_index(cup->rounds, CupRound, i).choose_teams, CupChooseTeam, j).sid, cup->sid) == 0)
return TRUE;
return FALSE;
}
/** Find out if the cup is part of the array of
cups that are displayed in the game. */
gboolean
query_cup_hidden(const Cup *cup)
{
gint i;
for(i = 0; i < acps->len; i++)
if(acp(i) == cup)
return FALSE;
return TRUE;
}

View File

@ -47,20 +47,21 @@ void
cup_reset(Cup *cup);
void
cup_get_team_pointers(Cup *cup, gint round, gboolean preload);
cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, gboolean preload);
void
cup_load_choose_team_generate(Cup *cup, CupRound *cup_round, const CupChooseTeam *ct);
void
cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct);
cup_load_choose_team(Cup *cup, GPtrArray *teams, GPtrArray *teams_sorted, const CupChooseTeam *ct);
void
cup_load_choose_team_from_league(Cup *cup, const League *league,
GPtrArray *teams, const CupChooseTeam *ct);
void
cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_team, GPtrArray *teams, const CupChooseTeam *ct);
cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_team, GPtrArray *teams,
GPtrArray *teams_sorted, const CupChooseTeam *ct);
gint
cup_get_first_week_of_cup_round(Cup *cup, gint cup_round, gboolean with_delay);
@ -132,4 +133,10 @@ cup_check_fixtures(const Cup *cup);
gboolean
cup_round_check_waits(const CupRound *cup_round);
gboolean
query_cup_self_referential(const Cup *cup);
gboolean
query_cup_hidden(const Cup *cup);
#endif

View File

@ -112,9 +112,20 @@ fixture_write_cup_fixtures(Cup *cup)
#endif
gint i;
GPtrArray *teams_sorted = NULL;
/* Store the order of teams in case the cup
uses teams from its previous incarnation (previous season). */
if(query_cup_self_referential(cup))
teams_sorted = cup_get_teams_sorted(cup);
cup_reset(cup);
for(i=0;i<cup->rounds->len;i++)
cup_get_team_pointers(cup, i, TRUE);
cup_get_team_pointers(cup, i, teams_sorted, TRUE);
if(teams_sorted != NULL)
g_ptr_array_free(teams_sorted, TRUE);
if(g_array_index(cup->rounds, CupRound, 0).round_robin_number_of_groups > 0)
fixture_write_cup_round_robin(
@ -175,7 +186,7 @@ fixture_update(Cup *cup)
}
new_round = &g_array_index(cup->rounds, CupRound, round + 1);
cup_get_team_pointers(cup, round + 1, FALSE);
cup_get_team_pointers(cup, round + 1, NULL, FALSE);
for(i=0;i<new_round->team_ptrs->len;i++)
g_ptr_array_add(teams, g_ptr_array_index(new_round->team_ptrs, i));
@ -547,8 +558,8 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
}
/* Special rule for cups that have to wait for other cups. */
if(cup_round != -1 && first_week < week + 1)
first_week = week + 1;
if(cup_round != -1 && first_week < week)
first_week = week;
/* first half of fixtures */
week_number = league_cup_get_week_with_break(clid, first_week);
@ -1798,3 +1809,16 @@ fixture_get_cup_round_name(const Fixture *fix, gchar *buf)
strcat(buf, _(" -- Replay matches"));
}
/* Reset the team pointers from the team ids in the fixtures. */
void
fixture_refresh_team_pointers(GArray *fixtures)
{
gint i, j;
for(i = 0; i < fixtures->len; i++)
{
for(j = 0; j < 2; j++)
g_array_index(fixtures, Fixture, i).teams[j] =
team_of_id(g_array_index(fixtures, Fixture, i).team_ids[j]);
}
}

View File

@ -174,4 +174,7 @@ fixtures_condense(GArray *fixtures);
void
fixture_get_cup_round_name(const Fixture *fix, gchar *buf);
void
fixture_refresh_team_pointers(GArray *fixtures);
#endif

View File

@ -132,10 +132,7 @@ start_new_season(void)
/* Deal with cups that have to take place before promotion/relegation. */
for(i=cps->len - 1; i >= 0; i--)
if(cp(i).add_week == -1)
{
cup_reset(&cp(i));
fixture_write_cup_fixtures(&cp(i));
}
if(season > 1)
{
@ -181,25 +178,12 @@ start_new_season(void)
needed for the international cups. */
for(i=cps->len - 1; i >= 0; i--)
{
if(cp(i).add_week >= 0)
{
cup_reset(&cp(i));
if(cp(i).add_week == 0)
fixture_write_cup_fixtures(&cp(i));
}
if(cp(i).add_week == 0)
fixture_write_cup_fixtures(&cp(i));
/* Reset team pointers using the stored ids
(pointers might have changed because of prom/rel). */
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]);
}
}
fixture_refresh_team_pointers(cp(i).fixtures);
}
for(i = acps->len - 1; i >= 0; i--)
@ -513,7 +497,7 @@ end_week_round_update_fixtures(void)
for(i=0;i<cps->len;i++)
{
if(cp(i).add_week == 1000 &&
cp(i).fixtures->len == 0 &&
query_cup_hidden(&cp(i)) &&
query_cup_begins(&cp(i)))
{
cp(i).last_week = cup_get_last_week_from_first(&cp(i), week + 1);

View File

@ -27,6 +27,7 @@
#include "league.h"
#include "misc.h"
#include "table.h"
#include "team.h"
#include "variables.h"
/** Return a newly allocated empty table. */
@ -317,3 +318,14 @@ table_copy(const Table *table)
return new_table;
}
/** Refresh the team pointers in the table from the team ids. */
void
table_refresh_team_pointers(Table *table)
{
gint i;
for(i = 0; i < table->elements->len; i++)
g_array_index(table->elements, TableElement, i).team =
team_of_id(g_array_index(table->elements, TableElement, i).team_id);
}

View File

@ -53,5 +53,8 @@ query_tables_in_country(void);
Table
table_copy(const Table *table);
void
table_refresh_team_pointers(Table *table);
#endif

View File

@ -215,21 +215,16 @@ xml_loadsave_leagues_cups_adjust_team_ptrs(void)
for(i = 0; i < ligs->len; i++)
{
for(j = 0; j < lig(i).fixtures->len; j++)
{
for(k = 0; k < 2; k++)
g_array_index(lig(i).fixtures, Fixture, j).teams[k] =
team_of_id(g_array_index(lig(i).fixtures, Fixture, j).team_ids[k]);
}
fixture_refresh_team_pointers(lig(i).fixtures);
for(j = 0; j < lig(i).tables->len; j++)
for(k = 0; k < g_array_index(lig(i).tables, Table, j).elements->len; k++)
g_array_index(g_array_index(lig(i).tables, Table, j).elements, TableElement, k).team =
team_of_id(g_array_index(g_array_index(lig(i).tables, Table, j).elements, TableElement, k).team_id);
table_refresh_team_pointers(&g_array_index(lig(i).tables, Table, j));
}
for(i = 0; i < cps->len; i++)
{
fixture_refresh_team_pointers(cp(i).fixtures);
for(j = 0; j < cp(i).rounds->len; j++)
{
team_ptrs = g_ptr_array_new();
@ -240,15 +235,7 @@ xml_loadsave_leagues_cups_adjust_team_ptrs(void)
g_array_index(cp(i).rounds, CupRound, j).team_ptrs = team_ptrs;
for(k = 0; k < g_array_index(cp(i).rounds, CupRound, j).tables->len; k++)
for(l = 0; l < g_array_index(g_array_index(cp(i).rounds, CupRound, j).tables, Table, k).elements->len; l++)
g_array_index(g_array_index(g_array_index(cp(i).rounds, CupRound, j).tables, Table, k).elements, TableElement, l).team =
team_of_id(g_array_index(g_array_index(g_array_index(cp(i).rounds, CupRound, j).tables, Table, k).elements, TableElement, l).team_id);
}
for(j = 0; j < cp(i).fixtures->len; j++)
{
for(k = 0; k < 2; k++)
g_array_index(cp(i).fixtures, Fixture, j).teams[k] = team_of_id(g_array_index(cp(i).fixtures, Fixture, j).team_ids[k]);
table_refresh_team_pointers(&g_array_index(g_array_index(cp(i).rounds, CupRound, j).tables, Table, k));
}
}
}

View File

@ -1004,4 +1004,4 @@ int_news_repetition_min_check_number 3
int_news_repetition_max_check_number 10
# how many news articles to keep in memory
int_news_history_length 50
int_news_history_length 100

View File

@ -114,26 +114,26 @@
</choose_team>
</choose_teams>
<delay>-18</delay>
<byes>0</byes>
<!-- <byes>0</byes> -->
</cup_round>
<cup_round>
<home_away>0</home_away>
<delay>-18</delay>
<byes>0</byes>
<!-- <byes>0</byes> -->
</cup_round>
<cup_round>
<home_away>0</home_away>
<choose_teams>
<choose_team>
<choose_team_sid>austria_cup</choose_team_sid>
<number_of_teams>1</number_of_teams>
<start_idx>1</start_idx>
<end_idx>1</end_idx>
</choose_team>
</choose_teams>
<!-- <choose_teams> -->
<!-- <choose_team> -->
<!-- <choose_team_sid>austria_cup</choose_team_sid> -->
<!-- <number_of_teams>1</number_of_teams> -->
<!-- <start_idx>1</start_idx> -->
<!-- <end_idx>1</end_idx> -->
<!-- </choose_team> -->
<!-- </choose_teams> -->
<delay>-15</delay>
</cup_round>