implemented 'load game' option

This commit is contained in:
Dave White 2004-06-04 22:45:36 +00:00
parent ad0a51e494
commit 5d3a4f5b3b
9 changed files with 103 additions and 48 deletions

View file

@ -23,7 +23,7 @@ height=600
[menu]
title=main_menu
image=lite
items=speak,objectives,unitlist,recruit,recall,statustable,endturn,undo,redo,save,statistics,preferences,quit
items=speak,objectives,unitlist,recruit,recall,statustable,endturn,undo,redo,save,load,statistics,preferences,quit
rect=3,1,100,22
xanchor=fixed
yanchor=fixed

View file

@ -90,6 +90,11 @@ language="English"
ctrl=yes
[/hotkey]
[hotkey]
command=load
key=l
ctrl=yes
[/hotkey]
[hotkey]
command=statustable
key=s
alt=yes
@ -112,7 +117,7 @@ language="English"
[hotkey]
command=labelterrain
key=l
ctrl=yes
alt=yes
[/hotkey]
[hotkey]
command=showenemymoves
@ -487,6 +492,7 @@ action_resistance="Attack Resistance"
action_describeunit="Unit Description"
action_renameunit="Rename Unit"
action_save="Save Game"
action_load="Load Game"
action_togglegrid="Toggle Grid"
action_statustable="Status Table"
action_recall="Recall"

View file

@ -792,8 +792,7 @@ void attack(display& gui, const gamemap& map,
if(stats.defender_plague && !map.is_village(loc)) {
d = units.find(defender_loc);
if(d != units.end()) {
units.insert(std::pair<gamemap::location,unit>(
loc,d->second));
units.insert(std::pair<gamemap::location,unit>(loc,d->second));
gui.draw_tile(loc.x,loc.y);
}
}

View file

@ -504,6 +504,11 @@ int play_game(int argc, char** argv)
SDL_WM_SetCaption(string_table["game_title"].c_str(), NULL);
}
//these variables are used to store the game that the user selects to load
//from within the game
std::string loaded_game = "";
bool loaded_game_show_replay = false;
for(;;) {
statistics::fresh_stats();
@ -670,23 +675,26 @@ int play_game(int argc, char** argv)
try {
play_level(units_data,game_config,&level,video,state,story);
return 0;
} catch(gamestatus::error& e) {
std::cerr << "caught error: '" << e.message << "'\n";
return 0;
} catch(gamestatus::load_game_exception& e) {
//the user's trying to load a game, so go into the normal title screen loop and load one
loaded_game = e.game;
loaded_game_show_replay = e.show_replay;
} catch(...) {
std::cerr << "caught unknown error playing level...\n";
return 0;
}
return 0;
}
recorder.clear();
std::cerr << "showing title screen...\n";
std::cerr << (SDL_GetTicks() - start_ticks) << "\n";
gui::TITLE_RESULT res = gui::TITLE_CONTINUE;
gui::TITLE_RESULT res = loaded_game.empty() ? gui::TITLE_CONTINUE : gui::LOAD_GAME;
while(res == gui::TITLE_CONTINUE) {
res = gui::show_title(disp);
}
@ -698,12 +706,11 @@ int play_game(int argc, char** argv)
return 0;
} else if(res == gui::LOAD_GAME) {
bool show_replay;
bool show_replay = loaded_game_show_replay;
const std::string game = dialogs::load_game_dialog(disp,&show_replay);
const std::string game = loaded_game.empty() ? dialogs::load_game_dialog(disp,&show_replay) : loaded_game;
if(game == "")
continue;
loaded_game = "";
try {
load_game(units_data,game,state);
@ -766,7 +773,7 @@ int play_game(int argc, char** argv)
if((**sides.first)["controller"] == "network")
(**sides.first)["controller"] = "human";
}
recorder.set_save_info(state);
std::vector<config*> story;
@ -791,10 +798,15 @@ int play_game(int argc, char** argv)
std::cerr << "error while playing the game: "
<< e.message << "\n";
return 0;
} catch(gamestatus::load_game_exception& e) {
//this will make it so next time through the title screen loop, this game is loaded
loaded_game = e.game;
loaded_game_show_replay = e.show_replay;
}
continue;
}
} else if(res == gui::TUTORIAL) {
state.campaign_type = "tutorial";
state.scenario = "tutorial";
@ -915,6 +927,10 @@ int play_game(int argc, char** argv)
gui::show_dialog(disp,NULL,"",std::string("The game map could not be loaded: ") + e.msg_,gui::OK_ONLY);
std::cerr << "The game map could not be loaded: " << e.msg_ << "\n";
continue;
} catch(gamestatus::load_game_exception& e) {
//this will make it so next time through the title screen loop, this game is loaded
loaded_game = e.game;
loaded_game_show_replay = e.show_replay;
}
continue;
@ -961,12 +977,19 @@ int play_game(int argc, char** argv)
game_data units_data(*units[0]);
const LEVEL_RESULT result = play_game(disp,state,game_config,units_data,video);
if(result == VICTORY) {
gui::show_dialog(disp,NULL,
string_table["end_game_heading"],
string_table["end_game_message"],
gui::OK_ONLY);
try {
const LEVEL_RESULT result = play_game(disp,state,game_config,units_data,video);
if(result == VICTORY) {
gui::show_dialog(disp,NULL,
string_table["end_game_heading"],
string_table["end_game_message"],
gui::OK_ONLY);
}
} catch(gamestatus::load_game_exception& e) {
//this will make it so next time through the title screen loop, this game is loaded
loaded_game = e.game;
loaded_game_show_replay = e.show_replay;
}
}

View file

