Added two match weeks for leagues.

This commit is contained in:
gyboth 2007-02-17 12:06:30 +00:00
parent 95e2074988
commit 3373a22094
8 changed files with 83 additions and 13 deletions

View File

@ -366,7 +366,7 @@ fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams)
{
g_array_append_val(cupround->tables, table_group[i]);
fixture_write_round_robin((gpointer)cup, cup_round,
teams_group[i], !cupround->home_away);
teams_group[i], !cupround->home_away);
}
g_ptr_array_free(teams, TRUE);
@ -395,8 +395,9 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
GPtrArray *teams, gboolean one_round)
{
gint i, j;
gint first_week, week_gap, week_round_number,
clid, first_fixture, rr_break;
gint first_week, week_gap, week_number,
week_round_number, clid, first_fixture,
rr_break;
gboolean home_advantage;
League *league = NULL;
Cup *cup = NULL;
@ -446,19 +447,27 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
}
/* first half of fixtures */
week_number = first_week;
for(i=0;i<len - 1;i++)
{
if(i > 0 && !query_league_matchday_in_two_match_week(league, i + 1))
week_number += week_gap;
fixture_write_round_robin_matchday(fixtures, cup_round, teams, i,
first_week + i * week_gap,
clid, home_advantage);
week_number, clid, home_advantage);
}
if(!one_round)
{
/* second half of fixtures */
first_week = first_week + (len - 2) * week_gap + rr_break;
week_number += rr_break;
for(i = 0; i < len - 1; i++)
{
week_round_number = (cup_round == -1) ? 1 :
fixture_get_free_round(first_week + i * week_gap, teams, -1, -1);
if(i > 0 && !query_league_matchday_in_two_match_week(league, len + i))
week_number += week_gap;
week_round_number =
fixture_get_free_round(week_number, teams, -1, -1);
for(j = 0; j < len / 2; j++)
fixture_write(fixtures,
@ -466,7 +475,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
first_fixture + i * (len / 2) + j).teams[1],
g_array_index(fixtures, Fixture,
first_fixture + i * (len / 2) + j).teams[0],
first_week + i * week_gap, week_round_number,
week_number, week_round_number,
clid, cup_round, 0, home_advantage, FALSE, FALSE);
}
}
@ -503,8 +512,7 @@ fixture_write_round_robin_matchday(GArray *fixtures, gint cup_round, GPtrArray *
gint i;
gint len = teams->len / 2;
gpointer home[len], away[len];
gint week_round_number = (cup_round == -1) ?
1 : fixture_get_free_round(week_number, teams, -1, -1);
gint week_round_number = fixture_get_free_round(week_number, teams, -1, -1);
home[0] = g_ptr_array_index(teams, len * 2 - 1);

View File

@ -339,6 +339,9 @@ free_league(League *league)
free_g_array(&league->fixtures);
free_g_array(&league->two_match_weeks[0]);
free_g_array(&league->two_match_weeks[1]);
free_league_stats(&league->stats);
}

View File

@ -74,6 +74,8 @@ league_new(gboolean new_id)
new.table.clid = new.id;
new.first_week = new.week_gap = 1;
new.two_match_weeks[0] = g_array_new(FALSE, FALSE, sizeof(gint));
new.two_match_weeks[1] = g_array_new(FALSE, FALSE, sizeof(gint));
new.round_robins = 2;
new.yellow_red = 1000;
@ -852,3 +854,24 @@ query_leagues_active_in_country(void)
return FALSE;
}
/** Find out whether a given matchday should occur in the same week
as the one before or a full week later. */
gboolean
query_league_matchday_in_two_match_week(const League *league, gint matchday)
{
gint i;
if(league == NULL)
return FALSE;
for(i=0;i<league->two_match_weeks[0]->len;i++)
{
if(g_array_index(league->two_match_weeks[0], gint, i) < matchday &&
matchday <= g_array_index(league->two_match_weeks[1], gint, i) &&
(matchday - g_array_index(league->two_match_weeks[0], gint, i)) % 2 == 1)
return TRUE;
}
return FALSE;
}

View File

@ -133,4 +133,7 @@ league_team_movements_compare_dest_idcs(gconstpointer a, gconstpointer b,
gboolean
query_leagues_active_in_country(void);
gboolean
query_league_matchday_in_two_match_week(const League *league, gint matchday);
#endif

View File

@ -101,10 +101,13 @@ typedef struct
gint first_week;
/** Weeks between two matchdays. Default 1. */
gint week_gap;
/** Here we store intervals of fixtures during which
there should be two matches in a week instead of one. */
GArray *two_match_weeks[2];
/** How many round robins are played. Important for
small leagues with 10 teams or so. Default: 1. */
gint round_robins;
/** */
/** Number of weeks between the parts of a round robin. */
gint rr_break;
/** Number of yellow cards until a player gets banned.
Default 1000 (which means 'off', basically). */

View File

@ -486,7 +486,7 @@ treeview_live_game_show_commentary(const LiveGameUnit *unit)
path = gtk_tree_model_get_path(GTK_TREE_MODEL(ls), &iter);
gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
gtk_widget_grab_focus (treeview);
gtk_widget_grab_focus(GTK_WIDGET(treeview));
gtk_tree_path_free(path);
}

View File

