Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more code cleanup and refactoring #2842

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ void DungeonResetScheduler::ScheduleAllDungeonResets()
}
}

void DungeonResetScheduler::ScheduleReset(bool add, time_t time, DungeonResetEvent event)
void DungeonResetScheduler::ScheduleReset(bool add, time_t const time, DungeonResetEvent event)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a pointer so no need for the time parameter to be const

{
MapPersistentStateManager::PersistentStateMap::iterator itr = m_InstanceSaves.m_instanceSaveByInstanceId.find(event.instanceId);
if (itr == m_InstanceSaves.m_instanceSaveByInstanceId.end())
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -300,7 +300,7 @@ class DungeonResetScheduler
m_resetTimeByMapId[mapId] = t;
}

void ScheduleReset(bool add, time_t time, DungeonResetEvent event);
void ScheduleReset(bool add, time_t const time, DungeonResetEvent event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for time to be const


void Update();

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why explicitly calling unit version

Copy link
Contributor Author

@schell244 schell244 Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for readability - there's no specific implementation for CleanupsBeforeDelete at creature (while at player there is, which then also calls 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 @@ -1492,7 +1492,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 @@ -4472,7 +4472,7 @@ void Player::_LoadSpellCooldowns(std::unique_ptr<QueryResult> result)
}
}

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

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

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

Expand Down Expand Up @@ -17992,7 +17992,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 @@ -18558,7 +18558,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 @@ -18933,7 +18933,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 @@ -19412,7 +19412,7 @@ void Player::SetLongSight(Aura const* aura)
}
}

void Player::UpdateLongSight()
void Player::UpdateLongSight() const
{
if (!m_longSightSpell)
return;
Expand Down Expand Up @@ -20160,7 +20160,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 @@ -20509,7 +20509,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 @@ -21453,17 +21453,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
Loading