initial commit, lordsawar source, slightly modified
[lordsawar] / src / main.cpp
1 // Copyright (C) 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2004, 2005, 2006 Andrea Paternesi
4 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
5 // Copyright (C) 2007 Ole Laursen
6 // Copyright (C) 2005, 2006 Josef Spillner
7 //
8 //  This program is free software; you can redistribute it and/or modify
9 //  it under the terms of the GNU General Public License as published by
10 //  the Free Software Foundation; either version 3 of the License, or
11 //  (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU Library General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
21 //  02110-1301, USA.
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <iostream>
28 #include <stdlib.h>
29 #include <time.h>
30
31 #include "Configuration.h"
32 #include "File.h"
33 #include "GraphicsCache.h"
34 #include "recently-played-game-list.h"
35 #include "cityset.h"
36 #include "tileset.h"
37 #include "shieldset.h"
38 #include "armyset.h"
39
40 #include "gui/main.h"
41
42
43 using namespace std;
44
45
46 int max_vector_width;
47 int main(int argc, char* argv[])
48 {
49   srand(time(NULL));         // set the random seed
50
51   initialize_configuration();
52   Vector<int>::setMaximumWidth(1000);
53   RecentlyPlayedGameList::getInstance()->loadFromFile(File::getSavePath() + "/recently-played.xml");
54
55   #if ENABLE_NLS
56   //cout << "Configuration::s_lang.c_str(): " << Configuration::s_lang.c_str() << endl;
57   setlocale(LC_ALL, Configuration::s_lang.c_str());
58   //setlocale(LC_ALL, "");
59   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
60   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
61   textdomain (GETTEXT_PACKAGE);
62   #endif
63
64   Main kit(argc, argv);
65
66   if (argc > 1)
67     {
68       for (int i = 2; i <= argc; i++)
69         {
70           string parameter(argv[i-1]); 
71           if (parameter == "-c")
72             {
73               i++;
74               //convert the next argument
75               char* error = 0;
76               long size = strtol(argv[i-1], &error, 10);
77               if (error && (*error != '\0'))
78                 {
79                   cerr <<_("non-numerical value for cache size") <<endl;
80                   exit(-1);
81                 }
82               Configuration::s_cacheSize = size;
83             }
84           else if (parameter == "--seed" || parameter == "-S")
85             {
86               i++;
87               //convert the next argument
88               char* error = 0;
89               long seed = strtol(argv[i-1], &error, 10);
90               if (error && (*error != '\0'))
91                 {
92                   cerr <<_("non-numerical value for seed value") <<endl;
93                   exit(-1);
94                 }
95               srand(seed);
96             }
97           else if (parameter == "--turn")
98             {
99               i++;
100               kit.turn_filename = argv[i-1];
101             }
102           else if (parameter == "--test" || parameter == "-t")
103             {
104               kit.start_test_scenario = true;
105             }
106           else if (parameter == "--stress-test" || parameter == "-s")
107             {
108               kit.start_stress_test = true;
109             }
110           else if (parameter == "--robots" || parameter == "-r")
111             {
112               kit.start_robots = -1;
113             }
114           else if (parameter == "--help" || parameter == "-h")
115             {
116               cout << argv[0] << " [OPTION]... [FILE]" << endl << endl;
117               cout << "LordsAWar! " << _("version") << " " << VERSION << endl << endl;
118               cout << _("Options:") << endl << endl; 
119               cout << "  -h, --help                 " << _("Shows this help screen") <<endl;
120               cout << "  -c <size>                  " << _("Set the cache size for imagery to SIZE bytes") <<endl;
121               cout << "  -t, --test                 " << _("Start with a test-scenario") << endl;
122               cout << "  -S, --seed <number>        " << _("Seed the random number generator with NUMBER") << endl;
123               cout << "  -s, --stress-test          " << _("Non-interactive stress test") << endl;
124               cout << "  -r, --robots               " << _("Non-interactive network stress test") << endl;
125               cout << endl;
126               cout << _("FILE can be a saved game file (.sav), or a map (.map) file.") << endl;
127               cout << endl;
128               cout << _("Report bugs to") << " <" << PACKAGE_BUGREPORT ">." << endl;
129               exit(0);
130             }
131           else
132             kit.load_filename = parameter;
133         }
134     }
135
136   if (kit.load_filename != "" && kit.start_test_scenario)
137     {
138       cerr <<_("Error: Cannot specify -t and have a file specified.") << endl;
139       exit (1);
140     }
141
142   if (kit.load_filename != "" && kit.start_stress_test)
143     {
144       cerr <<_("Error: Cannot specify -s and have a file specified.") << endl;
145       exit (1);
146     }
147
148   if (kit.start_stress_test && kit.start_test_scenario)
149     {
150       cerr <<_("Error: Cannot specify -s and -t simultaneously.") << endl;
151       exit (1);
152     }
153
154   if (kit.turn_filename != "" && kit.load_filename == "")
155     {
156       cerr <<_("Error: Must specify a file to load when specifying --turn.") << endl;
157       exit (1);
158     }
159
160
161   // Check if armysets are in the path (otherwise exit)
162   Armyset::scanSystemCollection();
163   Tileset::scanSystemCollection();
164   Shieldset::scanSystemCollection();
165   Cityset::scanSystemCollection();
166
167
168   kit.start_main_loop();
169
170   return EXIT_SUCCESS;
171 }