mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Aircraft - Drone Tools (#8276)
* Aircraft - Drone Tools * Update addons/aircraft/functions/fnc_droneAddActions.sqf Co-authored-by: Dystopian <sddex@ya.ru> * Update addons/aircraft/functions/fnc_droneAddMapHandler.sqf Co-authored-by: Dystopian <sddex@ya.ru> * Update fnc_droneAddActions.sqf * Move map drawing to laser and make it work on any source Co-authored-by: Dystopian <sddex@ya.ru>
This commit is contained in:
parent
89badcc71f
commit
ada486448c
@ -9,3 +9,9 @@ class Extended_PreInit_EventHandlers {
|
||||
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
|
||||
};
|
||||
};
|
||||
|
||||
class Extended_PostInit_EventHandlers {
|
||||
class ADDON {
|
||||
init = QUOTE(call COMPILE_FILE(XEH_postInit));
|
||||
};
|
||||
};
|
||||
|
@ -1,2 +1,6 @@
|
||||
PREP(initEjectAction);
|
||||
PREP(canShowEject);
|
||||
PREP(droneAddActions);
|
||||
PREP(droneGetTurretTargetPos);
|
||||
PREP(droneModifyWaypoint);
|
||||
PREP(droneSetWaypoint);
|
||||
PREP(initEjectAction);
|
||||
|
8
addons/aircraft/XEH_postInit.sqf
Normal file
8
addons/aircraft/XEH_postInit.sqf
Normal file
@ -0,0 +1,8 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
[QGVAR(droneModifyWaypoint), LINKFUNC(droneModifyWaypoint)] call CBA_fnc_addEventHandler;
|
||||
[QGVAR(droneSetWaypoint), LINKFUNC(droneSetWaypoint)] call CBA_fnc_addEventHandler;
|
||||
|
||||
if (hasInterface) then {
|
||||
["ACE_controlledUAV", LINKFUNC(droneAddActions)] call CBA_fnc_addEventHandler;
|
||||
};
|
121
addons/aircraft/functions/fnc_droneAddActions.sqf
Normal file
121
addons/aircraft/functions/fnc_droneAddActions.sqf
Normal file
@ -0,0 +1,121 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Adds actions to a drone
|
||||
*
|
||||
* Arguments:
|
||||
* 0: vehicle <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [v] call ace_aircraft_fnc_droneAddActions
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_vehicle"];
|
||||
TRACE_1("droneAddActions",_vehicle);
|
||||
|
||||
if (!alive _vehicle) exitWith {};
|
||||
if (_vehicle getVariable [QGVAR(droneActionsAdded), false]) exitWith {};
|
||||
_vehicle setVariable [QGVAR(droneActionsAdded), true];
|
||||
|
||||
// move to location
|
||||
private _condition = {
|
||||
params ["_vehicle"];
|
||||
(missionNamespace getVariable [QGVAR(droneWaypoints), true]) && {waypointsEnabledUAV _vehicle} && {(ACE_controlledUAV select 2) isEqualTo [0]}
|
||||
};
|
||||
private _statement = {
|
||||
params ["_vehicle"];
|
||||
private _group = group driver _vehicle;
|
||||
private _pos = ([_vehicle, [0]] call FUNC(droneGetTurretTargetPos)) select 0;
|
||||
[QGVAR(droneSetWaypoint), [_vehicle, _group, _pos, "MOVE"], _group] call CBA_fnc_targetEvent;
|
||||
};
|
||||
private _action = [QGVAR(droneSetWaypointMove), localize "$STR_AC_MOVE",
|
||||
"\a3\3DEN\Data\CfgWaypoints\Move_ca.paa", _statement, _condition] call EFUNC(interact_menu,createAction);
|
||||
[_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
|
||||
|
||||
|
||||
if (_vehicle isKindOf "Air") then {
|
||||
// loiter at location
|
||||
_condition = {
|
||||
params ["_vehicle"];
|
||||
(missionNamespace getVariable [QGVAR(droneWaypoints), true]) && {waypointsEnabledUAV _vehicle} && {(ACE_controlledUAV select 2) isEqualTo [0]}
|
||||
};
|
||||
_statement = {
|
||||
params ["_vehicle"];
|
||||
private _group = group driver _vehicle;
|
||||
private _pos = ([_vehicle, [0]] call FUNC(droneGetTurretTargetPos)) select 0;
|
||||
[QGVAR(droneSetWaypoint), [_vehicle, _group, _pos, "LOITER"], _group] call CBA_fnc_targetEvent;
|
||||
};
|
||||
_action = [QGVAR(droneSetWaypointLoiter), localize "$STR_AC_LOITER",
|
||||
"\a3\3DEN\Data\CfgWaypoints\Loiter_ca.paa", _statement, _condition] call EFUNC(interact_menu,createAction);
|
||||
[_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
|
||||
|
||||
|
||||
// set height
|
||||
_condition = {
|
||||
params ["_vehicle"];
|
||||
(missionNamespace getVariable [QGVAR(droneWaypoints), true]) && {waypointsEnabledUAV _vehicle} && {(ACE_controlledUAV select 2) isEqualTo [0]}
|
||||
};
|
||||
_statement = {
|
||||
params ["_vehicle", "", "_args"];
|
||||
private _group = group driver _vehicle;
|
||||
[QGVAR(droneModifyWaypoint), [_vehicle, _group, "height", _args], _group] call CBA_fnc_targetEvent;
|
||||
};
|
||||
_action = [QGVAR(setAltitude), localize "$STR_3den_waypoint_attribute_loiteraltitude_displayname",
|
||||
"", {}, _condition] call EFUNC(interact_menu,createAction);
|
||||
private _base = [_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
|
||||
{
|
||||
_action = [str _x, str _x, "", _statement, { true }, {}, _x] call EFUNC(interact_menu,createAction);
|
||||
[_vehicle, 1, _base, _action] call EFUNC(interact_menu,addActionToObject);
|
||||
} forEach [20, 50, 200, 500, 2000];
|
||||
|
||||
|
||||
// set loiter radius
|
||||
_condition = {
|
||||
params ["_vehicle"];
|
||||
private _group = group driver _vehicle;
|
||||
private _index = (currentWaypoint _group) min count waypoints _group;
|
||||
private _waypoint = [_group, _index];
|
||||
(missionNamespace getVariable [QGVAR(droneWaypoints), true]) && {waypointsEnabledUAV _vehicle} && {(ACE_controlledUAV select 2) isEqualTo [0]}
|
||||
&& {(waypointType _waypoint) == "LOITER"}
|
||||
};
|
||||
_statement = {
|
||||
params ["_vehicle", "", "_args"];
|
||||
private _group = group driver _vehicle;
|
||||
[QGVAR(droneModifyWaypoint), [_vehicle, _group, "radius", _args], _group] call CBA_fnc_targetEvent;
|
||||
};
|
||||
_action = [QGVAR(lotierRadius), localize "$STR_3den_waypoint_attribute_loiterradius_displayname",
|
||||
"", {}, _condition] call EFUNC(interact_menu,createAction);
|
||||
_base = [_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
|
||||
{
|
||||
_action = [str _x, str _x, "", _statement, { true }, {}, _x] call EFUNC(interact_menu,createAction);
|
||||
[_vehicle, 1, _base, _action] call EFUNC(interact_menu,addActionToObject);
|
||||
} forEach [500, 750, 1000, 1250, 1500];
|
||||
|
||||
|
||||
// set loiter direction
|
||||
_condition = {
|
||||
params ["_vehicle", "", "_args"];
|
||||
private _group = group driver _vehicle;
|
||||
private _index = (currentWaypoint _group) min count waypoints _group;
|
||||
private _waypoint = [_group, _index];
|
||||
|
||||
(missionNamespace getVariable [QGVAR(droneWaypoints), true]) && {waypointsEnabledUAV _vehicle} && {(ACE_controlledUAV select 2) isEqualTo [0]}
|
||||
&& {(waypointType _waypoint) == "LOITER"} && {(waypointLoiterType _waypoint) != _args}
|
||||
};
|
||||
_statement = {
|
||||
params ["_vehicle", "", "_args"];
|
||||
private _group = group driver _vehicle;
|
||||
[QGVAR(droneModifyWaypoint), [_vehicle, _group, "dir", _args], _group] call CBA_fnc_targetEvent;
|
||||
};
|
||||
_action = [QGVAR(lotierTypeR), localize "$STR_3den_waypoint_attribute_loiterdirection_displayname",
|
||||
"\a3\3DEN\Data\Attributes\LoiterDirection\cw_ca.paa", _statement, _condition, {}, "CIRCLE"] call EFUNC(interact_menu,createAction);
|
||||
[_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
|
||||
_action = [QGVAR(lotierTypeR), localize "$STR_3den_waypoint_attribute_loiterdirection_displayname",
|
||||
"\a3\3DEN\Data\Attributes\LoiterDirection\ccw_ca.paa", _statement, _condition, {}, "CIRCLE_L"] call EFUNC(interact_menu,createAction);
|
||||
[_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
|
||||
};
|
46
addons/aircraft/functions/fnc_droneGetTurretTargetPos.sqf
Normal file
46
addons/aircraft/functions/fnc_droneGetTurretTargetPos.sqf
Normal file
@ -0,0 +1,46 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Get drone's target location, if aimed at infinity it will return a virtual point
|
||||
*
|
||||
* Arguments:
|
||||
* 0: vehicle <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* [PosASL <ARRAY>, Real <BOOL>]
|
||||
*
|
||||
* Example:
|
||||
* [v] call ace_aircraft_fnc_droneGetTurretTargetPos
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_vehicle"];
|
||||
private _turret = [0];
|
||||
TRACE_2("droneGetTurretTargetPos",_vehicle,_turret);
|
||||
|
||||
private _turretConfig = [_vehicle, _turret] call CBA_fnc_getTurret;
|
||||
|
||||
private _gunBeg = _vehicle selectionPosition getText (_turretConfig >> "gunBeg");
|
||||
private _gunEnd = _vehicle selectionPosition getText (_turretConfig >> "gunEnd");
|
||||
|
||||
if (_gunEnd isEqualTo _gunBeg) then {
|
||||
// e.g. Darter doesn't have valid gunBeg/gunEnd
|
||||
private _vehicleConfig = configOf _vehicle;
|
||||
_gunBeg = _vehicle selectionPosition getText (_vehicleConfig >> "uavCameraGunnerDir");
|
||||
_gunEnd = _vehicle selectionPosition getText (_vehicleConfig >> "uavCameraGunnerPos");
|
||||
};
|
||||
|
||||
_gunBeg = AGLToASL (_vehicle modelToWorld _gunBeg);
|
||||
_gunEnd = AGLToASL (_vehicle modelToWorld _gunEnd);
|
||||
private _turretDir = _gunEnd vectorFromTo _gunBeg;
|
||||
private _farPoint = _gunEnd vectorAdd (_turretDir vectorMultiply 4999);
|
||||
|
||||
private _intersections = lineIntersectsSurfaces [_gunEnd, _farPoint, _vehicle, objNull, true, 1];
|
||||
if (_intersections isNotEqualTo []) then {
|
||||
[_intersections select 0 select 0, true]
|
||||
} else {
|
||||
// Not looking at anything, just get a virtual point where the camera is pointing
|
||||
_farPoint set [2, 0 max getTerrainHeightASL _farPoint];
|
||||
[_farPoint, false]
|
||||
};
|
36
addons/aircraft/functions/fnc_droneModifyWaypoint.sqf
Normal file
36
addons/aircraft/functions/fnc_droneModifyWaypoint.sqf
Normal file
@ -0,0 +1,36 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Modify the current waypoint of a drone
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Vehicle <OBJECT>
|
||||
* 1: Group <GROUP>
|
||||
* 2: Type <STRING>
|
||||
* 3: Value <ANY>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [v, group v, "height", 2000] call ace_aircraft_fnc_droneModifyWaypoint
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_vehicle", "_group", "_type", "_value"];
|
||||
TRACE_4("droneModifyWaypoint",_vehicle,_group,_type,_value);
|
||||
|
||||
private _index = (currentWaypoint _group) min count waypoints _group;
|
||||
private _waypoint = [_group, _index];
|
||||
switch (toLower _type) do {
|
||||
case ("height"): {
|
||||
private _pos = waypointPosition _waypoint;
|
||||
_pos set [2, _value];
|
||||
_waypoint setWaypointPosition [_pos, 0];
|
||||
_vehicle flyInHeight _value;
|
||||
};
|
||||
case ("radius"): { _waypoint setWaypointLoiterRadius _value; };
|
||||
case ("dir"): { _waypoint setWaypointLoiterType _value; };
|
||||
};
|
||||
_group setCurrentWaypoint _waypoint;
|
43
addons/aircraft/functions/fnc_droneSetWaypoint.sqf
Normal file
43
addons/aircraft/functions/fnc_droneSetWaypoint.sqf
Normal file
@ -0,0 +1,43 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Set new waypoint of a drone
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Vehicle <OBJECT>
|
||||
* 1: Group <GROUP>
|
||||
* 2: Pos 2D <ARRAY>
|
||||
* 3: Type <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [v, group v, [2000,5000], "LOITER"] call ace_aircraft_fnc_droneSetWaypoint
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_vehicle", "_group", "_pos", "_type"];
|
||||
TRACE_4("droneSetWaypoint",_vehicle,_group,_pos,_type);
|
||||
|
||||
private _index = (currentWaypoint _group) min count waypoints _group;
|
||||
private _waypoint = [_group, _index];
|
||||
// Try to save attributes from existing waypoint
|
||||
private _currentHeight = round ((waypointPosition _waypoint) select 2);
|
||||
private _currentLoiterRadius = waypointLoiterRadius _waypoint;
|
||||
private _currentLoiterType = waypointLoiterType _waypoint;
|
||||
|
||||
// Set pos to ATL
|
||||
_pos set [2, if (_currentHeight >= 50) then { _currentHeight } else { 0 }];
|
||||
|
||||
// [_group] call CBA_fnc_clearWaypoints;
|
||||
_waypoint = _group addWaypoint [_pos, 0];
|
||||
_waypoint setWaypointType _type;
|
||||
|
||||
TRACE_3("",_currentHeight,_currentLoiterRadius,_currentLoiterType);
|
||||
if (_currentHeight > 1) then { _vehicle flyInHeight _currentHeight; };
|
||||
if (_currentLoiterRadius > 1) then { _waypoint setWaypointLoiterRadius _currentLoiterRadius; };
|
||||
if (_currentLoiterType != "") then { _waypoint setWaypointLoiterType _currentLoiterType; };
|
||||
|
||||
_group setCurrentWaypoint _waypoint;
|
@ -1,5 +1,6 @@
|
||||
|
||||
PREP(addLaserTarget);
|
||||
PREP(addMapHandler);
|
||||
PREP(dev_drawVisibleLaserTargets);
|
||||
PREP(findLaserSource);
|
||||
PREP(handleLaserTargetCreation);
|
||||
|
@ -6,6 +6,13 @@ if (hasInterface) then {
|
||||
GVAR(pfID) = -1;
|
||||
|
||||
["CBA_settingsInitialized", {
|
||||
// Handle Map Drawing
|
||||
GVAR(mapLaserSource) = objNull;
|
||||
["ACE_controlledUAV", LINKFUNC(addMapHandler)] call CBA_fnc_addEventHandler;
|
||||
["turret", LINKFUNC(addMapHandler), false] call CBA_fnc_addPlayerEventHandler;
|
||||
["unit", LINKFUNC(addMapHandler), true] call CBA_fnc_addPlayerEventHandler;
|
||||
|
||||
// Laser code display
|
||||
["turret", LINKFUNC(showVehicleHud), false] call CBA_fnc_addPlayerEventHandler;
|
||||
["vehicle", LINKFUNC(showVehicleHud), true] call CBA_fnc_addPlayerEventHandler; // only one of these needs the retro flag
|
||||
|
||||
|
70
addons/laser/functions/fnc_addMapHandler.sqf
Normal file
70
addons/laser/functions/fnc_addMapHandler.sqf
Normal file
@ -0,0 +1,70 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Add laser drawing to map
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [] call ace_laser_fnc_addMapHandler
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
TRACE_3("addMapHandler",ace_player,typeOf vehicle ace_player,ACE_controlledUAV);
|
||||
|
||||
GVAR(mapLaserSource) = call {
|
||||
if (GVAR(showLaserOnMap) == 0) exitWith {
|
||||
TRACE_1("setting - disabled",GVAR(showLaserOnMap));
|
||||
objNull
|
||||
};
|
||||
if (alive (ACE_controlledUAV # 0)) exitWith {
|
||||
TRACE_1("using UAV",objNull);
|
||||
ACE_controlledUAV # 0;
|
||||
};
|
||||
if (GVAR(showLaserOnMap) == 1) exitWith {
|
||||
TRACE_1("setting - no UAV",GVAR(showLaserOnMap));
|
||||
objNull
|
||||
};
|
||||
private _player = ace_player;
|
||||
private _vehicle = vehicle _player;
|
||||
if ((_player != _vehicle) && {_player in [gunner _vehicle, commander _vehicle]}) exitWith {
|
||||
TRACE_1("using player's vehicle",_vehicle);
|
||||
_vehicle
|
||||
};
|
||||
if (GVAR(showLaserOnMap) == 2) exitWith {
|
||||
TRACE_1("setting - no UAV or vehicle",GVAR(showLaserOnMap));
|
||||
objNull
|
||||
};
|
||||
TRACE_1("using player",_player);
|
||||
_player
|
||||
};
|
||||
|
||||
if (!alive GVAR(mapLaserSource)) exitWith {};
|
||||
|
||||
[{!isNull findDisplay 12}, // for some reason the display is null for the frame when starting to control drone
|
||||
{
|
||||
private _map = ((findDisplay 12) displayCtrl 51);
|
||||
private _ehID = _map getVariable [QGVAR(ehID), -1];
|
||||
if (_ehID > -1) exitWith {};
|
||||
_ehID = _map ctrlAddEventHandler ["Draw", {
|
||||
if (!alive GVAR(mapLaserSource)) exitWith {};
|
||||
private _laserTarget = laserTarget GVAR(mapLaserSource);
|
||||
if (!alive _laserTarget) exitWith {};
|
||||
|
||||
params ["_map"];
|
||||
_map drawLine [getPos _laserTarget, getPos GVAR(mapLaserSource), [1,0,0,0.333]];
|
||||
_map drawIcon [
|
||||
"\A3\ui_f\data\igui\rscingameui\rscoptics\laser_designator_iconLaserOn.paa",
|
||||
[1,0,1,1],
|
||||
(getPos _laserTarget),
|
||||
16, 16,
|
||||
((getDir _laserTarget) + 90)
|
||||
];
|
||||
}];
|
||||
TRACE_2("added map drawEH",_map,_ehID);
|
||||
_map setVariable [QGVAR(ehID), _ehID];
|
||||
}, []] call CBA_fnc_waitUntilAndExecute;
|
@ -7,3 +7,15 @@ private _category = [LELSTRING(common,categoryUncategorized), LLSTRING(laser)];
|
||||
[0, 5, 2, -1],
|
||||
1
|
||||
] call CBA_fnc_addSetting;
|
||||
|
||||
[
|
||||
QGVAR(showLaserOnMap), "LIST",
|
||||
[LSTRING(showLaserOnMap), LSTRING(showLaserOnMap_tooltip)],
|
||||
_category,
|
||||
[
|
||||
[0, 1, 2, 3],
|
||||
[LELSTRING(Common,Disabled), "STR_A3_CfgEditorSubcategories_EdSubcat_Drones0", "str_dn_vehicles", LELSTRING(common,Always)],
|
||||
1
|
||||
],
|
||||
true
|
||||
] call CBA_fnc_addSetting;
|
||||
|
@ -85,5 +85,11 @@
|
||||
<Chinese>雷射 - 循環切換雷射碼 下</Chinese>
|
||||
<Turkish>Lazer - Çevrim Kodu aşağı</Turkish>
|
||||
</Key>
|
||||
<Key ID="STR_ACE_Laser_showLaserOnMap">
|
||||
<English>Draw Laser on Map</English>
|
||||
</Key>
|
||||
<Key ID="STR_ACE_Laser_showLaserOnMap_tooltip">
|
||||
<English>Active laser designator's position will be drawn on the map</English>
|
||||
</Key>
|
||||
</Package>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user