damage.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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/damage.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 2/13/02 6:06p $*
  29. * *
  30. * $Revision:: 52 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef DAMAGE_H
  36. #define DAMAGE_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef GAMEOBJREF_H
  41. #include "gameobjref.h"
  42. #endif
  43. #ifndef _DATASAFE_H
  44. #include "..\commando\datasafe.h"
  45. #endif //_DATASAFE_H
  46. #include "editable.h"
  47. /*
  48. **
  49. */
  50. typedef unsigned int ArmorType;
  51. typedef unsigned int WarheadType;
  52. typedef safe_unsigned_int SafeArmorType;
  53. typedef safe_unsigned_int SafeWarheadType;
  54. class ArmedGameObj;
  55. class DamageableGameObj;
  56. class BitStreamClass;
  57. class ChunkSaveClass;
  58. class ChunkLoadClass;
  59. /*
  60. **
  61. */
  62. class ArmorWarheadManager {
  63. public:
  64. // Build
  65. static void Init( void );
  66. static void Shutdown( void );
  67. static bool Is_Armor_Soft( ArmorType armor );
  68. // Type additions/access
  69. static int Get_Num_Armor_Types( void );
  70. static ArmorType Get_Armor_Type( const char *name );
  71. static const char * Get_Armor_Name( ArmorType type );
  72. static int Get_Num_Warhead_Types( void );
  73. static WarheadType Get_Warhead_Type( const char *name );
  74. static const char * Get_Warhead_Name( WarheadType type );
  75. // Save IDs
  76. static int Get_Armor_Save_ID( ArmorType type );
  77. static ArmorType Find_Armor_Save_ID( int id );
  78. static int Get_Warhead_Save_ID( WarheadType type );
  79. static ArmorType Find_Warhead_Save_ID( int id );
  80. // Damage Multiplier Settings
  81. // static void Set_Damage_Multiplier( ArmorType armor, WarheadType warhead, float multiplier );
  82. static float Get_Damage_Multiplier( ArmorType armor, WarheadType warhead );
  83. // Shield Absorbsion Settings
  84. // static void Set_Shield_Absorbsion( ArmorType armor, WarheadType warhead, float percent );
  85. static float Get_Shield_Absorbsion( ArmorType armor, WarheadType warhead );
  86. typedef enum {
  87. SPECIAL_DAMAGE_TYPE_NONE,
  88. SPECIAL_DAMAGE_TYPE_FIRE,
  89. SPECIAL_DAMAGE_TYPE_CHEM,
  90. SPECIAL_DAMAGE_TYPE_ELECTRIC,
  91. SPECIAL_DAMAGE_TYPE_CNC_FIRE,
  92. SPECIAL_DAMAGE_TYPE_CNC_CHEM,
  93. SPECIAL_DAMAGE_TYPE_SUPER_FIRE,
  94. NUM_SPECIAL_DAMAGE_TYPES, // Keep synced with ouch_types
  95. } SpecialDamageType;
  96. static SpecialDamageType Get_Special_Damage_Type( WarheadType type );
  97. static float Get_Special_Damage_Probability( WarheadType type );
  98. static WarheadType Get_Special_Damage_Warhead( SpecialDamageType type );
  99. static float Get_Special_Damage_Duration( SpecialDamageType type );
  100. static float Get_Special_Damage_Scale( SpecialDamageType type );
  101. static const char * Get_Special_Damage_Explosion( SpecialDamageType type );
  102. static float Get_Visceroid_Probability( WarheadType type );
  103. static bool Is_Skin_Impervious( SpecialDamageType type, ArmorType skin );
  104. private:
  105. static safe_float *Multipliers;
  106. static safe_float *Absorbsion;
  107. };
  108. /*
  109. **
  110. */
  111. class OffenseObjectClass {
  112. #define DEFAULT_DAMAGE 1.0f
  113. public:
  114. // Constructors & Destructor
  115. OffenseObjectClass( float damage = DEFAULT_DAMAGE, WarheadType warhead = 0, ArmedGameObj *owner = NULL ) : \
  116. Damage( damage ), Warhead( warhead ), ForceServerDamage( false ), EnableClientDamage( false ) { Set_Owner( owner ); }
  117. OffenseObjectClass( const OffenseObjectClass & base );
  118. ~OffenseObjectClass() { Set_Owner( NULL ); };
  119. bool Save( ChunkSaveClass & csave );
  120. bool Load( ChunkLoadClass & cload );
  121. // Offensive Damage Rating (ODR)
  122. void Set_Damage( float damage ) { Damage = damage; }
  123. float Get_Damage( void ) const { return Damage; }
  124. // Warhead
  125. void Set_Warhead( WarheadType warhead ) { Warhead = warhead; }
  126. WarheadType Get_Warhead( void ) const { return Warhead; }
  127. // Owner
  128. void Set_Owner( ArmedGameObj *owner ) { Owner = (ScriptableGameObj *)owner; }
  129. ArmedGameObj *Get_Owner( void ) const { return (ArmedGameObj *)Owner.Get_Ptr(); }
  130. // Special flag to force servers to apply damage. Only needed for client authoratative damage
  131. bool ForceServerDamage;
  132. // Special flag to disable client damage. So it only works for bullets. Only needed for client authoratative damage
  133. bool EnableClientDamage;
  134. private:
  135. // safe_float Damage;
  136. float Damage;
  137. WarheadType Warhead;
  138. GameObjReference Owner;
  139. };
  140. /**
  141. ** DefenseObjectClass
  142. ** This is a class that is meant to be embedded inside a game object and handles all health/damage
  143. ** tracking. Also, the definition for the game object which embeds this object can embed a
  144. ** DefenseObjectDefClass to automatically get all of the settings.
  145. **
  146. */
  147. class DefenseObjectDefClass;
  148. class DefenseObjectClass {
  149. #define DEFAULT_HEALTH 100.0f
  150. public:
  151. // Constructors & Destructor
  152. DefenseObjectClass( float health = DEFAULT_HEALTH, ArmorType skin = 0 ) :
  153. Health( health ), HealthMax( health ), Skin( skin ), ShieldStrength( 0 ), ShieldStrengthMax( 0 ), ShieldType( 0 ), CanObjectDie( true ) {};//,
  154. //LastSentHealth( -1 ), LastSentSkin( -1 ), LastSentShieldStrength( -1 ), LastSentShieldType( -1 ) {};
  155. ~DefenseObjectClass() {};
  156. // DefenseObjects now have a pointer to their cooresponing GameObj to report damage and scoring to the PlayerData
  157. void Init( const DefenseObjectDefClass & def, DamageableGameObj * owner);
  158. bool Save( ChunkSaveClass & csave );
  159. bool Load( ChunkLoadClass & cload );
  160. // Owner
  161. void Set_Owner( DamageableGameObj *owner ) { Owner = (ScriptableGameObj *)owner; }
  162. DamageableGameObj *Get_Owner( void ) const { return (DamageableGameObj *)Owner.Get_Ptr(); }
  163. // Skin
  164. void Set_Skin( ArmorType skin ) { Skin = skin; }
  165. ArmorType Get_Skin( void ) const { return Skin; }
  166. enum {MAX_MAX_HEALTH = 2000};//500};
  167. enum {MAX_MAX_SHIELD_STRENGTH = 2000};//500};
  168. // Health
  169. void Set_Health(float health);
  170. void Add_Health(float add_health);
  171. float Get_Health(void) const ;
  172. void Set_Health_Max(float health);
  173. float Get_Health_Max(void) const ;
  174. // Shield
  175. void Set_Shield_Strength(float str);
  176. void Add_Shield_Strength(float str);
  177. float Get_Shield_Strength(void) const ;
  178. void Set_Shield_Strength_Max(float str);
  179. float Get_Shield_Strength_Max(void) const ;
  180. void Set_Shield_Type( ArmorType type );
  181. unsigned long Get_Shield_Type( void ) const { return ShieldType; }
  182. // Apply Damage
  183. float Apply_Damage( const OffenseObjectClass & offense, float scale = 1.0f, int alternate_skin = -1 );
  184. float Do_Damage( const OffenseObjectClass & offense, float scale = 1.0f, int alternate_skin = -1 );
  185. // Request_Damage
  186. void Request_Damage( const OffenseObjectClass & offense, float scale = 1.0f );
  187. // Will an apply damage call actually repair?
  188. bool Is_Repair( const OffenseObjectClass & offense, float scale = 1.0f );
  189. // Would an apply damage call actually damage?
  190. bool Would_Damage( const OffenseObjectClass & offense, float scale = 1.0f );
  191. bool Is_Soft( void );
  192. void Set_Can_Object_Die( bool onoff ) { CanObjectDie = onoff; }
  193. // State import/export
  194. virtual void Import( BitStreamClass & packet );
  195. virtual void Export( BitStreamClass & packet );
  196. static void Set_Precision(void);
  197. float Get_Damage_Points(void) const { return DamagePoints; }
  198. float Get_Death_Points(void) const { return DeathPoints; }
  199. #ifdef WWDEBUG
  200. static bool Toggle_One_Shot_Kills(void) { OneShotKills = !OneShotKills; return OneShotKills; }
  201. #endif // _WWDEBUG
  202. private:
  203. safe_float Health;
  204. safe_float HealthMax;
  205. SafeArmorType Skin;
  206. safe_float ShieldStrength;
  207. safe_float ShieldStrengthMax;
  208. SafeArmorType ShieldType;
  209. safe_float DamagePoints;
  210. safe_float DeathPoints;
  211. bool CanObjectDie;
  212. GameObjReference Owner;
  213. void Mark_Owner_Dirty( void );
  214. #ifdef WWDEBUG
  215. static bool OneShotKills;
  216. #endif // _WWDEBUG
  217. };
  218. /**
  219. ** DefenseObjectDefClass
  220. ** This class is meant to be a component of a definition class for a game or physics
  221. ** object which contains a DefenseObject. Use the associated macro to make all of
  222. ** the member variables editable in your class.
  223. */
  224. class DefenseObjectDefClass
  225. {
  226. public:
  227. DefenseObjectDefClass(void);
  228. ~DefenseObjectDefClass(void);
  229. bool Save(ChunkSaveClass &csave);
  230. bool Load(ChunkLoadClass &cload);
  231. public:
  232. safe_float Health;
  233. safe_float HealthMax;
  234. SafeArmorType Skin;
  235. safe_float ShieldStrength;
  236. safe_float ShieldStrengthMax;
  237. SafeArmorType ShieldType;
  238. safe_float DamagePoints;
  239. safe_float DeathPoints;
  240. };
  241. /*
  242. ** Use this macro to make all of the member variables in a DefenseObjectDefClass editable.
  243. ** The first parameter to the macro is the type-name of your class (e.g. PhysicalGameObjectDef) and
  244. ** the second parameter is the name of the member variable which is the defense object def.
  245. */
  246. #ifdef PARAM_EDITING_ON
  247. #define DEFENSEOBJECTDEF_EDITABLE_PARAMS( class_name, member_name ) \
  248. \
  249. int param_counter; \
  250. NAMED_EDITABLE_PARAM( class_name, ParameterClass::TYPE_FLOAT, member_name ## .Health, "Health"); \
  251. NAMED_EDITABLE_PARAM( class_name, ParameterClass::TYPE_FLOAT, member_name ## .HealthMax, "HealthMax"); \
  252. \
  253. EnumParameterClass * skin_param = new EnumParameterClass( (int*)& member_name ## .Skin ); \
  254. skin_param->Set_Name("Skin"); \
  255. for ( param_counter = 0; param_counter < ArmorWarheadManager::Get_Num_Armor_Types(); param_counter++ ) { \
  256. skin_param->Add_Value(ArmorWarheadManager::Get_Armor_Name(param_counter), param_counter); \
  257. } \
  258. GENERIC_EDITABLE_PARAM(class_name,skin_param) \
  259. \
  260. NAMED_EDITABLE_PARAM( class_name, ParameterClass::TYPE_FLOAT, member_name ## .ShieldStrength, "ShieldStrength" ); \
  261. NAMED_EDITABLE_PARAM( class_name, ParameterClass::TYPE_FLOAT, member_name ## .ShieldStrengthMax, "ShieldStrengthMax" ); \
  262. \
  263. EnumParameterClass * shield_param = new EnumParameterClass( (int *)& member_name ## .ShieldType ); \
  264. shield_param->Set_Name ("Shield Type"); \
  265. for ( param_counter = 0; param_counter < ArmorWarheadManager::Get_Num_Armor_Types(); param_counter++ ) { \
  266. shield_param->Add_Value(ArmorWarheadManager::Get_Armor_Name(param_counter),param_counter); \
  267. } \
  268. GENERIC_EDITABLE_PARAM(class_name,shield_param) \
  269. \
  270. NAMED_EDITABLE_PARAM( class_name, ParameterClass::TYPE_FLOAT, member_name ## .DamagePoints, "DamagePoints"); \
  271. NAMED_EDITABLE_PARAM( class_name, ParameterClass::TYPE_FLOAT, member_name ## .DeathPoints, "DeathPoints");
  272. #else
  273. #define DEFENSEOBJECTDEF_EDITABLE_PARAMS( class_name, member_name )
  274. #endif
  275. #endif // DAMAGE_H