Advertisement
skotracker

ExileClient_construction_thread

Apr 19th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 10.42 KB | None | 0 0
  1. /**
  2.  * ExileClient_construction_beginExistingObject
  3.  *
  4.  * Edited for Exile by _sinworks
  5.  *
  6.  * Exile Mod
  7.  * www.exilemod.com
  8.  * © 2015 Exile Mod Team
  9.  *
  10.  * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
  11.  * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
  12.  */
  13.  
  14. private["_boundingBox","_boundingBoxMinimum","_boundingBoxMaximum","_boundingBoxPointsTop","_boundingBoxPointsBottom","_objectColor","_materialColor","_simulatePhysics","_position","_rotation","_vectorDirection","_isFlag","_vectorUp","_potentionalSnapObject","_snapToClassName","_snapToConfig","_snapPosition","_possibleSnapPosition","_contactThreshold","_isBelowTerrain","_worldPosition","_isInAir","_numberOfContactsBottom","_startPosition","_endPosition"];
  15. scriptName 'Exile Construction Thread';
  16. ("ExileClientConstructionModeLayer" call BIS_fnc_rscLayer) cutRsc ["RscExileConstructionMode", "PLAIN", 1, false];
  17. ExileClientIsInConstructionMode = true;
  18. ExileClientConstructionResult = 0;
  19. ExileClientConstructionStartPosition = getPosASL player;
  20. _boundingBox = boundingBoxReal ExileClientConstructionObject;
  21. _boundingBoxMinimum = _boundingBox select 0;
  22. _boundingBoxMaximum = _boundingBox select 1;
  23. _boundingBoxPointsTop =
  24. [
  25.     [_boundingBoxMinimum select 0, _boundingBoxMinimum select 1, _boundingBoxMaximum select 2],
  26.     [_boundingBoxMinimum select 0, _boundingBoxMaximum select 1, _boundingBoxMaximum select 2],
  27.     [_boundingBoxMaximum select 0, _boundingBoxMinimum select 1, _boundingBoxMaximum select 2],
  28.     [_boundingBoxMaximum select 0, _boundingBoxMaximum select 1, _boundingBoxMaximum select 2]
  29. ];
  30. _boundingBoxPointsBottom =
  31. [
  32.     [_boundingBoxMinimum select 0, _boundingBoxMinimum select 1, _boundingBoxMinimum select 2],
  33.     [_boundingBoxMinimum select 0, _boundingBoxMaximum select 1, _boundingBoxMinimum select 2],
  34.     [_boundingBoxMaximum select 0, _boundingBoxMinimum select 1, _boundingBoxMinimum select 2],
  35.     [_boundingBoxMaximum select 0, _boundingBoxMaximum select 1, _boundingBoxMinimum select 2],
  36.     [0, 0, _boundingBoxMinimum select 2]
  37. ];
  38. ExileClientConstructionBoundingRadius = 1 + 0.5 * ([_boundingBoxMaximum select 0, _boundingBoxMaximum select 1, 0] distance [_boundingBoxMinimum select 0, _boundingBoxMinimum select 1, 0]);
  39. ExileClientConstructionOffset set [1, 5 max ExileClientConstructionBoundingRadius];
  40. _objectColor = "#(argb,2,2,1)color(0.7,0.93,0,0.6,ca)";
  41. _materialColor = _objectColor;
  42. _simulatePhysics = false;
  43. _position = [0, 0, 0];
  44. _rotation = 0;
  45. _vectorDirection = [0, 0, 0];
  46. _isFlag = ExileClientConstructionKitClassName isEqualTo "Exile_Item_Flag";
  47. if (_isFlag) then
  48. {
  49.     ExileClientConstructionModePhysx = false;
  50. };
  51. [] call ExileClient_gui_constructionMode_update;
  52. while {ExileClientConstructionResult isEqualTo 0} do
  53. {
  54.     if (ExileClientConstructionProcess isEqualTo 1) then
  55.     {
  56.         if !(ExileClientConstructionKitClassName in (magazines player)) then
  57.         {
  58.             ExileClientConstructionResult = 2;
  59.         };
  60.     };
  61.     if !(ExileClientConstructionLock) then
  62.     {
  63.         _vectorUp = [0, 0, 1];
  64.         ExileClientConstructionCanPlaceObject = false;
  65.         switch (ExileClientConstructionMode) do
  66.         {
  67.             case 1:
  68.             {
  69.                 _position = ASLtoATL (AGLtoASL (player modelToWorld ExileClientConstructionOffset));
  70.                 _rotation = (ExileClientConstructionRotation + (getDir player) + 360) % 360;
  71.                 _vectorDirection = [sin(_rotation), cos(_rotation), 0];
  72.             };
  73.             case 2:
  74.             {
  75.                 _position = ASLtoATL (AGLtoASL (player modelToWorld ExileClientConstructionOffset));
  76.                 _position =
  77.                 [
  78.                     (_position select 0) - ((_position select 0) % (ExileClientConstructionGrid select 0)),
  79.                     (_position select 1) - ((_position select 1) % (ExileClientConstructionGrid select 1)),
  80.                     (_position select 2) - ((_position select 2) % (ExileClientConstructionGrid select 2))
  81.                 ];
  82.                 _rotation = (ExileClientConstructionRotation + 360) % 360;
  83.                 _vectorDirection = [sin(_rotation), cos(_rotation), 0];
  84.             };
  85.             case 3:
  86.             {
  87.                 ExileClientConstructionIsSnapped = false;
  88.                 if (ExileClientConstructionIsInSelectSnapObjectMode) then
  89.                 {
  90.                     ExileClientConstructionPossibleSnapPositions = [];
  91.                     ExileClientConstructionCurrentSnapToObject = objNull;
  92.                     _position = getPosATL player;
  93.                     _position set [2, -500];
  94.                     _rotation = (ExileClientConstructionRotation + (getDir player) + 360) % 360;
  95.                     _vectorDirection = [sin(_rotation), cos(_rotation), 0];
  96.                     _potentionalSnapObject = cursorTarget;
  97.                     if !(isNull _potentionalSnapObject) then
  98.                     {
  99.                         if (_potentionalSnapObject distance player < 12) then
  100.                         {
  101.                             _snapToClassName = typeOf _potentionalSnapObject;
  102.                             if (_snapToClassName in ExileClientConstructionSnapToObjectClassNames) then
  103.                             {
  104.                                 ExileClientConstructionCurrentSnapToObject = _potentionalSnapObject;
  105.                                 _snapToConfig = ("getText(_x >> 'staticObject') == _snapToClassName" configClasses(configFile >> "CfgConstruction")) select 0;
  106.                                 {
  107.                                     _snapPosition = getArray (_snapToConfig >> "SnapPositions" >> _x);
  108.                                     _possibleSnapPosition = ASLtoATL (AGLtoASL (_potentionalSnapObject modelToWorld _snapPosition));
  109.                                     ExileClientConstructionPossibleSnapPositions pushBack _possibleSnapPosition;
  110.                                 }
  111.                                 forEach getArray (ExileClientConstructionConfig >> "SnapObjects" >> _snapToClassName >> "positions");
  112.                             };
  113.                         };
  114.                     };
  115.                 }
  116.                 else
  117.                 {
  118.                     _position = ASLtoATL (AGLtoASL (player modelToWorld ExileClientConstructionOffset));
  119.                     _rotation = (ExileClientConstructionRotation + (getDir player) + 360) % 360;
  120.                     _vectorDirection = [sin(_rotation), cos(_rotation), 0];
  121.                     {
  122.                         if (_x distance _position < 1) exitWith
  123.                         {
  124.                             _position = _x;
  125.                             _rotation = (ExileClientConstructionRotation + (getDir ExileClientConstructionCurrentSnapToObject) + 360) % 360;
  126.                             _vectorDirection = [sin(_rotation), cos(_rotation), 0];
  127.                             _vectorUp = vectorUp ExileClientConstructionCurrentSnapToObject;
  128.                             ExileClientConstructionIsSnapped = true;
  129.                         };
  130.                     }
  131.                     forEach ExileClientConstructionPossibleSnapPositions;
  132.                 };
  133.             };
  134.         };
  135.         if (!ExileClientConstructionVectorMode) then {
  136.             detach ExileClientConstructionObject;
  137.             ExileClientConstructionObject setVectorDirAndUp [_vectorDirection, _vectorUp];
  138.             ExileClientConstructionObject setPosATL _position;
  139.             [ExileClientConstructionObject,[ExileClientConstructionPitch,ExileClientConstructionBank,_rotation]] call SetPitchBankYaw;
  140.         }
  141.         else
  142.         {
  143.             _rotation = (ExileClientConstructionRotation + (getDir ExileClientConstructionCurrentSnapToObject) + 360) % 360;
  144.             ExileClientConstructionObject attachTo [player,ExileClientConstructionOffset];
  145.             [ExileClientConstructionObject,[ExileClientConstructionPitch,ExileClientConstructionBank,_rotation]] call SetPitchBankYaw;
  146.         };
  147.     };
  148.     _contactThreshold = 0.1;
  149.     _isBelowTerrain = true;
  150.     {
  151.         _worldPosition = ASLtoATL (AGLtoASL (ExileClientConstructionObject modelToWorld _x));
  152.         if ((_worldPosition select 2) > _contactThreshold) exitWith {_isBelowTerrain = false};
  153.     }
  154.     forEach _boundingBoxPointsTop;
  155.     _isInAir = true;
  156.     _numberOfContactsBottom = 0;
  157.     {
  158.         _worldPosition = ASLtoATL (AGLtoASL (ExileClientConstructionObject modelToWorld _x));
  159.         if ((_worldPosition select 2) < _contactThreshold) then
  160.         {
  161.             _isInAir = false
  162.         };
  163.         _startPosition = ATLtoASL[_worldPosition select 0, _worldPosition select 1, (_worldPosition select 2) + _contactThreshold];
  164.         _endPosition = ATLtoASL [_worldPosition select 0, _worldPosition select 1, (_worldPosition select 2) - _contactThreshold];
  165.         if (count lineIntersectsObjs[_startPosition, _endPosition, ExileClientConstructionObject, objNull, false, 2] > 0) then
  166.         {
  167.             _numberOfContactsBottom = _numberOfContactsBottom + 1;
  168.         };
  169.     }
  170.     forEach _boundingBoxPointsBottom;
  171.     if (_isBelowTerrain) then
  172.     {
  173.         ExileClientConstructionCanPlaceObject = false;
  174.         _simulatePhysics = false;
  175.         _objectColor = "#(argb,2,2,1)color(0.91,0,0,0.6,ca)";
  176.     }
  177.     else
  178.     {
  179.         ExileClientConstructionCanPlaceObject = true;
  180.         if !(ExileClientConstructionModePhysx) then
  181.         {
  182.             _objectColor = "#(argb,2,2,1)color(0.7,0.93,0,0.6,ca)";
  183.             _simulatePhysics = false;
  184.         }
  185.         else
  186.         {
  187.             if (_isInAir) then
  188.             {
  189.                 if (_numberOfContactsBottom >= 3) then
  190.                 {
  191.                     _objectColor = "#(argb,2,2,1)color(0.7,0.93,0,0.6,ca)";
  192.                     _simulatePhysics = false;
  193.                 }
  194.                 else
  195.                 {
  196.                     _objectColor = "#(argb,2,2,1)color(1,0.79,0.07,0.6,ca)";
  197.                     _simulatePhysics = true;
  198.                 };
  199.             }
  200.             else
  201.             {
  202.                 _objectColor = "#(argb,2,2,1)color(0.7,0.93,0,0.6,ca)";
  203.                 _simulatePhysics = false;
  204.             };
  205.         };
  206.     };
  207.     if (ExileClientConstructionMode isEqualTo 3) then
  208.     {
  209.         if (!ExileClientConstructionIsSnapped) then
  210.         {
  211.             ExileClientConstructionCanPlaceObject = false;
  212.             _simulatePhysics = false;
  213.             _objectColor = "#(argb,2,2,1)color(0.91,0,0,0.6,ca)";
  214.         };
  215.     };
  216.     if !(([configName ExileClientConstructionConfig, ASLtoAGL (getPosASL ExileClientConstructionObject), getPlayerUID player] call ExileClient_util_world_canBuildHere) isEqualTo 0) then
  217.     {
  218.         ExileClientConstructionCanPlaceObject = false;
  219.         _simulatePhysics = false;
  220.         _objectColor = "#(argb,2,2,1)color(0.91,0,0,0.6,ca)";
  221.     };
  222.     if (_isFlag) then
  223.     {
  224.         if (((getPos ExileClientConstructionObject) select 2) > 0.2) then
  225.         {
  226.             ExileClientConstructionCanPlaceObject = false;
  227.             _simulatePhysics = false;
  228.             _objectColor = "#(argb,2,2,1)color(0.91,0,0,0.6,ca)";
  229.         };
  230.     };
  231.     if (_objectColor != _materialColor) then
  232.     {
  233.         ExileClientConstructionObject setObjectTextureGlobal[0, _objectColor];
  234.         ExileClientConstructionObject setObjectTextureGlobal[1, _objectColor];
  235.         ExileClientConstructionObject setObjectTextureGlobal[2, _objectColor];
  236.         ExileClientConstructionObject setObjectTextureGlobal[3, _objectColor];
  237.         _materialColor = _objectColor;
  238.     };
  239.     if (ExileClientConstructionStartPosition distance (getPosASL player) > 20) then
  240.     {
  241.         ExileClientConstructionResult = 3;
  242.     };
  243.     if (ExileClientPlayerIsInCombat) then
  244.     {
  245.         ExileClientConstructionModePhysx = true;
  246.         ExileClientConstructionResult = 2;
  247.     };
  248.     uiSleep 0.001;
  249. };
  250. if !(ExileClientConstructionModePhysx) then
  251. {
  252.     _simulatePhysics = false;
  253. };
  254. _simulatePhysics call ExileClient_construction_handleAbort;
  255. ExileClientConstructionObject = objNull;
  256. ExileClientIsInConstructionMode = false;
  257. ExileClientConstructionResult = 0;
  258. ExileClientConstructionProcess = 0;
  259. ExileClientConstructionLock = false;
  260. ("ExileClientConstructionModeLayer" call BIS_fnc_rscLayer) cutText ["", "PLAIN"];
  261. true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement