MCPcopy Create free account
hub / github.com/DFHack/dfhack / manageItemCreationEvent

Function manageItemCreationEvent

library/modules/EventManager.cpp:783–826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

781}
782
783static void manageItemCreationEvent(color_ostream& out) {
784 if (!df::global::world)
785 return;
786 if (!df::global::item_next_id)
787 return;
788 if ( nextItem >= *df::global::item_next_id ) {
789 return;
790 }
791
792 multimap<Plugin*,EventHandler> copy(handlers[EventType::ITEM_CREATED].begin(), handlers[EventType::ITEM_CREATED].end());
793 size_t index = df::item::binsearch_index(df::global::world->items.all, nextItem, false);
794 if ( index != 0 ) index--;
795
796 std::vector<int32_t> created_items;
797 for ( size_t a = index; a < df::global::world->items.all.size(); a++ ) {
798 df::item* item = df::global::world->items.all[a];
799 //already processed
800 if ( item->id < nextItem )
801 continue;
802 //invaders
803 if ( item->flags.bits.foreign )
804 continue;
805 //traders who bring back your items?
806 if ( item->flags.bits.trader )
807 continue;
808 //migrants
809 if ( item->flags.bits.owned )
810 continue;
811 //spider webs don't count
812 if ( item->flags.bits.spider_web )
813 continue;
814 created_items.push_back(item->id);
815 }
816
817 // handle all created items
818 for (int32_t item_id : created_items) {
819 for (auto &[_,handle] : copy) {
820 DEBUG(log,out).print("calling handler for item created event\n");
821 run_handler(out, EventType::ITEM_CREATED, handle, (void*)intptr_t(item_id));
822 }
823 }
824
825 nextItem = *df::global::item_next_id;
826}
827
828static void manageBuildingEvent(color_ostream& out) {
829 if (!df::global::world)

Callers

nothing calls this directly

Calls 6

binsearch_indexFunction · 0.85
run_handlerFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected