fix bug where selecting the same layout for a shipyard discarded the current progress and buffers
This commit is contained in:
@@ -284,6 +284,21 @@ void BuildingSystem::setShipLayout(FactoryState& state, BuildingId id, const Shi
|
||||
{
|
||||
if (building.id == id)
|
||||
{
|
||||
// No-op if the layout is unchanged, so re-applying the layout a shipyard
|
||||
// already has does not cancel its production cycle or wipe its buffers
|
||||
// (REQ-MAT-INPUT-BUFFER, REQ-BLD-SHIPYARD). Confirming the layout dialog
|
||||
// without editing anything, and a blueprint configuration transfer onto an
|
||||
// already-matching shipyard (REQ-UI-BLUEPRINT-TRANSFER), both land here.
|
||||
// An unset layout counts as an empty one: the two are equivalent for
|
||||
// buffers, production, and the spawned ship (see the spawn path below),
|
||||
// so an empty layout arriving at an unconfigured shipyard changes nothing.
|
||||
const bool unchanged = building.shipLayout.has_value()
|
||||
? *building.shipLayout == layout
|
||||
: layout.placedModules.empty();
|
||||
if (unchanged)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (building.production.has_value())
|
||||
{
|
||||
building.production = std::nullopt;
|
||||
|
||||
@@ -15,8 +15,23 @@ struct PlacedModule
|
||||
Rotation rotation;
|
||||
};
|
||||
|
||||
inline bool operator==(const PlacedModule& a, const PlacedModule& b)
|
||||
{
|
||||
return a.moduleId == b.moduleId && a.position == b.position && a.rotation == b.rotation;
|
||||
}
|
||||
|
||||
// The complete module configuration for a shipyard's current ship (REQ-MOD-CONFIG).
|
||||
struct ShipLayoutConfig
|
||||
{
|
||||
std::vector<PlacedModule> placedModules;
|
||||
};
|
||||
|
||||
// Deliberately order-sensitive: two layouts holding the same modules in a different
|
||||
// vector order compare unequal. This only decides whether applying a layout is a no-op
|
||||
// (REQ-MAT-INPUT-BUFFER), so the conservative answer is the safe one -- reporting a
|
||||
// change that is not one costs a buffer reset, reporting no change when there is one
|
||||
// would leave the shipyard stale.
|
||||
inline bool operator==(const ShipLayoutConfig& a, const ShipLayoutConfig& b)
|
||||
{
|
||||
return a.placedModules == b.placedModules;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user