fix bug where demolishing construction sites was not possible
This commit is contained in:
@@ -393,12 +393,31 @@ EntityId GameWorldView::buildingAtTile(QPoint tile) const
|
||||
{
|
||||
for (const QPoint& cell : b.bodyCells)
|
||||
{
|
||||
if (cell == tile) { return b.id; }
|
||||
if (cell == tile)
|
||||
{
|
||||
return b.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return kInvalidEntityId;
|
||||
}
|
||||
|
||||
EntityId GameWorldView::siteAtTile(QPoint tile) const
|
||||
{
|
||||
for (const ConstructionSite& s : m_sim->buildings().allSites())
|
||||
{
|
||||
for (const QPoint& cell : s.bodyCells)
|
||||
{
|
||||
if (cell == tile)
|
||||
{
|
||||
return s.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return kInvalidEntityId;
|
||||
}
|
||||
|
||||
|
||||
std::optional<QVector2D> GameWorldView::entityPosition(EntityId id) const
|
||||
{
|
||||
const Ship* ship = m_sim->ships().findShip(id);
|
||||
@@ -435,14 +454,23 @@ void GameWorldView::stepSpeed(int delta)
|
||||
|
||||
void GameWorldView::placeAtTile(QPoint tile)
|
||||
{
|
||||
if (!m_builderType.has_value()) { return; }
|
||||
if (!m_builderType.has_value())
|
||||
{
|
||||
return;
|
||||
}
|
||||
const BuildingType type = *m_builderType;
|
||||
|
||||
if (!isValidPlacement(type, tile, m_ghostRotation)) { return; }
|
||||
if (!isValidPlacement(type, tile, m_ghostRotation))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == BuildingType::Belt)
|
||||
{
|
||||
if (m_beltDragTiles.count(tile) > 0) { return; }
|
||||
if (m_beltDragTiles.count(tile) > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!m_sim->buildings().isTileOccupied(tile))
|
||||
{
|
||||
const EntityId id = m_sim->tryPlaceBuilding(
|
||||
@@ -914,13 +942,17 @@ void GameWorldView::mousePressEvent(QMouseEvent* event)
|
||||
}
|
||||
else if (m_demolishMode)
|
||||
{
|
||||
const EntityId hovered = buildingAtTile(tile);
|
||||
EntityId hovered = buildingAtTile(tile);
|
||||
if (hovered == kInvalidEntityId)
|
||||
{
|
||||
hovered = siteAtTile(tile);
|
||||
}
|
||||
if (hovered != kInvalidEntityId)
|
||||
{
|
||||
const Building* b = m_sim->buildings().findBuilding(hovered);
|
||||
const bool protected_ = b && (b->type == BuildingType::Hq
|
||||
const bool isProtected = b && (b->type == BuildingType::Hq
|
||||
|| b->type == BuildingType::PlayerDefenceStation);
|
||||
if (!protected_)
|
||||
if (!isProtected)
|
||||
{
|
||||
m_sim->demolish(hovered);
|
||||
m_demolishHoverId = kInvalidEntityId;
|
||||
|
||||
@@ -96,6 +96,7 @@ private:
|
||||
bool isValidPlacement(BuildingType type, QPoint anchor, Rotation rot) const;
|
||||
const BuildingDef* findBuildingDef(BuildingType type) const;
|
||||
EntityId buildingAtTile(QPoint tile) const;
|
||||
EntityId siteAtTile(QPoint tile) const;
|
||||
|
||||
void drawPortGlyph(QPainter& painter, QPoint bodyTile,
|
||||
Rotation direction, const QColor& color);
|
||||
|
||||
Reference in New Issue
Block a user