Faguss

overForest.sqf

Jul 1st, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. /*---------------------------------------------------------------
  2. overForest function by Raptorsaurus
  3.  
  4. Checks if a position or circular area will intersect (or come close to interecting)
  5. a forest area
  6.  
  7. ** This function has not been tested with non-BIS forest models. **
  8.  
  9. The required info passed to this function is:
  10.  
  11. - Position (either 2D [x,y] or 3D [x,y,z]
  12. - Radius of circular area (put 0 if just checking a single point)
  13.  
  14. Examples:
  15.  
  16. _overForest = [getPos player, 20] call overForest
  17.  
  18. if the player or the region within 20 m of him is in/over a forest _overForest will be true, otherwise it will be false
  19.  
  20. _overForest = [getMarkerPos "marker", 0] call overForest
  21.  
  22. If the marker is in a forest _overforest will be true, otherwise it will be false
  23.  
  24. Initialize this function by putting this in your init.sqs:
  25. overForest = preprocessFile "overForest.sqf"
  26. ---------------------------------------------------------------*/
  27. private ["_refpos", "_rad", "_inc", "_refobj", "_overForest", "_dis", "_radinc", "_bad"];
  28. private ["_radcnt","_X","_Y","_objA", "_dir", "_obj", "_x2", "_y2", "_Z", "_safepos"];
  29.  
  30. _refpos = _this select 0;
  31. _rad = (_this select 1) + 36;
  32. _radinc = _rad / ( (_rad / 10) - ((_rad / 10) % 1) );
  33.  
  34. _bad = ["SmokeSource","Track","Mark","ObjectDestructed","Explosion","Crater","CraterOnVehicle","Slop","Smoke","DynamicSound"];
  35.  
  36. _X = _refpos select 0;
  37. _Y = _refpos select 1;
  38. _Z = 18;
  39.  
  40. _overForest = false;
  41.  
  42. _refobj = "logic" createVehicle [0,0,1000];
  43. _safepos = [0,0,1000];
  44. _objA = [];
  45. _radcnt = 0;
  46. _inc = 0;
  47.  
  48. While {_radcnt <= _rad && ! _overForest}
  49. Do
  50. {
  51. if (_radcnt > 0) then {_inc = 360 / ((360 / Asin (_radinc/_radcnt)) - ((360 / Asin (_radinc/_radcnt)) % 1))};
  52. _dir = 0;
  53. While {_dir < 360 && ! _overForest}
  54. Do
  55. {
  56. _obj = nearestObject [(_X + (_radcnt * Sin _dir)), (_Y + (_radcnt * Cos _dir)), _Z];
  57. if (format ["%1",_obj] != "<NULL-object>" && ! (_obj in _objA) && ! ((typeOf _obj) in _bad))
  58. then
  59. {
  60. _objA = _objA + [_obj];
  61. _x2 = (getPos _obj) select 0;
  62. _y2 = (getPos _obj) select 1;
  63. _dis = sqrt((_X - _x2) ^2 + (_Y - _y2) ^2);
  64. if (_dis <= _rad)
  65. then
  66. {
  67. _refobj setPos (getPos _obj);
  68. _dis = _refobj distance _obj;
  69. if ((_dis > 6.8 && _dis < 6.9) || (_dis > 10.9 && _dis < 12.5) || _dis > 13) then {_overforest = true};
  70. _refobj setPos _safepos;
  71. };
  72. };
  73. if (_inc > 0) then {_dir = _dir + _inc} else {_dir = 360};
  74. };
  75. _radcnt = _radcnt + _radinc;
  76. };
  77. deleteVehicle _refobj;
  78. _overForest
Add Comment
Please, Sign In to add comment