diff --git a/Makefile b/Makefile index 111d1ad..77b1ba6 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ tracy_build: meson compile -j 10 -C builddir test: build - ./builddir/runtests "[inventory]" + ./builddir/runtests run: build test ifeq '$(OS)' 'Windows_NT' @@ -57,7 +57,7 @@ clean: meson compile --clean -C builddir debug_test: build - gdb --nx -x .gdbinit --ex run --args builddir/runtests -e "[inventory]" + gdb --nx -x .gdbinit --ex run --args builddir/runtests -e win_installer: powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' diff --git a/components.hpp b/components.hpp index 3d717e4..6bb6744 100644 --- a/components.hpp +++ b/components.hpp @@ -27,7 +27,8 @@ namespace components { }; struct Position { - Point location; + Point location{0,0}; + Point aiming_at{0,0}; }; struct Motion { diff --git a/gui/fsm.cpp b/gui/fsm.cpp index 6687018..eb83da5 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -101,14 +101,18 @@ namespace gui { } } - void FSM::ROTATING(Event ) { - if($main_ui.play_rotate()) { + void FSM::ROTATING(Event) { + if(auto aim = $main_ui.play_rotate()) { + auto& player_pos = System::player_position($level); + player_pos.aiming_at = *aim; state(State::IDLE); } } - void FSM::COMBAT_ROTATE(Event ) { - if($main_ui.play_rotate()) { + void FSM::COMBAT_ROTATE(Event) { + if(auto aim = $main_ui.play_rotate()) { + auto& player_pos = System::player_position($level); + player_pos.aiming_at = *aim; state(State::IN_COMBAT); } } @@ -132,6 +136,12 @@ namespace gui { void FSM::IDLE(Event ev, std::any data) { using enum Event; + auto& player_pos = System::player_position($level); + + fmt::println("AIMING AT: {},{}; POS: {},{}", + player_pos.aiming_at.x, player_pos.aiming_at.y, + player_pos.location.x, player_pos.location.y); + sound::stop("walk"); switch(ev) { diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 36a80a5..2bdbbd2 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -45,27 +45,26 @@ namespace gui { $overlay_ui.render($window); } - void MainUI::health_low() { - $overlay_ui.show_sprite("middle", "blood_splatter"); - } - - lel::Cell MainUI::overlay_cell(const std::string& name) { return $overlay_ui.$gui.cell_for(name); } - bool MainUI::play_rotate() { - bool done = $rayview.play_rotate(); - $needs_render = !done; - - return done; + std::optional MainUI::play_rotate() { + if($rayview.play_rotate()) { + $needs_render = false; + return std::make_optional($rayview.aiming_at); + } else { + $needs_render = true; + return std::nullopt; + } } - std::optional MainUI::play_move() { + std::optional MainUI::play_move() { if($rayview.play_move()) { $needs_render = false; - return std::make_optional( - $rayview.camera_target()); + return std::make_optional( + $rayview.camera_target(), + $rayview.aiming_at); } else { $needs_render = true; return std::nullopt; @@ -104,6 +103,9 @@ namespace gui { $rayview.update_level($level); $rayview.position_camera(player.x + 0.5, player.y + 0.5); + // BUG #57: I think this is in the wrong direction? + player_position.aiming_at = $rayview.aiming_at; + $compass_dir = 0; $overlay_ui.update_level(level); diff --git a/gui/main_ui.hpp b/gui/main_ui.hpp index a87a00e..35982ec 100644 --- a/gui/main_ui.hpp +++ b/gui/main_ui.hpp @@ -28,8 +28,8 @@ namespace gui { void render_debug(); void plan_rotate(int dir, float amount); - bool play_rotate(); - std::optional play_move(); + std::optional play_rotate(); + std::optional play_move(); Point plan_move(int dir, bool strafe); void abort_plan(); void update_level(GameLevel level); @@ -40,7 +40,6 @@ namespace gui { void dirty(); lel::Cell overlay_cell(const std::string& name); - void health_low(); void dead_entity(DinkyECS::Entity entity); }; } diff --git a/systems.cpp b/systems.cpp index 0c2c486..48a0be6 100644 --- a/systems.cpp +++ b/systems.cpp @@ -396,12 +396,15 @@ void System::device(World &world, Entity actor, Entity item) { } } -void System::plan_motion(World& world, Point move_to) { +void System::plan_motion(World& world, Position move_to) { auto& player = world.get_the(); auto& player_position = world.get(player.entity); + + player_position.aiming_at = move_to.aiming_at; + auto& motion = world.get(player.entity); - motion.dx = move_to.x - player_position.location.x; - motion.dy = move_to.y - player_position.location.y; + motion.dx = move_to.location.x - player_position.location.x; + motion.dy = move_to.location.y - player_position.location.y; } /* @@ -554,3 +557,8 @@ void System::remove_from_container(World& world, Entity cont_id, const std::stri auto entity = container.get(slot_id); container.remove(entity); } + +Position& System::player_position(GameLevel& level) { + auto& player = level.world->get_the(); + return level.world->get(player.entity); +} diff --git a/systems.hpp b/systems.hpp index 0e00ef5..a70f78f 100644 --- a/systems.hpp +++ b/systems.hpp @@ -18,7 +18,7 @@ namespace System { void init_positions(World &world, SpatialMap &collider); void device(World &world, Entity actor, Entity item); - void plan_motion(World& world, Point move_to); + void plan_motion(World& world, Position move_to); std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir); Entity spawn_item(World& world, const string& name); bool drop_item(GameLevel& level, Entity item); @@ -36,4 +36,5 @@ namespace System { void remove_from_container(World& world, Entity cont_id, const std::string& name); void remove_from_world(GameLevel &level, Entity entity); + Position& player_position(GameLevel& level); }