sculpt_and_grid_mapgen.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. use std::collections::BTreeMap;
  2. use std::path::PathBuf;
  3. use std::sync::Arc;
  4. use project_cold_water::audio::bvh::AcousticBvh;
  5. use project_cold_water::core::materials::MaterialId;
  6. use project_cold_water::modding::blueprint::{
  7. AssetBlueprint, BlueprintPayload, MapStampBlueprint, SCHEMA_VERSION,
  8. };
  9. use project_cold_water::modding::csg::{evaluate_csg_tree, CsgNode, CsgOp, PrimitiveKind};
  10. use project_cold_water::modding::registry::ModRegistry;
  11. use project_cold_water::sim::Simulation;
  12. use project_cold_water::world::generator::{
  13. CustomGridSpec, DynamicMapGenerator, GridCellScope, GridTemplateKind, MapGenConfig,
  14. };
  15. use project_cold_water::world::palette::{
  16. export_builtin_preset_to_map_stamp, MapGenPalette, MapGenSlot, WeightedAssetEntry,
  17. };
  18. use project_cold_water::world::terrain::ZoneType;
  19. use project_cold_water::world::{HeightQuery, MapScenario};
  20. fn make_temp_project_dir(tag: &str) -> PathBuf {
  21. let ts = std::time::SystemTime::now()
  22. .duration_since(std::time::UNIX_EPOCH)
  23. .map_or(0, |d| d.as_nanos());
  24. let dir = std::env::temp_dir().join(format!("cw_sculpt_test_{tag}_{ts}"));
  25. let _ = std::fs::remove_dir_all(&dir);
  26. std::fs::create_dir_all(&dir).expect("create temp dir");
  27. dir
  28. }
  29. #[test]
  30. fn test_mapgen_palette_custom_stamp_placement_and_builtin_export() {
  31. let dir = make_temp_project_dir("palette_stamp");
  32. // 1. Author a custom CSG MapStamp in temp project
  33. let stamp_bp = AssetBlueprint {
  34. schema_version: SCHEMA_VERSION,
  35. id: "test_custom_bastion".into(),
  36. name: "Test Custom Bastion".into(),
  37. author: "UnitTest".into(),
  38. payload: BlueprintPayload::MapStamp(MapStampBlueprint {
  39. nodes: vec![
  40. CsgNode::new_primitive(
  41. 1,
  42. "Bastion Block",
  43. CsgOp::Union,
  44. PrimitiveKind::Box,
  45. [0.0, 2.0, 0.0],
  46. [0.0, 0.0, 0.0],
  47. [7.0, 4.0, 7.0],
  48. MaterialId::Concrete,
  49. ),
  50. CsgNode::new_primitive(
  51. 2,
  52. "Room Cutout",
  53. CsgOp::Subtract,
  54. PrimitiveKind::Box,
  55. [0.0, 1.8, 0.0],
  56. [0.0, 0.0, 0.0],
  57. [5.0, 3.0, 5.0],
  58. MaterialId::Concrete,
  59. ),
  60. ],
  61. description: "Custom bastion stamp for generator palette test.".into(),
  62. blocks_navigation: true,
  63. }),
  64. };
  65. let mut mods = ModRegistry::load_project_dir(&dir, false);
  66. mods.save_blueprint(&dir, stamp_bp).expect("save custom stamp");
  67. // 2. Bind the custom stamp across slots in a custom MapGenPalette
  68. let mut zone_slots = BTreeMap::new();
  69. for &z in &ZoneType::ALL {
  70. let mut slots = BTreeMap::new();
  71. slots.insert(
  72. MapGenSlot::MediumBuilding,
  73. vec![WeightedAssetEntry::stamp("test_custom_bastion", 5.0, 6.0, true)],
  74. );
  75. slots.insert(
  76. MapGenSlot::LargeBuilding,
  77. vec![WeightedAssetEntry::stamp("test_custom_bastion", 5.0, 6.0, true)],
  78. );
  79. slots.insert(
  80. MapGenSlot::SmallBuilding,
  81. vec![WeightedAssetEntry::stamp("test_custom_bastion", 5.0, 6.0, true)],
  82. );
  83. slots.insert(
  84. MapGenSlot::Landmark,
  85. vec![WeightedAssetEntry::stamp("test_custom_bastion", 5.0, 6.0, true)],
  86. );
  87. slots.insert(
  88. MapGenSlot::Bridge,
  89. vec![WeightedAssetEntry::builtin("engine:bridge", 1.0, 14.0, false)],
  90. );
  91. zone_slots.insert(z, slots);
  92. }
  93. let palette = MapGenPalette {
  94. id: "custom_bastion_palette".into(),
  95. name: "Custom Bastion Palette".into(),
  96. zone_slots,
  97. };
  98. mods.save_palette(&dir, palette).expect("save custom palette");
  99. // 3. Reload from disk and generate a CustomGrid map using our palette
  100. let reloaded = ModRegistry::load_project_dir(&dir, false);
  101. assert!(reloaded.find_stamp("test_custom_bastion").is_some());
  102. assert!(reloaded.find_palette("custom_bastion_palette").is_some());
  103. let mut grid = CustomGridSpec::new(4, 4, GridCellScope::Block32m, ZoneType::SovietCityCore);
  104. grid.auto_roads = false;
  105. let mut cfg = MapGenConfig::custom_grid(grid, 777);
  106. cfg.palette_id = Some("custom_bastion_palette".into());
  107. let world = DynamicMapGenerator::new(cfg).build_with_mods(Some(&reloaded));
  108. assert!(
  109. !world.destructible.structures.is_empty(),
  110. "expected custom destructible stamps to be placed on the generated world"
  111. );
  112. assert!(
  113. world.static_indices.len() > 300,
  114. "expected static geometry from terrain + stamped CSG structures"
  115. );
  116. // 4. Convert a built-in generator preset -> editable CSG MapStamp
  117. let converted = export_builtin_preset_to_map_stamp("engine:block_medium");
  118. let BlueprintPayload::MapStamp(sb) = &converted.payload else {
  119. panic!("expected MapStamp payload from export_builtin_preset_to_map_stamp");
  120. };
  121. let polys = evaluate_csg_tree(&sb.nodes);
  122. assert!(!polys.is_empty(), "exported CSG stamp must evaluate to valid polygons");
  123. let _ = std::fs::remove_dir_all(&dir);
  124. }
  125. #[test]
  126. fn test_custom_grid_3x3_small_and_128x128_large_scaling() {
  127. // 1. Minimum 3x3 grid @ 32m scope -> 96m x 96m playable + scenic skirt -> 120m half_extent
  128. let mut small_grid = CustomGridSpec::new(3, 3, GridCellScope::Block32m, ZoneType::SuburbanTown);
  129. small_grid.set(1, 0, ZoneType::RiverCrossing);
  130. small_grid.set(1, 1, ZoneType::RiverCrossing);
  131. small_grid.set(1, 2, ZoneType::RiverCrossing);
  132. let small_world = DynamicMapGenerator::new(MapGenConfig::custom_grid(small_grid, 101)).build();
  133. assert!((small_world.world_half_extent - 120.0).abs() < 1.0);
  134. let small_play = small_world.height_grid.playable_half_extents();
  135. assert!((small_play.x - 48.0).abs() < 0.1 && (small_play.y - 48.0).abs() < 0.1);
  136. assert!(small_world.nav_grid.cells_per_side >= 16);
  137. assert!(!small_world.squad_spawns.is_empty());
  138. // 2. Maximum 128x128 grid @ 128m scope -> 16,384m playable + 25% skirt = 20,480m total (half_extent = 10,240m)
  139. let mut large_grid = CustomGridSpec::new(128, 128, GridCellScope::Sector128m, ZoneType::OpenField);
  140. large_grid.apply_template(GridTemplateKind::ValleyRiver, 404);
  141. let large_world = DynamicMapGenerator::new(MapGenConfig::custom_grid(large_grid, 404)).build();
  142. assert!(
  143. (large_world.world_half_extent - 10240.0).abs() < 1.0,
  144. "expected 20480m theater with +25% skirt (half_extent = 10240.0), got {}",
  145. large_world.world_half_extent
  146. );
  147. let large_play = large_world.height_grid.playable_half_extents();
  148. assert!((large_play.x - 8192.0).abs() < 1.0 && (large_play.y - 8192.0).abs() < 1.0);
  149. let chunks = large_world
  150. .terrain_chunks
  151. .as_ref()
  152. .expect("128x128 large grid must build 3-LOD chunked terrain");
  153. assert_eq!(chunks.chunks.len(), 256, "expected 16x16 = 256 LOD terrain chunks");
  154. let min_cx = chunks.chunks.iter().map(|c| c.bounds_min.x).fold(f32::MAX, f32::min);
  155. let max_cx = chunks.chunks.iter().map(|c| c.bounds_max.x).fold(f32::MIN, f32::max);
  156. let min_cz = chunks.chunks.iter().map(|c| c.bounds_min.z).fold(f32::MAX, f32::min);
  157. let max_cz = chunks.chunks.iter().map(|c| c.bounds_max.z).fold(f32::MIN, f32::max);
  158. assert!((min_cx + large_world.world_half_extent).abs() < 1.0);
  159. assert!((max_cx - large_world.world_half_extent).abs() < 1.0);
  160. assert!((min_cz + large_world.world_half_extent).abs() < 1.0);
  161. assert!((max_cz - large_world.world_half_extent).abs() < 1.0);
  162. assert!(
  163. large_world.nav_grid.cells_per_side <= 256,
  164. "NavGrid must remain bounded <= 256x256, got {}",
  165. large_world.nav_grid.cells_per_side
  166. );
  167. assert!(
  168. large_world.destructible.structures.len() <= 12_000,
  169. "destructible budget exceeded: {}",
  170. large_world.destructible.structures.len()
  171. );
  172. assert!(
  173. large_world.destructible.buildings.len() >= 20,
  174. "expected >= 20 destructible building clusters on 128x128 map, got {}",
  175. large_world.destructible.buildings.len()
  176. );
  177. assert!(
  178. large_world.squad_spawns.len() >= 2,
  179. "expected Federal & Militia spawns on 128x128 map"
  180. );
  181. }
  182. #[test]
  183. fn test_custom_grid_terrain_bounds_and_no_objects_outside_terrain() {
  184. let cases = [
  185. ("medium_16x16_64m", 16u16, 16u16, GridCellScope::District64m, GridTemplateKind::ValleyRiver),
  186. ("rect_24x8_64m", 24, 8, GridCellScope::District64m, GridTemplateKind::TwinCities),
  187. ("large_64x64_128m", 64, 64, GridCellScope::Sector128m, GridTemplateKind::RandomBiomes),
  188. ("island_12x12_64m", 12, 12, GridCellScope::District64m, GridTemplateKind::ArchipelagoLake),
  189. ];
  190. for (label, w, h, scope, tmpl) in cases {
  191. let mut spec = CustomGridSpec::new(w, h, scope, ZoneType::OpenField);
  192. spec.apply_template(tmpl, 5150);
  193. if label == "island_12x12_64m" {
  194. // Paint solid WaterLake border ring so skirt must continue into open water
  195. for x in 0..w {
  196. spec.set(x, 0, ZoneType::WaterLake);
  197. spec.set(x, h - 1, ZoneType::WaterLake);
  198. }
  199. for z in 0..h {
  200. spec.set(0, z, ZoneType::WaterLake);
  201. spec.set(w - 1, z, ZoneType::WaterLake);
  202. }
  203. }
  204. let world = DynamicMapGenerator::new(MapGenConfig::custom_grid(spec, 5150)).build();
  205. let play = world.height_grid.playable_half_extents();
  206. let he = world.world_half_extent;
  207. assert!(he >= play.x.max(play.y) + 48.0, "{label}: terrain must include scenic skirt");
  208. let chunks = world
  209. .terrain_chunks
  210. .as_ref()
  211. .unwrap_or_else(|| panic!("{label}: expected chunked terrain"));
  212. let min_cx = chunks.chunks.iter().map(|c| c.bounds_min.x).fold(f32::MAX, f32::min);
  213. let max_cx = chunks.chunks.iter().map(|c| c.bounds_max.x).fold(f32::MIN, f32::max);
  214. let min_cz = chunks.chunks.iter().map(|c| c.bounds_min.z).fold(f32::MAX, f32::min);
  215. let max_cz = chunks.chunks.iter().map(|c| c.bounds_max.z).fold(f32::MIN, f32::max);
  216. assert!(
  217. (min_cx + he).abs() < 1.0 && (max_cx - he).abs() < 1.0,
  218. "{label}: X chunk span [{min_cx}, {max_cx}] does not match [-{he}, +{he}]"
  219. );
  220. assert!(
  221. (min_cz + he).abs() < 1.0 && (max_cz - he).abs() < 1.0,
  222. "{label}: Z chunk span [{min_cz}, {max_cz}] does not match [-{he}, +{he}]"
  223. );
  224. // On chunked maps, static_vertices holds placed trees/buildings/props/bridges (not terrain).
  225. // Every single vertex must sit well inside the painted playable grid and never outside terrain!
  226. for v in &world.static_vertices {
  227. let px = v.position[0];
  228. let pz = v.position[2];
  229. assert!(
  230. px.abs() <= play.x + 18.0 && pz.abs() <= play.y + 18.0,
  231. "{label}: placed mesh vertex ({px}, {pz}) outside playable bounds ({}, {})",
  232. play.x,
  233. play.y
  234. );
  235. assert!(
  236. px.abs() <= he && pz.abs() <= he,
  237. "{label}: placed mesh vertex ({px}, {pz}) outside terrain half_extent {he}"
  238. );
  239. }
  240. // Biome-aware skirt height check + NavGrid clamping check
  241. let skirt_x = play.x + (he - play.x) * 0.75;
  242. let skirt_h = world.height_grid.height_at(skirt_x, 0.0);
  243. if label == "island_12x12_64m" {
  244. assert!(skirt_h < 0.0, "{label}: WaterLake border skirt should remain underwater, got {skirt_h}");
  245. } else {
  246. assert!(skirt_h > 4.0, "{label}: land border skirt should rise cleanly above sea level, got {skirt_h}");
  247. }
  248. let nav = &world.nav_grid;
  249. for iz in 0..nav.cells_per_side {
  250. let z = -nav.half_extent + (iz as f32 + 0.5) * nav.cell_size;
  251. for ix in 0..nav.cells_per_side {
  252. let x = -nav.half_extent + (ix as f32 + 0.5) * nav.cell_size;
  253. if nav.cells[iz * nav.cells_per_side + ix].is_walkable() {
  254. assert!(
  255. x.abs() <= play.x + nav.cell_size && z.abs() <= play.y + nav.cell_size,
  256. "{label}: walkable nav cell ({x}, {z}) leaked outside playable bounds"
  257. );
  258. }
  259. }
  260. }
  261. }
  262. }
  263. #[test]
  264. fn test_sculpt_empty_project_registry_has_no_cold_water_starters() {
  265. let dir = make_temp_project_dir("empty_sculpt_proj");
  266. let mods = ModRegistry::load_project_dir(&dir, false);
  267. assert!(mods.weapons.is_empty(), "Sculpt project must not seed Cold Water weapons");
  268. assert!(mods.vehicles.is_empty(), "Sculpt project must not seed Cold Water vehicles");
  269. assert!(mods.maps.is_empty(), "Sculpt project must not seed Cold Water maps");
  270. assert!(mods.stamps.is_empty(), "Sculpt project must not seed Cold Water stamps");
  271. assert!(
  272. !mods.mapgen_palettes.is_empty(),
  273. "Sculpt project should still have an engine default MapGenPalette"
  274. );
  275. let _ = std::fs::remove_dir_all(&dir);
  276. }
  277. #[test]
  278. fn test_custom_grid_painting_tools_and_json_roundtrip() {
  279. let dir = make_temp_project_dir("grid_roundtrip");
  280. let mut g = CustomGridSpec::new(12, 10, GridCellScope::District64m, ZoneType::OpenField);
  281. g.paint_line(0, 5, 11, 5, 1, ZoneType::RiverCrossing);
  282. assert_eq!(g.get(6, 5), ZoneType::RiverCrossing);
  283. g.paint_circle(2, 2, 2, ZoneType::SovietCityCore);
  284. assert_eq!(g.get(2, 2), ZoneType::SovietCityCore);
  285. g.flood_fill(9, 1, ZoneType::Forest);
  286. assert_eq!(g.get(9, 1), ZoneType::Forest);
  287. // Flood fill must not cross the RiverCrossing barrier at z=5
  288. assert_eq!(g.get(9, 8), ZoneType::OpenField);
  289. g.resize(16, 12, ZoneType::FoothillRidge);
  290. assert_eq!(g.width, 16);
  291. assert_eq!(g.height, 12);
  292. assert_eq!(g.get(15, 11), ZoneType::FoothillRidge);
  293. assert_eq!(g.get(6, 5), ZoneType::RiverCrossing);
  294. let path = dir.join("grids").join("roundtrip_test.cwgrid.json");
  295. g.save(&path).expect("save .cwgrid.json");
  296. let loaded = CustomGridSpec::load(&path).expect("load .cwgrid.json");
  297. assert_eq!(g, loaded);
  298. let _ = std::fs::remove_dir_all(&dir);
  299. }
  300. #[test]
  301. fn test_custom_grid_buildings_are_csg_destructible() {
  302. let mut spec = CustomGridSpec::new(16, 16, GridCellScope::District64m, ZoneType::OpenField);
  303. spec.apply_template(GridTemplateKind::ValleyRiver, 909);
  304. let world = DynamicMapGenerator::new(MapGenConfig::custom_grid(spec, 909)).build();
  305. assert!(
  306. world.destructible.buildings.len() >= 10,
  307. "expected >= 10 destructible buildings on 16x16 grid, got {}",
  308. world.destructible.buildings.len()
  309. );
  310. let first_aabb = world
  311. .destructible
  312. .structures
  313. .iter()
  314. .find(|s| s.building_id.is_some() && !s.polys.is_empty())
  315. .expect("first building panel")
  316. .aabb;
  317. let first_panel = (first_aabb.min + first_aabb.max) * 0.5;
  318. let last_aabb = world
  319. .destructible
  320. .structures
  321. .iter()
  322. .rev()
  323. .find(|s| s.building_id.is_some() && !s.polys.is_empty())
  324. .expect("last building panel")
  325. .aabb;
  326. let last_panel = (last_aabb.min + last_aabb.max) * 0.5;
  327. assert_ne!(first_panel, last_panel);
  328. let mut sim = Simulation::new(&world);
  329. let base_end = world
  330. .destructible
  331. .base_acoustic_tri_count
  332. .min(world.acoustic_triangles.len());
  333. sim.set_initial_bvh(Arc::new(AcousticBvh::build_split(
  334. world.acoustic_triangles[..base_end].to_vec(),
  335. &world.destructible,
  336. )));
  337. assert!(
  338. sim.apply_destruction_crater_batched(first_panel, 2.2, 42),
  339. "expected first grid building panel to carve"
  340. );
  341. assert!(
  342. sim.apply_destruction_crater_batched(last_panel, 2.2, 43),
  343. "expected last grid building panel to carve (not capped out)"
  344. );
  345. let new_bvh = sim.flush_destruction_updates();
  346. assert!(new_bvh.is_some(), "expected updated DynamicBvh after CSG craters");
  347. assert!(sim.destructible.revision >= 2);
  348. assert!(sim.take_world_geometry_dirty());
  349. }
  350. #[test]
  351. fn test_custom_grid_wide_and_oriented_rivers_have_no_mud_ridges_and_bank_to_bank_bridges() {
  352. // 1. Wide multi-cell river flanked by lakes (reproducing parallel mud ridge & fragmented bridge bug)
  353. let mut wide_spec = CustomGridSpec::new(9, 7, GridCellScope::District64m, ZoneType::OpenField);
  354. for gz in 0..7 {
  355. for gx in 2..=6 {
  356. let zt = if (2..=4).contains(&gz) {
  357. ZoneType::RiverCrossing
  358. } else {
  359. ZoneType::WaterLake
  360. };
  361. wide_spec.set(gx, gz, zt);
  362. }
  363. }
  364. let wide_world = DynamicMapGenerator::new(MapGenConfig::custom_grid(wide_spec, 4242)).build();
  365. let wl = wide_world.height_grid.water_level;
  366. assert!(wl > -10.0, "expected water level enabled");
  367. // Sample straight across the 5-cell-wide river interior (-128m..+128m at z=0) -> ZERO mud ridges!
  368. for step in 0..=32 {
  369. let x = -128.0 + (step as f32 / 32.0) * 256.0;
  370. let h = wide_world.height_grid.height_at(x, 0.0);
  371. assert!(
  372. h < wl - 0.5,
  373. "expected continuous submerged riverbed across 5-cell wide river at x={x:.1}, got h={h:.2} vs wl={wl:.2}"
  374. );
  375. }
  376. // All water mesh vertices must sit strictly flat at water_level (no climbing bank ramps)
  377. assert!(!wide_world.water_vertices.is_empty(), "expected water vertices on wide river");
  378. for wv in &wide_world.water_vertices {
  379. assert!(
  380. (wv.position[1] - wl).abs() < 1e-4,
  381. "water vertex sloped above/below water_level: y={} vs wl={}",
  382. wv.position[1],
  383. wl
  384. );
  385. }
  386. // Bank-to-bank bridge(s) must span East-West (!span_along_z) onto both dry banks and support A* crossing
  387. assert!(
  388. !wide_world.nav_grid.bridges.is_empty() && wide_world.nav_grid.bridges.len() <= 2,
  389. "expected 1-2 clean crossing bridges across wide river, got {}",
  390. wide_world.nav_grid.bridges.len()
  391. );
  392. let b = wide_world.nav_grid.bridges[0];
  393. assert!(!b.span_along_z, "expected East-West bridge spanning North-South river");
  394. assert!(
  395. b.half_span_x * 2.0 > 260.0,
  396. "expected full bank-to-bank bridge span > 260m across 5-cell (320m) channel, got {}",
  397. b.half_span_x * 2.0
  398. );
  399. let left_h = wide_world.height_grid.height_at(b.center_x - b.half_span_x, b.center_z);
  400. let right_h = wide_world.height_grid.height_at(b.center_x + b.half_span_x, b.center_z);
  401. assert!(left_h > wl + 0.4, "bridge west abutment should land on dry bank, got {left_h:.2}");
  402. assert!(right_h > wl + 0.4, "bridge east abutment should land on dry bank, got {right_h:.2}");
  403. let start = wide_world.nav_grid.nearest_walkable(glam::Vec3::new(-240.0, 0.0, -90.0));
  404. let goal = wide_world.nav_grid.nearest_walkable(glam::Vec3::new(240.0, 0.0, 90.0));
  405. let path = wide_world.nav_grid.find_path(start, goal);
  406. assert!(
  407. path.len() >= 2
  408. && path.last().map_or(false, |p| p.distance(goal) < 8.0)
  409. && path.iter().any(|p| {
  410. p.x.abs() < 40.0
  411. && wide_world
  412. .nav_grid
  413. .bridges
  414. .iter()
  415. .any(|br| (p.z - br.center_z).abs() < 12.0)
  416. }),
  417. "expected A* route to reach East bank across bridge, got {:?}",
  418. path
  419. );
  420. // 2. Horizontal (East-West) river across the middle -> continuous submerged channel & North-South bridge
  421. let mut ew_spec = CustomGridSpec::new(7, 7, GridCellScope::Block32m, ZoneType::OpenField);
  422. for gx in 0..7 {
  423. ew_spec.set(gx, 3, ZoneType::RiverCrossing);
  424. }
  425. let ew_world = DynamicMapGenerator::new(MapGenConfig::custom_grid(ew_spec, 5151)).build();
  426. let ew_wl = ew_world.height_grid.water_level;
  427. for step in 0..=24 {
  428. let x = -96.0 + (step as f32 / 24.0) * 192.0;
  429. let h = ew_world.height_grid.height_at(x, 0.0);
  430. assert!(
  431. h < ew_wl - 0.5,
  432. "expected continuous East-West river channel at x={x:.1}, got h={h:.2}"
  433. );
  434. }
  435. assert!(
  436. ew_world.nav_grid.bridges.iter().any(|br| br.span_along_z),
  437. "expected North-South bridge (span_along_z=true) across East-West river"
  438. );
  439. let n_bridge = ew_world.nav_grid.bridges.iter().find(|br| br.span_along_z).unwrap();
  440. let north_p = ew_world.nav_grid.nearest_walkable(glam::Vec3::new(-64.0, 0.0, -80.0));
  441. let south_p = ew_world.nav_grid.nearest_walkable(glam::Vec3::new(64.0, 0.0, 80.0));
  442. let ew_path = ew_world.nav_grid.find_path(north_p, south_p);
  443. let crossed_ns_bridge = ew_path
  444. .windows(2)
  445. .any(|seg| {
  446. let a = seg[0];
  447. let b = seg[1];
  448. (a.z <= 0.0 && b.z >= 0.0)
  449. && ew_world
  450. .nav_grid
  451. .bridges
  452. .iter()
  453. .any(|br| br.span_along_z && (a.x - br.center_x).abs() < 16.0 && (b.x - br.center_x).abs() < 16.0)
  454. });
  455. assert!(
  456. ew_path.len() >= 2
  457. && ew_path.last().map_or(false, |p| p.distance(south_p) < 8.0)
  458. && crossed_ns_bridge,
  459. "expected A* route across North-South bridge (x={:.1}) over East-West river, got {:?}",
  460. n_bridge.center_x,
  461. ew_path
  462. );
  463. }