62 protected static const string SOCKET_ =
"socket_";
63 protected static const string _PLUGGED =
"_plugged";
139 if ( BBB && BBB.GetType() ==
"Fence" )
141 to = to +
"0 -1.3 0";
162 pts[2] = to - dir1 - dir2;
163 pts[3] = to - dir1 + dir2;
166 return Shape.CreateLines(color, flags, pts, 5);
178 string cfg_energy_manager = cfg_item +
" EnergyManager ";
210 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!";
226 if ( update_interval <= 0 )
232 string cfg_check_energy_limit = cfg_energy_manager +
"energyStorageMax";
234 if ( !
GetGame().ConfigIsExisting (cfg_check_energy_limit) &&
m_Energy > 0 )
240 string cfg_check_plug_types = cfg_energy_manager +
"compatiblePlugTypes";
242 if (
GetGame().ConfigIsExisting (cfg_check_plug_types) )
254 string error_message_cord =
"Warning! " +
m_ThisEntityAI.GetType() +
": config parameter 'cordLength' is less than 0! Cord length should not be negative!";
255 DPrint(error_message_cord);
262 string cfg_animation_sources =
"cfgVehicles " +
m_ThisEntityAI.GetType() +
" " +
"AnimationSources ";
265 for (
int i_selection = 0; i_selection < animation_sources_count; i_selection++)
280 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!";
281 DPrint(error_message_sockets);
310 #ifdef DIAG_DEVELOPER
311 GetGame().m_EnergyManagerArray.Insert(
this );
456 bool deviceFound =
false;
458 for (
int i = indexStart; i >= 0; --i)
462 if (plugged_device == device_to_unplug)
472 int socket_ID = device_to_unplug.GetCompEM().GetMySocketID();
474 device_to_unplug.GetCompEM().SetEnergySource(null);
475 device_to_unplug.GetCompEM().DeviceUpdate();
476 device_to_unplug.GetCompEM().StartUpdates();
511 for (
int i = indexStart; i >= 0; --i)
533 if ( old_energy -
GetEnergyUsage() <= 0 || (old_energy != new_energy &&
Math.
Min(old_energy,new_energy) <= 0) )
552 for (
int i = 0; i < slots_c; ++i )
562 string texture_path = plug_owner.GetCompEM().GetCordTextureFile();
563 int selection_index =
m_ThisEntityAI.GetHiddenSelectionIndex( plugged_selection );
596 vector playerPosition = player.GetPosition();
662 string cfg_energy_usage =
"CfgVehicles " +
m_ThisEntityAI.GetType() +
" EnergyManager ";
696 bool current_state =
CanWork();
737 return energy_source.GetCompEM().PlugInDevice(
m_ThisEntityAI, socket_id);
770 float energy_usage = test_energy;
774 if (energy_usage == -1)
784 if (gathered_energy <= 0 && energy_usage <= 0)
789 int cycle_limit = 500;
791 while ( gathered_energy < energy_usage )
800 DPrint(
"Energy Manager ERROR: The 'cycle_limit' safety break had to be activated to prevent possible game freeze. Dumping debug information...");
805 if (energy_source.GetCompEM())
826 if ( energy_source && energy_source !=
m_ThisEntityAI && !energy_source.IsRuined() && energy_source.GetCompEM() && energy_source.GetCompEM().IsSwitchedOn() && energy_source.GetCompEM().CheckWetness() )
828 gathered_energy = gathered_energy + energy_source.GetCompEM().GetEnergy();
829 energy_source = energy_source.GetCompEM().GetEnergySource();
924 if ( plugged_devices < plugged_devices_limit )
960 if ( plug_ID_to_Check == plug_ID )
982 if ( device_to_plug.GetCompEM().GetEnergySource() !=
m_ThisEntityAI)
986 if ( device_to_plug.GetCompEM().IsEnergySourceAtReach( device_to_plug.GetPosition(), 0,
m_ThisEntityAI.GetPosition() ) )
1000 return potential_energy_provider.GetCompEM().CanReceivePlugFrom(
m_ThisEntityAI );
1033 if ( !
IsPlugged() && override_source_position ==
"-1 -1 -1" )
1046 if ( override_source_position ==
"-1 -1 -1" )
1053 source_pos = energy_source.GetPosition();
1058 source_pos = override_source_position;
1084 for (
int i = socket_count; i >= 0; --i )
1088 if ( selection_to_test == real_selection)
1192 #ifdef DIAG_DEVELOPER
1193 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_CONSUMPTION) || (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_RECHARGE)))
1222 if (added_energy != 0)
1225 #ifdef DIAG_DEVELOPER
1226 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_CONSUMPTION) && added_energy < 0)
1228 float timeAccel = FeatureTimeAccel.GetFeatureTimeAccelValue();
1229 added_energy *= timeAccel;
1233 bool energy_was_added = (added_energy > 0);
1235 float energy_to_clamp =
GetEnergy() + added_energy;
1240 if (energy_was_added)
1245 return energy_to_clamp - clamped_energy;
1254 float max_health = 0;
1269 float damage_coef = 1 - (health / max_health);
1342 for (
int i = 0; i < plugged_devices_c; ++i )
1347 return_array.Insert(device);
1351 return return_array;
1395 m_ThisEntityAI.PlaySoundSet( sound_plug,
"cablereel_plugin_SoundSet", 0, 0 );
1408 m_ThisEntityAI.PlaySoundSet( sound_unplug,
"cablereel_unplug_SoundSet", 0, 0 );
1422 if ( elec_device.GetCompEM().CanReceivePlugFrom(
m_ThisEntityAI ) )
1447 elec_device.GetCompEM().UnplugThis();
1509 foreach (
EntityAI device : devices)
1511 if ( device != originalCaller )
1513 device.GetCompEM().InteractBranch( originalCaller, player, system );
1532 int plugged_devices_c = plugged_devices.Count();
1534 for (
int i = 0; i < plugged_devices_c; ++i )
1536 EntityAI device = plugged_devices.Get(i);
1537 if ( device != original_caller )
1539 device.GetCompEM().UpdateCanWork();
1540 device.GetCompEM().DeviceUpdate();
1541 device.GetCompEM().StartUpdates();
1542 device.GetCompEM().WakeUpWholeBranch( original_caller );
1556 if (!plug_owner_by_socket)
1565 for (
int i = 0; i < slots_c; ++i )
1588 string texture_path = device_to_plug.GetCompEM().GetCordTextureFile();
1589 int selection_index =
m_ThisEntityAI.GetHiddenSelectionIndex( plugged_selection );
1590 m_ThisEntityAI.SetObjectTexture( selection_index, texture_path );
1591 device_to_plug.GetCompEM().SetMySocketID(socket_id);
1623 device_to_plug.IncreaseLifetime();
1625 if (device_to_plug.GetCompEM().IsPlugged())
1626 device_to_plug.GetCompEM().UnplugThis();
1673 plug_owner.GetCompEM().SetMySocketID(-1);
1688 float available_energy =
AddEnergy(-amount);
1690 if ( available_energy < 0 &&
IsPlugged() )
1695 if (next_power_source && next_power_source != original_caller)
1697 return next_power_source.GetCompEM().FindAndConsumeEnergy( original_caller, -available_energy );
1701 if ( available_energy >= 0)
1761 float consumed_energy_coef;
1767 consumed_energy_coef = 1.0;
1773 consumed_energy_coef = time / 1000;
1776 if (consumed_energy_coef > 0)
1780 bool has_consumed_enough =
true;
1787 if ( has_consumed_enough )
1797 OnWork( consume_energy );
proto bool ConfigGetChildName(string path, int index, out string name)
Get name of subclass 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 int GetTime()
returns mission time in milliseconds
proto native int ConfigGetChildrenCount(string path)
Get count of subclasses in config class on path.
static const string SEL_CORD_FOLDED
void SetElectricityIconVisibility(bool make_visible)
Energy manager: Sets visibility of the electricity icon (bolt).
void SwitchOn()
Energy manager: Switches ON the device so it starts doing its work if it has enough energy.
float GetEnergyMax()
Energy manager: Returns the maximum amount of energy this device can curently store....
bool GetPreviousSwitchState()
void UnplugAllDevices()
Energy manager: Unplugs everything directly connected to this device.
void SetMySocketID(int slot_ID)
static const string SOCKET_
void InteractBranch(EntityAI originalCaller, Man player=null, int system=0)
int m_EnergySourceStorageIDb3
float GetEnergyUsage()
Energy manager: Returns the number of energy this device needs to run itself (See its config >> energ...
void OnInteractBranch(EntityAI originalCaller, Man player, int system)
Called when the player is interacting with an item containing this energy component,...
void ComponentEnergyManager()
int GetEnergySourceNetworkIDLow()
bool IsWorking()
Energy manager: Returns true if this device is working right now.
int m_EnergySourceStorageIDb2
void SetEnergyMaxPristine(float new_limit)
Energy manager: Changes the maximum amount of energy this device can store (when pristine).
Shape DrawArrow(vector from, vector to, float size=0.5, int color=0xFFFFFFFF, float flags=0)
static const string _AVAILABLE
bool m_ConvertEnergyToQuantity
void SetDebugPlugs(bool newVal)
void GetCompatiblePlugTypes(out TIntArray IDs)
void SetEnergy0To1(float energy01)
Energy manager: Sets stored energy for this device between 0 and MAX based on relative input value be...
bool HasFreeSocket(int socket_id=-1)
Energy manager: Returns true if this device has any free socket to receive a plug....
ref Timer m_UpdateQuantityTimer
float GetWetnessExposure()
Returns wetness exposure value defined in config.
bool m_HasElectricityIcon
void WakeUpWholeBranch(EntityAI original_caller)
void UnplugDevice(EntityAI device_to_unplug)
Energy manager: Unplugs the given device from this one.
bool CheckWetness()
Energy manager: Checks if this device is being stopped from working by its wetness level....
static const string _PLUGGED
void SetUpdateInterval(float value)
Energy manager: Sets the interval of the OnWork(...) calls. Changing this value does not change the r...
void SetPassiveState(bool state=true)
Energy manager: Changes the status of this device. When it's passive (true), the main timer and OnWor...
bool PlugInDevice(EntityAI device_to_plug, int socket_id=-1)
void SetAttachmentAction(int new_action_type)
bool FindAndConsumeEnergy(EntityAI original_caller, float amount, bool ignore_switch_state=false)
void OnEnergyAdded()
Energy manager: Called when energy was added on this device.
void UnplugCordFromSocket(int socket_to_unplug_ID)
float AddEnergy(float added_energy)
Energy manager: Adds energy to this device and clamps it within its min/max storage limits....
const float DEFAULT_UPDATE_INTERVAL
int GetEnergySourceStorageIDb4()
void UnplugThis()
Energy manager: Unplugs this device from its power source.
float GetCurrentUpdateTime()
int GetPluggedDevicesCount()
Energy manager: Returns the number of devices plugged into this one.
void ClearLastUpdateTime()
void SetCordLength(float new_length)
Energy manager: Changes the length of the virtual power cord.
void SetEnergySourceClient(EntityAI source)
void SetEnergySource(EntityAI source)
int m_EnergySourceNetworkIDLow
int GetEnergy0To100()
Energy manager: Returns % of stored energy this device has as integer (from 0 to 100)
void ~ComponentEnergyManager()
void PlugCordIntoSocket(EntityAI device_to_plug, int socket_id=-1)
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...
void HandleMoveInsideCargo(EntityAI container)
float GetEnergy()
Energy manager: Returns the amount of stored energy this device has.
int GetPlugType()
Energy manager: Returns plug type. Check \DZ\data\basicDefines.hpp OR \Scripts\Classes\Component_cons...
bool CanBePluggedInto(EntityAI potential_energy_provider)
Energy manager: Returns true if this device can be plugged into the given energy source....
bool IsPlugged()
Energy manager: Returns true if this device is plugged into some other device (even if they are OFF o...
EntityAI GetEnergySource()
Energy manager: Returns the energy source this device is plugged into.
ref array< EntityAI > m_PluggedDevices
void OnAttachmentRemoved(EntityAI elec_device)
EntityAI GetThisEntityAI()
void OnWork(float consumed_energy)
const int MAX_SOCKETS_COUNT
array< EntityAI > GetPluggedDevices()
Energy manager: Returns an array of devices which are plugged into this one.
float m_ReduceMaxEnergyByDamageCoef
int GetEnergySourceNetworkIDHigh()
bool IsPassive()
Energy manager: Returns true if this device is set to be passive. False if otherwise.
bool HasConversionOfEnergyToQuantity()
Energy manager: Returns true if this item automatically converts its energy to quantity.
void SetPowered(bool state)
void SetPlugType(int new_type)
void StoreEnergySourceIDs(int b1, int b2, int b3, int b4)
int GetEnergySourceStorageIDb2()
ref TIntArray m_CompatiblePlugTypes
void UpdatePlugState()
Energy manager: Unplugs this device when it's necesarry.
void OnAttachmentAdded(EntityAI elec_device)
void OnIsPlugged(EntityAI source_device)
EntityAI m_Sockets[MAX_SOCKETS_COUNT]
string GetCordTextureFile()
Energy manager: Returns path to the cord texture file.
ref map< string, EntityAI > m_DeviceByPlugSelection
bool IsSelectionAPlug(string selection_to_test)
Energy manager: Returns true if this selection is a plug that's plugged into this device....
void SetEnergy(float new_energy)
Energy manager: Sets stored energy for this device. It ignores the min/max limit!
void SetPlugOwner(string selection_name, EntityAI device)
float GetCordLength()
Energy manager: Returns the length of the virtual power cord.
EntityAI GetPlugOwner(string plug_selection_name)
Energy manager: Returns the device to which the given plug selection belongs to.
int GetAttachmentAction()
bool CanWork(float test_energy=-1)
Energy manager: Checks whenever this device can do work or not.
EntityAI GetPluggedDevice()
Energy manager: Returns a device which is plugged into this one. If there are more devices to choose ...
void UpdateSelections()
Energy manager: Shows/Hides all selections this system works with. Call this if something is wrong wi...
void OnIsUnplugged(EntityAI last_energy_source)
bool GetRestorePlugState()
bool HasVisibleSocketsInInventory()
int m_AttachmentActionType
bool m_ShowSocketsInInventory
static const string SEL_CORD_PLUGGED
bool IsCordFolded()
Energy manager: Returns true if the cord of this device is folded. Returns false if it's plugged.
override int GetCompType()
void RestorePlugState(bool state)
int m_EnergySourceStorageIDb4
bool m_AutoSwitchOffWhenInCargo
float GetEnergy0To1()
Energy manager: Returns % of stored energy this device has as float (from 0.0 to 1....
void SwitchOff()
Energy manager: Switches OFF the device.
void OnOwnSocketReleased(EntityAI device)
array< EntityAI > GetPoweredDevices()
Energy manager: Returns an array of devices which are plugged into this one and are turned on.
override void Event_OnAwake()
bool ConsumeEnergy(float amount)
Energy manager: Consumes the given amount of energy. If there is not enough of stored energy in this ...
void RememberLastUpdateTime()
bool CanSwitchOn()
Energy manager: Checks if the device can be switched ON.
void ResetEnergyUsage()
Energy manager: Resets energy usage to default (config) value.
int m_EnergySourceNetworkIDHigh
int GetEnergySourceStorageIDb1()
bool IsPlugCompatible(int plug_ID)
Energy manager: Checks if the given plug is compatible with this device's socket. Used by CanReceiveP...
void SetEnergyUsage(float new_usage)
Energy manager: Changes the energy usage per second.
void OnEnergyConsumed()
Energy manager: Called when energy was consumed on this device.
void SetCordTextureFile(string new_path)
override void Event_OnInit()
bool CanSwitchOff()
Energy manager: Checks if the device can be switched OFF.
int GetSocketsCount()
Energy manager: Returns the count of power sockets (whenever used or not)
void SetDeviceBySocketID(int id, EntityAI plugged_device)
Energy manager: Stores the device which is plugged into the given socket ID.
void UpdateSocketSelections(int socket_id, EntityAI device_to_plug)
float GetUpdateInterval()
Energy manager: Returns the update interval of this device.
bool m_IsSwichedOnPreviousState
bool HasElectricityIcon()
Energy manager: Returns true if the electricity icon (bolt) is supposed to be visible for this device...
void OnOwnSocketTaken(EntityAI device)
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...
int m_EnergySourceStorageIDb1
EntityAI GetDeviceBySocketID(int id)
Energy manager: Returns the device which is plugged into the given socket ID.
float GetEnergyMaxPristine()
Energy manager: Returns the maximum amount of energy this device can store. It's damage is NOT taken ...
bool IsSwitchedOn()
Energy manager: Returns state of the switch. Whenever the device is working or not does not matter....
int GetEnergySourceStorageIDb3()
bool HasEnoughStoredEnergy()
Energy manager: Returns true if this device has enough of stored energy for its own use.
bool CanReceivePlugFrom(EntityAI device_to_plug)
Energy manager: Returns true if this device can receive power plug of the other device.
Wrapper class for managing sound through SEffectManager.
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto float Normalize()
Normalizes vector. Returns length.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
vector Perpend()
Returns perpendicular vector. Perpendicular vector is computed as cross product between input vector ...
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 Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float Min(float x, float y)
Returns smaller of two given values.
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'.