MCPcopy Create free account
hub / github.com/Astropulse/hexmap / build_tilemap

Function build_tilemap

map.py:755–888  ·  view source on GitHub ↗
(cfg: Config)

Source from the content-addressed store, hash-verified

753
754
755def build_tilemap(cfg: Config):
756 elev, peaks, ridges, humid, temp, equator, land, dist_to_land, dist_to_water = build_fields(cfg)
757 mtn = build_mountains(cfg, land, elev, peaks, ridges, temp)
758 dist_to_mtn = hex_bfs_distance(mtn)
759
760 water0, ocean, lakes = add_lakes(cfg, elev, land, dist_to_water, dist_to_mtn)
761 land2 = ~water0
762 ocean_only = ocean & (~lakes)
763
764 river = prune_rivers(cfg, carve_rivers(cfg, elev, land2, dist_to_water, peaks, ridges, dist_to_mtn), water0)
765
766 desert_f = noise_field(cfg, 200, cfg.desert_scale, cfg.desert_octaves, cfg.desert_smooth_passes)
767 wheat_f = noise_field(cfg, 210, cfg.wheat_scale, cfg.wheat_octaves, cfg.wheat_smooth_passes)
768 beach_f = noise_field(cfg, 220, cfg.beach_scale, cfg.beach_octaves, cfg.beach_smooth_passes)
769 jungle_seed = noise_field(cfg, 230, cfg.jungle_seed_scale, cfg.jungle_seed_octaves, cfg.jungle_seed_smooth)
770
771 tilemap = np.full((cfg.rows, cfg.cols), "grass", dtype=object)
772 tilemap[(river == 1) & land2] = "shallow_water"
773
774 mtn2 = mtn & land2
775 hills_near = hex_bfs_distance(mtn2) <= int(cfg.hill_near_mountain_dist)
776
777 eq = equator[:, None].astype(np.float32)
778 grass_min = np.maximum(0.0, cfg.grass_humid_min - cfg.equator_fields_strength * eq)
779 forest_cut = cfg.forest_humid + cfg.equator_forest_suppress * eq
780 hot_cut = cfg.hot_temp - 0.02 * eq
781
782 t = temp
783 h = humid
784 e = elev
785
786 land_mask = land2 & (tilemap != "shallow_water")
787
788 snow = land_mask & (t <= cfg.snow_temp)
789 taiga_or_dirt = land_mask & (t > cfg.snow_temp) & (t <= cfg.cold_temp)
790 tilemap[snow] = "snow"
791 tilemap[taiga_or_dirt & (h >= cfg.dry_humid)] = "taiga"
792 tilemap[taiga_or_dirt & (h < cfg.dry_humid)] = "dirt"
793
794 mtn_cells = land2 & mtn2
795 tilemap[mtn_cells & (t <= cfg.cold_temp)] = "snow"
796 tilemap[mtn_cells & (t > cfg.cold_temp)] = "mountains"
797
798 hills = land2 & (~mtn2) & (
799 ((e >= cfg.hill_level) & hills_near)
800 | ((e >= (cfg.hill_level - 0.03)) & (noise_field(cfg, 900, 14, 1, 0) > 0.90))
801 )
802 tilemap[hills & (t <= cfg.snow_temp)] = "snow"
803 tilemap[hills & (t > cfg.snow_temp)] = "hills"
804
805 warm = land2 & (t > cfg.cold_temp) & (tilemap == "grass")
806
807 desert_score = desert_f + (t - hot_cut) + cfg.desert_hot_boost + cfg.equator_desert_strength * eq
808 desert = warm & (t >= hot_cut) & (h <= 0.44) & (desert_score > 0.90)
809 tilemap[desert & (h <= cfg.very_dry_humid)] = "dunes"
810 tilemap[desert & (h > cfg.very_dry_humid)] = "sand"
811
812 swamp = warm & (~desert) & (h >= cfg.wet_humid)

Callers 1

mainFunction · 0.85

Calls 14

build_fieldsFunction · 0.85
build_mountainsFunction · 0.85
hex_bfs_distanceFunction · 0.85
add_lakesFunction · 0.85
prune_riversFunction · 0.85
carve_riversFunction · 0.85
noise_fieldFunction · 0.85
swamp_variantFunction · 0.85
hash01Function · 0.85
clusterFunction · 0.85
cluster_onceFunction · 0.85
smooth_boxFunction · 0.85

Tested by

no test coverage detected