Made EQUIPMENT_CHANGE event trigger for new units.

develop
expwnent 2014-07-03 08:10:12 -04:00
parent 9d2c7a1abc
commit d8c3a05f42
1 changed files with 48 additions and 40 deletions

@ -679,8 +679,15 @@ static void manageEquipmentEvent(color_ostream& out) {
*/
auto oldEquipment = equipmentLog.find(unit->id);
if ( oldEquipment != equipmentLog.end() ) {
vector<InventoryItem>& v = (*oldEquipment).second;
bool hadEquipment = oldEquipment != equipmentLog.end();
vector<InventoryItem>* temp;
if ( hadEquipment ) {
temp = &((*oldEquipment).second);
} else {
temp = new vector<InventoryItem>;
}
//vector<InventoryItem>& v = (*oldEquipment).second;
vector<InventoryItem>& v = *temp;
for ( auto b = v.begin(); b != v.end(); b++ ) {
InventoryItem& i = *b;
itemIdToInventoryItem[i.itemId] = i;
@ -713,6 +720,8 @@ static void manageEquipmentEvent(color_ostream& out) {
handle.eventHandler(out, (void*)&data);
}
}
if ( !hadEquipment )
delete temp;
//check for dropped items
for ( auto b = v.begin(); b != v.end(); b++ ) {
InventoryItem i = *b;
@ -725,7 +734,6 @@ static void manageEquipmentEvent(color_ostream& out) {
handle.eventHandler(out, (void*)&data);
}
}
}
//update equipment
vector<InventoryItem>& equipment = equipmentLog[unit->id];