From 7b5d1e3d46e94262a9c0fd3a01ab4685aea9d12d Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 1 May 2021 15:10:54 -0400 Subject: Added bash completion, amongst others --- src/creature.cc | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/creature.cc') diff --git a/src/creature.cc b/src/creature.cc index ee735d7..88b26e7 100644 --- a/src/creature.cc +++ b/src/creature.cc @@ -5,6 +5,7 @@ #include "feature.h" #include "weapon.h" #include "armor.h" +#include "attack.h" #include #include #include @@ -34,7 +35,7 @@ namespace creature { givenName = "Jerry"; //TODO: Autogenerate hpMax = this->getBonus(rules::Ability::Con()) * hdCount; for(int i = 0; i < hdCount; i++) { - hpMax += roll(hdSides); + hpMax += dice::roll(hdSides); } hp = hpMax; } @@ -61,6 +62,8 @@ namespace creature { data["langs"] = langs; data["cr"] = cr; data["prof"] = proficiency; + data["natural_armor"]["name"] = natArmorName; + data["natural_armor"]["bonus"] = natArmorBonus; data["d_immunities"] = dmgImmunities; data["d_resistances"] = dmgResistances; data["d_vulnerabilities"] = dmgVulnerabilities; @@ -162,7 +165,7 @@ namespace creature { int dex = c.getBonus(rules::Ability::Dex()); int baseBonus = 10 + dex; int miscBonus = 0; - for(auto a : getItems(c)) { + for(auto a : utils::castPtrs(c.getInventory())) { if(c.getScore(rules::Ability::Str()) < a->getStrRequirement()) { continue; } @@ -181,6 +184,24 @@ namespace creature { return baseBonus + miscBonus; } + vector> getAttacks(const Creature& c) { + vector> a = utils::castPtrs(c.getInventory()); + for(auto attack : utils::castPtrs(c.getFeatures())) { + a.push_back(shared_ptr(new entry::Weapon(attack->getWeapon()))); + } + return a; + } + + rules::Ability getBestAbility(const std::vector& abilities, const Creature& c) { + const rules::Ability* bestA = &abilities[0]; + for(auto a : abilities) { + if(c.getBonus(a) > c.getBonus(*bestA)) { + bestA = &a; + } + } + return *bestA; + } + template vector mapItems(const vector>& items) { vector out; for(auto i : items) { @@ -189,8 +210,16 @@ namespace creature { return out; } + vector dmgTypes2text(vector dmg) { + vector ret; + for(dmgType t : dmg) { + ret.push_back(t.getText()); + } + return ret; + } + string formatDmgTypeVector(string title, vector dmg) { - return title + ": " + utils::join(dmg, "; "); + return title + ": " + utils::join(dmgTypes2text(dmg), "; "); } string genText(const Creature& c) { @@ -199,7 +228,7 @@ namespace creature { if(! c.getNaturalArmor().first.empty()) { text << " (" << c.getNaturalArmor().first << ")"; } else { - string armor = utils::join(mapItems(creature::getItems(c)), ", "); + string armor = utils::join(mapItems(utils::castPtrs(c.getInventory())), ", "); if(! armor.empty()) { text << " (" << armor << ")"; } @@ -261,6 +290,9 @@ namespace creature { text << " * " << i->getText(c) << endl; } } + if(! c.Entry::getText().empty()) { + text << endl << c.Entry::getText() << endl; + } return text.str(); } -- cgit v1.2.3