void nofAggressiveDefender::MissionAggressiveDefendingLookForNewAggressor() { // Wenns das Zielgebäude nich mehr gibt, gleich nach Hause gehen! if(!attacked_goal) { ReturnHomeMissionAggressiveDefending(); return; } /// Vermeiden, dass in FindAggressor nochmal der Soldat zum Loslaufen gezwungen wird, weil er als state // noch drinstehen hat, dass er auf einen Kampf wartet state = STATE_AGGRESSIVEDEFENDING_WALKINGTOAGGRESSOR; // nach anderen suchen, die in meiner Nähe sind und mich evtl noch mit denen kloppen if((attacker = attacked_goal ->FindAggressor(this))) { // zum Angreifer gehen und mit ihm kämpfen if(state == STATE_MEETENEMY) MeetingEnemy(); else MissAggressiveDefendingWalk(); } else { // keiner will mehr mit mir kämpfen, dann geh ich halt wieder nach Hause ReturnHomeMissionAggressiveDefending(); } }
/// Handle walking for nofActiveSoldier speciefic sates void nofActiveSoldier::Walked() { switch(state) { default: return; case STATE_WALKINGHOME: WalkingHome(); return; case STATE_MEETENEMY: MeetingEnemy(); return; } }
/// 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; }
/// Informs this soldier that another soldier starts meeting him void nofActiveSoldier::MeetEnemy(nofActiveSoldier* other, const MapPoint figh_spot) { // Remember these things enemy = other; this->fightSpot_ = figh_spot; SoldierState old_state = state; state = STATE_MEETENEMY; // In some cases we have to start walking if(old_state == STATE_ATTACKING_WAITINGAROUNDBUILDING) { MeetingEnemy(); } }
/// 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; }