Fix UNIT_NEW_ACTIVE events (#2197)

* Updates eventful.lua to use UNIT_NEW_ACTIVE

* Fixes bug #2189

* Revises activeUnits declaration/initialization

* Fixes build error

* Update changelog.txt

* reword changelog entry

* add changelog entry for event name change

Co-authored-by: Myk <myk002@yahoo.com>
develop
Josh Cooper 2022-06-17 09:34:41 -07:00 committed by GitHub
parent ae5b00523e
commit d38ab1d152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

@ -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.

@ -199,6 +199,9 @@ static int32_t lastJobId = -1;
//job completed
static unordered_map<int32_t, df::job*> prevJobs;
//active units
static unordered_set<int32_t> activeUnits;
//unit death
static unordered_set<int32_t> 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<int32_t> activeUnits;
multimap<Plugin*,EventHandler> 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
}
}

@ -154,7 +154,7 @@ eventType=invertTable{
"JOB_INITIATED",
"JOB_STARTED",
"JOB_COMPLETED",
"NEW_UNIT_ACTIVE",
"UNIT_NEW_ACTIVE",
"UNIT_DEATH",
"ITEM_CREATED",
"BUILDING",