DIFF

class ComponentEnergyManagerSource

ComponentEnergyManager Component

All members, including inherited

Constructors 2

void ComponentEnergyManager()
References m_DebugPlugs
void ~ComponentEnergyManager()

Constants 7

protected const float DEFAULT_UPDATE_INTERVAL = 15
Referenced by Event_OnAwake()
protected static const string SOCKET_ = "socket_"
protected static const string _PLUGGED = "_plugged"
protected static const string _AVAILABLE = "_available"
static const string SEL_CORD_PLUGGED = "cord_plugged"
static const string SEL_CORD_FOLDED = "cord_folded"
const int MAX_SOCKETS_COUNT = 4
Referenced by Event_OnAwake()

Members 43

protected static bool m_DebugPlugs = false

true; // Use this to toggle visualisation of plug connections

protected Shape m_DebugPlugArrow
protected bool m_IsSwichedOn
protected bool m_IsSwichedOnPreviousState

Necesarry due to synchronization of m_IsSwichedOn

protected bool m_IsPassiveDevice
Referenced by DeviceUpdate(), Event_OnAwake(), IsPassive()
Show 2 more, SetPassiveState(), and StartUpdates()
protected bool m_IsWorking
Referenced by IsWorking(), and SetPowered()
protected bool m_CanWork
Referenced by CanWork(), DeviceUpdate(), Event_OnAwake()
Show 1 more, UpdateCanWork()
protected bool m_CanStopWork
Referenced by DeviceUpdate()
protected bool m_RestorePlugState

After server restart, this value reports if this device was plugged into something or not at the end of last session.

protected bool m_AutoSwitchOff
Referenced by DeviceUpdate(), and Event_OnAwake()
protected bool m_ShowSocketsInInventory
protected bool m_HasElectricityIcon

Electricity icon over the item in inventory

protected bool m_AutoSwitchOffWhenInCargo
protected bool m_IsPlugged

Synchronized variable

Referenced by IsPlugged(), and SetEnergySource()
protected bool m_ConvertEnergyToQuantity
protected int m_MySocketID = -1
Referenced by GetMySocketID(), and SetMySocketID()
protected int m_PlugType
protected int m_EnergySourceStorageIDb1

Storage persistence ID

protected int m_EnergySourceStorageIDb2

Storage persistence ID

protected int m_EnergySourceStorageIDb3

Storage persistence ID

protected int m_EnergySourceStorageIDb4

Storage persistence ID

protected int m_AttachmentActionType
protected int m_EnergySourceNetworkIDLow = -1

Network ID

protected int m_EnergySourceNetworkIDHigh = -1

Network ID

protected float m_EnergyUsage
protected float m_Energy
Referenced by Event_OnAwake(), GetEnergy(), GetEnergy0To1()
Show 2 more, GetEnergy0To100(), and SetEnergy()
protected float m_EnergyAtSpawn
protected float m_EnergyStorageMax
protected float m_ReduceMaxEnergyByDamageCoef
Referenced by Event_OnAwake(), and GetEnergyMax()
protected float m_SocketsCount
protected float m_CordLength
protected float m_LastUpdateTime
protected float m_WetnessExposure
protected float m_UpdateInterval

Interval of OnWork(...) calls and device updates.

protected string m_CordTextureFile
protected ref TIntArray m_CompatiblePlugTypes
EntityAI m_EnergySource

Energy source can be any EntityAI object

ref array<EntityAI> m_PluggedDevices
ref map<string,EntityAI> m_DeviceByPlugSelection
ref Timer m_UpdateTimer
Referenced by StartUpdates(), and StopUpdates()
ref Timer m_UpdateQuantityTimer
Referenced by Event_OnAwake(), and OnEnergyAdded()
ref Timer m_DebugUpdate
EntityAI m_Sockets[MAX_SOCKETS_COUNT]

Methods 116

override void Event_OnInit()
Shape DrawArrow(vector from, vector to, float size = 0.5, int color = 0xFFFFFFFF, float flags = 0)
Referenced by DebugUpdate()
EntityAI GetThisEntityAI()
override int GetCompType()
void RefreshDebug()
Referenced by SetDebugPlugs()
bool GetDebugPlugs()
References m_DebugPlugs
Referenced by DebugUpdate()
void SetDebugPlugs(bool newVal)
void SwitchOn()

Energy manager: Switches ON the device so it starts doing its work if it has enough energy.

void SwitchOff()

Energy manager: Switches OFF the device.

Referenced by ActionExtinquishTorchVideo.OnStartServer(), ActionLightItemOnFireWithBlowtorch.OnEndServer(), ActionLightItemOnFireWithBlowtorch.OnFinishProgressServer()
Show 40 more, ActionRepairBoatEngine.OnEndServer(), ActionRepairCarChassisWithBlowtorch.OnEndServer(), ActionRepairCarEngineWithBlowtorch.OnEndServer(), ActionRepairCarPartWithBlowtorch.OnEndServer(), ActionRepairItemWithBlowtorch.OnEndServer(), ActionTurnOffHeadtorch.Start(), ActionTurnOffHelmetFlashlight.Start(), ActionTurnOffPowerGenerator.OnExecuteServer(), ActionTurnOffSpotlight.OnExecuteServer(), ActionTurnOffTransmitter.OnExecuteServer(), ActionTurnOffWeaponFlashlight.OnExecuteServer(), ActionTurnOffWhileInHands.OnExecuteServer(), ActionTurnOffWhileOnGround.OnExecuteServer(), ActionViewOptics.ExitOptics(), AdvancedCommunication.TurnOffTransmitter(), DeviceUpdate(), HandleMoveInsideCargo(), OnDeviceDestroyed(), DayZPlayerImplement.SwitchOptics(), Defibrillator.DischargeServer(), Defibrillator.OnWorkStop(), EntityAI.OnVariablesSynchronized(), ExtinguishTorch.Do(), FlammableBase.OnItemInHandsPlayerSwimStart(), FlammableBase.OnSwitchOn(), Land_Radio_PanelBig.OnSwitchOn(), Land_Radio_PanelBig.OnWorkStop(), Land_Radio_PanelPAS.OnSwitchOn(), Land_WarheadStorage_PowerStation.OnLeverToggled(), Megaphone.OnSwitchOn(), Megaphone.OnWorkStop(), NVGoggles.RotateGoggles(), PlayerBase.OnCommandVehicleStart(), PlayerBase.SetEnergyManagerState(), PoweredOptic_Base.StopWorkServer(), PowerGeneratorBase.EEItemDetached(), Radio.OnWorkStop(), Spotlight.Fold(), TransmitterBase.OnSwitchOn(), and TransmitterBase.OnWorkStop()
void SetPassiveState(bool state = true)

Energy manager: Changes the status of this device. When it's passive (true), the main timer and OnWork events are not used.

void UnplugAllDevices()

Energy manager: Unplugs everything directly connected to this device

void RestorePlugState(bool state)
void SetEnergy0To1(float energy01)

Energy manager: Sets stored energy for this device between 0 and MAX based on relative input value between 0 and 1

void UpdateSelections()

Energy manager: Shows/Hides all selections this system works with. Call this if something is wrong with selections (like during Init and Restore event in config)

void GetCompatiblePlugTypes(out TIntArray IDs)
void StoreEnergySourceIDs(int b1, int b2, int b3, int b4)
void SetEnergyMaxPristine(float new_limit)

Energy manager: Changes the maximum amount of energy this device can store (when pristine).

void SetCordLength(float new_length)

Energy manager: Changes the length of the virtual power cord.

References m_CordLength
void SetPlugType(int new_type)
References m_PlugType
void SetAttachmentAction(int new_action_type)
void SetEnergyUsage(float new_usage)

Energy manager: Changes the energy usage per second.

References m_EnergyUsage
void ResetEnergyUsage()

Energy manager: Resets energy usage to default (config) value.

void SetCordTextureFile(string new_path)
void SetEnergySourceClient(EntityAI source)
void SetDeviceBySocketID(int id, EntityAI plugged_device)

Energy manager: Stores the device which is plugged into the given socket ID.

References m_Sockets
void SetElectricityIconVisibility(bool make_visible)

Energy manager: Sets visibility of the electricity icon (bolt).

void HandleMoveInsideCargo(EntityAI container)
void SetUpdateInterval(float value)

Energy manager: Sets the interval of the OnWork(...) calls. Changing this value does not change the rate of energy consumption.

References m_UpdateInterval
Referenced by Event_OnAwake()
bool GetRestorePlugState()
bool PlugThisInto(EntityAI energy_source, int socket_id = -1)

Energy manager: Attempts to plug this device into the energy_source. Returns true if the action was successfull, or false if not (due to plug incompatibility or no free socket on the receiver). The ID of the power socket is chosen automatically unless optional parameter socket_id is used (starting from 0). If the given ID is not free then a free socket is found.

bool CanWork(float test_energy = -1)

Energy manager: Checks whenever this device can do work or not.

test_energy
float optional parameter will overwite the default energy consumption value of this device.

Returns: bool Returns true if this device will work when it's switched on. Otherwise it returns false.

bool CheckWetness()

Energy manager: Checks if this device is being stopped from working by its wetness level. Returns true when its wetness is not blocking it, false when its to owet to work.

