1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-01-31 07:54:50 +01:00

"Commentary improvements."

This commit is contained in:
gyboth 2005-07-01 20:51:46 +00:00
parent 0d8bf904a4
commit aeb715bcf9
25 changed files with 658 additions and 397 deletions

File diff suppressed because one or more lines are too long

View File

@ -20,7 +20,7 @@ AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.]) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.])
dnl Add the languages which your application supports here. dnl Add the languages which your application supports here.
ALL_LINGUAS="de nl" ALL_LINGUAS="de nl fr"
AM_GLIB_GNU_GETTEXT AM_GLIB_GNU_GETTEXT
AC_OUTPUT([ AC_OUTPUT([

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2005-06-28 04:05+0200\n" "POT-Creation-Date: 2005-07-01 22:48+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -71,7 +71,7 @@ msgid ""
"player's value. Do you accept?" "player's value. Do you accept?"
msgstr "" msgstr ""
#: src/callback_func.c:383 src/callbacks.c:538 #: src/callback_func.c:383 src/callbacks.c:537
msgid "Your offer has been removed." msgid "Your offer has been removed."
msgstr "" msgstr ""
@ -148,7 +148,7 @@ msgstr ""
msgid "The current game state is unsaved and will be lost. Continue?" msgid "The current game state is unsaved and will be lost. Continue?"
msgstr "" msgstr ""
#: src/callbacks.c:148 src/callbacks.c:402 #: src/callbacks.c:148 src/callbacks.c:401
msgid "Transfers are disabled in this country definition." msgid "Transfers are disabled in this country definition."
msgstr "" msgstr ""
@ -161,86 +161,86 @@ msgstr ""
msgid "Transfer deadline is Week %d" msgid "Transfer deadline is Week %d"
msgstr "" msgstr ""
#: src/callbacks.c:162 #: src/callbacks.c:161
msgid "The transfer deadline is over." msgid "The transfer deadline is over."
msgstr "" msgstr ""
#: src/callbacks.c:171 src/callbacks.c:566 src/callbacks.c:583 #: src/callbacks.c:170 src/callbacks.c:565 src/callbacks.c:582
msgid "You still have some transfer business to manage." msgid "You still have some transfer business to manage."
msgstr "" msgstr ""
#: src/callbacks.c:175 #: src/callbacks.c:174
msgid "At least one user didn't take his turn this week. Continue?" msgid "At least one user didn't take his turn this week. Continue?"
msgstr "" msgstr ""
#: src/callbacks.c:181 #: src/callbacks.c:180
msgid "There are injured or banned players in one of the user teams. Continue?" msgid "There are injured or banned players in one of the user teams. Continue?"
msgstr "" msgstr ""
#: src/callbacks.c:386 #: src/callbacks.c:385
msgid "This is your first season." msgid "This is your first season."
msgstr "" msgstr ""
#: src/callbacks.c:404 src/callbacks.c:420 src/callbacks.c:436 #: src/callbacks.c:403 src/callbacks.c:419 src/callbacks.c:435
#: src/callbacks.c:454 src/callbacks.c:799 src/callbacks.c:815 #: src/callbacks.c:453 src/callbacks.c:798 src/callbacks.c:814
msgid "You haven't selected a player." msgid "You haven't selected a player."
msgstr "" msgstr ""
#: src/callbacks.c:406 #: src/callbacks.c:405
msgid "The player is already on the list." msgid "The player is already on the list."
msgstr "" msgstr ""
#: src/callbacks.c:422 #: src/callbacks.c:421
msgid "The player is not on the list." msgid "The player is not on the list."
msgstr "" msgstr ""
#: src/callbacks.c:438 #: src/callbacks.c:437
msgid "Your team can't have less than 11 players." msgid "Your team can't have less than 11 players."
msgstr "" msgstr ""
#: src/callbacks.c:459 #: src/callbacks.c:458
msgid "Penalty/free kick shooter deselected." msgid "Penalty/free kick shooter deselected."
msgstr "" msgstr ""
#: src/callbacks.c:465 #: src/callbacks.c:464
#, c-format #, c-format
msgid "%s will shoot penalties and free kicks when he plays." msgid "%s will shoot penalties and free kicks when he plays."
msgstr "" msgstr ""
#: src/callbacks.c:540 #: src/callbacks.c:539
msgid "You haven't made an offer for the player." msgid "You haven't made an offer for the player."
msgstr "" msgstr ""
#: src/callbacks.c:599 #: src/callbacks.c:598
msgid "Enter a structure. The digits must sum up to 10." msgid "Enter a structure. The digits must sum up to 10."
msgstr "" msgstr ""
#: src/callbacks.c:600 #: src/callbacks.c:599
msgid "Structure" msgid "Structure"
msgstr "" msgstr ""
#: src/callbacks.c:633 src/callbacks.c:649 #: src/callbacks.c:632 src/callbacks.c:648
msgid "No match stored." msgid "No match stored."
msgstr "" msgstr ""
#: src/callbacks.c:727 src/game_gui.c:309 #: src/callbacks.c:726 src/game_gui.c:309
msgid "Boost ON is disabled in this country definition." msgid "Boost ON is disabled in this country definition."
msgstr "" msgstr ""
#: src/callbacks.c:749 #: src/callbacks.c:748
msgid "Finances are disabled in this country definition." msgid "Finances are disabled in this country definition."
msgstr "" msgstr ""
#: src/callbacks.c:754 #: src/callbacks.c:753
msgid "" msgid ""
"Left-click: get loan; Right-click: pay back; Middle click: stadium window." "Left-click: get loan; Right-click: pay back; Middle click: stadium window."
msgstr "" msgstr ""
#: src/callbacks.c:768 #: src/callbacks.c:767
msgid "Stadium management is disabled in this country definition." msgid "Stadium management is disabled in this country definition."
msgstr "" msgstr ""
#: src/callbacks.c:793 #: src/callbacks.c:792
msgid "Contracts are disabled in this country definition." msgid "Contracts are disabled in this country definition."
msgstr "" msgstr ""
@ -733,38 +733,38 @@ msgstr ""
msgid "Next (W)" msgid "Next (W)"
msgstr "" msgstr ""
#: src/lg_commentary.c:331 src/team.c:500 #: src/lg_commentary.c:524 src/team.c:500
msgid "ALL OUT DEFEND" msgid "ALL OUT DEFEND"
msgstr "" msgstr ""
#: src/lg_commentary.c:334 src/team.c:502 #: src/lg_commentary.c:527 src/team.c:502
msgid "DEFEND" msgid "DEFEND"
msgstr "" msgstr ""
#: src/lg_commentary.c:337 src/team.c:504 #: src/lg_commentary.c:530 src/team.c:504
msgid "BALANCED" msgid "BALANCED"
msgstr "" msgstr ""
#: src/lg_commentary.c:340 src/team.c:506 #: src/lg_commentary.c:533 src/team.c:506
msgid "ATTACK" msgid "ATTACK"
msgstr "" msgstr ""
#: src/lg_commentary.c:343 src/team.c:508 #: src/lg_commentary.c:536 src/team.c:508
msgid "ALL OUT ATTACK" msgid "ALL OUT ATTACK"
msgstr "" msgstr ""
#. Boost value. #. Boost value.
#: src/lg_commentary.c:346 src/team.c:516 #: src/lg_commentary.c:539 src/team.c:516
msgid "ANTI" msgid "ANTI"
msgstr "" msgstr ""
#. Boost value. #. Boost value.
#: src/lg_commentary.c:349 src/team.c:519 #: src/lg_commentary.c:542 src/team.c:519
msgid "OFF" msgid "OFF"
msgstr "" msgstr ""
#. Boost value. #. Boost value.
#: src/lg_commentary.c:352 src/team.c:522 #: src/lg_commentary.c:545 src/team.c:522
msgid "ON" msgid "ON"
msgstr "" msgstr ""

View File

@ -16,17 +16,17 @@ bygfoot_SOURCES = \
file.c file.h free.h main.h misc.h option.h support.h variables.h \ file.c file.h free.h main.h misc.h option.h support.h variables.h \
finance.c callbacks.h finance.h game_gui.h maths.h option.h player.h team.h user.h \ finance.c callbacks.h finance.h game_gui.h maths.h option.h player.h team.h user.h \
fixture.c cup.h fixture.h free.h league.h main.h maths.h misc.h option.h table.h team.h user.h variables.h \ fixture.c cup.h fixture.h free.h league.h main.h maths.h misc.h option.h table.h team.h user.h variables.h \
free.c free.h transfer.h user.h variables.h \ free.c free.h lg_commentary_struct.h transfer.h user.h variables.h \
game.c cup.h finance.h fixture.h game_gui.h game.h league.h live_game.h main.h maths.h misc.h option.h player.h table.h team.h treeview.h user.h variables.h \ game.c cup.h finance.h fixture.h game_gui.h game.h league.h live_game.h main.h maths.h misc.h option.h player.h table.h team.h treeview.h user.h variables.h \
game_gui.c callbacks.h file.h game_gui.h gui.h league.h live_game.h maths.h misc.h option.h support.h team.h treeview.h user.h variables.h window.h \ game_gui.c callbacks.h file.h game_gui.h gui.h league.h live_game.h maths.h misc.h option.h support.h team.h treeview.h user.h variables.h window.h \
gui.c gui.h misc.h support.h variables.h window.h \ gui.c gui.h misc.h support.h variables.h window.h \
interface.c callbacks.h interface.h support.h \ interface.c callbacks.h interface.h support.h \
language.c callbacks.h free.h language.h lg_commentary.h misc.h option.h variables.h window.h \ language.c callbacks.h free.h language.h lg_commentary.h misc.h option.h variables.h window.h \
lg_commentary.c file.h free.h lg_commentary.h live_game.h main.h misc.h option.h player.h variables.h xml_lg_commentary.h \ lg_commentary.c cup.h file.h fixture.h league.h lg_commentary.h live_game.h main.h maths.h misc.h option.h player.h team.h variables.h xml_lg_commentary.h \
league.c cup.h free.h league.h main.h maths.h misc.h option.h player.h stat.h table.h team.h user.h variables.h \ league.c cup.h free.h league.h main.h maths.h misc.h option.h player.h stat.h table.h team.h user.h variables.h \
live_game.c callbacks.h fixture.h free.h game_gui.h game.h lg_commentary.h live_game.h main.h maths.h misc_callback_func.h option.h player.h support.h team.h treeview.h user.h variables.h window.h \ live_game.c callbacks.h fixture.h free.h game_gui.h game.h lg_commentary.h live_game.h main.h maths.h misc_callback_func.h misc.h option.h player.h support.h team.h treeview.h user.h variables.h window.h \
load_save.c callbacks.h file.h game_gui.h gui.h language.h load_save.h option.h support.h user.h variables.h xml.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_misc.h xml_loadsave_season_stats.h xml_loadsave_transfers.h xml_loadsave_users.h \ load_save.c callbacks.h file.h game_gui.h gui.h language.h load_save.h option.h support.h user.h variables.h xml.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_misc.h xml_loadsave_season_stats.h xml_loadsave_transfers.h xml_loadsave_users.h \
main.c file.h free.h language.h live_game.h main.h misc_callbacks.h name_struct.h option.h stat_struct.h transfer_struct.h variables.h window.h \ main.c file.h free.h language.h lg_commentary_struct.h live_game.h main.h misc_callbacks.h name_struct.h option.h stat_struct.h transfer_struct.h variables.h window.h \
maths.c maths.h misc.h variables.h \ maths.c maths.h misc.h variables.h \
misc.c main.h maths.h misc.h \ misc.c main.h maths.h misc.h \
misc_callbacks.c callback_func.h callbacks.h game_gui.h game.h gui.h live_game.h load_save.h main.h maths.h misc_callback_func.h misc_callbacks.h option.h user.h variables.h window.h xml_country.h \ misc_callbacks.c callback_func.h callbacks.h game_gui.h game.h gui.h live_game.h load_save.h main.h maths.h misc_callback_func.h misc_callbacks.h option.h user.h variables.h window.h xml_country.h \

View File

@ -287,7 +287,7 @@ callback_get_loan(void)
} }
stat1 = STATUS_GET_LOAN; stat1 = STATUS_GET_LOAN;
misc_print_grouped_int(max_loan, buf2, FALSE); misc_print_grouped_int(max_loan, buf2);
sprintf(buf, _("You can take out at most %s."), buf2); sprintf(buf, _("You can take out at most %s."), buf2);
window_show_digits(buf, _("Loan"), max_loan, NULL, 0); window_show_digits(buf, _("Loan"), max_loan, NULL, 0);
@ -313,7 +313,7 @@ callback_pay_loan(void)
} }
stat1 = STATUS_PAY_LOAN; stat1 = STATUS_PAY_LOAN;
misc_print_grouped_int(max_payback, buf2, FALSE); misc_print_grouped_int(max_payback, buf2);
sprintf(buf, _("You can pay back at most %s"), buf2); sprintf(buf, _("You can pay back at most %s"), buf2);
window_show_digits(buf, _("Payback"), max_payback, NULL, 0); window_show_digits(buf, _("Payback"), max_payback, NULL, 0);
@ -344,10 +344,10 @@ callback_transfer_list_user(gint button, gint idx)
game_gui_print_message(_("There are some offers for the player which you rejected or will see next week.")); game_gui_print_message(_("There are some offers for the player which you rejected or will see next week."));
else else
{ {
misc_print_grouped_int(transoff(idx, 0).fee, buf2, FALSE); misc_print_grouped_int(transoff(idx, 0).fee, buf2);
misc_print_grouped_int(ABS(transoff(idx, 0).fee - misc_print_grouped_int(ABS(transoff(idx, 0).fee -
player_of_id_team(current_user.tm, player_of_id_team(current_user.tm,
trans(idx).id)->value), buf3, FALSE); trans(idx).id)->value), buf3);
if(transoff(idx, 0).fee - if(transoff(idx, 0).fee -
player_of_id_team(current_user.tm, trans(idx).id)->value > 0) player_of_id_team(current_user.tm, trans(idx).id)->value > 0)
strcat(buf3, _(" more")); strcat(buf3, _(" more"));
@ -391,8 +391,8 @@ callback_transfer_list_cpu(gint button, gint idx)
return; return;
} }
misc_print_grouped_int(transoff(idx, 0).fee, buf2, FALSE); misc_print_grouped_int(transoff(idx, 0).fee, buf2);
misc_print_grouped_int(transoff(idx, 0).wage, buf3, FALSE); misc_print_grouped_int(transoff(idx, 0).wage, buf3);
sprintf(buf, _("You offered a transfer fee of %s and a wage of %s for %s. The owners and the player are satisfied with your offer. Do you still want to buy the player?"), sprintf(buf, _("You offered a transfer fee of %s and a wage of %s for %s. The owners and the player are satisfied with your offer. Do you still want to buy the player?"),
buf2, buf3, player_of_id_team(trans(idx).tm, trans(idx).id)->name->str); buf2, buf3, player_of_id_team(trans(idx).tm, trans(idx).id)->name->str);
@ -436,12 +436,6 @@ callback_transfer_list_clicked(gint button, gint idx)
return; return;
} }
if (week >= transfer_get_deadline()-1)
{
game_gui_print_message(_("You can't make an offer so close to the transfer deadline."));
return;
}
stat1 = STATUS_SHOW_TRANSFER_LIST; stat1 = STATUS_SHOW_TRANSFER_LIST;
stat2 = idx; stat2 = idx;
@ -617,7 +611,7 @@ callback_fire_player(gint idx)
stat2 = idx; stat2 = idx;
stat3 = (gint)rint(pl->wage * const_float("float_player_fire_wage_factor") * pl->contract); stat3 = (gint)rint(pl->wage * const_float("float_player_fire_wage_factor") * pl->contract);
misc_print_grouped_int(stat3, buf2, FALSE); misc_print_grouped_int(stat3, buf2);
sprintf(buf, _("You want to fire %s. Since his contract expires in %.1f years, he demands a compensation of %s. Do you accept?"), pl->name->str, pl->contract, buf2); sprintf(buf, _("You want to fire %s. Since his contract expires in %.1f years, he demands a compensation of %s. Do you accept?"), pl->name->str, pl->contract, buf2);

