combatgmode.cpp 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/combatgmode.cpp $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 2/23/02 2:04p $*
  29. * *
  30. * $Revision:: 267 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "combatgmode.h"
  36. #include "level.h"
  37. #include "input.h"
  38. #include "cnetwork.h"
  39. #include "AudibleSound.H"
  40. #include "debug.h"
  41. #include "registry.h"
  42. #include "_globals.h"
  43. #include "console.h"
  44. #include "radar.h"
  45. #include "spawn.h"
  46. #include "ccamera.h"
  47. #include "scorescreen.h"
  48. #include "devoptions.h"
  49. #include "useroptions.h"
  50. #include "systemsettings.h"
  51. #include "gameobjmanager.h"
  52. #include "building.h"
  53. #include "saveloadstatus.h"
  54. #include "playertype.h"
  55. #include "bitpackids.h"
  56. #include "vehicle.h"
  57. #include "doors.h"
  58. #include "elevator.h"
  59. #include "msgloop.h"
  60. #include "assetmgr.h"
  61. #include "font3d.h"
  62. #include "wwprofile.h"
  63. #include "gametype.h"
  64. #include "messagewindow.h"
  65. #include "objectives.h"
  66. #include "multihud.h"
  67. #include "textureloader.h"
  68. #include "wolgmode.h"
  69. #include "renegadedialogmgr.h"
  70. #include "textdisplay.h"
  71. #include "playermanager.h"
  72. #include "teammanager.h"
  73. #include "consolefunction.h"
  74. #include "overlay.h"
  75. #include "gameinitmgr.h"
  76. #include "campaign.h"
  77. #include "diaglog.h"
  78. #include "god.h"
  79. #include "sbbomanager.h"
  80. #include "savegame.h"
  81. #include "commandosaveload.h"
  82. #include "dlgmpingamechat.h"
  83. #include "loadingevent.h"
  84. #include "cheatmgr.h"
  85. #include "menubackdrop.h"
  86. #include "translatedb.h"
  87. #include "thread.h"
  88. #include "dlgcncteaminfo.h"
  89. #include "dlgcncbattleinfo.h"
  90. #include "bandwidthgraph.h"
  91. #include "suicideevent.h"
  92. #include "assetstatus.h"
  93. #include "stylemgr.h"
  94. #include "gametype.h"
  95. #include "wwmemlog.h"
  96. #include "directinput.h"
  97. #include "cncmodesettings.h"
  98. #include "announceevent.h"
  99. #include "fastallocator.h"
  100. #include "dlgcncserverinfo.h"
  101. #include "radiocommanddisplay.h"
  102. #include "hudinfo.h"
  103. #include "string_ids.h"
  104. #include "radiocommanddisplay.h"
  105. #include "consolemode.h"
  106. #include "specialbuilds.h"
  107. #include <wwlib\realcrc.h>
  108. #include "demosupport.h"
  109. #include "natter.h"
  110. #include "gamespyadmin.h"
  111. #include "dialogtests.h"
  112. #include "dialogmgr.h"
  113. #include "GameSpy_QnR.h"
  114. /*
  115. **
  116. */
  117. extern bool g_is_loading;
  118. bool g_b_core_restart;//TSS081401
  119. bool g_client_quit = false;
  120. AudibleSoundClass * CombatGameModeClass::BackgroundMusic = NULL;
  121. int CombatGameModeClass::IsHudShown = true;
  122. static int ForceGod = false;
  123. static bool ForceGodPending = true;
  124. static int DefaultToFirstPerson = true;
  125. static bool PendingCampaignContinue = false;
  126. /*
  127. **
  128. */
  129. class CombatGameMiscHandlerClass : public CombatMiscHandlerClass {
  130. public:
  131. virtual void Mission_Complete( bool success );
  132. virtual void Star_Killed( void );
  133. };
  134. CombatGameMiscHandlerClass GameMiscHandler;
  135. /*
  136. **
  137. */
  138. static void Combat_To_Menu (RenegadeDialogMgrClass::LOCATION location)
  139. {
  140. //
  141. // Remember: Combat and Menu are not mutually exclusive.
  142. // Therefore this function may be called when menu is already active.
  143. //
  144. if (!GameModeManager::Find("Menu")->Is_Active()) {
  145. //
  146. // Do not suspend Combat in Multiplayer game!
  147. //
  148. if (IS_SOLOPLAY) {
  149. GameModeManager::Find( "Combat" )->Suspend(); // suspend Combat Mode
  150. }
  151. //if (IS_SOLOPLAY) {
  152. if (IS_MISSION) {
  153. RenegadeDialogMgrClass::Goto_Location (location);
  154. } else {
  155. RenegadeDialogMgrClass::Goto_Location (RenegadeDialogMgrClass::LOC_CNC_REFERENCE);
  156. }
  157. }
  158. }
  159. /*
  160. **
  161. */
  162. static void Start_In_Game_Help(void)
  163. {
  164. //
  165. // Remember: Combat and Menu are not mutually exclusive.
  166. // Therefore this function may be called when menu is already active.
  167. //
  168. if (!GameModeManager::Find("Menu")->Is_Active()) {
  169. //
  170. // Do not suspend Combat in Multiplayer game!
  171. //
  172. if (IS_SOLOPLAY) {
  173. GameModeManager::Find( "Combat" )->Suspend(); // suspend Combat Mode
  174. }
  175. RenegadeDialogMgrClass::Goto_Location (RenegadeDialogMgrClass::LOC_IN_GAME_HELP);
  176. }
  177. }
  178. void CombatGameModeClass::Combat_Keyboard( void )
  179. {
  180. WWPROFILE( "Combat_Keyboard" );
  181. #ifdef ATI_DEMO_HACK
  182. // HACK: Make double-ESC exit back to desktop
  183. static unsigned esc_pressed_time=0x7ffff;
  184. if ( Input::Get_State( INPUT_FUNCTION_MENU_TOGGLE ) ) {
  185. unsigned current_time=WW3D::Get_Sync_Time();
  186. if ((current_time-esc_pressed_time)<5000) {
  187. cDevOptions::QuickFullExit.Set(true);
  188. esc_pressed_time=0x7ffff;
  189. }
  190. else {
  191. Get_Text_Display()->Print_System( "Press ESC again to exit to desktop...\n" );
  192. }
  193. esc_pressed_time=current_time;
  194. }
  195. // HACK: In ATI demo toggle the statistics display using TAB
  196. if ( Input::Get_State( INPUT_FUNCTION_EVA_MISSION_OBJECTIVES_TOGGLE ) ) {
  197. if (StatisticsDisplayManager::Is_Current_Display( "fps" )) {
  198. StatisticsDisplayManager::Set_Display( "off" );
  199. }
  200. else {
  201. StatisticsDisplayManager::Set_Display( "fps" );
  202. }
  203. }
  204. #else
  205. bool to_menu=Input::Get_State( INPUT_FUNCTION_MENU_TOGGLE );
  206. // If game doesn't have a focus and combat is active, suspend combat by entering menu
  207. if (!GameInFocus) {
  208. if (IS_SOLOPLAY && COMBAT_CAMERA && !COMBAT_CAMERA->Is_In_Cinematic() ) {
  209. to_menu|=GameModeManager::Find( "Combat" )->Is_Active();
  210. }
  211. }
  212. if ( to_menu ) {
  213. Combat_To_Menu( RenegadeDialogMgrClass::LOC_ENCYCLOPEDIA );
  214. }
  215. //
  216. // Handle the in-game EVA mission objectives window
  217. //
  218. if ( IS_MISSION && Input::Get_State( INPUT_FUNCTION_EVA_MISSION_OBJECTIVES_TOGGLE ) ) {
  219. if ( ObjectiveManager::Is_Viewer_Displayed() ) {
  220. ObjectiveManager::Page_Down_Viewer();
  221. } else {
  222. ObjectiveManager::Display_Viewer( true );
  223. }
  224. }
  225. #endif
  226. if ( Input::Get_State( INPUT_FUNCTION_HELP_SCREEN ) ) {
  227. Start_In_Game_Help();
  228. }
  229. if ( IS_SOLOPLAY && Input::Get_State( INPUT_FUNCTION_EVA_OBJECTIVES_SCREEN ) ) {
  230. Combat_To_Menu( RenegadeDialogMgrClass::LOC_OBJECTIVES );
  231. }
  232. if ( IS_SOLOPLAY && Input::Get_State( INPUT_FUNCTION_EVA_MAP_SCREEN ) ) {
  233. Combat_To_Menu( RenegadeDialogMgrClass::LOC_MAP );
  234. }
  235. //
  236. // Display the server info screen
  237. //
  238. if (!IS_MISSION && Input::Get_State( INPUT_FUNCTION_SERVER_INFO_TOGGLE )) {
  239. START_DIALOG (CNCServerInfoDialogClass);
  240. }
  241. //
  242. // Display the team information page
  243. //
  244. if (!IS_MISSION && cNetwork::I_Am_Client() && COMBAT_STAR != NULL) {
  245. if (Input::Get_State( INPUT_FUNCTION_TEAM_INFO_TOGGLE )) {
  246. START_DIALOG (CNCTeamInfoDialogClass);
  247. } else if (Input::Get_State( INPUT_FUNCTION_BATTLE_INFO_TOGGLE )) {
  248. START_DIALOG (CNCBattleInfoDialogClass);
  249. }/* else if (Input::Get_State( INPUT_FUNCTION_SERVER_INFO_TOGGLE )) {
  250. START_DIALOG (CNCServerInfoDialogClass);
  251. }*/
  252. // Handle radio commands
  253. for (int radioCmdIndex = INPUT_FUNCTION_RADIO_CMD_01; radioCmdIndex <= INPUT_FUNCTION_RADIO_CMD_30; ++radioCmdIndex) {
  254. if (Input::Get_State((InputFunction)radioCmdIndex)) {
  255. CNCModeSettingsDef* cncDef = CNCModeSettingsDef::Get_Instance();
  256. if (cncDef) {
  257. int radioCmdNum = (radioCmdIndex - INPUT_FUNCTION_RADIO_CMD_01);
  258. int radioCmd = cncDef->Get_Radio_Command(radioCmdNum);
  259. if (radioCmd) {
  260. CSAnnouncement* announce = new CSAnnouncement;
  261. assert(announce != NULL);
  262. announce->Init(cNetwork::Get_My_Team_Number(), radioCmd, ANNOUNCEMENT_TEAM, radioCmdNum);
  263. RadioCommandDisplayClass::Reset_Display_Timer();
  264. }
  265. }
  266. break;
  267. }
  268. }
  269. }
  270. if (!IS_MISSION && Input::Get_State( INPUT_FUNCTION_EVA_MISSION_OBJECTIVES_TOGGLE )) {
  271. //MultiHUDClass::Toggle_Verbose_Lists();
  272. MultiHUDClass::Next_Playerlist_Format();
  273. }
  274. #ifdef WWDEBUG
  275. if ( Input::Get_State( INPUT_FUNCTION_QUICK_FULL_EXIT ) ) {
  276. cDevOptions::QuickFullExit.Set(true);
  277. WWDEBUG_SAY(("Quick full exit requested by keypress.\n"));
  278. }
  279. if (cDevOptions::QuickFullExit.Is_True()) {
  280. GameInitMgrClass::End_Game();
  281. GameInitMgrClass::End_Client_Server();
  282. extern void Stop_Main_Loop (int exitCode);
  283. Stop_Main_Loop (EXIT_SUCCESS);
  284. }
  285. #endif
  286. if ( (The_Game() != NULL &&
  287. (Input::Get_State(INPUT_FUNCTION_BEGIN_PUBLIC_MESSAGE) ||
  288. (Input::Get_State(INPUT_FUNCTION_BEGIN_TEAM_MESSAGE) && cNetwork::I_Am_Client()))) &&
  289. !IS_MISSION)
  290. {
  291. MPIngameChatPopupClass * p_dialog = new MPIngameChatPopupClass;
  292. WWASSERT(p_dialog != NULL);
  293. //
  294. // Configure the dialog
  295. //
  296. if (Input::Get_State(INPUT_FUNCTION_BEGIN_PUBLIC_MESSAGE)) {
  297. p_dialog->Set_Default_Type(TEXT_MESSAGE_PUBLIC);
  298. } else {
  299. p_dialog->Set_Default_Type(TEXT_MESSAGE_TEAM);
  300. }
  301. p_dialog->Start_Dialog();
  302. REF_PTR_RELEASE (p_dialog);
  303. }
  304. if ( Input::Get_State( INPUT_FUNCTION_QUICKSAVE )) {
  305. // Only for singeplay
  306. if ( IS_MISSION ) {
  307. Quick_Save();
  308. }
  309. }
  310. }
  311. /*
  312. ** called when the mode is activated
  313. */
  314. void CombatGameModeClass::Init()
  315. {
  316. Debug_Say(("CombatGameModeClass::Init\n"));
  317. if (!IS_MISSION) {
  318. MultiHUDClass::Init();
  319. }
  320. PendingCampaignContinue = false;
  321. //
  322. // Initialize the radio command display window
  323. //
  324. RadioCommandDisplayClass::Initialize ();
  325. //
  326. // Notify combat about the state of the CameraLockedToTurret user option.
  327. //
  328. VehicleGameObj::Set_Camera_Locked_To_Turret(cUserOptions::CameraLockedToTurret.Get());
  329. }
  330. /*
  331. ** called when the mode is deactivated
  332. */
  333. void CombatGameModeClass::Shutdown()
  334. {
  335. Debug_Say(("CombatGameModeClass::Shutdown\n"));
  336. Core_Shutdown();
  337. //
  338. // Shutdown the radio command display window
  339. //
  340. RadioCommandDisplayClass::Shutdown ();
  341. return ;
  342. }
  343. class LoadingScreenClass
  344. {
  345. MenuBackDropClass backdrop;
  346. Render2DSentenceClass backdropText;
  347. Render2DSentenceClass backdropText2; // The BIG text
  348. float LoadTime;
  349. float LoadPercentage;
  350. float LoadPercentageDrawn;
  351. float LoadPercentageClamp;
  352. float LoadPercentageRate;
  353. public:
  354. LoadingScreenClass()
  355. {
  356. int color = 0xFFFFFFFF;
  357. WWMEMLOG(MEM_GAMEDATA);
  358. backdropText.Set_Texture_Size_Hint( 256 );
  359. backdropText2.Set_Texture_Size_Hint( 256 );
  360. LoadTime = 0.001f;
  361. LoadPercentage = 0;
  362. LoadPercentageDrawn = 0;
  363. LoadPercentageRate = 0;
  364. FontCharsClass *font = StyleMgrClass::Peek_Font( StyleMgrClass::FONT_INGAME_TXT );
  365. backdropText.Set_Font( font );
  366. font = StyleMgrClass::Peek_Font( StyleMgrClass::FONT_INGAME_BIG_TXT );
  367. backdropText2.Set_Font( font );
  368. // Parse Descriptions
  369. int count = CampaignManager::Get_Backdrop_Description_Count();
  370. for ( int i = 0; i < count; i++ ) {
  371. const char * read = CampaignManager::Get_Backdrop_Description( i );
  372. // Debug_Say(( "Parse %s\n", read ));
  373. StringClass desc = read;
  374. while ( desc.Get_Length() && desc[0] <= ' ' ) desc.Erase( 0, 1 );
  375. while ( desc.Get_Length() && desc[desc.Get_Length()-1]<=' ' ) desc.Erase(desc.Get_Length()-1, 1 );
  376. // Parse Big Translated Text
  377. if ( ::strnicmp( "Text2", desc, 5 ) == 0 ) {
  378. desc.Erase( 0, 5 );
  379. while ( desc.Get_Length() && desc[0] <= ' ' ) desc.Erase( 0, 1 );
  380. float x,y;
  381. ::sscanf( desc, "%f,%f,", &x, &y );
  382. const char * str = ::strchr( desc, ',' );
  383. if ( str != NULL ) {
  384. str = ::strchr( str+1, ',' );
  385. if ( str != NULL ) {
  386. WideStringClass wide_str = TranslateDBClass::Get_String( str+1 );
  387. backdropText2.Build_Sentence( wide_str );
  388. // Scale
  389. x *= Render2DClass::Get_Screen_Resolution().Right / 640.0f;
  390. y *= Render2DClass::Get_Screen_Resolution().Bottom / 480.0f;
  391. backdropText2.Set_Location( Vector2( (int)x, (int)y ) );
  392. backdropText2.Draw_Sentence( color );
  393. color=0xFFFFFFFF;
  394. backdropText2.Set_Wrapping_Width( 0 );
  395. }
  396. }
  397. }
  398. // Parse Translated Text
  399. if ( ::strnicmp( "Text", desc, 4 ) == 0 ) {
  400. desc.Erase( 0, 4 );
  401. while ( desc.Get_Length() && desc[0] <= ' ' ) desc.Erase( 0, 1 );
  402. float x,y;
  403. ::sscanf( desc, "%f,%f,", &x, &y );
  404. const char * str = ::strchr( desc, ',' );
  405. if ( str != NULL ) {
  406. str = ::strchr( str+1, ',' );
  407. if ( str != NULL ) {
  408. WideStringClass wide_str = TranslateDBClass::Get_String( str+1 );
  409. backdropText.Build_Sentence( wide_str );
  410. // Scale
  411. x *= Render2DClass::Get_Screen_Resolution().Right / 640.0f;
  412. y *= Render2DClass::Get_Screen_Resolution().Bottom / 480.0f;
  413. backdropText.Set_Location( Vector2( (int)x, (int)y ) );
  414. backdropText.Draw_Sentence( color );
  415. color=0xFFFFFFFF;
  416. backdropText.Set_Wrapping_Width( 0 );
  417. }
  418. }
  419. }
  420. // Set Big Wrapping Width
  421. if ( ::strnicmp( "Wrap2", desc, 5 ) == 0 ) {
  422. desc.Erase( 0, 5 );
  423. while ( desc.Get_Length() && desc[0] <= ' ' ) desc.Erase( 0, 1 );
  424. float w;
  425. ::sscanf( desc, "%f,", &w );
  426. // Scale
  427. w *= Render2DClass::Get_Screen_Resolution().Right / 640.0f;
  428. backdropText2.Set_Wrapping_Width( w );
  429. }
  430. // Set Wrapping Width
  431. if ( ::strnicmp( "Wrap", desc, 4 ) == 0 ) {
  432. desc.Erase( 0, 4 );
  433. while ( desc.Get_Length() && desc[0] <= ' ' ) desc.Erase( 0, 1 );
  434. float w;
  435. ::sscanf( desc, "%f,", &w );
  436. // Scale
  437. w *= Render2DClass::Get_Screen_Resolution().Right / 640.0f;
  438. backdropText.Set_Wrapping_Width( w );
  439. }
  440. // Parse test Text
  441. if ( ::strnicmp( "Test", desc, 4 ) == 0 ) {
  442. desc.Erase( 0, 4 );
  443. while ( desc.Get_Length() && desc[0] <= ' ' ) desc.Erase( 0, 1 );
  444. float x,y;
  445. ::sscanf( desc, "%f,%f,", &x, &y );
  446. const char * str = ::strchr( desc, ',' );
  447. if ( str != NULL ) {
  448. str = ::strchr( str+1, ',' );
  449. if ( str != NULL ) {
  450. WideStringClass wide_str;
  451. wide_str.Convert_From( str+1 );
  452. backdropText.Build_Sentence( wide_str );
  453. // Scale
  454. x *= Render2DClass::Get_Screen_Resolution().Right / 640.0f;
  455. y *= Render2DClass::Get_Screen_Resolution().Bottom / 480.0f;
  456. backdropText.Set_Location( Vector2( (int)x, (int)y ) );
  457. backdropText.Draw_Sentence( color );
  458. color=0xFFFFFFFF;
  459. backdropText.Set_Wrapping_Width( 0 );
  460. }
  461. }
  462. }
  463. // Parse back model
  464. if ( ::strnicmp( "Model", desc, 5 ) == 0 ) {
  465. desc.Erase( 0, 5 );
  466. while ( desc.Get_Length() && desc[0] <= ' ' ) desc.Erase( 0, 1 );
  467. backdrop.Set_Model(desc);
  468. StringClass anim_name;
  469. anim_name.Format( "%s.%s", desc, desc );
  470. backdrop.Set_Animation( anim_name );
  471. backdrop.Set_Animation_Percentage( 0 );
  472. }
  473. if ( ::strnicmp( "Color", desc, 5 ) == 0 ) {
  474. desc.Erase( 0, 5 );
  475. while ( desc.Get_Length() && desc[0] <= ' ' ) desc.Erase( 0, 1 );
  476. float r,g,b;
  477. ::sscanf( desc, "%f,%f,%f", &r, &g, &b );
  478. Vector3 c( r/255.0f, g/255.0f, b/255.0f );
  479. color = c.Convert_To_ARGB();
  480. }
  481. }
  482. SaveLoadStatus::Reset_Status_Count();
  483. }
  484. ~LoadingScreenClass()
  485. {
  486. }
  487. float Get_Predicted_Percentage( int state )
  488. {
  489. switch( state )
  490. {
  491. #define TOTAL (18.0f)
  492. case 0: return 0.1f / TOTAL;
  493. case 1: return 0.2f / TOTAL;
  494. case 2: return 0.3f / TOTAL;
  495. case 3: return 0.7f / TOTAL;
  496. case 4: return 3.8f / TOTAL;
  497. case 5: return 15.5f / TOTAL;
  498. case 6: return 17.6f / TOTAL;
  499. default: return 1.0f;
  500. }
  501. }
  502. void Render(bool update_network = false)
  503. {
  504. TimeManager::Update_Frame_Time();
  505. LoadTime += TimeManager::Get_Frame_Seconds();
  506. WW3D::Begin_Render( true, true, Vector3(0.0f,0.0f,0.0f), update_network ? &cNetwork::Update : NULL);
  507. backdrop.Render();
  508. backdropText.Render();
  509. backdropText2.Render();
  510. static int last_count = -1;
  511. static int _last_percent_drawn = -1;
  512. if ( last_count != CombatManager::Get_Load_Progress() ) {
  513. last_count = CombatManager::Get_Load_Progress();
  514. Debug_Say(( " ****** Status Count %d at %f\n", last_count, LoadTime ));
  515. LoadPercentage = Get_Predicted_Percentage( last_count );
  516. LoadPercentageRate = LoadPercentage / LoadTime;
  517. LoadPercentageClamp = Get_Predicted_Percentage( last_count+1 );
  518. }
  519. LoadPercentage += LoadPercentageRate * TimeManager::Get_Frame_Seconds();
  520. LoadPercentage = WWMath::Clamp( LoadPercentage, 0, LoadPercentageClamp );
  521. LoadPercentageDrawn += ( LoadPercentage - LoadPercentageDrawn ) * 0.1f;
  522. backdrop.Set_Animation_Percentage( LoadPercentageDrawn );
  523. if (ConsoleBox.Is_Exclusive() && _last_percent_drawn != LoadPercentageDrawn) {
  524. _last_percent_drawn = LoadPercentageDrawn;
  525. ConsoleBox.Print("Load %d%% complete\r", (int)(LoadPercentageDrawn * 100.0f));
  526. }
  527. #if 0
  528. StringClass txt=SaveLoadStatus::Get_Status_Text(0);
  529. txt=SaveLoadStatus::Get_Status_Text(1);
  530. #endif
  531. WW3D::End_Render();
  532. }
  533. };
  534. #define LOADTIME_NETWORK_UPDATE if (!IS_SOLOPLAY) cNetwork::Update()
  535. /*
  536. **
  537. */
  538. void CombatGameModeClass::Load_Level( void )
  539. {
  540. WWLOG_PREPARE_TIME_AND_MEMORY("CombatGameModeClass::Load_Level");
  541. WWMEMLOG(MEM_GAMEDATA);
  542. Debug_Say(("CombatGameModeClass::Load_Level\n"));
  543. ConsoleBox.Print("Loading level %s\n", The_Game()->Get_Map_Name());
  544. CombatManager::Set_Load_Progress(0);
  545. LoadingScreenClass loading_screen; // Try moving this to very start of loading
  546. loading_screen.Render(true);
  547. // Hack load reg for default first person. Is dont again later.
  548. Load_Registry_Keys();
  549. WWLOG_INTERMEDIATE("Load_REgistry_Keys");
  550. // Flush out current level
  551. INIT_STATUS("Release current level");
  552. LevelManager::Release_Level();
  553. WWLOG_INTERMEDIATE("Releasing old level");
  554. if (!ConsoleBox.Is_Exclusive()) {
  555. WW3D::_Invalidate_Textures();
  556. WWLOG_INTERMEDIATE("WW3D::_Invalidate_Textures()");
  557. AssetStatusClass::Peek_Instance()->Enable_Load_On_Demand_Reporting(false);
  558. }
  559. // LoadingScreenClass loading_screen;
  560. // loading_screen.Render(true);
  561. PendingCampaignContinue = false;
  562. g_is_loading = true;
  563. //
  564. // Stop the network layer from processing packets. This is needed in case a packet import or export accesses the datasafe
  565. // from the main thread while the loader thread is loading stuff into the datasafe. This won't shut off packet acks so no-one
  566. // will be disconnected as a result of this.
  567. //
  568. if (cNetwork::PServerConnection) {
  569. cNetwork::PServerConnection->Allow_Packet_Processing(false);
  570. }
  571. if (!IS_SOLOPLAY && cNetwork::PClientConnection != NULL) {
  572. cNetwork::PClientConnection->Allow_Extra_Timeout_For_Loading();
  573. }
  574. CombatManager::Pre_Load_Level(ConsoleBox.Is_Exclusive() ? false : true);
  575. INIT_STATUS("Apply system settings");
  576. SystemSettings::Apply_All();
  577. CombatManager::Set_Combat_Misc_Handler( &GameMiscHandler );
  578. // Flush out current level
  579. // INIT_STATUS("Release current level");
  580. // LevelManager::Release_Level();
  581. WWASSERT(PTheGameData != NULL);
  582. StringClass map_name(The_Game()->Get_Map_Name(),true);
  583. WWASSERT( !map_name.Is_Empty() );
  584. bool preload_assets = true;
  585. #ifdef WWDEBUG
  586. preload_assets = cDevOptions::PreloadAssets.Get();
  587. #endif
  588. DIAG_LOG(( "LOAD", "%s", map_name ));
  589. NetworkObjectMgrClass::Set_Is_Level_Loading (true);
  590. TextureLoader::Suspend_Texture_Load();
  591. CombatManager::Load_Level_Threaded( map_name, preload_assets );
  592. WWLOG_INTERMEDIATE("Level load preprocessing");
  593. while (!CombatManager::Is_Load_Level_Complete() ) {
  594. loading_screen.Render(true);
  595. Windows_Message_Handler();
  596. LOADTIME_NETWORK_UPDATE;
  597. ThreadClass::Sleep_Ms(50);
  598. }
  599. WWLOG_INTERMEDIATE("Threaded level load");
  600. GenericDataSafeClass::Set_Preferred_Thread(GetCurrentThreadId());
  601. TextureLoader::Continue_Texture_Load();
  602. WWLOG_INTERMEDIATE("TextureLoader::Continue_Texture_Load()");
  603. LOADTIME_NETWORK_UPDATE;
  604. // Post load processing ----------------------------------------------------
  605. INIT_STATUS("Post_Load_Processing");
  606. loading_screen.Render(true);
  607. Windows_Message_Handler();
  608. SaveLoadSystemClass::Post_Load_Processing(IS_SOLOPLAY ? NULL : &cNetwork::Update);
  609. NetworkObjectMgrClass::Set_Is_Level_Loading (false);
  610. WWLOG_INTERMEDIATE("SaveLoadSystemClass::Post_Load_Processing(&cNetwork::Update)");
  611. INIT_STATUS("Post_Load_Level");
  612. loading_screen.Render(true);
  613. Windows_Message_Handler();
  614. LOADTIME_NETWORK_UPDATE;
  615. CombatManager::Post_Load_Level();
  616. WWLOG_INTERMEDIATE("CombatManager::Post_Load_Level()");
  617. INIT_STATUS("Post_Load_Id_Uniqueness_Check");
  618. loading_screen.Render(true);
  619. Windows_Message_Handler();
  620. LOADTIME_NETWORK_UPDATE;
  621. Post_Load_Id_Uniqueness_Check();
  622. WWLOG_INTERMEDIATE("Post_Load_Id_Uniqueness_Check()");
  623. INIT_STATUS("Post_Load_Dynamic_Object_Filtering");
  624. loading_screen.Render(true);
  625. Windows_Message_Handler();
  626. LOADTIME_NETWORK_UPDATE;
  627. Post_Load_Dynamic_Object_Filtering();
  628. WWLOG_INTERMEDIATE("Post_Load_Dynamic_Object_Filtering()");
  629. // Spawn point validation --------------------------------------------------
  630. INIT_STATUS("Spawn_Point_Validation");
  631. loading_screen.Render(true);
  632. Windows_Message_Handler();
  633. LOADTIME_NETWORK_UPDATE;
  634. Spawn_Point_Validation();
  635. WWLOG_INTERMEDIATE("Spawn_Point_Validation()");
  636. // -------------------------------------------------------------------------
  637. //DefinitionMgrClass::List_Available_Definitions();
  638. INIT_STATUS("Compute world size");
  639. Compute_World_Size();
  640. WWLOG_INTERMEDIATE("Compute_World_Size()");
  641. //
  642. // Set precision for other stuff
  643. // This stuff should be placed elsewhere... when there are a few
  644. // more of them.
  645. //
  646. ControlClass::Set_Precision();
  647. //SoldierGameObj::Set_Precision();
  648. HumanStateClass::Set_Precision();
  649. VehicleGameObj::Set_Precision();
  650. DoorPhysClass::Set_Precision();
  651. ElevatorPhysClass::Set_Precision();
  652. DefenseObjectClass::Set_Precision();
  653. BuildingGameObj::Set_Precision();
  654. // Override background color if this is a dedicated server
  655. if (cNetwork::I_Am_Only_Server()) {
  656. GameModeManager::Set_Background_Color( Vector3( 0.0f, 0.0f, 0.4f ) );
  657. }
  658. INIT_STATUS("Registry keys");
  659. Load_Registry_Keys();
  660. Save_Registry_Keys();
  661. WWLOG_INTERMEDIATE("SaveLoadRegistry");
  662. // Radar init --------------------------------------------------------------
  663. INIT_STATUS("Init radar class"); // Init the radar after the game is loaded (so we have the global settings
  664. loading_screen.Render(true);
  665. Windows_Message_Handler();
  666. LOADTIME_NETWORK_UPDATE;
  667. RadarManager::Init();
  668. WWASSERT(PTheGameData != NULL);
  669. RadarManager::Set_Radar_Mode(The_Game()->Get_Radar_Mode());
  670. WWLOG_INTERMEDIATE("Init Radar");
  671. // -------------------------------------------------------------------------
  672. const bool is_reloaded = true;
  673. The_Game()->Reset_Game(is_reloaded);
  674. WWLOG_INTERMEDIATE("The_Game()->Reset_Game(is_reloaded)");
  675. // Buildings init ----------------------------------------------------------
  676. // After the level loads, the buildings collect all of their components
  677. INIT_STATUS("Init_Buildings");
  678. loading_screen.Render(true);
  679. Windows_Message_Handler();
  680. LOADTIME_NETWORK_UPDATE;
  681. GameObjManager::Init_Buildings();
  682. WWLOG_INTERMEDIATE("GameObjManager::Init_Buildings()");
  683. // -------------------------------------------------------------------------
  684. // Update texture loader ---------------------------------------------------
  685. // This is needed here as we want to apply all textures that may have changed
  686. // during the game loading before the game actually starts.
  687. INIT_STATUS("Init_Textures");
  688. loading_screen.Render(true);
  689. Windows_Message_Handler();
  690. LOADTIME_NETWORK_UPDATE;
  691. TextureLoader::Update(IS_SOLOPLAY ? NULL : &cNetwork::Update);
  692. WWLOG_INTERMEDIATE("TextureLoader::Update(&cNetwork::Update)");
  693. // -------------------------------------------------------------------------
  694. // Notify the game of "game start"
  695. WWASSERT(PTheGameData != NULL);
  696. The_Game()->On_Game_Begin();
  697. WWLOG_INTERMEDIATE("The_Game()->On_Game_Begin()");
  698. ForceGodPending = ForceGod != 0;
  699. /* if ( GameModeManager::Find( "Overlay3D" ) ) {
  700. ((Overlay3DGameModeClass*)GameModeManager::Find( "Overlay3D" ))->Start_Intro();
  701. }
  702. */
  703. LOADTIME_NETWORK_UPDATE;
  704. AssetStatusClass::Peek_Instance()->Enable_Load_On_Demand_Reporting(true);
  705. g_is_loading = false;
  706. ConsoleBox.Print("Load %d%% complete\n", 100);
  707. ConsoleBox.Print("Level loaded OK\n");
  708. GameSpyQnR.Init();
  709. //
  710. // Re-enable packet processing.
  711. //
  712. if (cNetwork::PServerConnection) {
  713. cNetwork::PServerConnection->Allow_Packet_Processing(true);
  714. }
  715. if (!ConsoleBox.Is_Exclusive()) {
  716. unsigned ffheap=FastAllocatorGeneral::Get_Allocator()->Get_Total_Heap_Size();
  717. unsigned ffuse=FastAllocatorGeneral::Get_Allocator()->Get_Total_Allocated_Size();
  718. unsigned actualuse=FastAllocatorGeneral::Get_Allocator()->Get_Total_Actual_Memory_Usage();
  719. unsigned count=FastAllocatorGeneral::Get_Allocator()->Get_Total_Allocation_Count();
  720. StringClass working_string(0,true);
  721. working_string.Format(
  722. "\nMalloc count: %d\n"
  723. "Free count: %d\n"
  724. "FF Heap: %d.%3.3d.%3.3d (%d Mb)\n"
  725. "FF Use: %d.%3.3d.%3.3d (%d Mb)\n"
  726. "Actual Use: %d.%3.3d.%3.3d (%d Mb)\n"
  727. "FF Count: %d\n"
  728. ,
  729. WW3D::Get_Last_Frame_Memory_Allocation_Count(),
  730. WW3D::Get_Last_Frame_Memory_Free_Count(),
  731. ffheap/(1000*1000),(ffheap/1000)%1000,ffheap%1000, ffheap/(1024*1024),
  732. ffuse/(1000*1000),(ffuse/10000)%1000,ffuse%1000, ffuse/(1024*1024),
  733. actualuse/(1000*1000),(actualuse/1000)%1000,actualuse%1000, actualuse/(1024*1024),
  734. count);
  735. WWDEBUG_SAY((working_string));
  736. }
  737. }
  738. void CombatGameModeClass::Core_Shutdown()
  739. {
  740. Debug_Say(("CombatGameModeClass::Core_Shutdown\n"));
  741. //
  742. // Switch to the in-game sound page to ensure all those sounds get freed
  743. // as we're shutting down the level.
  744. //
  745. WWAudioClass::Get_Instance ()->Push_Active_Sound_Page (WWAudioClass::PAGE_PRIMARY);
  746. MultiHUDClass::Shutdown();
  747. //cPlayerManager::Shutdown();
  748. //cTeamManager::Shutdown();
  749. // Shutdown the sound library
  750. if (BackgroundMusic != NULL) {
  751. BackgroundMusic->Stop ();
  752. BackgroundMusic->Release_Ref ();
  753. BackgroundMusic = NULL;
  754. }
  755. if (IS_MISSION) {
  756. //
  757. // Keep the GOD manager from offering a respawn when the star is gone
  758. //
  759. cGod::Exit();
  760. }
  761. CombatManager::Unload_Level();
  762. LevelManager::Release_Level();
  763. RadarManager::Shutdown();
  764. //
  765. // Restore the current sound page
  766. //
  767. WWAudioClass::Get_Instance ()->Pop_Active_Sound_Page ();
  768. }
  769. //-----------------------------------------------------------------------------
  770. void CombatGameModeClass::Post_Load_Id_Uniqueness_Check(void)
  771. {
  772. bool list_ids = false;
  773. //
  774. // Make sure no 2 phys objects have the same id.
  775. //
  776. // Debug_Say(("Testing id uniqueness for physical objects:\n"));
  777. int phys_obj_count = 0;
  778. SLNode<BaseGameObj> * objnode;
  779. for (objnode = GameObjManager::Get_Game_Obj_List()->Head(); objnode; objnode = objnode->Next()) {
  780. WWASSERT(objnode->Data() != NULL);
  781. PhysicalGameObj * p_phys_obj = objnode->Data()->As_PhysicalGameObj();
  782. if (p_phys_obj != NULL) {
  783. phys_obj_count++;
  784. if (list_ids) {
  785. Debug_Say((" Object %d, model %s\n",
  786. p_phys_obj->Get_ID(),
  787. p_phys_obj->Peek_Model()->Get_Name()));
  788. }
  789. SLNode<BaseGameObj> * objnode2;
  790. for (objnode2 = GameObjManager::Get_Game_Obj_List()->Head(); objnode2; objnode2 = objnode2->Next()) {
  791. WWASSERT(objnode2->Data() != NULL);
  792. PhysicalGameObj * p_phys_obj_2 = objnode2->Data()->As_PhysicalGameObj();
  793. if (p_phys_obj_2 != NULL &&
  794. p_phys_obj_2->Get_ID() == p_phys_obj->Get_ID()) {
  795. //WWASSERT(p_phys_obj_2 == p_phys_obj);
  796. if (p_phys_obj_2 != p_phys_obj) {
  797. Debug_Say(("Level file error: Two phys objects found with id %d.\n",
  798. p_phys_obj_2->Get_ID()));
  799. DIE;
  800. }
  801. }
  802. }
  803. }
  804. }
  805. // Debug_Say((" %d unique physical objects were loaded.\n", phys_obj_count));
  806. //
  807. // Make sure no 2 static objects have the same id.
  808. //
  809. // Debug_Say(("Testing id uniqueness for static objects:\n"));
  810. WWASSERT(COMBAT_SCENE != NULL);
  811. int static_obj_count = 0;
  812. RefPhysListIterator iter_1 = COMBAT_SCENE->Get_Static_Object_Iterator();
  813. for (iter_1.First(); !iter_1.Is_Done(); iter_1.Next()) {
  814. //StaticPhysClass * p_obj_1 = (StaticPhysClass *) iter_1.Peek_Obj();
  815. PhysClass * p_obj_1 = iter_1.Peek_Obj();
  816. WWASSERT(p_obj_1 != NULL);
  817. int object_id_1 = p_obj_1->Get_ID();
  818. static_obj_count++;
  819. if (list_ids) {
  820. //Debug_Say((" Object %d\n", object_id_1));
  821. Debug_Say((" Object %d, model %s\n",
  822. p_obj_1->Get_ID(),
  823. p_obj_1->Peek_Model()->Get_Name()));
  824. }
  825. RefPhysListIterator iter_2 = COMBAT_SCENE->Get_Static_Object_Iterator();
  826. for (iter_2.First(); !iter_2.Is_Done(); iter_2.Next()) {
  827. //StaticPhysClass * p_obj_2 = (StaticPhysClass *) iter_2.Peek_Obj();
  828. PhysClass * p_obj_2 = iter_2.Peek_Obj();
  829. WWASSERT(p_obj_2 != NULL);
  830. int object_id_2 = p_obj_2->Get_ID();
  831. //
  832. //
  833. // DO NOT DISABLE THIS
  834. //
  835. //
  836. if (object_id_1 == object_id_2 && p_obj_1 != p_obj_2) {
  837. Debug_Say(("Fatal level file error: Two static objects found with id %d.\n",
  838. object_id_1));
  839. DIE;
  840. }
  841. }
  842. }
  843. // Debug_Say((" %d unique static objects were loaded.\n", static_obj_count));
  844. }
  845. //-----------------------------------------------------------------------------
  846. void CombatGameModeClass::Post_Load_Dynamic_Object_Filtering(void)
  847. {
  848. //
  849. // Look through the soldiers and remove any that aren't
  850. // appropriate for this particular game type.
  851. //
  852. //
  853. // Any commando's that are tagged as having human players must be removed.
  854. // The player id field is not valid...
  855. // The exception is the commando belonging to the first player.
  856. //
  857. // Remove any soldiers with invalid player types for this game.
  858. //
  859. // Remove any grunts unless this is a mission.
  860. //
  861. WWASSERT(PTheGameData != NULL);
  862. SLNode<SmartGameObj> * objnode;
  863. for (objnode = GameObjManager::Get_Smart_Game_Obj_List()->Head(); objnode; objnode = objnode->Next()) {
  864. SmartGameObj * p_smart_obj = objnode->Data();
  865. WWASSERT(p_smart_obj != NULL);
  866. if (p_smart_obj->As_SoldierGameObj() != NULL) {
  867. if (p_smart_obj->Has_Player() && (p_smart_obj->Get_Control_Owner() > 1 ||
  868. (!cNetwork::I_Am_Client()))) {
  869. Debug_Say(("* Removing loaded soldier belonging to another player.\n"));
  870. p_smart_obj->Set_Delete_Pending();
  871. }
  872. if (!p_smart_obj->Is_Delete_Pending() &&
  873. !The_Game()->Is_Valid_Player_Type(p_smart_obj->Get_Player_Type())) {
  874. Debug_Say(("* Removing loaded soldier due to invalid playertype for this game.\n"));
  875. p_smart_obj->Set_Delete_Pending();
  876. }
  877. if (!p_smart_obj->Is_Delete_Pending() && !p_smart_obj->Has_Player() &&
  878. !IS_SOLOPLAY) {
  879. Debug_Say(("* Removing loaded soldier grunt in non-mission game (id = %d).\n",
  880. p_smart_obj->Get_ID()));
  881. p_smart_obj->Set_Delete_Pending();
  882. }
  883. }
  884. }
  885. }
  886. //-----------------------------------------------------------------------------
  887. void CombatGameModeClass::Compute_World_Size(void)
  888. {
  889. //
  890. // Tell networking system about the size of the world, to be used
  891. // in filtering.
  892. //
  893. Vector3 min;
  894. Vector3 max;
  895. WWASSERT(PhysicsSceneClass::Get_Instance() != NULL);
  896. PhysicsSceneClass::Get_Instance()->Get_Level_Extents(min, max);
  897. //Debug_Say(("World extends from (%5.2f, %5.2f, %5.2f) to (%5.2f, %5.2f, %5.2f)\n",
  898. // min.X, min.Y, min.Z, max.X, max.Y, max.Z));
  899. Vector3 longest_distance = max - min;
  900. //Debug_Say(("Longest distance is %5.2fm\n", longest_distance.Length()));
  901. WWASSERT(PTheGameData != NULL);
  902. The_Game()->Set_Maximum_World_Distance(longest_distance.Length());
  903. double margin = 1; // comfort zone
  904. //
  905. // Also, set encoding precision for positional information
  906. //
  907. cEncoderList::Set_Precision(BITPACK_WORLD_POSITION_X,
  908. min.X - margin, max.X + margin, 0.2);
  909. cEncoderList::Set_Precision(BITPACK_WORLD_POSITION_Y,
  910. min.Y - margin, max.Y + margin, 0.2);
  911. cEncoderList::Set_Precision(BITPACK_WORLD_POSITION_Z,
  912. min.Z - margin, max.Z + margin, 0.2);
  913. cEncoderList::Set_Precision(BITPACK_BUILDING_RADIUS,
  914. 0.0, 50.0, 0.1);
  915. }
  916. //-----------------------------------------------------------------------------
  917. #define ADD_CASE(exp) case exp: return #exp; break;
  918. static LPCSTR Playertype_To_String(int player_type)
  919. {
  920. switch (player_type) {
  921. ADD_CASE(PLAYERTYPE_MUTANT);
  922. ADD_CASE(PLAYERTYPE_NEUTRAL);
  923. ADD_CASE(PLAYERTYPE_RENEGADE);
  924. ADD_CASE(PLAYERTYPE_NOD);
  925. ADD_CASE(PLAYERTYPE_GDI);
  926. default:
  927. DIE;
  928. return "ERROR"; // to avoid compiler warning
  929. }
  930. }
  931. //-----------------------------------------------------------------------------
  932. void CombatGameModeClass::Spawn_Point_Validation(void)
  933. {
  934. if (cNetwork::I_Am_Server()) {
  935. bool is_spawners_valid = true;
  936. for (int spawn_type = PLAYERTYPE_RENEGADE; spawn_type <= PLAYERTYPE_LAST; spawn_type++) {
  937. if ( !SpawnManager::Spawner_Exists( spawn_type ) ) {
  938. Debug_Say((" Error: No spawn point(s) of type %s found.\n",
  939. Playertype_To_String(spawn_type)));
  940. is_spawners_valid = false;
  941. } else {
  942. Debug_Say((" Spawn point(s) of type %s found.\n",
  943. Playertype_To_String(spawn_type)));
  944. }
  945. }
  946. if (!IS_SOLOPLAY) {
  947. WWASSERT(is_spawners_valid);
  948. }
  949. }
  950. }
  951. //-----------------------------------------------------------------------------
  952. void CombatGameModeClass::Core_Restart(void)
  953. {
  954. Debug_Say(("CombatGameModeClass::Core_Restart\n"));
  955. Core_Shutdown();
  956. GameModeManager::Safely_Deactivate();
  957. INIT_STATUS("Reloading...");
  958. if ( IS_MISSION ) {
  959. #ifndef MULTIPLAYERDEMO
  960. StringClass new_name;
  961. WWASSERT(PTheGameData != NULL);
  962. new_name = CombatManager::Get_Last_LSD_Name();
  963. // convert .LSD to .MIX
  964. if ( new_name.Get_Length() > 4 &&
  965. ::stricmp( &new_name[new_name.Get_Length() - 4], ".LSD" ) == 0 ) {
  966. new_name.Erase( new_name.Get_Length() - 4, 4 );
  967. new_name += ".MIX";
  968. }
  969. The_Game()->Set_Map_Name( new_name );
  970. #endif // !MULTIPLAYERDEMO
  971. } else {
  972. //
  973. // Reset the timer system if we are a dedicated server and there is no-one in the game.
  974. // ST - 1/30/2002 12:44PM
  975. //
  976. if (The_Game() && The_Game()->IsDedicated.Is_True()) {
  977. if (cNetwork::PServerConnection && cNetwork::PServerConnection->Get_Num_RHosts() == 0) {
  978. GameModeClass *game_mode = GameModeManager::Find("LAN");
  979. //
  980. // Don't do this if the NAT thread is busy since it uses timers extensively.
  981. //
  982. if ((game_mode && game_mode->Is_Active()) || WOLNATInterface.Is_NAT_Thread_Busy() == false) {
  983. //
  984. // Danger! Danger!
  985. // This could cause code that uses time deltas to fail. Hopefully there isn't any code doing that right now.
  986. //
  987. SystemTime.Reset();
  988. TimeManager::Reset();
  989. GenericDataSafeClass::Reset_Timers();
  990. GameModeClass* game_mode = GameModeManager::Find("WOL");
  991. if (game_mode && game_mode->Is_Active()) {
  992. WolGameModeClass* wol_game = reinterpret_cast<WolGameModeClass*>(game_mode);
  993. wol_game->System_Timer_Reset();
  994. }
  995. }
  996. }
  997. }
  998. }
  999. //
  1000. // Reset packet optimizer bandwidth stats.
  1001. //
  1002. PacketManager.Reset_Stats();
  1003. Load_Level();
  1004. #ifdef WW3D_COMPILE_WITH_DX8__
  1005. DX8MeshRendererContainerClass::Invalidate_All();
  1006. #endif
  1007. }
  1008. //-----------------------------------------------------------------------------
  1009. /*
  1010. **
  1011. */
  1012. void CombatGameModeClass::Load_Registry_Keys(void)
  1013. {
  1014. RegistryClass * registry = new RegistryClass( APPLICATION_SUB_KEY_NAME_OPTIONS );
  1015. WWASSERT( registry );
  1016. if ( registry->Is_Valid() ) {
  1017. IsHudShown = registry->Get_Int( "IsHudShown", IsHudShown );
  1018. ForceGod = registry->Get_Int( "ForceGod", ForceGod );
  1019. //TSS
  1020. DefaultToFirstPerson = registry->Get_Int( "DefaultToFirstPerson", DefaultToFirstPerson );
  1021. CombatManager::Set_First_Person_Default(DefaultToFirstPerson == TRUE);
  1022. }
  1023. delete registry;
  1024. }
  1025. void CombatGameModeClass::Save_Registry_Keys(void)
  1026. {
  1027. RegistryClass * registry = new RegistryClass( APPLICATION_SUB_KEY_NAME_OPTIONS );
  1028. WWASSERT( registry );
  1029. if ( registry->Is_Valid() ) {
  1030. registry->Set_Int( "IsHudShown", IsHudShown );
  1031. registry->Set_Int( "ForceGod", ForceGod );
  1032. //TSS
  1033. DefaultToFirstPerson = CombatManager::Get_First_Person_Default();
  1034. registry->Set_Int( "DefaultToFirstPerson", DefaultToFirstPerson );
  1035. }
  1036. delete registry;
  1037. }
  1038. /*
  1039. ** called each time through the main loop when active
  1040. */
  1041. void CombatGameModeClass::Think()
  1042. {
  1043. WWPROFILE( "Combat Think" );
  1044. if ( !Is_Active() ) {
  1045. return;
  1046. }
  1047. Combat_Keyboard();
  1048. //
  1049. // Test again to see if we are active, because quick exit may inactivate us.
  1050. //
  1051. if ( !Is_Active() ) {
  1052. return;
  1053. }
  1054. CombatManager::Generate_Control();
  1055. //
  1056. // Network Update needs to be between input and think
  1057. //
  1058. float time_1;
  1059. {
  1060. WWMeasureItClass net_upd_time_s(&time_1);
  1061. cNetwork::Update();
  1062. }
  1063. float time_2;
  1064. {
  1065. WWMeasureItClass combat_think_time_s(&time_2);
  1066. CombatManager::Think();
  1067. }
  1068. if (cNetwork::I_Am_Server())
  1069. {
  1070. WWPROFILE( "cSbboManager stuff" );
  1071. cSbboManager::Increment_Accum_Time_S_Net_Update(time_1);
  1072. cSbboManager::Increment_Accum_Time_S_Combat_Think(time_2);
  1073. cSbboManager::Think();
  1074. }
  1075. DEMO_SECURITY_CHECK;
  1076. if ( COMBAT_STAR ) {
  1077. WWPROFILE( "Stuff 1" );
  1078. Vector3 pos;
  1079. COMBAT_STAR->Get_Position( &pos );
  1080. float facing = COMBAT_STAR->Get_Facing();
  1081. Get_Console()->Set_Player_Position( pos, facing );
  1082. if ( ForceGodPending ) {
  1083. ForceGodPending = false;
  1084. ConsoleFunctionManager::Parse_Input( "God" );
  1085. }
  1086. }
  1087. MultiHUDClass::Think();
  1088. cPlayerManager::Think();
  1089. cTeamManager::Think();
  1090. if ( PendingCampaignContinue ) {
  1091. WWPROFILE( "Stuff 2" );
  1092. PendingCampaignContinue = false;
  1093. Debug_Say(( "Handle Pending Campaign Continue\n" ));
  1094. CampaignManager::Continue();
  1095. }
  1096. #ifdef MULTIPLAYERDEMO
  1097. //
  1098. // Security check. Randomly every few minutes, check to see if a special
  1099. // MP demo object (id 100277) exists. If it doesn't, assume someone has hacked in
  1100. // a different map. Bail.
  1101. //
  1102. if ((::rand() % 10131 == 939) && (NetworkObjectMgrClass::Find_Object(100277) == NULL)) {
  1103. WWDEBUG_SAY(("MP DEMO OBJECT NOT FOUND... BAILING.\n"));
  1104. Suspend();
  1105. GameInitMgrClass::End_Game();
  1106. extern void Stop_Main_Loop (int);
  1107. Stop_Main_Loop(EXIT_SUCCESS);
  1108. }
  1109. #endif // MULTIPLAYERDEMO
  1110. if (g_b_core_restart) {
  1111. WWPROFILE( "g_b_core_restart" );
  1112. g_b_core_restart = false;
  1113. //Core_Restart();
  1114. cPlayer * p_me = cNetwork::Get_My_Player_Object();
  1115. if (p_me != NULL) {// && cNetwork::I_Am_Only_Client()) {
  1116. p_me->Set_Is_In_Game(false);
  1117. cLoadingEvent * p_loading_1 = new cLoadingEvent;
  1118. p_loading_1->Init(true);
  1119. Core_Restart();
  1120. p_me->Set_Is_In_Game(true);
  1121. cLoadingEvent * p_loading_2 = new cLoadingEvent;
  1122. p_loading_2->Init(false);
  1123. } else {
  1124. Core_Restart();
  1125. }
  1126. if (!IS_MISSION) {
  1127. MultiHUDClass::Init();
  1128. }
  1129. cNetwork::Enable_Waiting_Players();
  1130. /*
  1131. #if(0)
  1132. WWDEBUG_SAY(("****** CombatGameModeClass::Think On_Game_Begin()\n"));
  1133. WWASSERT(The_Game() != NULL);
  1134. // The_Game()->On_Game_End();
  1135. The_Game()->Reset_Game(false);
  1136. The_Game()->On_Game_Begin();//TSS091201
  1137. #endif
  1138. */
  1139. }
  1140. // Autosave, after one run throught main loop
  1141. if ( CombatManager::Is_Autosave_Requested() ) {
  1142. WWPROFILE( "Autosaving" );
  1143. Debug_Say(( "Autosaving\n" ));
  1144. int time=TIMEGETTIME();
  1145. CombatManager::Request_Autosave( false );
  1146. SaveGameManager::Set_Description( TRANSLATE( IDS_SAVE_AUTOSAVE ) );
  1147. SaveGameManager::Save_Game( "save\\autosave.sav", &_CommandoSaveLoad, NULL );
  1148. time=TIMEGETTIME()-time;
  1149. Debug_Say(( "Autosaving Complete, took %d.%2.2d seconds\n",time/1000,(time/10)%100 ));
  1150. }
  1151. //TSS090401
  1152. if (g_client_quit)
  1153. {
  1154. WWPROFILE( "g_client_quit" );
  1155. //
  1156. // This becomes true when the connection to the server breaks
  1157. //
  1158. g_client_quit = false;
  1159. Suspend();
  1160. GameInitMgrClass::End_Game();
  1161. //GAMESPY
  1162. if (cGameSpyAdmin::Get_Is_Launched_From_Gamespy())
  1163. {
  1164. #ifdef MULTIPLAYERDEMO
  1165. DialogMgrClass::Flush_Dialogs ();
  1166. START_DIALOG (SplashOutroMenuDialogClass);
  1167. #else
  1168. extern void Stop_Main_Loop (int);
  1169. Stop_Main_Loop(EXIT_SUCCESS);
  1170. #endif // MULTIPLAYERDEMO
  1171. }
  1172. else
  1173. {
  1174. GameInitMgrClass::Display_End_Game_Menu();
  1175. }
  1176. }
  1177. }
  1178. void CombatGameModeClass::Render()
  1179. {
  1180. if ( !Is_Active() ) {
  1181. return;
  1182. }
  1183. if (cNetwork::I_Am_Client()) {
  1184. /*
  1185. ** In multi-play, only render the combatmanager when we have a valid camera and the menu is not active
  1186. */
  1187. bool menu_active = false;
  1188. GameModeClass * menu_mode = GameModeManager::Find( "Menu" ); // Activate the main menu
  1189. if ((menu_mode != NULL) && (menu_mode->Get_State() == GAME_MODE_ACTIVE)) {
  1190. menu_active = true;
  1191. }
  1192. if ( COMBAT_CAMERA && COMBAT_CAMERA->Is_Valid() && (menu_active == false)) {
  1193. CombatManager::Render();
  1194. }
  1195. }
  1196. MultiHUDClass::Render();
  1197. cBandwidthGraph::Render();
  1198. cPlayerManager::Render();
  1199. cTeamManager::Render();
  1200. WWASSERT(PTheGameData != NULL);
  1201. The_Game()->Render();
  1202. RadioCommandDisplayClass::Render ();
  1203. }
  1204. //-----------------------------------------------------------------------------
  1205. void CombatGameModeClass::Toggle_Multi_Hud(void)
  1206. {
  1207. MultiHUDClass::Toggle();
  1208. }
  1209. // --------------------------------------------------------------
  1210. void CombatGameMiscHandlerClass::Mission_Complete( bool success )
  1211. {
  1212. if (IS_MISSION) {
  1213. if ( success ) {
  1214. PendingCampaignContinue = true;
  1215. } else {
  1216. cGod::Mission_Failed();
  1217. }
  1218. #if 0
  1219. GameModeManager::Find("Combat")->Suspend();
  1220. // GameModeManager::Find("Combat")->Deactivate();
  1221. // GameModeManager::Find("ScoreScreen")->Activate();
  1222. // ((ScoreScreenGameModeClass*)GameModeManager::Find("ScoreScreen"))->Set_Success( success );
  1223. if ( GameModeManager::Find( "Overlay3D" ) ) {
  1224. ((Overlay3DGameModeClass*)GameModeManager::Find( "Overlay3D" ))->Start_End_Screen();
  1225. }
  1226. #endif
  1227. }
  1228. }
  1229. void CombatGameMiscHandlerClass::Star_Killed( void )
  1230. {
  1231. cGod::Star_Killed();
  1232. }
  1233. void CombatGameModeClass::Resume(void)
  1234. {
  1235. //
  1236. // Show the message window (if necessary)
  1237. //
  1238. if ( CombatManager::Get_Message_Window () != NULL &&
  1239. CombatManager::Get_Message_Window ()->Has_Data ())
  1240. {
  1241. CombatManager::Get_Message_Window ()->Force_Display (true);
  1242. }
  1243. GameMajorModeClass::Resume();
  1244. return ;
  1245. }
  1246. void CombatGameModeClass::Suspend(void)
  1247. {
  1248. //
  1249. // Hide the message window
  1250. //
  1251. if (CombatManager::Get_Message_Window () != NULL) {
  1252. CombatManager::Get_Message_Window ()->Force_Display (false);
  1253. }
  1254. //
  1255. // Hide the objective viewer
  1256. //
  1257. ObjectiveManager::Display_Viewer (false);
  1258. GameMajorModeClass::Suspend();
  1259. return ;
  1260. }
  1261. /*
  1262. **
  1263. */
  1264. void CombatGameModeClass::Quick_Save( void )
  1265. {
  1266. bool saveA = true;
  1267. RegistryClass * registry = new RegistryClass( APPLICATION_SUB_KEY_NAME_OPTIONS );
  1268. WWASSERT( registry );
  1269. if ( registry->Is_Valid() ) {
  1270. saveA = registry->Get_Bool( "QuicksaveA", saveA );
  1271. }
  1272. #define SAVEGAME_NAME_A "save\\quicksaveA.sav"
  1273. #define SAVEGAME_NAME_B "save\\quicksaveB.sav"
  1274. // Check for a missing file
  1275. if ( !cMiscUtil::File_Exists(SAVEGAME_NAME_B) ) {
  1276. saveA = false;
  1277. }
  1278. if ( !cMiscUtil::File_Exists(SAVEGAME_NAME_A) ) {
  1279. saveA = true;
  1280. }
  1281. if ( saveA ) {
  1282. SaveGameManager::Set_Description( TRANSLATE(IDS_SAVE_QUICKSAVE_A) );
  1283. SaveGameManager::Save_Game( SAVEGAME_NAME_A, &_CommandoSaveLoad, NULL );
  1284. Debug_Say(( "Quicksaved A\n" ));
  1285. } else {
  1286. SaveGameManager::Set_Description( TRANSLATE(IDS_SAVE_QUICKSAVE_B) );
  1287. SaveGameManager::Save_Game( SAVEGAME_NAME_B, &_CommandoSaveLoad, NULL );
  1288. Debug_Say(( "Quicksaved B\n" ));
  1289. }
  1290. saveA = !saveA;
  1291. if ( registry->Is_Valid() ) {
  1292. registry->Set_Bool( "QuicksaveA", saveA );
  1293. }
  1294. delete registry;
  1295. // Display "Quick Saved"
  1296. HUDInfo::Set_HUD_Help_Text( TRANSLATE( IDS_M00DSGN_DSGN1017I1DSGN_TXT ), Vector3( 0,1,0 ) );
  1297. }
  1298. /**/
  1299. /*
  1300. if (::rand() % 10131 == 939)) {
  1301. bool bail = true;
  1302. ScriptableGameObj * p_obj = GameObjManager::Find_ScriptableGameObj(100277);
  1303. if (p_obj != NULL && p_obj->Get_Definition().Get_Name()) {
  1304. bail = false;
  1305. }
  1306. if (bail) {
  1307. Suspend();
  1308. GameInitMgrClass::End_Game();
  1309. extern void Stop_Main_Loop (int);
  1310. Stop_Main_Loop(EXIT_SUCCESS);
  1311. }
  1312. }
  1313. */