예제 #1
0
파일: citizen.cpp 프로젝트: x2f/wesciv
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));
		}
	}
}
예제 #2
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"]));
		}
	}
}