@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,486 @@
|
|
|
1
|
+
// Encapsula la creación física de habitaciones dentro de una parcela.
|
|
2
|
+
// El arreglo `types` contiene los nombres de salas en el orden que deben
|
|
3
|
+
// disponerse; el índice cero es la sala principal.
|
|
4
|
+
export function placeRooms(types, plotX0, plotZ0, plotWidth, plotDepth,
|
|
5
|
+
baseY, structures, orientation, parcelId,
|
|
6
|
+
ROOM_CONFIGS, createRoom) {
|
|
7
|
+
// the y-coordinate of a room is now exactly the terrain level (baseY)
|
|
8
|
+
// instead of one block above. previously we added +1 which caused all
|
|
9
|
+
// floors to "float" over the ground because heightMap stores the first
|
|
10
|
+
// air layer, not the top solid block. the surrounding surface stays at
|
|
11
|
+
// baseY, so using baseY here makes the floor flush with the terrain.
|
|
12
|
+
const y0 = baseY;
|
|
13
|
+
let offset = 0; // desplaza a lo largo del frente o del costado
|
|
14
|
+
let backOffset = 0; // desplazamiento hacia "detrás" (filas sucesivas)
|
|
15
|
+
let rowMaxCross = 0; // máxima profundidad/anchura de la fila actual
|
|
16
|
+
let rowStartOffset = Infinity; // inicio de la fila en el eje de offset
|
|
17
|
+
let rowEndOffset = 0; // fin de la fila en el eje de offset
|
|
18
|
+
const gap = 6; // separación entre filas (pasillo)
|
|
19
|
+
let assignedEntrance = false;
|
|
20
|
+
|
|
21
|
+
// cola de tipos; la vamos a modificar (reinsertar salas desplazadas, ROW_BREAK, etc.)
|
|
22
|
+
const queue = types.slice();
|
|
23
|
+
|
|
24
|
+
// filas actualmente pobladas (para cálculo de huecos y relocalización)
|
|
25
|
+
let rowRooms = [];
|
|
26
|
+
|
|
27
|
+
// filas ya completadas (para intentar reubicar salas solapadas ahí)
|
|
28
|
+
const completedRows = [];
|
|
29
|
+
|
|
30
|
+
// último pasillo horizontal insertado (para conectar con el siguiente)
|
|
31
|
+
let lastHall = null;
|
|
32
|
+
|
|
33
|
+
const ROW_BREAK = '__ROW_BREAK__';
|
|
34
|
+
|
|
35
|
+
// división previa en dos líneas si cabe todo en una sola fila
|
|
36
|
+
// y todas las salas quedarían en la misma línea. En ese caso
|
|
37
|
+
// repartimos por conteo: la mitad en la fila 0 y la otra mitad en la fila 1.
|
|
38
|
+
if (queue.length > 1) {
|
|
39
|
+
const dims = queue.map(t => {
|
|
40
|
+
const cfg = ROOM_CONFIGS[t];
|
|
41
|
+
if (!cfg) return 0;
|
|
42
|
+
let w = cfg.width;
|
|
43
|
+
let d = cfg.depth;
|
|
44
|
+
if (orientation === 'E' || orientation === 'O') [w, d] = [d, w];
|
|
45
|
+
return (orientation === 'N' || orientation === 'S') ? w : d;
|
|
46
|
+
});
|
|
47
|
+
const totalLength = dims.reduce((a, b) => a + b, 0);
|
|
48
|
+
const maxLine = (orientation === 'N' || orientation === 'S') ? plotWidth : plotDepth;
|
|
49
|
+
if (totalLength <= maxLine) {
|
|
50
|
+
// cabe todo en una línea; dividir estrictamente por el número de
|
|
51
|
+
// salas en dos mitades iguales (la segunda puede tener uno más si
|
|
52
|
+
// hay impar).
|
|
53
|
+
if (queue.length > 2) {
|
|
54
|
+
const mid = Math.floor(queue.length / 2);
|
|
55
|
+
const first = queue.slice(0, mid);
|
|
56
|
+
const second = queue.slice(mid);
|
|
57
|
+
queue.length = 0;
|
|
58
|
+
queue.push(...first, ROW_BREAK, ...second);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// búsqueda de un hueco de al menos `minWidth` bloques en una lista de salas
|
|
64
|
+
// `rooms` debe contener objetos {start, width} similares a `rowRooms`.
|
|
65
|
+
// Busca un hueco en la lista de `rooms` entre rangeStart y rangeEnd.
|
|
66
|
+
// Devuelve un objeto {pos,width} indicando la posición inicial y la anchura
|
|
67
|
+
// del hueco encontrado (>=minWidth), o null si no hay ninguno.
|
|
68
|
+
function findGapInList(rooms, rangeStart, rangeEnd, minWidth) {
|
|
69
|
+
const sorted = rooms.slice().sort((a, b) => a.start - b.start);
|
|
70
|
+
let prevEnd = rangeStart;
|
|
71
|
+
for (const r of sorted) {
|
|
72
|
+
const gap = r.start - prevEnd;
|
|
73
|
+
if (gap >= minWidth && prevEnd + minWidth <= rangeEnd) {
|
|
74
|
+
return { pos: prevEnd, width: gap };
|
|
75
|
+
}
|
|
76
|
+
prevEnd = Math.max(prevEnd, r.start + r.width);
|
|
77
|
+
}
|
|
78
|
+
const gap = rangeEnd - prevEnd;
|
|
79
|
+
if (gap >= minWidth) return { pos: prevEnd, width: gap };
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// convierte un offset primario y backOffset de fila a coordenadas (x0,z0)
|
|
84
|
+
// usando la orientación actual y las dimensiones w,d de la sala a ubicar.
|
|
85
|
+
function coordsFor(offsetPrim, w, d, rowBack) {
|
|
86
|
+
let xx, zz;
|
|
87
|
+
switch (orientation) {
|
|
88
|
+
case 'N':
|
|
89
|
+
xx = plotX0 + offsetPrim;
|
|
90
|
+
zz = plotZ0 + rowBack;
|
|
91
|
+
break;
|
|
92
|
+
case 'S':
|
|
93
|
+
xx = plotX0 + offsetPrim;
|
|
94
|
+
zz = plotZ0 + plotDepth - d - rowBack;
|
|
95
|
+
break;
|
|
96
|
+
case 'O':
|
|
97
|
+
xx = plotX0 + rowBack;
|
|
98
|
+
zz = plotZ0 + offsetPrim;
|
|
99
|
+
break;
|
|
100
|
+
case 'E':
|
|
101
|
+
xx = plotX0 + plotWidth - w - rowBack;
|
|
102
|
+
zz = plotZ0 + offsetPrim;
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
xx = zz = NaN;
|
|
106
|
+
}
|
|
107
|
+
return { x0: xx, z0: zz };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// función auxiliar para crear un pasillo horizontal y, si existe uno previo,
|
|
111
|
+
// insertar además el pasillo vertical conectante y relocalizar salas según sea
|
|
112
|
+
// necesario.
|
|
113
|
+
function addHorizontalHall(cx, cz, cw, cd) {
|
|
114
|
+
// before placing the hall, ensure it spans the union of the current
|
|
115
|
+
// row offsets (rowStartOffset/rowEndOffset) and the previous row
|
|
116
|
+
// represented by lastHall. this guarantees every room on both sides
|
|
117
|
+
// will be adjacent to the corridor.
|
|
118
|
+
let finalCx = cx, finalCz = cz, finalCw = cw, finalCd = cd;
|
|
119
|
+
if (lastHall) {
|
|
120
|
+
if (orientation === 'N' || orientation === 'S') {
|
|
121
|
+
const prevStart = lastHall.x;
|
|
122
|
+
const prevEnd = lastHall.x + lastHall.width;
|
|
123
|
+
const currStart = plotX0 + rowStartOffset;
|
|
124
|
+
const currEnd = plotX0 + rowEndOffset;
|
|
125
|
+
const unionStart = Math.min(prevStart, currStart);
|
|
126
|
+
const unionEnd = Math.max(prevEnd, currEnd);
|
|
127
|
+
finalCx = unionStart;
|
|
128
|
+
finalCw = unionEnd - unionStart;
|
|
129
|
+
// enlarge previous hall as well to match the union
|
|
130
|
+
lastHall.x = unionStart;
|
|
131
|
+
lastHall.width = unionEnd - unionStart;
|
|
132
|
+
} else {
|
|
133
|
+
const prevStart = lastHall.z;
|
|
134
|
+
const prevEnd = lastHall.z + lastHall.depth;
|
|
135
|
+
const currStart = plotZ0 + rowStartOffset;
|
|
136
|
+
const currEnd = plotZ0 + rowEndOffset;
|
|
137
|
+
const unionStart = Math.min(prevStart, currStart);
|
|
138
|
+
const unionEnd = Math.max(prevEnd, currEnd);
|
|
139
|
+
finalCz = unionStart;
|
|
140
|
+
finalCd = unionEnd - unionStart;
|
|
141
|
+
lastHall.z = unionStart;
|
|
142
|
+
lastHall.depth = unionEnd - unionStart;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const hallCfg = ROOM_CONFIGS.hallway || {};
|
|
146
|
+
const hinst = Object.assign({}, hallCfg, { width: finalCw, depth: finalCd });
|
|
147
|
+
if (parcelId) hinst.parcelId = parcelId;
|
|
148
|
+
createRoom(finalCx, y0, finalCz, hinst, structures);
|
|
149
|
+
// grab the structure object that was just pushed so callers can adjust it
|
|
150
|
+
const hallStruct = structures[structures.length - 1];
|
|
151
|
+
const newHall = { x: finalCx, y: y0, z: finalCz, width: finalCw, depth: finalCd };
|
|
152
|
+
|
|
153
|
+
if (lastHall) {
|
|
154
|
+
// calcular rango permitido en el eje "primario" (offset) intersectando
|
|
155
|
+
// los anchos de ambos pasillos horizontales y además limitándolo al
|
|
156
|
+
// segmento real ocupado por los pasillos. esto garantiza que el
|
|
157
|
+
// pasillo perpendicular siempre quede dentro de los dos horizontales
|
|
158
|
+
// y por ende puedan conectarse.
|
|
159
|
+
let rangeStart = rowStartOffset;
|
|
160
|
+
let rangeEnd = rowEndOffset;
|
|
161
|
+
let lastStart, lastEnd;
|
|
162
|
+
// límites del pasillo que acabamos de generar (newHall) también
|
|
163
|
+
// deben contribuir a la intersección.
|
|
164
|
+
let currentStart, currentEnd;
|
|
165
|
+
if (orientation === 'N' || orientation === 'S') {
|
|
166
|
+
lastStart = lastHall.x;
|
|
167
|
+
lastEnd = lastHall.x + lastHall.width;
|
|
168
|
+
currentStart = cx;
|
|
169
|
+
currentEnd = cx + cw;
|
|
170
|
+
} else {
|
|
171
|
+
lastStart = lastHall.z;
|
|
172
|
+
lastEnd = lastHall.z + lastHall.depth;
|
|
173
|
+
currentStart = cz;
|
|
174
|
+
currentEnd = cz + cd;
|
|
175
|
+
}
|
|
176
|
+
rangeStart = Math.max(rangeStart, lastStart, currentStart);
|
|
177
|
+
rangeEnd = Math.min(rangeEnd, lastEnd, currentEnd) - 6;
|
|
178
|
+
if (rangeEnd < rangeStart) {
|
|
179
|
+
// si no hay intersección con los tres, al menos garantizamos el
|
|
180
|
+
// área común entre los dos pasillos horizontales
|
|
181
|
+
rangeStart = Math.max(lastStart, currentStart);
|
|
182
|
+
rangeEnd = Math.min(lastEnd, currentEnd) - 6;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const gapInfo = findGapInList(rowRooms, rangeStart, rangeEnd, 6);
|
|
186
|
+
let verticalPos;
|
|
187
|
+
if (gapInfo === null) {
|
|
188
|
+
// ningún hueco libre: posicionamos al azar dentro del rango completo
|
|
189
|
+
verticalPos = rangeStart + Math.floor(Math.random() * (rangeEnd - rangeStart + 1));
|
|
190
|
+
} else {
|
|
191
|
+
// también varía dentro del hueco encontrado para más diversidad
|
|
192
|
+
const maxOffset = gapInfo.width - 6;
|
|
193
|
+
verticalPos = gapInfo.pos + Math.floor(Math.random() * (maxOffset + 1));
|
|
194
|
+
}
|
|
195
|
+
// crear pasillo vertical de ancho fijo 6 entre los dos horizontales
|
|
196
|
+
let vx, vz, vw, vd;
|
|
197
|
+
let zLow, zHigh;
|
|
198
|
+
if (orientation === 'N') {
|
|
199
|
+
vx = verticalPos;
|
|
200
|
+
vz = lastHall.z + lastHall.depth;
|
|
201
|
+
vw = 6;
|
|
202
|
+
vd = cz - vz;
|
|
203
|
+
zLow = vz;
|
|
204
|
+
zHigh = cz;
|
|
205
|
+
} else if (orientation === 'S') {
|
|
206
|
+
vx = verticalPos;
|
|
207
|
+
vz = Math.min(cz + cd, lastHall.z);
|
|
208
|
+
vw = 6;
|
|
209
|
+
vd = Math.abs((lastHall.z) - (cz + cd));
|
|
210
|
+
zLow = vz;
|
|
211
|
+
zHigh = vz + vd;
|
|
212
|
+
} else if (orientation === 'O') {
|
|
213
|
+
vz = verticalPos;
|
|
214
|
+
vx = lastHall.x + lastHall.width;
|
|
215
|
+
vd = 6;
|
|
216
|
+
vw = cz - vx;
|
|
217
|
+
zLow = vx;
|
|
218
|
+
zHigh = cz;
|
|
219
|
+
} else { // E
|
|
220
|
+
vz = verticalPos;
|
|
221
|
+
vx = Math.min(cz + cd, lastHall.x);
|
|
222
|
+
vd = Math.abs((lastHall.x) - (cz + cd));
|
|
223
|
+
vw = 6;
|
|
224
|
+
zLow = vx;
|
|
225
|
+
zHigh = vx + vd;
|
|
226
|
+
}
|
|
227
|
+
const vinst = Object.assign({}, hallCfg, { width: vw, depth: vd });
|
|
228
|
+
if (parcelId) vinst.parcelId = parcelId;
|
|
229
|
+
createRoom(vx, y0, vz, vinst, structures);
|
|
230
|
+
|
|
231
|
+
// tras generar el pasillo, detectar y relocalizar cualquier sala solapada
|
|
232
|
+
const toRequeue = [];
|
|
233
|
+
const handled = new Set();
|
|
234
|
+
|
|
235
|
+
// utilitario para superposición de rectángulos axis-aligned
|
|
236
|
+
function rectOverlap(ax1, az1, ax2, az2, bx1, bz1, bx2, bz2) {
|
|
237
|
+
return ax1 < bx2 && ax2 > bx1 && az1 < bz2 && az2 > bz1;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// rectángulo del pasillo vertical recién creado
|
|
241
|
+
const cabX1 = vx;
|
|
242
|
+
const cabZ1 = vz;
|
|
243
|
+
const cabX2 = vx + vw;
|
|
244
|
+
const cabZ2 = vz + vd;
|
|
245
|
+
|
|
246
|
+
const checkOverlap = (roomsList, rowBack) => {
|
|
247
|
+
const overlaps = [];
|
|
248
|
+
for (const r of roomsList) {
|
|
249
|
+
if (handled.has(r)) continue;
|
|
250
|
+
const { x0, z0 } = coordsFor(r.start, r.w, r.d, rowBack);
|
|
251
|
+
const roomX1 = x0;
|
|
252
|
+
const roomZ1 = z0;
|
|
253
|
+
const roomX2 = x0 + r.w;
|
|
254
|
+
const roomZ2 = z0 + r.d;
|
|
255
|
+
if (!rectOverlap(roomX1, roomZ1, roomX2, roomZ2, cabX1, cabZ1, cabX2, cabZ2))
|
|
256
|
+
continue;
|
|
257
|
+
overlaps.push(r);
|
|
258
|
+
handled.add(r);
|
|
259
|
+
// intentar reubicar inmediatamente en la última fila completada
|
|
260
|
+
let relocated = false;
|
|
261
|
+
if (completedRows.length) {
|
|
262
|
+
const lastRow = completedRows[completedRows.length - 1];
|
|
263
|
+
const gapPos = findGapInList(lastRow.rooms, 0,
|
|
264
|
+
(orientation === 'N' || orientation === 'S') ? plotWidth : plotDepth,
|
|
265
|
+
r.width);
|
|
266
|
+
if (gapPos !== null) {
|
|
267
|
+
const { x0: nx, z0: nz } = coordsFor(gapPos, r.w, r.d, lastRow.backOffset);
|
|
268
|
+
const inst = Object.assign({}, r.cfg, { width: r.w, depth: r.d });
|
|
269
|
+
if (orientation === 'N') inst.frontNorth = true;
|
|
270
|
+
else if (orientation === 'S') inst.frontSouth = true;
|
|
271
|
+
else if (orientation === 'E') inst.frontEast = true;
|
|
272
|
+
else if (orientation === 'O') inst.frontWest = true;
|
|
273
|
+
createRoom(nx, y0, nz, inst, structures);
|
|
274
|
+
lastRow.rooms.push({ type: r.type, start: gapPos, width: r.width, cfg: r.cfg, w: r.w, d: r.d, structIndex: structures.length - 1 });
|
|
275
|
+
// update the offset bounds for that row and extend hall if needed
|
|
276
|
+
lastRow.startOffset = Math.min(lastRow.startOffset, gapPos);
|
|
277
|
+
lastRow.endOffset = Math.max(lastRow.endOffset, gapPos + r.width);
|
|
278
|
+
if (lastRow.hall) {
|
|
279
|
+
if (orientation === 'N' || orientation === 'S') {
|
|
280
|
+
lastRow.hall.x = plotX0 + lastRow.startOffset;
|
|
281
|
+
lastRow.hall.width = lastRow.endOffset - lastRow.startOffset;
|
|
282
|
+
} else {
|
|
283
|
+
lastRow.hall.z = plotZ0 + lastRow.startOffset;
|
|
284
|
+
lastRow.hall.depth = lastRow.endOffset - lastRow.startOffset;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
relocated = true;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (!relocated) {
|
|
291
|
+
toRequeue.push(r.type);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (overlaps.length) {
|
|
295
|
+
const oldStructs = structures.slice();
|
|
296
|
+
structures.length = 0;
|
|
297
|
+
oldStructs.forEach((s, idx) => {
|
|
298
|
+
if (!overlaps.some(rr => rr.structIndex === idx)) structures.push(s);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return overlaps;
|
|
302
|
+
};
|
|
303
|
+
const currOver = checkOverlap(rowRooms, backOffset);
|
|
304
|
+
rowRooms = rowRooms.filter(r => !currOver.includes(r));
|
|
305
|
+
if (completedRows.length) {
|
|
306
|
+
const lastRow = completedRows[completedRows.length - 1];
|
|
307
|
+
const prevOver = checkOverlap(lastRow.rooms, lastRow.backOffset);
|
|
308
|
+
lastRow.rooms = lastRow.rooms.filter(r => !prevOver.includes(r));
|
|
309
|
+
}
|
|
310
|
+
if (toRequeue.length) queue.push(...toRequeue);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
lastHall = newHall;
|
|
314
|
+
return hallStruct;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// contador para asignar la primera sala como entrada
|
|
318
|
+
let roomCounter = 0;
|
|
319
|
+
|
|
320
|
+
while (queue.length) {
|
|
321
|
+
const t = queue.shift();
|
|
322
|
+
// sala especial: forzar salto de fila
|
|
323
|
+
if (t === ROW_BREAK) {
|
|
324
|
+
if (rowStartOffset < Infinity) {
|
|
325
|
+
let cx, cz, cw, cd;
|
|
326
|
+
if (orientation === 'N') {
|
|
327
|
+
cx = plotX0 + rowStartOffset;
|
|
328
|
+
cz = plotZ0 + backOffset + rowMaxCross;
|
|
329
|
+
cw = rowEndOffset - rowStartOffset;
|
|
330
|
+
cd = gap;
|
|
331
|
+
} else if (orientation === 'S') {
|
|
332
|
+
cx = plotX0 + rowStartOffset;
|
|
333
|
+
cz = plotZ0 + plotDepth - (backOffset + rowMaxCross) - gap;
|
|
334
|
+
cw = rowEndOffset - rowStartOffset;
|
|
335
|
+
cd = gap;
|
|
336
|
+
} else if (orientation === 'O') {
|
|
337
|
+
cz = plotZ0 + rowStartOffset;
|
|
338
|
+
cx = plotX0 + backOffset + rowMaxCross;
|
|
339
|
+
cd = rowEndOffset - rowStartOffset;
|
|
340
|
+
cw = gap;
|
|
341
|
+
} else { // E
|
|
342
|
+
cz = plotZ0 + rowStartOffset;
|
|
343
|
+
cx = plotX0 + plotWidth - (backOffset + rowMaxCross) - gap;
|
|
344
|
+
cd = rowEndOffset - rowStartOffset;
|
|
345
|
+
cw = gap;
|
|
346
|
+
}
|
|
347
|
+
// antes de colocar el pasillo, cerrar la fila actual
|
|
348
|
+
// registrar fila antes de mover el offset (igual que en canAdvance)
|
|
349
|
+
// capture hall reference and offset ranges
|
|
350
|
+
const hallRef = addHorizontalHall(cx, cz, cw, cd);
|
|
351
|
+
completedRows.push({ rooms: rowRooms.slice(), backOffset: backOffset,
|
|
352
|
+
startOffset: rowStartOffset,
|
|
353
|
+
endOffset: rowEndOffset,
|
|
354
|
+
hall: hallRef });
|
|
355
|
+
}
|
|
356
|
+
// avanzar al inicio de la siguiente fila (se usa el mismo incremento
|
|
357
|
+
// que en la lógica normal de avance de fila)
|
|
358
|
+
backOffset += rowMaxCross + gap;
|
|
359
|
+
|
|
360
|
+
// preparar variables para la nueva fila
|
|
361
|
+
offset = 0;
|
|
362
|
+
rowMaxCross = 0;
|
|
363
|
+
rowStartOffset = Infinity;
|
|
364
|
+
rowEndOffset = 0;
|
|
365
|
+
rowRooms = [];
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const cfg = ROOM_CONFIGS[t];
|
|
370
|
+
if (!cfg) continue;
|
|
371
|
+
|
|
372
|
+
let w = cfg.width;
|
|
373
|
+
let d = cfg.depth;
|
|
374
|
+
if (orientation === 'E' || orientation === 'O') {
|
|
375
|
+
[w, d] = [d, w];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const computeCoords = () => {
|
|
379
|
+
let xx, zz;
|
|
380
|
+
switch (orientation) {
|
|
381
|
+
case 'N':
|
|
382
|
+
xx = plotX0 + offset;
|
|
383
|
+
zz = plotZ0 + backOffset;
|
|
384
|
+
break;
|
|
385
|
+
case 'S':
|
|
386
|
+
xx = plotX0 + offset;
|
|
387
|
+
zz = plotZ0 + plotDepth - d - backOffset;
|
|
388
|
+
break;
|
|
389
|
+
case 'O':
|
|
390
|
+
xx = plotX0 + backOffset;
|
|
391
|
+
zz = plotZ0 + offset;
|
|
392
|
+
break;
|
|
393
|
+
case 'E':
|
|
394
|
+
xx = plotX0 + plotWidth - w - backOffset;
|
|
395
|
+
zz = plotZ0 + offset;
|
|
396
|
+
break;
|
|
397
|
+
default:
|
|
398
|
+
xx = zz = NaN;
|
|
399
|
+
}
|
|
400
|
+
return { x0: xx, z0: zz };
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
let placed = false;
|
|
404
|
+
while (!placed) {
|
|
405
|
+
const offsetBefore = offset;
|
|
406
|
+
const { x0, z0 } = computeCoords();
|
|
407
|
+
const fits = !(x0 < plotX0 || z0 < plotZ0 ||
|
|
408
|
+
x0 + w > plotX0 + plotWidth || z0 + d > plotZ0 + plotDepth);
|
|
409
|
+
|
|
410
|
+
if (fits) {
|
|
411
|
+
rowStartOffset = Math.min(rowStartOffset, offsetBefore);
|
|
412
|
+
rowEndOffset = Math.max(rowEndOffset, offsetBefore + ((orientation === 'N' || orientation === 'S') ? w : d));
|
|
413
|
+
|
|
414
|
+
const inst = Object.assign({}, cfg, { width: w, depth: d });
|
|
415
|
+
if (orientation === 'N') inst.frontNorth = true;
|
|
416
|
+
else if (orientation === 'S') inst.frontSouth = true;
|
|
417
|
+
else if (orientation === 'E') inst.frontEast = true;
|
|
418
|
+
else if (orientation === 'O') inst.frontWest = true;
|
|
419
|
+
|
|
420
|
+
if (roomCounter === 0) {
|
|
421
|
+
inst.hasFrontDoor = true;
|
|
422
|
+
roomCounter = 1;
|
|
423
|
+
}
|
|
424
|
+
if (parcelId) inst.parcelId = parcelId;
|
|
425
|
+
|
|
426
|
+
// registrar sala antes de crearla para poder relocalizar si hace falta
|
|
427
|
+
const startPrimary = offsetBefore;
|
|
428
|
+
const widthPrimary = (orientation === 'N' || orientation === 'S') ? w : d;
|
|
429
|
+
rowRooms.push({ type: t, start: startPrimary, width: widthPrimary,
|
|
430
|
+
cfg, w, d, structIndex: structures.length });
|
|
431
|
+
|
|
432
|
+
createRoom(x0, y0, z0, inst, structures);
|
|
433
|
+
|
|
434
|
+
rowMaxCross = Math.max(rowMaxCross, (orientation === 'N' || orientation === 'S') ? d : w);
|
|
435
|
+
offset += (orientation === 'N' || orientation === 'S') ? w : d;
|
|
436
|
+
placed = true;
|
|
437
|
+
} else {
|
|
438
|
+
const canAdvance = (orientation === 'N' || orientation === 'S') ?
|
|
439
|
+
(backOffset + rowMaxCross + gap + d <= plotDepth) :
|
|
440
|
+
(backOffset + rowMaxCross + gap + w <= plotWidth);
|
|
441
|
+
if (canAdvance) {
|
|
442
|
+
if (rowStartOffset < Infinity) {
|
|
443
|
+
let cx, cz, cw, cd;
|
|
444
|
+
if (orientation === 'N') {
|
|
445
|
+
cx = plotX0 + rowStartOffset;
|
|
446
|
+
cz = plotZ0 + backOffset + rowMaxCross;
|
|
447
|
+
cw = rowEndOffset - rowStartOffset;
|
|
448
|
+
cd = gap;
|
|
449
|
+
} else if (orientation === 'S') {
|
|
450
|
+
cx = plotX0 + rowStartOffset;
|
|
451
|
+
cz = plotZ0 + plotDepth - (backOffset + rowMaxCross) - gap;
|
|
452
|
+
cw = rowEndOffset - rowStartOffset;
|
|
453
|
+
cd = gap;
|
|
454
|
+
} else if (orientation === 'O') {
|
|
455
|
+
cz = plotZ0 + rowStartOffset;
|
|
456
|
+
cx = plotX0 + backOffset + rowMaxCross;
|
|
457
|
+
cd = rowEndOffset - rowStartOffset;
|
|
458
|
+
cw = gap;
|
|
459
|
+
} else { // E
|
|
460
|
+
cz = plotZ0 + rowStartOffset;
|
|
461
|
+
cx = plotX0 + plotWidth - (backOffset + rowMaxCross) - gap;
|
|
462
|
+
cd = rowEndOffset - rowStartOffset;
|
|
463
|
+
cw = gap;
|
|
464
|
+
}
|
|
465
|
+
// registrar fila actual antes de colocar el pasillo; capturamos el hall
|
|
466
|
+
const hallRef = addHorizontalHall(cx, cz, cw, cd);
|
|
467
|
+
completedRows.push({ rooms: rowRooms.slice(), backOffset: backOffset,
|
|
468
|
+
startOffset: rowStartOffset,
|
|
469
|
+
endOffset: rowEndOffset,
|
|
470
|
+
hall: hallRef });
|
|
471
|
+
}
|
|
472
|
+
backOffset += rowMaxCross + gap;
|
|
473
|
+
offset = 0;
|
|
474
|
+
rowMaxCross = 0;
|
|
475
|
+
rowStartOffset = Infinity;
|
|
476
|
+
rowEndOffset = 0;
|
|
477
|
+
rowRooms = [];
|
|
478
|
+
queue.unshift(t);
|
|
479
|
+
placed = true;
|
|
480
|
+
} else {
|
|
481
|
+
placed = true;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// genera_nidos.js - Decide los nidos de zombies del mapa (plan_supervivencia.md
|
|
2
|
+
// §5). Corre una sola vez al construir el mapa, con la heightMap todavía como
|
|
3
|
+
// arrays y las zonas `parcela` a mano. Es puro (sin sockets): lo prueba
|
|
4
|
+
// scripts/test_nidos.mjs.
|
|
5
|
+
|
|
6
|
+
import { PROB_NIDO_PARCELA, INTENTOS_NIDO, RADIO_NIDO, DIST_MIN_BASE_NIDO, DIST_MIN_ENTRE_NIDOS } from '../plugins/datos.js';
|
|
7
|
+
import { BLOCK_TYPES } from './mapConfig.js';
|
|
8
|
+
|
|
9
|
+
const MARGEN_EDIFICIO = 2; // aire libre entre el nido y cualquier pared
|
|
10
|
+
const MARGEN_OBJETO = 2; // ... y árboles/postes/luces (además del radio)
|
|
11
|
+
const MARGEN_BORDE_MAPA = 12;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param zonas lista de zonas del mapa (se usan las de tipo 'parcela')
|
|
15
|
+
* @param ctx { structures, entities, heightMap, surfaceTypeMap, width, depth, bases: [{x,z}], rand }
|
|
16
|
+
* @returns [{ id, x, y, z, radio, parcela }]
|
|
17
|
+
*/
|
|
18
|
+
export function generarNidos(zonas, ctx) {
|
|
19
|
+
const { structures = [], entities = [], heightMap, surfaceTypeMap, width, depth, bases = [], rand = Math.random } = ctx;
|
|
20
|
+
const nidos = [];
|
|
21
|
+
const edificios = structures.filter(s => s && s.width != null && s.depth != null && s.x >= 0 && s.z >= 0);
|
|
22
|
+
const objetos = entities.filter(e => e && e.type === 'entidad_objeto');
|
|
23
|
+
const R = RADIO_NIDO;
|
|
24
|
+
|
|
25
|
+
const alt = (x, z) => {
|
|
26
|
+
const col = heightMap[x];
|
|
27
|
+
const v = col && col[z];
|
|
28
|
+
return typeof v === 'number' ? v : null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const motivo = ctx.diag || {};
|
|
32
|
+
const no = (m) => { motivo[m] = (motivo[m] || 0) + 1; return false; };
|
|
33
|
+
const libre = (x, z) => {
|
|
34
|
+
if (x < MARGEN_BORDE_MAPA || z < MARGEN_BORDE_MAPA || x > width - MARGEN_BORDE_MAPA || z > depth - MARGEN_BORDE_MAPA) return no('borde');
|
|
35
|
+
const r = R + MARGEN_EDIFICIO;
|
|
36
|
+
for (const s of edificios) {
|
|
37
|
+
if (x > s.x - r && x < s.x + s.width + r && z > s.z - r && z < s.z + s.depth + r) return no('edificio');
|
|
38
|
+
}
|
|
39
|
+
const ro = R + MARGEN_OBJETO;
|
|
40
|
+
for (const e of objetos) if (Math.abs(e.x - x) < ro && Math.abs(e.z - z) < ro && Math.hypot(e.x - x, e.z - z) < ro) return no('objeto');
|
|
41
|
+
for (const b of bases) if (b && Math.hypot(b.x - x, b.z - z) < DIST_MIN_BASE_NIDO) return no('base');
|
|
42
|
+
for (const n of nidos) if (Math.hypot(n.x - x, n.z - z) < DIST_MIN_ENTRE_NIDOS) return no('entre');
|
|
43
|
+
// suelo plano y no calle/vereda: toda la huella a la misma altura
|
|
44
|
+
const h0 = alt(x, z);
|
|
45
|
+
if (h0 == null) return no('sinaltura');
|
|
46
|
+
for (let dx = -R; dx <= R; dx += 1) {
|
|
47
|
+
for (let dz = -R; dz <= R; dz += 1) {
|
|
48
|
+
if (dx * dx + dz * dz > R * R) continue;
|
|
49
|
+
const xi = x + dx, zi = z + dz;
|
|
50
|
+
if (alt(xi, zi) !== h0) return no('desnivel');
|
|
51
|
+
const t = surfaceTypeMap[xi] && surfaceTypeMap[xi][zi];
|
|
52
|
+
if (t === BLOCK_TYPES.ASPHALT || t === BLOCK_TYPES.VEREDA || t === BLOCK_TYPES.BRICK) return no('superficie');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
for (const z of zonas || []) {
|
|
59
|
+
if (z.tipo !== 'parcela') continue;
|
|
60
|
+
if (z.x0 < 0 || z.z0 < 0 || z.x1 > width || z.z1 > depth) continue; // parcela fuera del mapa recortado
|
|
61
|
+
if (rand() >= PROB_NIDO_PARCELA) continue;
|
|
62
|
+
const m = R + 2;
|
|
63
|
+
const ancho = z.x1 - z.x0 - 2 * m, prof = z.z1 - z.z0 - 2 * m;
|
|
64
|
+
if (ancho <= 0 || prof <= 0) continue;
|
|
65
|
+
for (let k = 0; k < INTENTOS_NIDO; k++) {
|
|
66
|
+
const x = Math.floor(z.x0 + m + rand() * ancho);
|
|
67
|
+
const zz = Math.floor(z.z0 + m + rand() * prof);
|
|
68
|
+
if (!libre(x, zz)) continue;
|
|
69
|
+
nidos.push({ id: nidos.length, x: x + 0.5, y: alt(x, zz), z: zz + 0.5, radio: R, parcela: z.id });
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return nidos;
|
|
74
|
+
}
|