Example #1
0
        internal override void GeneratePartial(IServerChunk[] chunks, int intoChunkX, int intoChunkZ, int fromChunkdX, int fromChunkdZ)
        {
            for (int i = 0; i < deposits.variants.Length; i++)
            {
                DepositVariant variant = deposits.variants[i];

                float quantityFactor = 1;
                int   originChunkX   = intoChunkX + fromChunkdX;
                int   originChunkZ   = intoChunkZ + fromChunkdZ;

                if (variant.WithOreMap)
                {
                    IMapRegion originMapRegion = api.WorldManager.GetMapRegion((originChunkX * chunksize) / regionSize, (originChunkZ * chunksize) / regionSize);
                    if (originMapRegion == null)
                    {
                        continue;
                    }
                    int lx = (originChunkX * chunksize + chunksize / 2) % regionSize;
                    int lz = (originChunkZ * chunksize + chunksize / 2) % regionSize;

                    IntMap map = null;
                    originMapRegion.OreMaps.TryGetValue(variant.Code, out map);
                    if (map != null)
                    {
                        float posXInRegionOre = GameMath.Clamp((float)lx / regionSize * noiseSizeOre, 0, noiseSizeOre - 1);
                        float posZInRegionOre = GameMath.Clamp((float)lz / regionSize * noiseSizeOre, 0, noiseSizeOre - 1);

                        int oreDist = originMapRegion.OreMaps[variant.Code].GetUnpaddedColorLerped(posXInRegionOre, posZInRegionOre);

                        quantityFactor = (oreDist & 0xff) / 255f;
                    }
                }

                float qModified = variant.Quantity * quantityFactor;
                int   quantity  = (int)qModified;
                quantity += chunkRand.NextInt(100) < 100 * (qModified - quantity) ? 1 : 0;


                while (quantity-- > 0)
                {
                    int offsetX = chunksize * fromChunkdX + chunkRand.NextInt(chunksize);
                    int offsetZ = chunksize * fromChunkdZ + chunkRand.NextInt(chunksize);

                    depositRand.SetWorldSeed(chunkRand.NextInt(10000000));
                    depositRand.InitPositionSeed(intoChunkX + fromChunkdX, intoChunkZ + fromChunkdZ);

                    Dictionary <Vec3i, DepositVariant> SubDepositsToPlace = GenDeposit(chunks, intoChunkX, intoChunkZ, offsetX, offsetZ, variant);


                    foreach (var val in SubDepositsToPlace)
                    {
                        depositRand.SetWorldSeed(chunkRand.NextInt(10000000));
                        depositRand.InitPositionSeed(intoChunkX + fromChunkdX, intoChunkZ + fromChunkdZ);

                        GenDeposit(chunks, intoChunkX, intoChunkZ, val.Key.X, val.Key.Z, val.Value, val.Key.Y);
                    }
                }
            }
        }
Example #2
0
 internal virtual void GenChunkColumn(IServerChunk[] chunks, int chunkX, int chunkZ)
 {
     for (int dx = -chunkRange; dx <= chunkRange; dx++)
     {
         for (int dz = -chunkRange; dz <= chunkRange; dz++)
         {
             chunkRand.InitPositionSeed(chunkX + dx, chunkZ + dz);
             GeneratePartial(chunks, chunkX, chunkZ, dx, dz);
         }
     }
 }
