| 1816 | } |
| 1817 | } |
| 1818 | return nullptr; |
| 1819 | } |
| 1820 | |
| 1821 | #define ROAD_DIAGS 0 |
| 1822 | #define HOUSE_DIAGS 0 |
| 1823 | |
| 1824 | #define DIST_NOT_SEARCH 5.0F |
| 1825 | |
| 1826 | bool AIUnit::CreatePath(Vector3Val from, Vector3Val to) |
| 1827 | { |
| 1828 | // this function always sets path.time to time of last search |
| 1829 | _path.SetSearchTime(Glob.time); |
| 1830 | const IPaths* fromBuilding = InsideBuilding(from); |
| 1831 | const IPaths* toBuilding = _house ? _house->GetIPaths() : InsideBuilding(to); |
| 1832 | EntityAI* veh = GetVehicle(); |
| 1833 | float combatHeight = veh->GetCombatHeight(); |
| 1834 | if (IsFreeSoldier() && (fromBuilding || toBuilding)) |
| 1835 | { |
| 1836 | // how much slower should units move in buildings |
| 1837 | if (fromBuilding == toBuilding) |
| 1838 | { |
| 1839 | #if HOUSE_DIAGS |
| 1840 | LOG_DEBUG(AI, "{}: fromTo {}", (const char*)GetDebugName(), |
| 1841 | (const char*)toBuilding->GetObject()->GetDebugName()); |
| 1842 | #endif |
| 1843 | Vector3 dummy; |
| 1844 | int posFrom = fromBuilding->FindNearestPoint(from - Vector3(0, combatHeight, 0), dummy); |
| 1845 | if (posFrom < 0) |
| 1846 | { |
| 1847 | return false; |
| 1848 | } |
| 1849 | int posTo = _house ? toBuilding->GetPos(_housePos) : toBuilding->FindNearestPoint(to, dummy); |
| 1850 | if (posTo < 0) |
| 1851 | { |
| 1852 | posTo = toBuilding->GetPos(0); |
| 1853 | if (posTo < 0) |
| 1854 | { |
| 1855 | return false; |
| 1856 | } |
| 1857 | } |
| 1858 | HOUSE_PATH_ARRAY(path, 64); |
| 1859 | |
| 1860 | if (!fromBuilding->SearchPath(posFrom, posTo, path)) |
| 1861 | { |
| 1862 | return false; // cannot get outside - failed |
| 1863 | } |
| 1864 | int n = path.Size(); |
| 1865 | _path.Resize(n); |
| 1866 | float cost = 0; |
| 1867 | Vector3 lastPos = path[0].pos; |
| 1868 | _path[0]._pos = lastPos; |
| 1869 | _path[0]._pos[1] += combatHeight; |
| 1870 | _path[0]._cost = cost; |
| 1871 | _path[0]._house = const_cast<Object*>(fromBuilding->GetObject()); |
| 1872 | _path[0]._index = path[0].index; |
| 1873 | for (int i = 1; i < n; i++) |
| 1874 | { |
| 1875 | cost += fromBuilding->GetBType()->GetCoefInside() * path[i].pos.Distance(lastPos) * |
nothing calls this directly
no test coverage detected