Def system changes.

This commit is contained in:
gyboth 2008-12-28 15:44:12 +00:00
parent e483bf25bd
commit 196a53cc63
8 changed files with 128 additions and 10 deletions

View File

@ -132,6 +132,7 @@ cup_round_new(void)
new.tables = g_array_new(FALSE, FALSE, sizeof(Table));
new.choose_teams = g_array_new(FALSE, FALSE, sizeof(CupChooseTeam));
new.teams = g_array_new(FALSE, FALSE, sizeof(Team));
new.waits = g_array_new(FALSE, FALSE, sizeof(CupRoundWait));
new.team_ptrs = g_ptr_array_new();
return new;
@ -352,7 +353,7 @@ cup_load_choose_team_from_cup(Cup *cup, const Cup *cup_temp, GPtrArray *teams, c
number_of_teams = 0;
cup_teams_sorted = NULL;
if(season == 1 && cup->add_week == 0)
if(season == 1 && week == 1 && cup->add_week == 0)
{
if(lig(0).teams->len < ct->number_of_teams)
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
@ -1262,3 +1263,44 @@ cup_check_fixtures(const Cup *cup)
return TRUE;
}
/** Check whether we have to wait for other cups
before we can write fixtures for the cup round. */
gboolean
cup_round_check_waits(const CupRound *cup_round)
{
gint i, j, k;
for(i = 0; i < cup_round->waits->len; i++)
{
for(j = 0; j < acps->len; j++)
{
if(strcmp(acp(j)->sid, g_array_index(cup_round->waits, CupRoundWait, i).cup_sid) == 0)
{
/* Cup round we're waiting for isn't even reached. */
if(g_array_index(acp(j)->fixtures, Fixture, acp(j)->fixtures->len - 1).round <
g_array_index(cup_round->waits, CupRoundWait, i).cup_round)
return TRUE;
for(k = acp(j)->fixtures->len - 1; k >= 0; k--)
{
/* Cup round we've been waiting for is finished,
we're not waiting anymore. */
if(g_array_index(acp(j)->fixtures, Fixture, k).round >
g_array_index(cup_round->waits, CupRoundWait, i).cup_round)
break;
/* Still waiting for matches to be calculated. */
if(g_array_index(acp(j)->fixtures, Fixture, k).round ==
g_array_index(cup_round->waits, CupRoundWait, i).cup_round &&
g_array_index(acp(j)->fixtures, Fixture, k).attendance == -1)
return TRUE;
}
break;
}
}
}
return FALSE;
}

View File

@ -129,4 +129,7 @@ cup_get_highlight_colour(const Cup *cup);
gboolean
cup_check_fixtures(const Cup *cup);
gboolean
cup_round_check_waits(const CupRound *cup_round);
#endif

View File

@ -29,6 +29,16 @@
#include "bygfoot.h"
#include "table_struct.h"
/** Information about what cup another cup has to wait for
before scheduling matches. */
typedef struct
{
/** The cup we wait for. */
gchar *cup_sid;
/** The cup round of the cup we wait for. */
gint cup_round;
} CupRoundWait;
/** Rules for a round of a cup.
Cups consist of rounds, e.g. the final counts as
a round or the round robin games. */
@ -90,6 +100,8 @@ typedef struct
GArray *choose_teams;
/** The round robin tables (in case there is a round robin). */
GArray *tables;
/** Array with CupRoundWaits. */
GArray *waits;
} CupRound;
/**

View File

@ -151,6 +151,11 @@ fixture_update(Cup *cup)
fixture_update_write_replays(cup))
return;
/** Still waiting for other cups. */
if(round + 1 < cup->rounds->len &&
cup_round_check_waits(&g_array_index(cup->rounds, CupRound, round + 1)))
return;
teams = fixture_get_cup_round_winners(cup);
if(round == cup->rounds->len - 1 && teams->len < 2)
@ -457,9 +462,9 @@ fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams)
GINT_TO_POINTER(FIXTURE_COMPARE_DATE + 100));
cup->next_fixture_update_week = (cup_round < cup->rounds->len - 1) ?
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number : -1;
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number : 1000;
cup->next_fixture_update_week_round = (cup_round < cup->rounds->len - 1) ?
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_round_number : -1;
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_round_number : 1000;
}
/** Write round robin fixtures for the teams in the array.
@ -535,6 +540,10 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
len++;
}
/* Special rule for cups that have to wait for other cups. */
if(first_week < week + 1)
first_week = week + 1;
/* first half of fixtures */
week_number = league_cup_get_week_with_break(clid, first_week);
for(i=0;i<len - 1;i++)
@ -671,6 +680,10 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams)
else if(round->randomise_teams)
teams = misc_randomise_g_pointer_array(teams);
/* Special rule for cups that have to wait for other cups. */
if(first_week < week + 1)
first_week = week + 1;
week_number = league_cup_get_week_with_break(cup->id, first_week);
week_round_number =
fixture_get_free_round(week_number, teams, -1, -1);
@ -711,11 +724,11 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams)
cup->next_fixture_update_week =
(cup_round < cup->rounds->len - 1 || round->replay > 0) ?
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number : -1;
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number : 1000;
cup->next_fixture_update_week_round =
(cup_round < cup->rounds->len - 1 || round->replay > 0) ?
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_round_number : -1;
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_round_number : 1000;
g_ptr_array_free(teams, TRUE);
}

