game.cpp, you should the whole function
[cpp]Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/)
{
if(item->getID() == newId && (newCount == -1 || (newCount == item->getSubType() && newCount != 0)))
return item;
Cylinder* cylinder = item->getParent();
if(!cylinder)
return NULL;
int32_t itemIndex = cylinder->__getIndexOfThing(item);
if(itemIndex == -1)
{
#ifdef __DEBUG__
std::cout << "Error: transformItem, itemIndex == -1" << std::endl;
#endif
return item;
}
if(!item->canTransform())
return item;
const ItemType& curType = Item::items[item->getID()];
const ItemType& newType = Item::items[newId];
if(curType.alwaysOnTop != newType.alwaysOnTop)
{
//This only occurs when you transform items on tiles from a downItem to a topItem (or vice versa)
//Remove the old, and add the new
ReturnValue ret = internalRemoveItem(NULL, item);
if(ret != RET_NOERROR)
return item;
Item* newItem = NULL;
if(newCount == -1)
newItem = Item::CreateItem(newId);
else
newItem = Item::CreateItem(newId, newCount);
newItem->copyAttributes(item);
if(internalAddItem(NULL, cylinder, newItem, INDEX_WHEREEVER, FLAG_NOLIMIT) == RET_NOERROR)
return newItem;
delete newItem;
return NULL;
}
if(curType.type == newType.type)
{
//Both items has the same type so we can safely change id/subtype
if(!newCount && (item->isStackable() || item->hasCharges()))
{
if(!item->isStackable() && (!item->getDefaultDuration() || item->getDuration() <= 0))
{
int32_t tmpId = newId;
if(curType.id == newType.id)
tmpId = curType.decayTo;
if(tmpId != -1)
{
item = transformItem(item, tmpId);
return item;
}
}
internalRemoveItem(NULL, item);
return NULL;
}
uint16_t itemId = item->getID();
int32_t count = item->getSubType();
cylinder->postRemoveNotification(NULL, item, cylinder, itemIndex, false);
if(curType.id != newType.id)
{
itemId = newId;
if(newType.group != curType.group)
item->setDefaultSubtype();
}
if(newCount != -1 && newType.hasSubType())
count = newCount;
cylinder->__updateThing(item, itemId, count);
cylinder->postAddNotification(NULL, item, cylinder, itemIndex);
return item;
}
//Replacing the the old item with the new while maintaining the old position
Item* newItem = NULL;
if(newCount == -1)
newItem = Item::CreateItem(newId);
else
newItem = Item::CreateItem(newId, newCount);
if(!newItem)
{
#ifdef __DEBUG__
std::cout << "Error: [Game::transformItem] Item of type " << item->getID() << " transforming into invalid type " << newId << std::endl;
#endif
return NULL;
}
cylinder->__replaceThing(itemIndex, newItem);
cylinder->postAddNotification(NULL, newItem, cylinder, itemIndex);
item->setParent(NULL);
cylinder->postRemoveNotification(NULL, item, cylinder, itemIndex, true);
FreeThing(item);
return newItem;
}[/cpp]
with
[cpp]Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/)
{
if(item->getID() == newId && (newCount == -1 || (newCount == item->getSubType() && newCount != 0)))
return item;
Cylinder* cylinder = item->getParent();
if(!cylinder)
return NULL;
int32_t itemIndex = cylinder->__getIndexOfThing(item);
if(itemIndex == -1)
{
#ifdef __DEBUG__
std::cout << "Error: transformItem, itemIndex == -1" << std::endl;
#endif
return item;
}
if(!item->canTransform())
return item;
const ItemType& curType = Item::items[item->getID()];
const ItemType& newType = Item::items[newId];
if(curType.alwaysOnTop != newType.alwaysOnTop)
{
//This only occurs when you transform items on tiles from a downItem to a topItem (or vice versa)
//Remove the old, and add the new
ReturnValue ret = internalRemoveItem(NULL, item);
if(ret != RET_NOERROR)
return item;
Item* newItem = NULL;
if(newCount == -1)
newItem = Item::CreateItem(newId);
else
newItem = Item::CreateItem(newId, newCount);
if(!newItem)
return NULL;
newItem->copyAttributes(item);
if(internalAddItem(NULL, cylinder, newItem, INDEX_WHEREEVER, FLAG_NOLIMIT) == RET_NOERROR)
return newItem;
delete newItem;
return NULL;
}
if(!newCount && (item->isStackable() || item->hasCharges()))
{
if(!item->isStackable() && (!item->getDefaultDuration() || item->getDuration() <= 0))
{
int32_t tmpId = newId;
if(curType.id == newType.id)
tmpId = curType.decayTo;
if(tmpId != -1)
{
item = transformItem(item, tmpId);
return item;
}
}
internalRemoveItem(NULL, item);
return NULL;
}
uint16_t itemId = item->getID();
int32_t count = item->getSubType();
if(curType.id != newType.id)
{
itemId = newId;
if(newType.group != curType.group)
item->setDefaultSubtype();
}
if(newCount != -1 && newType.hasSubType())
count = newCount;
if(curType.type != newType.type && (curType.type == ITEM_TYPE_CONTAINER || newType.type == ITEM_TYPE_CONTAINER)) {
internalRemoveItem(NULL, item);
Item* newItem = NULL;
if(count == -1)
newItem = Item::CreateItem(newId);
else
newItem = Item::CreateItem(newId, newCount);
if(!newItem)
return NULL;
if(internalAddItem(NULL, cylinder, newItem, INDEX_WHEREEVER, FLAG_NOLIMIT) == RET_NOERROR)
return newItem;
delete newItem;
return NULL;
}
cylinder->postRemoveNotification(NULL, item, cylinder, itemIndex, false);
cylinder->__updateThing(item, itemId, count);
cylinder->postAddNotification(NULL, item, cylinder, itemIndex);
return item;
}[/cpp]