Move spare barrel event handlers out of postInit

This commit is contained in:
esteldunedain 2016-03-01 18:14:36 -03:00
parent bc4a338d32
commit 46a96dd5da
5 changed files with 132 additions and 95 deletions

View File

@ -8,7 +8,9 @@ PREP(firedEH);
PREP(getWeaponData);
PREP(handleTakeEH);
PREP(jamWeapon);
PREP(loadCoolestSpareBarrel);
PREP(overheat);
PREP(sendSpareBarrelsTemperaturesHint);
PREP(swapBarrel);
PREP(swapBarrelCallback);
PREP(updateSpareBarrelsTemperaturesThread);

View File

@ -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 "<br/>";
_size = _size + 0.5;
};
if (_countWarm > 0) then {
_output pushBack _countWarm;
_output pushBack LSTRING(BarrelWarm);
_output pushBack "<br/>";
_size = _size + 0.5;
};
if (_countHot > 0) then {
_output pushBack _countHot;
_output pushBack LSTRING(BarrelHot);
_output pushBack "<br/>";
_size = _size + 0.5;
};
if (_countVeryHot > 0) then {
_output pushBack _countVeryHot;
_output pushBack LSTRING(BarrelVeryHot);
_output pushBack "<br/>";
_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);

View File

@ -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 <OBJECT>
* 1: Weapon <STRING>
* 2: Weapon temp before switching <NUMBER>
* 3: Mass of the removed barrel <NUMBER>
*
* 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;

View File

@ -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 <OBJECT>
* 1: Unit that has the spare barrels <STRING>
*
* 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 "<br/>";
_size = _size + 0.5;
};
if (_countWarm > 0) then {
_output pushBack _countWarm;
_output pushBack LSTRING(BarrelWarm);
_output pushBack "<br/>";
_size = _size + 0.5;
};
if (_countHot > 0) then {
_output pushBack _countHot;
_output pushBack LSTRING(BarrelHot);
_output pushBack "<br/>";
_size = _size + 0.5;
};
if (_countVeryHot > 0) then {
_output pushBack _countVeryHot;
_output pushBack LSTRING(BarrelVeryHot);
_output pushBack "<br/>";
_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);

View File

@ -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];