Loading.cpp 186 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. // Loading.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "FinalSun.h"
  20. #include "Loading.h"
  21. #include <fcntl.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <io.h>
  25. #include <stdio.h>
  26. #include "resource.h"
  27. #include "mapdata.h"
  28. #include "variables.h"
  29. #include "functions.h"
  30. #include "inlines.h"
  31. #include "MissionEditorPackLib.h"
  32. #include <chrono>
  33. #include <thread>
  34. #include "VoxelNormals.h"
  35. #include <format>
  36. #ifdef _DEBUG
  37. #define new DEBUG_NEW
  38. #undef THIS_FILE
  39. static char THIS_FILE[] = __FILE__;
  40. #endif
  41. /////////////////////////////////////////////////////////////////////////////
  42. // Dialogfeld CLoading
  43. CLoading::CLoading(CWnd* pParent /*=NULL*/)
  44. : CDialog(CLoading::IDD, pParent)
  45. {
  46. //{{AFX_DATA_INIT(CLoading)
  47. //}}AFX_DATA_INIT
  48. Create(CLoading::IDD, pParent);
  49. loaded=FALSE;
  50. cur_theat='T';
  51. m_hCache=NULL;
  52. m_hConquer=NULL;
  53. m_hIsoSnow=NULL;
  54. m_hIsoTemp=NULL;
  55. m_hLocal=NULL;
  56. m_hTemperat=NULL;
  57. m_hTibSun=NULL;
  58. m_hLangMD=NULL;
  59. m_pic_count=0;
  60. s_tiledata=NULL;
  61. t_tiledata=NULL;
  62. u_tiledata=NULL;
  63. s_tiledata_count=0;
  64. t_tiledata_count=0;
  65. u_tiledata_count=0;
  66. tiledata=NULL;
  67. tiledata_count=0;
  68. int i=0;
  69. for(i=0;i<101; i++)
  70. {
  71. m_hExpand[i].hExpand=NULL;
  72. }
  73. for(i=0;i<100; i++)
  74. {
  75. m_hECache[i]=NULL;
  76. }
  77. errstream << "CLoading::CLoading() called" << endl;
  78. errstream.flush();
  79. }
  80. void CLoading::DoDataExchange(CDataExchange* pDX)
  81. {
  82. CDialog::DoDataExchange(pDX);
  83. //{{AFX_DATA_MAP(CLoading)
  84. DDX_Control(pDX, IDC_VERSION, m_Version);
  85. DDX_Control(pDX, IDC_BUILTBY, m_BuiltBy);
  86. DDX_Control(pDX, IDC_CAP, m_cap);
  87. DDX_Control(pDX, IDC_PROGRESS1, m_progress);
  88. //}}AFX_DATA_MAP
  89. }
  90. BEGIN_MESSAGE_MAP(CLoading, CDialog)
  91. //{{AFX_MSG_MAP(CLoading)
  92. ON_WM_DESTROY()
  93. ON_WM_PAINT()
  94. //}}AFX_MSG_MAP
  95. END_MESSAGE_MAP()
  96. /////////////////////////////////////////////////////////////////////////////
  97. // message handlers CLoading
  98. BOOL bUseFirestorm=TRUE;
  99. void CLoading::Load()
  100. {
  101. auto startTime = std::chrono::steady_clock::now();
  102. CString artFile;
  103. // show a wait cursor
  104. SetCursor(LoadCursor(NULL, IDC_WAIT));
  105. // write a log
  106. errstream << "CLoading::Load() called" << std::endl << std::endl;
  107. errstream.flush();
  108. // initialize the FSunPackLib::XCC
  109. errstream << "Initializing FSunPackLib::XCC" << std::endl;
  110. errstream.flush();
  111. FSunPackLib::XCC_Initialize(TRUE);
  112. m_cap.SetWindowText(GetLanguageStringACP("LoadExtractStdMixFiles"));
  113. errstream << "Initializing mix files" << std::endl;
  114. errstream.flush();
  115. MEMORYSTATUS ms;
  116. ms.dwLength=sizeof(MEMORYSTATUS);
  117. GlobalMemoryStatus(&ms);
  118. int cs=ms.dwAvailPhys+ms.dwAvailPageFile;
  119. InitMixFiles();
  120. errstream << "Loading palettes" << std::endl << std::endl;
  121. errstream.flush();
  122. InitPalettes();
  123. // Load voxel normal tables
  124. InitVoxelNormalTables();
  125. // create a ini file containing some info XCC Mixer needs
  126. CreateINI();
  127. // set progress bar range to 0-2
  128. m_progress.SetRange(0,2);
  129. // rules.ini
  130. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadRules"));
  131. m_progress.SetPos(1);
  132. UpdateWindow();
  133. LoadTSIni("Rules.ini", &rules, FALSE);
  134. #ifdef TS_MODE
  135. if(bUseFirestorm)
  136. {
  137. // very special case, the types list don´t have any order according to the original rules!
  138. CIniFile fstorm;
  139. LoadTSIni("firestrm.ini", &fstorm, TRUE);
  140. int i;
  141. CString cuSection;
  142. cuSection="InfantryTypes";
  143. for(i=0;i<fstorm.sections[cuSection].values.size();i++)
  144. {
  145. // we simply add a FS to the index
  146. char c[50];
  147. itoa(i, c, 10);
  148. strcat(c, "FS");
  149. rules.sections[cuSection].values[c]=*fstorm.sections[cuSection].GetValue(i);
  150. rules.sections[cuSection].value_orig_pos[c]=rules.sections[cuSection].values.size()-1;
  151. }
  152. cuSection="VehicleTypes";
  153. for(i=0;i<fstorm.sections[cuSection].values.size();i++)
  154. {
  155. // we simply add a FS to the index
  156. char c[50];
  157. itoa(i, c, 10);
  158. strcat(c, "FS");
  159. rules.sections[cuSection].values[c]=*fstorm.sections[cuSection].GetValue(i);
  160. rules.sections[cuSection].value_orig_pos[c]=rules.sections[cuSection].values.size()-1;
  161. }
  162. cuSection="AircraftTypes";
  163. for(i=0;i<fstorm.sections[cuSection].values.size();i++)
  164. {
  165. // we simply add a FS to the index
  166. char c[50];
  167. itoa(i, c, 10);
  168. strcat(c, "FS");
  169. rules.sections[cuSection].values[c]=*fstorm.sections[cuSection].GetValue(i);
  170. rules.sections[cuSection].value_orig_pos[c]=rules.sections[cuSection].values.size()-1;
  171. }
  172. cuSection="BuildingTypes";
  173. for(i=0;i<fstorm.sections[cuSection].values.size();i++)
  174. {
  175. // we simply add a FS to the index
  176. char c[50];
  177. itoa(i, c, 10);
  178. strcat(c, "FS");
  179. rules.sections[cuSection].values[c]=*fstorm.sections[cuSection].GetValue(i);
  180. rules.sections[cuSection].value_orig_pos[c]=rules.sections[cuSection].values.size()-1;
  181. }
  182. cuSection="SuperWeaponTypes";
  183. for(i=0;i<fstorm.sections[cuSection].values.size();i++)
  184. {
  185. // we simply add a FS to the index
  186. char c[50];
  187. itoa(i, c, 10);
  188. strcat(c, "FS");
  189. rules.sections[cuSection].values[c]=*fstorm.sections[cuSection].GetValue(i);
  190. rules.sections[cuSection].value_orig_pos[c]=rules.sections[cuSection].values.size()-1;
  191. }
  192. for(i=0;i<fstorm.sections.size(); i++)
  193. {
  194. cuSection=*fstorm.GetSectionName(i);
  195. if(cuSection!="SuperWeaponTypes" && cuSection!="InfantryTypes" && cuSection!="VehicleTypes" && cuSection!="AircraftTypes" && cuSection!="BuildingTypes")
  196. {
  197. int e;
  198. for(e=0;e<fstorm.sections[cuSection].values.size();e++)
  199. {
  200. CString cuValue=*fstorm.sections[cuSection].GetValueName(e);
  201. rules.sections[cuSection].values[cuValue]=*fstorm.sections[cuSection].GetValue(e);
  202. }
  203. }
  204. }
  205. }
  206. #else
  207. if(bUseFirestorm && yuri_mode) // MW actually this is Yuri's Revenge
  208. {
  209. CIniFile rulesmd;
  210. LoadTSIni("rulesmd.ini", &rulesmd, TRUE);
  211. if(rulesmd.sections.size()>0)
  212. {
  213. rules=rulesmd;
  214. }
  215. }
  216. #endif
  217. m_progress.SetPos(2);
  218. //rules.DeleteLeadingSpaces(TRUE, TRUE);
  219. //rules.DeleteEndingSpaces(TRUE, TRUE);
  220. PrepareHouses();
  221. HackRules();
  222. UpdateWindow();
  223. // art.ini
  224. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadArt"));
  225. m_progress.SetPos(1);
  226. UpdateWindow();
  227. LoadTSIni("Art.ini", &art, FALSE);
  228. #ifdef TS_MODE
  229. if(bUseFirestorm) // LoadTSIni("ArtFs.ini", &art, TRUE);
  230. {
  231. CIniFile artfs;
  232. LoadTSIni("artfs.ini", &artfs, TRUE);
  233. // MW April 8th: bugfix... we erased Movies even if there was no new data!!!
  234. if(artfs.sections.size())
  235. {
  236. int i;
  237. CString cuSection;
  238. cuSection="Movies";
  239. art.sections.erase(cuSection);
  240. /*for(i=0;i<artfs.sections[cuSection].values.size();i++)
  241. {
  242. // we simply add a FS to the index
  243. char c[50];
  244. itoa(i, c, 10);
  245. strcat(c, "FS");
  246. art.sections[cuSection].values[c]=*artfs.sections[cuSection].GetValue(i);
  247. art.sections[cuSection].value_orig_pos[c]=art.sections[cuSection].values.size()-1;
  248. }*/
  249. for(i=0;i<artfs.sections.size(); i++)
  250. {
  251. cuSection=*artfs.GetSectionName(i);
  252. //if(cuSection!="Movies")
  253. {
  254. int e;
  255. for(e=0;e<artfs.sections[cuSection].values.size();e++)
  256. {
  257. CString cuValue=*artfs.sections[cuSection].GetValueName(e);
  258. art.sections[cuSection].values[cuValue]=*artfs.sections[cuSection].GetValue(e);
  259. if(cuSection=="Movies") art.sections[cuSection].value_orig_pos[cuValue]=artfs.sections[cuSection].GetValueOrigPos(e);
  260. }
  261. }
  262. }
  263. }
  264. }
  265. #else
  266. if(bUseFirestorm && yuri_mode) // Yuri's Revenge
  267. {
  268. CIniFile artmd;
  269. LoadTSIni("artmd.ini", &artmd, TRUE);
  270. if(artmd.sections.size()>0)
  271. {
  272. art.Clear();
  273. art=artmd;
  274. }
  275. }
  276. #endif
  277. m_progress.SetPos(2);
  278. //art.DeleteLeadingSpaces(TRUE, TRUE);
  279. //art.DeleteEndingSpaces(TRUE, TRUE);
  280. UpdateWindow();
  281. // tutorial.ini
  282. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadTutorial"));
  283. m_progress.SetPos(1);
  284. UpdateWindow();
  285. LoadTSIni("Tutorial.ini", &tutorial, FALSE);
  286. // sound.ini
  287. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadSound"));
  288. m_progress.SetPos(1);
  289. UpdateWindow();
  290. if(bUseFirestorm)
  291. {
  292. int b;
  293. for(b=99;b>0;b--)
  294. {
  295. char p[50];
  296. itoa(b, p, 10);
  297. CString name="Sound";
  298. if(strlen(p)<2) name+="0";
  299. name+=p;
  300. name+=".ini";
  301. LoadTSIni(name, &sound, FALSE);
  302. if(sound.sections.size()>0) break;
  303. }
  304. } else LoadTSIni("Sound01.ini", &sound, FALSE);
  305. if(sound.sections.size()==0) LoadTSIni("Sound.ini", &sound, FALSE);
  306. m_progress.SetPos(2);
  307. UpdateWindow();
  308. // eva.INI
  309. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadEva"));
  310. m_progress.SetPos(1);
  311. UpdateWindow();
  312. LoadTSIni("eva.ini", &eva, FALSE);
  313. m_progress.SetPos(2);
  314. UpdateWindow();
  315. // theme.INI
  316. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadTheme"));
  317. m_progress.SetPos(1);
  318. UpdateWindow();
  319. LoadTSIni("theme.ini", &theme, FALSE);
  320. m_progress.SetPos(2);
  321. UpdateWindow();
  322. // AI.INI
  323. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadAI"));
  324. m_progress.SetPos(1);
  325. UpdateWindow();
  326. LoadTSIni("Ai.ini", &ai, FALSE);
  327. #ifdef TS_MODE
  328. if(bUseFirestorm) LoadTSIni("aifs.ini", &ai, TRUE);;
  329. #else
  330. if(bUseFirestorm && yuri_mode) LoadTSIni("aimd.ini", &ai, TRUE); // YR
  331. #endif
  332. m_progress.SetPos(2);
  333. UpdateWindow();
  334. const BOOL preferLocalTheater = theApp.m_Options.bPreferLocalTheaterFiles ? TRUE : FALSE;
  335. // Temperat.INI
  336. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadTemperat"));
  337. m_progress.SetPos(1);
  338. UpdateWindow();
  339. LoadTSIni("Temperat.ini", &tiles_t, FALSE, preferLocalTheater);
  340. if(yuri_mode) LoadTSIni("TemperatMD.ini", &tiles_t, TRUE, preferLocalTheater);
  341. m_progress.SetPos(2);
  342. UpdateWindow();
  343. // Snow.INI
  344. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadSnow"));
  345. m_progress.SetPos(1);
  346. UpdateWindow();
  347. LoadTSIni("Snow.ini", &tiles_s, FALSE, preferLocalTheater);
  348. if(yuri_mode) LoadTSIni("SnowMD.ini", &tiles_s, TRUE, preferLocalTheater);
  349. m_progress.SetPos(2);
  350. UpdateWindow();
  351. // Urban.INI
  352. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadUrban"));
  353. m_progress.SetPos(1);
  354. UpdateWindow();
  355. LoadTSIni("Urban.ini", &tiles_u, FALSE, preferLocalTheater);
  356. if(yuri_mode) LoadTSIni("UrbanMD.ini", &tiles_u, TRUE, preferLocalTheater);
  357. m_progress.SetPos(2);
  358. UpdateWindow();
  359. if(yuri_mode)
  360. {
  361. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadUrbanN"));
  362. m_progress.SetPos(1);
  363. UpdateWindow();
  364. LoadTSIni("UrbanNMD.ini", &tiles_un, FALSE, preferLocalTheater);
  365. m_progress.SetPos(2);
  366. UpdateWindow();
  367. // MW FIX: MAKE URBAN RAMPS MORPHABLE:
  368. if(tiles_un.sections["TileSet0117"].FindName("Morphable")<0)
  369. tiles_un.sections["TileSet0117"].values["Morphable"]="true";
  370. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadLunar"));
  371. m_progress.SetPos(1);
  372. UpdateWindow();
  373. LoadTSIni("LunarMD.ini", &tiles_l, FALSE, preferLocalTheater);
  374. m_progress.SetPos(2);
  375. UpdateWindow();
  376. m_cap.SetWindowText(GetLanguageStringACP("LoadLoadDesert"));
  377. m_progress.SetPos(1);
  378. UpdateWindow();
  379. LoadTSIni("DesertMD.ini", &tiles_d, FALSE, preferLocalTheater);
  380. m_progress.SetPos(2);
  381. UpdateWindow();
  382. }
  383. // load Command & Conquer Rules.ini section names
  384. LoadStrings();
  385. // ok now directdraw
  386. m_cap.SetWindowText(GetLanguageStringACP("LoadInitDDraw"));
  387. m_progress.SetRange(0,4);
  388. InitDirectDraw();
  389. m_progress.SetPos(3);
  390. UpdateWindow();
  391. /*errstream << "Now calling InitPics()\n";
  392. errstream.flush();
  393. m_cap.SetWindowText(GetLanguageStringACP("LoadInitPics"));
  394. InitPics();
  395. errstream << "InitPics() finished\n\n\n";
  396. errstream.flush();*/
  397. auto delay = std::chrono::duration<double>(theApp.m_Options.fLoadScreenDelayInSeconds);
  398. if ((std::chrono::steady_clock::now() - startTime) < delay)
  399. {
  400. std::this_thread::sleep_until(startTime + delay);
  401. }
  402. DestroyWindow();
  403. }
  404. //
  405. // InitPics loads all graphics except terrain graphics!
  406. void CLoading::InitPics(CProgressCtrl* prog)
  407. {
  408. MEMORYSTATUS ms;
  409. ms.dwLength=sizeof(MEMORYSTATUS);
  410. GlobalMemoryStatus(&ms);
  411. int cs=ms.dwAvailPhys+ms.dwAvailPageFile;
  412. errstream << "InitPics() called. Available memory: " << cs << endl;
  413. errstream.flush();
  414. CalcPicCount();
  415. if(m_progress.m_hWnd!=NULL) m_progress.SetRange(0,m_pic_count/15+1);
  416. if(!theApp.m_Options.bDoNotLoadBMPs)
  417. {
  418. int k;
  419. CFileFind ff;
  420. CString bmps=(CString)AppPath+"\\pics2\\*.bmp";
  421. if(ff.FindFile(bmps))
  422. {
  423. BOOL lastFile=FALSE;
  424. for(k=0;k<m_bmp_count+1;k++)
  425. {
  426. if(ff.FindNextFile()==0)
  427. {
  428. if(lastFile) // we already were at last file, so that´s an error here!
  429. break;
  430. lastFile=TRUE;
  431. }
  432. try
  433. {
  434. pics[(LPCTSTR)ff.GetFileName()].pic = BitmapToSurface(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd, *BitmapFromFile(ff.GetFilePath())).Detach();
  435. DDSURFACEDESC2 desc;
  436. memset(&desc, 0, sizeof(DDSURFACEDESC2));
  437. desc.dwSize = sizeof(DDSURFACEDESC2);
  438. desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
  439. ((LPDIRECTDRAWSURFACE4)pics[(LPCTSTR)ff.GetFileName()].pic)->GetSurfaceDesc(&desc);
  440. pics[(LPCTSTR)ff.GetFileName()].wHeight = desc.dwHeight;
  441. pics[(LPCTSTR)ff.GetFileName()].wWidth = desc.dwWidth;
  442. pics[(LPCTSTR)ff.GetFileName()].wMaxWidth = desc.dwWidth;
  443. pics[(LPCTSTR)ff.GetFileName()].wMaxHeight = desc.dwHeight;
  444. pics[(LPCTSTR)ff.GetFileName()].bType = PICDATA_TYPE_BMP;
  445. FSunPackLib::SetColorKey(((LPDIRECTDRAWSURFACE4)(pics[(LPCTSTR)ff.GetFileName()].pic)), -1);
  446. }
  447. catch (const BitmapNotFound&)
  448. {
  449. }
  450. if(m_progress.m_hWnd!=NULL && k%15==0)
  451. {
  452. m_progress.SetPos(m_progress.GetPos()+1);
  453. UpdateWindow();
  454. }
  455. }
  456. }
  457. }
  458. DDSURFACEDESC2 desc;
  459. try {
  460. pics["SCROLLCURSOR"].pic = BitmapToSurface(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd, *BitmapFromResource(IDB_SCROLLCURSOR)).Detach();
  461. FSunPackLib::SetColorKey((LPDIRECTDRAWSURFACE4)pics["SCROLLCURSOR"].pic, -1);
  462. memset(&desc, 0, sizeof(DDSURFACEDESC2));
  463. desc.dwSize = sizeof(DDSURFACEDESC2);
  464. desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
  465. ((LPDIRECTDRAWSURFACE4)pics["SCROLLCURSOR"].pic)->GetSurfaceDesc(&desc);
  466. pics["SCROLLCURSOR"].wHeight = desc.dwHeight;
  467. pics["SCROLLCURSOR"].wWidth = desc.dwWidth;
  468. pics["SCROLLCURSOR"].bType = PICDATA_TYPE_BMP;
  469. }
  470. catch (const BitmapNotFound&)
  471. {
  472. }
  473. try {
  474. pics["CELLTAG"].pic = BitmapToSurface(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd, *BitmapFromResource(IDB_CELLTAG)).Detach();
  475. FSunPackLib::SetColorKey((LPDIRECTDRAWSURFACE4)pics["CELLTAG"].pic, CLR_INVALID);
  476. memset(&desc, 0, sizeof(DDSURFACEDESC2));
  477. desc.dwSize = sizeof(DDSURFACEDESC2);
  478. desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
  479. ((LPDIRECTDRAWSURFACE4)pics["CELLTAG"].pic)->GetSurfaceDesc(&desc);
  480. pics["CELLTAG"].wHeight = desc.dwHeight;
  481. pics["CELLTAG"].wWidth = desc.dwWidth;
  482. #ifdef RA2_MODE
  483. pics["CELLTAG"].x = -1;
  484. pics["CELLTAG"].y = 0;
  485. #else
  486. pics["CELLTAG"].x = -1;
  487. pics["CELLTAG"].y = -1;
  488. #endif
  489. pics["CELLTAG"].bType = PICDATA_TYPE_BMP;
  490. }
  491. catch (const BitmapNotFound&)
  492. {
  493. }
  494. try
  495. {
  496. pics["FLAG"].pic = BitmapToSurface(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd, *BitmapFromResource(IDB_FLAG)).Detach();
  497. FSunPackLib::SetColorKey((LPDIRECTDRAWSURFACE4)pics["FLAG"].pic, -1);
  498. memset(&desc, 0, sizeof(DDSURFACEDESC2));
  499. desc.dwSize = sizeof(DDSURFACEDESC2);
  500. desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
  501. ((LPDIRECTDRAWSURFACE4)pics["FLAG"].pic)->GetSurfaceDesc(&desc);
  502. pics["FLAG"].wHeight = desc.dwHeight;
  503. pics["FLAG"].wWidth = desc.dwWidth;
  504. pics["FLAG"].bType = PICDATA_TYPE_BMP;
  505. }
  506. catch (const BitmapNotFound&)
  507. {
  508. }
  509. // MW April 2nd, 2001
  510. // prepare 1x1 hidden tile replacement
  511. DDSURFACEDESC2 ddsd;
  512. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  513. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  514. ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
  515. ddsd.dwFlags=DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  516. ddsd.dwWidth=f_x;
  517. ddsd.dwHeight=f_y;
  518. LPDIRECTDRAWSURFACE4 srf=NULL;
  519. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd->CreateSurface(&ddsd, &srf, 0);
  520. pics["HTILE"].pic=srf;
  521. pics["HTILE"].wHeight=ddsd.dwHeight;
  522. pics["HTILE"].wWidth=ddsd.dwWidth;
  523. pics["HTILE"].bType=PICDATA_TYPE_BMP;
  524. HDC hDC;
  525. srf->GetDC(&hDC);
  526. HPEN p;
  527. int width=1;
  528. p=CreatePen(PS_DOT, 0, RGB(0,120,0));
  529. SelectObject(hDC,p);
  530. POINT p1, p2, p3, p4;
  531. p1.x=f_x/2;
  532. p1.y=0;
  533. p2.x=f_x/2+f_x/2;
  534. p2.y=f_y/2;
  535. p3.x=f_x/2-f_x/2+f_x/2-1;
  536. p3.y=f_y/2+f_y/2-1;
  537. p4.x=f_x/2+f_x/2-1;
  538. p4.y=f_y/2-1;
  539. SetBkMode(hDC, TRANSPARENT);
  540. MoveToEx(hDC, p1.x,p1.y-1,NULL);
  541. LineTo(hDC, p2.x+1,p2.y);
  542. LineTo(hDC, p3.x,p3.y+1);
  543. LineTo(hDC, p4.x-1, p4.y);
  544. LineTo(hDC, p1.x, p1.y-1);
  545. srf->ReleaseDC(hDC);
  546. DeleteObject(p);
  547. // new: Prepare building terrain information:
  548. int i;
  549. for(i=0;i<rules.sections["BuildingTypes"].values.size();i++)
  550. {
  551. PrepareUnitGraphic(*rules.sections["BuildingTypes"].GetValue(i));
  552. }
  553. ms.dwLength=sizeof(MEMORYSTATUS);
  554. GlobalMemoryStatus(&ms);
  555. cs=ms.dwAvailPhys+ms.dwAvailPageFile;
  556. int piccount=pics.size();
  557. errstream << "InitPics() finished and loaded " << piccount << " pictures. Available memory: " << cs << endl;
  558. errstream.flush();
  559. return;
  560. }
  561. BOOL CLoading::OnInitDialog()
  562. {
  563. CDialog::OnInitDialog();
  564. CString version;
  565. version.LoadString(IDS_VERSIONTEXT);
  566. #ifdef TS_MODE
  567. version.LoadString(IDS_VERSIONTEXTTS);
  568. #endif
  569. m_Version.SetWindowText(version);
  570. CString builder;
  571. builder.LoadString(IDS_BUILTBY);
  572. m_BuiltBy.SetWindowText(builder);
  573. SetDlgItemText(IDC_LBUILTBY, GetLanguageStringACP("LoadBuiltBy"));
  574. SetDlgItemText(IDC_LVERSION, GetLanguageStringACP("LoadVersion"));
  575. SetDlgItemText(IDC_CAP, GetLanguageStringACP("LoadLoading"));
  576. UpdateWindow();
  577. return TRUE;
  578. }
  579. // write a small ini file containing the FinalSun path and version (XCC needs this)
  580. // TODO: this was made for Win9x. It does not work anymore on modern operating systems if you don't run the editor as administrator (which you should not do)
  581. void CLoading::CreateINI()
  582. {
  583. wchar_t iniFile_[MAX_PATH];
  584. CIniFile path;
  585. CString version;
  586. GetWindowsDirectoryW(iniFile_, MAX_PATH);
  587. std::string iniFile = utf16ToUtf8(iniFile_);
  588. #ifdef RA2_MODE
  589. iniFile += "\\FinalAlert2.ini";
  590. #else
  591. iniFile += "\\FinalSun.ini";
  592. #endif
  593. #ifdef RA2_MODE
  594. CString app = "FinalAlert";
  595. #else
  596. CString app = "FinalSun";
  597. #endif
  598. version.LoadString(IDS_VERSION);
  599. path.sections[app].values["Path"]=AppPath;
  600. path.sections[app].values["Version"]=version;
  601. path.SaveFile(iniFile);
  602. }
  603. void CLoading::LoadTSIni(LPCTSTR lpFilename, CIniFile *lpIniFile, BOOL bIsExpansion, BOOL bCheckEditorDir)
  604. {
  605. errstream << "LoadTSIni(" << lpFilename << "," << lpIniFile << "," << bIsExpansion << ") called" << endl;
  606. errstream.flush();
  607. if (bCheckEditorDir) {
  608. // check if file is available in the editors application data folder
  609. if (DoesFileExist((u8AppDataPath + lpFilename).c_str()))
  610. {
  611. errstream << "File found in mission editor AppData directory (" << u8AppDataPath << ")" << endl;
  612. errstream.flush();
  613. if (!bIsExpansion)
  614. lpIniFile->LoadFile(u8AppDataPath + lpFilename, TRUE);
  615. else
  616. lpIniFile->InsertFile(u8AppDataPath + lpFilename, NULL, TRUE);
  617. return;
  618. }
  619. // check if file is available in the editors root folder
  620. if(DoesFileExist(CString(AppPath) + lpFilename))
  621. {
  622. errstream << "File found in Mission Editor directory (" << AppPath << ")" << endl;
  623. errstream.flush();
  624. if(!bIsExpansion)
  625. lpIniFile->LoadFile((CString)AppPath+lpFilename, TRUE);
  626. else
  627. lpIniFile->InsertFile((CString)AppPath+lpFilename, NULL, TRUE);
  628. return;
  629. }
  630. }
  631. if(theApp.m_Options.bSearchLikeTS)
  632. {
  633. // check if Rules.ini is available
  634. if(DoesFileExist((CString)TSPath+lpFilename))
  635. {
  636. errstream << "File found in TS directory (" << TSPath << ")" << endl;
  637. errstream.flush();
  638. if(!bIsExpansion)
  639. lpIniFile->LoadFile((CString)TSPath+lpFilename, TRUE);
  640. else
  641. lpIniFile->InsertFile((CString)TSPath+lpFilename, NULL, TRUE);
  642. return;
  643. }
  644. BOOL bExpandFound=FALSE;
  645. /*int i;
  646. for(i=1;i<101;i++)
  647. {
  648. if(m_hExpand[i].hExpand!=NULL)
  649. {
  650. if(FSunPackLib::XCC_ExtractFile(lpFilename, (CString)TSPath+(CString)"FinalSun"+lpFilename, m_hExpand[i].hExpand))
  651. {
  652. errstream << lpFilename << " found in expansion #" << i << endl;
  653. errstream.flush();
  654. //if(!bIsExpansion)
  655. // lpIniFile->InsertFile((CString)TSPath+(CString)"FinalSun"+lpFilename, NULL);
  656. //else
  657. lpIniFile->InsertFile((CString)TSPath+(CString)"FinalSun"+lpFilename, NULL, TRUE);
  658. DeleteFile((CString)TSPath+(CString)"FinalSun"+lpFilename);
  659. bExpandFound=TRUE;
  660. }
  661. }
  662. }*/
  663. HMIXFILE hMix=FindFileInMix(lpFilename);
  664. if(hMix)
  665. {
  666. if(FSunPackLib::XCC_ExtractFile(lpFilename, (CString)TSPath+(CString)"FinalSun"+lpFilename, hMix))
  667. {
  668. errstream << lpFilename << " found " << endl;
  669. errstream.flush();
  670. //if(!bIsExpansion)
  671. // lpIniFile->InsertFile((CString)TSPath+(CString)"FinalSun"+lpFilename, NULL);
  672. //else
  673. lpIniFile->InsertFile((CString)TSPath+(CString)"FinalSun"+lpFilename, NULL, TRUE);
  674. DeleteFile((CString)TSPath+(CString)"FinalSun"+lpFilename);
  675. bExpandFound=TRUE;
  676. }
  677. }
  678. if(!bIsExpansion && !bExpandFound)
  679. {
  680. // not found, go ahead if this is not a expansion only file...
  681. FSunPackLib::XCC_ExtractFile(lpFilename,(CString)TSPath+(CString)"FinalSun"+lpFilename, m_hLocal);
  682. lpIniFile->LoadFile((CString)TSPath+(CString)"FinalSun"+lpFilename, TRUE);
  683. DeleteFile((CString)TSPath+(CString)"FinalSun"+lpFilename);
  684. }
  685. }
  686. else if(bIsExpansion==FALSE)
  687. {
  688. FSunPackLib::XCC_ExtractFile(lpFilename,(CString)TSPath+(CString)"FinalSun"+lpFilename, m_hLocal);
  689. lpIniFile->LoadFile((CString)TSPath+(CString)"FinalSun"+lpFilename, TRUE);
  690. DeleteFile((CString)TSPath+(CString)"FinalSun"+lpFilename);
  691. return;
  692. }
  693. }
  694. void CLoading::InitSHPs(CProgressCtrl* prog)
  695. {
  696. MEMORYSTATUS ms;
  697. ms.dwLength=sizeof(MEMORYSTATUS);
  698. GlobalMemoryStatus(&ms);
  699. int cs=ms.dwAvailPhys+ms.dwAvailPageFile;
  700. errstream << "InitSHPs() called. Available memory: " << cs << endl;
  701. errstream.flush();
  702. int i;
  703. // overlay:
  704. if(!theApp.m_Options.bDoNotLoadOverlayGraphics)
  705. for(i=0;i<rules.sections["OverlayTypes"].values.size();i++)
  706. {
  707. LoadOverlayGraphic(*rules.sections["OverlayTypes"].GetValue(i), i);
  708. if(m_progress.m_hWnd!=NULL && i%15==0) {
  709. m_progress.SetPos(m_progress.GetPos()+1);
  710. UpdateWindow();
  711. }
  712. }
  713. if(!theApp.m_Options.bDoNotLoadVehicleGraphics)
  714. for(i=0;i<rules.sections["VehicleTypes"].values.size();i++)
  715. {
  716. LoadUnitGraphic(*rules.sections["VehicleTypes"].GetValue(i));
  717. if(m_progress.m_hWnd!=NULL && i%15==0) {
  718. m_progress.SetPos(m_progress.GetPos()+1);
  719. UpdateWindow();
  720. }
  721. }
  722. if(!theApp.m_Options.bDoNotLoadInfantryGraphics)
  723. for(i=0;i<rules.sections["InfantryTypes"].values.size();i++)
  724. {
  725. LoadUnitGraphic(*rules.sections["InfantryTypes"].GetValue(i));
  726. if(m_progress.m_hWnd!=NULL && i%15==0){
  727. m_progress.SetPos(m_progress.GetPos()+1);
  728. UpdateWindow();
  729. }
  730. }
  731. if(!theApp.m_Options.bDoNotLoadBuildingGraphics)
  732. for(i=0;i<rules.sections["BuildingTypes"].values.size();i++)
  733. {
  734. LoadUnitGraphic(*rules.sections["BuildingTypes"].GetValue(i));
  735. if(m_progress.m_hWnd!=NULL && i%15==0) {
  736. m_progress.SetPos(m_progress.GetPos()+1);
  737. UpdateWindow();
  738. }
  739. }
  740. if(!theApp.m_Options.bDoNotLoadAircraftGraphics)
  741. for(i=0;i<rules.sections["AircraftTypes"].values.size();i++)
  742. {
  743. LoadUnitGraphic(*rules.sections["AircraftTypes"].GetValue(i));
  744. if(m_progress.m_hWnd!=NULL && i%15==0) {
  745. m_progress.SetPos(m_progress.GetPos()+1);
  746. UpdateWindow();
  747. }
  748. }
  749. if(!theApp.m_Options.bDoNotLoadTreeGraphics)
  750. for(i=0;i<rules.sections["TerrainTypes"].values.size();i++)
  751. {
  752. LoadUnitGraphic(*rules.sections["TerrainTypes"].GetValue(i));
  753. if(m_progress.m_hWnd!=NULL && i%15==0)
  754. {
  755. m_progress.SetPos(m_progress.GetPos()+1);
  756. UpdateWindow();
  757. }
  758. }
  759. #ifdef SMUDGE_SUPP
  760. for(i=0;i<rules.sections["SmudgeTypes"].values.size();i++)
  761. {
  762. LoadUnitGraphic(*rules.sections["SmudgeTypes"].GetValue(i));
  763. /*if(m_progress.m_hWnd!=NULL && i%15==0)
  764. {
  765. m_progress.SetPos(m_progress.GetPos()+1);
  766. UpdateWindow();
  767. }*/
  768. }
  769. #endif
  770. }
  771. /*
  772. CLoading::LoadUnitGraphic();
  773. Matze:
  774. June 15th:
  775. - Added bib support, works fine.
  776. */
  777. #ifdef NOSURFACES_OBJECTS // palettized
  778. // blit util
  779. __forceinline void Blit_Pal(BYTE* dst, int x, int y, int dwidth, int dheight, BYTE* src, int swidth, int sheight)
  780. {
  781. if(src==NULL || dst==NULL) return;
  782. if(x+swidth<0 || y+sheight<0) return;
  783. if(x>=dwidth || y>=dheight) return;
  784. RECT blrect;
  785. RECT srcRect;
  786. srcRect.left=0;
  787. srcRect.top=0;
  788. srcRect.right=swidth;
  789. srcRect.bottom=sheight;
  790. blrect.left=x;
  791. if(blrect.left<0)
  792. {
  793. srcRect.left=1-blrect.left;
  794. blrect.left=1;
  795. }
  796. blrect.top=y;
  797. if(blrect.top<0)
  798. {
  799. srcRect.top=1-blrect.top;
  800. blrect.top=1;
  801. }
  802. blrect.right=(x+swidth);
  803. if(x+swidth>dwidth)
  804. {
  805. srcRect.right=swidth-((x+swidth)-dwidth);
  806. blrect.right=dwidth;
  807. }
  808. blrect.bottom=(y+sheight);
  809. if(y+sheight>dheight)
  810. {
  811. srcRect.bottom=sheight-((y+sheight)-dheight);
  812. blrect.bottom=dheight;
  813. }
  814. int i,e;
  815. for(i=srcRect.left;i<srcRect.right;i++)
  816. {
  817. for(e=srcRect.top;e<srcRect.bottom;e++)
  818. {
  819. BYTE& val=src[i+e*swidth];
  820. if(val)
  821. {
  822. BYTE* dest=dst+(blrect.left+i)+(blrect.top+e)*dwidth;
  823. *dest=val;
  824. }
  825. }
  826. }
  827. }
  828. __forceinline void Blit_PalD(BYTE* dst, RECT blrect, const BYTE* src, RECT srcRect, int swidth, int dwidth, int sheight, int dheight, const BYTE* const srcMask=nullptr)
  829. {
  830. if(src==NULL || dst==NULL) return;
  831. if(blrect.left+swidth<0 || blrect.top+sheight<0) return;
  832. if(blrect.left>=dwidth || blrect.top>=dheight) return;
  833. int x=blrect.left;
  834. int y=blrect.top;
  835. int i,e;
  836. for(i=srcRect.left;i<srcRect.right;i++)
  837. {
  838. for(e=srcRect.top;e<srcRect.bottom;e++)
  839. {
  840. auto pos = i + e * swidth;
  841. const BYTE& val=src[pos];
  842. if(blrect.left+i>0 && blrect.top+e>0 && blrect.left+i<dwidth && blrect.top+e<dheight)
  843. {
  844. if (srcMask)
  845. {
  846. if (srcMask[pos] == 0)
  847. continue;
  848. }
  849. else
  850. {
  851. if (val == 0)
  852. continue;
  853. }
  854. BYTE* dest=dst+(blrect.left+i)+(blrect.top+e)*dwidth;
  855. *dest=val;
  856. }
  857. }
  858. }
  859. }
  860. #ifdef TS_MODE
  861. const Vec3f lightDirection = Vec3f(1.0f, 0.0f, -1.0f).normalize();
  862. #else
  863. const Vec3f lightDirection = Vec3f(1.0f, 0.0f, -1.0f).normalize();
  864. #endif
  865. HTSPALETTE CLoading::GetIsoPalette(char theat)
  866. {
  867. HTSPALETTE isoPalette = m_hPalIsoTemp;
  868. switch (theat)
  869. {
  870. case 'T':
  871. case 'G':
  872. isoPalette = m_hPalIsoTemp;
  873. break;
  874. case 'A':
  875. isoPalette = m_hPalIsoSnow;
  876. break;
  877. case 'U':
  878. isoPalette = m_hPalIsoUrb;
  879. break;
  880. case 'N':
  881. isoPalette = m_hPalIsoUbn;
  882. break;
  883. case 'D':
  884. isoPalette = m_hPalIsoDes;
  885. break;
  886. case 'L':
  887. isoPalette = m_hPalIsoLun;
  888. break;
  889. }
  890. return isoPalette;
  891. }
  892. HTSPALETTE CLoading::GetUnitPalette(char theat)
  893. {
  894. HTSPALETTE isoPalette = m_hPalUnitTemp;
  895. switch (theat)
  896. {
  897. case 'T':
  898. case 'G':
  899. isoPalette = m_hPalUnitTemp;
  900. break;
  901. case 'A':
  902. isoPalette = m_hPalUnitSnow;
  903. break;
  904. case 'U':
  905. isoPalette = m_hPalUnitUrb;
  906. break;
  907. case 'N':
  908. isoPalette = m_hPalUnitUbn;
  909. break;
  910. case 'D':
  911. isoPalette = m_hPalUnitDes;
  912. break;
  913. case 'L':
  914. isoPalette = m_hPalUnitLun;
  915. break;
  916. }
  917. return isoPalette;
  918. }
  919. CString theatToSuffix(char theat)
  920. {
  921. if (theat == 'T') return ".tem";
  922. else if (theat == 'A') return ".sno";
  923. else if (theat == 'U') return ".urb";
  924. else if (theat == 'L') return ".lun";
  925. else if (theat == 'D') return ".des";
  926. else if (theat == 'N') return ".ubn";
  927. return ".tem";
  928. }
  929. char suffixToTheat(const CString& suffix)
  930. {
  931. if (suffix == ".tem")
  932. return 'T';
  933. else if (suffix == ".sno")
  934. return 'A';
  935. else if (suffix == ".urb")
  936. return 'U';
  937. else if (suffix == ".lun")
  938. return 'L';
  939. else if (suffix == ".des")
  940. return 'D';
  941. else if (suffix == ".ubn")
  942. return 'N';
  943. return 'T';
  944. }
  945. std::optional<FindShpResult> CLoading::FindUnitShp(const CString& image, char preferred_theat, const CIniFileSection& artSection)
  946. {
  947. if (image.IsEmpty())
  948. return std::nullopt;
  949. const char kTheatersToTry[] = { preferred_theat, 'G', 'T', 'A', 'U', 'N', 'D', 'L', 0};
  950. const CString kSuffixesToTry[] = { theatToSuffix(preferred_theat), ".tem", ".sno", ".urb", ".lun", ".des", ".ubn", ""};
  951. const char first = image.GetAt(0);
  952. const bool firstCharSupportsTheater = first == 'G' || first == 'N' || first == 'C' || first == 'Y';
  953. HTSPALETTE forcedPalette = 0;
  954. const auto& unitPalettePrefixes = g_data.sections["ForceUnitPalettePrefix"];
  955. if (unitPalettePrefixes.end() != std::find_if(unitPalettePrefixes.begin(), unitPalettePrefixes.end(), [&image](const auto& pair) {return image.Find(pair.second) == 0;}))
  956. {
  957. forcedPalette = GetUnitPalette(preferred_theat);
  958. }
  959. const auto& isoPalettePrefixes = g_data.sections["ForceIsoPalettePrefix"];
  960. if (isoPalettePrefixes.end() != std::find_if(isoPalettePrefixes.begin(), isoPalettePrefixes.end(), [&image](const auto& pair) {return image.Find(pair.second) == 0;}))
  961. {
  962. forcedPalette = GetIsoPalette(preferred_theat);
  963. }
  964. const bool isTheater = isTrue(artSection.GetValueByName("Theater"));
  965. const bool isNewTheater = isTrue(artSection.GetValueByName("NewTheater"));
  966. const bool terrainPalette = isTrue(artSection.GetValueByName("TerrainPalette"));
  967. auto unitOrIsoPalette = terrainPalette ? GetIsoPalette(preferred_theat) : GetUnitPalette(preferred_theat);
  968. HMIXFILE curMixFile = 0;
  969. CString curFilename = image + ".shp";
  970. TheaterChar curMixTheater = TheaterChar::None;
  971. char curTheater = 'G';
  972. CString curSuffix;
  973. // Phase 0: theater with .tem, .sno etc
  974. if (isTheater)
  975. {
  976. for (int t = 0; !(curSuffix = kSuffixesToTry[t]).IsEmpty(); ++t)
  977. {
  978. curFilename = image + curSuffix;
  979. curFilename.MakeLower();
  980. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  981. if (curMixFile)
  982. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(suffixToTheat(curSuffix)), forcedPalette ? forcedPalette : GetIsoPalette(suffixToTheat(curSuffix)));
  983. }
  984. }
  985. // Phase 1: if NewTheater is enabled and first character indicates support, try with real theater, then in order of kTheatersToTry
  986. // Otherwise,
  987. if (isNewTheater)
  988. {
  989. if (firstCharSupportsTheater)
  990. {
  991. /*curFilename.SetAt(1, preferred_theat);
  992. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  993. if (curMixFile)
  994. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(preferred_theat), GetUnitPalette(preferred_theat));*/
  995. for (int t = 0; curTheater=kTheatersToTry[t]; ++t)
  996. {
  997. curFilename.SetAt(1, curTheater);
  998. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  999. if (curMixFile)
  1000. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(curTheater), forcedPalette ? forcedPalette : unitOrIsoPalette);
  1001. }
  1002. }
  1003. }
  1004. // Phase 2: try again even if isNewTheater is not true but the first char signals it should support theaters
  1005. if (firstCharSupportsTheater)
  1006. {
  1007. /*curFilename.SetAt(1, preferred_theat);
  1008. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  1009. if (curMixFile)
  1010. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(preferred_theat), GetUnitPalette(preferred_theat));*/
  1011. for (int t = 0; curTheater = kTheatersToTry[t]; ++t)
  1012. {
  1013. curFilename.SetAt(1, curTheater);
  1014. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  1015. if (curMixFile)
  1016. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(curTheater), forcedPalette ? forcedPalette : unitOrIsoPalette);
  1017. }
  1018. }
  1019. // Phase 3: try unchanged filename
  1020. curFilename = image + ".shp";
  1021. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  1022. if (curMixFile)
  1023. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(preferred_theat), forcedPalette ? forcedPalette : unitOrIsoPalette);
  1024. // Phase 4: try lowercase and otherwise unchanged filename
  1025. curFilename = image + ".shp";
  1026. curFilename.MakeLower();
  1027. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  1028. if (curMixFile)
  1029. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(preferred_theat), forcedPalette ? forcedPalette : unitOrIsoPalette);
  1030. // Phase 5: try with .tem, .sno etc endings with preferred theater
  1031. for (int t = 0; !(curSuffix = kSuffixesToTry[t]).IsEmpty(); ++t)
  1032. {
  1033. curFilename = image + curSuffix;
  1034. curFilename.MakeLower();
  1035. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  1036. if (curMixFile)
  1037. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(suffixToTheat(curSuffix)), forcedPalette ? forcedPalette : GetIsoPalette(suffixToTheat(curSuffix)));
  1038. }
  1039. // Phase 6: try with theater in 2nd char even if first char does not indicate support
  1040. curFilename = image + ".shp";
  1041. for (int t = 0; curTheater = kTheatersToTry[t]; ++t)
  1042. {
  1043. curFilename.SetAt(1, curTheater);
  1044. curMixFile = FindFileInMix(curFilename, &curMixTheater);
  1045. if (curMixFile)
  1046. return FindShpResult(curMixFile, curMixTheater, curFilename, toTheaterChar(curTheater), forcedPalette ? forcedPalette : GetIsoPalette(curTheater));
  1047. }
  1048. return std::nullopt;
  1049. }
  1050. int lepton_to_screen_y(int leptons)
  1051. {
  1052. return leptons * f_y / 256;
  1053. }
  1054. BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype)
  1055. {
  1056. errstream << "Loading: " << lpUnittype << endl;
  1057. errstream.flush();
  1058. last_succeeded_operation=10;
  1059. CString _rules_image; // the image used
  1060. CString filename; // filename of the image
  1061. char theat=cur_theat; // standard theater char is t (Temperat). a is snow.
  1062. BOOL bAlwaysSetChar=FALSE; // second char is always theater, even if NewTheater not specified!
  1063. WORD wStep=1; // step is 1 for infantry, buildings, etc, and for shp vehicles it specifies the step rate between every direction
  1064. WORD wStartWalkFrame=0; // for examply cyborg reaper has another walk starting frame
  1065. int iTurretOffset=0; // used for centering y pos of turret (if existing) (for vehicles)
  1066. const BOOL bStructure=rules.sections["BuildingTypes"].FindValue(lpUnittype)>=0; // is this a structure?
  1067. const BOOL bVehicle = rules.sections["VehicleTypes"].FindValue(lpUnittype) >= 0; // is this a structure?
  1068. BOOL bPowerUp=rules.sections[lpUnittype].values["PowersUpBuilding"]!="";
  1069. CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview;
  1070. _rules_image=lpUnittype;
  1071. if(rules.sections[lpUnittype].values.find("Image")!=rules.sections[lpUnittype].values.end())
  1072. _rules_image=rules.sections[lpUnittype].values["Image"];
  1073. CString _art_image = _rules_image;
  1074. if(art.sections[_rules_image].values.find("Image")!=art.sections[_rules_image].values.end())
  1075. {
  1076. if(!isTrue(g_data.sections["IgnoreArtImage"].values[_rules_image]))
  1077. _art_image=art.sections[_rules_image].values["Image"];
  1078. }
  1079. const CString& image = _art_image;
  1080. const auto& rulesSection = rules.sections[lpUnittype];
  1081. const auto& artSection = art.sections[image];
  1082. if(!isTrue(art.sections[image].values["Voxel"])) // is it a shp graphic?
  1083. {
  1084. try
  1085. {
  1086. auto shp = FindUnitShp(image, cur_theat, artSection);
  1087. if (!shp)
  1088. {
  1089. errstream << "Building SHP in theater " << cur_theat << " not found: " << image << endl;
  1090. errstream.flush();
  1091. missingimages[lpUnittype] = TRUE;
  1092. return FALSE;
  1093. }
  1094. filename = shp->filename;
  1095. HTSPALETTE hPalette = shp->palette;
  1096. const auto hShpMix = shp->mixfile;
  1097. theat = static_cast<char>(shp->theat);
  1098. auto limited_to_theater = isTrue(artSection.GetValueByName("TerrainPalette")) ? shp->mixfile_theater : TheaterChar::None;
  1099. SHPHEADER head;
  1100. int superanim_1_zadjust=0;
  1101. int superanim_2_zadjust=0;
  1102. int superanim_3_zadjust=0;
  1103. int superanim_4_zadjust=0;
  1104. CString turretanim_name;
  1105. CString turretanim_filename;
  1106. CString barrelanim_filename;
  1107. BYTE* bib=NULL;
  1108. SHPHEADER bib_h;
  1109. BYTE* activeanim=NULL;
  1110. SHPHEADER activeanim_h;
  1111. BYTE* idleanim=NULL;
  1112. SHPHEADER idleanim_h;
  1113. BYTE* activeanim2=NULL;
  1114. SHPHEADER activeanim2_h;
  1115. BYTE* activeanim3=NULL;
  1116. SHPHEADER activeanim3_h;
  1117. BYTE* superanim1=NULL;
  1118. SHPHEADER superanim1_h;
  1119. BYTE* superanim2=NULL;
  1120. SHPHEADER superanim2_h;
  1121. BYTE* superanim3=NULL;
  1122. SHPHEADER superanim3_h;
  1123. BYTE* superanim4=NULL;
  1124. SHPHEADER superanim4_h;
  1125. BYTE* specialanim1=NULL;
  1126. SHPHEADER specialanim1_h;
  1127. BYTE* specialanim2=NULL;
  1128. SHPHEADER specialanim2_h;
  1129. BYTE* specialanim3=NULL;
  1130. SHPHEADER specialanim3_h;
  1131. BYTE* specialanim4=NULL;
  1132. SHPHEADER specialanim4_h;
  1133. BYTE** lpT=NULL;
  1134. SHPHEADER* lpT_h=NULL;
  1135. std::vector<BYTE> turretColors[8];
  1136. std::vector<BYTE> turretLighting[8];
  1137. std::vector<BYTE> vxlBarrelColors[8];
  1138. std::vector<BYTE> vxlBarrelLighting[8];
  1139. SHPHEADER turrets_h[8];
  1140. SHPIMAGEHEADER turretinfo[8];
  1141. SHPHEADER barrels_h[8];
  1142. SHPIMAGEHEADER barrelinfo[8];
  1143. if(hShpMix>0)
  1144. {
  1145. std::string shp_mixfile;
  1146. if (FSunPackLib::XCC_GetMixName(hShpMix, shp_mixfile))
  1147. {
  1148. errstream << (LPCTSTR)filename << " found ";
  1149. errstream << " in " << shp_mixfile << endl;
  1150. errstream.flush();
  1151. }
  1152. //hShpMix=20;
  1153. if(rules.sections[lpUnittype].values["Bib"]!="no") // seems to be ignored by TS, art.ini overwrites???
  1154. {
  1155. LoadBuildingSubGraphic("BibShape", artSection, bAlwaysSetChar, theat, hShpMix, bib_h, bib);
  1156. }
  1157. LoadBuildingSubGraphic("ActiveAnim", artSection, bAlwaysSetChar, theat, hShpMix, activeanim_h, activeanim);
  1158. LoadBuildingSubGraphic("IdleAnim", artSection, bAlwaysSetChar, theat, hShpMix, idleanim_h, idleanim);
  1159. LoadBuildingSubGraphic("ActiveAnim2", artSection, bAlwaysSetChar, theat, hShpMix, activeanim2_h, activeanim2);
  1160. LoadBuildingSubGraphic("ActiveAnim3", artSection, bAlwaysSetChar, theat, hShpMix, activeanim3_h, activeanim3);
  1161. if (!isTrue(g_data.sections["IgnoreSuperAnim1"].values[image]))
  1162. LoadBuildingSubGraphic("SuperAnim", artSection, bAlwaysSetChar, theat, hShpMix, superanim1_h, superanim1);
  1163. if (!isTrue(g_data.sections["IgnoreSuperAnim2"].values[image]))
  1164. LoadBuildingSubGraphic("SuperAnimTwo", artSection, bAlwaysSetChar, theat, hShpMix, superanim2_h, superanim2);
  1165. if (!isTrue(g_data.sections["IgnoreSuperAnim3"].values[image]))
  1166. LoadBuildingSubGraphic("SuperAnimThree", artSection, bAlwaysSetChar, theat, hShpMix, superanim3_h, superanim3);
  1167. if (!isTrue(g_data.sections["IgnoreSuperAnim4"].values[image]))
  1168. LoadBuildingSubGraphic("SuperAnimFour", artSection, bAlwaysSetChar, theat, hShpMix, superanim4_h, superanim4);
  1169. LoadBuildingSubGraphic("SpecialAnim", artSection, bAlwaysSetChar, theat, hShpMix, specialanim1_h, specialanim1);
  1170. LoadBuildingSubGraphic("SpecialAnimTwo", artSection, bAlwaysSetChar, theat, hShpMix, specialanim2_h, specialanim2);
  1171. LoadBuildingSubGraphic("SpecialAnimThree", artSection, bAlwaysSetChar, theat, hShpMix, specialanim3_h, specialanim3);
  1172. LoadBuildingSubGraphic("SpecialAnimFour", artSection, bAlwaysSetChar, theat, hShpMix, specialanim4_h, specialanim4);
  1173. BOOL bVoxelTurret = FALSE;
  1174. BOOL bVoxelBarrel = FALSE;
  1175. FSunPackLib::VoxelNormalClass vnc = FSunPackLib::VoxelNormalClass::Unknown;
  1176. if (isTrue(rules.sections[image].values["Turret"]))
  1177. {
  1178. turretanim_name = rules.sections[image].values["TurretAnim"];
  1179. auto vxl_turretanim_filename = turretanim_name.IsEmpty() ? image + "tur.vxl" : turretanim_name + ".vxl";
  1180. auto vxl_barrelanim_filename = image + "barl.vxl";
  1181. if (art.sections[turretanim_name].values.find("Image") != art.sections[turretanim_name].values.end())
  1182. vxl_turretanim_filename = art.sections[turretanim_name].values["Image"] + ".vxl";
  1183. if (bStructure && turretanim_name.GetLength() > 0 && isFalse(rules.sections[image].values["TurretAnimIsVoxel"]))
  1184. {
  1185. turretanim_filename = turretanim_name + ".shp";
  1186. if (art.sections[turretanim_name].values.find("Image") != art.sections[turretanim_name].values.end()) turretanim_filename = art.sections[turretanim_name].values["Image"] + ".shp";
  1187. if (isTrue(artSection.GetValueByName("NewTheater")))
  1188. {
  1189. auto tmp = turretanim_filename;
  1190. tmp.SetAt(1, theat);
  1191. if (FSunPackLib::XCC_DoesFileExist(tmp, hShpMix))
  1192. turretanim_filename = tmp;
  1193. }
  1194. FSunPackLib::SetCurrentSHP(turretanim_filename, hShpMix);
  1195. FSunPackLib::XCC_GetSHPHeader(&head);
  1196. int iStartTurret = 0;
  1197. const WORD wAnimCount = 4; // anims between each "normal" direction, seems to be hardcoded
  1198. int i;
  1199. for (i = 0;i < 8;i++)
  1200. {
  1201. if (iStartTurret + i * wAnimCount < head.c_images)
  1202. {
  1203. FSunPackLib::XCC_GetSHPImageHeader(iStartTurret + i * wAnimCount, &turretinfo[i]);
  1204. FSunPackLib::XCC_GetSHPHeader(&turrets_h[i]);
  1205. FSunPackLib::LoadSHPImage(iStartTurret + i * wAnimCount, turretColors[i]);
  1206. turretLighting[i].clear();
  1207. }
  1208. }
  1209. }
  1210. else if (
  1211. (bStructure && turretanim_name.GetLength() > 0 && isTrue(rules.sections[image].values["TurretAnimIsVoxel"]))
  1212. || (!bStructure && (FindFileInMix(vxl_turretanim_filename) || FindFileInMix(vxl_barrelanim_filename)))
  1213. )
  1214. {
  1215. turretanim_filename = vxl_turretanim_filename;
  1216. barrelanim_filename = vxl_barrelanim_filename;
  1217. HMIXFILE hVXL = FindFileInMix(vxl_turretanim_filename);
  1218. HMIXFILE hBarl = FindFileInMix(vxl_barrelanim_filename);
  1219. if (artSection.values.find("TurretOffset") != art.sections[image].values.end())
  1220. iTurretOffset = atoi(art.sections[image].values["TurretOffset"]);
  1221. Vec3f turretModelOffset(iTurretOffset / 6.0f, 0.0f, 0.0f);
  1222. if (hVXL)
  1223. {
  1224. bVoxelTurret = TRUE;
  1225. if (
  1226. FSunPackLib::SetCurrentVXL(turretanim_filename, hVXL)
  1227. )
  1228. {
  1229. // we assume the voxel normal class is always the same for the combined voxels
  1230. FSunPackLib::GetVXLSectionInfo(0, vnc);
  1231. int i;
  1232. for (i = 0;i < 8;i++)
  1233. {
  1234. float r_x, r_y, r_z;
  1235. const int dir = bVehicle ? ((i + 1) % 8) : i;
  1236. r_x = 300;
  1237. r_y = 0;
  1238. r_z = 45 * dir + 90;
  1239. // convert
  1240. const double pi = 3.141592654;
  1241. const Vec3f rotation(r_x / 180.0f * pi, r_y / 180.0f * pi, r_z / 180.0f * pi);
  1242. RECT r;
  1243. int center_x, center_y;
  1244. if (!
  1245. FSunPackLib::LoadVXLImage(*m_voxelNormalTables, lightDirection, rotation, turretModelOffset, turretColors[i], turretLighting[i], &center_x, &center_y, 0, 0, 0, 0, 0, &r)
  1246. )
  1247. {
  1248. }
  1249. else
  1250. {
  1251. turrets_h[i].cx = r.right - r.left;
  1252. turrets_h[i].cy = r.bottom - r.top;
  1253. turretinfo[i].x = center_x;
  1254. turretinfo[i].y = center_y;
  1255. turretinfo[i].cx = r.right - r.left;
  1256. turretinfo[i].cy = r.bottom - r.top;
  1257. }
  1258. }
  1259. }
  1260. }
  1261. if (hBarl)
  1262. {
  1263. bVoxelBarrel = TRUE;
  1264. if (
  1265. FSunPackLib::SetCurrentVXL(barrelanim_filename, hBarl)
  1266. )
  1267. {
  1268. // we assume the voxel normal class is always the same for the combined voxels
  1269. FSunPackLib::GetVXLSectionInfo(0, vnc);
  1270. int i;
  1271. for (i = 0;i < 8;i++)
  1272. {
  1273. float r_x, r_y, r_z;
  1274. const int dir = bVehicle ? ((i + 1) % 8) : i;
  1275. r_x = 300;
  1276. r_y = 0;
  1277. r_z = 45 * dir + 90;
  1278. // convert
  1279. const double pi = 3.141592654;
  1280. const Vec3f rotation(r_x / 180.0f * pi, r_y / 180.0f * pi, r_z / 180.0f * pi);
  1281. RECT r;
  1282. int center_x, center_y;
  1283. if (!
  1284. FSunPackLib::LoadVXLImage(*m_voxelNormalTables, lightDirection, rotation, turretModelOffset, vxlBarrelColors[i], vxlBarrelLighting[i], &center_x, &center_y, atoi(rules.sections[image].values["TurretAnimZAdjust"]), 0, 0, 0, 0, &r)
  1285. )
  1286. {
  1287. }
  1288. else
  1289. {
  1290. barrels_h[i].cx = r.right - r.left;
  1291. barrels_h[i].cy = r.bottom - r.top;
  1292. barrelinfo[i].x = center_x;
  1293. barrelinfo[i].y = center_y;
  1294. barrelinfo[i].cx = r.right - r.left;
  1295. barrelinfo[i].cy = r.bottom - r.top;
  1296. }
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }
  1302. if(art.sections[image].values.find("WalkFrames")!=art.sections[image].values.end())
  1303. wStep=atoi(art.sections[image].values["WalkFrames"]);
  1304. if(art.sections[image].values.find("StartWalkFrame")!=art.sections[image].values.end())
  1305. wStartWalkFrame=atoi(art.sections[image].values["StartWalkFrame"]);
  1306. if(art.sections[image].values["Palette"]=="lib")
  1307. hPalette=m_hPalLib;
  1308. BOOL bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix);
  1309. if(
  1310. !bSuccess
  1311. )
  1312. {
  1313. filename=image+".sno";
  1314. if(cur_theat=='T' || cur_theat=='U' /* || cur_theat=='N' ? */) hPalette=m_hPalIsoTemp;
  1315. HMIXFILE hShpMix=FindFileInMix(filename);
  1316. bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix);
  1317. if(!bSuccess)
  1318. {
  1319. missingimages[lpUnittype]=TRUE;
  1320. }
  1321. }
  1322. if(bSuccess)
  1323. {
  1324. FSunPackLib::XCC_GetSHPHeader(&head);
  1325. int i;
  1326. int maxPics=head.c_images;
  1327. if(maxPics>8) maxPics=8; // we only need 8 pictures for every direction!
  1328. if(bStructure && !bPowerUp && !isTrue(rules.sections[image].values["Turret"])) maxPics=1;
  1329. if(bVoxelTurret) maxPics=8;
  1330. if(!bStructure && rules.sections[image].values["Turret"]=="yes")
  1331. {
  1332. int iStartTurret=wStartWalkFrame+8*wStep;
  1333. const WORD wAnimCount=4; // anims between each "normal" direction, seems to be hardcoded
  1334. int i;
  1335. for(i=0;i<8;i++)
  1336. {
  1337. if(iStartTurret+i*wAnimCount<head.c_images)
  1338. {
  1339. FSunPackLib::XCC_GetSHPImageHeader(iStartTurret+i*wAnimCount, &turretinfo[i]);
  1340. FSunPackLib::XCC_GetSHPHeader(&turrets_h[i]);
  1341. FSunPackLib::LoadSHPImage(iStartTurret+i*wAnimCount, turretColors[i]);
  1342. }
  1343. }
  1344. }
  1345. // create an array of pointers to directdraw surfaces
  1346. lpT=new(BYTE*[maxPics]);
  1347. memset(lpT, 0, sizeof(BYTE)*maxPics);
  1348. std::vector<std::vector<BYTE>> lighting(maxPics);
  1349. std::vector<SHPIMAGEHEADER> shp_image_headers(maxPics);
  1350. if(bVoxelTurret && bStructure)
  1351. {
  1352. for(i=0;i<maxPics; i++)
  1353. {
  1354. FSunPackLib::LoadSHPImage(0, 1, &lpT[i]);
  1355. FSunPackLib::XCC_GetSHPImageHeader(0, &shp_image_headers[i]);
  1356. }
  1357. }
  1358. else if(wStep==1 && (rules.sections[lpUnittype].values["PowersUpBuilding"].GetLength()==0 || !isTrue(rules.sections[lpUnittype].values["Turret"])))
  1359. { // standard case...
  1360. FSunPackLib::LoadSHPImage(wStartWalkFrame, maxPics, lpT);
  1361. for (int i = 0; i < maxPics; ++i)
  1362. FSunPackLib::XCC_GetSHPImageHeader(wStartWalkFrame + i, &shp_image_headers[i]);
  1363. }
  1364. else if(rules.sections[lpUnittype].values["PowersUpBuilding"].GetLength()!=0 && isTrue(rules.sections[lpUnittype].values["Turret"]))
  1365. { // a "real" turret (vulcan cannon, etc...)
  1366. for(i=0;i<maxPics; i++)
  1367. {
  1368. FSunPackLib::LoadSHPImage(i*4, 1, &lpT[i]);
  1369. FSunPackLib::XCC_GetSHPImageHeader(i*4, &shp_image_headers[i]);
  1370. }
  1371. }
  1372. else
  1373. {
  1374. // walk frames used
  1375. for(i=0;i<maxPics; i++)
  1376. {
  1377. const int dir = bVehicle ? ((i + 1) % 8) : i;
  1378. const int pic_in_file = dir * wStep + wStartWalkFrame;
  1379. FSunPackLib::LoadSHPImage(pic_in_file, 1, &lpT[i]);
  1380. FSunPackLib::XCC_GetSHPImageHeader(pic_in_file, &shp_image_headers[i]);
  1381. }
  1382. }
  1383. for(i=0; i<maxPics; i++)
  1384. {
  1385. int pic_in_file=i;
  1386. if(bStructure && bVoxelTurret) pic_in_file=0;
  1387. SHPIMAGEHEADER imghead = shp_image_headers[i];
  1388. //FSunPackLib::XCC_GetSHPImageHeader(pic_in_file, &imghead);
  1389. if(bib!=NULL)
  1390. {
  1391. DDBLTFX fx;
  1392. memset(&fx, 0, sizeof(DDBLTFX));
  1393. fx.dwSize=sizeof(DDBLTFX);
  1394. //lpT[i]->Blt(NULL, bib, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1395. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, bib, bib_h.cx, bib_h.cy);
  1396. imghead.cx=head.cx-imghead.x; // update size of main graphic
  1397. imghead.cy=head.cy-imghead.y;
  1398. }
  1399. if(activeanim!=NULL)
  1400. {
  1401. DDBLTFX fx;
  1402. memset(&fx, 0, sizeof(DDBLTFX));
  1403. fx.dwSize=sizeof(DDBLTFX);
  1404. //lpT[i]->Blt(NULL, activeanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1405. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, activeanim, activeanim_h.cx, activeanim_h.cy);
  1406. }
  1407. if(idleanim!=NULL)
  1408. {
  1409. DDBLTFX fx;
  1410. memset(&fx, 0, sizeof(DDBLTFX));
  1411. fx.dwSize=sizeof(DDBLTFX);
  1412. //lpT[i]->Blt(NULL, idleanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1413. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, idleanim, idleanim_h.cx, idleanim_h.cy);
  1414. }
  1415. if(activeanim2!=NULL)
  1416. {
  1417. DDBLTFX fx;
  1418. memset(&fx, 0, sizeof(DDBLTFX));
  1419. fx.dwSize=sizeof(DDBLTFX);
  1420. //lpT[i]->Blt(NULL, activeanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1421. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, activeanim2, activeanim2_h.cx, activeanim2_h.cy);
  1422. }
  1423. if(activeanim3!=NULL)
  1424. {
  1425. DDBLTFX fx;
  1426. memset(&fx, 0, sizeof(DDBLTFX));
  1427. fx.dwSize=sizeof(DDBLTFX);
  1428. //lpT[i]->Blt(NULL, activeanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1429. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, activeanim3, activeanim3_h.cx, activeanim3_h.cy);
  1430. }
  1431. if(superanim1!=NULL)
  1432. {
  1433. DDBLTFX fx;
  1434. memset(&fx, 0, sizeof(DDBLTFX));
  1435. fx.dwSize=sizeof(DDBLTFX);
  1436. //lpT[i]->Blt(NULL, superanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1437. Blit_Pal(lpT[i], 0, superanim_1_zadjust, head.cx, head.cy, superanim1, superanim1_h.cx, superanim1_h.cy);
  1438. }
  1439. if(superanim2!=NULL)
  1440. {
  1441. DDBLTFX fx;
  1442. memset(&fx, 0, sizeof(DDBLTFX));
  1443. fx.dwSize=sizeof(DDBLTFX);
  1444. //lpT[i]->Blt(NULL, superanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1445. Blit_Pal(lpT[i], 0, superanim_2_zadjust, head.cx, head.cy, superanim2, superanim2_h.cx, superanim2_h.cy);
  1446. }
  1447. if(superanim3!=NULL)
  1448. {
  1449. DDBLTFX fx;
  1450. memset(&fx, 0, sizeof(DDBLTFX));
  1451. fx.dwSize=sizeof(DDBLTFX);
  1452. //lpT[i]->Blt(NULL, superanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1453. Blit_Pal(lpT[i], 0, superanim_3_zadjust, head.cx, head.cy, superanim3, superanim3_h.cx, superanim3_h.cy);
  1454. }
  1455. if(superanim4!=NULL && strcmp(lpUnittype, "YAGNTC")!=NULL)
  1456. {
  1457. DDBLTFX fx;
  1458. memset(&fx, 0, sizeof(DDBLTFX));
  1459. fx.dwSize=sizeof(DDBLTFX);
  1460. //lpT[i]->Blt(NULL, superanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1461. Blit_Pal(lpT[i], 0, superanim_4_zadjust, head.cx, head.cy, superanim4, superanim4_h.cx, superanim4_h.cy);
  1462. }
  1463. if(specialanim1!=NULL)
  1464. {
  1465. DDBLTFX fx;
  1466. memset(&fx, 0, sizeof(DDBLTFX));
  1467. fx.dwSize=sizeof(DDBLTFX);
  1468. //lpT[i]->Blt(NULL, specialanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1469. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, specialanim1, specialanim1_h.cx, specialanim1_h.cy);
  1470. }
  1471. if(specialanim2!=NULL)
  1472. {
  1473. DDBLTFX fx;
  1474. memset(&fx, 0, sizeof(DDBLTFX));
  1475. fx.dwSize=sizeof(DDBLTFX);
  1476. //lpT[i]->Blt(NULL, specialanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1477. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, specialanim2, specialanim2_h.cx, specialanim2_h.cy);
  1478. }
  1479. if(specialanim3!=NULL)
  1480. {
  1481. DDBLTFX fx;
  1482. memset(&fx, 0, sizeof(DDBLTFX));
  1483. fx.dwSize=sizeof(DDBLTFX);
  1484. //lpT[i]->Blt(NULL, specialanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1485. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, specialanim3, specialanim3_h.cx, specialanim3_h.cy);
  1486. }
  1487. if(specialanim4!=NULL)
  1488. {
  1489. DDBLTFX fx;
  1490. memset(&fx, 0, sizeof(DDBLTFX));
  1491. fx.dwSize=sizeof(DDBLTFX);
  1492. //lpT[i]->Blt(NULL, specialanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  1493. Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, specialanim4, specialanim4_h.cx, specialanim4_h.cy);
  1494. }
  1495. if (!vxlBarrelLighting[i].empty() || !turretLighting[i].empty())
  1496. lighting[i].resize(head.cx * head.cy, 46); // value needs to lead to 1.0 lighting
  1497. // barrels hidden behind turret:
  1498. if(!vxlBarrelColors[i].empty() && (i == 1 || i == 0 || i == 7))
  1499. {
  1500. DDSURFACEDESC2 ddsd;
  1501. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  1502. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  1503. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  1504. ddsd.dwWidth = barrels_h[i].cx;
  1505. ddsd.dwHeight = barrels_h[i].cy;
  1506. int XMover, YMover;
  1507. char c[50];
  1508. itoa(i, c, 10);
  1509. #ifdef RA2_MODE
  1510. XMover = atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + "X"]);
  1511. YMover = atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + "Y"]);
  1512. XMover += atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + (CString)"X" + c]);
  1513. YMover += atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + (CString)"Y" + c]);
  1514. #else
  1515. XMover = atoi(g_data.sections["BuildingVoxelBarrels"].values[(CString)lpUnittype + "X"]);
  1516. YMover = atoi(g_data.sections["BuildingVoxelBarrels"].values[(CString)lpUnittype + "Y"]);
  1517. #endif
  1518. RECT srcRect, destRect;
  1519. int mx = head.cx / 2 + atoi(rules.sections[image].values["TurretAnimX"]) - barrelinfo[i].x;
  1520. int my = head.cy / 2 + atoi(rules.sections[image].values["TurretAnimY"]) - barrelinfo[i].y;
  1521. srcRect.top = 0;
  1522. srcRect.left = 0;
  1523. srcRect.right = ddsd.dwWidth;
  1524. srcRect.bottom = ddsd.dwHeight;
  1525. destRect.top = YMover + my;
  1526. destRect.left = XMover + mx;
  1527. destRect.right = destRect.left + ddsd.dwWidth;
  1528. destRect.bottom = destRect.top + ddsd.dwHeight;
  1529. errstream << "vxl barrel: " << i << " size: " << ddsd.dwWidth << " " << ddsd.dwHeight << " at " << destRect.left << " " << destRect.top << endl;
  1530. errstream.flush();
  1531. Blit_PalD(lpT[i], destRect, vxlBarrelColors[i].data(), srcRect, ddsd.dwWidth, head.cx, ddsd.dwHeight, head.cy);
  1532. Blit_PalD(lighting[i].data(), destRect, vxlBarrelLighting[i].data(), srcRect, ddsd.dwWidth, head.cx, ddsd.dwHeight, head.cy, vxlBarrelColors[i].data());
  1533. }
  1534. if(!turretColors[i].empty())
  1535. {
  1536. DDSURFACEDESC2 ddsd;
  1537. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  1538. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  1539. ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  1540. //turrets[i]->GetSurfaceDesc(&ddsd);
  1541. // replace DX code:
  1542. ddsd.dwWidth=turrets_h[i].cx;
  1543. ddsd.dwHeight=turrets_h[i].cy;
  1544. int XMover, YMover;
  1545. char c[50];
  1546. itoa(i, c, 10);
  1547. #ifdef RA2_MODE
  1548. XMover = atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype + "X"]);
  1549. YMover = atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype + "Y"]);
  1550. XMover += atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype + (CString)"X" + c]);
  1551. YMover += atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype + (CString)"Y" + c]);
  1552. #else
  1553. XMover = atoi(g_data.sections["BuildingVoxelTurrets"].values[(CString)lpUnittype + "X"]);
  1554. YMover = atoi(g_data.sections["BuildingVoxelTurrets"].values[(CString)lpUnittype + "Y"]);
  1555. #endif
  1556. RECT srcRect, destRect;
  1557. if (bVoxelTurret)
  1558. {
  1559. int mx = head.cx / 2 + atoi(rules.sections[image].values["TurretAnimX"]) - turretinfo[i].x;
  1560. int my = head.cy / 2 + atoi(rules.sections[image].values["TurretAnimY"]) - turretinfo[i].y;
  1561. srcRect.top=0;
  1562. srcRect.left=0;
  1563. srcRect.right=ddsd.dwWidth;
  1564. srcRect.bottom=ddsd.dwHeight;
  1565. destRect.top=YMover+my;
  1566. destRect.left=XMover+mx;
  1567. destRect.right=destRect.left+ddsd.dwWidth;;
  1568. destRect.bottom=destRect.top+ddsd.dwHeight;
  1569. }
  1570. else // !bVoxelTurret
  1571. {
  1572. int mx = atoi(rules.sections[image].values["TurretAnimX"]);
  1573. int my = atoi(rules.sections[image].values["TurretAnimY"]);//+atoi(rules.sections[image].values["barrelAnimZAdjust"]);
  1574. srcRect.top = 0;
  1575. srcRect.left = 0;
  1576. srcRect.right = turrets_h[i].cx;
  1577. srcRect.bottom = turrets_h[i].cy;
  1578. destRect.top = YMover + my;
  1579. destRect.left = XMover + mx;
  1580. destRect.right = destRect.left + srcRect.right;
  1581. destRect.bottom = destRect.top + srcRect.bottom;
  1582. }
  1583. errstream << "vxl turret: " << i << " size: " << ddsd.dwWidth << " " << ddsd.dwHeight << " at " << destRect.left << " " << destRect.top << endl;
  1584. errstream.flush();
  1585. Blit_PalD(lpT[i], destRect, turretColors[i].data(), srcRect, ddsd.dwWidth, head.cx, ddsd.dwHeight, head.cy);
  1586. Blit_PalD(lighting[i].data(), destRect, turretLighting[i].data(), srcRect, ddsd.dwWidth, head.cx, ddsd.dwHeight, head.cy, turretColors[i].data());
  1587. }
  1588. // barrels in front of turret
  1589. if(!vxlBarrelColors[i].empty() && i!=1 && i!=0 && i!=7)
  1590. {
  1591. DDSURFACEDESC2 ddsd;
  1592. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  1593. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  1594. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  1595. ddsd.dwWidth = barrels_h[i].cx;
  1596. ddsd.dwHeight = barrels_h[i].cy;
  1597. int XMover, YMover;
  1598. char c[50];
  1599. itoa(i, c, 10);
  1600. #ifdef RA2_MODE
  1601. XMover = atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + "X"]);
  1602. YMover = atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + "Y"]);
  1603. XMover += atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + (CString)"X" + c]);
  1604. YMover += atoi(g_data.sections["BuildingVoxelBarrelsRA2"].values[(CString)lpUnittype + (CString)"Y" + c]);
  1605. #else
  1606. XMover = atoi(g_data.sections["BuildingVoxelBarrels"].values[(CString)lpUnittype + "X"]);
  1607. YMover = atoi(g_data.sections["BuildingVoxelBarrels"].values[(CString)lpUnittype + "Y"]);
  1608. #endif
  1609. RECT srcRect, destRect;
  1610. int mx = head.cx / 2 + atoi(rules.sections[image].values["TurretAnimX"]) - barrelinfo[i].x;
  1611. int my = head.cy / 2 + atoi(rules.sections[image].values["TurretAnimY"]) - barrelinfo[i].y;
  1612. srcRect.top = 0;
  1613. srcRect.left = 0;
  1614. srcRect.right = ddsd.dwWidth;
  1615. srcRect.bottom = ddsd.dwHeight;
  1616. destRect.top = YMover + my;
  1617. destRect.left = XMover + mx;
  1618. destRect.right = destRect.left + ddsd.dwWidth;
  1619. destRect.bottom = destRect.top + ddsd.dwHeight;
  1620. errstream << "vxl barrel: " << i << " size: " << ddsd.dwWidth << " " << ddsd.dwHeight << " at " << destRect.left << " " << destRect.top << endl;
  1621. errstream.flush();
  1622. Blit_PalD(lpT[i], destRect, vxlBarrelColors[i].data(), srcRect, ddsd.dwWidth, head.cx, ddsd.dwHeight, head.cy);
  1623. Blit_PalD(lighting[i].data(), destRect, vxlBarrelLighting[i].data(), srcRect, ddsd.dwWidth, head.cx, ddsd.dwHeight, head.cy, vxlBarrelColors[i].data());
  1624. }
  1625. if(!bPowerUp && i!=0 && (imghead.unknown==0 && !isTrue(g_data.sections["Debug"].values["IgnoreSHPImageHeadUnused"])) && bStructure)
  1626. {
  1627. if(lpT[i]) delete[] lpT[i];
  1628. lpT[i]=NULL;
  1629. }
  1630. else
  1631. {
  1632. char ic[50];
  1633. itoa(i, ic, 10);
  1634. PICDATA p;
  1635. p.pic=lpT[i];
  1636. if (std::find_if(lighting[i].begin(), lighting[i].end(), [](const BYTE b) { return b != 255; }) != lighting[i].end())
  1637. p.lighting = std::shared_ptr<std::vector<BYTE>>(new std::vector<BYTE>(std::move(lighting[i])));
  1638. else
  1639. lighting[i].clear();
  1640. p.vborder=new(VBORDER[head.cy]);
  1641. int k;
  1642. for(k=0;k<head.cy;k++)
  1643. {
  1644. int l,r;
  1645. GetDrawBorder(lpT[i], head.cx, k, l, r, 0);
  1646. p.vborder[k].left=l;
  1647. p.vborder[k].right=r;
  1648. }
  1649. if(hPalette==m_hPalIsoTemp || hPalette==m_hPalIsoUrb || hPalette==m_hPalIsoSnow || hPalette==m_hPalIsoUbn || hPalette==m_hPalIsoDes || hPalette==m_hPalIsoLun) p.pal=iPalIso;
  1650. if(hPalette==m_hPalTemp || hPalette==m_hPalUrb || hPalette==m_hPalSnow || hPalette==m_hPalUbn || hPalette==m_hPalLun || hPalette==m_hPalDes) p.pal=iPalTheater;
  1651. if(hPalette==m_hPalUnitTemp || hPalette==m_hPalUnitUrb || hPalette==m_hPalUnitSnow || hPalette==m_hPalUnitDes || hPalette==m_hPalUnitLun || hPalette==m_hPalUnitUbn) p.pal=iPalUnit;
  1652. if(hPalette==m_hPalLib) p.pal=iPalLib;
  1653. p.x=imghead.x;
  1654. p.y=imghead.y;
  1655. p.wHeight=imghead.cy;
  1656. p.wWidth=imghead.cx;
  1657. p.wMaxWidth=head.cx;
  1658. p.wMaxHeight=head.cy;
  1659. p.bType=PICDATA_TYPE_SHP;
  1660. p.bTerrain=limited_to_theater;
  1661. pics[image+ic]=p;
  1662. //errstream << " --> finished as " << (LPCSTR)(image+ic) << endl;
  1663. //errstream.flush();
  1664. }
  1665. }
  1666. delete[] lpT;
  1667. if(bib) delete[] bib;
  1668. if(activeanim) delete[] activeanim;
  1669. if(idleanim) delete[] idleanim;
  1670. if(activeanim2) delete[] activeanim2;
  1671. if(activeanim3) delete[] activeanim3;
  1672. if(superanim1) delete[] superanim1;
  1673. if(superanim2) delete[] superanim2;
  1674. if(superanim3) delete[] superanim3;
  1675. if(superanim4) delete[] superanim4;
  1676. if(specialanim1) delete[] specialanim1;
  1677. if(specialanim2) delete[] specialanim2;
  1678. if(specialanim3) delete[] specialanim3;
  1679. if(specialanim4) delete[] specialanim4;
  1680. //for(i=0;i<8;i++)
  1681. // if(turrets[i]) delete[] turrets[i];
  1682. }
  1683. //errstream << " --> Finished" << endl;
  1684. //errstream.flush();
  1685. }
  1686. else
  1687. {
  1688. errstream << "File in theater " << cur_theat << " not found: " << (LPCTSTR)filename << endl;
  1689. errstream.flush();
  1690. missingimages[lpUnittype]=TRUE;
  1691. }
  1692. }
  1693. catch(...)
  1694. {
  1695. errstream << " exception " << endl;
  1696. errstream.flush();
  1697. }
  1698. }
  1699. else
  1700. {
  1701. filename=image+".vxl";
  1702. HMIXFILE hMix=FindFileInMix(filename);
  1703. if(hMix==FALSE)
  1704. {
  1705. missingimages[lpUnittype]=TRUE;
  1706. return FALSE;
  1707. }
  1708. int XMover, YMover;
  1709. #ifdef RA2_MODE
  1710. XMover=atoi(g_data.sections["VehicleVoxelTurretsRA2"].values[(CString)lpUnittype+"X"]);
  1711. YMover=atoi(g_data.sections["VehicleVoxelTurretsRA2"].values[(CString)lpUnittype+"Y"]);
  1712. #else
  1713. XMover=atoi(g_data.sections["VehicleVoxelTurrets"].values[(CString)lpUnittype+"X"]);
  1714. YMover=atoi(g_data.sections["VehicleVoxelTurrets"].values[(CString)lpUnittype+"Y"]);
  1715. #endif
  1716. if (artSection.values.find("TurretOffset") != art.sections[image].values.end())
  1717. iTurretOffset = atoi(art.sections[image].values["TurretOffset"]);
  1718. int i;
  1719. for(i=0;i<8;i++)
  1720. {
  1721. float r_x,r_y,r_z;
  1722. r_x = 300;
  1723. r_y=0;
  1724. r_z=45*i+90;
  1725. //r_x = 0;
  1726. //r_y = 0;
  1727. //r_z = 0;
  1728. // convert
  1729. const double pi = 3.141592654;
  1730. Vec3f rotation(r_x / 180.0f * pi, r_y / 180.0f * pi, r_z / 180.0f * pi);
  1731. Vec3f turretModelOffset(iTurretOffset / 6.0f, 0.0f, 0.0f);
  1732. std::vector<BYTE> colors;
  1733. std::shared_ptr<std::vector<BYTE>> pLighting(new std::vector<BYTE>);
  1734. auto& lighting = *pLighting;
  1735. std::vector<BYTE> turretColors;
  1736. std::vector<BYTE> turretNormals;
  1737. std::vector<BYTE> barrelColors;
  1738. std::vector<BYTE> barrelNormals;
  1739. RECT lprT;
  1740. RECT lprB;
  1741. int turret_x,turret_y,turret_x_zmax,turret_y_zmax,barrel_x,barrel_y;
  1742. if(isTrue(rules.sections[lpUnittype].values["Turret"]))
  1743. {
  1744. if(FSunPackLib::SetCurrentVXL(image+"tur.vxl", hMix))
  1745. {
  1746. FSunPackLib::LoadVXLImage(*m_voxelNormalTables, lightDirection, rotation, turretModelOffset, turretColors, turretNormals, &turret_x,&turret_y, 0, &turret_x_zmax, &turret_y_zmax,-1,-1,&lprT);
  1747. }
  1748. if(FSunPackLib::SetCurrentVXL(image+"barl.vxl", hMix))
  1749. {
  1750. FSunPackLib::LoadVXLImage(*m_voxelNormalTables, lightDirection, rotation, turretModelOffset, barrelColors, barrelNormals, &barrel_x,&barrel_y, 0, NULL, NULL, 0, 0, &lprB);
  1751. }
  1752. }
  1753. if(!FSunPackLib::SetCurrentVXL(filename, hMix))
  1754. {
  1755. return FALSE;
  1756. }
  1757. int xcenter,ycenter,xcenter_zmax,ycenter_zmax;
  1758. RECT r;
  1759. if(!
  1760. FSunPackLib::LoadVXLImage(*m_voxelNormalTables, lightDirection, rotation, Vec3f(), colors, lighting, &xcenter, &ycenter,0, &xcenter_zmax, &ycenter_zmax,-1,-1,&r)
  1761. )
  1762. {
  1763. return FALSE;
  1764. }
  1765. FSunPackLib::VoxelNormalClass vnc = FSunPackLib::VoxelNormalClass::Unknown;
  1766. FSunPackLib::GetVXLSectionInfo(0, vnc); // we assume the normal class for all voxels sections and turrets or barrels is the same
  1767. DDSURFACEDESC2 ddsd;
  1768. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  1769. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  1770. ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  1771. ddsd.dwWidth=r.right-r.left;
  1772. ddsd.dwHeight=r.bottom-r.top;
  1773. //lpT->GetSurfaceDesc(&ddsd);
  1774. // turret
  1775. if(turretColors.size())
  1776. {
  1777. DDSURFACEDESC2 ddsdT;
  1778. memset(&ddsdT, 0, sizeof(DDSURFACEDESC2));
  1779. ddsdT.dwSize=sizeof(DDSURFACEDESC2);
  1780. ddsdT.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  1781. ddsdT.dwWidth=lprT.right-lprT.left;
  1782. ddsdT.dwHeight=lprT.bottom-lprT.top;
  1783. //lpTurret->GetSurfaceDesc(&ddsdT);
  1784. DDBLTFX fx;
  1785. memset(&fx, 0, sizeof(DDBLTFX));
  1786. fx.dwSize=sizeof(DDBLTFX);
  1787. RECT srcRect, destRect;
  1788. srcRect.left=0;
  1789. srcRect.right=ddsdT.dwWidth;
  1790. destRect.left=xcenter - turret_x + XMover;
  1791. destRect.right=destRect.left+ddsdT.dwWidth;
  1792. srcRect.top=0;
  1793. srcRect.bottom=ddsdT.dwHeight;
  1794. destRect.top=ycenter - turret_y + YMover;
  1795. destRect.bottom=destRect.top+ddsdT.dwHeight;
  1796. errstream << destRect.left << " " << destRect.top << endl;
  1797. errstream.flush();
  1798. Blit_PalD(colors.data(), destRect, turretColors.data(), srcRect, ddsdT.dwWidth, ddsd.dwWidth, ddsdT.dwHeight, ddsd.dwHeight);
  1799. Blit_PalD(lighting.data(), destRect, turretNormals.data(), srcRect, ddsdT.dwWidth, ddsd.dwWidth, ddsdT.dwHeight, ddsd.dwHeight, turretColors.data());
  1800. //AssertNormals(turretColors, turretNormals);
  1801. }
  1802. // barrel
  1803. if(barrelColors.size())
  1804. {
  1805. DDSURFACEDESC2 ddsdB;
  1806. memset(&ddsdB, 0, sizeof(DDSURFACEDESC2));
  1807. ddsdB.dwSize=sizeof(DDSURFACEDESC2);
  1808. ddsdB.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  1809. ddsdB.dwWidth=lprB.right-lprB.left;
  1810. ddsdB.dwHeight=lprB.bottom-lprB.top;
  1811. //lpBarrel->GetSurfaceDesc(&ddsdB);
  1812. DDSURFACEDESC2 ddsdT;
  1813. memset(&ddsdT, 0, sizeof(DDSURFACEDESC2));
  1814. ddsdT.dwSize=sizeof(DDSURFACEDESC2);
  1815. ddsdT.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  1816. if(turretColors.size())
  1817. {
  1818. ddsdT.dwWidth=lprT.right-lprT.left;
  1819. ddsdT.dwHeight=lprT.bottom-lprT.top;
  1820. //lpTurret->GetSurfaceDesc(&ddsdT);
  1821. }
  1822. DDBLTFX fx;
  1823. memset(&fx, 0, sizeof(DDBLTFX));
  1824. fx.dwSize=sizeof(DDBLTFX);
  1825. RECT srcRect, destRect;
  1826. srcRect.left=0;
  1827. srcRect.right=ddsdB.dwWidth;
  1828. destRect.left=xcenter-barrel_x+XMover;
  1829. destRect.right=destRect.left+ddsdB.dwWidth;
  1830. srcRect.top=0;
  1831. srcRect.bottom=ddsdB.dwHeight;
  1832. destRect.top=ycenter-barrel_y+YMover;
  1833. destRect.bottom=destRect.top+ddsdB.dwHeight;
  1834. Blit_PalD(colors.data(), destRect, barrelColors.data(), srcRect, ddsdB.dwWidth, ddsd.dwWidth, ddsdB.dwHeight, ddsd.dwHeight);
  1835. Blit_PalD(lighting.data(), destRect, barrelNormals.data(), srcRect, ddsdB.dwWidth, ddsd.dwWidth, ddsdB.dwHeight, ddsd.dwHeight, barrelColors.data());
  1836. //AssertNormals(vxlBarrelColors, barrelNormals);
  1837. }
  1838. // all VXL, so every non-transparent area should have a normal
  1839. //AssertNormals(colors, lighting);
  1840. char ic[50];
  1841. itoa(7-i, ic, 10);
  1842. errstream << ddsd.dwWidth << " " << ddsd.dwHeight << "\n";
  1843. PICDATA p;
  1844. p.pic = new(BYTE[colors.size()]);
  1845. memcpy(p.pic, colors.data(), colors.size());
  1846. p.lighting = pLighting;
  1847. p.normalClass = vnc;
  1848. p.vborder=new(VBORDER[ddsd.dwHeight]);
  1849. int k;
  1850. for(k=0;k<ddsd.dwHeight;k++)
  1851. {
  1852. int l,r;
  1853. GetDrawBorder(colors.data(), ddsd.dwWidth, k, l, r, 0);
  1854. p.vborder[k].left=l;
  1855. p.vborder[k].right=r;
  1856. }
  1857. //if(hPalette==m_hPalIsoTemp || hPalette==m_hPalIsoUrb || hPalette==m_hPalIsoSnow) p.pal=iPalIso;
  1858. //if(hPalette==m_hPalTemp || hPalette==m_hPalUrb || hPalette==m_hPalSnow) p.pal=iPalTheater;
  1859. //if(hPalette==m_hPalUnitTemp || hPalette==m_hPalUnitUrb || hPalette==m_hPalUnitSnow) p.pal=iPalUnit;
  1860. //if(hPalette==m_hPalLib) p.pal=iPalLib;
  1861. p.pal=iPalUnit;
  1862. p.x=-xcenter;
  1863. p.y=-ycenter;
  1864. p.wHeight=ddsd.dwHeight;
  1865. p.wWidth=ddsd.dwWidth;
  1866. p.wMaxWidth=ddsd.dwWidth;
  1867. p.wMaxHeight=ddsd.dwHeight;
  1868. p.bType=PICDATA_TYPE_VXL;
  1869. p.bTerrain=TheaterChar::None;
  1870. pics[image+ic]=p;
  1871. errstream << "vxl saved as " << (LPCSTR)image << (LPCSTR)ic << endl;
  1872. errstream.flush();
  1873. //delete[] lpT;
  1874. }
  1875. }
  1876. return FALSE;
  1877. }
  1878. void CLoading::LoadBuildingSubGraphic(const CString& subkey, const CIniFileSection& artSection, BOOL bAlwaysSetChar, char theat, HMIXFILE hShpMix, SHPHEADER& shp_h, BYTE*& shp)
  1879. {
  1880. CString subname = artSection.GetValueByName(subkey);
  1881. if (subname.GetLength() > 0)
  1882. {
  1883. auto res = FindUnitShp(subname, theat, artSection);
  1884. /*CString subfilename = subname + ".shp";
  1885. if (isTrue(artSection.GetValueByName("NewTheater")) || bAlwaysSetChar || subfilename.GetAt(0) == 'G' || subfilename.GetAt(0) == 'N' || subfilename.GetAt(0) == 'Y' || subfilename.GetAt(0) == 'C')
  1886. {
  1887. auto subfilename_theat = subfilename;
  1888. subfilename_theat.SetAt(1, theat);
  1889. if (FSunPackLib::XCC_DoesFileExist(subfilename_theat, hShpMix))
  1890. subfilename = subfilename_theat;
  1891. }*/
  1892. if (res && FSunPackLib::XCC_DoesFileExist(res->filename, res->mixfile))
  1893. {
  1894. FSunPackLib::SetCurrentSHP(res->filename, res->mixfile);
  1895. FSunPackLib::XCC_GetSHPHeader(&shp_h);
  1896. FSunPackLib::LoadSHPImage(0, 1, &shp);
  1897. }
  1898. }
  1899. }
  1900. #else // surfaces
  1901. BOOL CLoading::LoadUnitGraphic(LPCTSTR lpUnittype)
  1902. {
  1903. last_succeeded_operation=10;
  1904. CString _rules_image; // the image used
  1905. CString filename; // filename of the image
  1906. char theat=cur_theat; // standard theater char is t (Temperat). a is snow.
  1907. BOOL bAlwaysSetChar; // second char is always theater, even if NewTheater not specified!
  1908. WORD wStep=1; // step is 1 for infantry, buildings, etc, and for shp vehicles it specifies the step rate between every direction
  1909. WORD wStartWalkFrame=0; // for examply cyborg reaper has another walk starting frame
  1910. int iTurretOffset=0; // used for centering y pos of turret (if existing)
  1911. BOOL bStructure=rules.sections["BuildingTypes"].FindValue(lpUnittype)>=0; // is this a structure?
  1912. BOOL bPowerUp=rules.sections[lpUnittype].values["PowersUpBuilding"]!="";
  1913. HTSPALETTE hPalette;
  1914. if(theat=='T') hPalette=m_hPalIsoTemp;
  1915. if(theat=='A') hPalette=m_hPalIsoSnow;
  1916. if(theat=='U') hPalette=m_hPalIsoUrb;
  1917. CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview;
  1918. _rules_image = lpUnittype;
  1919. if (rules.sections[lpUnittype].values.find("Image") != rules.sections[lpUnittype].values.end())
  1920. _rules_image = rules.sections[lpUnittype].values["Image"];
  1921. CString _art_image = _rules_image;
  1922. if (art.sections[_rules_image].values.find("Image") != art.sections[_rules_image].values.end())
  1923. {
  1924. if (!isTrue(g_data.sections["IgnoreArtImage"].values[_rules_image]))
  1925. _art_image = art.sections[_rules_image].values["Image"];
  1926. }
  1927. const CString& image = _art_image;
  1928. const auto& rulesSection = rules.sections[lpUnittype];
  1929. const auto& artSection = art.sections[image];
  1930. if(!isTrue(art.sections[image].values["Voxel"])) // is it a shp graphic?
  1931. {
  1932. try
  1933. {
  1934. filename=image+".shp";
  1935. BYTE bTerrain=0;
  1936. BOOL isNewTerrain=FALSE;
  1937. if(isTrue(art.sections[image].values["NewTheater"]))//&& isTrue(artSection.GetValueByName("TerrainPalette")))//(filename.GetAt(0)=='G' || filename.GetAt(0)=='N' || filename.GetAt(0)=='C') && filename.GetAt(1)=='A')
  1938. {
  1939. hPalette=m_hPalUnitTemp;
  1940. if(theat=='A') hPalette=m_hPalUnitSnow;
  1941. if(theat=='U') hPalette=m_hPalUnitUrb;
  1942. filename.SetAt(1, theat);
  1943. isNewTerrain=TRUE;
  1944. }
  1945. HMIXFILE hShpMix=FindFileInMix(filename, &bTerrain);
  1946. BYTE bIgnoreTerrain=TRUE;
  1947. if(hShpMix==NULL && isNewTerrain)
  1948. {
  1949. filename.SetAt(1, 'G');
  1950. hShpMix=FindFileInMix(filename, &bTerrain);
  1951. if(hShpMix) theat='G';
  1952. }
  1953. if(hShpMix==NULL && isNewTerrain)
  1954. {
  1955. filename.SetAt(1, 'A');
  1956. hShpMix=FindFileInMix(filename, &bTerrain);
  1957. if(hShpMix) theat='A';
  1958. }
  1959. if(hShpMix==NULL && isNewTerrain)
  1960. {
  1961. filename.SetAt(1, 'T');
  1962. hShpMix=FindFileInMix(filename, &bTerrain);
  1963. if(hShpMix){
  1964. theat='T';
  1965. hPalette=m_hIsoTemp;
  1966. }
  1967. }
  1968. if(isTrue(artSection.GetValueByName("TerrainPalette")))
  1969. {
  1970. bIgnoreTerrain=FALSE;
  1971. if(cur_theat=='T')
  1972. hPalette=m_hPalIsoTemp;
  1973. else if(cur_theat=='A')
  1974. hPalette=m_hPalIsoSnow;
  1975. else if (cur_theat=='U')
  1976. hPalette=m_hPalIsoUrb;
  1977. }
  1978. if(hShpMix==0)
  1979. {
  1980. filename=image;
  1981. filename+=".shp";
  1982. hShpMix=FindFileInMix(filename, &bTerrain);
  1983. if(hShpMix==NULL)
  1984. {
  1985. filename=image;
  1986. if(theat=='T') filename+=".tem";
  1987. if(theat=='A') filename+=".sno";
  1988. if(theat=='U') filename+=".urb";
  1989. filename.MakeLower();
  1990. hShpMix=FindFileInMix(filename, &bTerrain);
  1991. if(hShpMix==NULL)
  1992. {
  1993. filename=image;
  1994. filename+=".tem";
  1995. hShpMix=FindFileInMix(filename, &bTerrain);
  1996. if(hShpMix)
  1997. {
  1998. hPalette=m_hPalIsoTemp;
  1999. }
  2000. }
  2001. if(hShpMix!=NULL)
  2002. {
  2003. }
  2004. else
  2005. {
  2006. filename=image+".shp";
  2007. filename.SetAt(1, 'A');
  2008. hShpMix=FindFileInMix(filename);
  2009. if(hShpMix!=NULL)
  2010. {
  2011. bAlwaysSetChar=TRUE;
  2012. }
  2013. else
  2014. {
  2015. filename.SetAt(1, 'A');
  2016. hShpMix=FindFileInMix(filename);
  2017. if(hShpMix!=NULL)
  2018. {
  2019. theat='A';
  2020. bAlwaysSetChar=TRUE;
  2021. }
  2022. else
  2023. {
  2024. filename.SetAt(1, 'U');
  2025. hShpMix=FindFileInMix(filename);
  2026. if(hShpMix) theat='U';
  2027. else
  2028. {
  2029. filename.SetAt(1, 'T');
  2030. hShpMix=FindFileInMix(filename);
  2031. if(hShpMix) theat='T';
  2032. }
  2033. }
  2034. }
  2035. }
  2036. }
  2037. else
  2038. {
  2039. theat='T';
  2040. }
  2041. }
  2042. else
  2043. {
  2044. // now we need to find out the palette
  2045. if(isTrue(artSection.GetValueByName("TerrainPalette"))) // it´s a file in isotemp.mix/isosno.mix
  2046. {
  2047. }
  2048. else // it´s a file in temperat.mix/snow.mix
  2049. {
  2050. if(cur_theat=='T') hPalette=m_hPalUnitTemp;
  2051. if(cur_theat=='A') hPalette=m_hPalUnitSnow;
  2052. if(cur_theat=='U') hPalette=m_hPalUnitUrb;
  2053. }
  2054. }
  2055. if(filename=="tibtre01.tem" || filename=="tibtre02.tem" || filename=="tibtre03.tem" || filename=="veinhole.tem")
  2056. {
  2057. hPalette=m_hPalUnitTemp;
  2058. }
  2059. SHPHEADER head;
  2060. CString bibname;
  2061. CString bibfilename;
  2062. CString activeanim_name;
  2063. CString activeanim_filename;
  2064. CString idleanim_name;
  2065. CString idleanim_filename;
  2066. CString activeanim2_name;
  2067. CString activeanim2_filename;
  2068. CString activeanim3_name;
  2069. CString activeanim3_filename;
  2070. CString superanim1_name,superanim1_filename;
  2071. CString superanim2_name,superanim2_filename;
  2072. CString superanim3_name,superanim3_filename;
  2073. CString superanim4_name,superanim4_filename;
  2074. CString specialanim1_name,specialanim1_filename;
  2075. CString specialanim2_name,specialanim2_filename;
  2076. CString specialanim3_name,specialanim3_filename;
  2077. CString specialanim4_name,specialanim4_filename;
  2078. CString turretanim_name;
  2079. CString turretanim_filename;
  2080. LPDIRECTDRAWSURFACE4 bib=NULL;
  2081. LPDIRECTDRAWSURFACE4 activeanim=NULL;
  2082. LPDIRECTDRAWSURFACE4 idleanim=NULL;
  2083. LPDIRECTDRAWSURFACE4 activeanim2=NULL;
  2084. LPDIRECTDRAWSURFACE4 activeanim3=NULL;
  2085. LPDIRECTDRAWSURFACE4 superanim1=NULL;
  2086. LPDIRECTDRAWSURFACE4 superanim2=NULL;
  2087. LPDIRECTDRAWSURFACE4 superanim3=NULL;
  2088. LPDIRECTDRAWSURFACE4 superanim4=NULL;
  2089. LPDIRECTDRAWSURFACE4 specialanim1=NULL;
  2090. LPDIRECTDRAWSURFACE4 specialanim2=NULL;
  2091. LPDIRECTDRAWSURFACE4 specialanim3=NULL;
  2092. LPDIRECTDRAWSURFACE4 specialanim4=NULL;
  2093. LPDIRECTDRAWSURFACE4* lpT=NULL;
  2094. LPDIRECTDRAWSURFACE4 turrets[8] = { 0 };
  2095. SHPIMAGEHEADER turretinfo[8];
  2096. if(hShpMix>0)
  2097. {
  2098. //errstream << (LPCTSTR)filename << " found " ;
  2099. //errstream.flush();
  2100. if(rules.sections[lpUnittype].values["Bib"]!="no") // seems to be ignored by TS, art.ini overwrites???
  2101. {
  2102. bibname=art.sections[image].values["BibShape"];
  2103. if(bibname.GetLength()>0)
  2104. {
  2105. bibfilename=bibname+".shp";
  2106. if(isTrue(art.sections[image].values["NewTheater"]))
  2107. bibfilename.SetAt(1, theat);
  2108. if(bAlwaysSetChar) bibfilename.SetAt(1, theat);
  2109. if(FSunPackLib::XCC_DoesFileExist(bibfilename, hShpMix))
  2110. {
  2111. FSunPackLib::SetCurrentSHP(bibfilename, hShpMix);
  2112. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &bib);
  2113. }
  2114. }
  2115. }
  2116. activeanim_name=art.sections[image].values["ActiveAnim"];
  2117. if(activeanim_name.GetLength()>0)
  2118. {
  2119. activeanim_filename=activeanim_name+".shp";
  2120. if(isTrue(art.sections[image].values["NewTheater"]))
  2121. activeanim_filename.SetAt(1, theat);
  2122. if(bAlwaysSetChar) activeanim_filename.SetAt(1, theat);
  2123. if(FSunPackLib::XCC_DoesFileExist(activeanim_filename, hShpMix))
  2124. {
  2125. FSunPackLib::SetCurrentSHP(activeanim_filename, hShpMix);
  2126. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &activeanim);
  2127. }
  2128. }
  2129. idleanim_name=art.sections[image].values["IdleAnim"];
  2130. if(idleanim_name.GetLength()>0)
  2131. {
  2132. idleanim_filename=idleanim_name+".shp";
  2133. if(isTrue(art.sections[image].values["NewTheater"]))
  2134. idleanim_filename.SetAt(1, theat);
  2135. if(bAlwaysSetChar) idleanim_filename.SetAt(1, theat);
  2136. if(FSunPackLib::XCC_DoesFileExist(idleanim_filename, hShpMix))
  2137. {
  2138. FSunPackLib::SetCurrentSHP(idleanim_filename, hShpMix);
  2139. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &idleanim);
  2140. }
  2141. }
  2142. activeanim2_name=art.sections[image].values["ActiveAnimTwo"];
  2143. if(activeanim2_name.GetLength()>0)
  2144. {
  2145. activeanim2_filename=activeanim2_name+".shp";
  2146. if(isTrue(art.sections[image].values["NewTheater"]))
  2147. activeanim2_filename.SetAt(1, theat);
  2148. if(bAlwaysSetChar) activeanim2_filename.SetAt(1, theat);
  2149. if(FSunPackLib::XCC_DoesFileExist(activeanim2_filename, hShpMix))
  2150. {
  2151. FSunPackLib::SetCurrentSHP(activeanim2_filename, hShpMix);
  2152. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &activeanim2);
  2153. }
  2154. }
  2155. activeanim3_name=art.sections[image].values["ActiveAnimThree"];
  2156. if(activeanim3_name.GetLength()>0)
  2157. {
  2158. activeanim3_filename=activeanim3_name+".shp";
  2159. if(isTrue(art.sections[image].values["NewTheater"]))
  2160. activeanim3_filename.SetAt(1, theat);
  2161. if(bAlwaysSetChar) activeanim3_filename.SetAt(1, theat);
  2162. if(FSunPackLib::XCC_DoesFileExist(activeanim3_filename, hShpMix))
  2163. {
  2164. FSunPackLib::SetCurrentSHP(activeanim3_filename, hShpMix);
  2165. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &activeanim3);
  2166. }
  2167. }
  2168. superanim1_name=art.sections[image].values["SuperAnim"];
  2169. if(superanim1_name.GetLength()>0)
  2170. {
  2171. superanim1_filename=superanim1_name+".shp";
  2172. if(isTrue(art.sections[image].values["NewTheater"]))
  2173. superanim1_filename.SetAt(1, theat);
  2174. if(bAlwaysSetChar) superanim1_filename.SetAt(1, theat);
  2175. if(FSunPackLib::XCC_DoesFileExist(superanim1_filename, hShpMix))
  2176. {
  2177. FSunPackLib::SetCurrentSHP(superanim1_filename, hShpMix);
  2178. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &superanim1);
  2179. }
  2180. }
  2181. superanim2_name=art.sections[image].values["SuperAnimTwo"];
  2182. if(superanim2_name.GetLength()>0)
  2183. {
  2184. superanim2_filename=superanim2_name+".shp";
  2185. if(isTrue(art.sections[image].values["NewTheater"]))
  2186. superanim2_filename.SetAt(1, theat);
  2187. if(bAlwaysSetChar) superanim2_filename.SetAt(1, theat);
  2188. if(FSunPackLib::XCC_DoesFileExist(superanim2_filename, hShpMix))
  2189. {
  2190. FSunPackLib::SetCurrentSHP(superanim2_filename, hShpMix);
  2191. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &superanim2);
  2192. }
  2193. }
  2194. superanim3_name=art.sections[image].values["SuperAnimThree"];
  2195. if(superanim3_name.GetLength()>0)
  2196. {
  2197. superanim3_filename=superanim3_name+".shp";
  2198. if(isTrue(art.sections[image].values["NewTheater"]))
  2199. superanim3_filename.SetAt(1, theat);
  2200. if(bAlwaysSetChar) superanim3_filename.SetAt(1, theat);
  2201. if(FSunPackLib::XCC_DoesFileExist(superanim3_filename, hShpMix))
  2202. {
  2203. FSunPackLib::SetCurrentSHP(superanim3_filename, hShpMix);
  2204. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &superanim3);
  2205. }
  2206. }
  2207. superanim4_name=art.sections[image].values["SuperAnimFour"];
  2208. if(superanim4_name.GetLength()>0)
  2209. {
  2210. superanim4_filename=superanim4_name+".shp";
  2211. if(isTrue(art.sections[image].values["NewTheater"]))
  2212. superanim4_filename.SetAt(1, theat);
  2213. if(bAlwaysSetChar) superanim4_filename.SetAt(1, theat);
  2214. if(FSunPackLib::XCC_DoesFileExist(superanim4_filename, hShpMix))
  2215. {
  2216. FSunPackLib::SetCurrentSHP(superanim4_filename, hShpMix);
  2217. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &superanim4);
  2218. }
  2219. }
  2220. specialanim1_name=art.sections[image].values["SpecialAnim"];
  2221. if(specialanim1_name.GetLength()>0)
  2222. {
  2223. specialanim1_filename=specialanim1_name+".shp";
  2224. if(isTrue(art.sections[image].values["NewTheater"]))
  2225. specialanim1_filename.SetAt(1, theat);
  2226. if(bAlwaysSetChar) specialanim1_filename.SetAt(1, theat);
  2227. if(FSunPackLib::XCC_DoesFileExist(specialanim1_filename, hShpMix))
  2228. {
  2229. FSunPackLib::SetCurrentSHP(specialanim1_filename, hShpMix);
  2230. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &specialanim1);
  2231. }
  2232. }
  2233. specialanim2_name=art.sections[image].values["SpecialAnimTwo"];
  2234. if(specialanim2_name.GetLength()>0)
  2235. {
  2236. specialanim2_filename=specialanim2_name+".shp";
  2237. if(isTrue(art.sections[image].values["NewTheater"]))
  2238. specialanim2_filename.SetAt(1, theat);
  2239. if(bAlwaysSetChar) specialanim2_filename.SetAt(1, theat);
  2240. if(FSunPackLib::XCC_DoesFileExist(specialanim2_filename, hShpMix))
  2241. {
  2242. FSunPackLib::SetCurrentSHP(specialanim2_filename, hShpMix);
  2243. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &specialanim2);
  2244. }
  2245. }
  2246. specialanim3_name=art.sections[image].values["SpecialAnimThree"];
  2247. if(specialanim3_name.GetLength()>0)
  2248. {
  2249. specialanim3_filename=specialanim3_name+".shp";
  2250. if(isTrue(art.sections[image].values["NewTheater"]))
  2251. specialanim3_filename.SetAt(1, theat);
  2252. if(bAlwaysSetChar) specialanim3_filename.SetAt(1, theat);
  2253. if(FSunPackLib::XCC_DoesFileExist(specialanim3_filename, hShpMix))
  2254. {
  2255. FSunPackLib::SetCurrentSHP(specialanim3_filename, hShpMix);
  2256. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &specialanim3);
  2257. }
  2258. }
  2259. specialanim4_name=art.sections[image].values["SpecialAnimFour"];
  2260. if(specialanim4_name.GetLength()>0)
  2261. {
  2262. specialanim4_filename=specialanim4_name+".shp";
  2263. if(isTrue(art.sections[image].values["NewTheater"]))
  2264. specialanim4_filename.SetAt(1, theat);
  2265. if(bAlwaysSetChar) specialanim4_filename.SetAt(1, theat);
  2266. if(FSunPackLib::XCC_DoesFileExist(specialanim4_filename, hShpMix))
  2267. {
  2268. FSunPackLib::SetCurrentSHP(specialanim4_filename, hShpMix);
  2269. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &specialanim4);
  2270. }
  2271. }
  2272. BOOL bVoxelTurret=FALSE;
  2273. turretanim_name=rules.sections[image].values["TurretAnim"];
  2274. if(bStructure && rules.sections[image].values["Turret"]=="yes" && turretanim_name.GetLength()>0 && rules.sections[image].values["TurretAnimIsVoxel"]!="true")
  2275. {
  2276. turretanim_filename=turretanim_name+".shp";
  2277. if(art.sections[turretanim_name].values.find("Image")!=art.sections[turretanim_name].values.end()) turretanim_filename=art.sections[turretanim_name].values["Image"]+".shp";
  2278. if(isTrue(art.sections[image].values["NewTheater"]))
  2279. turretanim_filename.SetAt(1, theat);
  2280. FSunPackLib::SetCurrentSHP(turretanim_filename, hShpMix);
  2281. FSunPackLib::XCC_GetSHPHeader(&head);
  2282. int iStartTurret=0;
  2283. const WORD wAnimCount=4; // anims between each "normal" direction, seems to be hardcoded
  2284. int i;
  2285. for(i=0;i<8;i++)
  2286. {
  2287. if(iStartTurret+i*wAnimCount<head.c_images)
  2288. {
  2289. FSunPackLib::XCC_GetSHPImageHeader(iStartTurret+i*wAnimCount, &turretinfo[i]);
  2290. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, iStartTurret+i*wAnimCount, 1, &turrets[i]);
  2291. }
  2292. }
  2293. }
  2294. else if(bStructure && rules.sections[image].values["Turret"]=="yes" && turretanim_name.GetLength()>0 && rules.sections[image].values["TurretAnimIsVoxel"]=="true")
  2295. {
  2296. turretanim_filename=turretanim_name+".vxl";
  2297. if(art.sections[turretanim_name].values.find("Image")!=art.sections[turretanim_name].values.end()) turretanim_filename=art.sections[turretanim_name].values["Image"]+".vxl";
  2298. //if(isTrue(art.sections[image].values["NewTheater"]))
  2299. // turretanim_filename.SetAt(1, theat);
  2300. HMIXFILE hVXL=FindFileInMix(turretanim_filename);
  2301. if(hVXL)
  2302. {
  2303. bVoxelTurret=TRUE;
  2304. if(
  2305. FSunPackLib::SetCurrentVXL(turretanim_filename, hVXL)
  2306. )
  2307. {
  2308. int i;
  2309. for(i=0;i<8;i++)
  2310. {
  2311. float r_x,r_y,r_z;
  2312. r_x=300;
  2313. r_y=0;
  2314. r_z=45*i+90;
  2315. // convert
  2316. const double pi = 3.141592654;
  2317. r_x=r_x/180.0f*pi;
  2318. r_y=r_y/180.0f*pi;
  2319. r_z=r_z/180.0f*pi;
  2320. int center_x, center_y;
  2321. if(!
  2322. FSunPackLib::LoadVXLImageInSurface(*m_voxelNormalTables, lightDirection, v.dd, 0, 1, r_x, r_y, r_z, &turrets[i], hPalette,&center_x, &center_y,atoi(rules.sections[image].values["TurretAnimZAdjust"]))
  2323. )
  2324. {
  2325. }
  2326. else
  2327. {
  2328. DDSURFACEDESC2 ddsd;
  2329. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  2330. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  2331. ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  2332. turrets[i]->GetSurfaceDesc(&ddsd);
  2333. turretinfo[i].x=-center_x;
  2334. turretinfo[i].y=-center_y;
  2335. turretinfo[i].cx=ddsd.dwWidth;
  2336. turretinfo[i].cy=ddsd.dwHeight;
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. if(art.sections[image].values.find("WalkFrames")!=art.sections[image].values.end())
  2343. wStep=atoi(art.sections[image].values["WalkFrames"]);
  2344. if(art.sections[image].values.find("StartWalkFrame")!=art.sections[image].values.end())
  2345. wStartWalkFrame=atoi(art.sections[image].values["StartWalkFrame"]);
  2346. if(art.sections[image].values.find("TurretOffset")!=art.sections[image].values.end())
  2347. iTurretOffset=atoi(art.sections[image].values["TurretOffset"]);
  2348. if(art.sections[image].values["Palette"]=="lib")
  2349. hPalette=m_hPalLib;
  2350. BOOL bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix);
  2351. if(
  2352. !bSuccess
  2353. )
  2354. {
  2355. filename=image+=".sno";
  2356. if(cur_theat=='T' || cur_theat=='U') hPalette=m_hPalIsoTemp;
  2357. hShpMix=FindFileInMix(filename, &bTerrain);
  2358. bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix);
  2359. if(!bSuccess)
  2360. {
  2361. missingimages[lpUnittype]=TRUE;
  2362. }
  2363. }
  2364. if(bSuccess)
  2365. {
  2366. FSunPackLib::XCC_GetSHPHeader(&head);
  2367. int i;
  2368. int maxPics=head.c_images;
  2369. if(maxPics>8) maxPics=8; // we only need 8 pictures for every direction!
  2370. if(bStructure && !bPowerUp) maxPics=1;
  2371. if(bVoxelTurret) maxPics=8;
  2372. if(!bStructure && rules.sections[image].values["Turret"]=="yes")
  2373. {
  2374. int iStartTurret=wStartWalkFrame+8*wStep;
  2375. const WORD wAnimCount=4; // anims between each "normal" direction, seems to be hardcoded
  2376. int i;
  2377. for(i=0;i<8;i++)
  2378. {
  2379. if(!bStructure && iStartTurret+i*wAnimCount<head.c_images)
  2380. {
  2381. FSunPackLib::XCC_GetSHPImageHeader(iStartTurret+i*wAnimCount, &turretinfo[i]);
  2382. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, iStartTurret+i*wAnimCount, 1, &turrets[i]);
  2383. }
  2384. }
  2385. }
  2386. // create an array of pointers to directdraw surfaces
  2387. lpT=new(LPDIRECTDRAWSURFACE4[maxPics]);
  2388. memset(lpT, 0, sizeof(LPDIRECTDRAWSURFACE4)*maxPics);
  2389. if(bVoxelTurret)
  2390. {
  2391. for(i=0;i<maxPics; i++)
  2392. {
  2393. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, 1, &lpT[i]);
  2394. }
  2395. }
  2396. else if(wStep==1 && (rules.sections[lpUnittype].values["PowersUpBuilding"].GetLength()==0 || !isTrue(rules.sections[lpUnittype].values["Turret"])))
  2397. { // standard case...
  2398. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, wStartWalkFrame, maxPics, lpT);
  2399. }
  2400. else if(rules.sections[lpUnittype].values["PowersUpBuilding"].GetLength()!=0 && isTrue(rules.sections[lpUnittype].values["Turret"]))
  2401. { // a "real" turret (vulcan cannon, etc...)
  2402. for(i=0;i<maxPics; i++)
  2403. {
  2404. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, i*4, 1, &lpT[i]);
  2405. }
  2406. }
  2407. else
  2408. { // walk frames used
  2409. for(i=0;i<maxPics; i++)
  2410. {
  2411. int pic_in_file=i;
  2412. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, i*wStep+wStartWalkFrame, 1, &lpT[i]);
  2413. }
  2414. }
  2415. for(i=0; i<maxPics; i++)
  2416. {
  2417. int pic_in_file=i;
  2418. if(bStructure && bVoxelTurret) pic_in_file=0;
  2419. SHPIMAGEHEADER imghead;
  2420. FSunPackLib::XCC_GetSHPImageHeader(pic_in_file, &imghead);
  2421. if(bib!=NULL)
  2422. {
  2423. DDBLTFX fx;
  2424. memset(&fx, 0, sizeof(DDBLTFX));
  2425. fx.dwSize=sizeof(DDBLTFX);
  2426. lpT[i]->Blt(NULL, bib, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2427. imghead.cx=head.cx-imghead.x; // update size of main graphic
  2428. imghead.cy=head.cy-imghead.y;
  2429. }
  2430. if(activeanim!=NULL)
  2431. {
  2432. DDBLTFX fx;
  2433. memset(&fx, 0, sizeof(DDBLTFX));
  2434. fx.dwSize=sizeof(DDBLTFX);
  2435. lpT[i]->Blt(NULL, activeanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2436. }
  2437. if(idleanim!=NULL)
  2438. {
  2439. DDBLTFX fx;
  2440. memset(&fx, 0, sizeof(DDBLTFX));
  2441. fx.dwSize=sizeof(DDBLTFX);
  2442. lpT[i]->Blt(NULL, idleanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2443. }
  2444. if(activeanim2!=NULL)
  2445. {
  2446. DDBLTFX fx;
  2447. memset(&fx, 0, sizeof(DDBLTFX));
  2448. fx.dwSize=sizeof(DDBLTFX);
  2449. lpT[i]->Blt(NULL, activeanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2450. }
  2451. if(activeanim3!=NULL)
  2452. {
  2453. DDBLTFX fx;
  2454. memset(&fx, 0, sizeof(DDBLTFX));
  2455. fx.dwSize=sizeof(DDBLTFX);
  2456. lpT[i]->Blt(NULL, activeanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2457. }
  2458. if(superanim1!=NULL)
  2459. {
  2460. DDBLTFX fx;
  2461. memset(&fx, 0, sizeof(DDBLTFX));
  2462. fx.dwSize=sizeof(DDBLTFX);
  2463. lpT[i]->Blt(NULL, superanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2464. }
  2465. if(superanim2!=NULL)
  2466. {
  2467. DDBLTFX fx;
  2468. memset(&fx, 0, sizeof(DDBLTFX));
  2469. fx.dwSize=sizeof(DDBLTFX);
  2470. lpT[i]->Blt(NULL, superanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2471. }
  2472. if(superanim3!=NULL)
  2473. {
  2474. DDBLTFX fx;
  2475. memset(&fx, 0, sizeof(DDBLTFX));
  2476. fx.dwSize=sizeof(DDBLTFX);
  2477. lpT[i]->Blt(NULL, superanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2478. }
  2479. if(superanim4!=NULL)
  2480. {
  2481. DDBLTFX fx;
  2482. memset(&fx, 0, sizeof(DDBLTFX));
  2483. fx.dwSize=sizeof(DDBLTFX);
  2484. lpT[i]->Blt(NULL, superanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2485. }
  2486. if(specialanim1!=NULL)
  2487. {
  2488. DDBLTFX fx;
  2489. memset(&fx, 0, sizeof(DDBLTFX));
  2490. fx.dwSize=sizeof(DDBLTFX);
  2491. lpT[i]->Blt(NULL, specialanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2492. }
  2493. if(specialanim2!=NULL)
  2494. {
  2495. DDBLTFX fx;
  2496. memset(&fx, 0, sizeof(DDBLTFX));
  2497. fx.dwSize=sizeof(DDBLTFX);
  2498. lpT[i]->Blt(NULL, specialanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2499. }
  2500. if(specialanim3!=NULL)
  2501. {
  2502. DDBLTFX fx;
  2503. memset(&fx, 0, sizeof(DDBLTFX));
  2504. fx.dwSize=sizeof(DDBLTFX);
  2505. lpT[i]->Blt(NULL, specialanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2506. }
  2507. if(specialanim4!=NULL)
  2508. {
  2509. DDBLTFX fx;
  2510. memset(&fx, 0, sizeof(DDBLTFX));
  2511. fx.dwSize=sizeof(DDBLTFX);
  2512. lpT[i]->Blt(NULL, specialanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx);
  2513. }
  2514. if(turrets[i]!=NULL)
  2515. {
  2516. DDBLTFX fx;
  2517. int iMove=0;
  2518. DDSURFACEDESC2 ddsd;
  2519. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  2520. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  2521. ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  2522. turrets[i]->GetSurfaceDesc(&ddsd);
  2523. memset(&fx, 0, sizeof(DDBLTFX));
  2524. fx.dwSize=sizeof(DDBLTFX);
  2525. RECT srcRect, destRect;
  2526. srcRect.left=0;
  2527. srcRect.right=ddsd.dwWidth;
  2528. destRect.left=(head.cx-ddsd.dwWidth)/2;
  2529. destRect.right=head.cx-destRect.left;
  2530. if(iMove<0)
  2531. {
  2532. srcRect.top=-iMove;
  2533. srcRect.bottom=ddsd.dwHeight;
  2534. destRect.top=0;
  2535. destRect.bottom=head.cy+iMove-(head.cy-ddsd.dwHeight);
  2536. }
  2537. else
  2538. {
  2539. int mx=imghead.x/2+imghead.cx/2+(-turretinfo[i].x/2-turretinfo[i].cx)+ atoi(rules.sections[image].values["TurretAnimX"]);
  2540. int my=imghead.y/2+imghead.cy/2+(-turretinfo[i].y/2-turretinfo[i].cy) + atoi(rules.sections[image].values["TurretAnimY"]);//+atoi(rules.sections[image].values["TurretAnimZAdjust"]);
  2541. if(ddsd.dwWidth!=head.cx || ddsd.dwHeight!=head.cy)
  2542. {
  2543. // voxel turret
  2544. //mx=head.cx/2-ddsd.dwWidth/2;//+atoi(rules.sections[image].values["TurretAnimX"]);
  2545. //my=head.cy/2-ddsd.dwHeight/2+atoi(rules.sections[image].values["TurretAnimY"])+atoi(rules.sections[image].values["TurretAnimZAdjust"])/2;
  2546. mx=imghead.x+imghead.cx/2+turretinfo[i].x+atoi(rules.sections[image].values["TurretAnimX"]);
  2547. my=imghead.y+imghead.cy/2+turretinfo[i].y+atoi(rules.sections[image].values["TurretAnimY"]);//+atoi(rules.sections[image].values["TurretAnimZAdjust"])/2;
  2548. errstream << turretinfo[i].x << " y:" << turretinfo[i].y << " mx:" << mx << " my:" << my << endl;
  2549. errstream.flush();
  2550. int XMover, YMover;
  2551. #ifdef RA2_MODE
  2552. XMover=atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype+"X"]);
  2553. YMover=atoi(g_data.sections["BuildingVoxelTurretsRA2"].values[(CString)lpUnittype+"Y"]);
  2554. #else
  2555. XMover=atoi(g_data.sections["BuildingVoxelTurrets"].values[(CString)lpUnittype+"X"]);
  2556. YMover=atoi(g_data.sections["BuildingVoxelTurrets"].values[(CString)lpUnittype+"Y"]);
  2557. #endif
  2558. mx+=XMover;
  2559. my+=YMover;
  2560. srcRect.top=0;
  2561. srcRect.left=0;
  2562. srcRect.right=ddsd.dwWidth;
  2563. srcRect.bottom=ddsd.dwHeight;
  2564. destRect.top=my;
  2565. destRect.left=mx;
  2566. destRect.right=destRect.left+ddsd.dwWidth;
  2567. destRect.bottom=destRect.top+ddsd.dwHeight;
  2568. if(destRect.top<0)
  2569. {
  2570. int old=destRect.top;
  2571. destRect.top=0;
  2572. srcRect.top-=old-destRect.top;
  2573. }
  2574. if(destRect.right>=head.cx)
  2575. {
  2576. int old=destRect.right;
  2577. destRect.right=head.cx;
  2578. srcRect.right-=old-destRect.right;
  2579. }
  2580. if(destRect.bottom>=head.cy)
  2581. {
  2582. int old=destRect.bottom;
  2583. destRect.bottom=head.cy;
  2584. srcRect.bottom-=old-destRect.bottom;
  2585. }
  2586. }
  2587. else
  2588. {
  2589. if(mx<0)mx=0;
  2590. if(my<0)my=0;
  2591. srcRect.top=0;
  2592. srcRect.right=ddsd.dwWidth-mx;
  2593. srcRect.bottom=ddsd.dwHeight-my;
  2594. destRect.top=my;
  2595. destRect.left=mx+(head.cx-ddsd.dwWidth)/2;
  2596. destRect.right=destRect.left+ddsd.dwWidth;;
  2597. destRect.bottom=destRect.top+ddsd.dwHeight;
  2598. }
  2599. }
  2600. if(lpT[i]->Blt(&destRect, turrets[i], &srcRect, DDBLT_KEYSRC | DDBLT_WAIT, &fx)!=DD_OK)
  2601. {
  2602. errstream << "vxl turret: " << i << " size: " << ddsd.dwWidth << " " << ddsd.dwHeight << " failed" << endl;
  2603. errstream.flush();
  2604. //exit(-99);
  2605. }
  2606. }
  2607. if(!bPowerUp && i!=0 && imghead.unknown==0 && bStructure)
  2608. {
  2609. if(lpT[i]) lpT[i]->Release();
  2610. }
  2611. else
  2612. {
  2613. char ic[50];
  2614. itoa(i, ic, 10);
  2615. PICDATA p;
  2616. p.pic=lpT[i];
  2617. p.x=imghead.x;
  2618. p.y=imghead.y;
  2619. p.wHeight=imghead.cy;
  2620. p.wWidth=imghead.cx;
  2621. p.wMaxWidth=head.cx;
  2622. p.wMaxHeight=head.cy;
  2623. p.bType=PICDATA_TYPE_SHP;
  2624. p.bTerrain=bTerrain;
  2625. if(bIgnoreTerrain) p.bTerrain=0;
  2626. pics[image+ic]=p;
  2627. //errstream << " --> finished as " << (LPCSTR)(image+ic) << endl;
  2628. //errstream.flush();
  2629. }
  2630. }
  2631. delete[] lpT;
  2632. if(bib) bib->Release();
  2633. if(activeanim)activeanim->Release();
  2634. if(idleanim)idleanim->Release();
  2635. if(activeanim2)activeanim2->Release();
  2636. if(activeanim3)activeanim3->Release();
  2637. if(superanim1)superanim1->Release();
  2638. if(superanim2)superanim2->Release();
  2639. if(superanim3)superanim3->Release();
  2640. if(superanim4)superanim4->Release();
  2641. if(specialanim1)specialanim1->Release();
  2642. if(specialanim2)specialanim2->Release();
  2643. if(specialanim3)specialanim3->Release();
  2644. if(specialanim4)specialanim4->Release();
  2645. for(i=0;i<8;i++)
  2646. if(turrets[i])turrets[i]->Release();
  2647. }
  2648. //errstream << " --> Finished" << endl;
  2649. //errstream.flush();
  2650. }
  2651. else
  2652. {
  2653. errstream << "File in theater " << cur_theat << " not found: " << (LPCTSTR)filename << endl;
  2654. errstream.flush();
  2655. missingimages[lpUnittype]=TRUE;
  2656. }
  2657. }
  2658. catch(...)
  2659. {
  2660. errstream << " exception " << endl;
  2661. errstream.flush();
  2662. }
  2663. }
  2664. else
  2665. {
  2666. filename=image+".vxl";
  2667. HMIXFILE hMix=FindFileInMix(filename);
  2668. if(hMix==FALSE)
  2669. {
  2670. missingimages[lpUnittype]=TRUE;
  2671. return FALSE;
  2672. }
  2673. int i;
  2674. try
  2675. {
  2676. for(i=0;i<8;i++)
  2677. {
  2678. float r_x,r_y,r_z;
  2679. r_x=300;
  2680. r_y=0;
  2681. r_z=45*i+90;
  2682. // convert
  2683. const double pi = 3.141592654;
  2684. r_x=r_x/180.0f*pi;
  2685. r_y=r_y/180.0f*pi;
  2686. r_z=r_z/180.0f*pi;
  2687. LPDIRECTDRAWSURFACE4 lpT;//=new(LPDIRECTDRAWSURFACE4[1]);
  2688. LPDIRECTDRAWSURFACE4 lpTurret=NULL;
  2689. LPDIRECTDRAWSURFACE4 lpBarrel=NULL;
  2690. int turret_x,turret_y,turret_x_zmax,turret_y_zmax,barrel_x,barrel_y;
  2691. if(isTrue(rules.sections[lpUnittype].values["Turret"]))
  2692. {
  2693. if(FSunPackLib::SetCurrentVXL(image+"tur.vxl", hMix))
  2694. {
  2695. FSunPackLib::LoadVXLImageInSurface(*m_voxelNormalTables, lightDirection, v.dd, 0, 1, r_x, r_y, r_z, &lpTurret, m_hPalUnitTemp,&turret_x,&turret_y,0,&turret_x_zmax, &turret_y_zmax,-1,-1);
  2696. }
  2697. if(FSunPackLib::SetCurrentVXL(image+"barl.vxl", hMix))
  2698. {
  2699. FSunPackLib::LoadVXLImageInSurface(*m_voxelNormalTables, lightDirection, v.dd, 0, 1, r_x, r_y, r_z, &lpBarrel, m_hPalUnitTemp,&barrel_x,&barrel_y,0,NULL,NULL,0,0);
  2700. }
  2701. }
  2702. if(!FSunPackLib::SetCurrentVXL(filename, hMix))
  2703. {
  2704. return FALSE;
  2705. }
  2706. int xcenter,ycenter,xcenter_zmax,ycenter_zmax;
  2707. if(!
  2708. FSunPackLib::LoadVXLImageInSurface(*m_voxelNormalTables, lightDirection, v.dd, 0, 1, r_x, r_y, r_z, &lpT, m_hPalUnitTemp,&xcenter, &ycenter,0,&xcenter_zmax,&ycenter_zmax)
  2709. )
  2710. {
  2711. return FALSE;
  2712. }
  2713. DDSURFACEDESC2 ddsd;
  2714. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  2715. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  2716. ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  2717. lpT->GetSurfaceDesc(&ddsd);
  2718. // turret
  2719. if(lpTurret)
  2720. {
  2721. DDSURFACEDESC2 ddsdT;
  2722. memset(&ddsdT, 0, sizeof(DDSURFACEDESC2));
  2723. ddsdT.dwSize=sizeof(DDSURFACEDESC2);
  2724. ddsdT.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  2725. lpTurret->GetSurfaceDesc(&ddsdT);
  2726. DDBLTFX fx;
  2727. memset(&fx, 0, sizeof(DDBLTFX));
  2728. fx.dwSize=sizeof(DDBLTFX);
  2729. RECT srcRect, destRect;
  2730. srcRect.left=0;
  2731. srcRect.right=ddsdT.dwWidth;
  2732. destRect.left=xcenter_zmax-turret_x;
  2733. destRect.right=destRect.left+ddsdT.dwWidth;
  2734. srcRect.top=0;
  2735. srcRect.bottom=ddsdT.dwHeight;
  2736. destRect.top=ycenter_zmax-turret_y;
  2737. destRect.bottom=destRect.top+ddsdT.dwHeight;
  2738. lpT->Blt(&destRect, lpTurret, &srcRect, DDBLT_KEYSRC | DDBLT_WAIT, &fx);
  2739. }
  2740. // barrel
  2741. if(lpBarrel)
  2742. {
  2743. DDSURFACEDESC2 ddsdB;
  2744. memset(&ddsdB, 0, sizeof(DDSURFACEDESC2));
  2745. ddsdB.dwSize=sizeof(DDSURFACEDESC2);
  2746. ddsdB.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  2747. lpBarrel->GetSurfaceDesc(&ddsdB);
  2748. DDSURFACEDESC2 ddsdT;
  2749. memset(&ddsdT, 0, sizeof(DDSURFACEDESC2));
  2750. ddsdT.dwSize=sizeof(DDSURFACEDESC2);
  2751. ddsdT.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  2752. if(lpTurret) lpTurret->GetSurfaceDesc(&ddsdT);
  2753. DDBLTFX fx;
  2754. memset(&fx, 0, sizeof(DDBLTFX));
  2755. fx.dwSize=sizeof(DDBLTFX);
  2756. RECT srcRect, destRect;
  2757. srcRect.left=0;
  2758. srcRect.right=ddsdB.dwWidth;
  2759. destRect.left=xcenter_zmax-barrel_x+(turret_x_zmax-turret_x);
  2760. destRect.right=destRect.left+ddsdB.dwWidth;
  2761. srcRect.top=0;
  2762. srcRect.bottom=ddsdB.dwHeight;
  2763. destRect.top=ycenter_zmax-barrel_y+(turret_y_zmax-turret_y);
  2764. destRect.bottom=destRect.top+ddsdB.dwHeight;
  2765. lpT->Blt(&destRect, lpBarrel, &srcRect, DDBLT_KEYSRC | DDBLT_WAIT, &fx);
  2766. }
  2767. char ic[50];
  2768. itoa(7-i, ic, 10);
  2769. errstream << ddsd.dwWidth << " " << ddsd.dwHeight << "\n";
  2770. PICDATA p;
  2771. p.pic=lpT;
  2772. p.x=-xcenter;
  2773. p.y=-ycenter;
  2774. p.wHeight=ddsd.dwHeight;
  2775. p.wWidth=ddsd.dwWidth;
  2776. p.wMaxWidth=ddsd.dwWidth;
  2777. p.wMaxHeight=ddsd.dwHeight;
  2778. p.bType=PICDATA_TYPE_VXL;
  2779. p.bTerrain=0;
  2780. pics[image+ic]=p;
  2781. errstream << "vxl saved as " << (LPCSTR)image << (LPCSTR)ic << endl;
  2782. errstream.flush();
  2783. if(lpBarrel) lpBarrel->Release();
  2784. if(lpTurret) lpTurret->Release();
  2785. //delete[] lpT;
  2786. }
  2787. }
  2788. catch(...)
  2789. {
  2790. }
  2791. }
  2792. return FALSE;
  2793. }
  2794. #endif
  2795. BOOL CLoading::InitMixFiles()
  2796. {
  2797. last_succeeded_operation=8;
  2798. MEMORYSTATUS ms;
  2799. ms.dwLength=sizeof(MEMORYSTATUS);
  2800. GlobalMemoryStatus(&ms);
  2801. int cs=ms.dwAvailPhys+ms.dwAvailPageFile;
  2802. errstream << "InitMixFiles() called. Available memory: " << cs << endl;
  2803. errstream.flush();
  2804. // load tibsun.mix and local.mix
  2805. if(DoesFileExist((CString)TSPath+(CString)"\\"+MAINMIX))
  2806. {
  2807. errstream << "Loading " MAINMIX ".mix" ;
  2808. errstream.flush();
  2809. m_hTibSun=FSunPackLib::XCC_OpenMix((CString)TSPath+(CString)"\\"+MAINMIX, NULL);
  2810. if(m_hTibSun!=NULL)
  2811. {
  2812. errstream << " success" << endl;
  2813. errstream.flush();
  2814. }
  2815. else
  2816. {
  2817. ShowWindow(SW_HIDE);
  2818. MessageBox(GetLanguageStringACP("Err_TSNotInstalled"));
  2819. exit(200);
  2820. }
  2821. m_hLanguage=FSunPackLib::XCC_OpenMix((CString)TSPath+(CString)"\\Language.mix", NULL);
  2822. m_hLangMD=FSunPackLib::XCC_OpenMix((CString)TSPath+(CString)"\\Langmd.mix", NULL);
  2823. m_hMarble=FSunPackLib::XCC_OpenMix((CString)TSPath+(CString)"\\marble.mix", NULL);
  2824. //if(!m_hLanguage) MessageBox("No language file found");
  2825. if(!m_hMarble)
  2826. {
  2827. m_hMarble=FSunPackLib::XCC_OpenMix((CString)AppPath+(CString)"\\marble.mix", NULL);
  2828. }
  2829. }
  2830. else
  2831. {
  2832. ShowWindow(SW_HIDE);
  2833. MessageBox(GetLanguageStringACP("Err_TSNotInstalled"));
  2834. exit(199);
  2835. }
  2836. errstream << "Loading local.mix";
  2837. errstream.flush();
  2838. if(DoesFileExist((CString)TSPath+"\\Local.mix")==FALSE || theApp.m_Options.bSearchLikeTS==FALSE)
  2839. {
  2840. m_hLocal=FSunPackLib::XCC_OpenMix("Local.mix", m_hTibSun);
  2841. }
  2842. else
  2843. m_hLocal=FSunPackLib::XCC_OpenMix((CString)TSPath+"\\Local.mix", NULL);
  2844. errstream << " successful" << endl;
  2845. errstream.flush();
  2846. errstream << "Loading conquer.mix, temperat.mix, isotemp.mix, isosnow.mix, isourb.mix and cache.mix";
  2847. errstream.flush();
  2848. m_hConquer=FSunPackLib::XCC_OpenMix("conquer.mix", m_hTibSun);
  2849. m_hTemperat=FSunPackLib::XCC_OpenMix("temperat.mix", m_hTibSun);
  2850. m_hUrban=FSunPackLib::XCC_OpenMix("urban.mix", m_hTibSun);
  2851. m_hSnow=FSunPackLib::XCC_OpenMix("snow.mix", m_hTibSun);
  2852. m_hUrbanN=FSunPackLib::XCC_OpenMix("urbann.mix", m_hTibSun);
  2853. m_hLunar=FSunPackLib::XCC_OpenMix("lunar.mix", m_hTibSun);
  2854. m_hDesert=FSunPackLib::XCC_OpenMix("desert.mix", m_hTibSun);
  2855. m_hIsoTemp=FSunPackLib::XCC_OpenMix("isotemp.mix", m_hTibSun);
  2856. m_hIsoSnow=FSunPackLib::XCC_OpenMix("isosnow.mix", m_hTibSun);
  2857. m_hIsoUrb=FSunPackLib::XCC_OpenMix("isourb.mix", m_hTibSun);
  2858. m_hIsoUbn=FSunPackLib::XCC_OpenMix("isoubn.mix", m_hTibSun);
  2859. m_hIsoLun=FSunPackLib::XCC_OpenMix("isolun.mix", m_hTibSun);
  2860. m_hIsoDes=FSunPackLib::XCC_OpenMix("isodes.mix", m_hTibSun);
  2861. m_hIsoGen=FSunPackLib::XCC_OpenMix("isogen.mix", m_hTibSun);
  2862. //m_hBuildings=FSunPackLib::XCC_OpenMix("_ID1085587737", m_hTibSun);
  2863. m_hBuildings=FSunPackLib::XCC_OpenMix("Generic.mix", m_hTibSun);
  2864. m_hCache=FSunPackLib::XCC_OpenMix("cache.mix", m_hTibSun);
  2865. m_hTem=FSunPackLib::XCC_OpenMix("tem.mix", m_hTibSun);
  2866. m_hSno=FSunPackLib::XCC_OpenMix("sno.mix", m_hTibSun);
  2867. m_hUrb=FSunPackLib::XCC_OpenMix("urb.mix", m_hTibSun);
  2868. m_hUbn=FSunPackLib::XCC_OpenMix("ubn.mix", m_hTibSun);
  2869. m_hLun=FSunPackLib::XCC_OpenMix("lun.mix", m_hTibSun);
  2870. m_hDes=FSunPackLib::XCC_OpenMix("des.mix", m_hTibSun);
  2871. if(!m_hMarble) FSunPackLib::XCC_OpenMix("marble.mix", m_hTibSun);
  2872. if(m_hMarble) theApp.m_Options.bSupportMarbleMadness=TRUE;
  2873. errstream << " successful" << endl;
  2874. errstream.flush();
  2875. int i;
  2876. yuri_mode=FALSE;
  2877. if(!theApp.m_Options.bSearchLikeTS) return TRUE;
  2878. if(DoesFileExist((CString)TSPath+"\\ra2md.mix"))
  2879. yuri_mode=TRUE; // MW Apr 17th, make it available right here!
  2880. // load expansion mix files
  2881. for(i=0;i<101;i++)
  2882. {
  2883. CString expand;
  2884. char n[50];
  2885. // MW April 17th, 2002:
  2886. // read expandxxmd.mix files in yurimode
  2887. itoa(i, n, 10);
  2888. expand=TSPath;
  2889. expand+="\\Expand";
  2890. if(yuri_mode) expand+="md";
  2891. if(i<10) expand+="0";
  2892. expand+=n;
  2893. expand+=".mix";
  2894. CString nappend=".mix";
  2895. CString append=".mix";
  2896. if(i==100) append="md.mix";
  2897. if(yuri_mode) append="md.mix";
  2898. if(i==100) expand=(CString)TSPath+"\\ra2md.mix"; // support the mission disk!!!
  2899. errstream << "Searching " << (LPCTSTR)expand << endl;
  2900. errstream.flush();
  2901. if(DoesFileExist(expand))
  2902. {
  2903. OutputDebugString(expand);
  2904. OutputDebugString(": ");
  2905. m_hExpand[i].hExpand=FSunPackLib::XCC_OpenMix(expand, NULL);
  2906. #ifdef YR_MODE
  2907. if(i==100 && m_hExpand[i].hExpand) yuri_mode=TRUE;
  2908. #endif
  2909. errstream << (LPCTSTR)expand << " found: loading ";
  2910. errstream.flush();
  2911. CString conquer="conquer";
  2912. if(i==100) conquer="conq";
  2913. if(FSunPackLib::XCC_DoesFileExist(conquer+append, m_hExpand[i].hExpand))
  2914. {
  2915. OutputDebugString(conquer+append);
  2916. OutputDebugString(": ");
  2917. m_hExpand[i].hConquer=FSunPackLib::XCC_OpenMix((CString)conquer+append, m_hExpand[i].hExpand);
  2918. errstream << "conquer.mix, ";
  2919. }
  2920. if(FSunPackLib::XCC_DoesFileExist((CString)"local"+append, m_hExpand[i].hExpand))
  2921. {
  2922. OutputDebugString((CString)"local"+append);
  2923. OutputDebugString(": ");
  2924. m_hExpand[i].hLocal=FSunPackLib::XCC_OpenMix((CString)"local"+append, m_hExpand[i].hExpand);
  2925. errstream << "local.mix, ";
  2926. }
  2927. //if(FSunPackLib::XCC_DoesFileExist("_ID1085587737", m_hExpand[i].hExpand))
  2928. {
  2929. //m_hExpand[i].hConquer=FSunPackLib::XCC_OpenMix("_ID1085587737", m_hExpand[i].hExpand);
  2930. //errstream << "1085587737, ";
  2931. }
  2932. if(FSunPackLib::XCC_DoesFileExist((CString)"temperat"+append, m_hExpand[i].hExpand))
  2933. {
  2934. OutputDebugString((CString)"temperat"+append);
  2935. OutputDebugString(": ");
  2936. m_hExpand[i].hTemperat=FSunPackLib::XCC_OpenMix((CString)"temperat"+append, m_hExpand[i].hExpand);
  2937. errstream << "temperat.mix, ";
  2938. errstream.flush();
  2939. }
  2940. if(FSunPackLib::XCC_DoesFileExist((CString)"urban"+append, m_hExpand[i].hExpand))
  2941. {
  2942. OutputDebugString((CString)"urban"+append);
  2943. OutputDebugString(": ");
  2944. m_hExpand[i].hUrban=FSunPackLib::XCC_OpenMix((CString)"urban"+append, m_hExpand[i].hExpand);
  2945. errstream << "urban.mix, ";
  2946. errstream.flush();
  2947. }
  2948. if(FSunPackLib::XCC_DoesFileExist((CString)"snow"+append, m_hExpand[i].hExpand))
  2949. {
  2950. OutputDebugString((CString)"snow"+append);
  2951. OutputDebugString(": ");
  2952. FSunPackLib::_DEBUG_EnableLogs=true;
  2953. HMIXFILE hM=FSunPackLib::XCC_OpenMix((CString)"snow"+append, m_hExpand[i].hExpand);
  2954. m_hExpand[i].hSnow=hM;
  2955. errstream << "snow.mix, ";
  2956. errstream.flush();
  2957. FSunPackLib::_DEBUG_EnableLogs=false;
  2958. }
  2959. CString generic="generic";
  2960. if(i==100) generic="gener";
  2961. if(FSunPackLib::XCC_DoesFileExist((CString)generic+append, m_hExpand[i].hExpand))
  2962. {
  2963. m_hExpand[i].hGeneric=FSunPackLib::XCC_OpenMix((CString)generic+append, m_hExpand[i].hExpand);
  2964. errstream << "generic.mix, ";
  2965. errstream.flush();
  2966. }
  2967. if(FSunPackLib::XCC_DoesFileExist((CString)"urbann"+nappend, m_hExpand[i].hExpand))
  2968. {
  2969. m_hExpand[i].hUrbanN=FSunPackLib::XCC_OpenMix((CString)"urbann"+nappend, m_hExpand[i].hExpand);
  2970. errstream << "urbann.mix, ";
  2971. errstream.flush();
  2972. }
  2973. if(FSunPackLib::XCC_DoesFileExist((CString)"lunar"+nappend, m_hExpand[i].hExpand))
  2974. {
  2975. m_hExpand[i].hLunar=FSunPackLib::XCC_OpenMix((CString)"lunar"+nappend, m_hExpand[i].hExpand);
  2976. errstream << "lunar.mix, ";
  2977. errstream.flush();
  2978. }
  2979. if(FSunPackLib::XCC_DoesFileExist((CString)"desert"+nappend, m_hExpand[i].hExpand))
  2980. {
  2981. m_hExpand[i].hDesert=FSunPackLib::XCC_OpenMix((CString)"desert"+nappend, m_hExpand[i].hExpand);
  2982. errstream << "desert.mix, ";
  2983. errstream.flush();
  2984. }
  2985. CString isotemp="isotemp";
  2986. if(i==100) isotemp="isotem";
  2987. if(FSunPackLib::XCC_DoesFileExist(isotemp+append, m_hExpand[i].hExpand))
  2988. {
  2989. m_hExpand[i].hIsoTemp=FSunPackLib::XCC_OpenMix((CString)isotemp+append, m_hExpand[i].hExpand);
  2990. errstream << "isotemp.mix, ";
  2991. errstream.flush();
  2992. }
  2993. CString isosnow="isosnow";
  2994. if(i==100) isosnow="isosno";
  2995. if(FSunPackLib::XCC_DoesFileExist((CString)isosnow+append, m_hExpand[i].hExpand))
  2996. {
  2997. m_hExpand[i].hIsoSnow=FSunPackLib::XCC_OpenMix((CString)isosnow+append, m_hExpand[i].hExpand);
  2998. errstream << "isosnow.mix, ";
  2999. errstream.flush();
  3000. }
  3001. if(FSunPackLib::XCC_DoesFileExist((CString)"isourb"+append, m_hExpand[i].hExpand))
  3002. {
  3003. m_hExpand[i].hIsoUrb=FSunPackLib::XCC_OpenMix((CString)"isourb"+append, m_hExpand[i].hExpand);
  3004. errstream << "isourb.mix, ";
  3005. errstream.flush();
  3006. }
  3007. if(FSunPackLib::XCC_DoesFileExist((CString)"isoubn"+append, m_hExpand[i].hExpand))
  3008. {
  3009. m_hExpand[i].hIsoUbnMd=FSunPackLib::XCC_OpenMix((CString)"isoubn"+append, m_hExpand[i].hExpand);
  3010. errstream << "isoubn.mix, ";
  3011. errstream.flush();
  3012. }
  3013. if(FSunPackLib::XCC_DoesFileExist((CString)"isolun"+append, m_hExpand[i].hExpand))
  3014. {
  3015. m_hExpand[i].hIsoLunMd=FSunPackLib::XCC_OpenMix((CString)"isolun"+append, m_hExpand[i].hExpand);
  3016. errstream << "isolun.mix, ";
  3017. errstream.flush();
  3018. }
  3019. if(FSunPackLib::XCC_DoesFileExist((CString)"isodes"+append, m_hExpand[i].hExpand))
  3020. {
  3021. m_hExpand[i].hIsoDesMd=FSunPackLib::XCC_OpenMix((CString)"isodes"+append, m_hExpand[i].hExpand);
  3022. errstream << "isodes.mix, ";
  3023. errstream.flush();
  3024. }
  3025. if(FSunPackLib::XCC_DoesFileExist((CString)"isoubn"+nappend, m_hExpand[i].hExpand))
  3026. {
  3027. m_hExpand[i].hIsoUbn=FSunPackLib::XCC_OpenMix((CString)"isoubn"+nappend, m_hExpand[i].hExpand);
  3028. errstream << "isoubn.mix, ";
  3029. errstream.flush();
  3030. }
  3031. if(FSunPackLib::XCC_DoesFileExist((CString)"isolun"+nappend, m_hExpand[i].hExpand))
  3032. {
  3033. m_hExpand[i].hIsoLun=FSunPackLib::XCC_OpenMix((CString)"isolun"+nappend, m_hExpand[i].hExpand);
  3034. errstream << "isolun.mix, ";
  3035. errstream.flush();
  3036. }
  3037. if(FSunPackLib::XCC_DoesFileExist((CString)"isodes"+nappend, m_hExpand[i].hExpand))
  3038. {
  3039. m_hExpand[i].hIsoDes=FSunPackLib::XCC_OpenMix((CString)"isodes"+nappend, m_hExpand[i].hExpand);
  3040. errstream << "isodes.mix, ";
  3041. errstream.flush();
  3042. }
  3043. if(FSunPackLib::XCC_DoesFileExist((CString)"isogen"+append, m_hExpand[i].hExpand))
  3044. {
  3045. m_hExpand[i].hIsoGenMd=FSunPackLib::XCC_OpenMix((CString)"isogen"+append, m_hExpand[i].hExpand);
  3046. errstream << "isogen.mix, ";
  3047. errstream.flush();
  3048. }
  3049. if(FSunPackLib::XCC_DoesFileExist((CString)"isogen"+nappend, m_hExpand[i].hExpand))
  3050. {
  3051. m_hExpand[i].hIsoGen=FSunPackLib::XCC_OpenMix((CString)"isogen"+nappend, m_hExpand[i].hExpand);
  3052. errstream << "isogen.mix, ";
  3053. errstream.flush();
  3054. }
  3055. CString cache="ecache01";
  3056. if(i==100) cache="cache";
  3057. if(FSunPackLib::XCC_DoesFileExist((CString)cache+append, m_hExpand[i].hExpand))
  3058. {
  3059. m_hExpand[i].hECache=FSunPackLib::XCC_OpenMix((CString)cache+append, m_hExpand[i].hExpand);
  3060. errstream << LPCSTR("ecache01"+append+", ");
  3061. errstream.flush();
  3062. }
  3063. if(FSunPackLib::XCC_DoesFileExist((CString)"tem"+append, m_hExpand[i].hExpand))
  3064. {
  3065. m_hExpand[i].hTem=FSunPackLib::XCC_OpenMix((CString)"tem"+append, m_hExpand[i].hExpand);
  3066. errstream << LPCSTR("tem"+append+", ");
  3067. errstream.flush();
  3068. }
  3069. if(FSunPackLib::XCC_DoesFileExist((CString)"sno"+append, m_hExpand[i].hExpand))
  3070. {
  3071. m_hExpand[i].hSno=FSunPackLib::XCC_OpenMix((CString)"sno"+append, m_hExpand[i].hExpand);
  3072. errstream << LPCSTR("sno"+append+", ");
  3073. errstream.flush();
  3074. }
  3075. if(FSunPackLib::XCC_DoesFileExist((CString)"urb"+append, m_hExpand[i].hExpand))
  3076. {
  3077. m_hExpand[i].hUrb=FSunPackLib::XCC_OpenMix((CString)"urb"+append, m_hExpand[i].hExpand);
  3078. errstream << LPCSTR("urb"+append+", ");
  3079. errstream.flush();
  3080. }
  3081. if(FSunPackLib::XCC_DoesFileExist((CString)"ubn"+nappend, m_hExpand[i].hExpand))
  3082. {
  3083. m_hExpand[i].hUbn=FSunPackLib::XCC_OpenMix((CString)"ubn"+nappend, m_hExpand[i].hExpand);
  3084. errstream << LPCSTR("ubn"+nappend+", ");
  3085. errstream.flush();
  3086. }
  3087. if(FSunPackLib::XCC_DoesFileExist((CString)"lun"+nappend, m_hExpand[i].hExpand))
  3088. {
  3089. m_hExpand[i].hLun=FSunPackLib::XCC_OpenMix((CString)"lun"+nappend, m_hExpand[i].hExpand);
  3090. errstream << LPCSTR("lun"+nappend+", ");
  3091. errstream.flush();
  3092. }
  3093. if(FSunPackLib::XCC_DoesFileExist((CString)"des"+nappend, m_hExpand[i].hExpand))
  3094. {
  3095. m_hExpand[i].hDes=FSunPackLib::XCC_OpenMix((CString)"des"+nappend, m_hExpand[i].hExpand);
  3096. errstream << LPCSTR("des"+nappend+", ");
  3097. errstream.flush();
  3098. }
  3099. if(FSunPackLib::XCC_DoesFileExist((CString)"marble"+append, m_hExpand[i].hExpand))
  3100. {
  3101. theApp.m_Options.bSupportMarbleMadness=TRUE;
  3102. m_hExpand[i].hMarble=FSunPackLib::XCC_OpenMix((CString)"marble"+append, m_hExpand[i].hExpand);
  3103. errstream << LPCSTR("marble"+append+", ");
  3104. errstream.flush();
  3105. }
  3106. errstream << endl;
  3107. errstream.flush();
  3108. }
  3109. else
  3110. {
  3111. m_hExpand[i].hExpand=NULL;
  3112. }
  3113. }
  3114. // load expansion ecache mix files
  3115. for(i=0;i<100;i++)
  3116. {
  3117. CString expand;
  3118. char n[50];
  3119. itoa(i, n, 10);
  3120. expand=TSPath;
  3121. if(!yuri_mode) expand+="\\ECache";
  3122. else expand+="\\ecachemd";
  3123. if(i<10) expand+="0";
  3124. expand+=n;
  3125. expand+=".mix";
  3126. if(DoesFileExist(expand))
  3127. {
  3128. m_hECache[i]=FSunPackLib::XCC_OpenMix(expand, NULL);
  3129. errstream << (LPCTSTR)expand << " found and loaded" << endl;
  3130. errstream.flush();
  3131. }
  3132. else
  3133. {
  3134. m_hECache[i]=NULL;
  3135. }
  3136. }
  3137. ms.dwLength=sizeof(MEMORYSTATUS);
  3138. GlobalMemoryStatus(&ms);
  3139. cs=ms.dwAvailPhys+ms.dwAvailPageFile;
  3140. errstream << "InitMixFiles() finished. Available memory: " << cs << endl;
  3141. errstream.flush();
  3142. return TRUE;
  3143. }
  3144. CLoading::~CLoading()
  3145. {
  3146. Unload();
  3147. }
  3148. void CLoading::Unload()
  3149. {
  3150. FSunPackLib::XCC_CloseMix(m_hCache);
  3151. FSunPackLib::XCC_CloseMix(m_hConquer);
  3152. FSunPackLib::XCC_CloseMix(m_hIsoSnow);
  3153. FSunPackLib::XCC_CloseMix(m_hIsoTemp);
  3154. FSunPackLib::XCC_CloseMix(m_hIsoUrb);
  3155. FSunPackLib::XCC_CloseMix(m_hIsoGen);
  3156. FSunPackLib::XCC_CloseMix(m_hLocal);
  3157. FSunPackLib::XCC_CloseMix(m_hTemperat);
  3158. FSunPackLib::XCC_CloseMix(m_hSnow);
  3159. FSunPackLib::XCC_CloseMix(m_hUrban);
  3160. FSunPackLib::XCC_CloseMix(m_hTibSun);
  3161. FSunPackLib::XCC_CloseMix(m_hSno);
  3162. FSunPackLib::XCC_CloseMix(m_hTem);
  3163. FSunPackLib::XCC_CloseMix(m_hUrb);
  3164. FSunPackLib::XCC_CloseMix(m_hBuildings);
  3165. m_hCache = NULL;
  3166. m_hConquer = NULL;
  3167. m_hIsoSnow = NULL;
  3168. m_hIsoTemp = NULL;
  3169. m_hIsoUrb = NULL;
  3170. m_hLocal = NULL;
  3171. m_hTemperat = NULL;
  3172. m_hSnow = NULL;
  3173. m_hUrban = NULL;
  3174. m_hTibSun = NULL;
  3175. m_hBuildings = NULL;
  3176. m_hIsoGen = NULL;
  3177. int i = 0;
  3178. for (i = 0;i < 100; i++)
  3179. {
  3180. FSunPackLib::XCC_CloseMix(m_hExpand[i].hExpand);
  3181. FSunPackLib::XCC_CloseMix(m_hExpand[i].hConquer);
  3182. FSunPackLib::XCC_CloseMix(m_hExpand[i].hECache);
  3183. FSunPackLib::XCC_CloseMix(m_hExpand[i].hIsoSnow);
  3184. FSunPackLib::XCC_CloseMix(m_hExpand[i].hIsoTemp);
  3185. FSunPackLib::XCC_CloseMix(m_hExpand[i].hIsoUrb);
  3186. FSunPackLib::XCC_CloseMix(m_hExpand[i].hIsoGen);
  3187. FSunPackLib::XCC_CloseMix(m_hExpand[i].hTemperat);
  3188. FSunPackLib::XCC_CloseMix(m_hExpand[i].hSnow);
  3189. FSunPackLib::XCC_CloseMix(m_hExpand[i].hUrban);
  3190. FSunPackLib::XCC_CloseMix(m_hExpand[i].hSno);
  3191. FSunPackLib::XCC_CloseMix(m_hExpand[i].hTem);
  3192. FSunPackLib::XCC_CloseMix(m_hExpand[i].hUrb);
  3193. FSunPackLib::XCC_CloseMix(m_hExpand[i].hBuildings);
  3194. m_hExpand[i].hExpand = NULL;
  3195. }
  3196. for (i = 0;i < 100; i++)
  3197. {
  3198. FSunPackLib::XCC_CloseMix(m_hECache[i]);
  3199. }
  3200. MEMORYSTATUS ms;
  3201. ms.dwLength = sizeof(MEMORYSTATUS);
  3202. GlobalMemoryStatus(&ms);
  3203. int cs = ms.dwAvailPhys + ms.dwAvailPageFile;
  3204. errstream << "CLoading::Unload finished. Available memory: " << cs << endl;
  3205. errstream.flush();
  3206. }
  3207. HMIXFILE CLoading::FindFileInMix(LPCTSTR lpFilename, TheaterChar* pTheaterChar)
  3208. {
  3209. if(pTheaterChar)
  3210. *pTheaterChar = TheaterChar::None;
  3211. int i;
  3212. // MW: added ecache support
  3213. for(i=100;i>=0; i--)
  3214. {
  3215. HMIXFILE cuExp=m_hECache[i];
  3216. if(cuExp!=NULL)
  3217. {
  3218. if(FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp))
  3219. return cuExp;
  3220. }
  3221. }
  3222. for(i=100;i>=0; i--)
  3223. {
  3224. EXPANDMIX cuExp=m_hExpand[i];
  3225. if(cuExp.hExpand!=NULL)
  3226. {
  3227. if(FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hExpand))
  3228. return cuExp.hExpand;
  3229. if(cuExp.hECache!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hECache))
  3230. return cuExp.hECache;
  3231. if(cuExp.hConquer!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hConquer))
  3232. return cuExp.hConquer;
  3233. if(cuExp.hLocal!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hLocal))
  3234. return cuExp.hLocal;
  3235. if(cuExp.hTemperat!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hTemperat))
  3236. return cuExp.hTemperat;
  3237. if(strcmp(lpFilename,"yayard.shp")==NULL)
  3238. FSunPackLib::_DEBUG_EnableLogs=true;
  3239. if(cuExp.hSnow!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hSnow))
  3240. return cuExp.hSnow;
  3241. FSunPackLib::_DEBUG_EnableLogs=false;
  3242. if(cuExp.hGeneric!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hGeneric))
  3243. return cuExp.hGeneric;
  3244. if(cuExp.hUrban!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hUrban))
  3245. return cuExp.hUrban;
  3246. if(cuExp.hUrbanN!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hUrbanN))
  3247. return cuExp.hUrbanN;
  3248. if(cuExp.hLunar!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hLunar))
  3249. return cuExp.hLunar;
  3250. if(cuExp.hDesert!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hDesert))
  3251. return cuExp.hDesert;
  3252. if(cuExp.hBuildings!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hBuildings))
  3253. return cuExp.hBuildings;
  3254. if(cuExp.hIsoGen!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoGen))
  3255. return cuExp.hIsoGen;
  3256. if(cuExp.hIsoGenMd!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoGenMd))
  3257. return cuExp.hIsoGenMd;
  3258. if(cuExp.hIsoTemp!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoTemp))
  3259. {
  3260. if(pTheaterChar) *pTheaterChar=TheaterChar::T;
  3261. return cuExp.hIsoTemp;
  3262. }
  3263. if(cuExp.hIsoSnow!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoSnow))
  3264. {
  3265. if(pTheaterChar) *pTheaterChar = TheaterChar::A;
  3266. return cuExp.hIsoSnow;
  3267. }
  3268. if(cuExp.hIsoUrb!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoUrb))
  3269. {
  3270. if(pTheaterChar) *pTheaterChar = TheaterChar::U;
  3271. return cuExp.hIsoUrb;
  3272. }
  3273. if(cuExp.hIsoUbn!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoUbn))
  3274. {
  3275. if(pTheaterChar) *pTheaterChar = TheaterChar::N;
  3276. return cuExp.hIsoUbn;
  3277. }
  3278. if(cuExp.hIsoDes!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoDes))
  3279. {
  3280. if(pTheaterChar) *pTheaterChar = TheaterChar::D;
  3281. return cuExp.hIsoDes;
  3282. }
  3283. if(cuExp.hIsoLun!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoLun))
  3284. {
  3285. if(pTheaterChar) *pTheaterChar = TheaterChar::L;
  3286. return cuExp.hIsoLun;
  3287. }
  3288. if(cuExp.hIsoUbnMd!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoUbnMd))
  3289. {
  3290. if(pTheaterChar) *pTheaterChar = TheaterChar::N;
  3291. return cuExp.hIsoUbnMd;
  3292. }
  3293. if(cuExp.hIsoDesMd!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoDesMd))
  3294. {
  3295. if(pTheaterChar) *pTheaterChar = TheaterChar::D;
  3296. return cuExp.hIsoDesMd;
  3297. }
  3298. if(cuExp.hIsoLunMd!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hIsoLunMd))
  3299. {
  3300. if(pTheaterChar) *pTheaterChar = TheaterChar::L;
  3301. return cuExp.hIsoLunMd;
  3302. }
  3303. if(cuExp.hSno!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hSno))
  3304. return cuExp.hSno;
  3305. if(cuExp.hTem!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hTem))
  3306. return cuExp.hTem;
  3307. if(cuExp.hUrb!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hUrb))
  3308. return cuExp.hUrb;
  3309. if(cuExp.hUbn!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hUbn))
  3310. return cuExp.hUbn;
  3311. if(cuExp.hLun!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hLun))
  3312. return cuExp.hLun;
  3313. if(cuExp.hDes!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hDes))
  3314. return cuExp.hDes;
  3315. if(cuExp.hMarble!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, cuExp.hMarble))
  3316. return cuExp.hMarble;
  3317. }
  3318. }
  3319. if(m_hTibSun!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hTibSun))
  3320. return m_hTibSun;
  3321. if(m_hLanguage!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hLanguage))
  3322. return m_hLanguage;
  3323. if(m_hLangMD!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hLangMD))
  3324. return m_hLangMD;
  3325. if(m_hLocal!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hLocal))
  3326. return m_hLocal;
  3327. if(m_hBuildings!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hBuildings))
  3328. return m_hBuildings;
  3329. if(m_hCache!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hCache))
  3330. return m_hCache;
  3331. if(m_hConquer!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hConquer))
  3332. return m_hConquer;
  3333. if(m_hTemperat!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hTemperat))
  3334. return m_hTemperat;
  3335. if(m_hSnow!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hSnow))
  3336. return m_hSnow;
  3337. if(m_hUrban!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hUrban))
  3338. return m_hUrban;
  3339. if(m_hUrbanN!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hUrbanN))
  3340. return m_hUrbanN;
  3341. if(m_hLunar!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hLunar))
  3342. return m_hLunar;
  3343. if(m_hDesert!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hDesert))
  3344. return m_hDesert;
  3345. if(m_hIsoGen!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hIsoGen))
  3346. {
  3347. return m_hIsoGen;
  3348. }
  3349. if(m_hIsoTemp!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hIsoTemp))
  3350. {
  3351. if(pTheaterChar) *pTheaterChar = TheaterChar::T;
  3352. return m_hIsoTemp;
  3353. }
  3354. if(m_hIsoSnow!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hIsoSnow))
  3355. {
  3356. if(pTheaterChar) *pTheaterChar = TheaterChar::A;
  3357. return m_hIsoSnow;
  3358. }
  3359. if(m_hIsoUrb!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hIsoUrb))
  3360. {
  3361. if(pTheaterChar) *pTheaterChar = TheaterChar::U;
  3362. return m_hIsoUrb;
  3363. }
  3364. if(m_hIsoUbn!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hIsoUbn))
  3365. {
  3366. if(pTheaterChar) *pTheaterChar = TheaterChar::N;
  3367. return m_hIsoUbn;
  3368. }
  3369. if(m_hIsoLun!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hIsoLun))
  3370. {
  3371. if(pTheaterChar) *pTheaterChar = TheaterChar::L;
  3372. return m_hIsoLun;
  3373. }
  3374. if(m_hIsoDes!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hIsoDes))
  3375. {
  3376. if(pTheaterChar) *pTheaterChar = TheaterChar::D;
  3377. return m_hIsoDes;
  3378. }
  3379. if(m_hTem!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hTem))
  3380. return m_hTem;
  3381. if(m_hSno!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hSno))
  3382. return m_hSno;
  3383. if(m_hUrb!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hUrb))
  3384. return m_hUrb;
  3385. if(m_hUbn!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hUbn))
  3386. return m_hUbn;
  3387. if(m_hLun!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hLun))
  3388. return m_hLun;
  3389. if(m_hDes!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hDes))
  3390. return m_hDes;
  3391. if(m_hMarble!=NULL && FSunPackLib::XCC_DoesFileExist(lpFilename, m_hMarble))
  3392. return m_hMarble;
  3393. return NULL;
  3394. }
  3395. void CLoading::InitPalettes()
  3396. {
  3397. errstream << "InitPalettes() called\n";
  3398. if(!FSunPackLib::XCC_ExtractFile("isotem.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3399. errstream << "IsoTem.pal failed\n";
  3400. m_hPalIsoTemp=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3401. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3402. if(!FSunPackLib::XCC_ExtractFile("isosno.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3403. errstream << "IsoSno.pal failed\n";
  3404. m_hPalIsoSnow=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3405. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3406. if(!FSunPackLib::XCC_ExtractFile("isourb.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3407. errstream << "IsoUrb.pal failed\n";
  3408. m_hPalIsoUrb=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3409. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3410. HMIXFILE m_hCache2=m_hExpand[100].hECache;
  3411. if(!FSunPackLib::XCC_ExtractFile("isolun.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3412. errstream << "IsoLun.pal failed\n";
  3413. m_hPalIsoLun=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3414. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3415. if(!FSunPackLib::XCC_ExtractFile("isodes.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3416. errstream << "IsoDes.pal failed\n";
  3417. m_hPalIsoDes=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3418. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3419. if(!FSunPackLib::XCC_ExtractFile("isoubn.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3420. errstream << "IsoUbn.pal failed\n";
  3421. m_hPalIsoUbn=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3422. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3423. if(!FSunPackLib::XCC_ExtractFile("unittem.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3424. errstream << "UnitTem.pal failed";
  3425. m_hPalUnitTemp=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3426. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3427. if(!FSunPackLib::XCC_ExtractFile("unitsno.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3428. errstream << "UnitSno.pal failed\n";
  3429. m_hPalUnitSnow=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3430. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3431. if(!FSunPackLib::XCC_ExtractFile("uniturb.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3432. errstream << "UnitUrb.pal failed\n";
  3433. m_hPalUnitUrb=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3434. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3435. if(!FSunPackLib::XCC_ExtractFile("unitlun.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3436. errstream << "UnitLun.pal failed\n";
  3437. m_hPalUnitLun=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3438. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3439. if(!FSunPackLib::XCC_ExtractFile("unitdes.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3440. errstream << "UnitDes.pal failed\n";
  3441. m_hPalUnitDes=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3442. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3443. if(!FSunPackLib::XCC_ExtractFile("unitubn.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3444. errstream << "UnitUbn.pal failed\n";
  3445. m_hPalUnitUbn=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3446. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3447. if(!FSunPackLib::XCC_ExtractFile("snow.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3448. errstream << "Snow.pal failed\n";
  3449. m_hPalSnow=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3450. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3451. if(!FSunPackLib::XCC_ExtractFile("temperat.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3452. errstream << "Temperat.pal failed\n";
  3453. m_hPalTemp=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3454. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3455. if(!FSunPackLib::XCC_ExtractFile("urban.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3456. errstream << "Urban.pal failed\n";
  3457. m_hPalUrb=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3458. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3459. if(!FSunPackLib::XCC_ExtractFile("lunar.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3460. errstream << "lunar.pal failed\n";
  3461. m_hPalLun=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3462. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3463. if(!FSunPackLib::XCC_ExtractFile("desert.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3464. errstream << "desert.pal failed\n";
  3465. m_hPalDes=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3466. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3467. if(!FSunPackLib::XCC_ExtractFile("urbann.pal", u8AppDataPath+"\\TmpPalette.pal", m_hCache2))
  3468. errstream << "urbann.pal failed\n";
  3469. m_hPalUbn=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3470. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3471. if(!FSunPackLib::XCC_ExtractFile("_ID2124019542", u8AppDataPath+"\\TmpPalette.pal", m_hCache))
  3472. errstream << "lib.pal failed\n";
  3473. m_hPalLib=FSunPackLib::LoadTSPalette(u8AppDataPath+"\\TmpPalette.pal", NULL);
  3474. deleteFile(u8AppDataPath +"\\TmpPalette.pal");
  3475. errstream << "\n";
  3476. errstream.flush();
  3477. }
  3478. void CLoading::InitTMPs(CProgressCtrl* prog)
  3479. {
  3480. FetchPalettes();
  3481. MEMORYSTATUS ms;
  3482. ms.dwLength=sizeof(MEMORYSTATUS);
  3483. GlobalMemoryStatus(&ms);
  3484. int cs=ms.dwAvailPhys+ms.dwAvailPageFile;
  3485. errstream << "InitTMPs() called. Available memory: " << cs << endl;
  3486. errstream.flush();
  3487. // we need to have that here, CMapData::UpdateIniFile() is too late for the shore hack
  3488. shoreset=atoi((*tiles).sections["General"].values["ShorePieces"]);
  3489. waterset=atoi((*tiles).sections["General"].values["WaterSet"]);
  3490. int i, tcount=0;
  3491. for(i=0;i<10000;i++)
  3492. {
  3493. CString tset;
  3494. char c[50];
  3495. itoa(i, c, 10);
  3496. int e;
  3497. for(e=0;e<4-strlen(c);e++)
  3498. tset+="0";
  3499. tset+=c;
  3500. CString sec="TileSet";
  3501. sec+=tset;
  3502. if(tiles->sections.find(sec)==tiles->sections.end()) break;
  3503. for(e=0;e<atoi(tiles->sections[sec].values["TilesInSet"]);e++)
  3504. {
  3505. tcount++;
  3506. }
  3507. }
  3508. if(prog) prog->SetRange(0, tcount);
  3509. if(prog) prog->SetPos(0);
  3510. if(*tiledata!=NULL) delete[] *tiledata;
  3511. *tiledata=new(TILEDATA[tcount]);
  3512. *tiledata_count=tcount;
  3513. DWORD tilecount=0;
  3514. for(i=0;i<10000;i++)
  3515. {
  3516. CString tset;
  3517. char c[50];
  3518. itoa(i, c, 10);
  3519. int e;
  3520. for(e=0;e<4-strlen(c);e++)
  3521. tset+="0";
  3522. tset+=c;
  3523. CString sec="TileSet";
  3524. sec+=tset;
  3525. if(tiles->sections.find(sec)==tiles->sections.end()) break;
  3526. BOOL bTib, bMorph, bPlace, bMadness;
  3527. bPlace=TRUE;
  3528. bTib=FALSE;
  3529. bMorph=FALSE;
  3530. bMadness=FALSE;
  3531. tiles->sections[sec].values["AllowTiberium"].MakeLower();
  3532. if(tiles->sections[sec].values["AllowTiberium"]=="true")
  3533. bTib=TRUE;
  3534. tiles->sections[sec].values["Morphable"].MakeLower();
  3535. if(tiles->sections[sec].values["Morphable"]=="true")
  3536. bMorph=TRUE;
  3537. tiles->sections[sec].values["AllowToPlace"].MakeLower();
  3538. if(tiles->sections[sec].values["AllowToPlace"]=="no")
  3539. bPlace=FALSE;
  3540. tiles->sections[sec].values["NonMarbleMadness"].MakeLower();
  3541. if(tiles->sections[sec].values["NonMarbleMadness"].GetLength()>0)
  3542. bMadness=TRUE;
  3543. auto tilesetAnimSection = tiles->GetSection(tiles->sections[sec].GetValueByName("SetName"));
  3544. tilesets_start[i]=tilecount;
  3545. for(e=0;e<atoi(tiles->sections[sec].values["TilesInSet"]);e++)
  3546. {
  3547. std::string sId = std::format("{:02}", e + 1);
  3548. CString filename=tiles->sections[sec].values["FileName"];
  3549. filename+=sId.c_str();
  3550. CString bas_f=filename;
  3551. CString suffix;
  3552. if(tiles==&tiles_t) suffix =".tem";
  3553. if(tiles==&tiles_s) suffix =".sno";
  3554. if(tiles==&tiles_u) suffix =".urb";
  3555. if(tiles==&tiles_un) suffix =".ubn";
  3556. if(tiles==&tiles_l) suffix =".lun";
  3557. if(tiles==&tiles_d) suffix =".des";
  3558. filename += suffix;
  3559. HTSPALETTE hPalette=m_hPalIsoTemp;
  3560. if(tiles==&tiles_s) hPalette=m_hPalIsoSnow;
  3561. if(tiles==&tiles_u) hPalette=m_hPalIsoUrb;
  3562. if(tiles==&tiles_t) hPalette=m_hPalIsoTemp;
  3563. if(tiles==&tiles_un) hPalette=m_hPalIsoUbn;
  3564. if(tiles==&tiles_d) hPalette=m_hPalIsoDes;
  3565. if(tiles==&tiles_l) hPalette=m_hPalIsoLun;
  3566. // MW add: use other...
  3567. if(FindFileInMix(filename)==NULL && tiles==&tiles_un) { filename=bas_f+".urb"; hPalette=m_hPalIsoUrb; }
  3568. if(FindFileInMix(filename)==NULL) { filename=bas_f+".tem"; hPalette=m_hPalIsoTemp; }
  3569. (*tiledata)[tilecount].bAllowTiberium=bTib;
  3570. (*tiledata)[tilecount].bAllowToPlace=bPlace;
  3571. (*tiledata)[tilecount].bMorphable=bMorph;
  3572. (*tiledata)[tilecount].bMarbleMadness=bMadness;
  3573. (*tiledata)[tilecount].wTileSet=i;
  3574. int reps;
  3575. for(reps=0;reps<5;reps++)
  3576. {
  3577. CString r_filename=filename;
  3578. if(reps>0)
  3579. {
  3580. char c[3];
  3581. c[0]='a'+reps-1;
  3582. c[1]='.';
  3583. c[2]=0;
  3584. r_filename.Replace(".", c);
  3585. if(!LoadTile(r_filename, FindFileInMix(filename), hPalette, tilecount, TRUE))
  3586. break;
  3587. }
  3588. else
  3589. {
  3590. LoadTile(filename, FindFileInMix(filename), hPalette, tilecount, FALSE);
  3591. }
  3592. }
  3593. if (tilesetAnimSection)
  3594. {
  3595. auto anim = tilesetAnimSection->GetValueByName(std::format("Tile{}Anim", sId).c_str());
  3596. auto offsetX = std::atoi(tilesetAnimSection->GetValueByName(std::format("Tile{}XOffset", sId).c_str()));
  3597. auto offsetY = std::atoi(tilesetAnimSection->GetValueByName(std::format("Tile{}YOffset", sId).c_str()));
  3598. auto attachesTo = std::atoi(tilesetAnimSection->GetValueByName(std::format("Tile{}AttachesTo", sId).c_str()));
  3599. auto animFileName = anim + suffix;
  3600. HMIXFILE hAnimMix = FindFileInMix(animFileName);
  3601. if (hAnimMix)
  3602. {
  3603. auto& tile = (*tiledata)[tilecount];
  3604. if (tile.wTileCount <= attachesTo)
  3605. {
  3606. ASSERT(tile.wTileCount > attachesTo);
  3607. }
  3608. else
  3609. {
  3610. auto& subtile = tile.tiles[attachesTo];
  3611. SHPHEADER shp_h;
  3612. SHPIMAGEHEADER shpi_h;
  3613. auto animPic = std::make_shared<PICDATA>();
  3614. auto rawPic = std::make_shared<std::vector<BYTE>>();
  3615. animPic->rawPic = rawPic;
  3616. FSunPackLib::SetCurrentSHP(animFileName, hAnimMix);
  3617. FSunPackLib::XCC_GetSHPHeader(&shp_h);
  3618. int imageNum = 1;
  3619. FSunPackLib::XCC_GetSHPImageHeader(1, &shpi_h);
  3620. if (shpi_h.unknown == 0)
  3621. {
  3622. // shadow
  3623. imageNum = 0;
  3624. }
  3625. FSunPackLib::XCC_GetSHPImageHeader(imageNum, &shpi_h);
  3626. if (FSunPackLib::LoadSHPImage(imageNum, *rawPic))
  3627. {
  3628. subtile.anim = animPic;
  3629. animPic->pic = animPic->rawPic->data();
  3630. animPic->bType = PICDATA_TYPE_SHP;
  3631. animPic->pal = iPalIso;
  3632. animPic->wWidth = animPic->wMaxWidth = shp_h.cx;
  3633. animPic->wHeight = animPic->wMaxHeight = shp_h.cy;
  3634. animPic->x = offsetX;
  3635. animPic->y = offsetY;
  3636. animPic->createVBorder();
  3637. }
  3638. }
  3639. }
  3640. }
  3641. tilecount++;
  3642. if(prog!=NULL /*&& tilecount%15==0*/)
  3643. {
  3644. prog->SetPos(tilecount);
  3645. prog->UpdateWindow();
  3646. }
  3647. }
  3648. }
  3649. tilecount=0;
  3650. for(i=0;i<10000;i++)
  3651. {
  3652. CString tset;
  3653. char c[50];
  3654. itoa(i, c, 10);
  3655. int e;
  3656. for(e=0;e<4-strlen(c);e++)
  3657. tset+="0";
  3658. tset+=c;
  3659. CString sec="TileSet";
  3660. sec+=tset;
  3661. if(tiles->sections.find(sec)==tiles->sections.end()) break;
  3662. int madnessid=atoi(tiles->sections[sec].values["MarbleMadness"]);
  3663. for(e=0;e<atoi(tiles->sections[sec].values["TilesInSet"]);e++)
  3664. {
  3665. if(madnessid)
  3666. {
  3667. (*tiledata)[tilecount].wMarbleGround=tilesets_start[madnessid]+(tilecount-tilesets_start[i]);
  3668. }
  3669. else
  3670. (*tiledata)[tilecount].wMarbleGround=0xFFFF;
  3671. tilecount++;
  3672. }
  3673. }
  3674. }
  3675. #ifdef NOSURFACES // first version, using palettized (or extracted) data
  3676. BOOL CLoading::LoadTile(LPCSTR lpFilename, HMIXFILE hOwner, HTSPALETTE hPalette, DWORD dwID, BOOL bReplacement)
  3677. {
  3678. last_succeeded_operation=12;
  3679. int tileCount;
  3680. if(FSunPackLib::XCC_DoesFileExist(lpFilename, hOwner))
  3681. {
  3682. FSunPackLib::SetCurrentTMP(lpFilename, hOwner);
  3683. {
  3684. //FSunPackLib::SetCurrentTMP((CString)AppPath+"\\TmpTmp.tmp"/* lpFilename*/, NULL/*hOwner*/);
  3685. int tileWidth, tileHeight;
  3686. RECT rect;
  3687. FSunPackLib::XCC_GetTMPInfo(&rect, &tileCount, &tileWidth, &tileHeight);
  3688. BYTE** pics=new(BYTE*[tileCount]);
  3689. if(FSunPackLib::LoadTMPImage(0, tileCount, pics)) // be aware this allocates memory!
  3690. //if(FSunPackLib::LoadTMPImageInSurface(v.dd,lpFilename, 0, tileCount, pics, hPalette, hOwner))
  3691. {
  3692. TILEDATA* td;
  3693. if(!bReplacement) td=&(*tiledata)[dwID];
  3694. else
  3695. {
  3696. TILEDATA* lpTmp=NULL;
  3697. if((*tiledata)[dwID].bReplacementCount)
  3698. {
  3699. lpTmp=new(TILEDATA[(*tiledata)[dwID].bReplacementCount]);
  3700. memcpy(lpTmp, (*tiledata)[dwID].lpReplacements, sizeof(TILEDATA)* (*tiledata)[dwID].bReplacementCount);
  3701. }
  3702. (*tiledata)[dwID].lpReplacements=new(TILEDATA[(*tiledata)[dwID].bReplacementCount+1]);
  3703. if((*tiledata)[dwID].bReplacementCount)
  3704. {
  3705. memcpy((*tiledata)[dwID].lpReplacements, lpTmp, sizeof(TILEDATA)*(*tiledata)[dwID].bReplacementCount);
  3706. delete[] lpTmp;
  3707. }
  3708. td=&(*tiledata)[dwID].lpReplacements[(*tiledata)[dwID].bReplacementCount];
  3709. (*tiledata)[dwID].bReplacementCount++;
  3710. }
  3711. td->tiles=new(SUBTILE[tileCount]);
  3712. td->wTileCount=tileCount;
  3713. td->cx=tileWidth;
  3714. td->cy=tileHeight;
  3715. td->rect=rect;
  3716. int i;
  3717. for(i=0;i<tileCount;i++)
  3718. {
  3719. if(pics[i]!=NULL)
  3720. {
  3721. int cx,cy;
  3722. BYTE height,terraintype,direction;
  3723. POINT p;
  3724. FSunPackLib::XCC_GetTMPTileInfo(i, &p, &cx, &cy, &direction, &height, &terraintype, &td->tiles[i].rgbLeft, &td->tiles[i].rgbRight);
  3725. td->tiles[i].pic=pics[i];
  3726. td->tiles[i].sX=p.x;
  3727. td->tiles[i].sY=p.y;
  3728. td->tiles[i].wWidth=cx;
  3729. td->tiles[i].wHeight=cy;
  3730. td->tiles[i].bZHeight=height;
  3731. td->tiles[i].bTerrainType=terraintype;
  3732. td->tiles[i].bHackedTerrainType=terraintype;
  3733. td->tiles[i].bDirection=direction;
  3734. td->tiles[i].vborder=new(VBORDER[cy]);
  3735. int k;
  3736. int size=0;
  3737. BOOL TranspInside=FALSE;
  3738. for(k=0;k<cy;k++)
  3739. {
  3740. int l,r;
  3741. BOOL* ti=NULL;
  3742. if(!TranspInside) ti=&TranspInside;
  3743. GetDrawBorder(pics[i], cx, k, l, r, 0, ti);
  3744. td->tiles[i].vborder[k].left=l;
  3745. td->tiles[i].vborder[k].right=r;
  3746. if(r>=l)
  3747. size+=r-l+1;
  3748. }
  3749. #ifdef NOSURFACES_EXTRACT
  3750. if(!TranspInside)
  3751. {
  3752. // extract the palette data!
  3753. td->tiles[i].bNotExtracted=FALSE;
  3754. td->tiles[i].pic=new(BYTE[size*bpp]);
  3755. int l;
  3756. int pos=0;
  3757. for(k=0;k<cy;k++)
  3758. {
  3759. int left, right;
  3760. left=td->tiles[i].vborder[k].left;
  3761. right=td->tiles[i].vborder[k].right;
  3762. for(l=left;l<=right;l++)
  3763. {
  3764. memcpy(&td->tiles[i].pic[pos], &iPalIso[pics[i][l+k*cx]], bpp);
  3765. pos+=bpp;
  3766. }
  3767. }
  3768. delete[] pics[i];
  3769. }
  3770. else
  3771. td->tiles[i].bNotExtracted=TRUE;
  3772. #endif
  3773. if(terraintype==0xa)
  3774. {
  3775. #ifdef RA2_MODE
  3776. td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3777. #else
  3778. td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3779. #endif
  3780. }
  3781. if(terraintype==TERRAINTYPE_ROUGH) td->tiles[i].bHackedTerrainType=TERRAINTYPE_GROUND;
  3782. //if((*tiledata)[dwID].wTileSet==waterset) (*tiledata)[dwID].tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3783. // shore hack: check fsdata.ini for new shore terrain
  3784. if(td->wTileSet==shoreset)
  3785. {
  3786. int h;
  3787. for(h=0;h<(*tiledata_count);h++)
  3788. {
  3789. if((*tiledata)[h].wTileSet==shoreset) break;
  3790. }
  3791. int pos=dwID-h;
  3792. char c[50];
  3793. itoa(pos,c,10);
  3794. CString hack=c;
  3795. hack+="_";
  3796. itoa(i, c, 10);
  3797. hack+=c;/*
  3798. hack+="_";
  3799. itoa(i/tileWidth, c, 10);
  3800. hack+=c;*/
  3801. CString section="ShoreTerrainTS";
  3802. #ifdef RA2_MODE
  3803. section="ShoreTerrainRA2";
  3804. #endif
  3805. if(g_data.sections[section].FindName(hack)>=0)
  3806. {
  3807. int t=atoi(g_data.sections[section].values[hack]);
  3808. if(t) td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3809. else
  3810. td->tiles[i].bHackedTerrainType=0xe;
  3811. }
  3812. }
  3813. if((*tiledata)[dwID].wTileSet==waterset) (*tiledata)[dwID].tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3814. }
  3815. else
  3816. {
  3817. td->tiles[i].pic=NULL;
  3818. td->tiles[i].sX=0;
  3819. td->tiles[i].sY=0;
  3820. td->tiles[i].wWidth=0;
  3821. td->tiles[i].wHeight=0;
  3822. td->tiles[i].bZHeight=0;
  3823. td->tiles[i].bTerrainType=0;
  3824. td->tiles[i].bDirection=0;
  3825. td->tiles[i].vborder=NULL;
  3826. }
  3827. }
  3828. }
  3829. if(tileCount>0) delete[] pics;
  3830. }
  3831. }
  3832. else
  3833. {
  3834. errstream << lpFilename << " not found" << endl;
  3835. return FALSE;
  3836. }
  3837. return TRUE;
  3838. }
  3839. #else // now standard version, with surfaces
  3840. BOOL CLoading::LoadTile(LPCSTR lpFilename, HMIXFILE hOwner, HTSPALETTE hPalette, DWORD dwID, BOOL bReplacement)
  3841. {
  3842. last_succeeded_operation=12;
  3843. //errstream << "Loading " << lpFilename << " owned by " << hOwner << ", palette " << hPalette ;
  3844. //errstream << lpFilename << endl;
  3845. //errstream.flush();
  3846. CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview;
  3847. //DeleteFile((CString)AppPath+(CString)"\\TmpTmp.tmp");
  3848. //FSunPackLib::XCC_ExtractFile(lpFilename, (CString)AppPath+(CString)"\\TmpTmp.tmp" /*lpFilename*//*, hOwner);
  3849. int tileCount;
  3850. try{
  3851. if(FSunPackLib::XCC_DoesFileExist(lpFilename, hOwner))
  3852. //if(DoesFileExist((CString)AppPath+(CString)"\\TmpTmp.tmp"))
  3853. {
  3854. //if(
  3855. FSunPackLib::SetCurrentTMP(lpFilename, hOwner);
  3856. //)
  3857. {
  3858. //FSunPackLib::SetCurrentTMP((CString)AppPath+"\\TmpTmp.tmp"/* lpFilename*//*, NULL/*hOwner*//*);
  3859. int tileWidth, tileHeight;
  3860. RECT rect;
  3861. FSunPackLib::XCC_GetTMPInfo(&rect, &tileCount, &tileWidth, &tileHeight);
  3862. LPDIRECTDRAWSURFACE4* pics=new(LPDIRECTDRAWSURFACE4[tileCount]);
  3863. if(FSunPackLib::LoadTMPImageInSurface(v.dd,0, tileCount, pics, hPalette))
  3864. //if(FSunPackLib::LoadTMPImageInSurface(v.dd,lpFilename, 0, tileCount, pics, hPalette, hOwner))
  3865. {
  3866. TILEDATA* td;
  3867. if(!bReplacement) td=&(*tiledata)[dwID];
  3868. else
  3869. {
  3870. TILEDATA* lpTmp=NULL;
  3871. if((*tiledata)[dwID].bReplacementCount)
  3872. {
  3873. lpTmp=new(TILEDATA[(*tiledata)[dwID].bReplacementCount]);
  3874. memcpy(lpTmp, (*tiledata)[dwID].lpReplacements, sizeof(TILEDATA)* (*tiledata)[dwID].bReplacementCount);
  3875. }
  3876. (*tiledata)[dwID].lpReplacements=new(TILEDATA[(*tiledata)[dwID].bReplacementCount+1]);
  3877. if((*tiledata)[dwID].bReplacementCount)
  3878. {
  3879. memcpy((*tiledata)[dwID].lpReplacements, lpTmp, sizeof(TILEDATA)*(*tiledata)[dwID].bReplacementCount);
  3880. delete[] lpTmp;
  3881. }
  3882. td=&(*tiledata)[dwID].lpReplacements[(*tiledata)[dwID].bReplacementCount];
  3883. (*tiledata)[dwID].bReplacementCount++;
  3884. }
  3885. td->tiles=new(SUBTILE[tileCount]);
  3886. td->wTileCount=tileCount;
  3887. td->cx=tileWidth;
  3888. td->cy=tileHeight;
  3889. td->rect=rect;
  3890. int i;
  3891. for(i=0;i<tileCount;i++)
  3892. {
  3893. if(pics[i]!=NULL)
  3894. {
  3895. int cx,cy;
  3896. BYTE height,terraintype,direction;
  3897. POINT p;
  3898. FSunPackLib::XCC_GetTMPTileInfo(i, &p, &cx, &cy, &direction, &height, &terraintype, &td->tiles[i].rgbLeft, &td->tiles[i].rgbRight);
  3899. td->tiles[i].pic=pics[i];
  3900. td->tiles[i].sX=p.x;
  3901. td->tiles[i].sY=p.y;
  3902. td->tiles[i].wWidth=cx;
  3903. td->tiles[i].wHeight=cy;
  3904. td->tiles[i].bZHeight=height;
  3905. td->tiles[i].bTerrainType=terraintype;
  3906. td->tiles[i].bHackedTerrainType=terraintype;
  3907. td->tiles[i].bDirection=direction;
  3908. if(terraintype==0xa)
  3909. {
  3910. #ifdef RA2_MODE
  3911. td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3912. #else
  3913. td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3914. #endif
  3915. }
  3916. if(terraintype==TERRAINTYPE_ROUGH) td->tiles[i].bHackedTerrainType=TERRAINTYPE_GROUND;
  3917. //if((*tiledata)[dwID].wTileSet==waterset) (*tiledata)[dwID].tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3918. // shore hack: check fsdata.ini for new shore terrain
  3919. if(td->wTileSet==shoreset)
  3920. {
  3921. int h;
  3922. for(h=0;h<(*tiledata_count);h++)
  3923. {
  3924. if((*tiledata)[h].wTileSet==shoreset) break;
  3925. }
  3926. int pos=dwID-h;
  3927. char c[50];
  3928. itoa(pos,c,10);
  3929. CString hack=c;
  3930. hack+="_";
  3931. itoa(i, c, 10);
  3932. hack+=c;/*
  3933. hack+="_";
  3934. itoa(i/tileWidth, c, 10);
  3935. hack+=c;*/
  3936. CString section="ShoreTerrainTS";
  3937. #ifdef RA2_MODE
  3938. section="ShoreTerrainRA2";
  3939. #endif
  3940. if(g_data.sections[section].FindName(hack)>=0)
  3941. {
  3942. int t=atoi(g_data.sections[section].values[hack]);
  3943. if(t) td->tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3944. else
  3945. td->tiles[i].bHackedTerrainType=0xe;
  3946. }
  3947. }
  3948. if((*tiledata)[dwID].wTileSet==waterset) (*tiledata)[dwID].tiles[i].bHackedTerrainType=TERRAINTYPE_WATER;
  3949. }
  3950. else
  3951. {
  3952. td->tiles[i].pic=NULL;
  3953. td->tiles[i].sX=0;
  3954. td->tiles[i].sY=0;
  3955. td->tiles[i].wWidth=0;
  3956. td->tiles[i].wHeight=0;
  3957. td->tiles[i].bZHeight=0;
  3958. td->tiles[i].bTerrainType=0;
  3959. td->tiles[i].bDirection=0;
  3960. }
  3961. }
  3962. }
  3963. if(tileCount>0) delete[] pics;
  3964. }
  3965. }
  3966. else
  3967. {
  3968. //errstream << " not found" << endl;
  3969. return FALSE;
  3970. }
  3971. }
  3972. catch(...)
  3973. {
  3974. }
  3975. if((*tiledata)[dwID].wTileCount==0 || (*tiledata)[dwID].tiles[0].pic==NULL)
  3976. {
  3977. //errstream << " failed" << endl;
  3978. //errstream.flush();
  3979. return FALSE;
  3980. }
  3981. else
  3982. {
  3983. //errstream << " succeeded" << endl;
  3984. //errstream.flush();
  3985. }
  3986. return TRUE;
  3987. }
  3988. #endif
  3989. #ifdef NOSURFACES_OBJECTS // palettized
  3990. void CLoading::LoadOverlayGraphic(LPCTSTR lpOvrlName_, int iOvrlNum)
  3991. {
  3992. last_succeeded_operation=11;
  3993. CString image; // the image used
  3994. CString filename; // filename of the image
  3995. SHPHEADER head;
  3996. char theat=cur_theat;
  3997. BYTE** lpT=NULL;
  3998. char OvrlID[50];
  3999. itoa(iOvrlNum, OvrlID, 10);
  4000. HTSPALETTE hPalette = m_hPalIsoTemp;
  4001. if(cur_theat=='T')
  4002. {
  4003. hPalette=m_hPalIsoTemp;
  4004. #ifdef RA2_MODE
  4005. hPalette=m_hPalIsoTemp;
  4006. #endif
  4007. }
  4008. if(cur_theat=='A')
  4009. {
  4010. hPalette=m_hPalIsoSnow;
  4011. #ifdef RA2_MODE
  4012. hPalette=m_hPalIsoSnow;
  4013. #endif
  4014. }
  4015. if(cur_theat=='U' && m_hPalIsoUrb)
  4016. {
  4017. hPalette=m_hPalIsoUrb;
  4018. #ifdef RA2_MODE
  4019. hPalette=m_hPalIsoUrb;
  4020. #endif
  4021. }
  4022. if(cur_theat=='N' && m_hPalIsoUbn)
  4023. {
  4024. hPalette=m_hPalIsoUbn;
  4025. #ifdef RA2_MODE
  4026. hPalette=m_hPalIsoUbn;
  4027. #endif
  4028. }
  4029. if(cur_theat=='L' && m_hPalIsoLun)
  4030. {
  4031. hPalette=m_hPalIsoLun;
  4032. #ifdef RA2_MODE
  4033. hPalette=m_hPalIsoLun;
  4034. #endif
  4035. }
  4036. if(cur_theat=='D' && m_hPalIsoDes)
  4037. {
  4038. hPalette=m_hPalIsoDes;
  4039. #ifdef RA2_MODE
  4040. hPalette=m_hPalIsoDes;
  4041. #endif
  4042. }
  4043. HTSPALETTE forcedPalette = 0;
  4044. const auto& isoPalettePrefixes = g_data.sections["ForceOvrlIsoPalettePrefix"];
  4045. const auto& unitPalettePrefixes = g_data.sections["ForceOvrlUnitPalettePrefix"];
  4046. const CString sOvrlName(lpOvrlName_);
  4047. if (unitPalettePrefixes.end() != std::find_if(unitPalettePrefixes.begin(), unitPalettePrefixes.end(), [&sOvrlName](const auto& pair) {return sOvrlName.Find(pair.second) == 0;}))
  4048. {
  4049. forcedPalette = GetUnitPalette(cur_theat);
  4050. }
  4051. if (isoPalettePrefixes.end() != std::find_if(isoPalettePrefixes.begin(), isoPalettePrefixes.end(), [&sOvrlName](const auto& pair) {return sOvrlName.Find(pair.second) == 0;}))
  4052. {
  4053. forcedPalette = GetIsoPalette(cur_theat);
  4054. }
  4055. HMIXFILE hMix;
  4056. CString lpOvrlName = lpOvrlName_;
  4057. if(lpOvrlName.Find(' ')>=0) lpOvrlName = lpOvrlName.Left(lpOvrlName.Find(' '));
  4058. //if(strchr(lpOvrlName, ' ')!=NULL) strchr(lpOvrlName, ' ')[0]=0;
  4059. //if(lpOvrlName
  4060. CString isveinhole_t=rules.sections[lpOvrlName].values["IsVeinholeMonster"];
  4061. CString istiberium_t=rules.sections[lpOvrlName].values["Tiberium"];
  4062. CString isveins_t=rules.sections[lpOvrlName].values["IsVeins"];
  4063. isveinhole_t.MakeLower();
  4064. istiberium_t.MakeLower();
  4065. isveins_t.MakeLower();
  4066. BOOL isveinhole=FALSE, istiberium=FALSE, isveins=FALSE;
  4067. if(isTrue(isveinhole_t)) isveinhole=TRUE;
  4068. if(isTrue(istiberium_t)) istiberium=TRUE;
  4069. if(isTrue(isveins_t)) isveins=TRUE;
  4070. image=lpOvrlName;
  4071. if(rules.sections[lpOvrlName].values.find("Image")!=rules.sections[lpOvrlName].values.end())
  4072. image=rules.sections[lpOvrlName].values["Image"];
  4073. TruncSpace(image);
  4074. CString imagerules=image;
  4075. if(art.sections[image].values.find("Image")!=art.sections[image].values.end())
  4076. image=art.sections[image].values["Image"];
  4077. TruncSpace(image);
  4078. if(cur_theat=='T') filename=image+".tem";
  4079. if(cur_theat=='A') filename=image+".sno";
  4080. if(cur_theat=='U') filename=image+".urb";
  4081. if(cur_theat=='N') filename=image+".ubn";
  4082. if(cur_theat=='L') filename=image+".lun";
  4083. if(cur_theat=='D') filename=image+".des";
  4084. hMix=FindFileInMix(filename);
  4085. const auto& artSection = art.sections[image];
  4086. if(hMix==NULL)
  4087. {
  4088. filename=image+".shp";
  4089. if(isTrue(artSection.GetValueByName("NewTheater")))
  4090. filename.SetAt(1, theat);
  4091. if(cur_theat=='U' && m_hPalUnitUrb) hPalette=m_hPalUnitUrb;
  4092. if(cur_theat=='T') hPalette=m_hPalUnitTemp;
  4093. if(cur_theat=='A') hPalette=m_hPalUnitSnow;
  4094. if(cur_theat=='N') hPalette=m_hPalUnitUbn;
  4095. if(cur_theat=='L') hPalette=m_hPalUnitLun;
  4096. if(cur_theat=='D') hPalette=m_hPalUnitDes;
  4097. hMix=FindFileInMix(filename);
  4098. //errstream << (LPCSTR)filename << " " << endl;
  4099. //errstream.flush();
  4100. if(hMix==NULL)
  4101. {
  4102. filename.SetAt(1, 'T');
  4103. hMix=FindFileInMix(filename);
  4104. }
  4105. if(hMix==NULL)
  4106. {
  4107. filename.SetAt(1, 'A');
  4108. hMix=FindFileInMix(filename);
  4109. }
  4110. if(hMix==NULL)
  4111. {
  4112. filename.SetAt(1, 'U');
  4113. hMix=FindFileInMix(filename);
  4114. }
  4115. if(hMix==NULL)
  4116. {
  4117. filename.SetAt(1, 'N');
  4118. hMix=FindFileInMix(filename);
  4119. }
  4120. if(hMix==NULL)
  4121. {
  4122. filename.SetAt(1, 'L');
  4123. hMix=FindFileInMix(filename);
  4124. }
  4125. if(hMix==NULL)
  4126. {
  4127. filename.SetAt(1, 'D');
  4128. hMix=FindFileInMix(filename);
  4129. }
  4130. if(cur_theat=='T' || cur_theat=='U')
  4131. {
  4132. hPalette=m_hPalUnitTemp;
  4133. }
  4134. else
  4135. hPalette=m_hPalUnitSnow;
  4136. }
  4137. if(hMix==NULL)
  4138. {
  4139. filename=image+".tem";
  4140. hMix=FindFileInMix(filename);
  4141. if(hMix) hPalette=m_hPalIsoTemp;
  4142. }
  4143. if(hMix==NULL)
  4144. {
  4145. filename=image+".sno";
  4146. hMix=FindFileInMix(filename);
  4147. if(hMix) hPalette=m_hPalIsoSnow;
  4148. }
  4149. if(hMix==NULL)
  4150. {
  4151. filename=image+".urb";
  4152. hMix=FindFileInMix(filename);
  4153. if(hMix && m_hPalIsoUrb) hPalette=m_hPalIsoUrb;
  4154. }
  4155. if(hMix==NULL)
  4156. {
  4157. filename=image+".ubn";
  4158. hMix=FindFileInMix(filename);
  4159. if(hMix && m_hPalIsoUbn) hPalette=m_hPalIsoUbn;
  4160. }
  4161. if(hMix==NULL)
  4162. {
  4163. filename=image+".lun";
  4164. hMix=FindFileInMix(filename);
  4165. if(hMix && m_hPalIsoLun) hPalette=m_hPalIsoLun;
  4166. }
  4167. if(hMix==NULL)
  4168. {
  4169. filename=image+".des";
  4170. hMix=FindFileInMix(filename);
  4171. if(hMix && m_hPalIsoDes) hPalette=m_hPalIsoDes;
  4172. }
  4173. if(isveinhole==TRUE || isveins==TRUE || istiberium==TRUE)
  4174. {
  4175. hPalette=m_hPalTemp;
  4176. #ifndef RA2_MODE
  4177. hPalette=m_hPalUnitTemp;
  4178. #endif
  4179. }
  4180. hPalette = forcedPalette ? forcedPalette : hPalette;
  4181. if(hMix!=NULL)
  4182. {
  4183. errstream << "Overlay: " << (LPCSTR) filename << endl;
  4184. errstream.flush();
  4185. FSunPackLib::SetCurrentSHP(filename, hMix);
  4186. {
  4187. FSunPackLib::XCC_GetSHPHeader(&head);
  4188. int i;
  4189. int maxPics=head.c_images;
  4190. if(maxPics>max_ovrl_img) maxPics=max_ovrl_img;
  4191. // create an array of pointers to directdraw surfaces
  4192. lpT=new(BYTE*[maxPics]);
  4193. memset(lpT, 0, sizeof(BYTE)*maxPics);
  4194. // if tiberium, change color
  4195. BOOL bIsBlueTib=FALSE;
  4196. BOOL bIsGreenTib=FALSE;
  4197. RGBTRIPLE rgbOld[16], rgbNew;
  4198. #ifndef RA2_MODE
  4199. if(istiberium)
  4200. {
  4201. if(lpOvrlName[4]=='_') // other than green!
  4202. bIsBlueTib=TRUE;
  4203. else
  4204. bIsGreenTib=TRUE;
  4205. int i;
  4206. for(i=0;i<16;i++)
  4207. {
  4208. if(bIsGreenTib)
  4209. {
  4210. rgbNew.rgbtBlue=0;
  4211. if(i!=0)
  4212. rgbNew.rgbtGreen=255-i*16+1;
  4213. else
  4214. rgbNew.rgbtGreen=255;
  4215. rgbNew.rgbtRed=0;
  4216. }
  4217. else if(bIsBlueTib)
  4218. {
  4219. if(i!=0)
  4220. rgbNew.rgbtBlue=255-i*16+1;
  4221. else
  4222. rgbNew.rgbtBlue=255;
  4223. rgbNew.rgbtGreen=0;
  4224. rgbNew.rgbtRed=0; // change green/blue (not RGB but BGR)
  4225. }
  4226. int rb=rgbNew.rgbtBlue;
  4227. int rr=rgbNew.rgbtRed;
  4228. FSunPackLib::SetTSPaletteEntry(hPalette, 0x10+i, &rgbNew, &rgbOld[i]);
  4229. }
  4230. }
  4231. #endif
  4232. FSunPackLib::LoadSHPImage(0, maxPics, lpT);
  4233. #ifndef RA2_MODE
  4234. if(istiberium)
  4235. for(i=0;i<16;i++)
  4236. FSunPackLib::SetTSPaletteEntry(hPalette, 0x10+i, &rgbOld[i], NULL);
  4237. #endif
  4238. for(i=0; i<maxPics; i++)
  4239. {
  4240. SHPIMAGEHEADER imghead;
  4241. FSunPackLib::XCC_GetSHPImageHeader(i, &imghead);
  4242. // MW: fixed april 20th, 2002
  4243. if(imghead.unknown==0 && !isTrue(g_data.sections["Debug"].values["IgnoreSHPImageHeadUnused"])) // is it a shadow or not used image?
  4244. if(lpT[i])
  4245. {
  4246. delete[] lpT[i];
  4247. lpT[i]=NULL;
  4248. }
  4249. if(/*imghead.unknown &&*/ lpT[i])
  4250. {
  4251. char ic[50];
  4252. itoa(i, ic, 10);
  4253. PICDATA p;
  4254. p.pic=lpT[i];
  4255. if(hPalette==m_hPalIsoTemp || hPalette==m_hPalIsoUrb || hPalette==m_hPalIsoSnow || hPalette==m_hPalIsoDes || hPalette==m_hPalIsoLun || hPalette==m_hPalIsoUbn) p.pal=iPalIso;
  4256. if(hPalette==m_hPalTemp || hPalette==m_hPalUrb || hPalette==m_hPalSnow || hPalette==m_hPalDes || hPalette==m_hPalLun || hPalette==m_hPalUbn) p.pal=iPalTheater;
  4257. if(hPalette==m_hPalUnitTemp || hPalette==m_hPalUnitUrb || hPalette==m_hPalUnitSnow || hPalette==m_hPalUnitDes || hPalette==m_hPalUnitLun || hPalette==m_hPalUnitUbn) p.pal=iPalUnit;
  4258. p.vborder=new(VBORDER[head.cy]);
  4259. int k;
  4260. for(k=0;k<head.cy;k++)
  4261. {
  4262. int l,r;
  4263. GetDrawBorder(lpT[i], head.cx, k, l, r, 0);
  4264. p.vborder[k].left=l;
  4265. p.vborder[k].right=r;
  4266. }
  4267. p.x=imghead.x;
  4268. p.y=imghead.y;
  4269. p.wHeight=imghead.cy;
  4270. p.wWidth=imghead.cx;
  4271. p.wMaxWidth=head.cx;
  4272. p.wMaxHeight=head.cy;
  4273. p.bType=PICDATA_TYPE_SHP;
  4274. pics[(CString)"OVRL"+ OvrlID + "_" + ic]=p;
  4275. }
  4276. }
  4277. delete[] lpT;
  4278. }
  4279. }
  4280. int i;
  4281. for(i=0; i<0xFF; i++)
  4282. {
  4283. char ic[50];
  4284. itoa(i, ic, 10);
  4285. pics[(CString)"OVRL"+ OvrlID + "_" + ic].bTried=TRUE;
  4286. }
  4287. }
  4288. #else // surfaces
  4289. void CLoading::LoadOverlayGraphic(LPCTSTR lpOvrlName_, int iOvrlNum)
  4290. {
  4291. last_succeeded_operation=11;
  4292. CString image; // the image used
  4293. CString filename; // filename of the image
  4294. SHPHEADER head;
  4295. char theat=cur_theat;
  4296. LPDIRECTDRAWSURFACE4* lpT=NULL;
  4297. char OvrlID[50];
  4298. itoa(iOvrlNum, OvrlID, 10);
  4299. HTSPALETTE hPalette;
  4300. if(cur_theat=='T')
  4301. {
  4302. hPalette=m_hPalIsoTemp;
  4303. #ifdef RA2_MODE
  4304. hPalette=m_hPalIsoTemp;
  4305. #endif
  4306. }
  4307. if(cur_theat=='A')
  4308. {
  4309. hPalette=m_hPalIsoSnow;
  4310. #ifdef RA2_MODE
  4311. hPalette=m_hPalIsoSnow;
  4312. #endif
  4313. }
  4314. if(cur_theat=='U' && m_hPalIsoUrb)
  4315. {
  4316. hPalette=m_hPalIsoUrb;
  4317. #ifdef RA2_MODE
  4318. hPalette=m_hPalIsoUrb;
  4319. #endif
  4320. }
  4321. HMIXFILE hMix;
  4322. CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview;
  4323. CString lpOvrlName = lpOvrlName_;
  4324. if (lpOvrlName.Find(' ') >= 0) lpOvrlName = lpOvrlName.Left(lpOvrlName.Find(' '));
  4325. CString isveinhole_t=rules.sections[lpOvrlName].values["IsVeinholeMonster"];
  4326. CString istiberium_t=rules.sections[lpOvrlName].values["Tiberium"];
  4327. CString isveins_t=rules.sections[lpOvrlName].values["IsVeins"];
  4328. isveinhole_t.MakeLower();
  4329. istiberium_t.MakeLower();
  4330. isveins_t.MakeLower();
  4331. BOOL isveinhole=FALSE, istiberium=FALSE, isveins=FALSE;
  4332. if(isTrue(isveinhole_t)) isveinhole=TRUE;
  4333. if(isTrue(istiberium_t)) istiberium=TRUE;
  4334. if(isTrue(isveins_t)) isveins=TRUE;
  4335. image=lpOvrlName;
  4336. if(rules.sections[lpOvrlName].values.find("Image")!=rules.sections[lpOvrlName].values.end())
  4337. image=rules.sections[lpOvrlName].values["Image"];
  4338. TruncSpace(image);
  4339. CString imagerules=image;
  4340. if(art.sections[image].values.find("Image")!=art.sections[image].values.end())
  4341. image=art.sections[image].values["Image"];
  4342. TruncSpace(image);
  4343. if(cur_theat=='T') filename=image+".tem";
  4344. if(cur_theat=='A') filename=image+".sno";
  4345. if(cur_theat=='U') filename=image+".urb";
  4346. hMix=FindFileInMix(filename);
  4347. if(hMix==NULL)
  4348. {
  4349. filename=image+".shp";
  4350. if(isTrue(art.sections[image].values["NewTheater"]))
  4351. filename.SetAt(1, theat);
  4352. if(cur_theat=='U' && m_hPalUnitUrb) hPalette=m_hPalUnitUrb;
  4353. if(cur_theat=='T') hPalette=m_hPalUnitTemp;
  4354. if(cur_theat=='A') hPalette=m_hPalUnitSnow;
  4355. hMix=FindFileInMix(filename);
  4356. // errstream << (LPCSTR)filename << " " << hMix;
  4357. if(hMix==NULL)
  4358. {
  4359. filename.SetAt(1, 'T');
  4360. hMix=FindFileInMix(filename);
  4361. }
  4362. if(hMix==NULL)
  4363. {
  4364. filename.SetAt(1, 'A');
  4365. hMix=FindFileInMix(filename);
  4366. }
  4367. if(hMix==NULL)
  4368. {
  4369. filename.SetAt(1, 'U');
  4370. hMix=FindFileInMix(filename);
  4371. }
  4372. if(cur_theat=='T' || cur_theat=='U')
  4373. {
  4374. hPalette=m_hPalUnitTemp;
  4375. }
  4376. else
  4377. hPalette=m_hPalUnitSnow;
  4378. }
  4379. if(hMix==NULL)
  4380. {
  4381. filename=image+".tem";
  4382. hMix=FindFileInMix(filename);
  4383. if(hMix) hPalette=m_hPalIsoTemp;
  4384. }
  4385. if(hMix==NULL)
  4386. {
  4387. filename=image+".sno";
  4388. hMix=FindFileInMix(filename);
  4389. if(hMix) hPalette=m_hPalIsoSnow;
  4390. }
  4391. if(hMix==NULL)
  4392. {
  4393. filename=image+".urb";
  4394. hMix=FindFileInMix(filename);
  4395. if(hMix && m_hPalIsoUrb) hPalette=m_hPalIsoUrb;
  4396. }
  4397. if(isveinhole==TRUE || isveins==TRUE || istiberium==TRUE)
  4398. {
  4399. hPalette=m_hPalTemp;
  4400. #ifndef RA2_MODE
  4401. hPalette=m_hPalUnitTemp;
  4402. #endif
  4403. }
  4404. if(hMix!=NULL)
  4405. {
  4406. FSunPackLib::SetCurrentSHP(filename, hMix);
  4407. {
  4408. FSunPackLib::XCC_GetSHPHeader(&head);
  4409. int i;
  4410. int maxPics=head.c_images;
  4411. if(maxPics>max_ovrl_img) maxPics=max_ovrl_img; // max may_ovrl_img pictures (memory usage!)
  4412. //errstream << ", loading " << maxPics << " of " << head.c_images << " pictures. ";
  4413. //errstream.flush();
  4414. // create an array of pointers to directdraw surfaces
  4415. lpT=new(LPDIRECTDRAWSURFACE4[maxPics]);
  4416. memset(lpT, 0, sizeof(LPDIRECTDRAWSURFACE4)*maxPics);
  4417. // if tiberium, change color
  4418. BOOL bIsBlueTib=FALSE;
  4419. BOOL bIsGreenTib=FALSE;
  4420. RGBTRIPLE rgbOld[16], rgbNew;
  4421. #ifndef RA2_MODE
  4422. if(istiberium)
  4423. {
  4424. if(lpOvrlName[4]=='_') // other than green!
  4425. bIsBlueTib=TRUE;
  4426. else
  4427. bIsGreenTib=TRUE;
  4428. int i;
  4429. for(i=0;i<16;i++)
  4430. {
  4431. if(bIsGreenTib)
  4432. {
  4433. rgbNew.rgbtBlue=0;
  4434. if(i!=0)
  4435. rgbNew.rgbtGreen=255-i*16+1;
  4436. else
  4437. rgbNew.rgbtGreen=255;
  4438. rgbNew.rgbtRed=0;
  4439. }
  4440. else if(bIsBlueTib)
  4441. {
  4442. if(i!=0)
  4443. rgbNew.rgbtBlue=255-i*16+1;
  4444. else
  4445. rgbNew.rgbtBlue=255;
  4446. rgbNew.rgbtGreen=0;
  4447. rgbNew.rgbtRed=0;
  4448. }
  4449. FSunPackLib::SetTSPaletteEntry(hPalette, 0x10+i, &rgbNew, &rgbOld[i]);
  4450. }
  4451. }
  4452. #endif
  4453. FSunPackLib::LoadSHPImageInSurface(v.dd, hPalette, 0, maxPics, lpT);
  4454. #ifndef RA2_MODE
  4455. if(istiberium)
  4456. for(i=0;i<16;i++)
  4457. FSunPackLib::SetTSPaletteEntry(hPalette, 0x10+i, &rgbOld[i], NULL);
  4458. #endif
  4459. for(i=0; i<maxPics; i++)
  4460. {
  4461. SHPIMAGEHEADER imghead;
  4462. FSunPackLib::XCC_GetSHPImageHeader(i, &imghead);
  4463. if(imghead.unknown==0) // is it a shadow or not used image?
  4464. if(lpT[i]) lpT[i]->Release();
  4465. if(imghead.unknown && lpT[i])
  4466. {
  4467. char ic[50];
  4468. itoa(i, ic, 10);
  4469. PICDATA p;
  4470. p.pic=lpT[i];
  4471. p.x=imghead.x;
  4472. p.y=imghead.y;
  4473. p.wHeight=imghead.cy;
  4474. p.wWidth=imghead.cx;
  4475. p.wMaxWidth=head.cx;
  4476. p.wMaxHeight=head.cy;
  4477. p.bType=PICDATA_TYPE_SHP;
  4478. pics[(CString)"OVRL"+ OvrlID + "_" + ic]=p;
  4479. }
  4480. }
  4481. delete[] lpT;
  4482. //errstream << " --> Finished" << endl;
  4483. //errstream.flush();
  4484. }
  4485. /*else
  4486. {
  4487. errstream << " failed";
  4488. errstream.flush();
  4489. }*/
  4490. }
  4491. else
  4492. {
  4493. //errstream << "File not found: " << (LPCTSTR)filename << endl;
  4494. //errstream.flush();
  4495. }
  4496. int i;
  4497. for(i=0; i<0xFF; i++)
  4498. {
  4499. char ic[50];
  4500. itoa(i, ic, 10);
  4501. pics[(CString)"OVRL"+ OvrlID + "_" + ic].bTried=TRUE;
  4502. }
  4503. }
  4504. #endif
  4505. void CLoading::OnDestroy()
  4506. {
  4507. CDialog::OnDestroy();
  4508. }
  4509. void CLoading::InitVoxelNormalTables()
  4510. {
  4511. try
  4512. {
  4513. std::ifstream f(std::string(AppPath) + "\\voxel_normal_tables.bin", std::ios::binary);
  4514. m_voxelNormalTables.reset(new VoxelNormalTables(f));
  4515. }
  4516. catch (const std::runtime_error& e)
  4517. {
  4518. errstream << e.what() << std::endl;
  4519. m_voxelNormalTables.reset(new VoxelNormalTables());
  4520. }
  4521. }
  4522. void CLoading::CalcPicCount()
  4523. {
  4524. m_pic_count=0;
  4525. CString bmps=(CString)AppPath+"\\pics\\*.bmp";
  4526. if(!theApp.m_Options.bDoNotLoadBMPs)
  4527. {
  4528. CFileFind ff;
  4529. if(ff.FindFile(bmps))
  4530. {
  4531. // found bmp
  4532. m_pic_count++;
  4533. while(ff.FindNextFile()) m_pic_count++;
  4534. }
  4535. }
  4536. m_bmp_count=m_pic_count;
  4537. if(!theApp.m_Options.bDoNotLoadVehicleGraphics) m_pic_count+=rules.sections["VehicleTypes"].values.size();
  4538. if(!theApp.m_Options.bDoNotLoadOverlayGraphics) m_pic_count+=rules.sections["OverlayTypes"].values.size();
  4539. if(!theApp.m_Options.bDoNotLoadInfantryGraphics) m_pic_count+=rules.sections["InfantryTypes"].values.size();
  4540. if(!theApp.m_Options.bDoNotLoadBuildingGraphics) m_pic_count+=rules.sections["BuildingTypes"].values.size();
  4541. if(!theApp.m_Options.bDoNotLoadAircraftGraphics) m_pic_count+=rules.sections["AircraftTypes"].values.size();
  4542. if(!theApp.m_Options.bDoNotLoadTreeGraphics) m_pic_count+=rules.sections["TerrainTypes"].values.size();
  4543. int i;
  4544. /*
  4545. if(!theApp.m_Options.bDoNotLoadSnowGraphics)
  4546. {
  4547. tiledata=&s_tiledata;
  4548. tiles=&tiles_s;
  4549. tiledata_count=&s_tiledata_count;
  4550. for(i=0;i<10000;i++)
  4551. {
  4552. CString tset;
  4553. char c[50];
  4554. itoa(i, c, 10);
  4555. int e;
  4556. for(e=0;e<4-strlen(c);e++)
  4557. tset+="0";
  4558. tset+=c;
  4559. CString sec="TileSet";
  4560. sec+=tset;
  4561. if(tiles->sections.find(sec)==tiles->sections.end()) break;
  4562. for(e=0;e<atoi(tiles->sections[sec].values["TilesInSet"]);e++)
  4563. {
  4564. m_pic_count++;
  4565. }
  4566. }
  4567. }
  4568. if(!theApp.m_Options.bDoNotLoadTemperateGraphics)
  4569. {
  4570. tiledata=&t_tiledata;
  4571. tiles=&tiles_t;
  4572. tiledata_count=&t_tiledata_count;
  4573. for(i=0;i<10000;i++)
  4574. {
  4575. CString tset;
  4576. char c[50];
  4577. itoa(i, c, 10);
  4578. int e;
  4579. for(e=0;e<4-strlen(c);e++)
  4580. tset+="0";
  4581. tset+=c;
  4582. CString sec="TileSet";
  4583. sec+=tset;
  4584. if(tiles->sections.find(sec)==tiles->sections.end()) break;
  4585. for(e=0;e<atoi(tiles->sections[sec].values["TilesInSet"]);e++)
  4586. {
  4587. m_pic_count++;
  4588. }
  4589. }
  4590. }*/
  4591. }
  4592. BOOL CLoading::InitDirectDraw()
  4593. {
  4594. last_succeeded_operation=7;
  4595. errstream << "\n\nDirectDrawCreate() will be called now\n";
  4596. errstream.flush();
  4597. CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview;
  4598. if(DirectDrawCreate(NULL, &v.dd_1, NULL)!=DD_OK)
  4599. {
  4600. errstream << "DirectDrawCreate() failed\n";
  4601. errstream.flush();
  4602. ShowWindow(SW_HIDE);
  4603. MessageBox("DirectDraw could not be initialized! Quitting...");
  4604. exit(-1);
  4605. return FALSE;
  4606. }
  4607. errstream << "DirectDrawCreate() successful\n\n";
  4608. errstream.flush();
  4609. if(m_progress.m_hWnd) m_progress.SetPos(1);
  4610. if(m_hWnd) UpdateWindow();
  4611. errstream << "Now querying the DirectX 7 or 6 interface\n";
  4612. errstream.flush();
  4613. if(v.dd_1->QueryInterface(IID_IDirectDraw7, (void**)&v.dd)!=DD_OK)
  4614. {
  4615. errstream << "QueryInterface() failed -> Using DirectX 6.0\n";
  4616. errstream.flush();
  4617. //ShowWindow(SW_HIDE);
  4618. //MessageBox("You don´t have DirectX 6.0 but an older version. Quitting...");
  4619. //exit(-1);
  4620. //return FALSE;
  4621. if(v.dd_1->QueryInterface(IID_IDirectDraw4, (void**)&v.dd)!=DD_OK)
  4622. {
  4623. MessageBox("You need at least DirectX 6.0 to run this program", "Error");
  4624. exit(-1);
  4625. return FALSE;
  4626. }
  4627. }
  4628. errstream << "QueryInterface() successful\n\nNow setting cooperative level\n";
  4629. errstream.flush();
  4630. if(v.dd->SetCooperativeLevel(v.m_hWnd, DDSCL_NORMAL | DDSCL_NOWINDOWCHANGES )!=DD_OK)
  4631. {
  4632. errstream << "SetCooperativeLevel() failed\n";
  4633. errstream.flush();
  4634. ShowWindow(SW_HIDE);
  4635. MessageBox("Cooperative Level could not be set! Quitting...");
  4636. v.dd->Release();
  4637. v.dd=NULL;
  4638. exit(-2);
  4639. return FALSE;
  4640. }
  4641. errstream << "SetCooperativeLevel() successful\n\nCreating primary surface\n";
  4642. errstream.flush();
  4643. if(m_progress.m_hWnd) m_progress.SetPos(2);
  4644. if(m_hWnd) UpdateWindow();
  4645. DDSURFACEDESC2 ddsd;
  4646. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  4647. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  4648. ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE ;
  4649. ddsd.dwFlags=DDSD_CAPS ;
  4650. int res=0;
  4651. int trycount=0;
  4652. do
  4653. {
  4654. res=v.dd->CreateSurface(&ddsd, &v.lpds, NULL);
  4655. errstream << "Return code: " << res << endl;
  4656. errstream.flush();
  4657. //if(res!=DD_OK && (res!=DDERR_PRIMARYSURFACEALREADYEXISTS || trycount>100))
  4658. if(res!=DD_OK && trycount>=300)
  4659. {
  4660. errstream << "CreateSurface() failed\n";
  4661. errstream.flush();
  4662. ShowWindow(SW_HIDE);
  4663. MessageBox("Primary surface could not be initialized! Quitting...");
  4664. v.dd->Release();
  4665. v.dd=NULL;
  4666. exit(-3);
  4667. return FALSE;
  4668. }
  4669. trycount++;
  4670. if(res!=DD_OK)
  4671. {
  4672. Sleep(50);
  4673. }
  4674. }while(res!=DD_OK);
  4675. #ifdef NOSURFACES
  4676. DDPIXELFORMAT pf;
  4677. memset(&pf, 0, sizeof(DDPIXELFORMAT));
  4678. pf.dwSize=sizeof(DDPIXELFORMAT);
  4679. v.lpds->GetPixelFormat(&pf);
  4680. if(!pf.dwBBitMask || !pf.dwRBitMask || !pf.dwGBitMask)
  4681. {
  4682. ShowWindow(SW_HIDE);
  4683. MessageBox("You must not use a palette color mode like 8 bit in order to run FinalSun/FinalAlert 2. Please check readme.txt","Error",MB_OK);
  4684. v.lpds->Release();
  4685. v.lpds=NULL;
  4686. v.dd->Release();
  4687. v.dd=NULL;
  4688. exit(-3);
  4689. return FALSE;
  4690. }
  4691. bpp=(pf.dwRGBBitCount+7)/8;
  4692. #endif
  4693. errstream << "CreateSurface() successful\n\nCreating backbuffer surface\n";
  4694. errstream.flush();
  4695. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  4696. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  4697. ddsd.dwFlags=DDSD_WIDTH | DDSD_HEIGHT;
  4698. v.lpds->GetSurfaceDesc(&ddsd);
  4699. ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
  4700. ddsd.dwFlags=DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  4701. if(v.dd->CreateSurface(&ddsd, &v.lpdsBack, NULL)!=DD_OK)
  4702. {
  4703. errstream << "CreateSurface() failed\n";
  4704. errstream.flush();
  4705. ShowWindow(SW_HIDE);
  4706. MessageBox("Backbuffer surface could not be initialized! Quitting...");
  4707. v.lpds->Release();
  4708. v.lpds=NULL;
  4709. v.dd->Release();
  4710. v.dd=NULL;
  4711. exit(-4);
  4712. return FALSE;
  4713. }
  4714. if (theApp.m_Options.bHighResUI && v.dd->CreateSurface(&ddsd, &v.lpdsBackHighRes, NULL) != DD_OK)
  4715. {
  4716. errstream << "CreateSurface() failed\n";
  4717. errstream.flush();
  4718. ShowWindow(SW_HIDE);
  4719. MessageBox("Highres Backbuffer surface could not be initialized! Quitting...");
  4720. v.lpdsBack->Release();
  4721. v.lpdsBack = NULL;
  4722. v.lpds->Release();
  4723. v.lpds = NULL;
  4724. v.dd->Release();
  4725. v.dd = NULL;
  4726. exit(-4);
  4727. return FALSE;
  4728. }
  4729. if(v.dd->CreateSurface(&ddsd, &v.lpdsTemp, NULL)!=DD_OK)
  4730. {
  4731. errstream << "CreateSurface() failed\n";
  4732. errstream.flush();
  4733. ShowWindow(SW_HIDE);
  4734. MessageBox("Tempbuffer surface could not be initialized! Quitting...");
  4735. v.lpdsBack->Release();
  4736. v.lpdsBack=NULL;
  4737. if (v.lpdsBackHighRes)
  4738. v.lpdsBackHighRes->Release();
  4739. v.lpdsBackHighRes = nullptr;
  4740. v.lpds->Release();
  4741. v.lpds=NULL;
  4742. v.dd->Release();
  4743. v.dd=NULL;
  4744. exit(-4);
  4745. return FALSE;
  4746. }
  4747. errstream << "CreateSurface() successful\n\nNow creating clipper\n";
  4748. errstream.flush();
  4749. LPDIRECTDRAWCLIPPER ddc;
  4750. if(v.dd->CreateClipper(0, &ddc, NULL)!=DD_OK)
  4751. {
  4752. errstream << "CreateClipper() failed\n";
  4753. errstream.flush();
  4754. ShowWindow(SW_HIDE);
  4755. MessageBox("Clipper could not be created! Quitting...");
  4756. v.lpdsTemp->Release();
  4757. v.lpdsTemp=NULL;
  4758. v.lpdsBack->Release();
  4759. v.lpdsBack=NULL;
  4760. if (v.lpdsBackHighRes)
  4761. v.lpdsBackHighRes->Release();
  4762. v.lpdsBackHighRes = nullptr;
  4763. v.lpds->Release();
  4764. v.lpds=NULL;
  4765. v.dd->Release();
  4766. v.dd=NULL;
  4767. exit(-6);
  4768. }
  4769. errstream << "CreateClipper() successful\n\n";
  4770. errstream.flush();
  4771. v.lpds->SetClipper(ddc);
  4772. ddc->SetHWnd(0, v.m_hWnd);
  4773. return TRUE;
  4774. }
  4775. void CLoading::OnPaint()
  4776. {
  4777. CPaintDC dc(this); // device context for painting
  4778. CWnd* poswindow=GetDlgItem(IDC_SAVEOFTEN);
  4779. if(!poswindow) return;
  4780. RECT r1,r2;
  4781. poswindow->GetWindowRect(&r1);
  4782. GetWindowRect(&r2);
  4783. dc.SetTextColor(RGB(255, 0, 0));
  4784. dc.SetBkMode(TRANSPARENT);
  4785. RECT dest;
  4786. dest.top=r1.bottom-r2.top-45;
  4787. dest.bottom=r1.bottom-r2.top+10;
  4788. dest.left=10;
  4789. dest.right=r1.right-r1.left+10;
  4790. CFont f;
  4791. f.CreatePointFont(90, "Tahoma");
  4792. dc.SelectObject(&f);
  4793. }
  4794. void CLoading::FreeTileSet()
  4795. {
  4796. // free the current tileset
  4797. int i;
  4798. for(i=0;i<(*tiledata_count);i++)
  4799. {
  4800. int e;
  4801. int z;
  4802. // delete replacements. Replacements themself MUST NOT have replacements
  4803. for(z=0;z<(*tiledata)[i].bReplacementCount;z++)
  4804. {
  4805. TILEDATA& rept=(*tiledata)[i].lpReplacements[z];
  4806. for(e=0;e<rept.wTileCount;e++)
  4807. {
  4808. #ifdef NOSURFACES
  4809. BYTE* curSur=rept.tiles[e].pic;
  4810. if(curSur) delete[] curSur;
  4811. if(rept.tiles[e].vborder) delete[] rept.tiles[e].vborder;
  4812. #else
  4813. LPDIRECTDRAWSURFACE4 curSur=rept.tiles[e].pic;
  4814. if(curSur) curSur->Release();
  4815. #endif
  4816. }
  4817. delete[] rept.tiles;
  4818. rept.tiles=NULL;
  4819. rept.wTileCount=0;
  4820. rept.bReplacementCount=0;
  4821. ASSERT(!rept.lpReplacements); // make sure we don´t have replacements for this replacement
  4822. }
  4823. for(e=0;e<(*tiledata)[i].wTileCount;e++)
  4824. {
  4825. #ifdef NOSURFACES
  4826. BYTE* curSur=(*tiledata)[i].tiles[e].pic;
  4827. if(curSur) delete[] curSur;
  4828. if((*tiledata)[i].tiles[e].vborder) delete[] (*tiledata)[i].tiles[e].vborder;
  4829. #else
  4830. LPDIRECTDRAWSURFACE4 curSur=(*tiledata)[i].tiles[e].pic;
  4831. if(curSur) curSur->Release();
  4832. #endif
  4833. }
  4834. delete[] ((*tiledata)[i].tiles);
  4835. (*tiledata)[i].tiles=NULL;
  4836. (*tiledata)[i].wTileCount=0;
  4837. (*tiledata)[i].bReplacementCount=0;
  4838. if((*tiledata)[i].lpReplacements) delete[] (*tiledata)[i].lpReplacements;
  4839. (*tiledata)[i].lpReplacements=NULL;
  4840. }
  4841. if(*tiledata) delete[] (*tiledata);
  4842. (*tiledata)=NULL;
  4843. (*tiledata_count)=0;
  4844. }
  4845. void CLoading::FreeAll()
  4846. {
  4847. last_succeeded_operation=14;
  4848. // MW fix: We need to set tiledata and tiledata_count to the old pointers again
  4849. int t=0;
  4850. if(tiledata==&t_tiledata) t=0;
  4851. if(tiledata==&s_tiledata) t=1;
  4852. if(tiledata==&u_tiledata) t=2;
  4853. if(tiledata==&un_tiledata) t=3;
  4854. if(tiledata==&l_tiledata) t=4;
  4855. if(tiledata==&d_tiledata) t=4;
  4856. //try{
  4857. tiledata=&t_tiledata;
  4858. tiledata_count=&t_tiledata_count;
  4859. FreeTileSet();
  4860. tiledata=&s_tiledata;
  4861. tiledata_count=&s_tiledata_count;
  4862. FreeTileSet();
  4863. tiledata=&u_tiledata;
  4864. tiledata_count=&u_tiledata_count;
  4865. FreeTileSet();
  4866. // MW New tilesets:
  4867. tiledata=&un_tiledata;
  4868. tiledata_count=&un_tiledata_count;
  4869. FreeTileSet();
  4870. tiledata=&l_tiledata;
  4871. tiledata_count=&l_tiledata_count;
  4872. FreeTileSet();
  4873. tiledata=&d_tiledata;
  4874. tiledata_count=&d_tiledata_count;
  4875. FreeTileSet();
  4876. /* }
  4877. catch(...)
  4878. {
  4879. errstream << "Exception in FreeTileSet()" << endl;
  4880. }*/
  4881. // MW Reset tiledata & tiledata_count
  4882. if(t==0) { tiledata=&t_tiledata; tiledata_count=&t_tiledata_count; }
  4883. if(t==1) { tiledata=&s_tiledata; tiledata_count=&s_tiledata_count; }
  4884. if(t==2) { tiledata=&u_tiledata; tiledata_count=&u_tiledata_count; }
  4885. if(t==3) { tiledata=&un_tiledata; tiledata_count=&un_tiledata_count; }
  4886. if(t==4) { tiledata=&l_tiledata; tiledata_count=&l_tiledata_count; }
  4887. if(t==5) { tiledata=&d_tiledata; tiledata_count=&d_tiledata_count; }
  4888. map<CString, PICDATA>::iterator i=pics.begin();
  4889. for (int e=0;e<pics.size();e++)
  4890. {
  4891. try{
  4892. #ifdef NOSURFACES_OBJECTS
  4893. if(i->second.bType==PICDATA_TYPE_BMP)
  4894. {
  4895. if(i->second.pic!=NULL)
  4896. {
  4897. ((LPDIRECTDRAWSURFACE4)i->second.pic)->Release();
  4898. }
  4899. }
  4900. else
  4901. {
  4902. if(i->second.pic!=NULL)
  4903. {
  4904. delete[] i->second.pic;
  4905. }
  4906. if(i->second.vborder) delete[] i->second.vborder;
  4907. }
  4908. #else
  4909. if(i->second.pic!=NULL) i->second.pic->Release();
  4910. #endif
  4911. i->second.pic=NULL;
  4912. }
  4913. catch(...)
  4914. {
  4915. CString err;
  4916. err="Access violation while trying to release surface ";
  4917. char c[6];
  4918. itoa(e,c,10);
  4919. err+=c;
  4920. err+="\n";
  4921. OutputDebugString(err);
  4922. continue;
  4923. }
  4924. i++;
  4925. }
  4926. try{
  4927. CFinalSunDlg* dlg=((CFinalSunDlg*)theApp.m_pMainWnd);
  4928. if(dlg->m_view.m_isoview->lpds!=NULL) dlg->m_view.m_isoview->lpds->Release();
  4929. dlg->m_view.m_isoview->lpds=NULL;
  4930. if(dlg->m_view.m_isoview->lpdsBack!=NULL) dlg->m_view.m_isoview->lpdsBack->Release();
  4931. dlg->m_view.m_isoview->lpdsBack=NULL;
  4932. if (dlg->m_view.m_isoview->lpdsBackHighRes != NULL) dlg->m_view.m_isoview->lpdsBackHighRes->Release();
  4933. dlg->m_view.m_isoview->lpdsBackHighRes = NULL;
  4934. if(dlg->m_view.m_isoview->lpdsTemp!=NULL) dlg->m_view.m_isoview->lpdsTemp->Release();
  4935. dlg->m_view.m_isoview->lpdsTemp=NULL;
  4936. if(dlg->m_view.m_isoview->dd!=NULL) dlg->m_view.m_isoview->dd->Release();
  4937. dlg->m_view.m_isoview->dd=NULL;
  4938. if(dlg->m_view.m_isoview->dd_1!=NULL) dlg->m_view.m_isoview->dd_1->Release();
  4939. dlg->m_view.m_isoview->dd_1=NULL;
  4940. }
  4941. catch(...)
  4942. {
  4943. errstream << "Exception while freeing DirectDraw" << endl;
  4944. }
  4945. }
  4946. void CLoading::PostNcDestroy()
  4947. {
  4948. // delete this; // on stack!
  4949. // CDialog::PostNcDestroy();
  4950. }
  4951. void CLoading::PrepareHouses()
  4952. {
  4953. int i;
  4954. int p=0 ;
  4955. for(i=0;i<rules.sections["Sides"].values.size();i++)
  4956. {
  4957. int t=0;
  4958. while(GetParam(*rules.sections["Sides"].GetValue(i), t).GetLength()>0)
  4959. {
  4960. sides[p].name=GetParam(*rules.sections["Sides"].GetValue(i), t);
  4961. sides[p].orig_n=rules.sections["Sides"].GetValueOrigPos(i); // mw fix instead of =i
  4962. t++;
  4963. p++;
  4964. }
  4965. }
  4966. for(i=0;i<rules.sections[HOUSES].values.size();i++)
  4967. {
  4968. if(rules.sections[HOUSES].GetValueOrigPos(i)<0) continue;
  4969. HOUSEINFO& house=houses[rules.sections[HOUSES].GetValueOrigPos(i)];
  4970. house.name=*rules.sections[HOUSES].GetValue(i);
  4971. house.bPlayable=isTrue(rules.sections[house.name].values["Multiplay"]);
  4972. memset(&house.color, 0, sizeof(RGBTRIPLE));
  4973. int e;
  4974. for(e=0;e<sides.size();e++)
  4975. {
  4976. house.side=NULL;
  4977. if(sides[e].name==rules.sections[house.name].values["Side"])
  4978. house.side=&sides[e];
  4979. }
  4980. }
  4981. }
  4982. BYTE* Search(BYTE** lpData, BYTE* lpSearched)
  4983. {
  4984. BYTE* lpDat=*lpData;
  4985. lpDat=(BYTE*)strstr((LPCSTR)lpDat, (LPCSTR)lpSearched)+strlen((LPCSTR)lpSearched);
  4986. return lpDat;
  4987. }
  4988. class SortDummy2{
  4989. public:
  4990. bool operator() (const CString& x, const CString& y) const
  4991. {
  4992. // the length is more important than spelling (numbers!!!)...
  4993. if(x.GetLength()<y.GetLength()) return true;
  4994. if(x.GetLength()==y.GetLength())
  4995. {
  4996. CString x2=x;
  4997. CString y2=y;
  4998. x2.MakeLower();
  4999. y2.MakeLower();
  5000. if(x2<y2) return true;
  5001. }
  5002. return false;
  5003. }
  5004. };
  5005. extern map<CString, XCString> AllStrings;
  5006. void CLoading::LoadStrings()
  5007. {
  5008. last_succeeded_operation=9;
  5009. #ifdef RA2_MODE
  5010. // MW April 17th, 2002:
  5011. // ra2md.csf supported!
  5012. std::string file="RA2.CSF";
  5013. if(yuri_mode)
  5014. file="RA2MD.CSF";
  5015. errstream << "LoadStrings() executing" << endl;
  5016. errstream.flush();
  5017. BYTE *lpData=NULL;
  5018. DWORD dwSize;
  5019. if(DoesFileExist((std::string(TSPath) + "\\" + file).c_str()))
  5020. {
  5021. std::ifstream f(std::string(TSPath) + "\\" + file, ios::binary);
  5022. if (f.good())
  5023. {
  5024. f.seekg(0, std::ios::end);
  5025. auto size = f.tellg();
  5026. if (size > 0)
  5027. {
  5028. lpData = new(BYTE[size]);
  5029. dwSize = size;
  5030. f.seekg(0, std::ios::beg);
  5031. f.read(reinterpret_cast<char*>(lpData), dwSize);
  5032. }
  5033. }
  5034. }
  5035. errstream << "LoadStrings() loading from mix" << endl;
  5036. errstream.flush();
  5037. if(!lpData)
  5038. {
  5039. HMIXFILE hMix=FindFileInMix(file.c_str());
  5040. //HMIXFILE hMix=m_hLanguage;
  5041. if(hMix)
  5042. {
  5043. if (FSunPackLib::XCC_ExtractFile(file, u8AppDataPath + "\\RA2Tmp.csf", hMix))
  5044. {
  5045. std::ifstream f(u8AppDataPath + "\\RA2Tmp.csf", ios::binary);
  5046. if (f.good())
  5047. {
  5048. f.seekg(0, std::ios::end);
  5049. auto size = f.tellg();
  5050. if (size > 0)
  5051. {
  5052. lpData = new(BYTE[size]);
  5053. dwSize = size;
  5054. f.seekg(0, std::ios::beg);
  5055. f.read(reinterpret_cast<char*>(lpData), dwSize);
  5056. }
  5057. }
  5058. }
  5059. if (!lpData)
  5060. {
  5061. MessageBox("String file not found, using rules.ini names","Error");
  5062. return;
  5063. }
  5064. }
  5065. else
  5066. {
  5067. MessageBox("String file not found, using rules.ini names","Error");
  5068. return;
  5069. }
  5070. }
  5071. BYTE* orig=static_cast<BYTE*>(lpData);
  5072. if(!(lpData=Search(&lpData, (BYTE*)" FSC"))) return;
  5073. RA2STRFILEHEAD head;
  5074. memcpy(&head, lpData, RA2STRFILEHEADSIZE);
  5075. lpData+=RA2STRFILEHEADSIZE;
  5076. map<CString, XCString, SortDummy2> strings;
  5077. int i;
  5078. //try{
  5079. for(i=0;i<head.dwCount1;i++)
  5080. {
  5081. ASSERT(orig+dwSize>lpData);
  5082. if(!(lpData=lpData+4))//Search(&lpData, (BYTE*)" LBL")))
  5083. {
  5084. return;
  5085. }
  5086. RA2STRINGENTRY entry;
  5087. memcpy(&entry.dwFlag, lpData, 4);
  5088. lpData+=4;
  5089. DWORD dwCharCount;
  5090. memcpy(&dwCharCount, lpData, 4);
  5091. lpData+=4;
  5092. BYTE* lpID=new(BYTE[dwCharCount+1]);
  5093. memcpy(lpID, lpData, dwCharCount);
  5094. lpData+=dwCharCount;
  5095. lpID[dwCharCount]=0;
  5096. entry.id=(CHAR*)new(BYTE[dwCharCount+1]);
  5097. strcpy(entry.id, (LPCSTR)lpID);
  5098. entry.id[dwCharCount]=0;
  5099. entry.id_size=dwCharCount;
  5100. // enable this to show the string ID
  5101. delete[](lpID);
  5102. BOOL b2Strings=FALSE;
  5103. if(lpData[0]=='W')
  5104. b2Strings=TRUE;
  5105. if(!(lpData=lpData+4))//Search(&lpData, (BYTE*)" RTS")))
  5106. {
  5107. return;
  5108. }
  5109. memcpy(&dwCharCount, lpData, 4);
  5110. lpData+=4;
  5111. WCHAR* lpwID=new(WCHAR[dwCharCount+1]);
  5112. int e;
  5113. for(e=0;e<dwCharCount;e++)
  5114. {
  5115. WCHAR w;
  5116. memcpy(&w, lpData, 2);
  5117. lpData+=2;
  5118. lpwID[e]=~w;
  5119. }
  5120. lpwID[dwCharCount]=0;
  5121. entry.value=lpwID;
  5122. entry.value_size=dwCharCount;
  5123. if(b2Strings)
  5124. {
  5125. memcpy(&dwCharCount, lpData, 4);
  5126. lpData+=4;
  5127. CHAR* lpwID2=new(CHAR[dwCharCount+1]);
  5128. int e;
  5129. for(e=0;e<dwCharCount;e++)
  5130. {
  5131. WCHAR w;
  5132. memcpy(&w, lpData, 1);
  5133. lpData+=1;
  5134. lpwID2[e]=w;
  5135. }
  5136. lpwID2[dwCharCount]=0;
  5137. entry.value_asc=lpwID2;
  5138. entry.value_asc_size=dwCharCount;
  5139. }
  5140. /*BYTE* bByte=new(BYTE[entry.value_size+1]);
  5141. wcstombs((LPSTR)bByte, entry.value, entry.value_size+1);
  5142. bByte[entry.value_size]=0;*/
  5143. strings[entry.id].SetString(entry.value, entry.value_size);
  5144. AllStrings[entry.id].SetString(entry.value, entry.value_size);
  5145. //delete[] bByte;
  5146. }
  5147. for(i=0;i<rules.sections.size();i++)
  5148. {
  5149. if(rules.GetSection(i)->FindName("UIName")>=0)
  5150. {
  5151. int e;
  5152. if(strings.find(rules.GetSection(i)->values["UIName"])!=strings.end())
  5153. {
  5154. //MessageBox(strings[rules.GetSection(i)->values["UIName"]].cString);
  5155. if(!strings[rules.GetSection(i)->values["UIName"]].bUsedDefault)
  5156. {
  5157. //CCStrings[*rules.GetSectionName(i)].cString=strings[rules.GetSection(i)->values["UIName"]].cString; //.SetString(strings[rules.GetSection(i)->values["UIName"]].wString, strings[rules.GetSection(i)->values["UIName"]].len);
  5158. CCStrings[*rules.GetSectionName(i)].SetString(strings[rules.GetSection(i)->values["UIName"]].wString, strings[rules.GetSection(i)->values["UIName"]].len);
  5159. }
  5160. else
  5161. {
  5162. CCStrings[*rules.GetSectionName(i)].SetString(strings[rules.GetSection(i)->values["UIName"]].wString, strings[rules.GetSection(i)->values["UIName"]].len);
  5163. CCStrings[*rules.GetSectionName(i)].cString=rules.GetSection(i)->GetValueByName("Name");
  5164. }
  5165. }
  5166. else
  5167. {
  5168. //MessageBox((LPSTR)(LPCSTR)rules.GetSection(i)->values["Name"], *rules.GetSectionName(i));
  5169. CCStrings[*rules.GetSectionName(i)].SetString((LPSTR)(LPCSTR)rules.GetSection(i)->GetValueByName("Name"));
  5170. }
  5171. }
  5172. else CCStrings[*rules.GetSectionName(i)].SetString((LPSTR)(LPCSTR)rules.GetSection(i)->GetValueByName("Name"));
  5173. }
  5174. #else
  5175. int i;
  5176. for(i=0;i<rules.sections.size();i++)
  5177. {
  5178. if(rules.GetSection(i)->FindName("Name")>=0)
  5179. {
  5180. //CCStrings[*rules.GetSectionName(i)].cString=rules.GetSection(i)->values["Name"];
  5181. //CCStrings[*rules.GetSectionName(i)].SetString=rul
  5182. CCStrings[*rules.GetSectionName(i)].SetString((LPSTR)(LPCSTR)rules.GetSection(i)->values["Name"]);
  5183. }
  5184. }
  5185. #endif
  5186. }
  5187. void CLoading::HackRules()
  5188. {
  5189. if(editor_mode==ra2_mode)
  5190. {
  5191. int i;
  5192. int max_c=0;
  5193. for(i=0;i<rules.sections["BuildingTypes"].values.size();i++)
  5194. {
  5195. int p=atoi(*rules.sections["BuildingTypes"].GetValueName(i));
  5196. if(p>max_c) max_c=p;
  5197. }
  5198. char c[50];
  5199. itoa(max_c+1,c,10);
  5200. rules.sections["BuildingTypes"].values[c]=rules.sections["General"].values["GDIGateOne"];
  5201. #ifdef RA2_MODE
  5202. // RULES(MD).INI has the incorrect colors set for the following houses, let's remap them to the expected values.
  5203. // Fixup YuriCountry colour
  5204. if (rules.sections["YuriCountry"].GetValueByName("Color") == "DarkRed") {
  5205. rules.sections["YuriCountry"].values["Color"] = "Purple";
  5206. }
  5207. // Fixup Allied colors
  5208. std::list<CString> allied_houses;
  5209. allied_houses.push_back("British");
  5210. allied_houses.push_back("French");
  5211. allied_houses.push_back("Germans");
  5212. allied_houses.push_back("Americans");
  5213. allied_houses.push_back("Alliance");
  5214. for (std::list<CString>::iterator it = allied_houses.begin(); it != allied_houses.end(); ++it) {
  5215. if (rules.sections[*it].GetValueByName("Color") == "Gold") {
  5216. rules.sections[*it].values["Color"] = "DarkBlue";
  5217. }
  5218. }
  5219. // Fixup Nod color
  5220. if (rules.sections["Nod"].GetValueByName("Color") == "Gold") {
  5221. rules.sections["Nod"].values["Color"] = "DarkRed";
  5222. }
  5223. #endif
  5224. }
  5225. }
  5226. void CLoading::PrepareBuildingTheaters()
  5227. {
  5228. // stub
  5229. }
  5230. /*
  5231. This actually just checks what palette the unit (only buildings make sense)
  5232. uses. Used for the ObjectBrowser (so it only shows those buildings that really exist
  5233. in the specific terrain)
  5234. Added: MW March 20th 2001
  5235. */
  5236. void CLoading::PrepareUnitGraphic(LPCSTR lpUnittype)
  5237. {
  5238. CString _rules_image; // the image used
  5239. CString filename; // filename of the image
  5240. char theat=cur_theat; // standard theater char is t (Temperat). a is snow.
  5241. BOOL bAlwaysSetChar; // second char is always theater, even if NewTheater not specified!
  5242. WORD wStep=1; // step is 1 for infantry, buildings, etc, and for shp vehicles it specifies the step rate between every direction
  5243. WORD wStartWalkFrame=0; // for examply cyborg reaper has another walk starting frame
  5244. int iTurretOffset=0; // used for centering y pos of turret (if existing)
  5245. BOOL bStructure=rules.sections["BuildingTypes"].FindValue(lpUnittype)>=0; // is this a structure?
  5246. if(!bStructure) return; // make sure we only use it for buildings now
  5247. BOOL bPowerUp=rules.sections[lpUnittype].values["PowersUpBuilding"]!="";
  5248. HTSPALETTE hPalette;
  5249. if(theat=='T') hPalette=m_hPalIsoTemp;
  5250. if(theat=='A') hPalette=m_hPalIsoSnow;
  5251. if(theat=='U') hPalette=m_hPalIsoUrb;
  5252. if(theat=='L') hPalette=m_hPalIsoLun;
  5253. if(theat=='D') hPalette=m_hPalIsoDes;
  5254. if(theat=='N') hPalette=m_hPalIsoUbn;
  5255. CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview;
  5256. _rules_image=lpUnittype;
  5257. if(rules.sections[lpUnittype].values.find("Image")!=rules.sections[lpUnittype].values.end())
  5258. _rules_image=rules.sections[lpUnittype].values["Image"];
  5259. CString _art_image = _rules_image;
  5260. if(art.sections[_rules_image].values.find("Image")!=art.sections[_rules_image].values.end())
  5261. {
  5262. if(!isTrue(g_data.sections["IgnoreArtImage"].values[_rules_image]))
  5263. _art_image=art.sections[_rules_image].values["Image"];
  5264. }
  5265. const CString& image = _art_image;
  5266. const auto& rulesSection = rules.sections[lpUnittype];
  5267. const auto& artSection = art.sections[image];
  5268. if(!isTrue(art.sections[image].values["Voxel"])) // is it a shp graphic?
  5269. {
  5270. try
  5271. {
  5272. /*filename = image + ".shp";
  5273. BYTE bTerrain=0;
  5274. BOOL isNewTerrain=FALSE;
  5275. if(isTrue(artSection.GetValueByName("NewTheater")))//&& isTrue(artSection.GetValueByName("TerrainPalette")))//(filename.GetAt(0)=='G' || filename.GetAt(0)=='N' || filename.GetAt(0)=='C') && filename.GetAt(1)=='A')
  5276. {
  5277. hPalette=m_hPalUnitTemp;
  5278. if(theat=='A') hPalette=m_hPalUnitSnow;
  5279. if(theat=='U') hPalette=m_hPalUnitUrb;
  5280. if(theat=='L') hPalette=m_hPalUnitLun;
  5281. if(theat=='D') hPalette=m_hPalUnitDes;
  5282. if(theat=='N') hPalette=m_hPalUnitUbn;
  5283. filename.SetAt(1, theat);
  5284. isNewTerrain=TRUE;
  5285. }
  5286. HMIXFILE hShpMix=FindFileInMix(filename, &bTerrain);
  5287. BYTE bIgnoreTerrain=TRUE;
  5288. if(hShpMix==NULL && isNewTerrain)
  5289. {
  5290. filename.SetAt(1, 'G');
  5291. hShpMix=FindFileInMix(filename, &bTerrain);
  5292. if(hShpMix) theat='G';
  5293. }
  5294. if(hShpMix==NULL && isNewTerrain)
  5295. {
  5296. filename.SetAt(1, 'N');
  5297. hShpMix=FindFileInMix(filename, &bTerrain);
  5298. if(hShpMix) theat='N';
  5299. }
  5300. if(hShpMix==NULL && isNewTerrain)
  5301. {
  5302. filename.SetAt(1, 'D');
  5303. hShpMix=FindFileInMix(filename, &bTerrain);
  5304. if(hShpMix) theat='D';
  5305. }
  5306. if(hShpMix==NULL && isNewTerrain)
  5307. {
  5308. filename.SetAt(1, 'L');
  5309. hShpMix=FindFileInMix(filename, &bTerrain);
  5310. if(hShpMix) theat='L';
  5311. }
  5312. if(hShpMix==NULL && isNewTerrain)
  5313. {
  5314. filename.SetAt(1, 'A');
  5315. hShpMix=FindFileInMix(filename, &bTerrain);
  5316. if(hShpMix) theat='A';
  5317. }
  5318. if(hShpMix==NULL && isNewTerrain)
  5319. {
  5320. filename.SetAt(1, 'T');
  5321. hShpMix=FindFileInMix(filename, &bTerrain);
  5322. if(hShpMix){
  5323. theat='T';
  5324. hPalette=m_hIsoTemp;
  5325. }
  5326. }
  5327. if(isTrue(artSection.GetValueByName("TerrainPalette")))
  5328. {
  5329. bIgnoreTerrain=FALSE;
  5330. if(cur_theat=='T')
  5331. hPalette=m_hPalIsoTemp;
  5332. else if(cur_theat=='A')
  5333. hPalette=m_hPalIsoSnow;
  5334. else if (cur_theat=='U')
  5335. hPalette=m_hPalIsoUrb;
  5336. else if(cur_theat=='L')
  5337. hPalette=m_hPalIsoLun;
  5338. else if(cur_theat=='D')
  5339. hPalette=m_hPalIsoDes;
  5340. else if(cur_theat=='N')
  5341. hPalette=m_hPalIsoUbn;
  5342. }
  5343. if(hShpMix==0)
  5344. {
  5345. filename=image;
  5346. filename+=".shp";
  5347. hShpMix=FindFileInMix(filename, &bTerrain);
  5348. if(hShpMix==NULL)
  5349. {
  5350. filename=image;
  5351. if(theat=='T') filename+=".tem";
  5352. if(theat=='A') filename+=".sno";
  5353. if(theat=='U') filename+=".urb";
  5354. if(theat=='L') filename+=".lun";
  5355. if(theat=='D') filename+=".des";
  5356. if(theat=='N') filename+=".ubn";
  5357. filename.MakeLower();
  5358. hShpMix=FindFileInMix(filename, &bTerrain);
  5359. if(hShpMix==NULL)
  5360. {
  5361. filename=image;
  5362. filename+=".tem";
  5363. hShpMix=FindFileInMix(filename, &bTerrain);
  5364. if(hShpMix)
  5365. {
  5366. hPalette=m_hPalIsoTemp;
  5367. }
  5368. }
  5369. if(hShpMix!=NULL)
  5370. {
  5371. }
  5372. else
  5373. {
  5374. filename=image+".shp";
  5375. filename.SetAt(1, 'A');
  5376. hShpMix=FindFileInMix(filename);
  5377. if(hShpMix!=NULL)
  5378. {
  5379. bAlwaysSetChar=TRUE;
  5380. }
  5381. else
  5382. {
  5383. filename.SetAt(1, 'A');
  5384. hShpMix=FindFileInMix(filename);
  5385. if(hShpMix!=NULL)
  5386. {
  5387. theat='A';
  5388. bAlwaysSetChar=TRUE;
  5389. }
  5390. else
  5391. {
  5392. filename.SetAt(1, 'U');
  5393. hShpMix=FindFileInMix(filename);
  5394. if(hShpMix) theat='U';
  5395. else
  5396. {
  5397. filename.SetAt(1, 'L');
  5398. hShpMix=FindFileInMix(filename);
  5399. if(hShpMix) theat='L';
  5400. else
  5401. {
  5402. filename.SetAt(1, 'D');
  5403. hShpMix=FindFileInMix(filename);
  5404. if(hShpMix) theat='D';
  5405. else
  5406. {
  5407. filename.SetAt(1, 'N');
  5408. hShpMix=FindFileInMix(filename);
  5409. if(hShpMix) theat='N';
  5410. else
  5411. {
  5412. filename.SetAt(1, 'T');
  5413. hShpMix=FindFileInMix(filename);
  5414. if(hShpMix) theat='T';
  5415. }
  5416. }
  5417. }
  5418. }
  5419. }
  5420. }
  5421. }
  5422. }
  5423. else
  5424. {
  5425. theat='T';
  5426. }
  5427. }
  5428. else
  5429. {
  5430. // now we need to find out the palette
  5431. if(isTrue(artSection.GetValueByName("TerrainPalette"))) // it´s a file in isotemp.mix/isosno.mix
  5432. {
  5433. }
  5434. else // it´s a file in temperat.mix/snow.mix
  5435. {
  5436. if(cur_theat=='T') hPalette=m_hPalUnitTemp;
  5437. if(cur_theat=='A') hPalette=m_hPalUnitSnow;
  5438. if(cur_theat=='U') hPalette=m_hPalUnitUrb;
  5439. if(cur_theat=='L') hPalette=m_hPalUnitLun;
  5440. if(cur_theat=='D') hPalette=m_hPalUnitDes;
  5441. if(cur_theat=='N') hPalette=m_hPalUnitUbn;
  5442. }
  5443. }*/
  5444. auto shp = FindUnitShp(image, cur_theat, artSection);
  5445. if (!shp)
  5446. return;
  5447. filename = shp->filename;
  5448. hPalette = shp->palette;
  5449. auto limited_to_theater = isTrue(artSection.GetValueByName("TerrainPalette")) ? shp->mixfile_theater : TheaterChar::None;
  5450. if(filename=="tibtre01.tem" || filename=="tibtre02.tem" || filename=="tibtre03.tem" || filename=="veinhole.tem")
  5451. {
  5452. hPalette=m_hPalUnitTemp;
  5453. }
  5454. if(shp->mixfile>0)
  5455. {
  5456. BOOL bSuccess=FSunPackLib::SetCurrentSHP(filename, shp->mixfile);
  5457. if(
  5458. !bSuccess
  5459. )
  5460. {
  5461. filename=image+".sno";
  5462. if(cur_theat=='T' || cur_theat=='U') hPalette=m_hPalIsoTemp;
  5463. HMIXFILE hShpMix=FindFileInMix(filename);
  5464. bSuccess=FSunPackLib::SetCurrentSHP(filename, hShpMix);
  5465. if(!bSuccess)
  5466. {
  5467. return;
  5468. }
  5469. }
  5470. if(bSuccess)
  5471. {
  5472. char ic[50];
  5473. int i=0;
  5474. itoa(i, ic, 10);
  5475. // just fill in a stub entry - Final* will automatically retry loading once the graphic really must be loaded
  5476. PICDATA p;
  5477. p.pic=NULL;
  5478. p.x=0;
  5479. p.y=0;
  5480. p.wHeight=0;
  5481. p.wWidth=0;
  5482. p.wMaxWidth=0;
  5483. p.wMaxHeight=0;
  5484. p.bType=PICDATA_TYPE_SHP;
  5485. p.bTerrain=limited_to_theater;
  5486. pics[image+ic]=p;
  5487. }
  5488. }
  5489. }
  5490. catch(...)
  5491. {
  5492. errstream << " exception " << endl;
  5493. errstream.flush();
  5494. }
  5495. }
  5496. }
  5497. /*
  5498. Helper function that fetches the palette data from FsunPackLib
  5499. FSunPackLib doesn´t provide any special function to retrieve a color table entry,
  5500. so we have to build it ourself
  5501. Also builds color_conv
  5502. */
  5503. void CLoading::FetchPalettes()
  5504. {
  5505. // SetTSPaletteEntry(HTSPALETTE hPalette, BYTE bIndex, RGBTRIPLE* rgb, RGBTRIPLE* orig);
  5506. // SetTSPaletteEntry can retrieve the current color table entry without modifying it!
  5507. // iso palette
  5508. HTSPALETTE hCur=0;
  5509. if(Map->GetTheater()==THEATER0) hCur=m_hPalIsoTemp;
  5510. if(Map->GetTheater()==THEATER1) hCur=m_hPalIsoSnow;
  5511. if(Map->GetTheater()==THEATER2) hCur=m_hPalIsoUrb;
  5512. if(Map->GetTheater()==THEATER3) hCur=m_hPalIsoUbn;
  5513. if(Map->GetTheater()==THEATER4) hCur=m_hPalIsoLun;
  5514. if(Map->GetTheater()==THEATER5) hCur=m_hPalIsoDes;
  5515. int i;
  5516. for(i=0;i<256;i++)
  5517. {
  5518. FSunPackLib::SetTSPaletteEntry(hCur, i, NULL /* don´t modify it!*/, &palIso[i] /*but retrieve it!*/);
  5519. }
  5520. // unit palette
  5521. if(Map->GetTheater()==THEATER0) hCur=m_hPalUnitTemp;
  5522. if(Map->GetTheater()==THEATER1) hCur=m_hPalUnitSnow;
  5523. if(Map->GetTheater()==THEATER2) hCur=m_hPalUnitUrb;
  5524. if(Map->GetTheater()==THEATER3) hCur=m_hPalUnitUbn;
  5525. if(Map->GetTheater()==THEATER4) hCur=m_hPalUnitLun;
  5526. if(Map->GetTheater()==THEATER5) hCur=m_hPalUnitDes;
  5527. for(i=0;i<256;i++)
  5528. {
  5529. FSunPackLib::SetTSPaletteEntry(hCur, i, NULL /* don´t modify it!*/, &palUnit[i] /*but retrieve it!*/);
  5530. }
  5531. // theater palette
  5532. if(Map->GetTheater()==THEATER0) hCur=m_hPalTemp;
  5533. if(Map->GetTheater()==THEATER1) hCur=m_hPalSnow;
  5534. if(Map->GetTheater()==THEATER2) hCur=m_hPalUrb;
  5535. if(Map->GetTheater()==THEATER3) hCur=m_hPalUbn;
  5536. if(Map->GetTheater()==THEATER4) hCur=m_hPalLun;
  5537. if(Map->GetTheater()==THEATER5) hCur=m_hPalDes;
  5538. for(i=0;i<256;i++)
  5539. {
  5540. FSunPackLib::SetTSPaletteEntry(hCur, i, NULL /* don´t modify it!*/, &palTheater[i] /*but retrieve it!*/);
  5541. }
  5542. // lib palette
  5543. hCur=m_hPalLib;
  5544. for(i=0;i<256;i++)
  5545. {
  5546. FSunPackLib::SetTSPaletteEntry(hCur, i, NULL /* don´t modify it!*/, &palLib[i] /*but retrieve it!*/);
  5547. }
  5548. CreateConvTable(palIso, iPalIso);
  5549. CreateConvTable(palLib, iPalLib);
  5550. CreateConvTable(palUnit, iPalUnit);
  5551. CreateConvTable(palTheater, iPalTheater);
  5552. CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview;
  5553. DDPIXELFORMAT pf;
  5554. memset(&pf, 0, sizeof(DDPIXELFORMAT));
  5555. pf.dwSize=sizeof(DDPIXELFORMAT);
  5556. v.lpds->GetPixelFormat(&pf);
  5557. v.pf = pf;
  5558. v.m_color_converter.reset(new FSunPackLib::ColorConverter(v.pf));
  5559. FSunPackLib::ColorConverter conf(pf);
  5560. const auto& rulesColors = rules.sections["Colors"];
  5561. for(i=0;i< rulesColors.values.size();i++)
  5562. {
  5563. CString col=*rulesColors.GetValueName(i);
  5564. COLORREF cref=v.GetColor("", col);
  5565. color_conv[col]=conf.GetColor(GetRValue(cref), GetGValue(cref), GetBValue(cref));
  5566. colorref_conv[cref]=color_conv[col];
  5567. }
  5568. }
  5569. void CLoading::CreateConvTable(RGBTRIPLE *pal, int *iPal)
  5570. {
  5571. CIsoView& v=*((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview;
  5572. DDPIXELFORMAT pf;
  5573. memset(&pf, 0, sizeof(DDPIXELFORMAT));
  5574. pf.dwSize=sizeof(DDPIXELFORMAT);
  5575. v.lpds->GetPixelFormat(&pf);
  5576. FSunPackLib::ColorConverter conf(pf);
  5577. int i;
  5578. for(i=0;i<256;i++)
  5579. {
  5580. iPal[i]=conf.GetColor(pal[i].rgbtRed, pal[i].rgbtGreen, pal[i].rgbtBlue);
  5581. }
  5582. }