Exemple #1
0
 public void Update(SquadCA squad)
 {
     if (currentState != null)
     {
         currentState.Tick(squad);
     }
 }
Exemple #2
0
        public void DismissSquad(SquadCA squad)
        {
            foreach (var unit in squad.Units)
            {
                unitsHangingAroundTheBase.Add(unit);
            }

            squad.Units.Clear();
        }
Exemple #3
0
        public void Tick(SquadCA owner)
        {
            if (!owner.IsValid)
            {
                return;
            }

            GoToRandomOwnBuilding(owner);
            owner.FuzzyStateMachine.ChangeState(owner, new UnitsForProtectionIdleState(), true);
        }
        public void Tick(SquadCA owner)
        {
            if (!owner.IsValid)
            {
                return;
            }

            Retreat(owner, true, true, true);
            owner.FuzzyStateMachine.ChangeState(owner, new UnitsForProtectionIdleState(), true);
        }
        public void Tick(SquadCA owner)
        {
            if (!owner.IsValid)
            {
                return;
            }

            if (!owner.IsTargetValid)
            {
                owner.TargetActor = owner.SquadManager.FindClosestEnemy(owner.CenterPosition, WDist.FromCells(owner.SquadManager.Info.ProtectionScanRadius));

                if (owner.TargetActor == null)
                {
                    Retreat(owner, false, true, true);
                    return;
                }
            }

            owner.FuzzyStateMachine.ChangeState(owner, new UnitsForProtectionAttackState(), true);
        }
Exemple #6
0
        public void ChangeState(SquadCA squad, IState newState, bool rememberPrevious)
        {
            if (rememberPrevious)
            {
                previousState = currentState;
            }

            if (currentState != null)
            {
                currentState.Deactivate(squad);
            }

            if (newState != null)
            {
                currentState = newState;
            }

            if (currentState != null)
            {
                currentState.Activate(squad);
            }
        }
        void IGameSaveTraitData.ResolveTraitData(Actor self, List <MiniYamlNode> data)
        {
            if (self.World.IsReplay)
            {
                return;
            }

            var initialBaseCenterNode = data.FirstOrDefault(n => n.Key == "InitialBaseCenter");

            if (initialBaseCenterNode != null)
            {
                initialBaseCenter = FieldLoader.GetValue <CPos>("InitialBaseCenter", initialBaseCenterNode.Value.Value);
            }

            var unitsHangingAroundTheBaseNode = data.FirstOrDefault(n => n.Key == "UnitsHangingAroundTheBase");

            if (unitsHangingAroundTheBaseNode != null)
            {
                unitsHangingAroundTheBase.Clear();
                unitsHangingAroundTheBase.AddRange(FieldLoader.GetValue <uint[]>("UnitsHangingAroundTheBase", unitsHangingAroundTheBaseNode.Value.Value)
                                                   .Select(a => self.World.GetActorById(a)).Where(a => a != null));
            }

            var activeUnitsNode = data.FirstOrDefault(n => n.Key == "ActiveUnits");

            if (activeUnitsNode != null)
            {
                activeUnits.Clear();
                activeUnits.AddRange(FieldLoader.GetValue <uint[]>("ActiveUnits", activeUnitsNode.Value.Value)
                                     .Select(a => self.World.GetActorById(a)).Where(a => a != null));
            }

            var rushTicksNode = data.FirstOrDefault(n => n.Key == "RushTicks");

            if (rushTicksNode != null)
            {
                rushTicks = FieldLoader.GetValue <int>("RushTicks", rushTicksNode.Value.Value);
            }

            var assignRolesTicksNode = data.FirstOrDefault(n => n.Key == "AssignRolesTicks");

            if (assignRolesTicksNode != null)
            {
                assignRolesTicks = FieldLoader.GetValue <int>("AssignRolesTicks", assignRolesTicksNode.Value.Value);
            }

            var attackForceTicksNode = data.FirstOrDefault(n => n.Key == "AttackForceTicks");

            if (attackForceTicksNode != null)
            {
                attackForceTicks = FieldLoader.GetValue <int>("AttackForceTicks", attackForceTicksNode.Value.Value);
            }

            var minAttackForceDelayTicksNode = data.FirstOrDefault(n => n.Key == "MinAttackForceDelayTicks");

            if (minAttackForceDelayTicksNode != null)
            {
                minAttackForceDelayTicks = FieldLoader.GetValue <int>("MinAttackForceDelayTicks", minAttackForceDelayTicksNode.Value.Value);
            }

            var squadsNode = data.FirstOrDefault(n => n.Key == "Squads");

            if (squadsNode != null)
            {
                SquadsCA.Clear();
                foreach (var n in squadsNode.Value.Nodes)
                {
                    SquadsCA.Add(SquadCA.Deserialize(bot, this, n.Value));
                }
            }
        }
Exemple #8
0
        public void Tick(SquadCA owner)
        {
            if (!owner.IsValid)
            {
                return;
            }

            if (!owner.IsTargetValid)
            {
                owner.TargetActor = owner.SquadManager.FindClosestEnemy(owner.CenterPosition, WDist.FromCells(owner.SquadManager.Info.ProtectionScanRadius));

                if (owner.TargetActor == null)
                {
                    owner.FuzzyStateMachine.ChangeState(owner, new UnitsForProtectionFleeState(), true);
                    return;
                }
            }

            // rescan target to prevent being ambushed and die without fight
            // return to AttackMove state for formation
            var teamLeader = owner.Units.ClosestTo(owner.TargetActor.CenterPosition);

            if (teamLeader == null)
            {
                return;
            }
            var teamTail             = owner.Units.MaxByOrDefault(a => (a.CenterPosition - owner.TargetActor.CenterPosition).LengthSquared);
            var protectionScanRadius = WDist.FromCells(owner.SquadManager.Info.ProtectionScanRadius);
            var targetActor          = ThreatScan(owner, teamLeader, protectionScanRadius) ?? ThreatScan(owner, teamTail, protectionScanRadius);
            var cannotRetaliate      = false;

            if (targetActor != null)
            {
                owner.TargetActor = targetActor;
            }

            if (!owner.IsTargetVisible)
            {
                if (Backoff < 0)
                {
                    owner.FuzzyStateMachine.ChangeState(owner, new UnitsForProtectionFleeState(), true);
                    Backoff = BackoffTicks;
                    return;
                }

                Backoff--;
            }
            else
            {
                cannotRetaliate = true;

                foreach (var a in owner.Units)
                {
                    // Air units control:
                    var ammoPools = a.TraitsImplementing <AmmoPool>().ToArray();
                    if (a.Info.HasTraitInfo <AircraftInfo>() && ammoPools.Any())
                    {
                        if (BusyAttack(a))
                        {
                            cannotRetaliate = false;
                            continue;
                        }

                        if (!ReloadsAutomatically(ammoPools, a.TraitOrDefault <Rearmable>()))
                        {
                            if (IsRearming(a))
                            {
                                continue;
                            }

                            if (!HasAmmo(ammoPools))
                            {
                                owner.Bot.QueueOrder(new Order("ReturnToBase", a, false));
                                continue;
                            }
                        }

                        if (CanAttackTarget(a, owner.TargetActor))
                        {
                            owner.Bot.QueueOrder(new Order("Attack", a, Target.FromActor(owner.TargetActor), false));
                            cannotRetaliate = false;
                        }
                        else if (a.Info.HasTraitInfo <GuardableInfo>())
                        {
                            owner.Bot.QueueOrder(new Order("Guard", a, Target.FromActor(teamLeader), false));
                        }
                    }

                    // Ground/naval units control:
                    else
                    {
                        if (CanAttackTarget(a, owner.TargetActor))
                        {
                            owner.Bot.QueueOrder(new Order("Attack", a, Target.FromActor(owner.TargetActor), false));
                            cannotRetaliate = false;
                        }
                        else if (a.Info.HasTraitInfo <GuardableInfo>())
                        {
                            owner.Bot.QueueOrder(new Order("Guard", a, Target.FromActor(teamLeader), false));
                        }
                    }
                }
            }

            if (cannotRetaliate)
            {
                owner.FuzzyStateMachine.ChangeState(owner, new UnitsForProtectionFleeState(), true);
            }
        }
Exemple #9
0
 public void Activate(SquadCA owner)
 {
 }
Exemple #10
0
 public void Deactivate(SquadCA owner)
 {
 }
Exemple #11
0
 public void Tick(SquadCA owner)
 {
     owner.FuzzyStateMachine.ChangeState(owner, new UnitsForProtectionAttackState(), true);
 }
Exemple #12
0
 public void Deactivate(SquadCA owner)
 {
     owner.Units.Clear();
 }
Exemple #13
0
 public void RevertToPreviousState(SquadCA squad, bool saveCurrentState)
 {
     ChangeState(squad, previousState, saveCurrentState);
 }