Move the ritual stuff to the combat namespace.

master
Zed A. Shaw 3 weeks ago
parent 49531ba148
commit 1d2968f826
  1. 32
      rituals.cpp
  2. 36
      rituals.hpp
  3. 2
      tests/ai.cpp
  4. 1
      tests/rituals.cpp

@ -1,23 +1,25 @@
#include "rituals.hpp" #include "rituals.hpp"
#include "ai_debug.hpp" #include "ai_debug.hpp"
void RitualAI::reset() { namespace combat {
start = original; void RitualAI::reset() {
} start = original;
}
bool RitualAI::will_do(std::string name) { bool RitualAI::will_do(std::string name) {
ai::check_valid_action(name, "RitualAI::is_able_to"); ai::check_valid_action(name, "RitualAI::is_able_to");
return plan.script[0].name == name; return plan.script[0].name == name;
} }
void RitualAI::set_state(std::string name, bool setting) { void RitualAI::set_state(std::string name, bool setting) {
ai::set(start, name, setting); ai::set(start, name, setting);
} }
void RitualAI::update() { void RitualAI::update() {
plan = ai::plan(script, start, goal); plan = ai::plan(script, start, goal);
} }
void RitualAI::dump() { void RitualAI::dump() {
ai::dump_script(script, start, plan.script); ai::dump_script(script, start, plan.script);
}
} }

@ -1,23 +1,25 @@
#pragma once #pragma once
#include "ai.hpp" #include "ai.hpp"
struct RitualAI { namespace combat {
std::string script; struct RitualAI {
ai::State start; std::string script;
ai::State original; ai::State start;
ai::State goal; ai::State original;
ai::ActionPlan plan; ai::State goal;
ai::ActionPlan plan;
RitualAI(std::string script, ai::State start, ai::State goal) : RitualAI(std::string script, ai::State start, ai::State goal) :
script(script), start(start), original(start), goal(goal) script(script), start(start), original(start), goal(goal)
{ {
} }
RitualAI() {}; RitualAI() {};
void reset(); void reset();
bool will_do(std::string name); bool will_do(std::string name);
void set_state(std::string name, bool setting); void set_state(std::string name, bool setting);
void update(); void update();
void dump(); void dump();
}; };
}

@ -217,7 +217,7 @@ TEST_CASE("confirm that cycles are avoided/detected", "[ai]") {
auto start = ai::load_state("initial"); auto start = ai::load_state("initial");
auto goal = ai::load_state("final"); auto goal = ai::load_state("final");
RitualAI ritual("actions", start, goal); combat::RitualAI ritual("actions", start, goal);
ritual.reset(); ritual.reset();
ritual.set_state("has_magick", true); ritual.set_state("has_magick", true);
ritual.set_state("cursed_item", true); ritual.set_state("cursed_item", true);

@ -2,6 +2,7 @@
#include <iostream> #include <iostream>
#include "rituals.hpp" #include "rituals.hpp"
using namespace combat;
TEST_CASE("prototype combat system ideas", "[combat]") { TEST_CASE("prototype combat system ideas", "[combat]") {
ai::reset(); ai::reset();

Loading…
Cancel
Save