Skip to main content

GlobalPopulationDefinition

A class in Root.Township, Alta.Populations.

Server-only asset for a world-wide population: spawns its prefabs in random location chunks weighted by biome attributes, up to a cap. Also the global-population (globalpop) console module with list, spawned, set-size, teleport and teleport-to commands.

Constructors​

MemberWhat it is
GlobalPopulationDefinition()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

10 private and internal fields
MemberWhat it is
private AttributeImpact[] attributesBiome attribute impacts multiplied together to weight which location chunks elements spawn in.
private bool isSpawningOnAStarBacking field for IsSpawningOnAStar.
private int iterationsBacking field for Iterations. At least 1.
private float maxAngleFromUpDotBacking field for MaxAngleFromUpDot, set in the inspector as an angle from up.
private int maxSpawnedLargest number of elements alive at once. CheckSpawned tops up to this; set-size changes it.
private AnimationCurve perTickGrowthCurveCurve sampled with a random value on each CheckSpawned to decide how many elements to add.
private NetworkPrefab[] prefabsPrefabs to spawn; each element picks one at random.
private HashSet<SpawnedElement> spawnedThe live spawned elements. Null until Initialize runs.
private int startingPopulationNumber spawned at StartUp when the timer spawns on initialize.
private PopulationTimerDefinition timerTimer definition that drives respawn checks and how long elements last before decaying.

Properties​

MemberWhat it is
bool IsSpawningOnAStar { get; }If true, spawns snap to the nearest A* pathfinding node and face a random way instead of aligning to the ground.
int Iterations { get; }How many tries to find a valid spawn position in a chunk.
float MaxAngleFromUpDot { get; }Steepest ground (as a dot product with up) a spawn position may have.

Methods​

MemberWhat it is
void CheckSpawned()If below the cap, spawns a random amount taken from the per-tick growth curve.
void Clean()Tears down the population's timer.
void CleanElement(SpawnedElement element)Removes one spawned element from the population, freeing a slot.
void Initialize()Creates the set of spawned elements if it doesn't exist yet.
void StartUp()Spawns the starting population if the timer says to, then sets up the growth timer.
6 private and internal methods
MemberWhat it is
private static IEnumerable<LocationChunk> GetSpawned(GlobalPopulationDefinition population)Console command globalpop spawned: lists the location chunks of a population's spawned elements.
private static IEnumerable<GlobalPopulationDefinition.PopulationInfo> ListPopulations()Console command globalpop list: lists every global population with its hash, name, spawned count and max size.
private static void SetSize(GlobalPopulationDefinition population, int maxSpawned)Console command globalpop set-size: sets the population's max size and spawns up to it straight away.
private void SpawnQuantity(int toSpawn)Spawns the given number of elements, each in a random location chunk weighted by the biome attributes.
private static async Task TeleportToPopulationItem(Player player, GlobalPopulationDefinition population, float distanceAway = 3)Console command globalpop teleport: teleports the player near a spawned element, force loading its chunk if none are loaded.
private static async Task TeleportToSpecificPopulationItem(Player player, GlobalPopulationDefinition population, int index, float distanceAway = 3)Console command globalpop teleport-to: teleports the player near the spawned element at the given index.

Used in​

Members of other types that take, return or hold a GlobalPopulationDefinition: