diff --git a/src/league.c b/src/league.c index c6cacb07..cfc9cb6b 100644 --- a/src/league.c +++ b/src/league.c @@ -1028,3 +1028,26 @@ league_add_table(League *league) g_array_append_val(league->tables, new_table); } + +gboolean +query_league_cup_has_property(gint clid, const gchar *property) +{ + const GPtrArray *properties = league_cup_get_properties(clid); + return query_misc_string_in_array(property, properties); +} + +GPtrArray* +league_cup_get_teams(gint clid) +{ + return (clid < ID_CUP_START) ? + (GPtrArray*)league_from_clid(clid)->teams : + cup_from_clid(clid)->teams; +} + +GPtrArray* +league_cup_get_properties(gint clid) +{ + return (clid < ID_CUP_START) ? + league_from_clid(clid)->properties : + cup_from_clid(clid)->properties; +} diff --git a/src/league.h b/src/league.h index 44e265f4..d626afc0 100644 --- a/src/league.h +++ b/src/league.h @@ -31,14 +31,10 @@ #include "league_struct.h" #include "fixture_struct.h" -#define league_cup_get_teams(clid) (clid < ID_CUP_START) ? ((gpointer)(league_from_clid(clid)->teams)) : ((gpointer)(cup_from_clid(clid)->teams)) #define league_cup_get_fixtures(clid) (clid < ID_CUP_START) ? (league_from_clid(clid)->fixtures) : (cup_from_clid(clid)->fixtures) #define league_cup_get_name_string(clid) (clid < ID_CUP_START) ? league_from_clid(clid)->name : cup_from_clid(clid)->name #define league_cup_get_yellow_red(clid) (clid < ID_CUP_START) ? (league_from_clid(clid)->yellow_red) : (cup_from_clid(clid)->yellow_red) -#define league_cup_get_properties(clid) (clid < ID_CUP_START) ? ((gpointer)(league_from_clid(clid)->properties)) : ((gpointer)(cup_from_clid(clid)->properties)) -#define query_league_cup_has_property(clid, string) query_misc_string_in_array(string, (GArray*)league_cup_get_properties(clid)) - #define league_table_cumul(league) (&g_array_index((league)->tables, Table, 0)) #define league_table(league) (&g_array_index((league)->tables, Table, league->tables->len - 1)) @@ -149,4 +145,13 @@ league_check_new_tables(League *league); void league_add_table(League *league); +gboolean +query_league_cup_has_property(gint clid, const gchar *property); + +GPtrArray* +league_cup_get_teams(gint clid); + +GPtrArray* +league_cup_get_properties(gint clid); + #endif diff --git a/src/misc.c b/src/misc.c index 5fa79211..513dbe44 100644 --- a/src/misc.c +++ b/src/misc.c @@ -300,7 +300,7 @@ misc_float_compare(gfloat first, gfloat second) /** Check whether the string is in the string array. */ gboolean -query_misc_string_in_array(const gchar *string, GPtrArray *array) +query_misc_string_in_array(const gchar *string, const GPtrArray *array) { gint i; diff --git a/src/misc.h b/src/misc.h index 8b7638d8..a234f5d7 100644 --- a/src/misc.h +++ b/src/misc.h @@ -59,7 +59,7 @@ gint misc_float_compare(gfloat first, gfloat second); gboolean -query_misc_string_in_array(const gchar *string, GPtrArray *array); +query_misc_string_in_array(const gchar *string, const GPtrArray *array); gboolean query_misc_integer_is_in_g_array(gint item, GArray *array); diff --git a/src/news.c b/src/news.c index 58b81439..78b7ac3d 100644 --- a/src/news.c +++ b/src/news.c @@ -105,7 +105,7 @@ news_select(const GArray *news_array, gchar *title, gchar *subtitle, const NewsArticle *article; gint order_articles[news_array->len]; - math_generate_permutation(order_articles, 0, news_array->len - 1); + news_articles_get_order(news_array, order_articles); *title_id = *subtitle_id = -1; @@ -192,8 +192,8 @@ news_check_for_repetition(gint id, gboolean is_title) /** Write a random order of indices into the integer array - (only depending on the priority values of the commentaries). - I don't like this implementation of ordering the commentaries + (only depending on the priority values of the news titles). + I don't like this implementation of ordering the titles according to their priority :-P can't think of a better one, though. */ void news_titles_get_order(const GArray *titles, gint *order) @@ -237,6 +237,52 @@ news_titles_get_order(const GArray *titles, gint *order) } } +/** Write a random order of indices into the integer array + (only depending on the priority values of the news articles). + I don't like this implementation of ordering the articles + according to their priority :-P can't think of a better one, though. */ +void +news_articles_get_order(const GArray *articles, gint *order) +{ +#ifdef DEBUG + printf("news_articles_get_order\n"); +#endif + + gint i, j, order_idx = 0; + gint priority_sum = 0, bounds[articles->len + 1]; + + bounds[0] = 0; + + for(i=0;ilen;i++) + { + priority_sum += g_array_index(articles, NewsArticle, i).priority; + bounds[i + 1] = priority_sum; + order[i] = -1; + } + + gint permutation[priority_sum]; + + math_generate_permutation(permutation, 1, priority_sum); + + for(i=0;ilen) + break; + + for(j=0;jlen;j++) + if(bounds[j] < permutation[i] && permutation[i] <= bounds[j + 1]) + { + if(!query_integer_is_in_array(j, order, articles->len)) + { + order[order_idx] = j; + order_idx++; + } + + break; + } + } +} + /** Set match-related tokens for the news. */ void news_set_match_tokens(const LiveGame *live_game) diff --git a/src/news.h b/src/news.h index 7b632161..3de666b0 100644 --- a/src/news.h +++ b/src/news.h @@ -73,4 +73,7 @@ news_set_fixture_tokens(const Fixture *fix); void news_set_rank_tokens(const Fixture *fix); +void +news_articles_get_order(const GArray *articles, gint *order); + #endif diff --git a/src/news_struct.h b/src/news_struct.h index 2f419f00..d26994ad 100644 --- a/src/news_struct.h +++ b/src/news_struct.h @@ -66,6 +66,8 @@ typedef struct /** A condition (if not fulfilled, the article doesn't get shown). */ gchar *condition; + /** Priority of the article. */ + gint priority; } NewsArticle; diff --git a/src/team.c b/src/team.c index 9eaa1a3c..05c5bef1 100644 --- a/src/team.c +++ b/src/team.c @@ -943,7 +943,7 @@ team_get_index(const Team *tm) #endif gint i; - gpointer *teams = league_cup_get_teams(tm->clid); + gpointer *teams = (gpointer*)league_cup_get_teams(tm->clid); if(tm->clid < ID_CUP_START) { diff --git a/src/xml_news.c b/src/xml_news.c index 53139aa2..3ec4f699 100644 --- a/src/xml_news.c +++ b/src/xml_news.c @@ -34,6 +34,7 @@ #define TAG_ARTICLE "news_article" #define TAG_ARTICLE_TYPE "type" #define TAG_ARTICLE_CONDITION "condition" +#define TAG_ARTICLE_PRIORITY "priority" #define TAG_ARTICLE_TITLE "title" #define TAG_ARTICLE_SUBTITLE "subtitle" @@ -54,6 +55,7 @@ enum XmlNewsStates STATE_ARTICLE, STATE_ARTICLE_TYPE, STATE_ARTICLE_CONDITION, + STATE_ARTICLE_PRIORITY, STATE_ARTICLE_TITLE, STATE_ARTICLE_SUBTITLE, STATE_END @@ -124,11 +126,14 @@ xml_news_read_start_element (GMarkupParseContext *context, new_article.titles = g_array_new(FALSE, FALSE, sizeof(NewsText)); new_article.subtitles = g_array_new(FALSE, FALSE, sizeof(NewsText)); new_article.condition = g_strdup("0"); + new_article.priority = 1; } else if(strcmp(element_name, TAG_ARTICLE_TYPE) == 0) state = STATE_ARTICLE_TYPE; else if(strcmp(element_name, TAG_ARTICLE_CONDITION) == 0) state = STATE_ARTICLE_CONDITION; + else if(strcmp(element_name, TAG_ARTICLE_PRIORITY) == 0) + state = STATE_ARTICLE_PRIORITY; else if(strcmp(element_name, TAG_ARTICLE_TITLE) == 0) { state = STATE_ARTICLE_TITLE; @@ -190,6 +195,7 @@ xml_news_read_end_element (GMarkupParseContext *context, 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 || strcmp(element_name, TAG_ARTICLE_TITLE) == 0 || strcmp(element_name, TAG_ARTICLE_SUBTITLE) == 0) state = STATE_ARTICLE; @@ -216,16 +222,21 @@ xml_news_read_text (GMarkupParseContext *context, #endif gchar buf[text_len + 1]; + gint int_value; strncpy(buf, text, text_len); buf[text_len] = '\0'; + 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) article_idx = xml_news_article_type_to_int(buf); else if(state == STATE_ARTICLE_CONDITION) misc_string_assign(&new_article.condition, buf); + else if(state == STATE_ARTICLE_PRIORITY) + new_article.priority = int_value; else if(state == STATE_ARTICLE_TITLE) { new_title.text = g_strdup(buf);