[9824] Use in taxi flight movegen original taxipath data.

This commit is contained in:
VladimirMangos 2010-05-02 04:32:52 +04:00
parent c52e9c5d27
commit 57dcc84940
15 changed files with 149 additions and 146 deletions

View file

@ -550,7 +550,7 @@ void LoadDBCStores(const std::string& dataPath)
// fill data (pointers to sTaxiPathNodeStore elements
for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
sTaxiPathNodesByPath[entry->path][entry->index] = entry;
sTaxiPathNodesByPath[entry->path].set(entry->index, entry);
// Initialize global taxinodes mask
// include existed nodes that have at least single not spell base (scripted) path

View file

@ -19,7 +19,9 @@
#ifndef MANGOS_DBCSTRUCTURE_H
#define MANGOS_DBCSTRUCTURE_H
#include "Common.h"
#include "DBCEnums.h"
#include "Path.h"
#include "Platform/Define.h"
#include <map>
@ -1846,7 +1848,17 @@ struct TaxiPathBySourceAndDestination
typedef std::map<uint32,TaxiPathBySourceAndDestination> TaxiPathSetForSource;
typedef std::map<uint32,TaxiPathSetForSource> TaxiPathSetBySource;
typedef std::vector<TaxiPathNodeEntry const*> TaxiPathNodeList;
struct TaxiPathNodePtr
{
TaxiPathNodePtr() : i_ptr(NULL) {}
TaxiPathNodePtr(TaxiPathNodeEntry const* ptr) : i_ptr(ptr) {}
TaxiPathNodeEntry const* i_ptr;
operator TaxiPathNodeEntry const& () const { return *i_ptr; }
};
typedef Path<TaxiPathNodePtr,TaxiPathNodeEntry const> TaxiPathNodeList;
typedef std::vector<TaxiPathNodeList> TaxiPathNodesByPath;
#define TaxiMaskSize 12

View file

@ -359,12 +359,20 @@ void
MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode)
{
if(i_owner->GetTypeId()==TYPEID_PLAYER)
{
if(path < sTaxiPathNodesByPath.size())
{
DEBUG_LOG("%s taxi to (Path %u node %u)", i_owner->GetObjectGuid().GetString().c_str(), path, pathnode);
FlightPathMovementGenerator* mgen = new FlightPathMovementGenerator(path,pathnode);
FlightPathMovementGenerator* mgen = new FlightPathMovementGenerator(sTaxiPathNodesByPath[path],pathnode);
Mutate(mgen);
}
else
{
sLog.outError("%s attempt taxi to (not existed Path %u node %u)",
i_owner->GetObjectGuid().GetString().c_str(), path, pathnode );
}
}
else
{
sLog.outError("%s attempt taxi to (Path %u node %u)",
i_owner->GetObjectGuid().GetString().c_str(), path, pathnode );

View file

@ -370,7 +370,7 @@ void Object::BuildMovementUpdate(ByteBuffer * data, uint16 updateFlags) const
}
}
Path &path = fmg->GetPath();
TaxiPathNodeList const& path = fmg->GetPath();
float x, y, z;
player->GetPosition(x, y, z);
@ -388,21 +388,21 @@ void Object::BuildMovementUpdate(ByteBuffer * data, uint16 updateFlags) const
*data << uint32(0); // added in 3.1
uint32 poscount = uint32(path.Size());
uint32 poscount = uint32(path.size());
*data << uint32(poscount); // points count
for(uint32 i = 0; i < poscount; ++i)
{
*data << float(path.GetNodes()[i].x);
*data << float(path.GetNodes()[i].y);
*data << float(path.GetNodes()[i].z);
*data << float(path[i].x);
*data << float(path[i].y);
*data << float(path[i].z);
}
*data << uint8(0); // splineMode
*data << float(path.GetNodes()[poscount-1].x);
*data << float(path.GetNodes()[poscount-1].y);
*data << float(path.GetNodes()[poscount-1].z);
*data << float(path[poscount-1].x);
*data << float(path[poscount-1].y);
*data << float(path[poscount-1].z);
}
}
else

View file

