aboutsummaryrefslogtreecommitdiff
path: root/src/creature.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-04-15 15:23:23 -0400
committerYour Name <you@example.com>2021-04-15 15:23:23 -0400
commitdfce4d0398a8bafbb7ad7a31345af181c0269c09 (patch)
tree695162ff8cc25e146f52d9e26fe19ffa9934b3d6 /src/creature.cc
parent9034c3d2533177f7cb7a7ce939ec53f7fa63f60e (diff)
downloaddmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.tar.gz
dmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.tar.bz2
dmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.zip
Added spells
Diffstat (limited to 'src/creature.cc')
-rw-r--r--src/creature.cc101
1 files changed, 6 insertions, 95 deletions
diff --git a/src/creature.cc b/src/creature.cc
index 24a8087..3587ab0 100644
--- a/src/creature.cc
+++ b/src/creature.cc
@@ -12,24 +12,9 @@ typedef nlohmann::json json;
using namespace std;
namespace creature {
- vector<dmgType> initDmgType(const json& dat) {
- vector<dmgType> stuff;
- for(json x : dat) {
- stuff.push_back(dmgType(x));
- }
- return stuff;
- }
-
- Creature::Creature(json data)
- : creatureName(data["name"]), size(data["size"]), type(data["type"]), alignment(data["alignment"]), hdCount(data["hit_die_count"]), hdSides(data["hit_die_sides"]), speed(data["speed"]), stats(data["stats"]), skills(data["skills"]), saves(data["saves"]), langs(data["langs"]), cr(data["cr"]), proficiency(data["prof"]), dmgImmunities(initDmgType(data["d_immunities"])), dmgResistances(initDmgType(data["d_resistances"])), dmgVulnerabilities(initDmgType(data["d_vulnerabilities"])), condImmunities(initDmgType(data["c_immunities"]))
+ Creature::Creature(const json& data)
+ : inventory(json2ptrvec<item::Item>(data["inventory"])), creatureName(data["name"]), size(data["size"]), type(data["type"]), alignment(data["alignment"]), hdCount(data["hit_die_count"]), hdSides(data["hit_die_sides"]), speed(data["speed"]), stats(data["stats"]), skills(data["skills"]), saves(data["saves"]), langs(data["langs"]), cr(data["cr"]), proficiency(data["prof"]), dmgImmunities(json2vec<dmgType>(data["d_immunities"])), dmgResistances(json2vec<dmgType>(data["d_resistances"])), dmgVulnerabilities(json2vec<dmgType>(data["d_vulnerabilities"])), condImmunities(json2vec<dmgType>(data["c_immunities"])), features(json2ptrvec<feature::Feature>(data["features"]))
{
- // Initialize features + inventory
- for(json data : data["features"]) {
- features.push_back(feature::Feature::create(data));
- }
- for(json data : data["inventory"]) {
- inventory.push_back(item::Item::create(data));
- }
// Initialize names and hp
if(((map<string, json>) data).contains("givenName")) {
givenName = data["givenName"];
@@ -53,14 +38,6 @@ namespace creature {
return ret;
}
- template<typename T> vector<json> getJsonVectR(vector<T> src) {
- vector<json> ret;
- for(T i : src) {
- ret.push_back(i.toJson());
- }
- return ret;
- }
-
nlohmann::json Creature::toJson() const {
return nlohmann::json({
{"name", creatureName},
@@ -76,10 +53,10 @@ namespace creature {
{"langs", langs},
{"cr", cr},
{"prof", proficiency},
- {"d_immunities", getJsonVectR(dmgImmunities)},
- {"d_resistances", getJsonVectR(dmgResistances)},
- {"d_vulnerabilities", getJsonVectR(dmgVulnerabilities)},
- {"c_immunities", getJsonVectR(condImmunities)},
+ {"d_immunities", dmgImmunities},
+ {"d_resistances", dmgResistances},
+ {"d_vulnerabilities", dmgVulnerabilities},
+ {"c_immunities", condImmunities},
{"givenName", givenName},
{"hpMax", hpMax},
{"hp", hp},
@@ -88,48 +65,6 @@ namespace creature {
});
}
- Creature::~Creature() {}
-
- string Creature::getCreatureName() const {
- return creatureName;
- }
-
- string Creature::getGivenName() const {
- return givenName;
- }
-
- void Creature::setGivenName(string name) {
- givenName = name;
- }
-
- string Creature::getType() const {
- return type;
- }
-
- string Creature::getSize() const {
- return size;
- }
-
- string Creature::getAlignment() const {
- return alignment;
- }
-
- double Creature::getCR() const {
- return cr;
- }
-
- string Creature::getLanguages() const {
- return langs;
- }
-
- int Creature::getHP() const {
- return hp;
- }
-
- int Creature::getHPMax() const {
- return hpMax;
- }
-
// True if type without matching qualifiers is in subdata
bool conditionApplies(const string& type, const vector<string>& qualifiers, const vector<dmgType> subdata) {
bool applies = false;
@@ -158,10 +93,6 @@ namespace creature {
}
}
- vector<string> Creature::getSenses() const {
- return senses;
- }
-
int Creature::getSkillBonus(const string& skill) const {
int bonus = this->getBonus(skill2ability[skill]);
if(skills.contains(skill)) {
@@ -170,14 +101,6 @@ namespace creature {
return bonus;
}
- int Creature::getScore(const string& ability) const {
- return stats.at(ability);
- }
-
- string Creature::getSpeed() const {
- return speed;
- }
-
int Creature::getAbilitySaveBonus(const string& ability) const {
int bonus = this->getBonus(ability);
if(find(saves.begin(), saves.end(), ability) != saves.end()) {
@@ -186,18 +109,6 @@ namespace creature {
return bonus;
}
- int Creature::getProficiency() const {
- return proficiency;
- }
-
- vector<shared_ptr<feature::Feature>> Creature::getFeatures() const {
- return features;
- }
-
- vector<shared_ptr<item::Item>> Creature::getInventory() const {
- return inventory;
- }
-
void Creature::addInventoryItem(shared_ptr<item::Item> item) {
inventory.push_back(item);
}