Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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 parent)
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 && poweredDevice.IsOn())
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 override void OnEnergyConsumed()
172 {
173 super.OnEnergyConsumed();
174
175 #ifdef SERVER
176 float energyCoef = GetCompEM().GetEnergy0To1();
177
178 if (energyCoef < m_EfficiencyDecayStart && m_EfficiencyDecayStart > 0)
179 {
180 m_Efficiency0To10 = Math.Round((energyCoef / m_EfficiencyDecayStart) * 10);
181 }
182
183 SetSynchDirty();
184 #endif
185 }
186
187 // BatteryCharging
188 override void OnEnergyAdded()
189 {
190 super.OnEnergyAdded();
191
192 #ifdef SERVER
193 float energyCoef = GetCompEM().GetEnergy0To1();
194
195 if (energyCoef < m_EfficiencyDecayStart && m_EfficiencyDecayStart > 0)
196 {
197 m_Efficiency0To10 = Math.Round((energyCoef / m_EfficiencyDecayStart) * 10);
198 }
199 else
200 {
202 }
203
204 SetSynchDirty();
205 #endif
206 }
207}
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
float m_EfficiencyDecayStart
float GetEfficiencyDecayStart()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
override bool ShowZonesHealth()
override void OnEnergyAdded()
override bool CanPutInCargo(EntityAI parent)
int m_Efficiency0To10
ENERGY CONSUMPTION.
override bool CanDisplayAttachmentSlot(int slot_id)
override bool CanPutIntoHands(EntityAI parent)
override void OnMovedInsideCargo(EntityAI container)
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.