Gave up on trying to get the GOAP algorithm to correctly apply the cost structure to competing choices, and instead I take the resulting action list and simply find the next best one based on cost.
This commit is contained in:
parent
52f45e1d45
commit
c014e65c13
11 changed files with 43 additions and 30 deletions
26
ai.cpp
26
ai.cpp
|
@ -162,13 +162,28 @@ namespace ai {
|
|||
return state.test(state_id(name));
|
||||
}
|
||||
|
||||
AIProfile* profile() {
|
||||
return &AIMGR.profile;
|
||||
ai::Action& EntityAI::best_fit() {
|
||||
dbc::check(plan.script.size() > 0, "empty action plan script");
|
||||
int lowest_cost = plan.script[0].cost;
|
||||
size_t best_action = 0;
|
||||
|
||||
for(size_t i = 0; i < plan.script.size(); i++) {
|
||||
auto& action = plan.script[i];
|
||||
if(!action.can_effect(start)) continue;
|
||||
|
||||
if(action.cost < lowest_cost) {
|
||||
lowest_cost = action.cost;
|
||||
best_action = i;
|
||||
}
|
||||
}
|
||||
|
||||
return plan.script[best_action];
|
||||
}
|
||||
|
||||
bool EntityAI::wants_to(std::string name) {
|
||||
ai::check_valid_action(name, "EntityAI::wants_to");
|
||||
return plan.script.size() > 0 && plan.script[0].name == name;
|
||||
dbc::check(plan.script.size() > 0, "empty action plan script");
|
||||
return best_fit().name == name;
|
||||
}
|
||||
|
||||
bool EntityAI::active() {
|
||||
|
@ -190,4 +205,9 @@ namespace ai {
|
|||
void EntityAI::update() {
|
||||
plan = ai::plan(script, start, goal);
|
||||
}
|
||||
|
||||
AIProfile* profile() {
|
||||
return &AIMGR.profile;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue