Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ set(MAIN_SOURCES
src/systems/maneuvering.cpp
src/systems/beamweapon.h
src/systems/beamweapon.cpp
src/systems/lifetimesystem.h
src/systems/lifetimesystem.cpp
src/systems/missilesystem.h
src/systems/missilesystem.cpp
src/systems/warpsystem.h
Expand Down
6 changes: 3 additions & 3 deletions scripts/api/entity/scanprobe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function ScanProbe()
local e = createEntity()
e.components = {
transform = {},
lifetime = {lifetime=60*10},
lifetime = {maximum=60*10},
radar_trace = {
icon="radar/probe.png",
min_size=10.0,
Expand Down Expand Up @@ -54,13 +54,13 @@ end
--- Defaults to 600 seconds (10 minutes).
--- Example: probe:setLifetime(60 * 5) -- sets the lifetime to 5 minutes
function Entity:setLifetime(lifetime)
if self.components.lifetime then self.components.lifetime.lifetime = lifetime end
if self.components.lifetime then self.components.lifetime.maximum = lifetime end
return self
end
--- Returns this ScanProbe's remaining lifetime.
--- Example: probe:getLifetime()
function Entity:getLifetime()
if self.components.lifetime then return self.components.lifetime.lifetime end
if self.components.lifetime then return self.components.lifetime.maximum - self.components.alive_for end
return 0.0
end
--- Sets this ScanProbe's owner entity.
Expand Down
4 changes: 2 additions & 2 deletions scripts/api/gm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ end
function __exportScanProbe(entity)
local extras = __exportBasics(entity)
local lt = entity.components.lifetime
if lt and lt.lifetime then
extras = extras .. string.format(":setLifetime(%.0f)", lt.lifetime)
if lt and lt.maximum then
extras = extras .. string.format(":setLifetime(%.0f)", lt.maximum)
end
local mt = entity.components.move_to
if mt and mt.speed then
Expand Down
2 changes: 1 addition & 1 deletion scripts/science_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/components/lifetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class LifeTime
{
public:
float lifetime = 1.0;
float maximum = 1.0;
float alive_for = 0.0;
sp::script::Callback on_expire;
};
1 change: 1 addition & 0 deletions src/components/missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions src/init/ecs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "systems/shieldsystem.h"
#include "systems/shipsystemssystem.h"
#include "systems/coolantsystem.h"
#include "systems/lifetimesystem.h"
#include "systems/missilesystem.h"
#include "systems/maneuvering.h"
#include "systems/energysystem.h"
Expand Down Expand Up @@ -145,6 +146,7 @@ void initSystemsAndComponents()
engine->registerSystem<ManeuveringSystem>();
engine->registerSystem<WarpSystem>();
engine->registerSystem<BeamWeaponSystem>();
engine->registerSystem<LifeTimeSystem>();
engine->registerSystem<MissileSystem>();
engine->registerSystem<ShieldSystem>();
engine->registerSystem<CoolantSystem>();
Expand Down
4 changes: 3 additions & 1 deletion src/script/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DelayedExplodeOnTouch>::name("delayed_explode_on_touch");
BIND_MEMBER(DelayedExplodeOnTouch, delay);
Expand Down Expand Up @@ -669,7 +670,8 @@ void initComponentScriptBindings()
BIND_MEMBER(MoveTo, target);
BIND_MEMBER(MoveTo, on_arrival);
sp::script::ComponentHandler<LifeTime>::name("lifetime");
BIND_MEMBER(LifeTime, lifetime);
BIND_MEMBER(LifeTime, maximum);
BIND_MEMBER(LifeTime, alive_for);
BIND_MEMBER(LifeTime, on_expire);

sp::script::ComponentHandler<Faction>::name("faction");
Expand Down
28 changes: 28 additions & 0 deletions src/systems/lifetimesystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "systems/lifetimesystem.h"


#include "components/missile.h"
#include "components/lifetime.h"
#include "ecs/query.h"
#include "multiplayer_server.h"
#include "systems/missilesystem.h"

void LifeTimeSystem::update(float delta)
{
if (game_server) {
// TODO: Not really part of missile

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment can now be removed :) glad you cleaned up my messy bit.

for(auto [entity, lifetime] : sp::ecs::Query<LifeTime>()) {
lifetime.alive_for += delta;
if (lifetime.alive_for >= lifetime.maximum) {
if (entity.hasComponent<ExplodeOnTimeout>() and entity.hasComponent<MissileSystem>()) {
if (auto eot = entity.getComponent<ExplodeOnTouch>()) {
if (auto missilesystem = entity.getComponent<MissileSystem>()){
missilesystem->explode(entity, {}, *eot);
}
}
}
entity.destroy();
}
}
}
}
9 changes: 9 additions & 0 deletions src/systems/lifetimesystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "ecs/system.h"

class LifeTimeSystem: public sp::ecs::System
{
public:
void update(float delta) override;
};
33 changes: 15 additions & 18 deletions src/systems/missilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,6 @@ void MissileSystem::update(float delta)
explode(entity, {}, deot);
}
}

if (game_server) {
// TODO: Not really part of missile
for(auto [entity, lifetime] : sp::ecs::Query<LifeTime>()) {
lifetime.lifetime -= delta;
if (lifetime.lifetime <= 0.0f) {
if (entity.hasComponent<ExplodeOnTimeout>()) {
if (auto eot = entity.getComponent<ExplodeOnTouch>()) {
explode(entity, {}, *eot);
}
}
entity.destroy();
}
}
}
}

void MissileSystem::collision(sp::ecs::Entity a, sp::ecs::Entity b, float force)
Expand Down Expand Up @@ -166,7 +151,16 @@ 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<LifeTime>();
if (lifetime->alive_for > eot.full_damage_after){
DamageSystem::applyDamage(target, eot.damage_at_center, info);
} else {
DamageSystem::applyDamage(target, eot.damage_at_center * (lifetime->alive_for / eot.full_damage_after), info);
}
} else {
DamageSystem::applyDamage(target, eot.damage_at_center, info);
}
}

auto e = sp::ecs::Entity::create();
Expand Down Expand Up @@ -293,6 +287,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<RawRadarSignatureInfo>(0.1f, 0.0f, 0.0f);
}
break;
Expand Down Expand Up @@ -350,8 +345,10 @@ void MissileSystem::spawnProjectile(sp::ecs::Entity source, MissileTubes::MountP
cpe.life_time = 10.0f;
}

if (tube.type_loaded != MW_Mine)
missile.addComponent<LifeTime>().lifetime = mwd.lifetime * category_modifier;
if (tube.type_loaded != MW_Mine){
auto& lifetime = missile.addComponent<LifeTime>();
lifetime.maximum = mwd.lifetime * category_modifier;
}

if (tube.type_loaded != MW_Mine) {
auto& dbad = missile.addComponent<DestroyedByAreaDamage>();
Expand Down
2 changes: 1 addition & 1 deletion src/systems/missilesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class MissileSystem
static void startUnload(sp::ecs::Entity source, MissileTubes::MountPoint& tube);
static void fire(sp::ecs::Entity source, MissileTubes::MountPoint& tube, float target_angle, sp::ecs::Entity target);
static float calculateFiringSolution(sp::ecs::Entity source, const MissileTubes::MountPoint& tube, sp::ecs::Entity target);
static void explode(sp::ecs::Entity source, sp::ecs::Entity target, ExplodeOnTouch& eot);

private:
static void explode(sp::ecs::Entity source, sp::ecs::Entity target, ExplodeOnTouch& eot);
static void spawnProjectile(sp::ecs::Entity source, MissileTubes::MountPoint& tube, float angle, sp::ecs::Entity target);
};
2 changes: 1 addition & 1 deletion src/systems/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sp::ecs::Entity ProbeSystem::launch(sp::ecs::Entity ship, glm::vec2 target)
auto probe = sp::ecs::Entity::create();
probe.addComponent<sp::Transform>(*ship_transform);
probe.addComponent<CallSign>().callsign = probe.toString().split(":", 1)[0] + "P";
probe.addComponent<LifeTime>().lifetime = 600.0f; // 600 sec., 10 min.
probe.addComponent<LifeTime>().maximum = 600.0f; // 600 sec., 10 min.
auto& hull = probe.addComponent<Hull>();
hull.current = hull.max = 1;

Expand Down
Loading