aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/Creature.cpp7
-rw-r--r--src/game/GameEvent.cpp77
-rw-r--r--src/game/GameEvent.h3
-rw-r--r--src/game/GameObject.cpp15
-rw-r--r--src/game/Level2.cpp37
-rw-r--r--src/game/Makefile.am2
-rw-r--r--src/game/ObjectMgr.cpp58
-rw-r--r--src/game/World.cpp7
8 files changed, 167 insertions, 39 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index e6fc9e394ba..6810b07de93 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -29,6 +29,7 @@
#include "QuestDef.h"
#include "GossipDef.h"
#include "Player.h"
+#include "PoolHandler.h"
#include "Opcodes.h"
#include "Log.h"
#include "LootMgr.h"
@@ -423,7 +424,11 @@ void Creature::Update(uint32 diff)
//Call AI respawn virtual function
i_AI->JustRespawned();
- GetMap()->Add(this);
+ uint16 poolid = poolhandler.IsPartOfAPool(GetGUIDLow(), GetTypeId());
+ if (poolid)
+ poolhandler.UpdatePool(poolid, GetGUIDLow(), GetTypeId());
+ else
+ GetMap()->Add(this);
}
break;
}
diff --git a/src/game/GameEvent.cpp b/src/game/GameEvent.cpp
index 6c2be2b5267..49b55f727e6 100644
--- a/src/game/GameEvent.cpp
+++ b/src/game/GameEvent.cpp
@@ -21,6 +21,7 @@
#include "GameEvent.h"
#include "World.h"
#include "ObjectMgr.h"
+#include "PoolHandler.h"
#include "ProgressBar.h"
#include "Language.h"
#include "Log.h"
@@ -916,6 +917,61 @@ void GameEvent::LoadFromDB()
delete result;
}
+
+ ////////////////////////
+ // GameEventPool
+ ////////////////////////
+
+ mGameEventPoolIds.resize(mGameEvent.size()*2-1);
+ // 1 2
+ result = WorldDatabase.Query("SELECT pool_template.entry, game_event_pool.event "
+ "FROM pool_template JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry");
+
+ count = 0;
+ if( !result )
+ {
+ barGoLink bar2(1);
+ bar2.step();
+
+ sLog.outString();
+ sLog.outString(">> Loaded %u pools in game events", count );
+ }
+ else
+ {
+
+ barGoLink bar2( result->GetRowCount() );
+ do
+ {
+ Field *fields = result->Fetch();
+
+ bar2.step();
+
+ uint32 entry = fields[0].GetUInt16();
+ int16 event_id = fields[1].GetInt16();
+
+ int32 internal_event_id = mGameEvent.size() + event_id - 1;
+
+ if(internal_event_id < 0 || internal_event_id >= mGameEventPoolIds.size())
+ {
+ sLog.outErrorDb("`game_event_pool` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
+ continue;
+ }
+
+ if (!poolhandler.CheckPool(entry))
+ {
+ sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", entry);
+ continue;
+ }
+
+ ++count;
+ IdList& poollist = mGameEventPoolIds[internal_event_id];
+ poollist.push_back(entry);
+
+ } while( result->NextRow() );
+ sLog.outString();
+ sLog.outString( ">> Loaded %u pools in game events", count );
+ delete result;
+ }
}
uint32 GameEvent::GetNPCFlag(Creature * cr)
@@ -1188,6 +1244,17 @@ void GameEvent::GameEventSpawn(int16 event_id)
}
}
}
+
+ if(internal_event_id < 0 || internal_event_id >= mGameEventPoolIds.size())
+ {
+ sLog.outError("GameEvent::GameEventSpawn attempt access to out of range mGameEventPoolIds element %i (size: %u)",internal_event_id,mGameEventPoolIds.size());
+ return;
+ }
+
+ for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr)
+ {
+ poolhandler.SpawnPool(*itr);
+ }
}
void GameEvent::GameEventUnspawn(int16 event_id)
@@ -1238,6 +1305,16 @@ void GameEvent::GameEventUnspawn(int16 event_id)
pGameobject->AddObjectToRemoveList();
}
}
+ if(internal_event_id < 0 || internal_event_id >= mGameEventPoolIds.size())
+ {
+ sLog.outError("GameEvent::GameEventUnspawn attempt access to out of range mGameEventPoolIds element %i (size: %u)",internal_event_id,mGameEventPoolIds.size());
+ return;
+ }
+
+ for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr)
+ {
+ poolhandler.DespawnPool(*itr);
+ }
}
void GameEvent::ChangeEquipOrModel(int16 event_id, bool activate)
diff --git a/src/game/GameEvent.h b/src/game/GameEvent.h
index 6333d906256..184f4934b5d 100644
--- a/src/game/GameEvent.h
+++ b/src/game/GameEvent.h
@@ -127,7 +127,9 @@ class GameEvent
bool hasGameObjectActiveEventExcept(uint32 go_guid, uint16 event_id);
protected:
typedef std::list<uint32> GuidList;
+ typedef std::list<uint16> IdList;
typedef std::vector<GuidList> GameEventGuidMap;
+ typedef std::vector<IdList> GameEventIdMap;
typedef std::pair<uint32, ModelEquip> ModelEquipPair;
typedef std::list<ModelEquipPair> ModelEquipList;
typedef std::vector<ModelEquipList> GameEventModelEquipMap;
@@ -149,6 +151,7 @@ class GameEvent
GameEventModelEquipMap mGameEventModelEquip;
GameEventGuidMap mGameEventCreatureGuids;
GameEventGuidMap mGameEventGameobjectGuids;
+ GameEventIdMap mGameEventPoolIds;
GameEventDataMap mGameEvent;
GameEventBitmask mGameEventBattleGroundHolidays;
QuestIdToEventConditionMap mQuestToEventConditions;
diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp
index 8c51259e9f0..dc04388ef59 100644
--- a/src/game/GameObject.cpp
+++ b/src/game/GameObject.cpp
@@ -22,6 +22,7 @@
#include "QuestDef.h"
#include "GameObject.h"
#include "ObjectMgr.h"
+#include "PoolHandler.h"
#include "SpellMgr.h"
#include "Spell.h"
#include "UpdateMask.h"
@@ -66,7 +67,7 @@ GameObject::~GameObject()
{
if(m_uint32Values) // field array can be not exist if GameOBject not loaded
{
- // crash possible at access to deleted GO in Unit::m_gameobj
+ // Possible crash at access to deleted GO in Unit::m_gameobj
uint64 owner_guid = GetOwnerGUID();
if(owner_guid)
{
@@ -281,7 +282,11 @@ void GameObject::Update(uint32 /*p_time*/)
return;
}
// respawn timer
- GetMap()->Add(this);
+ uint16 poolid = poolhandler.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT);
+ if (poolid)
+ poolhandler.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT);
+ else
+ GetMap()->Add(this);
break;
}
}
@@ -484,7 +489,11 @@ void GameObject::Delete()
SetGoState(1);
SetUInt32Value(GAMEOBJECT_FLAGS, GetGOInfo()->flags);
- AddObjectToRemoveList();
+ uint16 poolid = poolhandler.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT);
+ if (poolid)
+ poolhandler.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT);
+ else
+ AddObjectToRemoveList();
}
void GameObject::getFishLoot(Loot *fishloot, Player* loot_owner)
diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp
index 21f196c74e2..42fbea8255d 100644
--- a/src/game/Level2.cpp
+++ b/src/game/Level2.cpp
@@ -35,6 +35,7 @@
#include "World.h"
#include "GameEvent.h"
#include "SpellMgr.h"
+#include "PoolHandler.h"
#include "AccountMgr.h"
//#include "GMTicketMgr.h"
#include "WaypointManager.h"
@@ -204,7 +205,7 @@ bool ChatHandler::HandleTargetObjectCommand(const char* args)
result = WorldDatabase.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, "
"(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
- "LEFT OUTER JOIN game_event_gameobject on gameobject.guid=game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 1",
+ "LEFT OUTER JOIN game_event_gameobject on gameobject.guid=game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10",
m_session->GetPlayer()->GetPositionX(), m_session->GetPlayer()->GetPositionY(), m_session->GetPlayer()->GetPositionZ(), m_session->GetPlayer()->GetMapId(),eventFilter.str().c_str());
}
@@ -214,16 +215,34 @@ bool ChatHandler::HandleTargetObjectCommand(const char* args)
return true;
}
- Field *fields = result->Fetch();
- uint32 lowguid = fields[0].GetUInt32();
- uint32 id = fields[1].GetUInt32();
- float x = fields[2].GetFloat();
- float y = fields[3].GetFloat();
- float z = fields[4].GetFloat();
- float o = fields[5].GetFloat();
- int mapid = fields[6].GetUInt16();
+ bool found = false;
+ float x, y, z, o;
+ uint32 lowguid, id;
+ uint16 mapid, pool_id;
+
+ do
+ {
+ Field *fields = result->Fetch();
+ lowguid = fields[0].GetUInt32();
+ id = fields[1].GetUInt32();
+ x = fields[2].GetFloat();
+ y = fields[3].GetFloat();
+ z = fields[4].GetFloat();
+ o = fields[5].GetFloat();
+ mapid = fields[6].GetUInt16();
+ pool_id = poolhandler.IsPartOfAPool(lowguid, TYPEID_GAMEOBJECT);
+ if (!pool_id || (pool_id && poolhandler.IsSpawnedObject(pool_id, lowguid, TYPEID_GAMEOBJECT)))
+ found = true;
+ } while( result->NextRow() && (!found) );
+
delete result;
+ if (!found)
+ {
+ PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id);
+ return false;
+ }
+
GameObjectInfo const* goI = objmgr.GetGameObjectInfo(id);
if (!goI)
diff --git a/src/game/Makefile.am b/src/game/Makefile.am
index 2623472b2c0..256d24ada5b 100644
--- a/src/game/Makefile.am
+++ b/src/game/Makefile.am
@@ -227,6 +227,8 @@ libmangosgame_a_SOURCES = \
PossessedAI.h \
PointMovementGenerator.cpp \
PointMovementGenerator.h \
+ PoolHandler.cpp \
+ PoolHandler.h \
QueryHandler.cpp \
QuestDef.cpp \
QuestDef.h \
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index 651c710deb2..85706bc088e 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -939,9 +939,10 @@ void ObjectMgr::LoadCreatures()
QueryResult *result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid,"
// 4 5 6 7 8 9 10 11
"equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint,"
- // 12 13 14 15 16 17 18
- "curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, event "
- "FROM creature LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid");
+ // 12 13 14 15 16 17 18 19
+ "curhealth, curmana, DeathState, MovementType, spawnMask, phaseMask, event, pool_entry "
+ "FROM creature LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid "
+ "LEFT OUTER JOIN pool_creature ON creature.guid = pool_creature.guid");
if(!result)
{
@@ -968,11 +969,19 @@ void ObjectMgr::LoadCreatures()
Field *fields = result->Fetch();
bar.step();
- uint32 guid = fields[0].GetUInt32();
+ uint32 guid = fields[ 0].GetUInt32();
+ uint32 entry = fields[ 1].GetUInt32();
+
+ CreatureInfo const* cInfo = GetCreatureTemplate(entry);
+ if(!cInfo)
+ {
+ sLog.outErrorDb("Table `creature` has creature (GUID: %u) with non existing creature entry %u, skipped.", guid, entry);
+ continue;
+ }
CreatureData& data = mCreatureDataMap[guid];
- data.id = fields[ 1].GetUInt32();
+ data.id = entry;
data.mapid = fields[ 2].GetUInt32();
data.displayid = fields[ 3].GetUInt32();
data.equipmentId = fields[ 4].GetUInt32();
@@ -990,13 +999,7 @@ void ObjectMgr::LoadCreatures()
data.spawnMask = fields[16].GetUInt8();
data.phaseMask = fields[17].GetUInt16();
int16 gameEvent = fields[18].GetInt16();
-
- CreatureInfo const* cInfo = GetCreatureTemplate(data.id);
- if(!cInfo)
- {
- sLog.outErrorDb("Table `creature` have creature (GUID: %u) with not existed creature entry %u, skipped.",guid,data.id );
- continue;
- }
+ int16 PoolId = fields[19].GetInt16();
if(heroicCreatures.find(data.id)!=heroicCreatures.end())
{
@@ -1081,7 +1084,7 @@ void ObjectMgr::LoadCreatures()
}
}
- if (gameEvent==0) // if not this is to be managed by GameEvent System
+ if (gameEvent==0 && PoolId==0) // if not this is to be managed by GameEvent System or Pool system
AddCreatureToGrid(guid, &data);
++count;
@@ -1131,9 +1134,10 @@ void ObjectMgr::LoadGameobjects()
// 0 1 2 3 4 5 6
QueryResult *result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation,"
- // 7 8 9 10 11 12 13 14 15 16
- "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event "
- "FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid");
+ // 7 8 9 10 11 12 13 14 15 16 17
+ "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event, pool_entry "
+ "FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid "
+ "LEFT OUTER JOIN pool_gameobject ON gameobject.guid = pool_gameobject.guid");
if(!result)
{
@@ -1153,11 +1157,19 @@ void ObjectMgr::LoadGameobjects()
Field *fields = result->Fetch();
bar.step();
- uint32 guid = fields[0].GetUInt32();
+ uint32 guid = fields[ 0].GetUInt32();
+ uint32 entry = fields[ 1].GetUInt32();
+
+ GameObjectInfo const* gInfo = GetGameObjectInfo(entry);
+ if(!gInfo)
+ {
+ sLog.outErrorDb("Table `gameobject` has gameobject (GUID: %u) with non existing gameobject entry %u, skipped.", guid, entry);
+ continue;
+ }
GameObjectData& data = mGameObjectDataMap[guid];
- data.id = fields[ 1].GetUInt32();
+ data.id = entry;
data.mapid = fields[ 2].GetUInt32();
data.posX = fields[ 3].GetFloat();
data.posY = fields[ 4].GetFloat();
@@ -1174,13 +1186,7 @@ void ObjectMgr::LoadGameobjects()
data.spawnMask = fields[14].GetUInt8();
data.phaseMask = fields[15].GetUInt16();
int16 gameEvent = fields[16].GetInt16();
-
- GameObjectInfo const* gInfo = GetGameObjectInfo(data.id);
- if(!gInfo)
- {
- sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u) with not existed gameobject entry %u, skipped.",guid,data.id );
- continue;
- }
+ int16 PoolId = fields[17].GetInt16();
if(data.phaseMask==0)
{
@@ -1188,7 +1194,7 @@ void ObjectMgr::LoadGameobjects()
data.phaseMask = 1;
}
- if (gameEvent==0) // if not this is to be managed by GameEvent System
+ if (gameEvent==0 && PoolId==0) // if not this is to be managed by GameEvent System or Pool system
AddGameobjectToGrid(guid, &data);
++count;
diff --git a/src/game/World.cpp b/src/game/World.cpp
index 084be8f691b..21fb07d5794 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -57,6 +57,7 @@
#include "VMapFactory.h"
#include "GlobalEvents.h"
#include "GameEvent.h"
+#include "PoolHandler.h"
#include "Database/DatabaseImpl.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
@@ -1220,6 +1221,9 @@ void World::SetInitialWorldSettings()
sLog.outString( "Loading Gameobject Respawn Data..." ); // must be after PackInstances()
objmgr.LoadGameobjectRespawnTimes();
+ sLog.outString( "Loading Objects Pooling Data...");
+ poolhandler.LoadFromDB();
+
sLog.outString( "Loading Game Event Data...");
sLog.outString();
gameeventmgr.LoadFromDB();
@@ -1455,6 +1459,9 @@ void World::SetInitialWorldSettings()
sLog.outString("Calculate next daily quest reset time..." );
InitDailyQuestResetTime();
+ sLog.outString("Starting objects Pooling system..." );
+ poolhandler.Initialize();
+
sLog.outString("Starting Game Event system..." );
uint32 nextGameEvent = gameeventmgr.Initialize();
m_timers[WUPDATE_EVENTS].SetInterval(nextGameEvent); //depend on next event