DayZ Enforce
Script API
Private Member Functions | Private Attributes | List of all members
ComponentElectricDevice Class Reference

#include <ComponentElectricDevice.h>

Inheritance diagram for ComponentElectricDevice:
Component ComponentElectricDevicePowerGenerator ComponentElectricDeviceSpotlight

Private Member Functions

void  ComponentElectricDevice ()
 
void  ~ComponentElectricDevice ()
 
void  Event_OnAwake ()
 
void  Event_OnInit ()
 
void  GetCompatiblePlugTypes (out TIntArray IDs)
 
void  SwitchOn ()
  Switches ON the device. If it has enough energy, it will start doing its work. Otherwise it won't do any work. More...
 
void  SwitchOff ()
  Switches OFF the device. More...
 
void  SetEnergySource (EntityAI source)
 
void  StopUpdates ()
 
void  SetEnergy (float new_energy)
 
void  PlugInDevice (EntityAI device_to_plug)
  Plugs the given device into this one. More...
 
void  PlugThisInto (EntityAI energy_source)
  Plugs this device into the given one. More...
 
void  SetPlugOwner (string selection_name, EntityAI device)
  Sets the device to which the given plug selection belongs to. More...
 
bool  CanSwitchOn ()
 
bool  CanSwitchOff ()
 
bool  IsSwitchedOn ()
 
bool  IsAlwaysSwitchedOn ()
 
bool  IsPlugged ()
  Returns true if this device is plugged into some other electricity device (even if they are OFF or ruined). Otherwise it returns false. More...
 
bool  CanRun ()
 
int  GetCompType ()
 
int  GetSocketsCount ()
 
int  GetPlugType ()
  Returns plug type. Check .hpp OR .h files for types of plugs. More...
 
float  GetEnergyUsage ()
  Returns the number of energy this device needs to run itself (See its config >> energyUsagePerSecond) More...
 
float  GetEnergy ()
 
EntityAI  GetEnergySource ()
  Returns the energy source this device is plugged into. More...
 
EntityAI  GetPlugOwner (string plug_selection_name)
  Returns the device to which the given plug selection belongs to. More...
 
array< OLinkT GetPluggedDevices ()
  Returns an array of devices which are plugged into this one. More...
 
void  OnInitElectricity ()
  Object's initialization. Electricity system is fully initialized by this point. More...
 
void  OnSwitchOn ()
  Called when the device is turned on. More...
 
void  OnSwitchOff ()
  Called when the device is turned OFF. More...
 
void  OnWorkStart ()
  Called only once when this device starts doing its work. More...
 
void  OnWork (float consumed_energy)
  Called every device update if its supposed to do some work. The update can be every CONSUME_ENERGY_INTERVAL second or at random, depending on its manipulation. More...
 
void  OnWorkStop ()
  Called when the device stops working (was switched OFF or ran out of energy) More...
 
void  OnOwnSocketTaken ()
  When something is plugged to this device. More...
 
void  OnOwnSocketReleased ()
  When something is UNPLUGGED from this device. More...
 
void  OnIsPlugged ()
  Called when this device is plugged into some energy source. More...
 
void  OnIsUnplugged ()
  Called when this device is UNPLUGGED from the energy source. More...
 
void  UnplugDevice (EntityAI device_to_unplug, bool drop_plug_nearby=false)
  Unplugs a device from this one. More...
 
void  UnplugThis ()
  Unplugs this device from its power source. More...
 
void  UnplugAllDevices ()
  Unplugs everything connected directly to this device. More...
 
void  UpdateSelections ()
  Shows/Hides all selections this system works with. Call this if something is wrong with selections (like during Init and Restore event in config) More...
 
void  HideSelection (string selection_name)
  Hides selection of the given name. More...
 
void  ShowSelection (string selection_name)
  Shows selection of the given name. More...
 
void  UpdatePlugState ()
  Unplugs this device when it's necesarry. More...
 
bool  CanTurnOff ()
  Checks if the device can be turned OFF (Use this in User Actions as a condition) More...
 
bool  IsPowered ()
  Returns true if this device has consumed enough needed energy to do its work in this cycle. More...
 
bool  HasEnoughStoredEnergy ()
  Returns true if this device has enough of stored energy for its own use. More...
 
