Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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 {
81 m_Parent.OnGeneratorStart();
82 }
83
84 if (!g_Game.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 {
99 m_Parent.OnGeneratorStop();
100 }
101
102 if (!g_Game.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 (g_Game.IsServer() && m_Parent)
116 {
117 Land_WarheadStorage_Main bunker = m_Parent.GetClosestBunker();
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
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
static proto native int GetSlotIdFromString(string slot_name)
override bool DisableVicinityIcon()
static ref set< PowerGeneratorStatic > m_PowerGenerators
static void RegisterPersistentObject(PowerGeneratorStatic obj)
override void SetLowEnergyState(bool state)
override void OnStoreSave(ParamsWriteContext ctx)
override bool CanPutInCargo(EntityAI parent)
override bool CanReleaseAttachment(EntityAI attachment)
override vector GetSmokeParticlePosition()
void StoreLeverStates(int leverStateBits)
static PowerGeneratorStatic GetClosestGenerator(vector position, float tolerance)
override bool IsActionTargetVisible()
override bool CanPutIntoHands(EntityAI parent)
override vector GetSmokeParticleOrientation()
override bool OnStoreLoad(ParamsReadContext ctx, int version)
static void UnregisterPersistentObject(PowerGeneratorStatic obj)
void SetLowEnergyStateServer(bool state)
void SetParent(Land_WarheadStorage_PowerStation parent)
Land_WarheadStorage_PowerStation m_Parent
proto bool Write(void value_out)
proto bool Read(void value_in)
const float MAX
Definition enconvert.c:112
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
DayZGame g_Game
Definition dayzgame.c:3942
Serializer ParamsReadContext
Definition gameplay.c:15
Serializer ParamsWriteContext
Definition gameplay.c:16