WML_ASSERT -> VALIDATE

This commit is contained in:
Mark de Wever 2007-12-15 15:16:08 +00:00
parent 13fd639061
commit 3df02965dd
14 changed files with 22 additions and 22 deletions

View File

@ -256,14 +256,14 @@ battle_context::battle_context(const gamemap& map, const std::vector<team>& team
// A Python AI can send an invalid weapon and crash Wesnoth.
// Haven't found a way for the Python API to prevent this problem.
// So instead of segfaulting it sends an assertion failure.
WML_ASSERT(attacker_weapon < static_cast<int>(attacker.attacks().size()),
VALIDATE(attacker_weapon < static_cast<int>(attacker.attacks().size()),
_("An invalid weapon is selected, possibly by the Python AI."));
if (attacker_weapon == -1 && attacker.attacks().size() == 1 && attacker.attacks()[0].attack_weight() > 0 )
attacker_weapon = 0;
if (attacker_weapon == -1) {
WML_ASSERT(defender_weapon == -1,
VALIDATE(defender_weapon == -1,
_("An invalid weapon is send, possibly due to the Python AI."));
attacker_weapon = choose_attacker_weapon(attacker, defender, map, teams, units,
@ -279,12 +279,12 @@ battle_context::battle_context(const gamemap& map, const std::vector<team>& team
const attack_type *adef = NULL;
const attack_type *ddef = NULL;
if (attacker_weapon >= 0) {
WML_ASSERT(attacker_weapon < static_cast<int>(attacker.attacks().size()),
VALIDATE(attacker_weapon < static_cast<int>(attacker.attacks().size()),
_("An invalid weapon is selected, possibly by the Python AI."));
adef = &attacker.attacks()[attacker_weapon];
}
if (defender_weapon >= 0) {
WML_ASSERT(defender_weapon < static_cast<int>(defender.attacks().size()),
VALIDATE(defender_weapon < static_cast<int>(defender.attacks().size()),
_("An invalid weapon is selected, possibly by the Python AI."));
ddef = &defender.attacks()[defender_weapon];
}

View File

@ -1693,7 +1693,7 @@ void ai::analyze_potential_recruit_combat()
unit const &un = j->second;
const game_data::unit_type_map::const_iterator enemy_info = gameinfo_.unit_types.find(un.id());
WML_ASSERT((enemy_info != gameinfo_.unit_types.end()), _("Unknown unit type : ") + un.id());
VALIDATE((enemy_info != gameinfo_.unit_types.end()), _("Unknown unit type : ") + un.id());
int weight = un.cost() * un.hitpoints() / un.max_hitpoints();
weighting += weight;

View File

@ -73,7 +73,7 @@ struct move_cost_calculator : cost_calculator
if (units_.count(loc))
res *= 4.0;
WML_ASSERT(res > 0,
VALIDATE(res > 0,
_("Movement cost is 0, probably a terrain with movement cost of 0."));
return res;
}

View File

@ -155,7 +155,7 @@ const std::vector<game_config::server_info>& server_list()
static std::vector<game_config::server_info> pref_servers;
if(pref_servers.empty()) {
std::vector<game_config::server_info> &game_servers = game_config::server_list;
WML_ASSERT(game_servers.size() > 0, _("No server has been defined."));
VALIDATE(game_servers.size() > 0, _("No server has been defined."));
pref_servers.insert(pref_servers.begin(), game_servers.begin(), game_servers.end());
const std::vector<config *> &user_servers = get_prefs()->get_children("server");
std::vector<config *>::const_iterator server;

View File

@ -251,7 +251,7 @@ void gamestatus::write(config& cfg) const
//! Correct time is calculated from current time.
time_of_day gamestatus::get_time_of_day_turn(int nturn) const
{
WML_ASSERT(times_.size(), _("No time of day has been defined."));
VALIDATE(times_.size(), _("No time of day has been defined."));
int time = (currentTime_ + nturn - turn())% times_.size();
@ -266,7 +266,7 @@ time_of_day gamestatus::get_time_of_day_turn(int nturn) const
//! ~eturns time of day object for current turn.
time_of_day gamestatus::get_time_of_day() const
{
WML_ASSERT(times_.size(), _("No time of day has been defined."));
VALIDATE(times_.size(), _("No time of day has been defined."));
return times_[currentTime_];
}
@ -286,7 +286,7 @@ time_of_day gamestatus::get_time_of_day(int illuminated, const gamemap::location
for(std::vector<area_time_of_day>::const_iterator i = areas_.begin(); i != areas_.end(); ++i) {
if(i->hexes.count(loc) == 1) {
WML_ASSERT(i->times.size(), _("No time of day has been defined."));
VALIDATE(i->times.size(), _("No time of day has been defined."));
res = i->times[(n_turn-1)%i->times.size()];
break;
@ -371,7 +371,7 @@ void gamestatus::set_start_ToD(config &level, game_state* s_o_g)
void gamestatus::next_time_of_day()
{
WML_ASSERT(times_.size(), _("No time of day has been defined."));
VALIDATE(times_.size(), _("No time of day has been defined."));
currentTime_ = (currentTime_ + 1)%times_.size();
}

View File

@ -698,7 +698,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
log_scope("map generation");
// Odd widths are nasty
WML_ASSERT(is_even(width), _("Random maps with an odd width aren't supported."));
VALIDATE(is_even(width), _("Random maps with an odd width aren't supported."));
int ticks = SDL_GetTicks();

View File

@ -337,7 +337,7 @@ inline bool break_after(wchar_t ch)
//! wrap it on a char basis.
std::string word_wrap_text(const std::string& unwrapped_text, int font_size, int max_width, int max_height, int max_lines)
{
WML_ASSERT(max_width > 0, _("The maximum text width is less than 1."));
VALIDATE(max_width > 0, _("The maximum text width is less than 1."));
utils::utf8_iterator ch(unwrapped_text);
std::string current_word;

View File

@ -86,12 +86,12 @@ surface getMinimap(int w, int h, const gamemap& map, const viewpoint* vw)
symbols["terrain"] = t_translation::write_letter(terrain);
const std::string msg =
vgettext("Could not get image for terrain: $terrain.", symbols);
WML_ASSERT(false, msg);
VALIDATE(false, msg);
}
surf = surface(scale_surface_blended(tile,scale,scale));
WML_ASSERT(surf != NULL, _("Error creating or aquiring an image."));
VALIDATE(surf != NULL, _("Error creating or aquiring an image."));
i = normal_cache->insert(cache_map::value_type(terrain,surf)).first;
}
@ -103,7 +103,7 @@ surface getMinimap(int w, int h, const gamemap& map, const viewpoint* vw)
fog_cache->insert(cache_map::value_type(terrain,surf));
}
WML_ASSERT(surf != NULL, _("Error creating or aquiring an image."));
VALIDATE(surf != NULL, _("Error creating or aquiring an image."));
// we need a balanced shift up and down of the hexes.
// if not, only the bottom half-hexes are clipped

View File

@ -306,7 +306,7 @@ double shortest_path_calculator::cost(const gamemap::location& /*src*/,const gam
int const base_cost = unit_.movement_cost(map_[loc]);
// Pathfinding heuristic: the cost must be at least 1
WML_ASSERT(base_cost >= 1, _("Terrain with a movement cost less than 1 encountered."));
VALIDATE(base_cost >= 1, _("Terrain with a movement cost less than 1 encountered."));
if (total_movement_ < base_cost)
return getNoPathValue();

View File

@ -154,7 +154,7 @@ unit_race::unit_race(const config& cfg) :
{
//! @todo FIXME remove support after branching 1.4.
//! 2 versions with lg::wml_error
//! WML_ASSERT after that
//! VALIDATE after that
if(id_.empty()) {
// This code is only for compatibility with old race defs.
id_ = (cfg["name"]);

View File

@ -78,7 +78,7 @@ terrain_type::terrain_type(const config& cfg) :
editor_image_ = minimap_image_;
}
WML_ASSERT(number_ != t_translation::NONE_TERRAIN, _("'string' is a mandatory key in '[terrain]'."));
VALIDATE(number_ != t_translation::NONE_TERRAIN, _("'string' is a mandatory key in '[terrain]'."));
mvt_type_.push_back(number_);
def_type_.push_back(number_);

View File

@ -678,7 +678,7 @@ static t_layer string_to_layer_(const std::string& str)
// Validate the string (Note at the moment the error is caught at another
// location and sending a lg::wml_error() but that can be replaced later)
WML_ASSERT(str.size() <= 4, _("A terrain with a string with more "
VALIDATE(str.size() <= 4, _("A terrain with a string with more "
"than 4 characters has been found, the affected terrain is :") + str);
// The conversion to int puts the first char

View File

@ -308,7 +308,7 @@ theme::tborder::tborder(const config& cfg) :
border_image_bottom_odd(cfg["border_image_bottom_odd"]),
border_image_bottom_even(cfg["border_image_bottom_even"])
{
WML_ASSERT(size >= 0.0 && size <= 0.5, _("border_size should be between 0.0 and 0.5."));
VALIDATE(size >= 0.0 && size <= 0.5, _("border_size should be between 0.0 and 0.5."));
}
SDL_Rect& theme::object::location(const SDL_Rect& screen) const

View File

@ -34,7 +34,7 @@ class display;
#define __FUNCTION__ "(Unspecified)"
#endif
#endif
#define WML_ASSERT(cond, message) if(!(cond)) wml_exception(#cond, __FILE__, __LINE__, __FUNCTION__, message)
#define VALIDATE(cond, message) if(!(cond)) wml_exception(#cond, __FILE__, __LINE__, __FUNCTION__, message)
//! Helper function, don't call this directly.
void wml_exception(const char* cond, const char* file,