]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/lua_api/l_vmanip.cpp
Revert "Make Lint Happy"
[dragonfireclient.git] / src / script / lua_api / l_vmanip.cpp
index 1e973703c52630aae082ac9bfa7beee48ac45281..b99b1d98cfd32e0b129a59118e56eaa07fc72d0c 100644 (file)
@@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include "mapblock.h"
 #include "server.h"
-#include "mapgen.h"
+#include "mapgen/mapgen.h"
 #include "voxelalgorithms.h"
 
 // garbage collector
@@ -72,7 +72,7 @@ int LuaVoxelManip::l_get_data(lua_State *L)
        if (use_buffer)
                lua_pushvalue(L, 2);
        else
-               lua_newtable(L);
+               lua_createtable(L, volume, 0);
 
        for (u32 i = 0; i != volume; i++) {
                lua_Integer cid = vm->m_data[i].getContent();
@@ -91,7 +91,7 @@ int LuaVoxelManip::l_set_data(lua_State *L)
        MMVManip *vm = o->vm;
 
        if (!lua_istable(L, 2))
-               return 0;
+               throw LuaError("VoxelManip:set_data called with missing parameter");
 
        u32 volume = vm->m_area.getVolume();
        for (u32 i = 0; i != volume; i++) {
@@ -111,7 +111,7 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
        MAP_LOCK_REQUIRED;
 
        LuaVoxelManip *o = checkobject(L, 1);
-       bool update_light = lua_isboolean(L, 2) ? lua_toboolean(L, 2) : true;
+       bool update_light = !lua_isboolean(L, 2) || readParam<bool>(L, 2);
        GET_ENV_PTR;
        ServerMap *map = &(env->getServerMap());
        if (o->is_mapgen_vm || !update_light) {
@@ -123,11 +123,10 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
 
        MapEditEvent event;
        event.type = MEET_OTHER;
-       for (std::map<v3s16, MapBlock *>::iterator it = o->modified_blocks.begin();
-                       it != o->modified_blocks.end(); ++it)
-               event.modified_blocks.insert(it->first);
+       for (const auto &modified_block : o->modified_blocks)
+               event.modified_blocks.insert(modified_block.first);
 
-       map->dispatchEvent(&event);
+       map->dispatchEvent(event);
 
        o->modified_blocks.clear();
        return 0;
@@ -137,7 +136,7 @@ int LuaVoxelManip::l_get_node_at(lua_State *L)
 {
        NO_MAP_LOCK_REQUIRED;
 
-       INodeDefManager *ndef = getServer(L)->getNodeDefManager();
+       const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
 
        LuaVoxelManip *o = checkobject(L, 1);
        v3s16 pos        = check_v3s16(L, 2);
@@ -150,7 +149,7 @@ int LuaVoxelManip::l_set_node_at(lua_State *L)
 {
        NO_MAP_LOCK_REQUIRED;
 
-       INodeDefManager *ndef = getServer(L)->getNodeDefManager();
+       const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
 
        LuaVoxelManip *o = checkobject(L, 1);
        v3s16 pos        = check_v3s16(L, 2);
@@ -168,7 +167,7 @@ int LuaVoxelManip::l_update_liquids(lua_State *L)
        LuaVoxelManip *o = checkobject(L, 1);
 
        Map *map = &(env->getMap());
-       INodeDefManager *ndef = getServer(L)->getNodeDefManager();
+       const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
        MMVManip *vm = o->vm;
 
        Mapgen mg;
@@ -186,10 +185,13 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
        NO_MAP_LOCK_REQUIRED;
 
        LuaVoxelManip *o = checkobject(L, 1);
-       if (!o->is_mapgen_vm)
+       if (!o->is_mapgen_vm) {
+               warningstream << "VoxelManip:calc_lighting called for a non-mapgen "
+                       "VoxelManip object" << std::endl;
                return 0;
+       }
 
-       INodeDefManager *ndef = getServer(L)->getNodeDefManager();
+       const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
        EmergeManager *emerge = getServer(L)->getEmergeManager();
        MMVManip *vm = o->vm;
 
@@ -198,7 +200,7 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
        v3s16 fpmax  = vm->m_area.MaxEdge;
        v3s16 pmin   = lua_istable(L, 2) ? check_v3s16(L, 2) : fpmin + yblock;
        v3s16 pmax   = lua_istable(L, 3) ? check_v3s16(L, 3) : fpmax - yblock;
-       bool propagate_shadow = lua_isboolean(L, 4) ? lua_toboolean(L, 4) : true;
+       bool propagate_shadow = !lua_isboolean(L, 4) || readParam<bool>(L, 4);
 
        sortBoxVerticies(pmin, pmax);
        if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
@@ -219,11 +221,14 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
        NO_MAP_LOCK_REQUIRED;
 
        LuaVoxelManip *o = checkobject(L, 1);
-       if (!o->is_mapgen_vm)
+       if (!o->is_mapgen_vm) {
+               warningstream << "VoxelManip:set_lighting called for a non-mapgen "
+                       "VoxelManip object" << std::endl;
                return 0;
+       }
 
        if (!lua_istable(L, 2))
-               return 0;
+               throw LuaError("VoxelManip:set_lighting called with missing parameter");
 
        u8 light;
        light  = (getintfield_default(L, 2, "day",   0) & 0x0F);
@@ -256,7 +261,7 @@ int LuaVoxelManip::l_get_light_data(lua_State *L)
 
        u32 volume = vm->m_area.getVolume();
 
-       lua_newtable(L);
+       lua_createtable(L, volume, 0);
        for (u32 i = 0; i != volume; i++) {
                lua_Integer light = vm->m_data[i].param1;
                lua_pushinteger(L, light);
@@ -274,7 +279,8 @@ int LuaVoxelManip::l_set_light_data(lua_State *L)
        MMVManip *vm = o->vm;
 
        if (!lua_istable(L, 2))
-               return 0;
+               throw LuaError("VoxelManip:set_light_data called with missing "
+                               "parameter");
 
        u32 volume = vm->m_area.getVolume();
        for (u32 i = 0; i != volume; i++) {
@@ -303,7 +309,7 @@ int LuaVoxelManip::l_get_param2_data(lua_State *L)
        if (use_buffer)
                lua_pushvalue(L, 2);
        else
-               lua_newtable(L);
+               lua_createtable(L, volume, 0);
 
        for (u32 i = 0; i != volume; i++) {
                lua_Integer param2 = vm->m_data[i].param2;
@@ -322,7 +328,8 @@ int LuaVoxelManip::l_set_param2_data(lua_State *L)
        MMVManip *vm = o->vm;
 
        if (!lua_istable(L, 2))
-               return 0;
+               throw LuaError("VoxelManip:set_param2_data called with missing "
+                               "parameter");
 
        u32 volume = vm->m_area.getVolume();
        for (u32 i = 0; i != volume; i++) {