コード例 #1
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());
     RegisterType(Graveyard.InitializeData());
     RegisterType(AnimalPen.InitializeData());
     RegisterType(Treasury.InitializeData());
     staticIntialized = true;
 }
コード例 #2
0
ファイル: StashMoneyAct.cs プロジェクト: johan74/dwarfcorp
 public void SetZone(Treasury pile)
 {
     Agent.Blackboard.SetData(StockpileName, pile);
 }
コード例 #3
0
        /// <summary>
        /// Creates a flat, wooden balloon port for the balloon to land on, and Dwarves to sit on.
        /// </summary>
        /// <param name="roomDes">The player's BuildRoom designator (so that we can create a balloon port)</param>
        /// <param name="chunkManager">The terrain handler</param>
        /// <param name="x">The position of the center of the balloon port</param>
        /// <param name="z">The position of the center of the balloon port</param>
        /// <param name="size">The size of the (square) balloon port in voxels on a side</param>
        public BalloonPort GenerateInitialBalloonPort(RoomBuilder roomDes, ChunkManager chunkManager, float x, float z,
                                                      int size)
        {
            var centerCoordinate = GlobalVoxelCoordinate.FromVector3(new Vector3(x, VoxelConstants.ChunkSizeY - 1, z));

            var accumulator = 0;
            var count       = 0;

            for (var offsetX = -size; offsetX <= size; ++offsetX)
            {
                for (var offsetY = -size; offsetY <= size; ++offsetY)
                {
                    var topVoxel = VoxelHelpers.FindFirstVoxelBelowIncludeWater(
                        new VoxelHandle(chunkManager.ChunkData,
                                        centerCoordinate + new GlobalVoxelOffset(offsetX, 0, offsetY)));

                    if (topVoxel.Coordinate.Y > 0)
                    {
                        accumulator += topVoxel.Coordinate.Y + 1;
                        count       += 1;
                    }
                }
            }

            var averageHeight = (int)Math.Round(((float)accumulator / (float)count));

            // Next, create the balloon port by deciding which voxels to fill.
            var balloonPortDesignations = new List <VoxelHandle>();
            var treasuryDesignations    = new List <VoxelHandle>();

            for (int dx = -size; dx <= size; dx++)
            {
                for (int dz = -size; dz <= size; dz++)
                {
                    Vector3 worldPos = new Vector3(centerCoordinate.X + dx, centerCoordinate.Y, centerCoordinate.Z + dz);

                    var baseVoxel = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle(
                                                                         chunkManager.ChunkData, GlobalVoxelCoordinate.FromVector3(worldPos)));

                    if (!baseVoxel.IsValid)
                    {
                        continue;
                    }

                    var h          = baseVoxel.Coordinate.Y + 1;
                    var localCoord = baseVoxel.Coordinate.GetLocalVoxelCoordinate();

                    for (int y = averageHeight; y < h; y++)
                    {
                        var v = new VoxelHandle(baseVoxel.Chunk,
                                                new LocalVoxelCoordinate((int)localCoord.X, y, (int)localCoord.Z));
                        v.RawSetType(VoxelLibrary.GetVoxelType(0));
                        v.QuickSetLiquid(LiquidType.None, 0);
                    }

                    if (averageHeight < h)
                    {
                        h = averageHeight;
                    }

                    bool isPosX = (dx == size && dz == 0);
                    bool isPosZ = (dz == size & dx == 0);
                    bool isNegX = (dx == -size && dz == 0);
                    bool isNegZ = (dz == -size && dz == 0);
                    bool isSide = (isPosX || isNegX || isPosZ || isNegZ);

                    Vector3 offset = Vector3.Zero;

                    if (isSide)
                    {
                        if (isPosX)
                        {
                            offset = Vector3.UnitX;
                        }
                        else if (isPosZ)
                        {
                            offset = Vector3.UnitZ;
                        }
                        else if (isNegX)
                        {
                            offset = -Vector3.UnitX;
                        }
                        else if (isNegZ)
                        {
                            offset = -Vector3.UnitZ;
                        }
                    }

                    // Fill from the top height down to the bottom.
                    for (int y = h - 1; y < averageHeight; y++)
                    {
                        var v = new VoxelHandle(baseVoxel.Chunk,
                                                new LocalVoxelCoordinate((int)localCoord.X, y, (int)localCoord.Z));
                        v.RawSetType(VoxelLibrary.GetVoxelType("Scaffold"));
                        v.QuickSetLiquid(LiquidType.None, 0);

                        if (y == averageHeight - 1)
                        {
                            if (dz >= 0)
                            {
                                balloonPortDesignations.Add(v);
                            }
                            else
                            {
                                treasuryDesignations.Add(v);
                            }
                        }

                        if (isSide)
                        {
                            var ladderPos = new Vector3(worldPos.X, y, worldPos.Z) + offset +
                                            Vector3.One * 0.5f;
                            var ladderVox = new VoxelHandle(chunkManager.ChunkData,
                                                            GlobalVoxelCoordinate.FromVector3(ladderPos));
                            if (ladderVox.IsValid && ladderVox.IsEmpty)
                            {
                                var ladder = EntityFactory.CreateEntity <Ladder>("Ladder", ladderPos);
                                Master.Faction.OwnedObjects.Add(ladder);
                                ladder.Tags.Add("Moveable");
                                ladder.Tags.Add("Deconstructable");
                            }
                        }
                    }
                }
            }

            // Actually create the BuildRoom.
            BalloonPort    toBuild  = new BalloonPort(PlayerFaction, balloonPortDesignations, this);
            BuildRoomOrder buildDes = new BuildRoomOrder(toBuild, roomDes.Faction, this);

            buildDes.Build(true);
            roomDes.DesignatedRooms.Add(toBuild);

            // Also add a treasury
            Treasury treasury = new Treasury(PlayerFaction, treasuryDesignations, this);

            treasury.OnBuilt();
            roomDes.DesignatedRooms.Add(treasury);

            return(toBuild);
        }
コード例 #4
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);
     }
 }
コード例 #5
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));
                 */
            }
        }