From 2295c1d7cba3df6f7fc2e96b0d25df116d0b1692 Mon Sep 17 00:00:00 2001 From: "cedeel@gmail.com" Date: Fri, 8 Jun 2012 01:56:44 +0000 Subject: Configurable classic composition generator git-svn-id: http://mc-server.googlecode.com/svn/trunk@575 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Bindings.cpp | 6 +++--- source/Bindings.h | 2 +- source/CompoGen.cpp | 22 +++++++++++++++------- source/CompoGen.h | 10 +++++++++- source/cChestEntity.cpp | 18 ------------------ source/cChestEntity.h | 2 -- source/cChunkGenerator.cpp | 20 +++++++++++++++++++- source/cSignEntity.cpp | 26 -------------------------- source/cSignEntity.h | 2 -- 9 files changed, 47 insertions(+), 61 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index ab52bd5a1..5ad4ab7a9 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 06/07/12 23:02:08. +** Generated automatically by tolua++-1.0.92 on Fri Jun 8 03:43:28 2012. */ #ifndef __cplusplus @@ -13,8 +13,8 @@ /* Exported function */ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S); -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules -#include "tolua_base.h" +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +#include "tolua_base.h" #include "cTorch.h" #include "cStairs.h" #include "cStep.h" diff --git a/source/Bindings.h b/source/Bindings.h index 3de48f101..a5764b31e 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 06/07/12 23:02:09. +** Generated automatically by tolua++-1.0.92 on Fri Jun 8 03:43:28 2012. */ /* Exported function */ diff --git a/source/CompoGen.cpp b/source/CompoGen.cpp index 712db6dab..44bfa3ad5 100644 --- a/source/CompoGen.cpp +++ b/source/CompoGen.cpp @@ -119,10 +119,18 @@ void cCompoGenDebugBiomes::ComposeTerrain( /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cCompoGenClassic: -cCompoGenClassic::cCompoGenClassic(int a_SeaLevel, int a_BeachHeight, int a_BeachDepth) : +cCompoGenClassic::cCompoGenClassic(int a_SeaLevel, int a_BeachHeight, int a_BeachDepth, + BLOCKTYPE a_BlockTop, BLOCKTYPE a_BlockMiddle, BLOCKTYPE a_BlockBottom, + BLOCKTYPE a_BlockBeach, BLOCKTYPE a_BlockBeachBottom, BLOCKTYPE a_BlockSea) : m_SeaLevel(a_SeaLevel), m_BeachHeight(a_BeachHeight), - m_BeachDepth(a_BeachDepth) + m_BeachDepth(a_BeachDepth), + m_BlockTop(a_BlockTop), + m_BlockMiddle(a_BlockMiddle), + m_BlockBottom(a_BlockBottom), + m_BlockBeach(a_BlockBeach), + m_BlockBeachBottom(a_BlockBeachBottom), + m_BlockSea(a_BlockSea) { } @@ -152,9 +160,9 @@ void cCompoGenClassic::ComposeTerrain( memset(a_BlockMeta, 0, sizeof(a_BlockMeta)); // The patterns to use for different situations, must be same length! - static const BLOCKTYPE PatternGround[] = {E_BLOCK_GRASS, E_BLOCK_DIRT, E_BLOCK_DIRT, E_BLOCK_DIRT} ; - static const BLOCKTYPE PatternBeach[] = {E_BLOCK_SAND, E_BLOCK_SAND, E_BLOCK_SAND, E_BLOCK_SANDSTONE} ; - static const BLOCKTYPE PatternOcean[] = {E_BLOCK_DIRT, E_BLOCK_DIRT, E_BLOCK_DIRT, E_BLOCK_STONE} ; + static const BLOCKTYPE PatternGround[] = {m_BlockTop, m_BlockMiddle, m_BlockMiddle, m_BlockMiddle} ; + static const BLOCKTYPE PatternBeach[] = {m_BlockBeach, m_BlockBeach, m_BlockBeach, m_BlockBeachBottom} ; + static const BLOCKTYPE PatternOcean[] = {m_BlockMiddle, m_BlockMiddle, m_BlockMiddle, m_BlockBottom} ; static int PatternLength = ARRAYCOUNT(PatternGround); ASSERT(ARRAYCOUNT(PatternGround) == ARRAYCOUNT(PatternBeach)); ASSERT(ARRAYCOUNT(PatternGround) == ARRAYCOUNT(PatternOcean)); @@ -181,13 +189,13 @@ void cCompoGenClassic::ComposeTerrain( // Fill water from sealevel down to height (if any): for (int y = m_SeaLevel; y >= Height; --y) { - cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_STATIONARY_WATER); + cChunkDef::SetBlock(a_BlockTypes, x, y, z, m_BlockSea); } // Fill from height till the bottom: for (int y = Height; y >= 1; y--) { - cChunkDef::SetBlock(a_BlockTypes, x, y, z, (Height - y < PatternLength) ? Pattern[Height - y] : E_BLOCK_STONE); + cChunkDef::SetBlock(a_BlockTypes, x, y, z, (Height - y < PatternLength) ? Pattern[Height - y] : m_BlockBottom); } // The last layer is always bedrock: diff --git a/source/CompoGen.h b/source/CompoGen.h index 74e38757b..2a669f43b 100644 --- a/source/CompoGen.h +++ b/source/CompoGen.h @@ -79,13 +79,21 @@ class cCompoGenClassic : public cTerrainCompositionGen { public: - cCompoGenClassic(int a_SeaLevel, int a_BeachHeight, int a_BeachDepth); + cCompoGenClassic(int a_SeaLevel, int a_BeachHeight, int a_BeachDepth, + BLOCKTYPE a_BlockTop, BLOCKTYPE a_BlockMiddle, BLOCKTYPE a_BlockBottom, + BLOCKTYPE a_BlockBeach, BLOCKTYPE a_BlockBeachBottom, BLOCKTYPE a_BlockSea); protected: int m_SeaLevel; int m_BeachHeight; int m_BeachDepth; + BLOCKTYPE m_BlockTop; + BLOCKTYPE m_BlockMiddle; + BLOCKTYPE m_BlockBottom; + BLOCKTYPE m_BlockBeach; + BLOCKTYPE m_BlockBeachBottom; + BLOCKTYPE m_BlockSea; // cTerrainCompositionGen overrides: virtual void ComposeTerrain( diff --git a/source/cChestEntity.cpp b/source/cChestEntity.cpp index c7f4e6b0d..35fb2894e 100644 --- a/source/cChestEntity.cpp +++ b/source/cChestEntity.cpp @@ -106,24 +106,6 @@ void cChestEntity::SetSlot( int a_Slot, cItem & a_Item ) return false; \ } -bool cChestEntity::LoadFromFile(cFile & f) -{ - READ(f, m_PosX); - READ(f, m_PosY); - READ(f, m_PosZ); - - unsigned int NumSlots = 0; - READ(f, NumSlots); - for(unsigned int i = 0; i < NumSlots; i++) - { - cItem Item; - READ(f, Item.m_ItemID); - READ(f, Item.m_ItemCount); - READ(f, Item.m_ItemHealth); - SetSlot( i, Item ); - } - return true; -} diff --git a/source/cChestEntity.h b/source/cChestEntity.h index 2ae87d59f..6e625f8f5 100644 --- a/source/cChestEntity.h +++ b/source/cChestEntity.h @@ -37,8 +37,6 @@ public: const cItem * GetSlot( int a_Slot ) const; void SetSlot( int a_Slot, cItem & a_Item ); - OBSOLETE bool LoadFromFile(cFile & a_File); // deprecated format - bool LoadFromJson( const Json::Value& a_Value ); virtual void SaveToJson(Json::Value& a_Value ) override; diff --git a/source/cChunkGenerator.cpp b/source/cChunkGenerator.cpp index 14008add7..d595f333f 100644 --- a/source/cChunkGenerator.cpp +++ b/source/cChunkGenerator.cpp @@ -224,6 +224,17 @@ void cChunkGenerator::InitHeightGen(cIniFile & a_IniFile) +BLOCKTYPE ResolveBlock(AString BlockType, BLOCKTYPE DefaultBlock) +{ + int Block = BlockStringToType(BlockType); + if(Block < 0) + { + LOGWARN("[Generator] Could not parse block value \"%s\". Using default.", BlockType.c_str()); + return DefaultBlock; + } + return (BLOCKTYPE) Block; +} + void cChunkGenerator::InitCompositionGen(cIniFile & a_IniFile) @@ -260,7 +271,14 @@ void cChunkGenerator::InitCompositionGen(cIniFile & a_IniFile) int SeaLevel = a_IniFile.GetValueI("Generator", "ClassicSeaLevel", 60); int BeachHeight = a_IniFile.GetValueI("Generator", "ClassicBeachHeight", 2); int BeachDepth = a_IniFile.GetValueI("Generator", "ClassicBeachDepth", 4); - m_CompositionGen = new cCompoGenClassic(SeaLevel, BeachHeight, BeachDepth); + BLOCKTYPE BlockTop = ResolveBlock(a_IniFile.GetValue("Generator", "ClassicBlockTop", "grass"), E_BLOCK_GRASS); + BLOCKTYPE BlockMiddle = ResolveBlock(a_IniFile.GetValue("Generator", "ClassicBlockMiddle", "dirt"), E_BLOCK_DIRT); + BLOCKTYPE BlockBottom = ResolveBlock(a_IniFile.GetValue("Generator", "ClassicBlockBottom", "stone"), E_BLOCK_STONE); + BLOCKTYPE BlockBeach = ResolveBlock(a_IniFile.GetValue("Generator", "ClassicBlockBeach", "sand"), E_BLOCK_SAND); + BLOCKTYPE BlockBeachBottom = ResolveBlock(a_IniFile.GetValue("Generator", "ClassicBlockBeachBottom", "sandstone"), E_BLOCK_SANDSTONE); + BLOCKTYPE BlockSea = ResolveBlock(a_IniFile.GetValue("Generator", "ClassicBlockSea", "9"), E_BLOCK_STATIONARY_WATER); + m_CompositionGen = new cCompoGenClassic(SeaLevel, BeachHeight, BeachDepth, BlockTop, BlockMiddle, BlockBottom, BlockBeach, + BlockBeachBottom, BlockSea); } else { diff --git a/source/cSignEntity.cpp b/source/cSignEntity.cpp index ca21d847b..cf0a13650 100644 --- a/source/cSignEntity.cpp +++ b/source/cSignEntity.cpp @@ -104,32 +104,6 @@ cPacket * cSignEntity::GetPacket(void) return false; \ } -bool cSignEntity::LoadFromFile(cFile & f) -{ - READ(f, m_PosX); - READ(f, m_PosY); - READ(f, m_PosZ); - - for( int i = 0; i < 4; i++ ) - { - short Size = 0; - READ(f, Size); - if (Size > 0) - { - char * c_Str = new char[Size]; - if (f.Read(c_Str, Size) != Size ) - { - LOGERROR("ERROR READING SIGN FROM FILE"); - delete [] c_Str; - return false; - } - m_Line[i].assign( c_Str, Size ); - delete [] c_Str; - } - } - - return true; -} diff --git a/source/cSignEntity.h b/source/cSignEntity.h index 5d9d11a9c..3b633c8af 100644 --- a/source/cSignEntity.h +++ b/source/cSignEntity.h @@ -23,8 +23,6 @@ public: cSignEntity(ENUM_BLOCK_ID a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World); virtual ~cSignEntity(); - OBSOLETE bool LoadFromFile(cFile & a_File); // deprecated format - bool LoadFromJson( const Json::Value& a_Value ); virtual void SaveToJson(Json::Value& a_Value ) override; -- cgit v1.2.3