Permalink
Browse files

[for develop purposes] Transport system rewrite (including NPC on tra…

…nsport) by MaxXx2021 and lanc.
  • Loading branch information...
1 parent 797cd02 commit 662794a6bb0e8ee32e2e73de75e1108ea896253b @PSZ PSZ committed Sep 20, 2011
@@ -0,0 +1,3 @@
+-- npc on transport use transMap column (hack)
+ALTER TABLE creature
+ ADD COLUMN transMap mediumint(10) NOT NULL DEFAULT 0 AFTER orientation;
View
@@ -41,7 +41,9 @@
#include "MapPersistentStateMgr.h"
#include "BattleGroundMgr.h"
#include "Spell.h"
+#include "Transports.h"
#include "Util.h"
+#include "Unit.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
@@ -182,6 +184,9 @@ Creature::~Creature()
{
CleanupsBeforeDelete();
+ if (GetTransport())
+ GetTransport()->RemovePassenger(this);
+
m_vendorItemCounts.clear();
delete i_AI;
@@ -1072,6 +1077,8 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
CreatureData& data = sObjectMgr.NewOrExistCreatureData(GetGUIDLow());
uint32 displayId = GetNativeDisplayId();
+ uint32 transportMap = 0;
+ bool IsTransport = false;
// check if it's a custom model and if not, use 0 for displayId
CreatureInfo const *cinfo = GetCreatureInfo();
@@ -1090,25 +1097,34 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
displayId = 0;
}
+ if (GetTransport())
+ {
+ IsTransport = true;
+ uint32 MapId = GetTransport()->GetGOInfo()->moTransport.mapID;
+ if (MapId)
+ transportMap = MapId;
+ }
+
// data->guid = guid don't must be update at save
data.id = GetEntry();
data.mapid = mapid;
data.phaseMask = phaseMask;
data.modelid_override = displayId;
data.equipmentId = GetEquipmentId();
- data.posX = GetPositionX();
- data.posY = GetPositionY();
- data.posZ = GetPositionZ();
- data.orientation = GetOrientation();
+ data.posX = IsTransport ? GetTransOffsetX() : GetPositionX();
+ data.posY = IsTransport ? GetTransOffsetY() : GetPositionY();
+ data.posZ = IsTransport ? GetTransOffsetZ() : GetPositionZ();
+ data.orientation = IsTransport ? GetTransOffsetO() : GetOrientation();
+ data.transMap = transportMap;
data.spawntimesecs = m_respawnDelay;
// prevent add data integrity problems
- data.spawndist = GetDefaultMovementType()==IDLE_MOTION_TYPE ? 0 : m_respawnradius;
+ data.spawndist = GetDefaultMovementType() == IDLE_MOTION_TYPE ? 0 : m_respawnradius;
data.currentwaypoint = 0;
data.curhealth = GetHealth();
data.curmana = GetPower(POWER_MANA);
data.is_dead = m_isDeadByDefault;
// prevent add data integrity problems
- data.movementType = !m_respawnradius && GetDefaultMovementType()==RANDOM_MOTION_TYPE
+ data.movementType = !m_respawnradius && GetDefaultMovementType() == RANDOM_MOTION_TYPE
? IDLE_MOTION_TYPE : GetDefaultMovementType();
data.spawnMask = spawnMask;
@@ -1126,10 +1142,11 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
<< uint16(GetPhaseMask()) << "," // prevent out of range error
<< displayId <<","
<< GetEquipmentId() <<","
- << GetPositionX() << ","
- << GetPositionY() << ","
- << GetPositionZ() << ","
- << GetOrientation() << ","
+ << (IsTransport ? GetTransOffsetX() : GetPositionX()) << ","
+ << (IsTransport ? GetTransOffsetY() : GetPositionY()) << ","
+ << (IsTransport ? GetTransOffsetZ() : GetPositionZ()) << ","
+ << (IsTransport ? GetTransOffsetO() : GetOrientation()) << ","
+ << transportMap << ","
<< m_respawnDelay << "," //respawn time
<< (float) m_respawnradius << "," //spawn distance (float)
<< (uint32) (0) << "," //currentwaypoint
View
@@ -196,6 +196,7 @@ struct CreatureData
float posY;
float posZ;
float orientation;
+ uint32 transMap;
uint32 spawntimesecs;
float spawndist;
uint32 currentwaypoint;
@@ -45,13 +45,15 @@ VisibleNotifier::Notify()
// but exist one case when this possible and object not out of range: transports
if(Transport* transport = player.GetTransport())
{
- for(Transport::PlayerSet::const_iterator itr = transport->GetPassengers().begin();itr!=transport->GetPassengers().end();++itr)
+ for(Transport::UnitSet::const_iterator itr = transport->GetUnitPassengers().begin(); itr != transport->GetUnitPassengers().end(); ++itr)
{
if (i_clientGUIDs.find((*itr)->GetObjectGuid()) != i_clientGUIDs.end())
{
+ if ((*itr)->GetTypeId() != TYPEID_PLAYER)
+ continue;
+
// ignore far sight case
- (*itr)->UpdateVisibilityOf(*itr, &player);
- player.UpdateVisibilityOf(&player, *itr, i_data, i_visibleNow);
+ ((Player*)(*itr))->UpdateVisibilityOf(*itr, &player);
i_clientGUIDs.erase((*itr)->GetObjectGuid());
}
}
View
@@ -42,6 +42,7 @@
#include "GMTicketMgr.h"
#include "WaypointManager.h"
#include "Util.h"
+#include "Transports.h"
#include <cctype>
#include <iostream>
#include <fstream>
@@ -1603,35 +1604,73 @@ bool ChatHandler::HandleNpcAddCommand(char* args)
Player *chr = m_session->GetPlayer();
CreatureCreatePos pos(chr, chr->GetOrientation());
+ float tX = chr->GetTransOffsetX();
+ float tY = chr->GetTransOffsetY();
+ float tZ = chr->GetTransOffsetZ();
+ float tO = chr->GetTransOffsetO();
Map *map = chr->GetMap();
- Creature* pCreature = new Creature;
-
- // used guids from specially reserved range (can be 0 if no free values)
- uint32 lowguid = sObjectMgr.GenerateStaticCreatureLowGuid();
- if (!lowguid)
+ if (chr->GetTransport())
{
- SendSysMessage(LANG_NO_FREE_STATIC_GUID_FOR_SPAWN);
- SetSentErrorMessage(true);
- return false;
- }
+ float wX, wY;
+ wX = (tX*cos(chr->GetTransport()->GetOrientation()) + tY*sin(chr->GetTransport()->GetOrientation() + M_PI));
+ wY = (tY*cos(chr->GetTransport()->GetOrientation()) + tX*sin(chr->GetTransport()->GetOrientation()));
+ CreatureCreatePos pos(map, chr->GetTransport()->GetPositionX() + wX, chr->GetTransport()->GetPositionY() + wY, chr->GetTransport()->GetPositionZ() + tZ, chr->GetTransport()->GetOrientation() + tO, chr->GetTransport()->GetPhaseMask());
- if (!pCreature->Create(lowguid, pos, cinfo))
- {
- delete pCreature;
- return false;
+ Creature* pCreature = new Creature;
+
+ if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, cinfo))
+ {
+ delete pCreature;
+ return false;
+ }
+
+ pCreature->Relocate(chr->GetTransport()->GetPositionX() + wX, wY + chr->GetTransport()->GetPositionY(), chr->GetTransport()->GetPositionZ() + tZ, chr->GetTransport()->GetOrientation() + tO);
+
+ if(!pCreature->IsPositionValid())
+ {
+ sLog.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY());
+ delete pCreature;
+ return false;
+ }
+
+ pCreature->AIM_Initialize();
+
+ map->Add(pCreature);
+ chr->GetTransport()->EnterThisTransport(pCreature, tX, tY, tZ, tO);
+ pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
+ return true;
}
+ else
+ {
+ Creature* pCreature = new Creature;
- pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
+ // used guids from specially reserved range (can be 0 if no free values)
+ uint32 lowguid = sObjectMgr.GenerateStaticCreatureLowGuid();
+ if (!lowguid)
+ {
+ SendSysMessage(LANG_NO_FREE_STATIC_GUID_FOR_SPAWN);
+ SetSentErrorMessage(true);
+ return false;
+ }
- uint32 db_guid = pCreature->GetGUIDLow();
+ if (!pCreature->Create(lowguid, pos, cinfo))
+ {
+ delete pCreature;
+ return false;
+ }
- // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
- pCreature->LoadFromDB(db_guid, map);
+ pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
- map->Add(pCreature);
- sObjectMgr.AddCreatureToGrid(db_guid, sObjectMgr.GetCreatureData(db_guid));
- return true;
+ uint32 db_guid = pCreature->GetGUIDLow();
+
+ // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
+ pCreature->LoadFromDB(db_guid, map);
+
+ map->Add(pCreature);
+ sObjectMgr.AddCreatureToGrid(db_guid, sObjectMgr.GetCreatureData(db_guid));
+ return true;
+ }
}
//add item in vendorlist
@@ -1948,10 +1987,16 @@ bool ChatHandler::HandleNpcMoveCommand(char* args)
else
lowguid = pCreature->GetGUIDLow();
- float x = m_session->GetPlayer()->GetPositionX();
- float y = m_session->GetPlayer()->GetPositionY();
- float z = m_session->GetPlayer()->GetPositionZ();
- float o = m_session->GetPlayer()->GetOrientation();
+ Player* chr = m_session->GetPlayer();
+
+ uint32 TransMap = 0;
+ if (chr->GetTransport())
+ TransMap = chr->GetTransport()->GetGOInfo()->moTransport.mapID;
+
+ float x = chr->GetTransport() ? chr->GetTransOffsetX() : chr->GetPositionX();
+ float y = chr->GetTransport() ? chr->GetTransOffsetY() : chr->GetPositionY();
+ float z = chr->GetTransport() ? chr->GetTransOffsetZ() : chr->GetPositionZ();
+ float o = chr->GetTransport() ? chr->GetTransOffsetO() : chr->GetOrientation();
if (pCreature)
{
@@ -1962,7 +2007,16 @@ bool ChatHandler::HandleNpcMoveCommand(char* args)
const_cast<CreatureData*>(data)->posZ = z;
const_cast<CreatureData*>(data)->orientation = o;
}
- pCreature->GetMap()->CreatureRelocation(pCreature,x, y, z,o);
+ if (chr->GetTransport())
+ {
+ if (pCreature->GetTransport() && chr->GetTransport() != pCreature->GetTransport())
+ pCreature->GetTransport()->LeaveThisTransport(pCreature);
+
+ chr->GetTransport()->EnterThisTransport(pCreature, x, y, z, o);
+ }
+ else
+ pCreature->GetMap()->CreatureRelocation(pCreature,x, y, z,o);
+
pCreature->GetMotionMaster()->Initialize();
if (pCreature->isAlive()) // dead creature will reset movement generator at respawn
{
View
@@ -911,7 +911,7 @@ void Map::SendInitSelf( Player * player )
// build other passengers at transport also (they always visible and marked as visible and will not send at visibility update at add to map
if(Transport* transport = player->GetTransport())
{
- for(Transport::PlayerSet::const_iterator itr = transport->GetPassengers().begin();itr!=transport->GetPassengers().end();++itr)
+ for(Transport::UnitSet::const_iterator itr = transport->GetUnitPassengers().begin(); itr != transport->GetUnitPassengers().end(); ++itr)
{
if(player!=(*itr) && player->HaveAtClient(*itr))
{
@@ -3284,6 +3284,70 @@ void Map::PlayDirectSoundToMap(uint32 soundId)
itr->getSource()->SendDirectMessage(&data);
}
+Transport* Map::LoadTransportInMap(uint32 transportEntry, uint32 pointId, uint32 period, bool IsStoped /* = false*/, float orientation)
+{
+ Transport* trans = new Transport;
+ const GameObjectInfo *goinfo = ObjectMgr::GetGameObjectInfo(transportEntry);
+ if (!goinfo)
+ return NULL;
+
+ std::set<uint32> mapsUse;
+ trans->m_onePeriod = true;
+ trans->m_period = period;
+ trans->m_waypointTimer = 1000;
+ trans->m_microPointTimer = 1000;
+
+ if (!trans->GenerateWaypoints(goinfo->moTransport.taxiPathId, mapsUse))
+ {
+ delete trans;
+ return NULL;
+ }
+
+ uint32 mapid = trans->m_WayPoints[pointId].mapid;
+ float x = trans->m_WayPoints[pointId].x;
+ float y = trans->m_WayPoints[pointId].y;
+ float z = trans->m_WayPoints[pointId].z;
+ float o = orientation;
+
+ if (!trans->Create(transportEntry, mapid, x, y, z, o, GO_ANIMPROGRESS_DEFAULT, 0))
+ {
+ delete trans;
+ return NULL;
+ }
+
+ sMapMgr.m_Transports.insert(trans);
+
+ for (std::set<uint32>::const_iterator i = mapsUse.begin(); i != mapsUse.end(); ++i)
+ sMapMgr.m_TransportsByMap[*i].insert(trans);
+
+ Add(trans);
+
+ trans->SetWayPoint(pointId);
+ trans->LoadTransportAccessory();
+
+ if (IsStoped)
+ trans->BuildMovementPacket(this);
+ else
+ trans->BuildMovementPacket(this, true);
+
+ error_log("%s with Entry = %u LOADED in dX = %f, dY = %f, dZ = %f", trans->GetName(), trans->GetEntry(), x, y, z);
+
+ return trans;
+}
+
+/** ##### WARNING! USE THIS ONLY IF TRANSPORT ON WORLD MAP, NOT ON INSTANCE MAP! ##### */
+Transport* Map::GetTransportFromStorage(uint32 entry)
+{
+ for (MapManager::TransportSet::iterator itr = sMapMgr.m_Transports.begin(); itr != sMapMgr.m_Transports.end(); ++itr)
+ {
+ Transport* trans = *itr;
+ if (trans->GetEntry() == entry && this == trans->GetMap())
+ return trans;
+ }
+
+ return NULL;
+}
+
void Map::SetMapWeather(WeatherState state, float grade)
{
//Weather is OFF
View
@@ -35,6 +35,7 @@
#include "MapRefManager.h"
#include "Utilities/TypeList.h"
#include "ScriptMgr.h"
+#include "Transports.h"
#include "Weather.h"
#include "CreatureLinkingMgr.h"
#include "ObjectLock.h"
@@ -281,6 +282,10 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>
// Get Holder for Creature Linking
CreatureLinkingHolder* GetCreatureLinkingHolder() { return &m_creatureLinkingHolder; }
+ // Loading Transport
+ Transport* LoadTransportInMap(uint32 transportEntry, uint32 pointId = 0, uint32 period = 0, bool IsStoped = false, float orientation = 1.0f);
+ Transport* GetTransportFromStorage(uint32 entry);
+
private:
void LoadMapAndVMap(int gx, int gy);
@@ -548,7 +548,7 @@ void WorldSession::HandleMoverRelocation(MovementInfo& movementInfo)
{
if ((*iter)->GetObjectGuid() == movementInfo.GetTransportGuid())
{
- plMover->m_transport = (*iter);
+ plMover->SetTransport(*iter);
(*iter)->AddPassenger(plMover);
if (plMover->GetVehicleKit())
Oops, something went wrong.

0 comments on commit 662794a

Please sign in to comment.