From 8daaf04994fdb4e99b687bd43af917d56b64aa3f Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Thu, 24 Sep 2015 11:48:07 +0300 Subject: [PATCH] Fix TC build --- CreatureMethods.h | 2 +- ElunaUtility.h | 39 +++++++++++++++++++++++++++++++++++++++ GameObjectMethods.h | 2 +- GlobalMethods.h | 26 ++++++++++++++++---------- LuaEngine.cpp | 26 +++++++++++++++++++++----- MapMethods.h | 12 ++++++------ ObjectMethods.h | 4 ++++ PlayerMethods.h | 10 +++++++++- 8 files changed, 97 insertions(+), 24 deletions(-) diff --git a/CreatureMethods.h b/CreatureMethods.h index 9ab2c23..2989784 100644 --- a/CreatureMethods.h +++ b/CreatureMethods.h @@ -860,7 +860,7 @@ namespace LuaCreature int GetDBTableGUIDLow(Eluna* /*E*/, lua_State* L, Creature* creature) { #ifdef TRINITY - Eluna::Push(L, creature->GetDBTableGUIDLow()); + Eluna::Push(L, creature->GetSpawnId()); #else // on mangos based this is same as lowguid Eluna::Push(L, creature->GetGUIDLow()); diff --git a/ElunaUtility.h b/ElunaUtility.h index 63d3936..2a5c4e0 100644 --- a/ElunaUtility.h +++ b/ElunaUtility.h @@ -50,6 +50,45 @@ typedef QueryNamedResult ElunaQuery; #define GetTemplate GetProto #endif +#ifndef HIGHGUID_PLAYER +#define HIGHGUID_PLAYER HighGuid::Player +#endif +#ifndef HIGHGUID_UNIT +#define HIGHGUID_UNIT HighGuid::Unit +#endif +#ifndef HIGHGUID_GAMEOBJECT +#define HIGHGUID_GAMEOBJECT HighGuid::GameObject +#endif +#ifndef HIGHGUID_TRANSPORT +#define HIGHGUID_TRANSPORT HighGuid::Transport +#endif +#ifndef HIGHGUID_MO_TRANSPORT +#define HIGHGUID_MO_TRANSPORT HighGuid::Mo_Transport +#endif +#ifndef HIGHGUID_VEHICLE +#define HIGHGUID_VEHICLE HighGuid::Vehicle +#endif +#ifndef HIGHGUID_PET +#define HIGHGUID_PET HighGuid::Pet +#endif +#ifndef HIGHGUID_DYNAMICOBJECT +#define HIGHGUID_DYNAMICOBJECT HighGuid::DynamicObject +#endif +#ifndef HIGHGUID_CORPSE +#define HIGHGUID_CORPSE HighGuid::Corpse +#endif +#ifndef HIGHGUID_ITEM +#define HIGHGUID_ITEM HighGuid::Item +#endif +#ifndef HIGHGUID_INSTANCE +#define HIGHGUID_INSTANCE HighGuid::Instance +#endif +#ifndef HIGHGUID_GROUP +#define HIGHGUID_GROUP HighGuid::Group +#endif +#ifndef HIGHGUID_CONTAINER +#define HIGHGUID_CONTAINER HighGuid::Container +#endif #ifndef MAKE_NEW_GUID #define MAKE_NEW_GUID(l, e, h) ObjectGuid(h, e, l) #endif diff --git a/GameObjectMethods.h b/GameObjectMethods.h index e7436e2..c265d6f 100644 --- a/GameObjectMethods.h +++ b/GameObjectMethods.h @@ -157,7 +157,7 @@ namespace LuaGameObject int GetDBTableGUIDLow(Eluna* /*E*/, lua_State* L, GameObject* go) { #ifdef TRINITY - Eluna::Push(L, go->GetDBTableGUIDLow()); + Eluna::Push(L, go->GetSpawnId()); #else // on mangos based this is same as lowguid Eluna::Push(L, go->GetGUIDLow()); diff --git a/GlobalMethods.h b/GlobalMethods.h index adcaccd..9a4fdf1 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -438,12 +438,12 @@ namespace LuaGlobalFunctions * GUID consist of entry ID, low GUID, and type ID. * * @param uint64 guid : GUID of an [Object] - * @return uint32 typeId : type ID of the [Object] + * @return int32 typeId : type ID of the [Object] */ int GetGUIDType(Eluna* /*E*/, lua_State* L) { uint64 guid = Eluna::CHECKVAL(L, 1); - Eluna::Push(L, GUID_HIPART(guid)); + Eluna::Push(L, static_cast(GUID_HIPART(guid))); return 1; } @@ -1632,7 +1632,7 @@ namespace LuaGlobalFunctions if (save) { Creature* creature = new Creature(); - if (!creature->Create(eObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, phase, entry, x, y, z, o)) + if (!creature->Create(map->GenerateLowGuid(), map, phase, entry, x, y, z, o)) { delete creature; Eluna::Push(L); @@ -1641,15 +1641,21 @@ namespace LuaGlobalFunctions creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase); - uint32 db_lowguid = creature->GetDBTableGUIDLow(); - if (!creature->LoadCreatureFromDB(db_lowguid, map)) + uint32 db_guid = creature->GetSpawnId(); + + // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells() + // current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior + creature->CleanupsBeforeDelete(); + delete creature; + creature = new Creature(); + if (!creature->LoadCreatureFromDB(db_guid, map)) { delete creature; Eluna::Push(L); return 1; } - eObjectMgr->AddCreatureToGrid(db_lowguid, eObjectMgr->GetCreatureData(db_lowguid)); + eObjectMgr->AddCreatureToGrid(db_guid, eObjectMgr->GetCreatureData(db_guid)); Eluna::Push(L, creature); } else @@ -1688,9 +1694,9 @@ namespace LuaGlobalFunctions } GameObject* object = new GameObject; - uint32 lowguid = eObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT); + uint32 guidLow = map->GenerateLowGuid(); - if (!object->Create(lowguid, objectInfo->entry, map, phase, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY)) + if (!object->Create(guidLow, objectInfo->entry, map, phase, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY)) { delete object; Eluna::Push(L); @@ -1706,14 +1712,14 @@ namespace LuaGlobalFunctions object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase); // this will generate a new lowguid if the object is in an instance - if (!object->LoadGameObjectFromDB(lowguid, map)) + if (!object->LoadGameObjectFromDB(guidLow, map)) { delete object; Eluna::Push(L); return 1; } - eObjectMgr->AddGameobjectToGrid(lowguid, eObjectMgr->GetGOData(lowguid)); + eObjectMgr->AddGameobjectToGrid(guidLow, eObjectMgr->GetGOData(guidLow)); } else map->AddToMap(object); diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 8bae655..656981a 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -101,6 +101,22 @@ void Eluna::LoadScriptPaths() ELUNA_LOG_DEBUG("[Eluna]: Loaded %u scripts in %u ms", uint32(lua_scripts.size() + lua_extensions.size()), ElunaUtil::GetTimeDiff(oldMSTime)); } +#ifdef TRINITY +class ElunaAIUpdateWorker +{ +public: + void Visit(std::unordered_map& creatureMap) + { + for (auto const& p : creatureMap) + if (p.second->IsInWorld()) + p.second->AIM_Initialize(); + } + + template + void Visit(std::unordered_map&) { } +}; +#endif + void Eluna::_ReloadEluna() { LOCK_ELUNA; @@ -125,12 +141,12 @@ void Eluna::_ReloadEluna() #ifdef TRINITY // Re initialize creature AI restoring C++ AI or applying lua AI + sMapMgr->DoForAllMaps([](Map* map) { - HashMapHolder::MapType const m = ObjectAccessor::GetCreatures(); - for (HashMapHolder::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter) - if (iter->second->IsInWorld()) - iter->second->AIM_Initialize(); - } + ElunaAIUpdateWorker worker; + TypeContainerVisitor visitor(worker); + visitor.Visit(map->GetObjectsStore()); + }); #endif reload = false; diff --git a/MapMethods.h b/MapMethods.h index a39a420..e3d5486 100644 --- a/MapMethods.h +++ b/MapMethods.h @@ -213,25 +213,25 @@ namespace LuaMap switch (GUID_HIPART(guid)) { case HIGHGUID_PLAYER: - Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Player*)NULL)); + Eluna::Push(L, sObjectAccessor->GetPlayer(map, ObjectGuid(guid))); break; case HIGHGUID_TRANSPORT: case HIGHGUID_MO_TRANSPORT: case HIGHGUID_GAMEOBJECT: - Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (GameObject*)NULL)); + Eluna::Push(L, map->GetGameObject(ObjectGuid(guid))); break; case HIGHGUID_VEHICLE: case HIGHGUID_UNIT: - Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Creature*)NULL)); + Eluna::Push(L, map->GetCreature(ObjectGuid(guid))); break; case HIGHGUID_PET: - Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Pet*)NULL)); + Eluna::Push(L, map->GetPet(ObjectGuid(guid))); break; case HIGHGUID_DYNAMICOBJECT: - Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (DynamicObject*)NULL)); + Eluna::Push(L, map->GetDynamicObject(ObjectGuid(guid))); break; case HIGHGUID_CORPSE: - Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Corpse*)NULL)); + Eluna::Push(L, map->GetCorpse(ObjectGuid(guid))); break; default: break; diff --git a/ObjectMethods.h b/ObjectMethods.h index 5dac70b..dfa038a 100644 --- a/ObjectMethods.h +++ b/ObjectMethods.h @@ -182,7 +182,11 @@ namespace LuaObject */ int GetGUIDLow(Eluna* /*E*/, lua_State* L, Object* obj) { +#ifdef TRINITY + Eluna::Push(L, obj->GetGUID().GetCounter()); +#else Eluna::Push(L, obj->GetGUIDLow()); +#endif return 1; } diff --git a/PlayerMethods.h b/PlayerMethods.h index dcc0830..ffc585a 100644 --- a/PlayerMethods.h +++ b/PlayerMethods.h @@ -2157,7 +2157,11 @@ namespace LuaPlayer target->SetSummonPoint(map, x, y, z); WorldPacket data(SMSG_SUMMON_REQUEST, 8 + 4 + 4); +#ifdef TRINITY + data << uint64(player->GetGUID().GetCounter()); +#else data << uint64(player->GetGUIDLow()); +#endif data << uint32(zoneId); data << uint32(delay); target->GetSession()->SendPacket(&data); @@ -2228,7 +2232,11 @@ namespace LuaPlayer return 0; WorldPacket data(MSG_AUCTION_HELLO, 12); +#ifdef TRINITY + data << uint64(unit->GetGUID().GetCounter()); +#else data << uint64(unit->GetGUIDLow()); +#endif data << uint32(ahEntry->houseId); data << uint8(1); player->GetSession()->SendPacket(&data); @@ -2846,7 +2854,7 @@ namespace LuaPlayer // prepare Quest Tracker datas PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_QUEST_TRACK_GM_COMPLETE); stmt->setUInt32(0, quest->GetQuestId()); - stmt->setUInt32(1, player->GetGUIDLow()); + stmt->setUInt32(1, player->GetGUID().GetCounter()); // add to Quest Tracker CharacterDatabase.Execute(stmt);