aboutsummaryrefslogtreecommitdiff
path: root/src/creature.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/creature.cc')
-rw-r--r--src/creature.cc40
1 files changed, 36 insertions, 4 deletions
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 <algorithm>
#include <iostream>
#include <sstream>
@@ -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<entry::Armor>(c)) {
+ for(auto a : utils::castPtrs<entry::Item, entry::Armor>(c.getInventory())) {
if(c.getScore(rules::Ability::Str()) < a->getStrRequirement()) {
continue;
}
@@ -181,6 +184,24 @@ namespace creature {
return baseBonus + miscBonus;
}
+ vector<shared_ptr<entry::Weapon>> getAttacks(const Creature& c) {
+ vector<shared_ptr<entry::Weapon>> a = utils::castPtrs<entry::Item, entry::Weapon>(c.getInventory());
+ for(auto attack : utils::castPtrs<entry::Feature, entry::Attack>(c.getFeatures())) {
+ a.push_back(shared_ptr<entry::Weapon>(new entry::Weapon(attack->getWeapon())));
+ }
+ return a;
+ }
+
+ rules::Ability getBestAbility(const std::vector<rules::Ability>& 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<typename T> vector<string> mapItems(const vector<shared_ptr<T>>& items) {
vector<string> out;
for(auto i : items) {
@@ -189,8 +210,16 @@ namespace creature {
return out;
}
+ vector<string> dmgTypes2text(vector<dmgType> dmg) {
+ vector<string> ret;
+ for(dmgType t : dmg) {
+ ret.push_back(t.getText());
+ }
+ return ret;
+ }
+
string formatDmgTypeVector(string title, vector<dmgType> 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<entry::Armor>(c)), ", ");
+ string armor = utils::join(mapItems(utils::castPtrs<entry::Item, entry::Armor>(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();
}