public SetRangedSiegeWeaponState(
     RangedSiegeWeapon rangedSiegeWeapon,
     RangedSiegeWeapon.WeaponState state)
 {
     this.RangedSiegeWeapon = rangedSiegeWeapon;
     this.State             = state;
 }
 public RangedSiegeWeaponAi(RangedSiegeWeapon rangedSiegeWeapon)
     : base((UsableMachine)rangedSiegeWeapon)
 {
     this.threatSeeker = new ThreatSeeker(rangedSiegeWeapon);
     (this.UsableMachine as RangedSiegeWeapon).OnReloadDone += new RangedSiegeWeapon.OnSiegeWeaponReloadDone(this.FindNextTarget);
     this._delayTimer            = this._delayDuration;
     this._targetEvaluationTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.5f);
 }
Example #3
0
        private static FormationAI.BehaviorSide GetSideOf(SiegeWeapon weapon)
        {
            if (weapon is IPrimarySiegeWeapon primarySiegeWeapon)
            {
                return(primarySiegeWeapon.WeaponSide);
            }
            RangedSiegeWeapon rangedSiegeWeapon = weapon as RangedSiegeWeapon;

            return(FormationAI.BehaviorSide.Middle);
        }
Example #4
0
        internal ThreatSeeker(RangedSiegeWeapon weapon)
        {
            this.Weapon          = weapon;
            this.WeaponPositions = new List <Vec3>();
            this.WeaponPositions.Add(this.Weapon.GameEntity.GlobalPosition);
            this.targetAgent = (Agent)null;
            IEnumerable <UsableMachine> allWithType = Mission.Current.ActiveMissionObjects.FindAllWithType <UsableMachine>();

            this._potentialTargetUsableMachines = allWithType.Where <UsableMachine>((Func <UsableMachine, bool>)(um => um is ITargetable && (um as ITargetable).GetSide() != this.Weapon.Side && (NativeObject)(um as ITargetable).GetTargetEntity() != (NativeObject)null)).Select <UsableMachine, ITargetable>((Func <UsableMachine, ITargetable>)(um => um as ITargetable)).ToList <ITargetable>();
            this._referencePositions            = allWithType.OfType <ICastleKeyPosition>().ToList <ICastleKeyPosition>();
        }
Example #5
0
 public RangedSiegeWeaponChangeProjectile(RangedSiegeWeapon rangedSiegeWeapon, int index)
 {
     this.RangedSiegeWeapon = rangedSiegeWeapon;
     this.Index             = index;
 }
 public SetRangedSiegeWeaponAmmo(RangedSiegeWeapon rangedSiegeWeapon, int ammoCount)
 {
     this.RangedSiegeWeapon = rangedSiegeWeapon;
     this.AmmoCount         = ammoCount;
 }
 protected override void OnTick(
     Func <Agent, bool> isAgentManagedByThisMachineAI,
     Team potentialUsersTeam,
     float dt)
 {
     base.OnTick(isAgentManagedByThisMachineAI, potentialUsersTeam, dt);
     if (this.UsableMachine.PilotAgent != null && this.UsableMachine.PilotAgent.IsAIControlled)
     {
         RangedSiegeWeapon usableMachine = this.UsableMachine as RangedSiegeWeapon;
         if (usableMachine.State == RangedSiegeWeapon.WeaponState.WaitingAfterShooting && usableMachine.PilotAgent != null && usableMachine.PilotAgent.IsAIControlled)
         {
             usableMachine.ManualReload();
         }
         if ((double)dt > 0.0 && this._target == null && usableMachine.State == RangedSiegeWeapon.WeaponState.Idle)
         {
             if ((double)this._delayTimer <= 0.0)
             {
                 this.FindNextTarget();
             }
             this._delayTimer -= dt;
         }
         if (this._target != null)
         {
             if (this._target.Agent != null && !this._target.Agent.IsActive())
             {
                 this._target = (Threat)null;
                 return;
             }
             if (usableMachine.State == RangedSiegeWeapon.WeaponState.Idle && usableMachine.UserCount > 0)
             {
                 if (DebugSiegeBehaviour.ToggleTargetDebug)
                 {
                     Agent pilotAgent = this.UsableMachine.PilotAgent;
                 }
                 if (this._targetEvaluationTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)) && !(this.UsableMachine as RangedSiegeWeapon).CanShootAtBox(this._target.BoundingBoxMin, this._target.BoundingBoxMax))
                 {
                     ++this._cannotShootCounter;
                 }
                 if (this._cannotShootCounter < 4)
                 {
                     if (usableMachine.AimAtTarget(this._target.Position) && usableMachine.PilotAgent != null)
                     {
                         this._delayTimer -= dt;
                         if ((double)this._delayTimer <= 0.0)
                         {
                             usableMachine.Shoot();
                             this._target = (Threat)null;
                             this.SetTargetingTimer();
                             this._cannotShootCounter = 0;
                             this._targetEvaluationTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
                         }
                     }
                 }
                 else
                 {
                     this._target = (Threat)null;
                     this.SetTargetingTimer();
                     this._cannotShootCounter = 0;
                 }
             }
             else
             {
                 this._targetEvaluationTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
             }
         }
     }
     this.AfterTick(isAgentManagedByThisMachineAI, potentialUsersTeam, dt);
 }
Example #8
0
        internal Threat GetTarget()
        {
            IEnumerable <Threat> allThreats = this.GetAllThreats();

            foreach (Threat threat in allThreats)
            {
                threat.ThreatValue *= (float)(0.899999976158142 + (double)MBRandom.RandomFloat * 0.200000002980232);
            }
            if (this.currentThreat != null)
            {
                this.currentThreat = allThreats.SingleOrDefault <Threat>((Func <Threat, bool>)(t => t.Equals((object)this.currentThreat)));
                if (this.currentThreat != null)
                {
                    this.currentThreat.ThreatValue *= 2f;
                }
            }
            IEnumerable <Threat> source = allThreats.Where <Threat>((Func <Threat, bool>)(t =>
            {
                if ((t.WeaponEntity != null || t.Agent != null) && this.Weapon.CanShootAtBox(t.BoundingBoxMin, t.BoundingBoxMax))
                {
                    return(true);
                }
                return(t.Formation != null && t.Formation.GetCountOfUnitsWithCondition((Func <Agent, bool>)(agent =>
                {
                    RangedSiegeWeapon weapon = this.Weapon;
                    CapsuleData collisionCapsule = agent.CollisionCapsule;
                    Vec3 boxMin = collisionCapsule.GetBoxMin();
                    collisionCapsule = agent.CollisionCapsule;
                    Vec3 boxMax = collisionCapsule.GetBoxMax();
                    return weapon.CanShootAtBox(boxMin, boxMax);
                })) > 0);
            }));

            if (source.IsEmpty <Threat>())
            {
                return((Threat)null);
            }
            this.currentThreat = source.MaxBy <Threat, float>((Func <Threat, float>)(t => t.ThreatValue));
            if (this.currentThreat.WeaponEntity == null)
            {
                if (this.targetAgent != null && this.targetAgent.IsActive() && this.currentThreat.Formation.HasUnitsWithCondition((Func <Agent, bool>)(agent => agent == this.targetAgent)))
                {
                    RangedSiegeWeapon weapon           = this.Weapon;
                    CapsuleData       collisionCapsule = this.targetAgent.CollisionCapsule;
                    Vec3 boxMin = collisionCapsule.GetBoxMin();
                    collisionCapsule = this.targetAgent.CollisionCapsule;
                    Vec3 boxMax = collisionCapsule.GetBoxMax();
                    if (weapon.CanShootAtBox(boxMin, boxMax))
                    {
                        goto label_15;
                    }
                }
                float selectedAgentScore = float.MaxValue;
                Agent selectedAgent      = this.targetAgent;
                this.currentThreat.Formation.ApplyActionOnEachUnit((Action <Agent>)(agent =>
                {
                    float num = agent.Position.DistanceSquared(this.Weapon.GameEntity.GlobalPosition) * (float)((double)MBRandom.RandomFloat * 0.200000002980232 + 0.800000011920929);
                    if (agent == this.targetAgent)
                    {
                        num *= 0.5f;
                    }
                    if ((double)selectedAgentScore <= (double)num || !this.Weapon.CanShootAtBox(agent.CollisionCapsule.GetBoxMin(), agent.CollisionCapsule.GetBoxMax()))
                    {
                        return;
                    }
                    selectedAgent      = agent;
                    selectedAgentScore = num;
                }));
                this.targetAgent         = selectedAgent ?? this.currentThreat.Formation.GetUnitWithIndex(MBRandom.RandomInt(this.currentThreat.Formation.CountOfUnits));
                this.currentThreat.Agent = this.targetAgent;
            }
label_15:
            this.targetAgent = (Agent)null;
            return(this.currentThreat.WeaponEntity == null && this.currentThreat.Agent == null ? (Threat)null : this.currentThreat);
        }