本文整理汇总了C++中boost::thread_specific_ptr::retreiveVisitableObjs方法的典型用法代码示例。如果您正苦于以下问题:C++ thread_specific_ptr::retreiveVisitableObjs方法的具体用法?C++ thread_specific_ptr::retreiveVisitableObjs怎么用?C++ thread_specific_ptr::retreiveVisitableObjs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::thread_specific_ptr
的用法示例。
在下文中一共展示了thread_specific_ptr::retreiveVisitableObjs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: whatToDoToAchieve
TSubgoal CollectRes::whatToDoToAchieve()
{
std::vector<const IMarket*> markets;
std::vector<const CGObjectInstance*> visObjs;
ai->retreiveVisitableObjs(visObjs, true);
for(const CGObjectInstance *obj : visObjs)
{
if(const IMarket *m = IMarket::castFrom(obj, false))
{
if(obj->ID == Obj::TOWN && obj->tempOwner == ai->playerID && m->allowsTrade(EMarketMode::RESOURCE_RESOURCE))
markets.push_back(m);
else if(obj->ID == Obj::TRADING_POST) //TODO a moze po prostu test na pozwalanie handlu?
markets.push_back(m);
}
}
boost::sort(markets, [](const IMarket *m1, const IMarket *m2) -> bool
{
return m1->getMarketEfficiency() < m2->getMarketEfficiency();
});
markets.erase(boost::remove_if(markets, [](const IMarket *market) -> bool
{
return !(market->o->ID == Obj::TOWN && market->o->tempOwner == ai->playerID)
&& !ai->isAccessible(market->o->visitablePos());
}),markets.end());
if(!markets.size())
{
for(const CGTownInstance *t : cb->getTownsInfo())
{
if(cb->canBuildStructure(t, BuildingID::MARKETPLACE) == EBuildingState::ALLOWED)
return sptr (Goals::BuildThis(BuildingID::MARKETPLACE, t));
}
}
else
{
const IMarket *m = markets.back();
//attempt trade at back (best prices)
int howManyCanWeBuy = 0;
for(Res::ERes i = Res::WOOD; i <= Res::GOLD; vstd::advance(i, 1))
{
if(i == resID) continue;
int toGive = -1, toReceive = -1;
m->getOffer(i, resID, toGive, toReceive, EMarketMode::RESOURCE_RESOURCE);
assert(toGive > 0 && toReceive > 0);
howManyCanWeBuy += toReceive * (cb->getResourceAmount(i) / toGive);
}
if(howManyCanWeBuy + cb->getResourceAmount(static_cast<Res::ERes>(resID)) >= value)
{
auto backObj = cb->getTopObj(m->o->visitablePos()); //it'll be a hero if we have one there; otherwise marketplace
assert(backObj);
if (backObj->tempOwner != ai->playerID)
{
return sptr (Goals::GetObj(m->o->id.getNum()));
}
else
{
return sptr (Goals::GetObj(m->o->id.getNum()).setisElementar(true));
}
}
}
return sptr (setisElementar(true)); //all the conditions for trade are met
}