DayZ 1.24
Loading...
Searching...
No Matches
VehicleBattery.c
Go to the documentation of this file.
2{
3 override bool CanPutAsAttachment(EntityAI parent)
4 {
5 if (!super.CanPutAsAttachment(parent))
6 return false;
7
8 if (parent.IsInherited(BatteryCharger))
9 {
11 return charger.CanReceiveAttachment(this, InventorySlots.INVALID);
12 }
13
14 if (GetCompEM().GetPluggedDevice())
15 return false;
16
17 return true;
18 }
19
20 override bool CanDetachAttachment(EntityAI parent)
21 {
22 return true;
23 }
24
26 {
27 if (GetCompEM().IsPlugged())
28 return false;
29
30 return super.CanReceiveAttachment(attachment, slotId);
31 }
32
34 {
35 if (!super.CanPutIntoHands(parent))
36 return false;
37
38 if (HasEnergyManager())
39 {
40 ItemBase poweredDevice = ItemBase.Cast(GetCompEM().GetPluggedDevice());
41 if (poweredDevice && poweredDevice.IsInherited(MetalWire))
42 return true;
43 else if (poweredDevice)
44 return false;
45 }
46
47 return true;
48 }
49
50 override bool CanPutInCargo(EntityAI parent)
51 {
52 if (!super.CanPutInCargo(parent))
53 return false;
54
55 ItemBase poweredDevice = ItemBase.Cast(GetCompEM().GetPluggedDevice());
56
57 return !(poweredDevice && poweredDevice.IsInherited(MetalWire));
58 }
59
60 override void OnInventoryEnter(Man player)
61 {
62 super.OnInventoryEnter(player);
63
64 if (GetHierarchyParent() == player || (GetHierarchyParent() && GetHierarchyParent().GetInventory().GetCargo()))
65 {
66 if (HasEnergyManager())
67 {
68 ItemBase poweredDevice = ItemBase.Cast(GetCompEM().GetPluggedDevice());
69
70 if (poweredDevice)
71 {
72 if (poweredDevice.IsInherited(MetalWire))
73 {
74 //Unplug the device the wire is powering, but keep wire plugged to battery
75 if (poweredDevice.GetCompEM().IsPlugged())
76 poweredDevice.GetCompEM().UnplugDevice(poweredDevice.GetCompEM().GetPluggedDevice());
77 }
78 else
79 this.GetCompEM().UnplugAllDevices();
80 }
81 }
82 }
83 }
84
86 {
87 super.OnMovedInsideCargo(container);
88
89 if (HasEnergyManager())
90 {
91 ItemBase poweredDevice = ItemBase.Cast(GetCompEM().GetPluggedDevice());
92
93 if (poweredDevice)
94 {
95 //Should not be possible, but better safe than sorry
96 if (poweredDevice.IsInherited(MetalWire))
97 poweredDevice.GetCompEM().UnplugAllDevices();
98 else
99 this.GetCompEM().UnplugAllDevices();
100 }
101 }
102 }
103
105 {
106 if (GetCompEM().IsPlugged())
107 return false;
108
109 return super.CanDisplayAttachmentSlot(slot_id);
110 }
111
112 override bool DisplayNameRuinAttach()
113 {
114 return true;
115 }
116
117 override bool ShowZonesHealth()
118 {
119 return true;
120 }
121
122 override void SetActions()
123 {
124 super.SetActions();
125
129 }
130
131 //------------------------------------
133 //------------------------------------
134
135 private int m_Efficiency0To10; // Synchronized variable
136 static private float m_EfficiencyDecayStart = 0.1; // At this % of maximum energy the output of the battery starts to weaken.
137
139 {
141 RegisterNetSyncVariableInt("m_Efficiency0To10");
142
143 }
144
147 {
148 return m_Efficiency0To10 * 0.1;
149 }
150
153 {
155 }
156
157 override void OnEnergyConsumed()
158 {
159 super.OnEnergyConsumed();
160
161#ifdef SERVER
162 float energyCoef = GetCompEM().GetEnergy0To1();
163
166
167 SetSynchDirty();
168#endif
169 }
170
171 // BatteryCharging
172 override void OnEnergyAdded()
173 {
174 super.OnEnergyAdded();
175
176#ifdef SERVER
177 float energyCoef = GetCompEM().GetEnergy0To1();
178
181 else
183
184 SetSynchDirty();
185#endif
186 }
187}
void ActionDetach()
void AddAction(typename actionName)
provides access to slot configuration
const int INVALID
Invalid slot (-1)
void MetalWire()
Definition MetalWire.c:8
void BatteryCharger()
Definition EnMath.c:7
override bool CanDisplayAttachmentSlot(int slot_id)
float m_EfficiencyDecayStart
override void OnEnergyAdded()
override void SetActions()
override bool CanPutAsAttachment(EntityAI parent)
override void OnEnergyConsumed()
override void OnInventoryEnter(Man player)
float GetEfficiencyDecayStart()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
override void OnMovedInsideCargo(EntityAI container)
override bool CanDetachAttachment(EntityAI parent)
override bool DisplayNameRuinAttach()
float GetEfficiency0To1()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
override bool CanPutIntoHands(EntityAI player)
override bool CanPutInCargo(EntityAI parent)
int m_Efficiency0To10
ENERGY CONSUMPTION.
override bool ShowZonesHealth()
static proto float Round(float f)
Returns mathematical round of value.