@greenborn/mapa-voxel-back 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +107 -2
- package/package.json +36 -4
- package/src/formato/chunk_compacto.js +263 -0
- package/src/generador/cartel_tienda.js +118 -0
- package/src/generador/construirMapa.js +447 -0
- package/src/generador/excavar_refugios.js +32 -0
- package/src/generador/genera_casa/bathroom_impl.js +87 -0
- package/src/generador/genera_casa/bathrooms_insert.js +104 -0
- package/src/generador/genera_casa/generadorCasa.js +470 -0
- package/src/generador/genera_casa/generadorCasaConexiones.js +299 -0
- package/src/generador/genera_casa/generadorCasaPisos.js +816 -0
- package/src/generador/genera_casa/generadorCasaVentanas.js +361 -0
- package/src/generador/genera_casa/ubicacionSalaCasa.js +486 -0
- package/src/generador/genera_nidos.js +74 -0
- package/src/generador/genera_refugios.js +301 -0
- package/src/generador/genera_tiendas.js +200 -0
- package/src/generador/mapConfig.js +549 -0
- package/src/generador/mapType3.js +635 -0
- package/src/generador/mapType3Block.js +476 -0
- package/src/generador/mapType3Center.js +137 -0
- package/src/generador/mapType3Parcel.js +63 -0
- package/src/generador/mapType3Utils.js +299 -0
- package/src/generador/volumeBuffer.js +210 -0
- package/src/index.js +23 -0
- package/src/plugins/datos.js +111 -0
- package/src/plugins/registro.js +48 -0
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
import { WORLD_CONFIG, BLOCK_TYPES, generateMapPNGs } from './mapConfig.js';
|
|
2
|
+
import { VolumeBuffer, computeColumnHeights } from './volumeBuffer.js';
|
|
3
|
+
import { excavarRefugios } from './excavar_refugios.js';
|
|
4
|
+
import { blockZoneSize, veredaWidth, patternSize, processBlock, TIPOS_SIN_LUZ_INTERIOR } from './mapType3Block.js';
|
|
5
|
+
import { computeCenter } from './mapType3Center.js';
|
|
6
|
+
import { addWindows,
|
|
7
|
+
DEFAULT_WINDOW_HEIGHT_VALUE as DEFAULT_WINDOW_HEIGHT,
|
|
8
|
+
DEFAULT_WINDOW_ELEVATION_VALUE as DEFAULT_WINDOW_ELEVATION } from './genera_casa/generadorCasaVentanas.js';
|
|
9
|
+
import { filterStructuresInBounds, cleanWindows, carveInteriorConnections, finalizeVolume, rangesOverlap, sameLevel } from './mapType3Utils.js';
|
|
10
|
+
import { carveStairs, buildRoofParapets, buildRoofExtras } from './genera_casa/generadorCasaPisos.js';
|
|
11
|
+
import { pintarCarteles } from './cartel_tienda.js';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// toggle para habilitar/deshabilitar la creación automática de puertas
|
|
15
|
+
// entre salas adyacentes. Al desactivarlo las habitaciones permanecen
|
|
16
|
+
// separadas; la posibilidad queda para el futuro.
|
|
17
|
+
const ENABLE_INTERIOR_CONNECTIONS = false;
|
|
18
|
+
|
|
19
|
+
// Generador de mapa tipo 3: ENTAMADO de cuadras y calles.
|
|
20
|
+
// (modularizado) la lógica de cada cuadra se extrajo a mapType3Block.js; el archivo
|
|
21
|
+
// principal trazará calles y cuadras y delegará veredas, parterres y parcelas a
|
|
22
|
+
// dicho módulo.
|
|
23
|
+
// - Cuadras: zonas cuadradas de 176x176 bloques, al nivel del suelo (superficie)
|
|
24
|
+
// - Calles: franjas de 10 bloques de ancho que cruzan las cuadras; la superficie de la calle queda 1 bloque por debajo de la cuadras
|
|
25
|
+
// - En el interior de cada cuadra se subdivide en terrenos y para cada terreno se coloca
|
|
26
|
+
// una casa. Las casas ya no son una única sala central sino un conjunto de dormitorios
|
|
27
|
+
// (cocina, comedor, living, dormitorios, baños).
|
|
28
|
+
// * La anchura de la casa se asegura al menos 30 bloques para permitir dos estancias
|
|
29
|
+
// de 15 de ancho al frente.
|
|
30
|
+
// * Los dormitorios se ubican en dos columnas (dos dormitorios lado a lado) separadas
|
|
31
|
+
// por un **pasillo central de 4 bloques de ancho**. El código calcula primero el ancho
|
|
32
|
+
// disponible para habitaciones, reparte ese ancho en dos columnas y coloca el pasillo
|
|
33
|
+
// en el centro.
|
|
34
|
+
// * Los dormitorios se colocan uno tras otro en profundidad; si por restricciones de
|
|
35
|
+
// tamaño no pueden alinearse perfectamente, el pasillo asegura la conexión interna.
|
|
36
|
+
// * Se respetan los límites del terreno: si una habitación no cabe se omite.
|
|
37
|
+
// Se generan ventanas y puertas de acuerdo a la orientación y reglas probabilísticas.
|
|
38
|
+
function generateMapType3(width, depth, volumeHeight) {
|
|
39
|
+
const heightMap = [];
|
|
40
|
+
const maxHeightMap = [];
|
|
41
|
+
const structures = [];
|
|
42
|
+
|
|
43
|
+
// constantes de cuadras y veredas importadas desde mapType3Block.js
|
|
44
|
+
const baseY = Math.floor(volumeHeight / 2); // nivel base (topmost solid block para cuadras)
|
|
45
|
+
|
|
46
|
+
// Inicializar heightMap, maxHeightMap y surfaceTypeMap con el patrón cuadras/calles/veredas
|
|
47
|
+
const surfaceTypeMap = [];
|
|
48
|
+
for (let x = 0; x < width; x++) {
|
|
49
|
+
heightMap[x] = [];
|
|
50
|
+
maxHeightMap[x] = [];
|
|
51
|
+
surfaceTypeMap[x] = [];
|
|
52
|
+
for (let z = 0; z < depth; z++) {
|
|
53
|
+
const inStreetX = (x % patternSize) >= blockZoneSize;
|
|
54
|
+
const inStreetZ = (z % patternSize) >= blockZoneSize;
|
|
55
|
+
const isStreet = inStreetX || inStreetZ;
|
|
56
|
+
|
|
57
|
+
// heightMap almacena la "altura de superficie" como la primera capa de aire (convención usada por el cliente)
|
|
58
|
+
// - cuadras y veredas: topmost solid = baseY + 1
|
|
59
|
+
// - calles: topmost solid = baseY
|
|
60
|
+
const heightValue = isStreet ? baseY : (baseY + 1);
|
|
61
|
+
heightMap[x][z] = heightValue;
|
|
62
|
+
maxHeightMap[x][z] = heightValue;
|
|
63
|
+
|
|
64
|
+
// Determinar el tipo de bloque de superficie para esta celda
|
|
65
|
+
if (isStreet) {
|
|
66
|
+
surfaceTypeMap[x][z] = BLOCK_TYPES.ASPHALT;
|
|
67
|
+
} else {
|
|
68
|
+
// Dentro de una cuadra: comprobar si corresponde a la franja de vereda
|
|
69
|
+
const posInBlockX = x % patternSize;
|
|
70
|
+
const posInBlockZ = z % patternSize;
|
|
71
|
+
const isSidewalk = (posInBlockX < veredaWidth || posInBlockX >= (blockZoneSize - veredaWidth)) ||
|
|
72
|
+
(posInBlockZ < veredaWidth || posInBlockZ >= (blockZoneSize - veredaWidth));
|
|
73
|
+
surfaceTypeMap[x][z] = isSidewalk ? BLOCK_TYPES.VEREDA : BLOCK_TYPES.GREEN;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// dimensiones de la sala inicial y de las casas (altura de casa igual a sala)
|
|
79
|
+
const roomWidth = 12;
|
|
80
|
+
const roomHeight = 12;
|
|
81
|
+
const roomDepth = 12;
|
|
82
|
+
|
|
83
|
+
const entities = [];
|
|
84
|
+
// zonas de control del modo equipos (parcelas, veredas, calles y parques);
|
|
85
|
+
// ver plan_zonas_control.md. Son geometría estática: se calculan una sola
|
|
86
|
+
// vez acá y viajan con el resto del mapa.
|
|
87
|
+
const zonas = [];
|
|
88
|
+
|
|
89
|
+
// cada cuadra delegada a módulo separado (implementado en mapType3Block.js)
|
|
90
|
+
for (let blockStartX = 0; blockStartX < width; blockStartX += patternSize) {
|
|
91
|
+
for (let blockStartZ = 0; blockStartZ < depth; blockStartZ += patternSize) {
|
|
92
|
+
processBlock(blockStartX, blockStartZ, width, depth, baseY, heightMap, maxHeightMap, surfaceTypeMap, structures, entities, zonas);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// *** regenerar ventanas ahora que todas las parcelas existen ***
|
|
97
|
+
// primero calcular tamaño de parcela constante usando las mismas constantes
|
|
98
|
+
// que el módulo de cuadras. esto coincide con los cálculos en
|
|
99
|
+
// mapType3Center.processInterior.
|
|
100
|
+
const interiorDim = blockZoneSize - 2 * veredaWidth;
|
|
101
|
+
const plotWidth = interiorDim / 4;
|
|
102
|
+
const plotDepth = interiorDim / 2;
|
|
103
|
+
|
|
104
|
+
// limpiamos cualquier rango anterior y volvemos a llamar a addWindows para
|
|
105
|
+
// cada parcela usando los límites codificados en el parcelId.
|
|
106
|
+
structures.forEach(s => {
|
|
107
|
+
delete s.windowNorthRange;
|
|
108
|
+
delete s.windowSouthRange;
|
|
109
|
+
delete s.windowWestRange;
|
|
110
|
+
delete s.windowEastRange;
|
|
111
|
+
});
|
|
112
|
+
// la clave agrupa por parcela *y* planta: las casas de dos pisos repiten la
|
|
113
|
+
// misma huella, así que si se mezclaran las dos plantas en una sola lista
|
|
114
|
+
// cada sala taparía la pared de su gemela y no saldría ninguna ventana.
|
|
115
|
+
const parcels = Object.create(null);
|
|
116
|
+
structures.forEach(s => {
|
|
117
|
+
if (s.parcelId != null) {
|
|
118
|
+
const key = `${s.parcelId}|${s.floor || 0}`;
|
|
119
|
+
const list = parcels[key] || (parcels[key] = []);
|
|
120
|
+
// bathrooms should never get windows, so don't include them in the
|
|
121
|
+
// list passed to addWindows later. hallways *are* eligible: once
|
|
122
|
+
// they were excluded here the recalculation step effectively
|
|
123
|
+
// wiped out any openings created during house generation. the
|
|
124
|
+
// user has requested that pasillos also receive windows, so we
|
|
125
|
+
// allow them now.
|
|
126
|
+
if (s.type !== 'spawn' && s.type !== 'banio')
|
|
127
|
+
list.push(s);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
Object.keys(parcels).forEach(key => {
|
|
131
|
+
const [px, pz] = key.split('|')[0].split('_').map(Number);
|
|
132
|
+
addWindows(parcels[key], structures, px, pz, plotWidth, plotDepth);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// antes de devolver los datos limpiamos cualquier marca de ventana que
|
|
136
|
+
// apunte a una estructura de otra parcela (se generaron inicialmente en
|
|
137
|
+
// `generadorCasa`). Esto permite que scripts que sólo llamen a
|
|
138
|
+
// `generateMapType3` no vean ventanas inválidas.
|
|
139
|
+
structures.forEach(s => {
|
|
140
|
+
['North','South','West','East'].forEach(dir => {
|
|
141
|
+
const rangeKey = 'window' + dir + 'Range';
|
|
142
|
+
if (!s[rangeKey]) return;
|
|
143
|
+
const hx = s.x, hz = s.z, hw = s.width, hd = s.depth;
|
|
144
|
+
const neighbor = structures.find(t => {
|
|
145
|
+
if (t === s) return false;
|
|
146
|
+
if (t.parcelId === s.parcelId) return false;
|
|
147
|
+
if (!sameLevel(s, t)) return false;
|
|
148
|
+
if (dir === 'North') return t.z + t.depth === hz && rangesOverlap(s.x, s.x + hw, t.x, t.x + t.width);
|
|
149
|
+
if (dir === 'South') return s.z + hd === t.z && rangesOverlap(s.x, s.x + hw, t.x, t.x + t.width);
|
|
150
|
+
if (dir === 'West') return t.x + t.width === hx && rangesOverlap(s.z, s.z + hd, t.z, t.z + t.depth);
|
|
151
|
+
if (dir === 'East') return s.x + hw === t.x && rangesOverlap(s.z, s.z + hd, t.z, t.z + t.depth);
|
|
152
|
+
});
|
|
153
|
+
if (neighbor) delete s[rangeKey];
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// calcular y obtener la posición de inicio; la sala ya no se genera
|
|
158
|
+
// ni se agrega a `structures`.
|
|
159
|
+
const { startPosition, room } = computeCenter(width, depth, baseY, roomWidth, roomHeight, roomDepth, structures);
|
|
160
|
+
|
|
161
|
+
// pasillos deshabilitados; no se agrega ninguno por defecto
|
|
162
|
+
// if (!structures.some(s => s.type === 'hallway')) {
|
|
163
|
+
// const cx = Math.max(0, Math.min(width - 4, Math.floor(width/2) - 2));
|
|
164
|
+
// // hallway floor should sit at the same level as terrain
|
|
165
|
+
// const hy = baseY;
|
|
166
|
+
// const fallback = {
|
|
167
|
+
// type: 'hallway', x: cx, y: hy, z: 0,
|
|
168
|
+
// width: 4, depth: depth,
|
|
169
|
+
// floorTexture: BLOCK_TYPES.WHITE,
|
|
170
|
+
// ceilingTexture: BLOCK_TYPES.WHITE,
|
|
171
|
+
// wallTexture: BLOCK_TYPES.BRICK,
|
|
172
|
+
// tintColor: 0xFFFFFF,
|
|
173
|
+
// tintOpacity: 0.5
|
|
174
|
+
// };
|
|
175
|
+
// structures.push(fallback);
|
|
176
|
+
// }
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
return { heightMap, maxHeightMap, structures, startPosition, room, surfaceTypeMap, entities, zonas };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Generar volume para tipo 3 respetando heightMap (cuadras vs calles)
|
|
183
|
+
function generateVolumeType3(width, depth, volumeHeight, heightMap, startPosition, room, surfaceTypeMap, structures=[], zonasEspeciales=null, refugios=[]) {
|
|
184
|
+
// filter structures to ensure they lie within terrain bounds
|
|
185
|
+
if (structures && structures.length) {
|
|
186
|
+
structures = filterStructuresInBounds(structures, width, depth);
|
|
187
|
+
}
|
|
188
|
+
// VolumeBuffer reserva, por columna (x,z), sólo la altura que esa columna
|
|
189
|
+
// necesita en la práctica (suelo + el edificio más alto que la cubra) en
|
|
190
|
+
// vez de `volumeHeight` fijo para las ~1.000.000 de columnas del mapa.
|
|
191
|
+
// BLOCK_TYPES.AIR = 0 coincide con el valor inicial del Uint8Array, por lo que
|
|
192
|
+
// no hace falta inicializar explícitamente las celdas de aire.
|
|
193
|
+
const colHeights = computeColumnHeights(width, depth, volumeHeight, heightMap, room, structures);
|
|
194
|
+
const volume = new VolumeBuffer(width, volumeHeight, depth, colHeights);
|
|
195
|
+
|
|
196
|
+
// Determinar la altura de calle (superficie más baja) para asignar textura negra/asfalto
|
|
197
|
+
let minSurfaceHeight = Infinity;
|
|
198
|
+
for (let ix = 0; ix < width; ix++) {
|
|
199
|
+
for (let iz = 0; iz < depth; iz++) {
|
|
200
|
+
if (heightMap[ix] && typeof heightMap[ix][iz] === 'number') {
|
|
201
|
+
minSurfaceHeight = Math.min(minSurfaceHeight, heightMap[ix][iz]);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Solo iterar celdas no-AIR (las celdas AIR ya están a 0 por defecto)
|
|
207
|
+
for (let x = 0; x < width; x++) {
|
|
208
|
+
for (let z = 0; z < depth; z++) {
|
|
209
|
+
const surface = heightMap[x][z]; // primera capa de aire => nivel de superficie
|
|
210
|
+
for (let y = 0; y < surface; y++) {
|
|
211
|
+
if (y === surface - 1) {
|
|
212
|
+
// Capa superficial
|
|
213
|
+
if (surfaceTypeMap && surfaceTypeMap[x] && typeof surfaceTypeMap[x][z] !== 'undefined') {
|
|
214
|
+
volume.set(x, y, z, surfaceTypeMap[x][z]);
|
|
215
|
+
} else {
|
|
216
|
+
volume.set(x, y, z, (surface === minSurfaceHeight) ? BLOCK_TYPES.ASPHALT : BLOCK_TYPES.GRAY);
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
volume.set(x, y, z, BLOCK_TYPES.BROWN); // subsuelo
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// realizar limpieza de ventanas en estructuras antes de devolver datos
|
|
226
|
+
cleanWindows(structures);
|
|
227
|
+
|
|
228
|
+
// Si no se devolvió ninguna sala (nueva lógica) omitir este paso.
|
|
229
|
+
if (room) {
|
|
230
|
+
// Aplicar sala inicial (sobrescribe el terreno)
|
|
231
|
+
const { x: roomX, y: roomY, z: roomZ, width: roomWidth, height: roomHeight, depth: roomDepth } = room;
|
|
232
|
+
|
|
233
|
+
for (let x = roomX; x < roomX + roomWidth; x++) {
|
|
234
|
+
for (let z = roomZ; z < roomZ + roomDepth; z++) {
|
|
235
|
+
for (let y = roomY; y < roomY + roomHeight; y++) {
|
|
236
|
+
// bounds guard
|
|
237
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) continue;
|
|
238
|
+
if (x === roomX || x === roomX + roomWidth - 1 || z === roomZ || z === roomZ + roomDepth - 1) {
|
|
239
|
+
// Paredes
|
|
240
|
+
volume.set(x, y, z, BLOCK_TYPES.BRICK);
|
|
241
|
+
} else if (y === roomY + roomHeight - 1) {
|
|
242
|
+
// Techo
|
|
243
|
+
volume.set(x, y, z, BLOCK_TYPES.WHITE);
|
|
244
|
+
} else if (y === roomY) {
|
|
245
|
+
// Piso de la sala
|
|
246
|
+
volume.set(x, y, z, BLOCK_TYPES.GRAY);
|
|
247
|
+
} else {
|
|
248
|
+
// Interior aire
|
|
249
|
+
volume.set(x, y, z, BLOCK_TYPES.AIR);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Crear abertura en la pared este de la sala (igual comportamiento que antes)
|
|
256
|
+
const openingYStart = roomY + 1;
|
|
257
|
+
const openingYEnd = roomY + 6; // 6 bloques de alto
|
|
258
|
+
const openingZCenter = Math.floor((roomZ + roomZ + roomDepth) / 2); // Centro en Z
|
|
259
|
+
const openingZStart = openingZCenter - 1; // 4 bloques de ancho: -1, 0, 1, 2
|
|
260
|
+
const openingZEnd = openingZCenter + 2;
|
|
261
|
+
for (let y = openingYStart; y <= openingYEnd; y++) {
|
|
262
|
+
for (let z = openingZStart; z <= openingZEnd; z++) {
|
|
263
|
+
volume.set(roomX + roomWidth - 1, y, z, BLOCK_TYPES.AIR);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
// Dibujar las estructuras de tipo casa, pasillo, sala simple o cualquiera
|
|
270
|
+
// de los nuevos tipos (banio, cocina, etc.). Los `spawn` se ignoran.
|
|
271
|
+
for (const s of structures) {
|
|
272
|
+
if (s.type === 'spawn') continue;
|
|
273
|
+
// sólo dibujamos si la estructura tiene dimensiones válidas
|
|
274
|
+
const { x: hx, y: hy, z: hz, width: hw, height: hh, depth: hd } = s;
|
|
275
|
+
if (hw == null || hh == null || hd == null) continue;
|
|
276
|
+
// obtener texturas específicas si las tiene la estructura (salas diversas)
|
|
277
|
+
const wallTex = (s.wallTexture !== undefined) ? s.wallTexture : BLOCK_TYPES.BRICK;
|
|
278
|
+
const floorTex = (s.floorTexture !== undefined) ? s.floorTexture : BLOCK_TYPES.GRAY;
|
|
279
|
+
const ceilingTex = (s.ceilingTexture !== undefined) ? s.ceilingTexture : BLOCK_TYPES.WHITE;
|
|
280
|
+
// helper para asignar valor con posible tintado. el parámetro
|
|
281
|
+
// `isWall` indica que el bloque corresponde a una pared exterior; sólo
|
|
282
|
+
// entonces se deberán aplicar cualquiera de los tintados que tenga la
|
|
283
|
+
// estructura. los pisos y techos permanecen sin colorear.
|
|
284
|
+
const assign = (x, y, z, type, isWall = false) => {
|
|
285
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) return;
|
|
286
|
+
// sólo aplicamos tinte si el bloque es pared y la estructura define
|
|
287
|
+
// algún tinte (render o minimapa). legacy tintColor se considera
|
|
288
|
+
// también minimap, pero siempre ligado a paredes.
|
|
289
|
+
if (isWall && (s.tintRender != null || s.tintMinimap != null || s.tintColor != null)) {
|
|
290
|
+
const cell = { type };
|
|
291
|
+
if (s.tintRender != null) {
|
|
292
|
+
cell.tintRender = { color: s.tintRender, opacity: (s.tintOpacity != null ? s.tintOpacity : 0.5) };
|
|
293
|
+
}
|
|
294
|
+
if (s.tintMinimap != null) {
|
|
295
|
+
cell.tintMinimap = { color: s.tintMinimap, opacity: (s.tintMinimapOpacity != null ? s.tintMinimapOpacity : (s.tintOpacity != null ? s.tintOpacity : 0.5)) };
|
|
296
|
+
} else if (s.tintColor != null) {
|
|
297
|
+
cell.tintMinimap = { color: s.tintColor, opacity: (s.tintOpacity != null ? s.tintOpacity : 0.5) };
|
|
298
|
+
}
|
|
299
|
+
volume.set(x, y, z, cell);
|
|
300
|
+
} else {
|
|
301
|
+
volume.set(x, y, z, type);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
// paredes, techo y piso básicos
|
|
305
|
+
for (let x = hx; x < hx + hw; x++) {
|
|
306
|
+
for (let z = hz; z < hz + hd; z++) {
|
|
307
|
+
for (let y = hy; y < hy + hh; y++) {
|
|
308
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) continue;
|
|
309
|
+
if (x === hx || x === hx + hw - 1 || z === hz || z === hz + hd - 1) {
|
|
310
|
+
assign(x,y,z,wallTex, true);
|
|
311
|
+
} else if (y === hy + hh - 1) {
|
|
312
|
+
assign(x,y,z,ceilingTex, false);
|
|
313
|
+
} else if (y === hy) {
|
|
314
|
+
assign(x,y,z,floorTex, false);
|
|
315
|
+
} else {
|
|
316
|
+
volume.set(x, y, z, BLOCK_TYPES.AIR);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// si es una sala simple no dibujamos puertas o ventanas (pero sí los
|
|
323
|
+
// pasillos; las aberturas hacia los pasillos se manejarán más abajo).
|
|
324
|
+
if (s.type === 'room') continue;
|
|
325
|
+
|
|
326
|
+
// dimensiones para puertas y ventanas.
|
|
327
|
+
const doorHeightStart = hy + 1;
|
|
328
|
+
const doorHeightEnd = hy + 6; // 6 bloques de alto igual que sala inicial
|
|
329
|
+
const doorWidth = Math.min(4, hw - 2);
|
|
330
|
+
const doorXStart = hx + Math.floor((hw - doorWidth) / 2);
|
|
331
|
+
const doorZStart = hz + Math.floor((hd - doorWidth) / 2);
|
|
332
|
+
|
|
333
|
+
// ventanas definidas por parámetros reutilizables. la elevación y la
|
|
334
|
+
// altura ya vienen controladas por DEFAULT_WINDOW_ELEVATION/HEIGHT, que
|
|
335
|
+
// permiten mantener la compensación pedida por el usuario (inicio a dos
|
|
336
|
+
// bloques del suelo y altura reducida en uno).
|
|
337
|
+
const windowHeight = DEFAULT_WINDOW_HEIGHT;
|
|
338
|
+
const windowYStart = hy + DEFAULT_WINDOW_ELEVATION;
|
|
339
|
+
const windowYEnd = windowYStart + windowHeight - 1; // se mantiene la misma lógica de rango
|
|
340
|
+
|
|
341
|
+
const defaultWindowWidthX = Math.min(5, hw - 2);
|
|
342
|
+
const defaultWindowWidthZ = Math.min(5, hd - 2);
|
|
343
|
+
const windowXStart = hx + Math.floor((hw - defaultWindowWidthX) / 2);
|
|
344
|
+
const windowZStart = hz + Math.floor((hd - defaultWindowWidthZ) / 2);
|
|
345
|
+
|
|
346
|
+
// helper para vaciar un rectángulo en un lado fijo (X varía)
|
|
347
|
+
const carveWallZ = (sideZ, startY, endY) => {
|
|
348
|
+
for (let y = startY; y <= endY && y < hy + hh; y++) {
|
|
349
|
+
for (let x = windowXStart; x < windowXStart + windowWidth; x++) {
|
|
350
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || sideZ < 0 || sideZ >= depth) continue;
|
|
351
|
+
volume.set(x, y, sideZ, BLOCK_TYPES.AIR);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const carveWallX = (sideX, startY, endY) => {
|
|
356
|
+
for (let y = startY; y <= endY && y < hy + hh; y++) {
|
|
357
|
+
for (let z = windowZStart; z < windowZStart + windowWidth; z++) {
|
|
358
|
+
if (sideX < 0 || sideX >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) continue;
|
|
359
|
+
volume.set(sideX, y, z, BLOCK_TYPES.AIR);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// puerta de entrada sólo si corresponde
|
|
365
|
+
if (s.hasFrontDoor) {
|
|
366
|
+
if (s.frontNorth) {
|
|
367
|
+
const zFront = hz;
|
|
368
|
+
for (let y = doorHeightStart; y < doorHeightEnd && y < hy + hh; y++) {
|
|
369
|
+
for (let x = doorXStart; x < doorXStart + doorWidth; x++) {
|
|
370
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || zFront < 0 || zFront >= depth) continue;
|
|
371
|
+
volume.set(x, y, zFront, BLOCK_TYPES.AIR);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
for (let x = doorXStart; x < doorXStart + doorWidth; x++) {
|
|
375
|
+
if (x >= 0 && x < width && zFront >= 0 && zFront < depth) {
|
|
376
|
+
volume.set(x, hy, zFront, floorTex);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
} else if (s.frontSouth) {
|
|
380
|
+
const zFront = hz + hd - 1;
|
|
381
|
+
for (let y = doorHeightStart; y < doorHeightEnd && y < hy + hh; y++) {
|
|
382
|
+
for (let x = doorXStart; x < doorXStart + doorWidth; x++) {
|
|
383
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || zFront < 0 || zFront >= depth) continue;
|
|
384
|
+
volume.set(x, y, zFront, BLOCK_TYPES.AIR);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
for (let x = doorXStart; x < doorXStart + doorWidth; x++) {
|
|
388
|
+
if (x >= 0 && x < width && zFront >= 0 && zFront < depth) {
|
|
389
|
+
volume.set(x, hy, zFront, floorTex);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
} else if (s.frontWest) {
|
|
393
|
+
const xFront = hx;
|
|
394
|
+
for (let y = doorHeightStart; y < doorHeightEnd && y < hy + hh; y++) {
|
|
395
|
+
for (let z = doorZStart; z < doorZStart + doorWidth; z++) {
|
|
396
|
+
if (xFront < 0 || xFront >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) continue;
|
|
397
|
+
volume.set(xFront, y, z, BLOCK_TYPES.AIR);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
for (let z = doorZStart; z < doorZStart + doorWidth; z++) {
|
|
401
|
+
if (xFront >= 0 && xFront < width && z >= 0 && z < depth) {
|
|
402
|
+
volume.set(xFront, hy, z, floorTex);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
} else if (s.frontEast) {
|
|
406
|
+
const xFront = hx + hw - 1;
|
|
407
|
+
for (let y = doorHeightStart; y < doorHeightEnd && y < hy + hh; y++) {
|
|
408
|
+
for (let z = doorZStart; z < doorZStart + doorWidth; z++) {
|
|
409
|
+
if (xFront < 0 || xFront >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) continue;
|
|
410
|
+
volume.set(xFront, y, z, BLOCK_TYPES.AIR);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
for (let z = doorZStart; z < doorZStart + doorWidth; z++) {
|
|
414
|
+
if (xFront >= 0 && xFront < width && z >= 0 && z < depth) {
|
|
415
|
+
volume.set(xFront, hy, z, floorTex);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
// abrir muro interior si se ha generado una conexión de baño
|
|
421
|
+
// helper para calcular inicio y anchura en base al overlapRange si existe
|
|
422
|
+
const computeDoor = (range, defaultStart, defaultWidth) => {
|
|
423
|
+
if (range && range.end > range.start + 2) {
|
|
424
|
+
const overlapLen = range.end - range.start;
|
|
425
|
+
const dw = Math.min(defaultWidth, overlapLen - 2);
|
|
426
|
+
const start = range.start + Math.floor((overlapLen - dw) / 2);
|
|
427
|
+
return { start, width: dw };
|
|
428
|
+
}
|
|
429
|
+
return { start: defaultStart, width: defaultWidth };
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
if (s.openNorth) {
|
|
433
|
+
const zWall = hz;
|
|
434
|
+
const { start: xStart, width: wlen } = computeDoor(s.openNorthRange, doorXStart, doorWidth);
|
|
435
|
+
for (let y = doorHeightStart; y < doorHeightEnd && y < hy + hh; y++) {
|
|
436
|
+
for (let x = xStart; x < xStart + wlen; x++) {
|
|
437
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || zWall < 0 || zWall >= depth) continue;
|
|
438
|
+
volume.set(x, y, zWall, BLOCK_TYPES.AIR);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
for (let x = xStart; x < xStart + wlen; x++) {
|
|
442
|
+
if (x >= 0 && x < width && zWall >= 0 && zWall < depth) {
|
|
443
|
+
volume.set(x, hy, zWall, floorTex);
|
|
444
|
+
}
|
|
445
|
+
const otherZ = zWall - 1;
|
|
446
|
+
if (x >= 0 && x < width && otherZ >= 0 && otherZ < depth) {
|
|
447
|
+
volume.set(x, hy, otherZ, floorTex);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (s.openSouth) {
|
|
452
|
+
const zWall = hz + hd - 1;
|
|
453
|
+
const { start: xStart, width: wlen } = computeDoor(s.openSouthRange, doorXStart, doorWidth);
|
|
454
|
+
for (let y = doorHeightStart; y < doorHeightEnd && y < hy + hh; y++) {
|
|
455
|
+
for (let x = xStart; x < xStart + wlen; x++) {
|
|
456
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || zWall < 0 || zWall >= depth) continue;
|
|
457
|
+
volume.set(x, y, zWall, BLOCK_TYPES.AIR);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
for (let x = xStart; x < xStart + wlen; x++) {
|
|
461
|
+
if (x >= 0 && x < width && zWall >= 0 && zWall < depth) {
|
|
462
|
+
volume.set(x, hy, zWall, floorTex);
|
|
463
|
+
}
|
|
464
|
+
const otherZ = zWall + 1;
|
|
465
|
+
if (x >= 0 && x < width && otherZ >= 0 && otherZ < depth) {
|
|
466
|
+
volume.set(x, hy, otherZ, floorTex);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
if (s.openWest) {
|
|
471
|
+
const xWall = hx;
|
|
472
|
+
const { start: zStart, width: wlen } = computeDoor(s.openWestRange, doorZStart, doorWidth);
|
|
473
|
+
for (let y = doorHeightStart; y < doorHeightEnd && y < hy + hh; y++) {
|
|
474
|
+
for (let z = zStart; z < zStart + wlen; z++) {
|
|
475
|
+
if (xWall < 0 || xWall >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) continue;
|
|
476
|
+
volume.set(xWall, y, z, BLOCK_TYPES.AIR);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
for (let z = zStart; z < zStart + wlen; z++) {
|
|
480
|
+
if (xWall >= 0 && xWall < width && z >= 0 && z < depth) {
|
|
481
|
+
volume.set(xWall, hy, z, floorTex);
|
|
482
|
+
}
|
|
483
|
+
const otherX = xWall - 1;
|
|
484
|
+
if (otherX >= 0 && otherX < width && z >= 0 && z < depth) {
|
|
485
|
+
volume.set(otherX, hy, z, floorTex);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (s.openEast) {
|
|
490
|
+
const xWall = hx + hw - 1;
|
|
491
|
+
const { start: zStart, width: wlen } = computeDoor(s.openEastRange, doorZStart, doorWidth);
|
|
492
|
+
for (let y = doorHeightStart; y < doorHeightEnd && y < hy + hh; y++) {
|
|
493
|
+
for (let z = zStart; z < zStart + wlen; z++) {
|
|
494
|
+
if (xWall < 0 || xWall >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) continue;
|
|
495
|
+
volume.set(xWall, y, z, BLOCK_TYPES.AIR);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
for (let z = zStart; z < zStart + wlen; z++) {
|
|
499
|
+
if (xWall >= 0 && xWall < width && z >= 0 && z < depth) {
|
|
500
|
+
volume.set(xWall, hy, z, floorTex);
|
|
501
|
+
}
|
|
502
|
+
const otherX = xWall + 1;
|
|
503
|
+
if (otherX >= 0 && otherX < width && z >= 0 && z < depth) {
|
|
504
|
+
volume.set(otherX, hy, z, floorTex);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// helper para comprobar si, para una estructura `s`, una cara dada
|
|
510
|
+
// tiene adyacencia a una sala de otra parcela (bloqueante).
|
|
511
|
+
const sideHasOtherParcel = (side) => {
|
|
512
|
+
return structures.some(t => {
|
|
513
|
+
if (t === s) return false;
|
|
514
|
+
if (t.parcelId === s.parcelId) return false;
|
|
515
|
+
if (!sameLevel(s, t)) return false;
|
|
516
|
+
if (side === 'north') {
|
|
517
|
+
return t.z + t.depth === hz && rangesOverlap(s.x, s.x + hw, t.x, t.x + t.width);
|
|
518
|
+
}
|
|
519
|
+
if (side === 'south') {
|
|
520
|
+
return s.z + hd === t.z && rangesOverlap(s.x, s.x + hw, t.x, t.x + t.width);
|
|
521
|
+
}
|
|
522
|
+
if (side === 'west') {
|
|
523
|
+
return t.x + t.width === hx && rangesOverlap(s.z, s.z + hd, t.z, t.z + t.depth);
|
|
524
|
+
}
|
|
525
|
+
if (side === 'east') {
|
|
526
|
+
return s.x + hw === t.x && rangesOverlap(s.z, s.z + hd, t.z, t.z + t.depth);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
const carveWindowZ = (sideZ, startX, wlen) => {
|
|
532
|
+
for (let y = windowYStart; y <= windowYEnd && y < hy + hh; y++) {
|
|
533
|
+
for (let x = startX; x < startX + wlen; x++) {
|
|
534
|
+
if (x < 0 || x >= width || y < 0 || y >= volumeHeight || sideZ < 0 || sideZ >= depth) continue;
|
|
535
|
+
if (volume.getType(x, y, sideZ) === BLOCK_TYPES.AIR) continue;
|
|
536
|
+
volume.set(x, y, sideZ, BLOCK_TYPES.WINDOW);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
const carveWindowX = (sideX, startZ, wlen) => {
|
|
541
|
+
for (let y = windowYStart; y <= windowYEnd && y < hy + hh; y++) {
|
|
542
|
+
for (let z = startZ; z < startZ + wlen; z++) {
|
|
543
|
+
if (sideX < 0 || sideX >= width || y < 0 || y >= volumeHeight || z < 0 || z >= depth) continue;
|
|
544
|
+
if (volume.getType(sideX, y, z) === BLOCK_TYPES.AIR) continue;
|
|
545
|
+
volume.set(sideX, y, z, BLOCK_TYPES.WINDOW);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
// Helper para procesar uno o varios rangos de ventana en una cara.
|
|
551
|
+
// Los rangos ya contienen la posición y anchura exactas calculadas por
|
|
552
|
+
// assignWindows, así que los usamos directamente en lugar de pasar por
|
|
553
|
+
// computeDoor (que está pensado para puertas interiores y recorta el
|
|
554
|
+
// rango dos bloques, lo que provocaba que ventanas de ancho exactamente
|
|
555
|
+
// igual a DEFAULT_WINDOW_LENGTH fueran ignoradas).
|
|
556
|
+
const carveSide = (sideName, ranges, coord, carveFn) => {
|
|
557
|
+
if (!ranges) return;
|
|
558
|
+
if (!Array.isArray(ranges)) ranges = [ranges];
|
|
559
|
+
ranges.forEach(range => {
|
|
560
|
+
const start = range.start;
|
|
561
|
+
const wlen = range.end - range.start;
|
|
562
|
+
if (!(sideHasOtherParcel(sideName) && !s['front' + sideName[0].toUpperCase() + sideName.slice(1)])) {
|
|
563
|
+
carveFn(coord, start, wlen);
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
// norte (skip bathrooms entirely)
|
|
569
|
+
if (s.type !== 'banio' && (s.hasFrontWindow || s.windowNorthRange)) {
|
|
570
|
+
carveSide('north', s.windowNorthRange, hz, (c, st, wl) => carveWindowZ(c, st, wl));
|
|
571
|
+
}
|
|
572
|
+
// sur
|
|
573
|
+
if (s.type !== 'banio' && (s.hasBackWindow || s.windowSouthRange)) {
|
|
574
|
+
carveSide('south', s.windowSouthRange, hz + hd - 1, (c, st, wl) => carveWindowZ(c, st, wl));
|
|
575
|
+
}
|
|
576
|
+
// oeste
|
|
577
|
+
if (s.type !== 'banio' && s.windowWestRange) {
|
|
578
|
+
carveSide('west', s.windowWestRange, hx, (c, st, wl) => carveWindowX(c, st, wl));
|
|
579
|
+
}
|
|
580
|
+
// este
|
|
581
|
+
if (s.type !== 'banio' && s.windowEastRange) {
|
|
582
|
+
carveSide('east', s.windowEastRange, hx + hw - 1, (c, st, wl) => carveWindowX(c, st, wl));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// interconexiones obligatorias (puertas) entre ciertas salas.
|
|
587
|
+
// La lógica se ha factorizado en carveInteriorConnections para mantener
|
|
588
|
+
// generateVolumeType3 más legible.
|
|
589
|
+
carveInteriorConnections(volume, structures, width, depth, volumeHeight, ENABLE_INTERIOR_CONNECTIONS);
|
|
590
|
+
// las escaleras van al final: sus escalones y la caja de escalera manda
|
|
591
|
+
// sobre cualquier piso, techo o puerta que se haya dibujado antes.
|
|
592
|
+
carveStairs(volume, structures, width, depth, volumeHeight);
|
|
593
|
+
// el antepecho va después de las escaleras: es un anillo sobre la cubierta
|
|
594
|
+
// y no toca el hueco por donde la escalera sale al techo.
|
|
595
|
+
buildRoofParapets(volume, structures, width, depth, volumeHeight);
|
|
596
|
+
// casillas de escalera y tanques de agua, sobre la cubierta ya terminada
|
|
597
|
+
buildRoofExtras(volume, structures, width, depth, volumeHeight);
|
|
598
|
+
finalizeVolume(volume, surfaceTypeMap, structures, width, depth, volumeHeight);
|
|
599
|
+
// cartel de cada tienda sobre la puerta, en el plano de la calle (ver cartel_tienda.js)
|
|
600
|
+
pintarCarteles(volume, structures, width, depth, volumeHeight);
|
|
601
|
+
|
|
602
|
+
// Generar PNGs para este tipo de mapa (incluimos estructuras para pintar frentes)
|
|
603
|
+
// El nombre viaja colgado de `volume` (en vez de cambiar la firma de esta
|
|
604
|
+
// función) para que construirMapa() pueda reenviarlo al hilo principal
|
|
605
|
+
// cuando la generación corrió en el worker_thread de la ronda siguiente.
|
|
606
|
+
// Lámpara física empotrada en el techo de cada habitación con luz (ver
|
|
607
|
+
// agregarLucesInteriores en mapType3Block.js): la celda de techo del
|
|
608
|
+
// centro de la sala pasa a ser un bloque LAMPARA (emisivo y destructible),
|
|
609
|
+
// donde está la PointLight lógica. Se pone después de tallar todo
|
|
610
|
+
// (ventanas, pasillos, escaleras) y sólo si ahí hay techo sólido: si la
|
|
611
|
+
// celda es aire (abertura, hueco de escalera) no se coloca nada.
|
|
612
|
+
for (const s of structures) {
|
|
613
|
+
if (s.type === 'spawn' || TIPOS_SIN_LUZ_INTERIOR.has(s.type)) continue;
|
|
614
|
+
if (s.width == null || s.height == null || s.depth == null) continue;
|
|
615
|
+
const lx = Math.floor(s.x + s.width / 2);
|
|
616
|
+
const ly = Math.floor(s.y + s.height - 1);
|
|
617
|
+
const lz = Math.floor(s.z + s.depth / 2);
|
|
618
|
+
if (lx < 0 || lx >= width || ly < 0 || ly >= volumeHeight || lz < 0 || lz >= depth) continue;
|
|
619
|
+
const actual = volume.getType(lx, ly, lz);
|
|
620
|
+
if (actual !== BLOCK_TYPES.AIR && actual !== BLOCK_TYPES.WINDOW) volume.set(lx, ly, lz, BLOCK_TYPES.LAMPARA);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
volume.minimapFile = generateMapPNGs(volume, width, volumeHeight, depth, 'type3', structures, zonasEspeciales);
|
|
624
|
+
|
|
625
|
+
// refugios subterráneos (plan_supervivencia.md §13): se excavan DESPUÉS del
|
|
626
|
+
// minimapa para que el hueco de la trampilla no quede marcado en él.
|
|
627
|
+
if (refugios && refugios.length) excavarRefugios(volume, refugios, width, depth, volumeHeight);
|
|
628
|
+
|
|
629
|
+
return volume;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export {
|
|
633
|
+
generateMapType3,
|
|
634
|
+
generateVolumeType3
|
|
635
|
+
};
|