From c7fb00085854ed76b8b8945968de0505b8fbe8a2 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 14 Feb 2014 17:38:22 +0200 Subject: EmptyMap item handler --- src/Items/ItemEmptyMap.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Items/ItemEmptyMap.h (limited to 'src/Items/ItemEmptyMap.h') diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h new file mode 100644 index 000000000..5516033a0 --- /dev/null +++ b/src/Items/ItemEmptyMap.h @@ -0,0 +1,46 @@ + +// ItemEmptyMap.h + + + + + +#pragma once + +#include "../Entities/Entity.h" +#include "../Item.h" + + + + + +class cItemEmptyMapHandler : + public cItemHandler +{ + typedef cItemHandler super; + +public: + cItemEmptyMapHandler() : + super(E_ITEM_EMPTY_MAP) + { + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + UNUSED(a_Item); + UNUSED(a_BlockX); + UNUSED(a_BlockZ); + UNUSED(a_Dir); + + // The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it. + + const int RegionWidth = cChunkDef::Width * 8; + + int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; + int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; + + a_World->CreateMap(CenterX, CenterZ, 0); + + return true; + } +} ; -- cgit v1.2.3 From cf96e69716e0ccd0657cf275720bb11b915361c4 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 15 Feb 2014 20:06:47 +0200 Subject: cMap::UpdateRadius --- src/Items/ItemEmptyMap.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Items/ItemEmptyMap.h') diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 5516033a0..24d31151b 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -18,6 +18,8 @@ class cItemEmptyMapHandler : public cItemHandler { typedef cItemHandler super; + + static const unsigned int DEFAULT_SCALE = 0; public: cItemEmptyMapHandler() : @@ -34,12 +36,12 @@ public: // The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it. - const int RegionWidth = cChunkDef::Width * 8; + const int RegionWidth = cChunkDef::Width * 8 * pow(2, DEFAULT_SCALE); int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; - a_World->CreateMap(CenterX, CenterZ, 0); + a_World->CreateMap(CenterX, CenterZ, DEFAULT_SCALE); return true; } -- cgit v1.2.3 From 3b24bc870bb39a8b8812ed307250e1188b9ff788 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 17 Feb 2014 16:27:12 +0200 Subject: Map item handler; Fixed several bugs --- src/Items/ItemEmptyMap.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/Items/ItemEmptyMap.h') diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 24d31151b..b06cf9d13 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -41,7 +41,21 @@ public: int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; - a_World->CreateMap(CenterX, CenterZ, DEFAULT_SCALE); + cMap * NewMap = a_World->CreateMap(CenterX, CenterZ, DEFAULT_SCALE); + + // Remove empty map from inventory + if (!a_Player->GetInventory().RemoveOneEquippedItem()) + { + ASSERT(!"Inventory mismatch"); + return true; + } + + if (NewMap == NULL) + { + return true; + } + + a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, NewMap->GetID()), true, true); return true; } -- cgit v1.2.3 From f47187394572027cbfa07884cba2f54eaa6972ec Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 23 Feb 2014 15:03:40 +0200 Subject: Maps: Improvements --- src/Items/ItemEmptyMap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items/ItemEmptyMap.h') diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index b06cf9d13..db28511f3 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -41,7 +41,7 @@ public: int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth; int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth; - cMap * NewMap = a_World->CreateMap(CenterX, CenterZ, DEFAULT_SCALE); + cMap * NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE); // Remove empty map from inventory if (!a_Player->GetInventory().RemoveOneEquippedItem()) -- cgit v1.2.3