Permalink
Comparing changes
Open a pull request
- 2 commits
- 1 file changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
42 additions
and 22 deletions.
- +42 −22 src/Generating/DungeonRoomsFinisher.cpp
| @@ -40,10 +40,22 @@ class cDungeonRoom : | ||
| m_EndX(a_OriginX + a_HalfSizeX), | ||
| m_StartZ(a_OriginZ - a_HalfSizeZ), | ||
| m_EndZ(a_OriginZ + a_HalfSizeZ), | ||
| m_FloorHeight(a_FloorHeight), | ||
| m_Chest1(SelectChestCoords(a_Noise, a_OriginX + 1, a_OriginZ)), | ||
| m_Chest2(SelectChestCoords(a_Noise, a_OriginX + 2, a_OriginZ)) | ||
| m_FloorHeight(a_FloorHeight) | ||
| { | ||
| /* | ||
| Pick coords next to the wall for the chests. | ||
| This is done by indexing the possible coords, picking any one for the first chest | ||
| and then picking another position for the second chest that is not adjacent to the first pos | ||
| */ | ||
| int rnd = a_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) / 7; | ||
| int SizeX = m_EndX - m_StartX - 1; | ||
| int SizeZ = m_EndZ - m_StartZ - 1; | ||
| int NumPositions = 2 * SizeX + 2 * SizeZ; | ||
| 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_Chest2 = DecodeChestCoords(SecondChestPos, SizeX, SizeZ); | ||
| } | ||
| protected: | ||
| @@ -65,36 +77,29 @@ class cDungeonRoom : | ||
| /** Selects the coords for the chest, using the noise and coords provided. | ||
| Assumes that the room XZ ranges are already assigned. */ | ||
| Vector3i SelectChestCoords(cNoise & a_Noise, int a_X, int a_Z) | ||
| /** Decodes the position index along the room walls into a proper 2D position for a chest. */ | ||
| Vector3i DecodeChestCoords(int a_PosIdx, int a_SizeX, int a_SizeZ) | ||
| { | ||
| // Pick a coord next to the wall: | ||
| int rnd = a_Noise.IntNoise2DInt(a_X, a_Z) / 7; | ||
| int SizeX = m_EndX - m_StartX - 1; | ||
| int SizeZ = m_EndZ - m_StartZ - 1; | ||
| rnd = rnd % (2 * SizeX + 2 * SizeZ); | ||
| if (rnd < SizeX) | ||
| if (a_PosIdx < a_SizeX) | ||
| { | ||
| // Return a coord on the ZM side of the room: | ||
| return Vector3i(m_StartX + rnd + 1, E_META_CHEST_FACING_ZP, m_StartZ + 1); | ||
| return Vector3i(m_StartX + a_PosIdx + 1, E_META_CHEST_FACING_ZP, m_StartZ + 1); | ||
| } | ||
| rnd -= SizeX; | ||
| if (rnd < SizeZ) | ||
| a_PosIdx -= a_SizeX; | ||
| if (a_PosIdx < a_SizeZ) | ||
| { | ||
| // Return a coord on the XP side of the room: | ||
| return Vector3i(m_EndX - 1, E_META_CHEST_FACING_XM, m_StartZ + rnd + 1); | ||
| return Vector3i(m_EndX - 1, E_META_CHEST_FACING_XM, m_StartZ + a_PosIdx + 1); | ||
| } | ||
| rnd -= SizeZ; | ||
| if (rnd < SizeX) | ||
| a_PosIdx -= a_SizeZ; | ||
| if (a_PosIdx < a_SizeX) | ||
| { | ||
| // Return a coord on the ZP side of the room: | ||
| return Vector3i(m_StartX + rnd + 1, E_META_CHEST_FACING_ZM, m_StartZ + 1); | ||
| return Vector3i(m_StartX + a_PosIdx + 1, E_META_CHEST_FACING_ZM, m_StartZ + 1); | ||
| } | ||
| rnd -= SizeX; | ||
| a_PosIdx -= a_SizeX; | ||
| // Return a coord on the XM side of the room: | ||
| return Vector3i(m_StartX + 1, E_META_CHEST_FACING_XP, m_StartZ + rnd + 1); | ||
| return Vector3i(m_StartX + 1, E_META_CHEST_FACING_XP, m_StartZ + a_PosIdx + 1); | ||
| } | ||
| @@ -192,13 +197,28 @@ class cDungeonRoom : | ||
| 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 | ||
| 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 | ||
| // Place chests: | ||
| TryPlaceChest(a_ChunkDesc, m_Chest1); | ||
| TryPlaceChest(a_ChunkDesc, m_Chest2); | ||
| // 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) | ||
| ) | ||
| { | ||
| a_ChunkDesc.SetBlockTypeMeta(CenterX, b, CenterZ, E_BLOCK_MOB_SPAWNER, 0); | ||
| // TODO: Set the spawned mob | ||
| } | ||
| } | ||
| } ; | ||