1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2024-12-14 17:34:19 +01:00
This commit is contained in:
gyboth 2005-06-08 17:43:28 +00:00
parent 4602d36251
commit 13cfd155a9
5 changed files with 82 additions and 44 deletions

View File

@ -139,7 +139,7 @@ query_cup_choose_team_is_league(const gchar *sid)
/** Write the cup or league of the chooseteam into the appropriate pointer. */
void
cup_get_choose_team_league_cup(const CupChooseTeam *ct,
League **league, Cup **cup)
const League **league, const Cup **cup)
{
gint i, idx;
gchar trash[SMALL];
@ -228,8 +228,8 @@ cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct)
gint debug_num = teams->len;
gint number_of_teams = 0;
GPtrArray *cup_teams_sorted = NULL;
League *league = NULL;
Cup *cup_temp = NULL;
const League *league = NULL;
const Cup *cup_temp = NULL;
if(debug > 60)
printf("cup_load_choose_team: %s, %s \n", cup->name->str,
@ -631,14 +631,10 @@ cup_get_matchdays_in_cup_round(const Cup *cup, gint cup_round)
if(g_array_index(cup->rounds, CupRound, cup_round).
round_robin_number_of_groups > 0)
{
number_of_teams = cup_round_get_number_of_teams(cup, cup_round);
number_of_matchdays = ((number_of_teams / g_array_index(cup->rounds, CupRound, cup_round).
round_robin_number_of_groups) % 2 == 0) ?
2 * ((number_of_teams / g_array_index(cup->rounds, CupRound, cup_round).
round_robin_number_of_groups) - 1) :
2 * ((number_of_teams / g_array_index(cup->rounds, CupRound, cup_round).
round_robin_number_of_groups));
number_of_teams = cup_round_robin_get_number_of_teams(cup, cup_round);
number_of_matchdays = (number_of_teams % 2 == 0) ?
2 * (number_of_teams - 1) :
2 * number_of_teams;
}
else if(g_array_index(cup->rounds, CupRound, cup_round).home_away)
number_of_matchdays = 2;
@ -648,31 +644,69 @@ cup_get_matchdays_in_cup_round(const Cup *cup, gint cup_round)
return number_of_matchdays;
}
/** Return the number of teams playing in the given cup round.
/** Return the number of teams playing in a group of
the given cup round with round robin.
@param cup The cup we examine.
@param cup_round The index of the cup round.
@return The number teams. */
@return The number teams in one group. */
gint
cup_round_get_number_of_teams(const Cup *cup, gint round)
cup_round_robin_get_number_of_teams(const Cup *cup, gint round)
{
const CupRound *cup_round = &g_array_index(cup->rounds, CupRound, round);
gint number_of_teams = -1;
gint number_of_teams = 0;
if(round == 0)
number_of_teams = cup_round->new_teams;
number_of_teams = cup_round_get_new_teams(cup_round);
else if(g_array_index(cup->rounds, CupRound, round - 1).round_robin_number_of_groups > 0)
{
number_of_teams =
(g_array_index(cup->rounds, CupRound, round - 1).round_robin_number_of_groups *
g_array_index(cup->rounds, CupRound, round - 1).round_robin_number_of_advance) +
g_array_index(cup->rounds, CupRound, round - 1).round_robin_number_of_best_advance +
cup_round->new_teams;
cup_round_get_new_teams(cup_round);
}
else
number_of_teams = (cup_round_get_number_of_teams(cup, round - 1) / 2) +
cup_round->new_teams;
return number_of_teams;
while(number_of_teams % cup_round->round_robin_number_of_groups != 0)
number_of_teams--;
return number_of_teams / cup_round->round_robin_number_of_groups;
}
/** Return the number of new teams that come into the
cup in the given cup round. */
gint
cup_round_get_new_teams(const CupRound *cup_round)
{
gint i, new_teams = 0;
const Cup *cup_temp = NULL;
const League *league = NULL;
GPtrArray *teams_sorted = NULL;
if(cup_round->new_teams != 0)
new_teams = cup_round->new_teams;
else
{
for(i=0;i<cup_round->choose_teams->len;i++)
{
if(g_array_index(cup_round->choose_teams, CupChooseTeam, i).number_of_teams != -1)
new_teams += g_array_index(cup_round->choose_teams, CupChooseTeam, i).number_of_teams;
else
{
cup_get_choose_team_league_cup(&g_array_index(cup_round->choose_teams, CupChooseTeam, i),
&league, &cup_temp);
if(cup_temp == NULL)
new_teams += league->teams->len;
else
{
teams_sorted = cup_get_teams_sorted(cup_temp);
new_teams += teams_sorted->len;
g_ptr_array_free(teams_sorted, TRUE);
}
}
}
}
return new_teams;
}
/** Return the cup pointer belonging to the id.
@ -796,8 +830,8 @@ gboolean
query_cup_begins(const Cup *cup)
{
gint i;
League *league = NULL;
Cup *cup_temp = NULL;
const League *league = NULL;
const Cup *cup_temp = NULL;
gboolean proceed = FALSE;
const CupRound *cup_round = &g_array_index(cup->rounds, CupRound, 0);
@ -846,16 +880,16 @@ query_cup_begins(const Cup *cup)
}
/** Return the number of international cups in the country. */
gint
cup_count_international(void)
gboolean
query_cup_transfer(void)
{
gint i, return_value = 0;
gint i;
for(i=0;i<cps->len;i++)
if(query_cup_is_international(cp(i).id))
return_value++;
for(i=0;i<acps->len;i++)
if(acp(i)->teams->len > 0)
return TRUE;
return return_value;
return FALSE;
}
/** Find out whether the cup has a highlight property

View File

@ -43,7 +43,10 @@ gint
cup_get_matchdays_in_cup_round(const Cup *cup, gint cup_round);
gint
cup_round_get_number_of_teams(const Cup *cup, gint cup_round);
cup_round_robin_get_number_of_teams(const Cup *cup, gint round);
gint
cup_round_get_new_teams(const CupRound *cup_round);
Cup*
cup_from_clid(gint clid);
@ -77,7 +80,7 @@ query_cup_begins(const Cup *cup);
void
cup_get_choose_team_league_cup(const CupChooseTeam *ct,
League **league, Cup **cup);
const League **league, const Cup **cup);
gint
cup_get_last_week_from_first(const Cup *cup, gint first_week);
@ -91,8 +94,8 @@ cup_has_tables(gint clid);
Team*
cup_get_winner(const Cup *cup);
gint
cup_count_international(void);
gboolean
query_cup_transfer(void);
gchar*
cup_get_highlight_colour(const Cup *cup);

View File

@ -69,8 +69,8 @@ fixture_update(Cup *cup)
teams = fixture_get_cup_round_winners(cup);
if(teams->len < 2)
return;
if(round == cup->rounds->len - 1 && teams->len < 2)
return;
if(round + 1 > cup->rounds->len - 1)
g_warning("fixture_update: round index %d too high for round array (%d) in cup %s\n",
@ -85,7 +85,10 @@ fixture_update(Cup *cup)
g_ptr_array_add(teams, g_ptr_array_index(teams_new, i));
g_ptr_array_free(teams_new, TRUE);
}
if(teams->len < 2)
return;
if(cup->bye != NULL && cup->bye->len != 0)
{
for(i=0;i<cup->bye->len;i++)

View File

@ -814,11 +814,8 @@ team_get_sorted(GCompareDataFunc compare_function, gint type, gboolean cup)
{
for(i=0;i<cps->len;i++)
for(j=0;j<cp(i).rounds->len;j++)
{
if(g_array_index(cp(i).rounds, CupRound, j).teams->len > 0)
for(k=0;k<g_array_index(cp(i).rounds, CupRound, j).teams->len;k++)
g_ptr_array_add(teams, &g_array_index(g_array_index(cp(i).rounds, CupRound, j).teams, Team, k));
}
for(k=0;k<g_array_index(cp(i).rounds, CupRound, j).teams->len;k++)
g_ptr_array_add(teams, &g_array_index(g_array_index(cp(i).rounds, CupRound, j).teams, Team, k));
}
g_ptr_array_sort_with_data(teams, compare_function, GINT_TO_POINTER(type));

View File

@ -200,7 +200,7 @@ transfer_add_new_players(void)
for(i=0;i<number_of_new;i++)
transfer_add_player(transfer_player_get_new(
(math_rnd(0, 1) < const_float("float_transfer_cup_percentage") &&
cup_count_international() > 0)),
query_cup_transfer())),
math_rndi(const_int("int_transfer_time_lower"),
const_int("int_transfer_time_upper")));
}
@ -263,7 +263,8 @@ transfer_get_deadline(void)
gint length = 0;
for(i=0;i<ligs->len;i++)
length = MAX(length, (lig(i).teams->len - 1) * 2);
length = MAX(length,
g_array_index(lig(i).fixtures, Fixture, lig(i).fixtures->len - 1).week_number);
return (gint)rint((gfloat)length * const_float("float_transfer_deadline_percentage"));
}