Fix unit being constructed too early 1

This caused multiple bugs:
1) custom effects were not working on recall list units because units
   were created before lua initialisation (see issue #7234). This can
   cause OOS when the MP "Back to turn" feature is used.
2) (rare) Possible OOS causes by unsynced traits, see the comment
   in game_state.cpp before tb.build_team_stage_two()
This commit is contained in:
gfgtdf 2023-03-14 16:10:19 +01:00
parent 377cc62446
commit dd060f8540
3 changed files with 12 additions and 3 deletions

View file

@ -232,6 +232,9 @@ void game_state::init(const config& level, play_controller & pc)
for(team_builder& tb : team_builders) {
tb.build_team_stage_two();
}
for(team_builder& tb : team_builders) {
tb.build_team_stage_three();
}
for(std::size_t i = 0; i < board_.teams().size(); i++) {
// Labels from players in your ignore list default to hidden

View file

@ -66,6 +66,10 @@ void team_builder::build_team_stage_one()
// If the game state specifies additional units that can be recruited by the player, add them.
previous_recruits();
}
void team_builder::build_team_stage_two()
{
// place leader
leader();
@ -73,7 +77,7 @@ void team_builder::build_team_stage_one()
prepare_units();
}
void team_builder::build_team_stage_two()
void team_builder::build_team_stage_three()
{
// place units
// this is separate stage because we need to place units only after every other team is constructed

View file

@ -41,11 +41,13 @@ public:
team_builder(const team_builder&) = delete;
team_builder(team_builder&&) = default;
/** Handles the first stage of team initialization (everything except unit placement). */
/** Handles the first stage of team initialization (everything except unit construction). */
void build_team_stage_one();
/** Handles the second stage of team initialization (unit placement). */
/** Handles the second stage of team initialization ((some) unit construction). */
void build_team_stage_two();
/** Handles the third stage of team initialization (unit placement). */
void build_team_stage_three();
private:
int gold_info_ngold_;