define ship roles via added modules and allow multiple weapons
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "DynamicBodySystem.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "ModuleOwnerComponent.h"
|
||||
#include "MovementIntentSystem.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "ScrapSystem.h"
|
||||
@@ -173,6 +174,7 @@ void Simulation::tick()
|
||||
m_aiSystem->tickHomeReturnBehavior(m_admin); // priority 4
|
||||
m_aiSystem->tickThreatResponseBehavior(m_admin, *m_buildingSystem); // priority 3
|
||||
m_aiSystem->tickRepairBehavior(m_admin, *m_buildingSystem); // priority 2
|
||||
m_aiSystem->tickRepairTools(m_admin);
|
||||
m_aiSystem->tickSalvageBehavior(m_admin, *m_scrapSystem, *m_buildingSystem); // priority 1
|
||||
|
||||
// Step 8: combat resolution
|
||||
@@ -255,7 +257,12 @@ void Simulation::placeInitialStructures()
|
||||
}
|
||||
m_playerStation1Entity = m_admin.spawnStation(
|
||||
anchor, psParsed.footprint, absCells, psHp, psHp, false);
|
||||
m_admin.addComponent<WeaponComponent>(m_playerStation1Entity, psWeapon);
|
||||
{
|
||||
entt::entity wChild = m_admin.createModuleEntity();
|
||||
m_admin.addComponent<WeaponComponent>(wChild, psWeapon);
|
||||
m_admin.addComponent<ModuleOwnerComponent>(wChild,
|
||||
ModuleOwnerComponent{m_playerStation1Entity});
|
||||
}
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
}
|
||||
{
|
||||
@@ -267,7 +274,12 @@ void Simulation::placeInitialStructures()
|
||||
}
|
||||
m_playerStation2Entity = m_admin.spawnStation(
|
||||
anchor, psParsed.footprint, absCells, psHp, psHp, false);
|
||||
m_admin.addComponent<WeaponComponent>(m_playerStation2Entity, psWeapon);
|
||||
{
|
||||
entt::entity wChild = m_admin.createModuleEntity();
|
||||
m_admin.addComponent<WeaponComponent>(wChild, psWeapon);
|
||||
m_admin.addComponent<ModuleOwnerComponent>(wChild,
|
||||
ModuleOwnerComponent{m_playerStation2Entity});
|
||||
}
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
}
|
||||
|
||||
@@ -316,7 +328,12 @@ void Simulation::placeEnemyStationSet(int generation)
|
||||
}
|
||||
m_currentEnemyStationEntities[0] = m_admin.spawnStation(
|
||||
anchor, esParsed.footprint, absCells, esHp, esHp, true);
|
||||
m_admin.addComponent<WeaponComponent>(m_currentEnemyStationEntities[0], esWeapon);
|
||||
{
|
||||
entt::entity wChild = m_admin.createModuleEntity();
|
||||
m_admin.addComponent<WeaponComponent>(wChild, esWeapon);
|
||||
m_admin.addComponent<ModuleOwnerComponent>(wChild,
|
||||
ModuleOwnerComponent{m_currentEnemyStationEntities[0]});
|
||||
}
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
}
|
||||
{
|
||||
@@ -328,7 +345,12 @@ void Simulation::placeEnemyStationSet(int generation)
|
||||
}
|
||||
m_currentEnemyStationEntities[1] = m_admin.spawnStation(
|
||||
anchor, esParsed.footprint, absCells, esHp, esHp, true);
|
||||
m_admin.addComponent<WeaponComponent>(m_currentEnemyStationEntities[1], esWeapon);
|
||||
{
|
||||
entt::entity wChild = m_admin.createModuleEntity();
|
||||
m_admin.addComponent<WeaponComponent>(wChild, esWeapon);
|
||||
m_admin.addComponent<ModuleOwnerComponent>(wChild,
|
||||
ModuleOwnerComponent{m_currentEnemyStationEntities[1]});
|
||||
}
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
}
|
||||
}
|
||||
@@ -407,6 +429,15 @@ void Simulation::tickDeathsAndLoot()
|
||||
m_scrapSystem->spawn(pos.value, scrap, despawnAt);
|
||||
}
|
||||
m_buildingSystem->unregisterTileOccupancy(sb.bodyCells);
|
||||
{
|
||||
std::vector<entt::entity> stationChildren;
|
||||
m_admin.forEach<ModuleOwnerComponent>(
|
||||
[&](entt::entity ce, const ModuleOwnerComponent& o)
|
||||
{
|
||||
if (o.owner == deadEntity) { stationChildren.push_back(ce); }
|
||||
});
|
||||
for (entt::entity ce : stationChildren) { m_admin.destroy(ce); }
|
||||
}
|
||||
m_admin.destroy(deadEntity);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ void WaveSystem::tickWaveScheduler(Tick currentTick, ShipSystem& ships,
|
||||
if (currentTick >= entry.spawnAt)
|
||||
{
|
||||
ships.spawn(entry.schematicId, entry.level, entry.position,
|
||||
/*isEnemy=*/true);
|
||||
/*isEnemy=*/true, entry.layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -90,8 +90,9 @@ std::vector<WaveSystem::SpawnEntry> WaveSystem::composeWave(Tick currentTick,
|
||||
// Build eligible ship list with their costs at the current level.
|
||||
struct EligibleShip
|
||||
{
|
||||
std::string schematicId;
|
||||
double cost;
|
||||
std::string schematicId;
|
||||
double cost;
|
||||
std::vector<PlacedModule> defaultModules;
|
||||
};
|
||||
std::vector<EligibleShip> eligible;
|
||||
for (const ShipDef& def : m_config.ships.ships)
|
||||
@@ -100,8 +101,9 @@ std::vector<WaveSystem::SpawnEntry> WaveSystem::composeWave(Tick currentTick,
|
||||
if (cost > 0.0)
|
||||
{
|
||||
EligibleShip es;
|
||||
es.schematicId = def.id;
|
||||
es.cost = cost;
|
||||
es.schematicId = def.id;
|
||||
es.cost = cost;
|
||||
es.defaultModules = def.defaultModules;
|
||||
eligible.push_back(es);
|
||||
}
|
||||
}
|
||||
@@ -151,11 +153,12 @@ std::vector<WaveSystem::SpawnEntry> WaveSystem::composeWave(Tick currentTick,
|
||||
budget -= chosen.cost;
|
||||
|
||||
SpawnEntry entry;
|
||||
entry.schematicId = chosen.schematicId;
|
||||
entry.level = shipLevel;
|
||||
entry.spawnAt = 0; // set below after all picks are done
|
||||
entry.position = QVector2D(xDist(m_rng),
|
||||
static_cast<float>(yDist(m_rng)) + 0.5f);
|
||||
entry.schematicId = chosen.schematicId;
|
||||
entry.level = shipLevel;
|
||||
entry.spawnAt = 0; // set below after all picks are done
|
||||
entry.position = QVector2D(xDist(m_rng),
|
||||
static_cast<float>(yDist(m_rng)) + 0.5f);
|
||||
entry.layout.placedModules = chosen.defaultModules;
|
||||
picked.push_back(entry);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <QVector2D>
|
||||
|
||||
#include "GameConfig.h"
|
||||
#include "ShipLayout.h"
|
||||
#include "Tick.h"
|
||||
|
||||
class ShipSystem;
|
||||
@@ -40,10 +41,11 @@ public:
|
||||
private:
|
||||
struct SpawnEntry
|
||||
{
|
||||
std::string schematicId;
|
||||
int level;
|
||||
Tick spawnAt;
|
||||
QVector2D position;
|
||||
std::string schematicId;
|
||||
int level;
|
||||
Tick spawnAt;
|
||||
QVector2D position;
|
||||
ShipLayoutConfig layout;
|
||||
};
|
||||
|
||||
// Compose the next wave from the current threat budget, returning timed
|
||||
|
||||
Reference in New Issue
Block a user