2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-04-05 06:57:24 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
2015-04-05 22:50:07 +00:00
|
|
|
* Called when the mortar is fired.
|
2015-04-05 06:57:24 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: mortar - Object the event handler is assigned to <OBJECT>
|
|
|
|
* 1: weapon - Fired weapon <STRING>
|
|
|
|
* 2: muzzle - Muzzle that was used <STRING>
|
|
|
|
* 3: mode - Current mode of the fired weapon <STRING>
|
|
|
|
* 4: ammo - Ammo used <STRING>
|
|
|
|
* 5: magazine - magazine name which was used <STRING>
|
|
|
|
* 6: projectile - Object of the projectile that was shot <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
2015-04-05 06:57:24 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2015-04-06 06:05:28 +00:00
|
|
|
* [clientFiredBIS-XEH] call ace_mk6mortar_fnc_handleFired
|
2015-04-05 06:57:24 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2019-12-17 16:14:45 +00:00
|
|
|
params ["_vehicle", "", "", "", "", "", "_projectile"];
|
2015-12-19 15:30:01 +00:00
|
|
|
|
2015-04-06 06:05:28 +00:00
|
|
|
// Large enough distance to not simulate any wind deflection
|
2015-04-08 00:30:07 +00:00
|
|
|
if (_vehicle distance ACE_player > 8000) exitWith {false};
|
2015-04-05 22:50:07 +00:00
|
|
|
|
|
|
|
//AI will have no clue how to use:
|
2019-12-17 16:14:45 +00:00
|
|
|
private _shooterMan = gunner _vehicle;
|
2015-04-05 22:50:07 +00:00
|
|
|
if (!([_shooterMan] call EFUNC(common,isPlayer))) exitWith {false};
|
|
|
|
|
2015-04-24 18:26:09 +00:00
|
|
|
//Calculate air density:
|
2017-10-10 14:39:59 +00:00
|
|
|
private _altitude = (getPosASL _vehicle) select 2;
|
|
|
|
private _temperature = _altitude call EFUNC(weather,calculateTemperatureAtHeight);
|
|
|
|
private _pressure = _altitude call EFUNC(weather,calculateBarometricPressure);
|
|
|
|
private _relativeHumidity = EGVAR(weather,currentHumidity);
|
|
|
|
private _airDensity = [_temperature, _pressure, _relativeHumidity] call EFUNC(weather,calculateAirDensity);
|
|
|
|
private _relativeDensity = _airDensity / 1.225;
|
2015-04-24 18:26:09 +00:00
|
|
|
|
|
|
|
TRACE_5("FiredWeather",_temperature,_pressure,_relativeHumidity,_airDensity,_relativeDensity);
|
2015-04-05 22:50:07 +00:00
|
|
|
|
2015-04-05 22:07:55 +00:00
|
|
|
//powder effects:
|
2017-10-10 14:39:59 +00:00
|
|
|
private _newMuzzleVelocityCoefficent = (((_temperature + 273.13) / 288.13 - 1) / 40 + 1);
|
2015-04-05 22:07:55 +00:00
|
|
|
if (_newMuzzleVelocityCoefficent != 1) then {
|
2019-12-17 16:14:45 +00:00
|
|
|
private _bulletVelocity = velocity _projectile;
|
|
|
|
private _bulletSpeed = vectorMagnitude _bulletVelocity;
|
2015-04-05 22:07:55 +00:00
|
|
|
_bulletVelocity = (vectorNormalized _bulletVelocity) vectorMultiply (_bulletSpeed * _newMuzzleVelocityCoefficent);
|
|
|
|
_projectile setVelocity _bulletVelocity;
|
|
|
|
};
|
|
|
|
|
2015-04-24 18:26:09 +00:00
|
|
|
|
2015-04-05 08:02:24 +00:00
|
|
|
[{
|
2017-10-10 14:39:59 +00:00
|
|
|
params ["_args", "_pfID"];
|
|
|
|
_args params ["_shell", "_airFriction", "_time", "_relativeDensity"];
|
2015-04-05 06:57:24 +00:00
|
|
|
|
2015-11-30 16:14:05 +00:00
|
|
|
if (isNull _shell || {!alive _shell}) exitWith {
|
2015-11-30 15:45:20 +00:00
|
|
|
[_pfID] call CBA_fnc_removePerFrameHandler;
|
2015-04-05 08:02:24 +00:00
|
|
|
};
|
2015-04-05 06:57:24 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _deltaT = CBA_missionTime - _time;
|
2016-03-02 10:01:39 +00:00
|
|
|
_args set[2, CBA_missionTime];
|
2015-04-05 08:02:24 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _bulletVelocity = velocity _shell;
|
2015-04-05 08:02:24 +00:00
|
|
|
|
2017-11-10 14:44:15 +00:00
|
|
|
private _trueVelocity = _bulletVelocity vectorDiff wind;
|
2017-10-10 14:39:59 +00:00
|
|
|
private _trueSpeed = vectorMagnitude _trueVelocity;
|
2015-04-05 08:02:24 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _drag = _deltaT * _airFriction * _trueSpeed * _relativeDensity;
|
|
|
|
private _accel = _trueVelocity vectorMultiply (_drag);
|
|
|
|
private _bulletVelocity = _bulletVelocity vectorAdd _accel;
|
2015-04-05 08:02:24 +00:00
|
|
|
|
|
|
|
_shell setVelocity _bulletVelocity;
|
|
|
|
|
2016-03-02 10:01:39 +00:00
|
|
|
}, 0, [_projectile, MK6_82mm_AIR_FRICTION, CBA_missionTime, _relativeDensity]] call CBA_fnc_addPerFrameHandler;
|