gameinitmgr.cpp 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/gameinitmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 6/21/02 2:24p $*
  29. * *
  30. * $Revision:: 75 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "gameinitmgr.h"
  36. #include "gamedata.h"
  37. #include "gamemode.h"
  38. #include "cnetwork.h"
  39. #include "ww3d.h"
  40. #include "singlepl.h"
  41. #include "player.h"
  42. #include "renegadedialogmgr.h"
  43. #include "netinterface.h"
  44. #include "langmode.h"
  45. #include "wolgmode.h"
  46. #include "playermanager.h"
  47. #include "wwaudio.h"
  48. #include "saveloadstatus.h"
  49. #include "combatgmode.h"
  50. #include "useroptions.h"
  51. #include "lanchat.h"
  52. #include "rendobj.h"
  53. #include "phys.h"
  54. #include "pscene.h"
  55. #include "dx8renderer.h"
  56. #include "gdsingleplayer.h"
  57. #include "gdskirmish.h"
  58. #include "playertype.h"
  59. #include "gameobjmanager.h"
  60. #include "gametype.h"
  61. #include "god.h"
  62. #include "bioevent.h"
  63. #include "devoptions.h"
  64. #include "svrgoodbyeevent.h"
  65. #include "natter.h"
  66. #include "apppacketstats.h"
  67. #include "packetmgr.h"
  68. #include "autostart.h"
  69. #include "wwmemlog.h"
  70. #include "gamesideservercontrol.h"
  71. #include "slavemaster.h"
  72. #include "hud.h"
  73. #include "gamespyadmin.h"
  74. #include "serversettings.h"
  75. #include "gamespy_qnr.h"
  76. #include "specialbuilds.h"
  77. #include "modpackagemgr.h"
  78. #include "translatedb.h"
  79. #include "damage.h"
  80. #include "ccamera.h"
  81. #include "bones.h"
  82. #include "surfaceeffects.h"
  83. #include "ffactory.h"
  84. #include "ini.h"
  85. #include "dazzle.h"
  86. #include "scripts.h"
  87. static void _reload_game_configuration_files(void);
  88. // Defines.
  89. #define PRE_SERVICE_TIME 1500 // Time in milliseconds.
  90. #define POST_SERVICE_TIME 250 // Time in milliseconds.
  91. ////////////////////////////////////////////////////////////////
  92. // Static member initialization
  93. ////////////////////////////////////////////////////////////////
  94. bool GameInitMgrClass::IsClientRequired = false;
  95. bool GameInitMgrClass::IsServerRequired = false;
  96. bool GameInitMgrClass::RestoreSFX = false;
  97. bool GameInitMgrClass::RestoreMusic = false;
  98. bool GameInitMgrClass::NeedsGameExit = false;
  99. bool GameInitMgrClass::NeedsGameExitAll = false;
  100. int GameInitMgrClass::Mode = MODE_UNKNOWN;
  101. int GameInitMgrClass::WOLReturnDialog = RenegadeDialogMgrClass::LOC_INTERNET_MAIN;
  102. bool GameInitMgrClass::Is_Game_In_Progress(void)
  103. {
  104. GameModeClass* mode = GameModeManager::Find("Combat");
  105. //return (mode && mode->Is_Active());
  106. return (mode != NULL && !mode->Is_Inactive());
  107. }
  108. ////////////////////////////////////////////////////////////////
  109. //
  110. // Start_Game
  111. //
  112. ////////////////////////////////////////////////////////////////
  113. void
  114. GameInitMgrClass::Start_Game (const char *map_name, int teamChoice, unsigned long clanID)
  115. {
  116. unsigned long time;
  117. WWASSERT(map_name != NULL);
  118. WWDEBUG_SAY (("GameInitMgrClass::Start_Game(%s)\n", map_name));
  119. // NOTE: Multi-play does not need this fix because it does not sound page swap.
  120. if (IS_SOLOPLAY) {
  121. // IML: First, allow a short period to process any outstanding sound effects that may have
  122. // been started by the caller.
  123. time = TIMEGETTIME();
  124. while (TIMEGETTIME() - time < PRE_SERVICE_TIME) {
  125. WWAudioClass::Get_Instance ()->On_Frame_Update (0);
  126. }
  127. // IML: Ensure that there are no sound effects lingering on any playlist.
  128. WWAudioClass::Get_Instance ()->Flush_Playlist();
  129. // IML: Allow audio system to clean-up after flush.
  130. time = TIMEGETTIME();
  131. while (TIMEGETTIME() - time < POST_SERVICE_TIME) {
  132. WWAudioClass::Get_Instance ()->On_Frame_Update (0);
  133. }
  134. }
  135. //
  136. // Kill off any old suspended game
  137. //
  138. if (GameModeManager::Find ("Combat")->Is_Suspended ()) {
  139. End_Game ();
  140. GameModeManager::Safely_Deactivate ();
  141. }
  142. //
  143. // Set the map name
  144. //
  145. StringClass map(map_name,true);
  146. WWASSERT(PTheGameData != NULL);
  147. The_Game ()->Set_Map_Name (map);
  148. //
  149. // Determine if there is a mod specified... if so, load the mod package
  150. //
  151. ModPackageMgrClass::Load_Current_Mod ();
  152. //
  153. // Reload the sub-systems that may be affected by a mod
  154. //
  155. _reload_game_configuration_files();
  156. //
  157. // Check to ensure the game is configured correctly
  158. //
  159. #ifdef WWDEBUG
  160. WideStringClass outMsg;
  161. if (!The_Game()->Is_Valid_Settings(outMsg)) {
  162. WWDEBUG_SAY(("ERROR: %S\n", (const WCHAR*)outMsg));
  163. WWASSERT("The_Game()->Is_Valid_Settings()");
  164. }
  165. #endif
  166. //
  167. // Reset Data Safe state.
  168. //
  169. GenericDataSafeClass::Reset();
  170. //
  171. // Reset packet optimizer bandwidth stats.
  172. //
  173. PacketManager.Reset_Stats();
  174. //
  175. // Start either the client or server (or both) depending
  176. // on which mode we are in.
  177. //
  178. Start_Client_Server ();
  179. //
  180. // Deactivate the menu system
  181. //
  182. INIT_STATUS ("Deactivate menu");
  183. GameModeManager::Find ("Menu")->Deactivate ();
  184. //
  185. // Active the combat system
  186. //
  187. INIT_STATUS ("Activate combat");
  188. GameModeManager::Find ("Combat")->Activate ();
  189. INIT_STATUS ("");
  190. //
  191. // Load the level
  192. //
  193. CombatGameModeClass *game_mode = static_cast<CombatGameModeClass*>(GameModeManager::Find ("Combat"));
  194. game_mode->Load_Level ();
  195. //
  196. // Let the LAN or WOL interface know we are starting a game
  197. //
  198. if (Mode == MODE_LAN) {
  199. INIT_STATUS ("Go to location");
  200. PLC->Go_To_Location (LANLOC_INGAME);
  201. } else if (Mode == MODE_WOL) {
  202. INIT_STATUS ("Go to game channel");
  203. }
  204. //
  205. // Reset some rendering data
  206. //
  207. PhysicsSceneClass::Get_Instance()->Release_Projector_Resources ();
  208. TheDX8MeshRenderer.Invalidate ();
  209. //
  210. // Prevent the first couple frames from rendering, so that all textures get cached.
  211. //
  212. GameModeManager::Hide_Render_Frames (2);
  213. //
  214. // Send team/player information to the server (if necessary)
  215. //
  216. Transmit_Player_Data (teamChoice, clanID);
  217. //
  218. // Set the auto restart flag if required.
  219. //
  220. AutoRestart.Set_Restart_Flag((The_Game()->IsAutoRestart.Is_True()) ? true : false);
  221. //
  222. // Listen for server control messages.
  223. //
  224. GameSideServerControlClass::Init();
  225. return ;
  226. }
  227. ////////////////////////////////////////////////////////////////
  228. //
  229. // End_Game
  230. //
  231. ////////////////////////////////////////////////////////////////
  232. void
  233. GameInitMgrClass::End_Game (void)
  234. {
  235. unsigned long time;
  236. WWDEBUG_SAY (("GameInitMgrClass::End_Game\n"));
  237. // Do nothing if the game is not in progress.
  238. if ( !IS_MISSION && (!Is_Game_In_Progress())) {
  239. return;
  240. }
  241. // NOTE: Multi-play does not need this fix because it does not sound page swap.
  242. if (IS_SOLOPLAY) {
  243. // IML: Allow a short period to process any outstanding sound effects that may have
  244. // been started by the caller.
  245. time = TIMEGETTIME();
  246. while (TIMEGETTIME() - time < PRE_SERVICE_TIME) {
  247. WWAudioClass::Get_Instance ()->On_Frame_Update (0);
  248. }
  249. // IML: Ensure that there are no sound effects lingering on any playlist.
  250. WWAudioClass::Get_Instance ()->Flush_Playlist();
  251. // IML: Allow audio system to clean-up after flush.
  252. time = TIMEGETTIME();
  253. while (TIMEGETTIME() - time < POST_SERVICE_TIME) {
  254. WWAudioClass::Get_Instance ()->On_Frame_Update (0);
  255. }
  256. }
  257. #ifndef MULTIPLAYERDEMO
  258. if ( IS_MISSION && COMBAT_STAR ) {
  259. cGod::Store_Inventory( COMBAT_STAR );
  260. }
  261. #endif // !MULTIPLAYERDEMO
  262. // Stop reporting to Gamespy.
  263. if (Mode == MODE_LAN && GameSpyQnR.IsEnabled()) {
  264. GameSpyQnR.Shutdown();
  265. }
  266. //
  267. // A dedicated server will disable sfx & music. Restore them here.
  268. //
  269. if (WWAudioClass::Get_Instance() != NULL) {
  270. if (RestoreSFX) {
  271. WWAudioClass::Get_Instance()->Allow_Sound_Effects(true);
  272. }
  273. if (RestoreMusic) {
  274. WWAudioClass::Get_Instance()->Allow_Music(true);
  275. }
  276. }
  277. if (GameModeManager::Find( "Combat" )->Is_Active()) {
  278. //
  279. // Combat is still active during the ingame menu and multiplayer gameplay.
  280. // Suspend it first because that is the state that it is in for
  281. // single-player.
  282. //
  283. GameModeManager::Find( "Combat" )->Suspend();
  284. }
  285. //
  286. // Notify the game data object that the game is over
  287. //
  288. cGameData* theGame = PTheGameData;
  289. //
  290. // Shut down slave game servers.
  291. //
  292. SlaveMaster.Shutdown_Slaves();
  293. //
  294. // Stop listening for server control messages.
  295. //
  296. GameSideServerControlClass::Shutdown();
  297. if (theGame) {
  298. theGame->On_Game_End();
  299. }
  300. //
  301. // Disable auto restart mode.
  302. //
  303. // For forced exits the mode will already be correct.
  304. //
  305. if (!cGameData::Is_Manual_Exit()) {
  306. AutoRestart.Set_Restart_Flag(false);
  307. }
  308. //
  309. // Shutdown the combat system
  310. //
  311. GameModeManager::Find ("Combat")->Deactivate ();
  312. //
  313. // Let the game mode manager think to cleanup all pending states
  314. //
  315. GameModeManager::Think ();
  316. //
  317. // Shutdown the menu system as necessary
  318. //
  319. if (GameModeManager::Find ("Menu")->Is_Active ()) {
  320. GameModeManager::Find ("Menu")->Deactivate ();
  321. }
  322. // Leave the WWOnline game.
  323. GameModeClass* gameMode = GameModeManager::Find("WOL");
  324. if (gameMode && gameMode->Is_Active()) {
  325. WolGameModeClass* wolGame = static_cast<WolGameModeClass*>(gameMode);
  326. WWASSERT(wolGame != NULL);
  327. wolGame->Leave_Game();
  328. }
  329. if (cNetwork::I_Am_Server()) {
  330. bool is_quick_full_exit_requested = false;
  331. #ifdef WWDEBUG
  332. is_quick_full_exit_requested = cDevOptions::QuickFullExit.Get();
  333. #endif // WWDEBUG
  334. #pragma message("(TSS) ***** Memory leak here - please fix (ST - 6/14/2001 2:06PM) *****")
  335. cSvrGoodbyeEvent * p_event = new cSvrGoodbyeEvent;
  336. p_event->Init(is_quick_full_exit_requested);
  337. }
  338. cNetwork::Flush();
  339. End_Client_Server();
  340. //
  341. // Remove all players
  342. //
  343. cPlayerManager::Remove_All();
  344. cTeamManager::Remove_All();
  345. //
  346. // TSS092301
  347. // Destroy all netobjects !
  348. //
  349. NetworkObjectMgrClass::Set_All_Delete_Pending();
  350. NetworkObjectMgrClass::Delete_Pending();
  351. cGod::Reset();
  352. //
  353. // Unload whatever mod is currently loaded (if necessary)...
  354. //
  355. ModPackageMgrClass::Unload_Current_Mod ();
  356. return ;
  357. }
  358. ////////////////////////////////////////////////////////////////
  359. //
  360. // Continue_Game
  361. //
  362. ////////////////////////////////////////////////////////////////
  363. void
  364. GameInitMgrClass::Continue_Game(void)
  365. {
  366. unsigned long time;
  367. // IML : First, allow a short period to process any outstanding sound effects that may have been started by the caller.
  368. // NOTE: Multi-play does not need this fix because it does not sound page swap.
  369. if (IS_SOLOPLAY) {
  370. time = TIMEGETTIME();
  371. while (TIMEGETTIME() - time < PRE_SERVICE_TIME) {
  372. WWAudioClass::Get_Instance ()->On_Frame_Update (0);
  373. }
  374. }
  375. GameModeManager::Find ("Menu")->Deactivate ();
  376. GameModeManager::Find ("Combat" )->Resume ();
  377. //Force the hud to rebuild, in case weapn chart text changed
  378. HUDClass::Force_Weapon_Chart_Update();
  379. return ;
  380. }
  381. ////////////////////////////////////////////////////////////////
  382. //
  383. // Display_End_Game_Menu
  384. //
  385. ////////////////////////////////////////////////////////////////
  386. void
  387. GameInitMgrClass::Display_End_Game_Menu (void)
  388. {
  389. switch (Mode)
  390. {
  391. //
  392. // Display the main menu
  393. //
  394. default:
  395. case MODE_SP:
  396. case MODE_SKIRMISH:
  397. RenegadeDialogMgrClass::Goto_Location (RenegadeDialogMgrClass::LOC_MAIN_MENU);
  398. break;
  399. //
  400. // Display the LAN main menu
  401. //
  402. case MODE_LAN:
  403. //GAMESPY
  404. if (cGameSpyAdmin::Is_Gamespy_Game()) {
  405. RenegadeDialogMgrClass::Goto_Location (RenegadeDialogMgrClass::LOC_GAMESPY_MAIN);
  406. } else {
  407. RenegadeDialogMgrClass::Goto_Location (RenegadeDialogMgrClass::LOC_LAN_MAIN);
  408. }
  409. break;
  410. //
  411. // Display the WOL main menu
  412. //
  413. case MODE_WOL:
  414. RenegadeDialogMgrClass::Goto_Location ((RenegadeDialogMgrClass::LOCATION)WOLReturnDialog);
  415. break;
  416. }
  417. return ;
  418. }
  419. ////////////////////////////////////////////////////////////////
  420. //
  421. // Transmit_Player_Data
  422. //
  423. ////////////////////////////////////////////////////////////////
  424. void
  425. GameInitMgrClass::Transmit_Player_Data (int teamChoice, unsigned long clanID)
  426. {
  427. WWMEMLOG(MEM_NETWORK);
  428. WWDEBUG_SAY (("GameInitMgrClass::Transmit_Player_Data\n"));
  429. if (Mode == MODE_SP || Mode == MODE_SKIRMISH) {
  430. //
  431. // Send generic team information for the client in a single player game
  432. //
  433. cBioEvent * p_event = new cBioEvent;
  434. p_event->Init(teamChoice, clanID);
  435. } else if (IsClientRequired) {
  436. //
  437. // Send the player's team choice to the server
  438. //
  439. cBioEvent * p_event = new cBioEvent;
  440. p_event->Init(teamChoice, clanID);
  441. }
  442. WWDEBUG_SAY (("GameInitMgrClass::Transmit_Player_Data Done\n"));
  443. return ;
  444. }
  445. ////////////////////////////////////////////////////////////////
  446. //
  447. // Start_Client_Server
  448. //
  449. ////////////////////////////////////////////////////////////////
  450. void
  451. GameInitMgrClass::Start_Client_Server (void)
  452. {
  453. WWDEBUG_SAY (("GameInitMgrClass::Start_Client_Server\n"));
  454. assert(GameModeManager::Find("WOL"));
  455. if (GameModeManager::Find("WOL")->Is_Active()) {
  456. WWASSERT(PTheGameData != NULL);
  457. The_Game()->Set_Port(WOLNATInterface.Get_Port_As_Server());
  458. } else if (GameModeManager::Find("LAN")->Is_Active() && cGameSpyAdmin::Is_Gamespy_Game()) {
  459. WWASSERT(PTheGameData != NULL);
  460. The_Game()->Set_Port(cUserOptions::GameSpyGamePort.Get());
  461. }
  462. #ifdef WWDEBUG
  463. cRemoteHost::Set_Allow_Extra_Modem_Bandwidth_Throttling(cDevOptions::ExtraModemBandwidthThrottling.Get());
  464. #endif //WWDEBUG
  465. //
  466. // Start the server (if necessary)
  467. //
  468. if (IsServerRequired && !cNetwork::I_Am_Server ()) {
  469. cNetwork::Init_Server ();
  470. PacketManager.Set_Is_Server(true);
  471. //
  472. // Dedicated server disables playing of sfx & music
  473. //
  474. if ((IsClientRequired == false) && WWAudioClass::Get_Instance () != NULL) {
  475. if (WWAudioClass::Get_Instance ()->Are_Sound_Effects_On ()) {
  476. WWAudioClass::Get_Instance ()->Allow_Sound_Effects (false);
  477. RestoreSFX = true;
  478. }
  479. if (WWAudioClass::Get_Instance ()->Is_Music_On ()) {
  480. WWAudioClass::Get_Instance ()->Allow_Music (false);
  481. RestoreMusic = true;
  482. }
  483. }
  484. }
  485. //
  486. // Start the client (if necessary)
  487. //
  488. if (IsClientRequired && !cNetwork::I_Am_Client ()) {
  489. if (!IsServerRequired) {
  490. PacketManager.Set_Is_Server(false);
  491. }
  492. assert(GameModeManager::Find("WOL"));
  493. if (GameModeManager::Find("WOL")->Is_Active()) {
  494. cNetwork::Init_Client(WOLNATInterface.Get_Port_As_Server_Client());
  495. } else {
  496. cNetwork::Init_Client();
  497. }
  498. //
  499. // Wait for the client to connect to the server
  500. //
  501. WWDEBUG_SAY(("BEFORE GameInitMgrClass::Start_Client_Server tight update loop\n"));
  502. WWDEBUG_SAY(("Game IP = %s\n", cNetUtil::Address_To_String(The_Game()->Get_Ip_Address())));
  503. unsigned long time = TIMEGETTIME();
  504. do {
  505. cNetwork::Update ();
  506. if (TIMEGETTIME() - time > 20*1000) {
  507. break;
  508. }
  509. } while (!cNetwork::PClientConnection->Is_Established ());
  510. WWDEBUG_SAY(("AFTER GameInitMgrClass::Start_Client_Server tight update loop\n"));
  511. }
  512. // Sample output every 2 seconds.
  513. PacketManager.Set_Stats_Sampling_Frequency_Delay(2000);
  514. return ;
  515. }
  516. ////////////////////////////////////////////////////////////////
  517. //
  518. // End_Client_Server
  519. //
  520. ////////////////////////////////////////////////////////////////
  521. void
  522. GameInitMgrClass::End_Client_Server (void)
  523. {
  524. WWDEBUG_SAY (("GameInitMgrClass::End_Client_Server\n"));
  525. //
  526. // Cleanup the client
  527. //
  528. if (cNetwork::I_Am_Client ()) {
  529. cNetwork::Cleanup_Client ();
  530. }
  531. //
  532. // Cleanup the server
  533. //
  534. if (cNetwork::I_Am_Server ()) {
  535. cNetwork::Cleanup_Server ();
  536. }
  537. return ;
  538. }
  539. ////////////////////////////////////////////////////////////////
  540. //
  541. // Initialize_SP
  542. //
  543. ////////////////////////////////////////////////////////////////
  544. void
  545. GameInitMgrClass::Initialize_SP (void)
  546. {
  547. #ifndef MULTIPLAYERDEMO
  548. WWDEBUG_SAY (("GameInitMgrClass::Initialize_SP\n"));
  549. if (Mode != MODE_UNKNOWN) {
  550. Shutdown ();
  551. }
  552. //
  553. // Notify combat
  554. //
  555. //cSingleData::Set_Is_Single_Player (true);
  556. cGameType::Set_Game_Type(GAMETYPE_MISSION);
  557. //
  558. // Notify wwnet
  559. //
  560. cSinglePlayerData::Init ();
  561. WideStringClass widestring;
  562. widestring.Convert_From("Renegade");
  563. cNetInterface::Set_Nickname(widestring);
  564. //
  565. // Create the new game type
  566. //
  567. WWASSERT (PTheGameData == NULL);
  568. PTheGameData = new cGameDataSinglePlayer;
  569. WWASSERT(PTheGameData != NULL);
  570. //
  571. // Remember our state
  572. //
  573. IsClientRequired = true;
  574. IsServerRequired = true;
  575. Mode = MODE_SP;
  576. return ;
  577. #endif // !MULTIPLAYERDEMO
  578. }
  579. ////////////////////////////////////////////////////////////////
  580. //
  581. // Shutdown_SP
  582. //
  583. ////////////////////////////////////////////////////////////////
  584. void
  585. GameInitMgrClass::Shutdown_SP (void)
  586. {
  587. #ifndef MULTIPLAYERDEMO
  588. WWDEBUG_SAY (("GameInitMgrClass::Shutdown_SP\n"));
  589. //#pragma message ("TSS Fix memory leak here")
  590. //cSingleData::Set_Is_Single_Player(false);
  591. cGameType::Set_Game_Type(GAMETYPE_NONE);
  592. #endif // !MULTIPLAYERDEMO
  593. }
  594. ////////////////////////////////////////////////////////////////
  595. //
  596. // Initialize_Skirmish
  597. //
  598. ////////////////////////////////////////////////////////////////
  599. void
  600. GameInitMgrClass::Initialize_Skirmish(void)
  601. {
  602. #ifndef MULTIPLAYERDEMO
  603. WWDEBUG_SAY(("GameInitMgrClass::Initialize_Skirmish\n"));
  604. if (Mode != MODE_UNKNOWN) {
  605. Shutdown ();
  606. }
  607. //
  608. // Notify combat
  609. //
  610. //cSingleData::Set_Is_Single_Player(true);
  611. cGameType::Set_Game_Type(GAMETYPE_SKIRMISH);
  612. //
  613. // Notify wwnet
  614. //
  615. cSinglePlayerData::Init ();
  616. WideStringClass widestring;
  617. widestring.Convert_From("Renegade");
  618. cNetInterface::Set_Nickname(widestring);
  619. //
  620. // Create the new game type
  621. //
  622. WWASSERT (PTheGameData == NULL);
  623. PTheGameData = new cGameDataSkirmish;
  624. WWASSERT(PTheGameData != NULL);
  625. //
  626. // Remember our state
  627. //
  628. IsClientRequired = true;
  629. IsServerRequired = true;
  630. Mode = MODE_SKIRMISH;
  631. #endif // !MULTIPLAYERDEMO
  632. }
  633. ////////////////////////////////////////////////////////////////
  634. //
  635. // Shutdown_Skirmish
  636. //
  637. ////////////////////////////////////////////////////////////////
  638. void
  639. GameInitMgrClass::Shutdown_Skirmish(void)
  640. {
  641. #ifndef MULTIPLAYERDEMO
  642. WWDEBUG_SAY(("GameInitMgrClass::Shutdown_Skirmish\n"));
  643. //cSingleData::Set_Is_Single_Player(false);
  644. cGameType::Set_Game_Type(GAMETYPE_NONE);
  645. #endif // !MULTIPLAYERDEMO
  646. }
  647. ////////////////////////////////////////////////////////////////
  648. //
  649. // Initialize_LAN
  650. //
  651. ////////////////////////////////////////////////////////////////
  652. void
  653. GameInitMgrClass::Initialize_LAN (void)
  654. {
  655. WWDEBUG_SAY (("GameInitMgrClass::Initialize_LAN\n"));
  656. if (Mode != MODE_UNKNOWN) {
  657. Shutdown ();
  658. }
  659. //cSingleData::Set_Is_Single_Player (false);
  660. cGameType::Set_Game_Type(GAMETYPE_MULTIPLAY);
  661. //
  662. // Activate LAN interface
  663. //
  664. GameModeManager::Find ("LAN")->Activate ();
  665. //
  666. // Remember our state
  667. //
  668. IsClientRequired = false;
  669. IsServerRequired = false;
  670. Mode = MODE_LAN;
  671. return ;
  672. }
  673. ////////////////////////////////////////////////////////////////
  674. //
  675. // Shutdown_LAN
  676. //
  677. ////////////////////////////////////////////////////////////////
  678. void
  679. GameInitMgrClass::Shutdown_LAN (void)
  680. {
  681. WWDEBUG_SAY (("GameInitMgrClass::Shutdown_LAN\n"));
  682. //
  683. // Deactive the LAN interface
  684. //
  685. GameModeManager::Find ("LAN")->Deactivate ();
  686. cGameType::Set_Game_Type(GAMETYPE_NONE);
  687. }
  688. ////////////////////////////////////////////////////////////////
  689. //
  690. // Initialize_WOL
  691. //
  692. ////////////////////////////////////////////////////////////////
  693. void
  694. GameInitMgrClass::Initialize_WOL (void)
  695. {
  696. #ifndef MULTIPLAYERDEMO
  697. WWDEBUG_SAY (("GameInitMgrClass::Initialize_WOL\n"));
  698. if (Mode != MODE_UNKNOWN) {
  699. Shutdown ();
  700. }
  701. //cSingleData::Set_Is_Single_Player (false);
  702. cGameType::Set_Game_Type(GAMETYPE_MULTIPLAY);
  703. //
  704. // Activate WOL interface
  705. //
  706. GameModeManager::Find ("WOL")->Activate ();
  707. //
  708. // Remember our state
  709. //
  710. IsClientRequired = false;
  711. IsServerRequired = false;
  712. Mode = MODE_WOL;
  713. return ;
  714. #endif // !MULTIPLAYERDEMO
  715. }
  716. ////////////////////////////////////////////////////////////////
  717. //
  718. // Shutdown_WOL
  719. //
  720. ////////////////////////////////////////////////////////////////
  721. void
  722. GameInitMgrClass::Shutdown_WOL (void)
  723. {
  724. #ifndef MULTIPLAYERDEMO
  725. WWDEBUG_SAY (("GameInitMgrClass::Shutdown_WOL\n"));
  726. GameModeManager::Find ("WOL")->Deactivate ();
  727. cGameType::Set_Game_Type(GAMETYPE_NONE);
  728. #endif // !MULTIPLAYERDEMO
  729. }
  730. ////////////////////////////////////////////////////////////////
  731. //
  732. // Shutdown
  733. //
  734. ////////////////////////////////////////////////////////////////
  735. void
  736. GameInitMgrClass::Shutdown (void)
  737. {
  738. WWDEBUG_SAY (("GameInitMgrClass::Shutdown\n"));
  739. switch (Mode)
  740. {
  741. case MODE_SP:
  742. Shutdown_SP ();
  743. break;
  744. case MODE_SKIRMISH:
  745. Shutdown_Skirmish ();
  746. break;
  747. case MODE_LAN:
  748. Shutdown_LAN ();
  749. break;
  750. case MODE_WOL:
  751. Shutdown_WOL ();
  752. break;
  753. }
  754. //
  755. // Reset our state
  756. //
  757. IsClientRequired = false;
  758. IsServerRequired = false;
  759. Mode = MODE_UNKNOWN;
  760. End_Client_Server();
  761. if (cSinglePlayerData::Is_Single_Player()) {
  762. //
  763. // This needs to be done after the Cleanup_Client and Cleanup_Server
  764. //
  765. cSinglePlayerData::Cleanup();
  766. }
  767. //
  768. // Free the old game data
  769. //
  770. if (PTheGameData != NULL) {
  771. delete PTheGameData;
  772. PTheGameData = NULL;
  773. }
  774. //
  775. // Reset state
  776. //
  777. IsClientRequired = false;
  778. IsServerRequired = false;
  779. return ;
  780. }
  781. ////////////////////////////////////////////////////////////////
  782. //
  783. // Think
  784. //
  785. ////////////////////////////////////////////////////////////////
  786. void
  787. GameInitMgrClass::Think (void)
  788. {
  789. //
  790. // Safely exit the game and return to the menu (as necessary)
  791. //
  792. if (NeedsGameExit) {
  793. GameInitMgrClass::End_Game ();
  794. GameInitMgrClass::Display_End_Game_Menu ();
  795. NeedsGameExit = false;
  796. }
  797. if (NeedsGameExitAll) {
  798. GameInitMgrClass::End_Game ();
  799. extern void Stop_Main_Loop (int exitCode);
  800. Stop_Main_Loop (EXIT_SUCCESS);
  801. }
  802. return ;
  803. }
  804. void _reload_game_configuration_files(void)
  805. {
  806. //
  807. // (gth) All of this stuff is part of the day 120 Renegade patch and
  808. // is designed to make it possible to change the following systems
  809. // in mods
  810. //
  811. ArmorWarheadManager::Init();
  812. BonesManager::Init();
  813. SurfaceEffectsManager::Init();
  814. #if 0 // re-initting cameras seems to cause problems...
  815. CCameraClass::Init();
  816. #endif
  817. // Reload dazzles
  818. FileClass * dazzle_ini_file = _TheFileFactory->Get_File("DAZZLE.INI");
  819. if (dazzle_ini_file) {
  820. INIClass dazzle_ini(*dazzle_ini_file);
  821. DazzleRenderObjClass::Init_From_INI(&dazzle_ini);
  822. _TheFileFactory->Return_File(dazzle_ini_file);
  823. }
  824. // Reload the strings table
  825. TranslateDBClass::Initialize();
  826. FileClass *file = _TheFileFactory->Get_File( "STRINGS.TDB" );
  827. if (file != NULL) {
  828. file->Open (FileClass::READ); // Open or the file
  829. if ( file->Is_Available() ) {
  830. ChunkLoadClass cload (file); // Load the database
  831. SaveLoadSystemClass::Load(cload);
  832. }
  833. file->Close (); // Close the file
  834. _TheFileFactory->Return_File (file);
  835. }
  836. // Reload scripts.dll
  837. ScriptManager::Destroy_Pending();
  838. ScriptManager::Shutdown();
  839. ScriptManager::Init();
  840. }