| 1668 | void AIUnit::OperPath(ThinkImportance prec) |
| 1669 | { |
| 1670 | EntityAI* veh = GetVehicle(); |
| 1671 | |
| 1672 | SetHouse(nullptr, -1); |
| 1673 | Vector3Val pos = Position(); |
| 1674 | float dist2; |
| 1675 | |
| 1676 | if (_state != Stopped && _state != Stopping && _state != Delay && _state != InCargo) |
| 1677 | { |
| 1678 | if (!_noPath) |
| 1679 | { // construct path by strategic plan |
| 1680 | int planIndex = _planner->FindBestIndex(pos); |
| 1681 | int minPlanIndex = planIndex; |
| 1682 | float precision = veh->GetPrecision(); |
| 1683 | bool onRoad = GRoadNet->IsOnRoad(pos, precision * 1.2) != nullptr; |
| 1684 | do |
| 1685 | { |
| 1686 | _lastPlan = _planner->GetPlanPosition(planIndex, _expPosition); |
| 1687 | |
| 1688 | dist2 = (_expPosition - pos).SquareSizeXZ(); |
| 1689 | if (dist2 >= Square(1.1 * precision)) |
| 1690 | // do not force target under vehicle's precision |
| 1691 | { |
| 1692 | FieldPassing::Mode planMode = _planner->GetPlanMode(planIndex); |
| 1693 | if (!onRoad) |
| 1694 | { |
| 1695 | if (planMode == FieldPassing::MoveOnRoad) |
| 1696 | { |
| 1697 | break; // move onto road |
| 1698 | } |
| 1699 | } |
| 1700 | else |
| 1701 | { |
| 1702 | if (planMode != FieldPassing::MoveOnRoad) |
| 1703 | { |
| 1704 | break; // move out of road |
| 1705 | } |
| 1706 | } |
| 1707 | } |
| 1708 | } while (dist2 < Square(DIST_MIN_OPER) && ++planIndex < _planner->GetPlanSize()); |
| 1709 | |
| 1710 | if (_iter == 1) |
| 1711 | { |
| 1712 | if (planIndex > minPlanIndex) |
| 1713 | { |
| 1714 | planIndex--; |
| 1715 | _lastPlan = _planner->GetPlanPosition(planIndex, _expPosition); |
| 1716 | } |
| 1717 | } |
| 1718 | else if (_iter == 2) |
| 1719 | { |
| 1720 | if (planIndex < _planner->GetPlanSize() - 1) |
| 1721 | { |
| 1722 | planIndex++; |
| 1723 | _lastPlan = _planner->GetPlanPosition(planIndex, _expPosition); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | saturateMin(planIndex, _planner->GetPlanSize() - 1); |
nothing calls this directly
no test coverage detected