コード例 #1
0
        private void DestroySiegeWeapons()
        {
            if (this._mainInfantryFormation != null)
            {
                this._mainInfantryFormation.AI.ResetBehaviorWeights();
                TacticComponent.SetDefaultBehaviorWeights(this._mainInfantryFormation);
                BehaviorDefend behaviorDefend = this._mainInfantryFormation.AI.SetBehaviorWeight <BehaviorDefend>(1f);
                Vec2           vec2           = (this._teamAISallyOutAttacker.OuterGate.GameEntity.GlobalPosition.AsVec2 - this._teamAISallyOutAttacker.InnerGate.GameEntity.GlobalPosition.AsVec2).Normalized();
                WorldPosition  worldPosition1 = new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, this._teamAISallyOutAttacker.OuterGate.GameEntity.GlobalPosition, false);
                worldPosition1.SetVec2(worldPosition1.AsVec2 + (3f + this._mainInfantryFormation.Depth) * vec2);
                WorldPosition worldPosition2 = worldPosition1;
                behaviorDefend.DefensePosition = worldPosition2;
                this._mainInfantryFormation.AI.SetBehaviorWeight <BehaviorDestroySiegeWeapons>(1f);
            }
            GameEntity[] array1 = this._teamAISallyOutAttacker.ArcherPositions.ToArray <GameEntity>();
            int          length = array1.Length;

            if (length > 0)
            {
                Formation[] array2 = this._archerFormations.ToArray();
                for (int index = 0; index < array2.Length; ++index)
                {
                    array2[index].AI.ResetBehaviorWeights();
                    TacticComponent.SetDefaultBehaviorWeights(array2[index]);
                    array2[index].AI.SetBehaviorWeight <BehaviorShootFromCastleWalls>(1f);
                    array2[index].AI.GetBehavior <BehaviorShootFromCastleWalls>().ArcherPosition = array1[index % length];
                }
            }
            foreach (Formation cavalryFormation in this._cavalryFormations)
            {
                cavalryFormation.AI.ResetBehaviorWeights();
                TacticComponent.SetDefaultBehaviorWeights(cavalryFormation);
                cavalryFormation.AI.SetBehaviorWeight <BehaviorDestroySiegeWeapons>(1f);
            }
        }
コード例 #2
0
        private void WellRoundedAssault()
        {
            List <SiegeLane> currentLanes = this.DetermineCurrentLanes();

            this.AssignMeleeFormationsToLanes(this._meleeFormations, currentLanes);
            List <ArcherPosition> currentArcherPositions = this.DetermineCurrentArcherPositions(currentLanes);

            foreach (Formation rangedFormation in this._rangedFormations)
            {
                rangedFormation.AI.ResetBehaviorWeights();
                TacticComponent.SetDefaultBehaviorWeights(rangedFormation);
                rangedFormation.AI.SetBehaviorWeight <BehaviorSkirmish>(1f);
            }
            if (!currentArcherPositions.Any <ArcherPosition>())
            {
                return;
            }
            foreach (Formation rangedFormation in this._rangedFormations)
            {
                if (currentArcherPositions.IsEmpty <ArcherPosition>())
                {
                    currentArcherPositions.AddRange((IEnumerable <ArcherPosition>) this._teamAISiegeAttacker.ArcherPositions);
                }
                ArcherPosition randomElement = currentArcherPositions.GetRandomElement <ArcherPosition>();
                rangedFormation.AI.SetBehaviorWeight <BehaviorSparseSkirmish>(1f);
                rangedFormation.AI.GetBehavior <BehaviorSparseSkirmish>().ArcherPosition = randomElement.Entity;
                currentArcherPositions.Remove(randomElement);
            }
        }
コード例 #3
0
 private void HeadOutFromTheCastle()
 {
     if (this._mainInfantryFormation != null)
     {
         this._mainInfantryFormation.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantryFormation);
     }
     GameEntity[] array1 = this._teamAISallyOutAttacker.ArcherPositions.ToArray <GameEntity>();
     if (array1.Length != 0)
     {
         Formation[] array2 = this._archerFormations.ToArray();
         for (int index = 0; index < array2.Length; ++index)
         {
             array2[index].AI.ResetBehaviorWeights();
             TacticComponent.SetDefaultBehaviorWeights(array2[index]);
             array2[index].AI.SetBehaviorWeight <BehaviorShootFromCastleWalls>(1f);
             array2[index].AI.GetBehavior <BehaviorShootFromCastleWalls>().ArcherPosition = array1[index % array1.Length];
         }
     }
     foreach (Formation cavalryFormation in this._cavalryFormations)
     {
         cavalryFormation.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(cavalryFormation);
         cavalryFormation.AI.SetBehaviorWeight <BehaviorDestroySiegeWeapons>(1f);
     }
 }
コード例 #4
0
        private void AssignMeleeFormationsToLanes(
            List <Formation> meleeFormationsSource,
            List <SiegeLane> currentLanes)
        {
            List <Formation> meleeFormations = new List <Formation>(meleeFormationsSource.Count);

            meleeFormations.AddRange((IEnumerable <Formation>)meleeFormationsSource);
            List <SiegeLane> list = currentLanes.ToList <SiegeLane>();
            Formation        strongestFormation = meleeFormations.Any <Formation>() ? meleeFormations.MaxBy <Formation, float>((Func <Formation, float>)(mf => mf.QuerySystem.FormationPower)) : (Formation)null;
            bool             flag = meleeFormations.Count <Formation>() <= 1 || (double)strongestFormation.QuerySystem.FormationPower > (double)meleeFormations.Where <Formation>((Func <Formation, bool>)(f => f != strongestFormation)).Average <Formation>((Func <Formation, float>)(f => f.QuerySystem.FormationPower)) * 2.0;

            while (meleeFormations.Any <Formation>() && list.Any <SiegeLane>())
            {
                SiegeLane assaultedLane = list.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(l => meleeFormations.Any <Formation>((Func <Formation, bool>)(mf => mf.AI.Side == l.LaneSide))));
                if (assaultedLane != null)
                {
                    IEnumerable <Formation> source = meleeFormations.Where <Formation>((Func <Formation, bool>)(mf => mf.AI.Side == assaultedLane.LaneSide));
                    Formation f = source.Any <Formation>((Func <Formation, bool>)(pdf => pdf.IsAIControlled)) ? source.Where <Formation>((Func <Formation, bool>)(pdf => pdf.IsAIControlled)).MaxBy <Formation, float>((Func <Formation, float>)(pdf => pdf.QuerySystem.FormationPower)) : source.MaxBy <Formation, float>((Func <Formation, float>)(pdf => pdf.QuerySystem.FormationPower));
                    f.AI.ResetBehaviorWeights();
                    TacticComponent.SetDefaultBehaviorWeights(f);
                    f.AI.SetBehaviorWeight <BehaviorAssaultWalls>(1f);
                    f.AI.SetBehaviorWeight <BehaviorUseSiegeMachines>(1f);
                    f.AI.SetBehaviorWeight <BehaviorWaitForLadders>(1f);
                    meleeFormations.Remove(f);
                    list.Remove(assaultedLane);
                }
                else
                {
                    Formation f         = meleeFormations.Any <Formation>((Func <Formation, bool>)(mf => mf.IsAIControlled)) ? meleeFormations.Where <Formation>((Func <Formation, bool>)(mf => mf.IsAIControlled)).MaxBy <Formation, float>((Func <Formation, float>)(mf => mf.QuerySystem.FormationPower)) : meleeFormations.MaxBy <Formation, float>((Func <Formation, float>)(mf => mf.QuerySystem.FormationPower));
                    SiegeLane siegeLane = flag ? list.MinBy <SiegeLane, float>((Func <SiegeLane, float>)(l => l.LaneDifficulty)) : list.MaxBy <SiegeLane, float>((Func <SiegeLane, float>)(l => l.LaneDifficulty));
                    f.AI.Side = siegeLane.LaneSide;
                    f.AI.ResetBehaviorWeights();
                    TacticComponent.SetDefaultBehaviorWeights(f);
                    f.AI.SetBehaviorWeight <BehaviorAssaultWalls>(1f);
                    f.AI.SetBehaviorWeight <BehaviorUseSiegeMachines>(1f);
                    f.AI.SetBehaviorWeight <BehaviorWaitForLadders>(1f);
                    meleeFormations.Remove(f);
                    list.Remove(siegeLane);
                }
            }
            while (meleeFormations.Any <Formation>())
            {
                if (list.IsEmpty <SiegeLane>())
                {
                    list.AddRange((IEnumerable <SiegeLane>)currentLanes);
                }
                Formation f         = meleeFormations.MaxBy <Formation, float>((Func <Formation, float>)(mf => mf.QuerySystem.FormationPower));
                SiegeLane siegeLane = list.MaxBy <SiegeLane, float>((Func <SiegeLane, float>)(l => l.GetLaneCapacity()));
                f.AI.Side = siegeLane.LaneSide;
                f.AI.ResetBehaviorWeights();
                TacticComponent.SetDefaultBehaviorWeights(f);
                f.AI.SetBehaviorWeight <BehaviorAssaultWalls>(1f);
                f.AI.SetBehaviorWeight <BehaviorUseSiegeMachines>(1f);
                f.AI.SetBehaviorWeight <BehaviorWaitForLadders>(1f);
                meleeFormations.Remove(f);
                list.Remove(siegeLane);
            }
        }
コード例 #5
0
 private void StartRetreatToKeep()
 {
     foreach (Formation formation in this.Formations)
     {
         formation.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(formation);
         formation.AI.SetBehaviorWeight <BehaviorRetreatToKeep>(1f);
     }
 }
コード例 #6
0
        private void ArrangeDefenseFronts()
        {
            this._meleeFormations  = this.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation || f.QuerySystem.IsCavalryFormation)).ToList <Formation>();
            this._rangedFormations = this.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation || f.QuerySystem.IsRangedCavalryFormation)).ToList <Formation>();
            int count1 = Math.Min(8 - this._rangedFormations.Count, this._enemyClusters.Count);

            if (this._meleeFormations.Count != count1)
            {
                this.SplitFormationClassIntoGivenNumber((Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation || f.QuerySystem.IsCavalryFormation), count1);
                this._meleeFormations = this.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation || f.QuerySystem.IsCavalryFormation)).ToList <Formation>();
            }
            int count2 = Math.Min(8 - count1, this._enemyClusters.Count);

            if (this._rangedFormations.Count != count2)
            {
                this.SplitFormationClassIntoGivenNumber((Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation || f.QuerySystem.IsRangedCavalryFormation), count2);
                this._rangedFormations = this.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation || f.QuerySystem.IsRangedCavalryFormation)).ToList <Formation>();
            }
            foreach (TacticPerimeterDefense.DefenseFront defenseFront in this._defenseFronts)
            {
                defenseFront.MatchedEnemyCluster.UpdateClusterData();
                BehaviorDefendKeyPosition defendKeyPosition = defenseFront.MeleeFormation.AI.SetBehaviorWeight <BehaviorDefendKeyPosition>(1f);
                defendKeyPosition.EnemyClusterPosition = defenseFront.MatchedEnemyCluster.MedianAggregatePosition;
                defendKeyPosition.EnemyClusterPosition.SetVec2(defenseFront.MatchedEnemyCluster.AggregatePosition);
            }
            IEnumerable <TacticPerimeterDefense.EnemyCluster> enemyClusters = this._enemyClusters.Where <TacticPerimeterDefense.EnemyCluster>((Func <TacticPerimeterDefense.EnemyCluster, bool>)(ec => this._defenseFronts.All <TacticPerimeterDefense.DefenseFront>((Func <TacticPerimeterDefense.DefenseFront, bool>)(df => df.MatchedEnemyCluster != ec))));
            List <Formation> list1 = this._meleeFormations.Where <Formation>((Func <Formation, bool>)(mf => this._defenseFronts.All <TacticPerimeterDefense.DefenseFront>((Func <TacticPerimeterDefense.DefenseFront, bool>)(df => df.MeleeFormation != mf)))).ToList <Formation>();
            List <Formation> list2 = this._rangedFormations.Where <Formation>((Func <Formation, bool>)(rf => this._defenseFronts.All <TacticPerimeterDefense.DefenseFront>((Func <TacticPerimeterDefense.DefenseFront, bool>)(df => df.RangedFormation != rf)))).ToList <Formation>();

            foreach (TacticPerimeterDefense.EnemyCluster matchedEnemyCluster in enemyClusters)
            {
                if (list1.IsEmpty <Formation>())
                {
                    break;
                }
                Formation formation = list1.Last <Formation>();
                TacticPerimeterDefense.DefenseFront defenseFront = new TacticPerimeterDefense.DefenseFront(matchedEnemyCluster, formation);
                formation.AI.ResetBehaviorWeights();
                TacticComponent.SetDefaultBehaviorWeights(formation);
                BehaviorDefendKeyPosition defendKeyPosition = formation.AI.SetBehaviorWeight <BehaviorDefendKeyPosition>(1f);
                defendKeyPosition.DefensePosition      = this._defendPosition;
                defendKeyPosition.EnemyClusterPosition = matchedEnemyCluster.MedianAggregatePosition;
                defendKeyPosition.EnemyClusterPosition.SetVec2(matchedEnemyCluster.AggregatePosition);
                list1.Remove(formation);
                if (!list2.IsEmpty <Formation>())
                {
                    Formation f = list2.Last <Formation>();
                    f.AI.ResetBehaviorWeights();
                    TacticComponent.SetDefaultBehaviorWeights(f);
                    f.AI.SetBehaviorWeight <BehaviorSkirmishBehindFormation>(1f).ReferenceFormation = formation;
                    defenseFront.RangedFormation = f;
                    list2.Remove(f);
                    this._defenseFronts.Add(defenseFront);
                }
            }
        }
コード例 #7
0
 private void StartTacticalRetreat()
 {
     this.StopUsingAllMachines();
     foreach (Formation formation in this.Formations)
     {
         formation.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(formation);
         formation.AI.SetBehaviorWeight <BehaviorRetreatToKeep>(1f);
     }
 }
コード例 #8
0
 protected internal override void TickOccasionally()
 {
     foreach (Formation formation in this.Formations)
     {
         formation.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(formation);
         formation.AI.SetBehaviorWeight <BehaviorCharge>(10000f);
     }
     base.TickOccasionally();
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 private void InfantryRetreat()
 {
     if (this._mainInfantryFormation == null)
     {
         return;
     }
     this._mainInfantryFormation.AI.Side = FormationAI.BehaviorSide.Middle;
     this._mainInfantryFormation.AI.ResetBehaviorWeights();
     TacticComponent.SetDefaultBehaviorWeights(this._mainInfantryFormation);
     this._mainInfantryFormation.AI.SetBehaviorWeight <BehaviorDefendCastleKeyPosition>(1f);
 }
コード例 #11
0
 protected override void ManageFormationCounts()
 {
     this.ManageFormationCounts(1, 1, 1, 1);
     this._mainInfantry = TacticComponent.ChooseAndSortByPriority(this.Formations, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation), (Func <Formation, bool>)(f => f.IsAIControlled), (Func <Formation, float>)(f => f.QuerySystem.FormationPower)).FirstOrDefault <Formation>();
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.IsMainFormation = true;
     }
     this._archers       = TacticComponent.ChooseAndSortByPriority(this.Formations, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation), (Func <Formation, bool>)(f => f.IsAIControlled), (Func <Formation, float>)(f => f.QuerySystem.FormationPower)).FirstOrDefault <Formation>();
     this._cavalry       = TacticComponent.ChooseAndSortByPriority(this.Formations, (Func <Formation, bool>)(f => f.QuerySystem.IsCavalryFormation), (Func <Formation, bool>)(f => f.IsAIControlled), (Func <Formation, float>)(f => f.QuerySystem.FormationPower)).FirstOrDefault <Formation>();
     this._rangedCavalry = TacticComponent.ChooseAndSortByPriority(this.Formations, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedCavalryFormation), (Func <Formation, bool>)(f => f.IsAIControlled), (Func <Formation, float>)(f => f.QuerySystem.FormationPower)).FirstOrDefault <Formation>();
 }
コード例 #12
0
 private void OrganizedRetreat()
 {
     if (this.team.IsPlayerTeam && !this.team.IsPlayerGeneral && this.team.IsPlayerSergeant)
     {
         this.SoundTacticalHorn(TacticComponent.RetreatHornSoundIndex);
     }
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
         BehaviorDefend behaviorDefend       = this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefend>(1f);
         WorldPosition  positionForFormation = Mission.Current.GetClosestFleePositionForFormation(this._mainInfantry);
         positionForFormation.SetVec2(Mission.Current.GetClosestBoundaryPosition(positionForFormation.AsVec2));
         this._retreatPosition = positionForFormation.AsVec2;
         WorldPosition worldPosition = positionForFormation;
         behaviorDefend.DefensePosition = worldPosition;
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorPullBack>(1f);
     }
     if (this._archers != null)
     {
         this._archers.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._archers);
         this._archers.AI.SetBehaviorWeight <BehaviorScreenedSkirmish>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorPullBack>(1.5f);
     }
     if (this._leftCavalry != null)
     {
         this._leftCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._leftCavalry);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f).FlankSide = FormationAI.BehaviorSide.Left;
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorCavalryScreen>(1f);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorPullBack>(1.5f);
     }
     if (this._rightCavalry != null)
     {
         this._rightCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._rightCavalry);
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f).FlankSide = FormationAI.BehaviorSide.Right;
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorCavalryScreen>(1f);
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorPullBack>(1.5f);
     }
     if (this._rangedCavalry == null)
     {
         return;
     }
     this._rangedCavalry.AI.ResetBehaviorWeights();
     TacticComponent.SetDefaultBehaviorWeights(this._rangedCavalry);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorMountedSkirmish>(1f);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorPullBack>(1.5f);
     this._rangedCavalry.AI.SetBehaviorWeight <BehaviorHorseArcherSkirmish>(1f);
 }
