|
|
|
@ -1,19 +1,19 @@ |
|
|
|
|
#include "autowalker.hpp" |
|
|
|
|
#include "inventory.hpp" |
|
|
|
|
|
|
|
|
|
Pathing Autowalker::compute_paths() { |
|
|
|
|
template<typename Comp> |
|
|
|
|
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<components::Position, components::Combat>( |
|
|
|
|
fsm.$level.world->query<components::Position, Comp>( |
|
|
|
|
[&](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<components::Combat>(fsm, enemy_count); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Pathing Autowalker::path_to_items() { |
|
|
|
|
return compute_paths<components::InventoryItem>(fsm, item_count); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Pathing Autowalker::path_to_devices() { |
|
|
|
|
return compute_paths<components::Device>(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); |
|
|
|
|