From e9505523451810d3edd100d5d473a2f4e2cd8bfa Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 27 Feb 2016 00:29:30 -0300 Subject: [PATCH 01/15] Track temperatures of spare barrels --- addons/overheating/CfgMagazines.hpp | 11 ++++ addons/overheating/CfgVehicles.hpp | 5 +- addons/overheating/CfgWeapons.hpp | 11 ---- addons/overheating/XEH_PREP.hpp | 2 + addons/overheating/XEH_postInit.sqf | 40 +++++++++++++ addons/overheating/config.cpp | 2 + .../functions/fnc_calculateCooling.sqf | 58 +++++++++++++++++++ .../functions/fnc_swapBarrelCallback.sqf | 12 +++- ...c_updateSpareBarrelsTemperaturesThread.sqf | 40 +++++++++++++ .../functions/fnc_updateTemperature.sqf | 44 +------------- 10 files changed, 167 insertions(+), 58 deletions(-) create mode 100644 addons/overheating/CfgMagazines.hpp create mode 100644 addons/overheating/functions/fnc_calculateCooling.sqf create mode 100644 addons/overheating/functions/fnc_updateSpareBarrelsTemperaturesThread.sqf diff --git a/addons/overheating/CfgMagazines.hpp b/addons/overheating/CfgMagazines.hpp new file mode 100644 index 0000000000..ad381ff30e --- /dev/null +++ b/addons/overheating/CfgMagazines.hpp @@ -0,0 +1,11 @@ +class CfgMagazines { + class CA_Magazine; + class ACE_SpareBarrel: CA_Magazine { + descriptionshort = CSTRING(SpareBarrelDescription); + picture = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); + displayName = "ACE Spare Barrel"; //!!!CANNOT be localized!!!: because it is used as part of the magazineDetail string + count = 1; + mass = 40; + ACE_isUnique = 1; + }; +}; diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index c7d9c6790a..4911fcb7f6 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -15,7 +15,7 @@ class CfgVehicles { }; class ACE_SwapBarrel { displayName = CSTRING(SwapBarrel); - condition = QUOTE( 'ACE_SpareBarrel' in items _player && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _player >> 'ACE_Overheating_allowSwapBarrel') == 1} ); + condition = QUOTE( 'ACE_SpareBarrel' in magazines _player && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _player >> 'ACE_Overheating_allowSwapBarrel') == 1} ); statement = QUOTE( [ARR_2(_player, currentWeapon _player)] call FUNC(swapBarrel); ); showDisabled = 0; priority = 3; @@ -99,7 +99,7 @@ class CfgVehicles { MACRO_ADDITEM(ACE_SpareBarrel,6); }; }; - +/* // Add ACE_SpareBarrel to every machine gunner. #define MACRO_ADDSPAREBARREL \ items[] = {"FirstAidKit", "ACE_SpareBarrel"}; \ @@ -124,4 +124,5 @@ class CfgVehicles { // Czech class I_Soldier_02_F; class I_Soldier_AR_F:I_Soldier_02_F {MACRO_ADDSPAREBARREL}; class I_Soldier_support_base_F; class I_Soldier_AAR_F:I_Soldier_support_base_F {MACRO_ADDSPAREBARREL}; +*/ }; diff --git a/addons/overheating/CfgWeapons.hpp b/addons/overheating/CfgWeapons.hpp index f59c4d7911..c7a83eec6e 100644 --- a/addons/overheating/CfgWeapons.hpp +++ b/addons/overheating/CfgWeapons.hpp @@ -2,17 +2,6 @@ class CfgWeapons { class ACE_ItemCore; class InventoryItem_Base_F; - class ACE_SpareBarrel: ACE_ItemCore { - displayname = CSTRING(SpareBarrelName); - descriptionshort = CSTRING(SpareBarrelDescription); - //model = ""; - picture = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); - scope = 2; - class ItemInfo: InventoryItem_Base_F { - mass = 30; - }; - }; - class RifleCore; class Rifle: RifleCore { //Mean Rounds Between Stoppages (this will be scaled based on the barrel temp) diff --git a/addons/overheating/XEH_PREP.hpp b/addons/overheating/XEH_PREP.hpp index 312b8bb0c5..26366b9896 100644 --- a/addons/overheating/XEH_PREP.hpp +++ b/addons/overheating/XEH_PREP.hpp @@ -1,4 +1,5 @@ +PREP(calculateCooling); PREP(canUnjam); PREP(checkTemperature); PREP(clearJam); @@ -10,5 +11,6 @@ PREP(jamWeapon); PREP(overheat); PREP(swapBarrel); PREP(swapBarrelCallback); +PREP(updateSpareBarrelsTemperaturesThread); PREP(updateTemperature); PREP(updateTemperatureThread); diff --git a/addons/overheating/XEH_postInit.sqf b/addons/overheating/XEH_postInit.sqf index 0bb2da22ca..b19b96272d 100644 --- a/addons/overheating/XEH_postInit.sqf +++ b/addons/overheating/XEH_postInit.sqf @@ -8,6 +8,46 @@ if (isServer) then { GVAR(pseudoRandomList) pushBack [-1 + random 2, -1 + random 2]; }; publicVariable QGVAR(pseudoRandomList); + + // Keep track of the temperature of stored spare barrels + GVAR(storedSpareBarrels) = [] call CBA_fnc_hashCreate; + ["spareBarrelLoadedCoolest", { + params ["_unit", "_weapon", "_weaponTemp", "_barrelMass"]; + TRACE_4("spareBarrelLoadedCoolest1",_unit,_weapon,_weaponTemp,_barrelMass); + + // Find all spare barrel the player has + private _allMags = magazinesDetail _unit; + TRACE_1("spareBarrelLoadedCoolest2",_allMags); + _allMags = _allMags select {_x find "ACE Spare Barrel" == 0}; + TRACE_1("spareBarrelLoadedCoolest3",_allMags); + if ((count _allMags) < 1) exitWith {}; + + // Determine which on is coolest + private _coolestTemp = 10000; + private _coolestMag = _allMags select 0; + { + private _temp = 0; + if ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashHasKey) then { + _temp = ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashGet) select 0; + }; + TRACE_2("spareBarrelLoadedCoolest4",_x,_temp); + if (_temp < _coolestTemp) then { + _coolestTemp = _temp; + _coolestMag = _x; + }; + } forEach _allMags; + TRACE_3("spareBarrelLoadedCoolest5",_coolestTemp,_coolestMag,_weaponTemp); + + // The new weapon temperature is similar to the coolest barrel + // Publish the new temperature value + _unit setVariable [format [QGVAR(%1_temp), _weapon], _coolestTemp, true]; + + // Heat up the coolest barrel to the former weapon temperature + [GVAR(storedSpareBarrels), _coolestMag, [_weaponTemp, ACE_Time, _barrelMass]] call CBA_fnc_hashSet; + }] call EFUNC(common,addEventHandler); + + // Schedule cool down calculation of stored spare barrels + [] call FUNC(updateSpareBarrelsTemperaturesThread); }; diff --git a/addons/overheating/config.cpp b/addons/overheating/config.cpp index c57e55913d..673edcf77f 100644 --- a/addons/overheating/config.cpp +++ b/addons/overheating/config.cpp @@ -18,6 +18,8 @@ class CfgPatches { #include "CfgVehicles.hpp" +#include "CfgMagazines.hpp" + #include "CfgWeapons.hpp" #include "ACE_Settings.hpp" diff --git a/addons/overheating/functions/fnc_calculateCooling.sqf b/addons/overheating/functions/fnc_calculateCooling.sqf new file mode 100644 index 0000000000..955c41441e --- /dev/null +++ b/addons/overheating/functions/fnc_calculateCooling.sqf @@ -0,0 +1,58 @@ +/* + * Author: esteldunedain + * Calculate the cooling down of a weapon over a time interval. + * + * Argument: + * 0: Initial temperature + * 1: Barrel mass + * 2: Time interval + * + * Return value: + * Final temperature + * + * Example: + * [_temperature, _barrelMass, _totalTime] call ace_overheating_fnc_calculateCooling + * + * Public: No + */ +#include "script_component.hpp" + +params ["_temperature", "_barrelMass", "_totalTime"]; + +// If a long time passed since the last shot, there's no need to calculate anything; the weapon should be cool +if (_totalTime > 1800) exitWith {0}; + +//AR-15 (0.00570m bullet diameter) (barrel diameter usually 0.75" or 0.008255m radius) +//Steel Denisty = 7850 m^3 / kg +//Area of a cylinder (2/r)*(Pi * r^3 + V) - for a 0.008255m radius barrel -> Area = 210(1/meters) * Volume +//Adjusted volume for being hollowed out is ~1.1x +//So Area = 210 * 1.1 * (mass / 7850) = mass * 0.029427 (for steel near that diameter) + +private _barrelSurface = _barrelMass * 0.029427; + +TRACE_4("cooling",_temperature,_totalTime,_barrelMass,_barrelSurface); + +private _time = 0; +while {true} do { + private _deltaTime = (_totalTime - _time) min 20; + + _temperature = _temperature - ( + // Convective cooling + 25 * _barrelSurface * _temperature + // Radiative cooling + + 0.4 * 5.67e-8 * _barrelSurface * + ( (_temperature + 273.15)*(_temperature + 273.15) + * (_temperature + 273.15)*(_temperature + 273.15) + - 273.15 * 273.15 * 273.15 *273.15 ) + ) * _deltaTime / (_barrelMass * 466); + + if (_temperature < 1) exitWith {0}; + + if (isNil "_temperature") exitWith { + diag_log text format ["[ACE] ERROR: _totalTime = %1; _time = %2; _deltaTime = %3;", _totalTime, _time, _deltaTime]; + 0 + }; + + _time = _time + _deltaTime; + if (_time >= _totalTime) exitWith { _temperature max 0 }; +}; diff --git a/addons/overheating/functions/fnc_swapBarrelCallback.sqf b/addons/overheating/functions/fnc_swapBarrelCallback.sqf index 9c62e77f21..8bd63e4874 100644 --- a/addons/overheating/functions/fnc_swapBarrelCallback.sqf +++ b/addons/overheating/functions/fnc_swapBarrelCallback.sqf @@ -14,6 +14,7 @@ * * Public: No */ +#define DEBUG_MODE_FULL #include "script_component.hpp" params ["_player", "_weapon"]; @@ -26,7 +27,14 @@ playSound "ACE_BarrelSwap"; // don't consume the barrel, but rotate through them. [localize LSTRING(SwappedBarrel), QUOTE(PATHTOF(UI\spare_barrel_ca.paa))] call EFUNC(common,displayTextPicture); -// Publish the temperature variable -_player setVariable [format [QGVAR(%1_temp), _weapon], 0, true]; +private _temp = _player getVariable [format [QGVAR(%1_temp), _weapon], 0]; +private _barrelMass = 0.50 * (getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "mass") / 22.0) max 1.0; + +// Instruct the server to load the coolest spare barrel into the weapon and +// store the removed barrel with the former weapon temperature. The server +// also updates the current weapon temperature to match that of the new +// loaded barrel. +["spareBarrelLoadedCoolest", [_player, _weapon, _temp, _barrelMass]] call EFUNC(common,serverEvent); + // Store the update time _player setVariable [format [QGVAR(%1_time), _weapon], ACE_time]; diff --git a/addons/overheating/functions/fnc_updateSpareBarrelsTemperaturesThread.sqf b/addons/overheating/functions/fnc_updateSpareBarrelsTemperaturesThread.sqf new file mode 100644 index 0000000000..852cb1c580 --- /dev/null +++ b/addons/overheating/functions/fnc_updateSpareBarrelsTemperaturesThread.sqf @@ -0,0 +1,40 @@ +/* + * Author: esteldunedain + * Calculate cooldown of all the stored spare barrels. + * + * Argument: + * None + * + * Return value: + * None + * + * Example: + * [] call ace_overheating_fnc_updateSpareBarrelsTemperaturesThread + * + * Public: No + */ +#define DEBUG_MODE_FULL +#include "script_component.hpp" + +private _pairs = []; +TRACE_1("updateSpareBarrelsTemperaturesThread1",GVAR(storedSpareBarrels)); +[GVAR(storedSpareBarrels), {_pairs pushBack [_key, _value];}] call CBA_fnc_hashEachPair; +TRACE_1("updateSpareBarrelsTemperaturesThread2",_pairs); +{ + _x params ["_barrelMagazineID","_value"]; + _value params ["_initialTemp","_initialTime", "_barrelMass"]; + + // Calculate cooling + private _finalTemp = [_initialTemp, _barrelMass, ACE_time - _initialTime] call FUNC(calculateCooling); + TRACE_4("updateSpareBarrelsTemperaturesThread3",_barrelMagazineID,_initialTemp,_finalTemp,_barrelMass); + if (_finalTemp < 5) then { + // The barrel is cool enough to keep calculating. Remove it from the hash + [GVAR(storedSpareBarrels), _barrelMagazineID] call CBA_fnc_hashRem; + } else { + // Store the new temp + [GVAR(storedSpareBarrels), _barrelMagazineID, [_finalTemp, ACE_time, _barrelMass]] call CBA_fnc_hashSet; + }; +} forEach _pairs; + +// Schedule for execution again after 10 seconds +[DFUNC(updateSpareBarrelsTemperaturesThread), [], 10] call EFUNC(common,waitAndExecute); diff --git a/addons/overheating/functions/fnc_updateTemperature.sqf b/addons/overheating/functions/fnc_updateTemperature.sqf index 89d5975024..1643fe55b4 100644 --- a/addons/overheating/functions/fnc_updateTemperature.sqf +++ b/addons/overheating/functions/fnc_updateTemperature.sqf @@ -29,50 +29,8 @@ private _lastTime = _unit getVariable [_timeVarName, 0]; private _barrelMass = 0.50 * (getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "mass") / 22.0) max 1.0; -_fnc_cooling = { - params ["_temperature", "_barrelMass", "_totalTime"]; - - // If a long time passed since the last shot, there's no need to calculate anything; the weapon should be cool - if (_totalTime > 1800) exitWith {0}; - - //AR-15 (0.00570m bullet diameter) (barrel diameter usually 0.75" or 0.008255m radius) - //Steel Denisty = 7850 m^3 / kg - //Area of a cylinder (2/r)*(Pi * r^3 + V) - for a 0.008255m radius barrel -> Area = 210(1/meters) * Volume - //Adjusted volume for being hollowed out is ~1.1x - //So Area = 210 * 1.1 * (mass / 7850) = mass * 0.029427 (for steel near that diameter) - - private _barrelSurface = _barrelMass * 0.029427; - - TRACE_4("cooling",_temperature,_totalTime,_barrelMass,_barrelSurface); - - private _time = 0; - while {true} do { - private _deltaTime = (_totalTime - _time) min 20; - - _temperature = _temperature - ( - // Convective cooling - 25 * _barrelSurface * _temperature - // Radiative cooling - + 0.4 * 5.67e-8 * _barrelSurface * - ( (_temperature + 273.15)*(_temperature + 273.15) - * (_temperature + 273.15)*(_temperature + 273.15) - - 273.15 * 273.15 * 273.15 *273.15 ) - ) * _deltaTime / (_barrelMass * 466); - - if (_temperature < 1) exitWith {0}; - - if (isNil "_temperature") exitWith { - diag_log text format ["[ACE] ERROR: _totalTime = %1; _time = %2; _deltaTime = %3;", _totalTime, _time, _deltaTime]; - 0 - }; - - _time = _time + _deltaTime; - if (_time >= _totalTime) exitWith { _temperature max 0 }; - }; -}; - // Calculate cooling -_temperature = [_temperature, _barrelMass, ACE_time - _lastTime] call _fnc_cooling; +_temperature = [_temperature, _barrelMass, ACE_time - _lastTime] call FUNC(calculateCooling); TRACE_1("cooledTo",_temperature); // Calculate heating // Steel Heat Capacity = 466 J/(Kg.K) From b8f955468cc4b255eba4d922c03d8d2e972dc66b Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 27 Feb 2016 01:46:27 -0300 Subject: [PATCH 02/15] First version of "Check spare barrel temperatures" action --- addons/overheating/CfgVehicles.hpp | 9 +++++ addons/overheating/XEH_postInit.sqf | 61 +++++++++++++++++++++++++++++ addons/overheating/stringtable.xml | 18 +++++++++ 3 files changed, 88 insertions(+) diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index 4911fcb7f6..61b619a79b 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -30,6 +30,15 @@ class CfgVehicles { priority = 2.9; icon = QUOTE(PATHTOF(UI\temp_ca.paa)); }; + class ACE_CheckTemperatureSpareBarrels { + displayName = CSTRING(CheckTemperatureSpareBarrelsShort); + condition = QUOTE( 'ACE_SpareBarrel' in magazines _player); + exceptions[] = {"isNotInside", "isNotSitting"}; + statement = QUOTE([ARR_2('spareBarrelsCheckTemperatures',[ARR_2(_player,_player)])] call EFUNC(common,serverEvent);); + showDisabled = 0; + priority = 2.8; + icon = QUOTE(PATHTOF(UI\temp_ca.paa)); + }; }; }; }; diff --git a/addons/overheating/XEH_postInit.sqf b/addons/overheating/XEH_postInit.sqf index b19b96272d..f29a1c624c 100644 --- a/addons/overheating/XEH_postInit.sqf +++ b/addons/overheating/XEH_postInit.sqf @@ -11,6 +11,67 @@ if (isServer) then { // Keep track of the temperature of stored spare barrels GVAR(storedSpareBarrels) = [] call CBA_fnc_hashCreate; + + ["spareBarrelsCheckTemperatures", { + params ["_player","_unit"]; + // Find all spare barrel the player has + private _allMags = magazinesDetail _unit; + _allMags = _allMags select {_x find "ACE Spare Barrel" == 0}; + if ((count _allMags) < 1) exitWith {}; + + // Determine the temp of each barrel + private _temps = []; + { + private _temp = 0; + if ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashHasKey) then { + _temp = ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashGet) select 0; + }; + _temps pushBack _temp; + } forEach _allMags; + TRACE_1("_temps",_temps); + + // Count cool + private _countCool = {_x < 20} count _temps; + private _countWarm = {(_x >= 20) && (_x < 100)} count _temps; + private _countHot = {(_x >= 100) && (_x < 200)} count _temps; + private _countVeryHot = {(_x >= 200) && (_x < 600)} count _temps; + private _countExtremelyHot = {_x >= 600} count _temps; + private _output = ["%1 %2%3%4 %5%6%7 %8%9%10 %11%12%13 %14"]; + private _size = 1.0; + if (_countCool > 0) then { + _output pushBack _countCool; + _output pushBack LSTRING(BarrelCool); + _output pushBack "
"; + _size = _size + 0.5; + }; + if (_countWarm > 0) then { + _output pushBack _countWarm; + _output pushBack LSTRING(BarrelWarm); + _output pushBack "
"; + _size = _size + 0.5; + }; + if (_countHot > 0) then { + _output pushBack _countHot; + _output pushBack LSTRING(BarrelHot); + _output pushBack "
"; + _size = _size + 0.5; + }; + if (_countVeryHot > 0) then { + _output pushBack _countVeryHot; + _output pushBack LSTRING(BarrelVeryHot); + _output pushBack "
"; + _size = _size + 0.5; + }; + if (_countExtremelyHot > 0) then { + _output pushBack _countExtremelyHot; + _output pushBack LSTRING(BarrelExtremelyHot); + _size = _size + 0.5; + }; + + TRACE_1("_output",_output); + ["displayTextStructured", [_player], [_output, _size, _player]] call EFUNC(common,targetEvent); + }] call EFUNC(common,addEventHandler); + ["spareBarrelLoadedCoolest", { params ["_unit", "_weapon", "_weaponTemp", "_barrelMass"]; TRACE_4("spareBarrelLoadedCoolest1",_unit,_weapon,_weaponTemp,_barrelMass); diff --git a/addons/overheating/stringtable.xml b/addons/overheating/stringtable.xml index 57a9fee566..1e2490ea52 100644 --- a/addons/overheating/stringtable.xml +++ b/addons/overheating/stringtable.xml @@ -224,6 +224,9 @@ Sto controllando la temperatura... Проверка температуры... + + Check spare barrel temperatures + Temperature Temperatur @@ -236,5 +239,20 @@ Temperatura Температура + + Cool Spare Barrel/s + + + Warm Spare Barrel/s + + + Hot Spare Barrel/s + + + Very Hot Spare Barrel/s + + + Extremele Hot Spare Barrel/s + \ No newline at end of file From 46a96dd5da73e12c8b337c1fe121bd28db81566a Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 1 Mar 2016 18:14:36 -0300 Subject: [PATCH 03/15] Move spare barrel event handlers out of postInit --- addons/overheating/XEH_PREP.hpp | 2 + addons/overheating/XEH_postInit.sqf | 97 +------------------ .../functions/fnc_loadCoolestSpareBarrel.sqf | 51 ++++++++++ .../fnc_sendSpareBarrelsTemperaturesHint.sqf | 75 ++++++++++++++ .../functions/fnc_swapBarrelCallback.sqf | 2 +- 5 files changed, 132 insertions(+), 95 deletions(-) create mode 100644 addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf create mode 100644 addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf diff --git a/addons/overheating/XEH_PREP.hpp b/addons/overheating/XEH_PREP.hpp index 26366b9896..8f584ef6e6 100644 --- a/addons/overheating/XEH_PREP.hpp +++ b/addons/overheating/XEH_PREP.hpp @@ -8,7 +8,9 @@ PREP(firedEH); PREP(getWeaponData); PREP(handleTakeEH); PREP(jamWeapon); +PREP(loadCoolestSpareBarrel); PREP(overheat); +PREP(sendSpareBarrelsTemperaturesHint); PREP(swapBarrel); PREP(swapBarrelCallback); PREP(updateSpareBarrelsTemperaturesThread); diff --git a/addons/overheating/XEH_postInit.sqf b/addons/overheating/XEH_postInit.sqf index f29a1c624c..0e8eaad7c4 100644 --- a/addons/overheating/XEH_postInit.sqf +++ b/addons/overheating/XEH_postInit.sqf @@ -12,100 +12,9 @@ if (isServer) then { // Keep track of the temperature of stored spare barrels GVAR(storedSpareBarrels) = [] call CBA_fnc_hashCreate; - ["spareBarrelsCheckTemperatures", { - params ["_player","_unit"]; - // Find all spare barrel the player has - private _allMags = magazinesDetail _unit; - _allMags = _allMags select {_x find "ACE Spare Barrel" == 0}; - if ((count _allMags) < 1) exitWith {}; - - // Determine the temp of each barrel - private _temps = []; - { - private _temp = 0; - if ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashHasKey) then { - _temp = ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashGet) select 0; - }; - _temps pushBack _temp; - } forEach _allMags; - TRACE_1("_temps",_temps); - - // Count cool - private _countCool = {_x < 20} count _temps; - private _countWarm = {(_x >= 20) && (_x < 100)} count _temps; - private _countHot = {(_x >= 100) && (_x < 200)} count _temps; - private _countVeryHot = {(_x >= 200) && (_x < 600)} count _temps; - private _countExtremelyHot = {_x >= 600} count _temps; - private _output = ["%1 %2%3%4 %5%6%7 %8%9%10 %11%12%13 %14"]; - private _size = 1.0; - if (_countCool > 0) then { - _output pushBack _countCool; - _output pushBack LSTRING(BarrelCool); - _output pushBack "
"; - _size = _size + 0.5; - }; - if (_countWarm > 0) then { - _output pushBack _countWarm; - _output pushBack LSTRING(BarrelWarm); - _output pushBack "
"; - _size = _size + 0.5; - }; - if (_countHot > 0) then { - _output pushBack _countHot; - _output pushBack LSTRING(BarrelHot); - _output pushBack "
"; - _size = _size + 0.5; - }; - if (_countVeryHot > 0) then { - _output pushBack _countVeryHot; - _output pushBack LSTRING(BarrelVeryHot); - _output pushBack "
"; - _size = _size + 0.5; - }; - if (_countExtremelyHot > 0) then { - _output pushBack _countExtremelyHot; - _output pushBack LSTRING(BarrelExtremelyHot); - _size = _size + 0.5; - }; - - TRACE_1("_output",_output); - ["displayTextStructured", [_player], [_output, _size, _player]] call EFUNC(common,targetEvent); - }] call EFUNC(common,addEventHandler); - - ["spareBarrelLoadedCoolest", { - params ["_unit", "_weapon", "_weaponTemp", "_barrelMass"]; - TRACE_4("spareBarrelLoadedCoolest1",_unit,_weapon,_weaponTemp,_barrelMass); - - // Find all spare barrel the player has - private _allMags = magazinesDetail _unit; - TRACE_1("spareBarrelLoadedCoolest2",_allMags); - _allMags = _allMags select {_x find "ACE Spare Barrel" == 0}; - TRACE_1("spareBarrelLoadedCoolest3",_allMags); - if ((count _allMags) < 1) exitWith {}; - - // Determine which on is coolest - private _coolestTemp = 10000; - private _coolestMag = _allMags select 0; - { - private _temp = 0; - if ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashHasKey) then { - _temp = ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashGet) select 0; - }; - TRACE_2("spareBarrelLoadedCoolest4",_x,_temp); - if (_temp < _coolestTemp) then { - _coolestTemp = _temp; - _coolestMag = _x; - }; - } forEach _allMags; - TRACE_3("spareBarrelLoadedCoolest5",_coolestTemp,_coolestMag,_weaponTemp); - - // The new weapon temperature is similar to the coolest barrel - // Publish the new temperature value - _unit setVariable [format [QGVAR(%1_temp), _weapon], _coolestTemp, true]; - - // Heat up the coolest barrel to the former weapon temperature - [GVAR(storedSpareBarrels), _coolestMag, [_weaponTemp, ACE_Time, _barrelMass]] call CBA_fnc_hashSet; - }] call EFUNC(common,addEventHandler); + // Install event handlers for spare barrels + ["spareBarrelsSendTemperatureHint", FUNC(sendSpareBarrelsTemperaturesHint)] call EFUNC(common,addEventHandler); + ["spareBarrelsLoadCoolest", FUNC(loadCoolestSpareBarrel)] call EFUNC(common,addEventHandler); // Schedule cool down calculation of stored spare barrels [] call FUNC(updateSpareBarrelsTemperaturesThread); diff --git a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf new file mode 100644 index 0000000000..97fe9d8883 --- /dev/null +++ b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf @@ -0,0 +1,51 @@ +/* + * Author: esteldunedain + * Collect the temperature of all the spare barrels a unit has and load the + * coolest on the unit weapon. Runs on the server. + * + * Argument: + * 0: Unit + * 1: Weapon + * 2: Weapon temp before switching + * 3: Mass of the removed barrel + * + * Return value: + * None + * + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit", "_weapon", "_weaponTemp", "_barrelMass"]; +TRACE_4("loadCoolestSpareBarrel1",_unit,_weapon,_weaponTemp,_barrelMass); + +// Find all spare barrel the player has +private _allMags = magazinesDetail _unit; +TRACE_1("loadCoolestSpareBarrel2",_allMags); +_allMags = _allMags select {_x find "ACE Spare Barrel" == 0}; +TRACE_1("loadCoolestSpareBarrel3",_allMags); +if ((count _allMags) < 1) exitWith {}; + +// Determine which on is coolest +private _coolestTemp = 10000; +private _coolestMag = _allMags select 0; +{ + private _temp = 0; + if ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashHasKey) then { + _temp = ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashGet) select 0; + }; + TRACE_2("loadCoolestSpareBarrel4",_x,_temp); + if (_temp < _coolestTemp) then { + _coolestTemp = _temp; + _coolestMag = _x; + }; +} forEach _allMags; +TRACE_3("loadCoolestSpareBarrel5",_coolestTemp,_coolestMag,_weaponTemp); + +// The new weapon temperature is similar to the coolest barrel +// Publish the new temperature value +_unit setVariable [format [QGVAR(%1_temp), _weapon], _coolestTemp, true]; + +// Heat up the coolest barrel to the former weapon temperature +[GVAR(storedSpareBarrels), _coolestMag, [_weaponTemp, ACE_Time, _barrelMass]] call CBA_fnc_hashSet; diff --git a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf new file mode 100644 index 0000000000..01a6ecc0a4 --- /dev/null +++ b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf @@ -0,0 +1,75 @@ +/* + * Author: esteldunedain + * Collect the temperature of all the spare barrels a unit has and send a hint + * to a client. Runs on the server. + * + * Argument: + * 0: Target unit of the hint + * 1: Unit that has the spare barrels + * + * Return value: + * None + * + * + * Public: No + */ +#include "script_component.hpp" + +params ["_player","_unit"]; + +// Find all spare barrel the player has +private _allMags = magazinesDetail _unit; +_allMags = _allMags select {_x find "ACE Spare Barrel" == 0}; +if ((count _allMags) < 1) exitWith {}; + +// Determine the temp of each barrel +private _temps = []; +{ + private _temp = 0; + if ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashHasKey) then { + _temp = ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashGet) select 0; + }; + _temps pushBack _temp; +} forEach _allMags; +TRACE_1("_temps",_temps); + +// Count cool +private _countCool = {_x < 20} count _temps; +private _countWarm = {(_x >= 20) && (_x < 100)} count _temps; +private _countHot = {(_x >= 100) && (_x < 200)} count _temps; +private _countVeryHot = {(_x >= 200) && (_x < 600)} count _temps; +private _countExtremelyHot = {_x >= 600} count _temps; +private _output = ["%1 %2%3%4 %5%6%7 %8%9%10 %11%12%13 %14"]; +private _size = 1.0; +if (_countCool > 0) then { + _output pushBack _countCool; + _output pushBack LSTRING(BarrelCool); + _output pushBack "
"; + _size = _size + 0.5; +}; +if (_countWarm > 0) then { + _output pushBack _countWarm; + _output pushBack LSTRING(BarrelWarm); + _output pushBack "
"; + _size = _size + 0.5; +}; +if (_countHot > 0) then { + _output pushBack _countHot; + _output pushBack LSTRING(BarrelHot); + _output pushBack "
"; + _size = _size + 0.5; +}; +if (_countVeryHot > 0) then { + _output pushBack _countVeryHot; + _output pushBack LSTRING(BarrelVeryHot); + _output pushBack "
"; + _size = _size + 0.5; +}; +if (_countExtremelyHot > 0) then { + _output pushBack _countExtremelyHot; + _output pushBack LSTRING(BarrelExtremelyHot); + _size = _size + 0.5; +}; + +TRACE_1("_output",_output); +["displayTextStructured", [_player], [_output, _size, _player]] call EFUNC(common,targetEvent); diff --git a/addons/overheating/functions/fnc_swapBarrelCallback.sqf b/addons/overheating/functions/fnc_swapBarrelCallback.sqf index 8bd63e4874..6eba214617 100644 --- a/addons/overheating/functions/fnc_swapBarrelCallback.sqf +++ b/addons/overheating/functions/fnc_swapBarrelCallback.sqf @@ -34,7 +34,7 @@ private _barrelMass = 0.50 * (getNumber (configFile >> "CfgWeapons" >> _weapon > // store the removed barrel with the former weapon temperature. The server // also updates the current weapon temperature to match that of the new // loaded barrel. -["spareBarrelLoadedCoolest", [_player, _weapon, _temp, _barrelMass]] call EFUNC(common,serverEvent); +["spareBarrelsLoadCoolest", [_player, _weapon, _temp, _barrelMass]] call EFUNC(common,serverEvent); // Store the update time _player setVariable [format [QGVAR(%1_time), _weapon], ACE_time]; From a041555381376834bb4d482e6b927080a731fb85 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 1 Mar 2016 18:16:14 -0300 Subject: [PATCH 04/15] Add an animation and progressbar to the "Check spare barrels temperatures" action --- addons/overheating/CfgVehicles.hpp | 2 +- addons/overheating/XEH_PREP.hpp | 1 + .../fnc_checkSpareBarrelsTemperatures.sqf | 36 +++++++++++++++++++ addons/overheating/stringtable.xml | 5 ++- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 addons/overheating/functions/fnc_checkSpareBarrelsTemperatures.sqf diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index 61b619a79b..928a22420a 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -34,7 +34,7 @@ class CfgVehicles { displayName = CSTRING(CheckTemperatureSpareBarrelsShort); condition = QUOTE( 'ACE_SpareBarrel' in magazines _player); exceptions[] = {"isNotInside", "isNotSitting"}; - statement = QUOTE([ARR_2('spareBarrelsCheckTemperatures',[ARR_2(_player,_player)])] call EFUNC(common,serverEvent);); + statement = QUOTE( [ARR_1(_player)] call FUNC(checkSpareBarrelsTemperatures); ); showDisabled = 0; priority = 2.8; icon = QUOTE(PATHTOF(UI\temp_ca.paa)); diff --git a/addons/overheating/XEH_PREP.hpp b/addons/overheating/XEH_PREP.hpp index 8f584ef6e6..cc1948e6bd 100644 --- a/addons/overheating/XEH_PREP.hpp +++ b/addons/overheating/XEH_PREP.hpp @@ -1,6 +1,7 @@ PREP(calculateCooling); PREP(canUnjam); +PREP(checkSpareBarrelsTemperatures); PREP(checkTemperature); PREP(clearJam); PREP(displayTemperature); diff --git a/addons/overheating/functions/fnc_checkSpareBarrelsTemperatures.sqf b/addons/overheating/functions/fnc_checkSpareBarrelsTemperatures.sqf new file mode 100644 index 0000000000..b7509671bb --- /dev/null +++ b/addons/overheating/functions/fnc_checkSpareBarrelsTemperatures.sqf @@ -0,0 +1,36 @@ +/* + * Author: esteldunedain + * Make the player check the temperature of his spare barrels + * + * Arguments: + * 0: Player + * + * Return Value: + * None + * + * + * Public: No + */ +#include "script_component.hpp" + +params ["_player"]; + +// Check canInteractWith: +if (!([_player, objNull, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith))) exitWith {}; + +// Make the unit go kneeling +[_unit] call EFUNC(common,goKneeling); + +// Spawn a progress bar +[ + 5.0, + [_player], + { + // Time has enlapsed, ask the server to send the hint + ['spareBarrelsSendTemperatureHint', [_unit, _unit]] call EFUNC(common,serverEvent); + }, + {}, + (localize LSTRING(CheckingSpareBarrelsTemperatures)), + {true}, + ["isNotInside", "isNotSitting"] +] call EFUNC(common,progressBar); diff --git a/addons/overheating/stringtable.xml b/addons/overheating/stringtable.xml index ace5806f61..fc38ae0054 100644 --- a/addons/overheating/stringtable.xml +++ b/addons/overheating/stringtable.xml @@ -230,7 +230,10 @@ Проверка температуры... - Check spare barrel temperatures + Check spare barrels temperatures + + + Checking spare barrels temperatures... Temperature From b8c8c21a02de54fbe9081376fee72db6943ccba0 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 1 Mar 2016 18:17:23 -0300 Subject: [PATCH 05/15] Remove spare barrels from starting equipments --- addons/overheating/CfgVehicles.hpp | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index 928a22420a..8981c907f7 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -108,30 +108,4 @@ class CfgVehicles { MACRO_ADDITEM(ACE_SpareBarrel,6); }; }; -/* - // Add ACE_SpareBarrel to every machine gunner. - #define MACRO_ADDSPAREBARREL \ - items[] = {"FirstAidKit", "ACE_SpareBarrel"}; \ - respawnitems[] = {"FirstAidKit", "ACE_SpareBarrel"}; - - // NATO - class B_Soldier_02_f; class B_soldier_AR_F:B_Soldier_02_f {MACRO_ADDSPAREBARREL}; - class B_Soldier_support_base_F; class B_soldier_AAR_F:B_Soldier_support_base_F {MACRO_ADDSPAREBARREL}; - class B_Soldier_base_F; class B_CTRG_soldier_AR_A_F:B_Soldier_base_F {MACRO_ADDSPAREBARREL}; - - // Guerrilla - class I_G_Soldier_base_F; class I_G_Soldier_AR_F:I_G_Soldier_base_F {MACRO_ADDSPAREBARREL}; - class B_G_Soldier_AR_F:I_G_Soldier_AR_F {MACRO_ADDSPAREBARREL}; - class O_G_Soldier_AR_F:I_G_Soldier_AR_F {MACRO_ADDSPAREBARREL}; - - // Iran - class O_Soldier_base_F; class O_Soldier_AR_F:O_Soldier_base_F {MACRO_ADDSPAREBARREL}; - class O_Soldier_support_base_F; class O_Soldier_AAR_F:O_Soldier_support_base_F {MACRO_ADDSPAREBARREL}; - class O_Soldier_Urban_base; class O_soldierU_AR_F:O_Soldier_Urban_base {MACRO_ADDSPAREBARREL}; - class O_soldierU_AAR_F:O_Soldier_Urban_base {MACRO_ADDSPAREBARREL}; - - // Czech - class I_Soldier_02_F; class I_Soldier_AR_F:I_Soldier_02_F {MACRO_ADDSPAREBARREL}; - class I_Soldier_support_base_F; class I_Soldier_AAR_F:I_Soldier_support_base_F {MACRO_ADDSPAREBARREL}; -*/ }; From f130d6c2530cac2bc6fae3d73744e6bdd2909c02 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 1 Mar 2016 18:17:58 -0300 Subject: [PATCH 06/15] Increase spare barrel mass to 60 (2.7 Kg) --- addons/overheating/CfgMagazines.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/overheating/CfgMagazines.hpp b/addons/overheating/CfgMagazines.hpp index ad381ff30e..d9b3ee2bdc 100644 --- a/addons/overheating/CfgMagazines.hpp +++ b/addons/overheating/CfgMagazines.hpp @@ -5,7 +5,7 @@ class CfgMagazines { picture = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); displayName = "ACE Spare Barrel"; //!!!CANNOT be localized!!!: because it is used as part of the magazineDetail string count = 1; - mass = 40; + mass = 60; ACE_isUnique = 1; }; }; From e6a2ca71026a090a1f63018c8e93be2fc9573391 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 1 Mar 2016 19:25:45 -0300 Subject: [PATCH 07/15] Fix typos --- addons/overheating/CfgVehicles.hpp | 2 +- .../functions/fnc_checkSpareBarrelsTemperatures.sqf | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index 8981c907f7..61052553a4 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -34,7 +34,7 @@ class CfgVehicles { displayName = CSTRING(CheckTemperatureSpareBarrelsShort); condition = QUOTE( 'ACE_SpareBarrel' in magazines _player); exceptions[] = {"isNotInside", "isNotSitting"}; - statement = QUOTE( [ARR_1(_player)] call FUNC(checkSpareBarrelsTemperatures); ); + statement = QUOTE( [_player] call FUNC(checkSpareBarrelsTemperatures); ); showDisabled = 0; priority = 2.8; icon = QUOTE(PATHTOF(UI\temp_ca.paa)); diff --git a/addons/overheating/functions/fnc_checkSpareBarrelsTemperatures.sqf b/addons/overheating/functions/fnc_checkSpareBarrelsTemperatures.sqf index b7509671bb..e8dbaabec0 100644 --- a/addons/overheating/functions/fnc_checkSpareBarrelsTemperatures.sqf +++ b/addons/overheating/functions/fnc_checkSpareBarrelsTemperatures.sqf @@ -19,15 +19,17 @@ params ["_player"]; if (!([_player, objNull, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith))) exitWith {}; // Make the unit go kneeling -[_unit] call EFUNC(common,goKneeling); +[_player] call EFUNC(common,goKneeling); // Spawn a progress bar [ 5.0, [_player], { + params ["_args", "_elapsedTime", "_totalTime", "_errorCode"]; + _args params ["_player"]; // Time has enlapsed, ask the server to send the hint - ['spareBarrelsSendTemperatureHint', [_unit, _unit]] call EFUNC(common,serverEvent); + ['spareBarrelsSendTemperatureHint', [_player, _player]] call EFUNC(common,serverEvent); }, {}, (localize LSTRING(CheckingSpareBarrelsTemperatures)), From 850a499c0e246fbd70b10a90c0e04cc9abf1364d Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 1 Mar 2016 19:26:20 -0300 Subject: [PATCH 08/15] Localize spare barrel's displayName --- addons/overheating/CfgMagazines.hpp | 2 +- addons/overheating/XEH_preInit.sqf | 10 ++++++++++ .../functions/fnc_loadCoolestSpareBarrel.sqf | 13 ++++++------- .../fnc_sendSpareBarrelsTemperaturesHint.sqf | 9 +++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/addons/overheating/CfgMagazines.hpp b/addons/overheating/CfgMagazines.hpp index d9b3ee2bdc..cc040eca0f 100644 --- a/addons/overheating/CfgMagazines.hpp +++ b/addons/overheating/CfgMagazines.hpp @@ -1,9 +1,9 @@ class CfgMagazines { class CA_Magazine; class ACE_SpareBarrel: CA_Magazine { + displayName = CSTRING(SpareBarrelName); descriptionshort = CSTRING(SpareBarrelDescription); picture = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); - displayName = "ACE Spare Barrel"; //!!!CANNOT be localized!!!: because it is used as part of the magazineDetail string count = 1; mass = 60; ACE_isUnique = 1; diff --git a/addons/overheating/XEH_preInit.sqf b/addons/overheating/XEH_preInit.sqf index a7feade1c3..54bc392273 100644 --- a/addons/overheating/XEH_preInit.sqf +++ b/addons/overheating/XEH_preInit.sqf @@ -4,4 +4,14 @@ ADDON = false; #include "XEH_PREP.hpp" +FakeCBA_fnc_getMagazineIds = { + params [["_unit", objNull, [objNull]], ["_magazine", "", [""]]]; + + private _displayName = getText (configFile >> "CfgMagazines" >> _magazine >> "displayName"); + + if (_displayName isEqualTo "") exitWith {[]}; + + magazinesDetail _unit select {_x find _displayName == 0} apply {_x = _x splitString "[:]"; _x select (count _x - 1)}; +}; + ADDON = true; diff --git a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf index 97fe9d8883..23d2c7959e 100644 --- a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf +++ b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf @@ -21,15 +21,13 @@ params ["_unit", "_weapon", "_weaponTemp", "_barrelMass"]; TRACE_4("loadCoolestSpareBarrel1",_unit,_weapon,_weaponTemp,_barrelMass); // Find all spare barrel the player has -private _allMags = magazinesDetail _unit; -TRACE_1("loadCoolestSpareBarrel2",_allMags); -_allMags = _allMags select {_x find "ACE Spare Barrel" == 0}; -TRACE_1("loadCoolestSpareBarrel3",_allMags); -if ((count _allMags) < 1) exitWith {}; +private _allBarrels = [_unit, "ACE_SpareBarrel"] call FakeCBA_fnc_getMagazineIds; +TRACE_1("_allBarrels",_allBarrels); +if ((count _allBarrels) < 1) exitWith {}; // Determine which on is coolest private _coolestTemp = 10000; -private _coolestMag = _allMags select 0; +private _coolestMag = _allBarrels select 0; { private _temp = 0; if ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashHasKey) then { @@ -40,7 +38,7 @@ private _coolestMag = _allMags select 0; _coolestTemp = _temp; _coolestMag = _x; }; -} forEach _allMags; +} forEach _allBarrels; TRACE_3("loadCoolestSpareBarrel5",_coolestTemp,_coolestMag,_weaponTemp); // The new weapon temperature is similar to the coolest barrel @@ -49,3 +47,4 @@ _unit setVariable [format [QGVAR(%1_temp), _weapon], _coolestTemp, true]; // Heat up the coolest barrel to the former weapon temperature [GVAR(storedSpareBarrels), _coolestMag, [_weaponTemp, ACE_Time, _barrelMass]] call CBA_fnc_hashSet; + diff --git a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf index 01a6ecc0a4..9f286832c6 100644 --- a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf +++ b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf @@ -18,9 +18,10 @@ params ["_player","_unit"]; // Find all spare barrel the player has -private _allMags = magazinesDetail _unit; -_allMags = _allMags select {_x find "ACE Spare Barrel" == 0}; -if ((count _allMags) < 1) exitWith {}; +TRACE_2("sendSpareBarrelsTemperatureHunt",_player,_unit); +private _allBarrels = [_unit, "ACE_SpareBarrel"] call FakeCBA_fnc_getMagazineIds; +TRACE_1("_allBarrels",_allBarrels); +if ((count _allBarrels) < 1) exitWith {}; // Determine the temp of each barrel private _temps = []; @@ -30,7 +31,7 @@ private _temps = []; _temp = ([GVAR(storedSpareBarrels), _x] call CBA_fnc_hashGet) select 0; }; _temps pushBack _temp; -} forEach _allMags; +} forEach _allBarrels; TRACE_1("_temps",_temps); // Count cool From d8862897163ee46c23a4e3caf382a735eeab6c2e Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 1 Mar 2016 19:27:39 -0300 Subject: [PATCH 09/15] Display the new weapon temperature right after swapping barrels --- addons/overheating/XEH_postInit.sqf | 5 +++++ addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf | 2 ++ addons/overheating/functions/fnc_swapBarrelCallback.sqf | 3 --- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/overheating/XEH_postInit.sqf b/addons/overheating/XEH_postInit.sqf index 0e8eaad7c4..831c2c2348 100644 --- a/addons/overheating/XEH_postInit.sqf +++ b/addons/overheating/XEH_postInit.sqf @@ -55,3 +55,8 @@ GVAR(cacheSilencerData) = call CBA_fnc_createNamespace; ["firedPlayerNonLocal", DFUNC(firedEH)] call EFUNC(common,addEventHandler); }; }] call EFUNC(common,addEventHandler); + +// Install event handlers to display temp when a barrel was swapped +["barrelSwapped", { + _this call FUNC(displayTemperature); +}] call EFUNC(common,addEventHandler); diff --git a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf index 23d2c7959e..dd58d58207 100644 --- a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf +++ b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf @@ -48,3 +48,5 @@ _unit setVariable [format [QGVAR(%1_temp), _weapon], _coolestTemp, true]; // Heat up the coolest barrel to the former weapon temperature [GVAR(storedSpareBarrels), _coolestMag, [_weaponTemp, ACE_Time, _barrelMass]] call CBA_fnc_hashSet; +// Send an event so the local machine can show the hint +["barrelSwapped", _unit, [_unit, _weapon]] call EFUNC(common,objectEvent); diff --git a/addons/overheating/functions/fnc_swapBarrelCallback.sqf b/addons/overheating/functions/fnc_swapBarrelCallback.sqf index 6eba214617..62a3b13ef6 100644 --- a/addons/overheating/functions/fnc_swapBarrelCallback.sqf +++ b/addons/overheating/functions/fnc_swapBarrelCallback.sqf @@ -24,9 +24,6 @@ TRACE_2("params",_player,_weapon); _player playAction QGVAR(GestureMountMuzzle); playSound "ACE_BarrelSwap"; -// don't consume the barrel, but rotate through them. -[localize LSTRING(SwappedBarrel), QUOTE(PATHTOF(UI\spare_barrel_ca.paa))] call EFUNC(common,displayTextPicture); - private _temp = _player getVariable [format [QGVAR(%1_temp), _weapon], 0]; private _barrelMass = 0.50 * (getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "mass") / 22.0) max 1.0; From 62f598b2a6bca3049438c52154e3b9c612aac952 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 5 Mar 2016 13:11:20 -0300 Subject: [PATCH 10/15] Use the correct CBA function name, defining it in ACE as long as it doesn't exist already. --- addons/overheating/XEH_preInit.sqf | 12 +++++++----- .../functions/fnc_loadCoolestSpareBarrel.sqf | 2 +- .../fnc_sendSpareBarrelsTemperaturesHint.sqf | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/overheating/XEH_preInit.sqf b/addons/overheating/XEH_preInit.sqf index 54bc392273..dcd9ddc092 100644 --- a/addons/overheating/XEH_preInit.sqf +++ b/addons/overheating/XEH_preInit.sqf @@ -4,14 +4,16 @@ ADDON = false; #include "XEH_PREP.hpp" -FakeCBA_fnc_getMagazineIds = { - params [["_unit", objNull, [objNull]], ["_magazine", "", [""]]]; +if (isNil "CBA_fnc_getMagazineIds") then { + CBA_fnc_getMagazineIds = { + params [["_unit", objNull, [objNull]], ["_magazine", "", [""]]]; - private _displayName = getText (configFile >> "CfgMagazines" >> _magazine >> "displayName"); + private _displayName = getText (configFile >> "CfgMagazines" >> _magazine >> "displayName"); - if (_displayName isEqualTo "") exitWith {[]}; + if (_displayName isEqualTo "") exitWith {[]}; - magazinesDetail _unit select {_x find _displayName == 0} apply {_x = _x splitString "[:]"; _x select (count _x - 1)}; + magazinesDetail _unit select {_x find _displayName == 0} apply {_x = _x splitString "[:]"; _x select (count _x - 1)}; + }; }; ADDON = true; diff --git a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf index dd58d58207..a3f9998497 100644 --- a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf +++ b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf @@ -21,7 +21,7 @@ params ["_unit", "_weapon", "_weaponTemp", "_barrelMass"]; TRACE_4("loadCoolestSpareBarrel1",_unit,_weapon,_weaponTemp,_barrelMass); // Find all spare barrel the player has -private _allBarrels = [_unit, "ACE_SpareBarrel"] call FakeCBA_fnc_getMagazineIds; +private _allBarrels = [_unit, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIds; TRACE_1("_allBarrels",_allBarrels); if ((count _allBarrels) < 1) exitWith {}; diff --git a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf index 9f286832c6..eb3f514ac1 100644 --- a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf +++ b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf @@ -19,7 +19,7 @@ params ["_player","_unit"]; // Find all spare barrel the player has TRACE_2("sendSpareBarrelsTemperatureHunt",_player,_unit); -private _allBarrels = [_unit, "ACE_SpareBarrel"] call FakeCBA_fnc_getMagazineIds; +private _allBarrels = [_unit, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIds; TRACE_1("_allBarrels",_allBarrels); if ((count _allBarrels) < 1) exitWith {}; From ebfd76107e538888adede5814489f4933f81194e Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 5 Mar 2016 13:15:56 -0300 Subject: [PATCH 11/15] The function name was changed in CBA --- addons/overheating/XEH_preInit.sqf | 4 ++-- addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf | 2 +- .../functions/fnc_sendSpareBarrelsTemperaturesHint.sqf | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/overheating/XEH_preInit.sqf b/addons/overheating/XEH_preInit.sqf index dcd9ddc092..ccb7cba58a 100644 --- a/addons/overheating/XEH_preInit.sqf +++ b/addons/overheating/XEH_preInit.sqf @@ -4,8 +4,8 @@ ADDON = false; #include "XEH_PREP.hpp" -if (isNil "CBA_fnc_getMagazineIds") then { - CBA_fnc_getMagazineIds = { +if (isNil "CBA_fnc_getMagazineIndex") then { + CBA_fnc_getMagazineIndex = { params [["_unit", objNull, [objNull]], ["_magazine", "", [""]]]; private _displayName = getText (configFile >> "CfgMagazines" >> _magazine >> "displayName"); diff --git a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf index a3f9998497..b90271abd9 100644 --- a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf +++ b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf @@ -21,7 +21,7 @@ params ["_unit", "_weapon", "_weaponTemp", "_barrelMass"]; TRACE_4("loadCoolestSpareBarrel1",_unit,_weapon,_weaponTemp,_barrelMass); // Find all spare barrel the player has -private _allBarrels = [_unit, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIds; +private _allBarrels = [_unit, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIndex; TRACE_1("_allBarrels",_allBarrels); if ((count _allBarrels) < 1) exitWith {}; diff --git a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf index eb3f514ac1..2ff248016d 100644 --- a/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf +++ b/addons/overheating/functions/fnc_sendSpareBarrelsTemperaturesHint.sqf @@ -19,7 +19,7 @@ params ["_player","_unit"]; // Find all spare barrel the player has TRACE_2("sendSpareBarrelsTemperatureHunt",_player,_unit); -private _allBarrels = [_unit, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIds; +private _allBarrels = [_unit, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIndex; TRACE_1("_allBarrels",_allBarrels); if ((count _allBarrels) < 1) exitWith {}; From 6cf9787fd1d11316d48768d58b2afad840976d59 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 5 Mar 2016 13:18:41 -0300 Subject: [PATCH 12/15] Fix travis warning --- addons/overheating/XEH_preInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/overheating/XEH_preInit.sqf b/addons/overheating/XEH_preInit.sqf index ccb7cba58a..cdd1fa78dd 100644 --- a/addons/overheating/XEH_preInit.sqf +++ b/addons/overheating/XEH_preInit.sqf @@ -12,7 +12,7 @@ if (isNil "CBA_fnc_getMagazineIndex") then { if (_displayName isEqualTo "") exitWith {[]}; - magazinesDetail _unit select {_x find _displayName == 0} apply {_x = _x splitString "[:]"; _x select (count _x - 1)}; + (magazinesDetail _unit select {_x find _displayName == 0}) apply {_x = _x splitString "[:]"; _x select (count _x - 1)}; }; }; From ae8cbb4834ac98d6874140d367c930eea5287386 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 5 Mar 2016 23:33:30 -0300 Subject: [PATCH 13/15] Add "check temperature" and "swap barrel" actions for AARs --- addons/overheating/CfgVehicles.hpp | 30 +++++++++++++---- addons/overheating/XEH_PREP.hpp | 1 + addons/overheating/XEH_postInit.sqf | 8 ++--- .../functions/fnc_checkTemperature.sqf | 24 +++++++------- .../functions/fnc_loadCoolestSpareBarrel.sqf | 21 ++++++------ .../overheating/functions/fnc_swapBarrel.sqf | 24 +++++++++----- .../functions/fnc_swapBarrelAssistant.sqf | 33 +++++++++++++++++++ .../functions/fnc_swapBarrelCallback.sqf | 25 +++++++------- 8 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 addons/overheating/functions/fnc_swapBarrelAssistant.sqf diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index 61052553a4..528f77375c 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -4,7 +4,7 @@ class CfgVehicles { class CAManBase: Man { class ACE_SelfActions { class ACE_Equipment { - class ACE_UnJam { + class GVAR(UnJam) { displayName = CSTRING(UnjamWeapon); condition = QUOTE( [_player] call FUNC(canUnjam) ); exceptions[] = {"isNotInside", "isNotSitting"}; @@ -13,7 +13,7 @@ class CfgVehicles { priority = 4; icon = QUOTE(PATHTOF(UI\unjam_ca.paa)); }; - class ACE_SwapBarrel { + class GVAR(SwapBarrel) { displayName = CSTRING(SwapBarrel); condition = QUOTE( 'ACE_SpareBarrel' in magazines _player && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _player >> 'ACE_Overheating_allowSwapBarrel') == 1} ); statement = QUOTE( [ARR_2(_player, currentWeapon _player)] call FUNC(swapBarrel); ); @@ -21,16 +21,16 @@ class CfgVehicles { priority = 3; icon = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); }; - class ACE_CheckTemperature { + class GVAR(CheckTemperature) { displayName = CSTRING(CheckTemperatureShort); - condition = "switch (currentWeapon _player) do {case (''): {false}; case (primaryWeapon _player); case (secondaryWeapon _player); case (handgunWeapon _player): {true}; default {false}}"; + condition = "switch (currentWeapon _player) do {case (''): {false}; case (primaryWeapon _player); case (handgunWeapon _player): {true}; default {false}}"; exceptions[] = {"isNotInside", "isNotSitting"}; - statement = QUOTE( [ARR_2(_player, currentWeapon _player)] call FUNC(CheckTemperature); ); + statement = QUOTE( [ARR_3(_player, _player, currentWeapon _player)] call FUNC(checkTemperature); ); showDisabled = 0; priority = 2.9; icon = QUOTE(PATHTOF(UI\temp_ca.paa)); }; - class ACE_CheckTemperatureSpareBarrels { + class GVAR(CheckTemperatureSpareBarrels) { displayName = CSTRING(CheckTemperatureSpareBarrelsShort); condition = QUOTE( 'ACE_SpareBarrel' in magazines _player); exceptions[] = {"isNotInside", "isNotSitting"}; @@ -41,6 +41,24 @@ class CfgVehicles { }; }; }; + + class ACE_Actions { + class ACE_Weapon { + class GVAR(SwapBarrel) { + displayName = CSTRING(SwapBarrel); + condition = QUOTE( 'ACE_SpareBarrel' in magazines _player && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _target >> 'ACE_Overheating_allowSwapBarrel') == 1} ); + statement = QUOTE([ARR_3(_player, _target, currentWeapon _target)] call FUNC(swapBarrelAssistant);); + icon = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); + }; + class GVAR(CheckTemperature) { + displayName = CSTRING(CheckTemperatureShort); + condition = "switch (currentWeapon _target) do {case (''): {false}; case (primaryWeapon _target); case (handgunWeapon _target): {true}; default {false}}"; + exceptions[] = {"isNotInside", "isNotSitting"}; + statement = QUOTE( [ARR_3(_player, _target, currentWeapon _target)] call FUNC(checkTemperature); ); + icon = QUOTE(PATHTOF(UI\temp_ca.paa)); + }; + }; + }; }; class ReammoBox_F; diff --git a/addons/overheating/XEH_PREP.hpp b/addons/overheating/XEH_PREP.hpp index cc1948e6bd..44fd931ca0 100644 --- a/addons/overheating/XEH_PREP.hpp +++ b/addons/overheating/XEH_PREP.hpp @@ -13,6 +13,7 @@ PREP(loadCoolestSpareBarrel); PREP(overheat); PREP(sendSpareBarrelsTemperaturesHint); PREP(swapBarrel); +PREP(swapBarrelAssistant); PREP(swapBarrelCallback); PREP(updateSpareBarrelsTemperaturesThread); PREP(updateTemperature); diff --git a/addons/overheating/XEH_postInit.sqf b/addons/overheating/XEH_postInit.sqf index 831c2c2348..96d518ac9f 100644 --- a/addons/overheating/XEH_postInit.sqf +++ b/addons/overheating/XEH_postInit.sqf @@ -56,7 +56,7 @@ GVAR(cacheSilencerData) = call CBA_fnc_createNamespace; }; }] call EFUNC(common,addEventHandler); -// Install event handlers to display temp when a barrel was swapped -["barrelSwapped", { - _this call FUNC(displayTemperature); -}] call EFUNC(common,addEventHandler); +// Install event handler to display temp when a barrel was swapped +["showWeaponTemperature", DFUNC(displayTemperature)] call EFUNC(common,addEventHandler); +// Install event handler to initiate an assisted barrel swap +["initiateSwapBarrelAssisted", DFUNC(swapBarrel)] call EFUNC(common,addEventHandler); diff --git a/addons/overheating/functions/fnc_checkTemperature.sqf b/addons/overheating/functions/fnc_checkTemperature.sqf index f720665620..fd2ac5f56c 100644 --- a/addons/overheating/functions/fnc_checkTemperature.sqf +++ b/addons/overheating/functions/fnc_checkTemperature.sqf @@ -3,8 +3,9 @@ * Make the player check the temperature of his weapon * * Arguments: - * 0: Player - * 1: Weapon + * 0: Unit checking + * 1: Unit that has the weapon + * 2: Weapon * * Return Value: * None @@ -16,17 +17,18 @@ */ #include "script_component.hpp" -params ["_player", "_weapon"]; -TRACE_2("params",_player,_weapon); +params ["_assistant", "_gunner", "_weapon"]; +TRACE_3("params",_assistant,_gunner,_weapon); // Play animation and report temperature -private _action = getText (configFile >> "CfgWeapons" >> _weapon >> "ACE_checkTemperatureAction"); - -if (_action == "") then { - _action = "Gear"; +private _action = "PutDown"; +if (_assistant isEqualTo _gunner) then { + _action = getText (configFile >> "CfgWeapons" >> _weapon >> "ACE_checkTemperatureAction"); + if (_action == "") then { + _action = "Gear"; + }; }; - -_player playActionNow _action; +_assistant playActionNow _action; // Waits a sec before displaying the temperature -[FUNC(displayTemperature), [_player, _weapon], 1.0] call EFUNC(common,waitAndExecute); +[FUNC(displayTemperature), [_gunner, _weapon], 1.0] call EFUNC(common,waitAndExecute); diff --git a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf index b90271abd9..08cb85083c 100644 --- a/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf +++ b/addons/overheating/functions/fnc_loadCoolestSpareBarrel.sqf @@ -4,10 +4,11 @@ * coolest on the unit weapon. Runs on the server. * * Argument: - * 0: Unit - * 1: Weapon - * 2: Weapon temp before switching - * 3: Mass of the removed barrel + * 0: Unit that has the spare barrels + * 1: Unit that has the weapon + * 2: Weapon + * 3: Weapon temp before switching + * 4: Mass of the removed barrel * * Return value: * None @@ -17,11 +18,11 @@ */ #include "script_component.hpp" -params ["_unit", "_weapon", "_weaponTemp", "_barrelMass"]; -TRACE_4("loadCoolestSpareBarrel1",_unit,_weapon,_weaponTemp,_barrelMass); +params ["_assistant", "_gunner", "_weapon", "_weaponTemp", "_barrelMass"]; +TRACE_5("loadCoolestSpareBarrel1",_assistant,_gunner,_weapon,_weaponTemp,_barrelMass); // Find all spare barrel the player has -private _allBarrels = [_unit, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIndex; +private _allBarrels = [_assistant, "ACE_SpareBarrel"] call CBA_fnc_getMagazineIndex; TRACE_1("_allBarrels",_allBarrels); if ((count _allBarrels) < 1) exitWith {}; @@ -43,10 +44,10 @@ TRACE_3("loadCoolestSpareBarrel5",_coolestTemp,_coolestMag,_weaponTemp); // The new weapon temperature is similar to the coolest barrel // Publish the new temperature value -_unit setVariable [format [QGVAR(%1_temp), _weapon], _coolestTemp, true]; +_gunner setVariable [format [QGVAR(%1_temp), _weapon], _coolestTemp, true]; // Heat up the coolest barrel to the former weapon temperature [GVAR(storedSpareBarrels), _coolestMag, [_weaponTemp, ACE_Time, _barrelMass]] call CBA_fnc_hashSet; -// Send an event so the local machine can show the hint -["barrelSwapped", _unit, [_unit, _weapon]] call EFUNC(common,objectEvent); +// Send an event so the machines of the assistant and gunner can show the hint +["showWeaponTemperature", [_assistant, _gunner], [_gunner, _weapon]] call EFUNC(common,targetEvent); diff --git a/addons/overheating/functions/fnc_swapBarrel.sqf b/addons/overheating/functions/fnc_swapBarrel.sqf index bbdab91705..a63ef5a36a 100644 --- a/addons/overheating/functions/fnc_swapBarrel.sqf +++ b/addons/overheating/functions/fnc_swapBarrel.sqf @@ -3,29 +3,35 @@ * Make a unit start swapping it's barrel * * Argument: - * 0: Unit - * 1: Weapon + * 0: Unit initiating the action + * 1: Unit that has the weapon + * 2: Weapon * * Return value: * None * * Example: - * [player, currentWeapon player] call ace_overheating_fnc_swapBarrel + * [cursorTarget, player, currentWeapon player] call ace_overheating_fnc_swapBarrel * * Public: No */ #include "script_component.hpp" -params ["_player", "_weapon"]; -TRACE_2("params",_player,_weapon); +params ["_assistant", "_gunner", "_weapon"]; +TRACE_3("params",_assistant,_gunner,_weapon); // Make the standing player kneel down -if (stance _player != "PRONE") then { - [_player, "amovpknlmstpsraswrfldnon", 1] call EFUNC(common,doAnimation); +if (stance _gunner != "PRONE") then { + [_gunner, "amovpknlmstpsraswrfldnon", 1] call EFUNC(common,doAnimation); }; // Barrel dismount gesture -_player playActionNow QGVAR(GestureDismountMuzzle); +_gunner playActionNow QGVAR(GestureDismountMuzzle); playSound "ACE_BarrelSwap"; -[5, [_player, _weapon], {(_this select 0) call FUNC(swapBarrelCallback)}, {}, (localize LSTRING(SwappingBarrel))] call EFUNC(common,progressBar); +private _duration = 3.0; +if (_assistant isEqualTo _gunner) then { + _duration = 5.0; +}; + +[_duration, [_assistant,_gunner,_weapon], {(_this select 0) call FUNC(swapBarrelCallback)}, {}, (localize LSTRING(SwappingBarrel))] call EFUNC(common,progressBar); diff --git a/addons/overheating/functions/fnc_swapBarrelAssistant.sqf b/addons/overheating/functions/fnc_swapBarrelAssistant.sqf new file mode 100644 index 0000000000..5e3c31fc5e --- /dev/null +++ b/addons/overheating/functions/fnc_swapBarrelAssistant.sqf @@ -0,0 +1,33 @@ +/* + * Author: esteldunedain, Commy2 + * Make a unit start swapping the barrel of another unit + * + * Argument: + * 0: Unit initiating the action + * 1: Unit that has the weapon + * 2: Weapon + * + * Return value: + * None + * + * Example: + * [player, cursorTarget, currentWeapon cursorTarget] call ace_overheating_fnc_swapBarrelAssistant + * + * Public: No + */ +#include "script_component.hpp" + +params ["_assistant", "_gunner", "_weapon"]; +TRACE_3("params",_assistant,_gunner,_weapon); + +// Make the standing player kneel down +if (stance _assistant != "PRONE") then { + [_assistant, "amovpknlmstpsraswrfldnon", 1] call EFUNC(common,doAnimation); +}; + +// Barrel dismount gesture +playSound "ACE_BarrelSwap"; + +[3, [_assistant, _gunner, _weapon], {}, {}, (localize LSTRING(SwappingBarrel))] call EFUNC(common,progressBar); + +["initiateSwapBarrelAssisted", _gunner, [_assistant, _gunner, _weapon]] call EFUNC(common,objectEvent); diff --git a/addons/overheating/functions/fnc_swapBarrelCallback.sqf b/addons/overheating/functions/fnc_swapBarrelCallback.sqf index 62a3b13ef6..339b6627b1 100644 --- a/addons/overheating/functions/fnc_swapBarrelCallback.sqf +++ b/addons/overheating/functions/fnc_swapBarrelCallback.sqf @@ -1,10 +1,11 @@ /* - * Author: Commy2 + * Author: Commy2, esteldunedain * Swap barrel callback * * Argument: - * 0: Unit - * 1: Weapon + * 0: Unit initiating the action + * 1: Unit that has the weapon + * 2: Weapon * * Return value: * None @@ -17,21 +18,23 @@ #define DEBUG_MODE_FULL #include "script_component.hpp" -params ["_player", "_weapon"]; -TRACE_2("params",_player,_weapon); +params ["_assistant", "_gunner", "_weapon"]; +TRACE_3("params",_assistant,_gunner,_weapon); -// Barrel mount gesture -_player playAction QGVAR(GestureMountMuzzle); -playSound "ACE_BarrelSwap"; +if (_assistant isEqualTo _gunner) then { + // Barrel mount gesture + _gunner playAction QGVAR(GestureMountMuzzle); + playSound "ACE_BarrelSwap"; +}; -private _temp = _player getVariable [format [QGVAR(%1_temp), _weapon], 0]; +private _temp = _gunner getVariable [format [QGVAR(%1_temp), _weapon], 0]; private _barrelMass = 0.50 * (getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "mass") / 22.0) max 1.0; // Instruct the server to load the coolest spare barrel into the weapon and // store the removed barrel with the former weapon temperature. The server // also updates the current weapon temperature to match that of the new // loaded barrel. -["spareBarrelsLoadCoolest", [_player, _weapon, _temp, _barrelMass]] call EFUNC(common,serverEvent); +["spareBarrelsLoadCoolest", [_assistant, _gunner, _weapon, _temp, _barrelMass]] call EFUNC(common,serverEvent); // Store the update time -_player setVariable [format [QGVAR(%1_time), _weapon], ACE_time]; +_gunner setVariable [format [QGVAR(%1_time), _weapon], ACE_time]; From 7cc2da2bb132c2d44f00aedc8d24a747be451362 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 29 Apr 2016 23:38:01 -0500 Subject: [PATCH 14/15] Fix self swap action --- addons/overheating/CfgVehicles.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index 528f77375c..0a86535231 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -16,7 +16,7 @@ class CfgVehicles { class GVAR(SwapBarrel) { displayName = CSTRING(SwapBarrel); condition = QUOTE( 'ACE_SpareBarrel' in magazines _player && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _player >> 'ACE_Overheating_allowSwapBarrel') == 1} ); - statement = QUOTE( [ARR_2(_player, currentWeapon _player)] call FUNC(swapBarrel); ); + statement = QUOTE( [ARR_3(_player, _player, currentWeapon _player)] call FUNC(swapBarrel); ); showDisabled = 0; priority = 3; icon = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); From cf92ba9c46203fb734c9949b6d4f3617009620f6 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 4 May 2016 14:59:04 -0500 Subject: [PATCH 15/15] Overheating - Add Master Enabled Setting (barrelPR) --- addons/overheating/ACE_Settings.hpp | 6 ++ addons/overheating/CfgEventHandlers.hpp | 8 -- addons/overheating/CfgVehicles.hpp | 12 +-- addons/overheating/XEH_postInit.sqf | 101 ++++++++++-------- .../functions/fnc_swapBarrelCallback.sqf | 2 +- ...c_updateSpareBarrelsTemperaturesThread.sqf | 2 +- addons/overheating/stringtable.xml | 10 +- 7 files changed, 77 insertions(+), 64 deletions(-) diff --git a/addons/overheating/ACE_Settings.hpp b/addons/overheating/ACE_Settings.hpp index 6cff3268ff..abf08c9874 100644 --- a/addons/overheating/ACE_Settings.hpp +++ b/addons/overheating/ACE_Settings.hpp @@ -38,4 +38,10 @@ class ACE_Settings { displayName = CSTRING(unJamFailChance_displayName); description = CSTRING(unJamFailChance_description); }; + class GVAR(enabled) { + typeName = "BOOL"; + value = 1; + displayName = CSTRING(enabled_displayName); + description = CSTRING(enabled_description); + }; }; diff --git a/addons/overheating/CfgEventHandlers.hpp b/addons/overheating/CfgEventHandlers.hpp index 492230513f..5da5fd0dc2 100644 --- a/addons/overheating/CfgEventHandlers.hpp +++ b/addons/overheating/CfgEventHandlers.hpp @@ -16,11 +16,3 @@ class Extended_PostInit_EventHandlers { init = QUOTE( call COMPILE_FILE(XEH_postInit) ); }; }; - -class Extended_Take_EventHandlers { - class CAManBase { - class GVAR(UnjamReload) { - clientTake = QUOTE( _this call FUNC(handleTakeEH) ); - }; - }; -}; diff --git a/addons/overheating/CfgVehicles.hpp b/addons/overheating/CfgVehicles.hpp index 0a86535231..23a2b613f5 100644 --- a/addons/overheating/CfgVehicles.hpp +++ b/addons/overheating/CfgVehicles.hpp @@ -6,7 +6,7 @@ class CfgVehicles { class ACE_Equipment { class GVAR(UnJam) { displayName = CSTRING(UnjamWeapon); - condition = QUOTE( [_player] call FUNC(canUnjam) ); + condition = QUOTE( GVAR(enabled) && {[_player] call FUNC(canUnjam)} ); exceptions[] = {"isNotInside", "isNotSitting"}; statement = QUOTE( [ARR_2(_player, currentMuzzle _player)] call FUNC(clearJam); ); showDisabled = 0; @@ -15,7 +15,7 @@ class CfgVehicles { }; class GVAR(SwapBarrel) { displayName = CSTRING(SwapBarrel); - condition = QUOTE( 'ACE_SpareBarrel' in magazines _player && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _player >> 'ACE_Overheating_allowSwapBarrel') == 1} ); + condition = QUOTE( GVAR(enabled) && {'ACE_SpareBarrel' in magazines _player} && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _player >> 'ACE_Overheating_allowSwapBarrel') == 1} ); statement = QUOTE( [ARR_3(_player, _player, currentWeapon _player)] call FUNC(swapBarrel); ); showDisabled = 0; priority = 3; @@ -23,7 +23,7 @@ class CfgVehicles { }; class GVAR(CheckTemperature) { displayName = CSTRING(CheckTemperatureShort); - condition = "switch (currentWeapon _player) do {case (''): {false}; case (primaryWeapon _player); case (handgunWeapon _player): {true}; default {false}}"; + condition = "ace_overheating_enabled && {switch (currentWeapon _player) do {case (''): {false}; case (primaryWeapon _player); case (handgunWeapon _player): {true}; default {false}}}"; exceptions[] = {"isNotInside", "isNotSitting"}; statement = QUOTE( [ARR_3(_player, _player, currentWeapon _player)] call FUNC(checkTemperature); ); showDisabled = 0; @@ -32,7 +32,7 @@ class CfgVehicles { }; class GVAR(CheckTemperatureSpareBarrels) { displayName = CSTRING(CheckTemperatureSpareBarrelsShort); - condition = QUOTE( 'ACE_SpareBarrel' in magazines _player); + condition = QUOTE( GVAR(enabled) && {'ACE_SpareBarrel' in magazines _player}); exceptions[] = {"isNotInside", "isNotSitting"}; statement = QUOTE( [_player] call FUNC(checkSpareBarrelsTemperatures); ); showDisabled = 0; @@ -46,13 +46,13 @@ class CfgVehicles { class ACE_Weapon { class GVAR(SwapBarrel) { displayName = CSTRING(SwapBarrel); - condition = QUOTE( 'ACE_SpareBarrel' in magazines _player && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _target >> 'ACE_Overheating_allowSwapBarrel') == 1} ); + condition = QUOTE( GVAR(enabled) && {'ACE_SpareBarrel' in magazines _player} && {getNumber (configFile >> 'CfgWeapons' >> currentWeapon _target >> 'ACE_Overheating_allowSwapBarrel') == 1} ); statement = QUOTE([ARR_3(_player, _target, currentWeapon _target)] call FUNC(swapBarrelAssistant);); icon = QUOTE(PATHTOF(UI\spare_barrel_ca.paa)); }; class GVAR(CheckTemperature) { displayName = CSTRING(CheckTemperatureShort); - condition = "switch (currentWeapon _target) do {case (''): {false}; case (primaryWeapon _target); case (handgunWeapon _target): {true}; default {false}}"; + condition = "ace_overheating_enabled && {switch (currentWeapon _target) do {case (''): {false}; case (primaryWeapon _target); case (handgunWeapon _target): {true}; default {false}}}"; exceptions[] = {"isNotInside", "isNotSitting"}; statement = QUOTE( [ARR_3(_player, _target, currentWeapon _target)] call FUNC(checkTemperature); ); icon = QUOTE(PATHTOF(UI\temp_ca.paa)); diff --git a/addons/overheating/XEH_postInit.sqf b/addons/overheating/XEH_postInit.sqf index 96d518ac9f..e4935b8831 100644 --- a/addons/overheating/XEH_postInit.sqf +++ b/addons/overheating/XEH_postInit.sqf @@ -1,62 +1,69 @@ // by esteldunedain #include "script_component.hpp" -if (isServer) then { - GVAR(pseudoRandomList) = []; - // Construct a list of pseudo random 2D vectors - for "_i" from 0 to 30 do { - GVAR(pseudoRandomList) pushBack [-1 + random 2, -1 + random 2]; - }; - publicVariable QGVAR(pseudoRandomList); +if (hasInterface) then { + // Add keybinds + ["ACE3 Weapons", QGVAR(unjamWeapon), localize LSTRING(UnjamWeapon), + { + // Conditions: canInteract + if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false}; + // Conditions: specific - // Keep track of the temperature of stored spare barrels - GVAR(storedSpareBarrels) = [] call CBA_fnc_hashCreate; + if !(GVAR(enabled) && {[ACE_player] call FUNC(canUnjam)}) exitWith {false}; - // Install event handlers for spare barrels - ["spareBarrelsSendTemperatureHint", FUNC(sendSpareBarrelsTemperaturesHint)] call EFUNC(common,addEventHandler); - ["spareBarrelsLoadCoolest", FUNC(loadCoolestSpareBarrel)] call EFUNC(common,addEventHandler); - - // Schedule cool down calculation of stored spare barrels - [] call FUNC(updateSpareBarrelsTemperaturesThread); + // Statement + [ACE_player, currentMuzzle ACE_player, false] call FUNC(clearJam); + true + }, + {false}, + [19, [true, false, false]], false] call CBA_fnc_addKeybind; //SHIFT + R Key }; - -if !(hasInterface) exitWith {}; - -GVAR(cacheWeaponData) = call CBA_fnc_createNamespace; -GVAR(cacheAmmoData) = call CBA_fnc_createNamespace; -GVAR(cacheSilencerData) = call CBA_fnc_createNamespace; - -// Add keybinds -["ACE3 Weapons", QGVAR(unjamWeapon), localize LSTRING(UnjamWeapon), -{ - // Conditions: canInteract - if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false}; - // Conditions: specific - - if !([ACE_player] call FUNC(canUnjam)) exitWith {false}; - - // Statement - [ACE_player, currentMuzzle ACE_player, false] call FUNC(clearJam); - true -}, -{false}, -[19, [true, false, false]], false] call CBA_fnc_addKeybind; //SHIFT + R Key - - -// Schedule cool down calculation of player weapons at (infrequent) regular intervals -[] call FUNC(updateTemperatureThread); - ["SettingsInitialized", { + TRACE_1("SettingsInitialized eh", GVAR(enabled)); + if (!GVAR(enabled)) exitWith {}; + + if (isServer) then { + GVAR(pseudoRandomList) = []; + // Construct a list of pseudo random 2D vectors + for "_i" from 0 to 30 do { + GVAR(pseudoRandomList) pushBack [-1 + random 2, -1 + random 2]; + }; + publicVariable QGVAR(pseudoRandomList); + + // Keep track of the temperature of stored spare barrels + GVAR(storedSpareBarrels) = [] call CBA_fnc_hashCreate; + + // Install event handlers for spare barrels + ["spareBarrelsSendTemperatureHint", FUNC(sendSpareBarrelsTemperaturesHint)] call EFUNC(common,addEventHandler); + ["spareBarrelsLoadCoolest", FUNC(loadCoolestSpareBarrel)] call EFUNC(common,addEventHandler); + + // Schedule cool down calculation of stored spare barrels + [] call FUNC(updateSpareBarrelsTemperaturesThread); + }; + + if !(hasInterface) exitWith {}; + + GVAR(cacheWeaponData) = call CBA_fnc_createNamespace; + GVAR(cacheAmmoData) = call CBA_fnc_createNamespace; + GVAR(cacheSilencerData) = call CBA_fnc_createNamespace; + + //Add Take EH (for reload) + ["CAManBase", "Take", {_this call FUNC(handleTakeEH);}] call CBA_fnc_addClassEventHandler; + // Register fire event handler ["firedPlayer", DFUNC(firedEH)] call EFUNC(common,addEventHandler); // Only add eh to non local players if dispersion is enabled if (GVAR(overheatingDispersion)) then { ["firedPlayerNonLocal", DFUNC(firedEH)] call EFUNC(common,addEventHandler); }; -}] call EFUNC(common,addEventHandler); -// Install event handler to display temp when a barrel was swapped -["showWeaponTemperature", DFUNC(displayTemperature)] call EFUNC(common,addEventHandler); -// Install event handler to initiate an assisted barrel swap -["initiateSwapBarrelAssisted", DFUNC(swapBarrel)] call EFUNC(common,addEventHandler); + // Schedule cool down calculation of player weapons at (infrequent) regular intervals + [] call FUNC(updateTemperatureThread); + + // Install event handler to display temp when a barrel was swapped + ["showWeaponTemperature", DFUNC(displayTemperature)] call EFUNC(common,addEventHandler); + // Install event handler to initiate an assisted barrel swap + ["initiateSwapBarrelAssisted", DFUNC(swapBarrel)] call EFUNC(common,addEventHandler); + +}] call EFUNC(common,addEventHandler); diff --git a/addons/overheating/functions/fnc_swapBarrelCallback.sqf b/addons/overheating/functions/fnc_swapBarrelCallback.sqf index 339b6627b1..403989deca 100644 --- a/addons/overheating/functions/fnc_swapBarrelCallback.sqf +++ b/addons/overheating/functions/fnc_swapBarrelCallback.sqf @@ -15,7 +15,7 @@ * * Public: No */ -#define DEBUG_MODE_FULL +// #define DEBUG_MODE_FULL #include "script_component.hpp" params ["_assistant", "_gunner", "_weapon"]; diff --git a/addons/overheating/functions/fnc_updateSpareBarrelsTemperaturesThread.sqf b/addons/overheating/functions/fnc_updateSpareBarrelsTemperaturesThread.sqf index 852cb1c580..d6b74f6769 100644 --- a/addons/overheating/functions/fnc_updateSpareBarrelsTemperaturesThread.sqf +++ b/addons/overheating/functions/fnc_updateSpareBarrelsTemperaturesThread.sqf @@ -13,7 +13,7 @@ * * Public: No */ -#define DEBUG_MODE_FULL +// #define DEBUG_MODE_FULL #include "script_component.hpp" private _pairs = []; diff --git a/addons/overheating/stringtable.xml b/addons/overheating/stringtable.xml index 3eb67701de..e49ad433fc 100644 --- a/addons/overheating/stringtable.xml +++ b/addons/overheating/stringtable.xml @@ -282,7 +282,15 @@ Very Hot Spare Barrel/s - Extremele Hot Spare Barrel/s + Extremely Hot Spare Barrel/s + + + Overheating Enabled + Überhitzen Aktiviert + Activada Sobrecalentamiento + + + Master enable for the overheating/jamming module \ No newline at end of file