Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
dayzplayerimplementswimming.c
Go to the documentation of this file.
1 
3 {
4 
5  DayZPlayer m_pPlayer;
6  SHumanCommandSwimSettings m_pSettings;
7  bool m_bWasSwimming = false; // important for shallow water, so we know if we should get back into swimming when other fullbody command (like damage) finished
8 
10  {
11  m_pPlayer = pPlayer;
12  m_pSettings = pPlayer.GetDayZPlayerType().CommandSwimSettingsW();
13  }
14 
15  float GetWaterDepth()
16  {
17  vector pp = m_pPlayer.GetPosition();
18  vector wl = HumanCommandSwim.WaterLevelCheck(m_pPlayer, pp);
19 
20  return wl[0];
21  }
22 
23  float GetCharacterDepth()
24  {
25  vector pp = m_pPlayer.GetPosition();
26  vector wl = HumanCommandSwim.WaterLevelCheck(m_pPlayer, pp);
27 
28  return wl[1];
29  }
30 
31  bool CheckSwimmingStart(out vector waterLevel)
32  {
33  return DayZPlayerUtils.CheckWaterLevel(m_pPlayer,waterLevel) == EWaterLevels.LEVEL_SWIM_START;
34  }
35 
37  bool HandleSwimming(int pCurrentCommandID, HumanCommandMove pCMove, HumanMovementState pState)
38  {
39  if ( pCurrentCommandID == DayZPlayerConstants.COMMANDID_UNCONSCIOUS || pCurrentCommandID == DayZPlayerConstants.COMMANDID_DAMAGE )
40  return false;
41 
42  m_bWasSwimming = false;
43 
45  if (pCurrentCommandID != DayZPlayerConstants.COMMANDID_SWIM)
46  {
47  vector wl;
48  if (CheckSwimmingStart(wl))
49  {
50  m_pPlayer.StartCommand_Swim();
51  m_bWasSwimming = true;
52  return true;
53  }
54 
56  if ((pCurrentCommandID == DayZPlayerConstants.COMMANDID_MOVE) && (pCMove != null))
57  {
58  pCMove.SetCurrentWaterLevel(wl[1]);
59  m_pPlayer.SetCurrentWaterLevel(wl[1]);
60 
61  if (wl[1] > m_pSettings.m_fToErectLevel && pState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_ERECT && pState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_RAISEDERECT )
62  {
63  if ( DayZPlayerUtils.PlayerCanChangeStance(m_pPlayer, DayZPlayerConstants.STANCEIDX_ERECT) )
64  {
65  pCMove.ForceStanceUp(DayZPlayerConstants.STANCEIDX_ERECT);
66  }
67  else
68  {
69  m_pPlayer.StartCommand_Swim();
70  m_bWasSwimming = true;
71  return true;
72  }
73  }
74  else if (wl[1] > m_pSettings.m_fToCrouchLevel && (pState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_PRONE || pState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_RAISEDPRONE))
75  {
76  if ( DayZPlayerUtils.PlayerCanChangeStance(m_pPlayer, DayZPlayerConstants.STANCEIDX_CROUCH) )
77  {
78  pCMove.ForceStanceUp(DayZPlayerConstants.STANCEIDX_CROUCH);
79  }
80  else
81  {
82  m_pPlayer.StartCommand_Swim();
83  m_bWasSwimming = true;
84  return true;
85  }
86  }
87  }
88 
89  // not handled
90  return false;
91  }
92  else // if (pCurrentCommandID == DayZPlayerConstants.COMMANDID_SWIM)
93  {
94  if (GetWaterDepth() < m_pSettings.m_fWaterLevelOut)
95  {
96  if (DayZPlayerUtils.PlayerCanChangeStance(m_pPlayer, DayZPlayerConstants.STANCEIDX_ERECT, true))
97  {
98  HumanCommandSwim hcs = m_pPlayer.GetCommand_Swim();
99  hcs.StopSwimming();
100  m_bWasSwimming = false;
101  return true;
102  }
103  }
104 
106  m_bWasSwimming = true;
107  return true;
108  }
109  }
110 }
DayZPlayerImplementSwimming
Definition: dayzplayerimplementswimming.c:2
DayZPlayerUtils
private void DayZPlayerUtils()
cannot be instantiated
Definition: dayzplayerutils.c:461
DayZPlayer
Definition: dayzplayerimplement.c:72
HumanMovementState
Definition: human.c:1125
vector
Definition: enconvert.c:105
m_pPlayer
protected DayZPlayer m_pPlayer
data
Definition: dayzplayer.c:135
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
HumanCommandMove
Definition: human.c:433
EWaterLevels
EWaterLevels
Definition: ewaterlevels.c:1
HumanCommandSwim
class HumanCommandLadder HumanCommandSwim()
Definition: human.c:673
SHumanCommandSwimSettings
Definition: humansettings.c:45