* @brief Marks a pathfinding box as temporarily invalid ("bad") for the creature. * * This function records a box that the creature has failed to traverse * (e.g. due to collision, invalid height/zone, or clipping against geometry). * Bad boxes are used by the pathfinding system to prevent repeatedly attempting * the same failing overlap and getting stuck. * * Every creature can track a lim
| 552 | * @param boxNumber Pathfinding box to mark as bad. Ignored if NO_VALUE. |
| 553 | */ |
| 554 | static void AddBadBox(LOTInfo* LOT, int boxNumber) |
| 555 | { |
| 556 | if (boxNumber == NO_VALUE) |
| 557 | return; |
| 558 | |
| 559 | // Don't add bad boxes if penalty system is disabled. |
| 560 | if (g_GameFlow->GetSettings()->Pathfinding.CollisionPenaltyThreshold <= EPSILON) |
| 561 | return; |
| 562 | |
| 563 | // Check if bad box is already memorized. |
| 564 | for (auto& badBox : LOT->BadBoxes) |
| 565 | { |
| 566 | if (badBox.BoxNumber == boxNumber) |
| 567 | { |
| 568 | if (badBox.Count >= 0 && !badBox.Valid) |
| 569 | { |
| 570 | badBox.Valid = true; |
| 571 | badBox.Count++; |
| 572 | } |
| 573 | |
| 574 | return; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | // Find an empty slot to store the bad box. |
| 579 | for (auto& badBox : LOT->BadBoxes) |
| 580 | { |
| 581 | if (badBox.BoxNumber != NO_VALUE) |
| 582 | continue; |
| 583 | |
| 584 | badBox.Valid = true; |
| 585 | badBox.BoxNumber = boxNumber; |
| 586 | badBox.Count = 1; |
| 587 | return; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * @brief Checks if a pathfinding box is bad and currently in cooldown. |
no test coverage detected