Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- building optimizer for arma2 epoch
- Copyright (C) 2015 Halvhjearne & Suppe
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- Contact : halvhjearne@gmail.com
- */
- #include "buildings.sqf"
- if !(isServer)exitWith{diag_log "[BuildingOptimizer]: Exiting run on client machine, put line within if (isServer) part of the init to prevent this";};
- if(count _buildings == 0)exitWith{
- diag_log format["[BuildingOptimizer]: no vehicle(s) or building(s) found for world %1",worldName];
- };
- diag_log format["[BuildingOptimizer]: found %1 vehicle(s) or building(s) to build in %2",count _buildings,worldName];
- _time = diag_tickTime;
- HALV_cratefiller3 = {};
- if(_fillcrates)then{
- diag_log format["[BuildingOptimizer]: _fillcrates: '%1' loading 'HALV_cratefiller3' fnc",_fillcrates];
- HALV_cratefiller3 = {
- //object to fill
- _obj = _this select 0;
- //Array of items to pick from
- _array = _this select 1;
- //Array of items to pick from
- _itemarray = _array select 0;
- //Option 0 = Weapons, 1 = Magazines 2 = Backpacks
- _option = _array select 1;
- //Max items to pick from array
- _maxarray = _array select 2;
- //Min items to pick from array
- _minarray = _array select 3;
- //Max of each pick
- _maxitem = _array select 4;
- //Min of each pick
- _minitem = if(count _array > 5)then{_array select 5}else{1};
- //extra item chance, chance number between 0 & 1, 2 for always or -1 for never
- _addextraHOT = if(count _array > 6)then{_array select 6}else{-1};
- //extra item, defaults to hotwire kit, "" if you just need debug info
- _addextraHOTspecialItem = if(count _array > 7)then{if(_array select 7 != "")then{_array select 7}else{"ItemHotwireKit"};}else{"ItemHotwireKit"};
- //extra debug output, default false
- _DebugBox = if(count _array > 8)then{_array select 8}else{false};
- _arraycount = count _itemarray;
- _maxarrayresult = (round(random _maxarray));
- if(_maxarrayresult < (_minarray))then{_maxarrayresult = _minarray};
- 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];};
- for "_i" from 0 to (_maxarrayresult)-1 do {
- _item = _itemarray call BIS_fnc_selectRandom;
- _itemarray = _itemarray - [_item];
- _maxitemresult = round(random _maxitem);
- if(_maxitemresult < _minitem)then{_maxitemresult = _minitem};
- if(_DebugBox)then{diag_log format["[CrateFiller3]: '%1' item '%2' option '%3' max '%4' min '%5' result '%6'",_obj,_item,_option,_maxitem,_minitem,_maxitemresult];};
- /*
- if ( isClass (configFile >> "CFGweapons" >> _item)) then {
- //class is weapon
- _obj addWeaponCargoGlobal [_item,_maxitemresult];
- if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' Added '%2' x '%3'",_obj,_item,_maxitemresult];};
- _ammo = [] + getArray (configFile >> "cfgWeapons" >> _item >> "magazines");
- if (count _ammo > 0) then {
- _select = floor(random(count _ammo));
- _amount = (round(random 8))+2;
- _obj addMagazineCargoGlobal [(_ammo select _select),_amount];
- if(_DebugBox)then{diag_log format ["[CrateFiller3]: "CFGweapons" Obj '%1' Added '%2' x '%4' array '%5'",_obj,(_ammo select _select),_amount,_ammo];};
- };
- }else{
- if ( isClass (configFile >> "CFGMagazines" >> _item)) then {
- //class is magazine
- _obj addMagazineCargoGlobal [_item,_maxitemresult];
- if(_DebugBox)then{diag_log format ["[CrateFiller3]: "CFGMagazines" Obj '%1' Added '%2' x '%3'",_obj,_item,_maxitemresult];};
- }else{
- //class is something else (should be backpacks in this case)
- _obj addBackpackCargoGlobal [_item,_maxitemresult];
- if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' Added '%2' x '%3'",_obj,_item,_maxitemresult];};
- };
- };
- */
- switch (_option) do {
- case 0:
- {
- if(_maxitemresult > 0)then{
- _obj addWeaponCargoGlobal [_item,_maxitemresult];
- _ammo = [] + getArray (configFile >> "cfgWeapons" >> _item >> "magazines");
- if (count _ammo > 0) then {
- _select = floor(random(count _ammo));
- _amount = (round(random 8))+2;
- _obj addMagazineCargoGlobal [(_ammo select _select),_amount];
- if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' Added '%2' x '%4' array '%5'",_obj,(_ammo select _select),_amount,_ammo];};
- };
- };
- if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' item '%2' x '%3'",_obj,_item,_maxitemresult];};
- };
- case 1:
- {
- if(_maxitemresult > 0)then{_obj addMagazineCargoGlobal [_item,_maxitemresult];};
- if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' item '%2' x '%3'",_obj,_item,_maxitemresult];};
- };
- case 2:
- {
- if(_maxitemresult > 0)then{_obj addBackpackCargoGlobal [_item,_maxitemresult];};
- if(_DebugBox)then{diag_log format ["[CrateFiller3]: Obj '%1' item '%2' x '%3'",_obj,_item,_maxitemresult];};
- };
- default{diag_log format["[CrateFiller3]: Error wrong _option:%2 _obj: %1",_obj,_option];_DebugBox = false;_addextraHOT = -1;};
- };
- };
- if(random 1 <= _addextraHOT || _addextraHOT == 2)then{
- _obj addmagazinecargoglobal [_addextraHOTspecialItem,1];
- };
- if(_DebugBox)then{
- _cargo1 = getmagazinecargo _obj;
- diag_log format["[CrateFiller3]: %1 | Mag Cargo: %2",(typeOf _obj),_cargo1 select 0];
- diag_log format["[CrateFiller3]: %1 | Mag Cargo: %2",(typeOf _obj),_cargo1 select 1];
- _cargo2 = getweaponcargo _obj;
- diag_log format["[CrateFiller3]: %1 | Wea Cargo: %2",(typeOf _obj),_cargo2 select 0];
- diag_log format["[CrateFiller3]: %1 | Wea Cargo: %2",(typeOf _obj),_cargo2 select 1];
- _cargo3 = getbackpackcargo _obj;
- diag_log format["[CrateFiller3]: %1 | Bag Cargo: %2",(typeOf _obj),_cargo3 select 0];
- diag_log format["[CrateFiller3]: %1 | Bag Cargo: %2",(typeOf _obj),_cargo3 select 1];
- };
- true
- };
- };
- /*
- if(_checkarrays)then{
- {
- _arr = _x;
- //check if array is array
- if(typeName _arr != "ARRAY")exitWith{diag_log format["[BuildingOptimizer]: Array Error '%1'",_arr];};
- //check if array is too small
- if(count _arr < 2)exitWith{diag_log format["[BuildingOptimizer]: Array Error '%1'",_arr];};
- _build = _arr select 0;
- //check if _build array is array
- if(typeName _build != "ARRAY")exitWith{diag_log format["[BuildingOptimizer]: Array Error '%2' '%1'",_arr,_build];};
- //check if _build array is too small
- if(count _build < 2)exitWith{diag_log format["[BuildingOptimizer]: Array Error '%2' '%1'",_arr,_build];};
- //check if _build select 1 array is array
- if(typeName _build select 1 != "ARRAY")exitWith{diag_log format["[BuildingOptimizer]: Array Error '%2' '%1'",_arr,_build select 1];};
- //check if _build select 1 array is too small
- if(count _build select 1 < 2)exitWith{diag_log format["[BuildingOptimizer]: Array Error '%2' '%1'",_arr,_build select 1];};
- }count _buildings;
- };
- */
- _fnc_setvars =
- {
- _set = _this select 0;
- _obj = _this select 1;
- switch (_set) do {
- case 0:{_objectID = str(round(random 999999));_obj setVariable ["ObjectID", _objectID, true];_obj setVariable ["ObjectUID", _objectID, true];_obj setVariable ["Sarge",1,true];};
- case 1:{_obj allowDammage false;_obj addEventHandler ["HandleDamage", {false}];};
- 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;}];};
- case 3:{_obj setvehiclelock "locked";};
- case 4:{_obj setVariable ["objectLocked", true, true];};
- case 5:{_obj setVariable ["R3F_LOG_disabled",true,true];};
- case 6:{clearMagazineCargoGlobal _obj;clearWeaponCargoGlobal _obj;clearBackpackCargoGlobal _obj;};
- case 7:{_obj setVariable ["Sarge",1,true];};
- case 8:{_obj setVectorUp [0,0,1];};
- case 9:{_obj setVariable["permaLoot",true,true];};
- case 10:{_obj enableSimulation false;};
- case 11:{_obj setVehicleAmmo 0;};
- case 12:
- {
- _fadeFire = false;//fade out the fire at some point
- PVDZE_obj_Fire =
- [
- _obj, //object
- 5, //intensity
- time, //time to start
- false, //lifecheck
- _fadeFire
- ];
- publicVariable "PVDZE_obj_Fire";
- _obj setvariable ["fadeFire",_fadeFire,true];
- };
- };
- true
- };
- _fnc_buildit =
- {
- _cnt = 0;
- {
- _arr = _x;
- _build = _arr select 0;
- _building = switch (count _build) do {
- case 2:{createVehicle [(_build select 0), (_build select 1), [], 0, "CAN_COLLIDE"]};
- case 3:{createVehicle [(_build select 0), (_build select 1), (_build select 2), 0, "CAN_COLLIDE"]};
- case 4:{createVehicle [(_build select 0), (_build select 1), (_build select 2), (_build select 3), "CAN_COLLIDE"]};
- case 5:{createVehicle _build};
- };
- if(count (_arr select 1) > 0)then{
- _building setDir ((_arr select 1) select 0);
- };
- _building setPos (_build select 1);
- if(count _arr > 2)then{
- // diag_log format ["[BuildingOptimizer]: _building: %1 _build: %2 _arr: %3",_building,_build,_arr];
- {
- _handle = [_x,_building] call _fnc_setvars;
- waitUntil{_handle};
- }count (_arr select 2);
- if(count _arr > 3)then{
- if(_arr select 3 != "")then{
- _building setVehicleInit (_arr select 3);
- processInitCommands;
- };
- if(count _arr > 4)then{
- // diag_log format ["[BuildingOptimizer]: _build: %1 (_arr select 4): %2",_build,(_arr select 4)];
- {
- // diag_log format ["[BuildingOptimizer]: _building: %1 _x: %2",_building,_x];
- _handle = [_building,_x] call HALV_cratefiller3;
- // diag_log format ["[BuildingOptimizer]: _building: %1 _x: %2 _handle: %3",_building,_x,_handle];
- waitUntil{_handle};
- }count (_arr select 4);
- };
- };
- };
- _cnt = _cnt + 1;
- }count _this;
- _cnt
- };
- _num = _buildings call _fnc_buildit;
- 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