Merge pull request #1254 from mc-server/SingleTopBlockFinisher

Renamed cFinishGenSingleBiomeSingleTopBlock to cFinishGenSingleTopBlock
This commit is contained in:
Mattes D 2014-07-29 17:47:40 +02:00
commit d715eb7f5e
3 changed files with 92 additions and 22 deletions

View File

@ -324,7 +324,25 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
} }
else if (NoCaseCompare(*itr, "DeadBushes") == 0) else if (NoCaseCompare(*itr, "DeadBushes") == 0)
{ {
m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, biDesert, 2, E_BLOCK_SAND, E_BLOCK_SAND)); // A list with all the allowed biomes.
cFinishGenSingleTopBlock::BiomeList AllowedBiomes;
AllowedBiomes.push_back(biDesert);
AllowedBiomes.push_back(biDesertHills);
AllowedBiomes.push_back(biDesertM);
AllowedBiomes.push_back(biMesa);
AllowedBiomes.push_back(biMesaBryce);
AllowedBiomes.push_back(biMesaPlateau);
AllowedBiomes.push_back(biMesaPlateauF);
AllowedBiomes.push_back(biMesaPlateauFM);
AllowedBiomes.push_back(biMesaPlateauM);
// A list with all the allowed blocks that can be below the dead bush.
cFinishGenSingleTopBlock::BlockList AllowedBlocks;
AllowedBlocks.push_back(E_BLOCK_SAND);
AllowedBlocks.push_back(E_BLOCK_HARDENED_CLAY);
AllowedBlocks.push_back(E_BLOCK_STAINED_CLAY);
m_FinishGens.push_back(new cFinishGenSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks));
} }
else if (NoCaseCompare(*itr, "DirectOverhangs") == 0) else if (NoCaseCompare(*itr, "DirectOverhangs") == 0)
{ {
@ -371,7 +389,17 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
} }
else if (NoCaseCompare(*itr, "Lilypads") == 0) else if (NoCaseCompare(*itr, "Lilypads") == 0)
{ {
m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_LILY_PAD, biSwampland, 4, E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER)); // A list with all the allowed biomes.
cFinishGenSingleTopBlock::BiomeList AllowedBiomes;
AllowedBiomes.push_back(biSwampland);
AllowedBiomes.push_back(biSwamplandM);
// A list with all the allowed blocks that can be below the lilypad.
cFinishGenSingleTopBlock::BlockList AllowedBlocks;
AllowedBlocks.push_back(E_BLOCK_WATER);
AllowedBlocks.push_back(E_BLOCK_STATIONARY_WATER);
m_FinishGens.push_back(new cFinishGenSingleTopBlock(Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks));
} }
else if (NoCaseCompare(*itr, "NetherClumpFoliage") == 0) else if (NoCaseCompare(*itr, "NetherClumpFoliage") == 0)
{ {

View File

@ -454,14 +454,14 @@ void cFinishGenIce::GenFinish(cChunkDesc & a_ChunkDesc)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cFinishGenLilypads: // cFinishGenSingleTopBlock:
int cFinishGenSingleBiomeSingleTopBlock::GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap) int cFinishGenSingleTopBlock::GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap)
{ {
int res = 0; int res = 0;
for (size_t i = 0; i < ARRAYCOUNT(a_BiomeMap); i++) for (size_t i = 0; i < ARRAYCOUNT(a_BiomeMap); i++)
{ {
if (a_BiomeMap[i] == m_Biome) if (IsAllowedBiome(a_BiomeMap[i]))
{ {
res++; res++;
} }
@ -473,7 +473,7 @@ int cFinishGenSingleBiomeSingleTopBlock::GetNumToGen(const cChunkDef::BiomeMap &
void cFinishGenSingleBiomeSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc) void cFinishGenSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
{ {
// Add Lilypads on top of water surface in Swampland // Add Lilypads on top of water surface in Swampland
@ -486,11 +486,13 @@ void cFinishGenSingleBiomeSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
int z = (m_Noise.IntNoise3DInt(ChunkX - ChunkZ, i, ChunkZ) / 11) % cChunkDef::Width; int z = (m_Noise.IntNoise3DInt(ChunkX - ChunkZ, i, ChunkZ) / 11) % cChunkDef::Width;
// Place the block at {x, z} if possible: // Place the block at {x, z} if possible:
if (a_ChunkDesc.GetBiome(x, z) != m_Biome) EMCSBiome Biome = a_ChunkDesc.GetBiome(x, z);
if (!IsAllowedBiome(Biome))
{ {
// Incorrect biome // Incorrect biome
continue; continue;
} }
int Height = a_ChunkDesc.GetHeight(x, z); int Height = a_ChunkDesc.GetHeight(x, z);
if (Height >= cChunkDef::Height) if (Height >= cChunkDef::Height)
{ {
@ -502,13 +504,16 @@ void cFinishGenSingleBiomeSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
// Not an empty block // Not an empty block
continue; continue;
} }
BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, Height, z); BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, Height, z);
if ((BlockBelow == m_AllowedBelow1) || (BlockBelow == m_AllowedBelow2)) if (!IsAllowedBlockBelow(BlockBelow))
{ {
a_ChunkDesc.SetBlockType(x, Height + 1, z, m_BlockType); continue;
a_ChunkDesc.SetHeight(x, z, Height + 1);
} }
} // for i
a_ChunkDesc.SetBlockType(x, Height + 1, z, m_BlockType);
a_ChunkDesc.SetHeight(x, z, Height + 1);
}
} }

View File

@ -143,32 +143,69 @@ Used for:
- Lilypads finisher - Lilypads finisher
- DeadBushes finisher - DeadBushes finisher
*/ */
class cFinishGenSingleBiomeSingleTopBlock : class cFinishGenSingleTopBlock :
public cFinishGen public cFinishGen
{ {
public: public:
cFinishGenSingleBiomeSingleTopBlock( typedef std::vector<BLOCKTYPE> BlockList;
int a_Seed, BLOCKTYPE a_BlockType, EMCSBiome a_Biome, int a_Amount, bool m_IsAllowedBelow[256];
BLOCKTYPE a_AllowedBelow1, BLOCKTYPE a_AllowedBelow2
typedef std::vector<EMCSBiome> BiomeList;
bool m_IsBiomeAllowed[256];
cFinishGenSingleTopBlock(
int a_Seed, BLOCKTYPE a_BlockType, BiomeList a_Biomes, int a_Amount,
BlockList a_AllowedBelow
) : ) :
m_Noise(a_Seed), m_Noise(a_Seed),
m_BlockType(a_BlockType), m_BlockType(a_BlockType),
m_Biome(a_Biome), m_Amount(a_Amount)
m_Amount(a_Amount),
m_AllowedBelow1(a_AllowedBelow1),
m_AllowedBelow2(a_AllowedBelow2)
{ {
// Initialize all the block types.
for (int idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx)
{
m_IsAllowedBelow[idx] = false;
}
// Load the allowed blocks into m_IsAllowedBelow
for (BlockList::iterator itr = a_AllowedBelow.begin(); itr != a_AllowedBelow.end(); ++itr)
{
m_IsAllowedBelow[*itr] = true;
}
// Initialize all the biome types.
for (int idx = 0; idx < ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
{
m_IsBiomeAllowed[idx] = false;
}
// Load the allowed biomes into m_IsBiomeAllowed
for (BiomeList::iterator itr = a_Biomes.begin(); itr != a_Biomes.end(); ++itr)
{
m_IsBiomeAllowed[*itr] = true;
}
} }
protected: protected:
cNoise m_Noise; cNoise m_Noise;
BLOCKTYPE m_BlockType; BLOCKTYPE m_BlockType;
EMCSBiome m_Biome;
int m_Amount; ///< Relative amount of blocks to try adding. 1 = one block per 256 biome columns. int m_Amount; ///< Relative amount of blocks to try adding. 1 = one block per 256 biome columns.
BLOCKTYPE m_AllowedBelow1; ///< First of the two blocktypes that are allowed below m_BlockType
BLOCKTYPE m_AllowedBelow2; ///< Second of the two blocktypes that are allowed below m_BlockType
int GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap); int GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap);
// Returns true if the given biome is a biome that is allowed.
inline bool IsAllowedBiome(EMCSBiome a_Biome)
{
return m_IsBiomeAllowed[a_Biome];
}
// Returns true if the given blocktype may be below m_BlockType
inline bool IsAllowedBlockBelow(BLOCKTYPE a_BlockBelow)
{
return m_IsAllowedBelow[a_BlockBelow];
}
// cFinishGen override: // cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;