Skip to content

Commit 838acfd

Browse files
committed
Adds a few log lines to dig-now
1 parent 456020f commit 838acfd

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

plugins/dig-now.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "PluginManager.h"
77
#include "TileTypes.h"
88
#include "LuaTools.h"
9+
#include "Debug.h"
910

1011
#include "modules/Buildings.h"
1112
#include "modules/Gui.h"
@@ -26,10 +27,23 @@
2627
#include <df/world.h>
2728
#include <df/world_site.h>
2829

30+
#include <cinttypes>
31+
2932
DFHACK_PLUGIN("dig-now");
3033
REQUIRE_GLOBAL(plotinfo);
3134
REQUIRE_GLOBAL(world);
3235

36+
// Debugging
37+
namespace DFHack {
38+
DBG_DECLARE(dignow, general, DebugCategory::LINFO);
39+
DBG_DECLARE(dignow, channels, DebugCategory::LINFO);
40+
}
41+
42+
#define COORD "%" PRIi16 " %" PRIi16 " %" PRIi16
43+
#define COORDARGS(id) id.x, id.y, id.z
44+
45+
// todo: integrate logging for debugging the layered channel problem
46+
3347
using namespace DFHack;
3448

3549
struct boulder_percent_options {
@@ -321,10 +335,19 @@ static bool dig_tile(color_ostream &out, MapExtras::MapCache &map,
321335
df::tiletype tt = map.tiletypeAt(pos);
322336

323337
if (!is_diggable(map, pos, tt)) {
324-
out.print("dig_tile: not diggable\n");
338+
DEBUG(general).print("dig_tile: not diggable\n");
325339
return false;
326340
}
327341

342+
/** The algorithm process seems to be:
343+
* for each tile
344+
* check for a designation
345+
* if a designation exists send it to dig_tile
346+
*
347+
* dig_tile (below) then digs the layer below the channel designated tile
348+
* thereby changing it and causing its designation to be lost
349+
* */
350+
328351
df::tiletype target_type = df::tiletype::Void;
329352
switch(designation) {
330353
case df::tile_dig_designation::Default:
@@ -344,6 +367,7 @@ static bool dig_tile(color_ostream &out, MapExtras::MapCache &map,
344367
// todo: does can_dig_channel return false?
345368
if (can_dig_channel(tt) && map.ensureBlockAt(pos_below)
346369
&& is_diggable(map, pos_below, map.tiletypeAt(pos_below))) {
370+
TRACE(channels).print("dig_tile: channeling at (" COORD ")\n",COORDARGS(pos_below));
347371
target_type = df::tiletype::OpenSpace;
348372
DFCoord pos_above(pos.x, pos.y, pos.z+1);
349373
if (map.ensureBlockAt(pos_above)) {
@@ -360,6 +384,8 @@ static bool dig_tile(color_ostream &out, MapExtras::MapCache &map,
360384
}
361385
return true;
362386
}
387+
} else {
388+
DEBUG(channels).print("dig_tile: failed to channel at (" COORD ")\n", COORDARGS(pos_below));
363389
}
364390
break;
365391
}
@@ -414,6 +440,7 @@ static bool dig_tile(color_ostream &out, MapExtras::MapCache &map,
414440
return false;
415441

416442
dug_tiles.emplace_back(map, pos);
443+
TRACE(general).print("dig_tile: digging the designation tile at (" COORD ")\n",COORDARGS(pos));
417444
dig_type(map, pos, target_type);
418445

419446
// let light filter down to newly exposed tiles
@@ -613,6 +640,8 @@ static void do_dig(color_ostream &out, std::vector<DFCoord> &dug_coords,
613640
continue;
614641

615642
// todo: check if tile is in the job list with a dig type
643+
// todo: if it is cancel the job. Then check if the designation is removed on the map
644+
// todo: if the designation does disappear on the map, just rewrite things to queue the designation info that needs to be processed
616645

617646
DFCoord pos(x, y, z);
618647
df::tile_designation td = map.designationAt(pos);

0 commit comments

Comments
 (0)