forked from NotAShelf/rogged
various: add admin build; various layout improvements
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ieaa99fa0a32b42b1e97aada611d809b96a6a6964
This commit is contained in:
parent
d8b49054d5
commit
514a9560a2
9 changed files with 856 additions and 201 deletions
416
libs/map/map.c
416
libs/map/map.c
|
|
@ -25,7 +25,8 @@ int is_floor(const Map *map, int x, int y) {
|
|||
if (!in_bounds(x, y, MAP_WIDTH, MAP_HEIGHT))
|
||||
return 0;
|
||||
return map->tiles[y][x] == TILE_FLOOR || map->tiles[y][x] == TILE_STAIRS || map->tiles[y][x] == TILE_DOOR_OPEN ||
|
||||
map->tiles[y][x] == TILE_DOOR_RUINED || map->tiles[y][x] == TILE_DOOR_CLOSED;
|
||||
map->tiles[y][x] == TILE_DOOR_RUINED || map->tiles[y][x] == TILE_DOOR_CLOSED ||
|
||||
map->tiles[y][x] == TILE_RUBBLE || map->tiles[y][x] == TILE_SHALLOW_WATER;
|
||||
}
|
||||
|
||||
void get_room_center(Room *room, int *cx, int *cy) {
|
||||
|
|
@ -37,9 +38,25 @@ void get_room_center(Room *room, int *cx, int *cy) {
|
|||
static void carve_room(Map *map, Room *room) {
|
||||
for (int y = room->y; y < room->y + room->h; y++) {
|
||||
for (int x = room->x; x < room->x + room->w; x++) {
|
||||
if (in_bounds(x, y, MAP_WIDTH, MAP_HEIGHT)) {
|
||||
map->tiles[y][x] = TILE_FLOOR;
|
||||
if (!in_bounds(x, y, MAP_WIDTH, MAP_HEIGHT))
|
||||
continue;
|
||||
|
||||
int local_x = x - room->x;
|
||||
int local_y = y - room->y;
|
||||
int carved = 1;
|
||||
|
||||
if ((room->type == ROOM_SHRINE || room->type == ROOM_VAULT) &&
|
||||
((local_x == 0 && local_y == 0) || (local_x == room->w - 1 && local_y == 0) ||
|
||||
(local_x == 0 && local_y == room->h - 1) || (local_x == room->w - 1 && local_y == room->h - 1))) {
|
||||
carved = 0;
|
||||
}
|
||||
|
||||
if (room->type == ROOM_CRYPT &&
|
||||
((local_x == 0 || local_x == room->w - 1) && (local_y == 0 || local_y == room->h - 1)))
|
||||
carved = 0;
|
||||
|
||||
if (carved)
|
||||
map->tiles[y][x] = TILE_FLOOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -71,39 +88,125 @@ static int room_overlaps(Room *rooms, int count, Room *new_room) {
|
|||
// Add padding to prevent rooms from touching
|
||||
for (int i = 0; i < count; i++) {
|
||||
Room *r = &rooms[i];
|
||||
if (!(new_room->x > r->x + r->w || new_room->x + new_room->w < r->x || new_room->y > r->y + r->h ||
|
||||
new_room->y + new_room->h < r->y)) {
|
||||
if (!(new_room->x > r->x + r->w + 2 || new_room->x + new_room->w + 2 < r->x || new_room->y > r->y + r->h + 2 ||
|
||||
new_room->y + new_room->h + 2 < r->y)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static RoomType pick_room_type(int floor, int room_index) {
|
||||
if (room_index == 0)
|
||||
return ROOM_START;
|
||||
|
||||
int roll = rng_int(0, 99);
|
||||
if (floor <= 1) {
|
||||
if (roll < 35)
|
||||
return ROOM_GUARD;
|
||||
if (roll < 55)
|
||||
return ROOM_ARMORY;
|
||||
if (roll < 75)
|
||||
return ROOM_SHRINE;
|
||||
return ROOM_CRYPT;
|
||||
}
|
||||
if (floor == 2) {
|
||||
if (roll < 40)
|
||||
return ROOM_CISTERN;
|
||||
if (roll < 60)
|
||||
return ROOM_GUARD;
|
||||
if (roll < 80)
|
||||
return ROOM_SHRINE;
|
||||
return ROOM_CRYPT;
|
||||
}
|
||||
if (floor == 3) {
|
||||
if (roll < 35)
|
||||
return ROOM_CRYPT;
|
||||
if (roll < 60)
|
||||
return ROOM_LIBRARY;
|
||||
if (roll < 80)
|
||||
return ROOM_CISTERN;
|
||||
return ROOM_VAULT;
|
||||
}
|
||||
if (floor == 4) {
|
||||
if (roll < 35)
|
||||
return ROOM_FORGE;
|
||||
if (roll < 55)
|
||||
return ROOM_ARMORY;
|
||||
if (roll < 75)
|
||||
return ROOM_CRYPT;
|
||||
return ROOM_VAULT;
|
||||
}
|
||||
if (roll < 30)
|
||||
return ROOM_VAULT;
|
||||
if (roll < 55)
|
||||
return ROOM_CRYPT;
|
||||
if (roll < 75)
|
||||
return ROOM_FORGE;
|
||||
return ROOM_SHRINE;
|
||||
}
|
||||
|
||||
static void room_size_for_type(RoomType type, int *w, int *h) {
|
||||
switch (type) {
|
||||
case ROOM_START:
|
||||
*w = rng_int(7, 10);
|
||||
*h = rng_int(6, 8);
|
||||
break;
|
||||
case ROOM_GUARD:
|
||||
case ROOM_ARMORY:
|
||||
*w = rng_int(6, 11);
|
||||
*h = rng_int(5, 8);
|
||||
break;
|
||||
case ROOM_SHRINE:
|
||||
case ROOM_VAULT:
|
||||
*w = rng_int(7, 11);
|
||||
*h = rng_int(7, 11);
|
||||
break;
|
||||
case ROOM_CISTERN:
|
||||
*w = rng_int(8, 14);
|
||||
*h = rng_int(6, 10);
|
||||
break;
|
||||
case ROOM_CRYPT:
|
||||
case ROOM_LIBRARY:
|
||||
*w = rng_int(8, 13);
|
||||
*h = rng_int(5, 9);
|
||||
break;
|
||||
case ROOM_FORGE:
|
||||
*w = rng_int(7, 12);
|
||||
*h = rng_int(6, 9);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate rooms for this floor
|
||||
static int generate_rooms(Map *map, Room *rooms, int floor) {
|
||||
int room_count = 0;
|
||||
int attempts = 0;
|
||||
int max_attempts = 100;
|
||||
int max_attempts = 250;
|
||||
|
||||
// Room count varies by floor, but capped at max_rooms
|
||||
int target_rooms = 5 + (floor % 3) + rng_int(0, 3);
|
||||
int target_rooms = 8 + (floor % 3) + rng_int(0, 3);
|
||||
if (target_rooms > MAX_ROOMS)
|
||||
target_rooms = MAX_ROOMS;
|
||||
|
||||
while (room_count < target_rooms && attempts < max_attempts) {
|
||||
attempts++;
|
||||
|
||||
// Random room dimensions
|
||||
int w = rng_int(5, 12);
|
||||
int h = rng_int(5, 10);
|
||||
RoomType type = pick_room_type(floor, room_count);
|
||||
int w, h;
|
||||
room_size_for_type(type, &w, &h);
|
||||
|
||||
// Random position (within map bounds with 1-tile border)
|
||||
int x = rng_int(2, MAP_WIDTH - w - 2);
|
||||
int y = rng_int(2, MAP_HEIGHT - h - 2);
|
||||
int x, y;
|
||||
if (room_count == 0) {
|
||||
x = rng_int(3, 8);
|
||||
y = rng_int(3, MAP_HEIGHT - h - 4);
|
||||
} else {
|
||||
x = rng_int(2, MAP_WIDTH - w - 3);
|
||||
y = rng_int(2, MAP_HEIGHT - h - 3);
|
||||
}
|
||||
|
||||
Room new_room = {x, y, w, h};
|
||||
Room new_room = {x, y, w, h, type};
|
||||
|
||||
// Check for overlap
|
||||
if (!room_overlaps(rooms, room_count, &new_room)) {
|
||||
rooms[room_count] = new_room;
|
||||
carve_room(map, &new_room);
|
||||
|
|
@ -155,6 +258,103 @@ static int tile_in_any_room(int x, int y, Room *rooms, int room_count) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tile_in_room(const Room *room, int x, int y) {
|
||||
return x >= room->x && x < room->x + room->w && y >= room->y && y < room->y + room->h;
|
||||
}
|
||||
|
||||
Room *map_room_at(Map *map, int x, int y) {
|
||||
for (int i = 0; i < map->room_count; i++) {
|
||||
if (tile_in_room(&map->rooms[i], x, y))
|
||||
return &map->rooms[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int protected_room_tile(const Room *room, int x, int y) {
|
||||
int cx, cy;
|
||||
get_room_center((Room *)room, &cx, &cy);
|
||||
return (abs(x - cx) <= 1 && abs(y - cy) <= 1) || x == room->x || y == room->y || x == room->x + room->w - 1 ||
|
||||
y == room->y + room->h - 1;
|
||||
}
|
||||
|
||||
static void set_room_tile(Map *map, const Room *room, int x, int y, TileType tile) {
|
||||
if (!in_bounds(x, y, MAP_WIDTH, MAP_HEIGHT) || !tile_in_room(room, x, y) || protected_room_tile(room, x, y))
|
||||
return;
|
||||
if (map->tiles[y][x] == TILE_FLOOR)
|
||||
map->tiles[y][x] = tile;
|
||||
}
|
||||
|
||||
static void decorate_room(Map *map, const Room *room, int floor) {
|
||||
int cx, cy;
|
||||
get_room_center((Room *)room, &cx, &cy);
|
||||
|
||||
switch (room->type) {
|
||||
case ROOM_START:
|
||||
if (room->w >= 8 && room->h >= 6) {
|
||||
set_room_tile(map, room, room->x + 2, room->y + 2, TILE_RUBBLE);
|
||||
set_room_tile(map, room, room->x + room->w - 3, room->y + room->h - 3, TILE_RUBBLE);
|
||||
}
|
||||
break;
|
||||
case ROOM_GUARD:
|
||||
for (int y = room->y + 2; y < room->y + room->h - 2; y += 3) {
|
||||
set_room_tile(map, room, room->x + 2, y, TILE_STATUE);
|
||||
set_room_tile(map, room, room->x + room->w - 3, y, TILE_STATUE);
|
||||
}
|
||||
break;
|
||||
case ROOM_SHRINE:
|
||||
set_room_tile(map, room, cx - 2, cy, TILE_STATUE);
|
||||
set_room_tile(map, room, cx + 2, cy, TILE_STATUE);
|
||||
set_room_tile(map, room, cx, cy - 2, TILE_RUBBLE);
|
||||
set_room_tile(map, room, cx, cy + 2, TILE_RUBBLE);
|
||||
break;
|
||||
case ROOM_CISTERN:
|
||||
for (int y = cy - 1; y <= cy + 1; y++) {
|
||||
for (int x = cx - 2; x <= cx + 2; x++) {
|
||||
if ((x + y + floor) % 5 != 0)
|
||||
set_room_tile(map, room, x, y, TILE_SHALLOW_WATER);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ROOM_ARMORY:
|
||||
for (int x = room->x + 2; x < room->x + room->w - 2; x += 3) {
|
||||
set_room_tile(map, room, x, room->y + 2, TILE_RUBBLE);
|
||||
set_room_tile(map, room, x, room->y + room->h - 3, TILE_RUBBLE);
|
||||
}
|
||||
break;
|
||||
case ROOM_CRYPT:
|
||||
for (int x = room->x + 2; x < room->x + room->w - 2; x += 3) {
|
||||
set_room_tile(map, room, x, cy - 1, TILE_STATUE);
|
||||
set_room_tile(map, room, x, cy + 1, TILE_RUBBLE);
|
||||
}
|
||||
break;
|
||||
case ROOM_LIBRARY:
|
||||
for (int y = room->y + 2; y < room->y + room->h - 2; y += 2) {
|
||||
set_room_tile(map, room, room->x + 2, y, TILE_STATUE);
|
||||
set_room_tile(map, room, room->x + room->w - 3, y, TILE_RUBBLE);
|
||||
}
|
||||
break;
|
||||
case ROOM_FORGE:
|
||||
for (int y = cy - 1; y <= cy + 1; y++) {
|
||||
set_room_tile(map, room, cx - 2, y, TILE_RUBBLE);
|
||||
set_room_tile(map, room, cx + 2, y, TILE_RUBBLE);
|
||||
}
|
||||
set_room_tile(map, room, cx, cy - 2, TILE_STATUE);
|
||||
break;
|
||||
case ROOM_VAULT:
|
||||
set_room_tile(map, room, cx - 2, cy - 2, TILE_STATUE);
|
||||
set_room_tile(map, room, cx + 2, cy - 2, TILE_STATUE);
|
||||
set_room_tile(map, room, cx - 2, cy + 2, TILE_STATUE);
|
||||
set_room_tile(map, room, cx + 2, cy + 2, TILE_STATUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void decorate_rooms(Map *map, Room *rooms, int room_count, int floor) {
|
||||
for (int i = 0; i < room_count; i++) {
|
||||
decorate_room(map, &rooms[i], floor);
|
||||
}
|
||||
}
|
||||
|
||||
// Place doors at corridor-room junctions.
|
||||
// Doors sit on corridor tiles, not room tiles, so they occupy the actual doorway.
|
||||
static void place_doors(Map *map, Room *rooms, int room_count) {
|
||||
|
|
@ -187,23 +387,56 @@ static void place_doors(Map *map, Room *rooms, int room_count) {
|
|||
}
|
||||
|
||||
// Connect all rooms with corridors
|
||||
static void connect_rooms(Map *map, Room *rooms, int room_count) {
|
||||
for (int i = 0; i < room_count - 1; i++) {
|
||||
int cx1, cy1, cx2, cy2;
|
||||
get_room_center(&rooms[i], &cx1, &cy1);
|
||||
get_room_center(&rooms[i + 1], &cx2, &cy2);
|
||||
static int room_distance2(Room *a, Room *b) {
|
||||
int ax, ay, bx, by;
|
||||
get_room_center(a, &ax, &ay);
|
||||
get_room_center(b, &bx, &by);
|
||||
int dx = ax - bx;
|
||||
int dy = ay - by;
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
// Carve L-shaped corridor between rooms
|
||||
if (rng_int(0, 1) == 0) {
|
||||
carve_h_corridor(map, cx1, cx2, cy1);
|
||||
carve_v_corridor(map, cx2, cy1, cy2);
|
||||
} else {
|
||||
carve_v_corridor(map, cx1, cy1, cy2);
|
||||
carve_h_corridor(map, cx1, cx2, cy2);
|
||||
static void carve_connection(Map *map, Room *a, Room *b) {
|
||||
int cx1, cy1, cx2, cy2;
|
||||
get_room_center(a, &cx1, &cy1);
|
||||
get_room_center(b, &cx2, &cy2);
|
||||
|
||||
if (rng_int(0, 2) == 0) {
|
||||
int mid_x = (cx1 + cx2) / 2 + rng_int(-3, 3);
|
||||
carve_h_corridor(map, cx1, mid_x, cy1);
|
||||
carve_v_corridor(map, mid_x, cy1, cy2);
|
||||
carve_h_corridor(map, mid_x, cx2, cy2);
|
||||
} else if (rng_int(0, 1) == 0) {
|
||||
carve_h_corridor(map, cx1, cx2, cy1);
|
||||
carve_v_corridor(map, cx2, cy1, cy2);
|
||||
} else {
|
||||
carve_v_corridor(map, cx1, cy1, cy2);
|
||||
carve_h_corridor(map, cx1, cx2, cy2);
|
||||
}
|
||||
}
|
||||
|
||||
static void connect_rooms(Map *map, Room *rooms, int room_count) {
|
||||
for (int i = 1; i < room_count; i++) {
|
||||
int nearest = 0;
|
||||
int best = room_distance2(&rooms[i], &rooms[0]);
|
||||
for (int j = 1; j < i; j++) {
|
||||
int dist = room_distance2(&rooms[i], &rooms[j]);
|
||||
if (dist < best) {
|
||||
best = dist;
|
||||
nearest = j;
|
||||
}
|
||||
}
|
||||
carve_connection(map, &rooms[i], &rooms[nearest]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < room_count; i++) {
|
||||
if (rng_int(0, 99) >= 28)
|
||||
continue;
|
||||
int j = rng_int(0, room_count - 1);
|
||||
if (i != j)
|
||||
carve_connection(map, &rooms[i], &rooms[j]);
|
||||
}
|
||||
|
||||
// Place doors after all corridors are carved
|
||||
place_doors(map, rooms, room_count);
|
||||
}
|
||||
|
||||
|
|
@ -284,18 +517,121 @@ void get_random_floor_tile(Map *map, int *x, int *y, int attempts) {
|
|||
}
|
||||
}
|
||||
|
||||
int get_room_floor_tile(const Map *map, const Room *room, int *x, int *y) {
|
||||
*x = -1;
|
||||
*y = -1;
|
||||
|
||||
int cx = room->x + room->w / 2;
|
||||
int cy = room->y + room->h / 2;
|
||||
if (in_bounds(cx, cy, MAP_WIDTH, MAP_HEIGHT) && map->tiles[cy][cx] == TILE_FLOOR) {
|
||||
*x = cx;
|
||||
*y = cy;
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int radius = 1; radius < room->w + room->h; radius++) {
|
||||
for (int yy = cy - radius; yy <= cy + radius; yy++) {
|
||||
for (int xx = cx - radius; xx <= cx + radius; xx++) {
|
||||
if (!tile_in_room(room, xx, yy) || !in_bounds(xx, yy, MAP_WIDTH, MAP_HEIGHT))
|
||||
continue;
|
||||
if (map->tiles[yy][xx] == TILE_FLOOR) {
|
||||
*x = xx;
|
||||
*y = yy;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_random_floor_tile_excluding_room(Map *map, const Room *excluded, int *x, int *y, int attempts) {
|
||||
*x = -1;
|
||||
*y = -1;
|
||||
|
||||
for (int i = 0; i < attempts; i++) {
|
||||
int tx = rng_int(1, MAP_WIDTH - 2);
|
||||
int ty = rng_int(1, MAP_HEIGHT - 2);
|
||||
|
||||
if (map->tiles[ty][tx] == TILE_FLOOR && (excluded == NULL || !tile_in_room(excluded, tx, ty))) {
|
||||
*x = tx;
|
||||
*y = ty;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int ty = 1; ty < MAP_HEIGHT - 1; ty++) {
|
||||
for (int tx = 1; tx < MAP_WIDTH - 1; tx++) {
|
||||
if (map->tiles[ty][tx] == TILE_FLOOR && (excluded == NULL || !tile_in_room(excluded, tx, ty))) {
|
||||
*x = tx;
|
||||
*y = ty;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int map_validate_layout(const Map *map) {
|
||||
if (map->room_count <= 0)
|
||||
return 0;
|
||||
|
||||
int sx, sy;
|
||||
if (!get_room_floor_tile(map, &map->rooms[0], &sx, &sy))
|
||||
return 0;
|
||||
|
||||
unsigned char visited[MAP_HEIGHT][MAP_WIDTH];
|
||||
Vec2 queue[MAP_HEIGHT * MAP_WIDTH];
|
||||
memset(visited, 0, sizeof(visited));
|
||||
|
||||
int head = 0;
|
||||
int tail = 0;
|
||||
queue[tail++] = (Vec2){sx, sy};
|
||||
visited[sy][sx] = 1;
|
||||
|
||||
while (head < tail) {
|
||||
Vec2 p = queue[head++];
|
||||
const int dx[4] = {0, 0, 1, -1};
|
||||
const int dy[4] = {1, -1, 0, 0};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int nx = p.x + dx[i];
|
||||
int ny = p.y + dy[i];
|
||||
if (!in_bounds(nx, ny, MAP_WIDTH, MAP_HEIGHT) || visited[ny][nx] || !is_floor(map, nx, ny))
|
||||
continue;
|
||||
visited[ny][nx] = 1;
|
||||
queue[tail++] = (Vec2){nx, ny};
|
||||
}
|
||||
}
|
||||
|
||||
int stairs = 0;
|
||||
for (int y = 0; y < MAP_HEIGHT; y++) {
|
||||
for (int x = 0; x < MAP_WIDTH; x++) {
|
||||
if (is_floor(map, x, y) && !visited[y][x])
|
||||
return 0;
|
||||
if (map->tiles[y][x] == TILE_STAIRS) {
|
||||
if (!visited[y][x])
|
||||
return 0;
|
||||
stairs++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stairs == 1;
|
||||
}
|
||||
|
||||
void dungeon_generate(Dungeon *d, Map *map, int floor_num) {
|
||||
// Initialize map to all walls
|
||||
map_init(map);
|
||||
for (int attempt = 0; attempt < 4; attempt++) {
|
||||
map_init(map);
|
||||
map->room_count = generate_rooms(map, map->rooms, floor_num);
|
||||
connect_rooms(map, map->rooms, map->room_count);
|
||||
decorate_rooms(map, map->rooms, map->room_count, floor_num);
|
||||
place_stairs(map, map->rooms, map->room_count);
|
||||
|
||||
// Generate rooms
|
||||
map->room_count = generate_rooms(map, map->rooms, floor_num);
|
||||
|
||||
// Connect rooms with corridors
|
||||
connect_rooms(map, map->rooms, map->room_count);
|
||||
|
||||
// Place stairs in last room
|
||||
place_stairs(map, map->rooms, map->room_count);
|
||||
if (map_validate_layout(map))
|
||||
break;
|
||||
}
|
||||
|
||||
// Store dungeon state
|
||||
d->current_floor = floor_num;
|
||||
|
|
@ -326,7 +662,7 @@ static int trace_line_of_sight(const Map *map, int x1, int y1, int x2, int y2) {
|
|||
return 1;
|
||||
|
||||
TileType t = map->tiles[y][x];
|
||||
if ((t == TILE_WALL || t == TILE_DOOR_CLOSED) && !(x == x1 && y == y1))
|
||||
if ((t == TILE_WALL || t == TILE_DOOR_CLOSED || t == TILE_STATUE) && !(x == x1 && y == y1))
|
||||
return 0;
|
||||
|
||||
int e2 = 2 * err;
|
||||
|
|
@ -363,7 +699,7 @@ static int is_solid(const Map *map, int sub_x, int sub_y) {
|
|||
if (tx < 0 || tx >= map_w || ty < 0 || ty >= map_h)
|
||||
return 1;
|
||||
TileType t = map->tiles[ty][tx];
|
||||
return t == TILE_WALL || t == TILE_DOOR_CLOSED;
|
||||
return t == TILE_WALL || t == TILE_DOOR_CLOSED || t == TILE_STATUE;
|
||||
}
|
||||
|
||||
static float smoothstep_light(float edge0, float edge1, float x) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ void map_init(Map *map);
|
|||
|
||||
// Get a random floor tile position
|
||||
void get_random_floor_tile(Map *map, int *x, int *y, int attempts);
|
||||
int get_room_floor_tile(const Map *map, const Room *room, int *x, int *y);
|
||||
int get_random_floor_tile_excluding_room(Map *map, const Room *excluded, int *x, int *y, int attempts);
|
||||
Room *map_room_at(Map *map, int x, int y);
|
||||
int map_validate_layout(const Map *map);
|
||||
|
||||
// Visibility / Fog of War
|
||||
int is_in_view_range(int x, int y, int view_x, int view_y, int range);
|
||||
|
|
|
|||
|
|
@ -42,44 +42,67 @@ void paint_wall_tile(Tileset *ts, int id, int variant) {
|
|||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Base color is much darker for better contrast against floor
|
||||
Color base = variant == 0 ? (Color){45, 42, 38, 255} : (Color){35, 32, 28, 255};
|
||||
DrawRectangle((int)off.x, (int)off.y, w, h, base);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
Color base = variant == 0 ? (Color){38, 37, 39, 255} : (Color){33, 32, 35, 255};
|
||||
Color edge = variant == 0 ? (Color){48, 46, 46, 255} : (Color){42, 40, 41, 255};
|
||||
Color shadow = variant == 0 ? (Color){24, 23, 25, 255} : (Color){20, 19, 21, 255};
|
||||
Color highlight = variant == 0 ? (Color){56, 54, 52, 255} : (Color){49, 47, 46, 255};
|
||||
Color moss = variant == 0 ? (Color){38, 58, 42, 255} : (Color){28, 45, 34, 255};
|
||||
|
||||
// Brick pattern
|
||||
int brick_h = h / 3;
|
||||
int brick_w = w / 2;
|
||||
Color mortar = (Color){25, 22, 18, 255};
|
||||
Color brick_light = variant == 0 ? (Color){70, 65, 60, 255} : (Color){50, 47, 43, 255};
|
||||
Color brick_dark = variant == 0 ? (Color){40, 37, 33, 255} : (Color){30, 27, 24, 255};
|
||||
DrawRectangle(ox, oy, w, h, base);
|
||||
lcg_srand((unsigned int)(variant * 4099 + id * 9176));
|
||||
|
||||
int row_y = 0;
|
||||
for (int row = 0; row < 3; row++) {
|
||||
int y = (int)off.y + row * brick_h;
|
||||
int offset_x = (row % 2 == 0) ? 0 : brick_w / 2;
|
||||
for (int col = -1; col < 3; col++) {
|
||||
int x = (int)off.x + offset_x + col * brick_w;
|
||||
if (x >= (int)off.x + w)
|
||||
break;
|
||||
if (x + brick_w <= (int)off.x)
|
||||
continue;
|
||||
|
||||
// Clip to tile bounds
|
||||
int draw_x = x < (int)off.x ? (int)off.x : x;
|
||||
int draw_w = brick_w;
|
||||
if (draw_x + draw_w > (int)off.x + w)
|
||||
draw_w = (int)off.x + w - draw_x;
|
||||
|
||||
Color c = ((col + row) % 2 == 0) ? brick_light : brick_dark;
|
||||
DrawRectangle(draw_x, y, draw_w, brick_h - 1, c);
|
||||
int block_h = row == 2 ? h - row_y : lcg_rand_range(5, 6);
|
||||
int x = 0;
|
||||
int stagger = (row % 2) ? lcg_rand_range(-4, 0) : lcg_rand_range(-1, 2);
|
||||
while (x < w) {
|
||||
int block_w = lcg_rand_range(7, 12);
|
||||
int bx = ox + x + stagger;
|
||||
int by = oy + row_y;
|
||||
int bw = block_w;
|
||||
if (bx < ox) {
|
||||
bw -= ox - bx;
|
||||
bx = ox;
|
||||
}
|
||||
if (bx + bw > ox + w)
|
||||
bw = ox + w - bx;
|
||||
if (bw > 0) {
|
||||
Color face = ((x + row + variant) % 3 == 0) ? edge : base;
|
||||
DrawRectangle(bx, by, bw, block_h, face);
|
||||
if (row == 0)
|
||||
DrawLine(bx, by, bx + bw - 1, by, highlight);
|
||||
DrawLine(bx, by + block_h - 1, bx + bw - 1, by + block_h - 1, shadow);
|
||||
if (bw > 5 && block_h > 4 && lcg_rand_range(0, 99) < 18)
|
||||
DrawPixel(bx + lcg_rand_range(1, bw - 2), by + lcg_rand_range(1, block_h - 2), shadow);
|
||||
}
|
||||
x += block_w;
|
||||
}
|
||||
row_y += block_h;
|
||||
}
|
||||
|
||||
// Mortar lines
|
||||
for (int row = 1; row < 3; row++) {
|
||||
int y = (int)off.y + row * brick_h;
|
||||
DrawLine((int)off.x, y, (int)off.x + w - 1, y, mortar);
|
||||
for (int i = 0; i < 3 + variant; i++) {
|
||||
int px = ox + lcg_rand_range(1, w - 2);
|
||||
int py = oy + lcg_rand_range(1, h - 2);
|
||||
DrawPixel(px, py, lcg_rand_range(0, 1) ? highlight : shadow);
|
||||
}
|
||||
|
||||
if (variant == 1) {
|
||||
DrawLine(ox + 3, oy + 1, ox + 5, oy + 5, shadow);
|
||||
DrawLine(ox + 5, oy + 5, ox + 4, oy + 8, shadow);
|
||||
DrawLine(ox + 11, oy + 4, ox + 8, oy + 7, shadow);
|
||||
} else {
|
||||
DrawLine(ox + 9, oy + 2, ox + 12, oy + 5, shadow);
|
||||
DrawLine(ox + 12, oy + 5, ox + 10, oy + 9, shadow);
|
||||
DrawPixel(ox + 3, oy + 13, moss);
|
||||
DrawPixel(ox + 4, oy + 13, moss);
|
||||
DrawPixel(ox + 4, oy + 14, moss);
|
||||
}
|
||||
|
||||
DrawRectangle(ox, oy + h - 2, w, 2, (Color){16, 15, 17, 255});
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
|
|
@ -95,42 +118,44 @@ void paint_floor_tile(Tileset *ts, int id, int variant) {
|
|||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Base stone color - lighter than walls for contrast
|
||||
Color base = (Color){75, 72, 68, 255};
|
||||
DrawRectangle((int)off.x, (int)off.y, w, h, base);
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
Color base = variant == 0 ? (Color){61, 58, 55, 255}
|
||||
: variant == 1 ? (Color){67, 63, 58, 255}
|
||||
: variant == 2 ? (Color){56, 55, 58, 255}
|
||||
: (Color){64, 59, 53, 255};
|
||||
Color bevel = (Color){86, 82, 75, 255};
|
||||
Color seam = (Color){34, 32, 31, 255};
|
||||
Color chip = (Color){43, 41, 40, 255};
|
||||
|
||||
// Seeded noise based on variant
|
||||
DrawRectangle(ox, oy, w, h, base);
|
||||
lcg_srand((unsigned int)(variant * 7919 + id * 104729));
|
||||
|
||||
// Dithered noise dots - lighter shades
|
||||
int num_dots = 8 + variant * 4;
|
||||
int split_x = lcg_rand_range(6, 10);
|
||||
int split_y = lcg_rand_range(6, 10);
|
||||
DrawLine(ox + split_x, oy + 1, ox + split_x, oy + h - 2, seam);
|
||||
DrawLine(ox + 1, oy + split_y, ox + w - 2, oy + split_y, seam);
|
||||
DrawLine(ox + 1, oy + 1, ox + w - 2, oy + 1, bevel);
|
||||
DrawLine(ox + 1, oy + 1, ox + 1, oy + h - 2, bevel);
|
||||
DrawLine(ox + 1, oy + h - 2, ox + w - 2, oy + h - 2, seam);
|
||||
DrawLine(ox + w - 2, oy + 1, ox + w - 2, oy + h - 2, seam);
|
||||
|
||||
int num_dots = 14 + variant * 5;
|
||||
for (int i = 0; i < num_dots; i++) {
|
||||
int px = (int)off.x + lcg_rand_range(1, w - 2);
|
||||
int py = (int)off.y + lcg_rand_range(1, h - 2);
|
||||
int shade = lcg_rand_range(0, 3);
|
||||
Color c;
|
||||
if (shade == 0)
|
||||
c = (Color){85, 82, 78, 255};
|
||||
else if (shade == 1)
|
||||
c = (Color){65, 62, 58, 255};
|
||||
else
|
||||
c = (Color){90, 87, 83, 255};
|
||||
int px = ox + lcg_rand_range(1, w - 2);
|
||||
int py = oy + lcg_rand_range(1, h - 2);
|
||||
Color c = lcg_rand_range(0, 2) == 0 ? bevel : chip;
|
||||
DrawPixel(px, py, c);
|
||||
}
|
||||
|
||||
// Occasional crack line
|
||||
if (variant >= 2) {
|
||||
int crack_x = (int)off.x + lcg_rand_range(2, w - 3);
|
||||
int crack_y = (int)off.y + lcg_rand_range(2, h - 3);
|
||||
int crack_len = lcg_rand_range(2, 4);
|
||||
int crack_dir = lcg_rand_range(0, 1); // 0 = horizontal, 1 = vertical
|
||||
Color crack_color = (Color){55, 52, 48, 255};
|
||||
for (int i = 0; i < crack_len; i++) {
|
||||
if (crack_dir == 0)
|
||||
DrawPixel(crack_x + i, crack_y, crack_color);
|
||||
else
|
||||
DrawPixel(crack_x, crack_y + i, crack_color);
|
||||
}
|
||||
if (variant >= 1) {
|
||||
int crack_x = ox + lcg_rand_range(3, w - 4);
|
||||
int crack_y = oy + lcg_rand_range(3, h - 4);
|
||||
DrawPixel(crack_x, crack_y, seam);
|
||||
DrawPixel(crack_x + 1, crack_y, seam);
|
||||
DrawPixel(crack_x + 1, crack_y + 1, seam);
|
||||
if (variant >= 2)
|
||||
DrawPixel(crack_x + 2, crack_y + 2, seam);
|
||||
}
|
||||
|
||||
EndTextureMode();
|
||||
|
|
@ -148,32 +173,25 @@ void paint_stairs_tile(Tileset *ts, int id) {
|
|||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Dark stone background
|
||||
DrawRectangle((int)off.x, (int)off.y, w, h, (Color){40, 38, 35, 255});
|
||||
int ox = (int)off.x;
|
||||
int oy = (int)off.y;
|
||||
DrawRectangle(ox, oy, w, h, (Color){31, 29, 27, 255});
|
||||
|
||||
// Stair steps (3 steps)
|
||||
int step_h = h / 4;
|
||||
Color step_light = (Color){100, 95, 90, 255};
|
||||
Color step_dark = (Color){60, 57, 53, 255};
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int y = (int)off.y + h - (i + 1) * step_h;
|
||||
int inset = i * 2;
|
||||
int x = (int)off.x + inset;
|
||||
DrawRectangle(x, y, w - inset * 2, step_h - 1, step_light);
|
||||
DrawLine(x, y + step_h - 1, x + w - inset * 2 - 1, y + step_h - 1, step_dark);
|
||||
Color face = (Color){82, 76, 68, 255};
|
||||
Color lip = (Color){118, 106, 84, 255};
|
||||
Color drop = (Color){28, 25, 23, 255};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int y = oy + 3 + i * 3;
|
||||
int inset = i + 1;
|
||||
DrawRectangle(ox + inset, y, w - inset * 2, 2, face);
|
||||
DrawLine(ox + inset, y, ox + w - inset - 1, y, lip);
|
||||
DrawLine(ox + inset, y + 2, ox + w - inset - 1, y + 2, drop);
|
||||
}
|
||||
|
||||
// ">" symbol on top step
|
||||
int top_y = (int)off.y + 2;
|
||||
int cx = (int)off.x + w / 2;
|
||||
Color arrow = (Color){180, 175, 170, 255};
|
||||
DrawPixel(cx, top_y, arrow);
|
||||
DrawPixel(cx - 1, top_y + 1, arrow);
|
||||
DrawPixel(cx + 1, top_y + 1, arrow);
|
||||
DrawPixel(cx - 2, top_y + 2, arrow);
|
||||
DrawPixel(cx + 2, top_y + 2, arrow);
|
||||
DrawPixel(cx, top_y + 3, arrow);
|
||||
DrawLine(ox + 4, oy + 2, ox + 11, oy + 2, (Color){120, 111, 93, 255});
|
||||
DrawPixel(ox + 7, oy + 1, (Color){142, 134, 114, 255});
|
||||
DrawPixel(ox + 8, oy + 1, (Color){142, 134, 114, 255});
|
||||
DrawRectangle(ox + 6, oy + 13, 4, 1, (Color){12, 10, 9, 255});
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
|
@ -634,23 +652,22 @@ void paint_door_closed_tile(Tileset *ts, int id) {
|
|||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Wooden door frame
|
||||
Color wood_dark = (Color){100, 70, 40, 255};
|
||||
Color wood_light = (Color){140, 100, 60, 255};
|
||||
Color wood_mid = (Color){120, 85, 50, 255};
|
||||
Color iron = (Color){35, 32, 30, 255};
|
||||
Color wood_dark = (Color){72, 47, 30, 255};
|
||||
Color wood_mid = (Color){111, 73, 42, 255};
|
||||
Color wood_light = (Color){151, 103, 58, 255};
|
||||
|
||||
// Frame
|
||||
DrawRectangle(ox, oy, w, h, wood_dark);
|
||||
// Panels
|
||||
DrawRectangle(ox + 2, oy + 2, w - 4, h - 4, wood_mid);
|
||||
// Inner panel
|
||||
DrawRectangle(ox + 4, oy + 4, w - 8, h - 8, wood_light);
|
||||
// Cross pattern
|
||||
DrawRectangle(ox + 7, oy + 2, 2, h - 4, wood_dark);
|
||||
DrawRectangle(ox + 2, oy + 7, w - 4, 2, wood_dark);
|
||||
// Handle
|
||||
DrawPixel(ox + 12, oy + 8, (Color){200, 180, 50, 255});
|
||||
DrawPixel(ox + 12, oy + 9, (Color){200, 180, 50, 255});
|
||||
DrawRectangle(ox, oy, w, h, iron);
|
||||
DrawRectangle(ox + 2, oy + 1, w - 4, h - 2, wood_dark);
|
||||
DrawRectangle(ox + 3, oy + 2, 3, h - 4, wood_mid);
|
||||
DrawRectangle(ox + 7, oy + 2, 3, h - 4, wood_light);
|
||||
DrawRectangle(ox + 11, oy + 2, 2, h - 4, wood_mid);
|
||||
DrawRectangle(ox + 2, oy + 5, w - 4, 2, iron);
|
||||
DrawRectangle(ox + 2, oy + 11, w - 4, 2, iron);
|
||||
DrawPixel(ox + 4, oy + 3, (Color){180, 129, 72, 255});
|
||||
DrawPixel(ox + 8, oy + 9, (Color){84, 53, 32, 255});
|
||||
DrawPixel(ox + 12, oy + 8, (Color){208, 169, 69, 255});
|
||||
DrawPixel(ox + 12, oy + 9, (Color){166, 124, 51, 255});
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
|
@ -669,17 +686,19 @@ void paint_door_open_tile(Tileset *ts, int id) {
|
|||
|
||||
BeginTextureMode(ts->render_target);
|
||||
|
||||
// Open door - shows floor with door frame on sides
|
||||
Color floor = (Color){75, 72, 68, 255};
|
||||
Color wood_dark = (Color){100, 70, 40, 255};
|
||||
Color floor = (Color){58, 55, 52, 255};
|
||||
Color seam = (Color){32, 30, 29, 255};
|
||||
Color wood_dark = (Color){72, 47, 30, 255};
|
||||
Color wood_light = (Color){131, 88, 49, 255};
|
||||
|
||||
// Floor
|
||||
DrawRectangle(ox, oy, w, h, floor);
|
||||
// Door frame on left side (open)
|
||||
DrawLine(ox + 7, oy + 1, ox + 7, oy + h - 2, seam);
|
||||
DrawLine(ox + 1, oy + 8, ox + w - 2, oy + 8, seam);
|
||||
DrawRectangle(ox, oy, 3, h, wood_dark);
|
||||
// Hinges
|
||||
DrawPixel(ox + 1, oy + 4, (Color){80, 80, 80, 255});
|
||||
DrawPixel(ox + 1, oy + 12, (Color){80, 80, 80, 255});
|
||||
DrawRectangle(ox + 2, oy + 2, 2, h - 4, wood_light);
|
||||
DrawPixel(ox + 1, oy + 4, (Color){72, 72, 72, 255});
|
||||
DrawPixel(ox + 1, oy + 11, (Color){72, 72, 72, 255});
|
||||
DrawRectangle(ox + 4, oy + 13, 6, 1, (Color){25, 20, 17, 255});
|
||||
|
||||
EndTextureMode();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue