2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2017-06-02 21:51:07 +00:00
|
|
|
/*
|
|
|
|
* Author: Kingsley
|
2024-07-20 06:15:15 +00:00
|
|
|
* Mounts the player in the vehicle they are directly looking at based on their distance.
|
2017-06-02 21:51:07 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2024-07-20 06:15:15 +00:00
|
|
|
* 0: Target <OBJECT> (default: objNull)
|
2017-06-02 21:51:07 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2024-07-20 06:15:15 +00:00
|
|
|
* call ace_quickmount_fnc_getInNearest
|
2017-06-02 21:51:07 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
if (
|
|
|
|
!GVAR(enabled) ||
|
2017-06-02 21:51:07 +00:00
|
|
|
{isNull ACE_player} ||
|
2024-07-20 06:15:15 +00:00
|
|
|
{!isNull objectParent ACE_player} ||
|
|
|
|
{!(ACE_player call EFUNC(common,isAwake))}
|
2017-06-02 21:51:07 +00:00
|
|
|
) exitWith {};
|
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
params [["_target", objNull, [objNull]]];
|
|
|
|
TRACE_1("getInNearest",_target);
|
2019-07-05 20:22:07 +00:00
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
// If target is not defined (e.g. keybind was used), search for valid target
|
|
|
|
if (isNull _target) then {
|
|
|
|
private _start = ACE_player modelToWorldVisualWorld (ACE_player selectionPosition "pilot");
|
|
|
|
private _end = (_start vectorAdd (getCameraViewDirection ACE_player vectorMultiply GVAR(distance)));
|
|
|
|
private _objects = lineIntersectsSurfaces [_start, _end, ACE_player];
|
2019-07-05 20:22:07 +00:00
|
|
|
_target = (_objects param [0, []]) param [2, objNull];
|
|
|
|
};
|
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
if (!alive _target) exitWith {};
|
|
|
|
|
|
|
|
if (locked _target >= 2 || {!simulationEnabled _target}) exitWith {
|
|
|
|
[LLSTRING(VehicleLocked)] call EFUNC(common,displayTextStructured);
|
2017-06-02 21:51:07 +00:00
|
|
|
};
|
|
|
|
|
2019-07-05 20:22:07 +00:00
|
|
|
TRACE_2("",_target,typeOf _target);
|
2017-06-02 21:51:07 +00:00
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
if (
|
|
|
|
(speed _target > GVAR(speed)) ||
|
|
|
|
{["Air", "LandVehicle", "Ship", "StaticMortar"] findIf {_target isKindOf _x} == -1} ||
|
|
|
|
{!([ACE_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith))}
|
|
|
|
) exitWith {};
|
2017-06-02 21:51:07 +00:00
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
private _seats = ["driver", "gunner", "commander", "cargo"];
|
|
|
|
private _sortedSeats = [_seats select GVAR(priority)];
|
|
|
|
_seats deleteAt GVAR(priority);
|
|
|
|
_sortedSeats append _seats;
|
2017-06-02 21:51:07 +00:00
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
private _fullCrew = fullCrew [_target, "", true];
|
2017-06-02 21:51:07 +00:00
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
private _hasAction = false;
|
|
|
|
scopeName "SearchForSeat";
|
2017-06-02 21:51:07 +00:00
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
{
|
|
|
|
private _desiredRole = _x;
|
2017-06-02 21:51:07 +00:00
|
|
|
|
|
|
|
{
|
2024-07-20 06:15:15 +00:00
|
|
|
_x params ["_unit", "_role", "_cargoIndex", "_turretPath"];
|
|
|
|
|
|
|
|
if (!alive _unit) then {
|
|
|
|
private _effectiveRole = _role;
|
|
|
|
|
|
|
|
if ((_effectiveRole in ["driver", "gunner"]) && {unitIsUAV _target}) exitWith {}; // Ignoring UAV Driver/Gunner
|
|
|
|
if ((_effectiveRole == "driver") && {(getNumber (configOf _target >> "hasDriver")) == 0}) exitWith {}; // Ignoring Non Driver (static weapons)
|
|
|
|
|
|
|
|
// Seats can be locked independently of the main vehicle
|
|
|
|
if ((_effectiveRole == "driver") && {lockedDriver _target}) exitWith {TRACE_1("lockedDriver",_x);};
|
|
|
|
if ((_cargoIndex >= 0) && {_target lockedCargo _cargoIndex}) exitWith {TRACE_1("lockedCargo",_x);};
|
|
|
|
if ((_turretPath isNotEqualTo []) && {_target lockedTurret _turretPath}) exitWith {TRACE_1("lockedTurret",_x);};
|
|
|
|
|
|
|
|
if (_effectiveRole == "turret") then {
|
|
|
|
private _turretConfig = [_target, _turretPath] call CBA_fnc_getTurret;
|
|
|
|
|
|
|
|
if (getNumber (_turretConfig >> "isCopilot") == 1) exitWith {
|
|
|
|
_effectiveRole = "driver";
|
2017-06-02 21:51:07 +00:00
|
|
|
};
|
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
if (
|
|
|
|
_cargoIndex >= 0 || // FFV
|
|
|
|
{getText (_turretConfig >> "gun") == ""} // Turret without weapon
|
|
|
|
) exitWith {
|
|
|
|
_effectiveRole = "cargo";
|
2017-06-02 21:51:07 +00:00
|
|
|
};
|
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
_effectiveRole = "gunner"; // Door gunners / 2nd turret
|
2017-06-02 21:51:07 +00:00
|
|
|
};
|
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
TRACE_2("",_effectiveRole,_x);
|
|
|
|
|
|
|
|
if (_effectiveRole != _desiredRole) exitWith {};
|
|
|
|
|
|
|
|
if (_turretPath isNotEqualTo []) then {
|
|
|
|
// Using GetInTurret seems to solve problems with incorrect GetInEH params when gunner/commander
|
|
|
|
ACE_player action ["GetInTurret", _target, _turretPath];
|
|
|
|
TRACE_3("Getting In Turret",_x,_role,_turretPath);
|
|
|
|
} else {
|
|
|
|
if (_cargoIndex > -1) then {
|
|
|
|
// GetInCargo expects the index of the seat in the "cargo" array from fullCrew
|
|
|
|
// See description: https://community.bistudio.com/wiki/fullCrew
|
|
|
|
private _cargoActionIndex = (fullCrew [_target, "cargo", true]) findIf {(_x select 2) == _cargoIndex};
|
2017-06-02 21:51:07 +00:00
|
|
|
|
2024-07-20 06:15:15 +00:00
|
|
|
ACE_player action ["GetInCargo", _target, _cargoActionIndex];
|
|
|
|
TRACE_4("Getting In Cargo",_x,_role,_cargoActionIndex,_cargoIndex);
|
|
|
|
} else {
|
|
|
|
ACE_player action ["GetIn" + _role, _target];
|
|
|
|
TRACE_2("Getting In",_x,_role);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
_hasAction = true;
|
|
|
|
breakTo "SearchForSeat";
|
|
|
|
};
|
|
|
|
} forEach _fullCrew;
|
|
|
|
} forEach _sortedSeats;
|
|
|
|
|
|
|
|
if (!_hasAction) then {
|
|
|
|
TRACE_1("no empty seats",_hasAction);
|
|
|
|
[LLSTRING(VehicleFull)] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|