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

Method FindFreePosition

engine/Poseidon/AI/AIUnitImpl.cpp:2373–2472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2371bool AIUnit::FindFreePosition(Vector3& pos, Vector3& normal, bool soldier, EntityAI* veh,
2372 FindFreePositionCallback* isFree, void* context)
2373{
2374 OperMap map;
2375 int mask = MASK_AVOID_OBJECTS | MASK_AVOID_VEHICLES;
2376 float xf = pos.X() * InvLandGrid;
2377 float zf = pos.Z() * InvLandGrid;
2378 int x = toIntFloor(xf);
2379 int z = toIntFloor(zf);
2380 int border = 1;
2381 int xMin = x - border;
2382 int xMax = x + border + 1;
2383 int zMin = z - border;
2384 int zMax = z + border + 1;
2385 float dx, dz;
2386 if (xMax <= 0 || xMin >= LandRange || zMax <= 0 || zMin >= LandRange)
2387 {
2388 pos[1] = GLOB_LAND->GetSeaLevel();
2389 normal = VUp;
2390 return false;
2391 }
2392 if (xMin < 0)
2393 {
2394 xMin = 0;
2395 }
2396 if (xMax > LandRange)
2397 {
2398 xMax = LandRange;
2399 }
2400 if (zMin < 0)
2401 {
2402 zMin = 0;
2403 }
2404 if (zMax > LandRange)
2405 {
2406 zMax = LandRange;
2407 }
2408 for (z = zMin; z < zMax; z++)
2409 {
2410 for (x = xMin; x < xMax; x++)
2411 {
2412 map.CreateField(x, z, mask, veh);
2413 }
2414 }
2415
2416 bool ok = true;
2417 x = toIntFloor(pos.X() * InvOperItemGrid);
2418 z = toIntFloor(pos.Z() * InvOperItemGrid);
2419 if (map.GetFieldCost(x, z, true, veh, soldier) >= GET_UNACCESSIBLE || !isFree(pos, context))
2420 {
2421 ok = map.FindNearestEmpty(x, z, xf, zf, xMin * OperItemRange, zMin * OperItemRange,
2422 (xMax - xMin) * OperItemRange, (zMax - zMin) * OperItemRange, true, veh, soldier,
2423 isFree, context);
2424
2425 if (ok)
2426 {
2427 AI_ERROR(map.GetFieldCost(x, z, true, veh, soldier) < GET_UNACCESSIBLE);
2428 }
2429
2430 pos[0] = x * OperItemGrid + 0.5 * OperItemGrid;

Callers

nothing calls this directly

Calls 15

GetSeaLevelMethod · 0.80
ClearMapMethod · 0.80
MoveNetAwareMethod · 0.80
Vector3Class · 0.50
XMethod · 0.45
ZMethod · 0.45
CreateFieldMethod · 0.45
GetFieldCostMethod · 0.45
FindNearestEmptyMethod · 0.45
YMethod · 0.45
MinMethod · 0.45

Tested by

no test coverage detected