コード例 #13
0
 private void Engage()
 {
     if (this.team.IsPlayerTeam && !this.team.IsPlayerGeneral && this.team.IsPlayerSergeant)
     {
         this.SoundTacticalHorn(TacticComponent.AttackHornSoundIndex);
     }
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefend>(1f).TacticalDefendPosition = this._mainDefensiveLineObject;
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
     }
     if (this._archers != null)
     {
         this._archers.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._archers);
         this._archers.AI.SetBehaviorWeight <BehaviorSkirmish>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorScreenedSkirmish>(1f);
         if (this._linkedRangedDefensivePosition != null)
         {
             this._archers.AI.SetBehaviorWeight <BehaviorDefend>(1f).TacticalDefendPosition = this._linkedRangedDefensivePosition;
         }
     }
     if (this._leftCavalry != null)
     {
         this._leftCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._leftCavalry);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorFlank>(1f);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
     }
     if (this._rightCavalry != null)
     {
         this._rightCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._rightCavalry);
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorFlank>(1f);
         this._rightCavalry.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);
 }
コード例 #14
0
 private void Defend()
 {
     if (this.team.IsPlayerTeam && !this.team.IsPlayerGeneral && this.team.IsPlayerSergeant)
     {
         this.SoundTacticalHorn(TacticComponent.MoveHornSoundIndex);
     }
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorDefend>(1f).TacticalDefendPosition = this._chokePointTacticalPosition;
     }
     if (this._archers != null)
     {
         this._archers.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._archers);
         this._archers.AI.SetBehaviorWeight <BehaviorSkirmishLine>(1f);
         this._archers.AI.SetBehaviorWeight <BehaviorScreenedSkirmish>(1f);
         if (this._linkedRangedDefensivePosition != null)
         {
             this._archers.AI.SetBehaviorWeight <BehaviorDefend>(10f).TacticalDefendPosition = this._linkedRangedDefensivePosition;
         }
     }
     if (this._leftCavalry != null)
     {
         this._leftCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._leftCavalry);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f).FlankSide = FormationAI.BehaviorSide.Left;
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorCavalryScreen>(1f);
     }
     if (this._rightCavalry != null)
     {
         this._rightCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._rightCavalry);
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorProtectFlank>(1f).FlankSide = FormationAI.BehaviorSide.Right;
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorCavalryScreen>(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);
 }
コード例 #15
0
 private void Engage()
 {
     if (this._leftCavalry != null)
     {
         this._leftCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._leftCavalry);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorFlank>(1f);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
     }
     if (this._rightCavalry == null)
     {
         return;
     }
     this._rightCavalry.AI.ResetBehaviorWeights();
     TacticComponent.SetDefaultBehaviorWeights(this._rightCavalry);
     this._rightCavalry.AI.SetBehaviorWeight <BehaviorFlank>(1f);
     this._rightCavalry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
 }
コード例 #16
0
 private void Attack()
 {
     if (this.team.IsPlayerTeam && !this.team.IsPlayerGeneral && this.team.IsPlayerSergeant)
     {
         this.SoundTacticalHorn(TacticComponent.AttackHornSoundIndex);
     }
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorCautiousAdvance>(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 <BehaviorFlank>(1f);
         this._leftCavalry.AI.SetBehaviorWeight <BehaviorTacticalCharge>(1f);
     }
     if (this._rightCavalry != null)
     {
         this._rightCavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._rightCavalry);
         this._rightCavalry.AI.SetBehaviorWeight <BehaviorFlank>(1f);
         this._rightCavalry.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);
 }
コード例 #17
0
 protected override void ManageFormationCounts()
 {
     if (this._weaponsToBeDefendedState == TacticSallyOutDefense.WeaponsToBeDefended.TwoPrimary)
     {
         this.ManageFormationCounts(1, 1, 1, 1);
         this._mainInfantry = TacticComponent.ChooseAndSortByPriority(this.Formations, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation), (Func <Formation, bool>)(f => f.IsAIControlled), (Func <Formation, float>)(f => f.QuerySystem.FormationPower)).FirstOrDefault <Formation>();
         if (this._mainInfantry != null)
         {
             this._mainInfantry.AI.IsMainFormation = true;
         }
         this._archers          = TacticComponent.ChooseAndSortByPriority(this.Formations, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation), (Func <Formation, bool>)(f => f.IsAIControlled), (Func <Formation, float>)(f => f.QuerySystem.FormationPower)).FirstOrDefault <Formation>();
         this._cavalryFormation = TacticComponent.ChooseAndSortByPriority(this.Formations, (Func <Formation, bool>)(f => f.QuerySystem.IsCavalryFormation), (Func <Formation, bool>)(f => f.IsAIControlled), (Func <Formation, float>)(f => f.QuerySystem.FormationPower)).FirstOrDefault <Formation>();
         this._rangedCavalry    = TacticComponent.ChooseAndSortByPriority(this.Formations, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedCavalryFormation), (Func <Formation, bool>)(f => f.IsAIControlled), (Func <Formation, float>)(f => f.QuerySystem.FormationPower)).FirstOrDefault <Formation>();
     }
     else
     {
         this.AssignTacticFormations1121();
     }
 }
コード例 #18
0
 private void CavalryRetreat()
 {
     if (this._mainInfantryFormation != null)
     {
         this._mainInfantryFormation.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantryFormation);
         BehaviorDefend behaviorDefend = this._mainInfantryFormation.AI.SetBehaviorWeight <BehaviorDefend>(1f);
         Vec2           vec2           = (this._teamAISallyOutAttacker.OuterGate.GameEntity.GlobalPosition.AsVec2 - this._teamAISallyOutAttacker.InnerGate.GameEntity.GlobalPosition.AsVec2).Normalized();
         WorldPosition  worldPosition1 = new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, this._teamAISallyOutAttacker.OuterGate.GameEntity.GlobalPosition, false);
         worldPosition1.SetVec2(worldPosition1.AsVec2 + (3f + this._mainInfantryFormation.Depth) * vec2);
         WorldPosition worldPosition2 = worldPosition1;
         behaviorDefend.DefensePosition = worldPosition2;
     }
     foreach (Formation cavalryFormation in this._cavalryFormations)
     {
         cavalryFormation.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(cavalryFormation);
         cavalryFormation.AI.SetBehaviorWeight <BehaviorRetreatToKeep>(1f);
     }
 }
コード例 #19
0
        internal override float GetTacticWeight()
        {
            if (!this.team.TeamAI.IsDefenseApplicable || this.Formations.All <Formation>((Func <Formation, bool>)(f => !f.QuerySystem.IsInfantryFormation)))
            {
                return(0.0f);
            }
            Formation formation = this._mainInfantry ?? this.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)).MaxBy <Formation, int>((Func <Formation, int>)(f => f.CountOfUnits));

            if (formation == null)
            {
                return(0.0f);
            }
            if (this._mainInfantry == null)
            {
                this._mainInfantry = formation;
            }
            double num1 = (double)this.team.QuerySystem.InfantryRatio + (double)this.team.QuerySystem.RangedRatio;
            float  num2 = MBMath.Lerp(0.7f, 1f, (float)((150.0 - (double)MBMath.ClampFloat(this._mainInfantry.QuerySystem.AveragePosition.Distance(this._mainInfantry.QuerySystem.HighGroundCloseToForeseenBattleGround), 50f, 150f)) / 100.0));

            return((float)(num1 * 1.10000002384186) * TacticComponent.CalculateNotEngagingTacticalAdvantage(this.team.QuerySystem) * num2 / (float)Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio));
        }
コード例 #20
0
 private void Advance()
 {
     if (this.team.IsPlayerTeam && !this.team.IsPlayerGeneral && this.team.IsPlayerSergeant)
     {
         this.SoundTacticalHorn(TacticComponent.MoveHornSoundIndex);
     }
     if (this._mainInfantry != null)
     {
         this._mainInfantry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._mainInfantry);
         this._mainInfantry.AI.SetBehaviorWeight <BehaviorAdvance>(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._cavalry != null)
     {
         this._cavalry.AI.ResetBehaviorWeights();
         TacticComponent.SetDefaultBehaviorWeights(this._cavalry);
         this._cavalry.AI.SetBehaviorWeight <BehaviorAdvance>(1f);
         this._cavalry.AI.SetBehaviorWeight <BehaviorVanguard>(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);
 }
コード例 #21
0
        private float GetFormationBehaviourLaneEffectiveness(
            SiegeLane siegeLane,
            Formation formation,
            BehaviorComponent behaviour)
        {
            switch (behaviour)
            {
            case BehaviorAssaultWalls _:
                return((float)((formation.AI.Side == siegeLane.LaneSide ? 5.0 : 1.0) * (formation.AI.ActiveBehavior == null || !(formation.AI.ActiveBehavior.GetType() == behaviour.GetType()) ? 1.0 : 3.0)) * TacticComponent.GetFormationEffectivenessOverOrder(formation, OrderType.Charge) * siegeLane.PrimarySiegeWeapons.Where <IPrimarySiegeWeapon>((Func <IPrimarySiegeWeapon, bool>)(psw => psw.HasCompletedAction())).Max <IPrimarySiegeWeapon>((Func <IPrimarySiegeWeapon, float>)(psw => psw.SiegeWeaponPriority)));

            case BehaviorUseSiegeMachines _:
                return((float)((formation.AI.Side == siegeLane.LaneSide ? 5.0 : 1.0) * (formation.AI.ActiveBehavior == null || !(formation.AI.ActiveBehavior.GetType() == behaviour.GetType()) ? 1.0 : 3.0)) * TacticComponent.GetFormationEffectivenessOverOrder(formation, OrderType.Charge) * siegeLane.PrimarySiegeWeapons.Where <IPrimarySiegeWeapon>((Func <IPrimarySiegeWeapon, bool>)(psw => !psw.HasCompletedAction())).Max <IPrimarySiegeWeapon>((Func <IPrimarySiegeWeapon, float>)(psw => psw.SiegeWeaponPriority)));

            default:
                return(0.0f);
            }
        }
コード例 #22
0
        internal override float GetTacticWeight()
        {
            if (!this.team.TeamAI.IsDefenseApplicable || !this.CheckAndDetermineFormation(ref this._mainInfantry, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)) || !this.CheckAndDetermineFormation(ref this._archers, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)))
            {
                return(0.0f);
            }
            double num1 = (double)Math.Max(0, this._mainInfantry.CountOfUnits - 1) * ((double)this._mainInfantry.MaximumInterval + (double)this._mainInfantry.UnitDiameter) * 0.5 / Math.PI;
            double num2 = Math.Sqrt((double)this._archers.CountOfUnits);
            double num3 = (double)this._archers.UnitDiameter * num2 + (double)this._archers.Interval * (num2 - 1.0);

            if (num1 < num3)
            {
                return(0.0f);
            }
            if (!this.team.TeamAI.IsCurrentTactic((TacticComponent)this) || this._mainRingPosition == null || !this.IsTacticalPositionEligible(this._mainRingPosition))
            {
                this.DetermineRingPosition();
            }
            return(this._mainRingPosition == null ? 0.0f : (float)((double)Math.Min(this.team.QuerySystem.InfantryRatio, this.team.QuerySystem.RangedRatio) * 2.0 * 1.5) * this.GetTacticalPositionScore(this._mainRingPosition) * TacticComponent.CalculateNotEngagingTacticalAdvantage(this.team.QuerySystem) / (float)Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio));
        }
