summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-03-12 20:39:41 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-03-12 20:39:41 +0100
commit10c8c75bb7fdfeb66874ae921e467336e619ef82 (patch)
tree74ffa4418a91571bb91dee44cee3d450dbc9b70d /source
parentFixed MapChunk packets to include (fake) biome data, makes clients happy (diff)
downloadcuberite-10c8c75bb7fdfeb66874ae921e467336e619ef82.tar
cuberite-10c8c75bb7fdfeb66874ae921e467336e619ef82.tar.gz
cuberite-10c8c75bb7fdfeb66874ae921e467336e619ef82.tar.bz2
cuberite-10c8c75bb7fdfeb66874ae921e467336e619ef82.tar.lz
cuberite-10c8c75bb7fdfeb66874ae921e467336e619ef82.tar.xz
cuberite-10c8c75bb7fdfeb66874ae921e467336e619ef82.tar.zst
cuberite-10c8c75bb7fdfeb66874ae921e467336e619ef82.zip
Diffstat (limited to 'source')
-rw-r--r--source/WGFlat.cpp101
-rw-r--r--source/WGFlat.h35
-rw-r--r--source/cChunkGenerator.cpp14
-rw-r--r--source/cWorld.cpp6
-rw-r--r--source/cWorld.h2
5 files changed, 148 insertions, 10 deletions
diff --git a/source/WGFlat.cpp b/source/WGFlat.cpp
new file mode 100644
index 000000000..725572334
--- /dev/null
+++ b/source/WGFlat.cpp
@@ -0,0 +1,101 @@
+
+// WGFlat.cpp
+
+// Implements the cWGFlat class representing the flat world generator
+
+#include "Globals.h"
+#include "WGFlat.h"
+#include "../iniFile/iniFile.h"
+#include "cWorld.h"
+
+
+
+
+
+cWGFlat::cWGFlat(cWorld * a_World) :
+ super(a_World)
+{
+ // Load the settings from the INI file:
+ cIniFile INI(a_World->GetIniFileName());
+ INI.ReadFile();
+ m_Height = INI.GetValueI("flat", "height", 5);
+ if (m_Height < 1)
+ {
+ m_Height = 1;
+ }
+ if (m_Height > 250)
+ {
+ m_Height = 250;
+ }
+}
+
+
+
+
+
+void cWGFlat::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities)
+{
+ int SliceSize = cChunk::c_ChunkWidth * cChunk::c_ChunkWidth;
+ memset(a_BlockData, E_BLOCK_BEDROCK, SliceSize);
+ switch (m_Height)
+ {
+ case 1:
+ {
+ // Just the bedrock layer
+ break;
+ }
+ case 2:
+ {
+ // Bedrock + 1 dirt layer:
+ memset(a_BlockData + SliceSize, E_BLOCK_GRASS, SliceSize);
+ break;
+ }
+ case 3:
+ {
+ // Bedrock + 2 dirt layers:
+ memset(a_BlockData + SliceSize, E_BLOCK_DIRT, SliceSize);
+ memset(a_BlockData + 2 * SliceSize, E_BLOCK_GRASS, SliceSize);
+ break;
+ }
+ case 4:
+ {
+ // Bedrock + 3 dirt layers:
+ memset(a_BlockData + SliceSize, E_BLOCK_DIRT, 2 * SliceSize);
+ memset(a_BlockData + 3 * SliceSize, E_BLOCK_GRASS, SliceSize);
+ break;
+ }
+ default:
+ {
+ // Bedrock + stone layers + 3 dirt layers:
+ memset(a_BlockData + SliceSize, E_BLOCK_STONE, SliceSize * (m_Height - 4));
+ memset(a_BlockData + SliceSize * (m_Height - 3), E_BLOCK_DIRT, SliceSize * 2);
+ memset(a_BlockData + SliceSize * (m_Height - 1), E_BLOCK_GRASS, SliceSize);
+ break;
+ }
+ }
+ memset(a_BlockData + SliceSize * m_Height, E_BLOCK_AIR, cChunk::c_NumBlocks - SliceSize * m_Height);
+
+ SliceSize /= 2; // Nibbles from now on
+ char * Meta = a_BlockData + cChunk::c_NumBlocks;
+ memset(Meta, 0, cChunk::c_NumBlocks / 2);
+
+ char * SkyLight = Meta + cChunk::c_NumBlocks / 2;
+ memset(SkyLight, 0, m_Height * SliceSize);
+ memset(SkyLight + m_Height * SliceSize, 0xff, cChunk::c_NumBlocks / 2 - m_Height * SliceSize);
+
+ char * BlockLight = SkyLight + cChunk::c_NumBlocks / 2;
+ memset(BlockLight, 0, cChunk::c_NumBlocks / 2);
+}
+
+
+
+
+
+void cWGFlat::PostGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+{
+ // Nothing needed yet, just don't call the parent
+}
+
+
+
+
diff --git a/source/WGFlat.h b/source/WGFlat.h
new file mode 100644
index 000000000..79a2053c5
--- /dev/null
+++ b/source/WGFlat.h
@@ -0,0 +1,35 @@
+
+// WGFlat.h
+
+// Interfaces to the cWGFlat class representing the flat world generator
+
+
+
+
+
+#pragma once
+
+#include "cWorldGenerator.h"
+
+
+
+
+
+class cWGFlat :
+ public cWorldGenerator
+{
+ typedef cWorldGenerator super;
+
+protected:
+ int m_Height;
+
+ virtual void GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities) override;
+ virtual void PostGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) override;
+
+public:
+ cWGFlat(cWorld * a_World);
+} ;
+
+
+
+
diff --git a/source/cChunkGenerator.cpp b/source/cChunkGenerator.cpp
index e6296baa6..7dde581c2 100644
--- a/source/cChunkGenerator.cpp
+++ b/source/cChunkGenerator.cpp
@@ -5,13 +5,7 @@
#include "cWorld.h"
#include "cWorldGenerator.h"
#include "cWorldGenerator_Test.h"
-
-
-
-
-
-typedef std::pair<int, int> ChunkCoord;
-typedef std::list< ChunkCoord > ChunkCoordList;
+#include "WGFlat.h"
@@ -51,10 +45,14 @@ bool cChunkGenerator::Start(cWorld * a_World, const AString & a_WorldGeneratorNa
{
m_World = a_World;
- if (a_WorldGeneratorName.compare("Test") == 0 )
+ if (NoCaseCompare(a_WorldGeneratorName, "Test") == 0 )
{
m_pWorldGenerator = new cWorldGenerator_Test(a_World);
}
+ else if (NoCaseCompare(a_WorldGeneratorName, "flat") == 0)
+ {
+ m_pWorldGenerator = new cWGFlat(a_World);
+ }
else // Default
{
m_pWorldGenerator = new cWorldGenerator(a_World);
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index 62c952ba1..91fbe7f64 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -184,6 +184,7 @@ cWorld::cWorld( const AString & a_WorldName )
{
LOG("cWorld::cWorld(%s)", a_WorldName.c_str());
m_WorldName = a_WorldName;
+ m_IniFileName = m_WorldName + "/world.ini";
cMakeDir::MakeDir(m_WorldName.c_str());
@@ -197,7 +198,7 @@ cWorld::cWorld( const AString & a_WorldName )
AString GeneratorName;
AString StorageSchema("Default");
- cIniFile IniFile( m_WorldName + "/world.ini");
+ cIniFile IniFile(m_IniFileName);
if( IniFile.ReadFile() )
{
m_SpawnX = IniFile.GetValueF("SpawnPosition", "X", m_SpawnX );
@@ -219,7 +220,7 @@ cWorld::cWorld( const AString & a_WorldName )
IniFile.SetValue("Storage", "Schema", StorageSchema);
if( !IniFile.WriteFile() )
{
- LOG("WARNING: Could not write to %s/world.ini", a_WorldName.c_str());
+ LOG("WARNING: Could not write to %s", m_IniFileName.c_str());
}
}
LOGINFO("Seed: %i", m_WorldSeed );
@@ -302,6 +303,7 @@ cWorld::cWorld( const AString & a_WorldName )
g_BlockTransparent[ E_BLOCK_RED_ROSE ] = true;
g_BlockTransparent[ E_BLOCK_RED_MUSHROOM ] = true;
g_BlockTransparent[ E_BLOCK_BROWN_MUSHROOM ] = true;
+ g_BlockTransparent[ E_BLOCK_SNOW ] = true;
// TODO: Any other transparent blocks?
diff --git a/source/cWorld.h b/source/cWorld.h
index fa00a78bc..bdf2ae2c5 100644
--- a/source/cWorld.h
+++ b/source/cWorld.h
@@ -187,6 +187,7 @@ public:
unsigned int GetWorldSeed(void) const { return m_WorldSeed; } //tolua_export
const AString & GetName(void) const { return m_WorldName; } //tolua_export
+ const AString & GetIniFileName(void) const {return m_IniFileName; }
inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
{
@@ -299,6 +300,7 @@ private:
cChunkSender m_ChunkSender;
AString m_WorldName;
+ AString m_IniFileName;
cWorld(const AString & a_WorldName);
~cWorld();