Skip to content

Commit

Permalink
Some more code cleanup and refactoring (vmangos#2842)
Browse files Browse the repository at this point in the history
  • Loading branch information
schell244 authored Dec 20, 2024
1 parent f936d42 commit ae61d73
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 78 deletions.
5 changes: 3 additions & 2 deletions src/game/Battlegrounds/BattleGround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,10 @@ uint32 BattleGround::GetBonusHonorFromKill(uint32 kills) const
return kills * (uint32)MaNGOS::Honor::GetHonorGain(GetMaxLevel(), GetMaxLevel(), 1);
}

float BattleGround::GetHonorModifier() {
float BattleGround::GetHonorModifier() const
{
// If the game ends in under one hour, less Bonus Honor will be earned from control of mines, graveyards and for the General kill (win).
float elapsed = (float)GetStartTime() / IN_MILLISECONDS / HOUR;
float const elapsed = (float)GetStartTime() / (float)IN_MILLISECONDS / (float)HOUR;
return elapsed < 1.0f ? pow(60, elapsed - 1) : 1.0f;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/Battlegrounds/BattleGround.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class BattleGround
BattleGroundWinner GetWinner() const { return m_winner; }
uint32 GetBattlemasterEntry() const;
uint32 GetBonusHonorFromKill(uint32 kills) const;
float GetHonorModifier();
float GetHonorModifier() const;

// Set methods:
void SetName(char const* name) { m_name = name; }
Expand Down
1 change: 0 additions & 1 deletion src/game/LootMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class LootTemplate::LootGroup // A set of loot def
float TotalChance() const; // Overall chance for the group

void Verify(LootStore const& lootstore, uint32 id, uint32 group_id) const;
void CollectLootIds(LootIdSet& set) const;
void CheckLootRefs(LootIdSet* ref_set) const;
private:
LootStoreItemList ExplicitlyChanced; // Entries with chances defined in DB
Expand Down
4 changes: 2 additions & 2 deletions src/game/LootMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class LootTemplate
public:
// Adds an entry to the group (at loading stage)
void AddEntry(LootStoreItem& item);
// Rolls for every item in the template and adds the rolled items the the loot
// Rolls for every item in the template and adds the rolled items to the loot
void Process(Loot& loot, LootStore const& store, bool rate, uint8 GroupId = 0) const;

// True if template includes at least 1 quest drop entry
Expand All @@ -238,7 +238,7 @@ class LootTemplate
class LootValidatorRef : public Reference<Loot, LootValidatorRef>
{
public:
LootValidatorRef() {}
LootValidatorRef() = default;
void targetObjectDestroyLink() override {}
void sourceObjectDestroyLink() override {}
};
Expand Down
2 changes: 1 addition & 1 deletion src/game/Maps/MapPersistentStateMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ struct DungeonResetEvent
DungeonResetEvent(ResetEventType t, uint32 _mapid, uint32 _instanceid)
: type(t), mapId(_mapid), instanceId(_instanceid) {}

bool operator == (DungeonResetEvent const& e) { return e.mapId == mapId && e.instanceId == instanceId; }
bool operator==(DungeonResetEvent const& e) const { return e.mapId == mapId && e.instanceId == instanceId; }
};

typedef std::map<uint32, std::pair<uint32, time_t> > ResetTimeMapType;
Expand Down
4 changes: 2 additions & 2 deletions src/game/Maps/ZoneScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void ZoneScriptMgr::HandlePlayerLeaveZone(Player* plr, uint32 zoneid)
//sLog.Out(LOG_BASIC, LOG_LVL_DEBUG, "Player %u left ZoneScript", plr->GetGUIDLow());
}

ZoneScript * ZoneScriptMgr::GetZoneScriptToZoneId(uint32 zoneid)
ZoneScript* ZoneScriptMgr::GetZoneScriptToZoneId(uint32 zoneid)
{
ZoneScriptsMap::iterator itr = m_ZoneScriptsMap.find(zoneid);
if (itr == m_ZoneScriptsMap.end())
Expand Down Expand Up @@ -135,7 +135,7 @@ bool ZoneScriptMgr::HandleCustomSpell(Player* plr, uint32 spellId, GameObject* g
return false;
}

ZoneScript * ZoneScriptMgr::GetZoneScript(uint32 zoneId)
ZoneScript* ZoneScriptMgr::GetZoneScript(uint32 zoneId)
{
ZoneScriptsMap::iterator itr = m_ZoneScriptsMap.find(zoneId);
if (itr != m_ZoneScriptsMap.end())
Expand Down
4 changes: 2 additions & 2 deletions src/game/Maps/ZoneScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class ZoneScriptMgr
void HandlePlayerLeaveZone(Player* plr, uint32 areaflag);

// return assigned outdoor pvp
ZoneScript * GetZoneScriptToZoneId(uint32 zoneid);
ZoneScript* GetZoneScriptToZoneId(uint32 zoneid);

// handle custom (non-exist in dbc) spell if registered
bool HandleCustomSpell(Player* plr, uint32 spellId, GameObject* go);

// handle custom go if registered
bool HandleOpenGo(Player* plr, uint64 guid);

ZoneScript * GetZoneScript(uint32 zoneId);
ZoneScript* GetZoneScript(uint32 zoneId);

void AddZone(uint32 zoneid, ZoneScript * handle);

Expand Down
19 changes: 7 additions & 12 deletions src/game/ObjectGuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,14 @@ class ObjectGuid
uint64 m_guid;
};

namespace std {

template <>
struct hash<ObjectGuid>
template <>
struct std::hash<ObjectGuid>
{
std::size_t operator()(ObjectGuid const& k) const
{
std::size_t operator()(ObjectGuid const& k) const
{
using std::hash;
return hash<uint64>()(k.GetRawValue());
}
};

}
return std::hash<uint64>()(k.GetRawValue());
}
};

