2016-03-01 21:14:36 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2016-03-06 02:33:30 +00:00
|
|
|
* 0: Unit that has the spare barrels <OBJECT>
|
|
|
|
* 1: Unit that has the weapon <OBJECT>
|
|
|
|
* 2: Weapon <STRING>
|
|
|
|
* 3: Weapon temp before switching <NUMBER>
|
|
|
|
* 4: Mass of the removed barrel <NUMBER>
|
2016-03-01 21:14:36 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2016-03-01 21:14:36 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2016-03-06 02:33:30 +00:00
|
|
|
params ["_assistant", "_gunner", "_weapon", "_weaponTemp", "_barrelMass"];
|
|
|
|
TRACE_5("loadCoolestSpareBarrel1",_assistant,_gunner,_weapon,_weaponTemp,_barrelMass);
|
2016-08-27 08:21:15 +00:00
|
|
|
private _weaponBarrelClass = getText (configFile >> 'CfgWeapons' >> _weapon >> QGVAR(barrelClassname));
|
|
|
|
//If the weapon has no defined classname then use the ACE one
|
|
|
|
if(_weaponBarrelClass == "") then {
|
|
|
|
_weaponBarrelClass = "ACE_SpareBarrel";
|
|
|
|
};
|
2016-03-01 21:14:36 +00:00
|
|
|
// Find all spare barrel the player has
|
2016-08-27 08:21:15 +00:00
|
|
|
private _allBarrels = [_assistant, _weaponBarrelClass] call CBA_fnc_getMagazineIndex;
|
2016-03-01 22:26:20 +00:00
|
|
|
TRACE_1("_allBarrels",_allBarrels);
|
|
|
|
if ((count _allBarrels) < 1) exitWith {};
|
2016-03-01 21:14:36 +00:00
|
|
|
|
|
|
|
// Determine which on is coolest
|
|
|
|
private _coolestTemp = 10000;
|
2016-03-01 22:26:20 +00:00
|
|
|
private _coolestMag = _allBarrels select 0;
|
2016-03-01 21:14:36 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
};
|
2016-03-01 22:26:20 +00:00
|
|
|
} forEach _allBarrels;
|
2016-03-01 21:14:36 +00:00
|
|
|
TRACE_3("loadCoolestSpareBarrel5",_coolestTemp,_coolestMag,_weaponTemp);
|
|
|
|
|
|
|
|
// The new weapon temperature is similar to the coolest barrel
|
|
|
|
// Publish the new temperature value
|
2016-03-06 02:33:30 +00:00
|
|
|
_gunner setVariable [format [QGVAR(%1_temp), _weapon], _coolestTemp, true];
|
2016-03-01 21:14:36 +00:00
|
|
|
|
|
|
|
// Heat up the coolest barrel to the former weapon temperature
|
2016-05-18 09:57:40 +00:00
|
|
|
[GVAR(storedSpareBarrels), _coolestMag, [_weaponTemp, CBA_missionTime, _barrelMass]] call CBA_fnc_hashSet;
|
2016-03-01 22:26:20 +00:00
|
|
|
|
2016-03-06 02:33:30 +00:00
|
|
|
// Send an event so the machines of the assistant and gunner can show the hint
|
2016-07-03 17:58:40 +00:00
|
|
|
[QGVAR(showWeaponTemperature), [_gunner, _weapon], [_assistant, _gunner]] call CBA_fnc_targetEvent;
|