There are 3 different flags which determine where an item sits on a tile.
This is what is in my notes.
Code:
Ok, set of rules comes too:
1. We use the item on the tile which has the highest value in "Orders"
2. We ignore players when doing this..
3. Anything with a "topitem" or so flag breaks rule 1. These items are always the ones used
4. Doors, archyways, etc break rule 1. The will have highest order but still cannot be used unless they are the only thing on the tile. Guessing its another dat flag
Rule 3 is triggered by the Top_Order_2 flag
Rule 4 is triggered by the Top_Order_3 flag
stack == 0-index of the item on the tile
Undetermined: the rule for the "Top_Order_1" flag
Actual Code
Code:
int tMap::getTileTopItemIndex(tTile* tile, bool includeCreatures)
{
int highestOrder = -1;
int tileIndex = -1;
for (int stack = 0; stack < tile->count; stack++)
{
if (tile->items[stack].id > 99 || (includeCreatures && tile->items[stack].id == 99)) //we need to look at this... could be causing debugs letting id 99 through
{
if (tibiaClient::checkItemFlag(tile->items[stack].id, Consts::ITEM_FLAG_ALWAYSUSE) == 1)
{
tileIndex = stack;
break;
}
else if (stack == 1 && tile->count == 2 && tibiaClient::checkItemFlag(tile->items[stack].id, Consts::ITEM_FLAG_USEIFONLY) == 1)
{
tileIndex = stack;
break;
}
else if ((int)tile->orders[stack] > highestOrder && tibiaClient::checkItemFlag(tile->items[stack].id, Consts::ITEM_FLAG_USEIFONLY) == 0)
{
highestOrder = (int)tile->orders[stack];
tileIndex = stack;
}
}
}
return tileIndex;
}