draw debug lines to repair and salvage behavior targets
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
@@ -21,6 +22,8 @@
|
|||||||
#include "GameSpeedChangedEvent.h"
|
#include "GameSpeedChangedEvent.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
#include "PositionComponent.h"
|
#include "PositionComponent.h"
|
||||||
|
#include "RepairBehavior.h"
|
||||||
|
#include "SalvageScrapBehavior.h"
|
||||||
#include "ScrapSystem.h"
|
#include "ScrapSystem.h"
|
||||||
#include "SensorRangeComponent.h"
|
#include "SensorRangeComponent.h"
|
||||||
#include "ShipIdentityComponent.h"
|
#include "ShipIdentityComponent.h"
|
||||||
@@ -460,6 +463,25 @@ void ArenaView::drawDebugSensorRanges(QPainter& painter)
|
|||||||
|
|
||||||
void ArenaView::drawDebugTargetLines(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,
|
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent,
|
||||||
FactionComponent, AttackBehavior>(
|
FactionComponent, AttackBehavior>(
|
||||||
[&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/,
|
[&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/,
|
||||||
@@ -472,19 +494,33 @@ void ArenaView::drawDebugTargetLines(QPainter& painter)
|
|||||||
entityPosition(*attack.currentTarget);
|
entityPosition(*attack.currentTarget);
|
||||||
if (!targetPos.has_value()) { return; }
|
if (!targetPos.has_value()) { return; }
|
||||||
|
|
||||||
// Color the line by the ship's team, matching the per-side HQ/station
|
drawTargetLine(fac.isEnemy, pos.value, *targetPos);
|
||||||
// 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; }
|
|
||||||
|
|
||||||
QColor lineColor = it->second.fill;
|
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent,
|
||||||
lineColor.setAlpha(128);
|
FactionComponent, RepairBehavior>(
|
||||||
painter.setPen(QPen(lineColor, 1));
|
[&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/,
|
||||||
painter.drawLine(worldToWidget(pos.value), worldToWidget(*targetPos));
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@
|
|||||||
#include "GameOverEvent.h"
|
#include "GameOverEvent.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
#include "PositionComponent.h"
|
#include "PositionComponent.h"
|
||||||
|
#include "RepairBehavior.h"
|
||||||
|
#include "SalvageScrapBehavior.h"
|
||||||
#include "ScrapSystem.h"
|
#include "ScrapSystem.h"
|
||||||
#include "SelectionChangedEvent.h"
|
#include "SelectionChangedEvent.h"
|
||||||
#include "SensorRangeComponent.h"
|
#include "SensorRangeComponent.h"
|
||||||
@@ -927,6 +930,22 @@ void GameWorldView::drawDebugSensorRanges(QPainter& painter)
|
|||||||
|
|
||||||
void GameWorldView::drawDebugTargetLines(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<void(const std::string&, const QVector2D&, const QVector2D&)>
|
||||||
|
drawTargetLine = [&](const std::string& schematicId, const QVector2D& from,
|
||||||
|
const QVector2D& to)
|
||||||
|
{
|
||||||
|
const std::map<std::string, ShipVisuals>::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<ShipIdentityComponent, PositionComponent, AttackBehavior>(
|
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, AttackBehavior>(
|
||||||
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
|
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
|
||||||
const PositionComponent& pos, const AttackBehavior& attack)
|
const PositionComponent& pos, const AttackBehavior& attack)
|
||||||
@@ -937,14 +956,29 @@ void GameWorldView::drawDebugTargetLines(QPainter& painter)
|
|||||||
entityPosition(*attack.currentTarget);
|
entityPosition(*attack.currentTarget);
|
||||||
if (!targetPos.has_value()) { return; }
|
if (!targetPos.has_value()) { return; }
|
||||||
|
|
||||||
const std::map<std::string, ShipVisuals>::const_iterator it =
|
drawTargetLine(si.schematicId, pos.value, *targetPos);
|
||||||
m_visuals->ships.find(si.schematicId);
|
});
|
||||||
if (it == m_visuals->ships.end()) { return; }
|
|
||||||
|
|
||||||
QColor lineColor = it->second.fill;
|
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, RepairBehavior>(
|
||||||
lineColor.setAlpha(128);
|
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
|
||||||
painter.setPen(QPen(lineColor, 1));
|
const PositionComponent& pos, const RepairBehavior& repair)
|
||||||
painter.drawLine(worldToWidget(pos.value), worldToWidget(*targetPos));
|
{
|
||||||
|
if (!repair.currentTarget.has_value()) { return; }
|
||||||
|
|
||||||
|
const std::optional<QVector2D> targetPos =
|
||||||
|
entityPosition(*repair.currentTarget);
|
||||||
|
if (!targetPos.has_value()) { return; }
|
||||||
|
|
||||||
|
drawTargetLine(si.schematicId, pos.value, *targetPos);
|
||||||
|
});
|
||||||
|
|
||||||
|
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, SalvageScrapBehavior>(
|
||||||
|
[&](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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user