public T GetRandomClosest(Vector3 pos, PRNG prng, float maxDistance, List <Zone> excluded, int numAttempts = 5) { lock (_lock) { if (_zones.Count == 0) { return(default(T)); } float bestDistance = maxDistance; T res = default(T); for (int i = 0; i < numAttempts; i++) { var zone = GetRandom(prng) as Zone; if (excluded != null && excluded.Contains(zone)) { continue; } float dist = Vector3.Distance(zone.GetCenter(), pos); if (dist < bestDistance) { res = (T)zone; bestDistance = dist; } } return(res); } }
// Returns a random position within the zone. public Vector3 GetRandomPos(PRNG prng) { return(new Vector3 { x = prng.Get(mins.x, maxs.x), y = prng.Get(mins.y, maxs.y), z = prng.Get(mins.z, maxs.z), }); }
public int GetZombieClass(World world, Chunk chunk, int x, int y, PRNG prng) { ChunkAreaBiomeSpawnData spawnData = chunk.GetChunkBiomeSpawnData(); if (spawnData == null) { #if DEBUG Log.Out("No biome spawn data present"); #endif return(-1); } var biomeData = world.Biomes.GetBiome(spawnData.biomeId); if (biomeData == null) { #if DEBUG Log.Out("No biome data for biome id {0}", spawnData.biomeId); #endif return(-1); } BiomeSpawnEntityGroupList biomeSpawnEntityGroupList = list[biomeData.m_sBiomeName]; if (biomeSpawnEntityGroupList == null) { #if DEBUG Log.Out("No biome spawn group specified for {0}", biomeData.m_sBiomeName); #endif return(-1); } var numGroups = biomeSpawnEntityGroupList.list.Count; if (numGroups == 0) { #if DEBUG Log.Out("No biome spawn group is empty for {0}", biomeData.m_sBiomeName); #endif return(-1); } var dayTime = world.IsDaytime() ? EDaytime.Day : EDaytime.Night; for (int i = 0; i < 5; i++) { int pickIndex = prng.Get(0, numGroups); var pick = biomeSpawnEntityGroupList.list[pickIndex]; if (pick.daytime == EDaytime.Any || pick.daytime == dayTime) { int lastClassId = -1; return(EntityGroups.GetRandomFromGroup(pick.entityGroupRefName, ref lastClassId)); } } return(-1); }
public static TargetZone CreateRandom(PRNG prng, Vector3i worldMins, Vector3i worldMaxs) { float x = prng.Get(worldMins.x + BorderSize, worldMaxs.x - BorderSize); float z = prng.Get(worldMins.z + BorderSize, worldMaxs.z - BorderSize); return(new TargetZone { mins = new Vector3(x - ZoneSize, worldMins.y, z - ZoneSize), maxs = new Vector3(x + ZoneSize, worldMaxs.y, z + ZoneSize), center = new Vector3(x, worldMins.y, z), }); }
public T GetRandom(PRNG prng, int lastIndex = -1) { lock (_lock) { if (_zones.Count == 0) { return(default(T)); } for (int i = 0; i < 4; i++) { var idx = prng.Get(0, _zones.Count); var zone = _zones[idx] as Zone; if (zone.GetIndex() != lastIndex) { return((T)zone); } } return(default(T)); } }