2012-06-29 16:44:26 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
// This file is part of Remere's Map Editor
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2020-07-30 11:42:28 -03:00
|
|
|
// Remere's Map Editor is free software: you can redistribute it and/or modify
|
2012-06-29 16:44:26 +02:00
|
|
|
// 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.
|
2016-09-29 19:24:45 -03:00
|
|
|
//
|
2020-07-30 11:42:28 -03:00
|
|
|
// Remere's Map Editor is distributed in the hope that it will be useful,
|
2012-06-29 16:44:26 +02:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2020-07-30 11:42:28 -03:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-29 16:44:26 +02:00
|
|
|
// GNU General Public License for more details.
|
2016-09-29 19:24:45 -03:00
|
|
|
//
|
2012-06-29 16:44:26 +02:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2020-07-30 11:42:28 -03:00
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-06-29 16:44:26 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
|
#include "brush.h"
|
|
|
|
|
#include "graphics.h"
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
#include "tile.h"
|
|
|
|
|
#include "complexitem.h"
|
|
|
|
|
#include "iomap.h"
|
|
|
|
|
#include "item.h"
|
|
|
|
|
|
|
|
|
|
#include "ground_brush.h"
|
|
|
|
|
#include "carpet_brush.h"
|
|
|
|
|
#include "table_brush.h"
|
|
|
|
|
#include "wall_brush.h"
|
|
|
|
|
|
2023-01-25 23:45:36 -03:00
|
|
|
Item* Item::Create(uint16_t id, uint16_t subtype /*= 0xFFFF*/)
|
2012-06-29 16:44:26 +02:00
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
if(id == 0) return nullptr;
|
|
|
|
|
|
|
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.id == 0) {
|
|
|
|
|
return newd Item(id, subtype);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(type.isDepot()) {
|
|
|
|
|
return new Depot(id);
|
|
|
|
|
} else if(type.isContainer()) {
|
|
|
|
|
return new Container(id);
|
|
|
|
|
} else if(type.isTeleport()) {
|
|
|
|
|
return new Teleport(id);
|
|
|
|
|
} else if(type.isDoor()) {
|
|
|
|
|
return new Door(id);
|
|
|
|
|
} else if(subtype == 0xFFFF) {
|
|
|
|
|
if(type.isFluidContainer()) {
|
|
|
|
|
return new Item(id, LIQUID_NONE);
|
|
|
|
|
} else if(type.isSplash()) {
|
|
|
|
|
return new Item(id, LIQUID_WATER);
|
|
|
|
|
} else if(type.charges > 0) {
|
|
|
|
|
return new Item(id, type.charges);
|
2012-06-29 16:44:26 +02:00
|
|
|
} else {
|
2023-01-25 23:45:36 -03:00
|
|
|
return new Item(id, 1);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-25 23:45:36 -03:00
|
|
|
return new Item(id, subtype);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item::Item(unsigned short _type, unsigned short _count) :
|
|
|
|
|
id(_type),
|
|
|
|
|
subtype(1),
|
2016-11-09 12:17:17 -03:00
|
|
|
selected(false),
|
|
|
|
|
frame(0)
|
2012-06-29 16:44:26 +02:00
|
|
|
{
|
|
|
|
|
if(hasSubtype()) {
|
|
|
|
|
subtype = _count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item::~Item()
|
|
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item* Item::deepCopy() const
|
|
|
|
|
{
|
|
|
|
|
Item* copy = Create(id, subtype);
|
2015-12-06 11:42:37 -03:00
|
|
|
if(copy) {
|
2012-06-29 16:44:26 +02:00
|
|
|
copy->selected = selected;
|
|
|
|
|
if(attributes)
|
|
|
|
|
copy->attributes = newd ItemAttributeMap(*attributes);
|
|
|
|
|
}
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item* transformItem(Item* old_item, uint16_t new_id, Tile* parent)
|
|
|
|
|
{
|
2014-01-22 20:16:17 +01:00
|
|
|
if(old_item == nullptr)
|
|
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
old_item->setID(new_id);
|
|
|
|
|
// Through the magic of deepCopy, this will now be a pointer to an item of the correct type.
|
|
|
|
|
Item* new_item = old_item->deepCopy();
|
2015-12-06 11:42:37 -03:00
|
|
|
if(parent) {
|
2012-06-29 16:44:26 +02:00
|
|
|
// Find the old item and remove it from the tile, insert this one instead!
|
2015-12-06 11:42:37 -03:00
|
|
|
if(old_item == parent->ground) {
|
2012-06-29 16:44:26 +02:00
|
|
|
delete old_item;
|
|
|
|
|
parent->ground = new_item;
|
|
|
|
|
return new_item;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-30 18:27:02 +02:00
|
|
|
std::queue<Container*> containers;
|
2015-12-06 11:42:37 -03:00
|
|
|
for(ItemVector::iterator item_iter = parent->items.begin(); item_iter != parent->items.end(); ++item_iter) {
|
|
|
|
|
if(*item_iter == old_item) {
|
2012-06-29 16:44:26 +02:00
|
|
|
delete old_item;
|
|
|
|
|
item_iter = parent->items.erase(item_iter);
|
|
|
|
|
parent->items.insert(item_iter, new_item);
|
|
|
|
|
return new_item;
|
|
|
|
|
}
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2012-06-30 18:27:02 +02:00
|
|
|
Container* c = dynamic_cast<Container*>(*item_iter);
|
2015-12-06 11:42:37 -03:00
|
|
|
if(c)
|
2012-06-30 18:27:02 +02:00
|
|
|
containers.push(c);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
while(containers.size() != 0) {
|
2012-06-30 18:27:02 +02:00
|
|
|
Container* container = containers.front();
|
|
|
|
|
ItemVector& v = container->getVector();
|
2015-12-06 11:42:37 -03:00
|
|
|
for(ItemVector::iterator item_iter = v.begin(); item_iter != v.end(); ++item_iter) {
|
2012-06-30 18:27:02 +02:00
|
|
|
Item* i = *item_iter;
|
|
|
|
|
Container* c = dynamic_cast<Container*>(i);
|
|
|
|
|
if(c)
|
|
|
|
|
containers.push(c);
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
if(i == old_item) {
|
2012-06-30 18:27:02 +02:00
|
|
|
// Found it!
|
|
|
|
|
item_iter = v.erase(item_iter);
|
|
|
|
|
v.insert(item_iter, new_item);
|
|
|
|
|
return new_item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
containers.pop();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
2012-06-30 18:27:02 +02:00
|
|
|
|
|
|
|
|
delete new_item;
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-28 22:34:25 +01:00
|
|
|
uint32_t Item::memsize() const
|
2012-06-29 16:44:26 +02:00
|
|
|
{
|
2014-02-28 22:34:25 +01:00
|
|
|
uint32_t mem = sizeof(*this);
|
2012-06-29 16:44:26 +02:00
|
|
|
return mem;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 23:45:36 -03:00
|
|
|
void Item::setID(uint16_t new_id)
|
2015-12-06 11:42:37 -03:00
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
id = new_id;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 23:45:36 -03:00
|
|
|
void Item::setSubtype(uint16_t _subtype)
|
2012-06-29 16:44:26 +02:00
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
subtype = _subtype;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Item::hasSubtype() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
return (type.isFluidContainer()
|
|
|
|
|
|| type.stackable
|
|
|
|
|
|| type.charges != 0
|
|
|
|
|
|| type.isSplash()
|
|
|
|
|
|| isCharged());
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t Item::getSubtype() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
return hasSubtype() ? subtype : 0;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Item::hasProperty(enum ITEMPROPERTY prop) const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
switch(prop) {
|
2012-06-29 16:44:26 +02:00
|
|
|
case BLOCKSOLID:
|
2023-01-25 23:45:36 -03:00
|
|
|
if(type.unpassable)
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MOVEABLE:
|
2023-01-25 23:45:36 -03:00
|
|
|
if(type.moveable && getUniqueID() == 0)
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
break;
|
|
|
|
|
/*
|
|
|
|
|
case HASHEIGHT:
|
|
|
|
|
if(it.height != 0 )
|
|
|
|
|
return true;
|
|
|
|
|
break;
|
|
|
|
|
*/
|
|
|
|
|
case BLOCKPROJECTILE:
|
2023-01-25 23:45:36 -03:00
|
|
|
if(type.blockMissiles)
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BLOCKPATHFIND:
|
2023-01-25 23:45:36 -03:00
|
|
|
if(type.blockPathfinder)
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
break;
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2017-05-19 15:19:10 -03:00
|
|
|
case HOOK_SOUTH:
|
2023-01-25 23:45:36 -03:00
|
|
|
if(type.hookSouth)
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
break;
|
|
|
|
|
|
2017-05-19 15:19:10 -03:00
|
|
|
case HOOK_EAST:
|
2023-01-25 23:45:36 -03:00
|
|
|
if(type.hookEast)
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BLOCKINGANDNOTMOVEABLE:
|
2023-01-25 23:45:36 -03:00
|
|
|
if(type.unpassable && (!type.moveable || getUniqueID() != 0))
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
break;
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 23:15:42 -03:00
|
|
|
wxPoint Item::getDrawOffset() const
|
2015-12-06 11:42:37 -03:00
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.sprite) {
|
|
|
|
|
return type.sprite->getDrawOffset();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2023-01-25 23:15:42 -03:00
|
|
|
return wxPoint(0, 0);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-27 09:09:14 -03:00
|
|
|
uint16_t Item::getGroundSpeed() const
|
|
|
|
|
{
|
|
|
|
|
const auto& type = g_items.getItemType(id);
|
|
|
|
|
if(type.sprite) {
|
|
|
|
|
return type.sprite->ground_speed;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 16:47:45 -03:00
|
|
|
bool Item::hasLight() const
|
|
|
|
|
{
|
|
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.sprite) {
|
|
|
|
|
return type.sprite->hasLight();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SpriteLight Item::getLight() const
|
|
|
|
|
{
|
|
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.sprite) {
|
|
|
|
|
return type.sprite->getLight();
|
|
|
|
|
}
|
|
|
|
|
return SpriteLight{0, 0};
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
double Item::getWeight() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.stackable) {
|
|
|
|
|
return type.weight * std::max(1, (int)subtype);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2023-01-25 23:45:36 -03:00
|
|
|
return type.weight;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Item::setUniqueID(unsigned short n)
|
|
|
|
|
{
|
|
|
|
|
setAttribute("uid", n);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
void Item::setActionID(unsigned short n)
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
setAttribute("aid", n);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
void Item::setText(const std::string& str)
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
setAttribute("text", str);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
void Item::setDescription(const std::string& str)
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
setAttribute("desc", str);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
double Item::getWeight()
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.isStackable()) {
|
|
|
|
|
return type.weight * subtype;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2023-01-25 23:45:36 -03:00
|
|
|
return type.weight;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
bool Item::canHoldText() const
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
return isReadable() || canWriteText();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
bool Item::canHoldDescription() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
return g_items.getItemType(id).allowDistRead;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
uint8_t Item::getMiniMapColor() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
GameSprite* sprite = g_items.getItemType(id).sprite;
|
|
|
|
|
if(sprite) {
|
|
|
|
|
return sprite->getMiniMapColor();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
GroundBrush* Item::getGroundBrush() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.isGroundTile() && type.brush && type.brush->isGround()) {
|
|
|
|
|
return type.brush->asGround();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2016-11-12 10:30:06 -03:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
TableBrush* Item::getTableBrush() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.isTable && type.brush && type.brush->isTable()) {
|
|
|
|
|
return type.brush->asTable();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2016-11-12 10:30:06 -03:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
CarpetBrush* Item::getCarpetBrush() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.isCarpet && type.brush && type.brush->isCarpet()) {
|
|
|
|
|
return type.brush->asCarpet();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2016-11-12 10:30:06 -03:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
DoorBrush* Item::getDoorBrush() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(!type.isWall || !type.isBrushDoor || !type.brush || !type.brush->isWall()) {
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2016-11-12 10:30:06 -03:00
|
|
|
|
2023-01-25 23:45:36 -03:00
|
|
|
DoorType door_type = type.brush->asWall()->getDoorTypeFromID(id);
|
2016-11-12 10:30:06 -03:00
|
|
|
DoorBrush* door_brush = nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
// Quite a horrible dependency on a global here, meh.
|
2016-11-12 10:30:06 -03:00
|
|
|
switch(door_type) {
|
2012-06-29 16:44:26 +02:00
|
|
|
case WALL_DOOR_NORMAL: {
|
2016-11-12 10:30:06 -03:00
|
|
|
door_brush = g_gui.normal_door_brush;
|
2016-01-17 08:12:13 -03:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
case WALL_DOOR_LOCKED: {
|
2016-11-12 10:30:06 -03:00
|
|
|
door_brush = g_gui.locked_door_brush;
|
2016-01-17 08:12:13 -03:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
case WALL_DOOR_QUEST: {
|
2016-11-12 10:30:06 -03:00
|
|
|
door_brush = g_gui.quest_door_brush;
|
2016-01-17 08:12:13 -03:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
case WALL_DOOR_MAGIC: {
|
2016-11-12 10:30:06 -03:00
|
|
|
door_brush = g_gui.magic_door_brush;
|
2016-01-17 08:12:13 -03:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
case WALL_WINDOW: {
|
2016-11-12 10:30:06 -03:00
|
|
|
door_brush = g_gui.window_door_brush;
|
2016-01-17 08:12:13 -03:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
case WALL_HATCH_WINDOW: {
|
2016-11-12 10:30:06 -03:00
|
|
|
door_brush = g_gui.hatch_door_brush;
|
2016-01-17 08:12:13 -03:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
default: {
|
2016-01-17 08:12:13 -03:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2016-11-12 10:30:06 -03:00
|
|
|
return door_brush;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
WallBrush* Item::getWallBrush() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(type.isWall && type.brush && type.brush->isWall())
|
|
|
|
|
return type.brush->asWall();
|
2016-11-12 10:30:06 -03:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
BorderType Item::getWallAlignment() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
if(!type.isWall) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return BORDER_NONE;
|
|
|
|
|
}
|
2023-01-25 23:45:36 -03:00
|
|
|
return type.border_alignment;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
BorderType Item::getBorderAlignment() const
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
|
|
|
|
return type.border_alignment;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-09 12:17:17 -03:00
|
|
|
void Item::animate()
|
|
|
|
|
{
|
2023-01-25 23:45:36 -03:00
|
|
|
const ItemType& type = g_items.getItemType(id);
|
2016-11-09 12:17:17 -03:00
|
|
|
GameSprite* sprite = type.sprite;
|
|
|
|
|
if(!sprite || !sprite->animator)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
frame = sprite->animator->getFrame();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
// ============================================================================
|
|
|
|
|
// Static conversions
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
std::string Item::LiquidID2Name(uint16_t id)
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
switch(id) {
|
|
|
|
|
case LIQUID_NONE: return "None";
|
|
|
|
|
case LIQUID_WATER: return "Water";
|
|
|
|
|
case LIQUID_BLOOD: return "Blood";
|
|
|
|
|
case LIQUID_BEER: return "Beer";
|
|
|
|
|
case LIQUID_SLIME: return "Slime";
|
|
|
|
|
case LIQUID_LEMONADE: return "Lemonade";
|
|
|
|
|
case LIQUID_MILK: return "Milk";
|
|
|
|
|
case LIQUID_MANAFLUID: return "Manafluid";
|
|
|
|
|
case LIQUID_WATER2: return "Water";
|
|
|
|
|
case LIQUID_LIFEFLUID: return "Lifefluid";
|
|
|
|
|
case LIQUID_OIL: return "Oil";
|
|
|
|
|
case LIQUID_SLIME2: return "Slime";
|
|
|
|
|
case LIQUID_URINE: return "Urine";
|
|
|
|
|
case LIQUID_COCONUT_MILK: return "Coconut Milk";
|
|
|
|
|
case LIQUID_WINE: return "Wine";
|
|
|
|
|
case LIQUID_MUD: return "Mud";
|
|
|
|
|
case LIQUID_FRUIT_JUICE: return "Fruit Juice";
|
|
|
|
|
case LIQUID_LAVA: return "Lava";
|
|
|
|
|
case LIQUID_RUM: return "Rum";
|
|
|
|
|
case LIQUID_SWAMP: return "Swamp";
|
2021-04-28 23:55:47 -03:00
|
|
|
case LIQUID_INK: return "Ink";
|
|
|
|
|
case LIQUID_TEA: return "Tea";
|
|
|
|
|
case LIQUID_MEAD: return "Mead";
|
2012-06-29 16:44:26 +02:00
|
|
|
default: return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
uint16_t Item::LiquidName2ID(std::string liquid)
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
to_lower_str(liquid);
|
|
|
|
|
if(liquid == "none") return LIQUID_NONE;
|
|
|
|
|
if(liquid == "water") return LIQUID_WATER;
|
|
|
|
|
if(liquid == "blood") return LIQUID_BLOOD;
|
|
|
|
|
if(liquid == "beer") return LIQUID_BEER;
|
|
|
|
|
if(liquid == "slime") return LIQUID_SLIME;
|
|
|
|
|
if(liquid == "lemonade") return LIQUID_LEMONADE;
|
|
|
|
|
if(liquid == "milk") return LIQUID_MILK;
|
|
|
|
|
if(liquid == "manafluid") return LIQUID_MANAFLUID;
|
|
|
|
|
if(liquid == "lifefluid") return LIQUID_LIFEFLUID;
|
|
|
|
|
if(liquid == "oil") return LIQUID_OIL;
|
|
|
|
|
if(liquid == "urine") return LIQUID_URINE;
|
|
|
|
|
if(liquid == "coconut milk") return LIQUID_COCONUT_MILK;
|
|
|
|
|
if(liquid == "wine") return LIQUID_WINE;
|
|
|
|
|
if(liquid == "mud") return LIQUID_MUD;
|
|
|
|
|
if(liquid == "fruit juice") return LIQUID_FRUIT_JUICE;
|
|
|
|
|
if(liquid == "lava") return LIQUID_LAVA;
|
|
|
|
|
if(liquid == "rum") return LIQUID_RUM;
|
|
|
|
|
if(liquid == "swamp") return LIQUID_SWAMP;
|
2021-04-28 23:55:47 -03:00
|
|
|
if(liquid == "ink") return LIQUID_INK;
|
|
|
|
|
if(liquid == "tea") return LIQUID_TEA;
|
|
|
|
|
if(liquid == "mead") return LIQUID_MEAD;
|
2012-06-29 16:44:26 +02:00
|
|
|
return LIQUID_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// XML Saving & loading
|
|
|
|
|
|
2014-01-22 20:16:17 +01:00
|
|
|
Item* Item::Create(pugi::xml_node xml)
|
|
|
|
|
{
|
|
|
|
|
pugi::xml_attribute attribute;
|
|
|
|
|
|
2022-04-03 03:08:54 +02:00
|
|
|
uint16_t id = 0;
|
2015-12-06 11:42:37 -03:00
|
|
|
if((attribute = xml.attribute("id"))) {
|
2021-06-06 23:45:46 -03:00
|
|
|
id = attribute.as_ushort();
|
2014-01-22 20:16:17 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-03 03:08:54 +02:00
|
|
|
uint16_t count = 1;
|
2015-12-06 11:42:37 -03:00
|
|
|
if((attribute = xml.attribute("count")) || (attribute = xml.attribute("subtype"))) {
|
2021-06-06 23:45:46 -03:00
|
|
|
count = attribute.as_ushort();
|
2014-01-22 20:16:17 +01:00
|
|
|
}
|
|
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
return Create(id, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|