typedef std::unordered_set<ObjectGuid> ObjectGuidSet;
typedef std::list<ObjectGuid> GuidList;
Expand Down
2 changes: 1 addition & 1 deletion src/game/Objects/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Creature::Creature(CreatureSubtype subtype) :

Creature::~Creature()
{
CleanupsBeforeDelete();
Unit::CleanupsBeforeDelete();

m_vendorItemCounts.clear();

Expand Down
12 changes: 6 additions & 6 deletions src/game/Objects/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct CreatureCreatePos
class ThreatListProcesser
{
public:
ThreatListProcesser() {}
virtual ~ThreatListProcesser() {}
ThreatListProcesser() = default;
virtual ~ThreatListProcesser() = default;
virtual bool Process(Unit* unit) = 0;
};

Expand Down Expand Up @@ -126,7 +126,7 @@ class Creature : public Unit
void SaveHomePosition() { SetHomePosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); }
void SetHomePosition(float x, float y, float z, float o);
void GetHomePosition(float &x, float &y, float &z, float &o);
Position const& GetHomePosition() { return m_homePosition; }
Position const& GetHomePosition() const { return m_homePosition; }
float GetHomePositionO() const { return m_homePosition.o; }
void ResetHomePosition();

Expand All @@ -141,12 +141,12 @@ class Creature : public Unit
void SetDefaultValuesFromStaticFlags();

CreatureSubtype GetSubtype() const { return m_subtype; }
bool IsPet() const { return m_subtype == CREATURE_SUBTYPE_PET; }
bool IsPet() const override { return m_subtype == CREATURE_SUBTYPE_PET; }
bool IsTotem() const { return m_subtype == CREATURE_SUBTYPE_TOTEM; }
Totem const* ToTotem() const { return IsTotem() ? reinterpret_cast<Totem const*>(this) : nullptr; }
Totem* ToTotem() { return IsTotem() ? reinterpret_cast<Totem*>(this) : nullptr; }
bool IsTemporarySummon() const { return m_subtype == CREATURE_SUBTYPE_TEMPORARY_SUMMON; }
bool IsCorpse() const { return GetDeathState() == CORPSE; }
bool IsCorpse() const override { return GetDeathState() == CORPSE; }
bool IsDespawned() const { return GetDeathState() == DEAD; }
void SetCorpseDelay(uint32 delay) { m_corpseDelay = delay; }
bool IsRacialLeader() const { return GetCreatureInfo()->racial_leader; }
Expand Down Expand Up @@ -272,7 +272,7 @@ class Creature : public Unit
bool FallGround();

bool LoadFromDB(uint32 guid, Map* map, bool force = false);
void SaveToDB();
virtual void SaveToDB();
// overwrited in Pet
virtual void SaveToDB(uint32 mapid);
virtual void DeleteFromDB(); // overwrited in Pet
Expand Down
10 changes: 5 additions & 5 deletions src/game/Objects/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,19 @@ class Object
SpellCaster* ToSpellCaster();
SpellCaster const* ToSpellCaster() const;

inline bool IsCorpse() const { return GetTypeId() == TYPEID_CORPSE; }
virtual inline bool IsCorpse() const { return GetTypeId() == TYPEID_CORPSE; }
Corpse* ToCorpse();
Corpse const* ToCorpse() const;

bool IsPet() const;
virtual bool IsPet() const;
Pet* ToPet();
Pet const* ToPet() const;

virtual bool HasQuest(uint32 /* quest_id */) const { return false; }
virtual bool HasInvolvedQuest(uint32 /* quest_id */) const { return false; }
protected:

Object ();
Object();

void _InitValues();
void _Create (uint32 guidlow, uint32 entry, HighGuid guidhigh);
Expand Down Expand Up @@ -651,7 +651,7 @@ class WorldObject : public Object
bool IsFlying() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_FLYING); }
bool IsWalking() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_WALK_MODE); }
bool IsWalkingBackward() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_BACKWARD); }
bool IsMoving() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_MASK_MOVING); }
virtual bool IsMoving() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_MASK_MOVING); }
bool IsSwimming() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_SWIMMING); }
bool IsMovingButNotWalking() const { return IsMoving() && !(IsWalking() || IsWalkingBackward()); }

Expand Down Expand Up @@ -744,7 +744,7 @@ class WorldObject : public Object
bool HasMMapsForCurrentMap() const;

void SetZoneScript();
ZoneScript* GetZoneScript() const { return m_zoneScript; }
virtual ZoneScript* GetZoneScript() const { return m_zoneScript; }

void AddToClientUpdateList() override;
void RemoveFromClientUpdateList() override;
Expand Down
2 changes: 1 addition & 1 deletion src/game/Objects/Pet.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class Pet : public Creature
void CastPetAuras(bool current);
void CastPetAura(PetAura const* aura);

virtual void RemoveAllCooldowns(bool sendOnly = false) override;
void RemoveAllCooldowns(bool sendOnly = false) override;

void _LoadSpellCooldowns();
void _SaveSpellCooldowns();
Expand Down
24 changes: 12 additions & 12 deletions src/game/Objects/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ SpellAuraHolder const* Player::GetMirrorTimerBuff(MirrorTimer::Type timer) const
}
}

bool Player::IsCityProtector() { return m_ExtraFlags & PLAYER_EXTRA_CITY_PROTECTOR; }
bool Player::IsCityProtector() const { return m_ExtraFlags & PLAYER_EXTRA_CITY_PROTECTOR; }

void Player::SetCityTitle()
{
Expand Down Expand Up @@ -4467,7 +4467,7 @@ void Player::_LoadSpellCooldowns(std::unique_ptr<QueryResult> result)
}
}

void Player::_SaveSpellCooldowns()
void Player::_SaveSpellCooldowns() const
{
static SqlStatementID deleteSpellCooldown;

Expand Down Expand Up @@ -17873,7 +17873,7 @@ void Player::PossessSpellInitialize()
GetSession()->SendPacket(&data);
}

void Player::CharmSpellInitialize()
void Player::CharmSpellInitialize() const
{
Unit* charm = GetCharm();

Expand Down Expand Up @@ -17941,7 +17941,7 @@ void Player::CharmSpellInitialize()
GetSession()->SendPacket(&data);
}

void Player::RemovePetActionBar()
void Player::RemovePetActionBar() const
{
WorldPacket data(SMSG_PET_SPELLS, 8);
data << ObjectGuid();
Expand Down Expand Up @@ -18507,7 +18507,7 @@ bool Player::ActivateTaxiPathTo(uint32 taxi_path_id, uint32 spellid /*= 0*/, boo
return ActivateTaxiPathTo(nodes, nullptr, spellid, nocheck);
}

void Player::ContinueTaxiFlight()
void Player::ContinueTaxiFlight() const
{
uint32 sourceNode = m_taxi.GetTaxiSource();
if (!sourceNode)
Expand Down Expand Up @@ -18882,7 +18882,7 @@ bool Player::BuyItemFromVendor(ObjectGuid vendorGuid, uint32 item, uint8 count,
return crItem->maxcount != 0;
}

void Player::SendRaidGroupOnlyError(uint32 timer, RaidGroupError error)
void Player::SendRaidGroupOnlyError(uint32 timer, RaidGroupError error) const
{
WorldPacket data(SMSG_RAID_GROUP_ONLY, 4 + 4);
data << uint32(timer);
Expand Down Expand Up @@ -19361,7 +19361,7 @@ void Player::SetLongSight(Aura const* aura)
}
}

void Player::UpdateLongSight()
void Player::UpdateLongSight() const
{
if (!m_longSightSpell)
return;
Expand Down Expand Up @@ -20109,7 +20109,7 @@ ZoneScript* Player::GetZoneScript() const
return sZoneScriptMgr.GetZoneScriptToZoneId(GetZoneId());
}

bool Player::HasItemFitToSpellReqirements(SpellEntry const* spellInfo, Item const* ignoreItem)
bool Player::HasItemFitToSpellReqirements(SpellEntry const* spellInfo, Item const* ignoreItem) const
{
if (spellInfo->EquippedItemClass < 0)
return true;
Expand Down Expand Up @@ -20458,7 +20458,7 @@ void Player::ResurectUsingRequestData()
SpawnCorpseBones();
}

void Player::SetClientControl(Unit const* target, uint8 allowMove)
void Player::SetClientControl(Unit const* target, uint8 allowMove) const
{
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_9_4
WorldPacket data(SMSG_CLIENT_CONTROL_UPDATE, target->GetPackGUID().size() + 1);
Expand Down Expand Up @@ -21402,17 +21402,17 @@ bool Player::TeleportToHomebind(uint32 options, bool hearthCooldown)
return TeleportTo(m_homebind, (options | TELE_TO_FORCE_MAP_CHANGE));
}

Unit* Player::GetSelectedUnit()
Unit* Player::GetSelectedUnit() const
{
return GetMap()->GetUnit(m_curSelectionGuid);
}

Creature* Player::GetSelectedCreature()
Creature* Player::GetSelectedCreature() const
{
return GetMap()->GetCreature(m_curSelectionGuid);
}

Player* Player::GetSelectedPlayer()
Player* Player::GetSelectedPlayer() const
{
return GetMap()->GetPlayer(m_curSelectionGuid);
}
Expand Down
Loading

0 comments on commit ae61d73

Please sign in to comment.