From 08676128b0671612cd23c30b661b9908717f51c6 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 15 Oct 2014 21:15:12 +0200 Subject: Added loot to dungeons. --- src/Generating/DungeonRoomsFinisher.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/Generating') diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index f213455d6..de3a426a1 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "DungeonRoomsFinisher.h" #include "../FastRandom.h" +#include "../BlockEntities/ChestEntity.h" @@ -175,7 +176,32 @@ protected: } a_ChunkDesc.SetBlockTypeMeta(RelX, m_FloorHeight + 1, RelZ, E_BLOCK_CHEST, (NIBBLETYPE)a_Chest.y); - // TODO: Fill the chest with random loot + // Fill the chest with random loot + static const cLootProbab LootProbab[] = + { + // Item, MinAmount, MaxAmount, Weight + { 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_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_IRON_HORSE_ARMOR), 1, 1, 5 }, + { cItem(E_ITEM_13_DISC), 1, 1, 4 }, + { cItem(E_ITEM_CAT_DISC), 1, 1, 4 }, + { cItem(E_ITEM_GOLD_HORSE_ARMOR), 1, 1, 2 }, + { cItem(E_ITEM_DIAMOND_HORSE_ARMOR), 1, 1, 1 }, + } ; + + cChestEntity * ChestEntity = (cChestEntity *)a_ChunkDesc.GetBlockEntity(RelX, m_FloorHeight + 1, RelZ); + ASSERT((ChestEntity != NULL) && (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); + int Seed = Noise.IntNoise2DInt(RelX, RelZ); + ChestEntity->GetContents().GenerateRandomLootWithBooks(LootProbab, ARRAYCOUNT(LootProbab), NumSlots, Seed); } -- cgit v1.2.3 From 3f0d4fe250288a97845bdc4ce8f4f20e00fee728 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 15 Oct 2014 22:10:14 +0200 Subject: Reversed the order of the loot For some reason the rare items weren't generating at all. Added forgotten Golden Apple --- src/Generating/DungeonRoomsFinisher.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index de3a426a1..68c040fbe 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -180,6 +180,12 @@ protected: 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_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 }, @@ -189,11 +195,6 @@ protected: { 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_IRON_HORSE_ARMOR), 1, 1, 5 }, - { cItem(E_ITEM_13_DISC), 1, 1, 4 }, - { cItem(E_ITEM_CAT_DISC), 1, 1, 4 }, - { cItem(E_ITEM_GOLD_HORSE_ARMOR), 1, 1, 2 }, - { cItem(E_ITEM_DIAMOND_HORSE_ARMOR), 1, 1, 1 }, } ; cChestEntity * ChestEntity = (cChestEntity *)a_ChunkDesc.GetBlockEntity(RelX, m_FloorHeight + 1, RelZ); @@ -209,6 +210,9 @@ protected: // cGridStructGen::cStructure override: virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override { + 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 ( (m_EndX < a_ChunkDesc.GetChunkX() * cChunkDef::Width) || (m_StartX >= a_ChunkDesc.GetChunkX() * cChunkDef::Width + cChunkDef::Width) || @@ -219,6 +223,12 @@ protected: // The chunk is not intersecting the room at all, bail out return; } + + if (!cBlockInfo::CanBeTerraformed(a_ChunkDesc.GetBlockType(CenterX, m_FloorHeight + 1, CenterZ))) + { + return; + } + 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 @@ -235,8 +245,6 @@ protected: 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) -- cgit v1.2.3 From 5ed6d280ce5d199f8b319429e281c0ed48b82af8 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 16 Oct 2014 10:26:17 +0200 Subject: Reversed wrong fix for #1517. --- src/Generating/DungeonRoomsFinisher.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 68c040fbe..492bae129 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -210,9 +210,6 @@ protected: // cGridStructGen::cStructure override: virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override { - 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 ( (m_EndX < a_ChunkDesc.GetChunkX() * cChunkDef::Width) || (m_StartX >= a_ChunkDesc.GetChunkX() * cChunkDef::Width + cChunkDef::Width) || @@ -224,11 +221,6 @@ protected: return; } - if (!cBlockInfo::CanBeTerraformed(a_ChunkDesc.GetBlockType(CenterX, m_FloorHeight + 1, CenterZ))) - { - return; - } - 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 @@ -245,6 +237,8 @@ protected: 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) -- cgit v1.2.3