diff --git a/scripts/science_db.lua b/scripts/science_db.lua index 67f16c3328..e84fddb2f2 100644 --- a/scripts/science_db.lua +++ b/scripts/science_db.lua @@ -230,7 +230,7 @@ item:addKeyValue(_('Sizes'), _('Small (S) / Medium (M) / Large (L)')) populateMissileStats(item, missile_stat_keys, hvli_stats) item:setLongDescription(_([[A high-velocity lead impactor (HVLI) fires a simple slug of lead at a high velocity. This weapon is usually found in simpler ships since it does not require guidance computers. This also means its projectiles fly in a straight line from its tube and can't pursue a target. -Each shot from an HVLI fires a burst of 5 projectiles, which increases the chance to hit but requires precision aiming to be effective. It reaches its full damage potential at a range of 2u.]])) +Each shot from an HVLI fires a burst of 5 projectiles, which increases the chance to hit but requires precision aiming to be effective. It reaches its full damage potential at a range of 1u.]])) local function angleDifference(angle_a, angle_b) local ret = (angle_b or 0) - (angle_a or 0) diff --git a/src/components/lifetime.h b/src/components/lifetime.h index d054f38158..fbeaafe8ac 100644 --- a/src/components/lifetime.h +++ b/src/components/lifetime.h @@ -6,5 +6,6 @@ class LifeTime { public: float lifetime = 1.0; + float initial_lifetime = 1.0; sp::script::Callback on_expire; }; diff --git a/src/components/missile.h b/src/components/missile.h index 891639e0cd..45495f4571 100644 --- a/src/components/missile.h +++ b/src/components/missile.h @@ -31,6 +31,7 @@ class ExplodeOnTouch sp::ecs::Entity owner; DamageType damage_type = DamageType::Kinetic; string explosion_sfx; + float full_damage_after = 0.0f; }; class ExplodeOnTimeout { diff --git a/src/script/components.cpp b/src/script/components.cpp index c11385cfec..b0d2e4d6dd 100644 --- a/src/script/components.cpp +++ b/src/script/components.cpp @@ -310,6 +310,7 @@ void initComponentScriptBindings() BIND_MEMBER(ExplodeOnTouch, owner); BIND_MEMBER(ExplodeOnTouch, damage_type); BIND_MEMBER(ExplodeOnTouch, explosion_sfx); + BIND_MEMBER(ExplodeOnTouch, full_damage_after); sp::script::ComponentHandler::name("delayed_explode_on_touch"); BIND_MEMBER(DelayedExplodeOnTouch, delay); @@ -666,6 +667,7 @@ void initComponentScriptBindings() BIND_MEMBER(MoveTo, on_arrival); sp::script::ComponentHandler::name("lifetime"); BIND_MEMBER(LifeTime, lifetime); + BIND_MEMBER(LifeTime, initial_lifetime); BIND_MEMBER(LifeTime, on_expire); sp::script::ComponentHandler::name("faction"); diff --git a/src/systems/missilesystem.cpp b/src/systems/missilesystem.cpp index fe66aaf61c..86d706d43c 100644 --- a/src/systems/missilesystem.cpp +++ b/src/systems/missilesystem.cpp @@ -166,7 +166,17 @@ void MissileSystem::explode(sp::ecs::Entity source, sp::ecs::Entity target, Expl if (eot.blast_range > 100.0f || !target) { DamageSystem::damageArea(transform->getPosition(), eot.blast_range, eot.damage_at_edge, eot.damage_at_center, info, eot.blast_range / 2); } else { - DamageSystem::applyDamage(target, eot.damage_at_center, info); + if (eot.full_damage_after > 0.0f){ + auto lifetime = source.getComponent(); + float alive_for = lifetime->initial_lifetime - lifetime->lifetime; + if (alive_for > eot.full_damage_after){ + DamageSystem::applyDamage(target, eot.damage_at_center, info); + } else { + DamageSystem::applyDamage(target, eot.damage_at_center * (alive_for / eot.full_damage_after), info); + } + } else { + DamageSystem::applyDamage(target, eot.damage_at_center, info); + } } auto e = sp::ecs::Entity::create(); @@ -292,6 +302,7 @@ void MissileSystem::spawnProjectile(sp::ecs::Entity source, MissileTubes::MountP mc.damage_at_edge = 10.0f * category_modifier; mc.blast_range = 20.0f * category_modifier; mc.explosion_sfx = "sfx/explosion.wav"; + mc.full_damage_after = 1000.0f / (mwd.speed / category_modifier); // Full damage after 1U missile.addComponent(0.1f, 0.0f, 0.0f); } break; @@ -349,8 +360,11 @@ void MissileSystem::spawnProjectile(sp::ecs::Entity source, MissileTubes::MountP cpe.life_time = 10.0f; } - if (tube.type_loaded != MW_Mine) - missile.addComponent().lifetime = mwd.lifetime * category_modifier; + if (tube.type_loaded != MW_Mine){ + auto& lifetime = missile.addComponent(); + lifetime.lifetime = mwd.lifetime * category_modifier; + lifetime.initial_lifetime = mwd.lifetime * category_modifier; + } if (tube.type_loaded != MW_Mine) { auto& dbad = missile.addComponent();