DISPLAY.H 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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.h_v 2.15 16 Oct 1995 16:47:42 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.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : May 1, 1994 *
  30. * *
  31. * Last Update : May 1, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef DISPLAY_H
  37. #define DISPLAY_H
  38. #include "map.h"
  39. #include "layer.h"
  40. #define ICON_PIXEL_W 24
  41. #define ICON_PIXEL_H 24
  42. #define ICON_LEPTON_W 256
  43. #define ICON_LEPTON_H 256
  44. #define CELL_PIXEL_W ICON_PIXEL_W
  45. #define CELL_PIXEL_H ICON_PIXEL_H
  46. #define CELL_LEPTON_W ICON_LEPTON_W
  47. #define CELL_LEPTON_H ICON_LEPTON_H
  48. // -----------------------------------------------------------
  49. #define PIXEL_LEPTON_W (ICON_LEPTON_W/ICON_PIXEL_W)
  50. #define PIXEL_LEPTON_H (ICON_LEPTON_H/ICON_PIXEL_H)
  51. extern COORDINATE Coord_Add(COORDINATE coord1, COORDINATE coord2);
  52. class DisplayClass: public MapClass
  53. {
  54. public:
  55. /*
  56. ** This indicates the theater that the display is to represent.
  57. */
  58. TheaterType Theater;
  59. /*
  60. ** The tactical map display position is indicated by the cell of the
  61. ** upper left hand corner. These should not be altered directly. Use
  62. ** the Set_Tactical_Position function instead.
  63. */
  64. COORDINATE TacticalCoord;
  65. /*
  66. ** The dimensions (in cells) of the visible window onto the game map. This tactical
  67. ** map is how the player interacts and views the game world.
  68. */
  69. int TacLeptonWidth;
  70. int TacLeptonHeight;
  71. /*
  72. ** These layer control elements are used to group the displayable objects
  73. ** so that proper overlap can be obtained.
  74. */
  75. static LayerClass Layer[LAYER_COUNT];
  76. /*
  77. ** This records the position and shape of a placement cursor to display
  78. ** over the map. This cursor is used when placing buildings and also used
  79. ** extensively by the scenario editor.
  80. */
  81. CELL ZoneCell;
  82. short ZoneOffset;
  83. short const *CursorSize;
  84. bool ProximityCheck; // Is proximity check ok?
  85. /*
  86. ** This holds the building type that is about to be placed upon the map.
  87. ** It is only valid during the building placement state. The PendingLegal
  88. ** flag is updated as the cursor moves and it reflects the legality of
  89. ** placing the building at the desired location.
  90. */
  91. ObjectClass * PendingObjectPtr;
  92. ObjectTypeClass const * PendingObject;
  93. HousesType PendingHouse;
  94. static unsigned char FadingBrighten[256];
  95. static unsigned char FadingShade[256];
  96. static unsigned char FadingLight[256];
  97. static unsigned char RemapTables[HOUSE_COUNT][3][256];
  98. static unsigned char FadingGreen[256];
  99. static unsigned char FadingYellow[256];
  100. static unsigned char FadingRed[256];
  101. static unsigned char TranslucentTable[(MAGIC_COL_COUNT+1)*256];
  102. static unsigned char WhiteTranslucentTable[(1+1)*256];
  103. static unsigned char MouseTranslucentTable[(4+1)*256];
  104. static void const *TransIconset;
  105. static unsigned char UnitShadow[(USHADOW_COL_COUNT+1)*256];
  106. static unsigned char SpecialGhost[2*256];
  107. //-------------------------------------------------------------------------
  108. DisplayClass(void);
  109. virtual void Read_INI(char *buffer);
  110. void Write_INI(char *buffer);
  111. /*
  112. ** Initialization
  113. */
  114. virtual void One_Time(void); // One-time inits
  115. virtual void Init_Clear(void); // Clears all to known state
  116. virtual void Init_IO(void); // Inits button list
  117. virtual void Init_Theater(TheaterType theater); // Theater-specific inits
  118. /*
  119. ** General display/map/interface support functionality.
  120. */
  121. virtual void AI(KeyNumType &input, int x, int y);
  122. virtual void Draw_It(bool complete=false);
  123. /*
  124. ** Added functionality.
  125. */
  126. void Center_Map(void);
  127. virtual bool Map_Cell(CELL cell, HouseClass *house);
  128. virtual CELL Click_Cell_Calc(int x, int y);
  129. virtual void Help_Text(int , int =-1, int =-1, int =YELLOW, bool =false, int =0) {};
  130. virtual MouseType Get_Mouse_Shape(void) const = 0;
  131. virtual bool Scroll_Map(DirType facing, int & distance, bool really);
  132. virtual void Refresh_Cells(CELL cell, short const *list);
  133. virtual void Set_View_Dimensions(int x, int y, int width=-1, int height=-1);
  134. /*
  135. ** Pending object placement control.
  136. */
  137. virtual void Put_Place_Back(TechnoClass * ) {}; // Affects 'pending' system.
  138. void Cursor_Mark(CELL pos, bool on);
  139. void Set_Cursor_Shape(short const * list);
  140. CELL Set_Cursor_Pos(CELL pos = -1);
  141. void Get_Occupy_Dimensions(int & w, int & h, short const *list);
  142. /*
  143. ** Tactical map only functionality.
  144. */
  145. virtual void Set_Tactical_Position(COORDINATE coord);
  146. void Refresh_Band(void);
  147. void Select_These(COORDINATE coord1, COORDINATE coord2);
  148. COORDINATE Pixel_To_Coord(int x, int y);
  149. bool Coord_To_Pixel(COORDINATE coord, int &x, int &y);
  150. bool Push_Onto_TacMap(COORDINATE &source, COORDINATE &dest);
  151. void Remove(ObjectClass const *object, LayerType layer);
  152. void Submit(ObjectClass const *object, LayerType layer);
  153. CELL Calculated_Cell(SourceType dir, HousesType house);
  154. bool In_View(register CELL cell);
  155. bool Passes_Proximity_Check(ObjectTypeClass const *object);
  156. ObjectClass * Cell_Object(CELL cell, int x=0, int y=0);
  157. ObjectClass * Next_Object(ObjectClass * object);
  158. ObjectClass * Prev_Object(ObjectClass * object);
  159. int Cell_Shadow(CELL cell);
  160. short const * Text_Overlap_List(char const * text, int x, int y, int lines = 1);
  161. bool Is_Spot_Free(COORDINATE coord) const;
  162. COORDINATE Closest_Free_Spot(COORDINATE coord, bool any=false) const;
  163. void Sell_Mode_Control(int control);
  164. void Repair_Mode_Control(int control);
  165. void Flag_Cell(CELL cell) {
  166. Flag_To_Redraw(false);
  167. IsToRedraw = true;
  168. CellRedraw[cell] = true;
  169. };
  170. bool Is_Cell_Flagged(CELL cell) const {return CellRedraw.Is_True(cell);};
  171. /*
  172. ** Computes starting position based on player's units' Coords.
  173. */
  174. void Compute_Start_Pos(void);
  175. /*
  176. ** File I/O.
  177. */
  178. virtual void Code_Pointers(void);
  179. virtual void Decode_Pointers(void);
  180. protected:
  181. virtual void Mouse_Right_Press(void);
  182. virtual void Mouse_Left_Press(int x, int y);
  183. virtual void Mouse_Left_Up(bool shadow, ObjectClass * object, ActionType action, bool wwsmall = false);
  184. virtual void Mouse_Left_Held(int x, int y);
  185. virtual void Mouse_Left_Release(CELL cell, int x, int y, ObjectClass * object, ActionType action, bool wwsmall = false);
  186. public:
  187. /*
  188. ** This is the pixel offset for the upper left corner of the tactical map.
  189. */
  190. int TacPixelX;
  191. int TacPixelY;
  192. /*
  193. ** This is the coordinate that the tactical map should be in at next available opportunity.
  194. */
  195. COORDINATE DesiredTacticalCoord;
  196. /*
  197. ** If something in the tactical map is to be redrawn, this flag is set to true.
  198. */
  199. unsigned IsToRedraw:1;
  200. /*
  201. ** If the player is currently wielding a wrench (to select buildings for repair),
  202. ** then this flag is true. In such a state, normal movement and combat orders
  203. ** are preempted.
  204. */
  205. unsigned IsRepairMode:1;
  206. /*
  207. ** If the player is currently in "sell back" mode, then this flag will be
  208. ** true. While in this mode, anything clicked on will be sold back to the
  209. ** "factory".
  210. */
  211. unsigned IsSellMode:1;
  212. /*
  213. ** If the player is currently in ion cannon targetting mode, then this
  214. ** flag will be true. While in this mode, anything clicked on will be
  215. ** be destroyed by the ION cannon.
  216. */
  217. unsigned IsTargettingMode:2;
  218. protected:
  219. /*
  220. ** If it is currently in rubber band mode (multi unit selection), then this
  221. ** flag will be true. While in such a mode, normal input is prempted while
  222. ** the extended selection is in progress.
  223. */
  224. unsigned IsRubberBand:1;
  225. /*
  226. ** The moment the mouse is held down, this flag gets set. If the mouse is dragged
  227. ** a sufficient distance while held down, then true rubber band mode selection
  228. ** can begin. Using a minimum distance prevents accidental rubber band selection
  229. ** mode from being initiated.
  230. */
  231. unsigned IsTentative:1;
  232. /*
  233. ** This gadget class is used for capturing input to the tactical map. All mouse input
  234. ** will be routed through this gadget.
  235. */
  236. class TacticalClass : public GadgetClass {
  237. public:
  238. TacticalClass(void) : GadgetClass(0,0,0,0,LEFTPRESS|LEFTRELEASE|LEFTHELD|LEFTUP|RIGHTPRESS,true) {};
  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. static TacticalClass TacButton;
  248. private:
  249. /*
  250. ** This is a utility flag that is set during the icon draw process only if there
  251. ** was at least one shadow icon detected that should be redrawn. When the shadow
  252. ** drawing logic is to take place, but this flag is false, then the shadow drawing
  253. ** will be skipped since it would perform no function.
  254. */
  255. unsigned IsShadowPresent:1;
  256. /*
  257. ** Rubber band mode consists of stretching a box from the anchor point (specified
  258. ** here) to the current cursor position.
  259. */
  260. int BandX,BandY;
  261. int NewX,NewY;
  262. static void const *ShadowShapes;
  263. static unsigned char ShadowTrans[(SHADOW_COL_COUNT+1)*256];
  264. void Redraw_Icons(int draw_flags=0);
  265. void Redraw_Shadow(void);
  266. void Redraw_Shadow_Rects(void);
  267. /*
  268. ** This bit array is used to flag cells to be redrawn. If the icon needs to
  269. ** be redrawn for a cell, then the corresponding flag will be true.
  270. */
  271. static BooleanVectorClass CellRedraw;
  272. };
  273. #endif