@ -5219,26 +5219,6 @@ uint32 ObjectMgr::GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_al
return mount_id;
}
void ObjectMgr::GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds)
{
if(path >= sTaxiPathNodesByPath.size())
return;
TaxiPathNodeList& nodeList = sTaxiPathNodesByPath[path];
pathnodes.Resize(nodeList.size());
mapIds.resize(nodeList.size());
for(size_t i = 0; i < nodeList.size(); ++i)
{
pathnodes[ i ].x = nodeList[i]->x;
pathnodes[ i ].y = nodeList[i]->y;
pathnodes[ i ].z = nodeList[i]->z;
mapIds[i] = nodeList[i]->mapid;
}
}
void ObjectMgr::LoadGraveyardZones()
{
mGraveYardMap.clear(); // need for reload case

View file

@ -27,7 +27,6 @@
#include "GameObject.h"
#include "Corpse.h"
#include "QuestDef.h"
#include "Path.h"
#include "ItemPrototype.h"
#include "NPCHandler.h"
#include "Database/DatabaseEnv.h"
@ -54,8 +53,6 @@ extern SQLStorage sInstanceTemplate;
class Group;
class Guild;
class ArenaTeam;
class Path;
class TransportPath;
class Item;
struct GameTele
@ -499,7 +496,6 @@ class ObjectMgr
uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid, uint32 team );
void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false);
void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
Quest const* GetQuestTemplate(uint32 quest_id) const
{

View file

@ -22,64 +22,63 @@
#include "Common.h"
#include <vector>
class Path
{
public:
struct PathNode
struct SimplePathNode
{
float x,y,z;
};
void SetLength(const unsigned int sz)
template<typename PathElem, typename PathNode = PathElem>
class Path
{
i_nodes.resize( sz );
}
public:
size_t size() const { return i_nodes.size(); }
bool empty() const { return i_nodes.empty(); }
void resize(unsigned int sz) { i_nodes.resize(sz); }
void clear() { i_nodes.clear(); }
void erase(uint32 idx) { i_nodes.erase(i_nodes.begin()+idx); }
unsigned int Size() const { return i_nodes.size(); }
bool Empty() const { return i_nodes.empty(); }
void Resize(unsigned int sz) { i_nodes.resize(sz); }
void Clear(void) { i_nodes.clear(); }
PathNode const* GetNodes(uint32 start = 0) const { return &i_nodes[start]; }
float GetTotalLength() const { return GetTotalLength(0,Size()); }
float GetTotalLength(uint32 start, uint32 end) const
{
float len = 0, xd, yd, zd;
float len = 0.0f;
for(unsigned int idx=start+1; idx < end; ++idx)
{
xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x;
yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y;
zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].z;
PathNode const& node = i_nodes[idx];
PathNode const& prev = i_nodes[idx-1];
float xd = node.x - prev.x;
float yd = node.y - prev.y;
float zd = node.z - prev.z;
len += sqrtf( xd*xd + yd*yd + zd*zd );
}
return len;
}
float GetPassedLength(uint32 curnode, float x, float y, float z)
float GetTotalLength() const { return GetTotalLength(0,size()); }
float GetPassedLength(uint32 curnode, float x, float y, float z) const
{
float len = 0, xd, yd, zd;
for(unsigned int idx=1; idx < curnode; ++idx)
{
xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x;
yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y;
zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].z;
len += sqrtf( xd*xd + yd*yd + zd*zd );
}
float len = GetTotalLength(0,curnode);
if (curnode > 0)
{
xd = x - i_nodes[curnode-1].x;
yd = y - i_nodes[curnode-1].y;
zd = z - i_nodes[curnode-1].z;
PathNode const& node = i_nodes[curnode-1];
float xd = x - node.x;
float yd = y - node.y;
float zd = z - node.z;
len += sqrtf( xd*xd + yd*yd + zd*zd );
}
return len;
}
PathNode& operator[](const unsigned int idx) { return i_nodes[idx]; }
const PathNode& operator()(const unsigned int idx) const { return i_nodes[idx]; }
PathNode& operator[](size_t idx) { return i_nodes[idx]; }
PathNode const& operator[](size_t idx) const { return i_nodes[idx]; }
void set(size_t idx, PathElem elem) { i_nodes[idx] = elem; }
protected:
std::vector<PathNode> i_nodes;
std::vector<PathElem> i_nodes;
};
typedef Path<SimplePathNode> SimplePath;
#endif

