Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction - Add crew status check for some vehicle interactions #9637

Merged
merged 3 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion addons/cargo/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ GVAR(vehicleAction) = [
{locked _target < 2} &&
{([_player, _target] call EFUNC(interaction,getInteractionDistance)) < MAX_LOAD_DISTANCE} &&
{alive _target} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)}
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{[_player, _target] call EFUNC(interaction,canInteractWithVehicleCrew)}
}
] call EFUNC(interact_menu,createAction);

Expand All @@ -99,6 +100,7 @@ GVAR(objectActions) = [
{(_target getVariable [QGVAR(canLoad), getNumber (configOf _target >> QGVAR(canLoad))]) in [true, 1]} &&
{alive _target} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{[_player, _target] call EFUNC(interaction,canInteractWithVehicleCrew)} &&
{(_target getVariable [QGVAR(noRename), getNumber (configOf _target >> QGVAR(noRename))]) in [false, 0]}
}
] call EFUNC(interact_menu,createAction),
Expand All @@ -114,6 +116,7 @@ GVAR(objectActions) = [
{locked _target < 2} &&
{alive _target} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{[_player, _target] call EFUNC(interaction,canInteractWithVehicleCrew)} &&
{((nearestObjects [_target, GVAR(cargoHolderTypes), (MAX_LOAD_DISTANCE + 10)]) findIf {
private _hasCargoConfig = 1 == getNumber (configOf _x >> QGVAR(hasCargo));
private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false];
Expand Down
1 change: 1 addition & 0 deletions addons/interaction/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ PREP(hideMouseHint);

// interaction with units
PREP(canInteractWithCivilian);
PREP(canInteractWithVehicleCrew);
PREP(getDown);
PREP(sendAway);
PREP(canJoinGroup);
Expand Down
89 changes: 46 additions & 43 deletions addons/interaction/functions/fnc_addPassengersActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,68 @@
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Player <OBJECT>
* 3: Parameters <ARRAY>
* 2: Parameters <ARRAY>
*
* Return Value:
* Children actions <ARRAY>
*
* Example:
* [target, player, [params]] call ace_interaction_fnc_addPassengersActions
* [cursorObject, player, [params]] call ace_interaction_fnc_addPassengersActions
*
* Public: No
*/

params ["_vehicle", "_player"];

// If player is not in vehicle and the crew is hostile, do not show any actions
if !(_player in _vehicle || {[_player, _vehicle] call FUNC(canInteractWithVehicleCrew)}) exitWith {
[] // return
};

private _actions = [];
private _icon = "";

{
private _unit = _x;

if (_unit != _player && {getText (configOf _unit >> "simulation") != "UAVPilot"}) then {
private _icon = [
"",
"A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_driver_ca.paa",
"A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_gunner_ca.paa",
"A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_commander_ca.paa"
] select (([driver _vehicle, gunner _vehicle, commander _vehicle] find _unit) + 1);
_x params ["_unit", "_role"];

if (_unit getVariable [QEGVAR(captives,isHandcuffed), false]) then {
_icon = QPATHTOEF(captives,UI\handcuff_ca.paa);
};
_icon = [
"A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_driver_ca.paa",
"A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_gunner_ca.paa",
"A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_commander_ca.paa",
""
] select (["driver", "gunner", "commander"] find _role);

_actions pushBack [
[
format ["%1", _unit],
[_unit, true] call EFUNC(common,getName),
[_icon, "#FFFFFF"],
{
//statement (Run on hover) - reset the cache so we will insert actions immedietly when hovering over new unit
TRACE_2("Cleaning Cache",_target,vehicle _target);
[vehicle _target, QEGVAR(interact_menu,ATCache_ACE_SelfActions)] call EFUNC(common,eraseCache);
},
{true},
{
if (EGVAR(interact_menu,selectedTarget) isEqualTo _target) then {
_this call FUNC(addPassengerActions)
} else {
[] //not selected, don't waste time on actions
};
},
[_unit],
{[0, 0, 0]},
2,
[false,false,false,true,false], //add run on hover (4th bit true)
{if (["ace_medical_gui"] call EFUNC(common,isModLoaded)) then {call EFUNC(medical_gui,modifyActionTriageLevel)}}
] call EFUNC(interact_menu,createAction),
[],
_unit
];
if (_unit getVariable [QEGVAR(captives,isHandcuffed), false]) then {
_icon = QPATHTOEF(captives,UI\handcuff_ca.paa);
};
false
} count crew _vehicle;

_actions pushBack [
[
format ["%1", _unit],
[_unit, true] call EFUNC(common,getName),
[_icon, "#FFFFFF"],
{
// statement (Run on hover) - reset the cache so we will insert actions immediately when hovering over new unit
TRACE_2("Cleaning Cache",_target,objectParent _target);
[objectParent _target, QEGVAR(interact_menu,ATCache_ACE_SelfActions)] call EFUNC(common,eraseCache);
},
{true},
{
if (EGVAR(interact_menu,selectedTarget) isEqualTo _target) then {
_this call FUNC(addPassengerActions)
} else {
[] // not selected, don't waste time on actions
};
},
[_unit],
{[0, 0, 0]},
2,
[false, false, false, true, false], // add run on hover (4th bit true)
{if (["ace_medical_gui"] call EFUNC(common,isModLoaded)) then {call EFUNC(medical_gui,modifyActionTriageLevel)}}
] call EFUNC(interact_menu,createAction),
[],
_unit
];
} forEach ((fullCrew _vehicle) select {_x select 0 != _player && {!unitIsUAV (_x select 0)}});

_actions
26 changes: 26 additions & 0 deletions addons/interaction/functions/fnc_canInteractWithVehicleCrew.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "..\script_component.hpp"
/*
* Author: johnb43
* Checks if a unit can interact with the vehicle crew inside.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Vehicle <OBJECT>
*
* Return Value:
* Unit can interact with vehicle crew <BOOL>
*
* Example:
* [cursorObject, player] call ace_interaction_fnc_canInteractWithVehicleCrew
*
* Public: No
*/

params ["_player", "_vehicle"];

johnb432 marked this conversation as resolved.
Show resolved Hide resolved
private _sidePlayer = side _player;
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

((crew _vehicle) select {_x != _player && {!unitIsUAV _x}}) findIf { // ignore player and UAV units
// Units must all be unconscious, captive or friendly (side group is used in case unit is captive/unconscious) for actions to show up
!captive _x && {lifeState _x in ["HEALTHY", "INJURED"]} && {[_sidePlayer, side group _x] call BIS_fnc_sideIsEnemy}
Copy link
Contributor

@LinkIsGrim LinkIsGrim Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly related but we should update common FUNC(isAwake) to do this lifeState check instead, methinks. These are getting bad for readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking, I think we should change _unit getVariable ["ACE_isUnconscious", false] to lifeState (or EFUNC(common,isAwake), if we update it as per your suggestion) wherever possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

} == -1
2 changes: 1 addition & 1 deletion addons/quickmount/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
requiredAddons[] = {"ace_interaction"};
author = ECSTRING(common,ACETeam);
authors[] = {"Kingsley"};
url = ECSTRING(main,URL);
Expand Down
3 changes: 1 addition & 2 deletions addons/quickmount/functions/fnc_canShowFreeSeats.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ GVAR(enabled)
&& {isNull getConnectedUAVUnit _unit}
&& {simulationEnabled _vehicle}
&& {
-1 == crew _vehicle findIf {alive _x}
|| {0.6 <= side group _unit getFriend side group _vehicle}
[_unit, _vehicle] call EFUNC(interaction,canInteractWithVehicleCrew)
}
&& {
0.3 < vectorUp _vehicle select 2 // moveIn* and GetIn* don't work for flipped vehicles
Expand Down