示例#1
0
 public static void StopUsingMachine(
     this Formation formation,
     UsableMachine usable,
     bool isPlayerOrder = false)
 {
     if (!isPlayerOrder && !formation.IsAIControlled)
     {
         return;
     }
     formation.LeaveDetachment((IDetachment)usable);
 }
示例#2
0
 public static void StartUsingMachine(
     this Formation formation,
     UsableMachine usable,
     bool isPlayerOrder = false)
 {
     if (!isPlayerOrder && (!formation.IsAIControlled || Mission.Current.IsMissionEnding))
     {
         return;
     }
     formation.JoinDetachment((IDetachment)usable);
 }
        private void RecreateFollowEntityOrder()
        {
            this._followEntityOrder = MovementOrder.MovementOrderStop;
            UsableMachine usableMachine = this._primarySiegeWeapons.Where <UsableMachine>((Func <UsableMachine, bool>)(psw => !psw.IsDeactivated && psw is IPrimarySiegeWeapon && !(psw as IPrimarySiegeWeapon).HasCompletedAction())).FirstOrDefault <UsableMachine>();

            if (usableMachine == null)
            {
                return;
            }
            this._followEntityOrder = MovementOrder.MovementOrderFollowEntity(usableMachine.WaitEntity);
        }
 public static void SiegeDebug(UsableMachine usableMachine)
 {
     if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtRam"))
     {
         DebugSiegeBehaviour.DebugDefendState = DebugSiegeBehaviour.DebugStateDefender.DebugDefendersToRam;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtSt"))
     {
         DebugSiegeBehaviour.DebugDefendState = DebugSiegeBehaviour.DebugStateDefender.DebugDefendersToTower;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtBallistas2"))
     {
         DebugSiegeBehaviour.DebugDefendState = DebugSiegeBehaviour.DebugStateDefender.DebugDefendersToBallistae;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtMangonels2"))
     {
         DebugSiegeBehaviour.DebugDefendState = DebugSiegeBehaviour.DebugStateDefender.DebugDefendersToMangonels;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtNone2"))
     {
         DebugSiegeBehaviour.DebugDefendState = DebugSiegeBehaviour.DebugStateDefender.None;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtBallistas"))
     {
         DebugSiegeBehaviour.DebugAttackState = DebugSiegeBehaviour.DebugStateAttacker.DebugAttackersToBallistae;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtMangonels"))
     {
         DebugSiegeBehaviour.DebugAttackState = DebugSiegeBehaviour.DebugStateAttacker.DebugAttackersToMangonels;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtBattlements"))
     {
         DebugSiegeBehaviour.DebugAttackState = DebugSiegeBehaviour.DebugStateAttacker.DebugAttackersToBattlements;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyAimAtNone"))
     {
         DebugSiegeBehaviour.DebugAttackState = DebugSiegeBehaviour.DebugStateAttacker.None;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyTargetDebugActive"))
     {
         DebugSiegeBehaviour.ToggleTargetDebug = true;
     }
     else if (Input.DebugInput.IsHotKeyPressed("DebugSiegeBehaviourHotkeyTargetDebugDisactive"))
     {
         DebugSiegeBehaviour.ToggleTargetDebug = false;
     }
     int num = DebugSiegeBehaviour.ToggleTargetDebug ? 1 : 0;
 }
 protected internal override void TickOccasionally()
 {
     this._behaviourState = this.CheckAndChangeState();
     this.CalculateCurrentOrder();
     foreach (IPrimarySiegeWeapon primarySiegeWeapon in this._primarySiegeWeapons)
     {
         UsableMachine usable = primarySiegeWeapon as UsableMachine;
         if (!usable.IsDeactivated && !primarySiegeWeapon.HasCompletedAction() && !this.formation.IsUsingMachine(usable))
         {
             this.formation.StartUsingMachine(primarySiegeWeapon as UsableMachine);
         }
     }
     if (this._behaviourState == BehaviorAssaultWalls.BehaviorState.MoveToGate)
     {
         CastleGate innerGate = this._teamAISiegeComponent.InnerGate;
         if (innerGate != null && !innerGate.IsGateOpen && !innerGate.IsDestroyed)
         {
             if (!this.formation.IsUsingMachine((UsableMachine)innerGate))
             {
                 this.formation.StartUsingMachine((UsableMachine)innerGate);
             }
         }
         else
         {
             CastleGate outerGate = this._teamAISiegeComponent.OuterGate;
             if (outerGate != null && !outerGate.IsGateOpen && (!outerGate.IsDestroyed && !this.formation.IsUsingMachine((UsableMachine)outerGate)))
             {
                 this.formation.StartUsingMachine((UsableMachine)outerGate);
             }
         }
     }
     else
     {
         if (this.formation.Detachments.Contains((IDetachment)this._teamAISiegeComponent.OuterGate))
         {
             this.formation.StopUsingMachine((UsableMachine)this._teamAISiegeComponent.OuterGate);
         }
         if (this.formation.Detachments.Contains((IDetachment)this._teamAISiegeComponent.InnerGate))
         {
             this.formation.StopUsingMachine((UsableMachine)this._teamAISiegeComponent.InnerGate);
         }
     }
     this.formation.MovementOrder    = this.CurrentOrder;
     this.formation.FacingOrder      = this.CurrentFacingOrder;
     this.formation.ArrangementOrder = this.CurrentArrangementOrder;
 }
        public static Agent GetSuitableAgentForStandingPoint(
            UsableMachine usableMachine,
            StandingPoint standingPoint,
            IEnumerable <Agent> agents,
            List <Agent> usedAgents)
        {
            if (usableMachine.AmmoPickUpPoints.Contains(standingPoint) && usableMachine.StandingPoints.Any <StandingPoint>((Func <StandingPoint, bool>)(standingPoint2 => (standingPoint2.IsDeactivated || standingPoint2.HasUser || standingPoint2.HasAIMovingTo) && !standingPoint2.GameEntity.HasTag(usableMachine.AmmoPickUpTag) && standingPoint2 is StandingPointWithWeaponRequirement)))
            {
                return((Agent)null);
            }
            IEnumerable <Agent> source = agents.Where <Agent>((Func <Agent, bool>)(a =>
            {
                if (usedAgents.Contains(a) || !a.IsAIControlled || (!a.IsActive() || a.IsRunningAway) || (a.AIUseGameObjectIsEnabled() || a.AIMoveToGameObjectIsEnabled() || standingPoint.IsDisabledForAgent(a)))
                {
                    return(false);
                }
                return(a.Formation == null || !a.Formation.IsUnitDetached(a));
            }));

            return(!source.Any <Agent>() ? (Agent)null : source.MaxBy <Agent, float>((Func <Agent, float>)(a => standingPoint.GetUsageScoreForAgent(a))));
        }
示例#7
0
        public static Threat GetMaxThreat(List <ICastleKeyPosition> castleKeyPositions)
        {
            List <ITargetable> source1 = new List <ITargetable>();
            List <Threat>      source2 = new List <Threat>();

            foreach (GameEntity gameEntity in Mission.Current.ActiveMissionObjects.Select <MissionObject, GameEntity>((Func <MissionObject, GameEntity>)(amo => amo.GameEntity)))
            {
                UsableMachine firstScriptOfType = gameEntity.GetFirstScriptOfType <UsableMachine>();
                if (firstScriptOfType is ITargetable)
                {
                    source1.Add((ITargetable)firstScriptOfType);
                }
            }
            source1.RemoveAll((Predicate <ITargetable>)(um => um.GetSide() == BattleSideEnum.Defender));
            source2.AddRange(source1.Select <ITargetable, Threat>((Func <ITargetable, Threat>)(um => new Threat()
            {
                WeaponEntity = um,
                ThreatValue  = um.GetTargetValue(castleKeyPositions.Select <ICastleKeyPosition, Vec3>((Func <ICastleKeyPosition, Vec3>)(c => c.GetPosition())).ToList <Vec3>())
            })));
            return(source2.MaxBy <Threat, float>((Func <Threat, float>)(t => t.ThreatValue)));
        }
        public static Agent GetSuitableAgentForStandingPoint(
            UsableMachine usableMachine,
            StandingPoint standingPoint,
            IEnumerable <AgentValuePair <float> > agents,
            List <Agent> usedAgents,
            float weight)
        {
            if (usableMachine.IsStandingPointNotUsedOnAccountOfBeingAmmoLoad(standingPoint))
            {
                return((Agent)null);
            }
            IEnumerable <AgentValuePair <float> > source = agents.Where <AgentValuePair <float> >((Func <AgentValuePair <float>, bool>)(ap =>
            {
                Agent agent = ap.Agent;
                if (usedAgents.Contains(agent) || !agent.IsAIControlled || (!agent.IsActive() || agent.IsRunningAway) || (agent.AIUseGameObjectIsEnabled() || agent.AIMoveToGameObjectIsEnabled() || standingPoint.IsDisabledForAgent(agent)))
                {
                    return(false);
                }
                return(agent.Formation == null || !agent.Formation.IsUnitDetached(agent) || (double)agent.DetachmentWeight * 0.400000005960464 > (double)weight);
            }));

            return(!source.Any <AgentValuePair <float> >() ? (Agent)null : source.MaxBy <AgentValuePair <float>, float>((Func <AgentValuePair <float>, float>)(a => standingPoint.GetUsageScoreForAgent(a))).Agent);
        }
 protected UsableMachineAIBase(UsableMachine usableMachine)
 {
     this.UsableMachine = usableMachine;
     this._lastActiveWaitStandingPoint = this.UsableMachine.WaitEntity;
 }
示例#10
0
 public static bool IsUsingMachine(this Formation formation, UsableMachine usable) => formation.Detachments.Contains((IDetachment)usable);