public VoxelInfo[, ,] ApplyRule(VoxelInfo[, ,] neighbourhood)
        {
            // Apply each 18-th turn
            if (neighbourhood[1, 1, 1].Ticks < TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD))
            {
                return(null);
            }

            VoxelInfo[, ,] output = new VoxelInfo[3, 3, 3];
            int gen = neighbourhood[1, 1, 1].Generation;

            if (gen == 0)
            {
                // Grow 3x3 and ovveride current generation
                output[1, 1, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 1, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 2);
                output[2, 1, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 4);
                output[0, 1, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 4);
                output[1, 1, 2] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 4);
                output[1, 1, 0] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 4);
                output[2, 1, 2] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2);
                output[2, 1, 0] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2);
                output[0, 1, 2] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2);
                output[0, 1, 0] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2);

                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[2, 0, 1].Type) || neighbourhood[2, 0, 1].Type == VoxelType.EMPTY)
                {
                    output[2, 0, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 4, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[0, 0, 1].Type) || neighbourhood[0, 0, 1].Type == VoxelType.EMPTY)
                {
                    output[0, 0, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 4, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[1, 0, 2].Type) || neighbourhood[1, 0, 2].Type == VoxelType.EMPTY)
                {
                    output[1, 0, 2] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 4, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[1, 0, 0].Type) || neighbourhood[1, 0, 0].Type == VoxelType.EMPTY)
                {
                    output[1, 0, 0] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, TypeInformation.GetGrowingSteps(VoxelType.SPRUCE_WOOD) / 4, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[2, 0, 2].Type) || neighbourhood[2, 0, 2].Type == VoxelType.EMPTY)
                {
                    output[2, 0, 2] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[2, 0, 0].Type) || neighbourhood[2, 0, 0].Type == VoxelType.EMPTY)
                {
                    output[2, 0, 0] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[0, 0, 2].Type) || neighbourhood[0, 0, 2].Type == VoxelType.EMPTY)
                {
                    output[0, 0, 2] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[0, 0, 0].Type) || neighbourhood[0, 0, 0].Type == VoxelType.EMPTY)
                {
                    output[0, 0, 0] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, 2, 0, 0, Direction.UP);
                }
            }
            else if (gen < TypeInformation.GetGrowHeight(VoxelType.SPRUCE_WOOD))
            {
                // Grow upwards
                // Grow in given direction
                Int3 coord = DirectionConverter.FromDirection(DirectionConverter.ToOppositeDirection(neighbourhood[1, 1, 1].From));
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[coord.X, coord.Y, coord.Z].Type) || neighbourhood[coord.X, coord.Y, coord.Z].Type == VoxelType.EMPTY)
                {
                    output[coord.X, coord.Y, coord.Z] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, gen + 1, 0, 0, neighbourhood[1, 1, 1].From);
                }
                //output[1, 2, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD, true, gen + 1);
                output[1, 1, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD);
            }
            else
            {
                // Grow upwards one last time
                //output[1, 2, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD);
                if (neighbourhood[1, 1, 1].From != Direction.UP)
                {
                    output[1, 2, 1] = new VoxelInfo(VoxelType.SPRUCE_NEEDLE, true);
                }
                output[1, 1, 1] = new VoxelInfo(VoxelType.SPRUCE_WOOD);
            }
            return(output);
        }
