Skip to content

Commit

Permalink
-Internal: Gave WorldPosition and GuidPosition seperate files and rem…
Browse files Browse the repository at this point in the history
…oved unneeded includes.
  • Loading branch information
mostlikely4r committed Dec 19, 2022
1 parent 6d0a3e7 commit bb5241d
Show file tree
Hide file tree
Showing 35 changed files with 1,413 additions and 1,392 deletions.
4 changes: 3 additions & 1 deletion playerbot/FleeManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "TravelMgr.h"
#include "WorldPosition.h"

using namespace std;

Expand All @@ -10,6 +10,8 @@ namespace ai
{
class Engine;



class FleePoint {
public:
FleePoint(PlayerbotAI* ai, float x, float y, float z) : ai(ai), sumDistance(0.0f), minDistance(0.0f) {
Expand Down
162 changes: 162 additions & 0 deletions playerbot/GuidPosition.cpp
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();
}
76 changes: 76 additions & 0 deletions playerbot/GuidPosition.h
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;
}
}
1 change: 1 addition & 0 deletions playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "strategy/values/PositionValue.h"
#include "ServerFacade.h"
#include "TravelMgr.h"
#include "MoveSplineInitArgs.h"
#include "ChatHelper.h"
#include "strategy/values/BudgetValues.h"
#include "Social/SocialMgr.h"
Expand Down
2 changes: 1 addition & 1 deletion playerbot/PlayerbotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "RandomPlayerbotFactory.h"
#include "ServerFacade.h"
#include "AiFactory.h"
#include "TravelMgr.h"

#ifndef MANGOSBOT_ZERO
#ifdef CMANGOS
#include "Arena/ArenaTeam.h"
Expand Down
Loading

0 comments on commit bb5241d

Please sign in to comment.