Make line_of_sight return blocking node position
parent
33de69a173
commit
d9ef072305
|
@ -1308,8 +1308,9 @@ minetest.set_mapgen_params(MapgenParams)
|
||||||
^ flags and flagmask are in the same format and have the same options as 'mgflags' in minetest.conf
|
^ flags and flagmask are in the same format and have the same options as 'mgflags' in minetest.conf
|
||||||
minetest.clear_objects()
|
minetest.clear_objects()
|
||||||
^ clear all objects in the environments
|
^ clear all objects in the environments
|
||||||
minetest.line_of_sight(pos1,pos2,stepsize) ->true/false
|
minetest.line_of_sight(pos1, pos2, stepsize) -> true/false, pos
|
||||||
^ checkif there is a direct line of sight between pos1 and pos2
|
^ Check if there is a direct line of sight between pos1 and pos2
|
||||||
|
^ Returns the position of the blocking node when false
|
||||||
^ pos1 First position
|
^ pos1 First position
|
||||||
^ pos2 Second position
|
^ pos2 Second position
|
||||||
^ stepsize smaller gives more accurate results but requires more computing
|
^ stepsize smaller gives more accurate results but requires more computing
|
||||||
|
|
|
@ -354,7 +354,7 @@ ServerMap & ServerEnvironment::getServerMap()
|
||||||
return *m_map;
|
return *m_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize)
|
bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize, v3s16 *p)
|
||||||
{
|
{
|
||||||
float distance = pos1.getDistanceFrom(pos2);
|
float distance = pos1.getDistanceFrom(pos2);
|
||||||
|
|
||||||
|
@ -372,6 +372,9 @@ bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize)
|
||||||
MapNode n = getMap().getNodeNoEx(pos);
|
MapNode n = getMap().getNodeNoEx(pos);
|
||||||
|
|
||||||
if(n.param0 != CONTENT_AIR) {
|
if(n.param0 != CONTENT_AIR) {
|
||||||
|
if (p) {
|
||||||
|
*p = pos;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,7 +295,7 @@ public:
|
||||||
void step(f32 dtime);
|
void step(f32 dtime);
|
||||||
|
|
||||||
//check if there's a line of sight between two positions
|
//check if there's a line of sight between two positions
|
||||||
bool line_of_sight(v3f pos1, v3f pos2, float stepsize=1.0);
|
bool line_of_sight(v3f pos1, v3f pos2, float stepsize=1.0, v3s16 *p=NULL);
|
||||||
|
|
||||||
u32 getGameTime() { return m_game_time; }
|
u32 getGameTime() { return m_game_time; }
|
||||||
|
|
||||||
|
|
|
@ -648,7 +648,7 @@ int ModApiEnvMod::l_clear_objects(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// minetest.line_of_sight(pos1, pos2, stepsize) -> true/false
|
// minetest.line_of_sight(pos1, pos2, stepsize) -> true/false, pos
|
||||||
int ModApiEnvMod::l_line_of_sight(lua_State *L) {
|
int ModApiEnvMod::l_line_of_sight(lua_State *L) {
|
||||||
float stepsize = 1.0;
|
float stepsize = 1.0;
|
||||||
|
|
||||||
|
@ -663,7 +663,13 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) {
|
||||||
stepsize = lua_tonumber(L, 3);
|
stepsize = lua_tonumber(L, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushboolean(L, env->line_of_sight(pos1,pos2,stepsize));
|
v3s16 p;
|
||||||
|
bool success = env->line_of_sight(pos1, pos2, stepsize, &p);
|
||||||
|
lua_pushboolean(L, success);
|
||||||
|
if (!success) {
|
||||||
|
push_v3s16(L, p);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue