• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ unit类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中unit的典型用法代码示例。如果您正苦于以下问题:C++ unit类的具体用法?C++ unit怎么用?C++ unit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了unit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1:

/**
 * Convenience constructor for when an event has a unit, saving the caller
 * the need to explicitly get the location and underlying ID.
 */
entity_location::entity_location(const unit &u)
	: map_location(u.get_location())
	, id_(u.underlying_id())
	, filter_loc_(*this)
{}
开发者ID:doofus-01,项目名称:wesnoth,代码行数:9,代码来源:entity_location.cpp


示例2: BOOST_FOREACH

	BOOST_FOREACH (unit & i, units_) {
		if (i.side() == player_num) {
			i.new_turn();
		}
	}
开发者ID:sunny975,项目名称:wesnoth,代码行数:5,代码来源:game_board.cpp


示例3: recall_unit

void recall_unit(const unit& u)
{
	stats& s = get_stats(u.side_id());
	s.recalls[u.type_id()]++;
	s.recall_cost += u.cost();
}
开发者ID:aelthwin,项目名称:Battle-for-Wesnoth--Zombie-Edition,代码行数:6,代码来源:statistics.cpp


示例4: unit_movement_resetter

	unit_movement_resetter(unit& u, bool operate=true) : u_(u), moves_(u.movement_)
	{
		if(operate) {
			u.movement_ = u.total_movement();
		}
	}
开发者ID:dodikk,项目名称:iWesnoth,代码行数:6,代码来源:unit.hpp


示例5: FAIL

bool basic_unit_filter_impl::internal_matches_filter(const unit & u, const map_location& loc, const unit* u2) const
{
	if (!vcfg["name"].blank() && vcfg["name"].t_str() != u.name()) {
		return false;
	}

	if (!vcfg["id"].empty()) {
		std::vector<std::string> id_list = utils::split(vcfg["id"]);
		if (std::find(id_list.begin(), id_list.end(), u.id()) == id_list.end()) {
			return false;
		}
	}

	// Allow 'speaker' as an alternative to id, since people use it so often
	if (!vcfg["speaker"].blank() && vcfg["speaker"].str() != u.id()) {
		return false;
	}

	if (vcfg.has_child("filter_location")) {
		if (vcfg.count_children("filter_location") > 1) {
			FAIL("Encountered multiple [filter_location] children of a standard unit filter. "
				 "This is not currently supported and in all versions of wesnoth would have "
				 "resulted in the later children being ignored. You must use [and] or similar "
				 "to achieve the desired result.");
		}
		terrain_filter filt(vcfg.child("filter_location"), &fc_, use_flat_tod_);
		if (!filt.match(loc)) {
			return false;
		}
	}

	if(vcfg.has_child("filter_side")) {
		if (vcfg.count_children("filter_side") > 1) {
			FAIL("Encountered multiple [filter_side] children of a standard unit filter. "
				 "This is not currently supported and in all versions of wesnoth would have "
				 "resulted in the later children being ignored. You must use [and] or similar "
				 "to achieve the desired result.");
		}
		side_filter filt(vcfg.child("filter_side"), &fc_);
		if(!filt.match(u.side()))
			return false;
	}

	// Also allow filtering on location ranges outside of the location filter
	if (!vcfg["x"].blank() || !vcfg["y"].blank()){
		if(vcfg["x"] == "recall" && vcfg["y"] == "recall") {
			//locations on the map are considered to not be on a recall list
			if (fc_.get_disp_context().map().on_board(loc))
			{
				return false;
			}
		} else if(vcfg["x"].empty() && vcfg["y"].empty()) {
			return false;
		} else if(!loc.matches_range(vcfg["x"], vcfg["y"])) {
			return false;
		}
	}

	// The type could be a comma separated list of types
	if (!vcfg["type"].empty()) {
		std::vector<std::string> types = utils::split(vcfg["type"]);
		if (std::find(types.begin(), types.end(), u.type_id()) == types.end()) {
			return false;
		}
	}

	// The variation_type could be a comma separated list of types
	if (!vcfg["variation"].empty())
	{
		std::vector<std::string> types = utils::split(vcfg["variation"]);
		if (std::find(types.begin(), types.end(), u.variation()) == types.end()) {
			return false;
		}
	}

	// The has_variation_type could be a comma separated list of types
	if (!vcfg["has_variation"].empty())
	{
		bool match = false;
		// If this unit is a variation itself then search in the base unit's variations.
		const unit_type* const type = u.variation().empty() ? &u.type() : unit_types.find(u.type().base_id());
		assert(type);

		for (const std::string& variation_id : utils::split(vcfg["has_variation"])) {
			if (type->has_variation(variation_id)) {
				match = true;
				break;
			}
		}
		if (!match) return false;
	}

	if (!vcfg["ability"].empty())
	{
		bool match = false;

		for (const std::string& ability_id : utils::split(vcfg["ability"])) {
			if (u.has_ability_by_id(ability_id)) {
				match = true;
				break;
//.........这里部分代码省略.........
开发者ID:CliffsDover,项目名称:wesnoth,代码行数:101,代码来源:filter.cpp


示例6: VALIDATE

/** @todo FIXME: Hand previous defender unit in here. */
int battle_context::choose_defender_weapon(const unit& attacker,
		const unit& defender,
		unsigned attacker_weapon,
		const unit_map& units,
		const map_location& attacker_loc,
		const map_location& defender_loc,
		const combatant* prev_def)
{
	VALIDATE(attacker_weapon < attacker.attacks().size(), _("An invalid attacker weapon got selected."));

	const attack_type& att = attacker.attacks()[attacker_weapon];
	std::vector<unsigned int> choices;

	// What options does defender have?
	unsigned int i;

	for(i = 0; i < defender.attacks().size(); ++i) {
		const attack_type& def = defender.attacks()[i];

		if(def.range() == att.range() && def.defense_weight() > 0) {
			choices.push_back(i);
		}
	}

	if(choices.empty()) {
		return -1;
	}

	if(choices.size() == 1) {
		const battle_context_unit_stats def_stats(
				defender, defender_loc, choices[0], false, attacker, attacker_loc, att.shared_from_this(), units);

		return (def_stats.disable) ? -1 : choices[0];
	}

	// Multiple options:
	// First pass : get the best weight and the minimum simple rating for this weight.
	// simple rating = number of blows * damage per blows (resistance taken in account) * cth * weight
	// Eligible attacks for defense should have a simple rating greater or equal to this weight.

	int min_rating = 0;
	{
		double max_weight = 0.0;

		for(i = 0; i < choices.size(); ++i) {
			const attack_type& def = defender.attacks()[choices[i]];

			if(def.defense_weight() >= max_weight) {
				const battle_context_unit_stats def_stats(defender, defender_loc, choices[i], false, attacker,
						attacker_loc, att.shared_from_this(), units);

				if(def_stats.disable) {
					continue;
				}

				max_weight = def.defense_weight();
				int rating = static_cast<int>(
						def_stats.num_blows * def_stats.damage * def_stats.chance_to_hit * def.defense_weight());

				if(def.defense_weight() > max_weight || rating < min_rating) {
					min_rating = rating;
				}
			}
		}
	}

	// Multiple options: simulate them, save best.
	for(i = 0; i < choices.size(); ++i) {
		const attack_type& def = defender.attacks()[choices[i]];

		std::unique_ptr<battle_context_unit_stats> att_stats(new battle_context_unit_stats(
				attacker, attacker_loc, attacker_weapon, true, defender, defender_loc, def.shared_from_this(), units));

		std::unique_ptr<battle_context_unit_stats> def_stats(new battle_context_unit_stats(
				defender, defender_loc, choices[i], false, attacker, attacker_loc, att.shared_from_this(), units));

		if(def_stats->disable) {
			continue;
		}

		std::unique_ptr<combatant> att_comb(new combatant(*att_stats));
		std::unique_ptr<combatant> def_comb(new combatant(*def_stats, prev_def));

		att_comb->fight(*def_comb);

		int simple_rating = static_cast<int>(
				def_stats->num_blows * def_stats->damage * def_stats->chance_to_hit * def.defense_weight());

		if(simple_rating >= min_rating &&
			(!attacker_combatant_ || better_combat(*def_comb, *att_comb, *defender_combatant_, *attacker_combatant_, 1.0))
		) {
			attacker_combatant_ = std::move(att_comb);
			defender_combatant_ = std::move(def_comb);
			attacker_stats_ = std::move(att_stats);
			defender_stats_ = std::move(def_stats);
		}
	}

	return defender_stats_ ? defender_stats_->attack_num : -1;
//.........这里部分代码省略.........
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:101,代码来源:attack.cpp


示例7: find_routes

static void find_routes(const gamemap& map, const unit_map& /*units*/,
		const unit& u, const map_location& loc,
		int move_left, pathfind::paths::dest_vect &destinations,
		std::vector<team> const &teams,
		bool force_ignore_zocs, bool allow_teleport, int turns_left,
		const team &viewing_team,
		bool see_all, bool ignore_units)
{
	const team& current_team = teams[u.side() - 1];
	pathfind::teleport_map teleports;
	if (allow_teleport) {
	  teleports = pathfind::get_teleport_locations(u, viewing_team, see_all, ignore_units);
	}

	const int total_movement = u.total_movement();

	search_counter += 2;
	if (search_counter == 0) search_counter = 2;

	static std::vector<node> nodes;
	nodes.resize(map.w() * map.h());

	indexer index(map.w(), map.h());
	comp node_comp(nodes);

	int xmin = loc.x, xmax = loc.x, ymin = loc.y, ymax = loc.y, nb_dest = 1;

	nodes[index(loc)] = node(move_left, turns_left, map_location::null_location, loc);
	std::vector<int> pq;
	pq.push_back(index(loc));

	while (!pq.empty()) {
		node& n = nodes[pq.front()];
		std::pop_heap(pq.begin(), pq.end(), node_comp);
		pq.pop_back();
		n.in = search_counter;

		std::set<map_location> allowed_teleports;
		teleports.get_adjacents(allowed_teleports, n.curr);
		std::vector<map_location> locs(6 + allowed_teleports.size());
		std::copy(allowed_teleports.begin(), allowed_teleports.end(), locs.begin() + 6);
		get_adjacent_tiles(n.curr, &locs[0]);
		for (int i = locs.size(); i-- > 0; ) {
			if (!locs[i].valid(map.w(), map.h())) continue;

			if (locs[i] == n.curr) continue;

			node& next = nodes[index(locs[i])];

			bool next_visited = next.in - search_counter <= 1u;

			// Classic Dijkstra allow to skip chosen nodes (with next.in==search_counter)
			// But the cost function and hex grid allow to also skip visited nodes:
			// if next was visited, then we already have a path 'src-..-n2-next'
			// - n2 was chosen before n, meaning that it is nearer to src.
			// - the cost of 'n-next' can't be smaller than 'n2-next' because
			//   cost is independent of direction and we don't have more MP at n
			//   (important because more MP may allow to avoid waiting next turn)
			// Thus, 'src-..-n-next' can't be shorter.
			if (next_visited) continue;

			const int move_cost = u.movement_cost(map[locs[i]]);

			node t = node(n.movement_left, n.turns_left, n.curr, locs[i]);
			if (t.movement_left < move_cost) {
				t.movement_left = total_movement;
				t.turns_left--;
			}

			if (t.movement_left < move_cost || t.turns_left < 0) continue;

			t.movement_left -= move_cost;

			if (!ignore_units) {
				const unit *v =
					get_visible_unit(locs[i], viewing_team, see_all);
				if (v && current_team.is_enemy(v->side()))
					continue;

				if (!force_ignore_zocs && t.movement_left > 0
				    && pathfind::enemy_zoc(teams, locs[i], viewing_team, u.side(), see_all)
						&& !u.get_ability_bool("skirmisher", locs[i])) {
					t.movement_left = 0;
				}
			}

			++nb_dest;
			int x = locs[i].x;
			if (x < xmin) xmin = x;
			if (xmax < x) xmax = x;
			int y = locs[i].y;
			if (y < ymin) ymin = y;
			if (ymax < y) ymax = y;

			bool in_list = next.in == search_counter + 1;
			t.in = search_counter + 1;
			next = t;

			// if already in the priority queue then we just update it, else push it.
			if (in_list) { // never happen see next_visited above
//.........这里部分代码省略.........
开发者ID:RushilPatel,项目名称:BattleForWesnoth,代码行数:101,代码来源:pathfind.cpp


示例8: un_recall_unit_cost

int un_recall_unit_cost(const unit& u)  // this really belongs elsewhere, perhaps in undo.cpp
{					// but I'm too lazy to do it at the moment
	stats& s = get_stats(get_team_save_id(u));
	s.recalls[u.type_id()]--;
	return u.recall_cost();
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:6,代码来源:statistics.cpp


示例9: advance_unit

void advance_unit(const unit& u)
{
	stats& s = get_stats(get_team_save_id(u));
	s.advanced_to[u.type_id()]++;
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:5,代码来源:statistics.cpp


示例10: un_recall_unit

void un_recall_unit(const unit& u)
{
	stats& s = get_stats(get_team_save_id(u));
	s.recalls[u.type_id()]--;
	s.recall_cost -= u.cost();
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:6,代码来源:statistics.cpp


示例11: un_recruit_unit

void un_recruit_unit(const unit& u)
{
	stats& s = get_stats(get_team_save_id(u));
	s.recruits[u.type().base_id()]--;
	s.recruit_cost -= u.cost();
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:6,代码来源:statistics.cpp


示例12: recall_unit

void recall_unit(const unit& u)
{
	stats& s = get_stats(get_team_save_id(u));
	s.recalls[u.type_id()]++;
	s.recall_cost += u.cost();
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:6,代码来源:statistics.cpp


示例13: human_team_can_ai

bool human_team_can_ai(const unit& u)
{
	return !u.human() || tent::tower_mode() || u.provoked_turns() || u.task() == unit::TASK_GUARD;
}
开发者ID:hyrio,项目名称:War-Of-Kingdom,代码行数:4,代码来源:playsingle_controller.cpp


示例14: choose_defender_weapon

int battle_context::choose_attacker_weapon(const unit& attacker,
		const unit& defender,
		const unit_map& units,
		const map_location& attacker_loc,
		const map_location& defender_loc,
		double harm_weight,
		int* defender_weapon,
		const combatant* prev_def)
{
	std::vector<unsigned int> choices;

	// What options does attacker have?
	unsigned int i;

	for(i = 0; i < attacker.attacks().size(); ++i) {
		const attack_type& att = attacker.attacks()[i];

		if(att.attack_weight() > 0) {
			choices.push_back(i);
		}
	}

	if(choices.empty()) {
		return -1;
	}

	if(choices.size() == 1) {
		*defender_weapon
				= choose_defender_weapon(attacker, defender, choices[0], units, attacker_loc, defender_loc, prev_def);
		const_attack_ptr def_weapon
				= *defender_weapon >= 0 ? defender.attacks()[*defender_weapon].shared_from_this() : nullptr;
		attacker_stats_.reset(new battle_context_unit_stats(
				attacker, attacker_loc, choices[0], true, defender, defender_loc, def_weapon, units));

		if(attacker_stats_->disable) {
			return -1;
		}

		const attack_type& att = attacker.attacks()[choices[0]];
		defender_stats_.reset(new battle_context_unit_stats(
				defender, defender_loc, *defender_weapon, false, attacker, attacker_loc, att.shared_from_this(), units));

		return choices[0];
	}

	// Multiple options: simulate them, save best.
	std::unique_ptr<battle_context_unit_stats> best_att_stats(nullptr);
	std::unique_ptr<battle_context_unit_stats> best_def_stats(nullptr);

	std::unique_ptr<combatant> best_att_comb(nullptr);
	std::unique_ptr<combatant> best_def_comb(nullptr);

	for(i = 0; i < choices.size(); ++i) {
		const attack_type& att = attacker.attacks()[choices[i]];

		int def_weapon =
			choose_defender_weapon(attacker, defender, choices[i], units, attacker_loc, defender_loc, prev_def);

		// If that didn't simulate, do so now.
		if(!attacker_combatant_) {
			const_attack_ptr def = nullptr;

			if(def_weapon >= 0) {
				def = defender.attacks()[def_weapon].shared_from_this();
			}

			attacker_stats_.reset(new battle_context_unit_stats(
					attacker, attacker_loc, choices[i], true, defender, defender_loc, def, units));

			if(attacker_stats_->disable) {
				continue;
			}

			defender_stats_.reset(new battle_context_unit_stats(
					defender, defender_loc, def_weapon, false, attacker, attacker_loc, att.shared_from_this(), units));

			attacker_combatant_.reset(new combatant(*attacker_stats_));
			defender_combatant_.reset(new combatant(*defender_stats_, prev_def));

			attacker_combatant_->fight(*defender_combatant_);
		} else {
			if(attacker_stats_ != nullptr && attacker_stats_->disable) {
				continue;
			}
		}

		if(!best_att_comb ||
			better_combat(*attacker_combatant_, *defender_combatant_, *best_att_comb, *best_def_comb, harm_weight)
		) {
			best_att_comb = std::move(attacker_combatant_);
			best_def_comb = std::move(defender_combatant_);
			best_att_stats = std::move(attacker_stats_);
			best_def_stats = std::move(defender_stats_);
		}

		attacker_combatant_.reset();
		defender_combatant_.reset();
		attacker_stats_.reset();
		defender_stats_.reset();
	}
//.........这里部分代码省略.........
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:101,代码来源:attack.cpp


示例15: animate_unit_advancement

bool animate_unit_advancement(unit& u, size_t choice)
{
	const events::command_disabler cmd_disabler;

	if (u.advances() == false) {
		return false;
	}

	const std::vector<std::string>& options = u.advances_to();
	std::vector<config> mod_options = u.get_modification_advances();

	if (choice >= options.size() + mod_options.size()) {
		return false;
	}

	// When the unit advances, it fades to white, and then switches
	// to the new unit, then fades back to the normal colour

	game_display* disp = resources::screen;
	rect_of_hexes& draw_area = disp->draw_area();
	bool force_scroll = preferences::scroll_to_action();
	bool animate = force_scroll || point_in_rect_of_hexes(u.get_location().x, u.get_location().y, draw_area);
	if (!resources::screen->video().update_locked() && animate) {
		unit_animator animator;
		bool with_bars = true;
		animator.add_animation(&u, "levelout", u.get_location(), map_location(), 0, with_bars);
		animator.start_animations();
		animator.wait_for_end();
	}

	if(choice < options.size()) {
		// chosen_unit is not a reference, since the unit may disappear at any moment.
		std::string chosen_unit = options[choice];
		::advance_unit(u, chosen_unit);
	} else {
		unit* amla_unit = &u;
		const config &mod_option = mod_options[choice - options.size()];
		
		game_events::fire("advance", u.get_location());

		amla_unit->get_experience(increase_xp::attack_ublock(*amla_unit), -amla_unit->max_experience()); // subtract xp required
		// ALMA may want to change status, but add_modification in modify_according_to_hero cannot change state,
		// so it need call amla_unit->add_modification instead of amla_unit->modify_according_to_hero.
		amla_unit->add_modification(mod_option);

		game_events::fire("post_advance", u.get_location());
	}

	resources::screen->invalidate_unit();

	if (!resources::screen->video().update_locked()) {
		if (force_scroll || point_in_rect_of_hexes(u.get_location().x, u.get_location().y, draw_area)) {
			unit_animator animator;
			animator.add_animation(&u, "levelin", u.get_location(), map_location(), 0, true);
			animator.start_animations();
			animator.wait_for_end();
			animator.set_all_standing();
		
			resources::screen->invalidate(u.get_location());
			resources::screen->draw();
		}
		events::pump();
	}

	resources::screen->invalidate_all();
	if (force_scroll || point_in_rect_of_hexes(u.get_location().x, u.get_location().y, draw_area)) {
		resources::screen->draw();
	}

	return true;
}
开发者ID:hyrio,项目名称:War-Of-Kingdom,代码行数:71,代码来源:dialogs.cpp


示例16: weapon

battle_context_unit_stats::battle_context_unit_stats(const unit& u,
		const map_location& u_loc,
		int u_attack_num,
		bool attacking,
		const unit& opp,
		const map_location& opp_loc,
		const_attack_ptr opp_weapon,
		const unit_map& units)
	: weapon(nullptr)
	, attack_num(u_attack_num)
	, is_attacker(attacking)
	, is_poisoned(u.get_state(unit::STATE_POISONED))
	, is_slowed(u.get_state(unit::STATE_SLOWED))
	, slows(false)
	, drains(false)
	, petrifies(false)
	, plagues(false)
	, poisons(false)
	, backstab_pos(false)
	, swarm(false)
	, firststrike(false)
	, disable(false)
	, experience(u.experience())
	, max_experience(u.max_experience())
	, level(u.level())
	, rounds(1)
	, hp(0)
	, max_hp(u.max_hitpoints())
	, chance_to_hit(0)
	, damage(0)
	, slow_damage(0)
	, drain_percent(0)
	, drain_constant(0)
	, num_blows(0)
	, swarm_min(0)
	, swarm_max(0)
	, plague_type()
{
	// Get the current state of the unit.
	if(attack_num >= 0) {
		weapon = u.attacks()[attack_num].shared_from_this();
	}

	if(u.hitpoints() < 0) {
		LOG_CF << "Unit with " << u.hitpoints() << " hitpoints found, set to 0 for damage calculations\n";
		hp = 0;
	} else if(u.hitpoints() > u.max_hitpoints()) {
		// If a unit has more hp than its maximum, the engine will fail with an
		// assertion failure due to accessing the prob_matrix out of bounds.
		hp = u.max_hitpoints();
	} else {
		hp = u.hitpoints();
	}

	// Exit if no weapon.
	if(!weapon) {
		return;
	}

	// Get the weapon characteristics as appropriate.
	weapon->set_specials_context(u_loc, opp_loc, attacking, opp_weapon);

	if(opp_weapon) {
		opp_weapon->set_specials_context(opp_loc, u_loc, !attacking, weapon);
	}

	slows = weapon->get_special_bool("slow");
	drains = !opp.get_state("undrainable") && weapon->get_special_bool("drains");
	petrifies = weapon->get_special_bool("petrifies");
	poisons = !opp.get_state("unpoisonable") && weapon->get_special_bool("poison") && !opp.get_state(unit::STATE_POISONED);
	backstab_pos = is_attacker && backstab_check(u_loc, opp_loc, units, resources::gameboard->teams());
	rounds = weapon->get_specials("berserk").highest("value", 1).first;
	firststrike = weapon->get_special_bool("firststrike");

	{
		const int distance = distance_between(u_loc, opp_loc);
		const bool out_of_range = distance > weapon->max_range() || distance < weapon->min_range();
		disable = weapon->get_special_bool("disable") || out_of_range;
	}

	// Handle plague.
	unit_ability_list plague_specials = weapon->get_specials("plague");
	plagues = !opp.get_state("unplagueable") && !plague_specials.empty() &&
		opp.undead_variation() != "null" && !resources::gameboard->map().is_village(opp_loc);

	if(plagues) {
		plague_type = (*plague_specials.front().first)["type"].str();

		if(plague_type.empty()) {
			plague_type = u.type().base_id();
		}
	}

	// Compute chance to hit.
	chance_to_hit = opp.defense_modifier(resources::gameboard->map().get_terrain(opp_loc)) + weapon->accuracy()
		- (opp_weapon ? opp_weapon->parry() : 0);

	if(chance_to_hit > 100) {
		chance_to_hit = 100;
	}
//.........这里部分代码省略.........
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:101,代码来源:attack.cpp


示例17: attack_info

static int attack_info(reports::context & rc, const attack_type &at, config &res, const unit &u, const map_location &displayed_unit_hex)
{
	std::ostringstream str, tooltip;

	at.set_specials_context(displayed_unit_hex, u.side() == rc.screen().playing_side());
	int base_damage = at.damage();
	int specials_damage = at.modified_damage(false);
	int damage_multiplier = 100;
	int tod_bonus = combat_modifier(rc.units(), rc.map(), displayed_unit_hex, u.alignment(), u.is_fearless());
	damage_multiplier += tod_bonus;
	int leader_bonus = 0;
	if (under_leadership(rc.units(), displayed_unit_hex, &leader_bonus).valid())
		damage_multiplier += leader_bonus;

	bool slowed = u.get_state(unit::STATE_SLOWED);
	int damage_divisor = slowed ? 20000 : 10000;
	// Assume no specific resistance (i.e. multiply by 100).
	int damage = round_damage(specials_damage, damage_multiplier * 100, damage_divisor);

	// Hit points are used to calculate swarm, so they need to be bounded.
	unsigned max_hp = u.max_hitpoints();
	unsigned cur_hp = std::min<unsigned>(std::max(0, u.hitpoints()), max_hp);

	unsigned base_attacks = at.num_attacks();
	unsigned min_attacks, max_attacks;
	at.modified_attacks(false, min_attacks, max_attacks);
	unsigned num_attacks = swarm_blows(min_attacks, max_attacks, cur_hp, max_hp);

	SDL_Color dmg_color = font::weapon_color;
	if ( damage > specials_damage )
		dmg_color = font::good_dmg_color;
	else if ( damage < specials_damage )
		dmg_color = font::bad_dmg_color;

	str << span_color(dmg_color) << "  " << damage << naps << span_color(font::weapon_color)
		<< font::weapon_numbers_sep << num_attacks << ' ' << at.name()
		<< "</span>\n";
	tooltip << _("Weapon: ") << "<b>" << at.name() << "</b>\n"
		<< _("Damage: ") << "<b>" << damage << "</b>\n";

	if ( tod_bonus || leader_bonus || slowed || specials_damage != base_damage )
	{
		tooltip << '\t' << _("Base damage: ") << base_damage << '\n';
		if ( specials_damage != base_damage ) {
			tooltip << '\t' << _("With specials: ") << specials_damage << '\n';
		}
		if (tod_bonus) {
			tooltip << '\t' << _("Time of day: ")
				<< utils::signed_percent(tod_bonus) << '\n';
		}
		if (leader_bonus) {
			tooltip << '\t' << _("Leadership: ")
				<< utils::signed_percent(leader_bonus) << '\n';
		}
		if (slowed) {
			tooltip << '\t' << _("Slowed: ") << "/ 2" << '\n';
		}
	}

	tooltip << _("Attacks: ") << "<b>" << num_attacks << "</b>\n";
	if ( max_attacks != min_attacks  &&  cur_hp != max_hp ) {
		if ( max_attacks < min_attacks ) {
			// "Reverse swarm"
			tooltip << '\t' << _("Max swarm bonus: ") << (min_attacks-max_attacks) << '\n';
			tooltip << '\t' << _("Swarm: ") << "* "<< (100 - cur_hp*100/max_hp) << "%\n";
			tooltip << '\t' << _("Base attacks: ") << '+' << base_attacks << '\n';
			// The specials line will not necessarily match up with how the
			// specials are calculated, but for an unusual case, simple brevity
			// trumps complexities.
			if ( max_attacks != base_attacks ) {
				int attack_diff = int(max_attacks) - int(base_attacks);
				tooltip << '\t' << _("Specials: ") << utils::signed_value(attack_diff) << '\n';
			}
		}
		else {
			// Regular swarm
			tooltip << '\t' << _("Base attacks: ") << base_attacks << '\n';
			if ( max_attacks != base_attacks ) {
				tooltip << '\t' << _("With specials: ") << max_attacks << '\n';
			}
			if ( min_attacks != 0 ) {
				tooltip << '\t' << _("Subject to swarm: ") << (max_attacks-min_attacks) << '\n';
			}
			tooltip << '\t' << _("Swarm: ") << "* "<< (cur_hp*100/max_hp) << "%\n";
		}
	}
	else if ( num_attacks != base_attacks ) {
		tooltip << '\t' << _("Base attacks: ") << base_attacks << '\n';
		tooltip << '\t' << _("With specials: ") << num_attacks << '\n';
	}

	add_text(res, flush(str), flush(tooltip));

	std::string range = string_table["range_" + at.range()];
	std::string lang_type = string_table["type_" + at.type()];

	str << span_color(font::weapon_details_color) << "  " << "  "
		<< range << font::weapon_details_sep
		<< lang_type << "</span>\n";

//.........这里部分代码省略.........
开发者ID:CliffsDover,项目名称:wesnoth,代码行数:101,代码来源:reports.cpp


示例18: show_unit_description

void show_unit_description(CVideo& video, const unit &u)
{
	help::show_unit_description(video, u.type());
}
开发者ID:MysteryPoo,项目名称:wesnoth,代码行数:4,代码来源:help.cpp


示例19: number_of_possible_advances

int number_of_possible_advances(const unit &u)
{
	return u.advances_to().size() + u.get_modification_advances().size();
}
开发者ID:CliffsDover,项目名称:wesnoth_ios,代码行数:4,代码来源:unit_helper.cpp


示例20: add_unit_entry

static stuff_list_adder add_unit_entry(stuff_list_adder& progress, const unit& u, const display_context& dc)
{

	color_t team_color = game_config::tc_info(dc.get_team(u.side()).color())[0];
	std::stringstream s;

	s << '(' << u.get_location() << ')';
	progress.widget("loc", s.str());

	s.str("");
	s << font::span_color(team_color);
	s << "side=" << u.side() << "</span>";
	progress.widget("side", s.str(), true);

	if(u.can_recruit()) {
		progress.widget("leader", "<span color='yellow'>LEADER</span> ", true);
	}

	s.str("");
	s << "id=\"" << u.id() << '"';
	progress.widget("id", s.str());

	progress.widget("type", u.type_id());

	s.str("");
	s << "L" << u.level();
	progress.widget("level", s.str());

	s.str("");
	s << u.experience() << '/' << u.max_experience() << " xp";
	progress.widget("xp", s.str());

	s.str("");
	s << u.hitpoints() << '/' << u.max_hitpoints() << " hp";
	progress.widget("hp", s.str());

	progress.widget("traits", utils::join(u.get_traits_list(), ", "));

	return progress;
}
开发者ID:GregoryLundberg,项目名称:wesnoth,代码行数:40,代码来源:gamestate_inspector.cpp



注:本文中的unit类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ unit_map类代码示例发布时间:2022-05-31
下一篇:
C++ unique_lock类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap