From e920e35a5cb873f4f561e4bd63445091e49f3005 Mon Sep 17 00:00:00 2001 From: hg <4683435+hgtw@users.noreply.github.com> Date: Mon, 12 Feb 2024 03:58:48 -0500 Subject: [PATCH] [Cleanup] Use explicit conversions for enum formatting (#4064) This is prep for updating to fmt 10 which removed implicit conversions for enums. --- common/bodytypes.h | 2 ++ common/deity.h | 2 ++ common/emu_opcodes.h | 1 + common/guilds.h | 1 + common/patches/rof2_limits.h | 1 + common/skills.h | 2 ++ common/tasks.h | 2 ++ common/textures.h | 2 ++ world/cliententry.cpp | 2 +- world/clientlist.cpp | 2 +- zone/aggro.cpp | 4 ++-- zone/bot_commands/bot.cpp | 2 +- zone/client.cpp | 2 +- zone/client_packet.cpp | 4 ++-- zone/data_bucket.cpp | 4 ++-- zone/mob.cpp | 2 +- zone/mob_movement_manager.cpp | 2 +- zone/spawn2.h | 3 +++ zone/spells.cpp | 6 +++--- zone/task_manager.cpp | 2 +- zone/zoning.cpp | 2 +- 21 files changed, 33 insertions(+), 17 deletions(-) diff --git a/common/bodytypes.h b/common/bodytypes.h index 0528e14f6..6b00c8961 100644 --- a/common/bodytypes.h +++ b/common/bodytypes.h @@ -64,4 +64,6 @@ typedef enum { } bodyType; /* bodytypes above 64 make the mob not show up */ +constexpr int format_as(bodyType type) { return static_cast(type); } + #endif diff --git a/common/deity.h b/common/deity.h index 43542bb7d..6789aa723 100644 --- a/common/deity.h +++ b/common/deity.h @@ -71,6 +71,8 @@ namespace EQ bit_DeityAll = UINT32_MAX }; + constexpr int format_as(DeityType type) { return static_cast(type); } + extern DeityTypeBit GetDeityBitmask(DeityType deity_type); extern std::string GetDeityName(DeityType deity_type); extern const std::map& GetDeityMap(); diff --git a/common/emu_opcodes.h b/common/emu_opcodes.h index d7f1814da..9d5079bea 100644 --- a/common/emu_opcodes.h +++ b/common/emu_opcodes.h @@ -45,6 +45,7 @@ typedef enum { //EQEmu internal opcodes list _maxEmuOpcode } EmuOpcode; +constexpr int format_as(EmuOpcode opcode) { return static_cast(opcode); } extern const char *OpcodeNames[_maxEmuOpcode+1]; #endif diff --git a/common/guilds.h b/common/guilds.h index de1ea246f..11a6af704 100644 --- a/common/guilds.h +++ b/common/guilds.h @@ -81,5 +81,6 @@ typedef enum { GUILD_ACTION_MEMBERS_DEMOTE_SELF = 30, } GuildAction; +constexpr int format_as(GuildAction action) { return static_cast(action); } #endif diff --git a/common/patches/rof2_limits.h b/common/patches/rof2_limits.h index 114db68aa..fa5f551d1 100644 --- a/common/patches/rof2_limits.h +++ b/common/patches/rof2_limits.h @@ -158,6 +158,7 @@ namespace RoF2 slotCursor }; + constexpr int16 format_as(InventorySlots slot) { return static_cast(slot); } } // namespace enum_ using namespace enum_; diff --git a/common/skills.h b/common/skills.h index 9b7dee8e8..f19f9f700 100644 --- a/common/skills.h +++ b/common/skills.h @@ -162,6 +162,8 @@ namespace EQ // server profile does not reflect this yet..so, prefixed with 'PACKET_' #define PACKET_SKILL_ARRAY_SIZE 100 + constexpr int format_as(SkillType skill) { return static_cast(skill); } + bool IsTradeskill(SkillType skill); bool IsSpecializedSkill(SkillType skill); float GetSkillMeleePushForce(SkillType skill); diff --git a/common/tasks.h b/common/tasks.h index f6ca39da3..8f081daf5 100644 --- a/common/tasks.h +++ b/common/tasks.h @@ -252,6 +252,8 @@ typedef enum { ActivityCompleted = 2 } ActivityState; +constexpr int format_as(ActivityState state) { return static_cast(state); } + struct ClientActivityInformation { int activity_id; int done_count; diff --git a/common/textures.h b/common/textures.h index b415c442c..919a5fed4 100644 --- a/common/textures.h +++ b/common/textures.h @@ -54,6 +54,8 @@ namespace EQ tintInvalid = textureInvalid }; + constexpr int format_as(TextureSlot slot) { return static_cast(slot); } + const int8 LastTexture = weaponSecondary; const int8 LastTintableTexture = tintFeet; diff --git a/world/cliententry.cpp b/world/cliententry.cpp index 66a506a7b..3dda07e66 100644 --- a/world/cliententry.cpp +++ b/world/cliententry.cpp @@ -139,7 +139,7 @@ void ClientListEntry::SetOnline(CLE_Status iOnline) AccountName(), AccountID(), CLEStatusString[CLE_Status::Online], - iOnline + static_cast(iOnline) ); if (iOnline >= CLE_Status::Online && pOnline < CLE_Status::Online) { diff --git a/world/clientlist.cpp b/world/clientlist.cpp index eb7b960db..58b8f558d 100644 --- a/world/clientlist.cpp +++ b/world/clientlist.cpp @@ -280,7 +280,7 @@ void ClientList::SendCLEList(const int16& admin, const char* to, WorldTCPConnect fmt::format_to(std::back_inserter(out), fmt::runtime(newline)); } fmt::format_to(std::back_inserter(out), "ID: {} Acc# {} AccName: {} IP: {}", cle->GetID(), cle->AccountID(), cle->AccountName(), inet_ntoa(in)); - fmt::format_to(std::back_inserter(out), "{} Stale: {} Online: {} Admin: {}", newline, cle->GetStaleCounter(), cle->Online(), cle->Admin()); + fmt::format_to(std::back_inserter(out), "{} Stale: {} Online: {} Admin: {}", newline, cle->GetStaleCounter(), static_cast(cle->Online()), cle->Admin()); if (cle->LSID()) fmt::format_to(std::back_inserter(out), "{} LSID: {} LSName: {} WorldAdmin: {}", newline, cle->LSID(), cle->LSName(), cle->WorldAdmin()); if (cle->CharID()) diff --git a/zone/aggro.cpp b/zone/aggro.cpp index 4d5836951..1804c20dc 100644 --- a/zone/aggro.cpp +++ b/zone/aggro.cpp @@ -343,7 +343,7 @@ void NPC::DescribeAggro(Client *to_who, Mob *mob, bool verbose) { "{} does not have low enough faction, their Faction Level is {} ({}).", to_who->GetTargetDescription(mob), FactionValueToString(faction_value), - faction_value + static_cast(faction_value) ).c_str() ); return; @@ -556,7 +556,7 @@ bool Mob::CheckWillAggro(Mob *mob) { LogAggro("Is In zone?:[{}]\n", mob->InZone()); LogAggro("Dist^2: [{}]\n", distance_squared); LogAggro("Range^2: [{}]\n", aggro_range_squared); - LogAggro("Faction: [{}]\n", faction_value); + LogAggro("Faction: [{}]\n", static_cast(faction_value)); LogAggro("AlwaysAggroFlag: [{}]\n", AlwaysAggro()); LogAggro("Int: [{}]\n", GetINT()); LogAggro("Con: [{}]\n", GetLevelCon(mob->GetLevel())); diff --git a/zone/bot_commands/bot.cpp b/zone/bot_commands/bot.cpp index a89047cbb..3cca661a0 100644 --- a/zone/bot_commands/bot.cpp +++ b/zone/bot_commands/bot.cpp @@ -1107,7 +1107,7 @@ void bot_command_stance(Client *c, const Seperator *sep) fmt::format( "My current stance is {} ({}).", EQ::constants::GetStanceName(bot_iter->GetBotStance()), - bot_iter->GetBotStance() + static_cast(bot_iter->GetBotStance()) ).c_str() ); } diff --git a/zone/client.cpp b/zone/client.cpp index 4ee20c2f7..4f5231e3e 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -6955,7 +6955,7 @@ void Client::ShowXTargets(Client *c) fmt::format( "xtarget slot [{}] type [{}] ID [{}] name [{}]", i, - XTargets[i].Type, + static_cast(XTargets[i].Type), XTargets[i].ID, strlen(XTargets[i].Name) ? XTargets[i].Name : "No Name" ).c_str() diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 9919034ed..bd556ccd7 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -516,7 +516,7 @@ int Client::HandlePacket(const EQApplicationPacket *app) case CLIENT_LINKDEAD: break; default: - LogDebug("Unknown client_state: [{}]\n", client_state); + LogDebug("Unknown client_state: [{}]\n", static_cast(client_state)); break; } @@ -16342,7 +16342,7 @@ void Client::Handle_OP_XTargetRequest(const EQApplicationPacket *app) } default: - LogDebug("Unhandled XTarget Type [{}]", Type); + LogDebug("Unhandled XTarget Type [{}]", static_cast(Type)); break; } diff --git a/zone/data_bucket.cpp b/zone/data_bucket.cpp index 9e026d8b4..f52d27f79 100644 --- a/zone/data_bucket.cpp +++ b/zone/data_bucket.cpp @@ -410,7 +410,7 @@ void DataBucket::BulkLoadEntities(DataBucketLoadType::Type t, std::vector(t)); break; } @@ -546,7 +546,7 @@ void DataBucket::HandleWorldMessage(ServerPacket *p) n.e.id, n.e.key_, n.e.value, - n.update_action + static_cast(n.update_action) ); // delete diff --git a/zone/mob.cpp b/zone/mob.cpp index 34c5a7105..ca29c1de3 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -2521,7 +2521,7 @@ void Mob::SendStatsWindow(Client* c, bool use_window) CastToClient()->GetPVP() ? "Yes" : "No", CastToClient()->GetGM() ? "On" : "Off", EQ::constants::GetFlyModeName(static_cast(flymode)), - flymode, + static_cast(flymode), CastToClient()->GetGMSpeed() ? "On" : "Off", CastToClient()->GetHideMe() ? "On" : "Off", CastToClient()->GetGMInvul() ? "On" : "Off", diff --git a/zone/mob_movement_manager.cpp b/zone/mob_movement_manager.cpp index 1b4af7cd0..fb2ac11dc 100644 --- a/zone/mob_movement_manager.cpp +++ b/zone/mob_movement_manager.cpp @@ -1487,7 +1487,7 @@ void MobMovementManager::PushEvadeCombat(MobMovementEntry &mob_movement_entry) */ void MobMovementManager::HandleStuckBehavior(Mob *who, float x, float y, float z, MobMovementMode mob_movement_mode) { - LogDebug("Handle stuck behavior for {0} at ({1}, {2}, {3}) with movement_mode {4}", who->GetName(), x, y, z, mob_movement_mode); + LogDebug("Handle stuck behavior for {0} at ({1}, {2}, {3}) with movement_mode {4}", who->GetName(), x, y, z, static_cast(mob_movement_mode)); auto sb = who->GetStuckBehavior(); MobStuckBehavior behavior = RunToTarget; diff --git a/zone/spawn2.h b/zone/spawn2.h index 6d0ce9a0e..e16fb4a72 100644 --- a/zone/spawn2.h +++ b/zone/spawn2.h @@ -169,4 +169,7 @@ protected: TimeOfDay_Struct next_event; }; +constexpr int format_as(SpawnCondition::OnChange val) { return static_cast(val); } +constexpr int format_as(SpawnEvent::Action val) { return static_cast(val); } + #endif diff --git a/zone/spells.cpp b/zone/spells.cpp index 9a1b401d9..dffc4a2bd 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -407,7 +407,7 @@ bool Mob::DoCastSpell(uint16 spell_id, uint16 target_id, CastingSlot slot, spell.target_type == ST_Beam ) && target_id == 0 ) { - LogSpells("Spell [{}] auto-targeted the caster. Group? [{}], target type [{}]", spell_id, IsGroupSpell(spell_id), spell.target_type); + LogSpells("Spell [{}] auto-targeted the caster. Group? [{}], target type [{}]", spell_id, IsGroupSpell(spell_id), static_cast(spell.target_type)); target_id = GetID(); } @@ -2383,7 +2383,7 @@ bool Mob::DetermineSpellTargets(uint16 spell_id, Mob *&spell_target, Mob *&ae_ce default: { - LogSpells("I dont know Target Type: [{}] Spell: ([{}]) [{}]", spells[spell_id].target_type, spell_id, spells[spell_id].name); + LogSpells("I dont know Target Type: [{}] Spell: ([{}]) [{}]", static_cast(spells[spell_id].target_type), spell_id, spells[spell_id].name); Message(0, "I dont know Target Type: %d Spell: (%d) %s", spells[spell_id].target_type, spell_id, spells[spell_id].name); CastAction = CastActUnknown; break; @@ -2461,7 +2461,7 @@ bool Mob::SpellFinished(uint16 spell_id, Mob *spell_target, CastingSlot slot, in } } - LogSpells("Spell [{}]: target type [{}], target [{}], AE center [{}]", spell_id, CastAction, spell_target?spell_target->GetName():"NONE", ae_center?ae_center->GetName():"NONE"); + LogSpells("Spell [{}]: target type [{}], target [{}], AE center [{}]", spell_id, static_cast(CastAction), spell_target?spell_target->GetName():"NONE", ae_center?ae_center->GetName():"NONE"); // if a spell has the AEDuration flag, it becomes an AE on target // spell that's recast every 2500 msec for AEDuration msec. diff --git a/zone/task_manager.cpp b/zone/task_manager.cpp index 169e06fd9..34cb4d6c4 100644 --- a/zone/task_manager.cpp +++ b/zone/task_manager.cpp @@ -256,7 +256,7 @@ bool TaskManager::LoadTasks(int single_task) activity_id, task_data->activity_count, static_cast(ad->activity_type), - ad->goal_method, + static_cast(ad->goal_method), ad->goal_count, ad->zones.c_str(), ad->target_name.c_str(), diff --git a/zone/zoning.cpp b/zone/zoning.cpp index 2e680d7a6..93b3d6da6 100644 --- a/zone/zoning.cpp +++ b/zone/zoning.cpp @@ -746,7 +746,7 @@ void Client::ZonePC(uint32 zoneID, uint32 instance_id, float x, float y, float z z, heading, ignorerestrictions, - zm + static_cast(zm) ); cheat_manager.SetExemptStatus(Port, true);