Files
TCPlayerbotCore/src/server/game/Movement/MotionMaster.h
T

188 lines
6.8 KiB
C++
Raw Normal View History

2010-10-07 15:54:07 +02:00
/*
* Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-14 11:57:03 -05:00
#ifndef TRINITY_MOTIONMASTER_H
#define TRINITY_MOTIONMASTER_H
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Common.h"
#include <vector>
2009-08-30 09:54:35 -05:00
#include "SharedDefines.h"
#include "Object.h"
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
class MovementGenerator;
class Unit;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Creature Entry ID used for waypoints show, visible only for GMs
#define VISUAL_WAYPOINT 1
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// values 0 ... MAX_DB_MOTION_TYPE-1 used in DB
enum MovementGeneratorType
{
IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h
RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h
WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h
MAX_DB_MOTION_TYPE = 3, // *** this and below motion types can't be set in DB.
ANIMAL_RANDOM_MOTION_TYPE = MAX_DB_MOTION_TYPE, // AnimalRandomMovementGenerator.h
CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h
TARGETED_MOTION_TYPE = 5, // TargetedMovementGenerator.h
HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h
FLIGHT_MOTION_TYPE = 7, // WaypointMovementGenerator.h
POINT_MOTION_TYPE = 8, // PointMovementGenerator.h
FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h
DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h
ASSISTANCE_MOTION_TYPE= 11, // PointMovementGenerator.h (first part of flee for assistance)
ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h (second part of flee for assistance)
TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h (alt.second part of flee for assistance)
ROTATE_MOTION_TYPE = 14,
NULL_MOTION_TYPE = 15,
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
2009-01-16 22:57:03 -06:00
enum MovementSlot
{
MOTION_SLOT_IDLE,
MOTION_SLOT_ACTIVE,
MOTION_SLOT_CONTROLLED,
MAX_MOTION_SLOT,
};
2009-10-17 15:51:44 -07:00
enum MMCleanFlag
{
MMCF_NONE = 0,
MMCF_UPDATE = 1, // Clear or Expire called from update
MMCF_RESET = 2 // Flag if need top()->Reset()
};
2009-10-17 15:51:44 -07:00
enum RotateDirection
{
ROTATE_DIRECTION_LEFT,
ROTATE_DIRECTION_RIGHT,
};
2009-10-17 15:51:44 -07:00
2009-03-23 15:26:13 -06:00
// assume it is 25 yard per 0.6 second
#define SPEED_CHARGE 42.0f
2009-10-17 15:51:44 -07:00
2010-02-05 00:31:28 +01:00
class MotionMaster //: private std::stack<MovementGenerator *>
2008-10-02 16:23:55 -05:00
{
private:
2009-01-16 22:57:03 -06:00
//typedef std::stack<MovementGenerator *> Impl;
typedef MovementGenerator* _Ty;
_Ty Impl[MAX_MOTION_SLOT];
2009-03-04 10:16:15 -06:00
bool needInit[MAX_MOTION_SLOT];
typedef std::vector<_Ty> ExpireList;
2009-01-16 22:57:03 -06:00
int i_top;
2009-10-17 15:51:44 -07:00
bool empty() const { return (i_top < 0); }
2009-01-16 22:57:03 -06:00
void pop() { Impl[i_top] = NULL; --i_top; }
void push(_Ty _Val) { ++i_top; Impl[i_top] = _Val; }
2009-10-17 15:51:44 -07:00
2009-03-04 10:16:15 -06:00
bool needInitTop() const { return needInit[i_top]; }
void InitTop();
2008-10-02 16:23:55 -05:00
public:
2009-10-17 15:51:44 -07:00
2010-08-21 20:08:47 +02:00
explicit MotionMaster(Unit *unit) : i_top(-1), i_owner(unit), m_expList(NULL), m_cleanFlag(MMCF_NONE)
2009-01-17 13:29:26 -06:00
{
2009-10-17 16:20:24 -07:00
for (uint8 i = 0; i < MAX_MOTION_SLOT; ++i)
2009-03-04 10:16:15 -06:00
{
2009-01-17 13:29:26 -06:00
Impl[i] = NULL;
2009-03-04 10:16:15 -06:00
needInit[i] = true;
}
2009-01-17 13:29:26 -06:00
}
2008-10-02 16:23:55 -05:00
~MotionMaster();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void Initialize();
void InitDefault();
2009-10-17 15:51:44 -07:00
2009-01-17 00:00:48 -06:00
int size() const { return i_top + 1; }
2009-01-16 22:57:03 -06:00
_Ty top() const { return Impl[i_top]; }
_Ty GetMotionSlot(int slot) const { return Impl[slot]; }
2009-10-17 15:51:44 -07:00
void DirectDelete(_Ty curr);
void DelayedDelete(_Ty curr);
2009-10-17 15:51:44 -07:00
void UpdateMotion(uint32 diff);
void Clear(bool reset = true)
{
if (m_cleanFlag & MMCF_UPDATE)
{
2010-04-07 19:14:10 +02:00
if (reset)
m_cleanFlag |= MMCF_RESET;
else
m_cleanFlag &= ~MMCF_RESET;
DelayedClean();
}
else
DirectClean(reset);
}
void MovementExpired(bool reset = true)
{
if (m_cleanFlag & MMCF_UPDATE)
{
2010-04-07 19:14:10 +02:00
if (reset)
m_cleanFlag |= MMCF_RESET;
else
m_cleanFlag &= ~MMCF_RESET;
DelayedExpire();
}
else
DirectExpire(reset);
}
2009-10-17 15:51:44 -07:00
2009-01-16 22:57:03 -06:00
void MoveIdle(MovementSlot slot = MOTION_SLOT_ACTIVE);
2008-10-02 16:23:55 -05:00
void MoveTargetedHome();
2008-12-19 00:37:40 +02:00
void MoveRandom(float spawndist = 0.0f);
void MoveFollow(Unit* target, float dist, float angle, MovementSlot slot = MOTION_SLOT_ACTIVE);
2008-10-02 16:23:55 -05:00
void MoveChase(Unit* target, float dist = 0.0f, float angle = 0.0f);
void MoveConfused();
void MoveFleeing(Unit* enemy, uint32 time = 0);
2009-08-29 23:20:16 -05:00
void MovePoint(uint32 id, const Position &pos)
{ MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ); }
2008-10-02 16:23:55 -05:00
void MovePoint(uint32 id, float x,float y,float z);
2009-08-29 23:20:16 -05:00
void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint32 id = EVENT_CHARGE);
void MoveFall(float z, uint32 id = 0);
2009-04-11 22:41:15 -05:00
void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ);
void MoveJumpTo(float angle, float speedXY, float speedZ);
2009-03-23 15:26:13 -06:00
void MoveJump(float x, float y, float z, float speedXY, float speedZ);
void MoveSeekAssistance(float x,float y,float z);
void MoveSeekAssistanceDistract(uint32 timer);
2008-10-02 16:23:55 -05:00
void MoveTaxiFlight(uint32 path, uint32 pathnode);
void MoveDistract(uint32 time);
2009-02-09 08:16:34 -05:00
void MovePath(uint32 path_id, bool repeatable);
void MoveRotate(uint32 time, RotateDirection direction);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
MovementGeneratorType GetCurrentMovementGeneratorType() const;
MovementGeneratorType GetMotionSlotType(int slot) const;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void propagateSpeedChange();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
bool GetDestination(float &x, float &y, float &z);
private:
2009-01-16 22:57:03 -06:00
void Mutate(MovementGenerator *m, MovementSlot slot); // use Move* functions instead
2009-10-17 15:51:44 -07:00
void DirectClean(bool reset);
void DelayedClean();
2009-10-17 15:51:44 -07:00
void DirectExpire(bool reset);
void DelayedExpire();
2009-10-17 15:51:44 -07:00
Unit *i_owner;
ExpireList *m_expList;
uint8 m_cleanFlag;
2008-10-02 16:23:55 -05:00
};
#endif
2009-02-17 20:07:49 -06:00