/// Looks for enemies nearby which want to fight with this soldier /// Returns true if it found one bool nofActiveSoldier::FindEnemiesNearby(unsigned char excludedOwner) { RTTR_Assert(enemy == NULL); enemy = NULL; // Get all points in a radius of 2 std::vector<MapPoint> pts = gwg->GetPointsInRadius(pos, 2); // Don't forget own position pts.insert(pts.begin(), pos); for(std::vector<MapPoint>::const_iterator itPos = pts.begin(); itPos != pts.end(); ++itPos) { std::vector<noBase*> objects = gwg->GetDynamicObjectsFrom(*itPos); for(std::vector<noBase*>::iterator it = objects.begin(); it != objects.end(); ++it) { nofActiveSoldier* soldier = dynamic_cast<nofActiveSoldier*>(*it); if (!soldier || soldier->GetPlayer() == excludedOwner) continue; if (soldier->IsReadyForFight() && !gwg->GetPlayer(soldier->GetPlayer()).IsAlly(player)) { enemy = soldier; break; } } if(enemy) break; } // No enemy found? Goodbye if(!enemy) return false; // Try to find fighting spot if(excludedOwner==255) { if(!GetFightSpotNear(enemy, &fightSpot_)) { // No success? Then no fight enemy = NULL; return false; } } else//we have an excluded owner for our new enemy and that only happens in ffa situations when we won against the last defender so our fightspot is the exact location we have right now { fightSpot_ = pos; } // We try to meet us now state = STATE_MEETENEMY; // Inform the other soldier enemy->MeetEnemy(this, fightSpot_); // Walk to him MeetingEnemy(); return true; }
/// Looks for enemies nearby which want to fight with this soldier /// Returns true if it found one bool nofActiveSoldier::FindEnemiesNearby(unsigned char excludedOwner) { // Vector with potential victims std::vector<nofActiveSoldier*> soldiersNearby; // Look in radius 1 for(unsigned dir = 0; dir < 6; ++dir) { MapPoint t = gwg->GetNeighbour(pos, dir); std::vector<noBase*> objects = gwg->GetDynamicObjectsFrom(t); for(std::vector<noBase*>::iterator it = objects.begin(); it != objects.end(); ++it) if (dynamic_cast<nofActiveSoldier*>(*it) && dynamic_cast<nofActiveSoldier*>(*it)->GetPlayer()!=excludedOwner) soldiersNearby.push_back(dynamic_cast<nofActiveSoldier*>(*it)); } // ... and radius 2 for(unsigned dir = 0; dir < 12; ++dir) { MapPoint t = gwg->GetNeighbour2(pos, dir); std::vector<noBase*> objects = gwg->GetDynamicObjectsFrom(t); for(std::vector<noBase*>::iterator it = objects.begin(); it != objects.end(); ++it) if (dynamic_cast<nofActiveSoldier*>(*it) && dynamic_cast<nofActiveSoldier*>(*it)->GetPlayer()!=excludedOwner) soldiersNearby.push_back(dynamic_cast<nofActiveSoldier*>(*it)); } enemy = NULL; // Check if the victims have nothing better to do for(unsigned i = 0; i < soldiersNearby.size(); ++i) { // Ready for fight and good enemy = Good victim if (soldiersNearby[i]->IsReadyForFight() && !GAMECLIENT.GetPlayer(soldiersNearby[i]->GetPlayer()).IsAlly(this->player)) { enemy = soldiersNearby[i]; break; } } // No enemy found? Goodbye if(!enemy) return false; // Try to find fighting spot if(excludedOwner==255) { if(!GetFightSpotNear(enemy, &fightSpot_)) // No success? Then no fight return false; } else//we have an excluded owner for our new enemy and that only happens in ffa situations when we won against the last defender so our fightspot is the exact location we have right now { fightSpot_ = pos; } // We try to meet us now state = STATE_MEETENEMY; // Inform the other soldier enemy->MeetEnemy(this, fightSpot_); // Walk to him MeetingEnemy(); return true; }