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


C++ thread_specific_ptr::getMapHeader方法代码示例

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


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

示例1: whatToDoToAchieve

TSubgoal Win::whatToDoToAchieve()
{
	auto toBool = [=](const EventCondition &)
	{
		// TODO: proper implementation
		// Right now even already fulfilled goals will be included into generated list
		// Proper check should test if event condition is already fulfilled
		// Easiest way to do this is to call CGameState::checkForVictory but this function should not be
		// used on client side or in AI code
		return false;
	};

	std::vector<EventCondition> goals;

	for (const TriggeredEvent & event : cb->getMapHeader()->triggeredEvents)
	{
		//TODO: try to eliminate human player(s) using loss conditions that have isHuman element

		if (event.effect.type == EventEffect::VICTORY)
		{
			boost::range::copy(event.trigger.getFulfillmentCandidates(toBool), std::back_inserter(goals));
		}
	}

	//TODO: instead of returning first encountered goal AI should generate list of possible subgoals
	for (const EventCondition & goal : goals)
	{
		switch(goal.condition)
		{
		case EventCondition::HAVE_ARTIFACT:
			return sptr (Goals::GetArtOfType(goal.objectType));
		case EventCondition::DESTROY:
			{
				if (goal.object)
				{
					return sptr (Goals::GetObj(goal.object->id.getNum()));
				}
				else
				{
					// TODO: destroy all objects of type goal.objectType
					// This situation represents "kill all creatures" condition from H3
					break;
				}
			}
		case EventCondition::HAVE_BUILDING:
			{
			// TODO build other buildings apart from Grail
			// goal.objectType = buidingID to build
			// goal.object = optional, town in which building should be built
			// Represents "Improve town" condition from H3 (but unlike H3 it consists from 2 separate conditions)

				if (goal.objectType == BuildingID::GRAIL)
				{
					if(auto h = ai->getHeroWithGrail())
					{
						//hero is in a town that can host Grail
						if(h->visitedTown && !vstd::contains(h->visitedTown->forbiddenBuildings, BuildingID::GRAIL))
						{
							const CGTownInstance *t = h->visitedTown;
							return sptr (Goals::BuildThis(BuildingID::GRAIL, t));
						}
						else
						{
							auto towns = cb->getTownsInfo();
							towns.erase(boost::remove_if(towns,
												[](const CGTownInstance *t) -> bool
												{
													return vstd::contains(t->forbiddenBuildings, BuildingID::GRAIL);
												}),
										towns.end());
							boost::sort(towns, isCloser);
							if(towns.size())
							{
								return sptr (Goals::VisitTile(towns.front()->visitablePos()).sethero(h));
							}
						}
					}
					double ratio = 0;
					// maybe make this check a bit more complex? For example:
					// 0.75 -> dig randomly withing 3 tiles radius
					// 0.85 -> radius now 2 tiles
					// 0.95 -> 1 tile radius, position is fully known
					// AFAIK H3 AI does something like this
					int3 grailPos = cb->getGrailPos(ratio);
					if(ratio > 0.99)
					{
						return sptr (Goals::DigAtTile(grailPos));
					} //TODO: use FIND_OBJ
					else if(const CGObjectInstance * obj = ai->getUnvisitedObj(objWithID<Obj::OBELISK>)) //there are unvisited Obelisks
						return sptr (Goals::GetObj(obj->id.getNum()));
					else
						return sptr (Goals::Explore());
				}
				break;
			}
		case EventCondition::CONTROL:
			{
				if (goal.object)
				{
					return sptr (Goals::GetObj(goal.object->id.getNum()));
//.........这里部分代码省略.........
开发者ID:szpak,项目名称:vcmi,代码行数:101,代码来源:Goals.cpp


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