本文整理汇总了C++中boost::thread_specific_ptr::getTownsInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ thread_specific_ptr::getTownsInfo方法的具体用法?C++ thread_specific_ptr::getTownsInfo怎么用?C++ thread_specific_ptr::getTownsInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::thread_specific_ptr
的用法示例。
在下文中一共展示了thread_specific_ptr::getTownsInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: whatToDoToTrade
TSubgoal CollectRes::whatToDoToTrade()
{
std::vector<const IMarket *> markets;
std::vector<const CGObjectInstance *> visObjs;
ai->retrieveVisitableObjs(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)
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
{
if (!(market->o->ID == Obj::TOWN && market->o->tempOwner == ai->playerID))
{
if (!ai->isAccessible(market->o->visitablePos()))
return true;
}
return false;
}), markets.end());
if (!markets.size())
{
for (const CGTownInstance * t : cb->getTownsInfo())
{
if (cb->canBuildStructure(t, BuildingID::MARKETPLACE) == EBuildingState::ALLOWED)
return sptr(BuildThis(BuildingID::MARKETPLACE, t).setpriority(2));
}
}
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 * (ai->ah->freeResources()[i] / toGive);
}
if (howManyCanWeBuy >= value)
{
auto backObj = cb->getTopObj(m->o->visitablePos()); //it'll be a hero if we have one there; otherwise marketplace
assert(backObj);
auto objid = m->o->id.getNum();
if (backObj->tempOwner != ai->playerID) //top object not owned
{
return sptr(VisitObj(objid)); //just go there
}
else //either it's our town, or we have hero there
{
return sptr(Trade(resID, value, objid).setisElementar(true)); //we can do this immediately
}
}
}
return sptr(Invalid()); //cannot trade
}
示例3: getAllPossibleSubgoals
TGoalVec GatherArmy::getAllPossibleSubgoals()
{
//get all possible towns, heroes and dwellings we may use
TGoalVec ret;
if(!hero.validAndSet())
{
return ret;
}
//TODO: include evaluation of monsters gather in calculation
for(auto t : cb->getTownsInfo())
{
auto waysToVisit = ai->ah->howToVisitObj(hero, t);
if(waysToVisit.size())
{
//grab army from town
if(!t->visitingHero && howManyReinforcementsCanGet(hero.get(), t))
{
if(!vstd::contains(ai->townVisitsThisWeek[hero], t))
vstd::concatenate(ret, waysToVisit);
}
//buy army in town
if (!t->visitingHero || t->visitingHero == hero.get(true))
{
std::vector<int> values = {
value,
(int)howManyReinforcementsCanBuy(t->getUpperArmy(), t),
(int)howManyReinforcementsCanBuy(hero.get(), t) };
int val = *std::min_element(values.begin(), values.end());
if (val)
{
auto goal = sptr(BuyArmy(t, val).sethero(hero));
if(!ai->ah->containsObjective(goal)) //avoid loops caused by reserving same objective twice
ret.push_back(goal);
else
logAi->debug("Can not buy army, because of ai->ah->containsObjective");
}
}
//build dwelling
//TODO: plan building over multiple turns?
//auto bid = ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 8 - cb->getDate(Date::DAY_OF_WEEK));
//Do not use below code for now, rely on generic Build. Code below needs to know a lot of town/resource context to do more good than harm
/*auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 1);
if (bid.is_initialized())
{
auto goal = sptr(BuildThis(bid.get(), t).setpriority(priority));
if (!ai->ah->containsObjective(goal)) //avoid loops caused by reserving same objective twice
ret.push_back(goal);
else
logAi->debug("Can not build a structure, because of ai->ah->containsObjective");
}*/
}
}
auto otherHeroes = cb->getHeroesInfo();
auto heroDummy = hero;
vstd::erase_if(otherHeroes, [heroDummy](const CGHeroInstance * h)
{
if(h == heroDummy.h)
return true;
else if(!ai->isAccessibleForHero(heroDummy->visitablePos(), h, true))
return true;
else if(!ai->canGetArmy(heroDummy.h, h)) //TODO: return actual aiValue
return true;
else if(ai->getGoal(h)->goalType == GATHER_ARMY)
return true;
else
return false;
});
for(auto h : otherHeroes)
{
// Go to the other hero if we are faster
if(!vstd::contains(ai->visitedHeroes[hero], h))
{
vstd::concatenate(ret, ai->ah->howToVisitObj(hero, h));
}
// Go to the other hero if we are faster
if(!vstd::contains(ai->visitedHeroes[h], hero))
{
vstd::concatenate(ret, ai->ah->howToVisitObj(h, hero.get()));
}
}
std::vector<const CGObjectInstance *> objs;
for(auto obj : ai->visitableObjs)
{
if(obj->ID == Obj::CREATURE_GENERATOR1)
{
auto relationToOwner = cb->getPlayerRelations(obj->getOwner(), ai->playerID);
//Use flagged dwellings only when there are available creatures that we can afford
//.........这里部分代码省略.........