From 5a813a75412ac9b8fadb90c9abd46dd95aee8e9b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 29 Apr 2021 14:17:08 -0400 Subject: Removed data files from repo --- src/creature.cc | 99 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 44 deletions(-) (limited to 'src/creature.cc') diff --git a/src/creature.cc b/src/creature.cc index ac616ac..ee735d7 100644 --- a/src/creature.cc +++ b/src/creature.cc @@ -15,19 +15,16 @@ using namespace std; namespace creature { template map makeMap(map src) { - //cout << "Got here!\n"; map ret; for(auto& [abilityStr, val] : src) { ret.insert({T(abilityStr), val}); } - //cout << "And here!\n"; return ret; } - Creature::Creature(const json& data) - : inventory(json2ptrvec(data["inventory"])), stats(makeMap(data["stats"])), skills(makeMap(data["skills"])), 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"]), saves(json2vec(data["saves"])), langs(data["langs"]), cr(data["cr"]), proficiency(data["prof"]), natArmorName(data["natural_armor"]["name"]), natArmorBonus(data["natural_armor"]["bonus"]), dmgImmunities(json2vec(data["d_immunities"])), dmgResistances(json2vec(data["d_resistances"])), dmgVulnerabilities(json2vec(data["d_vulnerabilities"])), condImmunities(json2vec(data["c_immunities"])), features(json2ptrvec(data["features"])) + Creature::Creature(const json& data, const json& base) + : Entry(base), inventory(json2ptrvec(data["inventory"])), stats(makeMap(data["stats"])), skills(makeMap(data["skills"])), size(data["size"]), alignment(data["alignment"]), hdCount(data["hit_die_count"]), hdSides(data["hit_die_sides"]), speed(data["speed"]), saves(json2vec(data["saves"])), langs(data["langs"]), cr(data["cr"]), proficiency(data["prof"]), natArmorName(data["natural_armor"]["name"]), natArmorBonus(data["natural_armor"]["bonus"]), dmgImmunities(json2vec(data["d_immunities"])), dmgResistances(json2vec(data["d_resistances"])), dmgVulnerabilities(json2vec(data["d_vulnerabilities"])), condImmunities(json2vec(data["c_immunities"])), features(json2ptrvec(data["features"])) { - //cout << "...And here!\n"; // Initialize names and hp if(((map) data).contains("givenName")) { givenName = data["givenName"]; @@ -52,30 +49,28 @@ namespace creature { } nlohmann::json Creature::toJson() const { - return nlohmann::json({ - {"name", creatureName}, - {"size", size}, - {"type", type}, - {"alignment", alignment}, - {"hit_die_count", hdCount}, - {"hit_die_sides", hdSides}, - {"speed", speed}, - {"stats", stats}, - {"skills", skills}, - {"saves", saves}, - {"langs", langs}, - {"cr", cr}, - {"prof", proficiency}, - {"d_immunities", dmgImmunities}, - {"d_resistances", dmgResistances}, - {"d_vulnerabilities", dmgVulnerabilities}, - {"c_immunities", condImmunities}, - {"givenName", givenName}, - {"hpMax", hpMax}, - {"hp", hp}, - {"inventory", getJsonVectP(inventory)}, - {"features", getJsonVectP(features)} - }); + nlohmann::json data = Entry::toJson(); + data["size"] = size; + data["alignment"] = alignment; + data["hit_die_count"] = hdCount; + data["hit_die_sides"] = hdSides; + data["speed"] = speed; + data["stats"] = stats; + data["skills"] = skills; + data["saves"] = saves; + data["langs"] = langs; + data["cr"] = cr; + data["prof"] = proficiency; + data["d_immunities"] = dmgImmunities; + data["d_resistances"] = dmgResistances; + data["d_vulnerabilities"] = dmgVulnerabilities; + data["c_immunities"] = condImmunities; + data["givenName"] = givenName; + data["hpMax"] = hpMax; + data["hp"] = hp; + data["inventory"] = getJsonVectP(inventory); + data["features"] = getJsonVectP(features); + return data; } // True if type without matching qualifiers is in subdata @@ -194,6 +189,10 @@ namespace creature { return out; } + string formatDmgTypeVector(string title, vector dmg) { + return title + ": " + utils::join(dmg, "; "); + } + string genText(const Creature& c) { stringstream text; text << c.getGivenName() << " (" << c.getCreatureName() << "): " << c.getHP() << "/" << c.getHPMax() << " hp, " << getAC(c) << " ac"; @@ -205,49 +204,61 @@ namespace creature { text << " (" << armor << ")"; } } - text << ", speed " << c.getSpeed() << "\n"; - text << "A cr " << c.getCR() << " " << c.getAlignment() << " " << c.getSize() << " " << c.getType() << ".\n"; - text << "Stats:\n"; + text << ", speed " << c.getSpeed() << endl; + text << "A cr " << c.getCR() << " " << c.getAlignment() << " " << c.getSize() << " " << c.getType() << "." << endl; + text << "Stats:" << endl; using namespace rules; vector abilities {Ability::Str(), Ability::Dex(), Ability::Con(), Ability::Int(), Ability::Wis(), Ability::Cha()}; for(auto ability : abilities) { text << " " << setw(6) << std::left << ability.getAbbrev(); } - text << "\n"; + text << endl; for(auto ability : abilities) { text << setw(7) << std::left << (to_string(c.getScore(ability)) + "(" + to_string(c.getBonus(ability)) + ")"); } - text << "\n"; + text << endl; text << "Senses: "; if(! c.getSenses().empty()) { text << utils::join(c.getSenses(), ", ") << ". "; } - text << "Passive Perception " << 10 + c.getSkillBonus(rules::Skill::Perception()) << "\n"; + text << "Passive Perception " << 10 + c.getSkillBonus(rules::Skill::Perception()) << endl; if(! c.getLanguages().empty()) { - text << "Languages: " << c.getLanguages() << "\n"; + text << "Languages: " << c.getLanguages() << endl; } if(! c.getSkills().empty()) { - text << "\nSkills:\n"; + text << endl << "Skills:" << endl; for(auto skill : c.getSkills()) { - text << skill.first.getName() << " (+" << skill.second << ")\n"; + text << " * " << skill.first.getName() << " (+" << skill.second << ")" << endl; } } if(! c.getSaves().empty()) { - text << "\nSaves:\n"; + text << endl << "Saves:" << endl; for(auto save : c.getSaves()) { - text << save.first.getAbbrev() << " (+" << save.second << ")\n"; + text << " * " << save.first.getAbbrev() << " (+" << save.second << ")" << endl; } } + if(! c.getDmgImmunities().empty()) { + text << formatDmgTypeVector("\nDamage Immunities", c.getDmgImmunities()) << endl; + } + if(! c.getDmgResistances().empty()) { + text << formatDmgTypeVector("\nDamage Resistances", c.getDmgResistances()) << endl; + } + if(! c.getDmgVulnerabilities().empty()) { + text << formatDmgTypeVector("\nDamage Vulnerabilities", c.getDmgVulnerabilities()) << endl; + } + if(! c.getCondImmunities().empty()) { + text << formatDmgTypeVector("\nCondition Immunities", c.getCondImmunities()) << endl; + } if(! c.getFeatures().empty()) { - text << "\nFeatures:\n"; + text << endl << "Features:" << endl; for(auto f: c.getFeatures()) { - text << f->getText(c) << "\n"; + text << " * " << f->getText(c) << endl; } } if(! c.getInventory().empty()) { - text << "\nInventory:\n"; + text << endl << "Inventory:" << endl; for(auto i : c.getInventory()) { - text << i->getText(c) << "\n"; + text << " * " << i->getText(c) << endl; } } -- cgit v1.2.3