chore: General cleanup roundup (#1444)

* Moved unrelated changes out of the TryParse PR branch

* const correctness and cstdint type usage

* removing a few "== nullptr"

* amf constexpr, const-correctness, and attrib tagging

* update to account for feedback

* Fixing accidentally included header and hopefully fixing the MacOS issue too

* try reordering the amf3 specializations to fix the MacOS issue again

* Amf3 template class member func instantiation fix

* try including only on macos

* Using if constexpr rather than specialization

* Trying a different solution for the instantiation problem

* Remove #include "dPlatforms.h"
This commit is contained in:
jadebenn 2024-02-10 13:44:40 -06:00 committed by GitHub
parent 0c1ee0513d
commit 29666a1ff7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 218 additions and 228 deletions

View File

@ -10,7 +10,6 @@
#include "Database.h" #include "Database.h"
#include "eConnectionType.h" #include "eConnectionType.h"
#include "eChatInternalMessageType.h" #include "eChatInternalMessageType.h"
#include "eGameMasterLevel.h"
#include "ChatPackets.h" #include "ChatPackets.h"
#include "dConfig.h" #include "dConfig.h"
@ -21,14 +20,6 @@ void PlayerContainer::Initialize() {
GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("max_number_of_friends")).value_or(m_MaxNumberOfFriends); GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("max_number_of_friends")).value_or(m_MaxNumberOfFriends);
} }
PlayerContainer::~PlayerContainer() {
m_Players.clear();
}
PlayerData::PlayerData() {
gmLevel = eGameMasterLevel::CIVILIAN;
}
TeamData::TeamData() { TeamData::TeamData() {
lootFlag = Game::config->GetValue("default_team_loot") == "0" ? 0 : 1; lootFlag = Game::config->GetValue("default_team_loot") == "0" ? 0 : 1;
} }

View File

