当前位置: 首页>>代码示例>>C++>>正文


C++ unit_map::find方法代码示例

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


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

示例1: install_

		uint32_t install_(const std::string& fpath)
		{
			unit_map_cit cit = unit_map_.find(fpath);
			if(cit != unit_map_.end()) {  // find it !, To be not install.
				return 0;
			}

			auto tpath = strip_last_of_delimita_path(fpath);
			auto bpath = get_file_path(tpath);
			bpath += '/';

			unit_map_it it = unit_map_.find(bpath);
			if(it != unit_map_.end()) {
				unit_t& t = it->second;
				std::string name = get_file_name(tpath);
				if(fpath.back() == '/') name += '/';
				t.install_child(name);
			}

			uint32_t hnd = handle_set_.create();
			unit_t u;
			u.set_id(hnd);
			unit_map_.emplace(fpath, u);
			return hnd;
		}
开发者ID:hirakuni45,项目名称:glfw3_app,代码行数:25,代码来源:tree_unit.hpp

示例2: backstab_check

bool backstab_check(const map_location& attacker_loc,
                    const map_location& defender_loc,
                    const unit_map& units, const std::vector<team>& teams)
{
	const unit_map::const_iterator defender = units.find(defender_loc);
	if(defender == units.end()) return false; // No defender

	map_location adj[6];
	get_adjacent_tiles(defender_loc, adj);
	int i;
	for(i = 0; i != 6; ++i) {
		if(adj[i] == attacker_loc)
			break;
	}
	if(i >= 6) return false;  // Attack not from adjacent location

	const unit_map::const_iterator opp =
		units.find(adj[(i+3)%6]);
	if(opp == units.end()) return false; // No opposite unit
	if (opp->incapacitated()) return false;
	if (size_t(defender->side() - 1) >= teams.size() || size_t(opp->side() - 1) >= teams.size())
		return true; // If sides aren't valid teams, then they are enemies
	if (teams[defender->side() - 1].is_enemy(opp->side()))
		return true; // Defender and opposite are enemies
	return false; // Defender and opposite are friends
}
开发者ID:Coffee--,项目名称:wesnoth-old,代码行数:26,代码来源:attack.cpp

示例3: if

battle_context::battle_context(const unit_map& units,
		const map_location& attacker_loc, const map_location& defender_loc,
		int attacker_weapon, int defender_weapon, double aggression,
		const combatant *prev_def, const unit* attacker_ptr) :
	attacker_stats_(nullptr), defender_stats_(nullptr), attacker_combatant_(nullptr),
	defender_combatant_(nullptr)
{
	const unit &attacker = attacker_ptr ? *attacker_ptr : *units.find(attacker_loc);
	const unit &defender = *units.find(defender_loc);
	const double harm_weight = 1.0 - aggression;

	if (attacker_weapon == -1 && attacker.attacks().size() == 1 && attacker.attacks()[0].attack_weight() > 0 )
		attacker_weapon = 0;

	if (attacker_weapon == -1) {
		attacker_weapon = choose_attacker_weapon(attacker, defender, units,
			attacker_loc, defender_loc,
				harm_weight, &defender_weapon, prev_def);
	} else if (defender_weapon == -1) {
		defender_weapon = choose_defender_weapon(attacker, defender, attacker_weapon,
			units, attacker_loc, defender_loc, prev_def);
	}

	// If those didn't have to generate statistics, do so now.
	if (!attacker_stats_) {
		const attack_type *adef = nullptr;
		const attack_type *ddef = nullptr;
		if (attacker_weapon >= 0) {
			VALIDATE(attacker_weapon < static_cast<int>(attacker.attacks().size()),
					_("An invalid attacker weapon got selected."));
			adef = &attacker.attacks()[attacker_weapon];
		}
		if (defender_weapon >= 0) {
			VALIDATE(defender_weapon < static_cast<int>(defender.attacks().size()),
					_("An invalid defender weapon got selected."));
			ddef = &defender.attacks()[defender_weapon];
		}
		assert(!defender_stats_ && !attacker_combatant_ && !defender_combatant_);
		attacker_stats_ = new battle_context_unit_stats(attacker, attacker_loc, attacker_weapon,
				true, defender, defender_loc, ddef, units);
		defender_stats_ = new battle_context_unit_stats(defender, defender_loc, defender_weapon, false,
				attacker, attacker_loc, adef, units);
	}

	// There have been various bugs where only one of these was set
	assert(attacker_stats_);
	assert(defender_stats_);
}
开发者ID:CliffsDover,项目名称:wesnoth,代码行数:48,代码来源:attack.cpp

