CELL.H 12 KB

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