*Some code cleanups and crash fixes with Waypoint Movement Generator.
--HG-- branch : trunk
This commit is contained in:
+17
-130
@@ -2183,7 +2183,6 @@ bool ChatHandler::HandleWpAddCommand(const char* args)
|
||||
pathid = maxpathid+1;
|
||||
sLog.outDebug("DEBUG: HandleWpAddCommand - New path started.");
|
||||
PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -2222,7 +2221,6 @@ bool ChatHandler::HandleWpAddCommand(const char* args)
|
||||
|
||||
bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
||||
{
|
||||
|
||||
if(!*args)
|
||||
return false;
|
||||
|
||||
@@ -2230,9 +2228,8 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
||||
char* path_number = NULL;
|
||||
|
||||
if(*args)
|
||||
{
|
||||
path_number = strtok((char*)args, " ");
|
||||
}
|
||||
|
||||
|
||||
uint32 pathid = 0;
|
||||
uint32 guidlow = 0;
|
||||
@@ -2248,6 +2245,7 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(target->GetEntry() == 1)
|
||||
{
|
||||
PSendSysMessage("%s%s|r", "|cffff33ff", "You want to load path to a waypoint? Aren't you?");
|
||||
@@ -2256,6 +2254,7 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
||||
}
|
||||
|
||||
pathid = atoi(path_number);
|
||||
|
||||
if(!pathid)
|
||||
{
|
||||
PSendSysMessage("%s%s|r", "|cffff33ff", "No vallid path number provided.");
|
||||
@@ -2263,7 +2262,6 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
||||
}
|
||||
|
||||
guidlow = target->GetGUIDLow();
|
||||
|
||||
QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE guid = '%u'",guidlow);
|
||||
|
||||
if( result )
|
||||
@@ -2277,11 +2275,8 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
||||
WorldDatabase.PExecute("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE, guidlow);
|
||||
|
||||
target->LoadPath(pathid);
|
||||
|
||||
target->SetDefaultMovementType(WAYPOINT_MOTION_TYPE);
|
||||
|
||||
target->GetMotionMaster()->Initialize();
|
||||
|
||||
target->Say("Path loaded.",0,0);
|
||||
|
||||
return true;
|
||||
@@ -2581,14 +2576,14 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
|
||||
std::string show = show_str;
|
||||
// Check
|
||||
// Remember: "show" must also be the name of a column!
|
||||
if( (show != "delay") && (show != "event_id") && (show != "event_chance")
|
||||
if( (show != "delay") && (show != "action") && (show != "action_chance")
|
||||
&& (show != "move_flag") && (show != "del") && (show != "move") && (show != "wpadd")
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Next arg is: <GUID> <WPNUM> <ARGUMENT>
|
||||
// Next arg is: <PATHID> <WPNUM> <ARGUMENT>
|
||||
char* arg_str = NULL;
|
||||
|
||||
// Did user provide a GUID
|
||||
@@ -2599,39 +2594,33 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
|
||||
uint32 wpGuid = 0;
|
||||
Creature* target = getSelectedCreature();
|
||||
|
||||
if(target)
|
||||
if(!target || target->GetEntry() != VISUAL_WAYPOINT)
|
||||
{
|
||||
sLog.outDebug("DEBUG: HandleWpModifyCommand - User did select an NPC");
|
||||
SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
|
||||
return false;
|
||||
}
|
||||
|
||||
sLog.outDebug("DEBUG: HandleWpModifyCommand - User did select an NPC");
|
||||
// The visual waypoint
|
||||
Creature* wpCreature = NULL;
|
||||
|
||||
wpGuid = target->GetGUIDLow();
|
||||
|
||||
// Did the user select a visual spawnpoint?
|
||||
|
||||
if(wpGuid)
|
||||
wpCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
|
||||
|
||||
// attempt check creature existence by DB data
|
||||
else
|
||||
{
|
||||
|
||||
QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE path_id = '%u'",wpGuid);
|
||||
if(!result)
|
||||
{
|
||||
PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, wpGuid);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// User did select a visual waypoint?
|
||||
// Check the creature
|
||||
if (wpCreature->GetEntry() == VISUAL_WAYPOINT )
|
||||
{
|
||||
QueryResult *result =
|
||||
WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u",
|
||||
wpGuid);
|
||||
WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid);
|
||||
|
||||
if(!result)
|
||||
{
|
||||
sLog.outDebug("DEBUG: HandleWpModifyCommand - No waypoint found - used 'wpguid'");
|
||||
@@ -2659,135 +2648,33 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
|
||||
Field *fields = result->Fetch();
|
||||
pathid = fields[0].GetUInt32();
|
||||
point = fields[1].GetUInt32();
|
||||
}while( result->NextRow() );
|
||||
}
|
||||
while( result->NextRow() );
|
||||
|
||||
// Cleanup memory
|
||||
sLog.outDebug("DEBUG: HandleWpModifyCommand - Cleanup memory");
|
||||
delete result;
|
||||
// We have the waypoint number and the GUID of the "master npc"
|
||||
// Text is enclosed in "<>", all other arguments not
|
||||
|
||||
arg_str = strtok((char*)NULL, " ");
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// User did provide <GUID> <WPNUM>
|
||||
char* guid_str = strtok((char*)NULL, " ");
|
||||
char* point_str = strtok((char*)NULL, " ");
|
||||
|
||||
arg_str = strtok((char*)NULL, " ");
|
||||
|
||||
if( !guid_str )
|
||||
{
|
||||
SendSysMessage(LANG_WAYPOINT_NOGUID);
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !point_str )
|
||||
{
|
||||
SendSysMessage(LANG_WAYPOINT_NOWAYPOINTGIVEN);
|
||||
return false;
|
||||
}
|
||||
if( (show != "del") && (show != "move") )
|
||||
{
|
||||
if( !arg_str )
|
||||
{
|
||||
PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
pathid = atoi((char*)guid_str);
|
||||
PSendSysMessage("|cff33ffffDEBUG: GUID provided: %d|r", pathid);
|
||||
|
||||
point = atoi((char*)point_str);
|
||||
PSendSysMessage("|cff33ffffDEBUG: wpNumber provided: %d|r", point);
|
||||
|
||||
// Now we need the GUID of the visual waypoint
|
||||
// -> "del", "move", "add" command
|
||||
|
||||
QueryResult *result = WorldDatabase.PQuery( "SELECT wpguid FROM waypoint_data WHERE id = '%u' AND point = '%u'", pathid, point);
|
||||
if(result)
|
||||
{
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
wpGuid = fields[0].GetUInt32();
|
||||
}while( result->NextRow() );
|
||||
|
||||
|
||||
// Free memory
|
||||
delete result;
|
||||
}
|
||||
else
|
||||
{
|
||||
PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, pathid, point);
|
||||
// Select waypoint number from database
|
||||
QueryResult *result = WorldDatabase.PQuery( "SELECT position_x,position_y,position_z FROM waypoint_data WHERE point='%d' AND id = '%u'", point, pathid);
|
||||
if(!result)
|
||||
{
|
||||
PSendSysMessage(LANG_WAYPOINT_NOTFOUND, pathid);
|
||||
return true;
|
||||
}
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
float x = fields[0].GetFloat();
|
||||
float y = fields[1].GetFloat();
|
||||
float z = fields[2].GetFloat();
|
||||
// Cleanup memory
|
||||
delete result;
|
||||
|
||||
// Select waypoint number from database
|
||||
// Since we compare float values, we have to deal with
|
||||
// some difficulties.
|
||||
// Here we search for all waypoints that only differ in one from 1 thousand
|
||||
// (0.001) - There is no other way to compare C++ floats with mySQL floats
|
||||
// See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
|
||||
const char* maxDIFF = "0.01";
|
||||
|
||||
result = WorldDatabase.PQuery( "SELECT guid FROM creature WHERE (abs(position_x - %f) <= %s ) and (abs(position_y - %f) <= %s ) and (abs(position_z - %f) <= %s ) and id=%d",
|
||||
x, maxDIFF, y, maxDIFF, z, maxDIFF, VISUAL_WAYPOINT);
|
||||
if(!result)
|
||||
{
|
||||
|
||||
PSendSysMessage(LANG_WAYPOINT_WPCREATNOTFOUND, VISUAL_WAYPOINT);
|
||||
return true;
|
||||
}
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
wpGuid = fields[0].GetUInt32();
|
||||
}while( result->NextRow() );
|
||||
|
||||
|
||||
// Free memory
|
||||
delete result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sLog.outDebug("DEBUG: HandleWpModifyCommand - Parameters parsed - now execute the command");
|
||||
|
||||
// Check for argument
|
||||
if((show != "del") && (show != "move"))
|
||||
{
|
||||
if( arg_str == NULL )
|
||||
if(show != "del" && show != "move" && arg_str == NULL)
|
||||
{
|
||||
PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(show == "del" && target)
|
||||
{
|
||||
PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
|
||||
|
||||
// wpCreature
|
||||
|
||||
Creature* wpCreature = NULL;
|
||||
|
||||
if( wpGuid != 0 )
|
||||
{
|
||||
wpCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
|
||||
|
||||
@@ -92,7 +92,8 @@ void WaypointMovementGenerator<Player>::Reset(Player &unit){}
|
||||
template<>
|
||||
void WaypointMovementGenerator<Creature>::InitTraveller(Creature &unit, const WaypointData &node)
|
||||
{
|
||||
node.run ? unit.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE): unit.AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
|
||||
node.run ? unit.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE):
|
||||
unit.AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
|
||||
|
||||
unit.SetUInt32Value(UNIT_NPC_EMOTESTATE, 0);
|
||||
unit.SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
|
||||
@@ -173,18 +174,12 @@ WaypointMovementGenerator<Creature>::Update(Creature &unit, const uint32 &diff)
|
||||
//Determine waittime
|
||||
if(node.delay)
|
||||
i_nextMoveTime.Reset(node.delay);
|
||||
else
|
||||
i_nextMoveTime.Reset(100); //Prevents some lag
|
||||
|
||||
if(node.event_id && rand()%100 < node.event_chance && !ExecuteScript)
|
||||
{
|
||||
if(node.event_id && rand()%100 < node.event_chance)
|
||||
sWorld.ScriptsStart(sWaypointScripts, node.event_id, &unit, NULL);
|
||||
ExecuteScript = true;
|
||||
}
|
||||
|
||||
MovementInform(unit);
|
||||
unit.UpdateWaypointID(i_currentNode);
|
||||
traveller.Relocation(node.x, node.y, node.z);
|
||||
unit.clearUnitState(UNIT_STAT_MOVING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class TRINITY_DLL_SPEC WaypointMovementGenerator
|
||||
uint32 i_currentNode, path_id;
|
||||
TimeTrackerSmall i_nextMoveTime;
|
||||
WaypointPath *waypoints;
|
||||
bool repeating, custom_path, ExecuteScript, StopedByPlayer;
|
||||
bool repeating, StopedByPlayer;
|
||||
};
|
||||
|
||||
/** FlightPathMovementGenerator generates movement of the player for the paths
|
||||
|
||||
Reference in New Issue
Block a user