Simplified muzzle velocity shift calculation:

*Also added some missing privates
This commit is contained in:
ulteq 2015-04-25 12:36:04 +02:00
parent d414e5a3a1
commit 2d14ae61f9

View File

@ -19,7 +19,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_weapon", "_mode", "_ammo", "_magazine", "_caliber", "_bullet", "_abort", "_index", "_opticsName", "_opticType", "_bulletTraceVisible", "_temperature", "_barometricPressure", "_atmosphereModel", "_bulletMass", "_bulletLength", "_airFriction", "_dragModel", "_muzzleVelocity", "_muzzleVelocityCoef", "_muzzleAccessory", "_initSpeedCoef", "_muzzleVelocityShift", "_bulletVelocity", "_bulletSpeed", "_bulletLength", "_barrelTwist", "_twistDirection", "_stabilityFactor", "_transonicStabilityCoef"]; private ["_unit", "_weapon", "_mode", "_ammo", "_magazine", "_caliber", "_bullet", "_abort", "_index", "_opticsName", "_opticType", "_bulletTraceVisible", "_temperature", "_barometricPressure", "_atmosphereModel", "_bulletMass", "_bulletLength", "_airFriction", "_dragModel", "_muzzleVelocity", "_muzzleVelocityShift", "_bulletVelocity", "_bulletSpeed", "_bulletLength", "_barrelTwist", "_twistDirection", "_stabilityFactor", "_transonicStabilityCoef", "_ballisticCoefficients", "_velocityBoundaries"];
_unit = _this select 0; _unit = _this select 0;
_weapon = _this select 1; _weapon = _this select 1;
_mode = _this select 3; _mode = _this select 3;
@ -52,32 +52,14 @@ if (_abort || !(GVAR(extensionAvailable))) exitWith {
}; };
_airFriction = getNumber(configFile >> "cfgAmmo" >> _ammo >> "airFriction"); _airFriction = getNumber(configFile >> "cfgAmmo" >> _ammo >> "airFriction");
_muzzleVelocity = getNumber(configFile >> "cfgMagazines" >> _magazine >> "initSpeed");
_muzzleVelocityCoef = getNumber(configFile >> "cfgWeapons" >> _weapon >> "initSpeed");
if (_muzzleVelocityCoef > 0) then {
_muzzleVelocity = _muzzleVelocityCoef;
};
if (_muzzleVelocityCoef < 0) then {
_muzzleVelocity = _muzzleVelocity * (-1 * _muzzleVelocityCoef);
};
_muzzleAccessory = ""; _bulletVelocity = velocity _bullet;
switch (currentWeapon _unit) do { _muzzleVelocity = vectorMagnitude _bulletVelocity;
case primaryWeapon _unit: { _muzzleAccessory = (primaryWeaponItems _unit) select 0; };
case handgunWeapon _unit: { _muzzleAccessory = (handgunItems _unit) select 0; };
};
if (_muzzleAccessory != "" && isNumber(configFile >> "cfgWeapons" >> _muzzleAccessory >> "ItemInfo" >> "MagazineCoef" >> "initSpeed")) then {
_initSpeedCoef = getNumber(configFile >> "cfgWeapons" >> _muzzleAccessory >> "ItemInfo" >> "MagazineCoef" >> "initSpeed");
_muzzleVelocity = _muzzleVelocity * _initSpeedCoef;
};
if (GVAR(barrelLengthInfluenceEnabled)) then { if (GVAR(barrelLengthInfluenceEnabled)) then {
_muzzleVelocityShift = [_ammo, _weapon, _muzzleVelocity] call FUNC(calculateBarrelLengthVelocityShift); _muzzleVelocityShift = [_ammo, _weapon, _muzzleVelocity] call FUNC(calculateBarrelLengthVelocityShift);
if (_muzzleVelocityShift != 0) then { if (_muzzleVelocityShift != 0) then {
_bulletVelocity = velocity _bullet; _bulletVelocity = _bulletVelocity vectorAdd ((vectorNormalized _bulletVelocity) vectorMultiply (_muzzleVelocityShift));
_bulletSpeed = vectorMagnitude _bulletVelocity;
_bulletVelocity = _bulletVelocity vectorAdd ((vectorNormalized _bulletVelocity) vectorMultiply (_muzzleVelocityShift * (_bulletSpeed / _muzzleVelocity)));
_bullet setVelocity _bulletVelocity; _bullet setVelocity _bulletVelocity;
_muzzleVelocity = _muzzleVelocity + _muzzleVelocityShift; _muzzleVelocity = _muzzleVelocity + _muzzleVelocityShift;
}; };
@ -87,9 +69,7 @@ if (GVAR(ammoTemperatureEnabled)) then {
_temperature = GET_TEMPERATURE_AT_HEIGHT((getPosASL _unit) select 2); _temperature = GET_TEMPERATURE_AT_HEIGHT((getPosASL _unit) select 2);
_muzzleVelocityShift = [_ammo, _temperature] call FUNC(calculateAmmoTemperatureVelocityShift); _muzzleVelocityShift = [_ammo, _temperature] call FUNC(calculateAmmoTemperatureVelocityShift);
if (_muzzleVelocityShift != 0) then { if (_muzzleVelocityShift != 0) then {
_bulletVelocity = velocity _bullet; _bulletVelocity = _bulletVelocity vectorAdd ((vectorNormalized _bulletVelocity) vectorMultiply (_muzzleVelocityShift));
_bulletSpeed = vectorMagnitude _bulletVelocity;
_bulletVelocity = _bulletVelocity vectorAdd ((vectorNormalized _bulletVelocity) vectorMultiply (_muzzleVelocityShift * (_bulletSpeed / _muzzleVelocity)));
_bullet setVelocity _bulletVelocity; _bullet setVelocity _bulletVelocity;
_muzzleVelocity = _muzzleVelocity + _muzzleVelocityShift; _muzzleVelocity = _muzzleVelocity + _muzzleVelocityShift;
}; };