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

C++ unit_map类代码示例

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

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



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

示例1: assert

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,代码来源:


示例2: 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


示例3: verify

static void verify(const unit_map& units, const config& cfg) {
	std::stringstream errbuf;
	LOG_REPLAY << "verifying unit structure...\n";

	const size_t nunits = cfg["num_units"].to_size_t();
	if(nunits != units.size()) {
		errbuf << "SYNC VERIFICATION FAILED: number of units from data source differ: "
			   << nunits << " according to data source. " << units.size() << " locally\n";

		std::set<map_location> locs;
		BOOST_FOREACH(const config &u, cfg.child_range("unit"))
		{
			const map_location loc(u);
			locs.insert(loc);

			if(units.count(loc) == 0) {
				errbuf << "data source says there is a unit at "
					   << loc << " but none found locally\n";
			}
		}

		for(unit_map::const_iterator j = units.begin(); j != units.end(); ++j) {
			if (locs.count(j->get_location()) == 0) {
				errbuf << "local unit at " << j->get_location()
					   << " but none in data source\n";
			}
		}
		replay::process_error(errbuf.str());
		errbuf.clear();
	}
开发者ID:nguyenducnhaty,项目名称:wesnoth,代码行数:30,代码来源:replay.cpp


示例4: get_time_of_day

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


示例5: 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


示例6: 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


示例7: 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


示例8: reset

void move_unit_spectator::reset(const unit_map &units)
{
	ambusher_ = units.end();
	failed_teleport_ = units.end();
	seen_enemies_.clear();
	seen_friends_.clear();
	unit_ = units.end();
}
开发者ID:kreuz,项目名称:wesnoth,代码行数:8,代码来源:move.cpp


示例9:

unit_map::unit_map(const unit_map& that)
	: umap_()
	, lmap_()
{
	for (const_unit_iterator i = that.begin(); i != that.end(); ++i) {
		add(i->get_location(), *i);
	}
}
开发者ID:niegenug,项目名称:wesnoth,代码行数:8,代码来源:unit_map.cpp


示例10: under_leadership

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:

unit_map::unit_map(const unit_map& that) :
	/* Initialize to silence compiler warnings. */
	map_(),
	lmap_(),
	num_iters_(0),
	num_invalid_(0)
{
	for (const_unit_iterator i = that.begin(); i != that.end(); i++) {
		add(i->first, i->second);
	}
}
开发者ID:oys0317,项目名称:opensanguo,代码行数:11,代码来源:unit_map.cpp


示例12: 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


示例13: 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


示例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: can_up_treasure

bool can_up_treasure(unit_map& units, const hero& h)
{
	if (tent::tower_mode()) {
		return true;
	}
	unit* u = units.find_unit(h);
	if (u->is_city()) {
		return true;
	}
	artifical* city = units.city_from_loc(u->get_location());
	if (city) {
		return true;
	}
	return false;
}
开发者ID:hyrio,项目名称:War-Of-Kingdom,代码行数:15,代码来源:treasure.cpp


示例16: 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


示例17: assert

void recall::apply_temp_modifier(unit_map& unit_map)
{
	assert(valid_);
	temp_unit_->set_location(recall_hex_);

	DBG_WB << "Inserting future recall " << temp_unit_->name() << " [" << temp_unit_->id()
			<< "] at position " << temp_unit_->get_location() << ".\n";

	//temporarily remove unit from recall list
	std::vector<unit>& recalls = resources::teams->at(team_index()).recall_list();
	std::vector<unit>::iterator it = std::find_if(recalls.begin(), recalls.end(),
					unit_comparator_predicate(*temp_unit_));
	assert(it != recalls.end());
	recalls.erase(it);

	// Temporarily insert unit into unit_map
	unit_map.insert(temp_unit_);
	//unit map takes ownership of temp_unit
	temp_unit_ = NULL;

	//Add cost to money spent on recruits.
	temp_cost_ = resources::teams->at(team_index()).recall_cost();
	resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(temp_cost_);

	// Update gold in top bar
	resources::screen->invalidate_game_status();
}
开发者ID:blackberry,项目名称:Wesnoth,代码行数:27,代码来源:recall.cpp


示例18: 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


示例19: swap

void unit_map::swap(unit_map& o)
{
	assert(num_iters() == 0 && o.num_iters() == 0);

	std::swap(umap_, o.umap_);
	std::swap(lmap_, o.lmap_);
}
开发者ID:GregoryLundberg,项目名称:wesnoth,代码行数:7,代码来源:map.cpp


示例20: assert

void recall::apply_temp_modifier(unit_map& unit_map)
{
	assert(valid());
	temp_unit_->set_location(recall_hex_);

	DBG_WB << "Inserting future recall " << temp_unit_->name() << " [" << temp_unit_->id()
			<< "] at position " << temp_unit_->get_location() << ".\n";

	//temporarily remove unit from recall list
	UnitPtr it = resources::teams->at(team_index()).recall_list().extract_if_matches_id(temp_unit_->id());
	assert(it);

	//Add cost to money spent on recruits.
	int cost = resources::teams->at(team_index()).recall_cost();
	if (it->recall_cost() > -1) {
		cost = it->recall_cost();
	}

	// Temporarily insert unit into unit_map
	//unit map takes ownership of temp_unit
	unit_map.insert(temp_unit_);

	resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(cost);
	// Update gold in top bar
	resources::screen->invalidate_game_status();
}
开发者ID:AlainODea,项目名称:wesnoth,代码行数:26,代码来源:recall.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ unit_type类代码示例发布时间:2022-05-31
下一篇:
C++ unit类代码示例发布时间: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