Guest User

Untitled

a guest
Jan 7th, 2012
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. --- git/minetest/src/environment.h 2012-01-07 15:00:59.000000000 +0100
  2. +++ minetest/src/environment.h 2012-01-07 14:41:16.000000000 +0100
  3. @@ -270,6 +270,9 @@
  4. -------------------------------------------
  5. */
  6.  
  7. + // Find all nodes inside a radius around a point
  8. + core::list<MapNode> getNodesInsideRadius(v3s16 pos, float radius);
  9. +
  10. // Find all active objects inside a radius around a point
  11. std::set<u16> getObjectsInsideRadius(v3f pos, float radius);
  12.  
  13. --- git/minetest/src/environment.cpp 2012-01-07 15:00:59.000000000 +0100
  14. +++ minetest/src/environment.cpp 2012-01-07 14:42:47.000000000 +0100
  15. @@ -765,6 +766,32 @@
  16. abmhandler.apply(block);
  17. }
  18.  
  19. +core::list<MapNode> ServerEnvironment::getNodesInsideRadius(v3s16 pos, float radius)
  20. +{
  21. + core::list<MapNode> nodes;
  22. +
  23. +
  24. + for (int i = pos.X - radius; i < pos.X + radius; i ++) {
  25. +
  26. + for (int j = pos.Y - radius; j <pos.Y + radius; j ++) {
  27. +
  28. + for (int k = pos.Z - radius; k < pos.Z + radius; k ++) {
  29. + v3s16 current_pos = v3s16(i,j,k);
  30. +
  31. + if (current_pos.getDistanceFrom(pos) < radius) {
  32. +
  33. + MapNode n = m_map->getNodeNoEx(current_pos);
  34. +
  35. + nodes.push_back(n);
  36. + }
  37. +
  38. + }
  39. + }
  40. +
  41. + }
  42. + return nodes;
  43. +}
  44. +
  45. void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm)
  46. {
  47. m_abms.push_back(ABMWithState(abm));
  48. --- git/minetest/src/scriptapi.cpp 2012-01-07 15:01:00.000000000 +0100
  49. +++ minetest/src/scriptapi.cpp 2012-01-07 14:41:23.000000000 +0100
  50. @@ -2543,6 +2543,35 @@
  51. return 1;
  52. }
  53.  
  54. + // EnvRef:get_objects_inside_radius(pos, radius)
  55. + static int l_get_nodes_inside_radius(lua_State *L)
  56. + {
  57. + // Get the table insert function
  58. + lua_getglobal(L, "table");
  59. + lua_getfield(L, -1, "insert");
  60. + int table_insert = lua_gettop(L);
  61. + // Get environemnt
  62. + EnvRef *o = checkobject(L, 1);
  63. + ServerEnvironment *env = o->m_env;
  64. + if(env == NULL) return 0;
  65. + // Do it
  66. + v3s16 pos = read_v3s16(L, 2);
  67. + float radius = luaL_checknumber(L, 3);// * BS;
  68. + core::list<MapNode> nodes = env->getNodesInsideRadius(pos, radius);
  69. + lua_newtable(L);
  70. + int table = lua_gettop(L);
  71. + for(core::list<MapNode>::Iterator
  72. + i = nodes.begin(); i != nodes.end(); i++){
  73. + // Insert object reference into table
  74. + lua_pushvalue(L, table_insert);
  75. + lua_pushvalue(L, table);
  76. + pushnode(L, *i, env->getGameDef()->ndef());
  77. + if(lua_pcall(L, 2, 0, 0))
  78. + script_error(L, "error: %s", lua_tostring(L, -1));
  79. + }
  80. + return 1;
  81. + }
  82. +
  83. static int gc_object(lua_State *L) {
  84. EnvRef *o = *(EnvRef **)(lua_touserdata(L, 1));
  85. delete o;
  86. @@ -2620,6 +2649,7 @@
  87. method(EnvRef, get_meta),
  88. method(EnvRef, get_player_by_name),
  89. method(EnvRef, get_objects_inside_radius),
  90. + method(EnvRef, get_nodes_inside_radius),
  91. {0,0}
  92. };
Advertisement
Add Comment
Please, Sign In to add comment