soldierobserver.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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/soldierobserver.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 11/29/01 11:03a $*
  29. * *
  30. * $Revision:: 44 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef SOLDIEROBSERVER_H
  36. #define SOLDIEROBSERVER_H
  37. #include "always.h"
  38. #include "persistentgameobjobserver.h"
  39. #include "vector3.h"
  40. #include "gameobjref.h"
  41. #include "cover.h"
  42. #include "wwstring.h"
  43. #include "actionparams.h"
  44. class SoldierGameObj;
  45. class PhysicalGameObj;
  46. class SoldierObserverClass : public PersistentGameObjObserverClass
  47. {
  48. public:
  49. SoldierObserverClass(void);
  50. virtual ~SoldierObserverClass(void);
  51. virtual const char * Get_Name( void ) { return "Innate Soldier"; }
  52. // PersistClass interface
  53. virtual const PersistFactoryClass& Get_Factory(void) const;
  54. virtual bool Save(ChunkSaveClass &csave);
  55. virtual bool Load(ChunkLoadClass &cload);
  56. // GameObjObserverClass interface
  57. virtual void Attach(GameObject* obj);
  58. virtual void Detach(GameObject* obj);
  59. virtual void Created( GameObject * obj );
  60. virtual void Destroyed( GameObject * obj );
  61. virtual void Killed( GameObject * obj, GameObject * killer );
  62. virtual void Damaged( GameObject * obj, GameObject * damager, float amount );
  63. virtual void Custom( GameObject * obj, int type, int param, GameObject * sender );
  64. virtual void Sound_Heard( GameObject * obj, const CombatSound & sound );
  65. virtual void Enemy_Seen( GameObject * obj, GameObject * enemy );
  66. virtual void Action_Complete( GameObject * obj, int action_id, ActionCompleteReason complete_reason );
  67. virtual void Timer_Expired( GameObject * obj, int timer_id );
  68. virtual void Animation_Complete( GameObject * obj, const char * animation_name ) {}
  69. virtual void Poked( GameObject * obj, GameObject * poker );
  70. virtual void Entered( GameObject * obj, GameObject * enterer ) {}
  71. virtual void Exited( GameObject * obj, GameObject * exiter ) {}
  72. // State access
  73. void Reset_Conversation_Timer( void );
  74. void Set_Home_Location( const Vector3& location, float radius ) { HomeLocation = location; HomeRadius = radius; }
  75. void Set_Aggressiveness( float aggressiveness ) { Aggressiveness = aggressiveness; }
  76. void Set_Take_Cover_Probability( float probability ) { TakeCoverProbability = probability; }
  77. void Set_Is_Stationary( bool stationary ) { IsStationary = stationary; }
  78. void Get_Information( StringClass & string );
  79. typedef enum {
  80. SOLDIER_AI_RELAXED_IDLE = 0,
  81. SOLDIER_AI_ALERT_IDLE,
  82. SOLDIER_AI_FOOTSTEPS_HEARD,
  83. SOLDIER_AI_BULLET_HEARD,
  84. SOLDIER_AI_GUNSHOT_HEARD,
  85. SOLDIER_AI_ENEMY_SEEN,
  86. NUM_SOLDIER_AI_STATES,
  87. SOLDIER_AI_CONDITIONAL_IDLE = 100,
  88. } SoldierAIStates;
  89. bool Set_State( SoldierGameObj * soldier, int state, const Vector3& location = Vector3(0,0,0), GameObject* enemy = NULL);
  90. private:
  91. int State; // Current State
  92. float StateTimer; // Time spent in this state
  93. Vector3 HomeLocation; // Location to stay centered around
  94. float HomeRadius; // Radius to stay within
  95. Vector3 AlertPosition;
  96. float ActionTimer; // Used to make us change actions periodically
  97. GameObjReference EnemyObject;
  98. bool CoveredAttack;
  99. CoverEntryClass * CoverPosition;
  100. float ConversationTimer;
  101. bool IsAlerted;
  102. float Aggressiveness;
  103. float TakeCoverProbability;
  104. bool IsStationary;
  105. StringClass SubStateString;
  106. int LastEvent;
  107. int LastWeaponIndex;
  108. /*
  109. ** Innate AI States
  110. */
  111. void State_Changed( SoldierGameObj * soldier );
  112. void Notify_Neighbors_Sound( SoldierGameObj * soldier, const CombatSound & sound );
  113. void Notify_Neighbors_Enemy( SoldierGameObj * soldier, GameObject * enemy );
  114. /*
  115. ** Innate AI State Actions
  116. */
  117. void Think( SoldierGameObj * soldier, bool is_new_state = false );
  118. void State_Act( SoldierGameObj* soldier, bool is_new_state = false );
  119. void State_Act_Idle( SoldierGameObj * soldier );
  120. void State_Act_Footsteps_Heard( SoldierGameObj * soldier );
  121. void State_Act_Bullet_Heard( SoldierGameObj * soldier, bool is_new_state );
  122. void State_Act_Gunshot_Heard( SoldierGameObj * soldier );
  123. void State_Act_Attack( SoldierGameObj * soldier );
  124. /*
  125. ** Innate AI Actions
  126. */
  127. void Action_Reset( SoldierGameObj * soldier );
  128. void Action_Face_Location( SoldierGameObj * soldier, const Vector3 & location, SoldierAIState ai_state, bool crouched = false );
  129. void Action_Goto_Location( SoldierGameObj * soldier, const Vector3 & location, SoldierAIState ai_state, float speed = 1.0f, float distance = 1.0f, bool crouched = false );
  130. void Action_Goto_Location_Facing( SoldierGameObj * soldier, const Vector3 & location, SoldierAIState ai_state, const Vector3 & facing_pos, float speed = 1.0f, float distance = 1.0f, bool crouched = false );
  131. void Action_Attack_Object( SoldierGameObj * soldier, PhysicalGameObj * enemy, float range, bool kneel, const Vector3 & move_location, float arrived_distance );
  132. void Action_Dive( SoldierGameObj * soldier, const Vector3 & location );
  133. void Stay_Within_Home( SoldierGameObj * soldier, Vector3 * location, float * distance );
  134. bool Take_Cover( SoldierGameObj * soldier, bool force_face = false, const Vector3 & face_pos = Vector3(0,0,0) );
  135. void Look_Random( SoldierGameObj * soldier, float duration );
  136. /*
  137. ** Innate AI Cover Positions
  138. */
  139. void Release_Cover_Position( void );
  140. };
  141. #endif // SOLDIEROBSERVER_H