Example #3
0
        public void UpdateCloudTiles()
        {
            weatherSim.EnsureNoiseCacheIsFresh();
            byte zero = 0;
            int  end  = CloudTileLength - 2;

            // Load density from perlin noise
            for (int dx = 0; dx < CloudTileLength; dx++)
            {
                for (int dz = 0; dz < CloudTileLength; dz++)
                {
                    int x = (tilePosX + dx - CloudTileLength / 2 - tileOffsetX);
                    int z = (tilePosZ + dz - CloudTileLength / 2 - tileOffsetZ);
                    brightnessRand.InitPositionSeed(x, z);
                    double density = weatherSim.GetBlendedCloudDensityAt(dx, dz);

                    CloudTile cloudTile = cloudTiles[dx * CloudTileLength + dz];

                    cloudTile.MaxDensity = (byte)GameMath.Clamp((int)((64 * 255 * density * 3)) / 64, 0, 255);
                    cloudTile.Brightness = (byte)(235 + brightnessRand.NextInt(21));
                    cloudTile.YOffset    = (float)weatherSim.GetBlendedCloudOffsetYAt(dx, dz);
                }
            }


            // Has to be done after all densities have updated
            for (int dx = 0; dx < CloudTileLength; dx++)
            {
                for (int dz = 0; dz < CloudTileLength; dz++)
                {
                    CloudTile cloud = cloudTiles[dx * CloudTileLength + dz];

                    byte northDensity = dz < 1 ? zero : cloudTiles[dx * CloudTileLength + dz - 1].MaxDensity;
                    byte southDensity = dz >= end ? zero : cloudTiles[dx * CloudTileLength + dz + 1].MaxDensity;
                    byte eastDensity  = dx >= end ? zero : cloudTiles[(dx + 1) * CloudTileLength + dz].MaxDensity;
                    byte westDensity  = dx < 1 ? zero : cloudTiles[(dx - 1) * CloudTileLength + dz].MaxDensity;

                    int changeVal = northDensity == 0 || cloud.MaxDensity - northDensity > 5 ? 1 : -1;
                    cloud.NorthFaceDensity = (byte)GameMath.Clamp((cloud.NorthFaceDensity + changeVal), 0, cloud.MaxDensity);

                    changeVal             = eastDensity == 0 || cloud.MaxDensity - eastDensity > 5 ? 1 : -1;
                    cloud.EastFaceDensity = (byte)GameMath.Clamp((cloud.EastFaceDensity + changeVal), 0, cloud.MaxDensity);

                    changeVal = southDensity == 0 || cloud.MaxDensity - southDensity > 5 ? 1 : -1;
                    cloud.SouthFaceDensity = (byte)GameMath.Clamp((cloud.SouthFaceDensity + changeVal), 0, cloud.MaxDensity);

                    changeVal             = westDensity == 0 || cloud.MaxDensity - westDensity > 5 ? 1 : -1;
                    cloud.WestFaceDensity = (byte)GameMath.Clamp((cloud.WestFaceDensity + changeVal), 0, cloud.MaxDensity);

                    cloud.UpDownDensity += (byte)GameMath.Clamp(cloud.MaxDensity - cloud.UpDownDensity, -1, 1);
                }
            }
        }
Example #4
0
        internal override void GeneratePartial(IServerChunk[] chunks, int chunkX, int chunkZ, int cdx, int cdz)
        {
            int quantityCaves = chunkRand.NextInt(81) / 60;

            while (quantityCaves-- > 0)
            {
                int posX = cdx * chunksize + chunkRand.NextInt(chunksize);
                int posY = chunkRand.NextInt(worldheight - 20) + 8;
                int posZ = cdz * chunksize + chunkRand.NextInt(chunksize);


                float horAngle       = chunkRand.NextFloat() * GameMath.TWOPI;
                float vertAngle      = (chunkRand.NextFloat() - 0.5f) * 0.25f;
                float horizontalSize = chunkRand.NextFloat() * 2 + chunkRand.NextFloat();

                int maxIterations = chunkRange * chunksize - chunksize / 2;
                maxIterations = maxIterations - chunkRand.NextInt(maxIterations / 4);

                caveRand.SetWorldSeed(chunkRand.NextInt(10000000));
                caveRand.InitPositionSeed(chunkX + cdx, chunkZ + cdz);
                CarveTunnel(chunks, chunkX, chunkZ, posX, posY, posZ, horAngle, vertAngle, horizontalSize, 1f, 0, maxIterations, 0);
            }
        }
Example #5
0
        private void CmdCaveGenTest(IServerPlayer player, int groupId, CmdArgs args)
        {
            chunkRand = new FastPositionalRandom(api.WorldManager.Seed);

            airBlockId = api.World.GetBlock(new AssetLocation("rock-granite")).BlockId;

            int baseChunkX = api.World.BlockAccessor.MapSizeX / 2 / chunksize;
            int baseChunkZ = api.World.BlockAccessor.MapSizeZ / 2 / chunksize;

            for (int dx = -5; dx <= 5; dx++)
            {
                for (int dz = -5; dz <= 5; dz++)
                {
                    int chunkX = baseChunkX + dx;
                    int chunkZ = baseChunkZ + dz;

                    IServerChunk[] chunks = GetChunkColumn(chunkX, chunkZ);
                    ClearChunkColumn(chunks);


                    for (int gdx = -chunkRange; gdx <= chunkRange; gdx++)
                    {
                        for (int gdz = -chunkRange; gdz <= chunkRange; gdz++)
                        {
                            chunkRand.InitPositionSeed(chunkX + gdx, chunkZ + gdz);
                            GeneratePartial(chunks, chunkX, chunkZ, gdx, gdz);
                        }
                    }

                    MarkDirty(chunkX, chunkZ, chunks);
                }
            }

            airBlockId = 0;

            player.SendMessage(groupId, "Generated and chunks force resend flags set", EnumChatType.Notification);
        }