From c217861ab62987b798835194786dc99424e1804e Mon Sep 17 00:00:00 2001 From: "Emil A. Overbeck" Date: Sun, 19 Jul 2026 03:14:53 +0200 Subject: Recoil and armor --- src/game/build_graph.cpp | 15 +++++++++++++++ src/game/build_graph.hpp | 9 +++++++++ src/game/data.cpp | 4 ++++ src/game/data.hpp | 2 ++ 4 files changed, 30 insertions(+) (limited to 'src/game') diff --git a/src/game/build_graph.cpp b/src/game/build_graph.cpp index 032bbf5..a1195af 100644 --- a/src/game/build_graph.cpp +++ b/src/game/build_graph.cpp @@ -291,6 +291,21 @@ int BuildGraph::kill_grounded() { // Destruction // ============================================================================= +void BuildGraph::apply_recoil(float x, float y, float radius, + float dx, float dy, float strength) { + if (radius <= 0.0f || strength <= 0.0f) return; + + for (auto& n : nodes) { + if (n.is_foundation) continue; // pinned: the ground eats the recoil + float ox = n.x - x, oy = n.y - y; + float d = std::sqrt(ox*ox + oy*oy); + if (d >= radius) continue; + float f = 1.0f - d / radius; // linear falloff, as in apply_splash + n.vx += dx * strength * f; + n.vy += dy * strength * f; + } +} + void BuildGraph::apply_splash(float x, float y, float radius, float damage, float knockback) { if (radius <= 0.0f) return; diff --git a/src/game/build_graph.hpp b/src/game/build_graph.hpp index bf83a18..4452139 100644 --- a/src/game/build_graph.hpp +++ b/src/game/build_graph.hpp @@ -34,6 +34,8 @@ struct MaterialDef { bool blocks_projectiles; // stops cannon shells (wood yes; bg-brace/rope no) bool blocks_beam; // stops laser beams (all yes in Forts) float half_width; // visual thickness + float cost_metal; // metal spent placing one strut of this material + float cost_energy; // energy spent placing one strut of this material float r, g, b, a; // visual colour (also tints the texture) std::string name; std::string texture; // CC0 placeholder path ("" = flat colour) @@ -104,6 +106,13 @@ public: // not block splash (pure radius falloff, like Forts AoE). void apply_splash(float x, float y, float radius, float damage, float knockback); + // Directional velocity kick to free nodes within `radius` of (x,y), along the + // unit vector (dx,dy), with linear falloff. Weapon recoil uses this to shove + // the FIRING structure back (Forts' Recoil), unlike apply_splash's radial + // knockback on the target. No damage: recoil only moves the fort. + void apply_recoil(float x, float y, float radius, + float dx, float dy, float strength); + // Trace a laser beam from (ox,oy) along (dx,dy) up to `range`: damage + // optionally ignite EVERY strut it crosses, passing through beam-transparent // materials (bg-brace, ropes) and STOPPING at the first blocking one (wood). diff --git a/src/game/data.cpp b/src/game/data.cpp index 654cac6..3d9f6c0 100644 --- a/src/game/data.cpp +++ b/src/game/data.cpp @@ -36,6 +36,9 @@ MaterialDef read_material(const sol::table& m) { d.blocks_beam = m.get_or("blocks_beam", true); d.tension_only = m.get_or("tension_only", false); d.half_width = m.get_or("half_width", 0.15f); + // Defaults match the flat costs struts used before they became per-material. + d.cost_metal = m.get_or("cost_metal", 5.0f); + d.cost_energy = m.get_or("cost_energy", 25.0f); d.texture = m.get_or("texture", std::string("")); d.texture_forts = m.get_or("texture_forts", std::string("")); @@ -137,6 +140,7 @@ WeaponDef read_weapon(const sol::table& w) { d.beam_dps = w.get_or("beam_dps", 120.0f); d.beam_duration = w.get_or("beam_duration", 1.5f); d.energy_cost = w.get_or("energy_cost", 0.0f); + d.recoil = w.get_or("recoil", 0.0f); d.texture = w.get_or("texture", std::string("")); d.projectile_texture = w.get_or("projectile_texture", std::string("")); d.texture_forts = w.get_or("texture_forts", std::string("")); diff --git a/src/game/data.hpp b/src/game/data.hpp index fdf9e08..9b9aec1 100644 --- a/src/game/data.hpp +++ b/src/game/data.hpp @@ -24,6 +24,8 @@ struct WeaponDef { float beam_dps; // HP damage per second to the struck strut float beam_duration; // seconds the beam stays on float energy_cost; // energy spent per shot (Forts EnergyFireCost) + float recoil; // velocity kick shoved back into the FIRING + // structure on each shot (Forts Recoil); 0 = none std::string texture; // turret/base sprite (CC0 placeholder) std::string projectile_texture; // shell sprite (CC0 placeholder) std::string texture_forts; // preferred BYO Forts turret art -- cgit v1.3