MCPcopy Create free account
hub / github.com/DFHack/dfhack / getAttacker

Function getAttacker

library/modules/EventManager.cpp:1279–1391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1277}
1278
1279static InteractionData getAttacker(color_ostream& out, df::report* attackEvent, df::unit* lastAttacker, df::report* defendEvent, vector<df::unit*>& relevantUnits) {
1280 vector<df::unit*> attackers = relevantUnits;
1281 vector<df::unit*> defenders = relevantUnits;
1282
1283 //find valid interactions: TODO
1284 /*map<int32_t,vector<df::interaction*> > validInteractions;
1285 for ( size_t a = 0; a < relevantUnits.size(); a++ ) {
1286 df::unit* unit = relevantUnits[a];
1287 vector<df::interaction*>& interactions = validInteractions[unit->id];
1288 for ( size_t b = 0; b < unit->body.
1289 }*/
1290
1291 //if attackEvent
1292 // attacker must be same location
1293 // attacker name must start attack str
1294 // attack verb must match valid interaction of this attacker
1295 std::string attackVerb;
1296 if ( attackEvent ) {
1297//out.print("%s,%d\n",__FILE__,__LINE__);
1298 for ( size_t a = 0; a < attackers.size(); a++ ) {
1299 if ( attackers[a]->pos != attackEvent->pos ) {
1300 attackers.erase(attackers.begin()+a);
1301 a--;
1302 continue;
1303 }
1304 if ( lastAttacker && attackers[a] != lastAttacker ) {
1305 attackers.erase(attackers.begin()+a);
1306 a--;
1307 continue;
1308 }
1309
1310 std::string verbC = getVerb(attackers[a], attackEvent->text);
1311 if ( verbC.length() == 0 ) {
1312 attackers.erase(attackers.begin()+a);
1313 a--;
1314 continue;
1315 }
1316 attackVerb = verbC;
1317 }
1318 }
1319
1320 //if defendEvent
1321 // defender must be same location
1322 // defender name must start defend str
1323 // defend verb must match valid interaction of some attacker
1324 std::string defendVerb;
1325 if ( defendEvent ) {
1326//out.print("%s,%d\n",__FILE__,__LINE__);
1327 for ( size_t a = 0; a < defenders.size(); a++ ) {
1328 if ( defenders[a]->pos != defendEvent->pos ) {
1329 defenders.erase(defenders.begin()+a);
1330 a--;
1331 continue;
1332 }
1333 std::string verbC = getVerb(defenders[a], defendEvent->text);
1334 if ( verbC.length() == 0 ) {
1335 defenders.erase(defenders.begin()+a);
1336 a--;

Callers 1

manageInteractionEventFunction · 0.85

Calls 9

getVerbFunction · 0.85
lengthMethod · 0.80
findFunction · 0.50
sizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
printMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected