PC Stable Documentation
 
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Loading...
Searching...
No Matches
ComponentEnergyManager Class Reference

Private Member Functions

void ComponentEnergyManager ()
 
void ~ComponentEnergyManager ()
 
override void Event_OnInit ()
 
void DebugUpdate ()
 
Shape DrawArrow (vector from, vector to, float size=0.5, int color=0xFFFFFFFF, float flags=0)
 
EntityAI GetThisEntityAI ()
 
override void Event_OnAwake ()
 
override int GetCompType ()
 
void OnDeviceDestroyed ()
 
void RefreshDebug ()
 
bool GetDebugPlugs ()
 
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.
 
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 UnplugDevice (EntityAI device_to_unplug)
 Energy manager: Unplugs the given device from this one.
 
void UnplugThis ()
 Energy manager: Unplugs this device from its power source.
 
void UnplugAllDevices ()
 Energy manager: Unplugs everything directly connected to this device.
 
void RestorePlugState (bool state)
 
void SetEnergy (float new_energy)
 Energy manager: Sets stored energy for this device. It ignores the min/max limit!
 
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 UpdatePlugState ()
 Energy manager: Unplugs this device when it's necesarry.
 
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.
 
void SetPlugType (int new_type)
 
void SetAttachmentAction (int new_action_type)
 
void SetEnergyUsage (float new_usage)
 Energy manager: Changes the energy usage per second.
 
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.
 
void SetElectricityIconVisibility (bool make_visible)
 Energy manager: Sets visibility of the electricity icon (bolt).
 
void UpdateCanWork ()
 
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.
 
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 CanSwitchOn ()
 Energy manager: Checks if the device can be switched ON.
 
bool CanWork (float test_energy=-1)
 Energy manager: Checks whenever this device can do work or not.
 
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 CanSwitchOff ()
 Energy manager: Checks if the device can be switched OFF.
 
bool GetPreviousSwitchState ()
 
bool IsSwitchedOn ()
 Energy manager: Returns state of the switch. Whenever the device is working or not does not matter. Use IsWorking() to account for that as well.
 
bool IsCordFolded ()
 Energy manager: Returns true if the cord of this device is folded. Returns false if it's plugged.
 
bool IsPassive ()
 Energy manager: Returns true if this device is set to be passive. False if otherwise.
 
bool IsPlugged ()
 Energy manager: Returns true if this device is plugged into some other device (even if they are OFF or ruined). Otherwise it returns false.
 
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.
 
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.
 
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.
 
int GetSocketsCount ()
 Energy manager: Returns the count of power sockets (whenever used or not)
 
int GetPlugType ()
 Energy manager: Returns plug type. Check \DZ\data\basicDefines.hpp OR \Scripts\Classes\Component_constants.h files for types of plugs.
 
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 GetEnergy0To1 ()
 Energy manager: Returns % of stored energy this device has as float (from 0.0 to 1.0)
 
float GetUpdateInterval ()
 Energy manager: Returns the update interval of this device.
 
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)
 
float GetEnergy ()
 Energy manager: Returns the amount of stored energy this device has.
 
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 ()
 
float GetCordLength ()
 Energy manager: Returns the length of the virtual power cord.
 
EntityAI GetEnergySource ()
 Energy manager: Returns the energy source this device is plugged into.
 
EntityAI GetDeviceBySocketID (int id)
 Energy manager: Returns the device which is plugged into the given socket ID.
 
EntityAI GetPlugOwner (string plug_selection_name)
 Energy manager: Returns the device to which the given plug selection belongs to.
 
EntityAI GetPluggedDevice ()
 Energy manager: Returns a device which is plugged into this one. If there are more devices to choose from then it returns the first one that is found.
 
string GetCordTextureFile ()
 Energy manager: Returns path to the cord texture file.
 
array< EntityAIGetPluggedDevices ()
 Energy manager: Returns an array of devices which are plugged into this one.
 
array< EntityAIGetPoweredDevices ()
 Energy manager: Returns an array of devices which are plugged into this one and are turned on.
 
void OnWork (float consumed_energy)
 
void OnIsPlugged (EntityAI source_device)
 
void OnIsUnplugged (EntityAI last_energy_source)
 
void OnOwnSocketTaken (EntityAI device)
 
void OnOwnSocketReleased (EntityAI device)
 
void OnAttachmentAdded (EntityAI elec_device)
 
void OnAttachmentRemoved (EntityAI elec_device)
 
void StartUpdates ()
 
void OnEnergyConsumed ()
 Energy manager: Called when energy was consumed on this device.
 
void OnEnergyAdded ()
 Energy manager: Called when energy was added on this device.
 
protected void StopUpdates ()
 
void InteractBranch (EntityAI originalCaller, Man player=null, int system=0)
 
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.
 
protected void WakeUpWholeBranch (EntityAI original_caller)
 
protected void PlugCordIntoSocket (EntityAI device_to_plug, int socket_id=-1)
 
protected void UpdateSocketSelections (int socket_id, EntityAI device_to_plug)
 
protected void SetEnergySource (EntityAI source)
 
protected bool PlugInDevice (EntityAI device_to_plug, int socket_id=-1)
 
protected void SetPlugOwner (string selection_name, EntityAI device)
 
protected void UnplugCordFromSocket (int socket_to_unplug_ID)
 
protected void SetPowered (bool state)
 
protected bool FindAndConsumeEnergy (EntityAI original_caller, float amount, bool ignore_switch_state=false)
 
protected int GetMySocketID ()
 
protected void SetMySocketID (int slot_ID)
 
void Synch ()
 
void ClearLastUpdateTime ()
 
void RememberLastUpdateTime ()
 
float GetCurrentUpdateTime ()
 
void DeviceUpdate ()
 

Private Attributes

protected const float DEFAULT_UPDATE_INTERVAL = 15
 
protected Shape m_DebugPlugArrow
 
protected bool m_IsSwichedOn
 
protected bool m_IsSwichedOnPreviousState
 
protected bool m_IsPassiveDevice
 
protected bool m_IsWorking
 
protected bool m_CanWork
 
protected bool m_CanStopWork
 
protected bool m_RestorePlugState
 
protected bool m_AutoSwitchOff
 
protected bool m_ShowSocketsInInventory
 
protected bool m_HasElectricityIcon
 
protected bool m_AutoSwitchOffWhenInCargo
 
protected bool m_IsPlugged
 
protected bool m_ConvertEnergyToQuantity
 
protected int m_MySocketID = -1
 
protected int m_PlugType
 
protected int m_EnergySourceStorageIDb1
 
protected int m_EnergySourceStorageIDb2
 
protected int m_EnergySourceStorageIDb3
 
protected int m_EnergySourceStorageIDb4
 
protected int m_AttachmentActionType
 
protected int m_EnergySourceNetworkIDLow = -1
 
protected int m_EnergySourceNetworkIDHigh = -1
 
protected float m_EnergyUsage
 
protected float m_Energy
 
protected float m_EnergyAtSpawn
 
protected float m_EnergyStorageMax
 
protected float m_ReduceMaxEnergyByDamageCoef
 
protected float m_SocketsCount
 
protected float m_CordLength
 
protected float m_LastUpdateTime
 
protected float m_WetnessExposure
 
protected float m_UpdateInterval
 
protected string m_CordTextureFile
 
protected ref TIntArray m_CompatiblePlugTypes
 
EntityAI m_EnergySource
 
ref array< EntityAIm_PluggedDevices
 
ref map< string, EntityAIm_DeviceByPlugSelection
 
ref Timer m_UpdateTimer
 
ref Timer m_UpdateQuantityTimer
 
ref Timer m_DebugUpdate
 
const int MAX_SOCKETS_COUNT = 4
 
EntityAI m_Sockets [MAX_SOCKETS_COUNT]
 

Static Private Attributes

static protected bool m_DebugPlugs = false
 
static protected const string SOCKET_ = "socket_"
 
static protected const string _PLUGGED = "_plugged"
 
static protected const string _AVAILABLE = "_available"
 
static const string SEL_CORD_PLUGGED = "cord_plugged"
 
static const string SEL_CORD_FOLDED = "cord_folded"
 

Constructor & Destructor Documentation

◆ ComponentEnergyManager()

void ComponentEnergyManager ( )
inlineprivate

References m_DebugPlugs.

◆ ~ComponentEnergyManager()

void ~ComponentEnergyManager ( )
inlineprivate

References m_DebugPlugArrow.

Member Function Documentation

◆ AddEnergy()

float AddEnergy ( float  added_energy)
inlineprivate

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.

References Math::Clamp(), GetEnergy(), GetEnergyMax(), OnEnergyAdded(), OnEnergyConsumed(), SetEnergy(), and StartUpdates().

Referenced by FindAndConsumeEnergy(), and ItemBase::OnIgnitedTarget().

◆ CanBePluggedInto()

bool CanBePluggedInto ( EntityAI  potential_energy_provider)
inlineprivate

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

References Component::m_ThisEntityAI.

◆ CanReceivePlugFrom()

bool CanReceivePlugFrom ( EntityAI  device_to_plug)
inlineprivate

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

References HasFreeSocket(), IsPlugCompatible(), and Component::m_ThisEntityAI.

Referenced by PlugInDevice().

◆ CanSwitchOff()

bool CanSwitchOff ( )
inlineprivate

Energy manager: Checks if the device can be switched OFF.

References IsPassive(), and IsSwitchedOn().

Referenced by SwitchOff().

◆ CanSwitchOn()

bool CanSwitchOn ( )
inlineprivate

Energy manager: Checks if the device can be switched ON.

References IsSwitchedOn().

Referenced by SwitchOn().

◆ CanWork()

bool CanWork ( float  test_energy = -1)
inlineprivate

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

Parameters
test_energyfloat 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.

References CheckWetness(), DPrint(), GetEnergy(), GetEnergySource(), GetEnergyUsage(), GetGame(), m_CanWork, and Component::m_ThisEntityAI.

Referenced by UpdateCanWork().

◆ CheckWetness()

bool CheckWetness ( )
inlineprivate

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.

References Component::m_ThisEntityAI, and m_WetnessExposure.

Referenced by CanWork(), and DeviceUpdate().

◆ ClearLastUpdateTime()

void ClearLastUpdateTime ( )
inlineprivate

References m_LastUpdateTime.

Referenced by DeviceUpdate().

◆ ConsumeEnergy()

bool ConsumeEnergy ( float  amount)
inlineprivate

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.

References FindAndConsumeEnergy(), and Component::m_ThisEntityAI.

Referenced by DeviceUpdate().

◆ DebugUpdate()

◆ DeviceUpdate()

◆ DrawArrow()

Shape DrawArrow ( vector  from,
vector  to,
float  size = 0.5,
int  color = 0xFFFFFFFF,
float  flags = 0 
)
inlineprivate

References vector::Normalize(), vector::Perpend(), and Shape.

Referenced by DebugUpdate().

◆ Event_OnAwake()

◆ Event_OnInit()

override void Event_OnInit ( )
inlineprivate

◆ FindAndConsumeEnergy()

protected bool FindAndConsumeEnergy ( EntityAI  original_caller,
float  amount,
bool  ignore_switch_state = false 
)
inlineprivate

◆ GetAttachmentAction()

int GetAttachmentAction ( )
inlineprivate

◆ GetCompatiblePlugTypes()

void GetCompatiblePlugTypes ( out TIntArray  IDs)
inlineprivate

References m_CompatiblePlugTypes.

◆ GetCompType()

override int GetCompType ( )
inlineprivate

◆ GetCordLength()

float GetCordLength ( )
inlineprivate

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

References m_CordLength.

Referenced by IsEnergySourceAtReach().

◆ GetCordTextureFile()

string GetCordTextureFile ( )
inlineprivate

Energy manager: Returns path to the cord texture file.

References m_CordTextureFile.

◆ GetCurrentUpdateTime()

float GetCurrentUpdateTime ( )
inlineprivate

References GetGame(), and CGame::GetTime().

Referenced by DeviceUpdate(), and RememberLastUpdateTime().

◆ GetDebugPlugs()

bool GetDebugPlugs ( )
inlineprivate

References m_DebugPlugs.

Referenced by DebugUpdate().

◆ GetDeviceBySocketID()

EntityAI GetDeviceBySocketID ( int  id)
inlineprivate

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

References m_Sockets.

Referenced by HasFreeSocket(), PlugCordIntoSocket(), UnplugCordFromSocket(), and UpdateSelections().

◆ GetEnergy()

float GetEnergy ( )
inlineprivate

Energy manager: Returns the amount of stored energy this device has.

References m_Energy.

Referenced by AddEnergy(), CanWork(), ItemBase::HasEnoughEnergyForRepair(), HasEnoughStoredEnergy(), Entity::OnStoreSave(), and TransferEntityVariables().

◆ GetEnergy0To1()

float GetEnergy0To1 ( )
inlineprivate

Energy manager: Returns % of stored energy this device has as float (from 0.0 to 1.0)

