Compare commits

...

6 commits

Author SHA1 Message Date
79d575da10
Documentation 2026-02-27 22:10:35 +01:00
f06227f02e
Removing useless intermediate variables. 2026-02-27 22:10:11 +01:00
66911014f0
Add new line at the end of file 2026-02-27 20:36:08 +01:00
ea1206e58c
Add documentation 2026-02-27 20:35:51 +01:00
3c68557549
Remove useless namespace 2026-02-27 20:35:34 +01:00
ebd1cc2f05
Add constexpr 2026-02-27 20:34:54 +01:00
3 changed files with 60 additions and 36 deletions

View file

@ -55,8 +55,22 @@ namespace character {
static void from_json(const json &j, container &billy);
/*!
* \brief It inserts the object inside the sheet.
*
* This method changes values inside the sheet according to the book's rules.
* \param sheet sheet to insert object into
* \param objType the object to insert
* \return true: object inserted, false otherwise
*/
[[nodiscard]] bool insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept;
/*!
* \brief
* \param sheet sheet to erase object from
* \param objToErase the object to erase
* \return true: object erased, false otherwise
*/
[[nodiscard]] bool erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept;
[[nodiscard]] static bool is_full(const CharacterSheet &sheet) noexcept;
@ -72,13 +86,15 @@ namespace character {
std::minus<std::uint32_t> minus;
/*!
* \brief
* \param arg object used to change values
* \param sheet sheet to change
* \param operation Operation to apply to change values
*/
static void change_carac(const billyObjects &arg,
CharacterSheet &sheet,
characteristic::Characteristic &localHabilete,
characteristic::Characteristic &localAdresse,
characteristic::Characteristic &localEndurance,
characteristic::Characteristic &localChance,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation) noexcept;
const std::function<uint32_t(uint32_t, uint32_t)> &operation) noexcept;
};
}

View file

@ -12,6 +12,10 @@ namespace character {
}
namespace character::characteristic {
/*!
* \brief Different characteristic type
*/
enum class characType : std::uint8_t {
Adresse = 0,
Endurance = 1,
@ -19,17 +23,35 @@ namespace character::characteristic {
Habilete = 3
};
/*!
* \brief This class represents a characteristic for Billy (one of characType)
*/
class Characteristic {
protected:
friend character::BillyObjects;
friend BillyObjects;
using defaultValue = std::numeric_limits<std::int32_t>;
//! Total point for this charac
mutable std::int32_t total{ defaultValue::max() };
//! Base value
const std::uint32_t base{ 0 };
//! Value depending of the characType for this characteristic.
std::uint32_t carac{ 0 };
//! Value changed from a billyObjects (billyEnums) possessed
std::uint32_t materiel{ 0 };
//! Additional value when creating the character
std::uint32_t additional{ 0 };
static std::uint32_t get_base(const characType inType) noexcept {
/*!
* \brief Get base value depending of the characType
* \param inType Characteristic type used to get base number
* \return Base value depending of the characType
*/
static constexpr std::uint32_t get_base(const characType inType) noexcept {
switch (inType) {
case characType::Adresse:
return 1;
@ -44,21 +66,21 @@ namespace character::characteristic {
public:
const characType type{ characType::Adresse };
Characteristic() noexcept = default;
constexpr Characteristic() noexcept = default;
Characteristic(const characType inType,
const std::uint32_t carac,
const std::uint32_t materiel,
const std::uint32_t additional) :
constexpr Characteristic(const characType inType,
const std::uint32_t carac,
const std::uint32_t materiel,
const std::uint32_t additional) :
base(get_base(inType)),
carac(carac),
materiel(materiel),
additional(additional),
type(inType) { (void) get_total(); }
explicit Characteristic(const characType inType) : Characteristic(inType, 0, 0, 0) {}
constexpr explicit Characteristic(const characType inType) : Characteristic(inType, 0, 0, 0) {}
Characteristic(const Characteristic &charac) noexcept = default;
constexpr Characteristic(const Characteristic &charac) noexcept = default;
Characteristic &operator=(const Characteristic &charac) noexcept {
const_cast<std::uint32_t &>(base) = charac.base;
@ -109,4 +131,4 @@ namespace character::characteristic {
}
#endif //BILLYSHEET_CHARACTERISTIC_HPP
#endif //BILLYSHEET_CHARACTERISTIC_HPP

View file

@ -40,18 +40,13 @@ namespace character {
const auto &object = sheet.objects[objType];
sheet.available_objects.erase(objType);
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);
auto &local_endurance = static_cast<Characteristic &>(sheet.endurance);
auto &local_chance = static_cast<Characteristic &>(sheet.chance);
std::visit(overloaded{
[&](const weapons &) { ++sheet.nb_weapons; },
[&](const equipments &) { ++sheet.nb_equipments; },
[&](const tools &) { ++sheet.nb_tools; },
},
objType);
change_carac(object, sheet, local_habilete, local_adresse, local_endurance, local_chance, plus);
change_carac(object, sheet, plus);
return true;
}
return false;
@ -63,18 +58,13 @@ namespace character {
sheet.objects.erase(objToErase);
sheet.available_objects.insert(objToErase);
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);
auto &local_endurance = static_cast<Characteristic &>(sheet.endurance);
auto &local_chance = static_cast<Characteristic &>(sheet.chance);
std::visit(overloaded{
[&](const weapons &) { --sheet.nb_weapons; },
[&](const equipments &) { --sheet.nb_equipments; },
[&](const tools &) { --sheet.nb_tools; }
},
objToErase);
change_carac(obj, sheet, local_habilete, local_adresse, local_endurance, local_chance, minus);
change_carac(obj, sheet, minus);
return true;
}
return false;
@ -86,16 +76,12 @@ namespace character {
void BillyObjects::change_carac(const billyObjects &arg,
CharacterSheet &sheet,
Characteristic &localHabilete,
Characteristic &localAdresse,
Characteristic &localEndurance,
Characteristic &localChance,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation)
const std::function<uint32_t(uint32_t, uint32_t)> &operation)
noexcept {
localHabilete.materiel = operation(localHabilete.materiel, arg->add_materiel(localHabilete.type));
localAdresse.materiel = operation(localAdresse.materiel, arg->add_materiel(localAdresse.type));
localEndurance.materiel = operation(localEndurance.materiel, arg->add_materiel(localEndurance.type));
localChance.materiel = operation(localChance.materiel, arg->add_materiel(localChance.type));
sheet.habilete.materiel = operation(sheet.habilete.materiel, arg->add_materiel(sheet.habilete.type));
sheet.adresse.materiel = operation(sheet.adresse.materiel, arg->add_materiel(sheet.adresse.type));
sheet.endurance.materiel = operation(sheet.endurance.materiel, arg->add_materiel(sheet.endurance.type));
sheet.chance.materiel = operation(sheet.chance.materiel, arg->add_materiel(sheet.chance.type));
sheet.armor = operation(sheet.armor, arg->add_armor());
sheet.damage = operation(sheet.armor, arg->add_damage());
sheet.critique = operation(sheet.critique, arg->add_critique());