-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhousetile.cpp
114 lines (100 loc) · 3.2 KB
/
housetile.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
#include "otpch.h"
#include "housetile.h"
#include "house.h"
#include "game.h"
#include "configmanager.h"
extern ConfigManager g_config;
extern Game g_game;
HouseTile::HouseTile(int32_t x, int32_t y, int32_t z, House* _house):
DynamicTile(x, y, z)
{
house = _house;
setFlag(TILESTATE_HOUSE);
}
void HouseTile::__addThing(Creature* actor, int32_t index, Thing* thing)
{
Tile::__addThing(actor, index, thing);
if(!thing->getParent())
return;
if(Item* item = thing->getItem())
updateHouse(item);
}
void HouseTile::__internalAddThing(uint32_t index, Thing* thing)
{
Tile::__internalAddThing(index, thing);
if(!thing->getParent())
return;
if(Item* item = thing->getItem())
updateHouse(item);
}
void HouseTile::updateHouse(Item* item)
{
if(item->getTile() != this)
return;
Door* door = item->getDoor();
if(door && door->getDoorId())
house->addDoor(door);
else if(BedItem* bed = item->getBed())
house->addBed(bed);
}
ReturnValue HouseTile::__queryAdd(int32_t index, const Thing* thing, uint32_t count, uint32_t flags) const
{
if(const Creature* creature = thing->getCreature())
{
if(const Player* player = creature->getPlayer())
{
if(!house->isInvited(player))
return RET_PLAYERISNOTINVITED;
}
else
return RET_NOTPOSSIBLE;
}
else if(thing->getItem())
{
const uint32_t itemLimit = g_config.getNumber(ConfigManager::ITEMLIMIT_HOUSETILE);
if(itemLimit && getThingCount() > itemLimit)
return RET_TILEISFULL;
}
return Tile::__queryAdd(index, thing, count, flags);
}
Cylinder* HouseTile::__queryDestination(int32_t& index, const Thing* thing, Item** destItem, uint32_t& flags)
{
if(const Creature* creature = thing->getCreature())
{
if(const Player* player = creature->getPlayer())
{
if(!house->isInvited(player) && !player->hasFlag(PlayerFlag_CanEditHouses))
{
Tile* destTile = g_game.getTile(house->getEntry());
if(!destTile)
{
std::cout << "[Error - HouseTile::__queryDestination] Tile at house entry position for house: "
<< house->getName() << " (" << house->getId() << ") does not exist." << std::endl;
destTile = g_game.getTile(player->getMasterPosition());
if(!destTile)
destTile = &(Tile::nullTile);
}
index = -1;
*destItem = NULL;
return destTile;
}
}
}
return Tile::__queryDestination(index, thing, destItem, flags);
}