From 506039498950171c8bf7518195482e394c7d9a6c Mon Sep 17 00:00:00 2001 From: vbawol Date: Tue, 3 Oct 2017 10:25:59 -0500 Subject: [PATCH] Simple Garden Manager v1 currently set to run 24 minutes between each "grow" cycle, so from seed to mature should take around 1.2 hours from seed to fully mature. Option to also have mature items spoil on the next cycle (24 minutes). --- .../@epochhive/epochconfig.hpp | 1 + .../epoch_bases/EPOCH_server_saveBuilding.sqf | 5 ++ .../epoch_vehicle/EPOCH_load_storage.sqf | 6 ++ .../EpochEvents/GardenManager.sqf | 69 +++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 Sources/epoch_server_settings/EpochEvents/GardenManager.sqf diff --git a/Server_Install_Pack/@epochhive/epochconfig.hpp b/Server_Install_Pack/@epochhive/epochconfig.hpp index 8e475289..2f300d94 100644 --- a/Server_Install_Pack/@epochhive/epochconfig.hpp +++ b/Server_Install_Pack/@epochhive/epochconfig.hpp @@ -20,6 +20,7 @@ events[] = { { 2700, "Satellite", 0 , 1, -1, {} ,{"VR"}}, { 900, "ChangeWeather", 1 , 1, -1, {} ,{"VR"}}, { 1200, "ContainerSpawner", 0 , 1, -1, {} ,{"VR"}}, + { 1440, "GardenManager", 0 , 1, -1, {} ,{"VR"}}, { 300, "PlantSpawner", 0 , 1 , -1, {} ,{"VR"}} //No comma on last Entry }; diff --git a/Sources/epoch_server/compile/epoch_bases/EPOCH_server_saveBuilding.sqf b/Sources/epoch_server/compile/epoch_bases/EPOCH_server_saveBuilding.sqf index 522c878e..fa7237ee 100644 --- a/Sources/epoch_server/compile/epoch_bases/EPOCH_server_saveBuilding.sqf +++ b/Sources/epoch_server/compile/epoch_bases/EPOCH_server_saveBuilding.sqf @@ -46,6 +46,11 @@ if (isText _staticClassConfig) then { _storageObj = [_staticClass,_vehicle] call EPOCH_swapBuilding; + // add new gardens to manager + if (_staticClass isEqualTo "Garden_EPOCH") then { + EPOCH_activeGardens pushBackUnique _storageObj; + }; + if (_UseIndestructible) then { if ({_storageObj iskindof _x} count _ExceptedBaseObjects == 0) then { { diff --git a/Sources/epoch_server/compile/epoch_vehicle/EPOCH_load_storage.sqf b/Sources/epoch_server/compile/epoch_vehicle/EPOCH_load_storage.sqf index ae9e0bbd..c33a81df 100644 --- a/Sources/epoch_server/compile/epoch_vehicle/EPOCH_load_storage.sqf +++ b/Sources/epoch_server/compile/epoch_vehicle/EPOCH_load_storage.sqf @@ -24,6 +24,7 @@ _ExceptedBaseObjects = [_serverSettingsConfig, "ExceptedBaseObjects", []] call E _diag = diag_tickTime; EPOCH_StorageSlots = []; +EPOCH_activeGardens = []; for "_i" from 1 to _maxStorageLimit do { _storageSlotIndex = EPOCH_StorageSlots pushBack str(_i); _vehHiveKey = format ["%1:%2", (call EPOCH_fn_InstanceID), _i]; @@ -74,6 +75,11 @@ for "_i" from 1 to _maxStorageLimit do { _vehicle = createVehicle[_class, [0,0,0], [], 0, "CAN_COLLIDE"]; + // find gardens + if (_class isEqualTo "Garden_EPOCH") then { + EPOCH_activeGardens pushBack _vehicle; + }; + if (_UseIndestructible) then { if ({_vehicle iskindof _x} count _ExceptedBaseObjects == 0) then { { diff --git a/Sources/epoch_server_settings/EpochEvents/GardenManager.sqf b/Sources/epoch_server_settings/EpochEvents/GardenManager.sqf new file mode 100644 index 00000000..e164b064 --- /dev/null +++ b/Sources/epoch_server_settings/EpochEvents/GardenManager.sqf @@ -0,0 +1,69 @@ +/* + Garden Manager + by Aaron Clark - EpochMod.com + + Improvements and or bugfixes and other contributions are welcome via the github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server_settings/EpochEvents/GardenManager.sqf +*/ +//[[[cog import generate_private_arrays ]]] +private ["_babies","_babyClasses","_cargo","_garden","_mature","_matureClasses","_modifiedGardens","_seedClasses","_seeds","_spoil","_teenClasses","_teens"]; +//[[[end]]] + +_seedClasses = ["SeedPacket_GoldenSeal","SeedP acket_Hemp","SeedPacket_Poppy","SeedPacket_Pumpkin","SeedPacket_Sunflower"]; +_babyClasses = ["Sapling_GoldenSeal","Sapling_Hemp","Sapling_Poppy","Sapling_Pumpkin","Sapling_Sunflower"]; +_teenClasses = ["SaplingTeen_GoldenSeal","SaplingTeen_Hemp","SaplingTeen_Poppy","SaplingTeen_Pumpkin","SaplingTeen_Sunflower"]; +_matureClasses = ["GoldenSeal","Hemp","Poppy","Pumpkin","Sunflower"]; +_spoil = false; + +_modifiedGardens = []; +{ + _garden = _x; + _cargo = magazineCargo _x; + // find all seeds + _seeds = _cargo select {(typeOf _x) in _seedClasses}; + // find all baby plants + _babies = _cargo select {(typeOf _x) in _babyClasses}; + // find all teen plants + _teens = _cargo select {(typeOf _x) in _teenClasses}; + // find all mature plants + _mature = _cargo select {(typeOf _x) in _matureClasses}; + + // normalize storage + clearWeaponCargoGlobal _x; + clearMagazineCargoGlobal _x; + clearBackpackCargoGlobal _x; + clearItemCargoGlobal _x; + + // convert seeds to baby plants. + { + _garden addMagazineCargoGlobal [(_babyClasses param [_seedClasses find _x, _x]), 1]; + } forEach _seeds; + + // convert baby plants to teen + { + _garden addMagazineCargoGlobal [(_teenClasses param [_babyClasses find _x, _x]), 1]; + } forEach _babies; + + // convert teen plants to mature + { + _garden addMagazineCargoGlobal [(_matureClasses param [_teenClasses find _x, _x]), 1]; + } forEach _teens; + + // readd mature plants if spoil == false + if !(_spoil) then { + { + _garden addMagazineCargoGlobal [_x, 1]; + } forEach _mature; + }; + + // push to temp array for save + if !((magazineCargo _garden) isEqualTo _cargo) then { + _modifiedGardens pushBack _garden; + }; + +} forEach (missionNamespace getVariable ["EPOCH_activeGardens", []]); + +// force all modified gardens to save via queue +if !(_modifiedGardens isEqualTo []) then { + _modifiedGardens call EPOCH_server_save_vehicles; +};