* @brief Updates the pathfinding data when the target changes. * * When RequiredBox changes (new target selected), this function: * 1. Sets it as the new TargetBox. * 2. Adds it to the front of the search queue (Head). * 3. Increments SearchNumber to invalidate old search data. * 4. Calls SearchLOT to expand the search. * * The search works BACKWARDS from target to creature - each node's e
| 1674 | * @return true if search queue still has nodes to expand, false if exhausted. |
| 1675 | */ |
| 1676 | bool UpdateLOT(LOTInfo* LOT, int depth) |
| 1677 | { |
| 1678 | if (LOT->RequiredBox != NO_VALUE && LOT->RequiredBox != LOT->TargetBox) |
| 1679 | { |
| 1680 | // New target - reset search from this box. |
| 1681 | LOT->TargetBox = LOT->RequiredBox; |
| 1682 | |
| 1683 | auto* node = &LOT->Node[LOT->RequiredBox]; |
| 1684 | |
| 1685 | // Add target box to front of search queue. |
| 1686 | if (node->nextExpansion == NO_VALUE && LOT->Tail != LOT->RequiredBox) |
| 1687 | { |
| 1688 | node->nextExpansion = LOT->Head; |
| 1689 | |
| 1690 | if (LOT->Head == NO_VALUE) |
| 1691 | LOT->Tail = LOT->TargetBox; |
| 1692 | |
| 1693 | LOT->Head = LOT->TargetBox; |
| 1694 | } |
| 1695 | |
| 1696 | // New search number invalidates all previous search data. |
| 1697 | node->searchNumber = ++LOT->SearchNumber; |
| 1698 | node->exitBox = NO_VALUE; // Target has no exit (it IS the destination). |
| 1699 | node->cost = 0.0f; // Target box has zero cost. |
| 1700 | } |
| 1701 | |
| 1702 | return SearchLOT(LOT, depth); |
| 1703 | } |
| 1704 | |
| 1705 | bool SearchLOT(LOTInfo* LOT, int depth) |
| 1706 | { |
no test coverage detected