bool IsCordFolded()

Energy manager: Returns true if the cord of this device is folded. Returns false if it's plugged.

References IsPlugged()
bool IsPassive()

Energy manager: Returns true if this device is set to be passive. False if otherwise.

bool ConsumeEnergy(float amount)

Energy manager: Consumes the given amount of energy. If there is not enough of stored energy in this device, then it tries to take it from its power source, if any exists. Returns true if the requested amount of energy was consumed. Otherwise it returns false.

bool IsWorking()

Energy manager: Returns true if this device is working right now.

References m_IsWorking
Referenced by ActionBreakLongWoodenStick.ActionCondition(), ActionLightItemOnFireWithBlowtorch.OnUpdateServer(), ActionRaiseMegaphone.ActionCondition()
Show 45 more, ActionTuneFrequency.ActionCondition(), ActionTuneFrequencyOnGround.ActionCondition(), ActionTurnOffTransmitter.ActionCondition(), ActionTurnOnTransmitter.ActionCondition(), BarbedWire.OnPlacementComplete(), BatteryCharger.UpdateStatusLights(), Blowtorch.IsIgnited(), Chemlight_ColorBase.EEHealthLevelChanged(), Chemlight_ColorBase.StandUp(), DeviceUpdate(), OnDeviceDestroyed(), SwitchOff(), Defibrillator.OnIsCharged(), EntityAI.GetDebugText(), EntityAI.IsIgnited(), FlammableBase.CanBeTakenAsCargo(), FlammableBase.CanIgniteItem(), FlammableBase.CanPutAsAttachment(), FlammableBase.CanReleaseAttachment(), FlammableBase.GetMeleeHeavyMode(), FlammableBase.GetMeleeMode(), FlammableBase.GetMeleeSprintMode(), FlammableBase.IsIgnited(), FlammableBase.OnAttachmentQuantityChangedEx(), FlammableBase.UpdateMaterial(), Flashlight.OnInventoryExit(), GPSReceiver.IsTurnedOn(), Heatpack.IsSelfAdjustingTemperature(), Land_WarheadStorage_PowerStation.GetClosestBunker(), Land_WarheadStorage_PowerStation.LinkPowerGeneratorServer(), PortableGasStove.CanIgniteItem(), PortableGasStove.IsIgnited(), PortableGasStove.IsSelfAdjustingTemperature(), PowerGeneratorBase.CanManipulate(), PowerGeneratorBase.StartLoopSound(), PowerGeneratorStatic.CanReleaseAttachment(), Rag.CanBeSplit(), Roadflare.CanIgniteItem(), SharpenBroom.CanDo(), SmokeGrenadeBase.CanPutInCargo(), SplitBroom.CanDo(), Spotlight.UpdateAllSelections(), TLRLight.OnInventoryExit(), UniversalLight.OnInventoryExit(), and XmasLights.TurnOnItem()
bool HasEnoughStoredEnergy()

Energy manager: Returns true if this device has enough of stored energy for its own use.

bool HasFreeSocket(int socket_id = -1)

Energy manager: Returns true if this device has any free socket to receive a plug. If optional parameter socket_id is provided then only that socket ID is checked.

bool IsPlugCompatible(int plug_ID)

Energy manager: Checks if the given plug is compatible with this device's socket. Used by CanReceivePlugFrom() method.

bool CanReceivePlugFrom(EntityAI device_to_plug)

Energy manager: Returns true if this device can receive power plug of the other device.

bool CanBePluggedInto(EntityAI potential_energy_provider)

Energy manager: Returns true if this device can be plugged into the given energy source. Otherwise returns false.

bool HasElectricityIcon()

Energy manager: Returns true if the electricity icon (bolt) is supposed to be visible for this device. False if not.

bool HasConversionOfEnergyToQuantity()

Energy manager: Returns true if this item automatically converts its energy to quantity

bool IsEnergySourceAtReach(vector from_position, float add_tolerance = 0, vector override_source_position = "-1 -1 -1")

Energy manager: Returns true if this device's virtual power cord can reach its energy source at the given position, depending on its cordLength config parameter. Otherwise returns false.

from_position
vector position from where the measurement will be taken
add_tolerance
float parameter will add to the cord's length in meters (optional)

Returns: bool True if the power source will be at reach for the plug, or if config param cordLength is absent or 0. False if not, or is not plugged, or this device lacks Energy Manager component.

vector position_player = g_Game.GetPlayer().GetPosition();

if ( my_device.GetCompEM().IsEnergySourceAtReach( position_player )  )
{
	Print("Power source is at reach!");
}else{
	Print("Power source is NOT at reach!");
}
bool HasVisibleSocketsInInventory()
bool IsSelectionAPlug(string selection_to_test)

