From f90eebdd2dcdd3d13a39d9dfc566c65ac2ce1f87 Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 19 Jun 2018 22:41:18 +0300 Subject: [PATCH 1/2] Add designation job check to deramp Fixes #1228 --- plugins/deramp.cpp | 52 +++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/plugins/deramp.cpp b/plugins/deramp.cpp index fd7ceb3d7..97a3dc184 100644 --- a/plugins/deramp.cpp +++ b/plugins/deramp.cpp @@ -7,10 +7,12 @@ #include "DataDefs.h" #include "modules/Maps.h" +#include "modules/Job.h" #include "TileTypes.h" #include "df/map_block.h" #include "df/world.h" +#include "df/job.h" using std::vector; using std::string; @@ -20,6 +22,24 @@ using namespace df::enums; DFHACK_PLUGIN("deramp"); REQUIRE_GLOBAL(world); +static void doDeramp(df::map_block* block, df::map_block* above, int x, int y, df::tiletype oldT) +{ + // Current tile is a ramp. + // Set current tile, as accurately as can be expected + df::tiletype newT = findSimilarTileType(oldT, tiletype_shape::FLOOR); + + // If no change, skip it (couldn't find a good tile type) + if (oldT == newT) + return; + // Set new tile type, clear designation + block->tiletype[x][y] = newT; + block->designation[x][y].bits.dig = tile_dig_designation::No; + + // Check the tile above this one, in case a downward slope needs to be removed. + if ((above) && (tileShape(above->tiletype[x][y]) == tiletype_shape::RAMP_TOP)) + above->tiletype[x][y] = tiletype::OpenSpace; // open space +} + command_result df_deramp (color_ostream &out, vector & parameters) { if (!parameters.empty()) @@ -36,6 +56,23 @@ command_result df_deramp (color_ostream &out, vector & parameters) int count = 0; int countbad = 0; + df::job_list_link* next; + for (df::job_list_link* jl = world->jobs.list.next;jl; jl = next) { + next = jl->next; + df::job* job = jl->item; + if (job->job_type != df::job_type::RemoveStairs) + continue; + df::map_block *block = Maps::getTileBlock(job->pos); + df::coord2d bpos = job->pos - block->map_pos; + df::tiletype oldT = block->tiletype[bpos.x][bpos.y]; + if (tileShape(oldT) != tiletype_shape::RAMP) + continue; + df::map_block *above = Maps::getTileBlock(job->pos + df::coord(0,0,1)); + doDeramp(block, above, bpos.x, bpos.y, oldT); + count++; + Job::removeJob(job); + } + int num_blocks = 0, blocks_total = world->map.map_blocks.size(); for (int i = 0; i < blocks_total; i++) { @@ -50,20 +87,7 @@ command_result df_deramp (color_ostream &out, vector & parameters) if ((tileShape(oldT) == tiletype_shape::RAMP) && (block->designation[x][y].bits.dig == tile_dig_designation::Default)) { - // Current tile is a ramp. - // Set current tile, as accurately as can be expected - df::tiletype newT = findSimilarTileType(oldT, tiletype_shape::FLOOR); - - // If no change, skip it (couldn't find a good tile type) - if (oldT == newT) - continue; - // Set new tile type, clear designation - block->tiletype[x][y] = newT; - block->designation[x][y].bits.dig = tile_dig_designation::No; - - // Check the tile above this one, in case a downward slope needs to be removed. - if ((above) && (tileShape(above->tiletype[x][y]) == tiletype_shape::RAMP_TOP)) - above->tiletype[x][y] = tiletype::OpenSpace; // open space + doDeramp(block, above, x, y, oldT); count++; } // ramp fixer From a38aefbe4431fed01990ac8bbf71822aeafa7a6c Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 19 Jun 2018 22:44:14 +0300 Subject: [PATCH 2/2] Changelog entry for deramp fix --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index ccbce41c6..9eed82798 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -49,6 +49,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `remove-stress`: fixed an error when running on soul-less units (e.g. with ``-all``) - `revflood`: stopped revealing tiles adjacent to tiles above open space inappropriately - `stockpiles`: ``loadstock`` sets usable and unusable weapon and armor settings +- `deramp`: Fix deramp to find designations that already have jobs posted ## Misc Improvements - Added script name to messages produced by ``qerror()`` in Lua scripts