Loadsave system slightly changed.

This commit is contained in:
gyboth 2005-10-21 13:45:58 +00:00
parent fa0b06f39d
commit 54ac5de383
12 changed files with 293 additions and 108 deletions

File diff suppressed because one or more lines are too long

View File

@ -25,7 +25,7 @@ bygfoot_SOURCES = \
lg_commentary.c cup.h file.h fixture.h free.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 \
live_game.c callbacks.h fixture.h free.h game_gui.h game.h league.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 misc.h option.h support.h user.h variables.h window.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 misc.h option.h support.h user.h variables.h window.h xml.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_leagues_cups.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 lg_commentary_struct.h live_game.h load_save.h main.h misc_callbacks.h misc.h name_struct.h option.h stat_struct.h transfer_struct.h variables.h window.h \
maths.c maths.h misc.h variables.h \
misc.c main.h maths.h misc.h \
@ -56,6 +56,7 @@ bygfoot_SOURCES = \
xml_loadsave_cup.c cup.h file.h misc.h table.h team.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_teams.h \
xml_loadsave_fixtures.c file.h fixture.h misc.h team.h xml.h xml_loadsave_fixtures.h \
xml_loadsave_league.c file.h league.h misc.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_league.h xml_loadsave_league_stat.h xml_loadsave_table.h xml_loadsave_teams.h \
xml_loadsave_leagues_cups.c cup.h file.h free.h league_struct.h misc.h xml.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_leagues_cups.h \
xml_loadsave_league_stat.c file.h misc.h stat.h team.h xml.h xml_loadsave_league_stat.h \
xml_loadsave_live_game.c cup.h file.h fixture.h league.h live_game.h misc.h option.h variables.h xml.h xml_loadsave_live_game.h \
xml_loadsave_misc.c cup.h file.h misc.h variables.h xml.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_misc.h \

View File

@ -119,7 +119,10 @@ file_my_system(const gchar *command)
g_warning("file_my_system: system returned -1 when executing '%s'.", command);
if(!os_is_unix)
{
g_warning("Press RETURN to try to continue.");
getchar();
}
return FALSE;
}

View File

@ -1116,16 +1116,24 @@ game_get_default_penalty_shooter(const Team *tm)
return return_value;
}
/** Check whether the CPU team's strategy (boost, style, subs)
has to be adjusted. */
void
game_check_cpu_strategy(LiveGame *lg)
{
const LiveGameUnit *unit =
&g_array_index(lg->units, LiveGameUnit, lg->units->len - 1);
gint minutes_remaining =
live_game_get_minutes_remaining(unit);
/* gint */
/* game_get_cpu_goals_to_win(const Fixture *fix) */
/* { */
/* } */
if(unit->time == LIVE_GAME_UNIT_TIME_PENALTIES)
return;
}
/* /\** Check whether the CPU team's strategy (boost, style, subs) */
/* has to be adjusted. *\/ */
/* void */
/* game_check_cpu_strategy(LiveGame *lg) */
/* { */
/* const LiveGameUnit *unit = */
/* &g_array_index(lg->units, LiveGameUnit, lg->units->len - 1); */
/* gint minutes_remaining = -1, goals_to_win = -1; */
/* if(unit->time == LIVE_GAME_UNIT_TIME_PENALTIES) */
/* return; */
/* minutes_remaining = live_game_get_minutes_remaining(unit); */
/* goals_to_win = game_get_cpu_goals_to_win(lg->fix); */
/* } */

View File

@ -117,4 +117,7 @@ game_reset_players(gint idx);
gint
game_get_default_penalty_shooter(const Team *tm);
/* void */
/* game_check_cpu_strategy(LiveGame *lg); */
#endif

View File