bool  HasFreeSocket ()
  Returns true if this device has a free socket to receive another plug. More...
 
bool  CanReceivePlugFrom (EntityAI device_to_plug)
  Returns true if this device can receive power plug of the other device. More...
 
bool  IsEnergySourceAtReach (vector from_position, float add_tolerance=0)
  Returns true/false if this device's virtual power cord can/cannot reach its energy source at the given position. More...
 
float  AddEnergy (float added_energy)
  Adds energy to this device and clamps it within its min/max storage limits. Negative value is supported. Returns the amount of energy that was clamped. More...
 
float  GetEnergyMax ()
  Returns the maximum amount of energy this device can store. More...
 
string  GetCordTextureFile ()
  Returns path to the texture file. More...
 
EntityAI  GetObjectNearDroppedPlug ()
  Returns the EntityAI instance this device has its power plug nearby (for quick plug-in user action) More...
 
array< EntityAI GetPoweredDevices ()
  Returns an array of devices which are plugged into this one and are turned on. More...
 
void  DeviceUpdate ()
 
void  SetObjectNearDroppedPlug (EntityAI source)
 
void  WakeUpWholeBranch (EntityAI original_caller)
 
void  StartUpdates ()
 
void  PlugCordIntoSocket (EntityAI device_to_plug)
 
void  UnplugCordFromSocket (int socket_to_unplug_ID)
 
private void  SetEnergySourceSocketID (int slot_ID)
 
private void  SetPowered (bool state)
 
private void  DeleteOLinkArrays ()
 
private bool  ConsumeEnergy (local float amount)
 
int  GetPowerSourceSocketID ()
 
private float  GetCordLength ()
 

Private Attributes

bool  m_CfgIsPassiveDevice
 
private bool  m_IsSwichedOn
 
private bool  m_CfgAlwaysSwitchedOn
 
private bool  m_IsPassiveDevice
 
private bool  m_IsPowered
 
private bool  m_CanStopWork
 
private int  m_EnergySourceSocketID
 
private int  m_PlugType
 
private float  m_EnergyUsage
 
private float  m_Energy
 
private float  m_EnergyStorageMax
 
private float  m_SocketsCount
 
private float  m_CordLength
 
private float  m_LastUpdateTime
 
private string  m_CordTextureFile
 
private autoptr TIntArray  m_CompatiblePlugTypes
 
autoptr OLinkT  m_EnergySource
 
autoptr OLinkT  m_ObjectNearDroppedPlug
 
autoptr array< OLinkT m_PluggedDevices
 
autoptr map< string, EntityAI m_FoldedPlugs
 
protected autoptr OLinkT  m_EnergySource
 
autoptr Timer  m_UpdateTimer
 
const int  MAX_SOCKETS_COUNT = 999
 
EntityAI  m_Sockets [MAX_SOCKETS_COUNT]
 

Constructor & Destructor Documentation

void ComponentElectricDevice::ComponentElectricDevice ( )
private
void ComponentElectricDevice::~ComponentElectricDevice ( )
private

Member Function Documentation

void ComponentElectricDevice::Event_OnAwake ( )
private
void ComponentElectricDevice::Event_OnInit ( )
private
void ComponentElectricDevice::GetCompatiblePlugTypes ( out TIntArray  IDs )
private
void ComponentElectricDevice::SwitchOn ( )
private

Switches ON the device. If it has enough energy, it will start doing its work. Otherwise it won't do any work.

References CanSwitchOn(), DeviceUpdate(), m_IsSwichedOn, Component::m_ThisEntityAI, OnSwitchOn(), StartUpdates(), and WakeUpWholeBranch().

Referenced by ActionTurnOnTransmitterOnGround::OnComplete().

void ComponentElectricDevice::SwitchOff ( )
private
void ComponentElectricDevice::SetEnergySource ( EntityAI  source )
private
private void ComponentElectricDevice::StopUpdates ( )
private

References m_UpdateTimer.

Referenced by DeviceUpdate(), and SwitchOff().

void ComponentElectricDevice::SetEnergy ( float  new_energy )
private

References m_Energy.

Referenced by AddEnergy(), and PowerGenerator::SetFuel().

void ComponentElectricDevice::PlugInDevice ( EntityAI  device_to_plug )
private
void ComponentElectricDevice::PlugThisInto ( EntityAI  energy_source )
private

