[12672] Improve Waypoint Management

* Allow waypoints that have point-ids not from 1 to n
* Remove possibly bad sql-statements to "fix" the above property
* Simplify code a little bit

Remaining TODO: Bring commands up-to-date and also make things more simple instead of using the database to store visual waypoints
This commit is contained in:
Schmoozerd 2013-08-19 16:27:01 +03:00 committed by Antz
parent 5083596e26
commit e269f49f8e
5 changed files with 70 additions and 115 deletions

View file

@ -16,20 +16,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
creature_movement Table
alter table creature_movement add `textid1` int(11) NOT NULL default '0';
alter table creature_movement add `textid2` int(11) NOT NULL default '0';
alter table creature_movement add `textid3` int(11) NOT NULL default '0';
alter table creature_movement add `textid4` int(11) NOT NULL default '0';
alter table creature_movement add `textid5` int(11) NOT NULL default '0';
alter table creature_movement add `emote` int(10) unsigned default '0';
alter table creature_movement add `spell` int(5) unsigned default '0';
alter table creature_movement add `wpguid` int(11) default '0';
*/
#include <ctime>
#include "WaypointMovementGenerator.h"
@ -76,6 +62,11 @@ void WaypointMovementGenerator<Creature>::LoadPath(Creature& creature)
return;
}
}
// Initialize the i_currentNode to point to the first node
if (i_path->empty())
return;
i_currentNode = i_path->begin()->first;
}
void WaypointMovementGenerator<Creature>::Initialize(Creature& creature)
@ -119,14 +110,18 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
creature.clearUnitState(UNIT_STAT_ROAMING_MOVE);
m_isArrivalDone = true;
if (i_path->at(i_currentNode).script_id)
WaypointPath::const_iterator currPoint = i_path->find(i_currentNode);
MANGOS_ASSERT(currPoint != i_path->end());
WaypointNode const& node = currPoint->second;
if (node.script_id)
{
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature movement start script %u at point %u for %s.", i_path->at(i_currentNode).script_id, i_currentNode, creature.GetGuidStr().c_str());
creature.GetMap()->ScriptsStart(sCreatureMovementScripts, i_path->at(i_currentNode).script_id, &creature, &creature);
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature movement start script %u at point %u for %s.", node.script_id, i_currentNode, creature.GetGuidStr().c_str());
creature.GetMap()->ScriptsStart(sCreatureMovementScripts, node.script_id, &creature, &creature);
}
// We have reached the destination and can process behavior
if (WaypointBehavior* behavior = i_path->at(i_currentNode).behavior)
if (WaypointBehavior* behavior = node.behavior)
{
if (behavior->emote != 0)
creature.HandleEmote(behavior->emote);
@ -159,7 +154,7 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
// Inform script
MovementInform(creature);
Stop(i_path->at(i_currentNode).delay);
Stop(node.delay);
}
void WaypointMovementGenerator<Creature>::StartMoveNow(Creature& creature)
@ -177,7 +172,10 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature& creature)
if (Stopped(creature))
return;
if (WaypointBehavior* behavior = i_path->at(i_currentNode).behavior)
WaypointPath::const_iterator currPoint = i_path->find(i_currentNode);
MANGOS_ASSERT(currPoint != i_path->end());
if (WaypointBehavior* behavior = currPoint->second.behavior)
{
if (behavior->model2 != 0)
creature.SetDisplayId(behavior->model2);
@ -185,18 +183,24 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature& creature)
}
if (m_isArrivalDone)
i_currentNode = (i_currentNode + 1) % i_path->size();
{
++currPoint;
if (currPoint == i_path->end())
currPoint = i_path->begin();
i_currentNode = currPoint->first;
}
m_isArrivalDone = false;
creature.addUnitState(UNIT_STAT_ROAMING_MOVE);
const WaypointNode& node = i_path->at(i_currentNode);
WaypointNode const& nextNode = currPoint->second;;
Movement::MoveSplineInit init(creature);
init.MoveTo(node.x, node.y, node.z, true);
init.MoveTo(nextNode.x, nextNode.y, nextNode.z, true);
if (node.orientation != 100 && node.delay != 0)
init.SetFacing(node.orientation);
if (nextNode.orientation != 100 && nextNode.delay != 0)
init.SetFacing(nextNode.orientation);
creature.SetWalk(!creature.hasUnitState(UNIT_STAT_RUNNING_STATE) && !creature.IsLevitating(), false);
init.Launch();
}