View File

@ -151,7 +151,6 @@ on_button_transfers_clicked (GtkButton *button,
stat0 = STATUS_SHOW_TRANSFER_LIST; stat0 = STATUS_SHOW_TRANSFER_LIST;
game_gui_print_message(_("Left click to make an offer. Right click to remove offer.")); game_gui_print_message(_("Left click to make an offer. Right click to remove offer."));
sprintf(buf, _("Transfer deadline is Week %d"), transfer_get_deadline()); sprintf(buf, _("Transfer deadline is Week %d"), transfer_get_deadline());
printf("buf %s \n", buf);
game_gui_print_message_with_delay(buf); game_gui_print_message_with_delay(buf);
treeview_show_transfer_list(GTK_TREE_VIEW(lookup_widget(window.main, "treeview_right"))); treeview_show_transfer_list(GTK_TREE_VIEW(lookup_widget(window.main, "treeview_right")));
gtk_notebook_set_current_page(GTK_NOTEBOOK(lookup_widget(window.main, "notebook_player")), 1); gtk_notebook_set_current_page(GTK_NOTEBOOK(lookup_widget(window.main, "notebook_player")), 1);

View File

@ -160,16 +160,14 @@ void
file_check_home_dir_copy_conf_files(void) file_check_home_dir_copy_conf_files(void)
{ {
gint i; gint i;
gchar *conf_files[4] = gchar *conf_files[2] =
{"bygfoot.conf", {"bygfoot.conf",
"bygfoot_user.conf", "bygfoot_user.conf"};
"bygfoot_constants",
"bygfoot_app"};
const gchar *home = g_get_home_dir(); const gchar *home = g_get_home_dir();
gchar *conf_file = NULL; gchar *conf_file = NULL;
gchar buf[SMALL]; gchar buf[SMALL];
for(i=0;i<4;i++) for(i=0;i<2;i++)
{ {
sprintf(buf, "%s/%s/%s", home, HOMEDIRNAME, conf_files[i]); sprintf(buf, "%s/%s/%s", home, HOMEDIRNAME, conf_files[i]);
if(!g_file_test(buf, G_FILE_TEST_EXISTS)) if(!g_file_test(buf, G_FILE_TEST_EXISTS))
@ -444,6 +442,7 @@ file_load_opt_file(const gchar *filename, OptionList *optionlist)
void void
file_load_conf_files(void) file_load_conf_files(void)
{ {
gint i;
gchar *conf_file = file_find_support_file("bygfoot.conf", TRUE); gchar *conf_file = file_find_support_file("bygfoot.conf", TRUE);
file_load_opt_file(conf_file, &options); file_load_opt_file(conf_file, &options);
@ -452,6 +451,9 @@ file_load_conf_files(void)
file_load_opt_file(opt_str("string_opt_constants_file"), &constants); file_load_opt_file(opt_str("string_opt_constants_file"), &constants);
file_load_opt_file(opt_str("string_opt_appearance_file"), &constants_app); file_load_opt_file(opt_str("string_opt_appearance_file"), &constants_app);
file_load_opt_file("bygfoot_lg_tokens", &lg_tokens); file_load_opt_file("bygfoot_lg_tokens", &lg_tokens);
for(i=0;i<lg_tokens.list->len;i++)
g_array_index(lg_tokens.list, Option, i).value = i;
} }
/** Load a user-specific conf file. /** Load a user-specific conf file.

View File

@ -1,4 +1,5 @@
#include "free.h" #include "free.h"
#include "lg_commentary_struct.h"
#include "transfer.h" #include "transfer.h"
#include "user.h" #include "user.h"
#include "variables.h" #include "variables.h"
@ -16,6 +17,7 @@ free_memory(void)
free_country(FALSE); free_country(FALSE);
free_users(FALSE); free_users(FALSE);
free_live_game(&live_game_temp); free_live_game(&live_game_temp);
free_lg_commentary(FALSE);
free_support_dirs(); free_support_dirs();
} }
@ -450,7 +452,7 @@ free_cup_choose_team(CupChooseTeam *cup_choose_team)
void void
free_variables(void) free_variables(void)
{ {
gint i; gint i, j;
free_option_list(&options, FALSE); free_option_list(&options, FALSE);
free_option_list(&settings, FALSE); free_option_list(&settings, FALSE);
@ -458,9 +460,6 @@ free_variables(void)
free_option_list(&constants_app, FALSE); free_option_list(&constants_app, FALSE);
free_option_list(&lg_tokens, FALSE); free_option_list(&lg_tokens, FALSE);
for(i=0;i<LIVE_GAME_EVENT_END;i++)
free_g_string_array(&lg_commentary[i]);
free_g_string(&save_file); free_g_string(&save_file);
g_rand_free(rand_generator); g_rand_free(rand_generator);
@ -468,6 +467,29 @@ free_variables(void)
free_season_stats(FALSE); free_season_stats(FALSE);
} }
/** Free the list with live game commentary text. */
void
free_lg_commentary(gboolean reset)
{
gint i, j;
for(i=0;i<LIVE_GAME_EVENT_END;i++)
if(lg_commentary[i] != NULL)
{
for(j=0;j<lg_commentary[i]->len;j++)
{
free_g_string(&g_array_index(lg_commentary[i], LGCommentary, j).text);
free_g_string(&g_array_index(lg_commentary[i], LGCommentary, j).condition);
}
free_g_array(&lg_commentary[i]);
}
if(reset)
for(i=0;i<LIVE_GAME_EVENT_END;i++)
lg_commentary[i] = g_array_new(FALSE, FALSE, sizeof(LGCommentary));
}
/** /**
Free a GPtrArray containing GStrings. Free a GPtrArray containing GStrings.
@param array The array to be freed. @param array The array to be freed.

View File

@ -64,6 +64,9 @@ free_player(Player *pl);
void void
free_live_game(LiveGame *match); free_live_game(LiveGame *match);
void
free_lg_commentary(gboolean reset);
void void
free_option_list(OptionList *optionlist, gboolean reset); free_option_list(OptionList *optionlist, gboolean reset);

View File

@ -201,7 +201,7 @@ game_gui_set_main_window_header(void)
if(!sett_int("int_opt_disable_finances")) if(!sett_int("int_opt_disable_finances"))
{ {
misc_print_grouped_int(current_user.money, buf, FALSE); misc_print_grouped_int(current_user.money, buf);
gtk_label_set_text(label_money, buf); gtk_label_set_text(label_money, buf);
} }
else else
@ -566,9 +566,9 @@ game_gui_show_job_offer(Team *team, gint type)
misc_print_grouped_int(math_round_integer(team->stadium.capacity * misc_print_grouped_int(math_round_integer(team->stadium.capacity *
math_rndi(const_int("int_initial_money_lower"), math_rndi(const_int("int_initial_money_lower"),
const_int("int_initial_money_upper")), 2), const_int("int_initial_money_upper")), 2),
buf, FALSE); buf);
gtk_label_set_text(label_money, buf); gtk_label_set_text(label_money, buf);
misc_print_grouped_int(team->stadium.capacity, buf, FALSE); misc_print_grouped_int(team->stadium.capacity, buf);
gtk_label_set_text(label_cap, buf); gtk_label_set_text(label_cap, buf);
gui_label_set_text_from_int(label_saf, (gint)rint(team->stadium.safety * 100), FALSE); gui_label_set_text_from_int(label_saf, (gint)rint(team->stadium.safety * 100), FALSE);

View File

@ -18,7 +18,7 @@ gui_label_set_text_from_int(GtkLabel *label, gint number, gboolean append)
strcpy(buf2, ""); strcpy(buf2, "");
if(number > 1000) if(number > 1000)
misc_print_grouped_int(number, buf, FALSE); misc_print_grouped_int(number, buf);
else else
sprintf(buf, "%d", number); sprintf(buf, "%d", number);

View File

@ -1,28 +1,96 @@
#include <locale.h> #include <locale.h>
#include "cup.h"
#include "file.h" #include "file.h"
#include "free.h" #include "fixture.h"
#include "league.h"
#include "lg_commentary.h" #include "lg_commentary.h"
#include "live_game.h" #include "live_game.h"
#include "main.h" #include "main.h"
#include "maths.h"
#include "misc.h" #include "misc.h"
#include "option.h" #include "option.h"
#include "player.h" #include "player.h"
#include "team.h"
#include "variables.h" #include "variables.h"
#include "xml_lg_commentary.h" #include "xml_lg_commentary.h"
/** The replacement strings for the live game commentary tokens. */
gchar **token_rep;
/** Allocate memory for the token array and fill some tokens
at the beginning of the live game that don't change later. */
void
lg_commentary_initialize(const Fixture *fix)
{
gint i;
gchar buf[SMALL];
token_rep = (gchar**)g_malloc(sizeof(gchar*) * lg_tokens.list->len);
for(i=0;i<lg_tokens.list->len;i++)
token_rep[i] = NULL;
token_rep[option_int("string_lg_commentary_token_team_home", &lg_tokens)] =
g_strdup(fix->teams[0]->name->str);
token_rep[option_int("string_lg_commentary_token_team_away", &lg_tokens)] =
g_strdup(fix->teams[1]->name->str);
if(fix->teams[0]->clid < ID_CUP_START)
token_rep[option_int("string_lg_commentary_token_team_layer0", &lg_tokens)] =
misc_int_to_char(league_from_clid(fix->teams[0]->clid)->layer);
if(fix->teams[1]->clid < ID_CUP_START)
token_rep[option_int("string_lg_commentary_token_team_layer1", &lg_tokens)] =
misc_int_to_char(league_from_clid(fix->teams[1]->clid)->layer);
token_rep[option_int("string_lg_commentary_token_league_cup_name", &lg_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);
token_rep[option_int("string_lg_commentary_token_cup_round_name", &lg_tokens)] =
g_strdup(buf);
}
misc_print_grouped_int(fix->attendance, buf);
token_rep[option_int("string_lg_commentary_token_attendance", &lg_tokens)] =
g_strdup(buf);
token_rep[option_int("string_lg_commentary_token_yellow_limit", &lg_tokens)] =
misc_int_to_char(league_cup_get_yellow_red(fix->clid));
}
/** Free the memory occupied by the tokens array and the permanent tokens. */
void
lg_commentary_post_match(void)
{
g_free(token_rep[option_int("string_lg_commentary_token_team_home", &lg_tokens)]);
g_free(token_rep[option_int("string_lg_commentary_token_team_away", &lg_tokens)]);
g_free(token_rep[option_int("string_lg_commentary_token_attendance", &lg_tokens)]);
g_free(token_rep[option_int("string_lg_commentary_token_league_cup_name", &lg_tokens)]);
g_free(token_rep[option_int("string_lg_commentary_token_cup_round_name", &lg_tokens)]);
g_free(token_rep[option_int("string_lg_commentary_token_yellow_limit", &lg_tokens)]);
g_free(token_rep[option_int("string_lg_commentary_token_team_layer0", &lg_tokens)]);
g_free(token_rep[option_int("string_lg_commentary_token_team_layer1", &lg_tokens)]);
g_free(token_rep);
}
/** Generate commentary for the live game event in the unit. /** Generate commentary for the live game event in the unit.
@param unit The unit we comment. @param unit The unit we comment.
@param fix The fixture being calculated. */ @param fix The fixture being calculated. */
void void
lg_commentary_generate(LiveGameUnit *unit, const Fixture *fix) lg_commentary_generate(const LiveGame *live_game, LiveGameUnit *unit)
{ {
gchar buf[SMALL]; gchar buf[SMALL];
GPtrArray **commentaries = NULL; GArray **commentaries = NULL;
GPtrArray *strings = g_ptr_array_new();
gint i; gint i;
lg_commentary_set_strings(strings, unit, fix); 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);
if(unit->event.type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND || if(unit->event.type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND ||
unit->event.type == LIVE_GAME_EVENT_STYLE_CHANGE_DEFEND || unit->event.type == LIVE_GAME_EVENT_STYLE_CHANGE_DEFEND ||
@ -37,12 +105,12 @@ lg_commentary_generate(LiveGameUnit *unit, const Fixture *fix)
else else
commentaries = &lg_commentary[unit->event.type]; commentaries = &lg_commentary[unit->event.type];
*commentaries = misc_randomise_g_pointer_array(*commentaries); gint order[(*commentaries)->len];
lg_commentary_get_order(*commentaries, order);
for(i=0;i<(*commentaries)->len;i++) for(i=0;i<(*commentaries)->len;i++)
{ {
if(lg_commentary_replace_tokens( if(lg_commentary_check_commentary(&g_array_index(*commentaries, LGCommentary, order[i]), buf))
((GString*)g_ptr_array_index((*commentaries), i))->str, strings, buf))
break; break;
} }
@ -56,260 +124,385 @@ lg_commentary_generate(LiveGameUnit *unit, const Fixture *fix)
unit->event.commentary = g_string_new(buf); unit->event.commentary = g_string_new(buf);
for(i=0;i<lg_tokens.list->len;i++) for(i=0;i<lg_tokens.list->len;i++)
g_free(g_ptr_array_index(strings, i)); if(i != option_int("string_lg_commentary_token_team_home", &lg_tokens) &&
i != option_int("string_lg_commentary_token_team_away", &lg_tokens) &&
i != option_int("string_lg_commentary_token_attendance", &lg_tokens) &&
i != option_int("string_lg_commentary_token_cup_round_name", &lg_tokens) &&
i != option_int("string_lg_commentary_token_league_cup_name", &lg_tokens) &&
i != option_int("string_lg_commentary_token_yellow_limit", &lg_tokens) &&
i != option_int("string_lg_commentary_token_team_layer0", &lg_tokens) &&
i != option_int("string_lg_commentary_token_team_layer1", &lg_tokens))
{
g_free(token_rep[i]);
token_rep[i] = NULL;
}
}
g_ptr_array_free(strings, TRUE); /** Check whether the commentary conditions are fulfilled and whether
we can replace all tokens in the commentary. */
gboolean
lg_commentary_check_commentary(const LGCommentary *commentary, gchar *dest)
{
if(commentary->condition != NULL &&
!lg_commentary_parse_condition(commentary->condition->str))
return FALSE;
strcpy(dest, commentary->text->str);
if(lg_commentary_replace_tokens(dest))
{
lg_commentary_replace_expressions(dest);
if(lg_commentary_replace_tokens(dest))
return TRUE;
}
return FALSE;
}
/** Replace simple arithmetic expressions like "1 + 2"
and comparisons like "3 < 4" with the appropriate result. */
void
lg_commentary_replace_expressions(gchar *commentary_text)
{
gint i, j, last_idx = 0;
gint value = -1;
gchar buf[SMALL], buf2[SMALL];
strcpy(buf, commentary_text);
strcpy(commentary_text, "");
for(i=0;i<strlen(buf);i++)
if(buf[i] == '[')
{
strncpy(buf2, buf + last_idx, i - last_idx);
buf2[i - last_idx] = '\0';
strcat(commentary_text, buf2);
for(j=i + 1;j<strlen(buf);j++)
{
if(buf[j] == ']')
{
strncpy(buf2, buf + i + 1, j - i - 1);
buf2[j - i - 1] = '\0';
if(query_misc_string_contains(buf2, "<") ||
query_misc_string_contains(buf2, ">") ||
query_misc_string_contains(buf2, "="))
misc_parse(buf2, &value);
else
misc_parse_expression(buf2, &value);
sprintf(buf2, "%d", value);
strcat(commentary_text, buf2);
value = -1;
last_idx = j + 1;
break;
}
}
}
if(last_idx < strlen(buf))
{
strncpy(buf2, buf + last_idx, strlen(buf) - last_idx);
buf2[strlen(buf) - last_idx] = '\0';
strcat(commentary_text, buf2);
}
} }
/** Try to replace all special tokens in the string and write the result to dest. /** Try to replace all special tokens in the string and write the result to dest.
@param string The commentary string with tokens. @param commentary The commentary with tokens.
@param strings The replacements of the tokens.
@param dest The destination string. @param dest The destination string.
@return TRUE if we could replace all tokens, FALSE otherwise. */ @return TRUE if we could replace all tokens and the commentary condition
was fulfilled, FALSE otherwise. */
gboolean gboolean
lg_commentary_replace_tokens(const gchar *string, const GPtrArray *strings, gchar *dest) lg_commentary_replace_tokens(gchar *commentary_text)
{ {
gint i; gint i;
gboolean condition;
gchar buf[SMALL];
const gchar *buf2 = NULL;
strcpy(buf, string); for(i=0;i<lg_tokens.list->len;i++)
{
if(query_misc_string_contains(commentary_text,
g_array_index(lg_tokens.list, Option, i).string_value->str))
{
if(token_rep[i] == NULL)
return FALSE;
else
misc_string_replace_token(commentary_text,
g_array_index(lg_tokens.list, Option, i).string_value->str,
token_rep[i]);
}
}
return TRUE;
}
/** Find out whether the conditions of the commentary are fulfilled. */
gboolean
lg_commentary_parse_condition(const gchar *condition)
{
gint i;
gboolean return_value = FALSE;
gchar buf[SMALL];
strcpy(buf, condition);
for(i=0;i<lg_tokens.list->len;i++) for(i=0;i<lg_tokens.list->len;i++)
{ {
if(query_misc_string_contains(buf, g_array_index(lg_tokens.list, Option, i).string_value->str)) if(query_misc_string_contains(buf, g_array_index(lg_tokens.list, Option, i).string_value->str))
{ {
if(g_ptr_array_index(strings, i) == NULL) if(token_rep[i] == NULL)
return FALSE; return FALSE;
else else
misc_string_replace_token(buf, misc_string_replace_token(buf,
g_array_index(lg_tokens.list, Option, i).string_value->str, g_array_index(lg_tokens.list, Option, i).string_value->str,
(gchar*)g_ptr_array_index(strings, i)); token_rep[i]);
} }
} }
misc_replace_sums(buf); misc_parse(buf, &return_value);
if(buf[0] == '#') return return_value;
{
buf2 = misc_parse(buf + 1, &condition);
strcpy(dest, buf2);
return condition;
}
else
strcpy(dest, buf);
return TRUE;
} }
/** Get the strings corresponding to the commentary tokens. */
/** 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 void
lg_commentary_set_strings(GPtrArray *strings, const LiveGameUnit *unit, const Fixture *fix) lg_commentary_get_order(const GArray *commentaries, gint *order)
{
gint i, j, order_idx = 0;
gint priority_sum = 0, bounds[commentaries->len + 1];
bounds[0] = 0;
for(i=0;i<commentaries->len;i++)
{
priority_sum += g_array_index(commentaries, LGCommentary, i).priority;
bounds[i + 1] = priority_sum;
order[i] = -1;
}
gint permutation[priority_sum];
math_generate_permutation(permutation, 1, priority_sum);
for(i=0;i<priority_sum;i++)
{
if(order_idx == commentaries->len)
break;
for(j=0;j<commentaries->len;j++)
if(bounds[j] < permutation[i] && permutation[i] <= bounds[j + 1])
{
if(!query_integer_is_in_array(j, order, 0, commentaries->len))
{
order[order_idx] = j;
order_idx++;
}
break;
}
}
}
/** Fill the stats tokens. */
void
lg_commentary_set_stats_tokens(const LiveGameStats *stats)
{
token_rep[option_int("string_lg_commentary_token_stat_shots0", &lg_tokens)] =
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_SHOTS]);
token_rep[option_int("string_lg_commentary_token_stat_shot_per0", &lg_tokens)] =
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_SHOT_PERCENTAGE]);
token_rep[option_int("string_lg_commentary_token_stat_poss0", &lg_tokens)] =
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_POSSESSION]);
token_rep[option_int("string_lg_commentary_token_stat_pen0", &lg_tokens)] =
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_PENALTIES]);
token_rep[option_int("string_lg_commentary_token_stat_fouls0", &lg_tokens)] =
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_FOULS]);
token_rep[option_int("string_lg_commentary_token_stat_yellows0", &lg_tokens)] =
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_CARDS]);
token_rep[option_int("string_lg_commentary_token_stat_reds0", &lg_tokens)] =
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_REDS]);
token_rep[option_int("string_lg_commentary_token_stat_injs0", &lg_tokens)] =
misc_int_to_char(stats->values[0][LIVE_GAME_STAT_VALUE_INJURIES]);
token_rep[option_int("string_lg_commentary_token_stat_shots1", &lg_tokens)] =
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_SHOTS]);
token_rep[option_int("string_lg_commentary_token_stat_shot_per1", &lg_tokens)] =
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_SHOT_PERCENTAGE]);
token_rep[option_int("string_lg_commentary_token_stat_poss1", &lg_tokens)] =
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_POSSESSION]);
token_rep[option_int("string_lg_commentary_token_stat_pen1", &lg_tokens)] =
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_PENALTIES]);
token_rep[option_int("string_lg_commentary_token_stat_fouls1", &lg_tokens)] =
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_FOULS]);
token_rep[option_int("string_lg_commentary_token_stat_yellows1", &lg_tokens)] =
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_CARDS]);
token_rep[option_int("string_lg_commentary_token_stat_reds1", &lg_tokens)] =
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_REDS]);
token_rep[option_int("string_lg_commentary_token_stat_injs1", &lg_tokens)] =
misc_int_to_char(stats->values[1][LIVE_GAME_STAT_VALUE_INJURIES]);
}
/** Fill the tokens that contain general information. */
void
lg_commentary_set_basic_tokens(const LiveGameUnit *unit, const Fixture *fix)
{ {
gint i, tmp_int = 1;
gchar buf[SMALL]; 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));
for(i=0;i<lg_tokens.list->len;i++)
{
if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_team_home")) == 0)
g_ptr_array_add(strings, g_strdup(fix->teams[0]->name->str));
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_team_away")) == 0)
g_ptr_array_add(strings, g_strdup(fix->teams[1]->name->str));
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_team_in_poss")) == 0)
g_ptr_array_add(strings, g_strdup(fix->teams[unit->possession]->name->str));
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_team_not_in_poss")) == 0)
g_ptr_array_add(strings, g_strdup(fix->teams[!unit->possession]->name->str));
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_team_losing")) == 0)
{
if(unit->result[0] == unit->result[1])
g_ptr_array_add(strings, NULL);
else
g_ptr_array_add(strings, g_strdup(fix->teams[(unit->result[0] > unit->result[1])]->name->str));
}
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_team_winning")) == 0)
{
if(unit->result[0] == unit->result[1])
g_ptr_array_add(strings, NULL);
else
g_ptr_array_add(strings, g_strdup(fix->teams[(unit->result[0] < unit->result[1])]->name->str));
}
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_team")) == 0)
{
if(unit->event.team == -1)
g_ptr_array_add(strings, NULL);
else
g_ptr_array_add(strings, g_strdup(fix->teams[unit->event.team]->name->str));
}
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_player1")) == 0)
g_ptr_array_add(strings, lg_commentary_get_player_name(unit, fix, FALSE));
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_player2")) == 0)
g_ptr_array_add(strings, lg_commentary_get_player_name(unit, fix, TRUE));
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_attendance")) == 0)
{
misc_print_grouped_int(fix->attendance, buf, FALSE);
g_ptr_array_add(strings, g_strdup(buf));
}
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_time")) == 0)
{
sprintf(buf, "%d", unit->time);
g_ptr_array_add(strings, g_strdup(buf));
}
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_minute")) == 0)
{
sprintf(buf, "%d", live_game_unit_get_minute(unit));
g_ptr_array_add(strings, g_strdup(buf));
}
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_minute_remaining")) == 0)
{
if(unit->time == LIVE_GAME_UNIT_TIME_EXTRA_TIME)
tmp_int = 120 - live_game_unit_get_minute(unit);
else if(unit->time == LIVE_GAME_UNIT_TIME_SECOND_HALF)
tmp_int = 90 - live_game_unit_get_minute(unit);
else if(unit->time == LIVE_GAME_UNIT_TIME_FIRST_HALF)
tmp_int = 45 - live_game_unit_get_minute(unit);
if(unit->time == LIVE_GAME_UNIT_TIME_PENALTIES ||
tmp_int <= 0)
g_ptr_array_add(strings, NULL);
else
{
sprintf(buf, "%d", tmp_int);
g_ptr_array_add(strings, g_strdup(buf));
}
}
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_result")) == 0)
{
sprintf(buf, "%d : %d", unit->result[0], unit->result[1]); sprintf(buf, "%d : %d", unit->result[0], unit->result[1]);
g_ptr_array_add(strings, g_strdup(buf)); token_rep[option_int("string_lg_commentary_token_result", &lg_tokens)] =
} g_strdup(buf);
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_goals_home")) == 0) token_rep[option_int("string_lg_commentary_token_time", &lg_tokens)] =
{ misc_int_to_char(unit->time);
sprintf(buf, "%d", unit->result[0]); token_rep[option_int("string_lg_commentary_token_minute", &lg_tokens)] =
g_ptr_array_add(strings, g_strdup(buf)); misc_int_to_char(live_game_unit_get_minute(unit));
}
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str, if(unit->time == LIVE_GAME_UNIT_TIME_EXTRA_TIME)
lg_token("string_lg_commentary_token_goals_away")) == 0) tmp_int = 120 - current_min;
{ else if(unit->time == LIVE_GAME_UNIT_TIME_SECOND_HALF)
sprintf(buf, "%d", unit->result[1]); tmp_int = 90 - current_min;
g_ptr_array_add(strings, g_strdup(buf)); else if(unit->time == LIVE_GAME_UNIT_TIME_FIRST_HALF)
} tmp_int = 45 - current_min;
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str,
lg_token("string_lg_commentary_token_goal_diff")) == 0) if(unit->time != LIVE_GAME_UNIT_TIME_PENALTIES && tmp_int > 0)
{ token_rep[option_int("string_lg_commentary_token_minute_remaining", &lg_tokens)] =
sprintf(buf, "%d", ABS(unit->result[0] - unit->result[1])); misc_int_to_char(tmp_int);
g_ptr_array_add(strings, strdup(buf));
} if(query_fixture_is_draw(fix))
else if(strcmp(g_array_index(lg_tokens.list, Option, i).string_value->str, tmp_int = 120 - current_min;
lg_token("string_lg_commentary_token_extra")) == 0)
g_ptr_array_add(strings, lg_commentary_get_extra_data(unit, fix));
else else
{ tmp_int = 90 - current_min;
g_warning("lg_commentary_set_strings: no rule found for token %s.",
g_array_index(lg_tokens.list, Option, i).string_value->str); if(tmp_int > 0)
main_exit_program(EXIT_GENERAL, NULL); token_rep[option_int("string_lg_commentary_token_minute_total", &lg_tokens)] =
} misc_int_to_char(tmp_int);
}
token_rep[option_int("string_lg_commentary_token_goals0", &lg_tokens)] =
misc_int_to_char(unit->result[0]);
token_rep[option_int("string_lg_commentary_token_goals1", &lg_tokens)] =
misc_int_to_char(unit->result[1]);
token_rep[option_int("string_lg_commentary_token_goal_diff", &lg_tokens)] =
misc_int_to_char(ABS(unit->result[0] - unit->result[1]));
token_rep[option_int("string_lg_commentary_token_extra", &lg_tokens)] =
lg_commentary_get_extra_data(unit, fix);
token_rep[option_int("string_lg_commentary_token_possession", &lg_tokens)] =
misc_int_to_char(unit->possession);
token_rep[option_int("string_lg_commentary_token_no_possession", &lg_tokens)] =
misc_int_to_char(!unit->possession);
token_rep[option_int("string_lg_commentary_token_team_avskill0", &lg_tokens)] =
misc_int_to_char(avskill0);
token_rep[option_int("string_lg_commentary_token_team_avskill1", &lg_tokens)] =
misc_int_to_char(avskill1);
token_rep[option_int("string_lg_commentary_token_team_avskilldiff", &lg_tokens)] =
misc_int_to_char(ABS(avskill0 - avskill1));
} }
/** Return the name of a player involved in the unit (or NULL). /** Set the tokens containing team data. */
@param player Which player we look for. */ void
gchar* lg_commentary_set_team_tokens(const LiveGameUnit *unit, const Fixture *fix)
lg_commentary_get_player_name(const LiveGameUnit *unit, const Fixture *fix, gboolean player2)
{ {
gchar *return_value = NULL; if(unit->result[0] != unit->result[1])
if((player2 && unit->event.player2 == -1) ||
(!player2 && unit->event.player == -1))
return NULL;
if(unit->event.type == LIVE_GAME_EVENT_GENERAL)
return_value = (player2) ?
player_get_last_name(player_of_id_team(fix->teams[unit->possession],
unit->event.player2)->name->str) :
player_get_last_name(player_of_id_team(fix->teams[unit->possession],
unit->event.player)->name->str);
else if(unit->event.type == LIVE_GAME_EVENT_LOST_POSSESSION)
{ {
return_value = (player2) ? token_rep[option_int("string_lg_commentary_token_team_losing", &lg_tokens)] =
player_get_last_name(player_of_id_team(fix->teams[!unit->possession], g_strdup(fix->teams[(unit->result[0] > unit->result[1])]->name->str);
unit->event.player2)->name->str): token_rep[option_int("string_lg_commentary_token_team_winning", &lg_tokens)] =
player_get_last_name(player_of_id_team(fix->teams[unit->possession], g_strdup(fix->teams[(unit->result[0] < unit->result[1])]->name->str);
unit->event.player)->name->str);
} }
else if(unit->event.type == LIVE_GAME_EVENT_SCORING_CHANCE ||
if(unit->event.team != -1)
token_rep[option_int("string_lg_commentary_token_team", &lg_tokens)] =
g_strdup(fix->teams[unit->event.team]->name->str);
}
/** Set the player tokens. */
void
lg_commentary_set_player_tokens(const LiveGameUnit *unit, const Fixture *fix)
{
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_HEADER ||
unit->event.type == LIVE_GAME_EVENT_PENALTY || unit->event.type == LIVE_GAME_EVENT_PENALTY ||
unit->event.type == LIVE_GAME_EVENT_FREE_KICK) unit->event.type == LIVE_GAME_EVENT_FREE_KICK)
{ {
return_value = (player2) ? pl1 = player_of_id_team(fix->teams[unit->possession],
player_get_last_name(player_of_id_team(fix->teams[unit->possession], unit->event.player);
unit->event.player2)->name->str) :
player_get_last_name(player_of_id_team(fix->teams[unit->possession], if(unit->event.player2 != -1)
unit->event.player)->name->str); pl2 = player_of_id_team(fix->teams[unit->possession],
} unit->event.player2);
else if(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)
{
return_value = (player2) ?
player_get_last_name(player_of_id_team(fix->teams[!unit->possession],
unit->event.player2)->name->str) :
player_get_last_name(player_of_id_team(fix->teams[unit->possession],
unit->event.player)->name->str);
}
else if(unit->event.type == LIVE_GAME_EVENT_OWN_GOAL)
return_value =
player_get_last_name(player_of_id_team(fix->teams[!unit->possession],
unit->event.player)->name->str);
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)
{
return_value = (player2) ?
player_get_last_name(player_of_id_team(fix->teams[unit->event.team],
unit->event.player2)->name->str) :
player_get_last_name(player_of_id_team(fix->teams[!unit->event.team],
unit->event.player)->name->str);
} }
else if(unit->event.type == LIVE_GAME_EVENT_SEND_OFF || else if(unit->event.type == LIVE_GAME_EVENT_SEND_OFF ||
unit->event.type == LIVE_GAME_EVENT_INJURY || unit->event.type == LIVE_GAME_EVENT_INJURY ||
unit->event.type == LIVE_GAME_EVENT_TEMP_INJURY || unit->event.type == LIVE_GAME_EVENT_TEMP_INJURY ||
unit->event.type == LIVE_GAME_EVENT_SUBSTITUTION) unit->event.type == LIVE_GAME_EVENT_SUBSTITUTION)
return_value = (player2) ?
player_get_last_name(player_of_id_team(fix->teams[unit->event.team],
unit->event.player2)->name->str) :
player_get_last_name(player_of_id_team(fix->teams[unit->event.team],
unit->event.player)->name->str);
else
{ {
g_warning("lg_commentary_get_player_name: unknown event type %d\n", pl1 = player_of_id_team(fix->teams[unit->event.team],
unit->event.type); unit->event.player);
main_exit_program(EXIT_INT_NOT_FOUND, NULL); 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);
} }
return return_value; if(pl1 != NULL)
{
token_rep[option_int("string_lg_commentary_token_player0", &lg_tokens)] =
player_get_last_name(pl1->name->str);
token_rep[option_int("string_lg_commentary_token_player_goals0", &lg_tokens)] =
misc_int_to_char(player_games_goals_get(pl1, fix->clid, PLAYER_VALUE_GOALS));
token_rep[option_int("string_lg_commentary_token_player_goals_all0", &lg_tokens)] =
misc_int_to_char(player_all_games_goals(pl1, PLAYER_VALUE_GOALS));
token_rep[option_int("string_lg_commentary_token_player_yellows", &lg_tokens)] =
misc_int_to_char(player_card_get(pl1, fix->clid, PLAYER_VALUE_CARD_YELLOW));
}
if(pl2 != NULL)
{
token_rep[option_int("string_lg_commentary_token_player1", &lg_tokens)] =
player_get_last_name(pl2->name->str);
token_rep[option_int("string_lg_commentary_token_player_goals1", &lg_tokens)] =
misc_int_to_char(player_games_goals_get(pl2, fix->clid, PLAYER_VALUE_GOALS));
token_rep[option_int("string_lg_commentary_token_player_goals_all1", &lg_tokens)] =
misc_int_to_char(player_all_games_goals(pl2, PLAYER_VALUE_GOALS));
}
} }
/** Return some extra data depending on the unit type. */ /** Return some extra data depending on the unit type. */

