aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/ConfusedMovementGenerator.h13
-rw-r--r--src/game/Creature.cpp8
-rw-r--r--src/game/Creature.h11
-rw-r--r--src/game/FleeingMovementGenerator.cpp16
-rw-r--r--src/game/FleeingMovementGenerator.h1
-rw-r--r--src/game/HomeMovementGenerator.cpp14
-rw-r--r--src/game/HomeMovementGenerator.h1
-rw-r--r--src/game/MotionMaster.cpp11
-rw-r--r--src/game/MotionMaster.h3
-rw-r--r--src/game/Object.cpp3
-rw-r--r--src/game/RandomMovementGenerator.cpp16
-rw-r--r--src/game/RandomMovementGenerator.h13
-rw-r--r--src/game/TargetedMovementGenerator.h2
-rw-r--r--src/game/Unit.cpp2
-rw-r--r--src/game/WaypointMovementGenerator.cpp7
15 files changed, 85 insertions, 36 deletions
diff --git a/src/game/ConfusedMovementGenerator.h b/src/game/ConfusedMovementGenerator.h
index d4f1cd9267b..502617e140f 100644
--- a/src/game/ConfusedMovementGenerator.h
+++ b/src/game/ConfusedMovementGenerator.h
@@ -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;
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index c70ffdba940..3fc5598295a 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -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);
diff --git a/src/game/Creature.h b/src/game/Creature.h
index abffa6c710a..6312dfbe958 100644
--- a/src/game/Creature.h
+++ b/src/game/Creature.h
@@ -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
diff --git a/src/game/FleeingMovementGenerator.cpp b/src/game/FleeingMovementGenerator.cpp
index 47f305cda5d..69c2c37dffe 100644
--- a/src/game/FleeingMovementGenerator.cpp
+++ b/src/game/FleeingMovementGenerator.cpp
@@ -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)
diff --git a/src/game/FleeingMovementGenerator.h b/src/game/FleeingMovementGenerator.h
index 2fdb0986735..6024f64ded6 100644
--- a/src/game/FleeingMovementGenerator.h
+++ b/src/game/FleeingMovementGenerator.h
@@ -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; }
diff --git a/src/game/HomeMovementGenerator.cpp b/src/game/HomeMovementGenerator.cpp
index 1b02e4fddc2..76d5b9626d6 100644
--- a/src/game/HomeMovementGenerator.cpp
+++ b/src/game/HomeMovementGenerator.cpp
@@ -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;
}
diff --git a/src/game/HomeMovementGenerator.h b/src/game/HomeMovementGenerator.h
index 1f045134289..ce47d0351ee 100644
--- a/src/game/HomeMovementGenerator.h
+++ b/src/game/HomeMovementGenerator.h
@@ -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
diff --git a/src/game/MotionMaster.cpp b/src/game/MotionMaster.cpp
index 834770ae8a5..4b667ad9ccd 100644
--- a/src/game/MotionMaster.cpp
+++ b/src/game/MotionMaster.cpp
@@ -30,6 +30,7 @@
#include "PointMovementGenerator.h"
#include "TargetedMovementGenerator.h"
#include "WaypointMovementGenerator.h"
+#include "RandomMovementGenerator.h"
#include <cassert>
@@ -105,6 +106,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)
{
if( empty() || size() == 1 )
diff --git a/src/game/MotionMaster.h b/src/game/MotionMaster.h
index 3a17b8e135e..209b2cf176e 100644
--- a/src/game/MotionMaster.h
+++ b/src/game/MotionMaster.h
@@ -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);
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 858f141aa6c..efd041f34c2 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -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);
diff --git a/src/game/RandomMovementGenerator.cpp b/src/game/RandomMovementGenerator.cpp
index 311cc7c6e17..db4f6bf5b42 100644
--- a/src/game/RandomMovementGenerator.cpp
+++ b/src/game/RandomMovementGenerator.cpp
@@ -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 );
@@ -136,6 +140,10 @@ RandomMovementGenerator<Creature>::Reset(Creature &creature)
}
template<>
+void
+RandomMovementGenerator<Creature>::Finalize(Creature &creature){}
+
+template<>
bool
RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff)
{
diff --git a/src/game/RandomMovementGenerator.h b/src/game/RandomMovementGenerator.h
index dd6e3a48283..a88b227d17f 100644
--- a/src/game/RandomMovementGenerator.h
+++ b/src/game/RandomMovementGenerator.h
@@ -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
diff --git a/src/game/TargetedMovementGenerator.h b/src/game/TargetedMovementGenerator.h
index 6dcfae35aa7..75e60728ea3 100644
--- a/src/game/TargetedMovementGenerator.h
+++ b/src/game/TargetedMovementGenerator.h
@@ -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;
}
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 7d996e3e7a2..dba851c6fa7 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -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
diff --git a/src/game/WaypointMovementGenerator.cpp b/src/game/WaypointMovementGenerator.cpp
index 56f244dd831..42212113f61 100644
--- a/src/game/WaypointMovementGenerator.cpp
+++ b/src/game/WaypointMovementGenerator.cpp
@@ -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){}