smartgameobj.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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/smartgameobj.h $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 11/27/01 11:45a $*
  29. * *
  30. * $Revision:: 124 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef SMARTGAMEOBJ_H
  36. #define SMARTGAMEOBJ_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef ARMEDGAMEOBJ_H
  41. #include "armedgameobj.h"
  42. #endif
  43. #ifndef ACTION_H
  44. #include "action.h"
  45. #endif
  46. #ifndef CONTROL_H
  47. #include "control.h"
  48. #endif
  49. #ifndef COMBATSOUND_H
  50. #include "combatsound.h"
  51. #endif
  52. #ifndef PHYSCONTROL_H
  53. #include "physcontrol.h"
  54. #endif
  55. #ifndef __AUDIO_EVENTS_H
  56. #include "audioevents.h"
  57. #endif
  58. /*
  59. **
  60. */
  61. class VehicleGameObj;
  62. class SoldierGameObj;
  63. class BitStreamClass;
  64. class PlayerDataClass;
  65. class StealthEffectClass;
  66. /*
  67. ** SmartGameObjDef - Defintion class for a SmartGameObj
  68. */
  69. class SmartGameObjDef : public ArmedGameObjDef
  70. {
  71. public:
  72. SmartGameObjDef( void );
  73. virtual bool Save( ChunkSaveClass &csave );
  74. virtual bool Load( ChunkLoadClass &cload );
  75. DECLARE_EDITABLE( SmartGameObjDef, ArmedGameObjDef );
  76. protected:
  77. float SightRange;
  78. float SightArc;
  79. float ListenerScale;
  80. bool IsStealthUnit;
  81. friend class SmartGameObj;
  82. };
  83. /*
  84. **
  85. */
  86. class SmartGameObj : public ArmedGameObj {
  87. public:
  88. // Constructor and Destructor
  89. SmartGameObj( void );
  90. virtual ~SmartGameObj( void );
  91. // Definitions
  92. void Init( const SmartGameObjDef & definition );
  93. void Copy_Settings( const SmartGameObjDef & definition );
  94. void Re_Init( const SmartGameObjDef & definition );
  95. const SmartGameObjDef & Get_Definition( void ) const ;
  96. // Save / Load
  97. virtual bool Save( ChunkSaveClass & csave );
  98. virtual bool Load( ChunkLoadClass & cload );
  99. virtual void On_Post_Load(void);
  100. // Commands
  101. void Clear_Control( void ) { Control.Clear_Control(); }
  102. void Set_Boolean_Control( ControlClass::BooleanControl control, bool state = true ) { Control.Set_Boolean( control, state ); }
  103. void Set_Analog_Control( ControlClass::AnalogControl control, float value ) { Control.Set_Analog( control, value ); }
  104. void Import_Control_Cs( BitStreamClass & packet ) { Control.Import_Cs(packet); }
  105. void Export_Control_Cs( BitStreamClass & packet ) { Control.Export_Cs(packet); }
  106. void Import_Control_Sc( BitStreamClass & packet ) { Control.Import_Sc(packet); }
  107. void Export_Control_Sc( BitStreamClass & packet ) { Control.Export_Sc(packet); }
  108. ControlClass & Get_Control() { return Control; }
  109. void Control_Enable( bool enable ) { ControlEnabled = enable; }
  110. bool Is_Control_Enabled( void ) { return ControlEnabled; }
  111. void Reset_Controller( void );
  112. // Update this objects control by reading inputs or running AI/action code
  113. virtual void Generate_Control( void );
  114. // Client who controls this object
  115. enum {
  116. SERVER_CONTROL_OWNER = -99999,
  117. };
  118. int Get_Control_Owner(void) { return ControlOwner; }
  119. virtual int Get_Weapon_Control_Owner(void) { return Get_Control_Owner(); }
  120. virtual void Set_Control_Owner(int control_owner) { ControlOwner = control_owner; }
  121. // Player Data
  122. PlayerDataClass * Get_Player_Data( void ) { return PlayerData; }
  123. void Set_Player_Data( PlayerDataClass * player_data );
  124. bool Has_Player(void);
  125. bool Is_Human_Controlled(void);
  126. bool Is_Controlled_By_Me(void);
  127. // Act on this object's control state
  128. virtual void Apply_Control( void );
  129. // Thinking
  130. virtual void Think();
  131. virtual void Post_Think();
  132. // Damage
  133. virtual void Apply_Damage( const OffenseObjectClass & damager, float scale = 1.0f, int alternate_skin = -1 );
  134. // Object Motion
  135. virtual float Get_Max_Speed( void ) { return 10; }
  136. virtual float Get_Turn_Rate( void ) { return DEG_TO_RADF(360); }
  137. // Actions
  138. ActionClass *Get_Action( void ) { return &Action; }
  139. // Type identification
  140. virtual SmartGameObj *As_SmartGameObj() { return this; };
  141. // State import/export
  142. virtual void Import_Frequent( BitStreamClass & packet );
  143. virtual void Export_Frequent( BitStreamClass & packet );
  144. virtual void Import_State_Cs( BitStreamClass & packet );
  145. virtual void Export_State_Cs( BitStreamClass & packet );
  146. virtual void Export_Creation( BitStreamClass & packet );
  147. virtual void Import_Creation( BitStreamClass & packet );
  148. bool Is_Control_Data_Dirty(cPacket & packet);
  149. bool Is_Obj_Visible( PhysicalGameObj *obj );
  150. void Set_Enemy_Seen_Enabled( bool enabled ) { IsEnemySeenEnabled = enabled; }
  151. bool Is_Enemy_Seen_Enabled( void ) { return IsEnemySeenEnabled; }
  152. virtual Matrix3D Get_Look_Transform(void) { return Get_Transform(); }
  153. virtual void Get_Velocity(Vector3 & vel) {vel.Set(0, 0, 0);}
  154. virtual bool Is_Visible( void ) { return true; }
  155. virtual void On_Logical_Heard (LogicalListenerClass *listener, LogicalSoundClass *sound_obj);
  156. virtual void Begin_Hibernation( void );
  157. virtual void End_Hibernation( void );
  158. virtual void Get_Information( StringClass & string );
  159. //
  160. // Stealth interface
  161. // Enable_Stealth - turn this object's cloaking device on or off
  162. // Is_Stealth_Enabled - is this object's cloaking device turned on? (may not be cloaked yet though)
  163. // Is_Stealthed - is the object actually stealthed (takes some time to turn on and off...)
  164. // Get_Stealth_Fade_Distance - humans and vehicles fade in at different distances.
  165. //
  166. void Enable_Stealth(bool onoff);
  167. void Toggle_Stealth(void);
  168. bool Is_Stealth_Enabled(void);
  169. bool Is_Stealthed(void) const;
  170. virtual float Get_Stealth_Fade_Distance(void) const { return 25.0f; }
  171. void Grant_Stealth_Powerup(float seconds);
  172. float Remaining_Stealth_Powerup_Time(void);
  173. StealthEffectClass * Peek_Stealth_Effect(void);
  174. static float Get_Global_Sight_Range_Scale( void ) { return GlobalSightRangeScale; }
  175. static void Set_Global_Sight_Range_Scale( float scale ) { GlobalSightRangeScale = scale; }
  176. protected:
  177. ControlClass Control;
  178. PhysControllerClass Controller; // controller for the physics object
  179. bool ControlEnabled;
  180. void Alloc_Stealth_Effect(void);
  181. bool StealthEnabled; // stealth enabled by script or initialization code
  182. float StealthPowerupTimer; // stealth power is in effect
  183. float StealthFiringTimer; // timer for de-cloaking during
  184. StealthEffectClass * StealthEffect; // possible stealth effect
  185. private:
  186. ActionClass Action; // for actions
  187. int ControlOwner; // Client who controls this object
  188. PlayerDataClass * PlayerData;
  189. bool IsEnemySeenEnabled;
  190. float MovingSoundTimer;
  191. LogicalListenerClass* Listener;
  192. void Register_Listener(void);
  193. static float GlobalSightRangeScale;
  194. };
  195. #endif // SMARTGAMEOBJ_H
  196. //MOBIUS_CONTROL_OWNER = -1