@ -89,6 +89,14 @@ public:
game_error(const std::string& msg) : error("game_error: " + msg) {}
};
//an exception object used to signal that the user has decided to abort
//a game, and load another game instead
struct load_game_exception {
load_game_exception(const std::string& game, bool show_replay) : game(game), show_replay(show_replay) {}
std::string game;
bool show_replay;
};
private:
const time_of_day& get_time_of_day_turn(int nturn) const;

View file

@ -50,6 +50,7 @@ HOTKEY_COMMAND string_to_command(const std::string& str)
m.insert(val("describeunit",HOTKEY_UNIT_DESCRIPTION));
m.insert(val("renameunit",HOTKEY_RENAME_UNIT));
m.insert(val("save",HOTKEY_SAVE_GAME));
m.insert(val("load",HOTKEY_LOAD_GAME));
m.insert(val("recruit",HOTKEY_RECRUIT));
m.insert(val("repeatrecruit",HOTKEY_REPEAT_RECRUIT));
m.insert(val("recall",HOTKEY_RECALL));
@ -353,6 +354,10 @@ void execute_command(display& disp, HOTKEY_COMMAND command, command_executor* ex
if(executor)
executor->save_game();
break;
case HOTKEY_LOAD_GAME:
if(executor)
executor->load_game();
break;
case HOTKEY_TOGGLE_GRID:
if(executor)
executor->toggle_grid();

View file

@ -28,7 +28,7 @@ enum HOTKEY_COMMAND { HOTKEY_CYCLE_UNITS, HOTKEY_END_UNIT_TURN, HOTKEY_LEADER,
HOTKEY_ZOOM_IN, HOTKEY_ZOOM_OUT, HOTKEY_ZOOM_DEFAULT,
HOTKEY_FULLSCREEN, HOTKEY_ACCELERATED,
HOTKEY_TERRAIN_TABLE, HOTKEY_ATTACK_RESISTANCE,
HOTKEY_UNIT_DESCRIPTION, HOTKEY_RENAME_UNIT, HOTKEY_SAVE_GAME,
HOTKEY_UNIT_DESCRIPTION, HOTKEY_RENAME_UNIT, HOTKEY_SAVE_GAME, HOTKEY_LOAD_GAME,
HOTKEY_RECRUIT, HOTKEY_REPEAT_RECRUIT, HOTKEY_RECALL, HOTKEY_ENDTURN,
HOTKEY_TOGGLE_GRID, HOTKEY_STATUS_TABLE, HOTKEY_MUTE,
HOTKEY_SPEAK, HOTKEY_CREATE_UNIT, HOTKEY_PREFERENCES,
@ -90,34 +90,35 @@ class command_executor
{
public:
virtual void cycle_units() {};
virtual void end_turn() {};
virtual void goto_leader() {};
virtual void end_unit_turn() {};
virtual void undo() {};
virtual void redo() {};
virtual void terrain_table() {};
virtual void attack_resistance() {};
virtual void unit_description() {};
virtual void rename_unit() {};
virtual void save_game() {};
virtual void toggle_grid() {};
virtual void status_table() {};
virtual void recall() {};
virtual void recruit() {};
virtual void repeat_recruit() {};
virtual void speak() {};
virtual void create_unit() {};
virtual void preferences() {};
virtual void objectives() {};
virtual void unit_list() {};
virtual void show_statistics() {};
virtual void label_terrain() {};
virtual void show_enemy_moves(bool /*ignore_units*/) {};
virtual void toggle_shroud_updates() {};
virtual void update_shroud_now() {};
virtual void continue_move() {};
virtual void search() {};
virtual void cycle_units() {}
virtual void end_turn() {}
virtual void goto_leader() {}
virtual void end_unit_turn() {}
virtual void undo() {}
virtual void redo() {}
virtual void terrain_table() {}
virtual void attack_resistance() {}
virtual void unit_description() {}
virtual void rename_unit() {}
virtual void save_game() {}
virtual void load_game() {}
virtual void toggle_grid() {}
virtual void status_table() {}
virtual void recall() {}
virtual void recruit() {}
virtual void repeat_recruit() {}
virtual void speak() {}
virtual void create_unit() {}
virtual void preferences() {}
virtual void objectives() {}
virtual void unit_list() {}
virtual void show_statistics() {}
virtual void label_terrain() {}
virtual void show_enemy_moves(bool /*ignore_units*/) {}
virtual void toggle_shroud_updates() {}
virtual void update_shroud_now() {}
virtual void continue_move() {}
virtual void search() {}
// Map editor stuff.
virtual void edit_set_terrain() {}

View file

@ -926,6 +926,9 @@ bool turn_info::can_execute_command(hotkey::HOTKEY_COMMAND command) const
case hotkey::HOTKEY_SAVE_GAME:
return !commands_disabled;
case hotkey::HOTKEY_LOAD_GAME:
return network::nconnections() == 0; //can only load games if not in a network game
case hotkey::HOTKEY_SHOW_ENEMY_MOVES:
case hotkey::HOTKEY_BEST_ENEMY_MOVES:
return enemies_visible_;
@ -1471,6 +1474,15 @@ void turn_info::save_game()
save_game("",gui::OK_CANCEL);
}
void turn_info::load_game()
{
bool show_replay = false;
const std::string game = dialogs::load_game_dialog(gui_,&show_replay);
if(game != "") {
throw gamestatus::load_game_exception(game,show_replay);
}
}
void turn_info::save_game(const std::string& message, gui::DIALOG_TYPE dialog_type)
{
std::stringstream stream;

View file

@ -133,6 +133,7 @@ private:
virtual void unit_description();
virtual void rename_unit();
virtual void save_game();
virtual void load_game();
virtual void toggle_grid();
virtual void status_table();
virtual void recruit();