MechCmd2.cpp 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688
  1. //--------------------------------------------------------------------------
  2. //
  3. // And away we go. MechCommander 2 -- Electric Boogaloo
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. //-----------------------------------
  9. // Include Files
  10. #ifndef MCLIB_H
  11. #include "mclib.h"
  12. #endif
  13. #ifndef MISSION_H
  14. #include "mission.h"
  15. #endif
  16. #ifndef UNITDESG_H
  17. #include "unitdesg.h"
  18. #endif
  19. #ifndef LOGISTICS_H
  20. #include "logistics.h"
  21. #endif
  22. #ifndef GAMESOUND_H
  23. #include "gamesound.h"
  24. #endif
  25. #ifndef SOUNDS_H
  26. #include "sounds.h"
  27. #endif
  28. #ifndef MULTPLYR_H
  29. #include "multplyr.h"
  30. #endif
  31. #ifndef TEAM_H
  32. #include "team.h"
  33. #endif
  34. #ifndef VERSION_H
  35. #include "version.h"
  36. #endif
  37. #ifndef TURRET_H
  38. #include "turret.h"
  39. #endif
  40. #ifndef OPTIONSSCREENWRAPPER_H
  41. #include "OptionsScreenWrapper.h"
  42. #endif
  43. #ifndef GAMELOG_H
  44. #include "gamelog.h"
  45. #endif
  46. #ifndef LOGISTICSDIALOG_H
  47. #include "LogisticsDialog.h"
  48. #endif'
  49. #ifndef PREFS_H
  50. #include "prefs.h"
  51. #endif
  52. extern CPrefs prefs;
  53. #include "..\resource.h"
  54. #include <GameOS.hpp>
  55. #include <ToolOS.hpp>
  56. #include <Stuff\stuff.hpp>
  57. #include <MLR\MLR.hpp>
  58. #include <GosFX\gosfxheaders.hpp>
  59. //------------------------------------------------------------------------------------------------------------
  60. // MechCmdr2 Global Instances of Things
  61. UserHeapPtr systemHeap = NULL;
  62. UserHeapPtr guiHeap = NULL;
  63. FastFile **fastFiles = NULL;
  64. long numFastFiles = 0;
  65. long maxFastFiles = 0;
  66. long GameDifficulty = 0;
  67. long gammaLevel = 0;
  68. extern long DigitalMasterVolume;
  69. extern long MusicVolume;
  70. extern long sfxVolume;
  71. extern long RadioVolume;
  72. extern long BettyVolume;
  73. long resolution = 0;
  74. long renderer = 0;
  75. long FilterState = gos_FilterNone;
  76. bool quitGame = FALSE;
  77. bool justStartMission = FALSE;
  78. bool gamePaused = FALSE;
  79. bool hasGuardBand = false;
  80. bool canMultiTextureDetail = false;
  81. bool useUnlimitedAmmo = true;
  82. bool useLeftRightMouseProfile = true; // if false, use old style commands
  83. bool justResaveAllMaps = false;
  84. extern bool useWaterInterestTexture;
  85. extern bool useShadows;
  86. extern bool aborted;
  87. bool gotBombData = false;
  88. TimerManagerPtr timerManager = NULL;
  89. bool initGameLogs = false;
  90. bool initNetLog = false;
  91. GameLog* NetLog = NULL;
  92. bool initCombatLog = false;
  93. GameLog* CombatLog = NULL;
  94. bool initBugLog = false;
  95. GameLog* BugLog = NULL;
  96. bool initLRMoveLog = false;
  97. bool KillAmbientLight = false;
  98. void InitDW (void);
  99. extern DWORD NumDevices;
  100. unsigned long elementHeapSize = 1024000;
  101. unsigned long maxElements = 2048;
  102. unsigned long maxGroups = 1024;
  103. unsigned long systemHeapSize = 8192000;
  104. unsigned long guiHeapSize = 1023999;
  105. unsigned long logisticsHeapSize = 4095999;
  106. unsigned long missionHeapSize = 3072000;
  107. unsigned long spriteDataHeapSize = 2048000;
  108. unsigned long spriteHeapSize = 8192000;
  109. unsigned long polyHeapSize = 1024000;
  110. extern float ProcessorSpeed;
  111. void __stdcall ExitGameOS();
  112. DWORD gosResourceHandle = 0;
  113. HGOSFONT3D gosFontHandle = 0;
  114. float gosFontScale = 1.0;
  115. extern HGOSFONT3D FontHandle;
  116. FloatHelpPtr globalFloatHelp = NULL;
  117. unsigned long currentFloatHelp = 0;
  118. float MaxMinUV = 8.0f;
  119. DWORD BaseVertexColor = 0x00000000; //This color is applied to all vertices in game as Brightness correction.
  120. enum { CPU_UNKNOWN, CPU_PENTIUM, CPU_MMX, CPU_KATMAI } Processor = CPU_PENTIUM; //Needs to be set when GameOS supports ProcessorID -- MECHCMDR2
  121. extern float frameRate;
  122. void EnterWindowMode();
  123. extern long MaxMoveGoalChecks;
  124. extern bool useSound;
  125. extern bool useMusic;
  126. long MaxResourcePoints = -1;
  127. bool ShowMovers = false;
  128. bool EnemiesGoalPlan = false;
  129. bool inViewMode = false;
  130. extern bool CullPathAreas;
  131. unsigned long viewObject = 0x0;
  132. char missionName[1024];
  133. extern char FileMissingString[];
  134. extern char CDMissingString[];
  135. extern char MissingTitleString[];
  136. char* ExceptionGameMsg = NULL;
  137. char buildNumber[80];
  138. extern long TERRAIN_TXM_SIZE;
  139. long ObjectTextureSize = 128;
  140. extern unsigned long MultiPlayCommanderId;
  141. extern bool useRealLOS;
  142. bool reloadBounds = false;
  143. extern long DrawDebugCells;
  144. extern long GameVisibleVertices;
  145. bool EULAShown = false;
  146. SoundSystem* sndSystem;
  147. extern bool gNoDialogs;
  148. //DEBUG
  149. #define MAX_SHAPES 0
  150. TG_MultiShape testShape[36];
  151. TG_AnimateShape testAnim[36];
  152. Stuff::Vector3D pos[36] =
  153. {
  154. Stuff::Vector3D(-3400.0f,3000.0f,-1.0f),
  155. Stuff::Vector3D(-3300.0f,2700.0f,-1.0f),
  156. Stuff::Vector3D(-3300.0f,2800.0f,-1.0f),
  157. Stuff::Vector3D(-3300.0f,2900.0f,-1.0f),
  158. Stuff::Vector3D(-3300.0f,3000.0f,-1.0f),
  159. Stuff::Vector3D(-3200.0f,2700.0f,-1.0f),
  160. Stuff::Vector3D(-3200.0f,2800.0f,-1.0f),
  161. Stuff::Vector3D(-3200.0f,2900.0f,-1.0f),
  162. Stuff::Vector3D(-3200.0f,3000.0f,-1.0f),
  163. Stuff::Vector3D(-3100.0f,2700.0f,-1.0f),
  164. Stuff::Vector3D(-3100.0f,2800.0f,-1.0f),
  165. Stuff::Vector3D(-3100.0f,2900.0f,-1.0f),
  166. Stuff::Vector3D(-3100.0f,3000.0f,-1.0f),
  167. Stuff::Vector3D(-3000.0f,2700.0f,-1.0f),
  168. Stuff::Vector3D(-3000.0f,2800.0f,-1.0f),
  169. Stuff::Vector3D(-3000.0f,2900.0f,-1.0f),
  170. Stuff::Vector3D(-3000.0f,3000.0f,-1.0f),
  171. Stuff::Vector3D(-2900.0f,2700.0f,-1.0f),
  172. Stuff::Vector3D(-2900.0f,2800.0f,-1.0f),
  173. Stuff::Vector3D(-2900.0f,2900.0f,-1.0f),
  174. Stuff::Vector3D(-2900.0f,3000.0f,-1.0f),
  175. Stuff::Vector3D(-2800.0f,2700.0f,-1.0f),
  176. Stuff::Vector3D(-2800.0f,2800.0f,-1.0f),
  177. Stuff::Vector3D(-2800.0f,2900.0f,-1.0f),
  178. Stuff::Vector3D(-2800.0f,3000.0f,-1.0f),
  179. Stuff::Vector3D(-2700.0f,2700.0f,-1.0f),
  180. Stuff::Vector3D(-2700.0f,2800.0f,-1.0f),
  181. Stuff::Vector3D(-2700.0f,2900.0f,-1.0f),
  182. Stuff::Vector3D(-2700.0f,3000.0f,-1.0f),
  183. Stuff::Vector3D(-2600.0f,2700.0f,-1.0f),
  184. Stuff::Vector3D(-2600.0f,2800.0f,-1.0f),
  185. Stuff::Vector3D(-2600.0f,2900.0f,-1.0f),
  186. Stuff::Vector3D(-2600.0f,3000.0f,-1.0f),
  187. Stuff::Vector3D(-2500.0f,2700.0f,-1.0f),
  188. Stuff::Vector3D(-2500.0f,2800.0f,-1.0f),
  189. Stuff::Vector3D(-2500.0f,2900.0f,-1.0f)
  190. };
  191. #ifdef LAB_ONLY
  192. long currentLineElement = 0;
  193. LineElement *debugLines[10000];
  194. #define ProfileTime(x,y) x=GetCycles();y;x=GetCycles()-x;
  195. extern __int64 MCTimeMultiplayerUpdate;
  196. #else
  197. #define ProfileTime(x,y) y;
  198. #endif
  199. #define MAX_KILL_AT_START 100
  200. long NumDisableAtStart = 0;
  201. long DisableAtStart[MAX_KILL_AT_START];
  202. OptionsScreenWrapper *optionsScreenWrapper = NULL;
  203. bool bInvokeOptionsScreenFlag = false;
  204. bool SnifferMode = false;
  205. gos_VERTEX *testVertex = NULL;
  206. WORD *indexArray = NULL;
  207. DWORD testTextureHandle = 0xffffffff;
  208. float totalTime = 0;
  209. DWORD numIterations = 4;
  210. DWORD curIteration = 0;
  211. DWORD curDevice = 0;
  212. bool isUsingSoftware = false;
  213. #define MAX_HARDWARE_CARDS 5
  214. float trisPerSecond[MAX_HARDWARE_CARDS] =
  215. {
  216. 0.0f, 0.0f, 0.0f, 0.0f, 0.0f
  217. };
  218. extern bool loadInMissionSave;
  219. extern char CDInstallPath[];
  220. extern float averageFrameRate;
  221. extern long currentFrameNum;
  222. extern float last30Frames[];
  223. extern bool WindowsNT;
  224. extern EString *g_textureCache_FilenameOfLastLoadedTexture;
  225. bool checkedBomb = false;
  226. //***************************************************************************
  227. // DEBUGGING WINDOWS
  228. //***************************************************************************
  229. #define NUM_DEBUG_WINDOWS 4
  230. char DebugStatusBarString[256];
  231. GameDebugWindow* DebugWindow[NUM_DEBUG_WINDOWS] = {NULL, NULL, NULL, NULL};
  232. GameObjectPtr DebugGameObject[3] = {NULL, NULL, NULL};
  233. long GameObjectWindowList[3] = {0, 0, 0};
  234. long NumGameObjectsToDisplay = 0;
  235. bool DebugWindowOpen[NUM_DEBUG_WINDOWS] = {false, false, false, false};
  236. bool DebugStatusBarOpen = false;
  237. bool DebugScoreBoardOpen = false;
  238. bool DebugHelpOpen = false;
  239. void DEBUGWINS_print (char* s, long window = 0);
  240. //---------------------------------------------------------------------------
  241. void DEBUGWINS_init (void) {
  242. sprintf(DebugStatusBarString, "DEBUG Status Bar: GLENNBA");
  243. DebugWindow[0] = new GameDebugWindow;
  244. DebugWindow[0]->init();
  245. DebugWindow[0]->setPos(10, 200);
  246. if (DebugWindowOpen[0])
  247. DebugWindow[0]->open();
  248. else
  249. DebugWindow[0]->close();
  250. DebugWindow[1] = new GameDebugWindow;
  251. DebugWindow[1]->init();
  252. DebugWindow[1]->setPos(10, 20);
  253. if (DebugWindowOpen[1])
  254. DebugWindow[1]->open();
  255. else
  256. DebugWindow[1]->close();
  257. DebugWindow[2] = new GameDebugWindow;
  258. DebugWindow[2]->init();
  259. DebugWindow[2]->setPos(220, 20);
  260. if (DebugWindowOpen[2])
  261. DebugWindow[2]->open();
  262. else
  263. DebugWindow[2]->close();
  264. DebugWindow[3] = new GameDebugWindow;
  265. DebugWindow[3]->init();
  266. DebugWindow[3]->setPos(430, 20);
  267. if (DebugWindowOpen[3])
  268. DebugWindow[3]->open();
  269. else
  270. DebugWindow[3]->close();
  271. }
  272. //---------------------------------------------------------------------------
  273. void DEBUGWINS_destroy (void) {
  274. for (long i = 0; i < NUM_DEBUG_WINDOWS; i++)
  275. if (DebugWindow[i]) {
  276. DebugWindow[i]->destroy();
  277. delete DebugWindow[i];
  278. DebugWindow[i] = NULL;
  279. }
  280. }
  281. void initDialogs()
  282. {
  283. FullPathFileName path;
  284. path.init( artPath, "mcl_dialog", ".fit" );
  285. FitIniFile file;
  286. if ( NO_ERR != file.open( path ) )
  287. {
  288. char error[256];
  289. sprintf( error, "couldn't open file %s", (char*)path );
  290. Assert( 0, 0, error );
  291. return;
  292. }
  293. LogisticsOKDialog::init( file );
  294. file.close();
  295. path.init( artPath, "mcl_sm", ".fit" );
  296. if ( NO_ERR != file.open( path ) )
  297. {
  298. char error[256];
  299. sprintf( error, "couldn't open file %s", (char*)path );
  300. Assert( 0, 0, error );
  301. return;
  302. }
  303. LogisticsSaveDialog::init( file );
  304. file.close();
  305. path.init( artPath, "mcl_dialog_onebutton", ".fit" );
  306. if ( NO_ERR != file.open( path ) )
  307. {
  308. char error[256];
  309. sprintf( error, "couldn't open file %s", (char*)path );
  310. Assert( 0, 0, error );
  311. return;
  312. }
  313. LogisticsOneButtonDialog::init( file );
  314. }
  315. void endDialogs()
  316. {
  317. if (LogisticsOKDialog::s_instance)
  318. {
  319. delete LogisticsOKDialog::s_instance;
  320. LogisticsOKDialog::s_instance = NULL;
  321. }
  322. if (LogisticsSaveDialog::s_instance)
  323. {
  324. delete LogisticsSaveDialog::s_instance;
  325. LogisticsSaveDialog::s_instance = NULL;
  326. }
  327. if (LogisticsOneButtonDialog::s_instance)
  328. {
  329. delete LogisticsOneButtonDialog::s_instance;
  330. LogisticsOneButtonDialog::s_instance = NULL;
  331. }
  332. if (LogisticsLegalDialog::s_instance)
  333. {
  334. delete LogisticsLegalDialog::s_instance;
  335. LogisticsLegalDialog::s_instance = NULL;
  336. }
  337. }
  338. //---------------------------------------------------------------------------
  339. void DEBUGWINS_toggle (bool* windowsOpen) {
  340. for (long i = 0; i < NUM_DEBUG_WINDOWS; i++)
  341. if (windowsOpen[i])
  342. DebugWindow[i]->toggle();
  343. DebugHelpOpen = windowsOpen[NUM_DEBUG_WINDOWS];
  344. DebugStatusBarOpen = windowsOpen[NUM_DEBUG_WINDOWS + 1];
  345. DebugScoreBoardOpen = windowsOpen[NUM_DEBUG_WINDOWS + 2];
  346. }
  347. //---------------------------------------------------------------------------
  348. void DEBUGWINS_display (bool* windowsOpen) {
  349. for (long i = 0; i < NUM_DEBUG_WINDOWS; i++) {
  350. if (windowsOpen[i]) {
  351. DebugWindowOpen[i] = true;
  352. DebugWindow[i]->open();
  353. }
  354. else {
  355. DebugWindowOpen[i] = false;
  356. DebugWindow[i]->close();
  357. }
  358. }
  359. DebugHelpOpen = windowsOpen[NUM_DEBUG_WINDOWS];
  360. DebugStatusBarOpen = windowsOpen[NUM_DEBUG_WINDOWS + 1];
  361. DebugScoreBoardOpen = windowsOpen[NUM_DEBUG_WINDOWS + 2];
  362. }
  363. //---------------------------------------------------------------------------
  364. void DEBUGWINS_print (char* s, long window) {
  365. DebugWindow[window]->print(s);
  366. }
  367. //---------------------------------------------------------------------------
  368. void DEBUGWINS_setGameObject (long debugObj, GameObjectPtr obj) {
  369. if (debugObj == -1) {
  370. DebugGameObject[2] = DebugGameObject[1];
  371. DebugGameObject[1] = DebugGameObject[0];
  372. debugObj = 0;
  373. }
  374. DebugGameObject[debugObj] = obj;
  375. }
  376. //---------------------------------------------------------------------------
  377. void DEBUGWINS_viewGameObject (long debugObj) {
  378. if (DebugGameObject[debugObj]) {
  379. Stuff::Vector3D newPos = DebugGameObject[debugObj]->getPosition();
  380. eye->setPosition(newPos,false);
  381. }
  382. }
  383. //---------------------------------------------------------------------------
  384. void DEBUGWINS_removeGameObject (GameObjectPtr obj) {
  385. for (long i = 0; i < 3; i++)
  386. if (DebugGameObject[i] == obj) {
  387. DebugGameObject[i] = NULL;
  388. DebugWindow[1 + i]->clear();
  389. }
  390. }
  391. //---------------------------------------------------------------------------
  392. void DEBUGWINS_update (void) {
  393. for (long i = 0; i < 3; i++)
  394. if (DebugGameObject[i])
  395. DebugGameObject[i]->updateDebugWindow(DebugWindow[1 + i]);
  396. }
  397. //---------------------------------------------------------------------------
  398. void DEBUGWINS_renderSpecialWindows (void) {
  399. gos_TextSetAttributes(DebugWindow[0]->font, 0xffffffff, 1.0, true, true, false, false);
  400. gos_TextSetRegion(0, 0, Environment.screenWidth, Environment.screenHeight );
  401. gos_TextSetPosition(15, 10);
  402. if (DebugStatusBarOpen && DebugStatusBarString[0])
  403. gos_TextDraw(DebugStatusBarString);
  404. if (DebugScoreBoardOpen) {
  405. if (MPlayer) {
  406. long curY = Environment.screenHeight - 390;
  407. for (long i = 0; i < MPlayer->numTeams; i++) {
  408. char s[256];
  409. sprintf(s, "Team %d score = %d", i, MPlayer->teamScore[i]);
  410. gos_TextSetPosition(Environment.screenWidth - 380, curY);
  411. gos_TextDraw(s);
  412. curY += 10;
  413. }
  414. curY += 10;
  415. for (i = 0; i < MAX_MC_PLAYERS; i++)
  416. if (MPlayer->playerInfo[i].commanderID > -1) {
  417. char s[256];
  418. sprintf(s, "Player %d (%s) score = %d, %d kills, %d losses",
  419. i,
  420. MPlayer->playerInfo[i].name,
  421. MPlayer->playerInfo[i].score,
  422. MPlayer->playerInfo[i].kills,
  423. MPlayer->playerInfo[i].losses);
  424. gos_TextSetPosition(Environment.screenWidth - 380, curY);
  425. gos_TextDraw(s);
  426. curY += 10;
  427. }
  428. }
  429. else {
  430. gos_TextSetPosition(Environment.screenWidth - 275, Environment.screenHeight - 120);
  431. gos_TextDraw("Single-player Mission");
  432. }
  433. }
  434. if (DebugHelpOpen) {
  435. gos_TextSetPosition(15, 10);
  436. gos_TextDraw("DEBUGGING COMMANDS");
  437. gos_TextSetPosition(15, 20);
  438. gos_TextDraw("----------------------------------------------------------------------------");
  439. gos_TextSetPosition(15, 30);
  440. gos_TextDraw("ALT-W");
  441. gos_TextSetPosition(140, 30);
  442. gos_TextDraw("Toggle Debug Windows");
  443. gos_TextSetPosition(15, 40);
  444. gos_TextDraw("ALT-T");
  445. gos_TextSetPosition(140, 40);
  446. gos_TextDraw("Teleport to mouse");
  447. gos_TextSetPosition(15, 50);
  448. gos_TextDraw("ALT-/");
  449. gos_TextSetPosition(140, 50);
  450. gos_TextDraw("Quick Info");
  451. gos_TextSetPosition(15, 60);
  452. gos_TextDraw("ALT-SHFT-/");
  453. gos_TextSetPosition(140, 60);
  454. gos_TextDraw("Select Debug Object");
  455. gos_TextSetPosition(15, 70);
  456. gos_TextDraw("ALT-#");
  457. gos_TextSetPosition(140, 70);
  458. gos_TextDraw("Center on Debug Object # (1 thru 3)");
  459. gos_TextSetPosition(15, 80);
  460. gos_TextDraw("ALT-CTRL-#");
  461. gos_TextSetPosition(140, 80);
  462. gos_TextDraw("Toggle Info for Debug Object (1 thru 3)");
  463. gos_TextSetPosition(15, 90);
  464. gos_TextDraw("ALT-M");
  465. gos_TextSetPosition(140, 90);
  466. gos_TextDraw("Show All Movers (toggle)");
  467. gos_TextSetPosition(15, 100);
  468. gos_TextDraw("ALT-G");
  469. gos_TextSetPosition(140, 100);
  470. gos_TextDraw("GlobalMap Move Log (toggle)");
  471. gos_TextSetPosition(15, 110);
  472. gos_TextDraw("ALT-B");
  473. gos_TextSetPosition(140, 110);
  474. gos_TextDraw("Enemies Brain Dead (toggle)");
  475. gos_TextSetPosition(15, 120);
  476. gos_TextDraw("ALT-P");
  477. gos_TextSetPosition(140, 120);
  478. gos_TextDraw("Use Goal Planning (toggle on selected movers)");
  479. gos_TextSetPosition(15, 130);
  480. gos_TextDraw("ALT-CTRL-P");
  481. gos_TextSetPosition(140, 130);
  482. gos_TextDraw("Computer AI Use Goal Planning (toggle)");
  483. gos_TextSetPosition(15, 140);
  484. gos_TextDraw("ALT-4");
  485. gos_TextSetPosition(140, 140);
  486. gos_TextDraw("Damage Object for 1 point");
  487. gos_TextSetPosition(15, 150);
  488. gos_TextDraw("ALT-5");
  489. gos_TextSetPosition(140, 150);
  490. gos_TextDraw("Damage Object for 4 points");
  491. gos_TextSetPosition(15, 160);
  492. gos_TextDraw("ALT-6");
  493. gos_TextSetPosition(140, 160);
  494. gos_TextDraw("Damage Object for 9 points");
  495. gos_TextSetPosition(15, 170);
  496. gos_TextDraw("ALT-7");
  497. gos_TextSetPosition(140, 170);
  498. gos_TextDraw("Damage Object for 16 points");
  499. gos_TextSetPosition(15, 180);
  500. gos_TextDraw("ALT-8");
  501. gos_TextSetPosition(140, 180);
  502. gos_TextDraw("Damage Object for 25 points");
  503. gos_TextSetPosition(15, 190);
  504. gos_TextDraw("ALT-9");
  505. gos_TextSetPosition(140, 190);
  506. gos_TextDraw("Damage Object for 36 points");
  507. gos_TextSetPosition(15, 200);
  508. gos_TextDraw("ALT-0");
  509. gos_TextSetPosition(140, 200);
  510. gos_TextDraw("Disable Object");
  511. gos_TextSetPosition(15, 210);
  512. gos_TextDraw("ALT-V");
  513. gos_TextSetPosition(140, 210);
  514. gos_TextDraw("Display TacOrder Target in Debug Window");
  515. }
  516. }
  517. //---------------------------------------------------------------------------
  518. void DEBUGWINS_render (void) {
  519. for (long i = 0; i < NUM_DEBUG_WINDOWS; i++)
  520. DebugWindow[i]->render();
  521. DEBUGWINS_renderSpecialWindows();
  522. }
  523. //***************************************************************************
  524. char* GetGameInformation()
  525. {
  526. return(ExceptionGameMsg);
  527. }
  528. //long cLoadString (HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax );
  529. #define SnifferTime(x,y)
  530. DWORD startTime;
  531. DWORD endTime;
  532. //---------------------------------------------------------------------------
  533. void UpdateRenderers()
  534. {
  535. if (!SnifferMode)
  536. {
  537. hasGuardBand = true;
  538. //hasGuardBand = gos_GetMachineInformation(gos_Info_HasGuardBandClipping) != 0;
  539. canMultiTextureDetail = (gos_GetMachineInformation(gos_Info_CanMultitextureDetail) != 0);
  540. //---------------------------------------------------------------------------------
  541. //Doesn't work. Always returns 0 for TNT in Win2K build 2183 with 3.55 detonator
  542. //Assume worst case is +/- 8.0 for now.
  543. //MaxMinUV = gos_GetMachineInformation(gos_Info_GetMaximumUVSize);
  544. DWORD bColor = 0x0;
  545. if (eye && mission->isActive())
  546. bColor = eye->fogColor;
  547. gos_SetupViewport(1,1.0,1,bColor, 0.0, 0.0, 1.0, 1.0 ); //ALWAYS FULL SCREEN for now
  548. gos_SetRenderState( gos_State_Filter, gos_FilterBiLinear );
  549. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha );
  550. gos_SetRenderState( gos_State_AlphaTest, TRUE );
  551. gos_SetRenderState( gos_State_Clipping, TRUE);
  552. gos_SetRenderState( gos_State_TextureAddress, gos_TextureClamp );
  553. gos_SetRenderState( gos_State_Dither, 1);
  554. //---------------------------------------------------------------------------------------
  555. // Tell the mission to render, the operation to render and the logistics to render here.
  556. if (mission && (!optionsScreenWrapper || optionsScreenWrapper->isDone() ) )
  557. mission->render();
  558. if (logistics)
  559. {
  560. float viewMulX, viewMulY, viewAddX, viewAddY;
  561. gos_GetViewport(&viewMulX, &viewMulY, &viewAddX, &viewAddY);
  562. userInput->setViewport(viewMulX,viewMulY,viewAddX,viewAddY);
  563. logistics->render();
  564. }
  565. if (optionsScreenWrapper && !optionsScreenWrapper->isDone() )
  566. {
  567. float viewMulX, viewMulY, viewAddX, viewAddY;
  568. gos_GetViewport(&viewMulX, &viewMulY, &viewAddX, &viewAddY);
  569. userInput->setViewport(viewMulX,viewMulY,viewAddX,viewAddY);
  570. optionsScreenWrapper->render();
  571. }
  572. //------------------------------------------------------------
  573. gos_SetRenderState( gos_State_Filter, gos_FilterNone );
  574. userInput->render();
  575. DEBUGWINS_render();
  576. #ifdef LAB_ONLY
  577. if (currentLineElement)
  578. {
  579. for (long i=0;i<currentLineElement;i++)
  580. {
  581. debugLines[i]->draw();
  582. }
  583. }
  584. #endif
  585. }
  586. else
  587. {
  588. if (gos_GetMachineInformation(gos_Info_GetDeviceLocalMemory, curDevice) >= 6291456)
  589. {
  590. startTime=timeGetTime();
  591. gos_SetupViewport(1,1.0,1,0, 0.0, 0.0, 1.0, 1.0 ); //ALWAYS FULL SCREEN for now
  592. if (Environment.Renderer == 3)
  593. {
  594. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_OneZero);
  595. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  596. gos_SetRenderState( gos_State_MonoEnable, 1);
  597. gos_SetRenderState( gos_State_Perspective, 0);
  598. gos_SetRenderState( gos_State_Clipping, 2);
  599. gos_SetRenderState( gos_State_AlphaTest, 0);
  600. gos_SetRenderState( gos_State_Specular, 0);
  601. gos_SetRenderState( gos_State_Dither, 0);
  602. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulate);
  603. gos_SetRenderState( gos_State_Filter, gos_FilterBiLinear);
  604. gos_SetRenderState( gos_State_TextureAddress, gos_TextureWrap);
  605. gos_SetRenderState( gos_State_ZCompare, 1);
  606. gos_SetRenderState( gos_State_ZWrite, 1);
  607. //DWORD fogColor = 0x009f9f9f;
  608. //gos_SetRenderState( gos_State_Fog, (int)&fogColor);
  609. }
  610. else
  611. {
  612. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha);
  613. gos_SetRenderState( gos_State_ShadeMode, gos_ShadeGouraud);
  614. gos_SetRenderState( gos_State_MonoEnable, 1);
  615. gos_SetRenderState( gos_State_Perspective, 1);
  616. gos_SetRenderState( gos_State_Clipping, 2);
  617. gos_SetRenderState( gos_State_AlphaTest, 1);
  618. gos_SetRenderState( gos_State_Specular, 1);
  619. gos_SetRenderState( gos_State_Dither, 1);
  620. gos_SetRenderState( gos_State_TextureMapBlend, gos_BlendModulateAlpha);
  621. gos_SetRenderState( gos_State_Filter, gos_FilterBiLinear);
  622. gos_SetRenderState( gos_State_TextureAddress, gos_TextureWrap);
  623. gos_SetRenderState( gos_State_ZCompare, 1);
  624. gos_SetRenderState( gos_State_ZWrite, 1);
  625. DWORD fogColor = 0x009f9f9f;
  626. gos_SetRenderState( gos_State_Fog, (int)&fogColor);
  627. }
  628. //Send down 5000 triangles
  629. long nIterations = 5;
  630. for (long i=0;i<nIterations;i++)
  631. {
  632. DWORD totalVertices = 3000;
  633. gos_SetRenderState( gos_State_Texture, testTextureHandle);
  634. gos_RenderIndexedArray( testVertex, totalVertices, indexArray, totalVertices );
  635. }
  636. endTime=timeGetTime()-startTime;
  637. totalTime += endTime;
  638. }
  639. }
  640. }
  641. //---------------------------------------------------------------------------
  642. #define GAME_REG_KEY "Software\\Microsoft\\Microsoft Games\\MechCommander2\\1.0"
  643. typedef DWORD (*EBUPROC) (LPCTSTR lpRegKeyLocation, LPCTSTR lpEULAFileName, LPCSTR lpWarrantyFileName, BOOL fCheckForFirstRun);
  644. bool FirstRunEula(void)
  645. {
  646. return (true);
  647. }
  648. Stuff::MemoryStream *effectStream = NULL;
  649. extern MidLevelRenderer::MLRClipper * theClipper;
  650. bool gameStarted = false;
  651. void InitializeGameEngine()
  652. {
  653. __asm push esi;
  654. // gotta have this no matter what
  655. gosResourceHandle = gos_OpenResourceDLL("mc2res.dll");
  656. //Check for enough SwapFile Space FIRST!!!
  657. // In order to do that, we must force Win2K/XP to enlarge
  658. // its swapfile at the get go to insure goodness and that
  659. // the message does not come up during game run.
  660. void *testMem = VirtualAlloc(NULL,123000000,MEM_COMMIT,PAGE_READWRITE);
  661. MEMORYSTATUS ms;
  662. GlobalMemoryStatus( &ms );
  663. if (ms.dwTotalPageFile < 250000000)
  664. {
  665. char txt[4096];
  666. char msg[4096];
  667. cLoadString(IDS_SWAPFILE_TOO_SMALL,txt,4095);
  668. sprintf(msg,txt,(ms.dwAvailPageFile / (1024 * 1024)));
  669. char caption[1024];
  670. cLoadString(IDS_SWAPFILE_CAPTION,caption,1023);
  671. MessageBox(NULL,msg,caption,MB_OK | MB_ICONWARNING);
  672. gos_TerminateApplication();
  673. return;
  674. }
  675. if (testMem)
  676. VirtualFree(testMem,0,MEM_RELEASE);
  677. cLoadString(IDS_MC2_FILEMISSING,FileMissingString,511);
  678. cLoadString(IDS_MC2_CDMISSING,CDMissingString,1023);
  679. cLoadString(IDS_MC2_MISSING_TITLE,MissingTitleString,255);
  680. if ( !EULAShown )
  681. {
  682. if ( !FirstRunEula() )
  683. {
  684. gos_TerminateApplication();
  685. return;
  686. }
  687. }
  688. //Check for sufficient hard Drive space on drive game is running from
  689. char currentPath[1024];
  690. gos_GetCurrentPath( currentPath, 1023 );
  691. __int64 driveSpace = gos_GetDriveFreeSpace(currentPath);
  692. if (driveSpace < (20 * 1024 * 1024))
  693. {
  694. char title[256];
  695. char msg[2048];
  696. cLoadString(IDS_GAME_HDSPACE_ERROR,title,255);
  697. cLoadString(IDS_GAME_HDSPACE_MSG,msg,2047);
  698. DWORD result = MessageBox(NULL,msg,title,MB_OKCANCEL | MB_ICONWARNING);
  699. if (result == IDCANCEL)
  700. ExitGameOS();
  701. }
  702. //Check if we are a Voodoo 3. If so, ONLY allow editor to run IF
  703. // Starting resolution is 1024x768x16 or LOWER. NO 32-BIT ALLOWED!
  704. if ((gos_GetMachineInformation(gos_Info_GetDeviceVendorID,0) == 0x121a) &&
  705. (gos_GetMachineInformation(gos_Info_GetDeviceDeviceID,0) == 0x0005))
  706. {
  707. DEVMODE dev;
  708. memset( &dev, 0, sizeof ( DEVMODE ) );
  709. dev.dmSize = sizeof( DEVMODE );
  710. dev.dmSpecVersion = DM_SPECVERSION;
  711. EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &dev );
  712. if ((dev.dmPelsWidth > 1024) || (dev.dmPelsHeight > 768) || (dev.dmBitsPerPel > 16))
  713. {
  714. char title[256];
  715. char msg[2048];
  716. cLoadString(IDS_GAME_ERROR,title,255);
  717. cLoadString(IDS_GAME_VOODOO3,msg,2047);
  718. MessageBox(NULL,msg,title,MB_OK | MB_ICONWARNING);
  719. ExitGameOS();
  720. }
  721. }
  722. //Then, we should check to see if the options.cfg exists. if NOT,
  723. // Bring up a sniffer warning dialog, sniff, bring up sniffer end dialog and end.
  724. if (!fileExists("options.cfg"))
  725. {
  726. //Must also check for a RIVA TNT card with driver 4.10.1.0131
  727. // If this card is in the machine with this driver, do NOT allow sniffer to run.
  728. // Just copy minprefs.cfg to options.cfg and move on.
  729. if ((gos_GetMachineInformation(gos_Info_GetDeviceVendorID,0) == 0x10de) &&
  730. (gos_GetMachineInformation(gos_Info_GetDeviceDeviceID,0) == 0x0020) &&
  731. (gos_GetMachineInformation(gos_Info_GetDeviceDriverVersionHi,0) == 0x0004000a) &&
  732. (gos_GetMachineInformation(gos_Info_GetDeviceDriverVersionLo,0) == 0x00010083))
  733. {
  734. CopyFile("minprefs.cfg","orgprefs.cfg",true);
  735. CopyFile("minprefs.cfg","options.cfg",true);
  736. }
  737. else
  738. {
  739. //NEW Plan. Regardless, copy the minprefs to options. That way, sniffer can only screw up once!!
  740. // After the first run, it will no longer run and the game will continue with minprefs.
  741. SnifferMode = true;
  742. CopyFile("minprefs.cfg","orgprefs.cfg",true);
  743. CopyFile("minprefs.cfg","options.cfg",true);
  744. }
  745. }
  746. //Seed the random Number generator.
  747. gos_srand(timeGetTime());
  748. if (!SnifferMode)
  749. {
  750. //---------------------------------------------------------------------
  751. float doubleClickThreshold = 0.2f;
  752. long dragThreshold = .016667;
  753. Environment.Key_Exit=-1; // so escape doesn't kill your app
  754. //-------------------------------------------------------------
  755. // Find the CDPath in the registry and save it off so I can
  756. // look in CD Install Path for files.
  757. //Changed for the shared source release, just set to current directory
  758. //DWORD maxPathLength = 1023;
  759. //gos_LoadDataFromRegistry("CDPath", CDInstallPath, &maxPathLength);
  760. //if (!maxPathLength)
  761. // strcpy(CDInstallPath,"..\\");
  762. strcpy(CDInstallPath,".\\");
  763. //--------------------------------------------------------------
  764. // Start the SystemHeap and globalHeapList
  765. globalHeapList = new HeapList;
  766. gosASSERT(globalHeapList != NULL);
  767. globalHeapList->init();
  768. globalHeapList->update(); //Run Instrumentation into GOS Debugger Screen
  769. systemHeap = new UserHeap;
  770. gosASSERT(systemHeap != NULL);
  771. systemHeap->init(systemHeapSize,"SYSTEM");
  772. //Start finding the Leaks
  773. // systemHeap->startHeapMallocLog();
  774. //Check for OrgPrefs.cfg. If this file is not present,
  775. // We need to create it because sniffer didn't run.
  776. // Create a new prefs.cfg, too. This way, we can easily restore
  777. // them to a running state if they screw up their prefs.
  778. // All they have to do is delete the orgprefs.cfg file.
  779. // OR re-install!!
  780. //
  781. // ALWAYS use minPrefs.cfg here!
  782. if (!fileExists("orgprefs.cfg"))
  783. {
  784. CopyFile("minprefs.cfg","orgprefs.cfg",true);
  785. CopyFile("minprefs.cfg","options.cfg",true);
  786. }
  787. //--------------------------------------------------------------
  788. // Read in System.CFG
  789. FitIniFilePtr systemFile = new FitIniFile;
  790. #ifdef _DEBUG
  791. long systemOpenResult =
  792. #endif
  793. systemFile->open("system.cfg");
  794. #ifdef _DEBUG
  795. if( systemOpenResult != NO_ERR)
  796. {
  797. char Buffer[256];
  798. gos_GetCurrentPath( Buffer, 256 );
  799. STOP(( "Cannot find \"system.cfg\" file in %s",Buffer ));
  800. }
  801. #endif
  802. {
  803. #ifdef _DEBUG
  804. long systemBlockResult =
  805. #endif
  806. systemFile->seekBlock("systemHeap");
  807. gosASSERT(systemBlockResult == NO_ERR);
  808. {
  809. long result = systemFile->readIdULong("systemHeapSize",systemHeapSize);
  810. gosASSERT(result == NO_ERR);
  811. result = systemFile->readIdULong("guiHeapSize",guiHeapSize);
  812. gosASSERT(result == NO_ERR);
  813. result = systemFile->readIdULong("logisticsHeapSize",logisticsHeapSize);
  814. gosASSERT(result == NO_ERR);
  815. }
  816. #ifdef _DEBUG
  817. long systemPathResult =
  818. #endif
  819. systemFile->seekBlock("systemPaths");
  820. gosASSERT(systemPathResult == NO_ERR);
  821. {
  822. long result = systemFile->readIdString("terrainPath",terrainPath,79);
  823. gosASSERT(result == NO_ERR);
  824. result = systemFile->readIdString("artPath",artPath,79);
  825. gosASSERT(result == NO_ERR);
  826. result = systemFile->readIdString("fontPath",fontPath,79);
  827. gosASSERT(result == NO_ERR);
  828. result = systemFile->readIdString("savePath",savePath,79);
  829. gosASSERT(result == NO_ERR);
  830. result = systemFile->readIdString("spritePath",spritePath,79);
  831. gosASSERT(result == NO_ERR);
  832. result = systemFile->readIdString("shapesPath",shapesPath,79);
  833. gosASSERT(result == NO_ERR);
  834. result = systemFile->readIdString("soundPath",soundPath,79);
  835. gosASSERT(result == NO_ERR);
  836. result = systemFile->readIdString("objectPath",objectPath,79);
  837. gosASSERT(result == NO_ERR);
  838. result = systemFile->readIdString("cameraPath",cameraPath,79);
  839. gosASSERT(result == NO_ERR);
  840. result = systemFile->readIdString("tilePath",tilePath,79);
  841. gosASSERT(result == NO_ERR);
  842. result = systemFile->readIdString("missionPath",missionPath,79);
  843. gosASSERT(result == NO_ERR);
  844. result = systemFile->readIdString("warriorPath",warriorPath,79);
  845. gosASSERT(result == NO_ERR);
  846. result = systemFile->readIdString("profilePath",profilePath,79);
  847. gosASSERT(result == NO_ERR);
  848. result = systemFile->readIdString("interfacepath",interfacePath,79);
  849. gosASSERT(result == NO_ERR);
  850. result = systemFile->readIdString("moviepath",moviePath,79);
  851. gosASSERT(result == NO_ERR);
  852. result = systemFile->readIdString("CDsoundPath",CDsoundPath,79);
  853. gosASSERT(result == NO_ERR);
  854. result = systemFile->readIdString("CDmoviepath",CDmoviePath,79);
  855. gosASSERT(result == NO_ERR);
  856. result = systemFile->readIdString("CDspritePath",CDspritePath,79);
  857. gosASSERT(result == NO_ERR);
  858. }
  859. #ifdef _DEBUG
  860. long fastFileResult =
  861. #endif
  862. systemFile->seekBlock("FastFiles");
  863. gosASSERT(fastFileResult == NO_ERR);
  864. {
  865. long result = systemFile->readIdLong("NumFastFiles",maxFastFiles);
  866. if (result != NO_ERR)
  867. maxFastFiles = 0;
  868. if (maxFastFiles)
  869. {
  870. fastFiles = (FastFile **)malloc(maxFastFiles*sizeof(FastFile *));
  871. memset(fastFiles,0,maxFastFiles*sizeof(FastFile *));
  872. long fileNum = 0;
  873. char fastFileId[10];
  874. char fileName[100];
  875. sprintf(fastFileId,"File%d",fileNum);
  876. while (systemFile->readIdString(fastFileId,fileName,99) == NO_ERR)
  877. {
  878. bool result = FastFileInit(fileName);
  879. if (!result)
  880. STOP(("Unable to startup fastfiles. Probably an old one in the directory!!"));
  881. fileNum++;
  882. sprintf(fastFileId,"File%d",fileNum);
  883. }
  884. }
  885. }
  886. long result = systemFile->seekBlock("UseMusic");
  887. if (result == NO_ERR)
  888. useMusic = TRUE;
  889. else
  890. useMusic = FALSE;
  891. result = systemFile->seekBlock("UseSound");
  892. if (result == NO_ERR)
  893. {
  894. useSound = TRUE;
  895. }
  896. else
  897. {
  898. useSound = FALSE;
  899. useMusic = FALSE;
  900. }
  901. result = systemFile->seekBlock("CameraSettings");
  902. if (result == NO_ERR)
  903. {
  904. result = systemFile->readIdFloat("MaxPerspective",Camera::MAX_PERSPECTIVE);
  905. if (result != NO_ERR)
  906. Camera::MAX_PERSPECTIVE = 88.0f;
  907. if (Camera::MAX_PERSPECTIVE > 90.0f)
  908. Camera::MAX_PERSPECTIVE = 90.0f;
  909. result = systemFile->readIdFloat("MinPerspective",Camera::MIN_PERSPECTIVE);
  910. if (result != NO_ERR)
  911. Camera::MIN_PERSPECTIVE = 18.0f;
  912. if (Camera::MIN_PERSPECTIVE < 0.0f)
  913. Camera::MIN_PERSPECTIVE = 0.0f;
  914. result = systemFile->readIdFloat("MaxOrtho",Camera::MAX_ORTHO);
  915. if (result != NO_ERR)
  916. Camera::MAX_ORTHO = 88.0f;
  917. if (Camera::MAX_ORTHO > 90.0f)
  918. Camera::MAX_ORTHO = 90.0f;
  919. result = systemFile->readIdFloat("MinOrtho",Camera::MIN_ORTHO);
  920. if (result != NO_ERR)
  921. Camera::MIN_ORTHO = 18.0f;
  922. if (Camera::MIN_ORTHO < 0.0f)
  923. Camera::MIN_ORTHO = 0.0f;
  924. result = systemFile->readIdFloat("AltitudeMinimum",Camera::AltitudeMinimum);
  925. if (result != NO_ERR)
  926. Camera::AltitudeMinimum = 560.0f;
  927. if (Camera::AltitudeMinimum < 110.0f)
  928. Camera::AltitudeMinimum = 110.0f;
  929. result = systemFile->readIdFloat("AltitudeMaximumHi",Camera::AltitudeMaximumHi);
  930. if (result != NO_ERR)
  931. Camera::AltitudeMaximumHi = 1600.0f;
  932. result = systemFile->readIdFloat("AltitudeMaximumLo",Camera::AltitudeMaximumLo);
  933. if (result != NO_ERR)
  934. Camera::AltitudeMaximumHi = 1500.0f;
  935. }
  936. }
  937. systemFile->close();
  938. delete systemFile;
  939. systemFile = NULL;
  940. if (initGameLogs) {
  941. GameLog::setup();
  942. if (initNetLog && !NetLog) {
  943. NetLog = GameLog::getNewFile();
  944. if (!NetLog)
  945. Fatal(0, " Couldn't create Net Log ");
  946. long err = NetLog->open("net.log");
  947. if (err)
  948. Fatal(0, " Couldn't open Net Log ");
  949. }
  950. if (initCombatLog && !CombatLog) {
  951. CombatLog = GameLog::getNewFile();
  952. if (!CombatLog)
  953. Fatal(0, " Couldn't create Combat Log ");
  954. long err = CombatLog->open("combat.log");
  955. if (err)
  956. Fatal(0, " Couldn't open Combat Log ");
  957. }
  958. if (initBugLog && !BugLog) {
  959. BugLog = GameLog::getNewFile();
  960. if (!BugLog)
  961. Fatal(0, " Couldn't create Bug Log ");
  962. long err = BugLog->open("bug.log");
  963. if (err)
  964. Fatal(0, " Couldn't open Bug Log ");
  965. }
  966. if (initLRMoveLog && !GlobalMap::logEnabled) {
  967. GlobalMap::toggleLog();
  968. }
  969. }
  970. //--------------------------------------------------------------
  971. // Read in Prefs.cfg
  972. bool fullScreen = false;
  973. FitIniFilePtr prefsFile = new FitIniFile;
  974. FitIniFilePtr optsFile = new FitIniFile;
  975. long prefsOpenResult = prefsFile->open("prefs.cfg");
  976. gosASSERT (prefsOpenResult == NO_ERR);
  977. prefsOpenResult = optsFile->open("options.cfg");
  978. gosASSERT (prefsOpenResult == NO_ERR);
  979. {
  980. #ifdef _DEBUG
  981. long prefsBlockResult =
  982. #endif
  983. prefsFile->seekBlock("MechCommander2");
  984. optsFile->seekBlock("MechCommander2");
  985. gosASSERT(prefsBlockResult == NO_ERR);
  986. {
  987. /*The following commented out options have been moved to "options.cfg" and are
  988. handled by the CPrefs class (in "prefs.h"). They have been moved to CPrefs
  989. because these options are potentially affected by the options screen and may
  990. need to support "apply, cancel and save" functionality.
  991. Understood. Game must also know about them know or it cannot start up correctly!!
  992. -fs
  993. */
  994. // store volume settings in global variable since soundsystem
  995. // does not exist yet. These will be set in SoundSystem::init()
  996. long result = optsFile->readIdLong("DigitalMasterVolume",DigitalMasterVolume);
  997. if (result != NO_ERR)
  998. DigitalMasterVolume = 255;
  999. result = optsFile->readIdLong("MusicVolume",MusicVolume);
  1000. if (result != NO_ERR)
  1001. MusicVolume = 64;
  1002. result = optsFile->readIdLong("RadioVolume",RadioVolume);
  1003. if (result != NO_ERR)
  1004. RadioVolume = 64;
  1005. result = optsFile->readIdLong("SFXVolume",sfxVolume);
  1006. if (result != NO_ERR)
  1007. sfxVolume = 64;
  1008. result = optsFile->readIdLong("BettyVolume",BettyVolume);
  1009. if (result != NO_ERR)
  1010. BettyVolume = 64;
  1011. result = optsFile->readIdBoolean( "Shadows", useShadows);
  1012. if (result != NO_ERR)
  1013. useShadows = true;
  1014. result = optsFile->readIdBoolean( "DetailTexture", useWaterInterestTexture);
  1015. if (result != NO_ERR)
  1016. useWaterInterestTexture = true;
  1017. result = optsFile->readIdLong("Difficulty",GameDifficulty);
  1018. if (result != NO_ERR)
  1019. GameDifficulty = 1;
  1020. result = optsFile->readIdBoolean("UnlimitedAmmo",useUnlimitedAmmo);
  1021. if (result != NO_ERR)
  1022. useUnlimitedAmmo = true;
  1023. result = optsFile->readIdLong("Rasterizer",renderer);
  1024. if (result != NO_ERR)
  1025. renderer = 0;
  1026. if ((renderer < 0) || (renderer > 3))
  1027. renderer = 0;
  1028. result = optsFile->readIdLong("Resolution",resolution);
  1029. if (result != NO_ERR)
  1030. resolution = 0;
  1031. result = optsFile->readIdBoolean("FullScreen",fullScreen);
  1032. if (result != NO_ERR)
  1033. fullScreen = true;
  1034. result = optsFile->readIdLong("Brightness",gammaLevel);
  1035. if (result != NO_ERR)
  1036. gammaLevel = 0;
  1037. result = optsFile->readIdBoolean( "useLeftRightMouseProfile", useLeftRightMouseProfile );
  1038. if ( result != NO_ERR )
  1039. useLeftRightMouseProfile = true;
  1040. bool asyncMouse = false;
  1041. result = optsFile->readIdBoolean( "useAsyncMouse", asyncMouse );
  1042. if ( result != NO_ERR )
  1043. asyncMouse = false;
  1044. mc2UseAsyncMouse = asyncMouse;
  1045. long filterSetting;
  1046. result = prefsFile->readIdLong("FilterState",filterSetting);
  1047. if (result == NO_ERR)
  1048. {
  1049. switch (filterSetting)
  1050. {
  1051. default:
  1052. case 0:
  1053. FilterState = gos_FilterNone;
  1054. break;
  1055. case 1:
  1056. FilterState = gos_FilterBiLinear;
  1057. break;
  1058. case 2:
  1059. FilterState = gos_FilterTriLinear;
  1060. break;
  1061. }
  1062. }
  1063. result = prefsFile->readIdLong("TerrainTextureRes",TERRAIN_TXM_SIZE);
  1064. if (result != NO_ERR)
  1065. TERRAIN_TXM_SIZE = 64;
  1066. result = prefsFile->readIdLong("ObjectTextureRes",ObjectTextureSize);
  1067. if (result != NO_ERR)
  1068. ObjectTextureSize = 128;
  1069. result = prefsFile->readIdFloat("DoubleClickThreshold",doubleClickThreshold);
  1070. if (result != NO_ERR)
  1071. doubleClickThreshold = 0.2f;
  1072. result = prefsFile->readIdLong("DragThreshold",dragThreshold);
  1073. if (result != NO_ERR)
  1074. dragThreshold = .01667f;
  1075. result = prefsFile->readIdULong("BaseVertexColor",BaseVertexColor);
  1076. if (result != NO_ERR)
  1077. BaseVertexColor = 0x00000000;
  1078. result = prefsFile->readIdBoolean("RealLOS",useRealLOS);
  1079. if (result != NO_ERR)
  1080. useRealLOS = true;
  1081. result = prefsFile->readIdLong("GameVisibleVertices",GameVisibleVertices);
  1082. if (result != NO_ERR)
  1083. GameVisibleVertices = 30;
  1084. result = prefsFile->readIdFloat("MaxClipDistance",Camera::MaxClipDistance);
  1085. if (result != NO_ERR)
  1086. Camera::MaxClipDistance = 3000.0f;
  1087. result = prefsFile->readIdFloat("MinHazeDistance",Camera::MinHazeDistance);
  1088. if (result != NO_ERR)
  1089. Camera::MinHazeDistance = 2000.0f;
  1090. result = prefsFile->readIdFloat("View0Zoom",Camera::cameraZoom[0]);
  1091. if (result != NO_ERR)
  1092. Camera::cameraZoom[0] = 1200.0f;
  1093. result = prefsFile->readIdFloat("View0Tilt",Camera::cameraTilt[0]);
  1094. if (result != NO_ERR)
  1095. Camera::cameraTilt[0] = 35.0f;
  1096. result = prefsFile->readIdFloat("View1Zoom",Camera::cameraZoom[1]);
  1097. if (result != NO_ERR)
  1098. Camera::cameraZoom[1] = 1200.0f;
  1099. result = prefsFile->readIdFloat("View1Tilt",Camera::cameraTilt[1]);
  1100. if (result != NO_ERR)
  1101. Camera::cameraTilt[1] = 35.0f;
  1102. result = prefsFile->readIdFloat("View2Zoom",Camera::cameraZoom[2]);
  1103. if (result != NO_ERR)
  1104. Camera::cameraZoom[2] = 1200.0f;
  1105. result = prefsFile->readIdFloat("View2Tilt",Camera::cameraTilt[2]);
  1106. if (result != NO_ERR)
  1107. Camera::cameraTilt[2] = 35.0f;
  1108. result = prefsFile->readIdFloat("View3Zoom",Camera::cameraZoom[3]);
  1109. if (result != NO_ERR)
  1110. Camera::cameraZoom[3] = 1200.0f;
  1111. result = prefsFile->readIdFloat("View3Tilt",Camera::cameraTilt[3]);
  1112. if (result != NO_ERR)
  1113. Camera::cameraTilt[3] = 35.0f;
  1114. }
  1115. }
  1116. prefsFile->close();
  1117. optsFile->close();
  1118. delete prefsFile;
  1119. prefsFile = NULL;
  1120. delete optsFile;
  1121. optsFile = NULL;
  1122. //---------------------------------------------------------------------
  1123. //void __stdcall gos_SetScreenMode( DWORD Width, DWORD Height, DWORD bitDepth=16, DWORD Device=0, bool disableZBuffer=0, bool AntiAlias=0, bool RenderToVram=0, bool GotoFullScreen=0, int DirtyRectangle=0, bool GotoWindowMode=0, bool EnableStencil=0, DWORD Renderer=0 );
  1124. /*The following commented out code is now handled by CPrefs::applyPrefs()
  1125. (in "prefs.cpp").*/
  1126. /*
  1127. switch (resolution)
  1128. {
  1129. case 0: //640by480
  1130. if (renderer == 3)
  1131. gos_SetScreenMode(640,480,16,0,0,0,true,fullScreen,0,!fullScreen,0,renderer);
  1132. else
  1133. gos_SetScreenMode(640,480,16,0,0,0,0,fullScreen,0,!fullScreen,0,renderer);
  1134. break;
  1135. case 1: //800by600
  1136. if (renderer == 3)
  1137. gos_SetScreenMode(800,600,16,0,0,0,true,fullScreen,0,!fullScreen,0,renderer);
  1138. else
  1139. gos_SetScreenMode(800,600,16,0,0,0,0,fullScreen,0,!fullScreen,0,renderer);
  1140. break;
  1141. case 2: //1024by768
  1142. if (renderer == 3)
  1143. gos_SetScreenMode(1024,768,16,0,0,0,true,fullScreen,0,!fullScreen,0,renderer);
  1144. else
  1145. gos_SetScreenMode(1024,768,16,0,0,0,0,fullScreen,0,!fullScreen,0,renderer);
  1146. break;
  1147. case 3: //1280by1024
  1148. if (renderer == 3)
  1149. gos_SetScreenMode(1280,1024,16,0,0,0,true,fullScreen,0,!fullScreen,0,renderer);
  1150. else
  1151. gos_SetScreenMode(1280,1024,16,0,0,0,0,fullScreen,0,!fullScreen,0,renderer);
  1152. break;
  1153. case 4: //1600by1200
  1154. if (renderer == 3)
  1155. gos_SetScreenMode(1600,1200,16,0,0,0,true,fullScreen,0,!fullScreen,0,renderer);
  1156. else
  1157. gos_SetScreenMode(1600,1200,16,0,0,0,0,fullScreen,0,!fullScreen,0,renderer);
  1158. break;
  1159. }
  1160. */
  1161. /* load and apply options from "options.cfg" */
  1162. prefs.load();
  1163. prefs.applyPrefs();
  1164. //--------------------------------------------------
  1165. // Setup Mouse Parameters from Prefs.CFG
  1166. userInput = new UserInput;
  1167. userInput->init();
  1168. userInput->setMouseDoubleClickThreshold(doubleClickThreshold);
  1169. userInput->setMouseDragThreshold(dragThreshold);
  1170. //--------------------------------------------------
  1171. char temp[256];
  1172. cLoadString( IDS_FLOAT_HELP_FONT, temp, 255 );
  1173. char* pStr = strstr( temp, "," );
  1174. if ( pStr )
  1175. {
  1176. gosFontScale = -atoi( pStr + 1 );
  1177. *pStr = 0;
  1178. }
  1179. char path [256];
  1180. strcpy( path, "assets\\graphics\\" );
  1181. strcat( path, temp );
  1182. gosFontHandle = gos_LoadFont(path);
  1183. FontHandle = gosFontHandle;
  1184. globalFloatHelp = new FloatHelp(MAX_FLOAT_HELPS);
  1185. //
  1186. //----------------------------------
  1187. // Start associated stuff.
  1188. //----------------------------------
  1189. //-------------------------------
  1190. // Used to output debug stuff!
  1191. // Mondo COOL!
  1192. // simply do this in the code and stuff goes to the file called mc2.output
  1193. // DEBUG_STREAM << thing_you_want_to_output
  1194. //
  1195. // IMPORTANT NOTE:
  1196. Stuff::InitializeClasses();
  1197. MidLevelRenderer::InitializeClasses(8192*4,8192,0,0,true);
  1198. gosFX::InitializeClasses();
  1199. gos_PushCurrentHeap(MidLevelRenderer::Heap);
  1200. MidLevelRenderer::TGAFilePool *pool = new MidLevelRenderer::TGAFilePool("data\\tgl\\128\\");
  1201. MidLevelRenderer::MLRTexturePool::Instance = new MidLevelRenderer::MLRTexturePool(pool);
  1202. MidLevelRenderer::MLRSortByOrder *cameraSorter = new MidLevelRenderer::MLRSortByOrder(MidLevelRenderer::MLRTexturePool::Instance);
  1203. theClipper = new MidLevelRenderer::MLRClipper(0, cameraSorter);
  1204. gos_PopCurrentHeap();
  1205. //------------------------------------------------------
  1206. // Start the GOS FX.
  1207. gos_PushCurrentHeap(gosFX::Heap);
  1208. gosFX::EffectLibrary::Instance = new gosFX::EffectLibrary();
  1209. Check_Object(gosFX::EffectLibrary::Instance);
  1210. FullPathFileName effectsName;
  1211. effectsName.init(effectsPath,"mc2.fx","");
  1212. File effectFile;
  1213. long result = effectFile.open(effectsName);
  1214. if (result != NO_ERR)
  1215. STOP(("Could not find MC2.fx"));
  1216. long effectsSize = effectFile.fileSize();
  1217. MemoryPtr effectsData = (MemoryPtr)systemHeap->Malloc(effectsSize);
  1218. effectFile.read(effectsData,effectsSize);
  1219. effectFile.close();
  1220. effectStream = new Stuff::MemoryStream(effectsData,effectsSize);
  1221. gosFX::EffectLibrary::Instance->Load(effectStream);
  1222. gosFX::LightManager::Instance = new gosFX::LightManager();
  1223. gos_PopCurrentHeap();
  1224. systemHeap->Free(effectsData);
  1225. //--------------------------------------------------------------
  1226. // Start the GUI Heap.
  1227. guiHeap = new UserHeap;
  1228. gosASSERT(guiHeap != NULL);
  1229. guiHeap->init(guiHeapSize,"GUI");
  1230. //------------------------------------------------
  1231. // Fire up the MC Texture Manager.
  1232. mcTextureManager = new MC_TextureManager;
  1233. mcTextureManager->start();
  1234. //--------------------------------------------------------------
  1235. // Load up the mouse cursors
  1236. userInput->initMouseCursors("cursors");
  1237. userInput->mouseOff();
  1238. userInput->setMouseCursor(mState_NORMAL);
  1239. //------------------------------------------------
  1240. // Give the Sound System a Whirl!
  1241. soundSystem = new GameSoundSystem;
  1242. soundSystem->init();
  1243. ((SoundSystem *)soundSystem)->init("sound");
  1244. sndSystem = soundSystem; // for things in the lib that use sound
  1245. //-----------------------------------------------
  1246. // Only used by camera to retrieve screen coords.
  1247. globalPane = new PANE;
  1248. globalWindow = new WINDOW;
  1249. globalPane->window = globalWindow;
  1250. globalPane->x0 = 0;
  1251. globalPane->y0 = 0;
  1252. globalPane->x1 = Environment.screenWidth;
  1253. globalPane->y1 = Environment.screenHeight;
  1254. globalWindow->buffer = NULL; //This is set at the start of Renders. For now we HOLD LOCK during entire old 2D render test. This will go away once we hit 3D
  1255. globalWindow->shadow = NULL;
  1256. globalWindow->stencil = NULL;
  1257. globalWindow->x_max = globalPane->x1 - globalPane->x0 - 1;
  1258. globalWindow->y_max = globalPane->y1 - globalPane->y0 - 1;
  1259. //---------------------------------------------------------
  1260. // Start the Timers
  1261. timerManager = new TimerManager;
  1262. timerManager->init();
  1263. //---------------------------------------------------------
  1264. // Start the Color table code
  1265. initColorTables();
  1266. //---------------------------------------------------------
  1267. // Start the Mission, Scenario and Logistics classes here
  1268. mission = new Mission;
  1269. logistics = new Logistics;
  1270. GameDebugWindow::setFont("assets\\graphics\\arial8.tga");
  1271. DEBUGWINS_init();
  1272. StartupNetworking();
  1273. #ifdef USE_movie
  1274. movieSoundUseDirectSound(0);
  1275. #endif
  1276. if (justStartMission)
  1277. {
  1278. logistics->setLogisticsState(log_STARTMISSIONFROMCMDLINE);
  1279. char commandersToLoad[MAX_MC_PLAYERS][3] = {{0, 0, 0}, {1, 1, 1}, {2, 0, 2}, {3, 3, 3}, {4, 4, 4}, {5, 5, 5}, {6, 6, 6}, {7, 7, 7}};
  1280. mission->init(missionName, MISSION_LOAD_SP_QUICKSTART, 0, NULL, commandersToLoad, 2);
  1281. eye->activate();
  1282. eye->update();
  1283. mission->start();
  1284. }
  1285. else
  1286. {
  1287. int param = log_SPLASH;
  1288. if ( MPlayer && MPlayer->launchedFromLobby )
  1289. param = log_ZONE;
  1290. logistics->start( param); //Always start with logistics in Splash Screen Mode
  1291. Mission::initBareMinimum();
  1292. }
  1293. initDialogs();
  1294. gos_EnableSetting(gos_Set_LoseFocusBehavior, 2 );
  1295. DWORD numJoysticks = gosJoystick_CountJoysticks();
  1296. for (long i=0;i<numJoysticks;i++)
  1297. {
  1298. gosJoystick_Info joyInfo;
  1299. gosJoystick_GetInfo(i, &joyInfo);
  1300. //Search for the Attila Strategic Commander here.
  1301. // Look for the Attila VidPid 0x045e0033 (Unique!)
  1302. // Andy G did not do what I asked for here. Will do in our version when we branch.
  1303. // For NOW, ANY 3 Axis joystick with 15 buttons is a Strategic Commander.
  1304. if ((joyInfo.nAxes == 3) && (joyInfo.nButtons == 15))
  1305. {
  1306. userInput->addAttila(i);
  1307. gosJoystick_SetPolling(i, true, 0.1f);
  1308. }
  1309. }
  1310. //Time BOMB goes here.
  1311. // Set Date and write Binary data to registry under key
  1312. // GraphicsData!!
  1313. SYSTEMTIME bombDate;
  1314. DWORD dataSize = sizeof(SYSTEMTIME);
  1315. gos_LoadDataFromRegistry("GraphicsDataInit2", &bombDate, &dataSize);
  1316. if (dataSize == 0)
  1317. {
  1318. bombDate.wYear = 2001;
  1319. bombDate.wMonth = 6;
  1320. bombDate.wDayOfWeek = 5;
  1321. bombDate.wDay = 15;
  1322. bombDate.wHour = 0;
  1323. bombDate.wMinute = 0;
  1324. bombDate.wSecond = 0;
  1325. bombDate.wMilliseconds = 0;
  1326. dataSize = sizeof(SYSTEMTIME);
  1327. gos_SaveDataToRegistry("GraphicsDataInit2", &bombDate, dataSize);
  1328. }
  1329. gameStarted = true;
  1330. }
  1331. else
  1332. {
  1333. char msgBuffer[4096];
  1334. char msgTitle[1024];
  1335. cLoadString(IDS_SNIFFER_INIT_MSG,msgBuffer,4095);
  1336. cLoadString(IDS_SNIFFER_INIT_TITLE,msgTitle,1023);
  1337. MessageBox(NULL,msgBuffer,msgTitle,MB_OK);
  1338. //-------------------------------------------------------------
  1339. // Find the CDPath in the registry and save it off so I can
  1340. // look in CD Install Path for files.
  1341. //Changed for the shared source release, just set to current directory
  1342. //DWORD maxPathLength = 1023;
  1343. //gos_LoadDataFromRegistry("CDPath", CDInstallPath, &maxPathLength);
  1344. //if (!maxPathLength)
  1345. // memset(CDInstallPath,0,1024);
  1346. memset(CDInstallPath,0,1024);
  1347. //Set ScreenMode to 800x600x16 FULLSCREEN!!!!
  1348. // A window will return BAD DATA!!
  1349. //
  1350. // If this fails, GAME CANNOT RUN on their machine!!!!!
  1351. //
  1352. // Check which rasterizer comes up. If software, tell prefs we cannot run in hardware!!
  1353. //
  1354. while (((gos_GetMachineInformation(gos_Info_GetDeviceLocalMemory, curDevice) +
  1355. gos_GetMachineInformation(gos_Info_GetDeviceAGPMemory, curDevice)) < 6291456) &&
  1356. (curDevice < gos_GetMachineInformation( gos_Info_NumberDevices )))
  1357. curDevice++;
  1358. if (curDevice < gos_GetMachineInformation( gos_Info_NumberDevices ))
  1359. gos_SetScreenMode(800,600,16,curDevice,0,0,0,true,0,0,0,0);
  1360. //Create about a thousand textured random triangles.
  1361. testVertex = (gos_VERTEX *)malloc(sizeof(gos_VERTEX) * 3000);
  1362. indexArray = (WORD *)malloc(sizeof(WORD) * 3000);
  1363. for (long i=0;i<3000;i++)
  1364. {
  1365. testVertex[i].x = RandomNumber(1000) - 100;
  1366. testVertex[i].y = RandomNumber(800) - 100;
  1367. testVertex[i].z = ((float)RandomNumber(150) / 100.0f) - 0.25f;
  1368. testVertex[i].rhw = 0.5f;
  1369. testVertex[i].u = (float)RandomNumber(100) / 100.0f;
  1370. testVertex[i].v = (float)RandomNumber(100) / 100.0f;
  1371. testVertex[i].argb = 0x3fffffff;
  1372. testVertex[i].frgb = 0x3f1f2f3f;
  1373. indexArray[i] = i;
  1374. }
  1375. testTextureHandle = gos_NewTextureFromFile(gos_Texture_Solid,"testTxm.tga");
  1376. }
  1377. //Make any directories we need which should be empty.
  1378. CreateDirectory(savePath,NULL);
  1379. CreateDirectory(transcriptsPath,NULL);
  1380. //Startup the Office Watson Handler.
  1381. InitDW();
  1382. __asm pop esi;
  1383. }
  1384. //---------------------------------------------------------------------------
  1385. void TerminateGameEngine()
  1386. {
  1387. if (!gameStarted)
  1388. return;
  1389. if (!SnifferMode)
  1390. {
  1391. //--------------------------------------------------
  1392. // Setup Mouse Parameters from Prefs.CFG
  1393. if (userInput)
  1394. {
  1395. //Must call this to shut off the mouse async draw thread.
  1396. //DO NOT DELETE Yet!! Too many things assume this is around.
  1397. userInput->destroy();
  1398. }
  1399. //--------------------------------------------------
  1400. DEBUGWINS_destroy();
  1401. ShutdownNetworking();
  1402. delete theClipper;
  1403. theClipper = NULL;
  1404. //---------------------------------------------------------
  1405. // End the Mission, Operation and Logistics classes here
  1406. if (mission)
  1407. {
  1408. mission->destroy(false);
  1409. delete mission;
  1410. mission = NULL;
  1411. }
  1412. if (logistics)
  1413. {
  1414. logistics->destroy();
  1415. delete logistics;
  1416. logistics = NULL;
  1417. }
  1418. endDialogs();
  1419. if (optionsScreenWrapper)
  1420. {
  1421. optionsScreenWrapper->destroy();
  1422. delete optionsScreenWrapper;
  1423. optionsScreenWrapper = NULL;
  1424. }
  1425. //---------------------------------------------------------
  1426. // Start the Color table code
  1427. destroyColorTables();
  1428. GameLog::cleanup();
  1429. //---------------------------------------------------------
  1430. // End the Timers
  1431. delete timerManager;
  1432. timerManager = NULL;
  1433. //---------------------------------------------------------
  1434. // TEST of PORT
  1435. // Create VFX PANE and WINDOW to test draw of old terrain!
  1436. if (globalPane)
  1437. {
  1438. delete globalPane;
  1439. globalPane = NULL;
  1440. }
  1441. if (globalWindow)
  1442. {
  1443. delete globalWindow;
  1444. globalWindow = NULL;
  1445. }
  1446. //-------------------------------------------------------------
  1447. // Shut down the soundSytem for a change!
  1448. if (soundSystem)
  1449. {
  1450. soundSystem->destroy();
  1451. delete soundSystem;
  1452. soundSystem = NULL;
  1453. }
  1454. //------------------------------------------------
  1455. // shutdown the MC Texture Manager.
  1456. if (mcTextureManager)
  1457. {
  1458. mcTextureManager->destroy();
  1459. delete mcTextureManager;
  1460. mcTextureManager = NULL;
  1461. }
  1462. delete globalFloatHelp;
  1463. globalFloatHelp = NULL;
  1464. //--------------------------------------------------------------
  1465. // End the SystemHeap and globalHeapList
  1466. if (systemHeap)
  1467. {
  1468. systemHeap->destroy();
  1469. delete systemHeap;
  1470. systemHeap = NULL;
  1471. }
  1472. if (guiHeap)
  1473. {
  1474. guiHeap->destroy();
  1475. delete guiHeap;
  1476. guiHeap = NULL;
  1477. }
  1478. if (globalHeapList)
  1479. {
  1480. globalHeapList->destroy();
  1481. delete globalHeapList;
  1482. globalHeapList = NULL;
  1483. }
  1484. //----------------------------------------------------
  1485. // Shutdown the MLR and associated stuff libraries
  1486. //----------------------------------------------------
  1487. gos_PushCurrentHeap(gosFX::Heap);
  1488. delete effectStream;
  1489. delete gosFX::LightManager::Instance;
  1490. gos_PopCurrentHeap();
  1491. //
  1492. //-------------------
  1493. // Turn off libraries
  1494. //-------------------
  1495. //
  1496. gosFX::TerminateClasses();
  1497. MidLevelRenderer::TerminateClasses();
  1498. Stuff::TerminateClasses();
  1499. delete userInput;
  1500. userInput = NULL;
  1501. //Redundant. Something else is shutting this down.
  1502. //GOS sure does think its bad to delete something multiple times though.
  1503. //Even though it simply never is!
  1504. //gos_DeleteFont(gosFontHandle);
  1505. gos_CloseResourceDLL(gosResourceHandle);
  1506. //
  1507. //--------------------------
  1508. // Turn off the fast Files
  1509. //--------------------------
  1510. //
  1511. FastFileFini();
  1512. //
  1513. //Just down any global allocations
  1514. //
  1515. if (g_textureCache_FilenameOfLastLoadedTexture)
  1516. {
  1517. delete g_textureCache_FilenameOfLastLoadedTexture;
  1518. g_textureCache_FilenameOfLastLoadedTexture = NULL;
  1519. }
  1520. if (ForceGroupIcon::jumpJetIcon)
  1521. {
  1522. delete ForceGroupIcon::jumpJetIcon;
  1523. ForceGroupIcon::jumpJetIcon = NULL;
  1524. }
  1525. if (MechIcon::s_MechTextures)
  1526. {
  1527. delete [] MechIcon::s_MechTextures;
  1528. MechIcon::s_MechTextures = NULL;
  1529. }
  1530. if (ForceGroupIcon::s_textureMemory)
  1531. {
  1532. delete [] ForceGroupIcon::s_textureMemory;
  1533. ForceGroupIcon::s_textureMemory = NULL;
  1534. }
  1535. }
  1536. else
  1537. {
  1538. free(testVertex);
  1539. testVertex = NULL;
  1540. free(indexArray);
  1541. indexArray = NULL;
  1542. }
  1543. }
  1544. //-------------------------------
  1545. // Test TGL Parser.
  1546. bool extracted = false;
  1547. bool doTransformMath = true;
  1548. extern bool useFog;
  1549. extern long terrainLineChanged;
  1550. float frameNum = 0.0f;
  1551. bool enoughTime = true;
  1552. long enoughCount = 0;
  1553. //---------------------------------------------------------------------------
  1554. //
  1555. // No multi-thread now!
  1556. //
  1557. bool DoneSniffing = false;
  1558. void DoGameLogic()
  1559. {
  1560. if (!SnifferMode)
  1561. {
  1562. #ifdef LAB_ONLY //Used for debugging LOS
  1563. currentLineElement = 0;
  1564. #endif
  1565. if (MPlayer) {
  1566. ProfileTime(MCTimeMultiplayerUpdate,MPlayer->update());
  1567. if (MPlayer->waitingToStartMission)
  1568. {
  1569. if (MPlayer->startMission)
  1570. {
  1571. // logistics->setLogisticsState(log_DONE); // can't do this until screen animates out
  1572. soundSystem->playBettySample(BETTY_NEW_CAMPAIGN);
  1573. MPlayer->waitingToStartMission = false;
  1574. }
  1575. }
  1576. }
  1577. FloatHelp::resetAll();
  1578. //-------------------------------------
  1579. // Get me the current frameRate.
  1580. // Convert to frameLength and any other timing stuff.
  1581. //if (frameRate < 15.0)
  1582. // frameRate = 15.0;
  1583. //FrameRate can be zero in GameOS for some unknown fu-cocked reason.
  1584. if (frameRate < Stuff::SMALL)
  1585. frameRate = 4.0f;
  1586. frameLength = 1.0 / frameRate;
  1587. if (frameLength > 0.25f)
  1588. frameLength = 0.25f;
  1589. //Calc out the average frame rate so we can decide if we should use the
  1590. // movie Video or Just the Audio Track!
  1591. currentFrameNum++;
  1592. if (currentFrameNum == 30)
  1593. currentFrameNum = 0;
  1594. last30Frames[currentFrameNum] = frameRate;
  1595. averageFrameRate = 0.0f;
  1596. for (long fc=0;fc<30;fc++)
  1597. averageFrameRate += last30Frames[fc];
  1598. averageFrameRate /= 30.0f;
  1599. if (userInput->getKeyDown(KEY_R) && userInput->ctrl() && !userInput->alt() && !userInput->shift())
  1600. {
  1601. doTransformMath ^= true;
  1602. terrainLineChanged = turn;
  1603. }
  1604. if (doTransformMath)
  1605. {
  1606. //-------------------------------------
  1607. // Poll devices for this frame.
  1608. userInput->update();
  1609. //----------------------------------------
  1610. // Update the Sound System for this frame
  1611. soundSystem->update();
  1612. //----------------------------------------
  1613. // Update all of the timers
  1614. timerManager->update();
  1615. //-----------------------------------------------------
  1616. // Update Mission and Logistics here.
  1617. if (logistics)
  1618. {
  1619. long result = logistics->update();
  1620. if (result == log_DONE)
  1621. {
  1622. logistics->stop();
  1623. }
  1624. }
  1625. if ((true == bInvokeOptionsScreenFlag)
  1626. || (userInput->getKeyDown(KEY_O) && userInput->ctrl() && !userInput->alt() && !userInput->shift()))
  1627. {
  1628. bInvokeOptionsScreenFlag = false;
  1629. if ((!optionsScreenWrapper) || (optionsScreenWrapper->isDone()))
  1630. {
  1631. if (!optionsScreenWrapper)
  1632. {
  1633. optionsScreenWrapper = new OptionsScreenWrapper;
  1634. optionsScreenWrapper->init();
  1635. }
  1636. if (mission && mission->missionInterface && !mission->missionInterface->isPaused())
  1637. mission->missionInterface->togglePauseWithoutMenu();
  1638. optionsScreenWrapper->begin();
  1639. }
  1640. }
  1641. else
  1642. if (mission && (!optionsScreenWrapper || optionsScreenWrapper->isDone() ) )
  1643. {
  1644. long result = mission->update();
  1645. if (result == 9999) {
  1646. mission->destroy();
  1647. //delete mission;
  1648. //mission = NULL;
  1649. for (long i = 0; i < 3; i++) {
  1650. DebugGameObject[i] = NULL;
  1651. DebugWindow[i + 1]->clear();
  1652. }
  1653. if (MPlayer && MPlayer->isServer())
  1654. MPlayer->sendEndMission(1);
  1655. quitGame = true;
  1656. }
  1657. else if (result != mis_PLAYING)
  1658. {
  1659. //if (MPlayer && MPlayer->isServer())
  1660. // MPlayer->sendEndMission(1);
  1661. if (result < mis_PLAYER_DRAW)
  1662. soundSystem->playBettySample(BETTY_MISSION_LOST);
  1663. else if (result > mis_PLAYER_DRAW)
  1664. soundSystem->playBettySample(BETTY_MISSION_WON);
  1665. //Gotta get rid of the mission textures before Heidi starts her stuff!
  1666. // No RAM otherwise in mc2_18.
  1667. mcTextureManager->flush(true);
  1668. if (MPlayer && aborted) {
  1669. MPlayer->closeSession();
  1670. MPlayer->setMode(MULTIPLAYER_MODE_NONE);
  1671. logistics->start(log_SPLASH);
  1672. }
  1673. else
  1674. logistics->start(log_RESULTS); //Should be log_RESULTS!!!!!!
  1675. aborted = false;
  1676. if ( !LogisticsData::instance->campaignOver() || MPlayer || LogisticsData::instance->isSingleMission() ) {
  1677. mission->destroy();
  1678. //delete mission;
  1679. //mission = NULL;
  1680. }
  1681. for (long i = 0; i < 3; i++) {
  1682. DebugGameObject[i] = NULL;
  1683. DebugWindow[i + 1]->clear();
  1684. }
  1685. }
  1686. }
  1687. if (optionsScreenWrapper && !optionsScreenWrapper->isDone())
  1688. {
  1689. OptionsScreenWrapper::status_type result = optionsScreenWrapper->update();
  1690. if (result == OptionsScreenWrapper::opt_DONE)
  1691. {
  1692. optionsScreenWrapper->end();
  1693. if (mission && mission->missionInterface && mission->missionInterface->isPaused())
  1694. mission->missionInterface->togglePauseWithoutMenu();
  1695. }
  1696. }
  1697. }
  1698. DEBUGWINS_update();
  1699. //---------------------------------------------------
  1700. // Update heap instrumentation.
  1701. #ifdef LAB_ONLY
  1702. if (turn > 3)
  1703. globalHeapList->update();
  1704. #endif
  1705. //-----------------------------------------------------
  1706. // Check the TimeBomb to see if we should go away
  1707. /*
  1708. if (!checkedBomb)
  1709. {
  1710. SYSTEMTIME checkTime;
  1711. SYSTEMTIME bombTime;
  1712. DWORD dataSize = sizeof(SYSTEMTIME);
  1713. GetSystemTime(&checkTime);
  1714. if (!gotBombData)
  1715. {
  1716. gos_LoadDataFromRegistry("GraphicsDataInit2", &bombTime, &dataSize);
  1717. gotBombData = true;
  1718. }
  1719. if (dataSize == 0)
  1720. {
  1721. STOP(("NO Graphics Data Initializer - Please Login with administrator privileges")); //In Case they try to whack the registry entry while running!
  1722. }
  1723. if ((checkTime.wYear >= bombTime.wYear) &&
  1724. (checkTime.wMonth >= bombTime.wMonth) &&
  1725. (checkTime.wDay >= bombTime.wDay))
  1726. {
  1727. //If bomb goes off, set date to IMPOSSIBLE to achieve time!!
  1728. // If they whack the entry after this, it doesn't matter! The normal bomb will go off and then set this anyway.
  1729. // If they whack the entry, then reset their system clock, then run the game, it will work. Not much more I can do!
  1730. // I could delete files but it won't matter, they have the CD!
  1731. //
  1732. // MUST change version numbers on fastfiles after Code Complete and after EACH Beta we release!!
  1733. bombTime.wYear = 1950;
  1734. bombTime.wMonth = 0;
  1735. bombTime.wDay = 0;
  1736. gos_SaveDataToRegistry("GraphicsDataInit2", &bombTime, sizeof(SYSTEMTIME));
  1737. STOP(("Time Bomb has exploded!"));
  1738. quitGame = true;
  1739. }
  1740. checkedBomb = true;
  1741. }
  1742. */
  1743. //---------------------------------------------------------------
  1744. // Somewhere in all of the updates, we have asked to be excused!
  1745. if (quitGame)
  1746. {
  1747. //EnterWindowMode(); //Game crashes if _TerminateApp called from fullScreen
  1748. gos_TerminateApplication();
  1749. }
  1750. if (loadInMissionSave)
  1751. {
  1752. mission->load("data\\savegame\\testgame.ims");
  1753. loadInMissionSave = false;
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if (!DoneSniffing)
  1759. {
  1760. for (long i=0;i<3000;i++)
  1761. {
  1762. testVertex[i].x = RandomNumber(1000) - 100;
  1763. testVertex[i].y = RandomNumber(800) - 100;
  1764. testVertex[i].z = ((float)RandomNumber(150) / 100.0f) - 0.25f;
  1765. testVertex[i].rhw = 0.5f;
  1766. testVertex[i].u = (float)RandomNumber(100) / 100.0f;
  1767. testVertex[i].v = (float)RandomNumber(100) / 100.0f;
  1768. testVertex[i].argb = 0x3fffffff;
  1769. testVertex[i].frgb = 0x3f1f2f3f;
  1770. indexArray[i] = i;
  1771. }
  1772. curIteration++;
  1773. if (curIteration > numIterations)
  1774. {
  1775. if (gos_GetMachineInformation(gos_Info_GetDeviceLocalMemory, curDevice) >= 6291456)
  1776. trisPerSecond[curDevice] = 5000.0f * numIterations / (totalTime / 1000);
  1777. else
  1778. trisPerSecond[curDevice] = 0.0f;
  1779. curDevice++;
  1780. if ((curDevice >= NumDevices) || (curDevice > MAX_HARDWARE_CARDS))
  1781. {
  1782. FILE *sniffData = fopen("sniff.dat","wt");
  1783. if (sniffData)
  1784. {
  1785. char sniff[2048];
  1786. sprintf(sniff,"%f,%f,%f,%f,%f,%f\n",trisPerSecond[0],ProcessorSpeed,trisPerSecond[1],trisPerSecond[2],trisPerSecond[3],trisPerSecond[4]);
  1787. fputs(sniff,sniffData);
  1788. fclose(sniffData);
  1789. }
  1790. if ((trisPerSecond[0] > 1000000.0f) && (ProcessorSpeed > 595.0f))
  1791. {
  1792. CopyFile("hiPrefs.cfg","orgprefs.cfg",false);
  1793. CopyFile("hiPrefs.cfg","options.cfg",false);
  1794. }
  1795. else if ((trisPerSecond[0] > 1000000.0f) && (ProcessorSpeed <= 595.0f))
  1796. {
  1797. CopyFile("h2Prefs.cfg","orgprefs.cfg",false);
  1798. CopyFile("h2Prefs.cfg","options.cfg",false);
  1799. }
  1800. else if ((trisPerSecond[0] > 10000.0f) && (ProcessorSpeed > 595.0f))
  1801. {
  1802. CopyFile("midPrefs.cfg","orgprefs.cfg",false);
  1803. CopyFile("midPrefs.cfg","options.cfg",false);
  1804. }
  1805. else if ((trisPerSecond[1] > 1000000.0f) && (ProcessorSpeed > 595.0f))
  1806. {
  1807. CopyFile("hiPrefs1.cfg","orgprefs.cfg",false);
  1808. CopyFile("hiPrefs1.cfg","options.cfg",false);
  1809. }
  1810. else if ((trisPerSecond[1] > 1000000.0f) && (ProcessorSpeed <= 595.0f))
  1811. {
  1812. CopyFile("h2Prefs1.cfg","orgprefs.cfg",false);
  1813. CopyFile("h2Prefs1.cfg","options.cfg",false);
  1814. }
  1815. else if ((trisPerSecond[1] > 10000.0f) && (ProcessorSpeed > 595.0f))
  1816. {
  1817. CopyFile("midPrefs1.cfg","orgprefs.cfg",false);
  1818. CopyFile("midPrefs1.cfg","options.cfg",false);
  1819. }
  1820. else if (trisPerSecond[1] > 0.0f)
  1821. {
  1822. CopyFile("minPrefs1.cfg","orgprefs.cfg",false);
  1823. CopyFile("minPrefs1.cfg","options.cfg",false);
  1824. }
  1825. else
  1826. {
  1827. CopyFile("minPrefs.cfg","orgprefs.cfg",false);
  1828. CopyFile("minPrefs.cfg","options.cfg",false);
  1829. }
  1830. DoneSniffing = true;
  1831. }
  1832. else
  1833. {
  1834. //Don't sniff a below minspec card. Crash O Roni!
  1835. if (gos_GetMachineInformation(gos_Info_GetDeviceLocalMemory, curDevice) >= 6291456)
  1836. gos_SetScreenMode(800,600,16,curDevice,0,0,0,true,0,0,0,0);
  1837. else
  1838. curDevice++;
  1839. curIteration = 0;
  1840. }
  1841. }
  1842. }
  1843. else
  1844. {
  1845. gos_SetScreenMode(800,600,16,0,0,0,0,false,0,true,0,0);
  1846. DoneSniffing = true;
  1847. if (Environment.fullScreen == 0)
  1848. {
  1849. char msgBuffer[4096];
  1850. char msgTitle[1024];
  1851. cLoadString(IDS_SNIFFER_DONE_MSG,msgBuffer,4095);
  1852. cLoadString(IDS_SNIFFER_INIT_TITLE,msgTitle,1023);
  1853. MessageBox(NULL,msgBuffer,msgTitle,MB_OK);
  1854. gos_TerminateApplication();
  1855. }
  1856. }
  1857. }
  1858. }
  1859. //---------------------------------------------------------------------------
  1860. long textToLong (char *num)
  1861. {
  1862. long result = 0;
  1863. //------------------------------------
  1864. // Check if Hex Number
  1865. char *hexOffset = strstr(num,"0x");
  1866. if (hexOffset == NULL)
  1867. {
  1868. result = atol(num);
  1869. }
  1870. else
  1871. {
  1872. hexOffset += 2;
  1873. long numDigits = strlen(hexOffset)-1;
  1874. for (int i=0; i<=numDigits; i++)
  1875. {
  1876. if (!isalnum(hexOffset[i]) || (isalpha(hexOffset[i]) && toupper(hexOffset[i]) > 'F'))
  1877. {
  1878. hexOffset[i] = 0; // we've reach a "wrong" character. Either start of a comment or something illegal. Either way, stop evaluation here.
  1879. break;
  1880. }
  1881. }
  1882. numDigits = strlen(hexOffset)-1;
  1883. long power = 0;
  1884. for (long count = numDigits;count >= 0;count--,power++)
  1885. {
  1886. unsigned char currentDigit = toupper(hexOffset[count]);
  1887. if (currentDigit >= 'A' && currentDigit <= 'F')
  1888. {
  1889. result += (currentDigit - 'A' + 10)<<(4*power);
  1890. }
  1891. else if (currentDigit >= '0' && currentDigit <= '9')
  1892. {
  1893. result += (currentDigit - '0')<<(4*power);
  1894. }
  1895. else
  1896. {
  1897. //---------------------------------------------------------
  1898. // There is a digit in here I don't understand. Return 0.
  1899. result = 0;
  1900. break;
  1901. }
  1902. }
  1903. }
  1904. return(result);
  1905. }
  1906. //----------------------------------------------------------------------------
  1907. // Same command line Parser as MechCommander
  1908. void ParseCommandLine(char *command_line)
  1909. {
  1910. int i;
  1911. int n_args = 0;
  1912. int index = 0;
  1913. char *argv[30];
  1914. char tempCommandLine[4096];
  1915. memset(tempCommandLine,0,4096);
  1916. strncpy(tempCommandLine,command_line,4095);
  1917. while (tempCommandLine[index] != '\0') // until we null out
  1918. {
  1919. argv[n_args] = tempCommandLine + index;
  1920. n_args++;
  1921. while (tempCommandLine[index] != ' ' && tempCommandLine[index] != '\0')
  1922. {
  1923. index++;
  1924. }
  1925. while (tempCommandLine[index] == ' ')
  1926. {
  1927. tempCommandLine[index] = '\0';
  1928. index++;
  1929. }
  1930. }
  1931. i=0;
  1932. while (i<n_args)
  1933. {
  1934. if (strcmpi(argv[i],"-mission") == 0)
  1935. {
  1936. i++;
  1937. if (i < n_args)
  1938. {
  1939. justStartMission = true;
  1940. inViewMode = false;
  1941. if (argv[i][0] == '"')
  1942. {
  1943. // They typed in a quote, keep reading argvs
  1944. // until you find the close quote
  1945. strcpy(missionName,&(argv[i][1]));
  1946. bool scanName = true;
  1947. while (scanName && (i < n_args))
  1948. {
  1949. i++;
  1950. if (i < n_args)
  1951. {
  1952. strcat(missionName," ");
  1953. strcat(missionName,argv[i]);
  1954. if (strstr(argv[i],"\"") != NULL)
  1955. {
  1956. scanName = false;
  1957. missionName[strlen(missionName)-1] = 0;
  1958. }
  1959. }
  1960. else
  1961. {
  1962. //They put a quote on the line with no space.
  1963. //
  1964. scanName = false;
  1965. missionName[strlen(missionName)-1] = 0;
  1966. }
  1967. }
  1968. }
  1969. else
  1970. strcpy(missionName,argv[i]);
  1971. }
  1972. }
  1973. else if (strcmpi(argv[i],"-viewer") == 0)
  1974. {
  1975. i++;
  1976. if (i < n_args)
  1977. {
  1978. inViewMode = true;
  1979. justStartMission = true;
  1980. viewObject = textToLong(argv[i]);
  1981. strcpy(missionName,"mis0101");
  1982. }
  1983. }
  1984. else if (strcmpi(argv[i],"-nodialog") == 0)
  1985. {
  1986. gNoDialogs = true;
  1987. }
  1988. else if (strcmpi(argv[i],"-sniffer") == 0)
  1989. {
  1990. SnifferMode = true;
  1991. }
  1992. else if (strcmpi(argv[i], "-braindead") == 0) {
  1993. i++;
  1994. if (i < n_args) {
  1995. long teamID = textToLong(argv[i]);
  1996. MechWarrior::brainsEnabled[teamID] = false;
  1997. }
  1998. }
  1999. else if (strcmpi(argv[i], "-turrets_off") == 0) {
  2000. i++;
  2001. if (i < n_args) {
  2002. long teamID = textToLong(argv[i]);
  2003. Turret::turretsEnabled[teamID] = false;
  2004. }
  2005. }
  2006. else if (strcmpi(argv[i], "-debugwins") == 0) {
  2007. i++;
  2008. if (i < n_args) {
  2009. long winState = textToLong(argv[i]);
  2010. if (winState == 1)
  2011. DebugWindowOpen[0] = true;
  2012. else if (winState == 2) {
  2013. DebugWindowOpen[1] = true;
  2014. DebugWindowOpen[2] = true;
  2015. DebugWindowOpen[3] = true;
  2016. }
  2017. else if (winState == 3) {
  2018. DebugWindowOpen[0] = true;
  2019. DebugWindowOpen[1] = true;
  2020. DebugWindowOpen[2] = true;
  2021. DebugWindowOpen[3] = true;
  2022. }
  2023. }
  2024. }
  2025. else if (strcmpi(argv[i], "-objectwins") == 0) {
  2026. i++;
  2027. if (i < n_args) {
  2028. long partNumber = textToLong(argv[i]);
  2029. if (NumGameObjectsToDisplay < 3)
  2030. GameObjectWindowList[NumGameObjectsToDisplay++] = partNumber;
  2031. }
  2032. }
  2033. else if (strcmpi(argv[i], "-debugcells") == 0) {
  2034. i++;
  2035. if (i < n_args) {
  2036. long setting = textToLong(argv[i]);
  2037. if ((setting > 0) && (setting < 5))
  2038. DrawDebugCells = setting;
  2039. }
  2040. }
  2041. else if (strcmpi(argv[i], "-nopain") == 0) {
  2042. i++;
  2043. if (i < n_args) {
  2044. long teamID = textToLong(argv[i]);
  2045. Team::noPain[teamID] = true;
  2046. }
  2047. }
  2048. else if (strcmpi(argv[i], "-disable") == 0) {
  2049. i++;
  2050. if (i < n_args) {
  2051. long partID = textToLong(argv[i]);
  2052. DisableAtStart[NumDisableAtStart++] = partID;
  2053. }
  2054. }
  2055. else if (strcmpi(argv[i], "-log") == 0) {
  2056. i++;
  2057. initGameLogs = true;
  2058. if (i < n_args) {
  2059. if (strcmpi(argv[i], "net") == 0)
  2060. initNetLog = true;
  2061. if (strcmpi(argv[i], "weaponfire") == 0)
  2062. initCombatLog = true;
  2063. if (strcmpi(argv[i], "bugs") == 0)
  2064. initBugLog = true;
  2065. if (strcmpi(argv[i], "lrmove") == 0)
  2066. initLRMoveLog = true;
  2067. }
  2068. }
  2069. else if (strcmpi(argv[i], "-show") == 0) {
  2070. i++;
  2071. if (i < n_args) {
  2072. if (strcmpi(argv[i], "movers") == 0)
  2073. ShowMovers = true;
  2074. }
  2075. }
  2076. else if (strcmpi(argv[i], "-goalplan") == 0) {
  2077. i++;
  2078. if (i < n_args) {
  2079. if (strcmpi(argv[i], "enemies") == 0)
  2080. EnemiesGoalPlan = true;
  2081. }
  2082. }
  2083. else if (strcmpi(argv[i], "-killambient") == 0) {
  2084. KillAmbientLight = true;
  2085. }
  2086. else if (strcmpi(argv[i], "-movegoals") == 0) {
  2087. i++;
  2088. if (i < n_args)
  2089. MaxMoveGoalChecks = textToLong(argv[i]);
  2090. }
  2091. else if (strcmpi(argv[i], "-rps") == 0) {
  2092. i++;
  2093. if (i < n_args)
  2094. MaxResourcePoints = textToLong(argv[i]);
  2095. }
  2096. else if (strcmpi(argv[i], "-registerzone") == 0) {
  2097. MultiPlayer::registerZone = true;
  2098. }
  2099. else if (strcmpi(argv[i], "-dropzones") == 0) {
  2100. i++;
  2101. if (i < n_args) {
  2102. long numPlayers = strlen(argv[i]);
  2103. for (long j = 0; j < numPlayers; j++)
  2104. MultiPlayer::presetDropZones[j] = (argv[i][j] - '0');
  2105. }
  2106. }
  2107. i++;
  2108. }
  2109. }
  2110. bool notFirstTime = false;
  2111. //---------------------------------------------------------------------------
  2112. //
  2113. // Setup the GameOS structure -- This tells GameOS what I am using
  2114. //
  2115. void GetGameOSEnvironment( char* CommandLine )
  2116. {
  2117. ParseCommandLine(CommandLine);
  2118. Environment.applicationName = "MechCommander2\\1.0"; // MP012001";
  2119. Environment.debugLog = "";
  2120. Environment.spew = "";
  2121. Environment.TimeStampSpew = 0;
  2122. Environment.GetGameInformation = GetGameInformation;
  2123. Environment.UpdateRenderers = UpdateRenderers;
  2124. Environment.InitializeGameEngine = InitializeGameEngine;
  2125. Environment.DoGameLogic = DoGameLogic;
  2126. Environment.TerminateGameEngine = TerminateGameEngine;
  2127. Environment.Renderer = 0;
  2128. Environment.allowMultipleApps = false;
  2129. Environment.dontClearRegistry = true;
  2130. if (useSound)
  2131. {
  2132. Environment.soundDisable = FALSE;
  2133. Environment.soundHiFi = TRUE;
  2134. Environment.soundChannels = 20;
  2135. }
  2136. else
  2137. {
  2138. Environment.soundDisable = TRUE;
  2139. Environment.soundHiFi = FALSE;
  2140. Environment.soundChannels = 0;
  2141. }
  2142. //--------------------------
  2143. // Networking information...
  2144. // MechCommander GUID = {09608800-4815-11d2-92D2-0060973CFB2C}
  2145. // or {0x9608800, 0x4815, 0x11d2, {0x92, 0xd2, 0x0, 0x60, 0x97, 0x3c, 0xfb, 0x2c}}
  2146. Environment.NetworkGame = FALSE;
  2147. Environment.NetworkMaxPlayers = MAX_COMMANDERS;
  2148. Environment.NetworkGUID[0] = 0x09;
  2149. Environment.NetworkGUID[1] = 0x60;
  2150. Environment.NetworkGUID[2] = 0x88;
  2151. Environment.NetworkGUID[3] = 0x00;
  2152. Environment.NetworkGUID[4] = 0x48;
  2153. Environment.NetworkGUID[5] = 0x15;
  2154. Environment.NetworkGUID[6] = 0x11;
  2155. Environment.NetworkGUID[7] = 0xd2;
  2156. Environment.NetworkGUID[8] = 0x92;
  2157. Environment.NetworkGUID[9] = 0xd2;
  2158. Environment.NetworkGUID[10] = 0x00;
  2159. Environment.NetworkGUID[11] = 0x60;
  2160. Environment.NetworkGUID[12] = 0x97;
  2161. Environment.NetworkGUID[13] = 0x3c;
  2162. Environment.NetworkGUID[14] = 0xfb;
  2163. Environment.NetworkGUID[15] = 0x2c;
  2164. Environment.Key_FullScreen = 0;
  2165. Environment.Key_SwitchMonitors = 0;
  2166. Environment.Key_Exit = 0;
  2167. Environment.screenWidth = 800;
  2168. Environment.screenHeight = 600;
  2169. Environment.bitDepth = 16;
  2170. Environment.fullScreen = 0;
  2171. HKEY hKey;
  2172. LONG result;
  2173. char pData[1024];
  2174. DWORD szData = 1023;
  2175. result=RegOpenKey(HKEY_CURRENT_USER,GAME_REG_KEY,&hKey);
  2176. if( ERROR_SUCCESS==result )
  2177. {
  2178. result=RegQueryValueEx(hKey,"FIRSTRUN",NULL,NULL,(PBYTE)pData,&szData);
  2179. if ((result == ERROR_SUCCESS) && pData[0])
  2180. {
  2181. if (fileExists("options.cfg") && !SnifferMode)
  2182. #ifndef LAB_ONLY
  2183. Environment.fullScreen = 1;
  2184. #endif
  2185. EULAShown = true;
  2186. }
  2187. RegCloseKey(hKey);
  2188. }
  2189. Environment.version = versionStamp;
  2190. Environment.FullScreenDevice = 0;
  2191. Environment.AntiAlias = 0;
  2192. Environment.disableZBuffer = 0;
  2193. //
  2194. // Texture infomation
  2195. //
  2196. Environment.Texture_S_256 = 6;
  2197. Environment.Texture_S_128 = 1;
  2198. Environment.Texture_S_64 = 0;
  2199. Environment.Texture_S_32 = 1;
  2200. Environment.Texture_S_16 = 5;
  2201. Environment.Texture_K_256 = 2;
  2202. Environment.Texture_K_128 = 5;
  2203. Environment.Texture_K_64 = 5;
  2204. Environment.Texture_K_32 = 5;
  2205. Environment.Texture_K_16 = 5;
  2206. Environment.Texture_A_256 = 0;
  2207. Environment.Texture_A_128 = 1;
  2208. Environment.Texture_A_64 = 5;
  2209. Environment.Texture_A_32 = 1;
  2210. Environment.Texture_A_16 = 0;
  2211. Environment.RaidDataSource = "MechCommander 2:Raid4";
  2212. Environment.RaidFilePath = "\\\\aas1\\MC2\\Test\\GOSRaid";
  2213. Environment.RaidCustomFields = "Area=GOSRaid";
  2214. Environment.DisableLowEndCard = 1;
  2215. Environment.Suppress3DFullScreenWarning = 1;
  2216. Environment.RenderToVram = 1;
  2217. notFirstTime = true;
  2218. }
  2219. //***************************************************************************