DISPLAY.CPP 186 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: F:\projects\c&c\vcs\code\display.cpv 2.16 16 Oct 1995 16:48:24 JOE_BOSTIC $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : DISPLAY.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : September 10, 1993 *
  26. * *
  27. * Last Update : August 24, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * DisplayClass::AI -- Handles the maintenance tasks for the map display. *
  32. * DisplayClass::Calculated_Cell -- Fetch a map cell based on specified method. *
  33. * DisplayClass::Cell_Object -- Determines what has been clicked on. *
  34. * DisplayClass::Cell_Shadow -- Determine what shadow icon to use for the cell. *
  35. * DisplayClass::Click_Cell_Calc -- Determines cell from screen X & Y. *
  36. * DisplayClass::Coord_To_Pixel -- Determines X and Y pixel coordinates. *
  37. * DisplayClass::Cursor_Mark -- Set or resets the cursor display flag bits. *
  38. * DisplayClass::DisplayClass -- Default constructor for display class. *
  39. * DisplayClass::Draw_It -- Draws the tactical map. *
  40. * DisplayClass::Flag_To_Redraw -- Flags the display so that it will be redrawn as soon as poss*
  41. * DisplayClass::Get_Occupy_Dimensions -- computes width & height of the given occupy list *
  42. * DisplayClass::Init_Clear -- Clears the display to a known state. *
  43. * DisplayClass::Init_IO -- Creates the map's button list *
  44. * DisplayClass::Init_Theater -- Theater-specific initialization *
  45. * DisplayClass::Map_Cell -- Mark specified cell as having been mapped. *
  46. * DisplayClass::Mouse_Left_Held -- Handles the left button held down. *
  47. * DisplayClass::Mouse_Left_Press -- Handles the left mouse button press. *
  48. * DisplayClass::Mouse_Left_Release -- Handles the left mouse button release. *
  49. * DisplayClass::Mouse_Left_Up -- Handles the left mouse "cruising" over the map. *
  50. * DisplayClass::Mouse_Right_Press -- Handles the right mouse button press. *
  51. * DisplayClass::Next_Object -- Searches for next object on display. *
  52. * DisplayClass::One_Time -- Performs any special one time initializations. *
  53. * DisplayClass::Passes_Proximity_Check -- Determines if building placement is near friendly sq*
  54. * DisplayClass::Pixel_To_Coord -- converts screen coord to COORDINATE *
  55. * DisplayClass::Read_INI -- Reads map control data from INI file. *
  56. * DisplayClass::Redraw_Icons -- Draws all terrain icons necessary. *
  57. * DisplayClass::Redraw_Shadow -- Draw the shadow overlay. *
  58. * DisplayClass::Refresh_Band -- Causes all cells under the rubber band to be redrawn. *
  59. * DisplayClass::Refresh_Cells -- Redraws all cells in list. *
  60. * DisplayClass::Remove -- Removes a game object from the rendering system. *
  61. * DisplayClass::Repair_Mode_Control -- Controls the repair mode. *
  62. * DisplayClass::Scroll_Map -- Scroll the tactical map in desired direction. *
  63. * DisplayClass::Select_These -- All selectable objects in region are selected. *
  64. * DisplayClass::Sell_Mode_Control -- Controls the sell mode. *
  65. * DisplayClass::Set_Cursor_Pos -- Controls the display and animation of the tac cursor. *
  66. * DisplayClass::Set_Cursor_Shape -- Changes the shape of the terrain square cursor. *
  67. * DisplayClass::Set_View_Dimensions -- Sets the tactical display screen coordinates. *
  68. * DisplayClass::Submit -- Adds a game object to the map rendering system. *
  69. * DisplayClass::TacticalClass::Action -- Processes input for the tactical map. *
  70. * DisplayClass::Text_Overlap_List -- Creates cell overlap list for specified text string. *
  71. * DisplayClass::Write_INI -- Writes map data into INI file. *
  72. * DisplayClass::Set_Tactical_Position -- Sets the tactical view position. *
  73. * DisplayClass::Center_Map -- Centers the map about the currently selected objects *
  74. * DisplayClass::Prev_Object -- Searches for the previous object on the map. *
  75. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  76. #include "function.h"
  77. /*
  78. ** These layer control elements are used to group the displayable objects
  79. ** so that proper overlap can be obtained.
  80. */
  81. LayerClass DisplayClass::Layer[LAYER_COUNT];
  82. /*
  83. ** Fading tables
  84. */
  85. unsigned char DisplayClass::FadingBrighten[256];
  86. unsigned char DisplayClass::FadingShade[256];
  87. unsigned char DisplayClass::FadingLight[256];
  88. unsigned char DisplayClass::RemapTables[HOUSE_COUNT][3][256];
  89. unsigned char DisplayClass::FadingGreen[256];
  90. unsigned char DisplayClass::FadingYellow[256];
  91. unsigned char DisplayClass::FadingRed[256];
  92. unsigned char DisplayClass::TranslucentTable[(MAGIC_COL_COUNT+1)*256];
  93. unsigned char DisplayClass::WhiteTranslucentTable[(1+1)*256];
  94. unsigned char DisplayClass::MouseTranslucentTable[(4+1)*256];
  95. void const * DisplayClass::TransIconset;
  96. unsigned char DisplayClass::UnitShadow[(USHADOW_COL_COUNT+1)*256];
  97. unsigned char DisplayClass::SpecialGhost[2*256];
  98. void const * DisplayClass::ShadowShapes;
  99. unsigned char DisplayClass::ShadowTrans[(SHADOW_COL_COUNT+1)*256];
  100. /*
  101. ** Bit array of cell redraw flags
  102. */
  103. BooleanVectorClass DisplayClass::CellRedraw;
  104. /*
  105. ** The main button that intercepts user input to the map
  106. */
  107. DisplayClass::TacticalClass DisplayClass::TacButton;
  108. //
  109. // We need a way to bypass visible view checks when we are running in the context of GlyphX without using the
  110. // internal C&C renderer. We shouldn't know or care what the user is actually looking at
  111. // ST - 4/17/2019 9:01AM
  112. //
  113. bool DisplayClass::IgnoreViewConstraints = false;
  114. /*
  115. ** Define "_RETRIEVE" if the palette morphing tables are part of the loaded data. If this
  116. ** is undefined, then the files will be created.
  117. */
  118. #define _RETRIEVE
  119. static int const TEX_X = 0;
  120. static int const TEX_Y = 6;
  121. static int const TEX_W = 14;
  122. extern MixFileClass *TheaterIcons;
  123. //Added for getting the input for special character keys from the client
  124. // - 6/26/2019 JAS
  125. extern bool DLL_Export_Get_Input_Key_State(KeyNumType key);
  126. /***********************************************************************************************
  127. * DisplayClass::DisplayClass -- Default constructor for display class. *
  128. * *
  129. * This constructor for the display class just initializes some of the display settings. *
  130. * Most settings are initialized with the correct values at the time that the Init function *
  131. * is called. There are some cases where default values are wise and this routine fills *
  132. * those particular ones in. *
  133. * *
  134. * INPUT: none *
  135. * *
  136. * OUTPUT: none *
  137. * *
  138. * WARNINGS: none *
  139. * *
  140. * HISTORY: *
  141. * 12/06/1994 JLB : Created. *
  142. *=============================================================================================*/
  143. DisplayClass::DisplayClass(void)
  144. {
  145. TacticalCoord = 0;
  146. ShadowShapes = 0;
  147. TransIconset = 0;
  148. ZoneCell = 0;
  149. ZoneOffset = 0;
  150. CursorSize = 0;
  151. ProximityCheck = false;
  152. PendingObjectPtr = 0;
  153. PendingObject = 0;
  154. PendingHouse = HOUSE_NONE;
  155. IsRepairMode = false;
  156. IsTargettingMode = false;
  157. IsToRedraw = true;
  158. IsRubberBand = false;
  159. IsTentative = false;
  160. IsSellMode = false;
  161. }
  162. /***********************************************************************************************
  163. * DisplayClass::One_Time -- Performs any special one time initializations. *
  164. * *
  165. * This routine is called from the game initialization process. It is to perform any one *
  166. * time initializations necessary for the map display system. It allocates the staging *
  167. * buffer needed for the radar map. *
  168. * *
  169. * INPUT: none *
  170. * *
  171. * OUTPUT: none *
  172. * *
  173. * WARNINGS: This routine must be called ONCE and only once. *
  174. * *
  175. * HISTORY: *
  176. * 05/31/1994 JLB : Created. *
  177. * 05/31/1994 JLB : Handles layer system now. *
  178. * 06/02/1994 JLB : Takes care of misc display tables and data allocation. *
  179. *=============================================================================================*/
  180. void DisplayClass::One_Time(void)
  181. {
  182. Set_View_Dimensions(0, Map.Get_Tab_Height());
  183. MapClass::One_Time();
  184. /*
  185. ** Init the CellRedraw bit array. Do not do this in the constructor, since the
  186. ** BooleanVector may not have been constructed yet.
  187. */
  188. CellRedraw.Resize(MAP_CELL_TOTAL);
  189. for (LayerType layer = LAYER_FIRST; layer < LAYER_COUNT; layer++) {
  190. Layer[layer].One_Time();
  191. }
  192. /*
  193. ** Load the generic transparent icon set.
  194. */
  195. TransIconset = MixFileClass::Retrieve("TRANS.ICN");
  196. ShadowShapes = MixFileClass::Retrieve("SHADOW.SHP");
  197. Set_View_Dimensions(0, Map.Get_Tab_Height());
  198. /*
  199. ** Allocate and initialize the remap tables needed for each "house".
  200. */
  201. HousesType hindex;
  202. int fade;
  203. for (fade = 0; fade < 3; fade++) {
  204. for (hindex = HOUSE_FIRST; hindex < HOUSE_COUNT; hindex++) {
  205. int color;
  206. switch (fade) {
  207. case 0:
  208. for (color = 0; color < 256; color++) {
  209. RemapTables[hindex][fade][color] = color;
  210. }
  211. break;
  212. case 1:
  213. Mem_Copy(FadingLight, RemapTables[hindex][fade], 256);
  214. break;
  215. case 2:
  216. Mem_Copy(FadingShade, RemapTables[hindex][fade], 256);
  217. break;
  218. }
  219. Mem_Copy(&RemapTables[hindex][fade][((int)hindex+11)*16], &RemapTables[hindex][fade][(0+11)*16], 16);
  220. }
  221. }
  222. }
  223. /***********************************************************************************************
  224. * DisplayClass::Init_Clear -- clears the display to a known state *
  225. * *
  226. * INPUT: *
  227. * none. *
  228. * *
  229. * OUTPUT: *
  230. * none. *
  231. * *
  232. * WARNINGS: *
  233. * none. *
  234. * *
  235. * HISTORY: *
  236. * 03/17/1995 BRR : Created. *
  237. *=============================================================================================*/
  238. void DisplayClass::Init_Clear(void)
  239. {
  240. MapClass::Init_Clear();
  241. /*
  242. ** Clear any object being placed
  243. */
  244. PendingObjectPtr = 0;
  245. PendingObject = 0;
  246. PendingHouse = HOUSE_NONE;
  247. CursorSize = 0;
  248. IsTargettingMode = false;
  249. IsRepairMode = false;
  250. IsRubberBand = false;
  251. IsTentative = false;
  252. IsSellMode = false;
  253. /*
  254. ** Empty all the display's layers
  255. */
  256. for (LayerType layer = LAYER_FIRST; layer < LAYER_COUNT; layer++) {
  257. Layer[layer].Init();
  258. }
  259. }
  260. /***********************************************************************************************
  261. * DisplayClass::Init_IO -- clears & re-builds the map's button list *
  262. * *
  263. * INPUT: *
  264. * none. *
  265. * *
  266. * OUTPUT: *
  267. * none. *
  268. * *
  269. * WARNINGS: *
  270. * none. *
  271. * *
  272. * HISTORY: *
  273. * 03/17/1995 BRR : Created. *
  274. *=============================================================================================*/
  275. void DisplayClass::Init_IO(void)
  276. {
  277. MapClass::Init_IO();
  278. /*
  279. ** Re-attach our buttons to the main map button list, only in non-edit mode.
  280. */
  281. if (!Debug_Map) {
  282. TacButton.Zap();
  283. Add_A_Button(TacButton);
  284. }
  285. }
  286. /***********************************************************************************************
  287. * DisplayClass::Init_Theater -- Performs theater-specific initialization (mixfiles, etc) *
  288. * *
  289. * INPUT: *
  290. * theater new theater *
  291. * *
  292. * OUTPUT: *
  293. * none. *
  294. * *
  295. * WARNINGS: *
  296. * none. *
  297. * *
  298. * HISTORY: *
  299. * 03/17/1995 BRR : Created. *
  300. *=============================================================================================*/
  301. void DisplayClass::Init_Theater(TheaterType theater)
  302. {
  303. char fullname[16];
  304. char iconname[16];
  305. #ifndef _RETRIEVE
  306. static TLucentType const MouseCols[4] = {
  307. {BLACK, BLACK, 110, 0},
  308. {WHITE, WHITE, 110, 0},
  309. {LTGREY, LTGREY, 110, 0},
  310. {DKGREY, DKGREY, 110, 0}
  311. };
  312. static TLucentType const MagicCols[MAGIC_COL_COUNT] = {
  313. {32,32,110,0},
  314. {33,33,110,0},
  315. {34,34,110,0},
  316. {35,35,110,0},
  317. {36,36,110,0},
  318. {37,37,110,0},
  319. {38,38,110,0},
  320. {39,39,110,0},
  321. {BLACK, BLACK, 200, 0},
  322. {WHITE, BLACK, 40, 0},
  323. {LTGREY, BLACK, 80, 0},
  324. {DKGREY, BLACK, 140, 0}
  325. };
  326. static TLucentType const WhiteCols[1] = {
  327. {1, WHITE, 80, 0}
  328. };
  329. static TLucentType const ShadowCols[SHADOW_COL_COUNT] = {
  330. {WHITE+1, BLACK,130,0},
  331. {WHITE, BLACK,170,0},
  332. {LTGRAY, BLACK,250,0},
  333. {DKGRAY, BLACK,250,0}
  334. };
  335. static TLucentType const UShadowCols[USHADOW_COL_COUNT] = {
  336. {LTGREEN, BLACK,130,0}
  337. };
  338. #endif
  339. /*
  340. ---------------------- Invoke parent's init routine ----------------------
  341. */
  342. MapClass::Init_Theater(theater);
  343. /*
  344. ** Save the new theater value
  345. */
  346. Theater = theater;
  347. #ifndef DEMO
  348. /*
  349. ** Unload old mixfiles, and cache the new ones
  350. */
  351. sprintf(fullname, "%s.MIX", Theaters[Theater].Root);
  352. if (Theater != LastTheater){
  353. if (TheaterData) {
  354. delete TheaterData;
  355. }
  356. TheaterData = new MixFileClass(fullname);
  357. TheaterData->Cache();
  358. }
  359. #endif
  360. /*
  361. ** Register the hi-res icons mix file now since it is theater specific
  362. */
  363. sprintf(fullname, "%s.MIX", Theaters[Theater].Root);
  364. strcpy (iconname, fullname);
  365. strcpy (&iconname[4], "ICNH.MIX");
  366. if (Theater != LastTheater){
  367. if (TheaterIcons) {
  368. delete TheaterIcons;
  369. }
  370. TheaterIcons = new MixFileClass(iconname);
  371. TheaterIcons->Cache();
  372. }
  373. /*
  374. ** Load the custom palette associated with this theater.
  375. ** The fading palettes will have to be generated as well.
  376. */
  377. sprintf(fullname, "%s.PAL", Theaters[theater].Root);
  378. void const * ptr = MixFileClass::Retrieve(fullname);
  379. Mem_Copy((void *)ptr, GamePalette, 768);
  380. Mem_Copy(GamePalette, OriginalPalette, 768);
  381. #ifndef _RETRIEVE
  382. /*
  383. ** Make sure that remapping doesn't occur on the colors that cycle.
  384. */
  385. memset(&GamePalette[CYCLE_COLOR_START*3], 0x3F, CYCLE_COLOR_COUNT*3);
  386. #endif
  387. #ifdef _RETRIEVE
  388. CCFileClass(Fading_Table_Name("GREEN", theater)).Read(FadingGreen, sizeof(FadingGreen));
  389. #else
  390. Build_Fading_Table(GamePalette, FadingGreen, GREEN, 110);
  391. CCFileClass(Fading_Table_Name("GREEN", theater)).Write(FadingGreen, sizeof(FadingGreen));
  392. #endif
  393. if (theater == THEATER_DESERT) {
  394. FadingGreen[196] = 160;
  395. }
  396. #ifdef _RETRIEVE
  397. CCFileClass(Fading_Table_Name("YELLOW", theater)).Read(FadingYellow, sizeof(FadingYellow));
  398. #else
  399. Build_Fading_Table(GamePalette, FadingYellow, YELLOW, 140);
  400. CCFileClass(Fading_Table_Name("YELLOW", theater)).Write(FadingYellow, sizeof(FadingYellow));
  401. #endif
  402. #ifdef _RETRIEVE
  403. CCFileClass(Fading_Table_Name("RED", theater)).Read(FadingRed, sizeof(FadingRed));
  404. #else
  405. Build_Fading_Table(GamePalette, FadingRed, RED, 140);
  406. CCFileClass(Fading_Table_Name("RED", theater)).Write(FadingRed, sizeof(FadingRed));
  407. #endif
  408. #ifdef _RETRIEVE
  409. CCFileClass(Fading_Table_Name("MOUSE", theater)).Read(MouseTranslucentTable, sizeof(MouseTranslucentTable));
  410. #else
  411. Build_Translucent_Table(GamePalette, &MouseCols[0], 4, MouseTranslucentTable);
  412. CCFileClass(Fading_Table_Name("MOUSE", theater)).Write(MouseTranslucentTable, sizeof(MouseTranslucentTable));
  413. #endif
  414. // MouseDrawPtr = MouseTranslucentTable;
  415. // MouseDrawPtr2 = Add_Long_To_Pointer(MouseTranslucentTable, 256L);
  416. // MouseDrawVal = 1;
  417. // MouseDrawFlags = (int)SHAPE_GHOST;
  418. #ifdef _RETRIEVE
  419. CCFileClass(Fading_Table_Name("TRANS", theater)).Read(TranslucentTable, sizeof(TranslucentTable));
  420. #else
  421. Build_Translucent_Table(GamePalette, &MagicCols[0], MAGIC_COL_COUNT, TranslucentTable);
  422. CCFileClass(Fading_Table_Name("TRANS", theater)).Write(TranslucentTable, sizeof(TranslucentTable));
  423. #endif
  424. #ifdef _RETRIEVE
  425. CCFileClass(Fading_Table_Name("WHITE", theater)).Read(WhiteTranslucentTable, sizeof(WhiteTranslucentTable));
  426. #else
  427. Build_Translucent_Table(GamePalette, &WhiteCols[0], 1, WhiteTranslucentTable);
  428. CCFileClass(Fading_Table_Name("WHITE", theater)).Write(WhiteTranslucentTable, sizeof(WhiteTranslucentTable));
  429. #endif
  430. #ifdef _RETRIEVE
  431. CCFileClass(Fading_Table_Name("SHADOW", theater)).Read(ShadowTrans, sizeof(ShadowTrans));
  432. #else
  433. Build_Translucent_Table(GamePalette, &ShadowCols[0], SHADOW_COL_COUNT, ShadowTrans);
  434. CCFileClass(Fading_Table_Name("SHADOW", theater)).Write(ShadowTrans, sizeof(ShadowTrans));
  435. #endif
  436. #ifdef _RETRIEVE
  437. CCFileClass(Fading_Table_Name("UNITS", theater)).Read(UnitShadow, sizeof(UnitShadow));
  438. #else
  439. Conquer_Build_Translucent_Table(GamePalette, &UShadowCols[0], USHADOW_COL_COUNT, UnitShadow);
  440. CCFileClass(Fading_Table_Name("UNITS", theater)).Write(UnitShadow, sizeof(UnitShadow));
  441. #endif
  442. #ifdef _RETRIEVE
  443. CCFileClass(Fading_Table_Name("SHADE", theater)).Read(FadingShade, sizeof(FadingShade));
  444. #else
  445. Conquer_Build_Fading_Table(GamePalette, FadingShade, BLACK, 150);
  446. CCFileClass(Fading_Table_Name("SHADE", theater)).Write(FadingShade, sizeof(FadingShade));
  447. #endif
  448. #ifdef _RETRIEVE
  449. CCFileClass(Fading_Table_Name("LIGHT", theater)).Read(FadingLight, sizeof(FadingLight));
  450. #else
  451. Conquer_Build_Fading_Table(GamePalette, FadingLight, WHITE, 85);
  452. CCFileClass(Fading_Table_Name("LIGHT", theater)).Write(FadingLight, sizeof(FadingLight));
  453. #endif
  454. /*
  455. ** Create the shadow color used by aircraft.
  456. */
  457. Conquer_Build_Fading_Table(GamePalette, &SpecialGhost[256], BLACK, 100);
  458. for (int index = 0; index < 256; index++) {
  459. SpecialGhost[index] = 0;
  460. }
  461. Build_Fading_Table(GamePalette, FadingBrighten, WHITE, 25);
  462. #ifndef _RETRIEVE
  463. /*
  464. ** Restore the palette since it was mangled while building the fading tables.
  465. */
  466. sprintf(fullname, "%s.PAL", Theaters[theater].Root);
  467. ptr = MixFileClass::Retrieve(fullname);
  468. Mem_Copy((void *)ptr, GamePalette, 768);
  469. Mem_Copy(GamePalette, OriginalPalette, 768);
  470. #endif
  471. /*
  472. ** Adjust the palette according to the visual control option settings.
  473. */
  474. Options.Fixup_Palette();
  475. }
  476. /***********************************************************************************************
  477. * DisplayClass::Text_Overlap_List -- Creates cell overlap list for specified text string. *
  478. * *
  479. * This routine is used to create an overlap list that specifies all the cells that are *
  480. * covered by the specified text string. This overlap list is used to handle map refresh *
  481. * logic. *
  482. * *
  483. * INPUT: text -- Pointer to the text that would appear on the map and must have an *
  484. * overlap list generated. *
  485. * *
  486. * x,y -- The coordinates that the text would appear (upper left corner). *
  487. * *
  488. * OUTPUT: Returns with a pointer to an overlap list that covers all cells "under" the text *
  489. * if were displayed at the coordinates specified. The list is actually a series of *
  490. * offsets from the display's upper left corner cell number. *
  491. * *
  492. * WARNINGS: none *
  493. * *
  494. * HISTORY: *
  495. * 12/06/1994 JLB : Created. *
  496. * 12/07/1994 JLB : Sidebar fixup. *
  497. * 08/13/1995 JLB : Optimized for variable sized help text. *
  498. *=============================================================================================*/
  499. short const * DisplayClass::Text_Overlap_List(char const * text, int x, int y, int lines)
  500. {
  501. static short _list[30];
  502. if (text) {
  503. short * ptr = &_list[0];
  504. int len = String_Pixel_Width(text)+CELL_PIXEL_W;
  505. int right = TacPixelX + Lepton_To_Pixel(TacLeptonWidth);
  506. /*
  507. ** If the help text would spill into the sidebar, then flag this fact, but
  508. ** shorten the apparent length so that the icon list calculation will
  509. ** function correctly.
  510. */
  511. if (x+len >= TacPixelX+Lepton_To_Pixel(TacLeptonWidth)) {
  512. len = right-x;
  513. *ptr++ = REFRESH_SIDEBAR;
  514. }
  515. /*
  516. ** Build the list of overlap cell offset values according to the text
  517. ** coordinate and the length.
  518. */
  519. int height = (((FontHeight * lines) + 23) / 24) * 24;
  520. if (x <= right) {
  521. CELL ul = Click_Cell_Calc(x, y-1);
  522. CELL lr = Click_Cell_Calc(x+len-1, Bound(y+height, TacPixelY, SeenBuff.Get_Height() - 1));
  523. if (ul == -1) ul = Click_Cell_Calc(x, y);
  524. // if (lr == -1) lr = Click_Cell_Calc(x+len, y);
  525. if (ul != -1 && lr != -1) {
  526. for (int yy = Cell_Y(ul); yy <= Cell_Y(lr); yy++) {
  527. for (int xx = Cell_X(ul); xx <= Cell_X(lr); xx++) {
  528. *ptr++ = XY_Cell(xx, yy) - Coord_Cell(TacticalCoord);
  529. }
  530. }
  531. }
  532. }
  533. *ptr = REFRESH_EOL;
  534. }
  535. return(_list);
  536. }
  537. /***********************************************************************************************
  538. * DisplayClass::Set_View_Dimensions -- Sets the tactical display screen coordinates. *
  539. * *
  540. * Use this routine to set the tactical map screen coordinates and dimensions. This routine *
  541. * is typically used when the screen size or position changes as a result of the sidebar *
  542. * changing position or appearance. *
  543. * *
  544. * INPUT: x,y -- The X and Y pixel position on the screen for the tactical map upper left *
  545. * corner. *
  546. * *
  547. * width -- The width of the tactical display (in pixels). If this parameter is *
  548. * omitted, then the width will be as wide as the screen will allow. *
  549. * *
  550. * height-- The height of the tactial display (in pixels). If this parameter is *
  551. * omitted, then the width wil be as wide as the screen will allow. *
  552. * *
  553. * OUTPUT: none *
  554. * *
  555. * WARNINGS: none *
  556. * *
  557. * HISTORY: *
  558. * 12/06/1994 JLB : Created. *
  559. * 06/27/1995 JLB : Adjusts tactical map position if necessary. *
  560. *=============================================================================================*/
  561. void DisplayClass::Set_View_Dimensions(int x, int y, int width, int height)
  562. {
  563. #if (1) // This code pulled in from RA1. ST - 1/9/2019 10:53AM
  564. if (width == -1) {
  565. TacLeptonWidth = Pixel_To_Lepton(SeenBuff.Get_Width()-x);
  566. } else {
  567. TacLeptonWidth = width * CELL_LEPTON_W;
  568. }
  569. // ST - 3/1/2019 12:05PM
  570. // Made the below code more consistent with the width calculation. This is needed if we aren't going to draw the tabs at the top of the screen
  571. //
  572. if (height == -1) {
  573. TacLeptonHeight = Pixel_To_Lepton(SeenBuff.Get_Height()-y);
  574. //height = (SeenBuff.Get_Height()-y) / CELL_PIXEL_H;
  575. } else {
  576. TacLeptonHeight = height * CELL_LEPTON_H;
  577. }
  578. //TacLeptonHeight = height * CELL_LEPTON_H;
  579. /*
  580. ** Adjust the tactical cell if it is now in an invalid position
  581. ** because of the changed dimensions.
  582. */
  583. int xx = 0;// Coord_X(TacticalCoord) - (MapCellX * CELL_LEPTON_W);
  584. int yy = 0;// Coord_Y(TacticalCoord) - (MapCellY * CELL_LEPTON_H);
  585. Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, MapCellWidth * CELL_LEPTON_W, MapCellHeight * CELL_LEPTON_H);
  586. Set_Tactical_Position(XY_Coord(xx + (MapCellX * CELL_LEPTON_W), yy + (MapCellY * CELL_LEPTON_H)));
  587. TacPixelX = x;
  588. TacPixelY = y;
  589. WindowList[WINDOW_TACTICAL][WINDOWX] = x;
  590. WindowList[WINDOW_TACTICAL][WINDOWY] = y;
  591. WindowList[WINDOW_TACTICAL][WINDOWWIDTH] = Lepton_To_Pixel(TacLeptonWidth);
  592. WindowList[WINDOW_TACTICAL][WINDOWHEIGHT] = Lepton_To_Pixel(TacLeptonHeight);
  593. if (Window == WINDOW_TACTICAL) {
  594. Change_Window(0);
  595. Change_Window(Window);
  596. }
  597. IsToRedraw = true;
  598. Flag_To_Redraw(false);
  599. TacButton.X = TacPixelX;
  600. TacButton.Y = TacPixelY;
  601. TacButton.Width = Lepton_To_Pixel(TacLeptonWidth);
  602. TacButton.Height = Lepton_To_Pixel(TacLeptonHeight);
  603. #else //CNC code
  604. if (width == -1) {
  605. width = SeenBuff.Get_Width() - x;
  606. }
  607. TacLeptonWidth = Pixel_To_Lepton(width);
  608. if (height == -1) {
  609. height = SeenBuff.Get_Height() - y;
  610. }
  611. TacLeptonHeight = Pixel_To_Lepton(height);
  612. /*
  613. ** Adjust the tactical cell if it is now in an invalid position
  614. ** because of the changed dimensions.
  615. */
  616. int xx = Coord_X(TacticalCoord) - (MapCellX * CELL_LEPTON_W);
  617. int yy = Coord_Y(TacticalCoord) - (MapCellY * CELL_LEPTON_H);
  618. Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, MapCellWidth * CELL_LEPTON_W, MapCellHeight * CELL_LEPTON_H);
  619. Set_Tactical_Position(XY_Coord(xx + (MapCellX * CELL_LEPTON_W), yy + (MapCellY * CELL_LEPTON_H)));
  620. TacPixelX = x;
  621. TacPixelY = y;
  622. WindowList[WINDOW_TACTICAL][WINDOWX] = x >> 3;
  623. WindowList[WINDOW_TACTICAL][WINDOWY] = y;
  624. WindowList[WINDOW_TACTICAL][WINDOWWIDTH] = width >> 3;
  625. WindowList[WINDOW_TACTICAL][WINDOWHEIGHT] = height;
  626. if (Window == WINDOW_TACTICAL) {
  627. Change_Window(0);
  628. Change_Window(Window);
  629. }
  630. IsToRedraw = true;
  631. Flag_To_Redraw(false);
  632. TacButton.X = TacPixelX;
  633. TacButton.Y = TacPixelY;
  634. TacButton.Width = Lepton_To_Pixel(TacLeptonWidth);
  635. TacButton.Height = Lepton_To_Pixel(TacLeptonHeight);
  636. #endif
  637. }
  638. /***********************************************************************************************
  639. * DisplayClass::Set_Cursor_Shape -- Changes the shape of the terrain square cursor. *
  640. * *
  641. * This routine is used to set up the terrain cursor according to the size of the object *
  642. * that is to be placed down. The terrain cursor looks like an arbitrary collection of *
  643. * hatched square overlays. Typical use is when placing buildings. *
  644. * *
  645. * INPUT: list -- A pointer to the list that contains offsets to the cells that are to *
  646. * be marked. *
  647. * *
  648. * OUTPUT: none *
  649. * *
  650. * WARNINGS: none *
  651. * *
  652. * HISTORY: *
  653. * 06/03/1994 JLB : Created. *
  654. * 06/26/1995 JLB : Puts placement cursor into static buffer. *
  655. *=============================================================================================*/
  656. void DisplayClass::Set_Cursor_Shape(short const * list)
  657. {
  658. if (CursorSize) {
  659. Cursor_Mark(ZoneCell+ZoneOffset, false);
  660. }
  661. ZoneOffset = 0;
  662. if (list) {
  663. int w,h;
  664. static short _list[50];
  665. memcpy(_list, list, sizeof(_list));
  666. CursorSize = _list;
  667. Get_Occupy_Dimensions (w, h, CursorSize);
  668. ZoneOffset = -(((h/2)*MAP_CELL_W)+(w/2));
  669. Cursor_Mark(ZoneCell+ZoneOffset, true);
  670. } else {
  671. CursorSize = 0;
  672. }
  673. }
  674. /***********************************************************************************************
  675. * DisplayClass::Passes_Proximity_Check -- Determines if building placement is near friendly sq*
  676. * *
  677. * This routine is used by the building placement cursor logic to determine whether the *
  678. * at the current cursor position if the building would be adjacent to another friendly *
  679. * building. In cases where this is not true, then the building cannot be placed at all. *
  680. * This determination is returned by the function. *
  681. * *
  682. * INPUT: object -- The building object that the current placement system is examining. *
  683. * *
  684. * OUTPUT: bool; Can the pending building object be placed at the present cursor location *
  685. * checking only for proximity to friendly buildings? If this isn't for a *
  686. * building type object, then this routine always returns true. *
  687. * *
  688. * WARNINGS: none *
  689. * *
  690. * HISTORY: *
  691. * 06/06/1994 JLB : Created. *
  692. * 06/07/1994 JLB : Handles concrete check. *
  693. *=============================================================================================*/
  694. bool DisplayClass::Passes_Proximity_Check(ObjectTypeClass const *object)
  695. {
  696. #ifdef USE_RA_AI
  697. return Passes_Proximity_Check(object, PendingHouse, CursorSize, ZoneCell + ZoneOffset);
  698. #else //USE_RA_AI // Replaced by more generic function from RA, for RA AI. ST - 7/24/2019 5:46PM
  699. short const *ptr;
  700. /*
  701. ** In editor mode, the proximity check always passes.
  702. */
  703. if (Debug_Map) {
  704. return(true);
  705. }
  706. if (!object || !CursorSize || object->What_Am_I() != RTTI_BUILDINGTYPE) {
  707. return(true);
  708. }
  709. /*
  710. ** Scan through all cells that the building foundation would cover. If any adjacent
  711. ** cells to these are of friendly persuasion, then consider the proximity check to
  712. ** have been a success.
  713. */
  714. ptr = CursorSize;
  715. while (*ptr != REFRESH_EOL) {
  716. CELL cell = ZoneCell + ZoneOffset + *ptr++;
  717. for (FacingType facing = FACING_N; facing < FACING_COUNT; facing++) {
  718. CELL newcell = Adjacent_Cell(cell, facing);
  719. if (!In_Radar(cell)) return(false);
  720. TechnoClass * base = (*this)[newcell].Cell_Techno();
  721. /*
  722. ** The special cell ownership flag allows building adjacent
  723. ** to friendly walls and bibs even though there is no official
  724. ** building located there.
  725. */
  726. if ((*this)[newcell].Owner == PendingHouse) {
  727. return(true);
  728. }
  729. if (base && base->What_Am_I() == RTTI_BUILDING && base->House->Class->House == PendingHouse) {
  730. return(true);
  731. }
  732. }
  733. }
  734. return(false);
  735. #endif
  736. }
  737. #ifdef USE_RA_AI
  738. /*
  739. ** Additional version of Passes_Proximity_Check, inspired by RA implementation. Needed for RA AI. ST - 7/24/2019 5:42PM
  740. */
  741. /***********************************************************************************************
  742. * DisplayClass::Passes_Proximity_Check -- Determines if building placement is near friendly sq*
  743. * *
  744. * This routine is used by the building placement cursor logic to determine whether the *
  745. * at the current cursor position if the building would be adjacent to another friendly *
  746. * building. In cases where this is not true, then the building cannot be placed at all. *
  747. * This determination is returned by the function. *
  748. * *
  749. * INPUT: object -- The building object that the current placement system is examining. *
  750. * *
  751. * house -- The house to base the proximity check upon. Typically this is the *
  752. * player's house, but in multiplay, the computer needs to check for *
  753. * proximity as well. *
  754. * *
  755. * list -- Pointer to the building's offset list. *
  756. * *
  757. * trycell -- The cell to base the offset list on. *
  758. * *
  759. * OUTPUT: bool; Can the pending building object be placed at the present cursor location *
  760. * checking only for proximity to friendly buildings? If this isn't for a *
  761. * building type object, then this routine always returns true. *
  762. * *
  763. * WARNINGS: none *
  764. * *
  765. * HISTORY: *
  766. * 06/06/1994 JLB : Created. *
  767. * 06/07/1994 JLB : Handles concrete check. *
  768. * 10/11/1994 BWG : Added IsProximate check for ore refineries *
  769. *=============================================================================================*/
  770. bool DisplayClass::Passes_Proximity_Check(ObjectTypeClass const * object, HousesType house, short const * list, CELL trycell) const
  771. {
  772. short const *ptr;
  773. /*
  774. ** In editor mode, the proximity check always passes.
  775. */
  776. if (Debug_Map) {
  777. return(true);
  778. }
  779. if (!object || object->What_Am_I() != RTTI_BUILDINGTYPE) {
  780. return(true);
  781. }
  782. /*
  783. ** Scan through all cells that the building foundation would cover. If any adjacent
  784. ** cells to these are of friendly persuasion, then consider the proximity check to
  785. ** have been a success.
  786. */
  787. ptr = list;
  788. while (*ptr != REFRESH_EOL) {
  789. CELL cell = trycell + *ptr++;
  790. for (FacingType facing = FACING_N; facing < FACING_COUNT; facing++) {
  791. CELL newcell = Adjacent_Cell(cell, facing);
  792. if (!In_Radar(cell)) return(false);
  793. TechnoClass * base = (*this)[newcell].Cell_Techno();
  794. /*
  795. ** The special cell ownership flag allows building adjacent
  796. ** to friendly walls and bibs even though there is no official
  797. ** building located there.
  798. */
  799. if ((*this)[newcell].Owner == house) {
  800. return(true);
  801. }
  802. if (base && base->What_Am_I() == RTTI_BUILDING && base->House->Class->House == house) {
  803. return(true);
  804. }
  805. }
  806. }
  807. return(false);
  808. }
  809. #endif //USE_RA_AI
  810. /***********************************************************************************************
  811. * DisplayClass::Set_Cursor_Pos -- Controls the display and animation of the tac cursor. *
  812. * *
  813. * This routine controls the location, display, and animation of the *
  814. * tactical map cursor. *
  815. * *
  816. * INPUT: pos -- Position to move the cursor do. If -1 is passed then *
  817. * the cursor will just be hidden. If the position *
  818. * passed is the same as the last position passed in, *
  819. * then animation could occur (based on timers). *
  820. * *
  821. * OUTPUT: none *
  822. * *
  823. * WARNINGS: none *
  824. * *
  825. * HISTORY: *
  826. * 05/22/1991 JLB : Created. *
  827. * 06/02/1994 JLB : Converted to member function. *
  828. * 06/08/1994 JLB : If position is -1, then follow mouse. *
  829. * 02/28/1995 JLB : Forces placement cursor to fit on map. *
  830. *=============================================================================================*/
  831. CELL DisplayClass::Set_Cursor_Pos(CELL pos)
  832. {
  833. CELL prevpos; // Last position of cursor (for jump-back reasons).
  834. /*
  835. ** Follow the mouse position if no cell number is provided.
  836. */
  837. if (pos == -1) {
  838. pos = Click_Cell_Calc(Get_Mouse_X(), Get_Mouse_Y());
  839. }
  840. if (!CursorSize) {
  841. prevpos = ZoneCell;
  842. ZoneCell = pos;
  843. return(prevpos);
  844. }
  845. /*
  846. ** Adjusts the position so that the placement cursor is never partway off the
  847. ** tactical map.
  848. */
  849. int w,h;
  850. Get_Occupy_Dimensions (w, h, CursorSize);
  851. int x = Cell_X(pos + ZoneOffset);
  852. int y = Cell_Y(pos + ZoneOffset);
  853. if (x < Coord_XCell(TacticalCoord)) x = Coord_XCell(TacticalCoord);
  854. // if (x < TacMapX) x = TacMapX;
  855. if (y < Coord_YCell(TacticalCoord)) y = Coord_YCell(TacticalCoord);
  856. // if (y < TacMapY) y = TacMapY;
  857. if (x+w >= Coord_XCell(TacticalCoord) + Lepton_To_Cell(TacLeptonWidth)) x = Coord_XCell(TacticalCoord)+Lepton_To_Cell(TacLeptonWidth)-w;
  858. // if (x+w >= TacMapX+TacWidth) x = TacMapX+TacWidth-w;
  859. if (y+h >= Coord_YCell(TacticalCoord) + Lepton_To_Cell(TacLeptonHeight)) x = Coord_YCell(TacticalCoord)+Lepton_To_Cell(TacLeptonHeight)-h;
  860. // if (y+h >= TacMapY+TacHeight) y = TacMapY+TacHeight-h;
  861. pos = XY_Cell(x, y) - ZoneOffset;
  862. /*
  863. ** This checks to see if NO animation or drawing is to occur and, if so,
  864. ** exits.
  865. */
  866. if (pos == ZoneCell) return(pos);
  867. prevpos = ZoneCell;
  868. /*
  869. ** If the cursor is visible, then handle the graphic update.
  870. ** Otherwise, just update the global position of the cursor.
  871. */
  872. if (CursorSize) {
  873. /*
  874. ** Erase the old cursor (if it exists) AND the cursor is moving.
  875. */
  876. if (pos != ZoneCell && ZoneCell != -1) {
  877. Cursor_Mark(ZoneCell+ZoneOffset, false);
  878. }
  879. /*
  880. ** Render the cursor (could just be animation).
  881. */
  882. if (pos != -1) {
  883. Cursor_Mark(pos+ZoneOffset, true);
  884. }
  885. }
  886. ZoneCell = pos;
  887. ProximityCheck = Passes_Proximity_Check(PendingObject);
  888. return(prevpos);
  889. }
  890. /***********************************************************************************************
  891. * DisplayClass::Get_Occupy_Dimensions -- computes width & height of the given occupy list *
  892. * *
  893. * INPUT: *
  894. * w ptr to fill in with height *
  895. * h ptr to fill in with width *
  896. * *
  897. * OUTPUT: *
  898. * none. *
  899. * *
  900. * WARNINGS: *
  901. * none. *
  902. * *
  903. * HISTORY: *
  904. * 03/31/1995 BRR : Created. *
  905. *=============================================================================================*/
  906. void DisplayClass::Get_Occupy_Dimensions(int & w, int & h, short const *list)
  907. {
  908. int min_x = MAP_CELL_W;
  909. int max_x = -MAP_CELL_W;
  910. int min_y = MAP_CELL_H;
  911. int max_y = -MAP_CELL_H;
  912. int x,y;
  913. w = 0;
  914. h = 0;
  915. if (!list) {
  916. /*
  917. ** Loop through all cell offsets, accumulating max & min x- & y-coords
  918. */
  919. while (*list != REFRESH_EOL) {
  920. /*
  921. ** Compute x & y coords of the current cell offset. We can't use Cell_X()
  922. ** & Cell_Y(), because they use shifts to compute the values, and if the
  923. ** offset is negative we'll get a bogus coordinate!
  924. */
  925. x = (*list) % MAP_CELL_W;
  926. y = (*list) / MAP_CELL_H;
  927. max_x = MAX(max_x, x);
  928. min_x = MIN(min_x, x);
  929. max_y = MAX(max_y, y);
  930. min_y = MIN(min_y, y);
  931. list++;
  932. }
  933. w = MAX(1, max_x - min_x + 1);
  934. h = MAX(1, max_y - min_y + 1);
  935. }
  936. }
  937. /***********************************************************************************************
  938. * DisplayClass::Cursor_Mark -- Set or resets the cursor display flag bits. *
  939. * *
  940. * This routine will clear or set the cursor display bits on the map. *
  941. * If the bit is set, then the cursor will be rendered on that map *
  942. * icon. *
  943. * *
  944. * INPUT: pos -- Position of the upper left corner of the cursor. *
  945. * *
  946. * on -- Should the bit be turned on? *
  947. * *
  948. * OUTPUT: none *
  949. * *
  950. * WARNINGS: Be sure that every call to set the bits is matched by a *
  951. * corresponding call to clear the bits. *
  952. * *
  953. * HISTORY: *
  954. * 09/04/1991 JLB : Created. *
  955. * 06/02/1994 JLB : Converted to member function. *
  956. *=============================================================================================*/
  957. void DisplayClass::Cursor_Mark(CELL pos, bool on)
  958. {
  959. CELL const *ptr;
  960. CellClass *cellptr;
  961. if ((unsigned)pos >= MAP_CELL_TOTAL) return;
  962. /*
  963. ** For every cell in the CursorSize list, invoke its Redraw_Objects and
  964. ** toggle its IsCursorHere flag
  965. */
  966. ptr = CursorSize;
  967. while (*ptr != REFRESH_EOL) {
  968. CELL cell = pos + *ptr++;
  969. if (In_Radar(cell)) {
  970. cellptr = &(*this)[cell];
  971. cellptr->Redraw_Objects();
  972. if (on) {
  973. cellptr->IsCursorHere = true;
  974. } else {
  975. cellptr->IsCursorHere = false;
  976. }
  977. }
  978. }
  979. /*
  980. ** For every cell in the PendingObjectPtr's Overlap_List, invoke its
  981. ** Redraw_Objects routine.
  982. */
  983. if (PendingObjectPtr) {
  984. ptr = PendingObjectPtr->Overlap_List();
  985. while (*ptr != REFRESH_EOL) {
  986. CELL cell = pos + *ptr++;
  987. if (In_Radar(cell)) {
  988. cellptr = &(*this)[cell];
  989. cellptr->Redraw_Objects();
  990. }
  991. }
  992. }
  993. }
  994. /***********************************************************************************************
  995. * DisplayClass::AI -- Handles the maintenance tasks for the map display. *
  996. * *
  997. * This routine is called once per game display frame (15 times per second). It handles *
  998. * the mouse shape tracking and map scrolling as necessary. *
  999. * *
  1000. * INPUT: input -- The next key just fetched from the input queue. *
  1001. * *
  1002. * x,y -- Mouse coordinates. *
  1003. * *
  1004. * OUTPUT: Modifies the input code if necessary. When the input code is consumed, it gets *
  1005. * set to 0. *
  1006. * *
  1007. * WARNINGS: none *
  1008. * *
  1009. * HISTORY: *
  1010. * 06/01/1994 JLB : Created. *
  1011. * 06/02/1994 JLB : Filters mouse click input. *
  1012. * 06/07/1994 JLB : Fixed so template click will behave right. *
  1013. * 10/14/1994 JLB : Changing cursor shape over target. *
  1014. * 12/31/1994 JLB : Takes mouse coordinates as parameters. *
  1015. * 06/27/1995 JLB : Breaks out of rubber band mode if mouse leaves map. *
  1016. *=============================================================================================*/
  1017. void DisplayClass::AI(KeyNumType & input, int x, int y)
  1018. {
  1019. if (
  1020. IsRubberBand &&
  1021. (Get_Mouse_X() < TacPixelX ||
  1022. Get_Mouse_Y() < TacPixelY ||
  1023. Get_Mouse_X() >= (TacPixelX + Lepton_To_Pixel(TacLeptonWidth)) ||
  1024. Get_Mouse_Y() >= (TacPixelY + Lepton_To_Pixel(TacLeptonHeight)))) {
  1025. Mouse_Left_Release(-1, Get_Mouse_X(), Get_Mouse_Y(), NULL, ACTION_NONE);
  1026. }
  1027. MapClass::AI(input, x, y);
  1028. }
  1029. /***********************************************************************************************
  1030. * DisplayClass::Submit -- Adds a game object to the map rendering system. *
  1031. * *
  1032. * This routine is used to add an arbitrary (but tangible) game object to the map. It will *
  1033. * be rendered (made visible) once it is submitted to this function. This function builds *
  1034. * the list of game objects that get rendered each frame as necessary. It is possible to *
  1035. * submit the game object to different rendering layers. All objects in a layer get drawn *
  1036. * at the same time. Using this layer method it becomes possible to have objects "below" *
  1037. * other objects. *
  1038. * *
  1039. * INPUT: object -- Pointer to the object to add. *
  1040. * *
  1041. * layer -- The layer to add the object to. *
  1042. * *
  1043. * OUTPUT: none *
  1044. * *
  1045. * WARNINGS: none *
  1046. * *
  1047. * HISTORY: *
  1048. * 05/31/1994 JLB : Created. *
  1049. * 05/31/1994 JLB : Improved layer system. *
  1050. * 05/31/1994 JLB : Sorts object position if this is for the ground layer. *
  1051. *=============================================================================================*/
  1052. void DisplayClass::Submit(ObjectClass const * object, LayerType layer)
  1053. {
  1054. if (object) {
  1055. Layer[layer].Submit(object, (layer == LAYER_GROUND));
  1056. }
  1057. }
  1058. /***********************************************************************************************
  1059. * DisplayClass::Remove -- Removes a game object from the rendering system. *
  1060. * *
  1061. * Every object that is to disappear from the map must be removed from the rendering *
  1062. * system. *
  1063. * *
  1064. * INPUT: object -- The object to remove. *
  1065. * *
  1066. * layer -- The layer to remove it from. *
  1067. * *
  1068. * OUTPUT: none *
  1069. * *
  1070. * WARNINGS: none *
  1071. * *
  1072. * HISTORY: *
  1073. * 05/31/1994 JLB : Created. *
  1074. * 05/31/1994 JLB : Improved layer system. *
  1075. *=============================================================================================*/
  1076. void DisplayClass::Remove(ObjectClass const * object, LayerType layer)
  1077. {
  1078. if (object) {
  1079. Layer[layer].Delete((ObjectClass *)object);
  1080. }
  1081. }
  1082. /***********************************************************************************************
  1083. * DisplayClass::Click_Cell_Calc -- Determines cell from screen X & Y. *
  1084. * *
  1085. * This routine is used to determine the cell that is located at the *
  1086. * screen pixel coordinates given. Typical use is when the player *
  1087. * clicks with the mouse on the tactical map. *
  1088. * *
  1089. * INPUT: x,y -- Screen pixel coordinates. *
  1090. * *
  1091. * OUTPUT: Returns with cell that is under the coordinates specified. *
  1092. * If the coordinate specified is outside of the tactical *
  1093. * map, then -1 is returned. *
  1094. * *
  1095. * WARNINGS: none *
  1096. * *
  1097. * HISTORY: *
  1098. * 05/27/1994 JLB : Created. *
  1099. *=============================================================================================*/
  1100. CELL DisplayClass::Click_Cell_Calc(int x, int y)
  1101. {
  1102. x -= TacPixelX;
  1103. x = Pixel_To_Lepton(x);
  1104. y -= TacPixelY;
  1105. y = Pixel_To_Lepton(y);
  1106. // Possibly ignore the view constraints if we aren't using the internal renderer. ST - 4/17/2019 9:06AM
  1107. //if (x < TacLeptonWidth && y < TacLeptonHeight) {
  1108. if (IgnoreViewConstraints || (x < TacLeptonWidth && y < TacLeptonHeight)) {
  1109. COORDINATE tcoord = XY_Coord(Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(TacticalCoord))), Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(TacticalCoord))));
  1110. return(Coord_Cell(Coord_Add(tcoord, XY_Coord(x, y))));
  1111. }
  1112. return(-1);
  1113. }
  1114. /***********************************************************************************************
  1115. * DisplayClass::Read_INI -- Reads map control data from INI file. *
  1116. * *
  1117. * This routine is used to read the map control data from the INI *
  1118. * file. *
  1119. * *
  1120. * INPUT: buffer -- Pointer to the loaded INI file data. *
  1121. * *
  1122. * OUTPUT: none *
  1123. * *
  1124. * WARNINGS: The TriggerClass INI data must have been read before calling this function. *
  1125. * *
  1126. * HISTORY: *
  1127. * 05/27/1994 JLB : Created. *
  1128. *=============================================================================================*/
  1129. void DisplayClass::Read_INI(char *buffer)
  1130. {
  1131. char name[16];
  1132. int len; // Length of data in buffer.
  1133. char *tbuffer; // Accumulation buffer of Trigger names.
  1134. char *trigsection = "CellTriggers";
  1135. char buf[20]; // trigger name for a cell
  1136. int cell;
  1137. int i;
  1138. /*
  1139. ** Read the map dimensions.
  1140. */
  1141. Set_Map_Dimensions(WWGetPrivateProfileInt("MAP", "X", 1, buffer),
  1142. WWGetPrivateProfileInt("MAP", "Y", 1, buffer),
  1143. WWGetPrivateProfileInt("MAP", "Width", MAP_CELL_W-2, buffer),
  1144. WWGetPrivateProfileInt("MAP", "Height", MAP_CELL_H-2, buffer));
  1145. /*
  1146. ** The theater is determined at this point. There is specific data that
  1147. ** is custom to this data. Load the custom data (as it related to terrain)
  1148. ** at this point.
  1149. */
  1150. WWGetPrivateProfileString("MAP", "Theater", Theaters[THEATER_DESERT].Name, name, 13, buffer);
  1151. Theater = Theater_From_Name(name);
  1152. if (Theater == THEATER_NONE) {
  1153. Theater = THEATER_DESERT;
  1154. }
  1155. /*
  1156. ** Remove any old theater specific uncompressed shapes
  1157. */
  1158. if (Theater != LastTheater){
  1159. Reset_Theater_Shapes();
  1160. }
  1161. /*
  1162. ** Now that the theater is known, init the entire map hierarchy
  1163. */
  1164. Init(Theater);
  1165. /*
  1166. ** Special initializations occur when the theater is known.
  1167. */
  1168. TerrainTypeClass::Init(Theater);
  1169. TemplateTypeClass::Init(Theater);
  1170. OverlayTypeClass::Init(Theater);
  1171. UnitTypeClass::Init(Theater);
  1172. InfantryTypeClass::Init(Theater);
  1173. BuildingTypeClass::Init(Theater);
  1174. BulletTypeClass::Init(Theater);
  1175. AnimTypeClass::Init(Theater);
  1176. AircraftTypeClass::Init(Theater);
  1177. SmudgeTypeClass::Init(Theater);
  1178. LastTheater = Theater;
  1179. /*
  1180. ** Read the Waypoint entries.
  1181. */
  1182. for (i = 0; i < WAYPT_COUNT; i++) {
  1183. sprintf(buf,"%d",i);
  1184. Waypoint[i] = WWGetPrivateProfileInt ("Waypoints",buf,-1,buffer);
  1185. if (Waypoint[i] != -1) {
  1186. (*this)[Waypoint[i]].IsWaypoint = 1;
  1187. }
  1188. }
  1189. /*
  1190. ** Set the starting position (do this after Init(), which clears the cells'
  1191. ** IsWaypoint flags).
  1192. */
  1193. if (Waypoint[WAYPT_HOME] == -1) {
  1194. Waypoint[WAYPT_HOME] = XY_Cell(MapCellX, MapCellY);
  1195. }
  1196. Set_Tactical_Position(Cell_Coord(Waypoint[WAYPT_HOME])&0xFF00FF00L);
  1197. Views[0] = Views[1] = Views[2] = Views[3] = Waypoint[WAYPT_HOME];
  1198. /*
  1199. ** Read the cell trigger names, and assign TriggerClass pointers
  1200. */
  1201. len = strlen(buffer) + 2; // len is the length of the INI data
  1202. tbuffer = buffer + len; // tbuffer is after the INI data
  1203. /*
  1204. ** Read all entry names into 'tbuffer'.
  1205. */
  1206. WWGetPrivateProfileString(trigsection, NULL, NULL, tbuffer, ShapeBufferSize-len, buffer);
  1207. /*
  1208. ** Loop through all CellTrigger entries.
  1209. */
  1210. while (*tbuffer != '\0') {
  1211. /*
  1212. ** Get a cell trigger assignment.
  1213. */
  1214. WWGetPrivateProfileString(trigsection, tbuffer, NULL, buf, sizeof(buf) - 1, buffer);
  1215. /*
  1216. ** Get cell # from entry name.
  1217. */
  1218. cell = atoi(tbuffer);
  1219. if (cell > 0 && cell < MAP_CELL_TOTAL && !(*this)[cell].IsTrigger) {
  1220. /*
  1221. ** Assign trigger pointer using trigger name.
  1222. */
  1223. CellTriggers[cell] = TriggerClass::As_Pointer(buf);
  1224. if (CellTriggers[cell]) {
  1225. (*this)[cell].IsTrigger = 1;
  1226. if (CellTriggers[cell]) {
  1227. CellTriggers[cell]->AttachCount++;
  1228. }
  1229. }
  1230. }
  1231. /*
  1232. ** Step to next entry name.
  1233. */
  1234. tbuffer += strlen(tbuffer) + 1;
  1235. }
  1236. }
  1237. /***********************************************************************************************
  1238. * DisplayClass::Write_INI -- Writes map data into INI file. *
  1239. * *
  1240. * This routine is used to write the map control data into the INI *
  1241. * file. The scenario editor uses this when creating the scenario *
  1242. * startup file. *
  1243. * *
  1244. * INPUT: buffer -- Pointer to INI file data. *
  1245. * *
  1246. * OUTPUT: none *
  1247. * *
  1248. * WARNINGS: none *
  1249. * *
  1250. * HISTORY: *
  1251. * 05/27/1994 JLB : Created. *
  1252. *=============================================================================================*/
  1253. void DisplayClass::Write_INI(char *buffer)
  1254. {
  1255. char entry[20];
  1256. /*
  1257. ** Save the map parameters.
  1258. */
  1259. WWWritePrivateProfileString("MAP", "Theater", Theaters[Theater].Name, buffer);
  1260. WWWritePrivateProfileInt("MAP", "X", MapCellX, buffer);
  1261. WWWritePrivateProfileInt("MAP", "Y", MapCellY, buffer);
  1262. WWWritePrivateProfileInt("MAP", "Width", MapCellWidth, buffer);
  1263. WWWritePrivateProfileInt("MAP", "Height", MapCellHeight, buffer);
  1264. /*
  1265. ** Save the Waypoint entries.
  1266. */
  1267. for (int i = 0; i < WAYPT_COUNT; i++) {
  1268. sprintf(entry,"%d",i);
  1269. WWWritePrivateProfileInt ("Waypoints",entry,Waypoint[i],buffer);
  1270. }
  1271. /*
  1272. ** Erase the CellTriggers section.
  1273. */
  1274. WWWritePrivateProfileString("CellTriggers",NULL,NULL,buffer);
  1275. /*
  1276. ** Save the cell's triggers.
  1277. */
  1278. for (CELL cell = 0; cell < MAP_CELL_TOTAL; cell++) {
  1279. if ((*this)[cell].IsTrigger) {
  1280. /*
  1281. ** Get cell trigger pointer.
  1282. */
  1283. TriggerClass const * trig = CellTriggers[cell];
  1284. /*
  1285. ** Generate entry name.
  1286. */
  1287. sprintf(entry,"%d",cell);
  1288. /*
  1289. ** Save entry.
  1290. */
  1291. WWWritePrivateProfileString("CellTriggers", entry, trig->Get_Name(), buffer);
  1292. }
  1293. }
  1294. }
  1295. /***********************************************************************************************
  1296. * DisplayClass::Scroll_Map -- Scroll the tactical map in desired direction. *
  1297. * *
  1298. * This routine is used to scroll the tactical map view in the desired *
  1299. * direction. It can also be used to determine if scrolling would be *
  1300. * legal without actually performing any scrolling action. *
  1301. * *
  1302. * INPUT: facing -- The direction to scroll the tactical map. *
  1303. * *
  1304. * distance -- The distance in leptons to scroll the map. *
  1305. * *
  1306. * really -- Should the map actually be scrolled? If false, *
  1307. * then only the legality of a scroll is checked. *
  1308. * *
  1309. * OUTPUT: bool; Would scrolling in the desired direction be possible? *
  1310. * *
  1311. * WARNINGS: none *
  1312. * *
  1313. * HISTORY: *
  1314. * 10/07/1992 JLB : Created. *
  1315. * 05/20/1994 JLB : Converted to member function. *
  1316. * 08/09/1995 JLB : Added distance parameter. *
  1317. * 08/10/1995 JLB : Any direction scrolling. *
  1318. *=============================================================================================*/
  1319. bool DisplayClass::Scroll_Map(DirType facing, int & distance, bool really)
  1320. {
  1321. /*
  1322. ** If the distance is invalid then no further checking is required. Bail
  1323. ** with a no-can-do flag.
  1324. */
  1325. if (distance == 0) return(false);
  1326. FacingType crude = Dir_Facing(facing);
  1327. if (Coord_X(TacticalCoord) == Cell_To_Lepton(MapCellX) && crude != FACING_W) {
  1328. if (crude == FACING_SW) facing = DIR_S;
  1329. if (crude == FACING_NW) facing = DIR_N;
  1330. }
  1331. if (Coord_Y(TacticalCoord) == Cell_To_Lepton(MapCellY) && crude != FACING_N) {
  1332. if (crude == FACING_NW) facing = DIR_W;
  1333. if (crude == FACING_NE) facing = DIR_E;
  1334. }
  1335. if (Coord_X(TacticalCoord) + TacLeptonWidth == Cell_To_Lepton(MapCellX+MapCellWidth) && crude != FACING_E) {
  1336. if (crude == FACING_NE) facing = DIR_N;
  1337. if (crude == FACING_SE) facing = DIR_S;
  1338. }
  1339. if (Coord_Y(TacticalCoord) + TacLeptonHeight == Cell_To_Lepton(MapCellY+MapCellHeight) && crude != FACING_S) {
  1340. if (crude == FACING_SE) facing = DIR_E;
  1341. if (crude == FACING_SW) facing = DIR_W;
  1342. }
  1343. /*
  1344. ** Determine the coordinate that it wants to scroll to.
  1345. */
  1346. COORDINATE coord = Coord_Move(TacticalCoord, facing, distance);
  1347. /*
  1348. ** Clip the new coordinate to the edges of the game world.
  1349. */
  1350. int xx = Coord_X(coord) - Cell_To_Lepton(MapCellX);
  1351. int yy = Coord_Y(coord) - Cell_To_Lepton(MapCellY);
  1352. bool shifted = Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, Cell_To_Lepton(MapCellWidth), Cell_To_Lepton(MapCellHeight));
  1353. if (xx < 0) {
  1354. xx = 0;
  1355. shifted = true;
  1356. }
  1357. if (yy < 0) {
  1358. yy = 0;
  1359. shifted = true;
  1360. }
  1361. coord = XY_Coord(xx + Cell_To_Lepton(MapCellX), yy + Cell_To_Lepton(MapCellY));
  1362. /*
  1363. ** If the desired scroll was bound by the edge of the map, then adjust the distance to more accurately
  1364. ** reflect the actual distance moved.
  1365. */
  1366. if (shifted) {
  1367. distance = Distance(TacticalCoord, coord);
  1368. }
  1369. /*
  1370. ** If the new coordinate is the same as the old, then no scrolling would occur.
  1371. */
  1372. if (!distance || coord == TacticalCoord) return(false);
  1373. /*
  1374. ** Since the new coordinate is different than the old one, possibly adjust the real
  1375. ** tactical map accordingly.
  1376. */
  1377. if (really) {
  1378. Set_Tactical_Position(coord);
  1379. IsToRedraw = true;
  1380. Flag_To_Redraw(false);
  1381. }
  1382. return(true);
  1383. }
  1384. /***********************************************************************************************
  1385. * DisplayClass::Refresh_Cells -- Redraws all cells in list. *
  1386. * *
  1387. * This routine is used to flag all cells in the specified list for *
  1388. * redrawing. *
  1389. * *
  1390. * INPUT: cell -- The origin cell that the list is offset from. *
  1391. * *
  1392. * list -- Pointer to a list of offsets from the origin cell. *
  1393. * Each cell so specified is flagged for redraw. *
  1394. * *
  1395. * OUTPUT: none *
  1396. * *
  1397. * WARNINGS: This routine is rather slow (by definition). *
  1398. * *
  1399. * HISTORY: *
  1400. * 05/14/1994 JLB : Created. *
  1401. * 08/01/1994 JLB : Simplified. *
  1402. *=============================================================================================*/
  1403. void DisplayClass::Refresh_Cells(CELL cell, short const *list)
  1404. {
  1405. if (*list == REFRESH_SIDEBAR) {
  1406. list++;
  1407. }
  1408. while (*list != REFRESH_EOL) {
  1409. CELL newcell = cell + *list++;
  1410. if (In_Radar(newcell)) {
  1411. (*this)[newcell].Redraw_Objects();
  1412. }
  1413. }
  1414. }
  1415. /***********************************************************************************************
  1416. * DisplayClass::Cell_Shadow -- Determine what shadow icon to use for the cell. *
  1417. * *
  1418. * This routine will examine the specified cell and adjacent cells to *
  1419. * determine what shadow icon to use. *
  1420. * *
  1421. * INPUT: cell -- The cell to examine. *
  1422. * *
  1423. * OUTPUT: Returns with the shadow icon to use. -2= all black. *
  1424. * -1= map cell. *
  1425. * *
  1426. * WARNINGS: none *
  1427. * *
  1428. * HISTORY: *
  1429. * 03/01/1994 JLB : Created. *
  1430. * 04/04/1994 JLB : Revamped for new shadow icon method. *
  1431. * 04/30/1994 JLB : Converted to member function. *
  1432. * 03/06/2019 ST : Added house parameter so we can do this per player *
  1433. *=============================================================================================*/
  1434. int DisplayClass::Cell_Shadow(CELL cell, HouseClass *house)
  1435. {
  1436. if (house == NULL) {
  1437. return -1;
  1438. }
  1439. int index;
  1440. int value = -1;
  1441. CellClass *cellptr;
  1442. static char const CardShadow[16] = {-2,0,1,2,3,-1,4,-1,5,6,-1,-1,7,-1,-1,-1};
  1443. static char const DiagShadow[16] = {-2,8,9,-1,10,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1};
  1444. /*
  1445. ** Don't map cells that are at the edges. This solves
  1446. ** problem of accessing cells off the bounds of map and into
  1447. ** who-knows-what memory.
  1448. */
  1449. if ((unsigned)(Cell_X(cell)-1) >= MAP_CELL_W-2) return(-2);
  1450. if ((unsigned)(Cell_Y(cell)-1) >= MAP_CELL_H-2) return(-2); // Changed > to >= per Red Alert to fix out of bounds crash. ST - 3/25/2020 11:02PM
  1451. cellptr = &(*this)[cell];
  1452. if (!cellptr->Is_Mapped(house)) {
  1453. /*
  1454. ** Check the cardinal directions first. This will either result
  1455. ** in a solution or the flag to check the diagonals.
  1456. */
  1457. index = 0;
  1458. cellptr--;
  1459. if (cellptr->Is_Mapped(house)) index |= 0x08;
  1460. cellptr += MAP_CELL_W+1;
  1461. if (cellptr->Is_Mapped(house)) index |= 0x04;
  1462. cellptr -= MAP_CELL_W-1;
  1463. if (cellptr->Is_Mapped(house)) index |= 0x02;
  1464. cellptr -= MAP_CELL_W+1;
  1465. if (cellptr->Is_Mapped(house)) index |= 0x01;
  1466. value = CardShadow[index];
  1467. /*
  1468. ** The diagonals must be checked, since the cardinal directions
  1469. ** did not yield a valid result.
  1470. */
  1471. if (value == -2) {
  1472. index = 0;
  1473. cellptr--;
  1474. if (cellptr->Is_Mapped(house)) index |= 0x08;
  1475. cellptr += MAP_CELL_W*2;
  1476. if (cellptr->Is_Mapped(house)) index |= 0x04;
  1477. cellptr += 2;
  1478. if (cellptr->Is_Mapped(house)) index |= 0x02;
  1479. cellptr -= MAP_CELL_W*2;
  1480. if (cellptr->Is_Mapped(house)) index |= 0x01;
  1481. value = DiagShadow[index];
  1482. }
  1483. /*
  1484. ** Randomizer should go here. Add sets in multiples of 12.
  1485. */
  1486. }
  1487. return(value);
  1488. }
  1489. #if (0)
  1490. /***********************************************************************************************
  1491. * DisplayClass::Cell_Shadow -- Determine what shadow icon to use for the cell. *
  1492. * *
  1493. * This routine will examine the specified cell and adjacent cells to *
  1494. * determine what shadow icon to use. *
  1495. * *
  1496. * INPUT: cell -- The cell to examine. *
  1497. * *
  1498. * OUTPUT: Returns with the shadow icon to use. -2= all black. *
  1499. * -1= map cell. *
  1500. * *
  1501. * WARNINGS: none *
  1502. * *
  1503. * HISTORY: *
  1504. * 03/01/1994 JLB : Created. *
  1505. * 04/04/1994 JLB : Revamped for new shadow icon method. *
  1506. * 04/30/1994 JLB : Converted to member function. *
  1507. *=============================================================================================*/
  1508. int DisplayClass::Cell_Shadow(CELL cell)
  1509. {
  1510. int index;
  1511. int value = -1;
  1512. CellClass *cellptr;
  1513. static char const CardShadow[16] = {-2,0,1,2,3,-1,4,-1,5,6,-1,-1,7,-1,-1,-1};
  1514. static char const DiagShadow[16] = {-2,8,9,-1,10,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1};
  1515. /*
  1516. ** Don't map cells that are at the top or bottom edge. This solves
  1517. ** problem of accessing cells off the top or bottom of the map and into
  1518. ** who-knows-what memory.
  1519. */
  1520. if ((unsigned)(Cell_Y(cell)-1) > MAP_CELL_H-2) return(-2);
  1521. cellptr = &(*this)[cell];
  1522. if (!cellptr->IsMapped) {
  1523. /*
  1524. ** Check the cardinal directions first. This will either result
  1525. ** in a solution or the flag to check the diagonals.
  1526. */
  1527. index = 0;
  1528. cellptr--;
  1529. if (cellptr->IsMapped) index |= 0x08;
  1530. cellptr += MAP_CELL_W+1;
  1531. if (cellptr->IsMapped) index |= 0x04;
  1532. cellptr -= MAP_CELL_W-1;
  1533. if (cellptr->IsMapped) index |= 0x02;
  1534. cellptr -= MAP_CELL_W+1;
  1535. if (cellptr->IsMapped) index |= 0x01;
  1536. value = CardShadow[index];
  1537. /*
  1538. ** The diagonals must be checked, since the cardinal directions
  1539. ** did not yield a valid result.
  1540. */
  1541. if (value == -2) {
  1542. index = 0;
  1543. cellptr--;
  1544. if (cellptr->IsMapped) index |= 0x08;
  1545. cellptr += MAP_CELL_W*2;
  1546. if (cellptr->IsMapped) index |= 0x04;
  1547. cellptr += 2;
  1548. if (cellptr->IsMapped) index |= 0x02;
  1549. cellptr -= MAP_CELL_W*2;
  1550. if (cellptr->IsMapped) index |= 0x01;
  1551. value = DiagShadow[index];
  1552. }
  1553. /*
  1554. ** Randomizer should go here. Add sets in multiples of 12.
  1555. */
  1556. }
  1557. return(value);
  1558. }
  1559. #endif
  1560. /***********************************************************************************************
  1561. * DisplayClass::Map_Cell -- Mark specified cell as having been mapped. *
  1562. * *
  1563. * This routine maps the specified cell. The cell must not already *
  1564. * have been mapped and the mapping player must be the human. *
  1565. * This routine will update any adjacent cell map icon as appropriate. *
  1566. * *
  1567. * INPUT: cell -- The cell to be mapped. *
  1568. * *
  1569. * house -- The player that is doing the mapping. *
  1570. * *
  1571. * OUTPUT: bool; Was action taken to map this cell? *
  1572. * *
  1573. * WARNINGS: none. *
  1574. * *
  1575. * HISTORY: *
  1576. * 08/05/1992 JLB : Created. *
  1577. * 04/30/1994 JLB : Converted to member function. *
  1578. * 05/24/1994 JLB : Takes pointer to HouseClass. *
  1579. * 03/06/2019 ST : Use per-player mapping so we can track the shroud for all players *
  1580. *=============================================================================================*/
  1581. bool DisplayClass::Map_Cell(CELL cell, HouseClass * house, bool and_for_allies)
  1582. {
  1583. // It's OK to do this if the house isn't the local player. ST - 3/6/2019 11:06AM
  1584. //if (house != PlayerPtr || cell >= (CELL)Size) return(false);
  1585. if (house == NULL || cell >= (CELL)Size) return(false);
  1586. if (!house->IsHuman) {
  1587. if (!ShareAllyVisibility || !and_for_allies) {
  1588. return false;
  1589. }
  1590. }
  1591. /*
  1592. ** Maybe also recurse to map for allies
  1593. */
  1594. if (ShareAllyVisibility && and_for_allies) {
  1595. HousesType first_house = (GameToPlay == GAME_NORMAL) ? HOUSE_FIRST : HOUSE_MULTI1;
  1596. for (HousesType house_type = first_house; house_type < HOUSE_COUNT; house_type++) {
  1597. HouseClass *hptr = HouseClass::As_Pointer(house_type);
  1598. if (hptr && hptr->IsActive) {
  1599. if (hptr != house && house->Is_Ally(hptr)) {
  1600. Map_Cell(cell, hptr, false);
  1601. }
  1602. }
  1603. }
  1604. }
  1605. /*
  1606. ** Don't bother remapping this cell if it is already mapped.
  1607. */
  1608. //if ((*this)[cell].IsMapped) {
  1609. if ((*this)[cell].Is_Mapped(house)) { // Check by player. ST - 3/6/2019 10:28AM
  1610. return(false);
  1611. }
  1612. /*
  1613. ** Mark the cell as being mapped.
  1614. */
  1615. //(*this)[cell].IsMapped = true;
  1616. //(*this)[cell].IsVisible = true;
  1617. // Set by player. ST - 3/6/2019 10:29AM
  1618. (*this)[cell].Set_Mapped(house);
  1619. (*this)[cell].Set_Visible(house);
  1620. (*this)[cell].Redraw_Objects();
  1621. /*
  1622. ** Check out all adjacent cells to see if they need
  1623. ** to be mapped as well. This is necessary because of the
  1624. ** "unique" method of showing shadowed cells. Many combinations
  1625. ** are not allowed, and to fix this, just map the cells until
  1626. ** all is ok.
  1627. */
  1628. int xx = Cell_X(cell);
  1629. for (FacingType dir = FACING_FIRST; dir < FACING_COUNT; dir++) {
  1630. int shadow;
  1631. CELL c;
  1632. int xdiff;
  1633. c = Adjacent_Cell(cell, dir);
  1634. /*
  1635. ** Determine if the map edge has been wrapped. If so,
  1636. ** then don't process the cell.
  1637. */
  1638. if ((unsigned)c >= MAP_CELL_TOTAL) continue;
  1639. xdiff = Cell_X(c) - xx;
  1640. xdiff = ABS(xdiff);
  1641. if (xdiff > 1) continue;
  1642. if (c != cell && !(*this)[c].Is_Mapped(house)) { // Check by player. ST - 3/6/2019 10:28AM
  1643. shadow = Cell_Shadow(c, house);
  1644. /*
  1645. ** Either map the cell or mark it to be refreshed. It
  1646. ** will probably change form if it isn't actually mapped.
  1647. */
  1648. if (shadow == -1) {
  1649. Map_Cell(c, house, false);
  1650. } else {
  1651. if (shadow != -2) {
  1652. //(*this)[c].IsVisible = true;
  1653. (*this)[c].Set_Visible(house); // Set by player. ST - 3/6/2019 11:07AM
  1654. (*this)[c].Redraw_Objects();
  1655. }
  1656. }
  1657. }
  1658. }
  1659. TechnoClass * tech = (*this)[cell].Cell_Techno();
  1660. if (tech) {
  1661. tech->Revealed(house);
  1662. }
  1663. return(true);
  1664. }
  1665. /***********************************************************************************************
  1666. * DisplayClass::Coord_To_Pixel -- Determines X and Y pixel coordinates. *
  1667. * *
  1668. * This is the routine that figures out the location on the screen for *
  1669. * a specified coordinate. It is one of the fundamental routines *
  1670. * necessary for rendering the game objects. It performs some quick *
  1671. * tests to see if the coordinate is in a visible region and returns *
  1672. * this check as a boolean value. *
  1673. * *
  1674. * INPUT: coord -- The coordinate to check. *
  1675. * *
  1676. * x,y -- Reference to the pixel coordinates that this *
  1677. * coordinate would be when rendered. *
  1678. * *
  1679. * OUTPUT: bool; Is this coordinate in a visible portion of the map? *
  1680. * *
  1681. * WARNINGS: If the coordinate is not in a visible portion of the *
  1682. * map, then this X and Y parameters are not set. *
  1683. * *
  1684. * HISTORY: *
  1685. * 05/14/1994 JLB : Created. *
  1686. * 12/15/1994 JLB : Converted to member function. *
  1687. * 01/07/1995 JLB : Uses inline functions to extract coord components. *
  1688. * 08/09/1995 JLB : Uses new coordinate system. *
  1689. *=============================================================================================*/
  1690. #define EDGE_ZONE (CELL_LEPTON_W*2)
  1691. bool DisplayClass::Coord_To_Pixel(COORDINATE coord, int &x, int &y)
  1692. {
  1693. int xtac = Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(TacticalCoord)));
  1694. int xoff = Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(coord)));
  1695. xoff = (xoff + EDGE_ZONE) - xtac;
  1696. int ytac = Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(TacticalCoord)));
  1697. int yoff = Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(coord)));
  1698. yoff = (yoff + EDGE_ZONE) - ytac;
  1699. x = Lepton_To_Pixel(xoff) - CELL_PIXEL_W * 2;
  1700. y = Lepton_To_Pixel(yoff) - CELL_PIXEL_H * 2;
  1701. // Possibly ignore the view constraints if we aren't using the internal renderer. ST - 4/17/2019 9:06AM
  1702. return(coord && (IgnoreViewConstraints || ((xoff <= TacLeptonWidth + EDGE_ZONE * 2) && (yoff <= TacLeptonHeight + EDGE_ZONE * 2))));
  1703. }
  1704. #if (0) // reference. ST - 4/17/2019 9:07AM
  1705. bool DisplayClass::Coord_To_Pixel(COORDINATE coord, int &x, int &y)
  1706. {
  1707. if (coord) {
  1708. int xtac = Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(TacticalCoord)));
  1709. int xoff = Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(coord)));
  1710. xoff = (xoff+EDGE_ZONE) - xtac;
  1711. if (xoff <= TacLeptonWidth + EDGE_ZONE*2) {
  1712. int ytac = Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(TacticalCoord)));
  1713. int yoff = Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(coord)));
  1714. yoff = (yoff+EDGE_ZONE) - ytac;
  1715. if (yoff <= TacLeptonHeight + EDGE_ZONE*2) {
  1716. x = Lepton_To_Pixel(xoff)-CELL_PIXEL_W*2;
  1717. y = Lepton_To_Pixel(yoff)-CELL_PIXEL_H*2;
  1718. return(true);
  1719. }
  1720. }
  1721. }
  1722. return(false);
  1723. }
  1724. #endif
  1725. /***********************************************************************************************
  1726. * DisplayClass::Push_Onto_TacMap -- Moves x & y coords to being on tactical map *
  1727. * *
  1728. * This routine expects a line to be drawn between SOURCE & DEST, so it pushes the coords to *
  1729. * be within the region bounded by TacMapX,Y - + TacMapW,H. *
  1730. * *
  1731. * INPUT: source, dest -- References to the coordinates to check. *
  1732. * *
  1733. * *
  1734. * OUTPUT: bool; Are these coordinates in a visible portion of the map? *
  1735. * Returns true if the pushed source & dest are visible, but if neither are *
  1736. * within the map, then it returns false. *
  1737. * *
  1738. * *
  1739. * HISTORY: *
  1740. * 03/27/1995 BWG : Created. *
  1741. *=============================================================================================*/
  1742. bool DisplayClass::Push_Onto_TacMap(COORDINATE &source, COORDINATE &dest)
  1743. {
  1744. if (!source || !dest) return(false);
  1745. int x1 = Coord_X(source);
  1746. int y1 = Coord_Y(source);
  1747. int x2 = Coord_X(dest);
  1748. int y2 = Coord_Y(dest);
  1749. int left = Coord_X(TacticalCoord);
  1750. int right = Coord_X(TacticalCoord) + TacLeptonWidth;
  1751. int top = Coord_Y(TacticalCoord);
  1752. int bottom = Coord_Y(TacticalCoord) + TacLeptonHeight;
  1753. if (x1 < left && x2 < left) return(false);
  1754. if (x1 > right && x2 > right) return(false);
  1755. if (y1 < top && y2 < top) return(false);
  1756. if (y1 > bottom && y2 > bottom) return(false);
  1757. x1 = Bound(x1, left, right);
  1758. x2 = Bound(x2, left, right);
  1759. y1 = Bound(y1, top, bottom);
  1760. y2 = Bound(y2, top, bottom);
  1761. source = XY_Coord(x1, y1);
  1762. dest = XY_Coord(x2, y2);
  1763. return(true);
  1764. }
  1765. /***********************************************************************************************
  1766. * DisplayClass::Cell_Object -- Determines what has been clicked on. *
  1767. * *
  1768. * This routine is used to determine what the player has clicked on. *
  1769. * It is passed the cell that the click was on and it then examines *
  1770. * the cell and returns with a pointer to the object that is there. *
  1771. * *
  1772. * INPUT: cell -- The cell that has been clicked upon. *
  1773. * *
  1774. * x,y -- Optional offsets from the upper left corner of the cell to be used in *
  1775. * determining exactly which object in the cell is desired. *
  1776. * *
  1777. * OUTPUT: Returns with a pointer to the object that is "clickable" in *
  1778. * the specified cell. *
  1779. * *
  1780. * WARNINGS: none *
  1781. * *
  1782. * HISTORY: *
  1783. * 05/14/1994 JLB : Created. *
  1784. *=============================================================================================*/
  1785. ObjectClass * DisplayClass::Cell_Object(CELL cell, int x, int y)
  1786. {
  1787. return(*this)[cell].Cell_Object(x, y);
  1788. }
  1789. /***********************************************************************************************
  1790. * DisplayClass::Draw_It -- Draws the tactical map. *
  1791. * *
  1792. * This will draw the tactical map at the recorded position. This *
  1793. * routine is used whenever the tactical map moves or needs to be *
  1794. * completely redrawn. It will handle making the necessary adjustments *
  1795. * to accomodate a moving cursor. *
  1796. * *
  1797. * INPUT: forced -- bool; force redraw of the entire display? *
  1798. * *
  1799. * OUTPUT: none *
  1800. * *
  1801. * WARNINGS: none *
  1802. * *
  1803. * HISTORY: *
  1804. * 04/15/1991 JLB : Created. (benchmark = 292) *
  1805. * 04/15/1991 JLB : Added _cell2meta[] reference array (206) *
  1806. * 04/15/1991 JLB : Added actual map reference for terrain (207) *
  1807. * 04/16/1991 JLB : _cell2meta converted to int (194) *
  1808. * 04/16/1991 JLB : References actual CellIcon[] array (204) *
  1809. * 04/16/1991 JLB : Cell size increased to 16 x 16 (167) *
  1810. * 04/17/1991 JLB : Cell based tactical map rendering (165) *
  1811. * 04/22/1991 JLB : Uses Draw_Stamp() for icon rendering (426) *
  1812. * 04/22/1991 JLB : Draw_Stamp uses LogicPage now (276) *
  1813. * 04/23/1991 JLB : Map active location cursor (334) *
  1814. * 05/02/1991 JLB : Added smoothing and 3 icons sets (431) *
  1815. * 05/22/1991 JLB : Broken into Draw_Map() and Refresh_Map(). *
  1816. * 09/14/1991 JLB : Uses Refresh_Cell when new cells scroll onto display. *
  1817. * 05/12/1992 JLB : Destination page support. *
  1818. * 02/14/1994 JLB : Revamped. *
  1819. * 05/01/1994 JLB : Converted to member function. *
  1820. * 12/15/1994 JLB : Updated to work with display heirarchy. *
  1821. * 12/24/1994 JLB : Examines redraw bit intelligently. *
  1822. * 12/24/1994 JLB : Combined with old Refresh_Map() function. *
  1823. * 01/10/1995 JLB : Rubber band drawing. *
  1824. *=============================================================================================*/
  1825. void DisplayClass::Draw_It(bool forced)
  1826. {
  1827. int x,y; // Working cell index values.
  1828. MapClass::Draw_It(forced);
  1829. if (IsToRedraw || forced) {
  1830. IsToRedraw = false;
  1831. /*
  1832. ** In rubber band mode, mark all cells under the "rubber band" to be
  1833. ** redrawn.
  1834. */
  1835. Refresh_Band();
  1836. /*
  1837. ** If the multiplayer message system is displaying one or more messages,
  1838. ** flag all cells covered by the messages to redraw. This will prevent
  1839. ** messages from smearing the map if it scrolls.
  1840. */
  1841. int num = Messages.Num_Messages();
  1842. if (num) {
  1843. CELL cell;
  1844. for (cell = Coord_Cell(TacticalCoord); cell < Coord_Cell(TacticalCoord) + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1845. (*this)[cell].Redraw_Objects();
  1846. }
  1847. for (cell = Coord_Cell(TacticalCoord) + MAP_CELL_W;
  1848. cell < Coord_Cell(TacticalCoord) + MAP_CELL_W + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1849. (*this)[cell].Redraw_Objects();
  1850. }
  1851. if (num > 1) {
  1852. for (cell = Coord_Cell(TacticalCoord) + MAP_CELL_W*2;
  1853. cell < Coord_Cell(TacticalCoord) + MAP_CELL_W*2 + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1854. (*this)[cell].Redraw_Objects();
  1855. }
  1856. }
  1857. if (num > 3) {
  1858. for (cell = Coord_Cell(TacticalCoord) + MAP_CELL_W*3;
  1859. cell < Coord_Cell(TacticalCoord) + MAP_CELL_W*3 + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1860. (*this)[cell].Redraw_Objects();
  1861. }
  1862. }
  1863. if (num > 4) {
  1864. for (cell = Coord_Cell(TacticalCoord) + MAP_CELL_W*4;
  1865. cell < Coord_Cell(TacticalCoord) + MAP_CELL_W*4 + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1866. (*this)[cell].Redraw_Objects();
  1867. }
  1868. }
  1869. }
  1870. /*
  1871. ** Check for a movement of the tactical map. If there has been some
  1872. ** movement, then part (or all) of the icons must be redrawn.
  1873. */
  1874. if (Lepton_To_Pixel(Coord_X(DesiredTacticalCoord)) != Lepton_To_Pixel(Coord_X(TacticalCoord)) ||
  1875. Lepton_To_Pixel(Coord_Y(DesiredTacticalCoord)) != Lepton_To_Pixel(Coord_Y(TacticalCoord))) {
  1876. int xmod = Lepton_To_Pixel(Coord_X(DesiredTacticalCoord));
  1877. int ymod = Lepton_To_Pixel(Coord_Y(DesiredTacticalCoord));
  1878. int oldx = Lepton_To_Pixel(Coord_X(TacticalCoord))-xmod; // Old relative offset.
  1879. int oldy = Lepton_To_Pixel(Coord_Y(TacticalCoord))-ymod;
  1880. int oldw = Lepton_To_Pixel(TacLeptonWidth)-ABS(oldx); // Replicable width.
  1881. int oldh = Lepton_To_Pixel(TacLeptonHeight)-ABS(oldy); // Replicable height.
  1882. if (oldw < 1) forced = true;
  1883. if (oldh < 1) forced = true;
  1884. /*
  1885. ** Work out which map edges need to be redrawn
  1886. */
  1887. BOOL redraw_right = (oldx < 0) ? TRUE : FALSE; //Right hand edge
  1888. BOOL redraw_left = (oldx > 0) ? TRUE : FALSE; //Left hand edge
  1889. BOOL redraw_bottom= (oldy < 0) ? TRUE : FALSE; //Bottom edge
  1890. BOOL redraw_top = (oldy > 0) ? TRUE : FALSE; //Top edge
  1891. //Colour_Debug(2);
  1892. /*
  1893. ** Blit any replicable block to avoid having to drawstamp.
  1894. */
  1895. CachedIconsDrawn=0;
  1896. UnCachedIconsDrawn=0;
  1897. if (!forced && (oldw != Lepton_To_Pixel(TacLeptonWidth) || oldh != Lepton_To_Pixel(TacLeptonHeight))) {
  1898. Set_Cursor_Pos(-1);
  1899. /*
  1900. ** If hid page is in video memory then we may nned to blit from the seen page to
  1901. ** avoid blitting an overlapped region.
  1902. */
  1903. if (HidPage.Get_IsDirectDraw() && !OverlappedVideoBlits){
  1904. Hide_Mouse();
  1905. SeenBuff.Blit(HidPage,
  1906. ((oldx < 0) ? -oldx : 0) +TacPixelX,
  1907. ((oldy < 0) ? -oldy : 0) +TacPixelY,
  1908. ((oldx < 0) ? 0 : oldx) +TacPixelX,
  1909. ((oldy < 0) ? 0 : oldy) +TacPixelY,
  1910. oldw,
  1911. oldh);
  1912. Show_Mouse();
  1913. }else{
  1914. HidPage.Blit(HidPage,
  1915. ((oldx < 0) ? -oldx : 0) +TacPixelX,
  1916. ((oldy < 0) ? -oldy : 0) +TacPixelY,
  1917. ((oldx < 0) ? 0 : oldx) +TacPixelX,
  1918. ((oldy < 0) ? 0 : oldy) +TacPixelY,
  1919. oldw,
  1920. oldh);
  1921. }
  1922. } else {
  1923. forced = true;
  1924. }
  1925. if (oldx < 0) oldx = 0;
  1926. if (oldy < 0) oldy = 0;
  1927. /*
  1928. ** Record new map position for future reference.
  1929. */
  1930. ScenarioInit++;
  1931. Set_Tactical_Position(DesiredTacticalCoord);
  1932. ScenarioInit--;
  1933. if (!forced) {
  1934. /*
  1935. **
  1936. ** Set the 'redraw stamp' bit for any cells that could not be copied.
  1937. **
  1938. */
  1939. int startx = -Lepton_To_Pixel(Coord_XLepton(TacticalCoord));
  1940. int starty = -Lepton_To_Pixel(Coord_YLepton(TacticalCoord));
  1941. oldw -= 24;
  1942. oldh -= 24;
  1943. if (abs(oldx) < 0x25 && abs(oldy) < 0x25){
  1944. /*
  1945. ** The width of the area we redraw depends on the scroll speed
  1946. */
  1947. int extra_x = (abs(oldx)>=16) ? 2 : 1;
  1948. int extra_y = (abs(oldy)>=16) ? 2 : 1;
  1949. /*
  1950. ** Flag the cells across the top of the visible area if required
  1951. */
  1952. if (redraw_top){
  1953. for (y = starty; y <= starty+CELL_PIXEL_H*extra_y; y += CELL_PIXEL_H) {
  1954. for (x = startx; x <= Lepton_To_Pixel(TacLeptonWidth)+((CELL_PIXEL_W*2)); x += CELL_PIXEL_W) {
  1955. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1956. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1957. if (c > 0) (*this)[c].Redraw_Objects(true);
  1958. }
  1959. }
  1960. }
  1961. /*
  1962. ** Flag the cells across the bottom of the visible area if required
  1963. */
  1964. if (redraw_bottom){
  1965. for (y = Lepton_To_Pixel(TacLeptonHeight)-CELL_PIXEL_H*(1+extra_y); y <= Lepton_To_Pixel(TacLeptonHeight)+CELL_PIXEL_H*3; y += CELL_PIXEL_H) {
  1966. for (x = startx; x <= Lepton_To_Pixel(TacLeptonWidth)+((CELL_PIXEL_W*2)); x += CELL_PIXEL_W) {
  1967. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1968. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1969. if (c > 0) (*this)[c].Redraw_Objects(true);
  1970. }
  1971. }
  1972. }
  1973. /*
  1974. ** Flag the cells down the left of the visible area if required
  1975. */
  1976. if (redraw_left){
  1977. for (x = startx; x <= startx + CELL_PIXEL_W*extra_x; x += CELL_PIXEL_W) {
  1978. for (y = starty; y <= Lepton_To_Pixel(TacLeptonHeight)+((CELL_PIXEL_H*2)); y += CELL_PIXEL_H) {
  1979. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1980. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1981. if (c > 0) (*this)[c].Redraw_Objects(true);
  1982. }
  1983. }
  1984. }
  1985. /*
  1986. ** Flag the cells down the right of the visible area if required
  1987. */
  1988. if (redraw_right){
  1989. for (x = Lepton_To_Pixel(TacLeptonWidth)-CELL_PIXEL_W*(extra_x+1); x <= Lepton_To_Pixel(TacLeptonWidth)+CELL_PIXEL_W*3; x += CELL_PIXEL_W) {
  1990. for (y = starty; y <= Lepton_To_Pixel(TacLeptonHeight)+((CELL_PIXEL_H*2)); y += CELL_PIXEL_H) {
  1991. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1992. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1993. if (c > 0) (*this)[c].Redraw_Objects(true);
  1994. }
  1995. }
  1996. }
  1997. }else{
  1998. /*
  1999. ** Set the 'redraw stamp' bit for any cells that could not be copied.
  2000. */
  2001. int startx = -Lepton_To_Pixel(Coord_XLepton(TacticalCoord));
  2002. int starty = -Lepton_To_Pixel(Coord_YLepton(TacticalCoord));
  2003. oldw -= 24;
  2004. oldh -= 24;
  2005. for (y = starty; y <= Lepton_To_Pixel(TacLeptonHeight)+((CELL_PIXEL_H*2)); y += CELL_PIXEL_H) {
  2006. for (x = startx; x <= Lepton_To_Pixel(TacLeptonWidth)+((CELL_PIXEL_W*2)); x += CELL_PIXEL_W) {
  2007. if (x <= oldx || x >= oldx+oldw || y <= oldy || y >= oldy+oldh) {
  2008. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  2009. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  2010. if (c > 0) {
  2011. (*this)[c].Redraw_Objects(true);
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. } else {
  2019. /*
  2020. ** Set the tactical coordinate just in case the desired tactical has changed but
  2021. ** not enough to result in any visible map change. This is likely to occur with very
  2022. ** slow scroll rates.
  2023. */
  2024. ScenarioInit++;
  2025. if (DesiredTacticalCoord != TacticalCoord) {
  2026. Set_Tactical_Position(DesiredTacticalCoord);
  2027. }
  2028. ScenarioInit--;
  2029. }
  2030. /*
  2031. ** If the entire tactical map is forced to be redrawn, then set all the redraw flags
  2032. ** and let the normal processing take care of the rest.
  2033. */
  2034. if (forced) {
  2035. CellRedraw.Set();
  2036. }
  2037. //Colour_Debug(3);
  2038. /*
  2039. ** The first order of business is to redraw all the underlying icons that are
  2040. ** flagged to be redrawn.
  2041. */
  2042. //Redraw_Icons(CELL_BLIT_ONLY);
  2043. Redraw_Icons(0);
  2044. /*
  2045. ** Once the icons are drawn, duplicate the bottom line of the screen into the phantom
  2046. ** area one line below the screen. This causes the predator effect to work on any
  2047. ** shape drawn at the bottom of the screen.
  2048. */
  2049. //Colour_Debug(4);
  2050. #ifdef FIX_ME_LATER
  2051. // HidPage.Blit(HidPage, 0, HidPage.Get_Height()-1, 0, HidPage.Get_Height(), HidPage.Get_Width(), 1, false);
  2052. #endif //FIX_ME_LATER
  2053. if (HidPage.Lock()){
  2054. //Redraw_Icons(CELL_DRAW_ONLY);
  2055. /*
  2056. ** Redraw the game objects layer by layer. The layer drawing occurs on the ground layer
  2057. ** first and then followed by all the layers in increasing altituded.
  2058. */
  2059. for (LayerType layer = LAYER_GROUND; layer < LAYER_COUNT; layer++) {
  2060. for (int index = 0; index < Layer[layer].Count(); index++) {
  2061. Layer[layer][index]->Render(forced);
  2062. }
  2063. }
  2064. /*
  2065. ** Finally, redraw the shadow overlay as necessary.
  2066. */
  2067. //Colour_Debug(5);
  2068. Redraw_Shadow();
  2069. }
  2070. Redraw_Shadow_Rects();
  2071. HidPage.Unlock();
  2072. //Colour_Debug(8);
  2073. /*
  2074. ** Draw the rubber band over the top of it all.
  2075. */
  2076. if (IsRubberBand) {
  2077. LogicPage->Draw_Rect(BandX+TacPixelX, BandY+TacPixelY, NewX+TacPixelX, NewY+TacPixelY, WHITE);
  2078. }
  2079. /*
  2080. ** Clear the redraw flags so that normal redraw flag setting can resume.
  2081. */
  2082. CellRedraw.Reset();
  2083. //Colour_Debug(0);
  2084. #ifdef SCENARIO_EDITOR
  2085. /*
  2086. ** If we're placing an object (PendingObject is non-NULL), and that object
  2087. ** is NOT an icon, smudge, or overlay, draw it here.
  2088. ** Terrain, Buildings & Aircraft aren't drawn at the cell's center coord;
  2089. ** they're drawn at the upper left coord, so I have to AND the coord value
  2090. ** with 0xFF00FF00 to strip off the lepton coordinates, but leave the
  2091. ** cell coordinates.
  2092. */
  2093. if (Debug_Map && PendingObjectPtr) {
  2094. PendingObjectPtr->Coord = PendingObjectPtr->Class_Of().Coord_Fixup(Cell_Coord(ZoneCell + ZoneOffset));
  2095. PendingObjectPtr->Render(true);
  2096. }
  2097. #endif
  2098. }
  2099. }
  2100. /***********************************************************************************************
  2101. * DisplayClass::Redraw_Icons -- Draws all terrain icons necessary. *
  2102. * *
  2103. * This routine will redraw all of the terrain icons that are flagged *
  2104. * to be redrawn. *
  2105. * *
  2106. * INPUT: none *
  2107. * *
  2108. * OUTPUT: none *
  2109. * *
  2110. * WARNINGS: none. *
  2111. * *
  2112. * HISTORY: *
  2113. * 02/14/1994 JLB : Created. *
  2114. * 05/01/1994 JLB : Converted to member function. *
  2115. * 06/20/1994 JLB : Uses cell drawing support function. *
  2116. * 12/06/1994 JLB : Scans tactical view in separate row/colum loops *
  2117. * 12/24/1994 JLB : Uses the cell bit flag array to determine what to redraw. *
  2118. *=============================================================================================*/
  2119. void DisplayClass::Redraw_Icons(int draw_flags)
  2120. {
  2121. IsShadowPresent = false;
  2122. for (int y = -Coord_YLepton(TacticalCoord); y <= TacLeptonHeight; y += CELL_LEPTON_H) {
  2123. for (int x = -Coord_XLepton(TacticalCoord); x <= TacLeptonWidth; x += CELL_LEPTON_W) {
  2124. COORDINATE coord = Coord_Add(TacticalCoord, XY_Coord(x, y));
  2125. CELL cell = Coord_Cell(coord);
  2126. coord = Cell_Coord(cell) & 0xFF00FF00L;
  2127. /*
  2128. ** Only cells flagged to be redraw are examined.
  2129. */
  2130. if (In_View(cell) && Is_Cell_Flagged(cell)) {
  2131. int xpixel;
  2132. int ypixel;
  2133. if (Coord_To_Pixel(coord, xpixel, ypixel)) {
  2134. CellClass * cellptr = &(*this)[Coord_Cell(coord)];
  2135. /*
  2136. ** If there is a portion of the underlying icon that could be visible,
  2137. ** then draw it. Also draw the cell if the shroud is off.
  2138. */
  2139. if (cellptr->Is_Visible(PlayerPtr) || Debug_Unshroud) { // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2140. cellptr->Draw_It(xpixel, ypixel, draw_flags);
  2141. }
  2142. /*
  2143. ** If any cell is not fully mapped, then flag it so that the shadow drawing
  2144. ** process will occur. Only draw the shadow if Debug_Unshroud is false.
  2145. */
  2146. if (!cellptr->Is_Mapped(PlayerPtr) && !Debug_Unshroud) { // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2147. IsShadowPresent = true;
  2148. }
  2149. }
  2150. }
  2151. }
  2152. }
  2153. }
  2154. /***********************************************************************************************
  2155. * DisplayClass::Redraw_Shadow -- Draw the shadow overlay. *
  2156. * *
  2157. * This routine is called after all other tactical map rendering takes place. It draws *
  2158. * the shadow map over the tactical map. *
  2159. * *
  2160. * INPUT: none *
  2161. * *
  2162. * OUTPUT: none *
  2163. * *
  2164. * WARNINGS: none *
  2165. * *
  2166. * HISTORY: *
  2167. * 01/01/1995 JLB : Created. *
  2168. * 08/06/1995 JLB : Clips the fill rect if necessary. *
  2169. *=============================================================================================*/
  2170. void DisplayClass::Redraw_Shadow(void)
  2171. {
  2172. if (IsShadowPresent) {
  2173. for (int y = -Coord_YLepton(TacticalCoord); y <= TacLeptonHeight; y += CELL_LEPTON_H) {
  2174. for (int x = -Coord_XLepton(TacticalCoord); x <= TacLeptonWidth; x += CELL_LEPTON_W) {
  2175. COORDINATE coord = Coord_Add(TacticalCoord, XY_Coord(x, y));
  2176. CELL cell = Coord_Cell(coord);
  2177. coord = Cell_Coord(cell) & 0xFF00FF00;
  2178. /*
  2179. ** Only cells flagged to be redraw are examined.
  2180. */
  2181. if (In_View(cell) && Is_Cell_Flagged(cell)) {
  2182. int xpixel;
  2183. int ypixel;
  2184. if (Coord_To_Pixel(coord, xpixel, ypixel)) {
  2185. CellClass * cellptr = &(*this)[Coord_Cell(coord)];
  2186. if (!cellptr->Is_Mapped(PlayerPtr)) { // Pass player pointer since we will only be rendering in single player mode. ST - 3/6/2019 1:36PM
  2187. if (cellptr->Is_Visible(PlayerPtr)) { // Pass player pointer since we will only be rendering in single player mode. ST - 3/6/2019 1:36PM
  2188. int shadow = Cell_Shadow(cell, PlayerPtr); // Pass player pointer since we will only be rendering in single player mode. ST - 3/6/2019 1:36PM
  2189. if (shadow >= 0) {
  2190. CC_Draw_Shape(ShadowShapes, shadow, xpixel, ypixel, WINDOW_TACTICAL, SHAPE_GHOST, NULL, ShadowTrans);
  2191. }
  2192. }
  2193. }
  2194. }
  2195. }
  2196. }
  2197. }
  2198. }
  2199. }
  2200. /***********************************************************************************************
  2201. * DisplayClass::Redraw_Shadow -- Draw the shadow overlay. *
  2202. * *
  2203. * This routine is called after all other tactical map rendering takes place. It draws *
  2204. * the shadow map over the tactical map. *
  2205. * *
  2206. * INPUT: none *
  2207. * *
  2208. * OUTPUT: none *
  2209. * *
  2210. * WARNINGS: none *
  2211. * *
  2212. * HISTORY: *
  2213. * 01/01/1995 JLB : Created. *
  2214. * 08/06/1995 JLB : Clips the fill rect if necessary. *
  2215. *=============================================================================================*/
  2216. void DisplayClass::Redraw_Shadow_Rects(void)
  2217. {
  2218. if (IsShadowPresent) {
  2219. for (int y = -Coord_YLepton(TacticalCoord); y <= TacLeptonHeight; y += CELL_LEPTON_H) {
  2220. for (int x = -Coord_XLepton(TacticalCoord); x <= TacLeptonWidth; x += CELL_LEPTON_W) {
  2221. COORDINATE coord = Coord_Add(TacticalCoord, XY_Coord(x, y));
  2222. CELL cell = Coord_Cell(coord);
  2223. coord = Cell_Coord(cell) & 0xFF00FF00;
  2224. /*
  2225. ** Only cells flagged to be redraw are examined.
  2226. */
  2227. if (In_View(cell) && Is_Cell_Flagged(cell)) {
  2228. int xpixel;
  2229. int ypixel;
  2230. if (Coord_To_Pixel(coord, xpixel, ypixel)) {
  2231. CellClass * cellptr = &(*this)[Coord_Cell(coord)];
  2232. if (!cellptr->Is_Mapped(PlayerPtr)) { // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2233. if (!cellptr->Is_Visible(PlayerPtr)) { // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2234. int ww = CELL_PIXEL_W;
  2235. int hh = CELL_PIXEL_H;
  2236. if (Clip_Rect(&xpixel, &ypixel, &ww, &hh, Lepton_To_Pixel(TacLeptonWidth), Lepton_To_Pixel(TacLeptonHeight)) >= 0) {
  2237. LogicPage->Fill_Rect(TacPixelX+xpixel, TacPixelY+ypixel, TacPixelX+xpixel+ww-1, TacPixelY+ypixel+hh-1, BLACK);
  2238. }
  2239. }
  2240. }
  2241. }
  2242. }
  2243. }
  2244. }
  2245. }
  2246. }
  2247. /***********************************************************************************************
  2248. * DisplayClass::Next_Object -- Searches for next object on display. *
  2249. * *
  2250. * This utility routine is used to find the "next" object from the object specified. This *
  2251. * is typically used when <TAB> is pressed and the current object shifts. *
  2252. * *
  2253. * INPUT: object -- The current object to base the "next" calculation off of. *
  2254. * *
  2255. * OUTPUT: Returns with a pointer to the next object. If there is no objects available, *
  2256. * then NULL is returned. *
  2257. * *
  2258. * WARNINGS: none *
  2259. * *
  2260. * HISTORY: *
  2261. * 06/20/1994 JLB : Created. *
  2262. *=============================================================================================*/
  2263. ObjectClass * DisplayClass::Next_Object(ObjectClass * object)
  2264. {
  2265. ObjectClass * firstobj = 0;
  2266. bool foundmatch = false;
  2267. if (!object) {
  2268. foundmatch = true;
  2269. }
  2270. for (unsigned uindex = 0; uindex < (unsigned)Layer[LAYER_GROUND].Count(); uindex++) {
  2271. ObjectClass * obj = Layer[LAYER_GROUND][uindex];
  2272. /*
  2273. ** Verify that the object can be selected by and is owned by the player.
  2274. */
  2275. if (obj && obj->Is_Techno() && ((TechnoClass *)obj)->Is_Discovered_By_Player() && obj->Class_Of().IsSelectable && obj->Owner() == PlayerPtr->Class->House) {
  2276. if (!firstobj) firstobj = obj;
  2277. if (foundmatch) return(obj);
  2278. if (object == obj) foundmatch = true;
  2279. }
  2280. }
  2281. return(firstobj);
  2282. }
  2283. /***********************************************************************************************
  2284. * DisplayClass::Prev_Object -- Searches for the previous object on the map. *
  2285. * *
  2286. * This routine will search for the previous object. Previous is defined as the one listed *
  2287. * before the specified object in the ground layer. If there is no specified object, then *
  2288. * the last object in the ground layer is returned. *
  2289. * *
  2290. * INPUT: object -- Pointer to the object that "previous" is to be defined from. *
  2291. * *
  2292. * OUTPUT: Returns with a pointer to the object previous to the specified one. *
  2293. * *
  2294. * WARNINGS: none *
  2295. * *
  2296. * HISTORY: *
  2297. * 08/24/1995 JLB : Created. *
  2298. *=============================================================================================*/
  2299. ObjectClass * DisplayClass::Prev_Object(ObjectClass * object)
  2300. {
  2301. ObjectClass * firstobj = 0;
  2302. bool foundmatch = false;
  2303. if (!object) {
  2304. foundmatch = true;
  2305. }
  2306. for (int uindex = Layer[LAYER_GROUND].Count()-1; uindex >= 0; uindex--) {
  2307. ObjectClass * obj = Layer[LAYER_GROUND][uindex];
  2308. /*
  2309. ** Verify that the object can be selected by and is owned by the player.
  2310. */
  2311. if (obj && obj->Is_Techno() && ((TechnoClass *)obj)->Is_Discovered_By_Player() && obj->Class_Of().IsSelectable && obj->Owner() == PlayerPtr->Class->House) {
  2312. if (!firstobj) firstobj = obj;
  2313. if (foundmatch) return(obj);
  2314. if (object == obj) foundmatch = true;
  2315. }
  2316. }
  2317. return(firstobj);
  2318. }
  2319. /***********************************************************************************************
  2320. * DisplayClass::Pixel_To_Coord -- converts screen coord to COORDINATE *
  2321. * *
  2322. * INPUT: *
  2323. * x,y pixel coordinates to convert *
  2324. * *
  2325. * OUTPUT: *
  2326. * COORDINATE of pixel *
  2327. * *
  2328. * WARNINGS: *
  2329. * none. *
  2330. * *
  2331. * HISTORY: *
  2332. * 11/09/1994 BR : Created. *
  2333. * 12/06/1994 JLB : Uses map dimension variables in display class. *
  2334. * 12/10/1994 JLB : Uses union to speed building coordinate value. *
  2335. *=============================================================================================*/
  2336. COORDINATE DisplayClass::Pixel_To_Coord(int x, int y)
  2337. {
  2338. /*
  2339. ** Normalize the pixel coorindates to be relative to the upper left corner
  2340. ** of the tactical map. The coordinates are expressed in leptons.
  2341. */
  2342. x -= TacPixelX;
  2343. x = Pixel_To_Lepton(x);
  2344. y -= TacPixelY;
  2345. y = Pixel_To_Lepton(y);
  2346. /*
  2347. ** If pixel coordinate is over the tactical map, then translate it into a coordinate
  2348. ** value. If not, then just return with NULL.
  2349. */
  2350. // Possibly ignore the view constraints if we aren't using the internal renderer. ST - 4/17/2019 9:06AM
  2351. //if (x < TacLeptonWidth && y < TacLeptonHeight) {
  2352. if (IgnoreViewConstraints || (x < TacLeptonWidth && y < TacLeptonHeight)) {
  2353. return(Coord_Add(TacticalCoord, XY_Coord(x, y)));
  2354. }
  2355. return(0);
  2356. }
  2357. /***********************************************************************************************
  2358. * DisplayClass::Calculated_Cell -- Fetch a map cell based on specified method. *
  2359. * *
  2360. * Find a cell meeting the specified requirements. This function is *
  2361. * used for scenario reinforcements. *
  2362. * *
  2363. * INPUT: dir -- Method of picking a map cell. *
  2364. * *
  2365. * house -- The house to base calculation on. *
  2366. * *
  2367. * OUTPUT: Returns with the calculated cell. If 0, then this indicates *
  2368. * that no legal cell was found. *
  2369. * *
  2370. * WARNINGS: none *
  2371. * *
  2372. * HISTORY: *
  2373. * 10/07/1992 JLB : Created. *
  2374. * 04/11/1994 JLB : Revamped. *
  2375. * 05/18/1994 JLB : Converted to member function. *
  2376. *=============================================================================================*/
  2377. CELL DisplayClass::Calculated_Cell(SourceType dir, HousesType house)
  2378. {
  2379. CELL cell = 0; // Working cell number.
  2380. while (cell == 0) {
  2381. int x,y;
  2382. int index;
  2383. /*
  2384. ** Select a candidate cell based on the desired method.
  2385. */
  2386. switch (dir) {
  2387. /*
  2388. ** Looks for the northern most straight path shipping lane and returns
  2389. ** the cell of one of the ends.
  2390. */
  2391. case SOURCE_SHIPPING:
  2392. for (y = 0; y < MapCellHeight; y++) {
  2393. for (x = 0; x < MapCellWidth; x++) {
  2394. if ((*this)[XY_Cell(MapCellX+x, MapCellY+y)].Land_Type() != LAND_WATER) break;
  2395. }
  2396. if (x == MapCellWidth) {
  2397. return(XY_Cell(MapCellX+MapCellWidth, MapCellY+y));
  2398. }
  2399. }
  2400. return(0);
  2401. /*
  2402. ** Select a map edge.
  2403. */
  2404. case SOURCE_NORTH:
  2405. index = Random_Pick(1, MapCellWidth);
  2406. for (x = 0; x < MapCellWidth; x++) {
  2407. cell = XY_Cell(MapCellX+((x+index)%MapCellWidth), MapCellY-1);
  2408. if ((*this)[cell].Is_Generally_Clear() && (*this)[cell+MAP_CELL_W].Is_Generally_Clear()) break;
  2409. }
  2410. if (x == MapCellWidth) return(0);
  2411. break;
  2412. case SOURCE_EAST:
  2413. index = Random_Pick(1, MapCellHeight);
  2414. for (y = 0; y < MapCellHeight; y++) {
  2415. cell = XY_Cell(MapCellX+MapCellWidth, MapCellY+((y+index)%MapCellHeight));
  2416. if ((*this)[cell].Is_Generally_Clear() && (*this)[cell-1].Is_Generally_Clear()) break;
  2417. }
  2418. if (y == MapCellHeight) return(0);
  2419. break;
  2420. case SOURCE_SOUTH:
  2421. index = Random_Pick(1, MapCellWidth);
  2422. for (x = 0; x < MapCellWidth; x++) {
  2423. cell = XY_Cell(MapCellX+((x+index)%MapCellWidth), MapCellY+MapCellHeight);
  2424. if ((*this)[cell].Is_Generally_Clear() && (*this)[cell-MAP_CELL_W].Is_Generally_Clear()) break;
  2425. }
  2426. if (x == MapCellWidth) return(0);
  2427. break;
  2428. case SOURCE_WEST:
  2429. index = Random_Pick(1, MapCellHeight);
  2430. for (y = 0; y < MapCellHeight; y++) {
  2431. cell = XY_Cell(MapCellX-1, MapCellY+((y+index)%MapCellHeight));
  2432. if ((*this)[cell].Is_Generally_Clear() && (*this)[cell+1].Is_Generally_Clear()) break;
  2433. }
  2434. if (y == MapCellHeight) return(0);
  2435. break;
  2436. /*
  2437. ** Drop in at a random location.
  2438. */
  2439. case SOURCE_AIR:
  2440. cell = Waypoint[WAYPT_REINF];
  2441. if (cell < 1) {
  2442. cell = Coord_Cell(TacticalCoord);
  2443. return(cell);
  2444. } else {
  2445. if ((*this)[cell].Cell_Techno()) {
  2446. for (int radius = 1; radius < 7; radius++) {
  2447. CELL newcell = Coord_Cell(Coord_Scatter(Cell_Coord(cell), radius << 8, true));
  2448. if (In_Radar(newcell) && !(*this)[newcell].Cell_Techno()) {
  2449. cell = newcell;
  2450. break;
  2451. }
  2452. }
  2453. }
  2454. }
  2455. break;
  2456. /*
  2457. ** Dramatic entry point is somewhere on the visible screen as defined
  2458. ** by the current tactical map position.
  2459. */
  2460. case SOURCE_VISIBLE:
  2461. cell = XY_Cell(Coord_XCell(TacticalCoord)+Random_Pick(0, Lepton_To_Cell(TacLeptonWidth)-1), Coord_YCell(TacticalCoord)+Random_Pick(0, Lepton_To_Cell(TacLeptonHeight)-1));
  2462. if (house == PlayerPtr->Class->House && !In_Radar(cell)) {
  2463. cell = 0;
  2464. }
  2465. break;
  2466. /*
  2467. ** Drop off near friendly base or near a friendly unit or
  2468. ** just randomly if all else fails.
  2469. */
  2470. case SOURCE_ENEMYBASE:
  2471. case SOURCE_HOMEBASE:
  2472. return(0);
  2473. /*
  2474. ** Find an unoccupied beach cell.
  2475. */
  2476. case SOURCE_BEACH: {
  2477. CELL cells[MAP_CELL_W];
  2478. CELL alternate[MAP_CELL_W];
  2479. unsigned counter=0;
  2480. for (x = 0; x < MapCellWidth; x++) {
  2481. CELL newcell = 0;
  2482. if ((*this)[XY_Cell(x + MapCellX, MapCellHeight + MapCellY)].Land_Type() != LAND_WATER) continue;
  2483. if ((*this)[XY_Cell(x + MapCellX, MapCellHeight + MapCellY-1)].Land_Type() != LAND_WATER) continue;
  2484. for (y = MapCellHeight; y >= 0; y--) {
  2485. newcell = XY_Cell(x + MapCellX, y + MapCellY);
  2486. if ((*this)[newcell].Cell_Techno()) {
  2487. break;
  2488. }
  2489. if ((*this)[newcell].Land_Type() != LAND_WATER) {
  2490. break;
  2491. }
  2492. }
  2493. LandType land = (*this)[newcell].Land_Type();
  2494. if (( land == LAND_BEACH || land == LAND_CLEAR || land == LAND_ROAD) &&
  2495. !(*this)[newcell].Cell_Techno() &&
  2496. !(*this)[newcell].Cell_Terrain() &&
  2497. !(*this)[newcell-MAP_CELL_W].Cell_Techno() &&
  2498. !(*this)[newcell-MAP_CELL_W].Cell_Terrain() &&
  2499. !(*this)[newcell-(MAP_CELL_W*2)].Cell_Terrain() &&
  2500. !(*this)[newcell-(MAP_CELL_W*2)].Cell_Techno()) {
  2501. cells[counter++] = newcell;
  2502. if (counter >= (sizeof(cells) / sizeof(cells[0]))) {
  2503. break;
  2504. }
  2505. }
  2506. }
  2507. /*
  2508. ** Fixup entry list so that it doesn't come close to blocking terrain or other
  2509. ** units.
  2510. */
  2511. int counter2 = 0;
  2512. for (int index = 1; index < (int)counter-1; index++) {
  2513. if (Cell_X(cells[index-1])+1 == Cell_X(cells[index]) && Cell_X(cells[index+1])-1 == Cell_X(cells[index])) {
  2514. alternate[counter2++] = cells[index];
  2515. }
  2516. }
  2517. CELL cell = 0;
  2518. if (counter2) {
  2519. if (counter2 < 4) {
  2520. cell = alternate[counter2-1];
  2521. } else {
  2522. cell = alternate[counter2 - (counter2 / 4)];
  2523. }
  2524. } else {
  2525. if (counter) {
  2526. if (counter < 4) {
  2527. cell = cells[counter-1];
  2528. } else {
  2529. cell = cells[counter - (counter / 4)];
  2530. }
  2531. }
  2532. }
  2533. if (cell) {
  2534. if (Map.Theater == THEATER_DESERT) {
  2535. cell += MAP_CELL_W;
  2536. }
  2537. }
  2538. return(cell);
  2539. }
  2540. case SOURCE_OCEAN:
  2541. cell = XY_Cell(Random_Pick(0, MapCellWidth-2)+MapCellX, MapCellHeight+MapCellY);
  2542. break;
  2543. default:
  2544. return(0);
  2545. }
  2546. /*
  2547. ** The selected edge cell must be unoccupied and if this is for
  2548. ** the player, then it must be on an accessible map cell.
  2549. */
  2550. cell &= 0x0FFF;
  2551. if (cell && (*this)[cell].Cell_Techno()) {
  2552. cell = 0;
  2553. }
  2554. }
  2555. return(cell);
  2556. }
  2557. /***********************************************************************************************
  2558. * DisplayClass::Select_These -- All selectable objects in region are selected. *
  2559. * *
  2560. * Use this routine to simultaneously select all objects within the coordinate region *
  2561. * specified. This routine is used by the multi-select rubber band handler. *
  2562. * *
  2563. * INPUT: coord1 -- Coordinate of one corner of the selection region. *
  2564. * *
  2565. * coord2 -- The opposite corner of the selection region. *
  2566. * *
  2567. * additive -- Does this add to the existing selection or replace it. *
  2568. * *
  2569. * OUTPUT: none *
  2570. * *
  2571. * WARNINGS: none *
  2572. * *
  2573. * HISTORY: *
  2574. * 01/19/1995 JLB : Created. *
  2575. * 04/25/1995 JLB : Limited to non-building type. *
  2576. *=============================================================================================*/
  2577. static bool should_exclude_from_selection(ObjectClass* obj)
  2578. {
  2579. return (obj->What_Am_I() == RTTI_UNIT) &&
  2580. (((UnitClass *)obj)->Class->IsToHarvest ||
  2581. *((UnitClass *)obj) == UNIT_MCV);
  2582. }
  2583. void DisplayClass::Select_These(COORDINATE coord1, COORDINATE coord2, bool additive)
  2584. {
  2585. COORDINATE tcoord = TacticalCoord; //Cell_Coord(TacticalCell) & 0xFF00FF00L;
  2586. coord1 = Coord_Add(tcoord, coord1);
  2587. coord2 = Coord_Add(tcoord, coord2);
  2588. int x1 = Coord_X(coord1);
  2589. int x2 = Coord_X(coord2);
  2590. int y1 = Coord_Y(coord1);
  2591. int y2 = Coord_Y(coord2);
  2592. /*
  2593. ** Ensure that coordinate number one represents the upper left corner
  2594. ** and coordinate number two represents the lower right corner.
  2595. */
  2596. if (x1 > x2) {
  2597. int temp = x1;
  2598. x1 = x2;
  2599. x2 = temp;
  2600. }
  2601. if (y1 > y2) {
  2602. int temp = y1;
  2603. y1 = y2;
  2604. y2 = temp;
  2605. }
  2606. /*
  2607. ** Sweep through all ground layer objects and select the ones within the
  2608. ** bounding box.
  2609. */
  2610. if (!additive) {
  2611. Unselect_All();
  2612. }
  2613. AllowVoice = true;
  2614. for (int index = 0; index < Layer[LAYER_GROUND].Count(); index++) {
  2615. ObjectClass * obj = Layer[LAYER_GROUND][index];
  2616. COORDINATE ocoord = obj->Center_Coord();
  2617. int x = Coord_X(ocoord);
  2618. int y = Coord_Y(ocoord);
  2619. /*
  2620. ** Only try to select objects that are owned by the player, are allowed to be
  2621. ** selected, and are within the bouding box.
  2622. */
  2623. if ( obj->Class_Of().IsSelectable &&
  2624. obj->What_Am_I() != RTTI_BUILDING &&
  2625. (!obj->Is_Techno() || !((TechnoClass*)obj)->Is_Cloaked(PlayerPtr)) &&
  2626. x >= x1 && x <= x2 && y >= y1 && y <= y2) {
  2627. bool old_allow_voice = AllowVoice;
  2628. bool is_player_controlled = obj->Owner() == PlayerPtr->Class->House;
  2629. AllowVoice &= is_player_controlled;
  2630. if (obj->Select(true)) {
  2631. if (is_player_controlled) {
  2632. old_allow_voice = false;
  2633. }
  2634. }
  2635. AllowVoice = old_allow_voice;
  2636. }
  2637. }
  2638. /*
  2639. ** Select any aircraft with the bounding box.
  2640. */
  2641. for (int air_index = 0; air_index < Aircraft.Count(); air_index++) {
  2642. AircraftClass * aircraft = Aircraft.Ptr(air_index);
  2643. COORDINATE ocoord = Coord_Add(aircraft->Center_Coord(), XY_Coord(0, -Pixel_To_Lepton(aircraft->Altitude)));
  2644. int x = Coord_X(ocoord);
  2645. int y = Coord_Y(ocoord);
  2646. /*
  2647. ** Only try to select objects that are owned by the player, are allowed to be
  2648. ** selected, and are within the bounding box.
  2649. */
  2650. if ( aircraft->Class_Of().IsSelectable &&
  2651. !aircraft->Is_Cloaked(PlayerPtr) &&
  2652. !aircraft->Is_Selected_By_Player() &&
  2653. x >= x1 && x <= x2 && y >= y1 && y <= y2) {
  2654. bool old_allow_voice = AllowVoice;
  2655. bool is_player_controlled = aircraft->Owner() == PlayerPtr->Class->House;
  2656. AllowVoice &= is_player_controlled;
  2657. if (aircraft->Select(true)) {
  2658. if (is_player_controlled) {
  2659. old_allow_voice = false;
  2660. }
  2661. }
  2662. AllowVoice = old_allow_voice;
  2663. }
  2664. }
  2665. /*
  2666. ** If a mix of player and non-player controlled units were selected, make sure non-player controlled units are de-selected
  2667. */
  2668. bool player_controlled_units = false, non_player_controlled_units = false;
  2669. for (int i = 0; (i < CurrentObject.Count()) && (!player_controlled_units || !non_player_controlled_units); ++i) {
  2670. HouseClass * hptr = HouseClass::As_Pointer(CurrentObject[i]->Owner());
  2671. if (CurrentObject[i]->Owner() == PlayerPtr->Class->House) {
  2672. player_controlled_units = true;
  2673. }
  2674. else {
  2675. non_player_controlled_units = true;
  2676. }
  2677. }
  2678. if (player_controlled_units && non_player_controlled_units) {
  2679. for (int i = 0; i < CurrentObject.Count(); ++i) {
  2680. HouseClass * hptr = HouseClass::As_Pointer(CurrentObject[i]->Owner());
  2681. if (CurrentObject[i]->Owner() != PlayerPtr->Class->House) {
  2682. int count_before = CurrentObject.Count();
  2683. CurrentObject[i]->Unselect();
  2684. if (count_before <= CurrentObject.Count()) {
  2685. GlyphX_Debug_Print("Select_These failed to remove an object");
  2686. CurrentObject.Delete(CurrentObject[i]);
  2687. }
  2688. --i;
  2689. }
  2690. }
  2691. }
  2692. /*
  2693. ** If player-controlled units are non-additively selected, remove harvesters and MCVs if they aren't the only types of units selected
  2694. */
  2695. if (!additive && player_controlled_units) {
  2696. bool any_to_exclude = false, all_to_exclude = true;
  2697. for (int i = 0; i < CurrentObject.Count(); ++i) {
  2698. bool exclude = should_exclude_from_selection(CurrentObject[i]);
  2699. any_to_exclude |= exclude;
  2700. all_to_exclude &= exclude;
  2701. }
  2702. if (any_to_exclude && !all_to_exclude) {
  2703. for (int i = 0; i < CurrentObject.Count(); ++i) {
  2704. if (should_exclude_from_selection(CurrentObject[i])) {
  2705. int count_before = CurrentObject.Count();
  2706. CurrentObject[i]->Unselect();
  2707. if (count_before <= CurrentObject.Count()) {
  2708. GlyphX_Debug_Print("Select_These failed to remove an object");
  2709. CurrentObject.Delete(CurrentObject[i]);
  2710. }
  2711. --i;
  2712. }
  2713. }
  2714. }
  2715. }
  2716. AllowVoice = true;
  2717. }
  2718. /***********************************************************************************************
  2719. * DisplayClass::Refresh_Band -- Causes all cells under the rubber band to be redrawn. *
  2720. * *
  2721. * Use this routine to flag all cells that are covered in some fashion by the multi-unit *
  2722. * select "rubber band" to be redrawn. This is necessary whenever the rubber band changes *
  2723. * size or is being removed. *
  2724. * *
  2725. * INPUT: none *
  2726. * *
  2727. * OUTPUT: none *
  2728. * *
  2729. * WARNINGS: none *
  2730. * *
  2731. * HISTORY: *
  2732. * 01/19/1995 JLB : Created. *
  2733. *=============================================================================================*/
  2734. void DisplayClass::Refresh_Band(void)
  2735. {
  2736. if (IsRubberBand) {
  2737. /*
  2738. ** In rubber band mode, mark all cells under the "rubber band" to be
  2739. ** redrawn.
  2740. */
  2741. int x1 = BandX+TacPixelX;
  2742. int y1 = BandY+TacPixelY;
  2743. int x2 = NewX+TacPixelX;
  2744. int y2 = NewY+TacPixelY;
  2745. if (x1 > x2) {
  2746. int temp = x1;
  2747. x1 = x2;
  2748. x2 = temp;
  2749. }
  2750. if (y1 > y2) {
  2751. int temp = y1;
  2752. y1 = y2;
  2753. y2 = temp;
  2754. }
  2755. CELL cell;
  2756. for (int y = y1; y <= y2+CELL_PIXEL_H; y += CELL_PIXEL_H) {
  2757. cell = Click_Cell_Calc(x1, Bound(y, 0, TacPixelY+Lepton_To_Pixel(TacLeptonHeight)));
  2758. if (cell != -1) (*this)[cell].Redraw_Objects();
  2759. cell = Click_Cell_Calc(x2, Bound(y, 0, TacPixelY+Lepton_To_Pixel(TacLeptonHeight)));
  2760. if (cell != -1) (*this)[cell].Redraw_Objects();
  2761. }
  2762. for (int x = x1; x <= x2+CELL_PIXEL_W; x += CELL_PIXEL_W) {
  2763. cell = Click_Cell_Calc(Bound(x, 0, TacPixelX+Lepton_To_Pixel(TacLeptonWidth)), y1);
  2764. if (cell != -1) (*this)[cell].Redraw_Objects();
  2765. cell = Click_Cell_Calc(Bound(x, 0, TacPixelX+Lepton_To_Pixel(TacLeptonWidth)), y2);
  2766. if (cell != -1) (*this)[cell].Redraw_Objects();
  2767. }
  2768. }
  2769. }
  2770. /***********************************************************************************************
  2771. * DisplayClass::TacticalClass::Action -- Processes input for the tactical map. *
  2772. * *
  2773. * This routine handles the input directed at the tactical map. Since input, in this *
  2774. * regard, includes even the presence of the mouse over the tactical map, this routine *
  2775. * is called nearly every game frame. It handles adjusting the mouse shape as well as *
  2776. * giving orders to units. *
  2777. * *
  2778. * INPUT: flags -- The gadget event flags that triggered the call to this function. *
  2779. * *
  2780. * key -- A reference to the keyboard event (if any). *
  2781. * *
  2782. * OUTPUT: bool; Should processing be aborted on any succeeding buttons in the chain? *
  2783. * *
  2784. * WARNINGS: none *
  2785. * *
  2786. * HISTORY: *
  2787. * 02/17/1995 JLB : Created. *
  2788. *=============================================================================================*/
  2789. int DisplayClass::TacticalClass::Action(unsigned flags, KeyNumType & key)
  2790. {
  2791. int x,y; // Sub cell pixel coordinates.
  2792. bool shadow;
  2793. ObjectClass *object = 0;
  2794. ActionType action = ACTION_NONE; // Action possible with currently selected object.
  2795. /*
  2796. ** Set some working variables that depend on the mouse position. For the press
  2797. ** or release event, special mouse queuing storage variables are used. Other
  2798. ** events must use the current mouse position globals.
  2799. */
  2800. bool edge = false;
  2801. if (flags & (LEFTPRESS|LEFTRELEASE|RIGHTPRESS|RIGHTRELEASE)) {
  2802. x = _Kbd->MouseQX;
  2803. y = _Kbd->MouseQY;
  2804. } else {
  2805. x = Get_Mouse_X();
  2806. y = Get_Mouse_Y();
  2807. if (x == 0 || y == 199 || x == 319) edge = true;
  2808. }
  2809. COORDINATE coord = Map.Pixel_To_Coord(x, y);
  2810. CELL cell = Coord_Cell(coord);
  2811. // CELL cell = Map.Click_Cell_Calc(x, y);
  2812. if (coord) {
  2813. shadow = (!Map[cell].Is_Visible(PlayerPtr) && !Debug_Unshroud); // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2814. x -= Map.TacPixelX;
  2815. y -= Map.TacPixelY;
  2816. /*
  2817. ** Cause any displayed cursor to move along with the mouse cursor.
  2818. */
  2819. if (cell != Map.ZoneCell) {
  2820. Map.Set_Cursor_Pos(cell);
  2821. }
  2822. /*
  2823. ** Determine the object that the mouse is currently over.
  2824. */
  2825. if (!shadow) {
  2826. // int xxx = x + Lepton_To_Pixel(Coord_XLepton(Map.TacticalCoord));
  2827. // int yyy = y + Lepton_To_Pixel(Coord_YLepton(Map.TacticalCoord));
  2828. // object = Map.Cell_Object(cell, xxx % CELL_PIXEL_W, yyy % CELL_PIXEL_H);
  2829. object = Map.Close_Object(coord);
  2830. /*
  2831. ** Special case check to ignore cloaked object if not owned by the player.
  2832. */
  2833. // if (object && object->Is_Techno() && !((TechnoClass *)object)->IsOwnedByPlayer && ((TechnoClass *)object)->Cloak == CLOAKED) {
  2834. // object = NULL;
  2835. // }
  2836. }
  2837. /*
  2838. ** If there is a currently selected object, then the action to perform if
  2839. ** the left mouse button were clicked must be determined.
  2840. */
  2841. if (CurrentObject.Count()) {
  2842. if (object) {
  2843. action = Best_Object_Action(object);
  2844. } else {
  2845. action = Best_Object_Action(cell);
  2846. }
  2847. } else {
  2848. if (object && object->Class_Of().IsSelectable) {
  2849. action = ACTION_SELECT;
  2850. }
  2851. if (Map.IsRepairMode) {
  2852. if (object && object->Owner() == PlayerPtr->Class->House && object->Can_Repair()) {
  2853. action = ACTION_REPAIR;
  2854. } else {
  2855. action = ACTION_NO_REPAIR;
  2856. }
  2857. }
  2858. if (Map.IsSellMode) {
  2859. if (object && object->Owner() == PlayerPtr->Class->House && object->Can_Demolish()) {
  2860. if (object->What_Am_I() == RTTI_BUILDING) {
  2861. action = ACTION_SELL;
  2862. } else {
  2863. action = ACTION_SELL_UNIT;
  2864. }
  2865. } else {
  2866. /*
  2867. ** Check to see if the cursor is over an owned wall.
  2868. */
  2869. if (Map[cell].Overlay != OVERLAY_NONE &&
  2870. OverlayTypeClass::As_Reference(Map[cell].Overlay).IsWall &&
  2871. Map[cell].Owner == PlayerPtr->Class->House) {
  2872. action = ACTION_SELL;
  2873. } else {
  2874. action = ACTION_NO_SELL;
  2875. }
  2876. }
  2877. }
  2878. if (Map.IsTargettingMode == SPC_ION_CANNON) {
  2879. action = ACTION_ION;
  2880. }
  2881. if (Map.IsTargettingMode == SPC_NUCLEAR_BOMB) {
  2882. action = ACTION_NUKE_BOMB;
  2883. }
  2884. if (Map.IsTargettingMode == SPC_AIR_STRIKE) {
  2885. action = ACTION_AIR_STRIKE;
  2886. }
  2887. if (Map.PendingObject) {
  2888. action = ACTION_NONE;
  2889. }
  2890. }
  2891. /*
  2892. ** Move any cursor displayed.
  2893. */
  2894. if (cell != Map.ZoneCell) {
  2895. Map.Set_Cursor_Pos(cell);
  2896. }
  2897. /*
  2898. ** A right mouse button press cancels the current action or selection.
  2899. */
  2900. if (flags & RIGHTPRESS) {
  2901. Map.Mouse_Right_Press();
  2902. }
  2903. /*
  2904. ** Make sure that if the mouse button has been released and the map doesn't know about it,
  2905. ** then it must be informed. Do this by faking a mouse release event.
  2906. */
  2907. if ((flags & LEFTUP) && Map.IsRubberBand) {
  2908. flags |= LEFTRELEASE;
  2909. }
  2910. /*
  2911. ** When the mouse buttons aren't pressed, only the mouse cursor shape is processed.
  2912. ** The shape changes depending on what object the mouse is currently over and what
  2913. ** object is currently selected.
  2914. */
  2915. if (!edge) {
  2916. if (flags & LEFTUP) {
  2917. Map.Mouse_Left_Up(shadow, object, action);
  2918. }
  2919. }
  2920. /*
  2921. ** Normal actions occur when the mouse button is released. The press event is
  2922. ** intercepted and possible rubber-band mode is flagged.
  2923. */
  2924. if (flags & LEFTRELEASE) {
  2925. Map.Mouse_Left_Release(cell, x, y, object, action);
  2926. }
  2927. /*
  2928. ** When the mouse is first pressed on the map, then record the mouse
  2929. ** position so that a proper check before going into rubber band
  2930. ** mode can be made. Rubber band mode starts when the mouse is
  2931. ** held down and moved a certain minimum distance.
  2932. */
  2933. if (!edge && (flags & LEFTPRESS)) {
  2934. Map.Mouse_Left_Press(x, y);
  2935. }
  2936. /*
  2937. ** While the mouse is being held down, determine if rubber band mode should
  2938. ** start. If rubber band mode is already active, then update the size
  2939. ** and flag the map to redraw it.
  2940. */
  2941. if (flags & LEFTHELD) {
  2942. Map.Mouse_Left_Held(x, y);
  2943. }
  2944. }
  2945. return(GadgetClass::Action(0, key));
  2946. }
  2947. /***********************************************************************************************
  2948. * DisplayClass::TacticalClass::Selection_At_Mouse -- Object selection *
  2949. * *
  2950. * Selects any objects at the current mouse position. *
  2951. * *
  2952. * *
  2953. * INPUT: flags -- The gadget event flags that triggered the call to this function. *
  2954. * *
  2955. * key -- A reference to the keyboard event (if any). *
  2956. * *
  2957. * OUTPUT: bool; Should processing be aborted on any succeeding buttons in the chain? *
  2958. * *
  2959. * WARNINGS: none *
  2960. * *
  2961. * HISTORY: *
  2962. * 2019/09/17 JAS *
  2963. *=============================================================================================*/
  2964. int DisplayClass::TacticalClass::Selection_At_Mouse(unsigned flags, KeyNumType & key)
  2965. {
  2966. int x, y; // Sub cell pixel coordinates.
  2967. bool edge = false;
  2968. if (flags & (LEFTPRESS | LEFTRELEASE | RIGHTPRESS | RIGHTRELEASE)) {
  2969. x = _Kbd->MouseQX;
  2970. y = _Kbd->MouseQY;
  2971. }
  2972. else {
  2973. x = Get_Mouse_X();
  2974. y = Get_Mouse_Y();
  2975. if (x == 0 || y == 199 || x == 319) edge = true;
  2976. }
  2977. COORDINATE coord = Map.Pixel_To_Coord(x, y);
  2978. CELL cell = Coord_Cell(coord);
  2979. if (coord) {
  2980. bool shadow = (!Map[cell].Is_Visible(PlayerPtr) && !Debug_Unshroud); // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2981. x -= Map.TacPixelX;
  2982. y -= Map.TacPixelY;
  2983. /*
  2984. ** Cause any displayed cursor to move along with the mouse cursor.
  2985. */
  2986. if (cell != Map.ZoneCell) {
  2987. Map.Set_Cursor_Pos(cell);
  2988. }
  2989. ObjectClass* object = nullptr;
  2990. /*
  2991. ** Determine the object that the mouse is currently over.
  2992. */
  2993. if (!shadow) {
  2994. object = Map.Close_Object(coord);
  2995. }
  2996. if (object != nullptr)
  2997. {
  2998. bool shiftdown = DLL_Export_Get_Input_Key_State(KN_LSHIFT);
  2999. if (shiftdown)
  3000. {
  3001. Map.Mouse_Left_Release(cell, x, y, object, ACTION_TOGGLE_SELECT);
  3002. }
  3003. else
  3004. {
  3005. Map.Mouse_Left_Release(cell, x, y, object, ACTION_SELECT);
  3006. }
  3007. }
  3008. else
  3009. {
  3010. Unselect_All();
  3011. }
  3012. }
  3013. return 0;
  3014. }
  3015. /***********************************************************************************************
  3016. * DisplayClass::TacticalClass::Command_Object -- Commanding Units *
  3017. * *
  3018. * Issues a command to the currently selected unit. *
  3019. * *
  3020. * *
  3021. * INPUT: flags -- The gadget event flags that triggered the call to this function. *
  3022. * *
  3023. * key -- A reference to the keyboard event (if any). *
  3024. * *
  3025. * OUTPUT: bool; Should processing be aborted on any succeeding buttons in the chain? *
  3026. * *
  3027. * WARNINGS: none *
  3028. * *
  3029. * HISTORY: *
  3030. * 2019/09/17 JAS *
  3031. *=============================================================================================*/
  3032. int DisplayClass::TacticalClass::Command_Object(unsigned flags, KeyNumType & key)
  3033. {
  3034. int x, y; // Sub cell pixel coordinates.
  3035. bool edge = false;
  3036. if (flags & (LEFTPRESS | LEFTRELEASE | RIGHTPRESS | RIGHTRELEASE)) {
  3037. x = _Kbd->MouseQX;
  3038. y = _Kbd->MouseQY;
  3039. }
  3040. else {
  3041. x = Get_Mouse_X();
  3042. y = Get_Mouse_Y();
  3043. if (x == 0 || y == 199 || x == 319) edge = true;
  3044. }
  3045. COORDINATE coord = Map.Pixel_To_Coord(x, y);
  3046. CELL cell = Coord_Cell(coord);
  3047. ActionType action = ACTION_NONE;
  3048. if (coord) {
  3049. bool shadow = (!Map[cell].Is_Visible(PlayerPtr) && !Debug_Unshroud); // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  3050. x -= Map.TacPixelX;
  3051. y -= Map.TacPixelY;
  3052. /*
  3053. ** Cause any displayed cursor to move along with the mouse cursor.
  3054. */
  3055. if (cell != Map.ZoneCell) {
  3056. Map.Set_Cursor_Pos(cell);
  3057. }
  3058. ObjectClass* object = nullptr;
  3059. /*
  3060. ** Determine the object that the mouse is currently over.
  3061. */
  3062. if (!shadow) {
  3063. object = Map.Close_Object(coord);
  3064. }
  3065. if (CurrentObject.Count()) {
  3066. if (object) {
  3067. action = Best_Object_Action(object);
  3068. }
  3069. else {
  3070. action = Best_Object_Action(cell);
  3071. }
  3072. }
  3073. if (action != ACTION_SELECT)
  3074. {
  3075. Map.Mouse_Left_Release(cell, x, y, object, action);
  3076. }
  3077. }
  3078. return 0;
  3079. }
  3080. /***********************************************************************************************
  3081. * DisplayClass::Mouse_Right_Press -- Handles the right mouse button press. *
  3082. * *
  3083. * This routine is called when the right mouse button is pressed. This action is supposed *
  3084. * to cancel whatever mode or process is active. If there is nothing to cancel, then it *
  3085. * will default to unselecting any units that might be currently selected. *
  3086. * *
  3087. * INPUT: none *
  3088. * *
  3089. * OUTPUT: none *
  3090. * *
  3091. * WARNINGS: none *
  3092. * *
  3093. * HISTORY: *
  3094. * 02/24/1995 JLB : Created. *
  3095. *=============================================================================================*/
  3096. void DisplayClass::Mouse_Right_Press(void)
  3097. {
  3098. if (PendingObjectPtr && PendingObjectPtr->Is_Techno()) {
  3099. //PendingObjectPtr->Transmit_Message(RADIO_OVER_OUT);
  3100. PendingObjectPtr = 0;
  3101. PendingObject = 0;
  3102. PendingHouse = HOUSE_NONE;
  3103. Set_Cursor_Shape(0);
  3104. } else {
  3105. if (IsRepairMode) {
  3106. IsRepairMode = false;
  3107. } else {
  3108. if (IsSellMode) {
  3109. IsSellMode = false;
  3110. } else {
  3111. if (IsTargettingMode) {
  3112. IsTargettingMode = false;
  3113. } else {
  3114. Unselect_All();
  3115. }
  3116. }
  3117. }
  3118. }
  3119. Set_Default_Mouse(MOUSE_NORMAL, false);
  3120. }
  3121. /***********************************************************************************************
  3122. * DisplayClass::Mouse_Left_Up -- Handles the left mouse "cruising" over the map. *
  3123. * *
  3124. * This routine is called continuously while the mouse is over the tactical map but there *
  3125. * are no mouse buttons pressed. Typically, this adjusts the mouse shape and the pop-up *
  3126. * help text. *
  3127. * *
  3128. * INPUT: shadow -- Is the mouse hovering over shadowed terrain? *
  3129. * *
  3130. * object -- Pointer to the object that the mouse is currently over (may be NULL). *
  3131. * *
  3132. * action -- This is the action that the currently selected object (if any) will *
  3133. * perform if the left mouse button were clicked at this location. *
  3134. * *
  3135. * OUTPUT: none *
  3136. * *
  3137. * WARNINGS: none *
  3138. * *
  3139. * HISTORY: *
  3140. * 02/24/1995 JLB : Created. *
  3141. * 07/05/1995 JLB : Removed pop up help text for shadow and terrain after #3. *
  3142. *=============================================================================================*/
  3143. void DisplayClass::Mouse_Left_Up(bool shadow, ObjectClass * object, ActionType action, bool wwsmall)
  3144. {
  3145. IsTentative = false;
  3146. /*
  3147. ** Don't allow selection of an object that is located in shadowed terrain.
  3148. ** In fact, just show the normal move cursor in order to keep the shadowed
  3149. ** terrain a mystery.
  3150. */
  3151. if (shadow) {
  3152. switch (action) {
  3153. case ACTION_GUARD_AREA:
  3154. Set_Default_Mouse(MOUSE_AREA_GUARD, wwsmall);
  3155. break;
  3156. case ACTION_NONE:
  3157. Set_Default_Mouse(MOUSE_NORMAL, wwsmall);
  3158. break;
  3159. case ACTION_NO_SELL:
  3160. case ACTION_SELL:
  3161. case ACTION_SELL_UNIT:
  3162. Set_Default_Mouse(MOUSE_NO_SELL_BACK, wwsmall);
  3163. break;
  3164. case ACTION_NO_REPAIR:
  3165. case ACTION_REPAIR:
  3166. Set_Default_Mouse(MOUSE_NO_REPAIR, wwsmall);
  3167. break;
  3168. case ACTION_ION:
  3169. Set_Default_Mouse(MOUSE_ION_CANNON, wwsmall);
  3170. break;
  3171. case ACTION_NUKE_BOMB:
  3172. Set_Default_Mouse(MOUSE_NUCLEAR_BOMB, wwsmall);
  3173. break;
  3174. case ACTION_AIR_STRIKE:
  3175. Set_Default_Mouse(MOUSE_AIR_STRIKE, wwsmall);
  3176. break;
  3177. case ACTION_NOMOVE:
  3178. if (CurrentObject.Count()) {
  3179. MouseType mouse_type = MOUSE_NO_MOVE;
  3180. for (int i = 0; i < CurrentObject.Count(); ++i) {
  3181. if (CurrentObject[i]->What_Am_I() != RTTI_AIRCRAFT) {
  3182. mouse_type = MOUSE_CAN_MOVE;
  3183. break;
  3184. }
  3185. }
  3186. Set_Default_Mouse(mouse_type, wwsmall);
  3187. break;
  3188. }
  3189. // Fall into next case for non aircraft object types.
  3190. default:
  3191. Set_Default_Mouse(MOUSE_CAN_MOVE, wwsmall);
  3192. break;
  3193. }
  3194. } else {
  3195. /*
  3196. ** Change the mouse shape according to the default action that will occur
  3197. ** if the mouse button were clicked at this location.
  3198. */
  3199. switch (action) {
  3200. case ACTION_TOGGLE_SELECT:
  3201. case ACTION_SELECT:
  3202. Set_Default_Mouse(MOUSE_CAN_SELECT, wwsmall);
  3203. break;
  3204. case ACTION_MOVE:
  3205. Set_Default_Mouse(MOUSE_CAN_MOVE, wwsmall);
  3206. break;
  3207. case ACTION_GUARD_AREA:
  3208. Set_Default_Mouse(MOUSE_AREA_GUARD, wwsmall);
  3209. break;
  3210. case ACTION_HARVEST:
  3211. case ACTION_ATTACK:
  3212. Set_Default_Mouse(MOUSE_CAN_ATTACK, wwsmall);
  3213. break;
  3214. case ACTION_SABOTAGE:
  3215. Set_Default_Mouse(MOUSE_DEMOLITIONS, wwsmall);
  3216. break;
  3217. case ACTION_ENTER:
  3218. case ACTION_CAPTURE:
  3219. Set_Default_Mouse(MOUSE_ENTER, wwsmall);
  3220. break;
  3221. case ACTION_NOMOVE:
  3222. Set_Default_Mouse(MOUSE_NO_MOVE, wwsmall);
  3223. break;
  3224. case ACTION_NO_SELL:
  3225. Set_Default_Mouse(MOUSE_NO_SELL_BACK, wwsmall);
  3226. break;
  3227. case ACTION_NO_REPAIR:
  3228. Set_Default_Mouse(MOUSE_NO_REPAIR, wwsmall);
  3229. break;
  3230. case ACTION_SELF:
  3231. Set_Default_Mouse(MOUSE_DEPLOY, wwsmall);
  3232. break;
  3233. case ACTION_REPAIR:
  3234. Set_Default_Mouse(MOUSE_REPAIR, wwsmall);
  3235. break;
  3236. case ACTION_SELL_UNIT:
  3237. Set_Default_Mouse(MOUSE_SELL_UNIT, wwsmall);
  3238. break;
  3239. case ACTION_SELL:
  3240. Set_Default_Mouse(MOUSE_SELL_BACK, wwsmall);
  3241. break;
  3242. case ACTION_ION:
  3243. Set_Default_Mouse(MOUSE_ION_CANNON, wwsmall);
  3244. break;
  3245. case ACTION_NUKE_BOMB:
  3246. Set_Default_Mouse(MOUSE_NUCLEAR_BOMB, wwsmall);
  3247. break;
  3248. case ACTION_AIR_STRIKE:
  3249. Set_Default_Mouse(MOUSE_AIR_STRIKE, wwsmall);
  3250. break;
  3251. case ACTION_TOGGLE_PRIMARY:
  3252. Set_Default_Mouse(MOUSE_DEPLOY, wwsmall);
  3253. break;
  3254. default:
  3255. Set_Default_Mouse(MOUSE_NORMAL, wwsmall);
  3256. break;
  3257. }
  3258. }
  3259. #if 0
  3260. /*
  3261. ** Give a generic help message when over shadow terrain.
  3262. */
  3263. if (shadow) {
  3264. if (Scenario < 4) {
  3265. Help_Text(TXT_SHADOW);
  3266. } else {
  3267. Help_Text(TXT_NONE);
  3268. }
  3269. } else {
  3270. /*
  3271. ** If the mouse is held over objects on the map, then help text may
  3272. ** pop up that tells what the object is. This call informs the help
  3273. ** system of the text name for the object under the mouse.
  3274. */
  3275. if (object) {
  3276. int text;
  3277. int color = LTGREY;
  3278. /*
  3279. ** Fetch the appropriate background color for help text.
  3280. */
  3281. if (PlayerPtr->Is_Ally(object)) {
  3282. color = CC_GREEN;
  3283. } else {
  3284. if (object->Owner() == HOUSE_NONE || object->Owner() == HOUSE_NEUTRAL) {
  3285. color = LTGREY;
  3286. } else {
  3287. color = PINK;
  3288. }
  3289. }
  3290. /*
  3291. ** Fetch the name of the object. If it is an enemy object, then
  3292. ** the exact identity is glossed over with a generic text.
  3293. */
  3294. text = object->Full_Name();
  3295. if (object->Is_Techno() && !((TechnoTypeClass const &)object->Class_Of()).IsNominal) {
  3296. if (!PlayerPtr->Is_Ally(object)) {
  3297. switch (object->What_Am_I()) {
  3298. case RTTI_INFANTRY:
  3299. text = TXT_ENEMY_SOLDIER;
  3300. break;
  3301. case RTTI_UNIT:
  3302. text = TXT_ENEMY_VEHICLE;
  3303. break;
  3304. case RTTI_BUILDING:
  3305. if ( *((BuildingClass*)object) != STRUCT_MISSION) {
  3306. text = TXT_ENEMY_STRUCTURE;
  3307. }
  3308. break;
  3309. }
  3310. }
  3311. }
  3312. if (Scenario > 3 || object->What_Am_I() != RTTI_TERRAIN) {
  3313. Help_Text(text, -1, -1, color);
  3314. } else {
  3315. Help_Text(TXT_NONE);
  3316. }
  3317. } else {
  3318. Help_Text(TXT_NONE);
  3319. }
  3320. }
  3321. #endif
  3322. }
  3323. /***********************************************************************************************
  3324. * DisplayClass::Mouse_Left_Release -- Handles the left mouse button release. *
  3325. * *
  3326. * This routine is called when the left mouse button is released over the tactical map. *
  3327. * The release event is the workhorse of the game. Most actions occur at the moment of *
  3328. * mouse release. *
  3329. * *
  3330. * INPUT: cell -- The cell that the mouse is over. *
  3331. * *
  3332. * x,y -- The mouse pixel coordinate. *
  3333. * *
  3334. * object -- Pointer to the object that the mouse is over. *
  3335. * *
  3336. * action -- The action that the currently selected object (if any) will *
  3337. * perform. *
  3338. * *
  3339. * OUTPUT: none *
  3340. * *
  3341. * WARNINGS: none *
  3342. * *
  3343. * HISTORY: *
  3344. * 02/24/1995 JLB : Created. *
  3345. * 03/27/1995 JLB : Handles sell and repair actions. *
  3346. *=============================================================================================*/
  3347. void DisplayClass::Mouse_Left_Release(CELL cell, int x, int y, ObjectClass * object, ActionType action, bool wwsmall)
  3348. {
  3349. if (PendingObjectPtr) {
  3350. /*
  3351. ** Try to place the pending object onto the map.
  3352. */
  3353. if (ProximityCheck) {
  3354. OutList.Add(EventClass(EventClass::PLACE, PendingObjectPtr->What_Am_I(), cell + ZoneOffset));
  3355. } else {
  3356. Speak(VOX_DEPLOY);
  3357. }
  3358. } else {
  3359. if (IsRubberBand) {
  3360. Refresh_Band();
  3361. Select_These(XYPixel_Coord(BandX, BandY), XYPixel_Coord(x, y));
  3362. Set_Default_Mouse(MOUSE_NORMAL, wwsmall);
  3363. #ifdef NEVER
  3364. if (CurrentObject.Count()) {
  3365. if (CurrentObject[0]->Can_Player_Fire()) {
  3366. Set_Default_Mouse(MOUSE_CAN_ATTACK, wwsmall);
  3367. } else {
  3368. Set_Default_Mouse(MOUSE_NORMAL, wwsmall);
  3369. }
  3370. } else {
  3371. Set_Default_Mouse(MOUSE_NORMAL, wwsmall);
  3372. }
  3373. #endif
  3374. IsRubberBand = false;
  3375. IsTentative = false;
  3376. Map.DisplayClass::IsToRedraw = true;
  3377. Map.Flag_To_Redraw(false);
  3378. } else {
  3379. /*
  3380. ** Toggle the select state of the object.
  3381. */
  3382. if (action == ACTION_TOGGLE_SELECT) {
  3383. if (!object || !CurrentObject.Count()) {
  3384. action = ACTION_SELECT;
  3385. } else {
  3386. if (object->Is_Selected_By_Player()) {
  3387. object->Unselect();
  3388. } else {
  3389. object->Select();
  3390. }
  3391. }
  3392. }
  3393. /*
  3394. ** Selection of other object action.
  3395. */
  3396. if (action == ACTION_SELECT || (action == ACTION_NONE && object && object->Class_Of().IsSelectable && !object->Is_Selected_By_Player())) {
  3397. if (object->Is_Selected_By_Player()) {
  3398. object->Unselect();
  3399. }
  3400. if (object->Select()) {
  3401. Unselect_All_Except(object);
  3402. Set_Default_Mouse(MOUSE_NORMAL, wwsmall);
  3403. }
  3404. #ifdef NEVER
  3405. if (object->Can_Player_Fire()) {
  3406. Set_Default_Mouse(MOUSE_CAN_ATTACK, wwsmall);
  3407. } else {
  3408. Set_Default_Mouse(MOUSE_NORMAL, wwsmall);
  3409. }
  3410. #endif
  3411. }
  3412. /*
  3413. ** If an action was detected as possible, then pass this action event
  3414. ** to all selected objects.
  3415. */
  3416. if (action != ACTION_NONE && action != ACTION_SELECT && action != ACTION_TOGGLE_SELECT) {
  3417. /*
  3418. ** Pass the action to all the selected objects. But first, redetermine
  3419. ** what action that object should perform. This, seemingly redundant
  3420. ** process, is necessary since multiple objects could be selected and each
  3421. ** might perform a different action when the click occurs.
  3422. */
  3423. bool doflash = true;
  3424. AllowVoice = true;
  3425. for (int index = 0; index < CurrentObject.Count(); index++) {
  3426. ObjectClass * tobject = CurrentObject[index];
  3427. ActionType action = ACTION_NONE;
  3428. if (object) {
  3429. action = tobject->What_Action(object);
  3430. tobject->Active_Click_With(action, object);
  3431. } else {
  3432. action = tobject->What_Action(cell);
  3433. tobject->Active_Click_With(action, cell);
  3434. }
  3435. if (action != ACTION_NONE) {
  3436. AllowVoice = false;
  3437. }
  3438. }
  3439. AllowVoice = true;
  3440. if (action == ACTION_REPAIR && object->What_Am_I() == RTTI_BUILDING) {
  3441. OutList.Add(EventClass(EventClass::REPAIR, object->As_Target()));
  3442. }
  3443. if (action == ACTION_SELL_UNIT && object) {
  3444. switch (object->What_Am_I()) {
  3445. case RTTI_AIRCRAFT:
  3446. case RTTI_UNIT:
  3447. OutList.Add(EventClass(EventClass::SELL, object->As_Target()));
  3448. break;
  3449. default:
  3450. break;
  3451. }
  3452. }
  3453. if (action == ACTION_SELL) {
  3454. if (object) {
  3455. OutList.Add(EventClass(EventClass::SELL, object->As_Target()));
  3456. } else {
  3457. OutList.Add(EventClass(EventClass::SELL, ::As_Target(cell)));
  3458. }
  3459. }
  3460. if (action == ACTION_ION) {
  3461. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_ION_CANNON, cell));
  3462. }
  3463. if (action == ACTION_NUKE_BOMB) {
  3464. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_NUCLEAR_BOMB, cell));
  3465. }
  3466. if (action == ACTION_AIR_STRIKE) {
  3467. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_AIR_STRIKE, cell));
  3468. }
  3469. }
  3470. IsTentative = false;
  3471. }
  3472. }
  3473. }
  3474. /***********************************************************************************************
  3475. * DisplayClass::Mouse_Left_Press -- Handles the left mouse button press. *
  3476. * *
  3477. * Handle the left mouse button press while over the tactical map. If it isn't is *
  3478. * repair or sell mode, then a tentative transition to rubber band mode is flagged. If the *
  3479. * mouse moves a sufficient distance from this recorded position, then rubber band mode *
  3480. * is officially started. *
  3481. * *
  3482. * INPUT: x,y -- The mouse coordinates at the time of the press. *
  3483. * *
  3484. * OUTPUT: none *
  3485. * *
  3486. * WARNINGS: none *
  3487. * *
  3488. * HISTORY: *
  3489. * 02/24/1995 JLB : Created. *
  3490. *=============================================================================================*/
  3491. void DisplayClass::Mouse_Left_Press(int x, int y)
  3492. {
  3493. if (!IsRepairMode && !IsSellMode && !IsTargettingMode && !PendingObject) {
  3494. IsTentative = true;
  3495. BandX = x;
  3496. BandY = y;
  3497. NewX = x;
  3498. NewY = y;
  3499. }
  3500. }
  3501. /***********************************************************************************************
  3502. * DisplayClass::Mouse_Left_Held -- Handles the left button held down. *
  3503. * *
  3504. * This routine is called continuously while the left mouse button is held down over *
  3505. * the tactical map. This handles the rubber band mode detection and dragging. *
  3506. * *
  3507. * INPUT: x,y -- The mouse coordinate. *
  3508. * *
  3509. * OUTPUT: none *
  3510. * *
  3511. * WARNINGS: none *
  3512. * *
  3513. * HISTORY: *
  3514. * 02/24/1995 JLB : Created. *
  3515. *=============================================================================================*/
  3516. void DisplayClass::Mouse_Left_Held(int x, int y)
  3517. {
  3518. if (IsRubberBand) {
  3519. if (x != NewX || y != NewY) {
  3520. x = Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1);
  3521. y = Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1);
  3522. Refresh_Band();
  3523. NewX = x;
  3524. NewY = y;
  3525. IsToRedraw = true;
  3526. Flag_To_Redraw(false);
  3527. }
  3528. } else {
  3529. /*
  3530. ** If the mouse is still held down while a tentative extended select is possible, then
  3531. ** check to see if the mouse has moved a sufficient distance in order to activate
  3532. ** extended select mode.
  3533. */
  3534. if (IsTentative) {
  3535. /*
  3536. ** The mouse must have moved a minimum distance before rubber band mode can be
  3537. ** initiated.
  3538. */
  3539. if (ABS(x - BandX) > 4 || ABS(y - BandY) > 4) {
  3540. IsRubberBand = true;
  3541. x = Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1);
  3542. y = Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1);
  3543. NewX = x;
  3544. NewY = y;
  3545. IsToRedraw = true;
  3546. Flag_To_Redraw(false);
  3547. }
  3548. }
  3549. }
  3550. }
  3551. // Needed to accomodate Glyphx client sidebar. ST - 4/12/2019 5:29PM
  3552. extern int GlyphXClientSidebarWidthInLeptons;
  3553. /***********************************************************************************************
  3554. * DisplayClass::Set_Tactical_Position -- Sets the tactical view position. *
  3555. * *
  3556. * This routine is used to set the tactical view position. The requested position is *
  3557. * clipped to the map dimensions as necessary. *
  3558. * *
  3559. * INPUT: coord -- The coordinate desired for the upper left corner. *
  3560. * *
  3561. * OUTPUT: none *
  3562. * *
  3563. * WARNINGS: none *
  3564. * *
  3565. * HISTORY: *
  3566. * 08/13/1995 JLB : Created. *
  3567. *=============================================================================================*/
  3568. void DisplayClass::Set_Tactical_Position(COORDINATE coord)
  3569. {
  3570. /*
  3571. ** Bound the desired location to fit the legal map edges.
  3572. */
  3573. int xx = 0;// Coord_X(coord) - Cell_To_Lepton(MapCellX);
  3574. int yy = 0;// Coord_Y(coord) - Cell_To_Lepton(MapCellY);
  3575. Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, Cell_To_Lepton(MapCellWidth) + GlyphXClientSidebarWidthInLeptons, Cell_To_Lepton(MapCellHeight)); // Needed to accomodate Glyphx client sidebar. ST - 4/12/2019 5:29PM
  3576. coord = XY_Coord(xx + Cell_To_Lepton(MapCellX), yy + Cell_To_Lepton(MapCellY));
  3577. if (ScenarioInit) {
  3578. TacticalCoord = coord;
  3579. }
  3580. DesiredTacticalCoord = coord;
  3581. IsToRedraw = true;
  3582. Flag_To_Redraw(false);
  3583. }
  3584. /***********************************************************************************************
  3585. * DisplayClass::Compute_Start_Pos -- Computes player's start pos from unit coords. *
  3586. * *
  3587. * Use this function in multiplayer games, to compute the scenario starting Tactical Pos. *
  3588. * *
  3589. * INPUT: none *
  3590. * *
  3591. * OUTPUT: x, y -- Player starting location *
  3592. * *
  3593. * WARNINGS: none *
  3594. * *
  3595. * HISTORY: *
  3596. * 02/28/1995 JLB : Commented. *
  3597. * 06/26/1995 JLB : Fixed building loop. *
  3598. *=============================================================================================*/
  3599. void DisplayClass::Compute_Start_Pos(long& x, long& y)
  3600. {
  3601. /*
  3602. ** Find the summation cell-x & cell-y for all the player's units, infantry,
  3603. ** and buildings. Buildings are weighted so that they count 16 times more
  3604. ** than units or infantry.
  3605. */
  3606. x = 0;
  3607. y = 0;
  3608. long num = 0;
  3609. int i;
  3610. for (i = 0; i < Infantry.Count(); i++) {
  3611. InfantryClass * infp = Infantry.Ptr(i);
  3612. if (!infp->IsInLimbo && infp->House == PlayerPtr) {
  3613. x += (long)Coord_XCell (infp->Coord);
  3614. y += (long)Coord_YCell (infp->Coord);
  3615. num++;
  3616. }
  3617. }
  3618. for (i = 0; i < Units.Count(); i++) {
  3619. UnitClass * unitp = Units.Ptr(i);
  3620. if (!unitp->IsInLimbo && unitp->House == PlayerPtr) {
  3621. x += (long)Coord_XCell (unitp->Coord);
  3622. y += (long)Coord_YCell (unitp->Coord);
  3623. num++;
  3624. }
  3625. }
  3626. for (i = 0; i < Buildings.Count(); i++) {
  3627. BuildingClass * bldgp = Buildings.Ptr(i);
  3628. if (!bldgp->IsInLimbo && bldgp->House == PlayerPtr) {
  3629. x += (((long)Coord_XCell (bldgp->Coord)) << 4);
  3630. y += (((long)Coord_YCell (bldgp->Coord)) << 4);
  3631. num += 16;
  3632. }
  3633. }
  3634. /*
  3635. ** Divide each coord by 'num' to compute the average value
  3636. */
  3637. if (num > 0) {
  3638. x /= num;
  3639. } else {
  3640. x = 0;
  3641. }
  3642. if (num > 0) {
  3643. y /= num;
  3644. } else {
  3645. y = 0;
  3646. }
  3647. }
  3648. /***********************************************************************************************
  3649. * DisplayClass::Sell_Mode_Control -- Controls the sell mode. *
  3650. * *
  3651. * This routine will control the sell mode for the player. *
  3652. * *
  3653. * INPUT: control -- The mode to set the sell state to. *
  3654. * 0 = Turn sell mode off. *
  3655. * 1 = Turn sell mode on. *
  3656. * -1 = Toggle sell mode. *
  3657. * *
  3658. * OUTPUT: none *
  3659. * *
  3660. * WARNINGS: none *
  3661. * *
  3662. * HISTORY: *
  3663. * 07/08/1995 JLB : Created. *
  3664. *=============================================================================================*/
  3665. void DisplayClass::Sell_Mode_Control(int control)
  3666. {
  3667. bool mode = IsSellMode;
  3668. switch (control) {
  3669. case 0:
  3670. mode = false;
  3671. break;
  3672. case -1:
  3673. mode = (IsSellMode == false);
  3674. break;
  3675. case 1:
  3676. mode = true;
  3677. break;
  3678. }
  3679. if (mode != IsSellMode && !PendingObject) {
  3680. IsRepairMode = false;
  3681. if (mode && PlayerPtr->BScan) {
  3682. IsSellMode = true;
  3683. Unselect_All();
  3684. } else {
  3685. IsSellMode = false;
  3686. Revert_Mouse_Shape();
  3687. }
  3688. }
  3689. }
  3690. /***********************************************************************************************
  3691. * DisplayClass::Repair_Mode_Control -- Controls the repair mode. *
  3692. * *
  3693. * This routine is used to control the repair mode for the player. *
  3694. * *
  3695. * INPUT: control -- The mode to set the repair to. *
  3696. * 0 = Turn repair off. *
  3697. * 1 = Turn repair on. *
  3698. * -1= Toggle repair state. *
  3699. * *
  3700. * OUTPUT: none *
  3701. * *
  3702. * WARNINGS: none *
  3703. * *
  3704. * HISTORY: *
  3705. * 07/08/1995 JLB : Created. *
  3706. *=============================================================================================*/
  3707. void DisplayClass::Repair_Mode_Control(int control)
  3708. {
  3709. bool mode = IsRepairMode;
  3710. switch (control) {
  3711. case 0:
  3712. mode = false;
  3713. break;
  3714. case -1:
  3715. mode = (IsRepairMode == false);
  3716. break;
  3717. case 1:
  3718. mode = true;
  3719. break;
  3720. }
  3721. if (mode != IsRepairMode && !PendingObject) {
  3722. IsSellMode = false;
  3723. if (mode && PlayerPtr->BScan) {
  3724. IsRepairMode = true;
  3725. Unselect_All();
  3726. } else {
  3727. IsRepairMode = false;
  3728. Revert_Mouse_Shape();
  3729. }
  3730. }
  3731. }
  3732. /***********************************************************************************************
  3733. * DisplayClass::In_View -- Determines if cell is visible on screen. *
  3734. * *
  3735. * Use this routine to determine if the specified cell is visible on *
  3736. * the display. This is a useful fact, since many display operations *
  3737. * can be skipped if the cell is not visible. *
  3738. * *
  3739. * INPUT: cell -- The cell number to check. *
  3740. * *
  3741. * OUTPUT: bool; Is this cell visible on the display? *
  3742. * *
  3743. * WARNINGS: none *
  3744. * *
  3745. * HISTORY: *
  3746. * 04/30/1994 JLB : Created. *
  3747. * 04/30/1994 JLB : Converted to member function. *
  3748. *=============================================================================================*/
  3749. bool DisplayClass::In_View(register CELL cell)
  3750. {
  3751. COORDINATE coord = Cell_Coord(cell) & 0xFF00FF00L;
  3752. COORDINATE tcoord = TacticalCoord & 0xFF00FF00L;
  3753. if ((Coord_X(coord) - Coord_X(tcoord)) > TacLeptonWidth+255) return(false);
  3754. if ((Coord_Y(coord) - Coord_Y(tcoord)) > TacLeptonHeight+255) return(false);
  3755. return(true);
  3756. #ifdef OBSOLETE
  3757. int fudgex = Coord_XLepton(TacticalCoord) ? -1 : 0;
  3758. int fudgey = Coord_YLepton(TacticalCoord) ? -1 : 0;
  3759. if ((unsigned)(Cell_X(cell)-Coord_XCell(TacticalCoord)) > Lepton_To_Cell(TacLeptonWidth)+fudgex) return(false);
  3760. if ((unsigned)(Cell_Y(cell)-Coord_YCell(TacticalCoord)) > Lepton_To_Cell(TacLeptonHeight)+fudgey) return(false);
  3761. return(true);
  3762. #endif
  3763. #ifdef OBSOLETE
  3764. cell -= TacticalCell;
  3765. if (Cell_X(cell) >= TacWidth + (TacPartialX ? 1 : 0)) return(false);
  3766. if (Cell_Y(cell) >= TacHeight + (TacPartialY ? 1 : 0)) return(false);
  3767. return(true);
  3768. #endif
  3769. }
  3770. COORDINATE DisplayClass::Closest_Free_Spot(COORDINATE coord, bool any) const
  3771. {
  3772. if (coord & 0xC000C000) {
  3773. return(0x00800080);
  3774. }
  3775. return (*this)[Coord_Cell(coord)].Closest_Free_Spot(coord, any);
  3776. }
  3777. bool DisplayClass::Is_Spot_Free(COORDINATE coord) const
  3778. {
  3779. // This doesn't seem right... ST - 12/18/2018 10:09AM
  3780. //if (coord & 0xC000C000) {
  3781. // return(0x00800080);
  3782. //}
  3783. return (*this)[Coord_Cell(coord)].Is_Spot_Free(CellClass::Spot_Index(coord));
  3784. }
  3785. /***********************************************************************************************
  3786. * DisplayClass::Center_Map -- Centers the map about the currently selected objects *
  3787. * *
  3788. * This routine will average the position of all the selected objects and then center *
  3789. * the map about those objects. *
  3790. * *
  3791. * INPUT: none *
  3792. * *
  3793. * OUTPUT: The center coordinate. *
  3794. * *
  3795. * WARNINGS: The map position changes by this routine. *
  3796. * *
  3797. * HISTORY: *
  3798. * 08/22/1995 JLB : Created. *
  3799. *=============================================================================================*/
  3800. COORDINATE DisplayClass::Center_Map(void)
  3801. {
  3802. if (CurrentObject.Count()) {
  3803. unsigned x = 0;
  3804. unsigned y = 0;
  3805. for (int index = 0; index < CurrentObject.Count(); index++) {
  3806. COORDINATE coord = CurrentObject[index]->Center_Coord();
  3807. x += Coord_X(coord);
  3808. y += Coord_Y(coord);
  3809. }
  3810. x /= CurrentObject.Count();
  3811. y /= CurrentObject.Count();
  3812. Set_Tactical_Position(XY_Coord(x - (TacLeptonWidth/2), y - (TacLeptonHeight/2)));
  3813. return XY_Coord(x, y);
  3814. }
  3815. return 0;
  3816. }
  3817. static ActionType _priority_actions[] = {
  3818. ACTION_ATTACK,
  3819. ACTION_ENTER,
  3820. ACTION_REPAIR,
  3821. ACTION_SABOTAGE,
  3822. ACTION_CAPTURE,
  3823. ACTION_MOVE
  3824. };
  3825. static int get_action_priority(ActionType action)
  3826. {
  3827. for (int i = 0; i < sizeof(_priority_actions) / sizeof(_priority_actions[0]); ++i) {
  3828. if (_priority_actions[i] == action) {
  3829. return i;
  3830. }
  3831. }
  3832. return INT_MAX;
  3833. }
  3834. template <typename T>
  3835. static int index_of(const DynamicVectorClass<T*>& list, T* object)
  3836. {
  3837. for (int i = 0; i < list.Count(); i++) {
  3838. if (list[i] == object) {
  3839. return i;
  3840. }
  3841. }
  3842. return -1;
  3843. }
  3844. template <typename T>
  3845. static ObjectClass* Best_Object_With_ActionT(DynamicVectorClass<ObjectClass*>& objects, T subject)
  3846. {
  3847. DynamicVectorClass<const ObjectTypeClass*> checked_types;
  3848. if (objects.Count()) {
  3849. int best_priority = INT_MAX;
  3850. ObjectClass* best_object = objects[0];
  3851. for (int i = 0; i < objects.Count(); ++i) {
  3852. ObjectClass* object = objects[i];
  3853. const ObjectTypeClass* type = &object->Class_Of();
  3854. if (index_of(checked_types, type) != -1) {
  3855. continue;
  3856. }
  3857. checked_types.Add(type);
  3858. ActionType action = object->What_Action(subject);
  3859. int priority = get_action_priority(action);
  3860. if (priority < best_priority) {
  3861. best_priority = priority;
  3862. best_object = object;
  3863. if (best_priority == 0) {
  3864. break;
  3865. }
  3866. }
  3867. }
  3868. return best_object;
  3869. }
  3870. return NULL;
  3871. }
  3872. ObjectClass* Best_Object_With_Action(DynamicVectorClass<ObjectClass*>& objects, ObjectClass* object)
  3873. {
  3874. return Best_Object_With_ActionT(objects, object);
  3875. }
  3876. ObjectClass* Best_Object_With_Action(DynamicVectorClass<ObjectClass*>& objects, CELL cell)
  3877. {
  3878. return Best_Object_With_ActionT(objects, cell);
  3879. }
  3880. ActionType Best_Object_Action(DynamicVectorClass<ObjectClass*>& objects, ObjectClass* object)
  3881. {
  3882. ObjectClass* obj = Best_Object_With_Action(objects, object);
  3883. return (obj != NULL) ? obj->What_Action(object) : ACTION_NONE;
  3884. }
  3885. ActionType Best_Object_Action(DynamicVectorClass<ObjectClass*>& objects, CELL cell)
  3886. {
  3887. ObjectClass* obj = Best_Object_With_Action(objects, cell);
  3888. return (obj != NULL) ? obj->What_Action(cell) : ACTION_NONE;
  3889. }
  3890. ObjectClass* Best_Object_With_Action(ObjectClass* object)
  3891. {
  3892. return Best_Object_With_Action(CurrentObject.Raw(), object);
  3893. }
  3894. ObjectClass* Best_Object_With_Action(CELL cell)
  3895. {
  3896. return Best_Object_With_Action(CurrentObject.Raw(), cell);
  3897. }
  3898. ActionType Best_Object_Action(ObjectClass* object)
  3899. {
  3900. return Best_Object_Action(CurrentObject.Raw(), object);
  3901. }
  3902. ActionType Best_Object_Action(CELL cell)
  3903. {
  3904. return Best_Object_Action(CurrentObject.Raw(), cell);
  3905. }