Ejemplo n.º 1
0
 internal void OnApply(Formation formation)
 {
     formation.SetPositioning(unitSpacing: new int?(this.GetUnitSpacing()));
     this.Rearrange(formation);
     if (this.OrderEnum == ArrangementOrder.ArrangementOrderEnum.Scatter)
     {
         this.TickOccasionally(formation);
     }
     ArrangementOrder.ArrangementOrderEnum orderEnum = this.OrderEnum;
     formation.ApplyActionOnEachUnit((Action <Agent>)(agent =>
     {
         if (agent.IsAIControlled)
         {
             Agent.UsageDirection shieldDirectionOfUnit = ArrangementOrder.GetShieldDirectionOfUnit(formation, agent, orderEnum);
             agent.EnforceShieldUsage(shieldDirectionOfUnit);
         }
         agent.UpdateAgentProperties();
     }));
     if (formation.MovementOrder.OrderEnum != MovementOrder.MovementOrderEnum.Charge && formation.MovementOrder.OrderEnum != MovementOrder.MovementOrderEnum.ChargeToTarget)
     {
         if (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Circle && this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.ShieldWall && (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Square && this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Column))
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetDefaultMoveBehaviorValues));
         }
         else if (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Column)
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetDefensiveArrangementMoveBehaviorValues));
         }
         else
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetFollowBehaviorValues));
         }
     }
     this.tickTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.5f);
 }
Ejemplo n.º 2
0
 internal void OnCancel(Formation formation)
 {
     if (this.OrderEnum == ArrangementOrder.ArrangementOrderEnum.Scatter)
     {
         foreach (IDetachment detachment in formation.Detachments.Intersect <IDetachment>(formation.Team?.TeamAI != null ? (IEnumerable <IDetachment>)formation.Team.TeamAI.GetStrategicAreas() : (IEnumerable <IDetachment>) new List <StrategicArea>()).ToList <IDetachment>())
         {
             formation.LeaveDetachment(detachment);
         }
     }
     if (this.OrderEnum == ArrangementOrder.ArrangementOrderEnum.ShieldWall || this.OrderEnum == ArrangementOrder.ArrangementOrderEnum.Circle || this.OrderEnum == ArrangementOrder.ArrangementOrderEnum.Square)
     {
         formation.ApplyActionOnEachUnit((Action <Agent>)(agent =>
         {
             if (!agent.IsAIControlled)
             {
                 return;
             }
             agent.EnforceShieldUsage(Agent.UsageDirection.None);
         }));
     }
     if (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Column)
     {
         return;
     }
     formation.OnTick -= new Action <Formation>(formation.TickForColumnArrangementInitialPositioning);
 }
Ejemplo n.º 3
0
 private void ClearFormationAllContour(Formation formation)
 {
     _actionQueue.Enqueue(() =>
     {
         formation.ApplyActionOnEachUnit(ClearAgentFormationContour);
     });
 }
Ejemplo n.º 4
0
 private void ClearFormationFocusContour(Formation formation)
 {
     _actionQueue.Enqueue(() =>
     {
         formation.ApplyActionOnEachUnit(agent =>
                                         agent.GetComponent <RTSCameraAgentComponent>()?.ClearTargetOrSelectedFormationColor());
     });
 }
Ejemplo n.º 5
0
 private void ClearFormationContour(Formation formation, ColorLevel level)
 {
     _actionQueue.Enqueue(() =>
     {
         formation.ApplyActionOnEachUnit(agent =>
                                         agent.GetComponent <RTSCameraAgentComponent>()?.SetContourColor((int)level, null, true));
     });
 }
Ejemplo n.º 6
0
 private void SetFormationMouseOverContour(Formation formation, bool isEnemy)
 {
     _mouseOverFormation = formation;
     _actionQueue.Enqueue(() =>
     {
         formation.ApplyActionOnEachUnit(agent => SetAgentMouseOverContour(agent, isEnemy));
     });
 }
 private void SetFormationSelectedContour(Formation formation, bool isEnemy)
 {
     if (!isEnemy)
     {
         _allySelectedFormations.Add(formation);
     }
     if (HighlightEnabledForSelectedFormation)
     {
         formation.ApplyActionOnEachUnit(agent => SetAgentSelectedContour(agent, isEnemy));
     }
 }
Ejemplo n.º 8
0
        public FormationQuery(Formation formation)
        {
            Formation = formation;

            KdTree = new QueryData <KdTree <float, AgentPointInfo> >(() =>
            {
                var tree = new KdTree <float, AgentPointInfo>(2, new FloatMath(), AddDuplicateBehavior.Skip);
                formation.ApplyActionOnEachUnit(agent =>
                {
                    if (agent.IsActive())
                    {
                        AddAgent(tree, agent);
                    }
                });
                return(tree);
            }, 0.1f);

            AverageOfTargetAgents = new QueryData <Vec2>(() =>
            {
                Vec2 result = Vec2.Zero;
                int count   = 0;
                formation.ApplyActionOnEachUnit(agent =>
                {
                    var component = agent.GetComponent <CommandSystemAgentComponent>();
                    if (component == null)
                    {
                        return;
                    }

                    var targetPosition = component.PositionOfTargetAgent.Value;
                    result            += targetPosition.IsValid ? targetPosition : agent.Position.AsVec2;
                    ++count;
                });
                if (count == 0)
                {
                    return(Vec2.Invalid);
                }

                return(result * (1.0f / count));
            }, 1f);
        }
 private void SetFormationAsTargetContour(Formation formation, bool isEnemy)
 {
     if (isEnemy)
     {
         _enemyAsTargetFormations.Add(formation);
     }
     else
     {
         _allyAsTargetFormations.Add(formation);
     }
     formation.ApplyActionOnEachUnit(agent => SetAgentAsTargetContour(agent, isEnemy));
 }
Ejemplo n.º 10
0
        private Agent SimpleNearestAgentFromFormation(Vec2 pos)
        {
            Agent nearestAgent    = null;
            float nearestDistance = float.MaxValue;

            Formation.ApplyActionOnEachUnit(agent =>
            {
                float distance = pos.Distance(agent.Position.AsVec2);
                if (distance < nearestDistance)
                {
                    nearestAgent    = agent;
                    nearestDistance = distance;
                }
            });
            return(nearestAgent);
        }
Ejemplo n.º 11
0
        public FormationQuery(Formation formation)
        {
            Formation = formation;

            KdTree = new QueryData <KdTree <float, AgentPointInfo> >(() =>
            {
                var tree = new KdTree <float, AgentPointInfo>(2, new FloatMath(), AddDuplicateBehavior.Skip);
                formation.ApplyActionOnEachUnit(agent =>
                {
                    if (agent.IsActive())
                    {
                        AddAgent(tree, agent);
                    }
                });
                return(tree);
            }, 0.1f);
        }
Ejemplo n.º 12
0
        private async void ReactToIssuedOrder(OrderType orderType, IEnumerable <Formation> appliedFormations, params object[] delegateParams)
        {
            if (Mission.Current == null)
            {
                return;
            }

            _orderType = orderType;
            var randomAgent = appliedFormations.GetRandomElement().Team.ActiveAgents.GetRandomElement();

            PlayHornBasedOnCulture(randomAgent, Agent.Main, orderType);

            var shouldContinuouslyYell = _config.ResponsiveOrders.ContinuousChargeYell &&
                                         (orderType == OrderType.Charge ||
                                          orderType == OrderType.ChargeWithTarget);

            if (shouldContinuouslyYell)
            {
                var rng = MBRandom.RandomInt(8, 15);

                for (int i = 0; i < rng; i++)
                {
                    for (int f = 0; f <= appliedFormations.Count(); f++)
                    {
                        Formation formation = null;
                        try {
                            formation = appliedFormations.ElementAt(f);
                        } catch { }
                        if (formation == null)
                        {
                            return;
                        }

                        var timeGate = MBCommon.GetTime(MBCommon.TimeType.Mission) + (MBRandom.RandomInt(3, 9) / 10f);
                        while (Mission.Current != null)
                        {
                            if (timeGate > MBCommon.GetTime(MBCommon.TimeType.Mission))
                            {
                                await Task.Delay(300);

                                continue;
                            }
                            formation.ApplyActionOnEachUnit(Charge);
                            break;
                        }
                    }
                }
                _affirmativeAgentCounter = 0;
            }
            else
            {
                // default reaction
                for (int f = 0; f <= appliedFormations.Count(); f++)
                {
                    var formation = appliedFormations.ElementAt(f);
                    if (formation == null)
                    {
                        return;
                    }

                    formation.ApplyActionOnEachUnit(Affirmative);
                    _affirmativeAgentCounter = 0;
                }
            }
        }
