Made an AI debug view to I can make working on the AI easier. I might add the ability to toggle things on/off live to see what the AI does.
This commit is contained in:
parent
fc8e65f4d6
commit
4bf9a9177f
8 changed files with 60 additions and 16 deletions
1
ai.hpp
1
ai.hpp
|
@ -34,6 +34,7 @@ namespace ai {
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
void dump();
|
void dump();
|
||||||
|
std::string to_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AIManager {
|
struct AIManager {
|
||||||
|
|
10
ai_debug.cpp
10
ai_debug.cpp
|
@ -61,4 +61,14 @@ namespace ai {
|
||||||
dump_script(script, start, plan.script);
|
dump_script(script, start, plan.script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string EntityAI::to_string() {
|
||||||
|
AIProfile* profile = ai::profile();
|
||||||
|
std::string result = wants_to();
|
||||||
|
|
||||||
|
for(auto& [name, name_id] : *profile) {
|
||||||
|
result += fmt::format("\n{}={}", name, start.test(name_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ int number_left() {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Comp>
|
template<typename Comp>
|
||||||
Pathing compute_paths() {
|
Pathing compute_paths() {
|
||||||
auto& walls_original = GameDB::current_level().map->$walls;
|
auto& walls_original = GameDB::current_level().map->$walls;
|
||||||
|
@ -41,6 +42,16 @@ Pathing compute_paths() {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DinkyECS::Entity Autowalker::camera_aim() {
|
||||||
|
auto& level = GameDB::current_level();
|
||||||
|
// what happens if there's two things at that spot
|
||||||
|
if(level.collision->something_there(fsm.$main_ui.$rayview->aiming_at)) {
|
||||||
|
return level.collision->get(fsm.$main_ui.$rayview->aiming_at);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Autowalker::log(std::wstring msg) {
|
void Autowalker::log(std::wstring msg) {
|
||||||
fsm.$map_ui.log(msg);
|
fsm.$map_ui.log(msg);
|
||||||
}
|
}
|
||||||
|
@ -328,10 +339,10 @@ void Autowalker::process_move(Pathing& paths) {
|
||||||
rotate_player(current, target);
|
rotate_player(current, target);
|
||||||
|
|
||||||
// what are we aiming at?
|
// what are we aiming at?
|
||||||
auto aimed_at = fsm.$main_ui.camera_aim();
|
auto aimed_at = camera_aim();
|
||||||
|
|
||||||
if(aimed_at && GameDB::current_world()->has<components::InventoryItem>(aimed_at)) {
|
if(aimed_at && GameDB::current_world()->has<components::InventoryItem>(aimed_at)) {
|
||||||
// NOTE: if we're aiming at an item then pick it up
|
// 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
|
// for now just loot it then close to get it off the map
|
||||||
send_event(gui::Event::LOOT_ITEM);
|
send_event(gui::Event::LOOT_ITEM);
|
||||||
send_event(gui::Event::LOOT_OPEN);
|
send_event(gui::Event::LOOT_OPEN);
|
||||||
|
|
|
@ -39,6 +39,7 @@ struct Autowalker {
|
||||||
void player_use_healing();
|
void player_use_healing();
|
||||||
InventoryStats player_item_count();
|
InventoryStats player_item_count();
|
||||||
ai::State update_state(ai::State start);
|
ai::State update_state(ai::State start);
|
||||||
|
DinkyECS::Entity camera_aim();
|
||||||
|
|
||||||
Pathing path_to_enemies();
|
Pathing path_to_enemies();
|
||||||
Pathing path_to_items();
|
Pathing path_to_items();
|
||||||
|
|
|
@ -354,10 +354,9 @@ namespace gui {
|
||||||
$loot_ui.update();
|
$loot_ui.update();
|
||||||
event(Event::LOOT_OPEN);
|
event(Event::LOOT_OPEN);
|
||||||
break;
|
break;
|
||||||
case KEY::Z: {
|
case KEY::Z:
|
||||||
auto& player_pos = GameDB::player_position();
|
$main_ui.toggle_mind_reading();
|
||||||
System::distribute_loot({player_pos.aiming_at});
|
break;
|
||||||
} break;
|
|
||||||
case KEY::X:
|
case KEY::X:
|
||||||
event(Event::STAIRS_DOWN);
|
event(Event::STAIRS_DOWN);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "game_level.hpp"
|
#include "game_level.hpp"
|
||||||
|
#include "ai.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
using namespace components;
|
using namespace components;
|
||||||
|
@ -31,20 +32,12 @@ namespace gui {
|
||||||
$overlay_ui.init();
|
$overlay_ui.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
DinkyECS::Entity MainUI::camera_aim() {
|
|
||||||
auto& level = GameDB::current_level();
|
|
||||||
// what happens if there's two things at that spot
|
|
||||||
if(level.collision->something_there($rayview->aiming_at)) {
|
|
||||||
return level.collision->get($rayview->aiming_at);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainUI::render() {
|
void MainUI::render() {
|
||||||
if($needs_render) $rayview->render();
|
if($needs_render) $rayview->render();
|
||||||
$rayview->draw($window);
|
$rayview->draw($window);
|
||||||
|
|
||||||
|
if($mind_reading) render_mind_reading();
|
||||||
$overlay_ui.render($window);
|
$overlay_ui.render($window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +90,32 @@ namespace gui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainUI::toggle_mind_reading() {
|
||||||
|
$mind_reading = !$mind_reading;
|
||||||
|
|
||||||
|
if($mind_reading) {
|
||||||
|
render_mind_reading();
|
||||||
|
} else {
|
||||||
|
$overlay_ui.close_text("left");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainUI::render_mind_reading() {
|
||||||
|
auto level = GameDB::current_level();
|
||||||
|
if(level.collision->occupied($rayview->aiming_at)) {
|
||||||
|
auto entity = level.collision->get($rayview->aiming_at);
|
||||||
|
|
||||||
|
if(auto enemy_ai = level.world->get_if<ai::EntityAI>(entity)) {
|
||||||
|
$overlay_ui.show_text("left", fmt::format(L"AI: {}",
|
||||||
|
guecs::to_wstring(enemy_ai->to_string())));
|
||||||
|
} else {
|
||||||
|
$overlay_ui.show_text("left", L"no mind to read");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$overlay_ui.show_text("left", L"nothing there");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainUI::update_level() {
|
void MainUI::update_level() {
|
||||||
auto& level = GameDB::current_level();
|
auto& level = GameDB::current_level();
|
||||||
auto& player_position = GameDB::player_position();
|
auto& player_position = GameDB::player_position();
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace gui {
|
||||||
public:
|
public:
|
||||||
int $compass_dir = 0;
|
int $compass_dir = 0;
|
||||||
bool $needs_render = true;
|
bool $needs_render = true;
|
||||||
|
bool $mind_reading = false;
|
||||||
sf::Clock $clock;
|
sf::Clock $clock;
|
||||||
sf::RenderWindow& $window;
|
sf::RenderWindow& $window;
|
||||||
OverlayUI $overlay_ui;
|
OverlayUI $overlay_ui;
|
||||||
|
@ -31,7 +32,6 @@ namespace gui {
|
||||||
Point plan_move(int dir, bool strafe);
|
Point plan_move(int dir, bool strafe);
|
||||||
void abort_plan();
|
void abort_plan();
|
||||||
void update_level();
|
void update_level();
|
||||||
DinkyECS::Entity camera_aim();
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void render();
|
void render();
|
||||||
|
@ -39,5 +39,7 @@ namespace gui {
|
||||||
lel::Cell overlay_cell(const std::string& name);
|
lel::Cell overlay_cell(const std::string& name);
|
||||||
|
|
||||||
void dead_entity(DinkyECS::Entity entity);
|
void dead_entity(DinkyECS::Entity entity);
|
||||||
|
void toggle_mind_reading();
|
||||||
|
void render_mind_reading();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,6 +270,7 @@ void System::combat(int attack_id) {
|
||||||
battle.set_all("enemy_found", true);
|
battle.set_all("enemy_found", true);
|
||||||
battle.set_all("in_combat", true);
|
battle.set_all("in_combat", true);
|
||||||
battle.plan();
|
battle.plan();
|
||||||
|
battle.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
while(auto act = battle.next()) {
|
while(auto act = battle.next()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue