1 class PluginUniversalTemperatureSourceClient
extends PluginBase
3 const int MAX_SIMULTANEOUS_UTS = 10;
5 protected float m_UTSAverageTemperature;
11 protected TextWidget m_HeaderWidget[MAX_SIMULTANEOUS_UTS];
15 void PluginUniversalTemperatureSourceClient()
27 override void OnUpdate(
float delta_time)
42 for (
int i = 0; i < MAX_SIMULTANEOUS_UTS; i++)
44 m_RootWidget[i] =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/debug/day_z_debug_remoteinfo.layout");
52 foreach (UTemperatureSourceDebug utsd : m_UTemperatureSourceDebugs)
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();
72 ProcessUniversalTemperatureSources();
74 if (m_UTemperatureSourceDebugs.Count() > 0)
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));
84 protected void ProcessUniversalTemperatureSources()
86 if (m_UTemperatureSourceDebugs.Count() == 0)
88 m_UTSAverageTemperature = 0;
99 if (
vector.DistanceSq(
m_Player.GetPosition(), utsd.GetValue(0).ToVector()) >
Math.SqrFloat(utsd.GetValue(2).ToFloat()))
104 utsTemperatures.Insert(CalcTemperatureFromTemperatureSource(utsd));
107 float min = MiscGameplayFunctions.GetMinValue(utsTemperatures);
108 float max = MiscGameplayFunctions.GetMaxValue(utsTemperatures);
110 if (max > 0 && min < 0)
112 m_UTSAverageTemperature = (max + min) * 0.5;
116 m_UTSAverageTemperature = max;
121 protected float CalcTemperatureFromTemperatureSource(notnull UTemperatureSourceDebug utsd)
123 float distance =
vector.Distance(
m_Player.GetPosition(), utsd.GetValue(0).ToVector());
124 distance =
Math.Max(distance, 0.1);
125 float temperature = 0;
128 if (distance > utsd.GetValue(1).ToFloat())
130 float distFactor = 1 - (distance / utsd.GetValue(2).ToFloat());
131 distFactor =
Math.Max(distFactor, 0.0);
132 temperature = utsd.GetValue(3).ToFloat() * distFactor;
136 temperature = utsd.GetValue(3).ToFloat();
146 for (
int i = 0; i < MAX_SIMULTANEOUS_UTS; i++)
152 void UpdateStatWidgets()
155 int utsDebugCount = m_UTemperatureSourceDebugs.Count();
156 for (; i < utsDebugCount && i < MAX_SIMULTANEOUS_UTS; ++i)
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]);
164 if (screen_pos_stats[2] > 0 && screen_pos_stats[0] > 0 && screen_pos_stats[1] > 0)
167 UpdateStatWidget(i, utsd);
175 for (; i < MAX_SIMULTANEOUS_UTS; ++i)
184 void UpdateStatWidget(
int rowIndex, UTemperatureSourceDebug utsd)
188 m_HeaderWidget[rowIndex].SetText(utsd.GetHeader());
190 int numPairs = utsd.PairsCount();
191 for (
int i = 0; i < numPairs; ++i)
202 void RequestUniversalTemperatureSources(
PlayerBase player,
int enable)
208 m_UTemperatureSourceDebugs.Clear();
216 rpc.Send(player,
ERPCs.DEV_REQUEST_UTS_DEBUG,
true, player.GetIdentity());
223 foreach (UTemperatureSourceDebug utsd : m_UTemperatureSourceDebugs)
225 PrintString(
"-------------------------------------");
227 PrintString(
"-------------------------------------");
235 ctx.Read(m_UTemperatureSourceDebugs);