Implement taxi/transport event scripts support. Author: Vladimir

--HG--
branch : trunk
This commit is contained in:
Machiavelli
2010-06-23 01:59:32 +02:00
parent ffaffe3fd7
commit 968c27f55f
8 changed files with 72 additions and 28 deletions

View File

@@ -1716,8 +1716,8 @@ struct TaxiPathNodeEntry
float z; // 6 m_LocZ
uint32 actionFlag; // 7 m_flags
uint32 delay; // 8 m_delay
// 9 m_arrivalEventID
// 10 m_departureEventID
uint32 arrivalEventID; // 9 m_arrivalEventID
uint32 departureEventID; // 10 m_departureEventID
};
struct TotemCategoryEntry

View File

@@ -110,7 +110,7 @@ const char TalentEntryfmt[]="niiiiiiiixxxxixxixxxxxx";
const char TalentTabEntryfmt[]="nxxxxxxxxxxxxxxxxxxxiiix";
const char TaxiNodesEntryfmt[]="nifffssssssssssssssssxii";
const char TaxiPathEntryfmt[]="niii";
const char TaxiPathNodeEntryfmt[]="diiifffiixx";
const char TaxiPathNodeEntryfmt[]="diiifffiiii";
const char TotemCategoryEntryfmt[]="nxxxxxxxxxxxxxxxxxii";
const char VehicleEntryfmt[]="niffffiiiiiiiifffffffffffffffssssfifiixx";
const char VehicleSeatEntryfmt[]="niiffffffffffiiiiiifffffffiiifffiiiiiiiffiiiiixxxxxxxxxxxx";

View File

@@ -500,6 +500,16 @@ struct GameObjectInfo
default: return 0;
}
}
uint32 GetEventScriptId() const
{
switch(type)
{
case GAMEOBJECT_TYPE_GOOBER: return goober.eventId;
case GAMEOBJECT_TYPE_CHEST: return chest.eventId;
case GAMEOBJECT_TYPE_CAMERA: return camera.eventID;
default: return 0;
}
}
};
class OPvPCapturePoint;

View File

@@ -310,7 +310,8 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
if (keyFrames[keyFrames.size() - 1].node->mapid != keyFrames[0].node->mapid)
teleport = true;
WayPoint pos(keyFrames[0].node->mapid, keyFrames[0].node->x, keyFrames[0].node->y, keyFrames[0].node->z, teleport, 0);
WayPoint pos(keyFrames[0].node->mapid, keyFrames[0].node->x, keyFrames[0].node->y, keyFrames[0].node->z, teleport, 0,
keyFrames[0].node->arrivalEventID, keyFrames[0].node->departureEventID);
m_WayPoints[0] = pos;
t += keyFrames[0].node->delay * 1000;
@@ -390,8 +391,8 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
cM = keyFrames[i + 1].node->mapid;
}
WayPoint pos(keyFrames[i + 1].node->mapid, keyFrames[i + 1].node->x, keyFrames[i + 1].node->y, keyFrames[i + 1].node->z, teleport, 0);
WayPoint pos(keyFrames[i + 1].node->mapid, keyFrames[i + 1].node->x, keyFrames[i + 1].node->y, keyFrames[i + 1].node->z, teleport,
0, keyFrames[i + 1].node->arrivalEventID, keyFrames[i + 1].node->departureEventID);
// sLog.outString("T: %d, x: %f, y: %f, z: %f, t:%d", t, pos.x, pos.y, pos.z, teleport);
/*
if (keyFrames[i+1].delay > 5)
@@ -494,9 +495,13 @@ void Transport::Update(uint32 /*p_time*/)
m_timer = getMSTime() % m_period;
while (((m_timer - m_curr->first) % m_pathTime) > ((m_next->first - m_curr->first) % m_pathTime))
{
DoEventIfAny(*m_curr, true);
m_curr = GetNextWayPoint();
m_next = GetNextWayPoint();
DoEventIfAny(*m_curr,false);
// first check help in case client-server transport coordinates de-synchronization
if (m_curr->second.mapid != GetMapId() || m_curr->second.teleport)
{
@@ -582,3 +587,11 @@ void Transport::UpdateForMap(Map const* targetMap)
}
}
void Transport::DoEventIfAny(WayPointMap::value_type const& node, bool departure)
{
if (uint32 eventid = departure ? node.second.departureEventID : node.second.arrivalEventID)
{
sLog.outDebug("Taxi %s event %u of node %u of %s path", departure ? "departure" : "arrival", eventid, node.first, GetName());
GetMap()->ScriptsStart(sEventScripts, eventid, this, this);
}
}

View File

