fix issue where construction sites could be placed outside of game world and add tests

This commit is contained in:
2026-06-22 21:13:01 +02:00
parent 59688e6532
commit e5017ab3c5
6 changed files with 251 additions and 19 deletions

View File

@@ -385,30 +385,26 @@ const BuildingDef* GameWorldView::findBuildingDef(BuildingType type) const
bool GameWorldView::isValidPlacement(BuildingType type, QPoint anchor,
Rotation rot) const
{
// Terrain and world-bounds validity are owned by the simulation
// (REQ-BLD-PLACE-VALID); the presentation layer only adds the occupancy /
// rotate-in-place check.
if (!m_sim->buildings().isPlacementValid(type, anchor, rot))
{
return false;
}
const BuildingDef* def = findBuildingDef(type);
if (!def) { return false; }
const ParsedSurfaceMask parsed = parseSurfaceMask(def->surfaceMask, rot);
bool anyOccupied = false;
for (const QPoint& relCell : parsed.bodyCells)
{
const QPoint worldCell = anchor + relCell;
// Terrain check: S cells must be space (x >= 0), A cells must be asteroid (x < 0)
bool isShipDock = false;
for (const QPoint& dock : parsed.shipDockCells)
if (m_sim->buildings().isTileOccupied(anchor + relCell))
{
if (dock == relCell)
{
isShipDock = true;
break;
}
anyOccupied = true;
break;
}
if (isShipDock && worldCell.x() < 0) { return false; }
if (!isShipDock && worldCell.x() >= 0) { return false; }
if (m_sim->buildings().isTileOccupied(worldCell)) { anyOccupied = true; }
}
if (anyOccupied)