Author Topic: Bug in bool BattlescapeGame::findItem  (Read 1542 times)

Offline Xilmi

  • Moderator
  • Commander
  • ***
  • Posts: 642
    • View Profile
Bug in bool BattlescapeGame::findItem
« on: November 09, 2022, 10:36:36 pm »
The bug is that there is no validity check for when the unit wants to walk to pick up an item, which can cause an endless-loop.

So instead of:

Code: [Select]
        // if we're not standing on it, we should try to get to it.
action->target = targetItem->getTile()->getPosition();
action->type = BA_WALK;
walkToItem = true;
if (pickUpWeaponsMoreActively)
{
// don't end the turn after walking 1-2 tiles... pick up a weapon and shoot!
action->finalAction = false;
action->desperate = false;
action->actor->setHiding(false);
}

it should be something like:

Code: [Select]
// if we're not standing on it, we should try to get to it.
_save->getPathfinding()->calculate(action->actor, targetItem->getTile()->getPosition(), BAM_NORMAL);
if (_save->getPathfinding()->getStartDirection() != -1 && _save->getPathfinding()->getTotalTUCost() <= action->actor->getTimeUnits())
{
action->target = targetItem->getTile()->getPosition();
action->type = BA_WALK;
walkToItem = true;
if (pickUpWeaponsMoreActively)
{
// don't end the turn after walking 1-2 tiles... pick up a weapon and shoot!
action->finalAction = false;
action->desperate = false;
action->actor->setHiding(false);
}
}
« Last Edit: November 09, 2022, 10:38:12 pm by Xilmi »