DISPLAY.CPP 213 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/DISPLAY.CPP 3 3/09/97 8:04p 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 : October 20, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * DisplayClass::Compute_Start_Pos -- Computes player's start pos from unit coords. *
  32. * DisplayClass::AI -- Handles the maintenance tasks for the map display. *
  33. * DisplayClass::All_To_Look -- Direct all objects to look around for the player. *
  34. * DisplayClass::Calculated_Cell -- Fetch a map cell based on specified method. *
  35. * DisplayClass::Cell_Object -- Determines what has been clicked on. *
  36. * DisplayClass::Cell_Shadow -- Determine what shadow icon to use for the cell. *
  37. * DisplayClass::Center_Map -- Centers the map about the currently selected objects *
  38. * DisplayClass::Click_Cell_Calc -- Determines cell from screen X & Y. *
  39. * DisplayClass::Closest_Free_Spot -- Finds the closest cell sub spot that is free. *
  40. * DisplayClass::Coord_To_Pixel -- Determines X and Y pixel coordinates. *
  41. * DisplayClass::Cursor_Mark -- Set or resets the cursor display flag bits. *
  42. * DisplayClass::DisplayClass -- Default constructor for display class. *
  43. * DisplayClass::Draw_It -- Draws the tactical map. *
  44. * DisplayClass::Encroach_Shadow -- Causes the shadow to creep back by one cell. *
  45. * DisplayClass::Flag_Cell -- Flag the specified cell to be redrawn. *
  46. * DisplayClass::Flag_To_Redraw -- Flags the display so that it will be redrawn as soon as poss*
  47. * DisplayClass::Get_Occupy_Dimensions -- computes width & height of the given occupy list *
  48. * DisplayClass::Good_Reinforcement_Cell -- Checks cell for renforcement legality. *
  49. * DisplayClass::In_View -- Determines if cell is visible on screen. *
  50. * DisplayClass::Init_Clear -- Clears the display to a known state. *
  51. * DisplayClass::Init_IO -- Creates the map's button list *
  52. * DisplayClass::Init_Theater -- Theater-specific initialization *
  53. * DisplayClass::Is_Spot_Free -- Determines if cell sub spot is free of occupation. *
  54. * DisplayClass::Map_Cell -- Mark specified cell as having been mapped. *
  55. * DisplayClass::Mouse_Left_Held -- Handles the left button held down. *
  56. * DisplayClass::Mouse_Left_Press -- Handles the left mouse button press. *
  57. * DisplayClass::Mouse_Left_Release -- Handles the left mouse button release. *
  58. * DisplayClass::Mouse_Left_Up -- Handles the left mouse "cruising" over the map. *
  59. * DisplayClass::Mouse_Right_Press -- Handles the right mouse button press. *
  60. * DisplayClass::Next_Object -- Searches for next object on display. *
  61. * DisplayClass::One_Time -- Performs any special one time initializations. *
  62. * DisplayClass::Passes_Proximity_Check -- Determines if building placement is near friendly sq*
  63. * DisplayClass::Pixel_To_Coord -- converts screen coord to COORDINATE *
  64. * DisplayClass::Prev_Object -- Searches for the previous object on the map. *
  65. * DisplayClass::Read_INI -- Reads map control data from INI file. *
  66. * DisplayClass::Redraw_Icons -- Draws all terrain icons necessary. *
  67. * DisplayClass::Redraw_Shadow -- Draw the shadow overlay. *
  68. * DisplayClass::Refresh_Band -- Causes all cells under the rubber band to be redrawn. *
  69. * DisplayClass::Refresh_Cells -- Redraws all cells in list. *
  70. * DisplayClass::Remove -- Removes a game object from the rendering system. *
  71. * DisplayClass::Repair_Mode_Control -- Controls the repair mode. *
  72. * DisplayClass::Scroll_Map -- Scroll the tactical map in desired direction. *
  73. * DisplayClass::Select_These -- All selectable objects in region are selected. *
  74. * DisplayClass::Sell_Mode_Control -- Controls the sell mode. *
  75. * DisplayClass::Set_Cursor_Pos -- Controls the display and animation of the tac cursor. *
  76. * DisplayClass::Set_Cursor_Shape -- Changes the shape of the terrain square cursor. *
  77. * DisplayClass::Set_Tactical_Position -- Sets the tactical view position. *
  78. * DisplayClass::Set_View_Dimensions -- Sets the tactical display screen coordinates. *
  79. * DisplayClass::Shroud_Cell -- Returns the specified cell into the shrouded condition. *
  80. * DisplayClass::Submit -- Adds a game object to the map rendering system. *
  81. * DisplayClass::TacticalClass::Action -- Processes input for the tactical map. *
  82. * DisplayClass::Text_Overlap_List -- Creates cell overlap list for specified text string. *
  83. * DisplayClass::Write_INI -- Write the map data to the INI file specified. *
  84. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  85. #include "function.h"
  86. #include "vortex.h"
  87. /*
  88. ** These layer control elements are used to group the displayable objects
  89. ** so that proper overlap can be obtained.
  90. */
  91. LayerClass DisplayClass::Layer[LAYER_COUNT];
  92. /*
  93. ** Fading tables
  94. */
  95. unsigned char DisplayClass::FadingBrighten[256];
  96. unsigned char DisplayClass::FadingShade[256];
  97. unsigned char DisplayClass::FadingWayDark[256];
  98. unsigned char DisplayClass::FadingLight[256];
  99. unsigned char DisplayClass::FadingGreen[256];
  100. unsigned char DisplayClass::FadingYellow[256];
  101. unsigned char DisplayClass::FadingRed[256];
  102. unsigned char DisplayClass::TranslucentTable[(MAGIC_COL_COUNT+1)*256];
  103. unsigned char DisplayClass::WhiteTranslucentTable[(1+1)*256];
  104. unsigned char DisplayClass::MouseTranslucentTable[(4+1)*256];
  105. void const * DisplayClass::TransIconset;
  106. unsigned char DisplayClass::UnitShadow[(USHADOW_COL_COUNT+1)*256];
  107. unsigned char DisplayClass::UnitShadowAir[(USHADOW_COL_COUNT+1)*256];
  108. unsigned char DisplayClass::SpecialGhost[2*256];
  109. void const * DisplayClass::ShadowShapes;
  110. unsigned char DisplayClass::ShadowTrans[(SHADOW_COL_COUNT+1)*256];
  111. /*
  112. ** Bit array of cell redraw flags
  113. */
  114. BooleanVectorClass DisplayClass::CellRedraw;
  115. /*
  116. ** The main button that intercepts user input to the map
  117. */
  118. DisplayClass::TacticalClass DisplayClass::TacButton;
  119. //
  120. // We need a way to bypass visible view checks when we are running in the context of GlyphX without using the
  121. // internal C&C renderer. We shouldn't know or care what the user is actually looking at
  122. // ST - 4/17/2019 9:01AM
  123. //
  124. bool DisplayClass::IgnoreViewConstraints = false;
  125. static int const TEX_X = 0;
  126. static int const TEX_Y = 6;
  127. static int const TEX_W = 14;
  128. //Added for getting the input for special character keys from the client
  129. // - 6/26/2019 JAS
  130. extern bool DLL_Export_Get_Input_Key_State(KeyNumType key);
  131. /***********************************************************************************************
  132. * DisplayClass::DisplayClass -- Default constructor for display class. *
  133. * *
  134. * This constructor for the display class just initializes some of the display settings. *
  135. * Most settings are initialized with the correct values at the time that the Init function *
  136. * is called. There are some cases where default values are wise and this routine fills *
  137. * those particular ones in. *
  138. * *
  139. * INPUT: none *
  140. * *
  141. * OUTPUT: none *
  142. * *
  143. * WARNINGS: none *
  144. * *
  145. * HISTORY: *
  146. * 12/06/1994 JLB : Created. *
  147. *=============================================================================================*/
  148. DisplayClass::DisplayClass(void) :
  149. TacticalCoord(0),
  150. TacLeptonWidth(0),
  151. TacLeptonHeight(0),
  152. ZoneCell(0),
  153. ZoneOffset(0),
  154. CursorSize(0),
  155. ProximityCheck(false),
  156. PendingObjectPtr(0),
  157. PendingObject(0),
  158. PendingHouse(HOUSE_NONE),
  159. TacPixelX(0),
  160. TacPixelY(0),
  161. DesiredTacticalCoord(0),
  162. IsToRedraw(true),
  163. IsRepairMode(false),
  164. IsSellMode(false),
  165. IsTargettingMode(SPC_NONE),
  166. IsRubberBand(false),
  167. IsTentative(false),
  168. IsShadowPresent(false),
  169. BandX(0),
  170. BandY(0),
  171. NewX(0),
  172. NewY(0)
  173. {
  174. ShadowShapes = 0;
  175. TransIconset = 0;
  176. Set_View_Dimensions(0, 8, 320/CELL_PIXEL_W, 200/CELL_PIXEL_H);
  177. }
  178. /***********************************************************************************************
  179. * DisplayClass::One_Time -- Performs any special one time initializations. *
  180. * *
  181. * This routine is called from the game initialization process. It is to perform any one *
  182. * time initializations necessary for the map display system. It allocates the staging *
  183. * buffer needed for the radar map. *
  184. * *
  185. * INPUT: none *
  186. * *
  187. * OUTPUT: none *
  188. * *
  189. * WARNINGS: This routine must be called ONCE and only once. *
  190. * *
  191. * HISTORY: *
  192. * 05/31/1994 JLB : Created. *
  193. * 05/31/1994 JLB : Handles layer system now. *
  194. * 06/02/1994 JLB : Takes care of misc display tables and data allocation. *
  195. *=============================================================================================*/
  196. void DisplayClass::One_Time(void)
  197. {
  198. MapClass::One_Time();
  199. /*
  200. ** Init the CellRedraw bit array. Do not do this in the constructor, since the
  201. ** BooleanVector may not have been constructed yet.
  202. */
  203. CellRedraw.Resize(MAP_CELL_TOTAL);
  204. for (LayerType layer = LAYER_FIRST; layer < LAYER_COUNT; layer++) {
  205. Layer[layer].One_Time();
  206. }
  207. /*
  208. ** Load the generic transparent icon set.
  209. */
  210. TransIconset = MFCD::Retrieve("TRANS.ICN");
  211. #ifndef NDEBUG
  212. RawFileClass file("SHADOW.SHP");
  213. if (file.Is_Available()) {
  214. ShadowShapes = Load_Alloc_Data(file);
  215. } else {
  216. ShadowShapes = MFCD::Retrieve("SHADOW.SHP");
  217. }
  218. #else
  219. ShadowShapes = MFCD::Retrieve("SHADOW.SHP");
  220. #endif
  221. //PG Set_View_Dimensions(0, 8 * RESFACTOR);
  222. Set_View_Dimensions(0, 0);
  223. }
  224. /***********************************************************************************************
  225. * DisplayClass::Init_Clear -- clears the display to a known state *
  226. * *
  227. * INPUT: *
  228. * none. *
  229. * *
  230. * OUTPUT: *
  231. * none. *
  232. * *
  233. * WARNINGS: *
  234. * none. *
  235. * *
  236. * HISTORY: *
  237. * 03/17/1995 BRR : Created. *
  238. *=============================================================================================*/
  239. void DisplayClass::Init_Clear(void)
  240. {
  241. MapClass::Init_Clear();
  242. /*
  243. ** Clear any object being placed
  244. */
  245. PendingObjectPtr = 0;
  246. PendingObject = 0;
  247. PendingHouse = HOUSE_NONE;
  248. CursorSize = 0;
  249. IsTargettingMode = SPC_NONE;
  250. IsRepairMode = false;
  251. IsRubberBand = false;
  252. IsTentative = false;
  253. IsSellMode = false;
  254. /*
  255. ** Empty all the display's layers
  256. */
  257. for (LayerType layer = LAYER_FIRST; layer < LAYER_COUNT; layer++) {
  258. Layer[layer].Init();
  259. }
  260. }
  261. /***********************************************************************************************
  262. * DisplayClass::Init_IO -- clears & re-builds the map's button list *
  263. * *
  264. * INPUT: *
  265. * none. *
  266. * *
  267. * OUTPUT: *
  268. * none. *
  269. * *
  270. * WARNINGS: *
  271. * none. *
  272. * *
  273. * HISTORY: *
  274. * 03/17/1995 BRR : Created. *
  275. *=============================================================================================*/
  276. void DisplayClass::Init_IO(void)
  277. {
  278. MapClass::Init_IO();
  279. /*
  280. ** Re-attach our buttons to the main map button list, only in non-edit mode.
  281. */
  282. if (!Debug_Map) {
  283. TacButton.Zap();
  284. Add_A_Button(TacButton);
  285. }
  286. }
  287. /***********************************************************************************************
  288. * DisplayClass::Init_Theater -- Performs theater-specific initialization (mixfiles, etc) *
  289. * *
  290. * INPUT: *
  291. * theater new theater *
  292. * *
  293. * OUTPUT: *
  294. * none. *
  295. * *
  296. * WARNINGS: *
  297. * none. *
  298. * *
  299. * HISTORY: *
  300. * 03/17/1995 BRR : Created. *
  301. * 05/07/1996 JLB : Added translucent tables. *
  302. *=============================================================================================*/
  303. void DisplayClass::Init_Theater(TheaterType theater)
  304. {
  305. char fullname[16];
  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. {LTGREEN, BLACK,130,0}
  326. };
  327. static TLucentType const WhiteCols[1] = {
  328. {1, WHITE, 80, 0}
  329. };
  330. static TLucentType const ShadowCols[SHADOW_COL_COUNT] = {
  331. {WHITE+1, BLACK,130,0},
  332. {WHITE, BLACK,170,0},
  333. {LTGRAY, BLACK,250,0},
  334. {DKGRAY, BLACK,250,0}
  335. };
  336. static TLucentType const UShadowCols[USHADOW_COL_COUNT] = {
  337. {LTGREEN, BLACK,130,0}
  338. };
  339. static TLucentType const UShadowColsAir[USHADOW_COL_COUNT] = {
  340. {LTGREEN, WHITE,0,0}
  341. };
  342. static TLucentType const UShadowColsSnow[USHADOW_COL_COUNT] = {
  343. {LTGREEN, BLACK,75,0}
  344. };
  345. /*
  346. ** Invoke parent's init routine.
  347. */
  348. MapClass::Init_Theater(theater);
  349. /*
  350. ** Save the new theater value
  351. */
  352. Scen.Theater = theater;
  353. /*
  354. ** Unload old mixfiles, and cache the new ones
  355. */
  356. sprintf(fullname, "%s.MIX", Theaters[theater].Root);
  357. #ifndef WIN32
  358. LastTheater = THEATER_NONE;
  359. #endif
  360. if (Scen.Theater != LastTheater) {
  361. if (TheaterData != NULL) {
  362. delete TheaterData;
  363. }
  364. TheaterData = new MFCD(fullname, &FastKey);
  365. assert(TheaterData != NULL);
  366. bool theaterload = TheaterData->Cache(TheaterBuffer);
  367. assert(theaterload);
  368. // LastTheater = Scen.Theater;
  369. }
  370. /*
  371. ** Load the custom palette associated with this theater.
  372. ** The fading palettes will have to be generated as well.
  373. */
  374. sprintf(fullname, "%s.PAL", Theaters[theater].Root);
  375. PaletteClass const * ptr = (PaletteClass *)MFCD::Retrieve(fullname);
  376. GamePalette = * ptr;
  377. OriginalPalette = GamePalette;
  378. Build_Fading_Table(GamePalette.Get_Data(), FadingGreen, GREEN, 110);
  379. Build_Fading_Table(GamePalette.Get_Data(), FadingYellow, YELLOW, 140);
  380. Build_Fading_Table(GamePalette.Get_Data(), FadingRed, RED, 140);
  381. Build_Translucent_Table(GamePalette, &MouseCols[0], 4, MouseTranslucentTable);
  382. Build_Translucent_Table(GamePalette, &MagicCols[0], MAGIC_COL_COUNT, TranslucentTable);
  383. Build_Translucent_Table(GamePalette, &WhiteCols[0], 1, WhiteTranslucentTable);
  384. Build_Translucent_Table(GamePalette, &ShadowCols[0], SHADOW_COL_COUNT, ShadowTrans);
  385. Conquer_Build_Translucent_Table(GamePalette, &UShadowColsAir[0], USHADOW_COL_COUNT, UnitShadowAir);
  386. memcpy(&UnitShadowAir[256], ColorRemaps[PCOLOR_GOLD].RemapTable, sizeof(ColorRemaps[PCOLOR_GOLD].RemapTable));
  387. if (theater == THEATER_SNOW) {
  388. Conquer_Build_Translucent_Table(GamePalette, &UShadowColsSnow[0], USHADOW_COL_COUNT, UnitShadow);
  389. } else {
  390. Conquer_Build_Translucent_Table(GamePalette, &UShadowCols[0], USHADOW_COL_COUNT, UnitShadow);
  391. }
  392. if (theater == THEATER_SNOW) {
  393. Conquer_Build_Fading_Table(GamePalette, FadingShade, BLACK, 75);
  394. } else {
  395. Conquer_Build_Fading_Table(GamePalette, FadingShade, BLACK, 130);
  396. }
  397. Conquer_Build_Fading_Table(GamePalette, FadingLight, WHITE, 85);
  398. /*
  399. ** Create the shadow color used by aircraft.
  400. */
  401. Conquer_Build_Fading_Table(GamePalette, &SpecialGhost[256], BLACK, 100);
  402. for (int index = 0; index < 256; index++) {
  403. SpecialGhost[index] = 0;
  404. }
  405. Make_Fading_Table(GamePalette, FadingBrighten, WHITE, 25);
  406. Make_Fading_Table(GamePalette, FadingWayDark, DKGRAY, 192);
  407. /*
  408. ** Adjust the palette according to the visual control option settings.
  409. */
  410. Options.Fixup_Palette();
  411. }
  412. /***********************************************************************************************
  413. * DisplayClass::Text_Overlap_List -- Creates cell overlap list for specified text string. *
  414. * *
  415. * This routine is used to create an overlap list that specifies all the cells that are *
  416. * covered by the specified text string. This overlap list is used to handle map refresh *
  417. * logic. *
  418. * *
  419. * INPUT: text -- Pointer to the text that would appear on the map and must have an *
  420. * overlap list generated. *
  421. * *
  422. * x,y -- The coordinates that the text would appear (upper left corner). *
  423. * *
  424. * OUTPUT: Returns with a pointer to an overlap list that covers all cells "under" the text *
  425. * if were displayed at the coordinates specified. The list is actually a series of *
  426. * offsets from the display's upper left corner cell number. *
  427. * *
  428. * WARNINGS: none *
  429. * *
  430. * HISTORY: *
  431. * 12/06/1994 JLB : Created. *
  432. * 12/07/1994 JLB : Sidebar fixup. *
  433. * 08/13/1995 JLB : Optimized for variable sized help text. *
  434. *=============================================================================================*/
  435. short const * DisplayClass::Text_Overlap_List(char const * text, int x, int y) const
  436. {
  437. static short _list[60];
  438. int count = ARRAY_SIZE(_list);
  439. if (text != NULL) {
  440. short * ptr = &_list[0];
  441. int len = String_Pixel_Width(text)+CELL_PIXEL_W;
  442. int right = TacPixelX + Lepton_To_Pixel(TacLeptonWidth);
  443. /*
  444. ** If the help text would spill into the sidebar, then flag this fact, but
  445. ** shorten the apparent length so that the icon list calculation will
  446. ** function correctly.
  447. */
  448. if (x+len >= TacPixelX+Lepton_To_Pixel(TacLeptonWidth)) {
  449. len = right-x;
  450. *ptr++ = REFRESH_SIDEBAR;
  451. count--;
  452. }
  453. /*
  454. ** Build the list of overlap cell offset values according to the text
  455. ** coordinate and the length.
  456. */
  457. if (x <= right) {
  458. CELL ul = Click_Cell_Calc(x, y-1);
  459. CELL lr = Click_Cell_Calc(x+len-1, Bound(y+24, TacPixelY, TacPixelY+Lepton_To_Pixel(TacLeptonHeight) - 1));
  460. if (ul == -1) ul = Click_Cell_Calc(x, y);
  461. if (ul != -1 && lr != -1) {
  462. for (int yy = Cell_Y(ul); yy <= Cell_Y(lr); yy++) {
  463. for (int xx = Cell_X(ul); xx <= Cell_X(lr); xx++) {
  464. *ptr++ = XY_Cell(xx, yy) - Coord_Cell(TacticalCoord);
  465. count--;
  466. if (count < 2) break;
  467. }
  468. if (count < 2) break;
  469. }
  470. }
  471. }
  472. *ptr = REFRESH_EOL;
  473. }
  474. return(_list);
  475. }
  476. /***********************************************************************************************
  477. * DisplayClass::Set_View_Dimensions -- Sets the tactical display screen coordinates. *
  478. * *
  479. * Use this routine to set the tactical map screen coordinates and dimensions. This routine *
  480. * is typically used when the screen size or position changes as a result of the sidebar *
  481. * changing position or appearance. *
  482. * *
  483. * INPUT: x,y -- The X and Y pixel position on the screen for the tactical map upper left *
  484. * corner. *
  485. * *
  486. * width -- The width of the tactical display (in icons). If this parameter is *
  487. * omitted, then the width will be as wide as the screen will allow. *
  488. * *
  489. * height-- The height of the tactical display (in icons). If this parameter is *
  490. * omitted, then the width will be as wide as the screen will allow. *
  491. * *
  492. * OUTPUT: none *
  493. * *
  494. * WARNINGS: none *
  495. * *
  496. * HISTORY: *
  497. * 12/06/1994 JLB : Created. *
  498. * 06/27/1995 JLB : Adjusts tactical map position if necessary. *
  499. *=============================================================================================*/
  500. void DisplayClass::Set_View_Dimensions(int x, int y, int width, int height)
  501. {
  502. if (width == -1) {
  503. TacLeptonWidth = Pixel_To_Lepton(SeenBuff.Get_Width()-x);
  504. } else {
  505. TacLeptonWidth = width * CELL_LEPTON_W;
  506. }
  507. // ST - 3/1/2019 12:05PM
  508. // 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
  509. //
  510. if (height == -1) {
  511. TacLeptonHeight = Pixel_To_Lepton(SeenBuff.Get_Height() - y);
  512. //height = (SeenBuff.Get_Height()-y) / CELL_PIXEL_H;
  513. }
  514. else {
  515. TacLeptonHeight = height * CELL_LEPTON_H;
  516. }
  517. //TacLeptonHeight = height * CELL_LEPTON_H;
  518. /*
  519. ** Adjust the tactical cell if it is now in an invalid position
  520. ** because of the changed dimensions.
  521. */
  522. int xx = 0;// Coord_X(TacticalCoord) - (MapCellX * CELL_LEPTON_W);
  523. int yy = 0;// Coord_Y(TacticalCoord) - (MapCellY * CELL_LEPTON_H);
  524. Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, MapCellWidth * CELL_LEPTON_W, MapCellHeight * CELL_LEPTON_H);
  525. Set_Tactical_Position(XY_Coord(xx + (MapCellX * CELL_LEPTON_W), yy + (MapCellY * CELL_LEPTON_H)));
  526. TacPixelX = x;
  527. TacPixelY = y;
  528. WindowList[WINDOW_TACTICAL][WINDOWX] = x;
  529. WindowList[WINDOW_TACTICAL][WINDOWY] = y;
  530. WindowList[WINDOW_TACTICAL][WINDOWWIDTH] = Lepton_To_Pixel(TacLeptonWidth);
  531. WindowList[WINDOW_TACTICAL][WINDOWHEIGHT] = Lepton_To_Pixel(TacLeptonHeight);
  532. if (Window == WINDOW_TACTICAL) {
  533. Change_Window(0);
  534. Change_Window(Window);
  535. }
  536. IsToRedraw = true;
  537. Flag_To_Redraw(false);
  538. TacButton.X = TacPixelX;
  539. TacButton.Y = TacPixelY;
  540. TacButton.Width = Lepton_To_Pixel(TacLeptonWidth);
  541. TacButton.Height = Lepton_To_Pixel(TacLeptonHeight);
  542. }
  543. /***********************************************************************************************
  544. * DisplayClass::Set_Cursor_Shape -- Changes the shape of the terrain square cursor. *
  545. * *
  546. * This routine is used to set up the terrain cursor according to the size of the object *
  547. * that is to be placed down. The terrain cursor looks like an arbitrary collection of *
  548. * hatched square overlays. Typical use is when placing buildings. *
  549. * *
  550. * INPUT: list -- A pointer to the list that contains offsets to the cells that are to *
  551. * be marked. *
  552. * *
  553. * OUTPUT: none *
  554. * *
  555. * WARNINGS: none *
  556. * *
  557. * HISTORY: *
  558. * 06/03/1994 JLB : Created. *
  559. * 06/26/1995 JLB : Puts placement cursor into static buffer. *
  560. *=============================================================================================*/
  561. void DisplayClass::Set_Cursor_Shape(short const * list)
  562. {
  563. if (CursorSize) {
  564. Cursor_Mark(ZoneCell+ZoneOffset, false);
  565. }
  566. ZoneOffset = 0;
  567. if (list) {
  568. int w,h;
  569. static short _list[50];
  570. memcpy(_list, list, sizeof(_list));
  571. CursorSize = _list;
  572. Get_Occupy_Dimensions (w, h, CursorSize);
  573. ZoneOffset = -(((h/2)*MAP_CELL_W)+(w/2));
  574. Cursor_Mark(ZoneCell+ZoneOffset, true);
  575. } else {
  576. CursorSize = 0;
  577. }
  578. }
  579. /***********************************************************************************************
  580. * DisplayClass::Passes_Proximity_Check -- Determines if building placement is near friendly sq*
  581. * *
  582. * This routine is used by the building placement cursor logic to determine whether the *
  583. * at the current cursor position if the building would be adjacent to another friendly *
  584. * building. In cases where this is not true, then the building cannot be placed at all. *
  585. * This determination is returned by the function. *
  586. * *
  587. * INPUT: object -- The building object that the current placement system is examining. *
  588. * *
  589. * house -- The house to base the proximity check upon. Typically this is the *
  590. * player's house, but in multiplay, the computer needs to check for *
  591. * proximity as well. *
  592. * *
  593. * list -- Pointer to the building's offset list. *
  594. * *
  595. * trycell -- The cell to base the offset list on. *
  596. * *
  597. * OUTPUT: bool; Can the pending building object be placed at the present cursor location *
  598. * checking only for proximity to friendly buildings? If this isn't for a *
  599. * building type object, then this routine always returns true. *
  600. * *
  601. * WARNINGS: none *
  602. * *
  603. * HISTORY: *
  604. * 06/06/1994 JLB : Created. *
  605. * 06/07/1994 JLB : Handles concrete check. *
  606. * 10/11/1994 BWG : Added IsProximate check for ore refineries *
  607. *=============================================================================================*/
  608. bool DisplayClass::Passes_Proximity_Check(ObjectTypeClass const * object, HousesType house, short const * list, CELL trycell) const
  609. {
  610. short const * ptr;
  611. int retval = -1;
  612. bool noradar = false;
  613. //bool nomapped = false; // Not used. ST - 8/6/2019 10:51AM
  614. bool shipyard = false;
  615. if (house == PlayerPtr->Class->House) {
  616. PassedProximity = false;
  617. }
  618. /*
  619. ** In editor mode, the proximity check always passes.
  620. */
  621. if (Debug_Map) {
  622. return(true);
  623. }
  624. if (list == NULL || trycell == 0) {
  625. return(true);
  626. }
  627. if (object == NULL || object->What_Am_I() != RTTI_BUILDINGTYPE) {
  628. return(true);
  629. }
  630. BuildingTypeClass const * building = (BuildingTypeClass const *)object;
  631. /*
  632. ** Scan through all cells that the building foundation would cover. If any adjacent
  633. ** cells to these are of friendly persuasion, then consider the proximity check to
  634. ** have been a success.
  635. */
  636. ptr = list;
  637. // ptr = CursorSize;
  638. CELL cell = trycell;
  639. // CELL cell = ZoneCell;
  640. if (building->Adjacent == 1) {
  641. while (*ptr != REFRESH_EOL && (retval == -1) ) {
  642. cell = trycell + *ptr++;
  643. // cell = ZoneCell + ZoneOffset + *ptr++;
  644. if (!In_Radar(cell)) {
  645. retval = false;
  646. noradar = true;
  647. break;
  648. }
  649. for (FacingType facing = FACING_FIRST; facing < FACING_COUNT; facing++) {
  650. CELL newcell = Adjacent_Cell(cell, facing);
  651. if (!In_Radar(newcell)) continue;
  652. // Code has no effect. ST - 8/6/2019 10:51AM
  653. //if (!(*this)[newcell].IsMapped) {
  654. // nomapped = true;
  655. //}
  656. BuildingClass * base = (*this)[newcell].Cell_Building();
  657. /*
  658. ** The special cell ownership flag allows building adjacent
  659. ** to friendly walls and bibs even though there is no official
  660. ** building located there.
  661. */
  662. //BG: Modified so only walls can be placed next to walls - buildings can't.
  663. //JLB: Except for bibs, in which case buildings can be placed next to these.
  664. if (building->IsWall ||
  665. ((*this)[newcell].Smudge != SMUDGE_NONE && SmudgeTypeClass::As_Reference((*this)[newcell].Smudge).IsBib)) {
  666. if ((*this)[newcell].Owner == house) {
  667. retval = true;
  668. break;
  669. }
  670. }
  671. // we've found a building...
  672. if (base != NULL && base->House->Class->House == house && base->Class->IsBase) {
  673. retval = true;
  674. break;
  675. }
  676. /* BG: modifications to allow buildings one cell away from other buildings.
  677. ** This is done by scanning each cell that fails the check (hence getting
  678. ** to this point) and looking at the n/s/e/w adjacent cells to see if they
  679. ** have buildings in them. If they do, and they match us, then succeed.
  680. */
  681. if (retval != -1) break;
  682. for (FacingType newface = FACING_N; newface < FACING_COUNT; newface++) {
  683. CELL newercell = Adjacent_Cell(newcell, newface);
  684. if (building->IsWall ||
  685. ((*this)[newercell].Smudge != SMUDGE_NONE && SmudgeTypeClass::As_Reference((*this)[newercell].Smudge).IsBib)) {
  686. if ((*this)[newercell].Owner == house) {
  687. retval = true;
  688. break;
  689. }
  690. }
  691. TechnoClass * newbase = (*this)[newercell].Cell_Techno();
  692. // we've found a building...
  693. if (newbase != NULL && newbase->What_Am_I() == RTTI_BUILDING && newbase->House->Class->House == house && ((BuildingClass const *)newbase)->Class->IsBase) {
  694. retval = true;
  695. break;
  696. }
  697. }
  698. if (retval != -1) break;
  699. }
  700. }
  701. }
  702. if (retval == -1) retval = false;
  703. if (house == PlayerPtr->Class->House) {
  704. PassedProximity = (retval != false);
  705. }
  706. /*
  707. ** If this object has special dispensation to be placed further than one cell from
  708. ** other regular buildings, then check for this case now. Only bother to check if
  709. ** it hasn't already been given permission to be placed down.
  710. */
  711. if (!retval && !noradar && object->What_Am_I() == RTTI_BUILDINGTYPE) {
  712. // For land mines, let's make it check proximity within 10 squares
  713. if (building->Adjacent > 1) {
  714. for (int index = 0; index < Buildings.Count(); index++) {
  715. BuildingClass * obj = Buildings.Ptr(index);
  716. if (obj != NULL && !obj->IsInLimbo && obj->House->Class->House == house && obj->Class->IsBase) {
  717. int centdist = ::Distance(obj->Center_Coord(), Cell_Coord(cell));
  718. centdist /= CELL_LEPTON_W;
  719. centdist -= (obj->Class->Width() + obj->Class->Height()) / 2;
  720. if (centdist <= building->Adjacent) {
  721. retval = true;
  722. break;
  723. }
  724. }
  725. }
  726. }
  727. }
  728. return((bool)retval);
  729. }
  730. /***********************************************************************************************
  731. * DisplayClass::Set_Cursor_Pos -- Controls the display and animation of the tac cursor. *
  732. * *
  733. * This routine controls the location, display, and animation of the *
  734. * tactical map cursor. *
  735. * *
  736. * INPUT: pos -- Position to move the cursor do. If -1 is passed then *
  737. * the cursor will just be hidden. If the position *
  738. * passed is the same as the last position passed in, *
  739. * then animation could occur (based on timers). *
  740. * *
  741. * OUTPUT: none *
  742. * *
  743. * WARNINGS: none *
  744. * *
  745. * HISTORY: *
  746. * 05/22/1991 JLB : Created. *
  747. * 06/02/1994 JLB : Converted to member function. *
  748. * 06/08/1994 JLB : If position is -1, then follow mouse. *
  749. * 02/28/1995 JLB : Forces placement cursor to fit on map. *
  750. *=============================================================================================*/
  751. CELL DisplayClass::Set_Cursor_Pos(CELL pos)
  752. {
  753. CELL prevpos; // Last position of cursor (for jump-back reasons).
  754. /*
  755. ** Follow the mouse position if no cell number is provided.
  756. */
  757. if (pos == -1) {
  758. pos = Click_Cell_Calc(Get_Mouse_X(), Get_Mouse_Y());
  759. }
  760. if (CursorSize == NULL) {
  761. prevpos = ZoneCell;
  762. ZoneCell = pos;
  763. return(prevpos);
  764. }
  765. /*
  766. ** Adjusts the position so that the placement cursor is never part way off the
  767. ** tactical map.
  768. */
  769. int w,h;
  770. Get_Occupy_Dimensions(w, h, CursorSize);
  771. int x = Cell_X(pos + ZoneOffset);
  772. int y = Cell_Y(pos + ZoneOffset);
  773. if (x < Coord_XCell(TacticalCoord)) x = Coord_XCell(TacticalCoord);
  774. if (y < Coord_YCell(TacticalCoord)) y = Coord_YCell(TacticalCoord);
  775. if (x+w >= Coord_XCell(TacticalCoord) + Lepton_To_Cell(TacLeptonWidth)) x = Coord_XCell(TacticalCoord)+Lepton_To_Cell(TacLeptonWidth)-w;
  776. if (y+h >= Coord_YCell(TacticalCoord) + Lepton_To_Cell(TacLeptonHeight)) y = Coord_YCell(TacticalCoord)+Lepton_To_Cell(TacLeptonHeight)-h;
  777. pos = XY_Cell(x, y) - ZoneOffset;
  778. /*
  779. ** This checks to see if NO animation or drawing is to occur and, if so,
  780. ** exits.
  781. */
  782. if (pos == ZoneCell) return(pos);
  783. prevpos = ZoneCell;
  784. /*
  785. ** If the cursor is visible, then handle the graphic update.
  786. ** Otherwise, just update the global position of the cursor.
  787. */
  788. if (CursorSize != NULL) {
  789. /*
  790. ** Erase the old cursor (if it exists) AND the cursor is moving.
  791. */
  792. if (pos != ZoneCell && ZoneCell != -1) {
  793. Cursor_Mark(ZoneCell+ZoneOffset, false);
  794. }
  795. /*
  796. ** Render the cursor (could just be animation).
  797. */
  798. if (pos != -1) {
  799. Cursor_Mark(pos+ZoneOffset, true);
  800. }
  801. }
  802. ZoneCell = pos;
  803. ProximityCheck = Passes_Proximity_Check(PendingObject, PendingHouse, CursorSize, ZoneCell+ZoneOffset);
  804. return(prevpos);
  805. }
  806. /***********************************************************************************************
  807. * DisplayClass::Get_Occupy_Dimensions -- computes width & height of the given occupy list *
  808. * *
  809. * INPUT: *
  810. * w ptr to fill in with height *
  811. * h ptr to fill in with width *
  812. * *
  813. * OUTPUT: *
  814. * none. *
  815. * *
  816. * WARNINGS: *
  817. * none. *
  818. * *
  819. * HISTORY: *
  820. * 03/31/1995 BRR : Created. *
  821. *=============================================================================================*/
  822. void DisplayClass::Get_Occupy_Dimensions(int & w, int & h, short const * list) const
  823. {
  824. int min_x = MAP_CELL_W;
  825. int max_x = -MAP_CELL_W;
  826. int min_y = MAP_CELL_H;
  827. int max_y = -MAP_CELL_H;
  828. int x,y;
  829. w = 0;
  830. h = 0;
  831. if (!list) {
  832. /*
  833. ** Loop through all cell offsets, accumulating max & min x- & y-coords
  834. */
  835. while (*list != REFRESH_EOL) {
  836. /*
  837. ** Compute x & y coords of the current cell offset. We can't use Cell_X()
  838. ** & Cell_Y(), because they use shifts to compute the values, and if the
  839. ** offset is negative we'll get a bogus coordinate!
  840. */
  841. x = (*list) % MAP_CELL_W;
  842. y = (*list) / MAP_CELL_H;
  843. max_x = max(max_x, x);
  844. min_x = min(min_x, x);
  845. max_y = max(max_y, y);
  846. min_y = min(min_y, y);
  847. list++;
  848. }
  849. w = max(1, max_x - min_x + 1);
  850. h = min(1, max_y - min_y + 1);
  851. }
  852. }
  853. /***********************************************************************************************
  854. * DisplayClass::Cursor_Mark -- Set or resets the cursor display flag bits. *
  855. * *
  856. * This routine will clear or set the cursor display bits on the map. *
  857. * If the bit is set, then the cursor will be rendered on that map *
  858. * icon. *
  859. * *
  860. * INPUT: pos -- Position of the upper left corner of the cursor. *
  861. * *
  862. * on -- Should the bit be turned on? *
  863. * *
  864. * OUTPUT: none *
  865. * *
  866. * WARNINGS: Be sure that every call to set the bits is matched by a *
  867. * corresponding call to clear the bits. *
  868. * *
  869. * HISTORY: *
  870. * 09/04/1991 JLB : Created. *
  871. * 06/02/1994 JLB : Converted to member function. *
  872. *=============================================================================================*/
  873. void DisplayClass::Cursor_Mark(CELL pos, bool on)
  874. {
  875. CELL const * ptr;
  876. CellClass * cellptr;
  877. if ((unsigned)pos >= MAP_CELL_TOTAL) return;
  878. /*
  879. ** For every cell in the CursorSize list, invoke its Redraw_Objects and
  880. ** toggle its IsCursorHere flag
  881. */
  882. ptr = CursorSize;
  883. while (*ptr != REFRESH_EOL) {
  884. CELL cell = pos + *ptr++;
  885. if (In_Radar(cell)) {
  886. cellptr = &(*this)[cell];
  887. cellptr->Redraw_Objects();
  888. if (on) {
  889. cellptr->IsCursorHere = true;
  890. } else {
  891. cellptr->IsCursorHere = false;
  892. }
  893. }
  894. }
  895. /*
  896. ** For every cell in the PendingObjectPtr's Overlap_List, invoke its
  897. ** Redraw_Objects routine.
  898. */
  899. if (PendingObjectPtr && PendingObjectPtr->IsActive) {
  900. ptr = PendingObjectPtr->Overlap_List();
  901. while (*ptr != REFRESH_EOL) {
  902. CELL cell = pos + *ptr++;
  903. if (In_Radar(cell)) {
  904. cellptr = &(*this)[cell];
  905. cellptr->Redraw_Objects();
  906. }
  907. }
  908. }
  909. }
  910. /***********************************************************************************************
  911. * DisplayClass::AI -- Handles the maintenance tasks for the map display. *
  912. * *
  913. * This routine is called once per game display frame (15 times per second). It handles *
  914. * the mouse shape tracking and map scrolling as necessary. *
  915. * *
  916. * INPUT: input -- The next key just fetched from the input queue. *
  917. * *
  918. * x,y -- Mouse coordinates. *
  919. * *
  920. * OUTPUT: Modifies the input code if necessary. When the input code is consumed, it gets *
  921. * set to 0. *
  922. * *
  923. * WARNINGS: none *
  924. * *
  925. * HISTORY: *
  926. * 06/01/1994 JLB : Created. *
  927. * 06/02/1994 JLB : Filters mouse click input. *
  928. * 06/07/1994 JLB : Fixed so template click will behave right. *
  929. * 10/14/1994 JLB : Changing cursor shape over target. *
  930. * 12/31/1994 JLB : Takes mouse coordinates as parameters. *
  931. * 06/27/1995 JLB : Breaks out of rubber band mode if mouse leaves map. *
  932. *=============================================================================================*/
  933. void DisplayClass::AI(KeyNumType & input, int x, int y)
  934. {
  935. if (
  936. IsRubberBand &&
  937. (Get_Mouse_X() < TacPixelX ||
  938. Get_Mouse_Y() < TacPixelY ||
  939. Get_Mouse_X() >= (TacPixelX + Lepton_To_Pixel(TacLeptonWidth)) ||
  940. Get_Mouse_Y() >= (TacPixelY + Lepton_To_Pixel(TacLeptonHeight)))) {
  941. Mouse_Left_Release(-1, Get_Mouse_X(), Get_Mouse_Y(), NULL, ACTION_NONE);
  942. }
  943. MapClass::AI(input, x, y);
  944. }
  945. /***********************************************************************************************
  946. * DisplayClass::Submit -- Adds a game object to the map rendering system. *
  947. * *
  948. * This routine is used to add an arbitrary (but tangible) game object to the map. It will *
  949. * be rendered (made visible) once it is submitted to this function. This function builds *
  950. * the list of game objects that get rendered each frame as necessary. It is possible to *
  951. * submit the game object to different rendering layers. All objects in a layer get drawn *
  952. * at the same time. Using this layer method it becomes possible to have objects "below" *
  953. * other objects. *
  954. * *
  955. * INPUT: object -- Pointer to the object to add. *
  956. * *
  957. * layer -- The layer to add the object to. *
  958. * *
  959. * OUTPUT: none *
  960. * *
  961. * WARNINGS: none *
  962. * *
  963. * HISTORY: *
  964. * 05/31/1994 JLB : Created. *
  965. * 05/31/1994 JLB : Improved layer system. *
  966. * 05/31/1994 JLB : Sorts object position if this is for the ground layer. *
  967. *=============================================================================================*/
  968. void DisplayClass::Submit(ObjectClass const * object, LayerType layer)
  969. {
  970. if (object) {
  971. Layer[layer].Submit(object, (layer == LAYER_GROUND));
  972. }
  973. }
  974. /***********************************************************************************************
  975. * DisplayClass::Remove -- Removes a game object from the rendering system. *
  976. * *
  977. * Every object that is to disappear from the map must be removed from the rendering *
  978. * system. *
  979. * *
  980. * INPUT: object -- The object to remove. *
  981. * *
  982. * layer -- The layer to remove it from. *
  983. * *
  984. * OUTPUT: none *
  985. * *
  986. * WARNINGS: none *
  987. * *
  988. * HISTORY: *
  989. * 05/31/1994 JLB : Created. *
  990. * 05/31/1994 JLB : Improved layer system. *
  991. *=============================================================================================*/
  992. void DisplayClass::Remove(ObjectClass const * object, LayerType layer)
  993. {
  994. assert(object != 0);
  995. assert(object->IsActive);
  996. if (object) {
  997. Layer[layer].Delete((ObjectClass *)object);
  998. }
  999. }
  1000. /***********************************************************************************************
  1001. * DisplayClass::Click_Cell_Calc -- Determines cell from screen X & Y. *
  1002. * *
  1003. * This routine is used to determine the cell that is located at the *
  1004. * screen pixel coordinates given. Typical use is when the player *
  1005. * clicks with the mouse on the tactical map. *
  1006. * *
  1007. * INPUT: x,y -- Screen pixel coordinates. *
  1008. * *
  1009. * OUTPUT: Returns with cell that is under the coordinates specified. *
  1010. * If the coordinate specified is outside of the tactical *
  1011. * map, then -1 is returned. *
  1012. * *
  1013. * WARNINGS: none *
  1014. * *
  1015. * HISTORY: *
  1016. * 05/27/1994 JLB : Created. *
  1017. *=============================================================================================*/
  1018. CELL DisplayClass::Click_Cell_Calc(int x, int y) const
  1019. {
  1020. x -= TacPixelX;
  1021. x = Pixel_To_Lepton(x);
  1022. y -= TacPixelY;
  1023. y = Pixel_To_Lepton(y);
  1024. // Possibly ignore the view constraints if we aren't using the internal renderer. ST - 8/5/2019 11:56AM
  1025. if (IgnoreViewConstraints || (unsigned)x < TacLeptonWidth && (unsigned)y < TacLeptonHeight) {
  1026. COORDINATE tcoord = XY_Coord(Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(TacticalCoord))), Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(TacticalCoord))));
  1027. return(Coord_Cell(Coord_Add(tcoord, XY_Coord(x, y))));
  1028. }
  1029. return(-1);
  1030. }
  1031. /***********************************************************************************************
  1032. * DisplayClass::Scroll_Map -- Scroll the tactical map in desired direction. *
  1033. * *
  1034. * This routine is used to scroll the tactical map view in the desired *
  1035. * direction. It can also be used to determine if scrolling would be *
  1036. * legal without actually performing any scrolling action. *
  1037. * *
  1038. * INPUT: facing -- The direction to scroll the tactical map. *
  1039. * *
  1040. * distance -- The distance in leptons to scroll the map. *
  1041. * *
  1042. * really -- Should the map actually be scrolled? If false, *
  1043. * then only the legality of a scroll is checked. *
  1044. * *
  1045. * OUTPUT: bool; Would scrolling in the desired direction be possible? *
  1046. * *
  1047. * WARNINGS: none *
  1048. * *
  1049. * HISTORY: *
  1050. * 10/07/1992 JLB : Created. *
  1051. * 05/20/1994 JLB : Converted to member function. *
  1052. * 08/09/1995 JLB : Added distance parameter. *
  1053. * 08/10/1995 JLB : Any direction scrolling. *
  1054. *=============================================================================================*/
  1055. bool DisplayClass::Scroll_Map(DirType facing, int & distance, bool really)
  1056. {
  1057. /*
  1058. ** If the distance is invalid then no further checking is required. Bail
  1059. ** with a no-can-do flag.
  1060. */
  1061. if (distance == 0) return(false);
  1062. FacingType crude = Dir_Facing(facing);
  1063. if (Coord_X(TacticalCoord) == Cell_To_Lepton(MapCellX) && crude != FACING_W) {
  1064. if (crude == FACING_SW) facing = DIR_S;
  1065. if (crude == FACING_NW) facing = DIR_N;
  1066. }
  1067. if (Coord_Y(TacticalCoord) == Cell_To_Lepton(MapCellY) && crude != FACING_N) {
  1068. if (crude == FACING_NW) facing = DIR_W;
  1069. if (crude == FACING_NE) facing = DIR_E;
  1070. }
  1071. if (Coord_X(TacticalCoord) + TacLeptonWidth == Cell_To_Lepton(MapCellX+MapCellWidth) && crude != FACING_E) {
  1072. if (crude == FACING_NE) facing = DIR_N;
  1073. if (crude == FACING_SE) facing = DIR_S;
  1074. }
  1075. if (Coord_Y(TacticalCoord) + TacLeptonHeight == Cell_To_Lepton(MapCellY+MapCellHeight) && crude != FACING_S) {
  1076. if (crude == FACING_SE) facing = DIR_E;
  1077. if (crude == FACING_SW) facing = DIR_W;
  1078. }
  1079. /*
  1080. ** Determine the coordinate that it wants to scroll to.
  1081. */
  1082. COORDINATE coord = Coord_Move(TacticalCoord, facing, distance);
  1083. /*
  1084. ** Clip the new coordinate to the edges of the game world.
  1085. */
  1086. int xx = (int)(short)Coord_X(coord) - (short)Cell_To_Lepton(MapCellX);
  1087. int yy = (int)(short)Coord_Y(coord) - (short)Cell_To_Lepton(MapCellY);
  1088. bool shifted = Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, Cell_To_Lepton(MapCellWidth), Cell_To_Lepton(MapCellHeight));
  1089. if (xx < 0) {
  1090. xx = 0;
  1091. shifted = true;
  1092. }
  1093. if (yy < 0) {
  1094. yy = 0;
  1095. shifted = true;
  1096. }
  1097. coord = XY_Coord(xx + Cell_To_Lepton(MapCellX), yy + Cell_To_Lepton(MapCellY));
  1098. /*
  1099. ** If the desired scroll was bound by the edge of the map, then adjust the distance to more accurately
  1100. ** reflect the actual distance moved.
  1101. */
  1102. if (shifted) {
  1103. distance = Distance(TacticalCoord, coord);
  1104. }
  1105. /*
  1106. ** If the new coordinate is the same as the old, then no scrolling would occur.
  1107. */
  1108. if (!distance || coord == TacticalCoord) return(false);
  1109. /*
  1110. ** Since the new coordinate is different than the old one, possibly adjust the real
  1111. ** tactical map accordingly.
  1112. */
  1113. if (really) {
  1114. Set_Tactical_Position(coord);
  1115. IsToRedraw = true;
  1116. Flag_To_Redraw(false);
  1117. /*
  1118. ** Scrolled map REQUIRES all top layer units to be redrawn.
  1119. */
  1120. int index;
  1121. for (index = 0; index < Layer[LAYER_TOP].Count(); index++) {
  1122. Layer[LAYER_TOP][index]->Mark(MARK_CHANGE);
  1123. }
  1124. for (index = 0; index < Layer[LAYER_AIR].Count(); index++) {
  1125. Layer[LAYER_AIR][index]->Mark(MARK_CHANGE);
  1126. }
  1127. }
  1128. return(true);
  1129. }
  1130. /***********************************************************************************************
  1131. * DisplayClass::Refresh_Cells -- Redraws all cells in list. *
  1132. * *
  1133. * This routine is used to flag all cells in the specified list for *
  1134. * redrawing. *
  1135. * *
  1136. * INPUT: cell -- The origin cell that the list is offset from. *
  1137. * *
  1138. * list -- Pointer to a list of offsets from the origin cell. *
  1139. * Each cell so specified is flagged for redraw. *
  1140. * *
  1141. * OUTPUT: none *
  1142. * *
  1143. * WARNINGS: This routine is rather slow (by definition). *
  1144. * *
  1145. * HISTORY: *
  1146. * 05/14/1994 JLB : Created. *
  1147. * 08/01/1994 JLB : Simplified. *
  1148. *=============================================================================================*/
  1149. void DisplayClass::Refresh_Cells(CELL cell, short const * list)
  1150. {
  1151. short tlist[36];
  1152. if (*list == REFRESH_SIDEBAR) {
  1153. list++;
  1154. }
  1155. List_Copy(list, ARRAY_SIZE(tlist), tlist);
  1156. short * tt = tlist;
  1157. int count = 0;
  1158. while (*tt != REFRESH_EOL) {
  1159. if (count >= ARRAY_SIZE(tlist)) { // Added overrun check. ST - 8/14/2019 3:14PM
  1160. break;
  1161. }
  1162. CELL newcell = cell + *tt++;
  1163. if (In_Radar(newcell)) {
  1164. (*this)[newcell].Redraw_Objects();
  1165. }
  1166. count++;
  1167. }
  1168. }
  1169. /***********************************************************************************************
  1170. * DisplayClass::Cell_Shadow -- Determine what shadow icon to use for the cell. *
  1171. * *
  1172. * This routine will examine the specified cell and adjacent cells to *
  1173. * determine what shadow icon to use. *
  1174. * *
  1175. * INPUT: cell -- The cell to examine. *
  1176. * *
  1177. * OUTPUT: Returns with the shadow icon to use. -2= all black. *
  1178. * -1= map cell. *
  1179. * *
  1180. * WARNINGS: none *
  1181. * *
  1182. * HISTORY: *
  1183. * 03/01/1994 JLB : Created. *
  1184. * 04/04/1994 JLB : Revamped for new shadow icon method. *
  1185. * 04/30/1994 JLB : Converted to member function. *
  1186. * 08/05/2019 ST : Added house parameter so we can do this per player **
  1187. *=============================================================================================*/
  1188. int DisplayClass::Cell_Shadow(CELL cell, HouseClass *house) const
  1189. {
  1190. static char const _shadow[256]={
  1191. -1,33, 2, 2,34,37, 2, 2,
  1192. 4,26, 6, 6, 4,26, 6, 6,
  1193. 35,45,17,17,38,41,17,17,
  1194. 4,26, 6, 6, 4,26, 6, 6,
  1195. 8,21,10,10,27,31,10,10,
  1196. 12,23,14,14,12,23,14,14,
  1197. 8,21,10,10,27,31,10,10,
  1198. 12,23,14,14,12,23,14,14,
  1199. 32,36,25,25,44,40,25,25,
  1200. 19,30,20,20,19,30,20,20,
  1201. 39,43,29,29,42,46,29,29,
  1202. 19,30,20,20,19,30,20,20,
  1203. 8,21,10,10,27,31,10,10,
  1204. 12,23,14,14,12,23,14,14,
  1205. 8,21,10,10,27,31,10,10,
  1206. 12,23,14,14,12,23,14,14,
  1207. 1, 1, 3, 3,16,16, 3, 3,
  1208. 5, 5, 7, 7, 5, 5, 7, 7,
  1209. 24,24,18,18,28,28,18,18,
  1210. 5, 5, 7, 7, 5, 5, 7, 7,
  1211. 9, 9,11,11,22,22,11,11,
  1212. 13,13,-2,-2,13,13,-2,-2,
  1213. 9, 9,11,11,22,22,11,11,
  1214. 13,13,-2,-2,13,13,-2,-2,
  1215. 1, 1, 3, 3,16,16, 3, 3,
  1216. 5, 5, 7, 7, 5, 5, 7, 7,
  1217. 24,24,18,18,28,28,18,18,
  1218. 5, 5, 7, 7, 5, 5, 7, 7,
  1219. 9, 9,11,11,22,22,11,11,
  1220. 13,13,-2,-2,13,13,-2,-2,
  1221. 9, 9,11,11,22,22,11,11,
  1222. 13,13,-2,-2,13,13,-2,-2
  1223. };
  1224. int index = 0, value = -1;
  1225. /*
  1226. ** Don't map cells that are at the edges. This solves
  1227. ** problem of accessing cells off the bounds of map and into
  1228. ** who-knows-what memory.
  1229. */
  1230. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1231. if ((unsigned)(Cell_X(cell)-1) >= MAP_CELL_W-2) return(-1);
  1232. if ((unsigned)(Cell_Y(cell)-1) >= MAP_CELL_H-2) return(-1);
  1233. #else
  1234. if ((unsigned)(Cell_Y(cell)-1) > MAP_CELL_H-2) return(-1);
  1235. #endif
  1236. //if ((unsigned)(Cell_Y(cell)-1) > MAP_CELL_H-2) return(-2);
  1237. CellClass const * cellptr = &(*this)[cell];
  1238. /*
  1239. ** Presume solid black if that is what is here already.
  1240. */
  1241. if (!cellptr->Is_Visible(house) && !cellptr->Is_Mapped(house)) value = -2;
  1242. if (cellptr->Is_Mapped(house) /*&& !cellptr->IsVisible*/) {
  1243. /*
  1244. ** Build an index into the lookup table using all 8 surrounding cells.
  1245. ** We're mapping a revealed cell and we only care about the existence
  1246. ** of black cells. Bit numbering starts at the upper-right corner and
  1247. ** goes around the cell clockwise, so 0x80 = directly north.
  1248. */
  1249. cell -= MAP_CELL_W + 1; cellptr -= MAP_CELL_W + 1;
  1250. if (!cellptr->Is_Mapped(house) && In_Radar(cell)) index |= 0x40;
  1251. cell++; cellptr++;
  1252. if (!cellptr->Is_Mapped(house) && In_Radar(cell)) index |= 0x80;
  1253. cell++; cellptr++;
  1254. if (!cellptr->Is_Mapped(house) && In_Radar(cell)) index |= 0x01;
  1255. cell += MAP_CELL_W - 2; cellptr += MAP_CELL_W - 2;
  1256. if (!cellptr->Is_Mapped(house) && In_Radar(cell)) index |= 0x20;
  1257. cell += 2; cellptr += 2;
  1258. if (!cellptr->Is_Mapped(house) && In_Radar(cell)) index |= 0x02;
  1259. cell += MAP_CELL_W - 2; cellptr += MAP_CELL_W - 2;
  1260. if (!cellptr->Is_Mapped(house) && In_Radar(cell)) index |= 0x10;
  1261. cell++; cellptr++;
  1262. if (!cellptr->Is_Mapped(house) && In_Radar(cell)) index |= 0x08;
  1263. cell++; cellptr++;
  1264. if (!cellptr->Is_Mapped(house) && In_Radar(cell)) index |= 0x04;
  1265. value = _shadow[index];
  1266. }
  1267. return(value);
  1268. }
  1269. #if (0) // Old code for reference. ST - 8/15/2019 10:25AM
  1270. /***********************************************************************************************
  1271. * DisplayClass::Cell_Shadow -- Determine what shadow icon to use for the cell. *
  1272. * *
  1273. * This routine will examine the specified cell and adjacent cells to *
  1274. * determine what shadow icon to use. *
  1275. * *
  1276. * INPUT: cell -- The cell to examine. *
  1277. * *
  1278. * OUTPUT: Returns with the shadow icon to use. -2= all black. *
  1279. * -1= map cell. *
  1280. * *
  1281. * WARNINGS: none *
  1282. * *
  1283. * HISTORY: *
  1284. * 03/01/1994 JLB : Created. *
  1285. * 04/04/1994 JLB : Revamped for new shadow icon method. *
  1286. * 04/30/1994 JLB : Converted to member function. *
  1287. *=============================================================================================*/
  1288. int DisplayClass::Cell_Shadow(CELL cell) const
  1289. {
  1290. static char const _shadow[256]={
  1291. -1,33, 2, 2,34,37, 2, 2,
  1292. 4,26, 6, 6, 4,26, 6, 6,
  1293. 35,45,17,17,38,41,17,17,
  1294. 4,26, 6, 6, 4,26, 6, 6,
  1295. 8,21,10,10,27,31,10,10,
  1296. 12,23,14,14,12,23,14,14,
  1297. 8,21,10,10,27,31,10,10,
  1298. 12,23,14,14,12,23,14,14,
  1299. 32,36,25,25,44,40,25,25,
  1300. 19,30,20,20,19,30,20,20,
  1301. 39,43,29,29,42,46,29,29,
  1302. 19,30,20,20,19,30,20,20,
  1303. 8,21,10,10,27,31,10,10,
  1304. 12,23,14,14,12,23,14,14,
  1305. 8,21,10,10,27,31,10,10,
  1306. 12,23,14,14,12,23,14,14,
  1307. 1, 1, 3, 3,16,16, 3, 3,
  1308. 5, 5, 7, 7, 5, 5, 7, 7,
  1309. 24,24,18,18,28,28,18,18,
  1310. 5, 5, 7, 7, 5, 5, 7, 7,
  1311. 9, 9,11,11,22,22,11,11,
  1312. 13,13,-2,-2,13,13,-2,-2,
  1313. 9, 9,11,11,22,22,11,11,
  1314. 13,13,-2,-2,13,13,-2,-2,
  1315. 1, 1, 3, 3,16,16, 3, 3,
  1316. 5, 5, 7, 7, 5, 5, 7, 7,
  1317. 24,24,18,18,28,28,18,18,
  1318. 5, 5, 7, 7, 5, 5, 7, 7,
  1319. 9, 9,11,11,22,22,11,11,
  1320. 13,13,-2,-2,13,13,-2,-2,
  1321. 9, 9,11,11,22,22,11,11,
  1322. 13,13,-2,-2,13,13,-2,-2
  1323. };
  1324. int index = 0, value = -1;
  1325. /*
  1326. ** Don't map cells that are at the top or bottom edge. This solves
  1327. ** problem of accessing cells off the top or bottom of the map and into
  1328. ** who-knows-what memory.
  1329. */
  1330. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1331. if ((unsigned)(Cell_Y(cell)-1) >= MAP_CELL_H-2) return(-1);
  1332. #else
  1333. if ((unsigned)(Cell_Y(cell)-1) > MAP_CELL_H-2) return(-1);
  1334. #endif
  1335. //if ((unsigned)(Cell_Y(cell)-1) > MAP_CELL_H-2) return(-2);
  1336. CellClass const * cellptr = &(*this)[cell];
  1337. /*
  1338. ** Presume solid black if that is what is here already.
  1339. */
  1340. if (!cellptr->IsVisible && !cellptr->IsMapped) value = -2;
  1341. if (cellptr->IsMapped /*&& !cellptr->IsVisible*/) {
  1342. /*
  1343. ** Build an index into the lookup table using all 8 surrounding cells.
  1344. ** We're mapping a revealed cell and we only care about the existence
  1345. ** of black cells. Bit numbering starts at the upper-right corner and
  1346. ** goes around the cell clockwise, so 0x80 = directly north.
  1347. */
  1348. cellptr-= MAP_CELL_W + 1;
  1349. if (!cellptr->IsMapped) index |= 0x40;
  1350. cellptr++;
  1351. if (!cellptr->IsMapped) index |= 0x80;
  1352. cellptr++;
  1353. if (!cellptr->IsMapped) index |= 0x01;
  1354. cellptr += MAP_CELL_W - 2;
  1355. if (!cellptr->IsMapped) index |= 0x20;
  1356. cellptr += 2;
  1357. if (!cellptr->IsMapped) index |= 0x02;
  1358. cellptr += MAP_CELL_W - 2;
  1359. if (!cellptr->IsMapped) index |= 0x10;
  1360. cellptr++;
  1361. if (!cellptr->IsMapped) index |= 0x08;
  1362. cellptr++;
  1363. if (!cellptr->IsMapped) index |= 0x04;
  1364. value = _shadow[index];
  1365. }
  1366. return(value);
  1367. }
  1368. #endif
  1369. /***********************************************************************************************
  1370. * DisplayClass::Map_Cell -- Mark specified cell as having been mapped. *
  1371. * *
  1372. * This routine maps the specified cell. The cell must not already *
  1373. * have been mapped and the mapping player must be the human. *
  1374. * This routine will update any adjacent cell map icon as appropriate. *
  1375. * *
  1376. * INPUT: cell -- The cell to be mapped. *
  1377. * *
  1378. * house -- The player that is doing the mapping. *
  1379. * *
  1380. * OUTPUT: bool; Was action taken to map this cell? *
  1381. * *
  1382. * WARNINGS: none. *
  1383. * *
  1384. * HISTORY: *
  1385. * 08/05/1992 JLB : Created. *
  1386. * 04/30/1994 JLB : Converted to member function. *
  1387. * 05/24/1994 JLB : Takes pointer to HouseClass. *
  1388. * 02/20/1996 JLB : Allied units reveal the map for the player. *
  1389. * 08/05/2019 ST : Use per-player mapping so we can track the shroud for all players *
  1390. *=============================================================================================*/
  1391. bool DisplayClass::Map_Cell(CELL cell, HouseClass * house, bool check_radar_spied, bool and_for_allies)
  1392. {
  1393. // OK for house not to be PlayerPtr. ST - 8/6/2019 10:05AM
  1394. //if (house != PlayerPtr || !In_Radar(cell)) return(false);
  1395. if (house == NULL || !In_Radar(cell)) return(false);
  1396. if (!house->IsHuman) {
  1397. if (!ShareAllyVisibility || !and_for_allies && !check_radar_spied) {
  1398. return false;
  1399. }
  1400. }
  1401. /*
  1402. ** First check for the condition where we're spying on a house's radar
  1403. ** facility, to see if his mapping is applicable to us.
  1404. */
  1405. if (Session.Type != GAME_GLYPHX_MULTIPLAYER) {
  1406. // Original code. ST - 8/15/2019 10:26AM
  1407. if (house && house != PlayerPtr) {
  1408. if (house->RadarSpied & (1<<(PlayerPtr->Class->House))) house = PlayerPtr;
  1409. if (Session.Type == GAME_NORMAL && house->Is_Ally(PlayerPtr)) house = PlayerPtr;
  1410. }
  1411. } else {
  1412. // Version to work with any human player, not just PlayerPtr
  1413. if (house && check_radar_spied) {
  1414. for (int i=0 ; i<Session.Players.Count() ; i++) {
  1415. HouseClass *player_ptr = HouseClass::As_Pointer(Session.Players[i]->Player.ID);
  1416. if (player_ptr->IsHuman) {
  1417. if (house->RadarSpied & (1<<(player_ptr->Class->House))) {
  1418. Map_Cell(cell, player_ptr, false, false);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. }
  1424. /*
  1425. ** Maybe also recurse to map for allies
  1426. */
  1427. if (ShareAllyVisibility && and_for_allies && Session.Type == GAME_GLYPHX_MULTIPLAYER) {
  1428. for (int i=0 ; i<Session.Players.Count() ; i++) {
  1429. HouseClass *player_ptr = HouseClass::As_Pointer(Session.Players[i]->Player.ID);
  1430. if (player_ptr && player_ptr->IsActive && player_ptr->IsHuman) {
  1431. if (player_ptr != house && house->Is_Ally(player_ptr)) {
  1432. Map_Cell(cell, player_ptr, check_radar_spied, false);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. CellClass * cellptr = &(*this)[cell];
  1438. /*
  1439. ** Don't bother remapping this cell if it is already mapped.
  1440. */
  1441. #if (1)
  1442. if (cellptr->Is_Mapped(house)) {
  1443. if (!cellptr->Is_Visible(house)) {
  1444. cellptr->Redraw_Objects();
  1445. }
  1446. return(false);
  1447. }
  1448. #else
  1449. if (cellptr->IsMapped) {
  1450. if (!cellptr->IsVisible) {
  1451. cellptr->Redraw_Objects();
  1452. }
  1453. return(false);
  1454. }
  1455. #endif
  1456. /*
  1457. ** Mark the cell as being mapped. This must be done first because
  1458. ** if the IsVisible flag must be set, then it might affect the
  1459. ** adjacent cell processing.
  1460. */
  1461. // Set per player. ST - 8/6/2019 10:18AM
  1462. cellptr->Set_Mapped(house);
  1463. cellptr->Redraw_Objects();
  1464. if (Cell_Shadow(cell, house) == -1) {
  1465. cellptr->Set_Visible(house);
  1466. }
  1467. /*
  1468. ** Check out all adjacent cells to see if they need
  1469. ** to be mapped as well. This is necessary because of the
  1470. ** "unique" method of showing shadowed cells. Many combinations
  1471. ** are not allowed, and to fix this, just map the cells until
  1472. ** all is ok.
  1473. */
  1474. int xx = Cell_X(cell);
  1475. for (FacingType dir = FACING_FIRST; dir < FACING_COUNT; dir++) {
  1476. int shadow;
  1477. CELL c;
  1478. int xdiff;
  1479. c = Adjacent_Cell(cell, dir);
  1480. /*
  1481. ** Determine if the map edge has been wrapped. If so,
  1482. ** then don't process the cell.
  1483. */
  1484. if ((unsigned)c >= MAP_CELL_TOTAL) continue;
  1485. xdiff = Cell_X(c) - xx;
  1486. xdiff = ABS(xdiff);
  1487. if (xdiff > 1) continue;
  1488. CellClass * cptr = &(*this)[c];
  1489. cptr->Redraw_Objects();
  1490. #if (1)
  1491. // New client/server friendly code
  1492. if (c != cell && !cptr->Is_Visible(house)) {
  1493. shadow = Cell_Shadow(c, house);
  1494. if (shadow == -1) {
  1495. if (!cptr->Is_Mapped(house)) {
  1496. Map_Cell(c, house, check_radar_spied, false);
  1497. } else {
  1498. cptr->Set_Visible(house);
  1499. }
  1500. } else {
  1501. if (shadow != -2 && !cptr->Is_Mapped(house)) {
  1502. Map_Cell(c, house, check_radar_spied, false);
  1503. }
  1504. }
  1505. }
  1506. #else
  1507. // Old peer/peer code
  1508. if (c != cell && !cptr->IsVisible) {
  1509. shadow = Cell_Shadow(c);
  1510. if (shadow == -1) {
  1511. if (!cptr->IsMapped) {
  1512. Map_Cell(c, house);
  1513. } else {
  1514. cptr->IsVisible = true;
  1515. }
  1516. } else {
  1517. if (shadow != -2 && !cptr->IsMapped) {
  1518. Map_Cell(c, house);
  1519. }
  1520. }
  1521. }
  1522. #endif
  1523. }
  1524. TechnoClass * tech = (*this)[cell].Cell_Techno();
  1525. if (tech) {
  1526. tech->Revealed(house);
  1527. }
  1528. return(true);
  1529. }
  1530. /***********************************************************************************************
  1531. * DisplayClass::Coord_To_Pixel -- Determines X and Y pixel coordinates. *
  1532. * *
  1533. * This is the routine that figures out the location on the screen for *
  1534. * a specified coordinate. It is one of the fundamental routines *
  1535. * necessary for rendering the game objects. It performs some quick *
  1536. * tests to see if the coordinate is in a visible region and returns *
  1537. * this check as a boolean value. *
  1538. * *
  1539. * INPUT: coord -- The coordinate to check. *
  1540. * *
  1541. * x,y -- Reference to the pixel coordinates that this *
  1542. * coordinate would be when rendered. *
  1543. * *
  1544. * OUTPUT: bool; Is this coordinate in a visible portion of the map? *
  1545. * *
  1546. * WARNINGS: If the coordinate is not in a visible portion of the *
  1547. * map, then this X and Y parameters are not set. *
  1548. * *
  1549. * HISTORY: *
  1550. * 05/14/1994 JLB : Created. *
  1551. * 12/15/1994 JLB : Converted to member function. *
  1552. * 01/07/1995 JLB : Uses inline functions to extract coord components. *
  1553. * 08/09/1995 JLB : Uses new coordinate system. *
  1554. *=============================================================================================*/
  1555. #define EDGE_ZONE (CELL_LEPTON_W*2)
  1556. bool DisplayClass::Coord_To_Pixel(COORDINATE coord, int &x, int &y) const
  1557. {
  1558. int xtac = Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(TacticalCoord)));
  1559. int xoff = Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(coord)));
  1560. xoff = (xoff + EDGE_ZONE) - xtac;
  1561. int ytac = Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(TacticalCoord)));
  1562. int yoff = Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(coord)));
  1563. yoff = (yoff + EDGE_ZONE) - ytac;
  1564. x = Lepton_To_Pixel(xoff) - CELL_PIXEL_W * 2;
  1565. y = Lepton_To_Pixel(yoff) - CELL_PIXEL_H * 2;
  1566. // Possibly ignore the view constraints if we aren't using the internal renderer. ST - 4/17/2019 9:06AM
  1567. return(coord && (IgnoreViewConstraints || ((xoff <= TacLeptonWidth + EDGE_ZONE * 2) && (yoff <= TacLeptonHeight + EDGE_ZONE * 2))));
  1568. }
  1569. #if (0) //reference. ST - 5/8/2019
  1570. bool DisplayClass::Coord_To_Pixel(COORDINATE coord, int &x, int &y) const
  1571. {
  1572. if (coord) {
  1573. int xtac = Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(TacticalCoord)));
  1574. int xoff = Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(coord)));
  1575. xoff = (xoff+EDGE_ZONE) - xtac;
  1576. if ((unsigned)xoff <= TacLeptonWidth + EDGE_ZONE*2) {
  1577. int ytac = Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(TacticalCoord)));
  1578. int yoff = Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(coord)));
  1579. yoff = (yoff+EDGE_ZONE) - ytac;
  1580. if ((unsigned)yoff <= TacLeptonHeight + EDGE_ZONE*2) {
  1581. x = Lepton_To_Pixel(xoff)-CELL_PIXEL_W*2;
  1582. y = Lepton_To_Pixel(yoff)-CELL_PIXEL_H*2;
  1583. return(true);
  1584. }
  1585. }
  1586. }
  1587. return(false);
  1588. }
  1589. #endif
  1590. /***********************************************************************************************
  1591. * DisplayClass::Push_Onto_TacMap -- Moves x & y coords to being on tactical map *
  1592. * *
  1593. * This routine expects a line to be drawn between SOURCE & DEST, so it pushes the coords to *
  1594. * be within the region bounded by TacMapX,Y - + TacMapW,H. *
  1595. * *
  1596. * INPUT: source, dest -- References to the coordinates to check. *
  1597. * *
  1598. * *
  1599. * OUTPUT: bool; Are these coordinates in a visible portion of the map? *
  1600. * Returns true if the pushed source & dest are visible, but if neither are *
  1601. * within the map, then it returns false. *
  1602. * *
  1603. * *
  1604. * HISTORY: *
  1605. * 03/27/1995 BWG : Created. *
  1606. *=============================================================================================*/
  1607. bool DisplayClass::Push_Onto_TacMap(COORDINATE & source, COORDINATE & dest)
  1608. {
  1609. if (!source || !dest) return(false);
  1610. int x1 = Coord_X(source);
  1611. int y1 = Coord_Y(source);
  1612. int x2 = Coord_X(dest);
  1613. int y2 = Coord_Y(dest);
  1614. int left = Coord_X(TacticalCoord);
  1615. int right = Coord_X(TacticalCoord) + TacLeptonWidth;
  1616. int top = Coord_Y(TacticalCoord);
  1617. int bottom = Coord_Y(TacticalCoord) + TacLeptonHeight;
  1618. if (x1 < left && x2 < left) return(false);
  1619. if (x1 > right && x2 > right) return(false);
  1620. if (y1 < top && y2 < top) return(false);
  1621. if (y1 > bottom && y2 > bottom) return(false);
  1622. x1 = Bound(x1, left, right);
  1623. x2 = Bound(x2, left, right);
  1624. y1 = Bound(y1, top, bottom);
  1625. y2 = Bound(y2, top, bottom);
  1626. source = XY_Coord(x1, y1);
  1627. dest = XY_Coord(x2, y2);
  1628. return(true);
  1629. }
  1630. /***********************************************************************************************
  1631. * DisplayClass::Cell_Object -- Determines what has been clicked on. *
  1632. * *
  1633. * This routine is used to determine what the player has clicked on. *
  1634. * It is passed the cell that the click was on and it then examines *
  1635. * the cell and returns with a pointer to the object that is there. *
  1636. * *
  1637. * INPUT: cell -- The cell that has been clicked upon. *
  1638. * *
  1639. * x,y -- Optional offsets from the upper left corner of the cell to be used in *
  1640. * determining exactly which object in the cell is desired. *
  1641. * *
  1642. * OUTPUT: Returns with a pointer to the object that is "clickable" in *
  1643. * the specified cell. *
  1644. * *
  1645. * WARNINGS: none *
  1646. * *
  1647. * HISTORY: *
  1648. * 05/14/1994 JLB : Created. *
  1649. *=============================================================================================*/
  1650. ObjectClass * DisplayClass::Cell_Object(CELL cell, int x, int y) const
  1651. {
  1652. return(*this)[cell].Cell_Object(x, y);
  1653. }
  1654. /***********************************************************************************************
  1655. * DisplayClass::Draw_It -- Draws the tactical map. *
  1656. * *
  1657. * This will draw the tactical map at the recorded position. This *
  1658. * routine is used whenever the tactical map moves or needs to be *
  1659. * completely redrawn. It will handle making the necessary adjustments *
  1660. * to accomodate a moving cursor. *
  1661. * *
  1662. * INPUT: forced -- bool; force redraw of the entire display? *
  1663. * *
  1664. * OUTPUT: none *
  1665. * *
  1666. * WARNINGS: none *
  1667. * *
  1668. * HISTORY: *
  1669. * 04/15/1991 JLB : Created. (benchmark = 292) *
  1670. * 04/15/1991 JLB : Added _cell2meta[] reference array (206) *
  1671. * 04/15/1991 JLB : Added actual map reference for terrain (207) *
  1672. * 04/16/1991 JLB : _cell2meta converted to int (194) *
  1673. * 04/16/1991 JLB : References actual CellIcon[] array (204) *
  1674. * 04/16/1991 JLB : Cell size increased to 16 x 16 (167) *
  1675. * 04/17/1991 JLB : Cell based tactical map rendering (165) *
  1676. * 04/22/1991 JLB : Uses Draw_Stamp() for icon rendering (426) *
  1677. * 04/22/1991 JLB : Draw_Stamp uses LogicPage now (276) *
  1678. * 04/23/1991 JLB : Map active location cursor (334) *
  1679. * 05/02/1991 JLB : Added smoothing and 3 icons sets (431) *
  1680. * 05/22/1991 JLB : Broken into Draw_Map() and Refresh_Map(). *
  1681. * 09/14/1991 JLB : Uses Refresh_Cell when new cells scroll onto display. *
  1682. * 05/12/1992 JLB : Destination page support. *
  1683. * 02/14/1994 JLB : Revamped. *
  1684. * 05/01/1994 JLB : Converted to member function. *
  1685. * 12/15/1994 JLB : Updated to work with display hierarchy. *
  1686. * 12/24/1994 JLB : Examines redraw bit intelligently. *
  1687. * 12/24/1994 JLB : Combined with old Refresh_Map() function. *
  1688. * 01/10/1995 JLB : Rubber band drawing. *
  1689. *=============================================================================================*/
  1690. void DisplayClass::Draw_It(bool forced)
  1691. {
  1692. int x,y; // Working cell index values.
  1693. MapClass::Draw_It(forced);
  1694. if (IsToRedraw || forced) {
  1695. BStart(BENCH_TACTICAL);
  1696. IsToRedraw = false;
  1697. /*
  1698. ** In rubber band mode, mark all cells under the "rubber band" to be
  1699. ** redrawn.
  1700. */
  1701. Refresh_Band();
  1702. /*
  1703. ** Mark all cells under the vortex to be redrawn
  1704. */
  1705. ChronalVortex.Set_Redraw();
  1706. /*
  1707. ** If the multiplayer message system is displaying one or more messages,
  1708. ** flag all cells covered by the messages to redraw. This will prevent
  1709. ** messages from smearing the map if it scrolls.
  1710. */
  1711. int num = Session.Messages.Num_Messages();
  1712. if (num > 0) {
  1713. CELL cell;
  1714. for (cell = Coord_Cell(TacticalCoord); cell < Coord_Cell(TacticalCoord) + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1715. (*this)[cell].Redraw_Objects();
  1716. }
  1717. for (cell = Coord_Cell(TacticalCoord) + MAP_CELL_W;
  1718. cell < Coord_Cell(TacticalCoord) + MAP_CELL_W + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1719. (*this)[cell].Redraw_Objects();
  1720. }
  1721. if (num > 1) {
  1722. for (cell = Coord_Cell(TacticalCoord) + MAP_CELL_W*2;
  1723. cell < Coord_Cell(TacticalCoord) + MAP_CELL_W*2 + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1724. (*this)[cell].Redraw_Objects();
  1725. }
  1726. }
  1727. if (num > 2) {
  1728. for (cell = Coord_Cell(TacticalCoord) + MAP_CELL_W*3;
  1729. cell < Coord_Cell(TacticalCoord) + MAP_CELL_W*3 + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1730. (*this)[cell].Redraw_Objects();
  1731. }
  1732. }
  1733. if (num > 3) {
  1734. for (cell = Coord_Cell(TacticalCoord) + MAP_CELL_W*4;
  1735. cell < Coord_Cell(TacticalCoord) + MAP_CELL_W*4 + Lepton_To_Cell(TacLeptonWidth)+1; cell++) {
  1736. (*this)[cell].Redraw_Objects();
  1737. }
  1738. }
  1739. }
  1740. /*
  1741. ** Check for a movement of the tactical map. If there has been some
  1742. ** movement, then part (or all) of the icons must be redrawn.
  1743. */
  1744. if (Lepton_To_Pixel(Coord_X(DesiredTacticalCoord)) != Lepton_To_Pixel(Coord_X(TacticalCoord)) ||
  1745. Lepton_To_Pixel(Coord_Y(DesiredTacticalCoord)) != Lepton_To_Pixel(Coord_Y(TacticalCoord))) {
  1746. int xmod = Lepton_To_Pixel(Coord_X(DesiredTacticalCoord));
  1747. int ymod = Lepton_To_Pixel(Coord_Y(DesiredTacticalCoord));
  1748. int oldx = Lepton_To_Pixel(Coord_X(TacticalCoord))-xmod; // Old relative offset.
  1749. int oldy = Lepton_To_Pixel(Coord_Y(TacticalCoord))-ymod;
  1750. int oldw = Lepton_To_Pixel(TacLeptonWidth)-ABS(oldx); // Replicable width.
  1751. int oldh = Lepton_To_Pixel(TacLeptonHeight)-ABS(oldy); // Replicable height.
  1752. if (oldw < 1) forced = true;
  1753. if (oldh < 1) forced = true;
  1754. #ifdef WIN32 //For WIN32 only redraw the edges of the map that move into view
  1755. /*
  1756. ** Work out which map edges need to be redrawn
  1757. */
  1758. BOOL redraw_right = (oldx < 0) ? true : false; //Right hand edge
  1759. BOOL redraw_left = (oldx > 0) ? true : false; //Left hand edge
  1760. BOOL redraw_bottom= (oldy < 0) ? true : false; //Bottom edge
  1761. BOOL redraw_top = (oldy > 0) ? true : false; //Top edge
  1762. /*
  1763. ** Blit any replicable block to avoid having to drawstamp.
  1764. */
  1765. if (!forced && (oldw != Lepton_To_Pixel(TacLeptonWidth) || oldh != Lepton_To_Pixel(TacLeptonHeight))) {
  1766. Set_Cursor_Pos(-1);
  1767. /*
  1768. ** If hid page is in video memory then blit from the seen page to avoid blitting
  1769. ** an overlapped region.
  1770. */
  1771. if (HidPage.Get_IsDirectDraw()) {
  1772. Hide_Mouse();
  1773. SeenBuff.Blit(HidPage,
  1774. ((oldx < 0) ? -oldx : 0) +TacPixelX,
  1775. ((oldy < 0) ? -oldy : 0) +TacPixelY,
  1776. ((oldx < 0) ? 0 : oldx) +TacPixelX,
  1777. ((oldy < 0) ? 0 : oldy) +TacPixelY,
  1778. oldw,
  1779. oldh);
  1780. Show_Mouse();
  1781. } else {
  1782. HidPage.Blit(HidPage,
  1783. ((oldx < 0) ? -oldx : 0) +TacPixelX,
  1784. ((oldy < 0) ? -oldy : 0) +TacPixelY,
  1785. ((oldx < 0) ? 0 : oldx) +TacPixelX,
  1786. ((oldy < 0) ? 0 : oldy) +TacPixelY,
  1787. oldw,
  1788. oldh);
  1789. }
  1790. } else {
  1791. forced = true;
  1792. }
  1793. if (oldx < 0) oldx = 0;
  1794. if (oldy < 0) oldy = 0;
  1795. /*
  1796. ** Record new map position for future reference.
  1797. */
  1798. ScenarioInit++;
  1799. Set_Tactical_Position(DesiredTacticalCoord);
  1800. ScenarioInit--;
  1801. if (!forced) {
  1802. /*
  1803. **
  1804. ** Set the 'redraw stamp' bit for any cells that could not be copied.
  1805. **
  1806. */
  1807. int startx = -Lepton_To_Pixel(Coord_XLepton(TacticalCoord));
  1808. int starty = -Lepton_To_Pixel(Coord_YLepton(TacticalCoord));
  1809. oldw -= 24;
  1810. oldh -= 24;
  1811. if (abs(oldx) < 0x25 && abs(oldy) < 0x25) {
  1812. /*
  1813. ** The width of the area we redraw depends on the scroll speed
  1814. */
  1815. int extra_x = (abs(oldx)>=16) ? 2 : 1;
  1816. int extra_y = (abs(oldy)>=16) ? 2 : 1;
  1817. /*
  1818. ** Flag the cells across the top of the visible area if required
  1819. */
  1820. if (redraw_top) {
  1821. for (y = starty; y <= starty+CELL_PIXEL_H*extra_y; y += CELL_PIXEL_H) {
  1822. for (x = startx; x <= Lepton_To_Pixel(TacLeptonWidth)+((CELL_PIXEL_W*2)); x += CELL_PIXEL_W) {
  1823. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1824. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1825. if (c > 0) (*this)[c].Redraw_Objects(true);
  1826. }
  1827. }
  1828. }
  1829. /*
  1830. ** Flag the cells across the bottom of the visible area if required
  1831. */
  1832. if (redraw_bottom) {
  1833. 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) {
  1834. for (x = startx; x <= Lepton_To_Pixel(TacLeptonWidth)+((CELL_PIXEL_W*2)); x += CELL_PIXEL_W) {
  1835. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1836. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1837. if (c > 0) (*this)[c].Redraw_Objects(true);
  1838. }
  1839. }
  1840. }
  1841. /*
  1842. ** Flag the cells down the left of the visible area if required
  1843. */
  1844. if (redraw_left) {
  1845. for (x = startx; x <= startx + CELL_PIXEL_W*extra_x; x += CELL_PIXEL_W) {
  1846. for (y = starty; y <= Lepton_To_Pixel(TacLeptonHeight)+((CELL_PIXEL_H*2)); y += CELL_PIXEL_H) {
  1847. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1848. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1849. if (c > 0) (*this)[c].Redraw_Objects(true);
  1850. }
  1851. }
  1852. }
  1853. /*
  1854. ** Flag the cells down the right of the visible area if required
  1855. */
  1856. if (redraw_right) {
  1857. 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) {
  1858. for (y = starty; y <= Lepton_To_Pixel(TacLeptonHeight)+((CELL_PIXEL_H*2)); y += CELL_PIXEL_H) {
  1859. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1860. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1861. if (c > 0) (*this)[c].Redraw_Objects(true);
  1862. }
  1863. }
  1864. }
  1865. } else {
  1866. /*
  1867. ** Set the 'redraw stamp' bit for any cells that could not be copied.
  1868. */
  1869. int startx = -Lepton_To_Pixel(Coord_XLepton(TacticalCoord));
  1870. int starty = -Lepton_To_Pixel(Coord_YLepton(TacticalCoord));
  1871. oldw -= 24;
  1872. oldh -= 24;
  1873. for (y = starty; y <= Lepton_To_Pixel(TacLeptonHeight)+((CELL_PIXEL_H*2)); y += CELL_PIXEL_H) {
  1874. for (x = startx; x <= Lepton_To_Pixel(TacLeptonWidth)+((CELL_PIXEL_W*2)); x += CELL_PIXEL_W) {
  1875. if (x <= oldx || x >= oldx+oldw || y <= oldy || y >= oldy+oldh) {
  1876. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1877. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1878. if (c > 0) {
  1879. (*this)[c].Redraw_Objects(true);
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. } else {
  1887. /*
  1888. ** Set the tactical coordinate just in case the desired tactical has changed but
  1889. ** not enough to result in any visible map change. This is likely to occur with very
  1890. ** slow scroll rates.
  1891. */
  1892. ScenarioInit++;
  1893. if (DesiredTacticalCoord != TacticalCoord) {
  1894. Set_Tactical_Position(DesiredTacticalCoord);
  1895. }
  1896. ScenarioInit--;
  1897. }
  1898. #else //WIN32
  1899. /*
  1900. ** Blit any replicable block to avoid having to drawstamp.
  1901. */
  1902. if (!forced && (oldw != Lepton_To_Pixel(TacLeptonWidth) || oldh != Lepton_To_Pixel(TacLeptonHeight))) {
  1903. Set_Cursor_Pos(-1);
  1904. HidPage.Blit(HidPage,
  1905. ((oldx < 0) ? -oldx : 0) +TacPixelX,
  1906. ((oldy < 0) ? -oldy : 0) +TacPixelY,
  1907. ((oldx < 0) ? 0 : oldx) +TacPixelX,
  1908. ((oldy < 0) ? 0 : oldy) +TacPixelY,
  1909. oldw,
  1910. oldh);
  1911. } else {
  1912. forced = true;
  1913. }
  1914. if (oldx < 0) oldx = 0;
  1915. if (oldy < 0) oldy = 0;
  1916. /*
  1917. ** Record new map position for future reference.
  1918. */
  1919. ScenarioInit++;
  1920. Set_Tactical_Position(DesiredTacticalCoord);
  1921. ScenarioInit--;
  1922. if (!forced) {
  1923. /*
  1924. ** Set the 'redraw stamp' bit for any cells that could not be copied.
  1925. */
  1926. int startx = -Lepton_To_Pixel(Coord_XLepton(TacticalCoord));
  1927. int starty = -Lepton_To_Pixel(Coord_YLepton(TacticalCoord));
  1928. oldw -= 24;
  1929. oldh -= 24;
  1930. for (y = starty; y <= Lepton_To_Pixel(TacLeptonHeight)+((CELL_PIXEL_H*2)); y += CELL_PIXEL_H) {
  1931. for (x = startx; x <= Lepton_To_Pixel(TacLeptonWidth)+((CELL_PIXEL_W*2)); x += CELL_PIXEL_W) {
  1932. if (x <= oldx || x >= oldx+oldw || y <= oldy || y >= oldy+oldh) {
  1933. CELL c = Click_Cell_Calc(Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1) + TacPixelX,
  1934. Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1) + TacPixelY);
  1935. if (c > 0) {
  1936. (*this)[c].Redraw_Objects(true);
  1937. }
  1938. }
  1939. }
  1940. }
  1941. }
  1942. } else {
  1943. /*
  1944. ** Set the tactical coordinate just in case the desired tactical has changed but
  1945. ** not enough to result in any visible map change. This is likely to occur with very
  1946. ** slow scroll rates.
  1947. */
  1948. ScenarioInit++;
  1949. if (DesiredTacticalCoord != TacticalCoord) {
  1950. Set_Tactical_Position(DesiredTacticalCoord);
  1951. }
  1952. ScenarioInit--;
  1953. }
  1954. #endif
  1955. /*
  1956. ** If the entire tactical map is forced to be redrawn, then set all the redraw flags
  1957. ** and let the normal processing take care of the rest.
  1958. */
  1959. if (forced) {
  1960. CellRedraw.Set();
  1961. }
  1962. /*
  1963. ** The first order of business is to redraw all the underlying icons that are
  1964. ** flagged to be redrawn.
  1965. */
  1966. if (HidPage.Lock()) {
  1967. Redraw_Icons();
  1968. /*
  1969. ** Draw the infantry bodies in this special layer.
  1970. */
  1971. // for (int index = 0; index < Anims.Count(); index++) {
  1972. // AnimClass * anim = Anims.Ptr(index);
  1973. // if (*anim >= ANIM_CORPSE1 && *anim <= ANIM_CORPSE3) {
  1974. // anim->Render(forced);
  1975. // }
  1976. // }
  1977. #ifdef SORTDRAW
  1978. /*
  1979. ** Draw the vortex effect over the terrain
  1980. */
  1981. ChronalVortex.Render();
  1982. Redraw_OIcons();
  1983. #endif
  1984. HidPage.Unlock();
  1985. }
  1986. #ifndef WIN32
  1987. /*
  1988. ** Once the icons are drawn, duplicate the bottom line of the screen into the phantom
  1989. ** area one line below the screen. This causes the predator effect to work on any
  1990. ** shape drawn at the bottom of the screen.
  1991. */
  1992. HidPage.Blit(HidPage, 0, HidPage.Get_Height()-1, 0, HidPage.Get_Height(), HidPage.Get_Width(), 1, false);
  1993. #endif
  1994. if (HidPage.Lock()) {
  1995. #ifndef SORTDRAW
  1996. /*
  1997. ** Draw the vortex effect over the terrain
  1998. */
  1999. ChronalVortex.Render();
  2000. #endif
  2001. /*
  2002. ** Redraw the game objects layer by layer. The layer drawing occurs on the ground layer
  2003. ** first and then followed by all the layers in increasing altitude.
  2004. */
  2005. BStart(BENCH_OBJECTS);
  2006. for (LayerType layer = LAYER_FIRST; layer < LAYER_COUNT; layer++) {
  2007. for (int index = 0; index < Layer[layer].Count(); index++) {
  2008. ObjectClass * ptr = Layer[layer][index];
  2009. #ifdef SORTDRAW
  2010. /*
  2011. ** Techno objects are drawn as part of the cell redraw process since techno
  2012. ** objects in the ground layer are handled by the Occupier and Overlapper
  2013. ** pointer lists.
  2014. */
  2015. if (!Debug_Map && ptr->Is_Techno() && layer == LAYER_GROUND && ((TechnoClass*)ptr)->Visual_Character() == VISUAL_NORMAL) continue;
  2016. #endif
  2017. // if (ptr->What_Am_I() == RTTI_ANIM && *((AnimClass*)ptr) >= ANIM_CORPSE1 && *((AnimClass*)ptr) <= ANIM_CORPSE3) {
  2018. // continue;
  2019. // }
  2020. assert(ptr->IsActive);
  2021. ptr->Render(forced);
  2022. }
  2023. }
  2024. BEnd(BENCH_OBJECTS);
  2025. //ChronalVortex.Render();
  2026. /*
  2027. ** Finally, redraw the shadow overlay as necessary.
  2028. */
  2029. BStart(BENCH_SHROUD);
  2030. Redraw_Shadow();
  2031. BEnd(BENCH_SHROUD);
  2032. }
  2033. HidPage.Unlock();
  2034. #ifdef SORTDRAW
  2035. for (int index = 0; index < Layer[LAYER_GROUND].Count(); index++) {
  2036. Layer[LAYER_GROUND][index]->IsToDisplay = false;
  2037. }
  2038. #endif
  2039. /*
  2040. ** Draw the rubber band over the top of it all.
  2041. */
  2042. if (IsRubberBand) {
  2043. LogicPage->Draw_Rect(BandX+TacPixelX, BandY+TacPixelY, NewX+TacPixelX, NewY+TacPixelY, WHITE);
  2044. }
  2045. /*
  2046. ** Clear the redraw flags so that normal redraw flag setting can resume.
  2047. */
  2048. CellRedraw.Reset();
  2049. #ifdef SCENARIO_EDITOR
  2050. /*
  2051. ** If we're placing an object (PendingObject is non-NULL), and that object
  2052. ** is NOT an icon, smudge, or overlay, draw it here.
  2053. ** Terrain, Buildings & Aircraft aren't drawn at the cell's center coord;
  2054. ** they're drawn at the upper left coord, so I have to AND the coord value
  2055. ** with 0xFF00FF00 to strip off the lepton coordinates, but leave the
  2056. ** cell coordinates.
  2057. */
  2058. if (Debug_Map && PendingObjectPtr) {
  2059. PendingObjectPtr->Coord = PendingObjectPtr->Class_Of().Coord_Fixup(Cell_Coord(ZoneCell + ZoneOffset));
  2060. PendingObjectPtr->Render(true);
  2061. }
  2062. #endif
  2063. BEnd(BENCH_TACTICAL);
  2064. }
  2065. }
  2066. /***********************************************************************************************
  2067. * DisplayClass::Redraw_Icons -- Draws all terrain icons necessary. *
  2068. * *
  2069. * This routine will redraw all of the terrain icons that are flagged *
  2070. * to be redrawn. *
  2071. * *
  2072. * INPUT: none *
  2073. * *
  2074. * OUTPUT: none *
  2075. * *
  2076. * WARNINGS: none. *
  2077. * *
  2078. * HISTORY: *
  2079. * 02/14/1994 JLB : Created. *
  2080. * 05/01/1994 JLB : Converted to member function. *
  2081. * 06/20/1994 JLB : Uses cell drawing support function. *
  2082. * 12/06/1994 JLB : Scans tactical view in separate row/column loops *
  2083. * 12/24/1994 JLB : Uses the cell bit flag array to determine what to redraw. *
  2084. *=============================================================================================*/
  2085. void DisplayClass::Redraw_Icons(void)
  2086. {
  2087. IsShadowPresent = false;
  2088. for (int y = -Coord_YLepton(TacticalCoord); y <= TacLeptonHeight; y += CELL_LEPTON_H) {
  2089. for (int x = -Coord_XLepton(TacticalCoord); x <= TacLeptonWidth; x += CELL_LEPTON_W) {
  2090. COORDINATE coord = Coord_Add(TacticalCoord, XY_Coord(x, y));
  2091. CELL cell = Coord_Cell(coord);
  2092. coord = Coord_Whole(Cell_Coord(cell));
  2093. /*
  2094. ** Only cells flagged to be redraw are examined.
  2095. */
  2096. if (In_View(cell) && Is_Cell_Flagged(cell)) {
  2097. int xpixel;
  2098. int ypixel;
  2099. if (Coord_To_Pixel(coord, xpixel, ypixel)) {
  2100. CellClass * cellptr = &(*this)[coord];
  2101. /*
  2102. ** If there is a portion of the underlying icon that could be visible,
  2103. ** then draw it. Also draw the cell if the shroud is off.
  2104. */
  2105. //if (cellptr->IsMapped || Debug_Unshroud) {
  2106. if (cellptr->Is_Mapped(PlayerPtr) || Debug_Unshroud) { // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2107. cellptr->Draw_It(xpixel, ypixel);
  2108. }
  2109. /*
  2110. ** If any cell is not fully mapped, then flag it so that the shadow drawing
  2111. ** process will occur. Only draw the shadow if Debug_Unshroud is false.
  2112. */
  2113. //if (!cellptr->IsVisible && !Debug_Unshroud) {
  2114. if (!cellptr->Is_Visible(PlayerPtr) && !Debug_Unshroud) { // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2115. IsShadowPresent = true;
  2116. }
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. #ifdef SORTDRAW
  2123. void DisplayClass::Redraw_OIcons(void)
  2124. {
  2125. for (int y = -Coord_YLepton(TacticalCoord); y <= TacLeptonHeight; y += CELL_LEPTON_H) {
  2126. for (int x = -Coord_XLepton(TacticalCoord); x <= TacLeptonWidth; x += CELL_LEPTON_W) {
  2127. COORDINATE coord = Coord_Add(TacticalCoord, XY_Coord(x, y));
  2128. CELL cell = Coord_Cell(coord);
  2129. coord = Coord_Whole(Cell_Coord(cell));
  2130. /*
  2131. ** Only cells flagged to be redraw are examined.
  2132. */
  2133. if (In_View(cell) && Is_Cell_Flagged(cell)) {
  2134. int xpixel;
  2135. int ypixel;
  2136. if (Coord_To_Pixel(coord, xpixel, ypixel)) {
  2137. CellClass * cellptr = &(*this)[coord];
  2138. /*
  2139. ** If there is a portion of the underlying icon that could be visible,
  2140. ** then draw it. Also draw the cell if the shroud is off.
  2141. */
  2142. //if (cellptr->IsMapped || Debug_Unshroud) {
  2143. if (cellptr->Is_Mapped(PlayerPtr) || Debug_Unshroud) { // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  2144. cellptr->Draw_It(xpixel, ypixel, true);
  2145. }
  2146. }
  2147. }
  2148. }
  2149. }
  2150. }
  2151. #endif
  2152. /***********************************************************************************************
  2153. * DisplayClass::Redraw_Shadow -- Draw the shadow overlay. *
  2154. * *
  2155. * This routine is called after all other tactical map rendering takes place. It draws *
  2156. * the shadow map over the tactical map. *
  2157. * *
  2158. * INPUT: none *
  2159. * *
  2160. * OUTPUT: none *
  2161. * *
  2162. * WARNINGS: none *
  2163. * *
  2164. * HISTORY: *
  2165. * 01/01/1995 JLB : Created. *
  2166. * 08/06/1995 JLB : Clips the fill rect if necessary. *
  2167. *=============================================================================================*/
  2168. void DisplayClass::Redraw_Shadow(void)
  2169. {
  2170. if (IsShadowPresent) {
  2171. for (int y = -Coord_YLepton(TacticalCoord); y <= TacLeptonHeight; y += CELL_LEPTON_H) {
  2172. for (int x = -Coord_XLepton(TacticalCoord); x <= TacLeptonWidth; x += CELL_LEPTON_W) {
  2173. COORDINATE coord = Coord_Add(TacticalCoord, XY_Coord(x, y));
  2174. CELL cell = Coord_Cell(coord);
  2175. coord = Coord_Whole(Cell_Coord(cell));
  2176. /*
  2177. ** Only cells flagged to be redrawn are examined.
  2178. */
  2179. if (In_View(cell) && Is_Cell_Flagged(cell)) {
  2180. int xpixel;
  2181. int ypixel;
  2182. if (Coord_To_Pixel(coord, xpixel, ypixel)) {
  2183. CellClass * cellptr = &(*this)[coord];
  2184. //if (cellptr->IsVisible) continue;
  2185. if (cellptr->Is_Visible(PlayerPtr)) continue; // Use PlayerPtr since we won't be rendering in MP. ST - 8/6/2019 10:44AM
  2186. int shadow = -2;
  2187. //if (cellptr->IsMapped) {
  2188. if (cellptr->Is_Mapped(PlayerPtr)) { // Use PlayerPtr since we won't be rendering in MP. ST - 8/6/2019 10:44AM
  2189. shadow = Cell_Shadow(cell, PlayerPtr); // Use PlayerPtr since we won't be rendering in MP. ST - 8/6/2019 10:44AM
  2190. }
  2191. if (shadow >= 0) {
  2192. CC_Draw_Shape(ShadowShapes, shadow, xpixel, ypixel, WINDOW_TACTICAL, SHAPE_GHOST, NULL, ShadowTrans);
  2193. } else {
  2194. if (shadow != -1) {
  2195. int ww = CELL_PIXEL_W;
  2196. int hh = CELL_PIXEL_H;
  2197. if (Clip_Rect(&xpixel, &ypixel, &ww, &hh, Lepton_To_Pixel(TacLeptonWidth), Lepton_To_Pixel(TacLeptonHeight)) >= 0) {
  2198. LogicPage->Fill_Rect(TacPixelX+xpixel, TacPixelY+ypixel, TacPixelX+xpixel+ww-1, TacPixelY+ypixel+hh-1, BLACK);
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. /***********************************************************************************************
  2209. * DisplayClass::Next_Object -- Searches for next object on display. *
  2210. * *
  2211. * This utility routine is used to find the "next" object from the object specified. This *
  2212. * is typically used when <TAB> is pressed and the current object shifts. *
  2213. * *
  2214. * INPUT: object -- The current object to base the "next" calculation off of. *
  2215. * *
  2216. * OUTPUT: Returns with a pointer to the next object. If there is no objects available, *
  2217. * then NULL is returned. *
  2218. * *
  2219. * WARNINGS: none *
  2220. * *
  2221. * HISTORY: *
  2222. * 06/20/1994 JLB : Created. *
  2223. *=============================================================================================*/
  2224. ObjectClass * DisplayClass::Next_Object(ObjectClass * object) const
  2225. {
  2226. ObjectClass * firstobj = NULL;
  2227. bool foundmatch = false;
  2228. if (object == NULL) {
  2229. foundmatch = true;
  2230. }
  2231. for (unsigned uindex = 0; uindex < (unsigned)Layer[LAYER_GROUND].Count(); uindex++) {
  2232. ObjectClass * obj = Layer[LAYER_GROUND][uindex];
  2233. /*
  2234. ** Verify that the object can be selected by and is owned by the player.
  2235. */
  2236. if (obj != NULL && obj->Is_Players_Army()) {
  2237. if (firstobj == NULL) firstobj = obj;
  2238. if (foundmatch) return(obj);
  2239. if (object == obj) foundmatch = true;
  2240. }
  2241. }
  2242. return(firstobj);
  2243. }
  2244. /***********************************************************************************************
  2245. * DisplayClass::Prev_Object -- Searches for the previous object on the map. *
  2246. * *
  2247. * This routine will search for the previous object. Previous is defined as the one listed *
  2248. * before the specified object in the ground layer. If there is no specified object, then *
  2249. * the last object in the ground layer is returned. *
  2250. * *
  2251. * INPUT: object -- Pointer to the object that "previous" is to be defined from. *
  2252. * *
  2253. * OUTPUT: Returns with a pointer to the object previous to the specified one. *
  2254. * *
  2255. * WARNINGS: none *
  2256. * *
  2257. * HISTORY: *
  2258. * 08/24/1995 JLB : Created. *
  2259. *=============================================================================================*/
  2260. ObjectClass * DisplayClass::Prev_Object(ObjectClass * object) const
  2261. {
  2262. ObjectClass * firstobj = NULL;
  2263. bool foundmatch = false;
  2264. if (object == NULL) {
  2265. foundmatch = true;
  2266. }
  2267. for (int uindex = Layer[LAYER_GROUND].Count()-1; uindex >= 0; uindex--) {
  2268. ObjectClass * obj = Layer[LAYER_GROUND][uindex];
  2269. /*
  2270. ** Verify that the object can be selected by and is owned by the player.
  2271. */
  2272. if (obj != NULL && obj->Is_Players_Army()) {
  2273. if (firstobj == NULL) firstobj = obj;
  2274. if (foundmatch) return(obj);
  2275. if (object == obj) foundmatch = true;
  2276. }
  2277. }
  2278. return(firstobj);
  2279. }
  2280. /***********************************************************************************************
  2281. * DisplayClass::Pixel_To_Coord -- converts screen coord to COORDINATE *
  2282. * *
  2283. * INPUT: *
  2284. * x,y pixel coordinates to convert *
  2285. * *
  2286. * OUTPUT: *
  2287. * COORDINATE of pixel *
  2288. * *
  2289. * WARNINGS: *
  2290. * none. *
  2291. * *
  2292. * HISTORY: *
  2293. * 11/09/1994 BR : Created. *
  2294. * 12/06/1994 JLB : Uses map dimension variables in display class. *
  2295. * 12/10/1994 JLB : Uses union to speed building coordinate value. *
  2296. *=============================================================================================*/
  2297. COORDINATE DisplayClass::Pixel_To_Coord(int x, int y) const
  2298. {
  2299. /*
  2300. ** Normalize the pixel coordinates to be relative to the upper left corner
  2301. ** of the tactical map. The coordinates are expressed in leptons.
  2302. */
  2303. x -= TacPixelX;
  2304. x = Pixel_To_Lepton(x);
  2305. y -= TacPixelY;
  2306. y = Pixel_To_Lepton(y);
  2307. /*
  2308. ** If pixel coordinate is over the tactical map, then translate it into a coordinate
  2309. ** value. If not, then just return with NULL.
  2310. */
  2311. // Possibly ignore the view constraints if we aren't using the internal renderer. ST - 8/6/2019 10:47AM
  2312. //if ((unsigned)x < TacLeptonWidth && (unsigned)y < TacLeptonHeight) {
  2313. if (IgnoreViewConstraints || ((unsigned)x < TacLeptonWidth && (unsigned)y < TacLeptonHeight)) {
  2314. return(Coord_Add(TacticalCoord, XY_Coord(x, y)));
  2315. }
  2316. return(0);
  2317. }
  2318. /***********************************************************************************************
  2319. * DisplayClass::Calculated_Cell -- Fetch a map cell based on specified method. *
  2320. * *
  2321. * Find a cell meeting the specified requirements. This function is *
  2322. * used for scenario reinforcements. *
  2323. * *
  2324. * INPUT: dir -- Method of picking a map cell. *
  2325. * *
  2326. * waypoint -- Closest waypoint to use for finding appropriate map edge. *
  2327. * *
  2328. * cell -- Cell to find closest edge to if waypoint not specified. *
  2329. * *
  2330. * loco -- The locomotion of the reinforcements that are trying to enter. *
  2331. * *
  2332. * zonecheck -- Is zone checking required? *
  2333. * *
  2334. * mzone -- The movement zone type to check against (only if zone checking). *
  2335. * *
  2336. * OUTPUT: Returns with the calculated cell. If 0, then this indicates *
  2337. * that no legal cell was found. *
  2338. * *
  2339. * WARNINGS: none *
  2340. * *
  2341. * HISTORY: *
  2342. * 10/07/1992 JLB : Created. *
  2343. * 04/11/1994 JLB : Revamped. *
  2344. * 05/18/1994 JLB : Converted to member function. *
  2345. * 12/18/1995 JLB : Handles edge preference scan. *
  2346. * 06/24/1996 JLB : Removed Dune II legacy code. *
  2347. * 06/25/1996 JLB : Rewrote and greatly simplified. *
  2348. * 10/05/1996 JLB : Checks for zone and crushable status. *
  2349. *=============================================================================================*/
  2350. CELL DisplayClass::Calculated_Cell(SourceType dir, WAYPOINT waypoint, CELL cell, SpeedType loco, bool zonecheck, MZoneType mzone) const
  2351. {
  2352. bool vert = false;
  2353. bool horz = false;
  2354. int x = 0;
  2355. int y = 0;
  2356. CELL punt = 0; // If all else fails, return this cell location.
  2357. int zone = -1; // Tentative zone for legality checking.
  2358. /*
  2359. ** Waypoint edge detection for ground based reinforcements that have a waypoint origin are
  2360. ** determined by finding the closest map edge to the waypoint. Reinforcement location
  2361. ** scanning starts from that position.
  2362. */
  2363. CELL trycell = -1;
  2364. if (waypoint != -1) {
  2365. trycell = Scen.Waypoint[waypoint];
  2366. }
  2367. if (trycell == -1) {
  2368. trycell = cell;
  2369. }
  2370. /*
  2371. ** If zone checking is requested, then find the correct zone to use.
  2372. */
  2373. if (zonecheck && trycell != -1) {
  2374. zone = (*this)[trycell].Zones[mzone];
  2375. }
  2376. /*
  2377. ** If the cell or waypoint specified as been detected as legal, then set up the map edge
  2378. ** scanning values accordingly.
  2379. */
  2380. if (trycell != -1) {
  2381. x = Cell_X(trycell) - MapCellX;
  2382. x = min(x, (-Cell_X(trycell) + (MapCellX+MapCellWidth)));
  2383. y = Cell_Y(trycell) - MapCellY;
  2384. y = min(y, (-Cell_Y(trycell) + (MapCellY+MapCellHeight)));
  2385. if (x < y) {
  2386. vert = true;
  2387. horz = false;
  2388. if ((Cell_X(trycell)-MapCellX) < MapCellWidth/2) {
  2389. x = -1;
  2390. } else {
  2391. x = MapCellWidth;
  2392. }
  2393. y = Cell_Y(trycell) - MapCellY;
  2394. } else {
  2395. vert = false;
  2396. horz = true;
  2397. if ((Cell_Y(trycell)-MapCellY) < MapCellHeight/2) {
  2398. y = -1;
  2399. } else {
  2400. y = MapCellHeight;
  2401. }
  2402. x = Cell_X(trycell) - MapCellX;
  2403. }
  2404. }
  2405. /*
  2406. ** If no map edge can be inferred from the waypoint, then go with the
  2407. ** map edge specified by the edge parameter.
  2408. */
  2409. if (!vert && !horz) {
  2410. switch (dir) {
  2411. default:
  2412. case SOURCE_NORTH:
  2413. horz = true;
  2414. y = -1;
  2415. x = Random_Pick(0, MapCellWidth-1);
  2416. break;
  2417. case SOURCE_SOUTH:
  2418. horz = true;
  2419. y = MapCellHeight;
  2420. x = Random_Pick(0, MapCellWidth-1);
  2421. break;
  2422. case SOURCE_EAST:
  2423. vert = true;
  2424. x = MapCellWidth;
  2425. y = Random_Pick(0, MapCellHeight-1);
  2426. break;
  2427. case SOURCE_WEST:
  2428. vert = true;
  2429. x = -1;
  2430. y = Random_Pick(0, MapCellHeight-1);
  2431. break;
  2432. }
  2433. }
  2434. /*
  2435. ** Determine the default reinforcement cell if all else fails.
  2436. */
  2437. punt = XY_Cell(x + MapCellX, y + MapCellY);
  2438. /*
  2439. ** Scan through the vertical and horizontal edges of the map looking for
  2440. ** a relatively clear cell for object placement. The cell scanned is
  2441. ** from the edge position specified by the X and Y variables.
  2442. */
  2443. if (vert) {
  2444. int modifier = (x > MapCellX) ? -1 : 1;
  2445. for (int index = 0; index < MapCellHeight; index++) {
  2446. CELL trycell = XY_Cell(x + MapCellX, ((y + index) % MapCellHeight) + MapCellY);
  2447. if (Good_Reinforcement_Cell(trycell, trycell+modifier, loco, zone, mzone)) {
  2448. return(trycell);
  2449. }
  2450. }
  2451. }
  2452. if (horz) {
  2453. int modifier = (y > MapCellY) ? -MAP_CELL_W : MAP_CELL_W;
  2454. for (int index = 0; index < MapCellWidth; index++) {
  2455. CELL trycell = XY_Cell(((x + index) % MapCellWidth) + MapCellX, y + MapCellY);
  2456. if (Good_Reinforcement_Cell(trycell, trycell+modifier, loco, zone, mzone)) {
  2457. return(trycell);
  2458. }
  2459. }
  2460. }
  2461. /*
  2462. ** If there was no success in finding a suitable reinforcement edge cell, then return
  2463. ** with the default 'punt' cell location.
  2464. */
  2465. return(punt);
  2466. }
  2467. /***********************************************************************************************
  2468. * DisplayClass::Good_Reinforcement_Cell -- Checks cell for renforcement legality. *
  2469. * *
  2470. * This routine will check the secified cell (given the specified conditions) and determine *
  2471. * if that is a good cell for reinforcement purposes. It checks for passability of the cell *
  2472. * as well as zone and whether blocking walls can be crushed. *
  2473. * *
  2474. * INPUT: outcell -- The cell that is just outside the edge of the map. *
  2475. * *
  2476. * incell -- The cell that is just inside the edge of the map. *
  2477. * *
  2478. * loco -- The locomotion type of the reinforcement. *
  2479. * *
  2480. * zone -- The zone that the eventual movement destination lies. A reinforcement *
  2481. * edge must fall within the same zone. *
  2482. * *
  2483. * mzone -- The zone check type to check against (if zone checking required) *
  2484. * *
  2485. * OUTPUT: bool; Is the specified cell good for reinforcement purposes? *
  2486. * *
  2487. * WARNINGS: none *
  2488. * *
  2489. * HISTORY: *
  2490. * 10/05/1996 JLB : Created. *
  2491. *=============================================================================================*/
  2492. bool DisplayClass::Good_Reinforcement_Cell(CELL outcell, CELL incell, SpeedType loco, int zone, MZoneType mzone) const
  2493. {
  2494. /*
  2495. ** If the map edge location is not clear for object placement, then this is not
  2496. ** a good cell for reinforcement purposes.
  2497. */
  2498. if (!(*this)[outcell].Is_Clear_To_Move(loco, false, false)) {
  2499. return(false);
  2500. }
  2501. /*
  2502. ** If it looks like the on-map cell cannot be driven on to, then return with
  2503. ** the failure code.
  2504. */
  2505. if (!(*this)[incell].Is_Clear_To_Move(loco, false, false, zone, mzone)) {
  2506. return(false);
  2507. }
  2508. /*
  2509. ** If the reinforcement cell is already occupied, then return a failure code.
  2510. */
  2511. if ((*this)[outcell].Cell_Techno() != NULL) {
  2512. return(false);
  2513. }
  2514. if ((*this)[incell].Cell_Techno() != NULL) return(false);
  2515. /*
  2516. ** All tests have passed, return with success code.
  2517. */
  2518. //Mono_Printf("<%04X>\n", incell);Keyboard->Get();
  2519. return(true);
  2520. }
  2521. /***********************************************************************************************
  2522. * DisplayClass::Select_These -- All selectable objects in region are selected. *
  2523. * *
  2524. * Use this routine to simultaneously select all objects within the coordinate region *
  2525. * specified. This routine is used by the multi-select rubber band handler. *
  2526. * *
  2527. * INPUT: coord1 -- Coordinate of one corner of the selection region. *
  2528. * *
  2529. * coord2 -- The opposite corner of the selection region. *
  2530. * *
  2531. * additive -- Does this add to the existing selection or replace it. *
  2532. * *
  2533. * OUTPUT: none *
  2534. * *
  2535. * WARNINGS: none *
  2536. * *
  2537. * HISTORY: *
  2538. * 01/19/1995 JLB : Created. *
  2539. * 04/25/1995 JLB : Limited to non-building type. *
  2540. * 03/06/1996 JLB : Allows selection of aircraft with bounding box. *
  2541. *=============================================================================================*/
  2542. static bool should_exclude_from_selection(ObjectClass* obj)
  2543. {
  2544. return (obj->What_Am_I() == RTTI_UNIT) &&
  2545. (((UnitClass *)obj)->Class->IsToHarvest ||
  2546. *((UnitClass *)obj) == UNIT_MCV);
  2547. }
  2548. void DisplayClass::Select_These(COORDINATE coord1, COORDINATE coord2, bool additive)
  2549. {
  2550. COORDINATE tcoord = TacticalCoord; //Cell_Coord(TacticalCell) & 0xFF00FF00L;
  2551. coord1 = Coord_Add(tcoord, coord1);
  2552. coord2 = Coord_Add(tcoord, coord2);
  2553. int x1 = Coord_X(coord1);
  2554. int x2 = Coord_X(coord2);
  2555. int y1 = Coord_Y(coord1);
  2556. int y2 = Coord_Y(coord2);
  2557. /*
  2558. ** Ensure that coordinate number one represents the upper left corner
  2559. ** and coordinate number two represents the lower right corner.
  2560. */
  2561. if (x1 > x2) {
  2562. int temp = x1;
  2563. x1 = x2;
  2564. x2 = temp;
  2565. }
  2566. if (y1 > y2) {
  2567. int temp = y1;
  2568. y1 = y2;
  2569. y2 = temp;
  2570. }
  2571. /*
  2572. ** Sweep through all ground layer objects and select the ones within the
  2573. ** bounding box.
  2574. */
  2575. if (!additive) {
  2576. Unselect_All();
  2577. }
  2578. AllowVoice = true;
  2579. for (int index = 0; index < Layer[LAYER_GROUND].Count(); index++) {
  2580. ObjectClass * obj = Layer[LAYER_GROUND][index];
  2581. COORDINATE ocoord = obj->Center_Coord();
  2582. int x = Coord_X(ocoord);
  2583. int y = Coord_Y(ocoord);
  2584. /*
  2585. ** Only try to select objects that are allowed to be selected, and are within the bounding box.
  2586. */
  2587. HouseClass * hptr = HouseClass::As_Pointer(obj->Owner());
  2588. if ( obj->Class_Of().IsSelectable &&
  2589. obj->What_Am_I() != RTTI_BUILDING &&
  2590. (!obj->Is_Techno() || !((TechnoClass*)obj)->Is_Cloaked(PlayerPtr)) &&
  2591. x >= x1 && x <= x2 && y >= y1 && y <= y2) {
  2592. bool old_allow_voice = AllowVoice;
  2593. bool is_player_controlled = (hptr != NULL) && hptr->IsPlayerControl;
  2594. AllowVoice &= is_player_controlled;
  2595. if (obj->Select(true)) {
  2596. if (is_player_controlled) {
  2597. old_allow_voice = false;
  2598. }
  2599. }
  2600. AllowVoice = old_allow_voice;
  2601. }
  2602. }
  2603. /*
  2604. ** Select any aircraft with the bounding box.
  2605. */
  2606. for (int air_index = 0; air_index < Aircraft.Count(); air_index++) {
  2607. AircraftClass * aircraft = Aircraft.Ptr(air_index);
  2608. COORDINATE ocoord = aircraft->Center_Coord();
  2609. int x = Coord_X(ocoord);
  2610. int y = Coord_Y(ocoord);
  2611. /*
  2612. ** Only try to select objects that are allowed to be selected, and are within the bounding box.
  2613. */
  2614. if ( aircraft->Class->IsSelectable &&
  2615. !aircraft->Is_Cloaked(PlayerPtr) &&
  2616. !aircraft->Is_Selected_By_Player() &&
  2617. x >= x1 && x <= x2 && y >= y1 && y <= y2) {
  2618. bool old_allow_voice = AllowVoice;
  2619. bool is_player_controlled = aircraft->House->IsPlayerControl;
  2620. AllowVoice &= is_player_controlled;
  2621. if (aircraft->Select(true)) {
  2622. if (is_player_controlled) {
  2623. old_allow_voice = false;
  2624. }
  2625. }
  2626. AllowVoice = old_allow_voice;
  2627. }
  2628. }
  2629. /*
  2630. ** If a mix of player and non-player controlled units were selected, make sure non-player controlled units are de-selected
  2631. */
  2632. bool player_controlled_units = false, non_player_controlled_units = false;
  2633. for (int i = 0; (i < CurrentObject.Count()) && (!player_controlled_units || !non_player_controlled_units); ++i) {
  2634. HouseClass * hptr = HouseClass::As_Pointer(CurrentObject[i]->Owner());
  2635. if (hptr->IsPlayerControl) {
  2636. player_controlled_units = true;
  2637. }
  2638. else {
  2639. non_player_controlled_units = true;
  2640. }
  2641. }
  2642. if (player_controlled_units && non_player_controlled_units) {
  2643. for (int i = 0; i < CurrentObject.Count(); ++i) {
  2644. HouseClass * hptr = HouseClass::As_Pointer(CurrentObject[i]->Owner());
  2645. if (!hptr->IsPlayerControl) {
  2646. int count_before = CurrentObject.Count();
  2647. CurrentObject[i]->Unselect();
  2648. if (count_before <= CurrentObject.Count()) {
  2649. GlyphX_Debug_Print("Select_These failed to remove an object");
  2650. CurrentObject.Delete(CurrentObject[i]);
  2651. }
  2652. --i;
  2653. }
  2654. }
  2655. }
  2656. /*
  2657. ** If player-controlled units are non-additively selected, remove harvesters and MCVs if they aren't the only types of units selected
  2658. */
  2659. if (!additive && player_controlled_units) {
  2660. bool any_to_exclude = false, all_to_exclude = true;
  2661. for (int i = 0; i < CurrentObject.Count(); ++i) {
  2662. bool exclude = should_exclude_from_selection(CurrentObject[i]);
  2663. any_to_exclude |= exclude;
  2664. all_to_exclude &= exclude;
  2665. }
  2666. if (any_to_exclude && !all_to_exclude) {
  2667. for (int i = 0; i < CurrentObject.Count(); ++i) {
  2668. if (should_exclude_from_selection(CurrentObject[i])) {
  2669. int count_before = CurrentObject.Count();
  2670. CurrentObject[i]->Unselect();
  2671. if (count_before <= CurrentObject.Count()) {
  2672. GlyphX_Debug_Print("Select_These failed to remove an object");
  2673. CurrentObject.Delete(CurrentObject[i]);
  2674. }
  2675. --i;
  2676. }
  2677. }
  2678. }
  2679. }
  2680. AllowVoice = true;
  2681. }
  2682. /***********************************************************************************************
  2683. * DisplayClass::Refresh_Band -- Causes all cells under the rubber band to be redrawn. *
  2684. * *
  2685. * Use this routine to flag all cells that are covered in some fashion by the multi-unit *
  2686. * select "rubber band" to be redrawn. This is necessary whenever the rubber band changes *
  2687. * size or is being removed. *
  2688. * *
  2689. * INPUT: none *
  2690. * *
  2691. * OUTPUT: none *
  2692. * *
  2693. * WARNINGS: none *
  2694. * *
  2695. * HISTORY: *
  2696. * 01/19/1995 JLB : Created. *
  2697. *=============================================================================================*/
  2698. void DisplayClass::Refresh_Band(void)
  2699. {
  2700. if (IsRubberBand) {
  2701. /*
  2702. ** In rubber band mode, mark all cells under the "rubber band" to be
  2703. ** redrawn.
  2704. */
  2705. int x1 = BandX+TacPixelX;
  2706. int y1 = BandY+TacPixelY;
  2707. int x2 = NewX+TacPixelX;
  2708. int y2 = NewY+TacPixelY;
  2709. if (x1 > x2) {
  2710. int temp = x1;
  2711. x1 = x2;
  2712. x2 = temp;
  2713. }
  2714. if (y1 > y2) {
  2715. int temp = y1;
  2716. y1 = y2;
  2717. y2 = temp;
  2718. }
  2719. CELL cell;
  2720. for (int y = y1; y <= y2+CELL_PIXEL_H; y += CELL_PIXEL_H) {
  2721. cell = Click_Cell_Calc(x1, Bound(y, 0, TacPixelY+Lepton_To_Pixel(TacLeptonHeight)));
  2722. if (cell != -1) (*this)[cell].Redraw_Objects();
  2723. cell = Click_Cell_Calc(x2, Bound(y, 0, TacPixelY+Lepton_To_Pixel(TacLeptonHeight)));
  2724. if (cell != -1) (*this)[cell].Redraw_Objects();
  2725. }
  2726. for (int x = x1; x <= x2+CELL_PIXEL_W; x += CELL_PIXEL_W) {
  2727. cell = Click_Cell_Calc(Bound(x, 0, TacPixelX+Lepton_To_Pixel(TacLeptonWidth)), y1);
  2728. if (cell != -1) (*this)[cell].Redraw_Objects();
  2729. cell = Click_Cell_Calc(Bound(x, 0, TacPixelX+Lepton_To_Pixel(TacLeptonWidth)), y2);
  2730. if (cell != -1) (*this)[cell].Redraw_Objects();
  2731. }
  2732. /*
  2733. ** Stretching the rubber band requires all objects to be redrawn.
  2734. */
  2735. int index;
  2736. for (index = 0; index < Layer[LAYER_TOP].Count(); index++) {
  2737. Layer[LAYER_TOP][index]->Mark(MARK_CHANGE);
  2738. }
  2739. for (index = 0; index < Layer[LAYER_AIR].Count(); index++) {
  2740. Layer[LAYER_AIR][index]->Mark(MARK_CHANGE);
  2741. }
  2742. }
  2743. }
  2744. /***********************************************************************************************
  2745. * DisplayClass::TacticalClass::Action -- Processes input for the tactical map. *
  2746. * *
  2747. * This routine handles the input directed at the tactical map. Since input, in this *
  2748. * regard, includes even the presence of the mouse over the tactical map, this routine *
  2749. * is called nearly every game frame. It handles adjusting the mouse shape as well as *
  2750. * giving orders to units. *
  2751. * *
  2752. * INPUT: flags -- The gadget event flags that triggered the call to this function. *
  2753. * *
  2754. * key -- A reference to the keyboard event (if any). *
  2755. * *
  2756. * OUTPUT: bool; Should processing be aborted on any succeeding buttons in the chain? *
  2757. * *
  2758. * WARNINGS: none *
  2759. * *
  2760. * HISTORY: *
  2761. * 02/17/1995 JLB : Created. *
  2762. *=============================================================================================*/
  2763. int DisplayClass::TacticalClass::Action(unsigned flags, KeyNumType & key)
  2764. {
  2765. int x,y; // Sub cell pixel coordinates.
  2766. bool shadow;
  2767. ObjectClass * object = 0;
  2768. ActionType action = ACTION_NONE; // Action possible with currently selected object.
  2769. /*
  2770. ** Set some working variables that depend on the mouse position. For the press
  2771. ** or release event, special mouse queuing storage variables are used. Other
  2772. ** events must use the current mouse position globals.
  2773. */
  2774. if (flags & (LEFTPRESS|LEFTRELEASE|RIGHTPRESS|RIGHTRELEASE)) {
  2775. x = Keyboard->MouseQX;
  2776. y = Keyboard->MouseQY;
  2777. } else {
  2778. x = Get_Mouse_X();
  2779. y = Get_Mouse_Y();
  2780. }
  2781. bool edge = (y == 0 || x == 0 || x == SeenBuff.Get_Width()-1 || y == SeenBuff.Get_Height()-1);
  2782. COORDINATE coord = Map.Pixel_To_Coord(x, y);
  2783. CELL cell = Coord_Cell(coord);
  2784. if (coord) {
  2785. //shadow = (!Map[cell].IsMapped && !Debug_Unshroud);
  2786. shadow = (!Map[cell].Is_Mapped(PlayerPtr) && !Debug_Unshroud); // Use PlayerPtr since we won't be rendering in MP. ST - 8/6/2019 10:49AM
  2787. x -= Map.TacPixelX;
  2788. y -= Map.TacPixelY;
  2789. /*
  2790. ** Cause any displayed cursor to move along with the mouse cursor.
  2791. */
  2792. if (cell != Map.ZoneCell) {
  2793. Map.Set_Cursor_Pos(cell);
  2794. }
  2795. /*
  2796. ** Determine the object that the mouse is currently over.
  2797. */
  2798. if (!shadow) {
  2799. object = Map.Close_Object(coord);
  2800. /*
  2801. ** Special case check to ignore cloaked object if not allied with the player.
  2802. */
  2803. if (object != NULL && object->Is_Techno() && ((TechnoClass *)object)->Is_Cloaked(PlayerPtr, true)) {
  2804. object = NULL;
  2805. }
  2806. }
  2807. /*
  2808. ** If there is a currently selected object, then the action to perform if
  2809. ** the left mouse button were clicked must be determined.
  2810. */
  2811. if (CurrentObject.Count()) {
  2812. if (object != NULL) {
  2813. action = Best_Object_Action(object);
  2814. } else {
  2815. action = Best_Object_Action(cell);
  2816. }
  2817. } else {
  2818. if (object && object->Class_Of().IsSelectable) {
  2819. action = ACTION_SELECT;
  2820. }
  2821. if (Map.IsRepairMode) {
  2822. if (object && object->Owner() == PlayerPtr->Class->House && object->Can_Repair()) {
  2823. action = ACTION_REPAIR;
  2824. } else {
  2825. action = ACTION_NO_REPAIR;
  2826. }
  2827. }
  2828. if (Map.IsSellMode) {
  2829. if (object && object->Owner() == PlayerPtr->Class->House && object->Can_Demolish()) {
  2830. if (object->What_Am_I() == RTTI_BUILDING) {
  2831. action = ACTION_SELL;
  2832. } else {
  2833. action = ACTION_SELL_UNIT;
  2834. }
  2835. } else {
  2836. /*
  2837. ** Check to see if the cursor is over an owned wall.
  2838. */
  2839. if (Map[cell].Overlay != OVERLAY_NONE &&
  2840. OverlayTypeClass::As_Reference(Map[cell].Overlay).IsWall &&
  2841. Map[cell].Owner == PlayerPtr->Class->House) {
  2842. action = ACTION_SELL;
  2843. } else {
  2844. action = ACTION_NO_SELL;
  2845. }
  2846. }
  2847. }
  2848. if (Map.IsTargettingMode == SPC_NUCLEAR_BOMB) {
  2849. action = ACTION_NUKE_BOMB;
  2850. }
  2851. if (Map.IsTargettingMode == SPC_PARA_BOMB) {
  2852. action = ACTION_PARA_BOMB;
  2853. }
  2854. if (Map.IsTargettingMode == SPC_PARA_INFANTRY) {
  2855. action = ACTION_PARA_INFANTRY;
  2856. }
  2857. if (Map.IsTargettingMode == SPC_SPY_MISSION) {
  2858. action = ACTION_SPY_MISSION;
  2859. }
  2860. if (Map.IsTargettingMode == SPC_IRON_CURTAIN) {
  2861. action = ACTION_IRON_CURTAIN;
  2862. }
  2863. if (Map.IsTargettingMode == SPC_CHRONOSPHERE) {
  2864. action = ACTION_CHRONOSPHERE;
  2865. }
  2866. if (Map.IsTargettingMode == SPC_CHRONO2) {
  2867. action = ACTION_CHRONO2;
  2868. if (shadow) action = ACTION_NOMOVE;
  2869. ObjectClass const * tobject = As_Object(PlayerPtr->UnitToTeleport);
  2870. /*
  2871. ** Determine if the object can be teleported to the destination cell.
  2872. */
  2873. if (tobject != NULL && tobject->Is_Techno()) {
  2874. TechnoClass const * uobject = (TechnoClass const *)tobject;
  2875. if (!uobject->Can_Teleport_Here(cell)) {
  2876. // if (((UnitClass *)As_Object(PlayerPtr->UnitToTeleport))->Can_Enter_Cell(cell, FACING_NONE) != MOVE_OK) {
  2877. action = ACTION_NOMOVE;
  2878. }
  2879. }
  2880. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2881. else { // If the object is no longer valid, cancel targetting mode.
  2882. action = ACTION_NOMOVE;
  2883. Map.IsTargettingMode = SPC_NONE;
  2884. }
  2885. #endif
  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(cell, 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_Up(cell, shadow, object, action);
  2935. Map.Mouse_Left_Press(x, y);
  2936. }
  2937. /*
  2938. ** While the mouse is being held down, determine if rubber band mode should
  2939. ** start. If rubber band mode is already active, then update the size
  2940. ** and flag the map to redraw it.
  2941. */
  2942. if (flags & LEFTHELD) {
  2943. Map.Mouse_Left_Held(x, y);
  2944. }
  2945. }
  2946. return(GadgetClass::Action(0, key));
  2947. }
  2948. /***********************************************************************************************
  2949. * DisplayClass::TacticalClass::Selection_At_Mouse -- Object selection *
  2950. * *
  2951. * Selects any objects at the current mouse position. *
  2952. * *
  2953. * *
  2954. * INPUT: flags -- The gadget event flags that triggered the call to this function. *
  2955. * *
  2956. * key -- A reference to the keyboard event (if any). *
  2957. * *
  2958. * OUTPUT: bool; Should processing be aborted on any succeeding buttons in the chain? *
  2959. * *
  2960. * WARNINGS: none *
  2961. * *
  2962. * HISTORY: *
  2963. * 2019/09/17 JAS *
  2964. *=============================================================================================*/
  2965. int DisplayClass::TacticalClass::Selection_At_Mouse(unsigned flags, KeyNumType & key)
  2966. {
  2967. int x, y; // Sub cell pixel coordinates.
  2968. bool edge = false;
  2969. if (flags & (LEFTPRESS | LEFTRELEASE | RIGHTPRESS | RIGHTRELEASE)) {
  2970. x = Keyboard->MouseQX;
  2971. y = Keyboard->MouseQY;
  2972. }
  2973. else {
  2974. x = Get_Mouse_X();
  2975. y = Get_Mouse_Y();
  2976. if (x == 0 || y == 199 || x == 319) edge = true;
  2977. }
  2978. COORDINATE coord = Map.Pixel_To_Coord(x, y);
  2979. CELL cell = Coord_Cell(coord);
  2980. if (coord) {
  2981. 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
  2982. x -= Map.TacPixelX;
  2983. y -= Map.TacPixelY;
  2984. /*
  2985. ** Cause any displayed cursor to move along with the mouse cursor.
  2986. */
  2987. if (cell != Map.ZoneCell) {
  2988. Map.Set_Cursor_Pos(cell);
  2989. }
  2990. ObjectClass* object = nullptr;
  2991. /*
  2992. ** Determine the object that the mouse is currently over.
  2993. */
  2994. if (!shadow) {
  2995. object = Map.Close_Object(coord);
  2996. }
  2997. if (object != nullptr)
  2998. {
  2999. bool shiftdown = DLL_Export_Get_Input_Key_State(KN_LSHIFT);
  3000. if (shiftdown)
  3001. {
  3002. Map.Mouse_Left_Release(cell, x, y, object, ACTION_TOGGLE_SELECT);
  3003. }
  3004. else
  3005. {
  3006. Map.Mouse_Left_Release(cell, x, y, object, ACTION_SELECT);
  3007. }
  3008. }
  3009. else
  3010. {
  3011. Unselect_All();
  3012. }
  3013. }
  3014. return 0;
  3015. }
  3016. /***********************************************************************************************
  3017. * DisplayClass::TacticalClass::Command_Object -- Commanding Units *
  3018. * *
  3019. * Issues a command to the currently selected unit. *
  3020. * *
  3021. * *
  3022. * INPUT: flags -- The gadget event flags that triggered the call to this function. *
  3023. * *
  3024. * key -- A reference to the keyboard event (if any). *
  3025. * *
  3026. * OUTPUT: bool; Should processing be aborted on any succeeding buttons in the chain? *
  3027. * *
  3028. * WARNINGS: none *
  3029. * *
  3030. * HISTORY: *
  3031. * 2019/09/17 JAS *
  3032. *=============================================================================================*/
  3033. int DisplayClass::TacticalClass::Command_Object(unsigned flags, KeyNumType & key)
  3034. {
  3035. int x, y; // Sub cell pixel coordinates.
  3036. bool edge = false;
  3037. if (flags & (LEFTPRESS | LEFTRELEASE | RIGHTPRESS | RIGHTRELEASE)) {
  3038. x = Keyboard->MouseQX;
  3039. y = Keyboard->MouseQY;
  3040. }
  3041. else {
  3042. x = Get_Mouse_X();
  3043. y = Get_Mouse_Y();
  3044. if (x == 0 || y == 199 || x == 319) edge = true;
  3045. }
  3046. COORDINATE coord = Map.Pixel_To_Coord(x, y);
  3047. CELL cell = Coord_Cell(coord);
  3048. ActionType action = ACTION_NONE;
  3049. if (coord) {
  3050. bool shadow = (!Map[cell].Is_Mapped(PlayerPtr) && !Debug_Unshroud); // Use PlayerPtr since we won't be rendering in MP. ST - 3/6/2019 2:49PM
  3051. x -= Map.TacPixelX;
  3052. y -= Map.TacPixelY;
  3053. /*
  3054. ** Cause any displayed cursor to move along with the mouse cursor.
  3055. */
  3056. if (cell != Map.ZoneCell) {
  3057. Map.Set_Cursor_Pos(cell);
  3058. }
  3059. ObjectClass* object = nullptr;
  3060. /*
  3061. ** Determine the object that the mouse is currently over.
  3062. */
  3063. if (!shadow) {
  3064. object = Map.Close_Object(coord);
  3065. }
  3066. if (CurrentObject.Count()) {
  3067. if (object) {
  3068. action = Best_Object_Action(object);
  3069. }
  3070. else {
  3071. action = Best_Object_Action(cell);
  3072. }
  3073. }
  3074. if (action != ACTION_SELECT)
  3075. {
  3076. Map.Mouse_Left_Release(cell, x, y, object, action);
  3077. }
  3078. }
  3079. return 0;
  3080. }
  3081. /***********************************************************************************************
  3082. * DisplayClass::Mouse_Right_Press -- Handles the right mouse button press. *
  3083. * *
  3084. * This routine is called when the right mouse button is pressed. This action is supposed *
  3085. * to cancel whatever mode or process is active. If there is nothing to cancel, then it *
  3086. * will default to unselecting any units that might be currently selected. *
  3087. * *
  3088. * INPUT: none *
  3089. * *
  3090. * OUTPUT: none *
  3091. * *
  3092. * WARNINGS: none *
  3093. * *
  3094. * HISTORY: *
  3095. * 02/24/1995 JLB : Created. *
  3096. *=============================================================================================*/
  3097. void DisplayClass::Mouse_Right_Press(void)
  3098. {
  3099. if (PendingObjectPtr && PendingObjectPtr->Is_Techno()) {
  3100. //PendingObjectPtr->Transmit_Message(RADIO_OVER_OUT);
  3101. PendingObjectPtr = 0;
  3102. PendingObject = 0;
  3103. PendingHouse = HOUSE_NONE;
  3104. Set_Cursor_Shape(0);
  3105. } else {
  3106. if (IsRepairMode) {
  3107. IsRepairMode = false;
  3108. } else {
  3109. if (IsSellMode) {
  3110. IsSellMode = false;
  3111. } else {
  3112. if (IsTargettingMode != SPC_NONE) {
  3113. IsTargettingMode = SPC_NONE;
  3114. } else {
  3115. Unselect_All();
  3116. }
  3117. }
  3118. }
  3119. }
  3120. // If it breaks... call 228.
  3121. Set_Default_Mouse(MOUSE_NORMAL, Map.IsSmall);
  3122. }
  3123. /***********************************************************************************************
  3124. * DisplayClass::Mouse_Left_Up -- Handles the left mouse "cruising" over the map. *
  3125. * *
  3126. * This routine is called continuously while the mouse is over the tactical map but there *
  3127. * are no mouse buttons pressed. Typically, this adjusts the mouse shape and the pop-up *
  3128. * help text. *
  3129. * *
  3130. * INPUT: shadow -- Is the mouse hovering over shadowed terrain? *
  3131. * *
  3132. * object -- Pointer to the object that the mouse is currently over (may be NULL). *
  3133. * *
  3134. * action -- This is the action that the currently selected object (if any) will *
  3135. * perform if the left mouse button were clicked at this location. *
  3136. * *
  3137. * OUTPUT: none *
  3138. * *
  3139. * WARNINGS: none *
  3140. * *
  3141. * HISTORY: *
  3142. * 02/24/1995 JLB : Created. *
  3143. * 07/05/1995 JLB : Removed pop up help text for shadow and terrain after #3. *
  3144. *=============================================================================================*/
  3145. void DisplayClass::Mouse_Left_Up(CELL cell, bool shadow, ObjectClass * object, ActionType action, bool wsmall)
  3146. {
  3147. IsTentative = false;
  3148. TARGET target = TARGET_NONE;
  3149. if (object != NULL) {
  3150. target = object->As_Target();
  3151. } else {
  3152. if (cell != -1) {
  3153. target = As_Target(cell);
  3154. }
  3155. }
  3156. /*
  3157. ** Don't allow selection of an object that is located in shadowed terrain.
  3158. ** In fact, just show the normal move cursor in order to keep the shadowed
  3159. ** terrain a mystery.
  3160. */
  3161. if (shadow) {
  3162. switch (action) {
  3163. case ACTION_NO_DEPLOY:
  3164. Set_Default_Mouse(MOUSE_NO_DEPLOY, wsmall);
  3165. break;
  3166. case ACTION_NO_ENTER:
  3167. Set_Default_Mouse(MOUSE_NO_ENTER, wsmall);
  3168. break;
  3169. case ACTION_NO_GREPAIR:
  3170. Set_Default_Mouse(MOUSE_NO_GREPAIR, wsmall);
  3171. break;
  3172. case ACTION_DAMAGE:
  3173. Set_Default_Mouse(MOUSE_NORMAL, wsmall);
  3174. break;
  3175. case ACTION_GREPAIR:
  3176. Set_Default_Mouse(MOUSE_NORMAL, wsmall);
  3177. break;
  3178. case ACTION_GUARD_AREA:
  3179. Set_Default_Mouse(MOUSE_AREA_GUARD, wsmall);
  3180. break;
  3181. case ACTION_NONE:
  3182. Set_Default_Mouse(MOUSE_NORMAL, wsmall);
  3183. break;
  3184. case ACTION_NO_SELL:
  3185. case ACTION_SELL:
  3186. case ACTION_SELL_UNIT:
  3187. Set_Default_Mouse(MOUSE_NO_SELL_BACK, wsmall);
  3188. break;
  3189. case ACTION_NO_REPAIR:
  3190. case ACTION_REPAIR:
  3191. Set_Default_Mouse(MOUSE_NO_REPAIR, wsmall);
  3192. break;
  3193. case ACTION_NUKE_BOMB:
  3194. Set_Default_Mouse(MOUSE_NUCLEAR_BOMB, wsmall);
  3195. break;
  3196. case ACTION_AIR_STRIKE:
  3197. case ACTION_PARA_BOMB:
  3198. case ACTION_PARA_INFANTRY:
  3199. case ACTION_SPY_MISSION:
  3200. case ACTION_IRON_CURTAIN:
  3201. Set_Default_Mouse(MOUSE_AIR_STRIKE, wsmall);
  3202. break;
  3203. case ACTION_CHRONOSPHERE:
  3204. Set_Default_Mouse(MOUSE_CHRONO_SELECT, wsmall);
  3205. break;
  3206. case ACTION_CHRONO2:
  3207. Set_Default_Mouse(MOUSE_CHRONO_DEST, wsmall);
  3208. break;
  3209. case ACTION_HEAL:
  3210. Set_Default_Mouse(MOUSE_HEAL, wsmall);
  3211. break;
  3212. case ACTION_NOMOVE:
  3213. if (CurrentObject.Count()) {
  3214. MouseType mouse_type = MOUSE_NO_MOVE;
  3215. for (int i = 0; i < CurrentObject.Count(); ++i) {
  3216. if (CurrentObject[i]->What_Am_I() != RTTI_AIRCRAFT) {
  3217. mouse_type = MOUSE_CAN_MOVE;
  3218. break;
  3219. }
  3220. }
  3221. Set_Default_Mouse(mouse_type, wsmall);
  3222. break;
  3223. }
  3224. // Fall into next case for non aircraft object types.
  3225. default:
  3226. Set_Default_Mouse(MOUSE_CAN_MOVE, wsmall);
  3227. break;
  3228. }
  3229. } else {
  3230. /*
  3231. ** Change the mouse shape according to the default action that will occur
  3232. ** if the mouse button were clicked at this location.
  3233. */
  3234. switch (action) {
  3235. case ACTION_NO_DEPLOY:
  3236. Set_Default_Mouse(MOUSE_NO_DEPLOY, wsmall);
  3237. break;
  3238. case ACTION_NO_ENTER:
  3239. Set_Default_Mouse(MOUSE_NO_ENTER, wsmall);
  3240. break;
  3241. case ACTION_NO_GREPAIR:
  3242. Set_Default_Mouse(MOUSE_NO_GREPAIR, wsmall);
  3243. break;
  3244. case ACTION_DAMAGE:
  3245. Set_Default_Mouse(MOUSE_DAMAGE, wsmall);
  3246. break;
  3247. case ACTION_GREPAIR:
  3248. Set_Default_Mouse(MOUSE_GREPAIR, wsmall);
  3249. break;
  3250. case ACTION_TOGGLE_SELECT:
  3251. case ACTION_SELECT:
  3252. Set_Default_Mouse(MOUSE_CAN_SELECT, wsmall);
  3253. break;
  3254. case ACTION_MOVE:
  3255. Set_Default_Mouse(MOUSE_CAN_MOVE, wsmall);
  3256. break;
  3257. case ACTION_GUARD_AREA:
  3258. Set_Default_Mouse(MOUSE_AREA_GUARD, wsmall);
  3259. break;
  3260. case ACTION_ATTACK:
  3261. if (Target_Legal(target) && CurrentObject.Count() == 1 && CurrentObject[0]->Is_Techno() && ((TechnoClass *)CurrentObject[0])->In_Range(target, 0)) {
  3262. Set_Default_Mouse(MOUSE_STAY_ATTACK, wsmall);
  3263. break;
  3264. }
  3265. // fall into next case.
  3266. case ACTION_HARVEST:
  3267. Set_Default_Mouse(MOUSE_CAN_ATTACK, wsmall);
  3268. break;
  3269. case ACTION_SABOTAGE:
  3270. Set_Default_Mouse(MOUSE_DEMOLITIONS, wsmall);
  3271. break;
  3272. case ACTION_ENTER:
  3273. case ACTION_CAPTURE:
  3274. Set_Default_Mouse(MOUSE_ENTER, wsmall);
  3275. break;
  3276. case ACTION_NOMOVE:
  3277. Set_Default_Mouse(MOUSE_NO_MOVE, wsmall);
  3278. break;
  3279. case ACTION_NO_SELL:
  3280. Set_Default_Mouse(MOUSE_NO_SELL_BACK, wsmall);
  3281. break;
  3282. case ACTION_NO_REPAIR:
  3283. Set_Default_Mouse(MOUSE_NO_REPAIR, wsmall);
  3284. break;
  3285. case ACTION_SELF:
  3286. Set_Default_Mouse(MOUSE_DEPLOY, wsmall);
  3287. break;
  3288. case ACTION_REPAIR:
  3289. Set_Default_Mouse(MOUSE_REPAIR, wsmall);
  3290. break;
  3291. case ACTION_SELL_UNIT:
  3292. Set_Default_Mouse(MOUSE_SELL_UNIT, wsmall);
  3293. break;
  3294. case ACTION_SELL:
  3295. Set_Default_Mouse(MOUSE_SELL_BACK, wsmall);
  3296. break;
  3297. case ACTION_NUKE_BOMB:
  3298. Set_Default_Mouse(MOUSE_NUCLEAR_BOMB, wsmall);
  3299. break;
  3300. case ACTION_AIR_STRIKE:
  3301. case ACTION_PARA_BOMB:
  3302. case ACTION_PARA_INFANTRY:
  3303. case ACTION_SPY_MISSION:
  3304. case ACTION_IRON_CURTAIN:
  3305. Set_Default_Mouse(MOUSE_AIR_STRIKE, wsmall);
  3306. break;
  3307. case ACTION_CHRONOSPHERE:
  3308. Set_Default_Mouse(MOUSE_CHRONO_SELECT, wsmall);
  3309. break;
  3310. case ACTION_CHRONO2:
  3311. Set_Default_Mouse(MOUSE_CHRONO_DEST, wsmall);
  3312. break;
  3313. case ACTION_HEAL:
  3314. Set_Default_Mouse(MOUSE_HEAL, wsmall);
  3315. break;
  3316. case ACTION_TOGGLE_PRIMARY:
  3317. Set_Default_Mouse(MOUSE_DEPLOY, wsmall);
  3318. break;
  3319. default:
  3320. Set_Default_Mouse(MOUSE_NORMAL, wsmall);
  3321. break;
  3322. }
  3323. }
  3324. #if 0
  3325. /*
  3326. ** Never display help text if the mouse is held over the radar map.
  3327. */
  3328. if (wsmall) {
  3329. return;
  3330. }
  3331. /*
  3332. ** Give a generic help message when over shadow terrain.
  3333. */
  3334. if (shadow) {
  3335. // if (Scen.Scenario < 4) {
  3336. Help_Text(TXT_SHADOW);
  3337. // } else {
  3338. // Help_Text(TXT_NONE);
  3339. // }
  3340. } else {
  3341. /*
  3342. ** If the mouse is held over objects on the map, then help text may
  3343. ** pop up that tells what the object is. This call informs the help
  3344. ** system of the text name for the object under the mouse.
  3345. */
  3346. if (object != NULL) {
  3347. int text;
  3348. int color = LTGREY;
  3349. /*
  3350. ** Fetch the appropriate background color for help text.
  3351. */
  3352. if (PlayerPtr->Is_Ally(object)) {
  3353. color = GREEN;
  3354. } else {
  3355. if (object->Owner() == HOUSE_NONE || object->Owner() == HOUSE_NEUTRAL) {
  3356. color = LTGREY;
  3357. } else {
  3358. color = PINK;
  3359. }
  3360. }
  3361. /*
  3362. ** Fetch the name of the object. If it is an enemy object, then
  3363. ** the exact identity is glossed over with a generic text.
  3364. */
  3365. text = object->Full_Name();
  3366. if (object->Is_Techno() && !((TechnoTypeClass const &)object->Class_Of()).IsNominal) {
  3367. if (!((TechnoClass *)object)->House->Is_Ally(PlayerPtr)) {
  3368. // if (!PlayerPtr->Is_Ally(object)) {
  3369. switch (object->What_Am_I()) {
  3370. case RTTI_INFANTRY:
  3371. text = TXT_ENEMY_SOLDIER;
  3372. break;
  3373. case RTTI_UNIT:
  3374. text = TXT_ENEMY_VEHICLE;
  3375. break;
  3376. case RTTI_BUILDING:
  3377. text = TXT_ENEMY_STRUCTURE;
  3378. break;
  3379. }
  3380. }
  3381. }
  3382. if (/*Scen.Scenario > 3 ||*/ object->What_Am_I() != RTTI_TERRAIN) {
  3383. Help_Text(text, -1, -1, color);
  3384. } else {
  3385. Help_Text(TXT_NONE);
  3386. }
  3387. } else {
  3388. if ((*this)[cell].Land_Type() == LAND_TIBERIUM) {
  3389. Help_Text(TXT_MINERALS);
  3390. } else {
  3391. Help_Text(TXT_NONE);
  3392. }
  3393. }
  3394. }
  3395. #endif
  3396. }
  3397. /***********************************************************************************************
  3398. * DisplayClass::Mouse_Left_Release -- Handles the left mouse button release. *
  3399. * *
  3400. * This routine is called when the left mouse button is released over the tactical map. *
  3401. * The release event is the workhorse of the game. Most actions occur at the moment of *
  3402. * mouse release. *
  3403. * *
  3404. * INPUT: cell -- The cell that the mouse is over. *
  3405. * *
  3406. * x,y -- The mouse pixel coordinate. *
  3407. * *
  3408. * object -- Pointer to the object that the mouse is over. *
  3409. * *
  3410. * action -- The action that the currently selected object (if any) will *
  3411. * perform. *
  3412. * *
  3413. * OUTPUT: none *
  3414. * *
  3415. * WARNINGS: none *
  3416. * *
  3417. * HISTORY: *
  3418. * 02/24/1995 JLB : Created. *
  3419. * 03/27/1995 JLB : Handles sell and repair actions. *
  3420. *=============================================================================================*/
  3421. void DisplayClass::Mouse_Left_Release(CELL cell, int x, int y, ObjectClass * object, ActionType action, bool wsmall)
  3422. {
  3423. if (PendingObjectPtr) {
  3424. /*
  3425. ** Try to place the pending object onto the map.
  3426. */
  3427. if (ProximityCheck) {
  3428. OutList.Add(EventClass(EventClass::PLACE, PendingObjectPtr->What_Am_I(), cell + ZoneOffset));
  3429. } else {
  3430. Speak(VOX_DEPLOY);
  3431. }
  3432. } else {
  3433. if (IsRubberBand) {
  3434. Refresh_Band();
  3435. Select_These(XYP_Coord(BandX, BandY), XYP_Coord(x, y));
  3436. Set_Default_Mouse(MOUSE_NORMAL, wsmall);
  3437. IsRubberBand = false;
  3438. IsTentative = false;
  3439. Map.DisplayClass::IsToRedraw = true;
  3440. Map.Flag_To_Redraw(false);
  3441. } else {
  3442. /*
  3443. ** Toggle the select state of the object.
  3444. */
  3445. if (action == ACTION_TOGGLE_SELECT) {
  3446. if (!object || !CurrentObject.Count()) {
  3447. action = ACTION_SELECT;
  3448. } else {
  3449. if (object->Is_Selected_By_Player()) {
  3450. object->Unselect();
  3451. } else {
  3452. object->Select();
  3453. }
  3454. }
  3455. }
  3456. /*
  3457. ** Selection of other object action.
  3458. */
  3459. if (action == ACTION_SELECT || (action == ACTION_NONE && object && object->Class_Of().IsSelectable && !object->Is_Selected_By_Player())) {
  3460. if (object->Is_Selected_By_Player()) {
  3461. object->Unselect();
  3462. }
  3463. if (object->Select()) {
  3464. Unselect_All_Except(object);
  3465. Set_Default_Mouse(MOUSE_NORMAL, wsmall);
  3466. }
  3467. }
  3468. /*
  3469. ** If an action was detected as possible, then pass this action event
  3470. ** to all selected objects.
  3471. */
  3472. if (action != ACTION_NONE && action != ACTION_SELECT && action != ACTION_TOGGLE_SELECT) {
  3473. /*
  3474. ** Pass the action to all the selected objects. But first, redetermine
  3475. ** what action that object should perform. This, seemingly redundant
  3476. ** process, is necessary since multiple objects could be selected and each
  3477. ** might perform a different action when the click occurs.
  3478. */
  3479. bool doflash = true;
  3480. AllowVoice = true;
  3481. FormMove = false;
  3482. FormSpeed = SPEED_WHEEL;
  3483. FormMaxSpeed = MPH_LIGHT_SPEED;
  3484. if ( (action == ACTION_MOVE || action == ACTION_NOMOVE) && CurrentObject.Count()) {
  3485. /*
  3486. ** Scan all units. If any are selected that shouldn't be, or aren't
  3487. ** selected but should be, then this is not a formation move.
  3488. */
  3489. int group = 254; // init to invalid group #
  3490. if (CurrentObject[0]->Is_Foot()) {
  3491. group = ((FootClass *)CurrentObject[0])->Group;
  3492. }
  3493. /*
  3494. ** Presume this is a formation move unless something is detected
  3495. ** that will prevent it.
  3496. */
  3497. FormMove = true;
  3498. /*
  3499. ** First scan through all the selected units to make sure that they
  3500. ** are all of the same team and have been assigned a particular formation
  3501. */
  3502. for (int index = 0; index < CurrentObject.Count(); index++) {
  3503. ObjectClass const * tobject = CurrentObject[index];
  3504. /*
  3505. ** Only moveable (i.e., FootClass) objects can ever be in a formation
  3506. ** so if a selected object isn't of a FootClass type then it can't be
  3507. ** a formation move.
  3508. */
  3509. if (tobject->Is_Foot() == false) {
  3510. FormMove = false;
  3511. break;
  3512. }
  3513. /*
  3514. ** If the object is not part of the same team as the rest of the
  3515. ** selected group, or it just plain has never been assigned a
  3516. ** formation offset, then it can't be a formation move.
  3517. */
  3518. FootClass const * foot = (FootClass *)tobject;
  3519. if (foot->Group != group || foot->XFormOffset == 0x80000000) {
  3520. FormMove = false;
  3521. break;
  3522. }
  3523. /*
  3524. ** Determine the formation speed on the presumption that this
  3525. ** will turn out to be a formation move.
  3526. */
  3527. MPHType maxspeed = foot->Techno_Type_Class()->MaxSpeed;
  3528. if (maxspeed < FormMaxSpeed) {
  3529. FormMaxSpeed = maxspeed;
  3530. FormSpeed = foot->Techno_Type_Class()->Speed;
  3531. }
  3532. }
  3533. /*
  3534. ** Loop through all objects (that can theoretically be part of a team) and
  3535. ** if there are any that are part of the currently selected team, but
  3536. ** are not currently selected themselves, then this will force this move
  3537. ** to NOT be a formation move.
  3538. */
  3539. if (FormMove) {
  3540. for (int index = 0; index < ::Logic.Count(); index++) {
  3541. ObjectClass const * obj = ::Logic[index];
  3542. /*
  3543. ** If the object is selected, then it has already been scanned
  3544. ** by the previous loop.
  3545. */
  3546. if (obj->Is_Selected_By_Player()) continue;
  3547. /*
  3548. ** Only consider footclass objects.
  3549. */
  3550. if (!obj->Is_Foot()) continue;
  3551. FootClass const * foot = (FootClass *)obj;
  3552. /*
  3553. ** Only consider objects that are owned by the player.
  3554. */
  3555. if (!foot->Is_Owned_By_Player()) continue;
  3556. /*
  3557. ** If another member of this team has been discovered and
  3558. ** it isn't selected, then the formation move cannot take
  3559. ** place.
  3560. */
  3561. if (foot->Group == group) {
  3562. FormMove = false;
  3563. break;
  3564. }
  3565. }
  3566. }
  3567. }
  3568. for (int index = 0; index < CurrentObject.Count(); index++) {
  3569. ObjectClass * tobject = CurrentObject[index];
  3570. if (object != NULL) {
  3571. tobject->Active_Click_With(tobject->What_Action(object), object);
  3572. } else {
  3573. /*
  3574. ** Trap for formation moves: if this unit is part of a
  3575. ** formation (being part of a team qualifies) and they're
  3576. ** told to move, adjust the target destination so they stay
  3577. ** in formation when they arrive.
  3578. */
  3579. CELL newmove = cell;
  3580. int whatami = tobject->What_Am_I();
  3581. if (action == ACTION_MOVE && tobject->Is_Foot()) {
  3582. int oldisform;
  3583. FootClass * foot = (FootClass *)tobject;
  3584. oldisform = foot->IsFormationMove;
  3585. foot->IsFormationMove = FormMove;
  3586. if (FormMove && foot->Group != 255 ) {
  3587. newmove = foot->Adjust_Dest(cell);
  3588. }
  3589. foot->IsFormationMove = oldisform;
  3590. }
  3591. tobject->Active_Click_With(tobject->What_Action(cell), newmove);
  3592. }
  3593. AllowVoice = false;
  3594. }
  3595. AllowVoice = true;
  3596. FormMove = false;
  3597. if (action == ACTION_REPAIR && object->What_Am_I() == RTTI_BUILDING) {
  3598. OutList.Add(EventClass(EventClass::REPAIR, TargetClass(object)));
  3599. }
  3600. if (action == ACTION_SELL_UNIT && object) {
  3601. switch (object->What_Am_I()) {
  3602. case RTTI_AIRCRAFT:
  3603. case RTTI_UNIT:
  3604. OutList.Add(EventClass(EventClass::SELL, TargetClass(object)));
  3605. break;
  3606. default:
  3607. break;
  3608. }
  3609. }
  3610. if (action == ACTION_SELL) {
  3611. if (object) {
  3612. OutList.Add(EventClass(EventClass::SELL, TargetClass(object)));
  3613. } else {
  3614. OutList.Add(EventClass(EventClass::SELLCELL, cell));
  3615. // OutList.Add(EventClass(EventClass::SELL, ::As_Target(cell)));
  3616. }
  3617. }
  3618. if (action == ACTION_NUKE_BOMB) {
  3619. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_NUCLEAR_BOMB, cell));
  3620. }
  3621. if (action == ACTION_PARA_BOMB) {
  3622. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_PARA_BOMB, cell));
  3623. }
  3624. if (action == ACTION_PARA_INFANTRY) {
  3625. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_PARA_INFANTRY, cell));
  3626. }
  3627. if (action == ACTION_SPY_MISSION) {
  3628. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_SPY_MISSION, cell));
  3629. }
  3630. if (action == ACTION_IRON_CURTAIN) {
  3631. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_IRON_CURTAIN, cell));
  3632. }
  3633. if (action == ACTION_CHRONOSPHERE) {
  3634. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_CHRONOSPHERE, cell));
  3635. }
  3636. if (action == ACTION_CHRONO2) {
  3637. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_CHRONO2, cell));
  3638. }
  3639. }
  3640. IsTentative = false;
  3641. }
  3642. }
  3643. }
  3644. /***********************************************************************************************
  3645. * DisplayClass::Mouse_Left_Press -- Handles the left mouse button press. *
  3646. * *
  3647. * Handle the left mouse button press while over the tactical map. If it isn't is *
  3648. * repair or sell mode, then a tentative transition to rubber band mode is flagged. If the *
  3649. * mouse moves a sufficient distance from this recorded position, then rubber band mode *
  3650. * is officially started. *
  3651. * *
  3652. * INPUT: x,y -- The mouse coordinates at the time of the press. *
  3653. * *
  3654. * OUTPUT: none *
  3655. * *
  3656. * WARNINGS: none *
  3657. * *
  3658. * HISTORY: *
  3659. * 02/24/1995 JLB : Created. *
  3660. *=============================================================================================*/
  3661. void DisplayClass::Mouse_Left_Press(int x, int y)
  3662. {
  3663. if (!IsRepairMode && !IsSellMode && IsTargettingMode == SPC_NONE && !PendingObject) {
  3664. IsTentative = true;
  3665. BandX = x;
  3666. BandY = y;
  3667. NewX = x;
  3668. NewY = y;
  3669. }
  3670. }
  3671. /***********************************************************************************************
  3672. * DisplayClass::Mouse_Left_Held -- Handles the left button held down. *
  3673. * *
  3674. * This routine is called continuously while the left mouse button is held down over *
  3675. * the tactical map. This handles the rubber band mode detection and dragging. *
  3676. * *
  3677. * INPUT: x,y -- The mouse coordinate. *
  3678. * *
  3679. * OUTPUT: none *
  3680. * *
  3681. * WARNINGS: none *
  3682. * *
  3683. * HISTORY: *
  3684. * 02/24/1995 JLB : Created. *
  3685. *=============================================================================================*/
  3686. void DisplayClass::Mouse_Left_Held(int x, int y)
  3687. {
  3688. if (IsRubberBand) {
  3689. if (x != NewX || y != NewY) {
  3690. x = Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1);
  3691. y = Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1);
  3692. Refresh_Band();
  3693. NewX = x;
  3694. NewY = y;
  3695. IsToRedraw = true;
  3696. Flag_To_Redraw(false);
  3697. }
  3698. } else {
  3699. /*
  3700. ** If the mouse is still held down while a tentative extended select is possible, then
  3701. ** check to see if the mouse has moved a sufficient distance in order to activate
  3702. ** extended select mode.
  3703. */
  3704. if (IsTentative) {
  3705. /*
  3706. ** The mouse must have moved a minimum distance before rubber band mode can be
  3707. ** initiated.
  3708. */
  3709. if (ABS(x - BandX) > 4 || ABS(y - BandY) > 4) {
  3710. IsRubberBand = true;
  3711. x = Bound(x, 0, Lepton_To_Pixel(TacLeptonWidth)-1);
  3712. y = Bound(y, 0, Lepton_To_Pixel(TacLeptonHeight)-1);
  3713. NewX = x;
  3714. NewY = y;
  3715. IsToRedraw = true;
  3716. Flag_To_Redraw(false);
  3717. /*
  3718. ** Stretching the rubber band requires all objects to be redrawn.
  3719. */
  3720. int index;
  3721. for (index = 0; index < Layer[LAYER_TOP].Count(); index++) {
  3722. Layer[LAYER_TOP][index]->Mark(MARK_CHANGE);
  3723. }
  3724. for (index = 0; index < Layer[LAYER_AIR].Count(); index++) {
  3725. Layer[LAYER_AIR][index]->Mark(MARK_CHANGE);
  3726. }
  3727. }
  3728. }
  3729. }
  3730. }
  3731. // Needed to accomodate Glyphx client sidebar. ST - 4/12/2019 5:29PM
  3732. extern int GlyphXClientSidebarWidthInLeptons;
  3733. /***********************************************************************************************
  3734. * DisplayClass::Set_Tactical_Position -- Sets the tactical view position. *
  3735. * *
  3736. * This routine is used to set the tactical view position. The requested position is *
  3737. * clipped to the map dimensions as necessary. *
  3738. * *
  3739. * INPUT: coord -- The coordinate desired for the upper left corner. *
  3740. * *
  3741. * OUTPUT: none *
  3742. * *
  3743. * WARNINGS: none *
  3744. * *
  3745. * HISTORY: *
  3746. * 08/13/1995 JLB : Created. *
  3747. *=============================================================================================*/
  3748. void DisplayClass::Set_Tactical_Position(COORDINATE coord)
  3749. {
  3750. /*
  3751. ** Bound the desired location to fit the legal map edges.
  3752. */
  3753. int xx = 0;// (int)Coord_X(coord) - (int)Cell_To_Lepton(MapCellX);
  3754. int yy = 0;// (int)Coord_Y(coord) - (int)Cell_To_Lepton(MapCellY);
  3755. 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
  3756. // Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, Cell_To_Lepton(MapCellWidth), Cell_To_Lepton(MapCellHeight));
  3757. coord = XY_Coord(xx + Cell_To_Lepton(MapCellX), yy + Cell_To_Lepton(MapCellY));
  3758. if (ScenarioInit) {
  3759. TacticalCoord = coord;
  3760. }
  3761. DesiredTacticalCoord = coord;
  3762. IsToRedraw = true;
  3763. Flag_To_Redraw(false);
  3764. }
  3765. /***********************************************************************************************
  3766. * DisplayClass::Compute_Start_Pos -- Computes player's start pos from unit coords. *
  3767. * *
  3768. * Use this function in multiplayer games, to compute the scenario starting Tactical Pos. *
  3769. * *
  3770. * INPUT: none *
  3771. * *
  3772. * OUTPUT: x, y -- Player starting location *
  3773. * *
  3774. * WARNINGS: none *
  3775. * *
  3776. * HISTORY: *
  3777. * 02/28/1995 JLB : Commented. *
  3778. * 06/26/1995 JLB : Fixed building loop. *
  3779. * 10/20/1996 JLB : Doesn't wrap. *
  3780. *=============================================================================================*/
  3781. void DisplayClass::Compute_Start_Pos(long& x, long& y)
  3782. {
  3783. /*
  3784. ** Find the summation cell-x & cell-y for all the player's units, infantry,
  3785. ** and buildings. Buildings are weighted so that they count 16 times more
  3786. ** than units or infantry.
  3787. */
  3788. x = 0;
  3789. y = 0;
  3790. long num = 0;
  3791. int i;
  3792. for (i = 0; i < Infantry.Count(); i++) {
  3793. InfantryClass * infp = Infantry.Ptr(i);
  3794. if (!infp->IsInLimbo && infp->Is_Owned_By_Player()) {
  3795. x += (long)Coord_XCell(infp->Coord);
  3796. y += (long)Coord_YCell(infp->Coord);
  3797. num++;
  3798. }
  3799. }
  3800. for (i = 0; i < Units.Count(); i++) {
  3801. UnitClass * unitp = Units.Ptr(i);
  3802. if (!unitp->IsInLimbo && unitp->Is_Owned_By_Player()) {
  3803. x += (long)Coord_XCell(unitp->Coord);
  3804. y += (long)Coord_YCell(unitp->Coord);
  3805. num++;
  3806. }
  3807. }
  3808. for (i = 0; i < Buildings.Count(); i++) {
  3809. BuildingClass * bldgp = Buildings.Ptr(i);
  3810. if (!bldgp->IsInLimbo && bldgp->Is_Owned_By_Player()) {
  3811. x += (((long)Coord_XCell(bldgp->Coord)) * 16);
  3812. y += (((long)Coord_YCell(bldgp->Coord)) * 16);
  3813. num += 16;
  3814. }
  3815. }
  3816. for (i = 0; i < Vessels.Count(); i++) {
  3817. VesselClass * bldgp = Vessels.Ptr(i);
  3818. if (!bldgp->IsInLimbo && bldgp->Is_Owned_By_Player()) {
  3819. x += (((long)Coord_XCell(bldgp->Coord)));
  3820. y += (((long)Coord_YCell(bldgp->Coord)));
  3821. num++;
  3822. }
  3823. }
  3824. /*
  3825. ** Divide each coord by 'num' to compute the average value
  3826. */
  3827. if (num > 0) {
  3828. x /= num;
  3829. } else {
  3830. x = 0;
  3831. }
  3832. if (num > 0) {
  3833. y /= num;
  3834. } else {
  3835. y = 0;
  3836. }
  3837. }
  3838. /***********************************************************************************************
  3839. * DisplayClass::Sell_Mode_Control -- Controls the sell mode. *
  3840. * *
  3841. * This routine will control the sell mode for the player. *
  3842. * *
  3843. * INPUT: control -- The mode to set the sell state to. *
  3844. * 0 = Turn sell mode off. *
  3845. * 1 = Turn sell mode on. *
  3846. * -1 = Toggle sell mode. *
  3847. * *
  3848. * OUTPUT: none *
  3849. * *
  3850. * WARNINGS: none *
  3851. * *
  3852. * HISTORY: *
  3853. * 07/08/1995 JLB : Created. *
  3854. *=============================================================================================*/
  3855. void DisplayClass::Sell_Mode_Control(int control)
  3856. {
  3857. bool mode = IsSellMode;
  3858. switch (control) {
  3859. case 0:
  3860. mode = false;
  3861. break;
  3862. case -1:
  3863. mode = (IsSellMode == false);
  3864. break;
  3865. case 1:
  3866. mode = true;
  3867. break;
  3868. }
  3869. if (mode != IsSellMode && !PendingObject) {
  3870. IsRepairMode = false;
  3871. if (mode && PlayerPtr->BScan) {
  3872. IsSellMode = true;
  3873. Unselect_All();
  3874. } else {
  3875. IsSellMode = false;
  3876. Revert_Mouse_Shape();
  3877. }
  3878. }
  3879. }
  3880. /***********************************************************************************************
  3881. * DisplayClass::Repair_Mode_Control -- Controls the repair mode. *
  3882. * *
  3883. * This routine is used to control the repair mode for the player. *
  3884. * *
  3885. * INPUT: control -- The mode to set the repair to. *
  3886. * 0 = Turn repair off. *
  3887. * 1 = Turn repair on. *
  3888. * -1= Toggle repair state. *
  3889. * *
  3890. * OUTPUT: none *
  3891. * *
  3892. * WARNINGS: none *
  3893. * *
  3894. * HISTORY: *
  3895. * 07/08/1995 JLB : Created. *
  3896. *=============================================================================================*/
  3897. void DisplayClass::Repair_Mode_Control(int control)
  3898. {
  3899. bool mode = IsRepairMode;
  3900. switch (control) {
  3901. case 0:
  3902. mode = false;
  3903. break;
  3904. case -1:
  3905. mode = (IsRepairMode == false);
  3906. break;
  3907. case 1:
  3908. mode = true;
  3909. break;
  3910. }
  3911. if (mode != IsRepairMode && !PendingObject) {
  3912. IsSellMode = false;
  3913. if (mode && PlayerPtr->BScan) {
  3914. IsRepairMode = true;
  3915. Unselect_All();
  3916. } else {
  3917. IsRepairMode = false;
  3918. Revert_Mouse_Shape();
  3919. }
  3920. }
  3921. }
  3922. /***********************************************************************************************
  3923. * DisplayClass::In_View -- Determines if cell is visible on screen. *
  3924. * *
  3925. * Use this routine to determine if the specified cell is visible on *
  3926. * the display. This is a useful fact, since many display operations *
  3927. * can be skipped if the cell is not visible. *
  3928. * *
  3929. * INPUT: cell -- The cell number to check. *
  3930. * *
  3931. * OUTPUT: bool; Is this cell visible on the display? *
  3932. * *
  3933. * WARNINGS: none *
  3934. * *
  3935. * HISTORY: *
  3936. * 04/30/1994 JLB : Created. *
  3937. * 04/30/1994 JLB : Converted to member function. *
  3938. *=============================================================================================*/
  3939. bool DisplayClass::In_View(register CELL cell) const
  3940. {
  3941. if (cell & 0xC000) return(false);
  3942. COORDINATE coord = Coord_Whole(Cell_Coord(cell));
  3943. COORDINATE tcoord = Coord_Whole(TacticalCoord);
  3944. if ((Coord_X(coord) - Coord_X(tcoord)) > TacLeptonWidth+CELL_LEPTON_W-1) return(false);
  3945. if ((Coord_Y(coord) - Coord_Y(tcoord)) > TacLeptonHeight+CELL_LEPTON_H-1) return(false);
  3946. return(true);
  3947. }
  3948. /***********************************************************************************************
  3949. * DisplayClass::Closest_Free_Spot -- Finds the closest cell sub spot that is free. *
  3950. * *
  3951. * Use this routine to find the sub cell spot closest to the coordinate specified that is *
  3952. * free from occupation. Typical use of this is for infantry destination calculation. *
  3953. * *
  3954. * INPUT: coord -- The coordinate to use as the starting point when finding the closest *
  3955. * free spot. *
  3956. * *
  3957. * any -- Ignore occupation and just return the closest sub cell spot? *
  3958. * *
  3959. * OUTPUT: Returns with the coordinate of the closest free (possibly) sub cell location. *
  3960. * *
  3961. * WARNINGS: none *
  3962. * *
  3963. * HISTORY: *
  3964. * 09/22/1995 JLB : Created. *
  3965. *=============================================================================================*/
  3966. COORDINATE DisplayClass::Closest_Free_Spot(COORDINATE coord, bool any) const
  3967. {
  3968. if (coord & HIGH_COORD_MASK) {
  3969. return(0x00800080);
  3970. }
  3971. return Map[coord].Closest_Free_Spot(coord, any);
  3972. }
  3973. /***********************************************************************************************
  3974. * DisplayClass::Is_Spot_Free -- Determines if cell sub spot is free of occupation. *
  3975. * *
  3976. * Use this routine to determine if the coordinate (rounded to the nearest sub cell *
  3977. * position) is free for placement. Typical use of this would be for infantry placement. *
  3978. * *
  3979. * INPUT: coord -- The coordinate to examine for "freeness". The coordinate is rounded to *
  3980. * the nearest free sub cell spot. *
  3981. * *
  3982. * OUTPUT: Is the sub spot indicated by the coordinate free from previous occupation? *
  3983. * *
  3984. * WARNINGS: none *
  3985. * *
  3986. * HISTORY: *
  3987. * 09/22/1995 JLB : Created. *
  3988. *=============================================================================================*/
  3989. bool DisplayClass::Is_Spot_Free(COORDINATE coord) const
  3990. {
  3991. // This can't be right. Copy/paste error, maybe? ST - 5/8/2019
  3992. //if (coord & HIGH_COORD_MASK) {
  3993. // return(0x00800080);
  3994. //}
  3995. return Map[coord].Is_Spot_Free(CellClass::Spot_Index(coord));
  3996. }
  3997. /***********************************************************************************************
  3998. * DisplayClass::Center_Map -- Centers the map about the currently selected objects *
  3999. * *
  4000. * This routine will average the position of all the selected objects and then center *
  4001. * the map about those objects. *
  4002. * *
  4003. * INPUT: center -- The is an optional center about override coordinate. If specified, *
  4004. * then the map will be centered about that coordinate. Otherwise it *
  4005. * will center about the average location of all selected objects. *
  4006. * *
  4007. * OUTPUT: The center coordinate. *
  4008. * *
  4009. * WARNINGS: The map position changes by this routine. *
  4010. * *
  4011. * HISTORY: *
  4012. * 08/22/1995 JLB : Created. *
  4013. * 09/16/1996 JLB : Takes coordinate to center about (as override). *
  4014. *=============================================================================================*/
  4015. COORDINATE DisplayClass::Center_Map(COORDINATE center)
  4016. {
  4017. int x = 0;
  4018. // unsigned x = 0;
  4019. int y = 0;
  4020. // unsigned y = 0;
  4021. bool centerit = false;
  4022. if (CurrentObject.Count()) {
  4023. for (int index = 0; index < CurrentObject.Count(); index++) {
  4024. COORDINATE coord = CurrentObject[index]->Center_Coord();
  4025. x += Coord_X(coord);
  4026. y += Coord_Y(coord);
  4027. }
  4028. x /= CurrentObject.Count();
  4029. y /= CurrentObject.Count();
  4030. centerit = true;
  4031. }
  4032. if (center != 0L) {
  4033. x = Coord_X(center);
  4034. y = Coord_Y(center);
  4035. centerit = true;
  4036. }
  4037. if (centerit) {
  4038. center = XY_Coord(x, y);
  4039. x = x - (int)TacLeptonWidth/2;
  4040. if (x < Cell_To_Lepton(MapCellX)) x = Cell_To_Lepton(MapCellX);
  4041. y = y - (int)TacLeptonHeight/2;
  4042. if (y < Cell_To_Lepton(MapCellY)) y = Cell_To_Lepton(MapCellY);
  4043. Set_Tactical_Position(XY_Coord(x, y));
  4044. return center;
  4045. }
  4046. return 0;
  4047. }
  4048. /***********************************************************************************************
  4049. * DisplayClass::Encroach_Shadow -- Causes the shadow to creep back by one cell. *
  4050. * *
  4051. * This routine will cause the shadow to creep back by one cell. Multiple calls to this *
  4052. * routine will result in the shadow becoming more and more invasive until only the sight *
  4053. * range of player controlled units will keep the shadow pushed back. *
  4054. * *
  4055. * INPUT: none *
  4056. * house -- Player to apply shroud to *
  4057. * *
  4058. * OUTPUT: none *
  4059. * *
  4060. * WARNINGS: none *
  4061. * *
  4062. * HISTORY: *
  4063. * 10/16/1995 JLB : Created. *
  4064. * 08/06/2019 ST: Added house parameter for multiplayer *
  4065. *=============================================================================================*/
  4066. void DisplayClass::Encroach_Shadow(HouseClass * house)
  4067. {
  4068. CELL cell;
  4069. for (cell = 0; cell < MAP_CELL_TOTAL; cell++) {
  4070. if (!In_Radar(cell)) continue;
  4071. CellClass * cellptr = &(*this)[cell];
  4072. if (cellptr->Is_Visible(house) || !cellptr->Is_Mapped(house)) continue;
  4073. cellptr->IsToShroud = true; // IsToShroud isn't used outside this function. ST - 8/6/2019 2:28PM
  4074. }
  4075. /*
  4076. ** Mark all shadow edge cells to be fully shrouded. All adjacent mapped
  4077. ** cell should become partially shrouded.
  4078. */
  4079. for (cell = 0; cell < MAP_CELL_TOTAL; cell++) {
  4080. if (!In_Radar(cell)) continue;
  4081. if ((*this)[cell].IsToShroud) {
  4082. (*this)[cell].IsToShroud = false;
  4083. Shroud_Cell(cell, house);
  4084. }
  4085. }
  4086. All_To_Look(house);
  4087. Flag_To_Redraw(true);
  4088. }
  4089. /***********************************************************************************************
  4090. * DisplayClass::Shroud_Cell -- Returns the specified cell into the shrouded condition. *
  4091. * *
  4092. * This routine is called to add the shroud back to the cell specified. Typical of this *
  4093. * would be when the shroud is to regenerate. *
  4094. * *
  4095. * INPUT: cell -- The cell that the shroud is to be regenerated upon. *
  4096. * house -- Player to apply shroud to *
  4097. * *
  4098. * OUTPUT: none *
  4099. * *
  4100. * WARNINGS: Adjacent cells might be affected by this routine. The affect is determined *
  4101. * according to the legality of the partial shadow artwork. In the illegal cases *
  4102. * the adjacent cell might become shrouded as well. *
  4103. * *
  4104. * HISTORY: *
  4105. * 10/17/1995 JLB : Created. *
  4106. * 06/17/1996 JLB : Modified to handle the new shadow pieces. *
  4107. * 08/06/2019 ST: Added house parameter for multiplayer *
  4108. *=============================================================================================*/
  4109. void DisplayClass::Shroud_Cell(CELL cell, HouseClass * house)
  4110. {
  4111. if (house->IsGPSActive) {
  4112. if ( (*this)[cell].Is_Jamming(house) ) {
  4113. return;
  4114. }
  4115. }
  4116. if (!In_Radar(cell)) return;
  4117. CellClass * cellptr = &(*this)[cell];
  4118. if (cellptr->Is_Mapped(house)) {
  4119. cellptr->Set_Mapped(house, false);
  4120. cellptr->Set_Visible(house, false);
  4121. cellptr->Redraw_Objects();
  4122. /*
  4123. ** Check adjacent cells. There might be some weird combination of
  4124. ** shrouded cells such that more cells must be shrouded in order for
  4125. ** this to work.
  4126. */
  4127. for (FacingType dir = FACING_FIRST; dir < FACING_COUNT; dir++) {
  4128. CELL c = Adjacent_Cell(cell, dir);
  4129. CellClass * cptr = &(*this)[c];
  4130. /*
  4131. ** If this adjacent cell must be completely shrouded as a result
  4132. ** of the map change, yet it isn't already shrouded, then recursively
  4133. ** shroud that cell.
  4134. */
  4135. if (c != cell) {
  4136. cptr->Set_Visible(house, false);
  4137. }
  4138. /*
  4139. ** Always redraw the cell because, more than likely, the shroud
  4140. ** edge will change shape because of the map change.
  4141. */
  4142. cptr->Redraw_Objects();
  4143. }
  4144. }
  4145. }
  4146. /***********************************************************************************************
  4147. * DisplayClass::Read_INI -- Reads map control data from INI file. *
  4148. * *
  4149. * This routine is used to read the map control data from the INI *
  4150. * file. *
  4151. * *
  4152. * INPUT: buffer -- Pointer to the loaded INI file data. *
  4153. * *
  4154. * OUTPUT: none *
  4155. * *
  4156. * WARNINGS: The TriggerClass INI data must have been read before calling this function. *
  4157. * *
  4158. * HISTORY: *
  4159. * 05/27/1994 JLB : Created. *
  4160. *=============================================================================================*/
  4161. void DisplayClass::Read_INI(CCINIClass & ini)
  4162. {
  4163. /*
  4164. ** Read the map dimensions.
  4165. */
  4166. char const * const name = "Map";
  4167. int x = ini.Get_Int(name, "X", 1);
  4168. int y = ini.Get_Int(name, "Y", 1);
  4169. int w = ini.Get_Int(name, "Width", MAP_CELL_W-2);
  4170. int h = ini.Get_Int(name, "Height", MAP_CELL_H-2);
  4171. #ifndef FIXIT_VERSION_3 // Map size no longer restricted.
  4172. #ifdef FIXIT_CSII // checked - ajw
  4173. if(Session.Type >= GAME_MODEM && Session.Type <= GAME_INTERNET && PlayingAgainstVersion < VERSION_AFTERMATH_CS) {
  4174. /*
  4175. ** HACK ALERT:
  4176. ** Force the map to be limited to the size that 96x96 would be. If the
  4177. ** size is greater (due to hacking?) then shrink it down to legal size.
  4178. ** BG Note: only do this for multiplayer games against non-AfterMath.
  4179. */
  4180. if (w * h > 96 * 96) {
  4181. h -= (((w*h) - (96*96)) / w) + 1;
  4182. }
  4183. }
  4184. #else
  4185. /*
  4186. ** HACK ALERT:
  4187. ** Force the map to be limited to the size that 96x96 would be. If the
  4188. ** size is greater (due to hacking?) then shrink it down to legal size.
  4189. */
  4190. if (w * h > 96 * 96) {
  4191. h -= (((w*h) - (96*96)) / w) + 1;
  4192. }
  4193. #endif
  4194. #endif // !FIXIT_VERSION_3
  4195. Set_Map_Dimensions( x, y, w, h );
  4196. /*
  4197. ** The theater is determined at this point. There is specific data that
  4198. ** is custom to this data. Load the custom data (as it related to terrain)
  4199. ** at this point.
  4200. */
  4201. Scen.Theater = ini.Get_TheaterType(name, "Theater", THEATER_TEMPERATE);
  4202. if (Scen.Theater == THEATER_NONE) {
  4203. Scen.Theater = THEATER_TEMPERATE;
  4204. }
  4205. /*
  4206. ** Remove any old theater specific uncompressed shapes
  4207. */
  4208. #ifdef WIN32
  4209. if (Scen.Theater != LastTheater) {
  4210. Reset_Theater_Shapes();
  4211. }
  4212. #endif //WIN32
  4213. /*
  4214. ** Now that the theater is known, init the entire map hierarchy
  4215. */
  4216. Init(Scen.Theater);
  4217. /*
  4218. ** Special initializations occur when the theater is known.
  4219. */
  4220. TerrainTypeClass::Init(Scen.Theater);
  4221. TemplateTypeClass::Init(Scen.Theater);
  4222. OverlayTypeClass::Init(Scen.Theater);
  4223. UnitTypeClass::Init(Scen.Theater);
  4224. InfantryTypeClass::Init(Scen.Theater);
  4225. BuildingTypeClass::Init(Scen.Theater);
  4226. BulletTypeClass::Init(Scen.Theater);
  4227. AnimTypeClass::Init(Scen.Theater);
  4228. AircraftTypeClass::Init(Scen.Theater);
  4229. VesselTypeClass::Init(Scen.Theater);
  4230. SmudgeTypeClass::Init(Scen.Theater);
  4231. /*
  4232. ** Read the Waypoint entries.
  4233. */
  4234. for (int i = 0; i < WAYPT_COUNT; i++) {
  4235. char buf[20];
  4236. sprintf(buf, "%d", i);
  4237. Scen.Waypoint[i] = ini.Get_Int("Waypoints", buf, -1);
  4238. if (Scen.Waypoint[i] != -1) {
  4239. (*this)[Scen.Waypoint[i]].IsWaypoint = 1;
  4240. }
  4241. }
  4242. /*
  4243. ** Set the starting position (do this after Init(), which clears the cells'
  4244. ** IsWaypoint flags).
  4245. */
  4246. if (Scen.Waypoint[WAYPT_HOME] == -1) {
  4247. Scen.Waypoint[WAYPT_HOME] = XY_Cell(MapCellX + 5*RESFACTOR, MapCellY + 4*RESFACTOR);
  4248. }
  4249. Scen.Views[0] = Scen.Views[1] = Scen.Views[2] = Scen.Views[3] = Scen.Waypoint[WAYPT_HOME];
  4250. Set_Tactical_Position(Cell_Coord((Scen.Waypoint[WAYPT_HOME] - (MAP_CELL_W * 4 * RESFACTOR)) - (5*RESFACTOR)));
  4251. /*
  4252. ** Loop through all CellTrigger entries.
  4253. */
  4254. int len = ini.Entry_Count("CellTriggers");
  4255. for (int index = 0; index < len; index++) {
  4256. /*
  4257. ** Get a cell trigger and cell assignment.
  4258. */
  4259. char const * cellentry = ini.Get_Entry("CellTriggers", index);
  4260. TriggerTypeClass * tp = ini.Get_TriggerType("CellTriggers", cellentry);
  4261. CELL cell = atoi(cellentry);
  4262. if (tp != NULL && !(*this)[cell].Trigger.Is_Valid()) {
  4263. TriggerClass * tt = Find_Or_Make(tp);
  4264. if (tt) {
  4265. tt->AttachCount++;
  4266. tt->Cell = cell;
  4267. (*this)[cell].Trigger = tt;
  4268. }
  4269. }
  4270. }
  4271. /*
  4272. ** Read the map template data.
  4273. */
  4274. static char const * const MAPPACK = "MapPack";
  4275. len = ini.Get_UUBlock(MAPPACK, _staging_buffer, sizeof(_staging_buffer));
  4276. BufferStraw bstraw(_staging_buffer, len);
  4277. Map.Read_Binary(bstraw);
  4278. LastTheater = Scen.Theater;
  4279. }
  4280. /***********************************************************************************************
  4281. * DisplayClass::Write_INI -- Write the map data to the INI file specified. *
  4282. * *
  4283. * This routine will output all the data of this map to the INI database specified. *
  4284. * *
  4285. * INPUT: ini -- Reference to the INI handler to store the map data to. *
  4286. * *
  4287. * OUTPUT: none *
  4288. * *
  4289. * WARNINGS: Any existing map data in the INI database will be replaced by this function. *
  4290. * *
  4291. * HISTORY: *
  4292. * 07/03/1996 JLB : Created. *
  4293. *=============================================================================================*/
  4294. void DisplayClass::Write_INI(CCINIClass & ini)
  4295. {
  4296. char entry[20];
  4297. /*
  4298. ** Save the map parameters.
  4299. */
  4300. static char const * const NAME = "Map";
  4301. ini.Clear(NAME);
  4302. ini.Put_TheaterType(NAME, "Theater", Scen.Theater);
  4303. ini.Put_Int(NAME, "X", MapCellX);
  4304. ini.Put_Int(NAME, "Y", MapCellY);
  4305. ini.Put_Int(NAME, "Width", MapCellWidth);
  4306. ini.Put_Int(NAME, "Height", MapCellHeight);
  4307. /*
  4308. ** Save the Waypoint entries.
  4309. */
  4310. static char const * const WAYNAME = "Waypoints";
  4311. ini.Clear(WAYNAME);
  4312. for (int i = 0; i < WAYPT_COUNT; i++) {
  4313. if (Scen.Waypoint[i] != -1) {
  4314. sprintf(entry, "%d", i);
  4315. ini.Put_Int(WAYNAME, entry, Scen.Waypoint[i]);
  4316. }
  4317. }
  4318. /*
  4319. ** Save the cell's triggers.
  4320. */
  4321. static char const * const CELLTRIG = "CellTriggers";
  4322. ini.Clear(CELLTRIG);
  4323. for (CELL cell = 0; cell < MAP_CELL_TOTAL; cell++) {
  4324. if ((*this)[cell].Trigger.Is_Valid()) {
  4325. TriggerClass * tp = (*this)[cell].Trigger;
  4326. if (tp != NULL) {
  4327. /*
  4328. ** Generate entry name.
  4329. */
  4330. sprintf(entry, "%d", cell);
  4331. /*
  4332. ** Save entry.
  4333. */
  4334. ini.Put_TriggerType(CELLTRIG, entry, tp->Class);
  4335. }
  4336. }
  4337. }
  4338. /*
  4339. ** Write the map template data out to the ini file.
  4340. */
  4341. static char const * const MAPPACK = "MapPack";
  4342. BufferPipe bpipe(_staging_buffer, sizeof(_staging_buffer));
  4343. int len = Map.Write_Binary(bpipe);
  4344. ini.Clear(MAPPACK);
  4345. if (len) {
  4346. ini.Put_UUBlock(MAPPACK, _staging_buffer, len);
  4347. }
  4348. }
  4349. /***********************************************************************************************
  4350. * DisplayClass::All_To_Look -- Direct all objects to look around for the player. *
  4351. * *
  4352. * This routine will scan through all objects and tell them to look if they are supposed *
  4353. * to be able to reveal the map for the player. This routine may be necessary in cases *
  4354. * of gap generator reshroud logic. *
  4355. * *
  4356. * INPUT: none *
  4357. * *
  4358. * OUTPUT: none *
  4359. * *
  4360. * WARNINGS: none *
  4361. * *
  4362. * HISTORY: *
  4363. * 09/23/1996 JLB : Created. *
  4364. * 08/06/2019 ST : Added house parameter so it can work for multiple players *
  4365. *=============================================================================================*/
  4366. void DisplayClass::All_To_Look(HouseClass *house, bool units_only)
  4367. {
  4368. for (int index = 0; index < Layer[LAYER_GROUND].Count(); index++) {
  4369. ObjectClass * object = Layer[LAYER_GROUND][index];
  4370. if (object != NULL && object->Is_Techno()) {
  4371. TechnoClass * tech = ((TechnoClass *)object);
  4372. if (tech->What_Am_I() == RTTI_BUILDING && units_only) continue;
  4373. if (tech->House == house) {
  4374. if (tech->Is_Discovered_By_Player(house)) {
  4375. object->Look();
  4376. }
  4377. } else {
  4378. //if (tech->What_Am_I() == RTTI_BUILDING && Rule.IsAllyReveal && tech->House->Is_Ally(PlayerPtr)) {
  4379. if (tech->What_Am_I() == RTTI_BUILDING && Rule.IsAllyReveal && tech->House->Is_Ally(house)) {
  4380. tech->Look();
  4381. }
  4382. }
  4383. }
  4384. }
  4385. }
  4386. /*
  4387. ** Added house parameter for client/server multiplayer. ST - 8/12/2019 11:48AM
  4388. **
  4389. **
  4390. */
  4391. void DisplayClass::Constrained_Look(COORDINATE center, LEPTON distance, HouseClass *house)
  4392. {
  4393. for (int index = 0; index < Layer[LAYER_GROUND].Count(); index++) {
  4394. ObjectClass * object = Layer[LAYER_GROUND][index];
  4395. if (object != NULL && object->Is_Techno()) {
  4396. TechnoClass * tech = ((TechnoClass *)object);
  4397. // if (tech->What_Am_I() == RTTI_BUILDING && units_only) continue;
  4398. if (Session.Type != GAME_GLYPHX_MULTIPLAYER) {
  4399. if (tech->House->IsPlayerControl) {
  4400. if (tech->IsDiscoveredByPlayer && Distance(tech->Center_Coord(), center) <= (tech->Techno_Type_Class()->SightRange * CELL_LEPTON_W) + distance) {
  4401. object->Look();
  4402. }
  4403. } else {
  4404. if (tech->What_Am_I() == RTTI_BUILDING && Rule.IsAllyReveal && tech->House->Is_Ally(PlayerPtr) &&
  4405. Distance(tech->Center_Coord(), center) <= (tech->Techno_Type_Class()->SightRange * CELL_LEPTON_W) + distance) {
  4406. tech->Look();
  4407. }
  4408. }
  4409. } else {
  4410. if (tech->House->IsHuman) {
  4411. if (tech->House == house) {
  4412. if (tech->Is_Discovered_By_Player(house) && Distance(tech->Center_Coord(), center) <= (tech->Techno_Type_Class()->SightRange * CELL_LEPTON_W) + distance) {
  4413. object->Look();
  4414. }
  4415. } else {
  4416. if (tech->What_Am_I() == RTTI_BUILDING && Rule.IsAllyReveal && tech->House->Is_Ally(house) &&
  4417. Distance(tech->Center_Coord(), center) <= (tech->Techno_Type_Class()->SightRange * CELL_LEPTON_W) + distance) {
  4418. tech->Look();
  4419. }
  4420. }
  4421. }
  4422. }
  4423. }
  4424. }
  4425. }
  4426. /***********************************************************************************************
  4427. * DisplayClass::Flag_Cell -- Flag the specified cell to be redrawn. *
  4428. * *
  4429. * This will flag the cell to be redrawn. *
  4430. * *
  4431. * INPUT: cell -- The cell to be flagged. *
  4432. * *
  4433. * OUTPUT: none *
  4434. * *
  4435. * WARNINGS: none *
  4436. * *
  4437. * HISTORY: *
  4438. * 10/20/1996 JLB : Created. *
  4439. *=============================================================================================*/
  4440. void DisplayClass::Flag_Cell(CELL cell)
  4441. {
  4442. Flag_To_Redraw(false);
  4443. IsToRedraw = true;
  4444. CellRedraw[cell] = true;
  4445. }
  4446. static ActionType _priority_actions[] = {
  4447. ACTION_ATTACK,
  4448. ACTION_ENTER,
  4449. ACTION_HEAL,
  4450. ACTION_REPAIR,
  4451. ACTION_SABOTAGE,
  4452. ACTION_CAPTURE,
  4453. ACTION_MOVE
  4454. };
  4455. static int get_action_priority(ActionType action)
  4456. {
  4457. for (int i = 0; i < ARRAY_LENGTH(_priority_actions); ++i) {
  4458. if (_priority_actions[i] == action) {
  4459. return i;
  4460. }
  4461. }
  4462. return INT_MAX;
  4463. }
  4464. template <typename T>
  4465. static int index_of(const DynamicVectorClass<T*>& list, T* object)
  4466. {
  4467. for (int i = 0; i < list.Count(); i++) {
  4468. if (list[i] == object) {
  4469. return i;
  4470. }
  4471. }
  4472. return -1;
  4473. }
  4474. template <typename T>
  4475. static ObjectClass* Best_Object_With_ActionT(DynamicVectorClass<ObjectClass*>& objects, T subject)
  4476. {
  4477. DynamicVectorClass<const ObjectTypeClass*> checked_types;
  4478. if (objects.Count()) {
  4479. int best_priority = INT_MAX;
  4480. ObjectClass* best_object = objects[0];
  4481. for (int i = 0; i < objects.Count(); ++i) {
  4482. ObjectClass* object = objects[i];
  4483. const ObjectTypeClass* type = &object->Class_Of();
  4484. if (index_of(checked_types, type) != -1) {
  4485. continue;
  4486. }
  4487. checked_types.Add(type);
  4488. ActionType action = object->What_Action(subject);
  4489. int priority = get_action_priority(action);
  4490. if (priority < best_priority) {
  4491. best_priority = priority;
  4492. best_object = object;
  4493. if (best_priority == 0) {
  4494. break;
  4495. }
  4496. }
  4497. }
  4498. return best_object;
  4499. }
  4500. return NULL;
  4501. }
  4502. ObjectClass* Best_Object_With_Action(DynamicVectorClass<ObjectClass*>& objects, const ObjectClass* object)
  4503. {
  4504. return Best_Object_With_ActionT(objects, object);
  4505. }
  4506. ObjectClass* Best_Object_With_Action(DynamicVectorClass<ObjectClass*>& objects, CELL cell)
  4507. {
  4508. return Best_Object_With_ActionT(objects, cell);
  4509. }
  4510. ActionType Best_Object_Action(DynamicVectorClass<ObjectClass*>& objects, const ObjectClass* object)
  4511. {
  4512. ObjectClass* obj = Best_Object_With_Action(objects, object);
  4513. return (obj != NULL) ? obj->What_Action(object) : ACTION_NONE;
  4514. }
  4515. ActionType Best_Object_Action(DynamicVectorClass<ObjectClass*>& objects, CELL cell)
  4516. {
  4517. ObjectClass* obj = Best_Object_With_Action(objects, cell);
  4518. return (obj != NULL) ? obj->What_Action(cell) : ACTION_NONE;
  4519. }
  4520. ObjectClass* Best_Object_With_Action(const ObjectClass* object)
  4521. {
  4522. return Best_Object_With_Action(CurrentObject.Raw(), object);
  4523. }
  4524. ObjectClass* Best_Object_With_Action(CELL cell)
  4525. {
  4526. return Best_Object_With_Action(CurrentObject.Raw(), cell);
  4527. }
  4528. ActionType Best_Object_Action(const ObjectClass* object)
  4529. {
  4530. return Best_Object_Action(CurrentObject.Raw(), object);
  4531. }
  4532. ActionType Best_Object_Action(CELL cell)
  4533. {
  4534. return Best_Object_Action(CurrentObject.Raw(), cell);
  4535. }