move ecs related code to own folder
This commit is contained in:
@@ -10,16 +10,20 @@
|
||||
#include "BuildingSystem.h"
|
||||
#include "BuildingType.h"
|
||||
#include "CombatSystem.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "DynamicBodySystem.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "MovementIntentSystem.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "ScrapSystem.h"
|
||||
#include "Ship.h"
|
||||
#include "ShipIdentityComponent.h"
|
||||
#include "ShipSystem.h"
|
||||
#include "ShipsConfig.h"
|
||||
#include "StationBodyComponent.h"
|
||||
#include "StationsConfig.h"
|
||||
#include "SurfaceMask.h"
|
||||
#include "WeaponComponent.h"
|
||||
|
||||
ArenaSimulation::ArenaSimulation(const GameConfig& gameConfig,
|
||||
ArenaConfig arenaConfig,
|
||||
@@ -87,8 +91,6 @@ void ArenaSimulation::placeStructures()
|
||||
{
|
||||
absCells.push_back(QPoint(anchor.x() + rel.x(), anchor.y() + rel.y()));
|
||||
}
|
||||
const QVector2D center(anchorX + hqParsed.footprint.width() / 2.0f,
|
||||
anchorY + hqParsed.footprint.height() / 2.0f);
|
||||
m_team1HqEntity = m_admin.spawnStation(anchor, hqParsed.footprint, absCells,
|
||||
hp, hp, false);
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
@@ -116,7 +118,7 @@ void ArenaSimulation::placeStructures()
|
||||
auto placeArenaStation = [&](const ArenaStationEntry& entry, bool isEnemy)
|
||||
{
|
||||
float hp = 0.0f;
|
||||
Weapon weapon;
|
||||
WeaponComponent weapon;
|
||||
weapon.cooldownTicks = 0.0f;
|
||||
weapon.currentTarget = std::nullopt;
|
||||
const double lv = static_cast<double>(entry.level);
|
||||
@@ -157,7 +159,7 @@ void ArenaSimulation::placeStructures()
|
||||
}
|
||||
const entt::entity stationEntity = m_admin.spawnStation(
|
||||
anchor, parsed.footprint, absCells, hp, hp, isEnemy);
|
||||
m_admin.addComponent<Weapon>(stationEntity, weapon);
|
||||
m_admin.addComponent<WeaponComponent>(stationEntity, weapon);
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
};
|
||||
|
||||
@@ -275,8 +277,9 @@ void ArenaSimulation::tickDeaths()
|
||||
{
|
||||
// Dead ships.
|
||||
std::vector<entt::entity> deadShips;
|
||||
m_admin.forEach<ShipIdentity, Health>(
|
||||
[&deadShips](entt::entity e, const ShipIdentity& /*si*/, const Health& h)
|
||||
m_admin.forEach<ShipIdentityComponent, HealthComponent>(
|
||||
[&deadShips](entt::entity e, const ShipIdentityComponent& /*si*/,
|
||||
const HealthComponent& h)
|
||||
{
|
||||
if (h.hp <= 0.0f)
|
||||
{
|
||||
@@ -286,8 +289,8 @@ void ArenaSimulation::tickDeaths()
|
||||
|
||||
for (entt::entity deadEntity : deadShips)
|
||||
{
|
||||
const ShipIdentity& si = m_admin.get<ShipIdentity>(deadEntity);
|
||||
const Position& pos = m_admin.get<Position>(deadEntity);
|
||||
const ShipIdentityComponent& si = m_admin.get<ShipIdentityComponent>(deadEntity);
|
||||
const PositionComponent& pos = m_admin.get<PositionComponent>(deadEntity);
|
||||
for (const ShipDef& def : m_gameConfig.ships.ships)
|
||||
{
|
||||
if (def.id == si.schematicId && def.loot.scrapDrop > 0)
|
||||
@@ -303,8 +306,9 @@ void ArenaSimulation::tickDeaths()
|
||||
|
||||
// Dead stations.
|
||||
std::vector<entt::entity> deadStations;
|
||||
m_admin.forEach<StationBody, Health>(
|
||||
[&deadStations](entt::entity e, const StationBody& /*sb*/, const Health& h)
|
||||
m_admin.forEach<StationBodyComponent, HealthComponent>(
|
||||
[&deadStations](entt::entity e, const StationBodyComponent& /*sb*/,
|
||||
const HealthComponent& h)
|
||||
{
|
||||
if (h.hp <= 0.0f)
|
||||
{
|
||||
@@ -314,16 +318,16 @@ void ArenaSimulation::tickDeaths()
|
||||
|
||||
for (entt::entity deadEntity : deadStations)
|
||||
{
|
||||
const StationBody& sb = m_admin.get<StationBody>(deadEntity);
|
||||
const StationBodyComponent& sb = m_admin.get<StationBodyComponent>(deadEntity);
|
||||
m_buildingSystem->unregisterTileOccupancy(sb.bodyCells);
|
||||
m_admin.destroy(deadEntity);
|
||||
}
|
||||
|
||||
// Check end conditions — HQ proxy entities.
|
||||
const bool team1HqGone = !m_admin.isValid(m_team1HqEntity)
|
||||
|| m_admin.get<Health>(m_team1HqEntity).hp <= 0.0f;
|
||||
|| m_admin.get<HealthComponent>(m_team1HqEntity).hp <= 0.0f;
|
||||
const bool team2HqGone = !m_admin.isValid(m_team2HqEntity)
|
||||
|| m_admin.get<Health>(m_team2HqEntity).hp <= 0.0f;
|
||||
|| m_admin.get<HealthComponent>(m_team2HqEntity).hp <= 0.0f;
|
||||
|
||||
if (team1HqGone || team2HqGone)
|
||||
{
|
||||
@@ -336,19 +340,19 @@ void ArenaSimulation::tickDeaths()
|
||||
// Check if all ships and defence stations of one team are destroyed.
|
||||
bool team1HasUnits = false;
|
||||
bool team2HasUnits = false;
|
||||
m_admin.forEach<ShipIdentity, Faction>(
|
||||
m_admin.forEach<ShipIdentityComponent, FactionComponent>(
|
||||
[&team1HasUnits, &team2HasUnits](entt::entity /*e*/,
|
||||
const ShipIdentity& /*si*/,
|
||||
const Faction& f)
|
||||
const ShipIdentityComponent& /*si*/,
|
||||
const FactionComponent& f)
|
||||
{
|
||||
if (f.isEnemy) { team2HasUnits = true; }
|
||||
else { team1HasUnits = true; }
|
||||
});
|
||||
|
||||
m_admin.forEach<StationBody, Faction>(
|
||||
m_admin.forEach<StationBodyComponent, FactionComponent>(
|
||||
[&team1HasUnits, &team2HasUnits](entt::entity /*e*/,
|
||||
const StationBody& /*sb*/,
|
||||
const Faction& f)
|
||||
const StationBodyComponent& /*sb*/,
|
||||
const FactionComponent& f)
|
||||
{
|
||||
if (f.isEnemy) { team2HasUnits = true; }
|
||||
else { team1HasUnits = true; }
|
||||
@@ -442,7 +446,7 @@ void ArenaSimulation::updateStatus()
|
||||
hqEntry.total = 1;
|
||||
const entt::entity hqEntity = (ti == 0) ? m_team1HqEntity : m_team2HqEntity;
|
||||
hqEntry.surviving = (m_admin.isValid(hqEntity)
|
||||
&& m_admin.get<Health>(hqEntity).hp > 0.0f) ? 1 : 0;
|
||||
&& m_admin.get<HealthComponent>(hqEntity).hp > 0.0f) ? 1 : 0;
|
||||
teamStatus.entries.push_back(hqEntry);
|
||||
}
|
||||
|
||||
@@ -456,9 +460,10 @@ void ArenaSimulation::updateStatus()
|
||||
|
||||
int surviving = 0;
|
||||
const bool isEnemyTeam = (ti == 1);
|
||||
m_admin.forEach<ShipIdentity, Faction, Health>(
|
||||
m_admin.forEach<ShipIdentityComponent, FactionComponent, HealthComponent>(
|
||||
[&surviving, &shipEntry, isEnemyTeam](entt::entity /*e*/,
|
||||
const ShipIdentity& si, const Faction& f, const Health& h)
|
||||
const ShipIdentityComponent& si, const FactionComponent& f,
|
||||
const HealthComponent& h)
|
||||
{
|
||||
if (f.isEnemy == isEnemyTeam
|
||||
&& si.schematicId == shipEntry.schematicId
|
||||
@@ -484,9 +489,10 @@ void ArenaSimulation::updateStatus()
|
||||
|
||||
int surviving = 0;
|
||||
const bool isEnemyTeam = (ti == 1);
|
||||
m_admin.forEach<StationBody, Faction, Health>(
|
||||
m_admin.forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
[&surviving, &stationEntry, isEnemyTeam](entt::entity /*e*/,
|
||||
const StationBody& sb, const Faction& f, const Health& h)
|
||||
const StationBodyComponent& sb, const FactionComponent& f,
|
||||
const HealthComponent& h)
|
||||
{
|
||||
if (f.isEnemy == isEnemyTeam
|
||||
&& sb.anchor == stationEntry.position
|
||||
@@ -503,4 +509,3 @@ void ArenaSimulation::updateStatus()
|
||||
std::lock_guard<std::mutex> lock(m_statusMutex);
|
||||
m_status = newStatus;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user