Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 61c9305

Browse files
authored
Fix missing swimming animation (#4401)
Fix issue #606
1 parent b8b63de commit 61c9305

File tree

17 files changed

+404
-0
lines changed

17 files changed

+404
-0
lines changed

‎Client/game_sa/CPedSA.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,16 @@ void CPedSA::GetAttachedSatchels(std::vector<SSatchelsData>& satchelsList) const
578578
}
579579
}
580580

581+
void CPedSA::SetInWaterFlags(bool inWater)
582+
{
583+
auto* physicalInterface = static_cast<CPhysicalSAInterface*>(m_pInterface);
584+
if (!physicalInterface)
585+
return;
586+
587+
physicalInterface->bTouchingWater = inWater;
588+
physicalInterface->bSubmergedInWater = inWater;
589+
}
590+
581591
////////////////////////////////////////////////////////////////
582592
//
583593
// CPed_PreRenderAfterTest

‎Client/game_sa/CPedSA.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
475475

476476
void GetAttachedSatchels(std::vector<SSatchelsData> &satchelsList) const override;
477477

478+
void SetInWaterFlags(bool inWater) override;
479+
478480
static void StaticSetHooks();
479481

480482
private:

‎Client/game_sa/CTaskManagementSystemSA.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "TaskPhysicalResponseSA.h"
2323
#include "TaskSA.h"
2424
#include "TaskSecondarySA.h"
25+
#include "TaskSimpleSwimSA.h"
2526

2627
extern CGameSA* pGame;
2728

@@ -181,6 +182,9 @@ CTaskSA* CTaskManagementSystemSA::CreateAppropriateTask(CTaskSAInterface* pTaskI
181182
case TASK_COMPLEX_SUNBATHE:
182183
pTaskSA = new CTaskComplexSunbatheSA;
183184
break;
185+
case TASK_SIMPLE_SWIM:
186+
pTaskSA = new CTaskSimpleSwimSA;
187+
break;
184188

185189
// Car accessories
186190
case TASK_SIMPLE_CAR_SET_PED_IN_AS_PASSENGER:

‎Client/game_sa/CTasksSA.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ CTaskSimpleRunNamedAnim* CTasksSA::CreateTaskSimpleRunNamedAnim(const char* pAni
160160
return pTask;
161161
}
162162

163+
CTaskComplexInWater* CTasksSA::CreateTaskComplexInWater()
164+
{
165+
CTaskComplexInWaterSA* task = NewTask<CTaskComplexInWaterSA>();
166+
m_pTaskManagementSystem->AddTask(task);
167+
return task;
168+
}
169+
163170
CTaskComplexDie* CTasksSA::CreateTaskComplexDie(const eWeaponType eMeansOfDeath, const AssocGroupId animGroup, const AnimationId anim, const float fBlendDelta,
164171
const float fAnimSpeed, const bool bBeingKilledByStealth, const bool bFallingToDeath, const int iFallToDeathDir,
165172
const bool bFallToDeathOverRailing)

‎Client/game_sa/CTasksSA.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CTaskSimpleRunNamedAnim;
4242
class CTaskSimpleStealthKill;
4343
class CTaskSimpleTriggerLookAt;
4444
class CTaskSimpleUseGun;
45+
class CTaskComplexInWater;
4546

4647
class CTasksSA : public CTasks
4748
{
@@ -80,6 +81,8 @@ class CTasksSA : public CTasks
8081
const int iTime = -1, const bool bDontInterrupt = false, const bool bRunInSequence = false,
8182
const bool bOffsetPed = false, const bool bHoldLastFrame = false);
8283

84+
CTaskComplexInWater* CreateTaskComplexInWater();
85+
8386
CTaskComplexDie* CreateTaskComplexDie(const eWeaponType eMeansOfDeath = WEAPONTYPE_UNARMED, const AssocGroupId animGroup = 0 /*ANIM_STD_PED*/,
8487
const AnimationId anim = 0 /*ANIM_STD_KO_FRONT*/, const float fBlendDelta = 4.0f, const float fAnimSpeed = 0.0f,
8588
const bool bBeingKilledByStealth = false, const bool bFallingToDeath = false, const int iFallToDeathDir = 0,

‎Client/game_sa/TaskBasicSA.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,13 @@ CTaskComplexFacialSA::CTaskComplexFacialSA()
246246
call dwFunc
247247
}
248248
}
249+
250+
CTaskComplexInWaterSA::CTaskComplexInWaterSA()
251+
{
252+
CreateTaskInterface(sizeof(CTaskComplexInWaterSA));
253+
if (!IsValid())
254+
return;
255+
256+
// Call the constructor
257+
((void(__thiscall*)(CTaskComplexInWaterSAInterface*))0x6350D0)(static_cast<CTaskComplexInWaterSAInterface*>(GetInterface()));
258+
}

‎Client/game_sa/TaskBasicSA.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,14 @@ class CTaskComplexFacialSA : public virtual CTaskComplexSA, public virtual CTask
251251
public:
252252
CTaskComplexFacialSA();
253253
};
254+
255+
class CTaskComplexInWaterSAInterface : public CTaskComplexSAInterface
256+
{
257+
public:
258+
};
259+
260+
class CTaskComplexInWaterSA : public virtual CTaskComplexSA, public virtual CTaskComplexInWater
261+
{
262+
public:
263+
CTaskComplexInWaterSA();
264+
};

