Skip to content

Commit

Permalink
- Clean up spell facing behavior a bit. Visual target behavior should…
Browse files Browse the repository at this point in the history
… now be a lot smoother.

- Clean up Creature.cpp. NULL -> nullptr, gotta love it.
- Renamed some recently added members of Creature to match code style.
  • Loading branch information
Treeston committed Apr 2, 2016
1 parent ddb5c0b commit 1cf1d4a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 49 deletions.
84 changes: 39 additions & 45 deletions src/server/game/Entities/Creature/Creature.cpp
Expand Up @@ -54,7 +54,7 @@ TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const
if (itr != spellList.end())
return &itr->second;

return NULL;
return nullptr;
}

bool VendorItemData::RemoveItem(uint32 item_id)
Expand All @@ -78,7 +78,7 @@ VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, uint32 extend
for (VendorItemList::const_iterator i = m_items.begin(); i != m_items.end(); ++i)
if ((*i)->item == item_id && (*i)->ExtendedCost == extendedCost)
return *i;
return NULL;
return nullptr;
}

uint32 CreatureTemplate::GetRandomValidModelId() const
Expand Down Expand Up @@ -183,7 +183,7 @@ m_lootRecipient(), m_lootRecipientGroup(0), _skinner(), _pickpocketLootRestore(0
m_respawnDelay(300), m_corpseDelay(60), m_respawnradius(0.0f), m_boundaryCheckTime(2500), m_combatPulseTime(0), m_combatPulseDelay(0), m_reactState(REACT_AGGRESSIVE),
m_defaultMovementType(IDLE_MOTION_TYPE), m_spawnId(0), m_equipmentId(0), m_originalEquipmentId(0), m_AlreadyCallAssistance(false),
m_AlreadySearchedAssistance(false), m_regenHealth(true), m_AI_locked(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),
m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(NULL), m_creatureData(NULL), m_waypointID(0), m_path_id(0), m_formation(NULL)
m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), m_waypointID(0), m_path_id(0), m_formation(nullptr), m_focusSpell(nullptr), m_focusDelay(0)
{
m_regenTimer = CREATURE_REGEN_INTERVAL;
m_valuesCount = UNIT_END;
Expand All @@ -197,16 +197,14 @@ m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(
m_CombatDistance = 0;//MELEE_RANGE;

ResetLootMode(); // restore default loot mode
TriggerJustRespawned = false;
m_TriggerJustRespawned = false;
m_isTempWorldObject = false;
_focusSpell = NULL;
_focusDelay = 0;
}

Creature::~Creature()
{
delete i_AI;
i_AI = NULL;
i_AI = nullptr;

//if (m_uint32Values)
// TC_LOG_ERROR("entities.unit", "Deconstruct Creature Entry = %u", GetEntry());
Expand Down Expand Up @@ -490,9 +488,9 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/)

void Creature::Update(uint32 diff)
{
if (IsAIEnabled && TriggerJustRespawned)
if (IsAIEnabled && m_TriggerJustRespawned)
{
TriggerJustRespawned = false;
m_TriggerJustRespawned = false;
AI()->JustRespawned();
if (m_vehicleKit)
m_vehicleKit->Reset();
Expand Down Expand Up @@ -769,7 +767,7 @@ void Creature::DoFleeToGetAssistance()
float radius = sWorld->getFloatConfig(CONFIG_CREATURE_FAMILY_FLEE_ASSISTANCE_RADIUS);
if (radius >0)
{
Creature* creature = NULL;
Creature* creature = nullptr;

CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()));
Cell cell(p);
Expand Down Expand Up @@ -969,22 +967,22 @@ bool Creature::isCanTrainingAndResetTalentsOf(Player* player) const
Player* Creature::GetLootRecipient() const
{
if (!m_lootRecipient)
return NULL;
return nullptr;
return ObjectAccessor::FindConnectedPlayer(m_lootRecipient);
}

Group* Creature::GetLootRecipientGroup() const
{
if (!m_lootRecipientGroup)
return NULL;
return nullptr;
return sGroupMgr->GetGroupByGUID(m_lootRecipientGroup);
}

void Creature::SetLootRecipient(Unit* unit)
{
// set the player whose group should receive the right
// to loot the creature after it dies
// should be set to NULL after the loot disappears
// should be set to nullptr after the loot disappears

if (!unit)
{
Expand Down Expand Up @@ -1608,7 +1606,7 @@ void Creature::setDeathState(DeathState s)
if (sWorld->getBoolConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY) || isWorldBoss())
SaveRespawnTime();

ReleaseFocus(); // remove spellcast focus (this also clears unit target)
ReleaseFocus(nullptr, false); // remove spellcast focus
SetTarget(ObjectGuid::Empty); // drop target - dead mobs shouldn't ever target things

SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
Expand Down Expand Up @@ -1637,7 +1635,7 @@ void Creature::setDeathState(DeathState s)
//if (IsPet())
// setActive(true);
SetFullHealth();
SetLootRecipient(NULL);
SetLootRecipient(nullptr);
ResetPlayerDamageReq();

UpdateMovementFlags();
Expand Down Expand Up @@ -1717,7 +1715,7 @@ void Creature::Respawn(bool force)
{
//reset the AI to be sure no dirty or uninitialized values will be used till next tick
AI()->Reset();
TriggerJustRespawned = true;//delay event to next tick so all creatures are created on the map before processing
m_TriggerJustRespawned = true;//delay event to next tick so all creatures are created on the map before processing
}

uint32 poolid = GetSpawnId() ? sPoolMgr->IsPartOfAPool<Creature>(GetSpawnId()) : 0;
Expand Down Expand Up @@ -1814,7 +1812,7 @@ bool Creature::isWorldBoss() const
SpellInfo const* Creature::reachWithSpellAttack(Unit* victim)
{
if (!victim)
return NULL;
return nullptr;

for (uint32 i=0; i < CREATURE_MAX_SPELLS; ++i)
{
Expand Down Expand Up @@ -1856,13 +1854,13 @@ SpellInfo const* Creature::reachWithSpellAttack(Unit* victim)
continue;
return spellInfo;
}
return NULL;
return nullptr;
}

SpellInfo const* Creature::reachWithSpellCure(Unit* victim)
{
if (!victim)
return NULL;
return nullptr;

for (uint32 i=0; i < CREATURE_MAX_SPELLS; ++i)
{
Expand Down Expand Up @@ -1903,7 +1901,7 @@ SpellInfo const* Creature::reachWithSpellCure(Unit* victim)
continue;
return spellInfo;
}
return NULL;
return nullptr;
}

// select nearest hostile unit within the given distance (regardless of threat list).
Expand All @@ -1913,7 +1911,7 @@ Unit* Creature::SelectNearestTarget(float dist, bool playerOnly /* = false */) c
Cell cell(p);
cell.SetNoCreate();

Unit* target = NULL;
Unit* target = nullptr;

{
if (dist == 0.0f)
Expand All @@ -1939,7 +1937,7 @@ Unit* Creature::SelectNearestTargetInAttackDistance(float dist) const
Cell cell(p);
cell.SetNoCreate();

Unit* target = NULL;
Unit* target = nullptr;

if (dist > MAX_VISIBILITY_DISTANCE)
{
Expand All @@ -1963,7 +1961,7 @@ Unit* Creature::SelectNearestTargetInAttackDistance(float dist) const

Player* Creature::SelectNearestPlayer(float distance) const
{
Player* target = NULL;
Player* target = nullptr;

Trinity::NearestPlayerInObjectRangeCheck checker(this, distance);
Trinity::PlayerLastSearcher<Trinity::NearestPlayerInObjectRangeCheck> searcher(this, target, checker);
Expand Down Expand Up @@ -2260,7 +2258,7 @@ void Creature::SendZoneUnderAttackMessage(Player* attacker)

WorldPacket data(SMSG_ZONE_UNDER_ATTACK, 4);
data << (uint32)GetAreaId();
sWorld->SendGlobalMessage(&data, NULL, (enemy_team == ALLIANCE ? HORDE : ALLIANCE));
sWorld->SendGlobalMessage(&data, nullptr, (enemy_team == ALLIANCE ? HORDE : ALLIANCE));
}

void Creature::SetInCombatWithZone()
Expand Down Expand Up @@ -2757,13 +2755,13 @@ void Creature::SetTarget(ObjectGuid guid)
bool Creature::FocusTarget(Spell const* focusSpell, WorldObject const* target)
{
// already focused
if (_focusSpell)
if (m_focusSpell)
return false;

if ((!target || target == this) && !focusSpell->GetCastTime()) // instant cast, untargeted (or self-targeted) spell doesn't need any facing updates
return false;

_focusSpell = focusSpell;
m_focusSpell = focusSpell;

// "instant" creature casts that require re-targeting will be delayed by a short moment to prevent facing bugs
bool shouldDelay = false;
Expand Down Expand Up @@ -2799,15 +2797,9 @@ bool Creature::FocusTarget(Spell const* focusSpell, WorldObject const* target)
}
if (shouldDelay)
shouldDelay = !(focusSpell->IsTriggered() || focusSpell->GetCastTime() || focusSpell->GetSpellInfo()->IsChanneled());

}
}

// tell the creature that it should reacquire its current target after the cast is done (this is handled in ::Attack)
// player pets don't need to do this, as they automatically reacquire their target on focus release
if (!IsPet())
MustReacquireTarget();

bool canTurnDuringCast = !focusSpell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST);
// Face the target - we need to do this before the unit state is modified for no-turn spells
if (target)
Expand All @@ -2830,16 +2822,16 @@ bool Creature::IsFocusing(Spell const* focusSpell, bool withDelay)
return false;
}

if (focusSpell && (focusSpell != _focusSpell))
if (focusSpell && (focusSpell != m_focusSpell))
return false;

if (!_focusSpell)
if (!m_focusSpell)
{
if (!withDelay || !_focusDelay)
if (!withDelay || !m_focusDelay)
return false;
if (GetMSTimeDiffToNow(_focusDelay) > 1000) // @todo figure out if we can get rid of this magic number somehow
if (GetMSTimeDiffToNow(m_focusDelay) > 1000) // @todo figure out if we can get rid of this magic number somehow
{
_focusDelay = 0; // save checks in the future
m_focusDelay = 0; // save checks in the future
return false;
}
}
Expand All @@ -2849,23 +2841,25 @@ bool Creature::IsFocusing(Spell const* focusSpell, bool withDelay)

void Creature::ReleaseFocus(Spell const* focusSpell, bool withDelay)
{
if (!_focusSpell)
if (!m_focusSpell)
return;

// focused to something else
if (focusSpell && focusSpell != _focusSpell)
if (focusSpell && focusSpell != m_focusSpell)
return;

if (IsPet() && GetVictim()) // player pets do not use delay system
SetGuidValue(UNIT_FIELD_TARGET, EnsureVictim()->GetGUID());
if (IsPet()) // player pets do not use delay system
SetGuidValue(UNIT_FIELD_TARGET, GetVictim() ? EnsureVictim()->GetGUID() : ObjectGuid::Empty);
else
SetGuidValue(UNIT_FIELD_TARGET, ObjectGuid::Empty);
// tell the creature that it should reacquire its actual target after the delay expires (this is handled in ::Attack)
// player pets don't need to do this, as they automatically reacquire their target on focus release
MustReacquireTarget();

if (_focusSpell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST))
if (m_focusSpell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST))
ClearUnitState(UNIT_STATE_CANNOT_TURN);

