soldier.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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/soldier.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 3/29/02 1:41p $*
  29. * *
  30. * $Revision:: 192 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef SOLDIER_H
  36. #define SOLDIER_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef SMARTGAMEOBJ_H
  41. #include "smartgameobj.h"
  42. #endif
  43. #ifndef HUMANSTATE_H
  44. #include "humanstate.h"
  45. #endif
  46. #ifndef WWSTRING_H
  47. #include "wwstring.h"
  48. #endif
  49. #ifndef __DIALOGUE_HE
  50. #include "dialogue.h"
  51. #endif
  52. struct TransitionCompletionDataStruct;
  53. class PrivateTimerClass;
  54. class DynamicSpeechAnimClass;
  55. class TransitionEffectClass;
  56. class PersistantSurfaceEmitterClass;
  57. //const int NO_FLAG = -1;
  58. /*
  59. **
  60. */
  61. typedef enum {
  62. SOLDIER_INNATE_EVENT_ENEMY_SEEN = 1 << 0,
  63. SOLDIER_INNATE_EVENT_FOOTSTEP_HEARD = 1 << 1,
  64. SOLDIER_INNATE_EVENT_GUNSHOT_HEARD = 1 << 2,
  65. SOLDIER_INNATE_EVENT_BULLET_HEARD = 1 << 3,
  66. SOLDIER_INNATE_ACTIONS = 1 << 4,
  67. } SoldierInnateEvents;
  68. /*
  69. ** SoldierGameObjDef - Defintion class for a SoldierGameObj
  70. */
  71. class SoldierGameObjDef : public SmartGameObjDef
  72. {
  73. public:
  74. SoldierGameObjDef( void );
  75. virtual uint32 Get_Class_ID( void ) const;
  76. virtual PersistClass * Create( void ) const ;
  77. virtual bool Save( ChunkSaveClass &csave );
  78. virtual bool Load( ChunkLoadClass &cload );
  79. virtual const PersistFactoryClass & Get_Factory( void ) const;
  80. DialogueClass * Get_Dialog_List( void ) { return DialogList; }
  81. DECLARE_EDITABLE( SoldierGameObjDef, SmartGameObjDef );
  82. protected:
  83. float TurnRate;
  84. float JumpVelocity;
  85. float SkeletonHeight;
  86. float SkeletonWidth;
  87. bool UseInnateBehavior;
  88. float InnateAggressiveness;
  89. float InnateTakeCoverProbability;
  90. bool InnateIsStationary;
  91. DialogueClass DialogList[DIALOG_MAX];
  92. StringClass FirstPersonHands;
  93. int HumanAnimOverrideDefID;
  94. int HumanLoiterCollectionDefID;
  95. int DeathSoundPresetID;
  96. friend class SoldierGameObj;
  97. friend class SoldierObserverClass;
  98. };
  99. /*
  100. **
  101. */
  102. class SoldierGameObj : public SmartGameObj {
  103. public:
  104. SoldierGameObj();
  105. virtual ~SoldierGameObj();
  106. // Definitions
  107. virtual void Init( void );
  108. void Init( const SoldierGameObjDef & definition );
  109. void Copy_Settings( const SoldierGameObjDef & definition );
  110. void Re_Init( const SoldierGameObjDef & definition );
  111. const SoldierGameObjDef & Get_Definition( void ) const ;
  112. // Save / Load / Construction Factory
  113. virtual bool Save( ChunkSaveClass & csave );
  114. virtual bool Load( ChunkLoadClass & cload );
  115. virtual void On_Post_Load( void );
  116. virtual const PersistFactoryClass & Get_Factory( void ) const;
  117. // Physics
  118. HumanPhysClass * Peek_Human_Phys( void ) const;
  119. // Think
  120. virtual void Think( void );
  121. virtual void Post_Think( void );
  122. //virtual void Think_Pathfind( void );
  123. // Control
  124. virtual void Set_Control_Owner(int control_owner);
  125. virtual void Generate_Control( void );
  126. virtual void Apply_Control( void );
  127. // Damage
  128. virtual void Apply_Damage( const OffenseObjectClass & damager, float scale = 1.0f, int alternate_skin = -1 );
  129. virtual void Apply_Damage_Extended( const OffenseObjectClass & offense, float scale = 1.0f,
  130. const Vector3 & direction = Vector3( 0,0,0 ), const char * collision_box_name = NULL );
  131. virtual void Completely_Damaged( const OffenseObjectClass & damager ) {}
  132. virtual CollisionReactionType Collision_Occurred( const CollisionEventClass & event );
  133. virtual Vector3 Get_Bullseye_Position( void );
  134. // Turret
  135. virtual bool Is_Turreted( void ) { return false; }
  136. // Weapons
  137. virtual bool Set_Targeting( const Vector3 & pos, bool do_tilt = true );
  138. float Get_Weapon_Height( void );
  139. float Get_Weapon_Length( void );
  140. virtual const Matrix3D &Get_Muzzle( int index = 0 );
  141. bool Detonate_C4( void ) { return DetonateC4; }
  142. // Display
  143. virtual void Set_Weapon_Model( const char *model_name );
  144. virtual void Set_Weapon_Animation( const char *anim_name );
  145. virtual void Start_Transition_Animation( const char * anim_name, TransitionCompletionDataStruct * completion_data );
  146. virtual void Set_Animation( const char *animation_name, bool looping = true, float frame_offset = 0.0f );
  147. virtual void Set_Blended_Animation( const char *animation_name, bool looping = true, float frame_offset = 0.0f, bool play_backwards = false );
  148. void Handle_Legs( void );
  149. // Ladders
  150. void Exit_Ladder( void );
  151. void Enter_Ladder( bool top );
  152. // Network support
  153. virtual void Import_State_Cs( BitStreamClass & packet );
  154. virtual void Export_State_Cs( BitStreamClass & packet );
  155. void Interpret_Sc_Position_Data(const Vector3 & sc_position);
  156. void Interpret_Sc_State_Data(HumanStateClass::HumanStateType state,
  157. int sub_state, LPCSTR trans_name, const Vector3 & velocity, const Vector3 & sc_position);
  158. int Tally_Vis_Visible_Soldiers(void);
  159. bool Is_In_Elevator(void);
  160. virtual void Export_Creation( BitStreamClass &packet );
  161. virtual void Import_Creation( BitStreamClass &packet );
  162. virtual void Export_Rare( BitStreamClass &packet );
  163. virtual void Import_Rare( BitStreamClass &packet );
  164. virtual void Export_Occasional( BitStreamClass &packet );
  165. virtual void Import_Occasional( BitStreamClass &packet );
  166. virtual void Export_Frequent( BitStreamClass & packet );
  167. virtual void Import_Frequent( BitStreamClass & packet );
  168. bool Is_Dead( void ) { return Get_State() == HumanStateClass::DEATH; }
  169. bool Is_Destroyed( void ) { return Get_State() == HumanStateClass::DESTROY; }
  170. bool Is_Upright( void ) { return Get_State() == HumanStateClass::UPRIGHT; }
  171. bool Is_Wounded( void ) { return Get_State() == HumanStateClass::WOUNDED; }
  172. bool In_Transition( void ) { return Get_State() == HumanStateClass::TRANSITION; }
  173. bool Is_Airborne( void ) { return Get_State() == HumanStateClass::AIRBORNE; }
  174. bool Is_Crouched( void ) { return HumanState.Get_State_Flag( HumanStateClass::CROUCHED_FLAG ); }
  175. bool Is_Sniping( void ) { return HumanState.Get_State_Flag( HumanStateClass::SNIPING_FLAG ); }
  176. bool Is_Slow( void ) { return (Get_Sub_State() & HumanStateClass::SUB_STATE_SLOW) != 0; }
  177. bool Is_On_Ladder( void ) { return Get_State() == HumanStateClass::LADDER; }
  178. bool Is_State_Locked( void ) { return HumanState.Is_Locked(); }
  179. bool Is_In_Vehicle( void ) { return Get_State() == HumanStateClass::IN_VEHICLE; }
  180. void Reset_Loiter_Delay( void ) { HumanState.Reset_Loiter_Delay(); }
  181. void Set_Loiters_Allowed( bool allowed ) { HumanState.Set_Loiters_Allowed( allowed ); }
  182. virtual void Get_Information( StringClass & string );
  183. //virtual void Get_Extended_Information( StringClass & description );
  184. virtual void Get_Description(StringClass & description);
  185. void Toggle_Fly_Mode( void ); // Fly mode (for debugging/screen shots)
  186. // Object Motion
  187. virtual float Get_Max_Speed( void );
  188. virtual void Set_Max_Speed( float speed );
  189. virtual float Get_Turn_Rate( void );
  190. // Vehicles
  191. void Enter_Vehicle( VehicleGameObj * vehicle, const char * anim_name );
  192. void Exit_Vehicle( void );
  193. void Exit_Destroyed_Vehicle( int seat_num, const Vector3 & vehicle_pos );
  194. bool Is_Permitted_To_Enter_Vehicle( void );
  195. VehicleGameObj * Get_Vehicle( void ) { return Vehicle; }
  196. VehicleGameObj * Get_Profile_Vehicle( void ); // HACK
  197. bool Use_Ladder_View( void );
  198. StringClass Get_Animation_Name( void ) { return AnimationName; }
  199. const char * Get_State_Name( void ) { return HumanState.Get_State_Name(); }
  200. HumanStateClass * Get_Human_State( void ) { return &HumanState; }
  201. void Set_Model(const char *model_name);
  202. // Type identification
  203. virtual SoldierGameObj *As_SoldierGameObj() { return this; };
  204. // Velocity
  205. void Get_Velocity(Vector3 & vel);
  206. void Set_Velocity(Vector3 & vel);
  207. void Give_All_Weapons(void);
  208. bool Can_See(SoldierGameObj * p_soldier);
  209. // Rendering
  210. void Adjust_Skeleton( float height, float width );
  211. /*
  212. // Capture The Flag
  213. void Set_Ctf_Team_Flag(int team);
  214. int Get_Ctf_Team_Flag(void) {return CtfTeamFlag;}
  215. */
  216. // Head Looking
  217. void Look_At( const Vector3 & pos, float time ) { HeadLookTarget = pos; HeadLookDuration = time; HeadLookAngle = Vector3(0,0,0); }
  218. void Update_Look_At( const Vector3 & pos ) { HeadLookTarget = pos; }
  219. void Cancel_Look_At( void ) { HeadLookDuration = 0.001F; }
  220. void Look_Random( float time );
  221. bool Is_Looking( void ) { return (HeadLookDuration > 0); }
  222. virtual Matrix3D Get_Look_Transform(void);
  223. // Head and facing
  224. void Lock_Facing( PhysicalGameObj * game_obj, bool turn_body );
  225. // Innate Disabling
  226. void Innate_Enable( int bits = 0xFFFFFFFF ) { InnateEnableBits |= bits; }
  227. void Innate_Disable( int bits = 0xFFFFFFFF ) { InnateEnableBits &= ~bits; }
  228. bool Is_Innate_Enabled( int bits = 0xFFFFFFFF ) { return (InnateEnableBits & bits) != 0; }
  229. //static void Set_Precision(void);
  230. // Dialog support
  231. void Say_Dialogue( int dialog_id );
  232. static float Say_Dynamic_Dialogue( int text_id, SoldierGameObj *speaker = NULL, AudibleSoundClass **sound_obj_to_return = NULL );
  233. void Stop_Current_Speech( void );
  234. RenderObjClass * Find_Head_Model( void );
  235. void Prepare_Speech_Framework( void );
  236. //
  237. // "Ghost" support. "Ghosts" are soldier's who have their collision turned off
  238. // so they can walk through other soldiers.
  239. //
  240. void Enable_Ghost_Collision( bool onoff );
  241. bool Is_Soldier_Blocked( const Vector3 &curr_pos );
  242. bool Is_Safe_To_Disable_Ghost_Collision( const Vector3 &curr_pos );
  243. //
  244. // Speech support
  245. //
  246. DynamicSpeechAnimClass *Get_Facial_Anim (void) { return SpeechAnim; }
  247. void Set_Emot_Icon (const char *model_name, float duration );
  248. // Innate AI access
  249. SoldierObserverClass * Get_Innate_Controller( void );
  250. SoldierAIState Get_AI_State( void ) const { return AIState; }
  251. void Set_AI_State( SoldierAIState state );
  252. // Innate observer access
  253. void Set_Innate_Observer( SoldierObserverClass * observer ) { InnateObserver = observer; }
  254. SoldierObserverClass * Get_Innate_Observer( void ) { return InnateObserver; }
  255. void Clear_Innate_Observer( void ) { InnateObserver = NULL; }
  256. const char * Get_First_Person_Hands_Model_Name( void );
  257. void Perturb_Position(float max_perturb = 5);
  258. int Get_Key_Ring( void ) const { return KeyRing; }
  259. void Give_Key( int key_number ) { KeyRing |= (1 << key_number); }
  260. void Remove_Key( int key_number ) { KeyRing &= ~(1 << key_number); }
  261. bool Has_Key( int key_number ) { return ((1 << key_number) & KeyRing) != 0; }
  262. virtual bool Wants_Powerups( void ) { return Is_Human_Controlled(); }
  263. virtual bool Allow_Special_Damage_State_Lock( void ) { return (Is_Human_Controlled() == false); }
  264. virtual bool Is_Visible( void ) { return IsVisible; }
  265. void Set_Is_Visible( bool visible ) { IsVisible = visible; }
  266. //
  267. // Static debug support
  268. //
  269. static void Enable_Ghost_Collision_Debug_Display (bool onoff) { DisplayDebugBoxForGhostCollision = onoff; }
  270. static bool Is_Ghost_Collision_Debug_Display_Enabled (void) { return DisplayDebugBoxForGhostCollision; }
  271. virtual bool Is_Targetable( void ) const;
  272. // Stealth
  273. virtual float Get_Stealth_Fade_Distance(void) const;
  274. protected:
  275. RenderObjClass * WeaponRenderModel;
  276. RenderObjClass * BackWeaponRenderModel;
  277. RenderObjClass * BackFlagRenderModel;
  278. AnimControlClass * WeaponAnimControl;
  279. bool DetonateC4;
  280. TransitionCompletionDataStruct * TransitionCompletionData;
  281. StringClass AnimationName;
  282. VehicleGameObj * Vehicle;
  283. HumanStateClass HumanState;
  284. float LegFacing; // Direction the legs are facing
  285. bool SyncLegs; // Are we in the process of syncing the legs?
  286. bool LastLegMode;
  287. int KeyRing;
  288. bool IsUsingGhostCollision;
  289. DialogueClass DialogList[DIALOG_MAX];
  290. AudibleSoundClass * CurrentSpeech;
  291. // Head Look
  292. float HeadLookDuration;
  293. Vector3 HeadRotation;
  294. Vector3 HeadLookTarget;
  295. Vector3 HeadLookAngle;
  296. float HeadLookAngleTimer;
  297. HumanStateClass::HumanStateType Get_State( void ) { return HumanState.Get_State(); }
  298. int Get_Sub_State( void ) { return HumanState.Get_Sub_State(); }
  299. void Update_Locked_Facing( void );
  300. void Update_Back_Gun( void );
  301. void Set_Back_Weapon_Model( const char *model_name );
  302. // Move below to public?
  303. void Set_Back_Flag_Model( const char *model_name, const Vector3 & tint = Vector3(0, 0, 0) );
  304. int Get_Ouch_Type( const Vector3 & direction, const char * collision_box_name ) { return HumanState.Get_Ouch_Type( direction, collision_box_name ); }
  305. bool Internal_Set_Targeting( const Vector3 & pos, bool do_tilt = true );
  306. ArmorWarheadManager::SpecialDamageType SpecialDamageMode;
  307. float SpecialDamageTimer;
  308. GameObjReference SpecialDamageDamager;
  309. TransitionEffectClass * SpecialDamageEffect;
  310. void Set_Special_Damage_Mode( ArmorWarheadManager::SpecialDamageType mode, ArmedGameObj * damager = NULL );
  311. TransitionEffectClass * HealingEffect;
  312. void Handle_Head_look( void );
  313. //int CtfTeamFlag; // Capture The Flag - use NO_FLAG for no flag
  314. GameObjReference FacingObject;
  315. bool FacingAllowBodyTurn;
  316. int InnateEnableBits;
  317. SoldierObserverClass *InnateObserver;
  318. SoldierAIState AIState;
  319. DynamicSpeechAnimClass *SpeechAnim;
  320. float GenerateIdleFacialAnimTimer;
  321. RenderObjClass * HeadModel;
  322. RenderObjClass * EmotIconModel;
  323. float EmotIconTimer;
  324. bool InFlyMode;
  325. bool IsVisible;
  326. bool LadderUpMask;
  327. bool LadderDownMask;
  328. float ReloadingTilt;
  329. bool WeaponChanged;
  330. PersistantSurfaceEmitterClass * WaterWake;
  331. // Soldiers maintain all RenderObjs they have created for later use and saving
  332. // This is used for weapon models
  333. DynamicVectorClass<RenderObjClass*> RenderObjList;
  334. void Add_RenderObj( RenderObjClass * obj );
  335. RenderObjClass * Find_RenderObj( const char * name );
  336. void Reset_RenderObjs( void );
  337. void Update_Healing_Effect( void );
  338. //
  339. // Static debug support
  340. //
  341. static bool DisplayDebugBoxForGhostCollision;
  342. int Check(void);
  343. };
  344. #endif // SOLDIER_H