本文整理汇总了C++中Thing::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Thing::getPosition方法的具体用法?C++ Thing::getPosition怎么用?C++ Thing::getPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thing
的用法示例。
在下文中一共展示了Thing::getPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: luagetDistanceTo
int NpcScriptInterface::luagetDistanceTo(lua_State* L)
{
//getDistanceTo(uid)
ScriptEnvironment* env = getScriptEnv();
Npc* npc = env->getNpc();
if (!npc) {
reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
lua_pushnil(L);
return 1;
}
uint32_t uid = getNumber<uint32_t>(L, -1);
Thing* thing = env->getThingByUID(uid);
if (!thing) {
reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
lua_pushnil(L);
return 1;
}
const Position& thingPos = thing->getPosition();
const Position& npcPos = npc->getPosition();
if (npcPos.z != thingPos.z) {
lua_pushnumber(L, -1);
} else {
int32_t dist = std::max<int32_t>(Position::getDistanceX(npcPos, thingPos), Position::getDistanceY(npcPos, thingPos));
lua_pushnumber(L, dist);
}
return 1;
}
示例2: luagetDistanceTo
int NpcScriptInterface::luagetDistanceTo(lua_State *L)
{
//getDistanceTo(uid)
uint32_t uid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Npc* npc = env->getNpc();
Thing* thing = env->getThingByUID(uid);
if(thing && npc){
Position thing_pos = thing->getPosition();
Position npc_pos = npc->getPosition();
if(npc_pos.z != thing_pos.z){
lua_pushnumber(L, -1);
}
else{
int32_t dist = std::max(std::abs(npc_pos.x - thing_pos.x), std::abs(npc_pos.y - thing_pos.y));
lua_pushnumber(L, dist);
}
}
else{
reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
lua_pushnil(L);
}
return 1;
}