Merge pull request #98 from cbeck88/carryover_WML
feature: [endlevel] may specify carryover WML merged/appended into next scenario
This commit is contained in:
commit
acb49a5580
4 changed files with 71 additions and 3 deletions
|
@ -33,6 +33,8 @@ end_level_data::end_level_data()
|
|||
, carryover_percentage(game_config::gold_carryover_percentage)
|
||||
, carryover_add(false)
|
||||
, transient()
|
||||
, next_scenario_settings()
|
||||
, next_scenario_append()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -43,6 +45,13 @@ void end_level_data::write(config& cfg) const
|
|||
cfg["bonus"] = gold_bonus;
|
||||
cfg["carryover_percentage"] = carryover_percentage;
|
||||
cfg["carryover_add"] = carryover_add;
|
||||
if (!next_scenario_settings.empty()) {
|
||||
cfg.add_child("next_scenario_settings", next_scenario_settings);
|
||||
}
|
||||
if (!next_scenario_append.empty()) {
|
||||
cfg.add_child("next_scenario_append", next_scenario_append);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void end_level_data::read(const config& cfg)
|
||||
|
@ -52,4 +61,13 @@ void end_level_data::read(const config& cfg)
|
|||
gold_bonus = cfg["bonus"].to_bool(true);
|
||||
carryover_percentage = cfg["carryover_percentage"].to_int(game_config::gold_carryover_percentage);
|
||||
carryover_add = cfg["carryover_add"].to_bool(false);
|
||||
const config & next_scenario_settings_cfg = cfg.child_or_empty("next_scenario_settings");
|
||||
if (!next_scenario_settings_cfg.empty()) {
|
||||
next_scenario_settings = next_scenario_settings_cfg;
|
||||
}
|
||||
const config & next_scenario_append_cfg = cfg.child_or_empty("next_scenario_append");
|
||||
if (!next_scenario_append_cfg.empty()) {
|
||||
next_scenario_append = next_scenario_append_cfg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
class config;
|
||||
#include "config.hpp"
|
||||
|
||||
enum LEVEL_RESULT {
|
||||
NONE,
|
||||
|
@ -108,6 +108,9 @@ struct end_level_data
|
|||
bool carryover_add; /**< Add or replace next scenario's minimum starting gold. */
|
||||
transient_end_level transient;
|
||||
|
||||
config next_scenario_settings;
|
||||
config next_scenario_append;
|
||||
|
||||
void write(config& cfg) const;
|
||||
|
||||
void read(const config& cfg);
|
||||
|
|
|
@ -725,6 +725,15 @@ WML_HANDLER_FUNCTION(endlevel, /*event_info*/, cfg)
|
|||
std::string next_scenario = cfg["next_scenario"];
|
||||
if (!next_scenario.empty()) {
|
||||
resources::gamedata->set_next_scenario(next_scenario);
|
||||
|
||||
const config next_scenario_settings_cfg = cfg.get_parsed_config().child_or_empty("next_scenario_settings");
|
||||
if (!next_scenario_settings_cfg.empty()) {
|
||||
data.next_scenario_settings = next_scenario_settings_cfg;
|
||||
}
|
||||
const config next_scenario_append_cfg = cfg.get_parsed_config().child_or_empty("next_scenario_append");
|
||||
if (!next_scenario_append_cfg.empty()) {
|
||||
data.next_scenario_append = next_scenario_append_cfg;
|
||||
}
|
||||
}
|
||||
|
||||
std::string end_of_campaign_text = cfg["end_text"];
|
||||
|
|
|
@ -69,6 +69,33 @@ static void team_init(config& level, game_state& gamestate){
|
|||
}
|
||||
}
|
||||
|
||||
static void do_carryover_WML(config & level, game_state& gamestate){
|
||||
|
||||
if(gamestate.snapshot.child_or_empty("variables")["turn_number"].to_int(-1)<1){
|
||||
|
||||
carryover_info sides(gamestate.carryover_sides_start);
|
||||
|
||||
end_level_data end_level_ = sides.get_end_level();
|
||||
|
||||
if(!end_level_.next_scenario_settings.empty()) {
|
||||
level.merge_with(end_level_.next_scenario_settings);
|
||||
}
|
||||
if(!end_level_.next_scenario_append.empty())
|
||||
{
|
||||
level.append_children(end_level_.next_scenario_append);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void clear_carryover_WML (game_state & gamestate) {
|
||||
|
||||
if (gamestate.carryover_sides.has_child("end_level_data")) {
|
||||
config & eld = gamestate.carryover_sides.child("end_level_data");
|
||||
eld.clear_children("next_scenario_settings");
|
||||
eld.clear_children("next_scenario_append");
|
||||
}
|
||||
}
|
||||
|
||||
static void store_carryover(game_state& gamestate, playsingle_controller& playcontroller, display& disp, const end_level_data& end_level){
|
||||
bool has_next_scenario = !resources::gamedata->next_scenario().empty() &&
|
||||
resources::gamedata->next_scenario() != "null";
|
||||
|
@ -234,7 +261,9 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,
|
|||
int num_turns = (*level)["turns"].to_int(-1);
|
||||
|
||||
config init_level = *level;
|
||||
do_carryover_WML(init_level, state_of_game);
|
||||
team_init(init_level, state_of_game);
|
||||
clear_carryover_WML(state_of_game);
|
||||
|
||||
LOG_NG << "creating objects... " << (SDL_GetTicks() - ticks) << "\n";
|
||||
playsingle_controller playcontroller(init_level, state_of_game, ticks, num_turns, game_config, disp.video(), skip_replay);
|
||||
|
@ -281,7 +310,9 @@ static LEVEL_RESULT playmp_scenario(const config& game_config,
|
|||
int num_turns = (*level)["turns"].to_int(-1);
|
||||
|
||||
config init_level = *level;
|
||||
do_carryover_WML(init_level, state_of_game);
|
||||
team_init(init_level, state_of_game);
|
||||
clear_carryover_WML(state_of_game);
|
||||
|
||||
playmp_controller playcontroller(init_level, state_of_game, ticks, num_turns,
|
||||
game_config, disp.video(), skip_replay, io_type == IO_SERVER);
|
||||
|
@ -571,6 +602,14 @@ LEVEL_RESULT play_game(game_display& disp, game_state& gamestate,
|
|||
// mp::connect_engine.
|
||||
team_init(starting_pos, gamestate);
|
||||
|
||||
//We don't merge WML until start of next scenario, but if we want to allow user to disable MP ui in transition,
|
||||
//then we have to move "allow_new_game" attribute over now.
|
||||
bool allow_new_game_flag = (*scenario)["allow_new_game"].to_bool(true);
|
||||
|
||||
if (gamestate.carryover_sides_start.child_or_empty("end_level_data").child_or_empty("next_scenario_settings").has_attribute("allow_new_game")) {
|
||||
allow_new_game_flag = gamestate.carryover_sides_start.child_or_empty("end_level_data").child("next_scenario_settings")["allow_new_game"].to_bool();
|
||||
}
|
||||
|
||||
params.scenario_data = *scenario;
|
||||
params.mp_scenario = (*scenario)["id"].str();
|
||||
params.mp_scenario_name = (*scenario)["name"].str();
|
||||
|
@ -583,8 +622,7 @@ LEVEL_RESULT play_game(game_display& disp, game_state& gamestate,
|
|||
connect_engine(new mp::connect_engine(disp, gamestate,
|
||||
params, !network_game, false));
|
||||
|
||||
if ((*scenario)["allow_new_game"].to_bool(true) ||
|
||||
game_config::debug) {
|
||||
if (allow_new_game_flag || game_config::debug) {
|
||||
// Opens mp::connect dialog to allow users to
|
||||
// make an adjustments for scenario.
|
||||
mp::ui::result connect_res = mp::goto_mp_connect(disp,
|
||||
|
|
Loading…
Add table
Reference in a new issue