make ships orbit their targets

This commit is contained in:
2026-06-15 21:09:40 +02:00
parent 6b7c3df64a
commit 4153b7e2f5
17 changed files with 209 additions and 20 deletions

View File

@@ -343,12 +343,24 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
if (!weaponChildren.empty())
{
m_admin.addComponent<AttackBehavior>(entity, AttackBehavior{});
float maxWeaponRange = 0.0f;
for (entt::entity child : weaponChildren)
{
const float r = m_admin.get<WeaponComponent>(child).range_tiles;
if (r > maxWeaponRange) { maxWeaponRange = r; }
}
AttackBehavior attack;
attack.orbitRadius_tiles =
maxWeaponRange * static_cast<float>(m_config.world.orbitFactor);
m_admin.addComponent<AttackBehavior>(entity, attack);
if (!isEnemy)
{
RallyBehavior rally;
rally.rallyPoint = m_rallyPoint;
rally.rallyPoint = m_rallyPoint;
rally.orbitRadius_tiles =
static_cast<float>(m_config.world.rallyOrbitRadius_tiles);
m_admin.addComponent<RallyBehavior>(entity, rally);
}
}
@@ -365,6 +377,8 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
SalvageScrapBehavior salvage;
salvage.scrapTarget = std::nullopt;
salvage.maxCollectionRange_tiles = maxCollRange;
salvage.orbitRadius_tiles =
maxCollRange * static_cast<float>(m_config.world.orbitFactor);
m_admin.addComponent<SalvageScrapBehavior>(entity, salvage);
DeliverScrapBehavior deliver;
@@ -384,6 +398,8 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
RepairBehavior repair;
repair.currentTarget = std::nullopt;
repair.maxRepairRange_tiles = maxRepairRange;
repair.orbitRadius_tiles =
maxRepairRange * static_cast<float>(m_config.world.orbitFactor);
m_admin.addComponent<RepairBehavior>(entity, repair);
}