|
|
|
@ -3,13 +3,20 @@ |
|
|
|
|
#include "gui/ritual_ui.hpp" |
|
|
|
|
#include "game_level.hpp" |
|
|
|
|
|
|
|
|
|
struct InventoryStats { |
|
|
|
|
int healing = 0; |
|
|
|
|
int other = 0; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template<typename Comp> |
|
|
|
|
int number_left() { |
|
|
|
|
int count = 0; |
|
|
|
|
auto world = GameDB::current_world(); |
|
|
|
|
auto player = GameDB::the_player(); |
|
|
|
|
|
|
|
|
|
GameDB::current_world()->query<components::Position, Comp>( |
|
|
|
|
world->query<components::Position, Comp>( |
|
|
|
|
[&](const auto ent, auto&, auto&) { |
|
|
|
|
if(ent != GameDB::current_level().player) { |
|
|
|
|
if(ent != player) { |
|
|
|
|
count++; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -20,15 +27,16 @@ int number_left() { |
|
|
|
|
|
|
|
|
|
template<typename Comp> |
|
|
|
|
Pathing compute_paths() { |
|
|
|
|
auto& walls_original = GameDB::current_level().map->$walls; |
|
|
|
|
auto& level = GameDB::current_level(); |
|
|
|
|
auto& walls_original = level.map->$walls; |
|
|
|
|
auto walls_copy = walls_original; |
|
|
|
|
|
|
|
|
|
Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)}; |
|
|
|
|
|
|
|
|
|
GameDB::current_level().world->query<components::Position>( |
|
|
|
|
level.world->query<components::Position>( |
|
|
|
|
[&](const auto ent, auto& position) { |
|
|
|
|
if(ent != GameDB::current_level().player) { |
|
|
|
|
if(GameDB::current_level().world->has<Comp>(ent)) { |
|
|
|
|
if(ent != level.player) { |
|
|
|
|
if(level.world->has<Comp>(ent)) { |
|
|
|
|
paths.set_target(position.location); |
|
|
|
|
} else { |
|
|
|
|
// this will mark that spot as a wall so we don't path there temporarily
|
|
|
|
@ -111,6 +119,7 @@ void Autowalker::path_fail(Matrix& bad_paths, Point pos) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Autowalker::path_player(Pathing& paths, Point& target_out) { |
|
|
|
|
auto &level = GameDB::current_level(); |
|
|
|
|
bool found = paths.random_walk(target_out, false, PATHING_TOWARD, 4, 8); |
|
|
|
|
|
|
|
|
|
if(!found) { |
|
|
|
@ -121,7 +130,7 @@ bool Autowalker::path_player(Pathing& paths, Point& target_out) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!GameDB::current_level().map->can_move(target_out)) { |
|
|
|
|
if(!level.map->can_move(target_out)) { |
|
|
|
|
path_fail(paths.$paths, target_out); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -189,11 +198,6 @@ void Autowalker::rotate_player(Point current, Point target) { |
|
|
|
|
"player isn't facing the correct direction"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct InventoryStats { |
|
|
|
|
int healing = 0; |
|
|
|
|
int other = 0; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
ai::State Autowalker::update_state(ai::State start) { |
|
|
|
|
int enemy_count = number_left<components::Combat>(); |
|
|
|
|
int item_count = number_left<components::InventoryItem>(); |
|
|
|
@ -327,6 +331,7 @@ void Autowalker::autowalk() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Autowalker::process_move(Pathing& paths) { |
|
|
|
|
auto world = GameDB::current_world(); |
|
|
|
|
Point current = get_current_position(); |
|
|
|
|
Point target = current; |
|
|
|
|
|
|
|
|
@ -341,7 +346,7 @@ void Autowalker::process_move(Pathing& paths) { |
|
|
|
|
// what are we aiming at?
|
|
|
|
|
auto aimed_at = camera_aim(); |
|
|
|
|
|
|
|
|
|
if(aimed_at && GameDB::current_world()->has<components::InventoryItem>(aimed_at)) { |
|
|
|
|
if(aimed_at && world->has<components::InventoryItem>(aimed_at)) { |
|
|
|
|
// NOTE: if we're aiming at an item then pick it up
|
|
|
|
|
// for now just loot it then close to get it off the map
|
|
|
|
|
send_event(gui::Event::LOOT_ITEM); |
|
|
|
@ -361,7 +366,8 @@ void Autowalker::send_event(gui::Event ev) { |
|
|
|
|
|
|
|
|
|
bool Autowalker::player_health_good() { |
|
|
|
|
auto world = GameDB::current_world(); |
|
|
|
|
auto combat = world->get<components::Combat>(GameDB::the_player()); |
|
|
|
|
auto player = GameDB::the_player(); |
|
|
|
|
auto combat = world->get<components::Combat>(player); |
|
|
|
|
return float(combat.hp) / float(combat.max_hp) > 0.5f; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|