ACE3/addons/mk6mortar/functions/fnc_handleFired.sqf

82 lines
2.9 KiB
Plaintext
Raw Normal View History

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:
* Nothing
*
* 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
*/
#include "script_component.hpp"
2015-07-26 21:45:29 +00:00
if (!GVAR(airResistanceEnabled)) exitWith {};
2015-04-05 06:57:24 +00:00
PARAMS_7(_vehicle,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile);
2015-07-26 21:45:29 +00:00
private ["_shooterMan", "_temperature", "_newMuzzleVelocityCoefficent", "_bulletVelocity", "_bulletSpeed"];
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:
_shooterMan = gunner _vehicle;
if (!([_shooterMan] call EFUNC(common,isPlayer))) exitWith {false};
2015-04-24 18:26:09 +00:00
//Calculate air density:
_altitude = (getPosASL _vehicle) select 2;
_temperature = _altitude call EFUNC(weather,calculateTemperatureAtHeight);
2015-04-24 18:26:09 +00:00
_pressure = _altitude call EFUNC(weather,calculateBarometricPressure);
_relativeHumidity = EGVAR(weather,currentHumidity);
_airDensity = [_temperature, _pressure, _relativeHumidity] call EFUNC(weather,calculateAirDensity);
_relativeDensity = _airDensity / 1.225;
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:
2015-04-05 22:37:11 +00:00
_newMuzzleVelocityCoefficent = (((_temperature + 273.13) / 288.13 - 1) / 40 + 1);
2015-04-05 22:07:55 +00:00
if (_newMuzzleVelocityCoefficent != 1) then {
_bulletVelocity = velocity _projectile;
_bulletSpeed = vectorMagnitude _bulletVelocity;
_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
[{
private ["_deltaT", "_bulletVelocity", "_bulletSpeed", "_trueVelocity", "_trueSpeed", "_dragRef", "_accelRef", "_drag", "_accel"];
PARAMS_2(_args,_pfID);
2015-04-24 18:26:09 +00:00
EXPLODE_4_PVT(_args,_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
_deltaT = ACE_time - _time;
_args set[2, ACE_time];
2015-04-05 08:02:24 +00:00
_bulletVelocity = velocity _shell;
_bulletSpeed = vectorMagnitude _bulletVelocity;
2015-04-06 06:05:28 +00:00
_trueVelocity = _bulletVelocity vectorDiff ACE_wind;
_trueSpeed = vectorMagnitude _trueVelocity;
2015-04-05 08:02:24 +00:00
2015-04-24 18:26:09 +00:00
_drag = _deltaT * _airFriction * _trueSpeed * _relativeDensity;
2015-04-06 06:05:28 +00:00
_accel = _trueVelocity vectorMultiply (_drag);
_bulletVelocity = _bulletVelocity vectorAdd _accel;
2015-04-05 08:02:24 +00:00
_shell setVelocity _bulletVelocity;
}, 0, [_projectile, MK6_82mm_AIR_FRICTION, ACE_time, _relativeDensity]] call CBA_fnc_addPerFrameHandler;