diff --git a/src/game_state.cpp b/src/game_state.cpp index 2b3b9287669..42550586a71 100644 --- a/src/game_state.cpp +++ b/src/game_state.cpp @@ -392,6 +392,10 @@ const game_events::wmi_manager& game_state::get_wml_menu_items() const return this->events_manager_->wml_menu_items(); } +bool game_state::has_next_scenario() const +{ + return !gamedata_.next_scenario().empty() && gamedata_.next_scenario() != "null"; +} namespace { diff --git a/src/game_state.hpp b/src/game_state.hpp index f5a5378e65d..d233d30d702 100644 --- a/src/game_state.hpp +++ b/src/game_state.hpp @@ -135,6 +135,8 @@ public: /** Checks if any of the sides leaders can recruit at a location */ bool side_can_recruit_on(int side, map_location loc) const; + /** Checks whether this is not the last scenario (usually of a campaign)*/ + bool has_next_scenario() const; /** creates a new side during a game. @todo: maybe add parameters like id etc? */ void add_side_wml(config cfg); }; diff --git a/src/play_controller.hpp b/src/play_controller.hpp index 132d3ad51cf..fd8ba64cf8b 100644 --- a/src/play_controller.hpp +++ b/src/play_controller.hpp @@ -245,6 +245,8 @@ public: virtual replay_controller * get_replay_controller() const { return nullptr; } bool is_replay() const { return get_replay_controller() != nullptr; } + replay& recorder() const { return *replay_; } + t_string get_scenario_name() const { return level_["name"].t_str(); diff --git a/src/playmp_controller.cpp b/src/playmp_controller.cpp index 687d5032ce5..ab05d78d16c 100644 --- a/src/playmp_controller.cpp +++ b/src/playmp_controller.cpp @@ -205,7 +205,7 @@ void playmp_controller::after_human_turn() current_team().set_action_bonus_count(0); current_team().set_countdown_time(new_time); - resources::recorder->add_countdown_update(new_time, current_side()); + recorder().add_countdown_update(new_time, current_side()); } LOG_NG << "playmp::after_human_turn..."; @@ -293,9 +293,7 @@ void playmp_controller::maybe_linger() send_actions(); assert(is_regular_game_end()); if(!get_end_level_data().transient.linger_mode || get_teams().empty() || video::headless()) { - const bool has_next_scenario - = !gamestate().gamedata_.next_scenario().empty() && gamestate().gamedata_.next_scenario() != "null"; - if(!is_host() && has_next_scenario) { + if(!is_host() && gamestate().has_next_scenario()) { // If we continue without lingering we need to // make sure the host uploads the next scenario // before we attempt to download it. @@ -310,7 +308,7 @@ void playmp_controller::maybe_linger() void playmp_controller::surrender(int side_number) { undo_stack().clear(); - resources::recorder->add_surrender(side_number); + recorder().add_surrender(side_number); send_actions(); } @@ -365,7 +363,7 @@ void playmp_controller::process_network_data(bool unsync_only) config cfg; - if(!resources::recorder->at_end()) { + if(!recorder().at_end()) { // This should never do anything, the only case where // process_network_data_impl put something on the recorder // without immidiately exceuting it are user choices which @@ -394,7 +392,7 @@ playmp_controller::PROCESS_DATA_RESULT playmp_controller::process_network_data_i // the simple wesnothserver implementation in wesnoth was removed years ago. assert(cfg.all_children_count() == 1); assert(cfg.attribute_range().empty()); - if(!resources::recorder->at_end()) + if(!recorder().at_end()) { ERR_NW << "processing network data while still having data on the replay."; } @@ -430,7 +428,7 @@ playmp_controller::PROCESS_DATA_RESULT playmp_controller::process_network_data_i else if (cfg.has_child("whiteboard")) { set_scontext_unsynced scontext; - resources::whiteboard->process_network_data(cfg); + get_whiteboard()->process_network_data(cfg); } else if (auto change = cfg.optional_child("change_controller")) { @@ -479,7 +477,7 @@ playmp_controller::PROCESS_DATA_RESULT playmp_controller::process_network_turn_i } //note, that this function might call itself recursively: do_replay -> ... -> get_user_choice -> ... -> receive_actions -> ... -> handle_turn - resources::recorder->add_config(t, replay::MARK_AS_SENT); + recorder().add_config(t, replay::MARK_AS_SENT); do_replay(); return PROCESS_DATA_RESULT::CONTINUE; } @@ -516,7 +514,7 @@ void playmp_controller::process_network_side_drop_impl(const config& side_drop_c int action = 0; int first_observer_option_idx = 0; int control_change_options = 0; - bool has_next_scenario = !resources::gamedata->next_scenario().empty() && resources::gamedata->next_scenario() != "null"; + bool has_next_scenario = gamestate().has_next_scenario(); std::vector observers; std::vector allies; @@ -650,7 +648,7 @@ void playmp_controller::process_network_change_controller_impl(const config& cha update_viewing_player(); - resources::whiteboard->on_change_controller(side,tm); + get_whiteboard()->on_change_controller(side,tm); display::get_singleton()->labels().recalculate_labels(); @@ -663,12 +661,12 @@ void playmp_controller::send_actions() return; } - resources::whiteboard->send_network_data(); + get_whiteboard()->send_network_data(); - const bool send_everything = synced_context::is_unsynced() ? !resources::undo_stack->can_undo() : synced_context::undo_blocked(); + const bool send_everything = synced_context::is_unsynced() ? !undo_stack().can_undo() : synced_context::undo_blocked(); const replay::DATA_TYPE data_type = send_everything ? replay::ALL_DATA : replay::NON_UNDO_DATA; - config data = resources::recorder->get_unsent_commands(data_type); + config data = recorder().get_unsent_commands(data_type); if (!data.empty()) { send_to_wesnothd(config{ "turn", data}); }