コード例 #23
0
        internal override float GetTacticWeight()
        {
            if (!this.team.TeamAI.IsDefenseApplicable || !this.CheckAndDetermineFormation(ref this._mainInfantry, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)))
            {
                return(0.0f);
            }
            if (!this.team.TeamAI.IsCurrentTactic((TacticComponent)this) || this._chokePointTacticalPosition == null || !this.IsTacticalPositionEligible(this._chokePointTacticalPosition))
            {
                this.DetermineChokePoints();
            }
            if (this._chokePointTacticalPosition == null)
            {
                return(0.0f);
            }
            double infantryRatio = (double)this.team.QuerySystem.InfantryRatio;

            return((float)((infantryRatio + (double)Math.Min((float)infantryRatio, this.team.QuerySystem.RangedRatio)) * (double)MBMath.ClampFloat((float)this.team.QuerySystem.EnemyUnitCount / (float)this.team.QuerySystem.MemberCount, 0.33f, 3f) * (double)this.GetTacticalPositionScore(this._chokePointTacticalPosition) * (double)TacticComponent.CalculateNotEngagingTacticalAdvantage(this.team.QuerySystem) * 1.29999995231628) / (float)Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio));
        }
コード例 #24
0
 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);
 }
コード例 #25
0
 internal override float GetTacticWeight()
 {
     if (!this.team.TeamAI.IsDefenseApplicable || !this.CheckAndDetermineFormation(ref this._mainInfantry, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)))
     {
         return(0.0f);
     }
     if (!this.team.TeamAI.IsCurrentTactic((TacticComponent)this) || this._mainDefensiveLineObject == null || !this.IsTacticalPositionEligible(this._mainDefensiveLineObject))
     {
         this.DetermineMainDefensiveLine();
     }
     return(this._mainDefensiveLineObject == null ? 0.0f : (float)(((double)this.team.QuerySystem.InfantryRatio + (double)this.team.QuerySystem.RangedRatio) * 1.20000004768372) * this.GetTacticalPositionScore(this._mainDefensiveLineObject) * TacticComponent.CalculateNotEngagingTacticalAdvantage(this.team.QuerySystem) / (float)Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio));
 }
