1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2012 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef CL_CHARACTER_CL_H
23 #define CL_CHARACTER_CL_H
30 #include "nel/misc/types_nl.h"
31 #include "nel/misc/time_nl.h"
33 #include "nel/3d/u_play_list.h"
34 #include "nel/3d/target_anim_ctrl.h"
35 #include "nel/3d/u_particle_system_instance.h"
37 #include "entity_cl.h"
39 #include "entity_animation_manager.h"
40 #include "fx_manager.h"
41 #include "behaviour_context.h"
42 #include "attack_info.h"
43 #include "attached_fx.h"
45 #include "client_sheets/character_sheet.h"
46 #include "client_sheets/fx_sheet.h"
47 #include "client_sheets/attack_id_sheet.h"
52 #include "game_share/slot_types.h"
53 #include "game_share/gender.h"
54 #include "game_share/mode_and_behaviour.h"
57 extern NL3D::UScene
*Scene
;
62 class CCharacterSheet
;
68 class CGroupInSceneBubble
;
70 class CProjectileBuild
;
75 * Class to manage a character.
76 * \author Guillaume PUZIN
77 * \author Nevrax France
80 class CCharacterCL
: public CEntityCL
82 friend class CUserEntity
;
85 /// Stages to describ entity actions/motion.
87 enum { MaxNumAura
= 2 };
97 NLMISC_DECLARE_CLASS(CCharacterCL
);
99 /** \name CONSTRUCTOR and DESTRUCTOR
100 * Functions to construct or destroy the class.
103 /// Default Constructor
105 /// Default Destructor
106 virtual ~CCharacterCL();
109 /// Build the entity from a sheet.
110 virtual bool build(const CEntitySheet
*sheet
);
113 virtual void updatePreCollision(const NLMISC::TTime
&time
, CEntityCL
*target
);
114 virtual void updatePostCollision(const NLMISC::TTime
&time
, CEntityCL
*target
);
115 virtual void updateVisible (const NLMISC::TTime
¤tTimeInMs
, CEntityCL
*target
);
116 virtual void updateSomeClipped (const NLMISC::TTime
¤tTimeInMs
, CEntityCL
*target
);
117 virtual void updateClipped (const NLMISC::TTime
¤tTimeInMs
, CEntityCL
*target
);
119 // Get the move for the MOVE channel with the blend.
120 double getTheMove(double loopTimeStep
, double oldMovingTimeOffset
, double oldMovingTimeOffsetRun
) const;
121 // Get the move for any channel.
122 double getTheMove(double loopTimeStep
, double oldMovingTimeOffset
, TAnimationType channel
) const;
125 * Update the position of the entity after the motion.
126 * \param target : pointer on the current target.
128 virtual void updatePosCombatFloatChanged(CEntityCL
* /* target */) {}
130 * Update the position of the entity after the motion.
131 * \param target : pointer on the current target.
133 virtual void updatePosCombatFloat(double frameTimeRemaining
, CEntityCL
*target
);
135 * Update the position of the entity after the motion.
136 * \param time : Time for the position of the entity after the motion.
137 * \param target : pointer on the current target.
139 virtual void updatePos(const NLMISC::TTime
¤tTimeInMs
, CEntityCL
*target
);
140 /** Update the entity after all positions done.
142 virtual void updateVisiblePostPos(const NLMISC::TTime
&time
, CEntityCL
*target
);
143 /** Update the entity after the render like for the head offset.
145 virtual void updateVisiblePostRender();
146 /** Update all the entity after the render visible or not
148 virtual void updateAllPostRender();
151 virtual void computePrimitive();
153 /// Get the face instance. Returns NULL if no face.
154 virtual SInstanceCL
*getFace ();
156 /// Update eyes blink. For the moment, called by updatePos.
157 void updateBlink(const NLMISC::TTime
¤tTimeInMs
);
162 /// Get the entity position and set all visual stuff with it.
163 virtual void updateDisplay(CEntityCL
*parent
= 0);
165 /// Display the entity name.
166 virtual void displayName();
167 /// Display the Hp Modifiers
168 virtual void displayModifiers();
170 virtual void drawPath();
171 /// Draw the selection Box
172 virtual void drawBox();
174 /// Create in-scene interface
175 virtual void buildInSceneInterface ();
177 /// Destroy inscene interfaces
178 void releaseInSceneInterfaces();
180 /** \name HEAD_CODE_CONTROL
181 * Methods to manage the head code control.
184 /** Update the head Direction.
186 virtual void updateHeadDirection(CEntityCL
*target
);
187 /// Return the bone Id of the entity Head.
188 sint
headBone() const {return _HeadBoneId
;}
189 /// Return the bone Id of the entity pelvis.
190 //sint pelvisBone() const {return _PelvisBoneId;}
192 * Method to get the position of the head (in the world).
193 * \param headPos: will be set with the head position if succeed.
194 * \return 'true' if the param has been updated.
195 * \warning this method do NOT check if there is a skeleton.
197 virtual bool getHeadPos(NLMISC::CVector
&headPos
);
200 /// Return the selection box.
201 virtual const NLMISC::CAABBox
&selectBox();
204 /// Set the mode for the entity.
205 virtual bool mode(MBEHAV::EMode m
);
206 void setMode(MBEHAV::EMode m
) {_Mode
= m
; _ModeWanted
= m
;}
209 /** To Inform about another (or self) entity removal (to remove from selection for example).
210 * This will remove the entity from the target.
211 * \param slot : Slot of the entity that will be removed.
213 virtual void slotRemoved(const CLFECOMMON::TCLEntityId
&slot
);
236 TOnMove
onMove (const CAutomatonStateSheet
&curAnimState
);
238 TOnRot
onRotation (const CAutomatonStateSheet
&curAnimState
, NLMISC::CVector
&dirEndA
);
240 TOnBigBend
onBigBend (const CAutomatonStateSheet
&curAnimState
, NLMISC::CVector
&dirEndA
);
242 bool onBadHeading(const CAutomatonStateSheet
&curAnimState
);
244 /** Force an animation.
246 void setAnim(TAnimStateKey newKey
, TAnimStateKey subKey
= (TAnimStateKey
)CAnimation::UnknownAnim
, uint animID
=NL3D::UAnimationSet::NotFound
);
248 /// Set the LOD animation.
249 void setAnimLOD(bool changed
);
251 GSGENDER::EGender
getGender() const { return _Gender
; } // 0 -> male 1 -> female 2 -> beast
252 void setGender(GSGENDER::EGender gender
) {_Gender
= gender
;}
254 /// Method to return the attack radius of an entity
255 virtual double attackRadius() const;
256 /** Return the position the attacker should have to combat according to the attack angle.
257 * \param ang : 0 = the front, >0 and <Pi = left side, <0 and >-Pi = right side.
259 virtual NLMISC::CVectorD
getAttackerPos(double ang
, double dist
) const;
260 /// Return true if the opponent is well placed.
261 virtual bool isPlacedToFight(const NLMISC::CVectorD
&posAtk
, const NLMISC::CVector
&dirAtk
, double attackerRadius
) const;
263 /** Play an impact on the entity
264 * \param impactType : 0=magic, 1=melee
265 * \param type : see behaviour for spell
266 * \param intensity : see behaviour for spell
267 * \param id : see behaviour for spell
269 virtual void impact(uint impactType
, uint type
, uint id
, uint intensity
);
271 virtual void meleeImpact(const CAttackInfo
&damage
);
273 virtual void magicImpact(uint type
, uint intensity
);
277 * Methods only here for the debug.
280 /// Return number of stage remaining.
281 virtual uint
nbStage();
283 /// Return the number of attached FXs remaining to remove.
284 virtual uint
nbAttachedFXToRemove() {return (uint
)_AttachedFXListToRemove
.size();}
286 /// Set the animation state key.
287 bool animationStateKey(TAnimationType channel
, TAnimStateId value
);
289 /// Return the current animation name.
290 const std::string
¤tAnimationName() const;
291 /// Return the current animation set name.
292 std::string
currentAnimationSetName(TAnimationType animType
) const;
293 /// Change the entity colors.
294 virtual void changeColors(sint userColor
, sint hair
, sint eyes
, sint part
);
295 /// Display Debug Information.
296 virtual void displayDebug(float x
, float &y
, float lineStep
);
297 /// Display Debug Information for property stages
298 virtual void displayDebugPropertyStages(float x
, float &y
, float lineStep
);
299 /// set the NameId for debug in local
300 void debugSetNameId(uint32 nameId
) {updateVisualPropertyName(0, nameId
);}
304 * \return the sheet of the character
306 const CCharacterSheet
*getSheet() const {return _Sheet
;}
308 // Return true if this entity is a Kami
309 virtual bool isKami() const;
311 // Return true if this entity has Race set to Unknown
312 virtual bool isUnknownRace() const;
315 std::string
¤tAutomaton() {return _CurrentAutomaton
;}
316 std::vector
<const CAnimationSet
*> ¤tAnimSet() {return _CurrentAnimSet
;}
318 void processFrame(const NLMISC::TTime
¤tTimeInMs
);
319 void processStage(CStage
&stage
);
321 CLFECOMMON::TCLEntityId
mount() const {return _Mount
;}
322 CLFECOMMON::TCLEntityId
rider() const {return _Rider
;}
323 void rider(CLFECOMMON::TCLEntityId r
) {_Rider
= r
;}
327 * \param pos : result given in this variable. Only valid if return 'true'.
328 * \return bool : 'true' if the 'pos' has been filled.
330 virtual bool getChestPos(NLMISC::CVectorD
&pos
) const;
333 * \param pos : result given in this variable. Only valid if return 'true'.
334 * \return bool : 'true' if the 'pos' has been filled.
336 virtual bool getNamePos(NLMISC::CVectorD
&pos
);
338 /// Return true if the character is swimming (even if dead).
339 bool isSwimming() const {return (_Mode
== MBEHAV::SWIM
|| _Mode
== MBEHAV::SWIM_DEATH
|| _Mode
== MBEHAV::MOUNT_SWIM
);}
340 /// Return true if the character is riding.
341 bool isRiding() const {return (_Mode
== MBEHAV::MOUNT_NORMAL
|| _Mode
== MBEHAV::MOUNT_SWIM
);}
342 /// Is the entity in combat.
343 bool isFighting() const {return (_Mode
== MBEHAV::COMBAT
|| _Mode
== MBEHAV::COMBAT_FLOAT
);}
344 /// Return true if the character is currently dead.
345 virtual bool isDead() const {return (_Mode
== MBEHAV::DEATH
|| _Mode
== MBEHAV::SWIM_DEATH
);}
346 /// Return true if the character is really dead. With no lag because of anim or LCT
347 virtual bool isReallyDead() const {return (_TheoreticalMode
== MBEHAV::DEATH
|| _TheoreticalMode
== MBEHAV::SWIM_DEATH
);}
349 const CAutomatonStateSheet
*currentState() {return _CurrentState
;}
350 void currentState(const CAutomatonStateSheet
*newState
) {_CurrentState
= newState
;}
351 /// Return the entity sheet scale. (return 1.0 if there is any problem).
352 virtual float getSheetScale() const;
353 // Return the entity collision radius. (return 0.5 if there is any problem).
354 float getSheetColRadius() const;
355 /// Return the entity scale. (return 1.0 if there is any problem).
356 virtual float getScale() const;
357 /// Return 'true' is the entity is displayed.
358 virtual bool isVisible() const {return true;}
359 /// (Re-)Build the playlist (Removing the old one too).
360 virtual void buildPlaylist();
361 // return vector of ground fxs sorted by ground type, or NULL is ground fxs are not supported for the entity
362 virtual const std::vector
<CGroundFXSheet
> *getGroundFX() const;
363 virtual bool supportGroundFX() const { return true; }
367 /// Return the entity speed
368 virtual double getSpeed() const;
370 virtual uint32
getGuildNameID () const { return _GuildNameId
; }
371 virtual uint64
getGuildSymbol () const { return _GuildSymbol
; }
373 virtual uint32
getEventFactionID() const { return _EventFactionId
; }
374 virtual uint16
getPvpMode() const { return _PvpMode
; }
375 void setPvpMode(uint16 mode
) { _PvpMode
=mode
; }
376 virtual uint32
getLeagueID() const { return _LeagueId
; }
377 void setLeagueID(uint32 league
) { _LeagueId
=league
; }
379 virtual uint16
getOutpostId() const { return _OutpostId
; }
380 virtual OUTPOSTENUMS::TPVPSide
getOutpostSide() const { return _OutpostSide
; }
382 // get scale pos of character
383 float getScalePos() const { return _CharacterScalePos
; }
385 // get scale from reference scale (male fyros). For creatures, returns the same than _CharacterScalePos
386 virtual float getScaleRef() const { return _CharacterScalePos
; }
388 // Return true if this entity is a neutral entity.
389 virtual bool isNeutral () const;
390 // Return true if this entity is a user's friend.
391 virtual bool isFriend () const;
392 // Return true if this entity is a user's enemy.
393 virtual bool isEnemy () const;
394 // Return true if this entity is a user's ally.
395 virtual bool isAlly () const;
397 /// Return the People for the entity
398 virtual EGSPD::CPeople::TPeople
people() const;
399 virtual void setPeople(EGSPD::CPeople::TPeople people
);
401 /// *** Ingame interface
402 void setBubble (CGroupInSceneBubble
*bubble
);
403 // *** Ingame interface : get the current bubble assigned
404 CGroupInSceneBubble
*getBubble () { return _CurrentBubble
; }
406 // Attach a CAttachedFX object to that character.
407 void attachFX(const CAttachedFX::TSmartPtr fx
);
409 /** Apply the behaviour.
410 * \param behaviour : the behaviour to apply.
412 virtual void applyBehaviour(const CBehaviourContext
&behaviour
);
414 // align an fx to be positionned and oriented like that entity, and put in the same cluster system than this entity
415 void alignFX(NL3D::UParticleSystemInstance instance
, float scale
= 1.f
, const NLMISC::CVector
&localOffset
= NLMISC::CVector::Null
) const;
417 // align a fx using the given matrix (also add scale & offset) , and put in the same cluster system than this entity
418 void alignFX(NL3D::UParticleSystemInstance instance
, const NLMISC::CMatrix
&matrix
, float scale
= 1.f
, const NLMISC::CVector
&localOffset
= NLMISC::CVector::Null
) const;
420 // build a matrix aligned on that entity (includes dir & pos)
421 void buildAlignMatrix(NLMISC::CMatrix
&dest
) const;
423 /** Set a new aura fx
424 * If pointer is NULL, then previous aura is shutdown over several frames
425 * If pointer isn't NULL then a new aura is created. Any previously present aura is immediatly deleted.
427 void setAuraFX(uint index
, const CAnimationFX
*fx
);
428 /** Set a new link fx.
429 * If there's a previous link, the dispell fx is played to make it disappear
430 * If fx ptr is NULL then no new link fx is created (but dispell is still played)
432 void setLinkFX(const CAnimationFX
*fx
, const CAnimationFX
*dispell
);
435 const char *getBoneNameFromBodyPart(BODY::TBodyPart part
, BODY::TSide side
) const;
437 virtual bool getBoneHeight(BODY::TBodyPart localisation
, BODY::TSide side
, float &height
) const;
439 /// Get the Animation 'State' for an animation channel.
440 TAnimStateId
animState (TAnimationType channel
) const;
442 // retrieve right hand item sheet
443 virtual const CItemSheet
*getRightHandItemSheet() const;
444 virtual const CItemSheet
*getLeftHandItemSheet() const;
446 // get attack from an attack id (NULL if not found)
447 virtual const CAttack
*getAttack(const CAttackIDSheet
&id
) const;
449 /// Return the Entity Current Speed.
450 virtual double speed() const;
452 /// Ask if the entity is sit
453 bool isSit() const {return _Mode
== MBEHAV::SIT
;}
455 /// Ask if the entity is afk (a character is never afk but players can be)
456 virtual bool isAFK() const {return false;}
458 // reset all sound anim id this entity may own
459 virtual void resetAllSoundAnimId();
461 // manually set/get the job animation state
462 void setAnimJobSpecialisation(uint32 state
) {_AnimJobSpecialisation
= state
;}
463 uint32
getAnimJobSpecialisation() const {return _AnimJobSpecialisation
;}
465 virtual void removeAllAttachedFX();
468 void playCastFX(const CAnimationFXSet
*afs
, uint power
);
470 // Can the user select this entity by pressing space key ?
471 bool isSelectableBySpace() { return _SelectableBySpace
; }
474 /** A worn item and its attached fxs.
475 * The item instance itself is managed by _Instances
480 const CItemSheet
*Sheet
; // sheet of item, or NULL if not used
481 NL3D::UInstance Trail
; // trail linked to that fx
482 NL3D::UParticleSystemInstance AdvantageFX
; // adantage fx linked to that item
488 // release (but not remove the mesh, it is managed by _Instances)
495 void initFXs(SLOTTYPE::EVisualSlot visualSlot
, NL3D::UInstance parent
);
498 /** trigger fxs associated with an attack
499 * \param intensity in [1, 5]
501 void startAttackFX(NL3D::USkeleton skeleton
, uint intensity
, SLOTTYPE::EVisualSlot visualSlot
, bool activateTrail
);
504 // start/stop the advantage fx (advantage fx appears on a weapon that is mastered by user)
505 void enableAdvantageFX(NL3D::UInstance parent
);
506 /** set size of trail (value clamped to [0, 15]). This will map to the values given in the item sheet.
507 * 0 mean that there's no trail
509 void setTrailSize(uint size
);
512 // the various category of animated fx list
517 FXListAuto
// the list is determined by the sheet of the fx
520 static const uint8 _BadHairIndex
;
522 /// Stages to describ entity actions/motion.
523 // CStageSet _Stages;
526 /// Sound ids of the current animations (-1 if none set)
527 std::vector
<NLSOUND::TSoundAnimId
> _SoundId
;
528 /// The sound context for animation for this character
529 NLSOUND::CSoundContext _SoundContext
;
531 /// Subsidiary Key for the Animation State (emote).
532 TAnimStateId _SubStateKey
;
533 /// Pointer on the current Anim Set.
534 std::vector
<const CAnimationSet
*> _CurrentAnimSet
;
536 double _LastFrameTime
;
538 /// Lod Animation ??. false by default
539 bool _LodCharacterAnimEnabled
;
540 /// Time for lod animation
541 double _LodCharacterAnimTimeOffset
;
542 /// Which playList AnimSlot drive the LodCharacterAnimation. MOVE, by default.
543 uint _LodCharacterMasterAnimSlot
;
545 // value to scale the "pos" channel of the animation of the character.
546 float _CharacterScalePos
;
549 NLMISC::CVectorD _FirstPos
;
550 // Time of the first Position.
552 // Distance to the first stage.
554 // Time at which the first run animation should start in order to avoid pop (computed in updateStages())
555 // It is used to accelerate animations that are followed by positions
556 double _RunStartTimeNoPop
;
559 // Position of the destination.
560 NLMISC::CVectorD _DestPos
;
561 // Time of the destiantion.
563 // Distance to the destination or 0 if destination reached (in meter).
566 /// Position that was in the last stage with a position reached.
567 NLMISC::CVectorD _OldPos
;
568 /// Time of the last stage pos reached.
572 /// Is it a male ? female ? could be a beast :p
573 GSGENDER::EGender _Gender
;
575 /// Id of the Bone used to display the name.
577 /// Used to force the bone to be computed (but in CLod form)
578 NL3D::UTransform _NameTransform
;
579 /// If in Clod form, the name pos is computed with DeltaPos
580 mutable float _NameCLodDeltaZ
;
581 enum {NameCLodDeltaZNotComputed
= -1000000};
583 /// Id of the Bone used for the Middle of torso.
586 /// Pointers on items for visible slots.
587 std::vector
<CWornItem
> _Items
;
588 /// Instances Index for visible slots.
591 /// Should objects in hands be displayed ?
592 bool _ObjectsVisible
;
595 /// Id of the Bone for the Head. -1 if no bone.
597 // Id of the Pelvis Bone. -1 if no bone
598 //sint _PelvisBoneId;
599 /// Offset between the entity position and its head.
600 NLMISC::CVector _HeadOffset
;
601 /// true if the head offset has been computed at least once
602 bool _HeadOffsetComputed
;
606 /// Used to adjust the rotation of the animation to finish with the perfect orientation.
607 double _RotationFactor
;
608 /// This is the direction the entity will have at the end of the animation.
609 NLMISC::CVector _DirEndAnim
;
612 /// Automaton currently in use.
613 std::string _CurrentAutomaton
;
614 /// Pointer on the current state.
615 const CAutomatonStateSheet
*_CurrentState
;
616 /// The mode the entity should already be but still not the current one.
617 MBEHAV::EMode _ModeWanted
;
618 /// Number of frame remaining for the blend.
619 sint _BlendRemaining
;
620 /// Automaton currently in use.
621 std::string _OldAutomaton
;
622 /// Rotation at the end of the last animation for the blend.
623 NLMISC::CQuat _OldRotQuat
;
624 /// Scale for the skeleton according to the gabarit.
625 float _CustomScalePos
;
627 NLMISC::TTime _NextBlinkTime
;
628 /// Number of loop of the curren animation.
632 NL3D::CTargetAnimCtrl _TargetAnimCtrl
;
633 /// The job specialisation of the character (0 by default). visual prop from server
634 uint32 _AnimJobSpecialisation
;
636 /** List of animation FXs currently being played. Those FXs are shutdown as soon as an animation switch occurs.
637 * When theyareshutdown,theit emitter are stopped, and they are put in _RemoveAnimFXList,waiting for deletion
639 std::list
<CAttachedFX::TSmartPtr
> _AttachedFXListForCurrentAnim
;
640 /// List of attached to remove as soon as possible (when there are no particles left)
641 std::list
<CAttachedFX::TSmartPtr
> _AttachedFXListToRemove
;
643 std::list
<CAttachedFX::CBuildInfo
> _AttachedFXListToStart
;
645 CAttachedFX::TSmartPtr _AuraFX
[MaxNumAura
]; // special case for aura
646 CAttachedFX::TSmartPtr _LinkFX
; // special case for link
648 class CStaticFX
: public NLMISC::CRefCount
651 CAnimationFX AF
; // ideally this field should be per sheet, not per instance, but simpler this way
652 CAttachedFX::TSmartPtr FX
;
655 NLMISC::CSmartPtr
<CStaticFX
> _StaticFX
; // special case for static fx
658 /// FX from the right hand activated.
659 bool _RightFXActivated
;
660 /// FX from the left hand activated.
661 bool _LeftFXActivated
;
663 CLFECOMMON::TCLEntityId _Mount
;
664 CLFECOMMON::TCLEntityId _TheoreticalMount
;
665 CLFECOMMON::TCLEntityId _Rider
;
666 CLFECOMMON::TCLEntityId _TheoreticalRider
;
667 MOUNT_PEOPLE::TMountPeople _OwnerPeople
;
671 // if 0(default), LCT is fully applied, else this is the ServerTick when the LCT impact decrease
672 NLMISC::TGameCycle _StartDecreaseLCTImpact
;
674 // this time is the estimated time of the first important stage (excluding the first one)
675 double _ImportantStepTime
;
677 // The Colour of the entity hair.
679 // The Colour of the entity Eyes.
689 /// *** Ingame interface
690 class CGroupInSceneUserInfo
*_InSceneUserInterface
;
691 class CGroupInSceneBubble
*_CurrentBubble
;
694 uint32 _EventFactionId
;
696 PVP_CLAN::TPVPClan _PvpClan
;
699 OUTPOSTENUMS::TPVPSide _OutpostSide
;
701 // Can the user select this entity by pressing space key ?
702 bool _SelectableBySpace
;
704 // current attack (attacks include magic/melee/range/creature_attack)
705 const CAttack
*_CurrentAttack
;
706 CAttackIDSheet _CurrentAttackID
;
707 CAttackInfo _CurrentAttackInfo
;
711 // for selectBox() computing
712 sint64 _LastSelectBoxComputeTime
;
716 /// Pointer on the Sheet with basic parameters.
717 const CCharacterSheet
*_Sheet
;
720 // Adjust the Predicted Interval to fix some errors according to the distance.
721 NLMISC::TGameCycle
adjustPI(float x
, float y
, float z
, const NLMISC::TGameCycle
&pI
);
723 // Look at items in hands to change the animation set.
724 bool modeWithHiddenItems() const;
726 /** Returns true if current behaviour triggers an attack end.
727 * (when projectiles & impact fx are created)
729 bool isCurrentBehaviourAttackEnd() const;
731 /** Build attack infos from current behaviour
732 * This convert any attack encoded in current behaviour (magic/melee/range/creature_attack)
733 * into a common representation (CAttackInfo)
735 void buildAttackInfo(CAttackInfo
&dest
);
737 /** perform current attack
738 * list of targets if given by the behaviour context
739 * (where projectiles & impact fx are reated)
741 void performCurrentAttackEnd(const CBehaviourContext
&bc
, bool directOffensifSpell
, std::vector
<double> &targetHitDates
, TAnimStateKey animForCombat
);
743 // update current attack from the current behaviour (this update the "_Attack" field)
744 void updateCurrentAttack();
747 /** Create part of current attack (a single projectile or/and impact, total attack may contain severals)
748 * IMPORTANT: the instance on which this method is invoked is NOT always the caster (secondary missiles can be generated after main target has been reached)
749 * NB : target stick mode isn't filled, for this, should use computeTargetStickMode instead
750 * NB : once fully filled, the CProjectileBuild object should be inserted in the projectile manager
752 bool createCurrentAttackEndPart(CProjectileBuild
&destPB
,
753 const CAttack
*currentAttack
,
754 const CCharacterCL
&target
,
755 const CFXStickMode
*sm
,
761 bool mainImpactIsLocalised
,
762 const CAttackInfo
&attackInfo
,
763 const NLMISC::CVector
&additionnalOffset
= NLMISC::CVector::Null
767 // Return the automaton type of the entity (homin, creature, etc.)
768 virtual std::string
automatonType() const;
769 // Compute the current automaton for the entity.
770 void computeAutomaton();
772 // Return the atk height.
773 TAtkHeight
getAttackHeight(CEntityCL
*target
, BODY::TBodyPart localisation
, BODY::TSide side
) const;
778 /** Stop all attached FXs linked to current anim (this wait until FX have no more particle, after what they are effectively deleted)
779 * \param stopLoopingFX If set to true, looping fx are also stopped. A looping fx has RepeatMode == Loop in its sheet.
781 void stopAttachedFXForCurrrentAnim(bool stopLoopingFX
);
783 /** start items attack fxs
784 * \param intensity tranges from 1 to 5
786 void startItemAttackFXs(bool activateTrails
, uint intensity
);
788 // stop items attack fxs
789 void stopItemAttackFXs();
791 /** Compute some bone id (name, chest, head...)
792 * \warning This method do not check the bone is valid, nor there is a Scene.
794 void computeSomeBoneId();
797 /// Create the play list for this entity.
798 void createPlayList();
800 /** Compute each part of the visual equipement of the character
801 * \param slot: structure of the equipement.
802 * \param visualSlot: visual slot used by this item.
803 * \param instIdx : if not CEntityCL::BadIndex, replace the equipement instance at this index.
804 * \return uint32 : index of the instance or CEntityCL::BadIndex if there were a problem.
805 * \todo GUIGUI : find a better choice to avoid all these slotType tests
807 uint32
buildEquipment(const CCharacterSheet::CEquipment
&slot
, SLOTTYPE::EVisualSlot visualSlot
, sint color
= -1, uint32 instIdx
= CEntityCL::BadIndex
);
809 /// Compute the animation set to use according to weapons, mode and race.
810 virtual void computeAnimSet();
812 /// Update Entity Position.
813 virtual void updateVisualPropertyPos (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
, const NLMISC::TGameCycle
&pI
);
814 /// Update Entity Orientation.
815 virtual void updateVisualPropertyOrient (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
816 /// Update Entity Behaviour.
817 virtual void updateVisualPropertyBehaviour (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
818 /// Update Entity Name.
819 virtual void updateVisualPropertyName (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
820 /// Update Entity Target.
821 virtual void updateVisualPropertyTarget (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
822 /// Update Entity Mode.
823 virtual void updateVisualPropertyMode (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
824 /// Update the NPC Alternative Look Property.
825 virtual void updateVisualPropertyVpa (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
826 virtual void updateVisualPropertyVpb (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
827 /// Update Entity Mount
828 virtual void updateVisualPropertyEntityMounted (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
829 /// Update Entity Rider
830 virtual void updateVisualPropertyRiderEntity (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
831 /// Update Entity Bars
832 virtual void updateVisualPropertyBars (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
833 virtual void updateVisualPropertyGuildSymbol (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
834 virtual void updateVisualPropertyGuildNameID (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
835 virtual void updateVisualPropertyEventFactionID (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
836 virtual void updateVisualPropertyPvpMode (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
837 virtual void updateVisualPropertyPvpClan (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
838 virtual void updateVisualPropertyOwnerPeople (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
839 virtual void updateVisualPropertyOutpostInfos (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
841 /// Update Entity Status
842 virtual void updateVisualPropertyStatus (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
843 // Update target list
844 virtual void updateVisualPropertyTargetList (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
, uint listIndex
);
846 virtual void updateVisualPropertyVisualFX (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
847 /// Update vprop contextual attributes
848 virtual void updateVisualPropertyContextual (const NLMISC::TGameCycle
&gameCycle
, const sint64
&prop
);
849 // Get The Entity Skin
850 virtual sint
skin() const;
852 /// Get the direction that should have the character at the end of the animation.
853 const NL3D::CVector
&dirEndAnim() {return _DirEndAnim
;}
854 /// Set the direction that should have the character at the end of the animation.
855 void dirEndAnim(const NL3D::CVector
&vect
);
858 * Add an instance to the list of instance composing the entity.
859 * \param shapeName : shape filename.
860 * \param stickPoint : Name of the bone to stick on.
861 * \param texture : texture to use (in multi texture) or -1 for default texture.
862 * \param instIdx : if not CEntityCL::BadIndex, the instance will replace the one at this index.
863 * \return uint32 : index of the instance created, or CEntityCL::BadIndex.
865 uint32
addColoredInstance(const std::string
&shapeName
, const std::string
&stickPoint
= "", sint texture
= -1, uint32 instIdx
= BadIndex
, sint color
= -1);
867 /// Initialize properties of the entity (according to the class).
868 virtual void initProperties();
870 /// Method to Flag the character as dead and do everything needed.
871 virtual void setDead();
872 /// Method to Flag the character as alive and do everything needed.
873 virtual void setAlive();
876 double computeTimeStep(const double ¤tTime
);
879 double computeSpeed();
881 * Compute and return the speed factor to apply to the animation.
882 * \param speedToDest : evaluted speed to destination.
883 * \return double : the speed factor to use for the current animation.
885 double computeSpeedFactor(double speedToDest
);
888 void updateAnimationState();
890 double computeMotion(const double &oldMovingTimeOffset
, TAnimationType channel
= MOVE
) const;
892 /// Apply stage modifications.
893 bool applyStage(CStage
&stage
);
894 /// Apply The Current Stage (first stage).
895 bool applyCurrentStage();
896 /// Apply all stages to the first stage with a position.
897 void applyAllStagesToFirstPos();
900 virtual void beginCast(const MBEHAV::CBehaviour
&behaviour
);
901 void endCast(const MBEHAV::CBehaviour
&behaviour
, const MBEHAV::CBehaviour
&lastBehaviour
);
904 /// Play the time step for the loop and truncate to End Anim if Time Step too big.
905 void playToEndAnim(const double &startTimeOffset
, double &length
);
907 /// Call this method to give a time for each stage, compute distance to destination and some more information.
911 * Manage Events that could be created by the animation (like sound).
912 * \param startTime : time to start processing events from the current animation.
913 * \param stopTime : time to stop processing events from the current animation.
915 void animEventsProcessing(double startTime
, double stopTime
);
917 void applyColorSlot(SInstanceCL
&instance
, sint skin
, sint userColor
, sint hair
, sint eyes
);
919 /// Return the current max speed for the entity in meter per sec (!= swim, != mount, etc.)
920 virtual double getMaxSpeed() const;
922 virtual void drawName(const NLMISC::CMatrix
&mat
);
924 /// Set the Distance from the current entity position to the First Position.
925 void dist2FirstPos(double d2FP
);
926 /// Return the Distance from the current entity position to the First Position.
927 double dist2FirstPos() const;
928 /// Set the Distance from the current entity position to the Destination.
929 void dist2Dest(double d2D
);
930 /// Return the Distance from the current entity position to the Destination.
931 double dist2Dest() const;
932 /// Set the Entity Current Speed.
933 void speed(double s
);
934 /// Set the Factor between Walk & Run
935 void runFactor(double factor
);
936 /// Get the Factor between Walk & Run
937 double runFactor() const;
938 /// Set the Animation 'Offset' for an animation channel.
939 void animOffset(TAnimationType channel
, double offset
);
940 /// Get the Animation 'Offset' for an animation channel.
941 double animOffset(TAnimationType channel
) const;
942 /// Set the Animation 'State' for an animation channel.
943 void animState (TAnimationType channel
, TAnimStateId state
);
944 /// Set the Animation 'Index' in the 'State' for an animation channel.
945 void animIndex (TAnimationType channel
, CAnimation::TAnimId index
);
946 /// Get the Animation 'Index' in the 'State' for an animation channel.
947 CAnimation::TAnimId
animIndex (TAnimationType channel
) const;
948 /// Set the Animation 'Id' among all the animations for an animation channel.
949 void animId (TAnimationType channel
, uint id
);
950 /// Get the Animation 'Id' among all the animations for an animation channel.
951 uint
animId (TAnimationType channel
) const;
954 // Read/Write Variables from/to the stream.
955 virtual void readWrite(NLMISC::IStream
&f
);
956 // To call after a read from a stream to re-initialize the entity.
959 void showOrHideBodyParts( bool objectsVisible
);
960 bool objectsVisible() const { return _ObjectsVisible
; };
962 /// Return name position on Z axis defined in sheet
963 virtual float getNamePosZ() const;
966 static const std::string _EmptyString
;
967 const CCharacterSheet
*_ClothesSheet
;
968 uint32 _RHandInstIdx
;
969 uint32 _LHandInstIdx
;
970 // Return 'true' if the animation should be played from the end to the start.
971 std::vector
<bool> _AnimReversed
;
972 // Animation 'Offset' for each channel.
973 std::vector
<double> _AnimOffset
;
974 // Animation 'State' for each channel.
975 std::vector
<TAnimStateId
> _AnimState
;
976 // Animation 'Index' in the 'State' for each channel (-1 if none set).
977 std::vector
<CAnimation::TAnimId
> _AnimIndex
;
978 // Animation 'Id' among all the animations for each channel.
979 std::vector
<uint
> _AnimId
;
981 struct CNamePosHistory
984 CNamePosHistory() : LastNamePosZ(0.f
), LastBonePosZ(0.f
) {}
986 bool isInitialized() const { return LastNamePosZ
!= 0.f
; }
992 CNamePosHistory _NamePosHistory
;
995 /// Call it at the end of the current animation to choose the next one.
996 void endAnimTransition();
998 /** Return the shape pointer from tha item and according to the character gender.
999 * \param itemSheet : reference on the item sheet.
1000 * \return string & : reference on the shape name.
1002 std::string
shapeFromItem(const CItemSheet
&itemSheet
) const;
1004 /// Create the instance from an item
1005 uint32
createItemInstance(const CItemSheet
&itemSheet
, uint32 instIdx
, SLOTTYPE::EVisualSlot visualSlot
, const std::string
&bindBone
, sint8 texture
, sint color
);
1007 /** Return if the impact must be played.
1008 * \param anim : pointer on the current animation (MUST NOT BE NULL).
1009 * \param currentTime : current time in the animation.
1010 * \param triggerName : name of the trigger to check.
1011 * \param isActive : read (and can change) the state.
1012 * \param timeFactor : when to activate the impact if there is no track (value has to be between 0 and 1 to be valid).
1013 * \return bool : true if the trigger is valid.
1014 * \warning This method does not check if the animation is Null.
1016 bool beginImpact(NL3D::UAnimation
*anim
, NL3D::TAnimationTime currentTime
, const std::string
&triggerName
, bool &isActive
, float timeFactor
);
1017 /** FX played on the weapon when there is an impact.
1018 * \param index : index of the fx.
1019 * \param attackPower : power of the current attack.
1021 void weaponImpactFX(sint index
, uint attackPower
);
1023 // update attached fxs
1024 void updateAttachedFX();
1027 // Attach a CAttachedFX object to that character.
1028 void attachFXInternal(const CAttachedFX::TSmartPtr fx
, TAttachedFXList wantedList
);
1030 // attach an externally created fx in the given list (alive fx or shutting down fxs)
1031 void attachFX(NL3D::UParticleSystemInstance instance
,
1032 const CAnimationFX
*sheet
,
1033 const CFXStickMode
*stickMode
,
1034 TAttachedFXList targetList
,
1035 float timeOut
= FX_MANAGER_DEFAULT_TIMEOUT
,
1036 const NLMISC::CVector
&stickOffset
= NLMISC::CVector::Null
,
1037 uint maxNumAnimCount
= 0,
1038 uint8 targeterSlot
= CLFECOMMON::INVALID_SLOT
,
1039 const NLMISC::CMatrix
*staticMatrix
= NULL
1043 // apply visual fx from packed property (include auras and links)
1044 virtual void applyVisualFX(sint64 prop
);
1045 /// Helper fct : remove any obsolete reference in a CAnimFX list to an entity slot that has just been removed.
1046 static void updateAnimFXListForSlotRemoved(std::list
<CAttachedFX::TSmartPtr
> &fxList
, const CLFECOMMON::TCLEntityId
&slotRemoved
);
1048 // compute the best cast ray when creating a projectile (for guard towers)
1049 void computeBestCastRay(CEntityCL
&targetEntity
,
1050 const CFXStickMode
&targetStickMode
,
1051 NLMISC::CVector
&castWorldOrigin
,
1052 NLMISC::CVector
&castWorldPos
,
1053 NLMISC::CVector
&worldOffsetToCasterPivot
) const;
1055 // build cast fxs for static object (such as a guard tower ...)
1056 void buildStaticObjectCastFX(const NLMISC::CVector
&castWorldOrigin
,
1057 NLMISC::CVector
&castWorldPos
,
1058 const CAttackSheet
&sheet
,
1062 // Compute the stick mode on the target for an attack
1063 void computeTargetStickMode(const CAttackSheet
&sheet
, const CAttackInfo
&attackInfo
, CFXStickMode
&dest
, CEntityCL
&target
);
1065 // remove attached fxs that depends on another slot when it has been removed
1066 void updateAttachedFXListForSlotRemoved(std::list
<CAttachedFX::TSmartPtr
> &fxList
, const CLFECOMMON::TCLEntityId
&slotRemoved
);
1068 // apply the flying HP related to behaviour
1069 void applyBehaviourFlyingHPs(const CBehaviourContext
&bc
, const MBEHAV::CBehaviour
&behaviour
, const std::vector
<double> &targetHitDates
);
1072 // retrieve attack from an id and a list of attack lists filenames
1073 const CAttack
*getAttack(const CAttackIDSheet
&id
, const std::vector
<NLMISC::TSStringId
> &attackList
) const;
1074 void releaseStaticFX();
1075 void initStaticFX();
1079 #endif // CL_CHARACTER_CL_H
1081 /* End of character_cl.h */