| 1417 | } |
| 1418 | |
| 1419 | static void manageInteractionEvent(color_ostream& out) { |
| 1420 | if (!df::global::world) |
| 1421 | return; |
| 1422 | multimap<Plugin*,EventHandler> copy(handlers[EventType::INTERACTION].begin(), handlers[EventType::INTERACTION].end()); |
| 1423 | std::vector<df::report*>& reports = df::global::world->status.reports; |
| 1424 | size_t a = df::report::binsearch_index(reports, lastReportInteraction, false); |
| 1425 | while (a < reports.size() && reports[a]->id <= lastReportInteraction) { |
| 1426 | a++; |
| 1427 | } |
| 1428 | if ( a < reports.size() ) |
| 1429 | updateReportToRelevantUnits(); |
| 1430 | |
| 1431 | df::report* lastAttackEvent = nullptr; |
| 1432 | df::unit* lastAttacker = nullptr; |
| 1433 | //df::unit* lastDefender = NULL; |
| 1434 | unordered_map<int32_t,unordered_set<int32_t> > history; |
| 1435 | for ( ; a < reports.size(); a++ ) { |
| 1436 | df::report* report = reports[a]; |
| 1437 | lastReportInteraction = report->id; |
| 1438 | df::announcement_type type = report->type; |
| 1439 | if ( type != df::announcement_type::INTERACTION_ACTOR && type != df::announcement_type::INTERACTION_TARGET ) |
| 1440 | continue; |
| 1441 | if ( report->flags.bits.continuation ) |
| 1442 | continue; |
| 1443 | bool attack = type == df::announcement_type::INTERACTION_ACTOR; |
| 1444 | if ( attack ) { |
| 1445 | lastAttackEvent = report; |
| 1446 | lastAttacker = nullptr; |
| 1447 | //lastDefender = NULL; |
| 1448 | } |
| 1449 | vector<df::unit*> relevantUnits = gatherRelevantUnits(out, lastAttackEvent, report); |
| 1450 | InteractionData data = getAttacker(out, lastAttackEvent, lastAttacker, attack ? nullptr : report, relevantUnits); |
| 1451 | if ( data.attacker < 0 ) |
| 1452 | continue; |
| 1453 | //out.print("%s,%d\n",__FILE__,__LINE__); |
| 1454 | //if ( !attack && lastAttacker && data.attacker == lastAttacker->id && lastDefender && data.defender == lastDefender->id ) |
| 1455 | // continue; //lazy way of preventing duplicates |
| 1456 | if ( attack && a+1 < reports.size() && reports[a+1]->type == df::announcement_type::INTERACTION_TARGET ) { |
| 1457 | //out.print("%s,%d\n",__FILE__,__LINE__); |
| 1458 | vector<df::unit*> relevant_units = gatherRelevantUnits(out, lastAttackEvent, reports[a + 1]); |
| 1459 | InteractionData data2 = getAttacker(out, lastAttackEvent, lastAttacker, reports[a+1], relevant_units); |
| 1460 | if ( data.attacker == data2.attacker && (data.defender == -1 || data.defender == data2.defender) ) { |
| 1461 | //out.print("%s,%d\n",__FILE__,__LINE__); |
| 1462 | data = data2; |
| 1463 | a++; |
| 1464 | } |
| 1465 | } |
| 1466 | { |
| 1467 | #define HISTORY_ITEM 1 |
| 1468 | #if HISTORY_ITEM |
| 1469 | unordered_set<int32_t>& b = history[data.attacker]; |
| 1470 | if ( b.find(data.defender) != b.end() ) |
| 1471 | continue; |
| 1472 | history[data.attacker].insert(data.defender); |
| 1473 | //b.insert(data.defender); |
| 1474 | #else |
| 1475 | unordered_set<int32_t>& b = history[data.attackReport]; |
| 1476 | if ( b.find(data.defendReport) != b.end() ) |
nothing calls this directly
no test coverage detected