AM.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. //Filename : AM.CPP
  21. //Description : Ambition Entry Program
  22. #include <windows.h>
  23. #include <initguid.h>
  24. #ifdef ENABLE_INTRO_VIDEO
  25. #include <dshow.h>
  26. #endif
  27. #include <ALL.h>
  28. #include <OANLINE.h>
  29. #include <OAUDIO.h>
  30. #include <OBATTLE.h>
  31. #include <OBOX.h>
  32. #include <OBULLET.h>
  33. #include <OCONFIG.h>
  34. #include <ODATE.h>
  35. #include <OFIRM.h>
  36. #include <OFLAME.h>
  37. #include <OFONT.h>
  38. #include <OGAME.h>
  39. #include <OGAMESET.h>
  40. #include <OGFILE.h>
  41. #include <OGODRES.h>
  42. #include <OHELP.h>
  43. #include <OHILLRES.h>
  44. #include <OIMGRES.h>
  45. #include <OINFO.h>
  46. #include <OMONSRES.h>
  47. #include <OMOUSE.h>
  48. #include <OMOUSECR.h>
  49. #include <ONATION.h>
  50. #include <ONEWS.h>
  51. #include <OPLANT.h>
  52. #include <OPOWER.h>
  53. #include <ORACERES.h>
  54. #include <OREBEL.h>
  55. #include <OREMOTE.h>
  56. #include <OSPATH.h>
  57. #include <OSPATHS2.h>
  58. #include <OSITE.h>
  59. #include <OSPREUSE.h>
  60. #include <OSPY.h>
  61. #include <OSYS.h>
  62. #include <OTALKRES.h>
  63. #include <OTECHRES.h>
  64. #include <OTERRAIN.h>
  65. #include <OTOWN.h>
  66. #include <OTRANSL.h>
  67. #include <OUNIT.h>
  68. #include <OVGA.h>
  69. #ifdef ENABLE_INTRO_VIDEO
  70. #include <OVIDEO.h>
  71. #endif
  72. #include <OWALLRES.h>
  73. #include <OWORLD.h>
  74. #include <OWEATHER.h>
  75. #include <OTORNADO.h>
  76. #include <OTUTOR.h>
  77. #include <OSE.h>
  78. #include <OSERES.h>
  79. #include <OSNOWRES.h>
  80. #include <OSNOWG.h>
  81. #include <OROCKRES.h>
  82. #include <OROCK.h>
  83. #include <OEFFECT.h>
  84. #include <OEXPMASK.h>
  85. #include <OREGION.h>
  86. #include <OWARPT.h>
  87. #include <ODPLAY.h>
  88. #include <OIMMPLAY.h>
  89. #include <OERRCTRL.h>
  90. #include <OMUSIC.h>
  91. #include <OLOG.h>
  92. #include <OLONGLOG.h>
  93. //### begin alex 3/10 ###//
  94. #include <OGRPSEL.h>
  95. //#### end alex 3/10 ####//
  96. #include <OFIRMDIE.h>
  97. #include <OCRC_STO.h>
  98. // ###### begin Gilbert 23/10 #######//
  99. #include <OOPTMENU.h>
  100. #include <OINGMENU.h>
  101. // ###### end Gilbert 23/10 #######//
  102. //------- define game version constant --------//
  103. #ifdef AMPLUS
  104. char *GAME_VERSION_STR = "2.13.2";
  105. const int GAME_VERSION = 212; // Version 2.00, don't change it unless the format of save game files has been changed
  106. #else
  107. char *GAME_VERSION_STR = "1.11";
  108. const int GAME_VERSION = 111; // Version 1.00, don't change it unless the format of save game files has been changed
  109. #endif
  110. //-------- System class ----------//
  111. #ifndef NO_MEM_CLASS
  112. Mem mem; // constructor only init var and allocate memory
  113. #endif
  114. Error err; // constructor only call set_new_handler()d
  115. Mouse mouse;
  116. MouseCursor mouse_cursor;
  117. Misc m, m2;
  118. DateInfo date;
  119. Vga vga;
  120. VgaBuf vga_front, vga_back, vga_true_front;
  121. #ifdef ENABLE_INTRO_VIDEO
  122. Video video;
  123. #endif
  124. Audio audio;
  125. Music music;
  126. MultiPlayerType mp_obj;
  127. // MultiPlayerDP mp_dp;
  128. // MultiPlayerIM mp_im;
  129. Sys sys;
  130. Translate translate; // constructor only memset()
  131. SeekPath seek_path;
  132. SeekPathS2 seek_path_s2;
  133. SeekPathReuse seek_path_reuse;
  134. Flame flame[FLAME_GROW_STEP];
  135. Remote remote;
  136. ErrorControl ec_remote;
  137. AnimLine anim_line;
  138. SECtrl se_ctrl(&audio);
  139. SERes se_res;
  140. Log msg_log;
  141. #ifdef DEBUG
  142. LongLog * long_log;
  143. #endif
  144. //### begin alex 3/10 ###//
  145. GroupSelect group_select;
  146. //#### end alex 3/10 ####//
  147. //------- Resource class ----------//
  148. Font font_san, font_std, font_small, font_mid, font_news;
  149. Font font_hitpoint, font_bible, font_bard;
  150. #if( defined(GERMAN) || defined(FRENCH) || defined(SPANISH) )
  151. Font font_hall;
  152. #endif
  153. Box box;
  154. ImageRes image_icon, image_interface, image_menu,
  155. image_button, image_spict;
  156. ImageRes image_encyc;
  157. ImageRes image_tpict;
  158. ImageRes image_tutorial;
  159. #ifdef AMPLUS
  160. ImageRes image_menu_plus;
  161. ImageRes& image_menu2 = image_menu_plus;
  162. #else
  163. ImageRes& image_menu2 = image_menu;
  164. #endif
  165. SpriteRes sprite_res;
  166. SpriteFrameRes sprite_frame_res;
  167. UnitRes unit_res;
  168. TerrainRes terrain_res;
  169. PlantRes plant_res;
  170. WallRes wall_res;
  171. RawRes raw_res;
  172. FirmRes firm_res;
  173. FirmDieRes firm_die_res;
  174. RaceRes race_res;
  175. TownRes town_res;
  176. HillRes hill_res;
  177. TalkRes talk_res;
  178. TechRes tech_res;
  179. GodRes god_res;
  180. MonsterRes monster_res;
  181. SnowRes snow_res;
  182. RockRes rock_res;
  183. ExploredMask explored_mask;
  184. Help help;
  185. Tutor tutor;
  186. //-------- Game Data class -----------//
  187. UnitArray unit_array(100); // 100-initial array size
  188. BulletArray bullet_array(100);
  189. SiteArray site_array;
  190. TownArray town_array;
  191. NationArray nation_array;
  192. FirmArray firm_array;
  193. FirmDieArray firm_die_array;
  194. TornadoArray tornado_array(10);
  195. RebelArray rebel_array;
  196. SpyArray spy_array;
  197. SnowGroundArray snow_ground_array;
  198. RockArray rock_array;
  199. RockArray dirt_array;
  200. SpriteArray effect_array(50);
  201. RegionArray region_array;
  202. NewsArray news_array;
  203. WarPointArray war_point_array;
  204. CrcStore crc_store;
  205. //--------- Game Surface class ------------//
  206. Info info;
  207. Weather weather, weather_forecast[MAX_WEATHER_FORECAST];
  208. MagicWeather magic_weather;
  209. Config config;
  210. Game game;
  211. GameSet game_set; // no constructor
  212. Battle battle;
  213. Power power;
  214. World world;
  215. GameFileArray game_file_array;
  216. GameFile game_file;
  217. // ###### begin Gilbert 23/10 #######//
  218. OptionMenu option_menu;
  219. InGameMenu in_game_menu;
  220. // ###### end Gilbert 23/10 #######//
  221. //----------- Global Variables -----------//
  222. char game_design_mode=0;
  223. char game_demo_mode=0;
  224. char debug2_enable_flag=0;
  225. File seedCompareFile;
  226. char debug_seed_status_flag=0;
  227. int debug_sim_game_type = 0;
  228. int unit_search_node_used=0;
  229. short nation_hand_over_flag=0;
  230. int unit_search_tries = 0; // the number of tries used in the current searching
  231. char unit_search_tries_flag = 0; // indicate num of tries is set, reset after searching
  232. char new_config_dat_flag=0;
  233. #ifdef DEBUG
  234. int check_unit_dir1, check_unit_dir2;
  235. unsigned long last_unit_ai_profile_time = 0L;
  236. unsigned long unit_ai_profile_time = 0L;
  237. unsigned long last_unit_profile_time = 0L;
  238. unsigned long unit_profile_time = 0L;
  239. unsigned long seek_path_profile_time = 0L;
  240. unsigned long last_seek_path_profile_time = 0L;
  241. unsigned long last_sprite_array_profile_time = 0L;
  242. unsigned long sprite_array_profile_time = 0L;
  243. unsigned long last_sprite_idle_profile_time = 0L;
  244. unsigned long sprite_idle_profile_time = 0L;
  245. unsigned long last_sprite_move_profile_time = 0L;
  246. unsigned long sprite_move_profile_time = 0L;
  247. unsigned long last_sprite_wait_profile_time = 0L;
  248. unsigned long sprite_wait_profile_time = 0L;
  249. unsigned long last_sprite_attack_profile_time = 0L;
  250. unsigned long sprite_attack_profile_time = 0L;
  251. unsigned long last_unit_attack_profile_time = 0L;
  252. unsigned long unit_attack_profile_time = 0L;
  253. unsigned long last_unit_assign_profile_time = 0L;
  254. unsigned long unit_assign_profile_time = 0L;
  255. #endif
  256. //------- Define static functions --------//
  257. static void extra_error_handler();
  258. //---------- Begin of function WinMain ----------//
  259. //¹ç
  260. // WinMain - initialization, message loop
  261. //
  262. // Compilation constants:
  263. //
  264. // DEBUG - normal debugging
  265. // DEBUG2 - shortest path searching and unit action debugging
  266. // DEBUG3 - debugging some functions (e.g. Location::get_loc()) which
  267. // will cause major slowdown.
  268. //
  269. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  270. LPSTR lpCmdLine, int nCmdShow)
  271. {
  272. //try to read from CONFIG.DAT, moved to AM.CPP
  273. if( !config.load("CONFIG.DAT") )
  274. {
  275. new_config_dat_flag = 1;
  276. config.init();
  277. }
  278. //--------------------------------------//
  279. #ifdef IMAGICMP
  280. static char lobbyLaunchCmdLine[] = "IM";
  281. #else
  282. static char lobbyLaunchCmdLine[] = "-!lobby!";
  283. #endif
  284. #ifdef ENABLE_INTRO_VIDEO
  285. //----------- play movie ---------------//
  286. sys.set_game_dir();
  287. if( strstr(lpCmdLine, lobbyLaunchCmdLine) == NULL ) // skip if launch from lobby
  288. {
  289. String movieFileStr;
  290. movieFileStr = DIR_MOVIE;
  291. movieFileStr += "INTRO.AVI";
  292. video.set_skip_on_fail();
  293. // ###### begin Gilbert 29/10 #####//
  294. if( !m.is_file_exist("SKIPAVI.SYS") && m.is_file_exist(movieFileStr) )
  295. // ###### end Gilbert 29/10 #####//
  296. {
  297. //---------- play the movie now ---------//
  298. video.init();
  299. if( video.init_success )
  300. {
  301. video.play_until_end( movieFileStr, hInstance, 60 );
  302. }
  303. else
  304. {
  305. // display a message box (note:sys.main_hwnd is not valid)
  306. // MessageBox( NULL, "Cannot initialize ActiveMovie",
  307. // "Seven Kingdoms", MB_OK | MB_ICONWARNING | MB_DEFBUTTON1 | MB_TASKMODAL );
  308. }
  309. video.deinit();
  310. }
  311. }
  312. #endif // ENABLE_INTRO_VIDEO
  313. if( !sys.init(hInstance) )
  314. return FALSE;
  315. err.set_extra_handler( extra_error_handler ); // set extra error handler, save the game when a error happens
  316. #ifdef DEMO
  317. game.demo_disp_logo();
  318. game.main_menu();
  319. #else
  320. if( strstr(lpCmdLine, lobbyLaunchCmdLine) == NULL )
  321. game.main_menu();
  322. #ifndef DISABLE_MULTI_PLAYER
  323. else
  324. game.multi_player_menu(lpCmdLine); // if detect launched from lobby
  325. #endif // DISABLE_MULTI_PLAYER
  326. #endif
  327. sys.deinit();
  328. return 1;
  329. }
  330. //---------- End of function WinMain ----------//
  331. //----------- Begin of function Msg ----------//
  332. //
  333. // Routine for displaying debug messages
  334. //
  335. #ifdef DEBUG
  336. void __cdecl debug_msg( char* fmt, ... )
  337. {
  338. char buff[256];
  339. lstrcpy( buff, "SEVEN KINGDOMS: " );
  340. wvsprintf( buff+lstrlen(buff), fmt, (char*)(&fmt+1) );
  341. lstrcat( buff, "\r\n" );
  342. OutputDebugString( buff );
  343. }
  344. #endif
  345. //----------- End of function Msg ----------//
  346. //------- Begin of function extra_error_handler -----------//
  347. static void extra_error_handler()
  348. {
  349. if( game.game_mode != GAME_SINGLE_PLAYER )
  350. return;
  351. game_file_array.save_new_game("ERROR.SAV"); // save a new game immediately without prompting menu
  352. box.msg( "Error encountered. The game has been saved to ERROR.SAV" );
  353. }
  354. //----------- End of function extra_error_handler -------------//