change repair_tool application and add beams for salvager and repair_tool

This commit is contained in:
2026-06-18 22:14:09 +02:00
parent 7924e037aa
commit 9573b9789a
37 changed files with 498 additions and 199 deletions

View File

@@ -41,6 +41,7 @@
#include "ShipSystem.h"
#include "Simulation.h"
#include "StationBodyComponent.h"
#include "ScrapDataComponent.h"
#include "SurfaceMask.h"
#include "Tick.h"
#include "EscapeMenuRequestedEvent.h"
@@ -157,11 +158,11 @@ void GameWorldView::onFrame()
// Emit fire events via EventManager
{
const std::vector<WeaponFiredEvent> fires = m_sim->drainWeaponFiredEvents();
for (const WeaponFiredEvent& fe : fires)
const std::vector<BeamFiredEvent> fires = m_sim->drainBeamFiredEvents();
for (const BeamFiredEvent& fe : fires)
{
EventManager::getInstance()->sendEventImmediately(
std::make_shared<WeaponFiredEvent>(fe));
std::make_shared<BeamFiredEvent>(fe));
}
}
@@ -1031,12 +1032,20 @@ void GameWorldView::drawDebugOverlay(QPainter& painter)
void GameWorldView::drawBeams(QPainter& painter)
{
painter.setPen(QPen(m_visuals->beams.color, m_visuals->beams.widthPx));
for (const ActiveBeam& beam : m_activeBeams)
{
const std::optional<QVector2D> shooterPos = entityPosition(beam.event.shooter);
const std::optional<QVector2D> targetPos = entityPosition(beam.event.target);
if (!shooterPos.has_value() || !targetPos.has_value()) { continue; }
QColor color = m_visuals->beams.weaponColor;
switch (beam.event.kind)
{
case BeamKind::Weapon: color = m_visuals->beams.weaponColor; break;
case BeamKind::Repair: color = m_visuals->beams.repairColor; break;
case BeamKind::Salvage: color = m_visuals->beams.salvageColor; break;
}
painter.setPen(QPen(color, m_visuals->beams.widthPx));
painter.drawLine(worldToWidget(*shooterPos),
worldToWidget(*targetPos + beam.targetOffset));
}
@@ -1567,8 +1576,11 @@ void GameWorldView::resetForNewGame()
// Event handlers
// ---------------------------------------------------------------------------
void GameWorldView::handleEvent(std::shared_ptr<const WeaponFiredEvent> event)
void GameWorldView::handleEvent(std::shared_ptr<const BeamFiredEvent> event)
{
// Endpoint offset is a fraction of the target's visual size (REQ-SHP-FIRING-BEAM):
// half a ship's rendered radius, half a station's shorter footprint side, or
// half a scrap pile's rendered radius (scrap is drawn at tilePx()*0.2).
float maxRadius = 0.125f;
if (m_sim->admin().isValid(event->target)
&& m_sim->admin().hasAll<StationBodyComponent>(event->target))
@@ -1577,6 +1589,11 @@ void GameWorldView::handleEvent(std::shared_ptr<const WeaponFiredEvent> event)
const int shorter = std::min(sb.footprint.width(), sb.footprint.height());
maxRadius = shorter / 2.0f;
}
else if (m_sim->admin().isValid(event->target)
&& m_sim->admin().hasAll<ScrapDataComponent>(event->target))
{
maxRadius = 0.1f;
}
std::uniform_real_distribution<float> angleDist(0.0f, 6.28318530f);
std::uniform_real_distribution<float> radiusDist(0.0f, maxRadius);

View File

@@ -25,7 +25,7 @@
#include "ExitBlueprintModeRequestedEvent.h"
#include "ExitBuilderModeRequestedEvent.h"
#include "DebugDrawToggledEvent.h"
#include "WeaponFiredEvent.h"
#include "BeamFiredEvent.h"
#include "SchematicChoiceOption.h"
#include "SpeedChangeRequestedEvent.h"
@@ -50,7 +50,7 @@ struct QPointCompare
};
class GameWorldView : public QOpenGLWidget,
public CombinedEventHandler<WeaponFiredEvent,
public CombinedEventHandler<BeamFiredEvent,
BuildingTypeSelectedEvent,
ExitBuilderModeRequestedEvent,
DemolishModeToggleRequestedEvent,
@@ -84,7 +84,7 @@ private slots:
void onFrame();
private:
void handleEvent(std::shared_ptr<const WeaponFiredEvent> event) override;
void handleEvent(std::shared_ptr<const BeamFiredEvent> event) override;
void handleEvent(std::shared_ptr<const BuildingTypeSelectedEvent> event) override;
void handleEvent(std::shared_ptr<const ExitBuilderModeRequestedEvent> event) override;
void handleEvent(std::shared_ptr<const DemolishModeToggleRequestedEvent> event) override;
@@ -140,7 +140,7 @@ private:
struct ActiveBeam
{
WeaponFiredEvent event;
BeamFiredEvent event;
qint64 emittedWallMs;
QVector2D targetOffset;
};

View File

@@ -34,7 +34,9 @@ struct ShipVisuals
struct BeamVisuals
{
QColor color;
QColor weaponColor;
QColor repairColor;
QColor salvageColor;
int widthPx;
};

View File

@@ -209,8 +209,10 @@ VisualsConfig VisualsLoader::load(const std::string& path)
// Beams
{
toml::table& beams = requireSubtable(tbl, "beams", "root");
cfg.beams.color = parseColor(requireString(beams, "color", "beams"), "beams.color");
cfg.beams.widthPx = requireInt(beams, "width_px", "beams");
cfg.beams.weaponColor = parseColor(requireString(beams, "weapon_color", "beams"), "beams.weapon_color");
cfg.beams.repairColor = parseColor(requireString(beams, "repair_color", "beams"), "beams.repair_color");
cfg.beams.salvageColor = parseColor(requireString(beams, "salvage_color", "beams"), "beams.salvage_color");
cfg.beams.widthPx = requireInt(beams, "width_px", "beams");
}
// Overlays