Autowalker is now using the GOAP AI system and works way better. Still quite a lot of jank in the code but that'll get removed over time. Next thing is being able to detect when its near an item/enemy and properly react.

This commit is contained in:
Zed A. Shaw 2025-03-12 12:15:21 -04:00
parent ff81c78d13
commit d15c9b12fd
9 changed files with 84 additions and 47 deletions

10
ai.cpp
View file

@ -22,17 +22,17 @@ namespace ai {
Action result(config["name"], config["cost"]);
check(config.contains("needs"),
fmt::format("config_action: no 'needs' field", result.$name));
fmt::format("config_action: no 'needs' field", result.name));
check(config.contains("effects"),
fmt::format("config_action: no 'effects' field", result.$name));
fmt::format("config_action: no 'effects' field", result.name));
for(auto& [name_key, value] : config["needs"].items()) {
check(profile.contains(name_key), fmt::format("config_action: profile does not have name {}", result.$name, name_key));
check(profile.contains(name_key), fmt::format("config_action: profile does not have name {}", result.name, name_key));
result.needs(profile.at(name_key), bool(value));
}
for(auto& [name_key, value] : config["effects"].items()) {
check(profile.contains(name_key), fmt::format("config_action: profile does not have name {}", result.$name, name_key));
check(profile.contains(name_key), fmt::format("config_action: profile does not have name {}", result.name, name_key));
result.effect(profile.at(name_key), bool(value));
}
@ -79,7 +79,7 @@ namespace ai {
auto& actions = config["actions"];
for(auto& action_vars : actions) {
auto the_action = config_action(AIMGR.profile, action_vars);
AIMGR.actions.insert_or_assign(the_action.$name, the_action);
AIMGR.actions.insert_or_assign(the_action.name, the_action);
}
// load all states