| 1772 | bool AIUnit::CreateOperativePath() |
| 1773 | { |
| 1774 | EntityAI* veh = GetVehicle(); |
| 1775 | |
| 1776 | // new attempt |
| 1777 | if (_state == Delay && _delay <= Glob.time) |
| 1778 | { |
| 1779 | Verify(SetState(Wait)); |
| 1780 | return false; |
| 1781 | } |
| 1782 | |
| 1783 | if (_state != Init) |
| 1784 | { |
| 1785 | // check if current path is valid |
| 1786 | if (!VerifyPath()) |
| 1787 | { |
| 1788 | if (IsSubgroupLeader()) |
| 1789 | { |
| 1790 | Verify(SetState(Replan)); |
| 1791 | } |
| 1792 | else |
| 1793 | { |
| 1794 | Verify(SetState(Wait)); // clear plan |
| 1795 | } |
| 1796 | } |
| 1797 | // do not plan |
| 1798 | return false; |
| 1799 | } |
| 1800 | |
| 1801 | float combatHeight = veh->GetCombatHeight(); |
| 1802 | if (veh->GetType()->IsKindOf(GLOB_WORLD->Preloaded(VTypeAir)) || |
| 1803 | veh->GetType()->IsKindOf(GLOB_WORLD->Preloaded(VTypeShip))) |
| 1804 | { |
| 1805 | if (_mode == Exact) |
| 1806 | { |
| 1807 | _mode = DirectExact; |
| 1808 | } |
| 1809 | else if (_mode == Normal) |
| 1810 | { |
| 1811 | _mode = DirectNormal; |
| 1812 | } |
| 1813 | } |
| 1814 | if (_mode == DirectExact || _mode == DirectNormal) |
| 1815 | { |
| 1816 | // creates path from Position() to _expPosition if none in _planner |
| 1817 | CopyPath(*_planner); |
| 1818 | Verify(SetState(Busy)); |
| 1819 | return false; |
| 1820 | } |
| 1821 | else |
| 1822 | { |
| 1823 | float dist2 = (Position() - _expPosition).SquareSizeXZ(); |
| 1824 | if (dist2 < Square(DIST_NOT_SEARCH)) |
| 1825 | { |
| 1826 | if (_lastPlan) |
| 1827 | { |
| 1828 | float precision = veh->GetPrecision(); |
| 1829 | if (_wantedPosition.Distance(_plannedPosition) > Square(precision)) |
| 1830 | { |
| 1831 | ForceReplan(); |
nothing calls this directly
no test coverage detected