References m_Energy, and m_EnergyStorageMax.

◆ GetEnergy0To100()

int GetEnergy0To100 ( )
inlineprivate

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

References m_Energy, m_EnergyStorageMax, and Math::Round().

◆ GetEnergyAtSpawn()

float GetEnergyAtSpawn ( )
inlineprivate

◆ GetEnergyMax()

float GetEnergyMax ( )
inlineprivate

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.

References GetEnergyMaxPristine(), GetGame(), m_ReduceMaxEnergyByDamageCoef, and Component::m_ThisEntityAI.

Referenced by AddEnergy(), and SetEnergy0To1().

◆ GetEnergyMaxPristine()

float GetEnergyMaxPristine ( )
inlineprivate

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

References m_EnergyStorageMax.

Referenced by GetEnergyMax(), and InventoryItem::SetCEBasedQuantity().

◆ GetEnergySource()

EntityAI GetEnergySource ( )
inlineprivate

Energy manager: Returns the energy source this device is plugged into.

References m_EnergySource.

Referenced by CanWork(), DebugUpdate(), FindAndConsumeEnergy(), Entity::GetDebugText(), IsEnergySourceAtReach(), OnAttachmentRemoved(), Entity::OnStoreSave(), UnplugThis(), and UpdateSelections().

◆ GetEnergySourceNetworkIDHigh()

int GetEnergySourceNetworkIDHigh ( )
inlineprivate

◆ GetEnergySourceNetworkIDLow()

int GetEnergySourceNetworkIDLow ( )
inlineprivate

◆ GetEnergySourceStorageIDb1()

int GetEnergySourceStorageIDb1 ( )
inlineprivate

◆ GetEnergySourceStorageIDb2()

int GetEnergySourceStorageIDb2 ( )
inlineprivate

◆ GetEnergySourceStorageIDb3()

int GetEnergySourceStorageIDb3 ( )
inlineprivate

◆ GetEnergySourceStorageIDb4()

int GetEnergySourceStorageIDb4 ( )
inlineprivate

◆ GetEnergyUsage()

float GetEnergyUsage ( )
inlineprivate

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

References m_EnergyUsage.

Referenced by CanWork(), DeviceUpdate(), HasEnoughStoredEnergy(), and SetEnergy().

◆ GetMySocketID()

protected int GetMySocketID ( )
inlineprivate

References m_MySocketID.

◆ GetPluggedDevice()

EntityAI GetPluggedDevice ( )
inlineprivate

Energy manager: Returns a device which is plugged into this one. If there are more devices to choose from then it returns the first one that is found.

References GetPluggedDevices(), and GetPluggedDevicesCount().

◆ GetPluggedDevices()

array< EntityAI > GetPluggedDevices ( )
inlineprivate

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

References m_PluggedDevices.

Referenced by GetPluggedDevice(), GetPluggedDevicesCount(), GetPoweredDevices(), InteractBranch(), IsSelectionAPlug(), PlugInDevice(), UnplugAllDevices(), UnplugDevice(), and WakeUpWholeBranch().

◆ GetPluggedDevicesCount()

int GetPluggedDevicesCount ( )
inlineprivate

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

References GetPluggedDevices().

Referenced by GetPluggedDevice(), GetPoweredDevices(), HasFreeSocket(), UnplugAllDevices(), and UnplugDevice().

◆ GetPlugOwner()

EntityAI GetPlugOwner ( string  plug_selection_name)
inlineprivate

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

References m_DeviceByPlugSelection.

◆ GetPlugType()

int GetPlugType ( )
inlineprivate

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

References m_PlugType.

◆ GetPoweredDevices()

array< EntityAI > GetPoweredDevices ( )
inlineprivate

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

References GetPluggedDevices(), GetPluggedDevicesCount(), and IsSwitchedOn().

◆ GetPreviousSwitchState()

bool GetPreviousSwitchState ( )
inlineprivate

◆ GetRestorePlugState()

bool GetRestorePlugState ( )
inlineprivate

References m_RestorePlugState.

Referenced by Entity::EEOnAfterLoad().

◆ GetSocketsCount()

int GetSocketsCount ( )
inlineprivate

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

References m_SocketsCount.

Referenced by Event_OnAwake(), HasFreeSocket(), InteractBranch(), IsSelectionAPlug(), PlugCordIntoSocket(), UpdateSelections(), and WakeUpWholeBranch().

◆ GetThisEntityAI()

EntityAI GetThisEntityAI ( )
inlineprivate

◆ GetUpdateInterval()

float GetUpdateInterval ( )
inlineprivate

Energy manager: Returns the update interval of this device.

References m_UpdateInterval.

Referenced by StartUpdates().

◆ GetWetnessExposure()

float GetWetnessExposure ( )
inlineprivate

Returns wetness exposure value defined in config.

References m_WetnessExposure.

◆ HandleMoveInsideCargo()

void HandleMoveInsideCargo ( EntityAI  container)
inlineprivate

◆ HasConversionOfEnergyToQuantity()

bool HasConversionOfEnergyToQuantity ( )
inlineprivate

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

References m_ConvertEnergyToQuantity.

◆ HasElectricityIcon()

bool HasElectricityIcon ( )
inlineprivate

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

References m_HasElectricityIcon.

◆ HasEnoughStoredEnergy()

bool HasEnoughStoredEnergy ( )
inlineprivate

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

References GetEnergy(), and GetEnergyUsage().

Referenced by Event_OnAwake().

◆ HasFreeSocket()

bool HasFreeSocket ( int  socket_id = -1)
inlineprivate

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.

References GetDeviceBySocketID(), GetPluggedDevicesCount(), and GetSocketsCount().

Referenced by CanReceivePlugFrom().

◆ HasVisibleSocketsInInventory()

bool HasVisibleSocketsInInventory ( )
inlineprivate

◆ InteractBranch()

void InteractBranch ( EntityAI  originalCaller,
Man  player = null,
int  system = 0 
)
inlineprivate

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

References GetPluggedDevices(), GetSocketsCount(), and OnInteractBranch().

Referenced by PlugInDevice().

◆ IsCordFolded()

bool IsCordFolded ( )
inlineprivate

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

References IsPlugged().

◆ IsEnergySourceAtReach()

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

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.

Parameters
from_positionvector position from where the measurement will be taken
add_tolerancefloat 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 = GetGame().GetPlayer().GetPosition();
if ( my_device.GetCompEM().IsEnergySourceAtReach( position_player ) )
{
Print("Power source is at reach!");
}else{
Print("Power source is NOT at reach!");
}
proto native DayZPlayer GetPlayer()
Definition EnConvert.c:106
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.

References vector::Distance(), GetCordLength(), GetEnergySource(), and IsPlugged().

Referenced by Hologram::CorrectMaterialPathName(), and UpdatePlugState().

◆ IsPassive()

bool IsPassive ( )
inlineprivate

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

References m_IsPassiveDevice.

Referenced by CanSwitchOff(), and Entity::OnStoreSave().

◆ IsPlugCompatible()

bool IsPlugCompatible ( int  plug_ID)
inlineprivate

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

References m_CompatiblePlugTypes, and PLUG_UNDEFINED.

Referenced by CanReceivePlugFrom(), and Event_OnAwake().

◆ IsPlugged()

bool IsPlugged ( )
inlineprivate

Energy manager: Returns true if this device is plugged into some other device (even if they are OFF or ruined). Otherwise it returns false.

References m_IsPlugged.

Referenced by Hologram::CorrectMaterialPathName(), FindAndConsumeEnergy(), IsCordFolded(), IsEnergySourceAtReach(), and Entity::OnStoreSave().

◆ IsSelectionAPlug()

bool IsSelectionAPlug ( string  selection_to_test)
inlineprivate

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

References _PLUGGED, GetPluggedDevices(), GetSocketsCount(), SOCKET_, and string::ToString().

◆ IsSwitchedOn()

bool IsSwitchedOn ( )
inlineprivate

Energy manager: Returns state of the switch. Whenever the device is working or not does not matter. Use IsWorking() to account for that as well.

References m_IsSwichedOn.

Referenced by CanSwitchOff(), CanSwitchOn(), DeviceUpdate(), FindAndConsumeEnergy(), Entity::GetDebugText(), GetPoweredDevices(), HandleMoveInsideCargo(), Entity::OnStoreSave(), Entity::OnVariablesSynchronized(), and TransferEntityVariables().

◆ IsWorking()

bool IsWorking ( )
inlineprivate

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

References m_IsWorking.

Referenced by DeviceUpdate(), Entity::GetDebugText(), Entity::IsIgnited(), and SwitchOff().

◆ OnAttachmentAdded()

void OnAttachmentAdded ( EntityAI  elec_device)
inlineprivate

