ACE3/addons/mk6mortar/functions/fnc_handleFired.sqf

90 lines
3.2 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-04-24 18:26:09 +00:00
private ["_shooterMan", "_bisAirFriction", "_temperature", "_newMuzzleVelocityCoefficent", "_bulletVelocity", "_bulletSpeed", "_muzzleVelocity", "_muzzleVelocityShift"];
2015-04-08 00:30:07 +00:00
2015-04-05 06:57:24 +00:00
disableSerialization;
PARAMS_7(_vehicle,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile);
if (!GVAR(airResistanceEnabled)) exitWith {};
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-06 06:05:28 +00:00
//Should be zero, just make sure:
_bisAirFriction = getNumber (configFile >> "CfgAmmo" >> _ammo >> "airFriction");
if (_bisAirFriction != 0) exitWith {ERROR("Non zero base airFriction");};
2015-04-05 22:07:55 +00:00
2015-04-24 18:26:09 +00:00
//Calculate air density:
_altitude = (getPosASL _vehicle) select 2;
#define GET_TEMPERATURE_AT_HEIGHT(h) (EGVAR(weather,currentTemperature) - 0.0065 * (h))
_temperature = GET_TEMPERATURE_AT_HEIGHT(_altitude);
_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;
_muzzleVelocity = _muzzleVelocity + _muzzleVelocityShift;
};
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-04-05 08:02:24 +00:00
if (isNull _shell || {!alive _shell}) exitwith {
[_pfID] call cba_fnc_removePerFrameHandler;
};
2015-04-05 06:57:24 +00:00
2015-04-05 08:02:24 +00:00
_deltaT = time - _time;
_args set[2, time];
_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;
2015-04-24 18:26:09 +00:00
}, 0, [_projectile, MK6_82mm_AIR_FRICTION, time, _relativeDensity]] call CBA_fnc_addPerFrameHandler;