本文整理汇总了C++中Town::GetPercentTransported方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::GetPercentTransported方法的具体用法?C++ Town::GetPercentTransported怎么用?C++ Town::GetPercentTransported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Town
的用法示例。
在下文中一共展示了Town::GetPercentTransported方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindSubsidyPassengerRoute
/**
* Tries to create a passenger subsidy between two towns.
* @return True iff the subsidy was created.
*/
bool FindSubsidyPassengerRoute()
{
if (!Subsidy::CanAllocateItem()) return false;
Town *src = Town::GetRandom();
if (src->cache.population < SUBSIDY_PAX_MIN_POPULATION ||
src->GetPercentTransported(CT_PASSENGERS) > SUBSIDY_MAX_PCT_TRANSPORTED) {
return false;
}
const Town *dst = NULL;
if (CargoHasDestinations(CT_PASSENGERS)) {
/* Try to get a town from the demand destinations. */
CargoLink *link = src->GetRandomLink(CT_PASSENGERS, false);
if (link == src->cargo_links[CT_PASSENGERS].End()) return NULL;
if (link->dest != NULL && link->dest->GetType() != ST_TOWN) return NULL;
dst = static_cast<const Town *>(link->dest);
}
if (dst == NULL) dst = Town::GetRandom();
if (dst->cache.population < SUBSIDY_PAX_MIN_POPULATION || src == dst) {
return false;
}
if (DistanceManhattan(src->xy, dst->xy) > SUBSIDY_MAX_DISTANCE) return false;
if (CheckSubsidyDuplicate(CT_PASSENGERS, ST_TOWN, src->index, ST_TOWN, dst->index)) return false;
CreateSubsidy(CT_PASSENGERS, ST_TOWN, src->index, ST_TOWN, dst->index);
return true;
}