| 421 | } |
| 422 | |
| 423 | bool estimate_materials(color_ostream &out, EmbarkTileLayout &tile, MatMap &layerMats, MatMap &veinMats) |
| 424 | { |
| 425 | using namespace geo_layer_type; |
| 426 | |
| 427 | df::world_geo_biome *geo_biome = tile.geo_biome; |
| 428 | |
| 429 | if (!geo_biome) |
| 430 | { |
| 431 | out.printerr("Region geo-biome not found: ({}, {})\n", |
| 432 | tile.biome_pos.x, tile.biome_pos.y); |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | // soil depth increases by 1 every 5 levels below 150 |
| 437 | unsigned nlayers = std::min<unsigned>(16, geo_biome->layers.size()); |
| 438 | int soil_size = 0; |
| 439 | |
| 440 | for (unsigned i = 0; i < nlayers; i++) |
| 441 | { |
| 442 | auto layer = geo_biome->layers[i]; |
| 443 | if (layer->type == SOIL || layer->type == SOIL_SAND) |
| 444 | soil_size += layer->top_height - layer->bottom_height + 1; |
| 445 | } |
| 446 | |
| 447 | // Compute shifts for layers in the stack |
| 448 | int soil_erosion = soil_size - std::min(soil_size,tile.max_soil_depth); |
| 449 | int layer_shift[16]; |
| 450 | int cur_shift = tile.elevation+soil_erosion-1; |
| 451 | |
| 452 | for (unsigned i = 0; i < nlayers; i++) |
| 453 | { |
| 454 | auto layer = geo_biome->layers[i]; |
| 455 | layer_shift[i] = cur_shift; |
| 456 | |
| 457 | if (layer->type == SOIL || layer->type == SOIL_SAND) |
| 458 | { |
| 459 | int size = layer->top_height - layer->bottom_height + 1; |
| 460 | |
| 461 | // This is to replicate the behavior of a probable bug in the |
| 462 | // map generation code: if a layer is partially eroded, the |
| 463 | // removed levels are in fact transferred to the layer below, |
| 464 | // because unlike the case of removing the whole layer, the code |
| 465 | // does not execute a loop to shift the lower part of the stack up. |
| 466 | if (size > soil_erosion) |
| 467 | cur_shift -= soil_erosion; |
| 468 | |
| 469 | soil_erosion -= std::min(soil_erosion, size); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | // Estimate amounts |
| 474 | int last_bottom = tile.elevation; |
| 475 | |
| 476 | for (unsigned i = 0; i < nlayers; i++) |
| 477 | { |
| 478 | auto layer = geo_biome->layers[i]; |
| 479 | |
| 480 | int top_z = last_bottom-1; |
no test coverage detected