Use std::optional instead of sentinel values for absent data
Replace sentinel values that signalled "no value" with std::optional across simulation, UI, and balancing code: - BuildingId references: DeliverScrapBehavior::deliveryBay, Simulation::m_hqBuildingId, the return types of BuildingSystem::place and Simulation::tryPlaceBuilding (previously kInvalidBuildingId on failure), GameWorldView building/site-at-tile lookups and demolish hover, SelectedBuildingPanel::m_singleBuildingId. - Command id fields: the five id-carrying commands now hold optional<BuildingId>; CommandSerializer and Simulation::apply updated. The serialized replay format is unchanged. - Index sentinels: BlueprintPanel::m_activeIndex, BalancingWindow::m_inspectedArenaIndex, ArenaSimulation winnerTeam, and the moduleIndex grid cells in ShipLayoutDialog/ShipLayoutPreview. ShipLayoutDialog::m_activeModuleIndex was a tri-state, so it is modelled as bool m_removeMode + optional<int>. Building/ConstructionSite id defaults keep kInvalidBuildingId (identity, not an absent reference); entt::null and config -1 domain values are left as-is. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y7N59FsLA5e2kuVdqe4Uhc
This commit is contained in:
@@ -31,7 +31,7 @@ void DeliverScrapEvaluator::evaluate(EntityAdmin& admin, const BuildingSystem& b
|
||||
}
|
||||
|
||||
// Assign nearest SalvageBay if not yet assigned.
|
||||
if (deliver.deliveryBay == kInvalidBuildingId)
|
||||
if (!deliver.deliveryBay.has_value())
|
||||
{
|
||||
const Building* bay =
|
||||
buildings.findNearestBuilding(pos.value, BuildingType::SalvageBay);
|
||||
|
||||
Reference in New Issue
Block a user