BUILDING.H 13 KB

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