Cargo & Dragging - Disable UAV AI when being dragged, carried or cargo (#10100)

* Disable UAV AI when being dragged, carried or cargo

* Update addons/common/functions/fnc_disableAiUAV.sqf

* Improve dragging/carrying conditions, fixed duplicate JIP
This commit is contained in:
johnb432 2024-07-22 08:38:39 +02:00 committed by GitHub
parent 05c7f84b01
commit b6e9cabc34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 119 additions and 26 deletions

View File

@ -62,6 +62,17 @@ if (_item isEqualType objNull) then {
// Some objects below water will take damage over time, eventually becoming "water logged" and unfixable (because of negative z attach) // Some objects below water will take damage over time, eventually becoming "water logged" and unfixable (because of negative z attach)
[_item, "blockDamage", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); [_item, "blockDamage", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
// Prevent UAVs from firing
private _UAVCrew = _item call EFUNC(common,getVehicleUAVCrew);
if (_UAVCrew isNotEqualTo []) then {
{
[_x, true] call EFUNC(common,disableAiUAV);
} forEach _UAVCrew;
_item setVariable [QGVAR(isUAV), _UAVCrew, true];
};
}; };
// Invoke listenable event // Invoke listenable event

View File

@ -96,6 +96,18 @@ if (_object isEqualType objNull) then {
[QEGVAR(zeus,addObjects), [[_object], _objectCurators]] call CBA_fnc_serverEvent; [QEGVAR(zeus,addObjects), [[_object], _objectCurators]] call CBA_fnc_serverEvent;
}; };
// Reenable UAV crew
private _UAVCrew = _object getVariable [QGVAR(isUAV), []];
if (_UAVCrew isNotEqualTo []) then {
// Reenable AI
{
[_x, false] call EFUNC(common,disableAiUAV);
} forEach _UAVCrew;
_object setVariable [QGVAR(isUAV), nil, true];
};
} else { } else {
_object = createVehicle [_item, _emptyPosAGL, [], 0, "NONE"]; _object = createVehicle [_item, _emptyPosAGL, [], 0, "NONE"];

View File

@ -43,6 +43,7 @@ PREP(deviceKeyFindValidIndex);
PREP(deviceKeyRegisterNew); PREP(deviceKeyRegisterNew);
PREP(deprecateComponent); PREP(deprecateComponent);
PREP(disableAI); PREP(disableAI);
PREP(disableAiUAV);
PREP(disableUserInput); PREP(disableUserInput);
PREP(displayIcon); PREP(displayIcon);
PREP(displayText); PREP(displayText);

View File

@ -133,6 +133,30 @@
_object lockInventory (_set > 0); _object lockInventory (_set > 0);
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
[QGVAR(disableAiUAV), {
params ["_unit", "_disable"];
if (_disable) then {
private _features = ["AUTOTARGET", "TARGET", "WEAPONAIM"/*, "FIREWEAPON"*/, "RADIOPROTOCOL"]; // TODO: Uncomment in 2.18
// Save current status
_unit setVariable [QGVAR(featuresAiUAV), _features apply {[_x, _unit checkAIFeature _x]}];
{
_unit enableAIFeature [_x, false];
} forEach _features;
} else {
// Restore previous status
private _features = _unit getVariable [QGVAR(featuresAiUAV), []];
{
_unit enableAIFeature [_x select 0, _x select 1];
} forEach _features;
_unit setVariable [QGVAR(featuresAiUAV), nil];
};
}] call CBA_fnc_addEventHandler;
//Add a fix for BIS's zeus remoteControl module not reseting variables on DC when RC a unit //Add a fix for BIS's zeus remoteControl module not reseting variables on DC when RC a unit
//This variable is used for isPlayer checks //This variable is used for isPlayer checks
if (isServer) then { if (isServer) then {

View File

@ -0,0 +1,45 @@
#include "..\script_component.hpp"
/*
* Author: johnb43
* Disables/Enables UAV AI crew members, can be run on any machine and is applied globally.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Disable AI <BOOL>
*
* Return Value:
* None
*
* Example:
* [cursorObject, true] call ace_common_fnc_disableAiUAV
*
* Public: No
*/
params [["_unit", objNull, [objNull]], ["_disable", true, [false]]];
// Allow disabling of Zeus remote controlled units
if (!alive _unit || {isPlayer _unit} || {!unitIsUAV _unit}) exitWith {};
if (_disable) then {
// Ignore if already disabled
if (!isNil "_jipID") exitWith {};
// Disable shooting and targeting on every machine
// Give predefined JIP ID, in case of simultaneous executions on different machines
private _jipID = [QGVAR(disableAiUAV), [_unit, _disable], QGVAR(disableAiUAV_) + hashValue _unit] call CBA_fnc_globalEventJIP;
[_jipID, _unit] call CBA_fnc_removeGlobalEventJIP;
_unit setVariable [QGVAR(disableAiUavJipID), _jipID, true];
} else {
// Restore shooting and targeting to each client's individual state prior to disabling
private _jipID = _unit getVariable QGVAR(disableAiUavJipID);
if (isNil "_jipID") exitWith {};
_jipID call CBA_fnc_removeGlobalEventJIP;
_unit setVariable [QGVAR(disableAiUavJipID), nil, true];
[QGVAR(disableAiUAV), [_unit, _disable]] call CBA_fnc_globalEvent;
};

View File

@ -66,10 +66,10 @@ private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew);
if (_UAVCrew isNotEqualTo []) then { if (_UAVCrew isNotEqualTo []) then {
{ {
_target deleteVehicleCrew _x; [_x, true] call EFUNC(common,disableAiUAV);
} forEach _UAVCrew; } forEach _UAVCrew;
_target setVariable [QGVAR(isUAV), true, true]; _target setVariable [QGVAR(isUAV), _UAVCrew, true];
}; };
// Check everything // Check everything

View File

@ -73,8 +73,8 @@ if (_unit getHitPointDamage "HitLegs" >= 0.5) exitWith {
_idPFH call CBA_fnc_removePerFrameHandler; _idPFH call CBA_fnc_removePerFrameHandler;
}; };
// Drop static if crew is in it (UAV crew deletion may take a few frames) // Drop static if either non-UAV crew or new UAV crew is in it (ignore saved UAV crew)
if (_target isKindOf "StaticWeapon" && {!(_target getVariable [QGVAR(isUAV), false])} && {(crew _target) isNotEqualTo []}) exitWith { if (_target isKindOf "StaticWeapon" && {((crew _target) - (_target getVariable [QGVAR(isUAV), []])) isNotEqualTo []}) exitWith {
TRACE_2("static weapon crewed",_unit,_target); TRACE_2("static weapon crewed",_unit,_target);
[_unit, _target] call FUNC(dropObject_carry); [_unit, _target] call FUNC(dropObject_carry);

View File

@ -79,10 +79,10 @@ private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew);
if (_UAVCrew isNotEqualTo []) then { if (_UAVCrew isNotEqualTo []) then {
{ {
_target deleteVehicleCrew _x; [_x, true] call EFUNC(common,disableAiUAV);
} forEach _UAVCrew; } forEach _UAVCrew;
_target setVariable [QGVAR(isUAV), true, true]; _target setVariable [QGVAR(isUAV), _UAVCrew, true];
}; };
// Check everything // Check everything

View File

@ -51,8 +51,8 @@ if (_unit distance _target > 10 && {(CBA_missionTime - _startTime) >= 1}) exitWi
_idPFH call CBA_fnc_removePerFrameHandler; _idPFH call CBA_fnc_removePerFrameHandler;
}; };
// Drop static if crew is in it (UAV crew deletion may take a few frames) // Drop static if either non-UAV crew or new UAV crew is in it (ignore saved UAV crew)
if (_target isKindOf "StaticWeapon" && {!(_target getVariable [QGVAR(isUAV), false])} && {(crew _target) isNotEqualTo []}) exitWith { if (_target isKindOf "StaticWeapon" && {((crew _target) - (_target getVariable [QGVAR(isUAV), []])) isNotEqualTo []}) exitWith {
TRACE_2("static weapon crewed",_unit,_target); TRACE_2("static weapon crewed",_unit,_target);
[_unit, _target] call FUNC(dropObject); [_unit, _target] call FUNC(dropObject);

View File

@ -80,16 +80,16 @@ if (_unit getVariable ["ACE_isUnconscious", false]) then {
[_unit, "unconscious", 2] call EFUNC(common,doAnimation); [_unit, "unconscious", 2] call EFUNC(common,doAnimation);
}; };
// Recreate UAV crew (add a frame delay or this may cause the vehicle to be moved to [0,0,0]) // Reenable UAV crew
if (_target getVariable [QGVAR(isUAV), false]) then { private _UAVCrew = _target getVariable [QGVAR(isUAV), []];
_target setVariable [QGVAR(isUAV), nil, true];
[{ if (_UAVCrew isNotEqualTo []) then {
params ["_target"]; // Reenable AI
if (!alive _target) exitWith {}; {
TRACE_2("restoring uav crew",_target,getPosASL _target); [_x, false] call EFUNC(common,disableAiUAV);
createVehicleCrew _target; } forEach _UAVCrew;
}, [_target]] call CBA_fnc_execNextFrame;
_target setVariable [QGVAR(isUAV), nil, true];
}; };
// Fixes not being able to move when in combat pace // Fixes not being able to move when in combat pace

View File

@ -87,16 +87,16 @@ if !(_target isKindOf "CAManBase") then {
[QEGVAR(common,fixFloating), _target, _target] call CBA_fnc_targetEvent; [QEGVAR(common,fixFloating), _target, _target] call CBA_fnc_targetEvent;
}; };
// Recreate UAV crew (add a frame delay or this may cause the vehicle to be moved to [0,0,0]) // Reenable UAV crew
if (_target getVariable [QGVAR(isUAV), false]) then { private _UAVCrew = _target getVariable [QGVAR(isUAV), []];
_target setVariable [QGVAR(isUAV), nil, true];
[{ if (_UAVCrew isNotEqualTo []) then {
params ["_target"]; // Reenable AI
if (!alive _target) exitWith {}; {
TRACE_2("restoring uav crew",_target,getPosASL _target); [_x, false] call EFUNC(common,disableAiUAV);
createVehicleCrew _target; } forEach _UAVCrew;
}, [_target]] call CBA_fnc_execNextFrame;
_target setVariable [QGVAR(isUAV), nil, true];
}; };
// Reset mass // Reset mass