fixed some MP saving/loading bugs

This commit is contained in:
uid68803 2004-01-12 23:42:22 +00:00
parent fc78b69fd6
commit 8a3e61754c
5 changed files with 29 additions and 20 deletions

View file

@ -52,6 +52,10 @@ network_game_manager::~network_game_manager()
int play_multiplayer(display& disp, game_data& units_data, config cfg,
game_state& state, bool server)
{
state.available_units.clear();
state.variables.clear();
state.can_recruit.clear();
SDL_Rect rect;
char buf[100];
log_scope("play multiplayer");

View file

@ -94,6 +94,10 @@ int mp_connect::load_map(int map, int num_turns, int village_gold,
load_game(*data_, game, *state_);
state_->gold = -10000;
state_->available_units.clear();
state_->can_recruit.clear();
if(state_->campaign_type != "multiplayer") {
gui::show_dialog(*disp_, NULL, "",
string_table["not_multiplayer_save_message"],

View file

@ -139,12 +139,16 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
if(gold.empty())
gold = "100";
std::cerr << "found gold: '" << gold << "'\n";
int ngold = ::atoi(gold.c_str());
if(ui == unit_cfg.begin() && state_of_game.gold >= ngold &&
(*level)["disallow_recall"] != "yes") {
ngold = state_of_game.gold;
}
std::cerr << "set gold to '" << ngold << "'\n";
//if this side tag describes the leader of the side
if((**ui)["no_leader"] != "yes") {
unit new_unit(gameinfo, **ui);
@ -273,6 +277,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
int turn = 1;
std::cout << "starting main loop\n";
for(bool first_time = true; true; first_time = false, first_player = 0) {
int player_number = 0;
try {
if(first_time) {
@ -293,7 +299,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
for(std::vector<team>::iterator team_it = teams.begin()+first_player;
team_it != teams.end(); ++team_it) {
log_scope("player turn");
const int player_number = (team_it - teams.begin()) + 1;
player_number = (team_it - teams.begin()) + 1;
//if a side is dead, don't do their turn
if(team_units(units,player_number) == 0)
@ -475,15 +481,7 @@ redo_turn:
turn_end = do_replay(gui,map,gameinfo,units,teams,
player_number,status,state_of_game,&replay_obj);
} catch(replay::error&) {
std::string output = "errorlog";
const int res = gui::show_dialog(gui,NULL,"",
string_table["network_sync_error"],
gui::YES_NO,NULL,NULL,"",&output);
if(res == 0 && output.empty() == false) {
recorder.mark_current();
config starting_pos;
recorder.save_game(gameinfo,output,starting_pos);
}
turn_data.save_game(string_table["network_sync_error"]);
return QUIT;
}
@ -603,15 +601,11 @@ redo_turn:
e.disconnect();
}
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) {
config starting_pos;
recorder.save_game(gameinfo,label,starting_pos);
}
turn_info turn_data(gameinfo,state_of_game,status,
game_config,level,key,gui,
map,teams,player_number,units,true);
turn_data.save_game(string_table["save_game_error"]);
return QUIT;
}

View file

@ -1026,13 +1026,18 @@ void turn_info::rename_unit()
}
void turn_info::save_game()
{
save_game("");
}
void turn_info::save_game(const std::string& message)
{
std::stringstream stream;
stream << state_of_game_.label << " " << string_table["turn"]
<< " " << status_.turn();
std::string label = stream.str();
const int res = dialogs::get_save_name(gui_,"",string_table["save_game_label"],&label,gui::OK_CANCEL);
const int res = dialogs::get_save_name(gui_,message,string_table["save_game_label"],&label,gui::OK_CANCEL);
if(res == 0) {
config start;

View file

@ -71,6 +71,8 @@ public:
bool can_execute_command(hotkey::HOTKEY_COMMAND command) const;
void save_game(const std::string& message);
private:
void write_game_snapshot(config& cfg) const;