blob: 9536733826416601b02438b3d603c514c95ac0c8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// ItemEmptyMap.h
#pragma once
#include "../Entities/Entity.h"
#include "../Item.h"
class cItemEmptyMapHandler :
public cItemHandler
{
typedef cItemHandler super;
static const unsigned int DEFAULT_SCALE = 0;
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 = (int)(floor(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth);
int CenterZ = (int)(floor(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth);
cMap * NewMap = a_World->GetMapManager().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, (short)(NewMap->GetID() & 0x7fff)), true, true);
return true;
}
} ;
|