[1.16] Fix #7820 "Enable planning mode on start" Setting

previously the code that tried to activate the whiteboard failed because it checks `can_modify_game_state` which checks for `!synced_context::is_unsynced`.

This moves init_side_end() further down to be called after check_victory and do_final_checkup for technical reasons. But this is safe to do since these functions only set unrelated variables and don't throw (except in case of  a gamebreaking error ofc)
This commit is contained in:
gfgtdf 2023-08-03 15:44:02 +02:00
parent ec11479e68
commit 8537aad68f

View file

@ -458,76 +458,78 @@ void play_controller::maybe_do_init_side()
void play_controller::do_init_side()
{
set_scontext_synced sync;
log_scope("player turn");
// In case we might end up calling sync:network during the side turn events,
// and we don't want do_init_side to be called when a player drops.
gamestate_->init_side_done() = true;
init_side_done_now_ = true;
{ // Block for set_scontext_synced
set_scontext_synced sync;
log_scope("player turn");
// In case we might end up calling sync:network during the side turn events,
// and we don't want do_init_side to be called when a player drops.
gamestate_->init_side_done() = true;
init_side_done_now_ = true;
const std::string turn_num = std::to_string(turn());
const std::string side_num = std::to_string(current_side());
const std::string turn_num = std::to_string(turn());
const std::string side_num = std::to_string(current_side());
gamestate().gamedata_.get_variable("side_number") = current_side();
gamestate().gamedata_.get_variable("side_number") = current_side();
// We might have skipped some sides because they were empty so it is not enough to check for side_num==1
if(!gamestate().tod_manager_.has_turn_event_fired()) {
pump().fire("turn_" + turn_num);
pump().fire("new_turn");
gamestate().tod_manager_.turn_event_fired();
}
pump().fire("side_turn");
pump().fire("side_" + side_num + "_turn");
pump().fire("side_turn_" + turn_num);
pump().fire("side_" + side_num + "_turn_" + turn_num);
// We want to work out if units for this player should get healed,
// and the player should get income now.
// Healing/income happen if it's not the first turn of processing,
// or if we are loading a game.
if(turn() > 1) {
gamestate().board_.new_turn(current_side());
current_team().new_turn();
// If the expense is less than the number of villages owned
// times the village support capacity,
// then we don't have to pay anything at all
int expense = gamestate().board_.side_upkeep(current_side()) - current_team().support();
if(expense > 0) {
current_team().spend_gold(expense);
// We might have skipped some sides because they were empty so it is not enough to check for side_num==1
if(!gamestate().tod_manager_.has_turn_event_fired()) {
pump().fire("turn_" + turn_num);
pump().fire("new_turn");
gamestate().tod_manager_.turn_event_fired();
}
}
if(do_healing()) {
calculate_healing(current_side(), !is_skipping_replay());
}
pump().fire("side_turn");
pump().fire("side_" + side_num + "_turn");
pump().fire("side_turn_" + turn_num);
pump().fire("side_" + side_num + "_turn_" + turn_num);
// Do healing on every side turn except the very first side turn.
// (1.14 and earlier did healing whenever turn >= 2.)
set_do_healing(true);
// We want to work out if units for this player should get healed,
// and the player should get income now.
// Healing/income happen if it's not the first turn of processing,
// or if we are loading a game.
if(turn() > 1) {
gamestate().board_.new_turn(current_side());
current_team().new_turn();
// Set resting now after the healing has been done.
for(unit& patient : resources::gameboard->units()) {
if(patient.side() == current_side()) {
patient.set_resting(true);
// If the expense is less than the number of villages owned
// times the village support capacity,
// then we don't have to pay anything at all
int expense = gamestate().board_.side_upkeep(current_side()) - current_team().support();
if(expense > 0) {
current_team().spend_gold(expense);
}
}
if(do_healing()) {
calculate_healing(current_side(), !is_skipping_replay());
}
// Do healing on every side turn except the very first side turn.
// (1.14 and earlier did healing whenever turn >= 2.)
set_do_healing(true);
// Set resting now after the healing has been done.
for(unit& patient : resources::gameboard->units()) {
if(patient.side() == current_side()) {
patient.set_resting(true);
}
}
// Prepare the undo stack.
undo_stack().new_side_turn(current_side());
pump().fire("turn_refresh");
pump().fire("side_" + side_num + "_turn_refresh");
pump().fire("turn_" + turn_num + "_refresh");
pump().fire("side_" + side_num + "_turn_" + turn_num + "_refresh");
// Make sure vision is accurate.
actions::clear_shroud(current_side(), true);
check_victory();
sync.do_final_checkup();
}
// Prepare the undo stack.
undo_stack().new_side_turn(current_side());
pump().fire("turn_refresh");
pump().fire("side_" + side_num + "_turn_refresh");
pump().fire("turn_" + turn_num + "_refresh");
pump().fire("side_" + side_num + "_turn_" + turn_num + "_refresh");
// Make sure vision is accurate.
actions::clear_shroud(current_side(), true);
init_side_end();
check_victory();
sync.do_final_checkup();
}
void play_controller::init_side_end()