@ -70,6 +70,8 @@
#define TAG_TEAM_NAMES_FILE "team_names_file"
#define TAG_TEAM_AVERAGE_TALENT "team_average_talent"
#define TAG_TEAM_DEF_FILE "def_file"
#define TAG_TWO_MATCH_WEEK_START "two_match_week_start"
#define TAG_TWO_MATCH_WEEK_END "two_match_week_end"
/**
* Enum with the states used in the XML parser functions.
@ -108,6 +110,8 @@ enum XmlLeagueStates
STATE_TEAM_AVERAGE_TALENT,
STATE_TEAM_DEF_FILE,
STATE_BREAK,
STATE_TWO_MATCH_WEEK_START,
STATE_TWO_MATCH_WEEK_END,
STATE_END
};
@ -167,6 +171,10 @@ xml_league_read_start_element (GMarkupParseContext *context,
state = STATE_ACTIVE;
else if(strcmp(element_name, TAG_BREAK) == 0)
state = STATE_BREAK;
else if(strcmp(element_name, TAG_TWO_MATCH_WEEK_START) == 0)
state = STATE_TWO_MATCH_WEEK_START;
else if(strcmp(element_name, TAG_TWO_MATCH_WEEK_END) == 0)
state = STATE_TWO_MATCH_WEEK_END;
else if(strcmp(element_name, TAG_PROM_REL) == 0)
state = STATE_PROM_REL;
else if(strcmp(element_name, TAG_PROM_GAMES) == 0)
@ -244,6 +252,8 @@ xml_league_read_end_element (GMarkupParseContext *context,
strcmp(element_name, TAG_NAMES_FILE) == 0 ||
strcmp(element_name, TAG_ACTIVE) == 0 ||
strcmp(element_name, TAG_BREAK) == 0 ||
strcmp(element_name, TAG_TWO_MATCH_WEEK_START) == 0 ||
strcmp(element_name, TAG_TWO_MATCH_WEEK_END) == 0 ||
strcmp(element_name, TAG_PROM_REL) == 0 ||
strcmp(element_name, TAG_TEAMS) == 0)
state = STATE_LEAGUE;
@ -326,6 +336,10 @@ xml_league_read_text (GMarkupParseContext *context,
new_league.active = int_value;
else if(state == STATE_BREAK)
new_league.rr_break = int_value;
else if(state == STATE_TWO_MATCH_WEEK_START)
g_array_append_val(new_league.two_match_weeks[0], int_value);
else if(state == STATE_TWO_MATCH_WEEK_END)
g_array_append_val(new_league.two_match_weeks[1], int_value);
else if(state == STATE_PROM_GAMES_DEST_SID)
misc_string_assign(&new_league.prom_rel.prom_games_dest_sid, buf);
else if(state == STATE_PROM_GAMES_LOSER_SID)

View File

@ -54,6 +54,8 @@ enum
TAG_LEAGUE_PROM_REL_ELEMENT_DEST_SID,
TAG_LEAGUE_PROM_REL_ELEMENT_TYPE,
TAG_LEAGUE_BREAK,
TAG_LEAGUE_TWO_MATCH_WEEK_START,
TAG_LEAGUE_TWO_MATCH_WEEK_END,
TAG_END
};
@ -110,6 +112,8 @@ xml_loadsave_league_end_element (GMarkupParseContext *context,
tag == TAG_LEAGUE_LAYER ||
tag == TAG_LEAGUE_ACTIVE ||
tag == TAG_LEAGUE_BREAK ||
tag == TAG_LEAGUE_TWO_MATCH_WEEK_START ||
tag == TAG_LEAGUE_TWO_MATCH_WEEK_END ||
tag == TAG_LEAGUE_AVERAGE_TALENT ||
tag == TAG_LEAGUE_ROUND_ROBINS ||
tag == TAG_NAME ||
@ -190,6 +194,10 @@ xml_loadsave_league_text (GMarkupParseContext *context,
new_league->active = int_value;
else if(state == TAG_LEAGUE_BREAK)
new_league->rr_break = int_value;
else if(state == TAG_LEAGUE_TWO_MATCH_WEEK_START)
g_array_append_val(new_league->two_match_weeks[0], int_value);
else if(state == TAG_LEAGUE_TWO_MATCH_WEEK_END)
g_array_append_val(new_league->two_match_weeks[1], int_value);
else if(state == TAG_LEAGUE_AVERAGE_TALENT)
new_league->average_talent = float_value;
else if(state == TAG_LEAGUE_PROM_REL_PROM_GAMES_DEST_SID)
@ -283,6 +291,14 @@ xml_loadsave_league_write(const gchar *prefix, const League *league)
xml_write_int(fil, league->rr_break, TAG_LEAGUE_BREAK, I0);
xml_write_float(fil, league->average_talent, TAG_LEAGUE_AVERAGE_TALENT, I0);
for(i=0;i<league->two_match_weeks[0]->len;i++)
{
xml_write_int(fil, g_array_index(league->two_match_weeks[0], gint, i),
TAG_LEAGUE_TWO_MATCH_WEEK_START, I0);
xml_write_int(fil, g_array_index(league->two_match_weeks[1], gint, i),
TAG_LEAGUE_TWO_MATCH_WEEK_END, I0);
}
fprintf(fil, "%s<_%d>\n", I0, TAG_LEAGUE_PROM_REL);
xml_write_string(fil, league->prom_rel.prom_games_dest_sid,