From 41e0927843a8060fc381e7695faf4cf8d3c875e6 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 31 Mar 2013 19:05:41 +0000 Subject: cChunkDesc: Added the RandomFillRelCuboid() function git-svn-id: http://mc-server.googlecode.com/svn/trunk@1341 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Bindings.cpp | 91 ++++++++++++++++++++++++++++++++++++++++- source/Bindings.h | 2 +- source/Generating/ChunkDesc.cpp | 37 +++++++++++++++++ source/Generating/ChunkDesc.h | 26 +++++++++++- 4 files changed, 153 insertions(+), 3 deletions(-) diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 7512bba25..79b857a82 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 03/31/13 20:21:16. +** Generated automatically by tolua++-1.0.92 on 03/31/13 20:59:24. */ #ifndef __cplusplus @@ -21944,6 +21944,93 @@ tolua_lerror: } #endif //#ifndef TOLUA_DISABLE +/* method: RandomFillRelCuboid of class cChunkDesc */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChunkDesc_RandomFillRelCuboid00 +static int tolua_AllToLua_cChunkDesc_RandomFillRelCuboid00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cChunkDesc",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnumber(tolua_S,5,0,&tolua_err) || + !tolua_isnumber(tolua_S,6,0,&tolua_err) || + !tolua_isnumber(tolua_S,7,0,&tolua_err) || + !tolua_isnumber(tolua_S,8,0,&tolua_err) || + !tolua_isnumber(tolua_S,9,0,&tolua_err) || + !tolua_isnumber(tolua_S,10,0,&tolua_err) || + !tolua_isnumber(tolua_S,11,0,&tolua_err) || + !tolua_isnoobj(tolua_S,12,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cChunkDesc* self = (cChunkDesc*) tolua_tousertype(tolua_S,1,0); + int a_MinX = ((int) tolua_tonumber(tolua_S,2,0)); + int a_MaxX = ((int) tolua_tonumber(tolua_S,3,0)); + int a_MinY = ((int) tolua_tonumber(tolua_S,4,0)); + int a_MaxY = ((int) tolua_tonumber(tolua_S,5,0)); + int a_MinZ = ((int) tolua_tonumber(tolua_S,6,0)); + int a_MaxZ = ((int) tolua_tonumber(tolua_S,7,0)); + unsigned char a_BlockType = (( unsigned char) tolua_tonumber(tolua_S,8,0)); + unsigned char a_BlockMeta = (( unsigned char) tolua_tonumber(tolua_S,9,0)); + int a_RandomSeed = ((int) tolua_tonumber(tolua_S,10,0)); + int a_ChanceOutOf10k = ((int) tolua_tonumber(tolua_S,11,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'RandomFillRelCuboid'", NULL); +#endif + { + self->RandomFillRelCuboid(a_MinX,a_MaxX,a_MinY,a_MaxY,a_MinZ,a_MaxZ,a_BlockType,a_BlockMeta,a_RandomSeed,a_ChanceOutOf10k); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'RandomFillRelCuboid'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: RandomFillRelCuboid of class cChunkDesc */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChunkDesc_RandomFillRelCuboid01 +static int tolua_AllToLua_cChunkDesc_RandomFillRelCuboid01(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cChunkDesc",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cCuboid",0,&tolua_err)) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnumber(tolua_S,5,0,&tolua_err) || + !tolua_isnumber(tolua_S,6,0,&tolua_err) || + !tolua_isnoobj(tolua_S,7,&tolua_err) + ) + goto tolua_lerror; + else + { + cChunkDesc* self = (cChunkDesc*) tolua_tousertype(tolua_S,1,0); + const cCuboid* a_RelCuboid = ((const cCuboid*) tolua_tousertype(tolua_S,2,0)); + unsigned char a_BlockType = (( unsigned char) tolua_tonumber(tolua_S,3,0)); + unsigned char a_BlockMeta = (( unsigned char) tolua_tonumber(tolua_S,4,0)); + int a_RandomSeed = ((int) tolua_tonumber(tolua_S,5,0)); + int a_ChanceOutOf10k = ((int) tolua_tonumber(tolua_S,6,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'RandomFillRelCuboid'", NULL); +#endif + { + self->RandomFillRelCuboid(*a_RelCuboid,a_BlockType,a_BlockMeta,a_RandomSeed,a_ChanceOutOf10k); + } + } + return 0; +tolua_lerror: + return tolua_AllToLua_cChunkDesc_RandomFillRelCuboid00(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + /* method: new of class cCraftingGrid */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_new00 static int tolua_AllToLua_cCraftingGrid_new00(lua_State* tolua_S) @@ -24097,6 +24184,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"ReplaceRelCuboid",tolua_AllToLua_cChunkDesc_ReplaceRelCuboid01); tolua_function(tolua_S,"FloorRelCuboid",tolua_AllToLua_cChunkDesc_FloorRelCuboid00); tolua_function(tolua_S,"FloorRelCuboid",tolua_AllToLua_cChunkDesc_FloorRelCuboid01); + tolua_function(tolua_S,"RandomFillRelCuboid",tolua_AllToLua_cChunkDesc_RandomFillRelCuboid00); + tolua_function(tolua_S,"RandomFillRelCuboid",tolua_AllToLua_cChunkDesc_RandomFillRelCuboid01); tolua_endmodule(tolua_S); #ifdef __cplusplus tolua_cclass(tolua_S,"cCraftingGrid","cCraftingGrid","",tolua_collect_cCraftingGrid); diff --git a/source/Bindings.h b/source/Bindings.h index 60b6ade5e..e8e84f093 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 03/31/13 20:21:17. +** Generated automatically by tolua++-1.0.92 on 03/31/13 20:59:25. */ /* Exported function */ diff --git a/source/Generating/ChunkDesc.cpp b/source/Generating/ChunkDesc.cpp index 81e6851a4..f0927f294 100644 --- a/source/Generating/ChunkDesc.cpp +++ b/source/Generating/ChunkDesc.cpp @@ -7,6 +7,7 @@ #include "ChunkDesc.h" #include "../BlockArea.h" #include "../Cuboid.h" +#include "../Noise.h" @@ -489,6 +490,42 @@ void cChunkDesc::FloorRelCuboid( +void cChunkDesc::RandomFillRelCuboid( + int a_MinX, int a_MaxX, + int a_MinY, int a_MaxY, + int a_MinZ, int a_MaxZ, + BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, + int a_RandomSeed, int a_ChanceOutOf10k +) +{ + cNoise Noise(a_RandomSeed); + int MinX = std::max(a_MinX, 0); + int MinY = std::max(a_MinY, 0); + int MinZ = std::max(a_MinZ, 0); + int MaxX = std::min(a_MaxX, cChunkDef::Width - 1); + int MaxY = std::min(a_MaxY, cChunkDef::Height - 1); + int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1); + + for (int y = MinY; y <= MaxY; y++) + { + for (int z = MinZ; z <= MaxZ; z++) + { + for (int x = MinX; x <= MaxX; x++) + { + int rnd = (Noise.IntNoise3DInt(x, y, z) / 7) % 10000; + if (rnd <= a_ChanceOutOf10k) + { + SetBlockTypeMeta(x, y, z, a_BlockType, a_BlockMeta); + } + } + } // for z + } // for y +} + + + + + void cChunkDesc::CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas) { const NIBBLETYPE * AreaMetas = m_BlockArea.GetBlockMetas(); diff --git a/source/Generating/ChunkDesc.h b/source/Generating/ChunkDesc.h index a18b26142..5ec3759a9 100644 --- a/source/Generating/ChunkDesc.h +++ b/source/Generating/ChunkDesc.h @@ -142,7 +142,31 @@ public: a_DstType, a_DstMeta ); } - + + /// Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk + void RandomFillRelCuboid( + int a_MinX, int a_MaxX, + int a_MinY, int a_MaxY, + int a_MinZ, int a_MaxZ, + BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, + int a_RandomSeed, int a_ChanceOutOf10k + ); + + /// Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk + void RandomFillRelCuboid( + const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, + int a_RandomSeed, int a_ChanceOutOf10k + ) + { + RandomFillRelCuboid( + a_RelCuboid.p1.x, a_RelCuboid.p2.x, + a_RelCuboid.p1.y, a_RelCuboid.p2.y, + a_RelCuboid.p1.z, a_RelCuboid.p2.z, + a_BlockType, a_BlockMeta, + a_RandomSeed, a_ChanceOutOf10k + ); + } + // tolua_end -- cgit v1.2.3