DayZ Scripts
v1.21.156300 · Jun 20, 2023
 
Loading...
Searching...
No Matches
PluginUniversalTemperatureSourceClient.c
Go to the documentation of this file.
1class PluginUniversalTemperatureSourceClient extends PluginBase
2{
3 const int MAX_SIMULTANEOUS_UTS = 10;
4
5 protected float m_UTSAverageTemperature;
6
8
10 protected TextListboxWidget m_StatListWidgets[MAX_SIMULTANEOUS_UTS];
11 protected TextWidget m_HeaderWidget[MAX_SIMULTANEOUS_UTS];
12
14
16 {
17 m_UTemperatureSourceDebugs = new array<ref UTemperatureSourceDebug>();
18 }
19
20 override void OnInit()
21 {
22 #ifndef NO_GUI
24 #endif
25 }
26
27 override void OnUpdate(float delta_time)
28 {
29 #ifndef NO_GUI
30 if (!m_Player)
31 {
32 return;
33 }
34
36 DrawDebugs();
37 #endif
38 }
39
41 {
42 for (int i = 0; i < MAX_SIMULTANEOUS_UTS; i++)
43 {
44 m_RootWidget[i] = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/day_z_debug_remoteinfo.layout");
45 m_StatListWidgets[i] = TextListboxWidget.Cast(m_RootWidget[i].FindAnyWidget("TextListboxWidget0"));
46 m_HeaderWidget[i] = TextWidget.Cast(m_RootWidget[i].FindAnyWidget("TextWidget0"));
47 }
48 }
49
51 {
52 foreach (UTemperatureSourceDebug utsd : m_UTemperatureSourceDebugs)
53 {
54 float fullRange = utsd.GetValue(1).ToFloat();
55 float maxRange = utsd.GetValue(2).ToFloat();
56 float temp = utsd.GetValue(3).ToFloat();
57 vector sphPos = utsd.GetValue(0).ToVector();
58
59 int fullRangeColor = COLOR_RED_A;
60 int maxRangeColor = COLOR_YELLOW_A;
61 if (temp < 0)
62 {
63 fullRangeColor = COLOR_GREEN_A;
64 maxRangeColor = COLOR_BLUE_A;
65 }
66
67 Debug.DrawCylinder(sphPos, fullRange, fullRange, fullRangeColor, ShapeFlags.ONCE|ShapeFlags.TRANSP);
68 Debug.DrawCylinder(sphPos, maxRange, maxRange, maxRangeColor, ShapeFlags.ONCE|ShapeFlags.TRANSP);
69 Debug.DrawArrow(m_Player.GetPosition(), sphPos, 1.0, 0xffffffff, ShapeFlags.ONCE|ShapeFlags.TRANSP);
70 }
71
73
74 if (m_UTemperatureSourceDebugs.Count() > 0)
75 {
76 DbgUI.Begin("Universal Temp Sources", 10, 300);
77 DbgUI.Text(string.Format("Lookup radius: %1m (server-side)", PluginUniversalTemperatureSourceServer.LOOKUP_RADIUS));
78 DbgUI.Text(string.Format("Count: %1", m_UTemperatureSourceDebugs.Count()));
79 DbgUI.Text(string.Format("Avg. temp: %1 °C", m_UTSAverageTemperature));
80 DbgUI.End();
81 }
82 }
83
85 {
86 if (m_UTemperatureSourceDebugs.Count() == 0)
87 {
88 m_UTSAverageTemperature = 0;
89
90 return;
91 }
92
93 array<float> utsTemperatures = new array<float>();
94
95 // get temperature from the source (based on distance), save it for min/max filtering
97 {
99 if (vector.DistanceSq(m_Player.GetPosition(), utsd.GetValue(0).ToVector()) > Math.SqrFloat(utsd.GetValue(2).ToFloat()))
100 {
101 continue;
102 }
103
104 utsTemperatures.Insert(CalcTemperatureFromTemperatureSource(utsd));
105 }
106
107 float min = MiscGameplayFunctions.GetMinValue(utsTemperatures);
108 float max = MiscGameplayFunctions.GetMaxValue(utsTemperatures);
109
110 if (max > 0 && min < 0)
111 {
112 m_UTSAverageTemperature = (max + min) * 0.5;
113 }
114 else
115 {
116 m_UTSAverageTemperature = max;
117 }
118
119 }
120
121 protected float CalcTemperatureFromTemperatureSource(notnull UTemperatureSourceDebug utsd)
122 {
123 float distance = vector.Distance(m_Player.GetPosition(), utsd.GetValue(0).ToVector());
124 distance = Math.Max(distance, 0.1); //min distance cannot be 0 (division by zero)
125 float temperature = 0;
126
128 if (distance > utsd.GetValue(1).ToFloat())
129 {
130 float distFactor = 1 - (distance / utsd.GetValue(2).ToFloat());
131 distFactor = Math.Max(distFactor, 0.0);
132 temperature = utsd.GetValue(3).ToFloat() * distFactor;
133 }
134 else
135 {
136 temperature = utsd.GetValue(3).ToFloat();
137 }
138
139 //Print(temperature);
140
141 return temperature;
142 }
143
144 void EnableWidgets(bool enable)
145 {
146 for (int i = 0; i < MAX_SIMULTANEOUS_UTS; i++)
147 {
148 m_RootWidget[i].Show(enable);
149 }
150 }
151
153 {
154 int i = 0;
155 int utsDebugCount = m_UTemperatureSourceDebugs.Count();
156 for (; i < utsDebugCount && i < MAX_SIMULTANEOUS_UTS; ++i)
157 {
158 UTemperatureSourceDebug utsd = m_UTemperatureSourceDebugs[i];
159 vector pos = utsd.GetValue(0).ToVector();
160 vector screen_pos_stats = GetGame().GetScreenPos(pos + "0 0 0");
161 vector screen_pos_damage = GetGame().GetScreenPos(pos + "0 2 0");
162 m_RootWidget[i].SetPos(screen_pos_stats[0], screen_pos_stats[1]);
163
164 if (screen_pos_stats[2] > 0 && screen_pos_stats[0] > 0 && screen_pos_stats[1] > 0)
165 {
166 m_RootWidget[i].Show(true);
167 UpdateStatWidget(i, utsd);
168 }
169 else
170 {
171 m_RootWidget[i].Show(false);
172 }
173 }
174
175 for (; i < MAX_SIMULTANEOUS_UTS; ++i)
176 {
177 if (m_RootWidget[i])
178 {
179 m_RootWidget[i].Show(false);
180 }
181 }
182 }
183
184 void UpdateStatWidget(int rowIndex, UTemperatureSourceDebug utsd)
185 {
186 m_StatListWidgets[rowIndex].ClearItems();
187
188 m_HeaderWidget[rowIndex].SetText(utsd.GetHeader());
189
190 int numPairs = utsd.PairsCount();
191 for (int i = 0; i < numPairs; ++i)
192 {
193 m_StatListWidgets[rowIndex].AddItem(utsd.GetName(i), null, 0, i);
194 m_StatListWidgets[rowIndex].SetItem(i, utsd.GetValue(i), null, 1);
195 }
196
197 // manually add value for distance (client only)
198 m_StatListWidgets[rowIndex].AddItem("distance", null, 0, numPairs);
199 m_StatListWidgets[rowIndex].SetItem(numPairs, vector.Distance(m_Player.GetPosition(), utsd.GetValue(0).ToVector()).ToString(), null, 1);
200 }
201
203 {
204 //Debug.Log("RequestUniversalTemperatureSources called", "PluginUniversalTemperatureSourceClient");
205
206 if (!enable)
207 {
208 m_UTemperatureSourceDebugs.Clear();
209 m_Player = null;
210 EnableWidgets(false);
211 return;
212 }
213
214 ScriptRPC rpc = new ScriptRPC();
215 rpc.Write(enable);
216 rpc.Send(player, ERPCs.DEV_REQUEST_UTS_DEBUG, true, player.GetIdentity());
217
218 m_Player = player;
219 }
220
222 {
223 foreach (UTemperatureSourceDebug utsd : m_UTemperatureSourceDebugs)
224 {
225 PrintString("-------------------------------------");
226 utsd.Debug();
227 PrintString("-------------------------------------");
228 }
229 }
230
232 {
233 //Debug.Log("OnRPC called", "PluginUniversalTemperatureSourceClient");
234 //PrintedDebug();
235 ctx.Read(m_UTemperatureSourceDebugs);
236 }
237}
ERPCs
Definition ERPCs.c:2
DayZPlayer m_Player
Definition Hand_Events.c:42
ref TextListboxWidget m_StatListWidgets[MAX_SIMULTANIOUS_PLAYERS]
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
proto native vector GetScreenPos(vector world_pos)
Transforms position in world to position in screen in pixels as x, y component of vector,...
proto native WorkspaceWidget GetWorkspace()
Definition DbgUI.c:60
Definition Debug.c:14
static Shape DrawArrow(vector from, vector to, float size=0.5, int color=0xFFFFFFFF, int flags=0)
Definition Debug.c:383
static Shape DrawCylinder(vector pos, float radius, float height=1, int color=0x1fff7f7f, ShapeFlags flags=ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
Definition Debug.c:322
Definition EnMath.c:7
protected void ProcessUniversalTemperatureSources()
void OnRPC(ParamsReadContext ctx)
override void OnUpdate(float delta_time)
protected float CalcTemperatureFromTemperatureSource(notnull UTemperatureSourceDebug utsd)
void RequestUniversalTemperatureSources(PlayerBase player, int enable)
protected ref array< ref UTemperatureSourceDebug > m_UTemperatureSourceDebugs
void UpdateStatWidget(int rowIndex, UTemperatureSourceDebug utsd)
proto native void Send(Object target, int rpc_type, bool guaranteed, PlayerIdentity recipient=NULL)
Initiate remote procedure call. When called on client, RPC is evaluated on server; When called on ser...
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto string ToString()
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto native CGame GetGame()
const int COLOR_BLUE_A
Definition constants.c:71
const int COLOR_RED_A
Definition constants.c:69
const int COLOR_YELLOW_A
Definition constants.c:72
const int COLOR_GREEN_A
Definition constants.c:70
ShapeFlags
Definition EnDebug.c:126
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
static proto native void End()
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:345
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto float SqrFloat(float f)
Returns squared value.
proto native Widget FindAnyWidget(string pathname)
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.