diff --git a/src/debug.c b/src/debug.c index c57f93a2..90d0a192 100644 --- a/src/debug.c +++ b/src/debug.c @@ -162,6 +162,7 @@ debug_calibrate_betting_odds(gint skilldiffmax, gint matches_per_skilldiff) gint i, skilldiff, matches; Fixture *fix = &g_array_index(lig(0).fixtures, Fixture, 0); + LiveGame live_game; fix->home_advantage = FALSE; @@ -183,7 +184,7 @@ debug_calibrate_betting_odds(gint skilldiffmax, gint matches_per_skilldiff) g_array_index(fix->teams[1]->players, Player, i).fitness = 0.9; } - live_game_calculate_fixture(fix); + live_game_calculate_fixture(fix, &live_game); if(fix->result[0][0] < fix->result[1][0]) res[2]++; else diff --git a/src/fixture.c b/src/fixture.c index f8b02098..966a3ae6 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -739,6 +739,7 @@ fixture_write(GArray *fixtures, Team *home_team, Team *away_team, gint week_numb new.teams[1] = away_team; new.team_ids[0] = home_team->id; new.team_ids[1] = away_team->id; + new.live_game = NULL; for(i=0;i<3;i++) new.result[0][i] = new.result[1][i] = 0; diff --git a/src/fixture_struct.h b/src/fixture_struct.h index cc2249f8..491018c1 100644 --- a/src/fixture_struct.h +++ b/src/fixture_struct.h @@ -57,6 +57,8 @@ typedef struct /** How many people attended and whether there were special events. */ gint attendance; + /** Pointer to the live game used for the fixture calculation. */ + gpointer live_game; } Fixture; #endif diff --git a/src/free.c b/src/free.c index 9d812138..b0da8388 100644 --- a/src/free.c +++ b/src/free.c @@ -50,12 +50,13 @@ free_memory(void) free_country(&country, FALSE); free_users(FALSE); free_bets(FALSE); - free_live_game(&live_game_temp); free_lg_commentary(FALSE); free_news(FALSE); free_newspaper(FALSE); free_support_dirs(); free_jobs(FALSE); + + free_g_array(&live_games); } /** Free the transfer list. */ @@ -728,12 +729,18 @@ free_news(gboolean reset) g_free(g_array_index(news[i], NewsArticle, j).condition); for(k = 0; k < g_array_index(news[i], NewsArticle, j).titles->len; k++) + { g_free(g_array_index(g_array_index(news[i], NewsArticle, j).titles, NewsText, k).text); + g_free(g_array_index(g_array_index(news[i], NewsArticle, j).titles, NewsText, k).condition); + } g_array_free(g_array_index(news[i], NewsArticle, j).titles, TRUE); for(k = 0; k < g_array_index(news[i], NewsArticle, j).subtitles->len; k++) + { g_free(g_array_index(g_array_index(news[i], NewsArticle, j).subtitles, NewsText, k).text); + g_free(g_array_index(g_array_index(news[i], NewsArticle, j).subtitles, NewsText, k).condition); + } g_array_free(g_array_index(news[i], NewsArticle, j).subtitles, TRUE); } diff --git a/src/game.c b/src/game.c index 46bf8081..8968dfbb 100644 --- a/src/game.c +++ b/src/game.c @@ -32,7 +32,6 @@ #include "live_game.h" #include "main.h" #include "maths.h" -#include "news.h" #include "misc.h" #include "option.h" #include "player.h" @@ -984,6 +983,7 @@ game_update_stats_player(LiveGame *lg, const LiveGameUnit *unit) const Team *tm[2] = {lg->fix->teams[0], lg->fix->teams[1]}; GPtrArray *players = NULL; + const gchar *player_name; if(unit->event.type == LIVE_GAME_EVENT_GOAL || unit->event.type == LIVE_GAME_EVENT_OWN_GOAL) @@ -998,29 +998,34 @@ game_update_stats_player(LiveGame *lg, const LiveGameUnit *unit) /* A goal scored with a free kick. */ strcpy(buf2, _(" (FK)")); else if(unit->event.type == LIVE_GAME_EVENT_OWN_GOAL) + /* An own goal */ strcpy(buf2, _(" (OG)")); else strcpy(buf2, ""); - for(i=0;iplayers[array_index][LIVE_GAME_STAT_ARRAY_SCORERS]->len;i++) + player_name = player_of_id_team(tm[team], player)->name; + if(!own_goal) + g_ptr_array_add(stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS], g_strdup(player_name)); + + for(i=0;iplayers[array_index][LIVE_GAME_STAT_ARRAY_SCORERS_FOR_DISPLAY]->len;i++) { if(g_str_has_prefix((gchar*)g_ptr_array_index( - stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS], i), - player_of_id_team(tm[team], player)->name)) + stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS_FOR_DISPLAY], i), + player_name)) { sprintf(buf, "%s %d%s", (gchar*)g_ptr_array_index( - stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS], i), + stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS_FOR_DISPLAY], i), minute, buf2); misc_string_assign((gchar**)&g_ptr_array_index( - stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS], i), buf); + stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS_FOR_DISPLAY], i), buf); return; } } - sprintf(buf, "%s %d%s", player_of_id_team(tm[team], player)->name, + sprintf(buf, "%s %d%s", player_name, minute, buf2); - g_ptr_array_add(stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS], g_strdup(buf)); + g_ptr_array_add(stats->players[array_index][LIVE_GAME_STAT_ARRAY_SCORERS_FOR_DISPLAY], g_strdup(buf)); } else { @@ -1075,9 +1080,6 @@ 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; diff --git a/src/live_game.c b/src/live_game.c index 0e0e4ffc..998a306f 100644 --- a/src/live_game.c +++ b/src/live_game.c @@ -62,17 +62,19 @@ gboolean show; /** Calculate the result of a fixture using the live game variable. @param fix The fixture we calculate. + @param live_game The live game used for calculation. */ void -live_game_calculate_fixture(Fixture *fix) +live_game_calculate_fixture(Fixture *fix, LiveGame *live_game) { #ifdef DEBUG printf("live_game_calculate_fixture\n"); #endif + statp = live_game; if(stat0 != STATUS_LIVE_GAME_PAUSE && stat0 != STATUS_LIVE_GAME_CHANGE) - live_game_initialize(fix); + live_game_initialize(fix, live_game); else stat0 = STATUS_SHOW_LIVE_GAME; @@ -105,7 +107,7 @@ live_game_calculate_fixture(Fixture *fix) /** Initialize a few things at the beginning of a live game. */ void -live_game_initialize(Fixture *fix) +live_game_initialize(Fixture *fix, LiveGame *live_game) { #ifdef DEBUG printf("live_game_initialize\n"); @@ -113,13 +115,12 @@ live_game_initialize(Fixture *fix) stat2 = fixture_user_team_involved(fix); - statp = (stat2 != -1) ? - &usr(stat2).live_game : &live_game_temp; + statp = live_game; show = (stat2 != -1 && option_int("int_opt_user_show_live_game", &usr(stat2).options)); - live_game_reset(match, fix, TRUE); + live_game_reset(match, fix, (stat2 != -1)); if(show) { @@ -131,11 +132,12 @@ live_game_initialize(Fixture *fix) else gtk_window_set_title( GTK_WINDOW(window.live), - league_cup_get_name_string(((LiveGame*)statp)->fix->clid)); + league_cup_get_name_string(match->fix->clid)); window_live_set_up(); game_gui_live_game_show_opponent(); } + fix->live_game = match; game_initialize(fix); match->attendance = fix->attendance; @@ -1704,7 +1706,7 @@ live_game_resume(void) tms[i]->boost + 1); } - live_game_calculate_fixture(usr(stat2).live_game.fix); + live_game_calculate_fixture(usr(stat2).live_game.fix, &usr(stat2).live_game); } diff --git a/src/live_game.h b/src/live_game.h index 2000579a..bce2b1c8 100644 --- a/src/live_game.h +++ b/src/live_game.h @@ -30,10 +30,10 @@ #include "live_game_struct.h" void -live_game_calculate_fixture(Fixture *fix); +live_game_calculate_fixture(Fixture *fix, LiveGame *live_game); void -live_game_initialize(Fixture *fix); +live_game_initialize(Fixture *fix, LiveGame *live_game); gboolean query_live_game_event_is_break(gint minute, gint time); diff --git a/src/live_game_struct.h b/src/live_game_struct.h index f50885e0..c9924430 100644 --- a/src/live_game_struct.h +++ b/src/live_game_struct.h @@ -116,7 +116,8 @@ enum LiveGameStatValue enum LiveGameStatArray { - LIVE_GAME_STAT_ARRAY_SCORERS = 0, + LIVE_GAME_STAT_ARRAY_SCORERS_FOR_DISPLAY = 0, + LIVE_GAME_STAT_ARRAY_SCORERS, LIVE_GAME_STAT_ARRAY_YELLOWS, LIVE_GAME_STAT_ARRAY_REDS, LIVE_GAME_STAT_ARRAY_INJURED, diff --git a/src/main.c b/src/main.c index e92d31c3..bdf04840 100644 --- a/src/main.c +++ b/src/main.c @@ -209,13 +209,12 @@ main_init_variables(void) window.mmatches = window.bets = window.splash = window.training_camp = NULL; - live_game_reset(&live_game_temp, NULL, FALSE); - users = g_array_new(FALSE, FALSE, sizeof(User)); transfer_list = g_array_new(FALSE, FALSE, sizeof(Transfer)); season_stats = g_array_new(FALSE, FALSE, sizeof(SeasonStat)); name_lists = g_array_new(FALSE, FALSE, sizeof(NameList)); strategies = g_array_new(FALSE, FALSE, sizeof(Strategy)); + live_games = g_array_new(FALSE, FALSE, sizeof(LiveGame)); bets[0] = g_array_new(FALSE, FALSE, sizeof(BetMatch)); bets[1] = g_array_new(FALSE, FALSE, sizeof(BetMatch)); jobs = g_array_new(FALSE, FALSE, sizeof(Job)); diff --git a/src/misc.c b/src/misc.c index b7a1a4d0..f0138d33 100644 --- a/src/misc.c +++ b/src/misc.c @@ -706,6 +706,10 @@ misc_token_add(GPtrArray **token_rep, gint token_idx, gchar *replacement) { +/* printf("tok +%s+ rep +%s+\n", */ +/* g_strdup(g_array_index(tokens.list, Option, token_idx).string_value), */ +/* replacement); */ + g_ptr_array_add(token_rep[0], (gpointer)g_strdup(g_array_index(tokens.list, Option, token_idx).string_value)); g_ptr_array_add(token_rep[1], (gpointer)replacement); diff --git a/src/news.c b/src/news.c index b872cf7f..640f3101 100644 --- a/src/news.c +++ b/src/news.c @@ -31,6 +31,7 @@ #include "fixture.h" #include "language.h" #include "lg_commentary.h" +#include "live_game.h" #include "league.h" #include "main.h" #include "maths.h" @@ -38,6 +39,7 @@ #include "news.h" #include "option.h" #include "team.h" +#include "user.h" #include "variables.h" #include "xml_news.h" @@ -46,7 +48,7 @@ GPtrArray *token_rep_news[2]; /** Generate news for a user live game or a CPU fixture. */ void -news_generate_match(const LiveGame *live_game, const Fixture *fix) +news_generate_match(const LiveGame *live_game) { #ifdef DEBUG printf("news_generate_match\n"); @@ -59,7 +61,7 @@ news_generate_match(const LiveGame *live_game, const Fixture *fix) token_rep_news[0] = g_ptr_array_new(); token_rep_news[1] = g_ptr_array_new(); - news_set_match_tokens(live_game, fix); + news_set_match_tokens(live_game); news_select(news[NEWS_ARTICLE_TYPE_MATCH], title, subtitle, &title_id, &subtitle_id); @@ -134,7 +136,8 @@ 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_news, g_array_index(titles, NewsText, order[i]).text, title)) + 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)) @@ -214,25 +217,199 @@ news_titles_get_order(const GArray *titles, gint *order) /** Set match-related tokens for the news. */ void -news_set_match_tokens(const LiveGame *live_game, const Fixture *fix_) +news_set_match_tokens(const LiveGame *live_game) { #ifdef DEBUG printf("news_set_match_tokens\n"); #endif + lg_commentary_set_stats_tokens(&live_game->stats, token_rep_news); + news_set_fixture_tokens(live_game->fix); + news_set_league_cup_tokens(live_game->fix); + news_set_scorer_tokens(&live_game->stats); +} + +void +news_set_scorer_tokens(const LiveGameStats *stats) +{ + gint i, j, k; + GPtrArray *scorers[2]; + GArray *goals[2]; + gchar buf[SMALL]; + gchar scorer_str[SMALL]; + const gchar *scorer; + gchar high_scorer[SMALL]; + gint scorer_goals; + gint max_goals; + + for(i = 0; i < 2; i++) + { + scorers[i] = g_ptr_array_new(); + goals[i] = g_array_new(FALSE, FALSE, sizeof(gint)); + + for(j = 0; j < stats->players[i][LIVE_GAME_STAT_ARRAY_SCORERS]->len; j++) + { + scorer = (gchar*)g_ptr_array_index(stats->players[i][LIVE_GAME_STAT_ARRAY_SCORERS], j); + + for(k=0;klen;k++) + { + if(strcmp(scorer, (gchar*)g_ptr_array_index(scorers[i], k)) == 0) + { + g_array_index(goals[i], gint, k) = g_array_index(goals[i], gint, k) + 1; + break; + } + } + + if(k == scorers[i]->len) + { + gint onegoal = 1; + g_ptr_array_add(scorers[i], (gpointer)scorer); + g_array_append_val(goals[i], onegoal); + } + } + + max_goals = 0; + strcpy(buf, ""); + strcpy(scorer_str, ""); + strcpy(high_scorer, ""); + + for(j = 0; j < scorers[i]->len; j++) + { + scorer_goals = g_array_index(goals[i], gint, j); + scorer = (gchar*)g_ptr_array_index(scorers[i], j); + + if(scorer_goals > max_goals) + { + max_goals = scorer_goals; + strcpy(high_scorer, scorer); + } + + if(j == 0) + { + if(scorer_goals > 1) + sprintf(scorer_str, "%s (%d)", scorer, scorer_goals); + else + sprintf(scorer_str, "%s", scorer); + } + else if(j == scorers[i]->len - 1 && j != 0) + { + if(scorer_goals > 1) + sprintf(scorer_str, "%s and %s (%d)", buf, scorer, scorer_goals); + else + sprintf(scorer_str, "%s and %s", buf, scorer); + } + else + { + if(scorer_goals > 1) + sprintf(scorer_str, "%s, %s (%d)", buf, scorer, scorer_goals); + else + sprintf(scorer_str, "%s, %s", buf, scorer); + } + + 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_multiple_scorers%d", i); + misc_token_add(token_rep_news, + option_int(buf, &tokens), + misc_int_to_char((scorers[i]->len > 1))); + + sprintf(buf, "string_token_scorers%d", i); + misc_token_add(token_rep_news, + option_int(buf, &tokens), + g_strdup(scorer_str)); + sprintf(buf, "string_token_highscorer%d", i); + misc_token_add(token_rep_news, + option_int(buf, &tokens), + g_strdup(high_scorer)); + sprintf(buf, "string_token_highscorer_goals%d", i); + misc_token_add(token_rep_news, + option_int(buf, &tokens), + misc_int_to_char(max_goals)); + } + + g_ptr_array_free(scorers[i], TRUE); + g_array_free(goals[i], TRUE); + } +} + +void +news_set_league_cup_tokens(const Fixture *fix) +{ gchar buf[SMALL]; - const Fixture *fix; - gint avskill0, avskill1; const Cup *cup; const CupRound *cupround; - if(live_game == NULL) - fix = fix_; - else + if(fix->teams[0]->clid < ID_CUP_START) + 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_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_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_news, + option_int("string_token_league_cup_name", &tokens), + g_strdup(league_cup_get_name_string(fix->clid))); + + misc_token_add(token_rep_news, + option_int("string_token_cup", &tokens), + misc_int_to_char((fix->clid >= ID_CUP_START))); + + if(fix->clid >= ID_CUP_START) { - fix = live_game->fix; - lg_commentary_set_stats_tokens(&live_game->stats, token_rep_news); + cup = cup_from_clid(fix->clid); + cupround = &g_array_index(cup->rounds, CupRound, fix->round); + + cup_get_round_name(cup, fix->round, buf); + 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_news, + option_int("string_token_cup_knockout", &tokens), + g_strdup("0")); + misc_token_add(token_rep_news, + option_int("string_token_cup_round_robin", &tokens), + g_strdup("1")); + } + else + { + misc_token_add(token_rep_news, + option_int("string_token_cup_knockout", &tokens), + g_strdup("1")); + 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_news, + option_int("string_token_cup_match_winner", &tokens), + ((Team*)fixture_winner_of(fix, FALSE))->name); } +} + +void +news_set_fixture_tokens(const Fixture *fix) +{ + gchar buf[SMALL]; + gint avskill0, avskill1; avskill0 = (gint)rint(team_get_average_skill(fix->teams[0], TRUE)); avskill1 = (gint)rint(team_get_average_skill(fix->teams[1], TRUE)); @@ -242,6 +419,11 @@ news_set_match_tokens(const LiveGame *live_game, const Fixture *fix_) option_int("string_token_result", &tokens), g_strdup(buf)); + misc_print_grouped_int(fix->attendance, buf); + misc_token_add(token_rep_news, + option_int("string_token_attendance", &tokens), + g_strdup(buf)); + misc_token_add(token_rep_news, option_int("string_token_goals0", &tokens), misc_int_to_char(fix->result[0][0])); @@ -273,72 +455,7 @@ news_set_match_tokens(const LiveGame *live_game, const Fixture *fix_) 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_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_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_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_news, - option_int("string_token_league_cup_name", &tokens), - g_strdup(league_cup_get_name_string(fix->clid))); - - if(fix->clid >= ID_CUP_START) - { - 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", &tokens), - g_strdup("1")); - - cup_get_round_name(cup, fix->round, buf); - 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_news, - option_int("string_token_cup_knockout", &tokens), - g_strdup("0")); - misc_token_add(token_rep_news, - option_int("string_token_cup_round_robin", &tokens), - g_strdup("1")); - } - else - { - misc_token_add(token_rep_news, - option_int("string_token_cup_knockout", &tokens), - g_strdup("1")); - 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_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_news, - option_int("string_token_attendance", &tokens), - g_strdup(buf)); + } } /** Free the memory occupied by the tokens array and the permanent tokens. */ @@ -415,3 +532,34 @@ news_load_news_file(const gchar *news_file, gboolean abort) news_load_news_file("news_en.xml", TRUE); } } + +/** Find out if the match is interesting from a newspaper article + generation point of view. */ +gboolean +news_check_match_relevant(const LiveGame *live_game) +{ + gint i; + GArray *user_leagues; + + if(fixture_user_team_involved(live_game->fix) != -1) + return TRUE; + + user_leagues = g_array_new(FALSE, FALSE, sizeof(gint)); + + if(live_game->fix->clid >= ID_CUP_START && + live_game->fix->round >= cup_from_clid(live_game->fix->clid)->rounds->len - 4) + return TRUE; + + for(i = 0; i < users->len; i++) + if(!query_misc_integer_is_in_g_array(usr(i).tm->clid, user_leagues)) + g_array_append_val(user_leagues, usr(i).tm->clid); + + if(query_misc_integer_is_in_g_array(live_game->fix->clid, user_leagues)) + { + g_array_free(user_leagues, TRUE); + return TRUE; + } + + g_array_free(user_leagues, TRUE); + return FALSE; +} diff --git a/src/news.h b/src/news.h index d7d44c3b..3d2f6ec7 100644 --- a/src/news.h +++ b/src/news.h @@ -33,10 +33,10 @@ void news_free_tokens(void); void -news_set_match_tokens(const LiveGame *live_game, const Fixture *fix_); +news_set_match_tokens(const LiveGame *live_game); void -news_generate_match(const LiveGame *live_game, const Fixture *fix); +news_generate_match(const LiveGame *live_game); void news_select(const GArray *news_array, gchar *title, gchar *subtitle, @@ -58,5 +58,16 @@ news_load_news_file(const gchar *news_file, gboolean abort); void news_titles_get_order(const GArray *titles, gint *order); +gboolean +news_check_match_relevant(const LiveGame *live_game); + +void +news_set_scorer_tokens(const LiveGameStats *stats); + +void +news_set_league_cup_tokens(const Fixture *fix); + +void +news_set_fixture_tokens(const Fixture *fix); #endif diff --git a/src/news_struct.h b/src/news_struct.h index ff09095b..e07f1775 100644 --- a/src/news_struct.h +++ b/src/news_struct.h @@ -49,7 +49,10 @@ typedef struct gint priority; /** An id to keep track of already used texts (so as not to use the same one too frequently). */ - gint id; + gint id; + /** A condition (if not fulfilled, the title or subtitle + doesn't get considered). */ + gchar *condition; } NewsText; diff --git a/src/start_end.c b/src/start_end.c index 61c535b5..d8ee631b 100644 --- a/src/start_end.c +++ b/src/start_end.c @@ -60,7 +60,7 @@ typedef void(*WeekFunc)(void); is ended. */ WeekFunc end_week_round_funcs[] = {end_week_round_results, end_week_round_sort_tables, - end_week_round_update_fixtures, NULL}; + end_week_round_update_fixtures, end_week_round_generate_news, NULL}; /** Array of functions called when a week round is started. */ @@ -346,9 +346,17 @@ end_week_round_results(void) #endif gint i, j, done = 0; + LiveGame live_game; gchar buf[SMALL], buf2[SMALL]; gfloat num_matches = (gfloat)fixture_get_number_of_matches(week, week_round); + gint usr_idx; + + /** Free the matches from last week. */ + for(i = 0; i < live_games->len; i++) + free_live_game(&g_array_index(live_games, LiveGame, i)); + g_array_free(live_games, TRUE); + live_games = g_array_new(FALSE, FALSE, sizeof(LiveGame)); for(i=0;ilen;i++) { @@ -356,8 +364,18 @@ end_week_round_results(void) if(g_array_index(lig(i).fixtures, Fixture, j).week_number == week && g_array_index(lig(i).fixtures, Fixture, j).week_round_number == week_round && g_array_index(lig(i).fixtures, Fixture, j).attendance == -1) - { - live_game_calculate_fixture(&g_array_index(lig(i).fixtures, Fixture, j)); + { + usr_idx = fixture_user_team_involved(&g_array_index(lig(i).fixtures, Fixture, j)); + + if(usr_idx == -1) + { + g_array_append_val(live_games, live_game); + live_game_calculate_fixture(&g_array_index(lig(i).fixtures, Fixture, j), + &g_array_index(live_games, LiveGame, live_games->len - 1)); + } + else + live_game_calculate_fixture(&g_array_index(lig(i).fixtures, Fixture, j), + &usr(usr_idx).live_game); done++; fixture_result_to_buf(&g_array_index(lig(i).fixtures, Fixture, j), @@ -381,7 +399,17 @@ end_week_round_results(void) g_array_index(acp(i)->fixtures, Fixture, j).week_round_number == week_round && g_array_index(acp(i)->fixtures, Fixture, j).attendance == -1) { - live_game_calculate_fixture(&g_array_index(acp(i)->fixtures, Fixture, j)); + usr_idx = fixture_user_team_involved(&g_array_index(acp(i)->fixtures, Fixture, j)); + + if(usr_idx == -1) + { + g_array_append_val(live_games, live_game); + live_game_calculate_fixture(&g_array_index(acp(i)->fixtures, Fixture, j), + &g_array_index(live_games, LiveGame, live_games->len - 1)); + } + else + live_game_calculate_fixture(&g_array_index(acp(i)->fixtures, Fixture, j), + &usr(usr_idx).live_game); done++; fixture_result_to_buf(&g_array_index(acp(i)->fixtures, Fixture, j), @@ -484,6 +512,25 @@ end_week_round_update_fixtures(void) } } +/** Write newspaper articles after week round. */ +void +end_week_round_generate_news(void) +{ + gint i; + + /** News for user matches. */ + for(i = 0; i < users->len; i++) + if(usr(i).live_game.fix != NULL && + usr(i).live_game.fix->week_number == week && + usr(i).live_game.fix->week_round_number == week_round) + news_generate_match(&usr(i).live_game); + + /** News for other matches. */ + for(i = 0; i < live_games->len; i++) + if(news_check_match_relevant(&g_array_index(live_games, LiveGame, i))) + news_generate_match(&g_array_index(live_games, LiveGame, i)); +} + /** Start a new week round. */ void start_week_round(void) diff --git a/src/start_end.h b/src/start_end.h index 63a4b740..dc282be0 100644 --- a/src/start_end.h +++ b/src/start_end.h @@ -94,4 +94,7 @@ start_new_season_reset_ids(void); void start_week_update_leagues(void); +void +end_week_round_generate_news(void); + #endif diff --git a/src/stat.c b/src/stat.c index 09f54754..3698c81f 100644 --- a/src/stat.c +++ b/src/stat.c @@ -205,7 +205,8 @@ stat_create_season_stat(void) for(i=0;ilen;i++) { - if(!query_league_cup_has_property(lig(i).id, "omit_from_history")) + if(!query_league_cup_has_property(lig(i).id, "omit_from_history") && + !query_league_cup_has_property(lig(i).id, "inactive")) { for(j = 0; j < lig(i).tables->len; j++) { diff --git a/src/treeview.c b/src/treeview.c index f76b2906..0a341807 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -845,7 +845,10 @@ treeview_create_game_stats(LiveGame *live_game) for(k=0;kleague_symbol); diff --git a/src/variables.h b/src/variables.h index 6ebe1161..850ef019 100644 --- a/src/variables.h +++ b/src/variables.h @@ -104,8 +104,8 @@ GArray *name_lists; /** The struct containing the window pointers. */ Windows window; -/** The variable for non-user games (which aren't shown). */ -LiveGame live_game_temp; +/** The variables for non-user live games (which aren't shown). */ +GArray *live_games; /** The index of the current user in the #users array. */ gint cur_user; diff --git a/src/xml_news.c b/src/xml_news.c index 3a8437e5..53139aa2 100644 --- a/src/xml_news.c +++ b/src/xml_news.c @@ -38,6 +38,7 @@ #define TAG_ARTICLE_SUBTITLE "subtitle" #define ATT_NAME_TEXT_PRIORITY "priority" +#define ATT_NAME_TEXT_CONDITION "condition" #define ARTICLE_TYPE_NAME_MATCH "match" #define ARTICLE_TYPE_NAME_FINANCES "finances" @@ -109,6 +110,9 @@ xml_news_read_start_element (GMarkupParseContext *context, #ifdef DEBUG printf("xml_news_read_start_element\n"); #endif + gint atidx; + + atidx = 0; if(strcmp(element_name, TAG_NEWS) == 0) state = STATE_NEWS; @@ -119,6 +123,7 @@ xml_news_read_start_element (GMarkupParseContext *context, state = STATE_ARTICLE; 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"); } else if(strcmp(element_name, TAG_ARTICLE_TYPE) == 0) state = STATE_ARTICLE_TYPE; @@ -128,19 +133,33 @@ xml_news_read_start_element (GMarkupParseContext *context, { state = STATE_ARTICLE_TITLE; new_title.id = news_title_id_new; - if(attribute_names[0] != NULL && strcmp(attribute_names[0], ATT_NAME_TEXT_PRIORITY) == 0) - new_title.priority = (gint)g_ascii_strtod(attribute_values[0], NULL); - else - new_title.priority = 1; + new_title.priority = 1; + new_title.condition = g_strdup("1"); + + while(attribute_names[atidx] != NULL) + { + if(strcmp(attribute_names[atidx], ATT_NAME_TEXT_PRIORITY) == 0) + new_title.priority = (gint)g_ascii_strtod(attribute_values[atidx], NULL); + else if(strcmp(attribute_names[atidx], ATT_NAME_TEXT_CONDITION) == 0) + misc_string_assign(&new_title.condition, attribute_values[atidx]); + atidx++; + } } else if(strcmp(element_name, TAG_ARTICLE_SUBTITLE) == 0) { state = STATE_ARTICLE_SUBTITLE; new_subtitle.id = news_subtitle_id_new; - if(attribute_names[0] != NULL && strcmp(attribute_names[0], ATT_NAME_TEXT_PRIORITY) == 0) - new_subtitle.priority = (gint)g_ascii_strtod(attribute_values[0], NULL); - else - new_subtitle.priority = 1; + new_subtitle.priority = 1; + new_subtitle.condition = g_strdup("1"); + + while(attribute_names[atidx] != NULL) + { + if(strcmp(attribute_names[atidx], ATT_NAME_TEXT_PRIORITY) == 0) + new_subtitle.priority = (gint)g_ascii_strtod(attribute_values[atidx], NULL); + else if(strcmp(attribute_names[atidx], ATT_NAME_TEXT_CONDITION) == 0) + misc_string_assign(&new_subtitle.condition, attribute_values[atidx]); + atidx++; + } } else g_warning("xml_news_read_start_element: unknown tag: %s; I'm in state %d\n", @@ -206,7 +225,7 @@ xml_news_read_text (GMarkupParseContext *context, else if(state == STATE_ARTICLE_TYPE) article_idx = xml_news_article_type_to_int(buf); else if(state == STATE_ARTICLE_CONDITION) - new_article.condition = g_strdup(buf); + misc_string_assign(&new_article.condition, buf); else if(state == STATE_ARTICLE_TITLE) { new_title.text = g_strdup(buf); diff --git a/support_files/bygfoot_tokens b/support_files/bygfoot_tokens index d10712b4..662d7a99 100644 --- a/support_files/bygfoot_tokens +++ b/support_files/bygfoot_tokens @@ -88,6 +88,11 @@ string_token_cup_round_robin _CUPRR_ string_token_cup_knockout _CUPKO_ string_token_cup_stage _CUPSTAGE_ string_token_cup_match_winner _CUPMATCHWINNER_ -string_token_scorers _SCORERS_ -string_token_highscorer _HIGHSCORER_ -string_token_highscorer_goals _HIGHGOALS_ +string_token_multiple_scorers0 _MULTIPLESCORERS_ +string_token_multiple_scorers1 _MULTIPLESCORERS_ +string_token_scorers0 _SCORERS0_ +string_token_highscorer0 _HIGHSCORER0_ +string_token_highscorer_goals0 _HIGHGOALS0_ +string_token_scorers1 _SCORERS1_ +string_token_highscorer1 _HIGHSCORER1_ +string_token_highscorer_goals1 _HIGHGOALS1_ diff --git a/support_files/news/news_de.xml b/support_files/news/news_de.xml index 77b00ccd..f91e4903 100644 --- a/support_files/news/news_de.xml +++ b/support_files/news/news_de.xml @@ -20,6 +20,7 @@ _TW_: _RE_ against _TL_. _LEAGUECUPNAME_: _TL_ loses to _TW_! _TL_ overwhelmed by _SHOTS_TWN__ shots. + _SCORERS_TWN__ ensure victory for _TW_. diff --git a/support_files/news/news_en.xml b/support_files/news/news_en.xml index eceb3308..f91e4903 100644 --- a/support_files/news/news_en.xml +++ b/support_files/news/news_en.xml @@ -18,6 +18,9 @@ _TW_ just too strong. _TL_ in a world of misery! _TW_: _RE_ against _TL_. + _LEAGUECUPNAME_: _TL_ loses to _TW_! + _TL_ overwhelmed by _SHOTS_TWN__ shots. + _SCORERS_TWN__ ensure victory for _TW_.