"Easy commentary testing added."

This commit is contained in:
gyboth 2005-10-25 15:26:53 +00:00
parent 790a866019
commit 5f44084c90
9 changed files with 259 additions and 125 deletions

View File

@ -1,5 +1,8 @@
11/16/2005: v1.9.3
- updated German country definition (thanks to Sebastian Vöcking)
- added strategies for CPU teams
- added option to randomise teams in cups in the startup window
(relevant for the World Cup definition, mainly)
10/16/2005: v1.9.2

File diff suppressed because one or more lines are too long

View File

@ -138,16 +138,16 @@ file_my_system(const gchar *command)
gboolean
file_my_fopen(const gchar *filename, gchar *bits, FILE **fil, gboolean abort_program)
{
gchar *support_file = file_find_support_file(filename, FALSE);
gchar *support_file = NULL;
*fil = fopen(filename, bits);
if(*fil != NULL)
{
g_free(support_file);
return TRUE;
}
support_file = file_find_support_file(filename, FALSE);
*fil = fopen(support_file, bits);
if(*fil != NULL)
{
g_free(support_file);

View File

@ -45,71 +45,106 @@ GPtrArray *token_rep[2];
gboolean repetition;
/** Generate commentary for the live game event in the unit.
@param unit The unit we comment.
@param fix The fixture being calculated. */
@param live_game The live game being calculated.
@param unit The live game unit we generate the commentary for.
@param event_type The event type we generate the commentary for (needed
when commentary is being tested). */
void
lg_commentary_generate(const LiveGame *live_game, LiveGameUnit *unit)
lg_commentary_generate(const LiveGame *live_game, LiveGameUnit *unit,
const gchar *event_name, gint ev_type)
{
gint i, event_type = -1;
gint commentary_idx = -1;
gchar buf[SMALL];
GArray **commentaries = NULL;
gint i;
GArray *commentaries = NULL;
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 ||
unit->event.type == LIVE_GAME_EVENT_STYLE_CHANGE_DEFEND ||
unit->event.type == LIVE_GAME_EVENT_STYLE_CHANGE_BALANCED ||
unit->event.type == LIVE_GAME_EVENT_STYLE_CHANGE_ATTACK ||
unit->event.type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_ATTACK)
commentaries = &lg_commentary[LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND];
else if(unit->event.type == LIVE_GAME_EVENT_BOOST_CHANGE_ANTI ||
unit->event.type == LIVE_GAME_EVENT_BOOST_CHANGE_OFF ||
unit->event.type == LIVE_GAME_EVENT_BOOST_CHANGE_ON)
commentaries = &lg_commentary[LIVE_GAME_EVENT_BOOST_CHANGE_ANTI];
if(unit != NULL)
event_type = unit->event.type;
else
commentaries = &lg_commentary[unit->event.type];
event_type = (event_name == NULL) ? ev_type :
xml_lg_commentary_event_name_to_int(event_name);
gint order[(*commentaries)->len];
lg_commentary_get_order(*commentaries, order);
if(event_type == -1)
return;
if(live_game != NULL)
{
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(event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND ||
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_DEFEND ||
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_BALANCED ||
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ATTACK ||
event_type == LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_ATTACK)
commentaries = lg_commentary[LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND];
else if(event_type == LIVE_GAME_EVENT_BOOST_CHANGE_ANTI ||
event_type == LIVE_GAME_EVENT_BOOST_CHANGE_OFF ||
event_type == LIVE_GAME_EVENT_BOOST_CHANGE_ON)
commentaries = lg_commentary[LIVE_GAME_EVENT_BOOST_CHANGE_ANTI];
else
commentaries = lg_commentary[event_type];
commentary_idx = lg_commentary_select(commentaries, buf);
if(commentary_idx == -1)
g_warning("lg_commentary_generate: didn't find fitting commentary for unit type %d \n",
unit->event.type);
if(live_game != NULL)
{
unit->event.commentary = g_strdup(buf);
unit->event.commentary_id = (commentary_idx == -1) ?
-1 : g_array_index(commentaries, LGCommentary, commentary_idx).id;
for(i=0;i<tokens.list->len;i++)
if(i != option_int("string_token_team_home", &tokens) &&
i != option_int("string_token_team_away", &tokens) &&
i != option_int("string_token_attendance", &tokens) &&
i != option_int("string_token_cup_round_name", &tokens) &&
i != option_int("string_token_league_cup_name", &tokens) &&
i != option_int("string_token_yellow_limit", &tokens) &&
i != option_int("string_token_team_layer0", &tokens) &&
i != option_int("string_token_team_layer1", &tokens))
misc_token_remove(token_rep, i);
}
else
printf("%s: \"%s\"\n", event_name, buf);
}
/** Select a commentary from the array depending on the tokens
available and write the text into the buffer. */
gint
lg_commentary_select(const GArray *commentaries, gchar *buf)
{
gint i, order[commentaries->len];
lg_commentary_get_order(commentaries, order);
repetition = FALSE;
for(i=0;i<(*commentaries)->len;i++)
if(lg_commentary_check_commentary(&g_array_index(*commentaries, LGCommentary, order[i]), buf))
for(i=0;i<commentaries->len;i++)
if(lg_commentary_check_commentary(&g_array_index(commentaries, LGCommentary, order[i]), buf))
break;
if(i == (*commentaries)->len)
if(i == commentaries->len)
{
repetition = TRUE;
for(i=0;i<(*commentaries)->len;i++)
if(lg_commentary_check_commentary(&g_array_index(*commentaries, LGCommentary, order[i]), buf))
for(i=0;i<commentaries->len;i++)
if(lg_commentary_check_commentary(&g_array_index(commentaries, LGCommentary, order[i]), buf))
break;
}
if(i == (*commentaries)->len)
if(i == commentaries->len)
{
g_warning("lg_commentary_generate: didn't find fitting commentary for unit type %d \n",
unit->event.type);
strcpy(buf, "FIXME!");
return -1;
}
unit->event.commentary = g_strdup(buf);
unit->event.commentary_id = (i == (*commentaries)->len) ?
-1 : g_array_index(*commentaries, LGCommentary, order[i]).id;
for(i=0;i<tokens.list->len;i++)
if(i != option_int("string_token_team_home", &tokens) &&
i != option_int("string_token_team_away", &tokens) &&
i != option_int("string_token_attendance", &tokens) &&
i != option_int("string_token_cup_round_name", &tokens) &&
i != option_int("string_token_league_cup_name", &tokens) &&
i != option_int("string_token_yellow_limit", &tokens) &&
i != option_int("string_token_team_layer0", &tokens) &&
i != option_int("string_token_team_layer1", &tokens))
misc_token_remove(token_rep, i);
return order[i];
}
/** Check whether the commentary conditions are fulfilled and whether
@ -540,7 +575,7 @@ lg_commentary_initialize(const Fixture *fix)
/** Free the memory occupied by the tokens array and the permanent tokens. */
void
lg_commentary_post_match(void)
lg_commentary_free_tokens(void)
{
gint i;
@ -603,3 +638,52 @@ lg_commentary_load_commentary_file(const gchar *commentary_file, gboolean abort)
lg_commentary_load_commentary_file("lg_commentary_en.xml", TRUE);
}
}
/** Load a file with tokens for commentary testing purposes. */
void
lg_commentary_test_load_token_file(const gchar *token_file)
{
gchar token_name[SMALL], token_value[SMALL];
FILE *fil = NULL;
file_my_fopen(token_file, "r", &fil, TRUE);
token_rep[0] = g_ptr_array_new();
token_rep[1] = g_ptr_array_new();
while(file_get_next_opt_line(fil, token_name, token_value))
{
g_ptr_array_add(token_rep[0], (gpointer)g_strdup(token_name));
g_ptr_array_add(token_rep[1], (gpointer)g_strdup(token_value));
}
}
/** Test a live game commentary file.
@param commentary_file the commentary file to test.
@param token_file the file containing the token values to use.
@param event_name the event to test (or 'all' to test all events).
@param number_of_passes how many commentaries to generate. */
void
lg_commentary_test(const gchar *commentary_file, const gchar* token_file,
const gchar *event_name, gint number_of_passes)
{
gint i, j;
LiveGame dummy;
lg_commentary_load_commentary_file(commentary_file, TRUE);
lg_commentary_test_load_token_file(token_file);
dummy.units = g_array_new(FALSE, FALSE, sizeof(gint));
statp = (gpointer)&dummy;
if(event_name == NULL)
for(i=0;i<LIVE_GAME_EVENT_END;i++)
for(j=0;j<number_of_passes;j++)
lg_commentary_generate(NULL, NULL, NULL, i);
else
for(i=0;i<number_of_passes;i++)
lg_commentary_generate(NULL, NULL, event_name, -1);
g_array_free(dummy.units, TRUE);
}

View File

@ -30,7 +30,7 @@
#include "live_game_struct.h"
void
lg_commentary_post_match(void);
lg_commentary_free_tokens(void);
void
lg_commentary_initialize(const Fixture *fix);
@ -57,7 +57,8 @@ void
lg_commentary_set_stats_tokens(const LiveGameStats *stats);
void
lg_commentary_generate(const LiveGame *live_game, LiveGameUnit *unit);
lg_commentary_generate(const LiveGame *live_game, LiveGameUnit *unit,
const gchar *event_name, gint ev_type);
gchar*
lg_commentary_get_extra_data(const LiveGameUnit *unit, const Fixture *fix);
@ -68,4 +69,14 @@ lg_commentary_load_commentary_file_from_option(void);
void
lg_commentary_load_commentary_file(const gchar *commentary_file, gboolean abort);
void
lg_commentary_test_load_token_file(const gchar *token_file);
void
lg_commentary_test(const gchar *commentary_file, const gchar* token_file,
const gchar *event_name, gint number_of_passes);
gint
lg_commentary_select(const GArray *commentaries, gchar *buf);
#endif

View File

@ -91,7 +91,7 @@ live_game_calculate_fixture(Fixture *fix)
if(last_unit.event.type == LIVE_GAME_EVENT_END_MATCH)
{
if(fixture_user_team_involved(match->fix) != -1 || stat5 < -1000)
lg_commentary_post_match();
lg_commentary_free_tokens();
game_post_match(fix);
}
else if(stat0 == STATUS_LIVE_GAME_CHANGE)
@ -1424,7 +1424,7 @@ live_game_finish_unit(void)
match);
}
lg_commentary_generate(match, unit);
lg_commentary_generate(match, unit, NULL, -1);
if(-stat5 - 1000 == unit->event.type)
{

View File

@ -32,7 +32,7 @@
#include "file.h"
#include "free.h"
#include "language.h"
#include "lg_commentary_struct.h"
#include "lg_commentary.h"
#include "live_game.h"
#include "load_save.h"
#include "main.h"
@ -55,8 +55,11 @@ gboolean load_last_save;
void
main_parse_cl_arguments(gint *argc, gchar ***argv)
{
gchar *support_dir = NULL, *lang = NULL;
gint deb_level = -1;
gboolean testcom = FALSE;
gchar *support_dir = NULL, *lang = NULL,
*testcom_file = NULL, *token_file = NULL,
*event_name = NULL;
gint deb_level = -1, number_of_passes = 1;
GError *error = NULL;
GOptionContext *context = NULL;
GOptionEntry entries[] =
@ -69,6 +72,20 @@ main_parse_cl_arguments(gint *argc, gchar ***argv)
{ "last-save", 'l', 0, G_OPTION_ARG_NONE, &load_last_save, _("Load last savegame"), NULL },
{ "testcom", 't', 0, G_OPTION_ARG_NONE, &testcom, _("Test an XML commmentary file"), NULL },
{ "commentary-file", 'c', 0, G_OPTION_ARG_STRING, &testcom_file,
_("Commentary file name (may be in a support dir)"), "FILE" },
{ "token-file", 'T', 0, G_OPTION_ARG_STRING, &token_file,
_("File containing live game tokens"), "FILE" },
{ "event-name", 'e', 0, G_OPTION_ARG_STRING, &event_name,
_("Commentary event to test; leave out to test all commentaries"), "EVENTNAME" },
{ "num-passes", 'n', 0, G_OPTION_ARG_INT, &number_of_passes,
_("How many commentaries to generate per event"), "N" },
{NULL}};
if(argc == NULL || argv == NULL)
@ -82,6 +99,12 @@ main_parse_cl_arguments(gint *argc, gchar ***argv)
misc_print_error(&error, TRUE);
if(testcom)
{
lg_commentary_test(testcom_file, token_file, event_name, number_of_passes);
main_exit_program(EXIT_OK, NULL);
}
if(support_dir != NULL)
{
gchar *fullpath = g_path_get_dirname(support_dir);

View File

@ -81,6 +81,81 @@ enum XmlLgCommentaryStates
gint state, commentary_idx, priority;
gchar *condition;
/** Return the appropriate enum integer going with the event string. */
gint
xml_lg_commentary_event_name_to_int(const gchar *event_string)
{
gint return_value = -1;
if(strcmp(event_string, EVENT_NAME_GENERAL) == 0)
return_value = LIVE_GAME_EVENT_GENERAL;
else if(strcmp(event_string, EVENT_NAME_START_MATCH) == 0)
return_value = LIVE_GAME_EVENT_START_MATCH;
else if(strcmp(event_string, EVENT_NAME_HALF_TIME) == 0)
return_value = LIVE_GAME_EVENT_HALF_TIME;
else if(strcmp(event_string, EVENT_NAME_EXTRA_TIME) == 0)
return_value = LIVE_GAME_EVENT_EXTRA_TIME;
else if(strcmp(event_string, EVENT_NAME_END_MATCH) == 0)
return_value = LIVE_GAME_EVENT_END_MATCH;
else if(strcmp(event_string, EVENT_NAME_LOST_POSSESSION) == 0)
return_value = LIVE_GAME_EVENT_LOST_POSSESSION;
else if(strcmp(event_string, EVENT_NAME_SCORING_CHANCE) == 0)
return_value = LIVE_GAME_EVENT_SCORING_CHANCE;
else if(strcmp(event_string, EVENT_NAME_HEADER) == 0)
return_value = LIVE_GAME_EVENT_HEADER;
else if(strcmp(event_string, EVENT_NAME_PENALTY) == 0)
return_value = LIVE_GAME_EVENT_PENALTY;
else if(strcmp(event_string, EVENT_NAME_FREE_KICK) == 0)
return_value = LIVE_GAME_EVENT_FREE_KICK;
else if(strcmp(event_string, EVENT_NAME_GOAL) == 0)
return_value = LIVE_GAME_EVENT_GOAL;
else if(strcmp(event_string, EVENT_NAME_OWN_GOAL) == 0)
return_value = LIVE_GAME_EVENT_OWN_GOAL;
else if(strcmp(event_string, EVENT_NAME_POST) == 0)
return_value = LIVE_GAME_EVENT_POST;
else if(strcmp(event_string, EVENT_NAME_MISS) == 0)
return_value = LIVE_GAME_EVENT_MISS;
else if(strcmp(event_string, EVENT_NAME_SAVE) == 0)
return_value = LIVE_GAME_EVENT_SAVE;
else if(strcmp(event_string, EVENT_NAME_CROSS_BAR) == 0)
return_value = LIVE_GAME_EVENT_CROSS_BAR;
else if(strcmp(event_string, EVENT_NAME_FOUL) == 0)
return_value = LIVE_GAME_EVENT_FOUL;
else if(strcmp(event_string, EVENT_NAME_FOUL_YELLOW) == 0)
return_value = LIVE_GAME_EVENT_FOUL_YELLOW;
else if(strcmp(event_string, EVENT_NAME_FOUL_RED) == 0)
return_value = LIVE_GAME_EVENT_FOUL_RED;
else if(strcmp(event_string, EVENT_NAME_FOUL_RED_INJURY) == 0)
return_value = LIVE_GAME_EVENT_FOUL_RED_INJURY;
else if(strcmp(event_string, EVENT_NAME_SEND_OFF) == 0)
return_value = LIVE_GAME_EVENT_SEND_OFF;
else if(strcmp(event_string, EVENT_NAME_INJURY) == 0)
return_value = LIVE_GAME_EVENT_INJURY;
else if(strcmp(event_string, EVENT_NAME_TEMP_INJURY) == 0)
return_value = LIVE_GAME_EVENT_TEMP_INJURY;
else if(strcmp(event_string, EVENT_NAME_PENALTIES) == 0)
return_value = LIVE_GAME_EVENT_PENALTIES;
else if(strcmp(event_string, EVENT_NAME_STADIUM_BREAKDOWN) == 0)
return_value = LIVE_GAME_EVENT_STADIUM_BREAKDOWN;
else if(strcmp(event_string, EVENT_NAME_STADIUM_RIOTS) == 0)
return_value = LIVE_GAME_EVENT_STADIUM_RIOTS;
else if(strcmp(event_string, EVENT_NAME_STADIUM_FIRE) == 0)
return_value = LIVE_GAME_EVENT_STADIUM_FIRE;
else if(strcmp(event_string, EVENT_NAME_SUBSTITUTION) == 0)
return_value = LIVE_GAME_EVENT_SUBSTITUTION;
else if(strcmp(event_string, EVENT_NAME_STRUCTURE_CHANGE) == 0)
return_value = LIVE_GAME_EVENT_STRUCTURE_CHANGE;
else if(strcmp(event_string, EVENT_NAME_STYLE_CHANGE) == 0)
return_value = LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND;
else if(strcmp(event_string, EVENT_NAME_BOOST_CHANGE) == 0)
return_value = LIVE_GAME_EVENT_BOOST_CHANGE_ANTI;
else
g_warning("xml_lg_commentary_event_name_to_int: unknown event name %s \n",
event_string);
return return_value;
}
/**
* The function called by the parser when an opening tag is read.
* The state variable is changed in this function and
@ -168,73 +243,8 @@ xml_lg_commentary_read_text (GMarkupParseContext *context,
buf[text_len] = '\0';
if(state == STATE_EVENT_NAME)
{
if(strcmp(buf, EVENT_NAME_GENERAL) == 0)
commentary_idx = LIVE_GAME_EVENT_GENERAL;
else if(strcmp(buf, EVENT_NAME_START_MATCH) == 0)
commentary_idx = LIVE_GAME_EVENT_START_MATCH;
else if(strcmp(buf, EVENT_NAME_HALF_TIME) == 0)
commentary_idx = LIVE_GAME_EVENT_HALF_TIME;
else if(strcmp(buf, EVENT_NAME_EXTRA_TIME) == 0)
commentary_idx = LIVE_GAME_EVENT_EXTRA_TIME;
else if(strcmp(buf, EVENT_NAME_END_MATCH) == 0)
commentary_idx = LIVE_GAME_EVENT_END_MATCH;
else if(strcmp(buf, EVENT_NAME_LOST_POSSESSION) == 0)
commentary_idx = LIVE_GAME_EVENT_LOST_POSSESSION;
else if(strcmp(buf, EVENT_NAME_SCORING_CHANCE) == 0)
commentary_idx = LIVE_GAME_EVENT_SCORING_CHANCE;
else if(strcmp(buf, EVENT_NAME_HEADER) == 0)
commentary_idx = LIVE_GAME_EVENT_HEADER;
else if(strcmp(buf, EVENT_NAME_PENALTY) == 0)
commentary_idx = LIVE_GAME_EVENT_PENALTY;
else if(strcmp(buf, EVENT_NAME_FREE_KICK) == 0)
commentary_idx = LIVE_GAME_EVENT_FREE_KICK;
else if(strcmp(buf, EVENT_NAME_GOAL) == 0)
commentary_idx = LIVE_GAME_EVENT_GOAL;
else if(strcmp(buf, EVENT_NAME_OWN_GOAL) == 0)
commentary_idx = LIVE_GAME_EVENT_OWN_GOAL;
else if(strcmp(buf, EVENT_NAME_POST) == 0)
commentary_idx = LIVE_GAME_EVENT_POST;
else if(strcmp(buf, EVENT_NAME_MISS) == 0)
commentary_idx = LIVE_GAME_EVENT_MISS;
else if(strcmp(buf, EVENT_NAME_SAVE) == 0)
commentary_idx = LIVE_GAME_EVENT_SAVE;
else if(strcmp(buf, EVENT_NAME_CROSS_BAR) == 0)
commentary_idx = LIVE_GAME_EVENT_CROSS_BAR;
else if(strcmp(buf, EVENT_NAME_FOUL) == 0)
commentary_idx = LIVE_GAME_EVENT_FOUL;
else if(strcmp(buf, EVENT_NAME_FOUL_YELLOW) == 0)
commentary_idx = LIVE_GAME_EVENT_FOUL_YELLOW;
else if(strcmp(buf, EVENT_NAME_FOUL_RED) == 0)
commentary_idx = LIVE_GAME_EVENT_FOUL_RED;
else if(strcmp(buf, EVENT_NAME_FOUL_RED_INJURY) == 0)
commentary_idx = LIVE_GAME_EVENT_FOUL_RED_INJURY;
else if(strcmp(buf, EVENT_NAME_SEND_OFF) == 0)
commentary_idx = LIVE_GAME_EVENT_SEND_OFF;
else if(strcmp(buf, EVENT_NAME_INJURY) == 0)
commentary_idx = LIVE_GAME_EVENT_INJURY;
else if(strcmp(buf, EVENT_NAME_TEMP_INJURY) == 0)
commentary_idx = LIVE_GAME_EVENT_TEMP_INJURY;
else if(strcmp(buf, EVENT_NAME_PENALTIES) == 0)
commentary_idx = LIVE_GAME_EVENT_PENALTIES;
else if(strcmp(buf, EVENT_NAME_STADIUM_BREAKDOWN) == 0)
commentary_idx = LIVE_GAME_EVENT_STADIUM_BREAKDOWN;
else if(strcmp(buf, EVENT_NAME_STADIUM_RIOTS) == 0)
commentary_idx = LIVE_GAME_EVENT_STADIUM_RIOTS;
else if(strcmp(buf, EVENT_NAME_STADIUM_FIRE) == 0)
commentary_idx = LIVE_GAME_EVENT_STADIUM_FIRE;
else if(strcmp(buf, EVENT_NAME_SUBSTITUTION) == 0)
commentary_idx = LIVE_GAME_EVENT_SUBSTITUTION;
else if(strcmp(buf, EVENT_NAME_STRUCTURE_CHANGE) == 0)
commentary_idx = LIVE_GAME_EVENT_STRUCTURE_CHANGE;
else if(strcmp(buf, EVENT_NAME_STYLE_CHANGE) == 0)
commentary_idx = LIVE_GAME_EVENT_STYLE_CHANGE_ALL_OUT_DEFEND;
else if(strcmp(buf, EVENT_NAME_BOOST_CHANGE) == 0)
commentary_idx = LIVE_GAME_EVENT_BOOST_CHANGE_ANTI;
else
g_warning("xml_lg_commentary_read_text: unknown event name %s \n", buf);
}
else if(state == STATE_EVENT_COMMENTARY)
commentary_idx = xml_lg_commentary_event_name_to_int(buf);
else if(state == STATE_EVENT_COMMENTARY && commentary_idx != -1)
{
misc_string_assign(&commentary.text, buf);
commentary.condition = condition;

View File

@ -50,5 +50,8 @@ xml_lg_commentary_read_start_element (GMarkupParseContext *context,
gpointer user_data,
GError **error);
gint
xml_lg_commentary_event_name_to_int(const gchar *event_string);
#endif