Compile time option to change bit size of level.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
ba97fa8579
commit
39e1295013
|
@ -4,7 +4,7 @@ using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
export uint8_t CreatureLib_Creature_Construct(Creature*& out, const BattleLibrary* library,
|
export uint8_t CreatureLib_Creature_Construct(Creature*& out, const BattleLibrary* library,
|
||||||
const CreatureLib::Library::CreatureSpecies* species,
|
const CreatureLib::Library::CreatureSpecies* species,
|
||||||
const CreatureLib::Library::SpeciesVariant* variant, uint8_t level,
|
const CreatureLib::Library::SpeciesVariant* variant, level_int_t level,
|
||||||
uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender,
|
uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender,
|
||||||
uint8_t coloring, const CreatureLib::Library::Item* heldItem,
|
uint8_t coloring, const CreatureLib::Library::Item* heldItem,
|
||||||
const char* nickname, bool secretTalent, uint8_t talent,
|
const char* nickname, bool secretTalent, uint8_t talent,
|
||||||
|
@ -32,7 +32,7 @@ export uint8_t CreatureLib_Creature_ChangeVariant(Creature* p, const CreatureLib
|
||||||
Try(p->ChangeVariant(variant);)
|
Try(p->ChangeVariant(variant);)
|
||||||
}
|
}
|
||||||
|
|
||||||
SIMPLE_GET_FUNC(Creature, GetLevel, uint8_t);
|
SIMPLE_GET_FUNC(Creature, GetLevel, level_int_t);
|
||||||
SIMPLE_GET_FUNC(Creature, GetExperience, uint32_t);
|
SIMPLE_GET_FUNC(Creature, GetExperience, uint32_t);
|
||||||
SIMPLE_GET_FUNC(Creature, GetUniqueIdentifier, uint32_t);
|
SIMPLE_GET_FUNC(Creature, GetUniqueIdentifier, uint32_t);
|
||||||
SIMPLE_GET_FUNC(Creature, GetGender, CreatureLib::Library::Gender);
|
SIMPLE_GET_FUNC(Creature, GetGender, CreatureLib::Library::Gender);
|
||||||
|
|
|
@ -9,8 +9,8 @@ export GrowthRate* CreatureLib_LookupGrowthRate_Construct(uint32_t experiencePer
|
||||||
return new LookupGrowthRate(exp);
|
return new LookupGrowthRate(exp);
|
||||||
};
|
};
|
||||||
|
|
||||||
export uint8_t CreatureLib_ExternGrowthRate_Construct(GrowthRate*& out, uint8_t (*calcLevel)(uint32_t),
|
export uint8_t CreatureLib_ExternGrowthRate_Construct(GrowthRate*& out, level_int_t (*calcLevel)(uint32_t),
|
||||||
uint32_t (*calcExperience)(uint8_t)) {
|
uint32_t (*calcExperience)(level_int_t)) {
|
||||||
Try(out = new ExternGrowthRate(calcLevel, calcExperience);)
|
Try(out = new ExternGrowthRate(calcLevel, calcExperience);)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ export void CreatureLib_GrowthRate_Destruct(const GrowthRate* p) { delete p; }
|
||||||
export void CreatureLib_LookupGrowthRate_Destruct(const LookupGrowthRate* p) { delete p; }
|
export void CreatureLib_LookupGrowthRate_Destruct(const LookupGrowthRate* p) { delete p; }
|
||||||
export void CreatureLib_ExternGrowthRate_Destruct(const ExternGrowthRate* p) { delete p; }
|
export void CreatureLib_ExternGrowthRate_Destruct(const ExternGrowthRate* p) { delete p; }
|
||||||
|
|
||||||
export uint8_t CreatureLib_GrowthRate_CalculateLevel(uint8_t& out, const GrowthRate* p, uint32_t experience) {
|
export uint8_t CreatureLib_GrowthRate_CalculateLevel(level_int_t& out, const GrowthRate* p, uint32_t experience) {
|
||||||
Try(out = p->CalculateLevel(experience);)
|
Try(out = p->CalculateLevel(experience);)
|
||||||
}
|
}
|
||||||
|
|
||||||
export uint8_t CreatureLib_GrowthRate_CalculateExperience(uint32_t& out, const GrowthRate* p, uint8_t level) {
|
export uint8_t CreatureLib_GrowthRate_CalculateExperience(uint32_t& out, const GrowthRate* p, level_int_t level) {
|
||||||
Try(out = p->CalculateExperience(level);)
|
Try(out = p->CalculateExperience(level);)
|
||||||
}
|
}
|
|
@ -8,22 +8,22 @@ export GrowthRateLibrary* CreatureLib_GrowthRateLibrary_Construct(size_t initial
|
||||||
|
|
||||||
export void CreatureLib_GrowthRateLibrary_Destruct(GrowthRateLibrary* p) { delete p; }
|
export void CreatureLib_GrowthRateLibrary_Destruct(GrowthRateLibrary* p) { delete p; }
|
||||||
|
|
||||||
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(uint8_t& out, GrowthRateLibrary* library,
|
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevel(level_int_t& out, GrowthRateLibrary* library,
|
||||||
const char* growthRate, uint32_t experience) {
|
const char* growthRate, uint32_t experience) {
|
||||||
Try(out = library->CalculateLevel(ArbUt::StringView::CalculateHash(growthRate), experience);)
|
Try(out = library->CalculateLevel(ArbUt::StringView::CalculateHash(growthRate), experience);)
|
||||||
}
|
}
|
||||||
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(uint8_t& out, GrowthRateLibrary* library,
|
export uint8_t CreatureLib_GrowthRateLibrary_CalculateLevelWithHash(level_int_t& out, GrowthRateLibrary* library,
|
||||||
uint32_t growthRateHash, uint32_t experience) {
|
uint32_t growthRateHash, uint32_t experience) {
|
||||||
Try(out = library->CalculateLevel(growthRateHash, experience);)
|
Try(out = library->CalculateLevel(growthRateHash, experience);)
|
||||||
}
|
}
|
||||||
|
|
||||||
export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperience(uint32_t& out, GrowthRateLibrary* library,
|
export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperience(uint32_t& out, GrowthRateLibrary* library,
|
||||||
const char* growthRate, uint8_t level) {
|
const char* growthRate, level_int_t level) {
|
||||||
Try(out = library->CalculateExperience(ArbUt::StringView::CalculateHash(growthRate), level);)
|
Try(out = library->CalculateExperience(ArbUt::StringView::CalculateHash(growthRate), level);)
|
||||||
}
|
}
|
||||||
|
|
||||||
export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(uint32_t& out, GrowthRateLibrary* library,
|
export uint8_t CreatureLib_GrowthRateLibrary_CalculateExperienceWithHash(uint32_t& out, GrowthRateLibrary* library,
|
||||||
uint32_t growthRateHash, uint8_t level) {
|
uint32_t growthRateHash, level_int_t level) {
|
||||||
Try(out = library->CalculateExperience(growthRateHash, level);)
|
Try(out = library->CalculateExperience(growthRateHash, level);)
|
||||||
}
|
}
|
||||||
export uint8_t CreatureLib_GrowthRateLibrary_AddGrowthRate(GrowthRateLibrary* library, const char* growthRateName,
|
export uint8_t CreatureLib_GrowthRateLibrary_AddGrowthRate(GrowthRateLibrary* library, const char* growthRateName,
|
||||||
|
|
|
@ -8,7 +8,7 @@ export uint8_t CreatureLib_LearnableAttacks_Construct(LearnableAttacks*& out, si
|
||||||
|
|
||||||
export void CreatureLib_LearnableAttacks_Destruct(LearnableAttacks* p) { delete p; }
|
export void CreatureLib_LearnableAttacks_Destruct(LearnableAttacks* p) { delete p; }
|
||||||
|
|
||||||
export void CreatureLib_LearnableAttacks_AddLevelAttack(LearnableAttacks* p, uint8_t level, const AttackData* attack) {
|
export void CreatureLib_LearnableAttacks_AddLevelAttack(LearnableAttacks* p, level_int_t level, const AttackData* attack) {
|
||||||
p->AddLevelAttack(level, attack);
|
p->AddLevelAttack(level, attack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,5 @@ export const LibrarySettings* CreatureLib_LibrarySettings_Construct(uint8_t maxi
|
||||||
|
|
||||||
export void CreatureLib_LibrarySettings_Destruct(const LibrarySettings* p) { delete p; }
|
export void CreatureLib_LibrarySettings_Destruct(const LibrarySettings* p) { delete p; }
|
||||||
|
|
||||||
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalLevel, uint8_t);
|
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalLevel, level_int_t);
|
||||||
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalAttacks, uint8_t);
|
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalAttacks, uint8_t);
|
|
@ -10,6 +10,7 @@ option(WINDOWS "Whether the build target is Windows or not." OFF)
|
||||||
option(SHARED "Whether we should build a shared library, instead of a static one." OFF)
|
option(SHARED "Whether we should build a shared library, instead of a static one." OFF)
|
||||||
option(TESTS "Whether the test executable should be build as well." OFF)
|
option(TESTS "Whether the test executable should be build as well." OFF)
|
||||||
option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF)
|
option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF)
|
||||||
|
set(LEVEL_SIZE "8" CACHE STRING "Number of bits to store the level as. Can be 8, 16, 32, or 64")
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
add_compile_options(-fconcepts)
|
add_compile_options(-fconcepts)
|
||||||
|
@ -32,6 +33,18 @@ if (SHARED)
|
||||||
set(LIBTYPE SHARED)
|
set(LIBTYPE SHARED)
|
||||||
endif (SHARED)
|
endif (SHARED)
|
||||||
|
|
||||||
|
if (LEVEL_SIZE STREQUAL "8")
|
||||||
|
add_definitions(-DLEVEL_U8)
|
||||||
|
elseif (LEVEL_SIZE STREQUAL "16")
|
||||||
|
add_definitions(-DLEVEL_U16)
|
||||||
|
elseif (LEVEL_SIZE STREQUAL "32")
|
||||||
|
add_definitions(-DLEVEL_U32)
|
||||||
|
elseif (LEVEL_SIZE STREQUAL "64")
|
||||||
|
add_definitions(-DLEVEL_U64)
|
||||||
|
else ()
|
||||||
|
message(FATAL_ERROR, "Invalid level size was given.")
|
||||||
|
endif ()
|
||||||
|
|
||||||
file(GLOB_RECURSE LIBRARY_SRC_FILES
|
file(GLOB_RECURSE LIBRARY_SRC_FILES
|
||||||
"src/*.cpp" "src/*.hpp" "CInterface/*.cpp" "CInterface/*.hpp")
|
"src/*.cpp" "src/*.hpp" "CInterface/*.cpp" "CInterface/*.hpp")
|
||||||
add_library(CreatureLib SHARED ${LIBRARY_SRC_FILES})
|
add_library(CreatureLib SHARED ${LIBRARY_SRC_FILES})
|
||||||
|
|
|
@ -10,7 +10,7 @@ using namespace CreatureLib;
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
Creature::Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
|
Creature::Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
|
||||||
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
||||||
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level,
|
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, level_int_t level,
|
||||||
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
|
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
|
||||||
const ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
|
const ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
|
||||||
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
|
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <Arbutils/Collections/List.hpp>
|
#include <Arbutils/Collections/List.hpp>
|
||||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||||
#include <Arbutils/Memory/UniquePtrList.hpp>
|
#include <Arbutils/Memory/UniquePtrList.hpp>
|
||||||
|
#include "../../Defines.hpp"
|
||||||
#include "../../Library/ClampedStatisticSet.hpp"
|
#include "../../Library/ClampedStatisticSet.hpp"
|
||||||
#include "../../Library/CreatureData/CreatureSpecies.hpp"
|
#include "../../Library/CreatureData/CreatureSpecies.hpp"
|
||||||
#include "../../Library/Items/Item.hpp"
|
#include "../../Library/Items/Item.hpp"
|
||||||
|
@ -29,7 +30,7 @@ namespace CreatureLib::Battling {
|
||||||
ArbUt::BorrowedPtr<const Library::CreatureSpecies> _displaySpecies = nullptr;
|
ArbUt::BorrowedPtr<const Library::CreatureSpecies> _displaySpecies = nullptr;
|
||||||
ArbUt::BorrowedPtr<const Library::SpeciesVariant> _displayVariant = nullptr;
|
ArbUt::BorrowedPtr<const Library::SpeciesVariant> _displayVariant = nullptr;
|
||||||
|
|
||||||
uint8_t _level;
|
level_int_t _level;
|
||||||
uint32_t _experience;
|
uint32_t _experience;
|
||||||
uint32_t _uniqueIdentifier;
|
uint32_t _uniqueIdentifier;
|
||||||
Library::Gender _gender;
|
Library::Gender _gender;
|
||||||
|
@ -67,8 +68,8 @@ namespace CreatureLib::Battling {
|
||||||
public:
|
public:
|
||||||
Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
|
Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
|
||||||
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
||||||
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level, uint32_t experience,
|
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, level_int_t level,
|
||||||
uint32_t uid, Library::Gender gender, uint8_t coloring,
|
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
|
||||||
const ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
|
const ArbUt::BorrowedPtr<const Library::Item> heldItem, const std::string& nickname,
|
||||||
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
|
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
|
||||||
bool allowedExperienceGain = true);
|
bool allowedExperienceGain = true);
|
||||||
|
@ -88,7 +89,7 @@ namespace CreatureLib::Battling {
|
||||||
virtual void ChangeSpecies(const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
virtual void ChangeSpecies(const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
||||||
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant);
|
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant);
|
||||||
virtual void ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant);
|
virtual void ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant);
|
||||||
inline uint8_t GetLevel() const noexcept { return _level; }
|
inline level_int_t GetLevel() const noexcept { return _level; }
|
||||||
inline uint32_t GetExperience() const noexcept { return _experience; }
|
inline uint32_t GetExperience() const noexcept { return _experience; }
|
||||||
inline uint32_t GetUniqueIdentifier() const noexcept { return _uniqueIdentifier; }
|
inline uint32_t GetUniqueIdentifier() const noexcept { return _uniqueIdentifier; }
|
||||||
inline Library::Gender GetGender() const noexcept { return _gender; }
|
inline Library::Gender GetGender() const noexcept { return _gender; }
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef CREATURELIB_DEFINES_HPP
|
||||||
|
#define CREATURELIB_DEFINES_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#if LEVEL_U8
|
||||||
|
typedef uint8_t level_int_t;
|
||||||
|
#elif LEVEL_U16
|
||||||
|
typedef uint16_t level_int_t;
|
||||||
|
#elif LEVEL_U32
|
||||||
|
typedef uint32_t level_int_t;
|
||||||
|
#elif LEVEL_U64
|
||||||
|
typedef uint64_t level_int_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // CREATURELIB_DEFINES_HPP
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
using namespace CreatureLib::Library;
|
using namespace CreatureLib::Library;
|
||||||
|
|
||||||
void LearnableAttacks::AddLevelAttack(uint8_t level, ArbUt::BorrowedPtr<const AttackData> attack) {
|
void LearnableAttacks::AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr<const AttackData> attack) {
|
||||||
if (_learnedByLevel.Has(level)) {
|
if (_learnedByLevel.Has(level)) {
|
||||||
_learnedByLevel[level].Append(attack);
|
_learnedByLevel[level].Append(attack);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||||
#include <Arbutils/Random.hpp>
|
#include <Arbutils/Random.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include "../../Defines.hpp"
|
||||||
#include "../Attacks/AttackData.hpp"
|
#include "../Attacks/AttackData.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
|
@ -22,7 +23,7 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
virtual ~LearnableAttacks() = default;
|
virtual ~LearnableAttacks() = default;
|
||||||
|
|
||||||
void AddLevelAttack(uint8_t level, ArbUt::BorrowedPtr<const AttackData> attack);
|
void AddLevelAttack(level_int_t level, ArbUt::BorrowedPtr<const AttackData> attack);
|
||||||
|
|
||||||
inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); }
|
inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); }
|
||||||
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(uint8_t level) const {
|
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(uint8_t level) const {
|
||||||
|
|
|
@ -2,21 +2,22 @@
|
||||||
#define CREATURELIB_EXTERNGROWTHRATE_HPP
|
#define CREATURELIB_EXTERNGROWTHRATE_HPP
|
||||||
|
|
||||||
#include <Arbutils/Assert.hpp>
|
#include <Arbutils/Assert.hpp>
|
||||||
|
#include "../../Defines.hpp"
|
||||||
#include "GrowthRate.hpp"
|
#include "GrowthRate.hpp"
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
class ExternGrowthRate : public GrowthRate {
|
class ExternGrowthRate : public GrowthRate {
|
||||||
uint8_t (*_calcLevel)(uint32_t experience);
|
level_int_t (*_calcLevel)(uint32_t experience);
|
||||||
uint32_t (*_calcExperience)(uint8_t level);
|
uint32_t (*_calcExperience)(level_int_t level);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline ExternGrowthRate(uint8_t (*calcLevel)(uint32_t), uint32_t (*calcExperience)(uint8_t level))
|
inline ExternGrowthRate(level_int_t (*calcLevel)(uint32_t), uint32_t (*calcExperience)(level_int_t level))
|
||||||
: _calcLevel(calcLevel), _calcExperience(calcExperience) {
|
: _calcLevel(calcLevel), _calcExperience(calcExperience) {
|
||||||
AssertNotNull(calcLevel)
|
AssertNotNull(calcLevel)
|
||||||
AssertNotNull(calcExperience)
|
AssertNotNull(calcExperience)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t CalculateLevel(uint32_t experience) const override { return _calcLevel(experience); }
|
level_int_t CalculateLevel(uint32_t experience) const override { return _calcLevel(experience); }
|
||||||
uint32_t CalculateExperience(uint8_t level) const override { return _calcExperience(level); }
|
uint32_t CalculateExperience(level_int_t level) const override { return _calcExperience(level); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,15 @@
|
||||||
#define CREATURELIB_GROWTHRATE_HPP
|
#define CREATURELIB_GROWTHRATE_HPP
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include "../../Defines.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
class GrowthRate {
|
class GrowthRate {
|
||||||
public:
|
public:
|
||||||
virtual ~GrowthRate() = default;
|
virtual ~GrowthRate() = default;
|
||||||
|
|
||||||
[[nodiscard]] virtual uint8_t CalculateLevel(uint32_t experience) const = 0;
|
[[nodiscard]] virtual level_int_t CalculateLevel(uint32_t experience) const = 0;
|
||||||
[[nodiscard]] virtual uint32_t CalculateExperience(uint8_t level) const = 0;
|
[[nodiscard]] virtual uint32_t CalculateExperience(level_int_t level) const = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, u
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
|
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
|
||||||
uint8_t level) const {
|
level_int_t level) const {
|
||||||
auto find = _growthRates.find(growthRate);
|
auto find = _growthRates.find(growthRate);
|
||||||
if (find == _growthRates.end()) {
|
if (find == _growthRates.end()) {
|
||||||
THROW("Invalid growth rate was requested.");
|
THROW("Invalid growth rate was requested.");
|
||||||
|
@ -27,7 +27,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbU
|
||||||
return find->second->CalculateExperience(level);
|
return find->second->CalculateExperience(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t hash, uint8_t level) const {
|
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t hash, level_int_t level) const {
|
||||||
auto find = _growthRates.find(hash);
|
auto find = _growthRates.find(hash);
|
||||||
if (find == _growthRates.end()) {
|
if (find == _growthRates.end()) {
|
||||||
THROW("Invalid growth rate was requested.");
|
THROW("Invalid growth rate was requested.");
|
||||||
|
|
|
@ -21,8 +21,8 @@ namespace CreatureLib::Library {
|
||||||
|
|
||||||
[[nodiscard]] uint8_t CalculateLevel(const ArbUt::BasicStringView& growthRate, uint32_t experience) const;
|
[[nodiscard]] uint8_t CalculateLevel(const ArbUt::BasicStringView& growthRate, uint32_t experience) const;
|
||||||
[[nodiscard]] uint8_t CalculateLevel(uint32_t hash, uint32_t experience) const;
|
[[nodiscard]] uint8_t CalculateLevel(uint32_t hash, uint32_t experience) const;
|
||||||
[[nodiscard]] uint32_t CalculateExperience(const ArbUt::BasicStringView& growthRate, uint8_t level) const;
|
[[nodiscard]] uint32_t CalculateExperience(const ArbUt::BasicStringView& growthRate, level_int_t level) const;
|
||||||
[[nodiscard]] uint32_t CalculateExperience(uint32_t hash, uint8_t level) const;
|
[[nodiscard]] uint32_t CalculateExperience(uint32_t hash, level_int_t level) const;
|
||||||
|
|
||||||
void AddGrowthRate(uint32_t hash, GrowthRate* rate);
|
void AddGrowthRate(uint32_t hash, GrowthRate* rate);
|
||||||
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* rate);
|
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* rate);
|
||||||
|
|
|
@ -12,8 +12,8 @@ namespace CreatureLib::Library {
|
||||||
public:
|
public:
|
||||||
LookupGrowthRate(const ArbUt::List<uint32_t>& experience) : _experience(experience) {}
|
LookupGrowthRate(const ArbUt::List<uint32_t>& experience) : _experience(experience) {}
|
||||||
|
|
||||||
uint8_t CalculateLevel(uint32_t experience) const override {
|
level_int_t CalculateLevel(uint32_t experience) const override {
|
||||||
for (uint8_t i = 0; i < _experience.Count(); i++) {
|
for (level_int_t i = 0; i < _experience.Count(); i++) {
|
||||||
if (_experience[i] > experience) {
|
if (_experience[i] > experience) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ namespace CreatureLib::Library {
|
||||||
return _experience[_experience.Count() - 1];
|
return _experience[_experience.Count() - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CalculateExperience(uint8_t level) const override { return _experience[level - 1]; }
|
uint32_t CalculateExperience(level_int_t level) const override { return _experience[level - 1]; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,18 @@
|
||||||
#define CREATURELIB_LIBRARYSETTINGS_HPP
|
#define CREATURELIB_LIBRARYSETTINGS_HPP
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include "../Defines.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
class LibrarySettings {
|
class LibrarySettings {
|
||||||
uint8_t _maximalLevel;
|
level_int_t _maximalLevel;
|
||||||
uint8_t _maximalAttacks;
|
uint8_t _maximalAttacks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LibrarySettings(uint8_t maximalLevel, uint8_t maximalAttacks)
|
LibrarySettings(level_int_t maximalLevel, uint8_t maximalAttacks)
|
||||||
: _maximalLevel(maximalLevel), _maximalAttacks(maximalAttacks) {}
|
: _maximalLevel(maximalLevel), _maximalAttacks(maximalAttacks) {}
|
||||||
|
|
||||||
inline uint8_t GetMaximalLevel() const noexcept { return _maximalLevel; }
|
inline level_int_t GetMaximalLevel() const noexcept { return _maximalLevel; }
|
||||||
|
|
||||||
inline uint8_t GetMaximalAttacks() const noexcept { return _maximalAttacks; }
|
inline uint8_t GetMaximalAttacks() const noexcept { return _maximalAttacks; }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue