diff --git a/docs/changelog.txt b/docs/changelog.txt index 1302cf82e..4aa3e85c9 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## New Tweaks ## Fixes +- `eventful`: fixed UNIT_NEW_ACTIVE event firing too often - ``widgets.CycleHotkeyLabel``: allow initial option values to be specified as an index instead of an option value - ``job.removeJob()``: fixes regression in DFHack 0.47.05-r5 where items/buildings associated with the job were not getting disassociated when the job is removed. Now `build-now` can build buildings and `gui/mass-remove` can cancel building deconstruction again - `eventful`: fix ``eventful.registerReaction`` to correctly pass ``call_native`` argument thus allowing canceling vanilla item creation. Updated related documentation. @@ -49,6 +50,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `dfhack-examples-guide`: reduce required stock of dye for "Dye cloth" orders - `dfhack-examples-guide`: fix material conditions for making jugs and pots - `dfhack-examples-guide`: make wooden jugs by default to differentiate them from other stone tools. this allows players to more easily select jugs out with a properly-configured stockpile (i.e. the new ``woodentools`` alias) +- `eventful`: renamed NEW_UNIT_ACTIVE event to UNIT_NEW_ACTIVE to match the ``EventManager`` event name - `quickfort-alias-guide`: new aliases: ``forbidsearch``, ``permitsearch``, and ``togglesearch`` use the `search-plugin` plugin to alter the settings for a filtered list of item types when configuring stockpiles - `quickfort-alias-guide`: new aliases: ``stonetools`` and ``woodentools``. the ``jugs`` alias is deprecated. please use ``stonetools`` instead, which is the same as the old ``jugs`` alias. - `quickfort-alias-guide`: new aliases: ``usablehair``, ``permitusablehair``, and ``forbidusablehair`` alter settings for the types of hair/wool that can be made into cloth: sheep, llama, alpaca, and troll. The ``craftrefuse`` aliases have been altered to use this alias as well. diff --git a/library/modules/EventManager.cpp b/library/modules/EventManager.cpp index 70908aada..5d2a24ad0 100644 --- a/library/modules/EventManager.cpp +++ b/library/modules/EventManager.cpp @@ -199,6 +199,9 @@ static int32_t lastJobId = -1; //job completed static unordered_map prevJobs; +//active units +static unordered_set activeUnits; + //unit death static unordered_set livingUnits; @@ -256,6 +259,7 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event buildings.clear(); constructions.clear(); equipmentLog.clear(); + activeUnits.clear(); Buildings::clearBuildings(out); lastReport = -1; @@ -314,6 +318,9 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event } lastSyndromeTime = -1; for (auto unit : df::global::world->units.all) { + if (Units::isActive(unit)) { + activeUnits.emplace(unit->id); + } for (auto syndrome : unit->syndromes.active) { int32_t startTime = syndrome->year*ticksPerYear + syndrome->year_time; if ( startTime > lastSyndromeTime ) @@ -592,7 +599,6 @@ static void manageNewUnitActiveEvent(color_ostream& out) { if (!df::global::world) return; - static unordered_set activeUnits; multimap copy(handlers[EventType::UNIT_NEW_ACTIVE].begin(), handlers[EventType::UNIT_NEW_ACTIVE].end()); // iterate event handler callbacks for (auto &key_value : copy) { @@ -600,6 +606,7 @@ static void manageNewUnitActiveEvent(color_ostream& out) { for (df::unit* unit : df::global::world->units.active) { int32_t id = unit->id; if (!activeUnits.count(id)) { + activeUnits.emplace(id); handler.eventHandler(out, (void*) intptr_t(id)); // intptr_t() avoids cast from smaller type warning } } diff --git a/plugins/lua/eventful.lua b/plugins/lua/eventful.lua index b1520dac1..1e3170c45 100644 --- a/plugins/lua/eventful.lua +++ b/plugins/lua/eventful.lua @@ -154,7 +154,7 @@ eventType=invertTable{ "JOB_INITIATED", "JOB_STARTED", "JOB_COMPLETED", - "NEW_UNIT_ACTIVE", + "UNIT_NEW_ACTIVE", "UNIT_DEATH", "ITEM_CREATED", "BUILDING",