DayZ 1.28
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
Rangefinder.c
См. документацию.
1class Rangefinder extends PoweredOptic_Base
2{
3 static const float RANGEFINDER_MAX_DISTANCE = 913.4856; //TODO adjust maximal distance to match real life rangefinder
4
5 protected ref Timer m_Timer;
6 protected Widget m_Root;
8
9 protected string m_LayoutPath;
10
12 {
14 }
15
17 {
18 m_IsActionActive = false;
19 }
20
21 protected void InitRangeFinderData()
22 {
23 string path = "cfgVehicles " + GetType();
24 if (GetGame().ConfigIsExisting(path))
25 {
26 string layout;
27 if (GetGame().ConfigIsExisting(path + " rangeFinderLayout"))
28 {
29 GetGame().ConfigGetText(path + " rangeFinderLayout", layout);
30 }
31
32 if (layout != "" && layout.Length() > 0)
33 {
34 m_LayoutPath = layout;
35 }
36 else
37 {
38 m_LayoutPath = "gui/layouts/gameplay/rangefinder_hud.layout";
39 }
40 }
41 }
42
43 // How frequently the measurement should be taken
45 {
46 return 0.5;
47 }
48
49 override void OnWorkStart()
50 {
51 if (GetGame().IsServer() && !m_IsActionActive) // incorrectly synchronized state from EM
52 StopWorkServer();
53
54 if( !GetGame().IsDedicatedServer())
55 {
56 PlayerBase player_this = PlayerBase.Cast( GetGame().GetPlayer() );
57 PlayerBase player_owner = PlayerBase.Cast( GetHierarchyRootPlayer() );
58
59 if ( player_this == player_owner )
60 {
62 }
63 }
64 }
65
66 override void OnWorkStop()
67 {
68 if( !GetGame().IsDedicatedServer())
69 {
70 PlayerBase player_this = PlayerBase.Cast( GetGame().GetPlayer() );
71 PlayerBase player_owner = PlayerBase.Cast( GetHierarchyRootPlayer() );
72
73 if ( player_this == player_owner )
74 {
76 }
77 }
78 }
79
81 {
82 if( !m_Timer )
83 {
85 }
86
88
89 // Either use root as text widget directly or find the text as children, arbitrary layout is supported now.
91 if (!m_RangeText)
92 m_RangeText = TextWidget.Cast(m_Root.FindAnyWidget("RangeText"));
93
94 m_Timer.Run( GetMeasurementUpdateInterval(), this, "DoMeasurement", null, true );
95 }
96
98 {
99 if( m_Timer )
100 {
101 m_Timer.Stop();
102 }
103
104 if (m_Root)
105 {
106 delete m_Root;
107 }
108 }
109
110 protected void SetDistanceText(TextWidget text, float dist)
111 {
112 dist = Math.Round(dist);
113
114 if (dist < RANGEFINDER_MAX_DISTANCE)
115 {
116 if( dist < 10 )
117 text.SetText( "00" + dist.ToString() );
118 else if( dist < 100 )
119 text.SetText( "0" + dist.ToString() );
120 else
121 text.SetText( dist.ToString() );
122 }
123 else
124 {
125 SetInvalidText(text);
126 }
127 }
128
129 protected void SetInvalidText(TextWidget text)
130 {
131 text.SetText( "---" );
132 }
133
134 // Measures the distance and returns result in formated string
136 {
137 PlayerBase player = GetPlayer();
138
139 if ( player )
140 {
142 vector fromDirection = GetGame().GetCurrentCameraDirection();
143 vector to = from + (fromDirection * RANGEFINDER_MAX_DISTANCE);
144 vector contact_pos;
145 vector contact_dir;
146 int contactComponent;
147
148 bool hit = DayZPhysics.RaycastRV( from, to, contact_pos, contact_dir, contactComponent, NULL , NULL, player, false, false, ObjIntersectIFire);
149
150 // (a)
151 // from -> --- <- horizEnd
152 // (h) \ |
153 // to -> \|
154
155 // Generate result
156 float h = vector.Distance( from, contact_pos );
157
158 if (hit)
160 else
162
163 // Horizontal distance
164 TextWidget angleText = TextWidget.Cast(m_Root.FindAnyWidget("AngleText"));
165 TextWidget horizText = TextWidget.Cast(m_Root.FindAnyWidget("RangeHDText"));
166
167 vector horizontalTo = Vector( contact_pos[0], from[1], contact_pos[2] );
168 float a = vector.Distance( from, horizontalTo );
169
170 // Angle between horizontal and actual line
171 float heightDiff = contact_pos[1] - from[1];
172 float angle = Math.Atan( heightDiff / a ) * Math.RAD2DEG;
173 angle = Math.Round(angle);
174
175 if (angleText)
176 {
177 if (hit)
178 angleText.SetText(string.Format("%1", angle));
179 else
180 SetInvalidText( angleText );
181 }
182
183 if (horizText)
184 {
185 if (hit)
186 SetDistanceText( horizText, a );
187 else
188 SetInvalidText( horizText );
189 }
190 }
191 }
192
193 override void SetActions()
194 {
195 super.SetActions();
196
199 }
200
201 override void OnDebugSpawn()
202 {
203 GetInventory().CreateInInventory( "Battery9V" );
204 }
205}
eBleedingSourceType GetType()
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
void RemoveAction(typename actionName)
Определения AdvancedCommunication.c:252
PlayerBase GetPlayer()
Определения ModifierBase.c:51
string path
Определения OptionSelectorMultistate.c:142
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto native WorkspaceWidget GetWorkspace()
proto native vector GetCurrentCameraPosition()
proto native vector GetCurrentCameraDirection()
static proto bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, set< Object > results=NULL, Object with=NULL, Object ignore=NULL, bool sorted=false, bool ground_only=false, int iType=ObjIntersectView, float radius=0.0, CollisionFlags flags=CollisionFlags.NEARESTCONTACT)
Raycasts world by given parameters.
Определения DayZPhysics.c:124
Определения EnMath.c:7
Определения PlayerBaseClient.c:2
override void SetActions()
Определения Rangefinder.c:193
void Rangefinder()
Определения Rangefinder.c:11
Widget m_Root
Определения Rangefinder.c:6
void ~Rangefinder()
Определения Rangefinder.c:16
static const float RANGEFINDER_MAX_DISTANCE
Определения Rangefinder.c:3
void DoMeasurement()
Определения Rangefinder.c:135
void SetDistanceText(TextWidget text, float dist)
Определения Rangefinder.c:110
string m_LayoutPath
Определения Rangefinder.c:9
ref Timer m_Timer
Определения Rangefinder.c:5
void SetInvalidText(TextWidget text)
Определения Rangefinder.c:129
void StopPeriodicMeasurement()
Определения Rangefinder.c:97
void InitRangeFinderData()
Определения Rangefinder.c:21
void StartPeriodicMeasurement()
Определения Rangefinder.c:80
override void OnDebugSpawn()
Определения Rangefinder.c:201
TextWidget m_RangeText
Определения Rangefinder.c:7
float GetMeasurementUpdateInterval()
Определения Rangefinder.c:44
override void OnWorkStop()
Определения Rangefinder.c:66
override void OnWorkStart()
Определения Rangefinder.c:49
Определения NVGoggles.c:2
Определения EnWidgets.c:220
Определения DayZPlayerImplement.c:63
Определения EnWidgets.c:190
proto string ToString(bool simple=true)
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
Определения EnConvert.c:106
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Atan(float x)
Returns angle in radians from tangent.
static proto float Round(float f)
Returns mathematical round of value.
static const float RAD2DEG
Определения EnMath.c:16
proto native int Length()
Returns length of string.
const int CALL_CATEGORY_GAMEPLAY
Определения 3_Game/tools/tools.c:10
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.