make deconstruction its own system

This commit is contained in:
2026-08-05 07:10:46 +02:00
parent 1f4503176b
commit 60260540cd
8 changed files with 154 additions and 102 deletions

View File

@@ -181,7 +181,7 @@ int BuildingSystem::deconstruct(FactoryState& state, BuildingId id, Tick current
state.deconstructionQueue.push_back(std::move(entry));
if (wasEmpty)
{
startFrontDeconstruction(state, currentTick);
startFrontDeconstruction(state, m_config, currentTick);
}
return 0;
}
@@ -189,17 +189,6 @@ int BuildingSystem::deconstruct(FactoryState& state, BuildingId id, Tick current
return 0;
}
void BuildingSystem::startFrontDeconstruction(FactoryState& state, Tick currentTick)
{
if (state.deconstructionQueue.empty()) { return; }
DeconstructionEntry& front = state.deconstructionQueue.front();
if (front.completesAt == 0)
{
front.completesAt =
currentTick + secondsToTicks(m_config.world.deconstructionTimeSeconds);
}
}
// ---------------------------------------------------------------------------
// Set recipe
// ---------------------------------------------------------------------------
@@ -334,53 +323,6 @@ void BuildingSystem::setSiteSplitterFilters(FactoryState& state, BuildingId id,
// Tick hooks
// ---------------------------------------------------------------------------
void BuildingSystem::tickDeconstruction(FactoryState& state, Tick currentTick)
{
TRACE();
if (state.deconstructionQueue.empty())
{
return;
}
DeconstructionEntry& front = state.deconstructionQueue.front();
// Guard: if the front entry's timer was never started, start it now.
if (front.completesAt == 0)
{
startFrontDeconstruction(state, currentTick);
return;
}
if (currentTick < front.completesAt)
{
return;
}
// Remove the building from the world and credit its refund (REQ-BLD-DECONSTRUCT).
// Belt/tunnel/splitter tiles were already unregistered when the building was
// queued (see deconstruct), so only tile occupancy and the record remain.
for (std::vector<Building>::iterator it = state.buildings.begin();
it != state.buildings.end();
++it)
{
if (it->id != front.id) { continue; }
const BuildingDef* def = m_config.buildings.findBuildingDef(it->type);
state.grid.release(it->bodyCells);
state.buildings.erase(it);
if (def)
{
m_addBuildingBlocks(def->cost * m_config.world.refundPercentage / 100);
}
break;
}
state.deconstructionQueue.pop_front();
// Start the next queued deconstruction, if any.
startFrontDeconstruction(state, currentTick);
}
void BuildingSystem::cancelDeconstruction(FactoryState& state, BuildingId id)
{
for (std::deque<DeconstructionEntry>::iterator it = state.deconstructionQueue.begin();