Newspaper progressing.

This commit is contained in:
gyboth 2008-12-16 11:27:44 +00:00
parent 4481e16c83
commit 9b1534b87c
11 changed files with 76 additions and 40 deletions

View File

@ -1,15 +1,16 @@
06/12/2008: v2.3.1
- updated Chinese translations
- updated Romanian translation
06/01/2009: v2.3.1
- added possibility for multiple tables in leagues (think
apertura/clausura in south america)
- added joined leagues feature (think conferences in US sports)
- added variable round robins for cups and variable breaks between
round robins
- solved some minor bugs
- added clicking in tables and fixtures mode (switches to the
other view, respectively)
- updated Romanian player names
- added new images for simulation
- updated French translation
- added newspaper feature
- updated translations
06/11/2008: v2.3.0

View File

@ -65,6 +65,7 @@
#define lg_commentary_id_new (counters[COUNT_LG_COMM_ID]++)
#define news_title_id_new (counters[COUNT_NEWS_TITLE_ID]++)
#define news_subtitle_id_new (counters[COUNT_NEWS_SUBTITLE_ID]++)
#define news_article_id_new (counters[COUNT_NEWS_ARTICLE_ID]++)
/** Convenience abbreviation. */
#define ligs country.leagues

View File

@ -39,6 +39,7 @@ enum Counters
COUNT_LG_COMM_ID,
COUNT_NEWS_TITLE_ID,
COUNT_NEWS_SUBTITLE_ID,
COUNT_NEWS_ARTICLE_ID,
COUNT_SHOW_DEBUG,
COUNT_HINT_NUMBER,
COUNT_END

View File

