DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
PluginUniversalTemperatureSourceClient.c
См. документацию.
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];
12
13 protected PlayerBase m_Player;
14
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
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 {
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();
239 }
240}
ERPCs
Определения ERPCs.c:2
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()
Определения DbgUI.c:60
static Shape DrawCylinder(vector pos, float radius, float height=1, int color=0x1fff7f7f, ShapeFlags flags=ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
Определения Debug.c:335
static Shape DrawArrow(vector from, vector to, float size=0.5, int color=0xFFFFFFFF, int flags=0)
Определения Debug.c:404
Определения Debug.c:2
Определения EnMath.c:7
Определения PlayerBaseClient.c:2
void UpdateStatWidget(int rowIndex, UTemperatureSourceDebug utsd)
void RequestUniversalTemperatureSources(PlayerBase player, int enable)
void PluginUniversalTemperatureSourceClient()
override void OnInit()
void ProcessUniversalTemperatureSources()
void PluginUniversalTemperatureSourceServer()
TextWidget m_HeaderWidget[MAX_SIMULTANEOUS_UTS]
ref array< ref UTemperatureSourceDebug > m_UTemperatureSourceDebugs
TextListboxWidget m_StatListWidgets[MAX_SIMULTANEOUS_UTS]
const int MAX_SIMULTANEOUS_UTS
void OnRPC(ParamsReadContext ctx)
float CalcTemperatureFromTemperatureSource(notnull UTemperatureSourceDebug utsd)
PlayerBase m_Player
Определения PluginAdminLog.c:12
float m_UTSAverageTemperature
override void OnUpdate(float delta_time)
void EnableWidgets(bool enable)
ref Widget m_RootWidget[MAX_SIMULTANEOUS_UTS]
Определения PluginBase.c:2
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...
Определения gameplay.c:105
proto bool Write(void value_out)
proto bool Read(void value_in)
Определения EnWidgets.c:220
Определения EnWidgets.c:190
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto string ToString(bool simple=true)
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.
Определения EnConvert.c:106
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
const int COLOR_BLUE_A
Определения constants.c:71
const int COLOR_RED_A
Определения constants.c:69
const int COLOR_YELLOW_A
Определения constants.c:72
const int COLOR_GREEN_A
Определения constants.c:70
ShapeFlags
Определения 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);.
Определения 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.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.
proto native Widget FindAnyWidget(string pathname)