*Add new creature_template column VehicleId
*Allow spawn vehicles *Make vehicles grid objects. --HG-- branch : trunk
This commit is contained in:
@@ -1393,6 +1393,10 @@ bool Creature::LoadFromDB(uint32 guid, Map *map)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(const CreatureInfo *cInfo = objmgr.GetCreatureTemplate(data->id))
|
||||
if(cInfo->VehicleId)
|
||||
return false;
|
||||
|
||||
m_DBTableGuid = guid;
|
||||
if (map->GetInstanceId() != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT);
|
||||
|
||||
|
||||
@@ -207,6 +207,7 @@ struct CreatureInfo
|
||||
int32 resistance6;
|
||||
uint32 spells[CREATURE_MAX_SPELLS];
|
||||
uint32 PetSpellDataId;
|
||||
uint32 VehicleId;
|
||||
uint32 mingold;
|
||||
uint32 maxgold;
|
||||
char const* AIName;
|
||||
@@ -450,6 +451,7 @@ class TRINITY_DLL_SPEC Creature : public Unit
|
||||
bool isSummon() const { return m_summonMask & SUMMON_MASK_SUMMON; }
|
||||
bool isPet() const { return m_summonMask & SUMMON_MASK_PET; }
|
||||
bool isVehicle() const { return m_summonMask & SUMMON_MASK_VEHICLE; }
|
||||
bool isWorldCreature() const { return m_summonMask & SUMMON_MASK_PET; }
|
||||
bool isTotem() const { return m_summonMask & SUMMON_MASK_TOTEM; }
|
||||
void SetCorpseDelay(uint32 delay) { m_corpseDelay = delay; }
|
||||
bool isRacialLeader() const { return GetCreatureInfo()->RacialLeader; }
|
||||
|
||||
@@ -652,7 +652,7 @@ bool ChatHandler::HandleDebugSpawnVehicle(const char* args)
|
||||
|
||||
Vehicle *v = new Vehicle;
|
||||
Map *map = m_session->GetPlayer()->GetMap();
|
||||
if(!v->Create(objmgr.GenerateLowGuid(HIGHGUID_VEHICLE), map, entry, id, m_session->GetPlayer()->GetTeam()))
|
||||
if(!v->Create(objmgr.GenerateLowGuid(HIGHGUID_VEHICLE), map, m_session->GetPlayer()->GetPhaseMask(), entry, id, m_session->GetPlayer()->GetTeam()))
|
||||
{
|
||||
delete v;
|
||||
return false;
|
||||
|
||||
+3
-3
@@ -237,7 +237,7 @@ template<>
|
||||
void Map::AddToGrid(Creature* obj, NGridType *grid, Cell const& cell)
|
||||
{
|
||||
// add to world object registry in grid
|
||||
if(obj->isPet() || obj->isVehicle() || obj->IsTempWorldObject)
|
||||
if(obj->isWorldCreature() || obj->IsTempWorldObject)
|
||||
{
|
||||
(*grid)(cell.CellX(), cell.CellY()).AddWorldObject<Creature>(obj, obj->GetGUID());
|
||||
}
|
||||
@@ -289,7 +289,7 @@ template<>
|
||||
void Map::RemoveFromGrid(Creature* obj, NGridType *grid, Cell const& cell)
|
||||
{
|
||||
// remove from world object registry in grid
|
||||
if(obj->isPet() || obj->isVehicle() || obj->IsTempWorldObject)
|
||||
if(obj->isWorldCreature() || obj->IsTempWorldObject)
|
||||
{
|
||||
(*grid)(cell.CellX(), cell.CellY()).RemoveWorldObject<Creature>(obj, obj->GetGUID());
|
||||
}
|
||||
@@ -2022,7 +2022,7 @@ void Map::RemoveAllObjectsInRemoveList()
|
||||
switch(obj->GetTypeId())
|
||||
{
|
||||
case TYPEID_UNIT:
|
||||
if(!((Creature*)obj)->isPet() && !((Creature*)obj)->isVehicle())
|
||||
if(!((Creature*)obj)->isWorldCreature())
|
||||
SwitchGridContainers((Creature*)obj, on);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1632,7 +1632,10 @@ void WorldSession::HandleSpellClick( WorldPacket & recv_data )
|
||||
Vehicle *vehicle = ObjectAccessor::GetVehicle(guid);
|
||||
|
||||
if(!vehicle)
|
||||
{
|
||||
sLog.outError("Player %s cannot find vehicle %u", _player->GetName(), guid);
|
||||
return;
|
||||
}
|
||||
|
||||
_player->EnterVehicle(vehicle);
|
||||
}
|
||||
|
||||
@@ -435,7 +435,8 @@ void WorldSession::HandleDismissControlledVehicle(WorldPacket &recv_data)
|
||||
if(Vehicle *vehicle = ObjectAccessor::GetVehicle(vehicleGUID))
|
||||
{
|
||||
_player->ExitVehicle(vehicle);
|
||||
vehicle->Dismiss();
|
||||
if(!vehicle->GetDBTableGUIDLow())
|
||||
vehicle->Dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1746,7 +1746,7 @@ Vehicle* WorldObject::SummonVehicle(uint32 entry, float x, float y, float z, flo
|
||||
if(!ci)
|
||||
return NULL;
|
||||
|
||||
uint32 id = ci->spells[7]; //temp store id here
|
||||
uint32 id = ci->VehicleId; //temp store id here
|
||||
if(!id) id = 156;
|
||||
VehicleEntry const *ve = sVehicleStore.LookupEntry(id);
|
||||
if(!ve)
|
||||
@@ -1757,7 +1757,7 @@ Vehicle* WorldObject::SummonVehicle(uint32 entry, float x, float y, float z, flo
|
||||
uint32 team = 0;
|
||||
if (GetTypeId()==TYPEID_PLAYER)
|
||||
team = ((Player*)this)->GetTeam();
|
||||
if(!v->Create(objmgr.GenerateLowGuid(HIGHGUID_VEHICLE), map, entry, id, team))
|
||||
if(!v->Create(objmgr.GenerateLowGuid(HIGHGUID_VEHICLE), map, GetPhaseMask(), entry, id, team))
|
||||
{
|
||||
delete v;
|
||||
return NULL;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "ObjectAccessor.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Creature.h"
|
||||
#include "Vehicle.h"
|
||||
#include "GameObject.h"
|
||||
#include "DynamicObject.h"
|
||||
#include "Corpse.h"
|
||||
@@ -58,7 +59,7 @@ ObjectGridRespawnMover::Visit(CreatureMapType &m)
|
||||
|
||||
Creature * c = iter->getSource();
|
||||
|
||||
assert((!c->isPet() || !c->isVehicle()) && "ObjectGridRespawnMover don't must be called for pets");
|
||||
assert(!c->isWorldCreature() && "ObjectGridRespawnMover don't must be called for pets");
|
||||
|
||||
Cell const& cur_cell = c->GetCurrentCell();
|
||||
|
||||
@@ -134,6 +135,36 @@ void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> &
|
||||
}
|
||||
}
|
||||
|
||||
void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, CreatureMapType &m, uint32 &count, Map* map)
|
||||
{
|
||||
for(CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid)
|
||||
{
|
||||
Creature* obj = new Creature;
|
||||
uint32 guid = *i_guid;
|
||||
//sLog.outString("DEBUG: LoadHelper from table: %s for (guid: %u) Loading",table,guid);
|
||||
if(!obj->LoadFromDB(guid, map))
|
||||
{
|
||||
delete obj;
|
||||
obj = new Vehicle;
|
||||
if(!((Vehicle*)obj)->LoadFromDB(guid, map))
|
||||
{
|
||||
delete (Vehicle*)obj;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
obj->GetGridRef().link(&m, obj);
|
||||
|
||||
addUnitState(obj,cell);
|
||||
obj->AddToWorld();
|
||||
if(obj->isActiveObject())
|
||||
map->AddToActive(obj);
|
||||
|
||||
++count;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void LoadHelper(CellCorpseSet const& cell_corpses, CellPair &cell, CorpseMapType &m, uint32 &count, Map* map)
|
||||
{
|
||||
if(cell_corpses.empty())
|
||||
|
||||
@@ -19781,6 +19781,8 @@ void Player::InitGlyphsForLevel()
|
||||
|
||||
void Player::EnterVehicle(Vehicle *vehicle)
|
||||
{
|
||||
sLog.outDebug("Player %s enter vehicle entry %u id %u dbguid %u", GetName(), vehicle->GetEntry(), vehicle->GetVehicleId(), vehicle->GetDBTableGUIDLow());
|
||||
|
||||
if(vehicle->GetCharmerGUID())
|
||||
return;
|
||||
|
||||
|
||||
+75
-1
@@ -67,7 +67,7 @@ void Vehicle::Update(uint32 diff)
|
||||
Creature::Update(diff);
|
||||
}
|
||||
|
||||
bool Vehicle::Create(uint32 guidlow, Map *map, uint32 Entry, uint32 vehicleId, uint32 team)
|
||||
bool Vehicle::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 vehicleId, uint32 team)
|
||||
{
|
||||
SetMapId(map->GetId());
|
||||
SetInstanceId(map->GetInstanceId());
|
||||
@@ -102,3 +102,77 @@ void Vehicle::Dismiss()
|
||||
CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
bool Vehicle::LoadFromDB(uint32 guid, Map *map)
|
||||
{
|
||||
CreatureData const* data = objmgr.GetCreatureData(guid);
|
||||
|
||||
if(!data)
|
||||
{
|
||||
sLog.outErrorDb("Creature (GUID: %u) not found in table `creature`, can't load. ",guid);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 id = 0;
|
||||
if(const CreatureInfo *cInfo = objmgr.GetCreatureTemplate(data->id))
|
||||
id = cInfo->VehicleId;
|
||||
if(!id || !sVehicleStore.LookupEntry(id))
|
||||
return false;
|
||||
|
||||
m_DBTableGuid = guid;
|
||||
if (map->GetInstanceId() != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_VEHICLE);
|
||||
|
||||
uint16 team = 0;
|
||||
if(!Create(guid,map,data->phaseMask,data->id,id,team))
|
||||
return false;
|
||||
|
||||
Relocate(data->posX,data->posY,data->posZ,data->orientation);
|
||||
|
||||
if(!IsPositionValid())
|
||||
{
|
||||
sLog.outError("Creature (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)",GetGUIDLow(),GetEntry(),GetPositionX(),GetPositionY());
|
||||
return false;
|
||||
}
|
||||
//We should set first home position, because then AI calls home movement
|
||||
SetHomePosition(data->posX,data->posY,data->posZ,data->orientation);
|
||||
|
||||
m_respawnradius = data->spawndist;
|
||||
|
||||
m_respawnDelay = data->spawntimesecs;
|
||||
m_isDeadByDefault = data->is_dead;
|
||||
m_deathState = m_isDeadByDefault ? DEAD : ALIVE;
|
||||
|
||||
m_respawnTime = objmgr.GetCreatureRespawnTime(m_DBTableGuid,GetInstanceId());
|
||||
if(m_respawnTime > time(NULL)) // not ready to respawn
|
||||
{
|
||||
m_deathState = DEAD;
|
||||
if(canFly())
|
||||
{
|
||||
float tz = GetMap()->GetHeight(data->posX,data->posY,data->posZ,false);
|
||||
if(data->posZ - tz > 0.1)
|
||||
Relocate(data->posX,data->posY,tz);
|
||||
}
|
||||
}
|
||||
else if(m_respawnTime) // respawn time set but expired
|
||||
{
|
||||
m_respawnTime = 0;
|
||||
objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0);
|
||||
}
|
||||
|
||||
uint32 curhealth = data->curhealth;
|
||||
if(curhealth)
|
||||
{
|
||||
curhealth = uint32(curhealth*_GetHealthMod(GetCreatureInfo()->rank));
|
||||
if(curhealth < 1)
|
||||
curhealth = 1;
|
||||
}
|
||||
|
||||
SetHealth(m_deathState == ALIVE ? curhealth : 0);
|
||||
SetPower(POWER_MANA,data->curmana);
|
||||
|
||||
// checked at creature_template loading
|
||||
m_defaultMovementType = MovementGeneratorType(data->movementType);
|
||||
|
||||
AIM_Initialize();
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
-1
@@ -32,7 +32,7 @@ class Vehicle : public Creature
|
||||
void AddToWorld();
|
||||
void RemoveFromWorld();
|
||||
|
||||
bool Create (uint32 guidlow, Map *map, uint32 Entry, uint32 vehicleId, uint32 team);
|
||||
bool Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 vehicleId, uint32 team);
|
||||
|
||||
void setDeathState(DeathState s); // overwrite virtual Creature::setDeathState and Unit::setDeathState
|
||||
void Update(uint32 diff); // overwrite virtual Creature::Update and Unit::Update
|
||||
@@ -42,6 +42,7 @@ class Vehicle : public Creature
|
||||
|
||||
void Dismiss();
|
||||
|
||||
bool LoadFromDB(uint32 guid, Map *map);
|
||||
protected:
|
||||
uint32 m_vehicleId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user