From c0b08a6c1e4666c1d3044a264fc47711e821ce14 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 1 Dec 2014 17:51:20 +0100 Subject: Dungeons spawners now spawn mobs 25% for a spider, 25% for a skeleton and 50% for a zombie spawner. --- src/Generating/DungeonRoomsFinisher.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Generating') diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 7ab22c2c5..0267c41fa 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -7,6 +7,7 @@ #include "DungeonRoomsFinisher.h" #include "../FastRandom.h" #include "../BlockEntities/ChestEntity.h" +#include "../BlockEntities/MobSpawnerEntity.h" @@ -57,6 +58,22 @@ public: int SecondChestPos = (FirstChestPos + 2 + (rnd % (NumPositions - 3))) % NumPositions; m_Chest1 = DecodeChestCoords(FirstChestPos, SizeX, SizeZ); m_Chest2 = DecodeChestCoords(SecondChestPos, SizeX, SizeZ); + + // Choose what the mobspawner will spawn. + // 25% chance for a spider, 25% for a skeleton and 50% chance to get a zombie spawer. + NOISE_DATATYPE MobType = a_Noise.IntNoise3D(a_OriginX, m_FloorHeight, a_OriginZ); + if (MobType <= -0.5) + { + m_MonsterType = mtSkeleton; + } + else if (MobType <= 0) + { + m_MonsterType = mtSpider; + } + else + { + m_MonsterType = mtZombie; + } } protected: @@ -76,6 +93,8 @@ protected: /** The (absolute) coords of the second chest. The Y coord represents the chest's Meta value (facing). */ Vector3i m_Chest2; + /** The monster type for the mobspawner entity. */ + eMonsterType m_MonsterType; /** Decodes the position index along the room walls into a proper 2D position for a chest. @@ -246,7 +265,9 @@ protected: ) { a_ChunkDesc.SetBlockTypeMeta(CenterX, b, CenterZ, E_BLOCK_MOB_SPAWNER, 0); - // TODO: Set the spawned mob + cMobSpawnerEntity * MobSpawner = (cMobSpawnerEntity *)a_ChunkDesc.GetBlockEntity(CenterX, b, CenterZ); + ASSERT((MobSpawner != nullptr) && (MobSpawner->GetBlockType() == E_BLOCK_MOB_SPAWNER)); + MobSpawner->SetEntity(m_MonsterType); } } } ; -- cgit v1.2.3 From 7586069829af86a03f900daebc0cbf9622071f30 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 1 Dec 2014 19:07:54 +0100 Subject: Using static cast for Dungeon spawners --- src/Generating/DungeonRoomsFinisher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Generating') diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 0267c41fa..492ab1ed9 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -265,7 +265,7 @@ protected: ) { a_ChunkDesc.SetBlockTypeMeta(CenterX, b, CenterZ, E_BLOCK_MOB_SPAWNER, 0); - cMobSpawnerEntity * MobSpawner = (cMobSpawnerEntity *)a_ChunkDesc.GetBlockEntity(CenterX, b, CenterZ); + cMobSpawnerEntity * MobSpawner = static_cast(a_ChunkDesc.GetBlockEntity(CenterX, b, CenterZ)); ASSERT((MobSpawner != nullptr) && (MobSpawner->GetBlockType() == E_BLOCK_MOB_SPAWNER)); MobSpawner->SetEntity(m_MonsterType); } -- cgit v1.2.3 From 5db3ceb333e5a705de3ff03834d1c212e1c38e63 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 2 Dec 2014 09:42:49 +0100 Subject: Suggestions by xoft Using IntNoise3D to prevent needless floating point math --- src/Generating/DungeonRoomsFinisher.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 492ab1ed9..19ac3b8b2 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -61,12 +61,12 @@ public: // Choose what the mobspawner will spawn. // 25% chance for a spider, 25% for a skeleton and 50% chance to get a zombie spawer. - NOISE_DATATYPE MobType = a_Noise.IntNoise3D(a_OriginX, m_FloorHeight, a_OriginZ); - if (MobType <= -0.5) + int MobType = (a_Noise.IntNoise3D(a_OriginX, m_FloorHeight, a_OriginZ) / 7) % 100 + if (MobType <= 25) { m_MonsterType = mtSkeleton; } - else if (MobType <= 0) + else if (MobType <= 50) { m_MonsterType = mtSpider; } -- cgit v1.2.3 From a466986f53c2bec54bc25951d05036db5a3fb2e1 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 2 Dec 2014 09:55:25 +0100 Subject: Using IntNoise3DInt instead of IntNoise3D --- src/Generating/DungeonRoomsFinisher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Generating') diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 19ac3b8b2..847fcbf10 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -61,7 +61,7 @@ public: // Choose what the mobspawner will spawn. // 25% chance for a spider, 25% for a skeleton and 50% chance to get a zombie spawer. - int MobType = (a_Noise.IntNoise3D(a_OriginX, m_FloorHeight, a_OriginZ) / 7) % 100 + int MobType = (a_Noise.IntNoise3DInt(a_OriginX, m_FloorHeight, a_OriginZ) / 7) % 100 if (MobType <= 25) { m_MonsterType = mtSkeleton; -- cgit v1.2.3 From f1177984f102e7b9c8cdc9ca5e8d9b5c67a4330f Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 2 Dec 2014 10:20:20 +0100 Subject: Fixed forgotten semicolon --- src/Generating/DungeonRoomsFinisher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Generating') diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 847fcbf10..092e232ab 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -61,7 +61,7 @@ public: // Choose what the mobspawner will spawn. // 25% chance for a spider, 25% for a skeleton and 50% chance to get a zombie spawer. - int MobType = (a_Noise.IntNoise3DInt(a_OriginX, m_FloorHeight, a_OriginZ) / 7) % 100 + int MobType = (a_Noise.IntNoise3DInt(a_OriginX, m_FloorHeight, a_OriginZ) / 7) % 100; if (MobType <= 25) { m_MonsterType = mtSkeleton; -- cgit v1.2.3 From 27185dd3748b04af35a3d17eb5c2c58e826cd9cb Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Wed, 3 Dec 2014 00:26:15 -0800 Subject: clearing CheckBasicStyle.lua messages --- src/Generating/FinishGen.cpp | 26 +++++++++++++------------- src/Generating/FinishGen.h | 30 +++++++++++++++--------------- 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index b9d702429..9e035926e 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -65,7 +65,7 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc) { continue; } - + // Choose what block to use. NOISE_DATATYPE BlockType = m_Noise.IntNoise3D((int) ChunkX, y, (int) ChunkZ); if (BlockType < -0.7) @@ -195,10 +195,10 @@ void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc) { continue; } - + // Get the top block + 1. This is the place where the grass would finaly be placed: int y = a_ChunkDesc.GetHeight(x, z) + 1; - + if (y >= 255) { continue; @@ -281,7 +281,7 @@ bool cFinishGenSprinkleFoliage::TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_ { return false; } - + // All conditions met, place a sugarcane here: a_ChunkDesc.SetBlockType(a_RelX, a_RelY + 1, a_RelZ, E_BLOCK_SUGARCANE); return true; @@ -294,7 +294,7 @@ bool cFinishGenSprinkleFoliage::TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) { // Generate small foliage (1-block): - + // TODO: Update heightmap with 1-block-tall foliage for (int z = 0; z < cChunkDef::Width; z++) { @@ -319,7 +319,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) // WEIRD, since we're using heightmap, so there should NOT be anything above it continue; } - + const float xx = (float)BlockX; float val1 = m_Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f); float val2 = m_Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f); @@ -359,7 +359,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) } break; } // case E_BLOCK_GRASS - + case E_BLOCK_SAND: { int y = Top + 1; @@ -400,7 +400,7 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc) int ChunkZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; HEIGHTTYPE MaxHeight = a_ChunkDesc.GetMaxHeight(); - for (int x = 0; x < 16; x++) + for (int x = 0; x < 16; x++) { int xx = ChunkX + x; for (int z = 0; z < 16; z++) @@ -768,7 +768,7 @@ void cFinishGenPreSimulator::StationarizeFluid( } // for y } // for x } // for z - + // Turn fluid at the chunk edges into non-stationary fluid: for (int y = 0; y < cChunkDef::Height; y++) { @@ -860,12 +860,12 @@ void cFinishGenFluidSprings::GenFinish(cChunkDesc & a_ChunkDesc) // Not in this chunk return; } - + // Get the height at which to try: int Height = m_Noise.IntNoise3DInt(128 * a_ChunkDesc.GetChunkX(), 1024, 256 * a_ChunkDesc.GetChunkZ()) / 11; Height %= m_HeightDistribution.GetSum(); Height = m_HeightDistribution.MapValue(Height); - + // Try adding the spring at the height, if unsuccessful, move lower: for (int y = Height; y > 1; y--) { @@ -903,7 +903,7 @@ bool cFinishGenFluidSprings::TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int { return false; } - + static const struct { int x, y, z; @@ -934,7 +934,7 @@ bool cFinishGenFluidSprings::TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int { return false; } - + // Has exactly one air neighbor, place a spring: a_ChunkDesc.SetBlockTypeMeta(x, y, z, m_Fluid, 0); return true; diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index d45365683..c1100b51f 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -121,7 +121,7 @@ class cFinishGenSoulsandRims : public cFinishGen { public: - cFinishGenSoulsandRims(int a_Seed) : + cFinishGenSoulsandRims(int a_Seed) : m_Noise(a_Seed) { } @@ -141,14 +141,14 @@ class cFinishGenSprinkleFoliage : { public: cFinishGenSprinkleFoliage(int a_Seed) : m_Noise(a_Seed), m_Seed(a_Seed) {} - + protected: cNoise m_Noise; int m_Seed; - + /// Tries to place sugarcane at the coords specified, returns true if successful bool TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ); - + // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; @@ -186,31 +186,31 @@ public: { 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 (size_t 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: cNoise m_Noise; BLOCKTYPE m_BlockType; int m_Amount; ///< Relative amount of blocks to try adding. 1 = one block per 256 biome columns. - + int GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap); // Returns true if the given biome is a biome that is allowed. @@ -225,7 +225,7 @@ protected: return m_IsAllowedBelow[a_BlockBelow]; } - + // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; @@ -242,11 +242,11 @@ public: m_Level(a_Level) { } - + int GetLevel(void) const { return m_Level; } protected: int m_Level; - + // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; @@ -260,7 +260,7 @@ class cFinishGenPreSimulator : { public: cFinishGenPreSimulator(bool a_PreSimulateFallingBlocks, bool a_PreSimulateWater, bool a_PreSimulateLava); - + protected: bool m_PreSimulateFallingBlocks; @@ -272,7 +272,7 @@ protected: cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change cChunkDef::HeightMap & a_HeightMap // Height map to update by the current data ); - + /** For each fluid block: - if all surroundings are of the same fluid, makes it stationary; otherwise makes it flowing (excl. top) - all fluid on the chunk's edge is made flowing @@ -297,7 +297,7 @@ class cFinishGenFluidSprings : { public: cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, eDimension a_Dimension); - + protected: cNoise m_Noise; -- cgit v1.2.3