protected override void CalculateCurrentOrder()
        {
            Formation     formation = this.formation.Team.Formations.FirstOrDefault <Formation>((Func <Formation, bool>)(f => f != this.formation && f.AI.IsMainFormation));
            WorldPosition medianPosition;

            if (formation != null)
            {
                medianPosition = formation.QuerySystem.MedianPosition;
                Vec2 vec2 = (this.formation.QuerySystem.Team.AverageEnemyPosition - formation.QuerySystem.MedianPosition.AsVec2).Normalized();
                medianPosition.SetVec2(medianPosition.AsVec2 - vec2 * (40f + this.formation.Depth));
            }
            else
            {
                IEnumerable <Formation> source = this.formation.Team.FormationsIncludingSpecial.Where <Formation>((Func <Formation, bool>)(f => f != this.formation));
                if (source.IsEmpty <Formation>())
                {
                    this.CurrentOrder = MovementOrder.MovementOrderStop;
                    return;
                }
                Vec2 vec2_1 = new Vec2(source.Average <Formation>((Func <Formation, float>)(oa => oa.QuerySystem.AveragePosition.x)), source.Average <Formation>((Func <Formation, float>)(oa => oa.QuerySystem.AveragePosition.y)));
                Vec2 vec2_2 = (this.formation.QuerySystem.Team.AverageEnemyPosition - vec2_1).Normalized();
                medianPosition = this.formation.QuerySystem.MedianPosition;
                medianPosition.SetVec2(vec2_1 - vec2_2 * (20f + this.formation.Depth));
            }
            this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
        }
        protected override void CalculateCurrentOrder()
        {
            WorldPosition medianPosition;

            if (this.formation.Team.QuerySystem.EnemyTeams.SelectMany <TeamQuerySystem, Formation>((Func <TeamQuerySystem, IEnumerable <Formation> >)(t => t.Team.FormationsIncludingSpecial)).Any <Formation>() && this.formation.Team.FormationsIncludingSpecial.Any <Formation>())
            {
                float num1 = !this.formation.IsMounted() || (double)this.formation.Team.QuerySystem.CavalryRatio + (double)this.formation.Team.QuerySystem.RangedCavalryRatio < 33.2999992370605 ? 3f : 40f;
                if (this._mainFormation != null && this._mainFormation.CountOfUnits > 0)
                {
                    float num2 = this._mainFormation.Depth + num1;
                    medianPosition = this._mainFormation.QuerySystem.MedianPosition;
                    medianPosition.SetVec2(medianPosition.AsVec2 - (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this._mainFormation.QuerySystem.MedianPosition.AsVec2).Normalized() * num2);
                }
                else
                {
                    medianPosition = this.formation.QuerySystem.Team.MedianPosition;
                    medianPosition.SetVec2(this.formation.QuerySystem.Team.AveragePosition - (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this.formation.QuerySystem.Team.AveragePosition).Normalized() * num1);
                }
            }
            else
            {
                medianPosition = this.formation.QuerySystem.MedianPosition;
                medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
            }
            this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
        }
Exemple #3
0
        public static void SetPlayerFormation(FormationClass formationClass)
        {
            var mission = Mission.Current;

            if (mission.MainAgent != null && Mission.Current.PlayerTeam != null &&
                mission.MainAgent.Formation?.FormationIndex != formationClass)
            {
                var formation = mission.PlayerTeam.GetFormation(formationClass);
                if (formation.CountOfUnits == 0)
                {
                    // Fix the bug when player does not lead a formation, and the formation is assigned with another sergeant, the formation will not be controlled by AI.
                    if (Mission.Current.PlayerTeam.IsPlayerGeneral && formation.IsAIControlled)
                    {
                        formation.IsAIControlled = false;
                    }
                    // fix crash when begin a battle and assign player to an empty formation, then give it an shield wall order.
                    formation.MovementOrder = MovementOrder.MovementOrderMove(mission.MainAgent.GetWorldPosition());
                }

                if (mission.MainAgent.Formation != null)
                {
                    SetHasPlayer(mission.MainAgent.Formation, false);
                }
                mission.MainAgent.Formation = formation;
            }
        }
Exemple #4
0
        public static void SetPlayerFormation(FormationClass formationClass)
        {
            var mission = Mission.Current;

            if (mission.MainAgent != null && Mission.Current.PlayerTeam != null &&
                mission.MainAgent.Formation?.FormationIndex != formationClass)
            {
                var formation = mission.PlayerTeam.GetFormation(formationClass);
                if (formation.CountOfUnits == 0)
                {
                    if (formation.IsAIControlled)
                    {
                        formation.IsAIControlled = false;
                    }
                    // fix crash when begin a battle and assign player to an empty formation, then give it an shield wall order.
                    formation.MovementOrder = MovementOrder.MovementOrderMove(mission.MainAgent.GetWorldPosition());
                }

                if (mission.MainAgent.Formation != null)
                {
                    SetHasPlayer(mission.MainAgent.Formation, false);
                }
                mission.MainAgent.Formation = formation;
            }
        }
            static void PostfixCalculateCurrentOrder(Formation ___formation, ref MovementOrder ____currentOrder, ref Boolean ___IsCurrentOrderChanged, ref WorldPosition ____defensePosition)
            {
                if (___formation != null && ___formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation != null)
                {
                    WorldPosition medianPositionNew = ___formation.QuerySystem.MedianPosition;
                    medianPositionNew.SetVec2(___formation.QuerySystem.AveragePosition);

                    Formation significantEnemy = Utilities.FindSignificantEnemy(___formation, true, true, true, false, false);

                    if (significantEnemy != null)
                    {
                        float distance = ___formation.QuerySystem.MedianPosition.AsVec2.Distance(significantEnemy.QuerySystem.MedianPosition.AsVec2);
                        if (distance < (180f))
                        {
                            ____currentOrder         = MovementOrder.MovementOrderMove(medianPositionOld);
                            ___IsCurrentOrderChanged = true;
                        }
                        else
                        {
                            if (____defensePosition.IsValid)
                            {
                                medianPositionOld = ____defensePosition;
                                medianPositionOld.SetVec2(medianPositionOld.AsVec2 + ___formation.Direction * 10f);
                                ____currentOrder = MovementOrder.MovementOrderMove(medianPositionOld);
                            }
                            else
                            {
                                medianPositionOld = medianPositionNew;
                                medianPositionOld.SetVec2(medianPositionOld.AsVec2 + ___formation.Direction * 10f);
                            }
                        }
                    }
                }
            }
        protected override void CalculateCurrentOrder()
        {
            WorldPosition medianPosition;
            Vec2          direction;

            if (this.formation.QuerySystem.ClosestEnemyFormation != null)
            {
                medianPosition = this.formation.QuerySystem.MedianPosition;
                medianPosition.SetVec2((double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2) > 400.0 ? this.formation.QuerySystem.HighGroundCloseToForeseenBattleGround : this.formation.QuerySystem.AveragePosition);
                Vec2 vec2_1;
                if ((double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.formation.QuerySystem.HighGroundCloseToForeseenBattleGround) <= 25.0)
                {
                    Vec2 vec2_2 = this.formation.Direction;
                    vec2_2 = (double)vec2_2.DotProduct((this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized()) < 0.5 ? this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition : this.formation.Direction;
                    vec2_1 = vec2_2.Normalized();
                }
                else
                {
                    vec2_1 = (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - medianPosition.AsVec2).Normalized();
                }
                direction = vec2_1;
            }
            else
            {
                direction      = this.formation.Direction;
                medianPosition = this.formation.QuerySystem.MedianPosition;
                medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
            }
            this.CurrentOrder       = MovementOrder.MovementOrderMove(medianPosition);
            this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
        }
Exemple #7
0
        private void ResetOrderPositions()
        {
            this.behaviorSide = this.DetermineGatheringSide();
            SiegeLane  siegeLane  = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide));
            WorldFrame worldFrame = siegeLane == null ? WorldFrame.Invalid : siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().DefenseWaitFrame;

            this._gatheringTacticalPos = siegeLane != null?siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().WaitPosition : (TacticalPosition)null;

            if (this._gatheringTacticalPos != null)
            {
                this._gatherOrder          = MovementOrder.MovementOrderMove(this._gatheringTacticalPos.Position);
                this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
            }
            else if (worldFrame.Origin.IsValid)
            {
                double num = (double)worldFrame.Rotation.f.Normalize();
                this._gatherOrder          = MovementOrder.MovementOrderMove(worldFrame.Origin);
                this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
            }
            else
            {
                this._gatherOrder          = MovementOrder.MovementOrderMove(this.formation.QuerySystem.MedianPosition);
                this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
            }
            this._attackOrder       = MovementOrder.MovementOrderChargeToTarget(this._targetEnemyFormation);
            this._attackFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
            this.CurrentOrder       = this._behaviourState == BehaviorEliminateEnemyInsideCastle.BehaviourState.Attacking ? this._attackOrder : this._gatherOrder;
            this.CurrentFacingOrder = this._behaviourState == BehaviorEliminateEnemyInsideCastle.BehaviourState.Attacking ? this._attackFacingOrder : this._gatheringFacingOrder;
        }
 protected override void CalculateCurrentOrder()
 {
     if (this._mainFormation == null || this.formation.AI.IsMainFormation || this.formation.AI.Side != FormationAI.BehaviorSide.Left && this.formation.AI.Side != FormationAI.BehaviorSide.Right)
     {
         this._flankingEnemyCavalryFormation = (Formation)null;
         WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;
         medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
         this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
     }
     else
     {
         float time = MBCommon.GetTime(MBCommon.TimeType.Mission);
         if ((double)this._threatFormationCacheTime + 5.0 < (double)time)
         {
             this._threatFormationCacheTime = time;
             Vec2 vec2_1;
             Vec2 vec2_2;
             if (this.formation.AI.Side != FormationAI.BehaviorSide.Left)
             {
                 vec2_1 = this._mainFormation.Direction;
                 vec2_2 = vec2_1.RightVec();
             }
             else
             {
                 vec2_1 = this._mainFormation.Direction;
                 vec2_2 = vec2_1.LeftVec();
             }
             vec2_1 = vec2_2;
             Vec2 vec2_3 = vec2_1.Normalized();
             vec2_1 = this._mainFormation.Direction;
             Vec2 vec2_4                    = vec2_1.Normalized();
             Vec2 threatDirection           = vec2_3 - vec2_4;
             IEnumerable <Formation> source = Mission.Current.Teams.GetEnemiesOf(this.formation.Team).SelectMany <Team, Formation>((Func <Team, IEnumerable <Formation> >)(t => t.FormationsIncludingSpecial)).Where <Formation>((Func <Formation, bool>)(f =>
             {
                 WorldPosition medianPosition = f.QuerySystem.MedianPosition;
                 Vec2 asVec2_1  = medianPosition.AsVec2;
                 medianPosition = this._mainFormation.QuerySystem.MedianPosition;
                 Vec2 asVec2_2  = medianPosition.AsVec2;
                 Vec2 vec2      = asVec2_1 - asVec2_2;
                 return((double)threatDirection.Normalized().DotProduct(vec2.Normalized()) > Math.Cos(Math.PI / 8.0));
             }));
             this._flankingEnemyCavalryFormation = !source.Any <Formation>() ? (Formation)null : source.MaxBy <Formation, float>((Func <Formation, float>)(tef => tef.QuerySystem.FormationPower));
         }
         WorldPosition medianPosition1;
         if (this._flankingEnemyCavalryFormation == null)
         {
             medianPosition1 = this.formation.QuerySystem.MedianPosition;
             medianPosition1.SetVec2(this.formation.QuerySystem.AveragePosition);
         }
         else
         {
             Vec2  vec2 = this._flankingEnemyCavalryFormation.QuerySystem.MedianPosition.AsVec2 - this._mainFormation.QuerySystem.MedianPosition.AsVec2;
             float num  = vec2.Normalize() * 0.5f;
             medianPosition1 = this._mainFormation.QuerySystem.MedianPosition;
             medianPosition1.SetVec2(medianPosition1.AsVec2 + num * vec2);
         }
         this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition1);
     }
 }
Exemple #9
0
        protected override void CalculateCurrentOrder()
        {
            WorldPosition position  = this.formation.AI.Side == FormationAI.BehaviorSide.Right ? this.formation.QuerySystem.Team.RightFlankEdgePosition : this.formation.QuerySystem.Team.LeftFlankEdgePosition;
            Vec2          direction = (position.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized();

            this.CurrentOrder       = MovementOrder.MovementOrderMove(position);
            this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
        }
        protected override void CalculateCurrentOrder()
        {
            Vec2          direction      = this.formation.QuerySystem.ClosestEnemyFormation == null ? this.formation.Direction : (this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized();
            WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;

            medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
            this.CurrentOrder       = MovementOrder.MovementOrderMove(medianPosition);
            this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
        }
 protected override void CalculateCurrentOrder()
 {
     if (this._switchedToShieldWallRecently && !this._switchedToShieldWallTimer.Check(Mission.Current.Time) && (double)this.formation.QuerySystem.FormationDispersedness > 2.0)
     {
         WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;
         if (this._reformPosition.IsValid)
         {
             medianPosition.SetVec2(this._reformPosition);
         }
         else
         {
             this._reformPosition = this.formation.QuerySystem.AveragePosition + (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized() * 5f;
             medianPosition.SetVec2(this._reformPosition);
         }
         this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
     }
     else
     {
         this._switchedToShieldWallRecently = false;
         bool flag = false;
         Vec2 vec2_1;
         if (this.formation.QuerySystem.ClosestEnemyFormation != null && this.formation.QuerySystem.ClosestEnemyFormation.IsCavalryFormation)
         {
             Vec2   vec2_2          = this.formation.QuerySystem.AveragePosition - this.formation.QuerySystem.ClosestEnemyFormation.AveragePosition;
             double num1            = (double)vec2_2.Normalize();
             Vec2   currentVelocity = this.formation.QuerySystem.ClosestEnemyFormation.CurrentVelocity;
             float  num2            = currentVelocity.Normalize();
             if (num1 < 30.0 && (double)num2 > 2.0 && (double)vec2_2.DotProduct(currentVelocity) > 0.5)
             {
                 flag = true;
                 WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;
                 if (this._reformPosition.IsValid)
                 {
                     medianPosition.SetVec2(this._reformPosition);
                 }
                 else
                 {
                     vec2_1 = this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this.formation.QuerySystem.AveragePosition;
                     this._reformPosition = this.formation.QuerySystem.AveragePosition + vec2_1.Normalized() * 5f;
                     medianPosition.SetVec2(this._reformPosition);
                 }
                 this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
             }
         }
         if (flag)
         {
             return;
         }
         this._reformPosition = Vec2.Invalid;
         WorldPosition position = this.formation.Team.QuerySystem.EnemyTeams.SelectMany <TeamQuerySystem, Formation>((Func <TeamQuerySystem, IEnumerable <Formation> >)(t => t.Team.FormationsIncludingSpecial)).Count <Formation>() == 1 ? this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition : this.formation.QuerySystem.Team.MedianTargetFormationPosition;
         vec2_1 = this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this.formation.QuerySystem.AveragePosition;
         Vec2 direction = vec2_1.Normalized();
         this.CurrentOrder       = MovementOrder.MovementOrderMove(position);
         this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
     }
 }
Exemple #12
0
 protected override void CalculateCurrentOrder()
 {
     if (this._flagpositions.Any <FlagCapturePoint>())
     {
         this.CurrentOrder = MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, this._flagpositions.First <FlagCapturePoint>().Position, false));
     }
     else
     {
         this.CurrentOrder = MovementOrder.MovementOrderStop;
     }
 }
        public BehaviorUseMurderHole(Formation formation)
            : base(formation)
        {
            this.behaviorSide = formation.AI.Side;
            WorldPosition position = new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, (formation.Team.TeamAI as TeamAISiegeDefender).MurderHolePosition, false);

            this._outerGate        = (formation.Team.TeamAI as TeamAISiegeDefender).OuterGate;
            this._innerGate        = (formation.Team.TeamAI as TeamAISiegeDefender).InnerGate;
            this._batteringRam     = Mission.Current.ActiveMissionObjects.FindAllWithType <BatteringRam>().FirstOrDefault <BatteringRam>();
            this.CurrentOrder      = MovementOrder.MovementOrderMove(position);
            this.BehaviorCoherence = 0.0f;
        }
        static bool PrefixGetSubstituteOrder(MovementOrder __instance, ref MovementOrder __result, Formation formation)
        {
            if (formation != null && formation.QuerySystem.IsInfantryFormation && __instance.OrderType == OrderType.ChargeWithTarget)
            {
                var position = formation.QuerySystem.MedianPosition;
                position.SetVec2(formation.CurrentPosition);
                __result = MovementOrder.MovementOrderMove(position);
                return(false);
            }

            return(true);
        }
            static void PostfixCalculateCurrentOrder(Formation ____mainFormation, Formation ___formation, ref MovementOrder ____currentOrder, ref FacingOrder ___CurrentFacingOrder)
            {
                if (____mainFormation != null && ___formation != null)
                {
                    ___CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(____mainFormation.Direction);

                    WorldPosition medianPosition = ____mainFormation.QuerySystem.MedianPosition;
                    //medianPosition.SetVec2(medianPosition.AsVec2 - ____mainFormation.Direction * ((____mainFormation.Depth + ___formation.Depth) * 1.5f));
                    medianPosition.SetVec2(medianPosition.AsVec2 - ____mainFormation.Direction * ((____mainFormation.Depth + ___formation.Depth) * 0.25f + 0.0f));
                    ____currentOrder = MovementOrder.MovementOrderMove(medianPosition);
                }
            }
Exemple #16
0
 public override void OnMissionTick(float dt)
 {
     base.OnMissionTick(dt);
     if (!this._IsNewlyPopulatedFormationGivenOrder)
     {
         foreach (Formation formation in this.Mission.Teams.Where <Team>((Func <Team, bool>)(t => t.Side == BattleSideEnum.Defender)).SelectMany <Team, Formation>((Func <Team, IEnumerable <Formation> >)(t => t.FormationsIncludingSpecial)))
         {
             formation.MovementOrder = MovementOrder.MovementOrderMove(formation.QuerySystem.MedianPosition);
             this._IsNewlyPopulatedFormationGivenOrder = true;
         }
     }
     this._dtSum = 0.0f;
 }
            static void PostfixCalculateCurrentOrder(Formation ____mainFormation, Formation ___formation, ref MovementOrder ____currentOrder, ref FacingOrder ___CurrentFacingOrder)
            {
                if (____mainFormation != null && ___formation != null)
                {
                    MethodInfo method = typeof(FacingOrder).GetMethod("FacingOrderLookAtDirection", BindingFlags.NonPublic | BindingFlags.Static);
                    method.DeclaringType.GetMethod("FacingOrderLookAtDirection");
                    ___CurrentFacingOrder = (FacingOrder)method.Invoke(___CurrentFacingOrder, new object[] { ____mainFormation.Direction });

                    WorldPosition medianPosition = ____mainFormation.QuerySystem.MedianPosition;
                    //medianPosition.SetVec2(medianPosition.AsVec2 - ____mainFormation.Direction * ((____mainFormation.Depth + ___formation.Depth) * 1.5f));
                    medianPosition.SetVec2(medianPosition.AsVec2 - ____mainFormation.Direction * ((____mainFormation.Depth + ___formation.Depth) * 0.25f + 0.0f));
                    ____currentOrder = MovementOrder.MovementOrderMove(medianPosition);
                }
            }
        static void PostfixCalculateCurrentOrder(ref Formation ___formation, BehaviorSkirmish __instance, ref BehaviorState ____behaviorState, ref MovementOrder ____currentOrder)
        {
            if (___formation != null && ___formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation != null)
            {
                Vec2  enemyDirection = ___formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2 - ___formation.QuerySystem.AveragePosition;
                float distance       = enemyDirection.Normalize();

                switch (____behaviorState)
                {
                case BehaviorState.Shooting:
                    if (waitCountShooting > 50)
                    {
                        if (___formation.QuerySystem.MakingRangedAttackRatio < 0.4f && distance > 30f)
                        {
                            WorldPosition medianPosition = ___formation.QuerySystem.MedianPosition;
                            medianPosition.SetVec2(medianPosition.AsVec2 + ___formation.Direction * 5f);
                            ____currentOrder = MovementOrder.MovementOrderMove(medianPosition);
                        }
                        waitCountShooting = 0;
                    }
                    else
                    {
                        waitCountShooting++;
                    }

                    break;

                case BehaviorState.Approaching:
                    if (waitCountApproaching > 20)
                    {
                        if (distance < 200f)
                        {
                            WorldPosition medianPosition = ___formation.QuerySystem.MedianPosition;
                            medianPosition.SetVec2(medianPosition.AsVec2 + enemyDirection * 5f);
                            approachingRanging = medianPosition.AsVec2;
                            ____currentOrder   = MovementOrder.MovementOrderMove(medianPosition);
                        }
                        waitCountApproaching = 0;
                    }
                    else
                    {
                        WorldPosition medianPosition = ___formation.QuerySystem.MedianPosition;
                        medianPosition.SetVec2(approachingRanging);
                        ____currentOrder = MovementOrder.MovementOrderMove(medianPosition);
                        waitCountApproaching++;
                    }
                    break;
                }
            }
        }
Exemple #19
0
        private MovementOrder UncapturedFlagMoveOrder()
        {
            if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team)))
            {
                FlagCapturePoint flagCapturePoint = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => this.formation.Team.QuerySystem.GetLocalEnemyPower(fp.Position.AsVec2)));
                return(MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, flagCapturePoint.Position, false)));
            }
            if (!this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) == this.formation.Team)))
            {
                return(MovementOrder.MovementOrderStop);
            }
            Vec3 position = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) == this.formation.Team)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => fp.Position.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition))).Position;

            return(MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, position, false)));
        }
        protected override void CalculateCurrentOrder()
        {
            WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;

            if (this.formation.QuerySystem.ClosestEnemyFormation == null)
            {
                medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
                this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
            }
            else
            {
                Vec2 vec2 = (this.formation.QuerySystem.AveragePosition - this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2).Normalized();
                medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition + 50f * vec2);
                this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
            }
        }
 protected override void CalculateCurrentOrder()
 {
     if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null || (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition) > 2500.0)
     {
         this.CurrentOrder       = this.UncapturedFlagMoveOrder();
         this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
     }
     else
     {
         FlagCapturePoint flagCapturePoint = (FlagCapturePoint)null;
         if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team && !fp.IsContested)))
         {
             flagCapturePoint = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team && !fp.IsContested)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => this.formation.QuerySystem.AveragePosition.DistanceSquared(fp.Position.AsVec2)));
         }
         if (!this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsInfantryFormation && flagCapturePoint != null)
         {
             this.CurrentOrder       = MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, flagCapturePoint.Position, false));
             this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
         }
         else if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedFormation)
         {
             this.CurrentOrder       = MovementOrder.MovementOrderChargeToTarget(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.Formation);
             this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
         }
         else
         {
             Vec2          direction      = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition;
             float         num            = direction.Normalize();
             WorldPosition medianPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition;
             if ((double)num > (double)this.formation.QuerySystem.MissileRange)
             {
                 medianPosition.SetVec2(medianPosition.AsVec2 - direction * (this.formation.QuerySystem.MissileRange - this.formation.Depth * 0.5f));
             }
             else if ((double)num < (double)this.formation.QuerySystem.MissileRange * 0.400000005960464)
             {
                 medianPosition.SetVec2(medianPosition.AsVec2 - direction * (this.formation.QuerySystem.MissileRange * 0.7f));
             }
             else
             {
                 direction = direction.RightVec();
                 medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition + direction * 20f);
             }
             this.CurrentOrder       = MovementOrder.MovementOrderMove(medianPosition);
             this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
         }
     }
 }
Exemple #22
0
        public static bool GetSubstituteOrder_Prefix(MovementOrder __instance, ref MovementOrder __result,
                                                     Formation formation)
        {
            if (__instance.OrderType == OrderType.ChargeWithTarget && CommandSystemConfig.Get().AttackSpecificFormation)
            {
                var position = formation.QuerySystem.MedianPosition;
                position.SetVec2(formation.CurrentPosition);
                if (formation.Team == Mission.Current.PlayerTeam)
                {
                    Utility.DisplayFormationReadyMessage(formation);
                }
                __result = MovementOrder.MovementOrderMove(position);
                return(false);
            }

            return(true);
        }
Exemple #23
0
        protected override void CalculateCurrentOrder()
        {
            Vec2 direction = this.TacticalDefendPosition == null ? (this.formation.QuerySystem.ClosestEnemyFormation != null ? ((double)this.formation.Direction.DotProduct((this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition).Normalized()) < 0.5 ? this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition : this.formation.Direction).Normalized() : this.formation.Direction) : this.TacticalDefendPosition.Direction;

            if (this.TacticalDefendPosition != null)
            {
                this.CurrentOrder       = MovementOrder.MovementOrderMove(this.TacticalDefendPosition.Position);
                this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
            }
            else
            {
                WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;
                medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
                this.CurrentOrder       = MovementOrder.MovementOrderMove(medianPosition);
                this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
            }
        }
            protected override void CalculateCurrentOrder()
            {
                FieldInfo property = typeof(BehaviorComponent).GetField("formation", BindingFlags.NonPublic | BindingFlags.Instance);

                property.DeclaringType.GetField("formation");
                property.SetValue(this, attackingFormation, BindingFlags.NonPublic | BindingFlags.SetProperty, null, null);

                PropertyInfo PreserveExpireTimeInfo = typeof(BehaviorComponent).GetProperty("PreserveExpireTime", BindingFlags.NonPublic | BindingFlags.Instance);

                PreserveExpireTimeInfo.DeclaringType.GetProperty("PreserveExpireTime");
                PreserveExpireTimeInfo.SetValue(this, 0f, BindingFlags.NonPublic, null, null, null);

                FieldInfo _navmeshlessTargetPenaltyTimeInfo = typeof(BehaviorComponent).GetField("_navmeshlessTargetPenaltyTime", BindingFlags.NonPublic | BindingFlags.Instance);

                _navmeshlessTargetPenaltyTimeInfo.DeclaringType.GetField("_navmeshlessTargetPenaltyTime");
                _navmeshlessTargetPenaltyTimeInfo.SetValue(this, new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 20f), BindingFlags.NonPublic, null, null);

                WorldPosition position;

                if (attackingFormation != null && victimFormation != null && attackingFormation.QuerySystem.ClosestEnemyFormation != null)
                {
                    Vec2 vec;
                    if (attackingFormation.AI.Side == FormationAI.BehaviorSide.Left)
                    {
                        Vec2 v = (attackingFormation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - victimFormation.QuerySystem.MedianPosition.AsVec2).Normalized();
                        vec  = victimFormation.CurrentPosition + v.LeftVec().Normalized() * (victimFormation.Width + attackingFormation.Width + 5f);
                        vec -= v * (victimFormation.Depth + attackingFormation.Depth);
                    }
                    else
                    {
                        Vec2 v = (attackingFormation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - victimFormation.QuerySystem.MedianPosition.AsVec2).Normalized();
                        vec  = victimFormation.CurrentPosition + v.RightVec().Normalized() * (victimFormation.Width + attackingFormation.Width + 5f);
                        vec -= v * (victimFormation.Depth + attackingFormation.Depth);
                    }

                    WorldPosition medianPosition = victimFormation.QuerySystem.MedianPosition;
                    medianPosition.SetVec2(vec);
                    //position = (attackingFormation.AI.Side == FormationAI.BehaviorSide.Right) ? victimFormation.QuerySystem.Team.RightFlankEdgePosition : victimFormation.QuerySystem.Team.LeftFlankEdgePosition;
                    //Vec2 direction = (position.AsVec2 - attackingFormation.QuerySystem.AveragePosition).Normalized();
                    base.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
                }
                //CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
            }
        private void ResetOrderPositions()
        {
            this._primarySiegeWeapons = Mission.Current.ActiveMissionObjects.FindAllWithType <UsableMachine>().Where <UsableMachine>((Func <UsableMachine, bool>)(amo => amo is IPrimarySiegeWeapon)).Select <UsableMachine, IPrimarySiegeWeapon>((Func <UsableMachine, IPrimarySiegeWeapon>)(amo => amo as IPrimarySiegeWeapon)).ToList <IPrimarySiegeWeapon>();
            this._primarySiegeWeapons.RemoveAll((Predicate <IPrimarySiegeWeapon>)(uM => uM.WeaponSide != this.behaviorSide));
            IEnumerable <ICastleKeyPosition> source = TeamAISiegeComponent.SiegeLanes.Where <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide)).SelectMany <SiegeLane, ICastleKeyPosition>((Func <SiegeLane, IEnumerable <ICastleKeyPosition> >)(sila => (IEnumerable <ICastleKeyPosition>)sila.DefensePoints));

            this._innerGate   = this._teamAISiegeComponent.InnerGate;
            this._isGateLane  = this._teamAISiegeComponent.OuterGate.DefenseSide == this.behaviorSide;
            this._wallSegment = !this._isGateLane ? (!(source.FirstOrDefault <ICastleKeyPosition>((Func <ICastleKeyPosition, bool>)(dp => dp is WallSegment && (dp as WallSegment).IsBreachedWall)) is WallSegment wallSegment) ? this._primarySiegeWeapons.MaxBy <IPrimarySiegeWeapon, float>((Func <IPrimarySiegeWeapon, float>)(psw => psw.SiegeWeaponPriority)).TargetCastlePosition as WallSegment : wallSegment) : (WallSegment)null;
            this._stopOrder   = MovementOrder.MovementOrderStop;
            this._chargeOrder = MovementOrder.MovementOrderCharge;
            bool flag = this._teamAISiegeComponent.OuterGate != null && this.behaviorSide == this._teamAISiegeComponent.OuterGate.DefenseSide;

            this._attackEntityOrderOuterGate = !flag || this._teamAISiegeComponent.OuterGate.IsDeactivated || this._teamAISiegeComponent.OuterGate.State == CastleGate.GateState.Open ? MovementOrder.MovementOrderStop : MovementOrder.MovementOrderAttackEntity(this._teamAISiegeComponent.OuterGate.GameEntity, false);
            this._attackEntityOrderInnerGate = !flag || this._teamAISiegeComponent.InnerGate == null || (this._teamAISiegeComponent.InnerGate.IsDeactivated || this._teamAISiegeComponent.InnerGate.State == CastleGate.GateState.Open) ? MovementOrder.MovementOrderStop : MovementOrder.MovementOrderAttackEntity(this._teamAISiegeComponent.InnerGate.GameEntity, false);
            this._castleGateMoveOrder        = MovementOrder.MovementOrderMove(this._teamAISiegeComponent.OuterGate.MiddleFrame.Origin);
            this._wallSegmentMoveOrder       = !this._isGateLane ? MovementOrder.MovementOrderMove(this._wallSegment.MiddleFrame.Origin) : this._castleGateMoveOrder;
            this._facingOrder = FacingOrder.FacingOrderLookAtEnemy;
        }
        protected override void CalculateCurrentOrder()
        {
            Vec2          direction;
            WorldPosition medianPosition;

            if (this._mainFormation != null)
            {
                direction = this._mainFormation.Direction;
                Vec2 vec2 = (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this._mainFormation.QuerySystem.MedianPosition.AsVec2).Normalized();
                medianPosition = this._mainFormation.QuerySystem.MedianPosition;
                medianPosition.SetVec2(this._mainFormation.CurrentPosition + vec2 * (float)(((double)this._mainFormation.Depth + (double)this.formation.Depth) * 0.5 + 10.0));
            }
            else
            {
                direction      = this.formation.Direction;
                medianPosition = this.formation.QuerySystem.MedianPosition;
                medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
            }
            this.CurrentOrder       = MovementOrder.MovementOrderMove(medianPosition);
            this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
        }