Esempio n. 2
0
        public VoxelInfo[, ,] ApplyRule(VoxelInfo[, ,] neighbourhood)
        {
            // Apply each 18-th turn
            if (neighbourhood[1, 1, 1].Ticks < TypeInformation.GetGrowingSteps(VoxelType.PINE_WOOD))
            {
                return(null);
            }

            int height = random.Next((int)(TypeInformation.GetGrowHeight(VoxelType.PINE_WOOD) * 0.75), (int)(TypeInformation.GetGrowHeight(VoxelType.PINE_WOOD) * 1.25));

            VoxelInfo[, ,] output = new VoxelInfo[3, 3, 3];
            int gen = neighbourhood[1, 1, 1].Generation;
            int res = neighbourhood[1, 1, 1].Resources;

            if (gen == 0)
            {
                // Grow Cross and ovveride current generation
                output[1, 1, 1] = new VoxelInfo(VoxelType.PINE_WOOD, true, 1, 0, TypeInformation.GetGrowingSteps(VoxelType.PINE_WOOD) / 2);
                output[2, 1, 1] = new VoxelInfo(VoxelType.PINE_WOOD, true, 2, 30);
                output[0, 1, 1] = new VoxelInfo(VoxelType.PINE_WOOD, true, 2, 30);
                output[1, 1, 2] = new VoxelInfo(VoxelType.PINE_WOOD, true, 2, 30);
                output[1, 1, 0] = new VoxelInfo(VoxelType.PINE_WOOD, true, 2, 30);

                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[1, 0, 1].Type) || neighbourhood[1, 0, 1].Type == VoxelType.EMPTY)
                {
                    output[1, 0, 1] = new VoxelInfo(VoxelType.PINE_WOOD, true, random.Next(1, height), 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[2, 0, 1].Type) || neighbourhood[2, 0, 1].Type == VoxelType.EMPTY)
                {
                    output[2, 0, 1] = new VoxelInfo(VoxelType.PINE_WOOD, true, random.Next(1, height), 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[0, 0, 1].Type) || neighbourhood[0, 0, 1].Type == VoxelType.EMPTY)
                {
                    output[0, 0, 1] = new VoxelInfo(VoxelType.PINE_WOOD, true, random.Next(1, height), 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[1, 0, 2].Type) || neighbourhood[1, 0, 2].Type == VoxelType.EMPTY)
                {
                    output[1, 0, 2] = new VoxelInfo(VoxelType.PINE_WOOD, true, random.Next(1, height), 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[1, 0, 0].Type) || neighbourhood[1, 0, 0].Type == VoxelType.EMPTY)
                {
                    output[1, 0, 0] = new VoxelInfo(VoxelType.PINE_WOOD, true, random.Next(1, height), 0, 0, Direction.UP);
                }
            }
            else if (gen == -1)
            {
                output[1, 2, 1] = new VoxelInfo(VoxelType.PINE_NEEDLE, true);
                output[1, 1, 1] = new VoxelInfo(VoxelType.PINE_WOOD);
            }
            else if (gen < height)
            {
                if (res > 0 && gen > TypeInformation.GetGrowHeight(VoxelType.PINE_WOOD) / 2)
                {
                    if (random.Next(0, 11) > 7)
                    {
                        res -= 15;
                        Direction grow = GetBranchDirection(neighbourhood);
                        Int3      temp = DirectionConverter.FromDirection(grow);
                        if (neighbourhood[temp.X, 0, temp.Z].Type == VoxelType.EMPTY || TypeInformation.IsNotWoodButBiomass(neighbourhood[temp.X, 0, temp.Z].Type))
                        {
                            output[temp.X, temp.Y, temp.Z] = new VoxelInfo(VoxelType.PINE_WOOD, true, random.Next((int)(height * 0.75), height), 0, 0, DirectionConverter.ToOppositeDirection(grow));
                        }
                    }
                }
                Int3 coord = DirectionConverter.FromDirection(DirectionConverter.ToOppositeDirection(neighbourhood[1, 1, 1].From));
                // Grow in given direction
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[coord.X, coord.Y, coord.Z].Type) || neighbourhood[coord.X, coord.Y, coord.Z].Type == VoxelType.EMPTY)
                {
                    output[coord.X, coord.Y, coord.Z] = new VoxelInfo(VoxelType.PINE_WOOD, true, gen + 1, res, 0, neighbourhood[1, 1, 1].From);
                }
                output[1, 1, 1] = new VoxelInfo(VoxelType.PINE_WOOD);
            }
            else
            {
                // Grow upwards one last time
                if (neighbourhood[1, 1, 1].From != Direction.UP)
                {
                    output[1, 2, 1] = new VoxelInfo(VoxelType.PINE_WOOD, true, -1, 0, TypeInformation.GetGrowingSteps(VoxelType.PINE_WOOD));
                }
                output[1, 1, 1] = new VoxelInfo(VoxelType.PINE_WOOD);
            }
            return(output);
        }
