Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Xfurry <xfurry.cmangos@outlook.com>
  • Loading branch information
xfurry committed Dec 10, 2017
1 parent 50992bc commit 14a9304
Show file tree
Hide file tree
Showing 198 changed files with 6,118 additions and 5,951 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bin
build
tags
TAGS
win
!.gitignore
!.gitattributes
!.travis.yml
Expand Down
4 changes: 2 additions & 2 deletions src/framework/Policies/CreationPolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace MaNGOS
static T* Create()
{
static MaxAlign si_localStatic;
return new(&si_localStatic) T;
return new (&si_localStatic) T;
}

static void Destroy(T* obj)
Expand All @@ -93,7 +93,7 @@ namespace MaNGOS
if (!p)
return nullptr;

return new(p) T;
return new (p) T;
}

static void Destroy(T* p)
Expand Down
8 changes: 4 additions & 4 deletions src/framework/Policies/MemoryManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "../../dep/tbb/include/tbb/scalable_allocator.h"

void* operator new(size_t sz)
void* operator new (size_t sz)
{
void* res = scalable_malloc(sz);

Expand All @@ -42,7 +42,7 @@ void* operator new[](size_t sz)
return res;
}

void operator delete(void* ptr) throw()
void operator delete (void* ptr) throw()
{
scalable_free(ptr);
}
Expand All @@ -52,7 +52,7 @@ void operator delete[](void* ptr) throw()
scalable_free(ptr);
}

void* operator new(size_t sz, const std::nothrow_t&) throw()
void* operator new (size_t sz, const std::nothrow_t&) throw()
{
return scalable_malloc(sz);
}
Expand All @@ -62,7 +62,7 @@ void* operator new[](size_t sz, const std::nothrow_t&) throw()
return scalable_malloc(sz);
}

void operator delete(void* ptr, const std::nothrow_t&) throw()
void operator delete (void* ptr, const std::nothrow_t&) throw()
{
scalable_free(ptr);
}
Expand Down
14 changes: 7 additions & 7 deletions src/game/AI/BaseAI/CreatureAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CreatureAI::CreatureAI(Creature* creature) :

if (m_creature->IsNoAggroOnSight())
SetReactState(REACT_DEFENSIVE);
if(m_creature->IsGuard() || m_unit->GetCharmInfo()) // guards and charmed targets
if (m_creature->IsGuard() || m_unit->GetCharmInfo()) // guards and charmed targets
m_visibilityDistance = sWorld.getConfig(CONFIG_FLOAT_SIGHT_GUARDER);
}

Expand All @@ -65,7 +65,7 @@ CreatureAI::~CreatureAI()
{
}

void CreatureAI::MoveInLineOfSight(Unit * who)
void CreatureAI::MoveInLineOfSight(Unit* who)
{
if (!HasReactState(REACT_AGGRESSIVE))
return;
Expand All @@ -92,7 +92,7 @@ void CreatureAI::MoveInLineOfSight(Unit * who)
}
}

void CreatureAI::EnterCombat(Unit *enemy)
void CreatureAI::EnterCombat(Unit* enemy)
{
if (enemy && (m_creature->IsGuard() || m_creature->IsCivilian()))
{
Expand Down Expand Up @@ -280,9 +280,9 @@ void CreatureAI::HandleMovementOnAttackStart(Unit* victim) const
{
if (!m_unit->hasUnitState(UNIT_STAT_CAN_NOT_REACT))
{
if (m_dismountOnAggro)
if (m_dismountOnAggro)
m_unit->Unmount(); // all ais should unmount here

MotionMaster* creatureMotion = m_unit->GetMotionMaster();

if (!m_unit->hasUnitState(UNIT_STAT_NO_COMBAT_MOVEMENT))
Expand Down Expand Up @@ -317,8 +317,8 @@ void CreatureAI::CheckForHelp(Unit* who, Creature* me, float distance)
else // In non-instanceable creature must belong to same family and faction to attack player.
{
if (me->GetCreatureInfo()->Family == ((Creature*)who)->GetCreatureInfo()->Family &&
me->GetCreatureInfo()->FactionAlliance == ((Creature*)who)->GetCreatureInfo()->FactionAlliance &&
me->GetCreatureInfo()->FactionHorde == ((Creature*)who)->GetCreatureInfo()->FactionHorde)
me->GetCreatureInfo()->FactionAlliance == ((Creature*)who)->GetCreatureInfo()->FactionAlliance &&
me->GetCreatureInfo()->FactionHorde == ((Creature*)who)->GetCreatureInfo()->FactionHorde)
AttackStart(victim);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/AI/BaseAI/CreatureAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class CreatureAI

// Returns friendly unit with the most amount of hp missing from max hp
Unit* DoSelectLowestHpFriendly(float range, float minMissing = 1.f, bool percent = false);

void SetReactState(ReactStates st) { m_reactState = st; }
ReactStates GetReactState() const { return m_reactState; }
bool HasReactState(ReactStates state) const { return (m_reactState == state); }
Expand All @@ -403,7 +403,7 @@ class CreatureAI

// How far a creature can detect in MoveInLineOfSight
float m_visibilityDistance;

bool m_dismountOnAggro;

bool m_meleeEnabled; // If we allow melee auto attack
Expand Down
14 changes: 7 additions & 7 deletions src/game/AI/BaseAI/GameObjectAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ class GameObject;

class GameObjectAI
{
public:
explicit GameObjectAI(GameObject* go);
virtual ~GameObjectAI();
public:
explicit GameObjectAI(GameObject* go);
virtual ~GameObjectAI();

virtual void UpdateAI(const uint32 /*diff*/) {}
virtual void UpdateAI(const uint32 /*diff*/) {}

virtual void OnEventHappened(uint16 /*eventId*/, bool /*activate*/, bool /*resume*/) {}
virtual void OnEventHappened(uint16 /*eventId*/, bool /*activate*/, bool /*resume*/) {}

protected:
GameObject* m_go;
protected:
GameObject* m_go;
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion src/game/AI/BaseAI/GuardAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void GuardAI::MoveInLineOfSight(Unit* who)
else
{
if (m_creature->CanInitiateAttack() && m_creature->CanAttackOnSight(who) &&
(who->IsHostileToPlayers() || m_creature->IsHostileTo(who)) && who->isInAccessablePlaceFor(m_creature))
(who->IsHostileToPlayers() || m_creature->IsHostileTo(who)) && who->isInAccessablePlaceFor(m_creature))
{
float attackRadius = m_creature->GetAttackDistance(who);
if (m_creature->IsWithinDistInMap(who, attackRadius) && m_creature->IsWithinLOSInMap(who))
Expand Down
2 changes: 1 addition & 1 deletion src/game/AI/BaseAI/GuardianAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void GuardianAI::ProcessAction(CreatureEventAI_Action const& action, uint32 rnd,
return;

DEBUG_FILTER_LOG(LOG_FILTER_EVENT_AI_DEV, "GuardianAI: Process action %u (script %u) triggered for %s (invoked by %s)",
action.type, EventId, m_creature->GetGuidStr().c_str(), actionInvoker ? actionInvoker->GetGuidStr().c_str() : "<no invoker>");
action.type, EventId, m_creature->GetGuidStr().c_str(), actionInvoker ? actionInvoker->GetGuidStr().c_str() : "<no invoker>");

CreatureEventAI::ProcessAction(action, rnd, EventId, actionInvoker, AIEventSender);
}
Expand Down
22 changes: 11 additions & 11 deletions src/game/AI/BaseAI/GuardianAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ class Spell;

class GuardianAI : public CreatureEventAI
{
public:
public:

explicit GuardianAI(Creature* creature);
static int Permissible(const Creature* creature);
explicit GuardianAI(Creature* creature);
static int Permissible(const Creature* creature);

//bool IsControllable() const override { return true; }
virtual void JustRespawned() override;
virtual void EnterEvadeMode() override;
virtual void UpdateAI(const uint32 diff) override;
virtual void CombatStop() override;
//bool IsControllable() const override { return true; }
virtual void JustRespawned() override;
virtual void EnterEvadeMode() override;
virtual void UpdateAI(const uint32 diff) override;
virtual void CombatStop() override;

virtual bool ProcessEvent(CreatureEventAIHolder& holder, Unit* actionInvoker = nullptr, Creature* AIEventSender = nullptr) override;
virtual void ProcessAction(CreatureEventAI_Action const& action, uint32 rnd, uint32 eventId, Unit* actionInvoker, Creature* AIEventSender) override;
Unit* DoSelectLowestHpFriendly(float range, uint32 minHPDiff, bool onlyInCombat) const;
virtual bool ProcessEvent(CreatureEventAIHolder& holder, Unit* actionInvoker = nullptr, Creature* AIEventSender = nullptr) override;
virtual void ProcessAction(CreatureEventAI_Action const& action, uint32 rnd, uint32 eventId, Unit* actionInvoker, Creature* AIEventSender) override;
Unit* DoSelectLowestHpFriendly(float range, uint32 minHPDiff, bool onlyInCombat) const;
};
#endif
28 changes: 14 additions & 14 deletions src/game/AI/BaseAI/PetAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ void PetAI::MoveInLineOfSight(Unit* who)
Pet* pet = (m_unit->GetTypeId() == TYPEID_UNIT && static_cast<Creature*>(m_unit)->IsPet()) ? static_cast<Pet*>(m_unit) : nullptr;

if (HasReactState(REACT_AGGRESSIVE)
&& !(pet && pet->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
&& (m_unit->IsHostileTo(who) || who->IsHostileTo(m_unit->GetMaster()))
&& m_creature->CanAttackOnSight(who) && who->isInAccessablePlaceFor(m_unit)
&& m_unit->IsWithinDistInMap(who, m_unit->GetAttackDistance(who))
&& m_unit->GetDistanceZ(who) <= CREATURE_Z_ATTACK_RANGE
&& m_unit->IsWithinLOSInMap(who))
&& !(pet && pet->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
&& (m_unit->IsHostileTo(who) || who->IsHostileTo(m_unit->GetMaster()))
&& m_creature->CanAttackOnSight(who) && who->isInAccessablePlaceFor(m_unit)
&& m_unit->IsWithinDistInMap(who, m_unit->GetAttackDistance(who))
&& m_unit->GetDistanceZ(who) <= CREATURE_Z_ATTACK_RANGE
&& m_unit->IsWithinLOSInMap(who))
{
AttackStart(who);

Expand Down Expand Up @@ -111,7 +111,7 @@ void PetAI::UpdateAI(const uint32 diff)
return;
Creature* creature = (m_unit->GetTypeId() == TYPEID_UNIT) ? static_cast<Creature*>(m_unit) : nullptr;
Pet* pet = (creature && creature->IsPet()) ? static_cast<Pet*>(m_unit) : nullptr;

Unit* owner = m_unit->GetMaster();
if (!owner)
return;
Expand Down Expand Up @@ -150,10 +150,10 @@ void PetAI::UpdateAI(const uint32 diff)
uint32 minRange = charminfo->GetSpellOpenerMinRange();

if (!(victim = m_unit->getVictim())
|| (minRange != 0 && m_unit->IsWithinDistInMap(victim, minRange)))
|| (minRange != 0 && m_unit->IsWithinDistInMap(victim, minRange)))
charminfo->SetSpellOpener();
else if (m_unit->IsWithinDistInMap(victim, charminfo->GetSpellOpenerMaxRange())
&& m_unit->IsWithinLOSInMap(victim))
&& m_unit->IsWithinLOSInMap(victim))
{
// stop moving
m_unit->clearUnitState(UNIT_STAT_MOVING);
Expand Down Expand Up @@ -313,13 +313,13 @@ void PetAI::UpdateAI(const uint32 diff)
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "PetAI (guid = %u) is stopping attack.", m_unit->GetGUIDLow());
m_unit->CombatStop();
inCombat = false;

return;
}

// if pet misses its target, it will also be the first in threat list
if ((!creature || !(creature->GetCreatureInfo()->ExtraFlags & CREATURE_EXTRA_FLAG_NO_MELEE))
&& m_unit->CanReachWithMeleeAttack(victim))
&& m_unit->CanReachWithMeleeAttack(victim))
{
if (!m_unit->HasInArc(victim, 2 * M_PI_F / 3))
{
Expand Down Expand Up @@ -355,8 +355,8 @@ void PetAI::UpdateAI(const uint32 diff)
float stayPosZ = charminfo->GetStayPosZ();

if (m_unit->GetPositionX() == stayPosX
&& m_unit->GetPositionY() == stayPosY
&& m_unit->GetPositionZ() == stayPosZ)
&& m_unit->GetPositionY() == stayPosY
&& m_unit->GetPositionZ() == stayPosZ)
{
float StayPosO = charminfo->GetStayPosO();

Expand All @@ -380,7 +380,7 @@ void PetAI::UpdateAI(const uint32 diff)
}
}
else if (charmInfo && charmInfo->HasCommandState(COMMAND_FOLLOW)
&& !owner->IsWithinDistInMap(m_unit, (PET_FOLLOW_DIST * 2)))
&& !owner->IsWithinDistInMap(m_unit, (PET_FOLLOW_DIST * 2)))
m_unit->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/game/AI/BaseAI/PossessedAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ class Spell;

class PossessedAI : public CreatureAI
{
public:
public:

explicit PossessedAI(Creature* creature) : CreatureAI(creature) {}
explicit PossessedAI(Unit* unit) : CreatureAI(unit) {}
explicit PossessedAI(Creature* creature) : CreatureAI(creature) {}
explicit PossessedAI(Unit* unit) : CreatureAI(unit) {}

static int Permissible(const Creature* /*creature*/) { return PERMIT_BASE_NO; }
static int Permissible(const Creature* /*creature*/) { return PERMIT_BASE_NO; }

//void GetAIInformation(ChatHandler& reader) override;
//void GetAIInformation(ChatHandler& reader) override;

void UpdateAI(const uint32 diff) override
{
DoMeleeAttackIfReady();
}
void UpdateAI(const uint32 diff) override
{
DoMeleeAttackIfReady();
}
};
#endif
28 changes: 14 additions & 14 deletions src/game/AI/EventAI/CreatureEventAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ CreatureEventAI::CreatureEventAI(Creature* creature) : CreatureAI(creature),
if (aiName == "EventAI") // don't show error on GuardiansAI
{
sLog.outErrorEventAI("EventMap for Creature Id: %u, %s is empty but creature is using CreatureEventAI: '%s'.",
m_creature->GetEntry(), m_creature->GetGuidStr().c_str(), aiName.c_str());
m_creature->GetEntry(), m_creature->GetGuidStr().c_str(), aiName.c_str());
}
}
}
Expand Down Expand Up @@ -717,16 +717,16 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
{
switch (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType())
{
case CHASE_MOTION_TYPE:
case FOLLOW_MOTION_TYPE:
m_attackDistance = 0.0f;
m_attackAngle = 0.0f;

m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_attackDistance, m_attackAngle);
break;
default:
break;
case CHASE_MOTION_TYPE:
case FOLLOW_MOTION_TYPE:
m_attackDistance = 0.0f;
m_attackAngle = 0.0f;

m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_attackDistance, m_attackAngle);
break;
default:
break;
}
}
}
Expand Down Expand Up @@ -1419,7 +1419,7 @@ void CreatureEventAI::MoveInLineOfSight(Unit* who)

// if friendly event && who is not hostile OR hostile event && who is hostile
if ((itr->Event.ooc_los.noHostile && !m_creature->IsEnemy(who)) ||
((!itr->Event.ooc_los.noHostile) && m_creature->IsEnemy(who)))
((!itr->Event.ooc_los.noHostile) && m_creature->IsEnemy(who)))
{
// if range is ok and we are actually in LOS
if (m_creature->IsWithinDistInMap(who, fMaxAllowedRange) && m_creature->IsWithinLOSInMap(who))
Expand Down Expand Up @@ -1495,9 +1495,9 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
if (m_creature->IsWithinLOSInMap(victim))
{
if (m_LastSpellMaxRange && m_creature->IsInRange(victim, 0, (m_LastSpellMaxRange / 1.5f)) &&
m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
{
if(IsCombatMovement())
if (IsCombatMovement())
SetCombatMovement(false, true);
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/game/AI/EventAI/CreatureEventAIMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,8 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
{
ScriptMgr::ScriptTemplateVector templateData;
sScriptMgr.GetScriptStringTemplate(action.textNew.templateId, templateData);
for(auto& data : templateData)
if(data.first)
for (auto& data : templateData)
if (data.first)
usedTextIds.insert(data.first);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/AI/ScriptDevAI/PreCompiledHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define PRECOMPILED_H

#ifndef MSVC
#include "pchdef.h"
#include "pchdef.h"
#endif

#include "AI/ScriptDevAI/include/sc_creature.h"
Expand Down
Loading

0 comments on commit 14a9304

Please sign in to comment.