Exemple #27
0
        private void ResetOrderPositions()
        {
            SiegeLane  siegeLane  = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == FormationAI.BehaviorSide.Middle));
            WorldFrame worldFrame = (siegeLane != null ? siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>()?.DefenseWaitFrame : new WorldFrame?()) ?? WorldFrame.Invalid;

            this._gatheringTacticalPos = siegeLane != null?siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>()?.WaitPosition : (TacticalPosition)null;

            if (this._gatheringTacticalPos != null)
            {
                this._gatherOrder = MovementOrder.MovementOrderMove(this._gatheringTacticalPos.Position);
            }
            else if (worldFrame.Origin.IsValid)
            {
                double num = (double)worldFrame.Rotation.f.Normalize();
                this._gatherOrder = MovementOrder.MovementOrderMove(worldFrame.Origin);
            }
            else
            {
                this._gatherOrder = MovementOrder.MovementOrderMove(this.formation.QuerySystem.MedianPosition);
            }
            this._attackOrder = MovementOrder.MovementOrderCharge;
            this.CurrentOrder = this._calculateShouldStartAttacking ? this._attackOrder : this._gatherOrder;
        }
        static void PostfixCalculateCurrentOrder(ref Formation ___formation, BehaviorSkirmish __instance, ref BehaviorState ____behaviorState, ref MovementOrder ____currentOrder)
        {
            switch (____behaviorState)
            {
            case BehaviorState.Shooting:
                if (waitCount > 50)
                {
                    if (___formation != null && ___formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation != null && ___formation.QuerySystem.MakingRangedAttackRatio < 0.4f && ___formation.QuerySystem.MedianPosition.AsVec2.Distance(___formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.Formation.QuerySystem.MedianPosition.AsVec2) > 30f)
                    {
                        WorldPosition medianPosition = ___formation.QuerySystem.MedianPosition;
                        medianPosition.SetVec2(medianPosition.AsVec2 + ___formation.Direction * 5f);
                        ____currentOrder = MovementOrder.MovementOrderMove(medianPosition);
                    }
                    waitCount = 0;
                }
                else
                {
                    waitCount++;
                }

                break;
            }
        }
        static bool PrefixCalculateCurrentOrder(ref Formation ___formation, ref MovementOrder ____currentOrder, ref FacingOrder ___CurrentFacingOrder)
        {
            if (___formation != null && ___formation.QuerySystem.IsInfantryFormation && ___formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation != null)
            {
                Formation significantEnemy = Utilities.FindSignificantEnemy(___formation, true, true, false, false, false);
                if (significantEnemy != null)
                {
                    ___formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLine;
                    ___formation.FiringOrder      = FiringOrder.FiringOrderFireAtWill;
                    ___formation.FormOrder        = FormOrder.FormOrderWide;
                    ___formation.WeaponUsageOrder = WeaponUsageOrder.WeaponUsageOrderUseAny;

                    WorldPosition medianPosition = ___formation.QuerySystem.MedianPosition;
                    ____currentOrder = MovementOrder.MovementOrderMove(medianPosition);

                    Vec2 direction = (significantEnemy.QuerySystem.MedianPosition.AsVec2 - ___formation.QuerySystem.AveragePosition).Normalized();
                    ___CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);

                    return(false);
                }
            }
            return(true);
        }
 protected override void CalculateCurrentOrder()
 {
     if (this._mainFormation == null || this.formation.AI.IsMainFormation || this.formation.QuerySystem.ClosestEnemyFormation == null)
     {
         this.CurrentOrder       = MovementOrder.MovementOrderStop;
         this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
     }
     else
     {
         if (this._protectFlankState != BehaviorProtectFlank.BehaviourState.HoldingFlank && this._protectFlankState != BehaviorProtectFlank.BehaviourState.Returning)
         {
             return;
         }
         Vec2          direction      = this._mainFormation.Direction;
         Vec2          vec2_1         = (this.formation.QuerySystem.Team.MedianTargetFormationPosition.AsVec2 - this._mainFormation.QuerySystem.MedianPosition.AsVec2).Normalized();
         Vec2          vec2_2         = this.behaviorSide == FormationAI.BehaviorSide.Right || this.FlankSide == FormationAI.BehaviorSide.Right ? this._mainFormation.CurrentPosition + vec2_1.RightVec().Normalized() * (float)((double)this._mainFormation.Width + (double)this.formation.Width + 10.0) - vec2_1 * (this._mainFormation.Depth + this.formation.Depth) : (this.behaviorSide == FormationAI.BehaviorSide.Left || this.FlankSide == FormationAI.BehaviorSide.Left ? this._mainFormation.CurrentPosition + vec2_1.LeftVec().Normalized() * (float)((double)this._mainFormation.Width + (double)this.formation.Width + 10.0) - vec2_1 * (this._mainFormation.Depth + this.formation.Depth) : this._mainFormation.CurrentPosition + vec2_1 * (float)(((double)this._mainFormation.Depth + (double)this.formation.Depth) * 0.5 + 10.0));
         WorldPosition medianPosition = this._mainFormation.QuerySystem.MedianPosition;
         medianPosition.SetVec2(vec2_2);
         this._movementOrder     = MovementOrder.MovementOrderMove(medianPosition);
         this.CurrentOrder       = this._movementOrder;
         this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
     }
 }