various: fixup doors
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Id81f32d86f70a7df99c2ad3d478646416a6a6964
This commit is contained in:
parent
00b3798ae0
commit
d8b49054d5
6 changed files with 345 additions and 87 deletions
|
|
@ -15,6 +15,9 @@ void map_init(Map *map) {
|
|||
}
|
||||
memset(map->light_map, 0, sizeof(map->light_map));
|
||||
memset(map->remembered, 0, sizeof(map->remembered));
|
||||
memset(map->door_open_from, 255, sizeof(map->door_open_from));
|
||||
memset(map->door_anim_timer, 0, sizeof(map->door_anim_timer));
|
||||
memset(map->door_anim_target, 0, sizeof(map->door_anim_target));
|
||||
map->room_count = 0;
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +25,7 @@ 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_RUINED || map->tiles[y][x] == TILE_DOOR_CLOSED;
|
||||
}
|
||||
|
||||
void get_room_center(Room *room, int *cx, int *cy) {
|
||||
|
|
@ -128,13 +131,59 @@ static int is_room_boundary(Map *map, int x, int y) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Place doors at corridor-room junctions
|
||||
// DISABLED: Door placement removed per user request
|
||||
// A corridor tile is a narrow floor passage with walls on at least 2 sides.
|
||||
static int is_corridor_tile(const Map *map, int x, int y) {
|
||||
if (map->tiles[y][x] != TILE_FLOOR)
|
||||
return 0;
|
||||
int walls = 0;
|
||||
if (y > 0 && map->tiles[y - 1][x] == TILE_WALL)
|
||||
walls++;
|
||||
if (y < MAP_HEIGHT - 1 && map->tiles[y + 1][x] == TILE_WALL)
|
||||
walls++;
|
||||
if (x > 0 && map->tiles[y][x - 1] == TILE_WALL)
|
||||
walls++;
|
||||
if (x < MAP_WIDTH - 1 && map->tiles[y][x + 1] == TILE_WALL)
|
||||
walls++;
|
||||
return walls >= 2;
|
||||
}
|
||||
|
||||
static int tile_in_any_room(int x, int y, Room *rooms, int room_count) {
|
||||
for (int i = 0; i < room_count; i++) {
|
||||
if (x >= rooms[i].x && x < rooms[i].x + rooms[i].w && y >= rooms[i].y && y < rooms[i].y + rooms[i].h)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
(void)map;
|
||||
(void)rooms;
|
||||
(void)room_count;
|
||||
// No-op: doors disabled
|
||||
for (int y = 0; y < MAP_HEIGHT; y++) {
|
||||
for (int x = 0; x < MAP_WIDTH; x++) {
|
||||
if (map->tiles[y][x] != TILE_FLOOR)
|
||||
continue;
|
||||
if (!is_corridor_tile(map, x, y))
|
||||
continue;
|
||||
// Don't place doors inside rooms — corridors are between rooms
|
||||
if (tile_in_any_room(x, y, rooms, room_count))
|
||||
continue;
|
||||
// Corridor must be adjacent to a room floor tile
|
||||
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 = x + dx[i];
|
||||
int ny = y + dy[i];
|
||||
if (!in_bounds(nx, ny, MAP_WIDTH, MAP_HEIGHT))
|
||||
continue;
|
||||
if (map->tiles[ny][nx] != TILE_FLOOR)
|
||||
continue;
|
||||
if (tile_in_any_room(nx, ny, rooms, room_count)) {
|
||||
map->tiles[y][x] = TILE_DOOR_CLOSED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Connect all rooms with corridors
|
||||
|
|
@ -276,7 +325,8 @@ static int trace_line_of_sight(const Map *map, int x1, int y1, int x2, int y2) {
|
|||
if (x == x2 && y == y2)
|
||||
return 1;
|
||||
|
||||
if (map->tiles[y][x] == TILE_WALL && !(x == x1 && y == y1))
|
||||
TileType t = map->tiles[y][x];
|
||||
if ((t == TILE_WALL || t == TILE_DOOR_CLOSED) && !(x == x1 && y == y1))
|
||||
return 0;
|
||||
|
||||
int e2 = 2 * err;
|
||||
|
|
@ -421,7 +471,17 @@ void compute_lighting(Map *map, const LightSource *sources, int num_sources) {
|
|||
|
||||
for (int ty = 0; ty < MAP_HEIGHT; ty++) {
|
||||
for (int tx = 0; tx < MAP_WIDTH; tx++) {
|
||||
if (tile_brightness(map, tx, ty) > LIGHT_SIGHT_THRESHOLD)
|
||||
int max_bright = 0;
|
||||
int bx = tx * SUB_TILE_RES;
|
||||
int by = ty * SUB_TILE_RES;
|
||||
for (int dy = 0; dy < SUB_TILE_RES; dy++) {
|
||||
for (int dx = 0; dx < SUB_TILE_RES; dx++) {
|
||||
int v = map->light_map[by + dy][bx + dx];
|
||||
if (v > max_bright)
|
||||
max_bright = v;
|
||||
}
|
||||
}
|
||||
if (max_bright > LIGHT_SIGHT_THRESHOLD)
|
||||
map->remembered[ty][tx] = 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue