Added possibility to configure number of round robins in cup stages.

This commit is contained in:
gyboth 2008-12-13 15:15:03 +00:00
parent 1ca257946e
commit 31b448536f
13 changed files with 42 additions and 48 deletions

View File

@ -123,6 +123,7 @@ cup_round_new(void)
new.round_robin_number_of_groups = 0;
new.round_robin_number_of_advance = 0;
new.round_robin_number_of_best_advance = 0;
new.round_robins = 2;
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.two_match_week = FALSE;
@ -879,8 +880,7 @@ cup_get_matchdays_in_cup_round(const Cup *cup, gint round)
else
number_of_matchdays = number_of_teams;
if (cup_round->home_away)
number_of_matchdays *= 2;
number_of_matchdays *= cup_round->round_robins;
for(i=0;i<cup_round->two_match_weeks[0]->len;i++)
{

View File

@ -57,6 +57,8 @@ typedef struct
and additionally the best 3 from all the groups.
Default: 0. */
gint round_robin_number_of_best_advance;
/** How many matchdays there are in the round robin phase. */
gint round_robins;
/** Number of new teams participating in the cup round
(ie. teams that get loaded and are not advancing from a previous
round). */

View File

@ -70,7 +70,7 @@ fixture_write_league_fixtures(League *league)
/** Write fixtures for as many round robins as required by the maximum number of rrs given. */
for(i = 0; i < max_rr;)
{
fixture_write_round_robin((gpointer)league, -1, misc_copy_ptr_array(teams), (i == max_rr - 1));
fixture_write_round_robin((gpointer)league, -1, misc_copy_ptr_array(teams), (i == max_rr - 1), -1);
i += (i < max_rr - 1) ? 2 : 1;
}
@ -436,8 +436,16 @@ fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams)
for(i=0;i<number_of_groups;i++)
{
g_array_append_val(cupround->tables, table_group[i]);
fixture_write_round_robin((gpointer)cup, cup_round,
teams_group[i], !cupround->home_away);
for(j = 0; j < cupround->round_robins;)
{
fixture_write_round_robin((gpointer)cup, cup_round,
misc_copy_ptr_array(teams_group[i]),
(j == cupround->round_robins - 1),
(j == 0) ? -1 : g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number + cup->week_gap);
j += (j < cupround->round_robins - 1) ? 2 : 1;
}
g_ptr_array_free(teams_group[i], TRUE);
}
g_ptr_array_free(teams, TRUE);
@ -463,14 +471,14 @@ fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams)
@param one_round Whether a team plays each other team twice or only once. */
void
fixture_write_round_robin(gpointer league_cup, gint cup_round,
GPtrArray *teams, gboolean one_round)
GPtrArray *teams, gboolean one_round, gint first_week)
{
#ifdef DEBUG
printf("fixture_write_round_robin\n");
#endif
gint i, j;
gint first_week, week_gap, week_number,
gint week_gap, week_number,
week_round_number, clid, first_fixture,
rr_break;
gboolean home_advantage;
@ -500,7 +508,8 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
else
{
cup = (Cup*)league_cup;
first_week = cup_get_first_week_of_cup_round(cup, cup_round);
if(first_week == -1)
first_week = cup_get_first_week_of_cup_round(cup, cup_round);
week_gap = cup->week_gap;
fixtures = cup->fixtures;
two_match_weeks = g_array_index(cup->rounds, CupRound, cup_round).two_match_weeks;

View File

@ -50,7 +50,8 @@ void
fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams);
void
fixture_write_round_robin(gpointer league_cup, gint cup_round, GPtrArray *teams, gboolean one_round);
fixture_write_round_robin(gpointer league_cup, gint cup_round, GPtrArray *teams,
gboolean one_round, gint first_week);
void
fixture_write_round_robin_matchday(GArray *fixtures, gint cup_round, GPtrArray *teams,

View File

@ -758,11 +758,6 @@ free_newspaper(gboolean reset)
{
gint i;
for(i = 0; i < newspaper.names->len; i++)
g_free(g_ptr_array_index(newspaper.names, i));
g_ptr_array_free(newspaper.names, TRUE);
for(i = 0; i < newspaper.articles->len; i++)
{
g_free(g_array_index(newspaper.articles, NewsPaperArticle, i).title_small);
@ -773,10 +768,7 @@ free_newspaper(gboolean reset)
g_array_free(newspaper.articles, TRUE);
if(reset)
{
newspaper.names = g_ptr_array_new();
newspaper.articles = g_array_new(FALSE, FALSE, sizeof(NewsPaperArticle));
}
}
/**

View File

@ -239,7 +239,6 @@ main_init_variables(void)
news[i] = g_array_new(FALSE, FALSE, sizeof(NewsArticle));
newspaper.articles = g_array_new(FALSE, FALSE, sizeof(NewsPaperArticle));
newspaper.names = g_ptr_array_new();
file_load_conf_files();
xml_strategy_load_strategies();

View File

@ -77,14 +77,13 @@ typedef struct
gint week_number, week_round_number;
gint title_id, subtitle_id;
gchar *title_small, *title, *subtitle;
gint user_idx;
} NewsPaperArticle;
/** Structure holding the newspaper for the game. */
typedef struct
{
/** A selection of newspaper names. */
GPtrArray *names;
/** The array of created articles. */
GArray *articles;

View File

@ -58,6 +58,7 @@
#define TAG_CUP_ROUND_NUMBER_OF_GROUPS "number_of_groups"
#define TAG_CUP_ROUND_NUMBER_OF_ADVANCE "number_of_advance"
#define TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE "number_of_best_advance"
#define TAG_CUP_ROUND_ROUND_ROBINS "round_robins"
#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"
@ -101,6 +102,7 @@ enum XmlCupStates
STATE_CUP_ROUND_NUMBER_OF_GROUPS,
STATE_CUP_ROUND_NUMBER_OF_ADVANCE,
STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE,
STATE_CUP_ROUND_ROUND_ROBINS,
STATE_CUP_ROUND_TWO_MATCH_WEEK_START,
STATE_CUP_ROUND_TWO_MATCH_WEEK_END,
STATE_CUP_ROUND_TWO_MATCH_WEEK,
@ -199,6 +201,8 @@ xml_cup_read_start_element (GMarkupParseContext *context,
state = STATE_CUP_ROUND_NUMBER_OF_ADVANCE;
else if(strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) == 0)
state = STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE;
else if(strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBINS) == 0)
state = STATE_CUP_ROUND_ROUND_ROBINS;
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)
@ -263,7 +267,11 @@ xml_cup_read_end_element (GMarkupParseContext *context,
state = STATE_CUP;
else if(strcmp(element_name, TAG_CUP_ROUND) == 0)
{
state = STATE_CUP_ROUNDS;
state = STATE_CUP_ROUNDS;
if(new_round.home_away == 0)
new_round.round_robins = 1;
g_array_append_val(new_cup.rounds, new_round);
}
else if(strcmp(element_name, TAG_CUP_ROUND_HOME_AWAY) == 0 ||
@ -274,6 +282,7 @@ xml_cup_read_end_element (GMarkupParseContext *context,
strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_GROUPS) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_ADVANCE) == 0 ||
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_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 ||
@ -370,6 +379,8 @@ xml_cup_read_text (GMarkupParseContext *context,
new_round.round_robin_number_of_advance = int_value;
else if(state == STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE)
new_round.round_robin_number_of_best_advance = int_value;
else if(state == STATE_CUP_ROUND_ROUND_ROBINS)
new_round.round_robins = int_value;
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

@ -63,6 +63,7 @@ enum
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS,
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE,
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE,
TAG_CUP_ROUND_ROUND_ROBINS,
TAG_CUP_ROUND_TWO_MATCH_WEEK_START,
TAG_CUP_ROUND_TWO_MATCH_WEEK_END,
TAG_CUP_ROUND_TWO_MATCH_WEEK,
@ -181,6 +182,7 @@ xml_loadsave_cup_end_element (GMarkupParseContext *context,
tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS ||
tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE ||
tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE ||
tag == TAG_CUP_ROUND_ROUND_ROBINS ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK_START ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK_END ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK)
@ -301,6 +303,8 @@ xml_loadsave_cup_text (GMarkupParseContext *context,
new_round.round_robin_number_of_advance = int_value;
else if(state == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE)
new_round.round_robin_number_of_best_advance = int_value;
else if(state == TAG_CUP_ROUND_ROUND_ROBINS)
new_round.round_robins = int_value;
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)
@ -453,6 +457,8 @@ xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gin
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE, I1);
xml_write_int(fil, cup_round->round_robin_number_of_best_advance,
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE, I1);
xml_write_int(fil, cup_round->round_robins,
TAG_CUP_ROUND_ROUND_ROBINS, I1);
xml_write_int(fil, cup_round->two_match_week,
TAG_CUP_ROUND_TWO_MATCH_WEEK, I1);

View File

@ -129,9 +129,7 @@ xml_loadsave_newspaper_text (GMarkupParseContext *context,
int_value = (gint)g_ascii_strtod(buf, NULL);
if(state == TAG_NEWS_PAPER_NAME)
g_ptr_array_add(newspaper.names, g_strdup(buf));
else if(state == TAG_NEWS_PAPER_ARTICLE_WEEK)
if(state == TAG_NEWS_PAPER_ARTICLE_WEEK)
new_article.week_number = int_value;
else if(state == TAG_NEWS_PAPER_ARTICLE_WEEK_ROUND)
new_article.week_round_number = int_value;
@ -206,9 +204,6 @@ xml_loadsave_newspaper_write(const gchar *prefix)
fprintf(fil, "<_%d>\n", TAG_NEWS_PAPER);
for(i = 0; i < newspaper.names->len; i++)
xml_write_string(fil, (gchar*)g_ptr_array_index(newspaper.names, i), TAG_NEWS_PAPER_NAME, I1);
for(i=0;i<newspaper.articles->len;i++)
{
fprintf(fil, "%s<_%d>\n", I0, TAG_NEWS_PAPER_ARTICLE);

View File

@ -30,7 +30,6 @@
#include "xml_news.h"
#define TAG_NEWS "news"
#define TAG_PAPER_NAME "paper_name"
#define TAG_ARTICLE "news_article"
#define TAG_ARTICLE_TYPE "type"
#define TAG_ARTICLE_CONDITION "condition"
@ -51,7 +50,6 @@
enum XmlNewsStates
{
STATE_NEWS = 0,
STATE_PAPER_NAME,
STATE_ARTICLE,
STATE_ARTICLE_TYPE,
STATE_ARTICLE_CONDITION,
@ -118,8 +116,6 @@ xml_news_read_start_element (GMarkupParseContext *context,
if(strcmp(element_name, TAG_NEWS) == 0)
state = STATE_NEWS;
else if(strcmp(element_name, TAG_PAPER_NAME) == 0)
state = STATE_PAPER_NAME;
else if(strcmp(element_name, TAG_ARTICLE) == 0)
{
state = STATE_ARTICLE;
@ -191,8 +187,6 @@ xml_news_read_end_element (GMarkupParseContext *context,
state = STATE_NEWS;
g_array_append_val(news[article_idx], new_article);
}
else if(strcmp(element_name, TAG_PAPER_NAME) == 0)
state = STATE_NEWS;
else if(strcmp(element_name, TAG_ARTICLE_TYPE) == 0 ||
strcmp(element_name, TAG_ARTICLE_CONDITION) == 0 ||
strcmp(element_name, TAG_ARTICLE_PRIORITY) == 0 ||
@ -229,9 +223,7 @@ xml_news_read_text (GMarkupParseContext *context,
int_value = (gint)g_ascii_strtod(buf, NULL);
if(state == STATE_PAPER_NAME)
g_ptr_array_add(newspaper.names, g_strdup(buf));
else if(state == STATE_ARTICLE_TYPE)
if(state == STATE_ARTICLE_TYPE)
article_idx = xml_news_article_type_to_int(buf);
else if(state == STATE_ARTICLE_CONDITION)
misc_string_assign(&new_article.condition, buf);

View File

@ -1,10 +1,4 @@
<news>
<paper_name>Bygfoot Herald</paper_name>
<paper_name>4TehFans</paper_name>
<paper_name>Football Online</paper_name>
<paper_name>11vs11</paper_name>
<paper_name>The Pitch</paper_name>
<paper_name>News Of The Sports World</paper_name>
<news_article>
<type>match</type>
<condition>_CUP_ = 0 and _GD_ G 1</condition>

View File

@ -1,10 +1,4 @@
<news>
<paper_name>Bygfoot Herald</paper_name>
<paper_name>4TehFans</paper_name>
<paper_name>Football Online</paper_name>
<paper_name>11vs11</paper_name>
<paper_name>The Pitch</paper_name>
<paper_name>News Of The Sports World</paper_name>
<news_article>
<type>match</type>
<condition>_CUP_ = 0 and _GD_ G 1</condition>