View File

@ -3,43 +3,44 @@
#include "bygfoot.h" #include "bygfoot.h"
#include "fixture_struct.h" #include "fixture_struct.h"
#include "lg_commentary_struct.h"
#include "live_game_struct.h" #include "live_game_struct.h"
/** Tokens that get replaced in the commentary text. */ void
enum LGTokens lg_commentary_post_match(void);
{
LG_TOKEN_TEAM_HOME = 0,
LG_TOKEN_TEAM_AWAY,
LG_TOKEN_TEAM_IN_POSS,
LG_TOKEN_TEAM_NOT_IN_POSS,
LG_TOKEN_TEAM_LOSING,
LG_TOKEN_TEAM_WINNING,
LG_TOKEN_TEAM,
LG_TOKEN_ATTENDANCE,
LG_TOKEN_PLAYER1,
LG_TOKEN_PLAYER2,
LG_TOKEN_RESULT,
LG_TOKEN_MINUTE,
LG_TOKEN_GOALS_HOME,
LG_TOKEN_GOALS_AWAY,
LG_TOKEN_GOAL_DIFF,
LG_TOKEN_EXTRA,
LG_TOKEN_END
};
#define lg_token(name) option_string(name, &lg_tokens) void
lg_commentary_initialize(const Fixture *fix);
gchar*
lg_commentary_get_player_name(const LiveGameUnit *unit, const Fixture *fix, gint player);
gboolean gboolean
lg_commentary_replace_tokens(const gchar *string, const GPtrArray *strings, gchar *dest); lg_commentary_check_commentary(const LGCommentary *commentary, gchar *dest);
gboolean
lg_commentary_replace_tokens(gchar *commentary_text);
void void
lg_commentary_set_strings(GPtrArray *strings, const LiveGameUnit *unit, const Fixture *fix); lg_commentary_replace_expressions(gchar *commentary_text);
gboolean
lg_commentary_parse_condition(const gchar *condition);
void void
lg_commentary_generate(LiveGameUnit *unit, const Fixture *fix); lg_commentary_get_order(const GArray *commentaries, gint *order);
void
lg_commentary_set_basic_tokens(const LiveGameUnit *unit, const Fixture *fix);;
void
lg_commentary_set_player_tokens(const LiveGameUnit *unit, const Fixture *fix);
void
lg_commentary_set_team_tokens(const LiveGameUnit *unit, const Fixture *fix);
void
lg_commentary_set_stats_tokens(const LiveGameStats *stats);
void
lg_commentary_generate(const LiveGame *live_game, LiveGameUnit *unit);
gchar* gchar*
lg_commentary_get_extra_data(const LiveGameUnit *unit, const Fixture *fix); lg_commentary_get_extra_data(const LiveGameUnit *unit, const Fixture *fix);

