From f3427938b301c28c62e7786a726757cbe84d78b6 Mon Sep 17 00:00:00 2001 From: jodav Date: Mon, 12 Jan 2015 14:54:36 +0100 Subject: [PATCH 1/4] init --- .../_switchunits}/UI/IconSwitchUnits_ca.paa | Bin .../_switchunits}/clientInit.sqf | 0 .../_switchunits}/config.cpp | 0 .../functions/fn_addMapFunction.sqf | 0 .../functions/fn_handleMapClick.sqf | 0 .../_switchunits}/functions/fn_initPlayer.sqf | 0 .../_switchunits}/functions/fn_isValidAi.sqf | 0 .../functions/fn_markAiOnMap.sqf | 0 .../_switchunits}/functions/fn_module.sqf | 0 .../functions/fn_nearestPlayers.sqf | 0 .../_switchunits}/functions/fn_switchBack.sqf | 0 .../_switchunits}/functions/fn_switchUnit.sqf | 0 .../_switchunits}/stringtable.xml | 0 addons/switchunits/CfgEventHandlers.hpp | 5 ++ addons/switchunits/UI/IconSwitchUnits_ca.paa | Bin 0 -> 5625 bytes addons/switchunits/XEH_preInit.sqf | 11 +++ addons/switchunits/config.cpp | 17 ++++ .../functions/fnc_addMapFunction.sqf | 23 +++++ .../functions/fnc_handleMapClick.sqf | 41 +++++++++ .../switchunits/functions/fnc_initPlayer.sqf | 48 +++++++++++ .../switchunits/functions/fnc_isValidAi.sqf | 25 ++++++ .../switchunits/functions/fnc_markAiOnMap.sqf | 64 ++++++++++++++ addons/switchunits/functions/fnc_module.sqf | 38 +++++++++ .../functions/fnc_nearestPlayers.sqf | 31 +++++++ .../switchunits/functions/fnc_switchBack.sqf | 29 +++++++ .../switchunits/functions/fnc_switchUnit.sqf | 79 ++++++++++++++++++ addons/switchunits/script_component.hpp | 12 +++ 27 files changed, 423 insertions(+) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/UI/IconSwitchUnits_ca.paa (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/clientInit.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/config.cpp (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_addMapFunction.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_handleMapClick.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_initPlayer.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_isValidAi.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_markAiOnMap.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_module.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_nearestPlayers.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_switchBack.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/functions/fn_switchUnit.sqf (100%) rename {TO_MERGE/agm/SwitchUnits => addons/_switchunits}/stringtable.xml (100%) create mode 100644 addons/switchunits/CfgEventHandlers.hpp create mode 100644 addons/switchunits/UI/IconSwitchUnits_ca.paa create mode 100644 addons/switchunits/XEH_preInit.sqf create mode 100644 addons/switchunits/config.cpp create mode 100644 addons/switchunits/functions/fnc_addMapFunction.sqf create mode 100644 addons/switchunits/functions/fnc_handleMapClick.sqf create mode 100644 addons/switchunits/functions/fnc_initPlayer.sqf create mode 100644 addons/switchunits/functions/fnc_isValidAi.sqf create mode 100644 addons/switchunits/functions/fnc_markAiOnMap.sqf create mode 100644 addons/switchunits/functions/fnc_module.sqf create mode 100644 addons/switchunits/functions/fnc_nearestPlayers.sqf create mode 100644 addons/switchunits/functions/fnc_switchBack.sqf create mode 100644 addons/switchunits/functions/fnc_switchUnit.sqf create mode 100644 addons/switchunits/script_component.hpp 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/clientInit.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/clientInit.sqf rename to addons/_switchunits/clientInit.sqf diff --git a/TO_MERGE/agm/SwitchUnits/config.cpp b/addons/_switchunits/config.cpp similarity index 100% rename from TO_MERGE/agm/SwitchUnits/config.cpp rename to addons/_switchunits/config.cpp diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_addMapFunction.sqf b/addons/_switchunits/functions/fn_addMapFunction.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_addMapFunction.sqf rename to addons/_switchunits/functions/fn_addMapFunction.sqf diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_handleMapClick.sqf b/addons/_switchunits/functions/fn_handleMapClick.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_handleMapClick.sqf rename to addons/_switchunits/functions/fn_handleMapClick.sqf diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_initPlayer.sqf b/addons/_switchunits/functions/fn_initPlayer.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_initPlayer.sqf rename to addons/_switchunits/functions/fn_initPlayer.sqf diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_isValidAi.sqf b/addons/_switchunits/functions/fn_isValidAi.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_isValidAi.sqf rename to addons/_switchunits/functions/fn_isValidAi.sqf diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_markAiOnMap.sqf b/addons/_switchunits/functions/fn_markAiOnMap.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_markAiOnMap.sqf rename to addons/_switchunits/functions/fn_markAiOnMap.sqf diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_module.sqf b/addons/_switchunits/functions/fn_module.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_module.sqf rename to addons/_switchunits/functions/fn_module.sqf diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_nearestPlayers.sqf b/addons/_switchunits/functions/fn_nearestPlayers.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_nearestPlayers.sqf rename to addons/_switchunits/functions/fn_nearestPlayers.sqf diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_switchBack.sqf b/addons/_switchunits/functions/fn_switchBack.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_switchBack.sqf rename to addons/_switchunits/functions/fn_switchBack.sqf diff --git a/TO_MERGE/agm/SwitchUnits/functions/fn_switchUnit.sqf b/addons/_switchunits/functions/fn_switchUnit.sqf similarity index 100% rename from TO_MERGE/agm/SwitchUnits/functions/fn_switchUnit.sqf rename to addons/_switchunits/functions/fn_switchUnit.sqf 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 diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp new file mode 100644 index 0000000000..8af0265fe2 --- /dev/null +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -0,0 +1,5 @@ +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE( call compile preprocessFileLineNumbers PATHTOF(XEH_preInit.sqf) ); + }; +}; \ No newline at end of file diff --git a/addons/switchunits/UI/IconSwitchUnits_ca.paa b/addons/switchunits/UI/IconSwitchUnits_ca.paa new file mode 100644 index 0000000000000000000000000000000000000000..b5868f0423526e23d333d64c0059bd4cde278f1d GIT binary patch literal 5625 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 - sided + + Returns: + VOID +*/ + +private ["_unit"]; +_unit = _this select 0; + +["theMapClick", "onMapSingleClick", { + [_this, _pos, _shift, _alt] call AGM_SwitchUnits_fnc_handleMapClick; +}, [_unit, _sides]] call BIS_fnc_addStackedEventHandler; diff --git a/addons/switchunits/functions/fnc_handleMapClick.sqf b/addons/switchunits/functions/fnc_handleMapClick.sqf new file mode 100644 index 0000000000..642baed1bd --- /dev/null +++ b/addons/switchunits/functions/fnc_handleMapClick.sqf @@ -0,0 +1,41 @@ +/* + Name: AGM_SwitchUnits_fnc_handleMapClick + + Author(s): + bux578 + + Description: + Finds the clicked unit + + Parameters: + 0: OBJECT - MapClickEventHandlerArgs + 0: OBJECT - unit to switch to + 1: ARRAY - sides + + Returns: + VOID +*/ + +private ["_args", "_currentPlayerUnit", "_sides", "_pos", "_sideNearest"]; + +_currentPlayerUnit = (_this select 0) select 0; +_sides = (_this select 0) select 1; +_pos = _this select 1; + +_sideNearest = []; + +{ + if ([_x] call AGM_SwitchUnits_fnc_isValidAi && (side group _x in _sides)) then { + _sideNearest pushBack _x; + }; +} forEach (nearestObjects [_pos, ["Man"], 20]); + + +if (count _sideNearest > 0) then { + private ["_switchUnit"]; + + _switchUnit = _sideNearest select 0; + [_currentPlayerUnit, _switchUnit] call AGM_SwitchUnits_fnc_switchUnit; + + openMap false; +}; diff --git a/addons/switchunits/functions/fnc_initPlayer.sqf b/addons/switchunits/functions/fnc_initPlayer.sqf new file mode 100644 index 0000000000..c3ee6ce7b2 --- /dev/null +++ b/addons/switchunits/functions/fnc_initPlayer.sqf @@ -0,0 +1,48 @@ +/* + Name: AGM_SwitchUnits_fnc_initPlayer + + Author(s): + bux578 + + Description: + Initializes the player + + Parameters: + 0: OBJECT - player + 1: ARRAY - Array containing selected sides + + Returns: + VOID +*/ + +private ["_playerUnit", "_sides"]; + +_playerUnit = _this select 0; +_sides = _this select 1; + +if (vehicle _playerUnit == _playerUnit) then { + + [_sides] call AGM_SwitchUnits_fnc_markAiOnMap; + + _playerUnit setVariable ["AGM_SwitchUnits_IsPlayerUnit", true]; + _playerUnit allowDamage false; + + AGM_SwitchUnits_OriginalUnit = _playerUnit; + AGM_SwitchUnits_OriginalName = [_playerUnit] call AGM_Core_fnc_getName; + AGM_SwitchUnits_OriginalGroup = group _playerUnit; + + // remove all starting gear of a player + removeAllWeapons _playerUnit; + removeGoggles _playerUnit; + removeHeadgear _playerUnit; + removeVest _playerUnit; + removeAllAssignedItems _playerUnit; + clearAllItemsFromBackpack _playerUnit; + removeBackpack _playerUnit; + _playerUnit linkItem "ItemMap"; + removeUniform _playerUnit; + + [_playerUnit, "AGM_SwitchUnits", true] call AGM_Core_fnc_setForceWalkStatus; + + [_playerUnit, _sides] call AGM_SwitchUnits_fnc_addMapFunction; +}; diff --git a/addons/switchunits/functions/fnc_isValidAi.sqf b/addons/switchunits/functions/fnc_isValidAi.sqf new file mode 100644 index 0000000000..f91b27ffbe --- /dev/null +++ b/addons/switchunits/functions/fnc_isValidAi.sqf @@ -0,0 +1,25 @@ +/* + Name: AGM_SwitchUnits_fnc_isValidAi + + Author(s): + bux578 + + Description: + Checks if AI is a valid target for switching + + Parameters: + 0: OBJECT - unit + + Returns: + VOID +*/ + +private ["_unit"]; + +_unit = _this select 0; + +!([_unit] call AGM_Core_fnc_isPlayer +|| {_unit in playableUnits} +|| {vehicle _unit != _unit} +|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerUnit", false]} +|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerControlled", false]}) diff --git a/addons/switchunits/functions/fnc_markAiOnMap.sqf b/addons/switchunits/functions/fnc_markAiOnMap.sqf new file mode 100644 index 0000000000..05865bc060 --- /dev/null +++ b/addons/switchunits/functions/fnc_markAiOnMap.sqf @@ -0,0 +1,64 @@ +/* + Name: AGM_SwitchUnits_fnc_markAiOnMap + + Author(s): + bux578 + + Description: + Creates markers for AI units for given sides + Marks players in a different color + + Parameters: + 0: OBJECT - side + + Returns: + VOID +*/ + +private ["_sidesToShow"]; +_sidesToShow = _this select 0; + +_sidesToShow spawn { + + private ["_sides", "_allMarkerNames"]; + _sides = _this; + _allMarkerNames = []; + + while { true } do { + sleep 1.5; + + // delete markers + { + deleteMarkerLocal _x; + } forEach _allMarkerNames; + + // create markers + { + if (([_x] call AGM_SwitchUnits_fnc_isValidAi && (side group _x in _sides)) || (_x getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])) then { + private ["_markerName", "_marker", "_markerColor"]; + + //_markerName = format ["%1", [_x] call AGM_Core_fnc_getName]; + _markerName = str _x; + + _marker = createMarkerLocal [_markerName, position _x]; + _markerName setMarkerTypeLocal "mil_triangle"; + _markerName setMarkerShapeLocal "ICON"; + _markerName setMarkerSizeLocal [0.5,0.7]; + _markerName setMarkerDirLocal getDir _x; + + // commy's one liner magic + _markerColor = format ["Color%1", side group _x]; + + if ((_x getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])) then { + _markerName setMarkerColorLocal "ColorOrange"; + _markerName setMarkerTextLocal (_x getVariable ["AGM_SwitchUnits_PlayerControlledName",""]); + } else { + _markerName setMarkerColorLocal _markerColor; + _markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName")); + }; + + _allMarkerNames pushBack _markerName; + }; + } forEach allUnits; + }; +}; diff --git a/addons/switchunits/functions/fnc_module.sqf b/addons/switchunits/functions/fnc_module.sqf new file mode 100644 index 0000000000..43ec26199a --- /dev/null +++ b/addons/switchunits/functions/fnc_module.sqf @@ -0,0 +1,38 @@ +/* + 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/addons/switchunits/functions/fnc_nearestPlayers.sqf b/addons/switchunits/functions/fnc_nearestPlayers.sqf new file mode 100644 index 0000000000..04b185c455 --- /dev/null +++ b/addons/switchunits/functions/fnc_nearestPlayers.sqf @@ -0,0 +1,31 @@ +/* + Name: AGM_SwitchUnits_fnc_nearestPlayers + + Author(s): + bux578 + + Description: + Returns an array of alive players in a given radius around a given location + + Parameters: + 0: POSTION - Center position + 1: NUMBER - Radius + + Returns: + ARRAY - Player units +*/ + +private ["_position", "_radius", "_nearestPlayers"]; + +_position = _this select 0; +_radius = _this select 1; + +_nearestPlayers = []; + +{ + if ([_x] call AGM_Core_fnc_isPlayer && {alive _x}) then { + _nearestPlayers pushBack _x; + }; +} forEach (nearestObjects [_position, ["Man"], _radius]); + + _nearestPlayers diff --git a/addons/switchunits/functions/fnc_switchBack.sqf b/addons/switchunits/functions/fnc_switchBack.sqf new file mode 100644 index 0000000000..eba84d57f6 --- /dev/null +++ b/addons/switchunits/functions/fnc_switchBack.sqf @@ -0,0 +1,29 @@ +/* + Name: AGM_SwitchUnits_fnc_switchBack + + Author(s): + bux578 + + Description: + Switches back to the original player unit + This method needs to be "spawn"ed + + Parameters: + 0: OBJECT - original player unit + 1: OBJECT - respawned unit + + Returns: + VOID +*/ + +private ["_originalPlayerUnit", "_currentUnit"]; +_originalPlayerUnit = _this select 0; +_currentUnit = _this select 1; + +[_originalPlayerUnit] joinSilent AGM_SwitchUnits_OriginalGroup; + +waitUntil {local _originalPlayerUnit}; + +selectPlayer _originalPlayerUnit; + +deleteVehicle _currentUnit; diff --git a/addons/switchunits/functions/fnc_switchUnit.sqf b/addons/switchunits/functions/fnc_switchUnit.sqf new file mode 100644 index 0000000000..ddb2a1d523 --- /dev/null +++ b/addons/switchunits/functions/fnc_switchUnit.sqf @@ -0,0 +1,79 @@ +/* + 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/script_component.hpp b/addons/switchunits/script_component.hpp new file mode 100644 index 0000000000..40058509c2 --- /dev/null +++ b/addons/switchunits/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT blank +#include "\z\ace\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_BLANK + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_BLANK + #define DEBUG_SETTINGS DEBUG_SETTINGS_BLANK +#endif + +#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file From 7afce2a2417a5812aeea06116faea9adab371a06 Mon Sep 17 00:00:00 2001 From: jodav Date: Mon, 12 Jan 2015 15:09:07 +0100 Subject: [PATCH 2/4] more work --- addons/_switchunits/stringtable.xml | 6 +++--- addons/switchunits/CfgEventHandlers.hpp | 8 +++++++- addons/switchunits/XEH_postInit.sqf | 23 +++++++++++++++++++++++ addons/switchunits/config.cpp | 12 ++++++------ addons/switchunits/script_component.hpp | 10 +++++----- addons/switchunits/stringtable.xml | 22 ++++++++++++++++++++++ 6 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 addons/switchunits/XEH_postInit.sqf create mode 100644 addons/switchunits/stringtable.xml diff --git a/addons/_switchunits/stringtable.xml b/addons/_switchunits/stringtable.xml index 76e9782e5d..b12e8dc17d 100644 --- a/addons/_switchunits/stringtable.xml +++ b/addons/_switchunits/stringtable.xml @@ -1,8 +1,8 @@  - + - + Switched unit Einheit gewechselt Юнит переключен @@ -10,7 +10,7 @@ Przełącz jednostkę Cambiado de unidad - + This unit is too close to the enemy. Diese Einheit ist zu nah am Feind. Юнит слишком близок к противнику diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp index 8af0265fe2..35185e3a45 100644 --- a/addons/switchunits/CfgEventHandlers.hpp +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -2,4 +2,10 @@ class Extended_PreInit_EventHandlers { class ADDON { init = QUOTE( call compile preprocessFileLineNumbers PATHTOF(XEH_preInit.sqf) ); }; -}; \ No newline at end of file +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + postInit = QUOTE(call COMPILE_FILE(XEH_postInit) ); + }; +}; diff --git a/addons/switchunits/XEH_postInit.sqf b/addons/switchunits/XEH_postInit.sqf new file mode 100644 index 0000000000..6c769a5903 --- /dev/null +++ b/addons/switchunits/XEH_postInit.sqf @@ -0,0 +1,23 @@ +/* + Author(s): + bux578 +*/ + +0 spawn { + private ["_side"]; + + waitUntil {sleep 0.5; AGM_SwitchUnits_EnableSwitchUnits}; + + //_side = [west, east, independent, civilian] select AGM_SwitchUnits_SwitchUnitsAllowedForSide; + + _sides = []; + + if(AGM_SwitchUnits_SwitchToWest) then {_sides pushBack west}; + if(AGM_SwitchUnits_SwitchToEast) then {_sides pushBack east}; + if(AGM_SwitchUnits_SwitchToIndependent) then {_sides pushBack independent}; + if(AGM_SwitchUnits_SwitchToCivilian) then {_sides pushBack civilian}; + + if (player getVariable ["AGM_CanSwitchUnits", false]) then { + [player, _sides] call AGM_SwitchUnits_fnc_initPlayer; + }; +}; diff --git a/addons/switchunits/config.cpp b/addons/switchunits/config.cpp index 628865c703..f69ceb691b 100644 --- a/addons/switchunits/config.cpp +++ b/addons/switchunits/config.cpp @@ -6,12 +6,12 @@ class CfgPatches { weapons[] = {}; requiredVersion = 0.60; requiredAddons[] = {"ace_core"}; - version = "0.95"; - versionStr = "0.95"; - versionAr[] = {0,95,0}; - author[] = {""}; - authorUrl = ""; + version = QUOTE(VERSION); + versionStr = QUOTE(VERSION); + versionAr[] = {VERSION_AR}; + author[] = {"bux578"}; + authorUrl = "https://github.com/bux578/"; }; }; -#include "CfgEventHandlers.hpp" \ No newline at end of file +#include "CfgEventHandlers.hpp" diff --git a/addons/switchunits/script_component.hpp b/addons/switchunits/script_component.hpp index 40058509c2..3c4c77c007 100644 --- a/addons/switchunits/script_component.hpp +++ b/addons/switchunits/script_component.hpp @@ -1,12 +1,12 @@ -#define COMPONENT blank +#define COMPONENT SwitchUnits #include "\z\ace\addons\main\script_mod.hpp" -#ifdef DEBUG_ENABLED_BLANK +#ifdef DEBUG_ENABLED_SwitchUnits #define DEBUG_MODE_FULL #endif -#ifdef DEBUG_SETTINGS_BLANK - #define DEBUG_SETTINGS DEBUG_SETTINGS_BLANK +#ifdef DEBUG_SETTINGS_SwitchUnits + #define DEBUG_SETTINGS DEBUG_SETTINGS_SwitchUnits #endif -#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file +#include "\z\ace\addons\main\script_macros.hpp" diff --git a/addons/switchunits/stringtable.xml b/addons/switchunits/stringtable.xml new file mode 100644 index 0000000000..76e9782e5d --- /dev/null +++ b/addons/switchunits/stringtable.xml @@ -0,0 +1,22 @@ + + + + + + Switched unit + Einheit gewechselt + Юнит переключен + Prohozená jednotka + Przełącz jednostkę + Cambiado de unidad + + + This unit is too close to the enemy. + Diese Einheit ist zu nah am Feind. + Юнит слишком близок к противнику + Tato jednotka je moc blízko k nepříteli. + Ta jednostka jest zbyt blisko przeciwnika. + Esta unidad está demasiado cerca del enemigo. + + + From 5da1bdf9c00b10a09f407e43071c0252973fe4df Mon Sep 17 00:00:00 2001 From: bux578 Date: Mon, 12 Jan 2015 15:47:22 +0100 Subject: [PATCH 3/4] finish cba'ing --- addons/switchunits/CfgEventHandlers.hpp | 2 +- addons/switchunits/CfgVehicles.hpp | 65 +++++++++++++++++++ addons/switchunits/config.cpp | 14 ++++ .../functions/fnc_addMapFunction.sqf | 4 +- .../functions/fnc_handleMapClick.sqf | 6 +- .../switchunits/functions/fnc_initPlayer.sqf | 16 +++-- .../switchunits/functions/fnc_isValidAi.sqf | 8 ++- .../switchunits/functions/fnc_markAiOnMap.sqf | 10 +-- addons/switchunits/functions/fnc_module.sqf | 22 ++++--- .../functions/fnc_nearestPlayers.sqf | 4 +- .../switchunits/functions/fnc_switchBack.sqf | 4 +- .../switchunits/functions/fnc_switchUnit.sqf | 34 +++++----- 12 files changed, 143 insertions(+), 46 deletions(-) create mode 100644 addons/switchunits/CfgVehicles.hpp diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp index 35185e3a45..47dcd984d1 100644 --- a/addons/switchunits/CfgEventHandlers.hpp +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -1,6 +1,6 @@ class Extended_PreInit_EventHandlers { class ADDON { - init = QUOTE( call compile preprocessFileLineNumbers PATHTOF(XEH_preInit.sqf) ); + init = QUOTE( call COMPILE_FILE(XEH_preInit) ); }; }; 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/addons/switchunits/config.cpp b/addons/switchunits/config.cpp index f69ceb691b..63e81332cc 100644 --- a/addons/switchunits/config.cpp +++ b/addons/switchunits/config.cpp @@ -15,3 +15,17 @@ class CfgPatches { }; #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/addons/switchunits/functions/fnc_addMapFunction.sqf b/addons/switchunits/functions/fnc_addMapFunction.sqf index f65725aacf..0607d00fd3 100644 --- a/addons/switchunits/functions/fnc_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/addons/switchunits/functions/fnc_handleMapClick.sqf b/addons/switchunits/functions/fnc_handleMapClick.sqf index 642baed1bd..eb5da3ad10 100644 --- a/addons/switchunits/functions/fnc_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/addons/switchunits/functions/fnc_initPlayer.sqf b/addons/switchunits/functions/fnc_initPlayer.sqf index c3ee6ce7b2..60e5eaabc7 100644 --- a/addons/switchunits/functions/fnc_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/addons/switchunits/functions/fnc_isValidAi.sqf b/addons/switchunits/functions/fnc_isValidAi.sqf index f91b27ffbe..3803ce4fbd 100644 --- a/addons/switchunits/functions/fnc_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/addons/switchunits/functions/fnc_markAiOnMap.sqf b/addons/switchunits/functions/fnc_markAiOnMap.sqf index 05865bc060..79e72c7379 100644 --- a/addons/switchunits/functions/fnc_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 index 43ec26199a..c614b9c6d7 100644 --- a/addons/switchunits/functions/fnc_module.sqf +++ b/addons/switchunits/functions/fnc_module.sqf @@ -16,6 +16,8 @@ BOOLEAN (Good practice to include one) */ +#include "script_component.hpp" + if !(isServer) exitWith {}; _logic = _this select 0; @@ -23,16 +25,16 @@ _activated = _this select 2; if !(_activated) exitWith {}; -AGM_SwitchUnits_Module = true; +GVAR(Module) = true; -["AGM_SwitchUnits_EnableSwitchUnits", true] call AGM_Core_fnc_setParameter; +[QGVAR(EnableSwitchUnits), true] call EFUNC(Core, 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, 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); -[_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."; +diag_log text "[ACE]: SwitchUnits Module Initialized."; diff --git a/addons/switchunits/functions/fnc_nearestPlayers.sqf b/addons/switchunits/functions/fnc_nearestPlayers.sqf index 04b185c455..6475185171 100644 --- a/addons/switchunits/functions/fnc_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/addons/switchunits/functions/fnc_switchBack.sqf b/addons/switchunits/functions/fnc_switchBack.sqf index eba84d57f6..e9425c4fa4 100644 --- a/addons/switchunits/functions/fnc_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 index ddb2a1d523..6002ee3f8f 100644 --- a/addons/switchunits/functions/fnc_switchUnit.sqf +++ b/addons/switchunits/functions/fnc_switchUnit.sqf @@ -14,12 +14,14 @@ VOID */ +#include "script_component.hpp" + private ["_newUnit"]; _newUnit = _this select 1; // don't switch to original player units -if (!([_newUnit] call AGM_SwitchUnits_fnc_isValidAi)) exitWith {}; +if (!([_newUnit] call FUNC(isValidAi))) exitWith {}; _newUnit spawn { private ["_unit", "_allNearestPlayers", "_oldUnit", "_respawnEhId", "_oldOwner", "_leave"]; @@ -28,10 +30,10 @@ _newUnit spawn { _leave = false; - if (AGM_SwitchUnits_EnableSafeZone) then { + if (GVAR(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; + _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; @@ -40,40 +42,40 @@ _newUnit spawn { // exitWith doesn't exit past the "if(EnableSafeZone)" block if (_leave) exitWith { - [localize "STR_AGM_SwitchUnits_TooCloseToEnemy"] call AGM_Core_fnc_displayTextStructured; + [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], "{(_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; + [[_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 ["AGM_SwitchUnits_IsPlayerControlled", false, true]; - _oldUnit setVariable ["AGM_SwitchUnits_PlayerControlledName", "", true]; + _oldUnit setVariable [QGVAR(IsPlayerControlled), false, true]; + _oldUnit setVariable [QGVAR(PlayerControlledName), "", true]; - _respawnEhId = _unit getVariable ["AGM_SwitchUnits_RespawnEhId", -1]; + _respawnEhId = _unit getVariable [QGVAR(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]; + _unit setVariable [QGVAR(IsPlayerControlled), true, true]; + _unit setVariable [QGVAR(PlayerControlledName), GVAR(OriginalName), true]; _respawnEhId = _unit addEventHandler ["Respawn", { - [AGM_SwitchUnits_OriginalUnit, _this select 0] spawn AGM_SwitchUnits_fnc_switchBack; + [GVAR(OriginalUnit), _this select 0] spawn FUNC(switchBack); }]; - _unit setVariable ["AGM_SwitchUnits_RespawnEhId", _respawnEhId, true]; + _unit setVariable [QGVAR(RespawnEhId), _respawnEhId, true]; // set owner back to original owner - _oldOwner = _oldUnit getVariable["AGM_SwitchUnits_OriginalOwner", -1]; + _oldOwner = _oldUnit getVariable[QGVAR(OriginalOwner), -1]; if (_oldOwner > -1) then { - [[_oldUnit, _oldOwner], "{(_this select 0) setOwner (_this select 1)}", 1] call AGM_Core_fnc_execRemoteFnc; + [[_oldUnit, _oldOwner], QUOTE({(_this select 0) setOwner (_this select 1)}), 1] call EFUNC(Core, execRemoteFnc); }; - [localize "STR_AGM_SwitchUnits_SwitchedUnit"] call AGM_Core_fnc_displayTextStructured; + [localize "STR_ACE_SwitchUnits_SwitchedUnit"] call EFUNC(Core, displayTextStructured); }; From 91ba0c6a55fcf6ea8741c35b742c03f2cb9fe57b Mon Sep 17 00:00:00 2001 From: bux578 Date: Mon, 12 Jan 2015 15:48:32 +0100 Subject: [PATCH 4/4] remove temp folder didn't mean to push this --- addons/_switchunits/UI/IconSwitchUnits_ca.paa | Bin 5625 -> 0 bytes addons/_switchunits/clientInit.sqf | 23 --- addons/_switchunits/config.cpp | 140 ------------------ .../functions/fn_addMapFunction.sqf | 23 --- .../functions/fn_handleMapClick.sqf | 41 ----- .../_switchunits/functions/fn_initPlayer.sqf | 48 ------ .../_switchunits/functions/fn_isValidAi.sqf | 25 ---- .../_switchunits/functions/fn_markAiOnMap.sqf | 64 -------- addons/_switchunits/functions/fn_module.sqf | 38 ----- .../functions/fn_nearestPlayers.sqf | 31 ---- .../_switchunits/functions/fn_switchBack.sqf | 29 ---- .../_switchunits/functions/fn_switchUnit.sqf | 79 ---------- addons/_switchunits/stringtable.xml | 22 --- 13 files changed, 563 deletions(-) delete mode 100644 addons/_switchunits/UI/IconSwitchUnits_ca.paa delete mode 100644 addons/_switchunits/clientInit.sqf delete mode 100644 addons/_switchunits/config.cpp delete mode 100644 addons/_switchunits/functions/fn_addMapFunction.sqf delete mode 100644 addons/_switchunits/functions/fn_handleMapClick.sqf delete mode 100644 addons/_switchunits/functions/fn_initPlayer.sqf delete mode 100644 addons/_switchunits/functions/fn_isValidAi.sqf delete mode 100644 addons/_switchunits/functions/fn_markAiOnMap.sqf delete mode 100644 addons/_switchunits/functions/fn_module.sqf delete mode 100644 addons/_switchunits/functions/fn_nearestPlayers.sqf delete mode 100644 addons/_switchunits/functions/fn_switchBack.sqf delete mode 100644 addons/_switchunits/functions/fn_switchUnit.sqf delete mode 100644 addons/_switchunits/stringtable.xml diff --git a/addons/_switchunits/UI/IconSwitchUnits_ca.paa b/addons/_switchunits/UI/IconSwitchUnits_ca.paa deleted file mode 100644 index b5868f0423526e23d333d64c0059bd4cde278f1d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5625 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 - sided - - Returns: - VOID -*/ - -private ["_unit"]; -_unit = _this select 0; - -["theMapClick", "onMapSingleClick", { - [_this, _pos, _shift, _alt] call AGM_SwitchUnits_fnc_handleMapClick; -}, [_unit, _sides]] call BIS_fnc_addStackedEventHandler; diff --git a/addons/_switchunits/functions/fn_handleMapClick.sqf b/addons/_switchunits/functions/fn_handleMapClick.sqf deleted file mode 100644 index 642baed1bd..0000000000 --- a/addons/_switchunits/functions/fn_handleMapClick.sqf +++ /dev/null @@ -1,41 +0,0 @@ -/* - Name: AGM_SwitchUnits_fnc_handleMapClick - - Author(s): - bux578 - - Description: - Finds the clicked unit - - Parameters: - 0: OBJECT - MapClickEventHandlerArgs - 0: OBJECT - unit to switch to - 1: ARRAY - sides - - Returns: - VOID -*/ - -private ["_args", "_currentPlayerUnit", "_sides", "_pos", "_sideNearest"]; - -_currentPlayerUnit = (_this select 0) select 0; -_sides = (_this select 0) select 1; -_pos = _this select 1; - -_sideNearest = []; - -{ - if ([_x] call AGM_SwitchUnits_fnc_isValidAi && (side group _x in _sides)) then { - _sideNearest pushBack _x; - }; -} forEach (nearestObjects [_pos, ["Man"], 20]); - - -if (count _sideNearest > 0) then { - private ["_switchUnit"]; - - _switchUnit = _sideNearest select 0; - [_currentPlayerUnit, _switchUnit] call AGM_SwitchUnits_fnc_switchUnit; - - openMap false; -}; diff --git a/addons/_switchunits/functions/fn_initPlayer.sqf b/addons/_switchunits/functions/fn_initPlayer.sqf deleted file mode 100644 index c3ee6ce7b2..0000000000 --- a/addons/_switchunits/functions/fn_initPlayer.sqf +++ /dev/null @@ -1,48 +0,0 @@ -/* - Name: AGM_SwitchUnits_fnc_initPlayer - - Author(s): - bux578 - - Description: - Initializes the player - - Parameters: - 0: OBJECT - player - 1: ARRAY - Array containing selected sides - - Returns: - VOID -*/ - -private ["_playerUnit", "_sides"]; - -_playerUnit = _this select 0; -_sides = _this select 1; - -if (vehicle _playerUnit == _playerUnit) then { - - [_sides] call AGM_SwitchUnits_fnc_markAiOnMap; - - _playerUnit setVariable ["AGM_SwitchUnits_IsPlayerUnit", true]; - _playerUnit allowDamage false; - - AGM_SwitchUnits_OriginalUnit = _playerUnit; - AGM_SwitchUnits_OriginalName = [_playerUnit] call AGM_Core_fnc_getName; - AGM_SwitchUnits_OriginalGroup = group _playerUnit; - - // remove all starting gear of a player - removeAllWeapons _playerUnit; - removeGoggles _playerUnit; - removeHeadgear _playerUnit; - removeVest _playerUnit; - removeAllAssignedItems _playerUnit; - clearAllItemsFromBackpack _playerUnit; - removeBackpack _playerUnit; - _playerUnit linkItem "ItemMap"; - removeUniform _playerUnit; - - [_playerUnit, "AGM_SwitchUnits", true] call AGM_Core_fnc_setForceWalkStatus; - - [_playerUnit, _sides] call AGM_SwitchUnits_fnc_addMapFunction; -}; diff --git a/addons/_switchunits/functions/fn_isValidAi.sqf b/addons/_switchunits/functions/fn_isValidAi.sqf deleted file mode 100644 index f91b27ffbe..0000000000 --- a/addons/_switchunits/functions/fn_isValidAi.sqf +++ /dev/null @@ -1,25 +0,0 @@ -/* - Name: AGM_SwitchUnits_fnc_isValidAi - - Author(s): - bux578 - - Description: - Checks if AI is a valid target for switching - - Parameters: - 0: OBJECT - unit - - Returns: - VOID -*/ - -private ["_unit"]; - -_unit = _this select 0; - -!([_unit] call AGM_Core_fnc_isPlayer -|| {_unit in playableUnits} -|| {vehicle _unit != _unit} -|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerUnit", false]} -|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerControlled", false]}) diff --git a/addons/_switchunits/functions/fn_markAiOnMap.sqf b/addons/_switchunits/functions/fn_markAiOnMap.sqf deleted file mode 100644 index 05865bc060..0000000000 --- a/addons/_switchunits/functions/fn_markAiOnMap.sqf +++ /dev/null @@ -1,64 +0,0 @@ -/* - Name: AGM_SwitchUnits_fnc_markAiOnMap - - Author(s): - bux578 - - Description: - Creates markers for AI units for given sides - Marks players in a different color - - Parameters: - 0: OBJECT - side - - Returns: - VOID -*/ - -private ["_sidesToShow"]; -_sidesToShow = _this select 0; - -_sidesToShow spawn { - - private ["_sides", "_allMarkerNames"]; - _sides = _this; - _allMarkerNames = []; - - while { true } do { - sleep 1.5; - - // delete markers - { - deleteMarkerLocal _x; - } forEach _allMarkerNames; - - // create markers - { - if (([_x] call AGM_SwitchUnits_fnc_isValidAi && (side group _x in _sides)) || (_x getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])) then { - private ["_markerName", "_marker", "_markerColor"]; - - //_markerName = format ["%1", [_x] call AGM_Core_fnc_getName]; - _markerName = str _x; - - _marker = createMarkerLocal [_markerName, position _x]; - _markerName setMarkerTypeLocal "mil_triangle"; - _markerName setMarkerShapeLocal "ICON"; - _markerName setMarkerSizeLocal [0.5,0.7]; - _markerName setMarkerDirLocal getDir _x; - - // commy's one liner magic - _markerColor = format ["Color%1", side group _x]; - - if ((_x getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])) then { - _markerName setMarkerColorLocal "ColorOrange"; - _markerName setMarkerTextLocal (_x getVariable ["AGM_SwitchUnits_PlayerControlledName",""]); - } else { - _markerName setMarkerColorLocal _markerColor; - _markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName")); - }; - - _allMarkerNames pushBack _markerName; - }; - } forEach allUnits; - }; -}; diff --git a/addons/_switchunits/functions/fn_module.sqf b/addons/_switchunits/functions/fn_module.sqf deleted file mode 100644 index 43ec26199a..0000000000 --- a/addons/_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/addons/_switchunits/functions/fn_nearestPlayers.sqf b/addons/_switchunits/functions/fn_nearestPlayers.sqf deleted file mode 100644 index 04b185c455..0000000000 --- a/addons/_switchunits/functions/fn_nearestPlayers.sqf +++ /dev/null @@ -1,31 +0,0 @@ -/* - Name: AGM_SwitchUnits_fnc_nearestPlayers - - Author(s): - bux578 - - Description: - Returns an array of alive players in a given radius around a given location - - Parameters: - 0: POSTION - Center position - 1: NUMBER - Radius - - Returns: - ARRAY - Player units -*/ - -private ["_position", "_radius", "_nearestPlayers"]; - -_position = _this select 0; -_radius = _this select 1; - -_nearestPlayers = []; - -{ - if ([_x] call AGM_Core_fnc_isPlayer && {alive _x}) then { - _nearestPlayers pushBack _x; - }; -} forEach (nearestObjects [_position, ["Man"], _radius]); - - _nearestPlayers diff --git a/addons/_switchunits/functions/fn_switchBack.sqf b/addons/_switchunits/functions/fn_switchBack.sqf deleted file mode 100644 index eba84d57f6..0000000000 --- a/addons/_switchunits/functions/fn_switchBack.sqf +++ /dev/null @@ -1,29 +0,0 @@ -/* - Name: AGM_SwitchUnits_fnc_switchBack - - Author(s): - bux578 - - Description: - Switches back to the original player unit - This method needs to be "spawn"ed - - Parameters: - 0: OBJECT - original player unit - 1: OBJECT - respawned unit - - Returns: - VOID -*/ - -private ["_originalPlayerUnit", "_currentUnit"]; -_originalPlayerUnit = _this select 0; -_currentUnit = _this select 1; - -[_originalPlayerUnit] joinSilent AGM_SwitchUnits_OriginalGroup; - -waitUntil {local _originalPlayerUnit}; - -selectPlayer _originalPlayerUnit; - -deleteVehicle _currentUnit; diff --git a/addons/_switchunits/functions/fn_switchUnit.sqf b/addons/_switchunits/functions/fn_switchUnit.sqf deleted file mode 100644 index ddb2a1d523..0000000000 --- a/addons/_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/stringtable.xml b/addons/_switchunits/stringtable.xml deleted file mode 100644 index b12e8dc17d..0000000000 --- a/addons/_switchunits/stringtable.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - Switched unit - Einheit gewechselt - Юнит переключен - Prohozená jednotka - Przełącz jednostkę - Cambiado de unidad - - - This unit is too close to the enemy. - Diese Einheit ist zu nah am Feind. - Юнит слишком близок к противнику - Tato jednotka je moc blízko k nepříteli. - Ta jednostka jest zbyt blisko przeciwnika. - Esta unidad está demasiado cerca del enemigo. - - -