diff options
Diffstat (limited to 'src/Generating/DungeonRoomsFinisher.cpp')
-rw-r--r-- | src/Generating/DungeonRoomsFinisher.cpp | 178 |
1 files changed, 108 insertions, 70 deletions
diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 96dd28333..c52d7257f 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -24,20 +24,21 @@ static const int ROOM_HEIGHT = 4; //////////////////////////////////////////////////////////////////////////////// // cDungeonRoom: -class cDungeonRoom: - public cGridStructGen::cStructure +class cDungeonRoom : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; -public: - + public: cDungeonRoom( - int a_GridX, int a_GridZ, - int a_OriginX, int a_OriginZ, - int a_HalfSizeX, int a_HalfSizeZ, + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, + int a_HalfSizeX, + int a_HalfSizeZ, int a_FloorHeight, cNoise & a_Noise - ): + ) : Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_StartX(a_OriginX - a_HalfSizeX), m_EndX(a_OriginX + a_HalfSizeX), @@ -57,7 +58,7 @@ public: int FirstChestPos = rnd % NumPositions; // The corner positions are a bit more likely, but we don't mind rnd = rnd / 512; int SecondChestPos = (FirstChestPos + 2 + (rnd % (NumPositions - 3))) % NumPositions; - m_Chest1 = DecodeChestCoords(FirstChestPos, SizeX, SizeZ); + m_Chest1 = DecodeChestCoords(FirstChestPos, SizeX, SizeZ); m_Chest2 = DecodeChestCoords(SecondChestPos, SizeX, SizeZ); // Choose what the mobspawner will spawn. @@ -77,8 +78,7 @@ public: } } -protected: - + protected: // The X range of the room, start inclusive, end exclusive: int m_StartX, m_EndX; @@ -126,16 +126,25 @@ protected: - /** Fills the specified area of blocks in the chunk with the specified blocktype if they are one of the overwritten block types. - The coords are absolute, start coords are inclusive, end coords are exclusive. */ - void ReplaceCuboid(cChunkDesc & a_ChunkDesc, int a_StartX, int a_StartY, int a_StartZ, int a_EndX, int a_EndY, int a_EndZ, BLOCKTYPE a_DstBlockType) + /** Fills the specified area of blocks in the chunk with the specified blocktype if they are one of the overwritten + block types. The coords are absolute, start coords are inclusive, end coords are exclusive. */ + void ReplaceCuboid( + cChunkDesc & a_ChunkDesc, + int a_StartX, + int a_StartY, + int a_StartZ, + int a_EndX, + int a_EndY, + int a_EndZ, + BLOCKTYPE a_DstBlockType + ) { int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; int RelStartX = Clamp(a_StartX - BlockX, 0, cChunkDef::Width); int RelStartZ = Clamp(a_StartZ - BlockZ, 0, cChunkDef::Width); - int RelEndX = Clamp(a_EndX - BlockX, 0, cChunkDef::Width); - int RelEndZ = Clamp(a_EndZ - BlockZ, 0, cChunkDef::Width); + int RelEndX = Clamp(a_EndX - BlockX, 0, cChunkDef::Width); + int RelEndZ = Clamp(a_EndZ - BlockZ, 0, cChunkDef::Width); for (int y = a_StartY; y < a_EndY; y++) { for (int z = RelStartZ; z < RelEndZ; z++) @@ -153,16 +162,27 @@ protected: - /** Fills the specified area of blocks in the chunk with a random pattern of the specified blocktypes, if they are one of the overwritten block types. - The coords are absolute, start coords are inclusive, end coords are exclusive. The first blocktype uses 75% chance, the second 25% chance. */ - void ReplaceCuboidRandom(cChunkDesc & a_ChunkDesc, int a_StartX, int a_StartY, int a_StartZ, int a_EndX, int a_EndY, int a_EndZ, BLOCKTYPE a_DstBlockType1, BLOCKTYPE a_DstBlockType2) + /** Fills the specified area of blocks in the chunk with a random pattern of the specified blocktypes, if they are + one of the overwritten block types. The coords are absolute, start coords are inclusive, end coords are exclusive. + The first blocktype uses 75% chance, the second 25% chance. */ + void ReplaceCuboidRandom( + cChunkDesc & a_ChunkDesc, + int a_StartX, + int a_StartY, + int a_StartZ, + int a_EndX, + int a_EndY, + int a_EndZ, + BLOCKTYPE a_DstBlockType1, + BLOCKTYPE a_DstBlockType2 + ) { int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; int RelStartX = Clamp(a_StartX - BlockX, 0, cChunkDef::Width - 1); int RelStartZ = Clamp(a_StartZ - BlockZ, 0, cChunkDef::Width - 1); - int RelEndX = Clamp(a_EndX - BlockX, 0, cChunkDef::Width); - int RelEndZ = Clamp(a_EndZ - BlockZ, 0, cChunkDef::Width); + int RelEndX = Clamp(a_EndX - BlockX, 0, cChunkDef::Width); + int RelEndZ = Clamp(a_EndZ - BlockZ, 0, cChunkDef::Width); auto & rnd = GetRandomProvider(); for (int y = a_StartY; y < a_EndY; y++) { @@ -188,9 +208,8 @@ protected: { int RelX = a_Chest.x - a_ChunkDesc.GetChunkX() * cChunkDef::Width; int RelZ = a_Chest.z - a_ChunkDesc.GetChunkZ() * cChunkDef::Width; - if ( - (RelX < 0) || (RelX >= cChunkDef::Width) || // The X coord is not in this chunk - (RelZ < 0) || (RelZ >= cChunkDef::Width) // The Z coord is not in this chunk + if ((RelX < 0) || (RelX >= cChunkDef::Width) || // The X coord is not in this chunk + (RelZ < 0) || (RelZ >= cChunkDef::Width) // The Z coord is not in this chunk ) { return; @@ -198,34 +217,34 @@ protected: a_ChunkDesc.SetBlockTypeMeta(RelX, m_FloorHeight + 1, RelZ, E_BLOCK_CHEST, static_cast<NIBBLETYPE>(a_Chest.y)); // Fill the chest with random loot - static const cLootProbab LootProbab[] = - { + static const cLootProbab LootProbab[] = { // Item, MinAmount, MaxAmount, Weight - { cItem(E_ITEM_GOLDEN_APPLE), 1, 1, 1 }, - { cItem(E_ITEM_DIAMOND_HORSE_ARMOR), 1, 1, 1 }, - { cItem(E_ITEM_GOLD_HORSE_ARMOR), 1, 1, 2 }, - { cItem(E_ITEM_GOLD), 1, 4, 2 }, - { cItem(E_ITEM_13_DISC), 1, 1, 4 }, - { cItem(E_ITEM_CAT_DISC), 1, 1, 4 }, - { cItem(E_ITEM_IRON_HORSE_ARMOR), 1, 1, 5 }, - { cItem(E_ITEM_IRON), 1, 4, 10 }, - { cItem(E_ITEM_WHEAT), 1, 4, 10 }, - { cItem(E_ITEM_GUNPOWDER), 1, 4, 10 }, - { cItem(E_ITEM_STRING), 1, 4, 10 }, - { cItem(E_ITEM_REDSTONE_DUST), 1, 4, 10 }, - { cItem(E_ITEM_COAL), 1, 4, 10 }, - { cItem(E_ITEM_BONE), 1, 4, 10 }, - { cItem(E_ITEM_ROTTEN_FLESH), 1, 4, 10 }, - { cItem(E_ITEM_SADDLE), 1, 1, 10 }, - { cItem(E_ITEM_BUCKET), 1, 1, 10 }, - { cItem(E_ITEM_BREAD), 1, 1, 10 }, - { cItem(E_ITEM_NAME_TAG), 1, 1, 10 }, - { cItem(E_ITEM_BEETROOT_SEEDS), 2, 4, 10 }, - { cItem(E_ITEM_MELON_SEEDS), 2, 4, 10 }, - { cItem(E_ITEM_PUMPKIN_SEEDS), 2, 4, 10 }, - } ; - - cChestEntity * ChestEntity = static_cast<cChestEntity *>(a_ChunkDesc.GetBlockEntity(RelX, m_FloorHeight + 1, RelZ)); + {cItem(E_ITEM_GOLDEN_APPLE), 1, 1, 1}, + {cItem(E_ITEM_DIAMOND_HORSE_ARMOR), 1, 1, 1}, + {cItem(E_ITEM_GOLD_HORSE_ARMOR), 1, 1, 2}, + {cItem(E_ITEM_GOLD), 1, 4, 2}, + {cItem(E_ITEM_13_DISC), 1, 1, 4}, + {cItem(E_ITEM_CAT_DISC), 1, 1, 4}, + {cItem(E_ITEM_IRON_HORSE_ARMOR), 1, 1, 5}, + {cItem(E_ITEM_IRON), 1, 4, 10}, + {cItem(E_ITEM_WHEAT), 1, 4, 10}, + {cItem(E_ITEM_GUNPOWDER), 1, 4, 10}, + {cItem(E_ITEM_STRING), 1, 4, 10}, + {cItem(E_ITEM_REDSTONE_DUST), 1, 4, 10}, + {cItem(E_ITEM_COAL), 1, 4, 10}, + {cItem(E_ITEM_BONE), 1, 4, 10}, + {cItem(E_ITEM_ROTTEN_FLESH), 1, 4, 10}, + {cItem(E_ITEM_SADDLE), 1, 1, 10}, + {cItem(E_ITEM_BUCKET), 1, 1, 10}, + {cItem(E_ITEM_BREAD), 1, 1, 10}, + {cItem(E_ITEM_NAME_TAG), 1, 1, 10}, + {cItem(E_ITEM_BEETROOT_SEEDS), 2, 4, 10}, + {cItem(E_ITEM_MELON_SEEDS), 2, 4, 10}, + {cItem(E_ITEM_PUMPKIN_SEEDS), 2, 4, 10}, + }; + + cChestEntity * ChestEntity = + static_cast<cChestEntity *>(a_ChunkDesc.GetBlockEntity(RelX, m_FloorHeight + 1, RelZ)); ASSERT((ChestEntity != nullptr) && (ChestEntity->GetBlockType() == E_BLOCK_CHEST)); cNoise Noise(a_ChunkDesc.GetChunkX() ^ a_ChunkDesc.GetChunkZ()); int NumSlots = 3 + ((Noise.IntNoise3DInt(a_Chest.x, a_Chest.y, a_Chest.z) / 11) % 4); @@ -238,12 +257,10 @@ protected: // cGridStructGen::cStructure override: virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override { - if ( - (m_EndX < a_ChunkDesc.GetChunkX() * cChunkDef::Width) || + if ((m_EndX < a_ChunkDesc.GetChunkX() * cChunkDef::Width) || (m_StartX >= a_ChunkDesc.GetChunkX() * cChunkDef::Width + cChunkDef::Width) || - (m_EndZ < a_ChunkDesc.GetChunkZ() * cChunkDef::Width) || - (m_StartZ >= a_ChunkDesc.GetChunkZ() * cChunkDef::Width + cChunkDef::Width) - ) + (m_EndZ < a_ChunkDesc.GetChunkZ() * cChunkDef::Width) || + (m_StartZ >= a_ChunkDesc.GetChunkZ() * cChunkDef::Width + cChunkDef::Width)) { // The chunk is not intersecting the room at all, bail out return; @@ -251,14 +268,24 @@ protected: int b = m_FloorHeight + 1; // Bottom int t = m_FloorHeight + 1 + ROOM_HEIGHT; // Top - ReplaceCuboidRandom(a_ChunkDesc, m_StartX, m_FloorHeight, m_StartZ, m_EndX + 1, b, m_EndZ + 1, E_BLOCK_MOSSY_COBBLESTONE, E_BLOCK_COBBLESTONE); // Floor + ReplaceCuboidRandom( + a_ChunkDesc, + m_StartX, + m_FloorHeight, + m_StartZ, + m_EndX + 1, + b, + m_EndZ + 1, + E_BLOCK_MOSSY_COBBLESTONE, + E_BLOCK_COBBLESTONE + ); // Floor ReplaceCuboid(a_ChunkDesc, m_StartX + 1, b, m_StartZ + 1, m_EndX, t, m_EndZ, E_BLOCK_AIR); // Insides // Walls: - ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_StartZ, m_StartX + 1, t, m_EndZ, E_BLOCK_COBBLESTONE); // XM wall - ReplaceCuboid(a_ChunkDesc, m_EndX, b, m_StartZ, m_EndX + 1, t, m_EndZ, E_BLOCK_COBBLESTONE); // XP wall - ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_StartZ, m_EndX + 1, t, m_StartZ + 1, E_BLOCK_COBBLESTONE); // ZM wall - ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_EndZ, m_EndX + 1, t, m_EndZ + 1, E_BLOCK_COBBLESTONE); // ZP wall + ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_StartZ, m_StartX + 1, t, m_EndZ, E_BLOCK_COBBLESTONE); // XM wall + ReplaceCuboid(a_ChunkDesc, m_EndX, b, m_StartZ, m_EndX + 1, t, m_EndZ, E_BLOCK_COBBLESTONE); // XP wall + ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_StartZ, m_EndX + 1, t, m_StartZ + 1, E_BLOCK_COBBLESTONE); // ZM wall + ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_EndZ, m_EndX + 1, t, m_EndZ + 1, E_BLOCK_COBBLESTONE); // ZP wall // Place chests: TryPlaceChest(a_ChunkDesc, m_Chest1); @@ -267,18 +294,16 @@ protected: // Place the spawner: int CenterX = (m_StartX + m_EndX) / 2 - a_ChunkDesc.GetChunkX() * cChunkDef::Width; int CenterZ = (m_StartZ + m_EndZ) / 2 - a_ChunkDesc.GetChunkZ() * cChunkDef::Width; - if ( - (CenterX >= 0) && (CenterX < cChunkDef::Width) && - (CenterZ >= 0) && (CenterZ < cChunkDef::Width) - ) + if ((CenterX >= 0) && (CenterX < cChunkDef::Width) && (CenterZ >= 0) && (CenterZ < cChunkDef::Width)) { a_ChunkDesc.SetBlockTypeMeta(CenterX, b, CenterZ, E_BLOCK_MOB_SPAWNER, 0); - cMobSpawnerEntity * MobSpawner = static_cast<cMobSpawnerEntity *>(a_ChunkDesc.GetBlockEntity(CenterX, b, CenterZ)); + cMobSpawnerEntity * MobSpawner = + static_cast<cMobSpawnerEntity *>(a_ChunkDesc.GetBlockEntity(CenterX, b, CenterZ)); ASSERT((MobSpawner != nullptr) && (MobSpawner->GetBlockType() == E_BLOCK_MOB_SPAWNER)); MobSpawner->SetEntity(m_MonsterType); } } -} ; +}; @@ -287,7 +312,14 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cDungeonRoomsFinisher: -cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainShapeGen & a_ShapeGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib) : +cDungeonRoomsFinisher::cDungeonRoomsFinisher( + cTerrainShapeGen & a_ShapeGen, + int a_Seed, + int a_GridSize, + int a_MaxSize, + int a_MinSize, + const AString & a_HeightDistrib +) : Super(a_Seed + 100, a_GridSize, a_GridSize, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 1024), m_ShapeGen(a_ShapeGen), m_MaxHalfSize((a_MaxSize + 1) / 2), @@ -308,7 +340,12 @@ cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainShapeGen & a_ShapeGen, int -cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) +cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure( + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ +) { // Select a random room size in each direction: int rnd = m_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) / 7; @@ -335,5 +372,6 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int } // Create the dungeon room descriptor: - return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, height, m_Noise)); + return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, height, m_Noise) + ); } |