コード例 #1
0
// @inc: >0, decrease loyalty; < 0, increase loyalty
int hero::increase_loyalty(int inc, hero& leader)
{
	static int mid_loyalty16 = ftofxp8(HERO_MAX_LOYALTY / 2);
	static int max_loyalty16 = ftofxp8(HERO_MAX_LOYALTY);

	if (leader.base_catalog_ == base_catalog_) {
		// this is faithful hero, don't change.
		return loyalty(leader);
	}
	
	// effect factor: amtition, heart
	double inc_catalog_float = 1.0 * ambition_ * INC_CATALOG_UNIT_AMBITION + 1.0 * (255 - heart_) / 64 * INC_CATALOG_UNIT_HEART;
	int inc_catalog = inc * std::max<int>((int)inc_catalog_float, INC_CATALOG_UNIT_AMBITION + INC_CATALOG_UNIT_HEART);
	// effect factor: base catalog
	int mid = posix_abs((int)leader.base_catalog_ - base_catalog_);
	if (mid > HERO_MAX_LOYALTY / 2) {
		mid = HERO_MAX_LOYALTY - mid;
	}
	inc_catalog *= (mid + 14) / 15;

	// enlarger distance float_catalog_ and base_catalog_ of leader
	uint16_t leader_base_catalog16 = ftofxp8(leader.base_catalog_);
	bool up_float_catalog = false;
	if (float_catalog_ > leader_base_catalog16) {
		if (float_catalog_ - leader_base_catalog16 < mid_loyalty16) {
			up_float_catalog = true;
		}
	} else if (leader_base_catalog16 - float_catalog_ > mid_loyalty16) {
		up_float_catalog = true;
	}
	if ((up_float_catalog && inc_catalog > 0) || (!up_float_catalog && inc_catalog < 0)) {
		if (inc_catalog < 0) {
			inc_catalog *= -1;
		}
		// float_catalog_ += inc_catalog
		float_catalog_ += inc_catalog;
		if (float_catalog_ >= max_loyalty16) {
			float_catalog_ -= max_loyalty16;
		}
	} else if ((!up_float_catalog && inc_catalog > 0) || (up_float_catalog && inc_catalog < 0)) {
		if (inc_catalog < 0) {
			inc_catalog *= -1;
		}
		// float_catalog_ -= inc_catalog
		if (float_catalog_ >= inc_catalog) {
			float_catalog_ -= inc_catalog;
		} else {
			float_catalog_ = max_loyalty16 - (inc_catalog - float_catalog_);
		}
	}

	// calculate loyalty. same as loyalty(...)
	mid = posix_abs((int)leader.float_catalog_ - float_catalog_);
	mid = fxptoi8(mid);
	if (mid < HERO_MAX_LOYALTY / 2) {
		mid = HERO_MAX_LOYALTY - mid;
	}
	return mid;
}
コード例 #2
0
void hero::set_loyalty(hero& leader, int level, bool fixed)
{
	if (level > HERO_MAX_LOYALTY) {
		return;
	}
	int cur_level = loyalty(leader);
	if (cur_level == level) {
		return;
	}
	if (!fixed && cur_level >= level) {
		return;
	}

	bool up_float_catalog = false;
	int mid = posix_abs((int)leader.base_catalog_ - base_catalog_);
	if (mid < HERO_MAX_LOYALTY / 2) {
		if (leader.base_catalog_ < base_catalog_) {
			up_float_catalog = true;
		}
	} else {
		if (leader.base_catalog_ >= base_catalog_) {
			up_float_catalog = true;
		}
	}
	int to_catalog = leader.base_catalog_;
	if (up_float_catalog) {
		to_catalog = to_catalog + HERO_MAX_LOYALTY - level;
		if (to_catalog >= HERO_MAX_LOYALTY) {
			to_catalog -= HERO_MAX_LOYALTY;
		}
	} else {
		to_catalog = to_catalog - (HERO_MAX_LOYALTY - level);
		if (to_catalog < 0) {
			to_catalog = HERO_MAX_LOYALTY + to_catalog; 
		}
	}
	float_catalog_ = ftofxp8(to_catalog);
}
コード例 #3
0
hero::hero(uint16_t number, uint16_t leadership, uint16_t force, uint16_t intellect, uint16_t politics, uint16_t charm) :
	name_str_(),
	surname_str_()
{
	uint32_t idx;

	number_ = number;
	leadership_ = leadership;
	force_ = force;
	intellect_ = intellect;
	politics_ = politics;
	charm_ = charm;

	gender_ = HEROS_DEFAULT_GENDER;
	image_ = number;
	side_ = HEROS_INVALID_SIDE;
	city_ = HEROS_DEFAULT_CITY;
	// stratum_ = HEROS_DEFAULT_STRATUM;
	status_ = HEROS_DEFAULT_STATUS;
	official_ = HEROS_DEFAULT_OFFICIAL;
	feature_ = HEROS_NO_FEATURE;
	side_feature_ = HEROS_NO_FEATURE;
	activity_ = HEROS_DEFAULT_ACTIVITY;
	meritorious_ = 0;
	base_catalog_ = HEROS_DEFAULT_BASE_CATALOG;
	float_catalog_ = ftofxp8(base_catalog_);
	ambition_ = HEROS_DEFAULT_AMBITION;
	heart_ = HEROS_DEFAULT_HEART;
	treasure_ = HEROS_NO_TREASURE;

	// portrait image file
	imgfile_[0] ='\0';
	imgfile2_[0] ='\0';

	//
	// initial some field
	//
	
	// arms adaptability
	memset(arms_, 0, sizeof(arms_));

	// skill adaptability
	memset(skill_, 0, sizeof(skill_));

	// relation
	for (idx = 0; idx < HEROS_MAX_PARENT; idx ++) {
		parent_[idx].hero_ = HEROS_INVALID_NUMBER;
		parent_[idx].feeling_ = 0;
	}
	for (idx = 0; idx < HEROS_MAX_CONSORT; idx ++) {
		consort_[idx].hero_ = HEROS_INVALID_NUMBER;
		consort_[idx].feeling_ = 0;
	}
	for (idx = 0; idx < HEROS_MAX_OATH; idx ++) {
		oath_[idx].hero_ = HEROS_INVALID_NUMBER;
		oath_[idx].feeling_ = 0;
	}
	for (idx = 0; idx < HEROS_MAX_INTIMATE; idx ++) {
		intimate_[idx].hero_ = HEROS_INVALID_NUMBER;
		intimate_[idx].feeling_ = 0;
	}
	for (idx = 0; idx < HEROS_MAX_HATE; idx ++) {
		hate_[idx].hero_ = HEROS_INVALID_NUMBER;
		hate_[idx].feeling_ = 0;
	}
}
コード例 #4
0
ファイル: preferences.cpp プロジェクト: hyrio/War-Of-Kingdom
bool get_hero(hero& h, int default_image)
{
	const config& cfg = prefs.child("hero");
	if (cfg) {
		h.set_name(cfg["name"].str());
		h.set_surname(cfg["surname"].str());
		h.set_biography(cfg["biography"].str());

		h.gender_ = cfg["gender"].to_int(hero_gender_male);
		h.image_ = cfg["image"].to_int(default_image);

		h.leadership_ = ftofxp9(cfg["leadership"].to_int(1));
		h.force_ = ftofxp9(cfg["force"].to_int(1));
		h.intellect_ = ftofxp9(cfg["intellect"].to_int(1));
		h.spirit_ = ftofxp9(cfg["spirit"].to_int(1));
		h.charm_ = ftofxp9(cfg["charm"].to_int(1));

		std::stringstream str;
		for (int i = 0; i < HEROS_MAX_ARMS; i ++) {
			str.str("");
			str << "arms" << i;
			h.arms_[i] = ftofxp12(cfg[str.str()].to_int(0));
		}
		for (int i = 0; i < HEROS_MAX_SKILL; i ++) {
			str.str("");
			str << "skill" << i;
			h.skill_[i] = ftofxp12(cfg[str.str()].to_int(0));
		}

		h.side_feature_ = cfg["side_feature"].to_int(HEROS_NO_FEATURE);
		if (h.side_feature_ < 0 || h.side_feature_ > HEROS_MAX_FEATURE) {
			h.side_feature_ = HEROS_NO_FEATURE;
		}
		h.feature_ = cfg["feature"].to_int(HEROS_NO_FEATURE);
		if (h.feature_ < 0 || h.feature_ > HEROS_MAX_FEATURE) {
			h.feature_ = HEROS_NO_FEATURE;
		}
		h.tactic_ = cfg["tactic"].to_int(HEROS_NO_TACTIC);
		h.utype_ = cfg["utype"].to_int(HEROS_NO_UTYPE);
		h.character_ = cfg["character"].to_int(HEROS_NO_CHARACTER);

		h.base_catalog_ = cfg["base_catalog"].to_int();
		h.float_catalog_ = ftofxp8(h.base_catalog_);

		return true;
	} else {
		// h.set_name(_("Press left button to create hero"));
		h.set_name(public_account);
		h.set_surname("Mr.");

		h.gender_ = hero_gender_male;
		h.image_ = default_image;

		h.leadership_ = ftofxp9(1);
		h.force_ = ftofxp9(1);
		h.intellect_ = ftofxp9(1);
		h.spirit_ = ftofxp9(1);
		h.charm_ = ftofxp9(1);

		for (int i = 0; i < HEROS_MAX_ARMS; i ++) {
			h.arms_[i] = 0;
		}
		for (int i = 0; i < HEROS_MAX_SKILL; i ++) {
			h.skill_[i] = 0;
		}

		return false;
	}
}