Skip to content

Commit d9ef072

Browse files
stujones11ShadowNinja
stujones11
authored andcommittedDec 12, 2013
Make line_of_sight return blocking node position
1 parent 33de69a commit d9ef072

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed
 

‎doc/lua_api.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,9 @@ minetest.set_mapgen_params(MapgenParams)
13081308
^ flags and flagmask are in the same format and have the same options as 'mgflags' in minetest.conf
13091309
minetest.clear_objects()
13101310
^ clear all objects in the environments
1311-
minetest.line_of_sight(pos1,pos2,stepsize) ->true/false
1312-
^ checkif there is a direct line of sight between pos1 and pos2
1311+
minetest.line_of_sight(pos1, pos2, stepsize) -> true/false, pos
1312+
^ Check if there is a direct line of sight between pos1 and pos2
1313+
^ Returns the position of the blocking node when false
13131314
^ pos1 First position
13141315
^ pos2 Second position
13151316
^ stepsize smaller gives more accurate results but requires more computing

‎src/environment.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ ServerMap & ServerEnvironment::getServerMap()
354354
return *m_map;
355355
}
356356

357-
bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize)
357+
bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize, v3s16 *p)
358358
{
359359
float distance = pos1.getDistanceFrom(pos2);
360360

@@ -372,6 +372,9 @@ bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize)
372372
MapNode n = getMap().getNodeNoEx(pos);
373373

374374
if(n.param0 != CONTENT_AIR) {
375+
if (p) {
376+
*p = pos;
377+
}
375378
return false;
376379
}
377380
}

‎src/environment.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class ServerEnvironment : public Environment
295295
void step(f32 dtime);
296296

297297
//check if there's a line of sight between two positions
298-
bool line_of_sight(v3f pos1, v3f pos2, float stepsize=1.0);
298+
bool line_of_sight(v3f pos1, v3f pos2, float stepsize=1.0, v3s16 *p=NULL);
299299

300300
u32 getGameTime() { return m_game_time; }
301301

‎src/script/lua_api/l_env.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ int ModApiEnvMod::l_clear_objects(lua_State *L)
648648
return 0;
649649
}
650650

651-
// minetest.line_of_sight(pos1, pos2, stepsize) -> true/false
651+
// minetest.line_of_sight(pos1, pos2, stepsize) -> true/false, pos
652652
int ModApiEnvMod::l_line_of_sight(lua_State *L) {
653653
float stepsize = 1.0;
654654

@@ -663,7 +663,13 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) {
663663
stepsize = lua_tonumber(L, 3);
664664
}
665665

666-
lua_pushboolean(L, env->line_of_sight(pos1,pos2,stepsize));
666+
v3s16 p;
667+
bool success = env->line_of_sight(pos1, pos2, stepsize, &p);
668+
lua_pushboolean(L, success);
669+
if (!success) {
670+
push_v3s16(L, p);
671+
return 2;
672+
}
667673
return 1;
668674
}
669675

0 commit comments

Comments
 (0)