Exemplo n.º 1
0
Arquivo: world.cpp Projeto: x2f/wesciv
world::world(wml::const_node_ptr node)
  : map_(hex::generate_gamemap(node)),
    weather_x_(0), weather_y_(0),
    weather_next_turn_(game_logic::formula::create_optional_formula(node->attr("weather_next_turn"))),
    weather_function_(game_logic::formula::create_optional_formula(node->attr("weather_function")))
{
	sides_.push_back(government_ptr(new government));
}
Exemplo n.º 2
0
void terrain_improvement::init(wml::const_node_ptr node)
{
	wml::node::const_child_iterator i1 = node->begin_child("improvement");
	wml::node::const_child_iterator i2 = node->end_child("improvement");
	for(; i1 != i2; ++i1) {
		terrain_improvement_ptr t(new terrain_improvement(i1->second));
		cache[t->id()] = t;
	}
}
Exemplo n.º 3
0
unit_type::unit_type(wml::const_node_ptr node)
  : description_(node->attr("description")),
    texture_(graphics::texture::get(node->attr("image"))),
	movement_(wml::get_int(node, "movement", 10)),
	cost_(wml::get_int(node, "cost", 1))
{
	abilities_ = util::split(node->attr("abilities"));
	ability_build_city_ = has_ability("settle");
}
Exemplo n.º 4
0
 explicit compound_command(wml::const_node_ptr node) {
     if(!node) {
         return;
     }
     
     for(wml::node::const_all_child_iterator i = node->begin_children(); i != node->end_children(); ++i) {
         cmd_.push_back(create(*i));
     }
 }
Exemplo n.º 5
0
void parse_postdraw(wml::const_node_ptr postdraw, fb_ptr builder)
{
	for(wml::node::const_all_child_iterator i = postdraw->begin_children();
	    i != postdraw->end_children(); ++i) {
		fdb_ptr fdb = make_fdb(*i);
		if(!fdb.get()) continue;
		builder->add_postdraw(fdb);
	}
}
Exemplo n.º 6
0
level_tile level_object::build_tile(wml::const_node_ptr node)
{
	level_tile res;
	res.x = wml::get_int(node, "x");
	res.y = wml::get_int(node, "y");
	res.zorder = wml::get_int(node, "zorder");
	if(tiles_cache.count(node->attr("tile"))) {
		res.object = tiles_cache[node->attr("tile")];
	}
	res.face_right = wml::get_bool(node, "face_right");
	return res;
}
Exemplo n.º 7
0
constants_loader::constants_loader(wml::const_node_ptr node) : same_as_base_(false)
{
	constants_map m;
	if(node) {
		for(wml::node::const_attr_iterator i = node->begin_attr(); i != node->end_attr(); ++i) {
			const std::string& attr = i->first;
			if(std::find_if(attr.begin(), attr.end(), islower) != attr.end()) {
				//only all upper case are loaded as consts
				continue;
			}

			m[attr].serialize_from_string(i->second);
		}
	}

	if(constants_stack.empty() == false && constants_stack.back() == m) {
		same_as_base_ = true;
	} else if(constants_stack.empty() == false) {
		std::cerr << "CONSTANTS ARE DIFFERENT: ";
		for(constants_map::const_iterator i = m.begin(); i != m.end(); ++i) {
			if(constants_stack.back().count(i->first) == 0) {
				std::cerr << "NOT FOUND " << i->first << " ";
			} else if(i->second != constants_stack.back()[i->first]) {
				std::cerr << "DIFF " << i->first << " ";
			}
		}

		const constants_map& m2 = constants_stack.back();
		for(constants_map::const_iterator i = m2.begin(); i != m2.end(); ++i) {
			if(m.count(i->first) == 0) {
				std::cerr << "INSERTED " << i->first << " ";
			}
		}

		std::cerr << "\n";
	}

	//std::cerr << "ADD CONSTANTS_STACK ";
	for(constants_map::const_iterator i = m.begin(); i != m.end(); ++i) {
		std::cerr << i->first << " ";
	}

	if(m.begin() != m.end()) {
		std::cerr << "\n";
	}

	constants_stack.push_back(m);
}
Exemplo n.º 8
0
event_handler::event_handler(wml::const_node_ptr node)
    : node_(node),
	  first_time_only_(wml::get_bool(node, "first_time_only", false)),
	  already_run_(wml::get_bool(node, "already_run", false))
{
	const std::string& f = wml::get_str(node,"filter");
	if(!f.empty()) {
		filters_.push_back(formula_ptr(new formula(f)));
	}

	for(wml::node::const_all_child_iterator i = node->begin_children();
	    i != node->end_children(); ++i) {
		if((*i)->name() == "filter") {
			filters_.push_back(formula_ptr(new formula((*i)->attr("filter"))));
			continue;
		}

		const_wml_command_ptr cmd(wml_command::create(*i));
		if(cmd) {
			commands_.push_back(cmd);
		}
	}
}
Exemplo n.º 9
0
void load(const wml::const_node_ptr& node)
{
	for(wml::node::const_attr_iterator i = node->begin_attr();
	    i != node->end_attr(); ++i) {
		stat_calculation[i->first] = ptr(new formula(i->second));
	}

	wml::const_node_ptr penalties = node->get_child("ideal_strength_penalties");
	if(penalties) {
		for(wml::node::const_attr_iterator i = penalties->begin_attr();
		    i != penalties->end_attr(); ++i) {
			strength_penalty[i->first] = ptr(new formula(i->second));
		}
	}

	penalties = node->get_child("fatigue_penalties");
	if(penalties) {
		for(wml::node::const_attr_iterator i = penalties->begin_attr();
		    i != penalties->end_attr(); ++i) {
			fatigue_penalty[i->first] = ptr(new formula(i->second));
		}
	}

	wml::const_node_ptr height = node->get_child("height_advantage");
	if(height) {
		for(wml::node::const_attr_iterator i = height->begin_attr();
		    i != height->end_attr(); ++i) {
			height_advantage[i->first] = ptr(new formula(i->second));
		}
	}

	wml::const_node_ptr rules = node->get_child("rules");
	if(rules) {
		if(rules->has_attr("track")) {
			track_formula.reset(new formula((*rules)["track"]));
		}
	}
}
Exemplo n.º 10
0
terrain_improvement::terrain_improvement(wml::const_node_ptr node)
  : id_(node->attr("id")), texture_(graphics::texture::get(node->attr("image"))), cost_(wml::get_int(node, "cost"))
{}
Exemplo n.º 11
0
frame::frame(wml::const_node_ptr node)
   : id_(node->attr("id")),
     image_(node->attr("image")),
     variant_id_(id_),
     enter_event_id_(get_object_event_id("enter_" + id_ + "_anim")),
	 end_event_id_(get_object_event_id("end_" + id_ + "_anim")),
	 leave_event_id_(get_object_event_id("leave_" + id_ + "_anim")),
	 process_event_id_(get_object_event_id("process_" + id_)),
     texture_(graphics::texture::get(image_, node->attr("image_formula"))),
	 solid_(solid_info::create(node)),
     collide_rect_(node->has_attr("collide") ? rect(node->attr("collide")) :
	               rect(wml::get_int(node, "collide_x"),
                        wml::get_int(node, "collide_y"),
                        wml::get_int(node, "collide_w"),
                        wml::get_int(node, "collide_h"))),
	 hit_rect_(node->has_attr("hit") ? rect(node->attr("hit")) :
	               rect(wml::get_int(node, "hit_x"),
				        wml::get_int(node, "hit_y"),
				        wml::get_int(node, "hit_w"),
				        wml::get_int(node, "hit_h"))),
	 platform_rect_(node->has_attr("platform") ? rect(node->attr("platform")) :
	                rect(wml::get_int(node, "platform_x"),
	                     wml::get_int(node, "platform_y"),
	                     wml::get_int(node, "platform_w"), 1)),
	 img_rect_(node->has_attr("rect") ? rect(node->attr("rect")) :
	           rect(wml::get_int(node, "x"),
	                wml::get_int(node, "y"),
	                wml::get_int(node, "w"),
	                wml::get_int(node, "h"))),
	 feet_x_(wml::get_int(node, "feet_x")),
	 feet_y_(wml::get_int(node, "feet_y")),
	 accel_x_(wml::get_int(node, "accel_x", INT_MIN)),
	 accel_y_(wml::get_int(node, "accel_y", INT_MIN)),
	 velocity_x_(wml::get_int(node, "velocity_x", INT_MIN)),
	 velocity_y_(wml::get_int(node, "velocity_y", INT_MIN)),
	 nframes_(wml::get_int(node, "frames", 1)),
	 nframes_per_row_(wml::get_int(node, "frames_per_row", -1)),
	 frame_time_(wml::get_int(node, "duration", -1)),
	 reverse_frame_(wml::get_bool(node, "reverse")),
	 play_backwards_(wml::get_bool(node, "play_backwards")),
	 scale_(wml::get_int(node, "scale", 2)),
	 pad_(wml::get_int(node, "pad")),
	 rotate_(wml::get_int(node, "rotate")),
	 blur_(wml::get_int(node, "blur")),
	 rotate_on_slope_(wml::get_bool(node, "rotate_on_slope")),
	 damage_(wml::get_int(node, "damage")),
	 sounds_(util::split(node->attr("sound"))),
	 no_remove_alpha_borders_(wml::get_bool(node, "no_remove_alpha_borders", false)),
	 current_palette_(-1)
{
	std::vector<std::string> hit_frames = util::split((*node)["hit_frames"]);
	foreach(const std::string& f, hit_frames) {
		hit_frames_.push_back(boost::lexical_cast<int>(f));
	}
Exemplo n.º 12
0
void citizen::init(wml::const_node_ptr node)
{
	survive_formula = game_logic::formula::create_optional_formula(node->attr("survive_formula"));
	reproduce_formula = game_logic::formula::create_optional_formula(node->attr("reproduce_formula"));
	tile_attractiveness_formula.reset(new game_logic::formula(node->attr("tile_attractiveness_formula")));
	wages_wanted_formula = game_logic::formula::create_optional_formula(node->attr("wages_wanted_formula"));

	wml::const_node_ptr produce = node->get_child("produce");
	if(produce) {
		for(wml::node::const_attr_iterator i = produce->begin_attr(); i != produce->end_attr(); ++i) {
			produce_score_formulae[i->first].reset(new game_logic::formula(i->second));
		}
	}

	wml::const_node_ptr use = node->get_child("use");
	if(use) {
		for(wml::node::const_attr_iterator i = use->begin_attr(); i != use->end_attr(); ++i) {
			item_use_map[i->first] = atoi(i->second.c_str());
		}
	}

	wml::const_node_ptr trades = node->get_child("trades");
	if(trades) {
		for(wml::node::const_attr_iterator i = trades->begin_attr(); i != trades->end_attr(); ++i) {
			std::vector<std::string> keys = util::split(i->first, '_');
			if(keys.size() == 2) {
				trade_formula_map[std::pair<std::string,std::string>(keys[0], keys[1])].reset(new game_logic::formula(i->second));
			}
		}
	}

	wml::const_node_ptr buys = node->get_child("buys");
	if(buys) {
		for(wml::node::const_attr_iterator i = buys->begin_attr(); i != buys->end_attr(); ++i) {
			buy_formula_map[i->first].reset(new game_logic::formula(i->second));
		}
	}

	wml::const_node_ptr sells = node->get_child("sells");
	if(sells) {
		for(wml::node::const_attr_iterator i = sells->begin_attr(); i != sells->end_attr(); ++i) {
			sell_formula_map[i->first].reset(new game_logic::formula(i->second));
		}
	}

	wml::const_node_ptr buy_quantities = node->get_child("buy_quantities");
	if(buy_quantities) {
		for(wml::node::const_attr_iterator i = buy_quantities->begin_attr(); i != buy_quantities->end_attr(); ++i) {
			buy_quantity_formula_map[i->first].reset(new game_logic::formula(i->second));
		}
	}

	wml::const_node_ptr sell_quantities = node->get_child("sell_quantities");
	if(sell_quantities) {
		for(wml::node::const_attr_iterator i = sell_quantities->begin_attr(); i != sell_quantities->end_attr(); ++i) {
			sell_quantity_formula_map[i->first].reset(new game_logic::formula(i->second));
		}
	}
}
Exemplo n.º 13
0
void frame_draw_builder::init_from_wml(const wml::const_node_ptr& node) {
	for(wml::node::const_attr_iterator i = node->begin_attr();
	    i != node->end_attr(); ++i) {
		set_attr(i->first, i->second);
	}
}