(ctx: &ReducerContext)
| 221 | |
| 222 | pub fn build(ctx: &ReducerContext) { |
| 223 | let mut cache = LocationCache::new(); |
| 224 | let mut terrain_cache = TerrainChunkCache::fetch(ctx); |
| 225 | |
| 226 | let biomes_count = Biome::iter().count(); |
| 227 | for _ in 0..biomes_count { |
| 228 | cache.biome_chunks.push(0.0); |
| 229 | } |
| 230 | |
| 231 | // spawning points |
| 232 | for terrain_chunk in terrain_cache.iter_cached_values() { |
| 233 | for terrain_cell in terrain_chunk.local_iter(1) { |
| 234 | if terrain_cell.zoning_type == 1 && !terrain_cell.is_submerged() { |
| 235 | cache.spawn_locations.push(terrain_cell.coordinates().center_small_tile()); |
| 236 | } |
| 237 | cache.region_max_x = std::cmp::max(terrain_cell.x, cache.region_max_x); |
| 238 | cache.region_max_z = std::cmp::max(terrain_cell.z, cache.region_max_z); |
| 239 | cache.region_min_x = std::cmp::min(terrain_cell.x, cache.region_min_x); |
| 240 | cache.region_min_z = std::cmp::min(terrain_cell.z, cache.region_min_z); |
| 241 | cache.biome_chunks[terrain_cell.biome() as usize] += 1.0; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | // divide biome sizes by chunk size |
| 246 | for chunk_size in cache.biome_chunks.iter_mut() { |
| 247 | *chunk_size /= (TERRAIN_CHUNK_HEIGHT * TERRAIN_CHUNK_WIDTH) as f32; |
| 248 | } |
| 249 | |
| 250 | cache.region_max_x += 1; |
| 251 | cache.region_max_z += 1; |
| 252 | |
| 253 | log::info!("Starting location count {}", cache.spawn_locations.len()); |
| 254 | |
| 255 | if cache.region_max_x == 1 && cache.region_max_z == 1 { |
| 256 | log::info!("No world loaded, not building enemy spawn location cache."); |
| 257 | } else { |
| 258 | log::debug!("Started building enemy spawn location cache"); |
| 259 | cache.build_enemy_spawn_locations(ctx, &mut terrain_cache); |
| 260 | log::debug!("Done building enemy spawn location cache"); |
| 261 | } |
| 262 | |
| 263 | cache.collect_traveler_ruins_ids(ctx); |
| 264 | cache.collect_all_ruins_ids(ctx); |
| 265 | |
| 266 | if ctx.db.location_cache().try_insert(cache).is_err() { |
| 267 | log::error!("Failed to insert location cache"); |
| 268 | } |
| 269 | } |
| 270 | } |
nothing calls this directly
no test coverage detected