From 07dedfb3334db220defb4b1ef215404732e6a648 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Sun, 24 Nov 2019 21:32:07 +0100 Subject: [PATCH] Fixed/improved river tile detection --- docs/changelog.txt | 2 ++ plugins/embark-assistant/matcher.cpp | 2 +- plugins/embark-assistant/survey.cpp | 49 ++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index c1d7bae72..818f60d3c 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -52,6 +52,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `embark-assistant`: - fixed bug causing crash on worlds without generated metals (as well as pruning vectors as originally intended). - fixed bug causing mineral matching to fail to cut off at the magma sea, reporting presence of things that aren't (like DF does currently). + - fixed bug causing half of the river tiles not to be recognized. + - added logic to detect some river tiles DF doesn't generate data for (but are definitely present). - `gui/autogems`: fixed error when no world is loaded - `gui/companion-order`: - fixed error when resetting group leaders diff --git a/plugins/embark-assistant/matcher.cpp b/plugins/embark-assistant/matcher.cpp index c013a695e..715453551 100644 --- a/plugins/embark-assistant/matcher.cpp +++ b/plugins/embark-assistant/matcher.cpp @@ -2076,7 +2076,7 @@ namespace embark_assist { uint32_t preliminary_world_match(embark_assist::defs::world_tile_data *survey_results, embark_assist::defs::finders *finder, embark_assist::defs::match_results *match_results) { - // color_ostream_proxy out(Core::getInstance().getConsole()); +// color_ostream_proxy out(Core::getInstance().getConsole()); uint32_t count = 0; for (uint16_t i = 0; i < world->worldgen.worldgen_parms.dim_x; i++) { for (uint16_t k = 0; k < world->worldgen.worldgen_parms.dim_y; k++) { diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 5e9e44b5f..a2fb648f2 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -1043,11 +1043,11 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data mlt->at(i).at(k).river_present = false; mlt->at(i).at(k).river_elevation = 100; - if (details->rivers_vertical.active[i][k] == 1) { + if (details->rivers_vertical.active[i][k] != 0) { mlt->at(i).at(k).river_present = true; mlt->at(i).at(k).river_elevation = details->rivers_vertical.elevation[i][k]; } - else if (details->rivers_horizontal.active[i][k] == 1) { + else if (details->rivers_horizontal.active[i][k] != 0) { mlt->at(i).at(k).river_present = true; mlt->at(i).at(k).river_elevation = details->rivers_horizontal.elevation[i][k]; } @@ -1179,6 +1179,51 @@ void embark_assist::survey::survey_mid_level_tile(embark_assist::defs::geo_data } } + // This is messy. DF has some weird logic to leave out river bends with a South and an East connection, as well + // as river sources (and presumably sinks) that are to the North or the West of the connecting river. + // Experiments indicate these implicit river bends inherit their River Elevation from the lower of the two + // "parents", and it's assumed river sources and sinks similarly inherit it from their sole "parent". + // Two issues are known: + // - Lake and Ocean tiles may be marked as having a river when DF doesn't. However, DF does allow for rivers to + // exist in Ocean/Lake tiles, as well as sources/sinks. + // - DF generates rivers on/under glaciers, but does not display them (as they're frozen), nor are their names + // displayed. + // + for (uint8_t i = 1; i < 16; i++) { + for (uint8_t k = 0; k < 15; 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_present) { // Probably never true + mlt->at(i - 1).at(k).river_present = true; + mlt->at(i - 1).at(k).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; + } + } + } + } + + for (uint8_t i = 0; i < 16; i++) { + for (uint8_t k = 1; k < 16; k++) { + if (details->rivers_vertical.active[i][k] != 0 && + !mlt->at(i).at(k - 1).river_present) { + mlt->at(i).at(k - 1).river_present = true; + mlt->at(i).at(k - 1).river_elevation = mlt->at(i).at(k).river_elevation; + } + } + } + + for (uint8_t i = 1; i < 16; i++) { + for (uint8_t k = 0; k < 16; k++) { + if (details->rivers_horizontal.active[i][k] != 0 && + !mlt->at(i - 1).at(k).river_present) { + mlt->at(i - 1).at(k).river_present = true; + mlt->at(i - 1).at(k).river_elevation = mlt->at(i).at(k).river_elevation; + } + } + } + survey_results->at(x).at(y).aquifer_count = 0; survey_results->at(x).at(y).clay_count = 0; survey_results->at(x).at(y).sand_count = 0;