draw debug lines to repair and salvage behavior targets
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
#include <QKeyEvent>
|
||||
@@ -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<void(bool, const QVector2D&, const QVector2D&)> drawTargetLine =
|
||||
[&](bool isEnemy, const QVector2D& from, const QVector2D& to)
|
||||
{
|
||||
const BuildingType visType = isEnemy
|
||||
? BuildingType::EnemyDefenceStation
|
||||
: BuildingType::PlayerDefenceStation;
|
||||
const std::map<BuildingType, BuildingVisuals>::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<ShipIdentityComponent, PositionComponent,
|
||||
FactionComponent, AttackBehavior>(
|
||||
[&](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<BuildingType, BuildingVisuals>::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<ShipIdentityComponent, PositionComponent,
|
||||
FactionComponent, RepairBehavior>(
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/,
|
||||
const PositionComponent& pos, const FactionComponent& fac,
|
||||
const RepairBehavior& repair)
|
||||
{
|
||||
if (!repair.currentTarget.has_value()) { return; }
|
||||
|
||||
const std::optional<QVector2D> targetPos =
|
||||
entityPosition(*repair.currentTarget);
|
||||
if (!targetPos.has_value()) { return; }
|
||||
|
||||
drawTargetLine(fac.isEnemy, pos.value, *targetPos);
|
||||
});
|
||||
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent,
|
||||
FactionComponent, SalvageScrapBehavior>(
|
||||
[&](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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user