public override void RearrangeFrom(IFormationArrangement arrangement)
 {
     if (arrangement is ColumnFormation)
     {
         int unitCount = arrangement.UnitCount;
         if (unitCount > 0)
         {
             int?fileCountStatic = FormOrder.GetFileCountStatic(((Formation)this.owner).FormOrder.OrderEnum, unitCount);
             if (fileCountStatic.HasValue)
             {
                 this.FormFromWidth((int)Math.Ceiling((double)unitCount * 1.0 / (double)fileCountStatic.Value));
             }
         }
     }
     base.RearrangeFrom(arrangement);
 }
Ejemplo n.º 2
0
 protected internal override void TickOccasionally()
 {
     this.CalculateCurrentOrder();
     this.formation.MovementOrder = this.CurrentOrder;
     this.formation.FacingOrder   = this.CurrentFacingOrder;
     if ((double)this.formation.QuerySystem.AveragePosition.Distance(this.CurrentOrder.GetPosition(this.formation).AsVec2) - (double)this.formation.Width < 10.0)
     {
         this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderCircle;
         if (!this.formation.Team.Formations.Any <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)))
         {
             return;
         }
         Formation formation = this.formation.Team.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)).MaxBy <Formation, int>((Func <Formation, int>)(f => f.CountOfUnits));
         int       num       = (int)Math.Sqrt((double)formation.CountOfUnits);
         this.formation.FormOrder = FormOrder.FormOrderCustom(((float)(((double)num * (double)formation.UnitDiameter + (double)(num - 1) * (double)formation.Interval) * 0.5 * 1.41421294212341) + this.formation.Depth) * 2f);
     }
     else
     {
         this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLoose;
     }
 }
 protected internal override void TickOccasionally()
 {
     this.CalculateCurrentOrder();
     this.formation.MovementOrder = this.CurrentOrder;
     this.formation.FacingOrder   = this.CurrentFacingOrder;
     if ((double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.CurrentOrder.GetPosition(this.formation).AsVec2) < 100.0)
     {
         if (this.formation.QuerySystem.HasShield)
         {
             this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLine;
         }
         else if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation != null && (double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2) > 100.0 && (double)this.formation.QuerySystem.UnderRangedAttackRatio > 0.200000002980232 - (this.formation.ArrangementOrder.OrderEnum == ArrangementOrder.ArrangementOrderEnum.Loose ? 0.100000001490116 : 0.0))
         {
             this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLoose;
         }
         if (this._tacticalDefendPosition == null)
         {
             return;
         }
         float customWidth;
         if (this._tacticalDefendPosition.TacticalPositionType == TacticalPosition.TacticalPositionTypeEnum.ChokePoint)
         {
             customWidth = this._tacticalDefendPosition.Width;
         }
         else
         {
             int countOfUnits = this.formation.CountOfUnits;
             customWidth = Math.Min(this._tacticalDefendPosition.Width, (float)((double)this.formation.Interval * (double)(countOfUnits - 1) + (double)this.formation.UnitDiameter * (double)countOfUnits) / 3f);
         }
         this.formation.FormOrder = FormOrder.FormOrderCustom(customWidth);
     }
     else
     {
         this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLoose;
     }
 }
Ejemplo n.º 4
0
        protected internal override void TickOccasionally()
        {
            base.TickOccasionally();
            BehaviorDefendCastleKeyPosition.BehaviourState behaviourState = (this._teamAISiegeDefender == null ? 0 : (TeamAISiegeComponent.SiegeLanes.Any <SiegeLane>((Func <SiegeLane, bool>)(sl =>
            {
                if (sl.LaneSide != this.behaviorSide)
                {
                    return(false);
                }
                return(sl.IsOpen || sl.PrimarySiegeWeapons.Any <IPrimarySiegeWeapon>((Func <IPrimarySiegeWeapon, bool>)(psw => psw is SiegeWeapon && (psw as SiegeWeapon).GetComponent <SiegeWeaponMovementComponent>() != null && (psw as SiegeWeapon).GetComponent <SiegeWeaponMovementComponent>().HasArrivedAtTarget)));
            })) ? 1 : 0)) != 0 ? BehaviorDefendCastleKeyPosition.BehaviourState.Ready : BehaviorDefendCastleKeyPosition.BehaviourState.Waiting;
            if (behaviourState != this._behaviourState)
            {
                this._behaviourState    = behaviourState;
                this.CurrentOrder       = this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyOrder : this._waitOrder;
                this.CurrentFacingOrder = this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyFacingOrder : this._waitFacingOrder;
            }
            if (Mission.Current.MissionTeamAIType == Mission.MissionTeamAITypeEnum.Siege)
            {
                if (this._outerGate != null && this._outerGate.State == CastleGate.GateState.Open && !this._outerGate.IsDestroyed)
                {
                    if (!this.formation.IsUsingMachine((UsableMachine)this._outerGate))
                    {
                        this.formation.StartUsingMachine((UsableMachine)this._outerGate);
                    }
                }
                else if (this._innerGate != null && this._innerGate.State == CastleGate.GateState.Open && (!this._innerGate.IsDestroyed && !this.formation.IsUsingMachine((UsableMachine)this._innerGate)))
                {
                    this.formation.StartUsingMachine((UsableMachine)this._innerGate);
                }
                foreach (SiegeLadder siegeLadder in this._laddersOnThisSide)
                {
                    if (!siegeLadder.IsDisabledForBattleSide(BattleSideEnum.Defender) && !this.formation.IsUsingMachine((UsableMachine)siegeLadder))
                    {
                        this.formation.StartUsingMachine((UsableMachine)siegeLadder);
                    }
                }
            }
            this.CalculateCurrentOrder();
            this.formation.MovementOrder = this.CurrentOrder;
            this.formation.FacingOrder   = this.CurrentFacingOrder;
            if (this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready && this._tacticalMiddlePos != null)
            {
                this.formation.FormOrder = FormOrder.FormOrderCustom(this._tacticalMiddlePos.Width);
            }
            else if (this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Waiting && this._tacticalWaitPos != null)
            {
                this.formation.FormOrder = FormOrder.FormOrderCustom(this._tacticalWaitPos.Width);
            }
            bool flag = this._isDefendingWideGap && this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready && this.formation.QuerySystem.ClosestEnemyFormation != null && (this.formation.QuerySystem.IsUnderRangedAttack || (double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.CurrentOrder.GetPosition(this.formation).AsVec2) < 25.0 + (this._isInShieldWallDistance ? 75.0 : 0.0));

            if (flag == this._isInShieldWallDistance)
            {
                return;
            }
            this._isInShieldWallDistance = flag;
            if (this._isInShieldWallDistance && this.formation.QuerySystem.HasShield)
            {
                if (!(this.formation.ArrangementOrder != ArrangementOrder.ArrangementOrderShieldWall))
                {
                    return;
                }
                this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderShieldWall;
            }
            else
            {
                if (!(this.formation.ArrangementOrder == ArrangementOrder.ArrangementOrderLine))
                {
                    return;
                }
                this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLine;
            }
        }