Exemple #1
0
        private void tryOutput(IVoxelHandle handle)
        {
            if (handle.Data.Inventory[fishType] < maxItemCount)
            {
                return;
            }

            var target = handle.Get4Connected().FirstOrDefault(v => v.CanAcceptItemType(fishType));

            if (target == null || !target.CanAcceptItemType(fishType))
            {
                return;
            }

            for (int i = 0; i < maxItemCount; i++)
            {
                if (!target.CanAcceptItemType(fishType))
                {
                    break;
                }
                if (handle.Data.Inventory[fishType] == 0)
                {
                    break;
                }
                if (target.Type is RoadType)
                {
                    Road.DeliverItemClosest(target, handle, fishType);
                }
            }
        }
        private void tryOutput(IVoxelHandle handle)
        {
            if (handle.Data.Inventory.ItemCount == 0)
            {
                return;
            }
            var type   = handle.Data.Inventory.Items.First();
            var target = handle.Get4Connected().FirstOrDefault(v => v.CanAcceptItemType(type));

            if (target == null)
            {
                return;
            }

            for (int i = 0; i < 5; i++)
            {
                if (!target.CanAcceptItemType(type))
                {
                    break;
                }
                if (handle.Data.Inventory[type] == 0)
                {
                    break;
                }
                if (target.Type is RoadType)
                {
                    Road.DeliverItemClosest(target, handle, type);
                }
                else
                {
                    handle.Data.Inventory.TransferItemsTo(target.Data.Inventory, type, 1);
                }
            }
        }
Exemple #3
0
        private void tryOutput(IVoxelHandle handle)
        {
            if (handle.Data.Inventory.GetAmountOfType(stoneType) == 0)
            {
                return;
            }

            var target = handle.Get4Connected().FirstOrDefault(v => v.CanAcceptItemType(stoneType));

            if (target == null || !target.CanAcceptItemType(stoneType))
            {
                return;
            }

            for (int i = 0; i < inventoryCapacity; i++)
            {
                if (!target.CanAcceptItemType(stoneType))
                {
                    break;
                }
                if (handle.Data.Inventory[stoneType] == 0)
                {
                    break;
                }
                if (target.Type is RoadType)
                {
                    Road.DeliverItemClosest(target, handle, stoneType);
                }
            }
        }
Exemple #4
0
        private void tryDeliverPigment(IVoxelHandle handle)
        {
            if (handle.Data.Inventory.GetAmountOfType(pigmentType) == 0)
            {
                return;
            }

            var target = handle.Get4Connected().FirstOrDefault(v => v.CanAcceptItemType(pigmentType));

            if (target == null)
            {
                return;
            }
            if (!target.CanAcceptItemType(pigmentType))
            {
                return;
            }
            if (!(target.Type is RoadType))
            {
                return;
            }

            Road.DeliverItemClosest(target, handle, pigmentType);
            handle.Data.DataValue = 0;
        }
        public override IMesh GetMesh(IVoxelHandle handle)
        {
            var conn  = handle.Get4Connected().ToArray();
            var index = handle.Data.DataValue;

            index = index > meshBuilders.Count - 1 ? meshBuilders.Count - 1 : index;
            return(meshBuilders[index].CreateMesh(isConnectedType(conn[0]), isConnectedType(conn[1]), isConnectedType(conn[2]), isConnectedType(conn[3])));
        }
Exemple #6
0
        private bool tryTransferToDestination(IVoxelHandle road, TargetedItem item)
        {
            if (!road.Get4Connected().Contains(haxorIVoxelHandelize(road, item.Destination)))
            {
                return(false);
            }

            item.Source.Data.Inventory.DestroyItems(itemTypesFactory.GetOutgoingKanban(item.ItemType), 1);
            item.Destination.Data.Inventory.DestroyItems(itemTypesFactory.GetIncomingKanban(item.ItemType), 1);
            road.Data.Inventory.TransferItemsTo(item.Destination.Data.Inventory, item.ItemType, 1);
            road.Data.Road.Items.Remove(item);
            return(true);
        }
Exemple #7
0
        /// <summary>
        /// Checks whether two voxelhandles are connected via roads, returning the roadpiece neighbouring the source handle that connects the given handles (or null if not connected).
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public IVoxelHandle IsConnected(IVoxelHandle source, IVoxelHandle target)
        {
            //TODO: return roadpiece of shortest route
            var connRoads = source.Get4Connected().Where(e => e.Type is RoadType);

            if (!connRoads.Any())
            {
                return(null);
            }

            foreach (var roadPiece in connRoads)
            {
                if (FindConnectedVoxels(roadPiece, handle => handle.Equals(target)).Any())
                {
                    return(roadPiece);
                }
            }
            return(null);
        }
Exemple #8
0
        private Matrix getYRot(IVoxelHandle handle)
        {
            var yRot      = Matrix.Identity;
            var neigbours = handle.Get4Connected().ToList();

            if (checkIsAccesibleWater(handle, neigbours[0]))
            {
                yRot = Matrix.RotationY((float)Math.PI * 0.5f);
            }
            if (checkIsAccesibleWater(handle, neigbours[2]))
            {
                yRot = Matrix.RotationY(-(float)Math.PI * 0.5f);
            }
            if (checkIsAccesibleWater(handle, neigbours[3]))
            {
                yRot = Matrix.RotationY((float)Math.PI);
            }
            return(yRot);
        }
Exemple #9
0
        public override IMesh GetMesh(IVoxelHandle handle)
        {
            var conn = handle.Get4Connected().ToArray();
            var tmp  = meshBuilder.CreateMesh(isConnected(handle, conn[0]), clippedHeightDiff(handle, conn[0]),
                                              isConnected(handle, conn[1]), clippedHeightDiff(handle, conn[1]),
                                              isConnected(handle, conn[2]), clippedHeightDiff(handle, conn[2]),
                                              isConnected(handle, conn[3]), clippedHeightDiff(handle, conn[3]));

            var builder = new MeshBuilder();

            builder.AddMesh(tmp, Matrix.Identity);
            var groundMesh = GetDefaultGroundMesh(handle.Data.Height);

            if (groundMesh == null)
            {
                return(tmp);
            }
            builder.AddMesh(groundMesh, Matrix.Identity);
            return(builder.CreateMesh());
        }
        public override void Tick(IVoxelHandle handle)
        {
            handle.EachRandomInterval(2, () =>
            {
                var possible = handle.Get4Connected().Where(e => e.Type == Hole).ToArray();
                if (possible.Length == 0)
                {
                    return;
                }

                foreach (var b in possible)
                {
                    b.ChangeType(Water);
                    b.Data.DataValue = 0;
                }
            });

            if (handle.Data.DataValue >= maxDataVal)
            {
                return;
            }
            handle.EachRandomInterval(0.5f, () => { handle.Data.DataValue++; });
        }
        private void tryOutput(IVoxelHandle handle)
        {
            if (handle.Data.Inventory.GetAmountOfType(Forest.GetWoodItemType()) < inventorySize)
            {
                return;
            }

            var itemType = Forest.GetWoodItemType();

            if (handle.Data.Inventory[itemType] == 0)
            {
                return;
            }

            var target = handle.Get4Connected().FirstOrDefault(v => v.CanAcceptItemType(itemType));

            if (target == null || !target.CanAcceptItemType(itemType))
            {
                return;
            }

            for (int i = 0; i < inventorySize; i++)
            {
                if (!target.CanAcceptItemType(itemType))
                {
                    break;
                }
                if (handle.Data.Inventory[itemType] == 0)
                {
                    break;
                }
                if (target.Type is RoadType)
                {
                    Road.DeliverItemClosest(target, handle, itemType);
                }
            }
        }
Exemple #12
0
 private bool hasWaterNeighbour(IVoxelHandle handle)
 {
     return(handle.Get4Connected().Any(e => checkIsAccesibleWater(handle, e)));
 }
Exemple #13
0
 private static IEnumerable <IVoxelHandle> getNeighbourRoads(IVoxelHandle curr)
 {
     return(curr.Get4Connected().Where(v => v.Type is RoadType && isOnReachableHeight(curr, v)));
 }
Exemple #14
0
 private static IEnumerable <IVoxelHandle> getNeighbourValidInventories(ItemType type, IVoxelHandle curr)
 {
     return(curr.Get4Connected().Where(v => !(v.Type is RoadType) && v.CanAcceptItemType(type)));
 }
Exemple #15
0
        public override IMesh GetMesh(IVoxelHandle handle)
        {
            var conn = handle.Get4Connected().ToArray();

            return(meshBuilder.CreateMesh(isConnectedType(conn[0]), isConnectedType(conn[1]), isConnectedType(conn[2]), isConnectedType(conn[3])));
        }