Exemplo n.º 1
0
        private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            IntMap map;

            for (int i = 0; i < deposits.variants.Length; i++)
            {
                DepositVariant variant = deposits.variants[i];
                if (variant.OreMap != null)
                {
                    map      = new IntMap();
                    map.Size = noiseSizeOre + 1;
                    map.BottomRightPadding = 1;
                    map.Data = variant.OreMap.GenLayer(regionX * noiseSizeOre, regionZ * noiseSizeOre, noiseSizeOre + 1, noiseSizeOre + 1);
                    mapRegion.OreMaps[variant.Code] = map;
                }

                if (variant.ChildDeposits != null)
                {
                    for (int k = 0; k < variant.ChildDeposits.Length; k++)
                    {
                        DepositVariant childVariant = variant.ChildDeposits[k];
                        if (childVariant.OreMap != null)
                        {
                            map      = new IntMap();
                            map.Size = noiseSizeOre + 1;
                            map.BottomRightPadding = 1;
                            map.Data = childVariant.OreMap.GenLayer(regionX * noiseSizeOre, regionZ * noiseSizeOre, noiseSizeOre + 1, noiseSizeOre + 1);
                            mapRegion.OreMaps[childVariant.Code] = map;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public float GetOreMapFactor(int chunkx, int chunkz)
        {
            IMapRegion originMapRegion = api?.WorldManager.GetMapRegion(chunkx * chunksize / regionSize, chunkz * chunksize / regionSize);

            if (originMapRegion == null)
            {
                return(0);
            }
            int lx = (chunkx * chunksize + chunksize / 2) % regionSize;
            int lz = (chunkz * chunksize + chunksize / 2) % regionSize;

            IntDataMap2D map;

            originMapRegion.OreMaps.TryGetValue(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 = map.GetUnpaddedColorLerped(posXInRegionOre, posZInRegionOre);

                return((oreDist & 0xff) / 255f);
            }

            return(0);
        }
Exemplo n.º 3
0
        public void DebugVeinMaps(ICoreServerAPI api, IMapRegion mapRegion, int regionX, int regionZ)
        {
            TyronThreadPool.QueueTask(() =>
            {
                DirectoryInfo path = Directory.CreateDirectory(Path.Combine(GamePaths.DataPath, "VeinMaps", api.World.Seed.ToString()));
                Dictionary <string, IntDataMap2D> veinMaps = mapRegion.GetModdata <Dictionary <string, IntDataMap2D> >("veinmaps");

                foreach (var vein in veinMaps)
                {
                    IntDataMap2D veinMap = vein.Value;

                    Bitmap bmp = new Bitmap(veinMap.Size, veinMap.Size);
                    for (int x = 0; x < veinMap.Size; x++)
                    {
                        for (int y = 0; y < veinMap.Size; y++)
                        {
                            Argb8 test = new Argb8(veinMap.GetInt(x, y));
                            bmp.SetPixel(x, y, Color.FromArgb(test.Value));
                        }
                    }
                    Directory.CreateDirectory(Path.Combine(path.FullName, vein.Key.UcFirst()));

                    string pt = Path.Combine(path.FullName, vein.Key.UcFirst(), string.Format("{0}, {1}.png", regionX, regionZ));

                    bmp.Save(pt, ImageFormat.Png);
                }
            });
        }
Exemplo n.º 4
0
        public void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            IntDataMap2D map;

            if (OreMapLayer != null && !mapRegion.OreMaps.ContainsKey(Code))
            {
                map      = new IntDataMap2D();
                map.Size = noiseSizeOre + 1;
                map.BottomRightPadding = 1;
                map.Data = OreMapLayer.GenLayer(regionX * noiseSizeOre, regionZ * noiseSizeOre, noiseSizeOre + 1, noiseSizeOre + 1);
                mapRegion.OreMaps[Code] = map;
            }

            if (ChildDeposits != null)
            {
                for (int k = 0; k < ChildDeposits.Length; k++)
                {
                    DepositVariant childVariant = ChildDeposits[k];
                    if (childVariant.OreMapLayer != null && !mapRegion.OreMaps.ContainsKey(childVariant.Code))
                    {
                        map      = new IntDataMap2D();
                        map.Size = noiseSizeOre + 1;
                        map.BottomRightPadding = 1;
                        map.Data = childVariant.OreMapLayer.GenLayer(regionX * noiseSizeOre, regionZ * noiseSizeOre, noiseSizeOre + 1, noiseSizeOre + 1);
                        mapRegion.OreMaps[childVariant.Code] = map;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            int i = 0;

            Dictionary <string, IntDataMap2D> maps = new Dictionary <string, IntDataMap2D>();

            foreach (var val in mapRegion.OreMaps)
            {
                var OreVeinLayer = new MapLayerFractalARGB(api.World.Seed + i, 8, 0.0f, 64, 2048, 1024, 64, 128.0, 0.001);

                int regionSize = api.WorldManager.RegionSize;

                IntDataMap2D data = new IntDataMap2D()
                {
                    Data = OreVeinLayer.GenLayerDiffuse(regionX * regionSize, regionZ * regionSize, 128, regionSize, 0b1010001, 2, 0, 4, 8),
                    Size = regionSize,
                    BottomRightPadding = 0,
                    TopLeftPadding     = 0
                };

                maps[val.Key] = data;
                i++;
#if DEBUG
                api.Logger.StoryEvent(Math.Round(((float)i / mapRegion.OreMaps.Count) * 100, 2).ToString());
#endif
            }

            mapRegion.SetModdata("veinmaps", maps);

#if DEBUG
            DebugVeinMaps(api, mapRegion, regionX, regionZ);
#endif
        }
Exemplo n.º 6
0
        private bool ShouldPlaceAdjustedForOreMap(DepositVariant variant, int posX, int posZ, float quantity, float rndVal)
        {
            if (!variant.WithOreMap)
            {
                return(true);
            }

            float      quantityFactor  = 1;
            IMapRegion originMapRegion = api.WorldManager.GetMapRegion((posX) / regionSize, (posZ) / regionSize);

            if (originMapRegion == null)
            {
                return(false);
            }
            int lx = posX % regionSize;
            int lz = posZ % regionSize;

            IntMap map = null;

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

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

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

            return(quantity * quantityFactor > rndVal);
        }
Exemplo n.º 7
0
        public void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            int pad = 2;

            TerraGenConfig.depositVerticalDistortScale = 2;
            int noiseSize = api.WorldManager.RegionSize / TerraGenConfig.depositVerticalDistortScale;

            IntDataMap2D map = mapRegion.OreMapVerticalDistortBottom;

            map.Size = noiseSize + 2 * pad;
            map.BottomRightPadding = map.TopLeftPadding = pad;
            map.Data = verticalDistortBottom.GenLayer(regionX * noiseSize - pad, regionZ * noiseSize - pad, noiseSize + 2 * pad, noiseSize + 2 * pad);

            map      = mapRegion.OreMapVerticalDistortTop;
            map.Size = noiseSize + 2 * pad;
            map.BottomRightPadding = map.TopLeftPadding = pad;
            map.Data = verticalDistortTop.GenLayer(regionX * noiseSize - pad, regionZ * noiseSize - pad, noiseSize + 2 * pad, noiseSize + 2 * pad);


            for (int i = 0; i < Deposits.Length; i++)
            {
                DepositVariant variant = Deposits[i];
                variant.OnMapRegionGen(mapRegion, regionX, regionZ);
            }
        }
Exemplo n.º 8
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);
                    }
                }
            }
        }
