Skip to content

Commit e3a529a

Browse files
authored
Update burrow.cpp - Use Maps::forCoord; use using better
1 parent ad11f48 commit e3a529a

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

plugins/burrow.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Quickly adjust burrow tiles and units.
2+
13
#include "Core.h"
24
#include "Debug.h"
35
#include "LuaTools.h"
@@ -18,8 +20,8 @@
1820
#include "df/unit.h"
1921
#include "df/world.h"
2022

21-
using std::vector;
2223
using std::string;
24+
using std::vector;
2325
using namespace DFHack;
2426

2527
DFHACK_PLUGIN("burrow");
@@ -44,7 +46,7 @@ static void init_diggers(color_ostream& out);
4446
static void jobStartedHandler(color_ostream& out, void* ptr);
4547
static void jobCompletedHandler(color_ostream& out, void* ptr);
4648

47-
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
49+
DFhackCExport command_result plugin_init(color_ostream &out, vector<PluginCommand> &commands) {
4850
DEBUG(status, out).print("initializing %s\n", plugin_name);
4951
commands.push_back(
5052
PluginCommand("burrow",
@@ -117,7 +119,7 @@ static void init_diggers(color_ostream& out) {
117119
return;
118120
}
119121

120-
std::vector<df::job*> pvec;
122+
vector<df::job*> pvec;
121123
int start_id = 0;
122124
if (Job::listNewlyCreated(&pvec, &start_id)) {
123125
for (auto job : pvec) {
@@ -146,16 +148,12 @@ static void jobStartedHandler(color_ostream& out, void* ptr) {
146148
static void add_walls_to_burrow(color_ostream &out, df::burrow* b,
147149
const df::coord & pos1, const df::coord & pos2)
148150
{
149-
for (int z = pos1.z; z <= pos2.z; z++) {
150-
for (int y = pos1.y; y <= pos2.y; y++) {
151-
for (int x = pos1.x; x <= pos2.x; x++) {
152-
df::coord pos(x,y,z);
153-
df::tiletype *tt = Maps::getTileType(pos);
154-
if (tt && isWallTerrain(*tt))
155-
Burrows::setAssignedTile(b, pos, true);
156-
}
157-
}
158-
}
151+
Maps::forCoord([&b](df::coord pos) {
152+
auto tt = Maps::getTileType(pos);
153+
if (tt && isWallTerrain(*tt))
154+
Burrows::setAssignedTile(b, pos, true);
155+
return true; // next pos
156+
}, pos1, pos2);
159157
}
160158

161159
static void expand_burrows(color_ostream &out, const df::coord & pos, df::tiletype prev_tt, df::tiletype tt) {
@@ -327,7 +325,7 @@ static void setTilesByDesignation(df::burrow *target, df::tile_designation d_mas
327325
}
328326
}
329327

330-
static bool setTilesByKeyword(df::burrow *target, std::string name, bool enable) {
328+
static bool setTilesByKeyword(df::burrow *target, string name, bool enable) {
331329
CHECK_NULL_POINTER(target);
332330

333331
df::tile_designation mask;

0 commit comments

Comments
 (0)