View File

@ -644,8 +644,8 @@ free_cup(Cup *cup)
for(i=0;i<cup->rounds->len;i++)
free_cup_round(&g_array_index(cup->rounds, CupRound, i));
free_g_array(&cup->rounds);
free_g_array(&cup->fixtures);
free_g_array(&cup->week_breaks);
@ -667,6 +667,11 @@ free_cup_round(CupRound *cup_round)
free_g_array(&cup_round->two_match_weeks[0]);
free_g_array(&cup_round->two_match_weeks[1]);
for(j = 0; j < cup_round->waits->len; j++)
g_free(g_array_index(cup_round->waits, CupRoundWait, j).cup_sid);
free_g_array(&cup_round->waits);
if(cup_round->round_robin_number_of_groups > 0)
{
free_tables(&cup_round->tables);

View File

@ -490,8 +490,8 @@ end_week_round_update_fixtures(void)
gint i;
for(i=0;i<acps->len;i++)
if(acp(i)->next_fixture_update_week == week &&
acp(i)->next_fixture_update_week_round == week_round)
if(acp(i)->next_fixture_update_week <= week &&
acp(i)->next_fixture_update_week_round <= week_round)
fixture_update(acp(i));
for(i=0;i<ligs->len;i++)

View File

@ -55,6 +55,7 @@
#define TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE "number_of_best_advance"
#define TAG_CUP_ROUND_ROUND_ROBINS "round_robins"
#define TAG_CUP_ROUND_BREAK "break"
#define TAG_CUP_ROUND_WAIT "wait_for_cup"
#define TAG_CUP_ROUND_TWO_MATCH_WEEK_START "two_match_week_start"
#define TAG_CUP_ROUND_TWO_MATCH_WEEK_END "two_match_week_end"
#define TAG_CUP_ROUND_TWO_MATCH_WEEK "two_match_week"
@ -69,6 +70,8 @@
#define TAG_CHOOSE_TEAM_SKIP_GROUP_CHECK "skip_group_check"
#define TAG_CHOOSE_TEAM_FROM_TABLE "from_table"
#define ATT_NAME_CUP_ROUND_WAIT_ROUND "round"
/**
* Enum with the states used in the XML parser functions.
*/
@ -101,6 +104,7 @@ enum XmlCupStates
STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE,
STATE_CUP_ROUND_ROUND_ROBINS,
STATE_CUP_ROUND_BREAK,
STATE_CUP_ROUND_WAIT,
STATE_CUP_ROUND_TWO_MATCH_WEEK_START,
STATE_CUP_ROUND_TWO_MATCH_WEEK_END,
STATE_CUP_ROUND_TWO_MATCH_WEEK,
@ -127,6 +131,7 @@ Cup new_cup;
CupRound new_round;
CupChooseTeam new_choose_team;
WeekBreak new_week_break;
CupRoundWait new_wait;
/**
* The function called by the parser when an opening tag is read.
@ -212,6 +217,17 @@ xml_cup_read_start_element (GMarkupParseContext *context,
state = STATE_CUP_ROUND_ROUND_ROBINS;
else if(strcmp(element_name, TAG_CUP_ROUND_BREAK) == 0)
state = STATE_CUP_ROUND_BREAK;
else if(strcmp(element_name, TAG_CUP_ROUND_WAIT) == 0)
{
state = STATE_CUP_ROUND_WAIT;
if(attribute_names[0] != NULL && strcmp(attribute_names[0], ATT_NAME_CUP_ROUND_WAIT_ROUND) == 0)
new_wait.cup_round = (gint)g_ascii_strtod(attribute_values[0], NULL) - 1;
else
{
new_wait.cup_round = -1;
g_warning("xml_cup_read_start_element: No round number specified for cup round wait in cup %s\n", new_cup.name);
}
}
else if(strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_START) == 0)
state = STATE_CUP_ROUND_TWO_MATCH_WEEK_START;
else if(strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_END) == 0)
@ -299,13 +315,18 @@ xml_cup_read_end_element (GMarkupParseContext *context,
strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBINS) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_BREAK) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_WAIT) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_START) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_END) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_NEW_TEAMS) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_BYES) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAMS) == 0)
state = STATE_CUP_ROUND;
{
state = STATE_CUP_ROUND;
if(strcmp(element_name, TAG_CUP_ROUND_WAIT) == 0)
g_array_append_val(new_round.waits, new_wait);
}
else if(strcmp(element_name, TAG_CHOOSE_TEAM) == 0)
{
state = STATE_CHOOSE_TEAMS;
@ -401,6 +422,8 @@ xml_cup_read_text (GMarkupParseContext *context,
new_round.round_robins = int_value;
else if(state == STATE_CUP_ROUND_BREAK)
league_cup_fill_rr_breaks(new_round.rr_breaks, buf);
else if(state == STATE_CUP_ROUND_WAIT)
new_wait.cup_sid = g_strdup(buf);
else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK_START)
g_array_append_val(new_round.two_match_weeks[0], int_value);
else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK_END)

View File

@ -65,6 +65,8 @@ enum
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE,
TAG_CUP_ROUND_ROUND_ROBINS,
TAG_CUP_ROUND_BREAK,
TAG_CUP_ROUND_WAIT_CUP,
TAG_CUP_ROUND_WAIT_ROUND,
TAG_CUP_ROUND_TWO_MATCH_WEEK_START,
TAG_CUP_ROUND_TWO_MATCH_WEEK_END,
TAG_CUP_ROUND_TWO_MATCH_WEEK,
@ -82,6 +84,7 @@ CupChooseTeam new_choose_team;
CupRound new_round;
gchar *dirname;
WeekBreak new_week_break;
CupRoundWait new_wait;
void
xml_loadsave_cup_start_element (GMarkupParseContext *context,
@ -188,6 +191,8 @@ xml_loadsave_cup_end_element (GMarkupParseContext *context,
tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE ||
tag == TAG_CUP_ROUND_ROUND_ROBINS ||
tag == TAG_CUP_ROUND_BREAK ||
tag == TAG_CUP_ROUND_WAIT_CUP ||
tag == TAG_CUP_ROUND_WAIT_ROUND ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK_START ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK_END ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK)
@ -319,6 +324,13 @@ xml_loadsave_cup_text (GMarkupParseContext *context,
new_round.round_robins = int_value;
else if(state == TAG_CUP_ROUND_BREAK)
g_array_append_val(new_round.rr_breaks, int_value);
else if(state == TAG_CUP_ROUND_WAIT_CUP)
new_wait.cup_sid = g_strdup(buf);
else if(state == TAG_CUP_ROUND_WAIT_ROUND)
{
new_wait.cup_round = int_value;
g_array_append_val(new_round.waits, new_wait);
}
else if(state == TAG_CUP_ROUND_TWO_MATCH_WEEK_START)
g_array_append_val(new_round.two_match_weeks[0], int_value);
else if(state == TAG_CUP_ROUND_TWO_MATCH_WEEK_END)
@ -484,6 +496,14 @@ xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gin
xml_write_int(fil, g_array_index(cup_round->rr_breaks, gint, i),
TAG_CUP_ROUND_BREAK, I1);
for(i = 0; i < cup_round->waits->len; i++)
{
xml_write_string(fil, g_array_index(cup_round->waits, CupRoundWait, i).cup_sid,
TAG_CUP_ROUND_WAIT_CUP, I1);
xml_write_int(fil, g_array_index(cup_round->waits, CupRoundWait, i).cup_round,
TAG_CUP_ROUND_WAIT_ROUND, I1);
}
xml_write_int(fil, cup_round->two_match_week,
TAG_CUP_ROUND_TWO_MATCH_WEEK, I1);