DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
UniversalTemperatureSource.c
Go to the documentation of this file.
2{
3 float m_UpdateInterval = 1.0;
4 float m_TemperatureMin = 0;
5 float m_TemperatureMax = 100;
6 float m_TemperatureCap = float.MAX;
7 float m_RangeFull = 1;
8 float m_RangeMax = 2;
9
10 bool m_Updateable = false;
11 bool m_ManualUpdate = false;
12 bool m_AffectStat = false;
13
16}
17
18class UniversalTemperatureSourceResult
19{
20 float m_Temperature = 0;
21 // ?? what else
22}
23
25class UniversalTemperatureSourceTimer : Timer
26{
27 override void OnTimer()
28 {
29 if (m_params)
30 {
31 GetGame().GameScript.CallFunctionParams(m_target, m_function, null, m_params);
32 }
33 else
34 {
35 GetGame().GameScript.CallFunction(m_target, m_function, null, 0);
36 }
37 }
38
39 override void Stop()
40 {
41 SetRunning(false);
42 m_time = 0;
43 }
44
45 void SetParams(Param params)
46 {
47 m_params = params;
48 }
49}
50
51typedef UniversalTemperatureSource UTemperatureSource;
52
54{
55 protected bool m_Active
56 protected ref UniversalTemperatureSourceTimer m_Timer;
58 protected ref UniversalTemperatureSourceResult m_ResultValues;
60
62 {
63 m_Active = false;
64 m_Settings = pSettings;
65 m_Lambda = pLambda;
66 m_ResultValues = new UniversalTemperatureSourceResult();
67 m_Timer = new UniversalTemperatureSourceTimer();
68
69 Init(pParent);
70 }
71
73
74 void Init(EntityAI pParent)
75 {
76 if (pParent)
77 {
78 pParent.SetUniversalTemperatureSource(this);
79
80 m_Settings.m_Parent = pParent;
81 m_Settings.m_Position = pParent.GetPosition();
82 }
83
84 if (!m_Settings.m_ManualUpdate)
85 {
87
88 m_Timer.Run(m_Settings.m_UpdateInterval, this, "Update", params, m_Settings.m_Updateable);
89 SetActive(false);
90 }
91 }
92
94 {
95 return m_Settings.m_Position;
96 }
97
99 {
100 return m_Settings.m_RangeFull;
101 }
102
104 {
105 return m_Settings.m_RangeMax;
106 }
107
109 {
110 if (m_Settings.m_TemperatureCap != float.MAX)
111 {
112 return Math.Min(m_Settings.m_TemperatureCap, GetTemperatureRaw());
113 }
114
115 return GetTemperatureRaw();
116 }
117
119 {
120 if (m_ResultValues)
121 {
122 return m_ResultValues.m_Temperature;
123 }
124
125 return 0;
126 }
127
129 {
130 return m_Settings.m_TemperatureMin;
131 }
132
134 {
135 return m_Settings.m_TemperatureMax;
136 }
137
139 {
140 return m_Settings.m_Parent;
141 }
142
143 bool IsActive()
144 {
145 if (m_Settings.m_ManualUpdate)
146 {
147 return m_Active;
148 }
149
150 return m_Timer && m_Timer.IsRunning();
151 }
152
153 void SetActive(bool pActive)
154 {
155 if (m_Settings.m_ManualUpdate)
156 {
157 m_Active = pActive;
158 return;
159 }
160
161 if (pActive && !m_Timer.IsRunning())
162 {
163 m_Timer.Continue();
164 }
165 else
166 {
167 m_Timer.Stop();
168 }
169 }
170
171 void SetDefferedActive(bool pActive, float pSeconds)
172 {
173 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLaterByName(this, "SetActive", pSeconds * 1000, false, new Param1<bool>(pActive));
174 }
175
177 {
179 }
180
182 {
183 if (!IsActive())
184 {
185 return;
186 }
187
188 if (lambda)
189 {
190 settings.m_Position = settings.m_Parent.GetUniversalTemperatureSourcePosition();
191 lambda.Execute(settings, m_ResultValues);
192 }
193
194 }
195}
196
197typedef UniversalTemperatureSourceDebug UTemperatureSourceDebug
198
200{
201 const string DELIMITER_DATA = "|";
202 const string DELIMITER_KEYPAIR = ":";
203
204 string m_Header;
205 string m_Data;
209
211 {
212 m_Header = "";
213 m_Data = "";
214 m_Pairs = new array<string>();
215 m_Names = new array<string>();
216 m_Values = new array<string>();
217 }
218
219 void AddHeader(string header)
220 {
221 m_Header = header;
222 }
223
224 void Add(string name, string value)
225 {
226 m_Data = string.Format("%1%2:%3%4", m_Data, name, value, DELIMITER_DATA);
227 }
228
229 void Commit()
230 {
231 m_Pairs = ParseData();
233 }
234
236 {
237 return m_Pairs.Count();
238 }
239
240 string GetHeader()
241 {
242 return m_Header;
243 }
244
245 string GetName(int pIndex)
246 {
247 if (m_Names.Count() - 1 < pIndex)
248 {
249 Debug.Log(string.Format("GetName index: %1 from data of length: %2", pIndex, m_Names.Count()), "UniversalTemperatureSourceDebug");
250 return "";
251 }
252
253 return m_Names.Get(pIndex);
254 }
255
256 string GetValue(int pIndex)
257 {
258 if (m_Values.Count() - 1 < pIndex)
259 {
260 Debug.Log(string.Format("GetValue index: %1 from data of length: %2", pIndex, m_Values.Count()), "UniversalTemperatureSourceDebug");
261 return "";
262 }
263
264 return m_Values.Get(pIndex);
265 }
266
268 {
269
270 array<string> parsed = new array<string>();
271 if (m_Data)
272 {
273 m_Data.Split(DELIMITER_DATA, parsed);
274 }
275
276 return parsed;
277 }
278
279 protected void ParseKeyPairs()
280 {
281 m_Names.Clear();
282 m_Values.Clear();
283
284 if (m_Pairs)
285 {
286 for (int i = 0; i < m_Pairs.Count(); i++)
287 {
288 array<string> keypair = new array<string>();
289
290 m_Pairs.Get(i).Split(DELIMITER_KEYPAIR, keypair);
291 m_Names.Insert(keypair[0]);
292 m_Values.Insert(keypair[1]);
293 }
294 }
295 }
296
297 void Debug()
298 {
299 for (int i = 0; i < m_Names.Count(); i++)
300 {
301 Debug.Log(string.Format("%1: %2", m_Names.Get(i), m_Values.Get(i)), "UniversalTemperatureSourceDebug");
302 }
303 }
304}
override Widget Init()
Definition DayZGame.c:122
ref Timer m_Timer
Definition DayZGame.c:687
bool IsActive()
string name
float GetValue()
Definition SyncedValue.c:55
void SetActive()
Definition TrapBase.c:463
string GetHeader()
protected void ParseKeyPairs()
class UniversalTemperatureSourceSettings m_Temperature
ref array< string > m_Pairs
values parsed from m_Pairs
protected array< string > ParseData()
ref array< string > m_Names
void AddHeader(string header)
void Add(string name, string value)
const string DELIMITER_KEYPAIR
ref array< string > m_Values
names parsed from m_Pairs
override ScriptCallQueue GetCallQueue(int call_category)
Definition DayZGame.c:1153
ScriptModule GameScript
Definition Game.c:12
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
Definition EnMath.c:7
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
proto void CallLaterByName(Class obj, string fnName, int delay=0, bool repeat=false, Param params=NULL)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
override void Stop()
protected bool m_Active protected ref UniversalTemperatureSourceTimer m_Timer
void UniversalTemperatureSource(EntityAI pParent, UniversalTemperatureSourceSettings pSettings, UniversalTemperatureSourceLambdaBase pLambda)
protected ref UniversalTemperatureSourceLambdaBase m_Lambda
void ChangeSettings(UniversalTemperatureSourceSettings pSettings)
void SetDefferedActive(bool pActive, float pSeconds)
protected ref UniversalTemperatureSourceResult m_ResultValues
protected UniversalTemperatureSourceSettings m_Settings
void Update(UniversalTemperatureSourceSettings settings, UniversalTemperatureSourceLambdaBase lambda)
original Timer deletes m_params which is unwanted
void Execute(UniversalTemperatureSourceSettings pSettings, UniversalTemperatureSourceResult resultValues)
float m_TemperatureMax
min temperature you can get from the TemperatureSource
bool m_Updateable
maximum range where the receiver can get some temperature
bool m_AffectStat
update is called manually (ex. own tick of parent entity)
float m_RangeFull
temperature cap that will limit the return value from GetTemperature method
vector m_Position
if the temperature generated is also set as Temperature Stat on Item itself
bool m_ManualUpdate
if the Update is running periodically
float m_TemperatureMin
how often the Update is ticking
float m_RangeMax
range where the full temperature is given to receiver
float m_TemperatureCap
max temperature you can get from the TemperatureSource
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
const float MAX
Definition EnConvert.c:99
static const vector Zero
Definition EnConvert.c:110
proto native CGame GetGame()
proto volatile int CallFunction(Class inst, string function, out void returnVal, void parm)
proto volatile int CallFunctionParams(Class inst, string function, out void returnVal, Class parms)
static proto float Min(float x, float y)
Returns smaller of two given values.
void Split(string sample, out array< string > output)
Splits string into array of strings separated by 'sample'.
Definition EnString.c:396
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
protected void SetRunning(bool running)
Definition tools.c:340
protected float m_time
Definition tools.c:224
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
proto native owned string GetName()