|
| 1 | +#include "..\script_component.hpp" |
| 2 | +/* |
| 3 | + * Author: Dystopian |
| 4 | + * Adds Get In actions for vehicle seats and Passenger Actions for vehicle crew. |
| 5 | + * |
| 6 | + * Arguments: |
| 7 | + * 0: Vehicle <OBJECT> |
| 8 | + * |
| 9 | + * Return Value: |
| 10 | + * None |
| 11 | + * |
| 12 | + * Example: |
| 13 | + * cursorObject call ace_quickmount_fnc_addGetInActions |
| 14 | + * |
| 15 | + * Public: No |
| 16 | + */ |
| 17 | + |
| 18 | +#define ACTION_DISTANCE 4 |
| 19 | +#define CREW_HEIGHT_ABOVE_SEAT 0.3 |
| 20 | + |
| 21 | +params ["_vehicle"]; |
| 22 | + |
| 23 | +private _vehicleClass = typeOf _vehicle; |
| 24 | +private _vehicleConfig = configOf _vehicle; |
| 25 | +private _cargoProxyIndexes = getArray (_vehicleConfig >> "cargoProxyIndexes"); |
| 26 | +private _seatProxies = _vehicle call FUNC(getSeatProxies); |
| 27 | + |
| 28 | +private _seatPositions = GETVAR(_vehicle,GVAR(seatPositions),[]); |
| 29 | +if (_seatPositions isEqualType []) then { |
| 30 | + _seatPositions = createHashMapFromArray _seatPositions; |
| 31 | +}; |
| 32 | +private _seatPositionsConfig = getArray (_vehicleConfig >> QGVAR(seatPositions)); |
| 33 | +_seatPositionsConfig params [["_model", ""], ["_seatPositionsArray", []]]; |
| 34 | +// handle inherited classes with different model |
| 35 | +if (_model == getText (_vehicleConfig >> "model")) then { |
| 36 | + _seatPositions merge createHashMapFromArray _seatPositionsArray; |
| 37 | +}; |
| 38 | + |
| 39 | +TRACE_4("addGetInActions",_vehicleClass,_cargoProxyIndexes,_seatPositions,_seatProxies); |
| 40 | + |
| 41 | +private _conditionCrew = { |
| 42 | + call FUNC(canShowFreeSeats) |
| 43 | + && {!isNull ([_target, _actionParams select 0] call FUNC(getSeatUnit))} |
| 44 | +}; |
| 45 | +private _insertChildrenCrew = { |
| 46 | + private _unit = [_target, _actionParams select 0] call FUNC(getSeatUnit); |
| 47 | + [nil, nil, _unit] call EFUNC(interaction,addPassengerActions) |
| 48 | +}; |
| 49 | +private _modifierFunctionCrew = { |
| 50 | + params ["_target", "", "_params", "_actionData"]; |
| 51 | + _params params ["_seat"]; |
| 52 | + private _unit = [_target, _seat] call FUNC(getSeatUnit); |
| 53 | + if (isNull _unit) exitWith {}; // skip empty seats |
| 54 | + _actionData set [1, [_unit, true] call EFUNC(common,getName)]; |
| 55 | + if (["ace_medical_gui"] call EFUNC(common,isModLoaded)) then { |
| 56 | + _this set [0, _unit]; // == _target |
| 57 | + call EFUNC(medical_gui,modifyActionTriageLevel); |
| 58 | + }; |
| 59 | +}; |
| 60 | + |
| 61 | +private _allSeats = fullCrew [_vehicle, "", true]; |
| 62 | +private _cargoPositionNumber = -1; |
| 63 | + |
| 64 | +{ |
| 65 | + _x params ["", "_role", "_cargoIndex", "_turretPath", "_isPersonTurret", "", "_positionName"]; |
| 66 | + private _name = if (isLocalized _positionName) then {localize _positionName} else {_positionName}; |
| 67 | + |
| 68 | + private ["_proxyGroup", "_proxyIndex", "_icon", "_condition", "_statement", "_params", "_position", "_positionCrew"]; |
| 69 | + switch (_role) do { |
| 70 | + case "driver": { |
| 71 | + if ( |
| 72 | + unitIsUAV _vehicle |
| 73 | + || {getNumber (_vehicleConfig >> "hasDriver") == 0} |
| 74 | + ) then {continue}; |
| 75 | + _proxyGroup = "driver"; |
| 76 | + _proxyIndex = 1; |
| 77 | + _params = [_turretPath]; |
| 78 | + _condition = { |
| 79 | + call FUNC(canShowFreeSeats) |
| 80 | + && {!lockedDriver _target} |
| 81 | + && {!alive driver _target} |
| 82 | + }; |
| 83 | + _statement = {_player action ["GetInDriver", _target]}; |
| 84 | + _icon = [ICON_DRIVER, ICON_PILOT] select (_vehicle isKindOf "Air"); |
| 85 | + }; |
| 86 | + case "cargo": { |
| 87 | + INC(_cargoPositionNumber); |
| 88 | + _proxyGroup = "cargo"; |
| 89 | + _proxyIndex = _cargoProxyIndexes param [_cargoPositionNumber, _cargoPositionNumber + 1]; |
| 90 | + _params = [_cargoIndex, _cargoPositionNumber]; |
| 91 | + _condition = { |
| 92 | + call FUNC(canShowFreeSeats) |
| 93 | + && { |
| 94 | + private _cargoIndex = _actionParams select 0; |
| 95 | + !(_target lockedCargo _cargoIndex) |
| 96 | + && {!alive ([_target, _cargoIndex] call FUNC(getSeatUnit))} |
| 97 | + } |
| 98 | + }; |
| 99 | + _statement = {_player action ["GetInCargo", _target, _actionParams select 1]}; |
| 100 | + _name = format ["%1 %2", _name, _cargoPositionNumber + 1]; |
| 101 | + _icon = ICON_CARGO; |
| 102 | + }; |
| 103 | + default { |
| 104 | + if (_role == "gunner" && {unitIsUAV _vehicle}) then {continue}; |
| 105 | + private _turretConfig = [_vehicleConfig, _turretPath] call CBA_fnc_getTurret; |
| 106 | + private _proxyType = getText (_turretConfig >> "proxyType"); |
| 107 | + _proxyGroup = switch (_proxyType) do { |
| 108 | + case "CPCommander": {"commander"}; |
| 109 | + case "CPGunner": {"gunner"}; |
| 110 | + default {"cargo"}; |
| 111 | + }; |
| 112 | + _proxyIndex = getNumber (_turretConfig >> "proxyIndex"); |
| 113 | + _params = [_turretPath]; |
| 114 | + _condition = { |
| 115 | + call FUNC(canShowFreeSeats) |
| 116 | + && { |
| 117 | + private _turretPath = _actionParams select 0; |
| 118 | + !(_target lockedTurret _turretPath) |
| 119 | + && {!alive ([_target, _turretPath] call FUNC(getSeatUnit))} |
| 120 | + } |
| 121 | + }; |
| 122 | + _statement = {_player action ["GetInTurret", _target, _actionParams select 0]}; |
| 123 | + _icon = switch true do { |
| 124 | + case (getNumber (_turretConfig >> "isCopilot") > 0): {ICON_PILOT}; |
| 125 | + case (_role == "gunner"): {ICON_GUNNER}; |
| 126 | + case (_role == "commander"): {ICON_COMMANDER}; |
| 127 | + case (_isPersonTurret): {ICON_FFV}; |
| 128 | + case (getText (_turretConfig >> "gun") == ""): {ICON_CARGO}; |
| 129 | + default {ICON_TURRET}; |
| 130 | + }; |
| 131 | + }; |
| 132 | + }; |
| 133 | + |
| 134 | + private _positionString = _seatPositions getOrDefault [_params select 0, ""]; |
| 135 | + if (_positionString != "") then { |
| 136 | + _position = compile _positionString; |
| 137 | + _positionCrew = compile format ["(%1) vectorAdd [0, 0, %2]", _positionString, CREW_HEIGHT_ABOVE_SEAT]; |
| 138 | + TRACE_6("seat position",_role,_cargoIndex,_turretPath,_proxyGroup,_proxyIndex,_position); |
| 139 | + } else { |
| 140 | + private _seatProxy = _seatProxies getOrDefault [_proxyGroup, createHashMap] getOrDefault [_proxyIndex, []]; |
| 141 | + TRACE_6("seat proxy",_role,_cargoIndex,_turretPath,_proxyGroup,_proxyIndex,_seatProxy); |
| 142 | + if (_seatProxy isEqualTo []) then {continue}; |
| 143 | + // cannot use static position because some proxy positions move with turret rotation |
| 144 | + _position = compile format ["_target selectionPosition ['%1', %2, 'AveragePoint']", _seatProxy select 0, _seatProxy select 1]; |
| 145 | + _positionCrew = compile format [ |
| 146 | + "_target selectionPosition ['%1', %2, 'AveragePoint'] vectorAdd [0, 0, %3]", |
| 147 | + _seatProxy select 0, |
| 148 | + _seatProxy select 1, |
| 149 | + CREW_HEIGHT_ABOVE_SEAT |
| 150 | + ]; |
| 151 | + }; |
| 152 | + |
| 153 | + private _action = [ |
| 154 | + format ["%1%2%3empty", _role, _cargoIndex, _turretPath], |
| 155 | + _name, _icon, _statement, _condition, {}, _params, _position, ACTION_DISTANCE |
| 156 | + ] call EFUNC(interact_menu,createAction); |
| 157 | + [_vehicleClass, 0, [], _action] call EFUNC(interact_menu,addActionToClass); |
| 158 | + |
| 159 | + // modifier function needs icon color |
| 160 | + private _actionCrew = [ |
| 161 | + format ["%1%2%3crew", _role, _cargoIndex, _turretPath], |
| 162 | + "", [_icon, "#FFFFFF"], {}, _conditionCrew, _insertChildrenCrew, |
| 163 | + _params, _positionCrew, ACTION_DISTANCE, nil, _modifierFunctionCrew |
| 164 | + ] call EFUNC(interact_menu,createAction); |
| 165 | + [_vehicleClass, 0, [], _actionCrew] call EFUNC(interact_menu,addActionToClass); |
| 166 | +} forEach _allSeats; |
0 commit comments