Next phase of the refactor is done. Now to replace everything in Systems.

This commit is contained in:
Zed A. Shaw 2025-08-19 01:07:28 -04:00
parent 644ff6edc0
commit 81e25f73bb
10 changed files with 163 additions and 82 deletions

View file

@ -1,14 +1,15 @@
#include "autowalker.hpp"
#include "ai_debug.hpp"
#include "gui/ritual_ui.hpp"
#include "game_level.hpp"
template<typename Comp>
int number_left(gui::FSM& fsm) {
int number_left() {
int count = 0;
fsm.$level.world->query<components::Position, Comp>(
Game::current_world()->query<components::Position, Comp>(
[&](const auto ent, auto&, auto&) {
if(ent != fsm.$level.player) {
if(ent != Game::current().player) {
count++;
}
});
@ -17,16 +18,16 @@ int number_left(gui::FSM& fsm) {
}
template<typename Comp>
Pathing compute_paths(gui::FSM& fsm) {
auto& walls_original = fsm.$level.map->$walls;
Pathing compute_paths() {
auto& walls_original = Game::current().map->$walls;
auto walls_copy = walls_original;
Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)};
fsm.$level.world->query<components::Position>(
Game::current().world->query<components::Position>(
[&](const auto ent, auto& position) {
if(ent != fsm.$level.player) {
if(fsm.$level.world->has<Comp>(ent)) {
if(ent != Game::current().player) {
if(Game::current().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
@ -53,11 +54,11 @@ void Autowalker::close_status() {
}
Pathing Autowalker::path_to_enemies() {
return compute_paths<components::Combat>(fsm);
return compute_paths<components::Combat>();
}
Pathing Autowalker::path_to_items() {
return compute_paths<components::InventoryItem>(fsm);
return compute_paths<components::InventoryItem>();
}
void Autowalker::handle_window_events() {
@ -88,8 +89,7 @@ void Autowalker::process_combat() {
}
Point Autowalker::get_current_position() {
auto& player_position = fsm.$level.world->get<components::Position>(fsm.$level.player);
return player_position.location;
return Game::player_position().location;
}
void Autowalker::path_fail(Matrix& bad_paths, Point pos) {
@ -110,7 +110,7 @@ bool Autowalker::path_player(Pathing& paths, Point& target_out) {
}
}
if(!fsm.$level.map->can_move(target_out)) {
if(!Game::current().map->can_move(target_out)) {
path_fail(paths.$paths, target_out);
return false;
}
@ -184,8 +184,8 @@ struct InventoryStats {
};
ai::State Autowalker::update_state(ai::State start) {
int enemy_count = number_left<components::Combat>(fsm);
int item_count = number_left<components::InventoryItem>(fsm);
int enemy_count = number_left<components::Combat>();
int item_count = number_left<components::InventoryItem>();
ai::set(start, "no_more_enemies", enemy_count == 0);
ai::set(start, "no_more_items", item_count == 0);
@ -330,7 +330,7 @@ void Autowalker::process_move(Pathing& paths) {
// what are we aiming at?
auto aimed_at = fsm.$main_ui.camera_aim();
if(aimed_at && fsm.$level.world->has<components::InventoryItem>(aimed_at)) {
if(aimed_at && Game::current_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);
@ -349,7 +349,8 @@ void Autowalker::send_event(gui::Event ev) {
}
bool Autowalker::player_health_good() {
auto combat = fsm.$level.world->get<components::Combat>(fsm.$level.player);
auto world = Game::current_world();
auto combat = world->get<components::Combat>(Game::the_player());
return float(combat.hp) / float(combat.max_hp) > 0.5f;
}