CONQUER.CPP 178 KB

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