Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
powergeneratorstatic.c
Go to the documentation of this file.
1class PowerGeneratorStatic : PowerGeneratorBase
2{
3 const int SWITCH_COUNT = 6;
4 const int LOW_ENERGY_PERCENT = 5;
5
6 protected static ref set<PowerGeneratorStatic> m_PowerGenerators = new set<PowerGeneratorStatic>();
8
9 protected int m_ParentID1;
10 protected int m_ParentID2;
11 protected int m_ParentID3;
12 protected int m_ParentID4;
13
14 protected int m_LeverStatesBits;
15
20
25
27 {
28 m_PowerGenerators.Insert(obj);
29 }
30
32 {
34 return;
35 int index = m_PowerGenerators.Find(obj);
36 if (index != -1)
37 {
38 m_PowerGenerators.Remove(index);
39 }
40 }
41
42 static PowerGeneratorStatic GetClosestGenerator(vector position, float tolerance)
43 {
44 float toleranceSq = tolerance * tolerance;
45 float smallestDist = float.MAX;
47
49 {
50 float distSq = vector.DistanceSq(position,obj.GetPosition());
51 if (distSq < toleranceSq)
52 {
53 return obj;
54 }
55 }
56 return null;
57 }
58
60 {
61 m_Parent = parent;
62 }
63
64 // States saved thorugh the generator entity since it doesnt work when done building side
65 void StoreLeverStates(int leverStateBits)
66 {
67 m_LeverStatesBits = leverStateBits;
68 }
69
71 {
72 return m_LeverStatesBits;
73 }
74
75 // Generator is working
76 override void OnWorkStart()
77 {
78 super.OnWorkStart();
79 if (m_Parent)
80 {
82 }
83
84 if (!GetGame().IsServer())
85 return;
86
87 for (int i = 1; i <= SWITCH_COUNT; i++)
88 {
89 SetAnimationPhase("Switch" + i.ToString(), 1);
90 }
91 }
92
93 // Turn off when this runs out of fuel
94 override void OnWorkStop()
95 {
96 super.OnWorkStop();
97 if (m_Parent)
98 {
100 }
101
102 if (!GetGame().IsServer())
103 return;
104
105 for (int i = 1; i <= SWITCH_COUNT; i++)
106 {
107 SetAnimationPhase("Switch" + i.ToString(), 0);
108 }
109 }
110
111 override void SetLowEnergyState(bool state)
112 {
113 super.SetLowEnergyState(state);
114
115 if (GetGame().IsServer() && m_Parent)
116 {
118 if (bunker)
119 bunker.SetLowEnergyStateServer(state);
120 }
121 }
122
124 {
125 return "1.1 1.1 -1.1";
126 }
127
129 {
130 return "90 0 23";
131 }
132
133 // Checks sparkplug
134 override bool HasSparkplug()
135 {
136 int slot = InventorySlots.GetSlotIdFromString("GlowPlug");
137 EntityAI ent = GetInventory().FindAttachment(slot);
138
139 return ent && !ent.IsRuined();
140 }
141
142 // Taking item into inventory
143 override bool CanPutInCargo( EntityAI parent )
144 {
145 return false;
146 }
147
148 // Taking item into inventory
149 override bool CanPutIntoHands(EntityAI parent)
150 {
151 return false;
152 }
153
155 {
156 super.OnStoreSave(ctx);
157
158 if (m_Parent)
160
161 ctx.Write(m_ParentID1);
162 ctx.Write(m_ParentID2);
163 ctx.Write(m_ParentID3);
164 ctx.Write(m_ParentID4);
165
166 ctx.Write(m_LeverStatesBits);
167 }
168
169 override bool OnStoreLoad( ParamsReadContext ctx, int version )
170 {
171 if ( !super.OnStoreLoad( ctx, version ) )
172 return false;
173
174 if ( !ctx.Read(m_ParentID1))
175 {
176 return false;
177 }
178 if ( !ctx.Read(m_ParentID2))
179 {
180 return false;
181 }
182 if ( !ctx.Read(m_ParentID3))
183 {
184 return false;
185 }
186 if ( !ctx.Read( m_ParentID4))
187 {
188 return false;
189 }
190
191 if (version >= 141 && !ctx.Read(m_LeverStatesBits) )
192 return false;
193
194 return true;
195 }
196
197 override void EEOnAfterLoad()
198 {
199 // Does this part actually do anything?
201 if (powerStation)
202 {
203 PowerGeneratorStatic otherGenerator = powerStation.GetPowerGenerator();
204 if (otherGenerator)
205 {
206 otherGenerator.SetFuel(GetFuel());
207 Delete();
208 }
209 }
210 }
211
212 override bool CanReleaseAttachment(EntityAI attachment)
213 {
214 if (!super.CanReleaseAttachment(attachment))
215 return false;
216 return !GetCompEM().IsWorking();
217 }
218
219 override bool IsTakeable()
220 {
221 return false;
222 }
223
224 override bool IsActionTargetVisible()
225 {
226 return true;
227 }
228
229 override bool DisableVicinityIcon()
230 {
231 return true;
232 }
233
234 // DEPRECATED
235
236 void SetLowEnergyStateServer(bool state);
237}
provides access to slot configuration
Land_WarheadStorage_PowerStation m_Parent
void SetLowEnergyStateServer(bool state)
override bool CanPutIntoHands(EntityAI parent)
override bool DisableVicinityIcon()
static void RegisterPersistentObject(PowerGeneratorStatic obj)
void SetParent(Land_WarheadStorage_PowerStation parent)
static void UnregisterPersistentObject(PowerGeneratorStatic obj)
override vector GetSmokeParticleOrientation()
override void OnStoreSave(ParamsWriteContext ctx)
static ref set< PowerGeneratorStatic > m_PowerGenerators
override bool CanPutInCargo(EntityAI parent)
static PowerGeneratorStatic GetClosestGenerator(vector position, float tolerance)
void StoreLeverStates(int leverStateBits)
override bool IsActionTargetVisible()
override bool OnStoreLoad(ParamsReadContext ctx, int version)
override bool CanReleaseAttachment(EntityAI attachment)
override vector GetSmokeParticlePosition()
override void SetLowEnergyState(bool state)
Serialization general interface. Serializer API works with:
Definition serializer.c:56
proto native CGame GetGame()