◆ OnAttachmentRemoved()

void OnAttachmentRemoved ( EntityAI  elec_device)
inlineprivate

◆ OnDeviceDestroyed()

void OnDeviceDestroyed ( )
inlineprivate

◆ OnEnergyAdded()

void OnEnergyAdded ( )
inlineprivate

Energy manager: Called when energy was added on this device.

References Component::m_ThisEntityAI, m_UpdateQuantityTimer, and Timer::Stop().

Referenced by AddEnergy().

◆ OnEnergyConsumed()

void OnEnergyConsumed ( )
inlineprivate

Energy manager: Called when energy was consumed on this device.

References Component::m_ThisEntityAI.

Referenced by AddEnergy().

◆ OnInteractBranch()

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

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

References Component::m_ThisEntityAI.

Referenced by InteractBranch().

◆ OnIsPlugged()

void OnIsPlugged ( EntityAI  source_device)
inlineprivate

◆ OnIsUnplugged()

void OnIsUnplugged ( EntityAI  last_energy_source)
inlineprivate

◆ OnOwnSocketReleased()

void OnOwnSocketReleased ( EntityAI  device)
inlineprivate

◆ OnOwnSocketTaken()

void OnOwnSocketTaken ( EntityAI  device)
inlineprivate

◆ OnWork()

void OnWork ( float  consumed_energy)
inlineprivate

References Component::m_ThisEntityAI.

Referenced by DeviceUpdate().

◆ PlugCordIntoSocket()

protected void PlugCordIntoSocket ( EntityAI  device_to_plug,
int  socket_id = -1 
)
inlineprivate

◆ PlugInDevice()

◆ PlugThisInto()

bool PlugThisInto ( EntityAI  energy_source,
int  socket_id = -1 
)
inlineprivate

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.

References Component::m_ThisEntityAI.

Referenced by Entity::EEOnAfterLoad(), OnAttachmentAdded(), and Entity::OnVariablesSynchronized().

◆ RefreshDebug()

void RefreshDebug ( )
inlineprivate

◆ RememberLastUpdateTime()

void RememberLastUpdateTime ( )
inlineprivate

References GetCurrentUpdateTime(), and m_LastUpdateTime.

Referenced by DeviceUpdate().

◆ ResetEnergyUsage()

void ResetEnergyUsage ( )
inlineprivate

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

References CGame::ConfigGetFloat(), GetGame(), m_EnergyUsage, and Component::m_ThisEntityAI.

◆ RestorePlugState()

void RestorePlugState ( bool  state)
inlineprivate

References m_RestorePlugState.

Referenced by Entity::OnStoreLoad().

◆ SetAttachmentAction()

void SetAttachmentAction ( int  new_action_type)
inlineprivate

◆ SetCordLength()

void SetCordLength ( float  new_length)
inlineprivate

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

References m_CordLength.

◆ SetCordTextureFile()

void SetCordTextureFile ( string  new_path)
inlineprivate

References m_CordTextureFile.

◆ SetDebugPlugs()

void SetDebugPlugs ( bool  newVal)
inlineprivate

References m_DebugPlugs, and RefreshDebug().

◆ SetDeviceBySocketID()

void SetDeviceBySocketID ( int  id,
EntityAI  plugged_device 
)
inlineprivate

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

References m_Sockets.

Referenced by UnplugCordFromSocket(), and UpdateSocketSelections().

◆ SetElectricityIconVisibility()

void SetElectricityIconVisibility ( bool  make_visible)
inlineprivate

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

References m_HasElectricityIcon.

◆ SetEnergy()

void SetEnergy ( float  new_energy)
inlineprivate

Energy manager: Sets stored energy for this device. It ignores the min/max limit!

References GetEnergyUsage(), GetGame(), m_Energy, Component::m_ThisEntityAI, Math::Min(), and UpdateCanWork().

Referenced by AddEnergy(), Entity::OnStoreLoad(), SetEnergy0To1(), and TransferEntityVariables().

◆ SetEnergy0To1()

void SetEnergy0To1 ( float  energy01)
inlineprivate

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

References GetEnergyMax(), Math::Lerp(), and SetEnergy().

Referenced by InventoryItem::SetCEBasedQuantity().

◆ SetEnergyMaxPristine()

void SetEnergyMaxPristine ( float  new_limit)
inlineprivate

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

References m_EnergyStorageMax.

◆ SetEnergySource()

