DISPLAY.CPP 161 KB

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