@ -10,7 +10,7 @@
enum class eGameMasterLevel : uint8_t; enum class eGameMasterLevel : uint8_t;
struct IgnoreData { 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 { inline bool operator==(const std::string& other) const noexcept {
return playerName == other; return playerName == other;
} }
@ -24,7 +24,6 @@ struct IgnoreData {
}; };
struct PlayerData { struct PlayerData {
PlayerData();
operator bool() const noexcept { operator bool() const noexcept {
return playerID != LWOOBJID_EMPTY; return playerID != LWOOBJID_EMPTY;
} }
@ -45,7 +44,7 @@ struct PlayerData {
std::string playerName; std::string playerName;
std::vector<FriendData> friends; std::vector<FriendData> friends;
std::vector<IgnoreData> ignoredPlayers; std::vector<IgnoreData> ignoredPlayers;
eGameMasterLevel gmLevel; eGameMasterLevel gmLevel = static_cast<eGameMasterLevel>(0); // CIVILLIAN
bool isFTP = false; bool isFTP = false;
}; };
@ -61,8 +60,6 @@ struct TeamData {
class PlayerContainer { class PlayerContainer {
public: public:
~PlayerContainer();
void Initialize(); void Initialize();
void InsertPlayer(Packet* packet); void InsertPlayer(Packet* packet);
void RemovePlayer(Packet* packet); void RemovePlayer(Packet* packet);

View File

@ -31,54 +31,68 @@ enum class eAmf : uint8_t {
class AMFBaseValue { class AMFBaseValue {
public: public:
virtual eAmf GetValueType() { return eAmf::Undefined; }; [[nodiscard]] constexpr virtual eAmf GetValueType() const noexcept { return eAmf::Undefined; }
AMFBaseValue() {}; constexpr AMFBaseValue() noexcept = default;
virtual ~AMFBaseValue() {}; constexpr virtual ~AMFBaseValue() noexcept = default;
}; };
// AMFValue template class instantiations
template <typename ValueType> template <typename ValueType>
class AMFValue : public AMFBaseValue { class AMFValue : public AMFBaseValue {
public: public:
AMFValue() {}; AMFValue() = default;
AMFValue(ValueType value) { SetValue(value); }; AMFValue(const ValueType value) { m_Data = value; }
virtual ~AMFValue() override {}; 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: protected:
ValueType data; ValueType m_Data;
}; };
// Explicit template class instantiations
template class AMFValue<std::nullptr_t>;
template class AMFValue<bool>;
template class AMFValue<int32_t>;
template class AMFValue<uint32_t>;
template class AMFValue<std::string>;
template class AMFValue<double>;
// AMFValue template class member function instantiations
template <> [[nodiscard]] constexpr eAmf AMFValue<std::nullptr_t>::GetValueType() const noexcept { return eAmf::Null; }
template <> [[nodiscard]] constexpr eAmf AMFValue<bool>::GetValueType() const noexcept { return m_Data ? eAmf::True : eAmf::False; }
template <> [[nodiscard]] constexpr eAmf AMFValue<int32_t>::GetValueType() const noexcept { return eAmf::Integer; }
template <> [[nodiscard]] constexpr eAmf AMFValue<uint32_t>::GetValueType() const noexcept { return eAmf::Integer; }
template <> [[nodiscard]] constexpr eAmf AMFValue<std::string>::GetValueType() const noexcept { return eAmf::String; }
template <> [[nodiscard]] constexpr eAmf AMFValue<double>::GetValueType() const noexcept { return eAmf::Double; }
template <typename ValueType>
[[nodiscard]] constexpr eAmf AMFValue<ValueType>::GetValueType() const noexcept { return eAmf::Undefined; }
// As a string this is much easier to write and read from a BitStream. // As a string this is much easier to write and read from a BitStream.
template <> template <>
class AMFValue<const char*> : public AMFBaseValue { class AMFValue<const char*> : public AMFBaseValue {
public: public:
AMFValue() {}; AMFValue() = default;
AMFValue(const char* value) { SetValue(std::string(value)); }; AMFValue(const char* value) { m_Data = value; }
virtual ~AMFValue() override {}; 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; }; [[nodiscard]] const std::string& GetValue() const { return m_Data; }
void SetValue(std::string value) { data = value; }; void SetValue(const std::string& value) { m_Data = value; }
protected: protected:
std::string data; std::string m_Data;
}; };
typedef AMFValue<std::nullptr_t> AMFNullValue; using AMFNullValue = AMFValue<std::nullptr_t>;
typedef AMFValue<bool> AMFBoolValue; using AMFBoolValue = AMFValue<bool>;
typedef AMFValue<int32_t> AMFIntValue; using AMFIntValue = AMFValue<int32_t>;
typedef AMFValue<std::string> AMFStringValue; using AMFStringValue = AMFValue<std::string>;
typedef AMFValue<double> AMFDoubleValue; using AMFDoubleValue = AMFValue<double>;
template<> inline eAmf AMFValue<std::nullptr_t>::GetValueType() { return eAmf::Null; };
template<> inline eAmf AMFValue<bool>::GetValueType() { return this->data ? eAmf::True : eAmf::False; };
template<> inline eAmf AMFValue<int32_t>::GetValueType() { return eAmf::Integer; };
template<> inline eAmf AMFValue<uint32_t>::GetValueType() { return eAmf::Integer; };
template<> inline eAmf AMFValue<std::string>::GetValueType() { return eAmf::String; };
template<> inline eAmf AMFValue<double>::GetValueType() { return eAmf::Double; };
/** /**
* The AMFArrayValue object holds 2 types of lists: * The AMFArrayValue object holds 2 types of lists:
@ -89,12 +103,11 @@ template<> inline eAmf AMFValue<double>::GetValueType() { return eAmf::Double; }
* and are not to be deleted by a caller. * and are not to be deleted by a caller.
*/ */
class AMFArrayValue : public AMFBaseValue { class AMFArrayValue : public AMFBaseValue {
using AMFAssociative = std::unordered_map<std::string, AMFBaseValue*>;
typedef std::unordered_map<std::string, AMFBaseValue*> AMFAssociative; using AMFDense = std::vector<AMFBaseValue*>;
typedef std::vector<AMFBaseValue*> AMFDense;
public: public:
eAmf GetValueType() override { return eAmf::Array; }; [[nodiscard]] constexpr eAmf GetValueType() const noexcept override { return eAmf::Array; }
~AMFArrayValue() override { ~AMFArrayValue() override {
for (auto valueToDelete : GetDense()) { for (auto valueToDelete : GetDense()) {
@ -109,17 +122,17 @@ public:
valueToDelete.second = nullptr; valueToDelete.second = nullptr;
} }
} }
}; }
/** /**
* Returns the Associative portion of the object * 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 * 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. * Inserts an AMFValue into the associative portion with the given key.
@ -136,7 +149,7 @@ public:
* or nullptr if a key existed and was not the same type * or nullptr if a key existed and was not the same type
*/ */
template <typename ValueType> template <typename ValueType>
std::pair<AMFValue<ValueType>*, bool> Insert(const std::string& key, ValueType value) { [[maybe_unused]] std::pair<AMFValue<ValueType>*, bool> Insert(const std::string& key, const ValueType value) {
auto element = associative.find(key); auto element = associative.find(key);
AMFValue<ValueType>* val = nullptr; AMFValue<ValueType>* val = nullptr;
bool found = true; bool found = true;
@ -148,10 +161,10 @@ public:
found = false; found = false;
} }
return std::make_pair(val, found); return std::make_pair(val, found);
}; }
// Associates an array with a string key // Associates an array with a string key
std::pair<AMFBaseValue*, bool> Insert(const std::string& key) { [[maybe_unused]] std::pair<AMFBaseValue*, bool> Insert(const std::string& key) {
auto element = associative.find(key); auto element = associative.find(key);
AMFArrayValue* val = nullptr; AMFArrayValue* val = nullptr;
bool found = true; bool found = true;
@ -163,10 +176,10 @@ public:
found = false; found = false;
} }
return std::make_pair(val, found); return std::make_pair(val, found);
}; }
// Associates an array with an integer key // Associates an array with an integer key
std::pair<AMFBaseValue*, bool> Insert(const uint32_t& index) { [[maybe_unused]] std::pair<AMFBaseValue*, bool> Insert(const size_t index) {
AMFArrayValue* val = nullptr; AMFArrayValue* val = nullptr;
bool inserted = false; bool inserted = false;
if (index >= dense.size()) { if (index >= dense.size()) {
@ -176,7 +189,7 @@ public:
inserted = true; inserted = true;
} }
return std::make_pair(dynamic_cast<AMFArrayValue*>(dense.at(index)), inserted); return std::make_pair(dynamic_cast<AMFArrayValue*>(dense.at(index)), inserted);
}; }
/** /**
* @brief Inserts an AMFValue into the AMFArray key'd by index. * @brief Inserts an AMFValue into the AMFArray key'd by index.
@ -189,7 +202,7 @@ public:
* what was at the index. * what was at the index.
*/ */
template <typename ValueType> template <typename ValueType>
std::pair<AMFValue<ValueType>*, bool> Insert(const uint32_t& index, ValueType value) { [[maybe_unused]] std::pair<AMFValue<ValueType>*, bool> Insert(const size_t index, const ValueType value) {
AMFValue<ValueType>* val = nullptr; AMFValue<ValueType>* val = nullptr;
bool inserted = false; bool inserted = false;
if (index >= this->dense.size()) { if (index >= this->dense.size()) {
@ -199,7 +212,7 @@ public:
inserted = true; inserted = true;
} }
return std::make_pair(dynamic_cast<AMFValue<ValueType>*>(this->dense.at(index)), inserted); return std::make_pair(dynamic_cast<AMFValue<ValueType>*>(this->dense.at(index)), inserted);
}; }
/** /**
* Inserts an AMFValue into the associative portion with the given key. * Inserts an AMFValue into the associative portion with the given key.
@ -210,7 +223,7 @@ public:
* @param key The key to associate with the value * @param key The key to associate with the value
* @param value The value to insert * @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); auto element = associative.find(key);
if (element != associative.end() && element->second) { if (element != associative.end() && element->second) {
delete element->second; delete element->second;
@ -218,7 +231,7 @@ public:
} else { } else {
associative.insert(std::make_pair(key, value)); associative.insert(std::make_pair(key, value));
} }
}; }
/** /**
* Inserts an AMFValue into the associative portion with the given index. * Inserts an AMFValue into the associative portion with the given index.
@ -229,7 +242,7 @@ public:
* @param key The key to associate with the value * @param key The key to associate with the value
* @param value The value to insert * @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()) { if (index < dense.size()) {
AMFDense::iterator itr = dense.begin() + index; AMFDense::iterator itr = dense.begin() + index;
if (*itr) delete dense.at(index); if (*itr) delete dense.at(index);
@ -237,7 +250,7 @@ public:
dense.resize(index + 1); dense.resize(index + 1);
} }
dense.at(index) = value; dense.at(index) = value;
}; }
/** /**
* Pushes an AMFValue into the back of the dense portion. * Pushes an AMFValue into the back of the dense portion.
@ -250,9 +263,9 @@ public:
* @return The inserted pointer, or nullptr should the key already be in use. * @return The inserted pointer, or nullptr should the key already be in use.
*/ */
template <typename ValueType> template <typename ValueType>
inline AMFValue<ValueType>* Push(ValueType value) { [[maybe_unused]] inline AMFValue<ValueType>* Push(const ValueType value) {
return Insert(this->dense.size(), value).first; return Insert(this->dense.size(), value).first;
}; }
/** /**
* Removes the key from the associative portion * Removes the key from the associative portion
@ -261,7 +274,7 @@ public:
* *
* @param key The key to remove from the associative portion * @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); AMFAssociative::iterator it = this->associative.find(key);
if (it != this->associative.end()) { if (it != this->associative.end()) {
if (deleteValue) delete it->second; if (deleteValue) delete it->second;
@ -272,7 +285,7 @@ public:
/** /**
* Pops the last element in the dense portion, deleting it in the process. * 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()) { if (!this->dense.empty() && index < this->dense.size()) {
auto itr = this->dense.begin() + index; auto itr = this->dense.begin() + index;
if (*itr) delete (*itr); if (*itr) delete (*itr);
@ -284,29 +297,29 @@ public:
if (!this->dense.empty()) Remove(this->dense.size() - 1); 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); AMFAssociative::const_iterator it = this->associative.find(key);
if (it != this->associative.end()) { if (it != this->associative.end()) {
return dynamic_cast<AMFArrayValue*>(it->second); return dynamic_cast<AMFArrayValue*>(it->second);
} }
return nullptr; return nullptr;
}; }
AMFArrayValue* GetArray(const uint32_t index) { [[nodiscard]] AMFArrayValue* GetArray(const size_t index) {
return index >= this->dense.size() ? nullptr : dynamic_cast<AMFArrayValue*>(this->dense.at(index)); return index >= this->dense.size() ? nullptr : dynamic_cast<AMFArrayValue*>(this->dense.at(index));
}; }
inline AMFArrayValue* InsertArray(const std::string& key) { [[maybe_unused]] inline AMFArrayValue* InsertArray(const std::string& key) {
return static_cast<AMFArrayValue*>(Insert(key).first); return static_cast<AMFArrayValue*>(Insert(key).first);
}; }
inline AMFArrayValue* InsertArray(const uint32_t index) { [[maybe_unused]] inline AMFArrayValue* InsertArray(const size_t index) {
return static_cast<AMFArrayValue*>(Insert(index).first); return static_cast<AMFArrayValue*>(Insert(index).first);
}; }
inline AMFArrayValue* PushArray() { [[maybe_unused]] inline AMFArrayValue* PushArray() {
return static_cast<AMFArrayValue*>(Insert(this->dense.size()).first); return static_cast<AMFArrayValue*>(Insert(this->dense.size()).first);
}; }
/** /**
* Gets an AMFValue by the key from the associative portion and converts it * Gets an AMFValue by the key from the associative portion and converts it
@ -318,18 +331,18 @@ public:
* @return The AMFValue * @return The AMFValue
*/ */
template <typename AmfType> template <typename AmfType>
AMFValue<AmfType>* Get(const std::string& key) const { [[nodiscard]] AMFValue<AmfType>* Get(const std::string& key) const {
AMFAssociative::const_iterator it = this->associative.find(key); AMFAssociative::const_iterator it = this->associative.find(key);
return it != this->associative.end() ? return it != this->associative.end() ?
dynamic_cast<AMFValue<AmfType>*>(it->second) : dynamic_cast<AMFValue<AmfType>*>(it->second) :
nullptr; nullptr;
}; }
// Get from the array but dont cast it // 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); AMFAssociative::const_iterator it = this->associative.find(key);
return it != this->associative.end() ? it->second : nullptr; return it != this->associative.end() ? it->second : nullptr;
}; }
/** /**
* @brief Get an AMFValue object at a position in the dense portion. * @brief Get an AMFValue object at a position in the dense portion.
@ -341,16 +354,17 @@ public:
* @return The casted object, or nullptr. * @return The casted object, or nullptr.
*/ */
template <typename AmfType> template <typename AmfType>
AMFValue<AmfType>* Get(uint32_t index) const { [[nodiscard]] AMFValue<AmfType>* Get(const size_t index) const {
return index < this->dense.size() ? return index < this->dense.size() ?
dynamic_cast<AMFValue<AmfType>*>(this->dense.at(index)) : dynamic_cast<AMFValue<AmfType>*>(this->dense.at(index)) :
nullptr; nullptr;
}; }
// Get from the dense but dont cast it // 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; return index < this->dense.size() ? this->dense.at(index) : nullptr;
}; }
private: private:
/** /**
* The associative portion. These values are key'd with strings to an AMFValue. * The associative portion. These values are key'd with strings to an AMFValue.

View File

@ -162,7 +162,7 @@ public:
return new LDFData<T>(key, value); return new LDFData<T>(key, value);
} }
inline static T Default = {}; inline static const T Default = {};
}; };
// LDF Types // LDF Types

View File

@ -39,86 +39,84 @@ constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate);
//=========== TYPEDEFS ========== //=========== TYPEDEFS ==========
typedef int32_t LOT; //!< A LOT using LOT = int32_t; //!< A LOT
typedef int64_t LWOOBJID; //!< An object ID (should be unsigned actually but ok) using LWOOBJID = int64_t; //!< An object ID (should be unsigned actually but ok)
typedef int32_t TSkillID; //!< A skill ID using TSkillID = int32_t; //!< A skill ID
typedef uint32_t LWOCLONEID; //!< Used for Clone IDs using LWOCLONEID = uint32_t; //!< Used for Clone IDs
typedef uint16_t LWOMAPID; //!< Used for Map IDs using LWOMAPID = uint16_t; //!< Used for Map IDs
typedef uint16_t LWOINSTANCEID; //!< Used for Instance IDs using LWOINSTANCEID = uint16_t; //!< Used for Instance IDs
typedef uint32_t PROPERTYCLONELIST; //!< Used for Property Clone IDs using PROPERTYCLONELIST = uint32_t; //!< Used for Property Clone IDs
typedef uint32_t StripId; using StripId = uint32_t;
const LWOOBJID LWOOBJID_EMPTY = 0; //!< An empty object ID constexpr LWOOBJID LWOOBJID_EMPTY = 0; //!< An empty object ID
const LOT LOT_NULL = -1; //!< A null LOT constexpr LOT LOT_NULL = -1; //!< A null LOT
const int32_t LOOTTYPE_NONE = 0; //!< No loot type available constexpr int32_t LOOTTYPE_NONE = 0; //!< No loot type available
const float SECONDARY_PRIORITY = 1.0f; //!< Secondary Priority constexpr float SECONDARY_PRIORITY = 1.0f; //!< Secondary Priority
const uint32_t INVENTORY_MAX = 9999999; //!< The Maximum Inventory Size constexpr uint32_t INVENTORY_MAX = 9999999; //!< The Maximum Inventory Size
const uint32_t LWOCLONEID_INVALID = -1; //!< Invalid LWOCLONEID constexpr LWOCLONEID LWOCLONEID_INVALID = -1; //!< Invalid LWOCLONEID
const uint16_t LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID constexpr LWOINSTANCEID LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID
const uint16_t LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID constexpr LWOMAPID LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID
const uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID constexpr uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID
const float PI = 3.14159f; constexpr float PI = 3.14159f;
//============ STRUCTS ============== //============ STRUCTS ==============
struct LWOSCENEID { struct LWOSCENEID {
public: public:
LWOSCENEID() { m_sceneID = -1; m_layerID = 0; } constexpr LWOSCENEID() noexcept { m_sceneID = -1; m_layerID = 0; }
LWOSCENEID(int sceneID) { m_sceneID = sceneID; m_layerID = 0; } constexpr LWOSCENEID(int32_t sceneID) noexcept { m_sceneID = sceneID; m_layerID = 0; }
LWOSCENEID(int sceneID, unsigned int layerID) { m_sceneID = sceneID; m_layerID = layerID; } 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; } constexpr LWOSCENEID& operator=(const LWOSCENEID& rhs) noexcept { 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 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)); } constexpr bool operator<(const LWOSCENEID& rhs) const noexcept { 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 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); } constexpr bool operator==(const LWOSCENEID& rhs) const noexcept { 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 int32_t rhs) const noexcept { return m_sceneID == rhs; }
const int GetSceneID() const { return m_sceneID; } constexpr int32_t GetSceneID() const noexcept { return m_sceneID; }
const unsigned int GetLayerID() const { return m_layerID; } constexpr uint32_t GetLayerID() const noexcept { return m_layerID; }
void SetSceneID(const int sceneID) { m_sceneID = sceneID; } constexpr void SetSceneID(const int32_t sceneID) noexcept { m_sceneID = sceneID; }
void SetLayerID(const unsigned int layerID) { m_layerID = layerID; } constexpr void SetLayerID(const uint32_t layerID) noexcept { m_layerID = layerID; }
private: private:
int m_sceneID; int32_t m_sceneID;
unsigned int m_layerID; uint32_t m_layerID;
}; };
struct LWOZONEID { struct LWOZONEID {
public: public:
const LWOMAPID& GetMapID() const { return m_MapID; } constexpr const LWOMAPID& GetMapID() const noexcept { return m_MapID; }
const LWOINSTANCEID& GetInstanceID() const { return m_InstanceID; } constexpr const LWOINSTANCEID& GetInstanceID() const noexcept { return m_InstanceID; }
const LWOCLONEID& GetCloneID() const { return m_CloneID; } constexpr const LWOCLONEID& GetCloneID() const noexcept { return m_CloneID; }
//In order: def constr, constr, assign op //In order: def constr, constr, assign op
LWOZONEID() { m_MapID = LWOMAPID_INVALID; m_InstanceID = LWOINSTANCEID_INVALID; m_CloneID = LWOCLONEID_INVALID; } constexpr LWOZONEID() noexcept = default;
LWOZONEID(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLONEID& cloneID) { m_MapID = mapID; m_InstanceID = instanceID; m_CloneID = cloneID; } constexpr LWOZONEID(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLONEID& cloneID) noexcept { m_MapID = mapID; m_InstanceID = instanceID; m_CloneID = cloneID; }
LWOZONEID(const LWOZONEID& replacement) { *this = replacement; } constexpr LWOZONEID(const LWOZONEID& replacement) noexcept { *this = replacement; }
private: private:
LWOMAPID m_MapID; //1000 for VE, 1100 for AG, etc... LWOMAPID m_MapID = LWOMAPID_INVALID; //1000 for VE, 1100 for AG, etc...
LWOINSTANCEID m_InstanceID; //Instances host the same world, but on a different dWorld process. LWOINSTANCEID m_InstanceID = LWOINSTANCEID_INVALID; //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. 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 { struct LWONameValue {
uint32_t length = 0; //!< The length of the name uint32_t length = 0; //!< The length of the name
std::u16string name; //!< The name std::u16string name; //!< The name
LWONameValue(void) {} LWONameValue() = default;
LWONameValue(const std::u16string& name) { LWONameValue(const std::u16string& name) {
this->name = name; this->name = name;
this->length = static_cast<uint32_t>(name.length()); this->length = static_cast<uint32_t>(name.length());
} }
~LWONameValue(void) {}
}; };
struct FriendData { struct FriendData {

View File

@ -23,7 +23,7 @@
#include "CppScripts.h" #include "CppScripts.h"
QuickBuildComponent::QuickBuildComponent(Entity* entity) : Component(entity) { QuickBuildComponent::QuickBuildComponent(Entity* const entity) : Component{ entity } {
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition"); std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");
if (!checkPreconditions.empty()) { if (!checkPreconditions.empty()) {
@ -283,47 +283,47 @@ void QuickBuildComponent::DespawnActivator() {
} }
} }
Entity* QuickBuildComponent::GetActivator() { Entity* QuickBuildComponent::GetActivator() const {
return Game::entityManager->GetEntity(m_ActivatorId); return Game::entityManager->GetEntity(m_ActivatorId);
} }
NiPoint3 QuickBuildComponent::GetActivatorPosition() { NiPoint3 QuickBuildComponent::GetActivatorPosition() const noexcept {
return m_ActivatorPosition; return m_ActivatorPosition;
} }
float QuickBuildComponent::GetResetTime() { float QuickBuildComponent::GetResetTime() const noexcept {
return m_ResetTime; return m_ResetTime;
} }
float QuickBuildComponent::GetCompleteTime() { float QuickBuildComponent::GetCompleteTime() const noexcept {
return m_CompleteTime; return m_CompleteTime;
} }
int QuickBuildComponent::GetTakeImagination() { int32_t QuickBuildComponent::GetTakeImagination() const noexcept {
return m_TakeImagination; return m_TakeImagination;
} }
bool QuickBuildComponent::GetInterruptible() { bool QuickBuildComponent::GetInterruptible() const noexcept {
return m_Interruptible; return m_Interruptible;
} }
bool QuickBuildComponent::GetSelfActivator() { bool QuickBuildComponent::GetSelfActivator() const noexcept {
return m_SelfActivator; return m_SelfActivator;
} }
std::vector<int> QuickBuildComponent::GetCustomModules() { std::vector<int32_t> QuickBuildComponent::GetCustomModules() const noexcept {
return m_CustomModules; return m_CustomModules;
} }
int QuickBuildComponent::GetActivityId() { int32_t QuickBuildComponent::GetActivityId() const noexcept {
return m_ActivityId; return m_ActivityId;
} }
int QuickBuildComponent::GetPostImaginationCost() { int32_t QuickBuildComponent::GetPostImaginationCost() const noexcept {
return m_PostImaginationCost; return m_PostImaginationCost;
} }
float QuickBuildComponent::GetTimeBeforeSmash() { float QuickBuildComponent::GetTimeBeforeSmash() const noexcept {
return m_TimeBeforeSmash; return m_TimeBeforeSmash;
} }
@ -332,24 +332,24 @@ eQuickBuildState QuickBuildComponent::GetState() const noexcept {
} }
Entity* QuickBuildComponent::GetBuilder() const { Entity* QuickBuildComponent::GetBuilder() const {
auto* builder = Game::entityManager->GetEntity(m_Builder); auto* const builder = Game::entityManager->GetEntity(m_Builder);
return builder; return builder;
} }
bool QuickBuildComponent::GetRepositionPlayer() const { bool QuickBuildComponent::GetRepositionPlayer() const noexcept {
return m_RepositionPlayer; return m_RepositionPlayer;
} }
void QuickBuildComponent::SetActivatorPosition(NiPoint3 value) { void QuickBuildComponent::SetActivatorPosition(const NiPoint3& value) noexcept {
m_ActivatorPosition = value; m_ActivatorPosition = value;
} }
void QuickBuildComponent::SetResetTime(float value) { void QuickBuildComponent::SetResetTime(const float value) noexcept {
m_ResetTime = value; m_ResetTime = value;
} }
void QuickBuildComponent::SetCompleteTime(float value) { void QuickBuildComponent::SetCompleteTime(const float value) noexcept {
if (value < 0) { if (value < 0) {
m_CompleteTime = 4.5f; m_CompleteTime = 4.5f;
} else { } 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; m_TakeImagination = value;
} }
void QuickBuildComponent::SetInterruptible(bool value) { void QuickBuildComponent::SetInterruptible(const bool value) noexcept {
m_Interruptible = value; m_Interruptible = value;
} }
void QuickBuildComponent::SetSelfActivator(bool value) { void QuickBuildComponent::SetSelfActivator(const bool value) noexcept {
m_SelfActivator = value; m_SelfActivator = value;
} }
void QuickBuildComponent::SetCustomModules(std::vector<int> value) { void QuickBuildComponent::SetCustomModules(const std::vector<int32_t>& value) noexcept {
m_CustomModules = value; m_CustomModules = value;
} }
void QuickBuildComponent::SetActivityId(int value) { void QuickBuildComponent::SetActivityId(const int32_t value) noexcept {
m_ActivityId = value; m_ActivityId = value;
} }
void QuickBuildComponent::SetPostImaginationCost(int value) { void QuickBuildComponent::SetPostImaginationCost(const int32_t value) noexcept {
m_PostImaginationCost = value; m_PostImaginationCost = value;
} }
void QuickBuildComponent::SetTimeBeforeSmash(float value) { void QuickBuildComponent::SetTimeBeforeSmash(const float value) noexcept {
if (value < 0) { if (value < 0) {
m_TimeBeforeSmash = 10.0f; m_TimeBeforeSmash = 10.0f;
} else { } 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; 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) { if (m_State == eQuickBuildState::OPEN || m_State == eQuickBuildState::COMPLETED || m_State == eQuickBuildState::INCOMPLETE) {
m_Builder = user->GetObjectID(); m_Builder = user->GetObjectID();
@ -426,10 +426,8 @@ void QuickBuildComponent::StartQuickBuild(Entity* user) {
} }
} }
void QuickBuildComponent::CompleteQuickBuild(Entity* user) { void QuickBuildComponent::CompleteQuickBuild(Entity* const user) {
if (user == nullptr) { if (!user) return;
return;
}
auto* characterComponent = user->GetComponent<CharacterComponent>(); auto* characterComponent = user->GetComponent<CharacterComponent>();
if (characterComponent != nullptr) { if (characterComponent != nullptr) {
@ -518,7 +516,7 @@ void QuickBuildComponent::CompleteQuickBuild(Entity* user) {
RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f); RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f);
} }
void QuickBuildComponent::ResetQuickBuild(bool failed) { void QuickBuildComponent::ResetQuickBuild(const bool failed) {
Entity* builder = GetBuilder(); Entity* builder = GetBuilder();
if (m_State == eQuickBuildState::BUILDING && builder) { 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) { if (m_State != eQuickBuildState::COMPLETED || skipChecks) {
m_Builder = LWOOBJID_EMPTY; m_Builder = LWOOBJID_EMPTY;
@ -581,9 +579,7 @@ void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason
Game::entityManager->SerializeEntity(m_Parent); Game::entityManager->SerializeEntity(m_Parent);
} }
if (entity == nullptr) { if (!entity) return;
return;
}
CharacterComponent* characterComponent = entity->GetComponent<CharacterComponent>(); CharacterComponent* characterComponent = entity->GetComponent<CharacterComponent>();
if (characterComponent) { if (characterComponent) {

View File

@ -24,7 +24,7 @@ class QuickBuildComponent final : public Component {
public: public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD; static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
QuickBuildComponent(Entity* entity); QuickBuildComponent(Entity* const entity);
~QuickBuildComponent() override; ~QuickBuildComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override; void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
@ -50,124 +50,124 @@ public:
* Returns the entity that acts as the activator for this quickbuild * Returns the entity that acts as the activator for this quickbuild
* @return 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 * Returns the spawn position of the activator for this quickbuild, if any
* @return 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 * Sets the spawn position for the activator of this quickbuild
* @param value the spawn position to set for the activator * @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 * 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 * @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 * Sets the time it takes for the quickbuild to reset after being built
* @param value the reset time to set * @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 * Returns the time it takes to complete the quickbuild
* @return 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 * Sets the time it takes to complete the quickbuild
* @param value the completion time to set * @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 * Returns the imagination that's taken when completing the quickbuild
* @return 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 * Sets the imagination that's taken when completing the quickbuild
* @param value the imagination deduction to set * @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 * Returns if the quickbuild can be interrupted, currently unused
* @return if the quickbuild can be interrupted * @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 * Sets whether or not the quickbuild can be interrupted, currently unused
* @param value true if the quickbuild may be interrupted, false otherwise * @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 * Returns whether or not this entity contains a built-in activator
* @return 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 * Sets whether or not this entity contains a built-in activator. If set to false this will spawn activators on
* each new quickbuild. * each new quickbuild.
* @param value whether or not this entity contains a built-in activator * @param value whether or not this entity contains a built-in activator
*/ */
void SetSelfActivator(bool value); void SetSelfActivator(const bool value) noexcept;
/** /**
* Currently unused * Currently unused
*/ */
std::vector<int> GetCustomModules(); [[nodiscard]] std::vector<int32_t> GetCustomModules() const noexcept;
/** /**
* Currently unused * Currently unused
*/ */
void SetCustomModules(std::vector<int> value); void SetCustomModules(const std::vector<int32_t>& value) noexcept;
/** /**
* Returns the activity ID for participating in this quickbuild * Returns the activity ID for participating in this quickbuild
* @return 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 * Sets the activity ID for participating in this quickbuild
* @param value the activity ID to set * @param value the activity ID to set
*/ */
void SetActivityId(int value); void SetActivityId(const int32_t value) noexcept;
/** /**
* Currently unused * Currently unused
*/ */
int GetPostImaginationCost(); [[nodiscard]] int32_t GetPostImaginationCost() const noexcept;
/** /**
* Currently unused * 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 * 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 * @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 * Sets the time it takes for an incomplete quickbuild to be smashed automatically
* @param value the time to set * @param value the time to set
*/ */
void SetTimeBeforeSmash(float value); void SetTimeBeforeSmash(const float value) noexcept;
/** /**
* Returns the current quickbuild state * Returns the current quickbuild state
@ -179,19 +179,19 @@ public:
* Returns the player that is currently building this quickbuild * Returns the player that is currently building this quickbuild
* @return 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 * Returns whether or not the player is repositioned when initiating the quickbuild
* @return 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 * 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 * @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 * Adds a callback that is called when the quickbuild is completed
@ -209,7 +209,7 @@ public:
* Resets the quickbuild * Resets the quickbuild
* @param failed whether or not the player failed to complete the quickbuild, triggers an extra animation * @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 * Cancels the quickbuild if it wasn't completed
@ -217,7 +217,7 @@ public:
* @param failReason the reason the quickbuild was cancelled * @param failReason the reason the quickbuild was cancelled
* @param skipChecks whether or not to skip the check for the quickbuild not being completed * @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: private:
/** /**
* Whether or not the quickbuild state has been changed since we last serialized it. * Whether or not the quickbuild state has been changed since we last serialized it.
@ -287,7 +287,7 @@ private:
/** /**
* The imagination that's deducted when completing the quickbuild * The imagination that's deducted when completing the quickbuild
*/ */
int m_TakeImagination = 0; int32_t m_TakeImagination = 0;
/** /**
* Currently unused * Currently unused
@ -302,17 +302,17 @@ private:
/** /**
* Currently unused * Currently unused
*/ */
std::vector<int> m_CustomModules{}; std::vector<int32_t> m_CustomModules{};
/** /**
* The activity ID that players partake in when doing this quickbuild * The activity ID that players partake in when doing this quickbuild
*/ */
int m_ActivityId = 0; int32_t m_ActivityId = 0;
/** /**
* Currently unused * 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 * The time it takes for the quickbuild to reset when it's not completed yet
@ -327,7 +327,7 @@ private:
/** /**
* The amount of imagination that was drained when building this quickbuild * 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 * Whether to reposition the player or not when building
@ -337,7 +337,7 @@ private:
/** /**
* Currently unused * Currently unused
*/ */
float m_SoftTimer = 0; int32_t m_SoftTimer = 0;
/** /**
* The ID of the entity that's currently building the quickbuild * The ID of the entity that's currently building the quickbuild
@ -353,13 +353,13 @@ private:
* Starts the quickbuild for a certain entity * Starts the quickbuild for a certain entity
* @param user the entity to start the quickbuild * @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 * Completes the quickbuild for an entity, dropping loot and despawning the activator
* @param user the entity that completed the quickbuild * @param user the entity that completed the quickbuild
*/ */
void CompleteQuickBuild(Entity* user); void CompleteQuickBuild(Entity* const user);
}; };
#endif // QUICKBUILDCOMPONENT_H #endif // QUICKBUILDCOMPONENT_H

