MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / FindNearestEmpty

Method FindNearestEmpty

engine/Poseidon/AI/AIUnit.cpp:1916–1961  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1914 const int border = 0;
1915
1916 OperMap map;
1917 map.CreateMap(veh, xei - border, zei - border, xei + border, zei + border);
1918
1919 bool ret = map.GetFieldCost(xe, ze, true, GetVehicle(), IsSoldier()) < GET_UNACCESSIBLE;
1920 veh->PerformLock();
1921 return ret;
1922}
1923
1924bool AIUnit::FindNearestEmpty(Vector3& pos, bool soldier, EntityAI* veh)
1925{
1926 veh->PerformUnlock();
1927
1928 float xEnd = pos.X();
1929 float zEnd = pos.Z();
1930 float xef = xEnd * InvOperItemGrid;
1931 float zef = zEnd * InvOperItemGrid;
1932 int xe = toIntFloor(xef);
1933 int ze = toIntFloor(zef);
1934
1935 int xei = xe / OperItemRange;
1936 int zei = ze / OperItemRange;
1937
1938 const int border = 1;
1939
1940 OperMap map;
1941 map.CreateMap(veh, xei - border, zei - border, xei + border, zei + border);
1942
1943 if (map.GetFieldCost(xe, ze, true, veh, soldier) >= GET_UNACCESSIBLE)
1944 {
1945 int oxe = xe, oze = ze;
1946 if (map.FindNearestEmpty(xe, ze, xef, zef, (xei - border) * OperItemRange, (zei - border) * OperItemRange,
1947 (1 + 2 * border) * OperItemRange, (1 + 2 * border) * OperItemRange, true, veh, soldier,
1948 DefFindFreePositionCallback, nullptr))
1949 {
1950 // xEnd, zEnd must be changed (is forced into last path point)
1951 if (xe != oxe || ze != oze)
1952 {
1953 pos[0] = xe * OperItemGrid + 0.5 * OperItemGrid;
1954 pos[2] = ze * OperItemGrid + 0.5 * OperItemGrid;
1955 }
1956 }
1957 else
1958 {
1959#if LOG_PROBL
1960 Log("Unit %s: End point not found", (const char*)veh->GetDebugName());
1961 map.LogMap(xei - border, xei + border, zei - border, zei + border, xe, xe, ze, ze, false);
1962#endif
1963 veh->PerformLock();
1964 return false;

Callers 10

EstimateAttackMethod · 0.45
AttackThinkMethod · 0.45
KilledByMethod · 0.45
CreateNoRoadPathMethod · 0.45
FindFreePositionMethod · 0.45
PositionPilotMethod · 0.45
FormationPilotMethod · 0.45
AttackRunAwayFunction · 0.45
GetGetInPointFarFunction · 0.45
GetOutMoveFunction · 0.45

Calls 8

PerformUnlockMethod · 0.80
CreateMapMethod · 0.80
LogMapMethod · 0.80
PerformLockMethod · 0.80
XMethod · 0.45
ZMethod · 0.45
GetFieldCostMethod · 0.45
GetDebugNameMethod · 0.45

Tested by

no test coverage detected