protected void SetEnergySource ( EntityAI  source)
inlineprivate

◆ SetEnergySourceClient()

void SetEnergySourceClient ( EntityAI  source)
inlineprivate

References SetEnergySource().

◆ SetEnergyUsage()

void SetEnergyUsage ( float  new_usage)
inlineprivate

Energy manager: Changes the energy usage per second.

References m_EnergyUsage.

◆ SetMySocketID()

protected void SetMySocketID ( int  slot_ID)
inlineprivate

References m_MySocketID.

◆ SetPassiveState()

void SetPassiveState ( bool  state = true)
inlineprivate

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

References DeviceUpdate(), and m_IsPassiveDevice.

Referenced by Entity::OnStoreLoad().

◆ SetPlugOwner()

protected void SetPlugOwner ( string  selection_name,
EntityAI  device 
)
inlineprivate

◆ SetPlugType()

void SetPlugType ( int  new_type)
inlineprivate

References m_PlugType.

◆ SetPowered()

protected void SetPowered ( bool  state)
inlineprivate

References m_IsWorking.

Referenced by DeviceUpdate(), and OnDeviceDestroyed().

◆ SetUpdateInterval()

void SetUpdateInterval ( float  value)
inlineprivate

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().

◆ StartUpdates()

◆ StopUpdates()

protected void StopUpdates ( )
inlineprivate

References m_UpdateTimer, and Timer::Stop().

Referenced by DeviceUpdate(), and SwitchOff().

◆ StoreEnergySourceIDs()

void StoreEnergySourceIDs ( int  b1,
int  b2,
int  b3,
int  b4 
)
inlineprivate

◆ SwitchOff()

◆ SwitchOn()

◆ Synch()

void Synch ( )
inlineprivate

◆ UnplugAllDevices()

void UnplugAllDevices ( )
inlineprivate

Energy manager: Unplugs everything directly connected to this device.

References Get(), GetPluggedDevices(), GetPluggedDevicesCount(), and UnplugDevice().

Referenced by OnDeviceDestroyed().

◆ UnplugCordFromSocket()

protected void UnplugCordFromSocket ( int  socket_to_unplug_ID)
inlineprivate

◆ UnplugDevice()

void UnplugDevice ( EntityAI  device_to_unplug)
inlineprivate

◆ UnplugThis()

void UnplugThis ( )
inlineprivate

Energy manager: Unplugs this device from its power source.

References GetEnergySource(), GetGame(), and Component::m_ThisEntityAI.

Referenced by OnAttachmentRemoved(), OnDeviceDestroyed(), Entity::OnVariablesSynchronized(), and UpdatePlugState().

◆ UpdateCanWork()

void UpdateCanWork ( )
inlineprivate

◆ UpdatePlugState()

void UpdatePlugState ( )
inlineprivate

Energy manager: Unplugs this device when it's necesarry.

References IsEnergySourceAtReach(), Component::m_ThisEntityAI, and UnplugThis().

◆ UpdateSelections()

void UpdateSelections ( )
inlineprivate

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)

References _AVAILABLE, _PLUGGED, GetDeviceBySocketID(), GetEnergySource(), GetSocketsCount(), Component::m_ThisEntityAI, SEL_CORD_FOLDED, SEL_CORD_PLUGGED, SOCKET_, ToString(), and string::ToString().

◆ UpdateSocketSelections()

protected void UpdateSocketSelections ( int  socket_id,
EntityAI  device_to_plug 
)
inlineprivate

◆ WakeUpWholeBranch()

protected void WakeUpWholeBranch ( EntityAI  original_caller)
inlineprivate

Field Documentation

◆ _AVAILABLE

protected const string _AVAILABLE = "_available"
staticprivate

◆ _PLUGGED

protected const string _PLUGGED = "_plugged"
staticprivate

◆ DEFAULT_UPDATE_INTERVAL

protected const float DEFAULT_UPDATE_INTERVAL = 15
private

Referenced by Event_OnAwake().

◆ m_AttachmentActionType

protected int m_AttachmentActionType
private

◆ m_AutoSwitchOff

protected bool m_AutoSwitchOff
private

Referenced by DeviceUpdate(), and Event_OnAwake().

◆ m_AutoSwitchOffWhenInCargo

protected bool m_AutoSwitchOffWhenInCargo
private

◆ m_CanStopWork

protected bool m_CanStopWork
private

Referenced by DeviceUpdate().

◆ m_CanWork

protected bool m_CanWork
private

◆ m_CompatiblePlugTypes

protected ref TIntArray m_CompatiblePlugTypes
private

◆ m_ConvertEnergyToQuantity

protected bool m_ConvertEnergyToQuantity
private

◆ m_CordLength

protected float m_CordLength
private

◆ m_CordTextureFile

protected string m_CordTextureFile
private

◆ m_DebugPlugArrow

protected Shape m_DebugPlugArrow
private

◆ m_DebugPlugs

protected bool m_DebugPlugs = false
staticprivate

◆ m_DebugUpdate

ref Timer m_DebugUpdate
private

◆ m_DeviceByPlugSelection

ref map<string,EntityAI> m_DeviceByPlugSelection
private

◆ m_Energy

protected float m_Energy
private

◆ m_EnergyAtSpawn

protected float m_EnergyAtSpawn
private

Referenced by Event_OnAwake(), and GetEnergyAtSpawn().

◆ m_EnergySource

EntityAI m_EnergySource
private

Referenced by GetEnergySource(), and SetEnergySource().

◆ m_EnergySourceNetworkIDHigh

protected int m_EnergySourceNetworkIDHigh = -1
private

◆ m_EnergySourceNetworkIDLow

protected int m_EnergySourceNetworkIDLow = -1
private

◆ m_EnergySourceStorageIDb1

protected int m_EnergySourceStorageIDb1
private

◆ m_EnergySourceStorageIDb2

protected int m_EnergySourceStorageIDb2
private

◆ m_EnergySourceStorageIDb3

protected int m_EnergySourceStorageIDb3
private

◆ m_EnergySourceStorageIDb4

protected int m_EnergySourceStorageIDb4
private

◆ m_EnergyStorageMax

protected float m_EnergyStorageMax
private

◆ m_EnergyUsage

protected float m_EnergyUsage
private

◆ m_HasElectricityIcon

protected bool m_HasElectricityIcon
private

◆ m_IsPassiveDevice

protected bool m_IsPassiveDevice
private

◆ m_IsPlugged

protected bool m_IsPlugged
private

Referenced by IsPlugged(), and SetEnergySource().

◆ m_IsSwichedOn

protected bool m_IsSwichedOn
private

Referenced by IsSwitchedOn(), SwitchOff(), and SwitchOn().

◆ m_IsSwichedOnPreviousState

protected bool m_IsSwichedOnPreviousState
private

◆ m_IsWorking

protected bool m_IsWorking
private

Referenced by IsWorking(), and SetPowered().

◆ m_LastUpdateTime

protected float m_LastUpdateTime
private

◆ m_MySocketID

protected int m_MySocketID = -1
private

Referenced by GetMySocketID(), and SetMySocketID().

◆ m_PluggedDevices

ref array<EntityAI> m_PluggedDevices
private

Referenced by Event_OnAwake(), and GetPluggedDevices().

◆ m_PlugType

protected int m_PlugType
private

◆ m_ReduceMaxEnergyByDamageCoef

protected float m_ReduceMaxEnergyByDamageCoef
private

Referenced by Event_OnAwake(), and GetEnergyMax().

◆ m_RestorePlugState

protected bool m_RestorePlugState
private

◆ m_ShowSocketsInInventory

protected bool m_ShowSocketsInInventory
private

◆ m_Sockets

◆ m_SocketsCount

protected float m_SocketsCount
private

Referenced by Event_OnAwake(), and GetSocketsCount().

◆ m_UpdateInterval

protected float m_UpdateInterval
private

◆ m_UpdateQuantityTimer

ref Timer m_UpdateQuantityTimer
private

Referenced by Event_OnAwake(), and OnEnergyAdded().

◆ m_UpdateTimer

ref Timer m_UpdateTimer
private

Referenced by StartUpdates(), and StopUpdates().

◆ m_WetnessExposure

protected float m_WetnessExposure
private

◆ MAX_SOCKETS_COUNT

const int MAX_SOCKETS_COUNT = 4
private

Referenced by Event_OnAwake().

◆ SEL_CORD_FOLDED

const string SEL_CORD_FOLDED = "cord_folded"
staticprivate

◆ SEL_CORD_PLUGGED

const string SEL_CORD_PLUGGED = "cord_plugged"
staticprivate

◆ SOCKET_

protected const string SOCKET_ = "socket_"
staticprivate

The documentation for this class was generated from the following file: