forked from ike3/mangosbot-bots
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Internal: Gave WorldPosition and GuidPosition seperate files and rem…
…oved unneeded includes.
- Loading branch information
1 parent
6d0a3e7
commit bb5241d
Showing
35 changed files
with
1,413 additions
and
1,392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#pragma once | ||
|
||
#include "GuidPosition.h" | ||
#include <numeric> | ||
#include <iomanip> | ||
|
||
#include "GameEvents/GameEventMgr.h" | ||
|
||
using namespace ai; | ||
using namespace MaNGOS; | ||
|
||
Creature* GuidPosition::GetCreature() const | ||
{ | ||
if (!*this) | ||
return nullptr; | ||
|
||
return getMap()->GetAnyTypeCreature(*this); | ||
} | ||
|
||
Unit* GuidPosition::GetUnit() const | ||
{ | ||
if (!*this) | ||
return nullptr; | ||
|
||
if (IsPlayer()) | ||
return sObjectAccessor.FindPlayer(*this); | ||
|
||
return GetCreature(); | ||
} | ||
|
||
GameObject* GuidPosition::GetGameObject() | ||
{ | ||
if (!*this) | ||
return nullptr; | ||
|
||
return getMap()->GetGameObject(*this); | ||
} | ||
|
||
Player* GuidPosition::GetPlayer() const | ||
{ | ||
if (!*this) | ||
return nullptr; | ||
|
||
if (IsPlayer()) | ||
return sObjectAccessor.FindPlayer(*this); | ||
|
||
return nullptr; | ||
} | ||
|
||
const FactionTemplateEntry* GuidPosition::GetFactionTemplateEntry() const | ||
{ | ||
if (IsPlayer() && GetPlayer()) | ||
return GetPlayer()->GetFactionTemplateEntry(); | ||
if (IsCreature() && IsCreature()) | ||
return sFactionTemplateStore.LookupEntry(GetCreatureTemplate()->Faction); | ||
|
||
return nullptr; | ||
} | ||
|
||
const ReputationRank GuidPosition::GetReactionTo(const GuidPosition& other) | ||
{ | ||
if(other.IsUnit() && other.GetUnit()) | ||
if (other.GetUnit()->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED)) | ||
{ | ||
if (const Player* unitPlayer = other.GetUnit()->GetControllingPlayer()) | ||
{ | ||
if (unitPlayer->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP) && GetFactionTemplateEntry()->IsContestedGuardFaction()) | ||
return REP_HOSTILE; | ||
|
||
if (const ReputationRank* rank = unitPlayer->GetReputationMgr().GetForcedRankIfAny(GetFactionTemplateEntry())) | ||
return (*rank); | ||
|
||
#ifdef MANGOSBOT_ZERO | ||
const FactionEntry* unitFactionEntry = sFactionStore.LookupEntry(GetFactionTemplateEntry()->faction); | ||
return unitPlayer->GetReputationMgr().IsAtWar(unitFactionEntry) ? REP_HOSTILE : REP_FRIENDLY; | ||
#else | ||
if (!other.GetUnit()->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_IGNORE_REPUTATION)) | ||
{ | ||
#ifdef MANGOSBOT_TWO | ||
const FactionEntry* thisFactionEntry = sFactionStore.LookupEntry(GetFactionTemplateEntry()->faction); | ||
#else | ||
const FactionEntry* thisFactionEntry = sFactionStore.LookupEntry<FactionEntry>(GetFactionTemplateEntry()->faction); | ||
#endif | ||
if (thisFactionEntry && thisFactionEntry->HasReputation()) | ||
{ | ||
const ReputationMgr& reputationMgr = unitPlayer->GetReputationMgr(); | ||
return reputationMgr.GetRank(thisFactionEntry); | ||
} | ||
} | ||
#endif | ||
} | ||
} | ||
|
||
return PlayerbotAI::GetFactionReaction(GetFactionTemplateEntry(), other.GetFactionTemplateEntry()); | ||
} | ||
|
||
bool GuidPosition::isDead() | ||
{ | ||
if (!getMap()) | ||
return false; | ||
|
||
if (!getMap()->IsLoaded(getX(), getY())) | ||
return false; | ||
|
||
if (IsUnit() && GetUnit() && GetUnit()->IsInWorld() && GetUnit()->IsAlive()) | ||
return false; | ||
|
||
if (IsGameObject() && GetGameObject() && GetGameObject()->IsInWorld()) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
uint16 GuidPosition::IsPartOfAPool() | ||
{ | ||
if (IsCreature()) | ||
return sPoolMgr.IsPartOfAPool<Creature>(GetCounter()); | ||
if (IsGameObject()) | ||
return sPoolMgr.IsPartOfAPool<GameObject>(GetCounter()); | ||
|
||
return 0; | ||
} | ||
|
||
uint16 GuidPosition::GetGameEventId() | ||
{ | ||
if (uint16 pool_id = IsPartOfAPool()) | ||
{ | ||
uint16 top_pool_id = sPoolMgr.IsPartOfTopPool<Pool>(pool_id); | ||
|
||
if (int16 event_id = sGameEventMgr.GetGameEventId<Pool>(top_pool_id)) | ||
return event_id; | ||
} | ||
|
||
if (IsCreature()) | ||
return sGameEventMgr.GetGameEventId<Creature>(GetCounter()); | ||
if (IsGameObject()) | ||
return sGameEventMgr.GetGameEventId<GameObject>(GetCounter()); | ||
|
||
return 0; | ||
} | ||
|
||
bool GuidPosition::IsEventUnspawned() | ||
{ | ||
if (int16 event_id = GetGameEventId()) | ||
if (!sGameEventMgr.IsActiveEvent(event_id)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
string GuidPosition::print() | ||
{ | ||
ostringstream out; | ||
out << this; | ||
out << mapid << std::fixed << std::setprecision(2); | ||
out << ';' << coord_x; | ||
out << ';' << coord_y; | ||
out << ';' << coord_z; | ||
out << ';' << orientation; | ||
|
||
return out.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#pragma once | ||
|
||
#include "WorldPosition.h" | ||
|
||
namespace ai | ||
{ | ||
class GuidPosition : public ObjectGuid, public WorldPosition | ||
{ | ||
public: | ||
GuidPosition() : ObjectGuid(), WorldPosition() {} | ||
GuidPosition(ObjectGuid guid) { ObjectGuid::Set(guid); WorldPosition::set(guid); }; | ||
GuidPosition(ObjectGuid guid, WorldPosition pos) : ObjectGuid(guid), WorldPosition(pos) {}; | ||
GuidPosition(uint64 const& guid, WorldPosition const& pos) : ObjectGuid(guid), WorldPosition(pos) {}; | ||
//template<class T> | ||
//GuidPosition(ObjectGuid guid, T) : ObjectGuid(guid) {WorldPosition::set(WorldPosition(T))}; | ||
GuidPosition(CreatureDataPair const* dataPair) : ObjectGuid(HIGHGUID_UNIT, dataPair->second.id, dataPair->first), WorldPosition(dataPair) {}; | ||
GuidPosition(GameObjectDataPair const* dataPair) : ObjectGuid(HIGHGUID_GAMEOBJECT, dataPair->second.id, dataPair->first), WorldPosition(dataPair) {}; | ||
GuidPosition(WorldObject* wo) : WorldPosition(wo) { ObjectGuid::Set(wo->GetObjectGuid()); }; | ||
GuidPosition(HighGuid hi, uint32 entry, uint32 counter = 1, WorldPosition pos = WorldPosition()) : ObjectGuid(hi, entry, counter), WorldPosition(pos) {}; | ||
//GuidPosition(const GuidPosition& guidp) {this->Set(guidp); this->setLocation(((WorldPosition)guidp).getLocation()); }; | ||
|
||
CreatureData* GetCreatureData() { return IsCreature() ? sObjectMgr.GetCreatureData(GetCounter()) : nullptr; } | ||
CreatureInfo const* GetCreatureTemplate()const {return IsCreature() ? sObjectMgr.GetCreatureTemplate(GetEntry()) : nullptr; }; | ||
|
||
GameObjectInfo const* GetGameObjectInfo() { return IsGameObject() ? sObjectMgr.GetGameObjectInfo(GetEntry()) : nullptr; }; | ||
|
||
WorldObject* GetWorldObject() { return getMap() ? getMap()->GetWorldObject(*this) : nullptr;} | ||
Creature* GetCreature() const; | ||
Unit* GetUnit() const; | ||
GameObject* GetGameObject(); | ||
Player* GetPlayer() const; | ||
|
||
bool HasNpcFlag(NPCFlags flag) { return IsCreature() && GetCreatureTemplate()->NpcFlags & flag; } | ||
bool isGoType(GameobjectTypes type) { return IsGameObject() && GetGameObjectInfo()->type == type; } | ||
|
||
const FactionTemplateEntry* GetFactionTemplateEntry() const; | ||
const ReputationRank GetReactionTo(const GuidPosition& other); | ||
bool IsFriendlyTo(const GuidPosition& other) { return (GetFactionTemplateEntry() && other.GetFactionTemplateEntry()) ? (GetReactionTo(other) > REP_NEUTRAL) : false; } | ||
bool IsHostileTo(const GuidPosition& other) { return (GetFactionTemplateEntry() && other.GetFactionTemplateEntry()) ? (GetReactionTo(other) < REP_NEUTRAL) : false; } | ||
|
||
bool isDead(); //For loaded grids check if the unit/object is unloaded/dead. | ||
|
||
uint16 IsPartOfAPool(); | ||
uint16 GetGameEventId(); | ||
bool IsEventUnspawned(); | ||
|
||
virtual string print(); | ||
|
||
operator bool() const { return WorldPosition(*this) && !IsEmpty(); } | ||
bool operator== (ObjectGuid const& guid) const { return GetRawValue() == guid.GetRawValue(); } | ||
bool operator!= (ObjectGuid const& guid) const { return GetRawValue() != guid.GetRawValue(); } | ||
bool operator< (ObjectGuid const& guid) const { return GetRawValue() < guid.GetRawValue(); } | ||
}; | ||
|
||
inline ByteBuffer& operator<<(ByteBuffer& b, GuidPosition& guidP) | ||
{ | ||
b << (ObjectGuid)guidP; | ||
b << (WorldPosition)guidP; | ||
|
||
|
||
return b; | ||
} | ||
|
||
inline ByteBuffer& operator>>(ByteBuffer& b, GuidPosition& g) | ||
{ | ||
ObjectGuid guid; | ||
WorldPosition pos; | ||
|
||
b >> guid; | ||
b >> pos; | ||
|
||
g = GuidPosition(guid, pos); | ||
|
||
return b; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.