Example #1
0
        public override void Initialize()
        {
            bool hasAllResources = true;

            if (Resources != null)
            {
                foreach (Quantitiy <Resource.ResourceTags> resource in Resources)
                {
                    if (!Creature.Inventory.HasResource(resource, AllowHeterogenous))
                    {
                        hasAllResources = false;
                    }
                }
            }
            else if (ResourcesToStash != null)
            {
                foreach (ResourceAmount resource in ResourcesToStash)
                {
                    if (!Creature.Inventory.HasResource(resource))
                    {
                        hasAllResources = false;
                    }
                }
            }
            else
            {
                Tree = null;
                return;
            }


            if (!hasAllResources)
            {
                Stockpile nearestStockpile = Agent.Faction.GetNearestStockpile(Agent.Position, (pile) => !(pile is Graveyard));

                if (ResourcesToStash == null && Resources != null)
                {
                    ResourcesToStash = Agent.Faction.GetResourcesWithTags(Resources, AllowHeterogenous);
                }

                if (nearestStockpile == null || (ResourcesToStash != null && ResourcesToStash.Count == 0))
                {
                    Tree = null;
                    return;
                }
                else
                {
                    Tree = new Sequence(new Domain(() => HasResources(Agent), new GoToZoneAct(Agent, nearestStockpile)),
                                        new StashResourcesAct(Agent, ResourcesToStash),
                                        new SetBlackboardData <List <ResourceAmount> >(Agent, "ResourcesStashed", ResourcesToStash)
                                        );
                }
            }
            else
            {
                Tree = new SetBlackboardData <List <ResourceAmount> >(Agent, "ResourcesStashed", ResourcesToStash);
            }

            base.Initialize();
        }
        public int CompareStockpiles(Stockpile A, Stockpile B)
        {
            if (A == B)
            {
                return(0);
            }
            else
            {
                BoundingBox boxA    = A.GetBoundingBox();
                Vector3     centerA = (boxA.Min + boxA.Max) * 0.5f;
                float       costA   = (Creature.Physics.GlobalTransform.Translation - centerA).LengthSquared();

                BoundingBox boxB    = B.GetBoundingBox();
                Vector3     centerB = (boxB.Min + boxB.Max) * 0.5f;
                float       costB   = (Creature.Physics.GlobalTransform.Translation - centerB).LengthSquared();

                if (costA < costB)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
        }
Example #3
0
        public override void Initialize()
        {
            if (Agent.Status.Hunger.IsUnhappy())
            {
                Room commonRoom = Creature.Faction.GetNearestRoomOfType("CommonRoom", Agent.Position);

                if (commonRoom != null && commonRoom.IsBuilt)
                {
                    Tree = (new GoToZoneAct(Agent, commonRoom) & new GoToChairAndSitAct(Agent) & new Wrap(Creature.EatStockedFood));
                }
                else
                {
                    Stockpile stockRoom = Creature.Faction.GetNearestStockpile(Agent.Position);

                    if (stockRoom != null && stockRoom.IsBuilt)
                    {
                        Tree = new GoToZoneAct(Agent, stockRoom) & new Wrap(Creature.EatStockedFood);
                    }
                }
            }
            else
            {
                Tree = null;
            }

            base.Initialize();
        }
Example #4
0
 public StashResourcesAct(CreatureAI agent, Stockpile zone, Resource Resource) :
     base(agent)
 {
     Zone          = zone;
     this.Resource = Resource;
     Name          = "Stash " + Resource.TypeName;
 }
Example #5
0
        private void BuildNewVoxels(IEnumerable <Voxel> refs)
        {
            BuildRoomOrder      order        = null;
            IEnumerable <Voxel> designations = refs as IList <Voxel> ?? refs.ToList();
            IEnumerable <Voxel> nonEmpty     = designations.Select(r => r).Where(v => !v.IsEmpty);

            foreach (Voxel v in nonEmpty)
            {
                if (IsBuildDesignation(v) || IsInRoom(v))
                {
                    continue;
                }


                if (!v.GetVoxelAbove().IsEmpty)
                {
                    continue;
                }

                if (order == null)
                {
                    order = GetMostLikelyDesignation(v);
                }

                if (order != null)
                {
                    order.VoxelOrders.Add(new BuildVoxelOrder(order, order.ToBuild, v));
                }
                else
                {
                    if (CurrentRoomData != RoomLibrary.GetData("Stockpile"))
                    {
                        Room toBuild = RoomLibrary.CreateRoom(Faction, CurrentRoomData.Name, designations.ToList(), true, World);
                        DesignatedRooms.Add(toBuild);
                        order = new BuildRoomOrder(toBuild, Faction, Faction.World);
                        order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v));
                        BuildDesignations.Add(order);
                    }
                    else
                    {
                        Stockpile toBuild = new Stockpile(Faction, World);
                        DesignatedRooms.Add(toBuild);
                        order = new BuildStockpileOrder(toBuild, this.Faction);
                        order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v));
                        BuildDesignations.Add(order);
                    }
                }
            }

            if (order != null)
            {
                order.CreateFences(World.ComponentManager);
                TaskManager.AssignTasks(new List <Task>()
                {
                    new BuildRoomTask(order)
                }, Faction.FilterMinionsWithCapability(World.Master.SelectedMinions, GameMaster.ToolMode.Build));
            }
        }
 public TransferResourcesTask(WorldManager World, Stockpile Stockpile, Resource Resource)
 {
     this.World      = World;
     Priority        = TaskPriority.Medium;
     this.Stockpile  = Stockpile;
     this.Resource   = Resource;
     Name            = String.Format("Transfer {0} from {1}", Resource.TypeName, Stockpile);
     AutoRetry       = true;
     ReassignOnDeath = true;
 }
Example #7
0
 public static void InitializeStatics()
 {
     RegisterType(Stockpile.InitializeData());
     RegisterType(BalloonPort.InitializeData());
     RegisterType(BedRoom.InitializeData());
     RegisterType(CommonRoom.InitializeData());
     RegisterType(LibraryRoom.InitializeData());
     RegisterType(TrainingRoom.InitializeData());
     RegisterType(WorkshopRoom.InitializeData());
     RegisterType(Kitchen.InitializeData());
     staticIntialized = true;
 }
Example #8
0
 public static Room CreateRoom(Faction faction, string name, List <Voxel> designations, bool blueprint)
 {
     if (name == BalloonPort.BalloonPortName)
     {
         return(blueprint ? new BalloonPort(faction, true, designations, PlayState.ChunkManager) : new BalloonPort(faction, designations, PlayState.ChunkManager));
     }
     else if (name == BedRoom.BedRoomName)
     {
         return(blueprint ? new BedRoom(true, designations, PlayState.ChunkManager) : new BedRoom(designations, PlayState.ChunkManager));
     }
     else if (name == CommonRoom.CommonRoomName)
     {
         return(blueprint ? new CommonRoom(true, designations, PlayState.ChunkManager) : new CommonRoom(designations, PlayState.ChunkManager));
     }
     else if (name == LibraryRoom.LibraryRoomName)
     {
         return(blueprint ? new LibraryRoom(true, designations, PlayState.ChunkManager) : new LibraryRoom(designations, PlayState.ChunkManager));
     }
     else if (name == MushroomFarm.MushroomFarmName)
     {
         return(blueprint ? new MushroomFarm(true, designations, PlayState.ChunkManager) : new MushroomFarm(designations, PlayState.ChunkManager));
     }
     else if (name == TrainingRoom.TrainingRoomName)
     {
         return(blueprint ? new TrainingRoom(true, designations, PlayState.ChunkManager) : new TrainingRoom(designations, PlayState.ChunkManager));
     }
     else if (name == WheatFarm.WheatFarmName)
     {
         return(blueprint ? new WheatFarm(true, designations, PlayState.ChunkManager) : new WheatFarm(designations, PlayState.ChunkManager));
     }
     else if (name == WorkshopRoom.WorkshopName)
     {
         return(blueprint ? new WorkshopRoom(true, designations, PlayState.ChunkManager) : new WorkshopRoom(designations, PlayState.ChunkManager));
     }
     else if (name == Kitchen.KitchenName)
     {
         return(blueprint ? new Kitchen(true, designations, PlayState.ChunkManager) : new Kitchen(designations, PlayState.ChunkManager));
     }
     else if (name == Stockpile.StockpileName)
     {
         Stockpile toBuild = new Stockpile(faction);
         foreach (Voxel voxel in designations)
         {
             toBuild.AddVoxel(voxel);
         }
         return(toBuild);
     }
     else
     {
         return(null);
     }
 }
Example #9
0
        public IEnumerable <Status> LocateResources()
        {
            var resources = Agent.World.FindUnreservedResource(Item.ItemType.TypeName);

            if (resources.HasValue(out var res))
            {
                res.Item2.ReservedFor = Agent;
                Item.SelectedResource = res.Item2;
                ItemSource            = res.Item1;
                yield return(Status.Success);
            }
            else
            {
                yield return(Status.Fail);
            }
        }
Example #10
0
        public Stockpile GetNearestStockpile(Vector3 position)
        {
            Stockpile nearest = null;

            float closestDist = float.MaxValue;

            foreach (Stockpile stockpile in Stockpiles)
            {
                float dist = (stockpile.GetBoundingBox().Center() - position).LengthSquared();

                if (dist < closestDist)
                {
                    closestDist = dist;
                    nearest     = stockpile;
                }
            }

            return(nearest);
        }
Example #11
0
        public override void Initialize()
        {

            bool hasAllResources = true;


            foreach(ResourceAmount resource in Resources)
            {
             
                if (!Creature.Inventory.Resources.HasResource(resource))
                {
                    hasAllResources = false;
                }
            }


            if(!hasAllResources)
            { 
                Stockpile nearestStockpile = Agent.Faction.GetNearestStockpile(Agent.Position);

                if(nearestStockpile == null)
                {
                    Tree = null;
                    return;
                }
                else
                {
                    Tree = new Sequence(new GoToZoneAct(Agent, nearestStockpile),
                                        new StashResourcesAct(Agent, Resources)
                                        );
                }
            }
            else
            {
                Tree = new Wrap(AlwaysTrue);
            }
          
            base.Initialize();
        }
Example #12
0
        public Stockpile GetNearestStockpile(Vector3 position, Func <Stockpile, bool> predicate)
        {
            Stockpile nearest = null;

            float closestDist = float.MaxValue;

            foreach (Stockpile stockpile in Stockpiles.Where(predicate))
            {
                if (!stockpile.IsBuilt)
                {
                    continue;
                }
                float dist = (stockpile.GetBoundingBox().Center() - position).LengthSquared();

                if (dist < closestDist)
                {
                    closestDist = dist;
                    nearest     = stockpile;
                }
            }

            return(nearest);
        }
Example #13
0
 public bool GetStockpile()
 {
     stockpile = World.FindZone(StockpileFrom) as Stockpile;
     return(stockpile != null);
 }
Example #14
0
        private void BuildNewVoxels(IEnumerable <VoxelHandle> designations)
        {
            BuildRoomOrder order = null;

            foreach (var v in designations.Where(v => v.IsValid && !v.IsEmpty))
            {
                if (IsBuildDesignation(v) || IsInRoom(v))
                {
                    continue;
                }

                // This check should be rendered pointless by the call to Verify made just
                // before calling this function.
                var above = VoxelHelpers.GetVoxelAbove(v);
                if (above.IsValid && !above.IsEmpty)
                {
                    continue;
                }

                if (order == null)
                {
                    order = GetMostLikelyDesignation(v);
                }

                if (order != null && order.ToBuild.RoomData == CurrentRoomData && !order.IsBuilt)
                {
                    order.VoxelOrders.Add(new BuildVoxelOrder(order, order.ToBuild, v));
                }
                else if (order == null)
                {
                    if (CurrentRoomData == RoomLibrary.GetData("Stockpile"))
                    {
                        Stockpile toBuild = new Stockpile(Faction, World);
                        DesignatedRooms.Add(toBuild);
                        order = new BuildStockpileOrder(toBuild, this.Faction);
                        order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v));
                        BuildDesignations.Add(order);
                    }
                    else if (CurrentRoomData == RoomLibrary.GetData("Treasury"))
                    {
                        Treasury toBuild = new Treasury(Faction, World);
                        DesignatedRooms.Add(toBuild);
                        order = new BuildRoomOrder(toBuild, this.Faction, Faction.World);
                        order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v));
                        BuildDesignations.Add(order);
                    }
                    else
                    {
                        Room toBuild = RoomLibrary.CreateRoom(Faction, CurrentRoomData.Name, designations.ToList(), true, World);
                        DesignatedRooms.Add(toBuild);
                        order = new BuildRoomOrder(toBuild, Faction, Faction.World);
                        order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v));
                        BuildDesignations.Add(order);
                    }
                }
                else if (order.ToBuild.RoomData != CurrentRoomData || order.IsBuilt)
                {
                    order = null;
                }
            }

            if (order != null)
            {
                order.WorkObjects.AddRange(Fence.CreateFences(World.ComponentManager,
                                                              ContentPaths.Entities.DwarfObjects.constructiontape,
                                                              order.VoxelOrders.Select(o => o.Voxel),
                                                              true));
                foreach (var obj in order.WorkObjects)
                {
                    obj.Manager.RootComponent.AddChild(obj);
                }
                World.Master.TaskManager.AddTask(new BuildRoomTask(order));

                /*
                 * TaskManager.AssignTasks(new List<Task>()
                 * {
                 *  new BuildRoomTask(order)
                 * }, Faction.FilterMinionsWithCapability(World.Master.SelectedMinions, GameMaster.ToolMode.BuildZone));
                 */
            }
        }
 public BuildStockpileOrder(Stockpile toBuild, Faction faction)
     : base(toBuild, faction)
 {
 }
Example #16
0
 public BuildStockpileOrder(Stockpile toBuild, Faction faction)
     : base(toBuild, faction)
 {
 }
Example #17
0
        private void BuildNewVoxels(IEnumerable<Voxel> refs)
        {
            BuildRoomOrder order = null;
            IEnumerable<Voxel> designations = refs as IList<Voxel> ?? refs.ToList();
            IEnumerable<Voxel> nonEmpty = designations.Select(r => r).Where(v => !v.IsEmpty);
            foreach(Voxel v in nonEmpty)
            {
                if(IsBuildDesignation(v) || IsInRoom(v))
                {
                    continue;
                }

                if(order == null)
                {
                    order = GetMostLikelyDesignation(v);
                }

                if (order != null)
                {
                    order.VoxelOrders.Add(new BuildVoxelOrder(order, order.ToBuild, v));
                }
                else
                {
                    if(CurrentRoomData != RoomLibrary.GetData("Stockpile"))
                    {
                        Room toBuild = RoomLibrary.CreateRoom(CurrentRoomData.Name, designations.ToList(), true);
                        DesignatedRooms.Add(toBuild);
                        order = new BuildRoomOrder(toBuild, this.Faction);
                        order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v));
                        BuildDesignations.Add(order);
                    }
                    else
                    {
                        Stockpile toBuild = new Stockpile("Stockpile " + Stockpile.NextID(), PlayState.ChunkManager);
                        DesignatedRooms.Add(toBuild);
                        order = new BuildStockpileOrder(toBuild, this.Faction);
                        order.VoxelOrders.Add(new BuildVoxelOrder(order, toBuild, v));
                        BuildDesignations.Add(order);
                    }
                }
            }

            if(order != null)
            {
                TaskManager.AssignTasks(new List<Task>()
                {
                    new BuildRoomTask(order)
                }, Faction.FilterMinionsWithCapability(PlayState.Master.SelectedMinions, GameMaster.ToolMode.Build));
            }
        }
Example #18
0
 public static Room CreateRoom(string name, List<Voxel> designations, bool blueprint)
 {
     if (name == BalloonPort.BalloonPortName)
     {
         return blueprint ? new BalloonPort(true, designations, PlayState.ChunkManager) : new BalloonPort(designations, PlayState.ChunkManager);
     }
     else if (name == BedRoom.BedRoomName)
     {
         return blueprint ? new BedRoom(true, designations, PlayState.ChunkManager) : new BedRoom(designations, PlayState.ChunkManager);
     }
     else if (name == CommonRoom.CommonRoomName)
     {
         return blueprint ? new CommonRoom(true, designations, PlayState.ChunkManager) : new CommonRoom(designations, PlayState.ChunkManager);
     }
     else if (name == LibraryRoom.LibraryRoomName)
     {
         return blueprint ? new LibraryRoom(true, designations, PlayState.ChunkManager) : new LibraryRoom(designations, PlayState.ChunkManager);
     }
     else if (name == MushroomFarm.MushroomFarmName)
     {
         return blueprint ? new MushroomFarm(true, designations, PlayState.ChunkManager) : new MushroomFarm(designations, PlayState.ChunkManager);
     }
     else if (name == TrainingRoom.TrainingRoomName)
     {
         return blueprint ? new TrainingRoom(true, designations, PlayState.ChunkManager) : new TrainingRoom(designations, PlayState.ChunkManager);
     }
     else if (name == WheatFarm.WheatFarmName)
     {
         return blueprint ? new WheatFarm(true, designations, PlayState.ChunkManager) : new WheatFarm(designations, PlayState.ChunkManager);
     }
     else if (name == WorkshopRoom.WorkshopName)
     {
         return blueprint ? new WorkshopRoom(true, designations, PlayState.ChunkManager) : new WorkshopRoom(designations, PlayState.ChunkManager);
     }
     else if (name == Stockpile.StockpileName)
     {
         Stockpile toBuild = new Stockpile("Stockpile " + Stockpile.NextID(), PlayState.ChunkManager);
         foreach (Voxel voxel in designations)
         {
             toBuild.AddVoxel(voxel);
         }
         return toBuild;
     }
     else
     {
         return null;
     }
 }
 public void SetStockpile(Stockpile value)
 {
     Agent.Blackboard.SetData(StockpileName, value);
 }
Example #20
0
 public static Room CreateRoom(Faction faction, string name, List <VoxelHandle> designations, bool blueprint, WorldManager world)
 {
     // TODO(mklingen): omg get rid of this horrible legacy function!
     if (name == BalloonPort.BalloonPortName)
     {
         return(blueprint ? new BalloonPort(faction, true, designations, world) : new BalloonPort(faction, designations, world));
     }
     else if (name == BedRoom.BedRoomName)
     {
         return(blueprint ? new BedRoom(true, designations, world, faction) : new BedRoom(designations, world, faction));
     }
     else if (name == CommonRoom.CommonRoomName)
     {
         return(blueprint ? new CommonRoom(true, designations, world, faction) : new CommonRoom(designations, world, faction));
     }
     else if (name == LibraryRoom.LibraryRoomName)
     {
         return(blueprint ? new LibraryRoom(true, designations, world, faction) : new LibraryRoom(designations, world, faction));
     }
     else if (name == TrainingRoom.TrainingRoomName)
     {
         return(blueprint ? new TrainingRoom(true, designations, world, faction) : new TrainingRoom(designations, world, faction));
     }
     else if (name == WorkshopRoom.WorkshopName)
     {
         return(blueprint ? new WorkshopRoom(true, designations, world, faction) : new WorkshopRoom(designations, world, faction));
     }
     else if (name == Kitchen.KitchenName)
     {
         return(blueprint ? new Kitchen(true, designations, world, faction) : new Kitchen(designations, world, faction));
     }
     else if (name == Stockpile.StockpileName)
     {
         Stockpile toBuild = new Stockpile(faction, world);
         foreach (var voxel in designations)
         {
             toBuild.AddVoxel(voxel);
         }
         return(toBuild);
     }
     else if (name == Graveyard.GraveyardName)
     {
         return(blueprint
             ? new Graveyard(faction, true, designations, world)
             : new Graveyard(faction, designations, world));
     }
     else if (name == AnimalPen.AnimalPenName)
     {
         return(blueprint
             ? new AnimalPen(true, designations, world, faction) :
                new AnimalPen(designations, world, faction));
     }
     else if (name == Treasury.TreasuryName)
     {
         Treasury toBuild = new Treasury(faction, world);
         foreach (var voxel in designations)
         {
             toBuild.AddVoxel(voxel);
         }
         return(toBuild);
     }
     else
     {
         return(null);
     }
 }
Example #21
0
 public TransferResourcesAct(CreatureAI agent, Stockpile from, ResourceAmount resources) :
     base(agent)
 {
     StockpileFrom = from;
     Resources     = resources;
 }
 public void SetStockpile(Stockpile value)
 {
     Agent.Blackboard.SetData(StockpileName, value);
 }
        public int CompareStockpiles(Stockpile A, Stockpile B)
        {
            if(A == B)
            {
                return 0;
            }
            else
            {
                BoundingBox boxA = A.GetBoundingBox();
                Vector3 centerA = (boxA.Min + boxA.Max) * 0.5f;
                float costA = (Creature.Physics.GlobalTransform.Translation - centerA).LengthSquared();

                BoundingBox boxB = B.GetBoundingBox();
                Vector3 centerB = (boxB.Min + boxB.Max) * 0.5f;
                float costB = (Creature.Physics.GlobalTransform.Translation - centerB).LengthSquared();

                if(costA < costB)
                {
                    return -1;
                }
                else
                {
                    return 1;
                }
            }
        }
Example #24
0
 public TransferResourcesAct(CreatureAI agent, Stockpile from, Resource Resource) :
     base(agent)
 {
     StockpileFrom = from;
     this.Resource = Resource;
 }