DISPLAY.H 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/DISPLAY.H 1 3/03/97 10:24a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : DISPLAY.H *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : May 1, 1994 *
  26. * *
  27. * Last Update : May 1, 1994 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #ifndef DISPLAY_H
  33. #define DISPLAY_H
  34. #include "map.h"
  35. #include "layer.h"
  36. #define ICON_PIXEL_W 24
  37. #define ICON_PIXEL_H 24
  38. #define ICON_LEPTON_W 256
  39. #define ICON_LEPTON_H 256
  40. #define CELL_PIXEL_W ICON_PIXEL_W
  41. #define CELL_PIXEL_H ICON_PIXEL_H
  42. #define CELL_LEPTON_W ICON_LEPTON_W
  43. #define CELL_LEPTON_H ICON_LEPTON_H
  44. // -----------------------------------------------------------
  45. #define PIXEL_LEPTON_W (ICON_LEPTON_W/ICON_PIXEL_W)
  46. #define PIXEL_LEPTON_H (ICON_LEPTON_H/ICON_PIXEL_H)
  47. #define SIDE_BAR_TAC_WIDTH 10
  48. #define SIDE_BAR_TAC_HEIGHT 8
  49. extern COORDINATE Coord_Add(COORDINATE coord1, COORDINATE coord2);
  50. class DisplayClass: public MapClass
  51. {
  52. public:
  53. friend class DLLExportClass; // ST - 5/13/2019
  54. /*
  55. ** The tactical map display position is indicated by the cell of the
  56. ** upper left hand corner. These should not be altered directly. Use
  57. ** the Set_Tactical_Position function instead.
  58. */
  59. COORDINATE TacticalCoord;
  60. /*
  61. ** The dimensions (in cells) of the visible window onto the game map. This tactical
  62. ** map is how the player interacts and views the game world.
  63. */
  64. LEPTON TacLeptonWidth;
  65. LEPTON TacLeptonHeight;
  66. /*
  67. ** These layer control elements are used to group the displayable objects
  68. ** so that proper overlap can be obtained.
  69. */
  70. static LayerClass Layer[LAYER_COUNT];
  71. /*
  72. ** This records the position and shape of a placement cursor to display
  73. ** over the map. This cursor is used when placing buildings and also used
  74. ** extensively by the scenario editor.
  75. */
  76. CELL ZoneCell;
  77. short ZoneOffset;
  78. short const *CursorSize;
  79. short CursorShapeSave[256]; // For save/load
  80. bool ProximityCheck; // Is proximity check ok?
  81. /*
  82. ** This holds the building type that is about to be placed upon the map.
  83. ** It is only valid during the building placement state. The PendingLegal
  84. ** flag is updated as the cursor moves and it reflects the legality of
  85. ** placing the building at the desired location.
  86. */
  87. ObjectClass * PendingObjectPtr;
  88. ObjectTypeClass const * PendingObject;
  89. HousesType PendingHouse;
  90. static unsigned char FadingBrighten[256];
  91. static unsigned char FadingShade[256];
  92. static unsigned char FadingWayDark[256];
  93. static unsigned char FadingLight[256];
  94. static unsigned char FadingGreen[256];
  95. static unsigned char FadingYellow[256];
  96. static unsigned char FadingRed[256];
  97. static unsigned char TranslucentTable[(MAGIC_COL_COUNT+1)*256];
  98. static unsigned char WhiteTranslucentTable[(1+1)*256];
  99. static unsigned char MouseTranslucentTable[(4+1)*256];
  100. static void const *TransIconset;
  101. static unsigned char UnitShadow[(USHADOW_COL_COUNT+1)*256];
  102. static unsigned char UnitShadowAir[(USHADOW_COL_COUNT+1)*256];
  103. static unsigned char SpecialGhost[2*256];
  104. //-------------------------------------------------------------------------
  105. DisplayClass(void);
  106. DisplayClass(NoInitClass const & x) : MapClass(x) {};
  107. virtual void Read_INI(CCINIClass & ini);
  108. void Write_INI(CCINIClass & ini);
  109. /*
  110. ** Initialization
  111. */
  112. virtual void One_Time(void); // One-time inits
  113. virtual void Init_Clear(void); // Clears all to known state
  114. virtual void Init_IO(void); // Inits button list
  115. virtual void Init_Theater(TheaterType theater); // Theater-specific inits
  116. /*
  117. ** General display/map/interface support functionality.
  118. */
  119. virtual void AI(KeyNumType &input, int x, int y);
  120. virtual void Draw_It(bool complete=false);
  121. /*
  122. ** Added functionality.
  123. */
  124. void All_To_Look(HouseClass *house, bool units_only=false); // Added house parameter so it can work for multiple players. ST - 8/6/2019 2:30PM
  125. void Constrained_Look(COORDINATE coord, LEPTON distance, HouseClass *house); // Added house parameter for client/server multiplayer. ST - 8/12/2019 3:25PM
  126. void Shroud_Cell(CELL cell, HouseClass *house);
  127. void Encroach_Shadow(HouseClass *house);
  128. COORDINATE Center_Map(COORDINATE center=0L);
  129. virtual bool Map_Cell(CELL cell, HouseClass *house, bool check_radar_spied = true, bool and_for_allies = true); // Added check_radar_spied parameter to prevent recursion. ST - 8/6/2019 10:16AM. Added and_for_allies ST - 10/31/2019 1:18PM
  130. virtual CELL Click_Cell_Calc(int x, int y) const;
  131. virtual void Help_Text(int , int =-1, int =-1, int =YELLOW, bool =false) {};
  132. virtual MouseType Get_Mouse_Shape(void) const = 0;
  133. virtual bool Scroll_Map(DirType facing, int & distance, bool really);
  134. virtual void Refresh_Cells(CELL cell, short const *list);
  135. virtual void Set_View_Dimensions(int x, int y, int width=-1, int height=-1);
  136. /*
  137. ** Pending object placement control.
  138. */
  139. virtual void Put_Place_Back(TechnoClass * ) {}; // Affects 'pending' system.
  140. void Cursor_Mark(CELL pos, bool on);
  141. void Set_Cursor_Shape(short const * list);
  142. CELL Set_Cursor_Pos(CELL pos = -1);
  143. void Get_Occupy_Dimensions(int & w, int & h, short const *list) const;
  144. /*
  145. ** Tactical map only functionality.
  146. */
  147. virtual void Set_Tactical_Position(COORDINATE coord);
  148. void Refresh_Band(void);
  149. void Select_These(COORDINATE coord1, COORDINATE coord2, bool additive = false);
  150. COORDINATE Pixel_To_Coord(int x, int y) const;
  151. bool Coord_To_Pixel(COORDINATE coord, int & x, int & y) const;
  152. bool Push_Onto_TacMap(COORDINATE &source, COORDINATE &dest);
  153. void Remove(ObjectClass const * object, LayerType layer);
  154. void Submit(ObjectClass const * object, LayerType layer);
  155. CELL Calculated_Cell(SourceType dir, WAYPOINT waypoint=-1, CELL cell=-1, SpeedType loco=SPEED_FOOT, bool zonecheck=true, MZoneType mzone=MZONE_NORMAL) const;
  156. bool In_View(register CELL cell) const;
  157. bool Passes_Proximity_Check(ObjectTypeClass const * object, HousesType house, short const * list, CELL trycell) const;
  158. ObjectClass * Cell_Object(CELL cell, int x=0, int y=0) const;
  159. ObjectClass * Next_Object(ObjectClass * object) const;
  160. ObjectClass * Prev_Object(ObjectClass * object) const;
  161. int Cell_Shadow(CELL cell, HouseClass *house) const;
  162. short const * Text_Overlap_List(char const * text, int x, int y) const;
  163. bool Is_Spot_Free(COORDINATE coord) const;
  164. COORDINATE Closest_Free_Spot(COORDINATE coord, bool any=false) const;
  165. void Sell_Mode_Control(int control);
  166. void Repair_Mode_Control(int control);
  167. virtual void Flag_Cell(CELL cell);
  168. bool Is_Cell_Flagged(CELL cell) const {return CellRedraw.Is_True(cell);};
  169. /*
  170. ** Computes starting position based on player's units' Coords.
  171. */
  172. void Compute_Start_Pos(long& x, long& y);
  173. /*
  174. ** File I/O.
  175. */
  176. virtual void Code_Pointers(void);
  177. virtual void Decode_Pointers(void);
  178. protected:
  179. virtual void Mouse_Right_Press(void);
  180. virtual void Mouse_Left_Press(int x, int y);
  181. virtual void Mouse_Left_Up(CELL cell, bool shadow, ObjectClass * object, ActionType action, bool wsmall = false);
  182. virtual void Mouse_Left_Held(int x, int y);
  183. virtual void Mouse_Left_Release(CELL cell, int x, int y, ObjectClass * object, ActionType action, bool wsmall = false);
  184. public:
  185. /*
  186. ** This is the pixel offset for the upper left corner of the tactical map.
  187. */
  188. int TacPixelX;
  189. int TacPixelY;
  190. /*
  191. ** This is the coordinate that the tactical map should be in at next available opportunity.
  192. */
  193. COORDINATE DesiredTacticalCoord;
  194. /*
  195. ** If something in the tactical map is to be redrawn, this flag is set to true.
  196. */
  197. unsigned IsToRedraw:1;
  198. /*
  199. ** If the player is currently wielding a wrench (to select buildings for repair),
  200. ** then this flag is true. In such a state, normal movement and combat orders
  201. ** are preempted.
  202. */
  203. unsigned IsRepairMode:1;
  204. /*
  205. ** If the player is currently in "sell back" mode, then this flag will be
  206. ** true. While in this mode, anything clicked on will be sold back to the
  207. ** "factory".
  208. */
  209. unsigned IsSellMode:1;
  210. /*
  211. ** If the player is currently in ion cannon targeting mode, then this
  212. ** flag will be true. While in this mode, anything clicked on will be
  213. ** be destroyed by the ION cannon.
  214. */
  215. SpecialWeaponType IsTargettingMode;
  216. protected:
  217. /*
  218. ** If it is currently in rubber band mode (multi unit selection), then this
  219. ** flag will be true. While in such a mode, normal input is preempted while
  220. ** the extended selection is in progress.
  221. */
  222. unsigned IsRubberBand:1;
  223. /*
  224. ** The moment the mouse is held down, this flag gets set. If the mouse is dragged
  225. ** a sufficient distance while held down, then true rubber band mode selection
  226. ** can begin. Using a minimum distance prevents accidental rubber band selection
  227. ** mode from being initiated.
  228. */
  229. unsigned IsTentative:1;
  230. /*
  231. ** This gadget class is used for capturing input to the tactical map. All mouse input
  232. ** will be routed through this gadget.
  233. */
  234. class TacticalClass : public GadgetClass {
  235. public:
  236. TacticalClass(void) : GadgetClass(0,0,0,0,LEFTPRESS|LEFTRELEASE|LEFTHELD|LEFTUP|RIGHTPRESS,true) {};
  237. int Selection_At_Mouse(unsigned flags, KeyNumType & key);
  238. int Command_Object(unsigned flags, KeyNumType & key);
  239. protected:
  240. virtual int Action(unsigned flags, KeyNumType & key);
  241. };
  242. friend class TacticalClass;
  243. /*
  244. ** This is the "button" that tracks all input to the tactical map.
  245. ** It must be available to derived classes, for Save/Load purposes.
  246. */
  247. public: //ST - 1/21/2019 11:59AM
  248. static TacticalClass TacButton;
  249. private:
  250. /*
  251. ** This is a utility flag that is set during the icon draw process only if there
  252. ** was at least one shadow icon detected that should be redrawn. When the shadow
  253. ** drawing logic is to take place, but this flag is false, then the shadow drawing
  254. ** will be skipped since it would perform no function.
  255. */
  256. unsigned IsShadowPresent:1;
  257. /*
  258. ** Rubber band mode consists of stretching a box from the anchor point (specified
  259. ** here) to the current cursor position.
  260. */
  261. int BandX,BandY;
  262. int NewX,NewY;
  263. static void const *ShadowShapes;
  264. static unsigned char ShadowTrans[(SHADOW_COL_COUNT+1)*256];
  265. void Redraw_Icons(void);
  266. void Redraw_OIcons(void);
  267. void Redraw_Shadow(void);
  268. /*
  269. ** This bit array is used to flag cells to be redrawn. If the icon needs to
  270. ** be redrawn for a cell, then the corresponding flag will be true.
  271. */
  272. static BooleanVectorClass CellRedraw;
  273. bool Good_Reinforcement_Cell(CELL outcell, CELL incell, SpeedType loco, int zone, MZoneType mzone) const;
  274. //
  275. // We need a way to bypass visible view checks when we are running in the context of GlyphX without using the
  276. // internal C&C renderer. We shouldn't know or care what the user is actually looking at
  277. // ST - 4/17/2019 9:01AM
  278. //
  279. static bool IgnoreViewConstraints;
  280. /*
  281. ** Some additional padding in case we need to add data to the class and maintain backwards compatibility for save/load
  282. */
  283. unsigned char SaveLoadPadding[1024];
  284. };
  285. #endif