Beispiel #1
0
 private static float GetMinimumDistanceBetweenPositions(
     Vec3 position,
     IEnumerable <ICastleKeyPosition> referencePositions,
     out ICastleKeyPosition closestCastlePosition)
 {
     if (referencePositions != null && referencePositions.Count <ICastleKeyPosition>() != 0)
     {
         closestCastlePosition = referencePositions.MinBy <ICastleKeyPosition, float>((Func <ICastleKeyPosition, float>)(rp => rp.GetPosition().DistanceSquared(position)));
         return((float)Math.Sqrt((double)closestCastlePosition.GetPosition().DistanceSquared(position)));
     }
     closestCastlePosition = (ICastleKeyPosition)null;
     return(-1f);
 }
Beispiel #2
0
        private void ResetOrderPositions()
        {
            this.behaviorSide = this.formation.AI.Side;
            this._innerGate   = (CastleGate)null;
            this._outerGate   = (CastleGate)null;
            this._laddersOnThisSide.Clear();
            int num1 = Mission.Current.ActiveMissionObjects.FindAllWithType <CastleGate>().Any <CastleGate>((Func <CastleGate, bool>)(cg => cg.DefenseSide == this.behaviorSide && cg.GameEntity.HasTag("outer_gate"))) ? 1 : 0;

            this._isDefendingWideGap = false;
            WorldFrame worldFrame1;
            WorldFrame worldFrame2;

            if (num1 != 0)
            {
                CastleGate outerGate = this._teamAISiegeDefender.OuterGate;
                this._innerGate          = this._teamAISiegeDefender.InnerGate;
                this._outerGate          = this._teamAISiegeDefender.OuterGate;
                worldFrame1              = outerGate.MiddleFrame;
                worldFrame2              = outerGate.DefenseWaitFrame;
                this._tacticalMiddlePos  = outerGate.MiddlePosition;
                this._tacticalWaitPos    = outerGate.WaitPosition;
                this._isDefendingWideGap = false;
            }
            else
            {
                WallSegment wallSegment = Mission.Current.ActiveMissionObjects.FindAllWithType <WallSegment>().Where <WallSegment>((Func <WallSegment, bool>)(ws => ws.DefenseSide == this.behaviorSide && ws.IsBreachedWall)).FirstOrDefault <WallSegment>();
                if (wallSegment != null)
                {
                    worldFrame1              = wallSegment.MiddleFrame;
                    worldFrame2              = wallSegment.DefenseWaitFrame;
                    this._tacticalMiddlePos  = wallSegment.MiddlePosition;
                    this._tacticalWaitPos    = wallSegment.WaitPosition;
                    this._isDefendingWideGap = false;
                }
                else
                {
                    IEnumerable <SiegeWeapon> source = Mission.Current.ActiveMissionObjects.FindAllWithType <SiegeWeapon>().Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(sw =>
                    {
                        if (!(sw is IPrimarySiegeWeapon) || (sw as IPrimarySiegeWeapon).WeaponSide != this.behaviorSide)
                        {
                            return(false);
                        }
                        return(!sw.IsDestroyed || (sw as IPrimarySiegeWeapon).HasCompletedAction());
                    }));
                    if (!source.Any <SiegeWeapon>())
                    {
                        worldFrame1             = WorldFrame.Invalid;
                        worldFrame2             = WorldFrame.Invalid;
                        this._tacticalMiddlePos = (TacticalPosition)null;
                        this._tacticalWaitPos   = (TacticalPosition)null;
                    }
                    else
                    {
                        this._laddersOnThisSide = source.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(aw => aw is SiegeLadder)).Select <SiegeWeapon, SiegeLadder>((Func <SiegeWeapon, SiegeLadder>)(aw => aw as SiegeLadder)).ToList <SiegeLadder>();
                        ICastleKeyPosition targetCastlePosition = (source.FirstOrDefault <SiegeWeapon>() as IPrimarySiegeWeapon).TargetCastlePosition as ICastleKeyPosition;
                        worldFrame1             = targetCastlePosition.MiddleFrame;
                        worldFrame2             = targetCastlePosition.DefenseWaitFrame;
                        this._tacticalMiddlePos = targetCastlePosition.MiddlePosition;
                        this._tacticalWaitPos   = targetCastlePosition.WaitPosition;
                    }
                }
            }
            if (this._tacticalMiddlePos != null)
            {
                this._readyOrder       = MovementOrder.MovementOrderMove(this._tacticalMiddlePos.Position);
                this._readyFacingOrder = FacingOrder.FacingOrderLookAtDirection(this._tacticalMiddlePos.Direction);
            }
            else if (worldFrame1.Origin.IsValid)
            {
                double num2 = (double)worldFrame1.Rotation.f.Normalize();
                this._readyOrder       = MovementOrder.MovementOrderMove(worldFrame1.Origin);
                this._readyFacingOrder = FacingOrder.FacingOrderLookAtDirection(worldFrame1.Rotation.f.AsVec2);
            }
            else
            {
                this._readyOrder       = MovementOrder.MovementOrderStop;
                this._readyFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
            }
            if (this._tacticalWaitPos != null)
            {
                this._waitOrder       = MovementOrder.MovementOrderMove(this._tacticalWaitPos.Position);
                this._waitFacingOrder = FacingOrder.FacingOrderLookAtDirection(this._tacticalWaitPos.Direction);
            }
            else if (worldFrame2.Origin.IsValid)
            {
                double num2 = (double)worldFrame2.Rotation.f.Normalize();
                this._waitOrder       = MovementOrder.MovementOrderMove(worldFrame2.Origin);
                this._waitFacingOrder = FacingOrder.FacingOrderLookAtDirection(worldFrame2.Rotation.f.AsVec2);
            }
            else
            {
                this._waitOrder       = MovementOrder.MovementOrderStop;
                this._waitFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
            }
            this.CurrentOrder       = this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyOrder : this._waitOrder;
            this.CurrentFacingOrder = this.formation.QuerySystem.ClosestEnemyFormation == null || !TeamAISiegeComponent.IsFormationInsideCastle(this.formation.QuerySystem.ClosestEnemyFormation.Formation, true) ? (this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyFacingOrder : this._waitFacingOrder) : FacingOrder.FacingOrderLookAtEnemy;
        }