Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
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 }
ItemBase
Definition: inventoryitem.c:730
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
ActionDetach
void ActionDetach()
Definition: actiondetach.c:10
ActionAttachOnSelection
Definition: actionattachonselection.c:1
VehicleBattery
Definition: vehiclebattery.c:1
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Math
Definition: enmath.c:6
ActionPlugTargetIntoThis
Definition: actionplugtargetintothis.c:1
EntityAI
Definition: building.c:5