//////////////////////////////////////////////////////////////////////// // 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 . //////////////////////////////////////////////////////////////////////// #include "otpch.h" #include "housetile.h" #include "house.h" #include "game.h" extern Game g_game; HouseTile::HouseTile(int32_t x, int32_t y, int32_t z, House* _house): Tile(x, y, z) { house = _house; setFlag(TILESTATE_HOUSE); } HouseTile::~HouseTile() { // } void HouseTile::__addThing(Creature* actor, int32_t index, Thing* thing) { Tile::__addThing(actor, index, thing); if(Item* item = thing->getItem()) updateHouse(item); } void HouseTile::__internalAddThing(uint32_t index, Thing* thing) { Tile::__internalAddThing(index, thing); if(Item* item = thing->getItem()) updateHouse(item); } void HouseTile::updateHouse(Item* item) { if(item->getTile() == this) { Door* door = item->getDoor(); if(door && door->getDoorId() != 0) 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) && !player->hasFlag(PlayerFlag_CanEditHouses)) return RET_PLAYERISNOTINVITED; } } 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->getEntryPosition()); if(!destTile) { #ifdef __DEBUG__ assert(destTile != NULL); #endif std::cout << "[Error - HouseTile::__queryDestination] Tile at house entry position for house: " << house->getName() << " (" << house->getHouseId() << ") does not exist." << std::endl; destTile = g_game.getTile(player->getTemplePosition()); if(!destTile) destTile = &(Tile::nullTile); } index = -1; *destItem = NULL; return destTile; } } } return Tile::__queryDestination(index, thing, destItem, flags); }