mirror of
https://github.com/mangosfour/server.git
synced 2025-12-18 10:37:01 +00:00
[8989] Clean up parts of WaypointMovementGen code for better readability
Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
parent
1057f6fd28
commit
1eafc8dfc4
2 changed files with 59 additions and 36 deletions
|
|
@ -45,18 +45,20 @@ alter table creature_movement add `wpguid` int(11) default '0';
|
|||
//-----------------------------------------------//
|
||||
void WaypointMovementGenerator<Creature>::LoadPath(Creature &c)
|
||||
{
|
||||
sLog.outDetail("LoadPath: loading waypoint path for creature %d,%d", c.GetGUIDLow(), c.GetDBTableGUIDLow());
|
||||
sLog.outDetail("LoadPath: loading waypoint path for creature %u, %u", c.GetGUIDLow(), c.GetDBTableGUIDLow());
|
||||
|
||||
i_path = sWaypointMgr.GetPath(c.GetDBTableGUIDLow());
|
||||
|
||||
if (!i_path)
|
||||
{
|
||||
sLog.outErrorDb("WaypointMovementGenerator::LoadPath: creature %s (Entry: %u GUID: %d) doesn't have waypoint path",
|
||||
sLog.outErrorDb("WaypointMovementGenerator::LoadPath: creature %s (Entry: %u GUID: %u) doesn't have waypoint path",
|
||||
c.GetName(), c.GetEntry(), c.GetDBTableGUIDLow());
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 node_count = i_path->size();
|
||||
i_hasDone.resize(node_count);
|
||||
|
||||
for(uint32 i = 0; i < node_count-1; ++i)
|
||||
i_hasDone[i] = false;
|
||||
|
||||
|
|
@ -93,6 +95,7 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
|
|||
// i_path was modified by chat commands for example
|
||||
if (i_path->size() != i_hasDone.size())
|
||||
i_hasDone.resize(i_path->size());
|
||||
|
||||
if (i_currentNode >= i_path->size())
|
||||
i_currentNode = 0;
|
||||
|
||||
|
|
@ -104,21 +107,27 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
|
|||
// creature has been stopped in middle of the waypoint segment
|
||||
if (!i_destinationHolder.HasArrived() && creature.IsStopped())
|
||||
{
|
||||
if( i_nextMoveTime.Passed()) // Timer has elapsed, meaning this part controlled it
|
||||
// Timer has elapsed, meaning this part controlled it
|
||||
if (i_nextMoveTime.Passed())
|
||||
{
|
||||
SetStoppedByPlayer(false);
|
||||
// Now we re-set destination to same node and start travel
|
||||
|
||||
creature.addUnitState(UNIT_STAT_ROAMING);
|
||||
|
||||
if (creature.canFly())
|
||||
creature.AddMonsterMoveFlag(MONSTER_MOVE_FLY);
|
||||
|
||||
// Now we re-set destination to same node and start travel
|
||||
const WaypointNode &node = i_path->at(i_currentNode);
|
||||
i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z);
|
||||
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
||||
}
|
||||
else // if( !i_nextMoveTime.Passed())
|
||||
{ // unexpected end of timer && creature stopped && not at end of segment
|
||||
{
|
||||
// unexpected end of timer && creature stopped && not at end of segment
|
||||
if (!IsStoppedByPlayer())
|
||||
{ // Put 30 seconds delay
|
||||
{
|
||||
// Put 30 seconds delay
|
||||
i_destinationHolder.IncreaseTravelTime(STOP_TIME_FOR_PLAYER);
|
||||
i_nextMoveTime.Reset(STOP_TIME_FOR_PLAYER);
|
||||
SetStoppedByPlayer(true); // Mark we did it
|
||||
|
|
@ -140,20 +149,25 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
|
|||
{
|
||||
if (behavior->emote != 0)
|
||||
creature.SetUInt32Value(UNIT_NPC_EMOTESTATE, behavior->emote);
|
||||
|
||||
if (behavior->spell != 0)
|
||||
creature.CastSpell(&creature, behavior->spell, false);
|
||||
|
||||
if (behavior->model1 != 0)
|
||||
creature.SetDisplayId(behavior->model1);
|
||||
|
||||
if (behavior->textid[0])
|
||||
{
|
||||
// Not only one text is set
|
||||
if (behavior->textid[1])
|
||||
{
|
||||
// Select one from max 5 texts (0 and 1 laready checked)
|
||||
// Select one from max 5 texts (0 and 1 already checked)
|
||||
int i = 2;
|
||||
for(; i < MAX_WAYPOINT_TEXT; ++i)
|
||||
{
|
||||
if (!behavior->textid[i])
|
||||
break;
|
||||
}
|
||||
|
||||
creature.Say(behavior->textid[rand() % i], 0, 0);
|
||||
}
|
||||
|
|
@ -167,16 +181,21 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
|
|||
} // HasDone == false
|
||||
} // i_creature.IsStopped()
|
||||
|
||||
if( i_nextMoveTime.Passed() ) // This is at the end of waypoint segment or has been stopped by player
|
||||
// This is at the end of waypoint segment or has been stopped by player
|
||||
if (i_nextMoveTime.Passed())
|
||||
{
|
||||
if( creature.IsStopped() ) // If stopped then begin a new move segment
|
||||
// If stopped then begin a new move segment
|
||||
if (creature.IsStopped())
|
||||
{
|
||||
creature.addUnitState(UNIT_STAT_ROAMING);
|
||||
|
||||
if (creature.canFly())
|
||||
creature.AddMonsterMoveFlag(MONSTER_MOVE_FLY);
|
||||
|
||||
const WaypointNode &node = i_path->at(i_currentNode);
|
||||
i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z);
|
||||
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
||||
|
||||
uint32 idx = i_currentNode > 0 ? i_currentNode-1 : i_path->size()-1;
|
||||
|
||||
if (i_path->at(idx).orientation != 100)
|
||||
|
|
@ -185,18 +204,22 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
|
|||
if (WaypointBehavior *behavior = i_path->at(idx).behavior)
|
||||
{
|
||||
i_hasDone[idx] = false;
|
||||
|
||||
if (behavior->model2 != 0)
|
||||
creature.SetDisplayId(behavior->model2);
|
||||
|
||||
creature.SetUInt32Value(UNIT_NPC_EMOTESTATE, 0);
|
||||
}
|
||||
}
|
||||
else // If not stopped then stop it and set the reset of TimeTracker to waittime
|
||||
else
|
||||
{
|
||||
// If not stopped then stop it and set the reset of TimeTracker to waittime
|
||||
creature.StopMoving();
|
||||
SetStoppedByPlayer(false);
|
||||
|
||||
i_nextMoveTime.Reset(i_path->at(i_currentNode).delay);
|
||||
++i_currentNode;
|
||||
|
||||
if (i_currentNode >= i_path->size())
|
||||
i_currentNode = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "8988"
|
||||
#define REVISION_NR "8989"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue