CONQUER.CPP.BAK 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c0\vcs\code\conquer.cpv 4.83 24 Oct 1996 12:55:42 JOE_BOSTIC $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : CONQUER.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 3, 1991 *
  30. * *
  31. *---------------------------------------------------------------------------------------------*
  32. * Functions: *
  33. * CC_Draw_Shape -- Custom draw shape handler. *
  34. * Call_Back -- Main game maintenance callback routine. *
  35. * Color_Cycle -- Handle the general palette color cycling. *
  36. * Crate_From_Name -- Given a crate name convert it to a crate type. *
  37. * Disk_Space_Available -- returns bytes of free disk space *
  38. * Do_Record_Playback -- handles saving/loading map pos & current object *
  39. * Fading_Table_Name -- Builds a theater specific fading table name. *
  40. * Fetch_Techno_Type -- Convert type and ID into TechnoTypeClass pointer. *
  41. * Force_CD_Available -- Ensures that specified CD is available. *
  42. * Get_Radar_Icon -- Builds and alloc a radar icon from a shape file *
  43. * Handle_Team -- Processes team selection command. *
  44. * Handle_View -- Either records or restores the tactical view. *
  45. * KN_To_Facing -- Converts a keyboard input number into a facing value. *
  46. * Keyboard_Process -- Processes the tactical map input codes. *
  47. * Language_Name -- Build filename for current language. *
  48. * List_Copy -- Makes a copy of a cell offset list. *
  49. * Main_Game -- Main game startup routine. *
  50. * Main_Loop -- This is the main game loop (as a single loop). *
  51. * Map_Edit_Loop -- a mini-main loop for map edit mode only *
  52. * Message_Input -- allows inter-player message input processing *
  53. * MixFileHandler -- Handles VQ file access. *
  54. * Name_From_Source -- retrieves the name for the given SourceType *
  55. * Owner_From_Name -- Convert an owner name into a bitfield. *
  56. * Play_Movie -- Plays a VQ movie. *
  57. * Shake_The_Screen -- Dispatcher that shakes the screen. *
  58. * Shape_Dimensions -- Determine the minimum rectangle for the shape. *
  59. * Source_From_Name -- Converts ASCII name into SourceType. *
  60. * Sync_Delay -- Forces the game into a 15 FPS rate. *
  61. * Theater_From_Name -- Converts ASCII name into a theater number. *
  62. * Unselect_All -- Causes all selected objects to become unselected. *
  63. * VQ_Call_Back -- Maintenance callback used for VQ movies. *
  64. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  65. #ifdef TESTCODE
  66. class A {
  67. public:
  68. enum {VAR=1};
  69. };
  70. template<class T>
  71. class B {
  72. public:
  73. enum {VAR2=T::VAR}; // this is the line in question.
  74. };
  75. B<A> test;
  76. #endif
  77. #include "function.h"
  78. #ifdef WIN32
  79. #include "tcpip.h"
  80. #else
  81. #include "fakesock.h"
  82. TcpipManagerClass Winsock;
  83. #endif
  84. #include <stdlib.h>
  85. #include <stdio.h>
  86. #include <string.h>
  87. #include <direct.h>
  88. #include <fcntl.h>
  89. #include <io.h>
  90. #include <dos.h>
  91. #include <share.h>
  92. #include "ccdde.h"
  93. #include "vortex.h"
  94. #define SHAPE_TRANS 0x40
  95. void * Get_Shape_Header_Data(void * ptr);
  96. extern bool Spawn_WChat(void);
  97. /****************************************
  98. ** Function prototypes for this module **
  99. *****************************************/
  100. bool Main_Loop(void);
  101. void Keyboard_Process(KeyNumType & input);
  102. static void Message_Input(KeyNumType &input);
  103. static void Color_Cycle(void);
  104. bool Map_Edit_Loop(void);
  105. extern "C" {
  106. bool UseOldShapeDraw = false;
  107. }
  108. #ifdef CHEAT_KEYS
  109. void Dump_Heap_Pointers( void );
  110. void Error_In_Heap_Pointers( char * string );
  111. #endif
  112. static void Do_Record_Playback(void);
  113. void Toggle_Formation(void);
  114. extern "C" {
  115. extern char * __nheapbeg;
  116. }
  117. //
  118. // Special module globals for recording and playback
  119. //
  120. char TeamEvent = 0; // 0 = no event, 1,2,3 = team event type
  121. char TeamNumber = 0; // which team was selected? (1-9)
  122. char FormationEvent = 0; // 0 = no event, 1 = formation was toggled
  123. /* -----------------10/14/96 7:29PM------------------
  124. --------------------------------------------------*/
  125. /***********************************************************************************************
  126. * Main_Game -- Main game startup routine. *
  127. * *
  128. * This is the first official routine of the game. It handles game initialization and *
  129. * the main game loop control. *
  130. * *
  131. * Initialization: *
  132. * - Init_Game handles one-time-only inits *
  133. * - Select_Game is responsible for initializations required for each new game played *
  134. * (these may be different depending on whether a multiplayer game is selected, and *
  135. * other parameters) *
  136. * - This routine performs any un-inits required, both for each game played, and one-time *
  137. * *
  138. * INPUT: argc -- Number of command line arguments (including program name itself). *
  139. * *
  140. * argv -- Array of command line argument pointers. *
  141. * *
  142. * OUTPUT: none *
  143. * *
  144. * WARNINGS: none *
  145. * *
  146. * HISTORY: *
  147. * 10/01/1994 JLB : Created. *
  148. *=============================================================================================*/
  149. void Main_Game(int argc, char * argv[])
  150. {
  151. static bool fade = true;
  152. /*
  153. ** Perform one-time-only initializations
  154. */
  155. if (!Init_Game(argc, argv)) {
  156. return;
  157. }
  158. /*
  159. ** Game processing loop:
  160. ** 1) Select which game to play, or whether to exit (don't fade the palette
  161. ** on the first game selection, but fade it in on subsequent calls)
  162. ** 2) Invoke either the main-loop routine, or the editor-loop routine,
  163. ** until they indicate that the user wants to exit the scenario.
  164. */
  165. while (Select_Game(fade)) {
  166. fade = false;
  167. ScenarioInit = 0; // Kludge.
  168. fade = true;
  169. /*
  170. ** Initialise the color lookup tables for the chronal vortex
  171. */
  172. ChronalVortex.Stop();
  173. ChronalVortex.Setup_Remap_Tables(Scen.Theater);
  174. /*
  175. ** Make the game screen visible, clear the keyboard buffer of spurious
  176. ** values, and then show the mouse. This PRESUMES that Select_Game() has
  177. ** told the map to draw itself.
  178. */
  179. GamePalette.Set(FADE_PALETTE_MEDIUM);
  180. Keyboard->Clear();
  181. /*
  182. ** Only show the mouse if we're not playing back a recording.
  183. */
  184. if (Session.Play) {
  185. Hide_Mouse();
  186. TeamEvent = 0;
  187. TeamNumber = 0;
  188. FormationEvent = 0;
  189. } else {
  190. Show_Mouse();
  191. }
  192. #ifdef WIN32
  193. if (Session.Type == GAME_INTERNET) {
  194. Register_Game_Start_Time();
  195. GameStatisticsPacketSent = false;
  196. PacketLater = NULL;
  197. ConnectionLost = false;
  198. } else {
  199. DDEServer.Disable();
  200. }
  201. #endif //WIN32
  202. #ifdef SCENARIO_EDITOR
  203. /*
  204. ** Scenario-editor version of main-loop processing
  205. */
  206. for (;;) {
  207. /*
  208. ** Non-scenario-editor-mode: call the game's main loop
  209. */
  210. if (!Debug_Map) {
  211. TimeQuake = false;
  212. if (Main_Loop()) {
  213. break;
  214. }
  215. if (SpecialDialog != SDLG_NONE) {
  216. switch (SpecialDialog) {
  217. case SDLG_SPECIAL:
  218. Map.Help_Text(TXT_NONE);
  219. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  220. Special_Dialog();
  221. Map.Revert_Mouse_Shape();
  222. SpecialDialog = SDLG_NONE;
  223. break;
  224. case SDLG_OPTIONS:
  225. Map.Help_Text(TXT_NONE);
  226. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  227. Options.Process();
  228. Map.Revert_Mouse_Shape();
  229. SpecialDialog = SDLG_NONE;
  230. break;
  231. case SDLG_SURRENDER:
  232. Map.Help_Text(TXT_NONE);
  233. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  234. if (Surrender_Dialog(TXT_SURRENDER)) {
  235. PlayerPtr->Flag_To_Lose();
  236. }
  237. SpecialDialog = SDLG_NONE;
  238. Map.Revert_Mouse_Shape();
  239. break;
  240. default:
  241. break;
  242. }
  243. }
  244. } else {
  245. /*
  246. ** Scenario-editor-mode: call the editor's main loop
  247. */
  248. if (Map_Edit_Loop()) {
  249. break;
  250. }
  251. }
  252. }
  253. #else
  254. /*
  255. ** Non-editor version of main-loop processing
  256. */
  257. for (;;) {
  258. TimeQuake = false;
  259. /*
  260. **call the game's main loop
  261. */
  262. //VG_MONO
  263. Mono_Print("About to call Main Loop in Main Game/n/n");
  264. if (Main_Loop()) {
  265. break;
  266. }
  267. /*
  268. ** If the SpecialDialog flag is set, invoke the given special dialog.
  269. ** This must be done outside the main loop, since the dialog will call
  270. ** Main_Loop(), allowing the game to run in the background.
  271. */
  272. if (SpecialDialog != SDLG_NONE) {
  273. switch (SpecialDialog) {
  274. case SDLG_SPECIAL:
  275. Map.Help_Text(TXT_NONE);
  276. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  277. Special_Dialog();
  278. Map.Revert_Mouse_Shape();
  279. SpecialDialog = SDLG_NONE;
  280. break;
  281. case SDLG_OPTIONS:
  282. Map.Help_Text(TXT_NONE);
  283. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  284. Options.Process();
  285. Map.Revert_Mouse_Shape();
  286. SpecialDialog = SDLG_NONE;
  287. break;
  288. case SDLG_SURRENDER:
  289. Map.Help_Text(TXT_NONE);
  290. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  291. if (Surrender_Dialog(TXT_SURRENDER)) {
  292. OutList.Add(EventClass(EventClass::DESTRUCT));
  293. }
  294. SpecialDialog = SDLG_NONE;
  295. Map.Revert_Mouse_Shape();
  296. break;
  297. default:
  298. break;
  299. }
  300. }
  301. }
  302. #endif
  303. #ifdef WIN32
  304. /*
  305. ** Send the game stats to WChat if we havnt already done so
  306. */
  307. if (!GameStatisticsPacketSent && PacketLater) {
  308. Send_Statistics_Packet();
  309. }
  310. #endif //WIN32
  311. /*
  312. ** Scenario is done; fade palette to black
  313. */
  314. BlackPalette.Set(FADE_PALETTE_SLOW);
  315. VisiblePage.Clear();
  316. /*
  317. ** Un-initialize whatever needs it, for each game played.
  318. **
  319. ** Shut down either the modem or network; they'll get re-initialized if
  320. ** the user selections those options again in Select_Game(). This
  321. ** "re-boots" the modem & network code, which I currently feel is safer
  322. ** than just letting it hang around.
  323. ** (Skip this step if we're in playback mode; the modem or net won't have
  324. ** been initialized in that case.)
  325. */
  326. if (Session.Record || Session.Play) {
  327. Session.RecordFile.Close();
  328. }
  329. if (Session.Type == GAME_NULL_MODEM || Session.Type == GAME_MODEM) {
  330. if (!Session.Play) {
  331. Modem_Signoff();
  332. }
  333. } else {
  334. if (Session.Type == GAME_IPX) {
  335. if (!Session.Play) {
  336. Shutdown_Network();
  337. }
  338. }
  339. }
  340. /*
  341. ** If we're playing back, the mouse will be hidden; show it.
  342. ** Also, set all variables back to normal, to return to the main menu.
  343. */
  344. if (Session.Play) {
  345. Show_Mouse();
  346. Session.Type = GAME_NORMAL;
  347. Session.Play = 0;
  348. }
  349. #ifdef WIN32
  350. if (Special.IsFromWChat) {
  351. Shutdown_Network(); // Clear up the pseudo IPX stuff
  352. Winsock.Close();
  353. Special.IsFromWChat = false;
  354. SpawnedFromWChat = false;
  355. DDEServer.Delete_MPlayer_Game_Info(); //Make sure we dont use the same start packet twice
  356. Session.Type = GAME_NORMAL; //Have to do this or we will got straight to the multiplayer menu
  357. Spawn_WChat(); //Will switch back to Wchat. It must be there because its been poking us
  358. }
  359. #endif //WIN32
  360. }
  361. /*
  362. ** Free the scenario description buffers
  363. */
  364. Session.Free_Scenario_Descriptions();
  365. }
  366. /***********************************************************************************************
  367. * Keyboard_Process -- Processes the tactical map input codes. *
  368. * *
  369. * This routine is used to process the input codes while the player *
  370. * has the tactical map displayed. It handles all the keys that *
  371. * are appropriate to that mode. *
  372. * *
  373. * INPUT: input -- Input code as returned from Input_Num(). *
  374. * *
  375. * OUTPUT: none *
  376. * *
  377. * WARNINGS: none *
  378. * *
  379. * HISTORY: *
  380. * 01/21/1992 JLB : Created. *
  381. * 07/04/1995 JLB : Handles team and map control hotkeys. *
  382. *=============================================================================================*/
  383. void Keyboard_Process(KeyNumType & input)
  384. {
  385. ObjectClass * obj;
  386. int index;
  387. /*
  388. ** Don't do anything if there is not keyboard event.
  389. */
  390. if (input == KN_NONE) {
  391. return;
  392. }
  393. /*
  394. ** For network & modem, process user input for inter-player messages.
  395. */
  396. Message_Input(input);
  397. #ifdef WIN32
  398. /*
  399. ** The VK_BIT must be stripped from the "plain" value of the key so that a comparison to
  400. ** KN_1, for example, will yield TRUE if in fact the "1" key was pressed.
  401. */
  402. KeyNumType plain = KeyNumType(input & ~(WWKEY_SHIFT_BIT|WWKEY_ALT_BIT|WWKEY_CTRL_BIT|WWKEY_VK_BIT));
  403. KeyNumType key = KeyNumType(input & ~WWKEY_VK_BIT);
  404. #else
  405. KeyNumType plain = KeyNumType(input & ~(KN_SHIFT_BIT|KN_ALT_BIT|KN_CTRL_BIT));
  406. KeyNumType key = plain;
  407. #endif
  408. #ifdef CHEAT_KEYS
  409. if (Debug_Flag) {
  410. HousesType h;
  411. switch (int(input)) {
  412. case int(int(KN_M) | int(KN_SHIFT_BIT)):
  413. case int(int(KN_M) | int(KN_ALT_BIT)):
  414. case int(int(KN_M) | int(KN_CTRL_BIT)):
  415. for (h = HOUSE_FIRST; h < HOUSE_COUNT; h++) {
  416. Houses.Ptr(h)->Refund_Money(10000);
  417. }
  418. break;
  419. default:
  420. break;
  421. }
  422. }
  423. #endif
  424. #ifdef VIRGIN_CHEAT_KEYS
  425. if (Debug_Playtest && input == (KN_W|KN_ALT_BIT)) {
  426. PlayerPtr->Blockage = false;
  427. PlayerPtr->Flag_To_Win();
  428. }
  429. #endif
  430. #ifdef CHEAT_KEYS
  431. #ifdef WIN32
  432. if (Debug_Playtest && input == (KA_W|KN_ALT_BIT)) {
  433. #else
  434. if (Debug_Playtest && input == (KN_W|KN_ALT_BIT)) {
  435. #endif
  436. PlayerPtr->Blockage = false;
  437. PlayerPtr->Flag_To_Win();
  438. }
  439. if ((Debug_Flag || Debug_Playtest) && plain == KN_F4) {
  440. if (Session.Type == GAME_NORMAL) {
  441. Debug_Unshroud = (Debug_Unshroud == false);
  442. Map.Flag_To_Redraw(true);
  443. }
  444. }
  445. if (Debug_Flag && input == KN_SLASH) {
  446. if (Session.Type != GAME_NORMAL) {
  447. SpecialDialog = SDLG_SPECIAL;
  448. input = KN_NONE;
  449. } else {
  450. Special_Dialog();
  451. }
  452. }
  453. #endif
  454. /*
  455. ** Process prerecorded team selection. This will be an additive select
  456. ** if the SHIFT key is held down. It will create the team if the
  457. ** CTRL or ALT key is held down.
  458. */
  459. int action = 0;
  460. #ifdef WIN32
  461. if (input & WWKEY_SHIFT_BIT) action = 1;
  462. if (input & WWKEY_ALT_BIT) action = 3;
  463. if (input & WWKEY_CTRL_BIT) action = 2;
  464. #else
  465. if (input & KN_SHIFT_BIT) action = 1;
  466. if (input & KN_ALT_BIT) action = 3;
  467. if (input & KN_CTRL_BIT) action = 2;
  468. #endif
  469. /*
  470. ** If the "N" key is pressed, then select the next object.
  471. */
  472. if (key != 0 && key == Options.KeyNext) {
  473. if (action) {
  474. obj = Map.Prev_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
  475. } else {
  476. obj = Map.Next_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
  477. }
  478. if (obj != NULL) {
  479. Unselect_All();
  480. obj->Select();
  481. Map.Center_Map();
  482. Map.Flag_To_Redraw(true);
  483. }
  484. input = KN_NONE;
  485. }
  486. if (key != 0 && key == Options.KeyPrevious) {
  487. if (action) {
  488. obj = Map.Next_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
  489. } else {
  490. obj = Map.Prev_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
  491. }
  492. if (obj != NULL) {
  493. Unselect_All();
  494. obj->Select();
  495. Map.Center_Map();
  496. Map.Flag_To_Redraw(true);
  497. }
  498. input = KN_NONE;
  499. }
  500. /*
  501. ** All selected units will go into idle mode.
  502. */
  503. if (key != 0 && key == Options.KeyStop) {
  504. if (CurrentObject.Count()) {
  505. for (index = 0; index < CurrentObject.Count(); index++) {
  506. ObjectClass const * tech = CurrentObject[index];
  507. if (tech != NULL && (tech->Can_Player_Move() || (tech->Can_Player_Fire() && tech->What_Am_I() != RTTI_BUILDING))) {
  508. OutList.Add(EventClass(EventClass::IDLE, TargetClass(tech)));
  509. }
  510. }
  511. }
  512. input = KN_NONE;
  513. }
  514. /*
  515. ** All selected units will attempt to go into guard area mode.
  516. */
  517. if (key != 0 && key == Options.KeyGuard) {
  518. if (CurrentObject.Count()) {
  519. for (index = 0; index < CurrentObject.Count(); index++) {
  520. ObjectClass const * tech = CurrentObject[index];
  521. if (tech != NULL && tech->Can_Player_Move() && tech->Can_Player_Fire()) {
  522. OutList.Add(EventClass(TargetClass(tech), MISSION_GUARD_AREA));
  523. }
  524. }
  525. }
  526. input = KN_NONE;
  527. }
  528. /*
  529. ** All selected units will attempt to scatter.
  530. */
  531. if (key != 0 && key == Options.KeyScatter) {
  532. if (CurrentObject.Count()) {
  533. for (index = 0; index < CurrentObject.Count(); index++) {
  534. ObjectClass const * tech = CurrentObject[index];
  535. if (tech != NULL && tech->Can_Player_Move()) {
  536. OutList.Add(EventClass(EventClass::SCATTER, TargetClass(tech)));
  537. }
  538. }
  539. }
  540. input = KN_NONE;
  541. }
  542. /*
  543. ** Center the map around the currently selected objects. If no
  544. ** objects are selected, then fall into the home case.
  545. */
  546. if (key != 0 && (key == Options.KeyHome1 || key == Options.KeyHome2)) {
  547. if (CurrentObject.Count()) {
  548. Map.Center_Map();
  549. #ifdef WIN32
  550. Map.Flag_To_Redraw(true);
  551. #endif
  552. input = KN_NONE;
  553. } else {
  554. input = Options.KeyBase;
  555. }
  556. }
  557. /*
  558. ** Center the map about the construction yard or construction vehicle
  559. ** if one is present.
  560. */
  561. if (key != 0 && key == Options.KeyBase) {
  562. Unselect_All();
  563. if (PlayerPtr->CurBuildings) {
  564. for (index = 0; index < Buildings.Count(); index++) {
  565. BuildingClass * building = Buildings.Ptr(index);
  566. if (building != NULL && !building->IsInLimbo && building->House == PlayerPtr && *building == STRUCT_CONST) {
  567. Unselect_All();
  568. building->Select();
  569. if (building->IsLeader) break;
  570. }
  571. }
  572. }
  573. if (CurrentObject.Count() == 0 && PlayerPtr->CurUnits) {
  574. for (index = 0; index < Units.Count(); index++) {
  575. UnitClass * unit = Units.Ptr(index);
  576. if (unit != NULL && !unit->IsInLimbo && unit->House == PlayerPtr && *unit == UNIT_MCV) {
  577. Unselect_All();
  578. unit->Select();
  579. break;
  580. }
  581. }
  582. }
  583. if (CurrentObject.Count()) {
  584. Map.Center_Map();
  585. } else {
  586. if (PlayerPtr->Center != 0) {
  587. Map.Center_Map(PlayerPtr->Center);
  588. }
  589. }
  590. Map.Flag_To_Redraw(true);
  591. input = KN_NONE;
  592. }
  593. /*
  594. ** Toggle the status of formation for the current team
  595. */
  596. if (key != 0 && key == Options.KeyFormation) {
  597. Toggle_Formation();
  598. input = KN_NONE;
  599. }
  600. #ifdef TOFIX
  601. /*
  602. ** For multiplayer, 'R' pops up the surrender dialog.
  603. */
  604. if (input != 0 && input == Options.KeyResign) {
  605. if (!PlayerLoses && /*Session.Type != GAME_NORMAL &&*/ !PlayerPtr->IsDefeated) {
  606. SpecialDialog = SDLG_SURRENDER;
  607. input = KN_NONE;
  608. }
  609. input = KN_NONE;
  610. }
  611. #endif
  612. /*
  613. ** Handle making and breaking alliances.
  614. */
  615. if (key != 0 && key == Options.KeyAlliance) {
  616. if (Session.Type != GAME_NORMAL || Debug_Flag) {
  617. if (CurrentObject.Count() && !PlayerPtr->IsDefeated) {
  618. if (CurrentObject[0]->Owner() != PlayerPtr->Class->House) {
  619. OutList.Add(EventClass(EventClass::ALLY, CurrentObject[0]->Owner()));
  620. }
  621. }
  622. }
  623. input = KN_NONE;
  624. }
  625. /*
  626. ** Select all the units on the current display. This is equivalent to
  627. ** drag selecting the whole view.
  628. */
  629. if (key != 0 && key == Options.KeySelectView) {
  630. Map.Select_These(0x00000000, XY_Coord(Map.TacLeptonWidth, Map.TacLeptonHeight));
  631. input = KN_NONE;
  632. }
  633. /*
  634. ** Toggles the repair state similarly to pressing the repair button.
  635. */
  636. if (key != 0 && key == Options.KeyRepair) {
  637. Map.Repair_Mode_Control(-1);
  638. input = KN_NONE;
  639. }
  640. /*
  641. ** Toggles the sell state similarly to pressing the sell button.
  642. */
  643. if (key != 0 && key == Options.KeySell) {
  644. Map.Sell_Mode_Control(-1);
  645. input = KN_NONE;
  646. }
  647. /*
  648. ** Toggles the map zoom mode similarly to pressing the map button.
  649. */
  650. if (key != 0 && key == Options.KeyMap) {
  651. Map.Zoom_Mode_Control();
  652. input = KN_NONE;
  653. }
  654. /*
  655. ** Scrolls the sidebar up one slot.
  656. */
  657. if (key != 0 && key == Options.KeySidebarUp) {
  658. Map.SidebarClass::Scroll(true, -1);
  659. input = KN_NONE;
  660. }
  661. /*
  662. ** Scrolls the sidebar down one slot.
  663. */
  664. if (key != 0 && key == Options.KeySidebarDown) {
  665. Map.SidebarClass::Scroll(false, -1);
  666. input = KN_NONE;
  667. }
  668. /*
  669. ** Brings up the options dialog box.
  670. */
  671. if (key != 0 && (key == Options.KeyOption1 || key == Options.KeyOption2)) {
  672. Map.Help_Text(TXT_NONE); // Turns off help text.
  673. Queue_Options();
  674. input = KN_NONE;
  675. }
  676. /*
  677. ** Scrolls the tactical map in the direction specified.
  678. */
  679. int distance = CELL_LEPTON_W;
  680. if (key != 0 && key == Options.KeyScrollLeft) {
  681. Map.Scroll_Map(DIR_W, distance, true);
  682. input = KN_NONE;
  683. }
  684. if (key != 0 && key == Options.KeyScrollRight) {
  685. Map.Scroll_Map(DIR_E, distance, true);
  686. input = KN_NONE;
  687. }
  688. if (key != 0 && key == Options.KeyScrollUp) {
  689. Map.Scroll_Map(DIR_N, distance, true);
  690. input = KN_NONE;
  691. }
  692. if (key != 0 && key == Options.KeyScrollDown) {
  693. Map.Scroll_Map(DIR_S, distance, true);
  694. input = KN_NONE;
  695. }
  696. /*
  697. ** Teams are handled by the 10 special team keys. The manual comparison
  698. ** to the KN numbers is because the Windows keyboard driver can vary
  699. ** the base code number for the key depending on the shift or alt key
  700. ** state!
  701. */
  702. if (input != 0 && (plain == Options.KeyTeam1 || plain == KN_1)) {
  703. Handle_Team(0, action);
  704. input = KN_NONE;
  705. }
  706. if (input != 0 && (plain == Options.KeyTeam2 || plain == KN_2)) {
  707. Handle_Team(1, action);
  708. input = KN_NONE;
  709. }
  710. if (input != 0 && (plain == Options.KeyTeam3 || plain == KN_3)) {
  711. Handle_Team(2, action);
  712. input = KN_NONE;
  713. }
  714. if (input != 0 && (plain == Options.KeyTeam4 || plain == KN_4)) {
  715. Handle_Team(3, action);
  716. input = KN_NONE;
  717. }
  718. if (input != 0 && (plain == Options.KeyTeam5 || plain == KN_5)) {
  719. Handle_Team(4, action);
  720. input = KN_NONE;
  721. }
  722. if (input != 0 && (plain == Options.KeyTeam6 || plain == KN_6)) {
  723. Handle_Team(5, action);
  724. input = KN_NONE;
  725. }
  726. if (input != 0 && (plain == Options.KeyTeam7 || plain == KN_7)) {
  727. Handle_Team(6, action);
  728. input = KN_NONE;
  729. }
  730. if (input != 0 && (plain == Options.KeyTeam8 || plain == KN_8)) {
  731. Handle_Team(7, action);
  732. input = KN_NONE;
  733. }
  734. if (input != 0 && (plain == Options.KeyTeam9 || plain == KN_9)) {
  735. Handle_Team(8, action);
  736. input = KN_NONE;
  737. }
  738. if (input != 0 && (plain == Options.KeyTeam10 || plain == KN_0)) {
  739. Handle_Team(9, action);
  740. input = KN_NONE;
  741. }
  742. /*
  743. ** Handle the bookmark hotkeys.
  744. */
  745. if (input != 0 && plain == Options.KeyBookmark1 && !Debug_Map) {
  746. Handle_View(0, action);
  747. input = KN_NONE;
  748. }
  749. if (input != 0 && plain == Options.KeyBookmark2 && !Debug_Map) {
  750. Handle_View(1, action);
  751. input = KN_NONE;
  752. }
  753. if (input != 0 && plain == Options.KeyBookmark3 && !Debug_Map) {
  754. Handle_View(2, action);
  755. input = KN_NONE;
  756. }
  757. if (input != 0 && plain == Options.KeyBookmark4 && !Debug_Map) {
  758. Handle_View(3, action);
  759. input = KN_NONE;
  760. }
  761. #ifdef CHEAT_KEYS
  762. if (input != 0 && Debug_Flag && input && (input & KN_RLSE_BIT) == 0) {
  763. Debug_Key(input);
  764. }
  765. #endif
  766. }
  767. void Toggle_Formation(void) {
  768. int team = -1;
  769. long minx = 0x7FFFFFFFL, miny = 0x7FFFFFFFL;
  770. long maxx = 0, maxy = 0;
  771. int index;
  772. bool setform = 0;
  773. //
  774. // Recording support
  775. //
  776. if (Session.Record) {
  777. FormationEvent = 1;
  778. }
  779. /*
  780. ** Find the first selected object that is a member of a team, and
  781. ** register his group as the team we're using. Once we find the team
  782. ** number, update the 'setform' flag to know whether we should be setting
  783. ** the formation's offsets, or clearing them. If they currently have
  784. ** illegal offsets (as in 0x80000000), then we're setting.
  785. */
  786. for (index = 0; index < Units.Count(); index++) {
  787. UnitClass * obj = Units.Ptr(index);
  788. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->IsSelected) {
  789. team = obj->Group;
  790. if (team != -1) {
  791. setform = obj->XFormOffset == (int)0x80000000;
  792. TeamSpeed[team] = SPEED_WHEEL;
  793. TeamMaxSpeed[team] = MPH_LIGHT_SPEED;
  794. break;
  795. }
  796. }
  797. }
  798. if (team == -1) {
  799. for (index = 0; index < Infantry.Count(); index++) {
  800. InfantryClass * obj = Infantry.Ptr(index);
  801. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->IsSelected) {
  802. team = obj->Group;
  803. if (team != -1) {
  804. setform = obj->XFormOffset == (int)0x80000000;
  805. TeamSpeed[team] = SPEED_WHEEL;
  806. TeamMaxSpeed[team] = MPH_LIGHT_SPEED;
  807. break;
  808. }
  809. }
  810. }
  811. }
  812. if (team == -1) {
  813. for (index = 0; index < Vessels.Count(); index++) {
  814. VesselClass * obj = Vessels.Ptr(index);
  815. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->IsSelected) {
  816. team = obj->Group;
  817. if (team != -1) {
  818. setform = obj->XFormOffset == 0x80000000UL;
  819. TeamSpeed[team] = SPEED_WHEEL;
  820. TeamMaxSpeed[team] = MPH_LIGHT_SPEED;
  821. break;
  822. }
  823. }
  824. }
  825. }
  826. if (team == -1) return;
  827. /*
  828. ** Now that we have a team, let's go set (or clear) the formation offsets.
  829. */
  830. for (index = 0; index < Units.Count(); index++) {
  831. UnitClass * obj = Units.Ptr(index);
  832. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team) {
  833. obj->Mark(MARK_CHANGE);
  834. if (setform) {
  835. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  836. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  837. if (xc < minx) minx = xc;
  838. if (xc > maxx) maxx = xc;
  839. if (yc < miny) miny = yc;
  840. if (yc > maxy) maxy = yc;
  841. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  842. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  843. TeamSpeed[team] = obj->Class->Speed;
  844. }
  845. } else {
  846. obj->XFormOffset = obj->YFormOffset = (int)0x80000000;
  847. }
  848. }
  849. }
  850. for (index = 0; index < Infantry.Count(); index++) {
  851. InfantryClass * obj = Infantry.Ptr(index);
  852. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team) {
  853. obj->Mark(MARK_CHANGE);
  854. if (setform) {
  855. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  856. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  857. if (xc < minx) minx = xc;
  858. if (xc > maxx) maxx = xc;
  859. if (yc < miny) miny = yc;
  860. if (yc > maxy) maxy = yc;
  861. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  862. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  863. }
  864. } else {
  865. obj->XFormOffset = obj->YFormOffset = (int)0x80000000;
  866. }
  867. }
  868. }
  869. for (index = 0; index < Vessels.Count(); index++) {
  870. VesselClass * obj = Vessels.Ptr(index);
  871. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team) {
  872. obj->Mark(MARK_CHANGE);
  873. if (setform) {
  874. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  875. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  876. if (xc < minx) minx = xc;
  877. if (xc > maxx) maxx = xc;
  878. if (yc < miny) miny = yc;
  879. if (yc > maxy) maxy = yc;
  880. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  881. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  882. }
  883. } else {
  884. obj->XFormOffset = obj->YFormOffset = 0x80000000UL;
  885. }
  886. }
  887. }
  888. /*
  889. ** All the units have been counted to find the bounding rectangle and
  890. ** center of the formation, or to clear their offsets. Now, if we're to
  891. ** set them into formation, proceed to do so. Otherwise, bail.
  892. */
  893. if (setform) {
  894. int centerx = (int)((maxx - minx)/2)+minx;
  895. int centery = (int)((maxy - miny)/2)+miny;
  896. for (index = 0; index < Units.Count(); index++) {
  897. UnitClass * obj = Units.Ptr(index);
  898. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team) {
  899. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  900. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  901. obj->XFormOffset = xc - centerx;
  902. obj->YFormOffset = yc - centery;
  903. }
  904. }
  905. for (index = 0; index < Infantry.Count(); index++) {
  906. InfantryClass * obj = Infantry.Ptr(index);
  907. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team ) {
  908. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  909. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  910. obj->XFormOffset = xc - centerx;
  911. obj->YFormOffset = yc - centery;
  912. }
  913. }
  914. for (index = 0; index < Vessels.Count(); index++) {
  915. VesselClass * obj = Vessels.Ptr(index);
  916. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team ) {
  917. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  918. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  919. obj->XFormOffset = xc - centerx;
  920. obj->YFormOffset = yc - centery;
  921. }
  922. }
  923. }
  924. }
  925. /***********************************************************************************************
  926. * Message_Input -- allows inter-player message input processing *
  927. * *
  928. * INPUT: *
  929. * input key value *
  930. * *
  931. * OUTPUT: *
  932. * none. *
  933. * *
  934. * WARNINGS: *
  935. * none. *
  936. * *
  937. * HISTORY: *
  938. * 05/22/1995 BRR : Created. *
  939. *=============================================================================================*/
  940. #pragma off (unreferenced)
  941. static void Message_Input(KeyNumType &input)
  942. {
  943. int rc;
  944. char txt[MAX_MESSAGE_LENGTH+32];
  945. int id;
  946. SerialPacketType * serial_packet;
  947. int i;
  948. KeyNumType copy_input;
  949. //char *msg;
  950. /*
  951. ** Check keyboard input for a request to send a message.
  952. ** The 'to' argument for Add_Edit is prefixed to the message buffer; the
  953. ** message buffer is big enough for the 'to' field plus MAX_MESSAGE_LENGTH.
  954. ** To send the message, calling Get_Edit_Buf retrieves the buffer minus the
  955. ** 'to' portion. At the other end, the buffer allocated to display the
  956. ** message must be MAX_MESSAGE_LENGTH plus the size of "From: xxx (house)".
  957. */
  958. if (Session.Type != GAME_NORMAL && Session.Type != GAME_SKIRMISH && input >= KN_F1 && input < (KN_F1 + Session.MaxPlayers) && !Session.Messages.Is_Edit()) {
  959. memset (txt, 0, 40);
  960. /*
  961. ** For a serial game, send a message on F1 or F4; set 'txt' to the
  962. ** "Message:" string & add an editable message to the list.
  963. */
  964. if (Session.Type==GAME_NULL_MODEM || Session.Type==GAME_MODEM) {
  965. if (input==KN_F1 || input==(KN_F1 + Session.MaxPlayers - 1)) {
  966. strcpy(txt, Text_String(TXT_MESSAGE)); // "Message:"
  967. Session.Messages.Add_Edit (Session.ColorIdx,
  968. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  969. Map.Flag_To_Redraw(false);
  970. }
  971. } else if ((Session.Type == GAME_IPX || Session.Type == GAME_INTERNET) && !Session.Messages.Is_Edit()) {
  972. /*
  973. ** For a network game:
  974. ** F1-F7 = "To <name> (house):" (only allowed if we're not in ObiWan mode)
  975. ** F8 = "To All:"
  976. */
  977. if (input==(KN_F1 + Session.MaxPlayers - 1)) {
  978. Session.MessageAddress = IPXAddressClass(); // set to broadcast
  979. strcpy(txt, Text_String(TXT_TO_ALL)); // "To All:"
  980. Session.Messages.Add_Edit(Session.ColorIdx,
  981. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  982. Map.Flag_To_Redraw(false);
  983. } else if ((input - KN_F1) < Ipx.Num_Connections() && !Session.ObiWan) {
  984. id = Ipx.Connection_ID(input - KN_F1);
  985. Session.MessageAddress = (*(Ipx.Connection_Address (id)));
  986. sprintf(txt, Text_String(TXT_TO), Ipx.Connection_Name(id));
  987. Session.Messages.Add_Edit(Session.ColorIdx,
  988. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  989. Map.Flag_To_Redraw(false);
  990. }
  991. }
  992. }
  993. /*
  994. ** Process message-system input; send the message out if RETURN is hit.
  995. */
  996. copy_input = input;
  997. rc = Session.Messages.Input(input);
  998. /*
  999. ** If a single character has been added to an edit buffer, update the display.
  1000. */
  1001. if (rc == 1 && Session.Type != GAME_NORMAL) {
  1002. Map.Flag_To_Redraw(false);
  1003. }
  1004. /*
  1005. ** If backspace was hit, redraw the map. If the edit message was removed,
  1006. ** the map must be force-drawn, since it won't be able to compute the
  1007. ** cells to redraw; otherwise, let the map compute the cells to redraw,
  1008. ** by not force-drawing it, but just setting the IsToRedraw bit.
  1009. */
  1010. if (rc==2 && Session.Type != GAME_NORMAL) {
  1011. if (copy_input==KN_ESC) {
  1012. Map.Flag_To_Redraw(true);
  1013. } else {
  1014. Map.Flag_To_Redraw(false);
  1015. }
  1016. Map.DisplayClass::IsToRedraw = true;
  1017. }
  1018. /*
  1019. ** Send a message
  1020. */
  1021. if ((rc==3 || rc==4) && Session.Type != GAME_NORMAL && Session.Type != GAME_SKIRMISH) {
  1022. /*
  1023. ** Serial game: fill in a SerialPacketType & send it.
  1024. ** (Note: The size of the SerialPacketType.Command must be the same as
  1025. ** the EventClass.Type!)
  1026. */
  1027. if (Session.Type==GAME_NULL_MODEM || Session.Type==GAME_MODEM) {
  1028. serial_packet = (SerialPacketType *)NullModem.BuildBuf;
  1029. serial_packet->Command = SERIAL_MESSAGE;
  1030. strcpy (serial_packet->Name, Session.Players[0]->Name);
  1031. serial_packet->ID = Session.ColorIdx;
  1032. if (rc==3) {
  1033. strcpy (serial_packet->Message.Message, Session.Messages.Get_Edit_Buf());
  1034. } else {
  1035. strcpy (serial_packet->Message.Message, Session.Messages.Get_Overflow_Buf());
  1036. Session.Messages.Clear_Overflow_Buf();
  1037. }
  1038. /*
  1039. ** Send the message, and store this message in our LastMessage
  1040. ** buffer; the computer may send us a version of it later.
  1041. */
  1042. NullModem.Send_Message(NullModem.BuildBuf,
  1043. sizeof(SerialPacketType), 1);
  1044. strcpy(Session.LastMessage, serial_packet->Message.Message);
  1045. } else if (Session.Type == GAME_IPX || Session.Type == GAME_INTERNET) {
  1046. /*
  1047. ** Network game: fill in a GlobalPacketType & send it.
  1048. */
  1049. Session.GPacket.Command = NET_MESSAGE;
  1050. strcpy (Session.GPacket.Name, Session.Players[0]->Name);
  1051. Session.GPacket.Message.Color = Session.ColorIdx;
  1052. Session.GPacket.Message.NameCRC = Compute_Name_CRC(Session.GameName);
  1053. if (rc==3) {
  1054. strcpy (Session.GPacket.Message.Buf, Session.Messages.Get_Edit_Buf());
  1055. } else {
  1056. strcpy (Session.GPacket.Message.Buf,
  1057. Session.Messages.Get_Overflow_Buf());
  1058. Session.Messages.Clear_Overflow_Buf();
  1059. }
  1060. /*
  1061. ** If 'F4' was hit, MessageAddress will be a broadcast address; send
  1062. ** the message to every player we have a connection with.
  1063. */
  1064. if (Session.MessageAddress.Is_Broadcast()) {
  1065. for (i = 0; i < Ipx.Num_Connections(); i++) {
  1066. Ipx.Send_Global_Message(&Session.GPacket,
  1067. sizeof(GlobalPacketType), 1,
  1068. Ipx.Connection_Address(Ipx.Connection_ID(i)));
  1069. Ipx.Service();
  1070. }
  1071. } else {
  1072. /*
  1073. ** Otherwise, MessageAddress contains the exact address to send to.
  1074. ** Send to that address only.
  1075. */
  1076. Ipx.Send_Global_Message(&Session.GPacket,
  1077. sizeof(GlobalPacketType), 1,
  1078. &Session.MessageAddress);
  1079. Ipx.Service();
  1080. }
  1081. /*
  1082. ** Store this message in our LastMessage buffer; the computer may send
  1083. ** us a version of it later.
  1084. */
  1085. strcpy(Session.LastMessage, Session.GPacket.Message.Buf);
  1086. }
  1087. /*
  1088. ** Tell the map to completely update itself, since a message is now missing.
  1089. */
  1090. Map.Flag_To_Redraw(true);
  1091. }
  1092. }
  1093. #pragma on (unreferenced)
  1094. /***********************************************************************************************
  1095. * Color_Cycle -- Handle the general palette color cycling. *
  1096. * *
  1097. * This is a maintenance routine that handles the color cycling. It should be called as *
  1098. * often as necessary to achieve smooth color cycling effects -- at least 8 times a second. *
  1099. * *
  1100. * INPUT: none *
  1101. * *
  1102. * OUTPUT: none *
  1103. * *
  1104. * WARNINGS: none *
  1105. * *
  1106. * HISTORY: *
  1107. * 05/31/1994 JLB : Created. *
  1108. * 06/10/1994 JLB : Uses new cycle color values. *
  1109. * 12/21/1994 JLB : Handles text fade color. *
  1110. * 07/16/1996 JLB : Faster pulsing of white color. *
  1111. *=============================================================================================*/
  1112. void Color_Cycle(void)
  1113. {
  1114. static CDTimerClass<SystemTimerClass> _timer;
  1115. static CDTimerClass<SystemTimerClass> _ftimer;
  1116. static bool _up = false;
  1117. static int val = 255;
  1118. bool changed = false;
  1119. if (Options.IsPaletteScroll) {
  1120. /*
  1121. ** Process the fading white color. It is used for the radar box and other glowing
  1122. ** game interface elements.
  1123. */
  1124. if (!_ftimer) {
  1125. _ftimer = TIMER_SECOND/6;
  1126. #define STEP_RATE 20
  1127. if (_up) {
  1128. val += STEP_RATE;
  1129. if (val > 150) {
  1130. val = 150;
  1131. _up = false;
  1132. }
  1133. } else {
  1134. val -= STEP_RATE;
  1135. if (val < 0x20) {
  1136. val = 0x20;
  1137. _up = true;
  1138. }
  1139. }
  1140. /*
  1141. ** Set the pulse color as the proportional value between white and the
  1142. ** minimum value for pulsing.
  1143. */
  1144. InGamePalette[CC_PULSE_COLOR] = GamePalette[WHITE];
  1145. InGamePalette[CC_PULSE_COLOR].Adjust(val, BlackColor);
  1146. /*
  1147. ** Pulse the glowing embers between medium and dark red.
  1148. */
  1149. InGamePalette[CC_EMBER_COLOR] = RGBClass(255, 80, 80);
  1150. InGamePalette[CC_EMBER_COLOR].Adjust(val, BlackColor);
  1151. changed = true;
  1152. }
  1153. /*
  1154. ** Process the color cycling effects -- water.
  1155. */
  1156. if (!_timer) {
  1157. _timer = TIMER_SECOND/4;
  1158. RGBClass first = InGamePalette[CYCLE_COLOR_START+CYCLE_COLOR_COUNT-1];
  1159. for (int index = CYCLE_COLOR_START+CYCLE_COLOR_COUNT-1; index >= CYCLE_COLOR_START; index--) {
  1160. InGamePalette[index] = InGamePalette[index-1];
  1161. }
  1162. InGamePalette[CYCLE_COLOR_START] = first;
  1163. changed = true;
  1164. }
  1165. /*
  1166. ** If any of the processing functions changed the palette, then this palette must be
  1167. ** passed to the system.
  1168. */
  1169. if (changed) {
  1170. BStart(BENCH_PALETTE);
  1171. InGamePalette.Set();
  1172. // Set_Palette(InGamePalette);
  1173. BEnd(BENCH_PALETTE);
  1174. }
  1175. }
  1176. }
  1177. /***********************************************************************************************
  1178. * Call_Back -- Main game maintenance callback routine. *
  1179. * *
  1180. * This routine handles all the "real time" processing that needs to *
  1181. * occur. This includes palette fading and sound updating. It needs *
  1182. * to be called as often as possible. *
  1183. * *
  1184. * INPUT: none *
  1185. * *
  1186. * OUTPUT: none *
  1187. * *
  1188. * WARNINGS: none *
  1189. * *
  1190. * HISTORY: *
  1191. * 10/07/1992 JLB : Created. *
  1192. *=============================================================================================*/
  1193. void Call_Back(void)
  1194. {
  1195. /*
  1196. ** Music and speech maintenance
  1197. */
  1198. if (SampleType) {
  1199. Sound_Callback();
  1200. Theme.AI();
  1201. Speak_AI();
  1202. }
  1203. /*
  1204. ** Network maintenance.
  1205. */
  1206. if (Session.Type == GAME_IPX || Session.Type == GAME_INTERNET) {
  1207. IPX_Call_Back();
  1208. }
  1209. /*
  1210. ** Serial game maintenance.
  1211. */
  1212. if (Session.Type == GAME_NULL_MODEM || ((Session.Type == GAME_MODEM) && Session.ModemService)) {
  1213. NullModem.Service();
  1214. }
  1215. }
  1216. void IPX_Call_Back(void)
  1217. {
  1218. Ipx.Service();
  1219. /*
  1220. ** Read packets only if the game is "closed", so we don't steal global
  1221. ** messages from the connection dialogs.
  1222. */
  1223. if (!Session.NetOpen) {
  1224. if (Ipx.Get_Global_Message (&Session.GPacket, &Session.GPacketlen, &Session.GAddress, &Session.GProductID)) {
  1225. if (Session.GProductID == IPXGlobalConnClass::COMMAND_AND_CONQUER0) {
  1226. /*
  1227. ** If this is another player signing off, remove the connection &
  1228. ** mark that player's house as non-human, so the computer will take
  1229. ** it over.
  1230. */
  1231. if (Session.GPacket.Command == NET_SIGN_OFF) {
  1232. for (int i = 0; i < Ipx.Num_Connections(); i++) {
  1233. int id = Ipx.Connection_ID(i);
  1234. if (Session.GAddress == (*Ipx.Connection_Address(id))) {
  1235. Destroy_Connection(id, 0);
  1236. }
  1237. }
  1238. } else {
  1239. /*
  1240. ** Process a message from another user.
  1241. */
  1242. if (Session.GPacket.Command == NET_MESSAGE) {
  1243. bool msg_ok = false;
  1244. /*
  1245. ** If NetProtect is set, make sure this message came from within
  1246. ** this game.
  1247. */
  1248. if (!Session.NetProtect) {
  1249. msg_ok = true;
  1250. } else {
  1251. if (Session.GPacket.Message.NameCRC ==
  1252. Compute_Name_CRC(Session.GameName)) {
  1253. msg_ok = true;
  1254. } else {
  1255. msg_ok = false;
  1256. }
  1257. }
  1258. if (msg_ok) {
  1259. if (!Session.Messages.Concat_Message(Session.GPacket.Name,
  1260. Session.GPacket.Message.Color,
  1261. Session.GPacket.Message.Buf, Rule.MessageDelay * TICKS_PER_MINUTE)) {
  1262. Session.Messages.Add_Message (Session.GPacket.Name,
  1263. Session.GPacket.Message.Color,
  1264. Session.GPacket.Message.Buf,
  1265. Session.GPacket.Message.Color,
  1266. TPF_6PT_GRAD | TPF_USE_GRAD_PAL |
  1267. TPF_FULLSHADOW, Rule.MessageDelay * TICKS_PER_MINUTE);
  1268. Sound_Effect(VOC_INCOMING_MESSAGE);
  1269. }
  1270. /*
  1271. ** Tell the map to do a partial update (just to force the messages
  1272. ** to redraw).
  1273. */
  1274. Map.Flag_To_Redraw(true);
  1275. /*
  1276. ** Save this message in our last-message buffer
  1277. */
  1278. strcpy(Session.LastMessage, Session.GPacket.Message.Buf);
  1279. }
  1280. } else {
  1281. Process_Global_Packet(&Session.GPacket, &Session.GAddress);
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. }
  1288. /***********************************************************************************************
  1289. * Language_Name -- Build filename for current language. *
  1290. * *
  1291. * This routine attaches a language specific suffix to the base *
  1292. * filename provided. Typical use of this is when loading language *
  1293. * specific files at game initialization time. *
  1294. * *
  1295. * INPUT: basename -- Base name to append language specific *
  1296. * extension to. *
  1297. * *
  1298. * OUTPUT: Returns with pointer to completed filename. *
  1299. * *
  1300. * WARNINGS: The return pointer value is valid only until the next time *
  1301. * this routine is called. *
  1302. * *
  1303. * HISTORY: *
  1304. * 10/07/1992 JLB : Created. *
  1305. *=============================================================================================*/
  1306. char const * Language_Name(char const * basename)
  1307. {
  1308. static char _fullname[_MAX_FNAME+_MAX_EXT];
  1309. if (!basename) return(NULL);
  1310. sprintf(_fullname, "%s.ENG", basename);
  1311. return(_fullname);
  1312. }
  1313. /***********************************************************************************************
  1314. * Source_From_Name -- Converts ASCII name into SourceType. *
  1315. * *
  1316. * This routine is used to convert an ASCII name representing a *
  1317. * SourceType into the actual SourceType value. Typically, this is *
  1318. * used when processing the scenario INI file. *
  1319. * *
  1320. * INPUT: name -- The ASCII source name to process. *
  1321. * *
  1322. * OUTPUT: Returns with the SourceType represented by the name *
  1323. * specified. *
  1324. * *
  1325. * WARNINGS: none *
  1326. * *
  1327. * HISTORY: *
  1328. * 04/17/1994 JLB : Created. *
  1329. *=============================================================================================*/
  1330. SourceType Source_From_Name(char const * name)
  1331. {
  1332. if (name) {
  1333. for (SourceType source = SOURCE_FIRST; source < SOURCE_COUNT; source++) {
  1334. if (stricmp(SourceName[source], name) == 0) {
  1335. return(source);
  1336. }
  1337. }
  1338. }
  1339. return(SOURCE_NONE);
  1340. }
  1341. /***********************************************************************************************
  1342. * Name_From_Source -- retrieves the name for the given SourceType *
  1343. * *
  1344. * INPUT: *
  1345. * source SourceType to get the name for *
  1346. * *
  1347. * OUTPUT: *
  1348. * name of SourceType *
  1349. * *
  1350. * WARNINGS: *
  1351. * none. *
  1352. * *
  1353. * HISTORY: *
  1354. * 11/15/1994 BR : Created. *
  1355. *=============================================================================================*/
  1356. char const * Name_From_Source(SourceType source)
  1357. {
  1358. if ((unsigned)source < SOURCE_COUNT) {
  1359. return(SourceName[source]);
  1360. }
  1361. return("None");
  1362. }
  1363. /***********************************************************************************************
  1364. * Theater_From_Name -- Converts ASCII name into a theater number. *
  1365. * *
  1366. * This routine converts an ASCII representation of a theater and converts it into a *
  1367. * matching theater number. If no match was found, then THEATER_NONE is returned. *
  1368. * *
  1369. * INPUT: name -- Pointer to ASCII name to convert. *
  1370. * *
  1371. * OUTPUT: Returns with the name converted into a theater number. *
  1372. * *
  1373. * WARNINGS: none *
  1374. * *
  1375. * HISTORY: *
  1376. * 10/01/1994 JLB : Created. *
  1377. *=============================================================================================*/
  1378. TheaterType Theater_From_Name(char const * name)
  1379. {
  1380. TheaterType index;
  1381. if (name) {
  1382. for (index = THEATER_FIRST; index < THEATER_COUNT; index++) {
  1383. if (stricmp(name, Theaters[index].Name) == 0) {
  1384. return(index);
  1385. }
  1386. }
  1387. }
  1388. return(THEATER_NONE);
  1389. }
  1390. /***********************************************************************************************
  1391. * KN_To_Facing -- Converts a keyboard input number into a facing value. *
  1392. * *
  1393. * This routine determine which compass direction is represented by the keyboard value *
  1394. * provided. It is used for map scrolling and other directional control operations from *
  1395. * the keyboard. *
  1396. * *
  1397. * INPUT: input -- The KN number to convert. *
  1398. * *
  1399. * OUTPUT: Returns with the facing type that the keyboard number represents. If it could *
  1400. * not be translated, then FACING_NONE is returned. *
  1401. * *
  1402. * WARNINGS: none *
  1403. * *
  1404. * HISTORY: *
  1405. * 05/28/1994 JLB : Created. *
  1406. *=============================================================================================*/
  1407. FacingType KN_To_Facing(int input)
  1408. {
  1409. input &= ~(KN_ALT_BIT|KN_SHIFT_BIT|KN_CTRL_BIT);
  1410. switch (input) {
  1411. case KN_LEFT:
  1412. return(FACING_W);
  1413. case KN_RIGHT:
  1414. return(FACING_E);
  1415. case KN_UP:
  1416. return(FACING_N);
  1417. case KN_DOWN:
  1418. return(FACING_S);
  1419. case KN_UPLEFT:
  1420. return(FACING_NW);
  1421. case KN_UPRIGHT:
  1422. return(FACING_NE);
  1423. case KN_DOWNLEFT:
  1424. return(FACING_SW);
  1425. case KN_DOWNRIGHT:
  1426. return(FACING_SE);
  1427. default:
  1428. break;
  1429. }
  1430. return(FACING_NONE);
  1431. }
  1432. /***********************************************************************************************
  1433. * Sync_Delay -- Forces the game into a 15 FPS rate. *
  1434. * *
  1435. * This routine will wait until the timer for the current frame has expired before *
  1436. * returning. It is called at the end of every game loop in order to force the game loop *
  1437. * to run at a fixed rate. *
  1438. * *
  1439. * INPUT: none *
  1440. * *
  1441. * OUTPUT: none *
  1442. * *
  1443. * WARNINGS: This routine will delay an amount of time according to the game speed setting. *
  1444. * *
  1445. * HISTORY: *
  1446. * 01/04/1995 JLB : Created. *
  1447. * 03/06/1995 JLB : Fixed. *
  1448. *=============================================================================================*/
  1449. static void Sync_Delay(void)
  1450. {
  1451. /*
  1452. ** Accumulate the number of 'spare' ticks that are frittered away here.
  1453. */
  1454. SpareTicks += FrameTimer;
  1455. /*
  1456. ** Delay until the frame timer expires. This forces the game loop to be regulated to a
  1457. ** speed controlled by the game options slider.
  1458. */
  1459. while (FrameTimer) {
  1460. Color_Cycle();
  1461. Call_Back();
  1462. if (SpecialDialog == SDLG_NONE) {
  1463. #ifdef WIN32
  1464. WWMouse->Erase_Mouse(&HidPage, TRUE);
  1465. #endif //WIN32
  1466. KeyNumType input = KN_NONE;
  1467. int x, y;
  1468. Map.Input(input, x, y);
  1469. if (input) {
  1470. Keyboard_Process(input);
  1471. }
  1472. Map.Render();
  1473. }
  1474. }
  1475. Color_Cycle();
  1476. Call_Back();
  1477. }
  1478. /***********************************************************************************************
  1479. * Main_Loop -- This is the main game loop (as a single loop). *
  1480. * *
  1481. * This function will perform one game loop. *
  1482. * *
  1483. * INPUT: none *
  1484. * *
  1485. * OUTPUT: bool; Should the game end? *
  1486. * *
  1487. * WARNINGS: none *
  1488. * *
  1489. * HISTORY: *
  1490. * 10/01/1994 JLB : Created. *
  1491. *=============================================================================================*/
  1492. #ifdef WIN32
  1493. extern void Check_For_Focus_Loss(void);
  1494. void Reallocate_Big_Shape_Buffer(void);
  1495. #endif //WIN32
  1496. bool Main_Loop()
  1497. {
  1498. KeyNumType input; // Player input.
  1499. int x;
  1500. int y;
  1501. int framedelay;
  1502. if (!GameActive) return(!GameActive);
  1503. #ifdef WIN32
  1504. /*
  1505. ** Call the focus loss handler
  1506. */
  1507. Check_For_Focus_Loss();
  1508. /*
  1509. ** Allocate extra memory for uncompressed shapes as needed
  1510. */
  1511. Reallocate_Big_Shape_Buffer();
  1512. #endif
  1513. /*
  1514. ** Sync-bug trapping code
  1515. */
  1516. if (Frame >= Session.TrapFrame) {
  1517. Session.Trap_Object();
  1518. }
  1519. //
  1520. // Initialize our AI processing timer
  1521. //
  1522. Session.ProcessTimer = TickCount;
  1523. #if 1
  1524. if (Session.TrapCheckHeap) {
  1525. Debug_Trap_Check_Heap = true;
  1526. }
  1527. #endif
  1528. #ifdef CHEAT_KEYS
  1529. /*
  1530. ** Update the running status debug display.
  1531. */
  1532. Self_Regulate();
  1533. #endif
  1534. BStart(BENCH_GAME_FRAME);
  1535. /*
  1536. ** If there is no theme playing, but it looks like one is required, then start one
  1537. ** playing. This is usually the symptom of there being no transition score.
  1538. */
  1539. if (SampleType && Theme.What_Is_Playing() == THEME_NONE) {
  1540. Theme.Queue_Song(THEME_PICK_ANOTHER);
  1541. }
  1542. /*
  1543. ** Setup the timer so that the Main_Loop function processes at the correct rate.
  1544. */
  1545. if (Session.Type != GAME_NORMAL && Session.Type != GAME_SKIRMISH &&
  1546. Session.CommProtocol == COMM_PROTOCOL_MULTI_E_COMP) {
  1547. //
  1548. // In playback mode, run as fast as possible.
  1549. //
  1550. if (Session.Play) {
  1551. FrameTimer = 0;
  1552. } else {
  1553. framedelay = TIMER_SECOND / Session.DesiredFrameRate;
  1554. FrameTimer = framedelay;
  1555. }
  1556. } else {
  1557. if (Options.GameSpeed != 0) {
  1558. FrameTimer = Options.GameSpeed +
  1559. (PlayerPtr->Difficulty == DIFF_EASY ? 1 : 0) -
  1560. (PlayerPtr->Difficulty == DIFF_HARD ? 1 : 0);
  1561. } else {
  1562. FrameTimer = Options.GameSpeed + (PlayerPtr->Difficulty == DIFF_EASY ? 1 : 0);
  1563. }
  1564. }
  1565. /*
  1566. ** Update the display, unless we're inside a dialog.
  1567. */
  1568. if (!Session.Play) {
  1569. #ifdef WIN32
  1570. if (SpecialDialog == SDLG_NONE && GameInFocus) {
  1571. WWMouse->Erase_Mouse(&HidPage, TRUE);
  1572. #else
  1573. if (SpecialDialog == SDLG_NONE) {
  1574. #endif
  1575. Map.Input(input, x, y);
  1576. if (input) {
  1577. Keyboard_Process(input);
  1578. }
  1579. Map.Render();
  1580. }
  1581. }
  1582. /*
  1583. ** Save map's position & selected objects, if we're recording the game.
  1584. */
  1585. if (Session.Record || Session.Play) {
  1586. Do_Record_Playback();
  1587. }
  1588. #ifndef SORTDRAW
  1589. /*
  1590. ** Sort the map's ground layer by y-coordinate value. This is done
  1591. ** outside the IsToRedraw check, for the purposes of game sync'ing
  1592. ** between machines; this way, all machines will sort the Map's
  1593. ** layer in the same way, and any processing done that's based on
  1594. ** the order of this layer will remain in sync.
  1595. */
  1596. DisplayClass::Layer[LAYER_GROUND].Sort();
  1597. #endif
  1598. /*
  1599. ** AI logic operations are performed here.
  1600. */
  1601. Logic.AI();
  1602. TimeQuake = false;
  1603. /*
  1604. ** Manage the inter-player message list. If Manage() returns true, it means
  1605. ** a message has expired & been removed, and the entire map must be updated.
  1606. */
  1607. if (Session.Messages.Manage()) {
  1608. #ifdef WIN32
  1609. HiddenPage.Clear();
  1610. #else //WIN32
  1611. HidPage.Clear();
  1612. #endif //WIN32
  1613. Map.Flag_To_Redraw(true);
  1614. }
  1615. //
  1616. // Measure how long it took to process the AI
  1617. //
  1618. Session.ProcessTicks += (TickCount - Session.ProcessTimer);
  1619. Session.ProcessFrames++;
  1620. /*
  1621. ** Process all commands that are ready to be processed.
  1622. */
  1623. Queue_AI();
  1624. /*
  1625. ** Keep track of elapsed time in the game.
  1626. */
  1627. Score.ElapsedTime += TIMER_SECOND / TICKS_PER_SECOND;
  1628. Call_Back();
  1629. /*
  1630. ** Check for player wins or loses according to global event flag.
  1631. */
  1632. if (PlayerWins) {
  1633. #ifdef WIN32
  1634. /*
  1635. ** Send the game statistics to WChat.
  1636. */
  1637. if (Session.Type == GAME_INTERNET && !GameStatisticsPacketSent) {
  1638. Register_Game_End_Time();
  1639. Send_Statistics_Packet();
  1640. }
  1641. WWMouse->Erase_Mouse(&HidPage, TRUE);
  1642. #endif //WIN32
  1643. PlayerLoses = false;
  1644. PlayerWins = false;
  1645. PlayerRestarts = false;
  1646. Map.Help_Text(TXT_NONE);
  1647. Do_Win();
  1648. return(!GameActive);
  1649. }
  1650. if (PlayerLoses) {
  1651. #ifdef WIN32
  1652. /*
  1653. ** Send the game statistics to WChat.
  1654. */
  1655. if (Session.Type == GAME_INTERNET && !GameStatisticsPacketSent) {
  1656. Register_Game_End_Time();
  1657. Send_Statistics_Packet();
  1658. }
  1659. WWMouse->Erase_Mouse(&HidPage, TRUE);
  1660. #endif //WIN32
  1661. PlayerWins = false;
  1662. PlayerLoses = false;
  1663. PlayerRestarts = false;
  1664. Map.Help_Text(TXT_NONE);
  1665. Do_Lose();
  1666. return(!GameActive);
  1667. }
  1668. if (PlayerRestarts) {
  1669. #ifdef WIN32
  1670. WWMouse->Erase_Mouse(&HidPage, TRUE);
  1671. #endif //WIN32
  1672. PlayerWins = false;
  1673. PlayerLoses = false;
  1674. PlayerRestarts = false;
  1675. Map.Help_Text(TXT_NONE);
  1676. Do_Restart();
  1677. return(!GameActive);
  1678. }
  1679. /*
  1680. ** The frame logic has been completed. Increment the frame
  1681. ** counter.
  1682. */
  1683. Frame++;
  1684. /*
  1685. ** Is there a memory trasher altering the map??
  1686. */
  1687. if (Debug_Check_Map) {
  1688. if (!Map.Validate()) {
  1689. if (WWMessageBox().Process (TEXT_MAP_ERROR, TEXT_STOP, TEXT_CONTINUE)==0) {
  1690. GameActive = 0;
  1691. }
  1692. Map.Validate(); // give debugger a chance to catch it
  1693. }
  1694. }
  1695. #ifdef WIN32
  1696. if (Debug_MotionCapture) {
  1697. static void ** _array = 0;
  1698. static int _sequence = 0;
  1699. static int _seqsize = Rule.MovieTime * TICKS_PER_MINUTE;
  1700. if (_array == NULL) {
  1701. _array = new void * [_seqsize];
  1702. memset(_array, '\0', _seqsize * sizeof(void*));
  1703. }
  1704. if (_array == NULL) {
  1705. Debug_MotionCapture = false;
  1706. }
  1707. static GraphicBufferClass temp_page( SeenBuff.Get_Width(),
  1708. SeenBuff.Get_Height(),
  1709. NULL,
  1710. SeenBuff.Get_Width() * SeenBuff.Get_Height());
  1711. int size = SeenBuff.Get_Width() * SeenBuff.Get_Height();
  1712. if (_sequence < _seqsize) {
  1713. if (_array[_sequence] == NULL) {
  1714. _array[_sequence] = new char[size];
  1715. }
  1716. if (_array[_sequence] != NULL) {
  1717. SeenBuff.Blit(temp_page);
  1718. memmove(_array[_sequence], temp_page.Get_Buffer(), size);
  1719. }
  1720. _sequence++;
  1721. } else {
  1722. Debug_MotionCapture = false;
  1723. CDFileClass file;
  1724. file.Cache(200000);
  1725. char filename[30];
  1726. for (int index = 0; index < _sequence; index++) {
  1727. memmove(temp_page.Get_Buffer(), _array[index], size);
  1728. sprintf(filename, "cap%04d.pcx", index);
  1729. file.Set_Name(filename);
  1730. Write_PCX_File(file, temp_page, & GamePalette);
  1731. }
  1732. _sequence = 0;
  1733. }
  1734. }
  1735. #endif
  1736. BEnd(BENCH_GAME_FRAME);
  1737. Sync_Delay();
  1738. return(!GameActive);
  1739. }
  1740. #ifdef SCENARIO_EDITOR
  1741. /***************************************************************************
  1742. * Map_Edit_Loop -- a mini-main loop for map edit mode only *
  1743. * *
  1744. * INPUT: *
  1745. * *
  1746. * OUTPUT: *
  1747. * *
  1748. * WARNINGS: *
  1749. * *
  1750. * HISTORY: *
  1751. * 10/19/1994 BR : Created. *
  1752. *=========================================================================*/
  1753. bool Map_Edit_Loop(void)
  1754. {
  1755. /*
  1756. ** Redraw the map.
  1757. */
  1758. Map.Render();
  1759. /*
  1760. ** Get user input (keys, mouse clicks).
  1761. */
  1762. KeyNumType input;
  1763. #ifdef WIN32
  1764. WWMouse->Erase_Mouse(&HidPage, TRUE);
  1765. #endif //WIN32
  1766. int x;
  1767. int y;
  1768. Map.Input(input, x, y);
  1769. /*
  1770. ** Process keypress.
  1771. */
  1772. if (input) {
  1773. Keyboard_Process(input);
  1774. }
  1775. Call_Back(); // maintains Theme.AI() for music
  1776. Color_Cycle();
  1777. return(!GameActive);
  1778. }
  1779. /***************************************************************************
  1780. * Go_Editor -- Enables/disables the map editor *
  1781. * *
  1782. * INPUT: *
  1783. * flag true = go into editor mode; false = go into game mode *
  1784. * *
  1785. * OUTPUT: *
  1786. * none. *
  1787. * *
  1788. * WARNINGS: *
  1789. * none. *
  1790. * *
  1791. * HISTORY: *
  1792. * 10/19/1994 BR : Created. *
  1793. *=========================================================================*/
  1794. void Go_Editor(bool flag)
  1795. {
  1796. /*
  1797. ** Go into Scenario Editor mode
  1798. */
  1799. if (flag) {
  1800. Debug_Map = true;
  1801. Debug_Unshroud = true;
  1802. /*
  1803. ** Un-select any selected objects
  1804. */
  1805. Unselect_All();
  1806. /*
  1807. ** Turn off the sidebar if it's on
  1808. */
  1809. Map.Activate(0);
  1810. /*
  1811. ** Reset the map's Button list for the new mode
  1812. */
  1813. Map.Init_IO();
  1814. /*
  1815. ** Force a complete redraw of the screen
  1816. */
  1817. #ifdef WIN32
  1818. HiddenPage.Clear();
  1819. #else
  1820. HidPage.Clear();
  1821. #endif
  1822. Map.Flag_To_Redraw(true);
  1823. Map.Render();
  1824. } else {
  1825. /*
  1826. ** Go into normal game mode
  1827. */
  1828. Debug_Map = false;
  1829. Debug_Unshroud = false;
  1830. /*
  1831. ** Un-select any selected objects
  1832. */
  1833. Unselect_All();
  1834. /*
  1835. ** Reset the map's Button list for the new mode
  1836. */
  1837. Map.Init_IO();
  1838. /*
  1839. ** Force a complete redraw of the screen
  1840. */
  1841. HidPage.Clear();
  1842. Map.Flag_To_Redraw(true);
  1843. Map.Render();
  1844. }
  1845. }
  1846. #endif
  1847. /***********************************************************************************************
  1848. * MixFileHandler -- Handles VQ file access. *
  1849. * *
  1850. * This routine is called from the VQ player when it needs to access the source file. By *
  1851. * using this routine it is possible to virtualize the file system. *
  1852. * *
  1853. * INPUT: vqa -- Pointer to the VQA handle for this animation. *
  1854. * *
  1855. * action-- The requested action to perform. *
  1856. * *
  1857. * buffer-- Optional buffer pointer as needed by the type of action. *
  1858. * *
  1859. * nbytes-- The number of bytes (if needed) for this operation. *
  1860. * *
  1861. * OUTPUT: Returns a value consistent with the action requested. *
  1862. * *
  1863. * WARNINGS: none *
  1864. * *
  1865. * HISTORY: *
  1866. * 07/04/1995 JLB : Created. *
  1867. *=============================================================================================*/
  1868. long MixFileHandler(VQAHandle * vqa, long action, void * buffer, long nbytes)
  1869. {
  1870. CCFileClass * file;
  1871. long error;
  1872. file = (CCFileClass *)vqa->VQAio;
  1873. /*
  1874. ** Perform the action specified by the stream command.
  1875. */
  1876. switch (action) {
  1877. /*
  1878. ** VQACMD_READ means read NBytes from the stream and place it in the
  1879. ** memory pointed to by Buffer.
  1880. **
  1881. ** Any error code returned will be remapped by VQA library into
  1882. ** VQAERR_READ.
  1883. */
  1884. case VQACMD_READ:
  1885. error = (file->Read(buffer, (unsigned short)nbytes) != (unsigned short)nbytes);
  1886. break;
  1887. /*
  1888. ** VQACMD_WRITE is analogous to VQACMD_READ.
  1889. **
  1890. ** Writing is not allowed to the VQA file, VQA library will remap the
  1891. ** error into VQAERR_WRITE.
  1892. */
  1893. case VQACMD_WRITE:
  1894. error = 1;
  1895. break;
  1896. /*
  1897. ** VQACMD_SEEK asks that you perform a seek relative to the current
  1898. ** position. NBytes is a signed number, indicating seek direction
  1899. ** (positive for forward, negative for backward). Buffer has no meaning
  1900. ** here.
  1901. **
  1902. ** Any error code returned will be remapped by VQA library into
  1903. ** VQAERR_SEEK.
  1904. */
  1905. case VQACMD_SEEK:
  1906. error = (file->Seek(nbytes, SEEK_CUR) == -1);
  1907. break;
  1908. /*
  1909. ** VQACMD_OPEN asks that you open your stream for access.
  1910. */
  1911. case VQACMD_OPEN:
  1912. file = new CCFileClass((char *)buffer);
  1913. if (file != NULL && file->Is_Available()) {
  1914. error = file->Open((char *)buffer, READ);
  1915. if (error != -1) {
  1916. vqa->VQAio = (unsigned long)file;
  1917. error = 0;
  1918. } else {
  1919. delete file;
  1920. file = 0;
  1921. error = 1;
  1922. }
  1923. } else {
  1924. error = 1;
  1925. }
  1926. break;
  1927. case VQACMD_CLOSE:
  1928. file->Close();
  1929. delete file;
  1930. file = 0;
  1931. vqa->VQAio = 0;
  1932. error = 0;
  1933. break;
  1934. /*
  1935. ** VQACMD_INIT means to prepare your stream for reading. This is used for
  1936. ** certain streams that can't be read immediately upon opening, and need
  1937. ** further preparation. This operation is allowed to fail; the error code
  1938. ** will be returned directly to the client.
  1939. */
  1940. case VQACMD_INIT:
  1941. /*
  1942. ** IFFCMD_CLEANUP means to terminate the transaction with the associated
  1943. ** stream. This is used for streams that can't simply be closed. This
  1944. ** operation is not allowed to fail; any error returned will be ignored.
  1945. */
  1946. case VQACMD_CLEANUP:
  1947. error = 0;
  1948. break;
  1949. default:
  1950. error = 0;
  1951. break;
  1952. }
  1953. return(error);
  1954. }
  1955. void Rebuild_Interpolated_Palette(unsigned char * interpal)
  1956. {
  1957. for (int y=0; y<255; y++) {
  1958. for (int x=y+1; x<256; x++) {
  1959. *(interpal + (y*256+x)) = *(interpal + (x*256+y));
  1960. }
  1961. }
  1962. }
  1963. unsigned char * InterpolatedPalettes[50];
  1964. BOOL PalettesRead;
  1965. unsigned PaletteCounter;
  1966. /***********************************************************************************************
  1967. * Load_Interpolated_Palettes -- Loads in any precalculated palettes for hires VQs *
  1968. * *
  1969. * *
  1970. * *
  1971. * INPUT: Name of palette file *
  1972. * *
  1973. * OUTPUT: Number of palettes loaded *
  1974. * *
  1975. * WARNINGS: None *
  1976. * *
  1977. * HISTORY: *
  1978. * 5/7/96 9:49AM ST : Created *
  1979. *=============================================================================================*/
  1980. int Load_Interpolated_Palettes(char const * filename, BOOL add)
  1981. {
  1982. int num_palettes=0;
  1983. int i;
  1984. int start_palette;
  1985. PalettesRead = FALSE;
  1986. CCFileClass file(filename);
  1987. if (!add) {
  1988. for (i=0; i < 50; i++) {
  1989. InterpolatedPalettes[i]=NULL;
  1990. }
  1991. start_palette=0;
  1992. } else {
  1993. for (start_palette = 0; start_palette < 50; start_palette++) {
  1994. if (!InterpolatedPalettes[start_palette]) break;
  1995. }
  1996. }
  1997. /*
  1998. ** Hack another interpolated palette if the requested one is
  1999. ** not present.
  2000. */
  2001. if (!file.Is_Available()) {
  2002. file.Set_Name("AAGUN.VQP");
  2003. }
  2004. if (file.Is_Available()) {
  2005. file.Open(READ);
  2006. file.Read(&num_palettes , 4);
  2007. for (i=0; i < num_palettes; i++) {
  2008. InterpolatedPalettes[i+start_palette] = (unsigned char *)malloc (65536);
  2009. memset (InterpolatedPalettes[i+start_palette], 0, 65536);
  2010. for (int y = 0; y < 256; y++) {
  2011. file.Read (InterpolatedPalettes[i+start_palette] + y*256 , y+1);
  2012. }
  2013. Rebuild_Interpolated_Palette(InterpolatedPalettes[i+start_palette]);
  2014. }
  2015. PalettesRead = TRUE;
  2016. file.Close();
  2017. }
  2018. PaletteCounter = 0;
  2019. return (num_palettes);
  2020. }
  2021. void Free_Interpolated_Palettes(void)
  2022. {
  2023. for (int i = 0; i < 50 ;i++) {
  2024. if (InterpolatedPalettes[i]) {
  2025. free(InterpolatedPalettes[i]);
  2026. InterpolatedPalettes[i]=NULL;
  2027. }
  2028. }
  2029. }
  2030. /***********************************************************************************************
  2031. * Play_Movie -- Plays a VQ movie. *
  2032. * *
  2033. * Use this routine to play a VQ movie. It will dispatch the specified movie to the *
  2034. * VQ player. The routine will not return until the movie has finished playing. *
  2035. * *
  2036. * INPUT: name -- The name of the movie file (sans ".VQA"). *
  2037. * *
  2038. * theme -- The identifier for an optional theme that should be played in the *
  2039. * background while this VQ plays. *
  2040. * *
  2041. * clrscrn -- 'true' if to clear the screen when the movie is over *
  2042. * *
  2043. * OUTPUT: none *
  2044. * *
  2045. * WARNINGS: none *
  2046. * *
  2047. * HISTORY: *
  2048. * 12/19/1994 JLB : Created. *
  2049. *=============================================================================================*/
  2050. #ifdef WIN32
  2051. extern void Suspend_Audio_Thread(void);
  2052. extern void Resume_Audio_Thread(void);
  2053. #ifdef MOVIE640
  2054. extern GraphicBufferClass VQ640;
  2055. #endif
  2056. #endif
  2057. void Play_Movie(char const * name, ThemeType theme, bool clrscrn)
  2058. {
  2059. /*
  2060. ** Don't play movies in editor mode
  2061. */
  2062. if (Debug_Map) {
  2063. return;
  2064. }
  2065. /*
  2066. ** Don't play movies in multiplayer mode
  2067. */
  2068. if (Session.Type != GAME_NORMAL) {
  2069. return;
  2070. }
  2071. if (name) {
  2072. char fullname[_MAX_FNAME+_MAX_EXT];
  2073. _makepath(fullname, NULL, NULL, name, ".VQA");
  2074. #ifdef WIN32
  2075. char palname [_MAX_FNAME+_MAX_EXT];
  2076. _makepath(palname , NULL, NULL, name, ".VQP");
  2077. #endif //WIN32
  2078. #ifdef CHEAT_KEYS
  2079. Mono_Set_Cursor(0, 0);Mono_Printf("[%s]", fullname);
  2080. #endif
  2081. if (!CCFileClass(fullname).Is_Available()) return;
  2082. /*
  2083. ** Reset the anim control structure.
  2084. */
  2085. Anim_Init();
  2086. /*
  2087. ** Prepare to play a movie. First hide the mouse and stop any score that is playing.
  2088. ** While the score (if any) is fading to silence, fade the palette to black as well.
  2089. ** When the palette has finished fading, wait until the score has finished fading
  2090. ** before launching the movie.
  2091. */
  2092. Hide_Mouse();
  2093. Theme.Queue_Song(theme);
  2094. if (PreserveVQAScreen == 0 && !clrscrn) {
  2095. BlackPalette.Set(FADE_PALETTE_MEDIUM);
  2096. VisiblePage.Clear();
  2097. BlackPalette.Adjust(0x08, WhitePalette);
  2098. BlackPalette.Set();
  2099. BlackPalette.Adjust(0xFF);
  2100. BlackPalette.Set();
  2101. }
  2102. PreserveVQAScreen = 0;
  2103. Keyboard->Clear();
  2104. VQAHandle * vqa = NULL;
  2105. #ifdef WIN32
  2106. #ifdef MOVIE640
  2107. if(IsVQ640) {
  2108. AnimControl.ImageWidth = 640;
  2109. AnimControl.ImageHeight = 400;
  2110. AnimControl.ImageBuf = (unsigned char *)VQ640.Get_Offset();
  2111. } else {
  2112. AnimControl.ImageWidth = 320;
  2113. AnimControl.ImageHeight = 200;
  2114. AnimControl.ImageBuf = (unsigned char *)SysMemPage.Get_Offset();
  2115. }
  2116. #endif
  2117. #endif
  2118. if (!Debug_Quiet && Get_Digi_Handle() != -1) {
  2119. AnimControl.OptionFlags |= VQAOPTF_AUDIO;
  2120. } else {
  2121. AnimControl.OptionFlags &= ~VQAOPTF_AUDIO;
  2122. }
  2123. if ((vqa = VQA_Alloc()) != NULL) {
  2124. VQA_Init(vqa, MixFileHandler);
  2125. if (VQA_Open(vqa, fullname, &AnimControl) == 0) {
  2126. Brokeout = false;
  2127. #ifdef WIN32
  2128. //Suspend_Audio_Thread();
  2129. #ifdef MOVIE640
  2130. if(!IsVQ640) {
  2131. Load_Interpolated_Palettes(palname);
  2132. }
  2133. #else
  2134. Load_Interpolated_Palettes(palname);
  2135. #endif
  2136. //Set_Palette(BlackPalette);
  2137. SysMemPage.Clear();
  2138. InMovie = true;
  2139. #endif //WIN32
  2140. VQA_Play(vqa, VQAMODE_RUN);
  2141. VQA_Close(vqa);
  2142. #ifdef WIN32
  2143. //Resume_Audio_Thread();
  2144. InMovie = FALSE;
  2145. #ifdef MOVIE640
  2146. if(!IsVQ640) {
  2147. Free_Interpolated_Palettes();
  2148. }
  2149. #else
  2150. Free_Interpolated_Palettes();
  2151. #endif
  2152. IsVQ640 = false;
  2153. Set_Primary_Buffer_Format();
  2154. #endif //WIN32
  2155. /*
  2156. ** Any movie that ends prematurely must have the screen
  2157. ** cleared to avoid any unexpected palette glitches.
  2158. */
  2159. if (Brokeout) {
  2160. clrscrn = true;
  2161. VisiblePage.Clear();
  2162. Brokeout = false;
  2163. }
  2164. } else {
  2165. #ifndef NDEBUG
  2166. bool error = true;
  2167. assert(error);
  2168. #endif
  2169. }
  2170. VQA_Free(vqa);
  2171. } else {
  2172. assert(vqa != NULL);
  2173. }
  2174. /*
  2175. ** Presume that the screen is left in a garbage state as well as the palette
  2176. ** being in an unknown condition. Recover from this by clearing the screen and
  2177. ** forcing the palette to black.
  2178. */
  2179. if (clrscrn) {
  2180. VisiblePage.Clear();
  2181. BlackPalette.Adjust(0x08, WhitePalette);
  2182. BlackPalette.Set();
  2183. BlackPalette.Adjust(0xFF);
  2184. BlackPalette.Set();
  2185. }
  2186. Show_Mouse();
  2187. }
  2188. }
  2189. void Play_Movie(VQType name, ThemeType theme, bool clrscrn)
  2190. {
  2191. if (name != VQ_NONE) {
  2192. if (name == VQ_REDINTRO) {
  2193. IsVQ640 = true;
  2194. }
  2195. Play_Movie(VQName[name], theme, clrscrn);
  2196. IsVQ640 = false;
  2197. }
  2198. }
  2199. /***********************************************************************************************
  2200. * Unselect_All -- Causes all selected objects to become unselected. *
  2201. * *
  2202. * This routine will unselect all objects that are currently selected. *
  2203. * *
  2204. * INPUT: none *
  2205. * *
  2206. * OUTPUT: none *
  2207. * *
  2208. * WARNINGS: none *
  2209. * *
  2210. * HISTORY: *
  2211. * 01/19/1995 JLB : Created. *
  2212. *=============================================================================================*/
  2213. void Unselect_All(void)
  2214. {
  2215. while (CurrentObject.Count()) {
  2216. CurrentObject[0]->Unselect();
  2217. }
  2218. }
  2219. /***********************************************************************************************
  2220. * Fading_Table_Name -- Builds a theater specific fading table name. *
  2221. * *
  2222. * This routine builds a standard fading table name. This name is dependant on the theater *
  2223. * being played, since each theater has its own palette. *
  2224. * *
  2225. * INPUT: base -- The base name of this fading table. The base name can be no longer than *
  2226. * seven characters. *
  2227. * *
  2228. * theater -- The theater that this fading table is specific to. *
  2229. * *
  2230. * OUTPUT: Returns with a pointer to the constructed fading table filename. This pointer is *
  2231. * valid until this function is called again. *
  2232. * *
  2233. * WARNINGS: none *
  2234. * *
  2235. * HISTORY: *
  2236. * 01/19/1995 JLB : Created. *
  2237. *=============================================================================================*/
  2238. char const * Fading_Table_Name(char const * base, TheaterType theater)
  2239. {
  2240. static char _buffer[_MAX_FNAME+_MAX_EXT];
  2241. char root[_MAX_FNAME];
  2242. sprintf(root, "%1.1s%s", Theaters[theater].Root, base);
  2243. _makepath(_buffer, NULL, NULL, root, ".MRF");
  2244. return(_buffer);
  2245. }
  2246. /***********************************************************************************************
  2247. * Get_Radar_Icon -- Builds and alloc a radar icon from a shape file *
  2248. * *
  2249. * INPUT: void const * shapefile - pointer to a key framed shapefile *
  2250. * int shapenum - shape to extract from shapefile *
  2251. * *
  2252. * OUTPUT: void const * - 3/3 icon set of shape from file *
  2253. * *
  2254. * HISTORY: *
  2255. * 04/12/1995 PWG : Created. *
  2256. * 05/10/1995 JLB : Handles a null shapefile pointer. *
  2257. *=============================================================================================*/
  2258. void const * Get_Radar_Icon(void const * shapefile, int shapenum, int frames, int zoomfactor)
  2259. {
  2260. static int _offx[]={ 0, 0, -1, 1, 0, -1, 1, -1, 1};
  2261. static int _offy[]={ 0, 0, -1, 1, 0, -1, 1, -1, 1};
  2262. int lp,framelp;
  2263. char pixel;
  2264. char * retval = NULL;
  2265. char * buffer = NULL;
  2266. /*
  2267. ** If there is no shape file, then there can be no radar icon imagery.
  2268. */
  2269. if (!shapefile) return(NULL);
  2270. #if (0)
  2271. CCPalette.Set();
  2272. Set_Logic_Page(SeenBuff);
  2273. CC_Draw_Shape(shapefile, shapenum, 64, 64, WINDOW_MAIN, SHAPE_WIN_REL);
  2274. #endif
  2275. /*
  2276. ** Get the pixel width and height of the frame we built. This will
  2277. ** be used to extract icons and build pixels.
  2278. */
  2279. int pixel_width = Get_Build_Frame_Width( shapefile );
  2280. int pixel_height = Get_Build_Frame_Height( shapefile );
  2281. /*
  2282. ** Find the width and height in icons, adjust these by half an
  2283. ** icon because the artists may be sloppy and miss the edge of an
  2284. ** icon one way or the other.
  2285. */
  2286. int icon_width = (pixel_width + 12) / 24;
  2287. int icon_height = (pixel_height + 12) / 24;
  2288. /*
  2289. ** If we have been told to build as many frames as possible, then
  2290. ** find out how many frames there are to build.
  2291. */
  2292. if (frames == -1) frames = Get_Build_Frame_Count( shapefile );
  2293. /*
  2294. ** Allocate a position to store our icons. If the alloc fails then
  2295. ** we don't add these icons to the set.
  2296. **/
  2297. buffer = new char[(icon_width * icon_height * 9 * frames)+2];
  2298. if (!buffer) return(NULL);
  2299. /*
  2300. ** Save off the return value so that we can return it to the calling
  2301. ** function.
  2302. */
  2303. retval = (char *)buffer;
  2304. *buffer++ = (char)icon_width;
  2305. *buffer++ = (char)icon_height;
  2306. int val = 24/zoomfactor;
  2307. for (framelp = 0; framelp < frames; framelp ++) {
  2308. /*
  2309. ** Build the current frame. If the frame can not be built then we
  2310. ** just need to skip past this set of icons and try to build the
  2311. ** next frame.
  2312. */
  2313. #ifdef WIN32
  2314. void * ptr;
  2315. if ((ptr = (void *)(Build_Frame(shapefile, shapenum + framelp, SysMemPage.Get_Buffer()))) != NULL) {
  2316. ptr = Get_Shape_Header_Data(ptr);
  2317. #else //WIN#@
  2318. if (Build_Frame(shapefile, shapenum + framelp, HidPage.Get_Buffer()) <= (unsigned long)HidPage.Get_Size() ) {
  2319. #endif //WIN32
  2320. /*
  2321. ** Loop through the icon width and the icon height building icons
  2322. ** into the buffer pointer. When the getx or gety falls outside of
  2323. ** the width and height of the shape, just insert transparent pixels.
  2324. */
  2325. for (int icony = 0; icony < icon_height; icony ++) {
  2326. for (int iconx = 0; iconx < icon_width; iconx ++) {
  2327. #ifdef WIN32
  2328. for (int y = 0; y < zoomfactor; y++) {
  2329. for (int x = 0; x < zoomfactor; x++) {
  2330. int getx = (iconx * 24) + (x * val) + (zoomfactor / 2);
  2331. int gety = (icony * 24) + (y * val) + (zoomfactor / 2);
  2332. if ((getx < pixel_width) && (gety < pixel_height)) {
  2333. for (lp = 0; lp < 9; lp ++) {
  2334. pixel = *(char *)((char *)ptr + ((gety - _offy[lp]) * pixel_width) + getx-_offx[lp]);
  2335. #else //WIN32
  2336. for (int y = 0; y < 3; y++) {
  2337. for (int x = 0; x < 3; x++) {
  2338. int getx = (iconx * 24) + (x << 3) + 4;
  2339. int gety = (icony * 24) + (y << 3) + 4;
  2340. if ((getx < pixel_width) && (gety < pixel_height)) {
  2341. for (lp = 0; lp < 9; lp ++) {
  2342. pixel = *(char *)((char *)HidPage.Get_Buffer(), ((gety - _offy[lp]) * pixel_width) + getx-_offx[lp]);
  2343. #endif //WIN32
  2344. if (pixel == LTGREEN) pixel = 0;
  2345. if (pixel) {
  2346. break;
  2347. }
  2348. }
  2349. *buffer++ = pixel;
  2350. } else {
  2351. *buffer++ = 0;
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. } else {
  2358. buffer += icon_width * icon_height * 9;
  2359. }
  2360. }
  2361. return(retval);
  2362. }
  2363. /***********************************************************************************************
  2364. * CC_Draw_Shape -- Custom draw shape handler. *
  2365. * *
  2366. * All draw shape calls will route through this function. It handles all draws for *
  2367. * C&C. Such draws always occur to the logical page and assume certain things about *
  2368. * the parameters passed. *
  2369. * *
  2370. * INPUT: shapefile -- Pointer to the shape data file. This data file contains all the *
  2371. * embedded shapes. *
  2372. * *
  2373. * shapenum -- The shape number within the shapefile that will be drawn. *
  2374. * *
  2375. * x,y -- The pixel coordinates to draw the shape. *
  2376. * *
  2377. * window -- The clipping window to use. *
  2378. * *
  2379. * flags -- The custom draw shape flags. This controls how the parameters *
  2380. * are used (if any). *
  2381. * *
  2382. * fadingdata -- If SHAPE_FADING is desired, then this points to the fading *
  2383. * data table. *
  2384. * *
  2385. * ghostdata -- If SHAPE_GHOST is desired, then this points to the ghost remap *
  2386. * table. *
  2387. * *
  2388. * rotation -- Rotation to apply to the shape (DIR_N = no rotation at all). *
  2389. * *
  2390. * scale -- 24.8 fixed point scale factor. *
  2391. * *
  2392. * OUTPUT: none *
  2393. * *
  2394. * WARNINGS: none *
  2395. * *
  2396. * HISTORY: *
  2397. * 02/21/1995 JLB : Created. *
  2398. *=============================================================================================*/
  2399. void CC_Draw_Shape(void const * shapefile, int shapenum, int x, int y, WindowNumberType window, ShapeFlags_Type flags, void const * fadingdata, void const * ghostdata, DirType rotation, long scale)
  2400. {
  2401. int predoffset;
  2402. #ifdef WIN32
  2403. unsigned long shape_pointer;
  2404. #endif //WIN32
  2405. /*
  2406. ** Special kludge for E3 to prevent crashes
  2407. */
  2408. if ((flags & SHAPE_GHOST) && (!ghostdata)) {
  2409. ghostdata = DisplayClass::SpecialGhost;
  2410. }
  2411. if ((flags & SHAPE_FADING) && (!fadingdata)) {
  2412. fadingdata = DisplayClass::FadingShade;
  2413. }
  2414. static unsigned char * _xbuffer = 0;
  2415. if (!_xbuffer) {
  2416. _xbuffer = new unsigned char[SHAPE_BUFFER_SIZE];
  2417. }
  2418. if (shapefile != NULL && shapenum != -1) {
  2419. int width = Get_Build_Frame_Width(shapefile);
  2420. int height = Get_Build_Frame_Height(shapefile);
  2421. #ifdef NEVER
  2422. /*
  2423. ** Perform a quick clip check against the destination rectangle.
  2424. */
  2425. if (flags & SHAPE_CENTER) {
  2426. if (x-width/2 >= WindowList[window][WINDOWWIDTH]) return;
  2427. if (y-width/2 >= WindowList[window][WINDOWHEIGHT]) return;
  2428. if (x+width/2 < 0) return;
  2429. if (y+height/2 < 0) return;
  2430. } else {
  2431. if (x >= WindowList[window][WINDOWWIDTH]) return;
  2432. if (y >= WindowList[window][WINDOWHEIGHT]) return;
  2433. if (x+width < 0) return;
  2434. if (y+height < 0) return;
  2435. }
  2436. #endif
  2437. #ifdef WIN32
  2438. /*
  2439. ** In WIn95, build shape returns a pointer to the shape not its size
  2440. */
  2441. shape_pointer = Build_Frame(shapefile, shapenum, _ShapeBuffer);
  2442. if (shape_pointer) {
  2443. GraphicViewPortClass draw_window(LogicPage->Get_Graphic_Buffer(),
  2444. WindowList[window][WINDOWX] + LogicPage->Get_XPos(),
  2445. WindowList[window][WINDOWY] + LogicPage->Get_YPos(),
  2446. WindowList[window][WINDOWWIDTH],
  2447. WindowList[window][WINDOWHEIGHT]);
  2448. unsigned char * buffer = (unsigned char *) shape_pointer; //Get_Shape_Header_Data((void*)shape_pointer);
  2449. #else //WIN32
  2450. if ( Build_Frame(shapefile, shapenum, _ShapeBuffer ) <= (unsigned long)_ShapeBufferSize) {
  2451. GraphicViewPortClass draw_window(LogicPage,
  2452. WindowList[window][WINDOWX],
  2453. WindowList[window][WINDOWY],
  2454. WindowList[window][WINDOWWIDTH],
  2455. WindowList[window][WINDOWHEIGHT]);
  2456. unsigned char * buffer = (unsigned char *)_ShapeBuffer;
  2457. #endif //WIN32
  2458. UseOldShapeDraw = false;
  2459. /*
  2460. ** Rotation and scale handler.
  2461. */
  2462. if (rotation != DIR_N || scale != 0x0100) {
  2463. /*
  2464. ** Get the raw shape data without the new header and flag to use the old shape drawing
  2465. */
  2466. UseOldShapeDraw = true;
  2467. #ifdef WIN32
  2468. buffer = (unsigned char *) Get_Shape_Header_Data((void*)shape_pointer);
  2469. #endif
  2470. if (Debug_Rotate) {
  2471. GraphicBufferClass src(width, height, buffer);
  2472. width *= 2;
  2473. height *= 2;
  2474. memset(_xbuffer, '\0', SHAPE_BUFFER_SIZE);
  2475. GraphicBufferClass dst(width, height, _xbuffer);
  2476. Rotate_Bitmap(&src, &dst, rotation);
  2477. buffer = _xbuffer;
  2478. } else {
  2479. BitmapClass bm(width, height, buffer);
  2480. width *= 2;
  2481. height *= 2;
  2482. memset(_xbuffer, '\0', SHAPE_BUFFER_SIZE);
  2483. GraphicBufferClass gb(width, height, _xbuffer);
  2484. TPoint2D pt(width/2, height/2);
  2485. gb.Scale_Rotate(bm, pt, scale, (256-(rotation-64)));
  2486. buffer = _xbuffer;
  2487. }
  2488. }
  2489. /*
  2490. ** Special shadow drawing code (used for aircraft and bullets).
  2491. */
  2492. if ((flags & (SHAPE_FADING|SHAPE_PREDATOR)) == (SHAPE_FADING|SHAPE_PREDATOR)) {
  2493. flags = flags & ~(SHAPE_FADING|SHAPE_PREDATOR);
  2494. flags = flags | SHAPE_GHOST;
  2495. ghostdata = DisplayClass::SpecialGhost;
  2496. }
  2497. predoffset = Frame;
  2498. if (x > ( WindowList[window][WINDOWWIDTH] << 2)) {
  2499. predoffset = -predoffset;
  2500. }
  2501. if (draw_window.Lock()) {
  2502. if ((flags & (SHAPE_GHOST|SHAPE_FADING)) == (SHAPE_GHOST|SHAPE_FADING)) {
  2503. Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, ghostdata, fadingdata, 1, predoffset);
  2504. } else {
  2505. if (flags & SHAPE_FADING) {
  2506. Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, fadingdata, 1, predoffset);
  2507. } else {
  2508. if (flags & SHAPE_PREDATOR) {
  2509. Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, predoffset);
  2510. } else {
  2511. Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, ghostdata, predoffset);
  2512. }
  2513. }
  2514. }
  2515. draw_window.Unlock();
  2516. }
  2517. }
  2518. }
  2519. }
  2520. /***********************************************************************************************
  2521. * Shape_Dimensions -- Determine the minimum rectangle for the shape. *
  2522. * *
  2523. * This routine will calculate (using brute forced) the minimum rectangle that will *
  2524. * enclose the pixels of the shape. This rectangle will be relative to the upper left *
  2525. * corner of the maximum shape size. By using this minimum rectangle, it is possible to *
  2526. * greatly optimize the map 'dirty rectangle' logic. *
  2527. * *
  2528. * INPUT: shapedata -- Pointer to the shape data block. *
  2529. * *
  2530. * shapenum -- The shape number to examine. Each shape would have a different *
  2531. * dimension rectangle. *
  2532. * *
  2533. * OUTPUT: Returns with the rectangle that encloses the shape. *
  2534. * *
  2535. * WARNINGS: This routine uses brute force and is slow. It is presumed that the results *
  2536. * will be cached for subsiquent reuse. *
  2537. * *
  2538. * HISTORY: *
  2539. * 07/22/1996 JLB : Created. *
  2540. *=============================================================================================*/
  2541. Rect const Shape_Dimensions(void const * shapedata, int shapenum)
  2542. {
  2543. Rect rect;
  2544. if (shapedata == NULL || shapenum < 0 || shapenum > Get_Build_Frame_Count(shapedata)) {
  2545. return(rect);
  2546. }
  2547. char * shape;
  2548. #ifdef WIN32
  2549. void * sh = (void *)Build_Frame(shapedata, shapenum, _ShapeBuffer);
  2550. if (sh == NULL) return(rect);
  2551. // shape = (char *)sh;
  2552. shape = (char *)Get_Shape_Header_Data(sh);
  2553. #else
  2554. Build_Frame(shapedata, shapenum, _ShapeBuffer);
  2555. shape = (char *)_ShapeBuffer;
  2556. #endif
  2557. int width = Get_Build_Frame_Width(shapedata);
  2558. int height = Get_Build_Frame_Height(shapedata);
  2559. rect.X = 0;
  2560. rect.Y = 0;
  2561. int xlimit = width-1;
  2562. int ylimit = height-1;
  2563. /*
  2564. ** Find top edge of the shape.
  2565. */
  2566. for (int y = 0; y <= ylimit; y++) {
  2567. for (int x = 0; x <= xlimit; x++) {
  2568. if (shape[y*width + x] != 0) {
  2569. rect.Y = y;
  2570. rect.X = x;
  2571. y = ylimit+1;
  2572. break;
  2573. }
  2574. }
  2575. }
  2576. /*
  2577. ** Find bottom edge of the shape.
  2578. */
  2579. for (y = ylimit; y >= rect.Y; y--) {
  2580. for (int x = xlimit; x >= 0; x--) {
  2581. if (shape[y*width + x] != 0) {
  2582. rect.Height = (y-rect.Y)+1;
  2583. xlimit = x;
  2584. y = rect.Y-1;
  2585. break;
  2586. }
  2587. }
  2588. }
  2589. /*
  2590. ** Find left edge of the shape.
  2591. */
  2592. for (int x = 0; x < rect.X; x++) {
  2593. for (y = rect.Y; y < rect.Y+rect.Height; y++) {
  2594. if (shape[y*width + x] != 0) {
  2595. rect.X = x;
  2596. x = rect.X;
  2597. break;
  2598. }
  2599. }
  2600. }
  2601. /*
  2602. ** Find the right edge of the shape.
  2603. */
  2604. for (x = width-1; x >= xlimit; x--) {
  2605. for (y = rect.Y; y < rect.Y+rect.Height; y++) {
  2606. if (shape[y*width + x] != 0) {
  2607. rect.Width = (x-rect.X)+1;
  2608. x = xlimit-1;
  2609. break;
  2610. }
  2611. }
  2612. }
  2613. /*
  2614. ** Normalize the rectangle around the center of the shape.
  2615. */
  2616. rect.X -= width / 2;
  2617. rect.Y -= height / 2;
  2618. /*
  2619. ** Return with the minimum rectangle that encloses the shape.
  2620. */
  2621. return(rect);
  2622. }
  2623. /***********************************************************************************************
  2624. * Fetch_Techno_Type -- Convert type and ID into TechnoTypeClass pointer. *
  2625. * *
  2626. * This routine will convert the supplied RTTI type number and the ID value into a valid *
  2627. * TechnoTypeClass pointer. If there is an error in conversion, then NULL is returned. *
  2628. * *
  2629. * INPUT: type -- RTTI type of the techno class object. *
  2630. * *
  2631. * id -- Integer representation of the techno sub type number. *
  2632. * *
  2633. * OUTPUT: Returns with a pointer to the techno type class object specified or NULL if the *
  2634. * conversion could not occur. *
  2635. * *
  2636. * WARNINGS: none *
  2637. * *
  2638. * HISTORY: *
  2639. * 05/08/1995 JLB : Created. *
  2640. *=============================================================================================*/
  2641. TechnoTypeClass const * Fetch_Techno_Type(RTTIType type, int id)
  2642. {
  2643. switch (type) {
  2644. case RTTI_UNITTYPE:
  2645. case RTTI_UNIT:
  2646. return(&UnitTypeClass::As_Reference(UnitType(id)));
  2647. case RTTI_VESSELTYPE:
  2648. case RTTI_VESSEL:
  2649. return(&VesselTypeClass::As_Reference(VesselType(id)));
  2650. case RTTI_BUILDINGTYPE:
  2651. case RTTI_BUILDING:
  2652. return(&BuildingTypeClass::As_Reference(StructType(id)));
  2653. case RTTI_INFANTRYTYPE:
  2654. case RTTI_INFANTRY:
  2655. return(&InfantryTypeClass::As_Reference(InfantryType(id)));
  2656. case RTTI_AIRCRAFTTYPE:
  2657. case RTTI_AIRCRAFT:
  2658. return(&AircraftTypeClass::As_Reference(AircraftType(id)));
  2659. default:
  2660. break;
  2661. }
  2662. return(NULL);
  2663. }
  2664. /***********************************************************************************************
  2665. * VQ_Call_Back -- Maintenance callback used for VQ movies. *
  2666. * *
  2667. * This routine is called every frame of the VQ movie as it is being played. If this *
  2668. * routine returns non-zero, then the movie will stop. *
  2669. * *
  2670. * INPUT: buffer -- Pointer to the image buffer for the current frame. *
  2671. * *
  2672. * frame -- The frame number about to be displayed. *
  2673. * *
  2674. * OUTPUT: Should the movie be stopped? *
  2675. * *
  2676. * WARNINGS: none *
  2677. * *
  2678. * HISTORY: *
  2679. * 06/24/1995 JLB : Created. *
  2680. *=============================================================================================*/
  2681. #ifdef WIN32
  2682. void VQA_PauseAudio(void);
  2683. void Check_VQ_Palette_Set(void);
  2684. extern GraphicBufferClass VQ640;
  2685. extern bool IsVQ640;
  2686. long VQ_Call_Back(unsigned char *, long )
  2687. {
  2688. int key = 0;
  2689. if (Keyboard->Check()) {
  2690. key = Keyboard->Get();
  2691. Keyboard->Clear();
  2692. }
  2693. Check_VQ_Palette_Set();
  2694. #ifdef MOVIE640
  2695. if(IsVQ640) {
  2696. VQ640.Blit(SeenBuff);
  2697. } else {
  2698. Interpolate_2X_Scale(&SysMemPage, &SeenBuff, NULL);
  2699. }
  2700. #else
  2701. Interpolate_2X_Scale(&SysMemPage, &SeenBuff, NULL);
  2702. #endif
  2703. //Call_Back();
  2704. if ((BreakoutAllowed || Debug_Flag) && key == KN_ESC) {
  2705. Keyboard->Clear();
  2706. Brokeout = true;
  2707. return(true);
  2708. }
  2709. if (!GameInFocus) {
  2710. VQA_PauseAudio();
  2711. while (!GameInFocus) {
  2712. Check_For_Focus_Loss();
  2713. }
  2714. }
  2715. return(false);
  2716. }
  2717. #else //WIN32
  2718. long VQ_Call_Back(unsigned char *, long )
  2719. {
  2720. Call_Back();
  2721. if ((BreakoutAllowed || Debug_Flag) && Keyboard->Check()) {
  2722. if (Keyboard->Get() == KN_ESC) {
  2723. Keyboard->Clear();
  2724. Brokeout = true;
  2725. return(true);
  2726. }
  2727. Keyboard->Clear();
  2728. }
  2729. return(false);
  2730. }
  2731. #endif //WIN32
  2732. /***********************************************************************************************
  2733. * Handle_Team -- Processes team selection command. *
  2734. * *
  2735. * This routine will handle creation and selection of pseudo teams that the player can *
  2736. * create or control. A team in this sense is an arbitrary grouping of units such that *
  2737. * rapid selection control is allowed. *
  2738. * *
  2739. * INPUT: team -- The logical team number to process. *
  2740. * *
  2741. * action-- The action to perform on this team: *
  2742. * 0 - Toggle the select state for all members of this team. *
  2743. * 1 - Select the members of this team. *
  2744. * 2 - Make all selected objects members of this team. *
  2745. * *
  2746. * OUTPUT: none *
  2747. * *
  2748. * WARNINGS: none *
  2749. * *
  2750. * HISTORY: *
  2751. * 06/27/1995 JLB : Created. *
  2752. *=============================================================================================*/
  2753. void Handle_Team(int team, int action)
  2754. {
  2755. int index;
  2756. //
  2757. // Recording support
  2758. //
  2759. if (Session.Record) {
  2760. TeamNumber = (char)team;
  2761. TeamEvent = (char)action + 1;
  2762. }
  2763. AllowVoice = true;
  2764. switch (action) {
  2765. /*
  2766. ** Toggle the team selection. If the team is selected, then merely unselect it. If the
  2767. ** team is not selected, then unselect all others before selecting this team.
  2768. */
  2769. case 3:
  2770. case 0:
  2771. /*
  2772. ** If a non team member is currently selected, then deselect all objects
  2773. ** before selecting this team.
  2774. */
  2775. if (CurrentObject.Count()) {
  2776. if (CurrentObject[0]->Is_Foot() && ((FootClass *)CurrentObject[0])->Group != team) {
  2777. Unselect_All();
  2778. }
  2779. }
  2780. for (index = 0; index < Vessels.Count(); index++) {
  2781. VesselClass * obj = Vessels.Ptr(index);
  2782. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  2783. if (!obj->IsSelected) {
  2784. obj->Select();
  2785. AllowVoice = false;
  2786. }
  2787. }
  2788. }
  2789. for (index = 0; index < Units.Count(); index++) {
  2790. UnitClass * obj = Units.Ptr(index);
  2791. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  2792. if (!obj->IsSelected) {
  2793. obj->Select();
  2794. AllowVoice = false;
  2795. }
  2796. }
  2797. }
  2798. for (index = 0; index < Infantry.Count(); index++) {
  2799. InfantryClass * obj = Infantry.Ptr(index);
  2800. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  2801. if (!obj->IsSelected) {
  2802. obj->Select();
  2803. AllowVoice = false;
  2804. }
  2805. }
  2806. }
  2807. for (index = 0; index < Aircraft.Count(); index++) {
  2808. AircraftClass * obj = Aircraft.Ptr(index);
  2809. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  2810. if (!obj->IsSelected) {
  2811. obj->Select();
  2812. AllowVoice = false;
  2813. }
  2814. }
  2815. }
  2816. /*
  2817. ** Center the map around the team if the ALT key was pressed too.
  2818. */
  2819. if (action == 3) {
  2820. Map.Center_Map();
  2821. #ifdef WIN32
  2822. Map.Flag_To_Redraw(true);
  2823. #endif //WIn32
  2824. }
  2825. break;
  2826. /*
  2827. ** Additive selection of team.
  2828. */
  2829. case 1:
  2830. for (index = 0; index < Units.Count(); index++) {
  2831. UnitClass * obj = Units.Ptr(index);
  2832. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  2833. if (!obj->IsSelected) {
  2834. obj->Select();
  2835. AllowVoice = false;
  2836. }
  2837. }
  2838. }
  2839. for (index = 0; index < Vessels.Count(); index++) {
  2840. VesselClass * obj = Vessels.Ptr(index);
  2841. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  2842. if (!obj->IsSelected) {
  2843. obj->Select();
  2844. AllowVoice = false;
  2845. }
  2846. }
  2847. }
  2848. for (index = 0; index < Infantry.Count(); index++) {
  2849. InfantryClass * obj = Infantry.Ptr(index);
  2850. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  2851. if (!obj->IsSelected) {
  2852. obj->Select();
  2853. AllowVoice = false;
  2854. }
  2855. }
  2856. }
  2857. for (index = 0; index < Aircraft.Count(); index++) {
  2858. AircraftClass * obj = Aircraft.Ptr(index);
  2859. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  2860. if (!obj->IsSelected) {
  2861. obj->Select();
  2862. AllowVoice = false;
  2863. }
  2864. }
  2865. }
  2866. break;
  2867. /*
  2868. ** Create the team.
  2869. */
  2870. case 2: {
  2871. long minx = 0x7FFFFFFFL, miny = 0x7FFFFFFFL;
  2872. long maxx = 0, maxy = 0;
  2873. TeamSpeed[team] = SPEED_WHEEL;
  2874. TeamMaxSpeed[team] = MPH_LIGHT_SPEED;
  2875. for (index = 0; index < Units.Count(); index++) {
  2876. UnitClass * obj = Units.Ptr(index);
  2877. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  2878. if (obj->Group == team) obj->Group = 0xFF;
  2879. if (obj->IsSelected) {
  2880. obj->Group = team;
  2881. obj->Mark(MARK_CHANGE);
  2882. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  2883. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  2884. if (xc < minx) minx = xc;
  2885. if (xc > maxx) maxx = xc;
  2886. if (yc < miny) miny = yc;
  2887. if (yc > maxy) maxy = yc;
  2888. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  2889. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  2890. TeamSpeed[team] = obj->Class->Speed;
  2891. }
  2892. }
  2893. }
  2894. }
  2895. for (index = 0; index < Vessels.Count(); index++) {
  2896. VesselClass * obj = Vessels.Ptr(index);
  2897. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  2898. if (obj->Group == team) obj->Group = -1;
  2899. if (obj->IsSelected) {
  2900. obj->Group = team;
  2901. obj->Mark(MARK_CHANGE);
  2902. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  2903. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  2904. if (xc < minx) minx = xc;
  2905. if (xc > maxx) maxx = xc;
  2906. if (yc < miny) miny = yc;
  2907. if (yc > maxy) maxy = yc;
  2908. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  2909. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  2910. TeamSpeed[team] = obj->Class->Speed;
  2911. }
  2912. }
  2913. }
  2914. }
  2915. for (index = 0; index < Infantry.Count(); index++) {
  2916. InfantryClass * obj = Infantry.Ptr(index);
  2917. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  2918. if (obj->Group == team) obj->Group = 0xFF;
  2919. if (obj->IsSelected) {
  2920. obj->Group = team;
  2921. obj->Mark(MARK_CHANGE);
  2922. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  2923. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  2924. if (xc < minx) minx = xc;
  2925. if (xc > maxx) maxx = xc;
  2926. if (yc < miny) miny = yc;
  2927. if (yc > maxy) maxy = yc;
  2928. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  2929. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  2930. }
  2931. }
  2932. }
  2933. }
  2934. for (index = 0; index < Aircraft.Count(); index++) {
  2935. AircraftClass * obj = Aircraft.Ptr(index);
  2936. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  2937. if (obj->Group == team) obj->Group = 0xFF;
  2938. if (obj->IsSelected) {
  2939. obj->Group = team;
  2940. obj->Mark(MARK_CHANGE);
  2941. }
  2942. }
  2943. }
  2944. for (index = 0; index < Units.Count(); index++) {
  2945. UnitClass * obj = Units.Ptr(index);
  2946. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl &&
  2947. (obj->Group == team) && (obj->IsSelected) ) {
  2948. /*
  2949. ** When a team is first created, they're created without a
  2950. ** formation offset, so they will not be created in
  2951. ** formation. Later, if they're assigned a formation, the
  2952. ** XFormOffset & YFormOffset numbers will change to valid
  2953. ** offsets, and they'll be formationed.
  2954. */
  2955. #if(1)
  2956. obj->XFormOffset = obj->YFormOffset = (int)0x80000000;
  2957. #else
  2958. #if(1)
  2959. // Old always-north formation stuff
  2960. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  2961. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  2962. obj->XFormOffset = xc - centerx;
  2963. obj->YFormOffset = yc - centery;
  2964. #else
  2965. // New method: save direction and distance rather than x & y offset
  2966. obj->XFormOffset = ::Direction(As_Coord(center), obj->Center_Coord());
  2967. obj->YFormOffset = ::Distance (As_Coord(center), obj->Center_Coord());
  2968. #endif
  2969. #endif
  2970. }
  2971. }
  2972. for (index = 0; index < Infantry.Count(); index++) {
  2973. InfantryClass * obj = Infantry.Ptr(index);
  2974. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  2975. if (obj->Group == team) obj->Group = 0xFF;
  2976. if (obj->IsSelected) obj->Group = team;
  2977. if (obj->Group == team && obj->IsSelected) {
  2978. #if(1)
  2979. obj->XFormOffset = obj->YFormOffset = (int)0x80000000;
  2980. #else
  2981. #if(1)
  2982. // Old always-north formation stuff
  2983. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  2984. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  2985. obj->XFormOffset = xc - centerx;
  2986. obj->YFormOffset = yc - centery;
  2987. #else
  2988. // New method: save direction and distance rather than x & y offset
  2989. obj->XFormOffset = ::Direction(As_Coord(center), obj->Center_Coord());
  2990. obj->YFormOffset = ::Distance (As_Coord(center), obj->Center_Coord());
  2991. #endif
  2992. #endif
  2993. }
  2994. }
  2995. }
  2996. break;
  2997. }
  2998. default:
  2999. break;
  3000. }
  3001. AllowVoice = true;
  3002. }
  3003. /***********************************************************************************************
  3004. * Handle_View -- Either records or restores the tactical view. *
  3005. * *
  3006. * This routine is used to record or restore the current map tactical view. *
  3007. * *
  3008. * INPUT: view -- The view number to work with. *
  3009. * *
  3010. * action-- The action to perform with this view number. *
  3011. * 0 = Restore the view to this previously remembered location. *
  3012. * 1 = Record the current view location. *
  3013. * *
  3014. * OUTPUT: none *
  3015. * *
  3016. * WARNINGS: none *
  3017. * *
  3018. * HISTORY: *
  3019. * 07/04/1995 JLB : Created. *
  3020. *=============================================================================================*/
  3021. void Handle_View(int view, int action)
  3022. {
  3023. if ((unsigned)view < sizeof(Scen.Views)/sizeof(Scen.Views[0])) {
  3024. if (action == 0) {
  3025. Map.Set_Tactical_Position(Coord_Whole(Cell_Coord(Scen.Views[view])));
  3026. #ifdef WIN32
  3027. /*
  3028. ** Win95 scrolling logic cant handle just jumps in screen position so redraw the lot.
  3029. */
  3030. Map.Flag_To_Redraw (true);
  3031. #endif //WIN32
  3032. } else {
  3033. Scen.Views[view] = Coord_Cell(Map.TacticalCoord);
  3034. }
  3035. }
  3036. }
  3037. #ifndef ROR_NOT_READY
  3038. #define ROR_NOT_READY 21
  3039. #endif
  3040. static char * _CD_Volume_Label[] = {
  3041. "CD1",
  3042. "CD2",
  3043. };
  3044. static int _Num_Volumes = ARRAY_SIZE(_CD_Volume_Label);
  3045. #ifdef WIN32
  3046. /***********************************************************************************************
  3047. * Get_CD_Index -- returns the volume type of the CD in the given drive *
  3048. * *
  3049. * *
  3050. * *
  3051. * INPUT: drive number *
  3052. * timeout *
  3053. * *
  3054. * OUTPUT: 0 = gdi *
  3055. * 1 = nod *
  3056. * 2 = covert *
  3057. * -1 = non C&C *
  3058. * *
  3059. * WARNINGS: None *
  3060. * *
  3061. * HISTORY: *
  3062. * 5/21/96 5:27PM ST : Created *
  3063. *=============================================================================================*/
  3064. int Get_CD_Index (int cd_drive, int timeout)
  3065. {
  3066. char volume_name[128];
  3067. char buffer[128];
  3068. unsigned filename_length;
  3069. unsigned misc_dword;
  3070. int count = 0;
  3071. CountDownTimerClass timer;
  3072. timer.Set(timeout);
  3073. /*
  3074. ** Get the volume label. If we get a 'not ready' error then retry for the timeout
  3075. ** period.
  3076. */
  3077. for (;;) {
  3078. sprintf(buffer, "%c:\\", 'A' + cd_drive);
  3079. if (GetVolumeInformation ((char const *)buffer,
  3080. &volume_name[0] ,
  3081. (unsigned long)sizeof(volume_name),
  3082. (unsigned long *)NULL ,
  3083. (unsigned long *)&filename_length,
  3084. (unsigned long *)&misc_dword ,
  3085. (char *)NULL ,
  3086. (unsigned long)0)) {
  3087. /*
  3088. ** Try opening 'movies.mix' to verify that the CD is really there and is what
  3089. ** it says it is.
  3090. */
  3091. sprintf(buffer, "%c:\\main.mix", 'A' + cd_drive);
  3092. HANDLE handle = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ,
  3093. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  3094. if (handle != INVALID_HANDLE_VALUE) {
  3095. CloseHandle(handle);
  3096. /*
  3097. ** Match the volume label to the list of known C&C volume labels.
  3098. */
  3099. for (int i=0 ; i<_Num_Volumes ; i++) {
  3100. if (!stricmp(_CD_Volume_Label[i], volume_name)) return (i);
  3101. }
  3102. } else {
  3103. if (!count)
  3104. count++;
  3105. else return -1;
  3106. }
  3107. } else {
  3108. /*
  3109. ** Failed to get the volume label on a known CD drive.
  3110. ** If this is a CD changer it may require time to swap the disks so dont return
  3111. ** immediately if the error is ROR_NOT_READY
  3112. */
  3113. if (!timer.Time()) return -1;
  3114. int val = GetLastError();
  3115. if (val != ROR_NOT_READY) return -1;
  3116. }
  3117. }
  3118. }
  3119. #else
  3120. int Get_CD_Index (int cd_drive, int )
  3121. {
  3122. char buffer[128];
  3123. /*
  3124. ** We need to do this twice because of the possibilities of a directory
  3125. ** being cached. If this is so, it will only be discovered when we
  3126. ** actually attempt to read a file from the drive.
  3127. */
  3128. if(cd_drive) for (int count = 0; count < 2; count ++) {
  3129. struct find_t ft;
  3130. int file;
  3131. int open_failed;
  3132. /*
  3133. ** Create a path for the cd drive and attempt to read the volume label from
  3134. ** it.
  3135. */
  3136. sprintf(buffer, "%c:\\", 'A' + cd_drive);
  3137. /*
  3138. ** If we are able to read the volume label, this is good but not enough.
  3139. ** Further verification must be done.
  3140. */
  3141. if (!_dos_findfirst(buffer, _A_VOLID, &ft)) {
  3142. /*
  3143. ** Since some versions of disk cacheing software will cache the CD's
  3144. ** directory tracks, we may think the CD is in the drive when it is
  3145. ** actually not. To resolve this we must attempt to open a file on
  3146. ** the cd. Opening a file will always update the directory tracks
  3147. ** (suposedly).
  3148. */
  3149. sprintf(buffer, "%c:\\main.mix", 'A' + cd_drive);
  3150. open_failed = _dos_open(buffer, O_RDONLY|SH_DENYNO, &file);
  3151. if (!open_failed) {
  3152. _dos_close(file);
  3153. /*
  3154. ** Hey some times the stupid dos driver appends a period to the
  3155. ** name if it is eight characters long. If the last char is a
  3156. ** period then erase it.
  3157. */
  3158. if (ft.name[strlen(ft.name)-1] == '.') {
  3159. ft.name[strlen(ft.name)-1] = 0;
  3160. }
  3161. /*
  3162. ** Match the volume label to the list of known C&C volume labels.
  3163. */
  3164. for (int i=0 ; i < _Num_Volumes ; i++) {
  3165. if (!stricmp(_CD_Volume_Label[i], ft.name)) return (i);
  3166. }
  3167. }
  3168. }
  3169. }
  3170. return -1;
  3171. }
  3172. #endif
  3173. /***********************************************************************************************
  3174. * Force_CD_Available -- Ensures that specified CD is available. *
  3175. * *
  3176. * Call this routine when you need to ensure that the specified CD is actually in the *
  3177. * CD-ROM drive. *
  3178. * *
  3179. * INPUT: cd -- The CD that must be available. This will either be "0" for the GDI CD, or *
  3180. * "1" for the Nod CD. If either CD will qualify, then pass in "-1". *
  3181. * *
  3182. * OUTPUT: Is the CD inserted and available? If false is returned, then this indicates that *
  3183. * the player pressed <CANCEL>. *
  3184. * *
  3185. * WARNINGS: none *
  3186. * *
  3187. * HISTORY: *
  3188. * 07/11/1995 JLB : Created. *
  3189. * 05/22/1996 ST : Handles multiple CD drives / CD changers *
  3190. *=============================================================================================*/
  3191. bool Force_CD_Available(int cd)
  3192. {
  3193. #ifndef DEMO
  3194. static int _last = -1;
  3195. #endif
  3196. // static char _palette[768];
  3197. // static char _hold[256];
  3198. static void *font;
  3199. static char * _cd_name[] = {
  3200. "RED ALERT DISK 1",
  3201. "RED ALERT DISK 2",
  3202. };
  3203. int new_cd_drive = 0;
  3204. int cd_index;
  3205. char buffer[128];
  3206. int cd_drive;
  3207. int current_drive;
  3208. int drive_search_timeout;
  3209. ThemeType theme_playing = THEME_NONE;
  3210. /*
  3211. ** If the required CD is set to -2 then it means that the file is present
  3212. ** on the local hard drive and we shouldn't have to worry about it.
  3213. */
  3214. if (cd == -2) return(true);
  3215. /*
  3216. ** Find out if the CD in the current drive is the one we are looking for
  3217. */
  3218. current_drive = CCFileClass::Get_CD_Drive();
  3219. cd_index = Get_CD_Index(current_drive, 1*60);
  3220. if (cd_index >= 0) {
  3221. if (cd == cd_index || cd == -1) {
  3222. /*
  3223. ** The required CD is still in the CD drive we used last time
  3224. */
  3225. new_cd_drive = current_drive;
  3226. }
  3227. }
  3228. /*
  3229. ** Flag that we will have to restart the theme
  3230. */
  3231. theme_playing = Theme.What_Is_Playing();
  3232. Theme.Stop();
  3233. if (!new_cd_drive) {
  3234. /*
  3235. ** Check the last CD drive we used if its different from the current one
  3236. */
  3237. int last_drive = CCFileClass::Get_Last_CD_Drive();
  3238. /*
  3239. ** Make sure the last drive is valid and it isnt the current drive
  3240. */
  3241. if (last_drive && last_drive != CCFileClass::Get_CD_Drive()) {
  3242. /*
  3243. ** Find out if there is a C&C cd in the last drive and if so is it the one we are looking for
  3244. ** Give it a nice big timeout so the CD changer has time to swap the discs
  3245. */
  3246. cd_index = Get_CD_Index(last_drive, 10*60);
  3247. if (cd_index >= 0) {
  3248. if (cd == cd_index || cd == -1) {
  3249. /*
  3250. ** The required CD is in the CD drive we used last time
  3251. */
  3252. new_cd_drive = last_drive;
  3253. }
  3254. }
  3255. }
  3256. }
  3257. /*
  3258. ** Lordy. No sign of that blimming CD anywhere. Search all the CD drives
  3259. ** then if we still cant find it prompt the user to insert it.
  3260. */
  3261. if (!new_cd_drive) {
  3262. /*
  3263. ** Small timeout for the first pass through the drives
  3264. */
  3265. drive_search_timeout = 2*60;
  3266. for (;;) {
  3267. /*
  3268. ** Search all present CD drives for the required disc.
  3269. */
  3270. for (int i=0 ; i<CDList.Get_Number_Of_Drives() ; i++) {
  3271. cd_drive = CDList.Get_Next_CD_Drive();
  3272. cd_index = Get_CD_Index(cd_drive, drive_search_timeout);
  3273. if (cd_index>=0) {
  3274. /*
  3275. ** We found a C&C cd - lets see if it was the one we were looking for
  3276. */
  3277. if (cd == cd_index || cd == -1 || cd == -2) {
  3278. /*
  3279. ** Woohoo! The disk was in a different cd drive. Refresh the search path list
  3280. * and return.
  3281. */
  3282. new_cd_drive = cd_drive;
  3283. break;
  3284. }
  3285. }
  3286. }
  3287. /*
  3288. ** A new disc has become available so break
  3289. */
  3290. if (new_cd_drive) break;
  3291. /*
  3292. ** Increase the timeout for subsequent drive searches.
  3293. */
  3294. drive_search_timeout = 5*60;
  3295. /*
  3296. ** Prompt to insert the CD into the drive.
  3297. */
  3298. if (cd == -1) {
  3299. sprintf(buffer, Text_String(TXT_CD_DIALOG_1), cd+1, _cd_name[cd]);
  3300. } else {
  3301. sprintf(buffer, Text_String(TXT_CD_DIALOG_2), cd+1, _cd_name[cd]);
  3302. }
  3303. #ifdef WIN32
  3304. GraphicViewPortClass * oldpage = Set_Logic_Page(SeenBuff);
  3305. #else
  3306. GraphicBufferClass * oldpage = Set_Logic_Page(SeenBuff);
  3307. #endif
  3308. theme_playing = Theme.What_Is_Playing();
  3309. Theme.Stop();
  3310. int hidden = Get_Mouse_State();
  3311. font = (void *)FontPtr;
  3312. /*
  3313. ** Only set the palette if necessary.
  3314. */
  3315. if (PaletteClass::CurrentPalette[1].Red_Component() +
  3316. PaletteClass::CurrentPalette[1].Blue_Component() +
  3317. PaletteClass::CurrentPalette[1].Green_Component() == 0) {
  3318. GamePalette.Set();
  3319. }
  3320. Keyboard->Clear();
  3321. while (Get_Mouse_State()) Show_Mouse();
  3322. if (WWMessageBox().Process(buffer, TXT_OK, TXT_CANCEL, TXT_NONE, TRUE) == 1) {
  3323. Set_Logic_Page(oldpage);
  3324. Hide_Mouse();
  3325. return(false);
  3326. }
  3327. while (hidden--) Hide_Mouse();
  3328. Set_Font(font);
  3329. Set_Logic_Page(oldpage);
  3330. }
  3331. }
  3332. CurrentCD = cd_index;
  3333. #ifndef DEMO
  3334. CCFileClass::Set_CD_Drive(new_cd_drive);
  3335. CCFileClass::Refresh_Search_Drives();
  3336. /*
  3337. ** If it broke out of the query for CD-ROM loop, then this means that the
  3338. ** CD-ROM has been inserted.
  3339. */
  3340. // if (cd > -3 && _last != cd) {
  3341. if (cd > -1 && _last != cd) {
  3342. _last = cd;
  3343. Theme.Stop();
  3344. // if (ConquerMix) delete ConquerMix;
  3345. if (MoviesMix) delete MoviesMix;
  3346. if (GeneralMix) delete GeneralMix;
  3347. if (ScoreMix) delete ScoreMix;
  3348. if (MainMix) delete MainMix;
  3349. MainMix = new MFCD("MAIN.MIX", &FastKey);
  3350. assert(MainMix != NULL);
  3351. // ConquerMix = new MFCD("CONQUER.MIX", &FastKey);
  3352. if (CCFileClass("MOVIES1.MIX").Is_Available()) {
  3353. MoviesMix = new MFCD("MOVIES1.MIX", &FastKey);
  3354. } else {
  3355. MoviesMix = new MFCD("MOVIES2.MIX", &FastKey);
  3356. }
  3357. assert(MoviesMix != NULL);
  3358. GeneralMix = new MFCD("GENERAL.MIX", &FastKey);
  3359. ScoreMix = new MFCD("SCORES.MIX", &FastKey);
  3360. ThemeClass::Scan();
  3361. }
  3362. #endif
  3363. if (theme_playing != THEME_NONE) {
  3364. Theme.Queue_Song(theme_playing);
  3365. }
  3366. return(true);
  3367. }
  3368. /***************************************************************************
  3369. * DISK_SPACE_AVAILABLE -- returns bytes of free disk space *
  3370. * *
  3371. * INPUT: none *
  3372. * *
  3373. * OUTPUT: returns amount of free disk space *
  3374. * *
  3375. * HISTORY: *
  3376. * 08/11/1995 PWG : Created. *
  3377. *=========================================================================*/
  3378. unsigned long Disk_Space_Available(void)
  3379. {
  3380. struct diskfree_t diskdata;
  3381. unsigned drive;
  3382. _dos_getdrive(&drive);
  3383. _dos_getdiskfree(drive, &diskdata);
  3384. return(diskdata.avail_clusters * diskdata.sectors_per_cluster * diskdata.bytes_per_sector);
  3385. }
  3386. /***********************************************************************************************
  3387. * Do_Record_Playback -- handles saving/loading map pos & current object *
  3388. * *
  3389. * INPUT: *
  3390. * none. *
  3391. * *
  3392. * OUTPUT: *
  3393. * none. *
  3394. * *
  3395. * WARNINGS: *
  3396. * none. *
  3397. * *
  3398. * HISTORY: *
  3399. * 08/15/1995 BRR : Created. *
  3400. *=============================================================================================*/
  3401. static void Do_Record_Playback(void)
  3402. {
  3403. int count;
  3404. TARGET tgt;
  3405. int i;
  3406. COORDINATE coord;
  3407. ObjectClass * obj;
  3408. unsigned long sum;
  3409. unsigned long sum2;
  3410. unsigned long ltgt;
  3411. /*
  3412. ** Record a game
  3413. */
  3414. if (Session.Record) {
  3415. /*
  3416. ** Save the map's location
  3417. */
  3418. Session.RecordFile.Write(&Map.DesiredTacticalCoord,
  3419. sizeof (Map.DesiredTacticalCoord));
  3420. /*
  3421. ** Save the current object list count
  3422. */
  3423. count = CurrentObject.Count();
  3424. Session.RecordFile.Write(&count, sizeof(count));
  3425. /*
  3426. ** Save a CRC of the selected-object list.
  3427. */
  3428. sum = 0;
  3429. for (i = 0; i < count; i++) {
  3430. ltgt = (unsigned long)(CurrentObject[i]->As_Target());
  3431. sum += ltgt;
  3432. }
  3433. Session.RecordFile.Write (&sum, sizeof(sum));
  3434. /*
  3435. ** Save all selected objects.
  3436. */
  3437. for (i = 0; i < count; i++) {
  3438. tgt = CurrentObject[i]->As_Target();
  3439. Session.RecordFile.Write (&tgt, sizeof(tgt));
  3440. }
  3441. //
  3442. // Save team-selection and formation events
  3443. //
  3444. Session.RecordFile.Write (&TeamEvent, sizeof(TeamEvent));
  3445. Session.RecordFile.Write (&TeamNumber, sizeof(TeamNumber));
  3446. Session.RecordFile.Write (&FormationEvent, sizeof(FormationEvent));
  3447. Session.RecordFile.Write (TeamMaxSpeed, sizeof(TeamMaxSpeed));
  3448. Session.RecordFile.Write (TeamSpeed, sizeof(TeamSpeed));
  3449. Session.RecordFile.Write (&FormMove, sizeof(FormMove));
  3450. Session.RecordFile.Write (&FormSpeed, sizeof(FormSpeed));
  3451. Session.RecordFile.Write (&FormMaxSpeed, sizeof(FormMaxSpeed));
  3452. TeamEvent = 0;
  3453. TeamNumber = 0;
  3454. FormationEvent = 0;
  3455. }
  3456. /*
  3457. ** Play back a game ("attract" mode)
  3458. */
  3459. if (Session.Play) {
  3460. /*
  3461. ** Read & set the map's location.
  3462. */
  3463. if (Session.RecordFile.Read(&coord, sizeof(coord))==sizeof(coord)) {
  3464. if (coord != Map.DesiredTacticalCoord) {
  3465. Map.Set_Tactical_Position(coord);
  3466. }
  3467. }
  3468. if (Session.RecordFile.Read(&count, sizeof(count))==sizeof(count)) {
  3469. /*
  3470. ** Compute a CRC of the current object-selection list.
  3471. */
  3472. sum = 0;
  3473. for (i = 0; i < CurrentObject.Count(); i++) {
  3474. ltgt = (unsigned long)(CurrentObject[i]->As_Target());
  3475. sum += ltgt;
  3476. }
  3477. /*
  3478. ** Load the CRC of the objects on disk; if it doesn't match, select
  3479. ** all objects as they're loaded.
  3480. */
  3481. Session.RecordFile.Read (&sum2, sizeof(sum2));
  3482. if (sum2 != sum) {
  3483. Unselect_All();
  3484. }
  3485. AllowVoice = true;
  3486. for (i = 0; i < count; i++) {
  3487. if (Session.RecordFile.Read (&tgt, sizeof(tgt))==sizeof(tgt)) {
  3488. obj = As_Object(tgt);
  3489. if (obj && (sum2 != sum)) {
  3490. obj->Select();
  3491. AllowVoice = false;
  3492. }
  3493. }
  3494. }
  3495. AllowVoice = true;
  3496. }
  3497. //
  3498. // Save team-selection and formation events
  3499. //
  3500. Session.RecordFile.Read (&TeamEvent, sizeof(TeamEvent));
  3501. Session.RecordFile.Read (&TeamNumber, sizeof(TeamNumber));
  3502. Session.RecordFile.Read (&FormationEvent, sizeof(FormationEvent));
  3503. if (TeamEvent) {
  3504. Handle_Team(TeamNumber, TeamEvent - 1);
  3505. }
  3506. if (FormationEvent) {
  3507. Toggle_Formation();
  3508. }
  3509. Session.RecordFile.Read (TeamMaxSpeed, sizeof(TeamMaxSpeed));
  3510. Session.RecordFile.Read (TeamSpeed, sizeof(TeamSpeed));
  3511. Session.RecordFile.Read (&FormMove, sizeof(FormMove));
  3512. Session.RecordFile.Read (&FormSpeed, sizeof(FormSpeed));
  3513. Session.RecordFile.Read (&FormMaxSpeed, sizeof(FormMaxSpeed));
  3514. /*
  3515. ** The map isn't drawn in playback mode, so draw it here.
  3516. */
  3517. Map.Render();
  3518. }
  3519. }
  3520. /***********************************************************************************************
  3521. * Hires_Load -- Allocates memory for, and loads, a resolution dependant file. *
  3522. * *
  3523. * *
  3524. * *
  3525. * INPUT: Name of file to load *
  3526. * *
  3527. * OUTPUT: Ptr to loaded file *
  3528. * *
  3529. * WARNINGS: Caller is responsible for releasing the memory allocated *
  3530. * *
  3531. * *
  3532. * HISTORY: *
  3533. * 5/13/96 3:20PM ST : Created *
  3534. *=============================================================================================*/
  3535. void * Hires_Load(char * name)
  3536. {
  3537. char filename[30];
  3538. int length;
  3539. void * return_ptr;
  3540. #ifdef WIN32
  3541. sprintf(filename, "H%s", name);
  3542. #else
  3543. strcpy(filename, name);
  3544. #endif
  3545. CCFileClass file (filename);
  3546. if (file.Is_Available()) {
  3547. length = file.Size();
  3548. return_ptr = new char[length];
  3549. file.Read(return_ptr, length);
  3550. return (return_ptr);
  3551. } else {
  3552. return (NULL);
  3553. }
  3554. }
  3555. /***********************************************************************************************
  3556. * Crate_From_Name -- Given a crate name convert it to a crate type. *
  3557. * *
  3558. * Use this routine to convert an ASCII crate name into a crate type. If no match could *
  3559. * be found, then CRATE_MONEY is assumed. *
  3560. * *
  3561. * INPUT: name -- Pointer to the crate name text to convert into a crate type. *
  3562. * *
  3563. * OUTPUT: Returns with the crate name converted into a crate type. *
  3564. * *
  3565. * WARNINGS: none *
  3566. * *
  3567. * HISTORY: *
  3568. * 08/12/1996 JLB : Created. *
  3569. *=============================================================================================*/
  3570. CrateType Crate_From_Name(char const * name)
  3571. {
  3572. if (name != NULL) {
  3573. for (CrateType crate = CRATE_FIRST; crate < CRATE_COUNT; crate++) {
  3574. if (stricmp(name, CrateNames[crate]) == 0) return(crate);
  3575. }
  3576. }
  3577. return(CRATE_MONEY);
  3578. }
  3579. /***********************************************************************************************
  3580. * Owner_From_Name -- Convert an owner name into a bitfield. *
  3581. * *
  3582. * This will take an owner specification and convert it into a bitfield that represents *
  3583. * it. Sometimes this will be just a single house bit, but other times it could be *
  3584. * all the allies or soviet house bits combined. *
  3585. * *
  3586. * INPUT: text -- Pointer to the text to convert into a house bitfield. *
  3587. * *
  3588. * OUTPUT: Returns with the houses specified. The value is in the form of a bit field with *
  3589. * one bit per house type. *
  3590. * *
  3591. * WARNINGS: none *
  3592. * *
  3593. * HISTORY: *
  3594. * 08/12/1996 JLB : Created. *
  3595. *=============================================================================================*/
  3596. int Owner_From_Name(char const * text)
  3597. {
  3598. int ownable = 0;
  3599. if (stricmp(text, "soviet") == 0) {
  3600. ownable |= HOUSEF_SOVIET;
  3601. } else {
  3602. if (stricmp(text, "allies") == 0 || stricmp(text, "allied") == 0) {
  3603. ownable |= HOUSEF_ALLIES;
  3604. } else {
  3605. HousesType h = HouseTypeClass::From_Name(text);
  3606. if (h != HOUSE_NONE && (h < HOUSE_MULTI1 || h > HOUSE_MULTI8)) {
  3607. ownable |= (1 << h);
  3608. }
  3609. }
  3610. }
  3611. return(ownable);
  3612. }
  3613. /***********************************************************************************************
  3614. * Shake_The_Screen -- Dispatcher that shakes the screen. *
  3615. * *
  3616. * This routine will shake the game screen the number of shakes requested. *
  3617. * *
  3618. * INPUT: shakes -- The number of shakes to shake the screen. *
  3619. * *
  3620. * OUTPUT: none *
  3621. * *
  3622. * WARNINGS: none *
  3623. * *
  3624. * HISTORY: *
  3625. * 09/04/1996 BWG : Created. *
  3626. *=============================================================================================*/
  3627. void Shake_The_Screen(int shakes)
  3628. {
  3629. #ifdef WIN32
  3630. shakes += shakes;
  3631. Hide_Mouse();
  3632. SeenPage.Blit(HidPage);
  3633. int oldyoff = 0;
  3634. int newyoff = 0;
  3635. while(shakes--) {
  3636. int x = TickCount;
  3637. // CountDownTimer = 1;
  3638. do {
  3639. newyoff = Sim_Random_Pick(0,2) - 1;
  3640. } while (newyoff == oldyoff);
  3641. switch (newyoff) {
  3642. case -1:
  3643. HidPage.Blit(SeenPage, 0,2, 0,0, 640,398);
  3644. break;
  3645. case 0:
  3646. HidPage.Blit(SeenPage);
  3647. break;
  3648. case 1:
  3649. HidPage.Blit(SeenPage, 0,0, 0,2, 640,398);
  3650. break;
  3651. } while (x == TickCount);
  3652. // } while (CountDownTimer != 0) ;
  3653. }
  3654. HidPage.Blit(SeenPage);
  3655. Show_Mouse();
  3656. #else
  3657. Shake_Screen(shakes);
  3658. #endif
  3659. }
  3660. /***********************************************************************************************
  3661. * List_Copy -- Makes a copy of a cell offset list. *
  3662. * *
  3663. * This routine will make a copy of a cell offset list. It will only copy the significant *
  3664. * elements of the list limited by the maximum length specified. *
  3665. * *
  3666. * INPUT: source -- Pointer to a cell offset list. *
  3667. * *
  3668. * len -- The maximum number of cell offset elements to store in to the *
  3669. * destination list pointer. *
  3670. * *
  3671. * dest -- Pointer to the destination list to store the copy into. *
  3672. * *
  3673. * OUTPUT: none *
  3674. * *
  3675. * WARNINGS: Ensure that the destination list is large enough to hold the list copy. *
  3676. * *
  3677. * HISTORY: *
  3678. * 09/04/1996 JLB : Created. *
  3679. *=============================================================================================*/
  3680. void List_Copy(short const * source, int len, short * dest)
  3681. {
  3682. if (dest == NULL || dest == NULL) {
  3683. return;
  3684. }
  3685. while (len > 0) {
  3686. *dest = *source;
  3687. if (*dest == REFRESH_EOL) break;
  3688. dest++;
  3689. source++;
  3690. len--;
  3691. }
  3692. }
  3693. #if 0
  3694. //
  3695. // Boy, this function sure is crummy
  3696. //
  3697. void Crummy(int crumb1, int crumb2)
  3698. {
  3699. if (Debug_Check_Map && Debug_Heap_Dump) {
  3700. Mono_Printf("Hi, I'm Crummy. And so are these: %d, %d\n",crumb1,crumb2);
  3701. }
  3702. }
  3703. #endif