Advertisement
Guest User

Untitled

a guest
Dec 8th, 2015
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.92 KB | None | 0 0
  1. private["_allowedSnapObjects", "_currentZoffset", "_nearestObject", "_pOffset", "_snapPos", "_snapPosition", "_snapType", "_snapDistance", "_prevSnapDistance", "_pos2", "_dir", "_snapPointsPara", "_snapPointsPerp", "_distance", "_objSlot", "_currentTarget", "_allowedSnapPoints", "_snapObjects", "_class", "_buildingPos"];
  2. if !(isNil "EPOCH_simulSwap_Lock") exitWith{};
  3.  
  4. _object = _this select 0;
  5. _item = _this select 1;
  6. if (isNull _object) exitWith{ EPOCH_target = objNull; };
  7.  
  8. if (EPOCH_playerEnergy <= 0) exitWith{
  9. _dt = ["<t size = '0.8' shadow = '0' color = '#99ffffff'>Need Energy</t>", 0, 1, 5, 2, 0, 1] spawn bis_fnc_dynamictext;
  10. };
  11.  
  12. // He_Man
  13. //if !("" call EPOCH_isBuildAllowed) exitWith{};
  14. // He_Man
  15.  
  16. EPOCH_simulSwap_Lock = true;
  17.  
  18. _objType = typeOf _object;
  19.  
  20. _energyCost = getNumber(configfile >> "cfgVehicles" >> _objType >> "energyCost");
  21. if (_energyCost == 0) then {
  22. _energyCost = 0.1;
  23. };
  24.  
  25. _class = getText(configfile >> "cfgVehicles" >> _objType >> "GhostPreview");
  26. _maxHeight = getNumber(configfile >> "cfgVehicles" >> _objType >> "maxHeight");
  27. _simulClass = getText(configFile >> "CfgVehicles" >> _objType >> "simulClass");
  28. _snapChecks = getArray(configFile >> "CfgSnapChecks" >> _objType >> "nails");
  29. diag_log format["DEBUG: _snapChecks %1",_snapChecks];
  30. _maxSnapDistance = 1;
  31. _lastCheckTime = diag_tickTime;
  32. _stabilityCheck = false;
  33.  
  34. // force sim check if object has sim class and default max height to 9m if not already specified
  35. if (_simulClass != "") then {
  36. _stabilityCheck = true;
  37. if (_maxHeight == 0) then {
  38. _maxHeight = 500;
  39. };
  40. };
  41.  
  42. if (_class != "") then {
  43.  
  44. _objSlot = _object getVariable["BUILD_SLOT", -1];
  45.  
  46. deleteVehicle _object;
  47.  
  48. _pos2 = player modelToWorldVisual[EPOCH_X_OFFSET, EPOCH_Y_OFFSET, EPOCH_Z_OFFSET];
  49.  
  50. EPOCH_target = createVehicle[_class, _pos2, [], 0, "CAN_COLLIDE"];
  51. EPOCH_TEMPOBJ_PVS = EPOCH_target;
  52. publicVariableServer "EPOCH_TEMPOBJ_PVS";
  53.  
  54. if (_pos2 select 2 > _maxHeight) then {
  55. _pos2 set[2, _maxHeight];
  56. };
  57.  
  58. _pos2ATL = _pos2;
  59. if (surfaceIsWater _pos2ATL) then {
  60. _pos2ATL = ASLtoATL _pos2ATL;
  61. };
  62. EPOCH_target setposATL _pos2ATL;
  63.  
  64. EPOCH_target attachTo[player];
  65. _currentTarget = EPOCH_target;
  66.  
  67. if (_objSlot != -1) then {
  68. _currentTarget setVariable["BUILD_SLOT", _objSlot, true];
  69. };
  70.  
  71. _allowedSnapPoints = getArray(configfile >> "cfgVehicles" >> _class >> "allowedSnapPoints");
  72. _allowedSnapObjects = getArray(configfile >> "cfgVehicles" >> _class >> "allowedSnapObjects");
  73.  
  74. _currentOffSet = [];
  75. EP_snap = objNull;
  76. EP_snapPos = [0, 0, 0];
  77. _isSnap = false;
  78.  
  79. _EPOCH_1 = diag_tickTime;
  80. _EPOCH_2 = diag_tickTime;
  81. _nearestObjects = [];
  82.  
  83. while {EPOCH_target == _currentTarget} do {
  84.  
  85. _rejectMove = false;
  86. if ((diag_tickTime - _lastCheckTime) > 10) then {
  87. _lastCheckTime = diag_tickTime;
  88. _rejectMove = !(_objType call EPOCH_isBuildAllowed);
  89. };
  90. if (_rejectMove) exitWith{
  91. deleteVehicle EPOCH_target;
  92. };
  93.  
  94. _offSet = [EPOCH_X_OFFSET, EPOCH_Y_OFFSET, EPOCH_Z_OFFSET];
  95. _pos2 = player modelToWorldVisual _offSet;
  96.  
  97. if (surfaceIsWater _pos2) then {
  98. _pos2 set[2, ((getPosASL player) select 2) + EPOCH_Z_OFFSET];
  99. };
  100.  
  101. if !(_currentOffSet isEqualTo _offSet) then {
  102. _currentOffSet = _offSet;
  103. {
  104. detach _x;
  105. } forEach attachedObjects player;
  106.  
  107. if (_pos2 select 2 > _maxHeight) then {
  108. _pos2 set[2, _maxHeight];
  109. };
  110. _pos2ATL = _pos2;
  111. if (surfaceIsWater _pos2ATL) then {
  112. _pos2ATL = ASLtoATL _pos2ATL;
  113. };
  114.  
  115. EPOCH_target setposATL _pos2ATL;
  116. EPOCH_target attachTo[player];
  117. };
  118.  
  119. if (EPOCH_space) then {
  120. _dir2 = [vectorDir player, EPOCH_buildDirection] call EPOCH_returnVector;
  121. _up2 = (vectorUp player);
  122. EPOCH_space = false;
  123. EPOCH_target setVectorDirAndUp [_dir2,_up2];
  124. };
  125.  
  126. {
  127. _nearestObject = _x;
  128. if !(isNull EP_snap) then {
  129. if ((_pos2 distance EP_snapPos) < _maxSnapDistance) then {
  130. _nearestObject = EP_snap;
  131. };
  132. };
  133.  
  134. if (!isNull _nearestObject && _nearestObject isEqualTo _x) then {
  135.  
  136. _isSnap = false;
  137. _snapPosition = [0, 0, 0];
  138. _snapConfig = configfile >> "cfgVehicles" >> (typeOf _nearestObject);
  139. _snapPointsPara = getArray(_snapConfig >> "snapPointsPara");
  140. _snapPointsPerp = getArray(_snapConfig >> "snapPointsPerp");
  141.  
  142. // base line for z height offset
  143. _baselineSnapPos = _nearestObject modelToWorldVisual [0,0,0];
  144.  
  145. if (EPOCH_buildMode == 1) then {
  146.  
  147. {
  148. if (_x in _allowedSnapPoints) then {
  149. _pOffset = _nearestObject selectionPosition _x;
  150. _snapPos = _nearestObject modelToWorldVisual _pOffset;
  151. if (surfaceIsWater _snapPos) then {
  152. _snapPos set[2, ((getPosASL _nearestObject) select 2) + (_pOffset select 2)];
  153. };
  154. _snapDistance = _pos2 distance _snapPos;
  155. if (_snapDistance < _maxSnapDistance) exitWith{
  156. _isSnap = true;
  157. _snapPosition = _snapPos;
  158. _snapType = "para";
  159. };
  160. };
  161. } forEach _snapPointsPara;
  162.  
  163. {
  164. if (_x in _allowedSnapPoints) then {
  165. _pOffset = _nearestObject selectionPosition _x;
  166. _snapPos = _nearestObject modelToWorldVisual _pOffset;
  167. if (surfaceIsWater _snapPos) then {
  168. _snapPos set[2, ((getPosASL _nearestObject) select 2) + (_pOffset select 2)];
  169. };
  170. _snapDistance = _pos2 distance _snapPos;
  171. if (_snapDistance < _maxSnapDistance) exitWith{
  172. _isSnap = true;
  173. _snapPosition = _snapPos;
  174. _snapType = "perp";
  175. };
  176. };
  177. } forEach _snapPointsPerp;
  178. };
  179.  
  180. _distance = _pos2 distance _currentTarget;
  181.  
  182. if (_isSnap && _distance < 5) then {
  183.  
  184. EP_snap = _nearestObject;
  185. EP_snapPos = _snapPosition;
  186.  
  187. _direction = getDir _nearestObject;
  188. if (_snapType == "perp") then {
  189. _snapPos1 = [_snapPosition select 0, _snapPosition select 1, 0];
  190. _pos_snapObj = getposATL _nearestObject;
  191. _pos_snapObj set[2, 0];
  192.  
  193. _direction = _direction - ([_snapPos1, _pos_snapObj] call BIS_fnc_dirTo);
  194. }
  195. else {
  196. _direction = 0;
  197. };
  198. if (EPOCH_snapDirection > 0) then {
  199. if (EPOCH_snapDirection == 1) then {
  200. _direction = _direction + 90;
  201. };
  202. if (EPOCH_snapDirection == 2) then {
  203. _direction = _direction + 180;
  204. };
  205. if (EPOCH_snapDirection == 3) then {
  206. _direction = _direction + 270;
  207. };
  208. };
  209. if (_direction > 360) then {
  210. _direction = _direction - 360;
  211. };
  212. if (_direction < 0) then {
  213. _direction = 360 + _direction;
  214. };
  215.  
  216. if !(attachedObjects player isEqualTo[]) then {
  217. {
  218. detach _x;
  219. } forEach attachedObjects player;
  220. if (EPOCH_snapDirection > 0) then {
  221. if (EPOCH_snapDirection == 1) then {
  222. _direction = _direction + 90;
  223. };
  224. if (EPOCH_snapDirection == 2) then {
  225. _direction = _direction + 180;
  226. };
  227. if (EPOCH_snapDirection == 3) then {
  228. _direction = _direction + 270;
  229. };
  230. };
  231. if (_direction > 360) then {
  232. _direction = _direction - 360;
  233. };
  234. if (_direction < 0) then {
  235. _direction = 360 + _direction;
  236. };
  237.  
  238. _dir2 = [vectorDir _nearestObject, _direction] call EPOCH_returnVector;
  239.  
  240. if (_pos2 select 2 > _maxHeight) then {
  241. _pos2 set[2, _maxHeight];
  242. };
  243. if (surfaceIsWater _snapPosition) then {
  244. _snapPosition = ASLtoATL _snapPosition;
  245. };
  246.  
  247. _currentTarget setVectorDirAndUp[_dir2, (vectorUp _nearestObject)];
  248. _currentTarget setposATL _snapPosition;
  249.  
  250. if ((diag_tickTime - _EPOCH_2) > 2) then {
  251. _EPOCH_2 = diag_tickTime;
  252. _arr_snapPoints = [];
  253. EPOCH_arr_snapPoints = [];
  254. {
  255. _pos1_snap = _currentTarget modelToWorldVisual (_x select 0);
  256. _pos2_snap = _currentTarget modelToWorldVisual (_x select 1);
  257. _ins = lineIntersectsSurfaces [AGLToASL _pos1_snap, AGLToASL _pos2_snap,player,_currentTarget,true,1,"VIEW","FIRE"];
  258. if (count _ins > 0) then {
  259. if (surfaceIsWater _snapPosition) then {
  260. _arr_snapPoints pushBack (_ins select 0 select 0);
  261. } else {
  262. _arr_snapPoints pushBack ASLToATL(_ins select 0 select 0);
  263. };
  264. };
  265. if (count _arr_snapPoints >= 2) exitWith { EPOCH_arr_snapPoints = _arr_snapPoints; }
  266. } forEach _snapChecks;
  267. };
  268.  
  269. };
  270.  
  271. } else {
  272.  
  273. EPOCH_arr_snapPoints = [];
  274. if !(attachedObjects player isEqualTo[]) then {
  275. _offSet = [EPOCH_X_OFFSET, EPOCH_Y_OFFSET, EPOCH_Z_OFFSET];
  276. _pos1 = player modelToWorldVisual _offSet;
  277. if (surfaceIsWater _pos1) then {
  278. _pos1 set[2, ((getPosASL player) select 2) + EPOCH_Z_OFFSET];
  279. _pos1 = ASLtoATL _pos1;
  280. };
  281. EPOCH_target setposATL _pos1;
  282. EPOCH_target attachTo[player];
  283. };
  284. };
  285. };
  286.  
  287. } forEach _nearestObjects;
  288.  
  289. if ((diag_tickTime - _EPOCH_1) > 1) then {
  290. _EPOCH_1 = diag_tickTime;
  291. if !(isNull EPOCH_target) then {
  292. _nearestObjects = nearestObjects[EPOCH_target, _allowedSnapObjects, 12];
  293. EPOCH_playerEnergy = (EPOCH_playerEnergy - _energyCost) max 0;
  294. };
  295. };
  296.  
  297. };
  298.  
  299. EPOCH_arr_snapPoints = [];
  300.  
  301. {
  302. detach _x;
  303. } forEach attachedObjects player;
  304.  
  305.  
  306. if !(isNull _currentTarget) then {
  307.  
  308. // check if touching ground
  309. _currentPos = getPosATL _currentTarget;
  310. if (_currentPos select 2 > _maxHeight) then {
  311. _currentPos set[2, _maxHeight];
  312. _currentTarget setPosATL _currentPos;
  313. };
  314.  
  315. _currentPos set[2, (_currentPos select 2) + 0.1];
  316.  
  317. // remove item here
  318. if (([player, _item] call BIS_fnc_invRemove) == 1) then {
  319.  
  320. if (_stabilityCheck && !isTouchingGround _currentTarget) then {
  321.  
  322. _offsetZPos = [_currentPos select 0, _currentPos select 1, (_currentPos select 2) - 0.5];
  323. if !(terrainIntersect[_currentPos, _offsetZPos]) then {
  324.  
  325. _numberOfContacts = 0;
  326. {
  327. _pos1_snap = _currentTarget modelToWorldVisual (_x select 0);
  328. _pos2_snap = _currentTarget modelToWorldVisual (_x select 1);
  329. _ins = lineIntersectsSurfaces [AGLToASL _pos1_snap, AGLToASL _pos2_snap,player,_currentTarget,true,1,"VIEW","FIRE"];
  330. if (count _ins > 0) then {
  331. _numberOfContacts = _numberOfContacts + 1;
  332. };
  333. if (_numberOfContacts >= 2) exitWith {}
  334. } forEach _snapChecks;
  335.  
  336. if (_numberOfContacts < 2) then {
  337. // TODO: foundations need to be handled
  338. // change to sim
  339. _worldspace = [getposATL _currentTarget, vectordir _currentTarget, vectorup _currentTarget];
  340. deleteVehicle _currentTarget;
  341. _currentTarget = createVehicle[_simulClass, (_worldspace select 0), [], 0, "CAN_COLLIDE"];
  342. _currentTarget setVectorDirAndUp[_worldspace select 1, _worldspace select 2];
  343. _currentTarget setposATL(_worldspace select 0);
  344. };
  345. };
  346. };
  347. _currentTarget spawn EPOCH_countdown;
  348. };
  349. };
  350. };
  351.  
  352. [] spawn{
  353. uiSleep 2;
  354. EPOCH_simulSwap_Lock = nil;
  355. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement