public bool IsPatchSuitableUnderTree(BlockPatch patch, int mapSizeY, ClimateCondition climate, int y) { float rainRel = climate.Rainfall; if (rainRel < patch.MinRain || rainRel > patch.MaxRain) { // again faster path without needing to fetch temperature etc return(false); } float temp = climate.Temperature; if (temp < patch.MinTemp || temp > patch.MaxTemp) { // again faster path without needing to fetch sealevel and fertility return(false); } float sealevelDistRel = ((float)y - TerraGenConfig.seaLevel) / ((float)mapSizeY - TerraGenConfig.seaLevel); if (sealevelDistRel < patch.MinY || sealevelDistRel > patch.MaxY) { return(false); } // finally test fertility (the least common blockpatch criterion) float fertilityRel = climate.Fertility; return(fertilityRel >= patch.MinFertility && fertilityRel <= patch.MaxFertility); }
internal bool IsPatchSuitableAt(BlockPatch patch, Block onBlock, IWorldManagerAPI world, int climate, int y, float forestRel) { if ((patch.Placement == EnumBlockPatchPlacement.NearWater || patch.Placement == EnumBlockPatchPlacement.UnderWater) && onBlock.LiquidCode != "water") { return(false); } if ((patch.Placement == EnumBlockPatchPlacement.NearSeaWater || patch.Placement == EnumBlockPatchPlacement.UnderSeaWater) && onBlock.LiquidCode != "seawater") { return(false); } rain = TerraGenConfig.GetRainFall((climate >> 8) & 0xff, y); rainRel = rain / 255f; temp = TerraGenConfig.GetScaledAdjustedTemperature((climate >> 16) & 0xff, y - TerraGenConfig.seaLevel); sealevelDistRel = ((float)y - TerraGenConfig.seaLevel) / ((float)world.MapSizeY - TerraGenConfig.seaLevel); fertilityRel = TerraGenConfig.GetFertility(rain, temp, sealevelDistRel) / 255f; return (fertilityRel >= patch.MinFertility && fertilityRel <= patch.MaxFertility && rainRel >= patch.MinRain && rainRel <= patch.MaxRain && temp >= patch.MinTemp && temp <= patch.MaxTemp && sealevelDistRel >= patch.MinY && sealevelDistRel <= patch.MaxY && forestRel >= patch.MinForest && forestRel <= patch.MaxForest ); }
internal void ResolveBlockIds(ICoreServerAPI api, RockStrataConfig rockstrata) { for (int i = 0; i < Patches.Length; i++) { BlockPatch patch = Patches[i]; List <Block> blocks = new List <Block>(); for (int j = 0; j < patch.blockCodes.Length; j++) { AssetLocation code = patch.blockCodes[j]; if (code.Path.Contains("{rocktype}")) { if (patch.BlocksByRockType == null) { patch.BlocksByRockType = new Dictionary <int, Block[]>(); } for (int k = 0; k < rockstrata.Variants.Length; k++) { string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1]; AssetLocation rocktypedCode = code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype)); Block rockBlock = api.World.GetBlock(rockstrata.Variants[k].BlockCode); if (rockBlock != null) { patch.BlocksByRockType[rockBlock.BlockId] = new Block[] { api.World.GetBlock(rocktypedCode) }; } } } else { Block block = api.World.GetBlock(code); if (block != null) { blocks.Add(block); } else { api.World.Logger.Warning("Block patch Nr. {0}: Unable to resolve block with code {1}. Will ignore.", i, code); } } } patch.Blocks = blocks.ToArray(); if (patch.BlockCodeIndex == null) { patch.BlockCodeIndex = NatFloat.createUniform(0, patch.Blocks.Length); } } }
public bool IsPatchSuitableAt(BlockPatch patch, Block onBlock, int mapSizeY, int climate, int y, float forestRel, float shrubRel) { if ((patch.Placement == EnumBlockPatchPlacement.NearWater || patch.Placement == EnumBlockPatchPlacement.UnderWater) && onBlock.LiquidCode != "water") { return(false); } if ((patch.Placement == EnumBlockPatchPlacement.NearSeaWater || patch.Placement == EnumBlockPatchPlacement.UnderSeaWater) && onBlock.LiquidCode != "seawater") { return(false); } if (forestRel < patch.MinForest || forestRel > patch.MaxForest || shrubRel < patch.MinShrub || forestRel > patch.MaxShrub) { // faster path without needing to fetch rainfall and temperature etc return(false); } int rain = TerraGenConfig.GetRainFall((climate >> 8) & 0xff, y); float rainRel = rain / 255f; if (rainRel < patch.MinRain || rainRel > patch.MaxRain) { // again faster path without needing to fetch temperature etc return(false); } int temp = TerraGenConfig.GetScaledAdjustedTemperature((climate >> 16) & 0xff, y - TerraGenConfig.seaLevel); if (temp < patch.MinTemp || temp > patch.MaxTemp) { // again faster path without needing to fetch sealevel and fertility return(false); } float sealevelDistRel = ((float)y - TerraGenConfig.seaLevel) / ((float)mapSizeY - TerraGenConfig.seaLevel); if (sealevelDistRel < patch.MinY || sealevelDistRel > patch.MaxY) { return(false); } // finally test fertility (the least common blockpatch criterion) float fertilityRel = TerraGenConfig.GetFertility(rain, temp, sealevelDistRel) / 255f; return(fertilityRel >= patch.MinFertility && fertilityRel <= patch.MaxFertility); }
internal void ResolveBlockIds(ICoreServerAPI api, RockStrataConfig rockstrata, LCGRandom rnd) { List <BlockPatch> patchesNonTree = new List <BlockPatch>(); for (int i = 0; i < Patches.Length; i++) { BlockPatch patch = Patches[i]; bool handledbyTreegen = patch.Placement == EnumBlockPatchPlacement.OnTrees || patch.Placement == EnumBlockPatchPlacement.UnderTrees; if (!handledbyTreegen) { patchesNonTree.Add(patch); } patch.Init(api, rockstrata, rnd, i); } PatchesNonTree = patchesNonTree.ToArray(); }
internal void ResolveBlockIds(ICoreServerAPI api, RockstrataWorldProperty rockstrata) { for (int i = 0; i < Patches.Length; i++) { BlockPatch patch = Patches[i]; List <Block> blocks = new List <Block>(); for (int j = 0; j < patch.blockCodes.Length; j++) { AssetLocation code = patch.blockCodes[j]; if (code.Path.Contains("{rocktype}")) { if (patch.BlocksByRockType == null) { patch.BlocksByRockType = new Dictionary <ushort, Block[]>(); } for (int k = 0; k < rockstrata.Variants.Length; k++) { string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1]; patch.BlocksByRockType.Add( api.WorldManager.GetBlockId(rockstrata.Variants[k].BlockCode), new Block[] { api.World.GetBlock(code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype))) } ); } } else { blocks.Add(api.WorldManager.GetBlockType(api.WorldManager.GetBlockId(code))); } } patch.Blocks = blocks.ToArray(); if (patch.BlockCodeIndex == null) { patch.BlockCodeIndex = NatFloat.createUniform(0, patch.Blocks.Length); } } }