diff --git a/Sources/epoch_code/compile/setup/masterLoop/init.sqf b/Sources/epoch_code/compile/setup/masterLoop/init.sqf index d91627d7..adf68be6 100644 --- a/Sources/epoch_code/compile/setup/masterLoop/init.sqf +++ b/Sources/epoch_code/compile/setup/masterLoop/init.sqf @@ -249,26 +249,105 @@ _lootBubble = { {(_x nearObjects ["PlotPole_Epoch", 100]) isEqualTo []} && {(_x nearObjects ["ProtectionZone_Invisible_F", 25]) isEqualTo []} && {(_x nearEntities[["Epoch_Male_F", "Epoch_Female_F"], 15]) isEqualTo []} && - {!(isObjectHidden _x)} && + {!(isObjectHidden _x)} + }; + if !(_objects isEqualTo[]) then { + _LootsArray = []; { - private _selectedConfig = typeOf _x; + _building = _x; + _building setvariable ["Epoch_LastLootCheck",diag_ticktime]; + _selectedConfig = typeOf _building; if (_selectedConfig isEqualTo "") then { - (getModelInfo _x) params [["_modelName",""]]; + (getModelInfo _building) params [["_modelName",""]]; if (!isnil "_modelName") then { _selectedConfig = (_modelName splitString " .") joinString "_"; }; }; - ((toLower _selectedConfig) in _lootClasses) - } - }; - if !(_objects isEqualTo[]) then { - { - _x setvariable ["Epoch_LastLootCheck",diag_ticktime]; - } foreach _objects; - [player,Epoch_personalToken,_objects] remoteExec ["EPOCH_server_spawnLoot",2]; + _config = _masterConfig >> _selectedConfig; + if (isClass(_config)) then { + _buildingLoot = []; + if ((random 100) < (getNumber (_config >> "EpochLootChance"))) then { + _buildingLoot = [_building,"EpochLoot",[]]; + _cfgBaseBuilding = 'CfgBaseBuilding' call EPOCH_returnConfig; + _loots = getArray(_config >> "loottypes"); + _lootLimit = (round random(getNumber(_config >> "limit"))) max 1; + _possibleLoots = []; + { + _x params ["_posNameTMP","_class","_randomColor"]; + _posName = _posNameTMP; + _positions = getArray(_config >> _posName); + { + _possibleLoots pushBack [_class,_randomColor,_x]; + } forEach _positions; + } forEach _loots; + if !(_possibleLoots isEqualTo []) then { + for "_i" from 1 to _lootLimit do { + _possibleCount = count _possibleLoots; + if (_possibleCount > 0) then { + _randomIndex = (floor random(_possibleCount)); + _selectedLoot = _possibleLoots deleteAt _randomIndex; + _selectedLoot params ["_class","_randomColor","_position"]; + _position params ["_m2WPos","_relDir"]; + _pos = _building modelToWorld _m2WPos; + if (_pos select 2 < 0) then { + _pos set[2, 0]; + }; + if (_class isEqualType []) then { + _class = selectRandom _class; + }; + _dir = _relDir + (getDir _building); + _color = ""; + if (_randomColor isEqualTo "true") then { + _colors = getArray(_cfgBaseBuilding >> _class >> "availableTextures"); + if !(_colors isEqualTo[]) then { + _color = selectRandom _colors; + }; + }; + (_buildingLoot select 2) pushback [_class, _pos, _dir, _color]; + }; + }; + }; + } + else { + if ((random 100) < (getNumber (_config >> "GroundSpawnChance"))) then { + _buildingLoot = [_building,"GroundLoot",[]]; + _MinGroundContainers = getNumber (_config >> "MinGroundContainers"); + _MaxGroundContainers = getNumber (_config >> "MaxGroundContainers"); + _lootType = getText(_config >> "lootType"); + _loots = getArray(_config >> "loottypes"); + _positions = []; + { + _x params ["_posName","_class","_randomColor"]; + if !((tolower _posName) in ["cabinetpos","toolrackpos"]) then { + _positions = _positions + getArray (_config >> _posName); + }; + } forEach _loots; + if !(_positions isEqualTo []) then { + for "_i" from 1 to (_MinGroundContainers + (round (random (_MaxGroundContainers - _MinGroundContainers)))) do { + if ((count _positions) > 0) then { + _position = _positions deleteat (floor (random (count _positions))); + _position params ["_m2WPos","_relDir"]; + _pos = _building modelToWorld _m2WPos; + _pos vectoradd [0,0,0.1]; + if (_pos select 2 < 0) then { + _pos set[2, 0]; + }; + (_buildingLoot select 2) pushback [_lootType,_pos]; + }; + }; + }; + }; + }; + if !(_buildingLoot isEqualTo []) then { + _LootsArray pushback _buildingLoot; + }; + }; + } foreach _objects; + if !(_LootsArray isEqualTo []) then { + [player,Epoch_personalToken,_LootsArray] remoteExec ["EPOCH_server_spawnLoot",2]; + }; }; }; -call _lootBubble; // init weather temperature var if not already set if (isNil "EPOCH_CURRENT_WEATHER") then { diff --git a/Sources/epoch_config/Configs/CfgBuildingLootPos.hpp b/Sources/epoch_config/Configs/CfgBuildingLootPos.hpp index f3136cca..69bf74de 100644 --- a/Sources/epoch_config/Configs/CfgBuildingLootPos.hpp +++ b/Sources/epoch_config/Configs/CfgBuildingLootPos.hpp @@ -31,7 +31,7 @@ class CfgBuildingLootPos toiletPos[] = {}; kitchenSinkPos[] = {}; lootBias = 40; - lootTypes[] = {{"shelfPos","Shelf_EPOCH",true},{"fridgePos","Fridge_EPOCH",true},{"bedPos","Bed_EPOCH",false},{"couchPos","Couch_EPOCH",false},{"wardrobePos","wardrobe_epoch",false},{"cookerPos","cooker_epoch",false},{"chairPos",{"Chair_EPOCH","ChairRed_EPOCH"},true},{"filingPos","Filing_epoch",true},{"pelicanPos","Pelican_EPOCH",false},{"tablePos","Table_EPOCH",false},{"lockerPos","Locker_EPOCH",false},{"toolRackPos","ToolRack_EPOCH",false},{"shoeboxPos","Shoebox_EPOCH",false},{"palletPos","Tarp_EPOCH",false},{"freezerPos","Freezer_EPOCH",false},{"cabinetPos","Cabinet_EPOCH",false},{"toiletPos","toilet_epoch",false},{"kitchenSinkPos","KitchenSink_epoch",false}}; + lootTypes[] = {{"shelfPos","Shelf_EPOCH",false},{"fridgePos","Fridge_EPOCH",false},{"bedPos","Bed_EPOCH",false},{"couchPos","Couch_EPOCH",false},{"wardrobePos","wardrobe_epoch",false},{"cookerPos","cooker_epoch",false},{"chairPos",{"Chair_EPOCH","ChairRed_EPOCH"},false},{"filingPos","Filing_epoch",false},{"pelicanPos","Pelican_EPOCH",false},{"tablePos","Table_EPOCH",false},{"lockerPos","Locker_EPOCH",false},{"toolRackPos","ToolRack_EPOCH",false},{"shoeboxPos","Shoebox_EPOCH",false},{"palletPos","Tarp_EPOCH",false},{"freezerPos","Freezer_EPOCH",false},{"cabinetPos","Cabinet_EPOCH",false},{"toiletPos","toilet_epoch",false},{"kitchenSinkPos","KitchenSink_epoch",false}}; EpochLootChance = 20; // 20% of this Building Types will hold default Epoch Loot limit = 3; // Max 3 Furnitures will spawn in this Building type diff --git a/Sources/epoch_server/compile/epoch_looting/EPOCH_server_spawnLoot.sqf b/Sources/epoch_server/compile/epoch_looting/EPOCH_server_spawnLoot.sqf index 70bbd6d9..0a25c589 100644 --- a/Sources/epoch_server/compile/epoch_looting/EPOCH_server_spawnLoot.sqf +++ b/Sources/epoch_server/compile/epoch_looting/EPOCH_server_spawnLoot.sqf @@ -17,57 +17,24 @@ private [ "_masterConfig","_building","_buildingLoot","_selectedConfig","_config "_pos","_dir","_item","_color","_GroundSpawnChance","_MinGroundContainers","_MaxGroundContainers","_lootType" ]; -params [["_player",objNull,[objNull]],["_token","",[""]],["_objects",[]]]; +params [["_player",objNull,[objNull]],["_token","",[""]],["_LootsArray",[]]]; if !([_player, _token] call EPOCH_server_getPToken) exitWith{}; _masterConfig = getmissionconfig "CfgBuildingLootPos"; { - _building = _x; - _buildingLoot = []; - if !(_building in Epoch_LootedBuildings) then { - _building setvariable ["Epoch_LootCleanup",diag_ticktime + Epoch_LootCleanupTime]; - Epoch_LootedBuildings pushBackUnique _building; - _selectedConfig = typeOf _building; - if (_selectedConfig isEqualTo "") then { - (getModelInfo _building) params [["_modelName",""]]; - if (!isnil "_modelName") then { - _selectedConfig = (_modelName splitString " .") joinString "_"; - }; - }; - _config = _masterConfig >> _selectedConfig; - if (isClass(_config)) then { - _EpochLootChance = getNumber (_config >> "EpochLootChance"); - if ((random 100) < _EpochLootChance) then { - _cfgBaseBuilding = 'CfgBaseBuilding' call EPOCH_returnConfig; - _loots = getArray(_config >> "loottypes"); - _lootLimit = (round random(getNumber(_config >> "limit"))) max 1; - _possibleLoots = []; - { - _x params ["_posNameTMP","_class","_randomColor"]; - _posName = _posNameTMP; - _positions = getArray(_config >> _posName); + _x params [["_Building",objnull],["_LootType",""],["_buildingLootArray",[]]]; + if (!isnull _Building) then { + if !(_building in Epoch_LootedBuildings) then { + _buildingLoot = []; + _building setvariable ["Epoch_LootCleanup",diag_ticktime + Epoch_LootCleanupTime]; + Epoch_LootedBuildings pushBackUnique _building; + switch _LootType do { + case "EpochLoot": { { - _possibleLoots pushBack [_class,_randomColor,_x]; - } forEach _positions; - } forEach _loots; - if !(_possibleLoots isEqualTo []) then { - for "_i" from 1 to _lootLimit do { - _possibleCount = count _possibleLoots; - if (_possibleCount > 0) then { - _randomIndex = (floor random(_possibleCount)); - _selectedLoot = _possibleLoots deleteAt _randomIndex; - _selectedLoot params ["_class","_randomColor","_position"]; - _position params ["_m2WPos","_relDir"]; - _pos = _building modelToWorld _m2WPos; - if (_pos select 2 < 0) then { - _pos set[2, 0]; - }; - if (_class isEqualType []) then { - _class = selectRandom _class; - }; - _dir = _relDir + (getDir _building); - _item = createVehicle[_class, _pos, [], 0, "CAN_COLLIDE"]; + _x params ["_class","_pos","_dir","_color"]; + if (_class in (call Epoch_LootContainers)) then { + _item = createVehicle [_class, _pos, [], 0, "CAN_COLLIDE"]; _item setvariable ["Epoch_ParentBuilding",_building]; _buildingLoot pushback _item; _item setDir _dir; @@ -77,57 +44,32 @@ _masterConfig = getmissionconfig "CfgBuildingLootPos"; else { _item setPosATL _pos; }; - if (_randomColor isEqualTo "true") then { - _colors = getArray(_cfgBaseBuilding >> _class >> "availableTextures"); - if !(_colors isEqualTo[]) then { - _color = selectRandom _colors; - _item setObjectTextureGlobal[0, _color]; - }; + if !(_color isEqualTo "") then { + _item setObjectTextureGlobal [0, _color]; }; }; - }; - _building setvariable ["Epoch_BuildingLoot",_buildingLoot]; + } foreach _buildingLootArray; }; - } - else { - _GroundSpawnChance = getNumber (_config >> "GroundSpawnChance"); - if ((random 100) < _GroundSpawnChance) then { - _MinGroundContainers = getNumber (_config >> "MinGroundContainers"); - _MaxGroundContainers = getNumber (_config >> "MaxGroundContainers"); - _lootType = getText(_config >> "lootType"); - _loots = getArray(_config >> "loottypes"); - _positions = []; + case "GroundLoot": { { - _x params ["_posName","_class","_randomColor"]; - if !((tolower _posName) in ["cabinetpos","toolrackpos"]) then { - _positions = _positions + getArray (_config >> _posName); + _x params ["_lootType","_pos"]; + _item = createVehicle ["Epoch_LootHolder", _pos, [], 0, "CAN_COLLIDE"]; + _buildingLoot pushback _item; + if (surfaceIsWater _pos) then { + _item setPosASL _pos; + } + else { + _item setPosATL _pos; }; - } forEach _loots; - if !(_positions isEqualTo []) then { - for "_i" from 1 to (_MinGroundContainers + (round (random (_MaxGroundContainers - _MinGroundContainers)))) do { - if ((count _positions) > 0) then { - _position = _positions deleteat (floor (random (count _positions))); - _position params ["_m2WPos","_relDir"]; - _pos = _building modelToWorld _m2WPos; - _pos vectoradd [0,0,0.1]; - if (_pos select 2 < 0) then { - _pos set[2, 0]; - }; - _item = createVehicle ["Epoch_LootHolder", _pos, [], 0, "CAN_COLLIDE"]; - _buildingLoot pushback _item; - if (surfaceIsWater _pos) then { - _item setPosASL _pos; - } - else { - _item setPosATL _pos; - }; - [_item, format ["loots_%1",_lootType]] call EPOCH_serverLootObject; - }; - }; - _building setvariable ["Epoch_BuildingLoot",_buildingLoot,true]; // true for debug! - }; + [_item, format ["loots_%1",_lootType]] call EPOCH_serverLootObject; + + + } foreach _buildingLootArray; }; }; + if !(_buildingLoot isEqualTo []) then { + _building setvariable ["Epoch_BuildingLoot",_buildingLoot]; + }; }; }; -} foreach _objects; \ No newline at end of file +} foreach _LootsArray; \ No newline at end of file diff --git a/Sources/epoch_server/init/server_variables.sqf b/Sources/epoch_server/init/server_variables.sqf index 5fe2fc1a..91ec6838 100644 --- a/Sources/epoch_server/init/server_variables.sqf +++ b/Sources/epoch_server/init/server_variables.sqf @@ -160,3 +160,15 @@ Epoch_LootCleanupTime = getNumber ((getmissionconfig "CfgBuildingLootPos") >> "L if (Epoch_LootCleanupTime == 0) then { Epoch_LootCleanupTime = 300; }; + +Epoch_LootContainers = []; +{ + _x params ["","_class",""]; + if (_class isEqualType []) then { + Epoch_LootContainers = Epoch_LootContainers + _class; + } + else { + Epoch_LootContainers pushback _class; + }; +} forEach (getArray (missionConfigFile >> "CfgBuildingLootPos" >> "Default" >> "lootTypes")); +Epoch_LootContainers = compilefinal (str Epoch_LootContainers); diff --git a/Sources/epoch_server_settings/configs/CfgMainTable.h b/Sources/epoch_server_settings/configs/CfgMainTable.h index 2c942246..1542232d 100644 --- a/Sources/epoch_server_settings/configs/CfgMainTable.h +++ b/Sources/epoch_server_settings/configs/CfgMainTable.h @@ -745,8 +745,8 @@ class CfgMainTable }; class Cabinet_EPOCH : Default { - lootMin = 2; - LootMax = 4; + lootMin = 1; + LootMax = 3; tables[] = { { "Medical", 1 } };