Skip to content

Commit

Permalink
increase push force, if unflip unsuccessful
Browse files Browse the repository at this point in the history
  • Loading branch information
McDiod committed Jul 12, 2019
1 parent d3a3bb9 commit b725632
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
30 changes: 29 additions & 1 deletion addons/unflipping/XEH_preInitServer.sqf
Original file line number Diff line number Diff line change
@@ -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"];
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion addons/unflipping/functions/fn_unflipVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
Returns:
Vehicle was unflipped [BOOL]
*/

#define UNFLIP_FORCEFACTOR_EXPIRATIONTIME 300

params [
["_vehicle", objNull, [objNull]]
];
Expand All @@ -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;
Expand Down

0 comments on commit b725632

Please sign in to comment.