ATragMX - Fixes possible divison through zero

This commit is contained in:
ulteq 2016-11-16 14:20:44 +01:00 committed by ulteq
parent dbb59c8fd1
commit cb3693f664
2 changed files with 16 additions and 8 deletions

View File

@ -37,16 +37,20 @@ private ["_lowerIndex", "_upperIndex"];
for "_index" from 1 to (_lookupTableSize - 1) do { for "_index" from 1 to (_lookupTableSize - 1) do {
_upperIndex = _index; _upperIndex = _index;
_lowerIndex = _upperIndex - 1; _lowerIndex = _upperIndex - 1;
if (((_lookupTable select _index) select 0) >= (GVAR(targetRange) select GVAR(currentTarget))) exitWith {} if (((_lookupTable select _index) select 0) >= (GVAR(targetRange) select GVAR(currentTarget))) exitWith {};
}; };
private ["_lowerDistance", "_upperDistance", "_lowerC1", "_upperC1", "_slope", "_c1"]; private ["_lowerDistance", "_upperDistance", "_lowerC1", "_upperC1", "_c1"];
_lowerDistance = (_lookupTable select _lowerIndex) select 0; _lowerDistance = (_lookupTable select _lowerIndex) select 0;
_upperDistance = (_lookupTable select _upperIndex) select 0; _upperDistance = (_lookupTable select _upperIndex) select 0;
_lowerC1 = (_lookupTable select _lowerIndex) select 1; _lowerC1 = (_lookupTable select _lowerIndex) select 1;
_upperC1 = (_lookupTable select _upperIndex) select 1; _upperC1 = (_lookupTable select _upperIndex) select 1;
_slope = (_upperC1 - _lowerC1) / (_upperDistance - _lowerDistance); _c1 = _lowerC1;
_c1 = 0.1 max (_lowerC1 + ((GVAR(targetRange) select GVAR(currentTarget)) - _lowerDistance) * _slope) min 2.0; if (_lowerDistance != _upperDistance) then {
private _slope = (_upperC1 - _lowerC1) / (_upperDistance - _lowerDistance);
_c1 = _lowerC1 + ((GVAR(targetRange) select GVAR(currentTarget)) - _lowerDistance) * _slope;
};
_c1 = 0.1 max _c1 min 2.0;
if (_c1 != GVAR(workingMemory) select 15) then { if (_c1 != GVAR(workingMemory) select 15) then {
GVAR(workingMemory) set [15, _c1]; GVAR(workingMemory) set [15, _c1];

View File

@ -37,16 +37,20 @@ private ["_lowerIndex", "_upperIndex"];
for "_index" from 1 to (_lookupTableSize - 1) do { for "_index" from 1 to (_lookupTableSize - 1) do {
_upperIndex = _index; _upperIndex = _index;
_lowerIndex = _upperIndex - 1; _lowerIndex = _upperIndex - 1;
if (((_lookupTable select _index) select 0) >= GVAR(temperature)) exitWith {} if (((_lookupTable select _index) select 0) >= GVAR(temperature)) exitWith {};
}; };
private ["_lowerTemperature", "_upperTemperature", "_lowerMuzzleVelocity", "_upperMuzzleVelocity", "_slope", "_muzzleVelocity"]; private ["_lowerTemperature", "_upperTemperature", "_lowerMuzzleVelocity", "_upperMuzzleVelocity", "_muzzleVelocity"];
_lowerTemperature = (_lookupTable select _lowerIndex) select 0; _lowerTemperature = (_lookupTable select _lowerIndex) select 0;
_upperTemperature = (_lookupTable select _upperIndex) select 0; _upperTemperature = (_lookupTable select _upperIndex) select 0;
_lowerMuzzleVelocity = (_lookupTable select _lowerIndex) select 1; _lowerMuzzleVelocity = (_lookupTable select _lowerIndex) select 1;
_upperMuzzleVelocity = (_lookupTable select _upperIndex) select 1; _upperMuzzleVelocity = (_lookupTable select _upperIndex) select 1;
_slope = (_upperMuzzleVelocity - _lowerMuzzleVelocity) / (_upperTemperature - _lowerTemperature); _muzzleVelocity = _lowerMuzzleVelocity;
if (_lowerTemperature != _upperTemperature) then {
private _slope = (_upperMuzzleVelocity - _lowerMuzzleVelocity) / (_upperTemperature - _lowerTemperature);
_muzzleVelocity = _lowerMuzzleVelocity + (GVAR(temperature) - _lowerTemperature) * _slope; _muzzleVelocity = _lowerMuzzleVelocity + (GVAR(temperature) - _lowerTemperature) * _slope;
};
_muzzleVelocity = 100 max _muzzleVelocity min 1400;
if (_muzzleVelocity != GVAR(workingMemory) select 1) then { if (_muzzleVelocity != GVAR(workingMemory) select 1) then {
GVAR(workingMemory) set [1, _muzzleVelocity]; GVAR(workingMemory) set [1, _muzzleVelocity];