Energy manager: Returns true if this selection is a plug that's plugged into this device. Otherwise returns false.

References GetPluggedDevices(), GetSocketsCount(), int.ToString()
Show 2 more, _PLUGGED, and SOCKET_
int GetSocketsCount()

Energy manager: Returns the count of power sockets (whenever used or not)

References m_SocketsCount
int GetPlugType()

Energy manager: Returns plug type. Check \DZ\data\basicDefines.hpp OR \Scripts\Classes\Component\_constants.h files for types of plugs

References m_PlugType
int GetAttachmentAction()
int GetEnergySourceStorageIDb1()
int GetEnergySourceStorageIDb2()
int GetEnergySourceStorageIDb3()
int GetEnergySourceStorageIDb4()
int GetEnergySourceNetworkIDLow()
int GetEnergySourceNetworkIDHigh()
int GetPluggedDevicesCount()

Energy manager: Returns the number of devices plugged into this one.

int GetEnergy0To100()

Energy manager: Returns % of stored energy this device has as integer (from 0 to 100)

float GetWetnessExposure()

Returns wetness exposure value defined in config

float GetEnergyUsage()

Energy manager: Returns the number of energy this device needs to run itself (See its config >> energyUsagePerSecond)

References m_EnergyUsage
float AddEnergy(float added_energy)

Energy manager: Adds energy to this device and clamps it within its min/max storage limits. Returns the amount of energy that was clamped. Negative value is supported, but you should still use ConsumeEnergy(...) for propper substraction of energy.

float GetEnergyMax()

Energy manager: Returns the maximum amount of energy this device can curently store. If parameter 'reduceMaxEnergyByDamageCoef' is used in the config of this device then the returned value will be reduced by damage.

float GetEnergyMaxPristine()

Energy manager: Returns the maximum amount of energy this device can store. It's damage is NOT taken into account.

float GetEnergyAtSpawn()
References m_EnergyAtSpawn
float GetCordLength()

Energy manager: Returns the length of the virtual power cord.

References m_CordLength
EntityAI GetDeviceBySocketID(int id)

Energy manager: Returns the device which is plugged into the given socket ID.

References m_Sockets
EntityAI GetPlugOwner(string plug_selection_name)

Energy manager: Returns the device to which the given plug selection belongs to

string GetCordTextureFile()

Energy manager: Returns path to the cord texture file.

array<EntityAI> GetPluggedDevices()

Energy manager: Returns an array of devices which are plugged into this one

References m_PluggedDevices
array<EntityAI> GetPoweredDevices()

Energy manager: Returns an array of devices which are plugged into this one and are turned on

void OnWork(float consumed_energy)
Referenced by DeviceUpdate()
void OnIsUnplugged(EntityAI last_energy_source)
Referenced by UnplugDevice()
void OnAttachmentAdded(EntityAI elec_device)
void OnAttachmentRemoved(EntityAI elec_device)
void OnEnergyConsumed()

Energy manager: Called when energy was consumed on this device

Referenced by AddEnergy()
void OnEnergyAdded()

Energy manager: Called when energy was added on this device

Referenced by AddEnergy()
protected void StopUpdates()
References Timer.Stop(), and m_UpdateTimer
Referenced by DeviceUpdate(), and SwitchOff()
void InteractBranch(EntityAI originalCaller, Man player = null, int system = 0)

Gets called originally when the player is interacting with an item containing this energy component, then recursively following the branches of connection from the original item to the peripheries External calling of this function is not automatic for all item interactions and may need to be implemented on case by case bases Avoid using for gameplay logic, use 'OnInteractBranch' instead

protected void OnInteractBranch(EntityAI originalCaller, Man player, int system)

Called when the player is interacting with an item containing this energy component, or when interacting with an item this device is connected to

Referenced by InteractBranch()
protected void WakeUpWholeBranch(EntityAI original_caller)
protected void PlugCordIntoSocket(EntityAI device_to_plug, int socket_id = -1)
Referenced by PlugInDevice()
protected void SetPlugOwner(string selection_name, EntityAI device)
protected void SetPowered(bool state)
References m_IsWorking
protected bool FindAndConsumeEnergy(EntityAI original_caller, float amount, bool ignore_switch_state = false)
protected int GetMySocketID()
References m_MySocketID
Referenced by UnplugDevice()
protected void SetMySocketID(int slot_ID)
References m_MySocketID
void ClearLastUpdateTime()
References m_LastUpdateTime
Referenced by DeviceUpdate()
void RememberLastUpdateTime()
Referenced by DeviceUpdate()
float GetCurrentUpdateTime()
References CGame.GetTime()