Exemplo n.º 9
0
        void PrintProbeResults(IWorldAccessor world, IServerPlayer byPlayer, IItemSlot itemslot, BlockPos pos)
        {
            IBlockAccessor blockAccess = world.BlockAccessor;
            int            chunksize   = blockAccess.ChunkSize;
            int            regsize     = blockAccess.RegionSize;

            int mapheight    = blockAccess.GetTerrainMapheightAt(pos);
            int qchunkblocks = mapheight * chunksize * chunksize;

            IMapRegion reg = world.BlockAccessor.GetMapRegion(pos.X / regsize, pos.Z / regsize);
            int        lx  = pos.X % regsize;
            int        lz  = pos.Z % regsize;

            StringBuilder outtext = new StringBuilder();
            int           found   = 0;

            foreach (var val in reg.OreMaps)
            {
                IntMap map       = val.Value;
                int    noiseSize = map.InnerSize;

                float posXInRegionOre = (float)lx / regsize * noiseSize;
                float posZInRegionOre = (float)lz / regsize * noiseSize;

                int oreDist = map.GetUnpaddedColorLerped(posXInRegionOre, posZInRegionOre);

                double   absAvgq  = absAvgQuantity[val.Key];
                double   factor   = (oreDist & 0xff) / 255.0;
                double   quantity = factor * absAvgq;
                double   relq     = quantity / qchunkblocks;
                double   ppt      = relq * 1000;
                string[] names    = new string[] { "Very poor density", "Poor density", "Decent density", "High density", "Very high density", "Ultra high density" };

                if (factor > 0.05)
                {
                    if (found > 0)
                    {
                        outtext.Append("\n");
                    }
                    outtext.Append(string.Format("{1}: {2} ({0}‰)", ppt.ToString("0.#"), val.Key.Substring(0, 1).ToUpper() + val.Key.Substring(1), names[(int)GameMath.Clamp(factor * 5, 0, 5)]));
                    found++;
                }
            }

            IServerPlayer splr = byPlayer as IServerPlayer;

            if (outtext.Length == 0)
            {
                outtext.Append("No significant resources here.");
            }
            else
            {
                outtext.Insert(0, "Found " + found + " traces of ore\n");
            }
            splr.SendMessage(GlobalConstants.CurrentChatGroup, outtext.ToString(), EnumChatType.Notification);
        }
