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


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

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


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

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

示例2: add_modification

void hero::add_modification(unit_map& units, hero_map& heros, std::vector<team>& teams, const config& mod, unit* u, hero* leader)
{
	foreach (const config &effect, mod.child_range("effect")) {
		const std::string &apply_to = effect["apply_to"];

		if (apply_to == "loyalty") {
			int increase = effect["increase"].to_int();

			if (increase) {
				increase_catalog(-1 * increase, *leader);
				if (!u->is_artifical()) {
					u->adjust();
				}
				// play animation
				std::stringstream str;
				str << dgettext("wesnoth", "loyalty") << "\n";
				std::vector<unit*> touchers;
				if (artifical* city = units.city_from_loc(u->get_location())) {
					touchers.push_back((unit*)(city));
				} else {
					touchers.push_back(u);
				}
				unit_display::unit_touching(u->get_location(), touchers, increase, str.str());
			}			
		} else if (apply_to == "office") {
			artifical* selected_city = unit_2_artifical(u);

			status_ = hero_status_backing;
			side_ = selected_city->side() - 1;
			selected_city->finish_heros().push_back(this);
			std::vector<hero*>& wander_heros = selected_city->wander_heros();
			wander_heros.erase(std::find(wander_heros.begin(), wander_heros.end(), this));

			std::string message = _("Let me join in. I will do my best to maintenance our honor.");
			show_hero_message(this, selected_city, message, game_events::INCIDENT_RECOMMENDONESELF);

			map_location loc2(MAGIC_HERO, number_);
			game_events::fire("post_recommend", selected_city->get_location(), loc2);

		} else if (apply_to == "wande") {
			std::vector<hero*> captains;
			if (artifical* city = units.city_from_loc(u->get_location())) {
				// fresh/finish/reside troop
				if (u->is_city()) {
					for (int type = 0; type < 3; type ++) { 
						std::vector<hero*>* list;
						if (type == 0) {
							list = &city->fresh_heros();
						} else if (type == 1) {
							list = &city->finish_heros();
						} else {
							list = &city->wander_heros();
						}
						std::vector<hero*>::iterator i2 = std::find(list->begin(), list->end(), this);
						if (i2 != list->end()) {
							list->erase(i2);
							break;
						}
					}
				} else {
					std::vector<unit*>& reside_troops = city->reside_troops();
					int index = 0;
					for (std::vector<unit*>::iterator i2 = reside_troops.begin(); i2 != reside_troops.end(); ++ i2, index ++) {
						if (*i2 != u) {
							continue;
						}
						u->replace_captains_internal(*this, captains);
						if (captains.empty()) {
							city->troop_go_out(index);
						} else {
							u->replace_captains(captains);
						}
						break;
					}
				}
			} else {
				// field troop
				u->replace_captains_internal(*this, captains);
				if (captains.empty()) {
					units.erase(u);
				} else {
					u->replace_captains(captains);
				}
			}
			// select one city in myself side
			artifical* to_city = units.city_from_cityno(leader->city_);
			to_city->wander_into(*this);

		} else if (apply_to == "communicate") {
			int increase = effect["increase"].to_int();
			std::vector<std::pair<int, unit*> > pairs;

			for (hero_map::iterator i = heros.begin(); i != heros.end(); ++ i) {
				const hero& h = *i;
				if (h.side_ != side_ || h.number_ == number_) {
					continue;
				}
				unit* u = find_unit(units, h);
				if (u->is_city() && h.number_ == u->master().number_) {
					continue;
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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