[9891] Implement *_scripts for creature_movement

New field script_id in creature_movement can be filled for each waypoint point and run the corresponding script from creature_movement_scripts.
Script_id can be any value and several points/creatures can share the same script (with limits of course, such as script depending on location and other factors).

DB projects are advised to move current text, spells and emotes data in creature_movement fields as these fields are strictly no longer needed and may be fully removed in the future.

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-05-14 12:15:50 +02:00
parent 5a72466935
commit 312a076491
12 changed files with 110 additions and 9 deletions

View file

@ -85,8 +85,13 @@ void WaypointManager::Load()
// 0 1 2 3 4 5
result = WorldDatabase.Query("SELECT position_x, position_y, position_z, orientation, model1, model2,"
// 6 7 8 9 10 11 12 13 14 15
"waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, id, point FROM creature_movement");
// 6 7 8 9 10 11 12 13 14 15 16
"waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, id, point, script_id FROM creature_movement");
std::set<uint32> movementScriptSet;
for(ScriptMapMap::const_iterator itr = sCreatureMovementScripts.begin(); itr != sCreatureMovementScripts.end(); ++itr)
movementScriptSet.insert(itr->first);
barGoLink bar( (int)result->GetRowCount() );
do
@ -111,6 +116,7 @@ void WaypointManager::Load()
node.z = fields[2].GetFloat();
node.orientation = fields[3].GetFloat();
node.delay = fields[6].GetUInt32();
node.script_id = fields[16].GetUInt32();
// prevent using invalid coordinates
if(!MaNGOS::IsValidMapCoord(node.x, node.y, node.z, node.orientation))
@ -132,6 +138,20 @@ void WaypointManager::Load()
}
WorldDatabase.PExecute("UPDATE creature_movement SET position_x = '%f', position_y = '%f', position_z = '%f' WHERE id = '%u' AND point = '%u'", node.x, node.y, node.z, id, point);
}
if (node.script_id)
{
if (sCreatureMovementScripts.find(node.script_id) == sCreatureMovementScripts.end())
{
sLog.outErrorDb("Table creature_movement for id %u, point %u have script_id %u that does not exist in `creature_movement_scripts`, ignoring", id, point, node.script_id);
continue;
}
movementScriptSet.erase(node.script_id);
}
// WaypointBehavior can be dropped in time. Script_id added may 2010 and can handle all the below behavior.
WaypointBehavior be;
be.model1 = fields[4].GetUInt32();
be.model2 = fields[5].GetUInt32();
@ -173,6 +193,12 @@ void WaypointManager::Load()
} while( result->NextRow() );
delete result;
if (!movementScriptSet.empty())
{
for(std::set<uint32>::const_iterator itr = movementScriptSet.begin(); itr != movementScriptSet.end(); ++itr)
sLog.outErrorDb("Table `creature_movement_scripts` contain unused script, id %u.", *itr);
}
sLog.outString();
sLog.outString( ">> Waypoints and behaviors loaded" );
sLog.outString();
@ -233,7 +259,7 @@ void WaypointManager::_addNode(uint32 id, uint32 point, float x, float y, float
WaypointPathMap::iterator itr = m_pathMap.find(id);
if(itr == m_pathMap.end())
itr = m_pathMap.insert(WaypointPathMap::value_type(id, WaypointPath())).first;
itr->second.insert(itr->second.begin() + (point - 1), WaypointNode(x, y, z, o, delay, NULL));
itr->second.insert(itr->second.begin() + (point - 1), WaypointNode(x, y, z, o, delay, 0, NULL));
}
uint32 WaypointManager::GetLastPoint(uint32 id, uint32 default_notfound)