Advertisement
Guest User

fn_bases.sqf

a guest
Aug 21st, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.01 KB | None | 0 0
  1. /*
  2.        Created exclusively for ArmA2:OA - DayZMod.
  3.        Please request permission to use/alter/distribute from project leader (R4Z0R49).
  4.        adapted and modified by jOoPs
  5. */
  6. private ["_b","_amount","_radius","_lootMinRadius","_lootMaxRadius","_objectMinRadius","_objectMaxRadius","_randomObjects","_guaranteedObjects","_randomLoot","_guaranteedLoot","_nextPos","_basePos","_tmpobject","_qty","_baseClass","_centerPos","_placeSearchRadius","_placeMinDistance","_addLoot","_addWrecks","_placeSearchExpr","_small","_medium","_large","_placePrecision","_campList","_time"];
  7.  
  8. _qty = _this select 0;
  9. _centerPos = getMarkerPos (_this select 1);
  10. _placeSearchRadius = _this select 2;
  11. _placeMinDistance = _this select 3;
  12.  
  13. // add some loot around the camp
  14. _addLoot = {
  15. private ["_clutter","_index","_lootMaxRadius2","_itemType","_position","_item","_nearby","_basePos","_baseClass","_lootMinRadius","_lootMaxRadius","_randomLoot","_guaranteedLoot","_lootTable","_itemTypes","_weights","_cntWeights","_config"];
  16.  
  17.     _basePos = _this select 0;
  18.     _baseClass = _this select 1;
  19.     _lootMinRadius = _this select 2;
  20.     _lootMaxRadius = _this select 3;
  21.     _randomLoot = _this select 4;
  22.     _guaranteedLoot = _this select 5;
  23.     _lootMaxRadius2 = _lootMaxRadius + 5;
  24.        
  25.             _lootTable = ["HeliCrash","HeliCrash_No50s"] call BIS_fnc_selectRandom;
  26.             //_config =         missionConfigFile >> "CfgBuildingLoot" >> _lootTable;
  27.             _config =       configFile >> "CfgBuildingLoot" >> _lootTable;
  28.             _itemTypes =    [] + getArray (_config >> "itemType");
  29.             _index =        dayz_CBLBase find toLower(_lootTable);
  30.             _weights =      dayz_CBLChances select _index;
  31.             _cntWeights = (count _weights);
  32.             //Zero divisor fix
  33.             if((_cntWeights < 0)||(_cntWeights == 0))then{
  34.                 _cntWeights = _cntWeights + 1;
  35.             };
  36.        
  37.             for "_x" from (round(random _randomLoot) + _guaranteedLoot) to 1 step -1  do {
  38.                 //create loot
  39.                 _index = floor(random _cntWeights);
  40.                 //Zero divisor fix
  41.                 if((_index < 0)||(_index == 0))then{
  42.                     _index = _index + 1;
  43.                 };
  44.                 _index = _weights select _index;
  45.                 //Zero divisor fix
  46.                 if((_index < 0)||(_index == 0))then{
  47.                     _index = _index + 1;
  48.                 };
  49.                 _itemType = [];
  50.                 _itemType = _itemTypes select _index;
  51.  
  52.                 _position = [];
  53.                 _position = [_basePos,_lootMinRadius,_lootMaxRadius,0,0,0,0] call BIS_fnc_findSafePos;
  54.                 _position = [_position select 0,_position select 1,0];
  55.        
  56.                 if ((count _position) >= 2) then {
  57.                     _position set [2,0];
  58.                     _item = [_itemType select 0, _itemType select 1, _position, 1] call spawn_loot;
  59.                     _item setVariable ["permaLoot",true];
  60.                    
  61.                     if (dayz_spawnInfectedSite_clutterCutter == 1) then { // shift loot upward to 5cm
  62.                         _position set [2,0.05];
  63.                         _item setPosATL _position;
  64.                     }
  65.                     else { if (dayz_spawnInfectedSite_clutterCutter >= 2) then { // cutterclutter
  66.                         _clutter = createVehicle ["ClutterCutter_small_2_EP1", _position, [], 0, "CAN_COLLIDE"];
  67.                         _clutter setPos _position;
  68.                         if (dayz_spawnInfectedSite_clutterCutter == 3) then { // debug
  69.                             createVehicle ["Sign_sphere100cm_EP1", [_position select 0, _position select 1, 0.30], [], 0, "CAN_COLLIDE"];                  
  70.                         };
  71.                     };};
  72.                     sleep 0.001;
  73.                     diag_log(format["Infected Camps: Loot spawn at '%1:%3' with loot table '%2'", _baseClass, str(_itemType), _basePos]);
  74.  
  75.                     // ReammoBox is preferred parent class here, as WeaponHolder wouldn't match MedBox0 and other such items.
  76.                     _nearby = _basePos nearObjects ["ReammoBox", _lootMaxRadius2];
  77.                     {
  78.                         _x setVariable ["permaLoot",true];
  79.                     } forEach _nearby;
  80.                 };
  81.             }; // loot loop
  82. };
  83.  
  84. // add some dead bodies and veh wrecks all around
  85. _addWrecks = {
  86.     private ["_randomObjects","_guaranteedObjects","_position","_basePos","_objectMinRadius","_objectMaxRadius","_Bodys","_randomvehicle","_chance","_DeadBody","_wreck","_z"];
  87.     _basePos = _this select 0;
  88.     _objectMinRadius = _this select 1;
  89.     _objectMaxRadius = _this select 2;
  90.     _randomObjects = _this select 3;
  91.     _guaranteedObjects = _this select 4;
  92.     _z = 0;
  93.  
  94.     while {_z < ((round(random _randomObjects)) + _guaranteedObjects)} do {
  95.         _position = [_basePos,_objectMinRadius,_objectMaxRadius,1,0,20,0] call BIS_fnc_findSafePos;
  96.         _position = [_position select 0,_position select 1,0];
  97.         _Bodys = ["Body1","Body2"] call BIS_fnc_selectRandom;
  98.         _randomvehicle = ["SKODAWreck","HMMWVWreck","UralWreck","datsun01Wreck","hiluxWreck","datsun02Wreck","UAZWreck","BMP2Wreck","T72Wreck","LADAWreck"] select round(random 4);
  99.         _chance = random 1;
  100.         if (_chance < 0.9) then {
  101.             _DeadBody = createVehicle [_Bodys, _position, [], 0, "CAN_COLLIDE"];
  102.         } else {
  103.             _wreck = createVehicle [_randomvehicle, _position, [], 0, "CAN_COLLIDE"];
  104.         };
  105.         _z = _z + 1;
  106.     };
  107. };
  108.  
  109.  
  110. _placeSearchExpr = "(5 * forest) + (4 * trees) + (3 * meadow) - (20 * houses) - (30 * sea)";
  111. _small = ["Camp1_Small","Camp2_Small","Camp3_Small"];
  112. _medium = ["Camp2_Medium","Camp3_Medium","Camp4_Medium","Camp5_Medium"]; // "Camp2_Medium","Camp3_Medium","Camp4_Medium","Camp5_Medium"];
  113. _large = [];
  114. _baseArray = ["Camp1_Small","Camp2_Small","Camp3_Small","Camp2_Medium","Camp3_Medium","Camp4_Medium","Camp5_Medium"]; //use this for selection
  115.  
  116. _placePrecision = 30;
  117. _amount = 0;
  118. _radius = 0;
  119. _lootMinRadius = 0;
  120. _lootMaxRadius = 0;
  121. _objectMinRadius = 0;
  122. _objectMaxRadius = 0;
  123. _randomObjects = 0;
  124. _guaranteedObjects = 0;
  125. _randomLoot = 0;
  126. _guaranteedLoot = 0;
  127. _baseClass = "";
  128. _campList = [];
  129. _basePos = [];
  130. _markerPos = getMarkerPos "respawn_west";
  131. _b = _qty * 20;
  132.  
  133. _time = time;
  134. _tmpobject = "Land_HouseV2_05" createVehicleLocal _markerPos;
  135. while {(_b > 0) && (_qty > 0) && (round(time - _time) < 35)} do {
  136.     _baseClass = _baseArray select round(random ((count _baseArray) - 1));
  137.     if (_baseClass in _small) then { _amount = 10; _radius = 100; _lootMinRadius = 8; _lootMaxRadius = 13; _objectMinRadius = 10; _objectMaxRadius = 20; _randomObjects = 8; _guaranteedObjects = 2; _randomLoot = 3; _guaranteedLoot = 4; };
  138.     if (_baseClass in _medium) then { _amount = 25; _radius = 150; _lootMinRadius = 13; _lootMaxRadius = 20; _objectMinRadius = 10; _objectMaxRadius = 20; _randomObjects = 8; _guaranteedObjects = 2; _randomLoot = 4; _guaranteedLoot = 5; };
  139.     if (_baseClass in _large) then { _amount = 40; _radius = 200; _lootMinRadius = 20; _lootMaxRadius = 30; _objectMinRadius = 10; _objectMaxRadius = 20; _randomObjects = 8; _guaranteedObjects = 2; _randomLoot = 5; _guaranteedLoot = 6; };
  140.     {
  141.         if (_x select 1 > 3) then {
  142.             _basePos = _x select 0;
  143.             if (count _basePos >= 2) then {
  144.                 _basePos set [2, 0];
  145.                 _nextPos = _basePos findEmptyPosition [0, _placePrecision, "Land_HouseV2_05"];
  146.                 _basePos = _nextPos;
  147.                 if (count _basePos >= 2) then {
  148.                     _basePos set [2, 0];
  149.                     _tmpobject setPosATL _basePos;
  150.                     //sleep 0.003;
  151.                     _basePos = _tmpobject modelToWorld (boundingCenter _tmpobject);
  152.                     //sleep 0.003;
  153.                     _basePos set [2, 0];
  154.                     _tmpobject setPosATL _markerPos;
  155.                     //sleep 0.003;
  156.                     _basePos = _basePos isFlatEmpty [0, 0, _lootMaxRadius * 0.03, _lootMaxRadius, 0, false, objNull];
  157.                     if (count _basePos >= 2) then {
  158.                         _basePos set [2, 0];
  159.                         if ((0 == count (nearestObjects [_basePos, [], _lootMaxRadius])) AND {(0 == { ((_x select 0) distance _basePos) < _placeMinDistance } count _campList)}) then {
  160.                             _campList set [count _campList, [_basePos,_amount,_radius]];
  161.                             //diag_log(format["%1 found a nice spot at %2 (%3)", __FILE__, _basePos call fa_coor2str,_x select 1]);
  162.                             [_basePos, random 360, _baseClass] call spawnComposition;
  163.                             [_basePos, _baseClass, _lootMinRadius, _lootMaxRadius, _randomLoot, _guaranteedLoot] call _addLoot;
  164.                             [_basePos, _lootMinRadius, _lootMaxRadius, _randomObjects, _guaranteedObjects] call _addWrecks;
  165.                             _qty = _qty - 1;
  166.                         };
  167.                     };
  168.                 };
  169.             };
  170.             //sleep 0.01;
  171.         };
  172.     _b = _b - 1;
  173.     } forEach selectBestPlaces [_centerPos, _placeSearchRadius, _placeSearchExpr, _placePrecision, _qty];
  174. };
  175. deleteVehicle _tmpobject;
  176.  
  177. diag_log(format["%1: found %2 camps spots in %3 sec.", __FILE__, count _campList, round(time - _time)]);
  178.  
  179. _campList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement