|
|
@ -1004,6 +1004,7 @@ static InteractionData getAttacker(color_ostream& out, df::report* attackEvent,
|
|
|
|
// attack verb must match valid interaction of this attacker
|
|
|
|
// attack verb must match valid interaction of this attacker
|
|
|
|
std::string attackVerb;
|
|
|
|
std::string attackVerb;
|
|
|
|
if ( attackEvent ) {
|
|
|
|
if ( attackEvent ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
for ( size_t a = 0; a < attackers.size(); a++ ) {
|
|
|
|
for ( size_t a = 0; a < attackers.size(); a++ ) {
|
|
|
|
if ( attackers[a]->pos != attackEvent->pos ) {
|
|
|
|
if ( attackers[a]->pos != attackEvent->pos ) {
|
|
|
|
attackers.erase(attackers.begin()+a);
|
|
|
|
attackers.erase(attackers.begin()+a);
|
|
|
@ -1032,6 +1033,7 @@ static InteractionData getAttacker(color_ostream& out, df::report* attackEvent,
|
|
|
|
// defend verb must match valid interaction of some attacker
|
|
|
|
// defend verb must match valid interaction of some attacker
|
|
|
|
std::string defendVerb;
|
|
|
|
std::string defendVerb;
|
|
|
|
if ( defendEvent ) {
|
|
|
|
if ( defendEvent ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
for ( size_t a = 0; a < defenders.size(); a++ ) {
|
|
|
|
for ( size_t a = 0; a < defenders.size(); a++ ) {
|
|
|
|
if ( defenders[a]->pos != defendEvent->pos ) {
|
|
|
|
if ( defenders[a]->pos != defendEvent->pos ) {
|
|
|
|
defenders.erase(defenders.begin()+a);
|
|
|
|
defenders.erase(defenders.begin()+a);
|
|
|
@ -1050,13 +1052,16 @@ static InteractionData getAttacker(color_ostream& out, df::report* attackEvent,
|
|
|
|
|
|
|
|
|
|
|
|
//keep in mind one attacker zero defenders is perfectly valid for self-cast
|
|
|
|
//keep in mind one attacker zero defenders is perfectly valid for self-cast
|
|
|
|
if ( attackers.size() == 1 && defenders.size() == 1 && attackers[0] == defenders[0] ) {
|
|
|
|
if ( attackers.size() == 1 && defenders.size() == 1 && attackers[0] == defenders[0] ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if ( defenders.size() == 1 ) {
|
|
|
|
if ( defenders.size() == 1 ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
auto a = std::find(attackers.begin(),attackers.end(),defenders[0]);
|
|
|
|
auto a = std::find(attackers.begin(),attackers.end(),defenders[0]);
|
|
|
|
if ( a != attackers.end() )
|
|
|
|
if ( a != attackers.end() )
|
|
|
|
attackers.erase(a);
|
|
|
|
attackers.erase(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( attackers.size() == 1 ) {
|
|
|
|
if ( attackers.size() == 1 ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
auto a = std::find(defenders.begin(),defenders.end(),attackers[0]);
|
|
|
|
auto a = std::find(defenders.begin(),defenders.end(),attackers[0]);
|
|
|
|
if ( a != defenders.end() )
|
|
|
|
if ( a != defenders.end() )
|
|
|
|
defenders.erase(a);
|
|
|
|
defenders.erase(a);
|
|
|
@ -1066,13 +1071,16 @@ static InteractionData getAttacker(color_ostream& out, df::report* attackEvent,
|
|
|
|
//if trying attack-defend pair and it fails to find attacker, try defend only
|
|
|
|
//if trying attack-defend pair and it fails to find attacker, try defend only
|
|
|
|
InteractionData result = /*(InteractionData)*/ { std::string(), std::string(), -1, -1, -1, -1 };
|
|
|
|
InteractionData result = /*(InteractionData)*/ { std::string(), std::string(), -1, -1, -1, -1 };
|
|
|
|
if ( attackers.size() > 1 ) {
|
|
|
|
if ( attackers.size() > 1 ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
if ( Once::doOnce("EventManager interaction ambiguous attacker") ) {
|
|
|
|
if ( Once::doOnce("EventManager interaction ambiguous attacker") ) {
|
|
|
|
out.print("%s,%d: ambiguous attacker on report\n \'%s\'\n '%s'\n", __FILE__, __LINE__, attackEvent ? attackEvent->text.c_str() : "", defendEvent ? defendEvent->text.c_str() : "");
|
|
|
|
out.print("%s,%d: ambiguous attacker on report\n \'%s\'\n '%s'\n", __FILE__, __LINE__, attackEvent ? attackEvent->text.c_str() : "", defendEvent ? defendEvent->text.c_str() : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( attackers.size() < 1 ) {
|
|
|
|
} else if ( attackers.size() < 1 ) {
|
|
|
|
if ( defendEvent )
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
|
|
|
|
if ( attackEvent && defendEvent )
|
|
|
|
return getAttacker(out, NULL, NULL, defendEvent, relevantUnits);
|
|
|
|
return getAttacker(out, NULL, NULL, defendEvent, relevantUnits);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
//attackers.size() == 1
|
|
|
|
//attackers.size() == 1
|
|
|
|
result.attacker = attackers[0]->id;
|
|
|
|
result.attacker = attackers[0]->id;
|
|
|
|
if ( defenders.size() > 0 )
|
|
|
|
if ( defenders.size() > 0 )
|
|
|
@ -1089,6 +1097,7 @@ static InteractionData getAttacker(color_ostream& out, df::report* attackEvent,
|
|
|
|
if ( defendEvent )
|
|
|
|
if ( defendEvent )
|
|
|
|
result.defendReport = defendEvent->id;
|
|
|
|
result.defendReport = defendEvent->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1099,7 +1108,9 @@ static vector<df::unit*> gatherRelevantUnits(color_ostream& out, df::report* r1,
|
|
|
|
if ( r2 ) reports.push_back(r2);
|
|
|
|
if ( r2 ) reports.push_back(r2);
|
|
|
|
vector<df::unit*> result;
|
|
|
|
vector<df::unit*> result;
|
|
|
|
unordered_set<int32_t> ids;
|
|
|
|
unordered_set<int32_t> ids;
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
for ( size_t a = 0; a < reports.size(); a++ ) {
|
|
|
|
for ( size_t a = 0; a < reports.size(); a++ ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
vector<int32_t>& units = reportToRelevantUnits[reports[a]->id];
|
|
|
|
vector<int32_t>& units = reportToRelevantUnits[reports[a]->id];
|
|
|
|
if ( units.size() > 2 ) {
|
|
|
|
if ( units.size() > 2 ) {
|
|
|
|
if ( Once::doOnce("EventManager interaction too many relevant units") ) {
|
|
|
|
if ( Once::doOnce("EventManager interaction too many relevant units") ) {
|
|
|
@ -1112,6 +1123,7 @@ static vector<df::unit*> gatherRelevantUnits(color_ostream& out, df::report* r1,
|
|
|
|
result.push_back(df::unit::find(units[b]));
|
|
|
|
result.push_back(df::unit::find(units[b]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1149,11 +1161,14 @@ static void manageInteractionEvent(color_ostream& out) {
|
|
|
|
InteractionData data = getAttacker(out, lastAttackEvent, lastAttacker, attack ? NULL : report, relevantUnits);
|
|
|
|
InteractionData data = getAttacker(out, lastAttackEvent, lastAttacker, attack ? NULL : report, relevantUnits);
|
|
|
|
if ( data.attacker < 0 )
|
|
|
|
if ( data.attacker < 0 )
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
//if ( !attack && lastAttacker && data.attacker == lastAttacker->id && lastDefender && data.defender == lastDefender->id )
|
|
|
|
//if ( !attack && lastAttacker && data.attacker == lastAttacker->id && lastDefender && data.defender == lastDefender->id )
|
|
|
|
// continue; //lazy way of preventing duplicates
|
|
|
|
// continue; //lazy way of preventing duplicates
|
|
|
|
if ( attack && a+1 < reports.size() && reports[a+1]->type == df::announcement_type::INTERACTION_TARGET ) {
|
|
|
|
if ( attack && a+1 < reports.size() && reports[a+1]->type == df::announcement_type::INTERACTION_TARGET ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
InteractionData data2 = getAttacker(out, lastAttackEvent, lastAttacker, reports[a+1], gatherRelevantUnits(out, lastAttackEvent, reports[a+1]));
|
|
|
|
InteractionData data2 = getAttacker(out, lastAttackEvent, lastAttacker, reports[a+1], gatherRelevantUnits(out, lastAttackEvent, reports[a+1]));
|
|
|
|
if ( data.attacker == data2.attacker && (data.defender == -1 || data.defender == data2.defender) ) {
|
|
|
|
if ( data.attacker == data2.attacker && (data.defender == -1 || data.defender == data2.defender) ) {
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
data = data2;
|
|
|
|
data = data2;
|
|
|
|
a++;
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1174,6 +1189,7 @@ static void manageInteractionEvent(color_ostream& out) {
|
|
|
|
//b.insert(data.defendReport);
|
|
|
|
//b.insert(data.defendReport);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//out.print("%s,%d\n",__FILE__,__LINE__);
|
|
|
|
lastAttacker = df::unit::find(data.attacker);
|
|
|
|
lastAttacker = df::unit::find(data.attacker);
|
|
|
|
lastDefender = df::unit::find(data.defender);
|
|
|
|
lastDefender = df::unit::find(data.defender);
|
|
|
|
//fire event
|
|
|
|
//fire event
|
|
|
|