/* main.c 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. */ /* * Initial main.c file generated by Glade. Edit as required. * Glade will not overwrite this file. */ #include #include #include "bet_struct.h" #include "debug.h" #include "file.h" #include "free.h" #include "job_struct.h" #include "language.h" #include "lg_commentary.h" #include "live_game.h" #include "load_save.h" #include "main.h" #include "misc.h" #include "misc_callbacks.h" #include "name_struct.h" #include "option.h" #include "start_end.h" #include "stat_struct.h" #include "strategy_struct.h" #include "transfer_struct.h" #include "variables.h" #include "window.h" #include "xml_strategy.h" /** Whether the last save gets loaded at startup (cl switch -l). */ gboolean load_last_save; /** Parse the command line arguments given by the user. */ void main_parse_cl_arguments(gint *argc, gchar ***argv) { gboolean testcom = FALSE, calodds = FALSE; gchar *support_dir = NULL, *lang = NULL, *testcom_file = NULL, *token_file = NULL, *event_name = NULL, *debug_text = NULL; gint deb_level = -1, number_of_passes = 1, num_matches = 100, skilldiffmax = 20; GError *error = NULL; GOptionContext *context = NULL; GOptionEntry entries[] = {{ "support-dir", 's', 0, G_OPTION_ARG_STRING, &support_dir, _("Specify additional support directory (takes priority over default ones)"), "DIR" }, { "debug-level", 'd', 0, G_OPTION_ARG_INT, &deb_level, "[developer] Debug level to use", "N" }, { "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 }, { "testcom", 't', 0, G_OPTION_ARG_NONE, &testcom, _("Test an XML commentary 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, /* Live game tokens are strings like _AT_ in live game commentary files which will be filled in by the program during runtime; e.g. _AT_ becomes the attendace for the match. */ _("File containing live game tokens (may be in a support dir)"), "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" }, { "calodds", 'o', 0, G_OPTION_ARG_NONE, &calodds, "[developer] Calibrate the betting odds by simulating a lot of matches", NULL }, { "num-matches", 'm', 0, G_OPTION_ARG_INT, &num_matches, "[developer] How many matches to simulate per skill diff step", "N" }, { "num-skilldiff", 'S', 0, G_OPTION_ARG_INT, &skilldiffmax, "[developer] How many skill diff steps to take", "N" }, { "deb", 'D', 0, G_OPTION_ARG_STRING, &debug_text, "[developer] A debug command like 'deb100 to set the debug level'; see the debug window and debug.c", "STRING" }, {NULL}}; if(argc == NULL || argv == NULL) return; context = g_option_context_new(_("- a simple and addictive GTK2 football manager")); 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(calodds) { option_add(&options, "int_opt_calodds", 1, NULL); option_add(&options, "int_opt_calodds_skilldiffmax", skilldiffmax, NULL); option_add(&options, "int_opt_calodds_matches", num_matches, NULL); } 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); file_add_support_directory_recursive(fullpath); g_free(fullpath); g_free(support_dir); } if(deb_level != -1) option_set_int("int_debug", &constants, deb_level); if(lang != NULL) { language_set(language_get_code_index(lang) + 1); file_load_hints_file(); } if(debug_text != NULL) statp = debug_text; } /** Initialize some global variables. Most of them get nullified. */ void main_init_variables(void) { gint i; ligs = g_array_new(FALSE, FALSE, sizeof(League)); cps = g_array_new(FALSE, FALSE, sizeof(Cup));; acps = g_ptr_array_new(); country.name = NULL; country.symbol = NULL; country.sid = NULL;; season = week = week_round = 1; for(i=0;i 1 && !load_game_from_command_line(argv[1]))))) { stat0 = STATUS_SPLASH; window_show_splash(); if(os_is_unix) file_check_home_dir(); } gtk_main (); main_exit_program(EXIT_OK, NULL); return 0; } /** Exit the program with the given exit code and message. Try to destroy all widgets and free all memory first. @param exit_code The number we return to the shell. @param exit_message The message we print. @return The exit code of the program. */ void main_exit_program(gint exit_code, gchar *format, ...) { gchar text[SMALL]; va_list args; if(format != NULL) { va_start (args, format); g_vsprintf(text, format, args); va_end (args); g_warning(text); } if(gtk_main_level() > 0) gtk_main_quit(); free_memory(); if(!os_is_unix && exit_code != EXIT_OK) { g_warning("Press RETURN. Program will exit."); getchar(); } exit(exit_code); }