aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEmil A. Overbeck <emil.a.overbeck@gmail.com>2026-07-18 02:40:25 +0200
committerEmil A. Overbeck <emil.a.overbeck@gmail.com>2026-07-18 02:40:25 +0200
commit0807c89343480b15c7b63a0e864782179eb28ef5 (patch)
tree0da6e1a5600997faf240025fa3dcaaa223a87ae8 /src
parent0837872bed3d97d3433d7e0cbafffa7f271ebee1 (diff)
downloadforts_clone-0807c89343480b15c7b63a0e864782179eb28ef5.tar.gz
forts_clone-0807c89343480b15c7b63a0e864782179eb28ef5.zip
More Forts assets
Diffstat (limited to 'src')
-rw-r--r--src/engine/app.cpp32
-rw-r--r--src/engine/renderer.cpp8
-rw-r--r--src/engine/renderer.hpp7
-rw-r--r--src/game/build_graph.hpp4
-rw-r--r--src/game/data.cpp4
-rw-r--r--src/game/data.hpp9
6 files changed, 50 insertions, 14 deletions
diff --git a/src/engine/app.cpp b/src/engine/app.cpp
index 64b9f01..d5001c1 100644
--- a/src/engine/app.cpp
+++ b/src/engine/app.cpp
@@ -89,12 +89,14 @@ void App::run() {
// above is sky. Anything that falls into the ground is destroyed.
graph.ground_level = 1.0f;
- // Resolve each material's texture once (nullptr = draw flat colour).
+ // Resolve each material's texture once: prefer BYO Forts art, fall back to
+ // the CC0 placeholder, then to a flat colour (nullptr).
std::vector<SDL_Texture*> mat_tex(graph.materials.size(), nullptr);
for (size_t i = 0; i < graph.materials.size(); i++)
- if (!graph.materials[i].texture.empty())
- mat_tex[i] = renderer.load_texture(graph.materials[i].texture);
- SDL_Texture* ground_tex = renderer.load_texture("data/textures/ground.png");
+ mat_tex[i] = renderer.load_texture_or(graph.materials[i].texture_forts,
+ graph.materials[i].texture);
+ SDL_Texture* ground_tex = renderer.load_texture_or(
+ "forts:environment/midwest/ground/ground1.tga", "data/textures/ground.png");
// Short-lived explosion puffs spawned when debris hits the ground.
struct Explosion { float x, y, life; };
@@ -108,8 +110,16 @@ void App::run() {
if (weapons[i].name == "cannon") cannon_type = (int)i;
if (weapons[i].name == "laser") laser_type = (int)i;
}
- SDL_Texture* turret_tex = renderer.load_texture("data/textures/weapon_turret.png");
- SDL_Texture* shell_tex = renderer.load_texture("data/textures/projectile_laser.png");
+ // Per-weapon turret sprite (BYO Forts art, else CC0 placeholder).
+ std::vector<SDL_Texture*> weapon_tex(weapons.size(), nullptr);
+ for (size_t i = 0; i < weapons.size(); i++)
+ weapon_tex[i] = renderer.load_texture_or(weapons[i].texture_forts,
+ weapons[i].texture);
+ SDL_Texture* shell_tex = nullptr;
+ if (!weapons.empty())
+ shell_tex = renderer.load_texture_or(
+ weapons[cannon_type].projectile_texture_forts,
+ weapons[cannon_type].projectile_texture);
struct Cannon { float x, y, mount, aim, cooldown; int type; };
std::vector<Cannon> cannons;
@@ -127,8 +137,8 @@ void App::run() {
MapData map = load_map(script, "data");
std::vector<SDL_Texture*> dev_tex(device_defs.size(), nullptr);
for (size_t i = 0; i < device_defs.size(); i++)
- if (!device_defs[i].texture.empty())
- dev_tex[i] = renderer.load_texture(device_defs[i].texture);
+ dev_tex[i] = renderer.load_texture_or(device_defs[i].texture_forts,
+ device_defs[i].texture);
SDL_Texture* deposit_tex = renderer.load_texture("data/textures/deposit.png");
struct Device { int def, team; float x, y, hp, max_hp; bool on_deposit; };
@@ -673,8 +683,10 @@ void App::run() {
float bx = c.x + std::cos(c.aim) * bl * 0.5f;
float by = c.y + std::sin(c.aim) * bl * 0.5f;
renderer.draw_box(bx, by, bl * 0.5f, 0.12f, c.aim, 0.30f, 0.30f, 0.34f, 1.0f);
- if (turret_tex) renderer.draw_sprite(c.x, c.y, 0.5f, 0.5f, 0.0f, turret_tex);
- else renderer.draw_box(c.x, c.y, 0.5f, 0.5f, 0.0f, 0.4f, 0.4f, 0.45f, 1.0f);
+ SDL_Texture* wt = (c.type >= 0 && c.type < (int)weapon_tex.size())
+ ? weapon_tex[c.type] : nullptr;
+ if (wt) renderer.draw_sprite(c.x, c.y, 0.5f, 0.5f, 0.0f, wt);
+ else renderer.draw_box(c.x, c.y, 0.5f, 0.5f, 0.0f, 0.4f, 0.4f, 0.45f, 1.0f);
}
// Firing arc of the selected cannon (the cone of allowed directions).
diff --git a/src/engine/renderer.cpp b/src/engine/renderer.cpp
index 0ec6371..bc9bbf7 100644
--- a/src/engine/renderer.cpp
+++ b/src/engine/renderer.cpp
@@ -192,6 +192,14 @@ SDL_Texture* Renderer::load_texture(const std::string& path) {
return tex;
}
+SDL_Texture* Renderer::load_texture_or(const std::string& primary,
+ const std::string& fallback) {
+ if (!primary.empty()) {
+ if (SDL_Texture* t = load_texture(primary)) return t;
+ }
+ return fallback.empty() ? nullptr : load_texture(fallback);
+}
+
void Renderer::draw_sprite(float cx, float cy, float half_w, float half_h,
float angle, SDL_Texture* tex,
float r, float g, float b, float a) {
diff --git a/src/engine/renderer.hpp b/src/engine/renderer.hpp
index ddc8055..f5a087f 100644
--- a/src/engine/renderer.hpp
+++ b/src/engine/renderer.hpp
@@ -25,6 +25,13 @@ public:
// Load a texture (cached by path). Returns nullptr on failure.
SDL_Texture* load_texture(const std::string& path);
+ // Load `primary` if set, falling back to `fallback` if it is empty or fails
+ // to load. Used for BYO Forts art ("forts:...") that degrades to the CC0
+ // placeholder when the game is not installed. Returns nullptr if neither
+ // loads.
+ SDL_Texture* load_texture_or(const std::string& primary,
+ const std::string& fallback);
+
// Draw a textured quad in world coordinates, colour-modulated by (r,g,b,a).
void draw_sprite(float cx, float cy, float half_w, float half_h,
float angle, SDL_Texture* tex,
diff --git a/src/game/build_graph.hpp b/src/game/build_graph.hpp
index f92dbd3..bf83a18 100644
--- a/src/game/build_graph.hpp
+++ b/src/game/build_graph.hpp
@@ -36,7 +36,9 @@ struct MaterialDef {
float half_width; // visual thickness
float r, g, b, a; // visual colour (also tints the texture)
std::string name;
- std::string texture; // optional texture path ("" = flat colour)
+ std::string texture; // CC0 placeholder path ("" = flat colour)
+ std::string texture_forts; // preferred BYO Forts art ("forts:..."), falls
+ // back to `texture` then colour when absent
};
struct BuildNode {
diff --git a/src/game/data.cpp b/src/game/data.cpp
index 54f7fdb..654cac6 100644
--- a/src/game/data.cpp
+++ b/src/game/data.cpp
@@ -37,6 +37,7 @@ MaterialDef read_material(const sol::table& m) {
d.tension_only = m.get_or("tension_only", false);
d.half_width = m.get_or("half_width", 0.15f);
d.texture = m.get_or("texture", std::string(""));
+ d.texture_forts = m.get_or("texture_forts", std::string(""));
sol::optional<sol::table> col = m["color"];
d.r = col ? col->get_or(1, 0.8f) : 0.8f;
@@ -138,6 +139,8 @@ WeaponDef read_weapon(const sol::table& w) {
d.energy_cost = w.get_or("energy_cost", 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(""));
+ d.projectile_texture_forts = w.get_or("projectile_texture_forts", std::string(""));
return d;
}
} // namespace
@@ -213,6 +216,7 @@ DeviceDef read_device(const sol::table& d) {
v.cost_metal = d.get_or("cost_metal", 0.0f);
v.cost_energy = d.get_or("cost_energy", 0.0f);
v.texture = d.get_or("texture", std::string(""));
+ v.texture_forts = d.get_or("texture_forts", std::string(""));
sol::optional<sol::table> col = d["color"];
v.r = col ? col->get_or(1, 0.8f) : 0.8f;
v.g = col ? col->get_or(2, 0.8f) : 0.8f;
diff --git a/src/game/data.hpp b/src/game/data.hpp
index 3a7f912..fdf9e08 100644
--- a/src/game/data.hpp
+++ b/src/game/data.hpp
@@ -24,8 +24,10 @@ 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)
- std::string texture; // turret/base sprite
- std::string projectile_texture; // shell sprite
+ 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
+ std::string projectile_texture_forts; // preferred BYO Forts shell art
};
// Loads the material table from <data_dir>/materials.lua, then applies every
@@ -57,7 +59,8 @@ struct DeviceDef {
bool is_core; // reactor: destroying it decides the game
float half_w, half_h;
float cost_metal, cost_energy; // build cost
- std::string texture;
+ std::string texture; // CC0 placeholder ("" = flat colour)
+ std::string texture_forts; // preferred BYO Forts art, else texture
float r, g, b; // fallback colour when no texture
};