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