Exemplo n.º 10
0
        private void DoGenVillages(IMapRegion region, int chunkX, int chunkZ, bool postPass, ITreeAttribute chunkGenParams = null)
        {
            BlockPos pos = new BlockPos();

            strucRand.InitPositionSeed(chunkX, chunkZ);

            for (int i = 0; i < vcfg.VillageTypes.Length; i++)
            {
                WorldGenVillage struc = vcfg.VillageTypes[i];
                if (struc.PostPass != postPass)
                {
                    continue;
                }

                float chance = struc.Chance * vcfg.ChanceMultiplier;

                while (chance-- > strucRand.NextDouble())
                {
                    int dx       = strucRand.NextInt(chunksize);
                    int dz       = strucRand.NextInt(chunksize);
                    int ySurface = heightmap[dz * chunksize + dx];
                    if (ySurface <= 0 || ySurface >= worldheight - 15)
                    {
                        continue;
                    }

                    pos.Set(chunkX * chunksize + dx, ySurface, chunkZ * chunksize + dz);

                    struc.TryGenerate(worldgenBlockAccessor, api.World, pos, climateUpLeft, climateUpRight, climateBotLeft, climateBotRight, (loc, schematic) =>
                    {
                        string code = struc.Code + (schematic == null ? "" : "/" + schematic.FromFileName);

                        region.GeneratedStructures.Add(new GeneratedStructure()
                        {
                            Code = code, Group = struc.Group, Location = loc.Clone()
                        });
                        region.DirtyForSaving = true;

                        if (struc.BuildProtected)
                        {
                            api.World.Claims.Add(new LandClaim()
                            {
                                Areas = new List <Cuboidi>()
                                {
                                    loc.Clone()
                                },
                                Description        = struc.BuildProtectionDesc,
                                ProtectionLevel    = 10,
                                LastKnownOwnerName = struc.BuildProtectionName,
                                AllowUse           = true
                            });
                        }
                    });
                }
            }
        }
Exemplo n.º 11
0
        private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            int pad = TerraGenConfig.geoProvMapPadding;

            mapRegion.GeologicProvinceMap.Data = geologicprovinceGen.GenLayer(
                regionX * noiseSizeGeoProv - pad,
                regionZ * noiseSizeGeoProv - pad,
                noiseSizeGeoProv + 2 * pad,
                noiseSizeGeoProv + 2 * pad
                );
            mapRegion.GeologicProvinceMap.Size           = noiseSizeGeoProv + 2 * pad;
            mapRegion.GeologicProvinceMap.TopLeftPadding = mapRegion.GeologicProvinceMap.BottomRightPadding = pad;

            pad = 2;
            mapRegion.ClimateMap.Data = climateGen.GenLayer(
                regionX * noiseSizeClimate - pad,
                regionZ * noiseSizeClimate - pad,
                noiseSizeClimate + 2 * pad,
                noiseSizeClimate + 2 * pad
                );
            mapRegion.ClimateMap.Size           = noiseSizeClimate + 2 * pad;
            mapRegion.ClimateMap.TopLeftPadding = mapRegion.ClimateMap.BottomRightPadding = pad;


            mapRegion.ForestMap.Size = noiseSizeForest + 1;
            mapRegion.ForestMap.BottomRightPadding = 1;
            forestGen.SetInputMap(mapRegion.ClimateMap, mapRegion.ForestMap);
            mapRegion.ForestMap.Data = forestGen.GenLayer(regionX * noiseSizeForest, regionZ * noiseSizeForest, noiseSizeForest + 1, noiseSizeForest + 1);


            mapRegion.BeachMap.Size = noiseSizeBeach + 1;
            mapRegion.BeachMap.BottomRightPadding = 1;
            mapRegion.BeachMap.Data = beachGen.GenLayer(regionX * noiseSizeBeach, regionZ * noiseSizeBeach, noiseSizeBeach + 1, noiseSizeBeach + 1);

            mapRegion.ShrubMap.Size = noiseSizeShrubs + 1;
            mapRegion.ShrubMap.BottomRightPadding = 1;
            bushGen.SetInputMap(mapRegion.ClimateMap, mapRegion.ShrubMap);
            mapRegion.ShrubMap.Data = bushGen.GenLayer(regionX * noiseSizeShrubs, regionZ * noiseSizeShrubs, noiseSizeShrubs + 1, noiseSizeShrubs + 1);


            mapRegion.FlowerMap.Size = noiseSizeForest + 1;
            mapRegion.FlowerMap.BottomRightPadding = 1;
            flowerGen.SetInputMap(mapRegion.ClimateMap, mapRegion.FlowerMap);
            mapRegion.FlowerMap.Data = flowerGen.GenLayer(regionX * noiseSizeForest, regionZ * noiseSizeForest, noiseSizeForest + 1, noiseSizeForest + 1);



            pad = TerraGenConfig.landformMapPadding;
            mapRegion.LandformMap.Data           = landformsGen.GenLayer(regionX * noiseSizeLandform - pad, regionZ * noiseSizeLandform - pad, noiseSizeLandform + 2 * pad, noiseSizeLandform + 2 * pad);
            mapRegion.LandformMap.Size           = noiseSizeLandform + 2 * pad;
            mapRegion.LandformMap.TopLeftPadding = mapRegion.LandformMap.BottomRightPadding = pad;


            mapRegion.DirtyForSaving = true;
        }
