From 9f1a3b55323b2989b35d5e94d425be421b969998 Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Fri, 3 Mar 2023 10:53:45 +0100 Subject: [PATCH 1/7] Added dynamic simulation --- cScripts/CfgFunctions.hpp | 12 ++- cScripts/cScripts_preInit.sqf | 29 ++++- .../functions/init/fn_init_simulation.sqf | 100 ++++++++++++++++++ 3 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 cScripts/functions/init/fn_init_simulation.sqf diff --git a/cScripts/CfgFunctions.hpp b/cScripts/CfgFunctions.hpp index 31b499ef4..20494d389 100644 --- a/cScripts/CfgFunctions.hpp +++ b/cScripts/CfgFunctions.hpp @@ -5,6 +5,8 @@ class cScripts { class init_aceTagging {}; class init_aceItemReplace {}; + class init_simulation {}; + class init_skillAdjustment {}; class init_vehicle {}; class init_staging {}; @@ -67,7 +69,7 @@ class cScripts { class getRadioChannel {}; class setRadioChannel {}; class setActiveRadio {}; - + class getCompanyVariable {}; class hasCompanyVariable {}; @@ -87,7 +89,7 @@ class cScripts { class addHaloJump {}; class setVehicleLable {}; - + class addBaseCrate {}; class addStagingZone {}; @@ -123,7 +125,7 @@ class cScripts { class addArsenal {}; class getArsenalWhitelist {}; class getUnitArsenalDefault {}; - + class createActionCategory {}; class doGetOutHeloSide {}; @@ -136,13 +138,13 @@ class cScripts { class getRadioBase {}; class isValidFaction {}; - + class createVehicleLable {}; class getVehicleLable {}; class renameObject {}; class getIcon {}; - + class getAttendance {}; class getServerMetrics {}; }; diff --git a/cScripts/cScripts_preInit.sqf b/cScripts/cScripts_preInit.sqf index 41b40fe75..f19a4fade 100644 --- a/cScripts/cScripts_preInit.sqf +++ b/cScripts/cScripts_preInit.sqf @@ -340,13 +340,25 @@ private _cScriptSettings = "cScripts Mission Settings"; true ] call CBA_fnc_addSetting; +// 9; Preformence +[ // Dynamic Simulation + QEGVAR(Settings,dynamicSimulation), + "LIST", + ["Dynamic Simulation (Experimental)","Enable Dynamic Simulation for Eden and zeus spawned objects automaticly\n"], + [_cScriptSettings, "9; Preformence"], + [[0,1,2,3], ["Disabled", "Enabled", "Enabled (Only Eden Objects)", "Enabled (Only Zeus Spawned Objects)"], 0], + true, + {}, + true +] call CBA_fnc_addSetting; + -// 9; Other +// 10; Other [ // Primary Clan Tag QEGVAR(Settings,primaryClanTag), "EDITBOX", ["Primary Clantag","Primary clan tag to to check for"], - [_cScriptSettings, "9; Other"], + [_cScriptSettings, "10; Other"], '7CAV', true, {}, @@ -380,4 +392,17 @@ if (EGVAR(Settings,setAiSystemDifficulty) >= 1 ) then { call EFUNC(init,eventHandlers); +// Dynamic Simulation handler +if (EGVAR(Settings,dynamicSimulation) >= 1) then { + #ifdef DEBUG_MODE + [format["Dynamic Simulation set to: %1",EGVAR(Settings,dynamicSimulation)], "dynamicSimulation"] call FUNC(logInfo); + #endif + "Group" setDynamicSimulationDistance 1800; + "Vehicle" setDynamicSimulationDistance 2400; + "EmptyVehicle" setDynamicSimulationDistance 250; + "Prop" setDynamicSimulationDistance 50; + enableDynamicSimulationSystem true; + call FUNC(initSimulation); +}; + INFO("preInit", "Initialization completed."); diff --git a/cScripts/functions/init/fn_init_simulation.sqf b/cScripts/functions/init/fn_init_simulation.sqf new file mode 100644 index 000000000..03337fb39 --- /dev/null +++ b/cScripts/functions/init/fn_init_simulation.sqf @@ -0,0 +1,100 @@ +#include "..\script_component.hpp"; +/* + * Author: CPL.Brostrom.A + * This function add eventhandelers adding cav functionality to units and vehicles. + * + * Return Value: + * Nothing + * + * Example: + * call cScripts_fnc_init_simulation + * + * Public: No + */ + +#ifdef DEBUG_MODE + ["Applying Event Handers (init) to mission objects...", "InitSimulation"] call FUNC(logInfo); +#endif + +// Enables player trigger for dynamic simulation +player triggerDynamicSimulation true; // FIXME does this work? + + +if (EGVAR(Settings,dynamicSimulation) <= 2) then { + ["CAManBase", "init", { + (_this select 0) enableDynamicSimulation true; + group (_this select 0) enableDynamicSimulation true; + if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false; }; + }, true, [], true] call CBA_fnc_addClassEventHandler; + ["Tank", "init", { + (_this select 0) enableDynamicSimulation true; + if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; + _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; + }, true, [], true] call CBA_fnc_addClassEventHandler; + ["Car", "init", { + (_this select 0) enableDynamicSimulation true; + if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; + _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; + }, true, [], true] call CBA_fnc_addClassEventHandler; + ["Ship", "init", { + (_this select 0) enableDynamicSimulation true; + if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; + _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; + }, true, [], true] call CBA_fnc_addClassEventHandler; + ["Thing", "init", { + (_this select 0) enableDynamicSimulation true; + if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; + _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; + }, true, [], true] call CBA_fnc_addClassEventHandler; + ["ThingX", "init", { + (_this select 0) enableDynamicSimulation true; + if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; + _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; + }, true, [], true] call CBA_fnc_addClassEventHandler; + + ["Air", "init", { + [{ + private _vehicle = _this select 0; + { + #ifdef DEBUG_MODE + [format["Disabling DynamicSimulation for aircrew unit: %1", _x], "InitSimulation"] call FUNC(logInfo); + #endif + group (_x) enableDynamicSimulation false; + _x enableDynamicSimulation false; + } forEach crew _vehicle; + }, [_this select 0], 3] call CBA_fnc_waitAndExecute; + }, true, [], true] call CBA_fnc_addClassEventHandler; +}; + +// Disable Dynamic Simulation On curator Objects +if (EGVAR(Settings,dynamicSimulation) == 2) then { + ["All", "init", { + [{ + private _vehicle = _this select 0; + _vehicle addEventHandler ["CuratorObjectPlaced", { + params ["_curator", "_entity"]; + #ifdef DEBUG_MODE + [format["Disabling DynamicSimulation for curator spawned: %1", _entity], "InitSimulation"] call FUNC(logInfo); + #endif + group (_entity) enableDynamicSimulation false; + _entity enableDynamicSimulation false; + }]; + }, [_this select 0], 3] call CBA_fnc_waitAndExecute; + }, true, [], true] call CBA_fnc_addClassEventHandler; +}; +// Enable Dynamic Simulation On curator Objects +if (EGVAR(Settings,dynamicSimulation) == 3) then { + ["All", "init", { + [{ + private _vehicle = _this select 0; + _vehicle addEventHandler ["CuratorObjectPlaced", { + params ["_curator", "_entity"]; + #ifdef DEBUG_MODE + [format["Enabling DynamicSimulation for curator spawned: %1", _entity], "InitSimulation"] call FUNC(logInfo); + #endif + group (_entity) enableDynamicSimulation true; + _entity enableDynamicSimulation true; + }]; + }, [_this select 0], 3] call CBA_fnc_waitAndExecute; + }, true, [], true] call CBA_fnc_addClassEventHandler; +}; From 7d0c276e0c3b09beff045101f67db5acead3d721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brostr=C3=B6m=2EA=20=7C=20Evul?= Date: Mon, 20 Mar 2023 10:59:21 +0100 Subject: [PATCH 2/7] modernized the system and added a block for the system if airframes exist --- cScripts/cScripts_preInit.sqf | 10 +--- .../functions/init/fn_init_simulation.sqf | 56 ++++++++++++++----- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/cScripts/cScripts_preInit.sqf b/cScripts/cScripts_preInit.sqf index f19a4fade..b79e7660f 100644 --- a/cScripts/cScripts_preInit.sqf +++ b/cScripts/cScripts_preInit.sqf @@ -394,15 +394,7 @@ call EFUNC(init,eventHandlers); // Dynamic Simulation handler if (EGVAR(Settings,dynamicSimulation) >= 1) then { - #ifdef DEBUG_MODE - [format["Dynamic Simulation set to: %1",EGVAR(Settings,dynamicSimulation)], "dynamicSimulation"] call FUNC(logInfo); - #endif - "Group" setDynamicSimulationDistance 1800; - "Vehicle" setDynamicSimulationDistance 2400; - "EmptyVehicle" setDynamicSimulationDistance 250; - "Prop" setDynamicSimulationDistance 50; - enableDynamicSimulationSystem true; - call FUNC(initSimulation); + call EFUNC(init,simulation); }; INFO("preInit", "Initialization completed."); diff --git a/cScripts/functions/init/fn_init_simulation.sqf b/cScripts/functions/init/fn_init_simulation.sqf index 03337fb39..acdd9a7bc 100644 --- a/cScripts/functions/init/fn_init_simulation.sqf +++ b/cScripts/functions/init/fn_init_simulation.sqf @@ -7,20 +7,44 @@ * Nothing * * Example: - * call cScripts_fnc_init_simulation + * call EFUNC(init,simulation) * * Public: No */ +if (EGVAR(Settings,dynamicSimulation) == 0) exitWith {}; + +// Dont enable system if there are airfames +// TODO make this system work with airframes in a reliable way +private _hasAirframes = { + if (_x isKindOf "Air") exitWith {true}; +} forEach vehicles; +if (_hasAirframes) exitWith { + ["Dynamic Simulation have terminated it self due to mission containing airframes.", "dynamicSimulation"] call FUNC(warning); +}; + #ifdef DEBUG_MODE - ["Applying Event Handers (init) to mission objects...", "InitSimulation"] call FUNC(logInfo); + [format["Dynamic Simulation set to: %1",EGVAR(Settings,dynamicSimulation)], "dynamicSimulation"] call FUNC(info); #endif +"Group" setDynamicSimulationDistance 1800; +"Vehicle" setDynamicSimulationDistance 2400; +"EmptyVehicle" setDynamicSimulationDistance 250; +"Prop" setDynamicSimulationDistance 50; +enableDynamicSimulationSystem true; + // Enables player trigger for dynamic simulation -player triggerDynamicSimulation true; // FIXME does this work? +player triggerDynamicSimulation true; + + +if (!isServer) exitWith {}; +// Apply event handlers to objects +if ((EGVAR(Settings,dynamicSimulation) == 1) || (EGVAR(Settings,dynamicSimulation) == 2)) then { + #ifdef DEBUG_MODE + ["Applying Event Handers (init) to mission objects...", "InitSimulation"] call FUNC(info); + #endif -if (EGVAR(Settings,dynamicSimulation) <= 2) then { ["CAManBase", "init", { (_this select 0) enableDynamicSimulation true; group (_this select 0) enableDynamicSimulation true; @@ -52,12 +76,13 @@ if (EGVAR(Settings,dynamicSimulation) <= 2) then { _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; }, true, [], true] call CBA_fnc_addClassEventHandler; + // Disable activation and enabeling of simulation for airframes ["Air", "init", { [{ private _vehicle = _this select 0; { #ifdef DEBUG_MODE - [format["Disabling DynamicSimulation for aircrew unit: %1", _x], "InitSimulation"] call FUNC(logInfo); + [format["Disabling DynamicSimulation for aircrew unit: %1", _x], "InitSimulation"] call FUNC(info); #endif group (_x) enableDynamicSimulation false; _x enableDynamicSimulation false; @@ -74,7 +99,7 @@ if (EGVAR(Settings,dynamicSimulation) == 2) then { _vehicle addEventHandler ["CuratorObjectPlaced", { params ["_curator", "_entity"]; #ifdef DEBUG_MODE - [format["Disabling DynamicSimulation for curator spawned: %1", _entity], "InitSimulation"] call FUNC(logInfo); + [format["Disabling DynamicSimulation for curator spawned: %1", _entity], "InitSimulation"] call FUNC(info); #endif group (_entity) enableDynamicSimulation false; _entity enableDynamicSimulation false; @@ -82,19 +107,22 @@ if (EGVAR(Settings,dynamicSimulation) == 2) then { }, [_this select 0], 3] call CBA_fnc_waitAndExecute; }, true, [], true] call CBA_fnc_addClassEventHandler; }; + // Enable Dynamic Simulation On curator Objects if (EGVAR(Settings,dynamicSimulation) == 3) then { ["All", "init", { [{ private _vehicle = _this select 0; - _vehicle addEventHandler ["CuratorObjectPlaced", { - params ["_curator", "_entity"]; - #ifdef DEBUG_MODE - [format["Enabling DynamicSimulation for curator spawned: %1", _entity], "InitSimulation"] call FUNC(logInfo); - #endif - group (_entity) enableDynamicSimulation true; - _entity enableDynamicSimulation true; - }]; + if !(_vehicle isKindOf "Air") then { + _vehicle addEventHandler ["CuratorObjectPlaced", { + params ["_curator", "_entity"]; + #ifdef DEBUG_MODE + [format["Enabling DynamicSimulation for curator spawned: %1", _entity], "InitSimulation"] call FUNC(info); + #endif + group (_entity) enableDynamicSimulation true; + _entity enableDynamicSimulation true; + }]; + }; }, [_this select 0], 3] call CBA_fnc_waitAndExecute; }, true, [], true] call CBA_fnc_addClassEventHandler; }; From 60c5776da8a59d697f983b1acc7ad2c3c06d65ee Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Wed, 29 Nov 2023 16:35:13 +0100 Subject: [PATCH 3/7] Cleaning and simplyfied the system --- cScripts/cScripts_preInit.sqf | 8 +- .../functions/init/fn_init_simulation.sqf | 140 ++++++------------ 2 files changed, 52 insertions(+), 96 deletions(-) diff --git a/cScripts/cScripts_preInit.sqf b/cScripts/cScripts_preInit.sqf index 77a67c5cc..1157bd81f 100644 --- a/cScripts/cScripts_preInit.sqf +++ b/cScripts/cScripts_preInit.sqf @@ -332,13 +332,13 @@ private _cScriptSettings = "cScripts Mission Settings"; true ] call CBA_fnc_addSetting; -// 9; Preformence +// 9; Performance [ // Dynamic Simulation QEGVAR(Settings,dynamicSimulation), "LIST", - ["Dynamic Simulation (Experimental)","Enable Dynamic Simulation for Eden and zeus spawned objects automaticly\n"], - [_cScriptSettings, "9; Preformence"], - [[0,1,2,3], ["Disabled", "Enabled", "Enabled (Only Eden Objects)", "Enabled (Only Zeus Spawned Objects)"], 0], + ["Dynamic Simulation (Experimental)","Enable Dynamic Simulation for Eden and zeus spawned objects automatically\n"], + [_cScriptSettings, "9; Performance"], + [[0,1], ["Disabled", "Enabled"], 0], true, {}, true diff --git a/cScripts/functions/init/fn_init_simulation.sqf b/cScripts/functions/init/fn_init_simulation.sqf index acdd9a7bc..bcf897182 100644 --- a/cScripts/functions/init/fn_init_simulation.sqf +++ b/cScripts/functions/init/fn_init_simulation.sqf @@ -14,115 +14,71 @@ if (EGVAR(Settings,dynamicSimulation) == 0) exitWith {}; -// Dont enable system if there are airfames -// TODO make this system work with airframes in a reliable way +// Don't enable system if there are airframes +// TODO: make this system work with airframes in a reliable way private _hasAirframes = { if (_x isKindOf "Air") exitWith {true}; } forEach vehicles; if (_hasAirframes) exitWith { - ["Dynamic Simulation have terminated it self due to mission containing airframes.", "dynamicSimulation"] call FUNC(warning); + SHOW_WARNING("DynamicSimulation", "Dynamic Simulation have terminated it self due to mission containing airframes"); }; -#ifdef DEBUG_MODE - [format["Dynamic Simulation set to: %1",EGVAR(Settings,dynamicSimulation)], "dynamicSimulation"] call FUNC(info); -#endif +INFO_1("DynamicSimulation", "Dynamic Simulation set to: %1", EGVAR(Settings,dynamicSimulation)); +// System Values "Group" setDynamicSimulationDistance 1800; "Vehicle" setDynamicSimulationDistance 2400; "EmptyVehicle" setDynamicSimulationDistance 250; "Prop" setDynamicSimulationDistance 50; +"IsMoving" setDynamicSimulationDistanceCoef 3; + enableDynamicSimulationSystem true; // Enables player trigger for dynamic simulation player triggerDynamicSimulation true; -if (!isServer) exitWith {}; - // Apply event handlers to objects -if ((EGVAR(Settings,dynamicSimulation) == 1) || (EGVAR(Settings,dynamicSimulation) == 2)) then { - #ifdef DEBUG_MODE - ["Applying Event Handers (init) to mission objects...", "InitSimulation"] call FUNC(info); - #endif +INFO_1("DynamicSimulation", "Applying Event Handers (init) to mission objects..."); - ["CAManBase", "init", { - (_this select 0) enableDynamicSimulation true; - group (_this select 0) enableDynamicSimulation true; - if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false; }; - }, true, [], true] call CBA_fnc_addClassEventHandler; - ["Tank", "init", { - (_this select 0) enableDynamicSimulation true; - if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; - _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; - }, true, [], true] call CBA_fnc_addClassEventHandler; - ["Car", "init", { - (_this select 0) enableDynamicSimulation true; - if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; - _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; - }, true, [], true] call CBA_fnc_addClassEventHandler; - ["Ship", "init", { - (_this select 0) enableDynamicSimulation true; - if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; - _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; - }, true, [], true] call CBA_fnc_addClassEventHandler; - ["Thing", "init", { - (_this select 0) enableDynamicSimulation true; - if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; - _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; - }, true, [], true] call CBA_fnc_addClassEventHandler; - ["ThingX", "init", { - (_this select 0) enableDynamicSimulation true; - if (!isPlayer (_this select 0)) then { (_this select 0) triggerDynamicSimulation false }; - _this select 0 addEventHandler ["CuratorObjectPlaced", { [{_this select 0 enableDynamicSimulation false; }, [_this select 1], 3] call CBA_fnc_waitAndExecute;}]; - }, true, [], true] call CBA_fnc_addClassEventHandler; - - // Disable activation and enabeling of simulation for airframes - ["Air", "init", { - [{ - private _vehicle = _this select 0; - { - #ifdef DEBUG_MODE - [format["Disabling DynamicSimulation for aircrew unit: %1", _x], "InitSimulation"] call FUNC(info); - #endif - group (_x) enableDynamicSimulation false; - _x enableDynamicSimulation false; - } forEach crew _vehicle; - }, [_this select 0], 3] call CBA_fnc_waitAndExecute; - }, true, [], true] call CBA_fnc_addClassEventHandler; -}; +["CAManBase", "initPost", { + params ["_unit"]; + _unit enableDynamicSimulation true; + if (!isPlayer _unit) then { _unit triggerDynamicSimulation false }; +}, true, [], true] call CBA_fnc_addClassEventHandler; +["Tank", "initPost", { + params ["_vehicle"]; + _vehicle enableDynamicSimulation true; + if (!isPlayer _vehicle) then { _vehicle triggerDynamicSimulation false }; +}, true, [], true] call CBA_fnc_addClassEventHandler; +["Car", "initPost", { + params ["_vehicle"]; + _vehicle enableDynamicSimulation true; + if (!isPlayer _vehicle) then { _vehicle triggerDynamicSimulation false }; +}, true, [], true] call CBA_fnc_addClassEventHandler; +["Ship", "initPost", { + params ["_vehicle"]; + _vehicle enableDynamicSimulation true; + if (!isPlayer _vehicle) then { _vehicle triggerDynamicSimulation false }; +}, true, [], true] call CBA_fnc_addClassEventHandler; +["Thing", "initPost", { + params ["_object"]; + _object enableDynamicSimulation true; +}, true, [], true] call CBA_fnc_addClassEventHandler; +["ThingX", "initPost", { + params ["_object"]; + _object enableDynamicSimulation true; +}, true, [], true] call CBA_fnc_addClassEventHandler; -// Disable Dynamic Simulation On curator Objects -if (EGVAR(Settings,dynamicSimulation) == 2) then { - ["All", "init", { - [{ - private _vehicle = _this select 0; - _vehicle addEventHandler ["CuratorObjectPlaced", { - params ["_curator", "_entity"]; - #ifdef DEBUG_MODE - [format["Disabling DynamicSimulation for curator spawned: %1", _entity], "InitSimulation"] call FUNC(info); - #endif - group (_entity) enableDynamicSimulation false; - _entity enableDynamicSimulation false; - }]; - }, [_this select 0], 3] call CBA_fnc_waitAndExecute; - }, true, [], true] call CBA_fnc_addClassEventHandler; -}; - -// Enable Dynamic Simulation On curator Objects -if (EGVAR(Settings,dynamicSimulation) == 3) then { - ["All", "init", { - [{ - private _vehicle = _this select 0; - if !(_vehicle isKindOf "Air") then { - _vehicle addEventHandler ["CuratorObjectPlaced", { - params ["_curator", "_entity"]; - #ifdef DEBUG_MODE - [format["Enabling DynamicSimulation for curator spawned: %1", _entity], "InitSimulation"] call FUNC(info); - #endif - group (_entity) enableDynamicSimulation true; - _entity enableDynamicSimulation true; - }]; - }; - }, [_this select 0], 3] call CBA_fnc_waitAndExecute; - }, true, [], true] call CBA_fnc_addClassEventHandler; -}; +// Enabling animations for airframes +["Air", "initPost", { + params ["_vehicle"]; + [{ + params ["_vehicle"]; + { + INFO_1("DynamicSimulation", "Disabling DynamicSimulation for aircrew unit: %1", _x); + group (_x) enableDynamicSimulation false; + _x enableDynamicSimulation false; + } forEach crew _vehicle; + }, [_vehicle], 3] call CBA_fnc_waitAndExecute; +}, true, [], true] call CBA_fnc_addClassEventHandler; \ No newline at end of file From 859ca22fd440b56369a88846e7fa6032bbf4b196 Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Thu, 7 Dec 2023 20:04:07 +0100 Subject: [PATCH 4/7] Updated script --- cScripts/CfgFunctions.hpp | 4 - .../functions/init/fn_init_simulation.sqf | 112 +++++++++++++++--- 2 files changed, 98 insertions(+), 18 deletions(-) diff --git a/cScripts/CfgFunctions.hpp b/cScripts/CfgFunctions.hpp index 6d1996425..9ce30ea04 100644 --- a/cScripts/CfgFunctions.hpp +++ b/cScripts/CfgFunctions.hpp @@ -139,11 +139,7 @@ class cScripts { // Buttons and options class addReGear {}; class addHeal {}; - class addArsenal {}; - class getArsenalWhitelist {}; - class getUnitArsenalDefault {}; - class createActionCategory {}; class doGetOutHeloSide {}; diff --git a/cScripts/functions/init/fn_init_simulation.sqf b/cScripts/functions/init/fn_init_simulation.sqf index bcf897182..f5ab9e61c 100644 --- a/cScripts/functions/init/fn_init_simulation.sqf +++ b/cScripts/functions/init/fn_init_simulation.sqf @@ -1,3 +1,4 @@ +#define DEBUG_MODE #include "..\script_component.hpp"; /* * Author: CPL.Brostrom.A @@ -18,12 +19,13 @@ if (EGVAR(Settings,dynamicSimulation) == 0) exitWith {}; // TODO: make this system work with airframes in a reliable way private _hasAirframes = { if (_x isKindOf "Air") exitWith {true}; + false } forEach vehicles; if (_hasAirframes) exitWith { SHOW_WARNING("DynamicSimulation", "Dynamic Simulation have terminated it self due to mission containing airframes"); }; -INFO_1("DynamicSimulation", "Dynamic Simulation set to: %1", EGVAR(Settings,dynamicSimulation)); +INFO("DynamicSimulation", "Dynamic Simulation Enabled"); // System Values "Group" setDynamicSimulationDistance 1800; @@ -38,40 +40,122 @@ enableDynamicSimulationSystem true; player triggerDynamicSimulation true; + +// Handle AA units +private _antiAircraftUnits = []; +{ + private _name = configName _x; + private _nameLower = toLower _name; + if (["_aa", _nameLower] call BIS_fnc_inString) then { + if ((["_aaf", _nameLower] call BIS_fnc_inString)) then { + if (["_aa_aaf", _nameLower] call BIS_fnc_inString) then { + LOG_1("DEBUG", "AA UNIT: %1 (_aa_aaf)", _name); + _antiAircraftUnits append [_name]; + continue + }; + }; + if (["_aa_", _nameLower] call BIS_fnc_inString) then { + LOG_1("DEBUG", "AA UNIT: %1 (_aa_)", _name); + _antiAircraftUnits append [_name]; + continue + }; + }; + if (["zu23", _nameLower] call BIS_fnc_inString) then { + LOG_1("DEBUG", "AA UNIT: %1 (zu23)", _name); + _antiAircraftUnits append [_name]; + continue + }; +} forEach ("configName _x isKindOf 'LandVehicle'" configClasses (configFile >> "CfgVehicles")); + +diag_log format ["O_Soldier_AA_F, %1", ("O_Soldier_AA_F" in _antiAircraftUnits)]; + // Apply event handlers to objects -INFO_1("DynamicSimulation", "Applying Event Handers (init) to mission objects..."); +INFO("DynamicSimulation", "Applying Event Handers (init) to mission objects..."); -["CAManBase", "initPost", { +["CAManBase", "init", { params ["_unit"]; + if (!isPlayer _unit) then {_unit triggerDynamicSimulation false}; + INFO_2("DynamicSimulation", "Enabling dynamic simulation system for unit %1 (%2)", _unit, typeOf _unit); + group _unit enableDynamicSimulation true; _unit enableDynamicSimulation true; - if (!isPlayer _unit) then { _unit triggerDynamicSimulation false }; }, true, [], true] call CBA_fnc_addClassEventHandler; -["Tank", "initPost", { +["Tank", "init", { params ["_vehicle"]; + _vehicle triggerDynamicSimulation false; + INFO_2("DynamicSimulation", "Enabling dynamic simulation system for vehicle %1 (%2)", _vehicle, typeOf _vehicle); _vehicle enableDynamicSimulation true; - if (!isPlayer _vehicle) then { _vehicle triggerDynamicSimulation false }; }, true, [], true] call CBA_fnc_addClassEventHandler; -["Car", "initPost", { +["Car", "init", { params ["_vehicle"]; + INFO_2("DynamicSimulation", "Enabling dynamic simulation system for vehicle %1 (%2)", _vehicle, typeOf _vehicle); + _vehicle triggerDynamicSimulation false; _vehicle enableDynamicSimulation true; - if (!isPlayer _vehicle) then { _vehicle triggerDynamicSimulation false }; }, true, [], true] call CBA_fnc_addClassEventHandler; -["Ship", "initPost", { +["Ship", "init", { params ["_vehicle"]; + INFO_2("DynamicSimulation", "Enabling dynamic simulation system for vehicle %1 (%2)", _vehicle, typeOf _vehicle); + _vehicle triggerDynamicSimulation false; _vehicle enableDynamicSimulation true; - if (!isPlayer _vehicle) then { _vehicle triggerDynamicSimulation false }; }, true, [], true] call CBA_fnc_addClassEventHandler; -["Thing", "initPost", { +["Thing", "init", { params ["_object"]; + INFO_2("DynamicSimulation", "Enabling dynamic simulation system for object %1 (%2)", _object, typeOf _object); + _object triggerDynamicSimulation false; _object enableDynamicSimulation true; }, true, [], true] call CBA_fnc_addClassEventHandler; -["ThingX", "initPost", { +["ThingX", "init", { params ["_object"]; + INFO_2("DynamicSimulation", "Enabling dynamic simulation system for object %1 (%2)", _object, typeOf _object); + _object triggerDynamicSimulation false; _object enableDynamicSimulation true; }, true, [], true] call CBA_fnc_addClassEventHandler; -// Enabling animations for airframes -["Air", "initPost", { + +// Enabling animations for AA and Airframes +["CAManBase", "init", { + params ["_unit"]; + if (typeOf _unit in _antiAircraftUnits) exitWith { + [{ + params ["_unit"]; + INFO_2("DynamicSimulation", "Dynamic simulation system disabeld for Anti Aircraft unit %1 (%2)", _unit, typeOf _unit); + _unit enableDynamicSimulation false; + { + group (_x) enableDynamicSimulation false; + _x enableDynamicSimulation false; + } forEach crew _vehicle; + }, [_unit], 2] call CBA_fnc_waitAndExecute; + }; +}, true, [], true] call CBA_fnc_addClassEventHandler; +["Tank", "init", { + params ["_vehicle"]; + if (typeOf _vehicle in _antiAircraftUnits) exitWith { + [{ + params ["_vehicle"]; + INFO_2("DynamicSimulation", "Dynamic simulation system disabeld for Anti Aircraft vehicle %1 (%2)", _vehicle, typeOf _vehicle); + _vehicle enableDynamicSimulation false; + { + group (_x) enableDynamicSimulation false; + _x enableDynamicSimulation false; + } forEach crew _vehicle; + }, [_vehicle], 2] call CBA_fnc_waitAndExecute; + }; +}, true, [], true] call CBA_fnc_addClassEventHandler; +["Car", "init", { + params ["_vehicle"]; + if (typeOf _vehicle in _antiAircraftUnits) exitWith { + [{ + params ["_vehicle"]; + INFO_2("DynamicSimulation", "Dynamic simulation system disabeld for Anti Aircraft vehicle %1 (%2)", _vehicle, typeOf _vehicle); + _vehicle enableDynamicSimulation false; + { + group (_x) enableDynamicSimulation false; + _x enableDynamicSimulation false; + } forEach crew _vehicle; + }, [_vehicle], 2] call CBA_fnc_waitAndExecute; + }; +}, true, [], true] call CBA_fnc_addClassEventHandler; + +["Air", "init", { params ["_vehicle"]; [{ params ["_vehicle"]; From 5be47353f6a635cc180d958b1079d8807b9c7c2e Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Thu, 7 Dec 2023 21:05:44 +0100 Subject: [PATCH 5/7] Adjustments and updates --- cScripts/CfgFunctions.hpp | 2 +- .../functions/init/fn_init_chatCommands.sqf | 7 +++ .../functions/init/fn_init_simulation.sqf | 60 ++++++++++++++----- .../functions/init/fn_init_zenModuels.sqf | 4 +- .../fn_zenModule_enableUnitSimulation.sqf | 36 ----------- .../fn_zenModule_toggleUnitSimulation.sqf | 46 ++++++++++++++ 6 files changed, 100 insertions(+), 55 deletions(-) delete mode 100644 cScripts/functions/modules/fn_zenModule_enableUnitSimulation.sqf create mode 100644 cScripts/functions/modules/fn_zenModule_toggleUnitSimulation.sqf diff --git a/cScripts/CfgFunctions.hpp b/cScripts/CfgFunctions.hpp index 9ce30ea04..b493c34f7 100644 --- a/cScripts/CfgFunctions.hpp +++ b/cScripts/CfgFunctions.hpp @@ -193,7 +193,7 @@ class cScripts { }; class modules { file = "cScripts\functions\modules"; - class zenModule_EnableUnitSimulation {}; + class zenModule_toggleUnitSimulation {}; class zenModule_CreateFieldHospital {}; class zenModule_CreateMedicalCrate {}; diff --git a/cScripts/functions/init/fn_init_chatCommands.sqf b/cScripts/functions/init/fn_init_chatCommands.sqf index 6e6a218bc..af27b5b29 100644 --- a/cScripts/functions/init/fn_init_chatCommands.sqf +++ b/cScripts/functions/init/fn_init_chatCommands.sqf @@ -12,3 +12,10 @@ ["attendance", { [QGVAR(getAttendance)] call CBA_fnc_localEvent; }, "all"] call CBA_fnc_registerChatCommand; + +["enableAI", { + //[QGVAR(getAttendance)] call CBA_fnc_localEvent; +}, "all"] call CBA_fnc_registerChatCommand; +["disableAI", { + //[QGVAR(getAttendance)] call CBA_fnc_localEvent; +}, "all"] call CBA_fnc_registerChatCommand; \ No newline at end of file diff --git a/cScripts/functions/init/fn_init_simulation.sqf b/cScripts/functions/init/fn_init_simulation.sqf index f5ab9e61c..82c52ddda 100644 --- a/cScripts/functions/init/fn_init_simulation.sqf +++ b/cScripts/functions/init/fn_init_simulation.sqf @@ -17,13 +17,13 @@ if (EGVAR(Settings,dynamicSimulation) == 0) exitWith {}; // Don't enable system if there are airframes // TODO: make this system work with airframes in a reliable way -private _hasAirframes = { - if (_x isKindOf "Air") exitWith {true}; - false -} forEach vehicles; -if (_hasAirframes) exitWith { - SHOW_WARNING("DynamicSimulation", "Dynamic Simulation have terminated it self due to mission containing airframes"); -}; +//private _hasAirframes = { +// if (_x isKindOf "Air") exitWith {true}; +// false +//} forEach vehicles; +//if (_hasAirframes) exitWith { +// SHOW_WARNING("DynamicSimulation", "Dynamic Simulation have terminated it self due to mission containing airframes"); +//}; INFO("DynamicSimulation", "Dynamic Simulation Enabled"); @@ -65,9 +65,7 @@ private _antiAircraftUnits = []; _antiAircraftUnits append [_name]; continue }; -} forEach ("configName _x isKindOf 'LandVehicle'" configClasses (configFile >> "CfgVehicles")); - -diag_log format ["O_Soldier_AA_F, %1", ("O_Soldier_AA_F" in _antiAircraftUnits)]; +} forEach ("configName _x isKindOf 'LandVehicle' or configName _x isKindOf 'man'" configClasses (configFile >> "CfgVehicles")); // Apply event handlers to objects INFO("DynamicSimulation", "Applying Event Handers (init) to mission objects..."); @@ -116,11 +114,12 @@ INFO("DynamicSimulation", "Applying Event Handers (init) to mission objects...") params ["_unit"]; if (typeOf _unit in _antiAircraftUnits) exitWith { [{ - params ["_unit"]; + params ["_unit"]; INFO_2("DynamicSimulation", "Dynamic simulation system disabeld for Anti Aircraft unit %1 (%2)", _unit, typeOf _unit); _unit enableDynamicSimulation false; + group _unit enableDynamicSimulation false; { - group (_x) enableDynamicSimulation false; + group _x enableDynamicSimulation false; _x enableDynamicSimulation false; } forEach crew _vehicle; }, [_unit], 2] call CBA_fnc_waitAndExecute; @@ -133,8 +132,9 @@ INFO("DynamicSimulation", "Applying Event Handers (init) to mission objects...") params ["_vehicle"]; INFO_2("DynamicSimulation", "Dynamic simulation system disabeld for Anti Aircraft vehicle %1 (%2)", _vehicle, typeOf _vehicle); _vehicle enableDynamicSimulation false; + group _unit enableDynamicSimulation false; { - group (_x) enableDynamicSimulation false; + group _x enableDynamicSimulation false; _x enableDynamicSimulation false; } forEach crew _vehicle; }, [_vehicle], 2] call CBA_fnc_waitAndExecute; @@ -147,14 +147,14 @@ INFO("DynamicSimulation", "Applying Event Handers (init) to mission objects...") params ["_vehicle"]; INFO_2("DynamicSimulation", "Dynamic simulation system disabeld for Anti Aircraft vehicle %1 (%2)", _vehicle, typeOf _vehicle); _vehicle enableDynamicSimulation false; + group _unit enableDynamicSimulation false; { - group (_x) enableDynamicSimulation false; + group _x enableDynamicSimulation false; _x enableDynamicSimulation false; } forEach crew _vehicle; }, [_vehicle], 2] call CBA_fnc_waitAndExecute; }; }, true, [], true] call CBA_fnc_addClassEventHandler; - ["Air", "init", { params ["_vehicle"]; [{ @@ -165,4 +165,32 @@ INFO("DynamicSimulation", "Applying Event Handers (init) to mission objects...") _x enableDynamicSimulation false; } forEach crew _vehicle; }, [_vehicle], 3] call CBA_fnc_waitAndExecute; -}, true, [], true] call CBA_fnc_addClassEventHandler; \ No newline at end of file +}, true, [], true] call CBA_fnc_addClassEventHandler; + + +// Handle aircraft and death +player addEventHandler ["GetInMan", { + params ["_unit", "_role", "_vehicle", "_turret"]; + if (isPlayer _unit) then { + if (_vehicle isKindOf "Air") then { + INFO_2("DynamicSimulation", "Disabled simulation activation for %1 (%2) due to entre aircraft", _unit, typeof _unit); + _unit triggerDynamicSimulation false; + }; + }; +}]; +player addEventHandler ["GetOutMan", { + params ["_unit", "_role", "_vehicle", "_turret"]; + if (isPlayer _unit) then { + if (_vehicle isKindOf "Air") then { + INFO_2("DynamicSimulation", "Enabled simulation activation for %1 (%2) due to exit aircraft", _unit, typeof _unit); + _unit triggerDynamicSimulation true; + }; + }; +}]; +player addEventHandler ["Killed", { + params ["_unit", "_killer", "_instigator", "_useEffects"]; + if (isPlayer _unit) then { + INFO_2("DynamicSimulation", "Enabled simulation activation for %1 (%2) due to death", _unit, typeof _unit); + _unit triggerDynamicSimulation true; + }; +}]; \ No newline at end of file diff --git a/cScripts/functions/init/fn_init_zenModuels.sqf b/cScripts/functions/init/fn_init_zenModuels.sqf index 261bc0461..810a4e11a 100644 --- a/cScripts/functions/init/fn_init_zenModuels.sqf +++ b/cScripts/functions/init/fn_init_zenModuels.sqf @@ -20,10 +20,10 @@ if !(EGVAR(Settings,enable7cavZeusModules)) exitWith {}; INFO("init", "Initializing custom Zen Modules."); -["7Cav AI", "Enable Unit Simulation", +["7Cav AI", "Toggle Unit Simulation", { params ["_modulePos", "_objectPos"]; - [_modulePos, _objectPos] call EFUNC(zenModule,EnableUnitSimulation); + [_modulePos, _objectPos] call EFUNC(zenModule,toggleUnitSimulation); }, "\A3\ui_f\data\map\vehicleicons\iconManVirtual_ca.paa" ] call zen_custom_modules_fnc_register; diff --git a/cScripts/functions/modules/fn_zenModule_enableUnitSimulation.sqf b/cScripts/functions/modules/fn_zenModule_enableUnitSimulation.sqf deleted file mode 100644 index c9be31cc3..000000000 --- a/cScripts/functions/modules/fn_zenModule_enableUnitSimulation.sqf +++ /dev/null @@ -1,36 +0,0 @@ -#include "..\script_component.hpp"; -/* - * Author: CPL.Brostrom.A - * This module function enables adn unhide a units, vehicle and its group; - * that have been hidden and disabled by simulation manager and dynamic simulation. - * - * Arguments: - * 0: modulePos - * 1: objectPos - * - * Example: - * [getPos logic, this] call cScripts_fnc_zenModule_enableUnitSimulation - * - * Public: No - */ - -params ["_modulePos", "_objectPos"]; - -if (isNull _objectPos) exitWith { - ["Not a valid unit"] call zen_common_fnc_showMessage; -}; -if (!(isObjectHidden _objectPos) && simulationEnabled _objectPos) exitWith { - ["Unit already active"] call zen_common_fnc_showMessage; -}; - -_objectPos enableDynamicSimulation false; -[_objectPos, true] remoteExec ["enableSimulationGlobal", 2]; -[_objectPos, false] remoteExec ["hideObjectGlobal", 2]; - -group _objectPos enableDynamicSimulation false; -{ - [_x, true] remoteExec ["enableSimulationGlobal", 2]; - [_x, false] remoteExec ["hideObjectGlobal", 2]; -} forEach units group _objectPos; - -["Unit have been activated"] call zen_common_fnc_showMessage; diff --git a/cScripts/functions/modules/fn_zenModule_toggleUnitSimulation.sqf b/cScripts/functions/modules/fn_zenModule_toggleUnitSimulation.sqf new file mode 100644 index 000000000..eb94566af --- /dev/null +++ b/cScripts/functions/modules/fn_zenModule_toggleUnitSimulation.sqf @@ -0,0 +1,46 @@ +#include "..\script_component.hpp"; +/* + * Author: CPL.Brostrom.A + * This module function enables adn unhide a units, vehicle and its group; + * that have been hidden and disabled by simulation manager and dynamic simulation. + * + * Arguments: + * 0: modulePos + * 1: objectPos + * + * Example: + * [getPos logic, this] call cScripts_fnc_zenModule_enableUnitSimulation + * + * Public: No + */ + +params ["_modulePos", "_objectPos"]; + +if (isNull _objectPos) exitWith { + ["Not a valid unit"] call zen_common_fnc_showMessage; +}; + +if ((isObjectHidden _objectPos) || !(simulationEnabled _objectPos)) then { + _objectPos enableDynamicSimulation false; + [_objectPos, true] remoteExec ["enableSimulationGlobal", 2]; + [_objectPos, false] remoteExec ["hideObjectGlobal", 2]; + + group _objectPos enableDynamicSimulation false; + { + [_x, true] remoteExec ["enableSimulationGlobal", 2]; + [_x, false] remoteExec ["hideObjectGlobal", 2]; + _objectPos enableDynamicSimulation false; + } forEach units group _objectPos; + + ["Unit group have been enabled, revealed and have it's dynamic simulation disabled"] call zen_common_fnc_showMessage; +} else { + _objectPos enableDynamicSimulation true; + + group _objectPos enableDynamicSimulation true; + { + _objectPos enableDynamicSimulation true; + } forEach units group _objectPos; + + ["Unit group have been disabled and have its dynamic simulation enabled"] call zen_common_fnc_showMessage; +}; + From 6488c36f707b125fdfc65e106bb8684d5cba2851 Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Thu, 7 Dec 2023 21:05:51 +0100 Subject: [PATCH 6/7] Adjustments and updates --- cScripts/functions/init/fn_init_simulation.sqf | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cScripts/functions/init/fn_init_simulation.sqf b/cScripts/functions/init/fn_init_simulation.sqf index 82c52ddda..e75d3d4db 100644 --- a/cScripts/functions/init/fn_init_simulation.sqf +++ b/cScripts/functions/init/fn_init_simulation.sqf @@ -15,16 +15,6 @@ if (EGVAR(Settings,dynamicSimulation) == 0) exitWith {}; -// Don't enable system if there are airframes -// TODO: make this system work with airframes in a reliable way -//private _hasAirframes = { -// if (_x isKindOf "Air") exitWith {true}; -// false -//} forEach vehicles; -//if (_hasAirframes) exitWith { -// SHOW_WARNING("DynamicSimulation", "Dynamic Simulation have terminated it self due to mission containing airframes"); -//}; - INFO("DynamicSimulation", "Dynamic Simulation Enabled"); // System Values From 6629e6d1fffb5dfde2a26db48ca32165096cb779 Mon Sep 17 00:00:00 2001 From: AndreasBrostrom Date: Fri, 8 Dec 2023 18:13:41 +0100 Subject: [PATCH 7/7] fixed tab --- cScripts/functions/init/fn_init_simulation.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cScripts/functions/init/fn_init_simulation.sqf b/cScripts/functions/init/fn_init_simulation.sqf index e75d3d4db..034a9443f 100644 --- a/cScripts/functions/init/fn_init_simulation.sqf +++ b/cScripts/functions/init/fn_init_simulation.sqf @@ -178,7 +178,7 @@ player addEventHandler ["GetOutMan", { }; }]; player addEventHandler ["Killed", { - params ["_unit", "_killer", "_instigator", "_useEffects"]; + params ["_unit", "_killer", "_instigator", "_useEffects"]; if (isPlayer _unit) then { INFO_2("DynamicSimulation", "Enabled simulation activation for %1 (%2) due to death", _unit, typeof _unit); _unit triggerDynamicSimulation true;