|  |  | @ -114,7 +114,7 @@ static void manageBuildingEvent(color_ostream& out); | 
			
		
	
		
		
			
				
					
					|  |  |  | static void manageConstructionEvent(color_ostream& out); |  |  |  | static void manageConstructionEvent(color_ostream& out); | 
			
		
	
		
		
			
				
					
					|  |  |  | static void manageSyndromeEvent(color_ostream& out); |  |  |  | static void manageSyndromeEvent(color_ostream& out); | 
			
		
	
		
		
			
				
					
					|  |  |  | static void manageInvasionEvent(color_ostream& out); |  |  |  | static void manageInvasionEvent(color_ostream& out); | 
			
		
	
		
		
			
				
					
					|  |  |  | //static void manageEquipmentEvent(color_ostream& out);
 |  |  |  | static void manageEquipmentEvent(color_ostream& out); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | typedef void (*eventManager_t)(color_ostream&); |  |  |  | typedef void (*eventManager_t)(color_ostream&); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -128,7 +128,7 @@ static const eventManager_t eventManager[] = { | 
			
		
	
		
		
			
				
					
					|  |  |  |     manageConstructionEvent, |  |  |  |     manageConstructionEvent, | 
			
		
	
		
		
			
				
					
					|  |  |  |     manageSyndromeEvent, |  |  |  |     manageSyndromeEvent, | 
			
		
	
		
		
			
				
					
					|  |  |  |     manageInvasionEvent, |  |  |  |     manageInvasionEvent, | 
			
		
	
		
		
			
				
					
					|  |  |  | //    manageEquipmentEvent,
 |  |  |  |     manageEquipmentEvent, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | }; |  |  |  | }; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | //job initiated
 |  |  |  | //job initiated
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -159,6 +159,7 @@ static int32_t nextInvasion; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | //equipment change
 |  |  |  | //equipment change
 | 
			
		
	
		
		
			
				
					
					|  |  |  | //static unordered_map<int32_t, vector<df::unit_inventory_item> > equipmentLog;
 |  |  |  | //static unordered_map<int32_t, vector<df::unit_inventory_item> > equipmentLog;
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | static unordered_map<int32_t, vector<InventoryItem> > equipmentLog; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event event) { |  |  |  | void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event event) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     static bool doOnce = false; |  |  |  |     static bool doOnce = false; | 
			
		
	
	
		
		
			
				
					|  |  | @ -181,10 +182,10 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event | 
			
		
	
		
		
			
				
					
					|  |  |  |         livingUnits.clear(); |  |  |  |         livingUnits.clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         buildings.clear(); |  |  |  |         buildings.clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         constructions.clear(); |  |  |  |         constructions.clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         equipmentLog.clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         Buildings::clearBuildings(out); |  |  |  |         Buildings::clearBuildings(out); | 
			
		
	
		
		
			
				
					
					|  |  |  |         gameLoaded = false; |  |  |  |         gameLoaded = false; | 
			
		
	
		
		
			
				
					
					|  |  |  | //        equipmentLog.clear();
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } else if ( event == DFHack::SC_MAP_LOADED ) { |  |  |  |     } else if ( event == DFHack::SC_MAP_LOADED ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         /*
 |  |  |  |         /*
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         int32_t tick = df::global::world->frame_counter; |  |  |  |         int32_t tick = df::global::world->frame_counter; | 
			
		
	
	
		
		
			
				
					|  |  | @ -623,43 +624,76 @@ static void manageInvasionEvent(color_ostream& out) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | /*
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | static void manageEquipmentEvent(color_ostream& out) { |  |  |  | static void manageEquipmentEvent(color_ostream& out) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     multimap<Plugin*,EventHandler> copy(handlers[EventType::EQUIPMENT_CHANGE].begin(), handlers[EventType::EQUIPMENT_CHANGE].end()); |  |  |  |     multimap<Plugin*,EventHandler> copy(handlers[EventType::INVENTORY_CHANGE].begin(), handlers[EventType::INVENTORY_CHANGE].end()); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     unordered_map<int32_t, InventoryItem> itemIdToInventoryItem; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     unordered_set<int32_t> currentlyEquipped; | 
			
		
	
		
		
			
				
					
					|  |  |  |     for ( auto a = df::global::world->units.all.begin(); a != df::global::world->units.all.end(); a++ ) { |  |  |  |     for ( auto a = df::global::world->units.all.begin(); a != df::global::world->units.all.end(); a++ ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         itemIdToInventoryItem.clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         currentlyEquipped.clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         df::unit* unit = *a; |  |  |  |         df::unit* unit = *a; | 
			
		
	
		
		
			
				
					
					|  |  |  |         if ( unit->flags1.bits.dead ) |  |  |  |         /*if ( unit->flags1.bits.dead )
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             continue; |  |  |  |             continue; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         */ | 
			
		
	
		
		
			
				
					
					|  |  |  |          |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |         bool isNew = equipmentLog.find(unit->id) == equipmentLog.end(); |  |  |  |         auto oldEquipment = equipmentLog.find(unit->id); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         bool needsUpdate = isNew || equipmentLog[unit->id].size() != unit->inventory.size(); |  |  |  |         if ( oldEquipment != equipmentLog.end() ) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if ( !needsUpdate ) { |  |  |  |             vector<InventoryItem>& v = (*oldEquipment).second; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             for ( auto b = v.begin(); b != v.end(); b++ ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 InventoryItem& i = *b; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 itemIdToInventoryItem[i.itemId] = i; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             for ( size_t b = 0; b < unit->inventory.size(); b++ ) { |  |  |  |             for ( size_t b = 0; b < unit->inventory.size(); b++ ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 df::unit_inventory_item* item = unit->inventory[b]; |  |  |  |                 df::unit_inventory_item* dfitem_new = unit->inventory[b]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 df::unit_inventory_item& old = equipmentLog[unit->id][b]; |  |  |  |                 currentlyEquipped.insert(dfitem_new->item->id); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 if ( item->item == old.item && item->mode == old.mode && item->body_part_id == old.body_part_id && item->anon_1 == old.anon_1 && item->wound_id == old->wound_id ) |  |  |  |                 InventoryItem item_new(dfitem_new->item->id, *dfitem_new); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 auto c = itemIdToInventoryItem.find(dfitem_new->item->id); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 if ( c == itemIdToInventoryItem.end() ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     //new item equipped (probably just picked up)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     InventoryChangeData data(unit->id, NULL, &item_new); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     for ( auto h = copy.begin(); h != copy.end(); h++ ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         EventHandler handle = (*h).second; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         handle.eventHandler(out, (void*)&data); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                     continue; |  |  |  |                     continue; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 InventoryItem item_old = (*c).second; | 
			
		
	
		
		
			
				
					
					|  |  |  |                  |  |  |  |                  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 needsUpdate = true; |  |  |  |                 df::unit_inventory_item& item0 = item_old.item; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 break; |  |  |  |                 df::unit_inventory_item& item1 = item_new.item; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 if ( item0.mode == item1.mode && item0.body_part_id == item1.body_part_id && item0.wound_id == item1.wound_id ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     continue; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 //some sort of change in how it's equipped
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                  | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 InventoryChangeData data(unit->id, &item_old, &item_new); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 for ( auto h = copy.begin(); h != copy.end(); h++ ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     EventHandler handle = (*h).second; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     handle.eventHandler(out, (void*)&data); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |          |  |  |  |             //check for dropped items
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if ( needsUpdate && !isNew ) { |  |  |  |             for ( auto b = v.begin(); b != v.end(); b++ ) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             for ( auto c = copy.begin(); c != copy.end(); c++ ) { |  |  |  |                 InventoryItem i = *b; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 EventHandler handle = (*c).second; |  |  |  |                 if ( currentlyEquipped.find(i.itemId) != currentlyEquipped.end() ) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     continue; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 //TODO: delete ptr if invalid
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 InventoryChangeData data(unit->id, &i, NULL); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 for ( auto h = copy.begin(); h != copy.end(); h++ ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     EventHandler handle = (*h).second; | 
			
		
	
		
		
			
				
					
					|  |  |  |                     handle.eventHandler(out, (void*)&data); |  |  |  |                     handle.eventHandler(out, (void*)&data); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |          |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |         if ( needsUpdate ) { |  |  |  |         //update equipment
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             equipmentLog[unit->id].clear(); |  |  |  |         vector<InventoryItem>& equipment = equipmentLog[unit->id]; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         equipment.clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         for ( size_t b = 0; b < unit->inventory.size(); b++ ) { |  |  |  |         for ( size_t b = 0; b < unit->inventory.size(); b++ ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 equipmentLog[unit->id].push_back(* unit->inventory[b]); |  |  |  |             df::unit_inventory_item* dfitem = unit->inventory[b]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             InventoryItem item(dfitem->item->id, *dfitem); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             equipment.push_back(item); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | */ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |