mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 01:08:35 +00:00
fix(Core/Misc): Memleaks fixes. Part I. (#5546)
This commit is contained in:
@@ -787,7 +787,14 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl
|
||||
if (!map)
|
||||
{
|
||||
LOG_ERROR("server", "Battlefield::SpawnCreature: Can't create creature entry: %u map not found", entry);
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CreatureTemplate const* cinfo = sObjectMgr->GetCreatureTemplate(entry);
|
||||
if (!cinfo)
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Battlefield::SpawnCreature: entry %u does not exist.", entry);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Creature* creature = new Creature(true);
|
||||
@@ -801,12 +808,6 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl
|
||||
creature->setFaction(BattlefieldFactions[teamId]);
|
||||
creature->SetHomePosition(x, y, z, o);
|
||||
|
||||
CreatureTemplate const* cinfo = sObjectMgr->GetCreatureTemplate(entry);
|
||||
if (!cinfo)
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Battlefield::SpawnCreature: entry %u does not exist.", entry);
|
||||
return nullptr;
|
||||
}
|
||||
// force using DB speeds -- do we really need this?
|
||||
creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
|
||||
creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
|
||||
|
||||
@@ -2234,24 +2234,24 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extr
|
||||
}
|
||||
}
|
||||
|
||||
Position* Unit::GetMeleeAttackPoint(Unit* attacker)
|
||||
bool Unit::GetMeleeAttackPoint(Unit* attacker, Position& pos)
|
||||
{
|
||||
if (!attacker)
|
||||
{
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
AttackerSet attackers = getAttackers();
|
||||
|
||||
if (attackers.size() <= 1) // if the attackers are not more than one
|
||||
{
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
float meleeReach = GetExactDist2d(attacker);
|
||||
if (meleeReach <= 0)
|
||||
{
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
float minAngle = 0;
|
||||
@@ -2263,17 +2263,13 @@ Position* Unit::GetMeleeAttackPoint(Unit* attacker)
|
||||
for (const auto& otherAttacker: attackers)
|
||||
{
|
||||
// if the otherAttacker is not valid, skip
|
||||
if (!otherAttacker ||
|
||||
otherAttacker->GetGUID() == attacker->GetGUID() ||
|
||||
!otherAttacker->IsWithinMeleeRange(this) ||
|
||||
otherAttacker->isMoving()
|
||||
)
|
||||
if (!otherAttacker || otherAttacker->GetGUID() == attacker->GetGUID() ||
|
||||
!otherAttacker->IsWithinMeleeRange(this) || otherAttacker->isMoving())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float curretAngle = atan(attacker->GetExactDist2d(otherAttacker) / meleeReach);
|
||||
|
||||
if (minAngle == 0 || curretAngle < minAngle)
|
||||
{
|
||||
minAngle = curretAngle;
|
||||
@@ -2284,7 +2280,9 @@ Position* Unit::GetMeleeAttackPoint(Unit* attacker)
|
||||
}
|
||||
|
||||
if (!validAttackers || !refUnit)
|
||||
return nullptr;
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float contactDist = attackerSize + refUnit->GetCollisionRadius();
|
||||
float requiredAngle = atan(contactDist / meleeReach);
|
||||
@@ -2296,7 +2294,7 @@ Position* Unit::GetMeleeAttackPoint(Unit* attacker)
|
||||
|
||||
if (attackersAngle > angleTollerance)
|
||||
{
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
double angle = atan(contactDist / meleeReach);
|
||||
@@ -2316,11 +2314,13 @@ Position* Unit::GetMeleeAttackPoint(Unit* attacker)
|
||||
|
||||
if (!GetMap()->CanReachPositionAndGetValidCoords(this, x, y, z, true, true))
|
||||
{
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return new Position(x,y,z);
|
||||
pos.Relocate(x, y, z);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Unit::HandleProcExtraAttackFor(Unit* victim)
|
||||
|
||||
@@ -1467,7 +1467,7 @@ public:
|
||||
bool AttackStop();
|
||||
void RemoveAllAttackers();
|
||||
[[nodiscard]] AttackerSet const& getAttackers() const { return m_attackers; }
|
||||
[[nodiscard]] Position* GetMeleeAttackPoint(Unit* attacker);
|
||||
[[nodiscard]] bool GetMeleeAttackPoint(Unit* attacker, Position& pos);
|
||||
[[nodiscard]] bool isAttackingPlayer() const;
|
||||
[[nodiscard]] Unit* GetVictim() const { return m_attacking; }
|
||||
|
||||
|
||||
@@ -423,14 +423,15 @@ void ObjectMgr::LoadGossipMenuItemsLocales()
|
||||
uint16 MenuID = fields[0].GetUInt16();
|
||||
uint16 OptionID = fields[1].GetUInt16();
|
||||
std::string LocaleName = fields[2].GetString();
|
||||
std::string OptionText = fields[3].GetString();
|
||||
std::string BoxText = fields[4].GetString();
|
||||
|
||||
GossipMenuItemsLocale& data = _gossipMenuItemsLocaleStore[MAKE_PAIR32(MenuID, OptionID)];
|
||||
LocaleConstant locale = GetLocaleByName(LocaleName);
|
||||
if (locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
std::string OptionText = fields[3].GetString();
|
||||
std::string BoxText = fields[4].GetString();
|
||||
|
||||
GossipMenuItemsLocale& data = _gossipMenuItemsLocaleStore[MAKE_PAIR32(MenuID, OptionID)];
|
||||
AddLocaleString(OptionText, locale, data.OptionText);
|
||||
AddLocaleString(BoxText, locale, data.BoxText);
|
||||
} while (result->NextRow());
|
||||
|
||||
@@ -3721,23 +3721,23 @@ bool Map::CheckCollisionAndGetValidCoords(const WorldObject* source, float start
|
||||
|
||||
bool isWaterNext = IsInWater(destX, destY, destZ);
|
||||
|
||||
PathGenerator* path = new PathGenerator(source);
|
||||
PathGenerator path(source);
|
||||
|
||||
// Use a detour raycast to get our first collision point
|
||||
path->SetUseRaycast(true);
|
||||
bool result = path->CalculatePath(startX, startY, startZ, destX, destY, destZ, false);
|
||||
path.SetUseRaycast(true);
|
||||
bool result = path.CalculatePath(startX, startY, startZ, destX, destY, destZ, false);
|
||||
|
||||
const Unit* unit = source->ToUnit();
|
||||
bool notOnGround = path->GetPathType() & PATHFIND_NOT_USING_PATH
|
||||
bool notOnGround = path.GetPathType() & PATHFIND_NOT_USING_PATH
|
||||
|| isWaterNext || (unit && unit->IsFlying());
|
||||
|
||||
// Check for valid path types before we proceed
|
||||
if (!result || (!notOnGround && path->GetPathType() & ~(PATHFIND_NORMAL | PATHFIND_SHORTCUT | PATHFIND_INCOMPLETE | PATHFIND_FARFROMPOLY_END)))
|
||||
if (!result || (!notOnGround && path.GetPathType() & ~(PATHFIND_NORMAL | PATHFIND_SHORTCUT | PATHFIND_INCOMPLETE | PATHFIND_FARFROMPOLY_END)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
G3D::Vector3 endPos = path->GetPath().back();
|
||||
G3D::Vector3 endPos = path.GetPath().back();
|
||||
destX = endPos.x;
|
||||
destY = endPos.y;
|
||||
destZ = endPos.z;
|
||||
@@ -3790,7 +3790,9 @@ bool Map::CheckCollisionAndGetValidCoords(const WorldObject* source, float start
|
||||
if (gridHeight > INVALID_HEIGHT)
|
||||
{
|
||||
destZ = gridHeight + unit->GetHoverHeight();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,14 +364,14 @@ void MotionMaster::MoveCircleTarget(Unit* target)
|
||||
return;
|
||||
}
|
||||
|
||||
Position* point = target->GetMeleeAttackPoint(_owner);
|
||||
if (point == nullptr)
|
||||
Position pos;
|
||||
if (!target->GetMeleeAttackPoint(_owner, pos))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Movement::MoveSplineInit init(_owner);
|
||||
init.MoveTo(point->m_positionX, point->m_positionY, point->m_positionZ, false);
|
||||
init.MoveTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), false);
|
||||
init.SetWalk(true);
|
||||
init.SetFacing(target);
|
||||
init.Launch();
|
||||
|
||||
@@ -13,6 +13,15 @@
|
||||
#include "Spell.h"
|
||||
#include "Util.h"
|
||||
|
||||
template<class T>
|
||||
RandomMovementGenerator<T>::~RandomMovementGenerator() { }
|
||||
|
||||
template<>
|
||||
RandomMovementGenerator<Creature>::~RandomMovementGenerator()
|
||||
{
|
||||
delete _pathGenerator;
|
||||
}
|
||||
|
||||
template<>
|
||||
void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature)
|
||||
{
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
for (uint8 i = 0; i < RANDOM_POINTS_NUMBER; ++i)
|
||||
_validPointsVector[RANDOM_POINTS_NUMBER].push_back(i);
|
||||
}
|
||||
~RandomMovementGenerator();
|
||||
|
||||
void _setRandomLocation(T*);
|
||||
void DoInitialize(T*);
|
||||
|
||||
@@ -29,7 +29,7 @@ class ChaseMovementGenerator : public MovementGeneratorMedium<T, ChaseMovementGe
|
||||
public:
|
||||
ChaseMovementGenerator(Unit* target, std::optional<ChaseRange> range = {}, std::optional<ChaseAngle> angle = {})
|
||||
: TargetedMovementGeneratorBase(target), i_path(nullptr), i_recheckDistance(0), i_recalculateTravel(true), _range(range), _angle(angle) {}
|
||||
~ChaseMovementGenerator() {}
|
||||
~ChaseMovementGenerator() { delete i_path; }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() { return CHASE_MOTION_TYPE; }
|
||||
|
||||
@@ -65,7 +65,7 @@ class FollowMovementGenerator : public MovementGeneratorMedium<T, FollowMovement
|
||||
public:
|
||||
FollowMovementGenerator(Unit* target, float range, ChaseAngle angle)
|
||||
: TargetedMovementGeneratorBase(target), i_path(nullptr), i_recheckDistance(0), i_recalculateTravel(true), _range(range), _angle(angle) {}
|
||||
~FollowMovementGenerator() {}
|
||||
~FollowMovementGenerator() { delete i_path; }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() { return FOLLOW_MOTION_TYPE; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user