Skip to content

Commit

Permalink
Healing: Instead of hardcoding a turn-and-side-number check, indirect…
Browse files Browse the repository at this point in the history
… through a boolean.

This boolean may be exposed to WML in the future (ask gtgtdf).
  • Loading branch information
jostephd committed Oct 21, 2018
1 parent 024f3e1 commit 5ce2f2d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/game_state.cpp
Expand Up @@ -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()),
Expand All @@ -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()),
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/game_state.hpp
Expand Up @@ -56,6 +56,8 @@ class game_state : public filter_context
const std::unique_ptr<actions::undo_list> 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> end_level_data_;
bool init_side_done_;
Expand Down
5 changes: 4 additions & 1 deletion src/play_controller.cpp
Expand Up @@ -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());
Expand Down
8 changes: 8 additions & 0 deletions src/play_controller.hpp
Expand Up @@ -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_;
}
Expand Down

0 comments on commit 5ce2f2d

Please sign in to comment.