diff --git a/addons/laserpointer/functions/fnc_onDraw.sqf b/addons/laserpointer/functions/fnc_onDraw.sqf index 06c601869c..4c614064e7 100644 --- a/addons/laserpointer/functions/fnc_onDraw.sqf +++ b/addons/laserpointer/functions/fnc_onDraw.sqf @@ -15,8 +15,7 @@ */ #include "script_component.hpp" -// no lasers in thermal mode -if !(GVAR(isTI)) then { +if (count GVAR(redLaserUnits) + count GVAR(greenLaserUnits) > 0 && {!GVAR(isTI)}) then { private _brightness = 2 - call EFUNC(common,ambientBrightness); { diff --git a/addons/medical_ai/functions/fnc_isInjured.sqf b/addons/medical_ai/functions/fnc_isInjured.sqf index b4bece59d4..e91802f912 100644 --- a/addons/medical_ai/functions/fnc_isInjured.sqf +++ b/addons/medical_ai/functions/fnc_isInjured.sqf @@ -17,9 +17,4 @@ if !(alive _this) exitWith {false}; -private _bloodLoss = [_this] call EFUNC(medical,getBloodLoss); -private _pain = _this getVariable [QEGVAR(medical,pain), 0]; -private _unconscious = _this getVariable ["ACE_isUnconscious", false]; -// private _heartRate = _this getVariable [QEGVAR(medical,heartRate), 70]; - -(_bloodLoss > 0) || {_pain > 0.2} || _unconscious // || {_heartRate > 100} || {_heartRate < 40} +((_this getVariable [QEGVAR(medical,pain), 0] > 0.2) || {[_this] call EFUNC(medical,getBloodLoss) > 0 || {_this getVariable ["ACE_isUnconscious", false]}}) diff --git a/addons/overheating/functions/fnc_firedEH.sqf b/addons/overheating/functions/fnc_firedEH.sqf index c6e4abde6a..e9bf89eef7 100644 --- a/addons/overheating/functions/fnc_firedEH.sqf +++ b/addons/overheating/functions/fnc_firedEH.sqf @@ -20,76 +20,68 @@ TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectil BEGIN_COUNTER(firedEH); -if ((_unit distance ACE_player) > 3000 //Ignore far away shots +if ((_unit distance ACE_player) > 3000 || {(_muzzle != (primaryWeapon _unit)) && {_muzzle != (handgunWeapon _unit)}}) exitWith { // Only rifle or pistol muzzles (ignore grenades / GLs) END_COUNTER(firedEH); }; -// Compute new temperature if the unit is the local player -if (_unit == ACE_player) then { - _this call FUNC(overheat); -}; - // Get current temperature from the unit variable private _temperature = _unit getVariable [format [QGVAR(%1_temp), _weapon], 0]; private _scaledTemperature = linearConversion [0, 1000, _temperature, 0, 1, true]; TRACE_2("Unit fired with temp:",_unit,_temperature); -//Get weapon data from cache: +// Get weapon data from cache: ([_weapon] call FUNC(getWeaponData)) params ["_dispersion", "_slowdownFactor", "_jamChance"]; TRACE_4("weapon data from cache",_weapon,_dispersion,_slowdownFactor,_jamChance); -// Dispersion and bullet slow down -if (GVAR(overheatingDispersion) && _scaledTemperature > 0.1) then { - // Exit if GVAR(pseudoRandomList) isn't synced yet - if (isNil QGVAR(pseudoRandomList)) exitWith {ERROR("No pseudoRandomList sync");}; +if (_scaledTemperature > 0.1) then { + // Dispersion and bullet slow down + if (GVAR(overheatingDispersion)) then { + if (isNil QGVAR(pseudoRandomList)) exitWith {ERROR("No pseudoRandomList sync");}; - //Dispersion: 0 mils @ 0°C, 0.5 mils @ 333°C, 2.2 mils @ 666°C, 5 mils at 1000°C - _dispersion = _dispersion * 0.28125 * (_scaledTemperature^2); + //Dispersion: 0 mils @ 0°C, 0.5 mils @ 333°C, 2.2 mils @ 666°C, 5 mils at 1000°C + _dispersion = _dispersion * 0.28125 * (_scaledTemperature^2); - _slowdownFactor = _slowdownFactor * linearConversion [0.666, 1, _scaledTemperature, 0, -0.1, true]; + _slowdownFactor = _slowdownFactor * linearConversion [0.666, 1, _scaledTemperature, 0, -0.1, true]; - // Get the pseudo random values for dispersion from the remaining ammo count - (GVAR(pseudoRandomList) select ((_unit ammo _weapon) mod (count GVAR(pseudoRandomList)))) params ["_dispersionX", "_dispersionY"]; + // Get the pseudo random values for dispersion from the remaining ammo count + (GVAR(pseudoRandomList) select ((_unit ammo _weapon) mod (count GVAR(pseudoRandomList)))) params ["_dispersionX", "_dispersionY"]; - TRACE_4("change",_dispersion,_slowdownFactor,_dispersionX,_dispersionY); + TRACE_4("change",_dispersion,_slowdownFactor,_dispersionX,_dispersionY); - TRACE_PROJECTILE_INFO(_projectile); - [_projectile, _dispersionX * _dispersion, _dispersionY * _dispersion, _slowdownFactor * vectorMagnitude (velocity _projectile)] call EFUNC(common,changeProjectileDirection); - TRACE_PROJECTILE_INFO(_projectile); -}; - - -// ------ LOCAL AND NEARBY PLAYERS DEPENDING ON SETTINGS ------------ -// Particle effects only apply to the local player and, depending on settings, to other nearby players -if (_unit != ACE_player && (!GVAR(showParticleEffectsForEveryone) || {_unit distance ACE_player > 20})) exitWith { - END_COUNTER(firedEH); -}; - -//Particle Effects: -if (GVAR(showParticleEffects) && _scaledTemperature > 0.1 && {CBA_missionTime > (_unit getVariable [QGVAR(lastDrop), -1000]) + 0.40}) then { - _unit setVariable [QGVAR(lastDrop), CBA_missionTime]; - - private _direction = (_unit weaponDirection _weapon) vectorMultiply 0.25; - private _position = (position _projectile) vectorAdd (_direction vectorMultiply (4*(random 0.30))); - - // Refract SFX, beginning at temp 100°C and maxs out at 500°C - private _intensity = linearConversion [0.1, 0.5, _scaledTemperature, 0, 1, true]; - TRACE_3("refract",_direction,_position,_intensity); - if (_intensity > 0) then { - drop [ - "\A3\data_f\ParticleEffects\Universal\Refract", "", "Billboard", 10, 2, _position, _direction, 0, 1.2, 1.0, - 0.1, [0.10,0.25], [[0.6,0.6,0.6,0.3 * _intensity],[0.2,0.2,0.2,0.05 * _intensity]], [0,1], 0.1, 0.05, "", "", ""]; + TRACE_PROJECTILE_INFO(_projectile); + [_projectile, _dispersionX * _dispersion, _dispersionY * _dispersion, _slowdownFactor * vectorMagnitude (velocity _projectile)] call EFUNC(common,changeProjectileDirection); + TRACE_PROJECTILE_INFO(_projectile); }; - // Smoke SFX, beginning at temp 150°C - private _intensity = linearConversion [0.15, 1, _scaledTemperature, 0, 1, true]; - TRACE_3("smoke",_direction,_position,_intensity); - if (_intensity > 0) then { - drop [ - ["\A3\data_f\ParticleEffects\Universal\Universal", 16, 12, 1, 16], "", "Billboard", 10, 1.2, _position, - [0,0,0.15], 100 + random 80, 1.275, 1, 0.025, [0.15,0.43], [[0.6,0.6,0.6,0.5 * _intensity],[0.2,0.2,0.2,0.15 * _intensity]], - [0,1], 1, 0.04, "", "", ""]; + + // Particle Effects + if (GVAR(showParticleEffects) + && {GVAR(showParticleEffectsForEveryone) || {_unit == ACE_player} || {_unit distance ACE_player <= 20}} + && {CBA_missionTime > (_unit getVariable [QGVAR(lastDrop), -1000]) + 0.40}) then { + + _unit setVariable [QGVAR(lastDrop), CBA_missionTime]; + + private _direction = (_unit weaponDirection _weapon) vectorMultiply 0.25; + private _position = (position _projectile) vectorAdd (_direction vectorMultiply (4*(random 0.30))); + + // Refract SFX, beginning at temp 100°C and maxs out at 500°C + private _intensity = linearConversion [0.1, 0.5, _scaledTemperature, 0, 1, true]; + TRACE_3("refract",_direction,_position,_intensity); + if (_intensity > 0) then { + drop [ + "\A3\data_f\ParticleEffects\Universal\Refract", "", "Billboard", 10, 2, _position, _direction, 0, 1.2, 1.0, + 0.1, [0.10,0.25], [[0.6,0.6,0.6,0.3 * _intensity],[0.2,0.2,0.2,0.05 * _intensity]], [0,1], 0.1, 0.05, "", "", ""]; + }; + // Smoke SFX, beginning at temp 150°C + private _intensity = linearConversion [0.15, 1, _scaledTemperature, 0, 1, true]; + TRACE_3("smoke",_direction,_position,_intensity); + if (_intensity > 0) then { + drop [ + ["\A3\data_f\ParticleEffects\Universal\Universal", 16, 12, 1, 16], "", "Billboard", 10, 1.2, _position, + [0,0,0.15], 100 + random 80, 1.275, 1, 0.025, [0.15,0.43], [[0.6,0.6,0.6,0.5 * _intensity],[0.2,0.2,0.2,0.15 * _intensity]], + [0,1], 1, 0.04, "", "", ""]; + }; }; }; @@ -97,20 +89,34 @@ if (GVAR(showParticleEffects) && _scaledTemperature > 0.1 && {CBA_missionTime > // Only compute jamming for the local player if (_unit != ACE_player) exitWith {END_COUNTER(firedEH);}; -_jamChance = _jamChance * ([[0.5, 1, 2, 8, 20, 150], 5 * _scaledTemperature] call EFUNC(common,interpolateFromArray)); +// Compute new temperature once every 3 bullets +if ((_unit ammo _weapon) % 3 == 0) then { + _this call FUNC(overheat); +}; -// increase jam chance on dusty grounds if prone (and at ground level) -if ((stance _unit == "PRONE") && {((getPosATL _unit) select 2) < 1}) then { - private _surface = configFile >> "CfgSurfaces" >> ((surfaceType getPosASL _unit) select [1]); - if (isClass _surface) then { - TRACE_1("dust",getNumber (_surface >> "dust")); - _jamChance = _jamChance + (getNumber (_surface >> "dust")) * _jamChance; +private _value = 5 * _scaledTemperature; +private _array = [0.5, 1, 2, 8, 20, 150]; +_jamChance = _jamChance * linearConversion [0, 1, _value % 1, _array select floor _value, _array select ceil _value]; + +TRACE_3("check for random jam",_unit,_weapon,_jamChance); + +private _randomNumber = random 1; + +// Fail early if we know that we won't have a malfunction regardless of the ground type. +if (_randomNumber < _jamChance * 2) then { + if (_randomNumber > _jamChance) then { + // Increase jam chance on dusty grounds if prone (and at ground level) + if ((stance _unit == "PRONE") && {((getPosATL _unit) select 2) < 1}) then { + private _surface = configFile >> "CfgSurfaces" >> ((surfaceType getPosASL _unit) select [1]); + if (isClass _surface) then { + TRACE_1("dust",getNumber (_surface >> "dust")); + _jamChance = _jamChance + (getNumber (_surface >> "dust")) * _jamChance; + }; + }; + }; + if (_randomNumber < _jamChance) then { + [_unit, _weapon] call FUNC(jamWeapon); }; }; -TRACE_3("check for random jam",_unit,_weapon,_jamChance); -if ((random 1) < _jamChance) then { - [_unit, _weapon] call FUNC(jamWeapon); -}; - END_COUNTER(firedEH); diff --git a/addons/overheating/functions/fnc_overheat.sqf b/addons/overheating/functions/fnc_overheat.sqf index c29f2d5dd1..cc30e2ad22 100644 --- a/addons/overheating/functions/fnc_overheat.sqf +++ b/addons/overheating/functions/fnc_overheat.sqf @@ -23,27 +23,25 @@ params ["_unit", "_weapon", "", "", "_ammo", "", "_projectile"]; TRACE_4("params",_unit,_weapon,_ammo,_projectile); -// Only do heat calculations every 3 bullets -if (((_unit ammo _weapon) % 3) != 0) exitWith {}; - BEGIN_COUNTER(overheat); // Get bullet parameters -private _bulletMass = GVAR(cacheAmmoData) getVariable _ammo; -if (isNil "_bulletMass") then { +private _energyIncrement = GVAR(cacheAmmoData) getVariable _ammo; +if (isNil "_energyIncrement") then { _bulletMass = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_BulletMass"); if (_bulletMass == 0) then { // If the bullet mass is not configured, estimate it _bulletMass = 3.4334 + 0.5171 * (getNumber (configFile >> "CfgAmmo" >> _ammo >> "hit") + getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber")); }; - GVAR(cacheAmmoData) setVariable [_ammo, _bulletMass]; -}; + + // Projectile motion is roughly equal to Barrel heat + // Ref: https://en.wikipedia.org/wiki/Physics_of_firearms + // Muzzle Engergy = 1/2 * m * v^2 = (1/2 * 0.001 g/kg * bulletMass (grams) * v^2) + // Multiple by 3 becase we only calc every 3rd bullet: (3 * 1/2 * 0.001) = 0.0015 + private _energyIncrement = 0.0015 * _bulletMass * (vectorMagnitudeSqr velocity _projectile); -// Projectile motion is roughly equal to Barrel heat -// Ref: https://en.wikipedia.org/wiki/Physics_of_firearms -// Muzzle Engergy = 1/2 * m * v^2 = (1/2 * 0.001 g/kg * bulletMass (grams) * v^2) -// Multiple by 3 becase we only calc every 3rd bullet: (3 * 1/2 * 0.001) = 0.0015 -private _energyIncrement = 0.0015 * _bulletMass * (vectorMagnitudeSqr velocity _projectile); + GVAR(cacheAmmoData) setVariable [_ammo, _energyIncrement]; +}; // Increase overheating depending on how obstrusive is the current supressor, // if any. Typical arma supressors have visibleFire=0.5 and audibleFire=0.3, @@ -64,7 +62,7 @@ if (_silencer != "") then { _energyIncrement = _energyIncrement * _silencerCoef; }; -TRACE_2("heat",_bulletMass,_energyIncrement); +TRACE_1("heat",_energyIncrement); [_unit, _weapon, _energyIncrement] call FUNC(updateTemperature);