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
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#include "DeliverScrapEvaluator.h"
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "BehaviorScores.h"
|
|
#include "BehaviorTargeting.h"
|
|
#include "Building.h"
|
|
#include "BuildingSystem.h"
|
|
#include "BuildingType.h"
|
|
#include "DeliverScrapBehavior.h"
|
|
#include "EntityAdmin.h"
|
|
#include "PositionComponent.h"
|
|
#include "tracing.h"
|
|
|
|
void DeliverScrapEvaluator::evaluate(EntityAdmin& admin, const BuildingSystem& buildings)
|
|
{
|
|
TRACE();
|
|
const std::unordered_map<entt::entity, CargoState> cargoByShip = buildCargoByShip(admin);
|
|
|
|
admin.forEach<DeliverScrapBehavior, PositionComponent>(
|
|
[&](entt::entity e, DeliverScrapBehavior& deliver, const PositionComponent& pos)
|
|
{
|
|
const std::unordered_map<entt::entity, CargoState>::const_iterator it =
|
|
cargoByShip.find(e);
|
|
const bool cargoFull = (it != cargoByShip.end()) && isCargoFull(it->second);
|
|
|
|
if (!cargoFull)
|
|
{
|
|
deliver.score = BehaviorScores::kInactive;
|
|
return;
|
|
}
|
|
|
|
// Assign nearest SalvageBay if not yet assigned.
|
|
if (!deliver.deliveryBay.has_value())
|
|
{
|
|
const Building* bay =
|
|
buildings.findNearestBuilding(pos.value, BuildingType::SalvageBay);
|
|
if (bay) { deliver.deliveryBay = bay->id; }
|
|
}
|
|
|
|
deliver.score = BehaviorScores::kDeliver;
|
|
});
|
|
}
|