diff --git a/autowalker.cpp b/autowalker.cpp index 9658b66..d48fad4 100644 --- a/autowalker.cpp +++ b/autowalker.cpp @@ -1,19 +1,19 @@ #include "autowalker.hpp" +#include "inventory.hpp" -Pathing Autowalker::compute_paths() { +template +Pathing compute_paths(gui::FSM& fsm, int& count_out) { Pathing paths{fsm.$level.map->width(), fsm.$level.map->height()}; - enemy_count = 0; + count_out = 0; - fsm.$level.world->query( + fsm.$level.world->query( [&](const auto ent, auto& position, auto&) { if(ent != fsm.$level.player) { paths.set_target(position.location); - enemy_count++; + count_out++; } }); - fmt::println("PATHING to {} count enemies", enemy_count); - // BUG: using walls() will cause a map full of walls? dbc::check(matrix::width(fsm.$level.map->$walls) == paths.$width, "WTF the maps's walls width changed?"); dbc::check(matrix::height(fsm.$level.map->$walls) == paths.$height, "WTF the maps's walls height changed?"); @@ -23,6 +23,18 @@ Pathing Autowalker::compute_paths() { return paths; } +Pathing Autowalker::path_to_enemies() { + return compute_paths(fsm, enemy_count); +} + +Pathing Autowalker::path_to_items() { + return compute_paths(fsm, item_count); +} + +Pathing Autowalker::path_to_devices() { + return compute_paths(fsm, device_count); +} + void Autowalker::window_events() { fsm.$window.handleEvents( [&](const sf::Event::KeyPressed &) { @@ -121,7 +133,10 @@ void Autowalker::autowalk() { if(!fsm.autowalking) return; process_combat(); - auto paths = compute_paths(); + auto paths = path_to_enemies(); + if(enemy_count == 0) paths = path_to_items(); + if(item_count == 0) paths = path_to_devices(); + if(device_count == 0) dbc::log("no more enemies, items, or devices."); Point current = get_current_position(); Point target = current; @@ -132,12 +147,6 @@ void Autowalker::autowalk() { dbc::log("no paths found, aborting autowalk"); fsm.autowalking = false; return; - } else if(enemy_count == 0) { - dbc::log("Nobody left to kill. You win."); - fsm.autowalking = false; - return; - } else { - dbc::log("Hunting down more enemies."); } rotate_player(current, target); diff --git a/autowalker.hpp b/autowalker.hpp index 3b45178..b136a3d 100644 --- a/autowalker.hpp +++ b/autowalker.hpp @@ -4,6 +4,8 @@ struct Autowalker { int enemy_count = 0; + int item_count = 0; + int device_count = 0; gui::FSM& fsm; Autowalker(gui::FSM& fsm) @@ -12,7 +14,6 @@ struct Autowalker { void autowalk(); void start_autowalk(); void send_event(gui::Event ev); - Pathing compute_paths(); void window_events(); void process_combat(); bool path_player(Pathing& paths, Point &target_out); @@ -20,4 +21,7 @@ struct Autowalker { void rotate_player(Point current, Point target); bool player_has_moved(Point target); void process_move(); + Pathing path_to_enemies(); + Pathing path_to_items(); + Pathing path_to_devices(); };