Advertisement
Guest User

Untitled

a guest
Jan 7th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. --- git/minetest.modif/src/scriptapi.cpp 2012-01-07 15:08:37.000000000 +0100
  2. +++ minetest/src/scriptapi.cpp 2012-01-07 16:07:05.000000000 +0100
  3. @@ -2543,6 +2543,54 @@
  4. return 1;
  5. }
  6.  
  7. + // EnvRef:get_line_of_sight(pos,pos)
  8. + static int l_get_line_of_sight(lua_State *L)
  9. + {
  10. + //infostream<<"EnvRef::l_get_node()"<<std::endl;
  11. + EnvRef *o = checkobject(L, 1);
  12. + ServerEnvironment *env = o->m_env;
  13. + if(env == NULL) return 0;
  14. +
  15. + // pos1
  16. + v3f pos1 = checkFloatPos(L, 2);
  17. +
  18. + // pos2
  19. + v3f pos2 = checkFloatPos(L, 2);
  20. +
  21. +
  22. + float distance = pos1.getDistanceFrom(pos2);
  23. +
  24. + //calculate normalized direction vector
  25. + v3f normalized_vector = v3f((pos2.X - pos1.X)/distance,
  26. + (pos2.Y - pos1.Y)/distance,
  27. + (pos2.Z - pos1.Z)/distance);
  28. +
  29. + //find out if there's a node on path between pos1 and pos2
  30. +
  31. + for (int i = 1; i < distance; i++) {
  32. +
  33. + v3s16 pos = floatToInt(v3f(normalized_vector.X * i,
  34. + normalized_vector.Y * i,
  35. + normalized_vector.Z * i),BS);
  36. +
  37. +
  38. +
  39. + MapNode n = env->getMap().getNodeNoEx(pos);
  40. +
  41. + if(env->getGameDef()->ndef()->get(n).param_type == CPT_LIGHT) {
  42. + // Return true
  43. + lua_pushboolean(L, false);
  44. + return 1;
  45. + }
  46. + }
  47. +
  48. + // Return true
  49. + lua_pushboolean(L, true);
  50. + return 1;
  51. +
  52. + }
  53. +
  54. // EnvRef:get_objects_inside_radius(pos, radius)
  55. static int l_get_nodes_inside_radius(lua_State *L)
  56. {
  57. @@ -2650,6 +2698,7 @@
  58. method(EnvRef, get_player_by_name),
  59. method(EnvRef, get_objects_inside_radius),
  60. method(EnvRef, get_nodes_inside_radius),
  61. + method(EnvRef, get_line_of_sight),
  62. {0,0}
  63. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement