DayZ 1.24
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
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 return;
32
34 DrawDebugs();
35#endif
36 }
37
39 {
40 for (int i = 0; i < MAX_SIMULTANEOUS_UTS; i++)
41 {
42 m_RootWidget[i] = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/day_z_debug_remoteinfo.layout");
43 m_StatListWidgets[i] = TextListboxWidget.Cast(m_RootWidget[i].FindAnyWidget("TextListboxWidget0"));
44 m_HeaderWidget[i] = TextWidget.Cast(m_RootWidget[i].FindAnyWidget("TextWidget0"));
45 }
46 }
47
49 {
51 {
52 float fullRange = utsd.GetValue(1).ToFloat();
53 float maxRange = utsd.GetValue(2).ToFloat();
54 float temp = utsd.GetValue(3).ToFloat();
55 vector sphPos = utsd.GetValue(0).ToVector();
56
59 if (temp < 0)
60 {
63 }
64
67 Debug.DrawArrow(m_Player.GetPosition(), sphPos, 1.0, 0xffffffff, ShapeFlags.ONCE | ShapeFlags.TRANSP);
68 }
69
71
72 if (m_UTemperatureSourceDebugs.Count() > 0)
73 {
74 DbgUI.Begin("Universal Temp Sources", 10, 300);
75 DbgUI.Text(string.Format("Lookup radius: %1m (server-side)", PluginUniversalTemperatureSourceServer.LOOKUP_RADIUS));
76 DbgUI.Text(string.Format("Count: %1", m_UTemperatureSourceDebugs.Count()));
77 DbgUI.Text(string.Format("Avg. temp: %1 °C", m_UTSAverageTemperature));
78 DbgUI.End();
79 }
80 }
81
83 {
84 if (m_UTemperatureSourceDebugs.Count() == 0)
85 {
86 m_UTSAverageTemperature = 0;
87
88 return;
89 }
90
92
93 // get temperature from the source (based on distance), save it for min/max filtering
95 {
97 if (vector.DistanceSq(m_Player.GetPosition(), utsd.GetValue(0).ToVector()) > Math.SqrFloat(utsd.GetValue(2).ToFloat()))
98 continue;
99
101 }
102
103 float min = MiscGameplayFunctions.GetMinValue(utsTemperatures);
104 float max = MiscGameplayFunctions.GetMaxValue(utsTemperatures);
105
106 if (max > 0 && min < 0)
107 m_UTSAverageTemperature = (max + min) * 0.5;
108 else
109 m_UTSAverageTemperature = max;
110
111 }
112
114 {
115 float distance = vector.Distance(m_Player.GetPosition(), utsd.GetValue(0).ToVector());
116 distance = Math.Max(distance, 0.1); //min distance cannot be 0 (division by zero)
117 float temperature = 0;
118
120 if (distance > utsd.GetValue(1).ToFloat())
121 {
122 float distFactor = 1 - (distance / utsd.GetValue(2).ToFloat());
123 distFactor = Math.Max(distFactor, 0.0);
124 temperature = utsd.GetValue(3).ToFloat() * distFactor;
125 }
126 else
127 temperature = utsd.GetValue(3).ToFloat();
128
129 //Print(temperature);
130
131 return temperature;
132 }
133
135 {
136 for (int i = 0; i < MAX_SIMULTANEOUS_UTS; i++)
138 }
139
141 {
142 int i = 0;
143 int utsDebugCount = m_UTemperatureSourceDebugs.Count();
144 for (; i < utsDebugCount && i < MAX_SIMULTANEOUS_UTS; ++i)
145 {
146 UTemperatureSourceDebug utsd = m_UTemperatureSourceDebugs[i];
147 vector pos = utsd.GetValue(0).ToVector();
148 vector screen_pos_stats = GetGame().GetScreenPos(pos + "0 0 0");
149 vector screen_pos_damage = GetGame().GetScreenPos(pos + "0 2 0");
151
152 if (screen_pos_stats[2] > 0 && screen_pos_stats[0] > 0 && screen_pos_stats[1] > 0)
153 {
154 m_RootWidget[i].Show(true);
156 }
157 else
158 m_RootWidget[i].Show(false);
159 }
160
161 for (; i < MAX_SIMULTANEOUS_UTS; ++i)
162 {
163 if (m_RootWidget[i])
164 m_RootWidget[i].Show(false);
165 }
166 }
167
169 {
170 m_StatListWidgets[rowIndex].ClearItems();
171
172 m_HeaderWidget[rowIndex].SetText(utsd.GetHeader());
173
174 int numPairs = utsd.PairsCount();
175 for (int i = 0; i < numPairs; ++i)
176 {
177 m_StatListWidgets[rowIndex].AddItem(utsd.GetName(i), null, 0, i);
178 m_StatListWidgets[rowIndex].SetItem(i, utsd.GetValue(i), null, 1);
179 }
180
181 // manually add value for distance (client only)
182 m_StatListWidgets[rowIndex].AddItem("distance", null, 0, numPairs);
183 m_StatListWidgets[rowIndex].SetItem(numPairs, vector.Distance(m_Player.GetPosition(), utsd.GetValue(0).ToVector()).ToString(), null, 1);
184 }
185
187 {
188 //Debug.Log("RequestUniversalTemperatureSources called", "PluginUniversalTemperatureSourceClient");
189
190 if (!enable)
191 {
192 m_UTemperatureSourceDebugs.Clear();
193 m_Player = null;
194 EnableWidgets(false);
195 return;
196 }
197
198 ScriptRPC rpc = new ScriptRPC();
199 rpc.Write(enable);
200 rpc.Send(player, ERPCs.DEV_REQUEST_UTS_DEBUG, true, player.GetIdentity());
201
203 }
204
206 {
208 {
209 PrintString("-------------------------------------");
210 utsd.Debug();
211 PrintString("-------------------------------------");
212 }
213 }
214
216 {
217 //Debug.Log("OnRPC called", "PluginUniversalTemperatureSourceClient");
218 //PrintedDebug();
219 ctx.Read(m_UTemperatureSourceDebugs);
220 }
221}
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]
Definition DbgUI.c:60
Definition Debug.c:14
static Shape DrawCylinder(vector pos, float radius, float height=1, int color=0x1fff7f7f, ShapeFlags flags=ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
Definition Debug.c:450
static Shape DrawArrow(vector from, vector to, float size=0.5, int color=0xFFFFFFFF, int flags=0)
Definition Debug.c:511
Definition EnMath.c:7
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)
PlayerBase m_Player
override void OnUpdate(float delta_time)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
static proto native float Distance(vector v1, vector v2)
Returns the 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 End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:344
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)