View File

@ -2,7 +2,7 @@
#include "Action.h" #include "Action.h"
AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) { AddStripMessage::AddStripMessage(AMFArrayValue* const arguments) : BehaviorMessageBase{ arguments } {
actionContext = ActionContext(arguments); actionContext = ActionContext(arguments);
position = StripUiPosition(arguments); position = StripUiPosition(arguments);

View File

@ -18,7 +18,7 @@ class AMFArrayValue;
*/ */
class AddStripMessage : public BehaviorMessageBase { class AddStripMessage : public BehaviorMessageBase {
public: public:
AddStripMessage(AMFArrayValue* arguments); AddStripMessage(AMFArrayValue* const arguments);
StripUiPosition GetPosition() const { return position; }; StripUiPosition GetPosition() const { return position; };
ActionContext GetActionContext() const { return actionContext; }; ActionContext GetActionContext() const { return actionContext; };
std::vector<Action> GetActionsToAdd() const; std::vector<Action> GetActionsToAdd() const;

View File

@ -8,9 +8,9 @@ BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) {
this->behaviorId = GetBehaviorIdFromArgument(arguments); this->behaviorId = GetBehaviorIdFromArgument(arguments);
} }
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) { int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* const arguments) {
const auto* key = "BehaviorID"; const char* const key = "BehaviorID";
auto* behaviorIDValue = arguments->Get<std::string>(key); const auto* const behaviorIDValue = arguments->Get<std::string>(key);
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
this->behaviorId = this->behaviorId =
@ -22,11 +22,9 @@ int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments)
return this->behaviorId; return this->behaviorId;
} }
int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) { int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName) const {
auto* actionIndexAmf = arguments->Get<double>(keyName); const auto* const actionIndexAmf = arguments->Get<double>(keyName);
if (!actionIndexAmf) { if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex");
throw std::invalid_argument("Unable to find actionIndex");
}
return static_cast<int32_t>(actionIndexAmf->GetValue()); return static_cast<int32_t>(actionIndexAmf->GetValue());
} }

