MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / TargetBox

Function TargetBox

TombEngine/Game/control/box.cpp:1640–1658  ·  view source on GitHub ↗

* @brief Sets a box as the creature's navigation target. * * Generates a random position within the box boundaries as the target point. * This randomization prevents creatures from always going to the exact same * spot, making movement look more natural. * * Sets LOT->RequiredBox which triggers UpdateLOT to recalculate the path. * * @param LOT Pointer to the creature's LOTInfo. * @param b

Source from the content-addressed store, hash-verified

1638 * @param boxNumber The box to target.
1639 */
1640void TargetBox(LOTInfo* LOT, int boxNumber)
1641{
1642 if (boxNumber == NO_VALUE)
1643 return;
1644
1645 const auto* box = &g_Level.PathfindingBoxes[boxNumber];
1646
1647 // Generate random position within box bounds.
1648 // Maximize target precision. DO NOT change bracket precedence!
1649 LOT->Target.x = (int)((box->top * BLOCK(1)) + (float)GetRandomControl() * (((float)(box->bottom - box->top) - 1.0f) / 32.0f) + CLICK(2.0f));
1650 LOT->Target.z = (int)((box->left * BLOCK(1)) + (float)GetRandomControl() * (((float)(box->right - box->left) - 1.0f) / 32.0f) + CLICK(2.0f));
1651 LOT->RequiredBox = boxNumber;
1652
1653 // Flying creatures target slightly above the floor.
1654 if (LOT->Fly == NO_FLYING)
1655 LOT->Target.y = box->height;
1656 else
1657 LOT->Target.y = box->height - STEPUP_HEIGHT;
1658}
1659
1660/**
1661 * @brief Updates the pathfinding data when the target changes.

Callers 2

CreatureMoodFunction · 0.85
GetCreatureMoodFunction · 0.85

Calls 1

GetRandomControlFunction · 0.85

Tested by

no test coverage detected