diff --git a/src/ui/GameWorldView.cpp b/src/ui/GameWorldView.cpp index 7deeb6c..aac87da 100644 --- a/src/ui/GameWorldView.cpp +++ b/src/ui/GameWorldView.cpp @@ -118,6 +118,7 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config, , m_demolishMode(false) , m_demolishHoverId(kInvalidEntityId) , m_debugDraw(false) + , m_rng(std::random_device{}()) , m_boxSelecting(false) , m_scrollLeft(false) , m_scrollRight(false) @@ -158,9 +159,25 @@ void GameWorldView::onFrame() const std::vector fires = m_sim->drainFireEvents(); for (const FireEvent& fe : fires) { + float maxRadius = 0.125f; + const Building* tBld = m_sim->buildings().findBuilding(fe.target); + if (tBld) + { + const int shorter = std::min(tBld->footprint.width(), + tBld->footprint.height()); + maxRadius = shorter / 2.0f; + } + + std::uniform_real_distribution angleDist(0.0f, 6.28318530f); + std::uniform_real_distribution radiusDist(0.0f, maxRadius); + const float angle = angleDist(m_rng); + const float radius = radiusDist(m_rng); + ActiveBeam beam; beam.event = fe; beam.emittedWallMs = m_wallMs; + beam.targetOffset = QVector2D(radius * std::cos(angle), + radius * std::sin(angle)); m_activeBeams.push_back(beam); } } @@ -821,7 +838,8 @@ void GameWorldView::drawBeams(QPainter& painter) const std::optional shooterPos = entityPosition(beam.event.shooter); const std::optional targetPos = entityPosition(beam.event.target); if (!shooterPos.has_value() || !targetPos.has_value()) { continue; } - painter.drawLine(worldToWidget(*shooterPos), worldToWidget(*targetPos)); + painter.drawLine(worldToWidget(*shooterPos), + worldToWidget(*targetPos + beam.targetOffset)); } } diff --git a/src/ui/GameWorldView.h b/src/ui/GameWorldView.h index 304c8bd..b8cc731 100644 --- a/src/ui/GameWorldView.h +++ b/src/ui/GameWorldView.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -116,6 +117,7 @@ private: { FireEvent event; qint64 emittedWallMs; + QVector2D targetOffset; }; struct ToastEntry @@ -136,6 +138,7 @@ private: TickDriver m_tickDriver; QElapsedTimer m_frameTimer; qint64 m_wallMs; + std::mt19937 m_rng; double m_gameSpeedMultiplier; double m_prevNonZeroSpeed; float m_scrollXTiles;