Streak tokens for newspaper.

This commit is contained in:
gyboth 2008-12-07 12:45:33 +00:00
parent 50d4794c87
commit dc2efa178a
8 changed files with 116 additions and 27 deletions

View File

@ -1203,7 +1203,7 @@ fixture_compare_func(gconstpointer a, gconstpointer b, gpointer data)
/** Return an array with the last fixtures of the team. */ /** Return an array with the last fixtures of the team. */
GPtrArray* GPtrArray*
fixture_get_latest(const Team *tm) fixture_get_latest(const Team *tm, gboolean with_cups)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("fixture_get_latest\n"); printf("fixture_get_latest\n");
@ -1223,6 +1223,8 @@ fixture_get_latest(const Team *tm)
g_ptr_array_add(latest, &g_array_index(lig(i).fixtures, Fixture, j)); g_ptr_array_add(latest, &g_array_index(lig(i).fixtures, Fixture, j));
} }
if(with_cups)
{
for(i=0;i<acps->len;i++) for(i=0;i<acps->len;i++)
{ {
for(j=0;j<acp(i)->fixtures->len;j++) for(j=0;j<acp(i)->fixtures->len;j++)
@ -1232,6 +1234,7 @@ fixture_get_latest(const Team *tm)
g_array_index(acp(i)->fixtures, Fixture, j).teams[1] == tm) g_array_index(acp(i)->fixtures, Fixture, j).teams[1] == tm)
g_ptr_array_add(latest, &g_array_index(acp(i)->fixtures, Fixture, j)); g_ptr_array_add(latest, &g_array_index(acp(i)->fixtures, Fixture, j));
} }
}
g_ptr_array_sort_with_data(latest, fixture_compare_func, g_ptr_array_sort_with_data(latest, fixture_compare_func,
GINT_TO_POINTER(FIXTURE_COMPARE_DATE)); GINT_TO_POINTER(FIXTURE_COMPARE_DATE));

View File

@ -124,7 +124,7 @@ Fixture*
fixture_get_previous(gint clid, gint week_number, gint week_round_number); fixture_get_previous(gint clid, gint week_number, gint week_round_number);
GPtrArray* GPtrArray*
fixture_get_latest(const Team *tm); fixture_get_latest(const Team *tm, gboolean with_cups);
gint gint
fixture_compare_func(gconstpointer a, gconstpointer b, gpointer data); fixture_compare_func(gconstpointer a, gconstpointer b, gpointer data);

View File

