/* * Source Code (.pde / .php): MIT License; Documents & Open Data: CC0 1.0 Universal; * Copyright (c) 2026 Jan Bühring & Adaptive Intelligence Synthesis Network (Google AI). * * Project Database: https://xqskys.de * Framework: DTIM-ZEC Modular Physics Framework (DAMTP Academic Standard) * Compatibility: Processing 4.5.7 (Java) & processing.min.js (Web Canvas) */ // ============================================================================ // 1. GLOBAL CONFIGURATION & ACCESSIBILITY STATE // ============================================================================ boolean a11yMode = false; String statusMessage = "Willkommen an Bord der Norn-Arche! Wähle ein Modul und klicke ins Raster."; // Grid Configuration (18 x 12 tiles, 42px each = 756 x 504 map) int COLS = 18; int ROWS = 12; int TILE_SIZE = 42; int MAP_X = 20; int MAP_Y = 58; // Tile Types: // 0 = Weltraum (Vakuum), 1 = Schiffsboden (Hull), 2 = Hüllenwand (Wall), // 3 = Sauerstoff-Generator (O2), 4 = DTIM-ZEC Reaktor (Energie), // 5 = Hydroponik / Gurkenbeet (Nahrung), 6 = Meerschweinchen-Habitat (Moral), // 7 = Schlafkoje (Erholung) int TILE_SPACE = 0; int TILE_FLOOR = 1; int TILE_WALL = 2; int TILE_O2 = 3; int TILE_REACTOR = 4; int TILE_FARM = 5; int TILE_PIG_HAB = 6; int TILE_BED = 7; int[][] grid = new int[COLS][ROWS]; float[][] tileO2 = new float[COLS][ROWS]; // 0.0 .. 100.0 % oxygen per tile // Selected Build Brush int selectedTool = TILE_FLOOR; int[] toolCosts = {0, 5, 10, 25, 35, 20, 30, 15}; String[] toolNames = { "0: Abriss / Vakuum", "1: Schiffsboden (5 Metall)", "2: Hüllenwand (10 Metall)", "3: O2-Generator (25 Metall)", "4: DTIM-Reaktor (35 Metall)", "5: Gurken-Beet (20 Metall)", "6: Wheek-Habitat (30 Metall)", "7: Norn-Koje (15 Metall)" }; // Ship Resources int metal = 140; int energy = 40; int food = 35; int simTick = 0; // ============================================================================ // 2. CREW AGENTS (NORN CREW + MEERSCHWEINCHEN HELFER) // ============================================================================ int NUM_CREW = 4; String[] crewName = {"Norn Lyra", "Norn Kael", "Meerschweinchen Pip", "Meerschweinchen Fussel"}; boolean[] crewIsPig = {false, false, true, true}; float[] crewX = new float[NUM_CREW]; float[] crewY = new float[NUM_CREW]; float[] crewTargetX = new float[NUM_CREW]; float[] crewTargetY = new float[NUM_CREW]; float[] crewHunger = {85, 80, 90, 88}; // 0..100 (100 = satt) float[] crewMood = {80, 82, 95, 92}; // 0..100 String[] crewState = {"Bereit", "Bereit", "Wheek!", "Schnüffelt"}; // Background stars int NUM_STARS = 50; float[] starX = new float[NUM_STARS]; float[] starY = new float[NUM_STARS]; // ============================================================================ // 3. INITIALIZATION // ============================================================================ void setup() { size(1060, 640); smooth(); textFont(createFont("SansSerif", 13)); for (int i = 0; i < NUM_STARS; i++) { starX[i] = random(MAP_X, MAP_X + COLS * TILE_SIZE); starY[i] = random(MAP_Y, MAP_Y + ROWS * TILE_SIZE); } initShip(); } void initShip() { metal = 140; energy = 40; food = 35; simTick = 0; selectedTool = TILE_FLOOR; for (int c = 0; c < COLS; c++) { for (int r = 0; r < ROWS; r++) { grid[c][r] = TILE_SPACE; tileO2[c][r] = 0.0; } } // Build starter core room (cols 6..11, rows 4..7) for (int c = 6; c <= 11; c++) { for (int r = 4; r <= 7; r++) { boolean isEdge = (c == 6 || c == 11 || r == 4 || r == 7); grid[c][r] = isEdge ? TILE_WALL : TILE_FLOOR; tileO2[c][r] = isEdge ? 0.0 : 95.0; } } // Starter equipment inside core hull grid[7][5] = TILE_O2; grid[10][5] = TILE_REACTOR; grid[7][6] = TILE_FARM; grid[10][6] = TILE_PIG_HAB; // Place Crew inside starter room for (int i = 0; i < NUM_CREW; i++) { crewX[i] = 8.5 + (i % 2) * 0.8; crewY[i] = 5.5 + (i / 2) * 0.8; crewTargetX[i] = crewX[i]; crewTargetY[i] = crewY[i]; crewHunger[i] = 85.0; crewMood[i] = 85.0; } statusMessage = "Startsektion bereit! Baue Boden, Wände & Module mit Klick ins Raster."; } // ============================================================================ // 4. MAIN LOOP // ============================================================================ void draw() { drawBackground(); updateSimulation(); drawGrid(); drawCrew(); drawTopBar(); drawSidePanel(); drawBottomBar(); } // ============================================================================ // 5. SIMULATION: OXYGEN DIFFUSION, RESOURCES & CREW AI // ============================================================================ void updateSimulation() { simTick++; // 1. Oxygen diffusion & generation (every 10 frames for smooth performance) if (simTick % 10 == 0) { float[][] nextO2 = new float[COLS][ROWS]; for (int c = 0; c < COLS; c++) { for (int r = 0; r < ROWS; r++) { int t = grid[c][r]; if (t == TILE_SPACE || t == TILE_WALL) { nextO2[c][r] = 0.0; } else { float sum = tileO2[c][r]; int count = 1; boolean exposedToVacuum = false; int[] dc = {-1, 1, 0, 0}; int[] dr = {0, 0, -1, 1}; for (int k = 0; k < 4; k++) { int nc = c + dc[k]; int nr = r + dr[k]; if (nc < 0 || nc >= COLS || nr < 0 || nr >= ROWS || grid[nc][nr] == TILE_SPACE) { exposedToVacuum = true; } else if (grid[nc][nr] != TILE_WALL) { sum += tileO2[nc][nr]; count++; } } float avg = sum / count; if (exposedToVacuum) { avg *= 0.65; // Venting into space if hull is not sealed! } if (t == TILE_O2 && energy > 0) { avg = min(100.0, avg + 28.0); } nextO2[c][r] = max(0.0, avg - 0.15); } } } tileO2 = nextO2; } // 2. Resource production cycle (every 120 frames = ~2 seconds) if (simTick % 120 == 0) { int reactors = countTiles(TILE_REACTOR); int farms = countTiles(TILE_FARM); int pigHabs = countTiles(TILE_PIG_HAB); int o2Gens = countTiles(TILE_O2); energy = constrain(energy + reactors * 4 - o2Gens * 1, 0, 999); if (energy > 0) { food = constrain(food + farms * 2, 0, 999); } // Small passive salvage / asteroid mineral trickle metal = constrain(metal + 1, 0, 999); // Update Crew Needs for (int i = 0; i < NUM_CREW; i++) { crewHunger[i] = max(0, crewHunger[i] - 1.5); if (crewHunger[i] < 45 && food > 0) { food--; crewHunger[i] = min(100, crewHunger[i] + 35); crewState[i] = crewIsPig[i] ? "Mampft Gurke!" : "Isst Ration"; } int cx = constrain(int(crewX[i]), 0, COLS - 1); int cy = constrain(int(crewY[i]), 0, ROWS - 1); if (tileO2[cx][cy] < 30) { crewMood[i] = max(0, crewMood[i] - 4.0); crewState[i] = "Atemnot! (Wände bauen)"; } else { float pigBonus = (pigHabs > 0) ? 1.5 : 0.2; crewMood[i] = min(100, crewMood[i] + pigBonus); } } } // 3. Crew Movement (relaxed RimWorld-like wandering on walkable floor) for (int i = 0; i < NUM_CREW; i++) { float d = dist(crewX[i], crewY[i], crewTargetX[i], crewTargetY[i]); if (d < 0.12) { // Pick a new walkable floor tile int tries = 0; while (tries < 12) { int rc = int(random(COLS)); int rr = int(random(ROWS)); if (isWalkable(rc, rr) && tileO2[rc][rr] > 25) { crewTargetX[i] = rc + 0.5; crewTargetY[i] = rr + 0.5; if (grid[rc][rr] == TILE_PIG_HAB) { crewState[i] = crewIsPig[i] ? "WHEEK! Spielzeit" : "Streichelt Meerschweinchen"; } else if (grid[rc][rr] == TILE_FARM) { crewState[i] = crewIsPig[i] ? "Schnüffelt Gurken" : "Pflegt Hydroponik"; } else if (grid[rc][rr] == TILE_REACTOR) { crewState[i] = "Prüft DTIM-Metrik"; } else { crewState[i] = crewIsPig[i] ? "Trippelt herum" : "Patrouille"; } break; } tries++; } } else { float angle = atan2(crewTargetY[i] - crewY[i], crewTargetX[i] - crewX[i]); float spd = crewIsPig[i] ? 0.024 : 0.018; float nx = crewX[i] + cos(angle) * spd; float ny = crewY[i] + sin(angle) * spd; if (isWalkable(int(nx), int(ny))) { crewX[i] = nx; crewY[i] = ny; } else { crewTargetX[i] = crewX[i]; crewTargetY[i] = crewY[i]; } } } } boolean isWalkable(int c, int r) { if (c < 0 || c >= COLS || r < 0 || r >= ROWS) return false; int t = grid[c][r]; return (t != TILE_SPACE && t != TILE_WALL); } int countTiles(int type) { int count = 0; for (int c = 0; c < COLS; c++) { for (int r = 0; r < ROWS; r++) { if (grid[c][r] == type) count++; } } return count; } // ============================================================================ // 6. RENDERING: SHIP GRID & MODULES // ============================================================================ void drawBackground() { background(a11yMode ? 0 : color(11, 16, 28)); noStroke(); for (int i = 0; i < NUM_STARS; i++) { fill(a11yMode ? 170 : color(160, 185, 220, 95)); ellipse(starX[i], starY[i], 2, 2); } } void drawGrid() { rectMode(CORNER); for (int c = 0; c < COLS; c++) { for (int r = 0; r < ROWS; r++) { float x = MAP_X + c * TILE_SIZE; float y = MAP_Y + r * TILE_SIZE; int t = grid[c][r]; // Grid outline stroke(a11yMode ? color(60) : color(32, 45, 68, 120)); strokeWeight(1); if (t == TILE_SPACE) { noFill(); rect(x, y, TILE_SIZE, TILE_SIZE); continue; } // Base Floor Color tinted by O2 level float o2Ratio = constrain(tileO2[c][r] / 100.0, 0, 1); if (t == TILE_WALL) { fill(a11yMode ? color(220) : color(95, 110, 132)); stroke(a11yMode ? color(255, 255, 0) : color(155, 175, 200)); strokeWeight(1.5); rect(x, y, TILE_SIZE, TILE_SIZE); // Cross-brace pattern for accessibility line(x + 4, y + 4, x + TILE_SIZE - 4, y + TILE_SIZE - 4); continue; } // Walkable Floor Base if (a11yMode) { fill(o2Ratio > 0.3 ? color(28, 38, 45) : color(45, 15, 15)); stroke(140); } else { fill(lerpColor(color(58, 36, 44), color(42, 58, 82), o2Ratio)); stroke(68, 88, 118); } rect(x, y, TILE_SIZE, TILE_SIZE); // Module Icons & Distinct Shapes float cx = x + TILE_SIZE * 0.5; float cy = y + TILE_SIZE * 0.5; if (t == TILE_O2) { fill(a11yMode ? color(0, 220, 255) : color(75, 195, 235)); stroke(255); ellipse(cx, cy, 24, 24); fill(0); noStroke(); textAlign(CENTER, CENTER); text("O2", cx, cy); } else if (t == TILE_REACTOR) { fill(a11yMode ? color(255, 220, 0) : color(235, 175, 55)); stroke(255); quad(cx, cy - 14, cx + 14, cy, cx, cy + 14, cx - 14, cy); fill(0); noStroke(); textAlign(CENTER, CENTER); text("Z", cx, cy); } else if (t == TILE_FARM) { fill(a11yMode ? color(0, 255, 120) : color(72, 185, 98)); stroke(255); rect(x + 8, y + 8, TILE_SIZE - 16, TILE_SIZE - 16, 4); fill(0); noStroke(); textAlign(CENTER, CENTER); text("G", cx, cy); } else if (t == TILE_PIG_HAB) { fill(a11yMode ? color(255, 160, 0) : color(210, 145, 85)); stroke(255); ellipse(cx, cy, 26, 20); fill(0); noStroke(); textAlign(CENTER, CENTER); text("W", cx, cy); } else if (t == TILE_BED) { fill(a11yMode ? color(180, 140, 255) : color(115, 135, 205)); stroke(255); rect(x + 9, y + 6, TILE_SIZE - 18, TILE_SIZE - 12, 3); } } } // Hover preview highlight int hc = (mouseX - MAP_X) / TILE_SIZE; int hr = (mouseY - MAP_Y) / TILE_SIZE; if (mouseX >= MAP_X && hc >= 0 && hc < COLS && mouseY >= MAP_Y && hr >= 0 && hr < ROWS) { noFill(); stroke(a11yMode ? color(255, 255, 0) : color(120, 235, 210)); strokeWeight(2); rect(MAP_X + hc * TILE_SIZE, MAP_Y + hr * TILE_SIZE, TILE_SIZE, TILE_SIZE); } } void drawCrew() { for (int i = 0; i < NUM_CREW; i++) { float px = MAP_X + crewX[i] * TILE_SIZE; float py = MAP_Y + crewY[i] * TILE_SIZE; if (crewIsPig[i]) { // Cute Guinea Pig ("Meerschweinchen") fill(a11yMode ? color(255, 220, 0) : color(205, 140, 85)); stroke(0); strokeWeight(1.5); ellipse(px, py, 16, 11); fill(255); noStroke(); ellipse(px - 2, py, 5, 8); fill(0); ellipse(px + 5, py - 1.5, 2.5, 2.5); } else { // Norn Colonist fill(a11yMode ? color(0, 255, 255) : color(110, 215, 245)); stroke(0); strokeWeight(1.5); ellipse(px, py, 16, 16); fill(255); noStroke(); ellipse(px, py - 2, 8, 6); } } } // ============================================================================ // 7. RENDERING: TOP HUD, BUILD PALETTE & CREW ROSTER // ============================================================================ void drawTopBar() { rectMode(CORNER); fill(a11yMode ? 0 : color(18, 25, 42, 235)); stroke(a11yMode ? 255 : color(70, 105, 140)); strokeWeight(a11yMode ? 2 : 1); rect(10, 10, width - 20, 36, 6); fill(a11yMode ? 255 : 235); noStroke(); textAlign(LEFT, CENTER); float avgO2 = calculateAverageO2(); String modeStr = a11yMode ? "High Contrast [H]" : "Standard [H]"; String info = "DTIM-ZEC: NORN-ARCHE (SPACE HABITAT) | Metall: " + metal + " | Energie: " + energy + " | Gurken/Nahrung: " + food + " | Ø Sauerstoff: " + int(avgO2) + "%" + " | " + modeStr; text(info, 22, 28); } void drawSidePanel() { float px = 790; float py = 58; float pw = 260; float ph = 504; rectMode(CORNER); fill(a11yMode ? 10 : color(18, 26, 44, 240)); stroke(a11yMode ? 255 : color(75, 110, 150)); strokeWeight(a11yMode ? 2 : 1.5); rect(px, py, pw, ph, 8); float cx = px + 14; float cy = py + 22; textAlign(LEFT, CENTER); fill(a11yMode ? color(255, 255, 0) : color(120, 220, 205)); text("BAU-MENÜ (Klick oder Taste 0-7)", cx, cy); cy += 22; for (int t = 0; t < 8; t++) { boolean active = (selectedTool == t); if (a11yMode) { fill(active ? 55 : 0); stroke(active ? color(255, 255, 0) : color(180)); strokeWeight(active ? 2.5 : 1); } else { fill(active ? color(45, 78, 102) : color(28, 38, 60)); stroke(active ? color(110, 225, 205) : color(75, 105, 140)); strokeWeight(active ? 2 : 1); } rect(cx, cy, pw - 28, 26, 5); fill(a11yMode ? 255 : 230); noStroke(); text(toolNames[t], cx + 8, cy + 13); cy += 30; } cy += 8; stroke(a11yMode ? 255 : color(70, 100, 135)); line(cx, cy, px + pw - 14, cy); cy += 18; // Crew Roster fill(a11yMode ? color(255, 255, 0) : color(120, 220, 205)); text("BESATZUNG & MEERSCHWEINCHEN", cx, cy); cy += 20; for (int i = 0; i < NUM_CREW; i++) { fill(a11yMode ? 255 : 225); text(crewName[i], cx, cy); cy += 15; fill(a11yMode ? 210 : color(165, 195, 220)); text("Satt: " + int(crewHunger[i]) + "% | Moral: " + int(crewMood[i]) + "%", cx, cy); cy += 14; text("Status: " + crewState[i], cx, cy); cy += 20; } } void drawBottomBar() { rectMode(CORNER); fill(a11yMode ? 0 : color(18, 25, 42, 235)); stroke(a11yMode ? 255 : color(70, 105, 140)); strokeWeight(a11yMode ? 2 : 1); rect(10, height - 38, width - 20, 28, 5); fill(a11yMode ? color(255, 255, 0) : color(195, 225, 245)); noStroke(); textAlign(LEFT, CENTER); text("Log: " + statusMessage + " | [Linksklick] Bauen [Rechtsklick] Abriss [H] Sehhilfe [R] Neustart", 22, height - 24); } float calculateAverageO2() { float sum = 0; int floorCount = 0; for (int c = 0; c < COLS; c++) { for (int r = 0; r < ROWS; r++) { if (isWalkable(c, r)) { sum += tileO2[c][r]; floorCount++; } } } return (floorCount > 0) ? (sum / floorCount) : 0; } // ============================================================================ // 8. INPUT HANDLING (BUILD & DEMOLISH) // ============================================================================ void applyToolAt(int c, int r, int tool) { if (c < 0 || c >= COLS || r < 0 || r >= ROWS) return; int current = grid[c][r]; if (tool == TILE_SPACE) { if (current != TILE_SPACE) { metal += max(2, toolCosts[current] / 2); grid[c][r] = TILE_SPACE; tileO2[c][r] = 0; statusMessage = "Sektor abgerissen (+Metall zurückgewonnen)."; } return; } // Modules (O2, Reactor, Farm, Pig Habitat, Bed) require existing floor if (tool >= TILE_O2 && current != TILE_FLOOR) { statusMessage = "Module benötigen zuerst einen Schiffsboden (Taste 1)!"; return; } // Floor & Walls require space or floor if ((tool == TILE_FLOOR || tool == TILE_WALL) && current == tool) return; int cost = toolCosts[tool]; if (metal >= cost) { metal -= cost; grid[c][r] = tool; statusMessage = toolNames[tool] + " gebaut!"; } else { statusMessage = "Nicht genug Metall (" + cost + " benötigt)."; } } void mousePressed() { handleMouseAction(); } void mouseDragged() { handleMouseAction(); } void handleMouseAction() { // 1. Grid Click / Drag int c = (mouseX - MAP_X) / TILE_SIZE; int r = (mouseY - MAP_Y) / TILE_SIZE; if (mouseX >= MAP_X && c >= 0 && c < COLS && mouseY >= MAP_Y && r >= 0 && r < ROWS) { if (mouseButton == RIGHT) { applyToolAt(c, r, TILE_SPACE); } else if (mouseButton == LEFT) { applyToolAt(c, r, selectedTool); } return; } // 2. Side Palette Selection if (mouseX >= 804 && mouseX <= 1036) { for (int t = 0; t < 8; t++) { float by = 80 + t * 30; if (mouseY >= by && mouseY <= by + 26) { selectedTool = t; statusMessage = "Ausgewählt: " + toolNames[t]; } } } } void keyPressed() { if (key >= '0' && key <= '7') { selectedTool = key - '0'; statusMessage = "Ausgewählt: " + toolNames[selectedTool]; } if (key == 'h' || key == 'H') { a11yMode = !a11yMode; } if (key == 'r' || key == 'R') { initShip(); } }