View File

@ -0,0 +1,21 @@
#ifndef LG_COMMENTARY_STRUCT_H
#define LG_COMMENTARY_STRUCT_H
/** Structure describing a commentary
for the live game. */
typedef struct
{
/** The commentary text (possibly containing tokens). */
GString *text;
/** A condition (if not fulfilled, the commentary doesn't get
shown). */
GString *condition;
/** Priority of the commentary (compared to
the other ones for the same event).
The higher the priority the higher the
probability that the commentary gets picked. */
gint priority;
} LGCommentary;
#endif

View File

@ -7,6 +7,7 @@
#include "live_game.h" #include "live_game.h"
#include "main.h" #include "main.h"
#include "maths.h" #include "maths.h"
#include "misc.h"
#include "misc_callback_func.h" #include "misc_callback_func.h"
#include "option.h" #include "option.h"
#include "player.h" #include "player.h"
@ -39,6 +40,36 @@ void
live_game_calculate_fixture(Fixture *fix) live_game_calculate_fixture(Fixture *fix)
{ {
if(stat0 != STATUS_LIVE_GAME_PAUSE) if(stat0 != STATUS_LIVE_GAME_PAUSE)
live_game_initialize(fix);
else
stat0 = STATUS_SHOW_LIVE_GAME;
game_get_values(match->fix, match->team_values,
match->home_advantage);
if(debug > 80 && fixture_user_team_involved(match->fix) != -1)
printf("\n\nlive_game_calculate_fixture\n%04d %s %s %04d\n\n",
tm0->id, tm0->name->str, tm1->name->str, tm1->id);
do
{
live_game_create_unit();
live_game_evaluate_unit(&last_unit);
}
while(last_unit.event.type != LIVE_GAME_EVENT_END_MATCH &&
stat0 != STATUS_LIVE_GAME_PAUSE);
if(last_unit.event.type == LIVE_GAME_EVENT_END_MATCH)
{
if(fixture_user_team_involved(match->fix) != -1)
lg_commentary_post_match();
game_post_match(fix);
}
}
/** Initialize a few things at the beginning of a live game. */
void
live_game_initialize(Fixture *fix)
{ {
match = (fixture_user_team_involved(fix) != -1) ? match = (fixture_user_team_involved(fix) != -1) ?
&usr(fixture_user_team_involved(fix)).live_game : &live_game_temp; &usr(fixture_user_team_involved(fix)).live_game : &live_game_temp;
@ -60,30 +91,13 @@ live_game_calculate_fixture(Fixture *fix)
window.live = window_create(WINDOW_LIVE); window.live = window_create(WINDOW_LIVE);
else else
window_live_set_spinbuttons(); window_live_set_spinbuttons();
} }
game_initialize(fix); game_initialize(fix);
}
else
stat0 = STATUS_SHOW_LIVE_GAME;
game_get_values(match->fix, match->team_values, if(fixture_user_team_involved(match->fix) != -1)
match->home_advantage); lg_commentary_initialize(fix);
if(debug > 80 && fixture_user_team_involved(match->fix) != -1)
printf("\n\nlive_game_calculate_fixture\n%04d %s %s %04d\n\n",
tm0->id, tm0->name->str, tm1->name->str, tm1->id);
do
{
live_game_create_unit();
live_game_evaluate_unit(&last_unit);
}
while(last_unit.event.type != LIVE_GAME_EVENT_END_MATCH &&
stat0 != STATUS_LIVE_GAME_PAUSE);
if(last_unit.event.type == LIVE_GAME_EVENT_END_MATCH)
game_post_match(fix);
} }
/** Create a game unit for the live game. /** Create a game unit for the live game.
@ -216,8 +230,8 @@ live_game_create_start_unit(void)
new.event.player = new.event.player =
new.event.player2 = -1; new.event.player2 = -1;
new.event.commentary = NULL;
new.minute = 0; new.minute = 0;
new.event.commentary = NULL;
new.time = LIVE_GAME_UNIT_TIME_FIRST_HALF; new.time = LIVE_GAME_UNIT_TIME_FIRST_HALF;
new.possession = math_rndi(0, 1); new.possession = math_rndi(0, 1);
new.area = LIVE_GAME_UNIT_AREA_MIDFIELD; new.area = LIVE_GAME_UNIT_AREA_MIDFIELD;
@ -272,9 +286,7 @@ live_game_evaluate_unit(LiveGameUnit *unit)
type); type);
} }
/** Calculate a foul event. /** Calculate a foul event. */
@param general Whether to create a general event after
showing this one. @see live_game_event_general() */
void void
live_game_event_foul(void) live_game_event_foul(void)
{ {
@ -581,9 +593,9 @@ live_game_event_penalty(void)
if(last_unit.time != LIVE_GAME_UNIT_TIME_PENALTIES) if(last_unit.time != LIVE_GAME_UNIT_TIME_PENALTIES)
{ {
new = last_unit; new = last_unit;
new.event.commentary = NULL;
new.minute = -1; new.minute = -1;
new.event.type = LIVE_GAME_EVENT_PENALTY; new.event.type = LIVE_GAME_EVENT_PENALTY;
new.event.commentary = NULL;
g_array_append_val(unis, new); g_array_append_val(unis, new);
} }
@ -646,8 +658,8 @@ live_game_event_general(gboolean create_new)
{ {
new.minute = live_game_get_minute(); new.minute = live_game_get_minute();
new.time = last_unit.time; new.time = last_unit.time;
new.event.type = LIVE_GAME_EVENT_GENERAL;
new.event.commentary = NULL; new.event.commentary = NULL;
new.event.type = LIVE_GAME_EVENT_GENERAL;
new.result[0] = last_unit.result[0]; new.result[0] = last_unit.result[0];
new.result[1] = last_unit.result[1]; new.result[1] = last_unit.result[1];
new.event.team = -1; new.event.team = -1;
@ -874,13 +886,12 @@ live_game_event_substitution(gint team_number, gint sub_in, gint sub_out)
new.minute = -1; new.minute = -1;
new.time = live_game_get_time(&last_unit); new.time = live_game_get_time(&last_unit);
new.event.commentary = NULL;
new.event.type = LIVE_GAME_EVENT_SUBSTITUTION; new.event.type = LIVE_GAME_EVENT_SUBSTITUTION;
new.event.team = team_number; new.event.team = team_number;
new.event.player = sub_in; new.event.player = sub_in;
new.event.player2 = sub_out; new.event.player2 = sub_out;
new.event.commentary = NULL;
if(player_of_id_team(tm[team_number], sub_in)->cskill > 0) if(player_of_id_team(tm[team_number], sub_in)->cskill > 0)
{ {
@ -905,12 +916,12 @@ live_game_event_team_change(gint team_number, gint event_type)
new.minute = -1; new.minute = -1;
new.time = live_game_get_time(&last_unit); new.time = live_game_get_time(&last_unit);
new.event.commentary = NULL;
new.event.team = team_number; new.event.team = team_number;
new.event.player = new.event.player =
new.event.player2 = -1; new.event.player2 = -1;
new.event.type = event_type; new.event.type = event_type;
new.event.commentary = NULL;
g_array_append_val(unis, new); g_array_append_val(unis, new);
@ -933,7 +944,6 @@ live_game_event_duel(void)
new.minute = -1; new.minute = -1;
new.event.team = new.possession; new.event.team = new.possession;
new.event.commentary = NULL; new.event.commentary = NULL;
attacker = player_of_id_team(tm[new.possession], attacker = player_of_id_team(tm[new.possession],
@ -1307,7 +1317,7 @@ live_game_finish_unit(void)
match); match);
} }
lg_commentary_generate(unit, match->fix); lg_commentary_generate(match, unit);
unit->event.verbosity = live_game_event_get_verbosity(unit->event.type); unit->event.verbosity = live_game_event_get_verbosity(unit->event.type);
} }
@ -1514,4 +1524,3 @@ live_game_event_get_verbosity(gint event_type)
return return_value; return return_value;
} }

