diff --git a/src/balancing/ArenaView.cpp b/src/balancing/ArenaView.cpp index 673b34e..cf725b9 100644 --- a/src/balancing/ArenaView.cpp +++ b/src/balancing/ArenaView.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -21,6 +22,8 @@ #include "GameSpeedChangedEvent.h" #include "HealthComponent.h" #include "PositionComponent.h" +#include "RepairBehavior.h" +#include "SalvageScrapBehavior.h" #include "ScrapSystem.h" #include "SensorRangeComponent.h" #include "ShipIdentityComponent.h" @@ -460,6 +463,25 @@ void ArenaView::drawDebugSensorRanges(QPainter& painter) void ArenaView::drawDebugTargetLines(QPainter& painter) { + // Draw a thin translucent line from a ship to a target, colored by the ship's + // team to match the per-side HQ/station colors used elsewhere in the arena + // (team 1 player, team 2 enemy). Shared by the attack, repair and salvage lines. + const std::function drawTargetLine = + [&](bool isEnemy, const QVector2D& from, const QVector2D& to) + { + const BuildingType visType = isEnemy + ? BuildingType::EnemyDefenceStation + : BuildingType::PlayerDefenceStation; + const std::map::const_iterator it = + m_visuals->buildings.find(visType); + if (it == m_visuals->buildings.end()) { return; } + + QColor lineColor = it->second.fill; + lineColor.setAlpha(128); + painter.setPen(QPen(lineColor, 1)); + painter.drawLine(worldToWidget(from), worldToWidget(to)); + }; + m_sim->admin().forEach( [&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/, @@ -472,19 +494,33 @@ void ArenaView::drawDebugTargetLines(QPainter& painter) entityPosition(*attack.currentTarget); if (!targetPos.has_value()) { return; } - // Color the line by the ship's team, matching the per-side HQ/station - // colors used elsewhere in the arena (team 1 player, team 2 enemy). - const BuildingType visType = fac.isEnemy - ? BuildingType::EnemyDefenceStation - : BuildingType::PlayerDefenceStation; - const std::map::const_iterator it = - m_visuals->buildings.find(visType); - if (it == m_visuals->buildings.end()) { return; } + drawTargetLine(fac.isEnemy, pos.value, *targetPos); + }); - QColor lineColor = it->second.fill; - lineColor.setAlpha(128); - painter.setPen(QPen(lineColor, 1)); - painter.drawLine(worldToWidget(pos.value), worldToWidget(*targetPos)); + m_sim->admin().forEach( + [&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/, + const PositionComponent& pos, const FactionComponent& fac, + const RepairBehavior& repair) + { + if (!repair.currentTarget.has_value()) { return; } + + const std::optional targetPos = + entityPosition(*repair.currentTarget); + if (!targetPos.has_value()) { return; } + + drawTargetLine(fac.isEnemy, pos.value, *targetPos); + }); + + m_sim->admin().forEach( + [&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/, + const PositionComponent& pos, const FactionComponent& fac, + const SalvageScrapBehavior& salvage) + { + if (!salvage.scrapTarget.has_value()) { return; } + + drawTargetLine(fac.isEnemy, pos.value, *salvage.scrapTarget); }); } diff --git a/src/ui/GameWorldView.cpp b/src/ui/GameWorldView.cpp index 437c041..ee36a19 100644 --- a/src/ui/GameWorldView.cpp +++ b/src/ui/GameWorldView.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,8 @@ #include "GameOverEvent.h" #include "HealthComponent.h" #include "PositionComponent.h" +#include "RepairBehavior.h" +#include "SalvageScrapBehavior.h" #include "ScrapSystem.h" #include "SelectionChangedEvent.h" #include "SensorRangeComponent.h" @@ -927,6 +930,22 @@ void GameWorldView::drawDebugSensorRanges(QPainter& painter) void GameWorldView::drawDebugTargetLines(QPainter& painter) { + // Draw a thin translucent line from a ship to a target, colored by the ship's + // own schematic fill. Shared by the attack, repair and salvage target lines. + const std::function + drawTargetLine = [&](const std::string& schematicId, const QVector2D& from, + const QVector2D& to) + { + const std::map::const_iterator it = + m_visuals->ships.find(schematicId); + if (it == m_visuals->ships.end()) { return; } + + QColor lineColor = it->second.fill; + lineColor.setAlpha(128); + painter.setPen(QPen(lineColor, 1)); + painter.drawLine(worldToWidget(from), worldToWidget(to)); + }; + m_sim->admin().forEach( [&](entt::entity /*e*/, const ShipIdentityComponent& si, const PositionComponent& pos, const AttackBehavior& attack) @@ -937,14 +956,29 @@ void GameWorldView::drawDebugTargetLines(QPainter& painter) entityPosition(*attack.currentTarget); if (!targetPos.has_value()) { return; } - const std::map::const_iterator it = - m_visuals->ships.find(si.schematicId); - if (it == m_visuals->ships.end()) { return; } + drawTargetLine(si.schematicId, pos.value, *targetPos); + }); - QColor lineColor = it->second.fill; - lineColor.setAlpha(128); - painter.setPen(QPen(lineColor, 1)); - painter.drawLine(worldToWidget(pos.value), worldToWidget(*targetPos)); + m_sim->admin().forEach( + [&](entt::entity /*e*/, const ShipIdentityComponent& si, + const PositionComponent& pos, const RepairBehavior& repair) + { + if (!repair.currentTarget.has_value()) { return; } + + const std::optional targetPos = + entityPosition(*repair.currentTarget); + if (!targetPos.has_value()) { return; } + + drawTargetLine(si.schematicId, pos.value, *targetPos); + }); + + m_sim->admin().forEach( + [&](entt::entity /*e*/, const ShipIdentityComponent& si, + const PositionComponent& pos, const SalvageScrapBehavior& salvage) + { + if (!salvage.scrapTarget.has_value()) { return; } + + drawTargetLine(si.schematicId, pos.value, *salvage.scrapTarget); }); }