use meters in config
This commit is contained in:
@@ -62,30 +62,32 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
|
||||
const double x = static_cast<double>(level);
|
||||
const float tickRate = static_cast<float>(kTickRateHz);
|
||||
const float tileSize = static_cast<float>(m_config.world.tileSize_m);
|
||||
|
||||
float hp = static_cast<float>(def->health.hpFormula.evaluate(x));
|
||||
float maxHp = hp;
|
||||
float maxSpeedPerTick = static_cast<float>(def->movement.speedFormula.evaluate(x))
|
||||
/ tickRate;
|
||||
float mainAccelPerTick = static_cast<float>(
|
||||
def->movement.mainAccelerationFormula.evaluate(x))
|
||||
/ tickRate;
|
||||
float maneuveringAccelPerTick = static_cast<float>(
|
||||
def->movement.maneuveringAccelerationFormula.evaluate(x))
|
||||
/ tickRate;
|
||||
float angularAccelPerTick = static_cast<float>(
|
||||
def->movement.angularAccelerationFormula.evaluate(x))
|
||||
/ tickRate;
|
||||
float maxRotationSpeedPerTick = static_cast<float>(
|
||||
def->movement.maxRotationSpeedFormula.evaluate(x))
|
||||
/ tickRate;
|
||||
float sensorRange = static_cast<float>(
|
||||
def->sensor.sensorRangeFormula.evaluate(x));
|
||||
float maxSpeed_tpt = static_cast<float>(def->movement.speedFormula.evaluate(x))
|
||||
/ tileSize / tickRate;
|
||||
float mainAcceleration_tptt = static_cast<float>(
|
||||
def->movement.mainAccelerationFormula.evaluate(x))
|
||||
/ tileSize / tickRate;
|
||||
float maneuveringAcceleration_tptt = static_cast<float>(
|
||||
def->movement.maneuveringAccelerationFormula.evaluate(x))
|
||||
/ tileSize / tickRate;
|
||||
float maxAngularAcceleration_rptt = static_cast<float>(
|
||||
def->movement.angularAccelerationFormula.evaluate(x))
|
||||
/ tickRate;
|
||||
float maxRotationSpeed_rpt = static_cast<float>(
|
||||
def->movement.maxRotationSpeedFormula.evaluate(x))
|
||||
/ tickRate;
|
||||
float sensorRange_tiles = static_cast<float>(
|
||||
def->sensor.sensorRangeFormula.evaluate(x))
|
||||
/ tileSize;
|
||||
|
||||
entt::entity entity = m_admin.spawnShip(
|
||||
position, hp, maxHp,
|
||||
maxSpeedPerTick, mainAccelPerTick, maneuveringAccelPerTick,
|
||||
angularAccelPerTick, maxRotationSpeedPerTick, sensorRange,
|
||||
maxSpeed_tpt, mainAcceleration_tptt, maneuveringAcceleration_tptt,
|
||||
maxAngularAcceleration_rptt, maxRotationSpeed_rpt, sensorRange_tiles,
|
||||
level, schematicId, isEnemy);
|
||||
|
||||
// Determine module list: configured layout takes precedence over default.
|
||||
@@ -109,8 +111,8 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
WeaponComponent w;
|
||||
w.damage = static_cast<float>(
|
||||
modDef->weaponCapability->damageFormula.evaluate(mx));
|
||||
w.range = static_cast<float>(
|
||||
modDef->weaponCapability->attackRangeFormula.evaluate(mx));
|
||||
w.range_tiles = static_cast<float>(
|
||||
modDef->weaponCapability->attackRangeFormula.evaluate(mx)) / tileSize;
|
||||
w.fireRateHz = static_cast<float>(
|
||||
modDef->weaponCapability->attackRateFormula.evaluate(mx));
|
||||
w.cooldownTicks = 0.0f;
|
||||
@@ -128,8 +130,8 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
cargo.capacity = static_cast<int>(
|
||||
modDef->salvageCapability->cargoCapacityFormula.evaluate(mx));
|
||||
cargo.current = 0;
|
||||
cargo.collectionRange = static_cast<float>(
|
||||
modDef->salvageCapability->collectionRangeFormula.evaluate(mx));
|
||||
cargo.collectionRange_tiles = static_cast<float>(
|
||||
modDef->salvageCapability->collectionRangeFormula.evaluate(mx)) / tileSize;
|
||||
const double rate = modDef->salvageCapability->collectionRateFormula.evaluate(mx);
|
||||
cargo.collectionIntervalTicks = (rate > 0.0)
|
||||
? static_cast<int>(kTickRateHz / rate + 0.5)
|
||||
@@ -148,8 +150,8 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
rt.ratePerTick = static_cast<float>(
|
||||
modDef->repairCapability->repairRateFormula.evaluate(mx))
|
||||
/ static_cast<float>(kTickRateHz);
|
||||
rt.range = static_cast<float>(
|
||||
modDef->repairCapability->repairRangeFormula.evaluate(mx));
|
||||
rt.range_tiles = static_cast<float>(
|
||||
modDef->repairCapability->repairRangeFormula.evaluate(mx)) / tileSize;
|
||||
rt.currentTarget = std::nullopt;
|
||||
|
||||
entt::entity child = m_admin.createModuleEntity();
|
||||
@@ -207,6 +209,26 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
}
|
||||
}
|
||||
|
||||
// Range stat additive modifiers are expressed in metres in config; convert to tiles.
|
||||
const double tileSizeD = static_cast<double>(m_config.world.tileSize_m);
|
||||
const char* const kRangeStats[] = {
|
||||
"sensor_range", "attack_range", "collection_range", "repair_range"
|
||||
};
|
||||
std::map<std::string, std::pair<double, double>>* allModMaps[] = {
|
||||
&hullMods, &weaponMods, &salvageMods, &repairMods
|
||||
};
|
||||
for (const char* stat : kRangeStats)
|
||||
{
|
||||
for (std::map<std::string, std::pair<double, double>>* mods : allModMaps)
|
||||
{
|
||||
std::map<std::string, std::pair<double, double>>::iterator it = mods->find(stat);
|
||||
if (it != mods->end())
|
||||
{
|
||||
it->second.second /= tileSizeD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: apply a modifier map to a float stat.
|
||||
auto applyMod = [](float& stat, const std::string& name,
|
||||
const std::map<std::string, std::pair<double, double>>& mods)
|
||||
@@ -226,30 +248,30 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
DynamicBodyComponent& dynamics = m_admin.get<DynamicBodyComponent>(entity);
|
||||
SensorRangeComponent& sensor = m_admin.get<SensorRangeComponent>(entity);
|
||||
|
||||
applyMod(health.maxHp, "hp", hullMods);
|
||||
applyMod(health.maxHp, "hp", hullMods);
|
||||
health.hp = health.maxHp;
|
||||
applyMod(dynamics.maxSpeedPerTick, "speed", hullMods);
|
||||
applyMod(dynamics.mainAccelerationPerTick, "main_acceleration", hullMods);
|
||||
applyMod(dynamics.maneuveringAccelerationPerTick, "maneuvering_acceleration", hullMods);
|
||||
applyMod(dynamics.angularAccelerationPerTick, "angular_acceleration", hullMods);
|
||||
applyMod(dynamics.maxRotationSpeedPerTick, "max_rotation_speed", hullMods);
|
||||
applyMod(sensor.value, "sensor_range", hullMods);
|
||||
applyMod(dynamics.maxSpeed_tpt, "speed", hullMods);
|
||||
applyMod(dynamics.mainAcceleration_tptt, "main_acceleration", hullMods);
|
||||
applyMod(dynamics.maneuveringAcceleration_tptt, "maneuvering_acceleration", hullMods);
|
||||
applyMod(dynamics.maxAngularAcceleration_rptt, "angular_acceleration", hullMods);
|
||||
applyMod(dynamics.maxRotationSpeed_rpt, "max_rotation_speed", hullMods);
|
||||
applyMod(sensor.value_tiles, "sensor_range", hullMods);
|
||||
}
|
||||
|
||||
// Apply weapon modifiers to each weapon child.
|
||||
for (entt::entity child : weaponChildren)
|
||||
{
|
||||
WeaponComponent& w = m_admin.get<WeaponComponent>(child);
|
||||
applyMod(w.damage, "damage", weaponMods);
|
||||
applyMod(w.range, "attack_range", weaponMods);
|
||||
applyMod(w.fireRateHz, "attack_rate", weaponMods);
|
||||
applyMod(w.damage, "damage", weaponMods);
|
||||
applyMod(w.range_tiles, "attack_range", weaponMods);
|
||||
applyMod(w.fireRateHz, "attack_rate", weaponMods);
|
||||
}
|
||||
|
||||
// Apply salvage modifiers to each salvage child.
|
||||
for (entt::entity child : salvageChildren)
|
||||
{
|
||||
SalvageCargoComponent& c = m_admin.get<SalvageCargoComponent>(child);
|
||||
float fRange = c.collectionRange;
|
||||
float fRange = c.collectionRange_tiles;
|
||||
float fCapacity = static_cast<float>(c.capacity);
|
||||
// Apply rate modifier: compute rate from interval, apply multiplier, convert back.
|
||||
float fRate = (c.collectionIntervalTicks > 0)
|
||||
@@ -258,7 +280,7 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
applyMod(fRange, "collection_range", salvageMods);
|
||||
applyMod(fCapacity, "cargo_capacity", salvageMods);
|
||||
applyMod(fRate, "collection_rate", salvageMods);
|
||||
c.collectionRange = fRange;
|
||||
c.collectionRange_tiles = fRange;
|
||||
c.capacity = static_cast<int>(fCapacity + 0.5f);
|
||||
c.collectionIntervalTicks = (fRate > 0.0f)
|
||||
? static_cast<int>(static_cast<float>(kTickRateHz) / fRate + 0.5f)
|
||||
@@ -269,8 +291,8 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
for (entt::entity child : repairChildren)
|
||||
{
|
||||
RepairToolComponent& rt = m_admin.get<RepairToolComponent>(child);
|
||||
applyMod(rt.ratePerTick, "repair_rate", repairMods);
|
||||
applyMod(rt.range, "repair_range", repairMods);
|
||||
applyMod(rt.ratePerTick, "repair_rate", repairMods);
|
||||
applyMod(rt.range_tiles, "repair_range", repairMods);
|
||||
}
|
||||
|
||||
// --- Pass 3: attach behavior components based on capability presence -----
|
||||
@@ -292,14 +314,14 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
float maxCollRange = 0.0f;
|
||||
for (entt::entity child : salvageChildren)
|
||||
{
|
||||
const float r = m_admin.get<SalvageCargoComponent>(child).collectionRange;
|
||||
const float r = m_admin.get<SalvageCargoComponent>(child).collectionRange_tiles;
|
||||
if (r > maxCollRange) { maxCollRange = r; }
|
||||
}
|
||||
|
||||
SalvageBehaviorComponent sb;
|
||||
sb.scrapTarget = std::nullopt;
|
||||
sb.deliveryBay = kInvalidBuildingId;
|
||||
sb.maxCollectionRange = maxCollRange;
|
||||
sb.scrapTarget = std::nullopt;
|
||||
sb.deliveryBay = kInvalidBuildingId;
|
||||
sb.maxCollectionRange_tiles = maxCollRange;
|
||||
m_admin.addComponent<SalvageBehaviorComponent>(entity, sb);
|
||||
}
|
||||
|
||||
@@ -308,13 +330,13 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
float maxRepairRange = 0.0f;
|
||||
for (entt::entity child : repairChildren)
|
||||
{
|
||||
const float r = m_admin.get<RepairToolComponent>(child).range;
|
||||
const float r = m_admin.get<RepairToolComponent>(child).range_tiles;
|
||||
if (r > maxRepairRange) { maxRepairRange = r; }
|
||||
}
|
||||
|
||||
RepairBehaviorComponent rb;
|
||||
rb.currentTarget = std::nullopt;
|
||||
rb.maxRepairRange = maxRepairRange;
|
||||
rb.currentTarget = std::nullopt;
|
||||
rb.maxRepairRange_tiles = maxRepairRange;
|
||||
m_admin.addComponent<RepairBehaviorComponent>(entity, rb);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user