[8989] Clean up parts of WaypointMovementGen code for better readability

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2009-12-14 09:30:28 +01:00
parent 1057f6fd28
commit 1eafc8dfc4
2 changed files with 59 additions and 36 deletions

View file

@ -45,18 +45,20 @@ alter table creature_movement add `wpguid` int(11) default '0';
//-----------------------------------------------// //-----------------------------------------------//
void WaypointMovementGenerator<Creature>::LoadPath(Creature &c) 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()); i_path = sWaypointMgr.GetPath(c.GetDBTableGUIDLow());
if (!i_path) 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()); c.GetName(), c.GetEntry(), c.GetDBTableGUIDLow());
return; return;
} }
uint32 node_count = i_path->size(); uint32 node_count = i_path->size();
i_hasDone.resize(node_count); i_hasDone.resize(node_count);
for(uint32 i = 0; i < node_count-1; ++i) for(uint32 i = 0; i < node_count-1; ++i)
i_hasDone[i] = false; 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 // i_path was modified by chat commands for example
if (i_path->size() != i_hasDone.size()) if (i_path->size() != i_hasDone.size())
i_hasDone.resize(i_path->size()); i_hasDone.resize(i_path->size());
if (i_currentNode >= i_path->size()) if (i_currentNode >= i_path->size())
i_currentNode = 0; 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 // creature has been stopped in middle of the waypoint segment
if (!i_destinationHolder.HasArrived() && creature.IsStopped()) 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); SetStoppedByPlayer(false);
// Now we re-set destination to same node and start travel
creature.addUnitState(UNIT_STAT_ROAMING); creature.addUnitState(UNIT_STAT_ROAMING);
if (creature.canFly()) if (creature.canFly())
creature.AddMonsterMoveFlag(MONSTER_MOVE_FLY); creature.AddMonsterMoveFlag(MONSTER_MOVE_FLY);
// Now we re-set destination to same node and start travel
const WaypointNode &node = i_path->at(i_currentNode); const WaypointNode &node = i_path->at(i_currentNode);
i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z); i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z);
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime()); i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
} }
else // if( !i_nextMoveTime.Passed()) 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()) if (!IsStoppedByPlayer())
{ // Put 30 seconds delay {
// Put 30 seconds delay
i_destinationHolder.IncreaseTravelTime(STOP_TIME_FOR_PLAYER); i_destinationHolder.IncreaseTravelTime(STOP_TIME_FOR_PLAYER);
i_nextMoveTime.Reset(STOP_TIME_FOR_PLAYER); i_nextMoveTime.Reset(STOP_TIME_FOR_PLAYER);
SetStoppedByPlayer(true); // Mark we did it SetStoppedByPlayer(true); // Mark we did it
@ -140,20 +149,25 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
{ {
if (behavior->emote != 0) if (behavior->emote != 0)
creature.SetUInt32Value(UNIT_NPC_EMOTESTATE, behavior->emote); creature.SetUInt32Value(UNIT_NPC_EMOTESTATE, behavior->emote);
if (behavior->spell != 0) if (behavior->spell != 0)
creature.CastSpell(&creature, behavior->spell, false); creature.CastSpell(&creature, behavior->spell, false);
if (behavior->model1 != 0) if (behavior->model1 != 0)
creature.SetDisplayId(behavior->model1); creature.SetDisplayId(behavior->model1);
if (behavior->textid[0]) if (behavior->textid[0])
{ {
// Not only one text is set // Not only one text is set
if (behavior->textid[1]) 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; int i = 2;
for(; i < MAX_WAYPOINT_TEXT; ++i) for(; i < MAX_WAYPOINT_TEXT; ++i)
{
if (!behavior->textid[i]) if (!behavior->textid[i])
break; break;
}
creature.Say(behavior->textid[rand() % i], 0, 0); creature.Say(behavior->textid[rand() % i], 0, 0);
} }
@ -167,16 +181,21 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
} // HasDone == false } // HasDone == false
} // i_creature.IsStopped() } // 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); creature.addUnitState(UNIT_STAT_ROAMING);
if (creature.canFly()) if (creature.canFly())
creature.AddMonsterMoveFlag(MONSTER_MOVE_FLY); creature.AddMonsterMoveFlag(MONSTER_MOVE_FLY);
const WaypointNode &node = i_path->at(i_currentNode); const WaypointNode &node = i_path->at(i_currentNode);
i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z); i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z);
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime()); i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
uint32 idx = i_currentNode > 0 ? i_currentNode-1 : i_path->size()-1; uint32 idx = i_currentNode > 0 ? i_currentNode-1 : i_path->size()-1;
if (i_path->at(idx).orientation != 100) 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) if (WaypointBehavior *behavior = i_path->at(idx).behavior)
{ {
i_hasDone[idx] = false; i_hasDone[idx] = false;
if (behavior->model2 != 0) if (behavior->model2 != 0)
creature.SetDisplayId(behavior->model2); creature.SetDisplayId(behavior->model2);
creature.SetUInt32Value(UNIT_NPC_EMOTESTATE, 0); 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(); creature.StopMoving();
SetStoppedByPlayer(false); SetStoppedByPlayer(false);
i_nextMoveTime.Reset(i_path->at(i_currentNode).delay); i_nextMoveTime.Reset(i_path->at(i_currentNode).delay);
++i_currentNode; ++i_currentNode;
if (i_currentNode >= i_path->size()) if (i_currentNode >= i_path->size())
i_currentNode = 0; i_currentNode = 0;
} }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "8988" #define REVISION_NR "8989"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__