Ejemplo n.º 13
0
        private void TickOccasionally()
        {
            if (GameNetwork.IsClientOrReplay)
            {
                return;
            }
            List <Formation> formationList = new List <Formation>();
            int num1 = 0;

            foreach (Team team in (ReadOnlyCollection <Team>)Mission.Current.Teams)
            {
                if (team.Side == this.Side)
                {
                    foreach (Formation formation in team.FormationsIncludingSpecial)
                    {
                        if (formation.IsUsingMachine((UsableMachine)this))
                        {
                            formationList.Add(formation);
                            num1 += formation.UnitsWithoutLooseDetachedOnes.Count <IFormationUnit>();
                        }
                    }
                }
            }
            if (this.IsDisabledForBattleSide(this.Side) || this.AmmoCount <= 0 && !this.HasThrowingPointUsed)
            {
                foreach (Formation formation in formationList)
                {
                    formation.StopUsingMachine((UsableMachine)this);
                }
            }
            else if (formationList.Count == 0)
            {
                float     minDistanceSquared = float.MaxValue;
                Formation bestFormation      = (Formation)null;
                foreach (Team team in (ReadOnlyCollection <Team>)Mission.Current.Teams)
                {
                    if (team.Side == this.Side)
                    {
                        foreach (Formation formation1 in team.Formations)
                        {
                            Formation formation = formation1;
                            if (formation.CountOfUnitsWithoutLooseDetachedOnes >= this.MaxUserCount)
                            {
                                formation.ApplyActionOnEachUnit((Action <Agent>)(agent =>
                                {
                                    float num2 = agent.Position.DistanceSquared(this.GameEntity.GlobalPosition);
                                    if ((double)minDistanceSquared <= (double)num2)
                                    {
                                        return;
                                    }
                                    minDistanceSquared = num2;
                                    bestFormation      = formation;
                                }));
                            }
                        }
                    }
                }
                Formation formation2 = bestFormation;
                if (formation2 == null)
                {
                    return;
                }
                formation2.StartUsingMachine((UsableMachine)this);
            }
            else if (num1 == 0 && this.StandingPoints.Count <StandingPoint>((Func <StandingPoint, bool>)(sp => sp.HasUser || sp.HasAIMovingTo)) == 0)
            {
                foreach (Formation formation in formationList)
                {
                    formation.StopUsingMachine((UsableMachine)this);
                }
            }
            else
            {
                List <GameEntity> gameEntityList = (List <GameEntity>)null;
                foreach (StonePile.ThrowingPoint throwingPoint in this._throwingPoints)
                {
                    if (throwingPoint.StandingPoint.HasAIUser)
                    {
                        if (gameEntityList == null)
                        {
                            gameEntityList = this.GetEnemySiegeWeapons();
                            if (gameEntityList == null)
                            {
                                using (List <StonePile.ThrowingPoint> .Enumerator enumerator = this._throwingPoints.GetEnumerator())
                                {
                                    while (enumerator.MoveNext())
                                    {
                                        enumerator.Current.AttackEntity = (GameEntity)null;
                                    }
                                    break;
                                }
                            }
                        }
                        Agent      userAgent    = throwingPoint.StandingPoint.UserAgent;
                        GameEntity attackEntity = throwingPoint.AttackEntity;
                        if ((NativeObject)attackEntity != (NativeObject)null && (!gameEntityList.Contains(attackEntity) || !this.CanShootAtEntity(userAgent, attackEntity)))
                        {
                            throwingPoint.AttackEntity = (GameEntity)null;
                        }
                        if ((NativeObject)throwingPoint.AttackEntity == (NativeObject)null && gameEntityList != null)
                        {
                            foreach (GameEntity entity in gameEntityList)
                            {
                                if ((NativeObject)attackEntity != (NativeObject)entity && this.CanShootAtEntity(userAgent, entity))
                                {
                                    throwingPoint.AttackEntity = entity;
                                    break;
                                }
                            }
                        }
                    }
                }
                foreach (StonePile.VolumeBoxTimerPair volumeBoxTimerPair in this._volumeBoxTimerPairs)
                {
                    if (volumeBoxTimerPair.VolumeBox.HasAgentsIn((Predicate <Agent>)(a => a.Team != null && a.Team.Side == BattleSideEnum.Attacker)))
                    {
                        if ((double)volumeBoxTimerPair.Timer.ElapsedTime() > 3.5)
                        {
                            volumeBoxTimerPair.Timer.Reset(Mission.Current.Time);
                        }
                        else
                        {
                            volumeBoxTimerPair.Timer.Reset(Mission.Current.Time - 0.5f);
                        }
                    }
                }
            }
        }
 private static void ClearFormationAllContour(Formation formation)
 {
     formation.ApplyActionOnEachUnit(ClearAgentFormationContour);
 }