diff --git a/addons/unflipping/XEH_preInitServer.sqf b/addons/unflipping/XEH_preInitServer.sqf index 23588a2..688fd0e 100644 --- a/addons/unflipping/XEH_preInitServer.sqf +++ b/addons/unflipping/XEH_preInitServer.sqf @@ -1,5 +1,8 @@ #include "initSettings.sqf" +#define UNFLIP_CHECK_WAITTIME 4 +#define UNFLIP_FORCEFACTOR_STEP 0.2 +#define UNFLIP_FORCEFACTOR_MAX 5 ["vet_unflipping_unflip_start", { params ["_vehicle", "_player"]; @@ -31,7 +34,32 @@ // onTimeout (success) { params ["_vehicle"]; - _vehicle call vet_unflipping_fnc_unflipVehicle; + private _unflipAttempted = _vehicle call vet_unflipping_fnc_unflipVehicle; + + // check if unflip was successful + if (_unflipAttempted) then { + [{ + params ["_vehicle"]; + + if (isNull _vehicle) exitWith {}; + + private _upsideDown = (vectorUp _vehicle vectorDotProduct surfaceNormal getPos _vehicle) < -0.80; + private _bank = _vehicle call BIS_fnc_getPitchBank select 1; + + // unflip successful --> reset force factor + if (!_upsideDown && 55 > abs _bank) then { + _vehicle setVariable ["vet_forceFactor", nil, false]; + diag_log text format ["[VET_Unflipping] Vehicle '%1', unflip was successful.", _vehicle]; + + // unflip unsuccessful --> increase force factor + } else { + private _forceFactor = ((_vehicle getVariable ["vet_forceFactor", 1]) + UNFLIP_FORCEFACTOR_STEP) min UNFLIP_FORCEFACTOR_MAX; + _vehicle setVariable ["vet_forceFactor", _forceFactor, false]; + diag_log text format ["[VET_Unflipping] Vehicle '%1', unflip was unsuccessful. Increased force factor to %2", _vehicle, _forceFactor]; + }; + }, [_vehicle], UNFLIP_CHECK_WAITTIME] call CBA_fnc_waitAndExecute; + }; + _vehicle setVariable ["vet_unflippingUnits", [], true]; } ] call CBA_fnc_waitUntilAndExecute; diff --git a/addons/unflipping/functions/fn_unflipVehicle.sqf b/addons/unflipping/functions/fn_unflipVehicle.sqf index 219be41..bee1b07 100644 --- a/addons/unflipping/functions/fn_unflipVehicle.sqf +++ b/addons/unflipping/functions/fn_unflipVehicle.sqf @@ -15,6 +15,9 @@ Returns: Vehicle was unflipped [BOOL] */ + +#define UNFLIP_FORCEFACTOR_EXPIRATIONTIME 300 + params [ ["_vehicle", objNull, [objNull]] ]; @@ -35,7 +38,17 @@ if (!_upsideDown && 55 > abs _bank) exitWith {false}; private _bbr = boundingBoxReal _vehicle; private _vehicleWidth = abs (_bbr#0#0 * 2); -private _force = getMass _vehicle * ([1 + (_vehicleWidth/10), _vehicleWidth] select _upsideDown); +// force factor is set in vet_unflipping_unflip_start event +private _lastUnflipAttempt = _vehicle getVariable ["vet_lastUnflipAttempt", CBA_missionTime]; +private _forceFactor = if ((CBA_missionTime - _lastUnflipAttempt) < UNFLIP_FORCEFACTOR_EXPIRATIONTIME) then { + _vehicle getVariable ["vet_forceFactor", 1] +} else { + _vehicle setVariable ["vet_forceFactor", nil]; + 1 +}; +_vehicle setVariable ["vet_lastUnflipAttempt", CBA_missionTime]; + +private _force = getMass _vehicle * ([1 + (_vehicleWidth/10), _vehicleWidth] select _upsideDown) * _forceFactor; private _forcePointX = _bbr select ([0, 1] select _flipLeft) select 0; private _forcePointZ = _bbr select ([1, 0] select _upsideDown) select 2;