Skip to main content

BasicPopulation

A class in Root.Township, Alta.Populations.

The older, simpler population type: keeps a folder of spawned items up to a cap set by area and density, and spawns more on a tick timer. Server side.

Constructors​

MemberWhat it is
BasicPopulation(IPopulationFolder folder)Creates a BasicPopulation from folder.

Fields​

2 private and internal fields
MemberWhat it is
private HashSet<BasicPopulationItem> itemsThe population items currently registered, added by Register and AdoptExisting and removed when an item is removed.
private static Logger loggerNLog logger for this class.

Properties​

MemberWhat it is
PopulationSetup Definition { get; private set; }The PopulationSetup with the spawn rate settings.
IPopulationFolder Folder { get; private set; }The folder entity the spawned items live under.
int PopulationCap { get; }Most items: population per square metre times the folder's area and density multiplier.
TickTimer Timer { get; private set; }Tick timer at the respawn interval that triggers CheckSpawn.
int TotalPopulation { get; set; }How many items the population counts as existing, visible or not.
int VisiblePopulation { get; }How many entities are actually in the folder now.

Events​

MemberWhat it is
event BasicPopulation.PopulationEventHandler PopulationDecreasedRaised when an item leaves the population.
event BasicPopulation.PopulationEventHandler PopulationIncreasedRaised when an item joins the population.

Methods​

MemberWhat it is
void AdoptExisting()Registers every entity already in the folder as a member, for example after loading.
void CheckSpawn(TimeSpan elapsed)Grows the total by the spawn rate for the elapsed time, then spawns members toward it, limited by the emerge rate.
void Deregister(BasicPopulationItem item)Removes an item and raises PopulationDecreased. Called when an item is removed.
void LoadTime(TimeSpan time, int totalPopulation)Restores the saved total and timer, then catches up spawning for the time since the save.
void Register(BasicPopulationItem item)Adds an item, listens for its removal and raises PopulationIncreased.
void Replace(BasicPopulationItem basicPopulationItem, NetworkEntity replacement)Swaps a member for a new entity, keeping it counted. Used when a population item is replaced, such as a grown plant.
1 private and internal method
MemberWhat it is
private void CheckSpawn()Grows the total by the spawn rate for the elapsed time, then spawns members toward it, limited by the emerge rate.

Used in​

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