public int GenerateTerrainForBlockColumn(int x, int z) { int height = VoxelManager.Instance.CurrentWorld.TerrainMinHeight; float moisture = this.noise.GetCellular(x / 500f, 0, z / 500f); BiomeDefinition biome = VoxelManager.Instance.FindBiomeWithMoisture(moisture); if (biome == null) { biome = VoxelManager.Instance.DefaultBiome; } List <LayerDefinition> layers = biome.Layers; for (int i = 0; i < layers.Count; i++) { if (layers[i] == null) { Debug.LogError("Layer name '" + layers[i] + "' in layer order didn't match a valid layer"); continue; } layers[i].Noise = this.noise; if (layers[i].LayerType != LayerType.Structure) { height = layers[i].Generate(x, z, height); } } return(height); }
public Zone(int xi, int zi) { /** Zone generated with reproducible randomness from: seed, size and (x,z)-position * - x,z are NW corner of the zone * - biome arg should be null (force it in debug mode) **/ this.seed = String.Format("Zone{0}_{1}_{2}_{3}", Zombiome.worldSeed, Zombiome.worldSize, xi, zi); // receives center /* Geometry */ this.x = Hashes.Rand(xi * ZoneSize, (xi + 1) * ZoneSize, seed, "xcenter"); this.z = Hashes.Rand(zi * ZoneSize, (zi + 1) * ZoneSize, seed, "zcenter"); this.radius = CSutils.Hashes.Rand(20, ZoneSize / 2, seed, "radius"); /* Biome (TODO:robustify: get at a few other points) */ biomeFromPlayer = false; if (true) // (biome == null) { { this.biomeDef = GetBiomeProvider(this.x, this.z); if (this.biomeDef == null) { Printer.Write("Error NULL BiomeDefinition at", this.x, this.z, " ", xi, zi); Printer.Print("Error NULL BiomeDefinition at", this.x, this.z, " ", xi, zi); Printer.Print("player at ", GameManager.Instance.World.GetLocalPlayers()[0].GetPosition()); } else { Printer.Print("GetBiomeProvider", this.x, this.z, this.biomeDef, this.biomeDef == null); } } this.biome = ZBiomeInfo.Get(this.biomeDef.ToString()); effect = ZombiomeActivitySelector.Random(this); Printer.Log(64, "Zone instantiated:", this.x, this.z, biome, "seed:", seed, "effect:", effect, " dif/int:", difficulty, intensity); this.Log(); }
public static void ShowBiome(BiomeDefinition bd) { Printer.Print("========="); Printer.Print("Biome", bd, bd.m_Id, bd.m_sBiomeName, bd.m_SpectrumName, bd.TotalLayerDepth, bd.m_TopSoilBlock); // snow 1 snow snow 6 terrSnow //foreach(KeyValuePair<string,Byte> entry in BiomeDefinition.nameToId) Printer.Print("nameToId:", entry.Key, entry.Value); // snow:1 foreach (BiomeLayer layer in bd.m_Layers) { Printer.Print("nameToId:", layer); } foreach (BiomeBlockDecoration bbd in bd.m_DecoBlocks) { //Printer.Print("m_DecoBlocks:", bbd); Printer.Print("m_DecoBlocks:", bbd.m_sBlockName, bbd.m_BlockValue, bbd.m_Prob); } foreach (BiomeBlockDecoration bbd in bd.m_DistantDecoBlocks) { Printer.Print("m_DistantDecoBlocks:", bbd.m_sBlockName, bbd.m_BlockValue, bbd.m_Prob); } foreach (BiomeDefinition layer in bd.subbiomes) { Printer.Print("subbiomes:", layer); } // 6 * BiomeBlockDecoration, 6 * snow, 6 µ BiomeLayer BiomeDefinition sub = bd.subbiomes[0]; Printer.Print("subbiome", sub, sub.m_Id, sub.m_sBiomeName, sub.m_SpectrumName, sub.TotalLayerDepth, sub.m_TopSoilBlock); foreach (BiomeDefinition layer in sub.subbiomes) { Printer.Print("sub subbiomes: ?", layer); } }
public override void Execute(List <string> _params, CommandSenderInfo _senderInfo) { /* * Subbiomes seem always equal to main main biome * Subbiomes have no subbiomes */ List <EntityPlayerLocal> players = GameManager.Instance.World.GetLocalPlayers(); EntityPlayerLocal player = players[0]; foreach (string b in new string[] { "snow", "pine_forest", "desert", "water", "radiated", "wasteland" }) { BiomeDefinition bd = WorldBiomes.Instance.GetBiome(b); // or World.Biomes.GetBiome(b) ! ShowBiome(bd); } if (false) { // BiomeDefinition biome = this.world.GetBiome(this.blockPosStandingOn.x, this.blockPosStandingOn.z); BiomeDefinition bd = player.biomeStandingOn; ShowBiome(bd); ShowOthers(); } }
private void GetLayers(BiomeDefinition biome) { foreach (var layer in biome.m_Layers) { Layers.Add(new BCMBiomeLayer(layer)); } Bin.Add("Layers", Layers); }
private void GetDecoBlocks(BiomeDefinition biome) { foreach (var deco in biome.m_DecoBlocks) { DecoBlocks.Add(new BCMBiomeBlockDecoration(deco)); } Bin.Add("DecoBlocks", DecoBlocks); }
private void GetDecoPrefabs(BiomeDefinition biome) { foreach (var deco in biome.m_DecoPrefabs) { DecoPrefabs.Add(new BCMBiomePrefabDecoration(deco)); } Bin.Add("DecoPrefabs", DecoPrefabs); }
private void GetSubBiomes(BiomeDefinition biome) { foreach (var sub in biome.subbiomes) { SubBiomes.Add(new BCMSubBiome(sub)); } Bin.Add("SubBiomes", SubBiomes); }
public MovingDeco(Zone zone) : base(zone) { EffectType = EffectType.Ground; BiomeDefinition biomeDef = Zone.GetBiomeProvider(centerx, centerz); Printer.Print("MovingDeco init"); DecoSearch.Selector = block => DecoSearch.IsDeco(block, DecoSearch.Count > 5); // take small deco while size < 5 }
// public static Func<Vector3,Zone[]> Get = GetFour; public static BiomeDefinition GetBiomeProvider(int x, int z) { /* World.GetBiome(x,z) returns null when chunk isn't loaded. * I could default to player pos (maybe until biome is known), but breaks reproducibility * So let's use GetBiomeProvider instead. I don't think biomes change dynamically ? */ BiomeDefinition bd = GameManager.Instance.World.ChunkCache.ChunkProvider.GetBiomeProvider().GetBiomeAt(x, z); return(bd); // Seems to be null only if outside world boundaries }
public BCMSubBiome([NotNull] BiomeDefinition sub) { Id = sub.m_Id; Name = sub.m_sBiomeName; Freq = Math.Round(sub.freq, 6); Depth = sub.TotalLayerDepth; Prob = Math.Round(sub.prob, 6); foreach (var layer in sub.m_Layers) { Layers.Add(new BCMBiomeLayer(layer)); } foreach (var deco in sub.m_DecoBlocks) { DecoBlocks.Add(new BCMBiomeBlockDecoration(deco)); } foreach (var deco in sub.m_DecoPrefabs) { DecoPrefabs.Add(new BCMBiomePrefabDecoration(deco)); } }
private void GetReplacements(BiomeDefinition biome) { foreach (var r in biome.Replacements) { if (ItemClass.list[r.Key] == null) { continue; } if (ItemClass.list[r.Key].Name == null) { continue; } if (ItemClass.list[r.Value] == null) { continue; } Replacements.Add(ItemClass.list[r.Key].Name, ItemClass.list[r.Value].Name); } Bin.Add("Replacements", Replacements); }
public FloatingDeco(Zone zone) : base(zone) { EffectType = EffectType.Ground; BiomeDefinition biomeDef = Zone.GetBiomeProvider(centerx, centerz); List <string> _blockDeco = new List <string>(); foreach (BiomeBlockDecoration bbd in biomeDef.m_DistantDecoBlocks) { // Printer.Print("m_DistantDecoBlocks:", bbd.m_sBlockName, bbd.m_BlockValue, bbd.m_Prob); string dname = bbd.m_sBlockName; // m_BlockValue if (dname.StartsWith("tree") || dname.StartsWith("rock")) { decorationsSet.Add(dname); // _blockDeco.Append(dname); } } if (decorationsSet.Contains("water")) { decorationsSet.Remove("water"); } Printer.Log(60, "FloatingDeco Effect1, ndeco=", decorationsSet.Count); }
private static void testGetBiome(List <string> _params) { /* Using World.ChunkCache.ChunkProvider.GetBiomeProvider().GetBiomeAt * Instead of World.getbiome */ int x = int.Parse(_params[0]); int y = int.Parse(_params[1]); Printer.Print("testGetBiome at", x, y); World w = GameManager.Instance.World; ChunkCluster cc = w.ChunkCache; Printer.Print("testGetBiome ChunkCluster", cc); IChunkProvider icp = w.ChunkCache.ChunkProvider; Printer.Print("testGetBiome IChunkProvider", icp); IBiomeProvider bp = w.ChunkCache.ChunkProvider.GetBiomeProvider(); Printer.Print("testGetBiome IBiomeProvider", bp); BiomeDefinition bd = w.ChunkCache.ChunkProvider.GetBiomeProvider().GetBiomeAt(x, y); Printer.Print("testGetBiome BiomeDefinition", bd); }
public BCMSubBiome(BiomeDefinition sub) { Id = sub.m_Id; Name = sub.m_sBiomeName; //Color = sub.m_uiColor; //Rad = sub.m_RadiationLevel; //Spec = sub.m_SpectrumName; Freq = Math.Round(sub.freq, 6); Depth = sub.TotalLayerDepth; Prob = Math.Round(sub.prob, 6); foreach (var layer in sub.m_Layers) { Layers.Add(new BCMBiomeLayer(layer)); } foreach (var deco in sub.m_DecoBlocks) { DecoBlocks.Add(new BCMBiomeBlockDecoration(deco)); } foreach (var deco in sub.m_DecoPrefabs) { DecoPrefabs.Add(new BCMBiomePrefabDecoration(deco)); } }
private void GetDepth(BiomeDefinition biome) => Bin.Add("Depth", Depth = biome.TotalLayerDepth);
private void GetBiomes(BiomeDefinition obj) => Bin = new BCMBiome(obj, TypeStr, Options, StrFilter).Data();
bool PaintChunkA(VoxelChunk chunk) { if (chunk.position.y + 8 < minHeight) { chunk.isAboveSurface = false; return(false); } int chunkBottomPos = FastMath.FloorToInt(chunk.position.y - 8); int chunkTopPos = FastMath.FloorToInt(chunk.position.y + 8); bool isAboveSurface = false; bool atleastOneVoxel = false; Voxel[] voxels = chunk.voxels; VoxelDefinition voxDef = topVoxel; Vector3 pos; Vector3 position = chunk.position - new Vector3(8, 8, 8); int z, x, y; for (z = 0; z < 16; z++) { pos.z = position.z + z; for (x = 0; x < 16; x++) { pos.x = position.x + x; var heightMapInfo = env.GetHeightMapInfoFast(pos.x, pos.z); int surfaceLevel = heightMapInfo.groundLevel; int groundLevel = heightMapInfo.groundLevel; int waterLevel = env.waterLevel > 0 ? env.waterLevel : -1; BiomeDefinition biome = heightMapInfo.biome; if (biome == null) { continue; } if (chunkTopPos > surfaceLevel) { isAboveSurface = true; } int localY = (int)(surfaceLevel - chunkBottomPos); if (localY > 15) { localY = 15; } int index = z * ONE_Z_ROW + x; for (y = 0; y <= localY; y++) { pos.y = position.y + y; if ((int)pos.y == groundLevel) { voxDef = biome.voxelTop; } else { voxDef = biome.voxelDirt; } voxels[index].SetFast(voxDef, 15, 1, Misc.color32White); atleastOneVoxel = true; //Check if we should add trees or vegetation if ((int)pos.y == groundLevel) { if (pos.y > waterLevel) { float rn = WorldRand.GetValue(pos); if (env.enableTrees && biome.treeDensity > 0 && rn < biome.treeDensity && biome.trees.Length > 0) { // request a tree env.RequestTreeCreation( chunk, pos, env.GetTree(biome.trees, rn / biome.treeDensity)); } else if (env.enableVegetation && biome.vegetationDensity > 0 && rn < biome.vegetationDensity && biome.vegetation.Length > 0) { if (index >= 15 * ONE_Y_ROW) { // we're at the top layer for this chunk // place a request for vegetation for the chunk above us env.RequestVegetationCreation(chunk.top, index - ONE_Y_ROW * 15, env.GetVegetation(biome, rn / biome.vegetationDensity)); } else { // set a vegetation voxel voxels[index + ONE_Y_ROW].Set(env.GetVegetation(biome, rn / biome.vegetationDensity), Misc.color32White); } } } } index += ONE_Y_ROW; } } } chunk.isAboveSurface = isAboveSurface; return(atleastOneVoxel); }
private void GetId(BiomeDefinition biome) => Bin.Add("Id", Id = biome.m_Id);
private void GetName(BiomeDefinition biome) => Bin.Add("Name", Name = biome.m_sBiomeName);
private void GetColor(BiomeDefinition biome) => Bin.Add("Color", Color = BCUtils.UIntToHex(biome.m_uiColor));
public static void Physics(string seed, BiomeDefinition biome, BlockSetter.Options OptionBlock) { OptionBlock.avoidEntity = Hashes.Rand(0.5f, seed, "avoidEntity") ? true : false; OptionBlock.avoidBlock = Hashes.Rand(0.5f, seed, "avoidBlock") ? true : false; OptionBlock.elastic = Hashes.Rand(0.5f, seed, "elastic") ? 10 : 0; }
private void GetSpec(BiomeDefinition biome) => Bin.Add("Spec", Spec = biome.m_SpectrumName);
private void GetRad(BiomeDefinition biome) => Bin.Add("Rad", Rad = biome.m_RadiationLevel);
// This method is a modified version of vanilla, doing the same checks and balances. However, we do use the player position a bit more, and we change which biome spawning group we // will use, when below the terrain. public static void SpawnUpdate(string _spawnerName, bool _bSpawnEnemyEntities, ChunkAreaBiomeSpawnData _chunkBiomeSpawnData, ref List <Entity> spawnNearList, ref int lastClassId) { if (_chunkBiomeSpawnData == null) { return; } if (_bSpawnEnemyEntities) { if (GameStats.GetInt(EnumGameStats.EnemyCount) >= GamePrefs.GetInt(EnumGamePrefs.MaxSpawnedZombies)) { _bSpawnEnemyEntities = false; } else if (GameManager.Instance.World.aiDirector.BloodMoonComponent.BloodMoonActive) { _bSpawnEnemyEntities = false; } } if (!_bSpawnEnemyEntities && GameStats.GetInt(EnumGameStats.AnimalCount) >= GamePrefs.GetInt(EnumGamePrefs.MaxSpawnedAnimals)) { return; } bool flag = false; List <EntityPlayer> players = GameManager.Instance.World.GetPlayers(); // Player Position. Vector3 position = Vector3.zero; Rect rect = new Rect(1, 1, 1, 1); for (int i = 0; i < players.Count; i++) { if (players[i].Spawned) { position = players[i].GetPosition(); rect = new Rect(position.x - 40f, position.z - 40f, 80f, 20f); if (rect.Overlaps(_chunkBiomeSpawnData.area)) { flag = true; break; } } } // No valid player position. if (position == Vector3.zero) { return; } // Don't allow above ground spawning. Vector3i playerPosition = new Vector3i(position); float offSet = GameManager.Instance.World.GetTerrainHeight(playerPosition.x, playerPosition.z); if (offSet <= playerPosition.y) { return; } int minDistance = _bSpawnEnemyEntities ? 28 : 48; int maxDistance = _bSpawnEnemyEntities ? 54 : 70; Vector3 vector; if (!flag || !FindRandomSpawnPointNearPositionUnderground(rect, minDistance, maxDistance, false, out vector, playerPosition)) { return; } // Mob is above terrain; ignore. if (vector.y > offSet) { return; } BiomeDefinition biome = GameManager.Instance.World.Biomes.GetBiome(_chunkBiomeSpawnData.biomeId); if (biome == null) { return; } // Customize which spawning.xml entry to we want to use for spawns. String CaveType = "Cave"; // Search for the biome_Cave spawn group. If not found, load the generic Cave one. BiomeSpawnEntityGroupList biomeSpawnEntityGroupList = BiomeSpawningClass.list[biome.m_sBiomeName + "_Cave"]; if (biomeSpawnEntityGroupList == null) { biomeSpawnEntityGroupList = BiomeSpawningClass.list["Cave"]; } // if we are below 30, look for the biome specific deep cave, then deep cave if its not set. if (vector.y < 30) { CaveType = "DeepCave"; biomeSpawnEntityGroupList = BiomeSpawningClass.list[biome.m_sBiomeName + "_DeepCave"]; if (biomeSpawnEntityGroupList == null) { biomeSpawnEntityGroupList = BiomeSpawningClass.list["DeepCave"]; } } if (biomeSpawnEntityGroupList == null) { return; } EDaytime edaytime = GameManager.Instance.World.IsDaytime() ? EDaytime.Day : EDaytime.Night; GameRandom gameRandom = GameManager.Instance.World.GetGameRandom(); string entityGroupName = null; int num = -1; int num2 = gameRandom.RandomRange(biomeSpawnEntityGroupList.list.Count); int j = 0; while (j < 5) { BiomeSpawnEntityGroupData biomeSpawnEntityGroupData = biomeSpawnEntityGroupList.list[num2]; if (biomeSpawnEntityGroupData.daytime == EDaytime.Any || biomeSpawnEntityGroupData.daytime == edaytime) { bool flag2 = EntityGroups.IsEnemyGroup(biomeSpawnEntityGroupData.entityGroupRefName); if (!flag2 || _bSpawnEnemyEntities) { int num3 = biomeSpawnEntityGroupData.maxCount; if (flag2) { num3 = EntitySpawner.ModifySpawnCountByGameDifficulty(num3); } entityGroupName = biomeSpawnEntityGroupData.entityGroupRefName + "_" + biomeSpawnEntityGroupData.daytime.ToStringCached <EDaytime>() + "_" + CaveType; ulong respawnLockedUntilWorldTime = _chunkBiomeSpawnData.GetRespawnLockedUntilWorldTime(entityGroupName); if (respawnLockedUntilWorldTime <= 0UL || GameManager.Instance.World.worldTime >= respawnLockedUntilWorldTime) { if (respawnLockedUntilWorldTime > 0UL) { _chunkBiomeSpawnData.ClearRespawnLocked(entityGroupName); } if (_chunkBiomeSpawnData.GetEntitiesSpawned(entityGroupName) < num3) { num = num2; break; } } } } j++; num2 = (num2 + 1) % biomeSpawnEntityGroupList.list.Count; } if (num < 0) { //Debug.Log("max spawn reached: " + entityGroupName); return; } Bounds bb = new Bounds(vector, new Vector3(4f, 2.5f, 4f)); GameManager.Instance.World.GetEntitiesInBounds(typeof(Entity), bb, spawnNearList); int count = spawnNearList.Count; spawnNearList.Clear(); if (count > 0) { //Debug.Log("Spawn Count is maxed for "); return; } BiomeSpawnEntityGroupData biomeSpawnEntityGroupData2 = biomeSpawnEntityGroupList.list[num]; int randomFromGroup = EntityGroups.GetRandomFromGroup(biomeSpawnEntityGroupData2.entityGroupRefName, ref lastClassId, null); float spawnDeadChance = biomeSpawnEntityGroupData2.spawnDeadChance; _chunkBiomeSpawnData.IncEntitiesSpawned(entityGroupName); Entity entity = EntityFactory.CreateEntity(randomFromGroup, vector); entity.SetSpawnerSource(EnumSpawnerSource.Dynamic, _chunkBiomeSpawnData.chunk.Key, entityGroupName); EntityAlive myEntity = entity as EntityAlive; if (myEntity) { myEntity.SetSleeper(); } // Debug.Log("Spawning: " + myEntity.entityId + " " + vector ); GameManager.Instance.World.SpawnEntityInWorld(entity); if (spawnDeadChance > 0f && gameRandom.RandomFloat < spawnDeadChance) { entity.Kill(DamageResponse.New(true)); } GameManager.Instance.World.DebugAddSpawnedEntity(entity); }