Exemplo n.º 12
0
        public WeatherSimulationRegion getOrCreateWeatherSimForRegion(int regionX, int regionZ)
        {
            long       index2d   = MapRegionIndex2D(regionX, regionZ);
            IMapRegion mapregion = api.World.BlockAccessor.GetMapRegion(regionX, regionZ);

            if (mapregion == null)
            {
                return(null);
            }
            return(getOrCreateWeatherSimForRegion(index2d, mapregion));
        }
Exemplo n.º 13
0
        private void OnChunkColumnGenPostPass(IServerChunk[] chunks, int chunkX, int chunkZ, ITreeAttribute chunkGenParams = null)
        {
            if (!TerraGenConfig.GenerateStructures)
            {
                return;
            }

            IMapRegion region = chunks[0].MapChunk.MapRegion;

            DoGenStructures(region, chunkX, chunkZ, true, chunkGenParams);
            DoGenVillages(region, chunkX, chunkZ, true, chunkGenParams);
        }
Exemplo n.º 14
0
        private void Event_MapRegionLoaded(Vec2i mapCoord, IMapRegion region)
        {
            byte[] data = region.GetModdata("clothSystems");

            if (data != null && data.Length != 0)
            {
                var rsystems = SerializerUtil.Deserialize <List <ClothSystem> >(data);

                // Don't even try to resolve anything while the server is still starting up
                if (sapi.Server.CurrentRunPhase < EnumServerRunPhase.RunGame)
                {
                    foreach (var system in rsystems)
                    {
                        system.Active = false;
                        system.Init(api, this);
                        clothSystems[system.ClothId] = system;
                    }
                }
                else
                {
                    foreach (var system in clothSystems.Values)
                    {
                        system.updateActiveState(EnumActiveStateChange.RegionNowLoaded);
                    }

                    foreach (var system in rsystems)
                    {
                        system.Init(api, this);
                        system.restoreReferences();
                        clothSystems[system.ClothId] = system;
                    }


                    if (rsystems.Count > 0)
                    {
                        sapi.Network.GetChannel("clothphysics").BroadcastPacket(new ClothSystemPacket()
                        {
                            ClothSystems = rsystems.ToArray()
                        });
                    }
                }
            }
            else
            {
                if (sapi.Server.CurrentRunPhase >= EnumServerRunPhase.RunGame)
                {
                    foreach (var system in clothSystems.Values)
                    {
                        system.updateActiveState(EnumActiveStateChange.RegionNowLoaded);
                    }
                }
            }
        }
Exemplo n.º 15
0
        private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            /*mapRegion.DepositDistortionMap.Size = noiseSizeDepositDistortion + 1;
             * mapRegion.DepositDistortionMap.BottomRightPadding = 1;
             * mapRegion.DepositDistortionMap.Data = depositDistortionGen.GenLayer(regionX * noiseSizeDepositDistortion, regionZ * noiseSizeDepositDistortion, noiseSizeDepositDistortion + 1, noiseSizeDepositDistortion + 1);*/


            int pad = TerraGenConfig.geoProvMapPadding;

            mapRegion.GeologicProvinceMap.Data = geologicprovinceGen.GenLayer(
                regionX * noiseSizeGeoProv - pad,
                regionZ * noiseSizeGeoProv - pad,
                noiseSizeGeoProv + 2 * pad,
                noiseSizeGeoProv + 2 * pad
                );
            mapRegion.GeologicProvinceMap.Size           = noiseSizeGeoProv + 2 * pad;
            mapRegion.GeologicProvinceMap.TopLeftPadding = mapRegion.GeologicProvinceMap.BottomRightPadding = pad;

            mapRegion.ClimateMap.Size = noiseSizeClimate + 1;
            mapRegion.ClimateMap.BottomRightPadding = 1;
            mapRegion.ClimateMap.Data = climateGen.GenLayer(regionX * noiseSizeClimate, regionZ * noiseSizeClimate, noiseSizeClimate + 1, noiseSizeClimate + 1);


            mapRegion.ForestMap.Size = noiseSizeForest + 1;
            mapRegion.ForestMap.BottomRightPadding = 1;
            forestGen.SetInputMap(mapRegion.ClimateMap, mapRegion.ForestMap);
            mapRegion.ForestMap.Data = forestGen.GenLayer(regionX * noiseSizeForest, regionZ * noiseSizeForest, noiseSizeForest + 1, noiseSizeForest + 1);



            mapRegion.ShrubMap.Size = noiseSizeShrubs + 1;
            mapRegion.ShrubMap.BottomRightPadding = 1;
            bushGen.SetInputMap(mapRegion.ClimateMap, mapRegion.ShrubMap);
            mapRegion.ShrubMap.Data = bushGen.GenLayer(regionX * noiseSizeShrubs, regionZ * noiseSizeShrubs, noiseSizeShrubs + 1, noiseSizeShrubs + 1);


            mapRegion.FlowerMap.Size = noiseSizeForest + 1;
            mapRegion.FlowerMap.BottomRightPadding = 1;
            flowerGen.SetInputMap(mapRegion.ClimateMap, mapRegion.FlowerMap);
            mapRegion.FlowerMap.Data = flowerGen.GenLayer(regionX * noiseSizeForest, regionZ * noiseSizeForest, noiseSizeForest + 1, noiseSizeForest + 1);



            pad = TerraGenConfig.landformMapPadding;
            mapRegion.LandformMap.Data           = landformsGen.GenLayer(regionX * noiseSizeLandform - pad, regionZ * noiseSizeLandform - pad, noiseSizeLandform + 2 * pad, noiseSizeLandform + 2 * pad);
            mapRegion.LandformMap.Size           = noiseSizeLandform + 2 * pad;
            mapRegion.LandformMap.TopLeftPadding = mapRegion.LandformMap.BottomRightPadding = pad;

            //Console.WriteLine("map region {0} {1} generated", regionX, regionZ);

            mapRegion.DirtyForSaving = true;
        }
Exemplo n.º 16
0
        public float getDepositYDistort(BlockPos pos, int lx, int lz, float step, IMapChunk heremapchunk)
        {
            int rdx = (pos.X / chunksize) % regionChunkSize;
            int rdz = (pos.Z / chunksize) % regionChunkSize;


            IMapRegion reg     = heremapchunk.MapRegion;
            float      yOffTop = reg.OreMapVerticalDistortTop.GetIntLerpedCorrectly(rdx * step + step * ((float)lx / chunksize), rdz * step + step * ((float)lz / chunksize)) - 20;
            float      yOffBot = reg.OreMapVerticalDistortBottom.GetIntLerpedCorrectly(rdx * step + step * ((float)lx / chunksize), rdz * step + step * ((float)lz / chunksize)) - 20;

            float yRel = (float)pos.Y / worldheight;

            return(yOffBot * (1 - yRel) + yOffTop * yRel);
        }
Exemplo n.º 17
0
        public bool satisfiesMinDistance(BlockPos pos, IWorldAccessor world)
        {
            if (MinGroupDistance < 1)
            {
                return(true);
            }

            int regSize = world.BlockAccessor.RegionSize;

            int mapRegionSizeX = world.BlockAccessor.MapSizeX / regSize;
            int mapRegionSizeZ = world.BlockAccessor.MapSizeZ / regSize;

            int x1 = pos.X - MinGroupDistance;
            int z1 = pos.Z - MinGroupDistance;
            int x2 = pos.X + MinGroupDistance;
            int z2 = pos.Z + MinGroupDistance;

            // Definition: Max structure size is 256x256x256
            //int maxStructureSize = 256;

            int minDistSq = MinGroupDistance * MinGroupDistance;

            int minrx = GameMath.Clamp(x1 / regSize, 0, mapRegionSizeX);
            int minrz = GameMath.Clamp(z1 / regSize, 0, mapRegionSizeZ);

            int maxrx = GameMath.Clamp(x2 / regSize, 0, mapRegionSizeX);
            int maxrz = GameMath.Clamp(z2 / regSize, 0, mapRegionSizeZ);

            for (int rx = minrx; rx <= maxrx; rx++)
            {
                for (int rz = minrz; rz <= maxrz; rz++)
                {
                    IMapRegion mapregion = world.BlockAccessor.GetMapRegion(rx, rz);
                    if (mapregion == null)
                    {
                        continue;
                    }

                    foreach (var val in mapregion.GeneratedStructures)
                    {
                        if (val.Group == this.Group && val.Location.Center.SquareDistanceTo(pos.X, pos.Y, pos.Z) < minDistSq)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
        private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            int noiseSize = sapi.WorldManager.RegionSize / TerraGenConfig.blockPatchesMapScale;

            foreach (var val in blockPatchMapGens)
            {
                var map = IntDataMap2D.CreateEmpty();

                map.Size = noiseSize + 1;
                map.BottomRightPadding = 1;

                map.Data = val.Value.GenLayer(regionX * noiseSize, regionZ * noiseSize, noiseSize + 1, noiseSize + 1);
                mapRegion.BlockPatchMaps[val.Key] = map;
            }
        }
        public WeatherSimulationRegion getOrCreateWeatherSimForRegion(long index2d, IMapRegion mapregion)
        {
            Vec3i regioncoord = MapRegionPosFromIndex2D(index2d);
            WeatherSimulationRegion weatherSim;

            lock (weatherSimByMapRegionLock)
            {
                if (weatherSimByMapRegion.TryGetValue(index2d, out weatherSim))
                {
                    return(weatherSim);
                }
            }

            weatherSim = new WeatherSimulationRegion(this, regioncoord.X, regioncoord.Z);
            weatherSim.Initialize();

            byte[] data;
            if (mapregion.ModData.TryGetValue("weather", out data))
            {
                try
                {
                    weatherSim.FromBytes(data);
                    //api.World.Logger.Notification("{2}: Loaded weather pattern @{0}/{1}", regioncoord.X, regioncoord.Z, api.Side);
                }
                catch (Exception)
                {
                    //api.World.Logger.Warning("Unable to load weather pattern from region {0}/{1}, will load a random one. Likely due to game version change.", regioncoord.X, regioncoord.Z);
                    weatherSim.LoadRandomPattern();
                    weatherSim.NewWePattern.OnBeginUse();
                }
            }
            else
            {
                //api.World.Logger.Notification("{2}: Random weather pattern @{0}/{1}", regioncoord.X, regioncoord.Z, api.Side);
                weatherSim.LoadRandomPattern();
                weatherSim.NewWePattern.OnBeginUse();
                mapregion.ModData["weather"] = weatherSim.ToBytes();
            }

            weatherSim.MapRegion = mapregion;

            lock (weatherSimByMapRegionLock)
            {
                weatherSimByMapRegion[index2d] = weatherSim;
            }

            return(weatherSim);
        }
Exemplo n.º 20
0
        // How to store/load ropes

        // Store it inside regions. Use start point as reference position
        // What about cloth points that cross a region border? Maybe just never simulate anything at a chunk edge?
        // What about cloth points attached to entities that get unloaded?

        // Ok, let's just do the stupid most method and improve from there.
        private void Event_MapRegionUnloaded(Vec2i mapCoord, IMapRegion region)
        {
            List <ClothSystem> systems = new List <ClothSystem>();

            int regionSize = sapi.WorldManager.RegionSize;

            foreach (var cs in clothSystems.Values)
            {
                BlockPos pos  = cs.FirstPoint.Pos.AsBlockPos;
                int      regx = pos.X / regionSize;
                int      regZ = pos.Z / regionSize;

                if (regx == mapCoord.X && regZ == mapCoord.Y)
                {
                    systems.Add(cs);
                }
            }

            if (systems.Count == 0)
            {
                return;
            }

            region.SetModdata("clothSystems", SerializerUtil.Serialize(systems));
            int[] clothIds = new int[systems.Count];


            for (int i = 0; i < systems.Count; i++)
            {
                clothSystems.Remove(systems[i].ClothId);
                clothIds[i] = systems[i].ClothId;
            }

            foreach (var system in clothSystems.Values)
            {
                system.updateActiveState(EnumActiveStateChange.RegionNowUnloaded);
            }

            if (!sapi.Server.IsShuttingDown)
            {
                sapi.Network.GetChannel("clothphysics").BroadcastPacket(new UnregisterClothSystemPacket()
                {
                    ClothIds = clothIds
                });
            }
        }
 private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
 {
     mapRegion.ClimateMap = new IntDataMap2D()
     {
         Data = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 },
         Size = 2
     };
     mapRegion.ForestMap = new IntDataMap2D()
     {
         Data = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 },
         Size = 2
     };
     mapRegion.ShrubMap = new IntDataMap2D()
     {
         Data = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 },
         Size = 2
     };
 }
        private BlockPos HasExitPoint(Dictionary <Vec2i, IServerChunk[]> columnsByChunkCoordinate, int centerCx, int centerCz)
        {
            IMapRegion mapregion = columnsByChunkCoordinate[new Vec2i(centerCx, centerCz)][0].MapChunk.MapRegion;

            List <GeneratedStructure> structures = mapregion.GeneratedStructures;

            foreach (var structure in structures)
            {
                if (structure.Code.Contains("gates"))
                {
                    BlockPos pos = FindTranslocator(structure.Location, columnsByChunkCoordinate, centerCx, centerCz);
                    if (pos != null)
                    {
                        return(pos);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 23
0
 private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
 {
     /*int noiseSize = api.WorldManager.RegionSize / TerraGenConfig.rockStrataScale;
      * int pad = 2;
      *
      * mapRegion.RockStrata = new IntMap[strata.Variants.Length];
      * for (int i = 0; i < strata.Variants.Length; i++)
      * {
      *  IntMap intmap = new IntMap();
      *  mapRegion.RockStrata[i] = intmap;
      *  intmap.Data = strataNoises[i].GenLayerMax0(
      *      regionX * noiseSize - pad,
      *      regionZ * noiseSize - pad,
      *      noiseSize + 2 * pad,
      *      noiseSize + 2 * pad
      *  );
      *
      *  intmap.Size = noiseSize + 2 * pad;
      *  intmap.TopLeftPadding = intmap.BottomRightPadding = pad;
      * }*/
 }
Exemplo n.º 24
0
        private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            int noiseSize = api.WorldManager.RegionSize / TerraGenConfig.rockStrataScale;
            int pad       = 2;

            mapRegion.RockStrata = new IntMap[strata.Variants.Length];
            for (int i = 0; i < strata.Variants.Length; i++)
            {
                IntMap intmap = new IntMap();
                mapRegion.RockStrata[i] = intmap;
                intmap.Data             = strataNoises[i].GenLayer(
                    regionX * noiseSize - pad,
                    regionZ * noiseSize - pad,
                    noiseSize + 2 * pad,
                    noiseSize + 2 * pad
                    );

                intmap.Size           = noiseSize + 2 * pad;
                intmap.TopLeftPadding = intmap.BottomRightPadding = pad;
            }
        }
Exemplo n.º 25
0
        private void OnChunkColumnGen(IServerChunk[] chunks, int chunkX, int chunkZ, ITreeAttribute chunkGenParams = null)
        {
            if (!TerraGenConfig.GenerateStructures)
            {
                return;
            }

            IMapRegion region = chunks[0].MapChunk.MapRegion;

            IntMap forestMap  = region.ForestMap;
            IntMap climateMap = region.ClimateMap;
            int    rlX        = chunkX % regionChunkSize;
            int    rlZ        = chunkZ % regionChunkSize;


            // A region has 16 chunks
            // Size of the forest map is RegionSize / TerraGenConfig.forestMapScale  => 32*16 / 32  = 16 pixel
            // rlX, rlZ goes from 0..16 pixel
            // facF = 16/16 = 1
            // Get 4 pixels for chunkx, chunkz, chunkx+1 and chunkz+1 inside the map
            float facF = (float)forestMap.InnerSize / regionChunkSize;

            forestUpLeft   = forestMap.GetUnpaddedInt((int)(rlX * facF), (int)(rlZ * facF));
            forestUpRight  = forestMap.GetUnpaddedInt((int)(rlX * facF + facF), (int)(rlZ * facF));
            forestBotLeft  = forestMap.GetUnpaddedInt((int)(rlX * facF), (int)(rlZ * facF + facF));
            forestBotRight = forestMap.GetUnpaddedInt((int)(rlX * facF + facF), (int)(rlZ * facF + facF));

            float facC = (float)climateMap.InnerSize / regionChunkSize;

            climateUpLeft   = climateMap.GetUnpaddedInt((int)(rlX * facC), (int)(rlZ * facC));
            climateUpRight  = climateMap.GetUnpaddedInt((int)(rlX * facC + facC), (int)(rlZ * facC));
            climateBotLeft  = climateMap.GetUnpaddedInt((int)(rlX * facC), (int)(rlZ * facC + facC));
            climateBotRight = climateMap.GetUnpaddedInt((int)(rlX * facC + facC), (int)(rlZ * facC + facC));

            heightmap = chunks[0].MapChunk.WorldGenTerrainHeightMap;


            DoGenStructures(region, chunkX, chunkZ, false, chunkGenParams);
            DoGenVillages(region, chunkX, chunkZ, false, chunkGenParams);
        }
Exemplo n.º 26
0
        public bool isStructureAt(BlockPos pos, IWorldAccessor world)
        {
            int rx = pos.X / world.BlockAccessor.RegionSize;
            int rz = pos.Z / world.BlockAccessor.RegionSize;

            IMapRegion mapregion = world.BlockAccessor.GetMapRegion(rx, rz);

            if (mapregion == null)
            {
                return(false);
            }

            foreach (var val in mapregion.GeneratedStructures)
            {
                if (val.Location.Contains(pos) || val.Location.Contains(pos.X, pos.Y - 3, pos.Z))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 27
0
        private void OnSaveGameSaving()
        {
            HashSet <long> toRemove = new HashSet <long>();

            foreach (var val in weatherSimByMapRegion)
            {
                IMapRegion mapregion = sapi.WorldManager.GetMapRegion(val.Key);
                if (mapregion != null)
                {
                    mapregion.SetModdata("weather", val.Value.ToBytes());
                }
                else
                {
                    toRemove.Add(val.Key);
                }
            }

            foreach (var key in toRemove)
            {
                weatherSimByMapRegion.Remove(key);
            }
        }
Exemplo n.º 28
0
        public void SendWeatherStateUpdate(WeatherState state)
        {
            int regionSize = sapi.WorldManager.RegionSize;

            foreach (var plr in sapi.World.AllOnlinePlayers)
            {
                int plrRegionX = (int)plr.Entity.ServerPos.X / regionSize;
                int plrRegionZ = (int)plr.Entity.ServerPos.Z / regionSize;

                if (Math.Abs(state.RegionX - plrRegionX) <= 1 && Math.Abs(state.RegionZ - plrRegionZ) <= 1)
                {
                    serverChannel.SendPacket(state, plr as IServerPlayer);
                }
            }

            // Instanty store the change, so that players that connect shortly after also get the update
            IMapRegion mapregion = sapi.WorldManager.GetMapRegion(state.RegionX, state.RegionZ);

            if (mapregion != null)
            {
                mapregion.SetModdata("weather", SerializerUtil.Serialize(state));
            }
        }
        /// <summary>
        /// Returns 0..255
        /// </summary>
        /// <param name="code"></param>
        /// <param name="posX"></param>
        /// <param name="posZ"></param>
        /// <param name="mapregion"></param>
        /// <returns></returns>
        public int GetPatchDensity(string code, int posX, int posZ, IMapRegion mapregion)
        {
            if (mapregion == null)
            {
                return(0);
            }
            int lx = posX % regionSize;
            int lz = posZ % regionSize;

            IntDataMap2D map;

            mapregion.BlockPatchMaps.TryGetValue(code, out map);
            if (map != null)
            {
                float posXInRegionOre = GameMath.Clamp((float)lx / regionSize * noiseSizeDensityMap, 0, noiseSizeDensityMap - 1);
                float posZInRegionOre = GameMath.Clamp((float)lz / regionSize * noiseSizeDensityMap, 0, noiseSizeDensityMap - 1);

                int density = map.GetUnpaddedColorLerped(posXInRegionOre, posZInRegionOre);

                return(density);
            }

            return(0);
        }
Exemplo n.º 30
0
        private void OnMapRegionGen(IMapRegion mapRegion, int regionX, int regionZ)
        {
            int pad = TerraGenConfig.geoProvMapPadding;

            mapRegion.GeologicProvinceMap.Data = geologicprovinceGen.GenLayer(
                regionX * noiseSizeGeoProv - pad,
                regionZ * noiseSizeGeoProv - pad,
                noiseSizeGeoProv + 2 * pad,
                noiseSizeGeoProv + 2 * pad
                );
            mapRegion.GeologicProvinceMap.Size           = noiseSizeGeoProv + 2 * pad;
            mapRegion.GeologicProvinceMap.TopLeftPadding = mapRegion.GeologicProvinceMap.BottomRightPadding = pad;

            pad = 2;
            // dominionsmod we get the climate data through the GenClimateLayer method of WorldMap, which reads the climate.png
            if (worldMap.climateMap != null)
            {
                mapRegion.ClimateMap.Data = worldMap.GenClimateLayer(
                    regionX,
                    regionZ,
                    noiseSizeClimate + 2 * pad,
                    noiseSizeClimate + 2 * pad
                    );
            }
            else
            {
                mapRegion.ClimateMap.Data = climateGen.GenLayer(
                    regionX * noiseSizeClimate - pad,
                    regionZ * noiseSizeClimate - pad,
                    noiseSizeClimate + 2 * pad,
                    noiseSizeClimate + 2 * pad
                    );
            }
            mapRegion.ClimateMap.Size           = noiseSizeClimate + 2 * pad;
            mapRegion.ClimateMap.TopLeftPadding = mapRegion.ClimateMap.BottomRightPadding = pad;


            mapRegion.ForestMap.Size = noiseSizeForest + 1;
            mapRegion.ForestMap.BottomRightPadding = 1;
            forestGen.SetInputMap(mapRegion.ClimateMap, mapRegion.ForestMap);
            mapRegion.ForestMap.Data = forestGen.GenLayer(regionX * noiseSizeForest, regionZ * noiseSizeForest, noiseSizeForest + 1, noiseSizeForest + 1);


            mapRegion.BeachMap.Size = noiseSizeBeach + 1;
            mapRegion.BeachMap.BottomRightPadding = 1;
            mapRegion.BeachMap.Data = beachGen.GenLayer(regionX * noiseSizeBeach, regionZ * noiseSizeBeach, noiseSizeBeach + 1, noiseSizeBeach + 1);

            mapRegion.ShrubMap.Size = noiseSizeShrubs + 1;
            mapRegion.ShrubMap.BottomRightPadding = 1;
            bushGen.SetInputMap(mapRegion.ClimateMap, mapRegion.ShrubMap);
            mapRegion.ShrubMap.Data = bushGen.GenLayer(regionX * noiseSizeShrubs, regionZ * noiseSizeShrubs, noiseSizeShrubs + 1, noiseSizeShrubs + 1);


            mapRegion.FlowerMap.Size = noiseSizeForest + 1;
            mapRegion.FlowerMap.BottomRightPadding = 1;
            flowerGen.SetInputMap(mapRegion.ClimateMap, mapRegion.FlowerMap);
            mapRegion.FlowerMap.Data = flowerGen.GenLayer(regionX * noiseSizeForest, regionZ * noiseSizeForest, noiseSizeForest + 1, noiseSizeForest + 1);



            pad = TerraGenConfig.landformMapPadding;
            // dominionsmod
            if (worldMap.landformMap != null)
            {
                mapRegion.LandformMap.Data = worldMap.GenLandformLayer(regionX, regionZ, noiseSizeLandform + 2 * pad, noiseSizeLandform + 2 * pad);
            }
            else
            {
                mapRegion.LandformMap.Data = landformsGen.GenLayer(regionX * noiseSizeLandform - pad, regionZ * noiseSizeLandform - pad, noiseSizeLandform + 2 * pad, noiseSizeLandform + 2 * pad);
            }
            mapRegion.LandformMap.Size           = noiseSizeLandform + 2 * pad;
            mapRegion.LandformMap.TopLeftPadding = mapRegion.LandformMap.BottomRightPadding = pad;


            mapRegion.DirtyForSaving = true;
        }