ACE3/addons/advanced_ballistics/functions/fnc_handleFired.sqf

131 lines
6.3 KiB
Plaintext
Raw Normal View History

2015-04-05 19:08:55 +00:00
/*
* Author: Glowbal, Ruthberg
*
* Handles advanced ballistics for (BulletBase) projectiles
2015-04-05 19:08:55 +00:00
*
* Arguments:
* 0: unit - 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:
* None
2015-04-05 19:08:55 +00:00
*
* Public: No
*/
#include "script_component.hpp"
2015-08-06 08:58:07 +00:00
// Early Quiting
if (!hasInterface) exitWith {};
if (!GVAR(enabled)) exitWith {};
2015-08-06 11:35:55 +00:00
// Parameterization
private ["_abort", "_AmmoCacheEntry", "_WeaponCacheEntry", "_opticsName", "_opticType", "_bulletTraceVisible", "_temperature", "_barometricPressure", "_bulletMass", "_bulletLength", "_muzzleVelocity", "_muzzleVelocityShift", "_bulletVelocity", "_bulletLength", "_barrelTwist", "_stabilityFactor", "_aceTimeSecond", "_barrelVelocityShift", "_ammoTemperatureVelocityShift"];
params ["_unit", "_weapon", "", "_mode", "_ammo", "_magazine", "_bullet"];
2015-04-05 19:08:55 +00:00
2015-04-12 09:48:21 +00:00
_abort = false;
2015-08-06 08:58:07 +00:00
if (!(_ammo isKindOf "BulletBase")) exitWith {};
2015-04-05 19:08:55 +00:00
if (!alive _bullet) exitWith {};
if (!([_unit] call EFUNC(common,isPlayer))) exitWith {};
2015-04-12 10:09:55 +00:00
if (_unit distance ACE_player > GVAR(simulationRadius)) exitWith {};
2015-08-06 08:58:07 +00:00
if (underwater _unit) exitWith {};
2015-05-19 18:46:55 +00:00
if (!GVAR(simulateForEveryone) && !(local _unit)) then {
// The shooter is non local
_abort = true;
if (GVAR(simulateForSnipers)) then {
if (currentWeapon _unit == primaryWeapon _unit && count primaryWeaponItems _unit > 2) then {
_opticsName = (primaryWeaponItems _unit) select 2;
2015-05-08 15:20:56 +00:00
_opticType = getNumber(configFile >> "CfgWeapons" >> _opticsName >> "ItemInfo" >> "opticType");
_abort = _opticType != 2; // We only abort if the non local shooter is not a sniper
};
};
if (GVAR(simulateForGroupMembers) && _abort) then {
_abort = (group ACE_player) != (group _unit);
};
};
2015-05-01 08:26:37 +00:00
//if (!GVAR(vehicleGunnerEnabled) && !(_unit isKindOf "Man")) then { _abort = true; }; // We currently do not have firedEHs on vehicles
2015-05-08 15:20:56 +00:00
if (GVAR(disabledInFullAutoMode) && getNumber(configFile >> "CfgWeapons" >> _weapon >> _mode >> "autoFire") == 1) then { _abort = true; };
2015-04-12 09:48:21 +00:00
2015-04-13 10:56:53 +00:00
if (_abort || !(GVAR(extensionAvailable))) exitWith {
2015-09-16 09:54:49 +00:00
if (missionNamespace getVariable [QEGVAR(windDeflection,enabled), false]) then {
EGVAR(windDeflection,trackedBullets) pushBack [_bullet, getNumber(configFile >> "cfgAmmo" >> _ammo >> "airFriction")];
};
};
2015-08-06 08:58:07 +00:00
// Get Weapon and Ammo Configurations
_AmmoCacheEntry = uiNamespace getVariable format[QGVAR(%1), _ammo];
2015-08-06 08:58:07 +00:00
if (isNil "_AmmoCacheEntry") then {
_AmmoCacheEntry = _ammo call FUNC(readAmmoDataFromConfig);
2015-05-08 15:20:56 +00:00
};
_WeaponCacheEntry = uiNamespace getVariable format[QGVAR(%1), _weapon];
2015-08-06 08:58:07 +00:00
if (isNil "_WeaponCacheEntry") then {
_WeaponCacheEntry = _weapon call FUNC(readWeaponDataFromConfig);
2015-05-08 15:20:56 +00:00
};
2015-08-05 08:28:02 +00:00
_AmmoCacheEntry params ["_airFriction", "_caliber", "_bulletLength", "_bulletMass", "_transonicStabilityCoef", "_dragModel", "_ballisticCoefficients", "_velocityBoundaries", "_atmosphereModel", "_ammoTempMuzzleVelocityShifts", "_muzzleVelocityTable", "_barrelLengthTable"];
_WeaponCacheEntry params ["_barrelTwist", "_twistDirection", "_barrelLength"];
2015-08-06 08:58:07 +00:00
_bulletVelocity = velocity _bullet;
_muzzleVelocity = vectorMagnitude _bulletVelocity;
2015-04-05 19:08:55 +00:00
_barrelVelocityShift = 0;
if (GVAR(barrelLengthInfluenceEnabled)) then {
_barrelVelocityShift = [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, _muzzleVelocity] call FUNC(calculateBarrelLengthVelocityShift);
2015-04-05 19:08:55 +00:00
};
_ammoTemperatureVelocityShift = 0;
if (GVAR(ammoTemperatureEnabled)) then {
2015-08-06 08:58:07 +00:00
_temperature = ((getPosASL _unit) select 2) call EFUNC(weather,calculateTemperatureAtHeight);
_ammoTemperatureVelocityShift = ([_ammoTempMuzzleVelocityShifts, _temperature] call FUNC(calculateAmmoTemperatureVelocityShift));
2015-04-05 19:08:55 +00:00
};
2015-08-06 08:58:07 +00:00
if (GVAR(ammoTemperatureEnabled) || GVAR(barrelLengthInfluenceEnabled)) then {
_muzzleVelocityShift = _barrelVelocityShift + _ammoTemperatureVelocityShift;
TRACE_4("shift",_muzzleVelocity,_muzzleVelocityShift, _barrelVelocityShift, _ammoTemperatureVelocityShift);
2015-08-06 08:58:07 +00:00
if (_muzzleVelocityShift != 0) then {
_muzzleVelocity = _muzzleVelocity + _muzzleVelocityShift;
2015-08-06 08:58:07 +00:00
_bulletVelocity = _bulletVelocity vectorAdd ((vectorNormalized _bulletVelocity) vectorMultiply (_muzzleVelocityShift));
_bullet setVelocity _bulletVelocity;
};
};
2015-08-06 11:35:55 +00:00
2015-04-05 19:08:55 +00:00
_bulletTraceVisible = false;
2015-04-25 11:15:54 +00:00
if (GVAR(bulletTraceEnabled) && cameraView == "GUNNER") then {
if (currentWeapon ACE_player in ["ACE_Vector", "Binocular", "Rangefinder", "Laserdesignator"]) then {
_bulletTraceVisible = true;
} else {
if (currentWeapon ACE_player == primaryWeapon ACE_player && count primaryWeaponItems ACE_player > 2) then {
_opticsName = (primaryWeaponItems ACE_player) select 2;
2015-05-08 15:20:56 +00:00
_opticType = getNumber(configFile >> "CfgWeapons" >> _opticsName >> "ItemInfo" >> "opticType");
2015-04-25 11:15:54 +00:00
_bulletTraceVisible = _opticType == 2;
};
};
2015-04-05 19:08:55 +00:00
};
_stabilityFactor = 1.5;
if (_caliber > 0 && _bulletLength > 0 && _bulletMass > 0 && _barrelTwist > 0) then {
2015-08-06 08:58:07 +00:00
if (isNil "_temperature") then {
_temperature = ((getPosASL _unit) select 2) call EFUNC(weather,calculateTemperatureAtHeight);
};
_barometricPressure = ((getPosASL _bullet) select 2) call EFUNC(weather,calculateBarometricPressure);
2015-04-07 19:27:04 +00:00
_stabilityFactor = [_caliber, _bulletLength, _bulletMass, _barrelTwist, _muzzleVelocity, _temperature, _barometricPressure] call FUNC(calculateStabilityFactor);
2015-04-05 19:08:55 +00:00
};
GVAR(currentbulletID) = (GVAR(currentbulletID) + 1) % 10000;
2015-08-05 08:28:02 +00:00
_aceTimeSecond = floor ACE_time;
"ace_advanced_ballistics" callExtension format["new:%1:%2:%3:%4:%5:%6:%7:%8:%9:%10:%11:%12:%13:%14:%15:%16:%17:%18", GVAR(currentbulletID), _airFriction, _ballisticCoefficients, _velocityBoundaries, _atmosphereModel, _dragModel, _stabilityFactor, _twistDirection, _muzzleVelocity, _transonicStabilityCoef, getPosASL _bullet, EGVAR(common,mapLatitude), EGVAR(weather,currentTemperature), EGVAR(common,mapAltitude), EGVAR(weather,currentHumidity), overcast, _aceTimeSecond, ACE_time - _aceTimeSecond];
2015-08-16 17:49:47 +00:00
GVAR(allBullets) pushBack [_bullet, _caliber, _bulletTraceVisible, GVAR(currentbulletID)];
2015-08-16 17:49:47 +00:00
if (isNil QGVAR(BulletPFH)) then {
GVAR(BulletPFH) = [FUNC(handleFirePFH), GVAR(simulationInterval), []] call CBA_fnc_addPerFrameHandler;
};