diff options
author | Your Name <you@example.com> | 2022-01-03 16:25:45 -0500 |
---|---|---|
committer | Your Name <you@example.com> | 2022-01-03 16:25:45 -0500 |
commit | 3f78a7e1647ba94129236bd2bf4fc855c109628a (patch) | |
tree | 0a1538d44715738c8cbbae00bf1995777227b963 /src/dmtool.cc | |
parent | d222c5a39943ed9f83f11d63a42bdff4978179af (diff) | |
download | dmtool-3f78a7e1647ba94129236bd2bf4fc855c109628a.tar.gz dmtool-3f78a7e1647ba94129236bd2bf4fc855c109628a.tar.bz2 dmtool-3f78a7e1647ba94129236bd2bf4fc855c109628a.zip |
Added command to force a saving throw
Diffstat (limited to 'src/dmtool.cc')
-rw-r--r-- | src/dmtool.cc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/dmtool.cc b/src/dmtool.cc index e84630b..6ae096f 100644 --- a/src/dmtool.cc +++ b/src/dmtool.cc @@ -24,16 +24,23 @@ void checkArgs(std::string cmd, std::vector<std::string> args) { } } -// Removes flags from args (in-place) and returns vector of flags -std::vector<std::string> extractFlags(std::vector<std::string>& args) { - std::vector<std::string> ret; +// Removes flags from args (in-place) and returns map of options +std::map<std::string, std::string> extractFlags(std::vector<std::string>& args, const std::vector<std::string>& knownOptions = {}) { + std::map<std::string, std::string> ret; auto it = args.begin(); while(it != args.end()) { if((*it)[0] == '-') { while((*it)[0] == '-') { (*it).erase((*it).begin()); } - ret.push_back(*it); + if(it < args.end()-1) { + ret.emplace(*it, *(it+1)); + if(std::find(knownOptions.begin(), knownOptions.end(), *it) != knownOptions.end()) { + args.erase(it); + } + } else { + ret.emplace(*it, std::string()); + } args.erase(it); } else { it++; @@ -43,12 +50,12 @@ std::vector<std::string> extractFlags(std::vector<std::string>& args) { } int main(int argc, char *argv[]) { - // Full thing is surrounded in try/catch to pleasantly print out any errors + // Full thing is surrounded in try/catch to plesantly print out any errors try { std::string exename = argv[0]; std::vector<std::string> args(&argv[1], &argv[argc]); auto argsWithFlags = args; - std::vector<std::string> flags = extractFlags(args); + auto flags = extractFlags(args); cmd::mkdir({cmd::getTruePath("")}); if(args.empty()) { std::cout << cmd::list(args); @@ -68,6 +75,12 @@ int main(int argc, char *argv[]) { else if(cmd == "attack") std::cout << cmd::attack(args, flags); else if(cmd == "damage") std::cout << cmd::damage(args, flags); else if(cmd == "heal") std::cout << cmd::heal(args); + else if(cmd == "save") { + args = argsWithFlags; + extractFlags(args, {"damage", "type"}); + args.erase(args.begin()); + std::cout << cmd::save(args, flags); + } else if(cmd == "reset") std::cout << cmd::reset(args); else if(cmd == "set") std::cout << cmd::set(args); else if(cmd == "add") std::cout << cmd::add(args); |