OpenKKnD/engine-c/src/sprites.c
2026-09-19 19:25:36 +02:00

1294 lines
70 KiB
C

#include "kknd.h"
/* =========================================================================
* sprites.c - Procedural 2D sprite/terrain generation.
* Recreates the chunky post-apocalyptic KKND look without using any
* original game assets. All art is drawn at runtime into SDL textures.
* ========================================================================= */
#define SURF_FMT SDL_PIXELFORMAT_RGBA32
static SDL_Surface *new_surf(int w, int h) {
return SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SURF_FMT);
}
static void px(SDL_Surface *s, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
if (x < 0 || y < 0 || x >= s->w || y >= s->h) return;
Uint32 *p = (Uint32 *)((Uint8 *)s->pixels + y * s->pitch);
Uint32 pix = (a << 24) | (b << 16) | (g << 8) | r;
p[x] = pix;
}
static void fill_rect(SDL_Surface *s, int x, int y, int w, int h,
Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
for (int j = y; j < y + h; j++)
for (int i = x; i < x + w; i++)
px(s, i, j, r, g, b, a);
}
static void disc(SDL_Surface *s, int cx, int cy, int rad,
Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
for (int j = -rad; j <= rad; j++)
for (int i = -rad; i <= rad; i++)
if (i*i + j*j <= rad*rad)
px(s, cx + i, cy + j, r, g, b, a);
}
static void ring(SDL_Surface *s, int cx, int cy, int rad, int t,
Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
for (int j = -rad; j <= rad; j++)
for (int i = -rad; i <= rad; i++) {
int d = i*i + j*j;
if (d <= rad*rad && d >= (rad - t)*(rad - t))
px(s, cx + i, cy + j, r, g, b, a);
}
}
static void line(SDL_Surface *s, int x0, int y0, int x1, int y1,
Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
int dx = abs(x1 - x0), dy = -abs(y1 - y0);
int sx = x0 < x1 ? 1 : -1, sy = y0 < y1 ? 1 : -1;
int err = dx + dy;
for (;;) {
px(s, x0, y0, r, g, b, a);
if (x0 == x1 && y0 == y1) break;
int e2 = 2 * err;
if (e2 >= dy) { err += dy; x0 += sx; }
if (e2 <= dx) { err += dx; y0 += sy; }
}
}
static SDL_Color darken(SDL_Color c, float f) {
return (SDL_Color){
(Uint8)(c.r*f), (Uint8)(c.g*f), (Uint8)(c.b*f), c.a };
}
static SDL_Color lighten(SDL_Color c, float f) {
return (SDL_Color){
(Uint8)(c.r + (255-c.r)*f), (Uint8)(c.g + (255-c.g)*f),
(Uint8)(c.b + (255-c.b)*f), c.a };
}
/* ---------------- unit sprites ---------------- */
/* Near-black outline first (KKND2 silhouette), then bright faction fill.
* Geometry mirrors snapshot.c draw_unit atlas coords (center 15,15); SDL rotates live. */
SDL_Texture *sprites_make_unit(SDL_Renderer *r, UnitType t, Faction f) {
int S = 30;
SDL_Surface *s = new_surf(S, S);
SDL_Color base = faction_color(f);
SDL_Color dark = darken(base, 0.55f);
SDL_Color lite = lighten(base, 0.45f);
/* Tyre / mid-tone parity with snapshot draw_unit (mr/mg/mb). */
const Uint8 tr = 70, tg = 65, tb = 58;
const Uint8 ok = 18, og = 16, ob = 14; /* near-black outline */
(void)dark;
switch (t) {
case UT_INFANTRY:
/* boots/knees → torso/belt/pouches → pads → pack → helmet/visor/antenna → rifle+bayonet */
disc(s, 11, 23, 3, ok, og, ob, 255);
disc(s, 19, 23, 3, ok, og, ob, 255);
disc(s, 11, 23, 2, base.r, base.g, base.b, 255);
disc(s, 19, 23, 2, base.r, base.g, base.b, 255);
fill_rect(s, 10, 24, 3, 2, 40, 36, 30, 255); /* boot L */
fill_rect(s, 18, 24, 3, 2, 40, 36, 30, 255); /* boot R */
fill_rect(s, 10, 20, 3, 2, 55, 50, 42, 255); /* knee pad L */
fill_rect(s, 18, 20, 3, 2, 55, 50, 42, 255); /* knee pad R */
disc(s, 15, 15, 9, ok, og, ob, 255);
disc(s, 15, 15, 7, base.r, base.g, base.b, 255);
fill_rect(s, 11, 17, 8, 2, 45, 42, 36, 255); /* belt */
fill_rect(s, 12, 16, 2, 2, 60, 55, 45, 255); /* pouch L */
fill_rect(s, 16, 16, 2, 2, 60, 55, 45, 255); /* pouch R */
fill_rect(s, 9, 12, 3, 3, 50, 46, 40, 255); /* shoulder pad L */
fill_rect(s, 19, 12, 3, 3, 50, 46, 40, 255); /* shoulder pad R */
disc(s, 10, 16, 3, ok, og, ob, 255); /* backpack */
disc(s, 10, 16, 2, 50, 46, 40, 255);
fill_rect(s, 8, 15, 2, 3, 40, 38, 32, 255); /* pack strap */
disc(s, 15, 8, 5, ok, og, ob, 255);
disc(s, 15, 8, 4, lite.r, lite.g, lite.b, 255);
fill_rect(s, 12, 7, 5, 2, 30, 40, 50, 255); /* visor */
line(s, 14, 6, 14, 1, 50, 46, 40, 255); /* antenna */
line(s, 15, 6, 15, 0, lite.r, lite.g, lite.b, 255);
line(s, 16, 14, 16, 0, 40, 36, 30, 255);
line(s, 17, 14, 17, 1, 55, 50, 40, 255);
line(s, 18, 14, 18, 2, 45, 40, 34, 255);
disc(s, 17, 1, 2, 60, 55, 45, 255); /* muzzle tip */
line(s, 17, 2, 20, 0, 70, 65, 55, 255); /* bayonet */
line(s, 18, 2, 21, 1, 55, 50, 40, 255);
break;
case UT_BUGGY:
/* fenders + bumper + cabin + roll bar + spare + exhaust + lights + MG */
fill_rect(s, 2, 6, 26, 18, ok, og, ob, 255);
fill_rect(s, 4, 8, 22, 14, base.r, base.g, base.b, 255);
fill_rect(s, 3, 6, 6, 3, 45, 42, 36, 255); /* front fender L */
fill_rect(s, 21, 6, 6, 3, 45, 42, 36, 255); /* front fender R */
fill_rect(s, 3, 22, 6, 3, 45, 42, 36, 255); /* rear fender L */
fill_rect(s, 21, 22, 6, 3, 45, 42, 36, 255); /* rear fender R */
fill_rect(s, 1, 12, 3, 6, 55, 50, 40, 255); /* bumper */
fill_rect(s, 2, 13, 1, 4, 90, 80, 55, 255);
fill_rect(s, 6, 9, 10, 6, lite.r, lite.g, lite.b, 255);
fill_rect(s, 7, 8, 8, 3, 35, 55, 75, 255); /* windshield */
line(s, 8, 10, 8, 4, lite.r, lite.g, lite.b, 255); /* roll bar L */
line(s, 9, 10, 9, 4, 50, 46, 40, 255);
line(s, 18, 10, 18, 4, lite.r, lite.g, lite.b, 255); /* roll bar R */
line(s, 17, 10, 17, 4, 50, 46, 40, 255);
line(s, 8, 4, 18, 4, lite.r, lite.g, lite.b, 255);
line(s, 8, 5, 18, 5, 50, 46, 40, 255);
disc(s, 25, 16, 3, ok, og, ob, 255); /* spare tyre */
disc(s, 25, 16, 2, tr, tg, tb, 255);
disc(s, 25, 16, 1, 90, 85, 75, 255);
fill_rect(s, 26, 20, 3, 2, 40, 38, 32, 255); /* exhaust */
fill_rect(s, 27, 19, 2, 1, 70, 65, 55, 255);
disc(s, 4, 11, 2, 220, 200, 80, 255); /* headlight L */
disc(s, 4, 19, 2, 220, 200, 80, 255); /* headlight R */
disc(s, 8, 7, 5, ok, og, ob, 255);
disc(s, 22, 7, 5, ok, og, ob, 255);
disc(s, 8, 23, 5, ok, og, ob, 255);
disc(s, 22, 23, 5, ok, og, ob, 255);
disc(s, 8, 7, 4, tr, tg, tb, 255);
disc(s, 22, 7, 4, tr, tg, tb, 255);
disc(s, 8, 23, 4, tr, tg, tb, 255);
disc(s, 22, 23, 4, tr, tg, tb, 255);
disc(s, 8, 7, 2, 90, 85, 75, 255);
disc(s, 22, 7, 2, 90, 85, 75, 255);
disc(s, 8, 23, 2, 90, 85, 75, 255);
disc(s, 22, 23, 2, 90, 85, 75, 255);
line(s, 15, 14, 29, 14, 40, 36, 30, 255);
line(s, 15, 15, 29, 15, 50, 45, 35, 255);
line(s, 15, 16, 29, 16, 40, 36, 30, 255);
disc(s, 29, 15, 2, 60, 55, 45, 255);
break;
case UT_TANK:
/* skirts + road wheels + glacis + mantlet + coax + exhaust + antenna + barrel */
fill_rect(s, 2, 8, 5, 12, ok, og, ob, 255);
fill_rect(s, 23, 8, 5, 12, ok, og, ob, 255);
fill_rect(s, 3, 10, 3, 10, tr, tg, tb, 255);
fill_rect(s, 24, 10, 3, 10, tr, tg, tb, 255);
fill_rect(s, 2, 9, 5, 2, 50, 46, 40, 255); /* side skirt L top */
fill_rect(s, 23, 9, 5, 2, 50, 46, 40, 255); /* side skirt R top */
fill_rect(s, 2, 18, 5, 2, 50, 46, 40, 255); /* side skirt L bot */
fill_rect(s, 23, 18, 5, 2, 50, 46, 40, 255);
disc(s, 5, 11, 2, 40, 38, 32, 255); /* sprocket */
disc(s, 5, 15, 2, 40, 38, 32, 255); /* road wheel */
disc(s, 5, 20, 2, 40, 38, 32, 255);
disc(s, 26, 11, 2, 40, 38, 32, 255);
disc(s, 26, 15, 2, 40, 38, 32, 255);
disc(s, 26, 20, 2, 40, 38, 32, 255);
fill_rect(s, 4, 10, 22, 10, ok, og, ob, 255);
fill_rect(s, 6, 11, 18, 8, base.r, base.g, base.b, 255);
fill_rect(s, 5, 10, 8, 3, 55, 50, 42, 255); /* glacis plate */
fill_rect(s, 6, 11, 6, 2, lite.r, lite.g, lite.b, 255);
disc(s, 15, 15, 7, ok, og, ob, 255);
disc(s, 15, 15, 6, lite.r, lite.g, lite.b, 255);
fill_rect(s, 18, 13, 4, 5, 45, 42, 36, 255); /* mantlet */
fill_rect(s, 19, 14, 2, 3, 60, 55, 45, 255);
disc(s, 15, 12, 2, 40, 38, 32, 255); /* hatch */
line(s, 14, 12, 14, 2, 50, 46, 40, 255); /* antenna */
line(s, 15, 12, 15, 1, lite.r, lite.g, lite.b, 255);
fill_rect(s, 7, 20, 3, 2, 40, 38, 32, 255); /* exhaust */
fill_rect(s, 8, 19, 1, 1, 70, 65, 55, 255);
line(s, 15, 13, 29, 13, 45, 40, 32, 255);
line(s, 15, 14, 29, 14, 50, 45, 35, 255);
line(s, 15, 15, 29, 15, 55, 50, 40, 255);
line(s, 15, 16, 29, 16, 50, 45, 35, 255);
line(s, 15, 17, 28, 17, 45, 40, 32, 255);
line(s, 18, 12, 27, 11, 40, 36, 30, 255); /* coax MG */
line(s, 18, 12, 27, 12, 50, 45, 35, 255);
disc(s, 29, 15, 2, 60, 55, 45, 255);
disc(s, 8, 23, 4, tr, tg, tb, 255);
disc(s, 22, 23, 4, tr, tg, tb, 255);
break;
case UT_ARTILLERY:
/* howitzer: trails + cradle + shield + ammo + tube bands + brake + hubs */
fill_rect(s, 1, 18, 8, 3, ok, og, ob, 255); /* left outrigger */
fill_rect(s, 21, 18, 8, 3, ok, og, ob, 255); /* right outrigger */
fill_rect(s, 0, 19, 4, 2, 40, 38, 32, 255); /* spade L */
fill_rect(s, 26, 19, 4, 2, 40, 38, 32, 255); /* spade R */
fill_rect(s, 2, 20, 2, 2, 55, 50, 40, 255); /* trail pin L */
fill_rect(s, 26, 20, 2, 2, 55, 50, 40, 255); /* trail pin R */
fill_rect(s, 4, 11, 22, 10, ok, og, ob, 255);
fill_rect(s, 6, 13, 18, 7, base.r, base.g, base.b, 255);
fill_rect(s, 5, 14, 2, 5, 40, 38, 32, 255); /* chassis rail L */
fill_rect(s, 23, 14, 2, 5, 40, 38, 32, 255); /* chassis rail R */
fill_rect(s, 22, 12, 6, 8, 55, 50, 40, 255); /* ammo rack */
line(s, 23, 13, 27, 13, 90, 80, 55, 255);
line(s, 23, 15, 27, 15, 90, 80, 55, 255);
line(s, 23, 17, 27, 17, 90, 80, 55, 255);
fill_rect(s, 23, 14, 2, 2, 200, 160, 60, 255); /* shell tip */
fill_rect(s, 25, 16, 2, 2, 200, 160, 60, 255);
fill_rect(s, 10, 8, 10, 5, ok, og, ob, 255); /* gun shield */
fill_rect(s, 11, 9, 8, 3, lite.r, lite.g, lite.b, 255);
fill_rect(s, 12, 8, 6, 1, 255, 200, 40, 255); /* warn stripe */
disc(s, 15, 14, 4, ok, og, ob, 255); /* recoil cradle */
disc(s, 15, 14, 3, lite.r, lite.g, lite.b, 255);
fill_rect(s, 13, 13, 4, 3, 55, 50, 40, 255); /* breech */
fill_rect(s, 14, 14, 2, 1, 90, 80, 55, 255);
line(s, 15, 11, 3, 1, 45, 40, 32, 255); /* elevated tube */
line(s, 15, 12, 3, 2, 50, 45, 35, 255);
line(s, 15, 13, 2, 1, 55, 50, 40, 255);
line(s, 15, 14, 3, 3, 50, 45, 35, 255);
line(s, 15, 15, 4, 4, 45, 40, 32, 255);
disc(s, 10, 8, 1, 70, 65, 55, 255); /* tube band */
disc(s, 7, 5, 1, 70, 65, 55, 255);
fill_rect(s, 12, 16, 2, 3, 70, 65, 55, 255); /* elev hydrau */
fill_rect(s, 16, 16, 2, 3, 70, 65, 55, 255);
fill_rect(s, 1, 0, 5, 4, 60, 55, 45, 255); /* muzzle brake */
fill_rect(s, 2, 1, 3, 2, 30, 28, 24, 255);
disc(s, 3, 2, 1, 90, 85, 75, 255); /* brake ring */
line(s, 20, 11, 20, 6, 50, 46, 40, 255); /* antenna */
disc(s, 20, 5, 1, 200, 200, 80, 255);
disc(s, 8, 23, 5, ok, og, ob, 255);
disc(s, 22, 23, 5, ok, og, ob, 255);
disc(s, 8, 23, 4, tr, tg, tb, 255);
disc(s, 22, 23, 4, tr, tg, tb, 255);
disc(s, 8, 23, 2, 90, 85, 75, 255);
disc(s, 22, 23, 2, 90, 85, 75, 255);
break;
case UT_HARVESTER:
/* cabin + boom/scoop + conveyor + hopper panels + exhaust/lights + hubbed wheels */
fill_rect(s, 1, 6, 28, 18, ok, og, ob, 255);
fill_rect(s, 3, 8, 24, 14, base.r, base.g, base.b, 255);
fill_rect(s, 3, 8, 8, 8, lite.r, lite.g, lite.b, 255);
fill_rect(s, 4, 8, 6, 3, 35, 55, 75, 255); /* glass */
fill_rect(s, 5, 12, 4, 2, 45, 42, 36, 255); /* cabin panel */
line(s, 2, 14, 8, 11, 50, 46, 40, 255); /* boom arm */
line(s, 2, 15, 8, 12, 70, 65, 55, 255);
fill_rect(s, 0, 14, 5, 5, 90, 80, 55, 255); /* scoop lip */
fill_rect(s, 1, 15, 3, 3, 70, 60, 40, 255);
fill_rect(s, 11, 10, 14, 10, 55, 48, 32, 255); /* hopper bed */
fill_rect(s, 11, 10, 8, 10, 200, 170, 90, 255);
line(s, 14, 10, 24, 10, 160, 130, 70, 255); /* conveyor ribs */
line(s, 14, 13, 24, 13, 160, 130, 70, 255);
line(s, 14, 16, 24, 16, 160, 130, 70, 255);
fill_rect(s, 12, 9, 12, 1, 45, 40, 32, 255); /* hopper rim */
fill_rect(s, 24, 11, 3, 8, 50, 46, 40, 255); /* side panel */
fill_rect(s, 25, 12, 1, 6, 70, 65, 55, 255);
fill_rect(s, 20, 18, 4, 2, 40, 38, 32, 255); /* exhaust */
fill_rect(s, 21, 17, 2, 1, 70, 65, 55, 255);
disc(s, 4, 10, 2, 220, 200, 80, 255); /* cabin light */
disc(s, 2, 16, 1, 220, 180, 60, 255); /* scoop lamp */
disc(s, 8, 23, 5, ok, og, ob, 255);
disc(s, 22, 23, 5, ok, og, ob, 255);
disc(s, 8, 23, 4, tr, tg, tb, 255);
disc(s, 22, 23, 4, tr, tg, tb, 255);
disc(s, 8, 23, 2, 90, 85, 75, 255);
disc(s, 22, 23, 2, 90, 85, 75, 255);
line(s, 5, 7, 5, 2, lite.r, lite.g, lite.b, 255);
line(s, 6, 7, 6, 3, 50, 46, 40, 255);
break;
case UT_JEEP:
/* bumper + grill + seats + jerry cans + spare + lights + antenna + cage + MG */
fill_rect(s, 4, 9, 22, 12, ok, og, ob, 255);
fill_rect(s, 6, 11, 18, 8, base.r, base.g, base.b, 255);
fill_rect(s, 3, 12, 3, 6, 55, 50, 40, 255); /* bumper */
fill_rect(s, 4, 13, 1, 4, 90, 80, 55, 255);
fill_rect(s, 5, 13, 3, 4, 40, 38, 32, 255); /* grill */
line(s, 5, 14, 7, 14, 70, 65, 55, 255);
line(s, 5, 16, 7, 16, 70, 65, 55, 255);
fill_rect(s, 7, 10, 8, 5, lite.r, lite.g, lite.b, 255);
fill_rect(s, 8, 12, 3, 3, 45, 40, 35, 255); /* seat L */
fill_rect(s, 14, 12, 3, 3, 45, 40, 35, 255); /* seat R */
fill_rect(s, 22, 11, 3, 4, 70, 90, 50, 255); /* jerry can */
fill_rect(s, 23, 12, 1, 2, 90, 110, 60, 255);
disc(s, 24, 18, 3, ok, og, ob, 255); /* spare */
disc(s, 24, 18, 2, tr, tg, tb, 255);
disc(s, 24, 18, 1, 90, 85, 75, 255);
disc(s, 5, 11, 2, 220, 200, 80, 255); /* light L */
disc(s, 5, 19, 2, 220, 200, 80, 255); /* light R */
line(s, 16, 10, 16, 1, 50, 46, 40, 255); /* antenna */
line(s, 17, 10, 17, 2, lite.r, lite.g, lite.b, 255);
disc(s, 9, 22, 5, ok, og, ob, 255);
disc(s, 21, 22, 5, ok, og, ob, 255);
disc(s, 9, 22, 4, tr, tg, tb, 255);
disc(s, 21, 22, 4, tr, tg, tb, 255);
disc(s, 9, 22, 2, 90, 85, 75, 255);
disc(s, 21, 22, 2, 90, 85, 75, 255);
line(s, 11, 11, 11, 3, lite.r, lite.g, lite.b, 255);
line(s, 12, 11, 12, 3, 50, 46, 40, 255);
line(s, 19, 11, 19, 3, lite.r, lite.g, lite.b, 255);
line(s, 18, 11, 18, 3, 50, 46, 40, 255);
line(s, 11, 3, 19, 3, lite.r, lite.g, lite.b, 255);
line(s, 11, 4, 19, 4, 50, 46, 40, 255);
line(s, 15, 14, 28, 14, 40, 36, 30, 255);
line(s, 15, 15, 28, 15, 50, 45, 35, 255);
line(s, 15, 16, 28, 16, 40, 36, 30, 255);
disc(s, 28, 15, 2, 60, 55, 45, 255);
break;
case UT_MUTANT:
/* plates + eyes/jaw + spikes + dual claws + tail */
disc(s, 15, 17, 11, ok, og, ob, 255);
disc(s, 15, 15, 9, base.r, base.g, base.b, 255);
fill_rect(s, 10, 14, 4, 3, 45, 40, 35, 255); /* chest plate L */
fill_rect(s, 17, 14, 4, 3, 45, 40, 35, 255); /* chest plate R */
disc(s, 15, 9, 5, ok, og, ob, 255);
disc(s, 15, 9, 4, lite.r, lite.g, lite.b, 255);
fill_rect(s, 11, 7, 7, 2, 30, 40, 50, 255); /* brow */
disc(s, 12, 9, 1, 200, 60, 40, 255); /* eye L */
disc(s, 18, 9, 1, 200, 60, 40, 255); /* eye R */
fill_rect(s, 13, 11, 5, 2, 40, 30, 28, 255); /* jaw */
line(s, 14, 12, 14, 13, 70, 55, 45, 255); /* fang */
line(s, 16, 12, 16, 13, 70, 55, 45, 255);
line(s, 12, 6, 9, 0, 40, 36, 30, 255);
line(s, 13, 6, 10, 1, 55, 50, 40, 255);
line(s, 15, 5, 15, 0, 40, 36, 30, 255);
line(s, 16, 5, 16, 0, 55, 50, 40, 255);
line(s, 18, 6, 21, 0, 40, 36, 30, 255);
line(s, 17, 6, 20, 1, 55, 50, 40, 255);
line(s, 14, 4, 12, 0, 50, 45, 35, 255); /* extra spike */
line(s, 15, 16, 26, 8, 40, 36, 30, 255);
line(s, 15, 17, 26, 9, 50, 45, 35, 255);
line(s, 24, 9, 29, 5, 55, 50, 40, 255);
line(s, 24, 9, 29, 11, 55, 50, 40, 255);
line(s, 24, 10, 28, 8, 70, 60, 45, 255);
disc(s, 28, 8, 2, 70, 60, 45, 255); /* claw tip R */
line(s, 12, 16, 4, 10, 40, 36, 30, 255); /* second claw L */
line(s, 12, 17, 4, 11, 50, 45, 35, 255);
line(s, 5, 10, 1, 7, 55, 50, 40, 255);
line(s, 5, 11, 1, 13, 55, 50, 40, 255);
disc(s, 2, 10, 2, 70, 60, 45, 255);
line(s, 15, 20, 15, 27, 45, 40, 35, 255); /* tail */
line(s, 16, 20, 18, 28, 55, 50, 40, 255);
disc(s, 17, 27, 2, 60, 50, 40, 255);
disc(s, 10, 22, 4, ok, og, ob, 255);
disc(s, 20, 22, 4, ok, og, ob, 255);
disc(s, 10, 22, 3, base.r, base.g, base.b, 255);
disc(s, 20, 22, 3, base.r, base.g, base.b, 255);
break;
case UT_BEAST:
/* carapace plates/spines + eye + vents + tusks + hubbed multi-wheel */
fill_rect(s, 5, 9, 20, 12, ok, og, ob, 255);
fill_rect(s, 7, 11, 16, 8, base.r, base.g, base.b, 255);
fill_rect(s, 9, 10, 12, 3, lite.r, lite.g, lite.b, 255); /* carapace ridge */
fill_rect(s, 8, 13, 5, 3, 50, 46, 40, 255); /* plate L */
fill_rect(s, 17, 13, 5, 3, 50, 46, 40, 255); /* plate R */
line(s, 10, 9, 10, 5, 40, 36, 30, 255); /* spine */
line(s, 13, 9, 13, 4, 55, 50, 40, 255);
line(s, 16, 9, 16, 4, 55, 50, 40, 255);
line(s, 19, 9, 19, 5, 40, 36, 30, 255);
fill_rect(s, 11, 16, 2, 2, 30, 28, 24, 255); /* vent L */
fill_rect(s, 17, 16, 2, 2, 30, 28, 24, 255); /* vent R */
disc(s, 9, 21, 4, ok, og, ob, 255);
disc(s, 14, 22, 4, ok, og, ob, 255);
disc(s, 19, 21, 4, ok, og, ob, 255);
disc(s, 23, 22, 4, ok, og, ob, 255);
disc(s, 9, 21, 3, tr, tg, tb, 255);
disc(s, 14, 22, 3, tr, tg, tb, 255);
disc(s, 19, 21, 3, tr, tg, tb, 255);
disc(s, 23, 22, 3, tr, tg, tb, 255);
disc(s, 9, 21, 1, 90, 85, 75, 255); /* hub */
disc(s, 14, 22, 1, 90, 85, 75, 255);
disc(s, 19, 21, 1, 90, 85, 75, 255);
disc(s, 23, 22, 1, 90, 85, 75, 255);
disc(s, 24, 12, 6, ok, og, ob, 255);
disc(s, 24, 12, 5, lite.r, lite.g, lite.b, 255); /* snout */
disc(s, 26, 11, 1, 200, 80, 40, 255); /* eye */
line(s, 26, 10, 29, 8, 40, 36, 30, 255); /* tusk */
line(s, 26, 14, 29, 16, 40, 36, 30, 255);
line(s, 26, 12, 29, 12, 55, 50, 40, 255);
disc(s, 29, 12, 2, 60, 55, 45, 255);
break;
case UT_RAVAGER:
/* prow + ammo boxes + triple gatling + exhaust (vs tank cupola) */
fill_rect(s, 0, 7, 5, 14, ok, og, ob, 255);
fill_rect(s, 25, 7, 5, 14, ok, og, ob, 255);
fill_rect(s, 1, 10, 3, 10, tr, tg, tb, 255);
fill_rect(s, 26, 10, 3, 10, tr, tg, tb, 255);
disc(s, 3, 12, 2, 40, 38, 32, 255);
disc(s, 3, 20, 2, 40, 38, 32, 255);
disc(s, 28, 12, 2, 40, 38, 32, 255);
disc(s, 28, 20, 2, 40, 38, 32, 255);
fill_rect(s, 3, 9, 24, 12, ok, og, ob, 255);
fill_rect(s, 5, 10, 20, 10, base.r, base.g, base.b, 255);
fill_rect(s, 24, 8, 6, 6, 55, 48, 38, 255); /* prow plate */
line(s, 25, 9, 29, 11, 70, 60, 45, 255);
line(s, 25, 13, 29, 11, 70, 60, 45, 255);
fill_rect(s, 4, 8, 5, 4, 70, 55, 35, 255); /* ammo boxes */
fill_rect(s, 5, 9, 3, 2, 200, 160, 60, 255);
fill_rect(s, 10, 8, 5, 4, 70, 55, 35, 255);
fill_rect(s, 11, 9, 3, 2, 200, 160, 60, 255);
fill_rect(s, 12, 12, 10, 8, ok, og, ob, 255); /* gatling block */
fill_rect(s, 13, 13, 8, 6, lite.r, lite.g, lite.b, 255);
line(s, 20, 13, 29, 12, 45, 40, 32, 255); /* triple barrels */
line(s, 20, 15, 29, 15, 55, 50, 40, 255);
line(s, 20, 17, 29, 18, 45, 40, 32, 255);
disc(s, 29, 12, 1, 60, 55, 45, 255);
disc(s, 29, 15, 2, 60, 55, 45, 255);
disc(s, 29, 18, 1, 60, 55, 45, 255);
fill_rect(s, 2, 14, 3, 4, 40, 38, 32, 255); /* exhaust */
disc(s, 2, 15, 2, 90, 70, 40, 255);
disc(s, 2, 17, 1, 200, 100, 40, 255);
disc(s, 7, 23, 5, ok, og, ob, 255);
disc(s, 23, 23, 5, ok, og, ob, 255);
disc(s, 7, 23, 4, tr, tg, tb, 255);
disc(s, 23, 23, 4, tr, tg, tb, 255);
break;
case UT_FLAME:
/* dual tanks + gauges + hose + shield + nozzle jet + boots */
fill_rect(s, 7, 12, 16, 12, ok, og, ob, 255);
fill_rect(s, 9, 14, 12, 9, base.r, base.g, base.b, 255);
fill_rect(s, 10, 15, 3, 4, 45, 42, 36, 255); /* pouch */
fill_rect(s, 18, 16, 3, 3, 45, 42, 36, 255); /* belt box */
disc(s, 15, 9, 5, ok, og, ob, 255);
disc(s, 15, 9, 4, lite.r, lite.g, lite.b, 255);
fill_rect(s, 12, 8, 5, 2, 30, 40, 50, 255); /* visor */
fill_rect(s, 13, 7, 3, 1, 90, 100, 110, 255); /* brow plate */
fill_rect(s, 14, 11, 2, 3, 55, 50, 40, 255); /* shoulder plate */
disc(s, 6, 13, 5, ok, og, ob, 255); /* dual fuel tanks */
disc(s, 6, 13, 4, 90, 70, 40, 255);
disc(s, 6, 13, 2, 200, 120, 40, 255);
disc(s, 6, 19, 5, ok, og, ob, 255);
disc(s, 6, 19, 4, 90, 70, 40, 255);
disc(s, 6, 19, 2, 200, 120, 40, 255);
fill_rect(s, 4, 12, 2, 3, 255, 200, 40, 255); /* tank warn stripe */
fill_rect(s, 4, 18, 2, 3, 255, 200, 40, 255);
disc(s, 6, 11, 1, 60, 55, 45, 255); /* valve */
disc(s, 6, 17, 1, 60, 55, 45, 255);
disc(s, 6, 21, 1, 60, 55, 45, 255);
disc(s, 8, 13, 1, 180, 220, 255, 255); /* gauge */
disc(s, 8, 19, 1, 180, 220, 255, 255);
line(s, 8, 14, 10, 14, 50, 46, 40, 255); /* strap */
line(s, 8, 18, 10, 18, 50, 46, 40, 255);
line(s, 10, 14, 16, 16, 50, 45, 35, 255); /* hose */
line(s, 10, 15, 16, 17, 70, 55, 35, 255);
disc(s, 12, 15, 1, 70, 65, 55, 255); /* hose clamp */
disc(s, 14, 16, 1, 70, 65, 55, 255);
fill_rect(s, 16, 12, 5, 8, 55, 50, 40, 255); /* heat shield */
fill_rect(s, 17, 13, 3, 6, 90, 70, 40, 255);
fill_rect(s, 18, 14, 1, 4, 40, 38, 32, 255); /* nozzle grip */
disc(s, 19, 13, 1, 255, 180, 60, 255); /* pilot light */
line(s, 20, 14, 28, 19, 255, 120, 40, 255);
line(s, 20, 15, 28, 20, 255, 150, 50, 255);
line(s, 20, 16, 27, 21, 255, 180, 60, 255);
line(s, 20, 17, 26, 21, 255, 200, 80, 255);
line(s, 21, 13, 27, 17, 255, 100, 30, 255); /* upper jet */
disc(s, 28, 20, 3, 255, 200, 80, 255);
disc(s, 28, 20, 1, 255, 240, 160, 255);
disc(s, 26, 18, 1, 255, 220, 120, 255); /* ember */
disc(s, 27, 22, 1, 255, 160, 60, 255);
fill_rect(s, 11, 22, 3, 3, 40, 36, 30, 255); /* boot L */
fill_rect(s, 17, 22, 3, 3, 40, 36, 30, 255); /* boot R */
break;
case UT_MISSILE:
/* MLRS box + rails + stripes + cab + pods + hydrau + hubs (KKND rocket truck) */
fill_rect(s, 3, 12, 24, 12, ok, og, ob, 255);
fill_rect(s, 5, 14, 20, 8, base.r, base.g, base.b, 255);
fill_rect(s, 4, 15, 3, 5, 40, 38, 32, 255); /* chassis rail L */
fill_rect(s, 23, 15, 3, 5, 40, 38, 32, 255); /* chassis rail R */
fill_rect(s, 2, 11, 6, 7, ok, og, ob, 255); /* cab outline */
fill_rect(s, 3, 12, 4, 5, 55, 52, 45, 255);
fill_rect(s, 3, 12, 4, 2, 140, 180, 210, 255); /* cab glass */
fill_rect(s, 8, 4, 16, 10, ok, og, ob, 255); /* box launcher */
fill_rect(s, 9, 5, 14, 8, 50, 48, 42, 255);
line(s, 10, 6, 22, 6, 90, 85, 70, 255); /* rails */
line(s, 10, 8, 22, 8, 90, 85, 70, 255);
line(s, 10, 10, 22, 10, 90, 85, 70, 255);
line(s, 10, 12, 22, 12, 90, 85, 70, 255);
fill_rect(s, 9, 5, 3, 8, 255, 200, 40, 255); /* warning stripes */
fill_rect(s, 12, 5, 2, 8, 30, 28, 24, 255);
fill_rect(s, 14, 5, 3, 8, 255, 200, 40, 255);
fill_rect(s, 17, 5, 2, 8, 30, 28, 24, 255);
fill_rect(s, 19, 5, 3, 8, 255, 200, 40, 255);
disc(s, 23, 7, 2, 255, 120, 80, 255); /* nose tips */
disc(s, 23, 10, 2, 255, 140, 90, 255);
disc(s, 23, 12, 1, 255, 160, 100, 255);
fill_rect(s, 7, 14, 2, 4, 70, 65, 55, 255); /* hydraulic L */
fill_rect(s, 21, 14, 2, 4, 70, 65, 55, 255); /* hydraulic R */
line(s, 8, 13, 8, 5, 60, 55, 45, 255); /* elevate strut */
disc(s, 4, 10, 1, 200, 200, 80, 255); /* antenna tip */
line(s, 4, 10, 4, 8, 90, 90, 70, 255);
disc(s, 9, 23, 5, ok, og, ob, 255);
disc(s, 21, 23, 5, ok, og, ob, 255);
disc(s, 9, 23, 4, tr, tg, tb, 255);
disc(s, 21, 23, 4, tr, tg, tb, 255);
disc(s, 9, 23, 2, 90, 85, 75, 255);
disc(s, 21, 23, 2, 90, 85, 75, 255);
line(s, 22, 8, 29, 4, 255, 80, 60, 255);
line(s, 22, 10, 29, 6, 255, 100, 70, 255);
disc(s, 29, 5, 2, 255, 140, 90, 255);
disc(s, 28, 7, 1, 255, 180, 100, 255); /* exhaust spark */
break;
case UT_MEDIC:
/* bumper + grille + lights + door/side + mirrors + exhaust + light-bar + stretcher/cross + hubs */
fill_rect(s, 3, 9, 24, 17, ok, og, ob, 255);
fill_rect(s, 5, 11, 20, 13, 245, 245, 245, 255);
fill_rect(s, 6, 12, 18, 11, 255, 255, 255, 255);
fill_rect(s, 2, 13, 3, 6, 55, 50, 40, 255); /* bumper */
fill_rect(s, 3, 14, 1, 4, 90, 80, 55, 255);
fill_rect(s, 4, 14, 3, 4, 40, 38, 32, 255); /* grille */
line(s, 4, 15, 6, 15, 70, 65, 55, 255);
line(s, 4, 17, 6, 17, 70, 65, 55, 255);
disc(s, 4, 12, 2, 220, 200, 80, 255); /* headlight L */
disc(s, 4, 20, 2, 220, 200, 80, 255); /* headlight R */
fill_rect(s, 5, 8, 7, 5, 190, 215, 235, 255); /* cab glass */
fill_rect(s, 6, 9, 5, 3, 160, 190, 220, 255);
fill_rect(s, 12, 12, 2, 10, 200, 200, 205, 255); /* side door seam */
fill_rect(s, 13, 13, 1, 8, 170, 170, 175, 255);
fill_rect(s, 20, 13, 4, 8, 230, 230, 235, 255); /* rear panel */
fill_rect(s, 21, 14, 2, 6, 210, 210, 215, 255);
fill_rect(s, 4, 10, 2, 2, 50, 48, 42, 255); /* mirror L */
fill_rect(s, 4, 20, 2, 2, 50, 48, 42, 255); /* mirror R */
fill_rect(s, 24, 18, 3, 2, 40, 38, 32, 255); /* exhaust */
fill_rect(s, 25, 17, 2, 1, 70, 65, 55, 255);
fill_rect(s, 8, 3, 14, 3, 240, 40, 40, 255); /* light bar */
fill_rect(s, 10, 2, 10, 2, 255, 80, 80, 255);
fill_rect(s, 11, 1, 3, 2, 255, 220, 80, 255); /* amber beacon */
fill_rect(s, 16, 1, 3, 2, 80, 180, 255, 255); /* blue beacon */
fill_rect(s, 18, 11, 6, 3, 200, 40, 40, 255); /* stretcher cue */
fill_rect(s, 19, 12, 4, 1, 255, 200, 200, 255);
disc(s, 9, 24, 5, ok, og, ob, 255);
disc(s, 21, 24, 5, ok, og, ob, 255);
disc(s, 9, 24, 4, tr, tg, tb, 255);
disc(s, 21, 24, 4, tr, tg, tb, 255);
disc(s, 9, 24, 2, 90, 85, 75, 255);
disc(s, 21, 24, 2, 90, 85, 75, 255);
disc(s, 15, 10, 7, 230, 35, 35, 255);
fill_rect(s, 13, 4, 4, 12, 255, 255, 255, 255);
fill_rect(s, 9, 8, 12, 4, 255, 255, 255, 255);
break;
default:
disc(s, 15, 15, 10, ok, og, ob, 255);
disc(s, 15, 15, 8, base.r, base.g, base.b, 255);
break;
}
SDL_Texture *tex = SDL_CreateTextureFromSurface(r, s);
SDL_FreeSurface(s);
return tex;
}
/* ---------------- building sprites ---------------- */
/* Bright concrete pad + BT_* interiors (parity with snapshot draw_bld). */
SDL_Texture *sprites_make_bld(SDL_Renderer *r, BuildingType t, Faction f) {
int w = bld_def(t)->w, h = bld_def(t)->h;
int W = w * TILE, H = h * TILE;
SDL_Surface *s = new_surf(W, H);
SDL_Color base = faction_color(f);
SDL_Color dark = darken(base, 0.5f);
SDL_Color lite = lighten(base, 0.35f);
const Uint8 ok = 22, og = 20, ob = 16;
const Uint8 wall = 205, wall2 = 175;
/* Bright concrete pad on arid sand */
fill_rect(s, 0, 0, W, H, ok, og, ob, 255);
fill_rect(s, 2, 2, W - 4, H - 4, 210, 185, 130, 255);
fill_rect(s, 4, 4, W - 8, H - 8, wall2, (Uint8)(wall2 - 18), (Uint8)(wall2 - 45), 255);
fill_rect(s, 5, 5, W - 10, H - 10, wall, (Uint8)(wall - 22), (Uint8)(wall - 55), 255);
fill_rect(s, 5, 5, W - 10, 6, (Uint8)(wall + 30), (Uint8)(wall + 10), (Uint8)(wall - 20), 255);
switch (t) {
case BT_BASE:
if (f == FACTION_EVOLVED) {
/* hive: lobes + membrane ridges + spine + pit eye (KKND HQ read) */
disc(s, 14, 18, 14, ok, og, ob, 255);
disc(s, 14, 18, 12, base.r, base.g, base.b, 255);
disc(s, W - 14, 18, 14, ok, og, ob, 255);
disc(s, W - 14, 18, 12, base.r, base.g, base.b, 255);
disc(s, 16, H - 16, 12, ok, og, ob, 255);
disc(s, 16, H - 16, 10, base.r, base.g, base.b, 255);
disc(s, W - 16, H - 16, 12, ok, og, ob, 255);
disc(s, W - 16, H - 16, 10, base.r, base.g, base.b, 255);
disc(s, W/2, H/2, 16, ok, og, ob, 255);
disc(s, W/2, H/2, 14, base.r, base.g, base.b, 255);
/* membrane ridges between lobes */
line(s, 18, 20, W/2 - 8, H/2 - 4, ok, og, ob, 255);
line(s, W - 18, 20, W/2 + 8, H/2 - 4, ok, og, ob, 255);
line(s, 18, H - 18, W/2 - 6, H/2 + 6, ok, og, ob, 255);
line(s, W - 18, H - 18, W/2 + 6, H/2 + 6, ok, og, ob, 255);
/* dorsal spine + tendrils */
fill_rect(s, W/2 - 2, 4, 4, H/2 - 8, ok, og, ob, 255);
fill_rect(s, W/2 - 1, 5, 2, H/2 - 10, 90, 40, 55, 255);
line(s, W/2, 8, W/2 - 10, 18, 70, 30, 45, 255);
line(s, W/2, 8, W/2 + 10, 18, 70, 30, 45, 255);
/* dark pit + glowing eye */
disc(s, W/2, H/2, 8, 28, 18, 22, 255);
disc(s, W/2, H/2, 5, 60, 20, 30, 255);
disc(s, W/2, H/2, 3, 220, 60, 90, 255);
disc(s, W/2, H/2, 1, 255, 180, 200, 255);
ring(s, W/2, H/2, 10, 2, 50, 25, 35, 255); /* pit rim */
/* extra blisters */
disc(s, W/2 - 10, 10, 5, lite.r, lite.g, lite.b, 255);
disc(s, W/2 + 12, H - 12, 4, lite.r, lite.g, lite.b, 255);
disc(s, 10, H/2 + 2, 3, lite.r, lite.g, lite.b, 255);
disc(s, W - 10, H/2 - 4, 3, lite.r, lite.g, lite.b, 255);
disc(s, W/2 + 8, 14, 2, 180, 70, 100, 255);
} else {
/* Survivors HQ: towers + walkways + dome + dish + entry (KKND HQ read) */
fill_rect(s, 4, 4, 14, 14, ok, og, ob, 255);
fill_rect(s, 6, 6, 10, 10, base.r, base.g, base.b, 255);
fill_rect(s, W - 18, 4, 14, 14, ok, og, ob, 255);
fill_rect(s, W - 16, 6, 10, 10, base.r, base.g, base.b, 255);
fill_rect(s, 4, H - 18, 14, 14, ok, og, ob, 255);
fill_rect(s, 6, H - 16, 10, 10, base.r, base.g, base.b, 255);
fill_rect(s, W - 18, H - 18, 14, 14, ok, og, ob, 255);
fill_rect(s, W - 16, H - 16, 10, 10, base.r, base.g, base.b, 255);
/* tower windows + corner lights */
fill_rect(s, 8, 8, 3, 3, 200, 230, 255, 255);
fill_rect(s, W - 13, 8, 3, 3, 200, 230, 255, 255);
fill_rect(s, 8, H - 13, 3, 3, 200, 230, 255, 255);
fill_rect(s, W - 13, H - 13, 3, 3, 200, 230, 255, 255);
disc(s, 7, 5, 2, 255, 220, 80, 255);
disc(s, W - 7, 5, 2, 255, 220, 80, 255);
/* courtyard body + roof band */
fill_rect(s, 14, 14, W - 28, H - 28, ok, og, ob, 255);
fill_rect(s, 16, 16, W - 32, H - 32, base.r, base.g, base.b, 255);
fill_rect(s, 18, 18, W - 36, 8, lite.r, lite.g, lite.b, 255);
/* walkways between towers */
fill_rect(s, 16, 8, W - 32, 3, 90, 85, 70, 255);
fill_rect(s, 16, H - 11, W - 32, 3, 90, 85, 70, 255);
fill_rect(s, 8, 16, 3, H - 32, 90, 85, 70, 255);
fill_rect(s, W - 11, 16, 3, H - 32, 90, 85, 70, 255);
/* command dome + mast + radar dish */
disc(s, W/2, H/2 - 2, 10, ok, og, ob, 255);
disc(s, W/2, H/2 - 2, 8, lite.r, lite.g, lite.b, 255);
disc(s, W/2, H/2 - 2, 4, 255, 250, 180, 255);
fill_rect(s, W/2 - 2, 2, 4, H/2 - 6, 200, 180, 60, 255);
fill_rect(s, W/2 - 6, 2, 12, 3, 220, 210, 80, 255);
disc(s, W/2 + 8, 8, 5, ok, og, ob, 255); /* dish */
disc(s, W/2 + 8, 8, 3, 180, 200, 220, 255);
line(s, W/2 + 2, 6, W/2 + 8, 8, 160, 150, 100, 255);
/* entry bunker + blast doors */
fill_rect(s, W/2 - 8, H - 14, 16, 8, ok, og, ob, 255);
fill_rect(s, W/2 - 6, H - 12, 12, 6, 40, 38, 34, 255);
fill_rect(s, W/2 - 4, H - 11, 3, 4, 70, 65, 55, 255);
fill_rect(s, W/2 + 1, H - 11, 3, 4, 70, 65, 55, 255);
/* side annex slits */
fill_rect(s, 18, H/2 + 2, 6, 4, 160, 200, 230, 255);
fill_rect(s, W - 24, H/2 + 2, 6, 4, 160, 200, 230, 255);
}
break;
case BT_WARFACTORY:
/* hangar + crane + bay + office/chimney/ramp (KKND factory densify) */
fill_rect(s, 4, 6, W - 8, H - 12, ok, og, ob, 255);
fill_rect(s, 6, 8, W - 12, H - 16, base.r, base.g, base.b, 255);
fill_rect(s, 8, 10, W - 16, 12, lite.r, lite.g, lite.b, 255); /* roof ridge */
fill_rect(s, 10, 12, 5, 5, 55, 50, 42, 255); /* ridge vents */
fill_rect(s, W/2 - 8, 12, 5, 5, 55, 50, 42, 255);
fill_rect(s, W/2 + 3, 12, 5, 5, 55, 50, 42, 255);
fill_rect(s, W - 15, 12, 5, 5, 55, 50, 42, 255);
/* corner bracing + rivets */
fill_rect(s, 5, 7, 3, 3, 70, 65, 55, 255);
fill_rect(s, W - 8, 7, 3, 3, 70, 65, 55, 255);
fill_rect(s, 5, H - 14, 3, 3, 70, 65, 55, 255);
fill_rect(s, W - 8, H - 14, 3, 3, 70, 65, 55, 255);
fill_rect(s, 6, 8, 1, 1, 40, 38, 32, 255); /* rivet TL */
fill_rect(s, W - 7, 8, 1, 1, 40, 38, 32, 255);
fill_rect(s, 6, H - 13, 1, 1, 40, 38, 32, 255);
fill_rect(s, W - 7, H - 13, 1, 1, 40, 38, 32, 255);
/* upper office strip + windows */
fill_rect(s, 10, 14, W - 28, 6, dark.r, dark.g, dark.b, 255);
fill_rect(s, 12, 15, 3, 3, 160, 200, 230, 255);
fill_rect(s, 17, 15, 3, 3, 150, 190, 220, 255);
fill_rect(s, 22, 15, 3, 3, 170, 210, 235, 255);
fill_rect(s, W/2 - 2, 15, 3, 3, 155, 195, 225, 255);
/* chimney + smoke puff */
fill_rect(s, W/2 + 8, 4, 4, 10, ok, og, ob, 255);
fill_rect(s, W/2 + 9, 5, 2, 8, 55, 50, 45, 255);
disc(s, W/2 + 10, 3, 3, 90, 88, 85, 255);
disc(s, W/2 + 12, 2, 2, 110, 108, 105, 255);
/* side workshop annex + tool rack */
fill_rect(s, 4, H/2 - 4, 10, H/2 - 6, ok, og, ob, 255);
fill_rect(s, 5, H/2 - 2, 8, H/2 - 10, dark.r, dark.g, dark.b, 255);
fill_rect(s, 6, H/2, 6, 4, 90, 80, 55, 255); /* window slit */
fill_rect(s, 3, H - 18, 3, 8, 60, 55, 45, 255); /* tool rack */
fill_rect(s, 3, H - 17, 1, 2, 140, 120, 70, 255);
fill_rect(s, 5, H - 16, 1, 3, 120, 110, 90, 255);
/* side exhaust stacks */
fill_rect(s, W - 6, H/2 + 2, 3, 8, ok, og, ob, 255);
fill_rect(s, W - 5, H/2 + 3, 1, 6, 45, 42, 38, 255);
disc(s, W - 4, H/2 + 1, 2, 80, 78, 72, 255);
/* overhead crane mast + jib + cable/hook */
fill_rect(s, W - 14, 4, 6, H - 18, ok, og, ob, 255);
fill_rect(s, W - 13, 5, 4, H - 20, 95, 88, 70, 255);
fill_rect(s, 14, 6, W - 28, 4, ok, og, ob, 255);
fill_rect(s, 15, 7, W - 30, 2, 120, 110, 85, 255);
line(s, 18, 10, 18, 22, 70, 65, 50, 255);
line(s, 19, 10, 19, 26, 55, 50, 40, 255); /* cable */
disc(s, 18, 24, 3, 80, 75, 55, 255); /* hoist block */
fill_rect(s, 17, 27, 3, 2, 100, 90, 60, 255); /* hook */
fill_rect(s, W - 12, 3, 2, 2, 220, 200, 80, 255); /* floodlight */
fill_rect(s, W - 11, 2, 1, 3, 90, 85, 70, 255); /* antenna stub */
/* segmented bay doors + hazard + panels */
fill_rect(s, 12, H - 30, W - 28, 20, ok, og, ob, 255);
fill_rect(s, 14, H - 28, W - 32, 16, 32, 32, 38, 255);
fill_rect(s, 14, H - 28, W - 32, 2, 200, 160, 40, 255); /* hazard top */
fill_rect(s, 14, H - 14, W - 32, 2, 200, 160, 40, 255); /* hazard bot */
line(s, W/2 - 6, H - 28, W/2 - 6, H - 12, 70, 68, 60, 255);
line(s, W/2, H - 28, W/2, H - 12, 70, 68, 60, 255);
line(s, W/2 + 6, H - 28, W/2 + 6, H - 12, 70, 68, 60, 255);
line(s, 14, H - 20, W - 18, H - 20, 55, 52, 48, 255);
fill_rect(s, 16, H - 24, 4, 3, 45, 44, 40, 255); /* door panel */
fill_rect(s, W/2 + 2, H - 24, 4, 3, 45, 44, 40, 255);
fill_rect(s, W - 22, H - 24, 4, 3, 45, 44, 40, 255);
/* ramp lip + rails/tracks */
fill_rect(s, 10, H - 10, W - 20, 5, 50, 48, 42, 255);
fill_rect(s, 12, H - 9, W - 24, 2, 90, 75, 45, 255);
line(s, 14, H - 8, 14, H - 5, 70, 65, 50, 255);
line(s, W - 16, H - 8, W - 16, H - 5, 70, 65, 50, 255);
line(s, 14, H - 6, W - 16, H - 6, 60, 55, 42, 255); /* track */
line(s, 14, H - 5, W - 16, H - 5, 55, 50, 38, 255);
break;
case BT_REFINERY:
/* dense oil-field: pad, derrick, pumpjack, twin tanks, pipes, hopper (KKND) */
fill_rect(s, 3, H - 12, W - 6, 10, ok, og, ob, 255); /* slab */
fill_rect(s, 5, H - 10, W - 10, 6, 70, 62, 48, 255);
fill_rect(s, 6, H - 9, 2, 2, 35, 32, 28, 255); /* pad bolt L */
fill_rect(s, W - 8, H - 9, 2, 2, 35, 32, 28, 255); /* pad bolt R */
fill_rect(s, W/2 - 2, H - 9, 2, 2, 35, 32, 28, 255); /* pad bolt C */
fill_rect(s, 4, H - 4, W - 8, 2, 45, 38, 28, 255); /* curb */
/* latticed derrick mast + braces */
fill_rect(s, W/2 - 3, 4, 6, H - 18, ok, og, ob, 255);
fill_rect(s, W/2 - 2, 5, 4, H - 20, 95, 85, 65, 255);
fill_rect(s, W/2 - 4, 12, 8, 2, 55, 48, 38, 255); /* cross brace */
fill_rect(s, W/2 - 4, 26, 8, 2, 55, 48, 38, 255);
fill_rect(s, W/2 - 4, 40, 8, 2, 55, 48, 38, 255);
line(s, W/2 - 6, 10, W/2 + 6, 22, 55, 48, 38, 255);
line(s, W/2 + 6, 10, W/2 - 6, 22, 55, 48, 38, 255);
line(s, W/2 - 6, 24, W/2 + 6, 36, 55, 48, 38, 255);
line(s, W/2 + 6, 24, W/2 - 6, 36, 55, 48, 38, 255);
line(s, W/2 - 6, 38, W/2 + 6, H - 18, 55, 48, 38, 255);
line(s, W/2 + 6, 38, W/2 - 6, H - 18, 55, 48, 38, 255);
line(s, W/2 - 5, 8, W/2 - 5, H - 16, 40, 36, 30, 255);
line(s, W/2 + 5, 8, W/2 + 5, H - 16, 40, 36, 30, 255);
fill_rect(s, W/2 - 7, 2, 14, 5, ok, og, ob, 255); /* crown */
fill_rect(s, W/2 - 5, 3, 10, 3, 200, 170, 80, 255); /* beacon */
fill_rect(s, W/2 - 1, 1, 2, 2, 255, 230, 120, 255); /* beacon tip */
/* pumpjack horse-head (left of mast) */
fill_rect(s, 8, H/2 - 2, 4, H/2 - 8, ok, og, ob, 255);
fill_rect(s, 9, H/2, 2, H/2 - 12, 90, 80, 60, 255);
fill_rect(s, 6, H/2 - 6, 14, 4, ok, og, ob, 255);
fill_rect(s, 7, H/2 - 5, 12, 2, 110, 95, 70, 255);
fill_rect(s, 10, H/2 - 8, 3, 3, 70, 60, 45, 255); /* pivot block */
disc(s, 8, H/2 - 8, 4, ok, og, ob, 255); /* horse head */
disc(s, 8, H/2 - 8, 2, 130, 110, 80, 255);
line(s, 10, H/2 - 4, W/2 - 4, 16, 80, 70, 50, 255); /* bridle cable */
fill_rect(s, 7, H - 14, 6, 3, 50, 44, 34, 255); /* pump base */
/* gantry arm + walkway + bracing toward hopper */
fill_rect(s, W/2 + 2, 14, W/2 - 10, 4, ok, og, ob, 255);
fill_rect(s, W/2 + 3, 15, W/2 - 12, 2, 120, 100, 60, 255);
fill_rect(s, W/2 + 4, 18, W/2 - 16, 2, 70, 60, 45, 255); /* catwalk */
fill_rect(s, W/2 + 6, 20, 2, 8, 60, 52, 40, 255); /* catwalk post */
fill_rect(s, W - 18, 20, 2, 8, 60, 52, 40, 255);
fill_rect(s, W/2 + 8, 22, W/2 - 28, 1, 90, 75, 50, 255); /* rail */
line(s, W/2 + 4, 18, W - 12, H - 22, 90, 75, 50, 255);
/* hopper / processing shed + windows/door/hazard */
fill_rect(s, W - 24, H - 32, 18, 18, ok, og, ob, 255);
fill_rect(s, W - 22, H - 30, 14, 14, base.r, base.g, base.b, 255);
fill_rect(s, W - 20, H - 28, 10, 6, 140, 110, 55, 255);
fill_rect(s, W - 18, H - 26, 3, 3, 180, 220, 255, 255); /* window */
fill_rect(s, W - 13, H - 26, 3, 3, 180, 220, 255, 255);
fill_rect(s, W - 18, H - 22, 3, 3, 160, 200, 240, 255); /* window row2 */
fill_rect(s, W - 13, H - 22, 3, 3, 160, 200, 240, 255);
fill_rect(s, W - 16, H - 18, 4, 4, 40, 36, 30, 255); /* chute */
fill_rect(s, W - 21, H - 16, 5, 6, 35, 32, 38, 255); /* door */
fill_rect(s, W - 21, H - 16, 5, 1, 200, 160, 40, 255); /* hazard */
fill_rect(s, W - 19, H - 13, 1, 2, 180, 170, 90, 255); /* handle */
fill_rect(s, W - 12, H - 34, 4, 3, 90, 80, 55, 255); /* roof vent */
/* twin scrap tanks + bands/rivets */
disc(s, 14, H - 18, 9, ok, og, ob, 255);
disc(s, 14, H - 18, 7, 200, 165, 85, 255);
ring(s, 14, H - 18, 4, 2, 90, 70, 45, 255);
fill_rect(s, 8, H - 20, 12, 1, 120, 95, 50, 255); /* tank band */
fill_rect(s, 8, H - 16, 12, 1, 110, 88, 45, 255);
fill_rect(s, 10, H - 22, 2, 2, 90, 75, 45, 255); /* rivet */
fill_rect(s, 16, H - 14, 2, 2, 90, 75, 45, 255);
disc(s, 28, H - 16, 7, ok, og, ob, 255);
disc(s, 28, H - 16, 5, 180, 150, 75, 255);
ring(s, 28, H - 16, 3, 1, 80, 60, 40, 255);
fill_rect(s, 23, H - 18, 10, 1, 100, 80, 40, 255); /* tank2 band */
fill_rect(s, 25, H - 14, 2, 2, 85, 70, 40, 255); /* rivet */
fill_rect(s, 12, H - 28, 4, 3, ok, og, ob, 255); /* tank cap L */
fill_rect(s, 26, H - 24, 4, 2, ok, og, ob, 255); /* tank cap R */
/* pipe runs tank→mast→hopper + valves */
line(s, 20, H - 16, W/2 - 4, H - 12, 110, 90, 50, 255);
line(s, 28, H - 14, W/2 - 2, H - 14, 100, 85, 45, 255);
line(s, W/2 + 4, H - 14, W - 20, H - 20, 100, 85, 45, 255);
line(s, 14, H - 26, 14, H - 20, 100, 85, 45, 255); /* riser */
fill_rect(s, W/2 - 1, H - 16, 3, 4, 80, 70, 50, 255); /* valve */
fill_rect(s, W/2 - 2, H - 15, 5, 1, 200, 160, 40, 255); /* valve hazard */
fill_rect(s, 18, H - 15, 3, 3, 75, 65, 48, 255); /* elbow flange */
fill_rect(s, W - 22, H - 21, 3, 3, 75, 65, 48, 255); /* hopper flange */
/* oil stain + drip pans */
disc(s, W/2 - 8, H - 6, 4, 40, 32, 20, 255);
disc(s, W/2 + 6, H - 5, 3, 35, 28, 18, 255);
fill_rect(s, 10, H - 8, 8, 2, 30, 24, 16, 255); /* drip pan */
fill_rect(s, 24, H - 7, 6, 2, 28, 22, 14, 255);
break;
case BT_POWER:
/* denser KKND plant: pad, twin cooling, reactor, stack, switchyard, steam */
fill_rect(s, 2, H - 11, W - 4, 9, ok, og, ob, 255); /* slab */
fill_rect(s, 3, H - 9, W - 6, 6, 55, 50, 42, 255); /* pad */
fill_rect(s, 4, H - 8, 2, 2, 35, 32, 28, 255); /* pad bolt L */
fill_rect(s, W/2 - 1, H - 8, 2, 2, 35, 32, 28, 255); /* pad bolt C */
fill_rect(s, W - 6, H - 8, 2, 2, 35, 32, 28, 255); /* pad bolt R */
fill_rect(s, 3, H - 4, W - 6, 2, 45, 40, 32, 255); /* curb */
/* left cooling tower (taller cone + bands) */
fill_rect(s, 3, 7, 11, H - 18, ok, og, ob, 255);
fill_rect(s, 4, 8, 9, H - 20, 95, 145, 195, 255);
fill_rect(s, 5, 5, 7, 5, ok, og, ob, 255);
fill_rect(s, 6, 4, 5, 4, 70, 120, 170, 255); /* rim */
fill_rect(s, 5, 14, 1, H - 28, 70, 110, 150, 255); /* cooling fin L */
fill_rect(s, 11, 14, 1, H - 28, 70, 110, 150, 255);
fill_rect(s, 5, 18, 7, 1, 80, 125, 170, 255); /* band */
fill_rect(s, 5, 28, 7, 1, 75, 118, 162, 255);
fill_rect(s, 6, 22, 2, 2, 180, 220, 255, 255); /* port window */
disc(s, 8, 3, 3, 240, 248, 255, 255); /* steam puff */
disc(s, 6, 1, 2, 220, 235, 250, 255);
disc(s, 10, 2, 2, 230, 240, 252, 255);
disc(s, 9, 5, 2, 210, 228, 245, 255);
/* right cooling tower */
fill_rect(s, W - 14, 9, 11, H - 20, ok, og, ob, 255);
fill_rect(s, W - 13, 10, 9, H - 22, 85, 135, 185, 255);
fill_rect(s, W - 12, 7, 7, 4, ok, og, ob, 255);
fill_rect(s, W - 11, 6, 5, 3, 65, 115, 165, 255);
fill_rect(s, W - 12, 15, 1, H - 30, 65, 105, 145, 255);
fill_rect(s, W - 6, 15, 1, H - 30, 65, 105, 145, 255);
fill_rect(s, W - 12, 20, 7, 1, 70, 112, 155, 255); /* band */
fill_rect(s, W - 12, 30, 7, 1, 68, 108, 150, 255);
fill_rect(s, W - 10, 24, 2, 2, 170, 210, 245, 255); /* port */
disc(s, W - 9, 4, 3, 235, 245, 255, 255);
disc(s, W - 7, 2, 2, 210, 230, 250, 255);
disc(s, W - 11, 3, 2, 225, 238, 250, 255);
disc(s, W - 8, 6, 2, 200, 220, 240, 255);
/* central reactor block + glow + panels */
fill_rect(s, W/2 - 6, H/2 - 5, 12, H/2 - 1, ok, og, ob, 255);
fill_rect(s, W/2 - 5, H/2 - 3, 10, H/2 - 5, 55, 95, 150, 255);
fill_rect(s, W/2 - 4, H/2 - 1, 3, 3, 255, 200, 40, 255); /* warn L */
fill_rect(s, W/2 + 1, H/2 - 1, 3, 3, 255, 200, 40, 255); /* warn R */
fill_rect(s, W/2 - 3, H/2 + 4, 2, 2, 40, 70, 110, 255); /* panel */
fill_rect(s, W/2 + 1, H/2 + 4, 2, 2, 40, 70, 110, 255);
fill_rect(s, W/2 - 2, H/2 + 8, 4, 2, 200, 160, 40, 255); /* hazard belt */
disc(s, W/2, H/2 + 2, 4, 120, 200, 255, 255);
disc(s, W/2, H/2 + 2, 2, 250, 252, 255, 255);
ring(s, W/2, H/2 + 2, 5, 1, 90, 160, 220, 255);
line(s, W/2, 8, W/2, H - 10, 200, 230, 250, 255);
line(s, 8, H/2 + 2, W - 8, H/2 + 2, 180, 220, 245, 255);
/* exhaust stack + plume */
fill_rect(s, W/2 + 6, 6, 4, H/2 - 8, ok, og, ob, 255);
fill_rect(s, W/2 + 7, 7, 2, H/2 - 12, 60, 58, 52, 255);
fill_rect(s, W/2 + 6, 4, 4, 3, 50, 48, 42, 255); /* stack cap */
disc(s, W/2 + 8, 2, 3, 180, 190, 200, 255); /* smoke */
disc(s, W/2 + 9, 0, 2, 160, 170, 180, 255);
/* switchyard: transformers + bus + insulators */
fill_rect(s, W/2 - 10, H - 16, 7, 6, ok, og, ob, 255);
fill_rect(s, W/2 - 9, H - 15, 5, 4, 45, 42, 36, 255);
fill_rect(s, W/2 + 3, H - 15, 6, 5, ok, og, ob, 255);
fill_rect(s, W/2 + 4, H - 14, 4, 3, 50, 48, 40, 255);
fill_rect(s, W/2 - 8, H - 17, 2, 2, 90, 85, 70, 255); /* insulator */
fill_rect(s, W/2 + 5, H - 16, 2, 2, 90, 85, 70, 255);
fill_rect(s, W/2 - 1, H - 18, 3, 2, 70, 68, 58, 255); /* bus bar */
line(s, W/2 - 6, H - 16, W/2 - 6, H/2 + 6, 90, 85, 70, 255);
line(s, W/2 + 5, H - 14, W - 10, H/2 + 4, 80, 75, 60, 255);
line(s, W/2 + 2, H - 17, W/2 + 7, H/2 + 8, 85, 80, 65, 255);
/* control booth + fence */
fill_rect(s, 14, H - 20, 8, 8, ok, og, ob, 255);
fill_rect(s, 15, H - 19, 6, 6, 40, 55, 70, 255);
fill_rect(s, 16, H - 18, 2, 2, 180, 220, 255, 255); /* booth window */
fill_rect(s, 19, H - 18, 2, 2, 160, 200, 240, 255);
fill_rect(s, 17, H - 15, 2, 3, 35, 32, 38, 255); /* door */
fill_rect(s, 2, H - 13, 2, 4, 50, 48, 40, 255); /* fence post L */
fill_rect(s, W/2 - 12, H - 13, 2, 4, 50, 48, 40, 255);
fill_rect(s, W - 4, H - 13, 2, 4, 50, 48, 40, 255); /* fence post R */
line(s, 3, H - 12, W - 4, H - 12, 60, 55, 45, 255); /* fence rail */
break;
case BT_TURRET:
/* denser KKND turret: berm+bunker+cupola+barrel+radar+coax */
fill_rect(s, 1, H - 8, W - 2, 6, 70, 58, 42, 255); /* berm/sandbag ring */
fill_rect(s, 2, H - 7, 4, 4, 95, 82, 60, 255); /* bag L */
fill_rect(s, W - 6, H - 7, 4, 4, 95, 82, 60, 255); /* bag R */
fill_rect(s, W/2 - 4, H - 6, 8, 3, 85, 72, 52, 255); /* bag mid */
fill_rect(s, 2, H - 16, W - 4, 12, ok, og, ob, 255); /* bunker hull */
fill_rect(s, 3, H - 14, W - 6, 9, 48, 44, 38, 255); /* bunker slab */
fill_rect(s, 3, H - 15, W - 6, 2, 90, 82, 68, 255); /* top lip */
fill_rect(s, 4, H - 13, 5, 5, 70, 65, 55, 255); /* armor plate L */
fill_rect(s, W - 9, H - 13, 5, 5, 70, 65, 55, 255); /* armor plate R */
fill_rect(s, W/2 - 6, H - 10, 12, 4, 35, 32, 28, 255); /* embrasure */
fill_rect(s, W/2 - 5, H - 9, 10, 2, 20, 18, 16, 255); /* slit */
fill_rect(s, 5, H - 8, 2, 2, 28, 26, 22, 255); /* bolt L */
fill_rect(s, 8, H - 8, 2, 2, 28, 26, 22, 255);
fill_rect(s, W - 10, H - 8, 2, 2, 28, 26, 22, 255); /* bolt R */
fill_rect(s, W - 7, H - 8, 2, 2, 28, 26, 22, 255);
fill_rect(s, 2, H - 4, 3, 3, 55, 48, 38, 255); /* corner block L */
fill_rect(s, W - 5, H - 4, 3, 3, 55, 48, 38, 255); /* corner block R */
/* dual ammo crates + feed strut */
fill_rect(s, 2, H/2 + 1, 7, 9, ok, og, ob, 255);
fill_rect(s, 3, H/2 + 2, 5, 7, 55, 50, 42, 255);
fill_rect(s, 4, H/2 + 3, 3, 2, 200, 160, 40, 255); /* hazard stripe */
fill_rect(s, W - 9, H/2 + 2, 6, 8, ok, og, ob, 255);
fill_rect(s, W - 8, H/2 + 3, 4, 6, 50, 46, 38, 255);
fill_rect(s, W - 7, H/2 + 4, 2, 2, 200, 160, 40, 255);
line(s, 6, H/2 + 2, W/2 - 4, H/2, 40, 36, 30, 255);
line(s, W - 6, H/2 + 3, W/2 + 4, H/2 + 1, 40, 36, 30, 255);
/* access ladder */
fill_rect(s, 1, H/2 - 2, 2, 10, 60, 55, 45, 255);
fill_rect(s, 1, H/2, 3, 1, 90, 85, 70, 255);
fill_rect(s, 1, H/2 + 3, 3, 1, 90, 85, 70, 255);
fill_rect(s, 1, H/2 + 6, 3, 1, 90, 85, 70, 255);
/* ringed cupola + viewports */
disc(s, W/2, H/2, W/3 + 3, ok, og, ob, 255);
disc(s, W/2, H/2, W/3 + 1, base.r, base.g, base.b, 255);
ring(s, W/2, H/2, W/4 + 2, 2, dark.r, dark.g, dark.b, 255);
ring(s, W/2, H/2, W/4 - 1, 1, 35, 32, 28, 255);
disc(s, W/2, H/2, W/5, lite.r, lite.g, lite.b, 255);
disc(s, W/2, H/2 - 1, 3, 35, 32, 28, 255); /* hatch */
fill_rect(s, W/2 - 1, H/2 - 3, 2, 2, 20, 18, 16, 255); /* hatch handle */
fill_rect(s, W/2 - 6, H/2 - 1, 3, 2, 25, 22, 18, 255); /* viewport L */
fill_rect(s, W/2 + 3, H/2 - 1, 3, 2, 25, 22, 18, 255); /* viewport R */
disc(s, W/2 - 5, H/2 + 4, 1, 90, 85, 70, 255); /* rivet */
disc(s, W/2 + 5, H/2 + 4, 1, 90, 85, 70, 255);
disc(s, W/2 - 2, H/2 + 5, 1, 90, 85, 70, 255);
disc(s, W/2 + 2, H/2 + 5, 1, 90, 85, 70, 255);
/* main barrel shroud + bands + rail */
fill_rect(s, W/2 + 1, H/2 - 4, 14, 7, ok, og, ob, 255);
fill_rect(s, W/2 + 2, H/2 - 3, 13, 5, 40, 36, 30, 255);
fill_rect(s, W/2 + 3, H/2 - 2, 12, 3, 55, 50, 42, 255); /* bore highlight */
fill_rect(s, W/2 + 4, H/2 - 4, 2, 7, 70, 62, 50, 255); /* band */
fill_rect(s, W/2 + 8, H/2 - 4, 2, 7, 70, 62, 50, 255);
fill_rect(s, W/2 + 12, H/2 - 4, 2, 7, 70, 62, 50, 255);
fill_rect(s, W/2 + 2, H/2 + 3, 10, 2, 30, 28, 24, 255); /* recoil rail */
line(s, W/2, H/2, W/2 + 15, H/2 - 11, 28, 26, 22, 255);
line(s, W/2 + 1, H/2 + 1, W/2 + 15, H/2 - 10, 55, 48, 38, 255);
disc(s, W/2 + 14, H/2 - 11, 2, 255, 200, 80, 255); /* muzzle tip */
fill_rect(s, W/2 + 13, H/2 - 12, 3, 1, 255, 220, 120, 255); /* flash tip */
/* coax MG under barrel */
fill_rect(s, W/2 + 3, H/2 + 1, 8, 2, 45, 42, 36, 255);
fill_rect(s, W/2 + 10, H/2 + 1, 3, 1, 30, 28, 24, 255);
/* radar dish + mast + cable */
fill_rect(s, W/2 - 2, H/2 - 10, 3, 5, 50, 48, 40, 255); /* mast */
disc(s, W/2 - 1, H/2 - 11, 4, 90, 88, 78, 255);
disc(s, W/2 - 1, H/2 - 11, 2, 40, 38, 34, 255);
line(s, W/2 - 1, H/2 - 7, W/2 - 6, H/2 - 2, 60, 55, 45, 255);
/* searchlight + flood */
fill_rect(s, W/2 - 9, H/2 - 7, 5, 4, 200, 195, 160, 255);
fill_rect(s, W/2 - 8, H/2 - 6, 3, 2, 255, 250, 210, 255);
disc(s, W/2 - 7, H/2 - 8, 2, 255, 250, 210, 255);
fill_rect(s, W - 6, H/2 - 5, 3, 2, 220, 210, 160, 255); /* side flood */
break;
case BT_WALL:
/* denser fort: battlement, gate, scars, rubble (KKND fort read) */
fill_rect(s, 0, 4, W, H - 4, ok, og, ob, 255); /* outer hull */
fill_rect(s, 1, 6, W - 2, H - 8, 165, 145, 110, 255); /* face */
fill_rect(s, 2, 7, W - 4, H - 12, 150, 132, 100, 255); /* inner face */
fill_rect(s, 2, H - 6, W - 4, 4, 90, 78, 58, 255); /* plinth */
fill_rect(s, 3, H - 5, W - 6, 2, 70, 60, 48, 255); /* plinth shadow */
fill_rect(s, 1, H - 5, 3, 3, 70, 60, 45, 255); /* corner stone L */
fill_rect(s, W - 4, H - 5, 3, 3, 70, 60, 45, 255); /* corner stone R */
fill_rect(s, W/2 - 2, H - 4, 4, 2, 55, 48, 38, 255); /* threshold */
/* thick merlons + caps + 4th tooth */
fill_rect(s, 1, 1, 7, 10, ok, og, ob, 255);
fill_rect(s, 2, 2, 5, 8, 195, 175, 140, 255);
fill_rect(s, 3, 1, 3, 2, 220, 200, 160, 255); /* merlon cap L */
fill_rect(s, W/2 - 5, 1, 4, 9, ok, og, ob, 255); /* merlon mid-L */
fill_rect(s, W/2 - 4, 2, 2, 7, 200, 180, 145, 255);
fill_rect(s, W/2 - 1, 1, 7, 10, ok, og, ob, 255);
fill_rect(s, W/2, 2, 5, 8, 200, 180, 145, 255);
fill_rect(s, W/2 + 1, 1, 3, 2, 220, 200, 160, 255); /* merlon cap mid */
fill_rect(s, W - 8, 1, 7, 10, ok, og, ob, 255);
fill_rect(s, W - 7, 2, 5, 8, 190, 170, 135, 255);
fill_rect(s, W - 6, 1, 3, 2, 215, 195, 155, 255); /* merlon cap R */
fill_rect(s, 2, 10, W - 4, 3, 215, 195, 155, 255); /* coping */
fill_rect(s, 2, 11, W - 4, 1, 120, 105, 80, 255); /* coping shadow */
fill_rect(s, 4, 9, 2, 2, 180, 160, 125, 255); /* coping bolt L */
fill_rect(s, W - 6, 9, 2, 2, 180, 160, 125, 255); /* coping bolt R */
/* buttresses + mid pier */
fill_rect(s, 0, H/2 - 2, 4, H/2, ok, og, ob, 255);
fill_rect(s, 1, H/2, 2, H/2 - 4, 140, 125, 95, 255);
fill_rect(s, W - 4, H/2 - 2, 4, H/2, ok, og, ob, 255);
fill_rect(s, W - 3, H/2, 2, H/2 - 4, 140, 125, 95, 255);
fill_rect(s, W/2 - 2, H/2 + 4, 4, H/2 - 8, ok, og, ob, 255); /* mid pier */
fill_rect(s, W/2 - 1, H/2 + 5, 2, H/2 - 10, 130, 115, 88, 255);
/* gate arch + door + hinges */
fill_rect(s, W/2 - 4, H/2 + 2, 8, H/2 - 6, 45, 38, 30, 255); /* gate recess */
fill_rect(s, W/2 - 3, H/2 + 3, 6, H/2 - 8, 55, 48, 38, 255); /* door */
fill_rect(s, W/2 - 2, H/2 + 4, 4, 3, 35, 30, 24, 255); /* gate grate */
fill_rect(s, W/2 - 4, H/2 + 2, 1, H/2 - 8, 90, 80, 60, 255); /* hinge L */
fill_rect(s, W/2 + 3, H/2 + 2, 1, H/2 - 8, 90, 80, 60, 255); /* hinge R */
fill_rect(s, W/2 - 1, H - 8, 2, 2, 200, 180, 80, 255); /* lock plate */
/* embrasures + slits + scars */
fill_rect(s, W/2 - 2, H/2 - 4, 4, 5, 35, 30, 24, 255); /* embrasure */
fill_rect(s, W/2 - 1, H/2 - 2, 2, 3, 20, 18, 14, 255);
fill_rect(s, W/4 - 1, H/2 - 1, 3, 5, 40, 35, 28, 255); /* side slit L */
fill_rect(s, 3 * W/4 - 1, H/2 - 1, 3, 5, 40, 35, 28, 255); /* side slit R */
fill_rect(s, 5, H/2 + 8, 3, 2, 100, 70, 50, 255); /* blast scar L */
fill_rect(s, W - 8, H/2 + 7, 4, 2, 95, 65, 45, 255); /* blast scar R */
fill_rect(s, 3, H - 3, 4, 2, 80, 70, 55, 255); /* rubble L */
fill_rect(s, W - 7, H - 3, 4, 2, 80, 70, 55, 255); /* rubble R */
fill_rect(s, W/2 + 5, H/2 + 10, 2, 2, 60, 52, 40, 255); /* chip */
line(s, 2, H/2 + 1, W - 2, H/2 + 1, 55, 48, 38, 255);
line(s, 2, H/2 + 6, W - 2, H/2 + 6, 75, 65, 50, 255);
line(s, W/3, 8, W/3, H - 4, 65, 55, 42, 255);
line(s, 2 * W/3, 8, 2 * W/3, H - 4, 65, 55, 42, 255);
line(s, 4, H - 7, W - 4, H - 7, 50, 42, 32, 255); /* plinth seam */
disc(s, 6, H/2 + 10, 1, 70, 55, 40, 255); /* pock L */
disc(s, W - 6, H/2 + 9, 1, 70, 55, 40, 255); /* pock R */
break;
case BT_REPAIR:
/* dense garage: pad, hull, bay/lift, tool rack, crane, crates (KKND depot) */
fill_rect(s, 3, H - 8, W - 6, 6, ok, og, ob, 255); /* pad */
fill_rect(s, 4, H - 7, W - 8, 4, 55, 50, 40, 255);
fill_rect(s, 5, H - 6, 2, 2, 35, 32, 28, 255); /* pad bolt L */
fill_rect(s, W - 7, H - 6, 2, 2, 35, 32, 28, 255); /* pad bolt R */
/* main garage hull + roof band + rivets */
fill_rect(s, 4, 6, W - 8, H - 12, ok, og, ob, 255);
fill_rect(s, 6, 8, W - 12, H - 16, base.r, base.g, base.b, 255);
fill_rect(s, 8, 10, W - 16, 8, lite.r, lite.g, lite.b, 255); /* roof */
fill_rect(s, 10, 12, 4, 4, 50, 48, 40, 255); /* roof vents */
fill_rect(s, W/2 - 2, 12, 4, 4, 50, 48, 40, 255);
fill_rect(s, W - 14, 12, 4, 4, 50, 48, 40, 255);
fill_rect(s, 8, 11, 2, 2, 90, 85, 70, 255); /* rivet */
fill_rect(s, W - 12, 11, 2, 2, 90, 85, 70, 255);
fill_rect(s, 8, H - 18, 2, 2, 90, 85, 70, 255);
fill_rect(s, W - 12, H - 18, 2, 2, 90, 85, 70, 255);
line(s, 7, 20, W - 8, 20, 70, 65, 55, 255); /* roof seam */
/* open bay + lift pad + posts + ramps */
fill_rect(s, 10, H - 30, W - 28, 20, ok, og, ob, 255);
fill_rect(s, 12, H - 28, W - 32, 16, 38, 36, 32, 255);
fill_rect(s, W/2 - 10, H - 24, 20, 8, 70, 68, 58, 255); /* lift platform */
fill_rect(s, W/2 - 8, H - 22, 16, 4, 110, 100, 70, 255);
fill_rect(s, W/2 - 6, H - 20, 12, 2, 140, 120, 80, 255); /* lift deck highlight */
line(s, W/2 - 10, H - 24, W/2 - 10, H - 12, 90, 85, 70, 255);
line(s, W/2 + 10, H - 24, W/2 + 10, H - 12, 90, 85, 70, 255);
fill_rect(s, 12, H - 14, 6, 3, 60, 55, 45, 255); /* ramp L */
fill_rect(s, W - 26, H - 14, 6, 3, 60, 55, 45, 255); /* ramp R */
fill_rect(s, W/2 - 12, H - 12, 3, 4, 80, 75, 60, 255); /* lift post L */
fill_rect(s, W/2 + 9, H - 12, 3, 4, 80, 75, 60, 255); /* lift post R */
/* tool rack annex (left) denser */
fill_rect(s, 4, H/2 - 4, 12, H/2 - 4, ok, og, ob, 255);
fill_rect(s, 5, H/2 - 2, 10, H/2 - 8, dark.r, dark.g, dark.b, 255);
fill_rect(s, 6, H/2 + 2, 2, 6, 200, 160, 60, 255); /* tools */
fill_rect(s, 9, H/2 + 1, 2, 7, 180, 180, 190, 255);
fill_rect(s, 12, H/2 + 2, 2, 5, 160, 140, 80, 255);
fill_rect(s, 6, H/2 + 10, 8, 2, 90, 85, 70, 255); /* shelf */
fill_rect(s, 7, H/2 - 1, 6, 2, 120, 110, 90, 255); /* upper shelf */
/* overhead crane mast + jib + hook + trolley */
fill_rect(s, W - 16, 4, 8, H - 20, ok, og, ob, 255);
fill_rect(s, W - 14, 5, 5, H - 22, 95, 88, 70, 255);
fill_rect(s, W - 13, 8, 2, 2, 70, 65, 50, 255); /* mast rivet */
fill_rect(s, W - 13, H/2, 2, 2, 70, 65, 50, 255);
fill_rect(s, 16, 6, W - 32, 4, ok, og, ob, 255);
fill_rect(s, 17, 7, W - 34, 2, 120, 110, 85, 255);
fill_rect(s, W/2 - 3, 5, 6, 3, 100, 95, 75, 255); /* trolley */
line(s, W/2, 8, W/2, 20, 70, 65, 50, 255);
disc(s, W/2, 22, 3, 80, 75, 55, 255);
disc(s, W/2, 22, 1, 140, 130, 90, 255); /* hook tip */
line(s, W - 12, 10, W/2 + 4, 8, 90, 85, 65, 255); /* jib brace */
/* green service cross */
ring(s, W/2 - 6, H/2 + 4, 9, 2, 90, 200, 90, 255);
fill_rect(s, W/2 - 14, H/2 + 2, 16, 4, 120, 220, 120, 255);
fill_rect(s, W/2 - 8, H/2 - 4, 4, 16, 120, 220, 120, 255);
/* parts crates + oil drum + scrap pile */
fill_rect(s, W - 22, H - 14, 8, 6, 140, 100, 55, 255);
fill_rect(s, W - 20, H - 12, 4, 3, 180, 140, 70, 255);
fill_rect(s, W - 24, H - 18, 6, 5, 110, 80, 45, 255); /* crate stack */
fill_rect(s, 18, H - 16, 5, 6, 70, 90, 55, 255); /* oil drum */
disc(s, 20, H - 16, 3, 60, 80, 45, 255);
fill_rect(s, 24, H - 14, 6, 3, 90, 75, 55, 255); /* scrap */
fill_rect(s, W - 18, H - 8, 4, 2, 200, 160, 40, 255); /* hazard stripe */
/* side floodlight + bay hazard lintel */
fill_rect(s, W - 10, 4, 2, 2, 220, 200, 80, 255);
fill_rect(s, W - 9, 3, 1, 3, 90, 85, 70, 255);
fill_rect(s, 12, H - 30, W - 32, 2, 200, 160, 40, 255); /* bay hazard */
break;
case BT_RESEARCH:
/* dense lab: pad, hull, windows, dish mast, annex, instruments (KKND) */
fill_rect(s, 3, H - 8, W - 6, 6, ok, og, ob, 255); /* pad */
fill_rect(s, 4, H - 7, W - 8, 4, 55, 50, 40, 255);
fill_rect(s, 5, H - 6, 2, 2, 35, 32, 28, 255); /* pad bolt L */
fill_rect(s, W - 7, H - 6, 2, 2, 35, 32, 28, 255); /* pad bolt R */
/* main hull + upper band + rivets */
fill_rect(s, 5, 12, W - 10, H - 18, ok, og, ob, 255);
fill_rect(s, 7, 14, W - 14, H - 22, base.r, base.g, base.b, 255);
fill_rect(s, 9, 16, W - 18, 10, lite.r, lite.g, lite.b, 255);
fill_rect(s, 8, 15, 2, 2, 90, 85, 70, 255); /* rivet */
fill_rect(s, W - 12, 15, 2, 2, 90, 85, 70, 255);
fill_rect(s, 8, H - 20, 2, 2, 90, 85, 70, 255);
fill_rect(s, W - 12, H - 20, 2, 2, 90, 85, 70, 255);
line(s, 7, 26, W - 8, 26, 70, 65, 55, 255); /* hull seam */
/* glowing lab windows (2 rows + mullions + glow) */
fill_rect(s, 10, H/2 - 6, 8, 5, 180, 230, 255, 255);
fill_rect(s, 22, H/2 - 6, 8, 5, 160, 220, 250, 255);
fill_rect(s, 34, H/2 - 6, 8, 5, 180, 230, 255, 255);
fill_rect(s, 10, H/2 + 2, 8, 5, 150, 210, 245, 255);
fill_rect(s, 22, H/2 + 2, 8, 5, 170, 225, 255, 255);
fill_rect(s, 34, H/2 + 2, 8, 5, 150, 210, 245, 255);
fill_rect(s, 12, H/2 - 4, 4, 2, 240, 250, 255, 255);
fill_rect(s, 24, H/2 - 4, 4, 2, 230, 245, 255, 255);
fill_rect(s, 36, H/2 - 4, 4, 2, 240, 250, 255, 255);
line(s, 14, H/2 - 6, 14, H/2 - 1, 90, 140, 180, 255);
line(s, 26, H/2 - 6, 26, H/2 - 1, 90, 140, 180, 255);
line(s, 38, H/2 - 6, 38, H/2 - 1, 90, 140, 180, 255);
/* entry door + hazard */
fill_rect(s, W/2 - 5, H - 22, 10, 12, ok, og, ob, 255);
fill_rect(s, W/2 - 4, H - 21, 8, 10, 40, 38, 45, 255);
fill_rect(s, W/2 - 4, H - 21, 8, 2, 200, 160, 40, 255);
fill_rect(s, W/2 - 1, H - 16, 2, 3, 180, 170, 90, 255); /* handle */
/* primary dish on tall mast + braces */
fill_rect(s, W/2 + 4, 2, 5, 18, ok, og, ob, 255);
fill_rect(s, W/2 + 5, 3, 3, 16, 110, 100, 75, 255);
line(s, W/2 + 2, 14, W/2 + 5, 8, 80, 75, 55, 255);
line(s, W/2 + 10, 14, W/2 + 7, 8, 80, 75, 55, 255);
disc(s, W/2 + 6, 12, 13, ok, og, ob, 255);
disc(s, W/2 + 6, 12, 11, 215, 185, 85, 255);
ring(s, W/2 + 6, 12, 8, 2, 170, 140, 55, 255);
disc(s, W/2 + 6, 12, 4, 255, 245, 170, 255);
disc(s, W/2 + 6, 12, 2, 255, 255, 220, 255); /* feed */
line(s, W/2 + 6, 2, W/2 + 6, 12, 200, 190, 120, 255);
/* secondary small dish + cable */
fill_rect(s, 8, 4, 3, 10, ok, og, ob, 255);
fill_rect(s, 9, 5, 1, 8, 100, 95, 70, 255);
disc(s, 9, 8, 5, ok, og, ob, 255);
disc(s, 9, 8, 3, 190, 160, 70, 255);
disc(s, 9, 8, 1, 255, 240, 160, 255);
line(s, 12, 10, W/2 + 4, 14, 90, 85, 60, 255); /* coax */
/* roof vents / AC + floodlight */
fill_rect(s, 16, 8, 6, 4, ok, og, ob, 255);
fill_rect(s, 17, 9, 4, 2, 120, 115, 95, 255);
fill_rect(s, 24, 7, 5, 3, 70, 68, 60, 255);
fill_rect(s, 25, 6, 3, 2, 90, 88, 78, 255);
fill_rect(s, W - 14, 4, 2, 2, 220, 200, 80, 255); /* floodlight */
fill_rect(s, W - 13, 3, 1, 3, 90, 85, 70, 255);
/* side antenna array */
fill_rect(s, 10, 6, 3, 10, 200, 200, 140, 255);
fill_rect(s, 18, 4, 2, 12, 220, 220, 150, 255);
fill_rect(s, 14, 5, 2, 8, 180, 180, 130, 255);
disc(s, 11, 5, 2, 255, 240, 120, 255);
disc(s, 19, 3, 2, 255, 230, 100, 255);
disc(s, 15, 4, 1, 255, 220, 90, 255);
/* side annex / sample bay */
fill_rect(s, W - 16, H - 28, 12, 14, ok, og, ob, 255);
fill_rect(s, W - 15, H - 27, 10, 12, dark.r, dark.g, dark.b, 255);
fill_rect(s, W - 13, H - 25, 6, 4, 140, 200, 255, 255); /* annex window */
fill_rect(s, W - 12, H - 24, 2, 2, 230, 245, 255, 255);
fill_rect(s, W - 14, H - 18, 8, 2, 200, 160, 40, 255); /* hazard */
/* cooling pipes along hull */
line(s, 6, 20, 6, H - 14, 100, 140, 180, 255);
line(s, W - 8, 20, W - 8, H - 14, 100, 140, 180, 255);
fill_rect(s, 5, H/2, 3, 3, 80, 110, 140, 255); /* valve L */
fill_rect(s, W - 9, H/2 + 4, 3, 3, 80, 110, 140, 255);
/* instrument bank / console strip denser */
fill_rect(s, 10, H - 16, W - 30, 7, dark.r, dark.g, dark.b, 255);
fill_rect(s, 12, H - 14, 3, 3, 80, 220, 120, 255);
fill_rect(s, 17, H - 14, 3, 3, 80, 160, 255, 255);
fill_rect(s, 22, H - 14, 3, 3, 255, 180, 80, 255);
fill_rect(s, 27, H - 14, 3, 3, 200, 100, 255, 255);
fill_rect(s, 32, H - 14, 3, 3, 255, 80, 120, 255);
fill_rect(s, 12, H - 10, 22, 1, 60, 55, 50, 255); /* LED rail */
break;
default:
(void)dark;
break;
}
SDL_Texture *tex = SDL_CreateTextureFromSurface(r, s);
SDL_FreeSurface(s);
return tex;
}
/* ---------------- terrain tiles ---------------- */
SDL_Texture *sprites_make_terrain(SDL_Renderer *r, TerrainType t) {
SDL_Surface *s = new_surf(TILE, TILE);
Uint8 tr=0,tg=0,tb=0;
/* Classic KKND2 wasteland: yellow-tan sand (R>>B, G slightly under R). */
switch (t) {
case T_WASTELAND: tr=228; tg=188; tb=98; break;
case T_RUBBLE: tr=168; tg=138; tb=88; break;
case T_ROAD: tr=175; tg=148; tb=98; break;
case T_GRASS: tr=242; tg=198; tb=92; break; /* sunlit desert */
case T_WATER: tr=72; tg=128; tb=178; break;
case T_ROCK: tr=155; tg=142; tb=128; break;
case T_SCRAP: tr=240; tg=190; tb=78; break;
default: tr=228; tg=188; tb=98; break;
}
fill_rect(s, 0, 0, TILE, TILE, tr, tg, tb, 255);
/* speckle for texture */
for (int i = 0; i < 40; i++) {
int x = (i*73) % TILE, y = (i*131) % TILE;
int v = ((i*53) % 24) - 12;
px(s, x, y,
(Uint8)kknd_clampi(tr+v,0,255),
(Uint8)kknd_clampi(tg+v,0,255),
(Uint8)kknd_clampi(tb+v,0,255), 255);
}
if (t == T_SCRAP) {
/* stacked scrap mounds (live parity with snapshot) */
int cc = TILE / 2, cr = TILE / 2 + 2;
for (int k = 0; k < 7; k++) {
int ox = ((k * 7) % 14) - 7;
int oy = ((k * 5) % 10) - 5 - (k / 3) * 2;
int rad = 3 + (k & 1);
disc(s, cc + ox, cr + oy, rad, 235, 190, 85, 255);
disc(s, cc + ox - 1, cr + oy - rad / 2, rad - 1, 210, 165, 70, 255);
disc(s, cc + ox + 1, cr + oy - rad + 1,
(rad > 2) ? rad - 2 : 1, 255, 215, 120, 255);
}
}
if (t == T_WATER) {
for (int i = 0; i < TILE; i += 4)
line(s, 0, i, TILE, i, 60, 100, 150, 255);
}
if (t == T_ROCK) {
for (int i = 0; i < 12; i++) {
int x = (i*89) % TILE, y = (i*149) % TILE;
disc(s, x, y, 3, 130, 124, 118, 255);
}
}
SDL_Texture *tex = SDL_CreateTextureFromSurface(r, s);
SDL_FreeSurface(s);
return tex;
}
/* ---------------- bullets ---------------- */
static SDL_Texture *make_bullet(SDL_Renderer *r, int kind) {
int S = 10;
SDL_Surface *s = new_surf(S, S);
switch (kind) {
case 0: disc(s, 5, 5, 3, 255, 230, 120, 255); break; /* MG tracer */
case 1: disc(s, 5, 5, 4, 255, 160, 60, 255); break; /* shell */
case 2: disc(s, 5, 5, 3, 120, 255, 160, 255); break; /* laser */
case 3: disc(s, 5, 5, 4, 255, 90, 90, 255); break; /* missile */
default: disc(s, 5, 5, 3, 255, 255, 255, 255);
}
SDL_Texture *tex = SDL_CreateTextureFromSurface(r, s);
SDL_FreeSurface(s);
return tex;
}
int sprites_init(Sprites *sp, SDL_Renderer *r) {
memset(sp, 0, sizeof(Sprites));
for (int t = 0; t < T_COUNT; t++)
sp->terrain[t] = sprites_make_terrain(r, (TerrainType)t);
for (int t = 1; t < UT_COUNT; t++) {
sp->unit[t][FACTION_SURVIVOR] = sprites_make_unit(r, (UnitType)t, FACTION_SURVIVOR);
sp->unit[t][FACTION_EVOLVED] = sprites_make_unit(r, (UnitType)t, FACTION_EVOLVED);
sp->unit[t][FACTION_SERIES9] = sprites_make_unit(r, (UnitType)t, FACTION_SERIES9);
}
for (int t = 1; t < BT_COUNT; t++) {
sp->bld[t][FACTION_SURVIVOR] = sprites_make_bld(r, (BuildingType)t, FACTION_SURVIVOR);
sp->bld[t][FACTION_EVOLVED] = sprites_make_bld(r, (BuildingType)t, FACTION_EVOLVED);
sp->bld[t][FACTION_SERIES9] = sprites_make_bld(r, (BuildingType)t, FACTION_SERIES9);
}
for (int k = 0; k < 4; k++)
sp->bullet[k] = make_bullet(r, k);
sp->font_small = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSans.ttf", 14);
if (!sp->font_small)
sp->font_small = TTF_OpenFont("/usr/share/fonts/gnu-free/FreeSans.ttf", 14);
sp->font_med = sp->font_small ? TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSans.ttf", 20) : NULL;
sp->font_big = sp->font_small ? TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSans.ttf", 34) : NULL;
if (!sp->font_small) {
sp->font_small = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", 14);
}
return 1;
}
void sprites_free(Sprites *sp) {
for (int t = 0; t < T_COUNT; t++)
if (sp->terrain[t]) SDL_DestroyTexture(sp->terrain[t]);
for (int t = 1; t < UT_COUNT; t++)
for (int f = 0; f < MAX_FACTIONS; f++)
if (sp->unit[t][f]) SDL_DestroyTexture(sp->unit[t][f]);
for (int t = 1; t < BT_COUNT; t++)
for (int f = 0; f < MAX_FACTIONS; f++)
if (sp->bld[t][f]) SDL_DestroyTexture(sp->bld[t][f]);
for (int k = 0; k < 4; k++)
if (sp->bullet[k]) SDL_DestroyTexture(sp->bullet[k]);
if (sp->font_small) TTF_CloseFont(sp->font_small);
if (sp->font_med) TTF_CloseFont(sp->font_med);
if (sp->font_big) TTF_CloseFont(sp->font_big);
}