Пример #1
0
        /// <summary>
        /// This method performs a deep copy of the initial world state to a backup array for later restoration.
        /// </summary>
        private void CopyBlocks()
        {
            for (int x = 0; x < Blocks.GetLength(0); x++)
            {
                for (int y = 0; y < Blocks.GetLength(1); y++)
                {
                    for (int z = 0; z < Blocks.GetLength(2); z++)
                    {
                        if (Blocks[x, y, z] is AirBlock)
                        {
                            InitialBlocks[x, y, z] = new AirBlock();
                        }
                        else if (Blocks[x, y, z] is MulchBlock)
                        {
                            InitialBlocks[x, y, z] = new MulchBlock();
                        }
                        else if (Blocks[x, y, z] is ContainerBlock)
                        {
                            InitialBlocks[x, y, z] = new ContainerBlock();
                        }
                        else if (Blocks[x, y, z] is GrassBlock)
                        {
                            InitialBlocks[x, y, z] = new GrassBlock();
                        }
                        else if (Blocks[x, y, z] is StoneBlock)
                        {
                            InitialBlocks[x, y, z] = new StoneBlock();
                        }
                        else if (Blocks[x, y, z] is AcidicBlock)
                        {
                            InitialBlocks[x, y, z] = new AcidicBlock();
                        }
                        else if (Blocks[x, y, z] is NestBlock)
                        {
                            InitialBlocks[x, y, z] = new NestBlock();
                        }

                        InitialBlocks[x, y, z].worldXCoordinate = x;
                        InitialBlocks[x, y, z].worldYCoordinate = y;
                        InitialBlocks[x, y, z].worldZCoordinate = z;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Alters a pre-generated map so that acid blocks exist.
        /// </summary>
        private void GenerateAcidicRegions()
        {
            for (int i = 0; i < ConfigurationManager.Instance.Number_Of_Acidic_Regions; i++)
            {
                int xCoord = RNG.Next(0, Blocks.GetLength(0));
                int zCoord = RNG.Next(0, Blocks.GetLength(2));
                int yCoord = -1;
                for (int j = Blocks.GetLength(1) - 1; j >= 0; j--)
                {
                    if (Blocks[xCoord, j, zCoord] as AirBlock == null)
                    {
                        yCoord = j;
                        break;
                    }
                }

                //Generate a sphere around this point overriding non-air blocks
                for (int HX = xCoord - ConfigurationManager.Instance.Acidic_Region_Radius; HX < xCoord + ConfigurationManager.Instance.Acidic_Region_Radius; HX++)
                {
                    for (int HZ = zCoord - ConfigurationManager.Instance.Acidic_Region_Radius; HZ < zCoord + ConfigurationManager.Instance.Acidic_Region_Radius; HZ++)
                    {
                        for (int HY = yCoord - ConfigurationManager.Instance.Acidic_Region_Radius; HY < yCoord + ConfigurationManager.Instance.Acidic_Region_Radius; HY++)
                        {
                            float xSquare = (xCoord - HX) * (xCoord - HX);
                            float ySquare = (yCoord - HY) * (yCoord - HY);
                            float zSquare = (zCoord - HZ) * (zCoord - HZ);
                            float Dist    = Mathf.Sqrt(xSquare + ySquare + zSquare);
                            if (Dist <= ConfigurationManager.Instance.Acidic_Region_Radius)
                            {
                                int CX, CY, CZ;
                                CX = Mathf.Clamp(HX, 1, Blocks.GetLength(0) - 2);
                                CZ = Mathf.Clamp(HZ, 1, Blocks.GetLength(2) - 2);
                                CY = Mathf.Clamp(HY, 1, Blocks.GetLength(1) - 2);
                                if (Blocks[CX, CY, CZ] as AirBlock != null)
                                {
                                    Blocks[CX, CY, CZ] = new AcidicBlock();
                                }
                            }
                        }
                    }
                }
            }
        }