building.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. ** Command & Conquer Renegade(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. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/building.h $*
  25. * *
  26. * $Author:: Patrick $*
  27. * *
  28. * $Modtime:: 1/07/02 3:52p $*
  29. * *
  30. * $Revision:: 42 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef BUILDING_H
  39. #define BUILDING_H
  40. #include "always.h"
  41. #include "damageablegameobj.h"
  42. #include "combatphysobserver.h"
  43. #include "buildingaggregate.h"
  44. #include "lightphys.h"
  45. #include "playertype.h"
  46. /*
  47. ** Forward declarations
  48. */
  49. class AudibleSoundClass;
  50. class BaseControllerClass;
  51. class BuildingMonitorClass;
  52. class PowerPlantGameObj;
  53. class SoldierFactoryGameObj;
  54. class VehicleFactoryGameObj;
  55. class AirStripGameObj;
  56. class WarFactoryGameObj;
  57. class RefineryGameObj;
  58. class ComCenterGameObj;
  59. class RepairBayGameObj;
  60. /**
  61. ** BuildingConstants
  62. ** Convienent namespace declaration for the constants used with buildings
  63. */
  64. namespace BuildingConstants
  65. {
  66. typedef enum
  67. {
  68. TYPE_NONE = -1,
  69. TYPE_POWER_PLANT,
  70. TYPE_SOLDIER_FACTORY,
  71. TYPE_VEHICLE_FACTORY,
  72. TYPE_REFINERY,
  73. TYPE_COM_CENTER,
  74. TYPE_REPAIR_BAY,
  75. TYPE_SHRINE,
  76. TYPE_HELIPAD,
  77. TYPE_CONYARD,
  78. TYPE_BASE_DEFENSE,
  79. TYPE_COUNT
  80. } BuildingType;
  81. typedef enum
  82. {
  83. LEGACY_TEAM_GDI = 0,
  84. LEGACY_TEAM_NOD,
  85. } LegacyBuildingTeam;
  86. typedef enum
  87. {
  88. BASE_COUNT = 2,
  89. };
  90. }
  91. /**
  92. ** Building Game Obj Def
  93. ** This class is an editable definition for a building. It contains all constant data needed to initialize
  94. ** a BuildingGameObj.
  95. */
  96. class BuildingGameObjDef : public DamageableGameObjDef
  97. {
  98. public:
  99. BuildingGameObjDef( void );
  100. virtual uint32 Get_Class_ID( void ) const;
  101. virtual PersistClass * Create( void ) const ;
  102. virtual bool Save( ChunkSaveClass &csave );
  103. virtual bool Load( ChunkLoadClass &cload );
  104. virtual const PersistFactoryClass & Get_Factory( void ) const;
  105. DECLARE_EDITABLE( BuildingGameObjDef, DamageableGameObjDef );
  106. void Set_Type (BuildingConstants::BuildingType type) { Type = type; }
  107. BuildingConstants::BuildingType Get_Type (void) const { return Type; }
  108. const StringClass & Get_Mesh_Prefix (void) const { return MeshPrefix; }
  109. int Get_Damage_Report(int team) const;
  110. int Get_Destroy_Report(int team) const;
  111. protected:
  112. StringClass MeshPrefix;
  113. ArmorType MCTSkin;
  114. BuildingConstants::BuildingType Type;
  115. int GDIDamageReportID;
  116. int NodDamageReportID;
  117. int GDIDestroyReportID;
  118. int NodDestroyReportID;
  119. friend class BuildingGameObj;
  120. };
  121. /*
  122. ** Building Game Obj
  123. ** This class encapsulates the basic building functionality.
  124. **
  125. ** At initialization, the following things need to happen.
  126. ** - Collects all of the meshes that are part of the building using proximity, prefix matching
  127. ** and the "house" naming convention (# indicates an interior mesh, ^ indicates an exterior mesh).
  128. ** - Collect all of the BuildingAggregates that are part of the building using proximity and
  129. ** prefix matching.
  130. ** - Collect all light sources associated with the building using proximity and prefix matching.
  131. ** - Install itself as an observer into each StaticPhysClass (meshes and aggregates) that is part
  132. ** of the building.
  133. **
  134. ** During gameplay, the building code does the following things:
  135. ** - Responds to all bullet collisions and explosions on any of its meshes/aggregates by
  136. ** applying damage to the building.
  137. ** - When destroyed, applies the alternate materials on its exterior meshes
  138. ** - When the power goes out, applies the alternate materials on its interior meshes
  139. ** - When the state changes (power on/off, health 100,75,50,25,0) switches the behaviors of
  140. ** all aggregates.
  141. **
  142. */
  143. class BuildingGameObj : public DamageableGameObj, public CombatPhysObserverClass
  144. {
  145. public:
  146. // Constructor and Destructor
  147. BuildingGameObj( void );
  148. virtual ~BuildingGameObj( void );
  149. // Definitions
  150. virtual void Init( void );
  151. void Init( const BuildingGameObjDef & definition );
  152. const BuildingGameObjDef & Get_Definition( void ) const ;
  153. // Save / Load
  154. virtual bool Save( ChunkSaveClass & csave );
  155. virtual bool Load( ChunkLoadClass & cload );
  156. virtual const PersistFactoryClass & Get_Factory( void ) const;
  157. // Type identification
  158. virtual BuildingGameObj * As_BuildingGameObj( void ) { return this; }
  159. virtual DamageableGameObj * As_DamageableGameObj( void ) { return this; }
  160. virtual PowerPlantGameObj * As_PowerPlantGameObj (void) { return NULL; }
  161. virtual SoldierFactoryGameObj * As_SoldierFactoryGameObj (void) { return NULL; }
  162. virtual VehicleFactoryGameObj * As_VehicleFactoryGameObj (void) { return NULL; }
  163. virtual AirStripGameObj * As_AirStripGameObj (void) { return NULL; }
  164. virtual WarFactoryGameObj * As_WarFactoryGameObj (void) { return NULL; }
  165. virtual RefineryGameObj * As_RefineryGameObj (void) { return NULL; }
  166. virtual ComCenterGameObj * As_ComCenterGameObj (void) { return NULL; }
  167. virtual RepairBayGameObj * As_RepairBayGameObj (void) { return NULL; }
  168. /****/
  169. /*
  170. ** Position interface, the position of the building controller influences which meshes
  171. ** and other components are automatically assigned to this building. When there are two
  172. ** BuildingGameObj's that can accept a particular component, the closest one wins.
  173. */
  174. void Get_Position(Vector3 * pos) const { *pos = Position; }
  175. void Set_Position(const Vector3 & pos) { Position = pos; CollectionSphere.Center = pos; }
  176. /*
  177. ** Damage interface, designed to work similarly to a game object
  178. */
  179. virtual void Apply_Damage( const OffenseObjectClass & damager,
  180. float scale = 1.0f,
  181. int alternate_skin = -1 );
  182. void Apply_Damage_Building( const OffenseObjectClass & offense,
  183. StaticPhysClass * component );
  184. void Apply_Damage_Building( const OffenseObjectClass & offense,
  185. bool mct_damage );
  186. void Set_Normalized_Health (float health);
  187. /*
  188. ** Power interface, turn the power on and off
  189. */
  190. void Enable_Power(bool onoff);
  191. bool Is_Power_Enabled(void) const { return IsPowerOn; }
  192. /*
  193. ** Building announcment support
  194. */
  195. void Play_Announcement( int text_id, bool broadcast );
  196. void Stop_Current_Announcement( void );
  197. /*
  198. ** Utility functions for the building mesh naming convention.
  199. ** Exterior meshes contain a ^ as the first character following their prefix.
  200. ** Interior meshes contain a # as the first character following their prefix.
  201. */
  202. bool Name_Prefix_Matches_This_Building(const char * name);
  203. static bool Is_Interior_Mesh_Name(const char * name);
  204. static bool Is_Exterior_Mesh_Name(const char * name);
  205. const char * Get_Name_Prefix (void) const { return Get_Definition().MeshPrefix; }
  206. /*
  207. ** Building component support
  208. */
  209. void Collect_Building_Components (void);
  210. void Get_Collection_Sphere (SphereClass *sphere) const { *sphere = CollectionSphere; }
  211. void Set_Collection_Sphere (const SphereClass &sphere) { CollectionSphere = sphere; }
  212. /*
  213. ** CnC mode suport
  214. */
  215. virtual void CnC_Initialize (BaseControllerClass *base);
  216. virtual void On_Destroyed (void);
  217. virtual void On_Damaged (void);
  218. bool Is_Destroyed (void) const { return IsDestroyed; }
  219. /*
  220. ** Network support
  221. */
  222. virtual void Import_Rare (BitStreamClass &packet);
  223. virtual void Export_Rare (BitStreamClass &packet);
  224. virtual void Export_Creation (BitStreamClass &packet);
  225. virtual void Import_Creation (BitStreamClass &packet);
  226. static void Set_Precision (void);
  227. virtual bool Get_World_Position (Vector3 &pos) const { pos = Position; return true; }
  228. //virtual float Compute_Object_Priority (int client_id, const Vector3 &client_pos);
  229. //virtual void Get_Extended_Information( StringClass & description );
  230. virtual void Get_Description( StringClass & description );
  231. virtual bool Is_Tagged(void) { return false; }
  232. /*
  233. **
  234. */
  235. bool Is_GDI( void ) { return Get_Player_Type() == PLAYERTYPE_GDI; }
  236. bool Is_Nod( void ) { return Get_Player_Type() == PLAYERTYPE_NOD; }
  237. static void Set_Can_Repair_Buildings(bool flag) {CanRepairBuildings = flag;}
  238. static bool Get_Can_Repair_Buildings(void) {return CanRepairBuildings;}
  239. //
  240. // Informational
  241. //
  242. void Find_Closest_Poly (const Vector3 &pos, float *distance2);
  243. protected:
  244. /*
  245. ** CnC mode stuff
  246. */
  247. BuildingMonitorClass * BuildingMonitor;
  248. BaseControllerClass * BaseController;
  249. bool IsDestroyed;
  250. //private:
  251. Vector3 Position;
  252. bool IsPowerOn;
  253. int CurrentState; // derived from the health and IsPowerOn
  254. AudibleSoundClass * CurrentAnnouncement;
  255. SphereClass AnnouncementSphere;
  256. SphereClass CollectionSphere;
  257. RefMultiListClass<StaticPhysClass> InteriorMeshes;
  258. RefMultiListClass<StaticPhysClass> ExteriorMeshes;
  259. RefMultiListClass<BuildingAggregateClass> Aggregates;
  260. RefMultiListClass<LightPhysClass> PowerOnLights;
  261. RefMultiListClass<LightPhysClass> PowerOffLights;
  262. static bool CanRepairBuildings;
  263. void Initialize_Building(void);
  264. void Reset_Components(void);
  265. void Add_Mesh(StaticPhysClass * terrain);
  266. void Remove_Mesh(StaticPhysClass * terrain);
  267. void Add_Aggregate(BuildingAggregateClass * aggregate);
  268. void Remove_Aggregate(BuildingAggregateClass * aggregate);
  269. void Add_Light(LightPhysClass * light);
  270. void Find_Closest_Poly_For_Model (RenderObjClass *model, const Vector3 &pos, float *distance2);
  271. void Update_State(bool force_update = false);
  272. void Enable_Alternate_Materials(RefMultiListClass<StaticPhysClass> & models, bool onoff);
  273. void Enable_Alternate_Materials(RenderObjClass * model,bool onoff);
  274. friend class GameObjManager;
  275. };
  276. #endif // BUILDING_H