From eeea3c794f1d32bd1198e4f24bdbf2a40e0bb0fc Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 15 Mar 2025 23:39:54 -0400 Subject: [PATCH] The basic idea of using GOAP to figure out if combined items will produce a valid ritual, and what kind of things the ritual does, mostly works. --- assets/rituals.json | 16 ++++++++++++---- tests/combat.cpp | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/assets/rituals.json b/assets/rituals.json index 0b75541..7f2bfbd 100644 --- a/assets/rituals.json +++ b/assets/rituals.json @@ -3,17 +3,20 @@ "does_damage": 0, "has_spikes": 1, "has_magick": 2, - "is_complete": 3 + "does_physical": 3, + "does_magick": 4, + "is_complete": 5 }, "actions": [ { "name": "pierce_type", - "cost": 1000, + "cost": 0, "needs": { "is_complete": false, "has_spikes": true }, "effects": { + "does_physical": true, "does_damage": true } }, @@ -25,6 +28,7 @@ "has_magick": true }, "effects": { + "does_magick": true, "does_damage": true } }, @@ -41,12 +45,16 @@ ], "states": { "initial": { + "has_spikes": false, + "has_magick": false, "does_damage": false, "is_complete": false, - "has_spikes": false, - "has_magick": false + "does_magick": false, + "does_physical": false }, "final": { + "does_magick": true, + "does_physical": true, "does_damage": true, "is_complete": true } diff --git a/tests/combat.cpp b/tests/combat.cpp index a6a3e31..4bf6b92 100644 --- a/tests/combat.cpp +++ b/tests/combat.cpp @@ -6,16 +6,21 @@ struct RitualAI { std::string script; ai::State start; + ai::State original; ai::State goal; ai::ActionPlan plan; RitualAI(std::string script, ai::State start, ai::State goal) : - script(script), start(start), goal(goal) + script(script), start(start), original(start), goal(goal) { } RitualAI() {}; + void reset() { + start = original; + } + bool will_do(std::string name) { ai::check_valid_action(name, "RitualAI::is_able_to"); return plan.script[0].name == name; @@ -35,15 +40,6 @@ struct RitualAI { }; TEST_CASE("prototype combat system ideas", "[combat]") { - // as the player picks up items they go in the invetory - // and they player has little "bags" they can put items - // in that combine the items into rituals. How the items - // combine is controlled by the GOAP algorithm but tailored - // to item combinations that produce effects - - // probably need to use the code in ai.cpp in a different - // system for the ritual loading stuff - // ai::reset(); ai::init("assets/rituals.json"); @@ -54,14 +50,18 @@ TEST_CASE("prototype combat system ideas", "[combat]") { ritual.set_state("has_spikes", true); ritual.update(); - + fmt::println("------------ TEST WILL DO PIERCE"); ritual.dump(); REQUIRE(ritual.will_do("pierce_type")); + ritual.reset(); ritual.set_state("has_magick", true); + ritual.set_state("has_spikes", true); ritual.update(); - fmt::println("------------ TEST WILL DO MAGICK TOO"); ritual.dump(); REQUIRE(ritual.will_do("magick_type")); + + ritual.plan.script.pop_front(); + REQUIRE(ritual.will_do("pierce_type")); }