@ -1575,15 +1575,13 @@ live_game_finish_unit(void)
treeview_show_user_player_list();
}
game_update_stats(match, unit);
if(stat2 != -1 || stat5 < -1000)
{
if(unit->time != LIVE_GAME_UNIT_TIME_PENALTIES)
{
game_update_stats(match, unit);
if(show)
treeview_show_game_stats(GTK_TREE_VIEW(lookup_widget(window.live, "treeview_stats")),
match);
}
if(unit->time != LIVE_GAME_UNIT_TIME_PENALTIES && show)
treeview_show_game_stats(GTK_TREE_VIEW(lookup_widget(window.live, "treeview_stats")),
match);
lg_commentary_generate(match, unit, NULL, -1);

View File

@ -56,7 +56,7 @@ news_generate_match(const LiveGame *live_game)
gchar title_small[SMALL], buf[SMALL],
title[SMALL], subtitle[SMALL];
gint title_id, subtitle_id;
gint title_id, subtitle_id, article_id;
NewsPaperArticle new_article;
token_rep_news[0] = g_ptr_array_new();
@ -65,10 +65,11 @@ news_generate_match(const LiveGame *live_game)
news_set_match_tokens(live_game);
news_select(news[NEWS_ARTICLE_TYPE_MATCH], title, subtitle,
&title_id, &subtitle_id);
&article_id, &title_id, &subtitle_id);
if(title_id != -1 && subtitle_id != -1)
{
new_article.id = article_id;
new_article.week_number = week;
new_article.week_round_number = week_round;
@ -82,13 +83,7 @@ news_generate_match(const LiveGame *live_game)
new_article.title_id = title_id;
new_article.subtitle_id = subtitle_id;
new_article.user_idx = fixture_user_team_involved(live_game->fix);
/* printf("%s / %s -- %d %d\n", title, subtitle, title_id, subtitle_id); */
g_array_append_val(newspaper.articles, new_article);
/* gint i; */
/* for(i = 0; i < newspaper.articles->len; i++) */
/* printf("%s\n%s\n", g_array_index(newspaper.articles, NewsPaperArticle, i).title, */
/* g_array_index(newspaper.articles, NewsPaperArticle, i).subtitle); */
}
news_free_tokens();
@ -98,7 +93,7 @@ news_generate_match(const LiveGame *live_game)
available and write the texts and ids into the variables. */
void
news_select(const GArray *news_array, gchar *title, gchar *subtitle,
gint *title_id, gint *subtitle_id)
gint *article_id, gint *title_id, gint *subtitle_id)
{
#ifdef DEBUG
printf("news_select\n");
@ -113,18 +108,22 @@ news_select(const GArray *news_array, gchar *title, gchar *subtitle,
*title_id = *subtitle_id = -1;
for(i=0;i<news_array->len;i++)
{
/* printf("cond %s res %d\n", g_array_index(news_array, NewsArticle, order_articles[i]).condition, */
/* misc_parse_condition(g_array_index(news_array, NewsArticle, order_articles[i]).condition, token_rep_news)); */
if(misc_parse_condition(g_array_index(news_array, NewsArticle, order_articles[i]).condition, token_rep_news))
if(!news_check_article_for_repetition(g_array_index(news_array, NewsArticle, order_articles[i]).id) &&
misc_parse_condition(g_array_index(news_array, NewsArticle, order_articles[i]).condition, token_rep_news))
break;
}
if(i == news_array->len)
for(i=0;i<news_array->len;i++)
if(misc_parse_condition(g_array_index(news_array, NewsArticle, order_articles[i]).condition, token_rep_news))
break;
if(i == news_array->len)
return;
article = &g_array_index(news_array, NewsArticle, order_articles[i]);
*article_id = article->id;
gint order_titles[article->titles->len],
order_subtitles[article->subtitles->len];
news_titles_get_order(article->titles, order_titles);
@ -155,13 +154,11 @@ news_get_title(const GArray *titles, gchar *title, gint *order,
for(i = 0; i < titles->len; i++)
{
/* gboolean res = misc_string_replace_all_tokens(token_rep_news, g_array_index(titles, NewsText, order[i]).text, title); */
/* printf("title: %s %d\n", title, res); */
if(misc_parse_condition(g_array_index(titles, NewsText, order[i]).condition, token_rep_news) &&
misc_string_replace_all_tokens(token_rep_news, g_array_index(titles, NewsText, order[i]).text, title))
{
result = g_array_index(titles, NewsText, order[i]).id;
if(ignore_repetition || !news_check_for_repetition(result, is_title))
if(ignore_repetition || !news_check_title_for_repetition(result, is_title))
return result;
else
continue;
@ -173,10 +170,10 @@ news_get_title(const GArray *titles, gchar *title, gint *order,
/** Check whether a news article text has occurred in the paper recently. */
gboolean
news_check_for_repetition(gint id, gboolean is_title)
news_check_title_for_repetition(gint id, gboolean is_title)
{
#ifdef DEBUG
printf("news_check_for_repetition\n");
printf("news_check_title_for_repetition\n");
#endif
gint i;
@ -193,6 +190,26 @@ news_check_for_repetition(gint id, gboolean is_title)
return FALSE;
}
/** Check recent news for article repetition. */
gboolean
news_check_article_for_repetition(gint id)
{
#ifdef DEBUG
printf("news_check_article_for_repetition\n");
#endif
gint i;
gint end;
end = (newspaper.articles->len < const_int("int_news_repetition_check_number")) ?
0 : newspaper.articles->len - const_int("int_news_repetition_check_number");
for(i = newspaper.articles->len - 1; i >= end; i--)
if(g_array_index(newspaper.articles, NewsPaperArticle, i).id == id)
return TRUE;
return FALSE;
}
/** Write a random order of indices into the integer array
(only depending on the priority values of the news titles).
@ -332,10 +349,6 @@ news_set_streak_tokens(const Fixture *fix)
res[0] = math_sum_int_array(((Fixture*)g_ptr_array_index(latest_fixtures, j))->result[0], 3);
res[1] = math_sum_int_array(((Fixture*)g_ptr_array_index(latest_fixtures, j))->result[1], 3);
/* printf("%s %s %d %d str %d %d %d\n", ((Fixture*)g_ptr_array_index(latest_fixtures, j))->teams[0]->name, */
/* ((Fixture*)g_ptr_array_index(latest_fixtures, j))->teams[1]->name, res[0], res[1], */
/* streak_won, streak_lost, streak_unbeaten); */
if(res[0] == res[1])
{
if(streak_lost == 0)
@ -475,8 +488,6 @@ news_set_scorer_tokens(const LiveGameStats *stats)
strcpy(buf, scorer_str);
}
/* printf("%d +%s+ +%s+ %d\n", i, scorer_str, high_scorer, max_goals); */
if(strcmp(scorer_str, "") != 0)
{
sprintf(buf, "string_token_bool_multiple_scorers%d", i);
@ -543,6 +554,10 @@ news_set_league_cup_tokens(const Fixture *fix)
cup = cup_from_clid(fix->clid);
cupround = &g_array_index(cup->rounds, CupRound, fix->round);
misc_token_add(token_rep_news,
option_int("string_token_cup_stage", &tokens),
misc_int_to_char(cup->rounds->len - fix->round));
cup_get_round_name(cup, fix->round, buf);
misc_token_add(token_rep_news,
option_int("string_token_cup_round_name", &tokens),

View File

@ -40,14 +40,17 @@ news_generate_match(const LiveGame *live_game);
void
news_select(const GArray *news_array, gchar *title, gchar *subtitle,
gint *title_id, gint *subtitle_id);
gint *article_id, gint *title_id, gint *subtitle_id);
gint
news_get_title(const GArray *titles, gchar *title, gint *order,
gboolean is_title, gboolean ignore_repetition);
gboolean
news_check_for_repetition(gint id, gboolean is_title);
news_check_article_for_repetition(gint id);
gboolean
news_check_title_for_repetition(gint id, gboolean is_title);
void
news_load_news_file_from_option(void);

View File

@ -68,6 +68,8 @@ typedef struct
gchar *condition;
/** Priority of the article. */
gint priority;
/** An id to avoid repetitions. */
gint id;
} NewsArticle;
@ -77,6 +79,7 @@ typedef struct
gint week_number, week_round_number;
gint title_id, subtitle_id;
gchar *title_small, *title, *subtitle;
gint id;
gint user_idx;
} NewsPaperArticle;

View File

@ -35,6 +35,7 @@ enum
TAG_NEWS_PAPER = TAG_START_NEWS_PAPER,
TAG_NEWS_PAPER_NAME,
TAG_NEWS_PAPER_ARTICLE,
TAG_NEWS_PAPER_ARTICLE_ID,
TAG_NEWS_PAPER_ARTICLE_WEEK,
TAG_NEWS_PAPER_ARTICLE_WEEK_ROUND,
TAG_NEWS_PAPER_ARTICLE_TITLE_ID,
@ -98,6 +99,7 @@ xml_loadsave_newspaper_end_element (GMarkupParseContext *context,
}
else if(tag == TAG_NEWS_PAPER_ARTICLE_WEEK ||
tag == TAG_NEWS_PAPER_ARTICLE_WEEK_ROUND ||
tag == TAG_NEWS_PAPER_ARTICLE_ID ||
tag == TAG_NEWS_PAPER_ARTICLE_TITLE_SMALL ||
tag == TAG_NEWS_PAPER_ARTICLE_TITLE ||
tag == TAG_NEWS_PAPER_ARTICLE_TITLE_ID ||
@ -135,6 +137,8 @@ xml_loadsave_newspaper_text (GMarkupParseContext *context,
new_article.week_number = int_value;
else if(state == TAG_NEWS_PAPER_ARTICLE_WEEK_ROUND)
new_article.week_round_number = int_value;
else if(state == TAG_NEWS_PAPER_ARTICLE_ID)
new_article.id = int_value;
else if(state == TAG_NEWS_PAPER_ARTICLE_TITLE_SMALL)
new_article.title_small = g_strdup(buf);
else if(state == TAG_NEWS_PAPER_ARTICLE_TITLE)
@ -212,6 +216,8 @@ xml_loadsave_newspaper_write(const gchar *prefix)
{
fprintf(fil, "%s<_%d>\n", I0, TAG_NEWS_PAPER_ARTICLE);
xml_write_int(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).id,
TAG_NEWS_PAPER_ARTICLE_ID, I1);
xml_write_int(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).week_number,
TAG_NEWS_PAPER_ARTICLE_WEEK, I1);
xml_write_int(fil, g_array_index(newspaper.articles, NewsPaperArticle, i).week_round_number,

View File

@ -123,6 +123,7 @@ xml_news_read_start_element (GMarkupParseContext *context,
new_article.subtitles = g_array_new(FALSE, FALSE, sizeof(NewsText));
new_article.condition = g_strdup("0");
new_article.priority = 1;
new_article.id = news_article_id_new;
}
else if(strcmp(element_name, TAG_ARTICLE_TYPE) == 0)
state = STATE_ARTICLE_TYPE;

View File

@ -87,8 +87,8 @@ string_token_bool_cup _CUP_
string_token_bool_cup_knockout _CUPKO_
string_token_cup_stage _CUPSTAGE_
string_token_cup_match_winner _CUPMATCHWINNER_
string_token_bool_multiple_scorers0 _MULTIPLESCORERS_
string_token_bool_multiple_scorers1 _MULTIPLESCORERS_
string_token_bool_multiple_scorers0 _MULTIPLESCORERS0_
string_token_bool_multiple_scorers1 _MULTIPLESCORERS1_
string_token_scorers0 _SCORERS0_
string_token_highscorer0 _HIGHSCORER0_
string_token_highscorer_goals0 _HIGHGOALS0_

View File

@ -1,4 +1,11 @@
<news>
<news_article>
<type>match</type>
<condition>_GD_ = 1</condition>
<title>_TW_ beats _TN_</title>
<title>_TN_ succumbs to _TW_ in _LEAGUECUPNAME_</title>
<subtitle>_TW_ edges out _TN_ in a tight match.</subtitle>
</news_article>
<news_article>
<type>match</type>
<condition>_CUP_ = 0 and _GD_ G 1</condition>