define ship roles via added modules and allow multiple weapons
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -55,14 +55,6 @@ struct ToastVisuals
|
||||
int fontSize;
|
||||
};
|
||||
|
||||
enum class ShipRole
|
||||
{
|
||||
PlayerCombat,
|
||||
Salvage,
|
||||
Repair,
|
||||
Enemy,
|
||||
};
|
||||
|
||||
struct VisualsConfig
|
||||
{
|
||||
TileVisuals asteroid;
|
||||
@@ -70,7 +62,7 @@ struct VisualsConfig
|
||||
|
||||
std::map<BuildingType, BuildingVisuals> buildings;
|
||||
std::map<std::string, ItemVisuals> items;
|
||||
std::map<ShipRole, ShipVisuals> ships;
|
||||
std::map<std::string, ShipVisuals> ships;
|
||||
|
||||
BeamVisuals beams;
|
||||
OverlayVisuals overlays;
|
||||
|
||||
@@ -190,17 +190,20 @@ VisualsConfig VisualsLoader::load(const std::string& path)
|
||||
}
|
||||
}
|
||||
|
||||
// Ships
|
||||
// Ships (dynamic keys: each key is a schematic id)
|
||||
{
|
||||
toml::table& ships = requireSubtable(tbl, "ships", "root");
|
||||
cfg.ships[ShipRole::PlayerCombat] = parseShip(
|
||||
requireSubtable(ships, "player_combat", "ships"), "ships.player_combat");
|
||||
cfg.ships[ShipRole::Salvage] = parseShip(
|
||||
requireSubtable(ships, "salvage", "ships"), "ships.salvage");
|
||||
cfg.ships[ShipRole::Repair] = parseShip(
|
||||
requireSubtable(ships, "repair", "ships"), "ships.repair");
|
||||
cfg.ships[ShipRole::Enemy] = parseShip(
|
||||
requireSubtable(ships, "enemy", "ships"), "ships.enemy");
|
||||
for (toml::table::iterator it = ships.begin(); it != ships.end(); ++it)
|
||||
{
|
||||
std::string schematicId = std::string(it->first.str());
|
||||
toml::table* sub = it->second.as_table();
|
||||
if (sub == nullptr)
|
||||
{
|
||||
throw std::runtime_error("visuals.toml: ships." + schematicId
|
||||
+ " is not a table");
|
||||
}
|
||||
cfg.ships[schematicId] = parseShip(*sub, "ships." + schematicId);
|
||||
}
|
||||
}
|
||||
|
||||
// Beams
|
||||
|
||||
Reference in New Issue
Block a user