implement blueprint compatible overlap and configuration transfer
Implements the two rules specified in128bf81, which restore the copy-settings capability removed in648241bas a property of blueprint placement: press C on one configured building, then click same-type buildings to stamp its settings across the factory. The ghost colour and the click path already shared one predicate, canPlaceBuilding, which is what kept preview and outcome from disagreeing. The new rules make that answer four-valued, so the shared predicate becomes a shared classifier: resolveBlueprintGhost in PlacementRules returns PlaceNew / CompatibleOverlap / Transfer / Invalid, and both callers switch on it. Putting it in lib rather than in the view is the whole testability story -- src/ui is off the test include path. findRotateInPlaceTarget is now the tunnel guard plus a shared findCoincidingSameTypeBuilding core, so the two rules cannot drift apart; its existing tests pass untouched. Blueprint placement no longer emits RotateInPlaceCommand at all. Builder mode and the belt drag are unchanged. transferConfigTo sends every field unconditionally, so a field the blueprint stores nothing for clears the target's rather than leaving it. The simulation's unchanged-value guards absorb the no-op case, which is what keeps clicking an already-matching building free of buffer and production-progress loss. drawBuildingGhost's bool valid becomes GhostTint{Normal,Invalid,Transfer}; the transfer colour is taken at full RGB like the invalid one so it does not double-dim against the ghost opacity. visuals.toml regains the overlay colour under the name config_transfer, with its VisualsConfig field and loader line -- overlay keys are mandatory, so the three move together. The six new resolveBlueprintGhost cases failed on first run because the test buildings were anchored in space: BuildingSystem::place skips the terrain rules, resolveBlueprintGhost applies them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcReq7hVk4KUPhTDKWAG7K
This commit is contained in:
@@ -30,9 +30,27 @@ bool bodyCellsWithinWorldBounds(const FactoryState& state, const GameConfig& con
|
||||
bool isPlacementValid(const FactoryState& state, const GameConfig& config,
|
||||
BuildingType type, QPoint anchor, Rotation rotation);
|
||||
|
||||
// An existing building or site whose footprint a ghost exactly covers.
|
||||
struct CoincidingBuilding
|
||||
{
|
||||
BuildingId id;
|
||||
Rotation rotation;
|
||||
};
|
||||
|
||||
// The building or site whose footprint a ghost of the given type/anchor/rotation
|
||||
// exactly covers: same type, same body cells, a single owner. Operational buildings
|
||||
// and construction sites alike. Rotation is not part of the test -- the target's own
|
||||
// facing is reported so each caller can apply its own rule to it.
|
||||
std::optional<CoincidingBuilding> findCoincidingSameTypeBuilding(const FactoryState& state,
|
||||
const GameConfig& config,
|
||||
BuildingType type,
|
||||
QPoint anchor,
|
||||
Rotation rot);
|
||||
|
||||
// The building or site that a ghost of the given type/anchor/rotation would
|
||||
// rotate in place rather than replace: same type, same body cells, one owner
|
||||
// (REQ-BLD-ROTATE-IN-PLACE). Tunnels never qualify.
|
||||
// (REQ-BLD-ROTATE-IN-PLACE). Tunnels never qualify. Builder mode only; blueprint
|
||||
// placement mode never rotates anything -- see resolveBlueprintGhost.
|
||||
std::optional<BuildingId> findRotateInPlaceTarget(const FactoryState& state,
|
||||
const GameConfig& config,
|
||||
BuildingType type, QPoint anchor,
|
||||
@@ -46,6 +64,36 @@ std::optional<BuildingId> findRotateInPlaceTarget(const FactoryState& state,
|
||||
bool canPlaceBuilding(const FactoryState& state, const GameConfig& config,
|
||||
BuildingType type, QPoint anchor, Rotation rotation);
|
||||
|
||||
// What one ghost of a blueprint would do at its resolved tile.
|
||||
enum class BlueprintGhostAction
|
||||
{
|
||||
PlaceNew, // free, valid cells: a new construction site, charged for
|
||||
CompatibleOverlap, // the same building is already there: left untouched, free
|
||||
// (REQ-UI-BLUEPRINT-OVERLAP)
|
||||
Transfer, // hand this blueprint's settings to the building already there,
|
||||
// free (REQ-UI-BLUEPRINT-TRANSFER)
|
||||
Invalid // terrain, bounds, or an overlap that is neither of the above
|
||||
};
|
||||
|
||||
struct BlueprintGhostResolved
|
||||
{
|
||||
BlueprintGhostAction action;
|
||||
std::optional<BuildingId> targetId; // set for CompatibleOverlap and Transfer
|
||||
};
|
||||
|
||||
// Classifies one ghost of a blueprint against the current factory state
|
||||
// (REQ-UI-BLUEPRINT-OVERLAP, REQ-UI-BLUEPRINT-TRANSFER). `blueprintHoldsOneBuilding` is
|
||||
// the blueprint's stored size, counted before locked types are dropped, so the gesture
|
||||
// does not change behavior as the player unlocks things.
|
||||
//
|
||||
// Shared by the ghost coloring and the click path so a preview cannot disagree with what
|
||||
// the click then does -- the same reason resolveBeltDragPath is shared.
|
||||
BlueprintGhostResolved resolveBlueprintGhost(const FactoryState& state,
|
||||
const GameConfig& config,
|
||||
BuildingType type, QPoint anchor,
|
||||
Rotation rotation,
|
||||
bool blueprintHoldsOneBuilding);
|
||||
|
||||
// What a belt drag would do to one tile of its path (REQ-BLD-BELT-DRAG).
|
||||
enum class BeltTileAction
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user