We currently use a hack in two of our technologies to automagically upgrade our units, by setting the experience needed for the next level to 0.
The two affected technologies are:
- https://github.com/0ad/0ad/blob/master/binaries/data/mods/public/simulation/data/technologies/upgrade_rank_advanced_mercenary.json
- https://github.com/0ad/0ad/blob/master/binaries/data/mods/public/simulation/data/technologies/silvershields.json
Before Phab:rP26134 spawning units using TriggerHelper.SpawnUnits worked because auto-researched technologies were not considered when spawning entities. It would thus send you the correct ids but spawn the technically correct units instead of the promoted ones. They would only get promoted if something else triggered that mechanism. E.g making them gain experience.
Now, the unpromoted units spawn, their owner is changed so technologies get applied, and the cmpPosition component points to the old entity, failing to move it out of 0:0. A solution would be to move the ownership change after the position change, but anything after that will be wrong anyway, including the entities returned by the SpawnUnitsfunction. So for instance, you would not be able to set the formation since you wouldn't have the correct ids.
The correct solution seems to be the one proposed in this patch, which computes the correct template to spawn, before actually spawning it. Map makers are also notified that the template they asked to be spawned might not be the one the expect, to make upgrading scripts easier, and bugs easier to spot.