CONQUER.CPP 184 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/CONQUER.CPP 6 3/13/97 2:05p Steve_tall $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : CONQUER.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : April 3, 1991 *
  26. * *
  27. *---------------------------------------------------------------------------------------------*
  28. * Functions: *
  29. * CC_Draw_Shape -- Custom draw shape handler. *
  30. * Call_Back -- Main game maintenance callback routine. *
  31. * Color_Cycle -- Handle the general palette color cycling. *
  32. * Crate_From_Name -- Given a crate name convert it to a crate type. *
  33. * Disk_Space_Available -- returns bytes of free disk space *
  34. * Do_Record_Playback -- handles saving/loading map pos & current object *
  35. * Fading_Table_Name -- Builds a theater specific fading table name. *
  36. * Fetch_Techno_Type -- Convert type and ID into TechnoTypeClass pointer. *
  37. * Force_CD_Available -- Ensures that specified CD is available. *
  38. * Get_Radar_Icon -- Builds and alloc a radar icon from a shape file *
  39. * Handle_Team -- Processes team selection command. *
  40. * Handle_View -- Either records or restores the tactical view. *
  41. * KN_To_Facing -- Converts a keyboard input number into a facing value. *
  42. * Keyboard_Process -- Processes the tactical map input codes. *
  43. * Language_Name -- Build filename for current language. *
  44. * List_Copy -- Makes a copy of a cell offset list. *
  45. * Main_Game -- Main game startup routine. *
  46. * Main_Loop -- This is the main game loop (as a single loop). *
  47. * Map_Edit_Loop -- a mini-main loop for map edit mode only *
  48. * Message_Input -- allows inter-player message input processing *
  49. * MixFileHandler -- Handles VQ file access. *
  50. * Name_From_Source -- retrieves the name for the given SourceType *
  51. * Owner_From_Name -- Convert an owner name into a bitfield. *
  52. * Play_Movie -- Plays a VQ movie. *
  53. * Shake_The_Screen -- Dispatcher that shakes the screen. *
  54. * Shape_Dimensions -- Determine the minimum rectangle for the shape. *
  55. * Source_From_Name -- Converts ASCII name into SourceType. *
  56. * Sync_Delay -- Forces the game into a 15 FPS rate. *
  57. * Theater_From_Name -- Converts ASCII name into a theater number. *
  58. * Unselect_All -- Causes all selected objects to become unselected. *
  59. * VQ_Call_Back -- Maintenance callback used for VQ movies. *
  60. * Game_Registry_Key -- Returns pointer to string containing the registry subkey for the game.
  61. * Is_Counterstrike_Installed -- Function to determine the availability of the CS expansion.
  62. * Is_Aftermath_Installed -- Function to determine the availability of the AM expansion.
  63. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  64. #ifdef TESTCODE
  65. class A {
  66. public:
  67. enum {VAR=1};
  68. };
  69. template<class T>
  70. class B {
  71. public:
  72. enum {VAR2=T::VAR}; // this is the line in question.
  73. };
  74. B<A> test;
  75. #endif
  76. #include "function.h"
  77. #ifdef WIN32
  78. #ifdef WINSOCK_IPX
  79. #include "WSProto.h"
  80. #else //WINSOCK_IPX
  81. #include "tcpip.h"
  82. #endif //WINSOCK_IPX
  83. #else
  84. #include "fakesock.h"
  85. TcpipManagerClass Winsock;
  86. #endif
  87. #include <stdlib.h>
  88. #include <stdio.h>
  89. #include <string.h>
  90. #include <direct.h>
  91. #include <fcntl.h>
  92. #include <io.h>
  93. #include <dos.h>
  94. #include <share.h>
  95. #include "ccdde.h"
  96. #include "vortex.h"
  97. #ifdef WOLAPI_INTEGRATION
  98. //#include "WolDebug.h"
  99. #include "WolStrng.h"
  100. #include "WolapiOb.h"
  101. extern WolapiObject* pWolapi;
  102. #define PAGE_RESPOND_KEY KN_RETURN //KN_COMMA
  103. #endif
  104. #ifdef MPEGMOVIE
  105. #ifdef MCIMPEG
  106. #include "mcimovie.h"
  107. #endif
  108. #include "movie.h"
  109. MPG_RESPONSE far __stdcall MpegCallback(MPG_CMD cmd, LPVOID data, LPVOID user);
  110. #endif
  111. #define SHAPE_TRANS 0x40
  112. void * Get_Shape_Header_Data(void * ptr);
  113. extern bool Spawn_WChat(bool can_launch);
  114. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  115. void Enable_Secret_Units(void);
  116. #endif
  117. extern bool Is_Mission_Aftermath (char *file_name);
  118. extern bool Is_Mission_Counterstrike (char *file_name);
  119. #ifdef FIXIT_VERSION_3 // Stalemate games.
  120. extern void Do_Draw(void);
  121. #endif
  122. #ifdef CHEAT_KEYS
  123. bool bNoMovies = false;
  124. #endif
  125. /****************************************
  126. ** Function prototypes for this module **
  127. *****************************************/
  128. bool Main_Loop(void);
  129. void Keyboard_Process(KeyNumType & input);
  130. static void Message_Input(KeyNumType &input);
  131. void Color_Cycle(void);
  132. bool Map_Edit_Loop(void);
  133. extern "C" {
  134. bool UseOldShapeDraw = false;
  135. }
  136. #ifdef CHEAT_KEYS
  137. void Dump_Heap_Pointers( void );
  138. void Error_In_Heap_Pointers( char * string );
  139. #endif
  140. static void Do_Record_Playback(void);
  141. void Toggle_Formation(void);
  142. extern "C" {
  143. extern char * __nheapbeg;
  144. }
  145. //
  146. // Special module globals for recording and playback
  147. //
  148. char TeamEvent = 0; // 0 = no event, 1,2,3 = team event type
  149. char TeamNumber = 0; // which team was selected? (1-9)
  150. char FormationEvent = 0; // 0 = no event, 1 = formation was toggled
  151. /* -----------------10/14/96 7:29PM------------------
  152. --------------------------------------------------*/
  153. #if(TEN)
  154. void TEN_Call_Back(void);
  155. #endif // TEN
  156. #if(MPATH)
  157. void MPATH_Call_Back(void);
  158. #endif // MPATH
  159. /***********************************************************************************************
  160. * Main_Game -- Main game startup routine. *
  161. * *
  162. * This is the first official routine of the game. It handles game initialization and *
  163. * the main game loop control. *
  164. * *
  165. * Initialization: *
  166. * - Init_Game handles one-time-only inits *
  167. * - Select_Game is responsible for initializations required for each new game played *
  168. * (these may be different depending on whether a multiplayer game is selected, and *
  169. * other parameters) *
  170. * - This routine performs any un-inits required, both for each game played, and one-time *
  171. * *
  172. * INPUT: argc -- Number of command line arguments (including program name itself). *
  173. * *
  174. * argv -- Array of command line argument pointers. *
  175. * *
  176. * OUTPUT: none *
  177. * *
  178. * WARNINGS: none *
  179. * *
  180. * HISTORY: *
  181. * 10/01/1994 JLB : Created. *
  182. *=============================================================================================*/
  183. void Main_Game(int argc, char * argv[])
  184. {
  185. static bool fade = true;
  186. /*
  187. ** Perform one-time-only initializations
  188. */
  189. if (!Init_Game(argc, argv)) {
  190. return;
  191. }
  192. /*
  193. ** Game processing loop:
  194. ** 1) Select which game to play, or whether to exit (don't fade the palette
  195. ** on the first game selection, but fade it in on subsequent calls)
  196. ** 2) Invoke either the main-loop routine, or the editor-loop routine,
  197. ** until they indicate that the user wants to exit the scenario.
  198. */
  199. while (Select_Game(fade)) {
  200. // ST 5/14/2019
  201. if (RunningAsDLL) {
  202. return;
  203. }
  204. fade = false;
  205. ScenarioInit = 0; // Kludge.
  206. fade = true;
  207. /*
  208. ** Initialise the color lookup tables for the chronal vortex
  209. */
  210. ChronalVortex.Stop();
  211. ChronalVortex.Setup_Remap_Tables(Scen.Theater);
  212. /*
  213. ** Make the game screen visible, clear the keyboard buffer of spurious
  214. ** values, and then show the mouse. This PRESUMES that Select_Game() has
  215. ** told the map to draw itself.
  216. */
  217. GamePalette.Set(FADE_PALETTE_MEDIUM);
  218. Keyboard->Clear();
  219. /*
  220. ** Only show the mouse if we're not playing back a recording.
  221. */
  222. if (Session.Play) {
  223. Hide_Mouse();
  224. TeamEvent = 0;
  225. TeamNumber = 0;
  226. FormationEvent = 0;
  227. } else {
  228. Show_Mouse();
  229. }
  230. #ifdef WIN32
  231. if (Session.Type == GAME_INTERNET) {
  232. Register_Game_Start_Time();
  233. GameStatisticsPacketSent = false;
  234. PacketLater = NULL;
  235. ConnectionLost = false;
  236. } else {
  237. #ifndef WOLAPI_INTEGRATION
  238. DDEServer.Disable();
  239. #endif // !WOLAPI_INTEGRATION
  240. }
  241. #endif //WIN32
  242. #ifdef SCENARIO_EDITOR
  243. /*
  244. ** Scenario-editor version of main-loop processing
  245. */
  246. for (;;) {
  247. /*
  248. ** Non-scenario-editor-mode: call the game's main loop
  249. */
  250. if (!Debug_Map) {
  251. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  252. TimeQuake = PendingTimeQuake;
  253. PendingTimeQuake = false;
  254. #else
  255. TimeQuake = false;
  256. #endif
  257. if (Main_Loop()) {
  258. break;
  259. }
  260. if (SpecialDialog != SDLG_NONE) {
  261. switch (SpecialDialog) {
  262. case SDLG_SPECIAL:
  263. Map.Help_Text(TXT_NONE);
  264. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  265. Special_Dialog();
  266. Map.Revert_Mouse_Shape();
  267. SpecialDialog = SDLG_NONE;
  268. break;
  269. case SDLG_OPTIONS:
  270. Map.Help_Text(TXT_NONE);
  271. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  272. Options.Process();
  273. Map.Revert_Mouse_Shape();
  274. SpecialDialog = SDLG_NONE;
  275. break;
  276. case SDLG_SURRENDER:
  277. Map.Help_Text(TXT_NONE);
  278. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  279. if (Surrender_Dialog(TXT_SURRENDER)) {
  280. PlayerPtr->Flag_To_Lose();
  281. }
  282. SpecialDialog = SDLG_NONE;
  283. Map.Revert_Mouse_Shape();
  284. break;
  285. default:
  286. break;
  287. }
  288. }
  289. } else {
  290. /*
  291. ** Scenario-editor-mode: call the editor's main loop
  292. */
  293. if (Map_Edit_Loop()) {
  294. break;
  295. }
  296. }
  297. }
  298. #else
  299. /*
  300. ** Non-editor version of main-loop processing
  301. */
  302. for (;;) {
  303. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  304. TimeQuake = PendingTimeQuake;
  305. PendingTimeQuake = false;
  306. #else
  307. TimeQuake = false;
  308. #endif
  309. /*
  310. ** Call the game's main loop
  311. */
  312. if (Main_Loop()) {
  313. break;
  314. }
  315. /*
  316. ** If the SpecialDialog flag is set, invoke the given special dialog.
  317. ** This must be done outside the main loop, since the dialog will call
  318. ** Main_Loop(), allowing the game to run in the background.
  319. */
  320. if (SpecialDialog != SDLG_NONE) {
  321. switch (SpecialDialog) {
  322. case SDLG_SPECIAL:
  323. Map.Help_Text(TXT_NONE);
  324. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  325. Special_Dialog();
  326. Map.Revert_Mouse_Shape();
  327. SpecialDialog = SDLG_NONE;
  328. break;
  329. case SDLG_OPTIONS:
  330. Map.Help_Text(TXT_NONE);
  331. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  332. Options.Process();
  333. Map.Revert_Mouse_Shape();
  334. SpecialDialog = SDLG_NONE;
  335. break;
  336. case SDLG_SURRENDER:
  337. Map.Help_Text(TXT_NONE);
  338. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  339. if (Surrender_Dialog(TXT_SURRENDER)) {
  340. OutList.Add(EventClass(EventClass::DESTRUCT));
  341. }
  342. SpecialDialog = SDLG_NONE;
  343. Map.Revert_Mouse_Shape();
  344. break;
  345. /*ifdef FIXIT_VERSION_3 // Stalemate games.
  346. case SDLG_PROPOSE_DRAW:
  347. Map.Help_Text(TXT_NONE);
  348. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  349. if (Surrender_Dialog(TXT_WOL_PROPOSE_DRAW)) {
  350. OutList.Add(EventClass(EventClass::PROPOSE_DRAW));
  351. }
  352. SpecialDialog = SDLG_NONE;
  353. Map.Revert_Mouse_Shape();
  354. break;
  355. case SDLG_ACCEPT_DRAW:
  356. Map.Help_Text(TXT_NONE);
  357. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  358. if (Surrender_Dialog(TXT_WOL_ACCEPT_DRAW)) {
  359. OutList.Add(EventClass(EventClass::ACCEPT_DRAW));
  360. }
  361. SpecialDialog = SDLG_NONE;
  362. Map.Revert_Mouse_Shape();
  363. break;
  364. #endif
  365. */
  366. default:
  367. break;
  368. }
  369. }
  370. }
  371. #endif
  372. #ifdef WIN32
  373. /*
  374. ** Send the game stats to WChat if we haven't already done so
  375. */
  376. if (!GameStatisticsPacketSent && PacketLater) {
  377. Send_Statistics_Packet(); // After game sending if PacketLater set.
  378. }
  379. #endif //WIN32
  380. /*
  381. ** Scenario is done; fade palette to black
  382. */
  383. BlackPalette.Set(FADE_PALETTE_SLOW);
  384. VisiblePage.Clear();
  385. /*
  386. ** Un-initialize whatever needs it, for each game played.
  387. **
  388. ** Shut down either the modem or network; they'll get re-initialized if
  389. ** the user selections those options again in Select_Game(). This
  390. ** "re-boots" the modem & network code, which I currently feel is safer
  391. ** than just letting it hang around.
  392. ** (Skip this step if we're in playback mode; the modem or net won't have
  393. ** been initialized in that case.)
  394. */
  395. if (Session.Record || Session.Play) {
  396. Session.RecordFile.Close();
  397. }
  398. if (Session.Type == GAME_NULL_MODEM || Session.Type == GAME_MODEM) {
  399. if (!Session.Play) {
  400. //PG Modem_Signoff();
  401. }
  402. } else {
  403. if (Session.Type == GAME_IPX) {
  404. if (!Session.Play) {
  405. //PG Shutdown_Network();
  406. }
  407. }
  408. }
  409. #if(TEN)
  410. if (Session.Type == GAME_TEN) {
  411. Shutdown_TEN();
  412. //Prog_End();
  413. Emergency_Exit(0);
  414. }
  415. #endif // TEN
  416. #if(MPATH)
  417. if (Session.Type == GAME_MPATH) {
  418. Shutdown_MPATH();
  419. //Prog_End();
  420. Emergency_Exit(0);
  421. }
  422. #endif // MPATH
  423. /*
  424. ** If we're playing back, the mouse will be hidden; show it.
  425. ** Also, set all variables back to normal, to return to the main menu.
  426. */
  427. if (Session.Play) {
  428. Show_Mouse();
  429. Session.Type = GAME_NORMAL;
  430. Session.Play = 0;
  431. }
  432. #ifndef WOLAPI_INTEGRATION
  433. #ifdef WIN32
  434. if (Special.IsFromWChat) {
  435. //PG Shutdown_Network(); // Clear up the pseudo IPX stuff
  436. #ifndef WINSOCK_IPX
  437. Winsock.Close();
  438. #endif //WINSOCK_IPX
  439. Special.IsFromWChat = false;
  440. SpawnedFromWChat = false;
  441. DDEServer.Delete_MPlayer_Game_Info(); //Make sure we dont use the same start packet twice
  442. Session.Type = GAME_NORMAL; //Have to do this or we will got straight to the multiplayer menu
  443. Spawn_WChat(false); //Will switch back to Wchat. It must be there because its been poking us
  444. }
  445. #endif //WIN32
  446. #endif // !WOLAPI_INTEGRATION
  447. }
  448. /*
  449. ** Free the scenario description buffers
  450. */
  451. Session.Free_Scenario_Descriptions();
  452. }
  453. /***********************************************************************************************
  454. * Keyboard_Process -- Processes the tactical map input codes. *
  455. * *
  456. * This routine is used to process the input codes while the player *
  457. * has the tactical map displayed. It handles all the keys that *
  458. * are appropriate to that mode. *
  459. * *
  460. * INPUT: input -- Input code as returned from Input_Num(). *
  461. * *
  462. * OUTPUT: none *
  463. * *
  464. * WARNINGS: none *
  465. * *
  466. * HISTORY: *
  467. * 01/21/1992 JLB : Created. *
  468. * 07/04/1995 JLB : Handles team and map control hotkeys. *
  469. *=============================================================================================*/
  470. void Keyboard_Process(KeyNumType & input)
  471. {
  472. ObjectClass * obj;
  473. int index;
  474. /*
  475. ** Don't do anything if there is not keyboard event.
  476. */
  477. if (input == KN_NONE) {
  478. return;
  479. }
  480. /*
  481. ** For network & modem, process user input for inter-player messages.
  482. */
  483. Message_Input(input);
  484. #ifdef WIN32
  485. /*
  486. ** The VK_BIT must be stripped from the "plain" value of the key so that a comparison to
  487. ** KN_1, for example, will yield TRUE if in fact the "1" key was pressed.
  488. */
  489. KeyNumType plain = KeyNumType(input & ~(WWKEY_SHIFT_BIT|WWKEY_ALT_BIT|WWKEY_CTRL_BIT|WWKEY_VK_BIT));
  490. KeyNumType key = KeyNumType(input & ~WWKEY_VK_BIT);
  491. #else
  492. KeyNumType plain = KeyNumType(input & ~(KN_SHIFT_BIT|KN_ALT_BIT|KN_CTRL_BIT));
  493. KeyNumType key = plain;
  494. #endif
  495. #ifdef CHEAT_KEYS
  496. if (Debug_Flag) {
  497. HousesType h;
  498. switch (int(input)) {
  499. case int(int(KN_M) | int(KN_SHIFT_BIT)):
  500. case int(int(KN_M) | int(KN_ALT_BIT)):
  501. case int(int(KN_M) | int(KN_CTRL_BIT)):
  502. for (h = HOUSE_FIRST; h < HOUSE_COUNT; h++) {
  503. Houses.Ptr(h)->Refund_Money(10000);
  504. }
  505. break;
  506. default:
  507. break;
  508. }
  509. }
  510. #endif
  511. #ifdef VIRGIN_CHEAT_KEYS
  512. if (Debug_Playtest && input == (KN_W|KN_ALT_BIT)) {
  513. PlayerPtr->Blockage = false;
  514. PlayerPtr->Flag_To_Win();
  515. }
  516. #endif
  517. #ifdef CHEAT_KEYS
  518. #ifdef WIN32
  519. if (Debug_Playtest && input == (KA_W|KN_ALT_BIT)) {
  520. #else
  521. if (Debug_Playtest && input == (KN_W|KN_ALT_BIT)) {
  522. #endif
  523. PlayerPtr->Blockage = false;
  524. PlayerPtr->Flag_To_Win();
  525. }
  526. if ((Debug_Flag || Debug_Playtest) && plain == KN_F4) {
  527. if (Session.Type == GAME_NORMAL) {
  528. Debug_Unshroud = (Debug_Unshroud == false);
  529. Map.Flag_To_Redraw(true);
  530. }
  531. }
  532. if (Debug_Flag && input == KN_SLASH) {
  533. if (Session.Type != GAME_NORMAL) {
  534. SpecialDialog = SDLG_SPECIAL;
  535. input = KN_NONE;
  536. } else {
  537. Special_Dialog();
  538. }
  539. }
  540. #endif
  541. /*
  542. ** Process prerecorded team selection. This will be an additive select
  543. ** if the SHIFT key is held down. It will create the team if the
  544. ** CTRL or ALT key is held down.
  545. */
  546. int action = 0;
  547. #ifdef WIN32
  548. if (input & WWKEY_SHIFT_BIT) action = 1;
  549. if (input & WWKEY_ALT_BIT) action = 3;
  550. if (input & WWKEY_CTRL_BIT) action = 2;
  551. #else
  552. if (input & KN_SHIFT_BIT) action = 1;
  553. if (input & KN_ALT_BIT) action = 3;
  554. if (input & KN_CTRL_BIT) action = 2;
  555. #endif
  556. /*
  557. ** If the "N" key is pressed, then select the next object.
  558. */
  559. if (key != 0 && key == Options.KeyNext) {
  560. if (action) {
  561. obj = Map.Prev_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
  562. } else {
  563. obj = Map.Next_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
  564. }
  565. if (obj != NULL) {
  566. Unselect_All();
  567. obj->Select();
  568. Map.Center_Map();
  569. Map.Flag_To_Redraw(true);
  570. }
  571. input = KN_NONE;
  572. }
  573. if (key != 0 && key == Options.KeyPrevious) {
  574. if (action) {
  575. obj = Map.Next_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
  576. } else {
  577. obj = Map.Prev_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
  578. }
  579. if (obj != NULL) {
  580. Unselect_All();
  581. obj->Select();
  582. Map.Center_Map();
  583. Map.Flag_To_Redraw(true);
  584. }
  585. input = KN_NONE;
  586. }
  587. /*
  588. ** All selected units will go into idle mode.
  589. */
  590. if (key != 0 && key == Options.KeyStop) {
  591. if (CurrentObject.Count()) {
  592. for (index = 0; index < CurrentObject.Count(); index++) {
  593. ObjectClass const * tech = CurrentObject[index];
  594. if (tech != NULL && (tech->Can_Player_Move() || (tech->Can_Player_Fire() && tech->What_Am_I() != RTTI_BUILDING))) {
  595. OutList.Add(EventClass(EventClass::IDLE, TargetClass(tech)));
  596. }
  597. }
  598. }
  599. input = KN_NONE;
  600. }
  601. /*
  602. ** All selected units will attempt to go into guard area mode.
  603. */
  604. if (key != 0 && key == Options.KeyGuard) {
  605. if (CurrentObject.Count()) {
  606. for (index = 0; index < CurrentObject.Count(); index++) {
  607. ObjectClass const * tech = CurrentObject[index];
  608. if (tech != NULL && tech->Can_Player_Move() && tech->Can_Player_Fire()) {
  609. OutList.Add(EventClass(TargetClass(tech), MISSION_GUARD_AREA));
  610. }
  611. }
  612. }
  613. input = KN_NONE;
  614. }
  615. /*
  616. ** All selected units will attempt to scatter.
  617. */
  618. if (key != 0 && key == Options.KeyScatter) {
  619. if (CurrentObject.Count()) {
  620. for (index = 0; index < CurrentObject.Count(); index++) {
  621. ObjectClass const * tech = CurrentObject[index];
  622. if (tech != NULL && tech->Can_Player_Move()) {
  623. OutList.Add(EventClass(EventClass::SCATTER, TargetClass(tech)));
  624. }
  625. }
  626. }
  627. input = KN_NONE;
  628. }
  629. /*
  630. ** Center the map around the currently selected objects. If no
  631. ** objects are selected, then fall into the home case.
  632. */
  633. if (key != 0 && (key == Options.KeyHome1 || key == Options.KeyHome2)) {
  634. if (CurrentObject.Count()) {
  635. Map.Center_Map();
  636. #ifdef WIN32
  637. Map.Flag_To_Redraw(true);
  638. #endif
  639. input = KN_NONE;
  640. } else {
  641. input = Options.KeyBase;
  642. }
  643. }
  644. /*
  645. ** Center the map about the construction yard or construction vehicle
  646. ** if one is present.
  647. */
  648. if (key != 0 && key == Options.KeyBase) {
  649. Unselect_All();
  650. if (PlayerPtr->CurBuildings) {
  651. for (index = 0; index < Buildings.Count(); index++) {
  652. BuildingClass * building = Buildings.Ptr(index);
  653. if (building != NULL && !building->IsInLimbo && building->House == PlayerPtr && *building == STRUCT_CONST) {
  654. Unselect_All();
  655. building->Select();
  656. if (building->IsLeader) break;
  657. }
  658. }
  659. }
  660. if (CurrentObject.Count() == 0 && PlayerPtr->CurUnits) {
  661. for (index = 0; index < Units.Count(); index++) {
  662. UnitClass * unit = Units.Ptr(index);
  663. if (unit != NULL && !unit->IsInLimbo && unit->House == PlayerPtr && *unit == UNIT_MCV) {
  664. Unselect_All();
  665. unit->Select();
  666. break;
  667. }
  668. }
  669. }
  670. if (CurrentObject.Count()) {
  671. Map.Center_Map();
  672. } else {
  673. if (PlayerPtr->Center != 0) {
  674. Map.Center_Map(PlayerPtr->Center);
  675. }
  676. }
  677. Map.Flag_To_Redraw(true);
  678. input = KN_NONE;
  679. }
  680. /*
  681. ** Toggle the status of formation for the current team
  682. */
  683. if (key != 0 && key == Options.KeyFormation) {
  684. Toggle_Formation();
  685. input = KN_NONE;
  686. }
  687. #ifdef TOFIX
  688. /*
  689. ** For multiplayer, 'R' pops up the surrender dialog.
  690. */
  691. if (input != 0 && input == Options.KeyResign) {
  692. if (!PlayerLoses && /*Session.Type != GAME_NORMAL &&*/ !PlayerPtr->IsDefeated) {
  693. SpecialDialog = SDLG_SURRENDER;
  694. input = KN_NONE;
  695. }
  696. input = KN_NONE;
  697. }
  698. #endif
  699. /*
  700. ** Handle making and breaking alliances.
  701. */
  702. if (key != 0 && key == Options.KeyAlliance) {
  703. if (Session.Type != GAME_NORMAL || Debug_Flag) {
  704. if (CurrentObject.Count() && !PlayerPtr->IsDefeated) {
  705. if (CurrentObject[0]->Owner() != PlayerPtr->Class->House) {
  706. OutList.Add(EventClass(EventClass::ALLY, CurrentObject[0]->Owner()));
  707. }
  708. }
  709. }
  710. input = KN_NONE;
  711. }
  712. /*
  713. ** Select all the units on the current display. This is equivalent to
  714. ** drag selecting the whole view.
  715. */
  716. if (key != 0 && key == Options.KeySelectView) {
  717. Map.Select_These(0x00000000, XY_Coord(Map.TacLeptonWidth, Map.TacLeptonHeight));
  718. input = KN_NONE;
  719. }
  720. /*
  721. ** Toggles the repair state similarly to pressing the repair button.
  722. */
  723. if (key != 0 && key == Options.KeyRepair) {
  724. Map.Repair_Mode_Control(-1);
  725. input = KN_NONE;
  726. }
  727. /*
  728. ** Toggles the sell state similarly to pressing the sell button.
  729. */
  730. if (key != 0 && key == Options.KeySell) {
  731. Map.Sell_Mode_Control(-1);
  732. input = KN_NONE;
  733. }
  734. /*
  735. ** Toggles the map zoom mode similarly to pressing the map button.
  736. */
  737. if (key != 0 && key == Options.KeyMap) {
  738. Map.Zoom_Mode_Control();
  739. input = KN_NONE;
  740. }
  741. /*
  742. ** Scrolls the sidebar up one slot.
  743. */
  744. if (key != 0 && key == Options.KeySidebarUp) {
  745. Map.SidebarClass::Scroll(true, -1);
  746. input = KN_NONE;
  747. }
  748. /*
  749. ** Scrolls the sidebar down one slot.
  750. */
  751. if (key != 0 && key == Options.KeySidebarDown) {
  752. Map.SidebarClass::Scroll(false, -1);
  753. input = KN_NONE;
  754. }
  755. /*
  756. ** Brings up the options dialog box.
  757. */
  758. if (key != 0 && (key == Options.KeyOption1 || key == Options.KeyOption2)) {
  759. Map.Help_Text(TXT_NONE); // Turns off help text.
  760. Queue_Options();
  761. input = KN_NONE;
  762. }
  763. /*
  764. ** Scrolls the tactical map in the direction specified.
  765. */
  766. int distance = CELL_LEPTON_W;
  767. if (key != 0 && key == Options.KeyScrollLeft) {
  768. Map.Scroll_Map(DIR_W, distance, true);
  769. input = KN_NONE;
  770. }
  771. if (key != 0 && key == Options.KeyScrollRight) {
  772. Map.Scroll_Map(DIR_E, distance, true);
  773. input = KN_NONE;
  774. }
  775. if (key != 0 && key == Options.KeyScrollUp) {
  776. Map.Scroll_Map(DIR_N, distance, true);
  777. input = KN_NONE;
  778. }
  779. if (key != 0 && key == Options.KeyScrollDown) {
  780. Map.Scroll_Map(DIR_S, distance, true);
  781. input = KN_NONE;
  782. }
  783. /*
  784. ** Teams are handled by the 10 special team keys. The manual comparison
  785. ** to the KN numbers is because the Windows keyboard driver can vary
  786. ** the base code number for the key depending on the shift or alt key
  787. ** state!
  788. */
  789. if (input != 0 && (plain == Options.KeyTeam1 || plain == KN_1)) {
  790. Handle_Team(0, action);
  791. input = KN_NONE;
  792. }
  793. if (input != 0 && (plain == Options.KeyTeam2 || plain == KN_2)) {
  794. Handle_Team(1, action);
  795. input = KN_NONE;
  796. }
  797. if (input != 0 && (plain == Options.KeyTeam3 || plain == KN_3)) {
  798. Handle_Team(2, action);
  799. input = KN_NONE;
  800. }
  801. if (input != 0 && (plain == Options.KeyTeam4 || plain == KN_4)) {
  802. Handle_Team(3, action);
  803. input = KN_NONE;
  804. }
  805. if (input != 0 && (plain == Options.KeyTeam5 || plain == KN_5)) {
  806. Handle_Team(4, action);
  807. input = KN_NONE;
  808. }
  809. if (input != 0 && (plain == Options.KeyTeam6 || plain == KN_6)) {
  810. Handle_Team(5, action);
  811. input = KN_NONE;
  812. }
  813. if (input != 0 && (plain == Options.KeyTeam7 || plain == KN_7)) {
  814. Handle_Team(6, action);
  815. input = KN_NONE;
  816. }
  817. if (input != 0 && (plain == Options.KeyTeam8 || plain == KN_8)) {
  818. Handle_Team(7, action);
  819. input = KN_NONE;
  820. }
  821. if (input != 0 && (plain == Options.KeyTeam9 || plain == KN_9)) {
  822. Handle_Team(8, action);
  823. input = KN_NONE;
  824. }
  825. if (input != 0 && (plain == Options.KeyTeam10 || plain == KN_0)) {
  826. Handle_Team(9, action);
  827. input = KN_NONE;
  828. }
  829. /*
  830. ** Handle the bookmark hotkeys.
  831. */
  832. if (input != 0 && plain == Options.KeyBookmark1 && !Debug_Map) {
  833. Handle_View(0, action);
  834. input = KN_NONE;
  835. }
  836. if (input != 0 && plain == Options.KeyBookmark2 && !Debug_Map) {
  837. Handle_View(1, action);
  838. input = KN_NONE;
  839. }
  840. if (input != 0 && plain == Options.KeyBookmark3 && !Debug_Map) {
  841. Handle_View(2, action);
  842. input = KN_NONE;
  843. }
  844. if (input != 0 && plain == Options.KeyBookmark4 && !Debug_Map) {
  845. Handle_View(3, action);
  846. input = KN_NONE;
  847. }
  848. #ifdef CHEAT_KEYS
  849. if (input != 0 && Debug_Flag && input && (input & KN_RLSE_BIT) == 0) {
  850. Debug_Key(input);
  851. }
  852. #endif
  853. }
  854. void Toggle_Formation(void) {
  855. // MBL 03.23.2020: this has been copied to DLLExportClass::Team_Units_Formation_Toggle_On(), and modified as needed
  856. #if 0
  857. int team = -1;
  858. long minx = 0x7FFFFFFFL, miny = 0x7FFFFFFFL;
  859. long maxx = 0, maxy = 0;
  860. int index;
  861. bool setform = 0;
  862. //
  863. // Recording support
  864. //
  865. if (Session.Record) {
  866. FormationEvent = 1;
  867. }
  868. /*
  869. ** Find the first selected object that is a member of a team, and
  870. ** register his group as the team we're using. Once we find the team
  871. ** number, update the 'setform' flag to know whether we should be setting
  872. ** the formation's offsets, or clearing them. If they currently have
  873. ** illegal offsets (as in 0x80000000), then we're setting.
  874. */
  875. for (index = 0; index < Units.Count(); index++) {
  876. UnitClass * obj = Units.Ptr(index);
  877. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->IsSelected) {
  878. team = obj->Group;
  879. if (team != -1) {
  880. setform = obj->XFormOffset == (int)0x80000000;
  881. TeamSpeed[team] = SPEED_WHEEL;
  882. TeamMaxSpeed[team] = MPH_LIGHT_SPEED;
  883. break;
  884. }
  885. }
  886. }
  887. if (team == -1) {
  888. for (index = 0; index < Infantry.Count(); index++) {
  889. InfantryClass * obj = Infantry.Ptr(index);
  890. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->IsSelected) {
  891. team = obj->Group;
  892. if (team != -1) {
  893. setform = obj->XFormOffset == (int)0x80000000;
  894. TeamSpeed[team] = SPEED_WHEEL;
  895. TeamMaxSpeed[team] = MPH_LIGHT_SPEED;
  896. break;
  897. }
  898. }
  899. }
  900. }
  901. if (team == -1) {
  902. for (index = 0; index < Vessels.Count(); index++) {
  903. VesselClass * obj = Vessels.Ptr(index);
  904. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->IsSelected) {
  905. team = obj->Group;
  906. if (team != -1) {
  907. setform = obj->XFormOffset == 0x80000000UL;
  908. TeamSpeed[team] = SPEED_WHEEL;
  909. TeamMaxSpeed[team] = MPH_LIGHT_SPEED;
  910. break;
  911. }
  912. }
  913. }
  914. }
  915. if (team == -1) return;
  916. /*
  917. ** Now that we have a team, let's go set (or clear) the formation offsets.
  918. */
  919. for (index = 0; index < Units.Count(); index++) {
  920. UnitClass * obj = Units.Ptr(index);
  921. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team) {
  922. obj->Mark(MARK_CHANGE);
  923. if (setform) {
  924. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  925. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  926. if (xc < minx) minx = xc;
  927. if (xc > maxx) maxx = xc;
  928. if (yc < miny) miny = yc;
  929. if (yc > maxy) maxy = yc;
  930. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  931. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  932. TeamSpeed[team] = obj->Class->Speed;
  933. }
  934. } else {
  935. obj->XFormOffset = obj->YFormOffset = (int)0x80000000;
  936. }
  937. }
  938. }
  939. for (index = 0; index < Infantry.Count(); index++) {
  940. InfantryClass * obj = Infantry.Ptr(index);
  941. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team) {
  942. obj->Mark(MARK_CHANGE);
  943. if (setform) {
  944. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  945. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  946. if (xc < minx) minx = xc;
  947. if (xc > maxx) maxx = xc;
  948. if (yc < miny) miny = yc;
  949. if (yc > maxy) maxy = yc;
  950. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  951. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  952. }
  953. } else {
  954. obj->XFormOffset = obj->YFormOffset = (int)0x80000000;
  955. }
  956. }
  957. }
  958. for (index = 0; index < Vessels.Count(); index++) {
  959. VesselClass * obj = Vessels.Ptr(index);
  960. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team) {
  961. obj->Mark(MARK_CHANGE);
  962. if (setform) {
  963. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  964. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  965. if (xc < minx) minx = xc;
  966. if (xc > maxx) maxx = xc;
  967. if (yc < miny) miny = yc;
  968. if (yc > maxy) maxy = yc;
  969. if (obj->Class->MaxSpeed < TeamMaxSpeed[team]) {
  970. TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  971. }
  972. } else {
  973. obj->XFormOffset = obj->YFormOffset = 0x80000000UL;
  974. }
  975. }
  976. }
  977. /*
  978. ** All the units have been counted to find the bounding rectangle and
  979. ** center of the formation, or to clear their offsets. Now, if we're to
  980. ** set them into formation, proceed to do so. Otherwise, bail.
  981. */
  982. if (setform) {
  983. int centerx = (int)((maxx - minx)/2)+minx;
  984. int centery = (int)((maxy - miny)/2)+miny;
  985. for (index = 0; index < Units.Count(); index++) {
  986. UnitClass * obj = Units.Ptr(index);
  987. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team) {
  988. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  989. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  990. obj->XFormOffset = xc - centerx;
  991. obj->YFormOffset = yc - centery;
  992. }
  993. }
  994. for (index = 0; index < Infantry.Count(); index++) {
  995. InfantryClass * obj = Infantry.Ptr(index);
  996. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team ) {
  997. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  998. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  999. obj->XFormOffset = xc - centerx;
  1000. obj->YFormOffset = yc - centery;
  1001. }
  1002. }
  1003. for (index = 0; index < Vessels.Count(); index++) {
  1004. VesselClass * obj = Vessels.Ptr(index);
  1005. if (obj && !obj->IsInLimbo && obj->House == PlayerPtr && obj->Group == team ) {
  1006. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  1007. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  1008. obj->XFormOffset = xc - centerx;
  1009. obj->YFormOffset = yc - centery;
  1010. }
  1011. }
  1012. }
  1013. #endif
  1014. }
  1015. /***********************************************************************************************
  1016. * Message_Input -- allows inter-player message input processing *
  1017. * *
  1018. * INPUT: *
  1019. * input key value *
  1020. * *
  1021. * OUTPUT: *
  1022. * none. *
  1023. * *
  1024. * WARNINGS: *
  1025. * none. *
  1026. * *
  1027. * HISTORY: *
  1028. * 05/22/1995 BRR : Created. *
  1029. *=============================================================================================*/
  1030. //#pragma off (unreferenced)
  1031. static void Message_Input(KeyNumType &input)
  1032. {
  1033. int rc;
  1034. char txt[MAX_MESSAGE_LENGTH+32];
  1035. int id;
  1036. // SerialPacketType * serial_packet;
  1037. //int i;
  1038. KeyNumType copy_input;
  1039. //char *msg;
  1040. /*
  1041. ** Check keyboard input for a request to send a message.
  1042. ** The 'to' argument for Add_Edit is prefixed to the message buffer; the
  1043. ** message buffer is big enough for the 'to' field plus MAX_MESSAGE_LENGTH.
  1044. ** To send the message, calling Get_Edit_Buf retrieves the buffer minus the
  1045. ** 'to' portion. At the other end, the buffer allocated to display the
  1046. ** message must be MAX_MESSAGE_LENGTH plus the size of "From: xxx (house)".
  1047. */
  1048. #ifdef WOLAPI_INTEGRATION
  1049. if (Session.Type != GAME_NORMAL && Session.Type != GAME_SKIRMISH &&
  1050. ( ( input >= KN_F1 && input < (KN_F1 + Session.MaxPlayers) ) || input == PAGE_RESPOND_KEY ) &&
  1051. !Session.Messages.Is_Edit()) {
  1052. #else
  1053. if (Session.Type != GAME_NORMAL && Session.Type != GAME_SKIRMISH && input >= KN_F1 && input < (KN_F1 + Session.MaxPlayers) && !Session.Messages.Is_Edit()) {
  1054. #endif
  1055. memset (txt, 0, 40);
  1056. /*
  1057. ** For a serial game, send a message on F1 or F4; set 'txt' to the
  1058. ** "Message:" string & add an editable message to the list.
  1059. */
  1060. if (Session.Type==GAME_NULL_MODEM || Session.Type==GAME_MODEM) {
  1061. if (input==KN_F1 || input==(KN_F1 + Session.MaxPlayers - 1)) {
  1062. strcpy(txt, Text_String(TXT_MESSAGE)); // "Message:"
  1063. Session.Messages.Add_Edit (Session.ColorIdx,
  1064. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  1065. Map.Flag_To_Redraw(false);
  1066. }
  1067. } else if ((Session.Type == GAME_IPX || Session.Type == GAME_INTERNET) && !Session.Messages.Is_Edit()) {
  1068. /*
  1069. ** For a network game:
  1070. ** F1-F7 = "To <name> (house):" (only allowed if we're not in ObiWan mode)
  1071. ** F8 = "To All:"
  1072. */
  1073. if (input==(KN_F1 + Session.MaxPlayers - 1)) {
  1074. Session.MessageAddress = IPXAddressClass(); // set to broadcast
  1075. strcpy(txt, Text_String(TXT_TO_ALL)); // "To All:"
  1076. Session.Messages.Add_Edit(Session.ColorIdx,
  1077. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  1078. Map.Flag_To_Redraw(false);
  1079. #ifdef WOLAPI_INTEGRATION
  1080. } else if ((input - KN_F1) < Ipx.Num_Connections() && !Session.ObiWan && input != PAGE_RESPOND_KEY ) {
  1081. #else
  1082. } else if ((input - KN_F1) < Ipx.Num_Connections() && !Session.ObiWan) {
  1083. #endif
  1084. id = Ipx.Connection_ID(input - KN_F1);
  1085. Session.MessageAddress = (*(Ipx.Connection_Address (id)));
  1086. sprintf(txt, Text_String(TXT_TO), Ipx.Connection_Name(id));
  1087. Session.Messages.Add_Edit(Session.ColorIdx,
  1088. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  1089. Map.Flag_To_Redraw(false);
  1090. }
  1091. #ifdef WOLAPI_INTEGRATION
  1092. else if( Session.Type == GAME_INTERNET && pWolapi && !pWolapi->bConnectionDown && input == PAGE_RESPOND_KEY )
  1093. {
  1094. if( *pWolapi->szExternalPager )
  1095. {
  1096. // Respond to a page from external ww online user that paged me.
  1097. // Set MessageAddress to all zeroes, as a flag to ourselves later on.
  1098. NetNumType blip;
  1099. NetNodeType blop;
  1100. memset( blip, 0, 4 );
  1101. memset( blop, 0, 6 );
  1102. Session.MessageAddress = IPXAddressClass( blip, blop );
  1103. // Tell pWolapi not to reset szExternalPager for the time being.
  1104. pWolapi->bFreezeExternalPager = true;
  1105. sprintf( txt, Text_String( TXT_TO ), pWolapi->szExternalPager );
  1106. Session.Messages.Add_Edit(Session.ColorIdx,
  1107. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  1108. Map.Flag_To_Redraw(false);
  1109. Keyboard->Clear();
  1110. }
  1111. else
  1112. {
  1113. Session.Messages.Add_Message( NULL, 0, TXT_WOL_NOTPAGED, PCOLOR_GOLD, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_FULLSHADOW, Rule.MessageDelay * TICKS_PER_MINUTE );
  1114. Sound_Effect( VOC_SYS_ERROR );
  1115. }
  1116. }
  1117. #endif
  1118. }
  1119. #if(TEN)
  1120. /*
  1121. ** For a TEN game:
  1122. ** F1-F7 = "To <name> (house):" (only allowed if we're not in ObiWan mode)
  1123. ** F8 = "To All:"
  1124. */
  1125. else if (Session.Type == GAME_TEN && !Session.Messages.Is_Edit()) {
  1126. if (input==(KN_F1 + Session.MaxPlayers - 1)) {
  1127. Session.TenMessageAddress = -1; // set to broadcast
  1128. strcpy(txt,Text_String(TXT_TO_ALL)); // "To All:"
  1129. Session.Messages.Add_Edit(Session.ColorIdx,
  1130. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  1131. Map.Flag_To_Redraw(false);
  1132. } else if ((input - KN_F1) < Ten->Num_Connections() && !Session.ObiWan) {
  1133. id = Ten->Connection_ID(input - KN_F1);
  1134. Session.TenMessageAddress = Ten->Connection_Address(id);
  1135. sprintf(txt,Text_String(TXT_TO),Ten->Connection_Name(id));
  1136. Session.Messages.Add_Edit(Session.ColorIdx,
  1137. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  1138. Map.Flag_To_Redraw(false);
  1139. }
  1140. }
  1141. #endif // TEN
  1142. #if(MPATH)
  1143. /*
  1144. ** For a MPATH game:
  1145. ** F1-F7 = "To <name> (house):" (only allowed if we're not in ObiWan mode)
  1146. ** F8 = "To All:"
  1147. */
  1148. else if (Session.Type == GAME_MPATH && !Session.Messages.Is_Edit()) {
  1149. if (input==(KN_F1 + Session.MaxPlayers - 1)) {
  1150. Session.MPathMessageAddress = 0; // set to broadcast
  1151. strcpy(txt,Text_String(TXT_TO_ALL)); // "To All:"
  1152. Session.Messages.Add_Edit(Session.ColorIdx,
  1153. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  1154. Map.Flag_To_Redraw(false);
  1155. } else if ((input - KN_F1) < MPath->Num_Connections() && !Session.ObiWan) {
  1156. id = MPath->Connection_ID(input - KN_F1);
  1157. Session.MPathMessageAddress = MPath->Connection_Address(id);
  1158. sprintf(txt,Text_String(TXT_TO),MPath->Connection_Name(id));
  1159. Session.Messages.Add_Edit(Session.ColorIdx,
  1160. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 0, 232 * RESFACTOR);
  1161. Map.Flag_To_Redraw(false);
  1162. }
  1163. }
  1164. #endif // MPATH
  1165. }
  1166. /*
  1167. ** Process message-system input; send the message out if RETURN is hit.
  1168. */
  1169. copy_input = input;
  1170. rc = Session.Messages.Input(input);
  1171. /*
  1172. ** If a single character has been added to an edit buffer, update the display.
  1173. */
  1174. if (rc == 1 && Session.Type != GAME_NORMAL) {
  1175. Map.Flag_To_Redraw(false);
  1176. }
  1177. /*
  1178. ** If backspace was hit, redraw the map. If the edit message was removed,
  1179. ** the map must be force-drawn, since it won't be able to compute the
  1180. ** cells to redraw; otherwise, let the map compute the cells to redraw,
  1181. ** by not force-drawing it, but just setting the IsToRedraw bit.
  1182. */
  1183. if (rc==2 && Session.Type != GAME_NORMAL) {
  1184. if (copy_input==KN_ESC) {
  1185. Map.Flag_To_Redraw(true);
  1186. #ifdef WOLAPI_INTEGRATION
  1187. if( pWolapi )
  1188. // Just in case user was responding to a page from outside the game, and we had frozen the "szExternalPager".
  1189. pWolapi->bFreezeExternalPager = false;
  1190. #endif
  1191. } else {
  1192. Map.Flag_To_Redraw(false);
  1193. }
  1194. Map.DisplayClass::IsToRedraw = true;
  1195. }
  1196. /*
  1197. ** Send a message
  1198. */
  1199. if ((rc==3 || rc==4) && Session.Type != GAME_NORMAL && Session.Type != GAME_SKIRMISH) {
  1200. #if (0)
  1201. /*
  1202. ** Serial game: fill in a SerialPacketType & send it.
  1203. ** (Note: The size of the SerialPacketType.Command must be the same as
  1204. ** the EventClass.Type!)
  1205. */
  1206. if (Session.Type==GAME_NULL_MODEM || Session.Type==GAME_MODEM) {
  1207. serial_packet = (SerialPacketType *)NullModem.BuildBuf;
  1208. serial_packet->Command = SERIAL_MESSAGE;
  1209. strcpy (serial_packet->Name, Session.Players[0]->Name);
  1210. serial_packet->ID = Session.ColorIdx;
  1211. if (rc==3) {
  1212. strcpy (serial_packet->Message.Message, Session.Messages.Get_Edit_Buf());
  1213. } else {
  1214. strcpy (serial_packet->Message.Message, Session.Messages.Get_Overflow_Buf());
  1215. Session.Messages.Clear_Overflow_Buf();
  1216. }
  1217. /*
  1218. ** Send the message, and store this message in our LastMessage
  1219. ** buffer; the computer may send us a version of it later.
  1220. */
  1221. NullModem.Send_Message(NullModem.BuildBuf,
  1222. sizeof(SerialPacketType), 1);
  1223. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1224. char *ptr = &serial_packet->Message.Message[0];
  1225. if (!strncmp(ptr,"SECRET UNITS ON ",15) && NewUnitsEnabled) {
  1226. Enable_Secret_Units();
  1227. }
  1228. #endif
  1229. strcpy(Session.LastMessage, serial_packet->Message.Message);
  1230. } else if (Session.Type == GAME_IPX || Session.Type == GAME_INTERNET) {
  1231. #ifdef WOLAPI_INTEGRATION
  1232. NetNumType blip;
  1233. NetNodeType blop;
  1234. Session.MessageAddress.Get_Address( blip, blop );
  1235. if( blip[0] + blip[1] + blip[2] + blip[3] + blop[0] + blop[1] + blop[2] + blop[3] + blop[4] + blop[5] == 0 )
  1236. {
  1237. // This message is a response to the last person that paged me.
  1238. if( pWolapi && !pWolapi->bConnectionDown ) // (As connection may have gone down.)
  1239. {
  1240. pWolapi->Page( pWolapi->szExternalPager, Session.Messages.Get_Edit_Buf(), false );
  1241. pWolapi->bFreezeExternalPager = false;
  1242. }
  1243. }
  1244. else
  1245. #endif
  1246. {
  1247. /*
  1248. ** Network game: fill in a GlobalPacketType & send it.
  1249. */
  1250. Session.GPacket.Command = NET_MESSAGE;
  1251. strcpy (Session.GPacket.Name, Session.Players[0]->Name);
  1252. Session.GPacket.Message.Color = Session.ColorIdx;
  1253. Session.GPacket.Message.NameCRC = Compute_Name_CRC(Session.GameName);
  1254. if (rc==3) {
  1255. strcpy (Session.GPacket.Message.Buf, Session.Messages.Get_Edit_Buf());
  1256. } else {
  1257. strcpy (Session.GPacket.Message.Buf,
  1258. Session.Messages.Get_Overflow_Buf());
  1259. Session.Messages.Clear_Overflow_Buf();
  1260. }
  1261. /*
  1262. ** If 'F4' was hit, MessageAddress will be a broadcast address; send
  1263. ** the message to every player we have a connection with.
  1264. */
  1265. if (Session.MessageAddress.Is_Broadcast()) {
  1266. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1267. char *ptr = &Session.GPacket.Message.Buf[0];
  1268. if (!strncmp(ptr,"SECRET UNITS ON ",15) && NewUnitsEnabled) {
  1269. *ptr = 'X'; // force it to an odd hack so we know it was broadcast.
  1270. Enable_Secret_Units();
  1271. }
  1272. #endif
  1273. for (i = 0; i < Ipx.Num_Connections(); i++) {
  1274. Ipx.Send_Global_Message(&Session.GPacket,
  1275. sizeof(GlobalPacketType), 1,
  1276. Ipx.Connection_Address(Ipx.Connection_ID(i)));
  1277. Ipx.Service();
  1278. }
  1279. } else {
  1280. /*
  1281. ** Otherwise, MessageAddress contains the exact address to send to.
  1282. ** Send to that address only.
  1283. */
  1284. Ipx.Send_Global_Message(&Session.GPacket,
  1285. sizeof(GlobalPacketType), 1,
  1286. &Session.MessageAddress);
  1287. Ipx.Service();
  1288. }
  1289. /*
  1290. ** Store this message in our LastMessage buffer; the computer may send
  1291. ** us a version of it later.
  1292. */
  1293. strcpy(Session.LastMessage, Session.GPacket.Message.Buf);
  1294. }
  1295. }
  1296. #if(TEN)
  1297. /*
  1298. ** TEN game: fill in a GlobalPacketType & send it.
  1299. */
  1300. else if (Session.Type == GAME_TEN) {
  1301. Session.GPacket.Command = NET_MESSAGE;
  1302. strcpy (Session.GPacket.Name, Session.Players[0]->Name);
  1303. Session.GPacket.Message.Color = Session.ColorIdx;
  1304. Session.GPacket.Message.NameCRC = Compute_Name_CRC(Session.GameName);
  1305. if (rc==3) {
  1306. strcpy (Session.GPacket.Message.Buf, Session.Messages.Get_Edit_Buf());
  1307. } else {
  1308. strcpy (Session.GPacket.Message.Buf,
  1309. Session.Messages.Get_Overflow_Buf());
  1310. Session.Messages.Clear_Overflow_Buf();
  1311. }
  1312. Ten->Send_Global_Message(&Session.GPacket, sizeof(GlobalPacketType),
  1313. 1, Session.TenMessageAddress);
  1314. }
  1315. #endif // TEN
  1316. #if(MPATH)
  1317. /*
  1318. ** MPATH game: fill in a GlobalPacketType & send it.
  1319. */
  1320. else if (Session.Type == GAME_MPATH) {
  1321. Session.GPacket.Command = NET_MESSAGE;
  1322. strcpy (Session.GPacket.Name, Session.Players[0]->Name);
  1323. Session.GPacket.Message.Color = Session.ColorIdx;
  1324. Session.GPacket.Message.NameCRC = Compute_Name_CRC(Session.GameName);
  1325. if (rc==3) {
  1326. strcpy (Session.GPacket.Message.Buf, Session.Messages.Get_Edit_Buf());
  1327. } else {
  1328. strcpy (Session.GPacket.Message.Buf,
  1329. Session.Messages.Get_Overflow_Buf());
  1330. Session.Messages.Clear_Overflow_Buf();
  1331. }
  1332. MPath->Send_Global_Message(&Session.GPacket, sizeof(GlobalPacketType),
  1333. 1, Session.MPathMessageAddress);
  1334. }
  1335. #endif // MPATH
  1336. /*
  1337. ** Tell the map to completely update itself, since a message is now missing.
  1338. */
  1339. Map.Flag_To_Redraw(true);
  1340. #endif
  1341. }
  1342. }
  1343. //#pragma on (unreferenced)
  1344. /***********************************************************************************************
  1345. * Color_Cycle -- Handle the general palette color cycling. *
  1346. * *
  1347. * This is a maintenance routine that handles the color cycling. It should be called as *
  1348. * often as necessary to achieve smooth color cycling effects -- at least 8 times a second. *
  1349. * *
  1350. * INPUT: none *
  1351. * *
  1352. * OUTPUT: none *
  1353. * *
  1354. * WARNINGS: none *
  1355. * *
  1356. * HISTORY: *
  1357. * 05/31/1994 JLB : Created. *
  1358. * 06/10/1994 JLB : Uses new cycle color values. *
  1359. * 12/21/1994 JLB : Handles text fade color. *
  1360. * 07/16/1996 JLB : Faster pulsing of white color. *
  1361. *=============================================================================================*/
  1362. void Color_Cycle(void)
  1363. {
  1364. static CDTimerClass<SystemTimerClass> _timer;
  1365. static CDTimerClass<SystemTimerClass> _ftimer;
  1366. static bool _up = false;
  1367. static int val = 255;
  1368. bool changed = false;
  1369. if (Options.IsPaletteScroll) {
  1370. /*
  1371. ** Process the fading white color. It is used for the radar box and other glowing
  1372. ** game interface elements.
  1373. */
  1374. if (!_ftimer) {
  1375. _ftimer = TIMER_SECOND/6;
  1376. #define STEP_RATE 20
  1377. if (_up) {
  1378. val += STEP_RATE;
  1379. if (val > 150) {
  1380. val = 150;
  1381. _up = false;
  1382. }
  1383. } else {
  1384. val -= STEP_RATE;
  1385. if (val < 0x20) {
  1386. val = 0x20;
  1387. _up = true;
  1388. }
  1389. }
  1390. /*
  1391. ** Set the pulse color as the proportional value between white and the
  1392. ** minimum value for pulsing.
  1393. */
  1394. InGamePalette[CC_PULSE_COLOR] = GamePalette[WHITE];
  1395. InGamePalette[CC_PULSE_COLOR].Adjust(val, BlackColor);
  1396. /*
  1397. ** Pulse the glowing embers between medium and dark red.
  1398. */
  1399. InGamePalette[CC_EMBER_COLOR] = RGBClass(255, 80, 80);
  1400. InGamePalette[CC_EMBER_COLOR].Adjust(val, BlackColor);
  1401. changed = true;
  1402. }
  1403. /*
  1404. ** Process the color cycling effects -- water.
  1405. */
  1406. if (!_timer) {
  1407. _timer = TIMER_SECOND/4;
  1408. RGBClass first = InGamePalette[CYCLE_COLOR_START+CYCLE_COLOR_COUNT-1];
  1409. for (int index = CYCLE_COLOR_START+CYCLE_COLOR_COUNT-1; index >= CYCLE_COLOR_START; index--) {
  1410. InGamePalette[index] = InGamePalette[index-1];
  1411. }
  1412. InGamePalette[CYCLE_COLOR_START] = first;
  1413. changed = true;
  1414. }
  1415. /*
  1416. ** If any of the processing functions changed the palette, then this palette must be
  1417. ** passed to the system.
  1418. */
  1419. if (changed) {
  1420. BStart(BENCH_PALETTE);
  1421. InGamePalette.Set();
  1422. // Set_Palette(InGamePalette);
  1423. BEnd(BENCH_PALETTE);
  1424. }
  1425. }
  1426. }
  1427. /***********************************************************************************************
  1428. * Call_Back -- Main game maintenance callback routine. *
  1429. * *
  1430. * This routine handles all the "real time" processing that needs to *
  1431. * occur. This includes palette fading and sound updating. It needs *
  1432. * to be called as often as possible. *
  1433. * *
  1434. * INPUT: none *
  1435. * *
  1436. * OUTPUT: none *
  1437. * *
  1438. * WARNINGS: none *
  1439. * *
  1440. * HISTORY: *
  1441. * 10/07/1992 JLB : Created. *
  1442. *=============================================================================================*/
  1443. void Call_Back(void)
  1444. {
  1445. /*
  1446. ** Music and speech maintenance
  1447. */
  1448. if (SampleType) {
  1449. Sound_Callback();
  1450. Theme.AI();
  1451. Speak_AI();
  1452. }
  1453. /*
  1454. ** Network maintenance.
  1455. */
  1456. if (Session.Type == GAME_IPX || Session.Type == GAME_INTERNET) {
  1457. IPX_Call_Back();
  1458. }
  1459. /*
  1460. ** Serial game maintenance.
  1461. */
  1462. if (Session.Type == GAME_NULL_MODEM || ((Session.Type == GAME_MODEM) && Session.ModemService)) {
  1463. //NullModem.Service(); ST - 5/7/2019
  1464. }
  1465. #ifdef WOLAPI_INTEGRATION
  1466. // Wolapi maintenance.
  1467. if( pWolapi )
  1468. {
  1469. if( pWolapi->bInGame )
  1470. {
  1471. if( !pWolapi->bConnectionDown && ::timeGetTime() > pWolapi->dwTimeNextWolapiPump )
  1472. {
  1473. pWolapi->pChat->PumpMessages();
  1474. pWolapi->pNetUtil->PumpMessages();
  1475. pWolapi->dwTimeNextWolapiPump = ::timeGetTime() + WOLAPIPUMPWAIT + 700; // Slower pump during games.
  1476. if( pWolapi->bConnectionDown )
  1477. {
  1478. // Connection to server lost.
  1479. Session.Messages.Add_Message( NULL, 0, TXT_WOL_WOLAPIGONE, PCOLOR_GOLD, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_FULLSHADOW, Rule.MessageDelay * TICKS_PER_MINUTE );
  1480. Sound_Effect( WOLSOUND_LOGOUT );
  1481. // ajw (Wolapi object is now left around, so we can try to send game results.)
  1482. // // Kill wolapi.
  1483. // pWolapi->UnsetupCOMStuff();
  1484. // delete pWolapi;
  1485. // pWolapi = NULL;
  1486. }
  1487. }
  1488. }
  1489. else
  1490. {
  1491. // When showing a modal dialog during chat, this pumping is turned on. It's turned off immediately following.
  1492. if( pWolapi->bPump_In_Call_Back && ( ::timeGetTime() > pWolapi->dwTimeNextWolapiPump ) )
  1493. {
  1494. pWolapi->pChat->PumpMessages();
  1495. pWolapi->pNetUtil->PumpMessages();
  1496. pWolapi->dwTimeNextWolapiPump = ::timeGetTime() + WOLAPIPUMPWAIT;
  1497. }
  1498. }
  1499. }
  1500. #endif
  1501. #if(TEN)
  1502. if (Session.Type == GAME_TEN) {
  1503. TEN_Call_Back();
  1504. }
  1505. #endif // TEN
  1506. #if(MPATH)
  1507. if (Session.Type == GAME_MPATH) {
  1508. MPATH_Call_Back();
  1509. }
  1510. #endif // MPATH
  1511. }
  1512. void IPX_Call_Back(void)
  1513. {
  1514. #if (0)//PG
  1515. Ipx.Service();
  1516. /*
  1517. ** Read packets only if the game is "closed", so we don't steal global
  1518. ** messages from the connection dialogs.
  1519. */
  1520. if (!Session.NetOpen) {
  1521. if (Ipx.Get_Global_Message (&Session.GPacket, &Session.GPacketlen, &Session.GAddress, &Session.GProductID)) {
  1522. if (Session.GProductID == IPXGlobalConnClass::COMMAND_AND_CONQUER0) {
  1523. /*
  1524. ** If this is another player signing off, remove the connection &
  1525. ** mark that player's house as non-human, so the computer will take
  1526. ** it over.
  1527. */
  1528. if (Session.GPacket.Command == NET_SIGN_OFF) {
  1529. for (int i = 0; i < Ipx.Num_Connections(); i++) {
  1530. int id = Ipx.Connection_ID(i);
  1531. if (Session.GAddress == (*Ipx.Connection_Address(id))) {
  1532. Destroy_Connection(id, 0);
  1533. }
  1534. }
  1535. } else {
  1536. /*
  1537. ** Process a message from another user.
  1538. */
  1539. if (Session.GPacket.Command == NET_MESSAGE) {
  1540. bool msg_ok = false;
  1541. /*
  1542. ** If NetProtect is set, make sure this message came from within
  1543. ** this game.
  1544. */
  1545. if (!Session.NetProtect) {
  1546. msg_ok = true;
  1547. } else {
  1548. if (Session.GPacket.Message.NameCRC ==
  1549. Compute_Name_CRC(Session.GameName)) {
  1550. msg_ok = true;
  1551. } else {
  1552. msg_ok = false;
  1553. }
  1554. }
  1555. if (msg_ok) {
  1556. if (!Session.Messages.Concat_Message(Session.GPacket.Name,
  1557. Session.GPacket.Message.Color,
  1558. Session.GPacket.Message.Buf, Rule.MessageDelay * TICKS_PER_MINUTE)) {
  1559. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1560. if (NewUnitsEnabled && !strncmp(Session.GPacket.Message.Buf,"XECRET UNITS ON ",15)) {
  1561. Session.GPacket.Message.Buf[0]='S';
  1562. Enable_Secret_Units();
  1563. }
  1564. #endif
  1565. Session.Messages.Add_Message (Session.GPacket.Name,
  1566. Session.GPacket.Message.Color,
  1567. Session.GPacket.Message.Buf,
  1568. Session.GPacket.Message.Color,
  1569. TPF_6PT_GRAD | TPF_USE_GRAD_PAL |
  1570. TPF_FULLSHADOW, Rule.MessageDelay * TICKS_PER_MINUTE);
  1571. Sound_Effect(VOC_INCOMING_MESSAGE);
  1572. }
  1573. /*
  1574. ** Tell the map to do a partial update (just to force the messages
  1575. ** to redraw).
  1576. */
  1577. Map.Flag_To_Redraw(true);
  1578. /*
  1579. ** Save this message in our last-message buffer
  1580. */
  1581. strcpy(Session.LastMessage, Session.GPacket.Message.Buf);
  1582. }
  1583. } else {
  1584. Process_Global_Packet(&Session.GPacket, &Session.GAddress);
  1585. }
  1586. }
  1587. }
  1588. }
  1589. }
  1590. #endif
  1591. }
  1592. #if(TEN)
  1593. void TEN_Call_Back(void)
  1594. {
  1595. int id;
  1596. Ten->Service();
  1597. if (Ten->Get_Global_Message (&Session.GPacket, &Session.GPacketlen,
  1598. &Session.TenAddress)) {
  1599. //
  1600. // If this is another player signing off, remove the connection &
  1601. // mark that player's house as non-human, so the computer will take
  1602. // it over.
  1603. //
  1604. if (Session.GPacket.Command == NET_SIGN_OFF) {
  1605. for (int i = 0; i < Ten->Num_Connections(); i++) {
  1606. id = Ten->Connection_ID(i);
  1607. if (Session.TenAddress == Ten->Connection_Address(id)) {
  1608. Destroy_TEN_Connection(id, 0);
  1609. }
  1610. }
  1611. }
  1612. //
  1613. // Process a message from another user.
  1614. //
  1615. else if (Session.GPacket.Command == NET_MESSAGE) {
  1616. if (!Session.Messages.Concat_Message(Session.GPacket.Name,
  1617. Session.GPacket.Message.Color,
  1618. Session.GPacket.Message.Buf, Rule.MessageDelay * TICKS_PER_MINUTE)) {
  1619. Session.Messages.Add_Message (Session.GPacket.Name,
  1620. Session.GPacket.Message.Color,
  1621. Session.GPacket.Message.Buf,
  1622. Session.GPacket.Message.Color,
  1623. TPF_6PT_GRAD | TPF_USE_GRAD_PAL |
  1624. TPF_FULLSHADOW, Rule.MessageDelay * TICKS_PER_MINUTE);
  1625. Sound_Effect(VOC_INCOMING_MESSAGE);
  1626. /*
  1627. ** Tell the map to do a partial update (just to force the messages
  1628. ** to redraw).
  1629. */
  1630. Map.Flag_To_Redraw(true);
  1631. /*
  1632. ** Save this message in our last-message buffer
  1633. */
  1634. strcpy(Session.LastMessage, Session.GPacket.Message.Buf);
  1635. }
  1636. }
  1637. }
  1638. }
  1639. #endif // TEN
  1640. #if(MPATH)
  1641. void MPATH_Call_Back(void)
  1642. {
  1643. int id;
  1644. MPath->Service();
  1645. if (MPath->Get_Global_Message (&Session.GPacket, &Session.GPacketlen,
  1646. &Session.MPathAddress)) {
  1647. //
  1648. // If this is another player signing off, remove the connection &
  1649. // mark that player's house as non-human, so the computer will take
  1650. // it over.
  1651. //
  1652. if (Session.GPacket.Command == NET_SIGN_OFF) {
  1653. for (int i = 0; i < MPath->Num_Connections(); i++) {
  1654. id = MPath->Connection_ID(i);
  1655. if (Session.MPathAddress == MPath->Connection_Address(id)) {
  1656. Destroy_MPATH_Connection(id, 0);
  1657. }
  1658. }
  1659. }
  1660. //
  1661. // Process a message from another user.
  1662. //
  1663. else if (Session.GPacket.Command == NET_MESSAGE) {
  1664. if (!Session.Messages.Concat_Message(Session.GPacket.Name,
  1665. Session.GPacket.Message.Color,
  1666. Session.GPacket.Message.Buf, Rule.MessageDelay * TICKS_PER_MINUTE)) {
  1667. Session.Messages.Add_Message (Session.GPacket.Name,
  1668. Session.GPacket.Message.Color,
  1669. Session.GPacket.Message.Buf,
  1670. Session.GPacket.Message.Color,
  1671. TPF_6PT_GRAD | TPF_USE_GRAD_PAL |
  1672. TPF_FULLSHADOW, Rule.MessageDelay * TICKS_PER_MINUTE);
  1673. Sound_Effect(VOC_INCOMING_MESSAGE);
  1674. /*
  1675. ** Tell the map to do a partial update (just to force the messages
  1676. ** to redraw).
  1677. */
  1678. Map.Flag_To_Redraw(true);
  1679. /*
  1680. ** Save this message in our last-message buffer
  1681. */
  1682. strcpy(Session.LastMessage, Session.GPacket.Message.Buf);
  1683. }
  1684. }
  1685. }
  1686. }
  1687. #endif // MPATH
  1688. /***********************************************************************************************
  1689. * Language_Name -- Build filename for current language. *
  1690. * *
  1691. * This routine attaches a language specific suffix to the base *
  1692. * filename provided. Typical use of this is when loading language *
  1693. * specific files at game initialization time. *
  1694. * *
  1695. * INPUT: basename -- Base name to append language specific *
  1696. * extension to. *
  1697. * *
  1698. * OUTPUT: Returns with pointer to completed filename. *
  1699. * *
  1700. * WARNINGS: The return pointer value is valid only until the next time *
  1701. * this routine is called. *
  1702. * *
  1703. * HISTORY: *
  1704. * 10/07/1992 JLB : Created. *
  1705. *=============================================================================================*/
  1706. char const * Language_Name(char const * basename)
  1707. {
  1708. static char _fullname[_MAX_FNAME+_MAX_EXT];
  1709. if (!basename) return(NULL);
  1710. sprintf(_fullname, "%s.ENG", basename);
  1711. return(_fullname);
  1712. }
  1713. /***********************************************************************************************
  1714. * Source_From_Name -- Converts ASCII name into SourceType. *
  1715. * *
  1716. * This routine is used to convert an ASCII name representing a *
  1717. * SourceType into the actual SourceType value. Typically, this is *
  1718. * used when processing the scenario INI file. *
  1719. * *
  1720. * INPUT: name -- The ASCII source name to process. *
  1721. * *
  1722. * OUTPUT: Returns with the SourceType represented by the name *
  1723. * specified. *
  1724. * *
  1725. * WARNINGS: none *
  1726. * *
  1727. * HISTORY: *
  1728. * 04/17/1994 JLB : Created. *
  1729. *=============================================================================================*/
  1730. SourceType Source_From_Name(char const * name)
  1731. {
  1732. if (name) {
  1733. for (SourceType source = SOURCE_FIRST; source < SOURCE_COUNT; source++) {
  1734. if (stricmp(SourceName[source], name) == 0) {
  1735. return(source);
  1736. }
  1737. }
  1738. }
  1739. return(SOURCE_NONE);
  1740. }
  1741. /***********************************************************************************************
  1742. * Name_From_Source -- retrieves the name for the given SourceType *
  1743. * *
  1744. * INPUT: *
  1745. * source SourceType to get the name for *
  1746. * *
  1747. * OUTPUT: *
  1748. * name of SourceType *
  1749. * *
  1750. * WARNINGS: *
  1751. * none. *
  1752. * *
  1753. * HISTORY: *
  1754. * 11/15/1994 BR : Created. *
  1755. *=============================================================================================*/
  1756. char const * Name_From_Source(SourceType source)
  1757. {
  1758. if ((unsigned)source < SOURCE_COUNT) {
  1759. return(SourceName[source]);
  1760. }
  1761. return("None");
  1762. }
  1763. /***********************************************************************************************
  1764. * Theater_From_Name -- Converts ASCII name into a theater number. *
  1765. * *
  1766. * This routine converts an ASCII representation of a theater and converts it into a *
  1767. * matching theater number. If no match was found, then THEATER_NONE is returned. *
  1768. * *
  1769. * INPUT: name -- Pointer to ASCII name to convert. *
  1770. * *
  1771. * OUTPUT: Returns with the name converted into a theater number. *
  1772. * *
  1773. * WARNINGS: none *
  1774. * *
  1775. * HISTORY: *
  1776. * 10/01/1994 JLB : Created. *
  1777. *=============================================================================================*/
  1778. TheaterType Theater_From_Name(char const * name)
  1779. {
  1780. TheaterType index;
  1781. if (name) {
  1782. for (index = THEATER_FIRST; index < THEATER_COUNT; index++) {
  1783. if (stricmp(name, Theaters[index].Name) == 0) {
  1784. return(index);
  1785. }
  1786. }
  1787. }
  1788. return(THEATER_NONE);
  1789. }
  1790. /***********************************************************************************************
  1791. * KN_To_Facing -- Converts a keyboard input number into a facing value. *
  1792. * *
  1793. * This routine determine which compass direction is represented by the keyboard value *
  1794. * provided. It is used for map scrolling and other directional control operations from *
  1795. * the keyboard. *
  1796. * *
  1797. * INPUT: input -- The KN number to convert. *
  1798. * *
  1799. * OUTPUT: Returns with the facing type that the keyboard number represents. If it could *
  1800. * not be translated, then FACING_NONE is returned. *
  1801. * *
  1802. * WARNINGS: none *
  1803. * *
  1804. * HISTORY: *
  1805. * 05/28/1994 JLB : Created. *
  1806. *=============================================================================================*/
  1807. FacingType KN_To_Facing(int input)
  1808. {
  1809. input &= ~(KN_ALT_BIT|KN_SHIFT_BIT|KN_CTRL_BIT);
  1810. switch (input) {
  1811. case KN_LEFT:
  1812. return(FACING_W);
  1813. case KN_RIGHT:
  1814. return(FACING_E);
  1815. case KN_UP:
  1816. return(FACING_N);
  1817. case KN_DOWN:
  1818. return(FACING_S);
  1819. case KN_UPLEFT:
  1820. return(FACING_NW);
  1821. case KN_UPRIGHT:
  1822. return(FACING_NE);
  1823. case KN_DOWNLEFT:
  1824. return(FACING_SW);
  1825. case KN_DOWNRIGHT:
  1826. return(FACING_SE);
  1827. default:
  1828. break;
  1829. }
  1830. return(FACING_NONE);
  1831. }
  1832. /***********************************************************************************************
  1833. * Sync_Delay -- Forces the game into a 15 FPS rate. *
  1834. * *
  1835. * This routine will wait until the timer for the current frame has expired before *
  1836. * returning. It is called at the end of every game loop in order to force the game loop *
  1837. * to run at a fixed rate. *
  1838. * *
  1839. * INPUT: none *
  1840. * *
  1841. * OUTPUT: none *
  1842. * *
  1843. * WARNINGS: This routine will delay an amount of time according to the game speed setting. *
  1844. * *
  1845. * HISTORY: *
  1846. * 01/04/1995 JLB : Created. *
  1847. * 03/06/1995 JLB : Fixed. *
  1848. *=============================================================================================*/
  1849. static void Sync_Delay(void)
  1850. {
  1851. /*
  1852. ** Accumulate the number of 'spare' ticks that are frittered away here.
  1853. */
  1854. SpareTicks += FrameTimer;
  1855. /*
  1856. ** Delay until the frame timer expires. This forces the game loop to be regulated to a
  1857. ** speed controlled by the game options slider.
  1858. */
  1859. while (FrameTimer) {
  1860. Color_Cycle();
  1861. Call_Back();
  1862. if (SpecialDialog == SDLG_NONE) {
  1863. #ifdef WIN32
  1864. WWMouse->Erase_Mouse(&HidPage, TRUE);
  1865. #endif //WIN32
  1866. KeyNumType input = KN_NONE;
  1867. int x, y;
  1868. Map.Input(input, x, y);
  1869. if (input) {
  1870. Keyboard_Process(input);
  1871. }
  1872. Map.Render();
  1873. }
  1874. }
  1875. Color_Cycle();
  1876. Call_Back();
  1877. }
  1878. /***********************************************************************************************
  1879. * Main_Loop -- This is the main game loop (as a single loop). *
  1880. * *
  1881. * This function will perform one game loop. *
  1882. * *
  1883. * INPUT: none *
  1884. * *
  1885. * OUTPUT: bool; Should the game end? *
  1886. * *
  1887. * WARNINGS: none *
  1888. * *
  1889. * HISTORY: *
  1890. * 10/01/1994 JLB : Created. *
  1891. *=============================================================================================*/
  1892. #ifdef WIN32
  1893. extern void Check_For_Focus_Loss(void);
  1894. void Reallocate_Big_Shape_Buffer(void);
  1895. #endif //WIN32
  1896. bool Main_Loop()
  1897. {
  1898. KeyNumType input; // Player input.
  1899. int x;
  1900. int y;
  1901. int framedelay;
  1902. Mono_Set_Cursor(0,0);
  1903. if (!GameActive) return(!GameActive);
  1904. #ifdef WIN32
  1905. /*
  1906. ** Call the focus loss handler
  1907. */
  1908. Check_For_Focus_Loss();
  1909. /*
  1910. ** Allocate extra memory for uncompressed shapes as needed
  1911. */
  1912. Reallocate_Big_Shape_Buffer();
  1913. #endif
  1914. /*
  1915. ** Sync-bug trapping code
  1916. */
  1917. if (Frame >= Session.TrapFrame) {
  1918. Session.Trap_Object();
  1919. }
  1920. //
  1921. // Initialize our AI processing timer
  1922. //
  1923. Session.ProcessTimer = TickCount;
  1924. #if 1
  1925. if (Session.TrapCheckHeap) {
  1926. Debug_Trap_Check_Heap = true;
  1927. }
  1928. #endif
  1929. #ifdef CHEAT_KEYS
  1930. /*
  1931. ** Update the running status debug display.
  1932. */
  1933. Self_Regulate();
  1934. #endif
  1935. BStart(BENCH_GAME_FRAME);
  1936. /*
  1937. ** If there is no theme playing, but it looks like one is required, then start one
  1938. ** playing. This is usually the symptom of there being no transition score.
  1939. */
  1940. if (SampleType && Theme.What_Is_Playing() == THEME_NONE) {
  1941. Theme.Queue_Song(THEME_PICK_ANOTHER);
  1942. }
  1943. /*
  1944. ** Setup the timer so that the Main_Loop function processes at the correct rate.
  1945. */
  1946. if (Session.Type != GAME_NORMAL && Session.Type != GAME_SKIRMISH &&
  1947. Session.CommProtocol == COMM_PROTOCOL_MULTI_E_COMP) {
  1948. //
  1949. // In playback mode, run as fast as possible.
  1950. //
  1951. if (Session.Play) {
  1952. FrameTimer = 0;
  1953. } else {
  1954. #ifdef FIXIT_VERSION_3
  1955. if( !Session.DesiredFrameRate )
  1956. Session.DesiredFrameRate = 60; // A division by zero was happening (very rare).
  1957. #endif
  1958. framedelay = TIMER_SECOND / Session.DesiredFrameRate;
  1959. FrameTimer = framedelay;
  1960. }
  1961. } else {
  1962. if (Options.GameSpeed != 0) {
  1963. FrameTimer = Options.GameSpeed +
  1964. (PlayerPtr->Difficulty == DIFF_EASY ? 1 : 0) -
  1965. (PlayerPtr->Difficulty == DIFF_HARD ? 1 : 0);
  1966. } else {
  1967. FrameTimer = Options.GameSpeed + (PlayerPtr->Difficulty == DIFF_EASY ? 1 : 0);
  1968. }
  1969. }
  1970. /*
  1971. ** Update the display, unless we're inside a dialog.
  1972. */
  1973. if (!Session.Play) {
  1974. #ifdef WIN32
  1975. if (SpecialDialog == SDLG_NONE && GameInFocus) {
  1976. WWMouse->Erase_Mouse(&HidPage, TRUE);
  1977. #else
  1978. if (SpecialDialog == SDLG_NONE) {
  1979. #endif
  1980. Map.Input(input, x, y);
  1981. if (input) {
  1982. Keyboard_Process(input);
  1983. }
  1984. Map.Render();
  1985. }
  1986. }
  1987. /*
  1988. ** Save map's position & selected objects, if we're recording the game.
  1989. */
  1990. if (Session.Record || Session.Play) {
  1991. Do_Record_Playback();
  1992. }
  1993. #ifndef SORTDRAW
  1994. /*
  1995. ** Sort the map's ground layer by y-coordinate value. This is done
  1996. ** outside the IsToRedraw check, for the purposes of game sync'ing
  1997. ** between machines; this way, all machines will sort the Map's
  1998. ** layer in the same way, and any processing done that's based on
  1999. ** the order of this layer will remain in sync.
  2000. */
  2001. DisplayClass::Layer[LAYER_GROUND].Sort();
  2002. #endif
  2003. /*
  2004. ** AI logic operations are performed here.
  2005. */
  2006. Logic.AI();
  2007. TimeQuake = false;
  2008. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2009. if (!PendingTimeQuake) {
  2010. TimeQuakeCenter = 0;
  2011. }
  2012. #endif
  2013. /*
  2014. ** Manage the inter-player message list. If Manage() returns true, it means
  2015. ** a message has expired & been removed, and the entire map must be updated.
  2016. */
  2017. if (Session.Messages.Manage()) {
  2018. #ifdef WIN32
  2019. HiddenPage.Clear();
  2020. #else //WIN32
  2021. HidPage.Clear();
  2022. #endif //WIN32
  2023. Map.Flag_To_Redraw(true);
  2024. }
  2025. //
  2026. // Measure how long it took to process the AI
  2027. //
  2028. Session.ProcessTicks += (TickCount - Session.ProcessTimer);
  2029. Session.ProcessFrames++;
  2030. /*
  2031. ** Process all commands that are ready to be processed.
  2032. */
  2033. Queue_AI();
  2034. /*
  2035. ** Keep track of elapsed time in the game.
  2036. */
  2037. Score.ElapsedTime += TIMER_SECOND / TICKS_PER_SECOND;
  2038. Call_Back();
  2039. /*
  2040. ** Check for player wins or loses according to global event flag.
  2041. */
  2042. if (PlayerWins) {
  2043. #ifdef WIN32
  2044. /*
  2045. ** Send the game statistics to WChat.
  2046. */
  2047. if (Session.Type == GAME_INTERNET && !GameStatisticsPacketSent) {
  2048. Register_Game_End_Time();
  2049. Send_Statistics_Packet(); // Player just won.
  2050. }
  2051. WWMouse->Erase_Mouse(&HidPage, TRUE);
  2052. #endif //WIN32
  2053. PlayerLoses = false;
  2054. PlayerWins = false;
  2055. PlayerRestarts = false;
  2056. Map.Help_Text(TXT_NONE);
  2057. Do_Win();
  2058. return(!GameActive);
  2059. }
  2060. if (PlayerLoses) {
  2061. #ifdef WIN32
  2062. /*
  2063. ** Send the game statistics to WChat.
  2064. */
  2065. if (Session.Type == GAME_INTERNET && !GameStatisticsPacketSent) {
  2066. Register_Game_End_Time();
  2067. Send_Statistics_Packet(); // Player just lost.
  2068. }
  2069. WWMouse->Erase_Mouse(&HidPage, TRUE);
  2070. #endif //WIN32
  2071. PlayerWins = false;
  2072. PlayerLoses = false;
  2073. PlayerRestarts = false;
  2074. Map.Help_Text(TXT_NONE);
  2075. Do_Lose();
  2076. return(!GameActive);
  2077. }
  2078. if (PlayerRestarts) {
  2079. #ifdef WIN32
  2080. WWMouse->Erase_Mouse(&HidPage, TRUE);
  2081. #endif //WIN32
  2082. PlayerWins = false;
  2083. PlayerLoses = false;
  2084. PlayerRestarts = false;
  2085. Map.Help_Text(TXT_NONE);
  2086. Do_Restart();
  2087. return(!GameActive);
  2088. }
  2089. #ifdef FIXIT_VERSION_3 // Stalemate games.
  2090. if( Session.Type != GAME_NORMAL && Session.Type != GAME_SKIRMISH && Session.Players.Count() == 2 &&
  2091. Scen.bLocalProposesDraw && Scen.bOtherProposesDraw )
  2092. {
  2093. // End game in a draw.
  2094. if (Session.Type == GAME_INTERNET && !GameStatisticsPacketSent) {
  2095. Register_Game_End_Time();
  2096. Send_Statistics_Packet();
  2097. }
  2098. WWMouse->Erase_Mouse(&HidPage, TRUE);
  2099. Map.Help_Text(TXT_NONE);
  2100. Do_Draw();
  2101. return(!GameActive);
  2102. }
  2103. #endif
  2104. /*
  2105. ** The frame logic has been completed. Increment the frame
  2106. ** counter.
  2107. */
  2108. Frame++;
  2109. /*
  2110. ** Is there a memory trasher altering the map??
  2111. */
  2112. if (Debug_Check_Map) {
  2113. if (!Map.Validate()) {
  2114. if (WWMessageBox().Process (TEXT_MAP_ERROR, TEXT_STOP, TEXT_CONTINUE)==0) {
  2115. GameActive = 0;
  2116. }
  2117. Map.Validate(); // give debugger a chance to catch it
  2118. }
  2119. }
  2120. #if (0) //ST - 5/8/2019
  2121. #ifdef WIN32
  2122. if (Debug_MotionCapture) {
  2123. static void ** _array = 0;
  2124. static int _sequence = 0;
  2125. static int _seqsize = Rule.MovieTime * TICKS_PER_MINUTE;
  2126. if (_array == NULL) {
  2127. _array = new void * [_seqsize];
  2128. memset(_array, '\0', _seqsize * sizeof(void*));
  2129. }
  2130. if (_array == NULL) {
  2131. Debug_MotionCapture = false;
  2132. }
  2133. static GraphicBufferClass temp_page( SeenBuff.Get_Width(),
  2134. SeenBuff.Get_Height(),
  2135. NULL,
  2136. SeenBuff.Get_Width() * SeenBuff.Get_Height());
  2137. int size = SeenBuff.Get_Width() * SeenBuff.Get_Height();
  2138. if (_sequence < _seqsize) {
  2139. if (_array[_sequence] == NULL) {
  2140. _array[_sequence] = new char[size];
  2141. }
  2142. if (_array[_sequence] != NULL) {
  2143. SeenBuff.Blit(temp_page);
  2144. memmove(_array[_sequence], temp_page.Get_Buffer(), size);
  2145. }
  2146. _sequence++;
  2147. } else {
  2148. Debug_MotionCapture = false;
  2149. CDFileClass file;
  2150. file.Cache(200000);
  2151. char filename[30];
  2152. for (int index = 0; index < _sequence; index++) {
  2153. memmove(temp_page.Get_Buffer(), _array[index], size);
  2154. sprintf(filename, "cap%04d.pcx", index);
  2155. file.Set_Name(filename);
  2156. Write_PCX_File(file, temp_page, & GamePalette);
  2157. }
  2158. _sequence = 0;
  2159. }
  2160. }
  2161. #endif
  2162. #endif
  2163. BEnd(BENCH_GAME_FRAME);
  2164. Sync_Delay();
  2165. return(!GameActive);
  2166. }
  2167. #ifdef SCENARIO_EDITOR
  2168. /***************************************************************************
  2169. * Map_Edit_Loop -- a mini-main loop for map edit mode only *
  2170. * *
  2171. * INPUT: *
  2172. * *
  2173. * OUTPUT: *
  2174. * *
  2175. * WARNINGS: *
  2176. * *
  2177. * HISTORY: *
  2178. * 10/19/1994 BR : Created. *
  2179. *=========================================================================*/
  2180. bool Map_Edit_Loop(void)
  2181. {
  2182. /*
  2183. ** Redraw the map.
  2184. */
  2185. Map.Render();
  2186. /*
  2187. ** Get user input (keys, mouse clicks).
  2188. */
  2189. KeyNumType input;
  2190. #ifdef WIN32
  2191. WWMouse->Erase_Mouse(&HidPage, TRUE);
  2192. #endif //WIN32
  2193. int x;
  2194. int y;
  2195. Map.Input(input, x, y);
  2196. /*
  2197. ** Process keypress.
  2198. */
  2199. if (input) {
  2200. Keyboard_Process(input);
  2201. }
  2202. Call_Back(); // maintains Theme.AI() for music
  2203. Color_Cycle();
  2204. return(!GameActive);
  2205. }
  2206. /***************************************************************************
  2207. * Go_Editor -- Enables/disables the map editor *
  2208. * *
  2209. * INPUT: *
  2210. * flag true = go into editor mode; false = go into game mode *
  2211. * *
  2212. * OUTPUT: *
  2213. * none. *
  2214. * *
  2215. * WARNINGS: *
  2216. * none. *
  2217. * *
  2218. * HISTORY: *
  2219. * 10/19/1994 BR : Created. *
  2220. *=========================================================================*/
  2221. void Go_Editor(bool flag)
  2222. {
  2223. /*
  2224. ** Go into Scenario Editor mode
  2225. */
  2226. if (flag) {
  2227. Debug_Map = true;
  2228. Debug_Unshroud = true;
  2229. /*
  2230. ** Un-select any selected objects
  2231. */
  2232. Unselect_All();
  2233. /*
  2234. ** Turn off the sidebar if it's on
  2235. */
  2236. Map.Activate(0);
  2237. /*
  2238. ** Reset the map's Button list for the new mode
  2239. */
  2240. Map.Init_IO();
  2241. /*
  2242. ** Force a complete redraw of the screen
  2243. */
  2244. #ifdef WIN32
  2245. HiddenPage.Clear();
  2246. #else
  2247. HidPage.Clear();
  2248. #endif
  2249. Map.Flag_To_Redraw(true);
  2250. Map.Render();
  2251. } else {
  2252. /*
  2253. ** Go into normal game mode
  2254. */
  2255. Debug_Map = false;
  2256. Debug_Unshroud = false;
  2257. /*
  2258. ** Un-select any selected objects
  2259. */
  2260. Unselect_All();
  2261. /*
  2262. ** Reset the map's Button list for the new mode
  2263. */
  2264. Map.Init_IO();
  2265. /*
  2266. ** Force a complete redraw of the screen
  2267. */
  2268. HidPage.Clear();
  2269. Map.Flag_To_Redraw(true);
  2270. Map.Render();
  2271. }
  2272. }
  2273. #endif
  2274. #if (0)
  2275. /***********************************************************************************************
  2276. * MixFileHandler -- Handles VQ file access. *
  2277. * *
  2278. * This routine is called from the VQ player when it needs to access the source file. By *
  2279. * using this routine it is possible to virtualize the file system. *
  2280. * *
  2281. * INPUT: vqa -- Pointer to the VQA handle for this animation. *
  2282. * *
  2283. * action-- The requested action to perform. *
  2284. * *
  2285. * buffer-- Optional buffer pointer as needed by the type of action. *
  2286. * *
  2287. * nbytes-- The number of bytes (if needed) for this operation. *
  2288. * *
  2289. * OUTPUT: Returns a value consistent with the action requested. *
  2290. * *
  2291. * WARNINGS: none *
  2292. * *
  2293. * HISTORY: *
  2294. * 07/04/1995 JLB : Created. *
  2295. *=============================================================================================*/
  2296. long MixFileHandler(VQAHandle * vqa, long action, void * buffer, long nbytes)
  2297. {
  2298. CCFileClass * file;
  2299. long error;
  2300. file = (CCFileClass *)vqa->VQAio;
  2301. /*
  2302. ** Perform the action specified by the stream command.
  2303. */
  2304. switch (action) {
  2305. /*
  2306. ** VQACMD_READ means read NBytes from the stream and place it in the
  2307. ** memory pointed to by Buffer.
  2308. **
  2309. ** Any error code returned will be remapped by VQA library into
  2310. ** VQAERR_READ.
  2311. */
  2312. case VQACMD_READ:
  2313. error = (file->Read(buffer, (unsigned short)nbytes) != (unsigned short)nbytes);
  2314. break;
  2315. /*
  2316. ** VQACMD_WRITE is analogous to VQACMD_READ.
  2317. **
  2318. ** Writing is not allowed to the VQA file, VQA library will remap the
  2319. ** error into VQAERR_WRITE.
  2320. */
  2321. case VQACMD_WRITE:
  2322. error = 1;
  2323. break;
  2324. /*
  2325. ** VQACMD_SEEK asks that you perform a seek relative to the current
  2326. ** position. NBytes is a signed number, indicating seek direction
  2327. ** (positive for forward, negative for backward). Buffer has no meaning
  2328. ** here.
  2329. **
  2330. ** Any error code returned will be remapped by VQA library into
  2331. ** VQAERR_SEEK.
  2332. */
  2333. case VQACMD_SEEK:
  2334. error = (file->Seek(nbytes, SEEK_CUR) == -1);
  2335. break;
  2336. /*
  2337. ** VQACMD_OPEN asks that you open your stream for access.
  2338. */
  2339. case VQACMD_OPEN:
  2340. file = new CCFileClass((char *)buffer);
  2341. if (file != NULL && file->Is_Available()) {
  2342. error = file->Open((char *)buffer, READ);
  2343. if (error != -1) {
  2344. vqa->VQAio = (unsigned long)file;
  2345. error = 0;
  2346. } else {
  2347. delete file;
  2348. file = 0;
  2349. error = 1;
  2350. }
  2351. } else {
  2352. error = 1;
  2353. }
  2354. break;
  2355. case VQACMD_CLOSE:
  2356. file->Close();
  2357. delete file;
  2358. file = 0;
  2359. vqa->VQAio = 0;
  2360. error = 0;
  2361. break;
  2362. /*
  2363. ** VQACMD_INIT means to prepare your stream for reading. This is used for
  2364. ** certain streams that can't be read immediately upon opening, and need
  2365. ** further preparation. This operation is allowed to fail; the error code
  2366. ** will be returned directly to the client.
  2367. */
  2368. case VQACMD_INIT:
  2369. /*
  2370. ** IFFCMD_CLEANUP means to terminate the transaction with the associated
  2371. ** stream. This is used for streams that can't simply be closed. This
  2372. ** operation is not allowed to fail; any error returned will be ignored.
  2373. */
  2374. case VQACMD_CLEANUP:
  2375. error = 0;
  2376. break;
  2377. default:
  2378. error = 0;
  2379. break;
  2380. }
  2381. return(error);
  2382. }
  2383. #endif
  2384. void Rebuild_Interpolated_Palette(unsigned char * interpal)
  2385. {
  2386. for (int y=0; y<255; y++) {
  2387. for (int x=y+1; x<256; x++) {
  2388. *(interpal + (y*256+x)) = *(interpal + (x*256+y));
  2389. }
  2390. }
  2391. }
  2392. unsigned char * InterpolatedPalettes[100];
  2393. BOOL PalettesRead;
  2394. unsigned PaletteCounter;
  2395. /***********************************************************************************************
  2396. * Load_Interpolated_Palettes -- Loads in any precalculated palettes for hires VQs *
  2397. * *
  2398. * *
  2399. * *
  2400. * INPUT: Name of palette file *
  2401. * *
  2402. * OUTPUT: Number of palettes loaded *
  2403. * *
  2404. * WARNINGS: None *
  2405. * *
  2406. * HISTORY: *
  2407. * 5/7/96 9:49AM ST : Created *
  2408. *=============================================================================================*/
  2409. int Load_Interpolated_Palettes(char const * filename, BOOL add)
  2410. {
  2411. int num_palettes=0;
  2412. int i;
  2413. int start_palette;
  2414. PalettesRead = FALSE;
  2415. CCFileClass file(filename);
  2416. if (!add) {
  2417. for (i=0; i < ARRAY_SIZE(InterpolatedPalettes); i++) {
  2418. InterpolatedPalettes[i]=NULL;
  2419. }
  2420. start_palette=0;
  2421. } else {
  2422. for (start_palette = 0; start_palette < ARRAY_SIZE(InterpolatedPalettes); start_palette++) {
  2423. if (!InterpolatedPalettes[start_palette]) break;
  2424. }
  2425. }
  2426. /*
  2427. ** Hack another interpolated palette if the requested one is
  2428. ** not present.
  2429. */
  2430. if (!file.Is_Available()) {
  2431. file.Set_Name("AAGUN.VQP");
  2432. }
  2433. if (file.Is_Available()) {
  2434. file.Open(READ);
  2435. file.Read(&num_palettes , 4);
  2436. for (i=0; i < num_palettes; i++) {
  2437. InterpolatedPalettes[i+start_palette] = (unsigned char *)malloc (65536);
  2438. memset (InterpolatedPalettes[i+start_palette], 0, 65536);
  2439. for (int y = 0; y < 256; y++) {
  2440. file.Read (InterpolatedPalettes[i+start_palette] + y*256 , y+1);
  2441. }
  2442. Rebuild_Interpolated_Palette(InterpolatedPalettes[i+start_palette]);
  2443. }
  2444. PalettesRead = TRUE;
  2445. file.Close();
  2446. }
  2447. PaletteCounter = 0;
  2448. return (num_palettes);
  2449. }
  2450. void Free_Interpolated_Palettes(void)
  2451. {
  2452. for (int i = 0; i < ARRAY_SIZE(InterpolatedPalettes) ;i++) {
  2453. if (InterpolatedPalettes[i]) {
  2454. free(InterpolatedPalettes[i]);
  2455. InterpolatedPalettes[i]=NULL;
  2456. }
  2457. }
  2458. }
  2459. /***********************************************************************************************
  2460. * Play_Movie -- Plays a VQ movie. *
  2461. * *
  2462. * Use this routine to play a VQ movie. It will dispatch the specified movie to the *
  2463. * VQ player. The routine will not return until the movie has finished playing. *
  2464. * *
  2465. * INPUT: name -- The name of the movie file (sans ".VQA"). *
  2466. * *
  2467. * theme -- The identifier for an optional theme that should be played in the *
  2468. * background while this VQ plays. *
  2469. * *
  2470. * clrscrn -- 'true' if to clear the screen when the movie is over *
  2471. * *
  2472. * OUTPUT: none *
  2473. * *
  2474. * WARNINGS: none *
  2475. * *
  2476. * HISTORY: *
  2477. * 12/19/1994 JLB : Created. *
  2478. *=============================================================================================*/
  2479. #ifdef WIN32
  2480. extern void Suspend_Audio_Thread(void);
  2481. extern void Resume_Audio_Thread(void);
  2482. #ifdef MOVIE640
  2483. extern GraphicBufferClass VQ640;
  2484. #endif
  2485. #endif
  2486. extern void Play_Movie_GlyphX(const char * movie_name, ThemeType theme, bool immediate);
  2487. void Play_Movie(char const * name, ThemeType theme, bool clrscrn, bool immediate)
  2488. {
  2489. #if (1)
  2490. if (strcmp(name, "x") == 0 || strcmp(name, "X") == 0) {
  2491. return;
  2492. }
  2493. Play_Movie_GlyphX(name, theme, immediate);
  2494. return;
  2495. #else
  2496. #ifdef MPEGMOVIE
  2497. //theme = theme;
  2498. //clrscrn = clrscrn;
  2499. if( Using_DVD() )
  2500. {
  2501. if (PlayMpegMovie(name))
  2502. return;
  2503. }
  2504. #endif
  2505. #ifdef CHEAT_KEYS
  2506. // Mono_Printf("Movie: %s\n", name);
  2507. #endif //CHEAT_KEYS
  2508. /*
  2509. ** Don't play movies in editor mode
  2510. */
  2511. if (Debug_Map) {
  2512. return;
  2513. }
  2514. #ifdef CHEAT_KEYS
  2515. // Mono_Printf("A\n");
  2516. #endif //CHEAT_KEYS
  2517. /*
  2518. ** Don't play movies in multiplayer mode
  2519. */
  2520. if (Session.Type != GAME_NORMAL) {
  2521. return;
  2522. }
  2523. #ifdef CHEAT_KEYS
  2524. //Mono_Printf("b\n");
  2525. #endif //CHEAT_KEYS
  2526. if (name) {
  2527. char fullname[_MAX_FNAME+_MAX_EXT];
  2528. _makepath(fullname, NULL, NULL, name, ".VQA");
  2529. #ifdef WIN32
  2530. char palname [_MAX_FNAME+_MAX_EXT];
  2531. _makepath(palname , NULL, NULL, name, ".VQP");
  2532. #endif //WIN32
  2533. #ifdef CHEAT_KEYS
  2534. // Mono_Set_Cursor(0, 0);Mono_Printf("[%s]", fullname);
  2535. #endif
  2536. if (!CCFileClass(fullname).Is_Available()){
  2537. #ifdef CHEAT_KEYS
  2538. // Mono_Printf("fullname: %s\n", fullname);
  2539. #endif //CHEAT_KEYS
  2540. return;
  2541. }
  2542. /*
  2543. ** Reset the anim control structure.
  2544. */
  2545. Anim_Init();
  2546. /*
  2547. ** Prepare to play a movie. First hide the mouse and stop any score that is playing.
  2548. ** While the score (if any) is fading to silence, fade the palette to black as well.
  2549. ** When the palette has finished fading, wait until the score has finished fading
  2550. ** before launching the movie.
  2551. */
  2552. Hide_Mouse();
  2553. Theme.Queue_Song(theme);
  2554. if (PreserveVQAScreen == 0 && !clrscrn) {
  2555. BlackPalette.Set(FADE_PALETTE_MEDIUM);
  2556. VisiblePage.Clear();
  2557. BlackPalette.Adjust(0x08, WhitePalette);
  2558. BlackPalette.Set();
  2559. BlackPalette.Adjust(0xFF);
  2560. BlackPalette.Set();
  2561. }
  2562. PreserveVQAScreen = 0;
  2563. Keyboard->Clear();
  2564. VQAHandle * vqa = NULL;
  2565. #ifdef WIN32
  2566. #ifdef MOVIE640
  2567. if(IsVQ640) {
  2568. AnimControl.ImageWidth = 640;
  2569. AnimControl.ImageHeight = 400;
  2570. AnimControl.ImageBuf = (unsigned char *)VQ640.Get_Offset();
  2571. } else {
  2572. AnimControl.ImageWidth = 320;
  2573. AnimControl.ImageHeight = 200;
  2574. AnimControl.ImageBuf = (unsigned char *)SysMemPage.Get_Offset();
  2575. }
  2576. #endif
  2577. #endif
  2578. if (!Debug_Quiet && Get_Digi_Handle() != -1) {
  2579. AnimControl.OptionFlags |= VQAOPTF_AUDIO;
  2580. } else {
  2581. AnimControl.OptionFlags &= ~VQAOPTF_AUDIO;
  2582. }
  2583. if ((vqa = VQA_Alloc()) != NULL) {
  2584. VQA_Init(vqa, MixFileHandler);
  2585. if (VQA_Open(vqa, fullname, &AnimControl) == 0) {
  2586. Brokeout = false;
  2587. #ifdef WIN32
  2588. //Suspend_Audio_Thread();
  2589. #ifdef MOVIE640
  2590. if(!IsVQ640) {
  2591. Load_Interpolated_Palettes(palname);
  2592. }
  2593. #else
  2594. Load_Interpolated_Palettes(palname);
  2595. #endif
  2596. //Set_Palette(BlackPalette);
  2597. SysMemPage.Clear();
  2598. InMovie = true;
  2599. #endif //WIN32
  2600. VQA_Play(vqa, VQAMODE_RUN);
  2601. VQA_Close(vqa);
  2602. #ifdef WIN32
  2603. //Resume_Audio_Thread();
  2604. InMovie = FALSE;
  2605. #ifdef MOVIE640
  2606. if(!IsVQ640) {
  2607. Free_Interpolated_Palettes();
  2608. }
  2609. #else
  2610. Free_Interpolated_Palettes();
  2611. #endif
  2612. IsVQ640 = false;
  2613. Set_Primary_Buffer_Format();
  2614. #endif //WIN32
  2615. /*
  2616. ** Any movie that ends prematurely must have the screen
  2617. ** cleared to avoid any unexpected palette glitches.
  2618. */
  2619. if (Brokeout) {
  2620. clrscrn = true;
  2621. VisiblePage.Clear();
  2622. Brokeout = false;
  2623. }
  2624. } else {
  2625. #ifndef NDEBUG
  2626. bool error = true;
  2627. assert(error);
  2628. #endif
  2629. }
  2630. VQA_Free(vqa);
  2631. } else {
  2632. assert(vqa != NULL);
  2633. }
  2634. #ifdef CHEAT_KEYS
  2635. //Mono_Printf("d");
  2636. #endif //CHEAT_KEYS
  2637. /*
  2638. ** Presume that the screen is left in a garbage state as well as the palette
  2639. ** being in an unknown condition. Recover from this by clearing the screen and
  2640. ** forcing the palette to black.
  2641. */
  2642. if (clrscrn) {
  2643. VisiblePage.Clear();
  2644. BlackPalette.Adjust(0x08, WhitePalette);
  2645. BlackPalette.Set();
  2646. BlackPalette.Adjust(0xFF);
  2647. BlackPalette.Set();
  2648. }
  2649. Show_Mouse();
  2650. }
  2651. #endif
  2652. }
  2653. void Play_Movie(VQType name, ThemeType theme, bool clrscrn, bool immediate)
  2654. {
  2655. if (name != VQ_NONE) {
  2656. if (name == VQ_REDINTRO) {
  2657. IsVQ640 = true;
  2658. }
  2659. Play_Movie(VQName[name], theme, clrscrn, immediate);
  2660. IsVQ640 = false;
  2661. }
  2662. }
  2663. // Denzil 5/18/98 - Mpeg movie playback
  2664. #ifdef MPEGMOVIE
  2665. extern LPDIRECTDRAWPALETTE PalettePtr;
  2666. bool PlayMpegMovie(const char* name)
  2667. {
  2668. char path[MAX_PATH];
  2669. CCFileClass file;
  2670. const char* filename;
  2671. #ifdef CHEAT_KEYS
  2672. if( bNoMovies )
  2673. return true;
  2674. #endif
  2675. sprintf(path, "movies\\%.8s.%.3s", name, "mpg");
  2676. filename = file.Set_Name(path);
  2677. if (!file.Is_Available())
  2678. {
  2679. #if(1)
  2680. VisiblePage.Clear();
  2681. GamePalette.Set();
  2682. Show_Mouse();
  2683. sprintf(path, "Couldn't find %s\n", filename);
  2684. WWMessageBox().Process(path);
  2685. #endif
  2686. return false;
  2687. }
  2688. // Stop theme music
  2689. if (Misc_Focus_Loss_Function)
  2690. Misc_Focus_Loss_Function();
  2691. // Release primary surface
  2692. VisiblePage.Un_Init();
  2693. #ifdef MCIMPEG
  2694. if (MciMovie && MpgSettings && (MpgSettings->GetDeviceName() != NULL))
  2695. {
  2696. DirectDrawObject->SetCooperativeLevel(MainWindow, DDSCL_NORMAL);
  2697. if (!MciMovie->Open(filename, MpgSettings->GetDeviceName()))
  2698. {
  2699. WWMessageBox().Process("Couldn't open movie.\n");
  2700. }
  2701. else if (!MciMovie->Play(MainWindow))
  2702. {
  2703. WWMessageBox().Process("Couldn't play movie.\n");
  2704. }
  2705. DirectDrawObject->SetCooperativeLevel(MainWindow, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
  2706. }
  2707. else
  2708. #endif
  2709. {
  2710. DDSURFACEDESC ddsd;
  2711. IDirectDrawSurface* primary = NULL;
  2712. bool modeChange = false;
  2713. RECT rect;
  2714. if (FAILED(DirectDrawObject->SetDisplayMode(ScreenWidth, ScreenHeight, 16)))
  2715. {
  2716. WWMessageBox().Process("Couldn't change display mode.\n");
  2717. }
  2718. else
  2719. {
  2720. // Create primary surface reference
  2721. memset(&ddsd, 0, sizeof(ddsd));
  2722. ddsd.dwSize = sizeof(ddsd);
  2723. ddsd.dwFlags = DDSD_CAPS;
  2724. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  2725. if (FAILED(DirectDrawObject->CreateSurface(&ddsd, &primary, NULL)))
  2726. {
  2727. WWMessageBox().Process("Couldn't create primary movie surface.\n");
  2728. }
  2729. else
  2730. {
  2731. rect.top = rect.left = 0;
  2732. rect.bottom = ScreenHeight;
  2733. rect.right = ScreenWidth;
  2734. MpgSetCallback(MpegCallback, NULL);
  2735. MpgPlay(filename, DirectDrawObject, primary, &rect);
  2736. if (primary)
  2737. primary->Release();
  2738. }
  2739. DirectDrawObject->SetDisplayMode(ScreenWidth, ScreenHeight, 8);
  2740. }
  2741. }
  2742. // Restore surfaces
  2743. VisiblePage.Init(ScreenWidth, ScreenHeight, NULL, 0, (GBC_Enum)(GBC_VISIBLE|GBC_VIDEOMEM));
  2744. PaletteSurface->SetPalette(PalettePtr);
  2745. AllSurfaces.Set_Surface_Focus(true);
  2746. AllSurfaces.Restore_Surfaces();
  2747. return true;
  2748. }
  2749. MPG_RESPONSE far __stdcall MpegCallback(MPG_CMD cmd, LPVOID data, LPVOID user)
  2750. {
  2751. static IDirectDrawPalette* _palette = NULL;
  2752. user = user;
  2753. switch (cmd)
  2754. {
  2755. case MPGCMD_ERROR:
  2756. WWMessageBox().Process((char const *)data);
  2757. break;
  2758. case MPGCMD_INIT:
  2759. VisiblePage.Clear();
  2760. break;
  2761. case MPGCMD_CLEANUP:
  2762. VisiblePage.Clear();
  2763. if (_palette != NULL)
  2764. {
  2765. PaletteSurface->SetPalette(_palette);
  2766. _palette->Release();
  2767. _palette = NULL;
  2768. }
  2769. break;
  2770. case MPGCMD_PALETTE:
  2771. if (FAILED(PaletteSurface->GetPalette(&_palette)))
  2772. {
  2773. WWMessageBox().Process("Couldn't get primary palette.\n");
  2774. }
  2775. else
  2776. {
  2777. if (FAILED(PaletteSurface->SetPalette((IDirectDrawPalette*)data)))
  2778. {
  2779. WWMessageBox().Process("Couldn't set movie palette.\n");
  2780. }
  2781. }
  2782. break;
  2783. case MPGCMD_UPDATE:
  2784. if ((BreakoutAllowed || Debug_Flag) && Keyboard->Check())
  2785. {
  2786. if (Keyboard->Get() == KN_ESC)
  2787. {
  2788. Keyboard->Clear();
  2789. return MPGRES_QUIT;
  2790. }
  2791. Keyboard->Clear();
  2792. }
  2793. if (!GameInFocus)
  2794. {
  2795. MpgPause();
  2796. while (!GameInFocus)
  2797. {
  2798. Check_For_Focus_Loss();
  2799. }
  2800. MpgResume();
  2801. return MPGRES_LOSTFOCUS;
  2802. }
  2803. break;
  2804. default:
  2805. break;
  2806. }
  2807. return MPGRES_CONTINUE;
  2808. }
  2809. #endif
  2810. /***********************************************************************************************
  2811. * Unselect_All -- Causes all selected objects to become unselected. *
  2812. * *
  2813. * This routine will unselect all objects that are currently selected. *
  2814. * *
  2815. * INPUT: none *
  2816. * *
  2817. * OUTPUT: none *
  2818. * *
  2819. * WARNINGS: none *
  2820. * *
  2821. * HISTORY: *
  2822. * 01/19/1995 JLB : Created. *
  2823. *=============================================================================================*/
  2824. void Unselect_All(void)
  2825. {
  2826. //while (CurrentObject.Count()) {
  2827. // CurrentObject[0]->Unselect();
  2828. //}
  2829. //Added some error handling incase there was an issue removing the object - JAS 6/28/2019
  2830. while (CurrentObject.Count()) {
  2831. int count_before = CurrentObject.Count();
  2832. CurrentObject[0]->Unselect();
  2833. if (count_before <= CurrentObject.Count()) {
  2834. GlyphX_Debug_Print("Unselect_All failed to remove an object");
  2835. CurrentObject.Delete(CurrentObject[0]);
  2836. }
  2837. }
  2838. //End of change - JAS 6/28/2019
  2839. }
  2840. void Unselect_All_Except(ObjectClass* object)
  2841. {
  2842. int index = 0;
  2843. while (index < CurrentObject.Count()) {
  2844. if (CurrentObject[index] == object) {
  2845. index++;
  2846. continue;
  2847. }
  2848. int count_before = CurrentObject.Count();
  2849. CurrentObject[index]->Unselect();
  2850. if (count_before <= CurrentObject.Count()) {
  2851. GlyphX_Debug_Print("Unselect_All failed to remove an object");
  2852. CurrentObject.Delete(CurrentObject[index]);
  2853. }
  2854. }
  2855. }
  2856. /***********************************************************************************************
  2857. * Fading_Table_Name -- Builds a theater specific fading table name. *
  2858. * *
  2859. * This routine builds a standard fading table name. This name is dependant on the theater *
  2860. * being played, since each theater has its own palette. *
  2861. * *
  2862. * INPUT: base -- The base name of this fading table. The base name can be no longer than *
  2863. * seven characters. *
  2864. * *
  2865. * theater -- The theater that this fading table is specific to. *
  2866. * *
  2867. * OUTPUT: Returns with a pointer to the constructed fading table filename. This pointer is *
  2868. * valid until this function is called again. *
  2869. * *
  2870. * WARNINGS: none *
  2871. * *
  2872. * HISTORY: *
  2873. * 01/19/1995 JLB : Created. *
  2874. *=============================================================================================*/
  2875. char const * Fading_Table_Name(char const * base, TheaterType theater)
  2876. {
  2877. static char _buffer[_MAX_FNAME+_MAX_EXT];
  2878. char root[_MAX_FNAME];
  2879. sprintf(root, "%1.1s%s", Theaters[theater].Root, base);
  2880. _makepath(_buffer, NULL, NULL, root, ".MRF");
  2881. return(_buffer);
  2882. }
  2883. /***********************************************************************************************
  2884. * Get_Radar_Icon -- Builds and alloc a radar icon from a shape file *
  2885. * *
  2886. * INPUT: void const * shapefile - pointer to a key framed shapefile *
  2887. * int shapenum - shape to extract from shapefile *
  2888. * *
  2889. * OUTPUT: void const * - 3/3 icon set of shape from file *
  2890. * *
  2891. * HISTORY: *
  2892. * 04/12/1995 PWG : Created. *
  2893. * 05/10/1995 JLB : Handles a null shapefile pointer. *
  2894. *=============================================================================================*/
  2895. void const * Get_Radar_Icon(void const * shapefile, int shapenum, int frames, int zoomfactor)
  2896. {
  2897. static int _offx[]={ 0, 0, -1, 1, 0, -1, 1, -1, 1};
  2898. static int _offy[]={ 0, 0, -1, 1, 0, -1, 1, -1, 1};
  2899. int lp,framelp;
  2900. char pixel;
  2901. char * retval = NULL;
  2902. char * buffer = NULL;
  2903. /*
  2904. ** If there is no shape file, then there can be no radar icon imagery.
  2905. */
  2906. if (!shapefile) return(NULL);
  2907. #if (0)
  2908. CCPalette.Set();
  2909. Set_Logic_Page(SeenBuff);
  2910. CC_Draw_Shape(shapefile, shapenum, 64, 64, WINDOW_MAIN, SHAPE_WIN_REL);
  2911. #endif
  2912. /*
  2913. ** Get the pixel width and height of the frame we built. This will
  2914. ** be used to extract icons and build pixels.
  2915. */
  2916. int pixel_width = Get_Build_Frame_Width( shapefile );
  2917. int pixel_height = Get_Build_Frame_Height( shapefile );
  2918. /*
  2919. ** Find the width and height in icons, adjust these by half an
  2920. ** icon because the artists may be sloppy and miss the edge of an
  2921. ** icon one way or the other.
  2922. */
  2923. int icon_width = (pixel_width + 12) / 24;
  2924. int icon_height = (pixel_height + 12) / 24;
  2925. /*
  2926. ** If we have been told to build as many frames as possible, then
  2927. ** find out how many frames there are to build.
  2928. */
  2929. if (frames == -1) frames = Get_Build_Frame_Count( shapefile );
  2930. /*
  2931. ** Allocate a position to store our icons. If the alloc fails then
  2932. ** we don't add these icons to the set.
  2933. **/
  2934. buffer = new char[(icon_width * icon_height * 9 * frames)+2];
  2935. if (!buffer) return(NULL);
  2936. /*
  2937. ** Save off the return value so that we can return it to the calling
  2938. ** function.
  2939. */
  2940. retval = (char *)buffer;
  2941. *buffer++ = (char)icon_width;
  2942. *buffer++ = (char)icon_height;
  2943. int val = 24/zoomfactor;
  2944. for (framelp = 0; framelp < frames; framelp ++) {
  2945. /*
  2946. ** Build the current frame. If the frame can not be built then we
  2947. ** just need to skip past this set of icons and try to build the
  2948. ** next frame.
  2949. */
  2950. #ifdef WIN32
  2951. void * ptr;
  2952. if ((ptr = (void *)(Build_Frame(shapefile, shapenum + framelp, SysMemPage.Get_Buffer()))) != NULL) {
  2953. ptr = Get_Shape_Header_Data(ptr);
  2954. #else //WIN#@
  2955. if (Build_Frame(shapefile, shapenum + framelp, HidPage.Get_Buffer()) <= (unsigned long)HidPage.Get_Size() ) {
  2956. #endif //WIN32
  2957. /*
  2958. ** Loop through the icon width and the icon height building icons
  2959. ** into the buffer pointer. When the getx or gety falls outside of
  2960. ** the width and height of the shape, just insert transparent pixels.
  2961. */
  2962. for (int icony = 0; icony < icon_height; icony ++) {
  2963. for (int iconx = 0; iconx < icon_width; iconx ++) {
  2964. #ifdef WIN32
  2965. for (int y = 0; y < zoomfactor; y++) {
  2966. for (int x = 0; x < zoomfactor; x++) {
  2967. int getx = (iconx * 24) + (x * val) + (zoomfactor / 2);
  2968. int gety = (icony * 24) + (y * val) + (zoomfactor / 2);
  2969. if ((getx < pixel_width) && (gety < pixel_height)) {
  2970. for (lp = 0; lp < 9; lp ++) {
  2971. pixel = *(char *)((char *)ptr + ((gety - _offy[lp]) * pixel_width) + getx-_offx[lp]);
  2972. #else //WIN32
  2973. for (int y = 0; y < 3; y++) {
  2974. for (int x = 0; x < 3; x++) {
  2975. int getx = (iconx * 24) + (x << 3) + 4;
  2976. int gety = (icony * 24) + (y << 3) + 4;
  2977. if ((getx < pixel_width) && (gety < pixel_height)) {
  2978. for (lp = 0; lp < 9; lp ++) {
  2979. pixel = *(char *)((char *)HidPage.Get_Buffer(), ((gety - _offy[lp]) * pixel_width) + getx-_offx[lp]);
  2980. #endif //WIN32
  2981. if (pixel == LTGREEN) pixel = 0;
  2982. if (pixel) {
  2983. break;
  2984. }
  2985. }
  2986. *buffer++ = pixel;
  2987. } else {
  2988. *buffer++ = 0;
  2989. }
  2990. }
  2991. }
  2992. }
  2993. }
  2994. } else {
  2995. buffer += icon_width * icon_height * 9;
  2996. }
  2997. }
  2998. return(retval);
  2999. }
  3000. extern void DLL_Draw_Intercept(int shape_number, int x, int y, int width, int height, int flags, const ObjectClass *object, DirType rotation, long scale, const char *shape_file_name, char override_owner);
  3001. extern void DLL_Draw_Pip_Intercept(const ObjectClass* object, int pip);
  3002. 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);
  3003. void CC_Draw_Shape(const ObjectClass *object, void const * shapefile, int shapenum, int x, int y, WindowNumberType window, ShapeFlags_Type flags, void const * fadingdata, void const * ghostdata, DirType rotation, long virtualscale, int width, int height)
  3004. {
  3005. if (window == WINDOW_VIRTUAL) {
  3006. if (width == 0) width = Get_Build_Frame_Width(shapefile);
  3007. if (height == 0) height = Get_Build_Frame_Height(shapefile);
  3008. DLL_Draw_Intercept(shapenum, x, y, width, height, (int)flags, object, rotation, virtualscale, NULL, HOUSE_NONE);
  3009. return;
  3010. }
  3011. CC_Draw_Shape(shapefile, shapenum, x, y, window, flags, fadingdata, ghostdata, rotation);
  3012. }
  3013. void CC_Draw_Shape(const ObjectClass *object, const char *shape_file_name, void const * shapefile, int shapenum, int x, int y, WindowNumberType window, ShapeFlags_Type flags, void const * fadingdata, void const * ghostdata, DirType rotation, long virtualscale, char override_owner)
  3014. {
  3015. if (window == WINDOW_VIRTUAL) {
  3016. int width = Get_Build_Frame_Width(shapefile);
  3017. int height = Get_Build_Frame_Height(shapefile);
  3018. DLL_Draw_Intercept(shapenum, x, y, width, height, (int)flags, object, rotation, virtualscale, shape_file_name, override_owner);
  3019. return;
  3020. }
  3021. CC_Draw_Shape(shapefile, shapenum, x, y, window, flags, fadingdata, ghostdata, rotation);
  3022. }
  3023. void CC_Draw_Pip(const ObjectClass *object, void const * shapefile, int shapenum, int x, int y, WindowNumberType window, ShapeFlags_Type flags, void const * fadingdata, void const * ghostdata, DirType rotation)
  3024. {
  3025. if (window == WINDOW_VIRTUAL) {
  3026. DLL_Draw_Pip_Intercept(object, shapenum);
  3027. return;
  3028. }
  3029. CC_Draw_Shape(shapefile, shapenum, x, y, window, flags, fadingdata, ghostdata, rotation);
  3030. }
  3031. /***********************************************************************************************
  3032. * CC_Draw_Shape -- Custom draw shape handler. *
  3033. * *
  3034. * All draw shape calls will route through this function. It handles all draws for *
  3035. * C&C. Such draws always occur to the logical page and assume certain things about *
  3036. * the parameters passed. *
  3037. * *
  3038. * INPUT: shapefile -- Pointer to the shape data file. This data file contains all the *
  3039. * embedded shapes. *
  3040. * *
  3041. * shapenum -- The shape number within the shapefile that will be drawn. *
  3042. * *
  3043. * x,y -- The pixel coordinates to draw the shape. *
  3044. * *
  3045. * window -- The clipping window to use. *
  3046. * *
  3047. * flags -- The custom draw shape flags. This controls how the parameters *
  3048. * are used (if any). *
  3049. * *
  3050. * fadingdata -- If SHAPE_FADING is desired, then this points to the fading *
  3051. * data table. *
  3052. * *
  3053. * ghostdata -- If SHAPE_GHOST is desired, then this points to the ghost remap *
  3054. * table. *
  3055. * *
  3056. * rotation -- Rotation to apply to the shape (DIR_N = no rotation at all). *
  3057. * *
  3058. * scale -- 24.8 fixed point scale factor. *
  3059. * *
  3060. * OUTPUT: none *
  3061. * *
  3062. * WARNINGS: none *
  3063. * *
  3064. * HISTORY: *
  3065. * 02/21/1995 JLB : Created. *
  3066. *=============================================================================================*/
  3067. 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)
  3068. {
  3069. int predoffset;
  3070. #ifdef WIN32
  3071. unsigned long shape_pointer;
  3072. #endif //WIN32
  3073. /*
  3074. ** Special kludge for E3 to prevent crashes
  3075. */
  3076. if ((flags & SHAPE_GHOST) && (!ghostdata)) {
  3077. ghostdata = DisplayClass::SpecialGhost;
  3078. }
  3079. if ((flags & SHAPE_FADING) && (!fadingdata)) {
  3080. fadingdata = DisplayClass::FadingShade;
  3081. }
  3082. static unsigned char * _xbuffer = 0;
  3083. if (!_xbuffer) {
  3084. _xbuffer = new unsigned char[SHAPE_BUFFER_SIZE];
  3085. }
  3086. if (shapefile != NULL && shapenum != -1) {
  3087. int width = Get_Build_Frame_Width(shapefile);
  3088. int height = Get_Build_Frame_Height(shapefile);
  3089. #ifdef NEVER
  3090. /*
  3091. ** Perform a quick clip check against the destination rectangle.
  3092. */
  3093. if (flags & SHAPE_CENTER) {
  3094. if (x-width/2 >= WindowList[window][WINDOWWIDTH]) return;
  3095. if (y-width/2 >= WindowList[window][WINDOWHEIGHT]) return;
  3096. if (x+width/2 < 0) return;
  3097. if (y+height/2 < 0) return;
  3098. } else {
  3099. if (x >= WindowList[window][WINDOWWIDTH]) return;
  3100. if (y >= WindowList[window][WINDOWHEIGHT]) return;
  3101. if (x+width < 0) return;
  3102. if (y+height < 0) return;
  3103. }
  3104. #endif
  3105. #ifdef WIN32
  3106. /*
  3107. ** In WIn95, build shape returns a pointer to the shape not its size
  3108. */
  3109. shape_pointer = Build_Frame(shapefile, shapenum, _ShapeBuffer);
  3110. if (shape_pointer) {
  3111. GraphicViewPortClass draw_window(LogicPage->Get_Graphic_Buffer(),
  3112. WindowList[window][WINDOWX] + LogicPage->Get_XPos(),
  3113. WindowList[window][WINDOWY] + LogicPage->Get_YPos(),
  3114. WindowList[window][WINDOWWIDTH],
  3115. WindowList[window][WINDOWHEIGHT]);
  3116. unsigned char * buffer = (unsigned char *) shape_pointer; //Get_Shape_Header_Data((void*)shape_pointer);
  3117. #else //WIN32
  3118. if ( Build_Frame(shapefile, shapenum, _ShapeBuffer ) <= (unsigned long)_ShapeBufferSize) {
  3119. GraphicViewPortClass draw_window(LogicPage,
  3120. WindowList[window][WINDOWX],
  3121. WindowList[window][WINDOWY],
  3122. WindowList[window][WINDOWWIDTH],
  3123. WindowList[window][WINDOWHEIGHT]);
  3124. unsigned char * buffer = (unsigned char *)_ShapeBuffer;
  3125. #endif //WIN32
  3126. UseOldShapeDraw = false;
  3127. /*
  3128. ** Rotation handler.
  3129. */
  3130. if (rotation != DIR_N) {
  3131. /*
  3132. ** Get the raw shape data without the new header and flag to use the old shape drawing
  3133. */
  3134. UseOldShapeDraw = true;
  3135. #ifdef WIN32
  3136. buffer = (unsigned char *) Get_Shape_Header_Data((void*)shape_pointer);
  3137. #endif
  3138. if (Debug_Rotate) {
  3139. #if (0)//PG
  3140. GraphicBufferClass src(width, height, buffer);
  3141. width *= 2;
  3142. height *= 2;
  3143. memset(_xbuffer, '\0', SHAPE_BUFFER_SIZE);
  3144. GraphicBufferClass dst(width, height, _xbuffer);
  3145. Rotate_Bitmap(&src, &dst, rotation);
  3146. buffer = _xbuffer;
  3147. #endif
  3148. } else {
  3149. BitmapClass bm(width, height, buffer);
  3150. width *= 2;
  3151. height *= 2;
  3152. memset(_xbuffer, '\0', SHAPE_BUFFER_SIZE);
  3153. GraphicBufferClass gb(width, height, _xbuffer);
  3154. TPoint2D pt(width/2, height/2);
  3155. gb.Scale_Rotate(bm, pt, 0x0100, (256-(rotation-64)));
  3156. buffer = _xbuffer;
  3157. }
  3158. }
  3159. /*
  3160. ** Special shadow drawing code (used for aircraft and bullets).
  3161. */
  3162. if ((flags & (SHAPE_FADING|SHAPE_PREDATOR)) == (SHAPE_FADING|SHAPE_PREDATOR)) {
  3163. flags = flags & ~(SHAPE_FADING|SHAPE_PREDATOR);
  3164. flags = flags | SHAPE_GHOST;
  3165. ghostdata = DisplayClass::SpecialGhost;
  3166. }
  3167. predoffset = Frame;
  3168. if (x > ( WindowList[window][WINDOWWIDTH] << 2)) {
  3169. predoffset = -predoffset;
  3170. }
  3171. if (draw_window.Lock()) {
  3172. if ((flags & (SHAPE_GHOST|SHAPE_FADING)) == (SHAPE_GHOST|SHAPE_FADING)) {
  3173. Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, ghostdata, fadingdata, 1, predoffset);
  3174. } else {
  3175. if (flags & SHAPE_FADING) {
  3176. Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, fadingdata, 1, predoffset);
  3177. } else {
  3178. if (flags & SHAPE_PREDATOR) {
  3179. Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, predoffset);
  3180. } else {
  3181. Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, ghostdata, predoffset);
  3182. }
  3183. }
  3184. }
  3185. draw_window.Unlock();
  3186. }
  3187. }
  3188. }
  3189. }
  3190. /***********************************************************************************************
  3191. * Shape_Dimensions -- Determine the minimum rectangle for the shape. *
  3192. * *
  3193. * This routine will calculate (using brute forced) the minimum rectangle that will *
  3194. * enclose the pixels of the shape. This rectangle will be relative to the upper left *
  3195. * corner of the maximum shape size. By using this minimum rectangle, it is possible to *
  3196. * greatly optimize the map 'dirty rectangle' logic. *
  3197. * *
  3198. * INPUT: shapedata -- Pointer to the shape data block. *
  3199. * *
  3200. * shapenum -- The shape number to examine. Each shape would have a different *
  3201. * dimension rectangle. *
  3202. * *
  3203. * OUTPUT: Returns with the rectangle that encloses the shape. *
  3204. * *
  3205. * WARNINGS: This routine uses brute force and is slow. It is presumed that the results *
  3206. * will be cached for subsiquent reuse. *
  3207. * *
  3208. * HISTORY: *
  3209. * 07/22/1996 JLB : Created. *
  3210. *=============================================================================================*/
  3211. Rect const Shape_Dimensions(void const * shapedata, int shapenum)
  3212. {
  3213. Rect rect;
  3214. if (shapedata == NULL || shapenum < 0 || shapenum > Get_Build_Frame_Count(shapedata)) {
  3215. return(rect);
  3216. }
  3217. char * shape;
  3218. #ifdef WIN32
  3219. void * sh = (void *)Build_Frame(shapedata, shapenum, _ShapeBuffer);
  3220. if (sh == NULL) return(rect);
  3221. // shape = (char *)sh;
  3222. shape = (char *)Get_Shape_Header_Data(sh);
  3223. #else
  3224. Build_Frame(shapedata, shapenum, _ShapeBuffer);
  3225. shape = (char *)_ShapeBuffer;
  3226. #endif
  3227. int width = Get_Build_Frame_Width(shapedata);
  3228. int height = Get_Build_Frame_Height(shapedata);
  3229. rect.X = 0;
  3230. rect.Y = 0;
  3231. int xlimit = width-1;
  3232. int ylimit = height-1;
  3233. /*
  3234. ** Find top edge of the shape.
  3235. */
  3236. for (int y = 0; y <= ylimit; y++) {
  3237. for (int x = 0; x <= xlimit; x++) {
  3238. if (shape[y*width + x] != 0) {
  3239. rect.Y = y;
  3240. rect.X = x;
  3241. y = ylimit+1;
  3242. break;
  3243. }
  3244. }
  3245. }
  3246. /*
  3247. ** Find bottom edge of the shape.
  3248. */
  3249. for (int y = ylimit; y >= rect.Y; y--) {
  3250. for (int x = xlimit; x >= 0; x--) {
  3251. if (shape[y*width + x] != 0) {
  3252. rect.Height = (y-rect.Y)+1;
  3253. xlimit = x;
  3254. y = rect.Y-1;
  3255. break;
  3256. }
  3257. }
  3258. }
  3259. /*
  3260. ** Find left edge of the shape.
  3261. */
  3262. for (int x = 0; x < rect.X; x++) {
  3263. for (int y = rect.Y; y < rect.Y+rect.Height; y++) {
  3264. if (shape[y*width + x] != 0) {
  3265. rect.X = x;
  3266. x = rect.X;
  3267. break;
  3268. }
  3269. }
  3270. }
  3271. /*
  3272. ** Find the right edge of the shape.
  3273. */
  3274. for (int x = width-1; x >= xlimit; x--) {
  3275. for (int y = rect.Y; y < rect.Y+rect.Height; y++) {
  3276. if (shape[y*width + x] != 0) {
  3277. rect.Width = (x-rect.X)+1;
  3278. x = xlimit-1;
  3279. break;
  3280. }
  3281. }
  3282. }
  3283. /*
  3284. ** Normalize the rectangle around the center of the shape.
  3285. */
  3286. rect.X -= width / 2;
  3287. rect.Y -= height / 2;
  3288. /*
  3289. ** Return with the minimum rectangle that encloses the shape.
  3290. */
  3291. return(rect);
  3292. }
  3293. /***********************************************************************************************
  3294. * Fetch_Techno_Type -- Convert type and ID into TechnoTypeClass pointer. *
  3295. * *
  3296. * This routine will convert the supplied RTTI type number and the ID value into a valid *
  3297. * TechnoTypeClass pointer. If there is an error in conversion, then NULL is returned. *
  3298. * *
  3299. * INPUT: type -- RTTI type of the techno class object. *
  3300. * *
  3301. * id -- Integer representation of the techno sub type number. *
  3302. * *
  3303. * OUTPUT: Returns with a pointer to the techno type class object specified or NULL if the *
  3304. * conversion could not occur. *
  3305. * *
  3306. * WARNINGS: none *
  3307. * *
  3308. * HISTORY: *
  3309. * 05/08/1995 JLB : Created. *
  3310. *=============================================================================================*/
  3311. TechnoTypeClass const * Fetch_Techno_Type(RTTIType type, int id)
  3312. {
  3313. switch (type) {
  3314. case RTTI_UNITTYPE:
  3315. case RTTI_UNIT:
  3316. return(&UnitTypeClass::As_Reference(UnitType(id)));
  3317. case RTTI_VESSELTYPE:
  3318. case RTTI_VESSEL:
  3319. return(&VesselTypeClass::As_Reference(VesselType(id)));
  3320. case RTTI_BUILDINGTYPE:
  3321. case RTTI_BUILDING:
  3322. return(&BuildingTypeClass::As_Reference(StructType(id)));
  3323. case RTTI_INFANTRYTYPE:
  3324. case RTTI_INFANTRY:
  3325. return(&InfantryTypeClass::As_Reference(InfantryType(id)));
  3326. case RTTI_AIRCRAFTTYPE:
  3327. case RTTI_AIRCRAFT:
  3328. return(&AircraftTypeClass::As_Reference(AircraftType(id)));
  3329. default:
  3330. break;
  3331. }
  3332. return(NULL);
  3333. }
  3334. /***********************************************************************************************
  3335. * VQ_Call_Back -- Maintenance callback used for VQ movies. *
  3336. * *
  3337. * This routine is called every frame of the VQ movie as it is being played. If this *
  3338. * routine returns non-zero, then the movie will stop. *
  3339. * *
  3340. * INPUT: buffer -- Pointer to the image buffer for the current frame. *
  3341. * *
  3342. * frame -- The frame number about to be displayed. *
  3343. * *
  3344. * OUTPUT: Should the movie be stopped? *
  3345. * *
  3346. * WARNINGS: none *
  3347. * *
  3348. * HISTORY: *
  3349. * 06/24/1995 JLB : Created. *
  3350. *=============================================================================================*/
  3351. #ifdef WIN32
  3352. void VQA_PauseAudio(void) {};
  3353. void Check_VQ_Palette_Set(void);
  3354. extern GraphicBufferClass VQ640;
  3355. extern bool IsVQ640;
  3356. long VQ_Call_Back(unsigned char *, long )
  3357. {
  3358. return 0;
  3359. #if (0)//PG
  3360. int key = 0;
  3361. if (Keyboard->Check()) {
  3362. key = Keyboard->Get();
  3363. Keyboard->Clear();
  3364. }
  3365. Check_VQ_Palette_Set();
  3366. #ifdef MOVIE640
  3367. if(IsVQ640) {
  3368. VQ640.Blit(SeenBuff);
  3369. } else {
  3370. Interpolate_2X_Scale(&SysMemPage, &SeenBuff, NULL);
  3371. }
  3372. #else
  3373. Interpolate_2X_Scale(&SysMemPage, &SeenBuff, NULL);
  3374. #endif
  3375. //Call_Back();
  3376. if ((BreakoutAllowed || Debug_Flag) && key == KN_ESC) {
  3377. Keyboard->Clear();
  3378. Brokeout = true;
  3379. return(true);
  3380. }
  3381. if (!GameInFocus) {
  3382. VQA_PauseAudio();
  3383. while (!GameInFocus) {
  3384. Check_For_Focus_Loss();
  3385. }
  3386. }
  3387. return(false);
  3388. #endif
  3389. }
  3390. #else //WIN32
  3391. long VQ_Call_Back(unsigned char *, long )
  3392. {
  3393. Call_Back();
  3394. if ((BreakoutAllowed || Debug_Flag) && Keyboard->Check()) {
  3395. if (Keyboard->Get() == KN_ESC) {
  3396. Keyboard->Clear();
  3397. Brokeout = true;
  3398. return(true);
  3399. }
  3400. Keyboard->Clear();
  3401. }
  3402. return(false);
  3403. }
  3404. #endif //WIN32
  3405. /***********************************************************************************************
  3406. * Handle_Team -- Processes team selection command. *
  3407. * *
  3408. * This routine will handle creation and selection of pseudo teams that the player can *
  3409. * create or control. A team in this sense is an arbitrary grouping of units such that *
  3410. * rapid selection control is allowed. *
  3411. * *
  3412. * INPUT: team -- The logical team number to process. *
  3413. * *
  3414. * action-- The action to perform on this team: *
  3415. * 0 - Toggle the select state for all members of this team. *
  3416. * 1 - Select the members of this team. *
  3417. * 2 - Make all selected objects members of this team. *
  3418. * *
  3419. * OUTPUT: none *
  3420. * *
  3421. * WARNINGS: none *
  3422. * *
  3423. * HISTORY: *
  3424. * 06/27/1995 JLB : Created. *
  3425. *=============================================================================================*/
  3426. void Handle_Team(int team, int action)
  3427. {
  3428. int index;
  3429. //
  3430. // Recording support
  3431. //
  3432. if (Session.Record) {
  3433. TeamNumber = (char)team;
  3434. TeamEvent = (char)action + 1;
  3435. }
  3436. TeamFormDataStruct& team_form_data = TeamFormData[PlayerPtr->Class->House];
  3437. AllowVoice = true;
  3438. switch (action) {
  3439. /*
  3440. ** Toggle the team selection. If the team is selected, then merely unselect it. If the
  3441. ** team is not selected, then unselect all others before selecting this team.
  3442. */
  3443. case 3:
  3444. case 0:
  3445. /*
  3446. ** If a non team member is currently selected, then deselect all objects
  3447. ** before selecting this team.
  3448. */
  3449. for (index = 0; index < CurrentObject.Count(); index++) {
  3450. ObjectClass * obj = CurrentObject[index];
  3451. if (obj->Is_Foot() && ((FootClass *)obj)->Group != team) {
  3452. Unselect_All();
  3453. break;
  3454. }
  3455. }
  3456. for (index = 0; index < Vessels.Count(); index++) {
  3457. VesselClass * obj = Vessels.Ptr(index);
  3458. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  3459. if (!obj->Is_Selected_By_Player()) {
  3460. obj->Select();
  3461. AllowVoice = false;
  3462. }
  3463. }
  3464. }
  3465. for (index = 0; index < Units.Count(); index++) {
  3466. UnitClass * obj = Units.Ptr(index);
  3467. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  3468. if (!obj->Is_Selected_By_Player()) {
  3469. obj->Select();
  3470. AllowVoice = false;
  3471. }
  3472. }
  3473. }
  3474. for (index = 0; index < Infantry.Count(); index++) {
  3475. InfantryClass * obj = Infantry.Ptr(index);
  3476. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  3477. if (!obj->Is_Selected_By_Player()) {
  3478. obj->Select();
  3479. AllowVoice = false;
  3480. }
  3481. }
  3482. }
  3483. for (index = 0; index < Aircraft.Count(); index++) {
  3484. AircraftClass * obj = Aircraft.Ptr(index);
  3485. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  3486. if (!obj->Is_Selected_By_Player()) {
  3487. obj->Select();
  3488. AllowVoice = false;
  3489. }
  3490. }
  3491. }
  3492. /*
  3493. ** Center the map around the team if the ALT key was pressed too.
  3494. */
  3495. if (action == 3) {
  3496. Map.Center_Map();
  3497. #ifdef WIN32
  3498. Map.Flag_To_Redraw(true);
  3499. #endif //WIn32
  3500. }
  3501. break;
  3502. /*
  3503. ** Additive selection of team.
  3504. */
  3505. case 1:
  3506. for (index = 0; index < Units.Count(); index++) {
  3507. UnitClass * obj = Units.Ptr(index);
  3508. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  3509. if (!obj->Is_Selected_By_Player()) {
  3510. obj->Select();
  3511. AllowVoice = false;
  3512. }
  3513. }
  3514. }
  3515. for (index = 0; index < Vessels.Count(); index++) {
  3516. VesselClass * obj = Vessels.Ptr(index);
  3517. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  3518. if (!obj->Is_Selected_By_Player()) {
  3519. obj->Select();
  3520. AllowVoice = false;
  3521. }
  3522. }
  3523. }
  3524. for (index = 0; index < Infantry.Count(); index++) {
  3525. InfantryClass * obj = Infantry.Ptr(index);
  3526. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  3527. if (!obj->Is_Selected_By_Player()) {
  3528. obj->Select();
  3529. AllowVoice = false;
  3530. }
  3531. }
  3532. }
  3533. for (index = 0; index < Aircraft.Count(); index++) {
  3534. AircraftClass * obj = Aircraft.Ptr(index);
  3535. if (obj && !obj->IsInLimbo && obj->Group == team && obj->House->IsPlayerControl) {
  3536. if (!obj->Is_Selected_By_Player()) {
  3537. obj->Select();
  3538. AllowVoice = false;
  3539. }
  3540. }
  3541. }
  3542. break;
  3543. /*
  3544. ** Create the team.
  3545. */
  3546. case 2: {
  3547. long minx = 0x7FFFFFFFL, miny = 0x7FFFFFFFL;
  3548. long maxx = 0, maxy = 0;
  3549. team_form_data.TeamSpeed[team] = SPEED_WHEEL;
  3550. team_form_data.TeamMaxSpeed[team] = MPH_LIGHT_SPEED;
  3551. for (index = 0; index < Units.Count(); index++) {
  3552. UnitClass * obj = Units.Ptr(index);
  3553. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  3554. if (obj->Group == team) obj->Group = 0xFF;
  3555. if (obj->Is_Selected_By_Player()) {
  3556. obj->Group = team;
  3557. obj->Mark(MARK_CHANGE);
  3558. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  3559. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  3560. if (xc < minx) minx = xc;
  3561. if (xc > maxx) maxx = xc;
  3562. if (yc < miny) miny = yc;
  3563. if (yc > maxy) maxy = yc;
  3564. if (obj->Class->MaxSpeed < team_form_data.TeamMaxSpeed[team]) {
  3565. team_form_data.TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  3566. team_form_data.TeamSpeed[team] = obj->Class->Speed;
  3567. }
  3568. }
  3569. }
  3570. }
  3571. for (index = 0; index < Vessels.Count(); index++) {
  3572. VesselClass * obj = Vessels.Ptr(index);
  3573. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  3574. if (obj->Group == team) obj->Group = -1;
  3575. if (obj->Is_Selected_By_Player()) {
  3576. obj->Group = team;
  3577. obj->Mark(MARK_CHANGE);
  3578. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  3579. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  3580. if (xc < minx) minx = xc;
  3581. if (xc > maxx) maxx = xc;
  3582. if (yc < miny) miny = yc;
  3583. if (yc > maxy) maxy = yc;
  3584. if (obj->Class->MaxSpeed < team_form_data.TeamMaxSpeed[team]) {
  3585. team_form_data.TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  3586. team_form_data.TeamSpeed[team] = obj->Class->Speed;
  3587. }
  3588. }
  3589. }
  3590. }
  3591. for (index = 0; index < Infantry.Count(); index++) {
  3592. InfantryClass * obj = Infantry.Ptr(index);
  3593. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  3594. if (obj->Group == team) obj->Group = 0xFF;
  3595. if (obj->Is_Selected_By_Player()) {
  3596. obj->Group = team;
  3597. obj->Mark(MARK_CHANGE);
  3598. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  3599. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  3600. if (xc < minx) minx = xc;
  3601. if (xc > maxx) maxx = xc;
  3602. if (yc < miny) miny = yc;
  3603. if (yc > maxy) maxy = yc;
  3604. if (obj->Class->MaxSpeed < team_form_data.TeamMaxSpeed[team]) {
  3605. team_form_data.TeamMaxSpeed[team] = obj->Class->MaxSpeed;
  3606. }
  3607. }
  3608. }
  3609. }
  3610. for (index = 0; index < Aircraft.Count(); index++) {
  3611. AircraftClass * obj = Aircraft.Ptr(index);
  3612. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  3613. if (obj->Group == team) obj->Group = 0xFF;
  3614. if (obj->Is_Selected_By_Player()) {
  3615. obj->Group = team;
  3616. obj->Mark(MARK_CHANGE);
  3617. }
  3618. }
  3619. }
  3620. for (index = 0; index < Units.Count(); index++) {
  3621. UnitClass * obj = Units.Ptr(index);
  3622. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl &&
  3623. (obj->Group == team) && (obj->Is_Selected_By_Player()) ) {
  3624. /*
  3625. ** When a team is first created, they're created without a
  3626. ** formation offset, so they will not be created in
  3627. ** formation. Later, if they're assigned a formation, the
  3628. ** XFormOffset & YFormOffset numbers will change to valid
  3629. ** offsets, and they'll be formationed.
  3630. */
  3631. #if(1)
  3632. obj->XFormOffset = obj->YFormOffset = (int)0x80000000;
  3633. #else
  3634. #if(1)
  3635. // Old always-north formation stuff
  3636. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  3637. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  3638. obj->XFormOffset = xc - centerx;
  3639. obj->YFormOffset = yc - centery;
  3640. #else
  3641. // New method: save direction and distance rather than x & y offset
  3642. obj->XFormOffset = ::Direction(As_Coord(center), obj->Center_Coord());
  3643. obj->YFormOffset = ::Distance (As_Coord(center), obj->Center_Coord());
  3644. #endif
  3645. #endif
  3646. }
  3647. }
  3648. for (index = 0; index < Infantry.Count(); index++) {
  3649. InfantryClass * obj = Infantry.Ptr(index);
  3650. if (obj && !obj->IsInLimbo && obj->House->IsPlayerControl) {
  3651. if (obj->Group == team) obj->Group = 0xFF;
  3652. if (obj->Is_Selected_By_Player()) obj->Group = team;
  3653. if (obj->Group == team && obj->Is_Selected_By_Player()) {
  3654. #if(1)
  3655. obj->XFormOffset = obj->YFormOffset = (int)0x80000000;
  3656. #else
  3657. #if(1)
  3658. // Old always-north formation stuff
  3659. long xc = Cell_X(Coord_Cell(obj->Center_Coord()));
  3660. long yc = Cell_Y(Coord_Cell(obj->Center_Coord()));
  3661. obj->XFormOffset = xc - centerx;
  3662. obj->YFormOffset = yc - centery;
  3663. #else
  3664. // New method: save direction and distance rather than x & y offset
  3665. obj->XFormOffset = ::Direction(As_Coord(center), obj->Center_Coord());
  3666. obj->YFormOffset = ::Distance (As_Coord(center), obj->Center_Coord());
  3667. #endif
  3668. #endif
  3669. }
  3670. }
  3671. }
  3672. break;
  3673. }
  3674. default:
  3675. break;
  3676. }
  3677. AllowVoice = true;
  3678. }
  3679. /***********************************************************************************************
  3680. * Handle_View -- Either records or restores the tactical view. *
  3681. * *
  3682. * This routine is used to record or restore the current map tactical view. *
  3683. * *
  3684. * INPUT: view -- The view number to work with. *
  3685. * *
  3686. * action-- The action to perform with this view number. *
  3687. * 0 = Restore the view to this previously remembered location. *
  3688. * 1 = Record the current view location. *
  3689. * *
  3690. * OUTPUT: none *
  3691. * *
  3692. * WARNINGS: none *
  3693. * *
  3694. * HISTORY: *
  3695. * 07/04/1995 JLB : Created. *
  3696. *=============================================================================================*/
  3697. void Handle_View(int view, int action)
  3698. {
  3699. if ((unsigned)view < ARRAY_SIZE(Scen.Views)) {
  3700. if (action == 0) {
  3701. Map.Set_Tactical_Position(Coord_Whole(Cell_Coord(Scen.Views[view] - (MAP_CELL_W * 4 * RESFACTOR) - (5*RESFACTOR))));
  3702. #ifdef WIN32
  3703. /*
  3704. ** Win95 scrolling logic cant handle just jumps in screen position so redraw the lot.
  3705. */
  3706. Map.Flag_To_Redraw (true);
  3707. #endif //WIN32
  3708. } else {
  3709. Scen.Views[view] = Coord_Cell(Map.TacticalCoord) + (MAP_CELL_W*4*RESFACTOR) + (5*RESFACTOR);
  3710. }
  3711. }
  3712. }
  3713. #ifndef ROR_NOT_READY
  3714. #define ROR_NOT_READY 21
  3715. #endif
  3716. static char * _CD_Volume_Label[] = {
  3717. "CD1",
  3718. "CD2",
  3719. "CD3",
  3720. "CD4",
  3721. // Denzil 4/15/98
  3722. #ifdef DVD
  3723. "CD1", // ajw - Pushes RADVD to position 5, to match enum in Force_CD_Available(). 4 will never be returned here.
  3724. "RADVD",
  3725. #endif
  3726. };
  3727. static int _Num_Volumes = ARRAY_SIZE(_CD_Volume_Label);
  3728. #ifdef WIN32
  3729. /***********************************************************************************************
  3730. * Get_CD_Index -- returns the volume type of the CD in the given drive *
  3731. * *
  3732. * *
  3733. * *
  3734. * INPUT: drive number *
  3735. * timeout *
  3736. * *
  3737. * OUTPUT: 0 = gdi *
  3738. * 1 = nod *
  3739. * 2 = covert or CS *
  3740. * 3 = Aftermath
  3741. * 5 = DVD
  3742. * -1 = non C&C *
  3743. * *
  3744. * WARNINGS: None *
  3745. * *
  3746. * HISTORY: *
  3747. * 5/21/96 5:27PM ST : Created *
  3748. * 01/20/97 V.Grippi added CS support *
  3749. *=============================================================================================*/
  3750. int Get_CD_Index (int cd_drive, int timeout)
  3751. {
  3752. char volume_name[128];
  3753. char buffer[128];
  3754. unsigned filename_length;
  3755. unsigned misc_dword;
  3756. int count = 0;
  3757. CountDownTimerClass timer;
  3758. timer.Set(timeout);
  3759. /*
  3760. ** Get the volume label. If we get a 'not ready' error then retry for the timeout
  3761. ** period.
  3762. */
  3763. for (;;)
  3764. {
  3765. sprintf(buffer, "%c:\\", 'A' + cd_drive);
  3766. if (GetVolumeInformation ((char const *)buffer, &volume_name[0] ,
  3767. (unsigned long)sizeof(volume_name), (unsigned long *)NULL ,
  3768. (unsigned long *)&filename_length, (unsigned long *)&misc_dword,
  3769. (char *)NULL, (unsigned long)0))
  3770. {
  3771. /*
  3772. ** Try opening 'movies.mix' to verify that the CD is really there and is what
  3773. ** it says it is.
  3774. */
  3775. sprintf(buffer, "%c:\\main.mix", 'A' + cd_drive);
  3776. HANDLE handle = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  3777. if (handle != INVALID_HANDLE_VALUE)
  3778. {
  3779. CloseHandle(handle);
  3780. /*
  3781. ** Match the volume label to the list of known C&C volume labels.
  3782. */
  3783. for (int i = 0 ; i < _Num_Volumes; i++)
  3784. {
  3785. if (!stricmp(_CD_Volume_Label[i], volume_name))
  3786. return(i);
  3787. }
  3788. }
  3789. else
  3790. {
  3791. if (!count)
  3792. count++;
  3793. else
  3794. return -1;
  3795. }
  3796. }
  3797. else
  3798. {
  3799. /*
  3800. ** Failed to get the volume label on a known CD drive.
  3801. ** If this is a CD changer it may require time to swap the disks so dont return
  3802. ** immediately if the error is ROR_NOT_READY
  3803. */
  3804. if (!timer.Time())
  3805. return -1;
  3806. int val = GetLastError();
  3807. if (val != ROR_NOT_READY)
  3808. return -1;
  3809. }
  3810. }
  3811. }
  3812. #else
  3813. int Get_CD_Index(int cd_drive, int)
  3814. {
  3815. char buffer[128];
  3816. /*
  3817. ** We need to do this twice because of the possibilities of a directory
  3818. ** being cached. If this is so, it will only be discovered when we
  3819. ** actually attempt to read a file from the drive.
  3820. */
  3821. if(cd_drive) for (int count = 0; count < 2; count ++)
  3822. {
  3823. struct find_t ft;
  3824. int file;
  3825. int open_failed;
  3826. /*
  3827. ** Create a path for the cd drive and attempt to read the volume label from
  3828. ** it.
  3829. */
  3830. sprintf(buffer, "%c:\\", 'A' + cd_drive);
  3831. /*
  3832. ** If we are able to read the volume label, this is good but not enough.
  3833. ** Further verification must be done.
  3834. */
  3835. if (!_dos_findfirst(buffer, _A_VOLID, &ft))
  3836. {
  3837. /*
  3838. ** Since some versions of disk cacheing software will cache the CD's
  3839. ** directory tracks, we may think the CD is in the drive when it is
  3840. ** actually not. To resolve this we must attempt to open a file on
  3841. ** the cd. Opening a file will always update the directory tracks
  3842. ** (suposedly).
  3843. */
  3844. sprintf(buffer, "%c:\\main.mix", 'A' + cd_drive);
  3845. open_failed = _dos_open(buffer, O_RDONLY|SH_DENYNO, &file);
  3846. if (!open_failed)
  3847. {
  3848. _dos_close(file);
  3849. /*
  3850. ** Hey some times the stupid dos driver appends a period to the
  3851. ** name if it is eight characters long. If the last char is a
  3852. ** period then erase it.
  3853. */
  3854. if (ft.name[strlen(ft.name)-1] == '.')
  3855. {
  3856. ft.name[strlen(ft.name)-1] = 0;
  3857. }
  3858. /*
  3859. ** Match the volume label to the list of known C&C volume labels.
  3860. */
  3861. for (int i = 0 ; i < _Num_Volumes; i++)
  3862. {
  3863. if (!stricmp(_CD_Volume_Label[i], ft.name))
  3864. return (i);
  3865. }
  3866. }
  3867. }
  3868. }
  3869. return -1;
  3870. }
  3871. #endif
  3872. /***********************************************************************************************
  3873. * Force_CD_Available -- Ensures that specified CD is available. *
  3874. * *
  3875. * Call this routine when you need to ensure that the specified CD is actually in the *
  3876. * CD-ROM drive. *
  3877. * *
  3878. * INPUT: cd -- The CD that must be available. This will either be "0" for the GDI CD, or *
  3879. * "1" for the Nod CD. If either CD will qualify, then pass in "-1". *
  3880. * 0 = CD1
  3881. * 1 = CD2
  3882. * 2 = Counterstrike
  3883. * 3 = Aftermath
  3884. * 4 = Counterstrike or Aftermath
  3885. * 5 = DVD
  3886. * -1 = Any CD
  3887. * -2 = Local Harddisk
  3888. * *
  3889. * OUTPUT: Is the CD inserted and available? If false is returned, then this indicates that *
  3890. * the player pressed <CANCEL>. *
  3891. * *
  3892. * WARNINGS: none *
  3893. * *
  3894. * HISTORY: *
  3895. * 07/11/1995 JLB : Created. *
  3896. * 05/22/1996 ST : Handles multiple CD drives / CD changers *
  3897. * 01/20/1997 V.Grippi added expansion cd message
  3898. *=============================================================================================*/
  3899. #if (1) //ST - 5/13/2019
  3900. bool Force_CD_Available(int cd)
  3901. {
  3902. static int _last = -1;
  3903. if (_last != cd || cd == ALWAYS_RELOAD_CD) {
  3904. if (cd != ALWAYS_RELOAD_CD) {
  3905. _last = cd;
  3906. }
  3907. Theme.Stop();
  3908. // if (ConquerMix) delete ConquerMix;
  3909. if (MoviesMix) {
  3910. delete MoviesMix;
  3911. MoviesMix = 0;
  3912. }
  3913. if (GeneralMix) {
  3914. delete GeneralMix;
  3915. GeneralMix = 0;
  3916. }
  3917. if (ScoreMix) {
  3918. delete ScoreMix;
  3919. ScoreMix = 0;
  3920. }
  3921. if (MainMix) {
  3922. delete MainMix;
  3923. MainMix = 0;
  3924. }
  3925. MainMix = new MFCD("MAIN.MIX", &FastKey);
  3926. assert(MainMix != NULL);
  3927. // ConquerMix = new MFCD("CONQUER.MIX", &FastKey);
  3928. if (CCFileClass("MOVIES1.MIX").Is_Available())
  3929. MoviesMix = new MFCD("MOVIES1.MIX", &FastKey);
  3930. else
  3931. MoviesMix = new MFCD("MOVIES2.MIX", &FastKey);
  3932. assert(MoviesMix != NULL);
  3933. GeneralMix = new MFCD("GENERAL.MIX", &FastKey);
  3934. ScoreMix = new MFCD("SCORES.MIX", &FastKey);
  3935. }
  3936. return true;
  3937. }
  3938. #endif
  3939. #if (0) //ST - 5/13/2019
  3940. typedef enum {
  3941. CD_LOCAL = -2,
  3942. CD_ANY = -1,
  3943. CD_SOVIET = 0,
  3944. CD_ALLIED,
  3945. CD_COUNTERSTRIKE,
  3946. CD_AFTERMATH,
  3947. CD_CS_OR_AM,
  3948. CD_DVD
  3949. } CD_VOLUME;
  3950. #ifdef FIXIT_VERSION_3
  3951. #ifndef DVD
  3952. #error DVD must be defined!
  3953. #endif
  3954. bool Force_CD_Available( int cd_desired ) // ajw
  3955. {
  3956. static int _last = -1;
  3957. static void *font;
  3958. #ifdef FRENCH
  3959. static char * _cd_name[] = {
  3960. "ALERTE ROUGE CD1",
  3961. "ALERTE ROUGE CD2",
  3962. "CD Missions Taiga",
  3963. "CD Missions M.A.D.",
  3964. "ALERTE ROUGE DVD",
  3965. };
  3966. #endif
  3967. #ifdef GERMAN
  3968. static char * _cd_name[] = {
  3969. "ALARMSTUFE ROT CD1",
  3970. "ALARMSTUFE ROT CD2",
  3971. "CD Gegenangriff einlegen",
  3972. "CD TRANS einlegen",
  3973. "ALARMSTUFE ROT DVD",
  3974. };
  3975. #endif
  3976. #ifdef ENGLISH
  3977. static char * _cd_name[] = {
  3978. "RED ALERT DISK 1",
  3979. "RED ALERT DISK 2",
  3980. "CounterStrike CD",
  3981. "Aftermath CD",
  3982. "RED ALERT DVD",
  3983. };
  3984. #endif
  3985. int new_cd_drive = 0;
  3986. int cd_current;
  3987. int current_drive;
  3988. ThemeType theme_playing = THEME_NONE;
  3989. /*
  3990. ** If the required CD is set to -2 then it means that the file is present
  3991. ** on the local hard drive and we shouldn't have to worry about it.
  3992. */
  3993. if (cd_desired == CD_LOCAL) return(true);
  3994. /*
  3995. ** Find out if the CD in the current drive is the one we are looking for
  3996. */
  3997. current_drive = CCFileClass::Get_CD_Drive();
  3998. cd_current = Get_CD_Index(current_drive, 1*60);
  3999. // debugprint("Get_CD_Index just returned %d\n", cd_current);
  4000. // debugprint("We are checking for %d\n", cd_desired);
  4001. // debugprint("current_drive = %d\n", current_drive);
  4002. if( Using_DVD() )
  4003. {
  4004. // All requested cd indexes get rerouted to the DVD.
  4005. cd_desired = CD_DVD;
  4006. // if( RequiredCD != -1 )
  4007. // RequiredCD = CD_DVD; // Just seems like a good idea. Not sure if necessary. ajw
  4008. }
  4009. if (cd_current >= 0 )
  4010. {
  4011. if( cd_desired == CD_CS_OR_AM )
  4012. {
  4013. // If the current cd is CS or AM then change request to whatever
  4014. // is present.
  4015. if( cd_current == CD_COUNTERSTRIKE || cd_current == CD_AFTERMATH )
  4016. cd_desired = cd_current;
  4017. }
  4018. // If the current CD is requested or any CD will work
  4019. if( cd_desired == cd_current || cd_desired == CD_ANY )
  4020. {
  4021. /*
  4022. ** The required CD is still in the CD drive we used last time
  4023. */
  4024. new_cd_drive = current_drive;
  4025. }
  4026. }
  4027. /*
  4028. ** Flag that we will have to restart the theme
  4029. */
  4030. theme_playing = Theme.What_Is_Playing();
  4031. Theme.Stop();
  4032. // Check the last drive
  4033. if (!new_cd_drive)
  4034. {
  4035. /*
  4036. ** Check the last CD drive we used if it's different from the current one
  4037. */
  4038. int last_drive = CCFileClass::Get_Last_CD_Drive();
  4039. /*
  4040. ** Make sure the last drive is valid and it isn't the current drive
  4041. */
  4042. if (last_drive && last_drive != CCFileClass::Get_CD_Drive()) // Else we have already checked this cd.
  4043. {
  4044. /*
  4045. ** Find out if there is a C&C cd in the last drive and if so is it the one we are looking for
  4046. ** Give it a nice big timeout so the CD changer has time to swap the discs
  4047. */
  4048. cd_current = Get_CD_Index(last_drive, 10*60);
  4049. if (cd_current >= 0 )
  4050. {
  4051. if( cd_desired == CD_CS_OR_AM )
  4052. {
  4053. // If the cd is CS or AM then change request to whatever
  4054. // is present.
  4055. if( cd_current == CD_COUNTERSTRIKE || cd_current == CD_AFTERMATH )
  4056. cd_desired = cd_current;
  4057. }
  4058. // If the cd is present or any cd will work
  4059. if( cd_desired == cd_current || cd_desired == CD_ANY )
  4060. {
  4061. /*
  4062. ** The required CD is in the CD drive we used last time
  4063. */
  4064. new_cd_drive = last_drive;
  4065. }
  4066. }
  4067. }
  4068. }
  4069. /*
  4070. ** Lordy. No sign of that blimming CD anywhere. Search all the CD drives
  4071. ** then if we still can't find it prompt the user to insert it.
  4072. */
  4073. if (!new_cd_drive)
  4074. {
  4075. /*
  4076. ** Small timeout for the first pass through the drives
  4077. */
  4078. int drive_search_timeout = 2*60;
  4079. for (;;)
  4080. {
  4081. char buffer[128];
  4082. /*
  4083. ** Search all present CD drives for the required disc.
  4084. */
  4085. for (int i = 0 ; i < CDList.Get_Number_Of_Drives(); i++)
  4086. {
  4087. int cd_drive = CDList.Get_Next_CD_Drive();
  4088. cd_current = Get_CD_Index(cd_drive, drive_search_timeout);
  4089. if (cd_current >= 0)
  4090. {
  4091. /*
  4092. ** We found a C&C cd - lets see if it was the one we were looking for
  4093. */
  4094. // Require CS or AM
  4095. if( cd_desired == CD_CS_OR_AM )
  4096. {
  4097. // If the cd is CS or AM then change request to whatever
  4098. // is present.
  4099. if( cd_current == CD_COUNTERSTRIKE || cd_current == CD_AFTERMATH )
  4100. cd_desired = cd_current;
  4101. }
  4102. if( cd_desired == cd_current || cd_desired == CD_ANY )
  4103. {
  4104. /*
  4105. ** Woohoo! The disk was in a different cd drive. Refresh the search path list
  4106. * and return.
  4107. */
  4108. new_cd_drive = cd_drive;
  4109. break;
  4110. }
  4111. }
  4112. }
  4113. /*
  4114. ** A new disc has become available so break
  4115. */
  4116. if (new_cd_drive) break;
  4117. /*
  4118. ** Increase the timeout for subsequent drive searches.
  4119. */
  4120. drive_search_timeout = 5*60;
  4121. /*
  4122. ** Prompt to insert the CD into the drive.
  4123. */
  4124. //V.Grippi
  4125. if( cd_desired == CD_CS_OR_AM )
  4126. cd_desired = CD_AFTERMATH;
  4127. if( cd_desired == CD_DVD )
  4128. {
  4129. #ifdef FRENCH
  4130. sprintf(buffer, "InsŠrez le %s", _cd_name[4]);
  4131. #else
  4132. #ifdef GERMAN
  4133. sprintf(buffer, "Bitte %s", _cd_name[4]);
  4134. #else
  4135. sprintf(buffer, "Please insert the %s", _cd_name[4]);
  4136. #endif
  4137. #endif
  4138. }
  4139. else if( cd_desired == CD_COUNTERSTRIKE || cd_desired == CD_AFTERMATH )
  4140. {
  4141. #ifdef FRENCH
  4142. sprintf(buffer, "InsŠrez le %s", _cd_name[cd_desired]);
  4143. #else
  4144. #ifdef GERMAN
  4145. sprintf(buffer, "Bitte %s", _cd_name[cd_desired]);
  4146. #else
  4147. sprintf(buffer, "Please insert the %s", _cd_name[cd_desired]);
  4148. #endif
  4149. #endif
  4150. }
  4151. else if( cd_desired == CD_ANY )
  4152. {
  4153. sprintf(buffer, Text_String(TXT_CD_DIALOG_1), cd_desired+1, _cd_name[cd_desired]);
  4154. }
  4155. else // 0 or 1
  4156. {
  4157. sprintf(buffer, Text_String(TXT_CD_DIALOG_2), cd_desired+1, _cd_name[cd_desired]);
  4158. }
  4159. GraphicViewPortClass * oldpage = Set_Logic_Page(SeenBuff);
  4160. theme_playing = Theme.What_Is_Playing();
  4161. Theme.Stop();
  4162. int hidden = Get_Mouse_State();
  4163. font = (void *)FontPtr;
  4164. /*
  4165. ** Only set the palette if necessary.
  4166. */
  4167. if (PaletteClass::CurrentPalette[1].Red_Component() +
  4168. PaletteClass::CurrentPalette[1].Blue_Component() +
  4169. PaletteClass::CurrentPalette[1].Green_Component() == 0)
  4170. {
  4171. GamePalette.Set();
  4172. }
  4173. Keyboard->Clear();
  4174. while (Get_Mouse_State()) Show_Mouse();
  4175. if (WWMessageBox().Process(buffer, TXT_OK, TXT_CANCEL, TXT_NONE, TRUE) == 1)
  4176. {
  4177. Set_Logic_Page(oldpage);
  4178. #ifdef FIXIT_VERSION_3
  4179. while (hidden--) Hide_Mouse();
  4180. #else
  4181. Hide_Mouse();
  4182. #endif
  4183. return(false);
  4184. }
  4185. while (hidden--) Hide_Mouse();
  4186. Set_Font(font);
  4187. Set_Logic_Page(oldpage);
  4188. }
  4189. }
  4190. CurrentCD = cd_current;
  4191. CCFileClass::Set_CD_Drive(new_cd_drive);
  4192. CCFileClass::Refresh_Search_Drives();
  4193. /*
  4194. ** If it broke out of the query for CD-ROM loop, then this means that the
  4195. ** CD-ROM has been inserted.
  4196. */
  4197. if (cd_desired == 4) cd_desired--;
  4198. // ajw - Added condition of cd_desired != 5 to the following if.
  4199. // Reason: This was triggering before Init_Secondary_Mixfiles(), which was screwing up the mixfile system somehow.
  4200. //
  4201. // Since the DVD is the only disk that can possibly be required when Using_DVD(), I never have to reload the mix
  4202. // files here, because no other disk could ever have been asked for. And if not Using_DVD(), cd_desired will never
  4203. // be equal to 5. So this is safe.
  4204. if (cd_desired > -1 && _last != cd_desired && cd_desired != 5)
  4205. {
  4206. _last = cd_desired;
  4207. Theme.Stop();
  4208. // if (ConquerMix) delete ConquerMix;
  4209. if (MoviesMix) delete MoviesMix;
  4210. if (GeneralMix) delete GeneralMix;
  4211. if (ScoreMix) delete ScoreMix;
  4212. if (MainMix) delete MainMix;
  4213. MainMix = new MFCD("MAIN.MIX", &FastKey);
  4214. assert(MainMix != NULL);
  4215. // ConquerMix = new MFCD("CONQUER.MIX", &FastKey);
  4216. if (CCFileClass("MOVIES1.MIX").Is_Available())
  4217. MoviesMix = new MFCD("MOVIES1.MIX", &FastKey);
  4218. else
  4219. MoviesMix = new MFCD("MOVIES2.MIX", &FastKey);
  4220. assert(MoviesMix != NULL);
  4221. GeneralMix = new MFCD("GENERAL.MIX", &FastKey);
  4222. ScoreMix = new MFCD("SCORES.MIX", &FastKey);
  4223. ThemeClass::Scan();
  4224. }
  4225. return(true);
  4226. }
  4227. #else // FIXIT_VERSION_3 not defined
  4228. bool Force_CD_Available(int cd)
  4229. {
  4230. static int _last = -1;
  4231. // static char _palette[768];
  4232. // static char _hold[256];
  4233. static void *font;
  4234. #ifdef FRENCH
  4235. static char * _cd_name[] = {
  4236. "ALERTE ROUGE CD1",
  4237. "ALERTE ROUGE CD2",
  4238. "CD Missions Taiga",
  4239. "CD Missions M.A.D.",
  4240. // Denzil 4/15/98
  4241. #ifdef DVD
  4242. "ALERTE ROUGE DVD",
  4243. #endif
  4244. };
  4245. #endif
  4246. #ifdef GERMAN
  4247. static char * _cd_name[] = {
  4248. "ALARMSTUFE ROT CD1 einlegen",
  4249. "ALARMSTUFE ROT CD2 einlegen",
  4250. "CD Gegenangriff einlegen",
  4251. "CD TRANS einlegen",
  4252. // Denzil 4/15/98
  4253. #ifdef DVD
  4254. "ALARMSTUFE ROT DVD einlegen",
  4255. #endif
  4256. };
  4257. #endif
  4258. #ifdef ENGLISH
  4259. static char * _cd_name[] = {
  4260. "RED ALERT DISK 1",
  4261. "RED ALERT DISK 2",
  4262. "CounterStrike CD",
  4263. "Aftermath CD",
  4264. // Denzil 4/15/98
  4265. #ifdef DVD
  4266. "RED ALERT DVD",
  4267. #endif
  4268. };
  4269. #endif
  4270. int new_cd_drive = 0;
  4271. int cd_index;
  4272. char buffer[128];
  4273. int cd_drive;
  4274. int current_drive;
  4275. int drive_search_timeout;
  4276. ThemeType theme_playing = THEME_NONE;
  4277. //#ifdef FIXIT_ANTS
  4278. // if(Scen.ScenarioName[2] == 'A')
  4279. // cd = 2;
  4280. //#endif
  4281. /*
  4282. ** If the required CD is set to -2 then it means that the file is present
  4283. ** on the local hard drive and we shouldn't have to worry about it.
  4284. */
  4285. if (cd == CD_LOCAL) return(true);
  4286. /*
  4287. ** Find out if the CD in the current drive is the one we are looking for
  4288. */
  4289. current_drive = CCFileClass::Get_CD_Drive();
  4290. cd_index = Get_CD_Index(current_drive, 1*60);
  4291. #ifdef CHEAT_KEYS
  4292. // Mono_Printf("Get_CD_Index just returned %d\n", cd_index);
  4293. // Mono_Printf("We are checking for %d\n", cd);
  4294. // Mono_Printf("current_drive = %d\n", current_drive);
  4295. #endif //CHEAT_KEYS
  4296. #ifdef DVD // Denzil
  4297. // CD1 and CD2 are ignored, force the DVD
  4298. if (cd_index == 0 || cd_index == 1)
  4299. cd_index = -1;
  4300. #endif
  4301. if (cd_index >= 0 )
  4302. {
  4303. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  4304. // Require CS or AM
  4305. if (cd == CD_CS_OR_AM)
  4306. {
  4307. // If the current cd is CS or AM then change request to whatever
  4308. // is present.
  4309. if (cd_index == 2 || cd_index == 3)
  4310. {
  4311. cd = cd_index;
  4312. }
  4313. }
  4314. #endif
  4315. #ifdef DVD // Denzil
  4316. // If the current drive is the DVD then requests for CD1 and CD2 are okay
  4317. if (cd_index == 4)
  4318. {
  4319. // CD1, CD2 & DVD requests
  4320. if (cd == 0 || cd == 1 || cd == 5)
  4321. {
  4322. cd_index = cd;
  4323. }
  4324. }
  4325. #endif
  4326. // If the current CD is requested or any CD will work
  4327. if (cd == cd_index || cd == -1 )
  4328. {
  4329. /*
  4330. ** The required CD is still in the CD drive we used last time
  4331. */
  4332. new_cd_drive = current_drive;
  4333. }
  4334. }
  4335. /*
  4336. ** Flag that we will have to restart the theme
  4337. */
  4338. theme_playing = Theme.What_Is_Playing();
  4339. Theme.Stop();
  4340. // Check the last drive
  4341. if (!new_cd_drive)
  4342. {
  4343. /*
  4344. ** Check the last CD drive we used if it's different from the current one
  4345. */
  4346. int last_drive = CCFileClass::Get_Last_CD_Drive();
  4347. /*
  4348. ** Make sure the last drive is valid and it isn't the current drive
  4349. */
  4350. if (last_drive && last_drive != CCFileClass::Get_CD_Drive())
  4351. {
  4352. /*
  4353. ** Find out if there is a C&C cd in the last drive and if so is it the one we are looking for
  4354. ** Give it a nice big timeout so the CD changer has time to swap the discs
  4355. */
  4356. cd_index = Get_CD_Index(last_drive, 10*60);
  4357. #ifdef DVD // Denzil
  4358. // Ignore CD1 and CD2 disks, force DVD
  4359. if (cd_index == 0 || cd_index == 1)
  4360. cd_index = -1;
  4361. #endif
  4362. if (cd_index >= 0 )
  4363. {
  4364. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  4365. // Require CS or AM
  4366. if (cd == 4)
  4367. {
  4368. // If CS or AM was the last drive then use it
  4369. if (cd_index == 2 || cd_index == 3)
  4370. {
  4371. cd = cd_index;
  4372. }
  4373. }
  4374. #endif
  4375. #ifdef DVD // Denzil
  4376. // If DVD is in drive
  4377. if (cd_index == 4)
  4378. {
  4379. // CD1, CD2 and DVD requests are all on the DVD
  4380. if ((cd == 0) || (cd == 1) || (cd == 5))
  4381. {
  4382. cd_index = cd;
  4383. }
  4384. }
  4385. #endif
  4386. // If the cd is present or any cd will work
  4387. if (cd == cd_index || cd == -1 )
  4388. {
  4389. /*
  4390. ** The required CD is in the CD drive we used last time
  4391. */
  4392. new_cd_drive = last_drive;
  4393. }
  4394. }
  4395. }
  4396. }
  4397. /*
  4398. ** Lordy. No sign of that blimming CD anywhere. Search all the CD drives
  4399. ** then if we still can't find it prompt the user to insert it.
  4400. */
  4401. if (!new_cd_drive)
  4402. {
  4403. /*
  4404. ** Small timeout for the first pass through the drives
  4405. */
  4406. drive_search_timeout = 2*60;
  4407. for (;;)
  4408. {
  4409. /*
  4410. ** Search all present CD drives for the required disc.
  4411. */
  4412. for (int i = 0 ; i < CDList.Get_Number_Of_Drives(); i++)
  4413. {
  4414. cd_drive = CDList.Get_Next_CD_Drive();
  4415. cd_index = Get_CD_Index(cd_drive, drive_search_timeout);
  4416. #ifdef DVD // Denzil
  4417. // Ignore CD1 and CD2, force the DVD
  4418. if (cd_index == 0 || cd_index == 1)
  4419. cd_index = -1;
  4420. #endif
  4421. if (cd_index >= 0)
  4422. {
  4423. /*
  4424. ** We found a C&C cd - lets see if it was the one we were looking for
  4425. */
  4426. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  4427. // Require CS or AM
  4428. if (cd == 4)
  4429. {
  4430. // If the disk is CS or AM then request it
  4431. if (cd_index == 2 || cd_index == 3)
  4432. {
  4433. cd = cd_index;
  4434. }
  4435. }
  4436. #endif
  4437. #ifdef DVD // Denzil
  4438. if (cd_index == 4)
  4439. {
  4440. if ((cd == 0) || (cd == 1) || (cd == 5))
  4441. {
  4442. cd_index = cd;
  4443. }
  4444. }
  4445. #endif
  4446. if (cd == cd_index || cd == -1 || cd == -2 )
  4447. {
  4448. /*
  4449. ** Woohoo! The disk was in a different cd drive. Refresh the search path list
  4450. * and return.
  4451. */
  4452. new_cd_drive = cd_drive;
  4453. break;
  4454. }
  4455. }
  4456. }
  4457. /*
  4458. ** A new disc has become available so break
  4459. */
  4460. if (new_cd_drive) break;
  4461. /*
  4462. ** Increase the timeout for subsequent drive searches.
  4463. */
  4464. drive_search_timeout = 5*60;
  4465. /*
  4466. ** Prompt to insert the CD into the drive.
  4467. */
  4468. //V.Grippi
  4469. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  4470. if(cd == 4) cd--;
  4471. // CS or AM
  4472. if(cd == 2 || cd == 3)
  4473. {
  4474. #else
  4475. if(cd == 2)
  4476. {
  4477. #endif
  4478. #ifdef FRENCH
  4479. sprintf(buffer, "InsŠrez le %s", _cd_name[cd]);
  4480. #else
  4481. #ifdef GERMAN
  4482. sprintf(buffer, "Bitte %s", _cd_name[cd]);
  4483. #else
  4484. sprintf(buffer, "Please insert the %s", _cd_name[cd]);
  4485. #endif
  4486. #endif
  4487. }
  4488. else
  4489. {
  4490. #ifdef DVD
  4491. #ifdef FRENCH
  4492. sprintf(buffer, "InsŠrez le %s", _cd_name[4]);
  4493. #else
  4494. #ifdef GERMAN
  4495. sprintf(buffer, "Bitte %s", _cd_name[4]);
  4496. #else
  4497. sprintf(buffer, "Please insert the %s", _cd_name[4]);
  4498. #endif
  4499. #endif
  4500. #else
  4501. if (cd == -1 )
  4502. {
  4503. sprintf(buffer, Text_String(TXT_CD_DIALOG_1), cd+1, _cd_name[cd]);
  4504. }
  4505. else
  4506. {
  4507. sprintf(buffer, Text_String(TXT_CD_DIALOG_2), cd+1, _cd_name[cd]);
  4508. }
  4509. #endif
  4510. }
  4511. #ifdef WIN32
  4512. GraphicViewPortClass * oldpage = Set_Logic_Page(SeenBuff);
  4513. #else
  4514. GraphicBufferClass * oldpage = Set_Logic_Page(SeenBuff);
  4515. #endif
  4516. theme_playing = Theme.What_Is_Playing();
  4517. Theme.Stop();
  4518. int hidden = Get_Mouse_State();
  4519. font = (void *)FontPtr;
  4520. /*
  4521. ** Only set the palette if necessary.
  4522. */
  4523. if (PaletteClass::CurrentPalette[1].Red_Component() +
  4524. PaletteClass::CurrentPalette[1].Blue_Component() +
  4525. PaletteClass::CurrentPalette[1].Green_Component() == 0)
  4526. {
  4527. GamePalette.Set();
  4528. }
  4529. Keyboard->Clear();
  4530. while (Get_Mouse_State()) Show_Mouse();
  4531. if (WWMessageBox().Process(buffer, TXT_OK, TXT_CANCEL, TXT_NONE, TRUE) == 1)
  4532. {
  4533. Set_Logic_Page(oldpage);
  4534. Hide_Mouse();
  4535. return(false);
  4536. }
  4537. while (hidden--) Hide_Mouse();
  4538. Set_Font(font);
  4539. Set_Logic_Page(oldpage);
  4540. }
  4541. }
  4542. CurrentCD = cd_index;
  4543. CCFileClass::Set_CD_Drive(new_cd_drive);
  4544. CCFileClass::Refresh_Search_Drives();
  4545. /*
  4546. ** If it broke out of the query for CD-ROM loop, then this means that the
  4547. ** CD-ROM has been inserted.
  4548. */
  4549. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  4550. if (cd == 4) cd--;
  4551. #endif
  4552. // if (cd > -3 && _last != cd) {
  4553. if (cd > -1 && _last != cd)
  4554. {
  4555. _last = cd;
  4556. Theme.Stop();
  4557. // if (ConquerMix) delete ConquerMix;
  4558. if (MoviesMix) delete MoviesMix;
  4559. if (GeneralMix) delete GeneralMix;
  4560. if (ScoreMix) delete ScoreMix;
  4561. if (MainMix) delete MainMix;
  4562. MainMix = new MFCD("MAIN.MIX", &FastKey);
  4563. assert(MainMix != NULL);
  4564. // ConquerMix = new MFCD("CONQUER.MIX", &FastKey);
  4565. if (CCFileClass("MOVIES1.MIX").Is_Available())
  4566. {
  4567. MoviesMix = new MFCD("MOVIES1.MIX", &FastKey);
  4568. }
  4569. else
  4570. {
  4571. MoviesMix = new MFCD("MOVIES2.MIX", &FastKey);
  4572. }
  4573. assert(MoviesMix != NULL);
  4574. GeneralMix = new MFCD("GENERAL.MIX", &FastKey);
  4575. ScoreMix = new MFCD("SCORES.MIX", &FastKey);
  4576. ThemeClass::Scan();
  4577. }
  4578. if (theme_playing != THEME_NONE)
  4579. {
  4580. Theme.Queue_Song(theme_playing);
  4581. }
  4582. return(true);
  4583. }
  4584. #endif // FIXIT_VERSION_3
  4585. #endif // ST - 5/13/2019
  4586. /***************************************************************************
  4587. * DISK_SPACE_AVAILABLE -- returns bytes of free disk space *
  4588. * *
  4589. * INPUT: none *
  4590. * *
  4591. * OUTPUT: returns amount of free disk space *
  4592. * *
  4593. * HISTORY: *
  4594. * 08/11/1995 PWG : Created. *
  4595. *=========================================================================*/
  4596. unsigned long Disk_Space_Available(void)
  4597. {
  4598. return 0x7fffffff; //ST - 5/8/2019
  4599. #if (0)
  4600. struct diskfree_t diskdata;
  4601. unsigned drive;
  4602. _dos_getdrive(&drive);
  4603. _dos_getdiskfree(drive, &diskdata);
  4604. return(diskdata.avail_clusters * diskdata.sectors_per_cluster * diskdata.bytes_per_sector);
  4605. #endif
  4606. }
  4607. /***********************************************************************************************
  4608. * Do_Record_Playback -- handles saving/loading map pos & current object *
  4609. * *
  4610. * INPUT: *
  4611. * none. *
  4612. * *
  4613. * OUTPUT: *
  4614. * none. *
  4615. * *
  4616. * WARNINGS: *
  4617. * none. *
  4618. * *
  4619. * HISTORY: *
  4620. * 08/15/1995 BRR : Created. *
  4621. *=============================================================================================*/
  4622. static void Do_Record_Playback(void)
  4623. {
  4624. int count;
  4625. TARGET tgt;
  4626. int i;
  4627. COORDINATE coord;
  4628. ObjectClass * obj;
  4629. unsigned long sum;
  4630. unsigned long sum2;
  4631. unsigned long ltgt;
  4632. /*
  4633. ** Record a game
  4634. */
  4635. if (Session.Record) {
  4636. /*
  4637. ** Save the map's location
  4638. */
  4639. Session.RecordFile.Write(&Map.DesiredTacticalCoord,
  4640. sizeof (Map.DesiredTacticalCoord));
  4641. /*
  4642. ** Save the current object list count
  4643. */
  4644. count = CurrentObject.Count();
  4645. Session.RecordFile.Write(&count, sizeof(count));
  4646. /*
  4647. ** Save a CRC of the selected-object list.
  4648. */
  4649. sum = 0;
  4650. for (i = 0; i < count; i++) {
  4651. ltgt = (unsigned long)(CurrentObject[i]->As_Target());
  4652. sum += ltgt;
  4653. }
  4654. Session.RecordFile.Write (&sum, sizeof(sum));
  4655. /*
  4656. ** Save all selected objects.
  4657. */
  4658. for (i = 0; i < count; i++) {
  4659. tgt = CurrentObject[i]->As_Target();
  4660. Session.RecordFile.Write (&tgt, sizeof(tgt));
  4661. }
  4662. //
  4663. // Save team-selection and formation events
  4664. //
  4665. Session.RecordFile.Write (&TeamEvent, sizeof(TeamEvent));
  4666. Session.RecordFile.Write (&TeamNumber, sizeof(TeamNumber));
  4667. Session.RecordFile.Write (&FormationEvent, sizeof(FormationEvent));
  4668. Session.RecordFile.Write (TeamFormData, sizeof(TeamFormData));
  4669. Session.RecordFile.Write (&FormMove, sizeof(FormMove));
  4670. Session.RecordFile.Write (&FormSpeed, sizeof(FormSpeed));
  4671. Session.RecordFile.Write (&FormMaxSpeed, sizeof(FormMaxSpeed));
  4672. TeamEvent = 0;
  4673. TeamNumber = 0;
  4674. FormationEvent = 0;
  4675. }
  4676. /*
  4677. ** Play back a game ("attract" mode)
  4678. */
  4679. if (Session.Play) {
  4680. /*
  4681. ** Read & set the map's location.
  4682. */
  4683. if (Session.RecordFile.Read(&coord, sizeof(coord))==sizeof(coord)) {
  4684. if (coord != Map.DesiredTacticalCoord) {
  4685. Map.Set_Tactical_Position(coord);
  4686. }
  4687. }
  4688. if (Session.RecordFile.Read(&count, sizeof(count))==sizeof(count)) {
  4689. /*
  4690. ** Compute a CRC of the current object-selection list.
  4691. */
  4692. sum = 0;
  4693. for (i = 0; i < CurrentObject.Count(); i++) {
  4694. ltgt = (unsigned long)(CurrentObject[i]->As_Target());
  4695. sum += ltgt;
  4696. }
  4697. /*
  4698. ** Load the CRC of the objects on disk; if it doesn't match, select
  4699. ** all objects as they're loaded.
  4700. */
  4701. Session.RecordFile.Read (&sum2, sizeof(sum2));
  4702. if (sum2 != sum) {
  4703. Unselect_All();
  4704. }
  4705. AllowVoice = true;
  4706. for (i = 0; i < count; i++) {
  4707. if (Session.RecordFile.Read (&tgt, sizeof(tgt))==sizeof(tgt)) {
  4708. obj = As_Object(tgt);
  4709. if (obj && (sum2 != sum)) {
  4710. obj->Select();
  4711. AllowVoice = false;
  4712. }
  4713. }
  4714. }
  4715. AllowVoice = true;
  4716. }
  4717. //
  4718. // Save team-selection and formation events
  4719. //
  4720. Session.RecordFile.Read (&TeamEvent, sizeof(TeamEvent));
  4721. Session.RecordFile.Read (&TeamNumber, sizeof(TeamNumber));
  4722. Session.RecordFile.Read (&FormationEvent, sizeof(FormationEvent));
  4723. if (TeamEvent) {
  4724. Handle_Team(TeamNumber, TeamEvent - 1);
  4725. }
  4726. if (FormationEvent) {
  4727. Toggle_Formation();
  4728. }
  4729. Session.RecordFile.Read (TeamFormData, sizeof(TeamFormData));
  4730. Session.RecordFile.Read (&FormMove, sizeof(FormMove));
  4731. Session.RecordFile.Read (&FormSpeed, sizeof(FormSpeed));
  4732. Session.RecordFile.Read (&FormMaxSpeed, sizeof(FormMaxSpeed));
  4733. /*
  4734. ** The map isn't drawn in playback mode, so draw it here.
  4735. */
  4736. Map.Render();
  4737. }
  4738. }
  4739. /***********************************************************************************************
  4740. * Hires_Load -- Allocates memory for, and loads, a resolution dependant file. *
  4741. * *
  4742. * *
  4743. * *
  4744. * INPUT: Name of file to load *
  4745. * *
  4746. * OUTPUT: Ptr to loaded file *
  4747. * *
  4748. * WARNINGS: Caller is responsible for releasing the memory allocated *
  4749. * *
  4750. * *
  4751. * HISTORY: *
  4752. * 5/13/96 3:20PM ST : Created *
  4753. *=============================================================================================*/
  4754. void * Hires_Load(char * name)
  4755. {
  4756. char filename[30];
  4757. int length;
  4758. void * return_ptr;
  4759. #ifdef WIN32
  4760. sprintf(filename, "H%s", name);
  4761. #else
  4762. strcpy(filename, name);
  4763. #endif
  4764. CCFileClass file (filename);
  4765. if (file.Is_Available()) {
  4766. length = file.Size();
  4767. return_ptr = new char[length];
  4768. file.Read(return_ptr, length);
  4769. return (return_ptr);
  4770. } else {
  4771. return (NULL);
  4772. }
  4773. }
  4774. /***********************************************************************************************
  4775. * Crate_From_Name -- Given a crate name convert it to a crate type. *
  4776. * *
  4777. * Use this routine to convert an ASCII crate name into a crate type. If no match could *
  4778. * be found, then CRATE_MONEY is assumed. *
  4779. * *
  4780. * INPUT: name -- Pointer to the crate name text to convert into a crate type. *
  4781. * *
  4782. * OUTPUT: Returns with the crate name converted into a crate type. *
  4783. * *
  4784. * WARNINGS: none *
  4785. * *
  4786. * HISTORY: *
  4787. * 08/12/1996 JLB : Created. *
  4788. *=============================================================================================*/
  4789. CrateType Crate_From_Name(char const * name)
  4790. {
  4791. if (name != NULL) {
  4792. for (CrateType crate = CRATE_FIRST; crate < CRATE_COUNT; crate++) {
  4793. if (stricmp(name, CrateNames[crate]) == 0) return(crate);
  4794. }
  4795. }
  4796. return(CRATE_MONEY);
  4797. }
  4798. /***********************************************************************************************
  4799. * Owner_From_Name -- Convert an owner name into a bitfield. *
  4800. * *
  4801. * This will take an owner specification and convert it into a bitfield that represents *
  4802. * it. Sometimes this will be just a single house bit, but other times it could be *
  4803. * all the allies or soviet house bits combined. *
  4804. * *
  4805. * INPUT: text -- Pointer to the text to convert into a house bitfield. *
  4806. * *
  4807. * OUTPUT: Returns with the houses specified. The value is in the form of a bit field with *
  4808. * one bit per house type. *
  4809. * *
  4810. * WARNINGS: none *
  4811. * *
  4812. * HISTORY: *
  4813. * 08/12/1996 JLB : Created. *
  4814. *=============================================================================================*/
  4815. int Owner_From_Name(char const * text)
  4816. {
  4817. int ownable = 0;
  4818. if (stricmp(text, "soviet") == 0) {
  4819. ownable |= HOUSEF_SOVIET;
  4820. } else {
  4821. if (stricmp(text, "allies") == 0 || stricmp(text, "allied") == 0) {
  4822. ownable |= HOUSEF_ALLIES;
  4823. } else {
  4824. HousesType h = HouseTypeClass::From_Name(text);
  4825. if (h != HOUSE_NONE && (h < HOUSE_MULTI1 || h > HOUSE_MULTI8)) {
  4826. ownable |= (1 << h);
  4827. }
  4828. }
  4829. }
  4830. return(ownable);
  4831. }
  4832. /***********************************************************************************************
  4833. * Shake_The_Screen -- Dispatcher that shakes the screen. *
  4834. * *
  4835. * This routine will shake the game screen the number of shakes requested. *
  4836. * *
  4837. * INPUT: shakes -- The number of shakes to shake the screen. *
  4838. * house -- House to perform the shake for (or HOUSE_NONE if all players). *
  4839. * *
  4840. * OUTPUT: none *
  4841. * *
  4842. * WARNINGS: none *
  4843. * *
  4844. * HISTORY: *
  4845. * 09/04/1996 BWG : Created. *
  4846. *=============================================================================================*/
  4847. void Shake_The_Screen(int shakes, HousesType house)
  4848. {
  4849. for (char h = HOUSE_FIRST; h < HOUSE_COUNT; ++h) {
  4850. if ((house != HOUSE_NONE) && (h != house)) {
  4851. continue;
  4852. }
  4853. HouseClass* hptr = HouseClass::As_Pointer((HousesType)h);
  4854. if ((hptr != nullptr) && hptr->IsActive && hptr->IsHuman) {
  4855. hptr->ScreenShakeTime = CDTimerClass<FrameTimerClass>(hptr->ScreenShakeTime + shakes + shakes);
  4856. hptr->ScreenShakeTime.Start();
  4857. }
  4858. }
  4859. #if (0)
  4860. #ifdef WIN32
  4861. shakes += shakes;
  4862. Hide_Mouse();
  4863. SeenPage.Blit(HidPage);
  4864. int oldyoff = 0;
  4865. int newyoff = 0;
  4866. while(shakes--) {
  4867. int x = TickCount;
  4868. // CountDownTimer = 1;
  4869. do {
  4870. newyoff = Sim_Random_Pick(0,2) - 1;
  4871. } while (newyoff == oldyoff);
  4872. switch (newyoff) {
  4873. case -1:
  4874. HidPage.Blit(SeenPage, 0,2, 0,0, 640,398);
  4875. break;
  4876. case 0:
  4877. HidPage.Blit(SeenPage);
  4878. break;
  4879. case 1:
  4880. HidPage.Blit(SeenPage, 0,0, 0,2, 640,398);
  4881. break;
  4882. } while (x == TickCount);
  4883. // } while (CountDownTimer != 0) ;
  4884. }
  4885. HidPage.Blit(SeenPage);
  4886. Show_Mouse();
  4887. #else
  4888. Shake_Screen(shakes);
  4889. #endif
  4890. #endif
  4891. }
  4892. /***********************************************************************************************
  4893. * List_Copy -- Makes a copy of a cell offset list. *
  4894. * *
  4895. * This routine will make a copy of a cell offset list. It will only copy the significant *
  4896. * elements of the list limited by the maximum length specified. *
  4897. * *
  4898. * INPUT: source -- Pointer to a cell offset list. *
  4899. * *
  4900. * len -- The maximum number of cell offset elements to store in to the *
  4901. * destination list pointer. *
  4902. * *
  4903. * dest -- Pointer to the destination list to store the copy into. *
  4904. * *
  4905. * OUTPUT: none *
  4906. * *
  4907. * WARNINGS: Ensure that the destination list is large enough to hold the list copy. *
  4908. * *
  4909. * HISTORY: *
  4910. * 09/04/1996 JLB : Created. *
  4911. *=============================================================================================*/
  4912. void List_Copy(short const * source, int len, short * dest)
  4913. {
  4914. if (dest == NULL || dest == NULL) {
  4915. return;
  4916. }
  4917. while (len > 0) {
  4918. *dest = *source;
  4919. if (*dest == REFRESH_EOL) break;
  4920. dest++;
  4921. source++;
  4922. len--;
  4923. }
  4924. }
  4925. #if 0
  4926. //
  4927. // Boy, this function sure is crummy
  4928. //
  4929. void Crummy(int crumb1, int crumb2)
  4930. {
  4931. if (Debug_Check_Map && Debug_Heap_Dump) {
  4932. Mono_Printf("Hi, I'm Crummy. And so are these: %d, %d\n",crumb1,crumb2);
  4933. }
  4934. }
  4935. #endif
  4936. /***********************************************************************************************
  4937. * Game_Registry_Key -- Returns pointer to string containing the registry subkey for the game.
  4938. * This is located under HKEY_LOCAL_MACHINE.
  4939. * HISTORY:
  4940. * 11/19/98 ajw : Created
  4941. *=============================================================================================*/
  4942. const char* Game_Registry_Key()
  4943. {
  4944. #ifdef ENGLISH
  4945. static char szKey[] = "SOFTWARE\\Westwood\\Red Alert Windows 95 Edition";
  4946. #else
  4947. #ifdef GERMAN
  4948. static char szKey[] = "SOFTWARE\\Westwood\\Alarmstufe Rot Windows 95 Edition";
  4949. #else
  4950. static char szKey[] = "SOFTWARE\\Westwood\\Alerte Rouge version Windows 95";
  4951. #endif
  4952. #endif
  4953. return szKey;
  4954. }
  4955. /***********************************************************************************************
  4956. * Is_Counterstrike_Installed -- Function to determine the availability of the CS expansion *
  4957. * *
  4958. * *
  4959. * *
  4960. * INPUT: Nothing *
  4961. * *
  4962. * OUTPUT: true if Counterstrike is present *
  4963. * *
  4964. * WARNINGS: None *
  4965. * *
  4966. * HISTORY: *
  4967. * 4/1/97 11:39PM ST : Created *
  4968. *=============================================================================================*/
  4969. bool Is_Counterstrike_Installed (void)
  4970. {
  4971. return true; // Remasters always have Counterstrike. ST - 10/18/2019 11:06AM
  4972. #if (0)
  4973. // ajw 9/29/98
  4974. static bool bAlreadyChecked = false;
  4975. static bool bInstalled = false;
  4976. if( !bAlreadyChecked )
  4977. {
  4978. HKEY hKey;
  4979. if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, Game_Registry_Key(), 0, KEY_READ, &hKey ) != ERROR_SUCCESS )
  4980. return false;
  4981. DWORD dwValue;
  4982. DWORD dwBufSize = sizeof( DWORD );
  4983. if( RegQueryValueEx( hKey, "CStrikeInstalled", 0, NULL, (LPBYTE)&dwValue, &dwBufSize ) != ERROR_SUCCESS )
  4984. bInstalled = false;
  4985. else
  4986. bInstalled = (bool)dwValue; // (Presumably true, if it's there...)
  4987. RegCloseKey( hKey );
  4988. bAlreadyChecked = true;
  4989. }
  4990. return bInstalled;
  4991. // RawFileClass file("EXPAND.MIX");
  4992. // return(file.Is_Available());
  4993. #endif
  4994. }
  4995. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  4996. /***********************************************************************************************
  4997. *=============================================================================================*/
  4998. bool Is_Aftermath_Installed (void)
  4999. {
  5000. return true; // Remasters always have Aftermath. ST - 10/18/2019 11:06AM
  5001. #if (0)
  5002. // ajw 9/29/98
  5003. static bool bAlreadyChecked = false;
  5004. static bool bInstalled = false;
  5005. if( !bAlreadyChecked )
  5006. {
  5007. HKEY hKey;
  5008. if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, Game_Registry_Key(), 0, KEY_READ, &hKey ) != ERROR_SUCCESS )
  5009. return false;
  5010. DWORD dwValue;
  5011. DWORD dwBufSize = sizeof( DWORD );
  5012. if( RegQueryValueEx( hKey, "AftermathInstalled", 0, NULL, (LPBYTE)&dwValue, &dwBufSize ) != ERROR_SUCCESS )
  5013. bInstalled = false;
  5014. else
  5015. bInstalled = (bool)dwValue; // (Presumably true, if it's there...)
  5016. RegCloseKey( hKey );
  5017. bAlreadyChecked = true;
  5018. }
  5019. return bInstalled;
  5020. // RawFileClass file("EXPAND2.MIX");
  5021. // return(file.Is_Available());
  5022. #endif
  5023. }
  5024. #endif
  5025. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  5026. void Enable_Secret_Units(void)
  5027. {
  5028. #if 0
  5029. SecretUnitsEnabled=true;
  5030. UnitTypeClass::As_Reference(UNIT_PHASE).Level=10;
  5031. VesselTypeClass::As_Reference(VESSEL_CARRIER).Level=10;
  5032. for (int index = 0; index < Buildings.Count(); index++) {
  5033. Buildings.Ptr(index)->Update_Buildables();
  5034. }
  5035. #endif
  5036. }
  5037. #endif
  5038. #ifdef FIXIT_VERSION_3
  5039. bool Force_Scenario_Available( const char* szName )
  5040. {
  5041. // Calls Force_CD_Available based on type of scenario. szName is assumed to be an official scenario here.
  5042. if( Is_Mission_Counterstrike( (char*)szName ) )
  5043. {
  5044. // debugprint( "Force_Scenario_Available requiring disk 4...\n" );
  5045. return Force_CD_Available( 4 );
  5046. }
  5047. else if( Is_Mission_Aftermath( (char*)szName ) )
  5048. {
  5049. // debugprint( "Force_Scenario_Available requiring disk 3...\n" );
  5050. return Force_CD_Available( 3 );
  5051. }
  5052. return true;
  5053. }
  5054. #endif