summaryrefslogtreecommitdiffstats
path: root/source/ChestEntity.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-04-06 23:21:57 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-04-06 23:21:57 +0200
commit502935c061ea913180f0a77a7406f5292e697c79 (patch)
treea74e562a772b89db12985d6f1744ae91ff4890d6 /source/ChestEntity.cpp
parentAdded a tab in the serversettings where you can edit the world.ini of all your worlds. (diff)
downloadcuberite-502935c061ea913180f0a77a7406f5292e697c79.tar
cuberite-502935c061ea913180f0a77a7406f5292e697c79.tar.gz
cuberite-502935c061ea913180f0a77a7406f5292e697c79.tar.bz2
cuberite-502935c061ea913180f0a77a7406f5292e697c79.tar.lz
cuberite-502935c061ea913180f0a77a7406f5292e697c79.tar.xz
cuberite-502935c061ea913180f0a77a7406f5292e697c79.tar.zst
cuberite-502935c061ea913180f0a77a7406f5292e697c79.zip
Diffstat (limited to 'source/ChestEntity.cpp')
-rw-r--r--source/ChestEntity.cpp54
1 files changed, 43 insertions, 11 deletions
diff --git a/source/ChestEntity.cpp b/source/ChestEntity.cpp
index 2f038897c..d3c062924 100644
--- a/source/ChestEntity.cpp
+++ b/source/ChestEntity.cpp
@@ -9,6 +9,7 @@
#include "World.h"
#include "Root.h"
#include "Pickup.h"
+#include "Noise.h"
#include <json/json.h>
@@ -22,11 +23,20 @@ class cRoot;
+cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ) :
+ super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ)
+{
+ cBlockEntityWindowOwner::SetBlockEntity(this);
+}
+
+
+
+
+
cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
- cBlockEntity(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World)
+ super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World)
{
- m_Content = new cItem[ c_ChestHeight * c_ChestWidth ];
- SetBlockEntity(this); // cBlockEntityWindowOwner
+ cBlockEntityWindowOwner::SetBlockEntity(this);
}
@@ -40,8 +50,6 @@ cChestEntity::~cChestEntity()
{
Window->OwnerDestroyed();
}
-
- delete [] m_Content;
}
@@ -92,13 +100,37 @@ void cChestEntity::SetSlot(int a_Slot, const cItem & a_Item)
-#define READ(File, Var) \
- if (File.Read(&Var, sizeof(Var)) != sizeof(Var)) \
- { \
- LOGERROR("ERROR READING cChestEntity %s FROM FILE (line %d)", #Var, __LINE__); \
- return false; \
+void cChestEntity::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, int a_CountLootProbabs, int a_NumSlots, int a_Seed)
+{
+ // Calculate the total weight:
+ int TotalProbab = 1;
+ for (int i = 0; i < a_CountLootProbabs; i++)
+ {
+ TotalProbab += a_LootProbabs[i].m_Weight;
}
-
+
+ // Pick the loot items:
+ cNoise Noise(a_Seed);
+ for (int i = 0; i < a_NumSlots; i++)
+ {
+ int Rnd = (Noise.IntNoise1DInt(i) / 7);
+ int LootRnd = Rnd % TotalProbab;
+ Rnd >>= 8;
+ cItem CurrentLoot = cItem(E_ITEM_BOOK, 1, 0); // TODO: enchantment
+ for (int j = 0; j < a_CountLootProbabs; j++)
+ {
+ LootRnd -= a_LootProbabs[i].m_Weight;
+ if (LootRnd < 0)
+ {
+ CurrentLoot = a_LootProbabs[i].m_Item;
+ CurrentLoot.m_ItemCount = a_LootProbabs[i].m_MinAmount + (Rnd % (a_LootProbabs[i].m_MaxAmount - a_LootProbabs[i].m_MinAmount));
+ Rnd >>= 8;
+ break;
+ }
+ } // for j - a_LootProbabs[]
+ SetSlot(Rnd % ARRAYCOUNT(m_Content), CurrentLoot);
+ } // for i - NumSlots
+}