swashed
Member
- Joined
- Jul 9, 2023
- Messages
- 92
- Reaction score
- 12
I have a pre-compiled server that has an "auto-stacking" function that works flawlessly. When I compile the sources, this feature is no longer working. I think the author made some last minute changes before compiling the release, and now I need it back in and working. Can somebody take a look at this code and tell me if they see anything that may be causing it to not work?
full function: Cylinder* Container::__queryDestination
It works when I move items from one container to another.
Doesn't work when I loot gold from a monster
Does not work when I conjure ammo/food
This seems to be exclusive to the AddItem function, which I found 2 of
It looks like the meat of this method is locked behind a !test bool, which is possibly whats preventing it from completing?
There is also this container AddItem function that doesn't seem to make use of __queryDestination
C++:
bool autoStack = g_config.getBoolean(ConfigManager::CONTAINER_ITEMS_AUTO_STACK);
if(autoStack){
if(item->isStackable()){
if(item->getParent() != this){
//try find a suitable item to stack with
uint32_t n = 0;
for(ItemList::iterator cit = itemlist.begin(); cit != itemlist.end(); ++cit){
if((*cit) != item && (*cit)->getID() == item->getID() && (*cit)->getItemCount() < 100){
*destItem = (*cit);
index = n;
return this;
}
++n;
}
}
}
}
Post automatically merged:
full function: Cylinder* Container::__queryDestination
C++:
Cylinder* Container::__queryDestination(int32_t& index, const Thing* thing, Item** destItem,
uint32_t& flags)
{
if(index == 254 /*move up*/){
index = INDEX_WHEREEVER;
*destItem = NULL;
Container* parentContainer = dynamic_cast<Container*>(getParent());
if(parentContainer)
return parentContainer;
return this;
}
if(index == 255 /*add wherever*/){
index = INDEX_WHEREEVER;
*destItem = NULL;
}
else if(index >= (int32_t)capacity()){
/*
if you have a container, maximize it to show all 20 slots
then you open a bag that is inside the container you will have a bag with 8 slots
and a "grey" area where the other 12 slots where from the container
if you drop the item on that grey area
the client calculates the slot position as if the bag has 20 slots
*/
index = INDEX_WHEREEVER;
*destItem = NULL;
}
const Item* item = thing->getItem();
if(item == NULL){
return this;
}
bool autoStack = g_config.getBoolean(ConfigManager::CONTAINER_ITEMS_AUTO_STACK);
if(autoStack){
if(item->isStackable()){
if(item->getParent() != this){
//try find a suitable item to stack with
uint32_t n = 0;
for(ItemList::iterator cit = itemlist.begin(); cit != itemlist.end(); ++cit){
if((*cit) != item && (*cit)->getID() == item->getID() && (*cit)->getItemCount() < 100){
*destItem = (*cit);
index = n;
return this;
}
++n;
}
}
}
}
if(index != INDEX_WHEREEVER){
Thing* destThing = __getThing(index);
if(destThing)
*destItem = destThing->getItem();
Cylinder* subCylinder = dynamic_cast<Cylinder*>(*destItem);
if(subCylinder){
index = INDEX_WHEREEVER;
*destItem = NULL;
return subCylinder;
}
}
return this;
}
Post automatically merged:
It works when I move items from one container to another.
Post automatically merged:
Doesn't work when I loot gold from a monster
Post automatically merged:
Does not work when I conjure ammo/food
Post automatically merged:
This seems to be exclusive to the AddItem function, which I found 2 of
C++:
ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t index /*= INDEX_WHEREEVER*/,
uint32_t flags /*= 0*/, bool test /*= false*/)
{
uint32_t remainderCount = 0;
return internalAddItem(toCylinder, item, index, flags, test, remainderCount);
}
Post automatically merged:
C++:
ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t index,
uint32_t flags, bool test, uint32_t& remainderCount)
{
remainderCount = 0;
if(toCylinder == NULL || item == NULL){
return RET_NOTPOSSIBLE;
}
Cylinder* origToCylinder = toCylinder;
Item* toItem = NULL;
toCylinder = toCylinder->__queryDestination(index, item, &toItem, flags);
//check if we can add this item
ReturnValue ret = toCylinder->__queryAdd(index, item, item->getItemCount(), flags);
if(ret != RET_NOERROR){
return ret;
}
/*
Check if we can move add the whole amount, we do this by checking against the original cylinder,
since the queryDestination can return a cylinder that might only hold a part of the full amount.
*/
uint32_t maxQueryCount = 0;
ret = origToCylinder->__queryMaxCount(INDEX_WHEREEVER, item, item->getItemCount(), maxQueryCount, flags);
if(ret != RET_NOERROR){
return ret;
}
if(!test){
if(item->isStackable() && toItem){
uint32_t n = 0;
uint32_t m = std::min((uint32_t)item->getItemCount(), maxQueryCount);
if(toItem->getID() == item->getID()){
n = std::min((uint32_t)100 - toItem->getItemCount(), m);
toCylinder->__updateThing(toItem, toItem->getID(), toItem->getItemCount() + n);
}
if(m - n > 0){
if(m - n != item->getItemCount()){
Item* remainderItem = Item::CreateItem(item->getID(), m - n);
if(internalAddItem(origToCylinder, remainderItem, INDEX_WHEREEVER, flags, false) != RET_NOERROR){
FreeThing(remainderItem);
remainderCount = m - n;
}
}
else{
toCylinder->__addThing(index, item);
int32_t itemIndex = toCylinder->__getIndexOfThing(item);
if(itemIndex != -1){
toCylinder->postAddNotification(item, NULL, itemIndex);
}
}
}
else{
//fully merged with toItem, item will be destroyed
item->onRemoved();
FreeThing(item);
}
}
else{
toCylinder->__addThing(index, item);
int32_t itemIndex = toCylinder->__getIndexOfThing(item);
if(itemIndex != -1){
toCylinder->postAddNotification(item, NULL, itemIndex);
}
}
}
return RET_NOERROR;
}
Post automatically merged:
It looks like the meat of this method is locked behind a !test bool, which is possibly whats preventing it from completing?
Post automatically merged:
There is also this container AddItem function that doesn't seem to make use of __queryDestination
C++:
void Container::addItem(Item* item)
{
itemlist.push_back(item);
item->setParent(this);
}
Last edited: