62 protected static const string SOCKET_ =
"socket_";
63 protected static const string _PLUGGED =
"_plugged";
136 if ( BBB && BBB.GetType() ==
"Fence" )
138 to = to +
"0 -1.3 0";
159 pts[2] = to - dir1 - dir2;
160 pts[3] = to - dir1 + dir2;
163 return Shape.CreateLines(color, flags, pts, 5);
178 string cfg_energy_manager = cfg_item +
" EnergyManager ";
182 bool switch_on =
g_Game.ConfigGetFloat(cfg_energy_manager +
"switchOnAtSpawn");
200 float update_interval =
g_Game.ConfigGetFloat(cfg_energy_manager +
"updateInterval");
206 float cfg_max_quantity =
g_Game.ConfigGetFloat (cfg_item +
" varQuantityMax");
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!";
223 if ( update_interval <= 0 )
229 string cfg_check_energy_limit = cfg_energy_manager +
"energyStorageMax";
231 if ( !
g_Game.ConfigIsExisting (cfg_check_energy_limit) &&
m_Energy > 0 )
237 string cfg_check_plug_types = cfg_energy_manager +
"compatiblePlugTypes";
239 if (
g_Game.ConfigIsExisting (cfg_check_plug_types) )
251 string error_message_cord =
"Warning! " +
m_ThisEntityAI.GetType() +
": config parameter 'cordLength' is less than 0! Cord length should not be negative!";
252 DPrint(error_message_cord);
259 string cfg_animation_sources =
"cfgVehicles " +
m_ThisEntityAI.GetType() +
" " +
"AnimationSources ";
260 int animation_sources_count =
g_Game.ConfigGetChildrenCount(cfg_animation_sources);
262 for (
int i_selection = 0; i_selection < animation_sources_count; i_selection++)
266 g_Game.ConfigGetChildName(cfg_animation_sources, i_selection, selection);
277 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!";
278 DPrint(error_message_sockets);
307 #ifdef DIAG_DEVELOPER
308 g_Game.m_EnergyManagerArray.Insert(
this );
452 bool deviceFound =
false;
454 for (
int i = indexStart; i >= 0; --i)
458 if (plugged_device == device_to_unplug)
468 int socket_ID = device_to_unplug.GetCompEM().GetMySocketID();
470 device_to_unplug.GetCompEM().SetEnergySource(null);
471 device_to_unplug.GetCompEM().DeviceUpdate();
472 device_to_unplug.GetCompEM().StartUpdates();
507 for (
int i = indexStart; i >= 0; --i)
529 if (old_energy -
GetEnergyUsage() <= 0 || (old_energy != new_energy &&
Math.
Min(old_energy,new_energy) <= 0))
551 for (
int i = 0; i < slots_c; ++i)
561 string texture_path = plug_owner.GetCompEM().GetCordTextureFile();
562 int selection_index =
m_ThisEntityAI.GetHiddenSelectionIndex(plugged_selection);
595 vector playerPosition = player.GetPosition();
664 string cfg_energy_usage =
"CfgVehicles " +
m_ThisEntityAI.GetType() +
" EnergyManager ";
698 bool current_state =
CanWork();
743 return energy_source.GetCompEM().PlugInDevice(
m_ThisEntityAI, socket_id);
781 float energy_usage = test_energy;
785 if (energy_usage == -1)
795 if (gathered_energy <= 0 && energy_usage <= 0)
800 int cycle_limit = 500;
802 while ( gathered_energy < energy_usage )
811 DPrint(
"Energy Manager ERROR: The 'cycle_limit' safety break had to be activated to prevent possible game freeze. Dumping debug information...");
816 if (energy_source.GetCompEM())
837 if ( energy_source && energy_source !=
m_ThisEntityAI && !energy_source.IsRuined() && energy_source.GetCompEM() && energy_source.GetCompEM().IsSwitchedOn() && energy_source.GetCompEM().CheckWetness() )
839 gathered_energy = gathered_energy + energy_source.GetCompEM().GetEnergy();
840 energy_source = energy_source.GetCompEM().GetEnergySource();
949 if ( plugged_devices < plugged_devices_limit )
982 for (
int i = 0; i < nCompatiblePlugTypes; ++i )
986 if ( plug_ID_to_Check == plug_ID )
1007 if ( device_to_plug.GetCompEM().GetEnergySource() !=
m_ThisEntityAI)
1011 if ( device_to_plug.GetCompEM().IsEnergySourceAtReach( device_to_plug.GetPosition(), 0,
m_ThisEntityAI.GetPosition() ) )
1027 return potential_energy_provider.GetCompEM().CanReceivePlugFrom(
m_ThisEntityAI);
1065 if ( !
IsPlugged() && override_source_position ==
"-1 -1 -1" )
1078 if ( override_source_position ==
"-1 -1 -1" )
1085 source_pos = energy_source.GetPosition();
1090 source_pos = override_source_position;
1116 for (
int i = socket_count; i >= 0; --i )
1120 if ( selection_to_test == real_selection)
1224 #ifdef DIAG_DEVELOPER
1225 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_CONSUMPTION) || (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_RECHARGE)))
1254 if (added_energy != 0)
1257 #ifdef DIAG_DEVELOPER
1258 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_CONSUMPTION) && added_energy < 0)
1260 float timeAccel = FeatureTimeAccel.GetFeatureTimeAccelValue();
1261 added_energy *= timeAccel;
1265 bool energy_was_added = (added_energy > 0);
1267 float energy_to_clamp =
GetEnergy() + added_energy;
1272 if (energy_was_added)
1277 return energy_to_clamp - clamped_energy;
1286 float max_health = 0;
1301 float damage_coef = 1 - (health / max_health);
1374 for (
int i = 0; i < plugged_devices_c; ++i )
1379 return_array.Insert(device);
1383 return return_array;
1429 m_ThisEntityAI.PlaySoundSet(sound_plug,
"cablereel_plugin_SoundSet", 0, 0);
1445 m_ThisEntityAI.PlaySoundSet( sound_unplug,
"cablereel_unplug_SoundSet", 0, 0 );
1487 elec_device.GetCompEM().UnplugThis();
1538 foreach (
EntityAI device : devices)
1540 if ( device != originalCaller )
1542 device.GetCompEM().InteractBranch( originalCaller, player, system );
1562 int plugged_devices_c = plugged_devices.Count();
1564 for (
int i = 0; i < plugged_devices_c; ++i )
1566 EntityAI device = plugged_devices.Get(i);
1567 if ( device != original_caller )
1569 device.GetCompEM().UpdateCanWork();
1570 device.GetCompEM().DeviceUpdate();
1571 device.GetCompEM().StartUpdates();
1572 device.GetCompEM().WakeUpWholeBranch( original_caller );
1586 if (!plug_owner_by_socket)
1595 for (
int i = 0; i < slots_c; ++i )
1621 string texture_path = device_to_plug.GetCompEM().GetCordTextureFile();
1622 int selection_index =
m_ThisEntityAI.GetHiddenSelectionIndex( plugged_selection );
1623 m_ThisEntityAI.SetObjectTexture( selection_index, texture_path );
1624 device_to_plug.GetCompEM().SetMySocketID(socket_id);
1656 device_to_plug.IncreaseLifetime();
1658 if (device_to_plug.GetCompEM().IsPlugged())
1659 device_to_plug.GetCompEM().UnplugThis();
1706 plug_owner.GetCompEM().SetMySocketID(-1);
1721 float available_energy =
AddEnergy(-amount);
1723 if (available_energy < 0 &&
IsPlugged())
1728 if (next_power_source && next_power_source != original_caller)
1730 return next_power_source.GetCompEM().FindAndConsumeEnergy(original_caller, -available_energy);
1734 if (available_energy >= 0)
1795 float consumed_energy_coef;
1801 consumed_energy_coef = 1.0;
1807 consumed_energy_coef = time / 1000;
1810 if (consumed_energy_coef > 0)
1814 bool has_consumed_enough =
true;
1821 if ( has_consumed_enough )
1831 OnWork( consume_energy );
static const string SEL_CORD_FOLDED
ref Timer m_UpdateTimer
DEPRECATED BELOW.
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'.