@ -294,12 +294,78 @@ news_set_match_tokens(const LiveGame *live_game)
lg_commentary_set_stats_tokens(&live_game->stats, token_rep_news); lg_commentary_set_stats_tokens(&live_game->stats, token_rep_news);
news_set_fixture_tokens(live_game->fix); news_set_fixture_tokens(live_game->fix);
news_set_league_cup_tokens(live_game->fix); news_set_league_cup_tokens(live_game->fix);
news_set_streak_tokens(live_game->fix);
news_set_scorer_tokens(&live_game->stats); news_set_scorer_tokens(&live_game->stats);
if(live_game->fix->clid < ID_CUP_START) if(live_game->fix->clid < ID_CUP_START)
news_set_rank_tokens(live_game->fix); news_set_rank_tokens(live_game->fix);
} }
/** Set overall and league streak tokens for the two teams. */
void
news_set_streak_tokens(const Fixture *fix)
{
#ifdef DEBUG
printf("news_set_streak_tokens\n");
#endif
gint i, j, k,
streak_won, streak_lost;
gint res[2];
gchar buf[SMALL], buf2[SMALL];
GPtrArray *latest_fixtures;
for(i = 0; i < 2; i++)
{
for(k = 0; k < 2; k++)
{
latest_fixtures = fixture_get_latest(fix->teams[0], (k == 0));
streak_won = streak_lost = 0;
for(j=latest_fixtures->len - 1;j>=0;j--)
{
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);
if(res[0] == res[1])
break;
else if(res[(((Fixture*)g_ptr_array_index(latest_fixtures, j))->teams[0] == fix->teams[i])] >
res[(((Fixture*)g_ptr_array_index(latest_fixtures, j))->teams[0] != fix->teams[i])])
{
if(streak_won == 0)
streak_lost++;
else
break;
}
else
{
if(streak_lost == 0)
streak_won++;
else
break;
}
}
if(k == 0)
strcpy(buf2, "");
else
strcpy(buf2, "league_");
sprintf(buf, "string_token_streak_%swon%d", buf2, i);
misc_token_add(token_rep_news,
option_int(buf, &tokens),
misc_int_to_char(streak_won));
sprintf(buf, "string_token_streak_%slost%d", buf2, i);
misc_token_add(token_rep_news,
option_int(buf, &tokens),
misc_int_to_char(streak_lost));
g_ptr_array_free(latest_fixtures, TRUE);
}
}
}
void void
news_set_scorer_tokens(const LiveGameStats *stats) news_set_scorer_tokens(const LiveGameStats *stats)
{ {
@ -369,9 +435,9 @@ news_set_scorer_tokens(const LiveGameStats *stats)
else if(j == scorers[i]->len - 1 && j != 0) else if(j == scorers[i]->len - 1 && j != 0)
{ {
if(scorer_goals > 1) if(scorer_goals > 1)
sprintf(scorer_str, "%s and %s (%d)", buf, scorer, scorer_goals); sprintf(scorer_str, _("%s and %s (%d)"), buf, scorer, scorer_goals);
else else
sprintf(scorer_str, "%s and %s", buf, scorer); sprintf(scorer_str, _("%s and %s"), buf, scorer);
} }
else else
{ {
@ -564,6 +630,7 @@ news_free_tokens(void)
gint i; gint i;
/* printf("\n\n---------------------------------\n"); */
for(i=token_rep_news[0]->len - 1;i >= 0; i--) for(i=token_rep_news[0]->len - 1;i >= 0; i--)
{ {
/* printf("%s/%s\n", (gchar*)g_ptr_array_index(token_rep_news[0], i), */ /* printf("%s/%s\n", (gchar*)g_ptr_array_index(token_rep_news[0], i), */

View File

@ -76,4 +76,7 @@ news_set_rank_tokens(const Fixture *fix);
void void
news_articles_get_order(const GArray *articles, gint *order); news_articles_get_order(const GArray *articles, gint *order);
void
news_set_streak_tokens(const Fixture *fix);
#endif #endif

View File

@ -1121,7 +1121,7 @@ team_write_results(const Team *tm, gchar *result_buf, gchar *goals_buf)
#endif #endif
gint i; gint i;
GPtrArray *latest_fixtures = fixture_get_latest(tm); GPtrArray *latest_fixtures = fixture_get_latest(tm, TRUE);
gint res[2], goals[2] = {0, 0}; gint res[2], goals[2] = {0, 0};
gint end_idx = latest_fixtures->len - const_int("int_treeview_latest_results"); gint end_idx = latest_fixtures->len - const_int("int_treeview_latest_results");

View File

@ -99,3 +99,11 @@ string_token_rank0 _RANK0_
string_token_oldrank0 _OLDRANK0_ string_token_oldrank0 _OLDRANK0_
string_token_rank1 _RANK1_ string_token_rank1 _RANK1_
string_token_oldrank1 _OLDRANK1_ string_token_oldrank1 _OLDRANK1_
string_token_streak_won0 _WON0_
string_token_streak_lost0 _LOST0_
string_token_streak_won1 _WON1_
string_token_streak_lost1 _LOST1_
string_token_streak_league_won0 _LEAGUEWON0_
string_token_streak_league_lost0 _LEAGUELOST0_
string_token_streak_league_won1 _LEAGUEWON1_
string_token_streak_league_lost1 _LEAGUELOST1_

View File

@ -7,23 +7,27 @@
<paper_name>News Of The Sports World</paper_name> <paper_name>News Of The Sports World</paper_name>
<news_article> <news_article>
<type>match</type> <type>match</type>
<condition>_CUP_ = 0 _GD_ G 1</condition> <condition>_CUP_ = 0 and _GD_ G 1</condition>
<title>_TW_ [beats|crushes|kills] _TL_!</title> <title>_TW_ [beats|crushes|kills] _TL_!</title>
<subtitle>Result: _RE_</subtitle>
<title>_TL_ loses to _TW_!</title> <title>_TL_ loses to _TW_!</title>
<subtitle>_TL_ doesn't stand a chance against a _GOALS_TWN__ goal barrage.</subtitle>
<title>_TW_ wipes out _TL_!</title> <title>_TW_ wipes out _TL_!</title>
<subtitle>_RE_ is flattering for _TL_.</subtitle>
<title>_TL_ loses again!</title> <title>_TL_ loses again!</title>
<subtitle>_TW_ just too strong.</subtitle>
<title>_TL_ in a world of misery!</title> <title>_TL_ in a world of misery!</title>
<subtitle>_TW_: _RE_ against _TL_.</subtitle>
<title>_LEAGUECUPNAME_: _TL_ loses to _TW_!</title> <title>_LEAGUECUPNAME_: _TL_ loses to _TW_!</title>
<subtitle>Result: _RE_</subtitle>
<subtitle>_TL_ doesn't stand a chance against a _GOALS_TWN__ goal barrage.</subtitle>
<subtitle>_RE_ is flattering for _TL_.</subtitle>
<subtitle>_TW_ just too strong.</subtitle>
<subtitle>_TW_: _RE_ against _TL_.</subtitle>
<subtitle>_TL_ overwhelmed by _SHOTS_TWN__ shots.</subtitle> <subtitle>_TL_ overwhelmed by _SHOTS_TWN__ shots.</subtitle>
<subtitle condition="_MULTIPLESCORERS_ = 1">_SCORERS_TWN__ ensure victory for _TW_.</subtitle> <subtitle condition="_MULTIPLESCORERS_ = 1">_SCORERS_TWN__ ensure victory for _TW_.</subtitle>
<subtitle>_TW_ moves to rank _RANK_TWN__ in _LEAGUECUPNAME_.</subtitle> <subtitle condition="_RANK_TWN__ != _OLDRANK_TWN__">_TW_ moves to rank _RANK_TWN__ in _LEAGUECUPNAME_.</subtitle>
<subtitle condition="_RANK_TWN__ > _OLDRANK_TWN__">_TW_ moves to rank _RANK_TWN__ in _LEAGUECUPNAME_.</subtitle> <subtitle condition="_RANK_TWN__ > _OLDRANK_TWN__">_TW_ moves to rank _RANK_TWN__ in _LEAGUECUPNAME_.</subtitle>
<subtitle condition="_RANK_TWN__ = 1 and _OLDRANK_TWN__ != 1">_TW_ on top after defeating _TL_ _RE_.</subtitle> <subtitle condition="_RANK_TWN__ = 1 and _OLDRANK_TWN__ != 1">_TW_ on top after defeating _TL_ _RE_.</subtitle>
<subtitle condition="_WON_TWN__ > 1">_TW_'s streak now at _WON_TWN__ wins.</subtitle>
<subtitle condition="_LOST_TLN__ > 1">_TL_'s losing streak now at _LOST_TLN__!</subtitle>
<subtitle condition="_LEAGUEWON_TWN__ > 1">_TW_ wins _WON_TWN__th in a row in _LEAGUECUPNAME_.</subtitle>
<subtitle condition="_LEAGUELOST_TLN__ > 1">_TL_ loses _LOST_TLN__th in a row in _LEAGUECUPNAME_.</subtitle>
</news_article> </news_article>
</news> </news>

View File

@ -7,23 +7,27 @@
<paper_name>News Of The Sports World</paper_name> <paper_name>News Of The Sports World</paper_name>
<news_article> <news_article>
<type>match</type> <type>match</type>
<condition>_CUP_ = 0 _GD_ G 1</condition> <condition>_CUP_ = 0 and _GD_ G 1</condition>
<title>_TW_ [beats|crushes|kills] _TL_!</title> <title>_TW_ [beats|crushes|kills] _TL_!</title>
<subtitle>Result: _RE_</subtitle>
<title>_TL_ loses to _TW_!</title> <title>_TL_ loses to _TW_!</title>
<subtitle>_TL_ doesn't stand a chance against a _GOALS_TWN__ goal barrage.</subtitle>
<title>_TW_ wipes out _TL_!</title> <title>_TW_ wipes out _TL_!</title>
<subtitle>_RE_ is flattering for _TL_.</subtitle>
<title>_TL_ loses again!</title> <title>_TL_ loses again!</title>
<subtitle>_TW_ just too strong.</subtitle>
<title>_TL_ in a world of misery!</title> <title>_TL_ in a world of misery!</title>
<subtitle>_TW_: _RE_ against _TL_.</subtitle>
<title>_LEAGUECUPNAME_: _TL_ loses to _TW_!</title> <title>_LEAGUECUPNAME_: _TL_ loses to _TW_!</title>
<subtitle>Result: _RE_</subtitle>
<subtitle>_TL_ doesn't stand a chance against a _GOALS_TWN__ goal barrage.</subtitle>
<subtitle>_RE_ is flattering for _TL_.</subtitle>
<subtitle>_TW_ just too strong.</subtitle>
<subtitle>_TW_: _RE_ against _TL_.</subtitle>
<subtitle>_TL_ overwhelmed by _SHOTS_TWN__ shots.</subtitle> <subtitle>_TL_ overwhelmed by _SHOTS_TWN__ shots.</subtitle>
<subtitle condition="_MULTIPLESCORERS_ = 1">_SCORERS_TWN__ ensure victory for _TW_.</subtitle> <subtitle condition="_MULTIPLESCORERS_ = 1">_SCORERS_TWN__ ensure victory for _TW_.</subtitle>
<subtitle>_TW_ moves to rank _RANK_TWN__ in _LEAGUECUPNAME_.</subtitle> <subtitle condition="_RANK_TWN__ != _OLDRANK_TWN__">_TW_ moves to rank _RANK_TWN__ in _LEAGUECUPNAME_.</subtitle>
<subtitle condition="_RANK_TWN__ > _OLDRANK_TWN__">_TW_ moves to rank _RANK_TWN__ in _LEAGUECUPNAME_.</subtitle> <subtitle condition="_RANK_TWN__ > _OLDRANK_TWN__">_TW_ moves to rank _RANK_TWN__ in _LEAGUECUPNAME_.</subtitle>
<subtitle condition="_RANK_TWN__ = 1 and _OLDRANK_TWN__ != 1">_TW_ on top after defeating _TL_ _RE_.</subtitle> <subtitle condition="_RANK_TWN__ = 1 and _OLDRANK_TWN__ != 1">_TW_ on top after defeating _TL_ _RE_.</subtitle>
<subtitle condition="_WON_TWN__ > 1">_TW_'s streak now at _WON_TWN__ wins.</subtitle>
<subtitle condition="_LOST_TLN__ > 1">_TL_'s losing streak now at _LOST_TLN__!</subtitle>
<subtitle condition="_LEAGUEWON_TWN__ > 1">_TW_ wins _WON_TWN__th in a row in _LEAGUECUPNAME_.</subtitle>
<subtitle condition="_LEAGUELOST_TLN__ > 1">_TL_ loses _LOST_TLN__th in a row in _LEAGUECUPNAME_.</subtitle>
</news_article> </news_article>
</news> </news>