View File

@ -15,13 +15,13 @@ enum class BehaviorState : uint32_t;
*/ */
class BehaviorMessageBase { class BehaviorMessageBase {
public: public:
static inline int32_t DefaultBehaviorId = -1; static constexpr int32_t DefaultBehaviorId = -1;
const int32_t GetBehaviorId() const { return behaviorId; }; [[nodiscard]] int32_t GetBehaviorId() const { return behaviorId; };
bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; }; [[nodiscard]] bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; };
BehaviorMessageBase(AMFArrayValue* arguments); BehaviorMessageBase(AMFArrayValue* const arguments);
protected: protected:
int32_t GetBehaviorIdFromArgument(AMFArrayValue* arguments); [[nodiscard]] int32_t GetBehaviorIdFromArgument(AMFArrayValue* const arguments);
int32_t GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName = "actionIndex"); [[nodiscard]] int32_t GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName = "actionIndex") const;
int32_t behaviorId = DefaultBehaviorId; int32_t behaviorId = DefaultBehaviorId;
}; };

View File

@ -12,16 +12,12 @@ void AmDropshipComputer::OnStartup(Entity* self) {
void AmDropshipComputer::OnUse(Entity* self, Entity* user) { void AmDropshipComputer::OnUse(Entity* self, Entity* user) {
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>(); auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
if (quickBuildComponent == nullptr || quickBuildComponent->GetState() != eQuickBuildState::COMPLETED) { if (!quickBuildComponent || quickBuildComponent->GetState() != eQuickBuildState::COMPLETED) return;
return;
}
auto* missionComponent = user->GetComponent<MissionComponent>(); auto* missionComponent = user->GetComponent<MissionComponent>();
auto* inventoryComponent = user->GetComponent<InventoryComponent>(); auto* inventoryComponent = user->GetComponent<InventoryComponent>();
if (missionComponent == nullptr || inventoryComponent == nullptr) { if (!missionComponent || !inventoryComponent) return;
return;
}
if (inventoryComponent->GetLotCount(m_NexusTalonDataCard) != 0 || missionComponent->GetMission(979)->GetMissionState() == eMissionState::COMPLETE) { if (inventoryComponent->GetLotCount(m_NexusTalonDataCard) != 0 || missionComponent->GetMission(979)->GetMissionState() == eMissionState::COMPLETE) {
return; return;