kitchen: README + MISSIONS/engine-c keep-drop notes

This commit is contained in:
Hernâni Marques 2026-09-17 21:48:48 +02:00
parent 1d351918da
commit 575d7d29b8
No known key found for this signature in database
130 changed files with 9817 additions and 1 deletions

View file

@ -0,0 +1,20 @@
# src/building.h
#ifndef BUILDING_H
#define BUILDING_H
#include "entity.h"
enum BuildingType {
BUILDING_HQ,
BUILDING_BARRACKS,
BUILDING_COUNT
};
typedef struct {
Entity entity;
BuildingType type;
int resourceCost;
} Building;
#endif // BUILDING_H

View file

@ -0,0 +1,36 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ok_types.h"
#include "ok_map.h"
#include "ok_unit.h"
static int run_smoke(void) {
OkWorld w;
ok_map_init(&w, 42);
int a = ok_unit_spawn(&w, OK_FACTION_A, OK_UNIT_SCOUT, 1, 1);
int b = ok_unit_spawn(&w, OK_FACTION_B, OK_UNIT_SCOUT, OK_WORLD_W - 2, OK_WORLD_H - 2);
if (a < 0 || b < 0) { fprintf(stderr, "spawn failed\n"); return 2; }
for (int t = 0; t < 40; t++) ok_world_tick(&w);
if (ok_world_alive_count(&w, OK_FACTION_A) < 1 || ok_world_alive_count(&w, OK_FACTION_B) < 1) {
fprintf(stderr, "units died\n"); return 3;
}
if (w.units[a].x == 1 && w.units[a].y == 1) {
fprintf(stderr, "unit A did not move\n"); return 4;
}
printf("openkknd2: headless smoke test passed (ticks=%d units=%d resA=%d resB=%d)\n",
w.tick, w.unit_count, w.resources_a, w.resources_b);
return 0;
}
int main(int argc, char *argv[]) {
int headless = 0, smoke = 0;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--headless") == 0) headless = 1;
else if (strcmp(argv[i], "--smoke") == 0) smoke = 1;
}
if (headless && smoke) return run_smoke();
printf("openkknd2 - original open post-apoc RTS scaffold (not KKnD)\n");
printf("Usage: %s --headless --smoke\n", argv[0]);
return headless ? 0 : 1;
}

View file

@ -0,0 +1,45 @@
#include "ok_buildings.h"
#include "ok_map.h"
#include <stdio.h>
void ok_buildings_init(OkWorld *w) {
// Initialize buildings array - for now we'll use a simple approach
// In a more complete implementation, we'd have an actual building array
}
void ok_buildings_place(OkWorld *w, int x, int y, OkBuildingKind kind, OkFaction faction) {
// Check if placement is valid (walkable tile and not occupied)
if (!ok_map_walkable(w, x, y)) {
return;
}
// For now, we'll just update the resource count when a building is placed
int cost = 0;
switch (kind) {
case OK_BUILDING_HQ:
cost = 50;
break;
case OK_BUILDING_BARRACKS:
cost = 30;
break;
default:
return;
}
// Check if faction has enough resources
int *resources = (faction == OK_FACTION_A) ? &w->resources_a : &w->resources_b;
if (*resources < cost) {
return;
}
// Deduct cost and mark building as placed
*resources -= cost;
printf("Faction %d placed %s at (%d,%d)\n", faction,
(kind == OK_BUILDING_HQ) ? "HQ" : "Barracks", x, y);
}
void ok_buildings_update(OkWorld *w) {
// Simple building update logic - in a real implementation this would handle
// building construction, production, etc.
}

View file

@ -0,0 +1,29 @@
#include "ok_map.h"
#include <string.h>
static uint32_t rng_u32(uint32_t *s) {
*s = *s * 1664525u + 1013904223u;
return *s;
}
void ok_map_init(OkWorld *w, uint32_t seed) {
memset(w, 0, sizeof(*w));
uint32_t s = seed ? seed : 1u;
for (int y = 0; y < OK_WORLD_H; y++) {
for (int x = 0; x < OK_WORLD_W; x++) {
uint32_t r = rng_u32(&s);
if ((r % 17u) == 0u) w->tiles[y][x] = OK_TILE_BLOCK;
else if ((r % 11u) == 0u) w->tiles[y][x] = OK_TILE_RES;
else w->tiles[y][x] = OK_TILE_EMPTY;
}
}
w->tiles[1][1] = OK_TILE_EMPTY;
w->tiles[OK_WORLD_H - 2][OK_WORLD_W - 2] = OK_TILE_EMPTY;
w->resources_a = 100;
w->resources_b = 100;
}
bool ok_map_walkable(const OkWorld *w, int x, int y) {
if (x < 0 || y < 0 || x >= OK_WORLD_W || y >= OK_WORLD_H) return false;
return w->tiles[y][x] != OK_TILE_BLOCK;
}

View file

@ -0,0 +1,46 @@
#include "ok_unit.h"
#include "ok_map.h"
int ok_unit_spawn(OkWorld *w, OkFaction f, OkUnitKind k, int x, int y) {
if (w->unit_count >= OK_MAX_UNITS) return -1;
if (!ok_map_walkable(w, x, y)) return -1;
int id = w->unit_count++;
OkUnit *u = &w->units[id];
u->x = x; u->y = y; u->faction = f; u->kind = k;
u->hp = (k == OK_UNIT_SCOUT) ? 40 : 30;
u->alive = true;
return id;
}
void ok_unit_step_toward(OkWorld *w, int uid, int tx, int ty) {
if (uid < 0 || uid >= w->unit_count) return;
OkUnit *u = &w->units[uid];
if (!u->alive) return;
int nx = u->x + (tx > u->x) - (tx < u->x);
int ny = u->y + (ty > u->y) - (ty < u->y);
if (ok_map_walkable(w, nx, u->y)) u->x = nx;
if (ok_map_walkable(w, u->x, ny)) u->y = ny;
if (w->tiles[u->y][u->x] == OK_TILE_RES) {
if (u->faction == OK_FACTION_A) w->resources_a += 1;
else w->resources_b += 1;
w->tiles[u->y][u->x] = OK_TILE_EMPTY;
}
}
void ok_world_tick(OkWorld *w) {
w->tick++;
for (int i = 0; i < w->unit_count; i++) {
OkUnit *u = &w->units[i];
if (!u->alive) continue;
int tx = (u->faction == OK_FACTION_A) ? (OK_WORLD_W - 3) : 2;
int ty = (u->faction == OK_FACTION_A) ? (OK_WORLD_H - 3) : 2;
ok_unit_step_toward(w, i, tx, ty);
}
}
int ok_world_alive_count(const OkWorld *w, OkFaction f) {
int n = 0;
for (int i = 0; i < w->unit_count; i++)
if (w->units[i].alive && w->units[i].faction == f) n++;
return n;
}