Now it will path to enemies, then devices, then items but it does get stuck on stuff like devices.
This commit is contained in:
parent
87e1c25cd5
commit
cdb930a7f2
2 changed files with 27 additions and 14 deletions
|
@ -1,19 +1,19 @@
|
||||||
#include "autowalker.hpp"
|
#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()};
|
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&) {
|
[&](const auto ent, auto& position, auto&) {
|
||||||
if(ent != fsm.$level.player) {
|
if(ent != fsm.$level.player) {
|
||||||
paths.set_target(position.location);
|
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?
|
// 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::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?");
|
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;
|
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() {
|
void Autowalker::window_events() {
|
||||||
fsm.$window.handleEvents(
|
fsm.$window.handleEvents(
|
||||||
[&](const sf::Event::KeyPressed &) {
|
[&](const sf::Event::KeyPressed &) {
|
||||||
|
@ -121,7 +133,10 @@ void Autowalker::autowalk() {
|
||||||
if(!fsm.autowalking) return;
|
if(!fsm.autowalking) return;
|
||||||
|
|
||||||
process_combat();
|
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 current = get_current_position();
|
||||||
Point target = current;
|
Point target = current;
|
||||||
|
@ -132,12 +147,6 @@ void Autowalker::autowalk() {
|
||||||
dbc::log("no paths found, aborting autowalk");
|
dbc::log("no paths found, aborting autowalk");
|
||||||
fsm.autowalking = false;
|
fsm.autowalking = false;
|
||||||
return;
|
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);
|
rotate_player(current, target);
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
struct Autowalker {
|
struct Autowalker {
|
||||||
int enemy_count = 0;
|
int enemy_count = 0;
|
||||||
|
int item_count = 0;
|
||||||
|
int device_count = 0;
|
||||||
gui::FSM& fsm;
|
gui::FSM& fsm;
|
||||||
|
|
||||||
Autowalker(gui::FSM& fsm)
|
Autowalker(gui::FSM& fsm)
|
||||||
|
@ -12,7 +14,6 @@ struct Autowalker {
|
||||||
void autowalk();
|
void autowalk();
|
||||||
void start_autowalk();
|
void start_autowalk();
|
||||||
void send_event(gui::Event ev);
|
void send_event(gui::Event ev);
|
||||||
Pathing compute_paths();
|
|
||||||
void window_events();
|
void window_events();
|
||||||
void process_combat();
|
void process_combat();
|
||||||
bool path_player(Pathing& paths, Point &target_out);
|
bool path_player(Pathing& paths, Point &target_out);
|
||||||
|
@ -20,4 +21,7 @@ struct Autowalker {
|
||||||
void rotate_player(Point current, Point target);
|
void rotate_player(Point current, Point target);
|
||||||
bool player_has_moved(Point target);
|
bool player_has_moved(Point target);
|
||||||
void process_move();
|
void process_move();
|
||||||
|
Pathing path_to_enemies();
|
||||||
|
Pathing path_to_items();
|
||||||
|
Pathing path_to_devices();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue