From 5ce2f2df37ab8faf7e2e9fa9f3ba46a4c038a4c0 Mon Sep 17 00:00:00 2001 From: josteph Date: Sat, 20 Oct 2018 21:25:15 +0000 Subject: [PATCH] Healing: Instead of hardcoding a turn-and-side-number check, indirect through a boolean. This boolean may be exposed to WML in the future (ask gtgtdf). --- src/game_state.cpp | 3 +++ src/game_state.hpp | 2 ++ src/play_controller.cpp | 5 ++++- src/play_controller.hpp | 8 ++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/game_state.cpp b/src/game_state.cpp index d8f2d8716a9c..b39e11d137b6 100644 --- a/src/game_state.cpp +++ b/src/game_state.cpp @@ -56,6 +56,7 @@ game_state::game_state(const config & level, play_controller & pc, const ter_dat undo_stack_(new actions::undo_list(level.child("undo_stack"))), player_number_(level["playing_team"].to_int() + 1), next_player_number_(level["next_player_number"].to_int(player_number_ + 1)), + do_healing_(level["do_healing"].to_bool(false)), init_side_done_(level["init_side_done"].to_bool(false)), start_event_fired_(!level["playing_team"].empty()), server_request_number_(level["server_request_number"].to_int()), @@ -81,6 +82,7 @@ game_state::game_state(const config & level, play_controller & pc, game_board& b events_manager_(new game_events::manager()), player_number_(level["playing_team"].to_int() + 1), next_player_number_(level["next_player_number"].to_int(player_number_ + 1)), + do_healing_(level["do_healing"].to_bool(false)), end_level_data_(), init_side_done_(level["init_side_done"].to_bool(false)), start_event_fired_(!level["playing_team"].empty()), @@ -242,6 +244,7 @@ void game_state::write(config& cfg) const cfg["next_player_number"] = next_player_number_; } cfg["server_request_number"] = server_request_number_; + cfg["do_healing"] = do_healing_; //Call the lua save_game functions lua_kernel_->save_game(cfg); diff --git a/src/game_state.hpp b/src/game_state.hpp index 29c10904ff38..c1a39acfe602 100644 --- a/src/game_state.hpp +++ b/src/game_state.hpp @@ -56,6 +56,8 @@ class game_state : public filter_context const std::unique_ptr undo_stack_; int player_number_; int next_player_number_; + /// True if healing should be done at the beginning of the next side turn + bool do_healing_; boost::optional end_level_data_; bool init_side_done_; diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 8b7522f1b018..e53bcb0d9282 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -486,9 +486,12 @@ void play_controller::do_init_side() current_team().spend_gold(expense); } } - if (turn() > 1 || current_side() > 1) { + 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); // Prepare the undo stack. undo_stack().new_side_turn(current_side()); diff --git a/src/play_controller.hpp b/src/play_controller.hpp index 40c7842da2b2..8de60f566a1c 100644 --- a/src/play_controller.hpp +++ b/src/play_controller.hpp @@ -155,6 +155,14 @@ class play_controller : public controller_base, public events::observer, public return gamestate().board_.is_observer(); } + bool do_healing() const { + return gamestate().do_healing_; + } + + void set_do_healing(bool do_healing) { + gamestate().do_healing_ = do_healing; + } + game_state& gamestate() { return *gamestate_; }