diff options
author | Your Name <you@example.com> | 2021-04-29 14:17:08 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-04-29 14:17:08 -0400 |
commit | 5a813a75412ac9b8fadb90c9abd46dd95aee8e9b (patch) | |
tree | 75c5466d459c793430a6481cd276a624cd843794 /src/creature.h | |
parent | cd57ad6e208728bafcbc8c7d7b85d88603706978 (diff) | |
download | dmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.tar.gz dmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.tar.bz2 dmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.zip |
Removed data files from repo
Diffstat (limited to 'src/creature.h')
-rw-r--r-- | src/creature.h | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/creature.h b/src/creature.h index 1c8db21..c3ce5ae 100644 --- a/src/creature.h +++ b/src/creature.h @@ -1,25 +1,31 @@ #pragma once #include "json.hpp" -#include "jsonable.h" #include "rules.h" +#include "utils.h" +#include "entry.h" +#include <cmath> namespace entry { class Feature; -} -namespace entry { class Item; } -class Armor; -class Weapon; typedef nlohmann::json json; namespace creature { + class Creature; + class dmgType : public Jsonable { public: dmgType(const json& data) : type(data["type"]), qualifiers(data["qualifiers"]) {} std::string type; std::vector<std::string> qualifiers; + operator string() const { + if(qualifiers.empty()) { + return type; + } + return utils::join(qualifiers, ", ") + " " + type; + } json toJson(void) const { return json({ {"type", type}, @@ -29,9 +35,15 @@ namespace creature { }; - class Creature : public Jsonable { + // 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); + Creature(const json& data, const json& base); virtual ~Creature() {}; // Getters @@ -40,10 +52,13 @@ namespace creature { std::map<rules::Skill, int> getSkills(void) const; std::map<rules::Ability, int> getSaves(void) const; + //Override getText + virtual std::string getText() const override {return genText(*this);} + // Inline getters - std::string getCreatureName(void) const {return creatureName;} + std::string getCreatureName(void) const {return getName();} std::string getGivenName(void) const {return givenName;} - std::string getType(void) const {return type;} + //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;} @@ -54,10 +69,14 @@ namespace creature { std::vector<std::string> getSenses(void) const {return senses;} 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 (int) (getScore(ability) - 10) / 2;} + int getBonus(const rules::Ability& ability) const {return std::floor((getScore(ability) - 10) / 2.0);} int getProficiency(void) const {return proficiency;} std::vector<std::shared_ptr<entry::Feature>> getFeatures(void) const {return features;} 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;} // Setters (mutators) @@ -80,9 +99,9 @@ namespace creature { std::map<rules::Skill, int> skills; //Immutable variables - const std::string creatureName; + //const std::string creatureName; const std::string size; - const std::string type; + //const std::string type; const std::string alignment; const int hdCount; const int hdSides; @@ -113,10 +132,4 @@ namespace creature { } return Ts; } - - // 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); } |