mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-28 20:03:18 +00:00
Removed config::child_list from gamestatus.cpp.
This commit is contained in:
parent
dd48a01888
commit
b37cbbef96
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "global.hpp"
|
#include "global.hpp"
|
||||||
|
|
||||||
|
#include "foreach.hpp"
|
||||||
#include "gettext.hpp"
|
#include "gettext.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include "game_preferences.hpp"
|
#include "game_preferences.hpp"
|
||||||
@ -203,9 +204,9 @@ gamestatus::gamestatus(const config& time_cfg, int num_turns, game_state* s_o_g)
|
|||||||
|
|
||||||
set_start_ToD(const_cast<config&>(time_cfg),s_o_g);
|
set_start_ToD(const_cast<config&>(time_cfg),s_o_g);
|
||||||
|
|
||||||
const config::child_list& times_range = time_cfg.get_children("time_area");
|
foreach (const config &t, time_cfg.child_range("time_area")) {
|
||||||
for(config::child_list::const_iterator t = times_range.begin(); t != times_range.end(); ++t)
|
this->add_time_area(t);
|
||||||
this->add_time_area(**t);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gamestatus::write(config& cfg) const
|
void gamestatus::write(config& cfg) const
|
||||||
@ -401,24 +402,23 @@ bool gamestatus::next_turn()
|
|||||||
return numTurns_ == -1 || turn_ <= size_t(numTurns_);
|
return numTurns_ == -1 || turn_ <= size_t(numTurns_);
|
||||||
}
|
}
|
||||||
|
|
||||||
static player_info read_player(const config* cfg)
|
static player_info read_player(const config &cfg)
|
||||||
{
|
{
|
||||||
player_info res;
|
player_info res;
|
||||||
|
|
||||||
res.name = (*cfg)["name"];
|
res.name = cfg["name"];
|
||||||
|
|
||||||
res.gold = atoi((*cfg)["gold"].c_str());
|
res.gold = atoi(cfg["gold"].c_str());
|
||||||
res.gold_add = utils::string_bool((*cfg)["gold_add"]);
|
res.gold_add = utils::string_bool(cfg["gold_add"]);
|
||||||
|
|
||||||
const config::child_list& units = cfg->get_children("unit");
|
foreach (const config &u, cfg.child_range("unit")) {
|
||||||
for(config::child_list::const_iterator i = units.begin(); i != units.end(); ++i) {
|
res.available_units.push_back(unit(u, false));
|
||||||
res.available_units.push_back(unit(**i,false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.can_recruit.clear();
|
res.can_recruit.clear();
|
||||||
|
|
||||||
const std::string& can_recruit_str = (*cfg)["can_recruit"];
|
const std::string &can_recruit_str = cfg["can_recruit"];
|
||||||
if(can_recruit_str != "") {
|
if (!can_recruit_str.empty()) {
|
||||||
const std::vector<std::string> can_recruit = utils::split(can_recruit_str);
|
const std::vector<std::string> can_recruit = utils::split(can_recruit_str);
|
||||||
std::copy(can_recruit.begin(),can_recruit.end(),std::inserter(res.can_recruit,res.can_recruit.end()));
|
std::copy(can_recruit.begin(),can_recruit.end(),std::inserter(res.can_recruit,res.can_recruit.end()));
|
||||||
}
|
}
|
||||||
@ -498,7 +498,7 @@ game_state::game_state(const config& cfg, bool show_replay) :
|
|||||||
rng_.seed_random(lexical_cast_default<unsigned>((*snapshot)["random_calls"]));
|
rng_.seed_random(lexical_cast_default<unsigned>((*snapshot)["random_calls"]));
|
||||||
|
|
||||||
// Midgame saves have the recall list stored in the snapshot.
|
// Midgame saves have the recall list stored in the snapshot.
|
||||||
load_recall_list(snapshot->get_children("player"));
|
load_recall_list(snapshot->child_range("player"));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Start of scenario save, replays and MP campaign network next scenario
|
// Start of scenario save, replays and MP campaign network next scenario
|
||||||
@ -510,14 +510,14 @@ game_state::game_state(const config& cfg, bool show_replay) :
|
|||||||
// it will be preferred.
|
// it will be preferred.
|
||||||
if (replay_start != NULL){
|
if (replay_start != NULL){
|
||||||
// Check if we find some player information in the starting position
|
// Check if we find some player information in the starting position
|
||||||
const config::child_list& cfg_players = (*replay_start).get_children("player");
|
config::const_child_itors cfg_players = replay_start->child_range("player");
|
||||||
if (!cfg_players.empty())
|
if (cfg_players.first != cfg_players.second)
|
||||||
load_recall_list(cfg_players);
|
load_recall_list(cfg_players);
|
||||||
else
|
else
|
||||||
load_recall_list(cfg.get_children("player"));
|
load_recall_list(cfg.child_range("player"));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
load_recall_list(cfg.get_children("player"));
|
load_recall_list(cfg.child_range("player"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,7 +536,7 @@ game_state::game_state(const config& cfg, bool show_replay) :
|
|||||||
if(vars != NULL) {
|
if(vars != NULL) {
|
||||||
set_variables(*vars);
|
set_variables(*vars);
|
||||||
}
|
}
|
||||||
set_menu_items(cfg.get_children("menu_item"));
|
set_menu_items(cfg.child_range("menu_item"));
|
||||||
|
|
||||||
const config* const replay = cfg.child("replay");
|
const config* const replay = cfg.child("replay");
|
||||||
if(replay != NULL) {
|
if(replay != NULL) {
|
||||||
@ -552,10 +552,9 @@ game_state::game_state(const config& cfg, bool show_replay) :
|
|||||||
//See also playcampaign::play_game, where after finishing the scenario the replay
|
//See also playcampaign::play_game, where after finishing the scenario the replay
|
||||||
//will be saved.
|
//will be saved.
|
||||||
if(!starting_pos.empty()) {
|
if(!starting_pos.empty()) {
|
||||||
config::child_list player_list = cfg.get_children("player");
|
foreach (const config &p, cfg.child_range("player")) {
|
||||||
for (config::child_list::const_iterator p = player_list.begin(); p != player_list.end(); p++){
|
|
||||||
config& cfg_player = starting_pos.add_child("player");
|
config& cfg_player = starting_pos.add_child("player");
|
||||||
cfg_player.merge_with(**p);
|
cfg_player.merge_with(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1051,21 +1050,20 @@ void extract_summary_data_from_save(const game_state& gamestate, config& out)
|
|||||||
|
|
||||||
if(leader == "") {
|
if(leader == "") {
|
||||||
const config& snapshot = has_snapshot ? gamestate.snapshot : gamestate.starting_pos;
|
const config& snapshot = has_snapshot ? gamestate.snapshot : gamestate.starting_pos;
|
||||||
const config::child_list& sides = snapshot.get_children("side");
|
foreach (const config &side, snapshot.child_range("side"))
|
||||||
for(config::child_list::const_iterator s = sides.begin(); s != sides.end() && leader.empty(); ++s) {
|
{
|
||||||
|
if (side["controller"] != "human") {
|
||||||
if((**s)["controller"] != "human") {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(utils::string_bool((**s)["shroud"])) {
|
if (utils::string_bool(side["shroud"])) {
|
||||||
shrouded = true;
|
shrouded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config::child_list& units = (**s).get_children("unit");
|
foreach (const config &u, side.child_range("unit"))
|
||||||
for(config::child_list::const_iterator u = units.begin(); u != units.end(); ++u) {
|
{
|
||||||
if(utils::string_bool( (**u)["canrecruit"], false) == true) {
|
if (utils::string_bool(u["canrecruit"], false)) {
|
||||||
leader = (**u)["id"];
|
leader = u["id"];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1119,11 +1117,10 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
|
|||||||
/** @todo Ideally we should grab all leaders if there's more than 1 human player? */
|
/** @todo Ideally we should grab all leaders if there's more than 1 human player? */
|
||||||
std::string leader;
|
std::string leader;
|
||||||
|
|
||||||
const config::child_list& players = cfg_save.get_children("player");
|
foreach (const config &p, cfg_save.child_range("player"))
|
||||||
|
{
|
||||||
for(config::child_list::const_iterator i = players.begin(); i != players.end(); ++i) {
|
if (utils::string_bool(p["canrecruit"], false)) {
|
||||||
if (utils::string_bool( (**i)["canrecruit"], false) == true){
|
leader = p["save_id"];
|
||||||
leader = (**i)["save_id"];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1132,21 +1129,20 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
|
|||||||
if(leader == "") {
|
if(leader == "") {
|
||||||
const config* snapshot = has_snapshot ? cfg_snapshot : cfg_replay_start;
|
const config* snapshot = has_snapshot ? cfg_snapshot : cfg_replay_start;
|
||||||
if (snapshot != NULL){
|
if (snapshot != NULL){
|
||||||
const config::child_list& sides = snapshot->get_children("side");
|
foreach (const config &side, snapshot->child_range("side"))
|
||||||
for(config::child_list::const_iterator s = sides.begin(); s != sides.end() && leader.empty(); ++s) {
|
{
|
||||||
|
if (side["controller"] != "human") {
|
||||||
if((**s)["controller"] != "human") {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(utils::string_bool((**s)["shroud"])) {
|
if (utils::string_bool(side["shroud"])) {
|
||||||
shrouded = true;
|
shrouded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config::child_list& units = (**s).get_children("unit");
|
foreach (const config &u, side.child_range("unit"))
|
||||||
for(config::child_list::const_iterator u = units.begin(); u != units.end(); ++u) {
|
{
|
||||||
if(utils::string_bool( (**u)["canrecruit"], false) == true) {
|
if (utils::string_bool(u["canrecruit"], false)) {
|
||||||
leader = (**u)["id"];
|
leader = u["id"];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1226,18 +1222,19 @@ void game_state::clear_variable(const std::string& varname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_state::load_recall_list(const config::child_list& players)
|
void game_state::load_recall_list(const config::const_child_itors &players)
|
||||||
{
|
{
|
||||||
if(!players.empty()) {
|
if (players.first == players.second) return;
|
||||||
for(config::child_list::const_iterator i = players.begin(); i != players.end(); ++i) {
|
|
||||||
std::string save_id = (**i)["save_id"];
|
|
||||||
|
|
||||||
if(save_id.empty()) {
|
foreach (const config &p, players)
|
||||||
ERR_NG << "Corrupted player entry: NULL save_id" << std::endl;
|
{
|
||||||
} else {
|
const std::string &save_id = p["save_id"];
|
||||||
player_info player = read_player(*i);
|
|
||||||
this->players.insert(std::pair<std::string, player_info>(save_id,player));
|
if (save_id.empty()) {
|
||||||
}
|
ERR_NG << "Corrupted player entry: NULL save_id" << std::endl;
|
||||||
|
} else {
|
||||||
|
player_info player = read_player(p);
|
||||||
|
this->players.insert(std::make_pair(save_id, player));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1333,15 +1330,15 @@ void game_state::set_variables(const config& vars) {
|
|||||||
variables = vars;
|
variables = vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_state::set_menu_items(const config::child_list& menu_items) {
|
void game_state::set_menu_items(const config::const_child_itors &menu_items)
|
||||||
|
{
|
||||||
clear_wmi(wml_menu_items);
|
clear_wmi(wml_menu_items);
|
||||||
for (config::child_list::const_iterator i = menu_items.begin(),
|
foreach (const config &item, menu_items)
|
||||||
i_end = menu_items.end(); i != i_end; ++i)
|
|
||||||
{
|
{
|
||||||
const std::string& id = (**i)["id"].base_str();
|
const std::string &id = item["id"].base_str();
|
||||||
wml_menu_item*& mref = wml_menu_items[id];
|
wml_menu_item*& mref = wml_menu_items[id];
|
||||||
if(mref == NULL) {
|
if(mref == NULL) {
|
||||||
mref = new wml_menu_item(id, *i);
|
mref = new wml_menu_item(id, &item);
|
||||||
} else {
|
} else {
|
||||||
WRN_NG << "duplicate menu item (" << id << ") while loading gamestate\n";
|
WRN_NG << "duplicate menu item (" << id << ") while loading gamestate\n";
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param players Reference to the players section to load.
|
* @param players Reference to the players section to load.
|
||||||
*/
|
*/
|
||||||
void load_recall_list(const config::child_list& players);
|
void load_recall_list(const config::const_child_itors &players);
|
||||||
|
|
||||||
std::vector<scoped_wml_variable*> scoped_variables;
|
std::vector<scoped_wml_variable*> scoped_variables;
|
||||||
std::map<std::string, wml_menu_item*> wml_menu_items;
|
std::map<std::string, wml_menu_item*> wml_menu_items;
|
||||||
@ -116,7 +116,7 @@ public:
|
|||||||
const config& get_variables() const { return variables; }
|
const config& get_variables() const { return variables; }
|
||||||
void set_variables(const config& vars);
|
void set_variables(const config& vars);
|
||||||
|
|
||||||
void set_menu_items(const config::child_list& menu_items);
|
void set_menu_items(const config::const_child_itors &menu_items);
|
||||||
|
|
||||||
// Variable access
|
// Variable access
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ void level_to_gamestate(config& level, game_state& state)
|
|||||||
if(vars != NULL) {
|
if(vars != NULL) {
|
||||||
state.set_variables(*vars);
|
state.set_variables(*vars);
|
||||||
}
|
}
|
||||||
state.set_menu_items(level.get_children("menu_item"));
|
state.set_menu_items(level.child_range("menu_item"));
|
||||||
|
|
||||||
//Check whether it is a save-game by looking for snapshot data
|
//Check whether it is a save-game by looking for snapshot data
|
||||||
const bool saved_game = (level.child("snapshot") && level.child("snapshot")->child("side"));
|
const bool saved_game = (level.child("snapshot") && level.child("snapshot")->child("side"));
|
||||||
@ -136,13 +136,13 @@ void level_to_gamestate(config& level, game_state& state)
|
|||||||
if (state.snapshot.child("variables") != NULL){
|
if (state.snapshot.child("variables") != NULL){
|
||||||
state.set_variables(*state.snapshot.child("variables"));
|
state.set_variables(*state.snapshot.child("variables"));
|
||||||
}
|
}
|
||||||
state.set_menu_items(state.snapshot.get_children("menu_item"));
|
state.set_menu_items(state.snapshot.child_range("menu_item"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//If it is a start-of-scenario save, we need to load the player information from
|
//If it is a start-of-scenario save, we need to load the player information from
|
||||||
//the [player] tags
|
//the [player] tags
|
||||||
if(start_of_scenario){
|
if(start_of_scenario){
|
||||||
state.load_recall_list(state.starting_pos.get_children("player"));
|
state.load_recall_list(state.starting_pos.child_range("player"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//In any type of reload(normal save or start-of-scenario) the players could have
|
//In any type of reload(normal save or start-of-scenario) the players could have
|
||||||
|
@ -240,7 +240,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
|
|||||||
if(gamestate.snapshot.child("variables") != NULL) {
|
if(gamestate.snapshot.child("variables") != NULL) {
|
||||||
gamestate.set_variables(*gamestate.snapshot.child("variables"));
|
gamestate.set_variables(*gamestate.snapshot.child("variables"));
|
||||||
}
|
}
|
||||||
gamestate.set_menu_items(gamestate.snapshot.get_children("menu_item"));
|
gamestate.set_menu_items(gamestate.snapshot.child_range("menu_item"));
|
||||||
// Replace game label with that from snapshot
|
// Replace game label with that from snapshot
|
||||||
if (!gamestate.snapshot["label"].empty()){
|
if (!gamestate.snapshot["label"].empty()){
|
||||||
gamestate.label = gamestate.snapshot["label"];
|
gamestate.label = gamestate.snapshot["label"];
|
||||||
@ -417,13 +417,14 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
|
|||||||
std::string label = gamestate.label + _(" replay");
|
std::string label = gamestate.label + _(" replay");
|
||||||
if (dialogs::get_save_name(disp, "", _("Name: "), &label,
|
if (dialogs::get_save_name(disp, "", _("Name: "), &label,
|
||||||
gui::OK_CANCEL, _("Save Replay"), false, false) == 0) {
|
gui::OK_CANCEL, _("Save Replay"), false, false) == 0) {
|
||||||
try {
|
try {
|
||||||
config snapshot;
|
config snapshot;
|
||||||
//If the starting position contains player information, use this for
|
//If the starting position contains player information, use this for
|
||||||
//the replay savegame (this originally comes from the gamestate constructor,
|
//the replay savegame (this originally comes from the gamestate constructor,
|
||||||
//where the player stuff is added to the starting position to be used here.
|
//where the player stuff is added to the starting position to be used here.
|
||||||
config::child_list player_list = gamestate.starting_pos.get_children("player");
|
config::child_itors player_list =
|
||||||
if (player_list.size() > 0) {
|
gamestate.starting_pos.child_range("player");
|
||||||
|
if (player_list.first != player_list.second) {
|
||||||
recorder.set_save_info(gamestate, player_list);
|
recorder.set_save_info(gamestate, player_list);
|
||||||
}
|
}
|
||||||
recorder.save_game(label, snapshot, gamestate.starting_pos);
|
recorder.save_game(label, snapshot, gamestate.starting_pos);
|
||||||
|
@ -169,7 +169,7 @@ void replay::set_save_info(const game_state& save)
|
|||||||
saveInfo_ = save;
|
saveInfo_ = save;
|
||||||
}
|
}
|
||||||
|
|
||||||
void replay::set_save_info(const game_state& save, const config::child_list& players)
|
void replay::set_save_info(const game_state &save, const config::const_child_itors &players)
|
||||||
{
|
{
|
||||||
saveInfo_ = save;
|
saveInfo_ = save;
|
||||||
saveInfo_.players.clear();
|
saveInfo_.players.clear();
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
explicit replay(const config& cfg);
|
explicit replay(const config& cfg);
|
||||||
|
|
||||||
void set_save_info(const game_state& save);
|
void set_save_info(const game_state& save);
|
||||||
void set_save_info(const game_state& save, const config::child_list& players);
|
void set_save_info(const game_state &save, const config::const_child_itors &players);
|
||||||
void set_save_info_completion(const std::string &st);
|
void set_save_info_completion(const std::string &st);
|
||||||
|
|
||||||
void set_skip(bool skip);
|
void set_skip(bool skip);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user