*Fix the bug that sheep attacks people.
--HG-- branch : trunk
This commit is contained in:
+35
-15
@@ -55,10 +55,13 @@ MotionMaster::Initialize()
|
||||
{
|
||||
MovementGenerator* movement = FactorySelector::selectMovementGenerator((Creature*)i_owner);
|
||||
push( movement == NULL ? &si_idleMovement : movement );
|
||||
top()->Initialize(*i_owner);
|
||||
InitTop();
|
||||
}
|
||||
else
|
||||
{
|
||||
push(&si_idleMovement);
|
||||
needInit[MOTION_SLOT_IDLE] = false;
|
||||
}
|
||||
}
|
||||
|
||||
MotionMaster::~MotionMaster()
|
||||
@@ -100,33 +103,35 @@ MotionMaster::UpdateMotion(uint32 diff)
|
||||
|
||||
if(empty())
|
||||
Initialize();
|
||||
|
||||
if (m_cleanFlag & MMCF_RESET)
|
||||
{
|
||||
else if(needInitTop())
|
||||
InitTop();
|
||||
else if (m_cleanFlag & MMCF_RESET)
|
||||
top()->Reset(*i_owner);
|
||||
|
||||
m_cleanFlag &= ~MMCF_RESET;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::DirectClean(bool reset)
|
||||
{
|
||||
while( !empty() && size() > 1 )
|
||||
while(size() > 1)
|
||||
{
|
||||
MovementGenerator *curr = top();
|
||||
pop();
|
||||
if(curr) DirectDelete(curr);
|
||||
}
|
||||
|
||||
if(reset)
|
||||
if(needInitTop())
|
||||
InitTop();
|
||||
else if(reset)
|
||||
top()->Reset(*i_owner);
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::DelayedClean()
|
||||
{
|
||||
while( !empty() && size() > 1 )
|
||||
while(size() > 1)
|
||||
{
|
||||
MovementGenerator *curr = top();
|
||||
pop();
|
||||
@@ -137,31 +142,33 @@ MotionMaster::DelayedClean()
|
||||
void
|
||||
MotionMaster::DirectExpire(bool reset)
|
||||
{
|
||||
if( empty() || size() == 1 )
|
||||
return;
|
||||
|
||||
if(size() > 1 )
|
||||
{
|
||||
MovementGenerator *curr = top();
|
||||
pop();
|
||||
DirectDelete(curr);
|
||||
}
|
||||
|
||||
while(!top())
|
||||
--i_top;
|
||||
|
||||
if(empty())
|
||||
Initialize();
|
||||
if(reset)
|
||||
else if(needInitTop())
|
||||
InitTop();
|
||||
else if(reset)
|
||||
top()->Reset(*i_owner);
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::DelayedExpire()
|
||||
{
|
||||
if( empty() || size() == 1 )
|
||||
return;
|
||||
|
||||
if(size() > 1 )
|
||||
{
|
||||
MovementGenerator *curr = top();
|
||||
pop();
|
||||
DelayedDelete(curr);
|
||||
}
|
||||
|
||||
while(!top())
|
||||
--i_top;
|
||||
@@ -396,7 +403,14 @@ void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
|
||||
{
|
||||
i_top = slot;
|
||||
}
|
||||
|
||||
if(i_top > slot)
|
||||
needInit[slot] = true;
|
||||
else
|
||||
{
|
||||
m->Initialize(*i_owner);
|
||||
needInit[slot] = false;
|
||||
}
|
||||
Impl[slot] = m;
|
||||
}
|
||||
|
||||
@@ -446,6 +460,12 @@ MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const
|
||||
return top()->GetMovementGeneratorType();
|
||||
}
|
||||
|
||||
void MotionMaster::InitTop()
|
||||
{
|
||||
top()->Initialize(*i_owner);
|
||||
needInit[i_top] = false;
|
||||
}
|
||||
|
||||
void MotionMaster::DirectDelete(_Ty curr)
|
||||
{
|
||||
if(isStatic(curr))
|
||||
|
||||
@@ -68,18 +68,25 @@ class TRINITY_DLL_SPEC MotionMaster //: private std::stack<MovementGenerator *>
|
||||
//typedef std::stack<MovementGenerator *> Impl;
|
||||
typedef MovementGenerator* _Ty;
|
||||
_Ty Impl[MAX_MOTION_SLOT];
|
||||
bool needInit[MAX_MOTION_SLOT];
|
||||
typedef std::vector<_Ty> ExpireList;
|
||||
int i_top;
|
||||
|
||||
bool empty() const { return i_top < 0; }
|
||||
void pop() { Impl[i_top] = NULL; --i_top; }
|
||||
void push(_Ty _Val) { ++i_top; Impl[i_top] = _Val; }
|
||||
|
||||
bool needInitTop() const { return needInit[i_top]; }
|
||||
void InitTop();
|
||||
public:
|
||||
|
||||
explicit MotionMaster(Unit *unit) : i_owner(unit), m_expList(NULL), m_cleanFlag(MMCF_NONE), i_top(-1)
|
||||
{
|
||||
for(int i = 0; i < MAX_MOTION_SLOT; ++i)
|
||||
{
|
||||
Impl[i] = NULL;
|
||||
needInit[i] = true;
|
||||
}
|
||||
}
|
||||
~MotionMaster();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user