From 401a7af25e42efc1b451e2467a3b7cde55c30443 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 20 Feb 2023 00:14:28 +0100 Subject: Added inspect visuals for AI state --- kurator/src/Battle.cpp | 1 + kurator/src/inspect.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++-- kurator/src/inspect.h | 8 +++++++ 3 files changed, 63 insertions(+), 2 deletions(-) (limited to 'kurator/src') diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index fe3c37b..d214b89 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -162,6 +162,7 @@ Battle::draw() const ClearBackground(BLACK); Grid().draw(ctx.camera); draw_turret_visuals(ctx); + draw_ai_visuals(ctx); draw_crosses(ctx); draw_lines(ctx); draw_markers(ctx); diff --git a/kurator/src/inspect.cpp b/kurator/src/inspect.cpp index 062630c..8499e44 100644 --- a/kurator/src/inspect.cpp +++ b/kurator/src/inspect.cpp @@ -53,7 +53,9 @@ InspectionWindow::show() inspect(*it); inspect(*it); inspect(*it); + inspect(*it); inspect(*it); + inspect(*it); it = std::next(it); ImGui::PopID(); } @@ -75,6 +77,7 @@ InspectionWindow::select(entt::handle entity) entity.get().selected = true; auto* registry = entity.registry(); auto turrets = registry->view(); + entity.emplace(); selected.push_back(std::move(entity)); for (auto&& [entity_, turret] : turrets.each()) { if (turret.owner == entity) { @@ -96,6 +99,8 @@ InspectionWindow::deselect() entity_.get().selected = false; if (entity_.all_of()) entity_.remove(); + if (entity_.all_of()) + entity_.remove(); } selected.clear(); } @@ -147,14 +152,31 @@ inspect(entt::handle&, sim::HitPoints& points) template <> void +inspect(entt::handle&, sim::AIState& ai) +{ + ImGui::InputDouble("Keep At Range", &ai.keep_at_range, 0, 0, "%.1f"); +} + + +template <> +void +inspect(entt::handle&, AIVisuals& visuals) +{ + ImGui::Checkbox("Show Target", &visuals.show_target); + ImGui::Checkbox("Show Destination", &visuals.show_destination); +} + + +template <> +void inspect(entt::handle&, TurretVisuals& visuals) { ImGui::Checkbox("Show Turret Ranges", &visuals.visible); } -static Color OPTIMAL {0x88, 0x22, 0x22, 0xff}; -static Color EFFECTIVE {0x77, 0x50, 0x22, 0xff}; +static constexpr Color OPTIMAL {0x88, 0x22, 0x22, 0xff}; +static constexpr Color EFFECTIVE {0x77, 0x50, 0x22, 0xff}; void @@ -174,4 +196,34 @@ draw_turret_visuals(const sim::State& ctx) } +static constexpr Color DESTINATION {0x22, 0x22, 0x88, 0xff}; +static constexpr Color TARGET {0x44, 0x22, 0x66, 0xff}; + + +void +draw_ai_visuals(const sim::State& ctx) +{ + const auto visuals = ctx.registry.view(); + for (const auto& [entity, visuals, ai, transform] : visuals.each()) { + const auto start = ctx.camera.to_screen(transform.position); + if (visuals.show_target && ctx.registry.valid(ai.target)) { + const auto& target = ctx.registry.get(ai.target); + const auto end = ctx.camera.to_screen(target.position); + DrawLine(start.x, start.y, end.x, end.y, TARGET); + } + if (!visuals.show_destination) + continue; + static constexpr double radius = 8.0; + const auto dest = ctx.camera.to_screen(ai.destination); + const auto diff = dest - start; + const auto length = diff.magnitude(); + if (length > radius) { + const auto end = start + diff.normalized().scale(length - radius); + DrawLine(start.x, start.y, end.x, end.y, DESTINATION); + } + DrawCircleLines(dest.x, dest.y, radius, DESTINATION); + } +} + + } // namespace kurator diff --git a/kurator/src/inspect.h b/kurator/src/inspect.h index b123219..3b49d17 100644 --- a/kurator/src/inspect.h +++ b/kurator/src/inspect.h @@ -27,7 +27,15 @@ struct TurretVisuals }; +struct AIVisuals +{ + bool show_target = true; + bool show_destination = true; +}; + + void draw_turret_visuals(const sim::State& ctx); +void draw_ai_visuals(const sim::State& ctx); } // namespace kurator -- cgit v1.1