add collection rate for salvager modules and respect collection range of each of these modules
This commit is contained in:
@@ -530,6 +530,7 @@ static const StatEntry kKnownStats[] = {
|
||||
{"weapon", "attack_rate"},
|
||||
{"salvage", "collection_range"},
|
||||
{"salvage", "cargo_capacity"},
|
||||
{"salvage", "collection_rate"},
|
||||
{"repair", "repair_rate"},
|
||||
{"repair", "repair_range"},
|
||||
};
|
||||
@@ -636,13 +637,16 @@ ModulesConfig ConfigLoader::loadModules(const std::string& path)
|
||||
const std::string sPath = elemPath + ".salvage";
|
||||
const toml::table& sTable = requireTable(mt["salvage"], file, sPath);
|
||||
toml::table& sMt = const_cast<toml::table&>(sTable);
|
||||
if (sMt.contains("collection_range_formula") || sMt.contains("cargo_capacity_formula"))
|
||||
if (sMt.contains("collection_range_formula") || sMt.contains("cargo_capacity_formula")
|
||||
|| sMt.contains("collection_rate_formula"))
|
||||
{
|
||||
ModuleSalvageCapability cap;
|
||||
cap.collectionRangeFormula = requireFormula(sMt["collection_range_formula"],
|
||||
file, sPath + ".collection_range_formula");
|
||||
cap.cargoCapacityFormula = requireFormula(sMt["cargo_capacity_formula"],
|
||||
file, sPath + ".cargo_capacity_formula");
|
||||
cap.collectionRateFormula = requireFormula(sMt["collection_rate_formula"],
|
||||
file, sPath + ".collection_rate_formula");
|
||||
def.salvageCapability = std::move(cap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ struct ModuleSalvageCapability
|
||||
{
|
||||
Formula collectionRangeFormula;
|
||||
Formula cargoCapacityFormula;
|
||||
Formula collectionRateFormula;
|
||||
};
|
||||
|
||||
struct ModuleRepairCapability
|
||||
|
||||
@@ -5,4 +5,6 @@ struct SalvageCargoComponent
|
||||
int capacity;
|
||||
int current;
|
||||
float collectionRange;
|
||||
int collectionIntervalTicks;
|
||||
int cooldownTicksRemaining;
|
||||
};
|
||||
|
||||
@@ -379,6 +379,13 @@ void AiSystem::tickSalvageBehavior(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
|
||||
const std::vector<ScrapInfo> allScrap = scraps.allScrapInfo();
|
||||
|
||||
// Tick down per-module collection cooldowns.
|
||||
admin.forEach<SalvageCargoComponent>(
|
||||
[](entt::entity /*e*/, SalvageCargoComponent& c)
|
||||
{
|
||||
if (c.cooldownTicksRemaining > 0) { --c.cooldownTicksRemaining; }
|
||||
});
|
||||
|
||||
admin.forEach<SalvageBehaviorComponent, PositionComponent,
|
||||
SensorRangeComponent, MovementIntentComponent>(
|
||||
[&](entt::entity e, SalvageBehaviorComponent& salvageBehavior,
|
||||
@@ -461,26 +468,32 @@ void AiSystem::tickSalvageBehavior(EntityAdmin& admin, ScrapSystem& scraps,
|
||||
}
|
||||
if (retreating) { return; }
|
||||
|
||||
// Collect nearby scrap — increment first non-full salvage child.
|
||||
for (const ScrapInfo& si : allScrap)
|
||||
{
|
||||
if ((si.position - pos.value).length() <= collectRange)
|
||||
// Per-module independent collection: each ready module collects one scrap.
|
||||
bool anythingCollected = false;
|
||||
admin.forEach<SalvageCargoComponent, ModuleOwnerComponent>(
|
||||
[&](entt::entity /*ce*/, SalvageCargoComponent& c,
|
||||
const ModuleOwnerComponent& o)
|
||||
{
|
||||
bool collected = false;
|
||||
admin.forEach<SalvageCargoComponent, ModuleOwnerComponent>(
|
||||
[&](entt::entity /*ce*/, SalvageCargoComponent& c,
|
||||
const ModuleOwnerComponent& o)
|
||||
if (o.owner != e || c.current >= c.capacity
|
||||
|| c.cooldownTicksRemaining > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (const ScrapInfo& si : allScrap)
|
||||
{
|
||||
if ((si.position - pos.value).length() > c.collectionRange) { continue; }
|
||||
if (scraps.consume(si.entity))
|
||||
{
|
||||
if (collected || o.owner != e || c.current >= c.capacity) { return; }
|
||||
if (scraps.consume(si.entity))
|
||||
{
|
||||
++c.current;
|
||||
salvageBehavior.scrapTarget = std::nullopt;
|
||||
collected = true;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
++c.current;
|
||||
c.cooldownTicksRemaining = c.collectionIntervalTicks;
|
||||
anythingCollected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (anythingCollected)
|
||||
{
|
||||
salvageBehavior.scrapTarget = std::nullopt;
|
||||
}
|
||||
|
||||
// Move toward scrap target or find a new one.
|
||||
|
||||
@@ -129,6 +129,11 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
cargo.current = 0;
|
||||
cargo.collectionRange = static_cast<float>(
|
||||
modDef->salvageCapability->collectionRangeFormula.evaluate(mx));
|
||||
const double rate = modDef->salvageCapability->collectionRateFormula.evaluate(mx);
|
||||
cargo.collectionIntervalTicks = (rate > 0.0)
|
||||
? static_cast<int>(kTickRateHz / rate + 0.5)
|
||||
: 0;
|
||||
cargo.cooldownTicksRemaining = 0;
|
||||
|
||||
entt::entity child = m_admin.createModuleEntity();
|
||||
m_admin.addComponent<SalvageCargoComponent>(child, cargo);
|
||||
@@ -245,10 +250,18 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
|
||||
SalvageCargoComponent& c = m_admin.get<SalvageCargoComponent>(child);
|
||||
float fRange = c.collectionRange;
|
||||
float fCapacity = static_cast<float>(c.capacity);
|
||||
// Apply rate modifier: compute rate from interval, apply multiplier, convert back.
|
||||
float fRate = (c.collectionIntervalTicks > 0)
|
||||
? static_cast<float>(kTickRateHz) / static_cast<float>(c.collectionIntervalTicks)
|
||||
: 0.0f;
|
||||
applyMod(fRange, "collection_range", salvageMods);
|
||||
applyMod(fCapacity, "cargo_capacity", salvageMods);
|
||||
c.collectionRange = fRange;
|
||||
c.capacity = static_cast<int>(fCapacity);
|
||||
applyMod(fRate, "collection_rate", salvageMods);
|
||||
c.collectionRange = fRange;
|
||||
c.capacity = static_cast<int>(fCapacity + 0.5f);
|
||||
c.collectionIntervalTicks = (fRate > 0.0f)
|
||||
? static_cast<int>(static_cast<float>(kTickRateHz) / fRate + 0.5f)
|
||||
: 0;
|
||||
}
|
||||
|
||||
// Apply repair modifiers to each repair child.
|
||||
|
||||
Reference in New Issue
Block a user