diff options
author | Aki <please@ignore.pl> | 2023-02-20 00:14:28 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-02-20 00:14:28 +0100 |
commit | 401a7af25e42efc1b451e2467a3b7cde55c30443 (patch) | |
tree | 05cbb9466e35800de193a632d7ffd8d6ef20ec3b | |
parent | 72339476bb9d252c2752c662d9153dd81753991e (diff) | |
download | kurator-401a7af25e42efc1b451e2467a3b7cde55c30443.zip kurator-401a7af25e42efc1b451e2467a3b7cde55c30443.tar.gz kurator-401a7af25e42efc1b451e2467a3b7cde55c30443.tar.bz2 |
Added inspect visuals for AI state
-rw-r--r-- | kurator/src/Battle.cpp | 1 | ||||
-rw-r--r-- | kurator/src/inspect.cpp | 56 | ||||
-rw-r--r-- | kurator/src/inspect.h | 8 |
3 files changed, 63 insertions, 2 deletions
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<universe::TurretType>(*it); inspect<sim::FloatingMovement>(*it); inspect<sim::HitPoints>(*it); + inspect<sim::AIState>(*it); inspect<TurretVisuals>(*it); + inspect<AIVisuals>(*it); it = std::next(it); ImGui::PopID(); } @@ -75,6 +77,7 @@ InspectionWindow::select(entt::handle entity) entity.get<Marker>().selected = true; auto* registry = entity.registry(); auto turrets = registry->view<sim::TurretControl>(); + entity.emplace<AIVisuals>(); selected.push_back(std::move(entity)); for (auto&& [entity_, turret] : turrets.each()) { if (turret.owner == entity) { @@ -96,6 +99,8 @@ InspectionWindow::deselect() entity_.get<Marker>().selected = false; if (entity_.all_of<TurretVisuals>()) entity_.remove<TurretVisuals>(); + if (entity_.all_of<AIVisuals>()) + entity_.remove<AIVisuals>(); } 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<AIVisuals, sim::AIState, sim::Transform>(); + 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<sim::Transform>(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 |