finish cba'ing

This commit is contained in:
bux578 2015-01-12 15:47:22 +01:00
parent 7afce2a241
commit 5da1bdf9c0
12 changed files with 143 additions and 46 deletions

View File

@ -1,6 +1,6 @@
class Extended_PreInit_EventHandlers { class Extended_PreInit_EventHandlers {
class ADDON { class ADDON {
init = QUOTE( call compile preprocessFileLineNumbers PATHTOF(XEH_preInit.sqf) ); init = QUOTE( call COMPILE_FILE(XEH_preInit) );
}; };
}; };

View File

@ -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;
};
};
};
};

View File

@ -15,3 +15,17 @@ class CfgPatches {
}; };
#include "CfgEventHandlers.hpp" #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;
};

View File

@ -15,9 +15,11 @@
VOID VOID
*/ */
#include "script_component.hpp"
private ["_unit"]; private ["_unit"];
_unit = _this select 0; _unit = _this select 0;
["theMapClick", "onMapSingleClick", { ["theMapClick", "onMapSingleClick", {
[_this, _pos, _shift, _alt] call AGM_SwitchUnits_fnc_handleMapClick; [_this, _pos, _shift, _alt] call FUNC(handleMapClick);
}, [_unit, _sides]] call BIS_fnc_addStackedEventHandler; }, [_unit, _sides]] call BIS_fnc_addStackedEventHandler;

View File

@ -16,6 +16,8 @@
VOID VOID
*/ */
#include "script_component.hpp"
private ["_args", "_currentPlayerUnit", "_sides", "_pos", "_sideNearest"]; private ["_args", "_currentPlayerUnit", "_sides", "_pos", "_sideNearest"];
_currentPlayerUnit = (_this select 0) select 0; _currentPlayerUnit = (_this select 0) select 0;
@ -25,7 +27,7 @@ _pos = _this select 1;
_sideNearest = []; _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; _sideNearest pushBack _x;
}; };
} forEach (nearestObjects [_pos, ["Man"], 20]); } forEach (nearestObjects [_pos, ["Man"], 20]);
@ -35,7 +37,7 @@ if (count _sideNearest > 0) then {
private ["_switchUnit"]; private ["_switchUnit"];
_switchUnit = _sideNearest select 0; _switchUnit = _sideNearest select 0;
[_currentPlayerUnit, _switchUnit] call AGM_SwitchUnits_fnc_switchUnit; [_currentPlayerUnit, _switchUnit] call FUNC(switchUnit);
openMap false; openMap false;
}; };

View File

@ -15,6 +15,8 @@
VOID VOID
*/ */
#include "script_component.hpp"
private ["_playerUnit", "_sides"]; private ["_playerUnit", "_sides"];
_playerUnit = _this select 0; _playerUnit = _this select 0;
@ -22,14 +24,14 @@ _sides = _this select 1;
if (vehicle _playerUnit == _playerUnit) then { 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; _playerUnit allowDamage false;
AGM_SwitchUnits_OriginalUnit = _playerUnit; GVAR(OriginalUnit) = _playerUnit;
AGM_SwitchUnits_OriginalName = [_playerUnit] call AGM_Core_fnc_getName; GVAR(OriginalName) = [_playerUnit] call EFUNC(Core, getName);
AGM_SwitchUnits_OriginalGroup = group _playerUnit; GVAR(OriginalGroup) = group _playerUnit;
// remove all starting gear of a player // remove all starting gear of a player
removeAllWeapons _playerUnit; removeAllWeapons _playerUnit;
@ -42,7 +44,7 @@ if (vehicle _playerUnit == _playerUnit) then {
_playerUnit linkItem "ItemMap"; _playerUnit linkItem "ItemMap";
removeUniform _playerUnit; 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);
}; };

View File

@ -14,12 +14,14 @@
VOID VOID
*/ */
#include "script_component.hpp"
private ["_unit"]; private ["_unit"];
_unit = _this select 0; _unit = _this select 0;
!([_unit] call AGM_Core_fnc_isPlayer !([_unit] call EFUNC(Core, isPlayer)
|| {_unit in playableUnits} || {_unit in playableUnits}
|| {vehicle _unit != _unit} || {vehicle _unit != _unit}
|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerUnit", false]} || {_unit getVariable [QGVAR(IsPlayerUnit), false]}
|| {_unit getVariable ["AGM_SwitchUnits_IsPlayerControlled", false]}) || {_unit getVariable [QGVAR(IsPlayerControlled), false]})

View File

@ -15,6 +15,8 @@
VOID VOID
*/ */
#include "script_component.hpp"
private ["_sidesToShow"]; private ["_sidesToShow"];
_sidesToShow = _this select 0; _sidesToShow = _this select 0;
@ -34,10 +36,10 @@ _sidesToShow spawn {
// create markers // 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"]; private ["_markerName", "_marker", "_markerColor"];
//_markerName = format ["%1", [_x] call AGM_Core_fnc_getName]; //_markerName = format ["%1", [_x] call EFUNC(Core, getName)];
_markerName = str _x; _markerName = str _x;
_marker = createMarkerLocal [_markerName, position _x]; _marker = createMarkerLocal [_markerName, position _x];
@ -49,9 +51,9 @@ _sidesToShow spawn {
// commy's one liner magic // commy's one liner magic
_markerColor = format ["Color%1", side group _x]; _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 setMarkerColorLocal "ColorOrange";
_markerName setMarkerTextLocal (_x getVariable ["AGM_SwitchUnits_PlayerControlledName",""]); _markerName setMarkerTextLocal (_x getVariable [QGVAR(PlayerControlledName),""]);
} else { } else {
_markerName setMarkerColorLocal _markerColor; _markerName setMarkerColorLocal _markerColor;
_markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName")); _markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName"));

View File

@ -16,6 +16,8 @@
BOOLEAN (Good practice to include one) BOOLEAN (Good practice to include one)
*/ */
#include "script_component.hpp"
if !(isServer) exitWith {}; if !(isServer) exitWith {};
_logic = _this select 0; _logic = _this select 0;
@ -23,16 +25,16 @@ _activated = _this select 2;
if !(_activated) exitWith {}; 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, QGVAR(SwitchToWest), "SwitchToWest"] call EFUNC(Core, readBooleanParameterFromModule);
[_logic, "AGM_SwitchUnits_SwitchToEast", "SwitchToEast"] call AGM_Core_fnc_readBooleanParameterFromModule; [_logic, QGVAR(SwitchToEast), "SwitchToEast"] call EFUNC(Core, readBooleanParameterFromModule);
[_logic, "AGM_SwitchUnits_SwitchToIndependent", "SwitchToIndependent"] call AGM_Core_fnc_readBooleanParameterFromModule; [_logic, QGVAR(SwitchToIndependent), "SwitchToIndependent"] call EFUNC(Core, readBooleanParameterFromModule);
[_logic, "AGM_SwitchUnits_SwitchToCivilian", "SwitchToCivilian"] call AGM_Core_fnc_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; diag_log text "[ACE]: SwitchUnits Module Initialized.";
[_logic, "AGM_SwitchUnits_SafeZoneRadius", "SafeZoneRadius"] call AGM_Core_fnc_readNumericParameterFromModule;
diag_log text "[AGM]: SwitchUnits Module Initialized.";

View File

@ -15,6 +15,8 @@
ARRAY<OBJECT> - Player units ARRAY<OBJECT> - Player units
*/ */
#include "script_component.hpp"
private ["_position", "_radius", "_nearestPlayers"]; private ["_position", "_radius", "_nearestPlayers"];
_position = _this select 0; _position = _this select 0;
@ -23,7 +25,7 @@ _radius = _this select 1;
_nearestPlayers = []; _nearestPlayers = [];
{ {
if ([_x] call AGM_Core_fnc_isPlayer && {alive _x}) then { if ([_x] call EFUNC(Core, isPlayer) && {alive _x}) then {
_nearestPlayers pushBack _x; _nearestPlayers pushBack _x;
}; };
} forEach (nearestObjects [_position, ["Man"], _radius]); } forEach (nearestObjects [_position, ["Man"], _radius]);

View File

@ -16,11 +16,13 @@
VOID VOID
*/ */
#include "script_component.hpp"
private ["_originalPlayerUnit", "_currentUnit"]; private ["_originalPlayerUnit", "_currentUnit"];
_originalPlayerUnit = _this select 0; _originalPlayerUnit = _this select 0;
_currentUnit = _this select 1; _currentUnit = _this select 1;
[_originalPlayerUnit] joinSilent AGM_SwitchUnits_OriginalGroup; [_originalPlayerUnit] joinSilent GVAR(OriginalGroup);
waitUntil {local _originalPlayerUnit}; waitUntil {local _originalPlayerUnit};

View File

@ -14,12 +14,14 @@
VOID VOID
*/ */
#include "script_component.hpp"
private ["_newUnit"]; private ["_newUnit"];
_newUnit = _this select 1; _newUnit = _this select 1;
// don't switch to original player units // don't switch to original player units
if (!([_newUnit] call AGM_SwitchUnits_fnc_isValidAi)) exitWith {}; if (!([_newUnit] call FUNC(isValidAi))) exitWith {};
_newUnit spawn { _newUnit spawn {
private ["_unit", "_allNearestPlayers", "_oldUnit", "_respawnEhId", "_oldOwner", "_leave"]; private ["_unit", "_allNearestPlayers", "_oldUnit", "_respawnEhId", "_oldOwner", "_leave"];
@ -28,10 +30,10 @@ _newUnit spawn {
_leave = false; _leave = false;
if (AGM_SwitchUnits_EnableSafeZone) then { if (GVAR(EnableSafeZone)) then {
_allNearestPlayers = [position _unit, AGM_SwitchUnits_SafeZoneRadius] call AGM_SwitchUnits_fnc_nearestPlayers; _allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers);
_nearestEnemyPlayers = [_allNearestPlayers, {((side AGM_SwitchUnits_OriginalGroup) getFriend (side _this) < 0.6) && !(_this getVariable ["AGM_SwitchUnits_IsPlayerControlled", false])}] call AGM_Core_fnc_filter; _nearestEnemyPlayers = [_allNearestPlayers, {((side GVAR(OriginalGroup)) getFriend (side _this) < 0.6) && !(_this getVariable [QGVAR(IsPlayerControlled), false])}] call EFUNC(Core, filter);
if (count _nearestEnemyPlayers > 0) exitWith { if (count _nearestEnemyPlayers > 0) exitWith {
_leave = true; _leave = true;
@ -40,40 +42,40 @@ _newUnit spawn {
// exitWith doesn't exit past the "if(EnableSafeZone)" block // exitWith doesn't exit past the "if(EnableSafeZone)" block
if (_leave) exitWith { 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 // should switch locality
// This doesn't work anymore, because one's now able to switch to units from a different side // This doesn't work anymore, because one's now able to switch to units from a different side
//[_unit] joinSilent group player; //[_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; _oldUnit = player;
waitUntil {sleep 0.2; local _unit}; waitUntil {sleep 0.2; local _unit};
_oldUnit setVariable ["AGM_SwitchUnits_IsPlayerControlled", false, true]; _oldUnit setVariable [QGVAR(IsPlayerControlled), false, true];
_oldUnit setVariable ["AGM_SwitchUnits_PlayerControlledName", "", true]; _oldUnit setVariable [QGVAR(PlayerControlledName), "", true];
_respawnEhId = _unit getVariable ["AGM_SwitchUnits_RespawnEhId", -1]; _respawnEhId = _unit getVariable [QGVAR(RespawnEhId), -1];
if (_respawnEhId != -1) then { if (_respawnEhId != -1) then {
_oldUnit removeEventHandler ["Respawn", _respawnEhId]; _oldUnit removeEventHandler ["Respawn", _respawnEhId];
}; };
selectPlayer _unit; selectPlayer _unit;
_unit setVariable ["AGM_SwitchUnits_IsPlayerControlled", true, true]; _unit setVariable [QGVAR(IsPlayerControlled), true, true];
_unit setVariable ["AGM_SwitchUnits_PlayerControlledName", AGM_SwitchUnits_OriginalName, true]; _unit setVariable [QGVAR(PlayerControlledName), GVAR(OriginalName), true];
_respawnEhId = _unit addEventHandler ["Respawn", { _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 // set owner back to original owner
_oldOwner = _oldUnit getVariable["AGM_SwitchUnits_OriginalOwner", -1]; _oldOwner = _oldUnit getVariable[QGVAR(OriginalOwner), -1];
if (_oldOwner > -1) then { 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);
}; };