Skip to content

Commit

Permalink
Fix cases where airspaceControl wouldn't execute despite a player fly…
Browse files Browse the repository at this point in the history
…ing an air vehicle
  • Loading branch information
jaj22 committed Feb 5, 2024
1 parent 63e90d6 commit 0bc0367
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
37 changes: 19 additions & 18 deletions A3A/addons/core/functions/Base/fn_airspaceControl.sqf
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
#define CIV_HELI 0
#define MIL_HELI 1
#define JET 2

params ["_vehicle"];
#include "..\..\script_component.hpp"
FIX_LINE_NUMBERS()
/* Handles the airspace control of any player aircraft, breaking undercover and calling support
Execution on: Any
Execution on: Client
Scope: Internal
Params:
_vehicle: OBJECT : The vehicles that should be checked against enemy positions
_player: OBJECT : Player who boarded the vehicle
_vehicle: OBJECT : The vehicle that should be checked against enemy positions
Returns:
Nothing
*/

//If vehicle already has an airspace control script, exit here
if(_vehicle getVariable ["airspaceControl", false]) exitWith {};
#define CIV_HELI 0
#define MIL_HELI 1
#define JET 2

_vehicle setVariable ["airspaceControl", true, true];
#include "..\..\script_component.hpp"
FIX_LINE_NUMBERS()

params ["_player", "_vehicle"];

//Select the kind of aircraft
private _airType = -1;
Expand Down Expand Up @@ -72,13 +70,13 @@ private _fn_sendSupport =

private _markerSide = sidesX getVariable [_marker, sideUnknown];
//Reveal vehicle to all groups of the side so they can take actions
{
/* {
if(side _x == _markerSide) then
{
_x reveal [_vehicle, 4]; // TODO: doesn't actually work, needs remoteExec
};
} forEach allGroups;

*/
//Take actions against the aircraft
// Let support system decide whether it's worth reacting to
private _revealValue = [getMarkerPos _marker, _markerSide] call A3A_fnc_calculateSupportCallReveal;
Expand Down Expand Up @@ -137,9 +135,13 @@ private _fn_getMarkersInRange =
};


//While not in garage and alive and crewed we check what the aircraft is doing
while {!(isNull _vehicle) && {alive _vehicle && {count (crew _vehicle) != 0}}} do
while {_player in crew _vehicle && alive _vehicle} do
{
sleep 1;

// Only run the checks for the vehicle's commander
if (_player != effectiveCommander _vehicle) then { continue };

//Check undercover status
_vehicleIsUndercover = captive ((crew _vehicle) select 0);
_vehPos = getPosASL _vehicle;
Expand Down Expand Up @@ -230,7 +232,6 @@ while {!(isNull _vehicle) && {alive _vehicle && {count (crew _vehicle) != 0}}} d
};
};
};
sleep 1;
};

_vehicle setVariable ["airspaceControl", nil, true];
Debug_2("Exiting airspace control for player %1, vehicle %2", _player, typeof _vehicle);
13 changes: 0 additions & 13 deletions A3A/addons/core/functions/CREATE/fn_AIVEHinit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,6 @@ if (_side != teamPlayer) then
}];
};

if(_veh isKindOf "Air") then
{
//Start airspace control script if rebel player enters
_veh addEventHandler ["GetIn", {
params ["_veh", "_role", "_unit"];
if((side (group _unit) == teamPlayer) && {isPlayer _unit}) then
{
// TODO: check this isn't spammed
[_veh] spawn A3A_fnc_airspaceControl;
};
}];
};


// Handler for refunding vehicles after cleanup
if (A3A_vehicleResourceCosts getOrDefault [typeof _veh, 0] > 0) then {
Expand Down
16 changes: 13 additions & 3 deletions A3A/addons/core/functions/init/fn_initClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ player addEventHandler ["WeaponDisassembled", {
}];

player addEventHandler ["GetInMan", {
private ["_unit","_veh"];
_unit = _this select 0;
_veh = _this select 2;
params ["_unit", "_role", "_veh", "_turret"];
_exit = false;
if !([player] call A3A_fnc_isMember) then {
if (!isNil {_veh getVariable "A3A_locked"}) then {
Expand All @@ -287,9 +285,21 @@ player addEventHandler ["GetInMan", {
[] spawn A3A_fnc_goUndercover;
};
};
if (_veh isKindOf "Air") then {
Debug_2("Installing airspace control for player %1, vehicle %2", _unit, typeof _veh);
private _handle = [_unit, _veh] spawn A3A_fnc_airspaceControl;
_unit setVariable ["airspaceControlHandle", _handle];
};
};
}];

player addEventHandler ["GetOutMan", {
params ["_unit", "_role", "_veh", "_turret"];
Debug_2("Terminating airspace control for player %1, vehicle %2", _unit, typeof _veh);
private _handle = _unit getVariable ["airspaceControlHandle", scriptNull];
if (!isNull _handle) then { terminate _handle };
}];

// Prevent players getting shot by their own AIs. EH is respawn-persistent
player addEventHandler ["HandleRating", {0}];

Expand Down

0 comments on commit 0bc0367

Please sign in to comment.