61 protected static const string SOCKET_ =
"socket_";
62 protected static const string _PLUGGED =
"_plugged";
138 if ( BBB && BBB.GetType() ==
"Fence" )
140 to = to +
"0 -1.3 0";
161 pts[2] = to - dir1 - dir2;
162 pts[3] = to - dir1 + dir2;
165 return Shape.CreateLines(color, flags, pts, 5);
177 string cfg_energy_manager = cfg_item +
" EnergyManager ";
208 string error =
"Error! Item " +
m_ThisEntityAI.GetType() +
" has invalid configuration of the energy->quantity conversion feature. To fix this, add 'varQuantityMax' parameter with value higher than 0 to the item's config. Then make sure to re-build the PBO containing this item!";
224 if ( update_interval <= 0 )
230 string cfg_check_energy_limit = cfg_energy_manager +
"energyStorageMax";
232 if ( !
GetGame().ConfigIsExisting (cfg_check_energy_limit) &&
m_Energy > 0 )
238 string cfg_check_plug_types = cfg_energy_manager +
"compatiblePlugTypes";
240 if (
GetGame().ConfigIsExisting (cfg_check_plug_types) )
252 string error_message_cord =
"Warning! " +
m_ThisEntityAI.GetType() +
": config parameter 'cordLength' is less than 0! Cord length should not be negative!";
253 DPrint(error_message_cord);
260 string cfg_animation_sources =
"cfgVehicles " +
m_ThisEntityAI.GetType() +
" " +
"AnimationSources ";
263 for (
int i_selection = 0; i_selection < animation_sources_count; i_selection++)
278 string error_message_sockets =
"Error! " +
m_ThisEntityAI.GetType() +
": config parameter 'powerSocketsCount' is higher than the current limit (" +
MAX_SOCKETS_COUNT.ToString() +
")! Raise the limit (constant MAX_SOCKETS_COUNT) or decrease the powerSocketsCount parameter for this device!";
279 DPrint(error_message_sockets);
308 #ifdef DIAG_DEVELOPER
309 GetGame().m_EnergyManagerArray.Insert(
this );
454 bool device_found =
false;
456 for (
int i = index_start; i >= 0; --i )
460 if (plugged_device == device_to_unplug)
470 int socket_ID = device_to_unplug.GetCompEM().GetMySocketID();
472 device_to_unplug.GetCompEM().SetEnergySource(NULL);
473 device_to_unplug.GetCompEM().DeviceUpdate();
474 device_to_unplug.GetCompEM().StartUpdates();
509 for (
int i = index_start; i >= 0; --i )
531 if ( old_energy -
GetEnergyUsage() <= 0 || (old_energy != new_energy &&
Math.
Min(old_energy,new_energy) <= 0) )
553 for (
int i = 0; i < slots_c; ++i )
563 string texture_path = plug_owner.GetCompEM().GetCordTextureFile();
564 int selection_index =
m_ThisEntityAI.GetHiddenSelectionIndex( plugged_selection );
597 vector pos_player = player.GetPosition();
669 string cfg_energy_usage =
"CfgVehicles " +
m_ThisEntityAI.GetType() +
" EnergyManager ";
703 bool current_state =
CanWork();
744 return energy_source.GetCompEM().PlugInDevice(
m_ThisEntityAI, socket_id);
777 float energy_usage = test_energy;
781 if (energy_usage == -1)
791 if (gathered_energy <= 0 && energy_usage <= 0)
796 int cycle_limit = 500;
798 while ( gathered_energy < energy_usage )
807 DPrint(
"Energy Manager ERROR: The 'cycle_limit' safety break had to be activated to prevent possible game freeze. Dumping debug information...");
812 if (energy_source.GetCompEM())
833 if ( energy_source && energy_source !=
m_ThisEntityAI && !energy_source.IsRuined() && energy_source.GetCompEM() && energy_source.GetCompEM().IsSwitchedOn() && energy_source.GetCompEM().CheckWetness() )
835 gathered_energy = gathered_energy + energy_source.GetCompEM().GetEnergy();
836 energy_source = energy_source.GetCompEM().GetEnergySource();
931 if ( plugged_devices < plugged_devices_limit )
967 if ( plug_ID_to_Check == plug_ID )
989 if ( device_to_plug.GetCompEM().GetEnergySource() !=
m_ThisEntityAI)
993 if ( device_to_plug.GetCompEM().IsEnergySourceAtReach( device_to_plug.GetPosition(), 0,
m_ThisEntityAI.GetPosition() ) )
1007 return potential_energy_provider.GetCompEM().CanReceivePlugFrom(
m_ThisEntityAI );
1040 if ( !
IsPlugged() && override_source_position ==
"-1 -1 -1" )
1053 if ( override_source_position ==
"-1 -1 -1" )
1060 source_pos = energy_source.GetPosition();
1065 source_pos = override_source_position;
1091 for (
int i = socket_count; i >= 0; --i )
1095 if ( selection_to_test == real_selection)
1199 #ifdef DIAG_DEVELOPER
1200 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_CONSUMPTION) || (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_RECHARGE)))
1229 if (added_energy != 0)
1232 #ifdef DIAG_DEVELOPER
1233 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_CONSUMPTION) && added_energy < 0)
1235 float timeAccel = FeatureTimeAccel.GetFeatureTimeAccelValue();
1236 added_energy *= timeAccel;
1240 bool energy_was_added = (added_energy > 0);
1242 float energy_to_clamp =
GetEnergy() + added_energy;
1247 if (energy_was_added)
1252 return energy_to_clamp - clamped_energy;
1261 float max_health = 0;
1276 float damage_coef = 1 - (health / max_health);
1344 for (
int i = 0; i < plugged_devices_c; ++i )
1349 return_array.Insert(device);
1353 return return_array;
1397 m_ThisEntityAI.PlaySoundSet( sound_plug,
"cablereel_plugin_SoundSet", 0, 0 );
1410 m_ThisEntityAI.PlaySoundSet( sound_unplug,
"cablereel_unplug_SoundSet", 0, 0 );
1424 if ( elec_device.GetCompEM().CanReceivePlugFrom(
m_ThisEntityAI ) )
1449 elec_device.GetCompEM().UnplugThis();
1511 foreach (
EntityAI device : devices)
1513 if ( device != originalCaller )
1515 device.GetCompEM().InteractBranch( originalCaller, player, system );
1534 int plugged_devices_c = plugged_devices.Count();
1536 for (
int i = 0; i < plugged_devices_c; ++i )
1538 EntityAI device = plugged_devices.Get(i);
1539 if ( device != original_caller )
1541 device.GetCompEM().UpdateCanWork();
1542 device.GetCompEM().DeviceUpdate();
1543 device.GetCompEM().StartUpdates();
1544 device.GetCompEM().WakeUpWholeBranch( original_caller );
1558 if (!plug_owner_by_socket)
1567 for (
int i = 0; i < slots_c; ++i )
1590 string texture_path = device_to_plug.GetCompEM().GetCordTextureFile();
1591 int selection_index =
m_ThisEntityAI.GetHiddenSelectionIndex( plugged_selection );
1592 m_ThisEntityAI.SetObjectTexture( selection_index, texture_path );
1593 device_to_plug.GetCompEM().SetMySocketID(socket_id);
1631 device_to_plug.IncreaseLifetime();
1633 if ( device_to_plug.GetCompEM().IsPlugged() )
1634 device_to_plug.GetCompEM().UnplugThis();
1681 plug_owner.GetCompEM().SetMySocketID(-1);
1696 float available_energy =
AddEnergy(-amount);
1698 if ( available_energy < 0 &&
IsPlugged() )
1703 if (next_power_source && next_power_source != original_caller)
1705 return next_power_source.GetCompEM().FindAndConsumeEnergy( original_caller, -available_energy );
1709 if ( available_energy >= 0)
1769 float consumed_energy_coef;
1775 consumed_energy_coef = 1.0;
1781 consumed_energy_coef = time / 1000;
1784 if (consumed_energy_coef > 0)
1788 bool has_consumed_enough =
true;
1795 if ( has_consumed_enough )
1805 OnWork( consume_energy );
array< ref PlayerStatBase > Get()
proto native int ConfigGetChildrenCount(string path)
Get count of subclasses in config class on path.
proto native float ConfigGetFloat(string path)
Get float value from config on path.
proto native void ConfigGetIntArray(string path, out TIntArray values)
Get array of integers from config on path.
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto bool ConfigGetChildName(string path, int index, out string name)
Get name of subclass in config class on path.
proto int GetTime()
returns mission time in milliseconds
protected bool m_ShowSocketsInInventory
void StoreEnergySourceIDs(int b1, int b2, int b3, int b4)
protected int m_EnergySourceStorageIDb2
float AddEnergy(float added_energy)
Energy manager: Adds energy to this device and clamps it within its min/max storage limits....
int GetEnergySourceStorageIDb2()
static protected const string SOCKET_
protected int m_EnergySourceStorageIDb1
protected void SetPowered(bool state)
void SetUpdateInterval(float value)
Energy manager: Sets the interval of the OnWork(...) calls. Changing this value does not change the r...
void SwitchOff()
Energy manager: Switches OFF the device.
protected int m_AttachmentActionType
ref array< EntityAI > m_PluggedDevices
override void Event_OnAwake()
void SetCordLength(float new_length)
Energy manager: Changes the length of the virtual power cord.
EntityAI m_Sockets[MAX_SOCKETS_COUNT]
static protected const string _AVAILABLE
bool IsPlugged()
Energy manager: Returns true if this device is plugged into some other device (even if they are OFF o...
bool CanWork(float test_energy=-1)
Energy manager: Checks whenever this device can do work or not.
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 g...
protected void SetEnergySource(EntityAI source)
bool HasElectricityIcon()
Energy manager: Returns true if the electricity icon (bolt) is supposed to be visible for this device...
void SetAttachmentAction(int new_action_type)
protected bool FindAndConsumeEnergy(EntityAI original_caller, float amount, bool ignore_switch_state=false)
void SetDeviceBySocketID(int id, EntityAI plugged_device)
Energy manager: Stores the device which is plugged into the given socket ID.
float GetEnergy()
Energy manager: Returns the amount of stored energy this device has.
bool GetRestorePlugState()
array< EntityAI > GetPoweredDevices()
Energy manager: Returns an array of devices which are plugged into this one and are turned on.
EntityAI GetEnergySource()
Energy manager: Returns the energy source this device is plugged into.
void OnAttachmentAdded(EntityAI elec_device)
void SetPlugType(int new_type)
array< EntityAI > GetPluggedDevices()
Energy manager: Returns an array of devices which are plugged into this one.
void UnplugThis()
Energy manager: Unplugs this device from its power source.
void SwitchOn()
Energy manager: Switches ON the device so it starts doing its work if it has enough energy.
bool CanSwitchOn()
Energy manager: Checks if the device can be switched ON.
void UpdatePlugState()
Energy manager: Unplugs this device when it's necesarry.
protected float m_CordLength
void SetEnergy(float new_energy)
Energy manager: Sets stored energy for this device. It ignores the min/max limit!
float GetEnergy0To1()
Energy manager: Returns % of stored energy this device has as float (from 0.0 to 1....
protected float m_SocketsCount
bool CheckWetness()
Energy manager: Checks if this device is being stopped from working by its wetness level....
void ~ComponentEnergyManager()
protected bool m_IsSwichedOnPreviousState
protected const float DEFAULT_UPDATE_INTERVAL
protected int m_EnergySourceNetworkIDLow
protected float m_ReduceMaxEnergyByDamageCoef
protected int GetMySocketID()
int GetEnergySourceStorageIDb4()
protected bool m_AutoSwitchOff
bool HasVisibleSocketsInInventory()
void HandleMoveInsideCargo(EntityAI container)
float GetCurrentUpdateTime()
void OnEnergyConsumed()
Energy manager: Called when energy was consumed on this device.
int GetEnergy0To100()
Energy manager: Returns % of stored energy this device has as integer (from 0 to 100)
int GetEnergySourceNetworkIDHigh()
protected bool m_IsPassiveDevice
protected float m_LastUpdateTime
Shape DrawArrow(vector from, vector to, float size=0.5, int color=0xFFFFFFFF, float flags=0)
protected bool m_AutoSwitchOffWhenInCargo
protected float m_WetnessExposure
void InteractBranch(EntityAI originalCaller, Man player=null, int system=0)
static const string SEL_CORD_FOLDED
void GetCompatiblePlugTypes(out TIntArray IDs)
void OnOwnSocketTaken(EntityAI device)
void SetEnergyUsage(float new_usage)
Energy manager: Changes the energy usage per second.
protected void UpdateSocketSelections(int socket_id, EntityAI device_to_plug)
protected bool PlugInDevice(EntityAI device_to_plug, int socket_id=-1)
void SetElectricityIconVisibility(bool make_visible)
Energy manager: Sets visibility of the electricity icon (bolt).
bool IsWorking()
Energy manager: Returns true if this device is working right now.
void SetCordTextureFile(string new_path)
protected bool m_CanStopWork
ref map< string, EntityAI > m_DeviceByPlugSelection
bool HasEnoughStoredEnergy()
Energy manager: Returns true if this device has enough of stored energy for its own use.
void ResetEnergyUsage()
Energy manager: Resets energy usage to default (config) value.
protected void StopUpdates()
void OnWork(float consumed_energy)
protected bool m_IsSwichedOn
protected void PlugCordIntoSocket(EntityAI device_to_plug, int socket_id=-1)
protected bool m_HasElectricityIcon
void SetEnergy0To1(float energy01)
Energy manager: Sets stored energy for this device between 0 and MAX based on relative input value be...
protected bool m_ConvertEnergyToQuantity
EntityAI GetThisEntityAI()
void UpdateSelections()
Energy manager: Shows/Hides all selections this system works with. Call this if something is wrong wi...
void OnIsPlugged(EntityAI source_device)
protected void OnInteractBranch(EntityAI originalCaller, Man player, int system)
Called when the player is interacting with an item containing this energy component,...
protected float m_EnergyUsage
float GetEnergyMax()
Energy manager: Returns the maximum amount of energy this device can curently store....
void UnplugAllDevices()
Energy manager: Unplugs everything directly connected to this device.
void RestorePlugState(bool state)
void OnAttachmentRemoved(EntityAI elec_device)
override int GetCompType()
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 s...
protected bool m_RestorePlugState
float GetCordLength()
Energy manager: Returns the length of the virtual power cord.
protected bool m_IsPlugged
static protected bool m_DebugPlugs
protected void SetPlugOwner(string selection_name, EntityAI device)
static protected const string _PLUGGED
const int MAX_SOCKETS_COUNT
protected void UnplugCordFromSocket(int socket_to_unplug_ID)
void SetEnergyMaxPristine(float new_limit)
Energy manager: Changes the maximum amount of energy this device can store (when pristine).
void RememberLastUpdateTime()
bool HasFreeSocket(int socket_id=-1)
Energy manager: Returns true if this device has any free socket to receive a plug....
float GetWetnessExposure()
Returns wetness exposure value defined in config.
bool IsSelectionAPlug(string selection_to_test)
Energy manager: Returns true if this selection is a plug that's plugged into this device....
override void Event_OnInit()
int GetSocketsCount()
Energy manager: Returns the count of power sockets (whenever used or not)
protected Shape m_DebugPlugArrow
bool ConsumeEnergy(float amount)
Energy manager: Consumes the given amount of energy. If there is not enough of stored energy in this ...
int GetEnergySourceStorageIDb1()
protected float m_EnergyStorageMax
protected int m_EnergySourceStorageIDb4
protected void SetMySocketID(int slot_ID)
protected int m_MySocketID
float GetUpdateInterval()
Energy manager: Returns the update interval of this device.
int GetEnergySourceNetworkIDLow()
int GetEnergySourceStorageIDb3()
protected bool m_IsWorking
void SetEnergySourceClient(EntityAI source)
void OnEnergyAdded()
Energy manager: Called when energy was added on this device.
EntityAI GetPlugOwner(string plug_selection_name)
Energy manager: Returns the device to which the given plug selection belongs to.
bool GetPreviousSwitchState()
bool IsCordFolded()
Energy manager: Returns true if the cord of this device is folded. Returns false if it's plugged.
float GetEnergyMaxPristine()
Energy manager: Returns the maximum amount of energy this device can store. It's damage is NOT taken ...
void ComponentEnergyManager()
bool CanReceivePlugFrom(EntityAI device_to_plug)
Energy manager: Returns true if this device can receive power plug of the other device.
string GetCordTextureFile()
Energy manager: Returns path to the cord texture file.
void OnOwnSocketReleased(EntityAI device)
EntityAI GetPluggedDevice()
Energy manager: Returns a device which is plugged into this one. If there are more devices to choose ...
void SetDebugPlugs(bool newVal)
float GetEnergyUsage()
Energy manager: Returns the number of energy this device needs to run itself (See its config >> energ...
protected int m_EnergySourceStorageIDb3
protected float m_UpdateInterval
void UnplugDevice(EntityAI device_to_unplug)
Energy manager: Unplugs the given device from this one.
void SetPassiveState(bool state=true)
Energy manager: Changes the status of this device. When it's passive (true), the main timer and OnWor...
bool HasConversionOfEnergyToQuantity()
Energy manager: Returns true if this item automatically converts its energy to quantity.
protected int m_EnergySourceNetworkIDHigh
protected ref TIntArray m_CompatiblePlugTypes
bool IsPassive()
Energy manager: Returns true if this device is set to be passive. False if otherwise.
bool CanSwitchOff()
Energy manager: Checks if the device can be switched OFF.
ref Timer m_UpdateQuantityTimer
protected string m_CordTextureFile
void ClearLastUpdateTime()
static const string SEL_CORD_PLUGGED
int GetPluggedDevicesCount()
Energy manager: Returns the number of devices plugged into this one.
bool CanBePluggedInto(EntityAI potential_energy_provider)
Energy manager: Returns true if this device can be plugged into the given energy source....
int GetPlugType()
Energy manager: Returns plug type. Check \DZ\data\basicDefines.hpp OR \Scripts\Classes\Component_cons...
void OnIsUnplugged(EntityAI last_energy_source)
EntityAI GetDeviceBySocketID(int id)
Energy manager: Returns the device which is plugged into the given socket ID.
bool IsPlugCompatible(int plug_ID)
Energy manager: Checks if the given plug is compatible with this device's socket. Used by CanReceiveP...
int GetAttachmentAction()
protected void WakeUpWholeBranch(EntityAI original_caller)
bool IsSwitchedOn()
Energy manager: Returns state of the switch. Whenever the device is working or not does not matter....
protected EntityAI m_ThisEntityAI
Wrapper class for managing sound through SEffectManager.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto float Normalize()
Normalizes vector. Returns length.
vector Perpend()
Returns perpendicular vector. Perpendicular vector is computed as cross product between input vector ...
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto native CGame GetGame()
const int COMP_TYPE_ENERGY_MANAGER
void Error(string err)
Messagebox with error message.
proto void DPrint(string var)
Prints content of variable to console/log. Should be used for critical messages so it will appear in ...
proto volatile int CallFunction(Class inst, string function, out void returnVal, void parm)
static proto float Round(float f)
Returns mathematical round of value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float Min(float x, float y)
Returns smaller of two given values.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.