Skip to content

Commit

Permalink
Merge pull request #3948 from myk002/myk_burrow_autogrow
Browse files Browse the repository at this point in the history
[burrow] reintroduce autogrow
  • Loading branch information
myk002 authored Nov 2, 2023
2 parents c90fb81 + 940f7de commit ff052ae
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 556 deletions.
1 change: 1 addition & 0 deletions data/init/dfhack.tools.init
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

# Enable system services
enable buildingplan
enable burrow
enable confirm
enable logistics
enable overlay
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ Template for new versions:
# Future

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

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

## Fixes
- `stockpiles`: hide configure and help buttons when the overlay panel is minimized
Expand Down
45 changes: 0 additions & 45 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5612,51 +5612,6 @@ Native functions provided by the `buildingplan` plugin:
* ``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.
* ``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.

burrow
======

The `burrow` plugin implements extended burrow manipulations.

Events:

* ``onBurrowRename.foo = function(burrow)``

Emitted when a burrow might have been renamed either through
the game UI, or ``renameBurrow()``.

* ``onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype,worker)``

Emitted when a tile might have been dug out. Only tracked if the
auto-growing burrows feature is enabled.

Native functions:

* ``renameBurrow(burrow,name)``

Renames the burrow, emitting ``onBurrowRename`` and updating auto-grow state properly.

* ``findByName(burrow,name)``

Finds a burrow by name, using the same rules as the plugin command line interface.
Namely, trailing ``'+'`` characters marking auto-grow burrows are ignored.

* ``copyUnits(target,source,enable)``

Applies units from ``source`` burrow to ``target``. The ``enable``
parameter specifies if they are to be added or removed.

* ``copyTiles(target,source,enable)``

Applies tiles from ``source`` burrow to ``target``. The ``enable``
parameter specifies if they are to be added or removed.

* ``setTilesByKeyword(target,keyword,enable)``

Adds or removes tiles matching a predefined keyword. The keyword
set is the same as used by the command line.

The lua module file also re-exports functions from ``dfhack.burrows``.

.. _cxxrandom-api:

cxxrandom
Expand Down
4 changes: 3 additions & 1 deletion docs/plugins/burrow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ burrow

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

When run as a command, it can quickly adjust which tiles and/or units are
associated with the burrow.
Expand Down
25 changes: 14 additions & 11 deletions library/modules/EventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ std::array<eventManager_t,EventType::EVENT_MAX> compileManagerArray() {
//job initiated
static int32_t lastJobId = -1;

//job started
static unordered_set<int32_t> startedJobs;

//job completed
static unordered_map<int32_t, df::job*> prevJobs;

Expand Down Expand Up @@ -269,6 +272,7 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event
}
if ( event == DFHack::SC_MAP_UNLOADED ) {
lastJobId = -1;
startedJobs.clear();
for (auto &prevJob : prevJobs) {
Job::deleteJobStruct(prevJob.second, true);
}
Expand Down Expand Up @@ -461,29 +465,27 @@ static void manageJobStartedEvent(color_ostream& out) {
if (!df::global::world)
return;

static unordered_set<int32_t> startedJobs;

vector<df::job*> new_started_jobs;
// iterate event handler callbacks
multimap<Plugin*, EventHandler> copy(handlers[EventType::JOB_STARTED].begin(), handlers[EventType::JOB_STARTED].end());

unordered_set<int32_t> newStartedJobs;

for (df::job_list_link* link = &df::global::world->jobs.list; link->next != nullptr; link = link->next) {
df::job* job = link->next->item;
if (!job || !Job::getWorker(job))
continue;

int32_t j_id = job->id;
if (job && Job::getWorker(job) && !startedJobs.count(job->id)) {
startedJobs.emplace(job->id);
newStartedJobs.emplace(j_id);
if (!startedJobs.count(j_id)) {
for (auto &[_,handle] : copy) {
// the jobs must have a worker to start
DEBUG(log,out).print("calling handler for job started event\n");
handle.eventHandler(out, job);
}
}
if (link->next == nullptr || link->next->item->id != j_id) {
if ( Once::doOnce("EventManager jobstarted job removed") ) {
out.print("%s,%d: job %u removed from jobs linked list\n", __FILE__, __LINE__, j_id);
}
}
}

startedJobs = newStartedJobs;
}

//helper function for manageJobCompletedEvent
Expand All @@ -498,6 +500,7 @@ TODO: consider checking item creation / experience gain just in case
static void manageJobCompletedEvent(color_ostream& out) {
if (!df::global::world)
return;

int32_t tick0 = eventLastTick[EventType::JOB_COMPLETED];
int32_t tick1 = df::global::world->frame_counter;

Expand Down
Loading

0 comments on commit ff052ae

Please sign in to comment.