diff --git a/src/free.c b/src/free.c index 0e905cc2..9d812138 100644 --- a/src/free.c +++ b/src/free.c @@ -53,6 +53,7 @@ free_memory(void) free_live_game(&live_game_temp); free_lg_commentary(FALSE); free_news(FALSE); + free_newspaper(FALSE); free_support_dirs(); free_jobs(FALSE); } @@ -709,7 +710,7 @@ free_lg_commentary(gboolean reset) lg_commentary[i] = g_array_new(FALSE, FALSE, sizeof(LGCommentary)); } -/** Free the list with live game commentary text. */ +/** Free the news variables. */ void free_news(gboolean reset) { @@ -745,6 +746,31 @@ free_news(gboolean reset) news[i] = g_array_new(FALSE, FALSE, sizeof(NewsArticle)); } +void +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); + g_free(g_array_index(newspaper.articles, NewsPaperArticle, i).subtitle); + } + + g_array_free(newspaper.articles, TRUE); + + if(reset) + { + newspaper.names = g_ptr_array_new(); + newspaper.articles = g_array_new(FALSE, FALSE, sizeof(NewsPaperArticle)); + } +} + /** Free a GPtrArray containing strings. @param array The array to be freed. diff --git a/src/free.h b/src/free.h index 7d406fe9..647cd749 100644 --- a/src/free.h +++ b/src/free.h @@ -149,4 +149,7 @@ free_jobs(gboolean reset); void free_news(gboolean reset); +void +free_newspaper(gboolean reset); + #endif diff --git a/src/lg_commentary.c b/src/lg_commentary.c index c134a036..e8e25151 100644 --- a/src/lg_commentary.c +++ b/src/lg_commentary.c @@ -167,25 +167,13 @@ lg_commentary_check_commentary(const LGCommentary *commentary, gchar *dest) printf("lg_commentary_check_commentary\n"); #endif - gchar buf[SMALL]; - if(strlen(commentary->text) == 0 || (commentary->condition != NULL && !misc_parse_condition(commentary->condition, token_rep)) || (repetition == FALSE && query_lg_commentary_is_repetition(commentary->id))) return FALSE; - strcpy(dest, commentary->text); - - do - { - strcpy(buf, dest); - misc_string_replace_tokens(dest, token_rep); - misc_string_replace_expressions(dest); - } - while(strcmp(buf, dest) != 0); - - return (g_strrstr(dest, "_") == NULL); + return misc_string_replace_all_tokens(token_rep, commentary->text, dest); } /** Check whether a commentary with given id has been used in the last diff --git a/src/main.c b/src/main.c index 3775d4ea..e92d31c3 100644 --- a/src/main.c +++ b/src/main.c @@ -239,6 +239,9 @@ main_init_variables(void) for(i=0;i +#include +#include "cup.h" #include "file.h" +#include "fixture.h" #include "language.h" +#include "league.h" #include "main.h" +#include "maths.h" +#include "misc.h" #include "news.h" +#include "option.h" +#include "team.h" #include "variables.h" #include "xml_news.h" /** The replacement strings for the news tokens. */ GPtrArray *token_rep[2]; -/** Whether there was a news repetition rejection. */ -gboolean repetition; -/* /\** Generate news for the live game event in the unit. */ -/* @param live_game The live game being calculated. */ -/* @param unit The live game unit we generate the news for. */ -/* @param event_type The event type we generate the news for (needed */ -/* when news is being tested). *\/ */ -/* void */ -/* news_generate(const LiveGame *live_game, LiveGameUnit *unit, */ -/* const gchar *event_name, gint ev_type) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_generate\n"); */ -/* #endif */ +/** Generate news for a user live game or a CPU fixture. */ +void +news_generate_match(const LiveGame *live_game, const Fixture *fix) +{ +#ifdef DEBUG + printf("news_generate_match\n"); +#endif -/* gint i, event_type = -1; */ -/* gint news_idx = -1; */ -/* gchar buf[SMALL]; */ -/* GArray *commentaries = NULL; */ - -/* if(unit != NULL) */ -/* event_type = unit->event.type; */ -/* else */ -/* event_type = (event_name == NULL) ? ev_type : */ -/* xml_news_event_name_to_int(event_name); */ - -/* if(event_type == -1) */ -/* return; */ - -/* if(live_game != NULL) */ -/* { */ -/* news_set_basic_tokens(unit, live_game->fix); */ -/* news_set_team_tokens(unit, live_game->fix); */ -/* news_set_player_tokens(unit, live_game->fix); */ -/* news_set_stats_tokens(&live_game->stats); */ -/* } */ + gchar title[SMALL], subtitle[SMALL]; + gint title_id, subtitle_id; + NewsPaperArticle new_article; -/* if(event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND || */ -/* event_type == LIVE_GAME_EVENT_STYLE_CHANGE_DEFEND || */ -/* event_type == LIVE_GAME_EVENT_STYLE_CHANGE_BALANCED || */ -/* event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ATTACK || */ -/* event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_ATTACK) */ -/* commentaries = news[LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND]; */ -/* else if(event_type == LIVE_GAME_EVENT_BOOST_CHANGE_ANTI || */ -/* event_type == LIVE_GAME_EVENT_BOOST_CHANGE_OFF || */ -/* event_type == LIVE_GAME_EVENT_BOOST_CHANGE_ON) */ -/* commentaries = news[LIVE_GAME_EVENT_BOOST_CHANGE_ANTI]; */ -/* else */ -/* commentaries = news[event_type]; */ + token_rep[0] = g_ptr_array_new(); + token_rep[1] = g_ptr_array_new(); -/* news_idx = news_select(commentaries, buf); */ + news_set_match_tokens(live_game, fix); -/* if(news_idx == -1) */ -/* g_warning("news_generate: didn't find fitting news for unit type %d \n", */ -/* event_type); */ + news_select(news[NEWS_ARTICLE_TYPE_MATCH], title, subtitle, + &title_id, &subtitle_id); -/* if(live_game != NULL) */ -/* { */ -/* unit->event.news = g_strdup(buf); */ -/* unit->event.news_id = (news_idx == -1) ? */ -/* -1 : g_array_index(commentaries, LGNews, news_idx).id; */ - -/* for(i=0;ilen;i++) */ -/* if(i != option_int("string_token_team_home", &tokens) && */ -/* i != option_int("string_token_team_away", &tokens) && */ -/* i != option_int("string_token_attendance", &tokens) && */ -/* i != option_int("string_token_cup_round_name", &tokens) && */ -/* i != option_int("string_token_league_cup_name", &tokens) && */ -/* i != option_int("string_token_yellow_limit", &tokens) && */ -/* i != option_int("string_token_team_layer0", &tokens) && */ -/* i != option_int("string_token_team_layer1", &tokens)) */ -/* misc_token_remove(token_rep, i); */ -/* } */ -/* else */ -/* g_print("%s: \"%s\"\n", event_name, buf); */ -/* } */ + if(title_id != -1 && subtitle_id != -1) + { + new_article.week_number = week; + new_article.week_round_number = week_round; + new_article.title = g_strdup(title); + new_article.subtitle = g_strdup(subtitle); + new_article.title_id = title_id; + new_article.subtitle_id = subtitle_id; +// printf("%s / %s -- %d %d\n", title, subtitle, title_id, subtitle_id); + g_array_append_val(newspaper.articles, new_article); + } -/* /\** Select a news from the array depending on the tokens */ -/* available and write the text into the buffer. *\/ */ -/* gint */ -/* news_select(const GArray *commentaries, gchar *buf) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_select\n"); */ -/* #endif */ + news_free_tokens(); +} -/* gint i, order[commentaries->len]; */ +/** Select a news from the array depending on the tokens + 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) +{ +#ifdef DEBUG + printf("news_select\n"); +#endif -/* news_get_order(commentaries, order); */ + gint i; + const NewsArticle *article; -/* repetition = FALSE; */ + *title_id = *subtitle_id = -1; -/* for(i=0;ilen;i++) */ -/* if(news_check_news(&g_array_index(commentaries, LGNews, order[i]), buf)) */ -/* break; */ + for(i=0;ilen;i++) + if(news_check_article_condition(&g_array_index(news_array, NewsArticle, i))) + break; -/* if(i == commentaries->len) */ -/* { */ -/* repetition = TRUE; */ -/* for(i=0;ilen;i++) */ -/* if(news_check_news(&g_array_index(commentaries, LGNews, order[i]), buf)) */ -/* break; */ -/* } */ + if(i == news_array->len) + return; -/* if(i == commentaries->len) */ -/* { */ -/* strcpy(buf, "FIXME!"); */ -/* return -1; */ -/* } */ + article = &g_array_index(news_array, NewsArticle, i); -/* return order[i]; */ -/* } */ + gint order_titles[article->titles->len], + order_subtitles[article->subtitles->len]; + news_titles_get_order(article->titles, order_titles); + news_titles_get_order(article->subtitles, order_subtitles); -/* /\** Check whether the news conditions are fulfilled and whether */ -/* we can replace all tokens in the news. *\/ */ -/* gboolean */ -/* news_check_news(const LGNews *news, gchar *dest) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_check_news\n"); */ -/* #endif */ + *title_id = news_get_title(article->titles, title, order_titles, TRUE, FALSE); + if(*title_id == -1) + *title_id = news_get_title(article->titles, title, order_titles, TRUE, TRUE); -/* gchar buf[SMALL]; */ + *subtitle_id = news_get_title(article->subtitles, subtitle, order_subtitles, FALSE, FALSE); + if(*subtitle_id == -1) + *subtitle_id = news_get_title(article->subtitles, subtitle, order_subtitles, FALSE, TRUE); -/* if(strlen(news->text) == 0 || */ -/* (news->condition != NULL && */ -/* !misc_parse_condition(news->condition, token_rep)) || */ -/* (repetition == FALSE && query_news_is_repetition(news->id))) */ -/* return FALSE; */ + return; +} + +/** Try to find a news article title with valid tokens. */ +gint +news_get_title(const GArray *titles, gchar *title, gint *order, + gboolean is_title, gboolean ignore_repetition) +{ + gint i; + gint result; + + for(i = 0; i < titles->len; i++) + { + if(misc_string_replace_all_tokens(token_rep, 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)) + return result; + else + continue; + } + } + + return -1; +} + +/** Check whether a news article text has occurred in the paper recently. */ +gboolean +news_check_for_repetition(gint id, gboolean is_title) +{ + 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((is_title && g_array_index(newspaper.articles, NewsPaperArticle, i).title_id == id) || + (!is_title && g_array_index(newspaper.articles, NewsPaperArticle, i).subtitle_id == id)) + return TRUE; + + return FALSE; +} + +/** Check whether the news conditions are fulfilled and whether + we can replace all tokens in the news. */ +gboolean +news_check_article_condition(const NewsArticle *news_article) +{ +#ifdef DEBUG + printf("news_check_article_condition\n"); +#endif + + if(!misc_parse_condition(news_article->condition, token_rep))/* || */ +/* (repetition == FALSE && query_news_is_repetition(news_article->id))) */ + return FALSE; /* strcpy(dest, news->text); */ @@ -176,10 +183,11 @@ gboolean repetition; /* while(strcmp(buf, dest) != 0); */ /* return (g_strrstr(dest, "_") == NULL); */ -/* } */ + return TRUE; +} -/* /\** Check whether a news with given id has been used in the last */ -/* few commentaries. Return TRUE if so and FALSE otherwise. *\/ */ +/** Check whether a news with given id has been used in the last + few commentaries. Return TRUE if so and FALSE otherwise. */ /* gboolean */ /* query_news_is_repetition(gint id) */ /* { */ @@ -198,442 +206,197 @@ gboolean repetition; /* return FALSE; */ /* } */ -/* /\** 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 */ -/* according to their priority :-P can't think of a better one, though. *\/ */ -/* void */ -/* news_get_order(const GArray *commentaries, gint *order) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_get_order\n"); */ -/* #endif */ +/** 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 + according to their priority :-P can't think of a better one, though. */ +void +news_titles_get_order(const GArray *titles, gint *order) +{ +#ifdef DEBUG + printf("news_titles_get_order\n"); +#endif -/* gint i, j, order_idx = 0; */ -/* gint priority_sum = 0, bounds[commentaries->len + 1]; */ + gint i, j, order_idx = 0; + gint priority_sum = 0, bounds[titles->len + 1]; -/* bounds[0] = 0; */ + bounds[0] = 0; -/* for(i=0;ilen;i++) */ -/* { */ -/* priority_sum += g_array_index(commentaries, LGNews, i).priority; */ -/* bounds[i + 1] = priority_sum; */ -/* order[i] = -1; */ -/* } */ + for(i=0;ilen;i++) + { + priority_sum += g_array_index(titles, NewsText, i).priority; + bounds[i + 1] = priority_sum; + order[i] = -1; + } -/* gint permutation[priority_sum]; */ + gint permutation[priority_sum]; -/* math_generate_permutation(permutation, 1, priority_sum); */ + math_generate_permutation(permutation, 1, priority_sum); -/* for(i=0;ilen) */ -/* break; */ + 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, commentaries->len)) */ -/* { */ -/* order[order_idx] = j; */ -/* order_idx++; */ -/* } */ + for(j=0;jlen;j++) + if(bounds[j] < permutation[i] && permutation[i] <= bounds[j + 1]) + { + if(!query_integer_is_in_array(j, order, titles->len)) + { + order[order_idx] = j; + order_idx++; + } -/* break; */ -/* } */ -/* } */ -/* } */ + break; + } + } +} -/* /\** Fill the stats tokens. *\/ */ -/* void */ -/* news_set_stats_tokens(const LiveGameStats *stats) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_set_stats_tokens\n"); */ -/* #endif */ +/** Set match-related tokens for the news. */ +void +news_set_match_tokens(const LiveGame *live_game, const Fixture *fix_) +{ +#ifdef DEBUG + printf("news_set_match_tokens\n"); +#endif -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_shots0", &tokens), */ -/* misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_SHOTS])); */ + gchar buf[SMALL]; + const Fixture *fix; + gint avskill0, avskill1; + const Cup *cup; + const CupRound *cupround; -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_shot_per0", &tokens), */ -/* misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_SHOT_PERCENTAGE])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_poss0", &tokens), */ -/* misc_int_to_char((gint)rint(100 * */ -/* ((gfloat)stats->values[0][LIVE_GAME_STAT_VALUE_POSSESSION] / */ -/* ((gfloat)stats->values[0][LIVE_GAME_STAT_VALUE_POSSESSION] + */ -/* (gfloat)stats->values[1][LIVE_GAME_STAT_VALUE_POSSESSION]))))); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_pen0", &tokens), */ -/* misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_PENALTIES])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_fouls0", &tokens), */ -/* misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_FOULS])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_yellows0", &tokens), */ -/* misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_CARDS])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_reds0", &tokens), */ -/* misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_REDS])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_injs0", &tokens), */ -/* misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_INJURIES])); */ + fix = (live_game == NULL) ? fix_ : live_game->fix; -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_shots1", &tokens), */ -/* misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_SHOTS])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_shot_per1", &tokens), */ -/* misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_SHOT_PERCENTAGE])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_poss1", &tokens), */ -/* misc_int_to_char((gint)rint(100 * ((gfloat)stats->values[1][LIVE_GAME_STAT_VALUE_POSSESSION] / */ -/* ((gfloat)stats->values[0][LIVE_GAME_STAT_VALUE_POSSESSION] + */ -/* (gfloat)stats->values[1][LIVE_GAME_STAT_VALUE_POSSESSION]))))); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_pen1", &tokens), */ -/* misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_PENALTIES])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_fouls1", &tokens), */ -/* misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_FOULS])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_yellows1", &tokens), */ -/* misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_CARDS])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_reds1", &tokens), */ -/* misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_REDS])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_stat_injs1", &tokens), */ -/* misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_INJURIES])); */ -/* } */ + token_rep[0] = g_ptr_array_new(); + token_rep[1] = g_ptr_array_new(); -/* /\** Fill the tokens that contain general information. *\/ */ -/* void */ -/* news_set_basic_tokens(const LiveGameUnit *unit, const Fixture *fix) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_set_basic_tokens\n"); */ -/* #endif */ + avskill0 = (gint)rint(team_get_average_skill(fix->teams[0], TRUE)); + avskill1 = (gint)rint(team_get_average_skill(fix->teams[1], TRUE)); -/* gchar buf[SMALL]; */ -/* gint tmp_int = 1, current_min = live_game_unit_get_minute(unit); */ -/* gint avskill0 = (gint)rint(team_get_average_skill(fix->teams[0], TRUE)), */ -/* avskill1 = (gint)rint(team_get_average_skill(fix->teams[1], TRUE)); */ - -/* sprintf(buf, "%d : %d", unit->result[0], unit->result[1]); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_result", &tokens), */ -/* g_strdup(buf)); */ + fixture_result_to_buf(fix, buf, FALSE); + misc_token_add(token_rep, + option_int("string_token_result", &tokens), + g_strdup(buf)); -/* misc_token_add(token_rep, */ -/* option_int("string_token_time", &tokens), */ -/* misc_int_to_char(unit->time)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_minute", &tokens), */ -/* misc_int_to_char(current_min)); */ + misc_token_add(token_rep, + option_int("string_token_goals0", &tokens), + misc_int_to_char(fix->result[0][0])); + misc_token_add(token_rep, + option_int("string_token_goals1", &tokens), + misc_int_to_char(fix->result[1][0])); + misc_token_add(token_rep, + option_int("string_token_goal_diff", &tokens), + misc_int_to_char(ABS(fix->result[0][0] - fix->result[1][0]))); -/* tmp_int = live_game_get_minutes_remaining(unit); */ - -/* if(tmp_int > 0) */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_minute_remaining", &tokens), */ -/* misc_int_to_char(tmp_int)); */ + misc_token_add(token_rep, + option_int("string_token_team_home", &tokens), + g_strdup(fix->teams[0]->name)); + misc_token_add(token_rep, + option_int("string_token_team_away", &tokens), + g_strdup(fix->teams[1]->name)); -/* if(query_fixture_is_draw(fix)) */ -/* tmp_int = 120 - current_min; */ -/* else */ -/* tmp_int = 90 - current_min; */ + if(fix->result[0][0] != fix->result[1][0]) + { + misc_token_add(token_rep, + option_int("string_token_team_losing", &tokens), + g_strdup(fix->teams[(fix->result[0][0] > fix->result[1][0])]->name)); + misc_token_add(token_rep, + option_int("string_token_team_winning", &tokens), + g_strdup(fix->teams[(fix->result[0][0] < fix->result[1][0])]->name)); + misc_token_add(token_rep, + option_int("string_token_team_losingn", &tokens), + misc_int_to_char((fix->result[0][0] > fix->result[1][0]))); + misc_token_add(token_rep, + option_int("string_token_team_winningn", &tokens), + misc_int_to_char((fix->result[0][0] < fix->result[1][0]))); + } -/* if(tmp_int > 0) */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_minute_total", &tokens), */ -/* misc_int_to_char(tmp_int)); */ - -/* misc_token_add(token_rep, */ -/* option_int("string_token_goals0", &tokens), */ -/* misc_int_to_char(unit->result[0])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_goals1", &tokens), */ -/* misc_int_to_char(unit->result[1])); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_goal_diff", &tokens), */ -/* misc_int_to_char(ABS(unit->result[0] - unit->result[1]))); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_extra", &tokens), */ -/* news_get_extra_data(unit, fix)); */ - -/* misc_token_add(token_rep, */ -/* option_int("string_token_possession", &tokens), */ -/* misc_int_to_char(unit->possession)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_no_possession", &tokens), */ -/* misc_int_to_char(!unit->possession)); */ - -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_avskill0", &tokens), */ -/* misc_int_to_char(avskill0)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_avskill1", &tokens), */ -/* misc_int_to_char(avskill1)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_avskilldiff", &tokens), */ -/* misc_int_to_char(ABS(avskill0 - avskill1))); */ -/* } */ - -/* /\** Set the tokens containing team data. *\/ */ -/* void */ -/* news_set_team_tokens(const LiveGameUnit *unit, const Fixture *fix) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_set_team_tokens\n"); */ -/* #endif */ - -/* if(unit->result[0] != unit->result[1]) */ -/* { */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_losing", &tokens), */ -/* g_strdup(fix->teams[(unit->result[0] > unit->result[1])]->name)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_winning", &tokens), */ -/* g_strdup(fix->teams[(unit->result[0] < unit->result[1])]->name)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_losingn", &tokens), */ -/* misc_int_to_char((unit->result[0] > unit->result[1]))); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_winningn", &tokens), */ -/* misc_int_to_char((unit->result[0] < unit->result[1]))); */ -/* } */ - -/* if(unit->event.team != -1) */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team", &tokens), */ -/* misc_int_to_char(unit->event.team)); */ -/* } */ - -/* /\** Set the player tokens. *\/ */ -/* void */ -/* news_set_player_tokens(const LiveGameUnit *unit, const Fixture *fix) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_set_player_tokens\n"); */ -/* #endif */ - -/* Player *pl1 = NULL, */ -/* *pl2 = NULL; */ - -/* if(unit->event.type == LIVE_GAME_EVENT_GENERAL || */ -/* unit->event.type == LIVE_GAME_EVENT_SCORING_CHANCE || */ -/* unit->event.type == LIVE_GAME_EVENT_HEADER || */ -/* unit->event.type == LIVE_GAME_EVENT_PENALTY || */ -/* unit->event.type == LIVE_GAME_EVENT_FREE_KICK) */ -/* { */ -/* pl1 = player_of_id_team(fix->teams[unit->possession], */ -/* unit->event.player); */ - -/* if(unit->event.player2 != -1) */ -/* pl2 = player_of_id_team(fix->teams[unit->possession], */ -/* unit->event.player2); */ -/* } */ -/* else if(unit->event.type == LIVE_GAME_EVENT_SEND_OFF || */ -/* unit->event.type == LIVE_GAME_EVENT_INJURY || */ -/* unit->event.type == LIVE_GAME_EVENT_TEMP_INJURY || */ -/* unit->event.type == LIVE_GAME_EVENT_SUBSTITUTION) */ -/* { */ -/* pl1 = player_of_id_team(fix->teams[unit->event.team], */ -/* unit->event.player); */ -/* if(unit->event.player2 != -1) */ -/* pl2 = player_of_id_team(fix->teams[unit->event.team], */ -/* unit->event.player2); */ -/* } */ -/* else if(unit->event.type == LIVE_GAME_EVENT_LOST_POSSESSION || */ -/* unit->event.type == LIVE_GAME_EVENT_GOAL || */ -/* unit->event.type == LIVE_GAME_EVENT_MISS || */ -/* unit->event.type == LIVE_GAME_EVENT_SAVE || */ -/* unit->event.type == LIVE_GAME_EVENT_POST || */ -/* unit->event.type == LIVE_GAME_EVENT_CROSS_BAR) */ -/* { */ -/* pl1 = player_of_id_team(fix->teams[unit->possession], */ -/* unit->event.player); */ -/* pl2 = player_of_id_team(fix->teams[!unit->possession], */ -/* unit->event.player2); */ -/* } */ -/* else if(unit->event.type == LIVE_GAME_EVENT_OWN_GOAL) */ -/* pl1 = player_of_id_team(fix->teams[!unit->possession], */ -/* unit->event.player); */ -/* else if(unit->event.type == LIVE_GAME_EVENT_FOUL || */ -/* unit->event.type == LIVE_GAME_EVENT_FOUL_RED || */ -/* unit->event.type == LIVE_GAME_EVENT_FOUL_RED_INJURY || */ -/* unit->event.type == LIVE_GAME_EVENT_FOUL_YELLOW) */ -/* { */ -/* pl1 = player_of_id_team(fix->teams[!unit->event.team], */ -/* unit->event.player); */ -/* pl2 = player_of_id_team(fix->teams[unit->event.team], */ -/* unit->event.player2); */ -/* } */ - -/* if(pl1 != NULL) */ -/* { */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_player0", &tokens), */ -/* player_get_last_name(pl1->name)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_player_goals0", &tokens), */ -/* misc_int_to_char(player_games_goals_get( */ -/* pl1, fix->clid, PLAYER_VALUE_GOALS))); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_player_goals_all0", &tokens), */ -/* misc_int_to_char(player_all_games_goals(pl1, PLAYER_VALUE_GOALS))); */ -/* } */ - -/* if(pl2 != NULL) */ -/* { */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_player1", &tokens), */ -/* player_get_last_name(pl2->name)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_player_goals1", &tokens), */ -/* misc_int_to_char(player_games_goals_get(pl2, fix->clid, PLAYER_VALUE_GOALS))); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_player_goals_all1", &tokens), */ -/* misc_int_to_char(player_all_games_goals(pl2, PLAYER_VALUE_GOALS))); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_player_yellows", &tokens), */ -/* misc_int_to_char(player_card_get(pl2, fix->clid, PLAYER_VALUE_CARD_YELLOW))); */ -/* } */ -/* } */ - -/* /\** Return some extra data depending on the unit type. *\/ */ -/* gchar* */ -/* news_get_extra_data(const LiveGameUnit *unit, const Fixture *fix) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_get_extra_data\n"); */ -/* #endif */ - -/* #ifdef DEBUG */ -/* printf("news_get_extra_data\n"); */ -/* #endif */ - -/* gchar buf[SMALL]; */ - -/* switch(unit->event.type) */ -/* { */ -/* default: */ -/* return NULL; */ -/* break; */ -/* case LIVE_GAME_EVENT_STRUCTURE_CHANGE: */ -/* sprintf(buf, "%d", */ -/* fix->teams[unit->event.team]->structure); */ -/* break; */ -/* case LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND: */ -/* strcpy(buf, _("ALL OUT DEFEND")); */ -/* break; */ -/* case LIVE_GAME_EVENT_STYLE_CHANGE_DEFEND: */ -/* strcpy(buf, _("DEFEND")); */ -/* break; */ -/* case LIVE_GAME_EVENT_STYLE_CHANGE_BALANCED: */ -/* strcpy(buf, _("BALANCED")); */ -/* break; */ -/* case LIVE_GAME_EVENT_STYLE_CHANGE_ATTACK: */ -/* strcpy(buf, _("ATTACK")); */ -/* break; */ -/* case LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_ATTACK: */ -/* strcpy(buf, _("ALL OUT ATTACK")); */ -/* break; */ -/* case LIVE_GAME_EVENT_BOOST_CHANGE_ANTI: */ -/* strcpy(buf, _("ANTI")); */ -/* break; */ -/* case LIVE_GAME_EVENT_BOOST_CHANGE_OFF: */ -/* strcpy(buf, _("OFF")); */ -/* break; */ -/* case LIVE_GAME_EVENT_BOOST_CHANGE_ON: */ -/* strcpy(buf, _("ON")); */ -/* break; */ -/* } */ - -/* return g_strdup(buf); */ -/* } */ - -/* /\** Allocate memory for the token array and fill some tokens */ -/* at the beginning of the live game that don't change later. *\/ */ -/* void */ -/* news_initialize(const Fixture *fix) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_initialize\n"); */ -/* #endif */ - -/* gchar buf[SMALL]; */ - -/* token_rep[0] = g_ptr_array_new(); */ -/* token_rep[1] = g_ptr_array_new(); */ - -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_home", &tokens), */ -/* g_strdup(fix->teams[0]->name)); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_away", &tokens), */ -/* g_strdup(fix->teams[1]->name)); */ - -/* if(fix->teams[0]->clid < ID_CUP_START) */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_layer0", &tokens), */ -/* misc_int_to_char(league_from_clid(fix->teams[0]->clid)->layer)); */ -/* if(fix->teams[1]->clid < ID_CUP_START) */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_layer1", &tokens), */ -/* misc_int_to_char(league_from_clid(fix->teams[1]->clid)->layer)); */ + if(fix->teams[0]->clid < ID_CUP_START) + misc_token_add(token_rep, + option_int("string_token_team_layer0", &tokens), + misc_int_to_char(league_from_clid(fix->teams[0]->clid)->layer)); + if(fix->teams[1]->clid < ID_CUP_START) + misc_token_add(token_rep, + option_int("string_token_team_layer1", &tokens), + misc_int_to_char(league_from_clid(fix->teams[1]->clid)->layer)); -/* if(fix->teams[0]->clid < ID_CUP_START && */ -/* fix->teams[1]->clid < ID_CUP_START) */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_team_layerdiff", &tokens), */ -/* misc_int_to_char(league_from_clid(fix->teams[0]->clid)->layer - */ -/* league_from_clid(fix->teams[1]->clid)->layer)); */ + if(fix->teams[0]->clid < ID_CUP_START && + fix->teams[1]->clid < ID_CUP_START) + misc_token_add(token_rep, + option_int("string_token_team_layerdiff", &tokens), + misc_int_to_char(league_from_clid(fix->teams[0]->clid)->layer - + league_from_clid(fix->teams[1]->clid)->layer)); -/* misc_token_add(token_rep, */ -/* option_int("string_token_league_cup_name", &tokens), */ -/* g_strdup(league_cup_get_name_string(fix->clid))); */ + misc_token_add(token_rep, + option_int("string_token_league_cup_name", &tokens), + g_strdup(league_cup_get_name_string(fix->clid))); -/* if(fix->clid >= ID_CUP_START) */ -/* { */ -/* cup_get_round_name(cup_from_clid(fix->clid), fix->round, buf); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_cup_round_name", &tokens), */ -/* g_strdup(buf)); */ -/* } */ + if(fix->clid >= ID_CUP_START) + { + cup = cup_from_clid(fix->clid); + cupround = &g_array_index(cup->rounds, CupRound, fix->round); -/* misc_print_grouped_int(fix->attendance, buf); */ -/* misc_token_add(token_rep, */ -/* option_int("string_token_attendance", &tokens), */ -/* g_strdup(buf)); */ + misc_token_add(token_rep, + option_int("string_token_cup", &tokens), + g_strdup("1")); -/* misc_token_add(token_rep, */ -/* option_int("string_token_yellow_limit", &tokens), */ -/* misc_int_to_char(league_cup_get_yellow_red(fix->clid))); */ -/* } */ + cup_get_round_name(cup, fix->round, buf); + misc_token_add(token_rep, + option_int("string_token_cup_round_name", &tokens), + g_strdup(buf)); -/* /\** Free the memory occupied by the tokens array and the permanent tokens. *\/ */ -/* void */ -/* news_free_tokens(void) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_free_tokens\n"); */ -/* #endif */ + if(cupround->tables->len > 0) + { + misc_token_add(token_rep, + option_int("string_token_cup_knockout", &tokens), + g_strdup("0")); + misc_token_add(token_rep, + option_int("string_token_cup_round_robin", &tokens), + g_strdup("1")); + } + else + { + misc_token_add(token_rep, + option_int("string_token_cup_knockout", &tokens), + g_strdup("1")); + misc_token_add(token_rep, + option_int("string_token_cup_round_robin", &tokens), + g_strdup("0")); -/* gint i; */ + } + + if(fix->decisive) + misc_token_add(token_rep, + option_int("string_token_cup_match_winner", &tokens), + ((Team*)fixture_winner_of(fix, FALSE))->name); + } -/* for(i=token_rep[0]->len - 1;i >= 0; i--) */ -/* { */ -/* g_free(g_ptr_array_index(token_rep[0], i)); */ -/* g_free(g_ptr_array_index(token_rep[1], i)); */ -/* } */ + misc_print_grouped_int(fix->attendance, buf); + misc_token_add(token_rep, + option_int("string_token_attendance", &tokens), + g_strdup(buf)); +} -/* g_ptr_array_free(token_rep[0], TRUE); */ -/* g_ptr_array_free(token_rep[1], TRUE); */ -/* } */ +/** Free the memory occupied by the tokens array and the permanent tokens. */ +void +news_free_tokens(void) +{ +#ifdef DEBUG + printf("news_free_tokens\n"); +#endif + + gint i; + + for(i=token_rep[0]->len - 1;i >= 0; i--) + { + g_free(g_ptr_array_index(token_rep[0], i)); + g_free(g_ptr_array_index(token_rep[1], i)); + } + + g_ptr_array_free(token_rep[0], TRUE); + g_ptr_array_free(token_rep[1], TRUE); +} /** Load the appropriate news file by evaluating the language option. */ @@ -687,60 +450,3 @@ news_load_news_file(const gchar *news_file, gboolean abort) news_load_news_file("news_en.xml", TRUE); } } - -/* /\** Load a file with tokens for news testing purposes. *\/ */ -/* void */ -/* news_test_load_token_file(const gchar *token_file) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_test_load_token_file\n"); */ -/* #endif */ - -/* gchar token_name[SMALL], token_value[SMALL]; */ -/* FILE *fil = NULL; */ - -/* file_my_fopen(token_file, "r", &fil, TRUE); */ - -/* token_rep[0] = g_ptr_array_new(); */ -/* token_rep[1] = g_ptr_array_new(); */ - -/* while(file_get_next_opt_line(fil, token_name, token_value)) */ -/* { */ -/* g_ptr_array_add(token_rep[0], (gpointer)g_strdup(token_name)); */ -/* g_ptr_array_add(token_rep[1], (gpointer)g_strdup(token_value)); */ -/* } */ -/* } */ - -/* /\** Test a live game news file. */ -/* @param news_file the news file to test. */ -/* @param token_file the file containing the token values to use. */ -/* @param event_name the event to test (or 'all' to test all events). */ -/* @param number_of_passes how many commentaries to generate. *\/ */ -/* void */ -/* news_test(const gchar *news_file, const gchar* token_file, */ -/* const gchar *event_name, gint number_of_passes) */ -/* { */ -/* #ifdef DEBUG */ -/* printf("news_test\n"); */ -/* #endif */ - -/* gint i, j; */ -/* LiveGame dummy; */ - -/* news_load_news_file(news_file, TRUE); */ - -/* news_test_load_token_file(token_file); */ - -/* dummy.units = g_array_new(FALSE, FALSE, sizeof(gint)); */ -/* statp = (gpointer)&dummy; */ - -/* if(event_name == NULL) */ -/* for(i=0;i - + Bygfoot Herald + 4TehFans + Football Online + 11vs11 + The Pitch + News Of The Sports World - match_league - cond - title1 - subtitle1 - title2 - subtitle2 - - - - match_national_cup - condn - title1n - subtitle1n - title2n - subtitle2n + match + _GD_ > 1 + _TW_ [beats|crushes|kills] _TL_! + Result: _RE_ + _TL_ loses to _TW_! + _TL_ doesn't stand a chance against a _GOALS_TWN__ goal barrage. + _TW_ wipes out _TL_! + _RE_ is flattering for _TL_. + _TL_ loses again! + _TW_ just too strong. + _TL_ in a world of misery! + _TW_: _RE_ against _TL_. diff --git a/support_files/news/news_en.xml b/support_files/news/news_en.xml index e3c30a50..eceb3308 100644 --- a/support_files/news/news_en.xml +++ b/support_files/news/news_en.xml @@ -1,21 +1,23 @@ - + Bygfoot Herald + 4TehFans + Football Online + 11vs11 + The Pitch + News Of The Sports World - match_league - cond - title1 - subtitle1 - title2 - subtitle2 - - - - match_national_cup - condn - title1n - subtitle1n - title2n - subtitle2n + match + _GD_ > 1 + _TW_ [beats|crushes|kills] _TL_! + Result: _RE_ + _TL_ loses to _TW_! + _TL_ doesn't stand a chance against a _GOALS_TWN__ goal barrage. + _TW_ wipes out _TL_! + _RE_ is flattering for _TL_. + _TL_ loses again! + _TW_ just too strong. + _TL_ in a world of misery! + _TW_: _RE_ against _TL_.