fn_findSpace.sqf 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. File: fn_findSpace.sqf
  3. Author: Rarek [AW]
  4. Description
  5. | A simple way to find empty space using a series of parameters.
  6. | Designed for Side Mission / Priority Target creators who wish
  7. | to easily find space without having to faff around with findSafePos,
  8. | randomPos and isFlatEmpty.
  9. |
  10. | As a way to force the I&A 3 design, developers using this function
  11. | cannot search for a position within a specific area and must instead
  12. | search across the entirety of the game map.
  13. |____________________
  14. Parameters
  15. | 0 - Area (String)
  16. | REQUIRED
  17. | // treat this as "must be in/on X"
  18. | - "water" // ignores "must be flat" bool
  19. | - "shore"
  20. | - "land"
  21. | - "civilisation"
  22. | - "anywhere"
  23. | - "main"
  24. | 1 - Must be flat? (Bool|Optional)
  25. | Default FALSE
  26. | // essential for artillery pieces etc
  27. | 2 - Empty space needed radius (Object OR Integer OR classname|Optional)
  28. | Default 1
  29. | // If object, gets size and finds relevant empty space
  30. | // Otherwise, it'll just find an empty space with the
  31. | // radius given.
  32. | // Useful for spawning large buildings when size is unknown
  33. |____________________
  34. Returns
  35. | Single position in format [x,y,z] (Array)
  36. |____________________
  37. Examples
  38. | _pos = ["inland", TRUE, "O_Mortar_className_F"] call AW_fnc_findSpace;
  39. | _pos = ["water"] call AW_fnc_findSpace;
  40. | _pos = ["anywhere", FALSE, 50] call AW_fnc_findSpace;
  41. |____________________
  42. */
  43. private ["_this", "_area", "_gradient", "_radius"];
  44. _area = [_this,0,"land",[""]] call BIS_fnc_param;
  45. _gradient = [_this,1,2000,[true]] call BIS_fnc_param;
  46. if (typeName _gradient == "BOOL" && _gradient) then { _gradient = 0.3; };
  47. _radius = [_this,2,1,[objNull,[]]] call BIS_fnc_param;
  48. if (typeName _radius == "OBJECT") then { _radius = getPos _radius; };
  49. _pos = [];
  50. _validPos = false;
  51. while {!_validPos} do
  52. {
  53. _validPos = true;
  54. switch (_area) do
  55. {
  56. case "water": { _pos = [[], 0, -1, _radius, 2, 2000, 0] call BIS_fnc_findSafePos; };
  57. case "shore": { _pos = [[], 0, -1, _radius, 1, _gradient, 1] call BIS_fnc_findSafePos; };
  58. case "land": { _pos = [[], 0, -1, _radius, 0, _gradient, 0] call BIS_fnc_findSafePos; };
  59. case "civilisation": { /* to be created :D */ };
  60. case "anywhere": { _pos = [[], 0, -1, _radius, 1, _gradient, 0] call BIS_fnc_findSafePos; };
  61. case "main":
  62. {
  63. _mainPos = [];
  64. { if (["main_", _x] call BIS_fnc_inString) exitWith { _mainPos = markerPos _x; }; } forEach allMapMarkers;
  65. _pos = [_mainPos, 0, 500, _radius, 0, _gradient, 0] call BIS_fnc_findSafePos;
  66. };
  67. case "poi": { _pos = markerPos (pointsOfInterest call BIS_fnc_selectRandom); };
  68. default {};
  69. };
  70. {
  71. if ((_x distance _pos) < 1000) exitWith { _validPos = false; };
  72. } forEach playableUnits;
  73. };
  74. _pos