mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 17:05:44 +01:00
*Movement Generators standardization.
- bool GetDestination(&x,&y,&z) added to all movement generators.(it is used by update of players view distance) - Fixed when creature entering in combat not count this as StoppedByPlayer. - Random Movement Generator - added support for creating custom spawndist during the game. - Random Movement Generator - Db spawndist is checked only at initialize(NOT in each sellect of random location). - Added Random Movement to motion master - it can be called now by MoveRandom(spawndist) e.g. for use in SD2. - Home and Random movements no more using RespawnCoords(Home Position has implemented) - Fixed bug when creature is moving on path and enter combat, after that returns to spawn position. -Typo fix in Confused Movement Generator --HG-- branch : trunk
This commit is contained in:
@@ -18,8 +18,8 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_RANDOMMOTIONGENERATOR_H
|
||||
#define TRINITY_RANDOMMOTIONGENERATOR_H
|
||||
#ifndef TRINITY_CONFUSEDGENERATOR_H
|
||||
#define TRINITY_CONFUSEDGENERATOR_H
|
||||
|
||||
#include "MovementGenerator.h"
|
||||
#include "DestinationHolder.h"
|
||||
@@ -39,7 +39,14 @@ class TRINITY_DLL_SPEC ConfusedMovementGenerator
|
||||
void Reset(T &);
|
||||
bool Update(T &, const uint32 &);
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() { return CONFUSED_MOTION_TYPE; }
|
||||
bool GetDestination(float &x, float &y, float &z) const
|
||||
{
|
||||
if(i_destinationHolder.HasArrived()) return false;
|
||||
i_destinationHolder.GetDestination(x,y,z);
|
||||
return true;
|
||||
}
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() { return CONFUSED_MOTION_TYPE; }
|
||||
private:
|
||||
void _InitSpecific(T &, bool &, bool &);
|
||||
TimeTracker i_nextMoveTime;
|
||||
|
||||
@@ -1403,8 +1403,10 @@ bool Creature::LoadFromDB(uint32 guid, Map *map)
|
||||
sLog.outError("ERROR: Creature (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)",GetGUIDLow(),GetEntry(),GetPositionX(),GetPositionY());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_respawnradius = data->spawndist;
|
||||
//We should set first home position, because then AI calls home movement
|
||||
SetHomePosition(data->posX,data->posY,data->posZ,data->orientation);
|
||||
|
||||
m_respawnradius = data->spawndist;
|
||||
|
||||
m_respawnDelay = data->spawntimesecs;
|
||||
m_isDeadByDefault = data->is_dead;
|
||||
@@ -2003,7 +2005,7 @@ bool Creature::IsOutOfThreatArea(Unit* pVictim) const
|
||||
if(sMapStore.LookupEntry(GetMapId())->IsDungeon())
|
||||
return false;
|
||||
|
||||
float length = pVictim->GetDistance(CombatStartX,CombatStartY,CombatStartZ);
|
||||
float length = pVictim->GetDistance(mHome_X, mHome_Y, mHome_Z);
|
||||
float AttackDist = GetAttackDistance(pVictim);
|
||||
uint32 ThreatRadius = sWorld.getConfig(CONFIG_THREAT_RADIUS);
|
||||
|
||||
|
||||
@@ -615,8 +615,8 @@ class TRINITY_DLL_SPEC Creature : public Unit
|
||||
return m_charmInfo->GetCharmSpell(pos)->spellId;
|
||||
}
|
||||
|
||||
void SetCombatStartPosition(float x, float y, float z) { CombatStartX = x; CombatStartY = y; CombatStartZ = z; }
|
||||
void GetCombatStartPosition(float &x, float &y, float &z) { x = CombatStartX; y = CombatStartY; z = CombatStartZ; }
|
||||
void SetHomePosition(float x, float y, float z, float ori) { mHome_X = x; mHome_Y = y; mHome_Z = z; mHome_O = ori;}
|
||||
void GetHomePosition(float &x, float &y, float &z, float &ori) { x = mHome_X; y = mHome_Y; z = mHome_Z; ori = mHome_O; }
|
||||
|
||||
uint32 GetGlobalCooldown() const { return m_GlobalCooldown; }
|
||||
|
||||
@@ -675,9 +675,10 @@ class TRINITY_DLL_SPEC Creature : public Unit
|
||||
SpellSchoolMask m_meleeDamageSchoolMask;
|
||||
uint32 m_originalEntry;
|
||||
|
||||
float CombatStartX;
|
||||
float CombatStartY;
|
||||
float CombatStartZ;
|
||||
float mHome_X;
|
||||
float mHome_Y;
|
||||
float mHome_Z;
|
||||
float mHome_O;
|
||||
|
||||
private:
|
||||
//WaypointMovementGenerator vars
|
||||
|
||||
@@ -49,6 +49,22 @@ FleeingMovementGenerator<T>::_setTargetLocation(T &owner)
|
||||
i_destinationHolder.SetDestination(traveller, x, y, z);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool FleeingMovementGenerator<Creature>::GetDestination(float &x, float &y, float &z) const
|
||||
{
|
||||
if(i_destinationHolder.HasArrived())
|
||||
return false;
|
||||
|
||||
i_destinationHolder.GetDestination(x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool FleeingMovementGenerator<Player>::GetDestination(float &x, float &y, float &z) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
FleeingMovementGenerator<T>::_getPoint(T &owner, float &x, float &y, float &z)
|
||||
|
||||
@@ -37,6 +37,7 @@ class TRINITY_DLL_SPEC FleeingMovementGenerator
|
||||
void Finalize(T &);
|
||||
void Reset(T &);
|
||||
bool Update(T &, const uint32 &);
|
||||
bool GetDestination(float &x, float &y, float &z) const;
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() { return FLEEING_MOTION_TYPE; }
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "MapManager.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "DestinationHolderImp.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "WorldPacket.h"
|
||||
|
||||
void
|
||||
@@ -49,7 +48,7 @@ HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
|
||||
return;
|
||||
|
||||
float x, y, z;
|
||||
owner.GetRespawnCoord(x, y, z);
|
||||
owner.GetHomePosition(x, y, z, ori);
|
||||
|
||||
CreatureTraveller traveller(owner);
|
||||
|
||||
@@ -71,13 +70,10 @@ HomeMovementGenerator<Creature>::Update(Creature &owner, const uint32& time_diff
|
||||
// restore orientation of not moving creature at returning to home
|
||||
if(owner.GetDefaultMovementType()==IDLE_MOTION_TYPE)
|
||||
{
|
||||
if(CreatureData const* data = objmgr.GetCreatureData(owner.GetDBTableGUIDLow()))
|
||||
{
|
||||
owner.SetOrientation(data->orientation);
|
||||
WorldPacket packet;
|
||||
owner.BuildHeartBeatMsg(&packet);
|
||||
owner.SendMessageToSet(&packet, false);
|
||||
}
|
||||
owner.SetOrientation(ori);
|
||||
WorldPacket packet;
|
||||
owner.BuildHeartBeatMsg(&packet);
|
||||
owner.SendMessageToSet(&packet, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ class TRINITY_DLL_SPEC HomeMovementGenerator<Creature>
|
||||
void _setTargetLocation(Creature &);
|
||||
DestinationHolder< Traveller<Creature> > i_destinationHolder;
|
||||
|
||||
float ori;
|
||||
uint32 i_travel_timer;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "PointMovementGenerator.h"
|
||||
#include "TargetedMovementGenerator.h"
|
||||
#include "WaypointMovementGenerator.h"
|
||||
#include "RandomMovementGenerator.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@@ -104,6 +105,16 @@ MotionMaster::Clear(bool reset)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveRandom(float spawndist)
|
||||
{
|
||||
if(i_owner->GetTypeId()==TYPEID_UNIT)
|
||||
{
|
||||
DEBUG_LOG("Creature (GUID: %u) start moving random", i_owner->GetGUIDLow() );
|
||||
Mutate(new RandomMovementGenerator<Creature>(spawndist));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MovementExpired(bool reset)
|
||||
{
|
||||
|
||||
@@ -73,7 +73,8 @@ class TRINITY_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *>
|
||||
|
||||
void MoveIdle();
|
||||
void MoveTargetedHome();
|
||||
void MoveFollow(Unit* target, float dist, float angle);
|
||||
void MoveRandom(float spawndist = 0.0f);
|
||||
void MoveFollow(Unit* target, float dist, float angle);
|
||||
void MoveChase(Unit* target, float dist = 0.0f, float angle = 0.0f);
|
||||
void MoveConfused();
|
||||
void MoveFleeing(Unit* enemy);
|
||||
|
||||
@@ -1542,7 +1542,8 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCreature->Summon(spwtype, despwtime);
|
||||
pCreature->SetHomePosition(x, y, z, ang);
|
||||
pCreature->Summon(spwtype, despwtime);
|
||||
|
||||
if(GetTypeId()==TYPEID_UNIT && ((Creature*)this)->AI())
|
||||
((Creature*)this)->AI()->JustSummoned(pCreature);
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "Creature.h"
|
||||
#include "MapManager.h"
|
||||
#include "RandomMovementGenerator.h"
|
||||
#include "Traveller.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "DestinationHolderImp.h"
|
||||
#include "Map.h"
|
||||
#include "Util.h"
|
||||
@@ -42,9 +44,9 @@ template<>
|
||||
void
|
||||
RandomMovementGenerator<Creature>::_setRandomLocation(Creature &creature)
|
||||
{
|
||||
float X,Y,Z,z,nx,ny,nz,wander_distance,ori,dist;
|
||||
float X,Y,Z,z,nx,ny,nz,ori,dist;
|
||||
|
||||
creature.GetRespawnCoord(X, Y, Z, &ori, &wander_distance);
|
||||
creature.GetHomePosition(X, Y, Z, ori);
|
||||
|
||||
z = creature.GetPositionZ();
|
||||
uint32 mapid=creature.GetMapId();
|
||||
@@ -120,8 +122,10 @@ RandomMovementGenerator<Creature>::Initialize(Creature &creature)
|
||||
{
|
||||
if(!creature.isAlive())
|
||||
return;
|
||||
|
||||
if (creature.canFly())
|
||||
|
||||
wander_distance = creature.GetRespawnRadius();
|
||||
|
||||
if (creature.canFly())
|
||||
creature.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2);
|
||||
else
|
||||
creature.SetUnitMovementFlags(irand(0,RUNNING_CHANCE_RANDOMMV) > 0 ? MOVEMENTFLAG_WALK_MODE : MOVEMENTFLAG_NONE );
|
||||
@@ -135,6 +139,10 @@ RandomMovementGenerator<Creature>::Reset(Creature &creature)
|
||||
Initialize(creature);
|
||||
}
|
||||
|
||||
template<>
|
||||
void
|
||||
RandomMovementGenerator<Creature>::Finalize(Creature &creature){}
|
||||
|
||||
template<>
|
||||
bool
|
||||
RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff)
|
||||
|
||||
@@ -25,17 +25,17 @@
|
||||
#include "DestinationHolder.h"
|
||||
#include "Traveller.h"
|
||||
|
||||
|
||||
template<class T>
|
||||
class TRINITY_DLL_SPEC RandomMovementGenerator
|
||||
: public MovementGeneratorMedium< T, RandomMovementGenerator<T> >
|
||||
{
|
||||
public:
|
||||
RandomMovementGenerator() : i_nextMoveTime(0) {}
|
||||
|
||||
void _setRandomLocation(T &);
|
||||
// Wander dist is related on db spawn dist. So what if we wanna set eandom movement on summoned creature?!
|
||||
RandomMovementGenerator(float spawn_dist = 0.0f) : i_nextMoveTime(0), wander_distance(spawn_dist) {}
|
||||
|
||||
void _setRandomLocation(T &);
|
||||
void Initialize(T &);
|
||||
void Finalize(T &) {}
|
||||
void Finalize(T &);
|
||||
void Reset(T &);
|
||||
bool Update(T &, const uint32 &);
|
||||
bool GetDestination(float &x, float &y, float &z) const;
|
||||
@@ -48,6 +48,7 @@ class TRINITY_DLL_SPEC RandomMovementGenerator
|
||||
TimeTrackerSmall i_nextMoveTime;
|
||||
|
||||
DestinationHolder< Traveller<T> > i_destinationHolder;
|
||||
uint32 i_nextMove;
|
||||
float wander_distance;
|
||||
uint32 i_nextMove;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -57,7 +57,7 @@ class TRINITY_DLL_SPEC TargetedMovementGenerator
|
||||
|
||||
bool GetDestination(float &x, float &y, float &z) const
|
||||
{
|
||||
if(!i_destinationHolder.HasDestination()) return false;
|
||||
if(i_destinationHolder.HasArrived()) return false;
|
||||
i_destinationHolder.GetDestination(x,y,z);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8169,7 +8169,7 @@ bool Unit::Attack(Unit *victim, bool meleeAttack)
|
||||
((WorldObject*)this)->SendMessageToSet(&data, true);
|
||||
|
||||
((Creature*)this)->CallAssistance();
|
||||
((Creature*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
|
||||
((Creature*)this)->SetHomePosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation());
|
||||
}
|
||||
|
||||
// delay offhand weapon attack to next attack time
|
||||
|
||||
@@ -43,7 +43,6 @@ void
|
||||
WaypointMovementGenerator<Creature>::Initialize(Creature &u)
|
||||
{
|
||||
i_currentNode = -1;
|
||||
u.StopMoving();
|
||||
if(!path_id)
|
||||
path_id = u.GetWaypointPath();
|
||||
waypoints = WaypointMgr.GetPath(path_id);
|
||||
@@ -84,7 +83,11 @@ bool WaypointMovementGenerator<Player>::GetDestination(float &x, float &y, float
|
||||
}
|
||||
|
||||
template<>
|
||||
void WaypointMovementGenerator<Creature>::Reset(Creature &unit){}
|
||||
void WaypointMovementGenerator<Creature>::Reset(Creature &unit)
|
||||
{
|
||||
StopedByPlayer = false;
|
||||
i_nextMoveTime.Reset(0);
|
||||
}
|
||||
|
||||
template<>
|
||||
void WaypointMovementGenerator<Player>::Reset(Player &unit){}
|
||||
|
||||
Reference in New Issue
Block a user