Newspaper progressing.

This commit is contained in:
gyboth 2008-11-28 18:10:01 +00:00
parent ab93468b68
commit 669aca19fa
9 changed files with 77 additions and 114 deletions

View File

@ -84,7 +84,7 @@ callback_show_next_live_game(void)
options))
{
live_game_calculate_fixture(&g_array_index(acp(i)->fixtures, Fixture, j));
return;
return;
}
window_destroy(&window.live);

View File

@ -32,6 +32,7 @@
#include "live_game.h"
#include "main.h"
#include "maths.h"
#include "news.h"
#include "misc.h"
#include "option.h"
#include "player.h"
@ -1058,8 +1059,11 @@ game_post_match(Fixture *fix)
GPtrArray *teams = NULL;
Cup *cup = NULL;
gchar buf[SMALL], buf2[SMALL];
gint usr_idx;
if((debug > 100 && fixture_user_team_involved(fix) != -1) ||
usr_idx = fixture_user_team_involved(fix);
if((debug > 100 && usr_idx != -1) ||
debug > 130)
g_print("game_post_match: %s - %s\n",
fix->teams[0]->name,
@ -1070,6 +1074,9 @@ game_post_match(Fixture *fix)
for(i=0;i<2;i++)
team_update_post_match(fix->teams[i], fix);
if(usr_idx != -1)
news_generate_match(&usr(usr_idx).live_game, fix);
if(fix->clid < ID_CUP_START)
return;
@ -1103,17 +1110,17 @@ game_post_match(Fixture *fix)
}
g_ptr_array_free(teams, TRUE);
}
else if(fixture_user_team_involved(fix) != -1)
else if(usr_idx != -1)
{
cup_get_round_name(cup_from_clid(fix->clid), fix->round, buf);
sprintf(buf2, "%d", fix->round + 1);
user_history_add(&usr(fixture_user_team_involved(fix)),
user_history_add(&usr(usr_idx),
USER_HISTORY_REACH_CUP_ROUND,
usr(fixture_user_team_involved(fix)).tm->name,
usr(usr_idx).tm->name,
league_cup_get_name_string(fix->clid),
buf, buf2);
user_add_cup_success(&usr(fixture_user_team_involved(fix)),
user_add_cup_success(&usr(usr_idx),
cup, fix->round, USER_HISTORY_REACH_CUP_ROUND);
}
}

View File

@ -79,7 +79,7 @@ lg_commentary_generate(const LiveGame *live_game, LiveGameUnit *unit,
lg_commentary_set_basic_tokens(unit, live_game->fix);
lg_commentary_set_team_tokens(unit, live_game->fix);
lg_commentary_set_player_tokens(unit, live_game->fix);
lg_commentary_set_stats_tokens(&live_game->stats);
lg_commentary_set_stats_tokens(&live_game->stats, token_rep);
}
if(event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND ||
@ -244,65 +244,65 @@ lg_commentary_get_order(const GArray *commentaries, gint *order)
/** Fill the stats tokens. */
void
lg_commentary_set_stats_tokens(const LiveGameStats *stats)
lg_commentary_set_stats_tokens(const LiveGameStats *stats, GPtrArray **token_arrays)
{
#ifdef DEBUG
printf("lg_commentary_set_stats_tokens\n");
#endif
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_shots0", &tokens),
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_SHOTS]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
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,
misc_token_add(token_arrays,
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,
misc_token_add(token_arrays,
option_int("string_token_stat_pen0", &tokens),
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_PENALTIES]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_fouls0", &tokens),
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_FOULS]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_yellows0", &tokens),
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_CARDS]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_reds0", &tokens),
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_REDS]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_injs0", &tokens),
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_INJURIES]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_shots1", &tokens),
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_SHOTS]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
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,
misc_token_add(token_arrays,
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,
misc_token_add(token_arrays,
option_int("string_token_stat_pen1", &tokens),
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_PENALTIES]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_fouls1", &tokens),
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_FOULS]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_yellows1", &tokens),
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_CARDS]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_reds1", &tokens),
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_REDS]));
misc_token_add(token_rep,
misc_token_add(token_arrays,
option_int("string_token_stat_injs1", &tokens),
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_INJURIES]));
}

