CELL.H 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. ** Command & Conquer Red Alert(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: /CounterStrike/CELL.H 1 3/03/97 10:24a 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 : CELL.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 29, 1994 *
  30. * *
  31. * Last Update : April 29, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef CELL_H
  37. #define CELL_H
  38. #include "building.h"
  39. #include "unit.h"
  40. #include "template.h"
  41. /****************************************************************************
  42. ** Each cell on the map is controlled by the following structure.
  43. */
  44. class CellClass
  45. {
  46. public:
  47. /*
  48. ** This is the ID number of this cell. By placing the ID number here, it doesn't have
  49. ** be calculated. Calculating this number requires a divide and would occur about
  50. ** 5.72031 bijillion times per second.
  51. */
  52. short ID;
  53. /*
  54. ** Does this cell need to be updated on the radar map? If something changes in the cell
  55. ** that might change the radar map imagery, then this flag will be set. It gets cleared
  56. ** when the cell graphic is updated to the radar map.
  57. */
  58. unsigned IsPlot:1;
  59. /*
  60. ** Does this cell contain the special placement cursor graphic? This graphic is
  61. ** present when selecting a site for building placement.
  62. */
  63. unsigned IsCursorHere:1;
  64. /*
  65. ** A mapped cell has some portion of it visible. Maybe it has a shroud piece
  66. ** over it and maybe not.
  67. */
  68. unsigned IsMapped:1;
  69. /*
  70. ** A visible cell means that it is completely visible with no shroud over
  71. ** it at all.
  72. */
  73. unsigned IsVisible:1;
  74. /*
  75. ** Every cell can be assigned a waypoint. A waypoint can only be assigned
  76. ** to one cell, and vice-versa. This bit simply indicates whether this
  77. ** cell is assigned a waypoint or not.
  78. */
  79. unsigned IsWaypoint:1;
  80. /*
  81. ** Is this cell currently under the radar map cursor? If so then it
  82. ** needs to be updated whenever the map is updated.
  83. */
  84. unsigned IsRadarCursor:1;
  85. /*
  86. ** If this cell contains a house flag, then this will be true. The actual house
  87. ** flag it contains is specified by the Owner field.
  88. */
  89. unsigned IsFlagged:1;
  90. /*
  91. ** This is a working flag used to help keep track of what cells should be
  92. ** shrouded. By using this flag it allows a single pass through the map
  93. ** cells for determining shadow regrowth logic.
  94. */
  95. unsigned IsToShroud:1;
  96. /*
  97. ** This records the movement zone for this map. Movement zones share the
  98. ** same number if they are contiguous (terrain consideration only). There
  99. ** are basically two kinds of zones. The difference being determined by
  100. ** walls that can be crushed by movement. A vehicle that can crush walls
  101. ** will only consider the CrushZone. All other terrestrial travellers will
  102. ** use the normal Zone.
  103. */
  104. unsigned char Zones[MZONE_COUNT];
  105. /*
  106. ** This field controls whether an area is being jammed by a gap
  107. ** generator.
  108. */
  109. unsigned short Jammed;
  110. /*
  111. ** This is the trigger ID for any trigger that might be attached to
  112. ** this cell.
  113. */
  114. CCPtr<TriggerClass> Trigger;
  115. /*
  116. ** This contains the icon number and set to use for the base
  117. ** of the terrain. All rendering on an icon occurs AFTER the icon
  118. ** specified by this element is rendered. It is the lowest of the low.
  119. */
  120. TemplateType TType;
  121. unsigned char TIcon;
  122. /*
  123. ** The second layer of 'terrain' icons is represented by a simple
  124. ** type number and a value byte. This is sufficient for handling
  125. ** concrete and walls.
  126. */
  127. OverlayType Overlay;
  128. unsigned char OverlayData;
  129. /*
  130. ** This is used to specify any special 'stain' overlay icon. This
  131. ** typically includes infantry bodies or other temporary marks.
  132. */
  133. SmudgeType Smudge;
  134. unsigned char SmudgeData;
  135. /*
  136. ** Smudges and walls need to record ownership values. For walls, this
  137. ** allows adjacent building placement logic to work. For smudges, it
  138. ** allows building over smudges that are no longer attached to buildings
  139. ** in addition to fixing the adjacent placement logic.
  140. */
  141. HousesType Owner;
  142. /*
  143. ** This flag tells you what type of infantry currently occupy the
  144. ** cell or are moving into it.
  145. */
  146. HousesType InfType;
  147. /*
  148. ** These point to the object(s) that are located in this cell or overlap
  149. ** this cell.
  150. */
  151. private:
  152. ObjectClass * OccupierPtr;
  153. public:
  154. #ifdef SORTDRAW
  155. ObjectClass * Overlapper[10];
  156. #else
  157. ObjectClass * Overlapper[6];
  158. #endif
  159. /*
  160. ** This array of bit flags is used to indicate which sub positions
  161. ** within the cell are either occupied or are soon going to be
  162. ** occupied. For vehicles, the cells that the vehicle is passing over
  163. ** will be flagged with the vehicle bit. For infantry, the the sub
  164. ** position the infantry is stopped at or headed toward will be marked.
  165. ** The sub positions it passes over will NOT be marked.
  166. */
  167. union {
  168. struct {
  169. unsigned Center:1;
  170. unsigned NW:1;
  171. unsigned NE:1;
  172. unsigned SW:1;
  173. unsigned SE:1;
  174. unsigned Vehicle:1; // Reserved for vehicle occupation.
  175. unsigned Monolith:1; // Some immovable blockage is in cell.
  176. unsigned Building:1; // A building of some time (usually blocks movement).
  177. } Occupy;
  178. unsigned char Composite;
  179. } Flag;
  180. //----------------------------------------------------------------
  181. CellClass(void);
  182. CellClass(NoInitClass const & x) : Trigger(x) {}
  183. ~CellClass(void) {OccupierPtr=0;}
  184. int operator == (CellClass const & cell) const {return &cell == this;}
  185. /*
  186. ** Query functions.
  187. */
  188. bool Can_Tiberium_Germinate(void) const;
  189. bool Can_Tiberium_Grow(void) const;
  190. bool Can_Tiberium_Spread(void) const;
  191. bool Is_Bridge_Here(void) const;
  192. RTTIType What_Am_I(void) const {return(RTTI_CELL);}
  193. BuildingClass * Cell_Building(void) const;
  194. CELL Cell_Number(void) const {return(ID);}
  195. COORDINATE Cell_Coord(void) const;
  196. COORDINATE Closest_Free_Spot(COORDINATE coord, bool any=false) const;
  197. COORDINATE Free_Spot(void) const {return Closest_Free_Spot(Cell_Coord());}
  198. CellClass & Adjacent_Cell(FacingType face) {return (CellClass &)((*((CellClass const *)this)).Adjacent_Cell(face));}
  199. CellClass const & Adjacent_Cell(FacingType face) const;
  200. InfantryClass * Cell_Infantry(void) const;
  201. LandType Land_Type(void) const {return(Land);}
  202. ObjectClass * Cell_Find_Object(RTTIType rtti) const;
  203. ObjectClass * Cell_Object(int x=0, int y=0) const;
  204. ObjectClass * Cell_Occupier(void) const {return(OccupierPtr);}
  205. ObjectClass * Fetch_Occupier(void) const;
  206. TARGET As_Target(void) const {return ::As_Target(Cell_Number());}
  207. TechnoClass * Cell_Techno(int x=0, int y=0) const;
  208. TerrainClass * Cell_Terrain(void) const;
  209. UnitClass * Cell_Unit(void) const;
  210. VesselClass * Cell_Vessel(void) const;
  211. bool Goodie_Check(FootClass * object);
  212. bool Is_Clear_To_Build(SpeedType loco = SPEED_TRACK) const;
  213. bool Is_Clear_To_Move(SpeedType loco, bool ignoreinfantry, bool ignorevehicles, int zone=-1, MZoneType check=MZONE_NORMAL) const;
  214. bool Is_Spot_Free(int spot_index) const {return (! (Flag.Composite & (1 << spot_index)) ); }
  215. int Cell_Color(bool override=false) const;
  216. int Clear_Icon(void) const;
  217. static int Spot_Index(COORDINATE coord);
  218. /*
  219. ** Object placement and removal flag operations.
  220. */
  221. void Occupy_Down(ObjectClass * object);
  222. void Occupy_Up(ObjectClass * object);
  223. void Overlap_Down(ObjectClass * object);
  224. void Overlap_Up(ObjectClass * object);
  225. bool Flag_Place(HousesType house);
  226. bool Flag_Remove(void);
  227. /*
  228. ** File I/O.
  229. */
  230. bool Should_Save(void) const;
  231. bool Save(Pipe & file) const;
  232. bool Load(Straw & file);
  233. void Code_Pointers(void);
  234. void Decode_Pointers(void);
  235. /*
  236. ** Display and rendering controls.
  237. */
  238. void Draw_It(int x, int y, bool objects=false) const;
  239. void Redraw_Objects(bool forced=false);
  240. void Shimmer(void);
  241. /*
  242. ** Maintenance calculation support.
  243. */
  244. bool Grow_Tiberium(void);
  245. bool Spread_Tiberium(bool forced=false);
  246. long Tiberium_Adjust(bool pregame=false);
  247. void Wall_Update(void);
  248. void Concrete_Calc(void);
  249. void Recalc_Attributes(void);
  250. int Reduce_Tiberium(int levels);
  251. int Reduce_Wall(int damage);
  252. void Incoming(COORDINATE threat=0, bool forced=false, bool nokidding=false);
  253. void Adjust_Threat(HousesType house, int threat_value);
  254. int operator != (CellClass const &) const {return 0;}
  255. private:
  256. CellClass (CellClass const &) ;
  257. LandType Land; // The land type of this cell.
  258. };
  259. #endif