Most boolean WML attribute probes use the standard util::string_bool() now

[set_variable] accepts string_length=

[variable] accepts boolean_not_equals=

[modify_side] can set a side's AI parameters now, using the [ai]
syntax as side declarations do (patch #984)
This commit is contained in:
Ignacio R. Morelle 2008-03-06 11:14:52 +00:00
parent 2e4795c2bb
commit 93b26eba79
19 changed files with 72 additions and 38 deletions

View file

@ -5,21 +5,28 @@ Version 1.5.0-svn:
* map editor:
* Fixed not working "Update transition" and make "Delay transition update"
directly trigger an update when toggled off.
* WML engine:
* Fixed most C++ probes for boolean WML attributes to use utils::string_bool()
rather than true/false or yes/no string comparisons; as a result, they should accept
true non-zero values, "on", "yes" or "true" strings; and "0", "off", "no" or "false" are
considered false values.
* A variable string's length can now be obtained with [set_variable]string_length=
* Implemented [variable] boolean_not_equals= for simmetry with [variable] boolean_equals=
* [modify_side] can set AI parameters now, using the [ai] syntax implemented
for [side] declarations (patch #984)
* miscellaneous and bug fixes:
* added VICTORY_AND_DEFEAT_MUSIC macro - not wiring it in in trunk
content, in the hope that we get engine support for this soon, but it's
here to use in the meantime
* 'road' is no longer aliased to grassland. It now has its own key in
movetypes. Note! This will create compatibility issues with UMC
that relies on a grassland= in a movetype or [defense] tag to also
that relies on a grassland= in a [movement_costs] or [defense] tag to also
set stats for roads.
* remove an ancient wml update program which has been obsoleted by wmllint
* added the boost regex dependency
* added the sdl-ttf dependency
* default gender selection now works correctly for units with
only a female variant. Fixes bug #11197.
* Fixed all C++ code that did string comparisons against WML attribute
"canrecruit" to use the standard WML utility function utils::string_bool() instead
* Fixed a border case of unit portrait advancement on which generic portraits would be
treated as character-specific (affected female Elvish Archer line; it also theoretically
affected units with [variation]s using different portraits)

View file

@ -544,7 +544,7 @@ void save_preview_pane::draw_contents()
str << font::BOLD_TEXT << utils::escape(name) << "\n" << time_buf;
const std::string& campaign_type = summary["campaign_type"];
if(summary["corrupt"] == "yes") {
if(utils::string_bool(summary["corrupt"], false)) {
str << "\n" << _("#(Invalid)");
} else if (!campaign_type.empty()) {
str << "\n";
@ -563,7 +563,7 @@ void save_preview_pane::draw_contents()
str << "\n";
if(summary["snapshot"] == "no" && summary["replay"] == "yes") {
if(utils::string_bool(summary["replay"], false) && !utils::string_bool(summary["snapshot"], true)) {
str << _("replay");
} else if (!summary["turn"].empty()) {
str << _("Turn") << " " << summary["turn"];
@ -713,7 +713,7 @@ std::string load_game_dialog(display& disp, const config& game_config, const gam
*show_replay = lmenu.option_checked();
const config& summary = *summaries[res];
if(summary["replay"] == "yes" && summary["snapshot"] == "no") {
if(utils::string_bool(summary["replay"], false) && !utils::string_bool(summary["snapshot"], true)) {
*show_replay = true;
}
}

View file

@ -627,7 +627,7 @@ bool game_controller::play_multiplayer_mode()
return false;
}
if ((*side)["random_faction"] == "yes") {
if (utils::string_bool((*side)["random_faction"])) {
const config::child_list& factions = era_cfg->get_children("multiplayer_side");
std::vector<std::string> faction_choices, faction_excepts;
faction_choices = utils::split((*side)["choices"]);
@ -639,7 +639,7 @@ bool game_controller::play_multiplayer_mode()
faction_excepts.clear();
}
for(unsigned int i = 0, j = 0; i < factions.size(); ++i) {
if ((*factions[i])["random_faction"] != "yes") {
if (utils::string_bool((*factions[i])["random_faction"]) != true) {
const std::string& faction_id = (*factions[i])["id"];
if (
!faction_choices.empty() &&
@ -657,7 +657,7 @@ bool game_controller::play_multiplayer_mode()
}
}
}
if ((*side)["random_faction"] == "yes") {
if (utils::string_bool((*side)["random_faction"], false) == true) {
std::string side_name = (type == side_types.end() ? "default" : type->second);
std::cerr << "Could not find any non-random faction for side " << side_num << "\n";
return false;

View file

@ -262,6 +262,11 @@ bool internal_conditional_passed(const unit_map* units,
&& (utils::string_bool(value) != utils::string_bool(boolean_equals))) {
return false;
}
const std::string boolean_not_equals = values["boolean_not_equals"];
if(values.get_attribute("boolean_not_equals") != ""
&& (utils::string_bool(value) == utils::string_bool(boolean_not_equals))) {
return false;
}
const std::string contains = values["contains"];
if(values.get_attribute("contains") != "" && value.find(contains) == std::string::npos) {
return false;
@ -700,7 +705,9 @@ void event_handler::handle_event_command(const queued_event& event_info,
std::string fog = cfg["fog"];
std::string shroud = cfg["shroud"];
std::string village_gold = cfg["village_gold"];
// TODO? std::string colour = cfg["colour"];
const config::child_list& ai = cfg.get_config().get_children("ai");
// TODO: also allow client to modify a side's colour if it
// is possible to change it on the fly without causing visual glitches
assert(state_of_game != NULL);
const int side_num = lexical_cast_default<int>(side,1);
@ -713,7 +720,7 @@ void event_handler::handle_event_command(const queued_event& event_info,
(*teams)[team_index].change_team(team_name,
user_team_name);
}
// Modify recruit list
// Modify recruit list (override)
if (!recruit_str.empty()) {
std::vector<std::string> recruit = utils::split(recruit_str);
if (recruit.size() == 1 && recruit.back() == "")
@ -751,6 +758,10 @@ void event_handler::handle_event_command(const queued_event& event_info,
if (!village_gold.empty()) {
(*teams)[team_index].set_village_gold(lexical_cast_default<int>(village_gold));
}
// Override AI parameters
if (!ai.empty()) {
(*teams)[team_index].set_ai_parameters(ai);
}
}
}
// Stores of some attributes of a side: gold, income, team name
@ -1053,6 +1064,12 @@ void event_handler::handle_event_command(const queued_event& event_info,
var = str_cast(value);
}
}
const t_string string_length_target = cfg["string_length"];
if(string_length_target.empty() == false) {
const int value = string_length_target.str().length();
var = str_cast(value);
}
// Note: maybe we add more options later, eg. strftime formatting.
// For now make the stamp mandatory.

View file

@ -976,7 +976,7 @@ void extract_summary_data_from_save(const game_state& gamestate, config& out)
continue;
}
if((**s)["shroud"] == "yes") {
if(utils::string_bool((**s)["shroud"])) {
shrouded = true;
}
@ -1057,7 +1057,7 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
continue;
}
if((**s)["shroud"] == "yes") {
if(utils::string_bool((**s)["shroud"])) {
shrouded = true;
}

View file

@ -183,10 +183,10 @@ void hotkey_item::load_from_config(const config& cfg)
{
const std::string& key = cfg["key"];
alt_ = (cfg["alt"] == "yes");
cmd_ = (cfg["cmd"] == "yes");
ctrl_ = (cfg["ctrl"] == "yes");
shift_ = (cfg["shift"] == "yes");
alt_ = utils::string_bool(cfg["alt"]);
cmd_ = utils::string_bool(cfg["cmd"]);
ctrl_ = utils::string_bool(cfg["ctrl"]);
shift_ = utils::string_bool(cfg["shift"]);
if (!key.empty()) {
// They may really want a specific key on the keyboard: we assume

View file

@ -111,7 +111,7 @@ bool show_intro_part(display &disp, const config& part,
const std::string& background_name = part["background"];
const bool show_title = (part["show_title"] == "yes");
const bool show_title = utils::string_bool(part["show_title"]);
surface background(NULL);
if(background_name.empty() == false) {
@ -204,7 +204,7 @@ bool show_intro_part(display &disp, const config& part,
const int x = static_cast<int>(atoi(xloc.c_str())*scale);
const int y = static_cast<int>(atoi(yloc.c_str())*scale);
if ((**i)["scaled"] == "yes"){
if (utils::string_bool((**i)["scaled"])){
img = scale_surface(img, static_cast<int>(img->w*scale), static_cast<int>(img->h*scale));
}
@ -214,7 +214,7 @@ bool show_intro_part(display &disp, const config& part,
image_rect.w = img->w;
image_rect.h = img->h;
if ((**i)["centered"] == "yes"){
if (utils::string_bool((**i)["centered"])){
image_rect.x -= image_rect.w/2;
image_rect.y -= image_rect.h/2;
}

View file

@ -69,7 +69,7 @@ void leader_list_manager::update_leader_list(int side_index)
leaders_.clear();
if(side["random_faction"] == "yes") {
if(utils::string_bool(side["random_faction"])) {
if(leader_combo_ != NULL) {
std::vector<std::string> dummy;
dummy.push_back("-");

View file

@ -511,7 +511,7 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
if(!terrain.empty()) {
set_terrain(location(x2,y2),terrain[0]);
} else if(cfg["use_old"] != "yes") {
} else if(utils::string_bool(cfg["use_old"]) != true) {
set_terrain(location(x2,y2),t);
}
} else {

View file

@ -80,9 +80,9 @@ void play_controller::init(CVideo& video, bool is_replay){
recorder.set_skip(false);
const config::child_list& unit_cfg = level_.get_children("side");
bool snapshot = level_["snapshot"] == "yes";
const bool snapshot = utils::string_bool(level_["snapshot"]);
if(level_["modify_placing"] == "true") {
if(utils::string_bool(level_["modify_placing"])) {
LOG_NG << "modifying placing...\n";
place_sides_in_preferred_locations(map_,unit_cfg);
}

View file

@ -263,7 +263,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
std::vector<team>::iterator t;
for(t = teams_.begin(); t != teams_.end(); ++t) {
std::string countd_enabled = level_["mp_countdown"].c_str();
if ( countd_enabled == "yes" && !loading_game_ ){
if (utils::string_bool(countd_enabled) && !loading_game_ ){
t->set_countdown_time(1000 * lexical_cast_default<int>(level_["mp_countdown_init_time"],0));
}
}

View file

@ -56,7 +56,7 @@ display_manager::display_manager(display* d)
set_turbo_speed(turbo_speed());
set_fullscreen(fullscreen());
set_gamma(gamma());
set_colour_cursors(preferences::get("colour_cursors") == "yes");
set_colour_cursors(utils::string_bool(preferences::get("colour_cursors")));
}
display_manager::~display_manager()
@ -83,7 +83,7 @@ void set_fullscreen(bool ison)
gui::message_dialog(*disp,"",_("The video mode could not be changed. Your window manager must be set to 16 bits per pixel to run the game in windowed mode. Your display must support 1024x768x16 to run the game full screen.")).show();
}
// We reinit color cursors, because SDL on Mac seems to forget the SDL_Cursor
set_colour_cursors(preferences::get("colour_cursors") == "yes");
set_colour_cursors(utils::string_bool(preferences::get("colour_cursors")));
}
}
}

View file

@ -485,7 +485,7 @@ bool game::describe_slots() {
int num_sides = level_.get_children("side").size();
int i = 0;
for(config::child_list::const_iterator it = level_.get_children("side").begin(); it != level_.get_children("side").end(); ++it, ++i) {
if ((**it)["allow_player"] == "no" || (**it)["controller"] == "null") {
if ((utils::string_bool((**it)["allow_player"], true) == false) || (**it)["controller"] == "null") {
num_sides--;
} else {
if (!sides_taken_[i])

View file

@ -850,7 +850,7 @@ void server::process_data_lobby(const network::connection sock, const config& da
// See if the player is joining a game
if (data.child("join")) {
const std::string& id = (*data.child("join"))["id"];
const bool observer = ((*data.child("join"))["observe"] == "yes");
const bool observer = utils::string_bool((*data.child("join"))["observe"]);
const std::string& password = (*data.child("join"))["password"];
int game_id;
try {
@ -1061,7 +1061,7 @@ void server::process_data_game(const network::connection sock, const config& dat
// Update the game's description.
// If there is no shroud, then tell players in the lobby
// what the map looks like.
if (s["mp_shroud"] != "yes") {
if (true != utils::string_bool(s["mp_shroud"])) {
desc["map_data"] = s["map_data"];
}
desc["mp_era"] = (s.child("era") ? (*s.child("era"))["id"] : "");

View file

@ -553,7 +553,7 @@ void write_stats(config_writer &out)
void read_stats(const config& cfg)
{
fresh_stats();
mid_scenario = (cfg["mid_scenario"] == "true");
mid_scenario = (utils::string_bool(cfg["mid_scenario"]));
const config::child_list& scenarios = cfg.get_children("scenario");
for(config::child_list::const_iterator i = scenarios.begin(); i != scenarios.end(); ++i) {

View file

@ -366,8 +366,8 @@ team::team(const config& cfg, int gold) :
ally_shroud_(),
ally_fog_()
{
fog_.set_enabled(cfg["fog"] == "yes");
shroud_.set_enabled(cfg["shroud"] == "yes");
fog_.set_enabled( utils::string_bool(cfg["fog"]) );
shroud_.set_enabled( utils::string_bool(cfg["shroud"]) );
shroud_.read(cfg["shroud_data"]);
LOG_NG << "team::team(...): team_name: " << info_.team_name
@ -547,6 +547,15 @@ void team::set_ai_memory(const config& ai_mem){
info_.ai_memory_=ai_mem;
}
void team::set_ai_parameters(const config::child_list& ai_parameters)
{
info_.ai_params.clear(); // override
config::child_list::const_iterator i;
for (i = ai_parameters.begin(); i != ai_parameters.end(); ++i) {
info_.ai_params.push_back(**i);
}
}
bool team::shrouded(const gamemap::location& loc) const
{
if(!teams)
@ -842,4 +851,3 @@ int village_owner(const gamemap::location& loc)
return -1;
}
}

View file

@ -226,6 +226,7 @@ public:
const config& ai_parameters() const { return aiparams_; }
const config& ai_memory() const { return info_.ai_memory_; }
void set_ai_memory(const config& ai_mem);
void set_ai_parameters(const config::child_list& ai_parameters);
double leader_value() const { return info_.leader_value; }
void set_leader_value(double value) { info_.leader_value = value; }

View file

@ -491,7 +491,8 @@ theme::panel::panel(const config& cfg) : object(cfg), image_(cfg["image"])
theme::menu::menu() : context_(false)
{}
theme::menu::menu(const config& cfg) : object(cfg), context_(cfg["is_context_menu"] == "true"),
theme::menu::menu(const config& cfg) : object(cfg),
context_(utils::string_bool(cfg["is_context_menu"])),
title_(cfg["title"].str() + cfg["title_literal"].str()),
tooltip_(cfg["tooltip"]),
image_(cfg["image"]), type_(cfg["type"]),

View file

@ -527,7 +527,7 @@ void unit_type::build(const config& cfg, const movement_type_map& mv_types,
const config::child_list& variations = cfg.get_children("variation");
for(config::child_list::const_iterator var = variations.begin(); var != variations.end(); ++var) {
const config& var_cfg = **var;
if(var_cfg["inherit"] == "yes") {
if(utils::string_bool(var_cfg["inherit"])) {
config nvar_cfg(cfg);
nvar_cfg.merge_with(var_cfg);
nvar_cfg.clear_children("variation");
@ -545,7 +545,7 @@ void unit_type::build(const config& cfg, const movement_type_map& mv_types,
const config* const male_cfg = cfg.child("male");
if(male_cfg != NULL) {
config m_cfg;
if((*male_cfg)["inherit"]=="no") {
if(!utils::string_bool((*male_cfg)["inherit"], true)) {
m_cfg = *male_cfg;
} else {
m_cfg = cfg;
@ -559,7 +559,7 @@ void unit_type::build(const config& cfg, const movement_type_map& mv_types,
const config* const female_cfg = cfg.child("female");
if(female_cfg != NULL) {
config f_cfg;
if((*female_cfg)["inherit"]=="no") {
if(!utils::string_bool((*female_cfg)["inherit"], true)) {
f_cfg = *female_cfg;
} else {
f_cfg = cfg;