1
0

BlockCrops: Fixed comments and reformatted control flow. (#3576)

This commit is contained in:
Mattes D 2017-02-25 10:54:44 +01:00 committed by Julian Laubstein
parent 330d66097f
commit 7c17f77c84

View File

@ -14,28 +14,47 @@ class cBlockCropsHandler :
public cBlockPlant public cBlockPlant
{ {
typedef cBlockPlant Super; typedef cBlockPlant Super;
public: public:
cBlockCropsHandler(BLOCKTYPE a_BlockType)
: Super(a_BlockType, true) cBlockCropsHandler(BLOCKTYPE a_BlockType):
Super(a_BlockType, true)
{ {
} }
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override
{ {
cFastRandom rand; cFastRandom rand;
// Beetroots have three stages before fully grown // If not fully grown, drop the "seed" of whatever is growing:
if (a_Meta >= RipeMeta) if (a_Meta < RipeMeta)
{ {
// Is fully grown, drop the entire produce: switch (m_BlockType)
{
case E_BLOCK_BEETROOTS: a_Pickups.push_back(cItem(E_ITEM_BEETROOT_SEEDS, 1, 0)); break;
case E_BLOCK_CROPS: a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0)); break;
case E_BLOCK_CARROTS: a_Pickups.push_back(cItem(E_ITEM_CARROT, 1, 0)); break;
case E_BLOCK_POTATOES: a_Pickups.push_back(cItem(E_ITEM_POTATO, 1, 0)); break;
default:
{
ASSERT(!"Unhandled block type");
break;
}
}
return;
}
// Fully grown, drop the crop's produce:
switch (m_BlockType) switch (m_BlockType)
{ {
case E_BLOCK_BEETROOTS: case E_BLOCK_BEETROOTS:
{ {
char SeedCount = static_cast<char>(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2); char SeedCount = static_cast<char>(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2); // [1 .. 3] with high preference of 2
a_Pickups.push_back(cItem(E_ITEM_BEETROOT_SEEDS, SeedCount, 0)); a_Pickups.push_back(cItem(E_ITEM_BEETROOT_SEEDS, SeedCount, 0));
char BeetrootCount = static_cast<char>(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2); char BeetrootCount = static_cast<char>(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2); // [1 .. 3] with high preference of 2
a_Pickups.push_back(cItem(E_ITEM_BEETROOT, BeetrootCount, 0)); // [1 .. 3] with high preference of 2 a_Pickups.push_back(cItem(E_ITEM_BEETROOT, BeetrootCount, 0));
break; break;
} }
case E_BLOCK_CROPS: case E_BLOCK_CROPS:
@ -66,23 +85,8 @@ public:
} }
} // switch (m_BlockType) } // switch (m_BlockType)
} }
else
{
// Drop 1 item of whatever is growing
switch (m_BlockType)
{
case E_BLOCK_BEETROOTS: a_Pickups.push_back(cItem(E_ITEM_BEETROOT_SEEDS, 1, 0)); break;
case E_BLOCK_CROPS: a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0)); break;
case E_BLOCK_CARROTS: a_Pickups.push_back(cItem(E_ITEM_CARROT, 1, 0)); break;
case E_BLOCK_POTATOES: a_Pickups.push_back(cItem(E_ITEM_POTATO, 1, 0)); break;
default:
{
ASSERT(!"Unhandled block type");
break;
}
}
}
}
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{ {
@ -103,11 +107,15 @@ public:
} }
} }
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{ {
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND)); return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND));
} }
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{ {
UNUSED(a_Meta); UNUSED(a_Meta);