Fix implicit static cast...
...of config::attribute_value & to tstring & or t_token reference causes crashes. Some compilers were generating a temporary object and binding a reference to the temporary when creating an implicit cast to an attribute value. I removed the implicit cast and replaced all (I think) instances of the implicit cast with explicit 2 step operation. This fixes bugs like bug #18663, bug #18684
This commit is contained in:
parent
eb46598888
commit
cdb129508d
56 changed files with 521 additions and 454 deletions
|
@ -100,7 +100,7 @@ void set_about(const config &cfg)
|
|||
foreach (const config &about, cfg.child_range("about"))
|
||||
{
|
||||
about_list.add_child("about", about);
|
||||
const std::string &im = about["images"];
|
||||
const std::string im = about["images"];
|
||||
if (!images.empty())
|
||||
{
|
||||
if (images_default.empty())
|
||||
|
@ -117,14 +117,14 @@ void set_about(const config &cfg)
|
|||
|
||||
config temp;
|
||||
std::ostringstream text;
|
||||
const std::string &id = campaign["id"];
|
||||
const std::string id = campaign["id"];
|
||||
temp["title"] = campaign["name"];
|
||||
temp["id"] = id;
|
||||
std::string campaign_images;
|
||||
|
||||
foreach (const config &about, abouts)
|
||||
{
|
||||
const std::string &subtitle = about["title"];
|
||||
const std::string subtitle = about["title"];
|
||||
if (!subtitle.empty())
|
||||
{
|
||||
text << '+';
|
||||
|
@ -145,7 +145,7 @@ void set_about(const config &cfg)
|
|||
text << " " << entry["name"] << '\n';
|
||||
}
|
||||
|
||||
const std::string &im = about["images"];
|
||||
const std::string im = about["images"];
|
||||
if (!im.empty())
|
||||
{
|
||||
if (campaign_images.empty())
|
||||
|
|
|
@ -47,7 +47,7 @@ engine_cpp::~engine_cpp()
|
|||
|
||||
void engine_cpp::do_parse_aspect_from_config( const config &cfg, const std::string &id, std::back_insert_iterator<std::vector< aspect_ptr > > b )
|
||||
{
|
||||
const std::string aspect_factory_key = id+"*"+cfg["name"];//@note: hack which combines aspect id and name to get the std::string key of the aspect factory
|
||||
const std::string aspect_factory_key = id+"*"+cfg["name"].str();//@note: hack which combines aspect id and name to get the std::string key of the aspect factory
|
||||
aspect_factory::factory_map::iterator f = aspect_factory::get_list().find(aspect_factory_key);
|
||||
if (f == aspect_factory::get_list().end()){
|
||||
ERR_AI_ENGINE_CPP << "side "<<ai_.get_side()<< " : UNKNOWN aspect["<<aspect_factory_key<<"]" << std::endl;
|
||||
|
|
|
@ -104,7 +104,7 @@ void engine_fai::do_parse_stage_from_config( ai_context &context, const config &
|
|||
if (!cfg) {
|
||||
return;
|
||||
}
|
||||
const std::string &name = cfg["name"];
|
||||
const std::string name = cfg["name"];
|
||||
stage_ptr st_ptr;
|
||||
|
||||
//dropped from 1.8, as it's not ready
|
||||
|
|
|
@ -94,7 +94,7 @@ void configuration::init(const config &game_config)
|
|||
|
||||
|
||||
foreach (const config &ai_configuration, ais.child_range("ai")) {
|
||||
const std::string &id = ai_configuration["id"];
|
||||
const std::string id = ai_configuration["id"];
|
||||
if (id.empty()){
|
||||
|
||||
ERR_AI_CONFIGURATION << "skipped AI config due to missing id" << ". Config contains:"<< std::endl << ai_configuration << std::endl;
|
||||
|
@ -119,7 +119,7 @@ void configuration::add_era_ai_from_config(const config &era)
|
|||
{
|
||||
era_ai_configurations_.clear();
|
||||
foreach (const config &ai_configuration, era.child_range("ai")) {
|
||||
const std::string &id = ai_configuration["id"];
|
||||
const std::string id = ai_configuration["id"];
|
||||
if (id.empty()){
|
||||
|
||||
ERR_AI_CONFIGURATION << "skipped AI config due to missing id" << ". Config contains:"<< std::endl << ai_configuration << std::endl;
|
||||
|
|
|
@ -926,9 +926,9 @@ void formula_ai::on_create(){
|
|||
|
||||
foreach (const config &func, cfg_.child_range("function"))
|
||||
{
|
||||
const t_string &name = func["name"];
|
||||
const t_string &inputs = func["inputs"];
|
||||
const t_string &formula_str = func["formula"];
|
||||
const config::attribute_value &name = func["name"];
|
||||
const config::attribute_value &inputs = func["inputs"];
|
||||
const config::attribute_value &formula_str = func["formula"];
|
||||
|
||||
std::vector<std::string> args = utils::split(inputs);
|
||||
try {
|
||||
|
@ -938,7 +938,7 @@ void formula_ai::on_create(){
|
|||
args);
|
||||
}
|
||||
catch(game_logic::formula_error& e) {
|
||||
handle_exception(e, "Error while registering function '" + name + "'");
|
||||
handle_exception(e, "Error while registering function '" + name.str() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,9 +46,9 @@ void candidate_action_manager::load_config(const config& cfg, ai::formula_ai* ai
|
|||
candidate_action_ptr candidate_action_manager::load_candidate_action_from_config(const config& rc_action, ai::formula_ai* ai, function_symbol_table* function_table)
|
||||
{
|
||||
candidate_action_ptr new_ca;
|
||||
const t_string &name = rc_action["name"];
|
||||
const config::attribute_value &name = rc_action["name"];
|
||||
try {
|
||||
const t_string &type = rc_action["type"];
|
||||
const config::attribute_value &type = rc_action["type"];
|
||||
|
||||
if( type == "movement") {
|
||||
new_ca = candidate_action_ptr(new move_candidate_action(name, type, rc_action, function_table ));
|
||||
|
@ -58,7 +58,7 @@ candidate_action_ptr candidate_action_manager::load_candidate_action_from_config
|
|||
ERR_AI << "Unknown candidate action type: " << type << "\n";
|
||||
}
|
||||
} catch(formula_error& e) {
|
||||
ai->handle_exception(e, "Error while registering candidate action '" + name + "'");
|
||||
ai->handle_exception(e, "Error while registering candidate action '" + name.str() + "'");
|
||||
}
|
||||
return new_ca;
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ void holder::modify_ai(const config &cfg)
|
|||
// if not initialized, initialize now.
|
||||
get_ai_ref();
|
||||
}
|
||||
const std::string &act = cfg["action"];
|
||||
const std::string act = cfg["action"];
|
||||
LOG_AI_MOD << "side "<< side_ << " [modify_ai] "<<act<<" \""<<cfg["path"]<<"\""<<std::endl;
|
||||
DBG_AI_MOD << std::endl << cfg << std::endl;
|
||||
DBG_AI_MOD << "side "<< side_ << " before [modify_ai]"<<std::endl << to_config() << std::endl;
|
||||
|
@ -226,7 +226,7 @@ const std::string holder::describe_ai()
|
|||
if (this->ai_!=NULL) {
|
||||
return this->ai_->describe_self()+std::string(" for side ")+sidestr+std::string(" : ");
|
||||
} else {
|
||||
return std::string("not initialized ai with id=[")+cfg_["id"]+std::string("] for side ")+sidestr+std::string(" : ");
|
||||
return std::string("not initialized ai with id=[")+cfg_["id"].str()+std::string("] for side ")+sidestr+std::string(" : ");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -608,7 +608,7 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
|
|||
|
||||
int basex = TILEWIDTH / 2 + dx, basey = TILEWIDTH / 2 + dy;
|
||||
if (const config::attribute_value *base_ = img.get(z_base)) {
|
||||
std::vector<n_token::t_token> base = utils::split_token(*base_);
|
||||
std::vector<n_token::t_token> base = utils::split_attr(*base_);
|
||||
if(base.size() >= 2) {
|
||||
basex = atoi(base[0].c_str());
|
||||
basey = atoi(base[1].c_str());
|
||||
|
@ -617,7 +617,7 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
|
|||
|
||||
int center_x = -1, center_y = -1;
|
||||
if (const config::attribute_value *center_ = img.get(z_center)) {
|
||||
std::vector<n_token::t_token> center = utils::split_token(*center_);
|
||||
std::vector<n_token::t_token> center = utils::split_attr(*center_);
|
||||
if(center.size() >= 2) {
|
||||
center_x = atoi(center[0].c_str());
|
||||
center_y = atoi(center[1].c_str());
|
||||
|
@ -629,20 +629,20 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
|
|||
// Adds the other variants of the image
|
||||
foreach (const config &variant, img.child_range(z_variant))
|
||||
{
|
||||
const n_token::t_token &name = variant[z_name];
|
||||
const n_token::t_token &variations = img[z_variations];
|
||||
const n_token::t_token &tod = variant[z_tod];
|
||||
const config::attribute_value &name = variant[z_name];
|
||||
const config::attribute_value &variations = img[z_variations];
|
||||
const config::attribute_value &tod = variant[z_tod];
|
||||
bool random_start = variant[z_random_start].to_bool(true);
|
||||
|
||||
images.back().variants.push_back(rule_image_variant(name, variations, tod, random_start));
|
||||
images.back().variants.push_back(rule_image_variant(name.token(), variations.token(), tod.token(), random_start));
|
||||
}
|
||||
|
||||
// Adds the main (default) variant of the image at the end,
|
||||
// (will be used only if previous variants don't match)
|
||||
const n_token::t_token &name = img[z_name];
|
||||
const n_token::t_token &variations = img[z_variations];
|
||||
const config::attribute_value &name = img[z_name];
|
||||
const config::attribute_value &variations = img[z_variations];
|
||||
bool random_start = img[z_random_start].to_bool(true);
|
||||
images.back().variants.push_back(rule_image_variant(name, variations, random_start));
|
||||
images.back().variants.push_back(rule_image_variant(name.token(), variations.token(), random_start));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -684,19 +684,19 @@ void terrain_builder::add_constraints(terrain_builder::constraint_set &constrain
|
|||
t_translation::t_match(cfg[z_type], t_translation::WILDCARD), global_images);
|
||||
|
||||
|
||||
std::vector<n_token::t_token> item_string = utils::split_token(cfg[z_set_flag]);
|
||||
std::vector<n_token::t_token> item_string = utils::split_attr(cfg[z_set_flag]);
|
||||
constraint.set_flag.insert(constraint.set_flag.end(),
|
||||
item_string.begin(), item_string.end());
|
||||
|
||||
item_string = utils::split_token(cfg[z_has_flag]);
|
||||
item_string = utils::split_attr(cfg[z_has_flag]);
|
||||
constraint.has_flag.insert(constraint.has_flag.end(),
|
||||
item_string.begin(), item_string.end());
|
||||
|
||||
item_string = utils::split_token(cfg[z_no_flag]);
|
||||
item_string = utils::split_attr(cfg[z_no_flag]);
|
||||
constraint.no_flag.insert(constraint.no_flag.end(),
|
||||
item_string.begin(), item_string.end());
|
||||
|
||||
item_string = utils::split_token(cfg[z_set_no_flag]);
|
||||
item_string = utils::split_attr(cfg[z_set_no_flag]);
|
||||
constraint.set_flag.insert(constraint.set_flag.end(),
|
||||
item_string.begin(), item_string.end());
|
||||
constraint.no_flag.insert(constraint.no_flag.end(),
|
||||
|
@ -806,7 +806,7 @@ void terrain_builder::parse_config(const config &cfg, bool local)
|
|||
anchormap anchors;
|
||||
|
||||
// Parse the map= , if there is one (and fill the anchors list)
|
||||
parse_mapstring(br[z_map], pbr, anchors, br);
|
||||
parse_mapstring(br[z_map].token(), pbr, anchors, br);
|
||||
|
||||
// Parses the terrain constraints (TCs)
|
||||
foreach (const config &tc, br.child_range(z_tile))
|
||||
|
@ -821,7 +821,7 @@ void terrain_builder::parse_config(const config &cfg, bool local)
|
|||
loc.y = *v;
|
||||
}
|
||||
if (const config::attribute_value *v = tc.get(z_loc)) {
|
||||
std::vector<n_token::t_token> sloc = utils::split_token(*v);
|
||||
std::vector<n_token::t_token> sloc = utils::split_attr(*v);
|
||||
if(sloc.size() == 2) {
|
||||
loc.x = atoi(sloc[0].c_str());
|
||||
loc.y = atoi(sloc[1].c_str());
|
||||
|
@ -847,10 +847,10 @@ void terrain_builder::parse_config(const config &cfg, bool local)
|
|||
}
|
||||
}
|
||||
|
||||
const std::vector<n_token::t_token> global_set_flag = utils::split_token(br[z_set_flag]);
|
||||
const std::vector<n_token::t_token> global_no_flag = utils::split_token(br[z_no_flag]);
|
||||
const std::vector<n_token::t_token> global_has_flag = utils::split_token(br[z_has_flag]);
|
||||
const std::vector<n_token::t_token> global_set_no_flag = utils::split_token(br[z_set_no_flag]);
|
||||
const std::vector<n_token::t_token> global_set_flag = utils::split_attr(br[z_set_flag]);
|
||||
const std::vector<n_token::t_token> global_no_flag = utils::split_attr(br[z_no_flag]);
|
||||
const std::vector<n_token::t_token> global_has_flag = utils::split_attr(br[z_has_flag]);
|
||||
const std::vector<n_token::t_token> global_set_no_flag = utils::split_attr(br[z_set_no_flag]);
|
||||
|
||||
foreach (terrain_constraint &constraint, pbr.constraints)
|
||||
{
|
||||
|
@ -867,11 +867,11 @@ void terrain_builder::parse_config(const config &cfg, bool local)
|
|||
}
|
||||
|
||||
// Handles rotations
|
||||
const n_token::t_token &rotations = br[z_rotations];
|
||||
const config::attribute_value &rotations = br[z_rotations];
|
||||
|
||||
pbr.precedence = br[z_precedence];
|
||||
|
||||
add_rotated_rules(building_rules_, pbr, rotations);
|
||||
add_rotated_rules(building_rules_, pbr, rotations.token());
|
||||
|
||||
loadscreen::increment_progress();
|
||||
}
|
||||
|
|
|
@ -154,8 +154,8 @@ void cave_map_generator::generate_chambers()
|
|||
continue;
|
||||
}
|
||||
|
||||
const std::string &xpos = ch["x"];
|
||||
const std::string &ypos = ch["y"];
|
||||
const std::string xpos = ch["x"];
|
||||
const std::string ypos = ch["y"];
|
||||
|
||||
size_t min_xpos = 0, min_ypos = 0, max_xpos = width_, max_ypos = height_;
|
||||
|
||||
|
@ -188,7 +188,7 @@ void cave_map_generator::generate_chambers()
|
|||
const config &items = ch.child("items");
|
||||
new_chamber.items = items ? &items : NULL;
|
||||
|
||||
const std::string &id = ch["id"];
|
||||
const std::string id = ch["id"];
|
||||
if (!id.empty()) {
|
||||
chamber_ids_[id] = chambers_.size();
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ void cave_map_generator::generate_chambers()
|
|||
|
||||
foreach (const config &p, ch.child_range("passage"))
|
||||
{
|
||||
const std::string &dst = p["destination"];
|
||||
const std::string dst = p["destination"];
|
||||
|
||||
// Find the destination of this passage
|
||||
const std::map<std::string,size_t>::const_iterator itor = chamber_ids_.find(dst);
|
||||
|
|
|
@ -100,13 +100,13 @@ config::attribute_value &config::attribute_value::operator=(const t_token &v) {
|
|||
if (v == z_yes || v == z_true) return *this = true;
|
||||
if (v == z_no || v == z_false) return *this = false;
|
||||
|
||||
std::istringstream is(static_cast<std::string const &>(v));
|
||||
std::istringstream is(*v);
|
||||
int i;
|
||||
char extra_char;
|
||||
if( (is >> i) && ! is.get(extra_char) ) { *this = i; is_token_=true; token_value_ = v; return *this; }
|
||||
|
||||
is.clear();
|
||||
is.str(static_cast<std::string const &>(v));
|
||||
is.str(*v);
|
||||
double d;
|
||||
if( (is >> d) && ! is.get(extra_char) ) { *this = d; is_token_=true; token_value_ = v; return *this; }
|
||||
|
||||
|
@ -421,12 +421,12 @@ void config::merge_children_by_attribute(const t_token& key, const t_token& attr
|
|||
typedef std::map<t_token, config> config_map;
|
||||
config_map merged_children_map;
|
||||
foreach (const config &cfg, child_range(key)) {
|
||||
const t_token &value = cfg[attribute];
|
||||
config_map::iterator m = merged_children_map.find(value);
|
||||
const attribute_value &value = cfg[attribute];
|
||||
config_map::iterator m = merged_children_map.find(value.token());
|
||||
if ( m!=merged_children_map.end() ) {
|
||||
m->second.append(cfg);
|
||||
} else {
|
||||
merged_children_map.insert(std::make_pair(value, cfg));
|
||||
merged_children_map.insert(std::make_pair(value.token(), cfg));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,9 +237,9 @@ public:
|
|||
t_token const & token() const;
|
||||
|
||||
operator int() const { return to_int(); }
|
||||
operator std::string const &() const { return str(); } ///This is probably ill advised, due to spurious constructions
|
||||
operator t_string const &() const { return t_str(); }
|
||||
operator t_token const &() const {return token();}
|
||||
operator std::string const () const { return str(); } ///This is probably ill advised, due to spurious constructions
|
||||
//operator t_string const &() const { return t_str(); }
|
||||
//operator t_token const &() const {return token();}
|
||||
|
||||
bool operator==(const attribute_value &other) const;
|
||||
bool operator!=(const attribute_value &other) const { return !operator==(other); }
|
||||
|
|
|
@ -251,12 +251,12 @@ namespace game_config
|
|||
*a2 = teamC.get("rgb");
|
||||
if (!a1 || !a2) continue;
|
||||
std::string const & id = *a1;
|
||||
config::t_token const & idt = *a1;
|
||||
config::attribute_value const & idt = *a1;
|
||||
std::vector<Uint32> temp = string2rgb(*a2);
|
||||
team_rgb_range.insert(std::make_pair(id,color_range(temp)));
|
||||
team_rgb_name[id] = teamC["name"];
|
||||
team_rgb_name[id] = teamC["name"].token();
|
||||
//generate palette of same name;
|
||||
std::vector<Uint32> tp = palette(team_rgb_range[idt]);
|
||||
std::vector<Uint32> tp = palette(team_rgb_range[idt.token()]);
|
||||
if (tp.empty()) continue;
|
||||
team_rgb_colors.insert(std::make_pair(id,tp));
|
||||
//if this is being used, output log of palette for artists use.
|
||||
|
|
|
@ -514,7 +514,7 @@ bool game_controller::play_multiplayer_mode()
|
|||
foreach (const config &faction, era_cfg.child_range("multiplayer_side"))
|
||||
{
|
||||
if (faction["random_faction"].to_bool()) continue;
|
||||
const std::string &faction_id = faction["id"];
|
||||
const std::string faction_id = faction["id"];
|
||||
if (!faction_choices.empty() &&
|
||||
std::find(faction_choices.begin(), faction_choices.end(), faction_id) == faction_choices.end())
|
||||
continue;
|
||||
|
|
|
@ -289,7 +289,7 @@ static void show_wml_messages()
|
|||
typedef void (*wml_handler_function)(
|
||||
const game_events::queued_event &event_info, const vconfig &cfg);
|
||||
|
||||
typedef std::map<std::string, wml_handler_function> static_wml_action_map;
|
||||
typedef std::map<n_token::t_token, wml_handler_function> static_wml_action_map;
|
||||
/** Map of the default action handlers known of the engine. */
|
||||
static static_wml_action_map static_wml_actions;
|
||||
|
||||
|
@ -326,11 +326,13 @@ static static_wml_action_map static_wml_actions;
|
|||
*/
|
||||
#define WML_HANDLER_FUNCTION(pname, pei, pcfg) \
|
||||
static void wml_func_##pname(const game_events::queued_event &pei, const vconfig &pcfg); \
|
||||
struct wml_func_register_##pname \
|
||||
{ \
|
||||
wml_func_register_##pname() \
|
||||
{ static_wml_actions[#pname] = &wml_func_##pname; } \
|
||||
}; \
|
||||
struct wml_func_register_##pname \
|
||||
{ \
|
||||
wml_func_register_##pname() \
|
||||
{ \
|
||||
static const n_token::t_token z_##pname( #pname , false); \
|
||||
static_wml_actions[z_##pname] = &wml_func_##pname; } \
|
||||
}; \
|
||||
static wml_func_register_##pname wml_func_register_##pname##_aux; \
|
||||
static void wml_func_##pname(const game_events::queued_event& pei, const vconfig& pcfg)
|
||||
|
||||
|
@ -428,7 +430,7 @@ namespace game_events {
|
|||
|
||||
foreach (const vconfig &values, variables)
|
||||
{
|
||||
const n_token::t_token & name = values[z_name];
|
||||
const config::attribute_value & name = values[z_name];
|
||||
config::attribute_value value = resources::state_of_game->get_variable_const(name);
|
||||
n_token::t_token const & tk_value = value.token();
|
||||
double num_value = value.to_double();
|
||||
|
@ -449,7 +451,7 @@ namespace game_events {
|
|||
|
||||
#define TEST_TOKEN_ATTR(name, test) do { \
|
||||
if (values.has_attribute(name)) { \
|
||||
n_token::t_token const & attr_tk = values[name]; \
|
||||
config::attribute_value const & attr_tk = values[name]; \
|
||||
if (!(test)) return false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -461,8 +463,8 @@ namespace game_events {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
TEST_TOKEN_ATTR(z_equals, tk_value == attr_tk);
|
||||
TEST_TOKEN_ATTR(z_not_equals, tk_value != attr_tk);
|
||||
TEST_TOKEN_ATTR(z_equals, tk_value == attr_tk.token());
|
||||
TEST_TOKEN_ATTR(z_not_equals, tk_value != attr_tk.token());
|
||||
TEST_NUM_ATTR(z_numerical_equals, num_value == attr_num);
|
||||
TEST_NUM_ATTR(z_numerical_not_equals, num_value != attr_num);
|
||||
TEST_NUM_ATTR(z_greater_than, num_value > attr_num);
|
||||
|
@ -550,7 +552,7 @@ namespace game_events {
|
|||
const config::attribute_value& logger = cfg[z_logger];
|
||||
const config::attribute_value& msg = cfg[z_message];
|
||||
|
||||
put_wml_message(logger,msg);
|
||||
put_wml_message(logger.token(), msg.str());
|
||||
}
|
||||
|
||||
void handle_deprecated_message(const config& cfg)
|
||||
|
@ -656,7 +658,7 @@ namespace {
|
|||
|
||||
else {
|
||||
const config & cfg = new_handler.get_config();
|
||||
config::t_token const & id = cfg[z_id];
|
||||
config::attribute_value const & id = cfg[z_id];
|
||||
if(id != n_token::t_token::z_empty()) {
|
||||
foreach( game_events::event_handler const & eh, active_) {
|
||||
config const & temp_config( eh.get_config());
|
||||
|
@ -684,7 +686,7 @@ namespace {
|
|||
t_active::iterator i = temp.begin();
|
||||
while(i < temp.end()) {
|
||||
config const & temp_config = (*i).get_config();
|
||||
config::t_token const &event_id = temp_config[z_id];
|
||||
config::attribute_value const &event_id = temp_config[z_id];
|
||||
if(event_id != z_empty && event_id == id) {
|
||||
i = temp.erase(i); }
|
||||
else {
|
||||
|
@ -786,7 +788,7 @@ WML_HANDLER_FUNCTION(tunnel, /*event_info*/, cfg)
|
|||
|
||||
const bool remove = utils::string_bool(cfg[z_remove], false);
|
||||
if (remove) {
|
||||
const std::vector<config::t_token> ids = utils::split_token(cfg[z_id]);
|
||||
const std::vector<config::t_token> ids = utils::split_attr(cfg[z_id]);
|
||||
foreach(const config::t_token &id, ids) {
|
||||
resources::tunnels->remove(id);
|
||||
}
|
||||
|
@ -872,12 +874,12 @@ WML_HANDLER_FUNCTION(volume, /*event_info*/, cfg)
|
|||
|
||||
int vol;
|
||||
float rel;
|
||||
config::t_token const & music = cfg[z_music];
|
||||
config::t_token const & sound = cfg[z_sound];
|
||||
config::attribute_value const & music = cfg[z_music];
|
||||
config::attribute_value const & sound = cfg[z_sound];
|
||||
|
||||
if(!music.empty()) {
|
||||
vol = preferences::music_volume();
|
||||
rel = atof(music.c_str());
|
||||
rel = atof(music.token().c_str());
|
||||
if (rel >= 0.0 && rel < 100.0) {
|
||||
vol = static_cast<int>(rel*vol/100.0);
|
||||
}
|
||||
|
@ -886,7 +888,7 @@ WML_HANDLER_FUNCTION(volume, /*event_info*/, cfg)
|
|||
|
||||
if(!sound.empty()) {
|
||||
vol = preferences::sound_volume();
|
||||
rel = atof(sound.c_str());
|
||||
rel = atof(sound.token().c_str());
|
||||
if (rel >= 0.0 && rel < 100.0) {
|
||||
vol = static_cast<int>(rel*vol/100.0);
|
||||
}
|
||||
|
@ -942,7 +944,7 @@ WML_HANDLER_FUNCTION(store_time_of_day, /*event_info*/, cfg)
|
|||
// using 0 will use the current turn
|
||||
const time_of_day& tod = resources::tod_manager->get_time_of_day_with_areas(loc,turn);
|
||||
|
||||
config::t_token variable = cfg[z_variable];
|
||||
config::attribute_value variable = cfg[z_variable];
|
||||
if(variable.empty()) {
|
||||
variable = z_time_of_day;
|
||||
}
|
||||
|
@ -990,18 +992,18 @@ WML_HANDLER_FUNCTION(modify_side, /*event_info*/, cfg)
|
|||
|
||||
std::vector<team> &teams = *resources::teams;
|
||||
|
||||
t_string const & team_name = cfg[z_team_name];
|
||||
t_string const & user_team_name = cfg[z_user_team_name];
|
||||
config::t_token const & controller = cfg[z_controller];
|
||||
config::t_token const & recruit_str = cfg[z_recruit];
|
||||
config::t_token const & shroud_data = cfg[z_shroud_data];
|
||||
config::attribute_value const & team_name = cfg[z_team_name];
|
||||
config::attribute_value const & user_team_name = cfg[z_user_team_name];
|
||||
config::attribute_value const & controller = cfg[z_controller];
|
||||
config::attribute_value const & recruit_str = cfg[z_recruit];
|
||||
config::attribute_value const & shroud_data = cfg[z_shroud_data];
|
||||
const config& parsed = cfg.get_parsed_config();
|
||||
const config::const_child_itors &ai = parsed.child_range(z_ai);
|
||||
/**
|
||||
* @todo also allow client to modify a side's color if it is possible
|
||||
* to change it on the fly without causing visual glitches
|
||||
*/
|
||||
config::t_token const & switch_ai = cfg[z_switch_ai];
|
||||
config::attribute_value const & switch_ai = cfg[z_switch_ai];
|
||||
|
||||
std::set<int> sides = game_events::get_sides_set(cfg);
|
||||
size_t team_index;
|
||||
|
@ -1012,14 +1014,14 @@ WML_HANDLER_FUNCTION(modify_side, /*event_info*/, cfg)
|
|||
LOG_NG << "modifying side: " << side_num << "\n";
|
||||
if(!team_name.empty()) {
|
||||
LOG_NG << "change side's team to team_name '" << team_name << "'\n";
|
||||
teams[team_index].change_team(team_name, user_team_name);
|
||||
teams[team_index].change_team(team_name.t_str(), user_team_name.t_str());
|
||||
} else if(!user_team_name.empty()) {
|
||||
LOG_NG << "change side's user_team_name to '" << user_team_name << "'\n";
|
||||
teams[team_index].change_team(teams[team_index].team_name(), user_team_name);
|
||||
teams[team_index].change_team(teams[team_index].team_name(), user_team_name.t_str());
|
||||
}
|
||||
// Modify recruit list (override)
|
||||
if (!recruit_str.empty()) {
|
||||
std::vector<config::t_token> recruit = utils::split_token(recruit_str);
|
||||
std::vector<config::t_token> recruit = utils::split_attr(recruit_str);
|
||||
if (recruit.size() == 1 && recruit.back() == n_token::t_token::z_empty())
|
||||
recruit.clear();
|
||||
|
||||
|
@ -1099,11 +1101,11 @@ WML_HANDLER_FUNCTION(modify_turns, /*event_info*/, cfg)
|
|||
static const config::t_token z_current("current", false);
|
||||
|
||||
config::attribute_value const & value = cfg[z_value];
|
||||
config::t_token const & add = cfg[z_add];
|
||||
config::attribute_value const & add = cfg[z_add];
|
||||
config::attribute_value const & current = cfg[z_current];
|
||||
tod_manager& tod_man = *resources::tod_manager;
|
||||
if(!add.empty()) {
|
||||
tod_man.modify_turns(add);
|
||||
tod_man.modify_turns(add.token());
|
||||
} else if(!value.empty()) {
|
||||
tod_man.set_number_of_turns(value.to_int(-1));
|
||||
}
|
||||
|
@ -1136,14 +1138,14 @@ game_display::fake_unit *create_fake_unit(const vconfig& cfg)
|
|||
static const config::t_token z_image_mod("image_mod", false);
|
||||
static const config::t_token z_add("add", false);
|
||||
|
||||
config::t_token const & type = cfg[z_type];
|
||||
config::t_token const & variation = cfg[z_variation];
|
||||
config::t_token const & img_mods = cfg[z_image_mods];
|
||||
config::attribute_value const & type = cfg[z_type];
|
||||
config::attribute_value const & variation = cfg[z_variation];
|
||||
config::attribute_value const & img_mods = cfg[z_image_mods];
|
||||
|
||||
size_t side_num = cfg[z_side].to_int(1) - 1;
|
||||
if (side_num >= resources::teams->size()) side_num = 0;
|
||||
|
||||
unit_race::GENDER gender = string_gender(cfg[z_gender]);
|
||||
unit_race::GENDER gender = string_gender(cfg[z_gender].token());
|
||||
const unit_type *ut = unit_types.find(type);
|
||||
if (!ut) return NULL;
|
||||
game_display::fake_unit * fake_unit = new game_display::fake_unit(unit(ut, side_num + 1, false, gender));
|
||||
|
@ -1240,11 +1242,11 @@ WML_HANDLER_FUNCTION(move_unit_fake, /*event_info*/, cfg)
|
|||
if(!dummy_unit.get())
|
||||
return;
|
||||
|
||||
const config::t_token & x = cfg[z_x];
|
||||
const config::t_token & y = cfg[z_y];
|
||||
const config::attribute_value & x = cfg[z_x];
|
||||
const config::attribute_value & y = cfg[z_y];
|
||||
|
||||
const std::vector<config::t_token> xvals = utils::split_token(x);
|
||||
const std::vector<config::t_token> yvals = utils::split_token(y);
|
||||
const std::vector<config::t_token> xvals = utils::split_attr(x);
|
||||
const std::vector<config::t_token> yvals = utils::split_attr(y);
|
||||
|
||||
const std::vector<map_location>& path = fake_unit_path(*dummy_unit, xvals, yvals);
|
||||
if (!path.empty())
|
||||
|
@ -1273,8 +1275,8 @@ WML_HANDLER_FUNCTION(move_units_fake, /*event_info*/, cfg)
|
|||
size_t longest_path = 0;
|
||||
|
||||
foreach(const vconfig& config, unit_cfgs) {
|
||||
const std::vector<config::t_token> xvals = utils::split_token(config[z_x]);
|
||||
const std::vector<config::t_token> yvals = utils::split_token(config[z_y]);
|
||||
const std::vector<config::t_token> xvals = utils::split_attr(config[z_x]);
|
||||
const std::vector<config::t_token> yvals = utils::split_attr(config[z_y]);
|
||||
int skip_steps = config[z_skip_steps];
|
||||
game_display::fake_unit *u = create_fake_unit(config);
|
||||
units[paths.size()].reset(u);
|
||||
|
@ -1344,7 +1346,7 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
|||
|
||||
game_state *state_of_game = resources::state_of_game;
|
||||
|
||||
const config::t_token & name = cfg[z_name];
|
||||
const config::attribute_value & name = cfg[z_name];
|
||||
if(name == z_empty){
|
||||
throw config::error("Mandatory WML variable name is empty \"\"."); }
|
||||
|
||||
|
@ -1360,7 +1362,7 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
|||
var = value;
|
||||
}
|
||||
|
||||
const config::t_token & to_variable = cfg[z_to_variable];
|
||||
const config::attribute_value & to_variable = cfg[z_to_variable];
|
||||
if(to_variable.empty() == false) {
|
||||
var = state_of_game->get_variable(to_variable);
|
||||
}
|
||||
|
@ -1437,7 +1439,7 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
|||
|
||||
// Note: maybe we add more options later, eg. strftime formatting.
|
||||
// For now make the stamp mandatory.
|
||||
const config::t_token & time = cfg[z_time];
|
||||
const config::attribute_value & time = cfg[z_time];
|
||||
if(time == z_stamp) {
|
||||
var = int(SDL_GetTicks());
|
||||
}
|
||||
|
@ -1447,7 +1449,7 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
|||
// Each element in the list will be considered a separate choice,
|
||||
// unless it contains "..". In this case, it must be a numerical
|
||||
// range (i.e. -1..-10, 0..100, -10..10, etc).
|
||||
const std::string & rand = cfg[z_rand].str();
|
||||
const std::string rand = cfg[z_rand].str();
|
||||
|
||||
// The new random generator, the logic is a copy paste of the old random.
|
||||
if(rand.empty() == false) {
|
||||
|
@ -1530,9 +1532,9 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
|||
{
|
||||
const vconfig join_element=join_elements.front();
|
||||
|
||||
config::t_token const & array_name=join_element[z_variable];
|
||||
config::t_token const & separator=join_element[z_separator];
|
||||
config::t_token key_name=join_element[z_key];
|
||||
config::attribute_value const & array_name=join_element[z_variable];
|
||||
config::attribute_value const & separator=join_element[z_separator];
|
||||
config::attribute_value key_name=join_element[z_key];
|
||||
|
||||
if(key_name.empty())
|
||||
{
|
||||
|
@ -1547,11 +1549,11 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
|||
bool first = true;
|
||||
foreach (const config &cfg, vi.as_array())
|
||||
{
|
||||
config::t_token const & current_string = cfg[key_name];
|
||||
config::attribute_value const & current_string = cfg[key_name];
|
||||
if (remove_empty && current_string.empty()) continue;
|
||||
if (first) first = false;
|
||||
else joined_string += (*separator);
|
||||
joined_string += (*current_string);
|
||||
else joined_string += separator.str();
|
||||
joined_string += current_string.str();
|
||||
}
|
||||
|
||||
var=joined_string;
|
||||
|
@ -1581,7 +1583,7 @@ WML_HANDLER_FUNCTION(set_variables, /*event_info*/, cfg)
|
|||
const config::attribute_value & name = cfg[z_name];
|
||||
variable_info dest(name, true, variable_info::TYPE_CONTAINER);
|
||||
|
||||
config::t_token mode = cfg[z_mode]; // replace, append, merge, or insert
|
||||
config::attribute_value mode = cfg[z_mode]; // replace, append, merge, or insert
|
||||
if(mode == z_extend) {
|
||||
mode = z_append;
|
||||
} else if(mode != z_append && mode != z_merge) {
|
||||
|
@ -1633,9 +1635,10 @@ WML_HANDLER_FUNCTION(set_variables, /*event_info*/, cfg)
|
|||
} else if(!split_elements.empty()) {
|
||||
const vconfig split_element=split_elements.front();
|
||||
|
||||
config::t_token const & split_string=split_element[z_list];
|
||||
config::t_token const & separator_string=split_element[z_separator];
|
||||
config::t_token key_name=split_element[z_key];
|
||||
config::attribute_value const & asplit_string=split_element[z_list];
|
||||
config::t_token const & split_string=asplit_string.token();
|
||||
config::attribute_value const & separator_string=split_element[z_separator];
|
||||
config::attribute_value key_name=split_element[z_key];
|
||||
if(key_name.empty())
|
||||
{
|
||||
key_name = z_value;
|
||||
|
@ -1643,7 +1646,7 @@ WML_HANDLER_FUNCTION(set_variables, /*event_info*/, cfg)
|
|||
|
||||
bool remove_empty = split_element[z_remove_empty].to_bool();
|
||||
|
||||
char const * separator = separator_string.empty() ? NULL : &(*separator_string)[0];
|
||||
char const * separator = separator_string.empty() ? NULL : &(separator_string.str())[0];
|
||||
|
||||
std::vector<config::t_token> split_vector;
|
||||
|
||||
|
@ -1711,7 +1714,7 @@ WML_HANDLER_FUNCTION(role, /*event_info*/, cfg)
|
|||
vconfig filter(item);
|
||||
|
||||
// try to match units on the gamemap before the recall lists
|
||||
std::vector<config::t_token> types = utils::split_token(filter[z_type]);
|
||||
std::vector<config::t_token> types = utils::split_attr(filter[z_type]);
|
||||
const bool has_any_types = !types.empty();
|
||||
std::vector<config::t_token>::iterator ti = types.begin(),
|
||||
ti_end = types.end();
|
||||
|
@ -1732,7 +1735,7 @@ WML_HANDLER_FUNCTION(role, /*event_info*/, cfg)
|
|||
if(!found) {
|
||||
// next try to match units on the recall lists
|
||||
std::set<config::t_token> player_ids;
|
||||
std::vector<config::t_token> sides = utils::split_token(cfg[z_side]);
|
||||
std::vector<config::t_token> sides = utils::split_attr(cfg[z_side]);
|
||||
const bool has_any_sides = !sides.empty();
|
||||
foreach(config::t_token const& side_str, sides) {
|
||||
size_t side_num = lexical_cast_default<size_t>(side_str,0);
|
||||
|
@ -1969,14 +1972,14 @@ WML_HANDLER_FUNCTION(object, event_info, cfg)
|
|||
|
||||
const vconfig filter = cfg.child(z_filter);
|
||||
|
||||
config::t_token const &id = cfg[z_id];
|
||||
config::attribute_value const &id = cfg[z_id];
|
||||
|
||||
// If this item has already been used
|
||||
if(id != n_token::t_token::z_empty() && used_items.count(id))
|
||||
if(id != n_token::t_token::z_empty() && used_items.count(id.token()))
|
||||
return;
|
||||
|
||||
config::t_token const & image = cfg[z_image];
|
||||
config::t_token const & caption = cfg[z_name];
|
||||
config::attribute_value const & image = cfg[z_image];
|
||||
config::attribute_value const & caption = cfg[z_name];
|
||||
config::t_token text;
|
||||
|
||||
map_location loc;
|
||||
|
@ -1999,7 +2002,7 @@ WML_HANDLER_FUNCTION(object, event_info, cfg)
|
|||
|
||||
if (u != resources::units->end() && (filter.null() || game_events::unit_matches_filter(*u, filter)))
|
||||
{
|
||||
text = cfg[z_description];
|
||||
text = cfg[z_description].token();
|
||||
|
||||
u->add_modification(z_object, cfg.get_parsed_config());
|
||||
|
||||
|
@ -2007,9 +2010,9 @@ WML_HANDLER_FUNCTION(object, event_info, cfg)
|
|||
resources::screen->invalidate_unit();
|
||||
|
||||
// Mark this item as used up.
|
||||
used_items.insert(id);
|
||||
used_items.insert(id.token());
|
||||
} else {
|
||||
text = cfg[z_cannot_use_message];
|
||||
text = cfg[z_cannot_use_message].token();
|
||||
command_type = z_else;
|
||||
}
|
||||
|
||||
|
@ -2199,8 +2202,8 @@ WML_HANDLER_FUNCTION(kill, event_info, cfg)
|
|||
|
||||
// If the filter doesn't contain positional information,
|
||||
// then it may match units on all recall lists.
|
||||
t_string const cfg_x = cfg[z_x];
|
||||
t_string const cfg_y = cfg[z_y];
|
||||
config::attribute_value const cfg_x = cfg[z_x];
|
||||
config::attribute_value const cfg_y = cfg[z_y];
|
||||
if((cfg_x.empty() || cfg_x == z_recall)
|
||||
&& (cfg_y.empty() || cfg_y == z_recall))
|
||||
{
|
||||
|
@ -2251,7 +2254,7 @@ WML_HANDLER_FUNCTION(set_menu_item, /*event_info*/, cfg)
|
|||
static const config::t_token z_filter_location("filter_location", false);
|
||||
static const config::t_token z_command("command", false);
|
||||
|
||||
config::t_token const & id = cfg[z_id];
|
||||
config::attribute_value const & id = cfg[z_id];
|
||||
wml_menu_item*& mref = resources::state_of_game->wml_menu_items[id];
|
||||
if(mref == NULL) {
|
||||
mref = new wml_menu_item(id);
|
||||
|
@ -2260,7 +2263,7 @@ WML_HANDLER_FUNCTION(set_menu_item, /*event_info*/, cfg)
|
|||
mref->image = cfg[z_image].str();
|
||||
}
|
||||
if(cfg.has_attribute(z_description)) {
|
||||
mref->description = cfg[z_description];
|
||||
mref->description = cfg[z_description].t_str();
|
||||
}
|
||||
if(cfg.has_attribute(z_needs_select)) {
|
||||
mref->needs_select = cfg[z_needs_select].to_bool();
|
||||
|
@ -2356,7 +2359,7 @@ WML_HANDLER_FUNCTION(unstore_unit, /*event_info*/, cfg)
|
|||
resources::units->erase(loc);
|
||||
resources::units->add(loc, u);
|
||||
|
||||
config::t_token const &text = cfg[z_text];
|
||||
config::attribute_value const &text = cfg[z_text];
|
||||
play_controller *controller = resources::controller;
|
||||
if(!text.empty() && !controller->is_skipping_replay())
|
||||
{
|
||||
|
@ -2451,7 +2454,7 @@ WML_HANDLER_FUNCTION(store_starting_location, /*event_info*/, cfg)
|
|||
static const config::t_token z_side("side", false);
|
||||
static const config::t_token z_owner_side("owner_side", false);
|
||||
|
||||
config::t_token variable = cfg[z_variable];
|
||||
config::attribute_value variable = cfg[z_variable];
|
||||
if (variable.empty()) {
|
||||
variable=z_location;
|
||||
}
|
||||
|
@ -2482,7 +2485,7 @@ WML_HANDLER_FUNCTION(store_villages, /*event_info*/, cfg)
|
|||
static const config::t_token z_owner_side("owner_side", false);
|
||||
|
||||
log_scope(z_store_villages);
|
||||
config::t_token variable = cfg[z_variable];
|
||||
config::attribute_value variable = cfg[z_variable];
|
||||
if (variable.empty()) {
|
||||
variable=z_location;
|
||||
}
|
||||
|
@ -2544,14 +2547,14 @@ WML_HANDLER_FUNCTION(endlevel, /*event_info*/, cfg)
|
|||
}
|
||||
}
|
||||
|
||||
config::t_token const & next_scenario = cfg[z_next_scenario];
|
||||
config::attribute_value const & next_scenario = cfg[z_next_scenario];
|
||||
if (!next_scenario.empty()) {
|
||||
state_of_game->classification().next_scenario = next_scenario;
|
||||
state_of_game->classification().next_scenario = next_scenario.token();
|
||||
}
|
||||
|
||||
config::t_token const & end_of_campaign_text = cfg[z_end_text];
|
||||
config::attribute_value const & end_of_campaign_text = cfg[z_end_text];
|
||||
if (!end_of_campaign_text.empty()) {
|
||||
state_of_game->classification().end_text = end_of_campaign_text;
|
||||
state_of_game->classification().end_text = end_of_campaign_text.token();
|
||||
}
|
||||
|
||||
config::attribute_value end_of_campaign_text_delay = cfg[z_end_text_duration];
|
||||
|
@ -2562,11 +2565,11 @@ WML_HANDLER_FUNCTION(endlevel, /*event_info*/, cfg)
|
|||
|
||||
end_level_data &data = resources::controller->get_end_level_data();
|
||||
|
||||
config::t_token const & result = cfg[z_result];
|
||||
config::attribute_value const & result = cfg[z_result];
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
result.empty() || result == z_victory || result == z_defeat
|
||||
result.empty() || result.token() == z_victory || result.token() == z_defeat
|
||||
, _("Invalid value in the result key for [end_level]")
|
||||
, "result = '" + (*result) + "'.");
|
||||
, "result = '" + (*result.token()) + "'.");
|
||||
data.custom_endlevel_music = cfg[z_music].str();
|
||||
data.carryover_report = cfg[z_carryover_report].to_bool(true);
|
||||
data.prescenario_save = cfg[z_save].to_bool(true);
|
||||
|
@ -2717,8 +2720,8 @@ WML_HANDLER_FUNCTION(open_help, /*event_info*/, cfg)
|
|||
static const config::t_token z_topic("topic", false);
|
||||
|
||||
game_display &screen = *resources::screen;
|
||||
t_string topic_id = cfg[z_topic];
|
||||
help::show_help(screen, topic_id.to_serialized());
|
||||
config::attribute_value topic_id = cfg[z_topic];
|
||||
help::show_help(screen, topic_id.t_str().to_serialized());
|
||||
}
|
||||
// Helper namespace to do some subparts for message function
|
||||
namespace {
|
||||
|
@ -2745,7 +2748,7 @@ unit_map::iterator handle_speaker(
|
|||
game_display &screen = *resources::screen;
|
||||
|
||||
unit_map::iterator speaker = units->end();
|
||||
config::t_token const & speaker_str = cfg[z_speaker];
|
||||
config::attribute_value const & speaker_str = cfg[z_speaker];
|
||||
|
||||
if(speaker_str == z_unit) {
|
||||
speaker = units->find(event_info.loc1);
|
||||
|
@ -2791,7 +2794,7 @@ config::t_token get_image(const vconfig& cfg, unit_map::iterator speaker)
|
|||
{
|
||||
static const config::t_token z_image("image", false);
|
||||
|
||||
config::t_token image = cfg[z_image];
|
||||
config::attribute_value image = cfg[z_image];
|
||||
if (image.empty() && speaker != resources::units->end())
|
||||
{
|
||||
image = speaker->big_profile();
|
||||
|
@ -2801,7 +2804,7 @@ config::t_token get_image(const vconfig& cfg, unit_map::iterator speaker)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
return image;
|
||||
return image.token();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2816,14 +2819,14 @@ config::t_token get_caption(const vconfig& cfg, unit_map::iterator speaker)
|
|||
{
|
||||
static const config::t_token z_caption("caption", false);
|
||||
|
||||
config::t_token caption = cfg[z_caption];
|
||||
config::attribute_value caption = cfg[z_caption];
|
||||
if (caption.empty() && speaker != resources::units->end()) {
|
||||
caption = speaker->name().token();
|
||||
if(caption.empty()) {
|
||||
caption = speaker->type_name().token();
|
||||
}
|
||||
}
|
||||
return caption;
|
||||
return caption.token();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -2860,7 +2863,7 @@ struct message_user_choice : mp_sync::user_choice
|
|||
}
|
||||
|
||||
// Parse input text, if not available all fields are empty
|
||||
config::t_token const & text_input_label = text_input_element[z_label];
|
||||
config::attribute_value const & text_input_label = text_input_element[z_label];
|
||||
//gui2 saves a pointer to this string? odd
|
||||
std::string text_input_content = text_input_element[z_text];
|
||||
unsigned input_max_size = text_input_element[z_max_length].to_int(256);
|
||||
|
@ -2942,18 +2945,18 @@ WML_HANDLER_FUNCTION(message, event_info, cfg)
|
|||
}
|
||||
|
||||
// Check if this message is for this side
|
||||
config::t_token const & side_for_raw = cfg[z_side_for];
|
||||
config::attribute_value const & side_for_raw = cfg[z_side_for];
|
||||
if (!side_for_raw.empty())
|
||||
{
|
||||
/* Always ignore side_for when the message has some input
|
||||
boxes, but display the error message only if side_for is
|
||||
used for an inactive side. */
|
||||
bool side_for_show = has_input;
|
||||
if (has_input && (*side_for_raw) != str_cast(resources::controller->current_side()))
|
||||
if (has_input && (*side_for_raw.token()) != str_cast(resources::controller->current_side()))
|
||||
lg::wml_error << "[message]side_for= cannot query any user input out of turn.\n";
|
||||
|
||||
std::vector<config::t_token> side_for =
|
||||
utils::split_token(side_for_raw, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY);
|
||||
utils::split_attr(side_for_raw, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY);
|
||||
std::vector<config::t_token>::iterator itSide;
|
||||
size_t side;
|
||||
|
||||
|
@ -2990,11 +2993,11 @@ WML_HANDLER_FUNCTION(message, event_info, cfg)
|
|||
|
||||
for(vconfig::child_list::const_iterator mi = menu_items.begin();
|
||||
mi != menu_items.end(); ++mi) {
|
||||
config::t_token const & msg_str = (*mi)[z_message];
|
||||
config::attribute_value const & msg_str = (*mi)[z_message];
|
||||
if (!mi->has_child(z_show_if)
|
||||
|| game_events::conditional_passed(mi->child(z_show_if)))
|
||||
{
|
||||
options.push_back(msg_str);
|
||||
options.push_back(msg_str.token());
|
||||
option_events.push_back((*mi).get_children(z_command));
|
||||
}
|
||||
}
|
||||
|
@ -3051,7 +3054,7 @@ WML_HANDLER_FUNCTION(message, event_info, cfg)
|
|||
}
|
||||
}
|
||||
if(has_text_input) {
|
||||
config::t_token variable_name=text_input_element[z_variable];
|
||||
config::attribute_value variable_name=text_input_element[z_variable];
|
||||
if(variable_name.empty())
|
||||
variable_name=z_input;
|
||||
resources::state_of_game->set_variable(variable_name, t_string(text_input_result));
|
||||
|
@ -3068,11 +3071,11 @@ WML_HANDLER_FUNCTION(time_area, /*event_info*/, cfg)
|
|||
log_scope(z_time_area);
|
||||
|
||||
bool remove = cfg[z_remove].to_bool();
|
||||
config::t_token const & ids = cfg[z_id];
|
||||
config::attribute_value const & ids = cfg[z_id];
|
||||
|
||||
if(remove) {
|
||||
const std::vector<config::t_token> id_list =
|
||||
utils::split_token(ids, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY);
|
||||
utils::split_attr(ids, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY);
|
||||
foreach(const config::t_token& id, id_list) {
|
||||
resources::tod_manager->remove_time_area(id);
|
||||
LOG_NG << "event WML removed time_area '" << id << "'\n";
|
||||
|
@ -3080,7 +3083,7 @@ WML_HANDLER_FUNCTION(time_area, /*event_info*/, cfg)
|
|||
}
|
||||
else {
|
||||
config::t_token id;
|
||||
id = utils::split_token(ids,',',utils::STRIP_SPACES | utils::REMOVE_EMPTY).front();
|
||||
id = utils::split_attr(ids,',',utils::STRIP_SPACES | utils::REMOVE_EMPTY).front();
|
||||
// if(ids.find(',') != std::string::npos) {
|
||||
// id = utils::split_token(ids,',',utils::STRIP_SPACES | utils::REMOVE_EMPTY).front();
|
||||
// ERR_NG << "multiple ids for inserting a new time_area; will use only the first\n";
|
||||
|
@ -3129,7 +3132,7 @@ WML_HANDLER_FUNCTION(event, /*event_info*/, cfg)
|
|||
static const config::t_token z_delayed_variable_substitution("delayed_variable_substitution", false);
|
||||
|
||||
if (cfg[z_remove].to_bool(false)) {
|
||||
event_handlers.remove_event_handler(cfg[z_id]);
|
||||
event_handlers.remove_event_handler(cfg[z_id].token());
|
||||
} else if (!cfg[z_delayed_variable_substitution].to_bool(true)) {
|
||||
event_handlers.add_event_handler(game_events::event_handler(cfg.get_parsed_config()));
|
||||
} else {
|
||||
|
@ -3394,16 +3397,13 @@ namespace game_events {
|
|||
handle_event_commands(event_info, vconfig(cfg_));
|
||||
}
|
||||
|
||||
void handle_event_commands(const game_events::queued_event& event_info, const vconfig &cfg)
|
||||
{
|
||||
static const config::t_token z_command("command", false);
|
||||
|
||||
void handle_event_commands(const game_events::queued_event& event_info, const vconfig &cfg) {
|
||||
static const config::t_token z_command("command", false);
|
||||
resources::lua_kernel->run_wml_action(z_command, cfg, event_info);
|
||||
}
|
||||
|
||||
void handle_event_command(const config::t_token &cmd,
|
||||
const game_events::queued_event &event_info, const vconfig &cfg)
|
||||
{
|
||||
const game_events::queued_event &event_info, const vconfig &cfg) {
|
||||
log_scope2(log_engine, "handle_event_command");
|
||||
LOG_NG << "handling command '" << cmd << "' from "
|
||||
<< (cfg.is_volatile()?"volatile ":"") << "cfg 0x"
|
||||
|
@ -3423,7 +3423,7 @@ namespace game_events {
|
|||
static const config::t_token z_name("name", false);
|
||||
|
||||
std::string const & name(tname);
|
||||
const t_string& t_my_names = cfg_[z_name];
|
||||
const config::attribute_value& t_my_names = cfg_[z_name];
|
||||
const std::string& my_names = t_my_names;
|
||||
std::string::const_iterator itor,
|
||||
it_begin = my_names.begin(),
|
||||
|
@ -3541,7 +3541,7 @@ namespace game_events {
|
|||
foreach (const config &ev, cfg.child_range(z_event)) {
|
||||
event_handlers.add_event_handler(game_events::event_handler(ev));
|
||||
}
|
||||
foreach (const config::t_token &id, utils::split_token(cfg[z_unit_wml_ids])) {
|
||||
foreach (const config::t_token &id, utils::split_attr(cfg[z_unit_wml_ids])) {
|
||||
unit_wml_ids.insert(id);
|
||||
}
|
||||
|
||||
|
@ -3552,9 +3552,9 @@ namespace game_events {
|
|||
resources::lua_kernel->set_wml_action(action.first, action.second);
|
||||
}
|
||||
|
||||
config::t_token const & used = cfg[z_used_items];
|
||||
config::attribute_value const & used = cfg[z_used_items];
|
||||
if(!used.empty()) {
|
||||
const std::vector<config::t_token>& v = utils::split_token(used);
|
||||
const std::vector<config::t_token>& v = utils::split_attr(used);
|
||||
for(std::vector<config::t_token>::const_iterator i = v.begin(); i != v.end(); ++i) {
|
||||
used_items.insert(*i);
|
||||
}
|
||||
|
|
|
@ -541,16 +541,16 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
|
|||
|
||||
if (side[z_canrecruit].to_bool())
|
||||
{
|
||||
leader = side[z_id];
|
||||
leader_image = side[z_image];
|
||||
break;
|
||||
leader = side[z_id].token();
|
||||
leader_image = side[z_image].token();
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (const config &u, side.child_range(z_unit))
|
||||
{
|
||||
if (u[z_canrecruit].to_bool()) {
|
||||
leader = u[z_id];
|
||||
leader_image = u[z_image];
|
||||
leader = u[z_id].token();
|
||||
leader_image = u[z_image].token();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ std::vector<ttip> load(const config& cfg)
|
|||
std::vector<ttip> result;
|
||||
|
||||
foreach(const config &tip, cfg.child_range("tip")) {
|
||||
result.push_back(ttip(tip["text"]
|
||||
, tip["source"]
|
||||
, tip["encountered_units"]));
|
||||
result.push_back(ttip(tip["text"].t_str()
|
||||
, tip["source"].t_str()
|
||||
, tip["encountered_units"].t_str()));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -59,7 +59,7 @@ tbuilder_horizontal_listbox::tbuilder_horizontal_listbox(const config& cfg)
|
|||
foreach(const config &c, row.child_range("column")) {
|
||||
list_data.push_back(string_map());
|
||||
foreach (const config::attribute &i, c.attribute_range()) {
|
||||
list_data.back()[i.first] = i.second;
|
||||
list_data.back()[i.first] = i.second.t_str();
|
||||
}
|
||||
++col;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ tbuilder_listbox::tbuilder_listbox(const config& cfg)
|
|||
foreach(const config& c, row.child_range("column")) {
|
||||
list_data.push_back(string_map());
|
||||
foreach(const config::attribute& i, c.attribute_range()) {
|
||||
list_data.back()[i.first] = i.second;
|
||||
list_data.back()[i.first] = i.second.token();
|
||||
}
|
||||
++col;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ tbuilder_multi_page::tbuilder_multi_page(const config& cfg)
|
|||
foreach(const config &column, row.child_range("column")) {
|
||||
data.push_back(string_map());
|
||||
foreach(const config::attribute &i, column.attribute_range()) {
|
||||
data.back()[i.first] = i.second;
|
||||
data.back()[i.first] = i.second.token();
|
||||
}
|
||||
++col;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ tbuilder_slider::tbuilder_slider(const config& cfg)
|
|||
}
|
||||
|
||||
foreach(const config& label, labels.child_range("value")) {
|
||||
value_labels_.push_back(label["label"]);
|
||||
value_labels_.push_back(label["label"].t_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ void taddon_list::pre_show(CVideo& /*video*/, twindow& window)
|
|||
std::map<std::string, string_map> data;
|
||||
string_map item;
|
||||
|
||||
item["label"] = c["icon"];
|
||||
item["label"] = c["icon"].token();
|
||||
data.insert(std::make_pair("icon", item));
|
||||
|
||||
std::string tmp = c["name"];
|
||||
|
@ -92,10 +92,10 @@ void taddon_list::pre_show(CVideo& /*video*/, twindow& window)
|
|||
item["label"] = tmp;
|
||||
data.insert(std::make_pair("author", item));
|
||||
|
||||
item["label"] = c["downloads"];
|
||||
item["label"] = c["downloads"].token();
|
||||
data.insert(std::make_pair("downloads", item));
|
||||
|
||||
item["label"] = c["size"];
|
||||
item["label"] = c["size"].token();
|
||||
data.insert(std::make_pair("size", item));
|
||||
|
||||
list.add_row(data);
|
||||
|
|
|
@ -143,10 +143,10 @@ void tcampaign_selection::pre_show(CVideo& /*video*/, twindow& window)
|
|||
foreach(const config &campaign, campaigns_) {
|
||||
|
||||
/*** Add tree item ***/
|
||||
tree_group_field["label"] = campaign["icon"];
|
||||
tree_group_field["label"] = campaign["icon"].token();
|
||||
tree_group_item["icon"] = tree_group_field;
|
||||
|
||||
tree_group_field["label"] = campaign["name"];
|
||||
tree_group_field["label"] = campaign["name"].token();
|
||||
tree_group_item["name"] = tree_group_field;
|
||||
|
||||
if (campaign["completed"].to_bool()) {
|
||||
|
@ -161,11 +161,11 @@ void tcampaign_selection::pre_show(CVideo& /*video*/, twindow& window)
|
|||
string_map detail_item;
|
||||
std::map<std::string, string_map> detail_page;
|
||||
|
||||
detail_item["label"] = campaign["description"];
|
||||
detail_item["label"] = campaign["description"].token();
|
||||
detail_item["use_markup"] = "true";
|
||||
detail_page.insert(std::make_pair("description", detail_item));
|
||||
|
||||
detail_item["label"] = campaign["image"];
|
||||
detail_item["label"] = campaign["image"].token();
|
||||
detail_page.insert(std::make_pair("image", detail_item));
|
||||
|
||||
multi_page.add_page(detail_page);
|
||||
|
@ -212,10 +212,10 @@ void tcampaign_selection::pre_show(CVideo& /*video*/, twindow& window)
|
|||
string_map list_item;
|
||||
std::map<std::string, string_map> list_item_item;
|
||||
|
||||
list_item["label"] = c["icon"];
|
||||
list_item["label"] = c["icon"].token();
|
||||
list_item_item.insert(std::make_pair("icon", list_item));
|
||||
|
||||
list_item["label"] = c["name"];
|
||||
list_item["label"] = c["name"].token();
|
||||
list_item_item.insert(std::make_pair("name", list_item));
|
||||
|
||||
list.add_row(list_item_item);
|
||||
|
@ -232,11 +232,11 @@ void tcampaign_selection::pre_show(CVideo& /*video*/, twindow& window)
|
|||
string_map detail_item;
|
||||
std::map<std::string, string_map> detail_page;
|
||||
|
||||
detail_item["label"] = c["description"];
|
||||
detail_item["label"] = c["description"].token();
|
||||
detail_item["use_markup"] = "true";
|
||||
detail_page.insert(std::make_pair("description", detail_item));
|
||||
|
||||
detail_item["label"] = c["image"];
|
||||
detail_item["label"] = c["image"].token();
|
||||
detail_page.insert(std::make_pair("image", detail_item));
|
||||
|
||||
multi_page.add_page(detail_page);
|
||||
|
|
|
@ -248,7 +248,7 @@ void tgame_load::display_savegame(twindow& window)
|
|||
}
|
||||
|
||||
find_widget<timage>(&window, "imgLeader", false).
|
||||
set_label(cfg_summary["leader_image"]);
|
||||
set_label(cfg_summary["leader_image"].t_str());
|
||||
|
||||
find_widget<tminimap>(&window, "minimap", false).
|
||||
set_map_data(cfg_summary["map_data"]);
|
||||
|
@ -286,7 +286,7 @@ void tgame_load::evaluate_summary_string(std::stringstream& str
|
|||
}
|
||||
utils::string_map symbols;
|
||||
if (campaign != NULL) {
|
||||
symbols["campaign_name"] = (*campaign)["name"];
|
||||
symbols["campaign_name"] = (*campaign)["name"].token();
|
||||
} else {
|
||||
// Fallback to nontranslatable campaign id.
|
||||
symbols["campaign_name"] = "(" + campaign_id + ")";
|
||||
|
|
|
@ -193,7 +193,7 @@ game_info::game_info(const config& game, const config& game_config)
|
|||
{
|
||||
const config &era_cfg = game_config.find_child("era", "id", game["mp_era"]);
|
||||
utils::string_map symbols;
|
||||
symbols["era_id"] = game["mp_era"];
|
||||
symbols["era_id"] = game["mp_era"].token();
|
||||
if (era_cfg) {
|
||||
era = era_cfg["name"].str();
|
||||
era_short = era_cfg["short_name"].str();
|
||||
|
@ -270,7 +270,7 @@ game_info::game_info(const config& game, const config& game_config)
|
|||
}
|
||||
} else {
|
||||
utils::string_map symbols;
|
||||
symbols["scenario_id"] = game["mp_scenario"];
|
||||
symbols["scenario_id"] = game["mp_scenario"].token();
|
||||
scenario = vgettext("Unknown scenario: $scenario_id", symbols);
|
||||
map_info += scenario;
|
||||
verified = false;
|
||||
|
@ -298,7 +298,7 @@ game_info::game_info(const config& game, const config& game_config)
|
|||
started = false;
|
||||
if (vacant_slots > 0) {
|
||||
status = std::string(_n("Vacant Slot:", "Vacant Slots:",
|
||||
vacant_slots)) + " " + game["slots"];
|
||||
vacant_slots)) + " " + game["slots"].str();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -267,7 +267,7 @@ const std::string& tgui_definition::read(const config& cfg)
|
|||
* @end{parent}{name="/"}
|
||||
*/
|
||||
id = cfg["id"].str();
|
||||
description = cfg["description"];
|
||||
description = cfg["description"].token();
|
||||
|
||||
VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id"));
|
||||
VALIDATE(!description.empty(), missing_mandatory_wml_key("gui", "description"));
|
||||
|
@ -394,7 +394,7 @@ const std::string& tgui_definition::read(const config& cfg)
|
|||
sound_toggle_panel_click_ = settings["sound_toggle_panel_click"].str();
|
||||
sound_slider_adjust_ = settings["sound_slider_adjust"].str();
|
||||
|
||||
has_helptip_message_ = settings["has_helptip_message"];
|
||||
has_helptip_message_ = settings["has_helptip_message"].token();
|
||||
|
||||
VALIDATE(!has_helptip_message_.empty(),
|
||||
missing_mandatory_wml_key("[settings]", "has_helptip_message"));
|
||||
|
|
|
@ -104,8 +104,8 @@ bool load_language_list()
|
|||
foreach (const config &lang, cfg.child_range("locale"))
|
||||
{
|
||||
known_languages.push_back(
|
||||
language_def(lang["locale"], lang["name"], lang["dir"],
|
||||
lang["alternates"], lang["sort_name"]));
|
||||
language_def(lang["locale"].str(), lang["name"].t_str(), lang["dir"].str(),
|
||||
lang["alternates"].str(), lang["sort_name"].str()));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -230,7 +230,7 @@ bool load_strings(bool complain)
|
|||
DBG_G << "[language]\n";
|
||||
foreach (const config::attribute &j, lang.attribute_range()) {
|
||||
DBG_G << j.first << "=\"" << j.second << "\"\n";
|
||||
strings_[j.first] = j.second;
|
||||
strings_[j.first] = j.second.token();
|
||||
}
|
||||
DBG_G << "[/language]\n";
|
||||
}
|
||||
|
@ -285,8 +285,8 @@ void init_textdomains(const config& cfg)
|
|||
{
|
||||
foreach (const config &t, cfg.child_range("textdomain"))
|
||||
{
|
||||
const std::string &name = t["name"];
|
||||
const std::string &path = t["path"];
|
||||
const std::string name = t["name"];
|
||||
const std::string path = t["path"];
|
||||
|
||||
if(path.empty()) {
|
||||
t_string::add_textdomain(name, get_intl_dir());
|
||||
|
|
|
@ -310,7 +310,7 @@ void terrain_label::read(const config &cfg)
|
|||
|
||||
std::string tmp_color = cfg["color"];
|
||||
|
||||
text_ = cfg["text"];
|
||||
text_ = cfg["text"].token();
|
||||
team_name_ = cfg["team_name"].str();
|
||||
visible_in_fog_ = cfg["visible_in_fog"].to_bool(true);
|
||||
visible_in_shroud_ = cfg["visible_in_shroud"].to_bool();
|
||||
|
|
|
@ -1101,7 +1101,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
// '\' will be used if the road is going south east-north west
|
||||
// The terrain will be left unchanged otherwise
|
||||
// (if there is no clear direction).
|
||||
const std::string &convert_to_bridge = child["convert_to_bridge"];
|
||||
const std::string convert_to_bridge = child["convert_to_bridge"];
|
||||
if(convert_to_bridge.empty() == false) {
|
||||
if(step == rt.steps.begin() || step+1 == rt.steps.end())
|
||||
continue;
|
||||
|
@ -1152,7 +1152,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
}
|
||||
|
||||
// Just a plain terrain substitution for a road
|
||||
const std::string &convert_to = child["convert_to"];
|
||||
const std::string convert_to = child["convert_to"];
|
||||
if(convert_to.empty() == false) {
|
||||
const t_translation::t_terrain letter =
|
||||
t_translation::read_terrain_code(convert_to);
|
||||
|
@ -1305,7 +1305,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
t_translation::write_terrain_code(terrain[res.x][res.y]);
|
||||
if (const config &child = cfg.find_child("village", "terrain", str))
|
||||
{
|
||||
const std::string &convert_to = child["convert_to"];
|
||||
const std::string convert_to = child["convert_to"];
|
||||
if(convert_to != "") {
|
||||
terrain[res.x][res.y] =
|
||||
t_translation::read_terrain_code(convert_to);
|
||||
|
|
|
@ -3318,7 +3318,7 @@ void console_handler::do_choose_level() {
|
|||
int next = 0, nb = 0;
|
||||
foreach (const config &sc, menu_handler_.game_config_.child_range("scenario"))
|
||||
{
|
||||
const std::string &id = sc["id"];
|
||||
const std::string id = sc["id"];
|
||||
options.push_back(id);
|
||||
if (id == menu_handler_.gamestate_.classification().next_scenario)
|
||||
next = nb;
|
||||
|
@ -3331,7 +3331,7 @@ void console_handler::do_choose_level() {
|
|||
{
|
||||
if (mp["id"] == scenario)
|
||||
{
|
||||
const std::string &id = mp["id"];
|
||||
const std::string id = mp["id"];
|
||||
options.push_back(id);
|
||||
if (id == menu_handler_.gamestate_.classification().next_scenario)
|
||||
next = nb;
|
||||
|
|
|
@ -168,7 +168,7 @@ connect::side::side(connect& parent, const config& cfg, int index) :
|
|||
team_ = itor - parent_->team_names_.begin();
|
||||
}
|
||||
if (cfg.has_attribute("color")) {
|
||||
color_ = game_config::color_info(cfg["color"]).index() - 1;
|
||||
color_ = game_config::color_info(cfg["color"].token()).index() - 1;
|
||||
}
|
||||
llm_.set_color(color_);
|
||||
|
||||
|
@ -641,7 +641,7 @@ config connect::side::get_config() const
|
|||
if (allow_player_) {
|
||||
const config &ai_cfg = ai::configuration::get_ai_config_for(ai_algorithm_);
|
||||
res.add_child("ai",ai_cfg);
|
||||
symbols["playername"] = ai_cfg["description"];
|
||||
symbols["playername"] = ai_cfg["description"].token();
|
||||
} else { // do not import default ai cfg here - all is set by scenario config
|
||||
symbols["playername"] = _("Computer Player");
|
||||
}
|
||||
|
@ -668,9 +668,9 @@ config connect::side::get_config() const
|
|||
}
|
||||
res["user_description"] = t_string(description, "wesnoth");
|
||||
} else {
|
||||
res["player_id"] = player_id_ + res["side"];
|
||||
res["player_id"] = player_id_ + res["side"].str();
|
||||
if (enabled_ && !cfg_.has_attribute("save_id")) {
|
||||
res["save_id"] = player_id_ + res["side"];
|
||||
res["save_id"] = player_id_ + res["side"].str();
|
||||
}
|
||||
|
||||
res["user_description"] = player_id_;
|
||||
|
@ -963,7 +963,7 @@ void connect::side::resolve_random()
|
|||
leader_ = types[lchoice];
|
||||
} else {
|
||||
utils::string_map i18n_symbols;
|
||||
i18n_symbols["faction"] = fact["name"];
|
||||
i18n_symbols["faction"] = fact["name"].token();
|
||||
throw config::error(vgettext("Unable to find a leader type for faction $faction", i18n_symbols));
|
||||
}
|
||||
}
|
||||
|
@ -1373,7 +1373,7 @@ void connect::process_network_data(const config& data, const network::connection
|
|||
|
||||
if (const config &c = data.child("observer"))
|
||||
{
|
||||
const t_string &observer_name = c["name"];
|
||||
const config::attribute_value &observer_name = c["name"];
|
||||
if(!observer_name.empty()) {
|
||||
connected_user_list::iterator player = find_player(observer_name);
|
||||
if(player == users_.end()) {
|
||||
|
@ -1386,7 +1386,7 @@ void connect::process_network_data(const config& data, const network::connection
|
|||
}
|
||||
if (const config &c = data.child("observer_quit"))
|
||||
{
|
||||
const t_string &observer_name = c["name"];
|
||||
const config::attribute_value &observer_name = c["name"];
|
||||
if(!observer_name.empty()) {
|
||||
connected_user_list::iterator player = find_player(observer_name);
|
||||
if(player != users_.end() && find_player_side(observer_name) == -1) {
|
||||
|
@ -1641,7 +1641,7 @@ void connect::load_game()
|
|||
|
||||
if (params_.random_start_time)
|
||||
{
|
||||
if (!tod_manager::is_start_ToD(level_["random_start_time"]))
|
||||
if (!tod_manager::is_start_ToD(level_["random_start_time"].token()))
|
||||
{
|
||||
level_["random_start_time"] = true;
|
||||
}
|
||||
|
|
|
@ -435,7 +435,7 @@ void gamebrowser::set_game_items(const config& cfg, const config& game_config)
|
|||
{
|
||||
const config &era_cfg = game_config.find_child("era", "id", game["mp_era"]);
|
||||
utils::string_map symbols;
|
||||
symbols["era_id"] = game["mp_era"];
|
||||
symbols["era_id"] = game["mp_era"].token();
|
||||
if (era_cfg) {
|
||||
games_.back().map_info = era_cfg["name"].str();
|
||||
} else {
|
||||
|
@ -516,7 +516,7 @@ void gamebrowser::set_game_items(const config& cfg, const config& game_config)
|
|||
}
|
||||
} else {
|
||||
utils::string_map symbols;
|
||||
symbols["scenario_id"] = game["mp_scenario"];
|
||||
symbols["scenario_id"] = game["mp_scenario"].token();
|
||||
games_.back().map_info += vgettext("Unknown scenario: $scenario_id", symbols);
|
||||
verified = false;
|
||||
}
|
||||
|
|
|
@ -270,9 +270,9 @@ void wait::join_game(bool observe)
|
|||
}
|
||||
|
||||
int color = side_num;
|
||||
const config::t_token color_str = (*side_choice)["color"];
|
||||
const config::attribute_value color_str = (*side_choice)["color"];
|
||||
if (!color_str.empty())
|
||||
color = game_config::color_info(color_str).index() - 1;
|
||||
color = game_config::color_info(color_str.token()).index() - 1;
|
||||
|
||||
std::vector<const config *> leader_sides;
|
||||
foreach (const config &side, possible_sides) {
|
||||
|
@ -290,8 +290,8 @@ void wait::join_game(bool observe)
|
|||
foreach (const config *s, leader_sides)
|
||||
{
|
||||
const config &side = *s;
|
||||
const std::string &name = side["name"];
|
||||
const std::string &icon = side["image"];
|
||||
const std::string name = side["name"];
|
||||
const std::string icon = side["image"];
|
||||
|
||||
if (!icon.empty()) {
|
||||
std::string rgb = side["flag_rgb"];
|
||||
|
@ -451,7 +451,7 @@ void wait::generate_menu()
|
|||
std::string description = sd["user_description"];
|
||||
const std::string faction_id = sd["player_id"];
|
||||
|
||||
t_string side_name = sd["faction_name"];
|
||||
config::attribute_value side_name = sd["faction_name"];
|
||||
std::string leader_type = sd["type"];
|
||||
std::string gender_id = sd["gender"];
|
||||
|
||||
|
@ -496,7 +496,7 @@ void wait::generate_menu()
|
|||
if(side_name.str()[0] == font::IMAGE) {
|
||||
std::string::size_type p =
|
||||
side_name.str().find_first_of(COLUMN_SEPARATOR);
|
||||
if(p != std::string::npos && p < side_name.size()) {
|
||||
if(p != std::string::npos && p < side_name.str().size()) {
|
||||
side_name = IMAGE_PREFIX + leader_image + COLUMN_SEPARATOR + side_name.str().substr(p+1);
|
||||
}
|
||||
} else {
|
||||
|
@ -530,7 +530,7 @@ void wait::generate_menu()
|
|||
int disp_color = sd["color"];
|
||||
if(!sd["color"].empty()) {
|
||||
try {
|
||||
disp_color = game_config::color_info(sd["color"]).index();
|
||||
disp_color = game_config::color_info(sd["color"].token()).index();
|
||||
} catch(config::error&) {
|
||||
//ignore
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ config persist_file_context::get_var(const std::string &global) const
|
|||
for (size_t i = 0; i < arrsize; i++)
|
||||
ret.add_child(global,cfg.child(global,i));
|
||||
} else {
|
||||
ret = pack_scalar(global,cfg[global]);
|
||||
ret = pack_scalar(global,cfg[global].t_str());
|
||||
}
|
||||
} else {
|
||||
ret = pack_scalar(global,"");
|
||||
|
|
|
@ -59,7 +59,7 @@ static void get_global_variable(persist_context &ctx, const vconfig &pcfg)
|
|||
if (cfg) {
|
||||
size_t arrsize = cfg.child_count(global);
|
||||
if (arrsize == 0) {
|
||||
resources::state_of_game->set_variable(local,cfg[global]);
|
||||
resources::state_of_game->set_variable(local,cfg[global].t_str());
|
||||
} else {
|
||||
resources::state_of_game->clear_variable(local);
|
||||
for (size_t i = 0; i < arrsize; i++)
|
||||
|
@ -87,7 +87,7 @@ static void set_global_variable(persist_context &ctx, const vconfig &pcfg)
|
|||
const config &vars = resources::state_of_game->get_variables();
|
||||
size_t arraylen = vars.child_count(local);
|
||||
if (arraylen == 0) {
|
||||
val = pack_scalar(global,resources::state_of_game->get_variable(local));
|
||||
val = pack_scalar(global,resources::state_of_game->get_variable(local).t_str());
|
||||
} else {
|
||||
for (size_t i = 0; i < arraylen; i++)
|
||||
val.add_child(global,vars.child(local,i));
|
||||
|
|
|
@ -196,7 +196,7 @@ void play_controller::init(CVideo& video){
|
|||
std::string save_id = get_unique_saveid(side, seen_save_ids);
|
||||
seen_save_ids.insert(save_id);
|
||||
if (first_human_team_ == -1) {
|
||||
const std::string &controller = side["controller"];
|
||||
const std::string controller = side["controller"];
|
||||
if (controller == preferences::client_type() &&
|
||||
side["id"] == preferences::login()) {
|
||||
first_human_team_ = team_num;
|
||||
|
|
|
@ -147,8 +147,8 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
|
|||
const int side = lexical_cast<int>(change["side"]);
|
||||
const size_t index = static_cast<size_t>(side-1);
|
||||
|
||||
const std::string &controller = change["controller"];
|
||||
const std::string &player = change["player"];
|
||||
const std::string controller = change["controller"];
|
||||
const std::string player = change["player"];
|
||||
|
||||
if(index < resources::teams->size()) {
|
||||
team &tm = (*resources::teams)[index];
|
||||
|
|
22
src/race.cpp
22
src/race.cpp
|
@ -186,29 +186,33 @@ unit_race::unit_race(const config& cfg) :
|
|||
global_traits_(!cfg[z_ignore_global_traits].to_bool())
|
||||
|
||||
{
|
||||
config::attribute_value const & a_name= cfg[z_name];
|
||||
config::attribute_value const & a_male_name= cfg[z_male_name];
|
||||
config::attribute_value const & a_female_name= cfg[z_female_name];
|
||||
|
||||
if (id_.empty()) {
|
||||
lg::wml_error << "[race] '" << cfg[z_name] << "' is missing an id field.";
|
||||
lg::wml_error << "[race] '" << a_name << "' is missing an id field.";
|
||||
}
|
||||
if (plural_name_.empty()) {
|
||||
lg::wml_error << "[race] '" << cfg[z_name] << "' is missing a plural_name field.";
|
||||
plural_name_ = (cfg[z_name]);
|
||||
lg::wml_error << "[race] '" << a_name << "' is missing a plural_name field.";
|
||||
plural_name_ = (a_name.token());
|
||||
}
|
||||
// use z_name if z_male_name or z_female_name aren't available
|
||||
name_[MALE] = cfg[z_male_name];
|
||||
name_[MALE] = a_male_name.token();
|
||||
if(name_[MALE].empty()) {
|
||||
name_[MALE] = (cfg[z_name]);
|
||||
name_[MALE] = (a_male_name.token());
|
||||
}
|
||||
name_[FEMALE] = cfg[z_female_name];
|
||||
name_[FEMALE] = a_female_name.token();
|
||||
if(name_[FEMALE].empty()) {
|
||||
name_[FEMALE] = (cfg[z_name]);
|
||||
name_[FEMALE] = (a_female_name.token());
|
||||
}
|
||||
|
||||
if(chain_size_ <= 0)
|
||||
chain_size_ = 2;
|
||||
|
||||
//std::vector<std::string> names = ;
|
||||
next_[MALE] = markov_prefixes(utils::split_token(cfg[z_male_names]), chain_size_);
|
||||
next_[FEMALE] = markov_prefixes(utils::split_token(cfg[z_female_names]), chain_size_);
|
||||
next_[MALE] = markov_prefixes(utils::split_attr(cfg[z_male_names]), chain_size_);
|
||||
next_[FEMALE] = markov_prefixes(utils::split_attr(cfg[z_female_names]), chain_size_);
|
||||
}
|
||||
|
||||
config::t_token unit_race::generate_name(
|
||||
|
|
|
@ -826,9 +826,9 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
|
|||
}
|
||||
else if (const config &child = cfg->child("speak"))
|
||||
{
|
||||
const std::string &team_name = child["team_name"];
|
||||
const std::string &speaker_name = child["id"];
|
||||
const std::string &message = child["message"];
|
||||
const std::string team_name = child["team_name"];
|
||||
const std::string speaker_name = child["id"];
|
||||
const std::string message = child["message"];
|
||||
//if (!preferences::parse_should_show_lobby_join(speaker_name, message)) return;
|
||||
bool is_whisper = (speaker_name.find("whisper: ") == 0);
|
||||
get_replay_source().add_chat_message_location();
|
||||
|
@ -856,7 +856,7 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
|
|||
else if (const config &child = cfg->child("rename"))
|
||||
{
|
||||
const map_location loc(child, resources::state_of_game);
|
||||
const std::string &name = child["name"];
|
||||
const std::string name = child["name"];
|
||||
|
||||
unit_map::iterator u = resources::units->find(loc);
|
||||
if (u.valid()) {
|
||||
|
@ -1128,13 +1128,13 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
|
|||
else if (const config &child = cfg->child("fire_event"))
|
||||
{
|
||||
foreach (const config &v, child.child_range("set_variable")) {
|
||||
resources::state_of_game->set_variable(v["name"], v["value"]);
|
||||
resources::state_of_game->set_variable(v["name"], v["value"].t_str());
|
||||
}
|
||||
const config::t_token &event = child["raise"];
|
||||
const config::attribute_value &event = child["raise"];
|
||||
if (const config &source = child.child("source")) {
|
||||
game_events::fire(event, map_location(source, resources::state_of_game));
|
||||
game_events::fire(event.token(), map_location(source, resources::state_of_game));
|
||||
} else {
|
||||
game_events::fire(event);
|
||||
game_events::fire(event.token());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1001,7 +1001,7 @@ void autosave_savegame::create_filename()
|
|||
if (gamestate().classification().label.empty())
|
||||
filename = _("Auto-Save");
|
||||
else
|
||||
filename = gamestate().classification().label + "-" + _("Auto-Save") + snapshot()["turn_at"];
|
||||
filename = gamestate().classification().label + "-" + _("Auto-Save") + snapshot()["turn_at"].str();
|
||||
|
||||
set_filename(filename);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "SDL_types.h"
|
||||
#include "token.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
/** The type we use to represent Unicode strings. */
|
||||
typedef std::vector<wchar_t> wide_string;
|
||||
|
@ -54,6 +55,8 @@ enum { REMOVE_EMPTY = 0x01, /**< REMOVE_EMPTY : remove empty elements. */
|
|||
};
|
||||
|
||||
std::vector< n_token::t_token > split_token(n_token::t_token const &val, char c = ',', int flags = REMOVE_EMPTY | STRIP_SPACES);
|
||||
inline std::vector< n_token::t_token > split_attr(config::attribute_value const &val, char c = ',', int flags = REMOVE_EMPTY | STRIP_SPACES){
|
||||
return split_token(val.token(), c, flags); }
|
||||
std::vector< std::string > split(std::string const &val, char c = ',', int flags = REMOVE_EMPTY | STRIP_SPACES);
|
||||
|
||||
/**
|
||||
|
|
|
@ -549,7 +549,7 @@ void server::load_config() {
|
|||
|
||||
redirected_versions_.clear();
|
||||
foreach (const config &redirect, cfg_.child_range("redirect")) {
|
||||
foreach (const std::string &version, utils::split(redirect["version"])) {
|
||||
foreach (const std::string version, utils::split(redirect["version"])) {
|
||||
redirected_versions_[version] = redirect;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ void team::team_info::read(const config &cfg)
|
|||
gold = cfg["gold"];
|
||||
income = cfg["income"];
|
||||
team_name = cfg["team_name"].str();
|
||||
user_team_name = cfg["user_team_name"];
|
||||
user_team_name = cfg["user_team_name"].token();
|
||||
save_id = cfg["save_id"].str();
|
||||
current_player = cfg["current_player"].str();
|
||||
countdown_time = cfg["countdown_time"].str();
|
||||
|
@ -107,7 +107,7 @@ void team::team_info::read(const config &cfg)
|
|||
flag_icon = cfg["flag_icon"].str();
|
||||
description = cfg["id"].str();
|
||||
scroll_to_leader = cfg["scroll_to_leader"].to_bool(true);
|
||||
objectives = cfg["objectives"];
|
||||
objectives = cfg["objectives"].token();
|
||||
objectives_changed = cfg["objectives_changed"].to_bool();
|
||||
disallow_observers = cfg["disallow_observers"].to_bool();
|
||||
allow_player = cfg["allow_player"].to_bool(true);
|
||||
|
@ -158,7 +158,7 @@ void team::team_info::read(const config &cfg)
|
|||
}
|
||||
|
||||
const std::string temp_rgb_str = cfg["team_rgb"];
|
||||
game_config::t_team_rgb_range::const_iterator global_rgb = game_config::team_rgb_range.find(cfg["side"]);
|
||||
game_config::t_team_rgb_range::const_iterator global_rgb = game_config::team_rgb_range.find(cfg["side"].token());
|
||||
|
||||
if(!temp_rgb_str.empty()){
|
||||
std::vector<Uint32> temp_rgb = string2rgb(temp_rgb_str);
|
||||
|
|
|
@ -209,7 +209,7 @@ void team_builder::gold()
|
|||
|
||||
log_step("gold");
|
||||
|
||||
n_token::t_token gold = side_cfg_[z_gold];
|
||||
n_token::t_token gold = side_cfg_[z_gold].token();
|
||||
if(gold.empty()) {
|
||||
gold = z_default_gold_qty;
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ void team_builder::objectives()
|
|||
// If this team has no objectives, set its objectives
|
||||
// to the level-global z_objectives
|
||||
if (t_->objectives().empty())
|
||||
t_->set_objectives(level_[z_objectives], false);
|
||||
t_->set_objectives(level_[z_objectives].t_str(), false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -279,7 +279,7 @@ void team_builder::previous_recruits()
|
|||
// can be recruited for the player, add them.
|
||||
if (!player_cfg_) return;
|
||||
if (const config::attribute_value *v = player_cfg_->get(z_previous_recruits)) {
|
||||
foreach (const config::t_token &rec, utils::split_token(*v)) {
|
||||
foreach (const config::t_token &rec, utils::split_token(v->token())) {
|
||||
DBG_NG_TC << "adding previous recruit: " << rec << '\n';
|
||||
t_->add_recruit(rec);
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ void team_builder::handle_unit(const config &u, const char *origin)
|
|||
<< "] x=["<<u[z_x]
|
||||
<< "] y=["<<u[z_y]
|
||||
<<"]"<< std::endl;
|
||||
const config::t_token &id = u[z_id];
|
||||
const config::attribute_value &id = u[z_id];
|
||||
if (!id.empty()) {
|
||||
if ( seen_ids_.find(id)!=seen_ids_.end() ) {
|
||||
//seen before
|
||||
|
|
|
@ -149,22 +149,22 @@ terrain_type::terrain_type(const config& cfg) :
|
|||
|
||||
//mouse over message are only shown on villages
|
||||
if(village_) {
|
||||
income_description_ = cfg["income_description"];
|
||||
income_description_ = cfg["income_description"].token();
|
||||
if(income_description_ == "") {
|
||||
income_description_ = _("Village");
|
||||
}
|
||||
|
||||
income_description_ally_ = cfg["income_description_ally"];
|
||||
income_description_ally_ = cfg["income_description_ally"].token();
|
||||
if(income_description_ally_ == "") {
|
||||
income_description_ally_ = _("Allied village");
|
||||
}
|
||||
|
||||
income_description_enemy_ = cfg["income_description_enemy"];
|
||||
income_description_enemy_ = cfg["income_description_enemy"].token();
|
||||
if(income_description_enemy_ == "") {
|
||||
income_description_enemy_ = _("Enemy village");
|
||||
}
|
||||
|
||||
income_description_own_ = cfg["income_description_own"];
|
||||
income_description_own_ = cfg["income_description_own"].token();
|
||||
if(income_description_own_ == "") {
|
||||
income_description_own_ = _("Owned village");
|
||||
}
|
||||
|
|
|
@ -234,8 +234,8 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
|
|||
|
||||
// const t_string& t_tod_type = cfg_[z_time_of_day];
|
||||
// const t_string& t_tod_id = cfg_[z_time_of_day_id];
|
||||
const config::t_token& tod_type = cfg_[z_time_of_day];
|
||||
const config::t_token& tod_id = cfg_[z_time_of_day_id];
|
||||
const config::attribute_value& tod_type = cfg_[z_time_of_day];
|
||||
const config::attribute_value& tod_id = cfg_[z_time_of_day_id];
|
||||
static config const dummy_cfg;
|
||||
time_of_day tod(dummy_cfg);
|
||||
if(!tod_type.empty() || !tod_id.empty()) {
|
||||
|
@ -246,7 +246,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
|
|||
}
|
||||
}
|
||||
if(!tod_type.empty()) {
|
||||
const std::vector<config::t_token>& vals = utils::split_token(tod_type);
|
||||
const std::vector<config::t_token>& vals = utils::split_attr(tod_type);
|
||||
if(tod.lawful_bonus<0) {
|
||||
if(std::find(vals.begin(),vals.end(), z_chaotic) == vals.end()) {
|
||||
return false;
|
||||
|
@ -262,8 +262,8 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
|
|||
}
|
||||
|
||||
if(!tod_id.empty()) {
|
||||
if(tod_id != config::t_token(tod.id)) {
|
||||
const std::vector<config::t_token>& vals = utils::split_token(tod_id);
|
||||
if(tod_id != tod.id) {
|
||||
const std::vector<config::t_token>& vals = utils::split_attr(tod_id);
|
||||
if(std::find(vals.begin(),vals.end(),tod.id) == vals.end()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -166,9 +166,9 @@ void tod_manager::add_time_area(const config& cfg)
|
|||
{
|
||||
areas_.push_back(area_time_of_day());
|
||||
area_time_of_day &area = areas_.back();
|
||||
area.id = cfg[z_id];
|
||||
area.xsrc = cfg[z_x];
|
||||
area.ysrc = cfg[z_y];
|
||||
area.id = cfg[z_id].token();
|
||||
area.xsrc = cfg[z_x].token();
|
||||
area.ysrc = cfg[z_y].token();
|
||||
area.currentTime = cfg[z_current_time].to_int(0);
|
||||
std::vector<map_location> const& locs = parse_location_range(area.xsrc, area.ysrc, true);
|
||||
std::copy(locs.begin(), locs.end(), std::inserter(area.hexes, area.hexes.end()));
|
||||
|
@ -214,7 +214,7 @@ int tod_manager::get_start_ToD(const config &level) const
|
|||
|
||||
const config::attribute_value& cfg_random_start_time = level[z_random_start_time];
|
||||
if(!cfg_random_start_time.blank()) {
|
||||
const config::t_token& random_start_time = cfg_random_start_time;
|
||||
const config::t_token& random_start_time = cfg_random_start_time.token();
|
||||
//TODO:
|
||||
//Here there is danger of OOS (bug #15948)
|
||||
//But this randomization is needed on the other hand to make the "random start time" option
|
||||
|
|
|
@ -150,8 +150,8 @@ public:
|
|||
t_string(const std::string &str, const std::string &textdomain);
|
||||
|
||||
t_string &operator=(t_token const &);
|
||||
template <typename X> t_string &operator=(X const &o) {
|
||||
operator=(static_cast<t_token const &>(o)); return *this; }
|
||||
// template <typename X> t_string &operator=(X const &o) {
|
||||
// operator=(static_cast<t_token const &>(o)); return *this; }
|
||||
|
||||
t_string &operator=(std::string const &);
|
||||
t_string &operator=(const char *o);
|
||||
|
|
148
src/unit.cpp
148
src/unit.cpp
|
@ -95,10 +95,10 @@ static unit_race::GENDER generate_gender(const config &cfg, game_state *state) {
|
|||
static const config::t_token z_gender("gender", false);
|
||||
static const config::t_token z_type("type", false);
|
||||
static const config::t_token z_random_gender("random_gender", false);
|
||||
const config::t_token& gender = cfg[z_gender];
|
||||
const config::attribute_value& gender = cfg[z_gender];
|
||||
if(!gender.empty())
|
||||
return string_gender(gender);
|
||||
const config::t_token &type = cfg[z_type];
|
||||
return string_gender(gender.token());
|
||||
const config::attribute_value &type = cfg[z_type];
|
||||
if (type.empty())
|
||||
return unit_race::MALE;
|
||||
|
||||
|
@ -381,7 +381,7 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
|||
|
||||
advance_to(cfg, type(), use_traits, state);
|
||||
if (const config::attribute_value *v = cfg.get(z_race)) {
|
||||
if (const unit_race *r = unit_types.find_race(*v)) {
|
||||
if (const unit_race *r = unit_types.find_race(v->token())) {
|
||||
race_ = r;
|
||||
} else {
|
||||
static const unit_race dummy_race;
|
||||
|
@ -417,16 +417,22 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
|||
cfg_[z_halo] = *v;
|
||||
}
|
||||
if (const config::attribute_value *v = cfg.get(z_profile)) {
|
||||
config::t_token big = *v, small = cfg[z_small_profile];
|
||||
adjust_profile(small, big, z_empty);
|
||||
cfg_[z_profile] = big;
|
||||
cfg_[z_small_profile] = small;
|
||||
config::t_token const & big = v->token();
|
||||
config::attribute_value const & small = cfg[z_small_profile];
|
||||
std::pair<config::t_token, config::t_token> new_profiles = adjust_profile(small.token(), big, z_empty);
|
||||
cfg_[z_small_profile] = new_profiles.first;
|
||||
cfg_[z_profile] = new_profiles.second;
|
||||
//This replicates old code ///todo find a const correct way
|
||||
if(new_profiles.second != big){
|
||||
config::t_token & big_writable= const_cast<config::t_token &>( big);
|
||||
big_writable = new_profiles.second;
|
||||
}
|
||||
}
|
||||
max_hit_points_ = std::max(1, cfg[z_max_hitpoints].to_int(max_hit_points_));
|
||||
max_movement_ = std::max(0, cfg[z_max_moves].to_int(max_movement_));
|
||||
max_experience_ = std::max(1, cfg[z_max_experience].to_int(max_experience_));
|
||||
|
||||
std::vector<config::t_token> temp_advances = utils::split_token(cfg[z_advances_to]);
|
||||
std::vector<config::t_token> temp_advances = utils::split_attr(cfg[z_advances_to]);
|
||||
if(temp_advances.size() == 1 && temp_advances.front() == z_null) {
|
||||
advances_to_.clear();
|
||||
}else if(temp_advances.size() >= 1 && temp_advances.front() != z_empty ) {
|
||||
|
@ -564,7 +570,7 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
|||
cfg_[z_upkeep] = z_full;
|
||||
}
|
||||
|
||||
set_recruits(utils::split_token(cfg[z_extra_recruit]));
|
||||
set_recruits(utils::split_attr(cfg[z_extra_recruit]));
|
||||
cfg_.add_child(z_filter_recall, cfg.child_or_empty(z_filter_recall));
|
||||
|
||||
/** @todo Are these modified by read? if not they can be removed. */
|
||||
|
@ -807,7 +813,8 @@ void unit::generate_traits(bool musthaveonly, game_state* state)
|
|||
foreach (const config &t, type->possible_traits())
|
||||
{
|
||||
// Skip the trait if the unit already has it.
|
||||
const std::string &tid = t[z_id];
|
||||
const config::attribute_value & atid = t[z_id];
|
||||
const config::t_token & tid = atid.token();
|
||||
bool already = false;
|
||||
foreach (const config &mod, current_traits)
|
||||
{
|
||||
|
@ -819,7 +826,8 @@ void unit::generate_traits(bool musthaveonly, game_state* state)
|
|||
if (already) continue;
|
||||
|
||||
// Add the trait if it is mandatory.
|
||||
const std::string &avl = t[z_availability];
|
||||
const config::attribute_value &aavl = t[z_availability];
|
||||
const config::t_token &avl = aavl.token();
|
||||
if (avl == z_musthave)
|
||||
{
|
||||
modifications_.add_child(z_trait, t);
|
||||
|
@ -861,9 +869,9 @@ std::vector<config::t_token> unit::get_traits_list() const
|
|||
|
||||
foreach (const config &mod, modifications_.child_range(z_trait))
|
||||
{
|
||||
config::t_token const &id = mod[z_id];
|
||||
config::attribute_value const &id = mod[z_id];
|
||||
if (!id.empty())
|
||||
res.push_back(id);
|
||||
res.push_back(id.token());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1024,9 +1032,9 @@ config::t_token const & unit::big_profile() const
|
|||
static const config::t_token z_profile("profile", false);
|
||||
static const config::t_token z_unit_image("unit_image", false);
|
||||
|
||||
const config::t_token &prof = cfg_[z_profile];
|
||||
const config::attribute_value &prof = cfg_[z_profile];
|
||||
if (!prof.empty() && prof != z_unit_image) {
|
||||
return prof;
|
||||
return prof.token();
|
||||
}
|
||||
return absolute_image();
|
||||
}
|
||||
|
@ -1036,9 +1044,9 @@ config::t_token const & unit::small_profile() const
|
|||
|
||||
static const config::t_token z_small_profile("small_profile", false);
|
||||
static const config::t_token z_unit_image("unit_image", false);
|
||||
const config::t_token &prof = cfg_[z_small_profile];
|
||||
const config::attribute_value &prof = cfg_[z_small_profile];
|
||||
if (!prof.empty() && prof != z_unit_image) {
|
||||
return prof;
|
||||
return prof.token();
|
||||
}
|
||||
return absolute_image();
|
||||
}
|
||||
|
@ -1535,7 +1543,7 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
|||
}
|
||||
|
||||
config::attribute_value cfg_gender = cfg[z_gender];
|
||||
if (!cfg_gender.empty() && string_gender(cfg_gender) != gender()) {
|
||||
if (!cfg_gender.empty() && string_gender(cfg_gender.token()) != gender()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1553,7 +1561,7 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
|||
|
||||
config::attribute_value cfg_has_weapon = cfg[z_has_weapon];
|
||||
if (!cfg_has_weapon.empty()) {
|
||||
config::t_token const & weapon = cfg_has_weapon;
|
||||
config::t_token const & weapon = cfg_has_weapon.token();
|
||||
bool has_weapon = false;
|
||||
const std::vector<attack_type>& attacks = this->attacks();
|
||||
for(std::vector<attack_type>::const_iterator i = attacks.begin();
|
||||
|
@ -2416,7 +2424,7 @@ utils::string_map unit::get_base_resistances() const
|
|||
{
|
||||
utils::string_map res;
|
||||
foreach (const config::attribute &i, resistance.attribute_range()) {
|
||||
res[i.first] = i.second;
|
||||
res[i.first] = i.second.token();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -2453,11 +2461,13 @@ std::map<std::string,std::string> unit::advancement_icons() const
|
|||
static const config::t_token z_image("image", false);
|
||||
static const config::t_token z_description("description", false);
|
||||
|
||||
const std::string &image = adv[z_image];
|
||||
config::attribute_value const & aimage = adv[z_image];
|
||||
const config::t_token & image = aimage.token();
|
||||
if (image.empty()) continue;
|
||||
std::ostringstream tooltip;
|
||||
tooltip << temp[image];
|
||||
const std::string &tt = adv[z_description];
|
||||
config::attribute_value const & att = adv[z_description];
|
||||
const config::t_token & tt = att.token();
|
||||
if (!tt.empty())
|
||||
tooltip << tt << '\n';
|
||||
temp[image] = tooltip.str();
|
||||
|
@ -2614,10 +2624,11 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
static const config::t_token z_new_animation("new_animation", false);
|
||||
static const config::t_token z_ellipse("ellipse", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
static const config::t_token z_per_level("per level", false);
|
||||
|
||||
//some trait activate specific flags
|
||||
if(type == z_trait) {
|
||||
const config::t_token& id = mod[z_id];
|
||||
const config::attribute_value& id = mod[z_id];
|
||||
is_fearless_ = is_fearless_ || id == z_fearless;
|
||||
is_healthy_ = is_healthy_ || id == z_healthy;
|
||||
}
|
||||
|
@ -2631,7 +2642,7 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
foreach (const config &effect, mod.child_range(z_effect))
|
||||
{
|
||||
// See if the effect only applies to certain unit types
|
||||
const std::string &type_filter = effect[z_unit_type];
|
||||
const std::string type_filter = effect[z_unit_type];
|
||||
if(type_filter.empty() == false) {
|
||||
const std::vector<std::string>& types = utils::split(type_filter);
|
||||
if(std::find(types.begin(),types.end(),type_id()) == types.end()) {
|
||||
|
@ -2639,7 +2650,7 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
}
|
||||
}
|
||||
// See if the effect only applies to certain genders
|
||||
const config::t_token &gender_filter = effect[z_unit_gender];
|
||||
const config::attribute_value &gender_filter = effect[z_unit_gender];
|
||||
if(gender_filter.empty() == false) {
|
||||
const std::string& gender = gender_string(gender_);
|
||||
const std::vector<std::string>& genders = utils::split(gender_filter);
|
||||
|
@ -2652,12 +2663,13 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
if (const config &afilter = effect.child(z_filter))
|
||||
if (!matches_filter(vconfig(afilter), map_location(cfg_, NULL), false ,game_map, units, teams, lua_kernel, tod_manager)) continue;
|
||||
|
||||
const config::t_token &apply_to = effect[z_apply_to];
|
||||
const std::string &apply_times = effect[z_times];
|
||||
const config::attribute_value &apply_to = effect[z_apply_to];
|
||||
config::attribute_value const & aapply_times = effect[z_times];
|
||||
const config::t_token & apply_times = aapply_times.token();
|
||||
int times = 1;
|
||||
t_string description;
|
||||
|
||||
if (apply_times == "per level")
|
||||
if (apply_times == z_per_level)
|
||||
times = level_;
|
||||
if (times) {
|
||||
while (times > 0) {
|
||||
|
@ -2668,11 +2680,16 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
last_effect = effect;
|
||||
} else if(apply_to == z_profile) {
|
||||
if (const config::attribute_value *v = effect.get(z_portrait)) {
|
||||
config::t_token big = *v;
|
||||
config::t_token small = effect[z_small_portrait];
|
||||
adjust_profile(small, big, z_empty);
|
||||
cfg_[z_profile] = big;
|
||||
cfg_[z_small_profile] = small;
|
||||
config::t_token const & big = v->token();
|
||||
config::attribute_value const &small = effect[z_small_portrait];
|
||||
std::pair<config::t_token, config::t_token> new_profiles = adjust_profile(small.token(), big, z_empty);
|
||||
cfg_[z_small_profile] = new_profiles.first;
|
||||
cfg_[z_profile] = new_profiles.second;
|
||||
//This replicates old code ///todo find a const correct way
|
||||
if(new_profiles.second != big){
|
||||
config::t_token & big_writable= const_cast<config::t_token &>( big );
|
||||
big_writable = new_profiles.second;
|
||||
}
|
||||
}
|
||||
if (const config::attribute_value *v = effect.get(z_description))
|
||||
cfg_[z_description] = *v;
|
||||
|
@ -2714,26 +2731,31 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
}
|
||||
} else if(apply_to == z_hitpoints) {
|
||||
LOG_UT << "applying hitpoint mod..." << hit_points_ << "/" << max_hit_points_ << "\n";
|
||||
const std::string &increase_hp = effect[z_increase];
|
||||
const std::string &increase_total = effect[z_increase_total];
|
||||
const std::string &set_hp = effect[z_set];
|
||||
const std::string &set_total = effect[z_set_total];
|
||||
config::attribute_value const & aincrease_hp = effect[z_increase];
|
||||
config::attribute_value const & aincrease_total = effect[z_increase_total];
|
||||
config::attribute_value const & aset_hp = effect[z_set];
|
||||
config::attribute_value const & aset_total = effect[z_set_total];
|
||||
|
||||
const config::t_token &increase_hp = aincrease_hp.token();
|
||||
const config::t_token &increase_total = aincrease_total.token();
|
||||
const config::t_token &set_hp = aset_hp.token();
|
||||
const config::t_token &set_total = aset_total.token();
|
||||
|
||||
// If the hitpoints are allowed to end up greater than max hitpoints
|
||||
const bool violate_max = effect[z_violate_maximum].to_bool();
|
||||
|
||||
if(set_hp.empty() == false) {
|
||||
if(set_hp[set_hp.size()-1] == '%') {
|
||||
hit_points_ = lexical_cast_default<int>(set_hp)*max_hit_points_/100;
|
||||
if((*set_hp)[(*set_hp).size()-1] == '%') {
|
||||
hit_points_ = lexical_cast_default<int>(*set_hp)*max_hit_points_/100;
|
||||
} else {
|
||||
hit_points_ = lexical_cast_default<int>(set_hp);
|
||||
hit_points_ = lexical_cast_default<int>(*set_hp);
|
||||
}
|
||||
}
|
||||
if(set_total.empty() == false) {
|
||||
if(set_total[set_total.size()-1] == '%') {
|
||||
max_hit_points_ = lexical_cast_default<int>(set_total)*max_hit_points_/100;
|
||||
if((*set_total)[(*set_total).size()-1] == '%') {
|
||||
max_hit_points_ = lexical_cast_default<int>(*set_total)*max_hit_points_/100;
|
||||
} else {
|
||||
max_hit_points_ = lexical_cast_default<int>(set_total);
|
||||
max_hit_points_ = lexical_cast_default<int>(*set_total);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2766,7 +2788,8 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
if(hit_points_ < 1)
|
||||
hit_points_ = 1;
|
||||
} else if(apply_to == z_movement) {
|
||||
const std::string &increase = effect[z_increase];
|
||||
config::attribute_value const & aincrease = effect[z_increase];
|
||||
const config::t_token & increase = aincrease.token();
|
||||
|
||||
if(increase.empty() == false) {
|
||||
if (!times)
|
||||
|
@ -2781,7 +2804,8 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
if(movement_ > max_movement_)
|
||||
movement_ = max_movement_;
|
||||
} else if(apply_to == z_max_experience) {
|
||||
const std::string &increase = effect[z_increase];
|
||||
config::attribute_value const & aiincrease = effect[z_increase];
|
||||
const config::t_token & increase = aiincrease.token();
|
||||
|
||||
if(increase.empty() == false) {
|
||||
if (!times)
|
||||
|
@ -2794,15 +2818,15 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
} else if(apply_to == z_loyal) {
|
||||
cfg_[z_upkeep] = z_loyal;
|
||||
} else if(apply_to == z_status) {
|
||||
const config::t_token &add = effect[z_add];
|
||||
const config::t_token &remove = effect[z_remove];
|
||||
const config::attribute_value &add = effect[z_add];
|
||||
const config::attribute_value &remove = effect[z_remove];
|
||||
|
||||
if(add.empty() == false) {
|
||||
set_state(add, true);
|
||||
set_state(state_t(add.to_int()), true);
|
||||
}
|
||||
|
||||
if(remove.empty() == false) {
|
||||
set_state(remove, false);
|
||||
set_state(state_t(remove.to_int()), false);
|
||||
}
|
||||
} else if (apply_to == z_movement_costs) {
|
||||
config &mv = cfg_.child_or_add(z_movement_costs);
|
||||
|
@ -2903,20 +2927,23 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
}
|
||||
}
|
||||
} else if(apply_to == z_hitpoints) {
|
||||
const std::string &increase_total = effect[z_increase_total];
|
||||
config::attribute_value const & aincrease_total = effect[z_increase_total];
|
||||
const config::t_token &increase_total = aincrease_total.token();
|
||||
|
||||
if(increase_total.empty() == false) {
|
||||
description += utils::print_modifier(increase_total) + " " +
|
||||
t_string(N_(z_HP), z_wesnoth);
|
||||
}
|
||||
} else if(apply_to == z_movement) {
|
||||
const std::string &increase = effect[z_increase];
|
||||
config::attribute_value const & aincrease = effect[z_increase];
|
||||
const config::t_token & increase = aincrease.token();
|
||||
|
||||
if(increase.empty() == false) {
|
||||
description += utils::print_modifier(increase) + t_string(N_(" move"), z_wesnoth);
|
||||
}
|
||||
} else if(apply_to == z_max_experience) {
|
||||
const std::string &increase = effect[z_increase];
|
||||
config::attribute_value const & aincrease = effect[z_increase];
|
||||
const config::t_token & increase = aincrease.token();
|
||||
|
||||
if(increase.empty() == false) {
|
||||
description += utils::print_modifier(increase) + " " +
|
||||
|
@ -2942,7 +2969,8 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
} else if ((last_effect)["apply_to"] == "type") {
|
||||
config::attribute_value &prev_type = (*new_child)["prev_type"];
|
||||
if (prev_type.blank()) prev_type = type_id();
|
||||
const std::string& type_id = last_effect["name"];
|
||||
config::attribute_value const & atype_id = last_effect["name"];
|
||||
const config::t_token &type_id = atype_id.token();
|
||||
const unit_type* type = unit_types.find(type_id);
|
||||
if(type) {
|
||||
const bool heal_full = last_effect["heal_full"].to_bool(false);
|
||||
|
@ -2960,7 +2988,7 @@ void unit::add_modification(const config::t_token& type, const config& mod, bool
|
|||
|
||||
t_string description;
|
||||
|
||||
const t_string& mod_description = mod[z_description];
|
||||
const config::attribute_value& mod_description = mod[z_description];
|
||||
if (!mod_description.empty()) {
|
||||
description = mod_description + " ";
|
||||
}
|
||||
|
@ -2990,16 +3018,16 @@ void unit::add_trait_description(const config& trait, const t_string& descriptio
|
|||
static const config::t_token z_male_name("male_name", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
|
||||
const std::string& gender_string = gender_ == unit_race::FEMALE ? z_female_name : z_male_name;
|
||||
t_string const &gender_specific_name = trait[gender_string];
|
||||
const config::t_token& gender_string = gender_ == unit_race::FEMALE ? z_female_name : z_male_name;
|
||||
config::attribute_value const &gender_specific_name = trait[gender_string];
|
||||
|
||||
// if this is a t_string& instead of a t_string, msvc9 compiled windows binaries
|
||||
// choke on the case where both gender_specific_name and trait[z_name] are empty.
|
||||
const t_string& name = gender_specific_name.empty() ?
|
||||
const config::attribute_value& name = gender_specific_name.empty() ?
|
||||
trait[z_name] : gender_specific_name;
|
||||
|
||||
if(!name.empty()) {
|
||||
trait_names_.push_back(name);
|
||||
trait_names_.push_back(name.t_str());
|
||||
trait_descriptions_.push_back(description);
|
||||
}
|
||||
}
|
||||
|
@ -3034,7 +3062,7 @@ void unit::apply_modifications()
|
|||
log_scope("apply mods");
|
||||
|
||||
for(size_t i = 0; i != NumModificationTypes; ++i) {
|
||||
const std::string& mod = ModificationTypes[i];
|
||||
const config::t_token& mod = ModificationTypes[i];
|
||||
foreach (const config &m, modifications_.child_range(mod)) {
|
||||
log_scope("add mod");
|
||||
add_modification(ModificationTypes[i], m, true);
|
||||
|
|
10
src/unit.hpp
10
src/unit.hpp
|
@ -105,7 +105,7 @@ public:
|
|||
/** Information about the unit -- a detailed description of it */
|
||||
t_string unit_description() const {
|
||||
static const config::t_token z_description("description", false);
|
||||
return cfg_[z_description]; }
|
||||
return cfg_[z_description].t_str(); }
|
||||
|
||||
int hitpoints() const { return hit_points_; }
|
||||
int max_hitpoints() const { return max_hit_points_; }
|
||||
|
@ -285,21 +285,21 @@ public:
|
|||
/** The name of the file to game_display (used in menus). */
|
||||
config::t_token const & absolute_image() const {
|
||||
static const config::t_token z_image("image", false);
|
||||
return cfg_[z_image]; }
|
||||
return cfg_[z_image].token(); }
|
||||
config::t_token const & image_halo() const {
|
||||
static const config::t_token z_halo("halo", false);
|
||||
return cfg_[z_halo]; }
|
||||
return cfg_[z_halo].token(); }
|
||||
|
||||
config::t_token const & image_ellipse() const {
|
||||
static const config::t_token z_ellipse("ellipse", false);
|
||||
return cfg_[z_ellipse]; }
|
||||
return cfg_[z_ellipse].token(); }
|
||||
|
||||
config &variables() { return variables_; }
|
||||
const config &variables() const { return variables_; }
|
||||
|
||||
config::t_token usage() const {
|
||||
static const config::t_token z_usage("usage", false);
|
||||
return cfg_[z_usage]; }
|
||||
return cfg_[z_usage].token(); }
|
||||
unit_type::ALIGNMENT alignment() const { return alignment_; }
|
||||
const unit_race* race() const { return race_; }
|
||||
|
||||
|
|
|
@ -291,10 +291,10 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
|
||||
foreach (const config &i, cfg.child_range(z_filter_adjacent))
|
||||
{
|
||||
foreach (const std::string &j, utils::split(i[z_adjacent]))
|
||||
foreach (const config::t_token j, utils::split_attr(i[z_adjacent]))
|
||||
{
|
||||
map_location::DIRECTION index =
|
||||
map_location::parse_direction(j);
|
||||
map_location::parse_direction(*j);
|
||||
if (index == map_location::NDIRECTIONS)
|
||||
continue;
|
||||
unit_map::const_iterator unit = units.find(adjacent[index]);
|
||||
|
@ -308,9 +308,9 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
|
||||
foreach (const config &i, cfg.child_range(z_filter_adjacent_location))
|
||||
{
|
||||
foreach (const std::string &j, utils::split(i[z_adjacent]))
|
||||
foreach (const config::t_token j, utils::split_attr(i[z_adjacent]))
|
||||
{
|
||||
map_location::DIRECTION index = map_location::parse_direction(j);
|
||||
map_location::DIRECTION index = map_location::parse_direction(*j);
|
||||
if (index == map_location::NDIRECTIONS) {
|
||||
continue;
|
||||
}
|
||||
|
@ -583,16 +583,16 @@ std::vector<t_string> attack_type::special_tooltips(bool force) const
|
|||
foreach (const config::any_child &sp, specials.all_children_range())
|
||||
{
|
||||
if (force || special_active(sp.cfg, true)) {
|
||||
const t_string &name = sp.cfg[z_name];
|
||||
const config::attribute_value &name = sp.cfg[z_name];
|
||||
if (!name.empty()) {
|
||||
res.push_back(name);
|
||||
res.push_back(sp.cfg[z_description]);
|
||||
res.push_back(name.t_str());
|
||||
res.push_back(sp.cfg[z_description].t_str());
|
||||
}
|
||||
} else {
|
||||
t_string const &name = sp.cfg[z_name_inactive];
|
||||
config::attribute_value const &name = sp.cfg[z_name_inactive];
|
||||
if (!name.empty()) {
|
||||
res.push_back(name);
|
||||
res.push_back(sp.cfg[z_description_inactive]);
|
||||
res.push_back(name.t_str());
|
||||
res.push_back(sp.cfg[z_description_inactive].t_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -614,11 +614,11 @@ config::t_token attack_type::weapon_specials(bool force) const
|
|||
{
|
||||
config::t_token const *s = force || special_active(sp.cfg, true) ?
|
||||
&z_name : &z_name_inactive;
|
||||
config::t_token const &name = sp.cfg[*s];
|
||||
config::attribute_value const &name = sp.cfg[*s];
|
||||
|
||||
if (!name.empty()) {
|
||||
if (!res.empty()) { res += ',' ; }
|
||||
res += (* name );
|
||||
res += (* name.token() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,7 +666,7 @@ bool attack_type::special_active(gamemap const & game_map, unit_map const & unit
|
|||
|
||||
if(attacker_) {
|
||||
{
|
||||
config::t_token const &active = cfg[z_active_on];
|
||||
config::attribute_value const &active = cfg[z_active_on];
|
||||
if (!active.empty() && active != z_offense)
|
||||
return false;
|
||||
}
|
||||
|
@ -693,7 +693,7 @@ bool attack_type::special_active(gamemap const & game_map, unit_map const & unit
|
|||
}
|
||||
} else {
|
||||
{
|
||||
config::t_token const &active = cfg[z_active_on];
|
||||
config::attribute_value const &active = cfg[z_active_on];
|
||||
if (!active.empty() && active != z_defense)
|
||||
return false;
|
||||
}
|
||||
|
@ -762,7 +762,7 @@ bool attack_type::special_active(gamemap const & game_map, unit_map const & unit
|
|||
|
||||
foreach (const config &i, cfg.child_range(z_filter_adjacent))
|
||||
{
|
||||
foreach (const config::t_token &j, utils::split_token(i[z_adjacent]))
|
||||
foreach (const config::t_token &j, utils::split_attr(i[z_adjacent]))
|
||||
{
|
||||
map_location::DIRECTION index =
|
||||
map_location::parse_direction(j);
|
||||
|
@ -777,7 +777,7 @@ bool attack_type::special_active(gamemap const & game_map, unit_map const & unit
|
|||
|
||||
foreach (const config &i, cfg.child_range(z_filter_adjacent_location))
|
||||
{
|
||||
foreach (const config::t_token &j, utils::split_token(i[z_adjacent]))
|
||||
foreach (const config::t_token &j, utils::split_attr( (i[z_adjacent]) ))
|
||||
{
|
||||
map_location::DIRECTION index =
|
||||
map_location::parse_direction(j);
|
||||
|
@ -805,7 +805,7 @@ bool attack_type::special_affects_opponent(const config& cfg) const
|
|||
static const config::t_token z_attacker("attacker", false);
|
||||
|
||||
// log_scope("special_affects_opponent");
|
||||
config::t_token const &apply_to = cfg[z_apply_to];
|
||||
config::attribute_value const &apply_to = cfg[z_apply_to];
|
||||
if (apply_to.empty())
|
||||
return false;
|
||||
if (apply_to == z_both)
|
||||
|
@ -832,7 +832,7 @@ bool attack_type::special_affects_self(const config& cfg) const
|
|||
static const config::t_token z_defender("defender", false);
|
||||
|
||||
// log_scope("special_affects_self");
|
||||
config::t_token const &apply_to = cfg[z_apply_to];
|
||||
config::attribute_value const &apply_to = cfg[z_apply_to];
|
||||
if (apply_to.empty())
|
||||
return true;
|
||||
if (apply_to == z_both)
|
||||
|
|
|
@ -262,9 +262,9 @@ unit_animation::unit_animation(const config& cfg,const n_token::t_token& frame_s
|
|||
if (sub_anims_.find(fr.key) != sub_anims_.end()) continue;
|
||||
sub_anims_[fr.key] = particule(cfg, n_token::t_token((*fr.key).substr(0, (*fr.key).size() - 5)));
|
||||
}
|
||||
event_ =utils::split_token(cfg[z_apply_to]);
|
||||
event_ =utils::split_attr(cfg[z_apply_to]);
|
||||
|
||||
const std::vector<n_token::t_token>& my_directions = utils::split_token(cfg[z_direction]);
|
||||
const std::vector<n_token::t_token>& my_directions = utils::split_attr(cfg[z_direction]);
|
||||
for(std::vector<n_token::t_token>::const_iterator i = my_directions.begin(); i != my_directions.end(); ++i) {
|
||||
const map_location::DIRECTION d = map_location::parse_direction(*i);
|
||||
directions_.push_back(d);
|
||||
|
@ -277,13 +277,13 @@ unit_animation::unit_animation(const config& cfg,const n_token::t_token& frame_s
|
|||
secondary_unit_filter_.push_back(filter);
|
||||
}
|
||||
|
||||
std::vector<n_token::t_token> value_str = utils::split_token(cfg[z_value]);
|
||||
std::vector<n_token::t_token> value_str = utils::split_attr(cfg[z_value]);
|
||||
std::vector<n_token::t_token>::iterator value;
|
||||
for(value=value_str.begin() ; value != value_str.end() ; ++value) {
|
||||
value_.push_back(atoi(value->c_str()));
|
||||
}
|
||||
|
||||
std::vector<n_token::t_token> hits_str = utils::split_token(cfg[z_hits]);
|
||||
std::vector<n_token::t_token> hits_str = utils::split_attr(cfg[z_hits]);
|
||||
std::vector<n_token::t_token>::iterator hit;
|
||||
for(hit=hits_str.begin() ; hit != hits_str.end() ; ++hit) {
|
||||
if(*hit == z_yes || *hit == z_hit) {
|
||||
|
@ -296,7 +296,7 @@ unit_animation::unit_animation(const config& cfg,const n_token::t_token& frame_s
|
|||
hits_.push_back(KILL);
|
||||
}
|
||||
}
|
||||
std::vector<n_token::t_token> value2_str = utils::split_token(cfg[z_value_second]);
|
||||
std::vector<n_token::t_token> value2_str = utils::split_attr(cfg[z_value_second]);
|
||||
std::vector<n_token::t_token>::iterator value2;
|
||||
for(value2=value2_str.begin() ; value2 != value2_str.end() ; ++value2) {
|
||||
value2_.push_back(atoi(value2->c_str()));
|
||||
|
@ -542,7 +542,7 @@ static const config::t_token z_local_pois_sound("poison.ogg", false);
|
|||
animations.back().unit_anim_.override(0,600,particule::NO_CYCLE, z_local_1_0_600);
|
||||
animations.back().sub_anims_[z__death_sound] = particule();
|
||||
animations.back().sub_anims_[z__death_sound].add_frame(1,frame_builder());
|
||||
animations.back().sub_anims_[z__death_sound].add_frame(1,frame_builder().sound(cfg[z_die_sound]),true);
|
||||
animations.back().sub_anims_[z__death_sound].add_frame(1,frame_builder().sound(cfg[z_die_sound].token()),true);
|
||||
|
||||
animations.push_back(*itor);
|
||||
animations.back().event_ = utils::split_token(z_victory);
|
||||
|
@ -761,7 +761,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
|
|||
}
|
||||
else
|
||||
{
|
||||
std::vector<n_token::t_token> v = utils::split_token(anim[z_hits]);
|
||||
std::vector<n_token::t_token> v = utils::split_attr(anim[z_hits]);
|
||||
foreach (const n_token::t_token &hit_type, v)
|
||||
{
|
||||
config tmp = anim;
|
||||
|
@ -816,7 +816,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
|
|||
if(!cfg[z_die_sound].empty()) {
|
||||
animations.back().sub_anims_[z__death_sound] = particule();
|
||||
animations.back().sub_anims_[z__death_sound].add_frame(1,frame_builder());
|
||||
animations.back().sub_anims_[z__death_sound].add_frame(1,frame_builder().sound(cfg[z_die_sound]),true);
|
||||
animations.back().sub_anims_[z__death_sound].add_frame(1,frame_builder().sound(cfg[z_die_sound].token()),true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -617,10 +617,14 @@ void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const m
|
|||
secondary_loc = u->get_location().get_direction(dir);
|
||||
}
|
||||
}
|
||||
animator.add_animation(&*u, cfg[z_flag], u->get_location(),
|
||||
secondary_loc, cfg[z_value], cfg[z_with_bars].to_bool(),
|
||||
cfg[z_text], text_color, hits, primary, secondary,
|
||||
cfg[z_value_second]);
|
||||
config::attribute_value const & a_value_second= cfg[z_value_second];
|
||||
config::attribute_value const & a_flag= cfg[z_flag];
|
||||
config::attribute_value const & a_value= cfg[z_value];
|
||||
config::attribute_value const & a_text= cfg[z_text];
|
||||
animator.add_animation(&*u, a_flag.token(), u->get_location(),
|
||||
secondary_loc, a_value, cfg[z_with_bars].to_bool(),
|
||||
a_text.token(), text_color, hits, primary, secondary, a_value_second.to_int()
|
||||
);
|
||||
}
|
||||
const vconfig::child_list sub_anims = cfg.get_children(z_animate);
|
||||
vconfig::child_list::const_iterator anim_itor;
|
||||
|
|
|
@ -294,7 +294,7 @@ frame_builder::frame_builder(const config& cfg,const n_token::t_token& frame_str
|
|||
} else {
|
||||
primary_frame_ = t_false;
|
||||
}
|
||||
std::vector<n_token::t_token> color = utils::split_token(cfg[frame_string + z_text_color]);
|
||||
std::vector<n_token::t_token> color = utils::split_attr(cfg[frame_string + z_text_color]);
|
||||
if (color.size() == 3) {
|
||||
text_color_ = display::rgb(atoi(color[0].c_str()),
|
||||
atoi(color[1].c_str()), atoi(color[2].c_str()));
|
||||
|
@ -306,7 +306,7 @@ frame_builder::frame_builder(const config& cfg,const n_token::t_token& frame_str
|
|||
duration(cfg[frame_string + z_end].to_int() - cfg[frame_string + z_begin].to_int());
|
||||
}
|
||||
|
||||
color = utils::split_token(cfg[frame_string + z_blend_color]);
|
||||
color = utils::split_attr(cfg[frame_string + z_blend_color]);
|
||||
if (color.size() == 3) {
|
||||
blend_with_ = display::rgb(atoi(color[0].c_str()),
|
||||
atoi(color[1].c_str()), atoi(color[2].c_str()));
|
||||
|
|
|
@ -111,11 +111,11 @@ bool attack_type::matches_filter(const config& cfg,bool self) const
|
|||
static const config::t_token z_name("name", false);
|
||||
static const config::t_token z_type("type", false);
|
||||
static const config::t_token z_special("special", false);
|
||||
const std::vector<config::t_token>& filter_range = utils::split_token(cfg[z_range]);
|
||||
const config::t_token& filter_damage = cfg[z_damage];
|
||||
const std::vector<config::t_token> filter_name = utils::split_token(cfg[z_name]);
|
||||
const std::vector<config::t_token> filter_type = utils::split_token(cfg[z_type]);
|
||||
const config::t_token filter_special = cfg[z_special];
|
||||
const std::vector<config::t_token>& filter_range = utils::split_attr(cfg[z_range]);
|
||||
const config::attribute_value& filter_damage = cfg[z_damage];
|
||||
const std::vector<config::t_token> filter_name = utils::split_attr(cfg[z_name]);
|
||||
const std::vector<config::t_token> filter_type = utils::split_attr(cfg[z_type]);
|
||||
const config::attribute_value filter_special = cfg[z_special];
|
||||
|
||||
if(filter_range.empty() == false && std::find(filter_range.begin(),filter_range.end(),range()) == filter_range.end())
|
||||
return false;
|
||||
|
@ -130,7 +130,7 @@ bool attack_type::matches_filter(const config& cfg,bool self) const
|
|||
if(filter_type.empty() == false && std::find(filter_type.begin(),filter_type.end(),type()) == filter_type.end())
|
||||
return false;
|
||||
|
||||
if(!self && filter_special.empty() == false && !get_special_bool(filter_special,true))
|
||||
if(!self && filter_special.empty() == false && !get_special_bool(filter_special.token(),true))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -164,37 +164,37 @@ std::pair<bool, config::t_token> attack_type::apply_modification(const config& c
|
|||
if(!matches_filter(cfg,0)) {
|
||||
return std::make_pair(false, n_token::t_token::z_empty()); }
|
||||
|
||||
const config::t_token& set_name = cfg[z_set_name];
|
||||
const t_string& set_desc = cfg[z_set_description];
|
||||
const config::t_token& set_type = cfg[z_set_type];
|
||||
const config::t_token& del_specials = cfg[z_remove_specials];
|
||||
const config::attribute_value& set_name = cfg[z_set_name];
|
||||
const config::attribute_value& set_desc = cfg[z_set_description];
|
||||
const config::attribute_value& set_type = cfg[z_set_type];
|
||||
const config::attribute_value& del_specials = cfg[z_remove_specials];
|
||||
const config &set_specials = cfg.child(z_set_specials);
|
||||
const config::t_token& increase_damage = cfg[z_increase_damage];
|
||||
const config::t_token& increase_attacks = cfg[z_increase_attacks];
|
||||
const config::t_token& set_attack_weight = cfg[z_attack_weight];
|
||||
const config::t_token& set_defense_weight = cfg[z_defense_weight];
|
||||
const config::t_token& increase_accuracy = cfg[z_increase_accuracy];
|
||||
const config::t_token& increase_parry = cfg[z_increase_parry];
|
||||
const config::attribute_value& increase_damage = cfg[z_increase_damage];
|
||||
const config::attribute_value& increase_attacks = cfg[z_increase_attacks];
|
||||
const config::attribute_value& set_attack_weight = cfg[z_attack_weight];
|
||||
const config::attribute_value& set_defense_weight = cfg[z_defense_weight];
|
||||
const config::attribute_value& increase_accuracy = cfg[z_increase_accuracy];
|
||||
const config::attribute_value& increase_parry = cfg[z_increase_parry];
|
||||
|
||||
std::stringstream desc;
|
||||
|
||||
if(set_name.empty() == false) {
|
||||
id_ = set_name;
|
||||
id_ = set_name.token();
|
||||
cfg_[z_name] = id();
|
||||
}
|
||||
|
||||
if(set_desc.empty() == false) {
|
||||
description_ = set_desc;
|
||||
description_ = set_desc.token();
|
||||
cfg_[z_description] = description_;
|
||||
}
|
||||
|
||||
if(set_type.empty() == false) {
|
||||
type_ = set_type;
|
||||
type_ = set_type.token();
|
||||
cfg_[z_type] = type_;
|
||||
}
|
||||
|
||||
if(del_specials.empty() == false) {
|
||||
const std::vector<config::t_token>& dsl = utils::split_token(del_specials);
|
||||
const std::vector<config::t_token>& dsl = utils::split_attr(del_specials);
|
||||
if (config &specials = cfg_.child(z_specials))
|
||||
{
|
||||
config new_specials;
|
||||
|
@ -211,7 +211,7 @@ std::pair<bool, config::t_token> attack_type::apply_modification(const config& c
|
|||
}
|
||||
|
||||
if (set_specials) {
|
||||
const config::t_token &mode = set_specials[z_mode];
|
||||
const config::attribute_value &mode = set_specials[z_mode];
|
||||
if (mode != z_append) {
|
||||
cfg_.clear_children(z_specials);
|
||||
}
|
||||
|
@ -283,8 +283,8 @@ std::pair<bool, config::t_token> attack_type::describe_modification(const confi
|
|||
if(!matches_filter(cfg,0)) {
|
||||
return std::make_pair(false, n_token::t_token::z_empty()); }
|
||||
|
||||
const config::t_token& increase_damage = cfg[z_increase_damage];
|
||||
const config::t_token& increase_attacks = cfg[z_increase_attacks];
|
||||
const config::attribute_value& increase_damage = cfg[z_increase_damage];
|
||||
const config::attribute_value& increase_attacks = cfg[z_increase_attacks];
|
||||
|
||||
std::stringstream desc;
|
||||
|
||||
|
@ -319,11 +319,11 @@ unit_movement_type::unit_movement_type(const config& cfg, const unit_movement_ty
|
|||
static const config::t_token z_defense("defense", false);
|
||||
static const config::t_token z_resistance("resistance", false);
|
||||
|
||||
const t_string& name = cfg[z_name];
|
||||
const config::attribute_value& name = cfg[z_name];
|
||||
if (!name.empty())
|
||||
cfg_[z_name]= cfg[z_name];
|
||||
|
||||
const t_string& flies = cfg[z_flies];
|
||||
const config::attribute_value& flies = cfg[z_flies];
|
||||
if (!flies.empty())
|
||||
cfg_[z_flies]= cfg[z_flies];
|
||||
|
||||
|
@ -346,8 +346,10 @@ config::t_token unit_movement_type::name() const
|
|||
|
||||
if (!cfg_.has_attribute(z_name) && parent_)
|
||||
return parent_->name();
|
||||
else
|
||||
return cfg_[z_name];
|
||||
else {
|
||||
config::attribute_value const & nname = cfg_[z_name];
|
||||
return nname.token();
|
||||
}
|
||||
}
|
||||
|
||||
int unit_movement_type::resistance_against(const attack_type& attack) const
|
||||
|
@ -383,7 +385,7 @@ utils::string_map unit_movement_type::damage_table() const
|
|||
if (const config &resistance = cfg_.child(z_resistance))
|
||||
{
|
||||
foreach (const config::attribute &i, resistance.attribute_range()) {
|
||||
res[i.first] = i.second;
|
||||
res[i.first] = i.second.token();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -786,14 +788,14 @@ void unit_type::build_full(const movement_type_map &mv_types,
|
|||
|
||||
zoc_ = cfg[z_zoc].to_bool(level_ > 0);
|
||||
|
||||
const config::t_token& alpha_blend = cfg[z_alpha];
|
||||
const config::attribute_value& alpha_blend = cfg[z_alpha];
|
||||
if(alpha_blend.empty() == false) {
|
||||
alpha_ = ftofxp(atof(alpha_blend.c_str()));
|
||||
alpha_ = ftofxp(atof(alpha_blend.token().c_str()));
|
||||
}
|
||||
|
||||
const config::t_token& move_type = cfg[z_movement_type];
|
||||
const config::attribute_value& move_type = cfg[z_movement_type];
|
||||
|
||||
const movement_type_map::const_iterator it = mv_types.find(move_type);
|
||||
const movement_type_map::const_iterator it = mv_types.find(move_type.token());
|
||||
|
||||
if(it != mv_types.end()) {
|
||||
DBG_UT << "setting parent for movement_type " << move_type << "\n";
|
||||
|
@ -819,6 +821,7 @@ void unit_type::build_full(const movement_type_map &mv_types,
|
|||
void unit_type::build_help_index(const movement_type_map &mv_types,
|
||||
const race_map &races, const config::const_child_itors &traits)
|
||||
{
|
||||
static const config::t_token z_empty("", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
static const config::t_token z_description("description", false);
|
||||
static const config::t_token z_hitpoints("hitpoints", false);
|
||||
|
@ -846,8 +849,8 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
|
||||
const config &cfg = cfg_;
|
||||
|
||||
type_name_ = cfg_[z_name];
|
||||
description_ = cfg_[z_description];
|
||||
type_name_ = cfg_[z_name].token();
|
||||
description_ = cfg_[z_description].token();
|
||||
hitpoints_ = cfg[z_hitpoints].to_int(1);
|
||||
level_ = cfg[z_level];
|
||||
movement_ = cfg[z_movement].to_int(1);
|
||||
|
@ -858,14 +861,18 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
image_ = cfg_[z_image].token();
|
||||
small_profile_ = cfg_[z_small_profile].token();
|
||||
big_profile_ = cfg_[z_profile].token();
|
||||
adjust_profile(small_profile_, big_profile_, image_);
|
||||
std::pair<config::t_token, config::t_token> new_profiles = adjust_profile(small_profile_, big_profile_, z_empty);
|
||||
cfg_[z_small_profile] = new_profiles.first;
|
||||
cfg_[z_profile] = new_profiles.second;
|
||||
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (gender_types_[i])
|
||||
gender_types_[i]->build_help_index(mv_types, races, traits);
|
||||
}
|
||||
|
||||
const race_map::const_iterator race_it = races.find(cfg[z_race]);
|
||||
config::attribute_value const & rrace = cfg[z_race];
|
||||
const race_map::const_iterator race_it = races.find(rrace.token());
|
||||
if(race_it != races.end()) {
|
||||
race_ = &race_it->second;
|
||||
} else {
|
||||
|
@ -875,7 +882,7 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
// if num_traits is not defined, we use the num_traits from race
|
||||
num_traits_ = cfg[z_num_traits].to_int(race_->num_traits());
|
||||
|
||||
const std::vector<config::t_token> genders = utils::split_token(cfg[z_gender]);
|
||||
const std::vector<config::t_token> genders = utils::split_attr(cfg[z_gender]);
|
||||
for(std::vector<config::t_token>::const_iterator g = genders.begin(); g != genders.end(); ++g) {
|
||||
genders_.push_back(string_gender(*g));
|
||||
}
|
||||
|
@ -886,10 +893,10 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
if (const config &abil_cfg = cfg.child(z_abilities))
|
||||
{
|
||||
foreach (const config::any_child &ab, abil_cfg.all_children_range()) {
|
||||
const t_string &name = ab.cfg[z_name];
|
||||
const config::attribute_value &name = ab.cfg[z_name];
|
||||
if (!name.empty()) {
|
||||
abilities_.push_back(name);
|
||||
ability_tooltips_.push_back(ab.cfg[z_description]);
|
||||
abilities_.push_back(name.t_str());
|
||||
ability_tooltips_.push_back(ab.cfg[z_description].token());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -903,10 +910,10 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
continue;
|
||||
}
|
||||
foreach (const config::any_child &ab, abil_cfg.all_children_range()) {
|
||||
const t_string &name = ab.cfg[z_name];
|
||||
const config::attribute_value &name = ab.cfg[z_name];
|
||||
if (!name.empty()) {
|
||||
adv_abilities_.push_back(name);
|
||||
adv_ability_tooltips_.push_back(ab.cfg[z_description]);
|
||||
adv_abilities_.push_back(name.t_str());
|
||||
adv_ability_tooltips_.push_back(ab.cfg[z_description].token());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -961,9 +968,9 @@ void unit_type::build_created(const movement_type_map &mv_types,
|
|||
gender_types_[i]->build_created(mv_types, races, traits);}
|
||||
}
|
||||
|
||||
const config::t_token& advances_to_val = cfg[z_advances_to];
|
||||
const config::attribute_value& advances_to_val = cfg[z_advances_to];
|
||||
if(advances_to_val != z_null && advances_to_val != n_token::t_token::z_empty())
|
||||
advances_to_ = utils::split_token(advances_to_val);
|
||||
advances_to_ = utils::split_attr(advances_to_val);
|
||||
DBG_UT << "unit_type '" << id() << "' advances to : " << advances_to_val << "\n";
|
||||
|
||||
experience_needed_ = cfg[z_experience].to_int(500);
|
||||
|
@ -1108,9 +1115,9 @@ std::vector<config::t_token> unit_type::get_ability_list() const
|
|||
if (!abilities) return res;
|
||||
|
||||
foreach (const config::any_child &ab, abilities.all_children_range()) {
|
||||
const config::t_token &id = ab.cfg[z_id];
|
||||
const config::attribute_value &id = ab.cfg[z_id];
|
||||
if (!id.empty())
|
||||
res.push_back(id);
|
||||
res.push_back(id.token());
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -1124,13 +1131,13 @@ void unit_type::add_advancement(const unit_type &to_unit,int xp)
|
|||
{
|
||||
static const config::t_token z_id("id", false);
|
||||
|
||||
const config::t_token &to_id = to_unit.cfg_[z_id];
|
||||
const config::t_token &from_id = cfg_[z_id];
|
||||
const config::attribute_value &to_id = to_unit.cfg_[z_id];
|
||||
const config::attribute_value &from_id = cfg_[z_id];
|
||||
|
||||
// Add extra advancement path to this unit type
|
||||
LOG_CONFIG << "adding advancement from " << from_id << " to " << to_id << "\n";
|
||||
if(std::find(advances_to_.begin(), advances_to_.end(), to_id) == advances_to_.end()) {
|
||||
advances_to_.push_back(to_id);
|
||||
advances_to_.push_back(to_id.token());
|
||||
} else {
|
||||
LOG_CONFIG << "advancement from " << from_id
|
||||
<< " to " << to_id << " already known, ignoring.\n";
|
||||
|
@ -1257,11 +1264,12 @@ void unit_type_data::set_config(config &cfg)
|
|||
|
||||
foreach (config &ut, cfg.child_range(z_unit_type))
|
||||
{
|
||||
config::t_token id = ut[z_id];
|
||||
config::attribute_value id = ut[z_id];
|
||||
if (const config &bu = ut.child(z_base_unit))
|
||||
{
|
||||
config::attribute_value buid = bu[z_id];
|
||||
// Derive a new unit type from an existing base unit id
|
||||
config merge_cfg = find_config(bu[z_id]);
|
||||
config merge_cfg = find_config(buid.token());
|
||||
ut.clear_children(z_base_unit);
|
||||
merge_cfg.merge_with(ut);
|
||||
ut.swap(merge_cfg);
|
||||
|
@ -1392,13 +1400,13 @@ void unit_type_data::read_hide_help(const config& cfg)
|
|||
hide_help_race_.push_back(boost::unordered_set<config::t_token>());
|
||||
hide_help_type_.push_back(boost::unordered_set<config::t_token>());
|
||||
|
||||
std::vector<config::t_token> races = utils::split_token(cfg[z_race]);
|
||||
std::vector<config::t_token> races = utils::split_attr(cfg[z_race]);
|
||||
hide_help_race_.back().insert(races.begin(), races.end());
|
||||
|
||||
std::vector<config::t_token> types = utils::split_token(cfg[z_type]);
|
||||
std::vector<config::t_token> types = utils::split_attr(cfg[z_type]);
|
||||
hide_help_type_.back().insert(types.begin(), types.end());
|
||||
|
||||
std::vector<config::t_token> trees = utils::split_token(cfg[z_type_adv_tree]);
|
||||
std::vector<config::t_token> trees = utils::split_attr(cfg[z_type_adv_tree]);
|
||||
hide_help_type_.back().insert(trees.begin(), trees.end());
|
||||
foreach(const config::t_token& t_id, trees) {
|
||||
unit_type_map::iterator ut = types_.find(t_id);
|
||||
|
@ -1437,10 +1445,10 @@ void unit_type_data::add_advancement(unit_type& to_unit) const
|
|||
|
||||
foreach (const config &af, cfg.child_range(z_advancefrom))
|
||||
{
|
||||
const config::t_token &from = af[z_unit];
|
||||
const config::attribute_value &from = af[z_unit];
|
||||
int xp = af[z_experience];
|
||||
|
||||
unit_type_data::unit_type_map::iterator from_unit = types_.find(from);
|
||||
unit_type_data::unit_type_map::iterator from_unit = types_.find(from.token());
|
||||
|
||||
if (from_unit == types_.end()) {
|
||||
std::ostringstream msg;
|
||||
|
@ -1496,9 +1504,9 @@ bool unit_type::not_living() const
|
|||
// about gender checks, since we don't
|
||||
// know what the gender of the
|
||||
// hypothetical recruit is.
|
||||
const config::t_token &ut = effect[z_unit_type];
|
||||
const config::attribute_value &ut = effect[z_unit_type];
|
||||
if (!ut.empty()) {
|
||||
const std::vector<config::t_token> &types = utils::split_token(ut);
|
||||
const std::vector<config::t_token> &types = utils::split_attr(ut);
|
||||
if(std::find(types.begin(), types.end(), id()) == types.end())
|
||||
continue;
|
||||
}
|
||||
|
@ -1534,20 +1542,18 @@ bool unit_type::has_random_traits() const
|
|||
|
||||
unit_type_data unit_types;
|
||||
|
||||
void adjust_profile(config::t_token &small, config::t_token &big, config::t_token const &def)
|
||||
{
|
||||
if (big.empty())
|
||||
{
|
||||
std::pair<config::t_token, config::t_token> adjust_profile(config::t_token const &ismall, config::t_token const &ibig, config::t_token const &def) {
|
||||
config::t_token big(ibig), small(ismall);
|
||||
if (ibig.empty() || ibig == n_token::t_token::z_empty()) {
|
||||
// No profile data; use the default image.
|
||||
small = def;
|
||||
big = def;
|
||||
}
|
||||
else if (small.empty())
|
||||
{
|
||||
else if (ismall.empty() || ismall == n_token::t_token::z_empty()) {
|
||||
// No small profile; use the current profile for it and
|
||||
// try to infer the big one.
|
||||
small = big;
|
||||
std::string sbig = (*big);
|
||||
small = ibig;
|
||||
std::string sbig = (*ibig);
|
||||
std::string::size_type offset = sbig.find('~');
|
||||
offset = sbig.find_last_of('/', offset);
|
||||
if (offset != std::string::npos) {
|
||||
|
@ -1561,4 +1567,5 @@ void adjust_profile(config::t_token &small, config::t_token &big, config::t_toke
|
|||
big = config::t_token(sbig);
|
||||
}
|
||||
}
|
||||
return std::make_pair(small, big);
|
||||
}
|
||||
|
|
|
@ -417,6 +417,6 @@ private:
|
|||
|
||||
extern unit_type_data unit_types;
|
||||
|
||||
void adjust_profile(config::t_token &small, config::t_token &big, config::t_token const &def);
|
||||
std::pair<config::t_token, config::t_token> adjust_profile(config::t_token const &small, config::t_token const &big, config::t_token const &def);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -81,18 +81,6 @@ typedef boost::unordered_map<config const *, std::string const *> t_config_hashe
|
|||
t_config_hashes config_hashes;
|
||||
|
||||
|
||||
//Static tokens instantiated a single time as replacements for string literals
|
||||
static const config::t_token z_insert_tag("insert_tag", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
static const config::t_token z_variable("variable", false);
|
||||
static const config::t_token z_x("x", false);
|
||||
static const config::t_token z_y("y", false);
|
||||
static const config::t_token z_recall("recall", false);
|
||||
static const config::t_token z_length("length", false);
|
||||
static const config::t_token z___array("__array", false);
|
||||
static const config::t_token z___value("__value", false);
|
||||
|
||||
|
||||
config empty_config;
|
||||
|
||||
struct compare_str_ptr {
|
||||
|
@ -261,8 +249,11 @@ vconfig& vconfig::operator=(const vconfig& cfg)
|
|||
return *this;
|
||||
}
|
||||
|
||||
const config vconfig::get_parsed_config() const
|
||||
{
|
||||
const config vconfig::get_parsed_config() const {
|
||||
static const config::t_token z_insert_tag("insert_tag", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
static const config::t_token z_variable("variable", false);
|
||||
|
||||
config res;
|
||||
foreach (const config::attribute &i, cfg_->attribute_range()) {
|
||||
res[i.first] = expand(i.first);
|
||||
|
@ -272,24 +263,24 @@ const config vconfig::get_parsed_config() const
|
|||
{
|
||||
if (child.key == z_insert_tag) {
|
||||
vconfig insert_cfg(child.cfg);
|
||||
const t_string& name = insert_cfg[z_name];
|
||||
const t_string& vname = insert_cfg[z_variable];
|
||||
const config::attribute_value& name = insert_cfg[z_name];
|
||||
const config::attribute_value& vname = insert_cfg[z_variable];
|
||||
if(!vconfig_recursion.insert(vname).second) {
|
||||
throw recursion_error("vconfig::get_parsed_config() infinite recursion detected, aborting");
|
||||
}
|
||||
try {
|
||||
variable_info vinfo(vname.token(), false, variable_info::TYPE_CONTAINER);
|
||||
if(!vinfo.is_valid()) {
|
||||
res.add_child(name); //add empty tag
|
||||
res.add_child(name.token()); //add empty tag
|
||||
} else if(vinfo.is_explicit_index()) {
|
||||
res.add_child(name, vconfig(vinfo.as_container()).get_parsed_config());
|
||||
res.add_child(name.token(), vconfig(vinfo.as_container()).get_parsed_config());
|
||||
} else {
|
||||
variable_info::array_range range = vinfo.as_array();
|
||||
if(range.first == range.second) {
|
||||
res.add_child(name); //add empty tag
|
||||
res.add_child(name.token()); //add empty tag
|
||||
}
|
||||
while(range.first != range.second) {
|
||||
res.add_child(name, vconfig(*range.first++).get_parsed_config());
|
||||
res.add_child(name.token(), vconfig(*range.first++).get_parsed_config());
|
||||
}
|
||||
}
|
||||
vconfig_recursion.erase(vname);
|
||||
|
@ -310,8 +301,11 @@ const config vconfig::get_parsed_config() const
|
|||
return res;
|
||||
}
|
||||
|
||||
vconfig::child_list vconfig::get_children(const config::t_token& key) const
|
||||
{
|
||||
vconfig::child_list vconfig::get_children(const config::t_token& key) const {
|
||||
static const config::t_token z_insert_tag("insert_tag", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
static const config::t_token z_variable("variable", false);
|
||||
|
||||
vconfig::child_list res;
|
||||
|
||||
foreach (const config::any_child &child, cfg_->all_children_range())
|
||||
|
@ -349,6 +343,10 @@ vconfig::child_list vconfig::get_children(const std::string& key) const {return
|
|||
|
||||
vconfig vconfig::child(const config::t_token& key) const
|
||||
{
|
||||
static const config::t_token z_insert_tag("insert_tag", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
static const config::t_token z_variable("variable", false);
|
||||
|
||||
if (const config &natural = cfg_->child(key)) {
|
||||
return vconfig(&natural, cache_key_);
|
||||
}
|
||||
|
@ -370,6 +368,9 @@ vconfig vconfig::child(const std::string& key) const {return child(t_token(key))
|
|||
|
||||
bool vconfig::has_child(const config::t_token& key) const
|
||||
{
|
||||
static const config::t_token z_insert_tag("insert_tag", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
|
||||
if (cfg_->child(key)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -414,6 +415,9 @@ vconfig::all_children_iterator::all_children_iterator(const Itor &i, const confi
|
|||
}
|
||||
|
||||
vconfig::all_children_iterator& vconfig::all_children_iterator::operator++() {
|
||||
static const config::t_token z_insert_tag("insert_tag", false);
|
||||
static const config::t_token z_variable("variable", false);
|
||||
|
||||
if (inner_index_ >= 0 && i_->key == z_insert_tag)
|
||||
{
|
||||
variable_info vinfo(vconfig(i_->cfg)[z_variable].token(), false, variable_info::TYPE_CONTAINER);
|
||||
|
@ -450,15 +454,22 @@ vconfig::all_children_iterator::pointer vconfig::all_children_iterator::operator
|
|||
|
||||
config::t_token vconfig::all_children_iterator::get_key() const
|
||||
{
|
||||
static const config::t_token z_insert_tag("insert_tag", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
|
||||
const config::t_token &key = i_->key;
|
||||
if (inner_index_ >= 0 && key == z_insert_tag) {
|
||||
return vconfig(i_->cfg)[z_name];
|
||||
config::attribute_value const & xx= vconfig(i_->cfg)[z_name];
|
||||
return xx.token();
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
vconfig vconfig::all_children_iterator::get_child() const
|
||||
{
|
||||
static const config::t_token z_insert_tag("insert_tag", false);
|
||||
static const config::t_token z_variable("variable", false);
|
||||
|
||||
if (inner_index_ >= 0 && i_->key == z_insert_tag)
|
||||
{
|
||||
config * cp;
|
||||
|
@ -536,6 +547,9 @@ scoped_wml_variable::~scoped_wml_variable()
|
|||
|
||||
void scoped_xy_unit::activate()
|
||||
{
|
||||
static const config::t_token z_x("x", false);
|
||||
static const config::t_token z_y("y", false);
|
||||
|
||||
map_location loc = map_location(x_, y_);
|
||||
unit_map::const_iterator itor = umap_.find(loc);
|
||||
if(itor != umap_.end()) {
|
||||
|
@ -558,6 +572,10 @@ void scoped_weapon_info::activate()
|
|||
|
||||
void scoped_recall_unit::activate()
|
||||
{
|
||||
static const config::t_token z_x("x", false);
|
||||
static const config::t_token z_y("y", false);
|
||||
static const config::t_token z_recall("recall", false);
|
||||
|
||||
const t_teams& teams = teams_manager::get_teams();
|
||||
t_teams::const_iterator team_it;
|
||||
for (team_it = teams.begin(); team_it != teams.end(); ++team_it) {
|
||||
|
@ -716,6 +734,9 @@ void activate_scope_variable(t_parsed_tokens const & tokens)
|
|||
|
||||
|
||||
void variable_info::init(const config::t_token& varname, bool force_valid) {
|
||||
static const config::t_token z_length("length", false);
|
||||
static const config::t_token z___array("__array", false);
|
||||
static const config::t_token z___value("__value", false);
|
||||
try {
|
||||
|
||||
//an example varname is "unit_store.modifications.trait[0]"
|
||||
|
@ -798,7 +819,7 @@ void variable_info::init(const config::t_token& varname, bool force_valid) {
|
|||
//Process the last token
|
||||
|
||||
key = i->token;
|
||||
if(i->index != t_parsed::NO_INDEX){
|
||||
if(i->index != t_parsed::NO_INDEX && i->index != 0){
|
||||
explicit_index_ = true;
|
||||
size_t size = vars->child_count(key);
|
||||
index = i->index;
|
||||
|
|
Loading…
Add table
Reference in a new issue