Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
playersoundmanager.c
Go to the documentation of this file.
1 
2 const float SOUNDS_HEARING_DISTANCE = 50;
3 
5 {
10  //FREEZING,
11 
12  //------
13  // add stuff above !
14  //------
16 }
17 
18 
19 
21 {
23 
26 
28  {
29  m_Player = player;
30  Init();
31  }
32 
34  {
35  int index = handler.GetID();
36  m_Handlers[index] = handler;
37  }
38 
40  {
41  return m_Handlers[id];
42  }
43 
44  void Init()
45  {
46 
47  }
48 
49  void Update()
50  {
51 
52  }
53 
54 
55 }
56 
57 class PlayerSoundManagerServer extends PlayerSoundManagerBase
58 {
59  //------------------------
60  // REGISTER HANDLER HERE
61  //------------------------
62  override void Init()
63  {
64  RegisterHandler(new StaminaSoundHandlerServer(m_Player));
65  RegisterHandler(new HungerSoundHandlerServer(m_Player));
66  RegisterHandler(new ThirstSoundHandlerServer(m_Player));
67  RegisterHandler(new InjurySoundHandlerServer(m_Player));
68  }
69 
70  override void Update()
71  {
72  if( m_Player.IsUnconscious() )
73  {
74  return;
75  }
76 
77  for(int i = 0; i < (MAX_HANDLERS_COUNT - 1); i++)
78  {
79  m_Handlers[i].Update();
80  }
81  }
82 }
83 
85 {
89 
90  //------------------------
91  // REGISTER HANDLER HERE
92  //------------------------
93  override void Init()
94  {
95  RegisterHandler(new StaminaSoundHandlerClient(m_Player));
96  RegisterHandler(new HungerSoundHandlerClient(m_Player));
97  RegisterHandler(new ThirstSoundHandlerClient(m_Player));
98  RegisterHandler(new InjurySoundHandlerClient(m_Player));
99  //RegisterHandler(new FreezingSoundHandlerClient(m_Player));
100  }
101 
103  {
104 
105  if( !GetGame().IsDedicatedServer() )
106  {
107  m_ClientCharacterDistanceCheck.Run(2, this, "CheckAllowUpdate", null, true);
108  }
109  }
110 
111  void SetAllowUpdate(bool enable)
112  {
113  if( enable )
114  {
115  m_UpdateTimerRunning = true;
116  m_ClientCharacterTick.Run(0.03, this, "Update", null, true);
117  }
118  else
119  {
120  m_UpdateTimerRunning = false;
121  m_ClientCharacterTick.Stop();
122  }
123  }
124 
125  override void Update()
126  {
127  if( !m_Player.IsAlive() )
128  {
129  SetAllowUpdate(false);
130  return;
131  }
132 
133 #ifndef NO_GUI
134  for(int i = 0; i < MAX_HANDLERS_COUNT; i++)
135  {
136  m_Handlers[i].Update();
137  }
138 #endif
139  }
140 
142  {
143  if( GetGame().GetPlayer() )
144  {
145  bool is_at_hearing_distance = vector.Distance(GetGame().GetPlayer().GetPosition(), m_Player.GetPosition()) < SOUNDS_HEARING_DISTANCE;
146 
147  if( m_UpdateTimerRunning && !is_at_hearing_distance )
148  {
149  SetAllowUpdate(false);
150  }
151  else if( !m_UpdateTimerRunning && is_at_hearing_distance )
152  {
153  SetAllowUpdate(true);
154  }
155  //PrintString("distance:" + vector.Distance(GetGame().GetPlayer().GetPosition(), m_Player.GetPosition()).ToString());
156  }
157  }
158 }
GetGame
proto native CGame GetGame()
GetHandler
SoundHandlerBase GetHandler(eSoundHandlers id)
Definition: playersoundmanager.c:39
INJURY
@ INJURY
Definition: playersoundmanager.c:8
m_ClientCharacterDistanceCheck
ref Timer m_ClientCharacterDistanceCheck
Definition: playersoundmanager.c:87
m_UpdateTimerRunning
bool m_UpdateTimerRunning
Definition: playersoundmanager.c:88
COUNT
@ COUNT
Definition: playersoundmanager.c:15
MAX_HANDLERS_COUNT
const int MAX_HANDLERS_COUNT
Definition: playersoundmanager.c:24
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
CheckAllowUpdate
void CheckAllowUpdate()
Definition: playersoundmanager.c:141
Init
void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
Definition: playersoundmanager.c:44
m_Handlers
ref SoundHandlerBase m_Handlers[MAX_HANDLERS_COUNT]
Definition: playersoundmanager.c:25
PlayerSoundManagerClient
void PlayerSoundManagerClient(PlayerBase player)
Definition: playersoundmanager.c:102
RegisterHandler
void RegisterHandler(SoundHandlerBase handler)
Definition: playersoundmanager.c:33
SOUNDS_HEARING_DISTANCE
const float SOUNDS_HEARING_DISTANCE
Definition: playersoundmanager.c:2
Update
void Update()
Definition: playersoundmanager.c:49
eSoundHandlers
eSoundHandlers
Definition: playersoundmanager.c:4
THIRST
@ THIRST
Definition: playersoundmanager.c:9
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
SetAllowUpdate
void SetAllowUpdate(bool enable)
Definition: playersoundmanager.c:111
HUNGER
@ HUNGER
Definition: playersoundmanager.c:7
PlayerSoundManagerBase
void PlayerSoundManagerBase(PlayerBase player)
Definition: playersoundmanager.c:27
SoundHandlerBase
Definition: hungersoundhandler.c:1
Timer
Definition: dayzplayerimplement.c:62
m_Player
enum eSoundHandlers m_Player
PlayerSoundManagerBase
Definition: playersoundmanager.c:57
m_ClientCharacterTick
class PlayerSoundManagerServer extends PlayerSoundManagerBase m_ClientCharacterTick
STAMINA
@ STAMINA
Definition: playersoundmanager.c:6