| 876 | } |
| 877 | |
| 878 | static void manageConstructionEvent(color_ostream& out) { |
| 879 | if (!df::global::world) |
| 880 | return; |
| 881 | //unordered_set<df::construction*> constructionsNow(df::global::world->event.constructions.begin(), df::global::world->event.constructions.end()); |
| 882 | |
| 883 | multimap<Plugin*, EventHandler> copy(handlers[EventType::CONSTRUCTION].begin(), handlers[EventType::CONSTRUCTION].end()); |
| 884 | |
| 885 | unordered_set<df::construction> next_construction_set; // will be swapped with constructions |
| 886 | next_construction_set.reserve(constructions.bucket_count()); |
| 887 | vector<df::construction> new_constructions; |
| 888 | |
| 889 | // find new constructions - swapping found constructions over from constructions to next_construction_set |
| 890 | for (auto c : df::global::world->event.constructions) { |
| 891 | auto &construction = *c; |
| 892 | auto it = constructions.find(construction); |
| 893 | if (it == constructions.end()) { |
| 894 | // handle new construction event later |
| 895 | new_constructions.emplace_back(construction); |
| 896 | } |
| 897 | else { |
| 898 | constructions.erase(it); |
| 899 | } |
| 900 | next_construction_set.emplace(construction); |
| 901 | } |
| 902 | |
| 903 | constructions.swap(next_construction_set); |
| 904 | |
| 905 | // now next_construction_set contains all the constructions that were removed (not found in df::global::world->event.constructions) |
| 906 | for (auto& construction : next_construction_set) { |
| 907 | // handle construction removed event |
| 908 | for (const auto &[_,handle]: copy) { |
| 909 | DEBUG(log,out).print("calling handler for destroyed construction event\n"); |
| 910 | run_handler(out, EventType::CONSTRUCTION, handle, (void*) &construction); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | // now handle all the new constructions |
| 915 | for (auto& construction : new_constructions) { |
| 916 | for (const auto &[_,handle]: copy) { |
| 917 | DEBUG(log,out).print("calling handler for created construction event\n"); |
| 918 | run_handler(out, EventType::CONSTRUCTION, handle, (void*) &construction); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | static void manageSyndromeEvent(color_ostream& out) { |
| 924 | if (!df::global::world) |