public override void OnBodiesSelected(List <Body> bodies, InputManager.MouseButton button) { List <Task> tasks = new List <Task>(); foreach (Body animal in bodies.Where(c => c.Tags.Contains("DomesticAnimal"))) { Drawer3D.DrawBox(animal.BoundingBox, Color.Tomato, 0.1f, false); switch (button) { case InputManager.MouseButton.Left: { if (CanCatch(animal, true)) { var task = new WrangleAnimalTask(animal.GetRoot().GetComponent <Creature>()) { Priority = Task.PriorityType.Medium }; tasks.Add(task); } } break; case InputManager.MouseButton.Right: { var existingOrder = Player.Faction.Designations.GetEntityDesignation(animal, DesignationType.Wrangle); if (existingOrder != null) { Player.TaskManager.CancelTask(existingOrder.Task); } } break; } } if (tasks.Count > 0) { Player.TaskManager.AddTasks(tasks); OnConfirm(Player.SelectedMinions); } }
// 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); } } }