Beispiel #1
0
const char* hero::image(bool big)
{
	char* to;

	if (!big) {
		to = imgfile_;
	} else {
		to = imgfile2_;
		
	}
	if (!to[0]) {
		char text[_MAX_PATH];
		uint32_t fsize_low, fsize_high;
		if (!big) {
			sprintf(to, "hero-64/%u.png", image_);
		} else {
			sprintf(to, "hero-256/%u.png", image_);
		}
		sprintf(text, "%s//%s", image_file_root_.c_str(), to);
		posix_fsize_byname(text, fsize_low, fsize_high);
		if (!fsize_low && !fsize_high) {
			if (!big) {
				strcpy(to, "hero-64/default.png");
			} else {
				strcpy(to, "hero-256/default.png");
			}
		}
	}
	return to;
}
card::card(const config& card_cfg)
	: cfg_(card_cfg)
	, condition_cfg_(cfg_.child("condition"))
	, range_cfg_(cfg_.child("range"))
	, action_cfg_(cfg_.child("action"))
	, number_(CARDS_INVALID_NUMBER)
	, target_hero_(card_cfg["hero"].to_bool())
	, multitudinous_(card_cfg["multitudinous"].to_bool())
	, points_(-1)
	, range_(NONE)
	, mode_(card_cfg["mode"].str())
	, bomb_(card_cfg["bomb"].to_bool())
{
	if (!condition_cfg_) {
		throw config::error("[card] error, " + name() + " no [condition].");
	}
	if (!range_cfg_) {
		throw config::error("[card] error, " + name() + " no [range].");
	}
	if (!action_cfg_) {
		throw config::error("[card] error, " + name() + " no [action].");
	}
	name_str_ = cfg_["name"].str();
	desc_str_ = cfg_["description"].str();

	uint32_t fsize_low, fsize_high;
	image_str_ = image_file_root_ + "/card/" + cfg_["image"];
	posix_fsize_byname(image_str_.c_str(), fsize_low, fsize_high);
	if (!fsize_low && !fsize_high) {
		image_str_ = "card/default.png";
	} else {
		image_str_ = std::string("card/") + cfg_["image"];
	}

	points_ = cfg_["points"].to_int();

	if (range_cfg_) {
		int ranges = 0;
		if (range_cfg_["self"].to_bool()) {
			ranges ++;
		}
		std::vector<std::string> adjacent = utils::split(range_cfg_["adjacent"]);
		for (std::vector<std::string>::const_iterator dir = adjacent.begin(); dir != adjacent.end(); ++ dir) {
			map_location::DIRECTION dir_i = map_location::parse_direction(*dir);
			if (dir_i == map_location::NDIRECTIONS) {
				continue;
			}
			ranges ++;
		}
		if (ranges > 1) {
			range_ = MULTI;
		} else if (ranges == 1) {
			range_ = SINGLE;
		} else {
			range_ = NONE;
		}
	}
}