HomeWildfire Games

Calculate entity limit counts correctly when SpawnUnits fails in…

Description

Calculate entity limit counts correctly when SpawnUnits fails in ProductionQueue.

When adding a batch of unit, these in-training units get added to the production queue and to the entity limit count.
These in-training units need to be removed from the entity limit counts when spawning them, or we would be double-counting them. This was done when creating the cached entities, but this was too early: entities might fail to spawn, for example when there is no room around the foundation.

Change that so the entity limit count is now decremented right before giving spawned entities the correct owner (which triggers EntityLimits OnGlobalOwnershipChanged, which adds the spawned entities to the entity limit count).

Additionally, add Init to TrainingRestrictions so that the test setup doesn't complain. Other components have an empty Init instead of checking for Init in the test setup (and 61/67 have an Init function) so it seems more standard this way.

Reported By: elexis
Reviewed By: wraitii
Patch By: Angen
Tests By: wraitii

Differential Revision: https://code.wildfiregames.com/D1879

Event Timeline

Freagarach added inline comments.
/ps/trunk/binaries/data/mods/public/simulation/components/ProductionQueue.js
619

Notice that this function is also used by the cheats. Allowing unlimited entities to spawn using cheats seems good to me, but not having a proper count does not.