2005-10-20 17:45:00 +02:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2004-12-23 13:58:39 +01:00
|
|
|
/*
|
|
|
|
* Initial main.c file generated by Glade. Edit as required.
|
|
|
|
* Glade will not overwrite this file.
|
|
|
|
*/
|
|
|
|
|
2004-12-30 17:48:19 +01:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
#include "free.h"
|
2005-06-14 17:27:44 +02:00
|
|
|
#include "language.h"
|
2005-07-01 22:51:46 +02:00
|
|
|
#include "lg_commentary_struct.h"
|
2005-04-04 12:36:04 +02:00
|
|
|
#include "live_game.h"
|
2005-09-29 15:41:16 +02:00
|
|
|
#include "load_save.h"
|
2004-12-23 13:58:39 +01:00
|
|
|
#include "main.h"
|
2005-09-29 15:41:16 +02:00
|
|
|
#include "misc.h"
|
2005-06-14 17:27:44 +02:00
|
|
|
#include "misc_callbacks.h"
|
2005-06-01 20:19:02 +02:00
|
|
|
#include "name_struct.h"
|
2005-06-14 17:27:44 +02:00
|
|
|
#include "option.h"
|
2005-05-01 12:16:14 +02:00
|
|
|
#include "stat_struct.h"
|
2005-06-05 12:39:29 +02:00
|
|
|
#include "transfer_struct.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "variables.h"
|
|
|
|
#include "window.h"
|
|
|
|
|
2005-10-03 20:08:26 +02:00
|
|
|
/** Whether the last save gets loaded at startup
|
|
|
|
(cl switch -l). */
|
|
|
|
gboolean load_last_save;
|
2005-09-29 15:41:16 +02:00
|
|
|
|
|
|
|
/** Parse the command line arguments given by the user. */
|
|
|
|
void
|
|
|
|
main_parse_cl_arguments(gint *argc, gchar ***argv)
|
|
|
|
{
|
|
|
|
gchar *support_dir = NULL, *lang = NULL;
|
|
|
|
gint deb_level = -1;
|
|
|
|
GError *error = NULL;
|
|
|
|
GOptionContext *context = NULL;
|
|
|
|
GOptionEntry entries[] =
|
|
|
|
{{ "support-dir", 's', 0, G_OPTION_ARG_STRING, &support_dir,
|
2005-10-01 10:12:06 +02:00
|
|
|
_("Specify additional support directory (takes priority over default ones)"), "DIR" },
|
2005-09-29 15:41:16 +02:00
|
|
|
|
2005-10-01 10:12:06 +02:00
|
|
|
{ "debug-level", 'd', 0, G_OPTION_ARG_INT, &deb_level, _("Debug level to use"), "N" },
|
2005-09-29 15:41:16 +02:00
|
|
|
|
2005-10-01 10:12:06 +02:00
|
|
|
{ "lang", 'L', 0, G_OPTION_ARG_STRING, &lang, _("Language to use (a code like 'de')"), "CODE" },
|
|
|
|
|
|
|
|
{ "last-save", 'l', 0, G_OPTION_ARG_NONE, &load_last_save, _("Load last savegame"), NULL },
|
2005-09-29 15:41:16 +02:00
|
|
|
|
|
|
|
{NULL}};
|
|
|
|
|
|
|
|
if(argc == NULL || argv == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-10-01 10:12:06 +02:00
|
|
|
context = g_option_context_new(_("- a simple and addictive GTK2 football manager"));
|
2005-09-29 15:41:16 +02:00
|
|
|
g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
|
|
|
|
g_option_context_add_group(context, gtk_get_option_group (TRUE));
|
|
|
|
g_option_context_parse(context, argc, argv, &error);
|
|
|
|
g_option_context_free(context);
|
|
|
|
|
|
|
|
misc_print_error(&error, TRUE);
|
|
|
|
|
|
|
|
if(support_dir != NULL)
|
|
|
|
{
|
|
|
|
gchar *fullpath = g_path_get_dirname(support_dir);
|
|
|
|
file_add_support_directory_recursive(fullpath);
|
|
|
|
g_free(fullpath);
|
|
|
|
g_free(support_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(deb_level != -1)
|
2005-10-01 10:12:06 +02:00
|
|
|
option_set_int("int_debug", &constants, deb_level);
|
2005-09-29 15:41:16 +02:00
|
|
|
|
|
|
|
if(lang != NULL)
|
|
|
|
language_set(language_get_code_index(lang) + 1);
|
|
|
|
}
|
|
|
|
|
2004-12-23 13:58:39 +01:00
|
|
|
/**
|
|
|
|
Initialize some global variables. Most of them get nullified.
|
|
|
|
*/
|
|
|
|
void
|
2004-12-30 17:48:19 +01:00
|
|
|
main_init_variables(void)
|
2004-12-23 13:58:39 +01:00
|
|
|
{
|
2005-04-13 15:01:59 +02:00
|
|
|
gint i;
|
|
|
|
|
2005-09-29 15:41:16 +02:00
|
|
|
ligs = g_array_new(FALSE, FALSE, sizeof(League));
|
|
|
|
cps = g_array_new(FALSE, FALSE, sizeof(Cup));;
|
|
|
|
acps = g_ptr_array_new();
|
2005-10-09 11:35:44 +02:00
|
|
|
country.name = NULL;
|
|
|
|
country.symbol = NULL;
|
|
|
|
country.sid = NULL;;
|
2005-06-23 23:53:57 +02:00
|
|
|
|
2005-04-16 09:46:04 +02:00
|
|
|
season = week = week_round = 1;
|
|
|
|
|
2005-04-13 15:01:59 +02:00
|
|
|
for(i=0;i<COUNT_END;i++)
|
|
|
|
counters[i] = 0;
|
|
|
|
|
2005-04-14 21:07:25 +02:00
|
|
|
counters[COUNT_LEAGUE_ID] = ID_LEAGUE_START;
|
|
|
|
counters[COUNT_CUP_ID] = ID_CUP_START;
|
|
|
|
|
2005-03-27 19:59:57 +02:00
|
|
|
window.main = window.startup =
|
|
|
|
window.live = window.warning = window.progress = window.digits =
|
|
|
|
window.stadium = window.job_offer = window.yesno =
|
2005-06-14 22:04:37 +02:00
|
|
|
window.options = window.font_sel =
|
|
|
|
window.file_chooser = window.contract =
|
2005-08-20 21:39:36 +02:00
|
|
|
window.menu_player = window.user_management =
|
|
|
|
window.mmatches = NULL;
|
2004-12-23 13:58:39 +01:00
|
|
|
|
2005-04-04 12:36:04 +02:00
|
|
|
live_game_reset(&live_game_temp, NULL, FALSE);
|
2005-03-03 13:46:48 +01:00
|
|
|
|
|
|
|
users = g_array_new(FALSE, FALSE, sizeof(User));
|
2005-03-19 21:04:08 +01:00
|
|
|
transfer_list = g_array_new(FALSE, FALSE, sizeof(Transfer));
|
2005-05-01 12:16:14 +02:00
|
|
|
season_stats = g_array_new(FALSE, FALSE, sizeof(SeasonStat));
|
2005-06-01 20:19:02 +02:00
|
|
|
name_lists = g_array_new(FALSE, FALSE, sizeof(NameList));
|
2005-01-09 21:21:22 +01:00
|
|
|
|
2005-10-09 11:35:44 +02:00
|
|
|
save_file = NULL;
|
2005-04-04 12:36:04 +02:00
|
|
|
|
2005-06-26 13:42:01 +02:00
|
|
|
constants_app.list = settings.list =
|
2005-06-28 04:08:56 +02:00
|
|
|
constants.list = options.list = lg_tokens.list = NULL;
|
2005-06-26 13:42:01 +02:00
|
|
|
constants_app.datalist = settings.datalist =
|
2005-06-28 04:08:56 +02:00
|
|
|
constants.datalist = options.datalist = lg_tokens.datalist = NULL;
|
2005-03-24 08:42:24 +01:00
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
popups_active = 0;
|
2005-07-08 11:26:00 +02:00
|
|
|
selected_row = -1;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-03-17 21:26:01 +01:00
|
|
|
timeout_id = -1;
|
|
|
|
|
2005-06-26 13:42:01 +02:00
|
|
|
for(i=0;i<LIVE_GAME_EVENT_END;i++)
|
2005-07-01 22:51:46 +02:00
|
|
|
lg_commentary[i] = g_array_new(FALSE, FALSE, sizeof(LGCommentary));
|
2005-06-26 13:42:01 +02:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
file_load_conf_files();
|
2005-06-14 17:27:44 +02:00
|
|
|
|
|
|
|
language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);
|
2005-06-23 23:53:57 +02:00
|
|
|
|
|
|
|
/** Some of these (or all) are disabled (set to 1) in supernational
|
|
|
|
country defs. */
|
2005-06-26 13:42:01 +02:00
|
|
|
option_add(&settings, "int_opt_disable_finances", 0, NULL);
|
|
|
|
option_add(&settings, "int_opt_disable_transfers", 0, NULL);
|
|
|
|
option_add(&settings, "int_opt_disable_stadium", 0, NULL);
|
|
|
|
option_add(&settings, "int_opt_disable_contracts", 0, NULL);
|
|
|
|
option_add(&settings, "int_opt_disable_boost_on", 0, NULL);
|
2005-09-19 23:13:36 +02:00
|
|
|
option_add(&settings, "int_opt_disable_ya", 0, NULL);
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Process the command line arguments and do some things
|
|
|
|
that have to be done at the beginning (like initializing the
|
|
|
|
random number generator).
|
|
|
|
@param argc Number of command line arguments.
|
|
|
|
@param argv Command line arguments array.
|
|
|
|
*/
|
|
|
|
void
|
2005-09-29 15:41:16 +02:00
|
|
|
main_init(gint *argc, gchar ***argv)
|
2004-12-23 13:58:39 +01:00
|
|
|
{
|
|
|
|
gchar buf[SMALL];
|
|
|
|
gchar *pwd = g_get_current_dir();
|
|
|
|
|
2005-07-17 13:55:33 +02:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
os_is_unix = FALSE;
|
|
|
|
#else
|
|
|
|
os_is_unix = TRUE;
|
|
|
|
#endif
|
|
|
|
|
2005-04-04 12:36:04 +02:00
|
|
|
support_directories = NULL;
|
2004-12-23 13:58:39 +01:00
|
|
|
|
2005-07-17 13:55:33 +02:00
|
|
|
#ifdef G_OS_UNIX
|
2005-05-18 18:00:49 +02:00
|
|
|
file_add_support_directory_recursive(PACKAGE_DATA_DIR "/" PACKAGE "/support_files");
|
2005-07-17 13:55:33 +02:00
|
|
|
sprintf(buf, "%s%s%s", g_get_home_dir(), G_DIR_SEPARATOR_S, HOMEDIRNAME);
|
2005-01-10 16:24:15 +01:00
|
|
|
file_add_support_directory_recursive(buf);
|
2005-07-19 17:55:34 +02:00
|
|
|
#endif
|
2005-04-04 12:36:04 +02:00
|
|
|
|
2005-07-17 13:55:33 +02:00
|
|
|
sprintf(buf, "%s%ssupport_files", pwd, G_DIR_SEPARATOR_S);
|
2004-12-30 17:48:19 +01:00
|
|
|
file_add_support_directory_recursive(buf);
|
2005-10-01 10:12:06 +02:00
|
|
|
sprintf(buf, "%s%ssaves", pwd, G_DIR_SEPARATOR_S);
|
|
|
|
file_add_support_directory_recursive(buf);
|
|
|
|
g_free(pwd);
|
2005-04-04 12:36:04 +02:00
|
|
|
|
2005-07-19 17:55:34 +02:00
|
|
|
/* initialize the random nr generator */
|
|
|
|
rand_generator = g_rand_new();
|
|
|
|
|
2004-12-30 17:48:19 +01:00
|
|
|
main_init_variables();
|
2005-07-17 13:55:33 +02:00
|
|
|
|
2005-10-01 10:12:06 +02:00
|
|
|
if(os_is_unix)
|
|
|
|
file_check_home_dir();
|
2005-10-03 20:08:26 +02:00
|
|
|
|
|
|
|
load_last_save = FALSE;
|
2005-09-29 15:41:16 +02:00
|
|
|
main_parse_cl_arguments(argc, argv);
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the GTK stuff and the gettext stuff.
|
|
|
|
Start the game.
|
|
|
|
@param argc Number of command line arguments.
|
|
|
|
@param argv Command line arguments array.
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
main (gint argc, gchar *argv[])
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain (GETTEXT_PACKAGE);
|
|
|
|
#endif
|
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
gtk_set_locale ();
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
2005-09-29 15:41:16 +02:00
|
|
|
main_init(&argc, &argv);
|
|
|
|
|
2005-10-03 20:08:26 +02:00
|
|
|
if((load_last_save && !load_game_from_command_line("last_save")) ||
|
|
|
|
(!load_last_save && (argc == 1 ||
|
|
|
|
(argc > 1 && !load_game_from_command_line(argv[1])))))
|
2005-09-29 15:41:16 +02:00
|
|
|
{
|
|
|
|
window_show_startup();
|
|
|
|
stat0 = STATUS_TEAM_SELECTION;
|
|
|
|
}
|
2005-04-07 18:44:33 +02:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
gtk_main ();
|
2004-12-23 13:58:39 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
main_exit_program(EXIT_OK, NULL);
|
2004-12-30 17:48:19 +01:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
return 0;
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
2004-12-30 17:48:19 +01:00
|
|
|
|
2005-01-09 21:21:22 +01:00
|
|
|
/** Exit the program with the given exit code and message. Try to
|
2004-12-30 17:48:19 +01:00
|
|
|
destroy all widgets and free all memory first.
|
|
|
|
@param exit_code The number we return to the shell.
|
2005-01-09 21:21:22 +01:00
|
|
|
@param exit_message The message we print.
|
2004-12-30 17:48:19 +01:00
|
|
|
@return The exit code of the program. */
|
|
|
|
void
|
2005-01-09 21:21:22 +01:00
|
|
|
main_exit_program(gint exit_code, gchar *exit_message)
|
2004-12-30 17:48:19 +01:00
|
|
|
{
|
|
|
|
if(gtk_main_level() > 0)
|
|
|
|
gtk_main_quit();
|
|
|
|
|
|
|
|
free_memory();
|
2005-01-09 21:21:22 +01:00
|
|
|
|
|
|
|
if(exit_message != NULL)
|
|
|
|
g_warning(exit_message);
|
|
|
|
|
2004-12-30 17:48:19 +01:00
|
|
|
exit(exit_code);
|
|
|
|
}
|