CreatureLib/src/Library/CreatureData/CreatureSpecies.hpp

83 lines
5.0 KiB
C++

#ifndef CREATURELIB_CREATURESPECIES_HPP
#define CREATURELIB_CREATURESPECIES_HPP
#include "../Gender.hpp"
#include "SpeciesVariant.hpp"
namespace CreatureLib::Library {
/// @brief This holds the data required for a species of a creature, so the general data we can describe different
// creatures with.
class CreatureSpecies {
struct impl;
std::unique_ptr<impl> _impl;
public:
/// @brief Instantiates a CreatureSpecies.
/// @param id The unique id of the creature species.
/// @param name The name of the creature species. This should generally not be its display name.
/// @param defaultVariant The variant the creature species has by default.
/// @param genderRatio The ratio at which a creature species is male or female. 0 is always female, 1 is always
/// male. -1 makes the creature genderless.
/// @param growthRate The name of the growthrate this creature species should follow. These should be defined in
/// the growthrate library.
/// @param captureRate The chance to capture the creature species, between 0 and 255. 255 means instant capture,
/// 0 means impossible to capture.
/// @param flags A set of flags for use by the developer. These can be used for easy grouping.
CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate,
std::unordered_set<uint32_t> flags = {});
virtual ~CreatureSpecies();
/// @brief Returns the unique id of the creature species.
/// @return The unique id of the creature species
uint16_t GetId() const noexcept;
/// @brief Returns the gender rate of the creature species.
/// @return The gender rate of the creature species. 0 is always female, 1 is always male. -1 makes the creature
/// genderless.
float GetGenderRate() const noexcept;
/// @brief Returns the growthrate name of the creature species, as defined in the growthrate library.
/// @return The growthrate name of the creature species, as defined in the growthrate library.
const ArbUt::StringView& GetGrowthRate() const noexcept;
/// @brief Returns the capture rate of the creature species.
/// @return The base capture rate of the creature species. 255 means instant capture, 0 means impossible to
/// capture.
uint8_t GetCaptureRate() const noexcept;
/// @brief Checks whether the species contains a variant with a specific name.
/// @param key The name of the variant that's being looked for.
/// @return True if the species contains the variant, false otherwise.
[[nodiscard]] bool HasVariant(const ArbUt::BasicStringView& key) const noexcept;
/// @brief Checks whether the species contains a variant with a specific name.
/// @param hash The string hash of the variant that's being looked for. This hash can be retrieved from the
/// StringView class.
/// @return True if the species contains the variant, false otherwise.
[[nodiscard]] bool HasVariant(uint32_t hash) const noexcept;
/// @brief Try to get a variant of the species with a specific name.
/// @param name The name of the variant that's being looked for.
/// @param out If a variant is found, it will be put in this variable. If not, this will remain unchanged.
/// @return True if the species contains the variant, false otherwise.
[[nodiscard]] bool TryGetVariant(const ArbUt::BasicStringView& name,
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept;
/// @brief Try to get a variant of the species with a specific name.
/// @param name The string hash of the variant that's being looked for. This hash can be retrieved from the
/// StringView class.
/// @param out If a variant is found, it will be put in this variable. If not, this will remain unchanged.
/// @return True if the species contains the variant, false otherwise.
[[nodiscard]] bool TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept;
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(const ArbUt::BasicStringView& key) const;
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const;
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const noexcept;
[[nodiscard]] const ArbUt::StringView& GetName() const noexcept;
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant);
const ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>>& GetVariantsIterator() const;
bool HasFlag(const ArbUt::StringView& key) const noexcept;
bool HasFlag(uint32_t keyHash) const noexcept;
};
}
#endif // CREATURELIB_CREATURESPECIES_HPP