define ship roles via added modules and allow multiple weapons
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "EntityAdmin.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "ModuleOwnerComponent.h"
|
||||
#include "MovementIntentSystem.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "ScrapSystem.h"
|
||||
@@ -159,7 +160,12 @@ void ArenaSimulation::placeStructures()
|
||||
}
|
||||
const entt::entity stationEntity = m_admin.spawnStation(
|
||||
anchor, parsed.footprint, absCells, hp, hp, isEnemy);
|
||||
m_admin.addComponent<WeaponComponent>(stationEntity, weapon);
|
||||
{
|
||||
entt::entity wChild = m_admin.createModuleEntity();
|
||||
m_admin.addComponent<WeaponComponent>(wChild, weapon);
|
||||
m_admin.addComponent<ModuleOwnerComponent>(wChild,
|
||||
ModuleOwnerComponent{stationEntity});
|
||||
}
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
};
|
||||
|
||||
@@ -247,6 +253,7 @@ void ArenaSimulation::tick()
|
||||
m_aiSystem->tickHomeReturnBehavior(m_admin);
|
||||
m_aiSystem->tickThreatResponseBehavior(m_admin, *m_buildingSystem);
|
||||
m_aiSystem->tickRepairBehavior(m_admin, *m_buildingSystem);
|
||||
m_aiSystem->tickRepairTools(m_admin);
|
||||
m_aiSystem->tickSalvageBehavior(m_admin, *m_scrapSystem, *m_buildingSystem);
|
||||
|
||||
// Combat resolution (tick step 8).
|
||||
@@ -320,6 +327,15 @@ void ArenaSimulation::tickDeaths()
|
||||
{
|
||||
const StationBodyComponent& sb = m_admin.get<StationBodyComponent>(deadEntity);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,23 +14,12 @@
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "RepairToolComponent.h"
|
||||
#include "SalvageCargoComponent.h"
|
||||
#include "ScrapSystem.h"
|
||||
#include "ShipIdentityComponent.h"
|
||||
#include "StationBodyComponent.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
ShipRole shipRoleFromComponents(bool isEnemy, bool hasCargo, bool hasRepairTool)
|
||||
{
|
||||
if (isEnemy) { return ShipRole::Enemy; }
|
||||
if (hasCargo) { return ShipRole::Salvage; }
|
||||
if (hasRepairTool) { return ShipRole::Repair; }
|
||||
return ShipRole::PlayerCombat;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -322,15 +311,12 @@ void ArenaView::drawShips(QPainter& painter)
|
||||
{
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, FacingComponent,
|
||||
FactionComponent>(
|
||||
[&](entt::entity e, const ShipIdentityComponent& /*si*/,
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
|
||||
const PositionComponent& pos, const FacingComponent& facing,
|
||||
const FactionComponent& fac)
|
||||
const FactionComponent& /*fac*/)
|
||||
{
|
||||
const bool hasCargo = m_sim->admin().hasAll<SalvageCargoComponent>(e);
|
||||
const bool hasRepair = m_sim->admin().hasAll<RepairToolComponent>(e);
|
||||
const ShipRole role = shipRoleFromComponents(fac.isEnemy, hasCargo, hasRepair);
|
||||
const std::map<ShipRole, ShipVisuals>::const_iterator it =
|
||||
m_visuals->ships.find(role);
|
||||
const std::map<std::string, ShipVisuals>::const_iterator it =
|
||||
m_visuals->ships.find(si.schematicId);
|
||||
if (it == m_visuals->ships.end()) { return; }
|
||||
|
||||
const QPointF center = worldToWidget(pos.value);
|
||||
|
||||
Reference in New Issue
Block a user