add collection rate for salvager modules and respect collection range of each of these modules

This commit is contained in:
2026-06-02 21:20:44 +02:00
parent 9d0a60a93b
commit f921f00a0d
8 changed files with 64 additions and 24 deletions

View File

@@ -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.