本文整理汇总了C++中THMap::getParcelOwner方法的典型用法代码示例。如果您正苦于以下问题:C++ THMap::getParcelOwner方法的具体用法?C++ THMap::getParcelOwner怎么用?C++ THMap::getParcelOwner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类THMap
的用法示例。
在下文中一共展示了THMap::getParcelOwner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: l_map_get_litter_fraction
/* Compute the fraction of corridor tiles with litter, of the parcels owned by the given player. */
static int l_map_get_litter_fraction(lua_State *L)
{
THMap* pMap = luaT_testuserdata<THMap>(L);
int owner = static_cast<int>(luaL_checkinteger(L, 2));
if (owner == 0)
{
lua_pushnumber(L, 0.0); // Outside has no litter.
return 1;
}
double tile_count = 0;
double litter_count = 0;
for (int x = 0; x < pMap->getWidth(); x++)
{
for (int y = 0; y < pMap->getHeight(); y++)
{
const THMapNode* pNode = pMap->getNodeUnchecked(x, y);
if (pNode->iParcelId == 0 || owner != pMap->getParcelOwner(pNode->iParcelId) ||
pNode->iRoomId != 0)
{
continue;
}
tile_count++;
for(auto iter = pNode->objects.begin(); iter != pNode->objects.end(); iter++)
{
if(*iter == THObjectType::litter)
{
litter_count++;
break;
}
}
}
}
double fraction = (tile_count == 0) ? 0.0 : litter_count / tile_count;
lua_pushnumber(L, fraction);
return 1;
}
示例2: l_map_get_parcel_owner
static int l_map_get_parcel_owner(lua_State *L)
{
THMap* pMap = luaT_testuserdata<THMap>(L);
lua_pushinteger(L, pMap->getParcelOwner(static_cast<int>(luaL_checkinteger(L, 2))));
return 1;
}