‎Client/game_sa/TaskSimpleSwimSA.cpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
*
6+
* Multi Theft Auto is available from https://www.multitheftauto.com/
7+
*
8+
*****************************************************************************/
9+
10+
#include "StdInc.h"
11+
#include "TaskSimpleSwimSA.h"
12+
#include "CPedSA.h"
13+
14+
CTaskSimpleSwimSA::CTaskSimpleSwimSA(CPed* ped, CVector* pos)
15+
{
16+
CreateTaskInterface(sizeof(CTaskSimpleSAInterface));
17+
if (!IsValid())
18+
return;
19+
20+
// Call the constructor
21+
((void(__thiscall*)(CTaskSimpleSwimSAInterface*, CVector*, CPedSAInterface*))0x688930)(static_cast<CTaskSimpleSwimSAInterface*>(GetInterface()), pos, ped ? ped->GetPedInterface() : nullptr);
22+
}

‎Client/game_sa/TaskSimpleSwimSA.h‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
*
6+
* Multi Theft Auto is available from https://www.multitheftauto.com/
7+
*
8+
*****************************************************************************/
9+
10+
#pragma once
11+
12+
#include <CVector.h>
13+
#include "TaskSA.h"
14+
#include <game/TaskSimpleSwim.h>
15+
#include <enums/SurfaceType.h>
16+
#include <game/CTasks.h>
17+
18+
class CPedSAInterface;
19+
class CEntitySAInterface;
20+
21+
class CTaskSimpleSwimSAInterface : public CTaskSimpleSAInterface
22+
{
23+
public:
24+
bool m_finishedBlending;
25+
bool m_animBlockRefAdded;
26+
swimState m_swimState;
27+
int m_animID;
28+
float m_animSpeed;
29+
CVector m_pos;
30+
CPedSAInterface* m_ped;
31+
float m_rotationX;
32+
float m_turningRotationY;
33+
float m_upperTorsoRotationX;
34+
float m_aimingRotation;
35+
float m_stateChanger;
36+
CEntitySAInterface* m_entity;
37+
CVector m_climbPos;
38+
float m_angle;
39+
SurfaceTypes::Enum m_surfaceType;
40+
std::uint8_t m_field4D[3];
41+
float m_randomMoveBlendRatio;
42+
float m_swimStopTime;
43+
std::uint32_t m_timeStep;
44+
void* m_fxSystem; // FxSystem_cSAInterface*
45+
bool m_triggerWaterSplash;
46+
std::uint8_t m_field61[3];
47+
};
48+
49+
class CTaskSimpleSwimSA : public virtual CTaskSimpleSA, public virtual CTaskSimpleSwim
50+
{
51+
public:
52+
CTaskSimpleSwimSA() {};
53+
CTaskSimpleSwimSA(CPed* ped, CVector* pos);
54+
55+
const CTaskSimpleSwimSAInterface* GetTaskInterface() const { return static_cast<const CTaskSimpleSwimSAInterface*>(GetInterface()); }
56+
CTaskSimpleSwimSAInterface* GetTaskInterface() { return static_cast<CTaskSimpleSwimSAInterface*>(GetInterface()); }
57+
58+
swimState GetSwimState() const override { return GetTaskInterface()->m_swimState; }
59+
};

‎Client/mods/deathmatch/logic/CClientPed.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <game/TaskJumpFall.h>
3232
#include <game/TaskPhysicalResponse.h>
3333
#include <game/TaskAttack.h>
34+
#include <game/TaskSimpleSwim.h>
3435
#include "enums/VehicleType.h"
3536

3637
using std::list;
@@ -7250,3 +7251,32 @@ void CClientPed::RunClimbingTask()
72507251

72517252
climbTask->SetAsPedTask(m_pPlayerPed, TASK_PRIORITY_PRIMARY, true);
72527253
}
7254+
7255+
CTaskSimpleSwim* CClientPed::GetSwimmingTask() const
7256+
{
7257+
if (!m_pPlayerPed)
7258+
return nullptr;
7259+
7260+
CTask* simplestTask = const_cast<CTaskManager*>(GetTaskManager())->GetSimplestActiveTask();
7261+
if (!simplestTask || simplestTask->GetTaskType() != TASK_SIMPLE_SWIM)
7262+
return nullptr;
7263+
7264+
auto* swimmingTask = dynamic_cast<CTaskSimpleSwim*>(simplestTask);
7265+
return swimmingTask;
7266+
}
7267+
7268+
void CClientPed::RunSwimTask() const
7269+
{
7270+
if (!m_pPlayerPed || GetSwimmingTask())
7271+
return;
7272+
7273+
CTaskComplexInWater* inWaterTask = g_pGame->GetTasks()->CreateTaskComplexInWater();
7274+
if (!inWaterTask)
7275+
return;
7276+
7277+
// Set physical flags (bTouchingWater, bSubmergedInWater)
7278+
m_pPlayerPed->SetInWaterFlags(true);
7279+
7280+
inWaterTask->SetAsPedTask(m_pPlayerPed, TASK_PRIORITY_EVENT_RESPONSE_NONTEMP, true);
7281+
}
7282+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /