Exemplo n.º 1
0
        public override void OnBodiesSelected(List <GameComponent> bodies, InputManager.MouseButton button)
        {
            foreach (GameComponent other in bodies)
            {
                var creature = other.EnumerateAll().OfType <Creature>().FirstOrDefault();
                if (creature == null)
                {
                    continue;
                }

                if (World.Overworld.GetPolitics(creature.Faction.ParentFaction, World.PlayerFaction.ParentFaction).GetCurrentRelationship() == Relationship.Loving)
                {
                    World.UserInterface.ShowToolPopup("We refuse to attack allies.");
                    continue;
                }

                Drawer3D.DrawBox(other.BoundingBox, GameSettings.Current.Colors.GetColor("Hunt", Color.Red), 0.1f, false);

                if (button == InputManager.MouseButton.Left)
                {
                    var task = new KillEntityTask(other, KillEntityTask.KillType.Attack);
                    World.TaskManager.AddTask(task);
                    World.UserInterface.ShowToolPopup("Will attack this " + creature.Stats.CurrentClass.Name);
                    OnConfirm(World.PersistentData.SelectedMinions);
                }
                else if (button == InputManager.MouseButton.Right)
                {
                    if (World.PersistentData.Designations.GetEntityDesignation(other, DesignationType.Attack).HasValue(out var designation))
                    {
                        World.TaskManager.CancelTask(designation.Task);
                        World.UserInterface.ShowToolPopup("Attack cancelled for " + creature.Stats.CurrentClass.Name);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void HandleThreats()
        {
            List <Task>     tasks           = new List <Task>();
            List <Creature> threatsToRemove = new List <Creature>();

            foreach (Creature threat in Threats)
            {
                if (threat != null && !threat.IsDead)
                {
//                    if (!Designations.IsDesignation(threat.Physics, DesignationType.Attack))
                    {
                        var g = new KillEntityTask(threat.Physics, KillEntityTask.KillType.Auto);
                        //Designations.AddEntityDesignation(threat.Physics, DesignationType.Attack, null, g);
                        tasks.Add(g);
                    }
                    //                  else
                    {
                        //threatsToRemove.Add(threat);
                    }
                }
                else
                {
                    threatsToRemove.Add(threat);
                }
            }

            foreach (Creature threat in threatsToRemove)
            {
                Threats.Remove(threat);
            }

            TaskManager.AssignTasksGreedy(tasks, Minions);
        }
Exemplo n.º 3
0
 public KillEntityAct(Body entity, CreatureAI creature, KillEntityTask.KillType mode)
     : base(creature)
 {
     Mode = mode;
     Entity = entity;
     Name = "Kill Entity";
     Tree = new ForLoop(new Parallel(new Sequence(new GoToEntityAct(entity, creature),
                         new MeleeAct(Agent, entity)), new Wrap(Verify)), 5, true);
 }
Exemplo n.º 4
0
 public void OrderEnemyAttack()
 {
     foreach (CreatureAI enemy in Sensor.Enemies)
     {
         Task task = new KillEntityTask(enemy.Physics, KillEntityTask.KillType.Auto);
         if (!HasTaskWithName(task))
         {
             Creature.AI.Tasks.Add(task);
         }
     }
 }
Exemplo n.º 5
0
        /// <summary> Tell the creature to kill the given body. </summary>
        public void Kill(GameComponent entity)
        {
            var killTask = new KillEntityTask(entity, KillEntityTask.KillType.Auto)
            {
                ReassignOnDeath = false
            };

            if (!Tasks.Contains(killTask))
            {
                AssignTask(killTask);
            }
        }
Exemplo n.º 6
0
        /// <summary> For any enemy that this creature's enemy sensor knows about, order the creature to attack these enemies </summary>
        public virtual void OrderEnemyAttack()
        {
            foreach (CreatureAI enemy in Sensor.Enemies.Where(e => e != null && !e.IsDead && e.Creature != null))
            {
                if (enemy.Stats.IsFleeing)
                    continue;

                Task task = new KillEntityTask(enemy.Physics, KillEntityTask.KillType.Auto);
                if (!HasTaskWithName(task))
                {
                    Creature.AI.AssignTask(task);
                    MakeBattleAnnouncement(enemy);
                }
            }
        }
Exemplo n.º 7
0
        public void OrderEnemyAttack()
        {
            foreach (CreatureAI enemy in Sensor.Enemies)
            {
                Task task = new KillEntityTask(enemy.Physics, KillEntityTask.KillType.Auto);
                if (!HasTaskWithName(task))
                {
                    Creature.AI.Tasks.Add(task);

                    if (Faction == PlayState.PlayerFaction)
                    {
                        PlayState.AnnouncementManager.Announce(Stats.FullName + Drawer2D.WrapColor(" is fighting ", Color.DarkRed) + TextGenerator.IndefiniteArticle(enemy.Creature.Name),
                            Stats.FullName + " the " + Stats.CurrentLevel.Name + " is fighting " + TextGenerator.IndefiniteArticle(enemy.Stats.CurrentLevel.Name) + " " + enemy.Faction.Race.Name, 
                            ZoomToMe);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public override MaybeNull <Act> CreateScript(Creature creature)
        {
            if (creature.IsDead || creature.AI.IsDead)
            {
                return(null);
            }

            if (EntityToKill.GetRoot().GetComponent <Creature>().HasValue(out var otherCreature))
            {
                if (!otherCreature.IsDead && otherCreature.AI != null)
                {
                    // Flee if the other creature is too scary.
                    if (otherCreature != null && (creature.AI.Position - EntityToKill.Position).Length() < 10 && creature.AI.FightOrFlight(otherCreature.AI) == CreatureAI.FightOrFlightResponse.Flee)
                    {
                        Name            = "Flee Entity: " + EntityToKill.Name + " " + EntityToKill.GlobalID;
                        ReassignOnDeath = false;
                        IndicatorManager.DrawIndicator(IndicatorManager.StandardIndicators.Exclaim, creature.AI.Position, 1.0f, 1.0f, Vector2.UnitY * -32);
                        return(new FleeEntityAct(creature.AI)
                        {
                            Entity = EntityToKill, PathLength = 20
                        });
                    }

                    // Make the other creature defend itself.
                    var otherKill = new KillEntityTask(creature.Physics, KillType.Auto)
                    {
                        AutoRetry       = true,
                        ReassignOnDeath = false
                    };

                    if (!otherCreature.AI.HasTaskWithName(otherKill))
                    {
                        otherCreature.AI.AssignTask(otherKill);
                    }
                }
            }

            float radius = this.Mode == KillType.Auto ? 20.0f : 0.0f;

            return(new KillEntityAct(EntityToKill, creature.AI)
            {
                RadiusDomain = radius, Defensive = Mode == KillType.Auto
            });
        }
Exemplo n.º 9
0
        // This hack exists to find orphaned tasks not assigned to any dwarf, and to then
        // put them on the task list.
        public void UpdateOrphanedTasks()
        {
            orphanedTaskRateLimiter.Update(DwarfTime.LastTime);
            if (orphanedTaskRateLimiter.HasTriggered)
            {
                List <Task> orphanedTasks = new List <Task>();

                foreach (var ent in Faction.Designations.EnumerateEntityDesignations())
                {
                    if (ent.Type == DesignationType.Attack)
                    {
                        var task = new KillEntityTask(ent.Body, KillEntityTask.KillType.Attack);
                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }


                    else if (ent.Type == DesignationType.Craft)
                    {
                        var task = new CraftItemTask(ent.Tag as CraftDesignation);
                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }

                    // TODO ... other entity task types
                }

                if (orphanedTasks.Count > 0)
                {
                    //TaskManager.AssignTasksGreedy(orphanedTasks, Faction.Minions);
                    TaskManager.AddTasks(orphanedTasks);
                }
            }
        }
Exemplo n.º 10
0
        public void HandleThreats()
        {
            List <Task>     tasks           = new List <Task>();
            List <Creature> threatsToRemove = new List <Creature>();

            foreach (Creature threat in Threats)
            {
                if (threat != null && !threat.IsDead)
                {
                    Task g = new KillEntityTask(threat.Physics, KillEntityTask.KillType.Auto);

                    if (!IsTaskAssigned(g))
                    {
                        if (!AttackDesignations.Contains(threat.Physics))
                        {
                            AttackDesignations.Add(threat.Physics);
                        }
                        tasks.Add(g);
                    }
                    else
                    {
                        threatsToRemove.Add(threat);
                    }
                }
                else
                {
                    threatsToRemove.Add(threat);
                }
            }

            foreach (Creature threat in threatsToRemove)
            {
                Threats.Remove(threat);
            }

            TaskManager.AssignTasks(tasks, Minions);
        }
Exemplo n.º 11
0
        public override void OnBodiesSelected(List <Body> bodies, InputManager.MouseButton button)
        {
            foreach (Body other in bodies)
            {
                var creature = other.EnumerateAll().OfType <Creature>().FirstOrDefault();
                if (creature == null)
                {
                    continue;
                }

                if (Player.World.Diplomacy.GetPolitics(creature.Faction, Player.Faction).GetCurrentRelationship() == Relationship.Loving)
                {
                    Player.Faction.World.ShowToolPopup("We refuse to attack allies.");
                    continue;
                }

                Drawer3D.DrawBox(other.BoundingBox, GameSettings.Default.Colors.GetColor("Hunt", Color.Red), 0.1f, false);

                if (button == InputManager.MouseButton.Left)
                {
                    var task = new KillEntityTask(other, KillEntityTask.KillType.Attack);
                    Player.TaskManager.AddTask(task);
                    Player.Faction.World.ShowToolPopup("Will attack this " + creature.Species);
                    OnConfirm(Player.Faction.SelectedMinions);
                }
                else if (button == InputManager.MouseButton.Right)
                {
                    var designation = Player.Faction.Designations.GetEntityDesignation(other, DesignationType.Attack);
                    if (designation != null)
                    {
                        Player.TaskManager.CancelTask(designation.Task);
                        Player.Faction.World.ShowToolPopup("Attack cancelled for " + creature.Species);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public List<Task> CreateTasks()
        {
            List<Task> tasks = new List<Task>();

            if(Faction.Stockpiles.Count > 0)
            {
                tasks.AddRange(Faction.GatherDesignations.Select(i => new GatherItemTask(i)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));
            }

            foreach(CreatureAI creature in Faction.Minions)
            {
                if(creature.Status.Hunger.IsUnhappy())
                {
                    Task g = new SatisfyHungerTask();

                    if(IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }

                }
            }

            foreach (CreatureAI creature in Faction.Minions)
            {
                if (creature.Status.Energy.IsUnhappy() && PlayState.Time.IsNight())
                {
                    Task g = new SatisfyTirednessTask();

                    if (IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }

                }
            }

            List<Creature> threatsToRemove = new List<Creature>();
            foreach(Creature threat in Faction.Threats)
            {
                if(threat != null && !threat.IsDead)
                {
                    Task g = new KillEntityTask(threat.Physics, KillEntityTask.KillType.Auto);

                    if (!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
                else
                {
                    threatsToRemove.Add(threat);
                }
            }

            foreach (Creature threat in threatsToRemove)
            {
                Faction.Threats.Remove(threat);
            }

            foreach(BuildOrder i in Faction.DigDesignations)
            {
                if (i == null || i.Vox == null || i.Vox.Health <= 0)
                {
                    continue;
                }

                VoxelChunk chunk = PlayState.ChunkManager.ChunkData.GetVoxelChunkAtWorldLocation(i.Vox.Position);

                if(chunk != null)
                {
                    if(chunk.IsCompletelySurrounded(i.Vox))
                    {
                        continue;
                    }
                }

                Task g = new KillVoxelTask(i.Vox);

                if(!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                {
                    tasks.Add(g);
                }
            }

            tasks.AddRange(Faction.GuardDesignations.Select(i => new GuardVoxelTask(i.Vox)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));

            tasks.AddRange(Faction.ChopDesignations.Select(i => new KillEntityTask(i, KillEntityTask.KillType.Chop)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));

            if(Faction.Stockpiles.Count <= 0)
            {
                return tasks;
            }

            foreach(WallBuilder put in Faction.WallBuilder.Designations)
            {
                if(Faction.HasResources(new List<ResourceAmount>()
                {
                    new ResourceAmount(put.Type.ResourceToRelease)
                }))
                {

                    Task g = (new BuildVoxelTask(put.Vox, put.Type));

                    if(!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
            }

            foreach(ShipOrder ship in Faction.ShipDesignations)
            {
                List<Body> componentsToShip = new List<Body>();
                int remaining = ship.GetRemainingNumResources();

                if(remaining == 0)
                {
                    continue;
                }

                foreach(Stockpile s in Faction.Stockpiles)
                {
                    for(int i = componentsToShip.Count; i < remaining; i++)
                    {
                        // TODO: Reimplement
                        /*
                        Body r = s.FindItemWithTag(ship.Resource.ResourceType.ResourceName, componentsToShip);

                        if(r != null)
                        {
                            componentsToShip.Add(r);
                        }
                         */
                    }
                }

                foreach(Body loc in componentsToShip)
                {
                    // TODO: Reimplement
                    /*
                    if(ship.Port.ContainsItem(loc))
                    {
                        continue;
                    }
                     */

                    Task g = new PutItemInZoneTask(Item.FindItem(loc), ship.Port);

                    if(TaskIsAssigned(g) || !IsFeasible(g, Faction.Minions))
                    {
                        continue;
                    }

                    ship.Assignments.Add(g);
                    tasks.Add(g);
                }
            }

            return tasks;
        }
Exemplo n.º 13
0
        public void OrderEnemyAttack()
        {
            foreach (CreatureAI enemy in Sensor.Enemies)
            {
                Task task = new KillEntityTask(enemy.Physics, KillEntityTask.KillType.Auto);
                if (!HasTaskWithName(task))
                {
                    Creature.AI.Tasks.Add(task);

                    if (Faction == PlayState.PlayerFaction)
                    {
                        PlayState.AnnouncementManager.Announce(Stats.FullName + " is fighting a " + enemy.Creature.Name,
                            Stats.FullName + " the " + Stats.CurrentLevel.Name + " is fighting a " + enemy.Stats.CurrentLevel.Name + " " + enemy.Faction.Race.Name,
                            ZoomToMe);
                    }
                }
            }
        }
Exemplo n.º 14
0
        public void HandleThreats()
        {
            List<Task> tasks = new List<Task>();
            List<Creature> threatsToRemove = new List<Creature>();
            foreach (Creature threat in Threats)
            {
                if (threat != null && !threat.IsDead)
                {
                    Task g = new KillEntityTask(threat.Physics, KillEntityTask.KillType.Auto);

                    if (!IsTaskAssigned(g))
                    {
                        if (!AttackDesignations.Contains(threat.Physics))
                        {
                            AttackDesignations.Add(threat.Physics);
                        }
                        tasks.Add(g);
                    }
                    else
                    {
                        threatsToRemove.Add(threat);
                    }
                }
                else
                {
                    threatsToRemove.Add(threat);
                }
            }

            foreach (Creature threat in threatsToRemove)
            {
               Threats.Remove(threat);
            }

            TaskManager.AssignTasks(tasks, Minions);
        }
Exemplo n.º 15
0
        // This hack exists to find orphaned tasks not assigned to any dwarf, and to then
        // put them on the task list.
        public void UpdateOrphanedTasks()
        {
            orphanedTaskRateLimiter.Update(DwarfTime.LastTime);
            if (orphanedTaskRateLimiter.HasTriggered)
            {
                List <Task> orphanedTasks = new List <Task>();
                foreach (var block in Faction.Designations.EnumerateDesignations())
                {
                    if (block.Type == DesignationType.Put)
                    {
                        var type = (short)(block.Tag);
                        var task = new BuildVoxelTask(block.Voxel, VoxelLibrary.GetVoxelType(type).Name);

                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }
                    else if (block.Type == DesignationType.Dig)
                    {
                        var task = new KillVoxelTask(block.Voxel);
                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }
                    // TODO... other tasks here ?
                }

                foreach (var ent in Faction.Designations.EnumerateEntityDesignations())
                {
                    if (ent.Type == DesignationType.Attack)
                    {
                        var task = new KillEntityTask(ent.Body, KillEntityTask.KillType.Attack);
                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }
                    else if (ent.Type == DesignationType.Chop)
                    {
                        var task = new KillEntityTask(ent.Body, KillEntityTask.KillType.Chop);
                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }
                    else if (ent.Type == DesignationType.Wrangle)
                    {
                        var task = new WrangleAnimalTask(ent.Body.GetRoot().GetComponent <Creature>());
                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }
                    else if (ent.Type == DesignationType.Gather)
                    {
                        var task = new GatherItemTask(ent.Body);
                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }
                    else if (ent.Type == DesignationType.Craft)
                    {
                        var task = new CraftItemTask(ent.Tag as CraftDesignation);
                        if (!TaskManager.HasTask(task) &&
                            !Faction.Minions.Any(minion => minion.Tasks.Contains(task)))
                        {
                            orphanedTasks.Add(task);
                        }
                    }

                    /// TODO ... other entity task types
                }

                if (orphanedTasks.Count > 0)
                {
                    TaskManager.AssignTasksGreedy(orphanedTasks, Faction.Minions);
                }
            }
        }
Exemplo n.º 16
0
 public void Kill(Body entity)
 {
     KillEntityTask killTask = new KillEntityTask(entity, KillEntityTask.KillType.Auto);
     if (!Tasks.Contains(killTask))
         Tasks.Add(killTask);
 }
Exemplo n.º 17
0
        public List <Task> CreateTasks()
        {
            List <Task> tasks = new List <Task>();

            if (Faction.Stockpiles.Count > 0)
            {
                tasks.AddRange(Faction.GatherDesignations.Select(i => new GatherItemTask(i)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));
            }

            foreach (CreatureAI creature in Faction.Minions)
            {
                if (creature.Status.Hunger.IsUnhappy())
                {
                    Task g = new SatisfyHungerTask();

                    if (IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
            }

            foreach (CreatureAI creature in Faction.Minions)
            {
                if (creature.Status.Energy.IsUnhappy() && PlayState.Time.IsNight())
                {
                    Task g = new SatisfyTirednessTask();

                    if (IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
            }

            List <Creature> threatsToRemove = new List <Creature>();

            foreach (Creature threat in Faction.Threats)
            {
                if (threat != null && !threat.IsDead)
                {
                    Task g = new KillEntityTask(threat.Physics, KillEntityTask.KillType.Auto);

                    if (!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
                else
                {
                    threatsToRemove.Add(threat);
                }
            }

            foreach (Creature threat in threatsToRemove)
            {
                Faction.Threats.Remove(threat);
            }

            foreach (BuildOrder i in Faction.DigDesignations)
            {
                if (i == null || i.Vox == null || i.Vox.Health <= 0)
                {
                    continue;
                }

                VoxelChunk chunk = PlayState.ChunkManager.ChunkData.GetVoxelChunkAtWorldLocation(i.Vox.Position);

                if (chunk != null)
                {
                    if (chunk.IsCompletelySurrounded(i.Vox))
                    {
                        continue;
                    }
                }


                Task g = new KillVoxelTask(i.Vox);

                if (!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                {
                    tasks.Add(g);
                }
            }

            tasks.AddRange(Faction.GuardDesignations.Select(i => new GuardVoxelTask(i.Vox)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));

            tasks.AddRange(Faction.ChopDesignations.Select(i => new KillEntityTask(i, KillEntityTask.KillType.Chop)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));

            if (Faction.Stockpiles.Count <= 0)
            {
                return(tasks);
            }

            foreach (WallBuilder put in Faction.WallBuilder.Designations)
            {
                if (Faction.HasResources(new List <ResourceAmount>()
                {
                    new ResourceAmount(put.Type.ResourceToRelease)
                }))
                {
                    Task g = (new BuildVoxelTask(put.Vox, put.Type));

                    if (!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
            }

            foreach (ShipOrder ship in Faction.ShipDesignations)
            {
                List <Body> componentsToShip = new List <Body>();
                int         remaining        = ship.GetRemainingNumResources();

                if (remaining == 0)
                {
                    continue;
                }


                foreach (Stockpile s in Faction.Stockpiles)
                {
                    for (int i = componentsToShip.Count; i < remaining; i++)
                    {
                        // TODO: Reimplement

                        /*
                         * Body r = s.FindItemWithTag(ship.Resource.ResourceType.ResourceName, componentsToShip);
                         *
                         * if(r != null)
                         * {
                         *  componentsToShip.Add(r);
                         * }
                         */
                    }
                }

                foreach (Body loc in componentsToShip)
                {
                    // TODO: Reimplement

                    /*
                     * if(ship.Port.ContainsItem(loc))
                     * {
                     *  continue;
                     * }
                     */

                    Task g = new PutItemInZoneTask(Item.FindItem(loc), ship.Port);

                    if (TaskIsAssigned(g) || !IsFeasible(g, Faction.Minions))
                    {
                        continue;
                    }

                    ship.Assignments.Add(g);
                    tasks.Add(g);
                }
            }

            return(tasks);
        }
Exemplo n.º 18
0
        public List <Task> CreateTasks()
        {
            List <Task> tasks = new List <Task>();

            if (Faction.Stockpiles.Count > 0)
            {
                tasks.AddRange(Faction.GatherDesignations.Select(i => new GatherItemTask(i)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));
            }

            foreach (CreatureAI creature in Faction.Minions)
            {
                if (creature.Status.Hunger.IsUnhappy())
                {
                    Task g = new SatisfyHungerTask();

                    if (IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
            }

            foreach (CreatureAI creature in Faction.Minions)
            {
                if (creature.Status.Energy.IsUnhappy() && PlayState.Time.IsNight())
                {
                    Task g = new SatisfyTirednessTask();

                    if (IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
            }

            List <Creature> threatsToRemove = new List <Creature>();

            foreach (Creature threat in Faction.Threats)
            {
                if (threat != null && !threat.IsDead)
                {
                    Task g = new KillEntityTask(threat.Physics, KillEntityTask.KillType.Auto);

                    if (!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
                else
                {
                    threatsToRemove.Add(threat);
                }
            }

            foreach (Creature threat in threatsToRemove)
            {
                Faction.Threats.Remove(threat);
            }

            foreach (BuildOrder i in Faction.DigDesignations)
            {
                if (i == null || i.Vox == null || i.Vox.Health <= 0)
                {
                    continue;
                }

                VoxelChunk chunk = PlayState.ChunkManager.ChunkData.GetVoxelChunkAtWorldLocation(i.Vox.Position);

                if (chunk != null)
                {
                    if (chunk.IsCompletelySurrounded(i.Vox))
                    {
                        continue;
                    }
                }


                Task g = new KillVoxelTask(i.Vox);

                if (!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                {
                    tasks.Add(g);
                }
            }

            tasks.AddRange(Faction.GuardDesignations.Select(i => new GuardVoxelTask(i.Vox)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));

            tasks.AddRange(Faction.ChopDesignations.Select(i => new KillEntityTask(i, KillEntityTask.KillType.Chop)).Where(g => !TaskIsAssigned(g) && IsFeasible(g, Faction.Minions)));

            if (Faction.Stockpiles.Count <= 0)
            {
                return(tasks);
            }

            foreach (WallBuilder put in Faction.WallBuilder.Designations)
            {
                if (Faction.HasResources(new List <ResourceAmount>()
                {
                    new ResourceAmount(put.Type.ResourceToRelease)
                }))
                {
                    Task g = (new BuildVoxelTask(put.Vox, put.Type));

                    if (!TaskIsAssigned(g) && IsFeasible(g, Faction.Minions))
                    {
                        tasks.Add(g);
                    }
                }
            }

            return(tasks);
        }
Exemplo n.º 19
0
 public void OrderEnemyAttack()
 {
     foreach (CreatureAI enemy in Sensor.Enemies)
     {
         Task task = new KillEntityTask(enemy.Physics, KillEntityTask.KillType.Auto);
         if(!HasTaskWithName(task))
             Creature.AI.Tasks.Add(task);
     }
 }