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.
This commit is contained in:
parent
7984540c0c
commit
eeea3c794f
2 changed files with 24 additions and 16 deletions
|
@ -3,17 +3,20 @@
|
||||||
"does_damage": 0,
|
"does_damage": 0,
|
||||||
"has_spikes": 1,
|
"has_spikes": 1,
|
||||||
"has_magick": 2,
|
"has_magick": 2,
|
||||||
"is_complete": 3
|
"does_physical": 3,
|
||||||
|
"does_magick": 4,
|
||||||
|
"is_complete": 5
|
||||||
},
|
},
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"name": "pierce_type",
|
"name": "pierce_type",
|
||||||
"cost": 1000,
|
"cost": 0,
|
||||||
"needs": {
|
"needs": {
|
||||||
"is_complete": false,
|
"is_complete": false,
|
||||||
"has_spikes": true
|
"has_spikes": true
|
||||||
},
|
},
|
||||||
"effects": {
|
"effects": {
|
||||||
|
"does_physical": true,
|
||||||
"does_damage": true
|
"does_damage": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -25,6 +28,7 @@
|
||||||
"has_magick": true
|
"has_magick": true
|
||||||
},
|
},
|
||||||
"effects": {
|
"effects": {
|
||||||
|
"does_magick": true,
|
||||||
"does_damage": true
|
"does_damage": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -41,12 +45,16 @@
|
||||||
],
|
],
|
||||||
"states": {
|
"states": {
|
||||||
"initial": {
|
"initial": {
|
||||||
|
"has_spikes": false,
|
||||||
|
"has_magick": false,
|
||||||
"does_damage": false,
|
"does_damage": false,
|
||||||
"is_complete": false,
|
"is_complete": false,
|
||||||
"has_spikes": false,
|
"does_magick": false,
|
||||||
"has_magick": false
|
"does_physical": false
|
||||||
},
|
},
|
||||||
"final": {
|
"final": {
|
||||||
|
"does_magick": true,
|
||||||
|
"does_physical": true,
|
||||||
"does_damage": true,
|
"does_damage": true,
|
||||||
"is_complete": true
|
"is_complete": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,21 @@
|
||||||
struct RitualAI {
|
struct RitualAI {
|
||||||
std::string script;
|
std::string script;
|
||||||
ai::State start;
|
ai::State start;
|
||||||
|
ai::State original;
|
||||||
ai::State goal;
|
ai::State goal;
|
||||||
ai::ActionPlan plan;
|
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), goal(goal)
|
script(script), start(start), original(start), goal(goal)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RitualAI() {};
|
RitualAI() {};
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
start = original;
|
||||||
|
}
|
||||||
|
|
||||||
bool will_do(std::string name) {
|
bool 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;
|
||||||
|
@ -35,15 +40,6 @@ struct RitualAI {
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("prototype combat system ideas", "[combat]") {
|
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::reset();
|
||||||
ai::init("assets/rituals.json");
|
ai::init("assets/rituals.json");
|
||||||
|
|
||||||
|
@ -54,14 +50,18 @@ TEST_CASE("prototype combat system ideas", "[combat]") {
|
||||||
|
|
||||||
ritual.set_state("has_spikes", true);
|
ritual.set_state("has_spikes", true);
|
||||||
ritual.update();
|
ritual.update();
|
||||||
|
fmt::println("------------ TEST WILL DO PIERCE");
|
||||||
ritual.dump();
|
ritual.dump();
|
||||||
REQUIRE(ritual.will_do("pierce_type"));
|
REQUIRE(ritual.will_do("pierce_type"));
|
||||||
|
|
||||||
|
ritual.reset();
|
||||||
ritual.set_state("has_magick", true);
|
ritual.set_state("has_magick", true);
|
||||||
|
ritual.set_state("has_spikes", true);
|
||||||
ritual.update();
|
ritual.update();
|
||||||
|
|
||||||
fmt::println("------------ TEST WILL DO MAGICK TOO");
|
fmt::println("------------ TEST WILL DO MAGICK TOO");
|
||||||
ritual.dump();
|
ritual.dump();
|
||||||
REQUIRE(ritual.will_do("magick_type"));
|
REQUIRE(ritual.will_do("magick_type"));
|
||||||
|
|
||||||
|
ritual.plan.script.pop_front();
|
||||||
|
REQUIRE(ritual.will_do("pierce_type"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue