From 3e741134279e02d204a8d4638f2d46dfbf814d0c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 12 Sep 2014 23:18:02 +0100 Subject: Implemented Chest Minecarts --- src/UI/SlotArea.cpp | 35 ++++++++++++++++++++++++++ src/UI/SlotArea.h | 14 +++++++++++ src/UI/Window.cpp | 30 +++++++++++++++++++++++ src/UI/Window.h | 15 ++++++++++++ src/UI/WindowOwner.h | 69 +--------------------------------------------------- 5 files changed, 95 insertions(+), 68 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index b4facb2d3..999bed989 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -10,6 +10,7 @@ #include "../BlockEntities/DropSpenserEntity.h" #include "../BlockEntities/EnderChestEntity.h" #include "../BlockEntities/FurnaceEntity.h" +#include "../Entities/Minecart.h" #include "../Items/ItemHandler.h" #include "Window.h" #include "../CraftingRecipes.h" @@ -1919,6 +1920,40 @@ void cSlotAreaFurnace::HandleSmeltItem(const cItem & a_Result, cPlayer & a_Playe +//////////////////////////////////////////////////////////////////////////////// +// cSlotAreaMinecartWithChest: + +cSlotAreaMinecartWithChest::cSlotAreaMinecartWithChest(cMinecartWithChest * a_Chest, cWindow & a_ParentWindow) : + cSlotArea(27, a_ParentWindow), + m_Chest(a_Chest) +{ +} + + + + + +const cItem * cSlotAreaMinecartWithChest::GetSlot(int a_SlotNum, cPlayer & a_Player) const +{ + // a_SlotNum ranges from 0 to 26, use that to index the minecart chest entity's inventory directly: + UNUSED(a_Player); + return &(m_Chest->GetSlot(a_SlotNum)); +} + + + + + +void cSlotAreaMinecartWithChest::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) +{ + UNUSED(a_Player); + m_Chest->SetSlot(a_SlotNum, a_Item); +} + + + + + //////////////////////////////////////////////////////////////////////////////// // cSlotAreaInventoryBase: diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 6bbc87b76..0a35527d1 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -20,6 +20,7 @@ class cChestEntity; class cDropSpenserEntity; class cEnderChestEntity; class cFurnaceEntity; +class cMinecartWithChest; class cCraftingRecipe; class cEnchantingWindow; class cWorld; @@ -455,3 +456,16 @@ protected: + +class cSlotAreaMinecartWithChest : + public cSlotArea +{ +public: + cSlotAreaMinecartWithChest(cMinecartWithChest * a_ChestCart, cWindow & a_ParentWindow); + + virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; + +protected: + cMinecartWithChest * m_Chest; +}; \ No newline at end of file diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 66900269f..fd80a017d 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -14,6 +14,7 @@ #include "../BlockEntities/DropSpenserEntity.h" #include "../BlockEntities/EnderChestEntity.h" #include "../BlockEntities/HopperEntity.h" +#include "../Entities/Minecart.h" #include "../Root.h" #include "../Bindings/PluginManager.h" @@ -1047,6 +1048,34 @@ cChestWindow::~cChestWindow() +//////////////////////////////////////////////////////////////////////////////// +// cMinecartWithChestWindow: + +cMinecartWithChestWindow::cMinecartWithChestWindow(cMinecartWithChest * a_ChestCart) : + cWindow(wtChest, "Minecart with Chest"), + m_ChestCart(a_ChestCart) +{ + m_ShouldDistributeToHotbarFirst = false; + m_SlotAreas.push_back(new cSlotAreaMinecartWithChest(a_ChestCart, *this)); + m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); + + a_ChestCart->GetWorld()->BroadcastSoundEffect("random.chestopen", a_ChestCart->GetPosX(), a_ChestCart->GetPosY(), a_ChestCart->GetPosZ(), 1, 1); +} + + + + + +cMinecartWithChestWindow::~cMinecartWithChestWindow() +{ + m_ChestCart->GetWorld()->BroadcastSoundEffect("random.chestclosed", m_ChestCart->GetPosX(), m_ChestCart->GetPosY(), m_ChestCart->GetPosZ(), 1, 1); +} + + + + + //////////////////////////////////////////////////////////////////////////////// // cDropSpenserWindow: @@ -1073,6 +1102,7 @@ cEnderChestWindow::cEnderChestWindow(cEnderChestEntity * a_EnderChest) : m_BlockY(a_EnderChest->GetPosY()), m_BlockZ(a_EnderChest->GetPosZ()) { + m_ShouldDistributeToHotbarFirst = false; m_SlotAreas.push_back(new cSlotAreaEnderChest(a_EnderChest, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); diff --git a/src/UI/Window.h b/src/UI/Window.h index 3d860407f..f47cf4b99 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -23,6 +23,7 @@ class cDropSpenserEntity; class cEnderChestEntity; class cFurnaceEntity; class cHopperEntity; +class cMinecartWithChest; class cBeaconEntity; class cSlotArea; class cSlotAreaAnvil; @@ -360,6 +361,20 @@ protected: +class cMinecartWithChestWindow : + public cWindow +{ +public: + cMinecartWithChestWindow(cMinecartWithChest * a_ChestCart); + ~cMinecartWithChestWindow(); +private: + cMinecartWithChest * m_ChestCart; +}; + + + + + class cEnderChestWindow : public cWindow { diff --git a/src/UI/WindowOwner.h b/src/UI/WindowOwner.h index 7a7941e37..a8be3e6cb 100644 --- a/src/UI/WindowOwner.h +++ b/src/UI/WindowOwner.h @@ -52,77 +52,10 @@ public: { return m_Window; } - - /// Returns the block position at which the element owning the window is - virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) = 0; private: cWindow * m_Window; -} ; - - - - - -/** -Window owner that is associated with a block entity (chest, furnace, ...) -*/ -class cBlockEntityWindowOwner : - public cWindowOwner -{ -public: - cBlockEntityWindowOwner(void) : - m_BlockEntity(NULL) - { - } - - void SetBlockEntity(cBlockEntity * a_BlockEntity) - { - m_BlockEntity = a_BlockEntity; - } - - virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override - { - a_BlockX = m_BlockEntity->GetPosX(); - a_BlockY = m_BlockEntity->GetPosY(); - a_BlockZ = m_BlockEntity->GetPosZ(); - } - -private: - cBlockEntity * m_BlockEntity; -} ; - - - - - -/** -Window owner that is associated with an entity (chest minecart) -*/ -class cEntityWindowOwner : - public cWindowOwner -{ -public: - cEntityWindowOwner(void) : - m_Entity(NULL) - { - } - - void SetEntity(cEntity * a_Entity) - { - m_Entity = a_Entity; - } - - virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override - { - a_BlockX = (int)floor(m_Entity->GetPosX() + 0.5); - a_BlockY = (int)floor(m_Entity->GetPosY() + 0.5); - a_BlockZ = (int)floor(m_Entity->GetPosZ() + 0.5); - } - -private: - cEntity * m_Entity; -} ; +}; -- cgit v1.2.3 From a8c7dadfd72e95e55a2773a69c796c087f95cfbb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 13 Sep 2014 11:14:17 +0100 Subject: Added newlines --- src/UI/SlotArea.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 0a35527d1..35743908a 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -468,4 +468,8 @@ public: protected: cMinecartWithChest * m_Chest; -}; \ No newline at end of file +}; + + + + -- cgit v1.2.3 From bc37b895bca7591e5fc9945bea54d9cac6a1deeb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 13 Sep 2014 11:15:16 +0100 Subject: e.t.c. -> etc. etcetera, not egg tray conglomerate :P --- src/UI/SlotArea.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 35743908a..1eeeb9836 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -449,7 +449,7 @@ protected: // cItemGrid::cListener overrides: virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override; - /// Called after an item has been smelted to handle statistics e.t.c. + /// Called after an item has been smelted to handle statistics etc. void HandleSmeltItem(const cItem & a_Result, cPlayer & a_Player); } ; -- cgit v1.2.3 From 7ce09a9113d693b85fdda13b3c04a8b8eb900153 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 27 Sep 2014 19:19:28 +0100 Subject: Suggestions --- src/UI/WindowOwner.h | 68 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 11 deletions(-) (limited to 'src/UI') diff --git a/src/UI/WindowOwner.h b/src/UI/WindowOwner.h index a8be3e6cb..6845a161b 100644 --- a/src/UI/WindowOwner.h +++ b/src/UI/WindowOwner.h @@ -1,4 +1,3 @@ - #pragma once #include "../BlockEntities/BlockEntity.h" @@ -16,12 +15,6 @@ for entities / players in motion to close their windows when they get too far aw -// class cWindow; - - - - - /** Base class for the window owning */ @@ -32,16 +25,16 @@ public: m_Window(NULL) { } - + virtual ~cWindowOwner() { } - + void CloseWindow(void) { m_Window = NULL; } - + void OpenWindow(cWindow * a_Window) { m_Window = a_Window; @@ -52,7 +45,10 @@ public: { return m_Window; } - + + /// Returns the block position at which the element owning the window is + virtual Vector3i GetBlockPos(void) = 0; + private: cWindow * m_Window; }; @@ -60,3 +56,53 @@ private: + +/** +Window owner that is associated with a block entity (chest, furnace, ...) +*/ +class cBlockEntityWindowOwner : + public cWindowOwner +{ +public: + cBlockEntityWindowOwner(cBlockEntity * a_BlockEntity) : + m_BlockEntity(a_BlockEntity) + { + } + + virtual Vector3i GetBlockPos(void) override + { + return Vector3i(m_BlockEntity->GetPosX(), m_BlockEntity->GetPosY(), m_BlockEntity->GetPosZ()); + } + +private: + cBlockEntity * m_BlockEntity; +}; + + + + + +/** +Window owner that is associated with an entity (chest minecart) +*/ +class cEntityWindowOwner : + public cWindowOwner +{ +public: + cEntityWindowOwner(cEntity * a_Entity) : + m_Entity(a_Entity) + { + } + + virtual Vector3i GetBlockPos(void) override + { + return m_Entity->GetPosition().Floor(); + } + +private: + cEntity * m_Entity; +}; + + + + -- cgit v1.2.3 From b5a2c6667ac0845d17a709cc436afb570079a9a7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 3 Oct 2014 21:32:41 +0100 Subject: Improved furnaces * Fixed progress bar on 1.8 * Fixed bugs * Improved code * Fixes #1068 * Fixes #1070 --- src/UI/Window.cpp | 23 +++++------------------ src/UI/Window.h | 15 ++++++--------- 2 files changed, 11 insertions(+), 27 deletions(-) (limited to 'src/UI') diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index d83336f75..802d0d219 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -758,20 +758,7 @@ void cWindow::BroadcastWholeWindow(void) -void cWindow::BroadcastProgress(int a_Progressbar, int a_Value) -{ - cCSLock Lock(m_CS); - for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr) - { - (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Progressbar, a_Value); - } // for itr - m_OpenedBy[] -} - - - - - -void cWindow::SetProperty(int a_Property, int a_Value) +void cWindow::SetProperty(short a_Property, short a_Value) { cCSLock Lock(m_CS); for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) @@ -784,7 +771,7 @@ void cWindow::SetProperty(int a_Property, int a_Value) -void cWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) +void cWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player) { a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); } @@ -919,7 +906,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : -void cEnchantingWindow::SetProperty(int a_Property, int a_Value) +void cEnchantingWindow::SetProperty(short a_Property, short a_Value) { if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) { @@ -935,7 +922,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value) -void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) +void cEnchantingWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player) { if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) { @@ -951,7 +938,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla -int cEnchantingWindow::GetPropertyValue(int a_Property) +short cEnchantingWindow::GetPropertyValue(short a_Property) { if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) { diff --git a/src/UI/Window.h b/src/UI/Window.h index 6b6dce346..26dd7f125 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -130,9 +130,6 @@ public: /// Sends the contents of the whole window to all clients of this window. void BroadcastWholeWindow(void); - - /// Sends the progressbar to all clients of this window (same as SetProperty) - void BroadcastProgress(int a_Progressbar, int a_Value); // tolua_begin @@ -140,10 +137,10 @@ public: void SetWindowTitle(const AString & a_WindowTitle) { m_WindowTitle = a_WindowTitle; } /// Sends the UpdateWindowProperty (0x69) packet to all clients of the window - virtual void SetProperty(int a_Property, int a_Value); + virtual void SetProperty(short a_Property, short a_Value); /// Sends the UpdateWindowPropert(0x69) packet to the specified player - virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player); + virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player); // tolua_end @@ -287,16 +284,16 @@ class cEnchantingWindow : typedef cWindow super; public: cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ); - virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player) override; - virtual void SetProperty(int a_Property, int a_Value) override; + virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player) override; + virtual void SetProperty(short a_Property, short a_Value) override; /** Return the Value of a Property */ - int GetPropertyValue(int a_Property); + short GetPropertyValue(short a_Property); cSlotArea * m_SlotArea; protected: - int m_PropertyValue[3]; + short m_PropertyValue[3]; int m_BlockX, m_BlockY, m_BlockZ; }; -- cgit v1.2.3 From eeb580a74e48829908c303f8145802bfa1805c68 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 15 Oct 2014 19:01:55 +0200 Subject: Functions in cPluginManager get references instead of pointers. --- src/UI/SlotArea.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 999bed989..88d9f44fc 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -714,7 +714,7 @@ void cSlotAreaCrafting::UpdateRecipe(cPlayer & a_Player) { cCraftingGrid Grid(GetPlayerSlots(a_Player) + 1, m_GridSize, m_GridSize); cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); - cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe); + cRoot::Get()->GetCraftingRecipes()->GetRecipe(a_Player, Grid, Recipe); SetSlot(0, a_Player, Recipe.GetResult()); m_ParentWindow.SendSlot(a_Player, this, 0); } @@ -736,7 +736,7 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) // Not found. Add a new one: cCraftingGrid Grid(GetPlayerSlots(a_Player) + 1, m_GridSize, m_GridSize); cCraftingRecipe Recipe(Grid); - cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe); + cRoot::Get()->GetCraftingRecipes()->GetRecipe(a_Player, Grid, Recipe); m_Recipes.push_back(std::make_pair(a_Player.GetUniqueID(), Recipe)); return m_Recipes.back().second; } -- cgit v1.2.3 From a26541a7c3ced0569098edd0aae61c097c2912f4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 20 Oct 2014 21:55:07 +0100 Subject: En masse NULL -> nullptr replace --- src/UI/SlotArea.cpp | 40 ++++++++++++++++++++-------------------- src/UI/Window.cpp | 38 +++++++++++++++++++------------------- src/UI/Window.h | 6 +++--- src/UI/WindowOwner.h | 4 ++-- 4 files changed, 44 insertions(+), 44 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 88d9f44fc..9113ec343 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -48,9 +48,9 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); bool bAsync = false; - if (GetSlot(a_SlotNum, a_Player) == NULL) + if (GetSlot(a_SlotNum, a_Player) == nullptr) { - LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); return; } @@ -791,9 +791,9 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C } bool bAsync = false; - if (GetSlot(a_SlotNum, a_Player) == NULL) + if (GetSlot(a_SlotNum, a_Player) == nullptr) { - LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); return; } @@ -980,7 +980,7 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player) m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player); m_MaximumCost = 0; - ((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", NULL); + ((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", nullptr); int PosX, PosY, PosZ; ((cAnvilWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); @@ -1238,9 +1238,9 @@ void cSlotAreaBeacon::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); bool bAsync = false; - if (GetSlot(a_SlotNum, a_Player) == NULL) + if (GetSlot(a_SlotNum, a_Player) == nullptr) { - LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); return; } @@ -1408,9 +1408,9 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); bool bAsync = false; - if (GetSlot(a_SlotNum, a_Player) == NULL) + if (GetSlot(a_SlotNum, a_Player) == nullptr) { - LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); return; } @@ -1709,19 +1709,19 @@ cSlotAreaFurnace::~cSlotAreaFurnace() void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - if (m_Furnace == NULL) + if (m_Furnace == nullptr) { - LOGERROR("cSlotAreaFurnace::Clicked(): m_Furnace == NULL"); - ASSERT(!"cSlotAreaFurnace::Clicked(): m_Furnace == NULL"); + LOGERROR("cSlotAreaFurnace::Clicked(): m_Furnace == nullptr"); + ASSERT(!"cSlotAreaFurnace::Clicked(): m_Furnace == nullptr"); return; } if (a_SlotNum == 2) { bool bAsync = false; - if (GetSlot(a_SlotNum, a_Player) == NULL) + if (GetSlot(a_SlotNum, a_Player) == nullptr) { - LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); return; } @@ -2071,9 +2071,9 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C } bool bAsync = false; - if (GetSlot(a_SlotNum, a_Player) == NULL) + if (GetSlot(a_SlotNum, a_Player) == nullptr) { - LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); return; } @@ -2223,15 +2223,15 @@ const cItem * cSlotAreaTemporary::GetSlot(int a_SlotNum, cPlayer & a_Player) con LOGERROR("cSlotAreaTemporary: player \"%s\" not found for slot %d!", a_Player.GetName().c_str(), a_SlotNum); ASSERT(!"cSlotAreaTemporary: player not found!"); - // Player not found, this should not happen, ever! Return NULL, but things may break by this. - return NULL; + // Player not found, this should not happen, ever! Return nullptr, but things may break by this. + return nullptr; } if (a_SlotNum >= (int)(itr->second.size())) { LOGERROR("cSlotAreaTemporary: asking for more slots than actually stored!"); ASSERT(!"cSlotAreaTemporary: asking for more slots than actually stored!"); - return NULL; + return nullptr; } return &(itr->second[a_SlotNum]); @@ -2320,7 +2320,7 @@ cItem * cSlotAreaTemporary::GetPlayerSlots(cPlayer & a_Player) cItemMap::iterator itr = m_Items.find(a_Player.GetUniqueID()); if (itr == m_Items.end()) { - return NULL; + return nullptr; } return &(itr->second[0]); } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 802d0d219..1598dd3e7 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -33,7 +33,7 @@ cWindow::cWindow(WindowType a_WindowType, const AString & a_WindowTitle) : m_WindowTitle(a_WindowTitle), m_IsDestroyed(false), m_ShouldDistributeToHotbarFirst(true), - m_Owner(NULL) + m_Owner(nullptr) { if (a_WindowType == wtInventory) { @@ -105,10 +105,10 @@ const cItem * cWindow::GetSlot(cPlayer & a_Player, int a_SlotNum) const // Return the item at the specified slot for the specified player int LocalSlotNum = 0; const cSlotArea * Area = GetSlotArea(a_SlotNum, LocalSlotNum); - if (Area == NULL) + if (Area == nullptr) { - LOGWARNING("%s: requesting item from an invalid SlotArea (SlotNum %d), returning NULL.", __FUNCTION__, a_SlotNum); - return NULL; + LOGWARNING("%s: requesting item from an invalid SlotArea (SlotNum %d), returning nullptr.", __FUNCTION__, a_SlotNum); + return nullptr; } return Area->GetSlot(LocalSlotNum, a_Player); } @@ -122,7 +122,7 @@ void cWindow::SetSlot(cPlayer & a_Player, int a_SlotNum, const cItem & a_Item) // Set the item to the specified slot for the specified player int LocalSlotNum = 0; cSlotArea * Area = GetSlotArea(a_SlotNum, LocalSlotNum); - if (Area == NULL) + if (Area == nullptr) { LOGWARNING("%s: requesting write to an invalid SlotArea (SlotNum %d), ignoring.", __FUNCTION__, a_SlotNum); return; @@ -177,7 +177,7 @@ void cWindow::GetSlots(cPlayer & a_Player, cItems & a_Slots) const for (int i = 0; i < NumSlots; i++) { const cItem * Item = (*itr)->GetSlot(i, a_Player); - if (Item == NULL) + if (Item == nullptr) { a_Slots.push_back(cItem()); } @@ -311,7 +311,7 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) } cClientHandle * ClientHandle = a_Player.GetClientHandle(); - if (ClientHandle != NULL) + if (ClientHandle != nullptr) { ClientHandle->SendWindowClose(*this); } @@ -345,7 +345,7 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) void cWindow::OwnerDestroyed() { - m_Owner = NULL; + m_Owner = nullptr; // Close window for each player. Note that the last one needs special handling while (m_OpenedBy.size() > 1) { @@ -511,10 +511,10 @@ void cWindow::SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_Relativ void cWindow::Destroy(void) { - if (m_Owner != NULL) + if (m_Owner != nullptr) { m_Owner->CloseWindow(); - m_Owner = NULL; + m_Owner = nullptr; } m_IsDestroyed = true; } @@ -529,7 +529,7 @@ cSlotArea * cWindow::GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum) { LOGWARNING("%s: requesting an invalid SlotNum: %d out of %d slots", __FUNCTION__, a_GlobalSlotNum, GetNumSlots() - 1); ASSERT(!"Invalid SlotNum"); - return NULL; + return nullptr; } // Iterate through all the SlotAreas, find the correct one @@ -547,7 +547,7 @@ cSlotArea * cWindow::GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum) // We shouldn't be here - the check at the beginnning should prevent this. Log and assert LOGWARNING("%s: GetNumSlots() is out of sync: %d; LocalSlotNum = %d", __FUNCTION__, GetNumSlots(), LocalSlotNum); ASSERT(!"Invalid GetNumSlots"); - return NULL; + return nullptr; } @@ -560,7 +560,7 @@ const cSlotArea * cWindow::GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum { LOGWARNING("%s: requesting an invalid SlotNum: %d out of %d slots", __FUNCTION__, a_GlobalSlotNum, GetNumSlots() - 1); ASSERT(!"Invalid SlotNum"); - return NULL; + return nullptr; } // Iterate through all the SlotAreas, find the correct one @@ -578,7 +578,7 @@ const cSlotArea * cWindow::GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum // We shouldn't be here - the check at the beginnning should prevent this. Log and assert LOGWARNING("%s: GetNumSlots() is out of sync: %d; LocalSlotNum = %d", __FUNCTION__, GetNumSlots(), LocalSlotNum); ASSERT(!"Invalid GetNumSlots"); - return NULL; + return nullptr; } @@ -669,7 +669,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int { int LocalSlotNum = 0; cSlotArea * Area = GetSlotArea(*itr, LocalSlotNum); - if (Area == NULL) + if (Area == nullptr) { LOGWARNING("%s: Bad SlotArea for slot %d", __FUNCTION__, *itr); continue; @@ -836,7 +836,7 @@ void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Playe { m_RepairedItemName = a_Name; - if (a_Player != NULL) + if (a_Player != nullptr) { m_AnvilSlotArea->UpdateResult(*a_Player); } @@ -963,7 +963,7 @@ cChestWindow::cChestWindow(cChestEntity * a_Chest) : m_BlockY(a_Chest->GetPosY()), m_BlockZ(a_Chest->GetPosZ()), m_PrimaryChest(a_Chest), - m_SecondaryChest(NULL) + m_SecondaryChest(nullptr) { m_SlotAreas.push_back(new cSlotAreaChest(a_Chest, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); @@ -1014,7 +1014,7 @@ void cChestWindow::OpenedByPlayer(cPlayer & a_Player) cChunkDef::BlockToChunk(m_PrimaryChest->GetPosX(), m_PrimaryChest->GetPosZ(), ChunkX, ChunkZ); m_PrimaryChest->GetWorld()->MarkRedstoneDirty(ChunkX, ChunkZ); - if (m_SecondaryChest != NULL) + if (m_SecondaryChest != nullptr) { m_SecondaryChest->SetNumberOfPlayers(m_SecondaryChest->GetNumberOfPlayers() + 1); cChunkDef::BlockToChunk(m_SecondaryChest->GetPosX(), m_SecondaryChest->GetPosZ(), ChunkX, ChunkZ); @@ -1036,7 +1036,7 @@ bool cChestWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) cChunkDef::BlockToChunk(m_PrimaryChest->GetPosX(), m_PrimaryChest->GetPosZ(), ChunkX, ChunkZ); m_PrimaryChest->GetWorld()->MarkRedstoneDirty(ChunkX, ChunkZ); - if (m_SecondaryChest != NULL) + if (m_SecondaryChest != nullptr) { m_SecondaryChest->SetNumberOfPlayers(m_SecondaryChest->GetNumberOfPlayers() - 1); cChunkDef::BlockToChunk(m_SecondaryChest->GetPosX(), m_SecondaryChest->GetPosZ(), ChunkX, ChunkZ); diff --git a/src/UI/Window.h b/src/UI/Window.h index 26dd7f125..e62176d50 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -90,7 +90,7 @@ public: // tolua_begin - /// Returns the item at the specified slot for the specified player. Returns NULL if invalid SlotNum requested + /// Returns the item at the specified slot for the specified player. Returns nullptr if invalid SlotNum requested const cItem * GetSlot(cPlayer & a_Player, int a_SlotNum) const; /// Sets the item to the specified slot for the specified player @@ -189,13 +189,13 @@ protected: /** Returns the correct slot area for the specified window-global SlotNum Also returns the area-local SlotNum corresponding to the GlobalSlotNum - If the global SlotNum is out of range, returns NULL + If the global SlotNum is out of range, returns nullptr */ cSlotArea * GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum); /** Returns the correct slot area for the specified window-global SlotNum Also returns the area-local SlotNum corresponding to the GlobalSlotNum - If the global SlotNum is out of range, returns NULL. + If the global SlotNum is out of range, returns nullptr. Const version. */ const cSlotArea * GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum) const; diff --git a/src/UI/WindowOwner.h b/src/UI/WindowOwner.h index 6845a161b..4dc3cf080 100644 --- a/src/UI/WindowOwner.h +++ b/src/UI/WindowOwner.h @@ -22,7 +22,7 @@ class cWindowOwner { public: cWindowOwner() : - m_Window(NULL) + m_Window(nullptr) { } @@ -32,7 +32,7 @@ public: void CloseWindow(void) { - m_Window = NULL; + m_Window = nullptr; } void OpenWindow(cWindow * a_Window) -- cgit v1.2.3