View File

@ -56,7 +56,7 @@ void
lg_commentary_set_team_tokens(const LiveGameUnit *unit, const Fixture *fix);
void
lg_commentary_set_stats_tokens(const LiveGameStats *stats);
lg_commentary_set_stats_tokens(const LiveGameStats *stats, GPtrArray **token_arrays);
void
lg_commentary_generate(const LiveGame *live_game, LiveGameUnit *unit,

View File

@ -113,7 +113,7 @@ live_game_initialize(Fixture *fix)
stat2 = fixture_user_team_involved(fix);
statp= (stat2 != -1) ?
statp = (stat2 != -1) ?
&usr(stat2).live_game : &live_game_temp;
show = (stat2 != -1 &&
option_int("int_opt_user_show_live_game",

View File

@ -30,6 +30,7 @@
#include "file.h"
#include "fixture.h"
#include "language.h"
#include "lg_commentary.h"
#include "league.h"
#include "main.h"
#include "maths.h"
@ -41,7 +42,7 @@
#include "xml_news.h"
/** The replacement strings for the news tokens. */
GPtrArray *token_rep[2];
GPtrArray *token_rep_news[2];
/** Generate news for a user live game or a CPU fixture. */
void
@ -55,8 +56,8 @@ news_generate_match(const LiveGame *live_game, const Fixture *fix)
gint title_id, subtitle_id;
NewsPaperArticle new_article;
token_rep[0] = g_ptr_array_new();
token_rep[1] = g_ptr_array_new();
token_rep_news[0] = g_ptr_array_new();
token_rep_news[1] = g_ptr_array_new();
news_set_match_tokens(live_game, fix);
@ -99,7 +100,7 @@ news_select(const GArray *news_array, gchar *title, gchar *subtitle,
*title_id = *subtitle_id = -1;
for(i=0;i<news_array->len;i++)
if(news_check_article_condition(&g_array_index(news_array, NewsArticle, i)))
if(misc_parse_condition(g_array_index(news_array, NewsArticle, i).condition, token_rep_news))
break;
if(i == news_array->len)
@ -133,7 +134,7 @@ news_get_title(const GArray *titles, gchar *title, gint *order,
for(i = 0; i < titles->len; i++)
{
if(misc_string_replace_all_tokens(token_rep, g_array_index(titles, NewsText, order[i]).text, title))
if(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))
@ -164,52 +165,6 @@ news_check_for_repetition(gint id, gboolean is_title)
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); */
/* 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 TRUE;
}
/** 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) */
/* { */
/* #ifdef DEBUG */
/* printf("query_news_is_repetition\n"); */
/* #endif */
/* const GArray *units = ((LiveGame*)statp)->units; */
/* gint units_min = units->len - const_int("int_news_check_backwards") - 1; */
/* gint i, min = MAX(units_min, 0); */
/* for(i=units->len - 2; i>= min; i--) */
/* if(g_array_index(units, LiveGameUnit, i).event.news_id == id) */
/* return TRUE; */
/* return FALSE; */
/* } */
/** Write a random order of indices into the integer array
(only depending on the priority values of the commentaries).
@ -271,69 +226,72 @@ news_set_match_tokens(const LiveGame *live_game, const Fixture *fix_)
const Cup *cup;
const CupRound *cupround;
fix = (live_game == NULL) ? fix_ : live_game->fix;
token_rep[0] = g_ptr_array_new();
token_rep[1] = g_ptr_array_new();
if(live_game == NULL)
fix = fix_;
else
{
fix = live_game->fix;
lg_commentary_set_stats_tokens(&live_game->stats, token_rep_news);
}
avskill0 = (gint)rint(team_get_average_skill(fix->teams[0], TRUE));
avskill1 = (gint)rint(team_get_average_skill(fix->teams[1], TRUE));
fixture_result_to_buf(fix, buf, FALSE);
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_result", &tokens),
g_strdup(buf));
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_goals0", &tokens),
misc_int_to_char(fix->result[0][0]));
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_goals1", &tokens),
misc_int_to_char(fix->result[1][0]));
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_goal_diff", &tokens),
misc_int_to_char(ABS(fix->result[0][0] - fix->result[1][0])));
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_team_home", &tokens),
g_strdup(fix->teams[0]->name));
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_team_away", &tokens),
g_strdup(fix->teams[1]->name));
if(fix->result[0][0] != fix->result[1][0])
{
misc_token_add(token_rep,
misc_token_add(token_rep_news,
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,
misc_token_add(token_rep_news,
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,
misc_token_add(token_rep_news,
option_int("string_token_team_losingn", &tokens),
misc_int_to_char((fix->result[0][0] > fix->result[1][0])));
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_team_winningn", &tokens),
misc_int_to_char((fix->result[0][0] < fix->result[1][0])));
}
if(fix->teams[0]->clid < ID_CUP_START)
misc_token_add(token_rep,
misc_token_add(token_rep_news,
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,
misc_token_add(token_rep_news,
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,
misc_token_add(token_rep_news,
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,
misc_token_add(token_rep_news,
option_int("string_token_league_cup_name", &tokens),
g_strdup(league_cup_get_name_string(fix->clid)));
@ -342,43 +300,43 @@ news_set_match_tokens(const LiveGame *live_game, const Fixture *fix_)
cup = cup_from_clid(fix->clid);
cupround = &g_array_index(cup->rounds, CupRound, fix->round);
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_cup", &tokens),
g_strdup("1"));
cup_get_round_name(cup, fix->round, buf);
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_cup_round_name", &tokens),
g_strdup(buf));
if(cupround->tables->len > 0)
{
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_cup_knockout", &tokens),
g_strdup("0"));
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_cup_round_robin", &tokens),
g_strdup("1"));
}
else
{
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_cup_knockout", &tokens),
g_strdup("1"));
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_cup_round_robin", &tokens),
g_strdup("0"));
}
if(fix->decisive)
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_cup_match_winner", &tokens),
((Team*)fixture_winner_of(fix, FALSE))->name);
}
misc_print_grouped_int(fix->attendance, buf);
misc_token_add(token_rep,
misc_token_add(token_rep_news,
option_int("string_token_attendance", &tokens),
g_strdup(buf));
}
@ -393,14 +351,16 @@ news_free_tokens(void)
gint i;
for(i=token_rep[0]->len - 1;i >= 0; i--)
for(i=token_rep_news[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));
/* printf("%s/%s\n", (gchar*)g_ptr_array_index(token_rep_news[0], i), */
/* (gchar*)g_ptr_array_index(token_rep_news[1], i)); */
g_free(g_ptr_array_index(token_rep_news[0], i));
g_free(g_ptr_array_index(token_rep_news[1], i));
}
g_ptr_array_free(token_rep[0], TRUE);
g_ptr_array_free(token_rep[1], TRUE);
g_ptr_array_free(token_rep_news[0], TRUE);
g_ptr_array_free(token_rep_news[1], TRUE);
}
/** Load the appropriate news file by evaluating

View File

@ -49,9 +49,6 @@ news_get_title(const GArray *titles, gchar *title, gint *order,
gboolean
news_check_for_repetition(gint id, gboolean is_title);
gboolean
news_check_article_condition(const NewsArticle *news_article);
void
news_load_news_file_from_option(void);

View File

@ -359,9 +359,6 @@ end_week_round_results(void)
{
live_game_calculate_fixture(&g_array_index(lig(i).fixtures, Fixture, j));
if(fixture_user_team_involved(&g_array_index(lig(i).fixtures, Fixture, j)) != -1)
news_generate_match(NULL, &g_array_index(lig(i).fixtures, Fixture, j));
done++;
fixture_result_to_buf(&g_array_index(lig(i).fixtures, Fixture, j),
buf, FALSE);

View File

@ -18,6 +18,8 @@
<subtitle>_TW_ just too strong.</subtitle>
<title>_TL_ in a world of misery!</title>
<subtitle>_TW_: _RE_ against _TL_.</subtitle>
<title priority="15">_LEAGUECUPNAME_: _TL_ loses to _TW_!</title>
<subtitle priority="15">_TL_ overwhelmed by _SHOTS_TWN__ shots.</subtitle>
</news_article>
</news>