Esempio n. 3
0
        public VoxelInfo[, ,] ApplyRule(VoxelInfo[, ,] neighbourhood)
        {
            if (neighbourhood[1, 1, 1].Ticks < TypeInformation.GetGrowingSteps(VoxelType.HESPEROPHANES_CINNEREUS))
            {
                return(null);
            }

            VoxelInfo[, ,] output = new VoxelInfo[3, 3, 3];
            int gen = neighbourhood[1, 1, 1].Generation;
            int res = neighbourhood[1, 1, 1].Resources;

            int t = random.Next(0, 3);
            int h = random.Next(0, 3);
            int b = random.Next(0, 3);

            if (gen == 0)
            {
                if (IsWalkable(neighbourhood[t, h, b]))
                {
                    output[1, 1, 1] = new VoxelInfo(VoxelType.EMPTY);
                    output[t, h, b] = new VoxelInfo(VoxelType.HESPEROPHANES_CINNEREUS, true, 1);
                }
                else
                {
                    output[1, 1, 1] = new VoxelInfo(VoxelType.HESPEROPHANES_CINNEREUS, true, 1);
                }
            }
            else if (gen < TypeInformation.GetGrowHeight(VoxelType.HESPEROPHANES_CINNEREUS) && res == 10)
            {
                Int3 moveTo = DirectionConverter.FromDirection(neighbourhood[1, 1, 1].From);
                t = moveTo.X;
                h = moveTo.Y;
                b = moveTo.Z;
                output[t, h, b] = new VoxelInfo(VoxelType.HESPEROPHANES_CINNEREUS, true, 0);
                if (random.Next(0, 11) > 7)
                {
                    output[1, 1, 1] = new VoxelInfo(VoxelType.HESPEROPHANES_CINNEREUS, true, gen + random.Next(1, 5), 0, TypeInformation.GetGrowingSteps(VoxelType.HESPEROPHANES_CINNEREUS), Direction.SELF);
                }
                else
                {
                    output[1, 1, 1] = new VoxelInfo(VoxelType.EMPTY);
                }
            }
            else// if (gen < TypeInformation.GetGrowHeight(VoxelType.HESPEROPHANES_CINNEREUS))
            {
                Direction food = FoodInDirection(neighbourhood);
                if (food != Direction.SELF)
                {
                    Int3 foodPos = DirectionConverter.FromDirection(food);
                    int  eattime = -10;
                    if (neighbourhood[foodPos.X, foodPos.Y, foodPos.Z].Type == VoxelType.PINE_WOOD || neighbourhood[foodPos.X, foodPos.Y, foodPos.Z].Type == VoxelType.SPRUCE_WOOD)
                    {
                        eattime = -20;
                    }
                    if (neighbourhood[foodPos.X, foodPos.Y, foodPos.Z].Type == VoxelType.TEAK_WOOD || neighbourhood[foodPos.X, foodPos.Y, foodPos.Z].Type == VoxelType.OAK_WOOD)
                    {
                        eattime = -5;
                    }

                    output[1, 1, 1] = new VoxelInfo(VoxelType.HESPEROPHANES_CINNEREUS, true, gen + random.Next(0, 3), 10, eattime, food);
                }
                else if (IsWalkable(neighbourhood[t, h, b]))
                {
                    output[1, 1, 1] = new VoxelInfo(VoxelType.EMPTY);
                    output[t, h, b] = new VoxelInfo(VoxelType.HESPEROPHANES_CINNEREUS, true, gen + random.Next(1, 5));
                }
                else
                {
                    output[1, 1, 1] = new VoxelInfo(VoxelType.HESPEROPHANES_CINNEREUS, true, gen + random.Next(1, 5));
                }
            }

            /* else
             * {
             *   output[1, 1, 1] = new VoxelInfo(VoxelType.EMPTY);
             * }*/

            return(output);
        }
Esempio n. 4
0
        public VoxelInfo[, ,] ApplyRule(VoxelInfo[, ,] neighbourhood)
        {
            // Apply each 18-th turn
            if (neighbourhood[1, 1, 1].Ticks < TypeInformation.GetGrowingSteps(VoxelType.TEAK_WOOD))
            {
                return(null);
            }

            int height = random.Next((int)(TypeInformation.GetGrowHeight(VoxelType.TEAK_WOOD) * 0.75), (int)(TypeInformation.GetGrowHeight(VoxelType.TEAK_WOOD) * 1.25));

            VoxelInfo[, ,] output = new VoxelInfo[3, 3, 3];
            int gen = neighbourhood[1, 1, 1].Generation;

            if (gen == 0)
            {
                // Grow a 2x2 quad (override current generation)
                output[1, 1, 1] = new VoxelInfo(VoxelType.TEAK_WOOD, true, 1);
                output[2, 1, 1] = new VoxelInfo(VoxelType.TEAK_WOOD, true, 1);
                output[1, 1, 2] = new VoxelInfo(VoxelType.TEAK_WOOD, true, 1);
                output[2, 1, 2] = new VoxelInfo(VoxelType.TEAK_WOOD, true, 1);

                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[1, 0, 1].Type) || neighbourhood[1, 0, 1].Type == VoxelType.EMPTY)
                {
                    output[1, 0, 1] = new VoxelInfo(VoxelType.TEAK_WOOD, true, 1, 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[2, 0, 1].Type) || neighbourhood[2, 0, 1].Type == VoxelType.EMPTY)
                {
                    output[2, 0, 1] = new VoxelInfo(VoxelType.TEAK_WOOD, true, 1, 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[1, 0, 2].Type) || neighbourhood[1, 0, 2].Type == VoxelType.EMPTY)
                {
                    output[1, 0, 2] = new VoxelInfo(VoxelType.TEAK_WOOD, true, 1, 0, 0, Direction.UP);
                }
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[2, 0, 2].Type) || neighbourhood[2, 0, 2].Type == VoxelType.EMPTY)
                {
                    output[2, 0, 2] = new VoxelInfo(VoxelType.TEAK_WOOD, true, 1, 0, 0, Direction.UP);
                }
            }
            else if (gen < height)
            {
                Int3 coord = DirectionConverter.FromDirection(DirectionConverter.ToOppositeDirection(neighbourhood[1, 1, 1].From));
                // Grow in given direction
                if (TypeInformation.IsNotWoodButBiomass(neighbourhood[coord.X, coord.Y, coord.Z].Type) || neighbourhood[coord.X, coord.Y, coord.Z].Type == VoxelType.EMPTY)
                {
                    output[coord.X, coord.Y, coord.Z] = new VoxelInfo(VoxelType.TEAK_WOOD, true, gen + 1, 0, 0, neighbourhood[1, 1, 1].From);
                }
                output[1, 1, 1] = new VoxelInfo(VoxelType.TEAK_WOOD);
            }
            else
            {
                if (neighbourhood[1, 1, 1].From == Direction.DOWN)
                {
                    if (TypeInformation.IsNotWoodButBiomass(neighbourhood[1, 2, 1].Type) || neighbourhood[1, 2, 1].Type == VoxelType.EMPTY)
                    {
                        output[1, 2, 1] = new VoxelInfo(VoxelType.TEAK_LEAF, true, 1);
                    }
                }
                output[1, 1, 1] = new VoxelInfo(VoxelType.TEAK_WOOD);
            }
            return(output);
        }