*Some code cleanups and crash fixes with Waypoint Movement Generator.
--HG-- branch : trunk
This commit is contained in:
+18
-131
@@ -2183,7 +2183,6 @@ bool ChatHandler::HandleWpAddCommand(const char* args)
|
|||||||
pathid = maxpathid+1;
|
pathid = maxpathid+1;
|
||||||
sLog.outDebug("DEBUG: HandleWpAddCommand - New path started.");
|
sLog.outDebug("DEBUG: HandleWpAddCommand - New path started.");
|
||||||
PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
|
PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2212,7 +2211,7 @@ bool ChatHandler::HandleWpAddCommand(const char* args)
|
|||||||
Player* player = m_session->GetPlayer();
|
Player* player = m_session->GetPlayer();
|
||||||
Map *map = player->GetMap();
|
Map *map = player->GetMap();
|
||||||
|
|
||||||
WorldDatabase.PExecuteLog("INSERT INTO waypoint_data (id,point,position_x,position_y,position_z) VALUES ('%u','%u','%f', '%f', '%f')",
|
WorldDatabase.PExecuteLog("INSERT INTO waypoint_data (id, point, position_x, position_y, position_z) VALUES ('%u','%u','%f', '%f', '%f')",
|
||||||
pathid, point+1, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
|
pathid, point+1, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
|
||||||
|
|
||||||
PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", point,"|r|cff00ff00 created. ");
|
PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", point,"|r|cff00ff00 created. ");
|
||||||
@@ -2222,7 +2221,6 @@ bool ChatHandler::HandleWpAddCommand(const char* args)
|
|||||||
|
|
||||||
bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!*args)
|
if(!*args)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -2230,9 +2228,8 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
|||||||
char* path_number = NULL;
|
char* path_number = NULL;
|
||||||
|
|
||||||
if(*args)
|
if(*args)
|
||||||
{
|
|
||||||
path_number = strtok((char*)args, " ");
|
path_number = strtok((char*)args, " ");
|
||||||
}
|
|
||||||
|
|
||||||
uint32 pathid = 0;
|
uint32 pathid = 0;
|
||||||
uint32 guidlow = 0;
|
uint32 guidlow = 0;
|
||||||
@@ -2248,6 +2245,7 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
|||||||
SetSentErrorMessage(true);
|
SetSentErrorMessage(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(target->GetEntry() == 1)
|
if(target->GetEntry() == 1)
|
||||||
{
|
{
|
||||||
PSendSysMessage("%s%s|r", "|cffff33ff", "You want to load path to a waypoint? Aren't you?");
|
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);
|
pathid = atoi(path_number);
|
||||||
|
|
||||||
if(!pathid)
|
if(!pathid)
|
||||||
{
|
{
|
||||||
PSendSysMessage("%s%s|r", "|cffff33ff", "No vallid path number provided.");
|
PSendSysMessage("%s%s|r", "|cffff33ff", "No vallid path number provided.");
|
||||||
@@ -2263,7 +2262,6 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
guidlow = target->GetGUIDLow();
|
guidlow = target->GetGUIDLow();
|
||||||
|
|
||||||
QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE guid = '%u'",guidlow);
|
QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE guid = '%u'",guidlow);
|
||||||
|
|
||||||
if( result )
|
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);
|
WorldDatabase.PExecute("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE, guidlow);
|
||||||
|
|
||||||
target->LoadPath(pathid);
|
target->LoadPath(pathid);
|
||||||
|
|
||||||
target->SetDefaultMovementType(WAYPOINT_MOTION_TYPE);
|
target->SetDefaultMovementType(WAYPOINT_MOTION_TYPE);
|
||||||
|
|
||||||
target->GetMotionMaster()->Initialize();
|
target->GetMotionMaster()->Initialize();
|
||||||
|
|
||||||
target->Say("Path loaded.",0,0);
|
target->Say("Path loaded.",0,0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -2581,14 +2576,14 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
|
|||||||
std::string show = show_str;
|
std::string show = show_str;
|
||||||
// Check
|
// Check
|
||||||
// Remember: "show" must also be the name of a column!
|
// 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")
|
&& (show != "move_flag") && (show != "del") && (show != "move") && (show != "wpadd")
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next arg is: <GUID> <WPNUM> <ARGUMENT>
|
// Next arg is: <PATHID> <WPNUM> <ARGUMENT>
|
||||||
char* arg_str = NULL;
|
char* arg_str = NULL;
|
||||||
|
|
||||||
// Did user provide a GUID
|
// Did user provide a GUID
|
||||||
@@ -2599,39 +2594,33 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
|
|||||||
uint32 wpGuid = 0;
|
uint32 wpGuid = 0;
|
||||||
Creature* target = getSelectedCreature();
|
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
|
// The visual waypoint
|
||||||
Creature* wpCreature = NULL;
|
Creature* wpCreature = NULL;
|
||||||
|
|
||||||
wpGuid = target->GetGUIDLow();
|
wpGuid = target->GetGUIDLow();
|
||||||
|
|
||||||
// Did the user select a visual spawnpoint?
|
// Did the user select a visual spawnpoint?
|
||||||
|
|
||||||
if(wpGuid)
|
if(wpGuid)
|
||||||
wpCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
|
wpCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
|
||||||
|
|
||||||
// attempt check creature existence by DB data
|
// attempt check creature existence by DB data
|
||||||
else
|
else
|
||||||
{
|
|
||||||
|
|
||||||
QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE path_id = '%u'",wpGuid);
|
|
||||||
if(!result)
|
|
||||||
{
|
{
|
||||||
PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, wpGuid);
|
PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, wpGuid);
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// User did select a visual waypoint?
|
// User did select a visual waypoint?
|
||||||
// Check the creature
|
// Check the creature
|
||||||
if (wpCreature->GetEntry() == VISUAL_WAYPOINT )
|
if (wpCreature->GetEntry() == VISUAL_WAYPOINT )
|
||||||
{
|
{
|
||||||
QueryResult *result =
|
QueryResult *result =
|
||||||
WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u",
|
WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid);
|
||||||
wpGuid);
|
|
||||||
if(!result)
|
if(!result)
|
||||||
{
|
{
|
||||||
sLog.outDebug("DEBUG: HandleWpModifyCommand - No waypoint found - used 'wpguid'");
|
sLog.outDebug("DEBUG: HandleWpModifyCommand - No waypoint found - used 'wpguid'");
|
||||||
@@ -2659,135 +2648,33 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
|
|||||||
Field *fields = result->Fetch();
|
Field *fields = result->Fetch();
|
||||||
pathid = fields[0].GetUInt32();
|
pathid = fields[0].GetUInt32();
|
||||||
point = fields[1].GetUInt32();
|
point = fields[1].GetUInt32();
|
||||||
}while( result->NextRow() );
|
}
|
||||||
|
while( result->NextRow() );
|
||||||
|
|
||||||
// Cleanup memory
|
// Cleanup memory
|
||||||
sLog.outDebug("DEBUG: HandleWpModifyCommand - Cleanup memory");
|
sLog.outDebug("DEBUG: HandleWpModifyCommand - Cleanup memory");
|
||||||
delete result;
|
delete result;
|
||||||
// We have the waypoint number and the GUID of the "master npc"
|
// We have the waypoint number and the GUID of the "master npc"
|
||||||
// Text is enclosed in "<>", all other arguments not
|
// Text is enclosed in "<>", all other arguments not
|
||||||
|
|
||||||
arg_str = strtok((char*)NULL, " ");
|
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");
|
sLog.outDebug("DEBUG: HandleWpModifyCommand - Parameters parsed - now execute the command");
|
||||||
|
|
||||||
// Check for argument
|
// Check for argument
|
||||||
if((show != "del") && (show != "move"))
|
if(show != "del" && show != "move" && arg_str == NULL)
|
||||||
{
|
|
||||||
if( arg_str == NULL )
|
|
||||||
{
|
{
|
||||||
PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str);
|
PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(show == "del" && target)
|
if(show == "del" && target)
|
||||||
{
|
{
|
||||||
PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
|
PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
|
||||||
|
|
||||||
// wpCreature
|
// wpCreature
|
||||||
|
|
||||||
Creature* wpCreature = NULL;
|
Creature* wpCreature = NULL;
|
||||||
|
|
||||||
if( wpGuid != 0 )
|
if( wpGuid != 0 )
|
||||||
{
|
{
|
||||||
wpCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
|
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<>
|
template<>
|
||||||
void WaypointMovementGenerator<Creature>::InitTraveller(Creature &unit, const WaypointData &node)
|
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_NPC_EMOTESTATE, 0);
|
||||||
unit.SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
|
unit.SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
|
||||||
@@ -173,18 +174,12 @@ WaypointMovementGenerator<Creature>::Update(Creature &unit, const uint32 &diff)
|
|||||||
//Determine waittime
|
//Determine waittime
|
||||||
if(node.delay)
|
if(node.delay)
|
||||||
i_nextMoveTime.Reset(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);
|
sWorld.ScriptsStart(sWaypointScripts, node.event_id, &unit, NULL);
|
||||||
ExecuteScript = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
MovementInform(unit);
|
MovementInform(unit);
|
||||||
unit.UpdateWaypointID(i_currentNode);
|
unit.UpdateWaypointID(i_currentNode);
|
||||||
traveller.Relocation(node.x, node.y, node.z);
|
|
||||||
unit.clearUnitState(UNIT_STAT_MOVING);
|
unit.clearUnitState(UNIT_STAT_MOVING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class TRINITY_DLL_SPEC WaypointMovementGenerator
|
|||||||
uint32 i_currentNode, path_id;
|
uint32 i_currentNode, path_id;
|
||||||
TimeTrackerSmall i_nextMoveTime;
|
TimeTrackerSmall i_nextMoveTime;
|
||||||
WaypointPath *waypoints;
|
WaypointPath *waypoints;
|
||||||
bool repeating, custom_path, ExecuteScript, StopedByPlayer;
|
bool repeating, StopedByPlayer;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** FlightPathMovementGenerator generates movement of the player for the paths
|
/** FlightPathMovementGenerator generates movement of the player for the paths
|
||||||
|
|||||||
Reference in New Issue
Block a user