From 4dd180f825ed0cfaa4cc913318633fa496a971f6 Mon Sep 17 00:00:00 2001 From: Dave White Date: Sun, 19 Sep 2004 02:27:23 +0000 Subject: [PATCH] attempt to make new recall list structure backwards compatible... ...with previous versions --- .../Heir_To_The_Throne/Battle_for_Wesnoth.cfg | 9 +++++ src/game_events.cpp | 34 ++++++++++--------- src/gamestatus.cpp | 22 +++++++++--- src/gamestatus.hpp | 3 +- src/playturn.cpp | 4 +-- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/data/scenarios/Heir_To_The_Throne/Battle_for_Wesnoth.cfg b/data/scenarios/Heir_To_The_Throne/Battle_for_Wesnoth.cfg index 61078798a87..3b44567cd1f 100755 --- a/data/scenarios/Heir_To_The_Throne/Battle_for_Wesnoth.cfg +++ b/data/scenarios/Heir_To_The_Throne/Battle_for_Wesnoth.cfg @@ -128,6 +128,15 @@ Defeat: [event] name=start + [recall] + description=Delfador + [/recall] + [recall] + description=Kalenz + [/recall] + [recall] + description=Li'sar + [/recall] {MESSAGE Asheviere ("So, these rebels come at last to face me, while most of my army is off fighting the fickle clans.")} {MESSAGE Li'sar ("Surrender, mother. The land's blood is spent. I have come to take my rightful place.")} {MESSAGE Asheviere ("Ahh. My own daughter, a turncoat. So it is true. Such treason my reign must endure! But endure it will.")} diff --git a/src/game_events.cpp b/src/game_events.cpp index 5a59834d5b7..7acbaea6d33 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -776,27 +776,29 @@ bool event_handler::handle_event_command(const queued_event& event_info, const s //if we should recall units that match a certain description else if(cmd == "recall") { - for(int index=0; indexsize(); ++index) { - player_info* const player = state_of_game->get_player((*teams)[index].save_id()); + std::cerr << "recalling unit...\n"; + for(int index = 0; index < int(teams->size()); ++index) { + std::cerr << "for side " << index << "...\n"; + player_info* const player = state_of_game->get_player((*teams)[index].save_id()); if(player == NULL) { + std::cerr << "player not found!\n"; continue; } - std::vector& avail = player->available_units; + std::vector& avail = player->available_units; - for(std::vector::iterator u = avail.begin(); u != avail.end(); ++u) { - if(game_events::unit_matches_filter(*u,cfg)) { - gamemap::location loc(cfg); - recruit_unit(*game_map,index+1,*units,*u,loc,cfg["show"] == "no" ? NULL : screen,false,true); - avail.erase(u); - break; - } - } - } - } - - else if(cmd == "object") { + for(std::vector::iterator u = avail.begin(); u != avail.end(); ++u) { + std::cerr << "checking unit against filter...\n"; + if(game_events::unit_matches_filter(*u,cfg)) { + gamemap::location loc(cfg); + recruit_unit(*game_map,index+1,*units,*u,loc,cfg["show"] == "no" ? NULL : screen,false,true); + avail.erase(u); + break; + } + } + } + } else if(cmd == "object") { const config* filter = cfg.child("filter"); const std::string& id = cfg["id"]; @@ -1453,7 +1455,7 @@ bool unit_matches_filter(const unit& u, const config& filter) } } - return true; + return res; } bool unit_matches_filter(unit_map::const_iterator itor, const config& filter) diff --git a/src/gamestatus.cpp b/src/gamestatus.cpp index 281dce1c840..e7207bf61a4 100644 --- a/src/gamestatus.cpp +++ b/src/gamestatus.cpp @@ -224,16 +224,30 @@ game_state read_game(const game_data& data, const config* cfg) const config::child_list& players = cfg->get_children("player"); - if(players.size()==0) { - std::cerr << "WARNING: no players found, old save file?" << std::endl; + if(players.empty()) { + //backwards compatibility code: assume that there is player data + //in the file itself, which corresponds to the leader of side 1 + const config::child_list& units = cfg->get_children("unit"); + config::child_list::const_iterator i; + for(i = units.begin(); i != units.end(); ++i) { + if((**i)["side"] == "1" && (**i)["canrecruit"] == "1") { + break; + } + } + + if(i != units.end()) { + std::cerr << "backwards compatibility: loading player '" << (**i)["description"] << "'\n"; + player_info player = read_player(data,cfg); + res.players.insert(std::pair((**i)["description"],player)); + } } else { for(config::child_list::const_iterator i = players.begin(); i != players.end(); ++i) { - std::string save_id=(**i)["save_id"]; + std::string save_id = (**i)["save_id"]; if(save_id.empty()) { std::cerr << "Corrupted player entry: NULL save_id" << std::endl; } else { - player_info player=read_player(data, *i); + player_info player = read_player(data, *i); res.players.insert(std::pair(save_id,player)); } } diff --git a/src/gamestatus.hpp b/src/gamestatus.hpp index c74bf6537aa..ee185dfd9f8 100644 --- a/src/gamestatus.hpp +++ b/src/gamestatus.hpp @@ -146,7 +146,8 @@ struct game_state std::map players; // Return the Nth player, or NULL if no such player exists - player_info* get_player(std::string id) { + player_info* get_player(const std::string& id) { + std::cerr << "get_player('" << id << "')\n"; std::map::iterator found=players.find(id); if(found==players.end()) { diff --git a/src/playturn.cpp b/src/playturn.cpp index 76658626e08..1fc5e596474 100644 --- a/src/playturn.cpp +++ b/src/playturn.cpp @@ -1200,9 +1200,9 @@ void turn_info::undo() undo_action& action = undo_stack_.back(); if(action.is_recall()) { - player_info *player=state_of_game_.get_player(teams_[team_num_-1].save_id()); + player_info* const player = state_of_game_.get_player(teams_[team_num_-1].save_id()); - if(!player) { + if(player == NULL) { std::cerr << "WARNING: trying to undo a recall for side " << team_num_ << ", which has no recall list!" << std::endl; } else { // Undo a recall action