Ejemplo n.º 1
0
        //



        //Aqui vc coloca sua lógica
        public override void Step(Squad squad)
        {
            if (squad.TargetInfo == null || !squad.TargetInfo.IsValid)
            {
                foreach (var squaddie in squad.Units)
                {
                    squaddie.CurrentAction = UnitAction.IdleAction();
                }
                return;
            }

            if (squad.TargetInfo.Target == null)
            {
                foreach (var squaddie in squad.Units)
                {
                    squaddie.CurrentAction = UnitAction.MoveAction(squad.TargetInfo.Position);
                }
            }
            else
            {
                foreach (var squaddie in squad.Units)
                {
                    squaddie.CurrentAction = UnitAction.AttackAction(squad.TargetInfo.Target, squad.TargetInfo.Target.position);
                }
            }
        }
Ejemplo n.º 2
0
        public override void Step(Squad squad)
        {
            bool animosity;

            try
            {
                animosity = states[squad].animosity;
            }
            catch (KeyNotFoundException)
            {
                animosity = true; //this is for testing purposes, usually it should be 'false' here
                states.Add(squad, new State(animosity));
            }
            if (animosity == false && squad.TargetInfo != null && squad.TargetInfo.Position != null)
            {// se nós estamos em modo defensivo (animosity==false) e não há alvo-posição, não há nada a fazer
                foreach (var squaddie in squad.Units)
                {
                    squaddie.CurrentAction = UnitAction.MoveAction(squad.TargetInfo.Position);
                }
            }

            if (animosity == true)
            {
                HashSet <IHittable> enemiesList = this.FindSquadEnemies(squad);
                if (enemiesList.Count == 0)
                {
                    if (squad.TargetInfo != null && squad.TargetInfo.Position != null)
                    {
                        foreach (var squaddie in squad.Units)
                        {
                            squaddie.CurrentAction = UnitAction.MoveAction(squad.TargetInfo.Position);
                        }
                    }
                    else
                    {
                        foreach (var squaddie in squad.Units)
                        {
                            squaddie.CurrentAction = UnitAction.IdleAction();
                        }
                    }
                }
                else
                {
                    Dictionary <Unit, IHittable> localLockedEnemies;
                    try
                    {
                        localLockedEnemies = LockedEnemies[squad];
                    }
                    catch
                    {
                        localLockedEnemies = new Dictionary <Unit, IHittable>();
                        LockedEnemies.Add(squad, localLockedEnemies);
                    }
                    foreach (var squaddie in squad.Units)
                    {
                        if (!localLockedEnemies.ContainsKey(squaddie))
                        {
                            localLockedEnemies.Add(squaddie, null);
                        }
                    }

                    Dictionary <IHittable, MeeleOrRanged> numberOfSiblingsOnEnemy;
                    try
                    {
                        numberOfSiblingsOnEnemy = numberOfSquaddiesOnEnemy[squad];
                    }
                    catch (KeyNotFoundException)
                    {
                        numberOfSiblingsOnEnemy = new Dictionary <IHittable, MeeleOrRanged>();
                        numberOfSquaddiesOnEnemy.Add(squad, numberOfSiblingsOnEnemy);
                    }

                    foreach (var enemy in enemiesList)
                    {
                        if (!numberOfSiblingsOnEnemy.ContainsKey(enemy))
                        {
                            numberOfSquaddiesOnEnemy[squad].Add(enemy, new MeeleOrRanged());
                        }
                    }

                    foreach (var squaddie in squad.Units) //action definition loop
                    {
                        if (squaddie.Equals(null))
                        {
                            continue;
                        }
                        IHittable currentTarget = null;
                        if (localLockedEnemies[squaddie] == (null) || localLockedEnemies[squaddie].Equals(null)) //then we have to search for an enemy
                        {
                            currentTarget = defineEnemy(squaddie.Type, enemiesList, numberOfSiblingsOnEnemy, squaddie);
                            if (!(currentTarget == null || currentTarget.Equals(null)))
                            {
                                switch (squaddie.Type)
                                {
                                case Unit.ClassType.Infantry:
                                case Unit.ClassType.Cavalry:
                                    numberOfSiblingsOnEnemy[currentTarget].Meele++;
                                    break;

                                case Unit.ClassType.Artillary:
                                    numberOfSiblingsOnEnemy[currentTarget].Ranged++;
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                        else
                        {
                            currentTarget = localLockedEnemies[squaddie];
                        }
                        if (currentTarget != null)
                        {
                            Debug.Log(currentTarget);
                            //decide if attacking or moving
                            bool SupposedToAttack = AttackOrMove(squaddie, currentTarget, enemiesList, squaddie.Type); //false means we're supposed to move
                            Debug.Log(SupposedToAttack);
                            if (SupposedToAttack)
                            {
                                squaddie.CurrentAction = UnitAction.AttackAction(currentTarget, whereToMove(squaddie, currentTarget, enemiesList, squaddie.Type));
                            }
                            else
                            {
                                //decide where we're moving to
                                Vector3 whereTo = whereToMove(squaddie, currentTarget, enemiesList, squaddie.Type);
                                squaddie.CurrentAction = UnitAction.MoveAction(whereTo);
                            }
                            squaddie.OnDestroyed += () =>
                            {
                                try
                                {
                                    switch (squaddie.Type)
                                    {
                                    case Unit.ClassType.Infantry:
                                    case Unit.ClassType.Cavalry:
                                        numberOfSiblingsOnEnemy[currentTarget].Meele--;
                                        break;

                                    case Unit.ClassType.Artillary:
                                        numberOfSiblingsOnEnemy[currentTarget].Ranged--;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                catch (KeyNotFoundException)
                                {
                                    //ignore it
                                }
                            };
                        }
                        else
                        {
                            //seguir os outros caras e ficar pronto pra iniciar combate.
                            //o comportamento a seguir é temporário!
                            if (squad.TargetInfo != null && squad.TargetInfo.Position != null)
                            {
                                squaddie.CurrentAction = UnitAction.MoveAction(squad.TargetInfo.Position);
                            }
                        }
                        if (currentTarget != null && !currentTarget.Equals(null))// && currentTarget.getType() != RTS.HitType.Building) //don't lock on buildings, priorizze troops
                        {
                            localLockedEnemies[squaddie] = currentTarget;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override void Step(Squad squad)
        {
            bool animosity;

            try
            {
                animosity = states[squad].animosity;
            }
            catch (KeyNotFoundException)
            {
                animosity = true; //this is for testing purposes, usually it should be 'false' here
                states.Add(squad, new State(animosity));
            }
            if (animosity == false && squad.TargetInfo != null && squad.TargetInfo.Position != null)
            {// se nós estamos em modo defensivo (animosity==false) e não há alvo-posição, não há nada a fazer
                foreach (var squaddie in squad.Units)
                {
                    squaddie.CurrentAction = UnitAction.MoveAction(squad.TargetInfo.Position);
                }
            }

            if (animosity == true)
            {
                HashSet <IHittable> enemiesList = this.FindSquadEnemies(squad);
                if (enemiesList.Count == 0)
                {
                    if (squad.TargetInfo != null && squad.TargetInfo.Position != null)
                    {
                        foreach (var squaddie in squad.Units)
                        {
                            squaddie.CurrentAction = UnitAction.MoveAction(squad.TargetInfo.Position);
                        }
                    }
                    else
                    {
                        foreach (var squaddie in squad.Units)
                        {
                            squaddie.CurrentAction = UnitAction.IdleAction();
                        }
                    }
                }
                else
                {
                    foreach (var squaddie in squad.Units)
                    {
                        float     smallestDistance = float.PositiveInfinity;
                        IHittable currentTarget    = null;
                        foreach (var enemy in enemiesList)
                        {
                            float currentDistance = Vector3.Distance(enemy.position, squaddie.position);
                            if (currentDistance < smallestDistance)
                            {
                                smallestDistance = currentDistance;
                                currentTarget    = enemy;
                            }
                        }
                        squaddie.CurrentAction = UnitAction.AttackAction(currentTarget, currentTarget.position);
                    }
                }
            }
        }