Autowalker now paths reliably and can attack enemies by facing them. Just need to make it fight diagonally.

This commit is contained in:
Zed A. Shaw 2025-08-31 00:47:21 -04:00
parent 4365aa4bfc
commit f98cc543f6

View file

@ -2,6 +2,7 @@
#include "ai_debug.hpp" #include "ai_debug.hpp"
#include "gui/ritual_ui.hpp" #include "gui/ritual_ui.hpp"
#include "game_level.hpp" #include "game_level.hpp"
#include "systems.hpp"
#define DEBUG #define DEBUG
struct InventoryStats { struct InventoryStats {
@ -29,28 +30,11 @@ int number_left() {
template<typename Comp> template<typename Comp>
Pathing compute_paths() { Pathing compute_paths() {
auto& level = GameDB::current_level(); auto& level = GameDB::current_level();
auto& walls_original = level.map->$walls; auto walls_copy = level.map->$walls;
auto walls_copy = walls_original;
Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)}; Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)};
// first, put everything of this type as a target System::multi_path<Comp>(level, paths, walls_copy);
level.world->query<components::Position, Comp>(
[&](const auto ent, auto& position, auto&) {
if(ent != level.player) {
paths.set_target(position.location);
}
});
level.world->query<components::Collision>(
[&](const auto ent, auto& collision) {
if(collision.has) {
auto& pos = level.world->get<components::Position>(ent);
walls_copy[pos.location.y][pos.location.x] = WALL_VALUE;
}
});
paths.compute_paths(walls_copy);
auto pos = GameDB::player_position().location; auto pos = GameDB::player_position().location;
matrix::dump("compute_paths walls", walls_copy, pos.x, pos.y); matrix::dump("compute_paths walls", walls_copy, pos.x, pos.y);
@ -133,6 +117,7 @@ void Autowalker::path_fail(const std::string& msg, Matrix& bad_paths, Point pos)
bool Autowalker::path_player(Pathing& paths, Point& target_out) { bool Autowalker::path_player(Pathing& paths, Point& target_out) {
auto &level = GameDB::current_level(); auto &level = GameDB::current_level();
auto found = paths.find_path(target_out, PATHING_TOWARD, false); auto found = paths.find_path(target_out, PATHING_TOWARD, false);
if(found == PathingResult::FAIL) { if(found == PathingResult::FAIL) {