define ship roles via added modules and allow multiple weapons

This commit is contained in:
2026-06-01 22:57:53 +02:00
parent f363f7a67c
commit 9d0a60a93b
31 changed files with 873 additions and 407 deletions

View File

@@ -24,8 +24,6 @@
#include "FactionComponent.h"
#include "HealthComponent.h"
#include "PositionComponent.h"
#include "RepairToolComponent.h"
#include "SalvageCargoComponent.h"
#include "ScrapSystem.h"
#include "SensorRangeComponent.h"
#include "ShipIdentityComponent.h"
@@ -62,13 +60,6 @@ Rotation rotateCounterClockwise(Rotation r)
return Rotation::East;
}
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;
}
QString toDisplayName(const std::string& id)
{
@@ -847,15 +838,12 @@ void GameWorldView::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);
@@ -884,15 +872,12 @@ void GameWorldView::drawDebugSensorRanges(QPainter& painter)
painter.setBrush(Qt::NoBrush);
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, FacingComponent,
FactionComponent, SensorRangeComponent>(
[&](entt::entity e, const ShipIdentityComponent& /*si*/,
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
const PositionComponent& pos, const FacingComponent& /*facing*/,
const FactionComponent& fac, const SensorRangeComponent& sensor)
const FactionComponent& /*fac*/, const SensorRangeComponent& sensor)
{
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);