Advertisement
Guest User

Untitled

a guest
Jan 7th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ----------------------------------------------------------------------------
  2. Function: CBA_fnc_inArea
  3.  
  4. Description:
  5.     A function used to determine if a position is within a zone.
  6.  
  7.     The "position" can be given as a marker name, an object,
  8.     location, group or a position array.
  9.  
  10.     The zone is specificed either as a marker name or a trigger.
  11.  
  12. Parameters:
  13.     A two-element array, [ position, zone], where
  14.  
  15.     - position: Marker|Object|Location|Group|Position
  16.     - zone:     Marker|Trigger
  17.  
  18. Example:
  19.     (begin example)
  20.     // Is the marker "playermarker" inside the "safezone" marker area?
  21.     _safe = [ "playermarker", "safezone"] call CBA_fnc_inArea;
  22.  
  23.     // is the player within the safe zone marker area?
  24.     _pos = getPos player;
  25.     _safe = [ _pos, "safezone" ] call CBA_fnc_inArea;
  26.  
  27.     // Deny artillery if target is inside the trigger area
  28.     if ([_target, cityTrigger] call CBA_fnc_inArea) then
  29.     {
  30.         // deny fire mission
  31.     }
  32.     else
  33.     {
  34.         // fire away!
  35.     };
  36.     (end)  
  37.  
  38. Returns:
  39.     Boolean
  40.  
  41. Author:
  42.     Rommel
  43.  
  44. ---------------------------------------------------------------------------- */
  45. #include "script_component.hpp"
  46.  
  47. PARAMS_2(_position,_zRef);
  48.  
  49. _position = (_position call CBA_fnc_getpos);
  50.  
  51. private ["_zSize","_zDir","_zShape","_zPos"];
  52. switch (typename _zRef) do {
  53.     case "STRING" : {
  54.         _zSize = markerSize _zRef;
  55.         _zDir = markerDir _zRef;
  56.         _zShape = tolower (markerShape _zRef);
  57.         _zPos = (_zRef call CBA_fnc_getpos);
  58.     };
  59.     case "OBJECT" : {
  60.         _zSize = triggerArea _zRef;
  61.         _zDir = _zSize select 2;
  62.         _zShape = if (_zSize select 3) then {"rectangle"} else {"ellipse"};
  63.         _zPos = getpos _zRef;
  64.     };
  65. };
  66.  
  67. if (isnil "_zSize") exitwith {false};
  68.  
  69. _position = [_zPos,_position,_zDir] call CBA_fnc_vectRotate2D;
  70.  
  71. private ["_x1","_y1"];
  72. _x1 = _zpos select 0;
  73. _y1 = _zpos select 1;
  74.  
  75. private ["_x2","_y2"];
  76. _x2 = _position select 0;
  77. _y2 = _position select 1;
  78.  
  79. private ["_dx","_dy"];
  80. _dx = _x2 - _x1;
  81. _dy = _y2 - _y1;
  82.  
  83. private ["_zx","_zy"];
  84. _zx = _zsize select 0;
  85. _zy = _zsize select 1;
  86.  
  87. switch (_zShape) do {
  88.     case "ellipse" : {
  89.         ((_dx^2)/(_zx^2) + (_dy^2)/(_zy^2)) < 1
  90.     };
  91.     case "rectangle" : {
  92.         (abs _dx < _zx) and (abs _dy < _zy)
  93.     };
  94. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement