Browse Source

Use crawl table based search for item checks

fixes #3207
pull/3431/head
ephphatha 4 years ago committed by Anders Jenbo
parent
commit
335b0b9349
  1. 17
      Source/inv.cpp
  2. 14
      Source/items.cpp

17
Source/inv.cpp

@ -1130,18 +1130,11 @@ bool PutItem(Player &player, Point &position)
if (CanPut(position))
return true;
for (int l = 1; l < 50; l++) {
for (int j = -l; j <= l; j++) {
int yp = j + player.position.tile.y;
for (int i = -l; i <= l; i++) {
int xp = i + player.position.tile.x;
if (!CanPut({ xp, yp }))
continue;
position = { xp, yp };
return true;
}
}
std::optional<Point> itemPosition = FindClosestValidPosition(CanPut, player.position.tile, 1, 50);
if (itemPosition) {
position = *itemPosition;
return true;
}
return false;

14
Source/items.cpp

@ -3229,19 +3229,9 @@ int AllocateItem()
Point GetSuperItemLoc(Point position)
{
for (int k = 1; k < 50; k++) {
for (int j = -k; j <= k; j++) {
for (int i = -k; i <= k; i++) {
Displacement offset = { i, j };
Point positionToCheck = position + offset;
if (ItemSpaceOk(positionToCheck)) {
return positionToCheck;
}
}
}
}
std::optional<Point> itemPosition = FindClosestValidPosition(ItemSpaceOk, position, 1, 50);
return { 0, 0 }; // TODO handle no space for dropping items
return itemPosition.value_or(Point { 0, 0 }); // TODO handle no space for dropping items
}
void GetItemAttrs(Item &item, int itemData, int lvl)

Loading…
Cancel
Save