DayZ 1.24
Loading...
Searching...
No Matches
Rangefinder.c
Go to the documentation of this file.
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;
7
9 {
10 }
11
12 // How frequently the measurement should be taken
14 {
15 return 0.5;
16 }
17
18 override void OnWorkStart()
19 {
20 if (!GetGame().IsDedicatedServer())
21 {
23 PlayerBase player_owner = PlayerBase.Cast(GetHierarchyRootPlayer());
24
27 }
28 }
29
30 override void OnWorkStop()
31 {
32 if (!GetGame().IsDedicatedServer())
33 {
35 PlayerBase player_owner = PlayerBase.Cast(GetHierarchyRootPlayer());
36
39 }
40 }
41
43 {
44 if (!m_Timer)
46
47 m_RangeText = TextWidget.Cast(GetGame().GetWorkspace().CreateWidgets("gui/layouts/gameplay/rangefinder_hud.layout"));
48
49 m_Timer.Run(GetMeasurementUpdateInterval(), this, "DoMeasurement", null, true);
50 }
51
53 {
54 if (m_Timer)
55 m_Timer.Stop();
56
57 if (m_RangeText)
58 delete m_RangeText;
59 }
60
61 // Measures the distance and returns result in formated string
63 {
65
66 if (player)
67 {
68 vector from = GetGame().GetCurrentCameraPosition();
69 vector to = from + (GetGame().GetCurrentCameraDirection() * RANGEFINDER_MAX_DISTANCE);
73
75
76 // Generate result
79
80 if (dist < RANGEFINDER_MAX_DISTANCE)
81 {
82 if (dist < 10)
83 m_RangeText.SetText("00" + dist.ToString());
84 else if (dist < 100)
85 m_RangeText.SetText("0" + dist.ToString());
86 else
87 m_RangeText.SetText(dist.ToString());
88 }
89 else
90 m_RangeText.SetText("- - -");
91 }
92 }
93
94 override void SetActions()
95 {
96 super.SetActions();
97
100 }
101
102 override void OnDebugSpawn()
103 {
104 GetInventory().CreateInInventory("Battery9V");
105 }
106}
void AddAction(typename actionName)
void RemoveAction(typename actionName)
ref Timer m_Timer
Definition DayZGame.c:675
PlayerBase GetPlayer()
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.
Definition EnMath.c:7
override void SetActions()
Definition Rangefinder.c:94
static const float RANGEFINDER_MAX_DISTANCE
Definition Rangefinder.c:3
ref Timer m_Timer
Definition Rangefinder.c:5
void StopPeriodicMeasurement()
Definition Rangefinder.c:52
void StartPeriodicMeasurement()
Definition Rangefinder.c:42
override void OnDebugSpawn()
TextWidget m_RangeText
Definition Rangefinder.c:6
float GetMeasurementUpdateInterval()
Definition Rangefinder.c:13
override void OnWorkStop()
Definition Rangefinder.c:30
override void OnWorkStart()
Definition Rangefinder.c:18
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()
static proto float Round(float f)
Returns mathematical round of value.
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10