コード例 #26
0
        private void CreateBodyGuardFormation(Team team)
        {
            Agent                 generalAgent = (Agent)null;
            Formation             formation1   = (Formation)null;
            Formation             formation2   = (Formation)null;
            List <IFormationUnit> list1        = team.Formations.SelectMany <Formation, IFormationUnit>((Func <Formation, IEnumerable <IFormationUnit> >)(f => (IEnumerable <IFormationUnit>)f.UnitsWithoutLooseDetachedOnes)).ToList <IFormationUnit>();

            if (team.IsPlayerTeam && team.IsPlayerGeneral)
            {
                generalAgent = Mission.Current.MainAgent;
            }
            else
            {
                string generalName = team == this.Mission.AttackerTeam ? this._attackerGeneralName : (team == this.Mission.DefenderTeam ? this._defenderGeneralName : (team == this.Mission.AttackerAllyTeam ? this._attackerAllyGeneralName : (team == this.Mission.DefenderAllyTeam ? this._defenderAllyGeneralName : (string)null)));
                if (generalName != null && list1.Count <IFormationUnit>((Func <IFormationUnit, bool>)(ta => ((Agent)ta).Character != null && ((Agent)ta).Character.GetName().Equals(generalName))) == 1)
                {
                    generalAgent = (Agent)list1.First <IFormationUnit>((Func <IFormationUnit, bool>)(ta => ((Agent)ta).Character != null && ((Agent)ta).Character.GetName().Equals(generalName)));
                }
                else if (list1.Any <IFormationUnit>((Func <IFormationUnit, bool>)(u => !((Agent)u).IsMainAgent && ((Agent)u).IsHero)))
                {
                    generalAgent = (Agent)list1.Where <IFormationUnit>((Func <IFormationUnit, bool>)(u => !((Agent)u).IsMainAgent && ((Agent)u).IsHero)).MaxBy <IFormationUnit, float>((Func <IFormationUnit, float>)(u => ((Agent)u).CharPowerCached));
                }
            }
            team.GeneralAgent = generalAgent;
            if (generalAgent != null && team.QuerySystem.MemberCount >= 50)
            {
                formation1 = team.GetFormation(FormationClass.NumberOfRegularFormations);
                formation1.MovementOrder  = MovementOrder.MovementOrderMove(generalAgent.GetWorldPosition());
                formation1.IsAIControlled = true;
                Formation formation3 = generalAgent.Formation;
                generalAgent.Formation = formation1;
                team.TriggerOnFormationsChanged(formation1);
                formation1.QuerySystem.Expire();
                team.GeneralsFormation = formation1;
                if (this._createBodyguard && generalAgent.IsAIControlled)
                {
                    list1.Remove((IFormationUnit)generalAgent);
                    List <IFormationUnit> list2 = list1.Where <IFormationUnit>((Func <IFormationUnit, bool>)(u =>
                    {
                        if (((Agent)u).Character != null && ((Agent)u).Character.IsHero)
                        {
                            return(false);
                        }
                        return(generalAgent.MountAgent == null ? !((Agent)u).HasMount : ((Agent)u).HasMount);
                    })).ToList <IFormationUnit>();
                    int count = Math.Min((int)((double)list2.Count <IFormationUnit>() / 10.0), 20);
                    if (count != 0)
                    {
                        formation2 = team.GetFormation(FormationClass.Bodyguard);
                        formation2.MovementOrder  = MovementOrder.MovementOrderMove(generalAgent.GetWorldPosition());
                        formation2.IsAIControlled = true;
                        List <IFormationUnit>   list3      = list2.OrderByDescending <IFormationUnit, float>((Func <IFormationUnit, float>)(u => ((Agent)u).CharPowerCached)).Take <IFormationUnit>(count).ToList <IFormationUnit>();
                        IEnumerable <Formation> formations = list3.Select <IFormationUnit, Formation>((Func <IFormationUnit, Formation>)(bu => ((Agent)bu).Formation)).Distinct <Formation>();
                        foreach (IFormationUnit formationUnit1 in list3)
                        {
                            IFormationUnit formationUnit2;
                            Formation      formation4 = ((Agent)(formationUnit2 = formationUnit1)).Formation;
                            ((Agent)formationUnit2).Formation = formation2;
                        }
                        foreach (Formation formation4 in formations)
                        {
                            team.TriggerOnFormationsChanged(formation4);
                            formation4.QuerySystem.Expire();
                        }
                        team.TriggerOnFormationsChanged(formation2);
                        formation2.QuerySystem.Expire();
                    }
                }
                TacticComponent.SetDefaultBehaviorWeights(formation1);
                formation1.AI.SetBehaviorWeight <BehaviorGeneral>(1f);
                formation1.PlayerOwner = (Agent)null;
                if (formation2 != null)
                {
                    TacticComponent.SetDefaultBehaviorWeights(formation2);
                    formation2.AI.SetBehaviorWeight <BehaviorProtectGeneral>(1f);
                    formation2.PlayerOwner = (Agent)null;
                }
            }
            team.GeneralAgent       = generalAgent;
            team.GeneralsFormation  = formation1;
            team.BodyGuardFormation = formation2;
        }
コード例 #27
0
 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);
 }