Advertisement
Guest User

functions

a guest
May 22nd, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.70 KB | None | 0 0
  1. // =========================================================================================================
  2. // SAR_AI - DayZ AI library
  3. // Version: 1.1.0
  4. // Author: Sarge (sarge@krumeich.ch)
  5. //
  6. // Wiki: to come
  7. // Forum: http://opendayz.net/index.php?threads/sarge-ai-framework-public-release.8391/
  8. //
  9. // ---------------------------------------------------------------------------------------------------------
  10. // Required:
  11. // UPSMon
  12. // SHK_pos
  13. //
  14. // ---------------------------------------------------------------------------------------------------------
  15. // Sar_functions - generic functions library
  16. // last modified: 1.4.2013
  17. // ---------------------------------------------------------------------------------------------------------
  18. SAR_isKindOf_weapon = {
  19. //
  20. // own function because the BiS one does only search vehicle config
  21. //
  22. //
  23. // parameters:
  24. // _weapon = the weapon for which we search the parent class
  25. // _class = class to search for
  26. //
  27. // return value: true if found, otherwise false
  28. //
  29.  
  30. private ["_class","_weapon","_cfg_entry","_found","_search_class"];
  31.  
  32. _weapon = _this select 0;
  33. _class = _this select 1;
  34.  
  35. _cfg_entry = configFile >> "CfgWeapons" >> _weapon;
  36. _search_class = configFile >> "CfgWeapons" >> _class;
  37.  
  38. _found = false;
  39. while {isClass _cfg_entry} do
  40. {
  41. if (_cfg_entry == _search_class) exitWith { _found = true; };
  42.  
  43. _cfg_entry = inheritsFrom _cfg_entry;
  44. };
  45.  
  46. _found;
  47.  
  48. };
  49.  
  50.  
  51. SAR_AI_veh_trig_on_static = {
  52. //
  53. //
  54. //
  55.  
  56. private ["_unit_list","_unitlist","_trigger","_triggername","_player_joined","_player_left","_trig_unitlist","_units_leaving","_player_rating","_player_humanity","_bandits_in_trigger","_player_orig_group","_clientmachine","_trigger_activator","_forEachIndex","_dummy"];
  57.  
  58. if(!isServer) exitWith {};
  59.  
  60. if(SAR_EXTREME_DEBUG) then {diag_log "SAR_EXTREME_DEBUG: ----------------------------------Trigger activated, Script started ...------------------------------------------------------- > ";};
  61.  
  62. _unit_list = _this select 0;
  63. _trigger = _this select 1;
  64. _triggername = _this select 2;
  65. _unitlist=[];
  66. _trigger_activator = "";
  67.  
  68. if(SAR_EXTREME_DEBUG) then {
  69. {
  70. if(isPlayer _x) then {
  71. _trigger_activator = _unit_list select _forEachIndex;
  72. };
  73. } foreach _unit_list;
  74.  
  75. diag_log format["SAR_EXTREME_DEBUG: Trigger -> %1 at %2 was activated by %3!",_triggername,getpos _trigger,_trigger_activator];
  76. //diag_log format["SAR_EXTREME_DEBUG: count thislist = %1, count getvariable unitlist = %2",{(isPlayer _x) && (vehicle _x == _x) } count _unit_list, count (_trigger getVariable['unitlist',[]])];
  77. };
  78.  
  79.  
  80. // remove non players from the trigger unitlist
  81. {
  82. if (isPlayer _x) then {
  83. _unitlist set[count _unitlist,_x];
  84. };
  85. } foreach _unit_list;
  86.  
  87. if(SAR_EXTREME_DEBUG) then {[_unitlist] call SAR_debug_array;};
  88.  
  89. // get the units stored in the trigger variable
  90. _trig_unitlist = _trigger getVariable["unitlist",[]];
  91.  
  92.  
  93. // check if a unit left or joined the trigger
  94. // joined
  95. if(count _unitlist > count _trig_unitlist) then {
  96.  
  97. if(SAR_EXTREME_DEBUG) then {diag_log "SAR_EXTREME_DEBUG: ------------------------------------ Trigger entry start ---------------------------------------------------------------- >";};
  98.  
  99. //figure out the player that joined
  100. _player_joined = _unitlist select ((count _unitlist) -1);
  101.  
  102. if(SAR_EXTREME_DEBUG) then {diag_log format["SAR_EXTREME_DEBUG: Trigger DEBUG: Unit joined, name of joining unit is: %1",_player_joined];};
  103.  
  104. // if player has negative addrating, store it on player and set to 0
  105.  
  106. _player_rating = rating _player_joined;
  107.  
  108.  
  109. if (_player_rating < 0) then {
  110.  
  111. // store old rating on the player
  112. _player_joined setVariable ["SAR_rating",_player_rating,true];
  113.  
  114. //define global variable
  115. adjustrating = [_player_joined,(0 - _player_rating)];
  116.  
  117. // get the players machine ID
  118. _clientmachine = owner _player_joined;
  119.  
  120. // transmit the global variable to this client machine
  121. _clientmachine publicVariableClient "adjustrating";
  122.  
  123. };
  124.  
  125. // save and protect the old groupdata
  126. // save old group to player
  127. _player_joined setVariable ["SAR_player_group",group _player_joined,true];
  128.  
  129. // add a dummy unit into the group to keep it alive
  130. _dummy = (group _player_joined) createunit ["Rocket_DZ", [2500, 13100, 0], [],0, "FORM"];
  131.  
  132. [nil, _dummy, "per", rhideObject, true] call RE;
  133. [nil, _dummy, "per", rallowDamage, false] call RE;
  134. _dummy disableAI "FSM";
  135. _dummy disableAI "ANIM";
  136. _dummy disableAI "MOVE";
  137. _dummy disableAI "TARGET";
  138. _dummy disableAI "AUTOTARGET";
  139. _dummy setVehicleInit "this setIdentity 'id_SAR';this hideObject true;this allowDamage false;";
  140. [_dummy] joinSilent (group _player_joined);
  141.  
  142. diag_log "Joined a dummy unit to the original player group";
  143.  
  144.  
  145. // set variable to group so it doesnt get cleaned up
  146. (group _player_joined) setVariable ["SAR_protect",true,true];
  147.  
  148. // if bandit (humanity check) then switch the activating player and everyone in/close to the vehicle to resistance
  149. _player_humanity = _player_joined getVariable ["humanity",0];
  150.  
  151. if (_player_humanity < SAR_HUMANITY_HOSTILE_LIMIT) then { // player is a bandit
  152.  
  153. if(count _trig_unitlist > 0) then{ // there are already units in the trigger
  154.  
  155. _bandits_in_trigger = [_trig_unitlist] call SAR_AI_is_unfriendly_group;
  156.  
  157. if (!_bandits_in_trigger) then { // there are no bandits in the trigger list yet, create the group and add all units in the trigger list to the global resistance group
  158.  
  159. // join all units in the trigger list to that group
  160.  
  161. _trig_unitlist joinSilent SAR_grp_unfriendly;
  162.  
  163. if(SAR_EXTREME_DEBUG) then {diag_log "|||||||||||| A bandit joining created an unfriendly group and switched survivors in the trigger to the global unfriendly group!";};
  164.  
  165. };
  166.  
  167. // join player to global resistance group
  168. [_player_joined] joinSilent SAR_grp_unfriendly;
  169.  
  170. } else { // bandit player is the first at the vehicle
  171.  
  172. diag_log format["Tried to join %1 to unfriendly group: %2",_player_joined,SAR_grp_unfriendly];
  173. // join player to global resistance group
  174. [_player_joined] joinSilent grpNull;
  175. sleep .5;
  176. [_player_joined] joinSilent SAR_grp_unfriendly;
  177. sleep .5;
  178. diag_log format["Player is now %1, part of group: %2",_player_joined,group _player_joined];
  179.  
  180.  
  181. };
  182.  
  183. } else { // player is a survivor
  184.  
  185. if(count _trig_unitlist > 1) then{ // there are already units in the trigger
  186.  
  187. _bandits_in_trigger = [_trig_unitlist] call SAR_AI_is_unfriendly_group;
  188.  
  189. if (_bandits_in_trigger) then { // there are bandits in the trigger list, add survivor to the global resistance group
  190.  
  191. // join player to global unfriendly group
  192. [_player_joined] joinSilent SAR_grp_unfriendly;
  193.  
  194. } else { // the existing group is a survivor group
  195.  
  196. // join player to global friendly group
  197. [_player_joined] joinSilent SAR_grp_friendly;
  198.  
  199. };
  200. } else { // the survivor is the first at the vehicle
  201.  
  202. // join player to global friendly group
  203. [_player_joined] joinSilent SAR_grp_friendly;
  204. };
  205. };
  206.  
  207. // add joining player to the trigger list
  208. _trig_unitlist set [count _trig_unitlist, _player_joined];
  209. _trigger setVariable ["unitlist",_trig_unitlist,true];
  210.  
  211. if(SAR_EXTREME_DEBUG) then {diag_log "SAR_EXTREME_DEBUG: ------------------------------------ Trigger entry stop ---------------------------------------------------------------- >";};
  212.  
  213. } else { // a player left the trigger area
  214.  
  215. if(SAR_EXTREME_DEBUG) then {diag_log "SAR_EXTREME_DEBUG: ------------------------------------ Trigger exit start ---------------------------------------------------------------- >";};
  216.  
  217. // figure out which unit left by comparing _unitlist with _trig_unitlist
  218. _units_leaving = _trig_unitlist - _unitlist;
  219.  
  220. _player_left = _units_leaving select 0;
  221.  
  222. if(SAR_EXTREME_DEBUG) then {diag_log format["SAR_EXTREME_DEBUG: Trigger DEBUG: Unit left, name of leaving unit is: %1",_player_left];};
  223.  
  224. // remove the leaving unit from the trigger list by overwriting it with the real triggerlist contents
  225. if (count _unitlist == 0) then {
  226. _trigger setVariable ["unitlist",[],true];
  227. } else {
  228. _trigger setVariable ["unitlist",_unitlist,true];
  229. };
  230.  
  231. // if bandit, need to recheck the trigger group if still bandits in there, if not, remove all units from the resistance group
  232.  
  233. _player_humanity = _player_left getVariable ["humanity",0];
  234.  
  235. // restore old group of leaving player
  236. // load old group from player
  237. _player_orig_group = _player_left getVariable "SAR_player_group";
  238.  
  239. // join exiting player to his old group
  240. [_player_left] joinSilent _player_orig_group;
  241.  
  242. // remove dummy unit fom group
  243. {
  244. if !(isPlayer _x) then {
  245. deletevehicle _x;
  246. }
  247. } foreach units _player_orig_group;
  248.  
  249. // remove anti cleanup variable from player group
  250. _player_orig_group setVariable ["SAR_protect",nil,true];
  251.  
  252.  
  253. if (_player_humanity < SAR_HUMANITY_HOSTILE_LIMIT) then { // player is a bandit
  254.  
  255. if(count _unitlist > 0) then{ // there are still units in the trigger
  256.  
  257. // check if there are no bandits anymore in the trigger list
  258. _bandits_in_trigger = [_unitlist] call SAR_AI_is_unfriendly_group;
  259.  
  260. if (!_bandits_in_trigger) then { // no more bandits in the group, remove all of the remaining units from the resistance group and delete the group
  261.  
  262. // move all group members to the global friendly group
  263. _unitlist joinSilent SAR_grp_friendly;
  264.  
  265. diag_log "|||||||||||| A leaving bandit switched a trigger unfriendly group to friendly status";
  266.  
  267. };
  268. };
  269. };
  270.  
  271. // restore unit rating
  272.  
  273. // get old rating from the player
  274. _player_rating = _player_left getVariable ["SAR_rating",0];
  275.  
  276. //define global variable
  277. adjustrating = [_player_left,(0 + _player_rating)];
  278.  
  279. // get the players machine ID
  280. _clientmachine = owner _player_left;
  281.  
  282. // transmit the global variable to this client machine
  283. _clientmachine publicVariableClient "adjustrating";
  284.  
  285. if(SAR_EXTREME_DEBUG) then {diag_log "SAR_EXTREME_DEBUG: ------------------------------------ Trigger exit stop ---------------------------------------------------------------- >";};
  286. };
  287.  
  288.  
  289. if(SAR_EXTREME_DEBUG) then {diag_log "SAR_EXTREME_DEBUG: --------------------------------Trigger activated, Script finished----------------------------------------------------- > ";};
  290.  
  291. };
  292.  
  293. SAR_AI_veh_trig_off = {
  294. };
  295.  
  296. SAR_AI_is_unfriendly_group = {
  297. // parameters
  298. //
  299. // _trig_player_list = list of players in the trigger array
  300.  
  301. private ["_trig_player_list","_bandits_in_trigger","_player_humanity"];
  302.  
  303. _trig_player_list = _this select 0;
  304.  
  305. _bandits_in_trigger = false;
  306. {
  307. _player_humanity = _x getVariable ["humanity",0];
  308.  
  309. if(_player_humanity < SAR_HUMANITY_HOSTILE_LIMIT) then {
  310. _bandits_in_trigger = true;
  311. };
  312. } foreach _trig_player_list;
  313.  
  314. _bandits_in_trigger;
  315. };
  316.  
  317. SAR_debug_array = {
  318.  
  319. private["_array"];
  320.  
  321. _array = _this select 0;
  322.  
  323. diag_log " ";
  324. diag_log "SAR_DEBUG: Array contents ---------- start -----------";
  325. diag_log " ";
  326.  
  327. {
  328.  
  329. diag_log format[" %1. entry: %2",_foreachIndex,_x];
  330.  
  331. } foreach _array;
  332.  
  333. diag_log " ";
  334. diag_log "SAR_DEBUG: Array contents ----------- end ----------";
  335. diag_log " ";
  336. };
  337.  
  338.  
  339.  
  340. KRON_StrToArray = {
  341. private["_in","_i","_arr","_out"];
  342. _in=_this select 0;
  343. _arr = toArray(_in);
  344. _out=[];
  345. for "_i" from 0 to (count _arr)-1 do {
  346. _out=_out+[toString([_arr select _i])];
  347. };
  348. _out
  349. };
  350.  
  351. KRON_StrLeft = {
  352. private["_in","_len","_arr","_out"];
  353. _in=_this select 0;
  354. _len=(_this select 1)-1;
  355. _arr=[_in] call KRON_StrToArray;
  356. _out="";
  357. if (_len>=(count _arr)) then {
  358. _out=_in;
  359. } else {
  360. for "_i" from 0 to _len do {
  361. _out=_out + (_arr select _i);
  362. };
  363. };
  364. _out
  365. };
  366.  
  367.  
  368. SAR_unit_loadout_tools = {
  369. // Parameters:
  370. // _unittype (leader, soldier, sniper)
  371. //
  372. // return value: tools array
  373. //
  374.  
  375. private ["_unittype","_unit_tools_list","_unit_tools","_tool","_probability","_chance"];
  376.  
  377. _unittype = _this select 0;
  378.  
  379. switch (_unittype) do {
  380.  
  381. case "leader_sold" :
  382. {
  383. _unit_tools_list = SAR_leader_sold_tools;
  384. };
  385. case "soldier_sold" :
  386. {
  387. _unit_tools_list = SAR_rifleman_sold_tools;
  388. };
  389. case "sniper_sold" :
  390. {
  391. _unit_tools_list = SAR_sniper_sold_tools;
  392. };
  393. case "pistol_sold" :
  394. {
  395. _unit_tools_list = SAR_sniper_sold_pist_tools;
  396. };
  397. case "leader_band" :
  398. {
  399. _unit_tools_list = SAR_leader_band_tools;
  400. };
  401. case "soldier_band" :
  402. {
  403. _unit_tools_list = SAR_rifleman_band_tools;
  404. };
  405. case "sniper_band" :
  406. {
  407. _unit_tools_list = SAR_sniper_band_tools;
  408. };
  409. case "pistol_band" :
  410. {
  411. _unit_tools_list = SAR_sniper_band_pist_tools;
  412. };
  413. case "leader_surv" :
  414. {
  415. _unit_tools_list = SAR_leader_surv_tools;
  416. };
  417. case "soldier_surv" :
  418. {
  419. _unit_tools_list = SAR_rifleman_surv_tools;
  420. };
  421. case "sniper_surv" :
  422. {
  423. _unit_tools_list = SAR_sniper_surv_tools;
  424. };
  425. case "pistol_surv" :
  426. {
  427. _unit_tools_list = SAR_sniper_sold_surv_tools;
  428. };
  429.  
  430.  
  431. };
  432.  
  433. _unit_tools = [];
  434. {
  435. _tool = _x select 0;
  436. _probability = _x select 1;
  437. _chance = (random 100);
  438. if(_chance < _probability) then {
  439. _unit_tools set [count _unit_tools, _tool];
  440. };
  441. } foreach _unit_tools_list;
  442.  
  443. _unit_tools;
  444.  
  445. };
  446.  
  447. SAR_unit_loadout_items = {
  448. // Parameters:
  449. // _unittype (leader, soldier, sniper)
  450. //
  451. // return value: items array
  452. //
  453.  
  454. private ["_unittype","_unit_items_list","_unit_items","_item","_probability","_chance"];
  455.  
  456. _unittype = _this select 0;
  457.  
  458. switch (_unittype) do {
  459.  
  460. case "leader_sold" :
  461. {
  462. _unit_items_list = SAR_leader_sold_items;
  463. };
  464. case "soldier_sold" :
  465. {
  466. _unit_items_list = SAR_rifleman_sold_items;
  467. };
  468. case "sniper_sold" :
  469. {
  470. _unit_items_list = SAR_sniper_sold_items;
  471. };
  472. case "pistol_sold" :
  473. {
  474. _unit_items_list = SAR_sniper_sold_pist_items;
  475. };
  476. case "leader_band" :
  477. {
  478. _unit_items_list = SAR_leader_band_items;
  479. };
  480. case "soldier_band" :
  481. {
  482. _unit_items_list = SAR_rifleman_band_items;
  483. };
  484. case "sniper_band" :
  485. {
  486. _unit_items_list = SAR_sniper_band_items;
  487. };
  488. case "pistol_band" :
  489. {
  490. _unit_items_list = SAR_sniper_band_pist_items;
  491. };
  492. case "leader_surv" :
  493. {
  494. _unit_items_list = SAR_leader_surv_items;
  495. };
  496. case "soldier_surv" :
  497. {
  498. _unit_items_list = SAR_rifleman_surv_items;
  499. };
  500. case "sniper_surv" :
  501. {
  502. _unit_items_list = SAR_sniper_surv_items;
  503. };
  504. case "pistol_surv" :
  505. {
  506. _unit_items_list = SAR_sniper_surv_pist_items;
  507. };
  508.  
  509.  
  510.  
  511. };
  512.  
  513. _unit_items = [];
  514. {
  515. _item = _x select 0;
  516. _probability = _x select 1;
  517. _chance = (random 100);
  518. if(_chance < _probability) then {
  519. _unit_items set [count _unit_items, _item];
  520. };
  521. } foreach _unit_items_list;
  522.  
  523. _unit_items;
  524.  
  525. };
  526. SAR_unit_loadout_weapons = {
  527. // Parameters:
  528. // _unittype (leader, soldier, sniper)
  529. //
  530. // return value: weapons array
  531. //
  532.  
  533. private ["_unittype","_unit_weapon_list","_unit_pistol_list","_unit_pistol_name","_unit_weapon_name","_unit_weapon_names"];
  534.  
  535. _unittype = _this select 0;
  536.  
  537. switch (_unittype) do {
  538.  
  539. case "leader_sold" :
  540. {
  541. _unit_weapon_list = SAR_leader_sold_weapon_list;
  542. _unit_pistol_list = SAR_leader_sold_pistol_list;
  543. };
  544. case "soldier_sold" :
  545. {
  546. _unit_weapon_list = SAR_rifleman_sold_weapon_list;
  547. _unit_pistol_list = SAR_rifleman_sold_pistol_list;
  548. };
  549. case "sniper_sold" :
  550. {
  551. _unit_weapon_list = SAR_sniper_sold_weapon_list;
  552. _unit_pistol_list = SAR_sniper_sold_pistol_list;
  553. };
  554. case "pistol_sold" :
  555. {
  556. _unit_weapon_list = SAR_sniper_sold_pistol_weapon_list;
  557. _unit_pistol_list = SAR_sniper_sold_pistol_list;
  558. };
  559.  
  560. case "leader_band" :
  561. {
  562. _unit_weapon_list = SAR_leader_band_weapon_list;
  563. _unit_pistol_list = SAR_leader_band_pistol_list;
  564. };
  565. case "soldier_band" :
  566. {
  567. _unit_weapon_list = SAR_rifleman_band_weapon_list;
  568. _unit_pistol_list = SAR_rifleman_band_pistol_list;
  569. };
  570. case "sniper_band" :
  571. {
  572. _unit_weapon_list = SAR_sniper_band_weapon_list;
  573. _unit_pistol_list = SAR_sniper_band_pistol_list;
  574. };
  575. case "pistol_band" :
  576. {
  577. _unit_weapon_list = SAR_sniper_band_pistol_weapon_list;
  578. _unit_pistol_list = SAR_sniper_band_pistol_list;
  579. };
  580. case "leader_surv" :
  581. {
  582. _unit_weapon_list = SAR_leader_surv_weapon_list;
  583. _unit_pistol_list = SAR_leader_surv_pistol_list;
  584. };
  585. case "soldier_surv" :
  586. {
  587. _unit_weapon_list = SAR_rifleman_surv_weapon_list;
  588. _unit_pistol_list = SAR_rifleman_surv_pistol_list;
  589. };
  590. case "sniper_surv" :
  591. {
  592. _unit_weapon_list = SAR_sniper_surv_weapon_list;
  593. _unit_pistol_list = SAR_sniper_surv_pistol_list;
  594. };
  595. case "pistol_surv" :
  596. {
  597. _unit_weapon_list = SAR_sniper_surv_pistol_weapon_list;
  598. _unit_pistol_list = SAR_sniper_surv_pistol_list;
  599. };
  600.  
  601. };
  602.  
  603. _unit_weapon_names = [];
  604. _unit_weapon_name = _unit_weapon_list call BIS_fnc_selectRandom;
  605. _unit_pistol_name = _unit_pistol_list call BIS_fnc_selectRandom;
  606. _unit_weapon_names set [0, _unit_weapon_name];
  607. _unit_weapon_names set [1, _unit_pistol_name];
  608.  
  609. _unit_weapon_names;
  610.  
  611. };
  612.  
  613. SAR_unit_loadout = {
  614. // Parameters:
  615. // _unit (Unit to apply the loadout to)
  616. // _weapons (array with weapons for the loadout)
  617. // _items (array with items for the loadout)
  618. // _tools (array with tools for the loadout)
  619.  
  620. private ["_unit","_weapons","_weapon","_items","_unit_magazine_name","_item","_tool","_tools"];
  621.  
  622. _unit = _this select 0;
  623. _weapons = _this select 1;
  624. _items = _this select 2;
  625. _tools = _this select 3;
  626.  
  627. removeAllWeapons _unit;
  628.  
  629. // the above doesnt remove the tools, need this as well
  630. _unit removeweapon "ItemMap";
  631. _unit removeweapon "ItemCompass";
  632. _unit removeweapon "ItemRadio";
  633.  
  634. {
  635. _weapon = _weapons select _forEachIndex;
  636.  
  637. if (_weapon !="") then
  638. {
  639. _unit_magazine_name = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;
  640. _unit addMagazine _unit_magazine_name;
  641. _unit addWeapon _weapon;
  642. };
  643.  
  644. } foreach _weapons;
  645.  
  646. {
  647. _item = _items select _forEachIndex;
  648. _unit addMagazine _item;
  649. } foreach _items;
  650.  
  651. {
  652. _tool = _tools select _forEachIndex;
  653. _unit addWeapon _tool;
  654. } foreach _tools;
  655.  
  656. };
  657.  
  658. SAR_AI_mon_upd = {
  659.  
  660. // Parameters:
  661. // _typearray (possible values = "max_grps", "rnd_grps", "max_p_grp", "grps_band","grps_sold","grps_surv")
  662. // _valuearray (must be an array)
  663. // _gridname (is the areaname of the grid for this change)
  664.  
  665. private ["_typearray","_valuearray","_gridname","_path","_success"];
  666.  
  667. _typearray = _this select 0;
  668. _valuearray =_this select 1;
  669. _gridname = _this select 2;
  670.  
  671. _path = [SAR_AI_monitor, _gridname] call BIS_fnc_findNestedElement;
  672.  
  673. {
  674.  
  675. switch (_x) do
  676. {
  677. case "max_grps":
  678. {
  679. _path set [1,1];
  680. };
  681. case "rnd_grps":
  682. {
  683. _path set [1,2];
  684. };
  685. case "max_p_grp":
  686. {
  687. _path set [1,3];
  688. };
  689. case "grps_band":
  690. {
  691. _path set [1,4];
  692. };
  693. case "grps_sold":
  694. {
  695. _path set [1,5];
  696. };
  697. case "grps_surv":
  698. {
  699. _path set [1,6];
  700. };
  701.  
  702. };
  703.  
  704. _success = [SAR_AI_monitor, _path, _valuearray select _forEachIndex] call BIS_fnc_setNestedElement;
  705.  
  706. }foreach _typearray;
  707.  
  708. _success;
  709.  
  710.  
  711. };
  712. SAR_AI_mon_read = {
  713.  
  714. // Parameters:
  715. // _typearray (possible values = "max_grps", "rnd_grps", "max_p_grp", "grps_band","grps_sold","grps_surv")
  716. // _gridname (is the areaname of the grid for this change)
  717.  
  718. private ["_typearray","_gridname","_path","_resultarray"];
  719.  
  720. _typearray = _this select 0;
  721. _gridname = _this select 1;
  722. _resultarray=[];
  723.  
  724. _path = [SAR_AI_monitor, _gridname] call BIS_fnc_findNestedElement;
  725.  
  726. {
  727.  
  728. switch (_x) do
  729. {
  730. case "max_grps":
  731. {
  732. _path set [1,1];
  733. };
  734. case "rnd_grps":
  735. {
  736. _path set [1,2];
  737. };
  738. case "max_p_grp":
  739. {
  740. _path set [1,3];
  741. };
  742. case "grps_band":
  743. {
  744. _path set [1,4];
  745. };
  746. case "grps_sold":
  747. {
  748. _path set [1,5];
  749. };
  750. case "grps_surv":
  751. {
  752. _path set [1,6];
  753. };
  754.  
  755. };
  756.  
  757. _resultarray set[count _resultarray,[SAR_AI_monitor, _path ] call BIS_fnc_returnNestedElement];
  758.  
  759. }foreach _typearray;
  760.  
  761. _resultarray;
  762.  
  763. };
  764.  
  765. SAR_DEBUG_mon = {
  766.  
  767. diag_log "--------------------Start of AI monitor values -------------------------";
  768. {
  769. diag_log format["SAR EXTREME DEBUG: %1",_x];
  770. }foreach SAR_AI_monitor;
  771.  
  772. diag_log "--------------------End of AI monitor values -------------------------";
  773. };
  774.  
  775.  
  776. SAR_fnc_returnConfigEntry = {
  777.  
  778. private ["_config", "_entryName","_entry", "_value"];
  779.  
  780. _config = _this select 0;
  781. _entryName = _this select 1;
  782. _entry = _config >> _entryName;
  783.  
  784. //If the entry is not found and we are not yet at the config root, explore the class' parent.
  785. if (((configName (_config >> _entryName)) == "") && (!((configName _config) in ["CfgVehicles", "CfgWeapons", ""]))) then {
  786. [inheritsFrom _config, _entryName] call SAR_fnc_returnConfigEntry;
  787. }
  788. else { if (isNumber _entry) then { _value = getNumber _entry; } else { if (isText _entry) then { _value = getText _entry; }; }; };
  789. //Make sure returning 'nil' works.
  790. if (isNil "_value") exitWith {nil};
  791.  
  792. _value;
  793. };
  794.  
  795. // *WARNING* BIS FUNCTION RIPOFF - Taken from fn_fnc_returnVehicleTurrets and shortened a bit
  796. SAR_fnc_returnVehicleTurrets = {
  797.  
  798. private ["_entry","_turrets","_turretIndex","_i"];
  799.  
  800. _entry = _this select 0;
  801. _turrets = [];
  802. _turretIndex = 0;
  803.  
  804. //Explore all turrets and sub-turrets recursively.
  805. for "_i" from 0 to ((count _entry) - 1) do {
  806. private ["_subEntry"];
  807. _subEntry = _entry select _i;
  808. if (isClass _subEntry) then {
  809. private ["_hasGunner"];
  810. _hasGunner = [_subEntry, "hasGunner"] call SAR_fnc_returnConfigEntry;
  811. //Make sure the entry was found.
  812. if (!(isNil "_hasGunner")) then {
  813. if (_hasGunner == 1) then {
  814. _turrets = _turrets + [_turretIndex];
  815. //Include sub-turrets, if present.
  816. if (isClass (_subEntry >> "Turrets")) then { _turrets = _turrets + [[_subEntry >> "Turrets"] call SAR_fnc_returnVehicleTurrets]; }
  817. else { _turrets = _turrets + [[]]; };
  818. };
  819. };
  820. _turretIndex = _turretIndex + 1;
  821. };
  822. sleep 0.01;
  823. };
  824. _turrets;
  825. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement