Skip to content

Commit ff052ae

Browse files
authored
Merge pull request #3948 from myk002/myk_burrow_autogrow
[burrow] reintroduce autogrow
2 parents c90fb81 + 940f7de commit ff052ae

File tree

7 files changed

+141
-556
lines changed

7 files changed

+141
-556
lines changed

data/init/dfhack.tools.init

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080

8181
# Enable system services
8282
enable buildingplan
83+
enable burrow
8384
enable confirm
8485
enable logistics
8586
enable overlay

docs/changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ Template for new versions:
5252
# Future
5353

5454
## New Tools
55+
- `burrow`: (reinstated) automatically expand burrows as you dig
5556

5657
## New Features
5758
- `prospect`: can now give you an estimate of resources from the embark screen. hover the mouse over a potential embark area and run `prospect`.
59+
- `burrow`: integrated 3d box fill and 2d/3d flood fill extensions for burrow painting mode
5860

5961
## Fixes
6062
- `stockpiles`: hide configure and help buttons when the overlay panel is minimized

docs/dev/Lua API.rst

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,51 +5612,6 @@ Native functions provided by the `buildingplan` plugin:
56125612
* ``void doCycle()`` runs a check for whether buildings in the monitor list can be assigned items and unsuspended. This method runs automatically twice a game day, so you only need to call it directly if you want buildingplan to do a check right now.
56135613
* ``void scheduleCycle()`` schedules a cycle to be run during the next non-paused game frame. Can be called multiple times while the game is paused and only one cycle will be scheduled.
56145614

5615-
burrow
5616-
======
5617-
5618-
The `burrow` plugin implements extended burrow manipulations.
5619-
5620-
Events:
5621-
5622-
* ``onBurrowRename.foo = function(burrow)``
5623-
5624-
Emitted when a burrow might have been renamed either through
5625-
the game UI, or ``renameBurrow()``.
5626-
5627-
* ``onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype,worker)``
5628-
5629-
Emitted when a tile might have been dug out. Only tracked if the
5630-
auto-growing burrows feature is enabled.
5631-
5632-
Native functions:
5633-
5634-
* ``renameBurrow(burrow,name)``
5635-
5636-
Renames the burrow, emitting ``onBurrowRename`` and updating auto-grow state properly.
5637-
5638-
* ``findByName(burrow,name)``
5639-
5640-
Finds a burrow by name, using the same rules as the plugin command line interface.
5641-
Namely, trailing ``'+'`` characters marking auto-grow burrows are ignored.
5642-
5643-
* ``copyUnits(target,source,enable)``
5644-
5645-
Applies units from ``source`` burrow to ``target``. The ``enable``
5646-
parameter specifies if they are to be added or removed.
5647-
5648-
* ``copyTiles(target,source,enable)``
5649-
5650-
Applies tiles from ``source`` burrow to ``target``. The ``enable``
5651-
parameter specifies if they are to be added or removed.
5652-
5653-
* ``setTilesByKeyword(target,keyword,enable)``
5654-
5655-
Adds or removes tiles matching a predefined keyword. The keyword
5656-
set is the same as used by the command line.
5657-
5658-
The lua module file also re-exports functions from ``dfhack.burrows``.
5659-
56605615
.. _cxxrandom-api:
56615616

56625617
cxxrandom

docs/plugins/burrow.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ burrow
77

88
This tool has two modes. When enabled, it monitors burrows with names that end
99
in ``+``. If a wall at the edge of such a burrow is dug out, the burrow will be
10-
automatically extended to include the newly-revealed adjacent walls.
10+
automatically extended to include the newly-revealed adjacent walls. If a miner
11+
digs into an open space, such as a cavern, the open space will *not* be
12+
included in the burrow.
1113

1214
When run as a command, it can quickly adjust which tiles and/or units are
1315
associated with the burrow.

library/modules/EventManager.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ std::array<eventManager_t,EventType::EVENT_MAX> compileManagerArray() {
206206
//job initiated
207207
static int32_t lastJobId = -1;
208208

209+
//job started
210+
static unordered_set<int32_t> startedJobs;
211+
209212
//job completed
210213
static unordered_map<int32_t, df::job*> prevJobs;
211214

@@ -269,6 +272,7 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event
269272
}
270273
if ( event == DFHack::SC_MAP_UNLOADED ) {
271274
lastJobId = -1;
275+
startedJobs.clear();
272276
for (auto &prevJob : prevJobs) {
273277
Job::deleteJobStruct(prevJob.second, true);
274278
}
@@ -461,29 +465,27 @@ static void manageJobStartedEvent(color_ostream& out) {
461465
if (!df::global::world)
462466
return;
463467

464-
static unordered_set<int32_t> startedJobs;
465-
466-
vector<df::job*> new_started_jobs;
467468
// iterate event handler callbacks
468469
multimap<Plugin*, EventHandler> copy(handlers[EventType::JOB_STARTED].begin(), handlers[EventType::JOB_STARTED].end());
469470

471+
unordered_set<int32_t> newStartedJobs;
472+
470473
for (df::job_list_link* link = &df::global::world->jobs.list; link->next != nullptr; link = link->next) {
471474
df::job* job = link->next->item;
475+
if (!job || !Job::getWorker(job))
476+
continue;
477+
472478
int32_t j_id = job->id;
473-
if (job && Job::getWorker(job) && !startedJobs.count(job->id)) {
474-
startedJobs.emplace(job->id);
479+
newStartedJobs.emplace(j_id);
480+
if (!startedJobs.count(j_id)) {
475481
for (auto &[_,handle] : copy) {
476-
// the jobs must have a worker to start
477482
DEBUG(log,out).print("calling handler for job started event\n");
478483
handle.eventHandler(out, job);
479484
}
480485
}
481-
if (link->next == nullptr || link->next->item->id != j_id) {
482-
if ( Once::doOnce("EventManager jobstarted job removed") ) {
483-
out.print("%s,%d: job %u removed from jobs linked list\n", __FILE__, __LINE__, j_id);
484-
}
485-
}
486486
}
487+
488+
startedJobs = newStartedJobs;
487489
}
488490

489491
//helper function for manageJobCompletedEvent
@@ -498,6 +500,7 @@ TODO: consider checking item creation / experience gain just in case
498500
static void manageJobCompletedEvent(color_ostream& out) {
499501
if (!df::global::world)
500502
return;
503+
501504
int32_t tick0 = eventLastTick[EventType::JOB_COMPLETED];
502505
int32_t tick1 = df::global::world->frame_counter;
503506

0 commit comments

Comments
 (0)