View File

@ -7,6 +7,12 @@
void void
live_game_calculate_fixture(Fixture *fix); live_game_calculate_fixture(Fixture *fix);
void
live_game_initialize(Fixture *fix);
void
live_game_post_match(void);
gboolean gboolean
query_live_game_event_is_break(gint minute, gint time); query_live_game_event_is_break(gint minute, gint time);

View File

@ -8,6 +8,7 @@
#include "file.h" #include "file.h"
#include "free.h" #include "free.h"
#include "language.h" #include "language.h"
#include "lg_commentary_struct.h"
#include "live_game.h" #include "live_game.h"
#include "main.h" #include "main.h"
#include "misc_callbacks.h" #include "misc_callbacks.h"
@ -65,7 +66,7 @@ main_init_variables(void)
timeout_id = -1; timeout_id = -1;
for(i=0;i<LIVE_GAME_EVENT_END;i++) for(i=0;i<LIVE_GAME_EVENT_END;i++)
lg_commentary[i] = g_ptr_array_new(); lg_commentary[i] = g_array_new(FALSE, FALSE, sizeof(LGCommentary));
file_load_conf_files(); file_load_conf_files();

View File

@ -121,10 +121,9 @@ misc_randomise_g_pointer_array(GPtrArray *array)
/** Print a thousands-grouped output of 'number' into 'buf', /** Print a thousands-grouped output of 'number' into 'buf',
like 2 234 345 instead of 2234345. like 2 234 345 instead of 2234345.
@param number The number to print. @param number The number to print.
@buf The buffer to hold the number. @buf The buffer to hold the number. */
@append Whether to overwrite the buffer or append. */
void void
misc_print_grouped_int(gint number, gchar *buf, gboolean append) misc_print_grouped_int(gint number, gchar *buf)
{ {
gint i; gint i;
gchar buf2[SMALL]; gchar buf2[SMALL];
@ -132,7 +131,6 @@ misc_print_grouped_int(gint number, gchar *buf, gboolean append)
gfloat copy = (gfloat)(abs(number)); gfloat copy = (gfloat)(abs(number));
gint number2 = abs(number); gint number2 = abs(number);
if(!append)
strcpy(buf, ""); strcpy(buf, "");
while(copy >= 1) while(copy >= 1)
@ -341,7 +339,7 @@ misc_parse_value(const gchar *s, gint *value)
/* parse numeric expression (supports + and -) */ /* parse numeric expression (supports + and -) */
const gchar* const gchar*
misc_parse_expression(const gchar *s, gboolean *result) misc_parse_expression(const gchar *s, gint *result)
{ {
gint value = 0; gint value = 0;
s = misc_parse_value(s, &value); s = misc_parse_value(s, &value);
@ -367,7 +365,7 @@ misc_parse_expression(const gchar *s, gboolean *result)
/* parse comparison (supports '<', '>' and '=') */ /* parse comparison (supports '<', '>' and '=') */
const gchar* const gchar*
misc_parse_comparison(const gchar *s, gboolean *result) misc_parse_comparison(const gchar *s, gint *result)
{ {
gint value = 0; gint value = 0;
s = misc_parse_expression(s, result); s = misc_parse_expression(s, result);
@ -413,7 +411,7 @@ misc_parse_comparison(const gchar *s, gboolean *result)
} }
const gchar* const gchar*
misc_parse_and(const gchar *s, gboolean *result) misc_parse_and(const gchar *s, gint *result)
{ {
gint value = 0; gint value = 0;
s = misc_parse_comparison(s, result); s = misc_parse_comparison(s, result);
@ -428,7 +426,7 @@ misc_parse_and(const gchar *s, gboolean *result)
} }
const gchar* const gchar*
misc_parse(const gchar *s, gboolean *result) misc_parse(const gchar *s, gint *result)
{ {
gint value = 0; gint value = 0;
s = misc_parse_and(s, result); s = misc_parse_and(s, result);
@ -440,4 +438,3 @@ misc_parse(const gchar *s, gboolean *result)
} }
return s; return s;
} }

View File

@ -3,6 +3,8 @@
#include "bygfoot.h" #include "bygfoot.h"
#define misc_int_to_char(number) g_strdup_printf("%d", number)
void void
misc_print_error(GError **error, gboolean abort_program); misc_print_error(GError **error, gboolean abort_program);
@ -19,7 +21,7 @@ GPtrArray*
misc_randomise_g_pointer_array(GPtrArray *array); misc_randomise_g_pointer_array(GPtrArray *array);
void void
misc_print_grouped_int(gint number, gchar *buf, gboolean append); misc_print_grouped_int(gint number, gchar *buf);
gboolean gboolean
query_integer_is_in_array(gint item, gint *array, gint min, gint max); query_integer_is_in_array(gint item, gint *array, gint min, gint max);
@ -58,15 +60,15 @@ const gchar*
misc_parse_value(const gchar *s, gint *value); misc_parse_value(const gchar *s, gint *value);
const gchar* const gchar*
misc_parse_expression(const gchar *s, gboolean *result); misc_parse_expression(const gchar *s, gint *result);
const gchar* const gchar*
misc_parse_comparison(const gchar *s, gboolean *result); misc_parse_comparison(const gchar *s, gint *result);
const gchar* const gchar*
misc_parse_and(const gchar *s, gboolean *result); misc_parse_and(const gchar *s, gint *result);
const gchar* const gchar*
misc_parse(const gchar *s, gboolean *result); misc_parse(const gchar *s, gint *result);
#endif #endif

View File

@ -724,7 +724,7 @@ treeview_create_game_stats(LiveGame *live_game)
} }
} }
misc_print_grouped_int(live_game->fix->attendance, buf[0], FALSE); misc_print_grouped_int(live_game->fix->attendance, buf[0]);
sprintf(buf[1], _("Attendance\n%s"), buf[0]); sprintf(buf[1], _("Attendance\n%s"), buf[0]);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, buf[1], 1, "", 2, "", -1); gtk_list_store_set(ls, &iter, 0, buf[1], 1, "", 2, "", -1);
@ -1236,7 +1236,7 @@ treeview_create_stadium_summary(GtkListStore *ls)
} }
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
misc_print_grouped_int(current_user.tm->stadium.capacity, buf, FALSE); misc_print_grouped_int(current_user.tm->stadium.capacity, buf);
gtk_list_store_set(ls, &iter, 0, _("Stadium capacity"), 1, buf, 2, "", -1); gtk_list_store_set(ls, &iter, 0, _("Stadium capacity"), 1, buf, 2, "", -1);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
@ -1292,7 +1292,7 @@ treeview_create_finances(const User* user)
for(i=0;i<MON_IN_TRANSFERS;i++) for(i=0;i<MON_IN_TRANSFERS;i++)
if(in[i] != 0) if(in[i] != 0)
{ {
misc_print_grouped_int(in[i], buf, FALSE); misc_print_grouped_int(in[i], buf);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, in_titles[i], 1, buf, 2, "", -1); gtk_list_store_set(ls, &iter, 0, in_titles[i], 1, buf, 2, "", -1);
balance += in[i]; balance += in[i];
@ -1301,7 +1301,7 @@ treeview_create_finances(const User* user)
for(i=0;i<MON_OUT_TRANSFERS;i++) for(i=0;i<MON_OUT_TRANSFERS;i++)
if(out[i] != 0) if(out[i] != 0)
{ {
misc_print_grouped_int(out[i], buf3, FALSE); misc_print_grouped_int(out[i], buf3);
sprintf(buf, "<span foreground='%s'>%s</span>", sprintf(buf, "<span foreground='%s'>%s</span>",
const_app("string_treeview_finances_expenses_fg"), buf3); const_app("string_treeview_finances_expenses_fg"), buf3);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
@ -1309,7 +1309,7 @@ treeview_create_finances(const User* user)
balance += out[i]; balance += out[i];
} }
misc_print_grouped_int(balance, buf, FALSE); misc_print_grouped_int(balance, buf);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
/* Finances balance. */ /* Finances balance. */
gtk_list_store_set(ls, &iter, 0, _("Balance"), 1, "", 2, "", -1); gtk_list_store_set(ls, &iter, 0, _("Balance"), 1, "", 2, "", -1);
@ -1325,8 +1325,8 @@ treeview_create_finances(const User* user)
if(in[MON_IN_TRANSFERS] != 0 || out[MON_OUT_TRANSFERS] != 0) if(in[MON_IN_TRANSFERS] != 0 || out[MON_OUT_TRANSFERS] != 0)
{ {
misc_print_grouped_int(in[MON_IN_TRANSFERS], buf, FALSE); misc_print_grouped_int(in[MON_IN_TRANSFERS], buf);
misc_print_grouped_int(out[MON_OUT_TRANSFERS], buf3, FALSE); misc_print_grouped_int(out[MON_OUT_TRANSFERS], buf3);
sprintf(buf2, "<span foreground='%s'>%s</span>", sprintf(buf2, "<span foreground='%s'>%s</span>",
const_app("string_treeview_finances_expenses_fg"), buf3); const_app("string_treeview_finances_expenses_fg"), buf3);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
@ -1336,7 +1336,7 @@ treeview_create_finances(const User* user)
if(out[MON_OUT_STADIUM_IMPROVEMENT] + out[MON_OUT_STADIUM_BILLS] != 0) if(out[MON_OUT_STADIUM_IMPROVEMENT] + out[MON_OUT_STADIUM_BILLS] != 0)
{ {
misc_print_grouped_int(out[MON_OUT_STADIUM_IMPROVEMENT] + out[MON_OUT_STADIUM_BILLS], misc_print_grouped_int(out[MON_OUT_STADIUM_IMPROVEMENT] + out[MON_OUT_STADIUM_BILLS],
buf, FALSE); buf);
sprintf(buf2, "<span foreground='%s'>%s</span>", sprintf(buf2, "<span foreground='%s'>%s</span>",
const_app("string_treeview_finances_expenses_fg"), buf); const_app("string_treeview_finances_expenses_fg"), buf);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
@ -1346,7 +1346,7 @@ treeview_create_finances(const User* user)
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, "", 1, "", 2, "", -1); gtk_list_store_set(ls, &iter, 0, "", 1, "", 2, "", -1);
misc_print_grouped_int(user->money, buf, FALSE); misc_print_grouped_int(user->money, buf);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
if(user->money >= 0) if(user->money >= 0)
strcpy(buf2, buf); strcpy(buf2, buf);
@ -1355,13 +1355,13 @@ treeview_create_finances(const User* user)
const_app("string_treeview_finances_expenses_fg"), buf); const_app("string_treeview_finances_expenses_fg"), buf);
gtk_list_store_set(ls, &iter, 0, _("Money"), 1, buf2, 2, "", -1); gtk_list_store_set(ls, &iter, 0, _("Money"), 1, buf2, 2, "", -1);
misc_print_grouped_int(finance_team_drawing_credit_loan(user->tm, FALSE), buf, FALSE); misc_print_grouped_int(finance_team_drawing_credit_loan(user->tm, FALSE), buf);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, _("Drawing credit"), 1, buf, 2, "", -1); gtk_list_store_set(ls, &iter, 0, _("Drawing credit"), 1, buf, 2, "", -1);
if(user->debt != 0) if(user->debt != 0)
{ {
misc_print_grouped_int(user->debt, buf, FALSE); misc_print_grouped_int(user->debt, buf);
sprintf(buf2, "<span foreground='%s'>%s</span>", sprintf(buf2, "<span foreground='%s'>%s</span>",
const_app("string_treeview_finances_expenses_fg"), buf); const_app("string_treeview_finances_expenses_fg"), buf);
sprintf(buf, _("Debt (repay in %d weeks)"), user->counters[COUNT_USER_LOAN]); sprintf(buf, _("Debt (repay in %d weeks)"), user->counters[COUNT_USER_LOAN]);
@ -1376,7 +1376,7 @@ treeview_create_finances(const User* user)
gtk_list_store_set(ls, &iter, 0, _("Sponsor"), 1, user->sponsor.name->str, gtk_list_store_set(ls, &iter, 0, _("Sponsor"), 1, user->sponsor.name->str,
2, "", -1); 2, "", -1);
misc_print_grouped_int(user->sponsor.benefit, buf, FALSE); misc_print_grouped_int(user->sponsor.benefit, buf);
/* Contract time and money a sponsor pays. */ /* Contract time and money a sponsor pays. */
sprintf(buf2, _("%.1f months / %s"), ((gfloat)user->sponsor.contract) / 4, buf); sprintf(buf2, _("%.1f months / %s"), ((gfloat)user->sponsor.contract) / 4, buf);
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);

View File

@ -933,10 +933,10 @@ treeview_helper_player_to_cell(GtkTreeViewColumn *col,
pl->etal[current_user.scout % 10]); pl->etal[current_user.scout % 10]);
break; break;
case PLAYER_LIST_ATTRIBUTE_VALUE: case PLAYER_LIST_ATTRIBUTE_VALUE:
misc_print_grouped_int(pl->value, buf, FALSE); misc_print_grouped_int(pl->value, buf);
break; break;
case PLAYER_LIST_ATTRIBUTE_WAGE: case PLAYER_LIST_ATTRIBUTE_WAGE:
misc_print_grouped_int(pl->wage, buf, FALSE); misc_print_grouped_int(pl->wage, buf);
break; break;
case PLAYER_LIST_ATTRIBUTE_CONTRACT: case PLAYER_LIST_ATTRIBUTE_CONTRACT:
treeview_helper_player_contract_to_cell(renderer, buf, pl->contract); treeview_helper_player_contract_to_cell(renderer, buf, pl->contract);

View File

@ -443,26 +443,26 @@ user_event_show_next(void)
game_gui_show_warning(buf); game_gui_show_warning(buf);
break; break;
case EVENT_TYPE_TRANSFER_OFFER_REJECTED_BETTER_OFFER: case EVENT_TYPE_TRANSFER_OFFER_REJECTED_BETTER_OFFER:
misc_print_grouped_int(event->value1, buf2, FALSE); misc_print_grouped_int(event->value1, buf2);
misc_print_grouped_int(event->value2, buf3, FALSE); misc_print_grouped_int(event->value2, buf3);
sprintf(buf, _("The owners of %s have rejected your offer (%s / %s) for %s. There was a better offer for the player than yours."), ((Team*)event->value_pointer)->name->str, buf2, buf3, event->value_string->str); sprintf(buf, _("The owners of %s have rejected your offer (%s / %s) for %s. There was a better offer for the player than yours."), ((Team*)event->value_pointer)->name->str, buf2, buf3, event->value_string->str);
game_gui_show_warning(buf); game_gui_show_warning(buf);
break; break;
case EVENT_TYPE_TRANSFER_OFFER_REJECTED_FEE_WAGE: case EVENT_TYPE_TRANSFER_OFFER_REJECTED_FEE_WAGE:
misc_print_grouped_int(event->value1, buf2, FALSE); misc_print_grouped_int(event->value1, buf2);
misc_print_grouped_int(event->value2, buf3, FALSE); misc_print_grouped_int(event->value2, buf3);
sprintf(buf, _("The owners of %s have rejected your offer (%s / %s) for %s. Neither the fee nor the wage you offered were acceptable, they say."), ((Team*)event->value_pointer)->name->str, buf2, buf3, event->value_string->str); sprintf(buf, _("The owners of %s have rejected your offer (%s / %s) for %s. Neither the fee nor the wage you offered were acceptable, they say."), ((Team*)event->value_pointer)->name->str, buf2, buf3, event->value_string->str);
game_gui_show_warning(buf); game_gui_show_warning(buf);
break; break;
case EVENT_TYPE_TRANSFER_OFFER_REJECTED_FEE: case EVENT_TYPE_TRANSFER_OFFER_REJECTED_FEE:
misc_print_grouped_int(event->value1, buf2, FALSE); misc_print_grouped_int(event->value1, buf2);
misc_print_grouped_int(event->value2, buf3, FALSE); misc_print_grouped_int(event->value2, buf3);
sprintf(buf, _("The owners of %s have rejected your offer (%s / %s) for %s. The team owners weren't satisfied with the fee you offered."), ((Team*)event->value_pointer)->name->str, buf2, buf3, event->value_string->str); sprintf(buf, _("The owners of %s have rejected your offer (%s / %s) for %s. The team owners weren't satisfied with the fee you offered."), ((Team*)event->value_pointer)->name->str, buf2, buf3, event->value_string->str);
game_gui_show_warning(buf); game_gui_show_warning(buf);
break; break;
case EVENT_TYPE_TRANSFER_OFFER_REJECTED_WAGE: case EVENT_TYPE_TRANSFER_OFFER_REJECTED_WAGE:
misc_print_grouped_int(event->value1, buf2, FALSE); misc_print_grouped_int(event->value1, buf2);
misc_print_grouped_int(event->value2, buf3, FALSE); misc_print_grouped_int(event->value2, buf3);
/* A player from a team has rejected a transfer offer. */ /* A player from a team has rejected a transfer offer. */
sprintf(buf, _("%s of %s has rejected your offer (%s / %s). He wasn't satisfied with the wage you offered."), sprintf(buf, _("%s of %s has rejected your offer (%s / %s). He wasn't satisfied with the wage you offered."),
event->value_string->str, event->value_string->str,

View File

@ -35,7 +35,7 @@ OptionList settings;
OptionList lg_tokens; OptionList lg_tokens;
/** The array containing the live game commentary strings. */ /** The array containing the live game commentary strings. */
GPtrArray *lg_commentary[LIVE_GAME_EVENT_END]; GArray *lg_commentary[LIVE_GAME_EVENT_END];
/** The array containing players to be transfered. /** The array containing players to be transfered.
@see TransferPlayer */ @see TransferPlayer */

View File

@ -10,6 +10,9 @@
#define TAG_EVENT_NAME "name" #define TAG_EVENT_NAME "name"
#define TAG_EVENT_COMMENTARY "commentary" #define TAG_EVENT_COMMENTARY "commentary"
#define ATT_NAME_CONDITION "cond"
#define ATT_NAME_PRIORITY "pri"
#define EVENT_NAME_GENERAL "general" #define EVENT_NAME_GENERAL "general"
#define EVENT_NAME_START_MATCH "start_match" #define EVENT_NAME_START_MATCH "start_match"
#define EVENT_NAME_HALF_TIME "half_time" #define EVENT_NAME_HALF_TIME "half_time"
@ -52,8 +55,8 @@ enum XmlLgCommentaryStates
STATE_END STATE_END
}; };
gint state, commentary_idx; gint state, commentary_idx, priority;
gchar condition[SMALL]; GString *condition;
/** /**
* The function called by the parser when an opening tag is read. * The function called by the parser when an opening tag is read.
@ -69,6 +72,8 @@ xml_lg_commentary_read_start_element (GMarkupParseContext *context,
gpointer user_data, gpointer user_data,
GError **error) GError **error)
{ {
gint atidx = 0;
if(strcmp(element_name, TAG_EVENT) == 0) if(strcmp(element_name, TAG_EVENT) == 0)
state = STATE_EVENT; state = STATE_EVENT;
else if(strcmp(element_name, TAG_EVENT_NAME) == 0) else if(strcmp(element_name, TAG_EVENT_NAME) == 0)
@ -76,10 +81,20 @@ xml_lg_commentary_read_start_element (GMarkupParseContext *context,
else if(strcmp(element_name, TAG_EVENT_COMMENTARY) == 0) else if(strcmp(element_name, TAG_EVENT_COMMENTARY) == 0)
{ {
state = STATE_EVENT_COMMENTARY; state = STATE_EVENT_COMMENTARY;
if(attribute_names[0] != NULL)
sprintf(condition, "#%s", attribute_values[0]); condition = NULL;
else priority = 1;
strcpy(condition, "");
while(attribute_names[atidx] != NULL)
{
if(strcmp(attribute_names[atidx], ATT_NAME_CONDITION) == 0)
condition = g_string_new(attribute_values[atidx]);
else if(strcmp(attribute_names[atidx], ATT_NAME_PRIORITY) == 0)
priority = (gint)g_ascii_strtod(attribute_values[atidx], NULL);
atidx++;
}
} }
else if(strcmp(element_name, TAG_LG_COMMENTARY) != 0) else if(strcmp(element_name, TAG_LG_COMMENTARY) != 0)
g_warning("xml_lg_commentary_read_start_element: unknown tag: %s; I'm in state %d\n", g_warning("xml_lg_commentary_read_start_element: unknown tag: %s; I'm in state %d\n",
@ -121,7 +136,7 @@ xml_lg_commentary_read_text (GMarkupParseContext *context,
GError **error) GError **error)
{ {
gchar buf[text_len + 1]; gchar buf[text_len + 1];
GString *commentary = NULL; LGCommentary commentary;
strncpy(buf, text, text_len); strncpy(buf, text, text_len);
buf[text_len] = '\0'; buf[text_len] = '\0';
@ -195,9 +210,10 @@ xml_lg_commentary_read_text (GMarkupParseContext *context,
} }
else if(state == STATE_EVENT_COMMENTARY) else if(state == STATE_EVENT_COMMENTARY)
{ {
commentary = g_string_new(""); commentary.text = g_string_new(buf);
g_string_printf(commentary, "%s%s", condition, buf); commentary.condition = condition;
g_ptr_array_add(lg_commentary[commentary_idx], commentary); commentary.priority = MAX(1, priority);
g_array_append_val(lg_commentary[commentary_idx], commentary);
} }
} }
@ -219,7 +235,6 @@ xml_lg_commentary_read(const gchar *commentary_file)
gchar *file_contents; gchar *file_contents;
gint length; gint length;
GError *error = NULL; GError *error = NULL;
gint i;
context = context =
g_markup_parse_context_new(&parser, 0, NULL, NULL); g_markup_parse_context_new(&parser, 0, NULL, NULL);
@ -237,11 +252,7 @@ xml_lg_commentary_read(const gchar *commentary_file)
return; return;
} }
for(i=0;i<LIVE_GAME_EVENT_END;i++) free_lg_commentary(TRUE);
{
free_g_string_array(&lg_commentary[i]);
lg_commentary[i] = g_ptr_array_new();
}
if(g_markup_parse_context_parse(context, file_contents, length, &error)) if(g_markup_parse_context_parse(context, file_contents, length, &error))
{ {

View File

@ -725,9 +725,9 @@ int_name_max_product 2000
# list instead of the specified one # list instead of the specified one
float_name_random_list_prob 2000 float_name_random_list_prob 2000
string_language_names English Deutsch Nederlands string_language_names English Deutsch Français Nederlands
string_language_codes C de_DE nl_NL string_language_codes C de_DE fr_FR nl_NL
string_language_symbols flag_england.png flag_germany.png flag_nl.png string_language_symbols flag_england.png flag_germany.png flag_france.png flag_nl.png
# lower and upper limits of which percentage # lower and upper limits of which percentage
# of the player wages a sponsor pays; the actual # of the player wages a sponsor pays; the actual