1 /*
2 * Seven Kingdoms: Ancient Adversaries
3 *
4 * Copyright 1997,1998 Enlight Software Ltd.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 //Filename : AM.CPP
22 //Description : Ambition Entry Program
23
24 #include <ALL.h>
25 #include <version.h>
26
27 #ifdef ENABLE_INTRO_VIDEO
28 #include <initguid.h>
29 #include <dshow.h>
30 #endif
31
32 #include <OANLINE.h>
33 #include <OAUDIO.h>
34 #include <OBATTLE.h>
35 #include <OBOX.h>
36 #include <OBULLET.h>
37 #include <OCONFIG.h>
38 #include <ODATE.h>
39 #include <OFIRM.h>
40 #include <OFLAME.h>
41 #include <OFONT.h>
42 #include <OGAME.h>
43 #include <OGAMESET.h>
44 #include <OSaveGameArray.h>
45 #include <OGAMHALL.h>
46 #include <OGODRES.h>
47 #include <OHELP.h>
48 #include <OHILLRES.h>
49 #include <OIMGRES.h>
50 #include <OINFO.h>
51 #include <OMONSRES.h>
52 #include <OMOUSE.h>
53 #include <OMOUSECR.h>
54 #include <ONATION.h>
55 #include <ONEWS.h>
56 #include <OPLANT.h>
57 #include <OPOWER.h>
58 #include <ORACERES.h>
59 #include <OREBEL.h>
60 #include <OREMOTE.h>
61 #include <OSPATH.h>
62 #include <OSITE.h>
63 #include <OSPREUSE.h>
64 #include <OSPY.h>
65 #include <OSYS.h>
66 #include <OTALKRES.h>
67 #include <OTECHRES.h>
68 #include <OTERRAIN.h>
69 #include <OTOWN.h>
70 #include <OTownNetwork.h>
71 #include <OUNIT.h>
72 #include <OVGA.h>
73 #include <vga_util.h>
74 #ifdef ENABLE_INTRO_VIDEO
75 #include <OVIDEO.h>
76 #endif
77 #include <OWALLRES.h>
78 #include <OWORLD.h>
79 #include <OWEATHER.h>
80 #include <OTORNADO.h>
81 #include <OTUTOR.h>
82 #include <OSE.h>
83 #include <OSERES.h>
84 #include <OSNOWRES.h>
85 #include <OSNOWG.h>
86 #include <OROCKRES.h>
87 #include <OROCK.h>
88 #include <OEFFECT.h>
89 #include <OEXPMASK.h>
90 #include <OREGION.h>
91 #include <OWARPT.h>
92 #include <multiplayer.h>
93 #ifdef HAVE_LIBCURL
94 #include <WebService.h>
95 #endif
96 #include <OERRCTRL.h>
97 #include <OMUSIC.h>
98 #include <OLOG.h>
99 #include <OLONGLOG.h>
100 //### begin alex 3/10 ###//
101 #include <OGRPSEL.h>
102 //#### end alex 3/10 ####//
103 #include <OFIRMDIE.h>
104 #include <OCRC_STO.h>
105 // ###### begin Gilbert 23/10 #######//
106 #include <OOPTMENU.h>
107 #include <OINGMENU.h>
108 // ###### end Gilbert 23/10 #######//
109 #include <dbglog.h>
110 #include <CmdLine.h>
111 #include <LocaleRes.h>
112 #include <PlayerStats.h>
113 #include "gettext.h"
114 #include <ConfigAdv.h>
115
116 //------- define game version constant --------//
117
118 const char *GAME_VERSION_STR = SKVERSION;
119 const int GAME_VERSION = 212; // Version 2.00, don't change it unless the format of save game files has been changed
120
121 //-------- System class ----------//
122
123 #ifndef NO_MEM_CLASS
124 Mem mem; // constructor only init var and allocate memory
125 #endif
126
127 Error err; // constructor only call set_new_handler()d
128 Mouse mouse;
129 MouseCursor mouse_cursor;
130 Misc misc, misc2;
131 DateInfo date;
132 Vga vga;
133 VgaUtil vga_util;
134 VgaBuf vga_front, vga_back, vga_true_front;
135 #ifdef ENABLE_INTRO_VIDEO
136 Video video;
137 #endif
138 Audio audio;
139 Music music;
140 MultiPlayer mp_obj;
141 #ifdef HAVE_LIBCURL
142 WebService ws;
143 #endif
144 Sys sys;
145 SeekPath seek_path;
146 SeekPathReuse seek_path_reuse;
147 Flame flame[FLAME_GROW_STEP];
148 Remote remote;
149 ErrorControl ec_remote;
150 AnimLine anim_line;
151 SECtrl se_ctrl(&audio);
152 SERes se_res;
153 Log msg_log;
154 #ifdef DEBUG
155 LongLog * long_log;
156 #endif
157 //### begin alex 3/10 ###//
158 GroupSelect group_select;
159 //#### end alex 3/10 ####//
160
161 //------- Resource class ----------//
162
163 Font font_san, font_std, font_small, font_mid, font_news;
164 Font font_hitpoint, font_bible, font_bard;
165
166 #if( defined(GERMAN) || defined(FRENCH) || defined(SPANISH) )
167 Font font_hall;
168 #endif
169
170 Box box;
171 ImageRes image_icon, image_interface, image_menu,
172 image_button, image_spict;
173 ImageRes image_encyc;
174 ImageRes image_tpict;
175 ImageRes image_tutorial;
176 ImageRes image_menu_plus;
177 ImageRes& image_menu2 = image_menu_plus;
178 SpriteRes sprite_res;
179 SpriteFrameRes sprite_frame_res;
180 UnitRes unit_res;
181 TerrainRes terrain_res;
182 PlantRes plant_res;
183 WallRes wall_res;
184 RawRes raw_res;
185 FirmRes firm_res;
186 FirmDieRes firm_die_res;
187 RaceRes race_res;
188 TownRes town_res;
189 HillRes hill_res;
190 TalkRes talk_res;
191 TechRes tech_res;
192 GodRes god_res;
193 MonsterRes monster_res;
194 SnowRes snow_res;
195 RockRes rock_res;
196 ExploredMask explored_mask;
197 Help help;
198 Tutor tutor;
199 LocaleRes locale_res;
200
201 //-------- Game Data class -----------//
202
203 UnitArray unit_array(100); // 100-initial array size
204 BulletArray bullet_array(100);
205 SiteArray site_array;
206 TownArray town_array;
207 TownNetworkArray town_network_array;
208 NationArray nation_array;
209 FirmArray firm_array;
210 FirmDieArray firm_die_array;
211 TornadoArray tornado_array(10);
212 RebelArray rebel_array;
213 SpyArray spy_array;
214 SnowGroundArray snow_ground_array;
215 RockArray rock_array;
216 RockArray dirt_array;
217 SpriteArray effect_array(50);
218 RegionArray region_array;
219 NewsArray news_array;
220 WarPointArray war_point_array;
221 CrcStore crc_store;
222
223 //--------- Game Surface class ------------//
224
225 Info info;
226 Weather weather, weather_forecast[MAX_WEATHER_FORECAST];
227 MagicWeather magic_weather;
228 Config config;
229 Game game;
230 GameSet game_set; // no constructor
231 Battle battle;
232 Power power;
233 World world;
234 char scenario_file_name[FilePath::MAX_FILE_PATH+1];
235 SaveGameArray save_game_array;
236 nsPlayerStats::PlayerStats playerStats;
237 HallOfFame hall_of_fame;
238 // ###### begin Gilbert 23/10 #######//
239 OptionMenu option_menu;
240 InGameMenu in_game_menu;
241 // ###### end Gilbert 23/10 #######//
242 CmdLine cmd_line;
243 ConfigAdv config_adv;
244
245 //----------- Global Variables -----------//
246
247 char game_design_mode=0;
248 char game_demo_mode=0;
249 char debug2_enable_flag=0;
250 File seedCompareFile;
251 char debug_seed_status_flag=0;
252 int debug_sim_game_type = 0;
253 int unit_search_node_used=0;
254 short nation_hand_over_flag=0;
255 int unit_search_tries = 0; // the number of tries used in the current searching
256 char unit_search_tries_flag = 0; // indicate num of tries is set, reset after searching
257
258 char new_config_dat_flag=0;
259
260 #ifdef DEBUG
261 int check_unit_dir1, check_unit_dir2;
262 unsigned long last_unit_ai_profile_time = 0L;
263 unsigned long unit_ai_profile_time = 0L;
264 unsigned long last_unit_profile_time = 0L;
265 unsigned long unit_profile_time = 0L;
266 unsigned long seek_path_profile_time = 0L;
267 unsigned long last_seek_path_profile_time = 0L;
268 unsigned long last_sprite_array_profile_time = 0L;
269 unsigned long sprite_array_profile_time = 0L;
270 unsigned long last_sprite_idle_profile_time = 0L;
271 unsigned long sprite_idle_profile_time = 0L;
272 unsigned long last_sprite_move_profile_time = 0L;
273 unsigned long sprite_move_profile_time = 0L;
274 unsigned long last_sprite_wait_profile_time = 0L;
275 unsigned long sprite_wait_profile_time = 0L;
276 unsigned long last_sprite_attack_profile_time = 0L;
277 unsigned long sprite_attack_profile_time = 0L;
278 unsigned long last_unit_attack_profile_time = 0L;
279 unsigned long unit_attack_profile_time = 0L;
280 unsigned long last_unit_assign_profile_time = 0L;
281 unsigned long unit_assign_profile_time = 0L;
282 #endif
283
284 DBGLOG_DEFAULT_CHANNEL(am);
285
286 //------- Define static functions --------//
287
288 static void extra_error_handler();
289
290 //---------- Begin of function main ----------//
291 //
292 // Compilation constants:
293 //
294 // DEBUG - normal debugging
295 // DEBUG2 - shortest path searching and unit action debugging
296 // DEBUG3 - debugging some functions (e.g. Location::get_loc()) which
297 // will cause major slowdown.
298 //
main(int argc,char ** argv)299 int main(int argc, char **argv)
300 {
301 if (!sys.set_game_dir())
302 return 1;
303 locale_res.init();
304 sys.set_config_dir();
305
306 //try to read from CONFIG.DAT, moved to AM.CPP
307
308 if( !config.load("CONFIG.DAT") )
309 {
310 new_config_dat_flag = 1;
311 config.init();
312 }
313 config_adv.init();
314 if( config_adv.locale[0] )
315 locale_res.load();
316
317 //----- read command line arguments -----//
318
319 if( !cmd_line.init(argc, argv) )
320 return 1;
321
322 #ifdef ENABLE_INTRO_VIDEO
323 //----------- play movie ---------------//
324
325 if( cmd_line.startup_mode == STARTUP_NORMAL )
326 {
327 String movieFileStr;
328 movieFileStr = DIR_MOVIE;
329 movieFileStr += "INTRO.AVI";
330
331 video.set_skip_on_fail();
332
333 // ###### begin Gilbert 29/10 #####//
334 if( !misc.is_file_exist("SKIPAVI.SYS") && misc.is_file_exist(movieFileStr) )
335 // ###### end Gilbert 29/10 #####//
336 {
337 //---------- play the movie now ---------//
338
339 video.init();
340
341 if( video.init_success )
342 {
343 video.play_until_end( movieFileStr, hInstance, 60 );
344 }
345 else
346 {
347 // display a message box (note:sys.main_hwnd is not valid)
348 // MessageBox( NULL, "Cannot initialize ActiveMovie",
349 // "Seven Kingdoms", MB_OK | MB_ICONWARNING | MB_DEFBUTTON1 | MB_TASKMODAL );
350 }
351
352 video.deinit();
353 }
354 }
355 #endif // ENABLE_INTRO_VIDEO
356
357 if( !sys.init() )
358 {
359 vga.save_status_report();
360 return 1;
361 }
362
363 err.set_extra_handler( extra_error_handler ); // set extra error handler, save the game when a error happens
364
365 switch( cmd_line.startup_mode )
366 {
367 case STARTUP_NORMAL:
368 game.main_menu();
369 break;
370 #ifndef DISABLE_MULTI_PLAYER
371 case STARTUP_MULTI_PLAYER:
372 game.multi_player_menu(1, cmd_line.join_host);
373 break;
374 #endif
375 case STARTUP_TEST:
376 game.init();
377 battle.run_test();
378 game.deinit();
379 break;
380 case STARTUP_DEMO:
381 mouse_cursor.set_icon(CURSOR_NORMAL);
382 sys.disp_fps_flag = 1;
383 config.help_mode = NO_HELP;
384 game.init();
385 game.game_mode = GAME_DEMO;
386 info.init_random_seed(0);
387 battle.run(0);
388 game.deinit();
389 break;
390 default:
391 game.main_menu();
392 break;
393 }
394
395 sys.deinit();
396
397 return 0;
398 }
399 //---------- End of function main ----------//
400
401
402 //------- Begin of function extra_error_handler -----------//
403
extra_error_handler()404 static void extra_error_handler()
405 {
406 if( game.game_mode != GAME_SINGLE_PLAYER )
407 return;
408
409 save_game_array.save_new_game("ERROR.SAV"); // save a new game immediately without prompting menu
410
411 box.msg( "Error encountered. The game has been saved to ERROR.SAV" );
412 }
413 //----------- End of function extra_error_handler -------------//
414