Advertisement
Guest User

fnc_repair_tree

a guest
Mar 14th, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.51 KB | None | 0 0
  1. if !(isClass(configFile>>'CfgPatches'>>'cba_main')) then
  2. {
  3.     fnc_defaultParam = {
  4.         /* ----------------------------------------------------------------------------
  5.         Function: CBA_fnc_defaultParam
  6.  
  7.         Description:
  8.             Gets a value from parameters list (usually _this) with a default.
  9.  
  10.         Example (direct use of function):
  11.         (begin code)
  12.             private "_frog";
  13.             _frog = [_this, 2, 12] call CBA_fnc_defaultParam;
  14.         (end code)
  15.  
  16.         Example (macro):
  17.         (begin code)
  18.             #include "script_component.hpp"
  19.             DEFAULT_PARAM(2,_frog,12);
  20.         (end code)
  21.  
  22.         Parameters:
  23.             _params - Array of parameters, usually _this [Array]
  24.             _index - Parameter index in the params array [Integer: >= 0]
  25.             _defaultValue - Value to use if the array is too short [Any]
  26.  
  27.         Returns:
  28.             Value of parameter [Any]
  29.         ---------------------------------------------------------------------------- */
  30.         _params = _this select 0;
  31.         _index = _this select 1;
  32.         _defaultValue = _this select 2;
  33.        
  34.         private "_value";
  35.  
  36.         if (!isNil "_defaultValue") then {
  37.             _value = _defaultValue;
  38.         };
  39.  
  40.         if (!isNil "_params" && {(typeName _params) == "ARRAY"} && {count _params > _index} && {!isNil { _params select _index }}) then {
  41.             _value = _params select _index;
  42.         };
  43.  
  44.         // Return.
  45.         if (isNil "_value") then {
  46.             nil;
  47.         } else {
  48.             _value;
  49.         };
  50.     };
  51.     fnc_find = {
  52.         /* ----------------------------------------------------------------------------
  53.         Function: CBA_fnc_find
  54.  
  55.         Description:
  56.             Finds a string within another string.
  57.  
  58.         Parameters:
  59.             _haystack - String in which to search [String or ASCII char array]
  60.             _needle - String to search for [String or ASCII char array]
  61.             _initialIndex - Initial character index within _haystack to start the
  62.             search at [Number: 0+, defaults to 0].
  63.  
  64.         Returns:
  65.             First position of string. Returns -1 if not found [Number]
  66.  
  67.         Examples:
  68.             (begin example)
  69.                 _result = ["frog-headed fish", "f"] call CBA_fnc_find;
  70.                 // _result => 0
  71.  
  72.                 _result = ["frog-headed fish", "f", 5] call CBA_fnc_find;
  73.                 // _result => 12
  74.  
  75.                 _result = ["frog-headed fish", "fish"] call CBA_fnc_find;
  76.                 // _result => 12
  77.             (end)
  78.  
  79.         Author:
  80.             Xeno
  81.         ---------------------------------------------------------------------------- */
  82.         _haystack = _this select 0;
  83.         _needle = _this select 1;
  84.         _initialIndex = [_this, 2, 0] call fnc_defaultParam;
  85.         private ["_haystackCount", "_needleCount", "_foundPos",
  86.         "_needleIndex", "_doexit", "_notfound"];
  87.  
  88.         if (typeName _haystack == "STRING") then {
  89.             _haystack = toArray _haystack;
  90.         };
  91.  
  92.         if (typeName _needle == "STRING") then {
  93.             _needle = toArray _needle;
  94.         };
  95.  
  96.         _haystackCount = count _haystack;
  97.         _needleCount = count _needle;
  98.         _foundPos = -1;
  99.  
  100.         if ((_haystackCount - _initialIndex) < _needleCount) exitWith {_foundPos};
  101.  
  102.         _needleIndex = 0;
  103.         _doexit = false;
  104.         for "_i" from _initialIndex to (_haystackCount - 1) do {
  105.             if (_haystack select _i == _needle select _needleIndex) then {
  106.                 if (_needleCount == 1) exitWith {
  107.                     _foundPos = _i;
  108.                     _doexit = true;
  109.                 };
  110.                 if (_haystackCount - _i < _needleCount) exitWith {_doexit = true};
  111.                 _needleIndex = (_needleIndex) + 1;
  112.                 _notfound = false;
  113.                 for "_j" from (_i + 1) to (_i + _needleCount - 1) do {
  114.                     if (_haystack select _j != _needle select _needleIndex) exitWith
  115.                     {
  116.                         _notfound = true;
  117.                     };
  118.                     _needleIndex = (_needleIndex) + 1;
  119.                 };
  120.                 if (_notfound) then
  121.                 {
  122.                     _needleIndex = 0;
  123.                 } else {
  124.                     _foundPos = _i;
  125.                     _doexit = true;
  126.                 };
  127.             };
  128.             if (_doexit) exitWith {};
  129.         };
  130.  
  131.         _foundPos
  132.     };
  133.     // ==========================================================//
  134.     private ["_debug", "_trees"];
  135.     _debug = false;
  136.  
  137.     _trees = [];
  138.     {
  139.         if (([str _x, ": t_"] call fnc_find) > -1 || {([str _x, "palm"] call fnc_find) > -1}) then
  140.         {
  141.             _trees set [count _trees,_x];
  142.            
  143.         };
  144.     } forEach _this;
  145.     if _debug then
  146.     {
  147.         hint str _trees;
  148.         copyToClipboard str _trees;
  149.         {_x setdamage 1;} foreach _trees;
  150.         sleep 5;
  151.     };
  152.     {
  153.         if ((damage _x) > 0) then
  154.         {
  155.             _x setdamage 0;
  156.         };
  157.     } foreach _trees;
  158. }else{
  159.     private ["_debug", "_trees"];
  160.     _debug = false;
  161.  
  162.     _trees = [];
  163.     {
  164.         if (([str _x, ": t_"] call CBA_fnc_find) > -1 || {([str _x, "palm"] call CBA_fnc_find) > -1}) then
  165.         {
  166.             _trees set [count _trees,_x];
  167.            
  168.         };
  169.     } forEach _this;
  170.     if _debug then
  171.     {
  172.         hint str _trees;
  173.         copyToClipboard str _trees;
  174.         {_x setdamage 1;} foreach _trees;
  175.         sleep 5;
  176.     };
  177.     {
  178.         if ((damage _x) > 0) then
  179.         {
  180.             _x setdamage 0;
  181.         };
  182.     } foreach _trees;
  183. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement