Skip to content

Commit c43c1b9

Browse files
authored
Improve function getPedMoveState (PR #4316)
Fixes #1598 Fixes #1594 Fixes #1590
1 parent 078d46b commit c43c1b9

File tree

5 files changed

+96
-47
lines changed

5 files changed

+96
-47
lines changed

Client/game_sa/CPedSA.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class CPedSAInterface : public CPhysicalSAInterface
261261
int unk_52C;
262262

263263
int pedState;
264-
int moveState;
264+
PedMoveState::Enum moveState;
265265
int swimmingMoveState;
266266

267267
int unk_53C;
@@ -276,10 +276,10 @@ class CPedSAInterface : public CPhysicalSAInterface
276276
float fRotationSpeed;
277277
float fMoveAnim;
278278

279-
CEntitySAInterface* pContactEntity;
279+
CEntitySAInterface* pContactEntity; // m_standingOnEntity
280280
CVector unk_56C;
281281
CVector unk_578;
282-
CEntitySAInterface* pLastContactEntity;
282+
CEntitySAInterface* pLastContactEntity; // m_contactEntity
283283

284284
CVehicleSAInterface* pLastVehicle;
285285
CVehicleSAInterface* pVehicle;
@@ -421,8 +421,9 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
421421
void SetFightingStyle(eFightingStyle style, std::uint8_t styleExtra = 6) override;
422422

423423
CEntity* GetContactEntity() const override;
424+
bool IsStandingOnEntity() const override { return GetPedInterface()->pContactEntity != nullptr; };
424425

425-
int GetRunState() const override { return GetPedInterface()->moveState; }
426+
PedMoveState::Enum GetMoveState() const override { return GetPedInterface()->moveState; }
426427

427428
bool GetCanBeShotInVehicle() const override{ return GetPedInterface()->pedFlags.bCanBeShotInVehicle; }
428429
bool GetTestForShotInVehicle() const override { return GetPedInterface()->pedFlags.bTestForShotInVehicle; }

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,16 @@ void CClientPed::Init(CClientManager* pManager, unsigned long ulModelID, bool bI
231231
m_MovementStateNames[MOVEMENTSTATE_JOG] = "jog";
232232
m_MovementStateNames[MOVEMENTSTATE_SPRINT] = "sprint";
233233
m_MovementStateNames[MOVEMENTSTATE_CROUCH] = "crouch";
234-
// These two are inactive for now
235234
m_MovementStateNames[MOVEMENTSTATE_CRAWL] = "crawl";
236235
m_MovementStateNames[MOVEMENTSTATE_ROLL] = "roll";
237236
m_MovementStateNames[MOVEMENTSTATE_JUMP] = "jump";
238237
m_MovementStateNames[MOVEMENTSTATE_FALL] = "fall";
239238
m_MovementStateNames[MOVEMENTSTATE_CLIMB] = "climb";
239+
m_MovementStateNames[MOVEMENTSTATE_SWIM] = "swim";
240+
m_MovementStateNames[MOVEMENTSTATE_WALK_TO_POINT] = "walk_to_point";
241+
m_MovementStateNames[MOVEMENTSTATE_ASCENT_JETPACK] = "ascent_jetpack";
242+
m_MovementStateNames[MOVEMENTSTATE_DESCENT_JETPACK] = "descent_jetpack";
243+
m_MovementStateNames[MOVEMENTSTATE_JETPACK] = "jetpack_flying";
240244

241245
// Create the player model
242246
if (m_bIsLocalPlayer)
@@ -2420,53 +2424,63 @@ eMovementState CClientPed::GetMovementState()
24202424
const char* szComplexTaskName = GetTaskManager()->GetActiveTask()->GetTaskName();
24212425
const char* szSimpleTaskName = GetTaskManager()->GetSimplestActiveTask()->GetTaskName();
24222426

2423-
// Is he climbing?
2424-
if (strcmp(szSimpleTaskName, "TASK_SIMPLE_CLIMB") == 0)
2427+
// Check tasks
2428+
if (strcmp(szSimpleTaskName, "TASK_SIMPLE_CLIMB") == 0) // Is he climbing?
24252429
return MOVEMENTSTATE_CLIMB;
2426-
2427-
// Is he jumping?
2428-
else if (strcmp(szComplexTaskName, "TASK_COMPLEX_JUMP") == 0)
2430+
else if (strcmp(szComplexTaskName, "TASK_COMPLEX_JUMP") == 0) // Is he jumping?
24292431
return MOVEMENTSTATE_JUMP;
2432+
else if (strcmp(szSimpleTaskName, "TASK_SIMPLE_GO_TO_POINT") == 0) // Entering vehicle (walking to the doors)?
2433+
return MOVEMENTSTATE_WALK_TO_POINT;
2434+
else if (strcmp(szSimpleTaskName, "TASK_SIMPLE_SWIM") == 0) // Is he swimming?
2435+
return MOVEMENTSTATE_SWIM;
2436+
else if (strcmp(szSimpleTaskName, "TASK_SIMPLE_JETPACK") == 0) // Is he flying?
2437+
{
2438+
if (cs.ButtonCross != 0)
2439+
return MOVEMENTSTATE_ASCENT_JETPACK;
2440+
else if (cs.ButtonSquare != 0)
2441+
return MOVEMENTSTATE_DESCENT_JETPACK;
2442+
else
2443+
return MOVEMENTSTATE_JETPACK;
2444+
}
24302445

2431-
// Is he falling?
2432-
else if (!IsOnGround() && !GetContactEntity())
2446+
// Check movement state
2447+
if (!IsOnGround() && !GetContactEntity() && !m_pPlayerPed->IsStandingOnEntity() && !m_pPlayerPed->IsInWater() && (strcmp(szSimpleTaskName, "TASK_SIMPLE_IN_AIR") == 0 || strcmp(szSimpleTaskName, "TASK_SIMPLE_FALL") == 0)) // Is he falling?
24332448
return MOVEMENTSTATE_FALL;
24342449

2435-
// Grab his controller state
2436-
bool bWalkKey = false;
2437-
if (GetType() == CCLIENTPLAYER)
2438-
bWalkKey = CClientPad::GetControlState("walk", cs, true);
2439-
else
2440-
m_Pad.GetControlState("walk", bWalkKey);
2450+
// Sometimes it returns 'fall' or 'walk', so it's better to return false instead
2451+
if (IsEnteringVehicle() || IsLeavingVehicle())
2452+
return MOVEMENTSTATE_UNKNOWN;
24412453

2442-
// Is he standing up?
24432454
if (!IsDucked())
24442455
{
2445-
unsigned int iRunState = m_pPlayerPed->GetRunState();
2456+
bool walking = false;
2457+
if (GetType() == CCLIENTPLAYER)
2458+
walking = CClientPad::GetControlState("walk", cs, true);
2459+
else
2460+
m_Pad.GetControlState("walk", walking);
24462461

2447-
// Is he moving the contoller at all?
2448-
if (iRunState == 1 && cs.LeftStickX == 0 && cs.LeftStickY == 0)
2449-
return MOVEMENTSTATE_STAND;
2450-
2451-
// Is he either pressing the walk key, or has run state 1?
2452-
if (iRunState == 1 || bWalkKey && iRunState == 6)
2453-
return MOVEMENTSTATE_WALK;
2454-
else if (iRunState == 4)
2455-
return MOVEMENTSTATE_POWERWALK;
2456-
else if (iRunState == 6)
2457-
return MOVEMENTSTATE_JOG;
2458-
else if (iRunState == 7)
2459-
return MOVEMENTSTATE_SPRINT;
2462+
switch (m_pPlayerPed->GetMoveState())
2463+
{
2464+
case PedMoveState::PEDMOVE_STILL:
2465+
return MOVEMENTSTATE_STAND;
2466+
case PedMoveState::PEDMOVE_WALK:
2467+
return (cs.LeftStickX == 0 && cs.LeftStickY == 0) ? MOVEMENTSTATE_STAND : MOVEMENTSTATE_WALK;
2468+
case PedMoveState::PEDMOVE_SPRINT:
2469+
return MOVEMENTSTATE_SPRINT;
2470+
case PedMoveState::PEDMOVE_RUN:
2471+
return walking ? MOVEMENTSTATE_WALK : MOVEMENTSTATE_JOG; // FileEX: It should be MOVEMENTSTATE_RUN, but we're keeping JOG for backward compatibility (PEDMOVE_JOG is unused in SA)
2472+
}
24602473
}
24612474
else
24622475
{
24632476
// Is he moving the contoller at all?
24642477
if (cs.LeftStickX == 0 && cs.LeftStickY == 0)
24652478
return MOVEMENTSTATE_CROUCH;
24662479
else
2467-
return MOVEMENTSTATE_CRAWL;
2480+
return (cs.LeftStickX != 0 && cs.RightShoulder1 != 0) ? MOVEMENTSTATE_ROLL : MOVEMENTSTATE_CRAWL;
24682481
}
24692482
}
2483+
24702484
return MOVEMENTSTATE_UNKNOWN;
24712485
}
24722486

