!I (1670414, 1670415, 1670416, 1670424, 1670431):
[CRYENGINE.git] / Code / GameSDK / GameDll / HitDeathReactionsDefs.h
blob013dd104ddb6a5c9405ea5b3040a82c8a05c3d99
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 /*************************************************************************
4 -------------------------------------------------------------------------
5 Description:
7 -------------------------------------------------------------------------
8 History:
9 - 23:2:2010 17:14 : Created by David Ramos
10 *************************************************************************/
11 #pragma once
12 #ifndef __HIT_DEATH_REACTIONS_DEFS_H
13 #define __HIT_DEATH_REACTIONS_DEFS_H
15 #include <CryScriptSystem/ScriptHelpers.h> // SmartScriptTable
16 #include <CryAISystem/IAgent.h> // EStance enumeration
17 #include <CryAnimation/CryCharAnimationParams.h> // anim flags
18 #include <CryAnimation/ICryAnimation.h>
19 #include "ICryMannequin.h"
22 // Utility enum for specifying cardinal directions
23 enum ECardinalDirection
25 eCD_Invalid = -1,
27 // "90º" directions
28 eCD_Forward,
29 eCD_Back,
30 eCD_Left,
31 eCD_Right,
33 // "180º" direction
34 eCD_Ahead,
35 eCD_Behind,
36 eCD_LeftSide,
37 eCD_RightSide,
40 enum EAirState
42 eAS_Unset = -1,
43 eAS_OnGround,
44 eAS_OnObject,
45 eAS_OnGroundOrObject,
46 eAS_InAir,
49 // For the streaming request and releases
50 enum EReactionsRequestsFlags
52 eRRF_Alive = 1,
53 eRRF_OutFromPool = 2,
54 eRRF_AIEnabled = 4,
57 // Utility typedefs
58 typedef SmartScriptTable ScriptTablePtr;
59 enum { INVALID_PROFILE_ID = 0xFFFFFFFF };
60 typedef uint32 ProfileId;
61 typedef int ReactionId;
63 // Forward declarations
64 class CHitDeathReactions;
66 //
67 namespace
69 const char VALIDATION_ID[] = "__validationId";
70 const char REACTION_ID[] = "__reactionId";
71 const ReactionId INVALID_REACTION_ID = 0;
72 const unsigned char NO_COLLISION_REACTION = 0;
73 const uint32 DEFAULT_REACTION_ANIM_FLAGS = CA_FORCE_SKELETON_UPDATE | CA_DISABLE_MULTILAYER | CA_REPEAT_LAST_KEY | CA_ALLOW_ANIM_RESTART | CA_FORCE_TRANSITION_TO_ANIM;
74 const char HIT_DEATH_REACTIONS_SCRIPT_TABLE[] = "HitDeathReactions";
77 //////////////////////////////////////////////////////////////////////////
78 // Functor for random_shuffle
79 //////////////////////////////////////////////////////////////////////////
80 struct SRandomGeneratorFunct
82 SRandomGeneratorFunct(CMTRand_int32& pseudoRandomGenerator);
84 using result_type = uint32;
85 static constexpr result_type min() { return std::numeric_limits<result_type>::lowest(); }
86 static constexpr result_type max() { return std::numeric_limits<result_type>::max(); }
87 result_type operator()()
89 return static_cast<result_type>(m_pseudoRandomGenerator.GenerateUint32());
92 CMTRand_int32& m_pseudoRandomGenerator;
95 class CFragmentCache;
97 //////////////////////////////////////////////////////////////////////////
98 // Struct holding all the reaction parameters
99 //////////////////////////////////////////////////////////////////////////
100 struct SReactionParams
102 typedef std::vector<uint32> AnimCRCContainer;
104 //////////////////////////////////////////////////////////////////////////
105 struct SReactionAnim
107 SReactionAnim();
108 ~SReactionAnim();
110 void Reset();
112 int GetNextReactionAnimIndex() const;
113 int GetNextReactionAnimId(const IAnimationSet* pAnimSet) const;
114 void RequestNextAnim(const IAnimationSet* pAnimSet) const;
115 void ReleaseRequestedAnims();
117 int iLayer;
118 uint32 animFlags;
119 float fOverrideTransTimeToAG; // Used for overriding the transition time the animation on the current AG state is going to use when resumed
120 mutable AnimCRCContainer animCRCs; // List of animation CRCs
121 bool bAdditive;
122 bool bNoAnimCamera; // It won't trigger animation controlled camera even on 1st person
124 private:
125 void UpdateRequestedAnimStatus() const; // Checks if the requested anim has been loaded and calls OnAnimLoaded() if it is
126 void OnTimer(void* pUserData, IGameFramework::TimerID handler) const;
127 void OnAnimLoaded() const;
129 mutable int16 m_iNextAnimIndex;
130 mutable uint32 m_nextAnimCRC;
131 mutable uint32 m_requestedAnimCRC;
132 mutable IGameFramework::TimerID m_iTimerHandle;
134 DECLARE_SHARED_POINTERS(SReactionAnim);
136 //////////////////////////////////////////////////////////////////////////
137 struct SAnimGraphReaction
139 struct SVariationData
141 SVariationData() {}
142 SVariationData(const char* szName, const char* szValue) : sName(szName), sValue(szValue) {}
144 void GetMemoryUsage(ICrySizer * s) const
146 s->AddObject(sName);
147 s->AddObject(sValue);
150 string sName;
151 string sValue;
153 typedef std::vector<SVariationData> VariationsContainer;
155 void Reset();
157 string sAGInputValue; // Value that will be set in the signal input on the Animation Graph
158 VariationsContainer variations; // List of all the variations
160 //////////////////////////////////////////////////////////////////////////
161 struct SMannequinData
163 enum EActionType
165 EActionType_Fragment,
166 EActionType_Coop,
167 EActionType_FragTagCopyingFragment,
168 EActionType_DoNothing,
169 EActionType_Last = EActionType_DoNothing,
171 EActionType_Invalid,
174 void Initialize( const IActionController* piActionController );
175 void AddDB( const IActionController* piActionController, const IAnimationDatabase* piAnimationDatabase ) const;
176 int GetNextReactionAnimIndex() const;
177 int GetCurrentReactionAnimIndex() const;
178 void RequestNextAnim( const IActionController* piActionController ) const;
179 void ReleaseRequestedAnims();
180 bool IsCurrentFragmentLoaded() const;
182 SMannequinData() { Reset(); }
183 void Reset();
185 TagState tagState;
186 mutable uint32 m_iNextOptionIndex;
187 EActionType actionType;
189 uint32 m_numOptions;
191 // Added at the end of C3 because MP hitdeath works so differently the new precaching system was crashing.
192 // Essentially the way it worked before pre-caching was added.
193 mutable uint32 m_animIndexMP;
195 private:
197 void UpdateRequestedAnimStatus() const; // Checks if the requested anim has been loaded and calls OnAnimLoaded() if it is
198 void OnTimer(void* pUserData, IGameFramework::TimerID handler) const;
199 void OnAnimLoaded() const;
201 mutable IGameFramework::TimerID m_iTimerHandle;
202 mutable std::shared_ptr<CFragmentCache> m_pRequestedFragment;
203 mutable std::shared_ptr<CFragmentCache> m_pCurrentFragment;
207 typedef VectorSet<int> IdContainer;
208 typedef VectorSet<float> ThresholdsContainer;
210 //////////////////////////////////////////////////////////////////////////
211 struct SValidationParams
213 SValidationParams();
214 void Reset();
215 void GetMemoryUsage(ICrySizer * s) const;
217 ScriptTablePtr validationParamsScriptTable; // Holds the pointer to the script table holding the validation information
219 string sCustomValidationFunc;// Name of the customized validation func (if present)
220 float fMinimumSpeedAllowed; // Minimum speed of the actor receiving the hit for this reaction to be valid
221 float fMaximumSpeedAllowed; // Maximum speed of the actor receiving the hit for this reaction to be valid
222 IdContainer allowedPartIds; // set of partIds where the hit is allowed to impact for this reaction to be valid
223 ECardinalDirection shotOrigin; // cardinal direction where the shot came from
224 ECardinalDirection movementDir; // cardinal direction the player is moving towards
225 float fProbability; // decimal percentage of probability for this reaction to happen
226 IdContainer allowedStances; // this reaction is only allowed on these stances
227 IdContainer allowedHitTypes; // this reaction is only allowed from one of these hit types
228 IdContainer allowedProjectiles; // this reaction is only allowed when caused by one of these projectile class Ids
229 IdContainer allowedWeapons; // this reaction is only allowed when caused by one of these weapon class Ids
230 float fMinimumDamageAllowed; // Minimum damage for this reaction to be valid
231 float fMaximumDamageAllowed; // Maximum damage for this reaction to be valid
232 ThresholdsContainer healthThresholds; // The hit reaction is only allowed when it causes the health of the character to go past one of the health values in this container
233 unsigned int destructibleEvent; // Last destructible event CRC32 generated by the destructible parts system
234 float fMinimumDistance; // Minimum distance from the hit source allowed
235 float fMaximumDistance; // Maximum distance from the hit source allowed
236 bool bAllowOnlyWhenUsingMountedItems; // If TRUE, the reaction will only be valid if the guy is using a mounted item, if FALSE, it will be valid anytime
237 EAirState airState; // Only allow if actor is in the air or on the ground.
239 typedef std::vector<SValidationParams> ValidationParamsList;
241 enum Flags
243 OrientateToHitDir = BIT(0), // If marked, the entity orientates towards the shot origin before animation-based reactions
244 CollisionCheckIntersectionWithGround = BIT(1), // If marked and detecting collisions, the checks will try to get collisions with the ground
245 SleepRagdoll = BIT(2), // If marked if the ragdoll is enabled sometime in this reaction, it will be slept right away
246 OrientateToMovementDir = BIT(3), // If marked, the entity orientates towards the movement direction before animation-based reactions
247 NoRagdollOnEnd = BIT(4), // If marked, death reactions don't end on ragdoll
248 ReactionFinishesNotAiming = BIT(5), // If marked we don't force aiming at the end on animation-based reactions
249 ReactionsForbidden = BIT(6), // If marked further hit/death reactions during this reaction are forbidden
250 TriggerRagdollAfterSerializing = BIT(7), // If marked it will force the ragdoll after loading game
253 SReactionParams();
254 void Reset();
256 void GetMemoryUsage(ICrySizer * s) const;
258 ScriptTablePtr reactionScriptTable; // Holds the pointer to the script table holding the reaction information
260 // Validation attributes
261 ValidationParamsList validationParams;
263 // Execution attributes
264 string sCustomExecutionFunc; // Name of the customized execution func (if present)
265 string sCustomExecutionEndFunc; // Name of the customized execution func when the reaction finishes (if present)
266 string sCustomAISignal; // Signal to send to the actor's AI when reaction starts playing
267 SAnimGraphReaction agReaction; // Parameters for the anim-graph based reaction
268 SReactionAnimPtr reactionAnim; // Parameters for the reaction anim used for the default execution
269 SMannequinData mannequinData; // Pre-calculated tag state for cry mannequin
270 float orientationSnapAngle; // The angle in radians that the animation ought to play in relative to the hit direction
271 Vec3 endVelocity; // Vector with the velocity (in local space) the actor will be forced to have at the end of the reaction
272 bool bPauseAI; // while playing this reaction the AI is disabled
273 uint8 flags; // several flags (see SReactionParams::Flags enum above)
274 unsigned char reactionOnCollision; // Specifies if we want reaction on collision or not, and which reaction (collisions on death reactions are always ragdoll)
277 //////////////////////////////////////////////////////////////////////////
278 // Struct holding configuration for each file
279 //////////////////////////////////////////////////////////////////////////
280 struct SHitDeathReactionsConfig
282 SHitDeathReactionsConfig() : iCollisionBoneId(-1), fCollisionRadius(0.6f), fCollisionVerticalOffset(0.5f),
283 fCollMaxHorzAngleSin(0.342f), fCollMaxMovAngleCos(0.7071f), fCollReactionStartDist(0.4f), fMaximumReactionTime(4.0f),
284 manqTargetCRC(0), piOptionalAnimationADB(NULL), fragmentID(FRAGMENT_ID_INVALID), fEndRagdollTime(-1.0f) {}
286 void GetMemoryUsage(ICrySizer * s) const
288 s->AddObject(this, sizeof(*this));
291 int iCollisionBoneId; // Id of the bone the collision volume used for collisions with the environment is centered on
292 float fCollisionRadius; // Radius of the collision volume used for collisions with the environment
293 float fCollisionVerticalOffset; // Vertical offset applied to the collision volume position
294 float fCollMaxHorzAngleSin; // Sin of the maximum angle of the collision normal respect the horizontal (x-y) plane
295 float fCollMaxMovAngleCos; // Cos of the maximum angle of the collision normal respect the movement direction
296 float fCollReactionStartDist; // distance from the collision point (and parallel to the normal) where the collision reaction starts
297 float fMaximumReactionTime; // Maximum time a reaction will last. Used as failsafe when reactions can't communicate their end properly
298 float fEndRagdollTime; // End time for the ragdoll - we force it off if this is set.
299 uint32 manqTargetCRC; // The target tag for Coop
300 uint32 fragmentID; // Mannequin "hitDeath" fragment ID
301 const IAnimationDatabase* piOptionalAnimationADB; // The optional target adb for the slave.
304 DECLARE_SHARED_POINTERS(CHitDeathReactions);
306 // SReactionParams related typedefs
307 typedef std::vector<SReactionParams> ReactionsContainer;
308 DECLARE_SHARED_POINTERS(ReactionsContainer);
309 DECLARE_SHARED_POINTERS(SHitDeathReactionsConfig);
311 #endif // __HIT_DEATH_REACTIONS_DEFS_H