示例4: install_

		bool install_(const std::string& key, const T& value)
		{
			std::string fpath;
			if(!create_full_path(key, fpath)) {
				return false;
			}

			bool f = false;
			utils::strings ss = split_text(fpath, "/");
			std::string p;
			for(uint32_t i = 0; i < ss.size(); ++i) {
				p += '/';
				p += ss[i];
				unit_t u;
				u.value = value;
				u.set_id(serial_id_);
				std::pair<unit_map_it, bool> ret = unit_map_.insert(unit_pair(p, u));
				if(ret.second) {
					++serial_id_;
					auto prev = utils::get_file_path(p);
					if(p != prev) {
						unit_map_it it = unit_map_.find(prev);
						if(it != unit_map_.end()) {
							unit_t& t = it->second;
							t.install_child(utils::get_file_name(p));
						}
					}
					f = true;
				} else {
					f = false;
				}
			}
			return f;
		}
开发者ID:hirakuni45,项目名称:glfw3_app,代码行数:34,代码来源:tree_unit.hpp

示例5: apply_temp_modifier

void move::apply_temp_modifier(unit_map& unit_map)
{
	if (get_source_hex() == get_dest_hex())
		return; //zero-hex move, used by attack subclass

	// Safety: Make sure the old temporary_unit_mover (if any) is destroyed
	// before creating a new one.
	mover_.reset();

	//@todo: deal with multi-turn moves, which may for instance end their first turn
	// by capturing a village

	//@todo: we may need to change unit status here and change it back in remove_temp_modifier
	unit* unit;
	{
		unit_map::iterator unit_it = unit_map.find(get_source_hex());
		assert(unit_it != unit_map.end());
		unit = &*unit_it;
	}

	//Modify movement points
	DBG_WB <<"Move: Changing movement points for unit " << unit->name() << " [" << unit->id()
			<< "] from " << unit->movement_left() << " to "
			<< unit->movement_left() - movement_cost_ << ".\n";
	// Move the unit
	DBG_WB << "Move: Temporarily moving unit " << unit->name() << " [" << unit->id()
			<< "] from (" << get_source_hex() << ") to (" << get_dest_hex() <<")\n";
	mover_.reset(new temporary_unit_mover(unit_map, get_source_hex(), get_dest_hex(),
	                                      unit->movement_left() - movement_cost_));

	//Update status of fake unit (not undone by remove_temp_modifiers)
	//@todo this contradicts the name "temp_modifiers"
	fake_unit_->set_movement(unit->movement_left(), true);
}
开发者ID:,项目名称:,代码行数:34,代码来源:

示例6: can_generate

bool can_generate(const gamemap& map, const std::vector<team>& teams, const unit_map& units, const unit& u, const map_location& loc)
{
	if (!map.on_board(loc)) {
		return false;
	}
	if (u.movement_cost(map[loc]) == unit_movement_type::UNREACHABLE) {
		return false;
	}
	unit_map::const_iterator it = units.find(loc, false);
	if (it.valid() && !it->can_stand(u)) {
		return false;
	}

	map_location locs[6];
	get_adjacent_tiles(loc, locs);
	for (int i = 0; i != 6; ++i) {
		if (!map.on_board(locs[i])) {
			continue;
		}
		if (u.movement_cost(map[locs[i]]) != unit_movement_type::UNREACHABLE) {
			return true;
		}
	}
	return false;
}
开发者ID:coolsee,项目名称:War-Of-Kingdom,代码行数:25,代码来源:pathfind.cpp

示例7: time_of_day_at

