diff --git a/TO_MERGE/agm/SwitchUnits/config.cpp b/TO_MERGE/agm/SwitchUnits/config.cpp deleted file mode 100644 index 254a92be3a..0000000000 --- a/TO_MERGE/agm/SwitchUnits/config.cpp +++ /dev/null @@ -1,140 +0,0 @@ -class CfgPatches { - class AGM_SwitchUnits { - units[] = {}; - weapons[] = {}; - requiredVersion = 0.60; - requiredAddons[] = {AGM_Core}; - version = "0.95"; - versionStr = "0.95"; - versionAr[] = {0,95,0}; - author[] = {"bux578"}; - authorUrl = "https://github.com/bux578/"; - }; -}; - -class CfgFunctions { - class AGM_SwitchUnits { - class AGM_SwitchUnits { - file = "AGM_SwitchUnits\functions"; - class addMapFunction; - class handleMapClick; - class initPlayer; - class isValidAi; - class markAiOnMap; - class module; - class nearestPlayers; - class switchBack; - class switchUnit; - }; - }; -}; - - -class Extended_PostInit_EventHandlers { - class AGM_SwitchUnits { - clientInit = "call compile preprocessFileLineNumbers '\AGM_SwitchUnits\clientInit.sqf'"; - }; -}; - - -class CfgVehicles { - class Module_F; - class AGM_ModuleSwitchUnits: Module_F { - author = "AGM Team"; - category = "AGM"; - displayName = "SwitchUnits System"; - function = "AGM_SwitchUnits_fnc_module"; - scope = 2; - isGlobal = 1; - icon = "\AGM_SwitchUnits\UI\IconSwitchUnits_ca.paa"; - class Arguments { - class SwitchToWest { - displayName = "Switch to West?"; - description = "Allow switching to west units?"; - typeName = "BOOL"; - class values { - class Yes {name = "Yes"; value = 1;}; - class No {default = 1; name = "No"; value = 0;}; - }; - }; - class SwitchToEast { - displayName = "Switch to East?"; - description = "Allow switching to east units?"; - typeName = "BOOL"; - class values { - class Yes {name = "Yes"; value = 1;}; - class No {default = 1; name = "No"; value = 0;}; - }; - }; - class SwitchToIndependent { - displayName = "Switch to Independent?"; - description = "Allow switching to independent units?"; - typeName = "BOOL"; - class values { - class Yes {name = "Yes"; value = 1;}; - class No {default = 1; name = "No"; value = 0;}; - }; - }; - class SwitchToCivilian { - displayName = "Switch to Civilian?"; - description = "Allow switching to civilian units?"; - typeName = "BOOL"; - class values { - class Yes {name = "Yes"; value = 1;}; - class No {default = 1; name = "No"; value = 0;}; - }; - }; - class EnableSafeZone { - displayName = "Enable Safe Zone?"; - description = "Enable a safe zone around enemy units? Players can't switch to units inside of the safe zone."; - typeName = "BOOL"; - class values { - class Yes {default = 1; name = "Yes"; value = 1;}; - class No {name = "No"; value = 0;}; - }; - }; - class SafeZoneRadius { - displayName = "Safe Zone Radius"; - description = "The safe zone around players from a different team. Default: 200"; - typeName = "NUMBER"; - defaultValue = 100; - }; - - /* - - class EnableSwitchUnits { - displayName = "Enable SwitchUnits?"; - description = "Enable to switch to AI units? Default: No"; - typeName = "BOOL"; - class values { - class Yes {name = "Yes"; value = 1;}; - class No {default = 1; name = "No"; value = 0;}; - }; - }; - - class SwitchUnitsAllowedForSide { - displayName = "Allow for which side?"; - description = "Which side should be allowed to switch to AI units?"; - typeName = "NUMBER"; - class values { - class West {name = "West"; value = 0;}; - class East {default = 1; name = "East"; value = 1;}; - class Independent {name = "Independent"; value = 2;}; - class Civilian {name = "Civilian"; value = 3;}; - }; - };*/ - }; - }; -}; - -class AGM_Parameters_Numeric { - AGM_SwitchUnits_SafeZoneRadius = 100; -}; -class AGM_Parameters_Boolean { - AGM_SwitchUnits_EnableSwitchUnits = 0; - AGM_SwitchUnits_SwitchToWest = 0; - AGM_SwitchUnits_SwitchToEast = 0; - AGM_SwitchUnits_SwitchToIndependent = 0; - AGM_SwitchUnits_SwitchToCivilian = 0; - AGM_SwitchUnits_EnableSafeZone = 1; -}; diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_module.sqf b/TO_MERGE/agm/SwitchUnits/functions/fn_module.sqf deleted file mode 100644 index 43ec26199a..0000000000 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_module.sqf +++ /dev/null @@ -1,38 +0,0 @@ -/* - Name: AGM_SwitchUnits_fnc_module - - Author(s): - bux578 - - Description: - Initializes the SwitchUnits module - - Parameters: - 0: OBJECT - module logic - 1: ARRAY - list of affected units - 2: BOOLEAN - isActivated - - Returns: - BOOLEAN (Good practice to include one) -*/ - -if !(isServer) exitWith {}; - -_logic = _this select 0; -_activated = _this select 2; - -if !(_activated) exitWith {}; - -AGM_SwitchUnits_Module = true; - -["AGM_SwitchUnits_EnableSwitchUnits", true] call AGM_Core_fnc_setParameter; - -[_logic, "AGM_SwitchUnits_SwitchToWest", "SwitchToWest"] call AGM_Core_fnc_readBooleanParameterFromModule; -[_logic, "AGM_SwitchUnits_SwitchToEast", "SwitchToEast"] call AGM_Core_fnc_readBooleanParameterFromModule; -[_logic, "AGM_SwitchUnits_SwitchToIndependent", "SwitchToIndependent"] call AGM_Core_fnc_readBooleanParameterFromModule; -[_logic, "AGM_SwitchUnits_SwitchToCivilian", "SwitchToCivilian"] call AGM_Core_fnc_readBooleanParameterFromModule; - -[_logic, "AGM_SwitchUnits_EnableSafeZone", "EnableSafeZone"] call AGM_Core_fnc_readBooleanParameterFromModule; -[_logic, "AGM_SwitchUnits_SafeZoneRadius", "SafeZoneRadius"] call AGM_Core_fnc_readNumericParameterFromModule; - -diag_log text "[AGM]: SwitchUnits Module Initialized."; diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_switchUnit.sqf b/TO_MERGE/agm/SwitchUnits/functions/fn_switchUnit.sqf deleted file mode 100644 index ddb2a1d523..0000000000 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_switchUnit.sqf +++ /dev/null @@ -1,79 +0,0 @@ -/* - Name: AGM_SwitchUnits_fnc_switchUnit - - Author(s): - bux578 - - Description: - Selects the new given player unit - - Parameters: - 0: OBJECT - the unit to switch to - - Returns: - VOID -*/ - -private ["_newUnit"]; - -_newUnit = _this select 1; - -// don't switch to original player units -if (!([_newUnit] call AGM_SwitchUnits_fnc_isValidAi)) exitWith {}; - -_newUnit spawn { - private ["_unit", "_allNearestPlayers", "_oldUnit", "_respawnEhId", "_oldOwner", "_leave"]; - - _unit = _this; - - _leave = false; - - if (AGM_SwitchUnits_EnableSafeZone) then { - - _allNearestPlayers = [position _unit, AGM_SwitchUnits_SafeZoneRadius] call AGM_SwitchUnits_fnc_nearestPlayers; - _nearestEnemyPlayers = [_allNearestPlayers, {((side AGM_SwitchUnits_OriginalGroup) getFriend (side _this) < 0.6) && !(_this getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])}] call AGM_Core_fnc_filter; - - if (count _nearestEnemyPlayers > 0) exitWith { - _leave = true; - }; - }; - - // exitWith doesn't exit past the "if(EnableSafeZone)" block - if (_leave) exitWith { - [localize "STR_AGM_SwitchUnits_TooCloseToEnemy"] call AGM_Core_fnc_displayTextStructured; - }; - - // should switch locality - // This doesn't work anymore, because one's now able to switch to units from a different side - //[_unit] joinSilent group player; - [[_unit, player], "{(_this select 0) setVariable ['AGM_SwitchUnits_OriginalOwner', owner (_this select 0), true]; (_this select 0) setOwner owner (_this select 1)}", 1] call AGM_Core_fnc_execRemoteFnc; - - _oldUnit = player; - waitUntil {sleep 0.2; local _unit}; - - _oldUnit setVariable ["AGM_SwitchUnits_IsPlayerControlled", false, true]; - _oldUnit setVariable ["AGM_SwitchUnits_PlayerControlledName", "", true]; - - _respawnEhId = _unit getVariable ["AGM_SwitchUnits_RespawnEhId", -1]; - if (_respawnEhId != -1) then { - _oldUnit removeEventHandler ["Respawn", _respawnEhId]; - }; - - selectPlayer _unit; - - _unit setVariable ["AGM_SwitchUnits_IsPlayerControlled", true, true]; - _unit setVariable ["AGM_SwitchUnits_PlayerControlledName", AGM_SwitchUnits_OriginalName, true]; - - _respawnEhId = _unit addEventHandler ["Respawn", { - [AGM_SwitchUnits_OriginalUnit, _this select 0] spawn AGM_SwitchUnits_fnc_switchBack; - }]; - _unit setVariable ["AGM_SwitchUnits_RespawnEhId", _respawnEhId, true]; - - // set owner back to original owner - _oldOwner = _oldUnit getVariable["AGM_SwitchUnits_OriginalOwner", -1]; - if (_oldOwner > -1) then { - [[_oldUnit, _oldOwner], "{(_this select 0) setOwner (_this select 1)}", 1] call AGM_Core_fnc_execRemoteFnc; - }; - - [localize "STR_AGM_SwitchUnits_SwitchedUnit"] call AGM_Core_fnc_displayTextStructured; -}; diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp new file mode 100644 index 0000000000..47dcd984d1 --- /dev/null +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -0,0 +1,11 @@ +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE( call COMPILE_FILE(XEH_preInit) ); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + postInit = QUOTE(call COMPILE_FILE(XEH_postInit) ); + }; +}; diff --git a/addons/switchunits/CfgVehicles.hpp b/addons/switchunits/CfgVehicles.hpp new file mode 100644 index 0000000000..04a08bd8d5 --- /dev/null +++ b/addons/switchunits/CfgVehicles.hpp @@ -0,0 +1,65 @@ +class CfgVehicles { + class Module_F; + class ACE_ModuleSwitchUnits: Module_F { + author = "$STR_ACE_Core_ACETeam"; + category = "ACE"; + displayName = "SwitchUnits System"; + function = FUNC(module); + scope = 2; + isGlobal = 1; + icon = PATHTOF(UI\IconSwitchUnits_ca.paa); + class Arguments { + class SwitchToWest { + displayName = "Switch to West?"; + description = "Allow switching to west units?"; + typeName = "BOOL"; + class values { + class Yes {name = "Yes"; value = 1;}; + class No {default = 1; name = "No"; value = 0;}; + }; + }; + class SwitchToEast { + displayName = "Switch to East?"; + description = "Allow switching to east units?"; + typeName = "BOOL"; + class values { + class Yes {name = "Yes"; value = 1;}; + class No {default = 1; name = "No"; value = 0;}; + }; + }; + class SwitchToIndependent { + displayName = "Switch to Independent?"; + description = "Allow switching to independent units?"; + typeName = "BOOL"; + class values { + class Yes {name = "Yes"; value = 1;}; + class No {default = 1; name = "No"; value = 0;}; + }; + }; + class SwitchToCivilian { + displayName = "Switch to Civilian?"; + description = "Allow switching to civilian units?"; + typeName = "BOOL"; + class values { + class Yes {name = "Yes"; value = 1;}; + class No {default = 1; name = "No"; value = 0;}; + }; + }; + class EnableSafeZone { + displayName = "Enable Safe Zone?"; + description = "Enable a safe zone around enemy units? Players can't switch to units inside of the safe zone."; + typeName = "BOOL"; + class values { + class Yes {default = 1; name = "Yes"; value = 1;}; + class No {name = "No"; value = 0;}; + }; + }; + class SafeZoneRadius { + displayName = "Safe Zone Radius"; + description = "The safe zone around players from a different team. Default: 200"; + typeName = "NUMBER"; + defaultValue = 100; + }; + }; + }; +}; diff --git a/TO_MERGE/agm/SwitchUnits/UI/IconSwitchUnits_ca.paa b/addons/switchunits/UI/IconSwitchUnits_ca.paa similarity index 100% rename from TO_MERGE/agm/SwitchUnits/UI/IconSwitchUnits_ca.paa rename to addons/switchunits/UI/IconSwitchUnits_ca.paa diff --git a/TO_MERGE/agm/SwitchUnits/clientInit.sqf b/addons/switchunits/XEH_postInit.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/clientInit.sqf rename to addons/switchunits/XEH_postInit.sqf diff --git a/addons/switchunits/XEH_preInit.sqf b/addons/switchunits/XEH_preInit.sqf new file mode 100644 index 0000000000..7443b79565 --- /dev/null +++ b/addons/switchunits/XEH_preInit.sqf @@ -0,0 +1,11 @@ +#include "script_component.hpp" + +PREP(addMapFunction); +PREP(handleMapClick); +PREP(initPlayer); +PREP(isValidAi); +PREP(markAiOnMap); +PREP(module); +PREP(nearestPlayers); +PREP(switchBack); +PREP(switchUnit); diff --git a/addons/switchunits/config.cpp b/addons/switchunits/config.cpp new file mode 100644 index 0000000000..63e81332cc --- /dev/null +++ b/addons/switchunits/config.cpp @@ -0,0 +1,31 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = 0.60; + requiredAddons[] = {"ace_core"}; + version = QUOTE(VERSION); + versionStr = QUOTE(VERSION); + versionAr[] = {VERSION_AR}; + author[] = {"bux578"}; + authorUrl = "https://github.com/bux578/"; + }; +}; + +#include "CfgEventHandlers.hpp" +#include "CfgVehicles.hpp" + +class ACE_Parameters_Numeric { + GVAR(SafeZoneRadius) = 100; +}; + +class ACE_Parameters_Boolean { + GVAR(EnableSwitchUnits) = 0; + GVAR(SwitchToWest) = 0; + GVAR(SwitchToEast) = 0; + GVAR(SwitchToIndependent) = 0; + GVAR(SwitchToCivilian) = 0; + GVAR(EnableSafeZone) = 1; +}; diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_addMapFunction.sqf b/addons/switchunits/functions/fnc_addMapFunction.sqf similarity index 79% rename from TO_MERGE/agm/SwitchUnits/functions/fn_addMapFunction.sqf rename to addons/switchunits/functions/fnc_addMapFunction.sqf index f65725aacf..0607d00fd3 100644 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_addMapFunction.sqf +++ b/addons/switchunits/functions/fnc_addMapFunction.sqf @@ -15,9 +15,11 @@ VOID */ +#include "script_component.hpp" + private ["_unit"]; _unit = _this select 0; ["theMapClick", "onMapSingleClick", { - [_this, _pos, _shift, _alt] call AGM_SwitchUnits_fnc_handleMapClick; + [_this, _pos, _shift, _alt] call FUNC(handleMapClick); }, [_unit, _sides]] call BIS_fnc_addStackedEventHandler; diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_handleMapClick.sqf b/addons/switchunits/functions/fnc_handleMapClick.sqf similarity index 81% rename from TO_MERGE/agm/SwitchUnits/functions/fn_handleMapClick.sqf rename to addons/switchunits/functions/fnc_handleMapClick.sqf index 642baed1bd..eb5da3ad10 100644 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_handleMapClick.sqf +++ b/addons/switchunits/functions/fnc_handleMapClick.sqf @@ -16,6 +16,8 @@ VOID */ +#include "script_component.hpp" + private ["_args", "_currentPlayerUnit", "_sides", "_pos", "_sideNearest"]; _currentPlayerUnit = (_this select 0) select 0; @@ -25,7 +27,7 @@ _pos = _this select 1; _sideNearest = []; { - if ([_x] call AGM_SwitchUnits_fnc_isValidAi && (side group _x in _sides)) then { + if ([_x] call FUNC(isValidAi) && (side group _x in _sides)) then { _sideNearest pushBack _x; }; } forEach (nearestObjects [_pos, ["Man"], 20]); @@ -35,7 +37,7 @@ if (count _sideNearest > 0) then { private ["_switchUnit"]; _switchUnit = _sideNearest select 0; - [_currentPlayerUnit, _switchUnit] call AGM_SwitchUnits_fnc_switchUnit; + [_currentPlayerUnit, _switchUnit] call FUNC(switchUnit); openMap false; }; diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_initPlayer.sqf b/addons/switchunits/functions/fnc_initPlayer.sqf similarity index 63% rename from TO_MERGE/agm/SwitchUnits/functions/fn_initPlayer.sqf rename to addons/switchunits/functions/fnc_initPlayer.sqf index c3ee6ce7b2..60e5eaabc7 100644 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_initPlayer.sqf +++ b/addons/switchunits/functions/fnc_initPlayer.sqf @@ -15,6 +15,8 @@ VOID */ +#include "script_component.hpp" + private ["_playerUnit", "_sides"]; _playerUnit = _this select 0; @@ -22,14 +24,14 @@ _sides = _this select 1; if (vehicle _playerUnit == _playerUnit) then { - [_sides] call AGM_SwitchUnits_fnc_markAiOnMap; + [_sides] call FUNC(markAiOnMap); - _playerUnit setVariable ["AGM_SwitchUnits_IsPlayerUnit", true]; + _playerUnit setVariable [QGVAR(IsPlayerUnit), true]; _playerUnit allowDamage false; - AGM_SwitchUnits_OriginalUnit = _playerUnit; - AGM_SwitchUnits_OriginalName = [_playerUnit] call AGM_Core_fnc_getName; - AGM_SwitchUnits_OriginalGroup = group _playerUnit; + GVAR(OriginalUnit) = _playerUnit; + GVAR(OriginalName) = [_playerUnit] call EFUNC(Core, getName); + GVAR(OriginalGroup) = group _playerUnit; // remove all starting gear of a player removeAllWeapons _playerUnit; @@ -42,7 +44,7 @@ if (vehicle _playerUnit == _playerUnit) then { _playerUnit linkItem "ItemMap"; removeUniform _playerUnit; - [_playerUnit, "AGM_SwitchUnits", true] call AGM_Core_fnc_setForceWalkStatus; + [_playerUnit, "ACE_SwitchUnits", true] call EFUNC(Core, setForceWalkStatus); - [_playerUnit, _sides] call AGM_SwitchUnits_fnc_addMapFunction; + [_playerUnit, _sides] call AFUNC(addMapFunction); }; diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_isValidAi.sqf b/addons/switchunits/functions/fnc_isValidAi.sqf similarity index 62% rename from TO_MERGE/agm/SwitchUnits/functions/fn_isValidAi.sqf rename to addons/switchunits/functions/fnc_isValidAi.sqf index f91b27ffbe..3803ce4fbd 100644 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_isValidAi.sqf +++ b/addons/switchunits/functions/fnc_isValidAi.sqf @@ -14,12 +14,14 @@ VOID */ +#include "script_component.hpp" + private ["_unit"]; _unit = _this select 0; -!([_unit] call AGM_Core_fnc_isPlayer +!([_unit] call EFUNC(Core, isPlayer) || {_unit in playableUnits} || {vehicle _unit != _unit} -|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerUnit", false]} -|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerControlled", false]}) +|| {_unit getVariable [QGVAR(IsPlayerUnit), false]} +|| {_unit getVariable [QGVAR(IsPlayerControlled), false]}) diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_markAiOnMap.sqf b/addons/switchunits/functions/fnc_markAiOnMap.sqf similarity index 76% rename from TO_MERGE/agm/SwitchUnits/functions/fn_markAiOnMap.sqf rename to addons/switchunits/functions/fnc_markAiOnMap.sqf index 05865bc060..79e72c7379 100644 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_markAiOnMap.sqf +++ b/addons/switchunits/functions/fnc_markAiOnMap.sqf @@ -15,6 +15,8 @@ VOID */ +#include "script_component.hpp" + private ["_sidesToShow"]; _sidesToShow = _this select 0; @@ -34,10 +36,10 @@ _sidesToShow spawn { // create markers { - if (([_x] call AGM_SwitchUnits_fnc_isValidAi && (side group _x in _sides)) || (_x getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])) then { + if (([_x] call FUNC(isValidAi) && (side group _x in _sides)) || (_x getVariable [QGVAR(IsPlayerControlled), false])) then { private ["_markerName", "_marker", "_markerColor"]; - //_markerName = format ["%1", [_x] call AGM_Core_fnc_getName]; + //_markerName = format ["%1", [_x] call EFUNC(Core, getName)]; _markerName = str _x; _marker = createMarkerLocal [_markerName, position _x]; @@ -49,9 +51,9 @@ _sidesToShow spawn { // commy's one liner magic _markerColor = format ["Color%1", side group _x]; - if ((_x getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])) then { + if ((_x getVariable [QGVAR(IsPlayerControlled), false])) then { _markerName setMarkerColorLocal "ColorOrange"; - _markerName setMarkerTextLocal (_x getVariable ["AGM_SwitchUnits_PlayerControlledName",""]); + _markerName setMarkerTextLocal (_x getVariable [QGVAR(PlayerControlledName),""]); } else { _markerName setMarkerColorLocal _markerColor; _markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName")); diff --git a/addons/switchunits/functions/fnc_module.sqf b/addons/switchunits/functions/fnc_module.sqf new file mode 100644 index 0000000000..c614b9c6d7 --- /dev/null +++ b/addons/switchunits/functions/fnc_module.sqf @@ -0,0 +1,40 @@ +/* + Name: AGM_SwitchUnits_fnc_module + + Author(s): + bux578 + + Description: + Initializes the SwitchUnits module + + Parameters: + 0: OBJECT - module logic + 1: ARRAY - list of affected units + 2: BOOLEAN - isActivated + + Returns: + BOOLEAN (Good practice to include one) +*/ + +#include "script_component.hpp" + +if !(isServer) exitWith {}; + +_logic = _this select 0; +_activated = _this select 2; + +if !(_activated) exitWith {}; + +GVAR(Module) = true; + +[QGVAR(EnableSwitchUnits), true] call EFUNC(Core, setParameter); + +[_logic, QGVAR(SwitchToWest), "SwitchToWest"] call EFUNC(Core, readBooleanParameterFromModule); +[_logic, QGVAR(SwitchToEast), "SwitchToEast"] call EFUNC(Core, readBooleanParameterFromModule); +[_logic, QGVAR(SwitchToIndependent), "SwitchToIndependent"] call EFUNC(Core, readBooleanParameterFromModule); +[_logic, QGVAR(SwitchToCivilian), "SwitchToCivilian"] call EFUNC(Core, readBooleanParameterFromModule); + +[_logic, QGVAR(EnableSafeZone), "EnableSafeZone"] call EFUNC(Core, readBooleanParameterFromModule); +[_logic, QGVAR(SafeZoneRadius), "SafeZoneRadius"] call EFUNC(Core, readNumericParameterFromModule); + +diag_log text "[ACE]: SwitchUnits Module Initialized."; diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_nearestPlayers.sqf b/addons/switchunits/functions/fnc_nearestPlayers.sqf similarity index 85% rename from TO_MERGE/agm/SwitchUnits/functions/fn_nearestPlayers.sqf rename to addons/switchunits/functions/fnc_nearestPlayers.sqf index 04b185c455..6475185171 100644 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_nearestPlayers.sqf +++ b/addons/switchunits/functions/fnc_nearestPlayers.sqf @@ -15,6 +15,8 @@ ARRAY - Player units */ +#include "script_component.hpp" + private ["_position", "_radius", "_nearestPlayers"]; _position = _this select 0; @@ -23,7 +25,7 @@ _radius = _this select 1; _nearestPlayers = []; { - if ([_x] call AGM_Core_fnc_isPlayer && {alive _x}) then { + if ([_x] call EFUNC(Core, isPlayer) && {alive _x}) then { _nearestPlayers pushBack _x; }; } forEach (nearestObjects [_position, ["Man"], _radius]); diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_switchBack.sqf b/addons/switchunits/functions/fnc_switchBack.sqf similarity index 85% rename from TO_MERGE/agm/SwitchUnits/functions/fn_switchBack.sqf rename to addons/switchunits/functions/fnc_switchBack.sqf index eba84d57f6..e9425c4fa4 100644 --- a/TO_MERGE/agm/SwitchUnits/functions/fn_switchBack.sqf +++ b/addons/switchunits/functions/fnc_switchBack.sqf @@ -16,11 +16,13 @@ VOID */ +#include "script_component.hpp" + private ["_originalPlayerUnit", "_currentUnit"]; _originalPlayerUnit = _this select 0; _currentUnit = _this select 1; -[_originalPlayerUnit] joinSilent AGM_SwitchUnits_OriginalGroup; +[_originalPlayerUnit] joinSilent GVAR(OriginalGroup); waitUntil {local _originalPlayerUnit}; diff --git a/addons/switchunits/functions/fnc_switchUnit.sqf b/addons/switchunits/functions/fnc_switchUnit.sqf new file mode 100644 index 0000000000..6002ee3f8f --- /dev/null +++ b/addons/switchunits/functions/fnc_switchUnit.sqf @@ -0,0 +1,81 @@ +/* + Name: AGM_SwitchUnits_fnc_switchUnit + + Author(s): + bux578 + + Description: + Selects the new given player unit + + Parameters: + 0: OBJECT - the unit to switch to + + Returns: + VOID +*/ + +#include "script_component.hpp" + +private ["_newUnit"]; + +_newUnit = _this select 1; + +// don't switch to original player units +if (!([_newUnit] call FUNC(isValidAi))) exitWith {}; + +_newUnit spawn { + private ["_unit", "_allNearestPlayers", "_oldUnit", "_respawnEhId", "_oldOwner", "_leave"]; + + _unit = _this; + + _leave = false; + + if (GVAR(EnableSafeZone)) then { + + _allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers); + _nearestEnemyPlayers = [_allNearestPlayers, {((side GVAR(OriginalGroup)) getFriend (side _this) < 0.6) && !(_this getVariable [QGVAR(IsPlayerControlled), false])}] call EFUNC(Core, filter); + + if (count _nearestEnemyPlayers > 0) exitWith { + _leave = true; + }; + }; + + // exitWith doesn't exit past the "if(EnableSafeZone)" block + if (_leave) exitWith { + [localize "STR_ACE_SwitchUnits_TooCloseToEnemy"] call EFUNC(Core, displayTextStructured); + }; + + // should switch locality + // This doesn't work anymore, because one's now able to switch to units from a different side + //[_unit] joinSilent group player; + [[_unit, player], QUOTE({(_this select 0) setVariable [QGVAR(OriginalOwner), owner (_this select 0), true]; (_this select 0) setOwner owner (_this select 1)}), 1] call EFUNC(Core, execRemoteFnc); + + _oldUnit = player; + waitUntil {sleep 0.2; local _unit}; + + _oldUnit setVariable [QGVAR(IsPlayerControlled), false, true]; + _oldUnit setVariable [QGVAR(PlayerControlledName), "", true]; + + _respawnEhId = _unit getVariable [QGVAR(RespawnEhId), -1]; + if (_respawnEhId != -1) then { + _oldUnit removeEventHandler ["Respawn", _respawnEhId]; + }; + + selectPlayer _unit; + + _unit setVariable [QGVAR(IsPlayerControlled), true, true]; + _unit setVariable [QGVAR(PlayerControlledName), GVAR(OriginalName), true]; + + _respawnEhId = _unit addEventHandler ["Respawn", { + [GVAR(OriginalUnit), _this select 0] spawn FUNC(switchBack); + }]; + _unit setVariable [QGVAR(RespawnEhId), _respawnEhId, true]; + + // set owner back to original owner + _oldOwner = _oldUnit getVariable[QGVAR(OriginalOwner), -1]; + if (_oldOwner > -1) then { + [[_oldUnit, _oldOwner], QUOTE({(_this select 0) setOwner (_this select 1)}), 1] call EFUNC(Core, execRemoteFnc); + }; + + [localize "STR_ACE_SwitchUnits_SwitchedUnit"] call EFUNC(Core, displayTextStructured); +}; diff --git a/addons/switchunits/script_component.hpp b/addons/switchunits/script_component.hpp new file mode 100644 index 0000000000..3c4c77c007 --- /dev/null +++ b/addons/switchunits/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT SwitchUnits +#include "\z\ace\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_SwitchUnits + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_SwitchUnits + #define DEBUG_SETTINGS DEBUG_SETTINGS_SwitchUnits +#endif + +#include "\z\ace\addons\main\script_macros.hpp" diff --git a/TO_MERGE/agm/SwitchUnits/stringtable.xml b/addons/switchunits/stringtable.xml similarity index 100% rename from TO_MERGE/agm/SwitchUnits/stringtable.xml rename to addons/switchunits/stringtable.xml