Autowalker now correctly faces enemies to fight them.
This commit is contained in:
parent
9faad5f263
commit
759f93cae0
3 changed files with 19 additions and 31 deletions
|
@ -54,19 +54,6 @@
|
|||
"enemy_dead": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "face_enemy",
|
||||
"cost": 10,
|
||||
"needs": {
|
||||
"no_more_enemies": false,
|
||||
"in_combat": false,
|
||||
"enemy_found": true
|
||||
},
|
||||
"effects": {
|
||||
"in_combat": true,
|
||||
"enemy_dead": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "collect_items",
|
||||
"cost": 5,
|
||||
|
@ -132,7 +119,6 @@
|
|||
"Host::actions":
|
||||
["find_enemy",
|
||||
"kill_enemy",
|
||||
"face_enemy",
|
||||
"collect_items",
|
||||
"use_healing"],
|
||||
"Enemy::actions":
|
||||
|
|
|
@ -26,7 +26,6 @@ int number_left() {
|
|||
return count;
|
||||
}
|
||||
|
||||
|
||||
template<typename Comp>
|
||||
Pathing compute_paths() {
|
||||
auto& level = GameDB::current_level();
|
||||
|
@ -114,7 +113,6 @@ void Autowalker::path_fail(const std::string& msg, Matrix& bad_paths, Point pos)
|
|||
|
||||
bool Autowalker::path_player(Pathing& paths, Point& target_out) {
|
||||
auto &level = GameDB::current_level();
|
||||
|
||||
auto found = paths.find_path(target_out, PATHING_TOWARD, false);
|
||||
|
||||
if(found == PathingResult::FAIL) {
|
||||
|
@ -192,8 +190,6 @@ void Autowalker::handle_player_walk(ai::State& start, ai::State& goal) {
|
|||
auto paths = path_to_enemies();
|
||||
process_move(paths);
|
||||
face_enemy();
|
||||
} else if(action.name == "face_enemy") {
|
||||
face_enemy();
|
||||
} else if(action.name == "kill_enemy") {
|
||||
status(L"KILLING ENEMY");
|
||||
|
||||
|
@ -256,7 +252,6 @@ void Autowalker::open_map() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void Autowalker::autowalk() {
|
||||
handle_window_events();
|
||||
if(!fsm.autowalking) {
|
||||
|
@ -286,16 +281,16 @@ void Autowalker::autowalk() {
|
|||
void Autowalker::process_move(Pathing& paths) {
|
||||
auto world = GameDB::current_world();
|
||||
// target has to start at the player location then...
|
||||
auto target = GameDB::player_position().location;
|
||||
auto target_out = GameDB::player_position().location;
|
||||
|
||||
// ... target gets modified as an out parameter to find the path
|
||||
if(!path_player(paths, target)) {
|
||||
if(!path_player(paths, target_out)) {
|
||||
close_status();
|
||||
log(L"No paths found, aborting autowalk.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(rayview->aiming_at != target) rotate_player(target);
|
||||
if(rayview->aiming_at != target_out) rotate_player(target_out);
|
||||
|
||||
send_event(gui::Event::MOVE_FORWARD);
|
||||
|
||||
|
@ -303,9 +298,19 @@ void Autowalker::process_move(Pathing& paths) {
|
|||
}
|
||||
|
||||
bool Autowalker::found_enemy() {
|
||||
auto world = GameDB::current_world();
|
||||
auto aimed_at = camera_aim();
|
||||
return aimed_at != DinkyECS::NONE && world->has<components::Combat>(aimed_at);
|
||||
auto level = GameDB::current_level();
|
||||
auto player = GameDB::player_position();
|
||||
|
||||
for(matrix::compass it{level.map->$walls, player.location.x, player.location.y}; it.next();) {
|
||||
Point aim{it.x, it.y};
|
||||
if(aim != player.aiming_at ||
|
||||
!level.collision->occupied(player.aiming_at)) continue;
|
||||
|
||||
auto ent = level.collision->get(player.aiming_at);
|
||||
if(level.world->has<components::Combat>(ent)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Autowalker::found_item() {
|
||||
|
@ -347,12 +352,6 @@ bool Autowalker::face_enemy() {
|
|||
auto [found, neighbors] = level.collision->neighbors(player_at.location, true);
|
||||
|
||||
if(found) {
|
||||
fmt::println("FOUND ENEMIES:");
|
||||
for(auto& ent : neighbors) {
|
||||
auto enemy_pos = level.world->get<components::Position>(ent);
|
||||
fmt::println("\t{}={},{}", ent, enemy_pos.location.x, enemy_pos.location.y);
|
||||
}
|
||||
|
||||
auto enemy_pos = level.world->get<components::Position>(neighbors[0]);
|
||||
if(rayview->aiming_at != enemy_pos.location) rotate_player(enemy_pos.location);
|
||||
} else {
|
||||
|
|
|
@ -92,12 +92,15 @@ PathingResult Pathing::find_path(Point &out, int direction, bool diag)
|
|||
if(weight == direction) {
|
||||
out = {x, y};
|
||||
found = true;
|
||||
// only break if this is a lower path
|
||||
return true;
|
||||
} else if(weight == 0) {
|
||||
out = {x, y};
|
||||
found = true;
|
||||
// only found an equal path, keep checking
|
||||
}
|
||||
|
||||
// this says keep going
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue