aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYour Name <you@example.com>2022-01-16 21:32:01 -0500
committerYour Name <you@example.com>2022-01-16 21:32:01 -0500
commitd0e356d09e30a11c1e072415a5088f829d5c0a04 (patch)
tree1e64d37b9b424cd74c30ad4c8225828c7a76874e /src
parent3f78a7e1647ba94129236bd2bf4fc855c109628a (diff)
downloaddmtool-d0e356d09e30a11c1e072415a5088f829d5c0a04.tar.gz
dmtool-d0e356d09e30a11c1e072415a5088f829d5c0a04.tar.bz2
dmtool-d0e356d09e30a11c1e072415a5088f829d5c0a04.zip
Worked on features
Diffstat (limited to 'src')
-rw-r--r--src/attack.h2
-rw-r--r--src/cmd/cmd.cc (renamed from src/cmd.cc)2
-rw-r--r--src/cmd/cmd.h (renamed from src/cmd.h)2
-rw-r--r--src/cmd/cmd_fsops.cc (renamed from src/cmd_fsops.cc)4
-rw-r--r--src/cmd/cmd_manipulate.cc (renamed from src/cmd_manipulate.cc)16
-rw-r--r--src/cmd/cmd_query.cc (renamed from src/cmd_query.cc)8
-rw-r--r--src/cmd/cmd_usage.cc (renamed from src/cmd_usage.cc)0
-rw-r--r--src/creature.cc1
-rw-r--r--src/creature.h2
-rw-r--r--src/dmtool.cc2
-rw-r--r--src/entry.cc2
-rw-r--r--src/features/feature.cc (renamed from src/feature.cc)6
-rw-r--r--src/features/feature.h (renamed from src/feature.h)2
-rw-r--r--src/rules.cc7
-rw-r--r--src/rules.h44
-rw-r--r--src/spellcasting.h2
-rw-r--r--src/utils.h2
17 files changed, 67 insertions, 37 deletions
diff --git a/src/attack.h b/src/attack.h
index 2e4125b..e00eb25 100644
--- a/src/attack.h
+++ b/src/attack.h
@@ -1,5 +1,5 @@
#pragma once
-#include "feature.h"
+#include "features/feature.h"
#include "weapon.h"
namespace creature {
diff --git a/src/cmd.cc b/src/cmd/cmd.cc
index d84c55b..a1fd760 100644
--- a/src/cmd.cc
+++ b/src/cmd/cmd.cc
@@ -1,5 +1,5 @@
#include "cmd.h"
-#include "settings.h"
+#include "../settings.h"
#include <vector>
#include <string>
#include <filesystem>
diff --git a/src/cmd.h b/src/cmd/cmd.h
index 978f6db..ff96b32 100644
--- a/src/cmd.h
+++ b/src/cmd/cmd.h
@@ -3,7 +3,7 @@
#include <map>
#include <string>
#include <filesystem>
-#include "rules.h"
+#include "../rules.h"
namespace cmd {
// Corresponds to commands
diff --git a/src/cmd_fsops.cc b/src/cmd/cmd_fsops.cc
index ac4bdef..e638b96 100644
--- a/src/cmd_fsops.cc
+++ b/src/cmd/cmd_fsops.cc
@@ -1,6 +1,6 @@
#include "cmd.h"
-#include "utils.h"
-#include "entry.h"
+#include "../utils.h"
+#include "../entry.h"
#include <filesystem>
#include <sstream>
diff --git a/src/cmd_manipulate.cc b/src/cmd/cmd_manipulate.cc
index aa6407d..18df098 100644
--- a/src/cmd_manipulate.cc
+++ b/src/cmd/cmd_manipulate.cc
@@ -1,12 +1,12 @@
#include "cmd.h"
-#include "utils.h"
-#include "creature.h"
-#include "item.h"
-#include "spellcasting.h"
-#include "settings.h"
-#include "weapon.h"
-#include "dice.h"
-#include "armor.h"
+#include "../utils.h"
+#include "../creature.h"
+#include "../item.h"
+#include "../spellcasting.h"
+#include "../settings.h"
+#include "../weapon.h"
+#include "../dice.h"
+#include "../armor.h"
#include <sstream>
#include <memory>
#include <cstdlib>
diff --git a/src/cmd_query.cc b/src/cmd/cmd_query.cc
index e13876f..9c2dae6 100644
--- a/src/cmd_query.cc
+++ b/src/cmd/cmd_query.cc
@@ -1,8 +1,8 @@
#include "cmd.h"
-#include "utils.h"
-#include "creature.h"
-#include "dice.h"
-#include "weapon.h"
+#include "../utils.h"
+#include "../creature.h"
+#include "../dice.h"
+#include "../weapon.h"
#include <sstream>
namespace cmd {
diff --git a/src/cmd_usage.cc b/src/cmd/cmd_usage.cc
index 44daca4..44daca4 100644
--- a/src/cmd_usage.cc
+++ b/src/cmd/cmd_usage.cc
diff --git a/src/creature.cc b/src/creature.cc
index 6491024..ea8ef30 100644
--- a/src/creature.cc
+++ b/src/creature.cc
@@ -1,7 +1,6 @@
#include "creature.h"
#include "dice.h"
#include "rules.h"
-#include "feature.h"
#include "weapon.h"
#include "armor.h"
#include "attack.h"
diff --git a/src/creature.h b/src/creature.h
index 09760e3..de93b0e 100644
--- a/src/creature.h
+++ b/src/creature.h
@@ -2,7 +2,7 @@
#include "rules.h"
#include "utils.h"
#include "entry.h"
-#include "feature.h"
+#include "features/feature.h"
#include "item.h"
#include <nlohmann/json.hpp>
diff --git a/src/dmtool.cc b/src/dmtool.cc
index 6ae096f..3aec8b2 100644
--- a/src/dmtool.cc
+++ b/src/dmtool.cc
@@ -1,4 +1,4 @@
-#include "cmd.h"
+#include "cmd/cmd.h"
#include "utils.h"
#include <iostream>
#include <exception>
diff --git a/src/entry.cc b/src/entry.cc
index 663a40a..9c9b3da 100644
--- a/src/entry.cc
+++ b/src/entry.cc
@@ -1,6 +1,6 @@
#include "entry.h"
#include "utils.h"
-#include "feature.h"
+#include "features/feature.h"
#include "item.h"
#include "spell.h"
#include "creature.h"
diff --git a/src/feature.cc b/src/features/feature.cc
index 941de4e..0fd2d6c 100644
--- a/src/feature.cc
+++ b/src/features/feature.cc
@@ -1,7 +1,7 @@
#include "feature.h"
-#include "spellcasting.h"
-#include "attack.h"
-#include "utils.h"
+#include "../spellcasting.h"
+#include "../attack.h"
+#include "../utils.h"
#include <nlohmann/json.hpp>
#include <memory>
diff --git a/src/feature.h b/src/features/feature.h
index e3c8bdf..209a30a 100644
--- a/src/feature.h
+++ b/src/features/feature.h
@@ -1,6 +1,6 @@
#pragma once
#include <nlohmann/json.hpp>
-#include "entry.h"
+#include "../entry.h"
#include <memory>
namespace entry {
diff --git a/src/rules.cc b/src/rules.cc
index 96d9a51..900d023 100644
--- a/src/rules.cc
+++ b/src/rules.cc
@@ -37,6 +37,8 @@ namespace rules {
{"non-adamantine", "adamantine"}
};
+ const std::set<std::string> Condition::conditions {"blinded", "charmed", "deafened", "frightened", "grappled", "incapacitated", "invisible", "paralyzed", "petrified", "poisoned", "prone", "restrained", "stunned", "unconscious", "exhausted1", "exhausted2", "exhausted3", "exhausted4", "exhausted5", "exhausted6"};
+
std::ostream& operator<<(std::ostream& os, const Ability& a) {
os << std::string(a);
return os;
@@ -51,4 +53,9 @@ namespace rules {
os << std::string(q);
return os;
}
+
+ std::ostream& operator<<(std::ostream& os, const Condition& c) {
+ os << std::string(c);
+ return os;
+ }
}
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 {
diff --git a/src/spellcasting.h b/src/spellcasting.h
index 902f860..46d4ba8 100644
--- a/src/spellcasting.h
+++ b/src/spellcasting.h
@@ -1,5 +1,5 @@
#pragma once
-#include "feature.h"
+#include "features/feature.h"
#include "spell.h"
#include "rules.h"
#include "utils.h"
diff --git a/src/utils.h b/src/utils.h
index 77096e7..2998704 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -98,7 +98,7 @@ namespace utils {
template<typename F, typename T> std::vector<std::shared_ptr<T>> castPtrs(std::vector<std::shared_ptr<F>> from) {
std::vector<std::shared_ptr<T>> Ts;
for(std::shared_ptr<F> f : from) {
- std::shared_ptr<T> t = dynamic_pointer_cast<T>(f);
+ std::shared_ptr<T> t = std::dynamic_pointer_cast<T>(f);
if(t) {
Ts.push_back(t);
}