Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
vehiclebattery.c
Go to the documentation of this file.
1
class
VehicleBattery
:
ItemBase
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
140
AddAction
(
ActionAttachOnSelection
);
141
AddAction
(
ActionDetach
);
142
AddAction
(
ActionPlugTargetIntoThis
);
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
152
void
VehicleBattery
()
153
{
154
m_Efficiency0To10
= 10;
155
RegisterNetSyncVariableInt(
"m_Efficiency0To10"
);
156
157
}
158
160
float
GetEfficiency0To1
()
161
{
162
return
m_Efficiency0To10
* 0.1;
163
}
164
166
float
GetEfficiencyDecayStart
()
167
{
168
return
m_EfficiencyDecayStart
;
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
{
201
m_Efficiency0To10
= 10;
202
}
203
204
SetSynchDirty();
205
#endif
206
}
207
}
ActionDetach
void ActionDetach()
Definition
actiondetach.c:10
AddAction
void AddAction(typename actionName)
Definition
advancedcommunication.c:220
ActionAttachOnSelection
Definition
actionattachonselection.c:2
ActionPlugTargetIntoThis
Definition
actionplugtargetintothis.c:2
EntityAI
Definition
inventoryitem.c:2
InventorySlots
provides access to slot configuration
Definition
inventoryslots.c:6
InventorySlots::INVALID
const int INVALID
Invalid slot (-1).
Definition
inventoryslots.c:17
ItemBase
Definition
inventoryitem.c:742
ItemBase::MetalWire
void MetalWire()
Definition
metalwire.c:8
ItemBase::BatteryCharger
void BatteryCharger()
Definition
batterycharger.c:35
Math
Definition
enmath.c:7
VehicleBattery::m_EfficiencyDecayStart
float m_EfficiencyDecayStart
Definition
vehiclebattery.c:150
VehicleBattery::GetEfficiencyDecayStart
float GetEfficiencyDecayStart()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
Definition
vehiclebattery.c:166
VehicleBattery::ShowZonesHealth
override bool ShowZonesHealth()
Definition
vehiclebattery.c:131
VehicleBattery::OnEnergyAdded
override void OnEnergyAdded()
Definition
vehiclebattery.c:188
VehicleBattery::CanPutInCargo
override bool CanPutInCargo(EntityAI parent)
Definition
vehiclebattery.c:56
VehicleBattery::m_Efficiency0To10
int m_Efficiency0To10
ENERGY CONSUMPTION.
Definition
vehiclebattery.c:149
VehicleBattery::CanDisplayAttachmentSlot
override bool CanDisplayAttachmentSlot(int slot_id)
Definition
vehiclebattery.c:118
VehicleBattery::VehicleBattery
void VehicleBattery()
Definition
vehiclebattery.c:152
VehicleBattery::CanPutIntoHands
override bool CanPutIntoHands(EntityAI parent)
Definition
vehiclebattery.c:33
VehicleBattery::OnMovedInsideCargo
override void OnMovedInsideCargo(EntityAI container)
Definition
vehiclebattery.c:95
VehicleBattery::CanPutAsAttachment
override bool CanPutAsAttachment(EntityAI parent)
Definition
vehiclebattery.c:3
VehicleBattery::OnInventoryEnter
override void OnInventoryEnter(Man player)
Definition
vehiclebattery.c:68
VehicleBattery::DisplayNameRuinAttach
override bool DisplayNameRuinAttach()
Definition
vehiclebattery.c:126
VehicleBattery::CanDetachAttachment
override bool CanDetachAttachment(EntityAI parent)
Definition
vehiclebattery.c:20
VehicleBattery::CanReceiveAttachment
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Definition
vehiclebattery.c:25
VehicleBattery::GetEfficiency0To1
float GetEfficiency0To1()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
Definition
vehiclebattery.c:160
VehicleBattery::SetActions
override void SetActions()
Definition
vehiclebattery.c:136
VehicleBattery::OnEnergyConsumed
override void OnEnergyConsumed()
Definition
vehiclebattery.c:171
Math::Round
static proto float Round(float f)
Returns mathematical round of value.
Games
Dayz
scripts
4_world
entities
itembase
vehiclebattery.c
Generated by
1.17.0