BREAKING: First idea for the combat system but there's a bug in goap where I'm not removing closed parts or something like that.
This commit is contained in:
parent
75db188dc6
commit
63f032ff12
8 changed files with 130 additions and 4 deletions
2
Makefile
2
Makefile
|
@ -22,7 +22,7 @@ tracy_build:
|
||||||
meson compile -j 10 -C builddir
|
meson compile -j 10 -C builddir
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
./builddir/runtests "[ai-enemy]"
|
./builddir/runtests "[ai]"
|
||||||
|
|
||||||
run: build test
|
run: build test
|
||||||
powershell "cp ./builddir/zedcaster.exe ."
|
powershell "cp ./builddir/zedcaster.exe ."
|
||||||
|
|
2
ai.cpp
2
ai.cpp
|
@ -18,7 +18,7 @@ namespace ai {
|
||||||
Action config_action(AIProfile& profile, nlohmann::json& config) {
|
Action config_action(AIProfile& profile, nlohmann::json& config) {
|
||||||
check(config.contains("name"), "config_action: action config missing name");
|
check(config.contains("name"), "config_action: action config missing name");
|
||||||
check(config.contains("cost"), "config_action: action config missing cost");
|
check(config.contains("cost"), "config_action: action config missing cost");
|
||||||
check(config["cost"] < STATE_MAX, "config_action: action cost is greater than STATE_MAX");
|
// check(config["cost"] < STATE_MAX, "config_action: action cost is greater than STATE_MAX");
|
||||||
|
|
||||||
Action result(config["name"], config["cost"]);
|
Action result(config["name"], config["cost"]);
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
],
|
],
|
||||||
"states": {
|
"states": {
|
||||||
"Walker::initial_state": {
|
"Walker::initial_state": {
|
||||||
|
"tough_personality": true,
|
||||||
"enemy_found": false,
|
"enemy_found": false,
|
||||||
"enemy_dead": false,
|
"enemy_dead": false,
|
||||||
"health_good": true,
|
"health_good": true,
|
||||||
|
|
57
assets/rituals.json
Normal file
57
assets/rituals.json
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"profile": {
|
||||||
|
"does_damage": 0,
|
||||||
|
"has_spikes": 1,
|
||||||
|
"has_magick": 2,
|
||||||
|
"is_complete": 3
|
||||||
|
},
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"name": "pierce_type",
|
||||||
|
"cost": 1000,
|
||||||
|
"needs": {
|
||||||
|
"is_complete": false,
|
||||||
|
"has_spikes": true
|
||||||
|
},
|
||||||
|
"effects": {
|
||||||
|
"does_damage": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "magick_type",
|
||||||
|
"cost": 0,
|
||||||
|
"needs": {
|
||||||
|
"is_complete": false,
|
||||||
|
"has_magick": true
|
||||||
|
},
|
||||||
|
"effects": {
|
||||||
|
"does_damage": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "combined",
|
||||||
|
"cost": 0,
|
||||||
|
"needs": {
|
||||||
|
"does_damage": true
|
||||||
|
},
|
||||||
|
"effects": {
|
||||||
|
"is_complete": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"states": {
|
||||||
|
"initial": {
|
||||||
|
"does_damage": false,
|
||||||
|
"is_complete": false,
|
||||||
|
"has_spikes": false,
|
||||||
|
"has_magick": false
|
||||||
|
},
|
||||||
|
"final": {
|
||||||
|
"does_damage": true,
|
||||||
|
"is_complete": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"actions": ["pierce_type", "magick_type", "combined"]
|
||||||
|
}
|
||||||
|
}
|
2
goap.cpp
2
goap.cpp
|
@ -66,7 +66,7 @@ namespace ai {
|
||||||
|
|
||||||
inline int h(State start, State goal, Action& action) {
|
inline int h(State start, State goal, Action& action) {
|
||||||
(void)action; // not sure if cost goes here or on d()
|
(void)action; // not sure if cost goes here or on d()
|
||||||
return distance_to_goal(start, goal);
|
return distance_to_goal(start, goal) + action.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int d(State start, State goal, Action& action) {
|
inline int d(State start, State goal, Action& action) {
|
||||||
|
|
|
@ -126,6 +126,7 @@ sources = [
|
||||||
executable('runtests', sources + [
|
executable('runtests', sources + [
|
||||||
'tests/ansi_parser.cpp',
|
'tests/ansi_parser.cpp',
|
||||||
'tests/base.cpp',
|
'tests/base.cpp',
|
||||||
|
'tests/combat.cpp',
|
||||||
'tests/components.cpp',
|
'tests/components.cpp',
|
||||||
'tests/config.cpp',
|
'tests/config.cpp',
|
||||||
'tests/dbc.cpp',
|
'tests/dbc.cpp',
|
||||||
|
|
|
@ -171,7 +171,7 @@ TEST_CASE("ai autowalker ai test", "[ai]") {
|
||||||
REQUIRE(ai::test(result, "no_more_enemies"));
|
REQUIRE(ai::test(result, "no_more_enemies"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Confirm EntityAI behaves as expected", "[ai-enemy]") {
|
TEST_CASE("Confirm EntityAI behaves as expected", "[ai]") {
|
||||||
ai::reset();
|
ai::reset();
|
||||||
ai::init("assets/ai.json");
|
ai::init("assets/ai.json");
|
||||||
auto ai_start = ai::load_state("Enemy::initial_state");
|
auto ai_start = ai::load_state("Enemy::initial_state");
|
||||||
|
|
67
tests/combat.cpp
Normal file
67
tests/combat.cpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include "ai.hpp"
|
||||||
|
#include "ai_debug.hpp"
|
||||||
|
|
||||||
|
struct RitualAI {
|
||||||
|
std::string script;
|
||||||
|
ai::State start;
|
||||||
|
ai::State goal;
|
||||||
|
ai::ActionPlan plan;
|
||||||
|
|
||||||
|
RitualAI(std::string script, ai::State start, ai::State goal) :
|
||||||
|
script(script), start(start), goal(goal)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RitualAI() {};
|
||||||
|
|
||||||
|
bool will_do(std::string name) {
|
||||||
|
ai::check_valid_action(name, "RitualAI::is_able_to");
|
||||||
|
return plan.script[0].name == name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_state(std::string name, bool setting) {
|
||||||
|
ai::set(start, name, setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update() {
|
||||||
|
plan = ai::plan(script, start, goal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump() {
|
||||||
|
dump_script(script, start, plan.script);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
auto start = ai::load_state("initial");
|
||||||
|
auto goal = ai::load_state("final");
|
||||||
|
|
||||||
|
RitualAI ritual("actions", start, goal);
|
||||||
|
|
||||||
|
ritual.set_state("has_spikes", true);
|
||||||
|
ritual.update();
|
||||||
|
|
||||||
|
ritual.dump();
|
||||||
|
REQUIRE(ritual.will_do("pierce_type"));
|
||||||
|
|
||||||
|
ritual.set_state("has_magick", true);
|
||||||
|
ritual.update();
|
||||||
|
|
||||||
|
fmt::println("------------ TEST WILL DO MAGICK TOO");
|
||||||
|
ritual.dump();
|
||||||
|
REQUIRE(ritual.will_do("magick_type"));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue