Dayz Explorer 1.28.160049
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
9 protected ref Widget m_RootWidget[MAX_SIMULTANEOUS_UTS];
10 protected TextListboxWidget m_StatListWidgets[MAX_SIMULTANEOUS_UTS];
11 protected TextWidget m_HeaderWidget[MAX_SIMULTANEOUS_UTS];
12
13 protected PlayerBase m_Player;
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 else if (temp == 0)
67 {
68 fullRangeColor = 0x1fefefef;
69 maxRangeColor = 0x1fefefef;
70 }
71
72 Debug.DrawCylinder(sphPos, fullRange, fullRange, fullRangeColor, ShapeFlags.ONCE|ShapeFlags.TRANSP);
73 Debug.DrawCylinder(sphPos, maxRange, maxRange, maxRangeColor, ShapeFlags.ONCE|ShapeFlags.TRANSP);
74 Debug.DrawArrow(m_Player.GetPosition(), sphPos, 1.0, 0xffffffff, ShapeFlags.ONCE|ShapeFlags.TRANSP);
75 }
76
78
79 if (m_UTemperatureSourceDebugs.Count() > 0)
80 {
81 DbgUI.Begin("Universal Temp Sources", 10, 300);
82 DbgUI.Text(string.Format("Lookup radius: %1m (server-side)", PluginUniversalTemperatureSourceServer.LOOKUP_RADIUS));
83 DbgUI.Text(string.Format("Count: %1", m_UTemperatureSourceDebugs.Count()));
84 DbgUI.Text(string.Format("Avg. temp: %1 °C", m_UTSAverageTemperature));
85 DbgUI.End();
86 }
87 }
88
90 {
91 if (m_UTemperatureSourceDebugs.Count() == 0)
92 {
94
95 return;
96 }
97
98 array<float> utsTemperatures = new array<float>();
99
100 // get temperature from the source (based on distance), save it for min/max filtering
101 foreach (UniversalTemperatureSourceDebug utsd : m_UTemperatureSourceDebugs)
102 {
104 if (vector.DistanceSq(m_Player.GetPosition(), utsd.GetValue(0).ToVector()) > Math.SqrFloat(utsd.GetValue(2).ToFloat()))
105 continue;
106
107 utsTemperatures.Insert(CalcTemperatureFromTemperatureSource(utsd));
108 }
109
110 float min = MiscGameplayFunctions.GetMinValue(utsTemperatures);
111 float max = MiscGameplayFunctions.GetMaxValue(utsTemperatures);
112
113 if (max > 0 && min < 0)
114 {
115 m_UTSAverageTemperature = (max + min) * 0.5;
116 }
117 else
118 {
120 }
121
122 }
123
124 protected float CalcTemperatureFromTemperatureSource(notnull UTemperatureSourceDebug utsd)
125 {
126 float distance = vector.Distance(m_Player.GetPosition(), utsd.GetValue(0).ToVector());
127 distance = Math.Max(distance, 0.1); //min distance cannot be 0 (division by zero)
128 float temperature = 0;
129
131 if (distance > utsd.GetValue(1).ToFloat())
132 {
133 float distFactor = Math.InverseLerp(utsd.GetValue(2).ToFloat(), utsd.GetValue(1).ToFloat(), distance);
134 distFactor = Math.Max(distFactor, 0.0);
135 temperature = utsd.GetValue(3).ToFloat() * distFactor;
136 }
137 else
138 {
139 temperature = utsd.GetValue(3).ToFloat();
140 }
141
142 //Print(temperature);
143
144 return temperature;
145 }
146
147 void EnableWidgets(bool enable)
148 {
149 for (int i = 0; i < MAX_SIMULTANEOUS_UTS; i++)
150 {
151 m_RootWidget[i].Show(enable);
152 }
153 }
154
156 {
157 int i = 0;
158 int utsDebugCount = m_UTemperatureSourceDebugs.Count();
159 for (; i < utsDebugCount && i < MAX_SIMULTANEOUS_UTS; ++i)
160 {
161 UTemperatureSourceDebug utsd = m_UTemperatureSourceDebugs[i];
162 vector pos = utsd.GetValue(0).ToVector();
163 vector screen_pos_stats = GetGame().GetScreenPos(pos + "0 0 0");
164 vector screen_pos_damage = GetGame().GetScreenPos(pos + "0 2 0");
165 m_RootWidget[i].SetPos(screen_pos_stats[0], screen_pos_stats[1]);
166
167 if (screen_pos_stats[2] > 0 && screen_pos_stats[0] > 0 && screen_pos_stats[1] > 0)
168 {
169 m_RootWidget[i].Show(true);
170 UpdateStatWidget(i, utsd);
171 }
172 else
173 {
174 m_RootWidget[i].Show(false);
175 }
176 }
177
178 for (; i < MAX_SIMULTANEOUS_UTS; ++i)
179 {
180 if (m_RootWidget[i])
181 {
182 m_RootWidget[i].Show(false);
183 }
184 }
185 }
186
187 void UpdateStatWidget(int rowIndex, UTemperatureSourceDebug utsd)
188 {
189 m_StatListWidgets[rowIndex].ClearItems();
190
191 m_HeaderWidget[rowIndex].SetText(utsd.GetHeader());
192
193 int numPairs = utsd.PairsCount();
194 for (int i = 0; i < numPairs; ++i)
195 {
196 m_StatListWidgets[rowIndex].AddItem(utsd.GetName(i), null, 0, i);
197 m_StatListWidgets[rowIndex].SetItem(i, utsd.GetValue(i), null, 1);
198 }
199
200 // manually add value for distance (client only)
201 m_StatListWidgets[rowIndex].AddItem("distance", null, 0, numPairs);
202 m_StatListWidgets[rowIndex].SetItem(numPairs, vector.Distance(m_Player.GetPosition(), utsd.GetValue(0).ToVector()).ToString(), null, 1);
203 }
204
206 {
207 //Debug.Log("RequestUniversalTemperatureSources called", "PluginUniversalTemperatureSourceClient");
208
209 if (!enable)
210 {
211 m_UTemperatureSourceDebugs.Clear();
212 m_Player = null;
213 EnableWidgets(false);
214 return;
215 }
216
217 ScriptRPC rpc = new ScriptRPC();
218 rpc.Write(enable);
219 rpc.Send(player, ERPCs.DEV_REQUEST_UTS_DEBUG, true, player.GetIdentity());
220
221 m_Player = player;
222 }
223
225 {
226 foreach (UTemperatureSourceDebug utsd : m_UTemperatureSourceDebugs)
227 {
228 PrintString("-------------------------------------");
229 utsd.Debug();
230 PrintString("-------------------------------------");
231 }
232 }
233
235 {
236 //Debug.Log("OnRPC called", "PluginUniversalTemperatureSourceClient");
237 //PrintedDebug();
238 ctx.Read(m_UTemperatureSourceDebugs);
239 }
240}
Definition dbgui.c:60
Definition debug.c:2
Definition enmath.c:7
Plugin interface for controlling of agent pool system.
Definition pluginbase.c:2
void UpdateStatWidget(int rowIndex, UTemperatureSourceDebug utsd)
void RequestUniversalTemperatureSources(PlayerBase player, int enable)
ref array< ref UTemperatureSourceDebug > m_UTemperatureSourceDebugs
void OnRPC(ParamsReadContext ctx)
float CalcTemperatureFromTemperatureSource(notnull UTemperatureSourceDebug utsd)
override void OnUpdate(float delta_time)
Serialization general interface. Serializer API works with:
Definition serializer.c:56
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
float m_UTSAverageTemperature
Definition environment.c:88
ERPCs
Definition erpcs.c:2
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
class array< Class T > PrintString
DayZPlayer m_Player
Definition hand_events.c:42
ref TextListboxWidget m_StatListWidgets[MAX_SIMULTANIOUS_PLAYERS]
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]