@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,476 @@
|
|
|
1
|
+
// Lógica específica de una "cuadra" para el mapa tipo 3.
|
|
2
|
+
// Se ocupa de pintar veredas, parterres, delimitar parcelas y construir
|
|
3
|
+
// las casas/estructura interior. El archivo principal (mapType3.js) define
|
|
4
|
+
// la grilla de cuadras y calles y delega el trabajo de cada bloque a este módulo.
|
|
5
|
+
|
|
6
|
+
import { BLOCK_TYPES, WORLD_CONFIG } from './mapConfig.js';
|
|
7
|
+
import { processInterior } from './mapType3Center.js';
|
|
8
|
+
import { elegirArbol } from '../plugins/datos.js';
|
|
9
|
+
import { AUTOS, ORDEN_AUTOS, idEntidadAuto, PROPORCION_MOTOS } from '../plugins/datos.js';
|
|
10
|
+
import { ID_POSTE } from '../plugins/datos.js';
|
|
11
|
+
import { ID_LUZ_INTERIOR } from '../plugins/datos.js';
|
|
12
|
+
|
|
13
|
+
// Listas de autos por tipo. Se calculan al usarlas (no al cargar el módulo):
|
|
14
|
+
// los datos de autos llegan por plugin (ver plugins/registro.js).
|
|
15
|
+
// los drones de base los crea el juego, no se estacionan al azar.
|
|
16
|
+
function listasDeAutos() {
|
|
17
|
+
return {
|
|
18
|
+
MOTOS: ORDEN_AUTOS.filter(id => AUTOS[id].forma === 'moto'),
|
|
19
|
+
CARROS: ORDEN_AUTOS.filter(id => AUTOS[id].forma !== 'moto' && AUTOS[id].forma !== 'drone'),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Constantes compartidas con mapType3.js
|
|
24
|
+
const blockZoneSize = 176; // tamaño de la cuadra en bloques (doble) ajustado para que el interior siga siendo 144
|
|
25
|
+
const veredaWidth = 16; // ancho de la vereda en bloques (borde interior de la cuadra) duplicado
|
|
26
|
+
const streetWidth = 20; // ancho de la calle en bloques (doble)
|
|
27
|
+
const patternSize = blockZoneSize + streetWidth;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// dimensiones de la sala inicial y de las casas (altura de casa igual a sala)
|
|
31
|
+
const roomWidth = 12;
|
|
32
|
+
const roomHeight = 12;
|
|
33
|
+
const roomDepth = 12;
|
|
34
|
+
|
|
35
|
+
// parque: 10% de las cuadras. Pasto en todo el suelo y muchos árboles, más juntos
|
|
36
|
+
// que en una vereda (distancia mínima entre troncos de 6 bloques en vez de 8).
|
|
37
|
+
const PROBABILIDAD_PARQUE = 0.10;
|
|
38
|
+
const DISTANCIA_ARBOL_PARQUE = 6;
|
|
39
|
+
const INTENTOS_ARBOL_PARQUE = 400;
|
|
40
|
+
const MARGEN_PARQUE = 4; // sin árboles pegados a la calle
|
|
41
|
+
const RADIO_LIBRE_CENTRO_PARQUE = 8;
|
|
42
|
+
|
|
43
|
+
// parámetros para parterres
|
|
44
|
+
const patchSize = 2; // 2x2
|
|
45
|
+
const gapBetweenPatches = 16; // separación entre parterres (doble que antes)
|
|
46
|
+
const step = patchSize + gapBetweenPatches; // 18
|
|
47
|
+
|
|
48
|
+
// postes de alumbrado: uno cada POSTE_ESPACIADO bloques, pegados al cordón de
|
|
49
|
+
// la vereda (el borde que da a la calle), con el farol mirando hacia ella.
|
|
50
|
+
// Sólo forma por ahora, sin fuente de luz (ver cliente/modelo_poste.js).
|
|
51
|
+
const POSTE_ESPACIADO = 48; // el doble que antes (24): la mitad de postes por cuadra
|
|
52
|
+
const POSTE_MARGEN_ESQUINA = 10; // no pegado a la esquina, como los autos
|
|
53
|
+
|
|
54
|
+
// El árbol se planta en el CENTRO del parterre. Un bloque de índice i ocupa el
|
|
55
|
+
// intervalo [i, i+1) del mundo (es la convención de `fisica_mapa.js`, que pasa
|
|
56
|
+
// de mundo a bloque con Math.floor), así que un parterre que arranca en el
|
|
57
|
+
// bloque x0 y mide `patchSize` va de x0 a x0 + patchSize y su centro cae en
|
|
58
|
+
// x0 + patchSize/2. Antes se le restaba medio bloque y el árbol quedaba
|
|
59
|
+
// clavado en el centro del PRIMER bloque del parterre, con lo que de un lado
|
|
60
|
+
// le sobraba medio bloque y del otro bloque y medio: el tronco se salía al
|
|
61
|
+
// cantero en cuanto se lo escalaba. Con el centro bien puesto, el tronco tiene
|
|
62
|
+
// patchSize/2 bloques de radio para crecer, que es lo que da por cierto
|
|
63
|
+
// `cliente/arboles_config.js` en RADIO_MAX_TRONCO.
|
|
64
|
+
const patchCenterOffset = patchSize / 2;
|
|
65
|
+
|
|
66
|
+
// función auxiliar reutilizada por cada cuadra para evitar árboles demasiado
|
|
67
|
+
// cercanos unos de otros. Está encapsulada aquí ya que sólo se usa en este
|
|
68
|
+
// módulo y trabaja sobre el array "entities" que se pasa como argumento.
|
|
69
|
+
//
|
|
70
|
+
// La especie, el tamaño y la rotación los sortea `cliente/arboles_config.js` a
|
|
71
|
+
// partir de la posición del parterre: son los árboles procedurales de
|
|
72
|
+
// `cliente/modelo_arbol.js` y ya no hay un único GLTF repetido. El sorteo es
|
|
73
|
+
// determinista, así que el mismo parterre planta siempre el mismo árbol.
|
|
74
|
+
//
|
|
75
|
+
// La comparación de distancia mira TODOS los árboles, no los de la misma
|
|
76
|
+
// especie: con trece variedades, filtrar por modelo dejaría pasar dos árboles
|
|
77
|
+
// distintos superpuestos en las esquinas, donde se cruzan las dos hileras de
|
|
78
|
+
// la vereda.
|
|
79
|
+
function addTreeIfAllowed(entities, x, y, z, distanciaMinima = null) {
|
|
80
|
+
const treeMinDistance = distanciaMinima ?? ((typeof WORLD_CONFIG.treeMinDistance === 'number') ? WORLD_CONFIG.treeMinDistance : 8);
|
|
81
|
+
const treeMinDistanceSq = treeMinDistance * treeMinDistance;
|
|
82
|
+
for (const ent of entities) {
|
|
83
|
+
if (ent.arbol) {
|
|
84
|
+
const dx = ent.x - x;
|
|
85
|
+
const dz = ent.z - z;
|
|
86
|
+
if ((dx * dx + dz * dz) < treeMinDistanceSq) {
|
|
87
|
+
return false; // demasiado cerca: no añadir
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const { model, escala, rotY } = elegirArbol(x, z);
|
|
92
|
+
entities.push({ type: 'entidad_objeto', model, x, y, z, rotY, escala, arbol: true });
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Genera todos los detalles de una única cuadra. Se invoca desde generateMapType3
|
|
97
|
+
// por cada bloqueStartX/Z que delimita una cuadra. Modifica los mapas y arrays
|
|
98
|
+
// que se le pasan por referencia.
|
|
99
|
+
function processBlock(blockStartX, blockStartZ, width, depth, baseY, heightMap, maxHeightMap, surfaceTypeMap, structures, entities, zonas) {
|
|
100
|
+
const blockId = `${blockStartX}_${blockStartZ}`;
|
|
101
|
+
if (Math.random() < PROBABILIDAD_PARQUE) {
|
|
102
|
+
armarParque(blockStartX, blockStartZ, width, depth, heightMap, surfaceTypeMap, entities);
|
|
103
|
+
addVehiculos(blockStartX, blockStartZ, width, depth, heightMap, entities);
|
|
104
|
+
// zona de control: un parque es una única zona grande, sin parcelas ni
|
|
105
|
+
// veredas separadas (ver plan_zonas_control.md, "parques" pendiente).
|
|
106
|
+
if (zonas) {
|
|
107
|
+
zonas.push({
|
|
108
|
+
id: `${blockId}:parque`, tipo: 'parque',
|
|
109
|
+
x0: blockStartX, z0: blockStartZ,
|
|
110
|
+
x1: blockStartX + blockZoneSize, z1: blockStartZ + blockZoneSize
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
agregarZonasCalle(blockStartX, blockStartZ, blockId, zonas);
|
|
114
|
+
agregarPostes(blockStartX, blockStartZ, width, depth, heightMap, entities);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// procesar interior de la cuadra (parcelas y casas)
|
|
118
|
+
const structuresAntes = structures.length;
|
|
119
|
+
processInterior(blockStartX, blockStartZ, width, depth, baseY, heightMap, surfaceTypeMap, structures, roomWidth, roomHeight, zonas);
|
|
120
|
+
agregarLucesInteriores(structures, structuresAntes, entities);
|
|
121
|
+
agregarZonasVereda(blockStartX, blockStartZ, blockId, zonas);
|
|
122
|
+
agregarZonasCalle(blockStartX, blockStartZ, blockId, zonas);
|
|
123
|
+
// 2. añadir parterres en las veredas de esta cuadra
|
|
124
|
+
const patchOffset = Math.min(
|
|
125
|
+
veredaWidth - patchSize,
|
|
126
|
+
Math.floor(veredaWidth / 2) + 1
|
|
127
|
+
);
|
|
128
|
+
const alongLineStartOffset = patchOffset;
|
|
129
|
+
|
|
130
|
+
// Vereda norte (top)
|
|
131
|
+
const zTop = blockStartZ + patchOffset;
|
|
132
|
+
const maxOX_north = blockZoneSize - patchSize - patchOffset;
|
|
133
|
+
for (let ox = alongLineStartOffset; ox <= maxOX_north; ox += step) {
|
|
134
|
+
const x0 = blockStartX + ox;
|
|
135
|
+
const centerXi = x0;
|
|
136
|
+
const centerZi = zTop;
|
|
137
|
+
if (!(centerXi >= 0 && centerXi < width && centerZi >= 0 && centerZi < depth && surfaceTypeMap[centerXi][centerZi] === BLOCK_TYPES.VEREDA)) continue;
|
|
138
|
+
const centerY = heightMap[centerXi] && typeof heightMap[centerXi][centerZi] === 'number' ? heightMap[centerXi][centerZi] : baseY;
|
|
139
|
+
const treeY = Math.max(0, centerY - 1);
|
|
140
|
+
if (!addTreeIfAllowed(entities, x0 + patchCenterOffset, treeY, zTop + patchCenterOffset)) continue;
|
|
141
|
+
for (let dx = 0; dx < patchSize; dx++) {
|
|
142
|
+
for (let dz = 0; dz < patchSize; dz++) {
|
|
143
|
+
const x = x0 + dx;
|
|
144
|
+
const z = zTop + dz;
|
|
145
|
+
if (x >= 0 && x < width && z >= 0 && z < depth && surfaceTypeMap[x][z] === BLOCK_TYPES.VEREDA) {
|
|
146
|
+
surfaceTypeMap[x][z] = BLOCK_TYPES.GREEN;
|
|
147
|
+
if (heightMap[x] && typeof heightMap[x][z] === 'number') {
|
|
148
|
+
heightMap[x][z] = Math.max(0, heightMap[x][z] - 1);
|
|
149
|
+
if (maxHeightMap && maxHeightMap[x]) {
|
|
150
|
+
maxHeightMap[x][z] = heightMap[x][z];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Vereda sur (bottom)
|
|
159
|
+
const zBottom = blockStartZ + blockZoneSize - patchOffset - patchSize;
|
|
160
|
+
const maxOX_south = blockZoneSize - patchSize - patchOffset;
|
|
161
|
+
for (let ox = alongLineStartOffset; ox <= maxOX_south; ox += step) {
|
|
162
|
+
const x0 = blockStartX + ox;
|
|
163
|
+
const centerXi = x0;
|
|
164
|
+
const centerZi = zBottom;
|
|
165
|
+
if (!(centerXi >= 0 && centerXi < width && centerZi >= 0 && centerZi < depth && surfaceTypeMap[centerXi][centerZi] === BLOCK_TYPES.VEREDA)) continue;
|
|
166
|
+
const centerY = heightMap[centerXi] && typeof heightMap[centerXi][centerZi] === 'number' ? heightMap[centerXi][centerZi] : baseY;
|
|
167
|
+
const treeY = Math.max(0, centerY - 1);
|
|
168
|
+
if (!addTreeIfAllowed(entities, x0 + patchCenterOffset, treeY, zBottom + patchCenterOffset)) continue;
|
|
169
|
+
for (let dx = 0; dx < patchSize; dx++) {
|
|
170
|
+
for (let dz = 0; dz < patchSize; dz++) {
|
|
171
|
+
const x = x0 + dx;
|
|
172
|
+
const z = zBottom + dz;
|
|
173
|
+
if (x >= 0 && x < width && z >= 0 && z < depth && surfaceTypeMap[x][z] === BLOCK_TYPES.VEREDA) {
|
|
174
|
+
surfaceTypeMap[x][z] = BLOCK_TYPES.GREEN;
|
|
175
|
+
if (heightMap[x] && typeof heightMap[x][z] === 'number') {
|
|
176
|
+
heightMap[x][z] = Math.max(0, heightMap[x][z] - 1);
|
|
177
|
+
if (maxHeightMap && maxHeightMap[x]) {
|
|
178
|
+
maxHeightMap[x][z] = heightMap[x][z];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Vereda oeste (left)
|
|
187
|
+
const xLeft = blockStartX + patchOffset;
|
|
188
|
+
const maxOZ_west = blockZoneSize - patchSize - patchOffset;
|
|
189
|
+
for (let oz = alongLineStartOffset; oz <= maxOZ_west; oz += step) {
|
|
190
|
+
const z0 = blockStartZ + oz;
|
|
191
|
+
const centerXi = xLeft;
|
|
192
|
+
const centerZi = z0;
|
|
193
|
+
if (!(centerXi >= 0 && centerXi < width && centerZi >= 0 && centerZi < depth && surfaceTypeMap[centerXi][centerZi] === BLOCK_TYPES.VEREDA)) continue;
|
|
194
|
+
const centerY = heightMap[centerXi] && typeof heightMap[centerXi][centerZi] === 'number' ? heightMap[centerXi][centerZi] : baseY;
|
|
195
|
+
const treeY = Math.max(0, centerY - 1);
|
|
196
|
+
if (!addTreeIfAllowed(entities, xLeft + patchCenterOffset, treeY, z0 + patchCenterOffset)) continue;
|
|
197
|
+
for (let dx = 0; dx < patchSize; dx++) {
|
|
198
|
+
for (let dz = 0; dz < patchSize; dz++) {
|
|
199
|
+
const x = xLeft + dx;
|
|
200
|
+
const z = z0 + dz;
|
|
201
|
+
if (x >= 0 && x < width && z >= 0 && z < depth && surfaceTypeMap[x][z] === BLOCK_TYPES.VEREDA) {
|
|
202
|
+
surfaceTypeMap[x][z] = BLOCK_TYPES.GREEN;
|
|
203
|
+
if (heightMap[x] && typeof heightMap[x][z] === 'number') {
|
|
204
|
+
heightMap[x][z] = Math.max(0, heightMap[x][z] - 1);
|
|
205
|
+
if (maxHeightMap && maxHeightMap[x]) {
|
|
206
|
+
maxHeightMap[x][z] = heightMap[x][z];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Vereda este (right)
|
|
215
|
+
const xRight = blockStartX + blockZoneSize - patchOffset - patchSize;
|
|
216
|
+
const maxOZ_east = blockZoneSize - patchSize - patchOffset;
|
|
217
|
+
for (let oz = alongLineStartOffset; oz <= maxOZ_east; oz += step) {
|
|
218
|
+
const z0 = blockStartZ + oz;
|
|
219
|
+
const centerXi = xRight;
|
|
220
|
+
const centerZi = z0;
|
|
221
|
+
if (!(centerXi >= 0 && centerXi < width && centerZi >= 0 && centerZi < depth && surfaceTypeMap[centerXi][centerZi] === BLOCK_TYPES.VEREDA)) continue;
|
|
222
|
+
const centerY = heightMap[centerXi] && typeof heightMap[centerXi][centerZi] === 'number' ? heightMap[centerXi][centerZi] : baseY;
|
|
223
|
+
const treeY = Math.max(0, centerY - 1);
|
|
224
|
+
if (!addTreeIfAllowed(entities, xRight + patchCenterOffset, treeY, z0 + patchCenterOffset)) continue;
|
|
225
|
+
for (let dx = 0; dx < patchSize; dx++) {
|
|
226
|
+
for (let dz = 0; dz < patchSize; dz++) {
|
|
227
|
+
const x = xRight + dx;
|
|
228
|
+
const z = z0 + dz;
|
|
229
|
+
if (x >= 0 && x < width && z >= 0 && z < depth && surfaceTypeMap[x][z] === BLOCK_TYPES.VEREDA) {
|
|
230
|
+
surfaceTypeMap[x][z] = BLOCK_TYPES.GREEN;
|
|
231
|
+
if (heightMap[x] && typeof heightMap[x][z] === 'number') {
|
|
232
|
+
heightMap[x][z] = Math.max(0, heightMap[x][z] - 1);
|
|
233
|
+
if (maxHeightMap && maxHeightMap[x]) {
|
|
234
|
+
maxHeightMap[x][z] = heightMap[x][z];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
addVehiculos(blockStartX, blockStartZ, width, depth, heightMap, entities);
|
|
242
|
+
agregarPostes(blockStartX, blockStartZ, width, depth, heightMap, entities);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// --- zonas de control (modo equipos) ------------------------------------------
|
|
246
|
+
//
|
|
247
|
+
// Las 4 tiras de vereda de una cuadra, como zonas separadas (una por lado). Las
|
|
248
|
+
// esquinas quedan del lado de la vereda norte/sur para no superponer zonas.
|
|
249
|
+
function agregarZonasVereda(blockStartX, blockStartZ, blockId, zonas) {
|
|
250
|
+
if (!zonas) return;
|
|
251
|
+
zonas.push(
|
|
252
|
+
{ id: `${blockId}:vereda:N`, tipo: 'vereda', x0: blockStartX, z0: blockStartZ, x1: blockStartX + blockZoneSize, z1: blockStartZ + veredaWidth },
|
|
253
|
+
{ id: `${blockId}:vereda:S`, tipo: 'vereda', x0: blockStartX, z0: blockStartZ + blockZoneSize - veredaWidth, x1: blockStartX + blockZoneSize, z1: blockStartZ + blockZoneSize },
|
|
254
|
+
{ id: `${blockId}:vereda:O`, tipo: 'vereda', x0: blockStartX, z0: blockStartZ + veredaWidth, x1: blockStartX + veredaWidth, z1: blockStartZ + blockZoneSize - veredaWidth },
|
|
255
|
+
{ id: `${blockId}:vereda:E`, tipo: 'vereda', x0: blockStartX + blockZoneSize - veredaWidth, z0: blockStartZ + veredaWidth, x1: blockStartX + blockZoneSize, z1: blockStartZ + blockZoneSize - veredaWidth }
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Cada cuadra se queda con la calle de su lado este y la de su lado sur (la
|
|
260
|
+
// misma convención que `addVehiculos`, así ninguna calle se cuenta dos veces).
|
|
261
|
+
// La esquina sureste (donde se cruzan ambas calles) queda del lado de la zona
|
|
262
|
+
// sur para que, igual que con las veredas, no se superpongan.
|
|
263
|
+
function agregarZonasCalle(blockStartX, blockStartZ, blockId, zonas) {
|
|
264
|
+
if (!zonas) return;
|
|
265
|
+
zonas.push(
|
|
266
|
+
{ id: `${blockId}:calle:S`, tipo: 'calle', x0: blockStartX, z0: blockStartZ + blockZoneSize, x1: blockStartX + blockZoneSize + streetWidth, z1: blockStartZ + blockZoneSize + streetWidth },
|
|
267
|
+
{ id: `${blockId}:calle:E`, tipo: 'calle', x0: blockStartX + blockZoneSize, z0: blockStartZ, x1: blockStartX + blockZoneSize + streetWidth, z1: blockStartZ + blockZoneSize }
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// --- parque -------------------------------------------------------------------
|
|
272
|
+
//
|
|
273
|
+
// Con probabilidad PROBABILIDAD_PARQUE la cuadra entera es un parque: todo el
|
|
274
|
+
// suelo (veredas incluidas) queda como pasto, no hay casas ni parterres y se
|
|
275
|
+
// planta un bosque de árboles repartidos al azar. No se toca la altura, así que
|
|
276
|
+
// se camina igual que por una vereda.
|
|
277
|
+
function armarParque(blockStartX, blockStartZ, width, depth, heightMap, surfaceTypeMap, entities) {
|
|
278
|
+
for (let dx = 0; dx < blockZoneSize; dx++) {
|
|
279
|
+
for (let dz = 0; dz < blockZoneSize; dz++) {
|
|
280
|
+
const x = blockStartX + dx;
|
|
281
|
+
const z = blockStartZ + dz;
|
|
282
|
+
if (x < width && z < depth) surfaceTypeMap[x][z] = BLOCK_TYPES.GREEN;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// centro de la cuadra: ahí cae la sala de inicio (ver mapType3Center.js),
|
|
287
|
+
// así que no se planta nada alrededor para que el jugador no nazca tronco adentro
|
|
288
|
+
const centroX = blockStartX + blockZoneSize / 2;
|
|
289
|
+
const centroZ = blockStartZ + blockZoneSize / 2;
|
|
290
|
+
const radioLibreCentro = RADIO_LIBRE_CENTRO_PARQUE;
|
|
291
|
+
|
|
292
|
+
for (let i = 0; i < INTENTOS_ARBOL_PARQUE; i++) {
|
|
293
|
+
const x = blockStartX + MARGEN_PARQUE + Math.random() * (blockZoneSize - 2 * MARGEN_PARQUE);
|
|
294
|
+
const z = blockStartZ + MARGEN_PARQUE + Math.random() * (blockZoneSize - 2 * MARGEN_PARQUE);
|
|
295
|
+
const xi = Math.floor(x);
|
|
296
|
+
const zi = Math.floor(z);
|
|
297
|
+
if (xi >= width || zi >= depth) continue;
|
|
298
|
+
if ((x - centroX) ** 2 + (z - centroZ) ** 2 < radioLibreCentro ** 2) continue;
|
|
299
|
+
const y = Math.max(0, heightMap[xi][zi] - 1);
|
|
300
|
+
addTreeIfAllowed(entities, xi + 0.5, y, zi + 0.5, DISTANCIA_ARBOL_PARQUE);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// --- autos estacionados -------------------------------------------------------
|
|
305
|
+
//
|
|
306
|
+
// Cada cuadra se queda con la calle de su lado este y la de su lado sur (la
|
|
307
|
+
// del oeste y la del norte son las de la cuadra vecina), así ninguna calle
|
|
308
|
+
// recibe autos dos veces. Se estacionan en dos carriles, a 5 y a 15 bloques del
|
|
309
|
+
// cordón de la calle de 20: el centro queda libre para pasar.
|
|
310
|
+
//
|
|
311
|
+
// Sorteo determinista por cuadra (mismo mapa = mismos autos), con la misma
|
|
312
|
+
// idea que `elegirArbol`.
|
|
313
|
+
|
|
314
|
+
const AUTOS_MIN = 2;
|
|
315
|
+
const AUTOS_MAX = 3;
|
|
316
|
+
const CARRILES = [5, 15];
|
|
317
|
+
const MARGEN_CUADRA = 14; // a lo largo de la calle, lejos de las esquinas
|
|
318
|
+
const SEPARACION_AUTOS = 18;
|
|
319
|
+
|
|
320
|
+
function crearRng(semilla) {
|
|
321
|
+
let s = semilla >>> 0;
|
|
322
|
+
return () => {
|
|
323
|
+
s = (s + 0x6D2B79F5) >>> 0;
|
|
324
|
+
let t = s;
|
|
325
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
326
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
327
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function addVehiculos(blockStartX, blockStartZ, width, depth, heightMap, entities) {
|
|
332
|
+
const listas = listasDeAutos();
|
|
333
|
+
const rng = crearRng(Math.imul(blockStartX + 1, 73856093) ^ Math.imul(blockStartZ + 1, 19349663));
|
|
334
|
+
const cantidad = AUTOS_MIN + Math.floor(rng() * (AUTOS_MAX - AUTOS_MIN + 1));
|
|
335
|
+
const colocados = [];
|
|
336
|
+
// Se reparte por cuenta, no por sorteo: moto cada vez que las que hay hasta
|
|
337
|
+
// ahora no alcanzan para la proporción pedida. Así el mapa da casi exacto el
|
|
338
|
+
// 35% sin depender de la suerte (con 2 o 3 autos por cuadra, el azar solo
|
|
339
|
+
// se desviaría mucho).
|
|
340
|
+
let total = 0, motos = 0;
|
|
341
|
+
for (const e of entities) {
|
|
342
|
+
if (e.type !== 'vehiculo') continue;
|
|
343
|
+
total++;
|
|
344
|
+
if (AUTOS[e.model.slice('auto_'.length)].forma === 'moto') motos++;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
for (let intentos = 0; colocados.length < cantidad && intentos < 40; intentos++) {
|
|
348
|
+
const calleEste = rng() < 0.5;
|
|
349
|
+
const carril = CARRILES[rng() < 0.5 ? 0 : 1];
|
|
350
|
+
const t = MARGEN_CUADRA + rng() * (blockZoneSize - 2 * MARGEN_CUADRA);
|
|
351
|
+
|
|
352
|
+
// calleEste: la calle corre a lo largo de Z; si no, a lo largo de X
|
|
353
|
+
const x = calleEste ? blockStartX + blockZoneSize + carril : blockStartX + t;
|
|
354
|
+
const z = calleEste ? blockStartZ + t : blockStartZ + blockZoneSize + carril;
|
|
355
|
+
|
|
356
|
+
const lista = motos < Math.round(PROPORCION_MOTOS * (total + 1)) ? listas.MOTOS : listas.CARROS;
|
|
357
|
+
const modelo = lista[Math.floor(rng() * lista.length)];
|
|
358
|
+
const medio = AUTOS[modelo].largo / 2 + 1;
|
|
359
|
+
// el auto entero tiene que caer dentro del mapa
|
|
360
|
+
if (x + medio >= width || z + medio >= depth || x - medio < 0 || z - medio < 0) continue;
|
|
361
|
+
if (colocados.some(c => (c.x - x) ** 2 + (c.z - z) ** 2 < SEPARACION_AUTOS ** 2)) continue;
|
|
362
|
+
|
|
363
|
+
const y = heightMap[Math.floor(x)][Math.floor(z)];
|
|
364
|
+
// frente hacia un sentido u otro, con un pequeño desvío de estacionado
|
|
365
|
+
const sentido = rng() < 0.5 ? 1 : -1;
|
|
366
|
+
const base = calleEste ? -Math.PI / 2 : 0;
|
|
367
|
+
const rotY = base + (sentido > 0 ? 0 : Math.PI) + (rng() - 0.5) * 0.1;
|
|
368
|
+
|
|
369
|
+
const ent = { type: 'vehiculo', model: idEntidadAuto(modelo), x, y, z, rotY };
|
|
370
|
+
colocados.push(ent);
|
|
371
|
+
entities.push(ent);
|
|
372
|
+
total++;
|
|
373
|
+
if (lista === listas.MOTOS) motos++;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// --- postes de alumbrado -------------------------------------------------------
|
|
378
|
+
//
|
|
379
|
+
// Misma convención que `addVehiculos`/`agregarZonasCalle`: cada cuadra es
|
|
380
|
+
// dueña de la calle de su lado este y de su lado sur (las del oeste y el
|
|
381
|
+
// norte las pone la cuadra vecina), así ninguna calle recibe postes dos
|
|
382
|
+
// veces. Pero cada calle completa (ambas veredas) la planta esta misma
|
|
383
|
+
// función: el lado "propio" (pegado al cordón de esta cuadra) y el lado
|
|
384
|
+
// "opuesto" (pegado al cordón de la cuadra vecina, al otro lado de la
|
|
385
|
+
// calle), con las filas intercaladas medio paso entre sí (zigzag), como el
|
|
386
|
+
// alumbrado real. El farol siempre mira hacia la calle, así que cada lado
|
|
387
|
+
// usa la rotación contraria.
|
|
388
|
+
// Tipos de estructura que no son una habitación habitable: el pasillo no
|
|
389
|
+
// tiene nada que iluminar en especial (ya recibe luz de las habitaciones
|
|
390
|
+
// contiguas) y la caja de escalera queda atravesada por el hueco de la
|
|
391
|
+
// escalera, donde una luz fija en el centro quedaría flotando en el aire.
|
|
392
|
+
export const TIPOS_SIN_LUZ_INTERIOR = new Set(['hallway', 'escalera']);
|
|
393
|
+
|
|
394
|
+
// Luz fija por habitación: una por cada estructura que `processInterior`
|
|
395
|
+
// (mapType3Center.js / genera_casa/*) acaba de agregar a `structures` en
|
|
396
|
+
// esta cuadra (de ahí `desde`, el largo del array antes de llamarla). Mismo
|
|
397
|
+
// patrón que `agregarPostes`: el servidor ya conoce la geometría exacta de
|
|
398
|
+
// cada sala (ver `createRoom` en genera_casa/generadorCasa.js), así que el
|
|
399
|
+
// centro sale directo de esos datos sin tocar el heightMap ni el hilo
|
|
400
|
+
// principal del cliente (ver cliente/luces_interiores.js para el pool fijo
|
|
401
|
+
// de PointLight que la consume, encendida/apagada con el ciclo día/noche).
|
|
402
|
+
function agregarLucesInteriores(structures, desde, entities) {
|
|
403
|
+
for (let i = desde; i < structures.length; i++) {
|
|
404
|
+
const s = structures[i];
|
|
405
|
+
// luz de la casilla de la escalera en la azotea (ver planRoofExtras):
|
|
406
|
+
// `siempre` = de noche está prendida sí o sí (las de habitación se
|
|
407
|
+
// sortean, ver cliente/chunks/world_voxel.js)
|
|
408
|
+
if (s.casillaAzotea) {
|
|
409
|
+
const l = s.casillaAzotea.luz;
|
|
410
|
+
entities.push({ type: 'entidad_objeto', model: ID_LUZ_INTERIOR, x: l.x, y: l.y, z: l.z, siempre: true });
|
|
411
|
+
}
|
|
412
|
+
if (TIPOS_SIN_LUZ_INTERIOR.has(s.type)) continue;
|
|
413
|
+
entities.push({
|
|
414
|
+
type: 'entidad_objeto',
|
|
415
|
+
model: ID_LUZ_INTERIOR,
|
|
416
|
+
x: s.x + s.width / 2,
|
|
417
|
+
y: s.y + s.height - 1.5,
|
|
418
|
+
z: s.z + s.depth / 2
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function agregarPostes(blockStartX, blockStartZ, width, depth, heightMap, entities) {
|
|
424
|
+
const desde = POSTE_MARGEN_ESQUINA;
|
|
425
|
+
const hasta = blockZoneSize - POSTE_MARGEN_ESQUINA;
|
|
426
|
+
if (hasta <= desde) return;
|
|
427
|
+
const mitadPaso = POSTE_ESPACIADO / 2;
|
|
428
|
+
|
|
429
|
+
// calle del sur: vereda propia (borde sur de esta cuadra, farol hacia
|
|
430
|
+
// +Z) y vereda opuesta (borde norte de la cuadra vecina del sur, al otro
|
|
431
|
+
// lado de la calle, farol hacia -Z), intercaladas en X.
|
|
432
|
+
const zSur = blockStartZ + blockZoneSize - 1;
|
|
433
|
+
const zSurOpuesto = zSur + streetWidth + 1;
|
|
434
|
+
for (let ox = desde; ox <= hasta; ox += POSTE_ESPACIADO) {
|
|
435
|
+
const x = blockStartX + ox;
|
|
436
|
+
if (x >= 0 && x < width && zSur >= 0 && zSur < depth) {
|
|
437
|
+
const y = Math.max(0, (heightMap[x] && heightMap[x][zSur]) || 0);
|
|
438
|
+
entities.push({ type: 'entidad_objeto', model: ID_POSTE, x: x + 0.5, y, z: zSur + 0.5, rotY: 0 });
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
for (let ox = desde + mitadPaso; ox <= hasta; ox += POSTE_ESPACIADO) {
|
|
442
|
+
const x = blockStartX + ox;
|
|
443
|
+
if (x >= 0 && x < width && zSurOpuesto >= 0 && zSurOpuesto < depth) {
|
|
444
|
+
const y = Math.max(0, (heightMap[x] && heightMap[x][zSurOpuesto]) || 0);
|
|
445
|
+
entities.push({ type: 'entidad_objeto', model: ID_POSTE, x: x + 0.5, y, z: zSurOpuesto + 0.5, rotY: Math.PI });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// calle del este: vereda propia (borde este de esta cuadra, farol hacia
|
|
450
|
+
// +X) y vereda opuesta (borde oeste de la cuadra vecina del este, farol
|
|
451
|
+
// hacia -X), intercaladas en Z.
|
|
452
|
+
const xEste = blockStartX + blockZoneSize - 1;
|
|
453
|
+
const xEsteOpuesto = xEste + streetWidth + 1;
|
|
454
|
+
for (let oz = desde; oz <= hasta; oz += POSTE_ESPACIADO) {
|
|
455
|
+
const z = blockStartZ + oz;
|
|
456
|
+
if (xEste >= 0 && xEste < width && z >= 0 && z < depth) {
|
|
457
|
+
const y = Math.max(0, (heightMap[xEste] && heightMap[xEste][z]) || 0);
|
|
458
|
+
entities.push({ type: 'entidad_objeto', model: ID_POSTE, x: xEste + 0.5, y, z: z + 0.5, rotY: Math.PI / 2 });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
for (let oz = desde + mitadPaso; oz <= hasta; oz += POSTE_ESPACIADO) {
|
|
462
|
+
const z = blockStartZ + oz;
|
|
463
|
+
if (xEsteOpuesto >= 0 && xEsteOpuesto < width && z >= 0 && z < depth) {
|
|
464
|
+
const y = Math.max(0, (heightMap[xEsteOpuesto] && heightMap[xEsteOpuesto][z]) || 0);
|
|
465
|
+
entities.push({ type: 'entidad_objeto', model: ID_POSTE, x: xEsteOpuesto + 0.5, y, z: z + 0.5, rotY: -Math.PI / 2 });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export {
|
|
471
|
+
blockZoneSize,
|
|
472
|
+
veredaWidth,
|
|
473
|
+
streetWidth,
|
|
474
|
+
patternSize,
|
|
475
|
+
processBlock
|
|
476
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { BLOCK_TYPES } from './mapConfig.js';
|
|
2
|
+
import { blockZoneSize, veredaWidth, streetWidth, patternSize } from './mapType3Block.js';
|
|
3
|
+
import { generateParcel } from './mapType3Parcel.js';
|
|
4
|
+
import { determineFront } from './genera_casa/generadorCasa.js';
|
|
5
|
+
|
|
6
|
+
// Cálculo y posicionamiento de la sala de inicio en el centro de una cuadra.
|
|
7
|
+
// Dado el tamaño del mapa y las constantes geométricas, encuentra la
|
|
8
|
+
// coordenada "centro" que pertenezca a un interior de cuadra (no en calles o
|
|
9
|
+
// veredas), coloca una estructura de tipo `spawn` y devuelve tanto la
|
|
10
|
+
// información de la sala como la posición de inicio del jugador.
|
|
11
|
+
// El arreglo `structures` se modifica agregando el spawn.
|
|
12
|
+
|
|
13
|
+
function computeCenter(width, depth, baseY, roomWidth, roomHeight, roomDepth, structures) {
|
|
14
|
+
let centerX = Math.floor(width / 2);
|
|
15
|
+
let centerZ = Math.floor(depth / 2);
|
|
16
|
+
|
|
17
|
+
function nearestBlockCoord(coord, limit) {
|
|
18
|
+
for (let offset = 0; offset <= limit; offset++) {
|
|
19
|
+
for (const sign of [0, 1, -1]) {
|
|
20
|
+
const c = sign === 0 ? coord : coord + sign * offset;
|
|
21
|
+
if (c >= 0 && c < limit) {
|
|
22
|
+
const pos = c % patternSize;
|
|
23
|
+
if (pos >= veredaWidth && pos < (blockZoneSize - veredaWidth)) return c;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return Math.min(Math.max(coord, 0), limit - 1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
centerX = nearestBlockCoord(centerX, width);
|
|
31
|
+
centerZ = nearestBlockCoord(centerZ, depth);
|
|
32
|
+
|
|
33
|
+
const blockStartX = Math.floor(centerX / patternSize) * patternSize;
|
|
34
|
+
const blockStartZ = Math.floor(centerZ / patternSize) * patternSize;
|
|
35
|
+
|
|
36
|
+
const interiorSize = blockZoneSize - 2 * veredaWidth;
|
|
37
|
+
let roomX = blockStartX + veredaWidth + Math.floor((interiorSize - roomWidth) / 2);
|
|
38
|
+
let roomZ = blockStartZ + veredaWidth + Math.floor((interiorSize - roomDepth) / 2);
|
|
39
|
+
// spawn/room vertical position should match the terrain height as well.
|
|
40
|
+
// baseY represents the first air layer; the top solid block is at
|
|
41
|
+
// baseY-1, but callers expect the room coordinate to align with the
|
|
42
|
+
// structure generation code which uses the same convention. dropping the
|
|
43
|
+
// previous +1 keeps the player from spawning one block above ground.
|
|
44
|
+
const roomY = baseY;
|
|
45
|
+
// clamp dentro del mapa si los cálculos anteriores exceden
|
|
46
|
+
roomX = Math.max(0, Math.min(roomX, width - roomWidth));
|
|
47
|
+
roomZ = Math.max(0, Math.min(roomZ, depth - roomDepth));
|
|
48
|
+
|
|
49
|
+
// Note: we no longer add a `spawn` structure or carve a dedicated room
|
|
50
|
+
// around the starting point. The player will simply spawn at the computed
|
|
51
|
+
// coordinates, which remain at the center of a valid block interior.
|
|
52
|
+
const startPosition = {
|
|
53
|
+
x: roomX + Math.floor(roomWidth / 2),
|
|
54
|
+
y: roomY + 3,
|
|
55
|
+
z: roomZ + Math.floor(roomDepth / 2)
|
|
56
|
+
};
|
|
57
|
+
// return null for `room` so callers know not to create any special geometry
|
|
58
|
+
return { startPosition, room: null };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Realiza la subdivisión interna de una cuadra (parcelas + casas). Este código
|
|
62
|
+
// originalmente vivía dentro de mapType3Block.processBlock pero conceptualmente
|
|
63
|
+
// forma parte del "centro"; por eso fue movido aquí. Modifica los mapas y
|
|
64
|
+
// agrega estructuras de casa en `structures`.
|
|
65
|
+
function processInterior(blockStartX, blockStartZ, width, depth, baseY, heightMap, surfaceTypeMap, structures, roomWidth, roomHeight, zonas) {
|
|
66
|
+
const interiorStartX = blockStartX + veredaWidth;
|
|
67
|
+
// roomWidth is currently unused but passed for future flexibility.
|
|
68
|
+
const interiorStartZ = blockStartZ + veredaWidth;
|
|
69
|
+
const interiorDim = blockZoneSize - 2 * veredaWidth; // 176 - 32 = 144
|
|
70
|
+
const plotWidth = interiorDim / 4; // 144 / 4 = 36
|
|
71
|
+
const plotDepth = interiorDim / 2; // 144 / 2 = 72
|
|
72
|
+
const plotsX = Math.floor(interiorDim / plotWidth);
|
|
73
|
+
const plotsZ = Math.floor(interiorDim / plotDepth);
|
|
74
|
+
|
|
75
|
+
for (let px = 0; px < plotsX; px++) {
|
|
76
|
+
for (let pz = 0; pz < plotsZ; pz++) {
|
|
77
|
+
const plotX0 = interiorStartX + px * plotWidth;
|
|
78
|
+
const plotZ0 = interiorStartZ + pz * plotDepth;
|
|
79
|
+
|
|
80
|
+
// líneas horizontales (bordes superior e inferior)
|
|
81
|
+
for (let i = 0; i < plotWidth; i++) {
|
|
82
|
+
const x = plotX0 + i;
|
|
83
|
+
const zTop = plotZ0;
|
|
84
|
+
const zBottom = plotZ0 + plotDepth - 1;
|
|
85
|
+
if (x >= 0 && x < width) {
|
|
86
|
+
if (zTop >= 0 && zTop < depth) {
|
|
87
|
+
if (surfaceTypeMap[x][zTop] !== BLOCK_TYPES.ASPHALT) surfaceTypeMap[x][zTop] = BLOCK_TYPES.BRICK;
|
|
88
|
+
}
|
|
89
|
+
if (zBottom >= 0 && zBottom < depth) {
|
|
90
|
+
if (surfaceTypeMap[x][zBottom] !== BLOCK_TYPES.ASPHALT) surfaceTypeMap[x][zBottom] = BLOCK_TYPES.BRICK;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// líneas verticales (bordes izquierdo y derecho)
|
|
96
|
+
for (let j = 0; j < plotDepth; j++) {
|
|
97
|
+
const z = plotZ0 + j;
|
|
98
|
+
const xLeft = plotX0;
|
|
99
|
+
const xRight = plotX0 + plotWidth - 1;
|
|
100
|
+
if (z >= 0 && z < depth) {
|
|
101
|
+
if (xLeft >= 0 && xLeft < width) {
|
|
102
|
+
if (surfaceTypeMap[xLeft][z] !== BLOCK_TYPES.ASPHALT) surfaceTypeMap[xLeft][z] = BLOCK_TYPES.BRICK;
|
|
103
|
+
}
|
|
104
|
+
if (xRight >= 0 && xRight < width) {
|
|
105
|
+
if (surfaceTypeMap[xRight][z] !== BLOCK_TYPES.ASPHALT) surfaceTypeMap[xRight][z] = BLOCK_TYPES.BRICK;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// --- determinar orientación del frente ---
|
|
111
|
+
// ahora delegamos la lógica a la función reutilizable. el valor
|
|
112
|
+
// devuelto es una letra N/S/E/O o null si la parcela está rodeada.
|
|
113
|
+
const orientation = determineFront(px, pz, plotsX, plotsZ);
|
|
114
|
+
|
|
115
|
+
// delegar generación de parcela al módulo especializado
|
|
116
|
+
generateParcel(plotX0, plotZ0, plotWidth, plotDepth, width, depth, baseY,
|
|
117
|
+
surfaceTypeMap, structures,
|
|
118
|
+
orientation, roomHeight);
|
|
119
|
+
|
|
120
|
+
// zona de control (modo equipos): la parcela completa, tal como
|
|
121
|
+
// quedó delimitada arriba. Se guarda acá y no se descarta porque
|
|
122
|
+
// es la única vez que estos límites están a mano (ver
|
|
123
|
+
// plan_zonas_control.md).
|
|
124
|
+
if (zonas) {
|
|
125
|
+
zonas.push({
|
|
126
|
+
id: `${blockStartX}_${blockStartZ}:parcela:${px}_${pz}`,
|
|
127
|
+
tipo: 'parcela',
|
|
128
|
+
x0: plotX0, z0: plotZ0,
|
|
129
|
+
x1: plotX0 + plotWidth, z1: plotZ0 + plotDepth
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
continue; // resto del código original queda aquí para referencia pero no se ejecuta
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export { computeCenter, processInterior };
|