ACE3/addons/overheating/functions/fnc_jamWeapon.sqf
Drofseh 99c85e3c12
Overheating - Fix issues from release (#8617)
* move overheating cookoff into separate function

* move heatCoef and require mission restart for setting change

- move heatCoef to a more sensible place
- require mission restart for heatCoef setting change (it gets cached per ammo type)

* add exit to ammo temp loop if cookoffCoef is changed to 0 mid-mission

- add exit to ammo temp loop if cookoffCoef is changed to 0 mid-mission, this prevents an issue where all weapon cookoff regardless of temp, because required temp gets multiplied by cookoffCoef which has been set to 0.

* file end new line

* update header for ace_overheating_fnc_cookoffWeapon

* use ambientTemperature as floor for weapon and ammo temp

* add coolingCoef setting

* improve feature documentation

* add fnc_cookoffWeapon to XEH_PREP

* add type of jam to ace_weaponJammed local event

- add type of jam to ace_weaponJammed local event
- fix #8637

* fix misspelling

Co-authored-by: TyroneMF <TyroneMF@hotmail.com>

* clear all weapon heat on death

* Update addons/overheating/functions/fnc_updateTemperature.sqf

Co-authored-by: GhostIsSpooky <69561145+Salluci@users.noreply.github.com>

* deprecate ace_overheating_fnc_getBarrelMass, cache weapon bolt and barrel mass values

- cache closed bolt value by moving config look up to ace_overheating_fnc_getWeaponData
- cache barrel mass value by moving calculation from ace_overheating_fnc_getBarrelMass to ace_overheating_fnc_getWeaponData
- deprecate ace_overheating_fnc_getBarrelMass to be a wrapper for ace_overheating_fnc_getWeaponData that only returns barrel mass

* add public functions to get and set weapon and ammo temperature

* add `canCoolWeaponWithItem` function, workaround for #8657

* Apply suggestions from code review

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* add coef setting for addition heat from suppressor

* Update fnc_overheat.sqf

* improve fnc_canCoolWeaponWithItem

* remove extra (

* Move canCoolWeaponWithItem action code to function

* Use hashmaps and reset on settings change

* Apply suggestions from code review

Co-authored-by: jonpas <jonpas33@gmail.com>

Co-authored-by: TyroneMF <TyroneMF@hotmail.com>
Co-authored-by: GhostIsSpooky <69561145+Salluci@users.noreply.github.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
Co-authored-by: jonpas <jonpas33@gmail.com>
2021-11-08 12:06:31 -06:00

113 lines
4.2 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: Commy2, based on KK_fnc_playerWeaponMulfunction from KillzoneKid
* Jam the weapon
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
*
* Return Value:
* None
*
* Example:
* [player, currentWeapon player] call ace_overheating_fnc_jamWeapon
*
* Public: No
*/
params ["_unit", "_weapon"];
TRACE_2("params",_unit,_weapon);
// don't jam a weapon with no rounds left
private _ammo = _unit ammo _weapon;
if (_ammo < 1) exitWith {};
private _jammedWeapons = _unit getVariable [QGVAR(jammedWeapons), []];
_jammedWeapons pushBack _weapon;
_unit setVariable [QGVAR(jammedWeapons), _jammedWeapons];
// Get jam types, select one from available types
// Cookoffs only happen on Fire and Dud, dud rounds are lost on jam clear.
// Reduce chance of duds as temp increases (functionally increasing the chance of the others but with fewer commands)
private _temp = 1 max (_unit getVariable [format [QGVAR(%1_temp), _weapon], 0]);
private _jamTypesAllowed = getArray (configFile >> 'CfgWeapons' >> currentWeapon _unit >> QGVAR(jamTypesAllowed));
if (_jamTypesAllowed isEqualTo []) then {
_jamTypesAllowed = ["Eject", 1, "Extract", 1, "Feed", 1, "Fire", 1, "Dud", (5 / (_temp / 5))];
} else {
for "_i" from count _jamTypesAllowed to 1 step -1 do {
private _jamCurretType = _jamTypesAllowed select _i;
if !(_jamCurretType in ["Eject", "Extract", "Feed", "Fire", "Dud"]) exitWith { // check config values and switch to default values if unusual value found
ERROR_2("Weapon '%1' has unexpected value %2 in QQGVAR(jamTypesAllowed). Expected values are 'Eject', 'Extract', 'Feed', 'Fire', 'Dud'.",_weapon,_jamCurretType);
_jamTypesAllowed = ["Eject", 1, "Extract", 1, "Feed", 1, "Fire", 1, "Dud", (5 / (_temp / 5))];
};
if (_jamCurretType == "Dud") then {
_jamTypesAllowed insert [_i, [5 / (_temp / 5)]];
} else {
_jamTypesAllowed insert [_i, [1]];
};
};
};
private _jamType = selectRandomWeighted _jamTypesAllowed;
_unit setVariable [format [QGVAR(%1_jamType), _weapon], _jamType];
// Stop current burst
_unit setAmmo [_weapon, 0];
// this is to re-activate the 'DefaultAction', so you can jam a weapon while full auto shooting
[{
params ["_unit", "_weapon", "_ammo"];
_unit setAmmo [_weapon, _ammo];
}, [_unit, _weapon, _ammo]] call CBA_fnc_execNextFrame;
if (_weapon == primaryWeapon _unit) then {
playSound QGVAR(jamming_rifle);
} else {
if (_weapon == handgunWeapon _unit) then {
playSound QGVAR(jamming_pistol);
};
};
// only display the hint once, after you try to shoot an already jammed weapon
GVAR(knowAboutJam) = false;
["ace_weaponJammed", [_unit, _weapon, _jamType]] call CBA_fnc_localEvent;
if (_unit getVariable [QGVAR(JammingActionID), -1] == -1) then {
private _condition = {
private _unit = _this select 1;
[_unit] call CBA_fnc_canUseWeapon
&& {currentMuzzle _unit in (_unit getVariable [QGVAR(jammedWeapons), []])}
&& {!(currentMuzzle _unit in (_unit getVariable [QEGVAR(safemode,safedWeapons), []]))}
};
private _statement = {
params ["_zero","_one"];
playSound3D ["a3\sounds_f\weapons\Other\dry9.wss", _zero, false, eyePos _zero, 1, 1, 15];
if (!(missionNamespace getVariable [QGVAR(knowAboutJam), false]) && {_one ammo currentWeapon _one > 0} && {GVAR(DisplayTextOnJam)}) then {
private _jamType = _one getVariable [format [QGVAR(%1_jamType), currentWeapon _one], "None"];
private _jamMessage = localize LSTRING(FailureToFire);
switch true do {
case (_jamType isEqualTo "Eject"): {_jamMessage = localize LSTRING(FailureToEject)};
case (_jamType isEqualTo "Extract"): {_jamMessage = localize LSTRING(FailureToExtract)};
case (_jamType isEqualTo "Feed"): {_jamMessage = localize LSTRING(FailureToFeed)};
};
[
[localize LSTRING(WeaponJammed)],
[_jamMessage]
] call CBA_fnc_notify;
GVAR(knowAboutJam) = true;
};
};
private _id = [_unit, "DefaultAction", _condition, _statement] call EFUNC(common,addActionEventHandler);
_unit setVariable [QGVAR(JammingActionID), _id];
};