예제 #1
0
파일: team.cpp 프로젝트: aquileia/wesnoth
void team::team_info::write(config& cfg) const
{
	cfg["gold"] = gold;
	cfg["start_gold"] = start_gold;
	cfg["income"] = income;
	cfg["team_name"] = team_name;
	cfg["user_team_name"] = user_team_name;
	cfg["side_name"] = side_name;
	cfg["faction"] = faction;
	cfg["faction_name"] = faction_name;
	cfg["save_id"] = save_id;
	cfg["current_player"] = current_player;
	cfg["flag"] = flag;
	cfg["flag_icon"] = flag_icon;
	cfg["id"] = id;
	cfg["objectives"] = objectives;
	cfg["objectives_changed"] = objectives_changed;
	cfg["countdown_time"]= countdown_time;
	cfg["action_bonus_count"]= action_bonus_count;
	cfg["village_gold"] = income_per_village;
	cfg["village_support"] = support_per_village;
	cfg["recall_cost"] = recall_cost;
	cfg["disallow_observers"] = disallow_observers;
	cfg["allow_player"] = allow_player;
	cfg["chose_random"] = chose_random;
	cfg["no_leader"] = no_leader;
	cfg["defeat_condition"] = defeat_condition;
	cfg["hidden"] = hidden;
	cfg["suppress_end_turn_confirmation"] = no_turn_confirmation;
	cfg["scroll_to_leader"] = scroll_to_leader;
	cfg["controller"] = controller;
	cfg["recruit"] = utils::join(can_recruit);
	cfg["share_vision"] = share_vision;

	cfg["color"] = color;
	cfg["persistent"] = persistent;
	cfg["lost"] = lost;
	cfg["carryover_percentage"] = carryover_percentage;
	cfg["carryover_add"] = carryover_add;
	cfg["carryover_bonus"] = carryover_bonus;
	cfg["carryover_gold"] = carryover_gold;

	cfg.add_child("variables", variables);
	cfg.add_child("ai", ai::manager::to_config(side));
}
예제 #2
0
void wmi_container::to_config(config& cfg) const
{
	// Loop through our items.
	BOOST_FOREACH( const item_ptr & item, *this )
	{
		// Add this item as a child of cfg.
		item->to_config(cfg.add_child("menu_item"));
	}
}
예제 #3
0
/**
 * Writes this into the provided config.
 */
void recruit_action::write(config & cfg) const
{
	undo_action::write(cfg);
	shroud_clearing_action::write(cfg);

	recruit_from.write(cfg.add_child("leader"));
	config & child = cfg.child("unit");
	child["type"] = u_type.base_id();
}
예제 #4
0
void manager::write_sourcespecs(config& cfg) const
{
	for(positional_source_const_iterator i = sources_.begin(); i != sources_.end(); ++i) {
		assert(i->second);

		config& child = cfg.add_child("sound_source");
		child["id"] = i->first;
		i->second->write_config(child);
	}
}
예제 #5
0
static void utype_anim_replace_cfg_inernal(const config& src, config& dst, const utils::string_map& symbols)
{
	BOOST_FOREACH (const config::any_child& c, src.all_children_range()) {
		config& adding = dst.add_child(c.key);
		BOOST_FOREACH (const config::attribute &i, c.cfg.attribute_range()) {
			adding[i.first] = utils::interpolate_variables_into_string(i.second, &symbols);
		}
		utype_anim_replace_cfg_inernal(c.cfg, adding, symbols);
	}
}
예제 #6
0
/**
 * Writes merged data to a config.
 * @param[out] out_cfg     The config that will receive the data.
 * @param[in]  child_name  If not empty, create and write to a child config with this tag.
 *                         This *will* be created even if there is no data to write.
 * @param[in]  fallback    If not nullptr, its data will be merged with ours for the write.
 */
void movetype::terrain_info::data::write(
	config & out_cfg, const std::string & child_name, const terrain_info * fallback) const
{
	// Get a place to write to.
	config & merged = child_name.empty() ? out_cfg : out_cfg.add_child(child_name);

	if ( fallback )
		fallback->write(merged, "", true);
	merged.merge_with(cfg_);
}
예제 #7
0
/**
 * Writes to a config.
 */
void clearer_info::write(config & cfg) const
{
	// The key and tag names are intended to mirror those used by [unit]
	// (so a clearer_info can be constructed from a unit's config).
	cfg["underlying_id"] = underlying_id;
	cfg["vision"] = sight_range;
	if ( slowed )
		cfg.add_child("status")["slowed"] = true;
	costs.write(cfg, "vision_costs");
}
void music_track::write(config &parent_node, bool append) const
{
	config& m = parent_node.add_child("music");
	m["name"] = id_;
	m["ms_before"] = ms_before_;
	m["ms_after"] = ms_after_;
	if(append) {
		m["append"] = true;
	}
}
예제 #9
0
/**
 * Writes our data to a config, as a child if @a child_name is specified.
 * (No child is created if there is no data.)
 */
void movetype::resistances::write(config & out_cfg, const std::string & child_name) const
{
	if ( cfg_.empty() )
		return;

	if ( child_name.empty() )
		out_cfg.merge_with(cfg_);
	else
		out_cfg.add_child(child_name, cfg_);
}
예제 #10
0
파일: client.cpp 프로젝트: ehsan/wesnoth
bool addons_client::install_addon(config& archive_cfg, const addon_info& info)
{
	const cursor::setter cursor_setter(cursor::WAIT);

	utils::string_map i18n_symbols;
	i18n_symbols["addon_title"] = info.title;

	if(!check_names_legal(archive_cfg)) {
		gui2::show_error_message(disp_.video(),
			vgettext("The add-on <i>$addon_title</i> has an invalid file or directory "
				"name and cannot be installed.", i18n_symbols));
		return false;
	}

	// Add local version information before unpacking

	config* maindir = &archive_cfg.find_child("dir", "name", info.id);
	if(!*maindir) {
		LOG_ADDONS << "downloaded add-on '" << info.id << "' is missing its directory in the archive; creating it\n";
		maindir = &archive_cfg.add_child("dir");
		(*maindir)["name"] = info.id;
	}

	LOG_ADDONS << "generating version info for add-on '" << info.id << "'\n";

	std::ostringstream info_contents;
	config wml;

	info_contents <<
		"#\n"
		"# File automatically generated by Wesnoth to keep track\n"
		"# of version information on installed add-ons. DO NOT EDIT!\n"
		"#\n";

	info.write_minimal(wml.add_child("info"));
	write(info_contents, wml);

	config file;
	file["name"] = "_info.cfg";
	file["contents"] = info_contents.str();

	maindir->add_child("file", file);

	LOG_ADDONS << "unpacking " << info.id << '\n';

	// Remove any previously installed versions
	if(!remove_local_addon(info.id)) {
		WRN_ADDONS << "failed to uninstall previous version of " << info.id << "; the add-on may not work properly!\n";
	}

	unarchive_addon(archive_cfg);
	LOG_ADDONS << "unpacking finished\n";

	return true;
}
예제 #11
0
void save_hotkeys(config& cfg)
{
	cfg.clear_children("hotkey");

	for (hotkey_ptr item : hotkeys_) {
		if ((!item->is_default() && item->active()) ||
			(item->is_default() && item->is_disabled())) {
			item->save(cfg.add_child("hotkey"));
		}
	}
}
예제 #12
0
/**
 * If there is data, writes it to a config.
 * @param[out] out_cfg     The config that will receive the data.
 * @param[in]  child_name  If not empty, create and write to a child config with this tag.
 *                         This child will *not* be created if there is no data to write.
 */
void movetype::terrain_info::data::write(
	config & out_cfg, const std::string & child_name) const
{
	if ( cfg_.empty() )
		return;

	if ( child_name.empty() )
		out_cfg.merge_with(cfg_);
	else
		out_cfg.add_child(child_name, cfg_);
}
예제 #13
0
void music_track::write(config &parent_node, bool append) const
{
    config& m = parent_node.add_child("music");
    m["name"] = id_;
    m["ms_before"] = ms_before_;
    m["ms_after"] = ms_after_;
    if(append) {
        m["append"] = true;
    }
    //default behaviour is to shuffle
    m["shuffle"] = shuffle_;
}
예제 #14
0
파일: team.cpp 프로젝트: aquileia/wesnoth
void team::write(config& cfg) const
{
	info_.write(cfg);
	cfg["auto_shroud"] = auto_shroud_updates_;
	cfg["shroud"] = uses_shroud();
	cfg["fog"] = uses_fog();
	cfg["gold"] = gold_;

	// Write village locations
	for(std::set<map_location>::const_iterator t = villages_.begin(); t != villages_.end(); ++t) {
		t->write(cfg.add_child("village"));
	}

	cfg["shroud_data"] = shroud_.write();
	cfg["fog_data"] = fog_.write();
	if ( !fog_clearer_.empty() )
		write_location_range(fog_clearer_, cfg.add_child("fog_override"));

	cfg["countdown_time"] = countdown_time_;
	cfg["action_bonus_count"] = action_bonus_count_;
}
예제 #15
0
void team::write(config& cfg) const
{
	info_.write(cfg);
	cfg["auto_shroud"] = auto_shroud_updates_;
	cfg["shroud"] = uses_shroud();
	cfg["fog"] = uses_fog();
	cfg["gold"] = gold_;

	// Write village locations
	for(const map_location& loc : villages_) {
		loc.write(cfg.add_child("village"));
	}

	cfg["shroud_data"] = shroud_.write();
	cfg["fog_data"] = fog_.write();
	if(!fog_clearer_.empty())
		write_location_range(fog_clearer_, cfg.add_child("fog_override"));

	cfg["countdown_time"] = countdown_time_;
	cfg["action_bonus_count"] = action_bonus_count_;
}
예제 #16
0
void game_data::write_snapshot(config& cfg) const
{
	cfg["next_scenario"] = next_scenario_;

	cfg["can_end_turn"] = can_end_turn_;

	cfg["random_seed"] = rng_.get_random_seed_str();
	cfg["random_calls"] = rng_.get_random_calls();

	cfg.add_child("variables", variables_);

}
예제 #17
0
void carryover::to_config(config& cfg){
	config& side = cfg.add_child("side");
	side["save_id"] = save_id_;
	side["gold"] = gold_;
	side["add"] = add_;
	side["current_player"] = current_player_;
	side["previous_recruits"] = get_recruits(false);
	side.add_child("variables", variables_);
	for(const config & u_cfg : recall_list_) {
		side.add_child("unit", u_cfg);
	}
}
예제 #18
0
void manager::write_events(config& cfg)
{
	for(const handler_ptr &eh : *event_handlers_) {
		if ( !eh || eh->is_menu_item() ) {
			continue;
		}
		cfg.add_child("event", eh->get_config());
	}

	cfg["unit_wml_ids"] = utils::join(unit_wml_ids_);
	wml_menu_items_.to_config(cfg);
}
예제 #19
0
void map_labels::write(config& res) const
{
	for (team_label_map::const_iterator labs = labels_.begin(); labs != labels_.end(); ++labs)
	{
		for(label_map::const_iterator i = labs->second.begin(); i != labs->second.end(); ++i) {
			config item;
			i->second->write(item);


			res.add_child("label",item);
		}
	}
}
예제 #20
0
bool playturn_network_adapter::read(config& dst)
{
	assert(dst.empty());
	if(is_at_end())
	{
		read_from_network();
	}
	if(is_at_end())
	{
		//that means we couldn't read anything from the network.
		return false;
	}
	//skip empty data.
	while(next_ == data_.begin()->ordered_end())
	{
		data_.pop_front();
		next_ = data_.front().ordered_begin();
		assert(!is_at_end());
	}
	config& child = dst.add_child(next_->key);
	//TODO: implement a non const version of ordered children
	config& child_old = const_cast<config&>(next_->cfg);
	if(next_->key == "turn")
	{
		//split [turn] indo different [turn] for each child.
		assert(next_->cfg.all_children_count() > next_command_num_);
		config::all_children_iterator itor = child_old.ordered_begin();
		//TODO: implement operator + (all_children_iterator, int ) properly
		std::advance(itor, next_command_num_);
		//TODO: implement a non const version of ordered children
		config& childchild_old = const_cast<config&>(itor->cfg);
		config& childchild = child.add_child(itor->key);
		childchild.swap(childchild_old);
		
		++next_command_num_;
		if(next_->cfg.all_children_count() == next_command_num_)
		{
			next_command_num_ = 0;
			++next_;
		}
		return true;
	}
	else
	{
		child.swap(child_old);
		++next_;
		return true;
	}
}
예제 #21
0
void loadgame::fill_mplevel_config(config& level)
{
	// If we have a start of scenario MP campaign scenario the snapshot
	// is empty the starting position contains the wanted info.
	const config& start_data = !gamestate_.snapshot.empty() ? gamestate_.snapshot : gamestate_.starting_pos;
	level["map_data"] = start_data["map_data"];
	level["id"] = start_data["id"];
	level["name"] = start_data["name"];
	level["completion"] = start_data["completion"];
	// Probably not needed.
	level["turn"] = start_data["turn_at"];
	level["turn_at"] = start_data["turn_at"];

	level.add_child("multiplayer", gamestate_.mp_settings().to_config());

	//Start-of-scenario save
	if(gamestate_.snapshot.empty()){
		//For a start-of-scenario-save, write the data to the starting_pos and not the snapshot, since
		//there should only be snapshots for midgame reloads
		if (config &c = level.child("replay_start")) {
			c.merge_with(start_data);
		} else {
			level.add_child("replay_start") = start_data;
		}
		level.add_child("snapshot") = config();
	} else {
		level.add_child("snapshot") = start_data;
		level.add_child("replay_start") = gamestate_.starting_pos;
	}
	level["random_seed"] = start_data["random_seed"];
	level["random_calls"] = start_data["random_calls"];

	// Adds the replay data, and the replay start, to the level,
	// so clients can receive it.
	// level.add_child("statistics") = statistics::write_stats();
}
예제 #22
0
void wmi_container::to_config(config& cfg){
	for(std::map<std::string, wml_menu_item *>::const_iterator j=wml_menu_items_.begin();
		j!=wml_menu_items_.end(); ++j) {
		config new_cfg;
		new_cfg["id"]=j->first;
		new_cfg["image"]=j->second->image;
		new_cfg["description"]=j->second->description;
		new_cfg["needs_select"] = j->second->needs_select;
		if(!j->second->show_if.empty())
			new_cfg.add_child("show_if", j->second->show_if);
		if(!j->second->filter_location.empty())
			new_cfg.add_child("filter_location", j->second->filter_location);
		if(!j->second->command.empty())
			new_cfg.add_child("command", j->second->command);
		cfg.add_child("menu_item", new_cfg);
	}
}
예제 #23
0
void attack_type::write(config& cfg) const
{
	cfg["description"] = description_;
	cfg["name"] = id_;
	cfg["type"] = type_;
	cfg["icon"] = icon_;
	cfg["range"] = range_;
	cfg["min_range"] = min_range_;
	cfg["max_range"] = max_range_;
	cfg["damage"] = damage_;
	cfg["number"] = num_attacks_;
	cfg["attack_weight"] = attack_weight_;
	cfg["defense_weight"] = defense_weight_;
	cfg["accuracy"] = accuracy_;
	cfg["movement_used"] = movement_used_;
	cfg["parry"] = parry_;
	cfg.add_child("specials", specials_);
}
/** Read the file with the tips-of-the-day. */
void read_tips_of_day(config& tips_of_day)
{
	tips_of_day.clear();
	LOG_CF << "Loading tips of day\n";
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/tips.cfg"));
		read(tips_of_day, *stream);
	} catch(config::error&) {
		ERR_CF << "Could not read data/hardwired/tips.cfg\n";
	}

	//We shuffle the tips after each initial loading.
	config::const_child_itors itors = tips_of_day.child_range("tip");
	if (itors.first != itors.second ) {
		std::vector<config> tips(itors.first, itors.second);
		std::random_shuffle(tips.begin(), tips.end());
		tips_of_day.clear();
		foreach (const config &tip, tips) {
			tips_of_day.add_child("tip", tip);
		}
예제 #25
0
void save_hotkeys(config& cfg)
{
	cfg.clear_children(hotkey_tag_name);

	for(std::vector<hotkey_item>::iterator i = hotkeys_.begin(); i != hotkeys_.end(); ++i) {
		if (i->hidden() || i->get_type() == hotkey_item::UNBOUND || !i->is_in_active_scope())
			continue;

		config& item = cfg.add_child(hotkey_tag_name);
		item["command"] = i->get_command();
		if (i->get_type() == hotkey_item::CLEARED)
		{
			item["key"] = CLEARED_TEXT;
			continue;
		}

		if (i->get_type() == hotkey_item::BUTTON)
		{
			item["joystick"] = i->get_joystick();
			item["button"] = i->get_button();
		}

		if (i->get_type() == hotkey_item::HAT)
		{
			item["joystick"] = i->get_joystick();
			item["hat"] = i->get_hat();
			item["value"] = i->get_value();
		}

		if (i->get_type() == hotkey_item::BY_KEYCODE) {
			item["key"] = SDL_GetKeyName(SDLKey(i->get_keycode()));
			item["shift"] = i->get_shift();
		} else if (i->get_type() == hotkey_item::BY_CHARACTER) {
			item["key"] = utils::wchar_to_string(i->get_character());
		}
		item["alt"] = i->get_alt();
		item["ctrl"] = i->get_ctrl();
		item["cmd"] = i->get_cmd();
	}
}
예제 #26
0
void utype_anim_create_cfg(const std::string& anim_renamed_key, const std::string& tpl_id, config& dst, const utils::string_map& symbols)
{
	typedef std::multimap<std::string, const config>::const_iterator Itor;
	std::pair<Itor, Itor> its = instance->utype_anim_tpls().equal_range(tpl_id);
	while (its.first != its.second) {
		// tpl          animation instance
		// [anim] ----> [anim_renamed_key]
		config& sub_cfg = dst.add_child(anim_renamed_key);
		if (symbols.count("offset_x")) {
			sub_cfg["offset_x"] = symbols.find("offset_x")->second;
		}
		if (symbols.count("offset_y")) {
			sub_cfg["offset_y"] = symbols.find("offset_y")->second;
		}
		const config& anim_cfg = its.first->second;
		// replace
		BOOST_FOREACH (const config::attribute &i, anim_cfg.attribute_range()) {
			sub_cfg[i.first] = utils::interpolate_variables_into_string(i.second, &symbols);
		}
		utype_anim_replace_cfg_inernal(anim_cfg, sub_cfg, symbols);
		++ its.first;
	}
}
예제 #27
0
파일: unit2.cpp 프로젝트: suxinde2009/Rose
void unit2::generate_window(config& cfg) const
{
	cfg["name"] = cell_.id;
	cfg["description"] = t_string(cell_.window.description, cell_.window.textdomain);
	if (cell_.window.orientation != gui2::twidget::auto_orientation) {
		cfg["orientation"] = gui2::orientations.find(cell_.window.orientation)->second.id;
	}

	config& res_cfg = cfg.add_child("resolution");
	res_cfg["id"] = "1024x768";
	res_cfg["width"] = "1024";
	res_cfg["height"] = "768";

	config& screen_cfg = res_cfg.add_child("screen");
	screen_cfg["id"] = "screen";
	screen_cfg["rect"] = "0,0,1024,768";

	config& border_cfg = res_cfg.add_child("main_map_border");
	generate_main_map_border(border_cfg);

	controller_.generate_linked_groups(res_cfg);
	controller_.generate_context_menus(res_cfg);
}
예제 #28
0
파일: theme.cpp 프로젝트: dodikk/iWesnoth
static void do_resolve_rects(const config& cfg, config& resolved_config, config* resol_cfg = NULL) 
{
		// recursively resolve children
		for(config::all_children_iterator i = cfg.ordered_begin(); i != cfg.ordered_end(); ++i) {
			const config::all_children_iterator::value_type& value = *i;
			config& childcfg = resolved_config.add_child(value.first);
			do_resolve_rects(*value.second, childcfg, (value.first == "resolution") ? &childcfg : resol_cfg);
		}

		// copy all key/values
		for(string_map::const_iterator j = cfg.values.begin(); j != cfg.values.end(); ++j) {
			resolved_config.values[j->first] = j->second;
		}

		// override default reference rect with "ref" parameter if any
		if (!cfg["ref"].empty()) {
			if (resol_cfg == NULL) {
				ERR_DP << "Use of ref= outside a [resolution] block\n";
			} else {
				//DBG_DP << ">> Looking for " << cfg["ref"] << "\n";
				const config ref = find_ref (cfg["ref"], *resol_cfg);

				if (ref["id"].empty()) {
					ERR_DP << "Reference to non-existent rect id \"" << cfg["ref"] << "\"\n";
				} else if (ref["rect"].empty()) {
					ERR_DP << "Reference to id \"" << cfg["ref"] <<
						"\" which does not have a \"rect\"\n";
				} else {
					ref_rect = read_rect(ref);
				}
			}
		}
		// resolve the rect value to absolute coordinates
		if (!cfg["rect"].empty()) {
			resolved_config.values["rect"] = resolve_rect(cfg["rect"]);
		}
	}
예제 #29
0
/** Read the file with the tips-of-the-day. */
void read_tips_of_day(config& tips_of_day)
{
	tips_of_day.clear();
	LOG_CF << "Loading tips of day\n";
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/tips.cfg"));
		read(tips_of_day, *stream);
	} catch(config::error&) {
		ERR_CF << "Could not read data/hardwired/tips.cfg\n";
	}

	//we shuffle the tips after each initial loading. We only shuffle if
	//the upload_log preference has been set. If it hasn't been set, it's the
	//user's first time playing since this feature has been added, so we'll
	//leave the tips in their default order, which will always contain a tip
	//regarding the upload log first, so the user sees it.
	config::const_child_itors itors = tips_of_day.child_range("tip");
	if (itors.first != itors.second && preferences::has_upload_log()) {
		std::vector<config> tips(itors.first, itors.second);
		std::random_shuffle(tips.begin(), tips.end());
		tips_of_day.clear();
		foreach (const config &tip, tips) {
			tips_of_day.add_child("tip", tip);
		}
예제 #30
0
파일: info.cpp 프로젝트: ArtBears/wesnoth
void addon_info::write(config& cfg) const
{
	cfg["id"] = this->id;
	cfg["title"] = this->title;
	cfg["description"] = this->description;
	cfg["icon"] = this->icon;
	cfg["version"] = this->version.str();
	cfg["author"] = this->author;
	cfg["size"] = this->size;
	cfg["downloads"] = this->downloads;
	cfg["uploads"] = this->uploads;
	cfg["type"] = get_addon_type_string(this->type);

	for (const std::string& locale_id : this->locales) {
		cfg.add_child("translation")["language"] = locale_id;
	}

	cfg["core"] = this->core;
	cfg["dependencies"] = utils::join(this->depends);
	cfg["feedback_url"] = this->feedback_url;

	cfg["timestamp"] = this->updated;
	cfg["original_timestamp"] = this->created;
}