@@ -6119,7 +6133,7 @@ bool CClientPed::ShouldBeStealthAiming()
61196133
{
61206134
// We need to be either crouched, walking or standing
61216135
SBindableGTAControl* pWalkControl = pKeyBinds->GetBindableFromControl("walk");
6122-
if (m_pPlayerPed->GetRunState() == 1 || m_pPlayerPed->GetRunState() == 4 || pWalkControl && pWalkControl->bState)
6136+
if (m_pPlayerPed->GetMoveState() == PedMoveState::PEDMOVE_STILL || m_pPlayerPed->GetMoveState() == PedMoveState::PEDMOVE_WALK || pWalkControl && pWalkControl->bState)
61236137
{
61246138
// Do we have a target ped?
61256139
CClientPed* pTargetPed = GetTargetedPed();

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,22 @@ enum eBodyPart
6666
enum eMovementState
6767
{
6868
MOVEMENTSTATE_UNKNOWN,
69-
MOVEMENTSTATE_STAND, // Standing still
70-
MOVEMENTSTATE_WALK, // Walking
71-
MOVEMENTSTATE_POWERWALK, // Walking quickly
72-
MOVEMENTSTATE_JOG, // Jogging
73-
MOVEMENTSTATE_SPRINT, // Sprinting
74-
MOVEMENTSTATE_CROUCH, // Crouching still
75-
MOVEMENTSTATE_CRAWL, // Crouch-moving
76-
MOVEMENTSTATE_ROLL, // Crouch-rolling (Needs adding)
77-
MOVEMENTSTATE_JUMP, // Jumping
78-
MOVEMENTSTATE_FALL, // Falling
79-
MOVEMENTSTATE_CLIMB // Climbing
69+
MOVEMENTSTATE_STAND, // Standing still
70+
MOVEMENTSTATE_WALK, // Walking
71+
MOVEMENTSTATE_POWERWALK, // Walking quickly
72+
MOVEMENTSTATE_JOG, // Jogging (Unused)
73+
MOVEMENTSTATE_SPRINT, // Sprinting
74+
MOVEMENTSTATE_CROUCH, // Crouching still
75+
MOVEMENTSTATE_CRAWL, // Crouch-moving
76+
MOVEMENTSTATE_ROLL, // Crouch-rolling
77+
MOVEMENTSTATE_JUMP, // Jumping
78+
MOVEMENTSTATE_FALL, // Falling
79+
MOVEMENTSTATE_CLIMB, // Climbing
80+
MOVEMENTSTATE_SWIM, // Swimming
81+
MOVEMENTSTATE_WALK_TO_POINT, // Entering vehicle (walking to the door)
82+
MOVEMENTSTATE_ASCENT_JETPACK, // Ascending with jetpack
83+
MOVEMENTSTATE_DESCENT_JETPACK, // Descending with jetpack
84+
MOVEMENTSTATE_JETPACK, // Jetpack flying
8085
};
8186

8287
enum eDeathAnims

Client/sdk/game/CPed.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "CWeaponInfo.h"
1515
#include "CPedSound.h"
1616
#include "enums/PedState.h"
17+
#include "enums/PedMoveState.h"
1718

1819
// To avoid VS intellisense highlight errors
1920
#include <memory>
@@ -253,8 +254,9 @@ class CPed : public virtual CPhysical
253254
virtual void SetFightingStyle(eFightingStyle style, std::uint8_t styleExtra) = 0;
254255

255256
virtual CEntity* GetContactEntity() const = 0;
257+
virtual bool IsStandingOnEntity() const = 0;
256258

257-
virtual int GetRunState() const = 0;
259+
virtual PedMoveState::Enum GetMoveState() const = 0;
258260

259261
virtual bool GetCanBeShotInVehicle() const = 0;
260262
virtual bool GetTestForShotInVehicle() const = 0;

Shared/sdk/enums/PedMoveState.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: sdk/PedMoveState.h
6+
* PURPOSE: Header for common definitions
7+
*
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#pragma once
13+
14+
namespace PedMoveState
15+
{
16+
enum Enum
17+
{
18+
PEDMOVE_NONE = 0,
19+
PEDMOVE_STILL,
20+
PEDMOVE_TURN_L,
21+
PEDMOVE_TURN_R,
22+
PEDMOVE_WALK,
23+
PEDMOVE_JOG,
24+
PEDMOVE_RUN,
25+
PEDMOVE_SPRINT,
26+
};
27+
}

0 commit comments

Comments
 (0)