private void DefendCenterLocation()
 {
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f);
         BehaviorDefendSiegeWeapon behavior = this._mainInfantry.AI.GetBehavior <BehaviorDefendSiegeWeapon>();
         behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(FormationAI.BehaviorSide.Middle).ToWorldPosition());
         behavior.SetDefendedSiegeWeaponFromTactic(this._teamAISallyOutDefender.PrimarySiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(psw => psw is IPrimarySiegeWeapon && (psw as IPrimarySiegeWeapon).WeaponSide == FormationAI.BehaviorSide.Middle)));
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
     }
     if (this._archers != null)
     {
         this._archers.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._archers);
         this._archers.AI.SetBehaviorWeight <BehaviorSkirmishLine>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorScreenedSkirmish>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorSkirmish>(1f);
     }
     if (this._leftCavalry != null)
     {
         this._leftCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._leftCavalry);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f);
         BehaviorDefendSiegeWeapon behavior = this._leftCavalry.AI.GetBehavior <BehaviorDefendSiegeWeapon>();
         behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(FormationAI.BehaviorSide.Left).ToWorldPosition());
         behavior.SetDefendedSiegeWeaponFromTactic(this._teamAISallyOutDefender.PrimarySiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(psw => psw is IPrimarySiegeWeapon && (psw as IPrimarySiegeWeapon).WeaponSide == FormationAI.BehaviorSide.Left)));
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
         BehaviorProtectFlank behaviorProtectFlank = this._leftCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f);
         behaviorProtectFlank.FlankSide = FormationAI.BehaviorSide.Left;
         this._leftCavalry.AI.AddSpecialBehavior((BehaviorComponent)behaviorProtectFlank, true);
     }
     if (this._rightCavalry != null)
     {
         this._rightCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._rightCavalry);
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f);
         BehaviorDefendSiegeWeapon behavior = this._rightCavalry.AI.GetBehavior <BehaviorDefendSiegeWeapon>();
         behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(FormationAI.BehaviorSide.Right).ToWorldPosition());
         behavior.SetDefendedSiegeWeaponFromTactic(this._teamAISallyOutDefender.PrimarySiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(psw => psw is IPrimarySiegeWeapon && (psw as IPrimarySiegeWeapon).WeaponSide == FormationAI.BehaviorSide.Right)));
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
         BehaviorProtectFlank behaviorProtectFlank = this._leftCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f);
         behaviorProtectFlank.FlankSide = FormationAI.BehaviorSide.Right;
         this._rightCavalry.AI.AddSpecialBehavior((BehaviorComponent)behaviorProtectFlank, true);
     }
     if (this._rangedCavalry == null)
     {
         return;
     }
     this._rangedCavalry.AI.ResetBehaviorWeights();
     TacticComponent.SetDefaultBehaviorWeights(this._rangedCavalry);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorMountedSkirmish>(1f);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorHorseArcherSkirmish>(1f);
 }
 private void DefendSingleMainPosition()
 {
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
         if (this._destructableSiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon)) is IPrimarySiegeWeapon primarySiegeWeapon2)
         {
             this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f);
             BehaviorDefendSiegeWeapon behavior = this._mainInfantry.AI.GetBehavior <BehaviorDefendSiegeWeapon>();
             behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(primarySiegeWeapon2.WeaponSide).ToWorldPosition());
             behavior.SetDefendedSiegeWeaponFromTactic(primarySiegeWeapon2 as SiegeWeapon);
         }
         else
         {
             if (this._destructableSiegeWeapons.Any <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => !dsw.IsDisabled)))
             {
                 SiegeWeapon siegeWeapon = this._destructableSiegeWeapons.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => !dsw.IsDisabled)).MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(dsw => dsw.GameEntity.GlobalPosition.AsVec2.DistanceSquared(this._mainInfantry.QuerySystem.AveragePosition)));
                 this._mainInfantry.AI.ResetBehaviorWeights();
                 TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
                 this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f);
                 BehaviorDefendSiegeWeapon behavior = this._mainInfantry.AI.GetBehavior <BehaviorDefendSiegeWeapon>();
                 behavior.SetDefensePositionFromTactic(siegeWeapon.GameEntity.GlobalPosition.ToWorldPosition());
                 behavior.SetDefendedSiegeWeaponFromTactic(siegeWeapon);
             }
             else
             {
                 this._mainInfantry.AI.ResetBehaviorWeights();
                 TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
                 this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefend>(1f);
                 this._mainInfantry.AI.GetBehavior <BehaviorDefend>().DefensePosition = this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(FormationAI.BehaviorSide.Middle).ToWorldPosition();
             }
             this._mainInfantry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
         }
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
     }
     if (this._archers != null)
     {
         this._archers.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._archers);
         this._archers.AI.SetBehaviorWeight <BehaviorSkirmishLine>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorScreenedSkirmish>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorSkirmish>(1f);
     }
     if (this._leftCavalry != null)
     {
         this._leftCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._leftCavalry);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f).FlankSide = FormationAI.BehaviorSide.Left;
     }
     if (this._rightCavalry != null)
     {
         this._rightCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._rightCavalry);
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f).FlankSide = FormationAI.BehaviorSide.Right;
     }
     if (this._rangedCavalry == null)
     {
         return;
     }
     this._rangedCavalry.AI.ResetBehaviorWeights();
     TacticComponent.SetDefaultBehaviorWeights(this._rangedCavalry);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorMountedSkirmish>(1f);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorHorseArcherSkirmish>(1f);
 }
 private void DefendTwoMainPositions()
 {
     FormationAI.BehaviorSide infantrySide = FormationAI.BehaviorSide.BehaviorSideNotSet;
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f);
         BehaviorDefendSiegeWeapon behavior = this._mainInfantry.AI.GetBehavior <BehaviorDefendSiegeWeapon>();
         SiegeWeapon siegeWeapon            = this._destructableSiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon && (dsw as IPrimarySiegeWeapon).WeaponSide == FormationAI.BehaviorSide.Middle));
         if (siegeWeapon != null)
         {
             infantrySide = FormationAI.BehaviorSide.Middle;
         }
         else
         {
             siegeWeapon  = this._destructableSiegeWeapons.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon)).MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(dsw => dsw.GameEntity.GlobalPosition.AsVec2.DistanceSquared(this._mainInfantry.QuerySystem.AveragePosition)));
             infantrySide = (siegeWeapon as IPrimarySiegeWeapon).WeaponSide;
         }
         behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(infantrySide).ToWorldPosition());
         behavior.SetDefendedSiegeWeaponFromTactic(siegeWeapon);
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
     }
     if (this._archers != null)
     {
         this._archers.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._archers);
         this._archers.AI.SetBehaviorWeight <BehaviorSkirmishLine>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorScreenedSkirmish>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorSkirmish>(1f);
     }
     if (this._cavalryFormation != null)
     {
         if (infantrySide != FormationAI.BehaviorSide.BehaviorSideNotSet)
         {
             this._cavalryFormation.AI.ResetBehaviorWeights();
             TacticComponent.SetDefaultBehaviorWeights(this._cavalryFormation);
             this._cavalryFormation.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f);
             BehaviorDefendSiegeWeapon behavior = this._cavalryFormation.AI.GetBehavior <BehaviorDefendSiegeWeapon>();
             SiegeWeapon siegeWeapon            = this._destructableSiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && (dsw as IPrimarySiegeWeapon).WeaponSide != infantrySide));
             behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(siegeWeapon == null ? (this._destructableSiegeWeapons.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon)).MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(dsw => dsw.GameEntity.GlobalPosition.AsVec2.DistanceSquared(this._cavalryFormation.QuerySystem.AveragePosition))) as IPrimarySiegeWeapon).WeaponSide : (siegeWeapon as IPrimarySiegeWeapon).WeaponSide).ToWorldPosition());
             behavior.SetDefendedSiegeWeaponFromTactic(siegeWeapon);
             this._cavalryFormation.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
         }
         else
         {
             this._cavalryFormation.AI.ResetBehaviorWeights();
             TacticComponent.SetDefaultBehaviorWeights(this._cavalryFormation);
             this._cavalryFormation.AI.SetBehaviorWeight <BehaviorDefendSiegeWeapon>(1f);
             BehaviorDefendSiegeWeapon behavior = this._cavalryFormation.AI.GetBehavior <BehaviorDefendSiegeWeapon>();
             SiegeWeapon siegeWeapon            = this._destructableSiegeWeapons.FirstOrDefault <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && (dsw as IPrimarySiegeWeapon).WeaponSide == FormationAI.BehaviorSide.Middle));
             FormationAI.BehaviorSide side;
             if (siegeWeapon != null)
             {
                 side = FormationAI.BehaviorSide.Middle;
             }
             else
             {
                 siegeWeapon = this._destructableSiegeWeapons.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(dsw => dsw is IPrimarySiegeWeapon && dsw is IMoveableSiegeWeapon)).MinBy <SiegeWeapon, float>((Func <SiegeWeapon, float>)(dsw => dsw.GameEntity.GlobalPosition.AsVec2.DistanceSquared(this._cavalryFormation.QuerySystem.AveragePosition)));
                 side        = (siegeWeapon as IPrimarySiegeWeapon).WeaponSide;
             }
             behavior.SetDefensePositionFromTactic(this._teamAISallyOutDefender.CalculateSallyOutReferencePosition(side).ToWorldPosition());
             behavior.SetDefendedSiegeWeaponFromTactic(siegeWeapon);
             this._cavalryFormation.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
         }
     }
     if (this._rangedCavalry == null)
     {
         return;
     }
     this._rangedCavalry.AI.ResetBehaviorWeights();
     TacticComponent.SetDefaultBehaviorWeights(this._rangedCavalry);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorMountedSkirmish>(1f);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorHorseArcherSkirmish>(1f);
 }