rename EntityId to BuildingId
This commit is contained in:
@@ -4,6 +4,6 @@
|
||||
// Ships, stations, scrap, and the HQ proxy use entt::entity instead.
|
||||
// Ids are allocated centrally by the Simulation, strictly increasing, never
|
||||
// reused. 0 is reserved as the invalid id.
|
||||
using EntityId = long long;
|
||||
using BuildingId = long long;
|
||||
|
||||
constexpr EntityId kInvalidEntityId = 0;
|
||||
constexpr BuildingId kInvalidBuildingId = 0;
|
||||
@@ -1,7 +1,6 @@
|
||||
SET(HDRS
|
||||
${HDRS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Tick.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntityId.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Rotation.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingType.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntityAdmin.h
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <QSize>
|
||||
#include <QVector2D>
|
||||
|
||||
#include "EntityId.h"
|
||||
#include "Tick.h"
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
@@ -104,3 +103,4 @@ struct DespawnAt
|
||||
|
||||
struct HqProxy { char unused = 0; };
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "BuildingType.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "EntityId.h"
|
||||
#include "BuildingId.h"
|
||||
#include "MovementIntent.h"
|
||||
#include "ScrapSystem.h"
|
||||
#include "Ship.h"
|
||||
@@ -329,7 +329,7 @@ void AiSystem::tickScrapCollector(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
const float collectRange = cargo.collectionRange;
|
||||
|
||||
// Assign nearest SalvageBay if needed.
|
||||
if (sc.deliveryBay == kInvalidEntityId)
|
||||
if (sc.deliveryBay == kInvalidBuildingId)
|
||||
{
|
||||
const Building* bay = buildings.findNearestBuilding(pos.value,
|
||||
BuildingType::SalvageBay);
|
||||
@@ -339,10 +339,10 @@ void AiSystem::tickScrapCollector(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
}
|
||||
}
|
||||
|
||||
const EntityId bayId = sc.deliveryBay;
|
||||
const BuildingId bayId = sc.deliveryBay;
|
||||
|
||||
QVector2D bayPos = pos.value;
|
||||
if (bayId != kInvalidEntityId)
|
||||
if (bayId != kInvalidBuildingId)
|
||||
{
|
||||
const Building* bay = buildings.findBuilding(bayId);
|
||||
if (bay)
|
||||
@@ -360,7 +360,7 @@ void AiSystem::tickScrapCollector(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
{
|
||||
intent = MovementIntent{1, bayPos};
|
||||
}
|
||||
if (bayId != kInvalidEntityId
|
||||
if (bayId != kInvalidBuildingId
|
||||
&& (pos.value - bayPos).length() <= 1.0f)
|
||||
{
|
||||
if (buildings.deliverScrapToSalvageBay(bayId))
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <QSize>
|
||||
|
||||
#include "BuildingType.h"
|
||||
#include "EntityId.h"
|
||||
#include "BuildingId.h"
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
#include "Item.h"
|
||||
@@ -45,7 +45,7 @@ struct Production
|
||||
// Occupies tiles but does not produce.
|
||||
struct ConstructionSite
|
||||
{
|
||||
EntityId id = kInvalidEntityId;
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
QPoint anchor; // top-left of body bounding box
|
||||
QSize footprint;
|
||||
std::vector<QPoint> bodyCells; // absolute world tile coordinates
|
||||
@@ -59,7 +59,7 @@ struct ConstructionSite
|
||||
// A fully constructed, operational building.
|
||||
struct Building
|
||||
{
|
||||
EntityId id = kInvalidEntityId;
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
QPoint anchor; // top-left of body bounding box
|
||||
QSize footprint;
|
||||
Rotation rotation = Rotation::East;
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
|
||||
BuildingSystem::BuildingSystem(const GameConfig& config,
|
||||
BeltSystem& belts,
|
||||
std::function<EntityId()> allocateId,
|
||||
std::function<BuildingId()> allocateBuildingId,
|
||||
std::function<void(int)> addBuildingBlocks,
|
||||
std::function<void(const std::string&, QVector2D,
|
||||
const std::optional<ShipLayoutConfig>&)> spawnShip,
|
||||
std::mt19937& rng)
|
||||
: m_config(config)
|
||||
, m_belts(belts)
|
||||
, m_allocateId(std::move(allocateId))
|
||||
, m_allocateBuildingId(std::move(allocateBuildingId))
|
||||
, m_addBuildingBlocks(std::move(addBuildingBlocks))
|
||||
, m_spawnShip(std::move(spawnShip))
|
||||
, m_rng(rng)
|
||||
@@ -227,10 +227,10 @@ std::vector<Item> BuildingSystem::rollReprocessingOutput(const RecipeDef& recipe
|
||||
// Placement
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
EntityId BuildingSystem::place(BuildingType type, QPoint anchor,
|
||||
BuildingId BuildingSystem::place(BuildingType type, QPoint anchor,
|
||||
Rotation rotation, Tick currentTick)
|
||||
{
|
||||
const EntityId id = m_allocateId();
|
||||
const BuildingId id = m_allocateBuildingId();
|
||||
|
||||
const BuildingDef* def = findBuildingDef(type);
|
||||
assert(def != nullptr);
|
||||
@@ -269,7 +269,7 @@ EntityId BuildingSystem::place(BuildingType type, QPoint anchor,
|
||||
// Demolish
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int BuildingSystem::demolish(EntityId id)
|
||||
int BuildingSystem::demolish(BuildingId id)
|
||||
{
|
||||
// Construction queue?
|
||||
for (std::deque<ConstructionSite>::iterator it = m_constructionQueue.begin();
|
||||
@@ -325,7 +325,7 @@ int BuildingSystem::demolish(EntityId id)
|
||||
// Set recipe
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void BuildingSystem::setRecipe(EntityId id, const std::string& recipeId)
|
||||
void BuildingSystem::setRecipe(BuildingId id, const std::string& recipeId)
|
||||
{
|
||||
// Construction site: store recipe for when building completes.
|
||||
for (ConstructionSite& site : m_constructionQueue)
|
||||
@@ -371,7 +371,7 @@ void BuildingSystem::setRecipe(EntityId id, const std::string& recipeId)
|
||||
}
|
||||
}
|
||||
|
||||
void BuildingSystem::setShipLayout(EntityId id, const ShipLayoutConfig& layout)
|
||||
void BuildingSystem::setShipLayout(BuildingId id, const ShipLayoutConfig& layout)
|
||||
{
|
||||
for (ConstructionSite& site : m_constructionQueue)
|
||||
{
|
||||
@@ -821,7 +821,7 @@ void BuildingSystem::tickBeltPush()
|
||||
// Queries
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const Building* BuildingSystem::findBuilding(EntityId id) const
|
||||
const Building* BuildingSystem::findBuilding(BuildingId id) const
|
||||
{
|
||||
for (const Building& building : m_buildings)
|
||||
{
|
||||
@@ -833,7 +833,7 @@ const Building* BuildingSystem::findBuilding(EntityId id) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const ConstructionSite* BuildingSystem::findSite(EntityId id) const
|
||||
const ConstructionSite* BuildingSystem::findSite(BuildingId id) const
|
||||
{
|
||||
for (const ConstructionSite& site : m_constructionQueue)
|
||||
{
|
||||
@@ -866,7 +866,7 @@ std::vector<BuildingSystem::BeltTileInfo> BuildingSystem::allBeltTiles() const
|
||||
continue;
|
||||
}
|
||||
BeltTileInfo info;
|
||||
info.id = b.id;
|
||||
info.buildingId = b.id;
|
||||
info.tile = b.bodyCells.empty() ? b.anchor : b.bodyCells[0];
|
||||
info.type = b.type;
|
||||
if (!b.outputPorts.empty())
|
||||
@@ -893,7 +893,7 @@ bool BuildingSystem::isTileOccupied(QPoint tile) const
|
||||
return m_tileOccupancy.count({tile.x(), tile.y()}) > 0;
|
||||
}
|
||||
|
||||
std::optional<EntityId> BuildingSystem::findRotateInPlaceTarget(
|
||||
std::optional<BuildingId> BuildingSystem::findRotateInPlaceTarget(
|
||||
BuildingType type, QPoint anchor, Rotation rot) const
|
||||
{
|
||||
const BuildingDef* def = findBuildingDef(type);
|
||||
@@ -906,7 +906,7 @@ std::optional<EntityId> BuildingSystem::findRotateInPlaceTarget(
|
||||
const QPoint firstAbs = anchor + mask.bodyCells[0];
|
||||
const auto firstIt = m_tileOccupancy.find({firstAbs.x(), firstAbs.y()});
|
||||
if (firstIt == m_tileOccupancy.end()) { return std::nullopt; }
|
||||
const EntityId candidateId = firstIt->second;
|
||||
const BuildingId candidateId = firstIt->second;
|
||||
|
||||
for (const QPoint& rel : mask.bodyCells)
|
||||
{
|
||||
@@ -937,7 +937,7 @@ std::optional<EntityId> BuildingSystem::findRotateInPlaceTarget(
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void BuildingSystem::rotateInPlace(EntityId id, Rotation newRotation)
|
||||
void BuildingSystem::rotateInPlace(BuildingId id, Rotation newRotation)
|
||||
{
|
||||
// Construction site path — just update rotation; no ports to recompute.
|
||||
for (ConstructionSite& site : m_constructionQueue)
|
||||
@@ -1022,7 +1022,7 @@ const Building* BuildingSystem::findNearestBuilding(QVector2D worldPos,
|
||||
return best;
|
||||
}
|
||||
|
||||
bool BuildingSystem::deliverScrapToSalvageBay(EntityId bayId)
|
||||
bool BuildingSystem::deliverScrapToSalvageBay(BuildingId bayId)
|
||||
{
|
||||
Building* bay = nullptr;
|
||||
for (Building& b : m_buildings)
|
||||
@@ -1045,11 +1045,11 @@ bool BuildingSystem::deliverScrapToSalvageBay(EntityId bayId)
|
||||
return true;
|
||||
}
|
||||
|
||||
EntityId BuildingSystem::placeImmediate(BuildingType type,
|
||||
BuildingId BuildingSystem::placeImmediate(BuildingType type,
|
||||
const std::vector<std::string>& surfaceMask,
|
||||
QPoint anchor, Rotation rotation)
|
||||
{
|
||||
const EntityId id = m_allocateId();
|
||||
const BuildingId id = m_allocateBuildingId();
|
||||
const ParsedSurfaceMask mask = parseSurfaceMask(surfaceMask, rotation);
|
||||
|
||||
Building building;
|
||||
@@ -1078,7 +1078,7 @@ EntityId BuildingSystem::placeImmediate(BuildingType type,
|
||||
return id;
|
||||
}
|
||||
|
||||
bool BuildingSystem::removeBuilding(EntityId id)
|
||||
bool BuildingSystem::removeBuilding(BuildingId id)
|
||||
{
|
||||
for (std::vector<Building>::iterator it = m_buildings.begin();
|
||||
it != m_buildings.end();
|
||||
@@ -1111,7 +1111,7 @@ void BuildingSystem::forEachBuilding(std::function<void(Building&)> fn)
|
||||
}
|
||||
|
||||
void BuildingSystem::registerTileOccupancy(const std::vector<QPoint>& cells,
|
||||
EntityId ownerPlaceholder)
|
||||
BuildingId ownerPlaceholder)
|
||||
{
|
||||
for (const QPoint& cell : cells)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "BeltSystem.h"
|
||||
#include "Building.h"
|
||||
#include "BuildingType.h"
|
||||
#include "EntityId.h"
|
||||
#include "BuildingId.h"
|
||||
#include "GameConfig.h"
|
||||
#include "Rotation.h"
|
||||
#include "ModulesConfig.h"
|
||||
@@ -32,7 +32,7 @@ class BuildingSystem
|
||||
public:
|
||||
BuildingSystem(const GameConfig& config,
|
||||
BeltSystem& belts,
|
||||
std::function<EntityId()> allocateId,
|
||||
std::function<BuildingId()> allocateBuildingId,
|
||||
std::function<void(int)> addBuildingBlocks,
|
||||
std::function<void(const std::string&, QVector2D,
|
||||
const std::optional<ShipLayoutConfig>&)> spawnShip,
|
||||
@@ -41,21 +41,21 @@ public:
|
||||
// -- Placement / demolish ------------------------------------------------
|
||||
// Returns the new entity id. Belt and Splitter register with BeltSystem
|
||||
// directly; other types enter the construction queue.
|
||||
EntityId place(BuildingType type, QPoint anchor, Rotation rotation,
|
||||
BuildingId place(BuildingType type, QPoint anchor, Rotation rotation,
|
||||
Tick currentTick);
|
||||
|
||||
// Remove a building or construction site by id. Returns the refund in
|
||||
// building blocks (floor(cost * refundPercentage / 100)). Returns 0 for
|
||||
// unknown ids.
|
||||
int demolish(EntityId id);
|
||||
int demolish(BuildingId id);
|
||||
|
||||
// Set the recipe (or schematic id for shipyard) on a building or queued
|
||||
// construction site. Clears both buffers on an operational building.
|
||||
void setRecipe(EntityId id, const std::string& recipeId);
|
||||
void setRecipe(BuildingId id, const std::string& recipeId);
|
||||
|
||||
// Set the module layout for a shipyard. Cancels in-progress production
|
||||
// (materials discarded) and reinitializes input buffers (REQ-BLD-SHIPYARD).
|
||||
void setShipLayout(EntityId id, const ShipLayoutConfig& layout);
|
||||
void setShipLayout(BuildingId id, const ShipLayoutConfig& layout);
|
||||
|
||||
// -- Tick hooks (called from Simulation::tick in the documented order) ---
|
||||
void tickConstruction(Tick currentTick);
|
||||
@@ -67,15 +67,15 @@ public:
|
||||
// -- Queries -------------------------------------------------------------
|
||||
struct BeltTileInfo
|
||||
{
|
||||
EntityId id;
|
||||
BuildingId buildingId;
|
||||
QPoint tile;
|
||||
BuildingType type; // Belt or Splitter
|
||||
Rotation directionA; // Belt: its direction; Splitter: first output
|
||||
Rotation directionB; // Splitter: second output; Belt: same as directionA
|
||||
};
|
||||
|
||||
const Building* findBuilding(EntityId id) const;
|
||||
const ConstructionSite* findSite(EntityId id) const;
|
||||
const Building* findBuilding(BuildingId id) const;
|
||||
const ConstructionSite* findSite(BuildingId id) const;
|
||||
std::vector<Building> allBuildings() const;
|
||||
std::vector<ConstructionSite> allSites() const;
|
||||
std::vector<BeltTileInfo> allBeltTiles() const;
|
||||
@@ -84,36 +84,36 @@ public:
|
||||
// Returns the entity id of the building or construction site whose footprint
|
||||
// exactly coincides with the ghost (type, anchor, rot) and is of the same
|
||||
// building type. Returns nullopt otherwise.
|
||||
std::optional<EntityId> findRotateInPlaceTarget(BuildingType type,
|
||||
std::optional<BuildingId> findRotateInPlaceTarget(BuildingType type,
|
||||
QPoint anchor,
|
||||
Rotation rot) const;
|
||||
|
||||
// Rotate an existing building or construction site to newRotation in place.
|
||||
// For belt-type operational buildings, re-registers with BeltSystem (items
|
||||
// currently on the tile are discarded by BeltSystem::removeTile).
|
||||
void rotateInPlace(EntityId id, Rotation newRotation);
|
||||
void rotateInPlace(BuildingId id, Rotation newRotation);
|
||||
|
||||
// Find nearest operational building of the given type; nullptr if none.
|
||||
const Building* findNearestBuilding(QVector2D worldPos, BuildingType type) const;
|
||||
|
||||
// Register / unregister tile occupancy for ECS station entities.
|
||||
void registerTileOccupancy(const std::vector<QPoint>& cells, EntityId ownerPlaceholder);
|
||||
void registerTileOccupancy(const std::vector<QPoint>& cells, BuildingId ownerPlaceholder);
|
||||
void unregisterTileOccupancy(const std::vector<QPoint>& cells);
|
||||
|
||||
// Place one "scrap" item into a SalvageBay's output buffer.
|
||||
// Returns false if bay not found, wrong type, or output buffer is full.
|
||||
bool deliverScrapToSalvageBay(EntityId bayId);
|
||||
bool deliverScrapToSalvageBay(BuildingId bayId);
|
||||
|
||||
// Bypass the construction queue and create a fully-operational Building
|
||||
// immediately. Used for pre-placed structures (HQ, defence stations).
|
||||
// surfaceMask comes from the relevant config struct.
|
||||
EntityId placeImmediate(BuildingType type,
|
||||
BuildingId placeImmediate(BuildingType type,
|
||||
const std::vector<std::string>& surfaceMask,
|
||||
QPoint anchor, Rotation rotation);
|
||||
|
||||
// Remove an operational building by id without refund (used for deaths).
|
||||
// Returns true if found and removed.
|
||||
bool removeBuilding(EntityId id);
|
||||
bool removeBuilding(BuildingId id);
|
||||
|
||||
// Mutable iteration over all operational buildings.
|
||||
void forEachBuilding(std::function<void(Building&)> fn);
|
||||
@@ -130,7 +130,7 @@ private:
|
||||
|
||||
const GameConfig& m_config;
|
||||
BeltSystem& m_belts;
|
||||
std::function<EntityId()> m_allocateId;
|
||||
std::function<BuildingId()> m_allocateBuildingId;
|
||||
std::function<void(int)> m_addBuildingBlocks;
|
||||
std::function<void(const std::string&, QVector2D,
|
||||
const std::optional<ShipLayoutConfig>&)> m_spawnShip;
|
||||
@@ -140,5 +140,5 @@ private:
|
||||
std::deque<ConstructionSite> m_constructionQueue;
|
||||
|
||||
// Maps every occupied body-cell coordinate to the entity that owns it.
|
||||
std::map<std::pair<int, int>, EntityId> m_tileOccupancy;
|
||||
std::map<std::pair<int, int>, BuildingId> m_tileOccupancy;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <QVector2D>
|
||||
|
||||
#include "EntityId.h"
|
||||
#include "BuildingId.h"
|
||||
#include "MovementIntent.h"
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
@@ -49,7 +49,7 @@ struct ThreatResponse
|
||||
struct ScrapCollector
|
||||
{
|
||||
std::optional<QVector2D> scrapTarget;
|
||||
EntityId deliveryBay; // kInvalidEntityId until assigned at a salvage bay
|
||||
BuildingId deliveryBay; // kInvalidBuildingId until assigned at a salvage bay
|
||||
};
|
||||
|
||||
struct RepairBehavior
|
||||
|
||||
@@ -93,7 +93,7 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level, QVecto
|
||||
|
||||
ScrapCollector sc;
|
||||
sc.scrapTarget = std::nullopt;
|
||||
sc.deliveryBay = kInvalidEntityId;
|
||||
sc.deliveryBay = kInvalidBuildingId;
|
||||
m_admin.addComponent<ScrapCollector>(entity, sc);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ Simulation::Simulation(GameConfig config, unsigned int seed)
|
||||
, m_rng(seed)
|
||||
, m_currentTick(0)
|
||||
, m_nextDepartureTick(secondsToTicks(m_config.world.departureIntervalSeconds))
|
||||
, m_nextId(1)
|
||||
, m_nextBuildingId(1)
|
||||
, m_buildingBlocksStock(m_config.world.startingBuildingBlocks)
|
||||
, m_gameOver(false)
|
||||
, m_hqBuildingId(kInvalidEntityId)
|
||||
, m_hqBuildingId(kInvalidBuildingId)
|
||||
, m_hqProxyEntity(entt::null)
|
||||
, m_playerStation1Entity(entt::null)
|
||||
, m_playerStation2Entity(entt::null)
|
||||
@@ -32,7 +32,7 @@ Simulation::Simulation(GameConfig config, unsigned int seed)
|
||||
m_buildingSystem = std::make_unique<BuildingSystem>(
|
||||
m_config,
|
||||
m_beltSystem,
|
||||
[this]() { return allocateId(); },
|
||||
[this]() { return allocateBuildingId(); },
|
||||
[this](int amount) { m_buildingBlocksStock += amount; },
|
||||
[this](const std::string& id, QVector2D pos,
|
||||
const std::optional<ShipLayoutConfig>& layout) {
|
||||
@@ -82,10 +82,10 @@ void Simulation::reset(unsigned int seed)
|
||||
m_rng.seed(seed);
|
||||
m_currentTick = 0;
|
||||
m_nextDepartureTick = secondsToTicks(m_config.world.departureIntervalSeconds);
|
||||
m_nextId = 1;
|
||||
m_nextBuildingId = 1;
|
||||
m_buildingBlocksStock = m_config.world.startingBuildingBlocks;
|
||||
m_gameOver = false;
|
||||
m_hqBuildingId = kInvalidEntityId;
|
||||
m_hqBuildingId = kInvalidBuildingId;
|
||||
m_hqProxyEntity = entt::null;
|
||||
m_playerStation1Entity = entt::null;
|
||||
m_playerStation2Entity = entt::null;
|
||||
@@ -99,7 +99,7 @@ void Simulation::reset(unsigned int seed)
|
||||
m_buildingSystem = std::make_unique<BuildingSystem>(
|
||||
m_config,
|
||||
m_beltSystem,
|
||||
[this]() { return allocateId(); },
|
||||
[this]() { return allocateBuildingId(); },
|
||||
[this](int amount) { m_buildingBlocksStock += amount; },
|
||||
[this](const std::string& id, QVector2D pos,
|
||||
const std::optional<ShipLayoutConfig>& layout) {
|
||||
@@ -247,7 +247,7 @@ void Simulation::placeInitialStructures()
|
||||
m_playerStation1Entity = m_admin.spawnStation(
|
||||
anchor, psParsed.footprint, absCells, psHp, psHp, false);
|
||||
m_admin.addComponent<Weapon>(m_playerStation1Entity, psWeapon);
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateId());
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
}
|
||||
{
|
||||
const QPoint anchor(psAnchorX, ps2Y);
|
||||
@@ -259,7 +259,7 @@ void Simulation::placeInitialStructures()
|
||||
m_playerStation2Entity = m_admin.spawnStation(
|
||||
anchor, psParsed.footprint, absCells, psHp, psHp, false);
|
||||
m_admin.addComponent<Weapon>(m_playerStation2Entity, psWeapon);
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateId());
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
}
|
||||
|
||||
// Rally point: center of the player defence stations' X column, world vertical midpoint.
|
||||
@@ -308,7 +308,7 @@ void Simulation::placeEnemyStationSet(int generation)
|
||||
m_currentEnemyStationEntities[0] = m_admin.spawnStation(
|
||||
anchor, esParsed.footprint, absCells, esHp, esHp, true);
|
||||
m_admin.addComponent<Weapon>(m_currentEnemyStationEntities[0], esWeapon);
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateId());
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
}
|
||||
{
|
||||
const QPoint anchor(anchorX, y2);
|
||||
@@ -320,7 +320,7 @@ void Simulation::placeEnemyStationSet(int generation)
|
||||
m_currentEnemyStationEntities[1] = m_admin.spawnStation(
|
||||
anchor, esParsed.footprint, absCells, esHp, esHp, true);
|
||||
m_admin.addComponent<Weapon>(m_currentEnemyStationEntities[1], esWeapon);
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateId());
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ bool Simulation::isSchematicUnlocked(const std::string& shipId) const
|
||||
return it->second.unlocked;
|
||||
}
|
||||
|
||||
EntityId Simulation::tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation rotation)
|
||||
BuildingId Simulation::tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation rotation)
|
||||
{
|
||||
int cost = 0;
|
||||
for (const BuildingDef& def : m_config.buildings.buildings)
|
||||
@@ -525,13 +525,13 @@ EntityId Simulation::tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation
|
||||
}
|
||||
if (m_buildingBlocksStock < cost)
|
||||
{
|
||||
return kInvalidEntityId;
|
||||
return kInvalidBuildingId;
|
||||
}
|
||||
m_buildingBlocksStock -= cost;
|
||||
return m_buildingSystem->place(type, anchor, rotation, m_currentTick);
|
||||
}
|
||||
|
||||
void Simulation::demolish(EntityId id)
|
||||
void Simulation::demolish(BuildingId id)
|
||||
{
|
||||
m_buildingBlocksStock += m_buildingSystem->demolish(id);
|
||||
}
|
||||
@@ -586,7 +586,7 @@ const EntityAdmin& Simulation::admin() const
|
||||
return m_admin;
|
||||
}
|
||||
|
||||
EntityId Simulation::allocateId()
|
||||
BuildingId Simulation::allocateBuildingId()
|
||||
{
|
||||
return m_nextId++;
|
||||
return m_nextBuildingId++;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "entt/entity/entity.hpp"
|
||||
#include "SchematicDropEvent.h"
|
||||
#include "BuildingType.h"
|
||||
#include "EntityId.h"
|
||||
#include "BuildingId.h"
|
||||
#include "FireEvent.h"
|
||||
#include "GameConfig.h"
|
||||
#include "Rotation.h"
|
||||
@@ -62,11 +62,11 @@ public:
|
||||
bool isSchematicUnlocked(const std::string& shipId) const;
|
||||
|
||||
// Checks affordability, deducts building blocks, and places the building.
|
||||
// Returns the new entity id, or kInvalidEntityId if blocks are insufficient.
|
||||
EntityId tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation rotation);
|
||||
// Returns the new entity id, or kInvalidBuildingId if blocks are insufficient.
|
||||
BuildingId tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation rotation);
|
||||
|
||||
// Demolishes the building with the given id and refunds building blocks.
|
||||
void demolish(EntityId id);
|
||||
void demolish(BuildingId id);
|
||||
|
||||
BuildingSystem& buildings();
|
||||
const BuildingSystem& buildings() const;
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
const EntityAdmin& admin() const;
|
||||
|
||||
private:
|
||||
EntityId allocateId(); // Strictly increasing; never returns kInvalidEntityId.
|
||||
BuildingId allocateBuildingId(); // Strictly increasing; never returns kInvalidBuildingId.
|
||||
|
||||
// Populate HQ, player defence stations, and the first enemy station set.
|
||||
void placeInitialStructures();
|
||||
@@ -100,12 +100,12 @@ private:
|
||||
|
||||
Tick m_currentTick;
|
||||
Tick m_nextDepartureTick;
|
||||
EntityId m_nextId;
|
||||
BuildingId m_nextBuildingId;
|
||||
int m_buildingBlocksStock;
|
||||
bool m_gameOver = false;
|
||||
|
||||
// Pre-placed structure IDs.
|
||||
EntityId m_hqBuildingId; // Building id (for belt integration)
|
||||
BuildingId m_hqBuildingId; // Building id (for belt integration)
|
||||
entt::entity m_hqProxyEntity; // ECS entity (HP, targeting)
|
||||
entt::entity m_playerStation1Entity;
|
||||
entt::entity m_playerStation2Entity;
|
||||
|
||||
Reference in New Issue
Block a user