_focusSpell = nullptr;
_focusDelay = (!IsPet() && withDelay) ? getMSTime() : 0; // don't allow re-target right away to prevent visual bugs
m_focusSpell = nullptr;
m_focusDelay = (!IsPet() && withDelay) ? getMSTime() : 0; // don't allow re-target right away to prevent visual bugs
}

void Creature::StartPickPocketRefillTimer()
Expand Down
6 changes: 3 additions & 3 deletions src/server/game/Entities/Creature/Creature.h
Expand Up @@ -746,10 +746,10 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma

//Formation var
CreatureGroup* m_formation;
bool TriggerJustRespawned;
bool m_TriggerJustRespawned;

Spell const* _focusSpell; ///> Locks the target during spell cast for proper facing
uint32 _focusDelay;
Spell const* m_focusSpell; ///> Locks the target during spell cast for proper facing
uint32 m_focusDelay;

CreatureTextRepeatGroup m_textRepeat;
};
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Unit/Unit.h
Expand Up @@ -1276,7 +1276,7 @@ class TC_GAME_API Unit : public WorldObject
void _removeAttacker(Unit* pAttacker); // must be called only from Unit::AttackStop()
Unit* getAttackerForHelper() const; // If someone wants to help, who to give them
bool Attack(Unit* victim, bool meleeAttack);
void MustReacquireTarget() { m_shouldReacquireTarget = true; } // flags the Unit for forced target reacquisition in the next ::Attack call
void MustReacquireTarget() { m_shouldReacquireTarget = true; } // flags the Unit for forced (client displayed) target reacquisition in the next ::Attack call
void CastStop(uint32 except_spellid = 0);
bool AttackStop();
void RemoveAllAttackers();
Expand Down

0 comments on commit 1cf1d4a

Please sign in to comment.