Fix Hep ancestors sometimes spawning incorrectly #4245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the player gained enough piety to gain an ancestor on an enemy's turn or at the start of their turn (e.g. from an enemy digging or the player's passwal finishing), they will get a turn to act before their ancestor is summoned as the ancestor will be summoned at the end of the player's turn. Delaying the summoning of the ancestor to the end of the player's turn is done by storing a copy of the ancestor in a queue. This lead to a bug reported by krajj7 (aka chujev) where changing your ancestor's name on this turn would result in them spawning with the old name. Fix this by using the actual data for the ancestor instead of the data in the queue.
Queueing up spawning an ancestor also lead to a bug reported by NephilaWeaver where a teleport trap could teleport you into unexplored terrain giving you enough piety for an ancestor and then piety delay could bring you below the piety required for an ancestor but fail to remove your ancestor as it hadn't spawned yet. Then at the end of your next turn, your ancestor would spawn even though you didn't have enough piety. Then when your got enough piety for an ancestor, a second one would spawn. Fix this by checking if spawning an ancestor is needed before spawning one from the queue.
Fixes #3300
Fixes #3450