From 6e012bb032abd38f9c126bfd36648702b80e363c Mon Sep 17 00:00:00 2001 From: bseiller Date: Wed, 27 Jan 2021 23:05:40 +0100 Subject: [PATCH 01/23] refactoring embark-assistant survey, 1.iteration - survey.cpp: replacing repeated double vector access with a reference in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 105 ++++++++++++++-------------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 7a7ab334a..9fdd4086e 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -947,6 +947,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data for (uint8_t i = 0; i < 16; i++) { for (uint8_t k = 0; k < 16; k++) { + embark_assist::defs::mid_level_tile &mid_level_tile = mlt->at(i).at(k); max_soil_depth = -1; offset = details->biome[i][k]; @@ -954,23 +955,23 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data if (adjusted.x != x || adjusted.y != y) { - mlt->at(i).at(k).biome_offset = offset; + mid_level_tile.biome_offset = offset; } else { - mlt->at(i).at(k).biome_offset = 5; + mid_level_tile.biome_offset = 5; } - survey_results->at(x).at(y).biome_index[mlt->at(i).at(k).biome_offset] = + survey_results->at(x).at(y).biome_index[mid_level_tile.biome_offset] = world_data->region_map[adjusted.x][adjusted.y].region_id; - mlt->at(i).at(k).savagery_level = world_data->region_map[adjusted.x][adjusted.y].savagery / 33; - if (mlt->at(i).at(k).savagery_level == 3) { - mlt->at(i).at(k).savagery_level = 2; + mid_level_tile.savagery_level = world_data->region_map[adjusted.x][adjusted.y].savagery / 33; + if (mid_level_tile.savagery_level == 3) { + mid_level_tile.savagery_level = 2; } - mlt->at(i).at(k).evilness_level = world_data->region_map[adjusted.x][adjusted.y].evilness / 33; - if (mlt->at(i).at(k).evilness_level == 3) { - mlt->at(i).at(k).evilness_level = 2; + mid_level_tile.evilness_level = world_data->region_map[adjusted.x][adjusted.y].evilness / 33; + if (mid_level_tile.evilness_level == 3) { + mid_level_tile.evilness_level = 2; } elevation = details->elevation[i][k]; @@ -996,8 +997,8 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data base_z = elevation - 1; features = details->features[i][k]; - mlt->at(i).at(k).adamantine_level = -1; - mlt->at(i).at(k).magma_level = -1; + mid_level_tile.adamantine_level = -1; + mid_level_tile.magma_level = -1; end_check_l = static_cast(features.size()); for (size_t l = 0; l < end_check_l; l++) { @@ -1007,15 +1008,15 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data switch (world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]->getType()) { case df::feature_type::deep_special_tube: - mlt->at(i).at(k).adamantine_level = world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]->start_depth; + mid_level_tile.adamantine_level = world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]->start_depth; break; case df::feature_type::magma_pool: - mlt->at(i).at(k).magma_level = 2 - world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]->start_depth; + mid_level_tile.magma_level = 2 - world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]->start_depth; break; case df::feature_type::volcano: - mlt->at(i).at(k).magma_level = 3; + mid_level_tile.magma_level = 3; break; default: @@ -1046,43 +1047,43 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data int16_t cur_shift = elevation + soil_erosion - 1; aquifer = false; - mlt->at(i).at(k).aquifer = embark_assist::defs::Clear_Aquifer_Bits; - mlt->at(i).at(k).clay = false; - mlt->at(i).at(k).sand = false; - mlt->at(i).at(k).flux = false; - mlt->at(i).at(k).coal = false; + mid_level_tile.aquifer = embark_assist::defs::Clear_Aquifer_Bits; + mid_level_tile.clay = false; + mid_level_tile.sand = false; + mid_level_tile.flux = false; + mid_level_tile.coal = false; if (max_soil_depth == 0) { - mlt->at(i).at(k).soil_depth = 0; + mid_level_tile.soil_depth = 0; } else { - mlt->at(i).at(k).soil_depth = geo_summary->at(world_data->region_map[adjusted.x][adjusted.y].geo_index).soil_size - soil_erosion; + mid_level_tile.soil_depth = geo_summary->at(world_data->region_map[adjusted.x][adjusted.y].geo_index).soil_size - soil_erosion; } - mlt->at(i).at(k).offset = offset; - mlt->at(i).at(k).elevation = details->elevation[i][k]; - mlt->at(i).at(k).river_size = embark_assist::defs::river_sizes::None; - mlt->at(i).at(k).river_elevation = 100; + mid_level_tile.offset = offset; + mid_level_tile.elevation = details->elevation[i][k]; + mid_level_tile.river_size = embark_assist::defs::river_sizes::None; + mid_level_tile.river_elevation = 100; if (details->rivers_vertical.active[i][k] != 0) { - mlt->at(i).at(k).river_size = river_size_of (details->rivers_vertical.x_max[i][k] - details->rivers_vertical.x_min[i][k] + 1); - mlt->at(i).at(k).river_elevation = details->rivers_vertical.elevation[i][k]; + mid_level_tile.river_size = river_size_of (details->rivers_vertical.x_max[i][k] - details->rivers_vertical.x_min[i][k] + 1); + mid_level_tile.river_elevation = details->rivers_vertical.elevation[i][k]; } else if (details->rivers_horizontal.active[i][k] != 0) { - mlt->at(i).at(k).river_size = river_size_of (details->rivers_horizontal.y_max[i][k] - details->rivers_horizontal.y_min[i][k] + 1); - mlt->at(i).at(k).river_elevation = details->rivers_horizontal.elevation[i][k]; + mid_level_tile.river_size = river_size_of (details->rivers_horizontal.y_max[i][k] - details->rivers_horizontal.y_min[i][k] + 1); + mid_level_tile.river_elevation = details->rivers_horizontal.elevation[i][k]; } - if (mlt->at(i).at(k).river_size != embark_assist::defs::river_sizes::None && + if (mid_level_tile.river_size != embark_assist::defs::river_sizes::None && world_tile->flags.is_set(df::region_map_entry_flags::is_brook)) { - mlt->at(i).at(k).river_size = embark_assist::defs::river_sizes::Brook; + mid_level_tile.river_size = embark_assist::defs::river_sizes::Brook; } - if (tile->min_region_soil > mlt->at(i).at(k).soil_depth) { - tile->min_region_soil = mlt->at(i).at(k).soil_depth; + if (tile->min_region_soil > mid_level_tile.soil_depth) { + tile->min_region_soil = mid_level_tile.soil_depth; } - if (tile->max_region_soil < mlt->at(i).at(k).soil_depth) { - tile->max_region_soil = mlt->at(i).at(k).soil_depth; + if (tile->max_region_soil < mid_level_tile.soil_depth) { + tile->max_region_soil = mid_level_tile.soil_depth; } end_check_l = static_cast(world_data->geo_biomes[world_data->region_map[adjusted.x][adjusted.y].geo_index]->layers.size()); @@ -1124,38 +1125,38 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data if (top_z >= bottom_z) { last_bottom = bottom_z; - mlt->at(i).at(k).minerals[layer->mat_index] = true; + mid_level_tile.minerals[layer->mat_index] = true; end_check_m = static_cast(world->raws.inorganics[layer->mat_index]->metal_ore.mat_index.size()); for (uint16_t m = 0; m < end_check_m; m++) { - mlt->at(i).at(k).metals[world->raws.inorganics[layer->mat_index]->metal_ore.mat_index[m]] = true; + mid_level_tile.metals[world->raws.inorganics[layer->mat_index]->metal_ore.mat_index[m]] = true; } if (layer->type == df::geo_layer_type::SOIL || layer->type == df::geo_layer_type::SOIL_SAND) { if (world->raws.inorganics[layer->mat_index]->flags.is_set(df::inorganic_flags::SOIL_SAND)) { - mlt->at(i).at(k).sand = true; + mid_level_tile.sand = true; } } if (world->raws.inorganics[layer->mat_index]->economic_uses.size() > 0) { - mlt->at(i).at(k).economics[layer->mat_index] = true; + mid_level_tile.economics[layer->mat_index] = true; end_check_m = static_cast(world->raws.inorganics[layer->mat_index]->economic_uses.size()); for (uint16_t m = 0; m < end_check_m; m++) { if (world->raws.inorganics[layer->mat_index]->economic_uses[m] == state->clay_reaction) { - mlt->at(i).at(k).clay = true; + mid_level_tile.clay = true; } else if (world->raws.inorganics[layer->mat_index]->economic_uses[m] == state->flux_reaction) { - mlt->at(i).at(k).flux = true; + mid_level_tile.flux = true; } } for (uint16_t m = 0; m < state->coals.size(); m++) { if (layer->mat_index == state->coals[m]) { - mlt->at(i).at(k).coal = true; + mid_level_tile.coal = true; break; } } @@ -1164,31 +1165,31 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data end_check_m = static_cast(layer->vein_mat.size()); for (uint16_t m = 0; m < end_check_m; m++) { - mlt->at(i).at(k).minerals[layer->vein_mat[m]] = true; + mid_level_tile.minerals[layer->vein_mat[m]] = true; end_check_n = static_cast(world->raws.inorganics[layer->vein_mat[m]]->metal_ore.mat_index.size()); for (uint16_t n = 0; n < end_check_n; n++) { - mlt->at(i).at(k).metals[world->raws.inorganics[layer->vein_mat[m]]->metal_ore.mat_index[n]] = true; + mid_level_tile.metals[world->raws.inorganics[layer->vein_mat[m]]->metal_ore.mat_index[n]] = true; } if (world->raws.inorganics[layer->vein_mat[m]]->economic_uses.size() > 0) { - mlt->at(i).at(k).economics[layer->vein_mat[m]] = true; + mid_level_tile.economics[layer->vein_mat[m]] = true; end_check_n = static_cast(world->raws.inorganics[layer->vein_mat[m]]->economic_uses.size()); for (uint16_t n = 0; n < end_check_n; n++) { if (world->raws.inorganics[layer->vein_mat[m]]->economic_uses[n] == state->clay_reaction) { - mlt->at(i).at(k).clay = true; + mid_level_tile.clay = true; } else if (world->raws.inorganics[layer->vein_mat[m]]->economic_uses[n] == state->flux_reaction) { - mlt->at(i).at(k).flux = true; + mid_level_tile.flux = true; } } for (uint16_t n = 0; n < state->coals.size(); n++) { if (layer->vein_mat[m] == state->coals[n]) { - mlt->at(i).at(k).coal = true; + mid_level_tile.coal = true; break; } } @@ -1202,16 +1203,16 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } } if (!aquifer) { - mlt->at(i).at(k).aquifer = embark_assist::defs::None_Aquifer_Bit; + mid_level_tile.aquifer = embark_assist::defs::None_Aquifer_Bit; } else if (world_data->region_map[adjusted.x][adjusted.y].drainage % 20 == 7) { - mlt->at(i).at(k).aquifer = embark_assist::defs::Heavy_Aquifer_Bit; + mid_level_tile.aquifer = embark_assist::defs::Heavy_Aquifer_Bit; } else { - mlt->at(i).at(k).aquifer = embark_assist::defs::Light_Aquifer_Bit; + mid_level_tile.aquifer = embark_assist::defs::Light_Aquifer_Bit; } - mlt->at(i).at(k).trees = tree_level_of(world_data->regions[world_data->region_map[adjusted.x][adjusted.y].region_id]->type, + mid_level_tile.trees = tree_level_of(world_data->regions[world_data->region_map[adjusted.x][adjusted.y].region_id]->type, world_data->region_map[adjusted.x][adjusted.y].vegetation); } } From e90e84ab875c804ba3a74586fa40e1ceb9435fde Mon Sep 17 00:00:00 2001 From: bseiller Date: Thu, 28 Jan 2021 23:39:00 +0100 Subject: [PATCH 02/23] refactoring embark-assistant survey, 2.iteration - survey.cpp: replacing pointer and repeated nested vector access with a region_tile_datum reference in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 302 ++++++++++++++-------------- 1 file changed, 151 insertions(+), 151 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 9fdd4086e..c03d203b6 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -909,7 +909,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data auto screen = Gui::getViewscreenByType(0); int16_t x = screen->location.region_pos.x; int16_t y = screen->location.region_pos.y; - embark_assist::defs::region_tile_datum *tile = &survey_results->at(x).at(y); + embark_assist::defs::region_tile_datum &tile = survey_results->at(x).at(y); int8_t max_soil_depth; int8_t offset; int16_t elevation; @@ -930,9 +930,9 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data bool aquifer; for (uint16_t i = 0; i < state->max_inorganic; i++) { - tile->metals[i] = 0; - tile->economics[i] = 0; - tile->minerals[i] = 0; + tile.metals[i] = 0; + tile.economics[i] = 0; + tile.minerals[i] = 0; } for (uint8_t i = 0; i < 16; i++) { @@ -943,7 +943,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } } - for (uint8_t i = 1; i < 10; i++) survey_results->at(x).at(y).biome_index[i] = -1; + for (uint8_t i = 1; i < 10; i++) tile.biome_index[i] = -1; for (uint8_t i = 0; i < 16; i++) { for (uint8_t k = 0; k < 16; k++) { @@ -962,7 +962,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data mid_level_tile.biome_offset = 5; } - survey_results->at(x).at(y).biome_index[mid_level_tile.biome_offset] = + tile.biome_index[mid_level_tile.biome_offset] = world_data->region_map[adjusted.x][adjusted.y].region_id; mid_level_tile.savagery_level = world_data->region_map[adjusted.x][adjusted.y].savagery / 33; @@ -1078,12 +1078,12 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data mid_level_tile.river_size = embark_assist::defs::river_sizes::Brook; } - if (tile->min_region_soil > mid_level_tile.soil_depth) { - tile->min_region_soil = mid_level_tile.soil_depth; + if (tile.min_region_soil > mid_level_tile.soil_depth) { + tile.min_region_soil = mid_level_tile.soil_depth; } - if (tile->max_region_soil < mid_level_tile.soil_depth) { - tile->max_region_soil = mid_level_tile.soil_depth; + if (tile.max_region_soil < mid_level_tile.soil_depth) { + tile.max_region_soil = mid_level_tile.soil_depth; } end_check_l = static_cast(world_data->geo_biomes[world_data->region_map[adjusted.x][adjusted.y].geo_index]->layers.size()); @@ -1262,59 +1262,59 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } } - survey_results->at(x).at(y).aquifer = embark_assist::defs::Clear_Aquifer_Bits; - survey_results->at(x).at(y).clay_count = 0; - survey_results->at(x).at(y).sand_count = 0; - survey_results->at(x).at(y).flux_count = 0; - survey_results->at(x).at(y).coal_count = 0; - survey_results->at(x).at(y).min_region_soil = 10; - survey_results->at(x).at(y).max_region_soil = 0; - survey_results->at(x).at(y).savagery_count[0] = 0; - survey_results->at(x).at(y).savagery_count[1] = 0; - survey_results->at(x).at(y).savagery_count[2] = 0; - survey_results->at(x).at(y).evilness_count[0] = 0; - survey_results->at(x).at(y).evilness_count[1] = 0; - survey_results->at(x).at(y).evilness_count[2] = 0; + tile.aquifer = embark_assist::defs::Clear_Aquifer_Bits; + tile.clay_count = 0; + tile.sand_count = 0; + tile.flux_count = 0; + tile.coal_count = 0; + tile.min_region_soil = 10; + tile.max_region_soil = 0; + tile.savagery_count[0] = 0; + tile.savagery_count[1] = 0; + tile.savagery_count[2] = 0; + tile.evilness_count[0] = 0; + tile.evilness_count[1] = 0; + tile.evilness_count[2] = 0; for (uint8_t i = 0; i < 16; i++) { for (uint8_t k = 0; k < 16; k++) { - survey_results->at(x).at(y).aquifer |= mlt->at(i).at(k).aquifer; - if (mlt->at(i).at(k).clay) { survey_results->at(x).at(y).clay_count++; } - if (mlt->at(i).at(k).sand) { survey_results->at(x).at(y).sand_count++; } - if (mlt->at(i).at(k).flux) { survey_results->at(x).at(y).flux_count++; } - if (mlt->at(i).at(k).coal) { survey_results->at(x).at(y).coal_count++; } + tile.aquifer |= mlt->at(i).at(k).aquifer; + if (mlt->at(i).at(k).clay) { tile.clay_count++; } + if (mlt->at(i).at(k).sand) { tile.sand_count++; } + if (mlt->at(i).at(k).flux) { tile.flux_count++; } + if (mlt->at(i).at(k).coal) { tile.coal_count++; } - if (mlt->at(i).at(k).soil_depth < survey_results->at(x).at(y).min_region_soil) { - survey_results->at(x).at(y).min_region_soil = mlt->at(i).at(k).soil_depth; + if (mlt->at(i).at(k).soil_depth < tile.min_region_soil) { + tile.min_region_soil = mlt->at(i).at(k).soil_depth; } - if (mlt->at(i).at(k).soil_depth > survey_results->at(x).at(y).max_region_soil) { - survey_results->at(x).at(y).max_region_soil = mlt->at(i).at(k).soil_depth; + if (mlt->at(i).at(k).soil_depth > tile.max_region_soil) { + tile.max_region_soil = mlt->at(i).at(k).soil_depth; } if (mlt->at(i).at(k).river_size != embark_assist::defs::river_sizes::None) { - if (survey_results->at(x).at(y).min_river_size == embark_assist::defs::river_sizes::None || - mlt->at(i).at(k).river_size < survey_results->at(x).at(y).min_river_size) { - survey_results->at(x).at(y).min_river_size = mlt->at(i).at(k).river_size; + if (tile.min_river_size == embark_assist::defs::river_sizes::None || + mlt->at(i).at(k).river_size < tile.min_river_size) { + tile.min_river_size = mlt->at(i).at(k).river_size; } - if (survey_results->at(x).at(y).max_river_size < mlt->at(i).at(k).river_size) { - survey_results->at(x).at(y).max_river_size = mlt->at(i).at(k).river_size; + if (tile.max_river_size < mlt->at(i).at(k).river_size) { + tile.max_river_size = mlt->at(i).at(k).river_size; } if (i < 15 && mlt->at(i + 1).at(k).river_size != embark_assist::defs::river_sizes::None && abs (mlt->at(i).at(k).river_elevation - mlt->at(i + 1).at(k).river_elevation) > - survey_results->at(x).at(y).max_waterfall) { - survey_results->at(x).at(y).max_waterfall = + tile.max_waterfall) { + tile.max_waterfall = abs(mlt->at(i).at(k).river_elevation - mlt->at(i + 1).at(k).river_elevation); } if (k < 15 && mlt->at(i).at(k + 1).river_size != embark_assist::defs::river_sizes::None && abs(mlt->at(i).at(k).river_elevation - mlt->at(i).at(k + 1).river_elevation) > - survey_results->at(x).at(y).max_waterfall) { - survey_results->at(x).at(y).max_waterfall = + tile.max_waterfall) { + tile.max_waterfall = abs(mlt->at(i).at(k).river_elevation - mlt->at(i).at(k + 1).river_elevation); } } @@ -1325,23 +1325,23 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data // reanimating handled separately // thralling handled separately - if (survey_results->at(x).at(y).min_tree_level > mlt->at(i).at(k).trees) survey_results->at(x).at(y).min_tree_level = mlt->at(i).at(k).trees; - if (survey_results->at(x).at(y).max_tree_level < mlt->at(i).at(k).trees) survey_results->at(x).at(y).max_tree_level = mlt->at(i).at(k).trees; + if (tile.min_tree_level > mlt->at(i).at(k).trees) tile.min_tree_level = mlt->at(i).at(k).trees; + if (tile.max_tree_level < mlt->at(i).at(k).trees) tile.max_tree_level = mlt->at(i).at(k).trees; - survey_results->at(x).at(y).savagery_count[mlt->at(i).at(k).savagery_level]++; - survey_results->at(x).at(y).evilness_count[mlt->at(i).at(k).evilness_level]++; + tile.savagery_count[mlt->at(i).at(k).savagery_level]++; + tile.evilness_count[mlt->at(i).at(k).evilness_level]++; for (uint16_t l = 0; l < state->max_inorganic; l++) { - if (mlt->at(i).at(k).metals[l]) { survey_results->at(x).at(y).metals[l] = true; } - if (mlt->at(i).at(k).economics[l]) { survey_results->at(x).at(y).economics[l] = true; } - if (mlt->at(i).at(k).minerals[l]) { survey_results->at(x).at(y).minerals[l] = true; } + if (mlt->at(i).at(k).metals[l]) { tile.metals[l] = true; } + if (mlt->at(i).at(k).economics[l]) { tile.economics[l] = true; } + if (mlt->at(i).at(k).minerals[l]) { tile.minerals[l] = true; } } } } for (uint8_t i = 1; i < 10; i++) { - if (survey_results->at(x).at(y).biome_index[i] == -1) { - survey_results->at(x).at(y).biome[i] = -1; + if (tile.biome_index[i] == -1) { + tile.biome[i] = -1; } } @@ -1352,8 +1352,8 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data for (uint8_t i = 1; i < 10; i++) { - if (survey_results->at(x).at(y).biome[i] != -1) { - biomes[survey_results->at(x).at(y).biome[i]] = true; + if (tile.biome[i] != -1) { + biomes[tile.biome[i]] = true; } } int count = 0; @@ -1361,133 +1361,133 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data if (biomes[i]) count++; } - tile->biome_count = count; + tile.biome_count = count; for (uint8_t i = 0; i < 16; i++) { - tile->north_row[i].aquifer = mlt->at(i).at(0).aquifer; - tile->south_row[i].aquifer = mlt->at(i).at(15).aquifer; - tile->west_column[i].aquifer = mlt->at(0).at(i).aquifer; - tile->east_column[i].aquifer = mlt->at(15).at(i).aquifer; - - tile->north_row[i].clay= mlt->at(i).at(0).clay; - tile->south_row[i].clay = mlt->at(i).at(15).clay; - tile->west_column[i].clay = mlt->at(0).at(i).clay; - tile->east_column[i].clay = mlt->at(15).at(i).clay; - - tile->north_row[i].sand = mlt->at(i).at(0).sand; - tile->south_row[i].sand = mlt->at(i).at(15).sand; - tile->west_column[i].sand = mlt->at(0).at(i).sand; - tile->east_column[i].sand = mlt->at(15).at(i).sand; - - tile->north_row[i].flux = mlt->at(i).at(0).flux; // Not used - tile->south_row[i].flux = mlt->at(i).at(15).flux; - tile->west_column[i].flux = mlt->at(0).at(i).flux; - tile->east_column[i].flux = mlt->at(15).at(i).flux; - - tile->north_row[i].coal = mlt->at(i).at(0).coal; // Not used - tile->south_row[i].coal = mlt->at(i).at(15).coal; - tile->west_column[i].coal = mlt->at(0).at(i).coal; - tile->east_column[i].coal = mlt->at(15).at(i).coal; - - tile->north_row[i].soil_depth = mlt->at(i).at(0).soil_depth; - tile->south_row[i].soil_depth = mlt->at(i).at(15).soil_depth; - tile->west_column[i].soil_depth = mlt->at(0).at(i).soil_depth; - tile->east_column[i].soil_depth = mlt->at(15).at(i).soil_depth; - - tile->north_row[i].offset = mlt->at(i).at(0).offset; // Not used - tile->south_row[i].offset = mlt->at(i).at(15).offset; - tile->west_column[i].offset = mlt->at(0).at(i).offset; - tile->east_column[i].offset = mlt->at(15).at(i).offset; - - tile->north_row[i].elevation = mlt->at(i).at(0).elevation; - tile->south_row[i].elevation = mlt->at(i).at(15).elevation; - tile->west_column[i].elevation = mlt->at(0).at(i).elevation; - tile->east_column[i].elevation = mlt->at(15).at(i).elevation; - - tile->north_row[i].river_size = mlt->at(i).at(0).river_size; // Not used - tile->south_row[i].river_size = mlt->at(i).at(15).river_size; - tile->west_column[i].river_size = mlt->at(0).at(i).river_size; - tile->east_column[i].river_size = mlt->at(15).at(i).river_size; - - tile->north_row[i].river_elevation = mlt->at(i).at(0).river_elevation; // Not used - tile->south_row[i].river_elevation = mlt->at(i).at(15).river_elevation; - tile->west_column[i].river_elevation = mlt->at(0).at(i).river_elevation; - tile->east_column[i].river_elevation = mlt->at(15).at(i).river_elevation; - - tile->north_row[i].adamantine_level = mlt->at(i).at(0).adamantine_level; // Not used - tile->south_row[i].adamantine_level = mlt->at(i).at(15).adamantine_level; - tile->west_column[i].adamantine_level = mlt->at(0).at(i).adamantine_level; - tile->east_column[i].adamantine_level = mlt->at(15).at(i).adamantine_level; - - tile->north_row[i].magma_level = mlt->at(i).at(0).magma_level; // Not used - tile->south_row[i].magma_level = mlt->at(i).at(15).magma_level; - tile->west_column[i].magma_level = mlt->at(0).at(i).magma_level; - tile->east_column[i].magma_level = mlt->at(15).at(i).magma_level; - - tile->north_row[i].biome_offset = mlt->at(i).at(0).biome_offset; - tile->south_row[i].biome_offset = mlt->at(i).at(15).biome_offset; - tile->west_column[i].biome_offset = mlt->at(0).at(i).biome_offset; - tile->east_column[i].biome_offset = mlt->at(15).at(i).biome_offset; - - tile->north_row[i].trees = mlt->at(i).at(0).trees; - tile->south_row[i].trees = mlt->at(i).at(15).trees; - tile->west_column[i].trees = mlt->at(0).at(i).trees; - tile->east_column[i].trees = mlt->at(15).at(i).trees; + tile.north_row[i].aquifer = mlt->at(i).at(0).aquifer; + tile.south_row[i].aquifer = mlt->at(i).at(15).aquifer; + tile.west_column[i].aquifer = mlt->at(0).at(i).aquifer; + tile.east_column[i].aquifer = mlt->at(15).at(i).aquifer; + + tile.north_row[i].clay= mlt->at(i).at(0).clay; + tile.south_row[i].clay = mlt->at(i).at(15).clay; + tile.west_column[i].clay = mlt->at(0).at(i).clay; + tile.east_column[i].clay = mlt->at(15).at(i).clay; + + tile.north_row[i].sand = mlt->at(i).at(0).sand; + tile.south_row[i].sand = mlt->at(i).at(15).sand; + tile.west_column[i].sand = mlt->at(0).at(i).sand; + tile.east_column[i].sand = mlt->at(15).at(i).sand; + + tile.north_row[i].flux = mlt->at(i).at(0).flux; // Not used + tile.south_row[i].flux = mlt->at(i).at(15).flux; + tile.west_column[i].flux = mlt->at(0).at(i).flux; + tile.east_column[i].flux = mlt->at(15).at(i).flux; + + tile.north_row[i].coal = mlt->at(i).at(0).coal; // Not used + tile.south_row[i].coal = mlt->at(i).at(15).coal; + tile.west_column[i].coal = mlt->at(0).at(i).coal; + tile.east_column[i].coal = mlt->at(15).at(i).coal; + + tile.north_row[i].soil_depth = mlt->at(i).at(0).soil_depth; + tile.south_row[i].soil_depth = mlt->at(i).at(15).soil_depth; + tile.west_column[i].soil_depth = mlt->at(0).at(i).soil_depth; + tile.east_column[i].soil_depth = mlt->at(15).at(i).soil_depth; + + tile.north_row[i].offset = mlt->at(i).at(0).offset; // Not used + tile.south_row[i].offset = mlt->at(i).at(15).offset; + tile.west_column[i].offset = mlt->at(0).at(i).offset; + tile.east_column[i].offset = mlt->at(15).at(i).offset; + + tile.north_row[i].elevation = mlt->at(i).at(0).elevation; + tile.south_row[i].elevation = mlt->at(i).at(15).elevation; + tile.west_column[i].elevation = mlt->at(0).at(i).elevation; + tile.east_column[i].elevation = mlt->at(15).at(i).elevation; + + tile.north_row[i].river_size = mlt->at(i).at(0).river_size; // Not used + tile.south_row[i].river_size = mlt->at(i).at(15).river_size; + tile.west_column[i].river_size = mlt->at(0).at(i).river_size; + tile.east_column[i].river_size = mlt->at(15).at(i).river_size; + + tile.north_row[i].river_elevation = mlt->at(i).at(0).river_elevation; // Not used + tile.south_row[i].river_elevation = mlt->at(i).at(15).river_elevation; + tile.west_column[i].river_elevation = mlt->at(0).at(i).river_elevation; + tile.east_column[i].river_elevation = mlt->at(15).at(i).river_elevation; + + tile.north_row[i].adamantine_level = mlt->at(i).at(0).adamantine_level; // Not used + tile.south_row[i].adamantine_level = mlt->at(i).at(15).adamantine_level; + tile.west_column[i].adamantine_level = mlt->at(0).at(i).adamantine_level; + tile.east_column[i].adamantine_level = mlt->at(15).at(i).adamantine_level; + + tile.north_row[i].magma_level = mlt->at(i).at(0).magma_level; // Not used + tile.south_row[i].magma_level = mlt->at(i).at(15).magma_level; + tile.west_column[i].magma_level = mlt->at(0).at(i).magma_level; + tile.east_column[i].magma_level = mlt->at(15).at(i).magma_level; + + tile.north_row[i].biome_offset = mlt->at(i).at(0).biome_offset; + tile.south_row[i].biome_offset = mlt->at(i).at(15).biome_offset; + tile.west_column[i].biome_offset = mlt->at(0).at(i).biome_offset; + tile.east_column[i].biome_offset = mlt->at(15).at(i).biome_offset; + + tile.north_row[i].trees = mlt->at(i).at(0).trees; + tile.south_row[i].trees = mlt->at(i).at(15).trees; + tile.west_column[i].trees = mlt->at(0).at(i).trees; + tile.east_column[i].trees = mlt->at(15).at(i).trees; - tile->north_row[i].savagery_level = mlt->at(i).at(0).savagery_level; - tile->south_row[i].savagery_level = mlt->at(i).at(15).savagery_level; - tile->west_column[i].savagery_level = mlt->at(0).at(i).savagery_level; - tile->east_column[i].savagery_level = mlt->at(15).at(i).savagery_level; + tile.north_row[i].savagery_level = mlt->at(i).at(0).savagery_level; + tile.south_row[i].savagery_level = mlt->at(i).at(15).savagery_level; + tile.west_column[i].savagery_level = mlt->at(0).at(i).savagery_level; + tile.east_column[i].savagery_level = mlt->at(15).at(i).savagery_level; - tile->north_row[i].evilness_level = mlt->at(i).at(0).evilness_level; - tile->south_row[i].evilness_level = mlt->at(i).at(15).evilness_level; - tile->west_column[i].evilness_level = mlt->at(0).at(i).evilness_level; - tile->east_column[i].evilness_level = mlt->at(15).at(i).evilness_level; + tile.north_row[i].evilness_level = mlt->at(i).at(0).evilness_level; + tile.south_row[i].evilness_level = mlt->at(i).at(15).evilness_level; + tile.west_column[i].evilness_level = mlt->at(0).at(i).evilness_level; + tile.east_column[i].evilness_level = mlt->at(15).at(i).evilness_level; - tile->north_row[i].metals.resize(0); // Not used - tile->south_row[i].metals.resize(0); - tile->west_column[i].metals.resize(0); - tile->east_column[i].metals.resize(0); + tile.north_row[i].metals.resize(0); // Not used + tile.south_row[i].metals.resize(0); + tile.west_column[i].metals.resize(0); + tile.east_column[i].metals.resize(0); - tile->north_row[i].economics.resize(0); // Not used - tile->south_row[i].economics.resize(0); - tile->west_column[i].economics.resize(0); - tile->east_column[i].economics.resize(0); + tile.north_row[i].economics.resize(0); // Not used + tile.south_row[i].economics.resize(0); + tile.west_column[i].economics.resize(0); + tile.east_column[i].economics.resize(0); - tile->north_row[i].minerals.resize(0); // Not used - tile->south_row[i].minerals.resize(0); - tile->west_column[i].minerals.resize(0); - tile->east_column[i].minerals.resize(0); + tile.north_row[i].minerals.resize(0); // Not used + tile.south_row[i].minerals.resize(0); + tile.west_column[i].minerals.resize(0); + tile.east_column[i].minerals.resize(0); - tile->north_corner_selection[i] = world_data->region_details[0]->edges.biome_corner[i][0]; - tile->west_corner_selection[i] = world_data->region_details[0]->edges.biome_corner[0][i]; - tile->north_row_biome_x[i] = world_data->region_details[0]->edges.biome_x[i][0]; - tile->west_column_biome_y[i] = world_data->region_details[0]->edges.biome_y[0][i]; + tile.north_corner_selection[i] = world_data->region_details[0]->edges.biome_corner[i][0]; + tile.west_corner_selection[i] = world_data->region_details[0]->edges.biome_corner[0][i]; + tile.north_row_biome_x[i] = world_data->region_details[0]->edges.biome_x[i][0]; + tile.west_column_biome_y[i] = world_data->region_details[0]->edges.biome_y[0][i]; } for (uint8_t i = 0; i < 16; i++) { for (uint8_t k = 0; k < 16; k++) { - tile->region_type[i][k] = world_data->regions[tile->biome_index[mlt->at(i).at(k).biome_offset]]->type; + tile.region_type[i][k] = world_data->regions[tile.biome_index[mlt->at(i).at(k).biome_offset]]->type; } } // Focus has to be at the world tile to get neighbor info // - if (!tile->surveyed) { + if (!tile.surveyed) { for (uint16_t i = 0; i < world->entities.all.size(); i++) { if (world->entities.all[i]->flags.bits.neighbor) { if (world->entities.all[i]->type == df::historical_entity_type::SiteGovernment) { - tile->necro_neighbors++; + tile.necro_neighbors++; } else { - tile->neighbors.push_back(world->entities.all[i]->entity_raw->index); + tile.neighbors.push_back(world->entities.all[i]->entity_raw->index); } } } } - tile->surveyed = true; + tile.surveyed = true; } //================================================================================= From b33f06efeef86d093d9ba109f4015abab4b0a21e Mon Sep 17 00:00:00 2001 From: bseiller Date: Thu, 28 Jan 2021 23:48:09 +0100 Subject: [PATCH 03/23] refactoring embark-assistant survey, 3.iteration - survey.cpp: replacing repeated nested vector access with a mid_level_tile reference in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 51 +++++++++++++++-------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index c03d203b6..15db6cb5e 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -1278,44 +1278,45 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data for (uint8_t i = 0; i < 16; i++) { for (uint8_t k = 0; k < 16; k++) { - tile.aquifer |= mlt->at(i).at(k).aquifer; - if (mlt->at(i).at(k).clay) { tile.clay_count++; } - if (mlt->at(i).at(k).sand) { tile.sand_count++; } - if (mlt->at(i).at(k).flux) { tile.flux_count++; } - if (mlt->at(i).at(k).coal) { tile.coal_count++; } + embark_assist::defs::mid_level_tile &mid_level_tile = mlt->at(i).at(k); + tile.aquifer |= mid_level_tile.aquifer; + if (mid_level_tile.clay) { tile.clay_count++; } + if (mid_level_tile.sand) { tile.sand_count++; } + if (mid_level_tile.flux) { tile.flux_count++; } + if (mid_level_tile.coal) { tile.coal_count++; } - if (mlt->at(i).at(k).soil_depth < tile.min_region_soil) { - tile.min_region_soil = mlt->at(i).at(k).soil_depth; + if (mid_level_tile.soil_depth < tile.min_region_soil) { + tile.min_region_soil = mid_level_tile.soil_depth; } - if (mlt->at(i).at(k).soil_depth > tile.max_region_soil) { - tile.max_region_soil = mlt->at(i).at(k).soil_depth; + if (mid_level_tile.soil_depth > tile.max_region_soil) { + tile.max_region_soil = mid_level_tile.soil_depth; } - if (mlt->at(i).at(k).river_size != embark_assist::defs::river_sizes::None) { + if (mid_level_tile.river_size != embark_assist::defs::river_sizes::None) { if (tile.min_river_size == embark_assist::defs::river_sizes::None || - mlt->at(i).at(k).river_size < tile.min_river_size) { - tile.min_river_size = mlt->at(i).at(k).river_size; + mid_level_tile.river_size < tile.min_river_size) { + tile.min_river_size = mid_level_tile.river_size; } - if (tile.max_river_size < mlt->at(i).at(k).river_size) { - tile.max_river_size = mlt->at(i).at(k).river_size; + if (tile.max_river_size < mid_level_tile.river_size) { + tile.max_river_size = mid_level_tile.river_size; } if (i < 15 && mlt->at(i + 1).at(k).river_size != embark_assist::defs::river_sizes::None && - abs (mlt->at(i).at(k).river_elevation - mlt->at(i + 1).at(k).river_elevation) > + abs (mid_level_tile.river_elevation - mlt->at(i + 1).at(k).river_elevation) > tile.max_waterfall) { tile.max_waterfall = - abs(mlt->at(i).at(k).river_elevation - mlt->at(i + 1).at(k).river_elevation); + abs(mid_level_tile.river_elevation - mlt->at(i + 1).at(k).river_elevation); } if (k < 15 && mlt->at(i).at(k + 1).river_size != embark_assist::defs::river_sizes::None && - abs(mlt->at(i).at(k).river_elevation - mlt->at(i).at(k + 1).river_elevation) > + abs(mid_level_tile.river_elevation - mlt->at(i).at(k + 1).river_elevation) > tile.max_waterfall) { tile.max_waterfall = - abs(mlt->at(i).at(k).river_elevation - mlt->at(i).at(k + 1).river_elevation); + abs(mid_level_tile.river_elevation - mlt->at(i).at(k + 1).river_elevation); } } @@ -1325,16 +1326,16 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data // reanimating handled separately // thralling handled separately - if (tile.min_tree_level > mlt->at(i).at(k).trees) tile.min_tree_level = mlt->at(i).at(k).trees; - if (tile.max_tree_level < mlt->at(i).at(k).trees) tile.max_tree_level = mlt->at(i).at(k).trees; + if (tile.min_tree_level > mid_level_tile.trees) tile.min_tree_level = mid_level_tile.trees; + if (tile.max_tree_level < mid_level_tile.trees) tile.max_tree_level = mid_level_tile.trees; - tile.savagery_count[mlt->at(i).at(k).savagery_level]++; - tile.evilness_count[mlt->at(i).at(k).evilness_level]++; + tile.savagery_count[mid_level_tile.savagery_level]++; + tile.evilness_count[mid_level_tile.evilness_level]++; for (uint16_t l = 0; l < state->max_inorganic; l++) { - if (mlt->at(i).at(k).metals[l]) { tile.metals[l] = true; } - if (mlt->at(i).at(k).economics[l]) { tile.economics[l] = true; } - if (mlt->at(i).at(k).minerals[l]) { tile.minerals[l] = true; } + if (mid_level_tile.metals[l]) { tile.metals[l] = true; } + if (mid_level_tile.economics[l]) { tile.economics[l] = true; } + if (mid_level_tile.minerals[l]) { tile.minerals[l] = true; } } } } From 028a68ae6fbc680c17d3936e8570598c366ec1d6 Mon Sep 17 00:00:00 2001 From: bseiller Date: Sat, 30 Jan 2021 23:33:09 +0100 Subject: [PATCH 04/23] refactoring embark-assistant survey, 4.iteration - survey.cpp: replacing repeated nested vector access with a region_map_entry reference in survey_mid_level_tile; made a reference mid_level_tile const to prevent acidental change of values --- plugins/embark-assistant/survey.cpp | 35 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 8eb76515f..63e834977 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -961,15 +961,15 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data { mid_level_tile.biome_offset = 5; } + const df::region_map_entry ®ion_map_entry = world_data->region_map[adjusted.x][adjusted.y]; - tile.biome_index[mid_level_tile.biome_offset] = - world_data->region_map[adjusted.x][adjusted.y].region_id; + tile.biome_index[mid_level_tile.biome_offset] = region_map_entry.region_id; - mid_level_tile.savagery_level = world_data->region_map[adjusted.x][adjusted.y].savagery / 33; + mid_level_tile.savagery_level = region_map_entry.savagery / 33; if (mid_level_tile.savagery_level == 3) { mid_level_tile.savagery_level = 2; } - mid_level_tile.evilness_level = world_data->region_map[adjusted.x][adjusted.y].evilness / 33; + mid_level_tile.evilness_level = region_map_entry.evilness / 33; if (mid_level_tile.evilness_level == 3) { mid_level_tile.evilness_level = 2; } @@ -977,12 +977,11 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data elevation = details->elevation[i][k]; // Special biome adjustments - if (!world_data->region_map[adjusted.x][adjusted.y].flags.is_set(region_map_entry_flags::is_lake)) { - if (world_data->region_map[adjusted.x][adjusted.y].elevation >= 150) { // Mountain + if (!region_map_entry.flags.is_set(region_map_entry_flags::is_lake)) { + if (region_map_entry.elevation >= 150) { // Mountain max_soil_depth = 0; - } - else if (world_data->region_map[adjusted.x][adjusted.y].elevation < 100) { // Ocean + else if (region_map_entry.elevation < 100) { // Ocean if (elevation == 99) { elevation = 98; } @@ -1041,8 +1040,8 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data max_soil_depth = std::max((154 - elevation) / 5, 1); } - soil_erosion = geo_summary->at(world_data->region_map[adjusted.x][adjusted.y].geo_index).soil_size - - std::min((int)geo_summary->at(world_data->region_map[adjusted.x][adjusted.y].geo_index).soil_size, (int)max_soil_depth); + soil_erosion = geo_summary->at(region_map_entry.geo_index).soil_size - + std::min((int)geo_summary->at(region_map_entry.geo_index).soil_size, (int)max_soil_depth); int16_t layer_shift[16]; int16_t cur_shift = elevation + soil_erosion - 1; @@ -1057,7 +1056,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data mid_level_tile.soil_depth = 0; } else { - mid_level_tile.soil_depth = geo_summary->at(world_data->region_map[adjusted.x][adjusted.y].geo_index).soil_size - soil_erosion; + mid_level_tile.soil_depth = geo_summary->at(region_map_entry.geo_index).soil_size - soil_erosion; } mid_level_tile.offset = offset; mid_level_tile.elevation = details->elevation[i][k]; @@ -1086,11 +1085,11 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data tile.max_region_soil = mid_level_tile.soil_depth; } - end_check_l = static_cast(world_data->geo_biomes[world_data->region_map[adjusted.x][adjusted.y].geo_index]->layers.size()); + end_check_l = static_cast(world_data->geo_biomes[region_map_entry.geo_index]->layers.size()); if (end_check_l > 16) end_check_l = 16; for (uint16_t l = 0; l < end_check_l; l++) { - auto layer = world_data->geo_biomes[world_data->region_map[adjusted.x][adjusted.y].geo_index]->layers[l]; + auto layer = world_data->geo_biomes[region_map_entry.geo_index]->layers[l]; layer_shift[l] = cur_shift; if (layer->type == df::geo_layer_type::SOIL || @@ -1114,7 +1113,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data // Don't have to set up the end_check as we can reuse the one above. for (uint16_t l = 0; l < end_check_l; l++) { - auto layer = world_data->geo_biomes[world_data->region_map[adjusted.x][adjusted.y].geo_index]->layers[l]; + auto layer = world_data->geo_biomes[region_map_entry.geo_index]->layers[l]; top_z = last_bottom - 1; bottom_z = std::max((int)layer->bottom_height + layer_shift[l], (int)min_z); @@ -1205,15 +1204,15 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data if (!aquifer) { mid_level_tile.aquifer = embark_assist::defs::None_Aquifer_Bit; } - else if (world_data->region_map[adjusted.x][adjusted.y].drainage % 20 == 7) { + else if (region_map_entry.drainage % 20 == 7) { mid_level_tile.aquifer = embark_assist::defs::Heavy_Aquifer_Bit; } else { mid_level_tile.aquifer = embark_assist::defs::Light_Aquifer_Bit; } - mid_level_tile.trees = tree_level_of(world_data->regions[world_data->region_map[adjusted.x][adjusted.y].region_id]->type, - world_data->region_map[adjusted.x][adjusted.y].vegetation); + mid_level_tile.trees = tree_level_of(world_data->regions[region_map_entry.region_id]->type, + region_map_entry.vegetation); } } @@ -1278,7 +1277,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data for (uint8_t i = 0; i < 16; i++) { for (uint8_t k = 0; k < 16; k++) { - embark_assist::defs::mid_level_tile &mid_level_tile = mlt->at(i).at(k); + const embark_assist::defs::mid_level_tile &mid_level_tile = mlt->at(i).at(k); tile.aquifer |= mid_level_tile.aquifer; if (mid_level_tile.clay) { tile.clay_count++; } if (mid_level_tile.sand) { tile.sand_count++; } From 741e430a06df48e1d3d27efa7db2435139918991 Mon Sep 17 00:00:00 2001 From: bseiller Date: Sat, 30 Jan 2021 23:37:09 +0100 Subject: [PATCH 05/23] removing dead store from survey::survey_mid_level_tile - survey.cpp: deleting declaration of and assigments to variable base_z which is never used apart from a self-assigment --- plugins/embark-assistant/survey.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 63e834977..2610772f6 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -915,7 +915,6 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data int16_t elevation; int16_t last_bottom; int16_t top_z; - int16_t base_z; int16_t min_z = 0; // Initialized to silence warning about potential usage of uninitialized data. int16_t bottom_z; df::coord2d adjusted; @@ -994,7 +993,6 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } } - base_z = elevation - 1; features = details->features[i][k]; mid_level_tile.adamantine_level = -1; mid_level_tile.magma_level = -1; @@ -1026,8 +1024,6 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data feature->min_z != -30000) { auto layer = world_data->underground_regions[feature->layer]; - base_z = std::min((int)base_z, (int)feature->min_z); - if (layer->type == df::world_underground_region::MagmaSea) { min_z = feature->min_z; // The features are individual per region tile } From 115b8a439ffb3b43575f8c19003f9e402408a94e Mon Sep 17 00:00:00 2001 From: bseiller Date: Sun, 31 Jan 2021 13:58:17 +0100 Subject: [PATCH 06/23] fixing use of wrong indices, discovered during refactoring in survey::survey_mid_level_tile - survey.cpp: replacing faulty repeated nested vector access (due to wrong indices) with the existing region_map_entry reference --- plugins/embark-assistant/survey.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 2610772f6..4d5e16082 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -985,8 +985,8 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data elevation = 98; } - if ((world_data->geo_biomes[world_data->region_map[x][y].geo_index]->unk1 == 4 || - world_data->geo_biomes[world_data->region_map[x][y].geo_index]->unk1 == 5) && + if ((world_data->geo_biomes[region_map_entry.geo_index]->unk1 == 4 || + world_data->geo_biomes[region_map_entry.geo_index]->unk1 == 5) && details->unk12e8 < 500) { max_soil_depth = 0; } From 16438c59c899a140ca25d0fee493c60a0ebaae97 Mon Sep 17 00:00:00 2001 From: bseiller Date: Sun, 31 Jan 2021 14:03:49 +0100 Subject: [PATCH 07/23] Remove trailing whitespace as per lint rules --- plugins/embark-assistant/survey.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 4d5e16082..7fda5991d 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -1207,7 +1207,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data mid_level_tile.aquifer = embark_assist::defs::Light_Aquifer_Bit; } - mid_level_tile.trees = tree_level_of(world_data->regions[region_map_entry.region_id]->type, + mid_level_tile.trees = tree_level_of(world_data->regions[region_map_entry.region_id]->type, region_map_entry.vegetation); } } From 3181532bf2b48cc7a742c0ca5d6b5d583f788097 Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 00:24:56 +0100 Subject: [PATCH 08/23] refactoring embark-assistant survey, 5.iteration - survey.cpp: replacing repeated nested vector access with a const mid_level_tile reference in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 7fda5991d..23ea204e9 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -1298,20 +1298,20 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data tile.max_river_size = mid_level_tile.river_size; } - if (i < 15 && - mlt->at(i + 1).at(k).river_size != embark_assist::defs::river_sizes::None && - abs (mid_level_tile.river_elevation - mlt->at(i + 1).at(k).river_elevation) > - tile.max_waterfall) { - tile.max_waterfall = - abs(mid_level_tile.river_elevation - mlt->at(i + 1).at(k).river_elevation); + if (i < 15) { + const embark_assist::defs::mid_level_tile &eastern_neighbour = mlt->at(i + 1).at(k); + if (eastern_neighbour.river_size != embark_assist::defs::river_sizes::None && + abs(mid_level_tile.river_elevation - eastern_neighbour.river_elevation) > tile.max_waterfall) { + tile.max_waterfall = abs(mid_level_tile.river_elevation - eastern_neighbour.river_elevation); + } } - if (k < 15 && - mlt->at(i).at(k + 1).river_size != embark_assist::defs::river_sizes::None && - abs(mid_level_tile.river_elevation - mlt->at(i).at(k + 1).river_elevation) > - tile.max_waterfall) { - tile.max_waterfall = - abs(mid_level_tile.river_elevation - mlt->at(i).at(k + 1).river_elevation); + if (k < 15) { + const embark_assist::defs::mid_level_tile &southern_neighbour = mlt->at(i).at(k + 1); + if (southern_neighbour.river_size != embark_assist::defs::river_sizes::None && + abs(mid_level_tile.river_elevation - southern_neighbour.river_elevation) > tile.max_waterfall) { + tile.max_waterfall = abs(mid_level_tile.river_elevation - southern_neighbour.river_elevation); + } } } From aa520dfcce400cd4274f6dadb146b8714f4a1d97 Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 16:00:01 +0100 Subject: [PATCH 09/23] refactoring embark-assistant survey, 6.iteration - survey.cpp: add function to copy all incursion values from one mid_level_tile_incursion_base instance to another; replace repeated assignments with calls to new function in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 63 +++++++++-------------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 23ea204e9..ffbaf9fc2 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -902,6 +902,21 @@ void embark_assist::survey::high_level_world_survey(embark_assist::defs::geo_dat //================================================================================= +void inline copy_incursion_values(embark_assist::defs::mid_level_tile_incursion_base &target, + const embark_assist::defs::mid_level_tile_incursion_base &source) { + target.aquifer = source.aquifer; + target.clay = source.clay; + target.sand = source.sand; + target.soil_depth = source.soil_depth; + target.elevation = source.elevation; + target.biome_offset = source.biome_offset; + target.trees = source.trees; + target.savagery_level = source.savagery_level; + target.evilness_level = source.evilness_level; +} + +//================================================================================= + void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data *geo_summary, embark_assist::defs::world_tile_data *survey_results, embark_assist::defs::mid_level_tiles *mlt) { @@ -1360,50 +1375,10 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data tile.biome_count = count; for (uint8_t i = 0; i < 16; i++) { - tile.north_row[i].aquifer = mlt->at(i).at(0).aquifer; - tile.south_row[i].aquifer = mlt->at(i).at(15).aquifer; - tile.west_column[i].aquifer = mlt->at(0).at(i).aquifer; - tile.east_column[i].aquifer = mlt->at(15).at(i).aquifer; - - tile.north_row[i].clay= mlt->at(i).at(0).clay; - tile.south_row[i].clay = mlt->at(i).at(15).clay; - tile.west_column[i].clay = mlt->at(0).at(i).clay; - tile.east_column[i].clay = mlt->at(15).at(i).clay; - - tile.north_row[i].sand = mlt->at(i).at(0).sand; - tile.south_row[i].sand = mlt->at(i).at(15).sand; - tile.west_column[i].sand = mlt->at(0).at(i).sand; - tile.east_column[i].sand = mlt->at(15).at(i).sand; - - tile.north_row[i].soil_depth = mlt->at(i).at(0).soil_depth; - tile.south_row[i].soil_depth = mlt->at(i).at(15).soil_depth; - tile.west_column[i].soil_depth = mlt->at(0).at(i).soil_depth; - tile.east_column[i].soil_depth = mlt->at(15).at(i).soil_depth; - - tile.north_row[i].elevation = mlt->at(i).at(0).elevation; - tile.south_row[i].elevation = mlt->at(i).at(15).elevation; - tile.west_column[i].elevation = mlt->at(0).at(i).elevation; - tile.east_column[i].elevation = mlt->at(15).at(i).elevation; - - tile.north_row[i].biome_offset = mlt->at(i).at(0).biome_offset; - tile.south_row[i].biome_offset = mlt->at(i).at(15).biome_offset; - tile.west_column[i].biome_offset = mlt->at(0).at(i).biome_offset; - tile.east_column[i].biome_offset = mlt->at(15).at(i).biome_offset; - - tile.north_row[i].trees = mlt->at(i).at(0).trees; - tile.south_row[i].trees = mlt->at(i).at(15).trees; - tile.west_column[i].trees = mlt->at(0).at(i).trees; - tile.east_column[i].trees = mlt->at(15).at(i).trees; - - tile.north_row[i].savagery_level = mlt->at(i).at(0).savagery_level; - tile.south_row[i].savagery_level = mlt->at(i).at(15).savagery_level; - tile.west_column[i].savagery_level = mlt->at(0).at(i).savagery_level; - tile.east_column[i].savagery_level = mlt->at(15).at(i).savagery_level; - - tile.north_row[i].evilness_level = mlt->at(i).at(0).evilness_level; - tile.south_row[i].evilness_level = mlt->at(i).at(15).evilness_level; - tile.west_column[i].evilness_level = mlt->at(0).at(i).evilness_level; - tile.east_column[i].evilness_level = mlt->at(15).at(i).evilness_level; + copy_incursion_values(tile.north_row[i], mlt->at(i).at(0)); + copy_incursion_values(tile.south_row[i], mlt->at(i).at(15)); + copy_incursion_values(tile.west_column[i], mlt->at(0).at(i)); + copy_incursion_values(tile.east_column[i], mlt->at(15).at(i)); tile.north_corner_selection[i] = world_data->region_details[0]->edges.biome_corner[i][0]; tile.west_corner_selection[i] = world_data->region_details[0]->edges.biome_corner[0][i]; From db423cc11e8ac7e9bdecf1ad62ea63f167a08484 Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 22:22:10 +0100 Subject: [PATCH 10/23] refactoring embark-assistant survey, 7.iteration - survey.cpp: replacing repeated nested vector access with a const df::inorganic_raw pointer in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 33 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index ffbaf9fc2..3a46462f2 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -1137,29 +1137,29 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data mid_level_tile.minerals[layer->mat_index] = true; - end_check_m = static_cast(world->raws.inorganics[layer->mat_index]->metal_ore.mat_index.size()); + const df::inorganic_raw* inorganic_layer = world->raws.inorganics[layer->mat_index]; + end_check_m = static_cast(inorganic_layer->metal_ore.mat_index.size()); for (uint16_t m = 0; m < end_check_m; m++) { - mid_level_tile.metals[world->raws.inorganics[layer->mat_index]->metal_ore.mat_index[m]] = true; + mid_level_tile.metals[inorganic_layer->metal_ore.mat_index[m]] = true; } if (layer->type == df::geo_layer_type::SOIL || - layer->type == df::geo_layer_type::SOIL_SAND) { - if (world->raws.inorganics[layer->mat_index]->flags.is_set(df::inorganic_flags::SOIL_SAND)) { + layer->type == df::geo_layer_type::SOIL_SAND) { + if (inorganic_layer->flags.is_set(df::inorganic_flags::SOIL_SAND)) { mid_level_tile.sand = true; } } - if (world->raws.inorganics[layer->mat_index]->economic_uses.size() > 0) { + if (inorganic_layer->economic_uses.size() > 0) { mid_level_tile.economics[layer->mat_index] = true; - end_check_m = static_cast(world->raws.inorganics[layer->mat_index]->economic_uses.size()); + end_check_m = static_cast(inorganic_layer->economic_uses.size()); for (uint16_t m = 0; m < end_check_m; m++) { - if (world->raws.inorganics[layer->mat_index]->economic_uses[m] == state->clay_reaction) { + if (inorganic_layer->economic_uses[m] == state->clay_reaction) { mid_level_tile.clay = true; } - - else if (world->raws.inorganics[layer->mat_index]->economic_uses[m] == state->flux_reaction) { + else if (inorganic_layer->economic_uses[m] == state->flux_reaction) { mid_level_tile.flux = true; } } @@ -1177,22 +1177,23 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data for (uint16_t m = 0; m < end_check_m; m++) { mid_level_tile.minerals[layer->vein_mat[m]] = true; - end_check_n = static_cast(world->raws.inorganics[layer->vein_mat[m]]->metal_ore.mat_index.size()); + const df::inorganic_raw* inorganic_vein = world->raws.inorganics[layer->vein_mat[m]]; + end_check_n = static_cast(inorganic_vein->metal_ore.mat_index.size()); for (uint16_t n = 0; n < end_check_n; n++) { - mid_level_tile.metals[world->raws.inorganics[layer->vein_mat[m]]->metal_ore.mat_index[n]] = true; + mid_level_tile.metals[inorganic_vein->metal_ore.mat_index[n]] = true; } - if (world->raws.inorganics[layer->vein_mat[m]]->economic_uses.size() > 0) { + if (inorganic_vein->economic_uses.size() > 0) { mid_level_tile.economics[layer->vein_mat[m]] = true; - end_check_n = static_cast(world->raws.inorganics[layer->vein_mat[m]]->economic_uses.size()); + end_check_n = static_cast(inorganic_vein->economic_uses.size()); for (uint16_t n = 0; n < end_check_n; n++) { - if (world->raws.inorganics[layer->vein_mat[m]]->economic_uses[n] == state->clay_reaction) { + if (inorganic_vein->economic_uses[n] == state->clay_reaction) { mid_level_tile.clay = true; } - else if (world->raws.inorganics[layer->vein_mat[m]]->economic_uses[n] == state->flux_reaction) { + else if (inorganic_vein->economic_uses[n] == state->flux_reaction) { mid_level_tile.flux = true; } } @@ -1207,7 +1208,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } if (bottom_z <= elevation - 3 && - world->raws.inorganics[layer->mat_index]->flags.is_set(df::inorganic_flags::AQUIFER)) { + inorganic_layer->flags.is_set(df::inorganic_flags::AQUIFER)) { aquifer = true; } } From 9d64c9a5492c1a70bbc33eeed8941f1acd5a61a5 Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 22:25:57 +0100 Subject: [PATCH 11/23] refactoring embark-assistant survey, 8.iteration survey.cpp: remove unused includes --- plugins/embark-assistant/survey.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 3a46462f2..6e5848b45 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -14,13 +14,9 @@ #include "df/builtin_mats.h" #include "df/coord2d.h" #include "df/creature_interaction_effect.h" -#include "df/creature_interaction_effect_display_symbolst.h" #include "df/creature_interaction_effect_type.h" #include "df/entity_raw.h" #include "df/feature_init.h" -#include "df/feature_init_deep_special_tubest.h" -#include "df/feature_init_magma_poolst.h" -#include "df/feature_init_volcanost.h" #include "df/feature_type.h" #include "df/historical_entity.h" #include "df/historical_entity_type.h" @@ -29,17 +25,13 @@ #include "df/interaction.h" #include "df/interaction_effect.h" #include "df/interaction_effect_type.h" -#include "df/interaction_effect_animatest.h" #include "df/interaction_instance.h" #include "df/interaction_source.h" -#include "df/interaction_source_regionst.h" #include "df/interaction_source_type.h" #include "df/interaction_target.h" -#include "df/interaction_target_corpsest.h" #include "df/interaction_target_materialst.h" #include "df/material_common.h" #include "df/reaction.h" -#include "df/reaction_product.h" #include "df/reaction_product_itemst.h" #include "df/reaction_product_type.h" #include "df/region_map_entry.h" @@ -55,7 +47,6 @@ #include "df/world_region_details.h" #include "df/world_region_feature.h" #include "df/world_region_type.h" -#include "df/world_river.h" #include "df/world_site.h" #include "df/world_site_type.h" #include "df/world_underground_region.h" From 1ed783284e6b381a151da16d02dac7973e178958 Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 22:31:58 +0100 Subject: [PATCH 12/23] refactoring embark-assistant survey, 9.iteration - survey.cpp: replacing repeated vector access with a const world_geo_biome pointer in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 6e5848b45..93940106f 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -981,6 +981,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data elevation = details->elevation[i][k]; + df::world_geo_biome* world_geo_biome = world_data->geo_biomes[region_map_entry.geo_index]; // Special biome adjustments if (!region_map_entry.flags.is_set(region_map_entry_flags::is_lake)) { if (region_map_entry.elevation >= 150) { // Mountain @@ -991,8 +992,8 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data elevation = 98; } - if ((world_data->geo_biomes[region_map_entry.geo_index]->unk1 == 4 || - world_data->geo_biomes[region_map_entry.geo_index]->unk1 == 5) && + if ((world_geo_biome->unk1 == 4 || + world_geo_biome->unk1 == 5) && details->unk12e8 < 500) { max_soil_depth = 0; } @@ -1087,11 +1088,11 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data tile.max_region_soil = mid_level_tile.soil_depth; } - end_check_l = static_cast(world_data->geo_biomes[region_map_entry.geo_index]->layers.size()); + end_check_l = static_cast(world_geo_biome->layers.size()); if (end_check_l > 16) end_check_l = 16; for (uint16_t l = 0; l < end_check_l; l++) { - auto layer = world_data->geo_biomes[region_map_entry.geo_index]->layers[l]; + auto layer = world_geo_biome->layers[l]; layer_shift[l] = cur_shift; if (layer->type == df::geo_layer_type::SOIL || @@ -1115,7 +1116,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data // Don't have to set up the end_check as we can reuse the one above. for (uint16_t l = 0; l < end_check_l; l++) { - auto layer = world_data->geo_biomes[region_map_entry.geo_index]->layers[l]; + auto layer = world_geo_biome->layers[l]; top_z = last_bottom - 1; bottom_z = std::max((int)layer->bottom_height + layer_shift[l], (int)min_z); From 4fdcec58937c843d209ebf497cf457b77462fba6 Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 22:36:16 +0100 Subject: [PATCH 13/23] refactoring embark-assistant survey, 10.iteration - survey.cpp: replacing repeated vector access with auto value in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 93940106f..7fac3f0e3 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -981,7 +981,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data elevation = details->elevation[i][k]; - df::world_geo_biome* world_geo_biome = world_data->geo_biomes[region_map_entry.geo_index]; + const df::world_geo_biome* world_geo_biome = world_data->geo_biomes[region_map_entry.geo_index]; // Special biome adjustments if (!region_map_entry.flags.is_set(region_map_entry_flags::is_lake)) { if (region_map_entry.elevation >= 150) { // Mountain @@ -1009,14 +1009,15 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data auto feature = features[l]; if (feature->feature_idx != -1) { - switch (world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]->getType()) + auto feature_init = world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]; + switch (feature_init->getType()) { case df::feature_type::deep_special_tube: - mid_level_tile.adamantine_level = world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]->start_depth; + mid_level_tile.adamantine_level = feature_init->start_depth; break; case df::feature_type::magma_pool: - mid_level_tile.magma_level = 2 - world_data->feature_map[x / 16][y / 16].features->feature_init[x % 16][y % 16][feature->feature_idx]->start_depth; + mid_level_tile.magma_level = 2 - feature_init->start_depth; break; case df::feature_type::volcano: From aff64956fbd85457530b504baf24d3e4a659c610 Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 22:53:45 +0100 Subject: [PATCH 14/23] refactoring embark-assistant survey, 11.iteration - survey.cpp: replace repeated (nested) vector access with a auto pointers in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 7fac3f0e3..93feefd86 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -1044,8 +1044,9 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data max_soil_depth = std::max((154 - elevation) / 5, 1); } - soil_erosion = geo_summary->at(region_map_entry.geo_index).soil_size - - std::min((int)geo_summary->at(region_map_entry.geo_index).soil_size, (int)max_soil_depth); + auto geo_datum = geo_summary->at(region_map_entry.geo_index); + soil_erosion = geo_datum.soil_size - + std::min((int)geo_datum.soil_size, (int)max_soil_depth); int16_t layer_shift[16]; int16_t cur_shift = elevation + soil_erosion - 1; @@ -1060,7 +1061,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data mid_level_tile.soil_depth = 0; } else { - mid_level_tile.soil_depth = geo_summary->at(region_map_entry.geo_index).soil_size - soil_erosion; + mid_level_tile.soil_depth = geo_datum.soil_size - soil_erosion; } mid_level_tile.offset = offset; mid_level_tile.elevation = details->elevation[i][k]; @@ -1138,7 +1139,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } if (layer->type == df::geo_layer_type::SOIL || - layer->type == df::geo_layer_type::SOIL_SAND) { + layer->type == df::geo_layer_type::SOIL_SAND) { if (inorganic_layer->flags.is_set(df::inorganic_flags::SOIL_SAND)) { mid_level_tile.sand = true; } @@ -1233,14 +1234,15 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data // for (uint8_t i = 1; i < 16; i++) { for (uint8_t k = 0; k < 15; k++) { + auto western_neighbour = mlt->at(i - 1).at(k); if (details->rivers_horizontal.active[i][k] != 0 && details->rivers_vertical.active[i - 1][k + 1] != 0 && - mlt->at(i - 1).at(k).river_size == embark_assist::defs::river_sizes::None) { // Probably never true - mlt->at(i - 1).at(k).river_size = mlt->at(i).at(k).river_size; - mlt->at(i - 1).at(k).river_elevation = mlt->at(i).at(k).river_elevation; + western_neighbour.river_size == embark_assist::defs::river_sizes::None) { // Probably never true + western_neighbour.river_size = mlt->at(i).at(k).river_size; + western_neighbour.river_elevation = mlt->at(i).at(k).river_elevation; - if (mlt->at(i - 1).at(k).river_elevation > mlt->at(i - 1).at(k + 1).river_elevation) { - mlt->at(i - 1).at(k).river_elevation = mlt->at(i - 1).at(k + 1).river_elevation; + if (western_neighbour.river_elevation > mlt->at(i - 1).at(k + 1).river_elevation) { + western_neighbour.river_elevation = mlt->at(i - 1).at(k + 1).river_elevation; } } } @@ -1248,10 +1250,11 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data for (uint8_t i = 0; i < 16; i++) { for (uint8_t k = 1; k < 16; k++) { + auto northern_neighbour = mlt->at(i).at(k - 1); if (details->rivers_vertical.active[i][k] != 0 && - mlt->at(i).at(k - 1).river_size == embark_assist::defs::river_sizes::None) { - mlt->at(i).at(k - 1).river_size = mlt->at(i).at(k).river_size; - mlt->at(i).at(k - 1).river_elevation = mlt->at(i).at(k).river_elevation; + northern_neighbour.river_size == embark_assist::defs::river_sizes::None) { + northern_neighbour.river_size = mlt->at(i).at(k).river_size; + northern_neighbour.river_elevation = mlt->at(i).at(k).river_elevation; } } } From fede1360089e761c8b893361a7da57be94dcf7cf Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 22:57:30 +0100 Subject: [PATCH 15/23] refactoring embark-assistant survey, 12.iteration - survey.cpp: replace repeated (nested) vector access with an const int / auto pointer in survey_mid_level_tile --- plugins/embark-assistant/survey.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 93feefd86..d00e1b886 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -1169,9 +1169,10 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data end_check_m = static_cast(layer->vein_mat.size()); for (uint16_t m = 0; m < end_check_m; m++) { - mid_level_tile.minerals[layer->vein_mat[m]] = true; + const int vein_mat_index = layer->vein_mat[m]; + mid_level_tile.minerals[vein_mat_index] = true; - const df::inorganic_raw* inorganic_vein = world->raws.inorganics[layer->vein_mat[m]]; + const df::inorganic_raw* inorganic_vein = world->raws.inorganics[vein_mat_index]; end_check_n = static_cast(inorganic_vein->metal_ore.mat_index.size()); for (uint16_t n = 0; n < end_check_n; n++) { @@ -1179,7 +1180,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } if (inorganic_vein->economic_uses.size() > 0) { - mid_level_tile.economics[layer->vein_mat[m]] = true; + mid_level_tile.economics[vein_mat_index] = true; end_check_n = static_cast(inorganic_vein->economic_uses.size()); for (uint16_t n = 0; n < end_check_n; n++) { @@ -1193,7 +1194,7 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } for (uint16_t n = 0; n < state->coals.size(); n++) { - if (layer->vein_mat[m] == state->coals[n]) { + if (vein_mat_index == state->coals[n]) { mid_level_tile.coal = true; break; } @@ -1261,10 +1262,11 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data for (uint8_t i = 1; i < 16; i++) { for (uint8_t k = 0; k < 16; k++) { + auto western_neighbour = mlt->at(i - 1).at(k); if (details->rivers_horizontal.active[i][k] != 0 && - mlt->at(i - 1).at(k).river_size == embark_assist::defs::river_sizes::None) { - mlt->at(i - 1).at(k).river_size = mlt->at(i).at(k).river_size; - mlt->at(i - 1).at(k).river_elevation = mlt->at(i).at(k).river_elevation; + western_neighbour.river_size == embark_assist::defs::river_sizes::None) { + western_neighbour.river_size = mlt->at(i).at(k).river_size; + western_neighbour.river_elevation = mlt->at(i).at(k).river_elevation; } } } From 84151ccbf9bb973a50eccc309d3ac25b667415fe Mon Sep 17 00:00:00 2001 From: bseiller Date: Mon, 1 Feb 2021 23:52:51 +0100 Subject: [PATCH 16/23] Update changelog - changelog.txt: added entry for bug fix --- docs/changelog.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 989a9c558..bd8041eb0 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -33,6 +33,9 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future +## Fixes +- `embark-assistant`: fixed an issue that could result in "false positive" ocean tile matches in some cases when a soil depth criteria was specified + # 0.47.04-r5 ## Fixes From 76c9d7a678393eafb8f385651de358cdee029307 Mon Sep 17 00:00:00 2001 From: bseiller Date: Tue, 2 Feb 2021 00:32:30 +0100 Subject: [PATCH 17/23] Update changelog - changelog.txt: changed description of fix to be more concise Co-Authored-By: PatrikLundell <22739822+PatrikLundell@users.noreply.github.com> --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index bd8041eb0..617aec52c 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -34,7 +34,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future ## Fixes -- `embark-assistant`: fixed an issue that could result in "false positive" ocean tile matches in some cases when a soil depth criteria was specified +- `embark-assistant`: fixed bug in soil depth determination for ocean tiles # 0.47.04-r5 From 06cd0c843741ab42a45c6a926f6279675e07c56e Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 1 Feb 2021 23:23:19 -0500 Subject: [PATCH 18/23] Make libz.dylib optional on macOS Thurin reports that the path specified does not exist on macOS 11.2, and DFHack links successfully without it. CMake output from the find_package(ZLib) call in /CMakeLists.txt: Found ZLIB: /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/lib/libz.tbd (found suitable version "1.2.11", minimum required is "1.1.2") --- library/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 776a7de76..fd6c1c460 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -406,7 +406,10 @@ if(APPLE) set(ZIP_LIBRARY /usr/lib/libz.dylib) target_link_libraries(dfhack ${SDL_LIBRARY}) target_link_libraries(dfhack ${CXX_LIBRARY}) - target_link_libraries(dfhack ${ZIP_LIBRARY}) + if(EXISTS ${ZIP_LIBRARY}) + # doesn't exist on macOS 11, but DFHack seems to find the right library there + target_link_libraries(dfhack ${ZIP_LIBRARY}) + endif() target_link_libraries(dfhack ncurses) set_target_properties(dfhack PROPERTIES VERSION 1.0.0) set_target_properties(dfhack PROPERTIES SOVERSION 1.0.0) From 106349782888dca11465f96f8071ead627495636 Mon Sep 17 00:00:00 2001 From: myk002 Date: Tue, 2 Feb 2021 10:50:21 -0800 Subject: [PATCH 19/23] don't crash on malformed orders json --- docs/changelog.txt | 3 +++ plugins/orders.cpp | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 989a9c558..180021ea4 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -33,6 +33,9 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future +## Fixes +- `orders`: don't crash when importing orders with malformed JSON + # 0.47.04-r5 ## Fixes diff --git a/plugins/orders.cpp b/plugins/orders.cpp index 6c6888c0e..ab683f949 100644 --- a/plugins/orders.cpp +++ b/plugins/orders.cpp @@ -426,29 +426,38 @@ static command_result orders_import_command(color_ostream & out, const std::stri return CR_WRONG_USAGE; } + const std::string filename("dfhack-config/orders/" + name + ".json"); Json::Value orders; { - std::ifstream file("dfhack-config/orders/" + name + ".json"); + std::ifstream file(filename); if (!file.good()) { - out << COLOR_LIGHTRED << "Cannot find orders file." << std::endl; + out << COLOR_LIGHTRED << "Cannot find orders file: " << filename << std::endl; return CR_FAILURE; } - file >> orders; + try + { + file >> orders; + } + catch (const std::exception & e) + { + out << COLOR_LIGHTRED << "Error reading orders file: " << filename << ": " << e.what() << std::endl; + return CR_FAILURE; + } if (!file.good()) { - out << COLOR_LIGHTRED << "Error reading orders file." << std::endl; + out << COLOR_LIGHTRED << "Error reading orders file: " << filename << std::endl; return CR_FAILURE; } } if (orders.type() != Json::arrayValue) { - out << COLOR_LIGHTRED << "Invalid orders file: expected array" << std::endl; + out << COLOR_LIGHTRED << "Invalid orders file: " << filename << ": expected array" << std::endl; return CR_FAILURE; } From 625380a30b6fe63e5b5d8447aab0b26bfb6566fe Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 9 Feb 2021 00:11:59 -0500 Subject: [PATCH 20/23] Update submodules --- library/xml | 2 +- scripts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/xml b/library/xml index b7222848d..51f96f9ed 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit b7222848dbfd4391d8acafc926303bc4f6253d24 +Subproject commit 51f96f9edc52f8916d550f5f833e2959df68bfba diff --git a/scripts b/scripts index 86788f5bf..515c75d22 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 86788f5bf975da2506c61372ebfbe36ca47ed57c +Subproject commit 515c75d22d18e0d64e0e3d56ec32f16b209eeac6 From a051077820fbab069352ccf6ec067a645d913bf9 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Wed, 10 Feb 2021 18:54:05 -0600 Subject: [PATCH 21/23] update structures --- library/xml | 2 +- plugins/stockflow.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/xml b/library/xml index 51f96f9ed..58db67c6b 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 51f96f9edc52f8916d550f5f833e2959df68bfba +Subproject commit 58db67c6b6c1f0ffba27ada75a7bbbaef3001834 diff --git a/plugins/stockflow.cpp b/plugins/stockflow.cpp index 9533f1f6b..aede089ad 100644 --- a/plugins/stockflow.cpp +++ b/plugins/stockflow.cpp @@ -80,15 +80,15 @@ public: if (found) { // Entice the bookkeeper to spend less time update records. - ui->bookkeeper_precision += ui->bookkeeper_precision >> 3; + ui->nobles.bookkeeper_precision += ui->nobles.bookkeeper_precision >> 3; if (!bookkeeping) { command_method("start_bookkeeping", out); bookkeeping = true; } } else { // Entice the bookkeeper to update records more often. - ui->bookkeeper_precision -= ui->bookkeeper_precision >> 5; - ui->bookkeeper_cooldown -= ui->bookkeeper_cooldown >> 2; + ui->nobles.bookkeeper_precision -= ui->nobles.bookkeeper_precision >> 5; + ui->nobles.bookkeeper_cooldown -= ui->nobles.bookkeeper_cooldown >> 2; if (bookkeeping) { command_method("finish_bookkeeping", out); bookkeeping = false; From 49b6e814db4aae528cd7363084a64e8f2f11a543 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 10 Feb 2021 21:08:45 -0500 Subject: [PATCH 22/23] Bump to beta1, update submodules --- CMakeLists.txt | 2 +- docs/changelog.txt | 2 ++ library/xml | 2 +- scripts | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f17d8e6d3..bf0e045a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,7 +185,7 @@ endif() # set up versioning. set(DF_VERSION "0.47.05") -set(DFHACK_RELEASE "alpha0") +set(DFHACK_RELEASE "beta1") set(DFHACK_PRERELEASE TRUE) set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") diff --git a/docs/changelog.txt b/docs/changelog.txt index e530b9e38..3cf180c23 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -33,6 +33,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future +# 0.47.05-beta1 + ## Fixes - `embark-assistant`: fixed bug in soil depth determination for ocean tiles - `orders`: don't crash when importing orders with malformed JSON diff --git a/library/xml b/library/xml index 58db67c6b..f45c7324d 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 58db67c6b6c1f0ffba27ada75a7bbbaef3001834 +Subproject commit f45c7324de5ab6b18b3a3348a542cd125352ca0c diff --git a/scripts b/scripts index 515c75d22..52931e135 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 515c75d22d18e0d64e0e3d56ec32f16b209eeac6 +Subproject commit 52931e1357f20d911f38e3ca9cda528d9ee23f9c From 92a01e656f816c474fe43a6abb480f01aef38630 Mon Sep 17 00:00:00 2001 From: lethosor Date: Fri, 12 Feb 2021 00:37:32 -0500 Subject: [PATCH 23/23] Update scripts --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index 52931e135..3cb5415e0 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 52931e1357f20d911f38e3ca9cda528d9ee23f9c +Subproject commit 3cb5415e0044c80297bfbbae0722e22c86f72d33