BUILDING.H 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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/BUILDING.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 : BUILDING.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 14, 1994 *
  30. * *
  31. * Last Update : April 14, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef BUILDING_H
  37. #define BUILDING_H
  38. #include "radio.h"
  39. #include "cargo.h"
  40. #include "mission.h"
  41. #include "bullet.h"
  42. #include "target.h"
  43. #include "factory.h"
  44. #include "techno.h"
  45. #define MAX_DOOR_STAGE 18 // # of frames of door opening on weapons factory
  46. #define DOOR_OPEN_STAGE 9 // frame on which the door is entirely open
  47. #define MAX_REPAIR_ANIM_STAGE 5 // # of stages of anim for repair center cycling
  48. /****************************************************************************
  49. ** For each instance of a building in the game, there is one of
  50. ** these structures. This structure holds information that is specific
  51. ** and dynamic for a particular building.
  52. */
  53. class BuildingClass : public TechnoClass
  54. {
  55. public:
  56. /*
  57. ** This points to the control data that gives this building its characteristics.
  58. */
  59. CCPtr<BuildingTypeClass> Class;
  60. /*
  61. ** If this building is in the process of producing something, then this
  62. ** will point to the factory manager.
  63. */
  64. CCPtr<FactoryClass> Factory;
  65. /*
  66. ** This is the house that originally owned this factory. Objects buildable
  67. ** by this house type will be produced from this factory regardless of who
  68. ** the current owner is.
  69. */
  70. HousesType ActLike;
  71. /*
  72. ** This building should be rebuilt if it is destroyed. This is in spite
  73. ** of the condition of the prebuilt base list.
  74. */
  75. unsigned IsToRebuild:1;
  76. /*
  77. ** Is the building allowed to repair itself?
  78. */
  79. unsigned IsToRepair:1;
  80. /*
  81. ** If the computer owns this building, then it is allowed to sell it if
  82. ** the situation warrants it. In the other case, it cannot sell the
  83. ** building regardless of conditions.
  84. */
  85. unsigned IsAllowedToSell:1;
  86. /*
  87. ** If the building is at a good point to change orders, then this
  88. ** flag will be set to true.
  89. */
  90. unsigned IsReadyToCommence:1;
  91. /*
  92. ** If this building is currently spending money to repair itself, then
  93. ** this flag is true. It will automatically be set to false when the building
  94. ** has reached full strength, when money is exhausted, or if the player
  95. ** specifically stops the repair process.
  96. */
  97. unsigned IsRepairing:1;
  98. /*
  99. ** If repair is currently in progress and this flag is true, then a wrench graphic
  100. ** will be overlaid on the building to give visual feedback for the repair process.
  101. */
  102. unsigned IsWrenchVisible:1;
  103. /*
  104. ** This flag is set when a commando has raided the building and planted
  105. ** plastic explosives. When the CommandoCountDown timer expires, the
  106. ** building takes massive damage.
  107. */
  108. unsigned IsGoingToBlow:1;
  109. /*
  110. ** If this building was destroyed by some method that would prevent
  111. ** survivors, then this flag will be true.
  112. */
  113. unsigned IsSurvivorless:1;
  114. /*
  115. ** These state control variables are used by the obelisk for the charging
  116. ** animation.
  117. */
  118. unsigned IsCharging:1;
  119. unsigned IsCharged:1;
  120. /*
  121. ** A building that has been captured will not contain the full compliment
  122. ** of crew. This is true even if it subsequently gets captured back.
  123. */
  124. unsigned IsCaptured:1;
  125. /*
  126. ** Used by the gap generator to decide if it should jam or unjam
  127. */
  128. unsigned IsJamming:1;
  129. /*
  130. ** Used by radar facilities to know if they're being jammed by a mobile
  131. ** radar jammer
  132. */
  133. unsigned IsJammed:1;
  134. /*
  135. ** Used only by advanced tech center, this keeps track of whether the
  136. ** GPS satellite has been fired or not.
  137. */
  138. unsigned HasFired:1;
  139. /*
  140. ** If Grand_Opening was already called for this building, then this
  141. ** flag will be true. By utilizing this flag, multiple inadvertant
  142. ** calls to Grand_Opening won't cause problems.
  143. */
  144. unsigned HasOpened:1;
  145. /*
  146. ** Special countdown to destruction value. If the building is destroyed,
  147. ** it won't actually be removed from the map until this value reaches
  148. ** zero. This delay is for cosmetic reasons.
  149. */
  150. CDTimerClass<FrameTimerClass> CountDown;
  151. /*
  152. ** This is the current animation processing state that the building is
  153. ** in.
  154. */
  155. BStateType BState;
  156. BStateType QueueBState;
  157. /*
  158. ** For multiplayer games, this keeps track of the last house to damage
  159. ** this building, so if it burns to death or otherwise gradually dies,
  160. ** proper credit can be given for the kill.
  161. */
  162. HousesType WhoLastHurtMe;
  163. /*
  164. ** This is the saboteur responsible for this building's destruction.
  165. */
  166. TARGET WhomToRepay;
  167. /*
  168. ** This is a record of the last strength of the building. Every so often,
  169. ** it will compare this strength to the current strength. If there is a
  170. ** discrepancy, then the owner power is adjusted accordingly.
  171. */
  172. int LastStrength;
  173. /*
  174. ** This is a target id of an animation we're keeping track of. Examples
  175. ** of this usage are the advanced tech center, which needs to know
  176. ** when the sputdoor animation has reached a certain stage.
  177. */
  178. TARGET AnimToTrack;
  179. /*
  180. ** This is the countdown timer that regulates placement retry logic
  181. ** for factory type buildings.
  182. */
  183. CDTimerClass<FrameTimerClass> PlacementDelay;
  184. /*---------------------------------------------------------------------
  185. ** Constructors, Destructors, and overloaded operators.
  186. */
  187. static void * operator new(size_t size);
  188. static void * operator new(size_t , void * ptr) {return(ptr);};
  189. static void operator delete(void *ptr);
  190. BuildingClass(StructType type, HousesType house);
  191. #ifdef FIXIT_MULTI_SAVE
  192. BuildingClass(NoInitClass const & x) : TechnoClass(x), Class(x), Factory(x), CountDown(x), PlacementDelay(x) {};
  193. #else
  194. BuildingClass(NoInitClass const & x) : TechnoClass(x), Class(x), CountDown(x), PlacementDelay(x) {};
  195. #endif
  196. virtual ~BuildingClass(void);
  197. operator StructType(void) const {return Class->Type;};
  198. /*---------------------------------------------------------------------
  199. ** Member function prototypes.
  200. */
  201. static void Init(void);
  202. TARGET Target_Scan(void);
  203. BuildingTypeClass::AnimControlType const * Fetch_Anim_Control(void) {return (&Class->Anims[BState]);};
  204. /*
  205. ** Query functions.
  206. */
  207. virtual int Value(void) const;
  208. virtual void const * Get_Image_Data(void) const;
  209. virtual int How_Many_Survivors(void) const;
  210. virtual DirType Turret_Facing(void) const;
  211. virtual CELL Find_Exit_Cell(TechnoClass const * techno) const;
  212. virtual InfantryType Crew_Type(void) const;
  213. virtual int Pip_Count(void) const;
  214. virtual bool Can_Player_Move(void) const;
  215. virtual ActionType What_Action(ObjectClass const * target) const;
  216. virtual ActionType What_Action(CELL cell) const;
  217. virtual bool Can_Demolish(void) const;
  218. virtual ObjectTypeClass const & Class_Of(void) const {return *Class;};
  219. virtual DirType Fire_Direction(void) const;
  220. virtual short const * Overlap_List(bool redraw=false) const;
  221. int Shape_Number(void) const;
  222. int Power_Output(void) const;
  223. CELL Check_Point(CheckPointType cp) const;
  224. /*
  225. ** Coordinate inquiry functions. These are used for both display and
  226. ** combat purposes.
  227. */
  228. virtual COORDINATE Target_Coord(void) const;
  229. virtual COORDINATE Docking_Coord(void) const;
  230. virtual COORDINATE Center_Coord(void) const;
  231. virtual COORDINATE Sort_Y(void) const;
  232. virtual COORDINATE Exit_Coord(void) const;
  233. /*
  234. ** Object entry and exit from the game system.
  235. */
  236. virtual void Detach(TARGET target, bool all);
  237. virtual void Detach_All(bool all=true);
  238. virtual void Grand_Opening(bool captured = false);
  239. virtual void Update_Buildables(void);
  240. virtual MoveType Can_Enter_Cell(CELL cell, FacingType = FACING_NONE) const;
  241. virtual bool Unlimbo(COORDINATE , DirType dir = DIR_N);
  242. virtual bool Limbo(void);
  243. /*
  244. ** Display and rendering support functionality. Supports imagery and how
  245. ** object interacts with the map and thus indirectly controls rendering.
  246. */
  247. virtual void const * Remap_Table(void);
  248. virtual int Exit_Object(TechnoClass * base);
  249. virtual void Draw_It(int x, int y, WindowNumberType window) const;
  250. virtual bool Mark(MarkType mark=MARK_CHANGE);
  251. virtual void Fire_Out(void);
  252. void Begin_Mode(BStateType bstate);
  253. /*
  254. ** User I/O.
  255. */
  256. virtual void Active_Click_With(ActionType action, ObjectClass * object);
  257. virtual void Active_Click_With(ActionType action, CELL cell);
  258. /*
  259. ** Combat related.
  260. */
  261. virtual void Death_Announcement(TechnoClass const * source=0) const;
  262. virtual FireErrorType Can_Fire(TARGET, int which) const;
  263. virtual TARGET Greatest_Threat(ThreatType threat) const;
  264. virtual ResultType Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source=0, bool forced=false);
  265. virtual bool Captured(HouseClass * newowner);
  266. void Update_Radar_Spied(void);
  267. /*
  268. ** AI.
  269. */
  270. void Charging_AI(void);
  271. void Rotation_AI(void);
  272. void Factory_AI(void);
  273. void Repair_AI(void);
  274. void Animation_AI(void);
  275. virtual bool Revealed(HouseClass * house);
  276. virtual void Repair(int control);
  277. virtual void Sell_Back(int control);
  278. virtual RadioMessageType Receive_Message(RadioClass * from, RadioMessageType message, long & param);
  279. virtual void AI(void);
  280. virtual void Assign_Target(TARGET target);
  281. virtual bool Toggle_Primary(void);
  282. bool Flush_For_Placement(TechnoClass * techno, CELL cell);
  283. virtual int Mission_Unload(void);
  284. virtual int Mission_Repair(void);
  285. virtual int Mission_Attack(void);
  286. virtual int Mission_Harvest(void);
  287. virtual int Mission_Guard(void);
  288. virtual int Mission_Construction(void);
  289. virtual int Mission_Deconstruction(void);
  290. virtual int Mission_Missile(void);
  291. virtual void Enter_Idle_Mode(bool initial=false);
  292. void Remove_Gap_Effect(void);
  293. /*
  294. ** Scenario and debug support.
  295. */
  296. #ifdef CHEAT_KEYS
  297. virtual void Debug_Dump(MonoClass *mono) const;
  298. #endif
  299. /*
  300. ** File I/O.
  301. */
  302. static void Read_INI(CCINIClass & ini);
  303. static void Write_INI(CCINIClass & ini);
  304. static char *INI_Name(void) {return "STRUCTURES";};
  305. bool Load(Straw & file);
  306. bool Save(Pipe & file) const;
  307. private:
  308. void Drop_Debris(TARGET source = TARGET_NONE);
  309. static COORDINATE const CenterOffset[BSIZE_COUNT];
  310. };
  311. #endif