aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/environment.cpp5
-rw-r--r--src/environment.h2
-rw-r--r--src/script/lua_api/l_env.cpp10
3 files changed, 13 insertions, 4 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index e4567a78e..7fe5d356a 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -354,7 +354,7 @@ ServerMap & ServerEnvironment::getServerMap()
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);
@@ -372,6 +372,9 @@ bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize)
MapNode n = getMap().getNodeNoEx(pos);
if(n.param0 != CONTENT_AIR) {
+ if (p) {
+ *p = pos;
+ }
return false;
}
}
diff --git a/src/environment.h b/src/environment.h
index 9f9a0a23c..d9804e781 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -295,7 +295,7 @@ public:
void step(f32 dtime);
//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; }
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 4a8150396..d01889401 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -648,7 +648,7 @@ int ModApiEnvMod::l_clear_objects(lua_State *L)
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) {
float stepsize = 1.0;
@@ -663,7 +663,13 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) {
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;
}