derive threat cost dynamically

This commit is contained in:
2026-06-13 21:50:00 +02:00
parent 3716c2b734
commit 10c5ad678f
28 changed files with 498 additions and 79 deletions

View File

@@ -1144,6 +1144,8 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
break;
case Qt::Key_M:
m_debugDraw = !m_debugDraw;
EventManager::getInstance()->sendEventImmediately(
std::make_shared<DebugDrawToggledEvent>(m_debugDraw));
break;
case Qt::Key_L:
EventManager::getInstance()->addEvent(std::make_shared<TracePrintRequestedEvent>());
@@ -1438,6 +1440,11 @@ double GameWorldView::gameSpeed() const
return m_gameSpeedMultiplier;
}
bool GameWorldView::isDebugDrawEnabled() const
{
return m_debugDraw;
}
void GameWorldView::resetFrameTimer()
{
m_frameTimer.restart();

View File

@@ -24,6 +24,7 @@
#include "EventHandler.h"
#include "ExitBlueprintModeRequestedEvent.h"
#include "ExitBuilderModeRequestedEvent.h"
#include "DebugDrawToggledEvent.h"
#include "WeaponFiredEvent.h"
#include "SchematicChoiceOption.h"
#include "SpeedChangeRequestedEvent.h"
@@ -65,6 +66,7 @@ public:
~GameWorldView() override;
double gameSpeed() const;
bool isDebugDrawEnabled() const;
void resetFrameTimer();
void setGameSpeed(double multiplier);
void resetForNewGame();

View File

@@ -223,6 +223,7 @@ void MainWindow::handleEvent(std::shared_ptr<const LayoutDialogRequestedEvent> e
m_layoutBlueprints,
std::move(unlockedModuleIds),
std::move(moduleLevels),
m_gameWorldView->isDebugDrawEnabled(),
this);
if (dialog.exec() == QDialog::Accepted && dialog.result().has_value())
{

View File

@@ -23,6 +23,7 @@
#include "ShipIdentityComponent.h"
#include "ShipStatsCalculator.h"
#include "ShipStatsPanel.h"
#include "ThreatCostCalculator.h"
#include "StationBodyComponent.h"
#include "TickAdvancedEvent.h"
#include "Building.h"
@@ -784,6 +785,19 @@ void SelectedBuildingPanel::buildEntityShip(entt::entity entity)
const ShipStats stats = buildShipStatsFromEntity(admin, entity);
m_entityStatsPanel->refreshFromLive(stats, health.hp);
m_entityStatsPanel->setDebugDrawEnabled(m_debugDraw);
for (const ShipDef& def : m_config->ships.ships)
{
if (def.id == identity.schematicId)
{
double threat = calculateShipThreatCost(
m_config->threatCosts, *m_config, def.id, def.defaultModules);
m_entityStatsPanel->setThreatCost(threat);
break;
}
}
m_entityStatsPanel->show();
m_stationStatsLabel->hide();
@@ -869,3 +883,9 @@ void SelectedBuildingPanel::handleEvent(std::shared_ptr<const SelectionChangedEv
{
onSelectionChanged(event->ids);
}
void SelectedBuildingPanel::handleEvent(std::shared_ptr<const DebugDrawToggledEvent> event)
{
m_debugDraw = event->active;
m_entityStatsPanel->setDebugDrawEnabled(event->active);
}

View File

@@ -11,6 +11,7 @@
#include "Building.h"
#include "BuildingId.h"
#include "DebugDrawToggledEvent.h"
#include "EntitySelectedEvent.h"
#include "EventHandler.h"
#include "GameConfig.h"
@@ -33,7 +34,8 @@ class QVBoxLayout;
class SelectedBuildingPanel : public QWidget,
public CombinedEventHandler<TickAdvancedEvent,
EntitySelectedEvent,
SelectionChangedEvent>
SelectionChangedEvent,
DebugDrawToggledEvent>
{
Q_OBJECT
@@ -46,6 +48,7 @@ private:
void handleEvent(std::shared_ptr<const TickAdvancedEvent> event) override;
void handleEvent(std::shared_ptr<const EntitySelectedEvent> event) override;
void handleEvent(std::shared_ptr<const SelectionChangedEvent> event) override;
void handleEvent(std::shared_ptr<const DebugDrawToggledEvent> event) override;
private slots:
void onRecipeChanged(int comboIndex);
@@ -86,6 +89,7 @@ private:
QPoint m_splitterTile;
std::string m_currentRecipeId;
bool m_debugDraw = false;
std::optional<entt::entity> m_selectedEntity;
ShipStatsPanel* m_entityStatsPanel;
QLabel* m_entityTitleLabel;

View File

@@ -366,6 +366,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
std::vector<ShipLayoutBlueprint>& allBlueprints,
std::set<std::string> unlockedModuleIds,
std::map<std::string, int> moduleLevels,
bool debugDraw,
QWidget* parent)
: QDialog(parent)
, m_config(config)
@@ -380,6 +381,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
, m_removeButton(nullptr)
, m_gridWidget(nullptr)
, m_statsPanel(nullptr)
, m_debugDraw(debugDraw)
{
setWindowTitle(tr("Configure Ship Layout"));
setModal(true);
@@ -434,6 +436,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
// Left column: ship stats panel.
m_statsPanel = new ShipStatsPanel(config, this);
m_statsPanel->setDebugDrawEnabled(m_debugDraw);
columnsLayout->addWidget(m_statsPanel);
// Center column: module selection buttons.

View File

@@ -28,6 +28,7 @@ public:
std::vector<ShipLayoutBlueprint>& allBlueprints,
std::set<std::string> unlockedModuleIds,
std::map<std::string, int> moduleLevels,
bool debugDraw,
QWidget* parent = nullptr);
std::optional<ShipLayoutConfig> result() const;
@@ -77,6 +78,7 @@ private:
QPushButton* m_removeButton;
QWidget* m_gridWidget;
ShipStatsPanel* m_statsPanel;
bool m_debugDraw;
std::optional<ShipLayoutConfig> m_result;
};

View File

@@ -6,6 +6,7 @@
#include "GameConfig.h"
#include "ShipStatsCalculator.h"
#include "ThreatCostCalculator.h"
namespace
{
@@ -103,6 +104,11 @@ ShipStatsPanel::ShipStatsPanel(const GameConfig* config, QWidget* parent)
m_repairSection->setVisible(false);
layout->addWidget(m_repairSection);
// Threat cost — debug-only, initially hidden.
m_threatCostLabel = makeStatLabel(this);
m_threatCostLabel->setVisible(false);
layout->addWidget(m_threatCostLabel);
layout->addStretch();
}
@@ -115,6 +121,10 @@ void ShipStatsPanel::refresh(const std::string& shipId,
moduleLevelOverrides);
const QString hpText = tr("HP: %1").arg(static_cast<int>(stats.hp + 0.5f));
applyStats(stats, hpText);
const double threat = calculateShipThreatCost(m_config->threatCosts, *m_config,
shipId, modules);
setThreatCost(threat);
}
void ShipStatsPanel::refreshFromLive(const ShipStats& stats, float currentHp)
@@ -180,3 +190,15 @@ void ShipStatsPanel::applyStats(const ShipStats& stats, const QString& hpText)
m_repairSection->setVisible(false);
}
}
void ShipStatsPanel::setThreatCost(double cost)
{
m_threatCostLabel->setText(tr("Threat Cost: %1").arg(cost, 0, 'f', 1));
m_threatCostLabel->setVisible(m_debugDraw);
}
void ShipStatsPanel::setDebugDrawEnabled(bool enabled)
{
m_debugDraw = enabled;
m_threatCostLabel->setVisible(m_debugDraw);
}

View File

@@ -26,10 +26,14 @@ public:
void refreshFromLive(const ShipStats& stats, float currentHp);
void setThreatCost(double cost);
void setDebugDrawEnabled(bool enabled);
private:
void applyStats(const ShipStats& stats, const QString& hpText);
const GameConfig* m_config;
bool m_debugDraw = false;
QLabel* m_hpLabel;
QLabel* m_speedLabel;
@@ -50,4 +54,6 @@ private:
QWidget* m_repairSection;
QLabel* m_repairRateLabel;
QLabel* m_repairRangeLabel;
QLabel* m_threatCostLabel;
};