@@ -46,14 +46,20 @@ class Transport : public GameObject
struct WayPoint
{
WayPoint() : mapid(0), x(0), y(0), z(0), teleport(false), id(0) {}
WayPoint(uint32 _mapid, float _x, float _y, float _z, bool _teleport, uint32 _id) :
mapid(_mapid), x(_x), y(_y), z(_z), teleport(_teleport), id(_id) {}
WayPoint(uint32 _mapid, float _x, float _y, float _z, bool _teleport, uint32 _id = 0,
uint32 _arrivalEventID = 0, uint32 _departureEventID = 0)
: mapid(_mapid), x(_x), y(_y), z(_z), teleport(_teleport), id(_id),
arrivalEventID(_arrivalEventID), departureEventID(_departureEventID)
{
}
uint32 mapid;
float x;
float y;
float z;
bool teleport;
uint32 id;
uint32 arrivalEventID;
uint32 departureEventID;
};
typedef std::map<uint32, WayPoint> WayPointMap;
@@ -73,6 +79,7 @@ class Transport : public GameObject
private:
void TeleportTransport(uint32 newMapid, float x, float y, float z);
void UpdateForMap(Map const* map);
void DoEventIfAny(WayPointMap::value_type const& node, bool departure);
WayPointMap::const_iterator GetNextWayPoint();
};
#endif

View File

@@ -4813,26 +4813,9 @@ void ObjectMgr::LoadEventScripts()
// Load all possible script entries from gameobjects
for (uint32 i = 1; i < sGOStorage.MaxEntry; ++i)
{
GameObjectInfo const * goInfo = sGOStorage.LookupEntry<GameObjectInfo>(i);
if (goInfo)
{
switch(goInfo->type)
{
case GAMEOBJECT_TYPE_GOOBER:
if (goInfo->goober.eventId)
evt_scripts.insert(goInfo->goober.eventId);
break;
case GAMEOBJECT_TYPE_CHEST:
if (goInfo->chest.eventId)
evt_scripts.insert(goInfo->chest.eventId);
break;
case GAMEOBJECT_TYPE_CAMERA:
if (goInfo->camera.eventID)
evt_scripts.insert(goInfo->camera.eventID);
default:
break;
}
}
if (GameObjectInfo const * goInfo = sGOStorage.LookupEntry<GameObjectInfo>(i))
if (uint32 eventId = goInfo->GetEventScriptId())
evt_scripts.insert(eventId);
}
// Load all possible script entries from spells
for (uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
@@ -4851,6 +4834,20 @@ void ObjectMgr::LoadEventScripts()
}
}
for(size_t path_idx = 0; path_idx < sTaxiPathNodesByPath.size(); ++path_idx)
{
for(size_t node_idx = 0; node_idx < sTaxiPathNodesByPath[path_idx].size(); ++node_idx)
{
TaxiPathNodeEntry const& node = sTaxiPathNodesByPath[path_idx][node_idx];
if (node.arrivalEventID)
evt_scripts.insert(node.arrivalEventID);
if (node.departureEventID)
evt_scripts.insert(node.departureEventID);
}
}
// Then check if all scripts are in above list of possible script entries
for (ScriptMapMap::const_iterator itr = sEventScripts.begin(); itr != sEventScripts.end(); ++itr)
{

View File

@@ -278,10 +278,14 @@ bool FlightPathMovementGenerator::Update(Player &player, const uint32 &diff)
i_destinationHolder.ResetUpdate(FLIGHT_TRAVEL_UPDATE);
if (i_destinationHolder.HasArrived())
{
DoEventIfAny(player,(*i_path)[i_currentNode], false);
uint32 curMap = (*i_path)[i_currentNode].mapid;
++i_currentNode;
if (MovementInProgress())
{
DoEventIfAny(player,(*i_path)[i_currentNode], true);
DEBUG_LOG("loading node %u for player %s", i_currentNode, player.GetName());
if ((*i_path)[i_currentNode].mapid == curMap)
{
@@ -351,6 +355,17 @@ void FlightPathMovementGenerator::PreloadEndGrid()
sLog.outDetail("Unable to determine map to preload flightmaster grid");
}
void FlightPathMovementGenerator::DoEventIfAny(Player& player, TaxiPathNodeEntry const& node, bool departure)
{
if (uint32 eventid = departure ? node.departureEventID : node.arrivalEventID)
{
sLog.outDebug("Taxi %s event %u of node %u of path %u for player %s", departure ? "departure" : "arrival", eventid, node.index, node.path, player.GetName());
player.GetMap()->ScriptsStart(sEventScripts, eventid, &player, &player);
}
}
//
// Unique1's ASTAR Pathfinding Code... For future use & reference...
//

View File

@@ -115,6 +115,8 @@ public PathMovementBase<Player,TaxiPathNodeList const*>
bool HasArrived() const { return (i_currentNode >= i_path->size()); }
void SetCurrentNodeAfterTeleport();
void SkipCurrentNode() { ++i_currentNode; }
void DoEventIfAny(Player& player, TaxiPathNodeEntry const& node, bool departure);
bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Player,TaxiPathNodeList const*>::GetDestination(x,y,z); }
void PreloadEndGrid();