Add artifact win condition (#3)
Reviewed-on: #3 Co-authored-by: Malte Langkabel <malte.langkabel@gmail.com> Co-committed-by: Malte Langkabel <malte.langkabel@gmail.com>
This commit was merged in pull request #3.
This commit is contained in:
@@ -194,7 +194,11 @@ void GameWorldView::onFrame()
|
||||
static_cast<double>(elapsed), m_gameSpeedMultiplier);
|
||||
for (int i = 0; i < ticks; ++i)
|
||||
{
|
||||
if (m_replayPlayer->isFinished()) { break; }
|
||||
// Stop at the recorded stream's end, or at the run's terminal state:
|
||||
// the real game froze when it was won or lost, so the replay does too
|
||||
// (the recording may run a few ticks past that point).
|
||||
if (m_replayPlayer->isFinished()
|
||||
|| m_sim->isWon() || m_sim->isGameOver()) { break; }
|
||||
m_sim->tick();
|
||||
m_replayPlayer->advanceTo(m_sim->currentTick());
|
||||
}
|
||||
@@ -310,6 +314,14 @@ void GameWorldView::onFrame()
|
||||
m_schematicChoiceShown = false;
|
||||
}
|
||||
|
||||
// Win check
|
||||
if (m_sim->isWon() && !m_winShown)
|
||||
{
|
||||
m_winShown = true;
|
||||
m_gameSpeedMultiplier = 0.0;
|
||||
EventManager::getInstance()->sendEventImmediately(std::make_shared<WinEvent>());
|
||||
}
|
||||
|
||||
// Game over check
|
||||
if (m_sim->isGameOver() && !m_gameOverShown)
|
||||
{
|
||||
@@ -320,6 +332,20 @@ void GameWorldView::onFrame()
|
||||
}
|
||||
}
|
||||
|
||||
// Artifact count is a passive reflection of sim state (not a live-input source
|
||||
// like the schematic/game-over polls above), so it updates during replay too —
|
||||
// the recorded ApplySchematicChoice drives m_sim->artifactCount() forward and
|
||||
// the header bar must track it. Fires on the first frame (count 0 vs the -1
|
||||
// sentinel), which also populates the win-count max (replacing the "0/?" label).
|
||||
const int currentArtifactCount = m_sim->artifactCount();
|
||||
if (currentArtifactCount != m_lastArtifactCount)
|
||||
{
|
||||
m_lastArtifactCount = currentArtifactCount;
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<ArtifactCountChangedEvent>(
|
||||
currentArtifactCount, m_sim->config().world.artifacts.artifactWinCount));
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -1292,7 +1318,11 @@ void GameWorldView::drawReplayOverlay(QPainter& painter)
|
||||
painter.setPen(QColor(255, 220, 80));
|
||||
painter.drawText(QRect(0, 8, width(), 24), Qt::AlignHCenter | Qt::AlignTop, tr("REPLAY"));
|
||||
|
||||
if (m_replayPlayer->isFinished())
|
||||
// The replay is over once the recorded stream is exhausted or the run reached
|
||||
// its terminal state (win / defeat) — matching where playback freezes above.
|
||||
const bool ended = m_replayPlayer->isFinished()
|
||||
|| m_sim->isWon() || m_sim->isGameOver();
|
||||
if (ended)
|
||||
{
|
||||
// Dim the world so the end message reads clearly over it.
|
||||
painter.fillRect(rect(), QColor(0, 0, 0, 140));
|
||||
@@ -1304,6 +1334,16 @@ void GameWorldView::drawReplayOverlay(QPainter& painter)
|
||||
message = tr("Desync at tick %1").arg(static_cast<qlonglong>(*desync));
|
||||
painter.setPen(QColor(255, 90, 90));
|
||||
}
|
||||
else if (m_sim->isWon())
|
||||
{
|
||||
message = tr("Replay ended — Victory");
|
||||
painter.setPen(QColor(120, 255, 120));
|
||||
}
|
||||
else if (m_sim->isGameOver())
|
||||
{
|
||||
message = tr("Replay ended — Defeat");
|
||||
painter.setPen(QColor(255, 255, 255));
|
||||
}
|
||||
else
|
||||
{
|
||||
message = tr("Replay ended");
|
||||
@@ -1779,12 +1819,14 @@ void GameWorldView::resetForNewGame()
|
||||
m_scrollXTiles = 0.0f;
|
||||
m_scrollLeft = false;
|
||||
m_scrollRight = false;
|
||||
m_gameOverShown = false;
|
||||
m_prevNonZeroSpeed = 1.0;
|
||||
m_gameOverShown = false;
|
||||
m_winShown = false;
|
||||
m_prevNonZeroSpeed = 1.0;
|
||||
m_lastTick = Tick(-1);
|
||||
m_lastBlocks = -1;
|
||||
m_lastBossCounter = -1;
|
||||
m_lastBossCountdown = Tick(-1);
|
||||
m_lastArtifactCount = -1;
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<SelectionChangedEvent>(std::vector<BuildingId>{}));
|
||||
setGameSpeed(1.0);
|
||||
|
||||
Reference in New Issue
Block a user