int NodeTimerRef::l_stop(lua_State *L) { NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; env->getMap().removeNodeTimer(o->m_p); return 0; }
int NodeTimerRef::l_start(lua_State *L) { NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; f32 t = luaL_checknumber(L,2); env->getMap().setNodeTimer(o->m_p,NodeTimer(t,0)); return 0; }
int NodeTimerRef::l_get_elapsed(lua_State *L) { NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; NodeTimer t = env->getMap().getNodeTimer(o->m_p); lua_pushnumber(L,t.elapsed); return 1; }
int NodeTimerRef::l_is_started(lua_State *L) { NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; NodeTimer t = env->getMap().getNodeTimer(o->m_p); lua_pushboolean(L,(t.timeout != 0)); return 1; }
int NodeTimerRef::l_start(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; f32 t = readParam<float>(L,2); env->getMap().setNodeTimer(NodeTimer(t, 0, o->m_p)); return 0; }
int NodeTimerRef::l_get_timeout(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; NodeTimer t = env->getMap().getNodeTimer(o->m_p); lua_pushnumber(L,t.timeout); return 1; }
int NodeTimerRef::l_set(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; f32 t = luaL_checknumber(L,2); f32 e = luaL_checknumber(L,3); env->getMap().setNodeTimer(NodeTimer(t, e, o->m_p)); return 0; }
PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) { INodeDefManager *ndef = m_env->getGameDef()->ndef(); PathCost retval; retval.updated = true; v3s16 pos2 = pos + dir; //check limits if (!m_limits.isPointInside(pos2)) { DEBUG_OUT("Pathfinder: " << PP(pos2) << " no cost -> out of limits" << std::endl); return retval; } MapNode node_at_pos2 = m_env->getMap().getNodeNoEx(pos2); //did we get information about node? if (node_at_pos2.param0 == CONTENT_IGNORE ) { VERBOSE_TARGET << "Pathfinder: (1) area at pos: " << PP(pos2) << " not loaded"; return retval; } if (!ndef->get(node_at_pos2).walkable) { MapNode node_below_pos2 = m_env->getMap().getNodeNoEx(pos2 + v3s16(0, -1, 0)); //did we get information about node? if (node_below_pos2.param0 == CONTENT_IGNORE ) { VERBOSE_TARGET << "Pathfinder: (2) area at pos: " << PP((pos2 + v3s16(0, -1, 0))) << " not loaded"; return retval; } if (ndef->get(node_below_pos2).walkable) { retval.valid = true; retval.value = 1; retval.direction = 0; DEBUG_OUT("Pathfinder: "<< PP(pos) << " cost same height found" << std::endl); } else { v3s16 testpos = pos2 - v3s16(0, -1, 0); MapNode node_at_pos = m_env->getMap().getNodeNoEx(testpos); while ((node_at_pos.param0 != CONTENT_IGNORE) && (!ndef->get(node_at_pos).walkable) && (testpos.Y > m_limits.MinEdge.Y)) { testpos += v3s16(0, -1, 0); node_at_pos = m_env->getMap().getNodeNoEx(testpos); } //did we find surface? if ((testpos.Y >= m_limits.MinEdge.Y) && (node_at_pos.param0 != CONTENT_IGNORE) && (ndef->get(node_at_pos).walkable)) { if ((pos2.Y - testpos.Y - 1) <= m_maxdrop) { retval.valid = true; retval.value = 2; //difference of y-pos +1 (target node is ABOVE solid node) retval.direction = ((testpos.Y - pos2.Y) +1); DEBUG_OUT("Pathfinder cost below height found" << std::endl); } else { INFO_TARGET << "Pathfinder:" " distance to surface below to big: " << (testpos.Y - pos2.Y) << " max: " << m_maxdrop << std::endl; } } else { DEBUG_OUT("Pathfinder: no surface below found" << std::endl); } } } else { v3s16 testpos = pos2; MapNode node_at_pos = m_env->getMap().getNodeNoEx(testpos); while ((node_at_pos.param0 != CONTENT_IGNORE) && (ndef->get(node_at_pos).walkable) && (testpos.Y < m_limits.MaxEdge.Y)) { testpos += v3s16(0, 1, 0); node_at_pos = m_env->getMap().getNodeNoEx(testpos); } //did we find surface? if ((testpos.Y <= m_limits.MaxEdge.Y) && (!ndef->get(node_at_pos).walkable)) { if (testpos.Y - pos2.Y <= m_maxjump) { retval.valid = true; retval.value = 2; retval.direction = (testpos.Y - pos2.Y); DEBUG_OUT("Pathfinder cost above found" << std::endl); } else { DEBUG_OUT("Pathfinder: distance to surface above to big: " << (testpos.Y - pos2.Y) << " max: " << m_maxjump << std::endl); } } else { DEBUG_OUT("Pathfinder: no surface above found" << std::endl); } } return retval; }