Advertisement
Guest User

Untitled

a guest
Apr 4th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 8.48 KB | None | 0 0
  1. #include "..\main.h"
  2.  
  3. //#define SLEEP_LONG 2.5
  4. //#define PLACE_VICINITY_DIST 100
  5.  
  6.  
  7. #define MINIMUM_JUMP_DIST 50
  8. #define NEXT_ROAD_DIST    250  // Search for free road piece
  9.  
  10. #if 1
  11.  
  12. #define TIME_UNTIL_STUCK_CHECK  60
  13. #define STUCK_BELOW_DIST  70  // Half of base lenght (FOB_MAX_SIZE)
  14. #define JUMP_SLEEP        SLEEP_LONG
  15.  
  16. #else // If debug settings
  17.  
  18. #define TIME_UNTIL_STUCK_CHECK  1
  19. #define STUCK_BELOW_DIST  710
  20. #define JUMP_SLEEP 1
  21.  
  22. #endif
  23.  
  24. #define INF_JUMP_DISTANCE (MINIMUM_JUMP_DIST + 300)  // For inf
  25. #define SEEK_ROAD_DIST 450    // For vehicles
  26.  
  27. #define ENEMY_NEAR_DISTANCE_JUMP 500
  28.  
  29. #define JUMP_EFFECT 1
  30.  
  31. lastJumpPos = [0,0,0];
  32.  
  33. jumpOnStuck =
  34. {
  35. params ["_group"];
  36.  
  37.  sleep 5; // For testing mostly but little delay here is ok
  38.  
  39.  while { runLoops && _group call isGroupAlive } do
  40.  {
  41.   // No point to run if no movers
  42.  if(_group call isGroupSpawned) then
  43.  {
  44.  
  45.   _vehs = _group call getVehicles;
  46.    // Move only moving vehicles
  47.   _vehs = _vehs select { (getNumber (configfile >> "CfgVehicles" >> (typeof _x) >> "maxSpeed")) > 0 };
  48.  
  49.   _target = _group call getGroupNextMovePos;
  50.  
  51.   _jumped = false;
  52.  
  53.  
  54.  
  55.   //["Test moving %1", _vehs] call dbgmsg;
  56.  
  57.   {
  58.    _vehMan = _x;
  59.    _isMan = _vehMan isKindOf "man";
  60.   _vpos = getposATL _vehMan;
  61.  
  62.   // Vehicle or on foot
  63.   if((!_isMan || (vehicle _vehMan == _vehMan)) ) then
  64.   {
  65.  
  66.    // format["Time to stuck %1 ",time - (_vehMan getVariable "lastMoveTime")] call dbgmsg;
  67.  
  68.   if((time - (_vehMan getVariable ["lastMoveTime",0])) > TIME_UNTIL_STUCK_CHECK) then
  69.   {
  70.  
  71.  
  72.    // Jump only moving not fully spawned groups
  73.    // If not jumpong and not in target and not moved much - jump
  74.   if( (_group getVariable ["isMoving",false]) && (_group call isGroupMinSpawned)
  75.   &&  { !(_vehMan getVariable ["jumping",false]) && (_target distance2D _vpos) > PLACE_VICINITY_DIST && (_vehMan getVariable "lastPos") distance2D _vpos < STUCK_BELOW_DIST } ) then
  76.   {
  77.    ["one vehicle/man (%1) stuck! %2 -- %3",_isMan,_group,_vehMan] call dbgmsg;
  78.    
  79.    _moved = false;
  80.    
  81.    if(_isMan) then
  82.    {
  83.    _moved = [_group,_vehMan,_target,(_vehMan getVariable ["timesStuck",0])] call getPosNearestToTarget;
  84.    }
  85.    else
  86.    {
  87.    _moved = [_group,_vehMan,_target,(_vehMan getVariable ["timesStuck",0])] call getRoadNearestToTarget;
  88.  
  89.    if(_moved) then
  90.    {
  91.  
  92.     // Move all infantry with the vehicle (shouldnt be needed with minimal spawn)
  93.    {
  94.     _man = _x;
  95.     if(vehicle _man == _man) then
  96.     {
  97.     _man setVariable ["timesStuck",0];
  98.     _man setVariable ["lastPos", _vpos];
  99.     _man setVariable ["lastMoveTime",time];
  100.  
  101.      _vec = [random 360, 12] call getVector;
  102.      _manSetPos = [lastJumpPos,_vec] call addVector;
  103.      _manSetPos set [2,0];
  104.       _man setposATL _manSetPos;
  105.     };
  106.    } foreach (units _group);
  107.  
  108.    };
  109.  
  110.  
  111.    };
  112.    
  113.    if(!_moved) then
  114.    {
  115.    _vehMan setVariable ["timesStuck", (_vehMan getVariable ["timesStuck",0]) + 1];
  116.    }
  117.    else
  118.    {
  119.     _vehMan setVariable ["timesStuck",0];
  120.    };
  121.    
  122.    if(_moved) then
  123.    {
  124.     _jumped = true;
  125.    };
  126.   }
  127.   else
  128.   {
  129.    // systemchat format ["time took to move %1", time - _time];
  130.    
  131.    _vehMan setVariable ["timesStuck",0];
  132.   };
  133.  
  134.  
  135.    _vehMan setVariable ["lastPos", _vpos];
  136.    _vehMan setVariable ["lastMoveTime",time];
  137.   };
  138.  
  139.   };
  140.  
  141.   } forEach (_vehs + (units _group));
  142.  
  143.  
  144.  // Try to continue movement if jumped
  145.  if(_jumped) then
  146.  {
  147.  [_group,leader _group] spawn continueMoving;
  148.  };
  149.  };
  150.  
  151.  sleep JUMP_SLEEP;
  152. };
  153. };
  154.  
  155.  
  156.  
  157. getPosNearestToTarget =
  158. {
  159. params ["_group","_man","_target","_timesStuck"];
  160.  
  161.  _side = side _group;
  162.  
  163.  _spos = getposATL _man;
  164.  
  165.  // Todo --> if([_pos,_side,_eneDist] call isEnemyNear)
  166.  
  167.  _angle = [_spos,_target] call getAngle;
  168.  _vec = [_angle,INF_JUMP_DISTANCE] call getVector;
  169.  
  170.  _jpos = [_spos,_vec] call addvector;
  171.  
  172. _freepos = [_jpos, 0, 50, 0.5 , 0, 0.9, 0, [], [[0,0],[0,0]] ] call BIS_fnc_findSafePos;
  173.  
  174. _jumped = false;
  175.  
  176. if(_freepos call isValidCoord) then // Actually found anything?
  177. {
  178.  
  179. if(!([_freepos,_side,ENEMY_NEAR_DISTANCE_JUMP * 0.7] call isEnemyNear)) then
  180. {
  181.  
  182.  _freepos set [2,0];
  183.  
  184.  if(isnull _man) exitWith {}; // Just in case
  185.  
  186.  [_man,_freepos] spawn jumpToPos;
  187.  
  188.  _jumped = true;
  189. };
  190.  
  191. };
  192.  
  193.  _jumped
  194. };
  195.  
  196.  
  197. getRoadNearestToTarget =
  198. {
  199. params ["_group","_veh","_target","_timesStuck"];
  200. /*
  201. if(side _group == west) then
  202. {
  203. ["getRoadNearestToTarget 333 ::: %1 %2 %3", _group, leader _group, _veh] call dbgmsg;
  204. };*/
  205.  
  206. private _side = side _group;
  207.  
  208. private _pos = getposATL _veh;
  209.  
  210. private _eneDist = ENEMY_NEAR_DISTANCE_JUMP;
  211. if(_timesStuck >= 10) then
  212. {
  213.  _eneDist = _eneDist * 0.5;
  214. } else {
  215. if(_timesStuck >= 3) then
  216. {
  217.  _eneDist = _eneDist * 0.7;
  218. };
  219. };
  220.  
  221. if([_pos,_side,_eneDist] call isEnemyNear) exitWith { ["Can't jump enemy near %1",_group] call dbgmsg; false }; // can't jump if enemy near
  222.  
  223.  
  224. private _nearRoads = [_pos] call searchForRoads;
  225.  
  226. //["enenear 3"] call dbgmsg;
  227.  
  228.  
  229. _closestRoad = objNull;
  230. _closestDist = 10000000;
  231.  
  232. _dbgRoadSpot = false;
  233. _dbgEnemySpot = false;
  234.  
  235. {
  236.  private _road = _x;
  237.  
  238.  // Don't jump too short
  239.  if((_road distance2D _pos) > (MINIMUM_JUMP_DIST + NEXT_ROAD_DIST)) then
  240.  {
  241.   _dbgRoadSpot = true;
  242.  if(!([getposATL _road,_side,_eneDist] call isEnemyNear)) then
  243.  {
  244.   _dbgEnemySpot = true;
  245.  
  246.  private _dist = _road distance2D _target;
  247.  if(_dist < _closestDist) then
  248.  {
  249.   _closestDist = _dist;
  250.   _closestRoad = _road;
  251.  };
  252.  };
  253.  };
  254. } foreach _nearRoads;
  255.  
  256. private _foundPos = false; // Dbg
  257.  
  258. if(!isnull _closestRoad) then
  259. {
  260.  // systemchat format["Moving to %1", _closestRoad];
  261.  
  262.  _mpos = getposatl _closestRoad;
  263.  
  264.  
  265.  private _nearRoads = _mpos nearRoads NEXT_ROAD_DIST;
  266.  
  267.  //_nextVeh = 0;
  268.  while { count _mpos > 0 } do
  269.  {
  270.   scopename "getNewPos";
  271.  
  272.   // _veh = _vehs select _nextVeh;
  273.  
  274.  _eobjs = _mpos nearObjects 10; // Todo use spawn function
  275.  if(count _eobjs == 0) then
  276.  {
  277.  
  278.   ["Moving vehicle %1 %2 %3 = %4 (%5)", _group, leader _group, _veh, crew _veh, _group call getgrouptype] call dbgmsg;
  279.  
  280.   // systemchat "moving one vehicle";
  281.   _mpos set[2,0.5];
  282.  
  283.   lastJumpPos = _mpos;
  284.  
  285.   //_veh setposAtl _mpos;
  286.   if(isnull _veh) then { break; }; // Just in case
  287.  
  288.   [_veh,_mpos] spawn jumpToPos;
  289.  
  290.  
  291.  
  292.   // Todo move infantry in when jumping
  293.  
  294. _dir = _mpos call getRoadDir;
  295. if(_dir >= 0) then
  296. {
  297. _veh setdir _dir;
  298. };
  299.  
  300. [_veh] domove ([_mpos,_target] select (vehicle (leader _group) == _veh)); // must do or vehicle starts moving back
  301.  
  302.  // [_mpos,"","ColorRed"] call createDebugMarker;
  303.  
  304.   //_nextVeh = _nextVeh + 1;
  305.  
  306.   _foundPos = true;
  307.   breakout "getNewPos";
  308.  };
  309.  
  310.  _mpos = [];
  311.  
  312.  // Get next road pos if this one was blocked
  313.  if(count _nearRoads > 0) then
  314.  {
  315.  _mpos = getPosAtl (_nearRoads select 0);
  316.  _nearRoads deleteat 0;
  317.  };
  318.  
  319. };
  320.  
  321. }
  322. else
  323. {
  324.  ["Unable to find jump center road pos %1 %2 %3", _dbgRoadSpot, _dbgEnemySpot, count _nearRoads] call dbgmsg;
  325. };
  326.  
  327. if(!_foundPos) then { ["Could not get free jump pos! %1 -- %2",_group,_veh] call dbgmsg; };
  328.  
  329.  _foundPos
  330. };
  331.  
  332.  
  333.  
  334. jumpToPos =
  335. {
  336. scopename "jumpTo";
  337. params ["_unit","_toPos"];
  338.  
  339. // diag_log format ["jumpToPos: %1 %2 %3 %4 %5", side _unit, _unit,(_unit iskindof "man"), (_unit getVariable ["jumping",false]), _toPos];
  340.  
  341. if(!alive _unit) then { breakout "jumpTo"; };
  342.  
  343. if(_unit getVariable ["jumping",false]) exitwith {}; // Make sure this happens only once
  344.  
  345. private _isMan = (_unit iskindof "man");
  346.  
  347. _esize = 1;
  348. if(_unit iskindof "man") then
  349. {
  350.  _esize = 0;
  351. };
  352.  
  353. dostop _unit;
  354.  
  355. _unit setVariable ["jumping",true];
  356.  
  357. // [_toPos,"jump",["ColorRed","ColorBlue"] select (_unit iskindof "man") ] call createDebugMarker;
  358.  
  359.  
  360.  
  361.  
  362. #if JUMP_EFFECT
  363. [ _unit, true, _esize ] remoteExecCall ["BIS_fnc_VRSpawnEffect", call targetClients];
  364.  
  365. //[ _unit, true, 1 ] call BIS_fnc_VRSpawnEffect;
  366.  
  367. sleep 5;
  368.  
  369. if(!alive _unit) then { breakout "jumpTo"; };
  370.  
  371. #endif
  372.  
  373. // Make sure man has not gone in to a vehicle
  374. // If vehicle or man on foot (never move man in vehicle)
  375. if(!_isMan || !(_unit call inVehicle) ) then
  376. {
  377.  
  378.  
  379. private _freePos = [_toPos,SPAWN_VEH_SPACE,0,50] call findSafePosVehicle;
  380.  
  381. if(count _freePos > 0) then
  382. {
  383.  _toPos = _freePos;
  384. };
  385.  
  386. [_unit, _toPos] call setPosSafe;
  387.  
  388. /*
  389. if(side _unit == west && !_isMan && testmode) then
  390. {
  391.  _toPos set [0,(_toPos # 0) + 5];
  392.  player setposATL _toPos;
  393. };*/
  394.  
  395.  
  396. #if JUMP_EFFECT
  397.  
  398. sleep 5;
  399.  
  400. if(!alive _unit) then { breakout "jumpTo"; };
  401.  
  402. [ _unit, false, _esize ] remoteExecCall ["BIS_fnc_VRSpawnEffect", call targetClients];
  403.  
  404. #endif
  405.  
  406. };
  407.  
  408. _unit setVariable ["jumping",false];
  409.  
  410. };
  411.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement