fixed bug in multiplayer. Added saving of game on disconnect.

Added option to skip replay in multiplayer.
This commit is contained in:
Dave White 2003-10-19 00:37:37 +00:00
parent 93ba223f34
commit ab84c26a73
7 changed files with 51 additions and 6 deletions

View file

@ -130,6 +130,7 @@ connection_failed="Could not connect to the remote host"
connection_timeout="Connection timed out"
awaiting_connections="Waiting for players to connect"
position_taken="Filled"
multiplayer_save_name="multiplayer save"
position_vacant="Available"
observer="Observer"
@ -149,6 +150,8 @@ no_saves_message="There are no saved games to load.
load_game_heading="Load Game"
load_game_message="Choose the game to load"
replay_game_message="Show replay of game up to save point?"
save_game_error="A network disconnection has occured, and the game cannot continue. Do you want to save the game?"
multiplayer_save_name="multiplayer save"
end_game_heading="The End"
end_game_message="You have reached the end of the currently playable levels"
defeat_heading="Defeat"

View file

@ -410,6 +410,20 @@ void play_multiplayer(display& disp, game_data& units_data, config cfg,
recorder.set_save_info(state);
if(!recorder.empty()) {
const int res = gui::show_dialog(disp,NULL,
"", string_table["replay_game_message"],
gui::YES_NO);
//if yes, then show the replay, otherwise
//skip showing the replay
if(res == 0) {
recorder.set_skip(0);
} else {
std::cerr << "skipping...\n";
recorder.set_skip(-1);
}
}
std::vector<config*> story;
play_level(units_data,cfg,&level,disp.video(),state,story);
recorder.clear();

View file

@ -280,6 +280,19 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
if(replay_data != NULL) {
std::cerr << "setting replay\n";
recorder = replay(*replay_data);
if(!recorder.empty()) {
const int res = gui::show_dialog(disp,NULL,
"", string_table["replay_game_message"],
gui::YES_NO);
//if yes, then show the replay, otherwise
//skip showing the replay
if(res == 0) {
recorder.set_skip(0);
} else {
std::cerr << "skipping...\n";
recorder.set_skip(-1);
}
}
}
std::cerr << "starting game\n";

View file

@ -137,7 +137,8 @@ RESULT enter(display& disp, config& game_data)
const bool enter = key[KEY_ENTER] && !old_enter;
old_enter = key[KEY_ENTER];
if(enter || send_message.process(mousex,mousey,left_button)) {
if((enter || send_message.process(mousex,mousey,left_button)) &&
message_entry.text().empty() == false) {
config msg;
config& child = msg.add_child("message");
child["message"] = message_entry.text();

View file

@ -123,8 +123,6 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
bool replaying = (recorder.empty() == false);
const int start_command = recorder.ncommands();
std::cout << "starting main loop\n";
for(bool first_time = true; true; first_time = false) {
try {
@ -168,6 +166,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
dialogs::show_objectives(gui,*level);
}
const int start_command = recorder.ncommands();
try {
play_turn(gameinfo,state_of_game,status,terrain_config,
level, video, key, gui, events_manager, map,
@ -196,6 +196,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
}
} else if(!replaying && team_it->is_ai()) {
const int start_command = recorder.ncommands();
ai::do_move(gui,map,gameinfo,units,teams,
player_number,status);
@ -366,6 +368,18 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
gui::OK_ONLY);
return QUIT;
}
catch(network::error& e) {
std::string label = string_table["multiplayer_save_name"];
const int res = gui::show_dialog(gui,NULL,"",
string_table["save_game_error"],
gui::OK_CANCEL,NULL,NULL,
string_table["save_game_label"],&label);
if(res == 0) {
recorder.save_game(gameinfo,label);
}
return QUIT;
}
} //end for(;;)

View file

@ -437,8 +437,8 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
const std::map<gamemap::location,unit>::iterator u=units.find(src);
if(u == units.end()) {
std::cerr << "unfound location for source of movement: "
<< src.x << "," << src.y << "-"
<< dst.x << "," << dst.y << "\n";
<< (src.x+1) << "," << (src.y+1) << "-"
<< (dst.x+1) << "," << (dst.y+1) << "\n";
throw replay::error();
}

View file

@ -217,7 +217,7 @@ int show_dialog(display& disp, SDL_Surface* image,
font::draw_text(NULL, clipRect, message_font_size,
font::NORMAL_COLOUR, text_widget_label, 0, 0, NULL).w +
text_widget.width();
text_widget_height = text_widget.height();
text_widget_height = text_widget.height() + 6;
}
menu menu_(disp,menu_items,type == MESSAGE);