View file

@ -18209,30 +18209,30 @@ void Player::ContinueTaxiFlight()
float distPrev = MAP_SIZE*MAP_SIZE;
float distNext =
(nodeList[0]->x-GetPositionX())*(nodeList[0]->x-GetPositionX())+
(nodeList[0]->y-GetPositionY())*(nodeList[0]->y-GetPositionY())+
(nodeList[0]->z-GetPositionZ())*(nodeList[0]->z-GetPositionZ());
(nodeList[0].x-GetPositionX())*(nodeList[0].x-GetPositionX())+
(nodeList[0].y-GetPositionY())*(nodeList[0].y-GetPositionY())+
(nodeList[0].z-GetPositionZ())*(nodeList[0].z-GetPositionZ());
for(uint32 i = 1; i < nodeList.size(); ++i)
{
TaxiPathNodeEntry const* node = nodeList[i];
TaxiPathNodeEntry const* prevNode = nodeList[i-1];
TaxiPathNodeEntry const& node = nodeList[i];
TaxiPathNodeEntry const& prevNode = nodeList[i-1];
// skip nodes at another map
if (node->mapid != GetMapId())
if (node.mapid != GetMapId())
continue;
distPrev = distNext;
distNext =
(node->x-GetPositionX())*(node->x-GetPositionX())+
(node->y-GetPositionY())*(node->y-GetPositionY())+
(node->z-GetPositionZ())*(node->z-GetPositionZ());
(node.x-GetPositionX())*(node.x-GetPositionX())+
(node.y-GetPositionY())*(node.y-GetPositionY())+
(node.z-GetPositionZ())*(node.z-GetPositionZ());
float distNodes =
(node->x-prevNode->x)*(node->x-prevNode->x)+
(node->y-prevNode->y)*(node->y-prevNode->y)+
(node->z-prevNode->z)*(node->z-prevNode->z);
(node.x-prevNode.x)*(node.x-prevNode.x)+
(node.y-prevNode.y)*(node.y-prevNode.y)+
(node.z-prevNode.z)*(node.z-prevNode.z);
if (distNext + distPrev < distNodes)
{

View file

@ -215,7 +215,7 @@ void WorldSession::HandleMoveSplineDoneOpcode(WorldPacket& recv_data)
flight->Interrupt(*GetPlayer()); // will reset at map landing
flight->SetCurrentNodeAfterTeleport();
Path::PathNode const& node = flight->GetPath()[flight->GetCurrentNode()];
TaxiPathNodeEntry const& node = flight->GetPath()[flight->GetCurrentNode()];
flight->SkipCurrentNode();
GetPlayer()->TeleportTo(curDestNode->map_id,node.x,node.y,node.z,GetPlayer()->GetOrientation());

View file

@ -217,10 +217,10 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
{
if (mapChange == 0)
{
TaxiPathNodeEntry const* node_i = path[i];
if (node_i->mapid == path[i+1]->mapid)
TaxiPathNodeEntry const& node_i = path[i];
if (node_i.mapid == path[i+1].mapid)
{
keyFrame k(node_i->x, node_i->y, node_i->z, node_i->mapid, node_i->actionFlag, node_i->delay);
keyFrame k(node_i.x, node_i.y, node_i.z, node_i.mapid, node_i.actionFlag, node_i.delay);
keyFrames.push_back(k);
mapids.insert(k.mapid);
}

View file

@ -400,27 +400,6 @@ void Unit::SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, SplineTy
SendMessageToSet( &data, true );
}
void Unit::SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, SplineFlags flags)
{
uint32 traveltime = uint32(path.GetTotalLength(start, end) * 32);
uint32 pathSize = end - start;
WorldPacket data( SMSG_MONSTER_MOVE, (GetPackGUID().size()+1+4+4+4+4+1+4+4+4+pathSize*4*3) );
data << GetPackGUID();
data << uint8(0);
data << GetPositionX();
data << GetPositionY();
data << GetPositionZ();
data << uint32(getMSTime());
data << uint8(SPLINETYPE_NORMAL);
data << uint32(flags);
data << uint32(traveltime);
data << uint32(pathSize);
data.append((char*)path.GetNodes(start), pathSize * 4 * 3);
SendMessageToSet(&data, true);
}
void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime, Player* player)
{
if (!transitTime)

View file

@ -32,6 +32,8 @@
#include "Utilities/EventProcessor.h"
#include "MotionMaster.h"
#include "DBCStructure.h"
#include "Path.h"
#include "WorldPacket.h"
#include <list>
enum SpellInterruptFlags
@ -297,7 +299,6 @@ class DynamicObject;
class GameObject;
class Item;
class Pet;
class Path;
class PetAura;
class Totem;
@ -1388,9 +1389,11 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
// recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens
// if used additional args in ... part then floats must explicitly casted to double
void SendMonsterMove(float x, float y, float z, SplineType type, SplineFlags flags, uint32 Time, Player* player = NULL, ...);
void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, SplineFlags flags);
void SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime = 0, Player* player = NULL);
template<typename PathElem, typename PathNode>
void SendMonsterMoveByPath(Path<PathElem,PathNode> const& path, uint32 start, uint32 end, SplineFlags flags);
void SendHighestThreatUpdate(HostileReference* pHostileReference);
void SendThreatClear();
void SendThreatRemove(HostileReference* pHostileReference);
@ -1966,4 +1969,34 @@ bool Unit::CheckAllControlledUnits(Func const& func, bool withTotems, bool withG
return false;
}
template<typename Elem, typename Node>
inline void Unit::SendMonsterMoveByPath(Path<Elem,Node> const& path, uint32 start, uint32 end, SplineFlags flags)
{
uint32 traveltime = uint32(path.GetTotalLength(start, end) * 32);
uint32 pathSize = end - start;
WorldPacket data( SMSG_MONSTER_MOVE, (GetPackGUID().size()+1+4+4+4+4+1+4+4+4+pathSize*4*3) );
data << GetPackGUID();
data << uint8(0);
data << GetPositionX();
data << GetPositionY();
data << GetPositionZ();
data << uint32(getMSTime());
data << uint8(SPLINETYPE_NORMAL);
data << uint32(flags);
data << uint32(traveltime);
data << uint32(pathSize);
for(uint32 i = start; i < end; ++i)
{
data << float(path[i].x);
data << float(path[i].y);
data << float(path[i].z);
}
SendMessageToSet(&data, true);
}
#endif

View file

@ -280,29 +280,24 @@ bool WaypointMovementGenerator<Creature>::GetResetPosition( Creature&, float& x,
}
//----------------------------------------------------//
void FlightPathMovementGenerator::LoadPath(Player &)
{
sObjectMgr.GetTaxiPathNodes(i_pathId, i_path,i_mapIds);
}
uint32 FlightPathMovementGenerator::GetPathAtMapEnd() const
{
if(i_currentNode >= i_mapIds.size())
return i_mapIds.size();
if (i_currentNode >= i_path->size())
return i_path->size();
uint32 curMapId = i_mapIds[i_currentNode];
for(uint32 i = i_currentNode; i < i_mapIds.size(); ++i)
uint32 curMapId = (*i_path)[i_currentNode].mapid;
for(uint32 i = i_currentNode; i < i_path->size(); ++i)
{
if(i_mapIds[i] != curMapId)
if ((*i_path)[i].mapid != curMapId)
return i;
}
return i_mapIds.size();
return i_path->size();
}
void FlightPathMovementGenerator::Initialize(Player &player)
{
LoadPath(player);
Reset(player);
}
@ -343,7 +338,7 @@ void FlightPathMovementGenerator::Reset(Player & player)
player.SetFlag(UNIT_FIELD_FLAGS,UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT);
Traveller<Player> traveller(player);
// do not send movement, it was sent already
i_destinationHolder.SetDestination(traveller, i_path[i_currentNode].x, i_path[i_currentNode].y, i_path[i_currentNode].z, false);
i_destinationHolder.SetDestination(traveller, (*i_path)[i_currentNode].x, (*i_path)[i_currentNode].y, (*i_path)[i_currentNode].z, false);
player.SendMonsterMoveByPath(GetPath(),GetCurrentNode(),GetPathAtMapEnd(), SplineFlags(SPLINEFLAG_WALKMODE|SPLINEFLAG_FLYING));
}
@ -361,15 +356,15 @@ bool FlightPathMovementGenerator::Update(Player &player, const uint32 &diff)
i_destinationHolder.ResetUpdate(FLIGHT_TRAVEL_UPDATE);
if (i_destinationHolder.HasArrived())
{
uint32 curMap = i_mapIds[i_currentNode];
uint32 curMap = (*i_path)[i_currentNode].mapid;
++i_currentNode;
if (MovementInProgress())
{
DEBUG_LOG("loading node %u for player %s", i_currentNode, player.GetName());
if(i_mapIds[i_currentNode]==curMap)
if ((*i_path)[i_currentNode].mapid == curMap)
{
// do not send movement, it was sent already
i_destinationHolder.SetDestination(traveller, i_path[i_currentNode].x, i_path[i_currentNode].y, i_path[i_currentNode].z, false);
i_destinationHolder.SetDestination(traveller, (*i_path)[i_currentNode].x, (*i_path)[i_currentNode].y, (*i_path)[i_currentNode].z, false);
}
return true;
}
@ -388,13 +383,14 @@ bool FlightPathMovementGenerator::Update(Player &player, const uint32 &diff)
void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport()
{
if(i_mapIds.empty())
if (i_path->empty())
return;
uint32 map0 = i_mapIds[0];
for (size_t i = 1; i < i_mapIds.size(); ++i)
uint32 map0 = (*i_path)[0].mapid;
for (size_t i = 1; i < i_path->size(); ++i)
{
if(i_mapIds[i]!=map0)
if ((*i_path)[i].mapid != map0)
{
i_currentNode = i;
return;

View file

@ -39,14 +39,14 @@
#define FLIGHT_TRAVEL_UPDATE 100
#define STOP_TIME_FOR_PLAYER 3 * 60 * 1000 // 3 Minutes
template<class T, class P = Path>
template<class T, class P>
class MANGOS_DLL_SPEC PathMovementBase
{
public:
PathMovementBase() : i_currentNode(0) {}
virtual ~PathMovementBase() {};
bool MovementInProgress(void) const { return i_currentNode < i_path.Size(); }
bool MovementInProgress(void) const { return i_currentNode < i_path->size(); }
// template pattern, not defined .. override required
void LoadPath(T &);
@ -110,12 +110,14 @@ public PathMovementBase<Creature, WaypointPath const*>
*/
class MANGOS_DLL_SPEC FlightPathMovementGenerator
: public MovementGeneratorMedium< Player, FlightPathMovementGenerator >,
public PathMovementBase<Player>
public PathMovementBase<Player,TaxiPathNodeList const*>
{
uint32 i_pathId;
std::vector<uint32> i_mapIds;
public:
explicit FlightPathMovementGenerator(uint32 id, uint32 startNode = 0) : i_pathId(id) { i_currentNode = startNode; }
explicit FlightPathMovementGenerator(TaxiPathNodeList const& pathnodes, uint32 startNode = 0)
{
i_path = &pathnodes;
i_currentNode = startNode;
}
void Initialize(Player &);
void Finalize(Player &);
void Interrupt(Player &);
@ -123,15 +125,13 @@ public PathMovementBase<Player>
bool Update(Player &, const uint32 &);
MovementGeneratorType GetMovementGeneratorType() const { return FLIGHT_MOTION_TYPE; }
void LoadPath(Player &);
Path& GetPath() { return i_path; }
TaxiPathNodeList const& GetPath() { return *i_path; }
uint32 GetPathAtMapEnd() const;
bool HasArrived() const { return (i_currentNode >= i_path.Size()); }
bool HasArrived() const { return (i_currentNode >= i_path->size()); }
void SetCurrentNodeAfterTeleport();
void SkipCurrentNode() { ++i_currentNode; }
// allow use for overwrite empty implementation
bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Player>::GetDestination(x,y,z); }
bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Player,TaxiPathNodeList const*>::GetDestination(x,y,z); }
};
#endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9823"
#define REVISION_NR "9824"
#endif // __REVISION_NR_H__