time_of_day tod_manager::time_of_day_at(const unit_map& units,const map_location& loc, const gamemap& map) const
{
	int lighten = std::max<int>(map.get_terrain_info(map.get_terrain(loc)).light_modification() , 0);
	int darken = std::min<int>(map.get_terrain_info(map.get_terrain(loc)).light_modification() , 0);

	time_of_day tod = get_time_of_day(lighten + darken,loc);

	if(loc.valid()) {
		map_location locs[7];
		locs[0] = loc;
		get_adjacent_tiles(loc,locs+1);

		for(int i = 0; i != 7; ++i) {
			const unit_map::const_iterator itor = units.find(locs[i]);
			if(itor != units.end() &&
			    itor->second.get_ability_bool("illuminates") &&
			    !itor->second.incapacitated())
			{
				unit_ability_list illum = itor->second.get_abilities("illuminates");
				unit_abilities::effect illum_effect(illum,lighten,false);
				int mod = illum_effect.get_composite_value();
				if(mod + tod.lawful_bonus > illum.highest("max_value").first) {
					mod = illum.highest("max_value").first - tod.lawful_bonus;
				}
				lighten = std::max<int>(mod, lighten);
				darken = std::min<int>(mod, darken);
			}
		}
	}
	tod = get_time_of_day(lighten + darken,loc);

	return tod;
}
开发者ID:oys0317,项目名称:opensanguo,代码行数:33,代码来源:tod_manager.cpp

示例8: get_sub_directory

		//-----------------------------------------------------------------//
		utils::strings get_sub_directory(const std::string& root, bool full)
		{
			utils::strings list;

			auto fpath = create_full_path(root);
			if(fpath.empty()) {
				return list;
			}

			if(fpath.back() != '/') fpath += '/';

			unit_map_it it = unit_map_.find(fpath);
			if(it != unit_map_.end()) {
				const typename unit_t::childs& chs = it->second.get_childs();
				list.resize(chs.size());
				list.clear();
				for(const auto& s : chs) {
					if(full) {
						list.push_back(fpath + strip_last_of_delimita_path(s));
					} else {
						list.push_back(s);
					}
				}
			}
			return list;
		}
开发者ID:hirakuni45,项目名称:glfw3_app,代码行数:27,代码来源:tree_unit.hpp

示例9: create_list

		//-----------------------------------------------------------------//
		unit_map_its create_list(const std::string& root)
		{
			unit_map_its list;
			if(unit_map_.empty()) {
				list.clear();
				return list;
			}

			if(root.empty()) {
				list.resize(unit_map_.size());
				list.clear();
				for(unit_map_it it = unit_map_.begin(); it != unit_map_.end(); ++it) {
					list.push_back(it);
				}
			} else {
				auto fpath = create_full_path(root);
				if(fpath.empty()) {
					list.clear();
					return list;
				}

				unit_map_it it = unit_map_.find(fpath);
				if(it != unit_map_.end()) {
					const typename unit_t::childs& ch = it->second.get_childs();
					list.resize(ch.size());
					list.clear();
					for(const auto& s : ch) {
						auto path = create_full_path(s);
						if(!path.empty()) {
							it = unit_map_.find(path);
							if(it != unit_map_.end()) {
								list.push_back(it);
							}
						}
					}
				} else {
					list.clear();
				}
			}

			std::sort(list.begin(), list.end(), [] (unit_map_it l, unit_map_it r) {
				return l->first < r->first; }
			);

			return list;
		}
开发者ID:hirakuni45,项目名称:glfw3_app,代码行数:47,代码来源:tree_unit.hpp

示例10:

std::pair<int, map_location> under_leadership(const unit_map& units, const map_location& loc)
{
	const unit_map::const_iterator un = units.find(loc);
	if(un == units.end()) {
		return {0, map_location::null_location()};
	}

	unit_ability_list abil = un->get_abilities("leadership");
	return abil.highest("value");
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:10,代码来源:attack.cpp

示例11: is_directory

		//-----------------------------------------------------------------//
		bool is_directory(const std::string& path) const
		{
			auto fpath = create_full_path(path);
			if(fpath.empty()) {
				return false;
			}

			if(fpath.back() != '/') fpath += '/';

			return is_directory(unit_map_.find(fpath));
		}
开发者ID:hirakuni45,项目名称:glfw3_app,代码行数:12,代码来源:tree_unit.hpp

示例12: find

		//-----------------------------------------------------------------//
		uint32_t find(const std::string& path) const {
			auto fpath = create_full_path(path);
			if(fpath.empty()) {
				return 0;
			}

			unit_map_cit cit = unit_map_.find(fpath);
			if(cit != unit_map_.end()) {
				return cit->second.get_id();
			} else {
				return 0;
			}
		}
开发者ID:hirakuni45,项目名称:glfw3_app,代码行数:14,代码来源:tree_unit.hpp

示例13: under_leadership

map_location under_leadership(const unit_map& units, const map_location& loc,
                              int* bonus)
{
	const unit_map::const_iterator un = units.find(loc);
	if(un == units.end()) {
		return map_location::null_location;
	}
	unit_ability_list abil = un->get_abilities("leadership");
	if(bonus) {
		*bonus = abil.highest("value").first;
	}
	return abil.highest("value").second;
}
开发者ID:Coffee--,项目名称:wesnoth-old,代码行数:13,代码来源:attack.cpp

示例14: find_vacant_tile

map_location pathfind::find_vacant_tile(const gamemap& map,
				const unit_map& units,
				const map_location& loc,
				pathfind::VACANT_TILE_TYPE vacancy,
				const unit* pass_check)
{
	if (!map.on_board(loc)) return map_location();
	std::set<map_location> pending_tiles_to_check, tiles_checked;
	pending_tiles_to_check.insert(loc);
	// Iterate out 50 hexes from loc
	for (int distance = 0; distance < 50; ++distance) {
		if (pending_tiles_to_check.empty())
			return map_location();
		//Copy over the hexes to check and clear the old set
		std::set<map_location> tiles_checking;
		tiles_checking.swap(pending_tiles_to_check);
		//Iterate over all the hexes we need to check
		foreach (const map_location &loc, tiles_checking)
		{
			//If this area is not a castle but should, skip it.
			if (vacancy == pathfind::VACANT_CASTLE && !map.is_castle(loc)) continue;
			const bool pass_check_and_unreachable = pass_check
				&& pass_check->movement_cost(map[loc]) == unit_movement_type::UNREACHABLE;
			//If the unit can't reach the tile and we have searched
			//an area of at least radius 10 (arbitrary), skip the tile.
			//Neccessary for cases such as an unreachable
			//starting hex surrounded by 6 other unreachable hexes, in which case
			//the algorithm would not even search distance==1
			//even if there's a reachable hex for distance==2.
			if (pass_check_and_unreachable && distance > 10) continue;
			//If the hex is empty and we do either no pass check or the hex is reachable, return it.
			if (units.find(loc) == units.end() && !pass_check_and_unreachable) return loc;
			map_location adjs[6];
			get_adjacent_tiles(loc,adjs);
			foreach (const map_location &loc, adjs)
			{
				if (!map.on_board(loc)) continue;
				// Add the tile to be checked if it hasn't already been and
				// isn't being checked.
				if (tiles_checked.find(loc) == tiles_checked.end() &&
				    tiles_checking.find(loc) == tiles_checking.end())
				{
					pending_tiles_to_check.insert(loc);
				}
			}
		}
		tiles_checked.swap(tiles_checking);
	}
	return map_location();
}
开发者ID:ehsan,项目名称:wesnoth,代码行数:50,代码来源:pathfind.cpp

示例15: erase_

		uint32_t erase_(const std::string& fpath, handles& hnds)
		{
			unit_map_it it = unit_map_.find(fpath);
			if(it == unit_map_.end()) return 0;

			auto tpath = strip_last_of_delimita_path(fpath);
			auto bpath = get_file_path(tpath);
			bpath += '/';
			if(fpath.back() == '/') {  // is directory
				// erase sub directories
				unit_t::childs chs = it->second.get_childs();
				for(const auto& s : chs) {
//					std::cout << "Loop: " << (fpath + s) << std::endl;
					auto hnd = erase_(fpath + s, hnds);
					hnds.push_back(hnd);
				}
			}

			uint32_t hnd = 0;
			{
				unit_map_it it = unit_map_.find(fpath);
				if(it == unit_map_.end()) return 0;
				hnd = it->second.get_id();
				handle_set_.erase(hnd);
				unit_map_.erase(it);
			}

			{  // previous directory
				unit_map_it it = unit_map_.find(bpath);
				if(it != unit_map_.end()) {
					std::string s = get_file_name(tpath);
					if(fpath.back() == '/') s += '/';
					it->second.erase_child(s);
				}
			}
			return hnd;
		}
开发者ID:hirakuni45,项目名称:glfw3_app,代码行数:37,代码来源:tree_unit.hpp


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