aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2009-03-28 22:44:09 -0600
committermegamage <none@none>2009-03-28 22:44:09 -0600
commit783e4fd3ff077b3023046f407a99552c109ef486 (patch)
treef7f3c5c33ed75603e077e43ae9c3e9f56b5be4c0 /src
parent3a485c658d9003aaaa4bd8e99dfebb9e7f0ec862 (diff)
*Add new creature_template column VehicleId
*Allow spawn vehicles *Make vehicles grid objects. --HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/Creature.cpp4
-rw-r--r--src/game/Creature.h2
-rw-r--r--src/game/Debugcmds.cpp2
-rw-r--r--src/game/Map.cpp6
-rw-r--r--src/game/MiscHandler.cpp3
-rw-r--r--src/game/MovementHandler.cpp3
-rw-r--r--src/game/Object.cpp4
-rw-r--r--src/game/ObjectGridLoader.cpp33
-rw-r--r--src/game/Player.cpp2
-rw-r--r--src/game/Vehicle.cpp76
-rw-r--r--src/game/Vehicle.h3
-rw-r--r--src/shared/Database/SQLStorage.cpp4
12 files changed, 130 insertions, 12 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 49ec6854e9d..538a755e8ad 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -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);
diff --git a/src/game/Creature.h b/src/game/Creature.h
index 55923179967..5dd9dc9afdc 100644
--- a/src/game/Creature.h
+++ b/src/game/Creature.h
@@ -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; }
diff --git a/src/game/Debugcmds.cpp b/src/game/Debugcmds.cpp
index d0402b4851c..6e7ef493ce5 100644
--- a/src/game/Debugcmds.cpp
+++ b/src/game/Debugcmds.cpp
@@ -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;
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 1b2236b989e..c00b774c68f 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -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;
}
diff --git a/src/game/MiscHandler.cpp b/src/game/MiscHandler.cpp
index 44ae9cbb732..7b1a3731d16 100644
--- a/src/game/MiscHandler.cpp
+++ b/src/game/MiscHandler.cpp
@@ -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);
}
diff --git a/src/game/MovementHandler.cpp b/src/game/MovementHandler.cpp
index a8a4598fd62..28317cc1471 100644
--- a/src/game/MovementHandler.cpp
+++ b/src/game/MovementHandler.cpp
@@ -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();
}
}
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 79c3ebba369..c47c3625160 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -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;
diff --git a/src/game/ObjectGridLoader.cpp b/src/game/ObjectGridLoader.cpp
index 9078dd4268d..7c3c88756af 100644
--- a/src/game/ObjectGridLoader.cpp
+++ b/src/game/ObjectGridLoader.cpp
@@ -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())
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index d51ad0d506c..707467cd03d 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -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;
diff --git a/src/game/Vehicle.cpp b/src/game/Vehicle.cpp
index feffa1b4570..e5f45722eba 100644
--- a/src/game/Vehicle.cpp
+++ b/src/game/Vehicle.cpp
@@ -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;
+}
diff --git a/src/game/Vehicle.h b/src/game/Vehicle.h
index 6d9c7cd7943..06630368798 100644
--- a/src/game/Vehicle.h
+++ b/src/game/Vehicle.h
@@ -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;
diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp
index b5e7508afe5..8561afc4a33 100644
--- a/src/shared/Database/SQLStorage.cpp
+++ b/src/shared/Database/SQLStorage.cpp
@@ -27,8 +27,8 @@ extern DatabasePostgre WorldDatabase;
extern DatabaseMysql WorldDatabase;
#endif
-const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiisiifflliiis";
-const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiisiifflliiii";
+const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifflliiis";
+const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifflliiii";
const char CreatureDataAddonInfofmt[]="iiiiiiiis";
const char CreatureModelfmt[]="iffbi";
const char CreatureInfoAddonInfofmt[]="iiiiiiiis";