michail-nikolaev / task-force-arma-3-radio

TeamSpeak integration for Arma 3
http://radio.task-force.ru/en/
Other
313 stars 169 forks source link

battery usage #493

Open kavinsky opened 10 years ago

kavinsky commented 10 years ago

Add battery usage to radios

michail-nikolaev commented 10 years ago

moved to backlog.

Also, as I know even inbuilt batteries allow to use radio more than 4-6 hours - much more than real Arma game....

kavinsky commented 10 years ago

this could usefull for long endurance missions, saved with alive or local save.

CorruptedHeart commented 9 years ago

Once https://github.com/michail-nikolaev/task-force-arma-3-radio/pull/834 is merged, I'll take a look at this. It could be useful in situations where you'd like certain players to be cut off from others and low on radio battery and the like. It would need config entries

class radio {
    tf_batteryLife = 360; // in minutes
    tf_battery = "TF_SmallBattery"; // This is optional, but it could allow specific battery items
// for different radios for refilling them. Might be beneficial to make it an array,
// to support different battery types but that will change the following code to use the battery
// as an indication of total battery life and not the radio.
};

A couple variables (perhaps as an array) in the settings of the radio.

drain - NUMBER: the amount of drain the battery has taken.
lastDrainTime - NUMBER: time when the battery level was last adjusted

So every 15-20 seconds it will loop through all ON radios and adjust their battery level according to the drain.

tf_batteryDrain = [] spawn {
    while {true} do {
        private ["_allRadios"];
        sleep 20;
        _allRadios = currentUnit call TFAR_fnc_radiosList;
        {
            if (([_x] call TFAR_fnc_radioOn)) then {
                _battery = [_x] call TFAR_fnc_batteryLevel;
                _drain = (_battery select 0) + (time - (_battery select 1));
                _battery = [_drain, time];
                if (_drain >= getNumber(ConfigFile >> "CfgWeapons" >> _x >> "tf_batteryLife")) then {
                    _battery set [0, getNumber(ConfigFile >> "CfgWeapons" >> _x >> "tf_batteryLife")];
                };
                [_radio, _battery] call TFAR_fnc_batteryLevel;
            };
            false
        } count _allRadios;
        _radio = currentUnit call TFAR_fnc_backpackLR;
        if (([_radio] call TFAR_fnc_radioOn)) then {
            _battery = [_radio] call TFAR_fnc_batteryLevel;
            _drain = (_battery select 0) + (time - (_battery select 1));
                _battery = [_drain, time];
                if (_drain >= getNumber(ConfigFile >> "CfgVehicles" >> typeof (_radio select 0) >> "tf_batteryLife")) then {
                    _battery set [0, ConfigFile >> "CfgVehicles" >> typeof (_radio select 0) >> "tf_batteryLife")];
                };
                [_radio, _battery] call TFAR_fnc_batteryLevel;
        };
    };
};
// When a radio is switched ON, set the time to the current time.
// When the radio is switched OFF, drain the battery according to the time passed at that point.
michail-nikolaev commented 9 years ago

@CorruptedHeart I think we should to think about it before. For first - battery should be unique item. And, also, I want to create a modular system where is possible to attach devices to radio (antennas, batteries, transeivers, GPS, etc). We need to design it first catefully (to change dialog image according to devices, devices should use energy, etc).

jonpas commented 9 years ago

Also, if/when this is implemented, an option to disable it via module/server config would be needed, not everyone wants a full radio simulator.

michail-nikolaev commented 9 years ago

@jonpas it will not disabled by default but I always keep system easy to use. So, you start - and you could use radio. But if you want - put devices, change power and etc.

jonpas commented 9 years ago

I was aiming toward battery specifically. Antennas, Transceivers, GPS, that I don't mind. :)

michail-nikolaev commented 9 years ago

@jonpas in default mod battery should work long enough for typical MP game.

jonpas commented 9 years ago

Sounds good to me, good work.