diff options
author | Your Name <you@example.com> | 2022-01-16 21:32:01 -0500 |
---|---|---|
committer | Your Name <you@example.com> | 2022-01-16 21:32:01 -0500 |
commit | d0e356d09e30a11c1e072415a5088f829d5c0a04 (patch) | |
tree | 1e64d37b9b424cd74c30ad4c8225828c7a76874e /src/rules.h | |
parent | 3f78a7e1647ba94129236bd2bf4fc855c109628a (diff) | |
download | dmtool-d0e356d09e30a11c1e072415a5088f829d5c0a04.tar.gz dmtool-d0e356d09e30a11c1e072415a5088f829d5c0a04.tar.bz2 dmtool-d0e356d09e30a11c1e072415a5088f829d5c0a04.zip |
Worked on features
Diffstat (limited to 'src/rules.h')
-rw-r--r-- | src/rules.h | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/src/rules.h b/src/rules.h index 2894947..30464a8 100644 --- a/src/rules.h +++ b/src/rules.h @@ -2,6 +2,7 @@ #include "utils.h" #include <vector> #include <map> +#include <set> #include <string> #include <iostream> #include <algorithm> @@ -18,6 +19,10 @@ namespace rules { ri.payload = j; } std::string getPayload(void) const {return payload;} + bool operator==(const RuleItem& rhs) const {return getPayload() == rhs.getPayload();} + bool operator<(const RuleItem& rhs) const {return getPayload() < rhs.getPayload();} + operator std::string() const {return getPayload();} + operator bool() const {return ! getPayload().empty();} protected: std::string payload; }; @@ -26,10 +31,6 @@ namespace rules { public: std::string getFull() const {return abilities.at(getAbbrev());} std::string getAbbrev() const {return getPayload();} - operator std::string() const {return getAbbrev();} - bool operator<(const Ability& rhs) const {return getAbbrev() < rhs.getAbbrev();} - bool operator==(const Ability& rhs) const {return getAbbrev() == rhs.getAbbrev();} - operator bool() const {return ! getAbbrev().empty();} Ability() {} Ability(const std::string& abbrev) { @@ -67,10 +68,6 @@ namespace rules { public: std::string getName() const {return getPayload();} Ability getAbility() const {return Ability(skill2ability.at(getName()));} - operator std::string() const {return getName();} - bool operator<(const Skill& rhs) const {return getName() < rhs.getName();} - bool operator==(const Skill& rhs) const {return getName() == rhs.getName();} - operator bool() const {return ! getName().empty();} virtual ~Skill() {} @@ -128,9 +125,7 @@ namespace rules { } std::string getNegative() const {return getPayload();} std::string getPositive() const {return negative2positive.at(getNegative());} - operator std::string() const {return getNegative();} virtual ~Qualifier() {} - bool operator==(const Qualifier& rhs) const {return getNegative() == rhs.getNegative();} static Qualifier Magical() {return Qualifier("nonmagical");} static Qualifier Silvered() {return Qualifier("non-silvered");} @@ -140,9 +135,38 @@ namespace rules { static const std::map<std::string, std::string> negative2positive; }; + class Condition : public RuleItem { + public: + Condition() {} + Condition(std::string name) { + utils::lower(name); + if(conditions.count(name) == 0) { + throw std::invalid_argument("No such condition: " + name); + } + payload = name; + } + + virtual ~Condition() {} + + void incExhaustion() { + if(payload.find("exhausted") == std::string::npos) { + throw std::invalid_argument("Cannot increment exhaustion on condition " + payload); + } + int exhLvl = utils::parseInt(std::string(1, payload.back())); + if(exhLvl >= 6) { + throw std::invalid_argument("Cannot increment exhaustion beyond level 6"); + } + payload.back() = '0'+exhLvl+1; + } + + private: + static const std::set<std::string> conditions; + }; + std::ostream& operator<<(std::ostream& os, const Ability& a); std::ostream& operator<<(std::ostream& os, const Skill& s); std::ostream& operator<<(std::ostream& os, const Qualifier& q); + std::ostream& operator<<(std::ostream& os, const Condition& c); template<typename T> T tryGetAbilityOrSkill(std::string src) { try { |