attempt to make new recall list structure backwards compatible...

...with previous versions
This commit is contained in:
Dave White 2004-09-19 02:27:23 +00:00
parent 3d4b640e90
commit 4dd180f825
5 changed files with 49 additions and 23 deletions

View File

@ -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.")}

View File

@ -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; index<teams->size(); ++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<unit>& avail = player->available_units;
std::vector<unit>& avail = player->available_units;
for(std::vector<unit>::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<unit>::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)

View File

@ -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<std::string,player_info>((**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<std::string, player_info>(save_id,player));
}
}

View File

@ -146,7 +146,8 @@ struct game_state
std::map<std::string, player_info> 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<std::string, player_info>::iterator found=players.find(id);
if(found==players.end()) {

View File

@ -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