@ -700,6 +700,10 @@ live_game_event_general(gboolean create_new)
if((debug > 100 && fixture_user_team_involved(match->fix) != -1) ||
debug > 130)
printf("\t\tlive_game_event_general\n");
/* if(team_is_user(tm0) == -1 || team_is_user(tm1) == -1) */
/* game_check_cpu_strategy(match); */
if(create_new)
{
new.minute = live_game_get_minute();

View File

@ -36,18 +36,18 @@
#include "xml_loadsave_misc.h"
#include "xml_loadsave_cup.h"
#include "xml_loadsave_league.h"
#include "xml_loadsave_leagues_cups.h"
#include "xml_loadsave_season_stats.h"
#include "xml_loadsave_transfers.h"
#include "xml_loadsave_users.h"
#include "xml.h"
#define PROGRESS_MAX 8
#define PROGRESS_MAX 7
/** Save the game to the specified file. */
void
load_save_save_game(const gchar *filename)
{
gint i;
gchar buf[SMALL];
gchar *prefix = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
g_strndup(filename, strlen(filename) - strlen(const_str("string_fs_save_suffix"))) :
@ -73,26 +73,14 @@ load_save_save_game(const gchar *filename)
file_save_opt_file(buf, &settings);
if(debug > 60)
printf("load_save_save leagues \n");
printf("load_save_save leagues/cups \n");
gui_show_progress(
((PROGRESS_MAX * gtk_progress_bar_get_fraction(
GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar")))) + 1) / PROGRESS_MAX,
_("Saving leagues..."));
_("Saving leagues and cups..."));
for(i=0;i<ligs->len;i++)
xml_loadsave_league_write(prefix, &lig(i));
if(debug > 60)
printf("load_save_save cups \n");
gui_show_progress(
((PROGRESS_MAX * gtk_progress_bar_get_fraction(
GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar")))) + 1) / PROGRESS_MAX,
_("Saving cups..."));
for(i=0;i<cps->len;i++)
xml_loadsave_cup_write(prefix, &cp(i));
xml_loadsave_leagues_cups_write(prefix);
if(debug > 60)
printf("load_save_save users \n");
@ -220,19 +208,9 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
gui_show_progress(
((PROGRESS_MAX * gtk_progress_bar_get_fraction(
GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar")))) + 1) / PROGRESS_MAX,
_("Loading leagues..."));
_("Loading leagues and cups..."));
xml_load_leagues(dirname, prefix);
if(debug > 60)
printf("load_save_load cups \n");
gui_show_progress(
((PROGRESS_MAX * gtk_progress_bar_get_fraction(
GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar")))) + 1) / PROGRESS_MAX,
_("Loading cups..."));
xml_load_cups(dirname, prefix);
xml_loadsave_leagues_cups_read(dirname, prefix);
if(debug > 60)
printf("load_save_load users \n");

View File

@ -257,6 +257,12 @@ main_exit_program(gint exit_code, gchar *exit_message)
if(exit_message != NULL)
g_warning(exit_message);
if(!os_is_unix)
{
g_warning("Press RETURN. Program will exit.");
getchar();
}
exit(exit_code);
}

View File

@ -65,31 +65,7 @@ xml_load_users(const gchar *dirname, const gchar *basename)
}
void
xml_load_leagues(const gchar *dirname, const gchar *basename)
{
gint i;
gchar buf[SMALL];
GPtrArray *dir_contents = NULL;
sprintf(buf, "%s___league_", basename);
dir_contents = file_dir_get_contents(dirname, buf, ".xml");
free_leagues_array(&ligs, TRUE);
for(i=0;i<dir_contents->len;i++)
if(!g_str_has_suffix((gchar*)g_ptr_array_index(dir_contents, i), "_table.xml") &&
!g_str_has_suffix((gchar*)g_ptr_array_index(dir_contents, i), "_fixtures.xml") &&
!g_str_has_suffix((gchar*)g_ptr_array_index(dir_contents, i), "_teams.xml") &&
!g_str_has_suffix((gchar*)g_ptr_array_index(dir_contents, i), "_stat.xml") &&
!g_strrstr((gchar*)g_ptr_array_index(dir_contents, i), "_promcup"))
xml_load_league(dirname, (gchar*)g_ptr_array_index(dir_contents, i),
dir_contents);
free_gchar_array(&dir_contents);
}
void
xml_load_league(const gchar *dirname, const gchar *basename, const GPtrArray *dir_contents)
xml_load_league(const gchar *dirname, const gchar *basename)
{
gchar buf[SMALL];
League new = league_new(FALSE);
@ -125,37 +101,7 @@ xml_load_league(const gchar *dirname, const gchar *basename, const GPtrArray *di
}
void
xml_load_cups(const gchar *dirname, const gchar *basename)
{
gint i;
gchar buf[SMALL];
GPtrArray *dir_contents = NULL;
Cup new_cup;
sprintf(buf, "%s___cup_", basename);
dir_contents = file_dir_get_contents(dirname, buf, ".xml");
free_cups_array(&cps, TRUE);
for(i=0;i<dir_contents->len;i++)
{
if(!g_strrstr((gchar*)g_ptr_array_index(dir_contents, i), "_table") &&
!g_str_has_suffix((gchar*)g_ptr_array_index(dir_contents, i), "_fixtures.xml") &&
!g_str_has_suffix((gchar*)g_ptr_array_index(dir_contents, i), "_teams.xml"))
{
new_cup = cup_new(FALSE);
g_array_append_val(cps, new_cup);
xml_load_cup(&g_array_index(cps, Cup, cps->len - 1), dirname,
(gchar*)g_ptr_array_index(dir_contents, i),
dir_contents);
}
}
free_gchar_array(&dir_contents);
}
void
xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename, const GPtrArray *dir_contents)
xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename)
{
gchar buf[SMALL];
gchar *prefix = g_strndup(basename, strlen(basename) - 4);

View File

@ -67,6 +67,7 @@ enum XmlTags
#define TAG_END_PLAYERS 9900
#define TAG_START_LEAGUE_STAT 10000
#define TAG_START_SEASON_STATS 11000
#define TAG_START_LEAGUES_CUPS 12000
#define TAG_START_TRANSFERS 20000
#define xml_write_g_string(fil, gstring, tag, indent) xml_write_string(fil, (gstring)->str, tag, indent)
@ -84,16 +85,10 @@ void
xml_load_users(const gchar *dirname, const gchar *basename);
void
xml_load_leagues(const gchar *dirname, const gchar *basename);
xml_load_league(const gchar *dirname, const gchar *basename);
void
xml_load_league(const gchar *dirname, const gchar *basename, const GPtrArray *dir_contents);
void
xml_load_cups(const gchar *dirname, const gchar *basename);
void
xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename, const GPtrArray *dir_contents);
xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename);
void
xml_load_transfers(const gchar *dirname, const gchar *basename);

View File

@ -0,0 +1,183 @@
/*
Bygfoot Football Manager -- a small and simple GTK2-based
football management game.
http://bygfoot.sourceforge.net
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "cup.h"
#include "file.h"
#include "free.h"
#include "league_struct.h"
#include "misc.h"
#include "xml.h"
#include "xml_loadsave_cup.h"
#include "xml_loadsave_league.h"
#include "xml_loadsave_leagues_cups.h"
enum
{
TAG_LEAGUES_CUPS = TAG_START_LEAGUES_CUPS,
TAG_LEAGUE_FILE,
TAG_CUP_FILE,
TAG_END
};
gint state;
const gchar *dir;
void
xml_loadsave_leagues_cups_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error)
{
gint i;
gint tag = xml_get_tag_from_name(element_name);
gboolean valid_tag = FALSE;
for(i=TAG_LEAGUES_CUPS;i<TAG_END;i++)
if(tag == i)
{
state = i;
valid_tag = TRUE;
}
if(!valid_tag)
g_warning("xml_loadsave_leagues_cups_start_element: unknown tag: %s; I'm in state %d\n",
element_name, state);
}
void
xml_loadsave_leagues_cups_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error)
{
gint tag = xml_get_tag_from_name(element_name);
if(tag == TAG_LEAGUE_FILE ||
tag == TAG_CUP_FILE)
state = TAG_LEAGUES_CUPS;
else if(tag != TAG_LEAGUES_CUPS)
g_warning("xml_loadsave_leagues_cups_end_element: unknown tag: %s; I'm in state %d\n",
element_name, state);
}
void
xml_loadsave_leagues_cups_text (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error)
{
gchar buf[SMALL];
Cup new_cup;
strncpy(buf, text, text_len);
buf[text_len] = '\0';
if(state == TAG_LEAGUE_FILE)
xml_load_league(dir, buf);
else if(state == TAG_CUP_FILE)
{
new_cup = cup_new(FALSE);
g_array_append_val(cps, new_cup);
xml_load_cup(&g_array_index(cps, Cup, cps->len - 1), dir, buf);
}
}
/** Load the leagues and cups given in the leagues_cups.xml file. */
void
xml_loadsave_leagues_cups_read(const gchar *dirname, const gchar *prefix)
{
gchar file[SMALL];
GMarkupParser parser = {xml_loadsave_leagues_cups_start_element,
xml_loadsave_leagues_cups_end_element,
xml_loadsave_leagues_cups_text, NULL, NULL};
GMarkupParseContext *context;
gchar *file_contents;
guint length;
GError *error = NULL;
sprintf(file, "%s/%s___leagues_cups.xml", dirname, prefix);
context =
g_markup_parse_context_new(&parser, 0, NULL, NULL);
if(!g_file_get_contents(file, &file_contents, &length, &error))
{
g_warning("xml_loadsave_misc_read: error reading file %s\n", file);
misc_print_error(&error, TRUE);
}
free_leagues_array(&ligs, TRUE);
free_cups_array(&cps, TRUE);
dir = dirname;
if(g_markup_parse_context_parse(context, file_contents, length, &error))
{
g_markup_parse_context_end_parse(context, NULL);
g_markup_parse_context_free(context);
g_free(file_contents);
}
else
{
g_warning("xml_loadsave_misc_read: error parsing file %s\n", file);
misc_print_error(&error, TRUE);
}
}
/** Write the leagues into xml files with the given prefix. */
void
xml_loadsave_leagues_cups_write(const gchar *prefix)
{
gint i;
gchar buf[SMALL],
*basename = g_path_get_basename(prefix);
FILE *fil = NULL;
sprintf(buf, "%s___leagues_cups.xml", prefix);
file_my_fopen(buf, "w", &fil, TRUE);
fprintf(fil, "%s<_%d>\n", I0, TAG_LEAGUES_CUPS);
for(i=0;i<ligs->len;i++)
{
xml_loadsave_league_write(prefix, &lig(i));
sprintf(buf, "%s___league_%d.xml", basename, lig(i).id);
xml_write_string(fil, buf, TAG_LEAGUE_FILE, I1);
}
for(i=0;i<cps->len;i++)
{
xml_loadsave_cup_write(prefix, &cp(i));
sprintf(buf, "%s___cup_%d.xml", basename, cp(i).id);
xml_write_string(fil, buf, TAG_CUP_FILE, I1);
}
fprintf(fil, "%s</_%d>\n", I0, TAG_LEAGUES_CUPS);
fclose(fil);
g_free(basename);
}

View File

@ -0,0 +1,58 @@
/*
Bygfoot Football Manager -- a small and simple GTK2-based
football management game.
http://bygfoot.sourceforge.net
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef XML_LOADSAVE_LEAGUES_CUPS_H
#define XML_LOADSAVE_LEAGUES_CUPS_H
#include "bygfoot.h"
#include "variables.h"
void
xml_loadsave_leagues_cups_write(const gchar *prefix);
void
xml_loadsave_leagues_cups_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error);
void
xml_loadsave_leagues_cups_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error);
void
xml_loadsave_leagues_cups_text (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error);
void
xml_loadsave_leagues_cups_read(const gchar *dirname, const gchar *prefix);
#endif