Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / character_cl.h
blobca9c097ac52de17117fcb3d705ac8163ca13c41a
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2012 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
6 //
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
26 /////////////
27 // INCLUDE //
28 /////////////
29 // Misc.
30 #include "nel/misc/types_nl.h"
31 #include "nel/misc/time_nl.h"
32 // 3d.
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"
36 // Client.
37 #include "entity_cl.h"
38 #include "stage.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"
44 // Client Sheets
45 #include "client_sheets/character_sheet.h"
46 #include "client_sheets/fx_sheet.h"
47 #include "client_sheets/attack_id_sheet.h"
48 // std
49 #include <map>
50 #include <vector>
51 // Game Share
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;
59 ///////////
60 // CLASS //
61 ///////////
62 class CCharacterSheet;
63 class CItemSheet;
64 class CUserEntity;
65 class CAnimationFX;
66 class CItemFXSheet;
67 class CAttack;
68 class CGroupInSceneBubble;
69 class CAttackSheet;
70 class CProjectileBuild;
74 /**
75 * Class to manage a character.
76 * \author Guillaume PUZIN
77 * \author Nevrax France
78 * \date 2001
80 class CCharacterCL : public CEntityCL
82 friend class CUserEntity;
84 public:
85 /// Stages to describ entity actions/motion.
86 CStageSet _Stages;
87 enum { MaxNumAura = 2 };
88 enum TAtkHeight
90 AtkUnkownHeight = 0,
91 AtkLow,
92 AtkMiddle,
93 AtkHigh
96 public:
97 NLMISC_DECLARE_CLASS(CCharacterCL);
99 /** \name CONSTRUCTOR and DESTRUCTOR
100 * Functions to construct or destroy the class.
102 //@{
103 /// Default Constructor
104 CCharacterCL();
105 /// Default Destructor
106 virtual ~CCharacterCL();
107 //@}
109 /// Build the entity from a sheet.
110 virtual bool build(const CEntitySheet *sheet);
112 /// \from CEntityCl
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 &currentTimeInMs, CEntityCL *target);
116 virtual void updateSomeClipped (const NLMISC::TTime &currentTimeInMs, CEntityCL *target);
117 virtual void updateClipped (const NLMISC::TTime &currentTimeInMs, 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 &currentTimeInMs, 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();
150 // from CEntityCL
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 &currentTimeInMs);
159 /// Update system FX
160 void updateFX();
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();
169 /// Draw Path
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.
183 //@{
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);
198 //@}
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);
215 enum TOnMove
217 OnMoveNone = 0,
218 OnMoveForward,
219 OnMoveBackward,
220 OnMoveLeft,
221 OnMoveRight
223 enum TOnRot
225 OnRotNone = 0,
226 OnRotLeft,
227 OnRotRight
229 enum TOnBigBend
231 OnBendNone = 0,
232 OnBendLeft,
233 OnBendRight
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);
270 // from CEntityCL
271 virtual void meleeImpact(const CAttackInfo &damage);
272 // from CEntityCL
273 virtual void magicImpact(uint type, uint intensity);
276 /** \name DEBUG
277 * Methods only here for the debug.
279 //@{
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 &currentAnimationName() 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);}
301 //@}
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;
314 /// TEST
315 std::string &currentAutomaton() {return _CurrentAutomaton;}
316 std::vector<const CAnimationSet *> &currentAnimSet() {return _CurrentAnimSet;}
318 void processFrame(const NLMISC::TTime &currentTimeInMs);
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; }
364 //--------------//
365 // ENTITY INFOS //
366 //--------------//
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);
434 // From CEntityCL
435 const char *getBoneNameFromBodyPart(BODY::TBodyPart part, BODY::TSide side) const;
436 // ...
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; }
473 protected:
474 /** A worn item and its attached fxs.
475 * The item instance itself is managed by _Instances
477 class CWornItem
479 public:
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
483 public:
484 CWornItem()
486 Sheet = NULL;
488 // release (but not remove the mesh, it is managed by _Instances)
489 void release()
491 Sheet = NULL;
492 releaseFXs();
494 // init item fxs
495 void initFXs(SLOTTYPE::EVisualSlot visualSlot, NL3D::UInstance parent);
496 // release item fxs
497 void releaseFXs();
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);
502 // stop attack fx
503 void stopAttackFX();
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
513 enum TAttachedFXList
515 FXListToRemove,
516 FXListCurrentAnim,
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;
548 // First Position.
549 NLMISC::CVectorD _FirstPos;
550 // Time of the first Position.
551 double _FirstTime;
552 // Distance to the first stage.
553 double _DistToFirst;
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.
562 double _DestTime;
563 // Distance to the destination or 0 if destination reached (in meter).
564 double _DistToDest;
566 /// Position that was in the last stage with a position reached.
567 NLMISC::CVectorD _OldPos;
568 /// Time of the last stage pos reached.
569 double _OldPosTime;
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.
576 sint _NameBoneId;
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.
584 sint _ChestBoneId;
586 /// Pointers on items for visible slots.
587 std::vector<CWornItem> _Items;
588 /// Instances Index for visible slots.
589 uint32 _HeadIdx;
590 uint32 _FaceIdx;
591 /// Should objects in hands be displayed ?
592 bool _ObjectsVisible;
594 ////// HEAD
595 /// Id of the Bone for the Head. -1 if no bone.
596 sint _HeadBoneId;
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;
605 ////// ANIMATION
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;
610 /// ...
611 double _RotAngle;
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;
626 /// Next blink time
627 NLMISC::TTime _NextBlinkTime;
628 /// Number of loop of the curren animation.
629 uint32 _NbLoopAnim;
630 bool _MaxLoop;
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
650 public:
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;
669 bool _IsThereAMode;
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.
678 sint8 _HairColor;
679 // The Colour of the entity Eyes.
680 sint8 _EyesColor;
682 uint8 _HairIndex;
684 bool _LookRdy;
686 double _Speed;
687 double _RunFactor;
689 /// *** Ingame interface
690 class CGroupInSceneUserInfo *_InSceneUserInterface;
691 class CGroupInSceneBubble *_CurrentBubble;
692 uint32 _GuildNameId;
693 uint64 _GuildSymbol;
694 uint32 _EventFactionId;
695 uint16 _PvpMode;
696 PVP_CLAN::TPVPClan _PvpClan;
697 uint32 _LeagueId;
698 uint16 _OutpostId;
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;
709 bool _HideSkin;
711 // for selectBox() computing
712 sint64 _LastSelectBoxComputeTime;
714 bool _ScaleDone;
715 float _CustomScale;
716 float _BaseCustomScale;
717 float _StepCustomScale;
718 NLMISC::TTime _StartCustomScale;
720 /// Pointer on the Sheet with basic parameters.
721 const CCharacterSheet *_Sheet;
723 protected:
724 // Adjust the Predicted Interval to fix some errors according to the distance.
725 NLMISC::TGameCycle adjustPI(float x, float y, float z, const NLMISC::TGameCycle &pI);
727 // Look at items in hands to change the animation set.
728 bool modeWithHiddenItems() const;
730 /** Returns true if current behaviour triggers an attack end.
731 * (when projectiles & impact fx are created)
733 bool isCurrentBehaviourAttackEnd() const;
735 /** Build attack infos from current behaviour
736 * This convert any attack encoded in current behaviour (magic/melee/range/creature_attack)
737 * into a common representation (CAttackInfo)
739 void buildAttackInfo(CAttackInfo &dest);
741 /** perform current attack
742 * list of targets if given by the behaviour context
743 * (where projectiles & impact fx are reated)
745 void performCurrentAttackEnd(const CBehaviourContext &bc, bool directOffensifSpell, std::vector<double> &targetHitDates, TAnimStateKey animForCombat);
747 // update current attack from the current behaviour (this update the "_Attack" field)
748 void updateCurrentAttack();
751 /** Create part of current attack (a single projectile or/and impact, total attack may contain severals)
752 * 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)
753 * NB : target stick mode isn't filled, for this, should use computeTargetStickMode instead
754 * NB : once fully filled, the CProjectileBuild object should be inserted in the projectile manager
756 bool createCurrentAttackEndPart(CProjectileBuild &destPB,
757 const CAttack *currentAttack,
758 const CCharacterCL &target,
759 const CFXStickMode *sm,
760 double spawnDate,
761 double hitDate,
762 bool playImpactFX,
763 bool playImpactAnim,
764 bool magicResist,
765 bool mainImpactIsLocalised,
766 const CAttackInfo &attackInfo,
767 const NLMISC::CVector &additionnalOffset = NLMISC::CVector::Null
771 // Return the automaton type of the entity (homin, creature, etc.)
772 virtual std::string automatonType() const;
773 // Compute the current automaton for the entity.
774 void computeAutomaton();
776 // Return the atk height.
777 TAtkHeight getAttackHeight(CEntityCL *target, BODY::TBodyPart localisation, BODY::TSide side) const;
779 ////// FX
782 /** Stop all attached FXs linked to current anim (this wait until FX have no more particle, after what they are effectively deleted)
783 * \param stopLoopingFX If set to true, looping fx are also stopped. A looping fx has RepeatMode == Loop in its sheet.
785 void stopAttachedFXForCurrrentAnim(bool stopLoopingFX);
787 /** start items attack fxs
788 * \param intensity tranges from 1 to 5
790 void startItemAttackFXs(bool activateTrails, uint intensity);
792 // stop items attack fxs
793 void stopItemAttackFXs();
795 /** Compute some bone id (name, chest, head...)
796 * \warning This method do not check the bone is valid, nor there is a Scene.
798 void computeSomeBoneId();
801 /// Create the play list for this entity.
802 void createPlayList();
804 /** Compute each part of the visual equipement of the character
805 * \param slot: structure of the equipement.
806 * \param visualSlot: visual slot used by this item.
807 * \param instIdx : if not CEntityCL::BadIndex, replace the equipement instance at this index.
808 * \return uint32 : index of the instance or CEntityCL::BadIndex if there were a problem.
809 * \todo GUIGUI : find a better choice to avoid all these slotType tests
811 uint32 buildEquipment(const CCharacterSheet::CEquipment &slot, SLOTTYPE::EVisualSlot visualSlot, sint color = -1, uint32 instIdx = CEntityCL::BadIndex);
813 /// Compute the animation set to use according to weapons, mode and race.
814 virtual void computeAnimSet(sint32 fakeLeftHand = -1, sint32 fakeRightHand = -1);
816 /// Update Entity Position.
817 virtual void updateVisualPropertyPos (const NLMISC::TGameCycle &gameCycle, const sint64 &prop, const NLMISC::TGameCycle &pI);
818 /// Update Entity Orientation.
819 virtual void updateVisualPropertyOrient (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
820 /// Update Entity Behaviour.
821 virtual void updateVisualPropertyBehaviour (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
822 /// Update Entity Name.
823 virtual void updateVisualPropertyName (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
824 /// Update Entity Target.
825 virtual void updateVisualPropertyTarget (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
826 /// Update Entity Mode.
827 virtual void updateVisualPropertyMode (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
828 /// Update the NPC Alternative Look Property.
829 virtual void updateVisualPropertyVpa (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
830 virtual void updateVisualPropertyVpb (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
831 /// Update Entity Mount
832 virtual void updateVisualPropertyEntityMounted (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
833 /// Update Entity Rider
834 virtual void updateVisualPropertyRiderEntity (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
835 /// Update Entity Bars
836 virtual void updateVisualPropertyBars (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
837 virtual void updateVisualPropertyGuildSymbol (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
838 virtual void updateVisualPropertyGuildNameID (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
839 virtual void updateVisualPropertyEventFactionID (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
840 virtual void updateVisualPropertyPvpMode (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
841 virtual void updateVisualPropertyPvpClan (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
842 virtual void updateVisualPropertyOwnerPeople (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
843 virtual void updateVisualPropertyOutpostInfos (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
845 /// Update Entity Status
846 virtual void updateVisualPropertyStatus (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
847 // Update target list
848 virtual void updateVisualPropertyTargetList (const NLMISC::TGameCycle &gameCycle, const sint64 &prop, uint listIndex);
849 // Update tvisual fw
850 virtual void updateVisualPropertyVisualFX (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
851 /// Update vprop contextual attributes
852 virtual void updateVisualPropertyContextual (const NLMISC::TGameCycle &gameCycle, const sint64 &prop);
853 // Get The Entity Skin
854 virtual sint skin() const;
856 /// Get the direction that should have the character at the end of the animation.
857 const NL3D::CVector &dirEndAnim() {return _DirEndAnim;}
858 /// Set the direction that should have the character at the end of the animation.
859 void dirEndAnim(const NL3D::CVector &vect);
862 * Add an instance to the list of instance composing the entity.
863 * \param shapeName : shape filename.
864 * \param stickPoint : Name of the bone to stick on.
865 * \param texture : texture to use (in multi texture) or -1 for default texture.
866 * \param instIdx : if not CEntityCL::BadIndex, the instance will replace the one at this index.
867 * \return uint32 : index of the instance created, or CEntityCL::BadIndex.
869 uint32 addColoredInstance(const std::string &shapeName, const std::string &stickPoint = "", sint texture = -1, uint32 instIdx = BadIndex, sint color = -1);
871 /// Initialize properties of the entity (according to the class).
872 virtual void initProperties();
874 /// Method to Flag the character as dead and do everything needed.
875 virtual void setDead();
876 /// Method to Flag the character as alive and do everything needed.
877 virtual void setAlive();
879 void scale();
880 void applyScale(float oldCustomScale);
883 double computeTimeStep(const double &currentTime);
886 double computeSpeed();
888 * Compute and return the speed factor to apply to the animation.
889 * \param speedToDest : evaluted speed to destination.
890 * \return double : the speed factor to use for the current animation.
892 double computeSpeedFactor(double speedToDest);
895 void updateAnimationState();
897 double computeMotion(const double &oldMovingTimeOffset, TAnimationType channel = MOVE) const;
899 /// Apply stage modifications.
900 bool applyStage(CStage &stage);
901 /// Apply The Current Stage (first stage).
902 bool applyCurrentStage();
903 /// Apply all stages to the first stage with a position.
904 void applyAllStagesToFirstPos();
907 virtual void beginCast(const MBEHAV::CBehaviour &behaviour);
908 void endCast(const MBEHAV::CBehaviour &behaviour, const MBEHAV::CBehaviour &lastBehaviour);
911 /// Play the time step for the loop and truncate to End Anim if Time Step too big.
912 void playToEndAnim(const double &startTimeOffset, double &length);
914 /// Call this method to give a time for each stage, compute distance to destination and some more information.
915 void updateStages();
918 * Manage Events that could be created by the animation (like sound).
919 * \param startTime : time to start processing events from the current animation.
920 * \param stopTime : time to stop processing events from the current animation.
922 void animEventsProcessing(double startTime, double stopTime);
924 void applyColorSlot(SInstanceCL &instance, sint skin, sint userColor, sint hair, sint eyes);
926 /// Return the current max speed for the entity in meter per sec (!= swim, != mount, etc.)
927 virtual double getMaxSpeed() const;
928 // Draw the name.
929 virtual void drawName(const NLMISC::CMatrix &mat);
931 /// Set the Distance from the current entity position to the First Position.
932 void dist2FirstPos(double d2FP);
933 /// Return the Distance from the current entity position to the First Position.
934 double dist2FirstPos() const;
935 /// Set the Distance from the current entity position to the Destination.
936 void dist2Dest(double d2D);
937 /// Return the Distance from the current entity position to the Destination.
938 double dist2Dest() const;
939 /// Set the Entity Current Speed.
940 void speed(double s);
941 /// Set the Factor between Walk & Run
942 void runFactor(double factor);
943 /// Get the Factor between Walk & Run
944 double runFactor() const;
945 /// Set the Animation 'Offset' for an animation channel.
946 void animOffset(TAnimationType channel, double offset);
947 /// Get the Animation 'Offset' for an animation channel.
948 double animOffset(TAnimationType channel) const;
949 /// Set the Animation 'State' for an animation channel.
950 void animState (TAnimationType channel, TAnimStateId state);
951 /// Set the Animation 'Index' in the 'State' for an animation channel.
952 void animIndex (TAnimationType channel, CAnimation::TAnimId index);
953 /// Get the Animation 'Index' in the 'State' for an animation channel.
954 CAnimation::TAnimId animIndex (TAnimationType channel) const;
955 /// Set the Animation 'Id' among all the animations for an animation channel.
956 void animId (TAnimationType channel, uint id);
957 /// Get the Animation 'Id' among all the animations for an animation channel.
958 uint animId (TAnimationType channel) const;
961 // Read/Write Variables from/to the stream.
962 virtual void readWrite(NLMISC::IStream &f);
963 // To call after a read from a stream to re-initialize the entity.
964 virtual void load();
966 void showOrHideBodyParts( bool objectsVisible );
967 bool objectsVisible() const { return _ObjectsVisible; };
969 /// Return name position on Z axis defined in sheet
970 virtual float getNamePosZ() const;
972 private:
973 static const std::string _EmptyString;
974 const CCharacterSheet *_ClothesSheet;
975 uint32 _RHandInstIdx;
976 uint32 _LHandInstIdx;
977 // Return 'true' if the animation should be played from the end to the start.
978 std::vector<bool> _AnimReversed;
979 // Animation 'Offset' for each channel.
980 std::vector<double> _AnimOffset;
981 // Animation 'State' for each channel.
982 std::vector<TAnimStateId> _AnimState;
983 // Animation 'Index' in the 'State' for each channel (-1 if none set).
984 std::vector<CAnimation::TAnimId> _AnimIndex;
985 // Animation 'Id' among all the animations for each channel.
986 std::vector<uint> _AnimId;
988 struct CNamePosHistory
990 // ctor
991 CNamePosHistory() : LastNamePosZ(0.f), LastBonePosZ(0.f) {}
993 bool isInitialized() const { return LastNamePosZ != 0.f; }
995 float LastNamePosZ;
996 float LastBonePosZ;
999 CNamePosHistory _NamePosHistory;
1001 private:
1002 /// Call it at the end of the current animation to choose the next one.
1003 void endAnimTransition();
1005 /** Return the shape pointer from tha item and according to the character gender.
1006 * \param itemSheet : reference on the item sheet.
1007 * \return string & : reference on the shape name.
1009 std::string shapeFromItem(const CItemSheet &itemSheet) const;
1011 /// Create the instance from an item
1012 uint32 createItemInstance(const CItemSheet &itemSheet, uint32 instIdx, SLOTTYPE::EVisualSlot visualSlot, const std::string &bindBone, sint8 texture, sint color);
1014 /** Return if the impact must be played.
1015 * \param anim : pointer on the current animation (MUST NOT BE NULL).
1016 * \param currentTime : current time in the animation.
1017 * \param triggerName : name of the trigger to check.
1018 * \param isActive : read (and can change) the state.
1019 * \param timeFactor : when to activate the impact if there is no track (value has to be between 0 and 1 to be valid).
1020 * \return bool : true if the trigger is valid.
1021 * \warning This method does not check if the animation is Null.
1023 bool beginImpact(NL3D::UAnimation *anim, NL3D::TAnimationTime currentTime, const std::string &triggerName, bool &isActive, float timeFactor);
1024 /** FX played on the weapon when there is an impact.
1025 * \param index : index of the fx.
1026 * \param attackPower : power of the current attack.
1028 void weaponImpactFX(sint index, uint attackPower);
1030 // update attached fxs
1031 void updateAttachedFX();
1034 // Attach a CAttachedFX object to that character.
1035 void attachFXInternal(const CAttachedFX::TSmartPtr fx, TAttachedFXList wantedList);
1037 // attach an externally created fx in the given list (alive fx or shutting down fxs)
1038 void attachFX(NL3D::UParticleSystemInstance instance,
1039 const CAnimationFX *sheet,
1040 const CFXStickMode *stickMode,
1041 TAttachedFXList targetList,
1042 float timeOut = FX_MANAGER_DEFAULT_TIMEOUT,
1043 const NLMISC::CVector &stickOffset = NLMISC::CVector::Null,
1044 uint maxNumAnimCount = 0,
1045 uint8 targeterSlot = CLFECOMMON::INVALID_SLOT,
1046 const NLMISC::CMatrix *staticMatrix = NULL
1050 // apply visual fx from packed property (include auras and links)
1051 virtual void applyVisualFX(sint64 prop);
1052 /// Helper fct : remove any obsolete reference in a CAnimFX list to an entity slot that has just been removed.
1053 static void updateAnimFXListForSlotRemoved(std::list<CAttachedFX::TSmartPtr> &fxList, const CLFECOMMON::TCLEntityId &slotRemoved);
1055 // compute the best cast ray when creating a projectile (for guard towers)
1056 void computeBestCastRay(CEntityCL &targetEntity,
1057 const CFXStickMode &targetStickMode,
1058 NLMISC::CVector &castWorldOrigin,
1059 NLMISC::CVector &castWorldPos,
1060 NLMISC::CVector &worldOffsetToCasterPivot) const;
1062 // build cast fxs for static object (such as a guard tower ...)
1063 void buildStaticObjectCastFX(const NLMISC::CVector &castWorldOrigin,
1064 NLMISC::CVector &castWorldPos,
1065 const CAttackSheet &sheet,
1066 uint intensity
1069 // Compute the stick mode on the target for an attack
1070 void computeTargetStickMode(const CAttackSheet &sheet, const CAttackInfo &attackInfo, CFXStickMode &dest, CEntityCL &target);
1072 // remove attached fxs that depends on another slot when it has been removed
1073 void updateAttachedFXListForSlotRemoved(std::list<CAttachedFX::TSmartPtr> &fxList, const CLFECOMMON::TCLEntityId &slotRemoved);
1075 // apply the flying HP related to behaviour
1076 void applyBehaviourFlyingHPs(const CBehaviourContext &bc, const MBEHAV::CBehaviour &behaviour, const std::vector<double> &targetHitDates);
1078 protected:
1079 // retrieve attack from an id and a list of attack lists filenames
1080 const CAttack *getAttack(const CAttackIDSheet &id, const std::vector<NLMISC::TSStringId> &attackList) const;
1081 void releaseStaticFX();
1082 void initStaticFX();
1086 #endif // CL_CHARACTER_CL_H
1088 /* End of character_cl.h */