Advertisement
Halvhjearne

buildingOptimizer.sqf

Apr 10th, 2015
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.46 KB | None | 0 0
  1. /*
  2.     building optimizer for arma2 epoch
  3.    
  4.     Copyright (C) 2015  Halvhjearne & Suppe
  5.  
  6.     This program is free software: you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation, either version 3 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19.     Contact : halvhjearne@gmail.com
  20. */
  21.  
  22. #include "buildings.sqf"
  23. if !(isServer)exitWith{diag_log "[BuildingOptimizer]: Exiting run on client machine, put line within if (isServer) part of the init to prevent this";};
  24. if(count _buildings == 0)exitWith{
  25.     diag_log format["[BuildingOptimizer]: no vehicle(s) or building(s) found for world %1",worldName];
  26. };
  27.  
  28. diag_log format["[BuildingOptimizer]: found %1 vehicle(s) or building(s) to build in %2",count _buildings,worldName];
  29.  
  30. _time = diag_tickTime;
  31. HALV_cratefiller3 = {};
  32.  
  33. if(_fillcrates)then{
  34.     diag_log format["[BuildingOptimizer]: _fillcrates: '%1' loading 'HALV_cratefiller3' fnc",_fillcrates];
  35.     HALV_cratefiller3 = {
  36.         //object to fill
  37.         _obj =  _this select 0;
  38.         //Array of items to pick from
  39.         _array = _this select 1;
  40.         //Array of items to pick from
  41.         _itemarray = _array select 0;
  42.         //Option 0 = Weapons, 1 = Magazines 2 = Backpacks
  43.         _option = _array select 1;
  44.         //Max items to pick from array
  45.         _maxarray = _array select 2;
  46.         //Min items to pick from array
  47.         _minarray = _array select 3;
  48.         //Max of each pick
  49.         _maxitem = _array select 4;
  50.         //Min of each pick
  51.         _minitem = if(count _array > 5)then{_array select 5}else{1};
  52.         //extra item chance, chance number between 0 & 1, 2 for always or -1 for never
  53.         _addextraHOT = if(count _array > 6)then{_array select 6}else{-1};
  54.         //extra item, defaults to hotwire kit, "" if you just need debug info
  55.         _addextraHOTspecialItem = if(count _array > 7)then{if(_array select 7 != "")then{_array select 7}else{"ItemHotwireKit"};}else{"ItemHotwireKit"};
  56.         //extra debug output, default false
  57.         _DebugBox = if(count _array > 8)then{_array select 8}else{false};
  58.         _arraycount = count _itemarray;
  59.         _maxarrayresult = (round(random _maxarray));
  60.         if(_maxarrayresult < (_minarray))then{_maxarrayresult = _minarray};
  61.         if(_DebugBox)then{diag_log format["[CrateFiller3]: '%1' amount '%2' option '%3' max '%4' min result '%5' '%6' maxitem '%7' minitem '%8' array '%9'",_obj,_arraycount,_option,_maxarray,_minarray,_maxarrayresult,_maxitem,_minitem,_array];};
  62.         for "_i" from 0 to (_maxarrayresult)-1 do {
  63.             _item = _itemarray call BIS_fnc_selectRandom;
  64.             _itemarray = _itemarray - [_item];
  65.             _maxitemresult = round(random _maxitem);
  66.             if(_maxitemresult < _minitem)then{_maxitemresult = _minitem};
  67.             if(_DebugBox)then{diag_log format["[CrateFiller3]: '%1' item '%2' option '%3' max '%4' min '%5' result '%6'",_obj,_item,_option,_maxitem,_minitem,_maxitemresult];};
  68.             /*
  69.             if ( isClass (configFile >> "CFGweapons" >> _item)) then {
  70.             //class is weapon
  71.                 _obj addWeaponCargoGlobal [_item,_maxitemresult];
  72.                 if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' Added '%2' x '%3'",_obj,_item,_maxitemresult];};
  73.                 _ammo = [] + getArray (configFile >> "cfgWeapons" >> _item >> "magazines");
  74.                 if (count _ammo > 0) then {
  75.                     _select = floor(random(count _ammo));
  76.                     _amount = (round(random 8))+2;
  77.                     _obj addMagazineCargoGlobal [(_ammo select _select),_amount];
  78.                     if(_DebugBox)then{diag_log format ["[CrateFiller3]: "CFGweapons" Obj '%1' Added '%2' x '%4' array '%5'",_obj,(_ammo select _select),_amount,_ammo];};
  79.                 };
  80.             }else{
  81.                 if ( isClass (configFile >> "CFGMagazines" >> _item)) then {
  82.                 //class is magazine
  83.                     _obj addMagazineCargoGlobal [_item,_maxitemresult];
  84.                     if(_DebugBox)then{diag_log format ["[CrateFiller3]: "CFGMagazines" Obj '%1' Added '%2' x '%3'",_obj,_item,_maxitemresult];};
  85.                 }else{
  86.                 //class is something else (should be backpacks in this case)
  87.                     _obj addBackpackCargoGlobal [_item,_maxitemresult];
  88.                     if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' Added '%2' x '%3'",_obj,_item,_maxitemresult];};
  89.                 };
  90.             };
  91.             */
  92.             switch (_option) do {
  93.                 case 0:
  94.                 {
  95.                     if(_maxitemresult > 0)then{
  96.                         _obj addWeaponCargoGlobal [_item,_maxitemresult];
  97.                         _ammo = [] + getArray (configFile >> "cfgWeapons" >> _item >> "magazines");
  98.                         if (count _ammo > 0) then {
  99.                             _select = floor(random(count _ammo));
  100.                             _amount = (round(random 8))+2;
  101.                             _obj addMagazineCargoGlobal [(_ammo select _select),_amount];
  102.                             if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' Added '%2' x '%4' array '%5'",_obj,(_ammo select _select),_amount,_ammo];};
  103.                         };
  104.                     };
  105.                     if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' item '%2' x '%3'",_obj,_item,_maxitemresult];};
  106.                 };
  107.                 case 1:
  108.                 {
  109.                     if(_maxitemresult > 0)then{_obj addMagazineCargoGlobal [_item,_maxitemresult];};
  110.                     if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' item '%2' x '%3'",_obj,_item,_maxitemresult];};
  111.                 };
  112.                 case 2:
  113.                 {
  114.                     if(_maxitemresult > 0)then{_obj addBackpackCargoGlobal [_item,_maxitemresult];};
  115.                     if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' item '%2' x '%3'",_obj,_item,_maxitemresult];};
  116.                 };
  117.                 default{diag_log format["[CrateFiller3]: Error wrong _option:%2 _obj: %1",_obj,_option];_DebugBox = false;_addextraHOT = -1;};
  118.             };
  119.         };
  120.         if(random 1 <= _addextraHOT || _addextraHOT == 2)then{
  121.             _obj addmagazinecargoglobal [_addextraHOTspecialItem,1];
  122.         };
  123.         if(_DebugBox)then{
  124.             _cargo1 = getmagazinecargo _obj;
  125.             diag_log format["[CrateFiller3]: %1 | Mag Cargo: %2",(typeOf _obj),_cargo1 select 0];
  126.             diag_log format["[CrateFiller3]: %1 | Mag Cargo: %2",(typeOf _obj),_cargo1 select 1];
  127.             _cargo2 = getweaponcargo _obj;
  128.             diag_log format["[CrateFiller3]: %1 | Wea Cargo: %2",(typeOf _obj),_cargo2 select 0];
  129.             diag_log format["[CrateFiller3]: %1 | Wea Cargo: %2",(typeOf _obj),_cargo2 select 1];
  130.             _cargo3 = getbackpackcargo _obj;
  131.             diag_log format["[CrateFiller3]: %1 | Bag Cargo: %2",(typeOf _obj),_cargo3 select 0];
  132.             diag_log format["[CrateFiller3]: %1 | Bag Cargo: %2",(typeOf _obj),_cargo3 select 1];
  133.         };
  134.         true
  135.     };
  136. };
  137. /*
  138. if(_checkarrays)then{
  139.     {
  140.         _arr = _x;
  141.         //check if array is array
  142.         if(typeName _arr != "ARRAY")exitWith{diag_log format["[BuildingOptimizer]: Array Error '%1'",_arr];};
  143.         //check if array is too small
  144.         if(count _arr < 2)exitWith{diag_log format["[BuildingOptimizer]: Array Error '%1'",_arr];};
  145.         _build = _arr select 0;
  146.         //check if _build array is array
  147.         if(typeName _build != "ARRAY")exitWith{diag_log format["[BuildingOptimizer]: Array Error '%2' '%1'",_arr,_build];};
  148.         //check if _build array is too small
  149.         if(count _build < 2)exitWith{diag_log format["[BuildingOptimizer]: Array Error '%2' '%1'",_arr,_build];};
  150.         //check if _build select 1 array is array
  151.         if(typeName _build select 1 != "ARRAY")exitWith{diag_log format["[BuildingOptimizer]: Array Error '%2' '%1'",_arr,_build select 1];};
  152.         //check if _build select 1 array is too small
  153.         if(count _build select 1 < 2)exitWith{diag_log format["[BuildingOptimizer]: Array Error '%2' '%1'",_arr,_build select 1];};
  154.        
  155.        
  156.        
  157.        
  158.        
  159.     }count _buildings;
  160. };
  161. */
  162. _fnc_setvars =
  163. {
  164.     _set = _this select 0;
  165.     _obj = _this select 1;
  166.     switch (_set) do {
  167.         case 0:{_objectID = str(round(random 999999));_obj setVariable ["ObjectID", _objectID, true];_obj setVariable ["ObjectUID", _objectID, true];_obj setVariable ["Sarge",1,true];};
  168.         case 1:{_obj allowDammage false;_obj addEventHandler ["HandleDamage", {false}];};
  169.         case 2:{_obj addEventHandler ["GetIn",{_nil = [nil,(_this select 2),"loc",rTITLETEXT,"Warning: This vehicle will disappear on server restart!","PLAIN DOWN",5] call RE;}];};
  170.         case 3:{_obj setvehiclelock "locked";};
  171.         case 4:{_obj setVariable ["objectLocked", true, true];};
  172.         case 5:{_obj setVariable ["R3F_LOG_disabled",true,true];};
  173.         case 6:{clearMagazineCargoGlobal _obj;clearWeaponCargoGlobal _obj;clearBackpackCargoGlobal _obj;};
  174.         case 7:{_obj setVariable ["Sarge",1,true];};
  175.         case 8:{_obj setVectorUp [0,0,1];};
  176.         case 9:{_obj setVariable["permaLoot",true,true];};
  177.         case 10:{_obj enableSimulation false;};
  178.         case 11:{_obj setVehicleAmmo 0;};
  179.         case 12:
  180.         {
  181.             _fadeFire = false;//fade out the fire at some point
  182.             PVDZE_obj_Fire =
  183.             [
  184.                 _obj,       //object
  185.                 5,          //intensity
  186.                 time,       //time to start
  187.                 false,      //lifecheck
  188.                 _fadeFire
  189.             ];
  190.             publicVariable "PVDZE_obj_Fire";
  191.             _obj setvariable ["fadeFire",_fadeFire,true];
  192.         };
  193.     };
  194.     true
  195. };
  196.  
  197. _fnc_buildit =
  198. {
  199.     _cnt = 0;
  200.     {
  201.         _arr = _x;
  202.         _build = _arr select 0;
  203.         _building = switch (count _build) do {
  204.             case 2:{createVehicle [(_build select 0), (_build select 1), [], 0, "CAN_COLLIDE"]};
  205.             case 3:{createVehicle [(_build select 0), (_build select 1), (_build select 2), 0, "CAN_COLLIDE"]};
  206.             case 4:{createVehicle [(_build select 0), (_build select 1), (_build select 2), (_build select 3), "CAN_COLLIDE"]};
  207.             case 5:{createVehicle _build};
  208.         };
  209.         if(count (_arr select 1) > 0)then{
  210.             _building setDir ((_arr select 1) select 0);
  211.         };
  212.         _building setPos (_build select 1);
  213.         if(count _arr > 2)then{
  214. //          diag_log format ["[BuildingOptimizer]: _building: %1 _build: %2 _arr: %3",_building,_build,_arr];
  215.             {
  216.                 _handle = [_x,_building] call _fnc_setvars;
  217.                 waitUntil{_handle};
  218.             }count (_arr select 2);
  219.             if(count _arr > 3)then{
  220.                 if(_arr select 3 != "")then{
  221.                     _building setVehicleInit (_arr select 3);
  222.                     processInitCommands;
  223.                 };
  224.                 if(count _arr > 4)then{
  225. //                  diag_log format ["[BuildingOptimizer]: _build: %1 (_arr select 4): %2",_build,(_arr select 4)];
  226.                     {
  227. //                      diag_log format ["[BuildingOptimizer]: _building: %1 _x: %2",_building,_x];
  228.                         _handle = [_building,_x] call HALV_cratefiller3;
  229. //                      diag_log format ["[BuildingOptimizer]: _building: %1 _x: %2 _handle: %3",_building,_x,_handle];
  230.                         waitUntil{_handle};
  231.                     }count (_arr select 4);
  232.                 };
  233.             };
  234.         };
  235.         _cnt = _cnt + 1;
  236.     }count _this;
  237.     _cnt
  238. };
  239.  
  240. _num = _buildings call _fnc_buildit;
  241. diag_log format["[BuildingOptimizer]: build %1 of %2 vehicle(s) or building(s) in world %3 (time: %4 seconds)",_num,count _buildings,worldName,(diag_tickTime - _time)];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement