Skip to content

Commit

Permalink
Battleground: Codestyle changes for battleground adjacent code
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Sep 10, 2024
1 parent 713cc7c commit 3092e1d
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/game/BattleGround/BattleGroundMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ void BattleGroundMgr::ScheduleQueueUpdate(uint32 arenaRating, ArenaType arenaTyp
{
// std::lock_guard<std::mutex> guard(SchedulerLock);
// we will use only 1 number created of bgTypeId and bracket_id
uint64 schedule_id = ((uint64)arenaRating << 32) | (arenaType << 24) | (bgQueueTypeId << 16) | (bgTypeId << 8) | bracketId;
uint64 schedule_id = (uint64(arenaRating) << 32) | (uint64(arenaType) << 24) | (uint64(bgQueueTypeId) << 16) | (uint64(bgTypeId) << 8) | bracketId;
bool found = false;
for (unsigned long long i : m_queueUpdateScheduler)
{
Expand Down
5 changes: 2 additions & 3 deletions src/game/Entities/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,10 +1539,10 @@ void GameObject::Use(Unit* user, SpellEntry const* spellInfo)
if (goInfo->trap.charges > 0)
AddUse();

if (IsBattleGroundTrap && user->GetTypeId() == TYPEID_PLAYER)
if (IsBattleGroundTrap && user->IsPlayer())
{
// BattleGround gameobjects case
if (BattleGround* bg = ((Player*)user)->GetBattleGround())
if (BattleGround* bg = static_cast<Player*>(user)->GetBattleGround())
bg->HandleTriggerBuff(GetObjectGuid());
}

Expand All @@ -1553,7 +1553,6 @@ void GameObject::Use(Unit* user, SpellEntry const* spellInfo)
if (goInfo->ExtraFlags & GAMEOBJECT_EXTRA_FLAG_CUSTOM_ANIM_ON_USE)
SendGameObjectCustomAnim(GetObjectGuid());

// TODO: Despawning of traps? (Also related to code in ::Update)
return;
}
case GAMEOBJECT_TYPE_CHAIR: // 7 Sitting: Wooden bench, chairs
Expand Down
2 changes: 1 addition & 1 deletion src/game/Entities/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20022,7 +20022,7 @@ BattleGround* Player::GetBattleGround() const
if (GetBattleGroundId() == 0)
return nullptr;

return sBattleGroundMgr.GetBattleGround(GetBattleGroundId(), m_bgData.bgTypeID);
return GetMap()->GetBG();
}

bool Player::InArena() const
Expand Down
10 changes: 5 additions & 5 deletions src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,12 +1025,12 @@ uint32 Unit::DealDamage(Unit* dealer, Unit* victim, uint32 damage, CleanDamage c
duel_hasEnded = true;
}

if (dealer->GetTypeId() == TYPEID_PLAYER && dealer != victim)
if (dealer->IsPlayer() && dealer != victim)
{
Player* killer = static_cast<Player*>(dealer);

// in bg, count dmg if victim is also a player
if (victim->GetTypeId() == TYPEID_PLAYER)
if (victim->IsPlayer())
{
if (BattleGround* bg = killer->GetBattleGround())
{
Expand Down Expand Up @@ -7206,10 +7206,10 @@ int32 Unit::DealHeal(Unit* pVictim, uint32 addhealth, SpellEntry const* spellPro

unit->SendHealSpellLog(pVictim, spellProto->Id, addhealth, critical);

if (unit->GetTypeId() == TYPEID_PLAYER)
if (unit->IsPlayer())
{
if (BattleGround* bg = ((Player*)unit)->GetBattleGround())
bg->UpdatePlayerScore((Player*)unit, SCORE_HEALING_DONE, gain);
if (BattleGround* bg = static_cast<Player*>(unit)->GetBattleGround())
bg->UpdatePlayerScore(static_cast<Player*>(unit), SCORE_HEALING_DONE, gain);
}

// Script Event HealedBy
Expand Down
2 changes: 1 addition & 1 deletion src/game/Grids/ObjectGridLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ template<> void addUnitState(Creature* obj, CellPair const& cell_pair)
template <class T>
void LoadHelper(CellGuidSet const& guid_set, CellPair& cell, GridRefManager<T>& /*m*/, uint32& count, Map* map, GridType& grid)
{
BattleGround* bg = map->IsBattleGroundOrArena() ? ((BattleGroundMap*)map)->GetBG() : nullptr;
BattleGround* bg = map->GetBG();

for (uint32 guid : guid_set)
{
Expand Down
4 changes: 3 additions & 1 deletion src/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ class Map : public GridRefManager<NGridType>
WorldStateVariableManager& GetVariableManager() { return m_variableManager; }
WorldStateVariableManager const& GetVariableManager() const { return m_variableManager; }

virtual BattleGround* GetBG() const { return nullptr; }

// debug
std::set<ObjectGuid> m_objRemoveList; // this will eventually eat up too much memory - only used for debugging VisibleNotifier::Notify() customlog leak

Expand Down Expand Up @@ -622,7 +624,7 @@ class BattleGroundMap : public Map
void UnloadAll(bool pForce) override;

virtual void InitVisibilityDistance() override;
BattleGround* GetBG() const { return m_bg; }
BattleGround* GetBG() const override { return m_bg; }
void SetBG(BattleGround* bg) { m_bg = bg; }

// can't be nullptr for loaded map
Expand Down
4 changes: 2 additions & 2 deletions src/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4871,8 +4871,8 @@ SpellCastResult Spell::CheckCast(bool strict)
return SPELL_FAILED_NOT_STANDING;

// only allow triggered spells if at an ended battleground
if (!m_IsTriggeredSpell && m_caster->GetTypeId() == TYPEID_PLAYER)
if (BattleGround* bg = ((Player*)m_caster)->GetBattleGround())
if (!m_IsTriggeredSpell && m_caster->IsPlayer())
if (BattleGround* bg = static_cast<Player*>(m_caster)->GetBattleGround())
if (bg->GetStatus() == STATUS_WAIT_LEAVE)
return SPELL_FAILED_DONT_REPORT;

Expand Down
6 changes: 3 additions & 3 deletions src/game/Spells/SpellAuras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6916,9 +6916,9 @@ void Aura::PeriodicTick()
uint32 procEx = PROC_EX_NORMAL_HIT | PROC_EX_INTERNAL_HOT;

// add HoTs to amount healed in bgs
if (pCaster->GetTypeId() == TYPEID_PLAYER)
if (BattleGround* bg = ((Player*)pCaster)->GetBattleGround())
bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
if (pCaster->IsPlayer())
if (BattleGround* bg = static_cast<Player*>(pCaster)->GetBattleGround())
bg->UpdatePlayerScore(static_cast<Player*>(pCaster), SCORE_HEALING_DONE, gain);

if (pCaster->IsInCombat() && !pCaster->IsCrowdControlled())
target->getHostileRefManager().threatAssist(pCaster, float(gain) * 0.5f * sSpellMgr.GetSpellThreatMultiplier(spellProto), spellProto, false, true);
Expand Down
4 changes: 2 additions & 2 deletions src/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2461,8 +2461,8 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx)
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return;

if (BattleGround* bg = ((Player*)m_caster)->GetBattleGround())
bg->HandlePlayerDroppedFlag((Player*)m_caster);
if (BattleGround* bg = static_cast<Player*>(m_caster)->GetBattleGround())
bg->HandlePlayerDroppedFlag(static_cast<Player*>(m_caster));

m_caster->CastSpell(m_caster, 30452, TRIGGERED_OLD_TRIGGERED, nullptr);
return;
Expand Down
3 changes: 1 addition & 2 deletions src/game/Spells/SpellMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2473,8 +2473,7 @@ SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const* spell
if (!player)
return SPELL_FAILED_REQUIRES_AREA;
BattleGround* bg = player->GetBattleGround();
return map_id == 30 && bg
&& bg->GetStatus() != STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
return map_id == 30 && bg && bg->GetStatus() != STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
}
case 2584: // Waiting to Resurrect
case 42792: // Recently Dropped Flag
Expand Down

0 comments on commit 3092e1d

Please sign in to comment.