split a game exceptions into their own file...

...to avoid gratuitous dependencies on gamestatus, some cleanup of
deps against gamestatus
This commit is contained in:
Yann Dirson 2005-03-22 23:42:37 +00:00
parent ed980734c7
commit f83a0b1f76
24 changed files with 107 additions and 73 deletions

View file

@ -17,6 +17,7 @@
#include "display.hpp"
#include "events.hpp"
#include "game_config.hpp"
#include "game_errors.hpp"
#include "game_events.hpp"
#include "gettext.hpp"
#include "halo.hpp"
@ -1278,7 +1279,7 @@ unit get_advanced_unit(const game_data& info,
if(new_type != info.unit_types.end() && un != units.end()) {
return unit(&(new_type->second),un->second);
} else {
throw gamestatus::game_error("Could not find the unit being advanced"
throw game::game_error("Could not find the unit being advanced"
" to: " + advance_to);
}
}

View file

@ -18,6 +18,7 @@
#include "filesystem.hpp"
#include "font.hpp"
#include "game_config.hpp"
#include "game_errors.hpp"
#include "gettext.hpp"
#include "help.hpp"
#include "language.hpp"
@ -482,7 +483,7 @@ std::string load_game_dialog(display& disp, const config& game_config, const gam
} catch(config::error&) {
summary["corrupt"] = "yes";
ERR_G << "save '" << games[*s].name << "' could not be loaded (config parse error)\n";
} catch(gamestatus::load_game_failed&) {
} catch(game::load_game_failed&) {
summary["corrupt"] = "yes";
ERR_G << "save '" << games[*s].name << "' could not be loaded (load_game_failed exception)\n";
}

View file

@ -18,6 +18,7 @@
#include "events.hpp"
#include "font.hpp"
#include "game_config.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "halo.hpp"
#include "hotkeys.hpp"

View file

@ -14,7 +14,7 @@
#define DISPLAY_H_INCLUDED
class config;
#include "gamestatus.hpp"
class gamestatus;
#include "image.hpp"
#include "key.hpp"
#include "map.hpp"

View file

@ -19,7 +19,6 @@
#include "../filesystem.hpp"
#include "../font.hpp"
#include "../game_config.hpp"
#include "../gamestatus.hpp"
#include "../gettext.hpp"
#include "../key.hpp"
#include "../widgets/menu.hpp"

View file

@ -17,6 +17,7 @@
#include "../filesystem.hpp"
#include "../font.hpp"
#include "../game_config.hpp"
#include "../gamestatus.hpp"
#include "../gettext.hpp"
#include "../image.hpp"
#include "../language.hpp"

View file

@ -26,6 +26,7 @@
#include "filesystem.hpp"
#include "font.hpp"
#include "game_config.hpp"
#include "game_errors.hpp"
#include "game_events.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
@ -147,7 +148,7 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
config snapshot;
recorder.save_game(label, snapshot, state.starting_pos);
} catch(gamestatus::save_game_failed&) {
} catch(game::save_game_failed&) {
gui::show_error_message(disp, _("The game could not be saved"));
retry = true;
};
@ -169,10 +170,10 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
if(res != VICTORY) {
return res;
}
} catch(gamestatus::load_game_failed& e) {
} catch(game::load_game_failed& e) {
gui::show_error_message(disp, _("The game could not be loaded: ") + e.message);
return QUIT;
} catch(gamestatus::game_error& e) {
} catch(game::game_error& e) {
gui::show_error_message(disp, _("Error while playing the game: ") + e.message);
return QUIT;
} catch(gamemap::incorrect_format_exception& e) {
@ -204,7 +205,7 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
if(should_save == 0) {
try {
save_game(state);
} catch(gamestatus::save_game_failed&) {
} catch(game::save_game_failed&) {
gui::show_error_message(disp, _("The game could not be saved"));
retry = true;
}
@ -788,9 +789,9 @@ bool game_controller::play_multiplayer_mode()
try {
play_level(units_data_,game_config_,&level,video_,state_,story);
} catch(gamestatus::error& e) {
} catch(game::error& e) {
std::cerr << "caught error: '" << e.message << "'\n";
} catch(gamestatus::load_game_exception& e) {
} catch(game::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;
@ -853,7 +854,7 @@ bool game_controller::load_game()
}
}
} catch(gamestatus::error& e) {
} catch(game::error& e) {
gui::show_error_message(disp(), _("The file you have tried to load is corrupt: '") + e.message + '\'');
return false;
} catch(config::error& e) {
@ -913,11 +914,11 @@ bool game_controller::load_game()
try {
play_level(units_data_,game_config_,&starting_pos,video_,state_,story);
recorder.clear();
} catch(gamestatus::load_game_failed& e) {
} catch(game::load_game_failed& e) {
gui::show_error_message(disp(), _("The game could not be loaded: ") + e.message);
} catch(gamestatus::game_error& e) {
} catch(game::game_error& e) {
gui::show_error_message(disp(), _("Error while playing the game: ") + e.message);
} catch(gamestatus::load_game_exception& e) {
} catch(game::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;
@ -1327,9 +1328,9 @@ bool game_controller::play_multiplayer()
mp::start_client(disp(), game_config_, units_data_, host);
}
} catch(gamestatus::load_game_failed& e) {
} catch(game::load_game_failed& e) {
gui::show_error_message(disp(), _("The game could not be loaded: ") + e.message);
} catch(gamestatus::game_error& e) {
} catch(game::game_error& e) {
gui::show_error_message(disp(), _("Error while playing the game: ") + e.message);
} catch(network::error& e) {
std::cerr << "caught network error...\n";
@ -1343,7 +1344,7 @@ bool game_controller::play_multiplayer()
}
} catch(gamemap::incorrect_format_exception& e) {
gui::show_error_message(disp(), std::string(_("The game map could not be loaded: ")) + e.msg_);
} catch(gamestatus::load_game_exception& e) {
} catch(game::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;
@ -1436,7 +1437,7 @@ void game_controller::play_game(RELOAD_GAME_DATA reload)
the_end(disp().video());
about::show_about(disp().video());
}
} catch(gamestatus::load_game_exception& e) {
} catch(game::load_game_exception& e) {
//this will make it so next time through the title screen loop, this game is loaded
loaded_game_ = e.game;

53
src/game_errors.hpp Normal file
View file

@ -0,0 +1,53 @@
/* $Id$ */
/*
Copyright (C) 2003 by David White <davidnwhite@optusnet.com.au>
Copyright (C) 2005 by Yann Dirson <ydirson@altern.org>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GAME_ERRORS_HPP_INCLUDED
#define GAME_ERRORS_HPP_INCLUDED
namespace game {
struct error {
error() {}
error(const std::string& msg) : message(msg)
{}
std::string message;
};
//an exception object used when loading a game fails.
struct load_game_failed : public error {
load_game_failed() {}
load_game_failed(const std::string& msg) : error("load_game_failed: " + msg) {}
};
//an exception object used when saving a game fails.
struct save_game_failed : public error {
save_game_failed() {}
save_game_failed(const std::string& msg) : error("save_game_failed: " + msg) {}
};
//an exception object used for any general game error.
//e.g. data files are corrupt.
struct game_error : public error {
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;
};
}
#endif

View file

@ -15,6 +15,7 @@
#include "ai.hpp"
#include "display.hpp"
#include "game_errors.hpp"
#include "game_events.hpp"
#include "image.hpp"
#include "language.hpp"
@ -1283,7 +1284,7 @@ bool event_handler::handle_event_command(const queued_event& event_info, const s
<< " and the map location is invalid.\n";
}
}
} catch(gamestatus::load_game_failed& e) {
} catch(game::load_game_failed& e) {
ERR_NG << "could not de-serialize unit: '" << e.message << "'\n";
}
}

View file

@ -15,6 +15,7 @@
#include "filesystem.hpp"
#include "game_config.hpp"
#include "game_errors.hpp"
#include "gamestatus.hpp"
#include "language.hpp"
#include "log.hpp"
@ -426,7 +427,7 @@ void read_save_file(const std::string& name, config& cfg)
if(cfg.empty()) {
std::cerr << "Could not parse file data into config\n";
throw gamestatus::load_game_failed();
throw game::load_game_failed();
}
}
@ -440,7 +441,7 @@ void load_game(const game_data& data, const std::string& name, game_state& state
state = read_game(data,&cfg);
}
//throws gamestatus::save_game_failed
//throws game::save_game_failed
void save_game(const game_state& state)
{
log_scope("save_game");
@ -464,7 +465,7 @@ void save_game(const game_state& state)
write_save_index();
} catch(io_exception& e) {
throw gamestatus::save_game_failed(e.what());
throw game::save_game_failed(e.what());
}
}

View file

@ -63,40 +63,6 @@ public:
//has expired.
bool next_turn();
struct error {
error() {}
error(const std::string& msg) : message(msg)
{}
std::string message;
};
//an exception object used when loading a game fails.
struct load_game_failed : public error {
load_game_failed() {}
load_game_failed(const std::string& msg) : error("load_game_failed: " + msg) {}
};
//an exception object used when saving a game fails.
struct save_game_failed : public error {
save_game_failed() {}
save_game_failed(const std::string& msg) : error("save_game_failed: " + msg) {}
};
//an exception object used for any general game error.
//e.g. data files are corrupt.
struct game_error : public error {
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

@ -13,13 +13,15 @@ See the COPYING file for more details.
#include "global.hpp"
#include "astarnode.hpp"
#include "gamestatus.hpp"
#include "log.hpp"
#include "pathfind.hpp"
#include "util.hpp"
#include "astarnode.hpp"
#include "wassert.hpp"
class gamestatus;
#include <cmath>
#include <iostream>

View file

@ -18,6 +18,8 @@
#include "dialogs.hpp"
#include "events.hpp"
#include "filesystem.hpp"
#include "game_errors.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "game_events.hpp"
#include "halo.hpp"
@ -284,11 +286,11 @@ LEVEL_RESULT play_level(const game_data& gameinfo, const config& game_config,
}
if(map.empty()) {
throw gamestatus::load_game_failed("Map not found");
throw game::load_game_failed("Map not found");
}
if(!start_pos.valid() && new_unit.side() == 1) {
throw gamestatus::load_game_failed("No starting position for side 1");
throw game::load_game_failed("No starting position for side 1");
}
if(start_pos.valid()) {

View file

@ -15,9 +15,9 @@
class config;
class CVideo;
struct game_state;
#include "game_config.hpp"
#include "gamestatus.hpp"
#include "unit_types.hpp"
#include <vector>

View file

@ -16,6 +16,7 @@
#include "actions.hpp"
#include "dialogs.hpp"
#include "events.hpp"
#include "game_errors.hpp"
#include "game_events.hpp"
#include "gettext.hpp"
#include "help.hpp"
@ -1288,7 +1289,7 @@ void turn_info::end_turn()
write_game_snapshot(snapshot);
try {
recorder.save_game(_("Auto-Save"), snapshot, state_of_game_.starting_pos);
} catch(gamestatus::save_game_failed&) {
} catch(game::save_game_failed&) {
gui::show_dialog(gui_,NULL,"",_("Could not auto save the game. Please save the game manually."),gui::MESSAGE);
//do not bother retrying, since the user can just save the game
}
@ -1507,7 +1508,7 @@ void turn_info::load_game()
bool show_replay = false;
const std::string game = dialogs::load_game_dialog(gui_,terrain_config_,gameinfo_,&show_replay);
if(game != "") {
throw gamestatus::load_game_exception(game,show_replay);
throw game::load_game_exception(game,show_replay);
}
}
@ -1551,7 +1552,7 @@ void turn_info::save_game(const std::string& message, gui::DIALOG_TYPE dialog_ty
if(dialog_type != gui::NULL_DIALOG) {
gui::show_dialog(gui_,NULL,_("Saved"),_("The game has been saved"), gui::OK_ONLY);
}
} catch(gamestatus::save_game_failed&) {
} catch(game::save_game_failed&) {
gui::show_dialog(gui_,NULL,_("Error"),_("The game could not be saved"),gui::MESSAGE);
//do not bother retrying, since the user can just try to save the game again
};

View file

@ -13,13 +13,13 @@
#ifndef PLAYTURN_HPP_INCLUDED
#define PLAYTURN_HPP_INCLUDED
class gamestatus;
class replay_network_sender;
#include "actions.hpp"
#include "config.hpp"
#include "display.hpp"
#include "events.hpp"
#include "gamestatus.hpp"
#include "hotkeys.hpp"
#include "key.hpp"
#include "scoped_resource.hpp"

View file

@ -14,9 +14,9 @@
#define REPLAY_H_INCLUDED
class display;
class gamestatus;
#include "config.hpp"
#include "gamestatus.hpp"
#include "map.hpp"
#include "random.hpp"
#include "unit.hpp"

View file

@ -3,6 +3,7 @@
#include "actions.hpp"
#include "font.hpp"
#include "game_config.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "language.hpp"
#include "reports.hpp"

View file

@ -5,7 +5,8 @@
#include <string>
#include <vector>
#include "gamestatus.hpp"
class gamestatus;
#include "map.hpp"
#include "team.hpp"
#include "unit.hpp"

View file

@ -15,7 +15,7 @@
#include "game_config.hpp"
#include "game_events.hpp"
#include "gamestatus.hpp"
#include "game_errors.hpp"
#include "log.hpp"
#include "network.hpp"
#include "team.hpp"
@ -718,7 +718,7 @@ void validate_side(int side)
}
if(side < 1 || side > int(teams->size())) {
throw gamestatus::game_error("invalid side found in unit definition");
throw game::game_error("invalid side found in unit definition");
}
}

View file

@ -16,6 +16,8 @@
#include "config.hpp"
#include "map.hpp"
struct time_of_day;
#include <set>
#include <string>
#include <vector>
@ -234,8 +236,8 @@ struct teams_manager {
bool is_observer();
//function which will validate a side. Throws gamestatus::game_error
//function which will validate a side. Throws game::game_error
//if the side is invalid
void validate_side(int side); //throw gamestatus::game_error
void validate_side(int side); //throw game::game_error
#endif

View file

@ -14,7 +14,7 @@
#include "global.hpp"
#include "game_config.hpp"
#include "gamestatus.hpp"
#include "game_errors.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "pathfind.hpp"
@ -601,7 +601,7 @@ void unit::read(const game_data& data, const config& cfg)
if(i != data.unit_types.end())
type_ = &i->second;
else
throw gamestatus::load_game_failed("Unit not found: '" + cfg["type"] + "'");
throw game::load_game_failed("Unit not found: '" + cfg["type"] + "'");
wassert(type_ != NULL);

View file

@ -4,6 +4,7 @@
#include "display.hpp"
#include "events.hpp"
#include "game_config.hpp"
#include "gamestatus.hpp"
#include "halo.hpp"
#include "image.hpp"
#include "log.hpp"

View file

@ -14,7 +14,6 @@
#include "global.hpp"
#include "game_config.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "unit_types.hpp"