1
0

mapGeneration.py 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. import numpy as np
  2. import yaml
  3. import base64
  4. import struct
  5. import random
  6. import sys
  7. from pyfastnoiselite.pyfastnoiselite import (
  8. FastNoiseLite,
  9. NoiseType,
  10. FractalType,
  11. CellularReturnType,
  12. CellularDistanceFunction,
  13. DomainWarpType,
  14. )
  15. import time
  16. import os
  17. if len(sys.argv) == 1:
  18. mapWidth = 300
  19. mapHeight = 300
  20. print(f"No custom mapsize specified, using defaults: {mapWidth}w x {mapHeight}h")
  21. else:
  22. mapWidth = int(sys.argv[1])
  23. mapHeight = int(sys.argv[2])
  24. print(f"Using specified mapsize: {mapWidth}w x {mapHeight}h")
  25. # -----------------------------------------------------------------------------
  26. # Tilemap
  27. # -----------------------------------------------------------------------------
  28. TILEMAP = {
  29. 0: "Space",
  30. 1: "FloorDirt",
  31. 2: "FloorPlanetGrass",
  32. 3: "FloorGrassDark",
  33. 4: "FloorSand",
  34. 5: "FloorDirtRock",
  35. }
  36. TILEMAP_REVERSE = {v: k for k, v in TILEMAP.items()}
  37. # -----------------------------------------------------------------------------
  38. # Helper Functions
  39. # -----------------------------------------------------------------------------
  40. def round_to_chunk(number, chunk):
  41. """Rounds a number to the inferior multiplier of a chunk."""
  42. return number - (number % chunk)
  43. def add_border(tile_map, border_value):
  44. """Adds a border to tile_map with the specified value."""
  45. bordered = np.pad(
  46. tile_map, pad_width=1, mode="constant", constant_values=border_value
  47. )
  48. return bordered.astype(np.int32)
  49. def encode_tiles(tile_map):
  50. """Codifies the tiles in base64 for the YAML."""
  51. tile_bytes = bytearray()
  52. for y in range(tile_map.shape[0]): # u
  53. for x in range(tile_map.shape[1]):
  54. tile_id = tile_map[y, x]
  55. flags = 0
  56. variant = 0
  57. tile_bytes.extend(struct.pack("<I", tile_id)) # 4 bytes tile_id
  58. tile_bytes.append(flags) # 1 byte flag
  59. tile_bytes.append(variant) # 1 byte variant
  60. return base64.b64encode(tile_bytes).decode("utf-8")
  61. # -----------------------------------------------------------------------------
  62. # Generating a TileMap with multiple layers
  63. # -----------------------------------------------------------------------------
  64. def generate_tile_map(width, height, biome_tile_layers, seed_base=None):
  65. """Generates the tile_map based on the layers defined in biome_tile_layers."""
  66. tile_map = np.full((height, width), TILEMAP_REVERSE["FloorDirt"], dtype=np.int32)
  67. # Orders the layers by priority (largest to smallest)
  68. sorted_layers = sorted(
  69. biome_tile_layers, key=lambda layer: layer.get("priority", 1)
  70. )
  71. for layer in sorted_layers:
  72. noise = FastNoiseLite()
  73. noise.noise_type = layer["noise_type"]
  74. noise.fractal_octaves = layer["octaves"]
  75. noise.frequency = layer["frequency"]
  76. noise.fractal_type = layer["fractal_type"]
  77. if "cellular_distance_function" in layer:
  78. noise.cellular_distance_function = layer["cellular_distance_function"]
  79. if "cellular_return_type" in layer:
  80. noise.cellular_return_type = layer["cellular_return_type"]
  81. if "cellular_jitter" in layer:
  82. noise.cellular_jitter = layer["cellular_jitter"]
  83. if "fractal_lacunarity" in layer:
  84. noise.fractal_lacunarity = layer["fractal_lacunarity"]
  85. if seed_base is not None:
  86. seed_key = layer.get("seed_key", layer["tile_type"])
  87. noise.seed = (seed_base + hash(seed_key)) % (2**31)
  88. # Modulation config, if present
  89. mod_noise = None
  90. if "modulation" in layer:
  91. mod_config = layer["modulation"]
  92. mod_noise = FastNoiseLite()
  93. mod_noise.noise_type = mod_config.get(
  94. "noise_type", NoiseType.NoiseType_OpenSimplex2
  95. )
  96. if "cellular_distance_function" in mod_config:
  97. mod_noise.cellular_distance_function = mod_config[
  98. "cellular_distance_function"
  99. ]
  100. if "cellular_return_type" in mod_config:
  101. mod_noise.cellular_return_type = mod_config["cellular_return_type"]
  102. if "cellular_jitter" in mod_config:
  103. mod_noise.cellular_jitter = mod_config["cellular_jitter"]
  104. if "fractal_lacunarity" in mod_config:
  105. mod_noise.fractal_lacunarity = mod_config["fractal_lacunarity"]
  106. mod_noise.frequency = mod_config.get("frequency", 0.010)
  107. mod_noise.seed = (seed_base + hash(seed_key + "_mod")) % (2**31)
  108. threshold_min = mod_config.get("threshold_min", 0.4)
  109. threshold_max = mod_config.get("threshold_max", 0.6)
  110. count = 0
  111. dont_overwrite = [TILEMAP_REVERSE[t] for t in layer.get("dontOverwrite", [])]
  112. for y in range(height):
  113. for x in range(width):
  114. noise_value = noise.get_noise(x, y)
  115. noise_value = (noise_value + 1) / 2 # Normalise into [0, 1]
  116. place_tile = False
  117. if mod_noise:
  118. mod_value = mod_noise.get_noise(x, y)
  119. mod_value = (mod_value + 1) / 2
  120. if noise_value > layer["threshold"]:
  121. if mod_value > threshold_max:
  122. place_tile = True
  123. elif mod_value > threshold_min:
  124. probability = (mod_value - threshold_min) / (
  125. threshold_max - threshold_min
  126. )
  127. place_tile = random.random() < probability
  128. else:
  129. if noise_value > layer["threshold"]:
  130. place_tile = True
  131. if place_tile:
  132. current_tile = tile_map[y, x]
  133. if current_tile not in dont_overwrite:
  134. if (
  135. layer.get("overwrite", True)
  136. or current_tile == TILEMAP_REVERSE["Space"]
  137. ):
  138. tile_map[y, x] = TILEMAP_REVERSE[layer["tile_type"]]
  139. count += 1
  140. print(f"Layer {layer['tile_type']}: {count} tiles placed")
  141. return tile_map
  142. # -----------------------------------------------------------------------------
  143. # Entity generation
  144. # -----------------------------------------------------------------------------
  145. global_uid = 3
  146. def next_uid():
  147. """Generates an unique UID for each entity."""
  148. global global_uid
  149. uid = global_uid
  150. global_uid += 1
  151. return uid
  152. def generate_dynamic_entities(tile_map, biome_entity_layers, seed_base=None):
  153. """Generates dynamic entities based on the entity layers, respecting priorities."""
  154. groups = {}
  155. entity_count = {} # Count entities by proto
  156. h, w = tile_map.shape
  157. occupied_positions = set() # Set to trace occupied positions
  158. # Order layers by priority. Highest first
  159. sorted_layers = sorted(
  160. biome_entity_layers, key=lambda layer: layer.get("priority", 0), reverse=True
  161. )
  162. for layer in sorted_layers:
  163. # Get entity_protos list
  164. entity_protos = layer["entity_protos"]
  165. if isinstance(entity_protos, str): # If its a string, turns it into a list
  166. entity_protos = [entity_protos]
  167. # Set layer noise
  168. noise = FastNoiseLite()
  169. noise.noise_type = layer["noise_type"]
  170. noise.fractal_octaves = layer["octaves"]
  171. noise.frequency = layer["frequency"]
  172. noise.fractal_type = layer["fractal_type"]
  173. if "cellular_distance_function" in layer:
  174. noise.cellular_distance_function = layer["cellular_distance_function"]
  175. if "cellular_return_type" in layer:
  176. noise.cellular_return_type = layer["cellular_return_type"]
  177. if "cellular_jitter" in layer:
  178. noise.cellular_jitter = layer["cellular_jitter"]
  179. if "fractal_lacunarity" in layer:
  180. noise.fractal_lacunarity = layer["fractal_lacunarity"]
  181. if seed_base is not None:
  182. # Uses "seed_key" if available, if not uses a hash based on entity_protos
  183. seed_key = layer.get("seed_key", tuple(entity_protos))
  184. noise.seed = (seed_base + hash(seed_key)) % (2**31)
  185. for y in range(h):
  186. for x in range(w):
  187. if x == 0 or x == w - 1 or y == 0 or y == h - 1:
  188. continue
  189. if (x, y) in occupied_positions:
  190. continue
  191. tile_val = tile_map[y, x]
  192. noise_value = noise.get_noise(x, y)
  193. noise_value = (noise_value + 1) / 2 # Normalise into [0, 1]
  194. if noise_value > layer["threshold"] and layer["tile_condition"](
  195. tile_val
  196. ):
  197. # Chooses randomly a proto
  198. proto = random.choice(entity_protos)
  199. if proto not in groups:
  200. groups[proto] = []
  201. groups[proto].append(
  202. {
  203. "uid": next_uid(),
  204. "components": [
  205. {"type": "Transform", "parent": 2, "pos": f"{x},{y}"}
  206. ],
  207. }
  208. )
  209. occupied_positions.add((x, y))
  210. # Counts entities by proto
  211. entity_count[proto] = entity_count.get(proto, 0) + 1
  212. # Surrounding undestructible walls
  213. groups["WallRockIndestructible"] = []
  214. for y in range(h):
  215. for x in range(w):
  216. if x == 0 or x == w - 1 or y == 0 or y == h - 1:
  217. groups["WallRockIndestructible"].append(
  218. {
  219. "uid": next_uid(),
  220. "components": [
  221. {"type": "Transform", "parent": 2, "pos": f"{x},{y}"}
  222. ],
  223. }
  224. )
  225. # Count undestructible walls
  226. entity_count["WallRockIndestructible"] = (
  227. entity_count.get("WallRockIndestructible", 0) + 1
  228. )
  229. dynamic_groups = [
  230. {"proto": proto, "entities": ents} for proto, ents in groups.items()
  231. ]
  232. # Print generated protos
  233. for proto, count in entity_count.items():
  234. print(f"Generated {count} amount of {proto}")
  235. return dynamic_groups
  236. def generate_decals(tile_map, biome_decal_layers, seed_base=None, chunk_size=16):
  237. """Generate decals using biome_decal_layers and log the count of each decal type."""
  238. decals_by_id = {}
  239. h, w = tile_map.shape
  240. occupied_tiles = set()
  241. decal_count = {}
  242. for layer in biome_decal_layers:
  243. noise = FastNoiseLite()
  244. noise.noise_type = layer["noise_type"]
  245. noise.fractal_octaves = layer["octaves"]
  246. noise.frequency = layer["frequency"]
  247. noise.fractal_type = layer["fractal_type"]
  248. if seed_base is not None:
  249. seed_key = layer.get(
  250. "seed_key",
  251. (
  252. tuple(layer["decal_id"])
  253. if isinstance(layer["decal_id"], list)
  254. else layer["decal_id"]
  255. ),
  256. )
  257. noise.seed = (seed_base + hash(seed_key)) % (2**31)
  258. decal_ids = (
  259. layer["decal_id"]
  260. if isinstance(layer["decal_id"], list)
  261. else [layer["decal_id"]]
  262. )
  263. for y in range(h):
  264. for x in range(w):
  265. if x == 0 or x == w - 1 or y == 0 or y == h - 1:
  266. continue
  267. if (x, y) in occupied_tiles:
  268. continue
  269. tile_val = tile_map[y, x]
  270. noise_value = noise.get_noise(x, y)
  271. noise_value = (noise_value + 1) / 2
  272. if noise_value > layer["threshold"] and layer["tile_condition"](
  273. tile_val
  274. ):
  275. chosen_decal_id = random.choice(decal_ids)
  276. if chosen_decal_id not in decals_by_id:
  277. decals_by_id[chosen_decal_id] = []
  278. # Small random offset for decals
  279. offset_x = (
  280. noise.get_noise(x + 1000, y + 1000) + 1
  281. ) / 4 - 0.25 # Between -0.25 and 0.25
  282. offset_y = (
  283. noise.get_noise(x + 2000, y + 2000) + 1
  284. ) / 4 - 0.25 # Between -0.25 and 0.25
  285. pos_x = x + offset_x
  286. pos_y = y + offset_y
  287. pos_str = f"{pos_x:.7f},{pos_y:.7f}"
  288. decals_by_id[chosen_decal_id].append(
  289. {"color": layer.get("color", "#FFFFFFFF"), "position": pos_str}
  290. )
  291. occupied_tiles.add((x, y))
  292. decal_count[chosen_decal_id] = (
  293. decal_count.get(chosen_decal_id, 0) + 1
  294. )
  295. return decals_by_id
  296. # Defines uniqueMixes for the atmosphere
  297. unique_mixes = [
  298. {
  299. "volume": 2500,
  300. "immutable": True,
  301. "temperature": 278.15,
  302. "moles": [21.82478, 82.10312, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  303. },
  304. {
  305. "volume": 2500,
  306. "temperature": 278.15,
  307. "moles": [21.824879, 82.10312, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  308. },
  309. ]
  310. def generate_atmosphere_tiles(width, height, chunk_size):
  311. """Generates the atmos tiles based on the map size."""
  312. max_x = (width + chunk_size - 1) // chunk_size - 1
  313. max_y = (height + chunk_size - 1) // chunk_size - 1
  314. tiles = {}
  315. for y in range(-1, max_y + 1):
  316. for x in range(-1, max_x + 1):
  317. if x == -1 or x == max_x or y == -1 or y == max_y:
  318. tiles[f"{x},{y}"] = {0: 65535}
  319. else:
  320. tiles[f"{x},{y}"] = {1: 65535}
  321. return tiles
  322. def generate_main_entities(tile_map, chunk_size=16, decals_by_id=None):
  323. """Generates entities, decals and atmos."""
  324. if decals_by_id is None:
  325. decals_by_id = {}
  326. h, w = tile_map.shape
  327. chunks = {}
  328. for cy in range(0, h, chunk_size):
  329. for cx in range(0, w, chunk_size):
  330. chunk_key = f"{cx//chunk_size},{cy//chunk_size}"
  331. chunk_tiles = tile_map[cy : cy + chunk_size, cx : cx + chunk_size]
  332. if chunk_tiles.shape[0] < chunk_size or chunk_tiles.shape[1] < chunk_size:
  333. full_chunk = np.zeros((chunk_size, chunk_size), dtype=np.int32)
  334. full_chunk[: chunk_tiles.shape[0], : chunk_tiles.shape[1]] = chunk_tiles
  335. chunk_tiles = full_chunk
  336. chunks[chunk_key] = {
  337. "ind": f"{cx//chunk_size},{cy//chunk_size}",
  338. "tiles": encode_tiles(chunk_tiles),
  339. "version": 6,
  340. }
  341. atmosphere_chunk_size = 4
  342. atmosphere_tiles = generate_atmosphere_tiles(w, h, atmosphere_chunk_size)
  343. # Decals generation
  344. decal_nodes = []
  345. global_index = 0
  346. for decal_id, decals in decals_by_id.items():
  347. if decals:
  348. node_decals = {}
  349. for decal in decals:
  350. node_decals[str(global_index)] = decal["position"]
  351. global_index += 1
  352. node = {
  353. "node": {"color": decals[0]["color"], "id": decal_id},
  354. "decals": node_decals,
  355. }
  356. decal_nodes.append(node)
  357. print(f"Total decal nodes generated: {len(decal_nodes)}")
  358. print(f"Total decals: {global_index}")
  359. main = {
  360. "proto": "",
  361. "entities": [
  362. {
  363. "uid": 1,
  364. "components": [
  365. {"type": "MetaData", "name": "Map Entity"},
  366. {"type": "Transform"},
  367. {"type": "LightCycle"},
  368. {"type": "MapLight", "ambientLightColor": "#D8B059FF"},
  369. {"type": "Map", "mapPaused": True},
  370. {"type": "PhysicsMap"},
  371. {"type": "GridTree"},
  372. {"type": "MovedGrids"},
  373. {"type": "Broadphase"},
  374. {"type": "OccluderTree"},
  375. ],
  376. },
  377. {
  378. "uid": 2,
  379. "components": [
  380. {"type": "MetaData", "name": "grid"},
  381. {"type": "Transform", "parent": 1, "pos": "0,0"},
  382. {"type": "MapGrid", "chunks": chunks},
  383. {"type": "Broadphase"},
  384. {
  385. "type": "Physics",
  386. "angularDamping": 0.05,
  387. "bodyStatus": "InAir",
  388. "bodyType": "Dynamic",
  389. "fixedRotation": True,
  390. "linearDamping": 0.05,
  391. },
  392. {"type": "Fixtures", "fixtures": {}},
  393. {"type": "OccluderTree"},
  394. {"type": "SpreaderGrid"},
  395. {"type": "Shuttle"},
  396. {"type": "SunShadow"},
  397. {"type": "SunShadowCycle"},
  398. {"type": "GridPathfinding"},
  399. {
  400. "type": "Gravity",
  401. "gravityShakeSound": {
  402. "!type:SoundPathSpecifier": {
  403. "path": "/Audio/Effects/alert.ogg"
  404. }
  405. },
  406. "inherent": True,
  407. "enabled": True,
  408. },
  409. {"type": "BecomesStation", "id": "Nomads"},
  410. {"type": "Weather"},
  411. {
  412. "type": "WeatherNomads",
  413. "enabledWeathers": [
  414. "Rain",
  415. "Storm",
  416. "SnowfallLight",
  417. "SnowfallMedium",
  418. "SnowfallHeavy",
  419. ],
  420. "minSeasonMinutes": 10,
  421. "maxSeasonMinutes": 30,
  422. },
  423. {
  424. "type": "DecalGrid",
  425. "chunkCollection": {"version": 2, "nodes": decal_nodes},
  426. },
  427. {
  428. "type": "GridAtmosphere",
  429. "version": 2,
  430. "data": {
  431. "tiles": atmosphere_tiles,
  432. "uniqueMixes": unique_mixes,
  433. "chunkSize": atmosphere_chunk_size,
  434. },
  435. },
  436. {"type": "GasTileOverlay"},
  437. {"type": "RadiationGridResistance"},
  438. ],
  439. },
  440. ],
  441. }
  442. return main
  443. def generate_all_entities(tile_map, chunk_size=16, biome_layers=None, seed_base=None):
  444. """Combines tiles, entities and decals."""
  445. entities = []
  446. if biome_layers is None:
  447. biome_layers = []
  448. biome_tile_layers = [
  449. layer for layer in biome_layers if layer["type"] == "BiomeTileLayer"
  450. ]
  451. biome_entity_layers = [
  452. layer for layer in biome_layers if layer["type"] == "BiomeEntityLayer"
  453. ]
  454. biome_decal_layers = [
  455. layer for layer in biome_layers if layer["type"] == "BiomeDecalLayer"
  456. ]
  457. dynamic_groups = generate_dynamic_entities(tile_map, biome_entity_layers, seed_base)
  458. decals_by_chunk = generate_decals(
  459. tile_map, biome_decal_layers, seed_base, chunk_size
  460. )
  461. main_entities = generate_main_entities(tile_map, chunk_size, decals_by_chunk)
  462. entities.append(main_entities)
  463. entities.extend(dynamic_groups)
  464. spawn_points = generate_spawn_points(tile_map)
  465. entities.extend(spawn_points)
  466. return entities
  467. # -----------------------------------------------------------------------------
  468. # Save YAML
  469. # -----------------------------------------------------------------------------
  470. def represent_sound_path_specifier(dumper, data):
  471. """Customised representation for the SoundPathSpecifier in the YAML."""
  472. for key, value in data.items():
  473. if isinstance(key, str) and key.startswith("!type:"):
  474. tag = key
  475. if isinstance(value, dict) and "path" in value:
  476. return dumper.represent_mapping(tag, value)
  477. return dumper.represent_dict(data)
  478. def save_map_to_yaml(
  479. tile_map,
  480. biome_layers,
  481. output_dir,
  482. filename="output.yml",
  483. chunk_size=16,
  484. seed_base=None,
  485. ):
  486. """Saves the generated map in a YAML file in the specified folder."""
  487. all_entities = generate_all_entities(tile_map, chunk_size, biome_layers, seed_base)
  488. count = sum(len(group.get("entities", [])) for group in all_entities)
  489. map_data = {
  490. "meta": {
  491. "format": 7,
  492. "category": "Map",
  493. "engineVersion": "249.0.0",
  494. "forkId": "",
  495. "forkVersion": "",
  496. "time": "03/23/2025 18:21:23",
  497. "entityCount": count,
  498. },
  499. "maps": [1],
  500. "grids": [2],
  501. "orphans": [],
  502. "nullspace": [],
  503. "tilemap": TILEMAP,
  504. "entities": all_entities,
  505. }
  506. yaml.add_representer(dict, represent_sound_path_specifier)
  507. output_path = os.path.join(output_dir, filename)
  508. with open(output_path, "w") as outfile:
  509. yaml.dump(map_data, outfile, default_flow_style=False, sort_keys=False)
  510. import numpy as np
  511. from collections import defaultdict
  512. def apply_erosion(tile_map, tile_type, min_neighbors=3):
  513. h, w = tile_map.shape
  514. new_map = tile_map.copy()
  515. for y in range(1, h - 1):
  516. for x in range(1, w - 1):
  517. if tile_map[y, x] == tile_type:
  518. neighbors = 0
  519. neighbor_types = []
  520. for dy in [-1, 0, 1]:
  521. for dx in [-1, 0, 1]:
  522. if dy == 0 and dx == 0:
  523. continue
  524. neighbor_y = y + dy
  525. neighbor_x = x + dx
  526. if 0 <= neighbor_y < h and 0 <= neighbor_x < w:
  527. nt = tile_map[neighbor_y, neighbor_x]
  528. neighbor_types.append(nt)
  529. if nt == tile_type:
  530. neighbors += 1
  531. if neighbors < min_neighbors:
  532. counts = defaultdict(int)
  533. for nt in neighbor_types:
  534. counts[nt] += 1
  535. if counts:
  536. max_count = max(counts.values())
  537. candidates = [k for k, v in counts.items() if v == max_count]
  538. majority_type = candidates[0] # Defines majority_type here
  539. new_map[y, x] = majority_type
  540. return new_map
  541. def count_isolated_tiles(tile_map, tile_type, min_neighbors=3):
  542. h, w = tile_map.shape
  543. isolated = 0
  544. for y in range(1, h - 1):
  545. for x in range(1, w - 1):
  546. if tile_map[y, x] == tile_type:
  547. neighbors = sum(
  548. 1
  549. for dy in [-1, 0, 1]
  550. for dx in [-1, 0, 1]
  551. if not (dy == 0 and dx == 0)
  552. and 0 <= y + dy < h
  553. and 0 <= x + dx < w
  554. and tile_map[y + dy, x + dx] == tile_type
  555. )
  556. if neighbors < min_neighbors:
  557. isolated += 1
  558. return isolated
  559. def apply_iterative_erosion(tile_map, tile_type, min_neighbors=3, max_iterations=10):
  560. """Applies erosion interactively untill there are no more tiles with the declared min neighbors"""
  561. iteration = 0
  562. while iteration < max_iterations:
  563. isolated_before = count_isolated_tiles(tile_map, tile_type, min_neighbors)
  564. tile_map = apply_erosion(tile_map, tile_type, min_neighbors)
  565. isolated_after = count_isolated_tiles(tile_map, tile_type, min_neighbors)
  566. if isolated_after == isolated_before or isolated_after == 0:
  567. break
  568. iteration += 1
  569. return tile_map
  570. # -----------------------------------------------------------------------------
  571. # Spawn Point Generation
  572. # -----------------------------------------------------------------------------
  573. def generate_spawn_points(tile_map, num_points_per_corner=1):
  574. """Generates 4 SpawnPointNomads and 4 SpawnPointLatejoin, one on each corner, on FloorPlanetGrass."""
  575. h, w = tile_map.shape
  576. spawn_positions = set()
  577. nomads_entities = []
  578. latejoin_entities = []
  579. corners = ["top_left", "top_right", "bottom_left", "bottom_right"]
  580. astro_grass_id = TILEMAP_REVERSE["FloorPlanetGrass"]
  581. directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
  582. for corner in corners:
  583. found = False
  584. initial_size = 15 # Initial size to search for positions
  585. while not found and initial_size <= min(w, h) // 2:
  586. x_min, x_max, y_min, y_max = get_corner_region(corner, w, h, initial_size)
  587. candidates = []
  588. # Searchs for AstroTileGrass in the initial size in the corners
  589. for y in range(y_min, y_max + 1):
  590. for x in range(x_min, x_max + 1):
  591. if (
  592. tile_map[y, x] == astro_grass_id
  593. and (x, y) not in spawn_positions
  594. ):
  595. # Verifies adjacent valid tiles
  596. adjacent = []
  597. for dx, dy in directions:
  598. nx, ny = x + dx, y + dy
  599. if (
  600. 0 <= nx < w
  601. and 0 <= ny < h
  602. and tile_map[ny, nx] == astro_grass_id
  603. and (nx, ny) not in spawn_positions
  604. ):
  605. adjacent.append((nx, ny))
  606. if adjacent:
  607. candidates.append((x, y, adjacent))
  608. if candidates:
  609. x, y, adjacent = random.choice(candidates)
  610. adj_x, adj_y = random.choice(adjacent)
  611. if random.random() < 0.5:
  612. nomads_pos = (x, y)
  613. latejoin_pos = (adj_x, adj_y)
  614. else:
  615. nomads_pos = (adj_x, adj_y)
  616. latejoin_pos = (x, y)
  617. nomads_entities.append(
  618. {
  619. "uid": next_uid(),
  620. "components": [
  621. {
  622. "type": "Transform",
  623. "parent": 2,
  624. "pos": f"{nomads_pos[0]},{nomads_pos[1]}",
  625. }
  626. ],
  627. }
  628. )
  629. latejoin_entities.append(
  630. {
  631. "uid": next_uid(),
  632. "components": [
  633. {
  634. "type": "Transform",
  635. "parent": 2,
  636. "pos": f"{latejoin_pos[0]},{latejoin_pos[1]}",
  637. }
  638. ],
  639. }
  640. )
  641. spawn_positions.add(nomads_pos)
  642. spawn_positions.add(latejoin_pos)
  643. found = True
  644. else:
  645. initial_size += 1
  646. if not found:
  647. print(
  648. f"Possible to find an available position at the corner for spawn points {corner}"
  649. )
  650. print("SpawnPointNomads positions:")
  651. for ent in nomads_entities:
  652. pos = ent["components"][0]["pos"]
  653. print(pos)
  654. print("SpawnPointLatejoin positions:")
  655. for ent in latejoin_entities:
  656. pos = ent["components"][0]["pos"]
  657. print(pos)
  658. # Retorna as entidades no formato correto para o YAML
  659. return [
  660. {"proto": "SpawnPointNomads", "entities": nomads_entities},
  661. {"proto": "SpawnPointLatejoin", "entities": latejoin_entities},
  662. ]
  663. def get_corner_region(corner, w, h, initial_size):
  664. """Defines a region to search in the map's corners."""
  665. if corner == "top_left":
  666. x_min = 1
  667. x_max = min(initial_size, w - 2)
  668. y_min = 1
  669. y_max = min(initial_size, h - 2)
  670. elif corner == "top_right":
  671. x_min = max(w - 1 - initial_size, 1)
  672. x_max = w - 2
  673. y_min = 1
  674. y_max = min(initial_size, h - 2)
  675. elif corner == "bottom_left":
  676. x_min = 1
  677. x_max = min(initial_size, w - 2)
  678. y_min = max(h - 1 - initial_size, 1)
  679. y_max = h - 2
  680. elif corner == "bottom_right":
  681. x_min = max(w - 1 - initial_size, 1)
  682. x_max = w - 2
  683. y_min = max(h - 1 - initial_size, 1)
  684. y_max = h - 2
  685. else:
  686. raise ValueError("Invalid corner")
  687. return x_min, x_max, y_min, y_max
  688. # -----------------------------------------------------------------------------
  689. # Configuração do Mapa (MAP_CONFIG)
  690. # -----------------------------------------------------------------------------
  691. MAP_CONFIG = [
  692. { # Rock dirt formations
  693. "type": "BiomeTileLayer",
  694. "tile_type": "FloorDirtRock",
  695. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  696. "octaves": 2,
  697. "frequency": 0.01,
  698. "fractal_type": FractalType.FractalType_None,
  699. "threshold": -1.0,
  700. "overwrite": True,
  701. },
  702. { # Sprinkled dirt around the map
  703. "type": "BiomeTileLayer",
  704. "tile_type": "FloorDirt",
  705. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  706. "octaves": 10,
  707. "frequency": 0.3,
  708. "fractal_type": FractalType.FractalType_FBm,
  709. "threshold": 0.825,
  710. "overwrite": True,
  711. "dontOverwrite": ["FloorSand", "FloorDirtRock"],
  712. "priority": 10,
  713. },
  714. {
  715. "type": "BiomeTileLayer",
  716. "tile_type": "FloorPlanetGrass",
  717. "noise_type": NoiseType.NoiseType_Perlin,
  718. "octaves": 3,
  719. "frequency": 0.02,
  720. "fractal_type": FractalType.FractalType_None,
  721. "threshold": 0.4,
  722. "overwrite": True,
  723. },
  724. { # Boulders for flints
  725. "type": "BiomeEntityLayer",
  726. "entity_protos": "FloraRockSolid",
  727. "noise_type": NoiseType.NoiseType_OpenSimplex2S,
  728. "octaves": 6,
  729. "frequency": 0.3,
  730. "fractal_type": FractalType.FractalType_FBm,
  731. "threshold": 0.815,
  732. "tile_condition": lambda tile: tile
  733. in [
  734. TILEMAP_REVERSE["FloorPlanetGrass"],
  735. TILEMAP_REVERSE["FloorDirt"],
  736. TILEMAP_REVERSE["FloorDirtRock"],
  737. ],
  738. "priority": 1,
  739. },
  740. { # Rocks
  741. "type": "BiomeEntityLayer",
  742. "entity_protos": "WallRock",
  743. "noise_type": NoiseType.NoiseType_Cellular,
  744. "cellular_distance_function": CellularDistanceFunction.CellularDistanceFunction_Hybrid,
  745. "cellular_return_type": CellularReturnType.CellularReturnType_CellValue,
  746. "cellular_jitter": 1.070,
  747. "octaves": 2,
  748. "frequency": 0.015,
  749. "fractal_type": FractalType.FractalType_FBm,
  750. "threshold": 0.30,
  751. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorDirtRock"],
  752. "priority": 2,
  753. },
  754. { # Wild crops
  755. "type": "BiomeEntityLayer",
  756. "entity_protos": [
  757. "WildPlantPotato",
  758. "WildPlantCorn",
  759. "WildPlantRice",
  760. "WildPlantWheat",
  761. "WildPlantHemp",
  762. "WildPlantPoppy",
  763. "WildPlantAloe",
  764. "WildPlantYarrow",
  765. "WildPlantElderflower",
  766. "WildPlantMilkThistle",
  767. "WildPlantComfrey",
  768. ],
  769. "noise_type": NoiseType.NoiseType_OpenSimplex2S,
  770. "octaves": 6,
  771. "frequency": 0.3,
  772. "fractal_type": FractalType.FractalType_FBm,
  773. "threshold": 0.84,
  774. "tile_condition": lambda tile: tile in [TILEMAP_REVERSE["FloorPlanetGrass"]],
  775. "priority": 1,
  776. },
  777. { # Rivers
  778. "type": "BiomeEntityLayer",
  779. "entity_protos": "FloorWaterEntity",
  780. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  781. "octaves": 1,
  782. "fractal_lacunarity": 1.50,
  783. "frequency": 0.003,
  784. "fractal_type": FractalType.FractalType_Ridged,
  785. "threshold": 0.95,
  786. "tile_condition": lambda tile: True,
  787. "priority": 10,
  788. "seed_key": "river_noise",
  789. },
  790. { # River sand
  791. "type": "BiomeTileLayer",
  792. "tile_type": "FloorSand",
  793. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  794. "octaves": 1,
  795. "frequency": 0.003, # Same as the river
  796. "fractal_type": FractalType.FractalType_Ridged,
  797. "threshold": 0.935, # Larger than the river
  798. "overwrite": True,
  799. "seed_key": "river_noise",
  800. },
  801. { # Additional River Sand with More Curves
  802. "type": "BiomeTileLayer",
  803. "tile_type": "FloorSand",
  804. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  805. "octaves": 1,
  806. "frequency": 0.003,
  807. "fractal_type": FractalType.FractalType_Ridged,
  808. "threshold": 0.92, # Slightly lower than the original
  809. "overwrite": True,
  810. "seed_key": "river_noise", # Same as the original to follow its path
  811. "modulation": {
  812. "noise_type": NoiseType.NoiseType_Perlin, # Different noise for variation
  813. "frequency": 0.01, # Controls the scale of the variation
  814. "threshold_min": 0.43, # Lower bound where sand starts appearing
  815. "threshold_max": 0.55, # Upper bound for a smooth transition
  816. },
  817. },
  818. { # Trees
  819. "type": "BiomeEntityLayer",
  820. "entity_protos": "TreeTemperate",
  821. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  822. "octaves": 1,
  823. "frequency": 0.5,
  824. "fractal_type": FractalType.FractalType_FBm,
  825. "threshold": 0.9,
  826. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  827. "priority": 0,
  828. },
  829. ####### PREDATORS
  830. { # Wolves
  831. "type": "BiomeEntityLayer",
  832. "entity_protos": "SpawnMobGreyWolf",
  833. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  834. "octaves": 1,
  835. "frequency": 0.1,
  836. "fractal_type": FractalType.FractalType_FBm,
  837. "threshold": 0.9981,
  838. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  839. "priority": 11,
  840. },
  841. { # Bears
  842. "type": "BiomeEntityLayer",
  843. "entity_protos": "SpawnMobBear",
  844. "noise_type": NoiseType.NoiseType_Perlin,
  845. "octaves": 1,
  846. "frequency": 0.300,
  847. "fractal_type": FractalType.FractalType_FBm,
  848. "threshold": 0.958,
  849. "tile_condition": lambda tile: tile
  850. in [TILEMAP_REVERSE["FloorPlanetGrass"], TILEMAP_REVERSE["FloorDirtRock"]],
  851. "priority": 1,
  852. },
  853. { # Sabertooth
  854. "type": "BiomeEntityLayer",
  855. "entity_protos": "SpawnMobSabertooth",
  856. "noise_type": NoiseType.NoiseType_Perlin,
  857. "octaves": 1,
  858. "frequency": 0.300,
  859. "fractal_type": FractalType.FractalType_FBm,
  860. "threshold": 0.96882,
  861. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  862. "priority": 11,
  863. },
  864. ####### Preys
  865. { # Rabbits
  866. "type": "BiomeEntityLayer",
  867. "entity_protos": "SpawnMobRabbit",
  868. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  869. "octaves": 1,
  870. "frequency": 0.1,
  871. "fractal_type": FractalType.FractalType_FBm,
  872. "threshold": 0.9989,
  873. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  874. "priority": 11,
  875. },
  876. { # Chicken
  877. "type": "BiomeEntityLayer",
  878. "entity_protos": "SpawnMobChicken",
  879. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  880. "octaves": 1,
  881. "frequency": 0.1,
  882. "fractal_type": FractalType.FractalType_FBm,
  883. "threshold": 0.9989,
  884. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  885. "priority": 11,
  886. },
  887. { # Deers
  888. "type": "BiomeEntityLayer",
  889. "entity_protos": "SpawnMobDeer",
  890. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  891. "octaves": 1,
  892. "frequency": 0.1,
  893. "fractal_type": FractalType.FractalType_FBm,
  894. "threshold": 0.9989,
  895. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  896. "priority": 11,
  897. },
  898. { # Pigs
  899. "type": "BiomeEntityLayer",
  900. "entity_protos": "SpawnMobPig",
  901. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  902. "octaves": 1,
  903. "frequency": 0.1,
  904. "fractal_type": FractalType.FractalType_FBm,
  905. "threshold": 0.9992,
  906. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  907. "priority": 11,
  908. },
  909. # DECALS
  910. { # Bush Temperate group 1
  911. "type": "BiomeDecalLayer",
  912. "decal_id": [
  913. "BushTemperate1",
  914. "BushTemperate2",
  915. "BushTemperate3",
  916. "BushTemperate4",
  917. ],
  918. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  919. "octaves": 1,
  920. "frequency": 0.1,
  921. "fractal_type": FractalType.FractalType_FBm,
  922. "threshold": 0.96,
  923. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  924. "color": "#FFFFFFFF",
  925. },
  926. { # Bush Temperate group 2
  927. "type": "BiomeDecalLayer",
  928. "decal_id": [
  929. "BushTemperate5",
  930. "BushTemperate6",
  931. "BushTemperate7",
  932. "BushTemperate8",
  933. ],
  934. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  935. "octaves": 1,
  936. "frequency": 0.1,
  937. "fractal_type": FractalType.FractalType_FBm,
  938. "threshold": 0.96,
  939. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  940. "color": "#FFFFFFFF",
  941. },
  942. { # Bush Temperate group 3
  943. "type": "BiomeDecalLayer",
  944. "decal_id": ["BushTemperate9", "BushTemperate10", "BushTemperate11"],
  945. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  946. "octaves": 1,
  947. "frequency": 0.1,
  948. "fractal_type": FractalType.FractalType_FBm,
  949. "threshold": 0.96,
  950. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  951. "color": "#FFFFFFFF",
  952. },
  953. { # Bush Temperate group 4
  954. "type": "BiomeDecalLayer",
  955. "decal_id": [
  956. "BushTemperate12",
  957. "BushTemperate13",
  958. "BushTemperate14",
  959. "BushTemperate15",
  960. ],
  961. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  962. "octaves": 1,
  963. "frequency": 0.1,
  964. "fractal_type": FractalType.FractalType_FBm,
  965. "threshold": 0.96,
  966. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  967. "color": "#FFFFFFFF",
  968. },
  969. { # Bush Temperate group 5
  970. "type": "BiomeDecalLayer",
  971. "decal_id": ["BushTemperate16", "BushTemperate17", "BushTemperate18"],
  972. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  973. "octaves": 1,
  974. "frequency": 0.1,
  975. "fractal_type": FractalType.FractalType_FBm,
  976. "threshold": 0.96,
  977. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  978. "color": "#FFFFFFFF",
  979. },
  980. { # Bush Temperate group 6
  981. "type": "BiomeDecalLayer",
  982. "decal_id": [
  983. "BushTemperate19",
  984. "BushTemperate20",
  985. "BushTemperate21",
  986. "BushTemperate22",
  987. ],
  988. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  989. "octaves": 1,
  990. "frequency": 0.1,
  991. "fractal_type": FractalType.FractalType_FBm,
  992. "threshold": 0.96,
  993. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  994. "color": "#FFFFFFFF",
  995. },
  996. { # Bush Temperate group 7
  997. "type": "BiomeDecalLayer",
  998. "decal_id": ["BushTemperate23", "BushTemperate24", "BushTemperate25"],
  999. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  1000. "octaves": 1,
  1001. "frequency": 0.1,
  1002. "fractal_type": FractalType.FractalType_FBm,
  1003. "threshold": 0.96,
  1004. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  1005. "color": "#FFFFFFFF",
  1006. },
  1007. { # Bush Temperate group 8
  1008. "type": "BiomeDecalLayer",
  1009. "decal_id": ["BushTemperate26", "BushTemperate27", "BushTemperate28"],
  1010. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  1011. "octaves": 1,
  1012. "frequency": 0.1,
  1013. "fractal_type": FractalType.FractalType_FBm,
  1014. "threshold": 0.96,
  1015. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  1016. "color": "#FFFFFFFF",
  1017. },
  1018. { # Bush Temperate group 9
  1019. "type": "BiomeDecalLayer",
  1020. "decal_id": [
  1021. "BushTemperate29",
  1022. "BushTemperate30",
  1023. "BushTemperate31",
  1024. "BushTemperate32",
  1025. ],
  1026. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  1027. "octaves": 1,
  1028. "frequency": 0.1,
  1029. "fractal_type": FractalType.FractalType_FBm,
  1030. "threshold": 0.96,
  1031. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  1032. "color": "#FFFFFFFF",
  1033. },
  1034. { # Bush Temperate group 10
  1035. "type": "BiomeDecalLayer",
  1036. "decal_id": [
  1037. "BushTemperate33",
  1038. "BushTemperate34",
  1039. "BushTemperate35",
  1040. "BushTemperate36",
  1041. ],
  1042. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  1043. "octaves": 1,
  1044. "frequency": 0.1,
  1045. "fractal_type": FractalType.FractalType_FBm,
  1046. "threshold": 0.96,
  1047. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  1048. "color": "#FFFFFFFF",
  1049. },
  1050. { # Bush Temperate group 11 - High grass
  1051. "type": "BiomeDecalLayer",
  1052. "decal_id": [
  1053. "BushTemperate37",
  1054. "BushTemperate38",
  1055. "BushTemperate39",
  1056. "BushTemperate40",
  1057. "BushTemperate41",
  1058. "BushTemperate42",
  1059. ],
  1060. "noise_type": NoiseType.NoiseType_OpenSimplex2,
  1061. "octaves": 1,
  1062. "frequency": 0.1,
  1063. "fractal_type": FractalType.FractalType_FBm,
  1064. "threshold": 0.96,
  1065. "tile_condition": lambda tile: tile == TILEMAP_REVERSE["FloorPlanetGrass"],
  1066. "color": "#FFFFFFFF",
  1067. },
  1068. ]
  1069. # -----------------------------------------------------------------------------
  1070. # Execution
  1071. # -----------------------------------------------------------------------------
  1072. start_time = time.time()
  1073. seed_base = random.randint(0, 1000000)
  1074. print(f"Generated seed: {seed_base}")
  1075. width, height = mapWidth, mapHeight
  1076. chunk_size = 16
  1077. biome_tile_layers = [layer for layer in MAP_CONFIG if layer["type"] == "BiomeTileLayer"]
  1078. biome_entity_layers = [
  1079. layer for layer in MAP_CONFIG if layer["type"] == "BiomeEntityLayer"
  1080. ]
  1081. script_dir = os.path.dirname(os.path.abspath(__file__))
  1082. output_dir = os.path.join(script_dir, "Resources", "Maps", "civ")
  1083. os.makedirs(output_dir, exist_ok=True)
  1084. tile_map = generate_tile_map(width, height, biome_tile_layers, seed_base)
  1085. # Applies erosion to lone sand tiles, overwritting it with surrounding tiles
  1086. tile_map = apply_iterative_erosion(
  1087. tile_map, TILEMAP_REVERSE["FloorSand"], min_neighbors=1
  1088. )
  1089. bordered_tile_map = add_border(tile_map, border_value=TILEMAP_REVERSE["FloorDirt"])
  1090. save_map_to_yaml(
  1091. bordered_tile_map,
  1092. MAP_CONFIG,
  1093. output_dir,
  1094. filename="nomads_classic.yml",
  1095. chunk_size=chunk_size,
  1096. seed_base=seed_base,
  1097. )
  1098. end_time = time.time()
  1099. total_time = end_time - start_time
  1100. print(f"Map generated and saved in {total_time:.2f} seconds!")