62 protected static const string SOCKET_ =
"socket_";
63 protected static const string _PLUGGED =
"_plugged";
142 if ( BBB && BBB.GetType() ==
"Fence" )
144 to = to +
"0 -1.3 0";
165 pts[2] = to - dir1 - dir2;
166 pts[3] = to - dir1 + dir2;
169 return Shape.CreateLines(color, flags, pts, 5);
184 string cfg_energy_manager = cfg_item +
" EnergyManager ";
188 bool switch_on =
g_Game.ConfigGetFloat(cfg_energy_manager +
"switchOnAtSpawn");
206 float update_interval =
g_Game.ConfigGetFloat(cfg_energy_manager +
"updateInterval");
212 float cfg_max_quantity =
g_Game.ConfigGetFloat (cfg_item +
" varQuantityMax");
216 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!";
232 if ( update_interval <= 0 )
238 string cfg_check_energy_limit = cfg_energy_manager +
"energyStorageMax";
240 if ( !
g_Game.ConfigIsExisting (cfg_check_energy_limit) &&
m_Energy > 0 )
246 string cfg_check_plug_types = cfg_energy_manager +
"compatiblePlugTypes";
248 if (
g_Game.ConfigIsExisting (cfg_check_plug_types) )
260 string error_message_cord =
"Warning! " +
m_ThisEntityAI.GetType() +
": config parameter 'cordLength' is less than 0! Cord length should not be negative!";
261 DPrint(error_message_cord);
268 string cfg_animation_sources =
"cfgVehicles " +
m_ThisEntityAI.GetType() +
" " +
"AnimationSources ";
269 int animation_sources_count =
g_Game.ConfigGetChildrenCount(cfg_animation_sources);
271 for (
int i_selection = 0; i_selection < animation_sources_count; i_selection++)
275 g_Game.ConfigGetChildName(cfg_animation_sources, i_selection, selection);
286 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!";
287 DPrint(error_message_sockets);
316 #ifdef DIAG_DEVELOPER
317 g_Game.m_EnergyManagerArray.Insert(
this );
465 bool deviceFound =
false;
467 for (
int i = indexStart; i >= 0; --i)
471 if (plugged_device == device_to_unplug)
481 int socket_ID = device_to_unplug.GetCompEM().GetMySocketID();
483 device_to_unplug.GetCompEM().SetEnergySource(null);
484 device_to_unplug.GetCompEM().DeviceUpdate();
485 device_to_unplug.GetCompEM().StartUpdates();
520 for (
int i = indexStart; i >= 0; --i)
542 if (old_energy -
GetEnergyUsage() <= 0 || (old_energy != new_energy &&
Math.
Min(old_energy,new_energy) <= 0))
564 for (
int i = 0; i < slots_c; ++i)
574 string texture_path = plug_owner.GetCompEM().GetCordTextureFile();
575 int selection_index =
m_ThisEntityAI.GetHiddenSelectionIndex(plugged_selection);
608 vector playerPosition = player.GetPosition();
677 string cfg_energy_usage =
"CfgVehicles " +
m_ThisEntityAI.GetType() +
" EnergyManager ";
711 bool current_state =
CanWork();
756 return energy_source.GetCompEM().PlugInDevice(
m_ThisEntityAI, socket_id);
794 float energy_usage = test_energy;
798 if (energy_usage == -1)
808 if (gathered_energy <= 0 && energy_usage <= 0)
813 int cycle_limit = 500;
815 while ( gathered_energy < energy_usage )
824 DPrint(
"Energy Manager ERROR: The 'cycle_limit' safety break had to be activated to prevent possible game freeze. Dumping debug information...");
829 if (energy_source.GetCompEM())
850 if ( energy_source && energy_source !=
m_ThisEntityAI && !energy_source.IsRuined() && energy_source.GetCompEM() && energy_source.GetCompEM().IsSwitchedOn() && energy_source.GetCompEM().CheckWetness() )
852 gathered_energy = gathered_energy + energy_source.GetCompEM().GetEnergy();
853 energy_source = energy_source.GetCompEM().GetEnergySource();
962 if ( plugged_devices < plugged_devices_limit )
995 for (
int i = 0; i < nCompatiblePlugTypes; ++i )
999 if ( plug_ID_to_Check == plug_ID )
1020 if ( device_to_plug.GetCompEM().GetEnergySource() !=
m_ThisEntityAI)
1024 if ( device_to_plug.GetCompEM().IsEnergySourceAtReach( device_to_plug.GetPosition(), 0,
m_ThisEntityAI.GetPosition() ) )
1040 return potential_energy_provider.GetCompEM().CanReceivePlugFrom(
m_ThisEntityAI);
1078 if ( !
IsPlugged() && override_source_position ==
"-1 -1 -1" )
1091 if ( override_source_position ==
"-1 -1 -1" )
1098 source_pos = energy_source.GetPosition();
1103 source_pos = override_source_position;
1129 for (
int i = socket_count; i >= 0; --i )
1133 if ( selection_to_test == real_selection)
1237 #ifdef DIAG_DEVELOPER
1238 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_CONSUMPTION) || (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_RECHARGE)))
1267 if (added_energy != 0)
1270 #ifdef DIAG_DEVELOPER
1271 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_CONSUMPTION) && added_energy < 0)
1273 float timeAccel = FeatureTimeAccel.GetFeatureTimeAccelValue();
1274 added_energy *= timeAccel;
1278 bool energy_was_added = (added_energy > 0);
1280 float energy_to_clamp =
GetEnergy() + added_energy;
1285 if (energy_was_added)
1290 return energy_to_clamp - clamped_energy;
1299 float max_health = 0;
1314 float damage_coef = 1 - (health / max_health);
1387 for (
int i = 0; i < plugged_devices_c; ++i )
1392 return_array.Insert(device);
1396 return return_array;
1446 m_ThisEntityAI.PlaySoundSet(sound_plug,
"cablereel_plugin_SoundSet", 0, 0);
1462 m_ThisEntityAI.PlaySoundSet( sound_unplug,
"cablereel_unplug_SoundSet", 0, 0 );
1504 elec_device.GetCompEM().UnplugThis();
1568 foreach (
EntityAI device : devices)
1570 if ( device != originalCaller )
1572 device.GetCompEM().InteractBranch( originalCaller, player, system );
1592 int plugged_devices_c = plugged_devices.Count();
1594 for (
int i = 0; i < plugged_devices_c; ++i )
1596 EntityAI device = plugged_devices.Get(i);
1597 if ( device != original_caller )
1599 device.GetCompEM().UpdateCanWork();
1600 device.GetCompEM().DeviceUpdate();
1601 device.GetCompEM().StartUpdates();
1602 device.GetCompEM().WakeUpWholeBranch( original_caller );
1616 if (!plug_owner_by_socket)
1625 for (
int i = 0; i < slots_c; ++i )
1651 string texture_path = device_to_plug.GetCompEM().GetCordTextureFile();
1652 int selection_index =
m_ThisEntityAI.GetHiddenSelectionIndex( plugged_selection );
1653 m_ThisEntityAI.SetObjectTexture( selection_index, texture_path );
1654 device_to_plug.GetCompEM().SetMySocketID(socket_id);
1686 device_to_plug.IncreaseLifetime();
1688 if (device_to_plug.GetCompEM().IsPlugged())
1689 device_to_plug.GetCompEM().UnplugThis();
1736 plug_owner.GetCompEM().SetMySocketID(-1);
1751 float available_energy =
AddEnergy(-amount);
1753 if (available_energy < 0 &&
IsPlugged())
1758 if (next_power_source && next_power_source != original_caller)
1760 return next_power_source.GetCompEM().FindAndConsumeEnergy(original_caller, -available_energy);
1764 if (available_energy >= 0)
1825 float consumed_energy_coef;
1831 consumed_energy_coef = 1.0;
1837 consumed_energy_coef = time / 1000;
1840 if (consumed_energy_coef > 0)
1844 bool has_consumed_enough =
true;
1851 if ( has_consumed_enough )
1861 OnWork( consume_energy );
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 ...
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 ...
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'.