IsoView.cpp 166 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824
  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. /*
  17. ISOVIEW.CPP
  18. Implementation of the isometric view.
  19. */
  20. #include "stdafx.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /* Includes */
  27. #include "FinalSun.h"
  28. #include "IsoView.h"
  29. #include "DynamicGraphDlg.h"
  30. #include "infantry.h"
  31. #include "building.h"
  32. #include "unit.h"
  33. #include "aircraft.h"
  34. #include "waypointid.h"
  35. #include "celltag.h"
  36. #include "MyViewframe.h"
  37. #include "inlines.h"
  38. #include "macros.h"
  39. #include "FinalSunDlg.h"
  40. #include "loading.h"
  41. #include "Structs.h"
  42. #include "frontcliffmodifier.h"
  43. #include "backcliffmodifier.h"
  44. #include "LineDrawer.h"
  45. #include "MapTool.h"
  46. #include <format>
  47. #include <chrono>
  48. #include <algorithm>
  49. #include "TextDrawer.h"
  50. /* -------- */
  51. /* Externals */
  52. extern ACTIONDATA AD;
  53. void GetNodeName(CString& name, int n);
  54. /* --------- */
  55. /* Overlay picture table (maximum overlay count=0xFF) */
  56. PICDATA* ovrlpics[0xFF][max_ovrl_img];
  57. // cancel draw flag
  58. BOOL bCancelDraw = FALSE;
  59. BOOL bNoDraw = FALSE;
  60. // this variable will be set to TRUE when the window has lost focus
  61. // once the mouse is moved in the isoview again WITHOUT pressed button, it is set to FALSE again
  62. BOOL bDoNotAllowScroll = FALSE;
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CIsoView
  65. IMPLEMENT_DYNCREATE(CIsoView, CScrollView)
  66. BOOL bNoThreadDraw = FALSE;
  67. BOOL bDrawStats = TRUE;
  68. /*UINT PaintThreadProc( LPVOID pParam )
  69. {
  70. while(!bNoThreadDraw)
  71. {
  72. if(((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview!=NULL) ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->UpdateWindow();
  73. }
  74. return 0; // Thread erfolgreich ausgeführt
  75. }
  76. */
  77. class SurfaceLocker
  78. {
  79. public:
  80. SurfaceLocker(IDirectDrawSurface4* pDDS, LPRECT rect = nullptr) :
  81. SurfaceLocker()
  82. {
  83. m_hasRect = rect != nullptr;
  84. if (rect)
  85. m_rect = *rect;
  86. m_pDDS = pDDS;
  87. m_ddsd.dwSize = sizeof(DDSURFACEDESC2);
  88. m_ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  89. }
  90. DDSURFACEDESC2* ensure_locked()
  91. {
  92. if (m_locked)
  93. return &m_ddsd;
  94. if (m_pDDS->GetSurfaceDesc(&m_ddsd) != DD_OK)
  95. return nullptr;
  96. if (m_pDDS->Lock(m_hasRect ? &m_rect : nullptr, &m_ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL) != DD_OK)
  97. return nullptr;
  98. m_locked = true;
  99. if (!m_ddsd.lpSurface)
  100. return nullptr; // probably does not happen in reality
  101. return &m_ddsd;
  102. }
  103. void ensure_unlocked()
  104. {
  105. if (m_locked)
  106. {
  107. m_pDDS->Unlock(m_hasRect ? &m_rect : nullptr);
  108. }
  109. m_locked = false;
  110. }
  111. ~SurfaceLocker()
  112. {
  113. ensure_unlocked();
  114. }
  115. SurfaceLocker(const SurfaceLocker& other) = delete;
  116. SurfaceLocker& operator=(const SurfaceLocker& other) = delete;
  117. private:
  118. SurfaceLocker() = default;
  119. private:
  120. IDirectDrawSurface4* m_pDDS = nullptr;
  121. DDSURFACEDESC2 m_ddsd = { 0 };
  122. RECT m_rect = { 0 };
  123. bool m_hasRect = false;
  124. bool m_locked = false;
  125. };
  126. CIsoView::CIsoView()
  127. {
  128. srand(GetTickCount());
  129. m_bAltCliff = FALSE;
  130. m_NoMove = FALSE;
  131. b_IsLoading = FALSE;
  132. m_viewOffset = ProjectedVec(0, 0);
  133. dd = NULL;
  134. dd_1 = NULL;
  135. lpds = NULL;
  136. lpdsBack = NULL;
  137. lpdsBackHighRes = nullptr;
  138. lpdsTemp = NULL;
  139. pf = DDPIXELFORMAT{ 0 };
  140. line.left = 0;
  141. line.top = 0;
  142. line.right = 0;
  143. line.bottom = 0;
  144. m_menu.LoadMenu(IDR_MAPVIEW);
  145. m_drag = FALSE;
  146. // _map=NULL;
  147. AD.reset();
  148. m_BrushSize_x = 1;
  149. m_BrushSize_y = 1;
  150. rscroll = FALSE;
  151. m_zooming = false;
  152. bThreadPainting = TRUE;
  153. m_viewScale = Vec2<CSProjected, float>(1.0f, 1.0f);
  154. m_viewScaleControl = 1.0f;
  155. updateFontScaled();
  156. //m_paintthread=new(CIsoPaintThread);
  157. //m_paintthread->CreateThread();
  158. }
  159. CIsoView::~CIsoView()
  160. {
  161. // if(_map!=NULL) delete[] _map;
  162. // _map=NULL;
  163. //delete m_paintthread;
  164. bNoThreadDraw = TRUE;
  165. }
  166. BEGIN_MESSAGE_MAP(CIsoView, CView)
  167. //{{AFX_MSG_MAP(CIsoView)
  168. ON_WM_SYSCOMMAND()
  169. ON_WM_VSCROLL()
  170. ON_WM_HSCROLL()
  171. ON_WM_MOUSEMOVE()
  172. ON_WM_RBUTTONUP()
  173. ON_WM_LBUTTONDBLCLK()
  174. ON_WM_LBUTTONDOWN()
  175. ON_WM_LBUTTONUP()
  176. ON_WM_MOVE()
  177. ON_WM_SIZE()
  178. ON_WM_CHAR()
  179. ON_WM_DEADCHAR()
  180. ON_WM_KEYDOWN()
  181. ON_WM_KEYUP()
  182. ON_WM_TIMER()
  183. ON_WM_RBUTTONDOWN()
  184. ON_WM_KILLFOCUS()
  185. ON_WM_MOUSEWHEEL()
  186. //}}AFX_MSG_MAP
  187. ON_WM_MBUTTONDOWN()
  188. ON_WM_MBUTTONUP()
  189. END_MESSAGE_MAP()
  190. /////////////////////////////////////////////////////////////////////////////
  191. // Zeichnung CIsoView
  192. void CIsoView::OnInitialUpdate()
  193. {
  194. CView::OnInitialUpdate();
  195. }
  196. struct CHANGEHEIGHTDATA
  197. {
  198. int pos;
  199. BOOL bNonMorpheable;
  200. DWORD toHeight;
  201. };
  202. DWORD WINAPI ChangeHeightThread(
  203. LPVOID lpParameter // thread data
  204. )
  205. {
  206. CHANGEHEIGHTDATA* p = (CHANGEHEIGHTDATA*)lpParameter;
  207. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->ChangeTileHeight(p->pos, p->toHeight, p->bNonMorpheable);
  208. return 0;
  209. }
  210. /*
  211. dst must be surface data, src must be a 8 bit palette image
  212. */
  213. #ifdef NOSURFACES
  214. struct BlitRect
  215. {
  216. short left;
  217. short top;
  218. short right;
  219. short bottom;
  220. };
  221. __forceinline void BlitTerrain(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, const SUBTILE& st)//BYTE* src, int swidth, int sheight)
  222. {
  223. BYTE* src = st.pic;
  224. const unsigned short swidth = st.wWidth;
  225. const unsigned short sheight = st.wHeight;
  226. if (src == NULL || dst == NULL) return;
  227. //x += 1;
  228. //y += 1;
  229. //y -= f_y;
  230. if (x + swidth < dleft || y + sheight < dtop) return;
  231. if (x >= dright || y >= dbottom) return;
  232. BlitRect blrect;
  233. BlitRect srcRect;
  234. srcRect.left = 0;
  235. srcRect.top = 0;
  236. srcRect.right = swidth;
  237. srcRect.bottom = sheight;
  238. blrect.left = x;
  239. if (blrect.left < 0)
  240. {
  241. srcRect.left = 1 - blrect.left;
  242. blrect.left = 1;
  243. }
  244. blrect.top = y;
  245. if (blrect.top < 0)
  246. {
  247. srcRect.top = 1 - blrect.top;
  248. blrect.top = 1;
  249. }
  250. blrect.right = (x + swidth);
  251. if (x + swidth > dright)
  252. {
  253. srcRect.right = dright - x;//swidth-((x+swidth)-dright);
  254. blrect.right = dright;
  255. }
  256. blrect.bottom = (y + sheight);
  257. if (y + sheight > dbottom)
  258. {
  259. srcRect.bottom = dbottom - y;//sheight-((y+sheight)-dbottom);
  260. blrect.bottom = dbottom;
  261. }
  262. short i, e;
  263. #ifdef NOSURFACES_EXTRACT
  264. int pos = 0;
  265. if (!st.bNotExtracted)
  266. {
  267. for (e = srcRect.top;e < srcRect.bottom;e++)
  268. {
  269. short left = st.vborder[e].left;
  270. short right = st.vborder[e].right;
  271. short realright = right;
  272. //short realleft=left;
  273. //short addx_s=0;
  274. if (right >= srcRect.right) right = srcRect.right - 1;
  275. if (srcRect.left > 0)
  276. {
  277. pos += (realright - left + 1) * bpp;
  278. continue; // just cancel. this area is used by object browser. saves some performance
  279. //addx_s=srcRect.left;
  280. //left=max(left, srcRect.left);
  281. //left=//addx=left-srcRect.left;
  282. }
  283. if (realright >= left)
  284. {
  285. if (/*left<srcRect.left ||*/ left >= srcRect.right)
  286. {
  287. pos += (realright - left + 1) * bpp;
  288. continue;
  289. }
  290. void* dest = ((BYTE*)dst + (blrect.left + left) * bpp + (blrect.top + e) * dpitch);
  291. memcpy(dest, &st.pic[pos], bpp * (right - left + 1));
  292. pos += (realright - left + 1) * bpp;
  293. }
  294. }
  295. }
  296. else
  297. #endif
  298. for (e = srcRect.top;e < srcRect.bottom;e++)
  299. {
  300. short& left = st.vborder[e].left;
  301. short& right = st.vborder[e].right;
  302. auto l = max(left, srcRect.left);
  303. auto r = min(right, static_cast<short>(srcRect.right - 1));
  304. for (i = l;i <= r;i++)
  305. {
  306. //if (i < srcRect.left || i >= srcRect.right)
  307. {
  308. //dest+=bpp;
  309. }
  310. //else
  311. {
  312. BYTE& val = src[i + e * swidth];
  313. if (val)
  314. {
  315. void* dest = ((BYTE*)dst + (blrect.left + i) * bpp + (blrect.top + e) * dpitch);
  316. memcpy(dest, &iPalIso[val], bpp);
  317. }
  318. }
  319. }
  320. }
  321. }
  322. __forceinline void BlitTerrainHalfTransp(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, const SUBTILE& st)//BYTE* src, int swidth, int sheight)
  323. {
  324. BYTE* src = st.pic;
  325. const unsigned short swidth = st.wWidth;
  326. const unsigned short sheight = st.wHeight;
  327. if (src == NULL || dst == NULL) return;
  328. //x += 1;
  329. //y += 1;
  330. //y -= f_y;
  331. if (x + swidth < dleft || y + sheight < dtop) return;
  332. if (x >= dright || y >= dbottom) return;
  333. BlitRect blrect;
  334. BlitRect srcRect;
  335. srcRect.left = 0;
  336. srcRect.top = 0;
  337. srcRect.right = swidth;
  338. srcRect.bottom = sheight;
  339. blrect.left = x;
  340. if (blrect.left < 0)
  341. {
  342. srcRect.left = 1 - blrect.left;
  343. blrect.left = 1;
  344. }
  345. blrect.top = y;
  346. if (blrect.top < 0)
  347. {
  348. srcRect.top = 1 - blrect.top;
  349. blrect.top = 1;
  350. }
  351. blrect.right = (x + swidth);
  352. if (x + swidth > dright)
  353. {
  354. srcRect.right = dright - x;//swidth-((x+swidth)-dright);
  355. blrect.right = dright;
  356. }
  357. blrect.bottom = (y + sheight);
  358. if (y + sheight > dbottom)
  359. {
  360. srcRect.bottom = dbottom - y;//sheight-((y+sheight)-dbottom);
  361. blrect.bottom = dbottom;
  362. }
  363. short i, e;
  364. #ifdef NOSURFACES_EXTRACT
  365. int pos = 0;
  366. if (!st.bNotExtracted)
  367. {
  368. int a = 0;
  369. for (e = srcRect.top;e < srcRect.bottom;e += 1)
  370. {
  371. short left = st.vborder[e].left;
  372. short right = st.vborder[e].right;
  373. short realright = right;
  374. if (right >= srcRect.right) right = srcRect.right - 1;
  375. if (srcRect.left > 0)
  376. {
  377. pos += (realright - left + 1) * bpp;
  378. continue; // just cancel. this area is used by object browser. saves some performance
  379. }
  380. a++;
  381. if (realright >= left)
  382. {
  383. if (/*left<srcRect.left ||*/ left >= srcRect.right)
  384. {
  385. pos += (realright - left + 1) * bpp;
  386. continue;
  387. }
  388. void* dest = ((BYTE*)dst + (blrect.left + left) * bpp + (blrect.top + e) * dpitch);
  389. //memcpy(dest, &st.pic[pos], bpp*(right-left+1));
  390. //pos+=(right-left+1)*bpp;
  391. for (i = left + a % 2;i <= right;i += 2)
  392. {
  393. if (i < srcRect.left || i >= srcRect.right)
  394. {
  395. //dest+=bpp;
  396. }
  397. else
  398. {
  399. //BYTE& val=st.pic[pos+i*bpp];
  400. //if(val)
  401. {
  402. void* dest2 = (BYTE*)dest + (i - left) * bpp; //((BYTE*)dst+(blrect.left+i)*bpp+(blrect.top+e)*dpitch);
  403. memcpy(dest2, &st.pic[pos + (i - left) * bpp], bpp);
  404. }
  405. }
  406. }
  407. pos += (realright - left + 1) * bpp;
  408. }
  409. }
  410. }
  411. else
  412. #endif
  413. {
  414. int a = 0;
  415. for (e = srcRect.top;e < srcRect.bottom;e++)
  416. {
  417. short& left = st.vborder[e].left;
  418. short& right = st.vborder[e].right;
  419. a++;
  420. for (i = left + a % 2;i <= right;i += 2)
  421. {
  422. if (i < srcRect.left || i >= srcRect.right)
  423. {
  424. //dest+=bpp;
  425. }
  426. else
  427. {
  428. BYTE& val = src[i + e * swidth];
  429. if (val)
  430. {
  431. void* dest = ((BYTE*)dst + (blrect.left + i) * bpp + (blrect.top + e) * dpitch);
  432. memcpy(dest, &iPalIso[val], bpp);
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. const int houseColorMin = 0x10;
  440. const int houseColorMax = 0x1f;
  441. const int houseColorRelMax = houseColorMax - houseColorMin;
  442. inline void CalculateHouseColorPalette(int house_pal[houseColorRelMax + 1], const int* default_pal, const int* color = NULL)
  443. {
  444. if (color)
  445. {
  446. if (bpp == 4)
  447. {
  448. for (int n = 0; n <= houseColorRelMax; ++n)
  449. {
  450. const int v = (houseColorRelMax - n);
  451. auto src = reinterpret_cast<const BYTE*>(color);
  452. auto bdest = reinterpret_cast<BYTE*>(&house_pal[n]);
  453. bdest[0] = src[0] * v / houseColorRelMax;
  454. bdest[1] = src[1] * v / houseColorRelMax;
  455. bdest[2] = src[2] * v / houseColorRelMax;
  456. bdest[3] = src[3];
  457. }
  458. }
  459. else
  460. {
  461. // nowadays only 32 bit rendering should be used, so we take a shortcut here
  462. for (int n = 0; n <= houseColorRelMax; ++n)
  463. {
  464. house_pal[n] = *color;
  465. }
  466. }
  467. }
  468. else
  469. {
  470. for (int n = 0; n <= houseColorRelMax; ++n)
  471. {
  472. house_pal[n] = default_pal[n + houseColorMin];
  473. }
  474. }
  475. }
  476. /*
  477. There is no need for newpal
  478. */
  479. __forceinline void BlitPic(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, PICDATA& pd, int* color = NULL, int* newPal = NULL)//BYTE* src, int swidth, int sheight)
  480. {
  481. ASSERT(pd.bType != PICDATA_TYPE_BMP);
  482. if (newPal == NULL) newPal = pd.pal;
  483. BYTE* src = (BYTE*)pd.pic;
  484. int swidth = pd.wMaxWidth;
  485. int sheight = pd.wMaxHeight;
  486. if (src == NULL || dst == NULL) return;
  487. //x += 1;
  488. //y += 1;
  489. //y -= f_y;
  490. if (x + swidth < dleft || y + sheight < dtop) return;
  491. if (x >= dright || y >= dbottom) return;
  492. RECT blrect;
  493. RECT srcRect;
  494. srcRect.left = 0;
  495. srcRect.top = 0;
  496. srcRect.right = swidth;
  497. srcRect.bottom = sheight;
  498. blrect.left = x;
  499. if (blrect.left < 0)
  500. {
  501. srcRect.left = 1 - blrect.left;
  502. //blrect.left=1;
  503. }
  504. blrect.top = y;
  505. if (blrect.top < 0)
  506. {
  507. srcRect.top = 1 - blrect.top;
  508. //blrect.top=1;
  509. }
  510. blrect.right = (x + swidth);
  511. if (x + swidth > dright)
  512. {
  513. srcRect.right = swidth - ((x + swidth) - dright);
  514. blrect.right = dright;
  515. }
  516. blrect.bottom = (y + sheight);
  517. if (y + sheight > dbottom)
  518. {
  519. srcRect.bottom = sheight - ((y + sheight) - dbottom);
  520. blrect.bottom = dbottom;
  521. }
  522. int i, e;
  523. // calculate a palette for given color for values 0x10 to 0x1f - we might move this outside
  524. const int houseColorMin = 0x10;
  525. const int houseColorMax = 0x1f;
  526. const int houseColorRelMax = houseColorMax - houseColorMin;
  527. int houseColors[houseColorRelMax + 1] = { 0 };
  528. CalculateHouseColorPalette(houseColors, newPal, color);
  529. const BYTE* const pLighting = (bpp == 4 && pd.lighting && !pd.lighting->empty()) ? pd.lighting->data() : nullptr;
  530. for (e = srcRect.top;e < srcRect.bottom;e++)
  531. {
  532. int left = pd.vborder[e].left;
  533. int right = pd.vborder[e].right;
  534. if (left < srcRect.left)
  535. left = srcRect.left;
  536. if (right >= srcRect.right)
  537. right = srcRect.right - 1;
  538. for (i = left;i <= right;i++)
  539. {
  540. if (blrect.left + i < 0)
  541. continue;
  542. const int spos = i + e * swidth;
  543. BYTE val = src[spos];
  544. if (val)
  545. {
  546. void* dest = ((BYTE*)dst + (blrect.left + i) * bpp + (blrect.top + e) * dpitch);
  547. if (dest >= dst)
  548. {
  549. int c;
  550. if (!color || newPal != iPalUnit || val < houseColorMin || val > houseColorMax)
  551. {
  552. c = newPal[val];
  553. }
  554. else
  555. {
  556. // Replace the original palette color with the house color
  557. ASSERT(val >= houseColorMin && val <= houseColorMax);
  558. const int v = (val - houseColorMin);
  559. c = houseColors[v];
  560. }
  561. if (pLighting)
  562. {
  563. // bpp == 4
  564. ASSERT(bpp == 4);
  565. int l = pLighting[spos];
  566. BYTE* bc = reinterpret_cast<BYTE*>(&c);
  567. for (int i = 0; i < 4; ++i)
  568. bc[i] = min(255, bc[i] * (200 + l * 300 / 255) / 255); // game seems to overbrighten and have a lot of ambient - if you change this, also change Loading.cpp shp lighting value so that shp light stays at 1.0
  569. //bc[i] = min(255, bc[i] * (0 + l * (255 - 0) / 255) / 255);
  570. }
  571. memcpy(dest, &c, bpp);
  572. }
  573. }
  574. }
  575. }
  576. }
  577. __forceinline void BlitPicHalfTransp(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, PICDATA& pd, int* color = NULL, int* newPal = NULL)//BYTE* src, int swidth, int sheight)
  578. {
  579. ASSERT(pd.bType != PICDATA_TYPE_BMP);
  580. if (newPal == NULL) newPal = pd.pal;
  581. BYTE* src = (BYTE*)pd.pic;
  582. int swidth = pd.wMaxWidth;
  583. int sheight = pd.wMaxHeight;
  584. if (src == NULL || dst == NULL) return;
  585. //x += 1;
  586. //y += 1;
  587. //y -= f_y;
  588. if (x + swidth < dleft || y + sheight < dtop) return;
  589. if (x >= dright || y >= dbottom) return;
  590. RECT blrect;
  591. RECT srcRect;
  592. srcRect.left = 0;
  593. srcRect.top = 0;
  594. srcRect.right = swidth;
  595. srcRect.bottom = sheight;
  596. blrect.left = x;
  597. if (blrect.left < 0)
  598. {
  599. srcRect.left = 1 - blrect.left;
  600. //blrect.left=1;
  601. }
  602. blrect.top = y;
  603. if (blrect.top < 0)
  604. {
  605. srcRect.top = 1 - blrect.top;
  606. //blrect.top=1;
  607. }
  608. blrect.right = (x + swidth);
  609. if (x + swidth > dright)
  610. {
  611. srcRect.right = swidth - ((x + swidth) - dright);
  612. blrect.right = dright;
  613. }
  614. blrect.bottom = (y + sheight);
  615. if (y + sheight > dbottom)
  616. {
  617. srcRect.bottom = sheight - ((y + sheight) - dbottom);
  618. blrect.bottom = dbottom;
  619. }
  620. int i, e;
  621. for (e = srcRect.top;e < srcRect.bottom;e++)
  622. {
  623. int left = pd.vborder[e].left;
  624. int right = pd.vborder[e].right;
  625. if (left < srcRect.left) left = srcRect.left;
  626. if (right >= srcRect.right) right = srcRect.right - 1;
  627. int a = e % 2 + left % 2;
  628. for (i = left + a;i <= right;i += 2)
  629. {
  630. //a++;
  631. if (blrect.left + i < 0) continue;
  632. //if(a%2) continue;
  633. BYTE& val = src[i + e * swidth];
  634. //0x10-0x1f,
  635. if (val)
  636. {
  637. void* dest = ((BYTE*)dst + (blrect.left + i) * bpp + (blrect.top + e) * dpitch);
  638. //*dest=newPal[val];
  639. if (dest >= dst)
  640. {
  641. if (!color || newPal != iPalUnit || val < 0x10 || val>0x1f)
  642. {
  643. memcpy(dest, &newPal[val], bpp);
  644. }
  645. else
  646. {
  647. //int col=0;
  648. memcpy(dest, color, bpp);
  649. }
  650. }
  651. }
  652. }
  653. }
  654. }
  655. #endif
  656. /////////////////////////////////////////////////////////////////////////////
  657. // Diagnose CIsoView
  658. #ifdef _DEBUG
  659. void CIsoView::AssertValid() const
  660. {
  661. CView::AssertValid();
  662. }
  663. void CIsoView::Dump(CDumpContext& dc) const
  664. {
  665. CView::Dump(dc);
  666. }
  667. #endif //_DEBUG
  668. /////////////updateFontScaled////////////////////////////////////////////////////////////////
  669. // Behandlungsroutinen für Nachrichten CIsoView
  670. void CIsoView::updateFontScaled()
  671. {
  672. auto dc = CDC::FromHandle(::GetDC(NULL));
  673. m_fontDefaultHeight = -MulDiv(12, dc->GetDeviceCaps(LOGPIXELSY), 72);
  674. m_Font9Height = -MulDiv(9, dc->GetDeviceCaps(LOGPIXELSY), 72);
  675. if (dd)
  676. {
  677. m_textDefault.reset(new TextDrawer(dd, m_fontDefaultHeight, RGB(0,0,0), RGB(255, 255, 255)));
  678. m_text9.reset(new TextDrawer(dd, m_Font9Height, RGB(0, 0, 0), RGB(255, 255, 255)));
  679. m_textScaled.reset(new TextDrawer(dd, m_fontDefaultHeight / m_viewScale.y, RGB(0, 0, 0), RGB(255, 255, 255)));
  680. m_text9Scaled.reset(new TextDrawer(dd, m_Font9Height / m_viewScale.y, RGB(0, 0, 0), RGB(255, 255, 255)));
  681. m_textBlue.reset(new TextDrawer(dd, m_fontDefaultHeight, RGB(0, 0, 255), RGB(255, 255, 255)));
  682. m_textBlueScaled.reset(new TextDrawer(dd, m_fontDefaultHeight / m_viewScale.y, RGB(0, 0, 255), RGB(255, 255, 255)));
  683. m_textBlue9.reset(new TextDrawer(dd, m_Font9Height, RGB(0, 0, 255), RGB(255, 255, 255)));
  684. m_textBlue9Scaled.reset(new TextDrawer(dd, m_Font9Height / m_viewScale.y, RGB(0, 0, 255), RGB(255, 255, 255)));
  685. }
  686. }
  687. BOOL CIsoView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  688. {
  689. BOOL r = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  690. this->SetScrollRange(SB_HORZ, 0, 1, TRUE);
  691. this->SetScrollRange(SB_VERT, 0, 1, TRUE);
  692. // AfxBeginThread(PaintThreadProc, 0, 0, 0xFFFF);
  693. return r;
  694. }
  695. void CIsoView::OnSysCommand(UINT nID, LPARAM lParam)
  696. {
  697. // TODO: Code für die Behandlungsroutine für Nachrichten hier einfügen und/oder Standard aufrufen
  698. if (nID == SC_CLOSE)
  699. {
  700. // ok now just hide the window
  701. ShowWindow(SW_HIDE);
  702. return;
  703. }
  704. CView::OnSysCommand(nID, lParam);
  705. }
  706. inline int GetScrPos(CWnd* pOwner, UINT nSB, UINT nSBCode, UINT& nPos)
  707. {
  708. SCROLLINFO scr;
  709. scr.cbSize = sizeof(SCROLLINFO);
  710. scr.fMask = SIF_ALL;
  711. pOwner->GetScrollInfo(nSB, &scr);
  712. switch (nSBCode)
  713. {
  714. case SB_LEFT:
  715. {
  716. nPos = scr.nMin;
  717. break;
  718. }
  719. case SB_RIGHT:
  720. {
  721. nPos = scr.nMax;
  722. break;
  723. }
  724. case SB_THUMBTRACK:
  725. case SB_THUMBPOSITION:
  726. {
  727. break;
  728. }
  729. case SB_LINELEFT:
  730. {
  731. nPos = scr.nPos - 1;
  732. break;
  733. }
  734. case SB_LINERIGHT:
  735. {
  736. nPos = scr.nPos + 1;
  737. break;
  738. }
  739. case SB_PAGELEFT:
  740. {
  741. nPos = scr.nPos - 5;
  742. break;
  743. }
  744. case SB_PAGERIGHT:
  745. {
  746. nPos = scr.nPos + 5;
  747. break;
  748. }
  749. }
  750. return nPos;
  751. }
  752. void CIsoView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  753. {
  754. if (nSBCode == SB_ENDSCROLL || nSBCode == SB_THUMBTRACK) return;
  755. nPos = GetScrPos(this, SB_VERT, nSBCode, nPos);
  756. this->SetScrollPos(SB_VERT, nPos, TRUE);
  757. m_viewOffset.y = (nPos + Map->GetWidth() / 2 - 4) * f_y;
  758. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  759. CMyViewFrame& dlg = *(CMyViewFrame*)owner;
  760. dlg.m_minimap.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  761. }
  762. void CIsoView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  763. {
  764. if (nSBCode == SB_ENDSCROLL || nSBCode == SB_THUMBTRACK) return;
  765. nPos = GetScrPos(this, SB_HORZ, nSBCode, nPos);
  766. RECT r;
  767. GetWindowRect(&r);
  768. m_viewOffset.x = (nPos + Map->GetHeight() / 2 - 1) * f_x;
  769. this->SetScrollPos(SB_HORZ, nPos, TRUE);
  770. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  771. CMyViewFrame& dlg = *(CMyViewFrame*)owner;
  772. dlg.m_minimap.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  773. }
  774. /*
  775. This function is called when any data has been changed in another dialog.
  776. It is used to initialize and update the dialog.
  777. */
  778. void CIsoView::UpdateDialog(BOOL bRepos)
  779. {
  780. OutputDebugString("Isoview updated\n");
  781. UpdateOverlayPictures();
  782. if (bRepos && Map->GetIsoSize() != 0)
  783. {
  784. m_viewScale = Vec2<CSProjected, float>(1.0f, 1.0f);
  785. m_viewScaleControl = 1.0f;
  786. auto r = GetScaledDisplayRect();
  787. UpdateScrollRanges();
  788. SetScroll((Map->GetIsoSize() / 2 - r.right / f_x / 2) * f_x, (Map->GetIsoSize() / 2 - r.bottom / f_y / 2) * f_y);
  789. }
  790. RedrawWindow(NULL, NULL, RDW_INVALIDATE);
  791. }
  792. void CIsoView::UpdateScrollRanges()
  793. {
  794. auto r = GetScaledDisplayRect();
  795. SetScrollRange(SB_HORZ, 0, Map->GetWidth() - r.right / f_x + 4, TRUE);
  796. SetScrollRange(SB_VERT, 0, Map->GetHeight() - r.bottom / f_y + 6, TRUE);
  797. }
  798. BOOL CIsoView::PreCreateWindow(CREATESTRUCT& cs)
  799. {
  800. // we overwrite that, because in debug version its necessary that a view is a child window!
  801. // save the old style and let CView::PreCreateWindow() think we are using a child window, then restore old style.
  802. int ostyle = cs.style;
  803. cs.style |= WS_CHILD | WS_VSCROLL | WS_HSCROLL;
  804. BOOL bres = CView::PreCreateWindow(cs);
  805. cs.style = ostyle;
  806. return bres;
  807. }
  808. void CIsoView::OnMouseMove(UINT nFlags, CPoint point)
  809. {
  810. if (b_IsLoading) return;
  811. static BOOL isMoving = FALSE;
  812. CIniFile& ini = Map->GetIniFile();
  813. cur_x_mouse = point.x;
  814. cur_y_mouse = point.y;
  815. if (!(nFlags & MK_RBUTTON)) bDoNotAllowScroll = FALSE;
  816. if (rscroll)
  817. {
  818. if (!(nFlags & MK_RBUTTON))
  819. {
  820. ReleaseCapture();
  821. KillTimer(11);
  822. rscroll = FALSE;
  823. ShowCursor(TRUE);
  824. CMyViewFrame& dlg = *(CMyViewFrame*)owner;
  825. dlg.m_minimap.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  826. }
  827. else
  828. {
  829. isMoving = FALSE;
  830. return;
  831. }
  832. }
  833. if (!bDoNotAllowScroll && (nFlags & MK_RBUTTON) && !rscroll) // check if scroll should start
  834. {
  835. if (abs(point.x - rclick_x) > 2 || abs(point.y - rclick_y) > 2)
  836. {
  837. // yes, begin scrolling!
  838. rscroll = TRUE;
  839. SetTimer(11, 25, NULL);
  840. SetCapture();
  841. //while(ShowCursor(FALSE)>0);
  842. isMoving = FALSE;
  843. return;
  844. }
  845. }
  846. if ((nFlags & MK_MBUTTON) == 0)
  847. m_zooming = false;
  848. if (!bDoNotAllowScroll && m_zooming)
  849. {
  850. if ((nFlags & MK_MBUTTON) == MK_MBUTTON)
  851. {
  852. auto diff = point - m_MButtonMoveZooming;
  853. m_MButtonMoveZooming = point;
  854. Zoom(m_MButtonDown, -diff.cy / 1000.0f);
  855. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  856. return;
  857. }
  858. }
  859. m_moved = TRUE;
  860. if (b_IsLoading == TRUE) return;
  861. if (Map->GetIsoSize() == 0 || isMoving == TRUE || m_zooming) return;
  862. isMoving = TRUE;
  863. // SetError(TranslateStringACP("Ready"));
  864. RECT r;
  865. //GetClientRect(&r);
  866. //ClientToScreen(&r);
  867. GetWindowRect(&r);
  868. const auto viewOffsetWR = m_viewOffset + ProjectedVec(r.left, r.top);
  869. const auto projCoords = GetProjectedCoordinatesFromClientCoordinates(point);
  870. const MapCoords mapCoords = GetMapCoordinatesFromClientCoordinates(point, (nFlags & MK_CONTROL) == MK_CONTROL);
  871. m_cellCursor = MapCoords(-1, -1);
  872. const int x = mapCoords.x; // compat
  873. const int y = mapCoords.y;
  874. int mapwidth = Map->GetWidth();
  875. int mapheight = Map->GetHeight();
  876. BOOL bOutside = FALSE;
  877. if (AD.mode != ACTIONMODE_COPY && AD.mode != ACTIONMODE_PASTE)
  878. {
  879. if (x < 1 || y < 1 || x + y<mapwidth + 1 || x + y>mapwidth + mapheight * 2 || (y + 1 > mapwidth && x - 1 < y - mapwidth) || (x + 1 > mapwidth && y + mapwidth - 1 < x))
  880. {
  881. isMoving = FALSE;
  882. return;
  883. }
  884. }
  885. else
  886. {
  887. if (x < 1 || y < 1 || x >= mapwidth + mapheight - 1 || y >= mapwidth + mapheight - 1)
  888. {
  889. bOutside = TRUE;
  890. if (AD.mode == ACTIONMODE_COPY || AD.mode == ACTIONMODE_PASTE)
  891. {
  892. isMoving = FALSE;
  893. return;
  894. }
  895. }
  896. }
  897. if (lpdsBack)
  898. // reset back buffer to last DrawMap()
  899. lpdsBack->BltFast(0, 0, lpdsTemp, NULL, DDBLTFAST_WAIT);
  900. //lpdsBack->Blt(NULL, lpdsTemp, NULL, 0, 0);
  901. //int cell_x = x;
  902. //int cell_y = y;
  903. {
  904. // Preview rendering
  905. if (AD.mode == ACTIONMODE_SETTILE && !((nFlags & MK_LBUTTON) && !(nFlags & MK_CONTROL) && (nFlags & MK_SHIFT)))
  906. {
  907. // No placement, just preview
  908. bCancelDraw = TRUE;
  909. int i, e, f, n;
  910. int p = 0;
  911. //FIELDDATA oldData[36][36][10][10];
  912. int width = (*tiledata)[AD.type].cx;
  913. int height = (*tiledata)[AD.type].cy;
  914. int pos = x - width + 1 + (y - height + 1) * Map->GetIsoSize();
  915. int startheight = Map->GetHeightAt(x + y * Map->GetIsoSize()) + AD.z_data;
  916. int ground = (Map->GetFielddataAt(x + y * Map->GetIsoSize()))->wGround;
  917. if (ground == 0xFFFF) ground = 0;
  918. startheight -= (*tiledata)[ground].tiles[Map->GetFielddataAt(x + y * Map->GetIsoSize())->bSubTile].bZHeight;
  919. TILEDATA td = (*tiledata)[AD.type];
  920. Map->TakeSnapshot(TRUE, x - width - 4, y - height - 4, x - width + m_BrushSize_x * width + 7, y - height + m_BrushSize_y * height + 7);
  921. int cur_pos = pos;
  922. int isosize = Map->GetIsoSize();
  923. int height_add = height * isosize;
  924. char c[50];
  925. itoa(AD.data, c, 10);
  926. for (f = 0;f < m_BrushSize_x;f++)
  927. {
  928. for (n = 0;n < m_BrushSize_y;n++)
  929. {
  930. int tile = AD.type;
  931. if (AD.data == 1)
  932. {
  933. int n = rand() * 5 / RAND_MAX;
  934. tile += n;
  935. }
  936. cur_pos = pos + f * width + n * height_add;
  937. p = 0;
  938. for (i = 0;i < td.cx;i++)
  939. {
  940. for (e = 0;e < td.cy;e++)
  941. {
  942. if (x - width + 1 + f * width + i >= Map->GetIsoSize() ||
  943. y - height + 1 + n * height + e >= Map->GetIsoSize())
  944. {
  945. }
  946. else
  947. if (td.tiles[p].pic != NULL)
  948. {
  949. int mypos = cur_pos + i + e * isosize;
  950. Map->SetHeightAt(mypos, startheight + td.tiles[p].bZHeight);
  951. Map->SetTileAt(mypos, tile, p);
  952. }
  953. p++;
  954. }
  955. }
  956. }
  957. }
  958. if (!((nFlags & MK_CONTROL) && (nFlags & MK_SHIFT)))
  959. {
  960. if (!theApp.m_Options.bDisableAutoShore) Map->CreateShore(x - width - 2, y - height - 2, x - width + td.cx * m_BrushSize_x + 5, y - height + td.cy * m_BrushSize_y + 5, FALSE);
  961. for (f = 0;f < m_BrushSize_x;f++)
  962. {
  963. for (n = 0;n < m_BrushSize_y;n++)
  964. {
  965. cur_pos = pos + f * width + n * height_add;
  966. p = 0;
  967. for (i = -1;i < td.cx + 1;i++)
  968. {
  969. for (e = -1;e < td.cy + 1;e++)
  970. {
  971. Map->SmoothAllAt(cur_pos + i + (e)*isosize);
  972. }
  973. }
  974. }
  975. }
  976. }
  977. bCancelDraw = FALSE;
  978. DrawMap();
  979. Map->Undo();
  980. m_drag = FALSE;
  981. }
  982. else if (m_drag && AD.mode == ACTIONMODE_CLIFFFRONT)
  983. {
  984. RECT affect;
  985. if (m_mapx < x) affect.left = m_mapx - 2; else affect.left = x - 2;
  986. if (m_mapx < x) affect.right = x + 2; else affect.right = m_mapx + 2;
  987. if (m_mapy < y) affect.top = m_mapy - 2; else affect.top = y - 2;
  988. if (m_mapy < y) affect.bottom = y + 2; else affect.bottom = m_mapy + 2;
  989. //Map->TakeSnapshot();
  990. Map->TakeSnapshot(TRUE, affect.left, affect.top, affect.right, affect.bottom);
  991. CFrontCliffModifier f;
  992. BOOL bAlt = FALSE;
  993. if (Map->GetTheater() == THEATER3 && m_bAltCliff)
  994. bAlt = TRUE;
  995. f.PlaceCliff(m_mapx, m_mapy, x, y, bAlt);
  996. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  997. //Map->TakeSnapshot();
  998. Map->TakeSnapshot(TRUE, affect.left, affect.top, affect.right, affect.bottom);
  999. Map->Undo();
  1000. Map->Undo();
  1001. }
  1002. else if (m_drag && AD.mode == ACTIONMODE_CLIFFBACK)
  1003. {
  1004. RECT affect;
  1005. if (m_mapx < x) affect.left = m_mapx - 2; else affect.left = x - 2;
  1006. if (m_mapx < x) affect.right = x + 2; else affect.right = m_mapx + 2;
  1007. if (m_mapy < y) affect.top = m_mapy - 2; else affect.top = y - 2;
  1008. if (m_mapy < y) affect.bottom = y + 2; else affect.bottom = m_mapy + 2;
  1009. //Map->TakeSnapshot();
  1010. Map->TakeSnapshot(TRUE, affect.left, affect.top, affect.right, affect.bottom);
  1011. CBackCliffModifier f;
  1012. BOOL bAlt = FALSE;
  1013. if (Map->GetTheater() == THEATER3 && m_bAltCliff)
  1014. bAlt = TRUE;
  1015. f.PlaceCliff(m_mapx, m_mapy, x, y);
  1016. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1017. //Map->TakeSnapshot();
  1018. Map->TakeSnapshot(TRUE, affect.left, affect.top, affect.right, affect.bottom);
  1019. Map->Undo();
  1020. Map->Undo();
  1021. }
  1022. else if (AD.mode == ACTIONMODE_COPY && m_drag)
  1023. {
  1024. last_succeeded_operation = 80301; //bugtracing once more
  1025. int x1, x2, y1, y2;
  1026. if (m_mapx < x)
  1027. {
  1028. x1 = m_mapx;
  1029. x2 = x;
  1030. }
  1031. else
  1032. {
  1033. x1 = x;
  1034. x2 = m_mapx;
  1035. }
  1036. if (m_mapy < y)
  1037. {
  1038. y1 = m_mapy;
  1039. y2 = y;
  1040. }
  1041. else
  1042. {
  1043. y1 = y;
  1044. y2 = m_mapy;
  1045. }
  1046. DDSURFACEDESC2 ddsd;
  1047. ZeroMemory(&ddsd, sizeof(ddsd));
  1048. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  1049. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  1050. lpdsBack->GetSurfaceDesc(&ddsd);
  1051. lpdsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
  1052. int i, e;
  1053. int isosize = Map->GetIsoSize();
  1054. for (i = 0;i < x2 - x1 + 1;i++)
  1055. {
  1056. for (e = 0;e < y2 - y1 + 1;e++)
  1057. {
  1058. last_succeeded_operation = 80302;
  1059. int x_s = x1 + i;
  1060. int y_s = y1 + e;
  1061. if (x_s < 0 || y_s < 0 || x_s >= isosize || y_s >= isosize) continue;
  1062. if (theApp.m_Options.bFlat) ToPhys(&x_s, &y_s); else ToPhys3d(&x_s, &y_s);
  1063. x_s -= m_viewOffset.x;
  1064. y_s -= m_viewOffset.y;
  1065. last_succeeded_operation = 80305;
  1066. DrawCell(ddsd.lpSurface, ddsd.dwWidth, ddsd.dwHeight, ddsd.lPitch, x_s, y_s, 1, 1, m_color_converter->GetColor(255, 0, 0));
  1067. last_succeeded_operation = 80303;
  1068. }
  1069. }
  1070. lpdsBack->Unlock(NULL);
  1071. BlitBackbufferToHighRes();
  1072. RenderUIOverlay();
  1073. FlipHighResBuffer();
  1074. last_succeeded_operation = 80304;
  1075. }
  1076. else if (AD.mode == ACTIONMODE_PASTE)
  1077. {
  1078. Map->TakeSnapshot();
  1079. Map->Paste(x, y, AD.z_data);
  1080. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1081. Map->Undo();
  1082. }
  1083. else if ((AD.mode == ACTIONMODE_PLACE || AD.mode == ACTIONMODE_RANDOMTERRAIN) && (nFlags & ~MK_CONTROL) == 0 && AD.type != 7 && (AD.type != 6 || (AD.type == 6 && ((AD.data >= 30 && AD.data <= 33) || AD.data == 2 || AD.data == 3)))) // everything placing but not overlay!
  1084. {
  1085. FIELDDATA oldData[32][32];
  1086. INFANTRY infData[SUBPOS_COUNT][32][32];
  1087. int i, e;
  1088. //if(AD.type!=1 || Map->GetInfantryCountAt(x+y*Map->GetIsoSize())==0)
  1089. {
  1090. for (i = 0;i < 32;i++)
  1091. {
  1092. for (e = 0;e < 32;e++)
  1093. {
  1094. oldData[i][e] = *Map->GetFielddataAt(i + x + (e + y) * Map->GetIsoSize());
  1095. int z;
  1096. for (z = 0;z < SUBPOS_COUNT;z++)
  1097. if (oldData[i][e].infantry[z] > -1)
  1098. Map->GetInfantryData(oldData[i][e].infantry[z], &infData[z][i][e]);
  1099. }
  1100. }
  1101. PlaceCurrentObjectAt(x, y);
  1102. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1103. for (i = 0;i < 32;i++)
  1104. {
  1105. for (e = 0;e < 32;e++)
  1106. {
  1107. DWORD dwPos = i + x + (e + y) * Map->GetIsoSize();
  1108. FIELDDATA cur_field;
  1109. cur_field = *Map->GetFielddataAt(dwPos);
  1110. if (cur_field.aircraft != oldData[i][e].aircraft)
  1111. Map->DeleteAircraft(cur_field.aircraft);
  1112. int z;
  1113. for (z = 0;z < SUBPOS_COUNT;z++)
  1114. if (cur_field.infantry[z] != oldData[i][e].infantry[z])
  1115. {
  1116. Map->DeleteInfantry(cur_field.infantry[z]);
  1117. }
  1118. if (cur_field.node.index != oldData[i][e].node.index)
  1119. {
  1120. CString house;
  1121. int id = Map->GetNodeAt(dwPos, house);
  1122. Map->DeleteNode(house, id);
  1123. }
  1124. if (cur_field.structure != oldData[i][e].structure)
  1125. Map->DeleteStructure(cur_field.structure);
  1126. if (cur_field.terrain != oldData[i][e].terrain)
  1127. Map->DeleteTerrain(cur_field.terrain);
  1128. #ifdef SMUDGE_SUPP
  1129. if (cur_field.smudge != oldData[i][e].smudge)
  1130. Map->DeleteSmudge(cur_field.smudge);
  1131. #endif
  1132. if (cur_field.unit != oldData[i][e].unit)
  1133. Map->DeleteUnit(cur_field.unit);
  1134. if (cur_field.overlay != oldData[i][e].overlay)
  1135. Map->SetOverlayAt(dwPos, oldData[i][e].overlay);
  1136. if (cur_field.overlaydata != oldData[i][e].overlaydata)
  1137. Map->SetOverlayDataAt(dwPos, oldData[i][e].overlaydata);
  1138. Map->SetFielddataAt(dwPos, &oldData[i][e]);
  1139. }
  1140. }
  1141. }
  1142. //else
  1143. // RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1144. }
  1145. else
  1146. {
  1147. SurfaceLocker locker(lpdsBack);
  1148. auto desc = locker.ensure_locked();
  1149. if (desc)
  1150. DrawCellCursor(mapCoords, *desc);
  1151. m_cellCursor = mapCoords;
  1152. //RedrawWindow(NULL, NULL, RDW_INVALIDATE);
  1153. locker.ensure_unlocked();
  1154. BlitBackbufferToHighRes();
  1155. RenderUIOverlay();
  1156. FlipHighResBuffer();
  1157. }
  1158. }
  1159. // display the coordinates
  1160. char c[50];
  1161. CString cap;
  1162. itoa(x, c, 10);
  1163. cap += c;
  1164. cap += " / ";
  1165. itoa(y, c, 10);
  1166. cap += c;
  1167. cap += " - ";
  1168. itoa(Map->GetHeightAt(x + y * Map->GetIsoSize()), c, 10);
  1169. cap += c;
  1170. CStatusBarCtrl& stat = ((CMyViewFrame*)owner)->m_statbar.GetStatusBarCtrl();
  1171. stat.SetText(cap, 1, 0);
  1172. // drag
  1173. if (m_drag && AD.mode == 0)
  1174. {
  1175. RedrawWindow(NULL, NULL, RDW_INVALIDATE);
  1176. CPaintDC dc(this);
  1177. dc.SetROP2(R2_NOT);
  1178. const auto renderOffset = CPoint(f_x / 2 / m_viewScale.x, f_y / 2 / m_viewScale.y);
  1179. const auto from = GetClientCoordinates(MapCoords(m_mapx, m_mapy)) + renderOffset;
  1180. const auto to = GetClientCoordinates(mapCoords) + renderOffset;
  1181. dc.MoveTo(from.x, from.y);
  1182. dc.LineTo(to.x, to.y);
  1183. }
  1184. else if (AD.mode == ACTIONMODE_SETTILE && (nFlags & MK_LBUTTON) && ((nFlags & MK_SHIFT) || Map->hasLat(AD.type)) && !(nFlags & MK_CONTROL))
  1185. {
  1186. // Sound(SOUND_LAYDOWNTILE); // too many sounds
  1187. PlaceTile(x, y, nFlags);
  1188. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1189. isMoving = FALSE;
  1190. return;
  1191. }
  1192. else if ((nFlags & MK_LBUTTON) && (nFlags & MK_SHIFT) && AD.mode == ACTIONMODE_HEIGHTEN)
  1193. {
  1194. OnLButtonDown(nFlags, point);
  1195. isMoving = FALSE;
  1196. return;
  1197. }
  1198. else if ((nFlags & MK_LBUTTON) && (nFlags & MK_SHIFT) && AD.mode == ACTIONMODE_LOWER)
  1199. {
  1200. OnLButtonDown(nFlags, point);
  1201. isMoving = FALSE;
  1202. return;
  1203. }
  1204. else if ((nFlags == MK_LBUTTON) && AD.mode == ACTIONMODE_FLATTENGROUND)
  1205. {
  1206. m_TileChangeCount = 0;
  1207. // if(abs(m_FlattenLastX-x)<2 && abs(m_FlattenLastY-y)<2) //ReachableFrom(x+y*Map->GetIsoSize(), m_mapx+m_mapy*Map->GetIsoSize()))
  1208. int ground = Map->GetFielddataAt(x + (y)*Map->GetIsoSize())->wGround;
  1209. if (ground == 0xFFFF) ground = 0;
  1210. //if((*tiledata)[ground].bMorphable)
  1211. {
  1212. int left = -m_BrushSize_x / 2;
  1213. int right = m_BrushSize_x / 2 + 1;
  1214. int top = -m_BrushSize_y / 2;
  1215. int bottom = m_BrushSize_y / 2 + 1;
  1216. BOOL doNotSave = FALSE;
  1217. int n, m;
  1218. int isosize = Map->GetIsoSize();
  1219. for (m = left;m < right;m++)
  1220. {
  1221. for (n = top;n < bottom;n++)
  1222. {
  1223. int pos = x + m + (y + n) * isosize;
  1224. int ground = Map->GetFielddataAt(pos)->wGround;
  1225. if (ground == 0xFFFF) ground = 0;
  1226. /*int ground1=Map->GetFielddataAt(pos-m)->wGround;
  1227. if(ground1==0xFFFF) ground=0;
  1228. int ground2=Map->GetFielddataAt(pos-n*isosize)->wGround;
  1229. if(ground2==0xFFFF) ground=0;*/
  1230. if (!(*tiledata)[ground].bMorphable)
  1231. {
  1232. {
  1233. if (n <= 0 /*&& !(*tiledata)[ground1].bMorphable*/) top = n + 1;
  1234. if (m <= 0 /*&& !(*tiledata)[ground2].bMorphable*/) left = m + 1;
  1235. if (n > 0 /*&& !(*tiledata)[ground1].bMorphable*/) bottom = n;
  1236. if (m > 0 /*&& !(*tiledata)[ground2].bMorphable*/) right = m;
  1237. }
  1238. }
  1239. if (n < top)
  1240. {
  1241. m = left;
  1242. n = top;
  1243. }
  1244. if (m < left)
  1245. {
  1246. n = top;
  1247. m = left;
  1248. }
  1249. }
  1250. }
  1251. m_funcRect.left = x;
  1252. m_funcRect.top = y;
  1253. m_funcRect.bottom = y;
  1254. m_funcRect.right = x;
  1255. for (m = left;m < right;m++)
  1256. {
  1257. for (n = top;n < bottom;n++)
  1258. {
  1259. int ground = Map->GetFielddataAt(x + m + (y + n) * Map->GetIsoSize())->wGround;
  1260. if (ground == 0xFFFF) ground = 0;
  1261. if ((*tiledata)[ground].bMorphable)
  1262. {
  1263. int i;
  1264. int max = isosize * isosize;
  1265. for (i = 0;i < max;i++)
  1266. Map->SetReserved(i, 0);
  1267. // do not make any slopes yet, we do this once we´re finished with the whole area!
  1268. // helps to speed up performance!
  1269. ChangeTileHeight(x + m + (y + n) * isosize, m_FlattenHeight, FALSE, FALSE, TRUE);
  1270. }
  1271. else
  1272. {
  1273. if (n == 0 && m == 0)
  1274. doNotSave = TRUE;
  1275. }
  1276. }
  1277. }
  1278. /*
  1279. Some trick for improving performance is using the m_funcRect parameter to get
  1280. the area that any ChangeTileHeight() calls affected.
  1281. */
  1282. ASSERT(m_funcRect.left <= m_funcRect.right);
  1283. ASSERT(m_funcRect.top <= m_funcRect.bottom);
  1284. for (m = m_funcRect.left - 1;m <= m_funcRect.right + 1;m++)
  1285. for (n = m_funcRect.top - 1;n <= m_funcRect.bottom + 1;n++)
  1286. Map->CreateSlopesAt(m + n * isosize);
  1287. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1288. if (!doNotSave)
  1289. {
  1290. m_FlattenLastX = x;
  1291. m_FlattenLastY = y;
  1292. }
  1293. }
  1294. }
  1295. else if ((nFlags & MK_LBUTTON) && (nFlags & MK_SHIFT) && AD.mode == ACTIONMODE_HEIGHTENTILE)
  1296. {
  1297. OnLButtonDown(nFlags, point);
  1298. }
  1299. else if ((nFlags & MK_LBUTTON) && (nFlags & MK_SHIFT) && AD.mode == ACTIONMODE_LOWERTILE)
  1300. {
  1301. OnLButtonDown(nFlags, point);
  1302. }
  1303. else if ((nFlags == MK_LBUTTON) && AD.mode == ACTIONMODE_WAYPOINT) // waypoints
  1304. {
  1305. if (AD.type == 1)
  1306. {
  1307. //delete waypoint
  1308. int w = Map->GetWaypointAt(x + y * Map->GetIsoSize());
  1309. if (w < 0)
  1310. {
  1311. isMoving = FALSE;
  1312. return;
  1313. }
  1314. Map->DeleteWaypoint(w);
  1315. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1316. }
  1317. else if (AD.type == 0)
  1318. {
  1319. int n = Map->GetWaypointAt(x + y * Map->GetIsoSize());
  1320. if (n >= 0)
  1321. {
  1322. isMoving = FALSE;
  1323. return;
  1324. }
  1325. Map->AddWaypoint("", x + y * Map->GetIsoSize());
  1326. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1327. }
  1328. else if (AD.type >= 3)
  1329. {
  1330. int n = Map->GetWaypointAt(x + y * Map->GetIsoSize());
  1331. if (n >= 0)
  1332. {
  1333. isMoving = FALSE;
  1334. return;
  1335. }
  1336. char c[50];
  1337. int max = AD.type - 3;
  1338. // MW April 8th: place waypoints before selected one if they are not there!
  1339. // makes the user aware that he is doing something he should not do.
  1340. // he should not skip starting locations
  1341. // this logic is here to make sure there are no random starting points.
  1342. // I do not want to change this when saving the map, as triggers may rely on the
  1343. // actual starting position!
  1344. int i;
  1345. int e;
  1346. int notfound = -1;
  1347. for (e = 0;e < max;e++)
  1348. {
  1349. BOOL bFound = FALSE;
  1350. for (i = 0;i < Map->GetWaypointCount();i++)
  1351. {
  1352. CString id;
  1353. DWORD pos;
  1354. Map->GetWaypointData(i, &id, &pos);
  1355. if (atoi(id) == e) bFound = TRUE;
  1356. if (bFound) break;
  1357. }
  1358. if (!bFound)
  1359. {
  1360. notfound = e;
  1361. break;
  1362. }
  1363. }
  1364. if (notfound >= 0) max = notfound;
  1365. AD.type = 3 + max;
  1366. itoa(max, c, 10);
  1367. if (!Map->IsMultiplayer())
  1368. {
  1369. Map->AddWaypoint("99", x + (y + 1) * Map->GetIsoSize());
  1370. Map->AddWaypoint("98", x + (y)*Map->GetIsoSize());
  1371. }
  1372. else
  1373. {
  1374. Map->AddWaypoint(c, x + y * Map->GetIsoSize());
  1375. }
  1376. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1377. }
  1378. }
  1379. else if ((nFlags == MK_LBUTTON) && AD.mode == ACTIONMODE_CELLTAG) // celltags
  1380. {
  1381. if (AD.type == 1)
  1382. {
  1383. int n = Map->GetCelltagAt(x + y * Map->GetIsoSize());
  1384. if (n < 0)
  1385. {
  1386. isMoving = FALSE;
  1387. return;
  1388. }
  1389. Map->DeleteCelltag(n);
  1390. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1391. }
  1392. else if (AD.type == 4)
  1393. {
  1394. Map->AddCelltag(AD.data_s, x + y * Map->GetIsoSize());
  1395. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1396. }
  1397. }
  1398. else if ((nFlags == MK_LBUTTON) && AD.mode == ACTIONMODE_NODE) // nodes
  1399. {
  1400. if (AD.type == 1) // create node, delete building
  1401. {
  1402. int n = Map->GetStructureAt(x + y * Map->GetIsoSize());
  1403. if (n < 0)
  1404. {
  1405. isMoving = FALSE;
  1406. return;
  1407. }
  1408. STDOBJECTDATA sod;
  1409. Map->GetStdStructureData(n, &sod);
  1410. CString tmp;
  1411. if (Map->GetNodeAt(atoi(sod.x) + atoi(sod.y) * Map->GetIsoSize(), tmp) >= 0)
  1412. {
  1413. SetError("You cannot place a node on another node");
  1414. {
  1415. isMoving = FALSE;
  1416. return;
  1417. };
  1418. }
  1419. Map->DeleteStructure(n);
  1420. NODE node;
  1421. node.x = sod.x;
  1422. node.y = sod.y;
  1423. node.house = sod.house;
  1424. node.type = sod.type;
  1425. Map->AddNode(&node, 0);
  1426. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1427. }
  1428. else if (AD.type == 0) // create node, don´t delete building
  1429. {
  1430. int n = Map->GetStructureAt(x + y * Map->GetIsoSize());
  1431. if (n < 0)
  1432. {
  1433. isMoving = FALSE;
  1434. return;
  1435. }
  1436. STDOBJECTDATA sod;
  1437. Map->GetStdStructureData(n, &sod);
  1438. CString tmp;
  1439. if (Map->GetNodeAt(atoi(sod.x) + atoi(sod.y) * Map->GetIsoSize(), tmp) >= 0)
  1440. {
  1441. SetError("You cannot place a node on another node");
  1442. {
  1443. isMoving = FALSE;
  1444. return;
  1445. };
  1446. }
  1447. NODE node;
  1448. node.x = sod.x;
  1449. node.y = sod.y;
  1450. node.type = sod.type;
  1451. node.house = sod.house;
  1452. Map->AddNode(&node, 0);
  1453. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1454. }
  1455. else if (AD.type == 2) // delete node
  1456. {
  1457. CString owner;
  1458. int n = Map->GetNodeAt(x + y * Map->GetIsoSize(), owner);
  1459. if (n < 0)
  1460. {
  1461. isMoving = FALSE;
  1462. return;
  1463. }
  1464. Map->DeleteNode(owner, n);
  1465. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1466. }
  1467. }
  1468. else if ((nFlags == MK_LBUTTON) && AD.mode == ACTIONMODE_ERASEFIELD)
  1469. {
  1470. int h;
  1471. DWORD dwPos = x + y * Map->GetIsoSize();
  1472. h = Map->GetInfantryAt(dwPos);
  1473. if (h > -1)
  1474. {
  1475. Map->DeleteInfantry(h);
  1476. }
  1477. h = Map->GetUnitAt(dwPos);
  1478. if (h > -1)
  1479. {
  1480. Map->DeleteUnit(h);
  1481. }
  1482. h = Map->GetStructureAt(dwPos);
  1483. if (h > -1)
  1484. {
  1485. Map->DeleteStructure(h);
  1486. }
  1487. h = Map->GetAirAt(dwPos);
  1488. if (h > -1)
  1489. {
  1490. Map->DeleteAircraft(h);
  1491. }
  1492. h = Map->GetTerrainAt(dwPos);
  1493. if (h > -1)
  1494. {
  1495. Map->DeleteTerrain(h);
  1496. }
  1497. #ifdef SMUDGE_SUPP
  1498. const FIELDDATA& fd = *Map->GetFielddataAt(dwPos);
  1499. h = fd.smudge;
  1500. if (h > -1)
  1501. {
  1502. Map->DeleteSmudge(h);
  1503. }
  1504. #endif
  1505. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1506. }
  1507. else if (AD.mode == ACTIONMODE_MAPTOOL)
  1508. {
  1509. if (AD.tool)
  1510. AD.tool->onMouseMove(projCoords, mapCoords, MapToolMouseFlagsFromWin32(nFlags));
  1511. }
  1512. else if ((nFlags & MK_LBUTTON) == MK_LBUTTON && (AD.mode == ACTIONMODE_PLACE || AD.mode == ACTIONMODE_RANDOMTERRAIN))
  1513. {
  1514. // ADD OBJECTS
  1515. if (AD.mode == ACTIONMODE_PLACE && AD.type == 6) Map->TakeSnapshot();
  1516. if (AD.mode == ACTIONMODE_PLACE && AD.type == 6 && AD.data == 5) // bridges
  1517. {
  1518. // calculate the x and y value...
  1519. int x = mapCoords.x;
  1520. int y = mapCoords.y;
  1521. if (abs(x - m_mapx) >= abs(y - m_mapy))
  1522. {
  1523. // it´s from bottom left to top right
  1524. y = m_mapy;
  1525. }
  1526. else
  1527. {
  1528. // from bottom right to top left
  1529. x = m_mapx;
  1530. }
  1531. // draw a line
  1532. int px1, py1, px2, py2;
  1533. px1 = m_mapx;
  1534. py1 = m_mapy;
  1535. px2 = x;
  1536. py2 = y;
  1537. if (theApp.m_Options.bFlat)
  1538. ToPhys(&px1, &py1);
  1539. else
  1540. ToPhys3d(&px1, &py1);
  1541. if (theApp.m_Options.bFlat)
  1542. ToPhys(&px2, &py2);
  1543. else
  1544. ToPhys3d(&px2, &py2);
  1545. px1 += f_x / 2 - m_viewOffset.x - r.left;
  1546. py1 += f_y / 2 - m_viewOffset.y - r.top;
  1547. px2 += f_x / 2 - m_viewOffset.x - r.left;
  1548. py2 += f_y / 2 - m_viewOffset.y - r.top;
  1549. CRect r;
  1550. GetWindowRect(r);
  1551. px1 += r.left;
  1552. px2 += r.left;
  1553. py1 += r.top;
  1554. py2 += r.top;
  1555. HDC dc;
  1556. lpdsBack->GetDC(&dc);
  1557. POINT p;
  1558. MoveToEx(dc, px1, py1, &p);
  1559. LineTo(dc, px2, py2);
  1560. lpdsBack->ReleaseDC(dc);
  1561. BlitBackbufferToHighRes();
  1562. RenderUIOverlay();
  1563. FlipHighResBuffer();
  1564. //lpds->Blt(NULL, lpdsBack, NULL, 0, 0);
  1565. }
  1566. else
  1567. {
  1568. PlaceCurrentObjectAt(x, y);
  1569. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1570. }
  1571. if (AD.mode == ACTIONMODE_PLACE && AD.type == 6)
  1572. {
  1573. Map->TakeSnapshot();
  1574. Map->Undo();
  1575. }
  1576. }
  1577. UpdateStatusBar(x, y);
  1578. isMoving = FALSE;
  1579. CView::OnMouseMove(nFlags, point);
  1580. }
  1581. void CIsoView::DrawCellCursor(const MapCoords& mapCoords, const DDSURFACEDESC2& desc)
  1582. {
  1583. ProjectedVec drawOffset(0*4, 0*3);
  1584. ProjectedCoords drawCoords2d = GetRenderTargetCoordinates(mapCoords, 0) + drawOffset;
  1585. ProjectedCoords drawCoords = GetRenderTargetCoordinates(mapCoords) + drawOffset;
  1586. static const COLORREF _cell_hilight_colors[16] = {
  1587. RGB(255, 255, 255), // level 0
  1588. RGB( 170, 0, 170), // level 1
  1589. RGB(0, 170, 170), // level 2
  1590. RGB(0, 170, 0), // level 3
  1591. RGB(90, 255, 90), // level 4
  1592. RGB(255, 255, 90), // level 5
  1593. RGB(255, 50, 50), // level 6
  1594. RGB(170, 85, 0), // level 7
  1595. RGB(170, 0, 0), // level 8
  1596. RGB(85, 255, 255), // level 9
  1597. RGB(80, 80, 255), // level 10
  1598. RGB(0, 0, 170), // level 11
  1599. RGB(0, 0, 0), // level 12
  1600. RGB(85,85 ,85), // level 13
  1601. RGB(170, 170, 170), // level 14
  1602. RGB(255, 255, 255) // level 15
  1603. };
  1604. const FIELDDATA& m = *Map->GetFielddataAt(mapCoords.x + mapCoords.y * Map->GetIsoSize());
  1605. int tileheight = m.bHeight;
  1606. int new_tileheight = std::clamp(tileheight, 0, 16);
  1607. DrawCell(desc.lpSurface, desc.dwWidth, desc.dwHeight, desc.lPitch, drawCoords.x, drawCoords.y, 1, 1, m_color_converter->GetColor(_cell_hilight_colors[new_tileheight]), false, true, m_color_converter->GetColor(60, 60, 255));
  1608. LineDrawer l(desc.lpSurface, bpp, desc.dwWidth, desc.dwHeight, desc.lPitch);
  1609. POINT p1, p2, p3, p4;
  1610. p2.x = drawCoords2d.x + 1 * f_x / 2 + f_x / 2;
  1611. p2.y = drawCoords2d.y + 1 * f_y / 2;
  1612. p3.x = drawCoords2d.x + 1 * f_x / 2 - 1 * f_x / 2 + f_x / 2 - 1;
  1613. p3.y = drawCoords2d.y + 1 * f_y / 2 + 1 * f_y / 2 - 1;
  1614. p4.x = drawCoords2d.x - 1 * f_x / 2 + f_x / 2 - 1;
  1615. p4.y = drawCoords2d.y + 1 * f_y / 2 - 1;
  1616. POINT p5, p6, p7, p8;
  1617. p6.x = drawCoords.x + 1 * f_x / 2 + f_x / 2;
  1618. p6.y = drawCoords.y + 1 * f_y / 2;
  1619. p7.x = drawCoords.x + 1 * f_x / 2 - 1 * f_x / 2 + f_x / 2 - 1;
  1620. p7.y = drawCoords.y + 1 * f_y / 2 + 1 * f_y / 2 - 1;
  1621. p8.x = drawCoords.x - 1 * f_x / 2 + f_x / 2 - 1;
  1622. p8.y = drawCoords.y + 1 * f_y / 2 - 1;
  1623. auto col = m_color_converter->GetColor(60, 60, 60);
  1624. if (drawCoords2d != drawCoords)
  1625. {
  1626. for (int y = 0; y < 2; ++y)
  1627. {
  1628. l.MoveTo(p2.x + 1, p2.y + y);
  1629. l.LineTo(p6.x + 1, p6.y + y, col, LineStyle::Dotted_4);
  1630. l.MoveTo(p3.x, p3.y + 1 + y);
  1631. l.LineTo(p7.x, p7.y + 1 + y, col, LineStyle::Dotted_4);
  1632. l.MoveTo(p4.x - 1, p4.y + y);
  1633. l.LineTo(p8.x - 1, p8.y + y, col, LineStyle::Dotted_4);
  1634. l.MoveTo(p2.x, p2.y + y);
  1635. l.LineTo(p6.x, p6.y + y, col, LineStyle::Dotted_4);
  1636. l.MoveTo(p3.x + 1, p3.y + 1 + y);
  1637. l.LineTo(p7.x + 1, p7.y + 1 + y, col, LineStyle::Dotted_4);
  1638. l.MoveTo(p4.x, p4.y + y);
  1639. l.LineTo(p8.x, p8.y + y, col, LineStyle::Dotted_4);
  1640. }
  1641. }
  1642. }
  1643. const int valadded = 10000;
  1644. void CIsoView::OnRButtonUp(UINT nFlags, CPoint point)
  1645. {
  1646. if (rscroll)
  1647. {
  1648. if (b_IsLoading) return;
  1649. ReleaseCapture();
  1650. KillTimer(11);
  1651. ShowCursor(TRUE);
  1652. CMyViewFrame& dlg = *(CMyViewFrame*)owner;
  1653. dlg.m_minimap.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1654. }
  1655. if (nFlags == 0 && point.x == 0 && point.y == 0)
  1656. {
  1657. m_drag = FALSE; return;
  1658. }
  1659. CIniFile& ini = Map->GetIniFile();
  1660. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1661. if (!rscroll) m_drag = FALSE;
  1662. const auto projCoords = GetProjectedCoordinatesFromClientCoordinates(point);
  1663. const MapCoords mapCoords = GetMapCoordinatesFromClientCoordinates(point, (nFlags & MK_CONTROL) == MK_CONTROL);
  1664. const int x = mapCoords.x; // compat
  1665. const int y = mapCoords.y;
  1666. // context menu
  1667. if (AD.mode != 0 && !rscroll)
  1668. {
  1669. bool ignoreClick = false;
  1670. if (AD.mode == ACTIONMODE_MAPTOOL)
  1671. {
  1672. if (AD.tool)
  1673. ignoreClick = AD.tool->onRButtonUp(projCoords, mapCoords, MapToolMouseFlagsFromWin32(nFlags));
  1674. }
  1675. if (!ignoreClick)
  1676. {
  1677. AD.reset();
  1678. CMyViewFrame& frame = *((CMyViewFrame*)owner);
  1679. frame.m_objectview->GetTreeCtrl().Select(frame.m_objectview->GetTreeCtrl().GetRootItem(), TVGN_CARET);
  1680. }
  1681. return;
  1682. }
  1683. rscroll = FALSE;
  1684. return;
  1685. CView::OnRButtonUp(nFlags, point);
  1686. }
  1687. // from old (popup menu) interface, taken over and used by OnLButtonDblClick
  1688. BOOL CIsoView::OnCommand(WPARAM wParam, LPARAM lParam)
  1689. {
  1690. int wNotifyCode = HIWORD(wParam); // notification code
  1691. int wID = LOWORD(wParam); // item, control, or accelerator identifier
  1692. HWND hwndCtl = (HWND)lParam; // handle of control
  1693. CIniFile& ini = Map->GetIniFile();
  1694. if (wID < valadded)
  1695. {
  1696. // a standard menu, no popup!
  1697. switch (wID)
  1698. {
  1699. case 4:
  1700. {
  1701. last_succeeded_operation = 54310;
  1702. //get the number
  1703. if (Map->GetAirAt(m_mapx + m_mapy * Map->GetIsoSize()) != -1)
  1704. {
  1705. HandleProperties(Map->GetAirAt(m_mapx + m_mapy * Map->GetIsoSize()), 2);
  1706. }
  1707. else if (Map->GetInfantryAt(m_mapx + m_mapy * Map->GetIsoSize()) != -1)
  1708. {
  1709. last_succeeded_operation = 54311;
  1710. int z;
  1711. for (z = 0;z < SUBPOS_COUNT;z++)
  1712. if (Map->GetInfantryAt(m_mapx + m_mapy * Map->GetIsoSize(), z) != -1) HandleProperties(Map->GetInfantryAt(m_mapx + m_mapy * Map->GetIsoSize(), z), 0);
  1713. }
  1714. else if (Map->GetUnitAt(m_mapx + m_mapy * Map->GetIsoSize()) != -1)
  1715. {
  1716. HandleProperties(Map->GetUnitAt(m_mapx + m_mapy * Map->GetIsoSize()), 3);
  1717. }
  1718. else if (Map->GetStructureAt(m_mapx + m_mapy * Map->GetIsoSize()) != -1)
  1719. {
  1720. HandleProperties(Map->GetStructureAt(m_mapx + m_mapy * Map->GetIsoSize()), 1);
  1721. }
  1722. break;
  1723. }
  1724. }
  1725. return 0;
  1726. }
  1727. return CView::OnCommand(wParam, lParam);
  1728. }
  1729. void CIsoView::HandleProperties(int n, int type)
  1730. {
  1731. CIniFile& ini = Map->GetIniFile();
  1732. if (n < 0) return;
  1733. switch (type)
  1734. {
  1735. case 0:
  1736. {
  1737. last_succeeded_operation = 54312;
  1738. // infantry
  1739. INFANTRY data;
  1740. Map->GetInfantryData(n, &data);
  1741. last_succeeded_operation = 54313;
  1742. CInfantrie dlg(this);
  1743. char tmp[255];
  1744. dlg.Init((LPCTSTR)data.house, (LPCTSTR)data.strength, (LPCTSTR)data.action,
  1745. (LPCTSTR)data.direction, (LPCTSTR)data.tag, (LPCTSTR)data.flag1,
  1746. (LPCTSTR)data.flag2, (LPCTSTR)data.flag3, (LPCTSTR)data.flag4, (LPCTSTR)data.flag5);
  1747. int res = dlg.DoModal();
  1748. if (res == IDCANCEL) return;
  1749. data.action = dlg.m_action;
  1750. data.strength = dlg.m_strength;
  1751. data.tag = dlg.m_tag;
  1752. data.direction = dlg.m_direction;
  1753. data.house = dlg.m_house;
  1754. data.flag1 = dlg.m_flag1;
  1755. data.flag2 = dlg.m_flag2;
  1756. data.flag3 = dlg.m_flag3;
  1757. data.flag4 = dlg.m_flag4;
  1758. data.flag5 = dlg.m_flag5;
  1759. Map->DeleteInfantry(n);
  1760. Map->AddInfantry(&data);
  1761. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1762. break;
  1763. }
  1764. case 1:
  1765. {
  1766. // building
  1767. STRUCTURE data;
  1768. Map->GetStructureData(n, &data);
  1769. CBuilding dlg(this);
  1770. char tmp[255];
  1771. dlg.Init((LPCTSTR)data.house, (LPCTSTR)data.strength, (LPCTSTR)data.direction, (LPCTSTR)data.tag,
  1772. (LPCTSTR)data.flag1, (LPCTSTR)data.flag2, (LPCTSTR)data.energy,
  1773. (LPCTSTR)data.upgradecount, (LPCTSTR)data.spotlight, (LPCTSTR)data.upgrade1, (LPCTSTR)data.upgrade2,
  1774. (LPCTSTR)data.upgrade3, (LPCTSTR)data.flag3, (LPCTSTR)data.flag4);
  1775. dlg.m_type = data.type;
  1776. int res = dlg.DoModal();
  1777. if (res == IDCANCEL) return;
  1778. data.strength = dlg.m_strength;
  1779. data.tag = dlg.m_tag;
  1780. data.direction = dlg.m_direction;
  1781. data.house = dlg.m_house;
  1782. data.spotlight = dlg.m_spotlight;
  1783. data.flag1 = dlg.m_flag1;
  1784. data.flag2 = dlg.m_flag2;
  1785. data.flag3 = dlg.m_flag3;
  1786. data.flag4 = dlg.m_flag4;
  1787. data.energy = dlg.m_energy;
  1788. data.upgradecount = dlg.m_upgradecount;
  1789. data.upgrade1 = dlg.m_upgrade1;
  1790. data.upgrade2 = dlg.m_upgrade2;
  1791. data.upgrade3 = dlg.m_upgrade3;
  1792. Map->DeleteStructure(n);
  1793. Map->AddStructure(&data);
  1794. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1795. break;
  1796. }
  1797. case 2:
  1798. {
  1799. // aircraft
  1800. AIRCRAFT data;
  1801. Map->GetAircraftData(n, &data);
  1802. CAircraft dlg(this);
  1803. char tmp[255];
  1804. dlg.Init(data.house, data.strength, data.direction, data.action,
  1805. data.tag, data.flag1, data.flag2, data.flag3, data.flag4);
  1806. int res = dlg.DoModal();
  1807. if (res == IDCANCEL) return;
  1808. data.action = dlg.m_action;
  1809. data.strength = dlg.m_strength;
  1810. data.tag = dlg.m_tag;
  1811. data.direction = dlg.m_direction;
  1812. data.house = dlg.m_house;
  1813. data.flag1 = dlg.m_flag1;
  1814. data.flag2 = dlg.m_flag2;
  1815. data.flag3 = dlg.m_flag3;
  1816. data.flag4 = dlg.m_flag4;
  1817. Map->DeleteAircraft(n);
  1818. Map->AddAircraft(&data);
  1819. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1820. break;
  1821. }
  1822. case 3:
  1823. {
  1824. // vehicle
  1825. UNIT data;
  1826. Map->GetUnitData(n, &data);
  1827. CUnit dlg(this);
  1828. char tmp[255];
  1829. dlg.Init(data.house, data.strength, data.direction, data.action,
  1830. data.tag, data.flag1, data.flag2, data.flag3, data.flag4, data.flag5, data.flag6);
  1831. int res = dlg.DoModal();
  1832. if (res == IDCANCEL) return;
  1833. data.action = dlg.m_action;
  1834. data.strength = dlg.m_strength;
  1835. data.tag = dlg.m_tag;
  1836. data.direction = dlg.m_direction;
  1837. data.house = dlg.m_house;
  1838. data.flag1 = dlg.m_flag1;
  1839. data.flag2 = dlg.m_flag2;
  1840. data.flag3 = dlg.m_flag3;
  1841. data.flag4 = dlg.m_flag4;
  1842. data.flag5 = dlg.m_flag5;
  1843. data.flag6 = dlg.m_flag6;
  1844. Map->DeleteUnit(n);
  1845. Map->AddUnit(&data);
  1846. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1847. break;
  1848. }
  1849. }
  1850. }
  1851. void CIsoView::OnLButtonDblClk(UINT nFlags, CPoint point)
  1852. {
  1853. if (b_IsLoading == TRUE) return;
  1854. m_NoMove = TRUE;
  1855. m_drag = FALSE;
  1856. const auto projCoords = GetProjectedCoordinatesFromClientCoordinates(point);
  1857. const MapCoords mapCoords = GetMapCoordinatesFromClientCoordinates(point, (nFlags & MK_CONTROL) == MK_CONTROL);
  1858. if (AD.mode == ACTIONMODE_MAPTOOL)
  1859. {
  1860. if (AD.tool)
  1861. AD.tool->onLButtonDblClick(projCoords, mapCoords, MapToolMouseFlagsFromWin32(nFlags));
  1862. }
  1863. else
  1864. {
  1865. if (!Map->isInside(mapCoords))
  1866. return;
  1867. m_mapx = mapCoords.x;
  1868. m_mapy = mapCoords.y;
  1869. int pos = m_mapx + m_mapy * Map->GetIsoSize();
  1870. if (Map->GetCelltagAt(pos) < 0)
  1871. {
  1872. OnCommand(4, 0);
  1873. }
  1874. else
  1875. OnCommand(9, 0);
  1876. }
  1877. m_NoMove = FALSE;
  1878. CView::OnLButtonDblClk(nFlags, point);
  1879. }
  1880. void CIsoView::OnLButtonDown(UINT nFlags, CPoint point)
  1881. {
  1882. if (Map->GetIsoSize() == 0) return;
  1883. if (b_IsLoading == TRUE) return;
  1884. CIniFile& ini = Map->GetIniFile();
  1885. const auto projCoords = GetProjectedCoordinatesFromClientCoordinates(point);
  1886. const MapCoords mapCoords = GetMapCoordinatesFromClientCoordinates(point, (nFlags & MK_CONTROL) == MK_CONTROL);
  1887. const int x = mapCoords.x; // compat
  1888. const int y = mapCoords.y;
  1889. int mapwidth = Map->GetWidth();
  1890. int mapheight = Map->GetHeight();
  1891. //if(x>=Map->GetIsoSize() || y>=Map->GetIsoSize() || x<0 || y<0) return;
  1892. if (AD.mode != ACTIONMODE_COPY && AD.mode != ACTIONMODE_PASTE && AD.mode != ACTIONMODE_MAPTOOL)
  1893. {
  1894. if (!Map->isInside(mapCoords))
  1895. return;
  1896. if (x < 1 || y < 1 || x + y<mapwidth + 1 || x + y>mapwidth + mapheight * 2 || (y + 1 > mapwidth && x - 1 < y - mapwidth) || (x + 1 > mapwidth && y + mapwidth - 1 < x))
  1897. return;
  1898. }
  1899. int px = m_mapx;
  1900. int py = m_mapy;
  1901. m_mapx = x;
  1902. m_mapy = y;
  1903. CStatusBarCtrl& stat = ((CMyViewFrame*)owner)->m_statbar.GetStatusBarCtrl();
  1904. if (AD.mode == ACTIONMODE_CLIFFFRONT || AD.mode == ACTIONMODE_CLIFFBACK)
  1905. {
  1906. m_drag = TRUE;
  1907. }
  1908. else if (AD.mode == ACTIONMODE_PASTE)
  1909. {
  1910. Map->TakeSnapshot();
  1911. Map->Paste(m_mapx, m_mapy, AD.z_data);
  1912. Map->TakeSnapshot();
  1913. Map->Undo();
  1914. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1915. }
  1916. else if (AD.mode == ACTIONMODE_COPY)
  1917. {
  1918. if (!m_drag)
  1919. {
  1920. m_drag = TRUE;
  1921. }
  1922. else // 2nd click
  1923. {
  1924. int x1, x2, y1, y2;
  1925. if (px < x)
  1926. {
  1927. x1 = px;
  1928. x2 = x;
  1929. }
  1930. else
  1931. {
  1932. x1 = x;
  1933. x2 = px;
  1934. }
  1935. if (py < y)
  1936. {
  1937. y1 = py;
  1938. y2 = y;
  1939. }
  1940. else
  1941. {
  1942. y1 = y;
  1943. y2 = py;
  1944. }
  1945. Map->Copy(x1, y1, x2 + 1, y2 + 1);
  1946. m_drag = FALSE;
  1947. }
  1948. }
  1949. else if (Map->IsGroundObjectAt(m_mapx + m_mapy * Map->GetIsoSize()) && AD.mode == 0 && m_NoMove == FALSE)
  1950. {
  1951. m_drag = TRUE;
  1952. m_moved = FALSE;
  1953. m_id = Map->GetInfantryAt(m_mapx + m_mapy * Map->GetIsoSize());
  1954. m_type = 0;
  1955. if (m_id < 0)
  1956. {
  1957. m_id = Map->GetUnitAt(m_mapx + m_mapy * Map->GetIsoSize());
  1958. m_type = 3;
  1959. }
  1960. if (m_id < 0)
  1961. {
  1962. m_id = Map->GetAirAt(m_mapx + m_mapy * Map->GetIsoSize());
  1963. m_type = 2;
  1964. }
  1965. if (m_id < 0)
  1966. {
  1967. m_id = Map->GetTerrainAt(m_mapx + m_mapy * Map->GetIsoSize());
  1968. m_type = 4;
  1969. }
  1970. if (m_id < 0)
  1971. {
  1972. m_id = Map->GetStructureAt(m_mapx + m_mapy * Map->GetIsoSize());
  1973. STDOBJECTDATA sod;
  1974. Map->GetStdStructureData(m_id, &sod);
  1975. m_mapx = atoi(sod.x);
  1976. m_mapy = atoi(sod.y);
  1977. m_type = 1;
  1978. }
  1979. }
  1980. else if (AD.mode == ACTIONMODE_SETTILE)
  1981. {
  1982. if ((nFlags & MK_CONTROL) && !(nFlags & MK_SHIFT))
  1983. {
  1984. // Fill the whole area
  1985. Sound(SOUND_LAYDOWNTILE);
  1986. Map->TakeSnapshot();
  1987. int i;
  1988. for (i = 0;i < Map->GetIsoSize() * Map->GetIsoSize();i++)
  1989. Map->SetReserved(i, 0);
  1990. FillArea(x, y, AD.type, 0);
  1991. Map->TakeSnapshot();
  1992. Map->Undo();
  1993. }
  1994. else
  1995. {
  1996. // just place a single tile
  1997. if (!(nFlags & MK_SHIFT))
  1998. {
  1999. Sound(SOUND_LAYDOWNTILE);
  2000. }
  2001. PlaceTile(x, y, nFlags);
  2002. }
  2003. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2004. }
  2005. else if (AD.mode == ACTIONMODE_HIDETILESET)
  2006. {
  2007. int ground = Map->GetFielddataAt(x + (y)*Map->GetIsoSize())->wGround;
  2008. if (ground == 0xFFFF) ground = 0;
  2009. //if(ground!=0)
  2010. HideTileSet((*tiledata)[ground].wTileSet);
  2011. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2012. }
  2013. else if (AD.mode == ACTIONMODE_HIDEFIELD)
  2014. {
  2015. Map->HideField(x + y * Map->GetIsoSize(), TRUE);
  2016. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2017. }
  2018. else if (AD.mode == ACTIONMODE_HEIGHTEN)
  2019. {
  2020. Map->TakeSnapshot();
  2021. m_TileChangeCount = 0;
  2022. //if(x==m_mapx && y==m_mapy)
  2023. //try
  2024. {
  2025. int ground = Map->GetFielddataAt(x + (y)*Map->GetIsoSize())->wGround;
  2026. if (ground == 0xFFFF) ground = 0;
  2027. if ((nFlags & MK_CONTROL) && !(*tiledata)[ground].bMorphable)
  2028. {
  2029. SetError("Applying non-morphable terrain height change, please wait...");
  2030. stat.RedrawWindow();
  2031. stat.UpdateWindow();
  2032. }
  2033. m_funcRect.left = x;
  2034. m_funcRect.top = y;
  2035. m_funcRect.bottom = y;
  2036. m_funcRect.right = x;
  2037. if ((*tiledata)[ground].bMorphable)
  2038. {
  2039. int f, n;
  2040. int oheight = Map->GetHeightAt(x + y * Map->GetIsoSize());
  2041. for (f = -m_BrushSize_x / 2;f < m_BrushSize_x / 2 + 1;f++)
  2042. {
  2043. for (n = -m_BrushSize_y / 2;n < m_BrushSize_y / 2 + 1;n++)
  2044. {
  2045. int pos = x + f + (y + n) * Map->GetIsoSize();
  2046. int ground = Map->GetFielddataAt(pos)->wGround;
  2047. if (ground == 0xFFFF) ground = 0;
  2048. if ((*tiledata)[ground].bMorphable && Map->GetHeightAt(pos) == oheight)
  2049. {
  2050. Map->SetHeightAt(pos, oheight + 1);
  2051. }
  2052. }
  2053. }
  2054. for (f = -m_BrushSize_x / 2;f < m_BrushSize_x / 2 + 1;f++)
  2055. {
  2056. for (n = -m_BrushSize_y / 2;n < m_BrushSize_y / 2 + 1;n++)
  2057. {
  2058. int pos = x + f + (y + n) * Map->GetIsoSize();
  2059. int ground = Map->GetFielddataAt(pos)->wGround;
  2060. if (ground == 0xFFFF) ground = 0;
  2061. if ((*tiledata)[ground].bMorphable && Map->GetHeightAt(x + f + (y + n) * Map->GetIsoSize()) == oheight + 1)
  2062. {
  2063. int i;
  2064. for (i = 0;i < Map->GetIsoSize() * Map->GetIsoSize();i++)
  2065. Map->SetReserved(i, 0);
  2066. ChangeTileHeight(x + f + (y + n) * Map->GetIsoSize(), oheight + 1, FALSE, (nFlags & MK_CONTROL), TRUE);
  2067. }
  2068. }
  2069. }
  2070. }
  2071. else
  2072. {
  2073. int i;
  2074. for (i = 0;i < Map->GetIsoSize() * Map->GetIsoSize();i++)
  2075. Map->SetReserved(i, 0);
  2076. // TODO: replace recursion, otherwise be aware of stack issues!
  2077. try
  2078. {
  2079. ChangeTileHeight(x + (y)*Map->GetIsoSize(), Map->GetHeightAt(x + y * Map->GetIsoSize()) + 1, FALSE, !(nFlags & MK_CONTROL));
  2080. }
  2081. catch (...)
  2082. {
  2083. MessageBox("Stack is too small to complete operation!", "Error");
  2084. }
  2085. }
  2086. int f, n;
  2087. for (f = m_funcRect.left - 1;f <= m_funcRect.right + 1;f++)
  2088. {
  2089. for (n = m_funcRect.top - 1;n <= m_funcRect.bottom + 1;n++)
  2090. {
  2091. int pos = f + (n)*Map->GetIsoSize();
  2092. Map->CreateSlopesAt(pos);
  2093. }
  2094. }
  2095. /*CHANGEHEIGHTDATA d;
  2096. d.pos=x+y*Map->GetIsoSize();
  2097. d.bNonMorpheable=FALSE;
  2098. d.toHeight=Map->GetHeightAt(x+y*Map->GetIsoSize())+1;
  2099. DWORD id;
  2100. HANDLE hThread=CreateThread(NULL, 4000000, ChangeHeightThread, &d, NULL, &id);
  2101. SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
  2102. WaitForSingleObjectEx(hThread, INFINITE, FALSE);*/
  2103. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2104. Map->TakeSnapshot();
  2105. Map->Undo();
  2106. }
  2107. //catch(...)
  2108. {
  2109. // MessageBox("Error occured","Error");
  2110. }
  2111. }
  2112. else if (AD.mode == ACTIONMODE_LOWER)
  2113. {
  2114. Map->TakeSnapshot();
  2115. m_TileChangeCount = 0;
  2116. //if(x==m_mapx && y==m_mapy)
  2117. //try
  2118. {
  2119. int ground = Map->GetFielddataAt(x + (y)*Map->GetIsoSize())->wGround;
  2120. if (ground == 0xFFFF) ground = 0;
  2121. if ((nFlags & MK_CONTROL) && !(*tiledata)[ground].bMorphable)
  2122. {
  2123. SetError("Applying non-morphable terrain height change, please wait...");
  2124. stat.RedrawWindow();
  2125. stat.UpdateWindow();
  2126. }
  2127. int i;
  2128. m_funcRect.left = x;
  2129. m_funcRect.top = y;
  2130. m_funcRect.bottom = y;
  2131. m_funcRect.right = x;
  2132. if ((*tiledata)[ground].bMorphable)
  2133. {
  2134. int f, n;
  2135. int oheight = Map->GetHeightAt(x + y * Map->GetIsoSize());
  2136. for (f = -m_BrushSize_x / 2;f < m_BrushSize_x / 2 + 1;f++)
  2137. {
  2138. for (n = -m_BrushSize_y / 2;n < m_BrushSize_y / 2 + 1;n++)
  2139. {
  2140. int pos = x + f + (y + n) * Map->GetIsoSize();
  2141. int ground = Map->GetFielddataAt(pos)->wGround;
  2142. if (ground == 0xFFFF) ground = 0;
  2143. if ((*tiledata)[ground].bMorphable && Map->GetHeightAt(pos) == oheight)
  2144. {
  2145. Map->SetHeightAt(pos, oheight - 1);
  2146. }
  2147. }
  2148. }
  2149. for (f = -m_BrushSize_x / 2;f < m_BrushSize_x / 2 + 1;f++)
  2150. {
  2151. for (n = -m_BrushSize_y / 2;n < m_BrushSize_y / 2 + 1;n++)
  2152. {
  2153. int pos = x + f + (y + n) * Map->GetIsoSize();
  2154. int ground = Map->GetFielddataAt(pos)->wGround;
  2155. if (ground == 0xFFFF) ground = 0;
  2156. if ((*tiledata)[ground].bMorphable && Map->GetHeightAt(x + f + (y + n) * Map->GetIsoSize()) == oheight - 1)
  2157. {
  2158. for (i = 0;i < Map->GetIsoSize() * Map->GetIsoSize();i++)
  2159. Map->SetReserved(i, 0);
  2160. ChangeTileHeight(x + f + (y + n) * Map->GetIsoSize(), oheight - 1, FALSE, (nFlags & MK_CONTROL), TRUE);
  2161. }
  2162. }
  2163. }
  2164. }
  2165. else
  2166. {
  2167. for (i = 0;i < Map->GetIsoSize() * Map->GetIsoSize();i++)
  2168. Map->SetReserved(i, 0);
  2169. try
  2170. {
  2171. ChangeTileHeight(x + (y)*Map->GetIsoSize(), Map->GetHeightAt(x + y * Map->GetIsoSize()) - 1, FALSE, !(nFlags & MK_CONTROL));
  2172. }
  2173. catch (...)
  2174. {
  2175. MessageBox("Stack is too small to complete operation!", "Error");
  2176. }
  2177. }
  2178. int f, n;
  2179. for (f = m_funcRect.left - 1;f <= m_funcRect.right + 1;f++)
  2180. {
  2181. for (n = m_funcRect.top - 1;n <= m_funcRect.bottom + 1;n++)
  2182. {
  2183. int pos = f + (n)*Map->GetIsoSize();
  2184. Map->CreateSlopesAt(pos);
  2185. }
  2186. }
  2187. /*CHANGEHEIGHTDATA d;
  2188. d.pos=x+y*Map->GetIsoSize();
  2189. d.bNonMorpheable=FALSE;
  2190. d.toHeight=Map->GetHeightAt(x+y*Map->GetIsoSize())-1;
  2191. DWORD id;
  2192. HANDLE hThread=CreateThread(NULL, 4000000, ChangeHeightThread, &d, NULL, &id);
  2193. SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
  2194. WaitForSingleObjectEx(hThread, INFINITE, FALSE);*/
  2195. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2196. }
  2197. //catch(...)
  2198. {
  2199. // MessageBox("Error occured","Error");
  2200. }
  2201. Map->TakeSnapshot();
  2202. Map->Undo();
  2203. }
  2204. else if (AD.mode == ACTIONMODE_HEIGHTENTILE)
  2205. {
  2206. Map->TakeSnapshot();
  2207. int n, m;
  2208. for (m = -m_BrushSize_x / 2;m < m_BrushSize_x / 2 + 1;m++)
  2209. {
  2210. for (n = -m_BrushSize_y / 2;n < m_BrushSize_y / 2 + 1;n++)
  2211. {
  2212. Map->SetHeightAt(x + m + (y + n) * Map->GetIsoSize(), Map->GetHeightAt(x + m + (y + n) * Map->GetIsoSize()) + 1);
  2213. }
  2214. }
  2215. if (nFlags & MK_CONTROL)
  2216. for (m = -m_BrushSize_x / 2 - 1;m < m_BrushSize_x / 2 + 2;m++)
  2217. {
  2218. for (n = -m_BrushSize_y / 2 - 1;n < m_BrushSize_y / 2 + 2;n++)
  2219. {
  2220. Map->CreateSlopesAt(x + m + (y + n) * Map->GetIsoSize());
  2221. }
  2222. }
  2223. Map->TakeSnapshot();
  2224. Map->Undo();
  2225. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2226. }
  2227. else if (AD.mode == ACTIONMODE_LOWERTILE)
  2228. {
  2229. Map->TakeSnapshot();
  2230. int n, m;
  2231. for (m = -m_BrushSize_x / 2;m < m_BrushSize_x / 2 + 1;m++)
  2232. {
  2233. for (n = -m_BrushSize_y / 2;n < m_BrushSize_y / 2 + 1;n++)
  2234. {
  2235. Map->SetHeightAt(x + m + (y + n) * Map->GetIsoSize(), Map->GetHeightAt(x + m + (y + n) * Map->GetIsoSize()) - 1);
  2236. }
  2237. }
  2238. if (nFlags & MK_CONTROL)
  2239. for (m = -m_BrushSize_x / 2 - 1;m < m_BrushSize_x / 2 + 2;m++)
  2240. {
  2241. for (n = -m_BrushSize_y / 2 - 1;n < m_BrushSize_y / 2 + 2;n++)
  2242. {
  2243. Map->CreateSlopesAt(x + m + (y + n) * Map->GetIsoSize());
  2244. }
  2245. }
  2246. Map->TakeSnapshot();
  2247. Map->Undo();
  2248. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2249. }
  2250. else if (AD.mode == ACTIONMODE_FLATTENGROUND)
  2251. {
  2252. Map->TakeSnapshot();
  2253. m_FlattenHeight = Map->GetHeightAt(x + y * Map->GetIsoSize());
  2254. m_FlattenLastX = x;
  2255. m_FlattenLastY = y;
  2256. Map->TakeSnapshot();
  2257. Map->Undo();
  2258. }
  2259. else if (Map->GetWaypointAt(m_mapx + m_mapy * Map->GetIsoSize()) >= 0 && AD.mode == 0)
  2260. {
  2261. m_drag = TRUE;
  2262. m_id = Map->GetWaypointAt(m_mapx + m_mapy * Map->GetIsoSize());
  2263. m_type = 6;
  2264. }
  2265. else if (Map->GetCelltagAt(m_mapx + m_mapy * Map->GetIsoSize()) >= 0 && AD.mode == 0)
  2266. {
  2267. m_drag = TRUE;
  2268. m_id = Map->GetCelltagAt(m_mapx + m_mapy * Map->GetIsoSize());
  2269. m_type = 5;
  2270. }
  2271. else if ((AD.mode < 3 || AD.mode>4) || (AD.mode == 3 && AD.type == 0) || (AD.mode >= 3 && AD.mode <= 4 && AD.type == 1))
  2272. {
  2273. OnMouseMove(nFlags, point);
  2274. }
  2275. else if (AD.mode == 3)
  2276. {
  2277. if (AD.type == 2)
  2278. {
  2279. // create waypoint
  2280. CWaypointID w(this);
  2281. if (w.DoModal() != IDCANCEL)
  2282. {
  2283. int n = w.m_value;
  2284. char id[50];
  2285. itoa(n, id, 10);
  2286. Map->AddWaypoint(id, x + y * Map->GetIsoSize());
  2287. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2288. }
  2289. }
  2290. if (AD.type >= 3) OnMouseMove(nFlags, point);
  2291. }
  2292. else if (AD.mode == 4)
  2293. {
  2294. if (AD.type == 0)
  2295. {
  2296. // create celltag
  2297. CCellTag w(this);
  2298. if (w.DoModal() != IDCANCEL)
  2299. {
  2300. Map->AddCelltag(w.m_tag, x + y * Map->GetIsoSize());
  2301. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2302. }
  2303. }
  2304. if (AD.type == 2)
  2305. {
  2306. // change celltag properties
  2307. int n = Map->GetCelltagAt(x + y * Map->GetIsoSize());
  2308. if (n < 0) return;
  2309. DWORD dwPos;
  2310. CString tag;
  2311. Map->GetCelltagData(n, &tag, &dwPos);
  2312. CCellTag dlg(this);
  2313. dlg.m_tag = tag;
  2314. dlg.m_tag += " (";
  2315. dlg.m_tag += GetParam(Map->GetIniFile().sections["Tags"].values[(LPCTSTR)tag], 1);
  2316. dlg.m_tag += ")";
  2317. if (dlg.DoModal() == IDCANCEL) return;
  2318. Map->DeleteCelltag(n);
  2319. Map->AddCelltag(dlg.m_tag, dwPos);
  2320. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2321. }
  2322. }
  2323. CView::OnLButtonDown(nFlags, point);
  2324. }
  2325. void CIsoView::PlaceTile(const int x, const int y, const UINT nMouseFlags)
  2326. {
  2327. Map->TakeSnapshot(TRUE, x - 6, y - 6, x + (*tiledata)[AD.type].cx * m_BrushSize_x + 7, y + (*tiledata)[AD.type].cy * m_BrushSize_y + 7);
  2328. int i, e, f, n;
  2329. int p = 0;
  2330. int width = (*tiledata)[AD.type].cx;
  2331. int height = (*tiledata)[AD.type].cy;
  2332. int pos = x - width + 1 + (y - height + 1) * Map->GetIsoSize();
  2333. int startheight = Map->GetHeightAt(x + y * Map->GetIsoSize()) + AD.z_data;
  2334. int ground = Map->GetFielddataAt(x + y * Map->GetIsoSize())->wGround;
  2335. if (ground == 0xFFFF) ground = 0;
  2336. startheight -= (*tiledata)[ground].tiles[Map->GetFielddataAt(x + y * Map->GetIsoSize())->bSubTile].bZHeight;
  2337. for (f = 0;f < m_BrushSize_x;f++)
  2338. {
  2339. for (n = 0;n < m_BrushSize_y;n++)
  2340. {
  2341. int tile = AD.type;
  2342. if (AD.data == 1)
  2343. {
  2344. int n = rand() * 5 / RAND_MAX;
  2345. tile += n;
  2346. }
  2347. p = 0;
  2348. for (i = 0;i < (*tiledata)[AD.type].cx;i++)
  2349. {
  2350. for (e = 0;e < (*tiledata)[AD.type].cy;e++)
  2351. {
  2352. if (x - width + 1 + f * width + i >= Map->GetIsoSize() ||
  2353. y - height + 1 + n * height + e >= Map->GetIsoSize())
  2354. {
  2355. }
  2356. else
  2357. if ((*tiledata)[AD.type].tiles[p].pic != NULL)
  2358. {
  2359. Map->SetHeightAt(pos + i + f * width + (e + n * height) * Map->GetIsoSize(), startheight + (*tiledata)[AD.type].tiles[p].bZHeight);
  2360. Map->SetTileAt(pos + i + f * width + (e + n * height) * Map->GetIsoSize(), tile, p);
  2361. }
  2362. p++;
  2363. }
  2364. }
  2365. }
  2366. }
  2367. if (!((nMouseFlags & MK_CONTROL) && (nMouseFlags & MK_SHIFT)))
  2368. {
  2369. if (!theApp.m_Options.bDisableAutoShore) Map->CreateShore(x - 5, y - 5, x + (*tiledata)[AD.type].cx * m_BrushSize_x + 5, y + (*tiledata)[AD.type].cy * m_BrushSize_y + 5, FALSE);
  2370. //Map->CreateShore(0,0,Map->GetIsoSize(), Map->GetIsoSize());
  2371. for (f = 0;f < m_BrushSize_x;f++)
  2372. {
  2373. for (n = 0;n < m_BrushSize_y;n++)
  2374. {
  2375. p = 0;
  2376. for (i = -1;i < (*tiledata)[AD.type].cx + 1;i++)
  2377. {
  2378. for (e = -1;e < (*tiledata)[AD.type].cy + 1;e++)
  2379. {
  2380. Map->SmoothAllAt(pos + i + f * width + (e + n * height) * Map->GetIsoSize());
  2381. p++;
  2382. }
  2383. }
  2384. }
  2385. }
  2386. }
  2387. // now make current tiles available for redo
  2388. Map->TakeSnapshot(TRUE, x - 6, y - 6, x + (*tiledata)[AD.type].cx * m_BrushSize_x + 6, y + (*tiledata)[AD.type].cy * m_BrushSize_y + 6);
  2389. Map->Undo();
  2390. }
  2391. void CIsoView::OnLButtonUp(UINT nFlags, CPoint point)
  2392. {
  2393. if (b_IsLoading == TRUE) return;
  2394. CIniFile& ini = Map->GetIniFile();
  2395. const auto projCoords = GetProjectedCoordinatesFromClientCoordinates(point);
  2396. const MapCoords mapCoords = GetMapCoordinatesFromClientCoordinates(point, (nFlags & MK_CONTROL) == MK_CONTROL);
  2397. const int dx = mapCoords.x; // compat
  2398. const int dy = mapCoords.y;
  2399. //if(dx>=Map->GetIsoSize() || dy>=Map->GetIsoSize() || dx<0 || dy<0) return;
  2400. int mapwidth = Map->GetWidth();
  2401. int mapheight = Map->GetHeight();
  2402. if (AD.mode != ACTIONMODE_COPY && AD.mode != ACTIONMODE_PASTE && AD.mode != ACTIONMODE_MAPTOOL)
  2403. {
  2404. if (!Map->isInside(mapCoords))
  2405. return;
  2406. if (dx < 1 || dy < 1 || dx + dy<mapwidth + 1 || dx + dy>mapwidth + mapheight * 2 || (dy + 1 > mapwidth && dx - 1 < dy - mapwidth) || (dx + 1 > mapwidth && dy + mapwidth - 1 < dx))
  2407. return;
  2408. }
  2409. char fx[50], fy[50];
  2410. itoa(dx, fx, 10);
  2411. itoa(dy, fy, 10);
  2412. int x, y;
  2413. x = dx;
  2414. y = dy;
  2415. // check if user did select something else than 0 in object browser
  2416. if (AD.mode != 0 && AD.mode != ACTIONMODE_COPY)
  2417. {
  2418. if (m_moved)
  2419. m_drag = FALSE;
  2420. m_moved = FALSE;
  2421. }
  2422. if (AD.mode == ACTIONMODE_FLATTENGROUND)
  2423. {
  2424. Map->TakeSnapshot();
  2425. Map->Undo();
  2426. }
  2427. if (AD.mode == ACTIONMODE_CLIFFFRONT || AD.mode == ACTIONMODE_CLIFFBACK)
  2428. {
  2429. m_drag = FALSE;
  2430. Map->Redo();
  2431. /*Map->TakeSnapshot();
  2432. if(AD.mode==ACTIONMODE_CLIFFFRONT)
  2433. {
  2434. CFrontCliffModifier f;
  2435. f.PlaceCliff(m_mapx, m_mapy, x, y);
  2436. }
  2437. else if(AD.mode==ACTIONMODE_CLIFFBACK)
  2438. {
  2439. CBackCliffModifier f;
  2440. f.PlaceCliff(m_mapx, m_mapy, x, y);
  2441. }*/
  2442. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2443. }
  2444. if (AD.mode == ACTIONMODE_COPY && m_drag)
  2445. {
  2446. /*m_drag=FALSE;
  2447. int x1, x2, y1, y2;
  2448. if(m_mapx<x) { x1=m_mapx; x2=x; } else { x1=x; x2=m_mapx; }
  2449. if(m_mapy<y) { y1=m_mapy; y2=y; } else { y1=y; y2=m_mapy; }
  2450. Map->Copy(x1, y1, x2+1, y2+1);*/
  2451. m_moved = FALSE;
  2452. }
  2453. if (m_drag && m_moved)
  2454. {
  2455. m_moved = FALSE;
  2456. // ok, drag the object at m_mapx/m_mapy to x/y
  2457. int x = dx, y = dy;
  2458. char strX[15], strY[15];
  2459. itoa(x, strX, 10);
  2460. itoa(y, strY, 10);
  2461. switch (m_type)
  2462. {
  2463. case 0: // drag infantry
  2464. {
  2465. INFANTRY infantry;
  2466. Map->GetInfantryData(m_id, &infantry);
  2467. infantry.x = strX;
  2468. infantry.y = strY;
  2469. infantry.pos = "-1";
  2470. if ((nFlags != MK_SHIFT))
  2471. {
  2472. Map->DeleteInfantry(m_id);
  2473. }
  2474. Map->AddInfantry(&infantry);
  2475. break;
  2476. }
  2477. case 1: // drag structure
  2478. {
  2479. STRUCTURE structure;
  2480. Map->GetStructureData(m_id, &structure);
  2481. structure.x = strX;
  2482. structure.y = strY;
  2483. if ((nFlags != MK_SHIFT))
  2484. {
  2485. Map->DeleteStructure(m_id);
  2486. }
  2487. Map->AddStructure(&structure);
  2488. break;
  2489. }
  2490. case 2: // drag aircraft
  2491. {
  2492. AIRCRAFT aircraft;
  2493. Map->GetAircraftData(m_id, &aircraft);
  2494. aircraft.x = strX;
  2495. aircraft.y = strY;
  2496. if ((nFlags != MK_SHIFT))
  2497. {
  2498. Map->DeleteAircraft(m_id);
  2499. }
  2500. Map->AddAircraft(&aircraft);
  2501. break;
  2502. }
  2503. case 3: // drag vehicles
  2504. {
  2505. UNIT unit;
  2506. Map->GetUnitData(m_id, &unit);
  2507. unit.x = strX;
  2508. unit.y = strY;
  2509. if (!(nFlags == MK_SHIFT))
  2510. {
  2511. Map->DeleteUnit(m_id);
  2512. }
  2513. Map->AddUnit(&unit);
  2514. break;
  2515. }
  2516. case 4: // drag terrain
  2517. {
  2518. CString type;
  2519. Map->GetTerrainData(m_id, &type);
  2520. if ((nFlags != MK_SHIFT))
  2521. {
  2522. Map->DeleteTerrain(m_id);
  2523. }
  2524. Map->AddTerrain(type, x + y * Map->GetIsoSize());
  2525. break;
  2526. }
  2527. case 5: // drag celltag
  2528. {
  2529. CString tag;
  2530. DWORD dwPos;
  2531. Map->GetCelltagData(m_id, &tag, &dwPos);
  2532. if ((nFlags != MK_SHIFT))
  2533. {
  2534. Map->DeleteCelltag(m_id);
  2535. }
  2536. Map->AddCelltag(tag, x + y * Map->GetIsoSize());
  2537. break;
  2538. }
  2539. case 6: // drag waypoint
  2540. {
  2541. CString ID;
  2542. DWORD dwPos;
  2543. Map->GetWaypointData(m_id, &ID, &dwPos);
  2544. if (!(nFlags == MK_SHIFT))
  2545. {
  2546. Map->DeleteWaypoint(m_id);
  2547. }
  2548. Map->AddWaypoint(ID, x + y * Map->GetIsoSize());
  2549. break;
  2550. }
  2551. }
  2552. m_drag = FALSE;
  2553. line.left = 0;
  2554. line.top = 0;
  2555. line.right = 0;
  2556. line.bottom = 0;
  2557. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2558. }
  2559. else if (AD.mode == ACTIONMODE_MAPTOOL)
  2560. {
  2561. if (AD.tool)
  2562. AD.tool->onLButtonUp(projCoords, mapCoords, MapToolMouseFlagsFromWin32(nFlags));
  2563. }
  2564. else if (AD.mode == ACTIONMODE_PLACE) // painting stuff
  2565. {
  2566. m_moved = FALSE;
  2567. if (AD.type == 6) // Overlay
  2568. {
  2569. if (AD.data == 5) // birdges
  2570. {
  2571. if (x == m_mapx && y == m_mapy) return;
  2572. int ovrltype = 0x18;
  2573. if (abs(x - m_mapx) >= abs(y - m_mapy))
  2574. {
  2575. // it´s from bottom left to top right
  2576. y = m_mapy;
  2577. ovrltype = 0x19;
  2578. }
  2579. else
  2580. {
  2581. // from bottom right to top left
  2582. x = m_mapx;
  2583. ovrltype = 0x18;
  2584. }
  2585. int tmp;
  2586. if (x < m_mapx)
  2587. {
  2588. tmp = m_mapx;
  2589. m_mapx = x;
  2590. x = tmp;
  2591. }
  2592. if (y < m_mapy)
  2593. {
  2594. tmp = m_mapy;
  2595. m_mapy = y;
  2596. y = tmp;
  2597. }
  2598. // okay, now we can do it...
  2599. int i;
  2600. if (AD.data2 == 0) // big bridge
  2601. {
  2602. int startheight = Map->GetFielddataAt(m_mapx + m_mapy * Map->GetIsoSize())->bHeight;
  2603. if (y == m_mapy)
  2604. {
  2605. for (i = m_mapx;i <= x;i++)
  2606. {
  2607. if (Map->GetFielddataAt(i + m_mapy * Map->GetIsoSize())->bHeight == startheight - 4)
  2608. {
  2609. startheight = Map->GetFielddataAt(i + m_mapy * Map->GetIsoSize())->bHeight;
  2610. break;
  2611. }
  2612. }
  2613. }
  2614. else
  2615. {
  2616. for (i = m_mapy;i <= y;i++)
  2617. {
  2618. if (Map->GetFielddataAt(m_mapx + i * Map->GetIsoSize())->bHeight == startheight - 4)
  2619. {
  2620. startheight = Map->GetFielddataAt(m_mapx + i * Map->GetIsoSize())->bHeight;
  2621. break;
  2622. }
  2623. }
  2624. }
  2625. if (y == m_mapy)
  2626. {
  2627. for (i = m_mapx;i <= x;i++)
  2628. {
  2629. if (Map->GetFielddataAt(i + m_mapy * Map->GetIsoSize())->bHeight == startheight)
  2630. {
  2631. Map->SetOverlayAt(i + m_mapy * Map->GetIsoSize(), ovrltype);
  2632. Map->SetOverlayDataAt(i + m_mapy * Map->GetIsoSize(), 0x9);
  2633. }
  2634. }
  2635. }
  2636. else
  2637. {
  2638. for (i = m_mapy;i <= y;i++)
  2639. {
  2640. if (Map->GetFielddataAt(m_mapx + i * Map->GetIsoSize())->bHeight == startheight)
  2641. {
  2642. Map->SetOverlayAt(m_mapx + i * Map->GetIsoSize(), ovrltype);
  2643. Map->SetOverlayDataAt(m_mapx + i * Map->GetIsoSize(), 0x0);
  2644. }
  2645. }
  2646. }
  2647. }
  2648. if (AD.data2 == 2) // big track bridge
  2649. {
  2650. int startheight = Map->GetFielddataAt(m_mapx + m_mapy * Map->GetIsoSize())->bHeight;
  2651. if (y == m_mapy)
  2652. {
  2653. for (i = m_mapx;i <= x;i++)
  2654. {
  2655. if (Map->GetFielddataAt(i + m_mapy * Map->GetIsoSize())->bHeight == startheight - 4)
  2656. {
  2657. startheight = Map->GetFielddataAt(i + m_mapy * Map->GetIsoSize())->bHeight;
  2658. break;
  2659. }
  2660. }
  2661. }
  2662. else
  2663. {
  2664. for (i = m_mapy;i <= y;i++)
  2665. {
  2666. if (Map->GetFielddataAt(m_mapx + i * Map->GetIsoSize())->bHeight == startheight - 4)
  2667. {
  2668. startheight = Map->GetFielddataAt(m_mapx + i * Map->GetIsoSize())->bHeight;
  2669. break;
  2670. }
  2671. }
  2672. }
  2673. if (y == m_mapy)
  2674. {
  2675. for (i = m_mapx;i <= x;i++)
  2676. {
  2677. if (Map->GetFielddataAt(i + m_mapy * Map->GetIsoSize())->bHeight == startheight)
  2678. {
  2679. Map->SetOverlayAt(i + m_mapy * Map->GetIsoSize(), 0x3c);
  2680. #ifdef RA2_MODE
  2681. Map->SetOverlayAt(i + m_mapy * Map->GetIsoSize(), 0xee);
  2682. #endif
  2683. Map->SetOverlayDataAt(i + m_mapy * Map->GetIsoSize(), 0x9);
  2684. }
  2685. }
  2686. }
  2687. else
  2688. {
  2689. for (i = m_mapy;i <= y;i++)
  2690. {
  2691. if (Map->GetFielddataAt(m_mapx + i * Map->GetIsoSize())->bHeight == startheight)
  2692. {
  2693. Map->SetOverlayAt(m_mapx + i * Map->GetIsoSize(), 0x3b);
  2694. #ifdef RA2_MODE
  2695. Map->SetOverlayAt(m_mapx + i * Map->GetIsoSize(), 0xed);
  2696. #endif
  2697. Map->SetOverlayDataAt(m_mapx + i * Map->GetIsoSize(), 0x0);
  2698. }
  2699. }
  2700. }
  2701. /*if(y==m_mapy)
  2702. {
  2703. for(i=m_mapx;i<=x;i++)
  2704. {
  2705. Map->SetOverlayAt(i+m_mapy*Map->GetIsoSize(), 0x3b);
  2706. Map->SetOverlayDataAt(i+m_mapy*Map->GetIsoSize(), 0x9);
  2707. }
  2708. }
  2709. else
  2710. {
  2711. for(i=m_mapy;i<=y;i++)
  2712. {
  2713. Map->SetOverlayAt(m_mapx+i*Map->GetIsoSize(), 0x3b);
  2714. Map->SetOverlayDataAt(m_mapx+i*Map->GetIsoSize(), 0x0);
  2715. }
  2716. }*/
  2717. }
  2718. else if (AD.data2 == 1 || AD.data2 == 3) // small bridge
  2719. {
  2720. int start = 0x4a;
  2721. if (AD.data2 == 3) start = 0xcd;
  2722. if (y == m_mapy)
  2723. {
  2724. srand((unsigned)time(NULL));
  2725. for (i = m_mapx + 1;i <= x - 1;i++)
  2726. {
  2727. int v2 = ((float)rand() / (float)RAND_MAX) * 4;
  2728. Map->SetOverlayAt(i + (m_mapy - 1) * Map->GetIsoSize(), start + 9 + v2);
  2729. Map->SetOverlayDataAt(i + (m_mapy - 1) * Map->GetIsoSize(), 0x0);
  2730. Map->SetOverlayAt(i + (m_mapy + 0) * Map->GetIsoSize(), start + 9 + v2);
  2731. Map->SetOverlayDataAt(i + (m_mapy + 0) * Map->GetIsoSize(), 0x1);
  2732. Map->SetOverlayAt(i + (m_mapy + 1) * Map->GetIsoSize(), start + 9 + v2);
  2733. Map->SetOverlayDataAt(i + (m_mapy + 1) * Map->GetIsoSize(), 0x2);
  2734. }
  2735. Map->SetOverlayAt(m_mapx + (m_mapy - 1) * Map->GetIsoSize(), start + 22);
  2736. Map->SetOverlayAt(m_mapx + (m_mapy - 0) * Map->GetIsoSize(), start + 22);
  2737. Map->SetOverlayAt(m_mapx + (m_mapy + 1) * Map->GetIsoSize(), start + 22);
  2738. Map->SetOverlayDataAt(m_mapx + (m_mapy - 1) * Map->GetIsoSize(), 0x0);
  2739. Map->SetOverlayDataAt(m_mapx + (m_mapy - 0) * Map->GetIsoSize(), 0x1);
  2740. Map->SetOverlayDataAt(m_mapx + (m_mapy + 1) * Map->GetIsoSize(), 0x2);
  2741. Map->SetOverlayAt(x + (m_mapy - 1) * Map->GetIsoSize(), start + 24);
  2742. Map->SetOverlayAt(x + (m_mapy - 0) * Map->GetIsoSize(), start + 24);
  2743. Map->SetOverlayAt(x + (m_mapy + 1) * Map->GetIsoSize(), start + 24);
  2744. Map->SetOverlayDataAt(x + (m_mapy - 1) * Map->GetIsoSize(), 0x0);
  2745. Map->SetOverlayDataAt(x + (m_mapy - 0) * Map->GetIsoSize(), 0x1);
  2746. Map->SetOverlayDataAt(x + (m_mapy + 1) * Map->GetIsoSize(), 0x2);
  2747. }
  2748. else
  2749. {
  2750. srand((unsigned)time(NULL));
  2751. for (i = m_mapy + 1;i <= y - 1;i++)
  2752. {
  2753. int v2 = ((float)rand() / (float)RAND_MAX) * 4;
  2754. Map->SetOverlayAt((m_mapx - 1) + i * Map->GetIsoSize(), start + v2);
  2755. Map->SetOverlayDataAt((m_mapx - 1) + i * Map->GetIsoSize(), 0x0);
  2756. Map->SetOverlayAt((m_mapx - 0) + i * Map->GetIsoSize(), start + v2);
  2757. Map->SetOverlayDataAt((m_mapx - 0) + i * Map->GetIsoSize(), 0x1);
  2758. Map->SetOverlayAt((m_mapx + 1) + i * Map->GetIsoSize(), start + v2);
  2759. Map->SetOverlayDataAt((m_mapx + 1) + i * Map->GetIsoSize(), 0x2);
  2760. }
  2761. Map->SetOverlayAt((m_mapx - 1) + m_mapy * Map->GetIsoSize(), start + 20);
  2762. Map->SetOverlayAt((m_mapx - 0) + m_mapy * Map->GetIsoSize(), start + 20);
  2763. Map->SetOverlayAt((m_mapx + 1) + m_mapy * Map->GetIsoSize(), start + 20);
  2764. Map->SetOverlayDataAt((m_mapx - 1) + m_mapy * Map->GetIsoSize(), 0x0);
  2765. Map->SetOverlayDataAt((m_mapx - 0) + m_mapy * Map->GetIsoSize(), 0x1);
  2766. Map->SetOverlayDataAt((m_mapx + 1) + m_mapy * Map->GetIsoSize(), 0x2);
  2767. Map->SetOverlayAt((m_mapx - 1) + y * Map->GetIsoSize(), start + 18);
  2768. Map->SetOverlayAt((m_mapx - 0) + y * Map->GetIsoSize(), start + 18);
  2769. Map->SetOverlayAt((m_mapx + 1) + y * Map->GetIsoSize(), start + 18);
  2770. Map->SetOverlayDataAt((m_mapx - 1) + y * Map->GetIsoSize(), 0x0);
  2771. Map->SetOverlayDataAt((m_mapx + 0) + y * Map->GetIsoSize(), 0x1);
  2772. Map->SetOverlayDataAt((m_mapx + 1) + y * Map->GetIsoSize(), 0x2);
  2773. }
  2774. }
  2775. //UpdateMap();
  2776. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2777. }
  2778. }
  2779. }
  2780. CFinalSunDlg& dlg = *(CFinalSunDlg*)theApp.m_pMainWnd;
  2781. dlg.m_view.m_minimap.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2782. m_moved = FALSE;
  2783. CView::OnLButtonUp(nFlags, point);
  2784. }
  2785. void CIsoView::TextOut(int x, int y, const char* text, COLORREF col)
  2786. {
  2787. HDC hdc;
  2788. lpdsBack->GetDC(&hdc);
  2789. SetTextColor(hdc, col);
  2790. SetBkMode(hdc, TRANSPARENT);
  2791. ::TextOut(hdc, x, y, text, strlen(text));
  2792. lpdsBack->ReleaseDC(hdc);
  2793. }
  2794. void CIsoView::TextOut(HDC hDC, int x, int y, const char* text, COLORREF col)
  2795. {
  2796. SetTextColor(hDC, col);
  2797. SetBkMode(hDC, TRANSPARENT);
  2798. ::TextOut(hDC, x, y, text, strlen(text));
  2799. }
  2800. void CIsoView::OnMove(int x, int y)
  2801. {
  2802. CView::OnMove(x, y);
  2803. if (lpds == NULL) return;
  2804. LPDIRECTDRAWCLIPPER ddc;
  2805. lpds->GetClipper(&ddc);
  2806. ddc->SetHWnd(0, m_hWnd);
  2807. updateFontScaled();
  2808. RedrawWindow();
  2809. }
  2810. void CIsoView::OnSize(UINT nType, int cx, int cy)
  2811. {
  2812. // CView::OnSize(nType, cx, cy);
  2813. if (lpds == NULL) return;
  2814. LPDIRECTDRAWCLIPPER ddc;
  2815. lpds->GetClipper(&ddc);
  2816. ddc->SetHWnd(0, m_hWnd);
  2817. updateFontScaled();
  2818. CMyViewFrame& dlg = *(CMyViewFrame*)owner;
  2819. dlg.m_minimap.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2820. UpdateScrollRanges();
  2821. GetWindowRect(&m_myRect);
  2822. }
  2823. COLORREF CIsoView::GetColor(const char* house, const char* vcolor)
  2824. {
  2825. COLORREF neutral = RGB(120, 120, 120);
  2826. COLORREF GDI = RGB(170, 170, 0);
  2827. COLORREF Nod = RGB(255, 0, 0);
  2828. COLORREF other = RGB(255, 255, 0);
  2829. CString color;
  2830. CIniFile& ini = Map->GetIniFile();
  2831. if (house && strlen(house))
  2832. {
  2833. if (ini.sections.find(house) != ini.sections.end())
  2834. {
  2835. color = ini.sections[house].values["Color"];
  2836. }
  2837. else
  2838. color = rules.sections[house].values["Color"];
  2839. }
  2840. if (vcolor)
  2841. color = vcolor;
  2842. if (color)
  2843. {
  2844. CString colorValues;
  2845. if (ini.sections.contains("Colors"))
  2846. {
  2847. colorValues = ini.sections["Colors"].GetValueByName(color);
  2848. }
  2849. if (colorValues.IsEmpty() && rules.sections.contains("Colors"))
  2850. {
  2851. colorValues = rules.sections["Colors"].GetValueByName(color);
  2852. }
  2853. auto colorArray = SplitParams(colorValues);
  2854. if (colorArray.size() == 3)
  2855. {
  2856. unsigned char hsv[3] = { static_cast<unsigned char>(std::atoi(colorArray[0])), static_cast<unsigned char>(std::atoi(colorArray[1])), static_cast<unsigned char>(std::atoi(colorArray[2])) };
  2857. unsigned char rgb[3];
  2858. HSVToRGB(hsv, rgb);
  2859. return RGB(rgb[0], rgb[1], rgb[2]);
  2860. }
  2861. }
  2862. #ifndef RA2_MODE
  2863. if (strstr(house, houses[0].name) != NULL)
  2864. {
  2865. return GDI;
  2866. }
  2867. else if (strstr(house, houses[1].name) != NULL)
  2868. {
  2869. return Nod;
  2870. }
  2871. else if (strstr(house, houses[2].name) != NULL)
  2872. {
  2873. return neutral;
  2874. }
  2875. else
  2876. {
  2877. if (isIncluded(color, "darkred") != NULL)
  2878. {
  2879. return Nod;
  2880. }
  2881. if (isIncluded(color, "grey") != NULL)
  2882. {
  2883. return RGB(120, 120, 120);
  2884. }
  2885. if (isIncluded(color, "gold") != NULL)
  2886. {
  2887. return GDI;
  2888. }
  2889. return other;
  2890. }
  2891. #else
  2892. if (isIncluded(color, "darkred") != NULL)
  2893. {
  2894. return RGB(130, 20, 20);
  2895. }
  2896. if (isIncluded(color, "grey") != NULL)
  2897. {
  2898. return RGB(120, 120, 120);
  2899. }
  2900. if (isIncluded(color, "red") != NULL)
  2901. {
  2902. return RGB(240, 20, 20);
  2903. }
  2904. if (isIncluded(color, "lightgold") != NULL)
  2905. {
  2906. return RGB(220, 220, 150);
  2907. }
  2908. if (isIncluded(color, "yellow") != NULL)
  2909. {
  2910. return RGB(240, 240, 0);
  2911. }
  2912. if (isIncluded(color, "gold") != NULL)
  2913. {
  2914. return RGB(230, 200, 0);
  2915. }
  2916. if (isIncluded(color, "darkgreen") != NULL)
  2917. {
  2918. return RGB(50, 160, 70);
  2919. }
  2920. if (isIncluded(color, "neongreen") != NULL)
  2921. {
  2922. return RGB(10, 255, 10);
  2923. }
  2924. if (isIncluded(color, "green") != NULL)
  2925. {
  2926. return RGB(50, 200, 70);
  2927. }
  2928. if (isIncluded(color, "darkblue") != NULL)
  2929. {
  2930. return RGB(30, 30, 150);
  2931. }
  2932. if (isIncluded(color, "lightblue") != NULL)
  2933. {
  2934. return RGB(100, 100, 200);
  2935. }
  2936. if (isIncluded(color, "neonblue") != NULL)
  2937. {
  2938. return RGB(35, 205, 255);
  2939. }
  2940. {
  2941. return other;
  2942. }
  2943. #endif
  2944. }
  2945. /*
  2946. GetOverlayPic(BYTE ovrl, BYTE ovrldata);
  2947. Returns the picture that should be used to draw the overlay tile.
  2948. First checks if a explicite bitmap exists for this tile, if not
  2949. checks if it can be displayed by a standard bitmap.
  2950. For bridges, it also needs the overlaydata.
  2951. */
  2952. inline PICDATA* GetOverlayPic(BYTE ovrl, BYTE ovrldata)
  2953. {
  2954. char c[50];
  2955. char d[50];
  2956. itoa(ovrl, c, 10);
  2957. itoa(ovrldata, d, 10);
  2958. CString fname = (CString)"OVRL" + c + "_" + d;
  2959. // MessageBox(0,fname,"",0);
  2960. if (pics.find(fname) != pics.end()) return &pics[fname];
  2961. //errstream << "pic " << (LPCSTR)fname << " not found" << endl;
  2962. return NULL;
  2963. }
  2964. void CIsoView::OnDraw(CDC* pDC)
  2965. {
  2966. DrawMap();
  2967. }
  2968. void CIsoView::ReInitializeDDraw()
  2969. {
  2970. b_IsLoading = TRUE;
  2971. ReleaseCapture();
  2972. KillTimer(11);
  2973. // rscroll=FALSE;
  2974. #ifdef NOSURFACES
  2975. while ((GetDeviceCaps(::GetDC(::GetDesktopWindow()), BITSPIXEL) <= 8))
  2976. {
  2977. if (MessageBox("You currently only have 8 bit color mode enabled. FinalAlert 2 does not work in 8 bit color mode. Please change the color mode and then click on OK. Click Cancel to quit (and save the map as backup.map).", "Error", MB_OKCANCEL) == IDCANCEL)
  2978. {
  2979. ((CFinalSunDlg*)theApp.m_pMainWnd)->SaveMap((u8AppDataPath + "\\backup.map").c_str());
  2980. PostQuitMessage(0);
  2981. return;
  2982. }
  2983. }
  2984. #endif
  2985. CDynamicGraphDlg dlg;
  2986. dlg.ShowWindow(SW_SHOW);
  2987. dlg.UpdateWindow();
  2988. dd->RestoreAllSurfaces();
  2989. updateFontScaled();
  2990. missingimages.clear();
  2991. theApp.m_loading->FreeAll();
  2992. theApp.m_loading->InitDirectDraw();
  2993. theApp.m_loading->InitPics();
  2994. theApp.m_loading->InitTMPs(&dlg.m_Progress);
  2995. memset(ovrlpics, 0, max_ovrl_img * 0xFF * sizeof(LPDIRECTDRAWSURFACE4));
  2996. //UpdateOverlayPictures(-1);
  2997. //Map->UpdateIniFile(MAPDATA_UPDATE_FROM_INI);
  2998. Map->UpdateBuildingInfo();
  2999. Map->UpdateTreeInfo();
  3000. #ifdef SMUDGE_SUPP
  3001. Map->UpdateSmudgeInfo();
  3002. #endif
  3003. b_IsLoading = FALSE;
  3004. //Sleep(2500);
  3005. dlg.DestroyWindow();
  3006. RedrawWindow();
  3007. /*
  3008. CString CommandLine;
  3009. if(res==IDYES)
  3010. {
  3011. CFileDialog dlg(FALSE, ".mpr", "noname.mpr", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "TS maps|*.mpr;*.map|TS multi maps|*.mpr|TS single maps|*.map|");
  3012. do
  3013. {
  3014. char cuPath[MAX_PATH];
  3015. GetCurrentDirectory(MAX_PATH, cuPath);
  3016. dlg.m_ofn.lpstrInitialDir=cuPath;
  3017. if(theApp.m_Options.TSExe.GetLength()) dlg.m_ofn.lpstrInitialDir=(char*)(LPCTSTR)theApp.m_Options.TSExe;
  3018. }while(dlg.DoModal()==IDCANCEL) ;
  3019. CommandLine=dlg.GetPathName();
  3020. ((CFinalSunDlg*)theApp.m_pMainWnd)->SaveMap(dlg.GetPathName());
  3021. }
  3022. if(res==IDNO || res==IDYES)
  3023. {
  3024. PROCESS_INFORMATION pi;
  3025. STARTUPINFO si;
  3026. memset(&si, 0, sizeof(STARTUPINFO));
  3027. si.cb=sizeof(STARTUPINFO);
  3028. char myExe[MAX_PATH];
  3029. GetModuleFileName(NULL, myExe, MAX_PATH);
  3030. BOOL success=CreateProcess(myExe,
  3031. (LPTSTR)(LPCTSTR)CommandLine,
  3032. NULL,
  3033. NULL,
  3034. FALSE,
  3035. NORMAL_PRIORITY_CLASS,
  3036. NULL,
  3037. AppPath,
  3038. &si,
  3039. &pi);
  3040. }
  3041. theApp.m_pMainWnd->DestroyWindow();*/
  3042. /*CLoading load;
  3043. load.InitDirectDraw();
  3044. load.InitMixFiles();
  3045. load.InitPics();
  3046. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  3047. b_IsLoading=FALSE;*/
  3048. }
  3049. void CIsoView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  3050. {
  3051. CView::OnChar(nChar, nRepCnt, nFlags);
  3052. }
  3053. void CIsoView::OnDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  3054. {
  3055. CView::OnDeadChar(nChar, nRepCnt, nFlags);
  3056. }
  3057. void CIsoView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  3058. {
  3059. int nPos;
  3060. if (nChar == 68) // D key
  3061. {
  3062. theApp.m_Options.bFlat = !theApp.m_Options.bFlat;
  3063. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  3064. }
  3065. if (nChar == 65)
  3066. m_bAltCliff = !m_bAltCliff;
  3067. CView::OnKeyDown(nChar, nRepCnt, nFlags);
  3068. }
  3069. void CIsoView::SetError(const char* text)
  3070. {
  3071. CMyViewFrame& v = *((CMyViewFrame*)owner);
  3072. v.m_statbar.GetStatusBarCtrl().SetText(text, 0, 0);
  3073. }
  3074. int CIsoView::GetOverlayDirection(int x, int y)
  3075. {
  3076. DWORD dwIsoSize = Map->GetIsoSize();
  3077. int p = -1;
  3078. int type = Map->GetOverlayAt(x + y * dwIsoSize);
  3079. BOOL isTrail = FALSE;
  3080. int i;
  3081. for (i = 0;i < overlay_count;i++)
  3082. if (overlay_number[i] == type)
  3083. if (overlay_trail[i]) isTrail = TRUE;
  3084. if (isTrack(type)) // handling a train track
  3085. {
  3086. if (isTrack(Map->GetOverlayAt((x - 1) + (y - 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 1) + (y + 1) * dwIsoSize)))
  3087. return 0;
  3088. if (isTrack(Map->GetOverlayAt((x + 1) + (y - 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x - 1) + (y + 1) * dwIsoSize)))
  3089. return 1;
  3090. if (isTrack(Map->GetOverlayAt((x - 1) + (y - 0) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 1) + (y + 0) * dwIsoSize)))
  3091. return 2;
  3092. if (isTrack(Map->GetOverlayAt((x - 0) + (y - 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 0) + (y + 1) * dwIsoSize)))
  3093. return 3;
  3094. if (isTrack(Map->GetOverlayAt((x - 1) + (y - 0) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 1) + (y + 1) * dwIsoSize)))
  3095. return 4;
  3096. if (isTrack(Map->GetOverlayAt((x - 0) + (y - 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 1) + (y + 1) * dwIsoSize)))
  3097. return 5;
  3098. if (isTrack(Map->GetOverlayAt((x - 1) + (y - 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x - 0) + (y + 1) * dwIsoSize)))
  3099. return 6;
  3100. if (isTrack(Map->GetOverlayAt((x - 1) + (y - 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 1) + (y + 0) * dwIsoSize)))
  3101. return 7;
  3102. if (isTrack(Map->GetOverlayAt((x - 1) + (y - 0) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 1) + (y - 1) * dwIsoSize)))
  3103. return 8;
  3104. if (isTrack(Map->GetOverlayAt((x + 0) + (y + 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 1) + (y - 1) * dwIsoSize)))
  3105. return 9;
  3106. if (isTrack(Map->GetOverlayAt((x - 0) + (y - 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x - 1) + (y + 1) * dwIsoSize)))
  3107. return 10;
  3108. if (isTrack(Map->GetOverlayAt((x - 1) + (y + 1) * dwIsoSize)) && isTrack(Map->GetOverlayAt((x + 1) + (y + 0) * dwIsoSize)))
  3109. return 11;
  3110. if (isTrack(Map->GetOverlayAt((x - 1) + (y - 1) * dwIsoSize)))
  3111. return 0;
  3112. if (isTrack(Map->GetOverlayAt((x - 1) + (y + 1) * dwIsoSize)))
  3113. return 1;
  3114. if (isTrack(Map->GetOverlayAt((x - 1) + (y - 0) * dwIsoSize)))
  3115. return 2;
  3116. if (isTrack(Map->GetOverlayAt((x - 0) + (y - 1) * dwIsoSize)))
  3117. return 3;
  3118. if (isTrack(Map->GetOverlayAt((x + 1) + (y + 1) * dwIsoSize)))
  3119. return 0;
  3120. if (isTrack(Map->GetOverlayAt((x + 1) + (y - 1) * dwIsoSize)))
  3121. return 1;
  3122. if (isTrack(Map->GetOverlayAt((x + 1) + (y + 0) * dwIsoSize)))
  3123. return 2;
  3124. if (isTrack(Map->GetOverlayAt((x + 0) + (y + 1) * dwIsoSize)))
  3125. return 3;
  3126. return 0;
  3127. }
  3128. else if (isTrail) // handling something like a sandbag
  3129. {
  3130. p = 0;
  3131. if (Map->GetOverlayAt(x - 1 + (y - 0) * dwIsoSize) == type) p |= 0x1;
  3132. if (Map->GetOverlayAt(x + (y + 1) * dwIsoSize) == type) p |= 0x2;
  3133. if (Map->GetOverlayAt(x + 1 + (y + 0) * dwIsoSize) == type) p |= 0x4;
  3134. if (Map->GetOverlayAt(x + (y - 1) * dwIsoSize) == type) p |= 0x8;
  3135. }
  3136. return p;
  3137. }
  3138. void CIsoView::HandleTrail(int x, int y)
  3139. {
  3140. int i, e;
  3141. int type = Map->GetOverlayAt(x + y * Map->GetIsoSize());
  3142. if (isTrack(type)) // is a track (overlay must be changed)
  3143. {
  3144. for (i = x - 2;i <= x + 2;i++)
  3145. {
  3146. for (e = y - 1;e <= y + 1;e++)
  3147. {
  3148. if (isTrack(Map->GetOverlayAt(i + e * Map->GetIsoSize())))
  3149. Map->SetOverlayAt(i + e * Map->GetIsoSize(), 0x27 + GetOverlayDirection(i, e));
  3150. }
  3151. }
  3152. }
  3153. else // something like a sandbag (overlaydata must be changed)
  3154. {
  3155. for (i = x - 2;i <= x + 2;i++)
  3156. {
  3157. for (e = y - 1;e <= y + 1;e++)
  3158. {
  3159. if (Map->GetOverlayAt(i + e * Map->GetIsoSize()) == type)
  3160. {
  3161. int dir = GetOverlayDirection(i, e);
  3162. if (dir >= 0) Map->SetOverlayDataAt(i + e * Map->GetIsoSize(), dir);
  3163. }
  3164. }
  3165. }
  3166. }
  3167. }
  3168. /*
  3169. DrawCell(int x, int y, int w, int h, COLORREF col)
  3170. Draws a frame around one or more cells.
  3171. w is the width, h is the height (in cells).
  3172. x and y are pixel coordinates.
  3173. col specifies the color.
  3174. */
  3175. void CIsoView::DrawCell(int x, int y, int w, int h, COLORREF col, BOOL dotted, HDC hDC_)
  3176. {
  3177. // correct the y value:
  3178. //y -= f_y;
  3179. POINT p1, p2, p3, p4;
  3180. p1.x = x + f_x / 2;
  3181. p1.y = y;
  3182. p2.x = x + w * f_x / 2 + f_x / 2;
  3183. p2.y = y + w * f_y / 2;
  3184. p3.x = x + w * f_x / 2 - h * f_x / 2 + f_x / 2 - 1;
  3185. p3.y = y + h * f_y / 2 + w * f_y / 2 - 1;
  3186. p4.x = x - h * f_x / 2 + f_x / 2 - 1;
  3187. p4.y = y + h * f_y / 2 - 1;
  3188. HDC hDC = hDC_;
  3189. if (!hDC)
  3190. while (lpdsBack->GetDC(&hDC) == DDERR_WASSTILLDRAWING);
  3191. HPEN p;
  3192. int width = 1;
  3193. #ifdef RA2_MODE
  3194. width = 2;
  3195. #endif
  3196. if (!dotted) p = CreatePen(PS_SOLID, width, col);
  3197. else p = CreatePen(PS_DOT, 0, col);
  3198. SelectObject(hDC, p);
  3199. if (dotted)
  3200. {
  3201. SetBkMode(hDC, TRANSPARENT);
  3202. MoveToEx(hDC, p1.x, p1.y - 1, NULL);
  3203. LineTo(hDC, p2.x + 1, p2.y);
  3204. LineTo(hDC, p3.x, p3.y + 1);
  3205. LineTo(hDC, p4.x - 1, p4.y);
  3206. LineTo(hDC, p1.x, p1.y - 1);
  3207. }
  3208. if (!dotted)
  3209. {
  3210. MoveToEx(hDC, p1.x, p1.y, NULL);
  3211. LineTo(hDC, p2.x, p2.y);
  3212. LineTo(hDC, p3.x, p3.y);
  3213. LineTo(hDC, p4.x, p4.y);
  3214. LineTo(hDC, p1.x, p1.y);
  3215. }
  3216. if (!hDC_)
  3217. lpdsBack->ReleaseDC(hDC);
  3218. DeleteObject(p);
  3219. }
  3220. void CIsoView::DrawCell(void* dest, int dest_width, int dest_height, int dest_pitch, int drawx, int drawy, int w, int h, int col, bool dotted, bool touchNeighbours, int colNeighbour) const
  3221. {
  3222. if (colNeighbour == CLR_INVALID)
  3223. colNeighbour = col;
  3224. // correct the y value:
  3225. //y -= f_y;
  3226. POINT p1, p2, p3, p4;
  3227. p1.x = drawx + f_x / 2;
  3228. p1.y = drawy;
  3229. p2.x = drawx + w * f_x / 2 + f_x / 2;
  3230. p2.y = drawy + w * f_y / 2;
  3231. p3.x = drawx + w * f_x / 2 - h * f_x / 2 + f_x / 2;
  3232. p3.y = drawy + h * f_y / 2 + w * f_y / 2;
  3233. p4.x = drawx - h * f_x / 2 + f_x / 2;
  3234. p4.y = drawy + h * f_y / 2;
  3235. LineDrawer drawer(dest, bpp, dest_width, dest_height, dest_pitch);
  3236. const LineStyle style = dotted ? LineStyle::Dotted_4 : LineStyle::Standard;
  3237. for (int x = 0; x < 1; ++x) // you could use this loop for more thickness
  3238. {
  3239. for (int y = 0; y < 1; ++y)
  3240. {
  3241. // inside the MM tile
  3242. drawer.MoveTo(p1.x + x + 1, p1.y + y + 1);
  3243. drawer.LineTo(p2.x + x - 2, p2.y + y - 1, col, style);
  3244. drawer.LineTo(p3.x + x + 1, p3.y + y - 3, col, style);
  3245. drawer.LineTo(p3.x + x, p3.y + y - 3, col, style);
  3246. drawer.LineTo(p4.x + x + 3, p4.y + y - 1, col, style);
  3247. drawer.LineTo(p4.x + x + 2, p4.y + y - 1, col, style);
  3248. drawer.MoveTo(p4.x + x + 3, p4.y + y - 1);
  3249. drawer.LineTo(p1.x + x, p1.y + y + 1, col, style);
  3250. drawer.LineTo(p1.x + x + 1, p1.y + y + 1, col, style);
  3251. // on inner pixels of MM tile boundary
  3252. drawer.MoveTo(p1.x + x + 1, p1.y + y);
  3253. drawer.LineTo(p2.x + x, p2.y + y - 1, col, style);
  3254. drawer.LineTo(p3.x + x + 1, p3.y + y - 2, col, style);
  3255. drawer.LineTo(p3.x + x, p3.y + y - 2, col, style);
  3256. drawer.LineTo(p4.x + x + 1, p4.y + y - 1, col, style);
  3257. drawer.LineTo(p1.x + x, p1.y + y, col, style);
  3258. drawer.LineTo(p1.x + x + 1, p1.y + y, col, style);
  3259. }
  3260. }
  3261. // pixels of neighboured MM tiles boundary
  3262. if (touchNeighbours)
  3263. {
  3264. for (int x = 0; x < 1; ++x) // you could use this loop for more thickness
  3265. {
  3266. for (int y = 0; y < 1; ++y)
  3267. {
  3268. drawer.MoveTo(p1.x + x + 1, p1.y + y - 1);
  3269. drawer.LineTo(p2.x + x - 2, p2.y + y - 3, colNeighbour, style);
  3270. drawer.MoveTo(p2.x + x - 2, p2.y + y - 2);
  3271. drawer.LineTo(p2.x + x - 1, p2.y + y, colNeighbour, style);
  3272. drawer.LineTo(p2.x + x, p2.y + y, colNeighbour, style);
  3273. drawer.LineTo(p3.x + x + 1, p3.y + y - 1, colNeighbour, style);
  3274. drawer.LineTo(p3.x + x, p3.y + y - 1, colNeighbour, style);
  3275. drawer.LineTo(p4.x + x + 1, p4.y + y, colNeighbour, style);
  3276. drawer.LineTo(p4.x + x, p4.y + y - 1, colNeighbour, style);
  3277. drawer.LineTo(p1.x + x, p1.y + y - 1, colNeighbour, style);
  3278. drawer.LineTo(p1.x + x + 1, p1.y + y - 1, colNeighbour, style);
  3279. }
  3280. }
  3281. }
  3282. }
  3283. void CIsoView::DrawTube(const CTube& tube, const DDSURFACEDESC2* lockedDDSD, const COLORREF* color) const
  3284. {
  3285. SurfaceLocker locker(lpdsBack);
  3286. if (!lockedDDSD || !lockedDDSD->lpSurface)
  3287. {
  3288. lockedDDSD = locker.ensure_locked();
  3289. }
  3290. if (!lockedDDSD)
  3291. return;
  3292. // TODO: culling if required
  3293. // find out if we are tube #1 or #2 for bidirectional tubes
  3294. bool type0 = tube.getStartX() == tube.getEndX() ? (tube.getStartY() < tube.getEndY()) : (tube.getStartX() < tube.getEndX());
  3295. const auto col = color ? m_color_converter->GetColor(*color) : (type0 ? m_color_converter->GetColor(255, 0, 0) : m_color_converter->GetColor(0, 0, 255));
  3296. ProjectedVec lineOffset = type0 ? ProjectedVec() : ProjectedVec(1, 1);
  3297. int lowestHeight = min(Map->GetHeightAt(tube.getStartCoords()), Map->GetHeightAt(tube.getEndCoords()));
  3298. LineDrawer ld(lockedDDSD->lpSurface, bpp, lockedDDSD->dwWidth, lockedDDSD->dwHeight, lockedDDSD->lPitch);
  3299. auto startDraw = GetRenderTargetCoordinates(tube.getStartCoords(), lowestHeight);
  3300. ld.MoveTo(startDraw.x + f_x / 2 + lineOffset.x, startDraw.y + f_y / 2 + lineOffset.y);
  3301. tube.walk([this, &tube, lockedDDSD, &ld, lowestHeight, col, lineOffset](const auto& wi) {
  3302. auto draw = GetRenderTargetCoordinates(wi.pos, lowestHeight);
  3303. if (wi.pos == tube.getEndCoords())
  3304. {
  3305. // end coordinates are drawn as cross
  3306. LineDrawer startLD(lockedDDSD->lpSurface, bpp, lockedDDSD->dwWidth, lockedDDSD->dwHeight, lockedDDSD->lPitch);
  3307. ProjectedVec off(7, 4);
  3308. startLD.DrawLine(draw.x + off.x, draw.y + f_y / 2, draw.x + f_x - off.x, draw.y + f_y / 2, col);
  3309. startLD.DrawLine(draw.x + f_x / 2 - 1, draw.y + off.y, draw.x + f_x / 2 - 1, draw.y + f_y - off.y, col);
  3310. }
  3311. if (wi.pos == tube.getStartCoords())
  3312. {
  3313. // Start coordinates are drawn as cell
  3314. DrawCell(lockedDDSD->lpSurface, lockedDDSD->dwWidth, lockedDDSD->dwHeight, lockedDDSD->lPitch, draw.x, draw.y, 1, 1, col, true);
  3315. }
  3316. ld.LineTo(draw.x + f_x / 2 + lineOffset.x, draw.y + f_y / 2 + lineOffset.y, col);
  3317. return true;
  3318. });
  3319. }
  3320. MapCoords CIsoView::GetMapCoordinates(const ProjectedCoords& projCoords, bool bAllowAccessBehindCliffs, bool ignoreHideFlagsAndOutside) const
  3321. {
  3322. return theApp.m_Options.bFlat ? Map->ToMapCoords(projCoords) : Map->ToMapCoords3d(projCoords, bAllowAccessBehindCliffs, ignoreHideFlagsAndOutside);
  3323. }
  3324. MapCoords CIsoView::GetMapCoordinatesFromRenderTargetCoordinates(const ProjectedCoords& projCoords, bool bAllowAccessBehindCliffs, bool ignoreHideFlagsAndOutside) const
  3325. {
  3326. return GetMapCoordinates(projCoords + m_viewOffset, bAllowAccessBehindCliffs, ignoreHideFlagsAndOutside);
  3327. }
  3328. MapCoords CIsoView::GetMapCoordinatesFromClientCoordinates(const CPoint& clientPt, bool bAllowAccessBehindCliffs, bool ignoreHideFlagsAndOutside) const
  3329. {
  3330. return GetMapCoordinates(GetProjectedCoordinatesFromClientCoordinates(clientPt), bAllowAccessBehindCliffs, ignoreHideFlagsAndOutside);
  3331. }
  3332. ProjectedCoords CIsoView::GetProjectedCoordinatesFromClientCoordinates(const CPoint& clientPt) const
  3333. {
  3334. RECT r;
  3335. GetWindowRect(&r);
  3336. const auto viewOffsetWR = m_viewOffset + ProjectedVec(r.left, r.top);
  3337. const auto projCoords = ProjectedCoords(clientPt.x * m_viewScale.x, clientPt.y * m_viewScale.y) + viewOffsetWR;
  3338. return projCoords;
  3339. }
  3340. ProjectedCoords CIsoView::GetProjectedCoordinates(const MapCoords& mapCoords) const
  3341. {
  3342. return theApp.m_Options.bFlat ? Map->ProjectCoords(mapCoords) : Map->ProjectCoords3d(mapCoords);
  3343. }
  3344. ProjectedCoords CIsoView::GetProjectedCoordinates(const MapCoords& mapCoords, int mapZ) const
  3345. {
  3346. return Map->ProjectCoords3d(mapCoords, mapZ);
  3347. }
  3348. ProjectedCoords CIsoView::GetRenderTargetCoordinates(const MapCoords& mapCoords) const
  3349. {
  3350. // Draw coordinates are display coordinates
  3351. return GetProjectedCoordinates(mapCoords) - m_viewOffset;
  3352. }
  3353. ProjectedCoords CIsoView::GetRenderTargetCoordinates(const MapCoords& mapCoords, int mapZ) const
  3354. {
  3355. return GetProjectedCoordinates(mapCoords, mapZ) - m_viewOffset;
  3356. }
  3357. CPoint CIsoView::GetClientCoordinates(const MapCoords& mapCoords) const
  3358. {
  3359. RECT r;
  3360. GetWindowRect(&r);
  3361. const auto windowPos = ProjectedVec(r.left, r.top);
  3362. //const auto p = ScaleBackToFrontBuffer(GetRenderTargetCoordinates(mapCoords)) - windowPos;
  3363. const auto rtc = GetRenderTargetCoordinates(mapCoords);
  3364. const auto p = ((ProjectedCoords(rtc.x, rtc.y) - windowPos) / m_viewScale).convertT<std::int32_t>();
  3365. return CPoint(p.x, p.y);
  3366. }
  3367. CPoint CIsoView::GetClientCoordinatesFromWorld(const ProjectedCoords& projectedCoords) const
  3368. {
  3369. RECT r;
  3370. GetWindowRect(&r);
  3371. const auto windowPos = ProjectedVec(r.left, r.top);
  3372. //const auto p = ScaleBackToFrontBuffer(GetRenderTargetCoordinates(mapCoords)) - windowPos;
  3373. const auto rtc = projectedCoords - m_viewOffset;
  3374. const auto p = ((ProjectedCoords(rtc.x, rtc.y)) / m_viewScale).convertT<std::int32_t>();
  3375. return CPoint(p.x, p.y);
  3376. }
  3377. ProjectedCoords CIsoView::ScaleBackToFrontBuffer(const ProjectedCoords& backBufferCoords) const
  3378. {
  3379. RECT r;
  3380. GetWindowRect(&r);
  3381. const auto windowPos = ProjectedVec(r.left, r.top);
  3382. return ((ProjectedCoords(backBufferCoords.x, backBufferCoords.y) - windowPos) / m_viewScale).convertT<std::int32_t>() + windowPos;
  3383. }
  3384. void CIsoView::UpdateStatusBar(int x, int y)
  3385. {
  3386. CString statusbar;//=TranslateStringACP("Ready");
  3387. FIELDDATA m = *Map->GetFielddataAt(x + y * Map->GetIsoSize());
  3388. if (m.wGround == 0xFFFF) m.wGround = 0;
  3389. if (m.wGround < (*tiledata_count) && m.bSubTile < (*tiledata)[m.wGround].wTileCount)
  3390. {
  3391. statusbar = "Terrain type: 0x";
  3392. char c[50];
  3393. itoa((*tiledata)[m.wGround].tiles[m.bSubTile].bTerrainType, c, 16);
  3394. statusbar += c;
  3395. statusbar += ", height: ";
  3396. itoa(m.bHeight, c, 10);
  3397. statusbar += c;
  3398. statusbar += " / ";
  3399. }
  3400. if (Map->GetOverlayAt(x + y * Map->GetIsoSize()) != 0xFF)
  3401. {
  3402. char ov[50];
  3403. itoa(Map->GetOverlayAt(x + y * Map->GetIsoSize()), ov, 16);
  3404. int i;
  3405. CString name;
  3406. name = "0x";
  3407. name += ov;
  3408. for (i = 0;i < overlay_count;i++)
  3409. {
  3410. if (overlay_number[i] == Map->GetOverlayAt(x + y * Map->GetIsoSize()))
  3411. name = overlay_name[i];
  3412. }
  3413. itoa(Map->GetOverlayDataAt(x + y * Map->GetIsoSize()), ov, 16);
  3414. statusbar += GetLanguageStringACP("OvrlStatus");
  3415. statusbar += TranslateStringACP(name);
  3416. statusbar += ", OverlayData: 0x";
  3417. statusbar += ov;
  3418. }
  3419. STDOBJECTDATA sod;
  3420. sod.type = "";
  3421. int n = Map->GetStructureAt(x + y * Map->GetIsoSize());
  3422. int on = -1;
  3423. if (n >= 0)
  3424. {
  3425. Map->GetStdStructureData(n, &sod);
  3426. statusbar = GetLanguageStringACP("StructStatus");
  3427. on = n;
  3428. }
  3429. n = Map->GetUnitAt(x + y * Map->GetIsoSize());
  3430. if (n >= 0)
  3431. {
  3432. Map->GetStdUnitData(n, &sod);
  3433. statusbar = GetLanguageStringACP("UnitStatus");
  3434. on = n;
  3435. }
  3436. n = Map->GetAirAt(x + y * Map->GetIsoSize());
  3437. if (n >= 0)
  3438. {
  3439. Map->GetStdAircraftData(n, &sod);
  3440. statusbar = GetLanguageStringACP("AirStatus");
  3441. on = n;
  3442. }
  3443. n = Map->GetInfantryAt(x + y * Map->GetIsoSize());
  3444. if (n >= 0)
  3445. {
  3446. Map->GetStdInfantryData(n, &sod);
  3447. statusbar = GetLanguageStringACP("InfStatus");
  3448. on = n;
  3449. }
  3450. if (sod.type.GetLength() > 0)
  3451. {
  3452. char c[50];
  3453. itoa(on, c, 10);
  3454. statusbar += "ID ";
  3455. statusbar += c;
  3456. statusbar += ", ";
  3457. statusbar += TranslateStringACP(Map->GetUnitName(sod.type));
  3458. statusbar += " (";
  3459. statusbar += TranslateHouse(sod.house, TRUE);
  3460. statusbar += ", ";
  3461. statusbar += sod.type;
  3462. statusbar += ")";
  3463. }
  3464. /*
  3465. // activate this code to display information about the mappack!
  3466. statusbar="MAPPACK: ";
  3467. int i;
  3468. FIELDDATA td=Map->GetFielddataAt(x+y*Map->GetIsoSize());
  3469. char c[50];
  3470. itoa(td.wGround, c, 10);
  3471. statusbar+="tile: ";
  3472. statusbar+=c;
  3473. statusbar+=" ";
  3474. for(i=0;i<3;i++)
  3475. {
  3476. itoa(td.bMapData[i], c, 10);
  3477. statusbar+=c;
  3478. statusbar+=" ";
  3479. }
  3480. statusbar+=" height: ";
  3481. itoa(td.bHeight, c, 10);
  3482. statusbar+=c;
  3483. statusbar+=" ";
  3484. itoa(td.bMapData2[0],c,10);
  3485. statusbar+=c;*/
  3486. n = Map->GetCelltagAt(x + y * Map->GetIsoSize());
  3487. if (n >= 0)
  3488. {
  3489. CString type;
  3490. CString name;
  3491. DWORD pos;
  3492. Map->GetCelltagData(n, &type, &pos);
  3493. CIniFile& ini = Map->GetIniFile();
  3494. if (ini.sections["Tags"].values.find(type) != ini.sections["Tags"].values.end())
  3495. name = GetParam(ini.sections["Tags"].values[type], 1);
  3496. statusbar += GetLanguageStringACP("CellTagStatus");
  3497. statusbar += name;
  3498. statusbar += " (";
  3499. statusbar += type;
  3500. statusbar += ")";
  3501. }
  3502. if (AD.mode == ACTIONMODE_SETTILE)
  3503. {
  3504. statusbar = GetLanguageStringACP("TilePlaceStatus");
  3505. }
  3506. if (AD.mode == ACTIONMODE_COPY)
  3507. statusbar = GetLanguageStringACP("CopyHelp");
  3508. if (statusbar.GetLength() > 0)
  3509. SetError(statusbar);
  3510. }
  3511. void CIsoView::UpdateOverlayPictures(int id)
  3512. {
  3513. if (id < 0)
  3514. {
  3515. memset(ovrlpics, 0, max_ovrl_img * 0xFF * sizeof(LPDIRECTDRAWSURFACE4));
  3516. int i, e;
  3517. for (i = 0;i < 0xFF;i++)
  3518. {
  3519. for (e = 0;e < max_ovrl_img;e++)
  3520. {
  3521. /*PICDATA& p=GetOverlayPic(i, e);
  3522. if(p.pic!=NULL) ovrlpics[i][e]=&p;
  3523. else
  3524. ovrlpics[i][e]=NULL;*/
  3525. ovrlpics[i][e] = GetOverlayPic(i, e);
  3526. }
  3527. }
  3528. }
  3529. else
  3530. {
  3531. int e;
  3532. for (e = 0;e < max_ovrl_img;e++)
  3533. {
  3534. ovrlpics[id][e] = GetOverlayPic(id, e);
  3535. }
  3536. }
  3537. }
  3538. __forceinline void FixTileHeight(DWORD dwPos, int x, int y)
  3539. {
  3540. return; // we use CMapData::CreateSlopes() to fix slopes now
  3541. int oheight = Map->GetHeightAt(dwPos);
  3542. int isosize = Map->GetIsoSize();
  3543. char bHeightDiff[9];
  3544. int i, e;
  3545. for (i = -1;i < 2;i++)
  3546. {
  3547. for (e = -1;e < 2;e++)
  3548. {
  3549. if (x + i < 0 || y + e < 0 || x + i >= isosize || y + e >= isosize) bHeightDiff[i + 1 + (e + 1) * 3] = 0;
  3550. else
  3551. bHeightDiff[i + 1 + (e + 1) * 3] = oheight - Map->GetHeightAt(dwPos + i + e * isosize);
  3552. }
  3553. }
  3554. if (bHeightDiff[1] < 0 && bHeightDiff[7] < 0)
  3555. {
  3556. Map->SetHeightAt(dwPos, oheight + 1);
  3557. return;
  3558. }
  3559. if (bHeightDiff[3] < 0 && bHeightDiff[5] < 0)
  3560. {
  3561. Map->SetHeightAt(dwPos, oheight + 1);
  3562. return;
  3563. }
  3564. if (
  3565. (bHeightDiff[1] < 0 && bHeightDiff[6] < 0) ||
  3566. (bHeightDiff[1] < 0 && bHeightDiff[8] < 0) /*||
  3567. (bHeightDiff[3]<0 && bHeightDiff[2]<0) ||
  3568. (bHeightDiff[3]<0 && bHeightDiff[8]<0) ||
  3569. (bHeightDiff[5]<0 && bHeightDiff[0]<0) ||
  3570. (bHeightDiff[5]<0 && bHeightDiff[6]<0) ||
  3571. (bHeightDiff[7]<0 && bHeightDiff[0]<0) ||
  3572. (bHeightDiff[7]<0 && bHeightDiff[2]<0) */
  3573. )
  3574. {
  3575. Map->SetHeightAt(dwPos, oheight + 1);
  3576. return;
  3577. }
  3578. }
  3579. /*
  3580. ChangeTileHeight();
  3581. General routine for changing the height of a tile.
  3582. Warning: This routine calls itself if necessary, and therefore may be quite performance hungry!
  3583. */
  3584. void __fastcall CIsoView::ChangeTileHeight(DWORD dwPos, DWORD dwNewHeight, BOOL bNonMorpheableMove, BOOL bOnlyThisTile, BOOL bNoSlopes)
  3585. {
  3586. int isosize = Map->GetIsoSize();
  3587. int mapsize = isosize * isosize;
  3588. int mapwidth = Map->GetWidth();
  3589. int mapheight = Map->GetHeight();
  3590. int dwX = dwPos % isosize;
  3591. int dwY = dwPos / isosize;
  3592. //if(dwX==0 || dwY==0 || dwX+dwY<mapwidth || dwX+dwY>mapwidth+mapheight*2 || (dwY>mapwidth && dwX<dwY-mapwidth) || (dwX>mapwidth && dwY+mapwidth<dwX)) return;
  3593. //if( dwX<2|| dwY<2 || dwX+dwY<mapwidth+2 || dwX+dwY+2>mapwidth+mapheight*2 || (dwY+2>mapwidth && dwX-2<dwY-mapwidth) || (dwX+2>mapwidth && dwY+mapwidth-2<dwX)) return;
  3594. if (dwX < 1 || dwY < 1 || dwX + dwY<mapwidth + 1 || dwX + dwY>mapwidth + mapheight * 2 || (dwY + 1 > mapwidth && dwX - 1 < dwY - mapwidth) || (dwX + 1 > mapwidth && dwY + mapwidth - 1 < dwX)) return;
  3595. FIELDDATA orig_fd = *Map->GetFielddataAt(dwPos);
  3596. //if(bOnlyHeighten && dwNewHeight<orig_fd.bHeight) return;
  3597. if (orig_fd.wGround == 0xFFFF) orig_fd.wGround = 0;
  3598. int orig_ground = orig_fd.wGround;
  3599. if (orig_fd.bReserved) return;
  3600. if (dwX < m_funcRect.left) m_funcRect.left = dwX;
  3601. if (dwY < m_funcRect.top) m_funcRect.top = dwY;
  3602. if (dwX > m_funcRect.right) m_funcRect.right = dwX;
  3603. if (dwY > m_funcRect.bottom) m_funcRect.bottom = dwY;
  3604. BOOL bCliffNext = FALSE;
  3605. /*if(bOnlyHeighten)
  3606. {
  3607. bCliffNext=FALSE;
  3608. /*int i;
  3609. int e;
  3610. for(i=-1;i<2;i++)
  3611. {
  3612. for(e=-1;e<2;e++)
  3613. {
  3614. int pos=dwPos+i+(e)*isosize;
  3615. FIELDDATA fd=*Map->GetFielddataAt(pos);
  3616. if(fd.wGround==0xFFFF) fd.wGround=0;
  3617. if((*tiledata)[fd.wGround].wTileSet==cliffset || fd.bCliffHack)
  3618. {
  3619. bCliffNext=TRUE;
  3620. break;
  3621. }
  3622. }
  3623. if(bCliffNext) break;
  3624. }*//*
  3625. }*/
  3626. Map->SetReserved(dwPos, 1);
  3627. if (!(*tiledata)[orig_ground].bMorphable) bNonMorpheableMove = TRUE;
  3628. Map->SetHeightAt(dwPos, dwNewHeight);
  3629. int i, e;
  3630. for (i = -1;i < 2;i++)
  3631. {
  3632. for (e = -1;e < 2;e++)
  3633. {
  3634. int pos = dwPos + i + (e)*isosize;
  3635. FIELDDATA fd = *Map->GetFielddataAt(pos);
  3636. if (fd.wGround == 0xFFFF) fd.wGround = 0;
  3637. BOOL bAllowed = TRUE;
  3638. if (dwX == 0 && i == -1) bAllowed = FALSE;
  3639. else if (dwY == 0 && e == -1) bAllowed = FALSE;
  3640. else if (dwX == isosize - 1 && i == 1) bAllowed = FALSE;
  3641. else if (dwY == isosize - 1 && e == 1) bAllowed = FALSE;
  3642. if (bOnlyThisTile)
  3643. {
  3644. if (fd.wGround != orig_fd.wGround) bAllowed = FALSE; // was another tile
  3645. else
  3646. {
  3647. // we now need to check if it is really the same tile or just the same tile type (!)
  3648. int of = orig_fd.bSubTile;
  3649. int f = fd.bSubTile;
  3650. int width = (*tiledata)[orig_ground].cy;
  3651. int height = (*tiledata)[orig_ground].cx;
  3652. int ox = of / width;
  3653. int oy = of % width;
  3654. int x = f / width;
  3655. int y = f % width;
  3656. if (x - ox != i || y - oy != e) bAllowed = FALSE;
  3657. }
  3658. }
  3659. int ground = fd.wGround;
  3660. if (bAllowed && !fd.bReserved && pos > 0 && pos < mapsize)
  3661. {
  3662. BOOL bDestMorphable = (*tiledata)[fd.wGround].bMorphable;
  3663. TILEDATA destTile = (*tiledata)[fd.wGround];
  3664. TILEDATA sourceTile = (*tiledata)[orig_fd.wGround];
  3665. if (bAllowed && (!bNonMorpheableMove || bDestMorphable))
  3666. {
  3667. if (e == 1 && i == 1)
  3668. {
  3669. int leftGround = Map->GetFielddataAt(dwPos + 1)->wGround;
  3670. int rightGround = Map->GetFielddataAt(dwPos + isosize)->wGround;
  3671. if (leftGround == 0xFFFF) leftGround = 0;
  3672. if (rightGround == 0xFFFF) rightGround = 0;
  3673. if (!(*tiledata)[leftGround].bMorphable && !(*tiledata)[rightGround].bMorphable)
  3674. bAllowed = FALSE;
  3675. }
  3676. if (e == -1 && i == -1)
  3677. {
  3678. int leftGround = Map->GetFielddataAt(dwPos - 1)->wGround;
  3679. int rightGround = Map->GetFielddataAt(dwPos - isosize)->wGround;
  3680. if (leftGround == 0xFFFF) leftGround = 0;
  3681. if (rightGround == 0xFFFF) rightGround = 0;
  3682. if (!(*tiledata)[leftGround].bMorphable && !(*tiledata)[rightGround].bMorphable)
  3683. bAllowed = FALSE;
  3684. }
  3685. if (e == -1 && i == 1)
  3686. {
  3687. int leftGround = Map->GetFielddataAt(dwPos - 1)->wGround;
  3688. int rightGround = Map->GetFielddataAt(dwPos + isosize)->wGround;
  3689. if (leftGround == 0xFFFF) leftGround = 0;
  3690. if (rightGround == 0xFFFF) rightGround = 0;
  3691. if (!(*tiledata)[leftGround].bMorphable && !(*tiledata)[rightGround].bMorphable)
  3692. bAllowed = FALSE;
  3693. }
  3694. if (e == 1 && i == -1)
  3695. {
  3696. int leftGround = Map->GetFielddataAt(dwPos + 1)->wGround;
  3697. int rightGround = Map->GetFielddataAt(dwPos - isosize)->wGround;
  3698. if (leftGround == 0xFFFF) leftGround = 0;
  3699. if (rightGround == 0xFFFF) rightGround = 0;
  3700. if (!(*tiledata)[leftGround].bMorphable && !(*tiledata)[rightGround].bMorphable)
  3701. bAllowed = FALSE;
  3702. }
  3703. }
  3704. if (/*(*tiledata)[ground].bMorphable &&*/ bAllowed)
  3705. {
  3706. int need_diff = (*tiledata)[ground].tiles[fd.bSubTile].bZHeight - (*tiledata)[orig_ground].tiles[orig_fd.bSubTile].bZHeight;
  3707. //if(Map->GetHeightAt(pos)-dwNewHeight!=need_diff || !bNonMorpheableMove)
  3708. {
  3709. int diff = fd.bHeight - dwNewHeight;
  3710. /*
  3711. Activate this code to use the huge slopes
  3712. Removed because it did look worse than the normal slopes
  3713. */
  3714. /*
  3715. if(i && abs(i)==abs(e))
  3716. {
  3717. if(diff<-1) diff++;
  3718. if(diff>1) diff--;
  3719. }*/
  3720. if (!bNonMorpheableMove && bDestMorphable)
  3721. {
  3722. //if(!bOnlyHeighten)//!bCliffNext)
  3723. {
  3724. if (diff < -1)
  3725. ChangeTileHeight(pos, dwNewHeight - 1, bNonMorpheableMove, bOnlyThisTile, bNoSlopes);
  3726. if (diff > 1)
  3727. ChangeTileHeight(pos, dwNewHeight + 1, bNonMorpheableMove, bOnlyThisTile, bNoSlopes);
  3728. }
  3729. /*else
  3730. {
  3731. ChangeTileHeight(pos, dwNewHeight, bNonMorpheableMove, bOnlyThisTile, bOnlyHeighten);
  3732. }*/
  3733. }
  3734. else if (bNonMorpheableMove)
  3735. {
  3736. if (!bDestMorphable /*&& (*tiledata)[fd.wGround].wTileSet==(*tiledata)[orig_fd.wGround].wTileSet*/ /*&& need_diff!=fd.bHeight-orig_fd.bHeight*/)
  3737. {
  3738. if (destTile.tiles[fd.bSubTile].bTerrainType == sourceTile.tiles[orig_fd.bSubTile].bTerrainType || destTile.wTileSet == sourceTile.wTileSet)
  3739. {
  3740. ChangeTileHeight(pos, dwNewHeight + need_diff, TRUE, bOnlyThisTile, bNoSlopes);
  3741. }
  3742. }
  3743. else if (bDestMorphable /*&& need_diff!=fd.bHeight-orig_fd.bHeight*/)
  3744. {
  3745. //diff-=need_diff;
  3746. if ((sourceTile.cx > 1 && sourceTile.cy > 1 && (e < 0 && i < 0)) || ((sourceTile.cx < 2 || sourceTile.cy < 2) && (e > 0 && i > 0)))
  3747. {
  3748. ChangeTileHeight(pos, dwNewHeight, FALSE, bOnlyThisTile, bNoSlopes);
  3749. }
  3750. else
  3751. {
  3752. if (diff - need_diff > 0)
  3753. ChangeTileHeight(pos, dwNewHeight + need_diff, FALSE, bOnlyThisTile, bNoSlopes);
  3754. else if (diff - need_diff < 0)
  3755. ChangeTileHeight(pos, dwNewHeight + need_diff, FALSE, bOnlyThisTile, bNoSlopes);
  3756. }
  3757. }
  3758. }
  3759. }
  3760. }
  3761. }
  3762. }
  3763. }
  3764. /*for(i=-1;i<2;i++)
  3765. {
  3766. for(e=-1;e<2;e++)
  3767. {
  3768. FixTileHeight(dwPos+i+e*isosize, dwX+i, dwY+e);
  3769. }
  3770. }*/
  3771. if (!bNoSlopes)
  3772. {
  3773. for (i = -1;i < 2;i++)
  3774. {
  3775. for (e = -1;e < 2;e++)
  3776. {
  3777. int pos = dwPos + i + (e)*isosize;
  3778. if (pos > 0 && pos < mapsize)
  3779. Map->CreateSlopesAt(pos);
  3780. }
  3781. }
  3782. }
  3783. }
  3784. BOOL CIsoView::ReachableFrom(DWORD dwStart, DWORD dwEnd)
  3785. {
  3786. FIELDDATA orig_fd = *Map->GetFielddataAt(dwStart);
  3787. if (orig_fd.wGround == 0xFF) orig_fd.wGround = 0;
  3788. int orig_ground = orig_fd.wGround;
  3789. if (orig_fd.bReserved) return FALSE;
  3790. orig_fd.bReserved = 1;
  3791. if (dwStart == dwEnd) return TRUE;
  3792. int i, e;
  3793. for (i = -1;i < 2;i++)
  3794. {
  3795. for (e = -1;e < 2;e++)
  3796. {
  3797. int new_ground = orig_fd.wGround;
  3798. if (new_ground == 0xFFFF) new_ground = 0;
  3799. if (!(*tiledata)[new_ground].bMorphable && ReachableFrom(dwStart + i + e * Map->GetIsoSize(), dwEnd))
  3800. return TRUE;
  3801. }
  3802. }
  3803. return FALSE;
  3804. }
  3805. void CIsoView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  3806. {
  3807. CView::OnKeyUp(nChar, nRepCnt, nFlags);
  3808. }
  3809. void CIsoView::HideTileSet(DWORD dwTileSet)
  3810. {
  3811. int i;
  3812. for (i = 0;i < *tiledata_count;i++)
  3813. {
  3814. if ((*tiledata)[i].wTileSet == dwTileSet) (*tiledata)[i].bHide = TRUE;
  3815. }
  3816. }
  3817. void CIsoView::BlitBackbufferToHighRes()
  3818. {
  3819. // MW:
  3820. // the primary buffer and the (optional) high-res buffer cover the whole screen (Windows automatic high DPI scaling does not change this)
  3821. // the backbuffer also has the size of the whole screen, however we don't render to the whole screen
  3822. // we only render to the visible window rectangle (which IS affected by Windows' automatic DPI scaling features)
  3823. // Additionally, we have a user-controlled scale factor.
  3824. // If the user zooms in, we only render to a smaller part of the backbuffer and stretch it to the window rectangle (which may then again be stretched by Windows DPI if enabled in the Windows settings).
  3825. // the rectangle we render to has the same left/top border but a lower value for right/bottom.
  3826. //
  3827. // This is a simple scaling and also scales any text that has already been rendered to the backbuffer (which is why we're usually rendering text afterwards to the HighRes backbuffer).
  3828. // Altogether it'd probably be best to move from DirectDraw to Direct3D, support high DPI awareness and do the scaling right when initially drawing the map.
  3829. if (m_viewScale != Vec2<CSProjected, float>(1.0f, 1.0f) && lpdsBackHighRes)
  3830. {
  3831. // copy scene backbuffer to the high-res buffer that will receive text rendering
  3832. RECT dr;
  3833. GetWindowRect(&dr);
  3834. auto cr = GetScaledDisplayRect();
  3835. lpdsBackHighRes->Blt(&dr, lpdsBack, &cr, DDBLT_WAIT, 0);
  3836. }
  3837. else
  3838. {
  3839. // do nothing, backbuffer will receive additional text rendering as text doesn't have to be scaled
  3840. }
  3841. }
  3842. void CIsoView::FlipHighResBuffer()
  3843. {
  3844. if (m_viewScale != Vec2<CSProjected, float>(1.0f, 1.0f) && lpdsBackHighRes)
  3845. {
  3846. // This flip copies the high-res backbuffer to the front buffer
  3847. RECT dr;
  3848. GetWindowRect(&dr);
  3849. lpds->Blt(&dr, lpdsBackHighRes, &dr, DDBLT_WAIT, 0);
  3850. }
  3851. else
  3852. {
  3853. // copy scene backbuffer to the front buffer that will receive text/gdi rendering
  3854. RECT dr;
  3855. GetWindowRect(&dr);
  3856. auto cr = GetScaledDisplayRect();
  3857. lpds->Blt(&dr, lpdsBack, &cr, DDBLT_WAIT, 0);
  3858. }
  3859. }
  3860. void CIsoView::ShowAllTileSets()
  3861. {
  3862. int i;
  3863. for (i = 0;i < *tiledata_count;i++)
  3864. {
  3865. (*tiledata)[i].bHide = FALSE;
  3866. }
  3867. }
  3868. void CIsoView::PlaceCurrentObjectAt(int x, int y)
  3869. {
  3870. if (AD.mode == ACTIONMODE_RANDOMTERRAIN)
  3871. {
  3872. if (Map->GetTerrainAt(x + y * Map->GetIsoSize()) >= 0)
  3873. {
  3874. return;
  3875. }
  3876. CString s;
  3877. int n = rand() * rndterrainsrc.size() / RAND_MAX;
  3878. // safety checks...
  3879. if (n >= rndterrainsrc.size()) n = rndterrainsrc.size() - 1;
  3880. if (n < 0) n = 0;
  3881. s = rndterrainsrc[n];
  3882. Map->AddTerrain(s, x + y * Map->GetIsoSize());
  3883. return;
  3884. }
  3885. if (AD.type == 1) // ADD INFANTRY
  3886. {
  3887. if (Map->GetInfantryCountAt(x + y * Map->GetIsoSize()) >= SUBPOS_COUNT)
  3888. {
  3889. return;
  3890. }
  3891. Map->AddInfantry(NULL, AD.data_s, currentOwner, x + y * Map->GetIsoSize());
  3892. //RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  3893. }
  3894. else if (AD.type == 2) // add structure
  3895. {
  3896. int n = Map->GetStructureAt(x + y * Map->GetIsoSize());
  3897. if (n >= 0)
  3898. {
  3899. STDOBJECTDATA sod;
  3900. Map->GetStdStructureData(n, &sod);
  3901. if (strcmp(sod.type, "GAPAVE") != NULL)
  3902. {
  3903. //isMoving=FALSE;
  3904. return;
  3905. }
  3906. }
  3907. Map->AddStructure(NULL, AD.data_s, currentOwner, x + y * Map->GetIsoSize());
  3908. //RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  3909. }
  3910. else if (AD.type == 3) // add aircraft
  3911. {
  3912. if (Map->GetAirAt(x + y * Map->GetIsoSize()) >= 0)
  3913. {
  3914. return;
  3915. }
  3916. Map->AddAircraft(NULL, AD.data_s, currentOwner, x + y * Map->GetIsoSize());
  3917. //RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  3918. }
  3919. else if (AD.type == 4) // add vehicle
  3920. {
  3921. if (Map->GetUnitAt(x + y * Map->GetIsoSize()) >= 0)
  3922. {
  3923. return;
  3924. }
  3925. Map->AddUnit(NULL, AD.data_s, currentOwner, x + y * Map->GetIsoSize());
  3926. //RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  3927. }
  3928. else if (AD.type == 5) // add terrain
  3929. {
  3930. if (Map->GetTerrainAt(x + y * Map->GetIsoSize()) >= 0)
  3931. {
  3932. return;
  3933. }
  3934. Map->AddTerrain(AD.data_s, x + y * Map->GetIsoSize());
  3935. //RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  3936. }
  3937. else if (AD.type == 6)
  3938. {
  3939. // Overlay
  3940. DWORD dwPos = x + y * Map->GetIsoSize();
  3941. FIELDDATA m = *Map->GetFielddataAt(dwPos);
  3942. if (m.wGround == 0xFFFF) m.wGround = 0;
  3943. BYTE oldOverlay = Map->GetOverlayAt(dwPos);
  3944. BYTE oldOverlayData = Map->GetOverlayDataAt(dwPos);
  3945. if (AD.data == 1) // delete overlay
  3946. {
  3947. int gx, gy;
  3948. for (gx = x - AD.data2;gx <= x + AD.data2;gx++)
  3949. {
  3950. for (gy = y - AD.data2;gy <= y + AD.data2;gy++)
  3951. {
  3952. Map->SetOverlayDataAt(gx + gy * Map->GetIsoSize(), 0xFF);
  3953. Map->SetOverlayAt(gx + gy * Map->GetIsoSize(), 0xFF);
  3954. HandleTrail(gx - 1, gy - 1);
  3955. HandleTrail(gx + 1, gy - 1);
  3956. HandleTrail(gx - 1, gy + 1);
  3957. HandleTrail(gx + 1, gy + 1);
  3958. HandleTrail(gx - 0, gy - 1);
  3959. HandleTrail(gx + 0, gy + 1);
  3960. HandleTrail(gx - 1, gy + 0);
  3961. HandleTrail(gx + 1, gy + 0);
  3962. }
  3963. }
  3964. }
  3965. else if (AD.data == 2) // green tiberium mode
  3966. {
  3967. {
  3968. if (AD.data2 == 0)
  3969. {
  3970. int i, e;
  3971. for (i = 0;i < m_BrushSize_x;i++)
  3972. {
  3973. for (e = 0;e < m_BrushSize_y;e++)
  3974. {
  3975. int curground = Map->GetFielddataAt(dwPos + i + e * Map->GetIsoSize())->wGround;
  3976. if (curground == 0xFFFF) curground = 0;
  3977. if ((*tiledata)[curground].bAllowTiberium)
  3978. {
  3979. //srand( GetTickCount()+i+e*5 );
  3980. int v1 = ((float)rand() / (float)RAND_MAX) * 8.0f + 0x68;
  3981. int v2 = ((float)rand() / (float)RAND_MAX) * 8.0f + 1;
  3982. Map->SetOverlayAt(dwPos + i + e * Map->GetIsoSize(), v1);
  3983. Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), v2);
  3984. }
  3985. }
  3986. }
  3987. }
  3988. else if (AD.data2 == 10)
  3989. {
  3990. int i, e;
  3991. for (i = 0;i < m_BrushSize_x;i++)
  3992. {
  3993. for (e = 0;e < m_BrushSize_y;e++)
  3994. {
  3995. int curground = Map->GetFielddataAt(dwPos + i + e * Map->GetIsoSize())->wGround;
  3996. if (curground == 0xFFFF) curground = 0;
  3997. if ((*tiledata)[curground].bAllowTiberium)
  3998. {
  3999. Map->SetOverlayAt(dwPos + i + e * Map->GetIsoSize(), 0x70);
  4000. Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), 0x5);
  4001. }
  4002. }
  4003. }
  4004. }
  4005. else if (AD.data2 == 20)
  4006. {
  4007. int i, e;
  4008. for (i = 0;i < m_BrushSize_x;i++)
  4009. {
  4010. for (e = 0;e < m_BrushSize_y;e++)
  4011. {
  4012. int ovrl = Map->GetOverlayAt(dwPos + i + e * Map->GetIsoSize());
  4013. if (ovrl > 0x65 && ovrl < 0x72)
  4014. {
  4015. if (Map->GetOverlayDataAt(i + e * Map->GetIsoSize() + dwPos) < 9) Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), Map->GetOverlayDataAt(dwPos + i + e * Map->GetIsoSize()) + 1);
  4016. }
  4017. }
  4018. }
  4019. }
  4020. else if (AD.data2 == 21)
  4021. {
  4022. int i, e;
  4023. for (i = 0;i < m_BrushSize_x;i++)
  4024. {
  4025. for (e = 0;e < m_BrushSize_y;e++)
  4026. {
  4027. int ovrl = Map->GetOverlayAt(dwPos + i + e * Map->GetIsoSize());
  4028. if (ovrl > 0x65 && ovrl < 0x72)
  4029. {
  4030. if (Map->GetOverlayDataAt(dwPos + i + e * Map->GetIsoSize()) > 0) Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), Map->GetOverlayDataAt(dwPos + i + e * Map->GetIsoSize()) - 1);
  4031. }
  4032. }
  4033. }
  4034. }
  4035. }
  4036. }
  4037. else if (AD.data == 3) // blue tiberium mode
  4038. {
  4039. int o = 0x7f;
  4040. #ifdef RA2_MODE
  4041. o = 0x1e;
  4042. #endif
  4043. //if((*tiledata)[m.wGround].bAllowTiberium)
  4044. {
  4045. if (AD.data2 == 0)
  4046. {
  4047. int i, e;
  4048. for (i = 0;i < m_BrushSize_x;i++)
  4049. {
  4050. for (e = 0;e < m_BrushSize_y;e++)
  4051. {
  4052. int curground = Map->GetFielddataAt(dwPos + i + e * Map->GetIsoSize())->wGround;
  4053. if (curground == 0xFFFF) curground = 0;
  4054. if ((*tiledata)[curground].bAllowTiberium)
  4055. {
  4056. int v2 = ((float)rand() / (float)RAND_MAX) * 8 + 1;
  4057. Map->SetOverlayAt(dwPos + i + e * Map->GetIsoSize(), o);
  4058. Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), v2);
  4059. }
  4060. }
  4061. }
  4062. }
  4063. else if (AD.data2 == 10)
  4064. {
  4065. int i, e;
  4066. for (i = 0;i < m_BrushSize_x;i++)
  4067. {
  4068. for (e = 0;e < m_BrushSize_y;e++)
  4069. {
  4070. int curground = Map->GetFielddataAt(dwPos + i + e * Map->GetIsoSize())->wGround;
  4071. if (curground == 0xFFFF) curground = 0;
  4072. if ((*tiledata)[curground].bAllowTiberium)
  4073. {
  4074. Map->SetOverlayAt(dwPos + i + e * Map->GetIsoSize(), o);
  4075. Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), 0x5);
  4076. }
  4077. }
  4078. }
  4079. }
  4080. else if (AD.data2 == 20)
  4081. {
  4082. int i, e;
  4083. for (i = 0;i < m_BrushSize_x;i++)
  4084. {
  4085. for (e = 0;e < m_BrushSize_y;e++)
  4086. {
  4087. int ovrl = Map->GetOverlayAt(dwPos + i + e * Map->GetIsoSize());
  4088. if (ovrl == o)
  4089. {
  4090. if (Map->GetOverlayDataAt(dwPos + i + e * Map->GetIsoSize()) < 9) Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), Map->GetOverlayDataAt(dwPos + i + e * Map->GetIsoSize()) + 1);
  4091. }
  4092. }
  4093. }
  4094. }
  4095. else if (AD.data2 == 21)
  4096. {
  4097. int i, e;
  4098. for (i = 0;i < m_BrushSize_x;i++)
  4099. {
  4100. for (e = 0;e < m_BrushSize_y;e++)
  4101. {
  4102. int ovrl = Map->GetOverlayAt(dwPos + i + e * Map->GetIsoSize());
  4103. if (ovrl == o)
  4104. {
  4105. if (Map->GetOverlayDataAt(dwPos + i + e * Map->GetIsoSize()) > 0) Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), Map->GetOverlayDataAt(dwPos + i + e * Map->GetIsoSize()) - 1);
  4106. }
  4107. }
  4108. }
  4109. }
  4110. }
  4111. }
  4112. else if (AD.data == 4) // veinhole stuff mode
  4113. {
  4114. if (AD.data2 == 0) // Set veinhole!
  4115. {
  4116. int gx, gy;
  4117. for (gx = x - 1;gx <= x + 1;gx++)
  4118. {
  4119. for (gy = y - 1;gy <= y + 1;gy++)
  4120. {
  4121. Map->SetOverlayAt(gx + gy * Map->GetIsoSize(), OVRL_VEINHOLEBORDER);
  4122. Map->SetOverlayDataAt(gx + gy * Map->GetIsoSize(), 0x0);
  4123. }
  4124. }
  4125. Map->SetOverlayAt(dwPos, OVRL_VEINHOLE);
  4126. Map->SetOverlayDataAt(dwPos, 0x0);
  4127. Map->SetHeightAt(dwPos, Map->GetHeightAt(dwPos) - 1);
  4128. }
  4129. else if (AD.data2 == 1) // set veins
  4130. {
  4131. Map->SetOverlayAt(dwPos, OVRL_VEINS);
  4132. Map->SetOverlayDataAt(dwPos, 0x30);
  4133. }
  4134. }
  4135. else if (AD.data == 30) // any overlay
  4136. {
  4137. Map->SetOverlayAt(dwPos, AD.data2);
  4138. Map->SetOverlayDataAt(dwPos, 0);
  4139. int i;
  4140. for (i = 0;i < overlay_count;i++)
  4141. {
  4142. if (overlay_number[i] == AD.data2)
  4143. {
  4144. if (overlay_trail[i])
  4145. {
  4146. // handle trail stuff!
  4147. HandleTrail(x, y);
  4148. }
  4149. }
  4150. }
  4151. }
  4152. else if (AD.data == 33)
  4153. {
  4154. int i, e;
  4155. for (i = 0;i < m_BrushSize_x;i++)
  4156. {
  4157. for (e = 0;e < m_BrushSize_y;e++)
  4158. {
  4159. Map->SetOverlayAt(dwPos + i + e * Map->GetIsoSize(), AD.data2);
  4160. Map->SetOverlayDataAt(dwPos + i + e * Map->GetIsoSize(), AD.data3);
  4161. }
  4162. }
  4163. }
  4164. else if (AD.data == 31)
  4165. {
  4166. Map->SetOverlayAt(dwPos, AD.data2);
  4167. }
  4168. else if (AD.data == 32)
  4169. {
  4170. Map->SetOverlayDataAt(dwPos, AD.data2);
  4171. }
  4172. // RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW);
  4173. }
  4174. else if (AD.type == 7)
  4175. {
  4176. // set owner!
  4177. BOOL bchanged = FALSE;
  4178. int t = Map->GetStructureAt(x + y * Map->GetIsoSize());
  4179. if (t >= 0)
  4180. {
  4181. STRUCTURE structure;
  4182. Map->GetStructureData(t, &structure);
  4183. Map->DeleteStructure(t);
  4184. structure.house = AD.data_s;
  4185. Map->AddStructure(&structure);
  4186. bchanged = TRUE;
  4187. }
  4188. t = Map->GetUnitAt(x + y * Map->GetIsoSize());
  4189. if (t >= 0)
  4190. {
  4191. UNIT unit;
  4192. Map->GetUnitData(t, &unit);
  4193. Map->DeleteUnit(t);
  4194. unit.house = AD.data_s;
  4195. Map->AddUnit(&unit);
  4196. bchanged = TRUE;
  4197. }
  4198. t = Map->GetAirAt(x + y * Map->GetIsoSize());
  4199. if (t >= 0)
  4200. {
  4201. AIRCRAFT aircraft;
  4202. Map->GetAircraftData(t, &aircraft);
  4203. Map->DeleteAircraft(t);
  4204. aircraft.house = AD.data_s;
  4205. Map->AddAircraft(&aircraft);
  4206. bchanged = TRUE;
  4207. }
  4208. int z;
  4209. for (z = 0;z < SUBPOS_COUNT;z++)
  4210. {
  4211. t = Map->GetInfantryAt(x + y * Map->GetIsoSize(), z);
  4212. if (t >= 0)
  4213. {
  4214. INFANTRY infantry;
  4215. Map->GetInfantryData(t, &infantry);
  4216. Map->DeleteInfantry(t);
  4217. infantry.house = AD.data_s;
  4218. Map->AddInfantry(&infantry);
  4219. bchanged = TRUE;
  4220. }
  4221. }
  4222. if (bchanged)
  4223. {
  4224. //RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW);
  4225. }
  4226. }
  4227. #ifdef SMUDGE_SUPP
  4228. else if (AD.type == 8) // add smudge
  4229. {
  4230. if (Map->GetFielddataAt(x + y * Map->GetIsoSize())->smudge >= 0)
  4231. {
  4232. return;
  4233. }
  4234. SMUDGE s;
  4235. s.type = AD.data_s;
  4236. s.x = x;
  4237. s.y = y;
  4238. s.deleted = 0;
  4239. Map->AddSmudge(&s);
  4240. //RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  4241. }
  4242. #endif
  4243. }
  4244. void CIsoView::OnTimer(UINT nIDEvent)
  4245. {
  4246. // theApp.m_loading->FreeAll();
  4247. // theApp.m_loading->InitPics();
  4248. last_succeeded_operation = 1000000;
  4249. if (nIDEvent == 11)
  4250. {
  4251. // BUGSEARCH
  4252. //if(b_IsLoading) return;
  4253. //
  4254. m_viewOffset += ProjectedVec((cur_x_mouse - rclick_x) / 2, (cur_y_mouse - rclick_y) / 2);
  4255. SetScroll(m_viewOffset.x, m_viewOffset.y);
  4256. InvalidateRect(NULL, FALSE);
  4257. }
  4258. else
  4259. {
  4260. errstream << "Timer calls InitTMPs()" << endl;
  4261. errstream.flush();
  4262. theApp.m_loading->InitTMPs();
  4263. CView::OnTimer(nIDEvent);
  4264. KillTimer(nIDEvent);
  4265. b_IsLoading = FALSE;
  4266. RedrawWindow();
  4267. }
  4268. }
  4269. void CIsoView::FillArea(DWORD dwX, DWORD dwY, DWORD dwID, BYTE bSubTile)
  4270. {
  4271. if ((*tiledata)[dwID].cx != 1 || (*tiledata)[dwID].cy != 1)
  4272. {
  4273. MessageBox("You can only use 1x1 tiles to fill areas.");
  4274. return;
  4275. }
  4276. FIELDDATA* f = Map->GetFielddataAt(dwX + dwY * Map->GetIsoSize());
  4277. f->bReserved = TRUE;
  4278. int mapwidth, mapheight;
  4279. mapwidth = Map->GetWidth();
  4280. mapheight = Map->GetHeight();
  4281. int i, e;
  4282. for (i = -1;i < 2;i++)
  4283. {
  4284. for (e = -1;e < 2;e++)
  4285. {
  4286. if (abs(i) == abs(e)) continue;
  4287. int cur_x, cur_y;
  4288. cur_x = dwX + i;
  4289. cur_y = dwY + e;
  4290. if (cur_x < 1 || cur_y < 1 || cur_x + cur_y<mapwidth + 1 || cur_x + cur_y>mapwidth + mapheight * 2 || (cur_y + 1 > mapwidth && cur_x - 1 < cur_y - mapwidth) || (cur_x + 1 > mapwidth && cur_y + mapwidth - 1 < cur_x)) continue;
  4291. FIELDDATA* f2 = Map->GetFielddataAt(cur_x + cur_y * Map->GetIsoSize());
  4292. if (f2->bReserved) continue;
  4293. if (f2->wGround != dwID && f2->wGround == f->wGround && f2->bSubTile == f->bSubTile)
  4294. {
  4295. FillArea(cur_x, cur_y, dwID, bSubTile);
  4296. }
  4297. }
  4298. }
  4299. f->wGround = dwID;
  4300. f->bSubTile = bSubTile;
  4301. }
  4302. void CIsoView::AutoLevel()
  4303. {
  4304. Map->TakeSnapshot();
  4305. int mapsize = Map->GetIsoSize() * Map->GetIsoSize();
  4306. int mapedge = Map->GetIsoSize();
  4307. if (mapsize == 0) return;
  4308. BOOL* bChanged;
  4309. bChanged = new(BOOL[mapsize]);
  4310. memset(bChanged, 0, mapsize);
  4311. int iCliffStart = -1; //, iSlopeSetStart = -1;
  4312. int i;
  4313. for (i = 0;i < *tiledata_count;i++)
  4314. {
  4315. if ((*tiledata)[i].wTileSet == cliffset)
  4316. {
  4317. iCliffStart = i;
  4318. break;
  4319. }
  4320. }
  4321. if (iCliffStart < 0)
  4322. return;
  4323. /*for (i = 0;i<*tiledata_count;i++)
  4324. {
  4325. if((*tiledata)[i].wTileSet==slopesetpiecesset)
  4326. {
  4327. iSlopeSetStart=i;
  4328. break;
  4329. }
  4330. }*/
  4331. /*int count=atoi(g_data.sections["SlopeSetPiecesDirections"].values["Count"]);
  4332. BYTE* bXLeftSearch=new(BYTE[count]);
  4333. BYTE* bXRightSearch=new(BYTE[count]);
  4334. BYTE* bYTopSearch=new(BYTE[count]);
  4335. BYTE* bYBottomSearch=new(BYTE[count]);
  4336. for(i=0;i<count;i++)
  4337. {
  4338. char c[50];
  4339. itoa(i,c,10);
  4340. CString s=*g_data.sections["SlopeSetPiecesDirections"].GetValue(i);
  4341. if(s=="Right_1") { bXLeftSearch=0; bXRightSearch=1; b
  4342. else if(s=="Left_1") bDirections[i]=1;
  4343. else if(s=="Bottom_1") bDirections[i]=2;
  4344. else if(s=="Top_1") bDirections[i]=3;
  4345. else if(s=="Right_2") bDirections[i]=4;
  4346. else if(s=="Left_2") bDirections[i]=5;
  4347. else if(s=="Bottom_2") bDirections[i]=6;
  4348. else if(s=="Top_2") bDirections[i]=7;
  4349. }*/
  4350. for (i = 0;i < mapsize;i++)
  4351. {
  4352. FIELDDATA* f1 = Map->GetFielddataAt(i);
  4353. int o_ground = f1->wGround;
  4354. if (o_ground == 0xFFFF) o_ground = 0;
  4355. int o_width = (*tiledata)[o_ground].cx;
  4356. int o_height = (*tiledata)[o_ground].cy;
  4357. int ox, oy;
  4358. ox = i % mapedge;
  4359. oy = i / mapedge;
  4360. int x, y;
  4361. for (x = -1;x < 2;x++)
  4362. {
  4363. for (y = -1;y < 2;y++)
  4364. {
  4365. if (x == -1 && y == -1) continue;
  4366. if (x == 1 && y == 1) continue;
  4367. if (x == 1 && y == -1) continue;
  4368. if (x == -1 && y == 1) continue;
  4369. int count = 0;
  4370. int p, k;
  4371. int heights[32][32];
  4372. memset(heights, 0, 32 * 32 * sizeof(int));
  4373. for (p = 0;p < o_width;p++)
  4374. {
  4375. for (k = 0;k < o_height;k++)
  4376. {
  4377. count++;
  4378. heights[p][k] = (*tiledata)[o_ground].tiles[p + k * o_width].bZHeight;
  4379. }
  4380. }
  4381. if (o_ground < 8 + iCliffStart || o_ground>13 + iCliffStart)
  4382. {
  4383. if (count < 4 || count>4)
  4384. {
  4385. if (x < 0 || y < 0) continue;
  4386. }
  4387. if (heights[0][0] && !heights[1][1])
  4388. {
  4389. if (heights[1][0] && heights[0][1])
  4390. {
  4391. if (x < 0 || y < 0) continue;
  4392. }
  4393. }
  4394. if (heights[0][0] && heights[1][1])
  4395. {
  4396. if (x < 0 || y>0) continue;
  4397. }
  4398. if (!heights[0][0] && heights[1][0] && heights[0][1] && heights[1][1])
  4399. {
  4400. if (x < 0 || y < 0) continue;
  4401. }
  4402. }
  4403. else
  4404. {
  4405. if (x > 0 || y > 0) continue;
  4406. }
  4407. if (x + ox > mapedge || x + ox<0 || y + oy>mapedge || y + oy < 0)
  4408. continue;
  4409. FIELDDATA* cur_f = Map->GetFielddataAt(i + x + y * mapedge);
  4410. int cur_ground = cur_f->wGround;
  4411. if (cur_ground == 0xFFFF) cur_ground = 0;
  4412. int cur_set;
  4413. if ((*tiledata)[cur_ground].wTileSet != (*tiledata)[o_ground].wTileSet)
  4414. {
  4415. if (((*tiledata)[o_ground].wTileSet == cliffset || (*tiledata)[o_ground].wTileSet == slopesetpiecesset) && (*tiledata)[cur_ground].bMorphable)
  4416. {
  4417. int height_diff = f1->bHeight - cur_f->bHeight;
  4418. if (o_ground >= 8 + iCliffStart && o_ground <= 13 + iCliffStart && (*tiledata)[o_ground].tiles[cur_f->bSubTile].bZHeight == 0) height_diff += 4;
  4419. int need_diff = height_diff;//(*tiledata)[o_ground].tiles[f1->bSubTile].bZHeight-(*tiledata)[cur_ground].tiles[cur_f->bSubTile].bZHeight;
  4420. //if((*tiledata)[o_ground].tiles[f1->bSubTile].bZ
  4421. if (abs(height_diff) > 1)
  4422. {
  4423. //ChangeTileHeight(i+x+y*mapedge,f1->bHeight,FALSE, FALSE);
  4424. int height = f1->bHeight;
  4425. if (o_ground >= 8 + iCliffStart && o_ground <= 13 + iCliffStart && (*tiledata)[o_ground].tiles[cur_f->bSubTile].bZHeight == 0) height = f1->bHeight + 4;
  4426. Map->SetHeightAt(i + x + y * mapedge, height);
  4427. bChanged[i + x + y * mapedge] = TRUE;
  4428. }
  4429. else if (height_diff)
  4430. Map->CreateSlopesAt(i + x + y * mapedge);
  4431. //bChanged[i+x+y*mapedge]=TRUE;
  4432. }
  4433. }
  4434. }
  4435. }
  4436. }
  4437. for (i = 0;i < mapsize;i++)
  4438. {
  4439. if (bChanged[i])
  4440. {
  4441. int e;
  4442. for (e = 0;e < Map->GetIsoSize() * Map->GetIsoSize();e++)
  4443. Map->SetReserved(e, 0);
  4444. ChangeTileHeight(i, Map->GetHeightAt(i), FALSE, FALSE);
  4445. }
  4446. }
  4447. /* delete[] bXSearch;
  4448. delete[] bYSearch;*/
  4449. if (bChanged) delete[] bChanged;
  4450. RedrawWindow();
  4451. Map->TakeSnapshot();
  4452. Map->Undo();
  4453. }
  4454. inline void ToIso3d_NoAccessCheck(int* x, int* y)
  4455. {
  4456. int cx = *x, cy = *y;
  4457. ToIso(&cx, &cy);
  4458. int i, e = 0;
  4459. for (i = 15;i >= 0;i--)
  4460. {
  4461. for (e = 0;e < 3;e++)
  4462. {
  4463. int a;
  4464. int m, n;
  4465. int px, py;
  4466. m = cx + i;
  4467. n = cy + i;
  4468. if (e == 1) m -= 1;
  4469. if (e == 2) n -= 1;
  4470. px = m;
  4471. py = n;
  4472. if (m >= 0 && n >= 0 && m < Map->GetIsoSize() && n < Map->GetIsoSize())
  4473. {
  4474. FIELDDATA mfd = *Map->GetFielddataAt(px + py * Map->GetIsoSize());
  4475. int ground = mfd.wGround;
  4476. if (ground == 0xFFFF) ground = 0;
  4477. //if(mfd.bHide==FALSE && !(*tiledata)[ground].bHide)
  4478. {
  4479. ToPhys3d(&m, &n);
  4480. // now m and n hold the pixel coordinates for the current field...
  4481. // we now need to check if cx and cy are in this field
  4482. //if(*x >= m && *x<= m+f_x && *y>=n && *y<=n+f_y)
  4483. {
  4484. int dx = *x - m;
  4485. int dy = *y - n - f_y / 2;//-f_y/2;
  4486. int dx1 = dx;
  4487. int dy1 = dy;
  4488. dx = ((float)dy1) / ((float)f_y) - ((float)dx1) / ((float)f_x) + 1.0f;//+ 1 + (float)0.5 +1;
  4489. dy = ((float)dx1) / ((float)f_x) + ((float)dy1) / ((float)f_y) + 0.0f;//- 1-(float)0.5 +1;
  4490. if (((dx == 0 && dy == 0) || (!bAllowAccessBehindCliffs && *y - n > f_y)))
  4491. {
  4492. *x = px - 0;
  4493. *y = py + 0;
  4494. return;
  4495. }
  4496. }
  4497. }
  4498. }
  4499. }
  4500. }
  4501. /*
  4502. for(i=15;i>=0;i--)
  4503. {
  4504. for(e=0;e<3;e++)
  4505. {
  4506. int a;
  4507. int m,n;
  4508. int px,py;
  4509. m=cx+i;
  4510. n=cy+i;
  4511. if(e==1) m-=1;
  4512. if(e==2) n-=1;
  4513. px=m;
  4514. py=n;
  4515. if(m>=0 && n>=0 && m< Map->GetIsoSize() && n<Map->GetIsoSize())
  4516. {
  4517. ToPhys3d(&m, &n);
  4518. // just find at least one tile if possible...
  4519. if(*x>m && *y>n)
  4520. {
  4521. *x=px;
  4522. *y=py;
  4523. return;
  4524. }
  4525. }
  4526. }
  4527. }*/
  4528. *x = cx;//-1;
  4529. *y = cy;//-1;
  4530. }
  4531. void CIsoView::DrawMap()
  4532. {
  4533. const CMapData* const Map = ::Map;
  4534. if (bNoDraw) return;
  4535. if (bCancelDraw)
  4536. {
  4537. bCancelDraw = FALSE;
  4538. return;
  4539. }
  4540. last_succeeded_operation = 100;
  4541. if (lpds == NULL || b_IsLoading || tiledata == NULL || (*tiledata) == NULL || (*tiledata_count == 0)) return; // just to make sure...
  4542. if (lpds->IsLost() != DD_OK)
  4543. {
  4544. // we lost our surfaces, we need to reinitialize directdraw and all associated objects
  4545. ReInitializeDDraw();
  4546. return;
  4547. }
  4548. if (Map->GetIsoSize() == 0) return;
  4549. auto startTime = std::chrono::steady_clock::now();
  4550. // draw a white background
  4551. DDBLTFX fx;
  4552. memset(&fx, 0, sizeof(DDBLTFX));
  4553. fx.dwSize = sizeof(DDBLTFX);
  4554. fx.dwFillColor = RGB(255, 255, 255);
  4555. lpdsBack->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &fx);
  4556. // get the window rect
  4557. RECT r = GetScaledDisplayRect();
  4558. // the code here draws the coordinate system
  4559. int i;
  4560. // now, we draw all the objects
  4561. int left, right, top, bottom;
  4562. {
  4563. RECT cr;
  4564. GetClientRect(&cr);
  4565. auto topLeft = GetMapCoordinatesFromClientCoordinates(CPoint(0, 0), false, true);
  4566. auto topRight = GetMapCoordinatesFromClientCoordinates(CPoint(cr.right, 0), false, true);
  4567. auto bottomLeft = GetMapCoordinatesFromClientCoordinates(CPoint(0, cr.bottom), false, true);
  4568. auto bottomRight = GetMapCoordinatesFromClientCoordinates(CPoint(cr.right, cr.bottom), false, true);
  4569. left = min(topLeft.x, topRight.x);
  4570. top = min(topLeft.y, topRight.y);
  4571. right = max(bottomLeft.x, bottomRight.x);
  4572. bottom = max(bottomLeft.y, bottomRight.y);
  4573. }
  4574. // some large buildings may be out of reach:
  4575. left -= 2;
  4576. top -= 2;
  4577. right += 7;
  4578. bottom += 7;
  4579. // validate the coordinates
  4580. if (left < 0) left = 0;
  4581. if (bottom >= Map->GetIsoSize() || bottom < top) bottom = Map->GetIsoSize();
  4582. if (right >= Map->GetIsoSize() || right < left) right = Map->GetIsoSize();
  4583. if (top < 0) top = 0;
  4584. BOOL bMarbleHeight = TRUE;
  4585. //if(Map->GetTheater()==THEATER4 || Map->GetTheater()==THEATER3) bMarbleHeight=FALSE;
  4586. // Now left, right, top & bottom contain the needed values
  4587. DWORD MM_heightstart = tilesets_start[atoi((*tiles).sections["General"].values["HeightBase"])];
  4588. // now draw everything
  4589. int u, v, z;
  4590. int mapwidth, mapheight;
  4591. mapwidth = Map->GetWidth();
  4592. mapheight = Map->GetHeight();
  4593. DDSURFACEDESC2 ddsd;
  4594. ZeroMemory(&ddsd, sizeof(ddsd));
  4595. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  4596. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  4597. lpdsBack->GetSurfaceDesc(&ddsd);
  4598. #ifdef NOSURFACES
  4599. lpdsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
  4600. #endif
  4601. // we render texts and waypoints last as they should be always visible anyway and because text rendering is currently done using GDI -> getting a DC for every text is too slow nowadays
  4602. m_texts_to_render.clear();
  4603. m_waypoints_to_render.clear();
  4604. for (u = left;u < right;u++)
  4605. {
  4606. for (v = top;v < bottom;v++)
  4607. {
  4608. const MapCoords mapCoords(u, v);
  4609. if (bCancelDraw)
  4610. {
  4611. bCancelDraw = FALSE;
  4612. }
  4613. if (u < 1 || v < 1 || u + v<mapwidth + 1 || u + v>mapwidth + mapheight * 2 || (v + 1 > mapwidth && u - 1 < v - mapwidth) || (u + 1 > mapwidth && v + mapwidth - 1 < u))
  4614. continue;
  4615. FIELDDATA m = *Map->GetFielddataAt(mapCoords);
  4616. const auto drawCoords = GetRenderTargetCoordinates(mapCoords);
  4617. // draw terrain
  4618. if (m.wGround >= (*tiledata_count))
  4619. m.wGround = 0;
  4620. DWORD dwOrigGround = m.wGround;
  4621. if (theApp.m_Options.bMarbleMadness)
  4622. {
  4623. if ((*tiledata)[m.wGround].wMarbleGround != 0xFFFF)
  4624. {
  4625. m.wGround = (*tiledata)[m.wGround].wMarbleGround;
  4626. }
  4627. else if (bMarbleHeight)
  4628. {
  4629. //drawy+=f_y*m.bHeight;
  4630. m.wGround = MM_heightstart + m.bHeight;
  4631. m.bSubTile = 0;
  4632. }
  4633. }
  4634. if (!m.bRedrawTerrain)
  4635. {
  4636. TILEDATA* td = &(*tiledata)[m.wGround];
  4637. if (td->bReplacementCount)
  4638. {
  4639. if (m.bRNDImage > 0)
  4640. {
  4641. m.bRNDImage <= td->bReplacementCount ? td = &td->lpReplacements[m.bRNDImage - 1] : td = &td->lpReplacements[td->bReplacementCount - 1];
  4642. }
  4643. }
  4644. if (m.bSubTile < td->wTileCount && td->tiles[m.bSubTile].pic != NULL)
  4645. {
  4646. const SUBTILE& st = td->tiles[m.bSubTile];
  4647. const auto stDrawCoords = drawCoords + st.drawOffset();
  4648. if (!m.bHide && (*tiledata)[dwOrigGround].bHide == FALSE)
  4649. {
  4650. #ifndef NOSURFACES
  4651. Blit(st.pic, stDrawCoords.x, stDrawCoords.y, st.wWidth, st.wHeight);
  4652. #else
  4653. BlitTerrain(ddsd.lpSurface, stDrawCoords.x, stDrawCoords.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, st);
  4654. #endif
  4655. }
  4656. else // draw soemthing representing the tile
  4657. {
  4658. #ifndef NOSURFACES
  4659. DrawCell(stDrawCoords.x, stDrawCoords.y, 1, 1, RGB(0, 140, 0), FALSE, FALSE);
  4660. #else
  4661. BlitTerrainHalfTransp(ddsd.lpSurface, stDrawCoords.x, stDrawCoords.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, st);
  4662. #endif
  4663. }
  4664. }
  4665. }
  4666. }
  4667. }
  4668. for (u = left;u < right;u++)
  4669. {
  4670. for (v = top;v < bottom;v++)
  4671. {
  4672. const MapCoords mapCoords(u, v);
  4673. if (bCancelDraw)
  4674. {
  4675. bCancelDraw = FALSE;
  4676. }
  4677. if (u < 1 || v < 1 || u + v<mapwidth + 1 || u + v>mapwidth + mapheight * 2 || (v + 1 > mapwidth && u - 1 < v - mapwidth) || (u + 1 > mapwidth && v + mapwidth - 1 < u))
  4678. continue;
  4679. FIELDDATA m = *Map->GetFielddataAt(mapCoords); // copy
  4680. const auto drawCoords = GetRenderTargetCoordinates(mapCoords);
  4681. if (m.wGround == 0xFFFF)
  4682. m.wGround = 0;
  4683. DWORD dwOrigGround = m.wGround;
  4684. if (theApp.m_Options.bMarbleMadness)
  4685. {
  4686. if ((*tiledata)[m.wGround].wMarbleGround != 0xFFFF)
  4687. {
  4688. m.wGround = (*tiledata)[m.wGround].wMarbleGround;
  4689. }
  4690. else if (bMarbleHeight)
  4691. {
  4692. //y+=f_y*m.bHeight;
  4693. m.wGround = MM_heightstart + m.bHeight;
  4694. m.bSubTile = 0;
  4695. }
  4696. }
  4697. if (m.bRedrawTerrain)
  4698. {
  4699. // draw cliff again to hide buildings behind
  4700. if (m.wGround < *tiledata_count)
  4701. {
  4702. TILEDATA* td = &(*tiledata)[m.wGround];
  4703. if (td->bReplacementCount)
  4704. {
  4705. if (m.bRNDImage > 0)
  4706. {
  4707. m.bRNDImage <= td->bReplacementCount ? td = &td->lpReplacements[m.bRNDImage - 1] : td = &td->lpReplacements[td->bReplacementCount - 1];
  4708. }
  4709. }
  4710. if (m.bSubTile < td->wTileCount && td->tiles[m.bSubTile].pic != NULL)
  4711. {
  4712. const SUBTILE& st = td->tiles[m.bSubTile];
  4713. const auto stDrawCoords = drawCoords + st.drawOffset();
  4714. if (!m.bHide && (*tiledata)[dwOrigGround].bHide == FALSE)
  4715. {
  4716. #ifndef NOSURFACES
  4717. Blit(st.pic, stDrawCoords.x, stDrawCoords.y, st.wWidth, st.wHeight);
  4718. #else
  4719. BlitTerrain(ddsd.lpSurface, stDrawCoords.x, stDrawCoords.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, st);
  4720. if (st.anim)
  4721. {
  4722. const auto animDrawCoords = drawCoords + ProjectedVec(f_x / 2 - st.anim->wMaxWidth / 2, f_y / 2 - st.anim->wMaxHeight / 2) + st.anim->drawOffset();
  4723. BlitPic(ddsd.lpSurface, animDrawCoords.x, animDrawCoords.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, *st.anim);
  4724. }
  4725. #endif
  4726. }
  4727. else // draw soemthing representing the tile
  4728. {
  4729. #ifndef NOSURFACES
  4730. DrawCell(stDrawCoords.x, stDrawCoords.y, 1, 1, RGB(0, 140, 0), FALSE, FALSE);
  4731. #else
  4732. BlitTerrainHalfTransp(ddsd.lpSurface, stDrawCoords.x, stDrawCoords.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, st);
  4733. #endif
  4734. }
  4735. }
  4736. }
  4737. }
  4738. // draw terrain animation (tunnel tops, waterfalls)
  4739. // tunnel tops might be repainted later so that units do not appear on top - this probably could be done in CLoading so that instead of a back tile a front tile is responsible for drawing the animation
  4740. {
  4741. if (m.wGround < *tiledata_count)
  4742. {
  4743. TILEDATA* td = &(*tiledata)[m.wGround];
  4744. if (m.bSubTile < td->wTileCount)
  4745. {
  4746. const SUBTILE& st = td->tiles[m.bSubTile];
  4747. if (!m.bHide && (*tiledata)[dwOrigGround].bHide == FALSE && st.anim)
  4748. {
  4749. #ifndef NOSURFACES
  4750. #else
  4751. const auto animDrawCoords = drawCoords + ProjectedVec(f_x / 2 - st.anim->wMaxWidth / 2, f_y / 2 - st.anim->wMaxHeight / 2) + st.anim->drawOffset();
  4752. BlitPic(ddsd.lpSurface, animDrawCoords.x, animDrawCoords.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, *st.anim);
  4753. #endif
  4754. }
  4755. }
  4756. }
  4757. }
  4758. // draw overlay
  4759. if (m.overlay != 0xFF)
  4760. {
  4761. PICDATA pic;
  4762. pic.pic = NULL;
  4763. if (ovrlpics[m.overlay][m.overlaydata] != NULL)
  4764. {
  4765. pic = *ovrlpics[m.overlay][m.overlaydata];
  4766. }
  4767. if (pic.pic == NULL)
  4768. {
  4769. if (!pic.bTried)
  4770. {
  4771. SetError("Loading graphics");
  4772. theApp.m_loading->LoadOverlayGraphic(*rules.sections["OverlayTypes"].GetValue(m.overlay), m.overlay);
  4773. UpdateOverlayPictures(m.overlay);
  4774. if (ovrlpics[m.overlay][m.overlaydata] != NULL)
  4775. pic = *ovrlpics[m.overlay][m.overlaydata];
  4776. }
  4777. if (pic.pic == NULL)
  4778. {
  4779. if (!(m.overlay >= 0x4a && m.overlay <= 0x65) && !(m.overlay >= 0xcd && m.overlay <= 0xec))
  4780. {
  4781. char cd[50];
  4782. cd[0] = '0';
  4783. cd[1] = 'x';
  4784. itoa(m.overlay, cd + 2, 16);
  4785. m_texts_to_render.push_back({ cd, drawCoords.x + f_x / 2, drawCoords.y + f_y / 2, RGB(0,0,0), false, true, true});
  4786. // TextOut(drawx,drawy, cd, RGB(0,0,0));
  4787. }
  4788. }
  4789. }
  4790. if (pic.pic != NULL)
  4791. {
  4792. ProjectedVec offset(f_x / 2 - pic.wMaxWidth / 2, -pic.wMaxHeight / 2);
  4793. if (m.overlay == OVRL_VEINHOLE) // veinhole, big, special case
  4794. {
  4795. offset.y -= f_y * 3 / 2;
  4796. }
  4797. else if (isBigBridge(m.overlay)) // bridge special case
  4798. {
  4799. // drawy-=f_y;
  4800. if (m.overlaydata >= 0x09 && m.overlaydata <= 0x11)
  4801. {
  4802. offset.y -= f_y / 2;
  4803. }
  4804. offset.x -= 1; // hmm... strange, but this is needed
  4805. }
  4806. else if (isTrack(m.overlay))
  4807. offset.y += f_y / 2;
  4808. if (m.overlay >= 0x4a && m.overlay <= 0x65) offset.y += f_y / 2;
  4809. if (m.overlay >= 0xcd && m.overlay <= 0xec) offset.y += f_y / 2;
  4810. const auto drawCoordsOvrl = drawCoords + offset;
  4811. #ifndef NOSURFACES
  4812. Blit(pic.pic, drawCoordsOvrl.x, drawCoordsOvrl.y);
  4813. #else
  4814. #ifdef RA2_MODE
  4815. BlitPic(ddsd.lpSurface, drawCoordsOvrl.x, drawCoordsOvrl.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic);
  4816. #endif
  4817. #ifdef TS_MODE
  4818. if (!isGreenTiberium(m.overlay) && !(m.overlay == 0x7f)) // no tib
  4819. BlitPic(ddsd.lpSurface, drawCoordsOvrl.x, drawCoordsOvrl.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic);
  4820. else if (m.overlay == 0x7f) // blue tib
  4821. {
  4822. int n = RGB(200, 0, 0);
  4823. BlitPic(ddsd.lpSurface, drawCoordsOvrl.x, drawCoordsOvrl.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic, &n);
  4824. }
  4825. else
  4826. {
  4827. int n = RGB(0, 200, 0);
  4828. BlitPic(ddsd.lpSurface, drawCoordsOvrl.x, drawCoordsOvrl.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic, &n);
  4829. }
  4830. #endif
  4831. #endif
  4832. }
  4833. }
  4834. if (m.structure != -1)
  4835. {
  4836. last_succeeded_operation = 10101;
  4837. // for structures we need to check if they weren´t drawn earlier
  4838. // (every field that this building achieves has this building as .structure)
  4839. if (Map->GetStructureAt(mapCoords - MapVec(-1, 0)) != m.structure && Map->GetStructureAt(mapCoords - MapVec(0, -1)) != m.structure)
  4840. {
  4841. STRUCTUREPAINT objp;
  4842. Map->GetStructurePaint(m.structure, &objp);
  4843. const auto drawCoordsBld = GetRenderTargetCoordinates(MapCoords(objp.x, objp.y));
  4844. int id = m.structuretype;
  4845. int w = 1, h = 1;
  4846. PICDATA pic;
  4847. if (id > -1 && id < 0x0F00)
  4848. {
  4849. w = buildinginfo[id].w;
  4850. h = buildinginfo[id].h;
  4851. int dir = objp.direction / 32;
  4852. // MW April 13th 2001: fix for building direction
  4853. dir = (7 - dir) % 8;
  4854. pic = buildinginfo[id].pic[dir];
  4855. if (pic.pic == NULL) pic = buildinginfo[id].pic[0];
  4856. }
  4857. #ifndef NOSURFACES
  4858. DrawCell(drawCoordsBld.x, drawCoordsBld.y, w, h, colorref_conv[objp.col]);
  4859. #else
  4860. // MW 07/19/01: Paint cell if user chose so...
  4861. if (theApp.m_Options.bShowCells)
  4862. {
  4863. DrawCell(ddsd.lpSurface, ddsd.dwWidth, ddsd.dwHeight, ddsd.lPitch, drawCoordsBld.x, drawCoordsBld.y, w, h, colorref_conv[objp.col]);
  4864. }
  4865. #endif
  4866. if (pic.pic == NULL)
  4867. {
  4868. if (!missingimages[objp.type])
  4869. {
  4870. SetError("Loading graphics");
  4871. theApp.m_loading->LoadUnitGraphic(objp.type);
  4872. ::Map->UpdateBuildingInfo(objp.type);
  4873. int dir = (7 - objp.direction / 32) % 8;
  4874. pic = buildinginfo[id].pic[dir];
  4875. if (pic.pic == NULL) pic = buildinginfo[id].pic[0];
  4876. }
  4877. if (pic.pic == NULL)
  4878. {
  4879. #ifndef NOSURFACES
  4880. Blit(pics["HOUSE"].pic, drawCoordsBld.x, drawCoordsBld.y - 19); // draw a ugly house
  4881. #endif
  4882. missingimages[objp.type] = TRUE;
  4883. }
  4884. }
  4885. if (pic.pic) // picture
  4886. {
  4887. // it was that easy! just center on top end!!!
  4888. const auto drawCoordsBldShp = drawCoordsBld + ProjectedVec(f_x / 2 - pic.wMaxWidth / 2, -pic.wMaxHeight / 2);
  4889. #ifndef NOSURFACES
  4890. Blit(pic.pic, drawCoordsBldShp.x, drawCoordsBldShp.y, pic.wMaxWidth, pic.wMaxHeight);
  4891. #else
  4892. BlitPic(ddsd.lpSurface, drawCoordsBldShp.x, drawCoordsBldShp.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic, &colorref_conv[objp.col]);
  4893. #endif
  4894. for (int upgrade = 0; upgrade < objp.upradecount; ++upgrade)
  4895. {
  4896. const auto& upg = upgrade == 0 ? objp.upgrade1 : (upgrade == 1 ? objp.upgrade2 : objp.upgrade3);
  4897. if (upg.GetLength() == 0)
  4898. continue;
  4899. PICDATA pic;
  4900. int dir = (7 - objp.direction / 32) % 8;
  4901. pic = pics[GetUnitPictureFilename(upg, dir)];
  4902. if (!missingimages[upg] && pic.pic == NULL)
  4903. {
  4904. SetError("Loading graphics");
  4905. theApp.m_loading->LoadUnitGraphic(upg);
  4906. ::Map->UpdateBuildingInfo(upg);
  4907. pic = pics[GetUnitPictureFilename(upg, dir)];
  4908. if (pic.pic == NULL) missingimages[upg] = TRUE;
  4909. }
  4910. if (pic.pic != NULL)
  4911. {
  4912. static const CString LocLookup[3][2] = { {"PowerUp1LocXX", "PowerUp1LocYY"}, {"PowerUp2LocXX", "PowerUp2LocYY"}, {"PowerUp3LocXX", "PowerUp3LocYY"} };
  4913. const auto drawCoordsPowerUp = drawCoordsBldShp + ProjectedVec(
  4914. atoi(art.sections[objp.type].values[LocLookup[upgrade][0]]),
  4915. atoi(art.sections[objp.type].values[LocLookup[upgrade][1]])
  4916. );
  4917. // py-=atoi(art.sections[obj.type].values["PowerUp1LocZZ"]);
  4918. #ifndef NOSURFACES
  4919. Blit(pic.pic, drawCoordsPowerUp.x, drawCoordsPowerUp.y);
  4920. #else
  4921. BlitPic(ddsd.lpSurface, drawCoordsPowerUp.x, drawCoordsPowerUp.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic, &colorref_conv[objp.col]);
  4922. #endif
  4923. }
  4924. }
  4925. }
  4926. }
  4927. }
  4928. if (m.node.type > -1)
  4929. {
  4930. last_succeeded_operation = 10102;
  4931. CString house = m.node.house;
  4932. CString tmp;
  4933. if (Map->GetNodeAt(mapCoords + MapVec(1, 0), tmp) != m.node.index && Map->GetNodeAt(mapCoords + MapVec(0, 1), tmp) != m.node.index)
  4934. {
  4935. const auto drawCoordsBld = GetRenderTargetCoordinates(mapCoords - MapVec(buildinginfo[m.node.type].h - 1, buildinginfo[m.node.type].w - 1));
  4936. COLORREF c;
  4937. c = GetColor(house);
  4938. int id = m.node.type;
  4939. int w = 1, h = 1;
  4940. PICDATA pic;
  4941. if (id > -1 && id < 0x0F00)
  4942. {
  4943. w = buildinginfo[id].w;
  4944. h = buildinginfo[id].h;
  4945. pic = buildinginfo[id].pic[0];
  4946. }
  4947. //#ifndef NOSURFACES
  4948. #ifdef NOSURFACES
  4949. if (m.structure >= 0) // only paint cell if we have a structure preplaced, as we have a half transparent image
  4950. {
  4951. #endif
  4952. // place it 2 pixels lower so that user can see the dotted lines even if the building itself has the cells drawn
  4953. DrawCell(ddsd.lpSurface, ddsd.dwWidth, ddsd.dwHeight, ddsd.lPitch, drawCoordsBld.x, drawCoordsBld.y + 3, w, h, colorref_conv[c], true);
  4954. #ifdef NOSURFACES
  4955. }
  4956. #endif
  4957. //#endif
  4958. if (pic.pic == NULL)
  4959. {
  4960. if (!missingimages[*rules.sections["BuildingTypes"].GetValue(m.node.type)])
  4961. {
  4962. SetError("Loading graphics");
  4963. theApp.m_loading->LoadUnitGraphic(*rules.sections["BuildingTypes"].GetValue(m.node.type));
  4964. ::Map->UpdateBuildingInfo(*rules.sections["BuildingTypes"].GetValue(m.node.type));
  4965. pic = buildinginfo[id].pic[0];
  4966. }
  4967. if (pic.pic == NULL);
  4968. {
  4969. #ifndef NOSURFACES
  4970. Blit(pics["HOUSE"].pic, drawCoordsBld.x, drawCoordsBld.y - 19);
  4971. #endif
  4972. missingimages[*rules.sections["BuildingTypes"].GetValue(m.node.type)] = TRUE;
  4973. }
  4974. }
  4975. if (pic.pic) // picture
  4976. {
  4977. const auto drawCoordsBldShp = drawCoordsBld + ProjectedVec(f_x / 2 - pic.wMaxWidth / 2, -pic.wMaxHeight / 2);
  4978. #ifndef NOSURFACES
  4979. Blit(pic.pic, drawCoordsBldShp.x, drawCoordsBldShp.y);
  4980. #else
  4981. BlitPicHalfTransp(ddsd.lpSurface, drawCoordsBldShp.x, drawCoordsBldShp.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic, &colorref_conv[c]);
  4982. #endif
  4983. }
  4984. }
  4985. }
  4986. if (m.unit != -1)
  4987. {
  4988. UNIT obj;
  4989. Map->GetUnitData(m.unit, &obj);
  4990. COLORREF c = GetColor(obj.house);
  4991. CString lpPicFile = GetUnitPictureFilename(obj.type, atoi(obj.direction) / 32);
  4992. #ifndef NOSURFACES
  4993. DrawCell(drawCoords.x, drawCoords.y, 1, 1, c);
  4994. #endif
  4995. PICDATA p = pics[lpPicFile];
  4996. if (p.pic == NULL || lpPicFile.GetLength() == 0)
  4997. {
  4998. if (!missingimages[obj.type])
  4999. {
  5000. SetError("Loading graphics");
  5001. theApp.m_loading->LoadUnitGraphic(obj.type);
  5002. lpPicFile = GetUnitPictureFilename(obj.type, atoi(obj.direction) / 32);
  5003. p = pics[lpPicFile];
  5004. }
  5005. if (p.pic == NULL)
  5006. {
  5007. #ifndef NOSURFACES
  5008. Blit(pics["TANK"].pic, drawCoords.x, drawCoords.y);
  5009. // TextOut(drawx+f_x/4,drawy+f_y/4, obj.type,c);
  5010. m_texts_to_render.push_back({ obj.type, drawCoords.x + f_x / 4, drawCoords.y + f_y / 4, m_color_converter->GetColor(c)});
  5011. #endif
  5012. missingimages[obj.type] = TRUE;
  5013. }
  5014. }
  5015. if (p.pic)// we have a picture!
  5016. {
  5017. const auto drawCoordsOffset = (p.bType == PICDATA_TYPE_BMP) ? ProjectedVec((f_y / 4) + p.x, (f_y - p.wHeight) + p.y) - p.drawOffset() :
  5018. (p.bType == PICDATA_TYPE_SHP) ? ProjectedVec(f_x / 2 - (p.wMaxWidth / 2), f_y / 2 - (p.wMaxHeight / 2)) : ProjectedVec(f_x / 2, f_y / 2) + p.drawOffset();
  5019. auto drawCoordsUnit = drawCoords + drawCoordsOffset;
  5020. #ifndef NOSURFACES
  5021. Blit(p.pic, drawCoordsUnit.x, drawCoordsUnit.y);
  5022. #else
  5023. BlitPic(ddsd.lpSurface, drawCoordsUnit.x, drawCoordsUnit.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, p, &colorref_conv[c]);
  5024. #endif
  5025. }
  5026. }
  5027. if (m.aircraft != -1)
  5028. {
  5029. last_succeeded_operation = 10102;
  5030. AIRCRAFT obj;
  5031. Map->GetAircraftData(m.aircraft, &obj);
  5032. COLORREF c = GetColor(obj.house);
  5033. CString lpPicFile = GetUnitPictureFilename(obj.type, atoi(obj.direction) / 32);
  5034. #ifndef NOSURFACES
  5035. DrawCell(drawCoords.x, drawCoords.y, 1, 1, c);
  5036. #endif
  5037. PICDATA p = pics[lpPicFile];
  5038. if (p.pic == NULL)
  5039. {
  5040. if (!missingimages[obj.type])
  5041. {
  5042. SetError("Loading graphics");
  5043. theApp.m_loading->LoadUnitGraphic(obj.type);
  5044. p = pics[lpPicFile];
  5045. }
  5046. if (p.pic == NULL)
  5047. {
  5048. #ifndef NOSURFACES
  5049. Blit(pics["TANK"].pic, drawCoords.x, drawCoords.y);
  5050. //TextOut(drawx+f_x/4,drawy+f_y/4, obj.type,c);
  5051. m_texts_to_render.push_back({ obj.type, drawCoords.x + f_x / 4, drawCoords.y + f_y / 4, m_color_converter->GetColor(c) });
  5052. #endif
  5053. missingimages[obj.type] = TRUE;
  5054. }
  5055. }
  5056. if (p.pic)// we have a picture!
  5057. {
  5058. const auto drawCoordsOffset = (p.bType == PICDATA_TYPE_BMP) ? ProjectedVec(f_x / 2 - p.wWidth / 2, f_y - p.wHeight) - p.drawOffset() :
  5059. (p.bType == PICDATA_TYPE_SHP) ? ProjectedVec(f_x / 2 - (p.wMaxWidth / 2), f_y / 2 - (p.wMaxHeight / 2)) : ProjectedVec(f_x / 2, f_y / 2) + p.drawOffset();
  5060. auto drawCoordsAir = drawCoords + drawCoordsOffset;
  5061. #ifndef NOSURFACES
  5062. Blit(p.pic, drawCoordsAir.x, drawCoordsAir.y);
  5063. #else
  5064. BlitPic(ddsd.lpSurface, drawCoordsAir.x, drawCoordsAir.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, p, &colorref_conv[c]);
  5065. #endif
  5066. }
  5067. }
  5068. int ic;
  5069. for (ic = 0;ic < SUBPOS_COUNT;ic++)
  5070. if (m.infantry[ic] != -1)
  5071. {
  5072. last_succeeded_operation = 10103;
  5073. //errstream << "GetInfantryData()" << endl;
  5074. //errstream.flush();
  5075. INFANTRY obj;
  5076. Map->GetInfantryData(m.infantry[ic], &obj);
  5077. //errstream << "Done " << (LPCSTR)obj.type << endl;
  5078. //errstream.flush();
  5079. COLORREF c = GetColor(obj.house);
  5080. int dir = (7 - atoi(obj.direction) / 32) % 8;
  5081. CString lpPicFile = GetUnitPictureFilename(obj.type, dir);
  5082. #ifndef NOSURFACES
  5083. DrawCell(drawCoords.x, drawCoords.y, 1, 1, c);
  5084. #endif
  5085. static const ProjectedVec subPosLookup[5] = { ProjectedVec(0, -f_y / 4), ProjectedVec(f_x / 4 , 0), ProjectedVec(-f_x / 4, 0), ProjectedVec(0, f_y / 4), ProjectedVec()};
  5086. auto drawCoordsInf = drawCoords + subPosLookup[ic > 4 ? 4 : ic];
  5087. PICDATA p = pics[lpPicFile];
  5088. if (p.pic == NULL)
  5089. {
  5090. if (!missingimages[obj.type])
  5091. {
  5092. SetError("Loading graphics");
  5093. theApp.m_loading->LoadUnitGraphic(obj.type);
  5094. p = pics[lpPicFile];
  5095. }
  5096. if (p.pic == NULL)
  5097. {
  5098. #ifndef NOSURFACES
  5099. Blit(pics["MAN"].pic, drawCoordsInf.x, drawCoordsInf.y);
  5100. // TextOut(drawx+f_x/4,drawy+f_y/4, obj.type,c);
  5101. m_texts_to_render.push_back({ obj.type, drawCoordsInf.x + f_x / 4, drawCoordsInf.y + f_y / 4, RGB(0,0,0) });
  5102. #endif
  5103. missingimages[obj.type] = TRUE;
  5104. }
  5105. }
  5106. if (p.pic)// we have a picture!
  5107. {
  5108. auto drawCoordsInfShp = drawCoordsInf + ProjectedVec(f_x / 2 - (p.wMaxWidth / 2), f_y / 2 - (p.wMaxHeight / 2));
  5109. #ifndef NOSURFACES
  5110. Blit(p.pic, drawCoordsInfShp.x, drawCoordsInfShp.y, p.wWidth, p.wHeight);
  5111. #else
  5112. BlitPic(ddsd.lpSurface, drawCoordsInfShp.x, drawCoordsInfShp.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, p, &colorref_conv[c]);
  5113. #endif
  5114. }
  5115. }
  5116. if (m.terrain != -1)
  5117. {
  5118. last_succeeded_operation = 10104;
  5119. int id = m.terraintype;
  5120. int w = 1, h = 1;
  5121. PICDATA pic;
  5122. if (id > -1 && id < 0x0F00)
  5123. {
  5124. w = treeinfo[id].w;
  5125. h = treeinfo[id].h;
  5126. pic = treeinfo[id].pic;
  5127. }
  5128. //CString lpPicFile=GetUnitPictureFilename(type, 0);
  5129. if (pic.pic == NULL)
  5130. {
  5131. CString type;
  5132. Map->GetTerrainData(m.terrain, &type);
  5133. if (missingimages.find(type) == missingimages.end())
  5134. {
  5135. SetError("Loading graphics");
  5136. theApp.m_loading->LoadUnitGraphic(type);
  5137. ::Map->UpdateTreeInfo(type);
  5138. pic = treeinfo[id].pic;
  5139. }
  5140. if (pic.pic == NULL)
  5141. {
  5142. #ifndef NOSURFACES
  5143. Blit(pics["TREE"].pic, drawCoords.x, drawCoords.y - 19);
  5144. #endif
  5145. missingimages[type] = TRUE;
  5146. }
  5147. }
  5148. if (pic.pic);
  5149. {
  5150. auto drawCoordsTerrain = drawCoords + ProjectedVec(f_x / 2 - (pic.wMaxWidth / 2), f_y / 2 - 3 - (pic.wMaxHeight / 2));
  5151. #ifndef NOSURFACES
  5152. Blit(pic.pic, drawCoordsTerrain.x, drawCoordsTerrain.y);
  5153. #else
  5154. BlitPic(ddsd.lpSurface, drawCoordsTerrain.x, drawCoordsTerrain.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic);
  5155. #endif
  5156. }
  5157. }
  5158. #ifdef SMUDGE_SUPP
  5159. if (m.smudge != -1)
  5160. {
  5161. last_succeeded_operation = 10104;
  5162. int id = m.smudgetype;
  5163. PICDATA pic;
  5164. if (id > -1 && id < 0x0F00)
  5165. {
  5166. pic = smudgeinfo[id].pic;
  5167. }
  5168. if (pic.pic == NULL)
  5169. {
  5170. SMUDGE data;
  5171. CString& type = data.type;
  5172. Map->GetSmudgeData(m.smudge, &data);
  5173. if (missingimages.find(type) == missingimages.end())
  5174. {
  5175. SetError("Loading graphics");
  5176. theApp.m_loading->LoadUnitGraphic(type);
  5177. ::Map->UpdateSmudgeInfo(type);
  5178. pic = smudgeinfo[id].pic;
  5179. }
  5180. if (pic.pic == NULL)
  5181. {
  5182. #ifndef NOSURFACES
  5183. // Blit(pics["TREE"].pic,drawCoords.x,drawCoords.y-19);
  5184. #endif
  5185. missingimages[type] = TRUE;
  5186. }
  5187. }
  5188. if (pic.pic)
  5189. {
  5190. auto drawCoordsSmudge = drawCoords + ProjectedVec(f_x / 2 - (pic.wMaxWidth / 2), /*f_y / 2 - 3*/ - (pic.wMaxHeight / 2));
  5191. #ifndef NOSURFACES
  5192. Blit(pic.pic, drawCoordsSmudge.x, drawCoordsSmudge.y);
  5193. #else
  5194. BlitPic(ddsd.lpSurface, drawCoordsSmudge.x, drawCoordsSmudge.y, r.left, r.top, ddsd.lPitch, r.right, r.bottom, pic);
  5195. #endif
  5196. }
  5197. }
  5198. #endif
  5199. if (m.celltag != -1)
  5200. {
  5201. #ifdef NOSURFACES
  5202. lpdsBack->Unlock(NULL);
  5203. #endif
  5204. Blit((LPDIRECTDRAWSURFACE4)pics["CELLTAG"].pic, drawCoords.x - 1, drawCoords.y - 1);
  5205. #ifdef NOSURFACES
  5206. lpdsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
  5207. #endif
  5208. }
  5209. if (m.waypoint != -1)
  5210. {
  5211. DWORD dwPos;
  5212. CString ID;
  5213. Map->GetWaypointData(m.waypoint, &ID, &dwPos);
  5214. #ifdef NOSURFACES
  5215. lpdsBack->Unlock(NULL);
  5216. #endif
  5217. // move the graphic and text into place
  5218. #ifdef RA2_MODE
  5219. int image_fudge_x = 4;
  5220. int image_fudge_y = -20;
  5221. int text_fudge_x = 12;
  5222. int text_fudge_y = -24;
  5223. #else
  5224. int image_fudge_x = 4;
  5225. int image_fudge_y = -15;
  5226. int text_fudge_x = 9;
  5227. int text_fudge_y = -17;
  5228. #endif
  5229. const ProjectedVec waypointImageOffset(image_fudge_x, image_fudge_y);
  5230. const ProjectedVec waypointTextOffset((f_x / 2) + text_fudge_x, (f_y / 2) + text_fudge_y);
  5231. #ifdef RA2_MODE
  5232. bool useFont9 = false;
  5233. #else
  5234. bool useFont9 = true;
  5235. #endif
  5236. const auto waypointImageCoords = ProjectedCoords({ drawCoords.x, drawCoords.y }) + waypointImageOffset;
  5237. const auto waypointTextCoords = ProjectedCoords({ drawCoords.x, drawCoords.y }) + waypointTextOffset;
  5238. m_waypoints_to_render.push_back({ waypointImageCoords.x, waypointImageCoords.y });
  5239. m_texts_to_render.push_back({ ID.GetString(), waypointTextCoords.x, waypointTextCoords.y, RGB(0,0,255), false, useFont9, true});
  5240. #ifdef NOSURFACES
  5241. lpdsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
  5242. #endif
  5243. }
  5244. }
  5245. }
  5246. for (const auto& tube : Map->GetTubes())
  5247. {
  5248. DrawTube(*tube, &ddsd);
  5249. }
  5250. #ifdef NOSURFACES
  5251. lpdsBack->Unlock(NULL);
  5252. #endif
  5253. // delayed waypoint rendering
  5254. for (const auto& wp : m_waypoints_to_render)
  5255. {
  5256. Blit((LPDIRECTDRAWSURFACE4)pics["FLAG"].pic, wp.drawx, wp.drawy);
  5257. }
  5258. // map tool rendering
  5259. if (AD.mode == ACTIONMODE_MAPTOOL)
  5260. {
  5261. if (AD.tool)
  5262. AD.tool->render();
  5263. }
  5264. lpdsTemp->Blt(NULL, lpdsBack, NULL, 0, 0); // lpdsTemp always holds the scene drawn above, unscaled to the window
  5265. if (m_cellCursor != MapCoords(-1, -1))
  5266. {
  5267. SurfaceLocker locker(lpdsBack);
  5268. auto desc = locker.ensure_locked();
  5269. if (desc)
  5270. DrawCellCursor(m_cellCursor, *desc);
  5271. }
  5272. auto renderDuration = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - startTime); // not including text output, ReleaseDC, waitForVerticalBlank etc below
  5273. if (bDrawStats)
  5274. {
  5275. if (theApp.m_Options.bShowStats)
  5276. {
  5277. auto systemStats = std::format("ms: {0} Left: {1} Top: {2} Right: {3} Bottom: {4}", renderDuration.count(), left, top, right, bottom);
  5278. m_texts_to_render.push_back({ systemStats.c_str(), r.left + 10, r.top + 10 + (-m_fontDefaultHeight) * 3 / 2, RGB(0,0,0), true });
  5279. }
  5280. auto moneyStr = std::format("Credits on map: {0}", Map->GetMoneyOnMap());
  5281. m_texts_to_render.push_back({ moneyStr.c_str(), r.left + 10, r.top + 10, RGB(0,0,0), true });
  5282. }
  5283. if (rscroll)
  5284. {
  5285. const auto& sc = pics["SCROLLCURSOR"];
  5286. Blit((LPDIRECTDRAWSURFACE4)sc.pic, rclick_x * m_viewScale.x + r.left - sc.wWidth / 2, rclick_y * m_viewScale.y + r.top - sc.wHeight / 2);
  5287. }
  5288. BlitBackbufferToHighRes(); // lpdsBackHighRes contains the same graphic, but scaled to the whole window
  5289. RenderUIOverlay();
  5290. if (theApp.m_Options.bVSync)
  5291. dd->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
  5292. FlipHighResBuffer();
  5293. last_succeeded_operation = 10100;
  5294. }
  5295. void CIsoView::RenderUIOverlay()
  5296. {
  5297. if (!m_textDefault)
  5298. updateFontScaled();
  5299. LPDIRECTDRAWSURFACE4 dds = lpdsBack;
  5300. bool useHighRes = false;
  5301. if (m_viewScale != Vec2<CSProjected, float>(1.0f, 1.0f) && lpdsBackHighRes)
  5302. {
  5303. dds = lpdsBackHighRes;
  5304. useHighRes = true;
  5305. }
  5306. DDSURFACEDESC2 ddsd;
  5307. ZeroMemory(&ddsd, sizeof(ddsd));
  5308. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  5309. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  5310. dds->GetSurfaceDesc(&ddsd);
  5311. dds->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
  5312. LineDrawer d(ddsd.lpSurface, bpp, ddsd.dwWidth, ddsd.dwHeight, ddsd.lPitch);
  5313. int lr, lt, ll, lb;
  5314. ll = Map->GetWidth();
  5315. lt = 1;
  5316. lr = Map->GetHeight();
  5317. lb = Map->GetIsoSize() - 1;
  5318. int h_lefttop = 0;//Map->GetHeightAt(ll+lt*Map->GetIsoSize());
  5319. int h_leftbottom = 0;//Map->GetHeightAt(lr+lb*Map->GetIsoSize());
  5320. ToPhys((int*)&ll, (int*)&lt);
  5321. ToPhys((int*)&lr, (int*)&lb);
  5322. ll -= m_viewOffset.x - f_x / 2;
  5323. lt -= m_viewOffset.y - f_y / 2;
  5324. lr -= m_viewOffset.x - f_x / 2;
  5325. lb -= m_viewOffset.y - f_y / 2;
  5326. lt -= h_lefttop * f_y / 2;
  5327. lb -= h_leftbottom * f_y / 2;
  5328. auto sllt = useHighRes ? ScaleBackToFrontBuffer(ProjectedCoords(ll, lt)) : ProjectedCoords(ll, lt);
  5329. auto slbr = useHighRes ? ScaleBackToFrontBuffer(ProjectedCoords(lr, lb)) : ProjectedCoords(lr, lb);
  5330. RECT ls;
  5331. Map->GetLocalSize(&ls);
  5332. ProjectedCoords l_lt(
  5333. ll + ls.left * f_x - f_x / 2,
  5334. lt + (ls.top - 4) * f_y
  5335. );
  5336. ProjectedCoords l_br(
  5337. ll + ls.left * f_x + ls.right * f_x - f_x / 2,
  5338. lt + (ls.top - 4 + 4) * f_y + ls.bottom * f_y
  5339. );
  5340. auto ls_lt = useHighRes ? ScaleBackToFrontBuffer(l_lt) : l_lt;
  5341. auto ls_br = useHighRes ? ScaleBackToFrontBuffer(l_br) : l_br;
  5342. auto red = m_color_converter->GetColor(255, 0, 0);
  5343. auto blue = m_color_converter->GetColor(0, 0, 255);
  5344. d.Rectangle(sllt.x, sllt.y, slbr.x, slbr.y, red);
  5345. d.Rectangle(sllt.x-1, sllt.y-1, slbr.x+1, slbr.y+1, red);
  5346. d.Rectangle(ls_lt.x, ls_lt.y, ls_br.x, ls_br.y, blue);
  5347. d.Rectangle(ls_lt.x+1, ls_lt.y+1, ls_br.x-1, ls_br.y-1, blue);
  5348. dds->Unlock(NULL);
  5349. RECT r;
  5350. GetWindowRect(&r);
  5351. for (const auto& s : m_texts_to_render)
  5352. {
  5353. const bool blue = s.color == RGB(0, 0, 255); // TODO: TextRenderer should support setting the color at render time
  5354. if (s.fixedScreenPos || !useHighRes)
  5355. {
  5356. auto textRenderer = s.useFont9 ? (blue ? *m_textBlue9 : *m_text9) : (blue ? *m_textBlue : *m_textDefault);
  5357. textRenderer.RenderText(dds, s.drawx, s.drawy, s.text, s.centered);
  5358. }
  5359. else
  5360. {
  5361. auto textRenderer = s.useFont9 ? (blue ? *m_textBlue9Scaled : *m_text9Scaled) : (blue ? *m_textBlueScaled : *m_textScaled);
  5362. textRenderer.RenderText(dds, r.left + (s.drawx - r.left) / m_viewScale.x, r.top + (s.drawy - r.top) / m_viewScale.y, s.text, s.centered);
  5363. }
  5364. }
  5365. }
  5366. void CIsoView::OnRButtonDown(UINT nFlags, CPoint point)
  5367. {
  5368. rclick_x = point.x;
  5369. rclick_y = point.y;
  5370. rscroll = FALSE;
  5371. CView::OnRButtonDown(nFlags, point);
  5372. }
  5373. void CIsoView::SetScroll(int xscroll, int yscroll)
  5374. {
  5375. RECT r;
  5376. GetWindowRect(&r);
  5377. m_viewOffset = ProjectedVec(xscroll, yscroll);
  5378. if (m_viewOffset.x < (Map->GetHeight() / 2 - 14 - r.left / f_x) * f_x)
  5379. m_viewOffset.x = (Map->GetHeight() / 2 - 14 - r.left / f_x) * f_x;
  5380. if (m_viewOffset.x + r.right * m_viewScale.x > (Map->GetHeight() / 2 + Map->GetWidth() + 14) * f_x)
  5381. m_viewOffset.x = (Map->GetHeight() / 2 + Map->GetWidth() + 14) * f_x - r.right * m_viewScale.x;
  5382. if (m_viewOffset.y < (Map->GetWidth() / 2 - 14 - r.top / f_y) * f_y)
  5383. m_viewOffset.y = (Map->GetWidth() / 2 - 14 - r.top / f_y) * f_y;
  5384. if (m_viewOffset.y + r.bottom * m_viewScale.y > (Map->GetWidth() / 2 + Map->GetHeight() + 4) * f_y)
  5385. m_viewOffset.y = (Map->GetWidth() / 2 + Map->GetHeight() + 4) * f_y - r.bottom * m_viewScale.y;
  5386. SetScrollPos(SB_VERT, (m_viewOffset.y / f_y - Map->GetWidth() / 2 + 4), TRUE);
  5387. SetScrollPos(SB_HORZ, (m_viewOffset.x / f_x - Map->GetHeight() / 2 + 1), TRUE);
  5388. }
  5389. RECT CIsoView::GetScaledDisplayRect() const
  5390. {
  5391. RECT r;
  5392. GetWindowRect(&r);
  5393. r.right = r.right - (r.right - r.left) * (1.0f - m_viewScale.x);
  5394. r.bottom = r.bottom - (r.bottom - r.top) * (1.0f - m_viewScale.y);
  5395. return r; // RVO
  5396. }
  5397. void CIsoView::GetScroll(int& xscroll, int& yscroll) const
  5398. {
  5399. xscroll = m_viewOffset.x;
  5400. yscroll = m_viewOffset.y;
  5401. }
  5402. void CIsoView::OnKillFocus(CWnd* pNewWnd)
  5403. {
  5404. CView::OnKillFocus(pNewWnd);
  5405. if (rscroll)
  5406. {
  5407. errstream << "Killing scroll" << endl;
  5408. errstream.flush();
  5409. ReleaseCapture();
  5410. KillTimer(11);
  5411. ShowCursor(TRUE);
  5412. rscroll = FALSE;
  5413. bDoNotAllowScroll = TRUE;
  5414. }
  5415. }
  5416. // takes an index, not an waypoint id!
  5417. void CIsoView::FocusWaypoint(int index)
  5418. {
  5419. int x, y;
  5420. DWORD dwPos;
  5421. Map->GetWaypointData(index, NULL, &dwPos);
  5422. x = dwPos % Map->GetIsoSize();
  5423. y = dwPos / Map->GetIsoSize();
  5424. ToPhys3d(&x, &y);
  5425. RECT r;
  5426. GetWindowRect(&r);
  5427. auto pos = ProjectedVec((x - (r.right - r.left) / 2 * m_viewScale.x) - r.left, (y - (r.bottom - r.top) / 2 * m_viewScale.y) - r.top);
  5428. SetScroll(pos.x, pos.y);
  5429. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  5430. }
  5431. BOOL CIsoView::OnMouseWheel(UINT nFlags, short zDelta, CPoint ptScreen)
  5432. {
  5433. CPoint pt = ptScreen;
  5434. ScreenToClient(&pt); // Attention: MouseWheel event has screen coordinates in contrast to e.g. MouseMove
  5435. float smoothF = float(zDelta) / std::numeric_limits<short>::max();
  5436. float fixedF = zDelta > 0 ? std::numeric_limits<short>::max() : std::numeric_limits<short>::min();
  5437. Zoom(pt, theApp.m_Options.viewScaleUseSteps ? fixedF : smoothF);
  5438. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  5439. CMyViewFrame& dlg = *(CMyViewFrame*)owner;
  5440. dlg.m_minimap.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  5441. return CView::OnMouseWheel(nFlags, zDelta, pt);
  5442. }
  5443. void CIsoView::Zoom(CPoint& pt, float f)
  5444. {
  5445. auto oldScaledMPos = GetProjectedCoordinatesFromClientCoordinates(pt);
  5446. auto oldScale = m_viewScale;
  5447. auto oldViewScaleControl = m_viewScaleControl;
  5448. m_viewScaleControl *= (1.0f - f * theApp.m_Options.viewScaleSpeed);
  5449. if (m_viewScaleControl > 1.0f)
  5450. m_viewScaleControl = 1.0f;
  5451. if (m_viewScaleControl < 0.1f)
  5452. m_viewScaleControl = 0.1f;
  5453. if (!theApp.m_Options.viewScaleUseSteps)
  5454. m_viewScale.set(m_viewScaleControl, m_viewScaleControl);
  5455. else
  5456. {
  5457. // find previous step
  5458. auto prevStepIt = std::find_if(theApp.m_Options.viewScaleSteps.rbegin(), theApp.m_Options.viewScaleSteps.rend(), [oldScale](auto f) {return f >= oldScale.x;});
  5459. auto stepIt = std::find_if(theApp.m_Options.viewScaleSteps.rbegin(), theApp.m_Options.viewScaleSteps.rend(), [this](auto f) {return f >= m_viewScaleControl;});
  5460. if (stepIt > prevStepIt)
  5461. stepIt = prevStepIt + 1;
  5462. if (stepIt < prevStepIt)
  5463. stepIt = prevStepIt - 1;
  5464. auto nextScale = stepIt == theApp.m_Options.viewScaleSteps.rend() ? 1.0f : *stepIt;
  5465. m_viewScale.set(nextScale, nextScale);
  5466. }
  5467. auto newScaledMPos = GetProjectedCoordinatesFromClientCoordinates(pt);
  5468. m_viewOffset = m_viewOffset + ((oldScaledMPos - newScaledMPos)).convertT<std::int32_t>(); // this lets the mouse cursor pixel stay constant
  5469. UpdateScrollRanges();
  5470. SetScroll(m_viewOffset.x, m_viewOffset.y);
  5471. updateFontScaled();
  5472. }
  5473. void CIsoView::OnMButtonDown(UINT nFlags, CPoint point)
  5474. {
  5475. // TODO: Fügen Sie hier Ihren Meldungshandlercode ein, und/oder benutzen Sie den Standard.
  5476. m_MButtonDown = point;
  5477. m_MButtonMoveZooming = point;
  5478. m_zooming = true;
  5479. CView::OnMButtonDown(nFlags, point);
  5480. }
  5481. void CIsoView::OnMButtonUp(UINT nFlags, CPoint point)
  5482. {
  5483. // TODO: Fügen Sie hier Ihren Meldungshandlercode ein, und/oder benutzen Sie den Standard.
  5484. m_zooming = false;
  5485. CView::OnMButtonUp(nFlags, point);
  5486. }