Plugs this device into the given one.

References EntityAI::GetCompElec(), Component::m_ThisEntityAI, and PlugInDevice().

void ComponentElectricDevice::SetPlugOwner ( string  selection_name,
EntityAI  device 
)
private

Sets the device to which the given plug selection belongs to.

References m_FoldedPlugs.

Referenced by PlugCordIntoSocket(), PlugInDevice(), UnplugCordFromSocket(), and UnplugDevice().

bool ComponentElectricDevice::CanSwitchOn ( )
private
bool ComponentElectricDevice::CanSwitchOff ( )
private
bool ComponentElectricDevice::IsSwitchedOn ( )
private
bool ComponentElectricDevice::IsAlwaysSwitchedOn ( )
private
bool ComponentElectricDevice::IsPlugged ( )
private

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

References GetEnergySource().

Referenced by IsEnergySourceAtReach(), and ActionTurnOnTransmitterOnGround::OnComplete().

bool ComponentElectricDevice::CanRun ( )
private
int ComponentElectricDevice::GetCompType ( )
private

References COMP_TYPE_ELE_DEVICE.

int ComponentElectricDevice::GetSocketsCount ( )
private
int ComponentElectricDevice::GetPlugType ( )
private

Returns plug type. Check .hpp OR .h files for types of plugs.

References m_PlugType.

Referenced by CanReceivePlugFrom().

float ComponentElectricDevice::GetEnergyUsage ( )
private

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

References m_EnergyUsage.

Referenced by CanRun(), DeviceUpdate(), and HasEnoughStoredEnergy().

float ComponentElectricDevice::GetEnergy ( )
private
EntityAI ComponentElectricDevice::GetEnergySource ( )
private

Returns the energy source this device is plugged into.

References m_EnergySource.

Referenced by CanRun(), ConsumeEnergy(), IsEnergySourceAtReach(), IsPlugged(), UnplugThis(), UpdateSelections(), and ~ComponentElectricDevice().

EntityAI ComponentElectricDevice::GetPlugOwner ( string  plug_selection_name )
private

Returns the device to which the given plug selection belongs to.

References m_FoldedPlugs.

Referenced by PlugInDevice(), and UnplugDevice().

array< OLinkT > ComponentElectricDevice::GetPluggedDevices ( )
private

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

References m_PluggedDevices.

Referenced by DeleteOLinkArrays(), GetPoweredDevices(), HasFreeSocket(), PlugInDevice(), UnplugAllDevices(), UnplugDevice(), and WakeUpWholeBranch().

void ComponentElectricDevice::OnInitElectricity ( )
private

Object's initialization. Electricity system is fully initialized by this point.

References Component::m_ThisEntityAI, and EntityAI::OnInitElectricity().

Referenced by Event_OnInit().

void ComponentElectricDevice::OnSwitchOn ( )
private

Called when the device is turned on.

References Component::m_ThisEntityAI, and EntityAI::OnSwitchOn().

Referenced by SwitchOn().

void ComponentElectricDevice::OnSwitchOff ( )
private

Called when the device is turned OFF.

References Component::m_ThisEntityAI, and EntityAI::OnSwitchOff().

Referenced by SwitchOff().

void ComponentElectricDevice::OnWorkStart ( )
private

Called only once when this device starts doing its work.

References Component::m_ThisEntityAI, and EntityAI::OnWorkStart().

Referenced by DeviceUpdate().

void ComponentElectricDevice::OnWork ( float  consumed_energy )
private

Called every device update if its supposed to do some work. The update can be every CONSUME_ENERGY_INTERVAL second or at random, depending on its manipulation.

References Component::m_ThisEntityAI, and EntityAI::OnWork().

Referenced by DeviceUpdate().

void ComponentElectricDevice::OnWorkStop ( )
private

Called when the device stops working (was switched OFF or ran out of energy)

References Component::m_ThisEntityAI, and EntityAI::OnWorkStop().

Referenced by DeviceUpdate().

void ComponentElectricDevice::OnOwnSocketTaken ( )
private

When something is plugged to this device.

References Component::m_ThisEntityAI, and EntityAI::OnOwnSocketTaken().

Referenced by PlugInDevice().

void ComponentElectricDevice::OnOwnSocketReleased ( )
private

When something is UNPLUGGED from this device.

References Component::m_ThisEntityAI, and EntityAI::OnOwnSocketReleased().

Referenced by UnplugDevice().

void ComponentElectricDevice::OnIsPlugged ( )
private

Called when this device is plugged into some energy source.

References Component::m_ThisEntityAI, and EntityAI::OnIsPlugged().

Referenced by SetEnergySource(), and SetObjectNearDroppedPlug().

void ComponentElectricDevice::OnIsUnplugged ( )
private

Called when this device is UNPLUGGED from the energy source.

References Component::m_ThisEntityAI, and EntityAI::OnIsUnplugged().

Referenced by UnplugDevice().

void ComponentElectricDevice::UnplugDevice ( EntityAI  device_to_unplug,
bool  drop_plug_nearby = false 
)
private
void ComponentElectricDevice::UnplugThis ( )
private
void ComponentElectricDevice::UnplugAllDevices ( )
private

Unplugs everything connected directly to this device.

References GetPluggedDevices(), and UnplugDevice().

Referenced by PowerGenerator::EEItemLocationChanged().

void ComponentElectricDevice::UpdateSelections ( )
private

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 EntityAI::GetCompElec(), GetCordTextureFile(), GetEnergySource(), GetSocketsCount(), EntityAI::HideSelection(), itoa(), m_Sockets, Component::m_ThisEntityAI, EntityAI::SetObjectTexture(), and EntityAI::ShowSelection().

void ComponentElectricDevice::HideSelection ( string  selection_name )
private

Hides selection of the given name.

void ComponentElectricDevice::ShowSelection ( string  selection_name )
private

Shows selection of the given name.

void ComponentElectricDevice::UpdatePlugState ( )
private
bool ComponentElectricDevice::CanTurnOff ( )
private

Checks if the device can be turned OFF (Use this in User Actions as a condition)

References IsAlwaysSwitchedOn(), and IsSwitchedOn().

Referenced by SwitchOff().

bool ComponentElectricDevice::IsPowered ( )
private

Returns true if this device has consumed enough needed energy to do its work in this cycle.

References m_IsPowered.

Referenced by DeviceUpdate(), and SwitchOff().

bool ComponentElectricDevice::HasEnoughStoredEnergy ( )
private

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

References GetEnergy(), and GetEnergyUsage().

Referenced by ComponentElectricDevicePowerGenerator::CanSwitchOn().

bool ComponentElectricDevice::HasFreeSocket ( )
private

Returns true if this device has a free socket to receive another plug.

References GetPluggedDevices(), and GetSocketsCount().

Referenced by CanReceivePlugFrom().

bool ComponentElectricDevice::CanReceivePlugFrom ( EntityAI  device_to_plug )
private

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

References EntityAI::GetCompElec(), GetPlugType(), HasFreeSocket(), m_CompatiblePlugTypes, Component::m_ThisEntityAI, and PLUG_UNDEFINED.

bool ComponentElectricDevice::IsEnergySourceAtReach ( vector  from_position,
float  add_tolerance = 0 
)
private

Returns true/false if this device's virtual power cord can/cannot reach its energy source at the given position.

Parameters
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 device will be at reach. False if not, or is not plugged, or is not an electricity device.
vector position_player = GetPlayer().GetPosition();
//if ( my_device.ComponentElectricDevice().IsEnergySourceAtReach( GetPlayer().GetPosition() ) ) // WRONG! Do NOT send function as a parameter!
if ( my_device.ComponentElectricDevice().IsEnergySourceAtReach( position_player ) )
{
Print("device is at reach!");
}else{
Print("device is NOT at reach!");
}

References GetCordLength(), GetEnergySource(), IsPlugged(), and EnMath3D::VectorDistance().

Referenced by UpdatePlugState().

float ComponentElectricDevice::AddEnergy ( float  added_energy )
private

Adds energy to this device and clamps it within its min/max storage limits. Negative value is supported. Returns the amount of energy that was clamped.

References clamp(), GetEnergy(), GetEnergyMax(), GetGame(), SetEnergy(), and StartUpdates().

Referenced by ConsumeEnergy().

float ComponentElectricDevice::GetEnergyMax ( )
private

Returns the maximum amount of energy this device can store.

References m_EnergyStorageMax.

Referenced by AddEnergy(), PowerGenerator::CanAddFuel(), and PowerGenerator::OnInitElectricity().

string ComponentElectricDevice::GetCordTextureFile ( )
private

Returns path to the texture file.

References m_CordTextureFile.

Referenced by PlugCordIntoSocket(), UnplugDevice(), and UpdateSelections().

EntityAI ComponentElectricDevice::GetObjectNearDroppedPlug ( )
private

Returns the EntityAI instance this device has its power plug nearby (for quick plug-in user action)

References m_ObjectNearDroppedPlug.

array< EntityAI > ComponentElectricDevice::GetPoweredDevices ( )
private

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

References GetPluggedDevices(), and IsSwitchedOn().

private void ComponentElectricDevice::DeviceUpdate ( )
private
void ComponentElectricDevice::SetObjectNearDroppedPlug ( EntityAI  source )
private
private void ComponentElectricDevice::WakeUpWholeBranch ( EntityAI  original_caller )
private
void ComponentElectricDevice::StartUpdates ( )
private
void ComponentElectricDevice::PlugCordIntoSocket ( EntityAI  device_to_plug )
private
void ComponentElectricDevice::UnplugCordFromSocket ( int  socket_to_unplug_ID )
private
void ComponentElectricDevice::SetEnergySourceSocketID ( int  slot_ID )
private
private void ComponentElectricDevice::SetPowered ( bool  state )
private

References m_IsPowered.

Referenced by DeviceUpdate().

private void ComponentElectricDevice::DeleteOLinkArrays ( )
private
private bool ComponentElectricDevice::ConsumeEnergy ( local float  amount )
private
private int ComponentElectricDevice::GetPowerSourceSocketID ( )
private

References m_EnergySourceSocketID.

Referenced by UnplugDevice().

private float ComponentElectricDevice::GetCordLength ( )
private

References m_CordLength.

Referenced by IsEnergySourceAtReach().

Member Data Documentation

bool ComponentElectricDevice::m_CfgIsPassiveDevice
private

Referenced by StartUpdates().

private bool ComponentElectricDevice::m_IsSwichedOn
private
private bool ComponentElectricDevice::m_CfgAlwaysSwitchedOn
private
private bool ComponentElectricDevice::m_IsPassiveDevice
private

Referenced by DeviceUpdate(), and Event_OnAwake().

private bool ComponentElectricDevice::m_IsPowered
private
private bool ComponentElectricDevice::m_CanStopWork
private

Referenced by DeviceUpdate(), and Event_OnAwake().

private int ComponentElectricDevice::m_EnergySourceSocketID
private
private int ComponentElectricDevice::m_PlugType
private

Referenced by Event_OnAwake(), and GetPlugType().

private float ComponentElectricDevice::m_EnergyUsage
private
private float ComponentElectricDevice::m_Energy
private
private float ComponentElectricDevice::m_EnergyStorageMax
private

Referenced by Event_OnAwake(), and GetEnergyMax().

private float ComponentElectricDevice::m_SocketsCount
private
private float ComponentElectricDevice::m_CordLength
private
private float ComponentElectricDevice::m_LastUpdateTime
private

Referenced by DeviceUpdate(), and Event_OnAwake().

private string ComponentElectricDevice::m_CordTextureFile
private
private autoptr TIntArray ComponentElectricDevice::m_CompatiblePlugTypes
private
autoptr OLinkT ComponentElectricDevice::m_EnergySource
private
autoptr OLinkT ComponentElectricDevice::m_ObjectNearDroppedPlug
private
autoptr array<OLinkT> ComponentElectricDevice::m_PluggedDevices
private
autoptr map<string,EntityAI> ComponentElectricDevice::m_FoldedPlugs
private
protected autoptr OLinkT ComponentElectricDevice::m_EnergySource
private
autoptr Timer ComponentElectricDevice::m_UpdateTimer
private
const int ComponentElectricDevice::MAX_SOCKETS_COUNT = 999
private

Referenced by Event_OnAwake().

EntityAI ComponentElectricDevice::m_Sockets[MAX_SOCKETS_COUNT]
private

The documentation for this class was generated from the following files:
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)