aboutsummaryrefslogtreecommitdiff
path: root/src/creature.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-09 13:56:46 -0400
committerYour Name <you@example.com>2021-05-09 13:56:46 -0400
commitd13358b71ec15085f2638fd9c3fc634df62dfc94 (patch)
tree467c643a068bf2d83da3632823a6434244ae004e /src/creature.h
parente3aaa68a2ea1a403256150121c57a0287014162f (diff)
downloaddmtool-d13358b71ec15085f2638fd9c3fc634df62dfc94.tar.gz
dmtool-d13358b71ec15085f2638fd9c3fc634df62dfc94.tar.bz2
dmtool-d13358b71ec15085f2638fd9c3fc634df62dfc94.zip
Reduced dependency on json-related hacks
Diffstat (limited to 'src/creature.h')
-rw-r--r--src/creature.h90
1 files changed, 40 insertions, 50 deletions
diff --git a/src/creature.h b/src/creature.h
index 0970f04..6e0d226 100644
--- a/src/creature.h
+++ b/src/creature.h
@@ -19,32 +19,27 @@ typedef nlohmann::json json;
namespace creature {
class Creature;
- class dmgType : public Jsonable {
- public:
- dmgType(const json& data) : type(data["type"]), qualifiers(utils::json2vec<rules::Qualifier>(data["qualifiers"])) {}
- std::string type;
- std::vector<rules::Qualifier> qualifiers;
- std::string getText() const {
- if(qualifiers.empty()) {
- return type;
- }
- return utils::join(qualifiers, ", ") + " " + type;
- }
- json toJson(void) const {
- return json({
- {"type", type},
- {"qualifiers", qualifiers}
- });
+ struct dmgType {
+ std::string type;
+ std::vector<rules::Qualifier> qualifiers;
+ std::string getText() const {
+ if(qualifiers.empty()) {
+ return type;
}
+ return utils::join(qualifiers, ", ") + " " + type;
+ }
+ };
+ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(dmgType, type, qualifiers);
+ struct NatArmor {
+ std::string name;
+ int bonus;
};
+ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NatArmor, name, bonus);
// Convenience function to calculate AC
const int getAC(const Creature& c);
- // Convenience function to spit out everything about it
- std::string genText(const Creature& c);
-
class Creature : public entry::Entry {
public:
Creature(const json& data, const json& base);
@@ -57,16 +52,15 @@ namespace creature {
std::map<rules::Ability, int> getSaves(void) const;
//Override getText
- virtual std::string getText() const override {return genText(*this);}
+ virtual std::string getText() const override;
// Inline getters
std::string getCreatureName(void) const {return getName();}
std::string getGivenName(void) const {return givenName;}
- //std::string getType(void) const {return getType();}
std::string getSize(void) const {return size;}
std::string getAlignment(void) const {return alignment;}
double getCR(void) const {return cr;}
- std::pair<std::string, int> getNaturalArmor(void) const {return {natArmorName, natArmorBonus};}
+ NatArmor getNaturalArmor(void) const {return natural_armor;}
std::string getLanguages(void) const {return langs;}
int getHP(void) const {return hp;}
int getHPMax(void) const {return hpMax;}
@@ -74,14 +68,14 @@ namespace creature {
std::string getSpeed(void) const {return speed;}
int getScore(const rules::Ability& ability) const {return stats.at(ability);}
int getBonus(const rules::Ability& ability) const {return std::floor((getScore(ability) - 10) / 2.0);}
- int getProficiency(void) const {return proficiency;}
+ int getProficiency(void) const {return prof;}
std::vector<std::shared_ptr<entry::Feature>> getFeatures(void) const {return features;}
std::shared_ptr<entry::Spellcasting> getSpellcasting(void) const;
std::vector<std::shared_ptr<entry::Item>> getInventory(void) const {return inventory;}
- std::vector<dmgType> getDmgImmunities(void) const {return dmgImmunities;}
- std::vector<dmgType> getDmgResistances(void) const {return dmgResistances;}
- std::vector<dmgType> getDmgVulnerabilities(void) const {return dmgVulnerabilities;}
- std::vector<dmgType> getCondImmunities(void) const {return condImmunities;}
+ std::vector<dmgType> getDmgImmunities(void) const {return d_immunities;}
+ std::vector<dmgType> getDmgResistances(void) const {return d_resistances;}
+ std::vector<dmgType> getDmgVulnerabilities(void) const {return d_vulnerabilities;}
+ std::vector<dmgType> getCondImmunities(void) const {return c_immunities;}
// Setters (mutators)
@@ -90,7 +84,7 @@ namespace creature {
void applyHealing(int amount);
void setScore(const rules::Ability& ability, int score);
void setProfLevel(const rules::Skill& skill, int level);
- void setProficiency(int prof) {proficiency = prof;}
+ void setProficiency(int p) {prof = p;}
void addInventoryItem(std::shared_ptr<entry::Item> item);
void addSpell(std::shared_ptr<entry::Spell> spell);
void removeSpell(std::shared_ptr<entry::Spell> spell);
@@ -100,34 +94,30 @@ namespace creature {
virtual json toJson(void) const;
private:
- // Mutable variables
+
std::string givenName;
int hpMax;
int hp;
std::vector<std::shared_ptr<entry::Item>> inventory;
std::map<rules::Ability, int> stats;
std::map<rules::Skill, int> skills;
- int proficiency;
-
- //Immutable variables
- //const std::string creatureName;
- const std::string size;
- //const std::string type;
- const std::string alignment;
- const int hdCount;
- const int hdSides;
- const std::string speed;
- const std::vector<rules::Ability> saves;
- const std::vector<std::string> senses;
- const std::string langs;
- const double cr;
- const std::string natArmorName;
- const int natArmorBonus;
- const std::vector<dmgType> dmgImmunities;
- const std::vector<dmgType> dmgResistances;
- const std::vector<dmgType> dmgVulnerabilities;
- const std::vector<dmgType> condImmunities;
- const std::vector<std::shared_ptr<entry::Feature>> features;
+ int prof;
+ std::string size;
+ std::string alignment;
+ int hit_die_count;
+ int hit_die_sides;
+ std::string speed;
+ std::vector<rules::Ability> saves;
+ std::vector<std::string> senses;
+ std::string langs;
+ double cr;
+ bool observant;
+ NatArmor natural_armor;
+ std::vector<dmgType> d_immunities;
+ std::vector<dmgType> d_resistances;
+ std::vector<dmgType> d_vulnerabilities;
+ std::vector<dmgType> c_immunities;
+ std::vector<std::shared_ptr<entry::Feature>> features;
};