Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
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.PhysicsGetPositionWS();
18 vector wl = HumanCommandSwim.WaterLevelCheck(m_pPlayer, pp);
19
20 return wl[0];
21 }
22
23 float GetCharacterDepth()
24 {
25 vector pp = m_pPlayer.PhysicsGetPositionWS();
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]);
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}
override void SetCurrentWaterLevel(float pWaterLevel)
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
DayZPlayer m_pPlayer
data
Definition dayzplayer.c:135
EWaterLevels
Definition ewaterlevels.c:2