From cd0c08dc7ce754473178ad3f32f7740a1dddc1eb Mon Sep 17 00:00:00 2001 From: Vaino Kauppila Date: Thu, 2 Jul 2026 22:58:25 +0300 Subject: Initial import: LibreForts (M0-M5 in progress) Open-source Forts clone: custom C++20 engine + data-driven (Lua) 2D physics artillery RTS. - Building: node/strut graph on a stiff mass-spring solver (canon Forts model), triangulation rigidity, axial + 30-degree angle-stress breaking, cascading collapse, fire (DoT + spread), ground destroys debris. - Weapons (M4): cannon (ballistic) + laser (beam/ignite) with select-and-aim-in- arc UX; splash / beam damage; bg-brace passthrough. - Devices + economy (M5): reactors + win/loss + restart, mines/turbines/battery, metal deposits, storage caps, per-shot energy cost. - Data-driven via Lua/sol2 with a layered mod loader; enemy-fort scenario mod. - Renderer: SDL3 + textures + ImGui dev UI. stb_image + ImGui vendored. - Assets: CC0 placeholders only; real game art loaded at runtime from the user's own install via forts: paths (bring-your-own; nothing copyrighted committed). See README.md / CLAUDE.md and research/ + requirements/ for detail. --- src/game/data.hpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/game/data.hpp (limited to 'src/game/data.hpp') diff --git a/src/game/data.hpp b/src/game/data.hpp new file mode 100644 index 0000000..3a7f912 --- /dev/null +++ b/src/game/data.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include "game/build_graph.hpp" // MaterialDef +#include +#include + +class ScriptEngine; + +// A weapon definition, loaded from Lua (data/weapons.lua). Values are in our +// world units (scaled from the Forts data). +struct WeaponDef { + std::string name; + float muzzle_speed; // launch speed (units/s) + float reload; // seconds between shots + float splash_damage; // damage at blast centre + float splash_radius; // blast radius (units) + float knockback; // impulse applied to nearby nodes + float projectile_radius; // collision radius of the shell + float fire_chance; // 0..1 chance to ignite on impact (M4 fire) + float min_fire_angle; // firing-arc lower bound, radians rel. to mount + float max_fire_angle; // firing-arc upper bound, radians rel. to mount + bool is_beam; // laser (hitscan beam) vs ballistic shell + float beam_range; // max beam length (units) + 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) + std::string texture; // turret/base sprite + std::string projectile_texture; // shell sprite +}; + +// Loads the material table from /materials.lua, then applies every +// mod under /mods// (each may define mod.lua with a Priority and +// a materials.lua that mutates the base table) in (priority, name) order. +// Returns the final material list. Empty on failure. +std::vector load_materials(ScriptEngine& script, + const std::string& data_dir); + +// Loads weapons from /weapons.lua (+ mod overrides), same layering. +std::vector load_weapons(ScriptEngine& script, + const std::string& data_dir); + +// Loads prebuilt structures from /structures.lua (+ mods) and builds +// them into `graph`. Each structure is a list of beams {x1,y1,x2,y2,material}. +// Used for scenario forts (e.g. the enemy target). Requires graph.materials set. +void load_structures(ScriptEngine& script, const std::string& data_dir, + BuildGraph& graph); + +// A device type (reactor / mine / turbine / battery / ...), from data/devices.lua. +struct DeviceDef { + std::string name; + float hp; + float energy_rate, metal_rate; // resources produced per second (mine e<0) + float energy_storage, metal_storage;// added to the resource caps + bool needs_deposit; // mine: only produces on a metal deposit + bool wind; // turbine: energy scales with height + float wind_max_rate, wind_max_height; + bool is_core; // reactor: destroying it decides the game + float half_w, half_h; + float cost_metal, cost_energy; // build cost + std::string texture; + float r, g, b; // fallback colour when no texture +}; + +// Scenario map: metal deposits + pre-placed devices (player reactor, enemy +// reactor, starter generators), from data/map.lua (+ mods). +struct PlacedDevice { std::string type; float x, y; int team; }; +struct MapData { + std::vector> deposits; + std::vector devices; +}; + +std::vector load_devices(ScriptEngine& script, const std::string& data_dir); +MapData load_map(ScriptEngine& script, const std::string& data_dir); -- cgit v1.3