DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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 {
10 BatteryCharger charger = BatteryCharger.Cast(parent);
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
25 override bool CanReceiveAttachment(EntityAI attachment, int slotId)
26 {
27 if (GetCompEM().IsPlugged())
28 return false;
29
30 return super.CanReceiveAttachment(attachment, slotId);
31 }
32
33 override bool CanPutIntoHands(EntityAI player)
34 {
35 if (!super.CanPutIntoHands(parent))
36 {
37 return false;
38 }
39
40 if (HasEnergyManager())
41 {
42 ItemBase poweredDevice = ItemBase.Cast(GetCompEM().GetPluggedDevice());
43 if (poweredDevice && poweredDevice.IsInherited(MetalWire))
44 {
45 return true;
46 }
47 else if (poweredDevice)
48 {
49 return false;
50 }
51 }
52
53 return true;
54 }
55
56 override bool CanPutInCargo(EntityAI parent)
57 {
58 if (!super.CanPutInCargo(parent))
59 {
60 return false;
61 }
62
63 ItemBase poweredDevice = ItemBase.Cast(GetCompEM().GetPluggedDevice());
64
65 return !(poweredDevice && poweredDevice.IsInherited(MetalWire));
66 }
67
68 override void OnInventoryEnter(Man player)
69 {
70 super.OnInventoryEnter(player);
71
72 if (GetHierarchyParent() == player || (GetHierarchyParent() && GetHierarchyParent().GetInventory().GetCargo()))
73 {
74 if (HasEnergyManager())
75 {
76 ItemBase poweredDevice = ItemBase.Cast(GetCompEM().GetPluggedDevice());
77
78 if (poweredDevice)
79 {
80 if (poweredDevice.IsInherited(MetalWire))
81 {
82 //Unplug the device the wire is powering, but keep wire plugged to battery
83 if (poweredDevice.GetCompEM().IsPlugged())
84 poweredDevice.GetCompEM().UnplugDevice(poweredDevice.GetCompEM().GetPluggedDevice());
85 }
86 else
87 {
88 this.GetCompEM().UnplugAllDevices();
89 }
90 }
91 }
92 }
93 }
94
95 override void OnMovedInsideCargo(EntityAI container)
96 {
97 super.OnMovedInsideCargo(container);
98
99 if (HasEnergyManager())
100 {
101 ItemBase poweredDevice = ItemBase.Cast(GetCompEM().GetPluggedDevice());
102
103 if (poweredDevice)
104 {
105 //Should not be possible, but better safe than sorry
106 if (poweredDevice.IsInherited(MetalWire))
107 {
108 poweredDevice.GetCompEM().UnplugAllDevices();
109 }
110 else
111 {
112 this.GetCompEM().UnplugAllDevices();
113 }
114 }
115 }
116 }
117
118 override bool CanDisplayAttachmentSlot(int slot_id)
119 {
120 if (GetCompEM().IsPlugged())
121 return false;
122
123 return super.CanDisplayAttachmentSlot(slot_id);
124 }
125
126 override bool DisplayNameRuinAttach()
127 {
128 return true;
129 }
130
131 override bool ShowZonesHealth()
132 {
133 return true;
134 }
135
136 override void SetActions()
137 {
138 super.SetActions();
139
143 }
144
145 //------------------------------------
147 //------------------------------------
148
149 private int m_Efficiency0To10; // Synchronized variable
150 static private float m_EfficiencyDecayStart = 0.1; // At this % of maximum energy the output of the battery starts to weaken.
151
153 {
155 RegisterNetSyncVariableInt("m_Efficiency0To10");
156
157 }
158
161 {
162 return m_Efficiency0To10 * 0.1;
163 }
164
167 {
169 }
170
171 //Update Battery energy level before it overrides quantity
172 override void SetCEBasedQuantity()
173 {
174 super.SetCEBasedQuantity();
175
176 if (GetCompEM())
177 GetCompEM().SetEnergy( GetCompEM().GetEnergyMax() * (GetQuantity() / GetQuantityMax()));
178 }
179
180 override void OnEnergyConsumed()
181 {
182 super.OnEnergyConsumed();
183
184 #ifdef SERVER
185 float energyCoef = GetCompEM().GetEnergy0To1();
186
187 if (energyCoef < m_EfficiencyDecayStart && m_EfficiencyDecayStart > 0)
188 {
189 m_Efficiency0To10 = Math.Round((energyCoef / m_EfficiencyDecayStart) * 10);
190 }
191
192 SetSynchDirty();
193 #endif
194 }
195
196 // BatteryCharging
197 override void OnEnergyAdded()
198 {
199 super.OnEnergyAdded();
200
201 #ifdef SERVER
202 float energyCoef = GetCompEM().GetEnergy0To1();
203
204 if (energyCoef < m_EfficiencyDecayStart && m_EfficiencyDecayStart > 0)
205 {
206 m_Efficiency0To10 = Math.Round((energyCoef / m_EfficiencyDecayStart) * 10);
207 }
208 else
209 {
211 }
212
213 SetSynchDirty();
214 #endif
215 }
216}
void ActionDetach()
void AddAction(typename actionName)
override float GetQuantity()
Definition ItemBase.c:7967
override int GetQuantityMax()
Definition ItemBase.c:7907
provides access to slot configuration
const int INVALID
Invalid slot (-1)
void MetalWire()
Definition MetalWire.c:8
void BatteryCharger()
Definition EnMath.c:7
float GetEfficiencyDecayStart()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
override bool ShowZonesHealth()
override bool CanPutIntoHands(EntityAI player)
override void OnEnergyAdded()
override bool CanPutInCargo(EntityAI parent)
override bool CanDisplayAttachmentSlot(int slot_id)
static private float m_EfficiencyDecayStart
override void SetCEBasedQuantity()
override void OnMovedInsideCargo(EntityAI container)
private int m_Efficiency0To10
ENERGY CONSUMPTION.
override bool CanPutAsAttachment(EntityAI parent)
override void OnInventoryEnter(Man player)
override bool DisplayNameRuinAttach()
override bool CanDetachAttachment(EntityAI parent)
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
float GetEfficiency0To1()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
override void SetActions()
override void OnEnergyConsumed()
static proto float Round(float f)
Returns mathematical round of value.