Advertisement
ComfySeven4

ObjectMapper.sqf

Jan 30th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 2.97 KB | None | 0 0
  1. scriptName "fn_objectsMapper.sqf";
  2. /*
  3.     Author: Joris-Jan van 't Land, modified for ArmA3: Outlawz7
  4.  
  5.     Description:
  6.     Takes an array of data about a dynamic object template and creates the objects.
  7.  
  8.     Parameter(s):
  9.     _this select 0: position of the template - Array [X, Y, Z]
  10.     _this select 1: azimuth of the template in degrees - Number
  11.     _this select 2: object template script name - script
  12.     (optional) _this select 3: set vector up - boolean
  13.  
  14.     Example(s):
  15.     _newComp = [(getPos this), (getDir this), "dyno_a3\doc\csat_guardpost01.sqf", false] call (compile (preprocessFileLineNumbers "dyno_a3\otl7_Mapper.sqf"));
  16.     _newComp = [(getPos this), (getDir this), "dyno_a3\doc\csat_guardpost01.sqf", true] call (compile (preprocessFileLineNumbers "dyno_a3\otl7_Mapper.sqf"));
  17. */
  18.  
  19. private ["_pos", "_azi", "_objs", "_rdm"];
  20. _pos = _this select 0;
  21. _azi = _this select 1;
  22. _script = "Compositions\fob.sqf";
  23. _setVector = _this select 3;
  24.  
  25. private ["_newObjs"];
  26.  
  27. //If the object array is in a script, call it.
  28. _objs = call (compile (preprocessFileLineNumbers _script));
  29.  
  30. _newObjs = [];
  31.  
  32. private ["_posX", "_posY"];
  33. _posX = _pos select 0;
  34. _posY = _pos select 1;
  35.  
  36. //Function to multiply a [2, 2] matrix by a [2, 1] matrix.
  37. private ["_multiplyMatrixFunc"];
  38. _multiplyMatrixFunc =
  39. {
  40.     private ["_array1", "_array2", "_result"];
  41.     _array1 = _this select 0;
  42.     _array2 = _this select 1;
  43.  
  44.     _result =
  45.     [
  46.         (((_array1 select 0) select 0) * (_array2 select 0)) + (((_array1 select 0) select 1) * (_array2 select 1)),
  47.         (((_array1 select 1) select 0) * (_array2 select 0)) + (((_array1 select 1) select 1) * (_array2 select 1))
  48.     ];
  49.  
  50.     _result
  51. };
  52.  
  53. for "_i" from 0 to ((count _objs) - 1) do
  54. {
  55.  
  56.         private ["_obj", "_type", "_relPos", "_azimuth", "_fuel", "_damage", "_newObj"];
  57.         _obj = _objs select _i;
  58.         _type = _obj select 0;
  59.         _relPos = _obj select 1;
  60.         _azimuth = _obj select 2;
  61.        
  62.         //Optionally map fuel and damage for backwards compatibility.
  63.         if ((count _obj) > 3) then {_fuel = _obj select 3};
  64.         if ((count _obj) > 4) then {_damage = _obj select 4};
  65.    
  66.         //Rotate the relative position using a rotation matrix.
  67.         private ["_rotMatrix", "_newRelPos", "_newPos"];
  68.         _rotMatrix =
  69.         [
  70.             [cos _azi, sin _azi],
  71.             [-(sin _azi), cos _azi]
  72.         ];
  73.         _newRelPos = [_rotMatrix, _relPos] call _multiplyMatrixFunc;
  74.    
  75.         //Backwards compatability causes for height to be optional.
  76.         private ["_z"];
  77.         if ((count _relPos) > 2) then {_z = _relPos select 2} else {_z = 0};
  78.    
  79.         _newPos = [_posX + (_newRelPos select 0), _posY + (_newRelPos select 1), _z];
  80.    
  81.         //Create the object and make sure it's in the correct location.
  82.         _newObj = _type createVehicle _newPos;
  83.         _newObj setDir (_azi + _azimuth);
  84.         _newObj setPos _newPos;
  85.         if (_setVector) then {_newObj setVectorUp [0,0,1];};
  86.        
  87.         //If fuel and damage were grabbed, map them.
  88.         if (!isNil "_fuel") then {_newObj setFuel _fuel};
  89.         if (!isNil "_damage") then {_newObj setDamage _damage};
  90.    
  91.         _newObjs = _newObjs + [_newObj];
  92.  
  93. };
  94.  
  95. _newObjs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement