From d90d5a7ac1bfa0b8f109e17b4c867581ccbbff35 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Mon, 16 May 2016 14:55:19 +0100 Subject: [PATCH] Rewrite global AI skill zeus module Remove the use of ace settings and makes the module more zeus specific. It might be worth adding a similar module or mission settings to ace_ai for mission editing. --- addons/zeus/ACE_Settings.hpp | 43 ------------ addons/zeus/CfgVehicles.hpp | 2 +- addons/zeus/XEH_PREP.hpp | 1 - addons/zeus/XEH_postInit.sqf | 14 +--- addons/zeus/XEH_preInit.sqf | 2 + .../functions/fnc_moduleGlobalSetSkill.sqf | 49 +++++++------ addons/zeus/functions/fnc_setSkillsLocal.sqf | 29 -------- .../zeus/functions/fnc_ui_globalSetSkill.sqf | 70 ++++++++----------- .../zeus/functions/fnc_ui_teleportPlayers.sqf | 3 +- addons/zeus/ui/RscAttributes.hpp | 20 +++--- 10 files changed, 73 insertions(+), 160 deletions(-) delete mode 100644 addons/zeus/functions/fnc_setSkillsLocal.sqf diff --git a/addons/zeus/ACE_Settings.hpp b/addons/zeus/ACE_Settings.hpp index 6fb1570c5a..6488a23e4e 100644 --- a/addons/zeus/ACE_Settings.hpp +++ b/addons/zeus/ACE_Settings.hpp @@ -26,47 +26,4 @@ class ACE_Settings { value = 0; typeName = "BOOL"; }; - - class GVAR(aiSkill_set) { - category = QUOTE(PREFIX); - displayName = "Global AI Set Skill: Master Enable"; - typeName = "BOOL"; - value = 0; - }; - class GVAR(aiSkill_general) { - category = QUOTE(PREFIX); - displayName = "Global AI Set Skill: general,commanding,courage"; - typeName = "SCALAR"; - value = 0.5; - }; - class GVAR(aiSkill_aimingAccuracy) { - category = QUOTE(PREFIX); - displayName = "Global AI Set Skill: aimingAccuracy"; - typeName = "SCALAR"; - value = 0.5; - }; - class GVAR(aiSkill_weaponHandling) { - category = QUOTE(PREFIX); - displayName = "Global AI Set Skill: aimingShake,aimingSpeed,reloadSpeed"; - typeName = "SCALAR"; - value = 0.5; - }; - class GVAR(aiSkill_spotting) { - category = QUOTE(PREFIX); - displayName = "Global AI Set Skill: spotDistance,spotTime"; - typeName = "SCALAR"; - value = 0.5; - }; - class GVAR(aiSkill_COVER) { - category = QUOTE(PREFIX); - displayName = "Global AI Set Skill: AI Seek Cover"; - typeName = "BOOL"; - value = 1; - }; - class GVAR(aiSkill_AUTOCOMBAT) { - category = QUOTE(PREFIX); - displayName = "Global AI Set Skill: Ai Switch To Combat Mode"; - typeName = "BOOL"; - value = 1; - }; }; diff --git a/addons/zeus/CfgVehicles.hpp b/addons/zeus/CfgVehicles.hpp index 4a143ad380..2f169801c0 100644 --- a/addons/zeus/CfgVehicles.hpp +++ b/addons/zeus/CfgVehicles.hpp @@ -117,7 +117,7 @@ class CfgVehicles { }; }; class GVAR(moduleGlobalSetSkill): GVAR(moduleBase) { - displayName = "Global Set AI Skill"; + displayName = "Global AI Skill"; // icon = "\a3\Modules_F_Curator\Data\iconEndMission_ca.paa"; // portrait = "\a3\Modules_F_Curator\Data\portraitEndMission_ca.paa"; curatorInfoType = QGVAR(RscGlobalSetSkill); diff --git a/addons/zeus/XEH_PREP.hpp b/addons/zeus/XEH_PREP.hpp index 5d24c0177c..a72f220d31 100644 --- a/addons/zeus/XEH_PREP.hpp +++ b/addons/zeus/XEH_PREP.hpp @@ -16,7 +16,6 @@ PREP(moduleSurrender); PREP(moduleTeleportPlayers); PREP(moduleUnconscious); PREP(moduleZeusSettings); -PREP(setSkillsLocal); PREP(ui_globalSetSkill); PREP(ui_teleportPlayers); PREP(ui_vehCargo); diff --git a/addons/zeus/XEH_postInit.sqf b/addons/zeus/XEH_postInit.sqf index c05983b00f..c2c7c192eb 100644 --- a/addons/zeus/XEH_postInit.sqf +++ b/addons/zeus/XEH_postInit.sqf @@ -1,14 +1,4 @@ #include "script_component.hpp" -if (isServer) then { - ["ServerUpdateAISettings",FUNC(moduleGlobalSetSkill)] call EFUNC(common,addEventHandler); -}; - -["UpdateAISettings", { - TRACE_1("UpdateAISettings EH",_this); - { - if (local _x) then { - [_x] call FUNC(setSkillsLocal); - }; - } forEach allUnits; -}] call EFUNC(common,addEventHandler); +// Global skill module PVs values for persistence, just listen for the PV +QGVAR(GlobalSkillAI) addPublicVariableEventHandler FUNC(moduleGlobalSetSkill); diff --git a/addons/zeus/XEH_preInit.sqf b/addons/zeus/XEH_preInit.sqf index 0d03673e46..9616a9a861 100644 --- a/addons/zeus/XEH_preInit.sqf +++ b/addons/zeus/XEH_preInit.sqf @@ -8,4 +8,6 @@ if (isServer) then { ["zeusUnitAssigned", FUNC(handleZeusUnitAssigned)] call EFUNC(common,addEventHandler); }; +GVAR(GlobalSkillAI) = [0.5,0.5,0.5,0.5,true,true]; + ADDON = true; diff --git a/addons/zeus/functions/fnc_moduleGlobalSetSkill.sqf b/addons/zeus/functions/fnc_moduleGlobalSetSkill.sqf index d654801894..b25bc5e5f3 100644 --- a/addons/zeus/functions/fnc_moduleGlobalSetSkill.sqf +++ b/addons/zeus/functions/fnc_moduleGlobalSetSkill.sqf @@ -1,27 +1,32 @@ #include "script_component.hpp" -params ["_logic"]; -TRACE_1("params",_logic); +_this params ["_varName","_varValue"]; +_varValue params ["_general","_accuracy","_handling","_spotting","_cover","_combat"]; +TRACE_1("Params",_this); -[QGVAR(aiSkill_set), true, false, true] call ace_common_fnc_setSetting; -if (!GVAR(aiSkill_set)) exitWith { - TRACE_1("Setting must be forced off", GVAR(aiSkill_set)); -}; +TRACE_6("AI settings updated",GVAR(GlobalSkillAI)); +{ + if (local _x) then { + _unit setSkill ["general", _general]; + _unit setSkill ["commanding", _general]; + _unit setSkill ["courage", _general]; + _unit setSkill ["aimingAccuracy", _accuracy]; + _unit setSkill ["aimingShake", _handling]; + _unit setSkill ["aimingSpeed", _handling]; + _unit setSkill ["reloadSpeed", _handling]; + _unit setSkill ["spotDistance", _spotting]; + _unit setSkill ["spotTime", _spotting]; -private _val = _logic getVariable ["aiSkill_general", -1]; -if (_val != -1) then { [QGVAR(aiSkill_general), _val, false, true] call ace_common_fnc_setSetting; }; -_val = _logic getVariable ["aiSkill_aimingAccuracy", -1]; -if (_val != -1) then { [QGVAR(aiSkill_aimingAccuracy), _val, false, true] call ace_common_fnc_setSetting; }; -_val = _logic getVariable ["aiSkill_weaponHandling", -1]; -if (_val != -1) then { [QGVAR(aiSkill_weaponHandling), _val, false, true] call ace_common_fnc_setSetting; }; -_val = _logic getVariable ["aiSkill_spotting", -1]; -if (_val != -1) then { [QGVAR(aiSkill_spotting), _val, false, true] call ace_common_fnc_setSetting; }; -_val = _logic getVariable ["aiSkill_COVER", -1]; -if (!(_val isEqualTo -1)) then { [QGVAR(aiSkill_COVER), _val, false, true] call ace_common_fnc_setSetting; }; -_val = _logic getVariable ["aiSkill_AUTOCOMBAT", -1]; -if (!(_val isEqualTo -1)) then { [QGVAR(aiSkill_AUTOCOMBAT), _val, false, true] call ace_common_fnc_setSetting; }; + if (_cover) then { + _unit enableAI "COVER"; + } else { + _unit disableAI "COVER"; + }; -["UpdateAISettings", []] call ace_common_fnc_globalEvent; -deleteVehicle _logic; - -TRACE_6("ai settings updated",GVAR(aiSkill_general),GVAR(aiSkill_aimingAccuracy),GVAR(aiSkill_weaponHandling),GVAR(aiSkill_spotting),GVAR(aiSkill_COVER),GVAR(aiSkill_AUTOCOMBAT)); + if (_combat) then { + _unit enableAI "AUTOCOMBAT"; + } else { + _unit disableAI "AUTOCOMBAT"; + }; + }; +} forEach allUnits; diff --git a/addons/zeus/functions/fnc_setSkillsLocal.sqf b/addons/zeus/functions/fnc_setSkillsLocal.sqf deleted file mode 100644 index fc99fb2f33..0000000000 --- a/addons/zeus/functions/fnc_setSkillsLocal.sqf +++ /dev/null @@ -1,29 +0,0 @@ -#include "script_component.hpp" - -params ["_unit"]; -TRACE_1("params",_unit); - -{ - _unit setSkill [_x, GVAR(aiSkill_general)]; -} forEach ["general", "commanding", "courage"]; -{ - _unit setSkill [_x, GVAR(aiSkill_aimingAccuracy)]; -} forEach ["aimingAccuracy"]; -{ - _unit setSkill [_x, GVAR(aiSkill_weaponHandling)]; -} forEach ["aimingShake", "aimingSpeed", "reloadSpeed"]; -{ - _unit setSkill [_x, GVAR(aiSkill_spotting)]; -} forEach ["spotDistance", "spotTime"]; -if (GVAR(aiSkill_COVER)) then { - _unit enableAI "COVER"; -} else { - _unit disableAI "COVER"; -}; -if (GVAR(aiSkill_AUTOCOMBAT)) then { - _unit enableAI "AUTOCOMBAT"; -} else { - _unit disableAI "AUTOCOMBAT"; -}; - -TRACE_1("ai sills set",_unit); diff --git a/addons/zeus/functions/fnc_ui_globalSetSkill.sqf b/addons/zeus/functions/fnc_ui_globalSetSkill.sqf index 3b7c0b3e5f..32a2b8ccb7 100644 --- a/addons/zeus/functions/fnc_ui_globalSetSkill.sqf +++ b/addons/zeus/functions/fnc_ui_globalSetSkill.sqf @@ -13,61 +13,49 @@ TRACE_1("logicObject",_logic); _control ctrlRemoveAllEventHandlers "setFocus"; -_fnc_sliderMove = { +//Specific on-load stuff: +private _fnc_sliderMove = { params ["_slider"]; - private _idc = ctrlIDC _slider; - private _curVal = switch (_idc) do { - case (16184): {GVAR(aiSkill_general)}; - case (16185): {GVAR(aiSkill_aimingAccuracy)}; - case (16186): {GVAR(aiSkill_weaponHandling)}; - case (16187): {GVAR(aiSkill_spotting)}; - }; + private _idc = ctrlIDC _slider; // IDCs ∈ [16184,16187] + private _curVal = GVAR(GlobalSkillAI) select (_idc - 16184); // [0,3] _slider ctrlSetTooltip format ["%1%3 (was %2%3)", round(sliderPosition _slider * 100), round(_curVal * 100), "%"]; }; -//Specific on-load stuff: -(_display displayCtrl 16184) sliderSetRange [0, 1]; -(_display displayCtrl 16184) sliderSetPosition (GVAR(aiSkill_general) max 0); -(_display displayCtrl 16184) ctrlAddEventHandler ["SliderPosChanged", _fnc_sliderMove]; -(_display displayCtrl 16184) call _fnc_sliderMove; +{ + private _slider = _display displayCtrl _x; + _slider sliderSetRange [0, 1]; + _slider sliderSetSpeed [0.01,0.1]; + _slider sliderSetPosition (GVAR(GlobalSkillAI) select _forEachIndex); + _slider ctrlAddEventHandler ["SliderPosChanged", _fnc_sliderMove]; + _slider call _fnc_sliderMove; +} forEach [16184,16185,16186,16187]; -(_display displayCtrl 16185) sliderSetRange [0, 1]; -(_display displayCtrl 16185) sliderSetPosition (GVAR(aiSkill_aimingAccuracy) max 0); -(_display displayCtrl 16185) ctrlAddEventHandler ["SliderPosChanged", _fnc_sliderMove]; -(_display displayCtrl 16185) call _fnc_sliderMove; - -(_display displayCtrl 16186) sliderSetRange [0, 1]; -(_display displayCtrl 16186) sliderSetPosition (GVAR(aiSkill_weaponHandling) max 0); -(_display displayCtrl 16186) ctrlAddEventHandler ["SliderPosChanged", _fnc_sliderMove]; -(_display displayCtrl 16186) call _fnc_sliderMove; - -(_display displayCtrl 16187) sliderSetRange [0, 1]; -(_display displayCtrl 16187) sliderSetPosition (GVAR(aiSkill_spotting) max 0); -(_display displayCtrl 16187) ctrlAddEventHandler ["SliderPosChanged", _fnc_sliderMove]; -(_display displayCtrl 16187) call _fnc_sliderMove; - -(_display displayCtrl 16188) cbSetChecked GVAR(aiSkill_COVER); - -(_display displayCtrl 16189) cbSetChecked GVAR(aiSkill_AUTOCOMBAT); +(_display displayCtrl 16188) cbSetChecked (GVAR(GlobalSkillAI) select 4); +(_display displayCtrl 16189) cbSetChecked (GVAR(GlobalSkillAI) select 5); private _fnc_onConfirm = { params [["_ctrlButtonOK", controlNull, [controlNull]]]; TRACE_1("_fnc_onConfirm params",_this); + private _display = ctrlparent _ctrlButtonOK; if (isNull _display) exitWith {}; - private _logic = missionnamespace getvariable ["BIS_fnc_initCuratorAttributes_target", objnull]; - if (isNull _logic) exitWith {diag_log text format ["[POTATO] - ERROR Logic [%1] is null on confirm", _logic];}; + private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull); + if (isNull _logic) exitWith {}; - TRACE_2("set",_logic, sliderPosition (_display displayCtrl 16184)); - _logic setVariable ["aiSkill_general", sliderPosition (_display displayCtrl 16184), true]; - _logic setVariable ["aiSkill_aimingAccuracy", sliderPosition (_display displayCtrl 16185), true]; - _logic setVariable ["aiSkill_weaponHandling", sliderPosition (_display displayCtrl 16186), true]; - _logic setVariable ["aiSkill_spotting", sliderPosition (_display displayCtrl 16187), true]; - _logic setVariable ["aiSkill_COVER", cbChecked (_display displayCtrl 16188), true]; - _logic setVariable ["aiSkill_AUTOCOMBAT", cbChecked (_display displayCtrl 16189), true]; + GVAR(GlobalSkillAI) = [ + sliderPosition (_display displayCtrl 16184), // General + sliderPosition (_display displayCtrl 16185), // Accuracy + sliderPosition (_display displayCtrl 16186), // Handling + sliderPosition (_display displayCtrl 16187), // Spotting + cbChecked (_display displayCtrl 16188), // Seek cover + cbChecked (_display displayCtrl 16189) // Autocombat + ]; + publicVariable QGVAR(GlobalSkillAI); // Values should persist for future use - ["ServerUpdateAISettings", [_logic]] call EFUNC(common,serverEvent); + // PV EH won't run on local machine + [QGVAR(GlobalSkillAI),GVAR(GlobalSkillAI)] call FUNC(moduleGlobalSetSkill); + deleteVehicle _logic; }; _ctrlButtonOK ctrladdeventhandler ["buttonclick", _fnc_onConfirm]; diff --git a/addons/zeus/functions/fnc_ui_teleportPlayers.sqf b/addons/zeus/functions/fnc_ui_teleportPlayers.sqf index d9a496b17f..9990d6c683 100644 --- a/addons/zeus/functions/fnc_ui_teleportPlayers.sqf +++ b/addons/zeus/functions/fnc_ui_teleportPlayers.sqf @@ -35,11 +35,12 @@ private _fnc_onUnload = { private _fnc_onConfirm = { params [["_ctrlButtonOK", controlNull, [controlNull]]]; + private _display = ctrlparent _ctrlButtonOK; if (isNull _display) exitWith {}; private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull); - if (isNull _logic) exitWith {diag_log text format ["[POTATO] - ERROR Logic [%1] is null on confirm", _logic];}; + if (isNull _logic) exitWith {}; private _lb = _display displayCtrl 16189; diff --git a/addons/zeus/ui/RscAttributes.hpp b/addons/zeus/ui/RscAttributes.hpp index 641daa7af0..62de9bc20d 100644 --- a/addons/zeus/ui/RscAttributes.hpp +++ b/addons/zeus/ui/RscAttributes.hpp @@ -36,8 +36,8 @@ class GVAR(RscGlobalSetSkill): RscDisplayAttributes { class controls { class Title1: RscText { idc = -1; - text = "Skill: General"; - toolTip = "Global AI Set Skill: general,commanding,courage"; + text = "General Skill"; + toolTip = "Changes: general, commanding, courage"; x = 0; y = 0; w = W_PART(10); @@ -53,8 +53,8 @@ class GVAR(RscGlobalSetSkill): RscDisplayAttributes { }; class Title2: Title1 { idc = -1; - text = "Skill: aimingAccuracy"; - toolTip = "Global AI Set Skill: aimingAccuracy"; + text = "Accuracy"; + toolTip = "Changes: aimingAccuracy"; y = H_PART(1.1); }; class Value2: Value1 { @@ -63,8 +63,8 @@ class GVAR(RscGlobalSetSkill): RscDisplayAttributes { }; class Title3: Title1 { idc = -1; - text = "Skill: weaponHandling"; - toolTip = "Global AI Set Skill: aimingShake,aimingSpeed,reloadSpeed"; + text = "Weapon Handling"; + toolTip = "Changes: aimingShake, aimingSpeed, reloadSpeed"; y = H_PART(2.2); }; class Value3: Value1 { @@ -73,8 +73,8 @@ class GVAR(RscGlobalSetSkill): RscDisplayAttributes { }; class Title4: Title1 { idc = -1; - text = "Skill: spotting"; - toolTip = "Global AI Set Skill: spotDistance,spotTime"; + text = "Spotting"; + toolTip = "Changes: spotDistance, spotTime"; y = H_PART(3.3); }; class Value4: Value1 { @@ -84,7 +84,7 @@ class GVAR(RscGlobalSetSkill): RscDisplayAttributes { class Title5: Title1 { idc = -1; text = "Seek Cover"; - toolTip = "Global AI Set Skill: AI Seek Cover"; + toolTip = "Will AI seek cover"; y = H_PART(4.4); }; class Value5: RscCheckBox { @@ -97,7 +97,7 @@ class GVAR(RscGlobalSetSkill): RscDisplayAttributes { class Title6: Title5 { idc = -1; text = "AUTOCOMBAT"; - toolTip = "Global AI Set Skill: Ai Switch To Combat Mode"; + toolTip = "Will AI automatically switch to combat mode"; y = H_PART(5.5); }; class Value6: Value5 {