fixed bug with loading some saved games in multiplayer

This commit is contained in:
Dave White 2003-10-23 11:49:12 +00:00
parent 0e3a2a4ac5
commit 3e96a51d3e
7 changed files with 66 additions and 21 deletions

View file

@ -459,6 +459,13 @@ void config::read(const std::string& data,
break;
}
}
assert(!element_names.empty());
element_names.pop();
if(!element_names.empty()) {
throw error("Configuration not terminated: no closing tag to '" +
element_names.top() + "'");
}
}
std::string config::write() const

View file

@ -440,13 +440,13 @@ void display::draw(bool update,bool force)
sideBarBgDrawn_ = true;
}
if(invalidateAll_) {
if(invalidateAll_ && !map_.empty()) {
for(int x = -1; x <= map_.x(); ++x)
for(int y = -1; y <= map_.y(); ++y)
draw_tile(x,y);
invalidateAll_ = false;
draw_minimap(mapx()+Minimap_x,Minimap_y,Minimap_w,Minimap_h);
} else {
} else if(!map_.empty()) {
for(std::set<gamemap::location>::const_iterator it =
invalidated_.begin(); it != invalidated_.end(); ++it) {
draw_tile(it->x,it->y);
@ -455,7 +455,9 @@ void display::draw(bool update,bool force)
invalidated_.clear();
}
draw_sidebar();
if(!map_.empty()) {
draw_sidebar();
}
int mousex, mousey;
const int mouse_flags = SDL_GetMouseState(&mousex,&mousey);

View file

@ -81,6 +81,11 @@ public:
return loc.valid() && loc.x < x() && loc.y < y();
}
bool empty() const
{
return x() == 0 || y() == 0;
}
const std::vector<location>& towers() const { return towers_; }
const terrain_type& get_terrain_info(TERRAIN terrain) const;

View file

@ -294,6 +294,9 @@ void play_multiplayer(display& disp, game_data& units_data, config cfg,
recorder = replay(state.replay_data);
//add the replay data under the level data so clients can
//receive it
level_ptr->children["replay"].clear();
level_ptr->add_child("replay") = state.replay_data;
} else {
@ -429,6 +432,10 @@ void play_multiplayer(display& disp, game_data& units_data, config cfg,
}
}
//any replay data isn't meant to hang around under the level,
//it was just there to tell clients about the replay data
level.children["replay"].clear();
std::vector<config*> story;
play_level(units_data,cfg,&level,disp.video(),state,story);
recorder.clear();

View file

@ -276,10 +276,14 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
}
}
//any replay data is only temporary and should be removed from
//the level data in case we want to save the game later
config* const replay_data = sides.child("replay");
config replay_data_store;
if(replay_data != NULL) {
replay_data_store = *replay_data;
std::cerr << "setting replay\n";
recorder = replay(*replay_data);
recorder = replay(replay_data_store);
if(!recorder.empty()) {
const int res = gui::show_dialog(disp,NULL,
"", string_table["replay_game_message"],
@ -293,6 +297,8 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
recorder.set_skip(-1);
}
}
sides.children["replay"].clear();
}
std::cerr << "starting game\n";

View file

@ -123,6 +123,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
bool replaying = (recorder.empty() == false);
int turn = 1;
std::cout << "starting main loop\n";
for(bool first_time = true; true; first_time = false) {
try {
@ -138,6 +139,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
gui.new_turn();
gui.invalidate_game_status();
std::cerr << "turn: " << turn++ << "\n";
for(std::vector<team>::iterator team_it = teams.begin();
team_it != teams.end(); ++team_it) {
const int player_number = (team_it - teams.begin()) + 1;
@ -155,11 +158,14 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
}
if(replaying) {
std::cerr << "doing replay " << player_number << "\n";
replaying = do_replay(gui,map,gameinfo,units,teams,
player_number,status,state_of_game);
std::cerr << "result of replay: " << (replaying?"true":"false") << "\n";
}
if(!replaying && team_it->is_human()) {
std::cerr << "is human...\n";
if(first_time && team_it == teams.begin() &&
level->values["objectives"].empty() == false) {
@ -215,28 +221,38 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
gui.draw();
SDL_Delay(500);
} else if(!replaying && team_it->is_network()) {
config cfg;
turn_info turn_data;
std::cerr << "is networked...\n";
for(;;) {
network::connection res = network::receive_data(cfg);
if(res && cfg.children["turn"].empty() == false) {
break;
bool turn_end = false;
while(!turn_end) {
config cfg;
turn_info turn_data;
for(;;) {
network::connection res =
network::receive_data(cfg);
if(res && cfg.children["turn"].empty() == false) {
break;
}
turn_slice(gameinfo,state_of_game,status,
terrain_config,level,video,key,gui,map,
teams,player_number,units,turn_data,true);
}
turn_slice(gameinfo,state_of_game,status,terrain_config,
level,video,key,gui,map,teams,player_number,
units,turn_data,true);
std::cerr << "replay: '" << cfg.children["turn"].front()->write() << "'\n";
replay replay_obj(*cfg.children["turn"].front());
replay_obj.start_replay();
turn_end = do_replay(gui,map,gameinfo,units,teams,
player_number,status,state_of_game,&replay_obj);
recorder.add_config(*cfg.children["turn"].front());
}
std::cerr << "replay: '" << cfg.children["turn"].front()->write() << "'\n";
replay replay_obj(*cfg.children["turn"].front());
replay_obj.start_replay();
do_replay(gui,map,gameinfo,units,teams,
player_number,status,state_of_game,&replay_obj);
recorder.add_config(*cfg.children["turn"].front());
std::cerr << "finished networked...\n";
}
for(unit_map::iterator uit = units.begin();

View file

@ -290,6 +290,8 @@ config* replay::get_next_action()
if(pos_ >= commands().size())
return NULL;
std::cerr << "up to replay action " << pos_ << "/" << commands().size() << "\n";
current_ = commands()[pos_];
++pos_;
return current_;