diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index 7d8d7d97..dbbaeb9e 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -10,7 +10,6 @@ #include "Database.h" #include "eConnectionType.h" #include "eChatInternalMessageType.h" -#include "eGameMasterLevel.h" #include "ChatPackets.h" #include "dConfig.h" @@ -21,14 +20,6 @@ void PlayerContainer::Initialize() { GeneralUtils::TryParse(Game::config->GetValue("max_number_of_friends")).value_or(m_MaxNumberOfFriends); } -PlayerContainer::~PlayerContainer() { - m_Players.clear(); -} - -PlayerData::PlayerData() { - gmLevel = eGameMasterLevel::CIVILIAN; -} - TeamData::TeamData() { lootFlag = Game::config->GetValue("default_team_loot") == "0" ? 0 : 1; } diff --git a/dChatServer/PlayerContainer.h b/dChatServer/PlayerContainer.h index f34b1e54..3f2d783a 100644 --- a/dChatServer/PlayerContainer.h +++ b/dChatServer/PlayerContainer.h @@ -10,7 +10,7 @@ enum class eGameMasterLevel : uint8_t; struct IgnoreData { - IgnoreData(const std::string& name, const LWOOBJID& id) : playerName(name), playerId(id) {} + IgnoreData(const std::string& name, const LWOOBJID& id) : playerName{ name }, playerId{ id } {} inline bool operator==(const std::string& other) const noexcept { return playerName == other; } @@ -24,7 +24,6 @@ struct IgnoreData { }; struct PlayerData { - PlayerData(); operator bool() const noexcept { return playerID != LWOOBJID_EMPTY; } @@ -45,7 +44,7 @@ struct PlayerData { std::string playerName; std::vector friends; std::vector ignoredPlayers; - eGameMasterLevel gmLevel; + eGameMasterLevel gmLevel = static_cast(0); // CIVILLIAN bool isFTP = false; }; @@ -61,8 +60,6 @@ struct TeamData { class PlayerContainer { public: - ~PlayerContainer(); - void Initialize(); void InsertPlayer(Packet* packet); void RemovePlayer(Packet* packet); diff --git a/dCommon/Amf3.h b/dCommon/Amf3.h index 967313c7..dbafba1f 100644 --- a/dCommon/Amf3.h +++ b/dCommon/Amf3.h @@ -31,54 +31,68 @@ enum class eAmf : uint8_t { class AMFBaseValue { public: - virtual eAmf GetValueType() { return eAmf::Undefined; }; - AMFBaseValue() {}; - virtual ~AMFBaseValue() {}; + [[nodiscard]] constexpr virtual eAmf GetValueType() const noexcept { return eAmf::Undefined; } + constexpr AMFBaseValue() noexcept = default; + constexpr virtual ~AMFBaseValue() noexcept = default; }; -template +// AMFValue template class instantiations +template class AMFValue : public AMFBaseValue { public: - AMFValue() {}; - AMFValue(ValueType value) { SetValue(value); }; - virtual ~AMFValue() override {}; + AMFValue() = default; + AMFValue(const ValueType value) { m_Data = value; } + virtual ~AMFValue() override = default; - eAmf GetValueType() override { return eAmf::Undefined; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override; + + [[nodiscard]] const ValueType& GetValue() const { return m_Data; } + void SetValue(const ValueType value) { m_Data = value; } - const ValueType& GetValue() { return data; }; - void SetValue(ValueType value) { data = value; }; protected: - ValueType data; + ValueType m_Data; }; +// Explicit template class instantiations +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; +template class AMFValue; + +// AMFValue template class member function instantiations +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Null; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Integer; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::String; } +template <> [[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Double; } + +template +[[nodiscard]] constexpr eAmf AMFValue::GetValueType() const noexcept { return eAmf::Undefined; } + // As a string this is much easier to write and read from a BitStream. -template<> +template <> class AMFValue : public AMFBaseValue { public: - AMFValue() {}; - AMFValue(const char* value) { SetValue(std::string(value)); }; - virtual ~AMFValue() override {}; + AMFValue() = default; + AMFValue(const char* value) { m_Data = value; } + virtual ~AMFValue() override = default; - eAmf GetValueType() override { return eAmf::String; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::String; } - const std::string& GetValue() { return data; }; - void SetValue(std::string value) { data = value; }; + [[nodiscard]] const std::string& GetValue() const { return m_Data; } + void SetValue(const std::string& value) { m_Data = value; } protected: - std::string data; + std::string m_Data; }; -typedef AMFValue AMFNullValue; -typedef AMFValue AMFBoolValue; -typedef AMFValue AMFIntValue; -typedef AMFValue AMFStringValue; -typedef AMFValue AMFDoubleValue; - -template<> inline eAmf AMFValue::GetValueType() { return eAmf::Null; }; -template<> inline eAmf AMFValue::GetValueType() { return this->data ? eAmf::True : eAmf::False; }; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::Integer; }; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::Integer; }; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::String; }; -template<> inline eAmf AMFValue::GetValueType() { return eAmf::Double; }; +using AMFNullValue = AMFValue; +using AMFBoolValue = AMFValue; +using AMFIntValue = AMFValue; +using AMFStringValue = AMFValue; +using AMFDoubleValue = AMFValue; /** * The AMFArrayValue object holds 2 types of lists: @@ -89,12 +103,11 @@ template<> inline eAmf AMFValue::GetValueType() { return eAmf::Double; } * and are not to be deleted by a caller. */ class AMFArrayValue : public AMFBaseValue { - - typedef std::unordered_map AMFAssociative; - typedef std::vector AMFDense; + using AMFAssociative = std::unordered_map; + using AMFDense = std::vector; public: - eAmf GetValueType() override { return eAmf::Array; }; + [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::Array; } ~AMFArrayValue() override { for (auto valueToDelete : GetDense()) { @@ -109,17 +122,17 @@ class AMFArrayValue : public AMFBaseValue { valueToDelete.second = nullptr; } } - }; + } /** * Returns the Associative portion of the object */ - inline AMFAssociative& GetAssociative() { return this->associative; }; + [[nodiscard]] inline AMFAssociative& GetAssociative() noexcept { return this->associative; } /** * Returns the dense portion of the object */ - inline AMFDense& GetDense() { return this->dense; }; + [[nodiscard]] inline AMFDense& GetDense() noexcept { return this->dense; } /** * Inserts an AMFValue into the associative portion with the given key. @@ -135,8 +148,8 @@ class AMFArrayValue : public AMFBaseValue { * @return The inserted element if the type matched, * or nullptr if a key existed and was not the same type */ - template - std::pair*, bool> Insert(const std::string& key, ValueType value) { + template + [[maybe_unused]] std::pair*, bool> Insert(const std::string& key, const ValueType value) { auto element = associative.find(key); AMFValue* val = nullptr; bool found = true; @@ -148,10 +161,10 @@ class AMFArrayValue : public AMFBaseValue { found = false; } return std::make_pair(val, found); - }; + } // Associates an array with a string key - std::pair Insert(const std::string& key) { + [[maybe_unused]] std::pair Insert(const std::string& key) { auto element = associative.find(key); AMFArrayValue* val = nullptr; bool found = true; @@ -163,10 +176,10 @@ class AMFArrayValue : public AMFBaseValue { found = false; } return std::make_pair(val, found); - }; + } // Associates an array with an integer key - std::pair Insert(const uint32_t& index) { + [[maybe_unused]] std::pair Insert(const size_t index) { AMFArrayValue* val = nullptr; bool inserted = false; if (index >= dense.size()) { @@ -176,7 +189,7 @@ class AMFArrayValue : public AMFBaseValue { inserted = true; } return std::make_pair(dynamic_cast(dense.at(index)), inserted); - }; + } /** * @brief Inserts an AMFValue into the AMFArray key'd by index. @@ -188,8 +201,8 @@ class AMFArrayValue : public AMFBaseValue { * @return The inserted element, or nullptr if the type did not match * what was at the index. */ - template - std::pair*, bool> Insert(const uint32_t& index, ValueType value) { + template + [[maybe_unused]] std::pair*, bool> Insert(const size_t index, const ValueType value) { AMFValue* val = nullptr; bool inserted = false; if (index >= this->dense.size()) { @@ -199,7 +212,7 @@ class AMFArrayValue : public AMFBaseValue { inserted = true; } return std::make_pair(dynamic_cast*>(this->dense.at(index)), inserted); - }; + } /** * Inserts an AMFValue into the associative portion with the given key. @@ -210,7 +223,7 @@ class AMFArrayValue : public AMFBaseValue { * @param key The key to associate with the value * @param value The value to insert */ - void Insert(const std::string& key, AMFBaseValue* value) { + void Insert(const std::string& key, AMFBaseValue* const value) { auto element = associative.find(key); if (element != associative.end() && element->second) { delete element->second; @@ -218,7 +231,7 @@ class AMFArrayValue : public AMFBaseValue { } else { associative.insert(std::make_pair(key, value)); } - }; + } /** * Inserts an AMFValue into the associative portion with the given index. @@ -229,7 +242,7 @@ class AMFArrayValue : public AMFBaseValue { * @param key The key to associate with the value * @param value The value to insert */ - void Insert(const uint32_t index, AMFBaseValue* value) { + void Insert(const size_t index, AMFBaseValue* const value) { if (index < dense.size()) { AMFDense::iterator itr = dense.begin() + index; if (*itr) delete dense.at(index); @@ -237,7 +250,7 @@ class AMFArrayValue : public AMFBaseValue { dense.resize(index + 1); } dense.at(index) = value; - }; + } /** * Pushes an AMFValue into the back of the dense portion. @@ -249,10 +262,10 @@ class AMFArrayValue : public AMFBaseValue { * * @return The inserted pointer, or nullptr should the key already be in use. */ - template - inline AMFValue* Push(ValueType value) { + template + [[maybe_unused]] inline AMFValue* Push(const ValueType value) { return Insert(this->dense.size(), value).first; - }; + } /** * Removes the key from the associative portion @@ -261,7 +274,7 @@ class AMFArrayValue : public AMFBaseValue { * * @param key The key to remove from the associative portion */ - void Remove(const std::string& key, bool deleteValue = true) { + void Remove(const std::string& key, const bool deleteValue = true) { AMFAssociative::iterator it = this->associative.find(key); if (it != this->associative.end()) { if (deleteValue) delete it->second; @@ -272,7 +285,7 @@ class AMFArrayValue : public AMFBaseValue { /** * Pops the last element in the dense portion, deleting it in the process. */ - void Remove(const uint32_t index) { + void Remove(const size_t index) { if (!this->dense.empty() && index < this->dense.size()) { auto itr = this->dense.begin() + index; if (*itr) delete (*itr); @@ -284,29 +297,29 @@ class AMFArrayValue : public AMFBaseValue { if (!this->dense.empty()) Remove(this->dense.size() - 1); } - AMFArrayValue* GetArray(const std::string& key) { + [[nodiscard]] AMFArrayValue* GetArray(const std::string& key) { AMFAssociative::const_iterator it = this->associative.find(key); if (it != this->associative.end()) { return dynamic_cast(it->second); } return nullptr; - }; + } - AMFArrayValue* GetArray(const uint32_t index) { + [[nodiscard]] AMFArrayValue* GetArray(const size_t index) { return index >= this->dense.size() ? nullptr : dynamic_cast(this->dense.at(index)); - }; + } - inline AMFArrayValue* InsertArray(const std::string& key) { + [[maybe_unused]] inline AMFArrayValue* InsertArray(const std::string& key) { return static_cast(Insert(key).first); - }; + } - inline AMFArrayValue* InsertArray(const uint32_t index) { + [[maybe_unused]] inline AMFArrayValue* InsertArray(const size_t index) { return static_cast(Insert(index).first); - }; + } - inline AMFArrayValue* PushArray() { + [[maybe_unused]] inline AMFArrayValue* PushArray() { return static_cast(Insert(this->dense.size()).first); - }; + } /** * Gets an AMFValue by the key from the associative portion and converts it @@ -318,18 +331,18 @@ class AMFArrayValue : public AMFBaseValue { * @return The AMFValue */ template - AMFValue* Get(const std::string& key) const { + [[nodiscard]] AMFValue* Get(const std::string& key) const { AMFAssociative::const_iterator it = this->associative.find(key); return it != this->associative.end() ? dynamic_cast*>(it->second) : nullptr; - }; + } // Get from the array but dont cast it - AMFBaseValue* Get(const std::string& key) const { + [[nodiscard]] AMFBaseValue* Get(const std::string& key) const { AMFAssociative::const_iterator it = this->associative.find(key); return it != this->associative.end() ? it->second : nullptr; - }; + } /** * @brief Get an AMFValue object at a position in the dense portion. @@ -341,16 +354,17 @@ class AMFArrayValue : public AMFBaseValue { * @return The casted object, or nullptr. */ template - AMFValue* Get(uint32_t index) const { + [[nodiscard]] AMFValue* Get(const size_t index) const { return index < this->dense.size() ? dynamic_cast*>(this->dense.at(index)) : nullptr; - }; + } // Get from the dense but dont cast it - AMFBaseValue* Get(const uint32_t index) const { + [[nodiscard]] AMFBaseValue* Get(const size_t index) const { return index < this->dense.size() ? this->dense.at(index) : nullptr; - }; + } + private: /** * The associative portion. These values are key'd with strings to an AMFValue. diff --git a/dCommon/LDFFormat.h b/dCommon/LDFFormat.h index 7bcc91a2..3a4f2ea7 100644 --- a/dCommon/LDFFormat.h +++ b/dCommon/LDFFormat.h @@ -162,7 +162,7 @@ class LDFData: public LDFBaseData { return new LDFData(key, value); } - inline static T Default = {}; + inline static const T Default = {}; }; // LDF Types diff --git a/dCommon/dEnums/dCommonVars.h b/dCommon/dEnums/dCommonVars.h index f4f8fdfb..d871e267 100644 --- a/dCommon/dEnums/dCommonVars.h +++ b/dCommon/dEnums/dCommonVars.h @@ -39,86 +39,84 @@ constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate); //=========== TYPEDEFS ========== -typedef int32_t LOT; //!< A LOT -typedef int64_t LWOOBJID; //!< An object ID (should be unsigned actually but ok) -typedef int32_t TSkillID; //!< A skill ID -typedef uint32_t LWOCLONEID; //!< Used for Clone IDs -typedef uint16_t LWOMAPID; //!< Used for Map IDs -typedef uint16_t LWOINSTANCEID; //!< Used for Instance IDs -typedef uint32_t PROPERTYCLONELIST; //!< Used for Property Clone IDs -typedef uint32_t StripId; - -const LWOOBJID LWOOBJID_EMPTY = 0; //!< An empty object ID -const LOT LOT_NULL = -1; //!< A null LOT -const int32_t LOOTTYPE_NONE = 0; //!< No loot type available -const float SECONDARY_PRIORITY = 1.0f; //!< Secondary Priority -const uint32_t INVENTORY_MAX = 9999999; //!< The Maximum Inventory Size -const uint32_t LWOCLONEID_INVALID = -1; //!< Invalid LWOCLONEID -const uint16_t LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID -const uint16_t LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID -const uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID - -const float PI = 3.14159f; +using LOT = int32_t; //!< A LOT +using LWOOBJID = int64_t; //!< An object ID (should be unsigned actually but ok) +using TSkillID = int32_t; //!< A skill ID +using LWOCLONEID = uint32_t; //!< Used for Clone IDs +using LWOMAPID = uint16_t; //!< Used for Map IDs +using LWOINSTANCEID = uint16_t; //!< Used for Instance IDs +using PROPERTYCLONELIST = uint32_t; //!< Used for Property Clone IDs +using StripId = uint32_t; + +constexpr LWOOBJID LWOOBJID_EMPTY = 0; //!< An empty object ID +constexpr LOT LOT_NULL = -1; //!< A null LOT +constexpr int32_t LOOTTYPE_NONE = 0; //!< No loot type available +constexpr float SECONDARY_PRIORITY = 1.0f; //!< Secondary Priority +constexpr uint32_t INVENTORY_MAX = 9999999; //!< The Maximum Inventory Size +constexpr LWOCLONEID LWOCLONEID_INVALID = -1; //!< Invalid LWOCLONEID +constexpr LWOINSTANCEID LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID +constexpr LWOMAPID LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID +constexpr uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID + +constexpr float PI = 3.14159f; //============ STRUCTS ============== struct LWOSCENEID { public: - LWOSCENEID() { m_sceneID = -1; m_layerID = 0; } - LWOSCENEID(int sceneID) { m_sceneID = sceneID; m_layerID = 0; } - LWOSCENEID(int sceneID, unsigned int layerID) { m_sceneID = sceneID; m_layerID = layerID; } + constexpr LWOSCENEID() noexcept { m_sceneID = -1; m_layerID = 0; } + constexpr LWOSCENEID(int32_t sceneID) noexcept { m_sceneID = sceneID; m_layerID = 0; } + constexpr LWOSCENEID(int32_t sceneID, uint32_t layerID) noexcept { m_sceneID = sceneID; m_layerID = layerID; } - LWOSCENEID& operator=(const LWOSCENEID& rhs) { m_sceneID = rhs.m_sceneID; m_layerID = rhs.m_layerID; return *this; } - LWOSCENEID& operator=(const int rhs) { m_sceneID = rhs; m_layerID = 0; return *this; } + constexpr LWOSCENEID& operator=(const LWOSCENEID& rhs) noexcept { m_sceneID = rhs.m_sceneID; m_layerID = rhs.m_layerID; return *this; } + constexpr LWOSCENEID& operator=(const int32_t rhs) noexcept { m_sceneID = rhs; m_layerID = 0; return *this; } - bool operator<(const LWOSCENEID& rhs) const { return (m_sceneID < rhs.m_sceneID || (m_sceneID == rhs.m_sceneID && m_layerID < rhs.m_layerID)); } - bool operator<(const int rhs) const { return m_sceneID < rhs; } + constexpr bool operator<(const LWOSCENEID& rhs) const noexcept { return (m_sceneID < rhs.m_sceneID || (m_sceneID == rhs.m_sceneID && m_layerID < rhs.m_layerID)); } + constexpr bool operator<(const int32_t rhs) const noexcept { return m_sceneID < rhs; } - bool operator==(const LWOSCENEID& rhs) const { return (m_sceneID == rhs.m_sceneID && m_layerID == rhs.m_layerID); } - bool operator==(const int rhs) const { return m_sceneID == rhs; } + constexpr bool operator==(const LWOSCENEID& rhs) const noexcept { return (m_sceneID == rhs.m_sceneID && m_layerID == rhs.m_layerID); } + constexpr bool operator==(const int32_t rhs) const noexcept { return m_sceneID == rhs; } - const int GetSceneID() const { return m_sceneID; } - const unsigned int GetLayerID() const { return m_layerID; } + constexpr int32_t GetSceneID() const noexcept { return m_sceneID; } + constexpr uint32_t GetLayerID() const noexcept { return m_layerID; } - void SetSceneID(const int sceneID) { m_sceneID = sceneID; } - void SetLayerID(const unsigned int layerID) { m_layerID = layerID; } + constexpr void SetSceneID(const int32_t sceneID) noexcept { m_sceneID = sceneID; } + constexpr void SetLayerID(const uint32_t layerID) noexcept { m_layerID = layerID; } private: - int m_sceneID; - unsigned int m_layerID; + int32_t m_sceneID; + uint32_t m_layerID; }; struct LWOZONEID { public: - const LWOMAPID& GetMapID() const { return m_MapID; } - const LWOINSTANCEID& GetInstanceID() const { return m_InstanceID; } - const LWOCLONEID& GetCloneID() const { return m_CloneID; } + constexpr const LWOMAPID& GetMapID() const noexcept { return m_MapID; } + constexpr const LWOINSTANCEID& GetInstanceID() const noexcept { return m_InstanceID; } + constexpr const LWOCLONEID& GetCloneID() const noexcept { return m_CloneID; } //In order: def constr, constr, assign op - LWOZONEID() { m_MapID = LWOMAPID_INVALID; m_InstanceID = LWOINSTANCEID_INVALID; m_CloneID = LWOCLONEID_INVALID; } - LWOZONEID(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLONEID& cloneID) { m_MapID = mapID; m_InstanceID = instanceID; m_CloneID = cloneID; } - LWOZONEID(const LWOZONEID& replacement) { *this = replacement; } + constexpr LWOZONEID() noexcept = default; + constexpr LWOZONEID(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLONEID& cloneID) noexcept { m_MapID = mapID; m_InstanceID = instanceID; m_CloneID = cloneID; } + constexpr LWOZONEID(const LWOZONEID& replacement) noexcept { *this = replacement; } private: - LWOMAPID m_MapID; //1000 for VE, 1100 for AG, etc... - LWOINSTANCEID m_InstanceID; //Instances host the same world, but on a different dWorld process. - LWOCLONEID m_CloneID; //To differentiate between "your property" and "my property". Always 0 for non-prop worlds. + LWOMAPID m_MapID = LWOMAPID_INVALID; //1000 for VE, 1100 for AG, etc... + LWOINSTANCEID m_InstanceID = LWOINSTANCEID_INVALID; //Instances host the same world, but on a different dWorld process. + LWOCLONEID m_CloneID = LWOCLONEID_INVALID; //To differentiate between "your property" and "my property". Always 0 for non-prop worlds. }; -const LWOSCENEID LWOSCENEID_INVALID = -1; +constexpr LWOSCENEID LWOSCENEID_INVALID = -1; struct LWONameValue { uint32_t length = 0; //!< The length of the name std::u16string name; //!< The name - LWONameValue(void) {} + LWONameValue() = default; LWONameValue(const std::u16string& name) { this->name = name; this->length = static_cast(name.length()); } - - ~LWONameValue(void) {} }; struct FriendData { diff --git a/dGame/dComponents/QuickBuildComponent.cpp b/dGame/dComponents/QuickBuildComponent.cpp index 2514f194..6cef87d3 100644 --- a/dGame/dComponents/QuickBuildComponent.cpp +++ b/dGame/dComponents/QuickBuildComponent.cpp @@ -23,7 +23,7 @@ #include "CppScripts.h" -QuickBuildComponent::QuickBuildComponent(Entity* entity) : Component(entity) { +QuickBuildComponent::QuickBuildComponent(Entity* const entity) : Component{ entity } { std::u16string checkPreconditions = entity->GetVar(u"CheckPrecondition"); if (!checkPreconditions.empty()) { @@ -283,47 +283,47 @@ void QuickBuildComponent::DespawnActivator() { } } -Entity* QuickBuildComponent::GetActivator() { +Entity* QuickBuildComponent::GetActivator() const { return Game::entityManager->GetEntity(m_ActivatorId); } -NiPoint3 QuickBuildComponent::GetActivatorPosition() { +NiPoint3 QuickBuildComponent::GetActivatorPosition() const noexcept { return m_ActivatorPosition; } -float QuickBuildComponent::GetResetTime() { +float QuickBuildComponent::GetResetTime() const noexcept { return m_ResetTime; } -float QuickBuildComponent::GetCompleteTime() { +float QuickBuildComponent::GetCompleteTime() const noexcept { return m_CompleteTime; } -int QuickBuildComponent::GetTakeImagination() { +int32_t QuickBuildComponent::GetTakeImagination() const noexcept { return m_TakeImagination; } -bool QuickBuildComponent::GetInterruptible() { +bool QuickBuildComponent::GetInterruptible() const noexcept { return m_Interruptible; } -bool QuickBuildComponent::GetSelfActivator() { +bool QuickBuildComponent::GetSelfActivator() const noexcept { return m_SelfActivator; } -std::vector QuickBuildComponent::GetCustomModules() { +std::vector QuickBuildComponent::GetCustomModules() const noexcept { return m_CustomModules; } -int QuickBuildComponent::GetActivityId() { +int32_t QuickBuildComponent::GetActivityId() const noexcept { return m_ActivityId; } -int QuickBuildComponent::GetPostImaginationCost() { +int32_t QuickBuildComponent::GetPostImaginationCost() const noexcept { return m_PostImaginationCost; } -float QuickBuildComponent::GetTimeBeforeSmash() { +float QuickBuildComponent::GetTimeBeforeSmash() const noexcept { return m_TimeBeforeSmash; } @@ -332,24 +332,24 @@ eQuickBuildState QuickBuildComponent::GetState() const noexcept { } Entity* QuickBuildComponent::GetBuilder() const { - auto* builder = Game::entityManager->GetEntity(m_Builder); + auto* const builder = Game::entityManager->GetEntity(m_Builder); return builder; } -bool QuickBuildComponent::GetRepositionPlayer() const { +bool QuickBuildComponent::GetRepositionPlayer() const noexcept { return m_RepositionPlayer; } -void QuickBuildComponent::SetActivatorPosition(NiPoint3 value) { +void QuickBuildComponent::SetActivatorPosition(const NiPoint3& value) noexcept { m_ActivatorPosition = value; } -void QuickBuildComponent::SetResetTime(float value) { +void QuickBuildComponent::SetResetTime(const float value) noexcept { m_ResetTime = value; } -void QuickBuildComponent::SetCompleteTime(float value) { +void QuickBuildComponent::SetCompleteTime(const float value) noexcept { if (value < 0) { m_CompleteTime = 4.5f; } else { @@ -357,31 +357,31 @@ void QuickBuildComponent::SetCompleteTime(float value) { } } -void QuickBuildComponent::SetTakeImagination(int value) { +void QuickBuildComponent::SetTakeImagination(const int32_t value) noexcept { m_TakeImagination = value; } -void QuickBuildComponent::SetInterruptible(bool value) { +void QuickBuildComponent::SetInterruptible(const bool value) noexcept { m_Interruptible = value; } -void QuickBuildComponent::SetSelfActivator(bool value) { +void QuickBuildComponent::SetSelfActivator(const bool value) noexcept { m_SelfActivator = value; } -void QuickBuildComponent::SetCustomModules(std::vector value) { +void QuickBuildComponent::SetCustomModules(const std::vector& value) noexcept { m_CustomModules = value; } -void QuickBuildComponent::SetActivityId(int value) { +void QuickBuildComponent::SetActivityId(const int32_t value) noexcept { m_ActivityId = value; } -void QuickBuildComponent::SetPostImaginationCost(int value) { +void QuickBuildComponent::SetPostImaginationCost(const int32_t value) noexcept { m_PostImaginationCost = value; } -void QuickBuildComponent::SetTimeBeforeSmash(float value) { +void QuickBuildComponent::SetTimeBeforeSmash(const float value) noexcept { if (value < 0) { m_TimeBeforeSmash = 10.0f; } else { @@ -389,11 +389,11 @@ void QuickBuildComponent::SetTimeBeforeSmash(float value) { } } -void QuickBuildComponent::SetRepositionPlayer(bool value) { +void QuickBuildComponent::SetRepositionPlayer(const bool value) noexcept { m_RepositionPlayer = value; } -void QuickBuildComponent::StartQuickBuild(Entity* user) { +void QuickBuildComponent::StartQuickBuild(Entity* const user) { if (m_State == eQuickBuildState::OPEN || m_State == eQuickBuildState::COMPLETED || m_State == eQuickBuildState::INCOMPLETE) { m_Builder = user->GetObjectID(); @@ -426,10 +426,8 @@ void QuickBuildComponent::StartQuickBuild(Entity* user) { } } -void QuickBuildComponent::CompleteQuickBuild(Entity* user) { - if (user == nullptr) { - return; - } +void QuickBuildComponent::CompleteQuickBuild(Entity* const user) { + if (!user) return; auto* characterComponent = user->GetComponent(); if (characterComponent != nullptr) { @@ -518,7 +516,7 @@ void QuickBuildComponent::CompleteQuickBuild(Entity* user) { RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f); } -void QuickBuildComponent::ResetQuickBuild(bool failed) { +void QuickBuildComponent::ResetQuickBuild(const bool failed) { Entity* builder = GetBuilder(); if (m_State == eQuickBuildState::BUILDING && builder) { @@ -553,7 +551,7 @@ void QuickBuildComponent::ResetQuickBuild(bool failed) { } } -void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason failReason, bool skipChecks) { +void QuickBuildComponent::CancelQuickBuild(Entity* const entity, const eQuickBuildFailReason failReason, const bool skipChecks) { if (m_State != eQuickBuildState::COMPLETED || skipChecks) { m_Builder = LWOOBJID_EMPTY; @@ -581,9 +579,7 @@ void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason Game::entityManager->SerializeEntity(m_Parent); } - if (entity == nullptr) { - return; - } + if (!entity) return; CharacterComponent* characterComponent = entity->GetComponent(); if (characterComponent) { diff --git a/dGame/dComponents/QuickBuildComponent.h b/dGame/dComponents/QuickBuildComponent.h index d9cc4190..556264a8 100644 --- a/dGame/dComponents/QuickBuildComponent.h +++ b/dGame/dComponents/QuickBuildComponent.h @@ -24,7 +24,7 @@ class QuickBuildComponent final : public Component { public: static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD; - QuickBuildComponent(Entity* entity); + QuickBuildComponent(Entity* const entity); ~QuickBuildComponent() override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override; @@ -50,124 +50,124 @@ class QuickBuildComponent final : public Component { * Returns the entity that acts as the activator for this quickbuild * @return the entity that acts as the activator for this quickbuild */ - Entity* GetActivator(); + [[nodiscard]] Entity* GetActivator() const; /** * Returns the spawn position of the activator for this quickbuild, if any * @return the spawn position of the activator for this quickbuild, if any */ - NiPoint3 GetActivatorPosition(); + [[nodiscard]] NiPoint3 GetActivatorPosition() const noexcept; /** * Sets the spawn position for the activator of this quickbuild * @param value the spawn position to set for the activator */ - void SetActivatorPosition(NiPoint3 value); + void SetActivatorPosition(const NiPoint3& value) noexcept; /** * Returns the time it takes for the quickbuild to reset after being built * @return the time it takes for the quickbuild to reset after being built */ - float GetResetTime(); + [[nodiscard]] float GetResetTime() const noexcept; /** * Sets the time it takes for the quickbuild to reset after being built * @param value the reset time to set */ - void SetResetTime(float value); + void SetResetTime(const float value) noexcept; /** * Returns the time it takes to complete the quickbuild * @return the time it takes to complete the quickbuild */ - float GetCompleteTime(); + [[nodiscard]] float GetCompleteTime() const noexcept; /** * Sets the time it takes to complete the quickbuild * @param value the completion time to set */ - void SetCompleteTime(float value); + void SetCompleteTime(const float value) noexcept; /** * Returns the imagination that's taken when completing the quickbuild * @return the imagination that's taken when completing the quickbuild */ - int GetTakeImagination(); + [[nodiscard]] int32_t GetTakeImagination() const noexcept; /** * Sets the imagination that's taken when completing the quickbuild * @param value the imagination deduction to set */ - void SetTakeImagination(int value); + void SetTakeImagination(const int32_t value) noexcept; /** * Returns if the quickbuild can be interrupted, currently unused * @return if the quickbuild can be interrupted */ - bool GetInterruptible(); + [[nodiscard]] bool GetInterruptible() const noexcept; /** * Sets whether or not the quickbuild can be interrupted, currently unused * @param value true if the quickbuild may be interrupted, false otherwise */ - void SetInterruptible(bool value); + void SetInterruptible(const bool value) noexcept; /** * Returns whether or not this entity contains a built-in activator * @return whether or not this entity contains a built-in activator */ - bool GetSelfActivator(); + [[nodiscard]] bool GetSelfActivator() const noexcept; /** * Sets whether or not this entity contains a built-in activator. If set to false this will spawn activators on * each new quickbuild. * @param value whether or not this entity contains a built-in activator */ - void SetSelfActivator(bool value); + void SetSelfActivator(const bool value) noexcept; /** * Currently unused */ - std::vector GetCustomModules(); + [[nodiscard]] std::vector GetCustomModules() const noexcept; /** * Currently unused */ - void SetCustomModules(std::vector value); + void SetCustomModules(const std::vector& value) noexcept; /** * Returns the activity ID for participating in this quickbuild * @return the activity ID for participating in this quickbuild */ - int GetActivityId(); + [[nodiscard]] int32_t GetActivityId() const noexcept; /** * Sets the activity ID for participating in this quickbuild * @param value the activity ID to set */ - void SetActivityId(int value); + void SetActivityId(const int32_t value) noexcept; /** * Currently unused */ - int GetPostImaginationCost(); + [[nodiscard]] int32_t GetPostImaginationCost() const noexcept; /** * Currently unused */ - void SetPostImaginationCost(int value); + void SetPostImaginationCost(const int32_t value) noexcept; /** * Returns the time it takes for an incomplete quickbuild to be smashed automatically * @return the time it takes for an incomplete quickbuild to be smashed automatically */ - float GetTimeBeforeSmash(); + [[nodiscard]] float GetTimeBeforeSmash() const noexcept; /** * Sets the time it takes for an incomplete quickbuild to be smashed automatically * @param value the time to set */ - void SetTimeBeforeSmash(float value); + void SetTimeBeforeSmash(const float value) noexcept; /** * Returns the current quickbuild state @@ -179,19 +179,19 @@ class QuickBuildComponent final : public Component { * Returns the player that is currently building this quickbuild * @return the player that is currently building this quickbuild */ - Entity* GetBuilder() const; + [[nodiscard]] Entity* GetBuilder() const; /** * Returns whether or not the player is repositioned when initiating the quickbuild * @return whether or not the player is repositioned when initiating the quickbuild */ - bool GetRepositionPlayer() const; + [[nodiscard]] bool GetRepositionPlayer() const noexcept; /** * Sets whether or not the player is repositioned when initiating the quickbuild * @param value whether or not the player is repositioned when initiating the quickbuild */ - void SetRepositionPlayer(bool value); + void SetRepositionPlayer(const bool value) noexcept; /** * Adds a callback that is called when the quickbuild is completed @@ -209,7 +209,7 @@ class QuickBuildComponent final : public Component { * Resets the quickbuild * @param failed whether or not the player failed to complete the quickbuild, triggers an extra animation */ - void ResetQuickBuild(bool failed); + void ResetQuickBuild(const bool failed); /** * Cancels the quickbuild if it wasn't completed @@ -217,7 +217,7 @@ class QuickBuildComponent final : public Component { * @param failReason the reason the quickbuild was cancelled * @param skipChecks whether or not to skip the check for the quickbuild not being completed */ - void CancelQuickBuild(Entity* builder, eQuickBuildFailReason failReason, bool skipChecks = false); + void CancelQuickBuild(Entity* const builder, const eQuickBuildFailReason failReason, const bool skipChecks = false); private: /** * Whether or not the quickbuild state has been changed since we last serialized it. @@ -287,7 +287,7 @@ class QuickBuildComponent final : public Component { /** * The imagination that's deducted when completing the quickbuild */ - int m_TakeImagination = 0; + int32_t m_TakeImagination = 0; /** * Currently unused @@ -302,17 +302,17 @@ class QuickBuildComponent final : public Component { /** * Currently unused */ - std::vector m_CustomModules{}; + std::vector m_CustomModules{}; /** * The activity ID that players partake in when doing this quickbuild */ - int m_ActivityId = 0; + int32_t m_ActivityId = 0; /** * Currently unused */ - int m_PostImaginationCost = 0; + int32_t m_PostImaginationCost = 0; /** * The time it takes for the quickbuild to reset when it's not completed yet @@ -327,7 +327,7 @@ class QuickBuildComponent final : public Component { /** * The amount of imagination that was drained when building this quickbuild */ - int m_DrainedImagination = 0; + int32_t m_DrainedImagination = 0; /** * Whether to reposition the player or not when building @@ -337,7 +337,7 @@ class QuickBuildComponent final : public Component { /** * Currently unused */ - float m_SoftTimer = 0; + int32_t m_SoftTimer = 0; /** * The ID of the entity that's currently building the quickbuild @@ -353,13 +353,13 @@ class QuickBuildComponent final : public Component { * Starts the quickbuild for a certain entity * @param user the entity to start the quickbuild */ - void StartQuickBuild(Entity* user); + void StartQuickBuild(Entity* const user); /** * Completes the quickbuild for an entity, dropping loot and despawning the activator * @param user the entity that completed the quickbuild */ - void CompleteQuickBuild(Entity* user); + void CompleteQuickBuild(Entity* const user); }; #endif // QUICKBUILDCOMPONENT_H diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp index 6f0741dd..ac6e8db7 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.cpp @@ -2,7 +2,7 @@ #include "Action.h" -AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { +AddStripMessage::AddStripMessage(AMFArrayValue* const arguments) : BehaviorMessageBase{ arguments } { actionContext = ActionContext(arguments); position = StripUiPosition(arguments); diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h index 5cceb510..2e2bf9a0 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/AddStripMessage.h @@ -18,7 +18,7 @@ class AMFArrayValue; */ class AddStripMessage : public BehaviorMessageBase { public: - AddStripMessage(AMFArrayValue* arguments); + AddStripMessage(AMFArrayValue* const arguments); StripUiPosition GetPosition() const { return position; }; ActionContext GetActionContext() const { return actionContext; }; std::vector GetActionsToAdd() const; diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp index 0aad74dd..a49a8aeb 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp @@ -8,9 +8,9 @@ BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) { this->behaviorId = GetBehaviorIdFromArgument(arguments); } -int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) { - const auto* key = "BehaviorID"; - auto* behaviorIDValue = arguments->Get(key); +int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* const arguments) { + const char* const key = "BehaviorID"; + const auto* const behaviorIDValue = arguments->Get(key); if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { this->behaviorId = @@ -22,11 +22,9 @@ int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) return this->behaviorId; } -int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) { - auto* actionIndexAmf = arguments->Get(keyName); - if (!actionIndexAmf) { - throw std::invalid_argument("Unable to find actionIndex"); - } +int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName) const { + const auto* const actionIndexAmf = arguments->Get(keyName); + if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex"); return static_cast(actionIndexAmf->GetValue()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h index 8a841d7f..f55fde8e 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h @@ -15,13 +15,13 @@ enum class BehaviorState : uint32_t; */ class BehaviorMessageBase { public: - static inline int32_t DefaultBehaviorId = -1; - const int32_t GetBehaviorId() const { return behaviorId; }; - bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; }; - BehaviorMessageBase(AMFArrayValue* arguments); + static constexpr int32_t DefaultBehaviorId = -1; + [[nodiscard]] int32_t GetBehaviorId() const { return behaviorId; }; + [[nodiscard]] bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; }; + BehaviorMessageBase(AMFArrayValue* const arguments); protected: - int32_t GetBehaviorIdFromArgument(AMFArrayValue* arguments); - int32_t GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName = "actionIndex"); + [[nodiscard]] int32_t GetBehaviorIdFromArgument(AMFArrayValue* const arguments); + [[nodiscard]] int32_t GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName = "actionIndex") const; int32_t behaviorId = DefaultBehaviorId; }; diff --git a/dScripts/02_server/Map/AM/AmDropshipComputer.cpp b/dScripts/02_server/Map/AM/AmDropshipComputer.cpp index 357187ef..e88ec468 100644 --- a/dScripts/02_server/Map/AM/AmDropshipComputer.cpp +++ b/dScripts/02_server/Map/AM/AmDropshipComputer.cpp @@ -12,16 +12,12 @@ void AmDropshipComputer::OnStartup(Entity* self) { void AmDropshipComputer::OnUse(Entity* self, Entity* user) { auto* quickBuildComponent = self->GetComponent(); - if (quickBuildComponent == nullptr || quickBuildComponent->GetState() != eQuickBuildState::COMPLETED) { - return; - } + if (!quickBuildComponent || quickBuildComponent->GetState() != eQuickBuildState::COMPLETED) return; auto* missionComponent = user->GetComponent(); auto* inventoryComponent = user->GetComponent(); - if (missionComponent == nullptr || inventoryComponent == nullptr) { - return; - } + if (!missionComponent || !inventoryComponent) return; if (inventoryComponent->GetLotCount(m_NexusTalonDataCard) != 0 || missionComponent->GetMission(979)->GetMissionState() == eMissionState::COMPLETE) { return;