diff options
Diffstat (limited to 'src/entities')
40 files changed, 4 insertions, 5428 deletions
diff --git a/src/entities/Automobile.cpp b/src/entities/Automobile.cpp deleted file mode 100644 index 54eed17a..00000000 --- a/src/entities/Automobile.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "Automobile.h" - -CAutomobile::CAutomobile(int mi, uint8 owner) -{ - ctor(mi, owner); -} - -WRAPPER CAutomobile* CAutomobile::ctor(int, uint8) { EAXJMP(0x52C6B0); } - -WRAPPER void CAutomobile::SetDoorDamage(int32, uint32, bool) { EAXJMP(0x530200); } -WRAPPER void CAutomobile::SetPanelDamage(int32, uint32, bool) { EAXJMP(0x5301A0); } -WRAPPER void CAutomobile::SetBumperDamage(int32, uint32, bool) { EAXJMP(0x530120); } - -STARTPATCHES -InjectHook(0x52D170, &CAutomobile::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/Automobile.h b/src/entities/Automobile.h deleted file mode 100644 index b1463936..00000000 --- a/src/entities/Automobile.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -#include "DamageManager.h" -#include "Vehicle.h" - -struct CDoor -{ - float m_fAngleWhenOpened; - float m_fAngleWhenClosed; - char field_8; - char field_9; - char field_10; - char field_11; - float m_fAngle; - float m_fPreviousAngle; - float m_fAngularVelocity; - CVector m_vecVelocity; -}; - -class CAutomobile : public CVehicle -{ -public: - // 0x288 - CDamageManager Damage; - CDoor Doors[6]; - RwFrame *m_aCarNodes[NUM_CAR_NODES]; - CColPoint m_aWheelColPoints[4]; - float m_aWheelDist[4]; - float m_aWheelDistPrev[4]; - float m_aWheelSkidThing[4]; - int field_49C; - bool m_aWheelSkidmarkMuddy[4]; - bool m_aWheelSkidmarkBloody[4]; - float m_aWheelRotation[4]; - float m_aWheelPosition[4]; - float m_aWheelSpeed[4]; - uint8 stuff3[12]; - uint32 m_nBusDoorTimerEnd; - uint32 m_nBusDoorTimerStart; - float m_aSuspensionRange[4]; - float m_aSuspensionLineLength[4]; - float m_fHeightAboveRoad; - float m_fImprovedHandling; - uint8 stuff6[32]; - CPhysical *m_aGroundPhysical[4]; // physicals touching wheels - CVector m_aGroundOffset[4]; // from ground object to colpoint - CEntity *m_pBlowUpEntity; - float m_weaponThingA; // TODO - float m_weaponThingB; // TODO - float m_fCarGunLR; - float m_fCarGunUD; - float m_fWindScreenRotation; - uint8 stuff4[4]; - uint8 m_nWheelsOnGround_2; - uint8 m_nWheelsOnGround; - uint8 m_nWheelsOnGroundPrev; - uint8 stuff5[5]; - int32 m_aWheelState[4]; - - CAutomobile(int, uint8); - CAutomobile* ctor(int, uint8); - void SetDoorDamage(int32, uint32, bool); /* TODO: eDoors */ - void SetPanelDamage(int32, uint32, bool); /* TODO: ePanels */ - void SetBumperDamage(int32, uint32, bool); /* TODO: ePanels */ - void dtor() { this->CAutomobile::~CAutomobile(); } -}; -static_assert(sizeof(CAutomobile) == 0x5A8, "CAutomobile: error"); -static_assert(offsetof(CAutomobile, m_aWheelDist) == 0x46C, "CAutomobile: error"); diff --git a/src/entities/Boat.cpp b/src/entities/Boat.cpp deleted file mode 100644 index 076a910e..00000000 --- a/src/entities/Boat.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "Boat.h" - -CBoat::CBoat(int mi, uint8 owner) -{ - ctor(mi, owner); -} - -WRAPPER CBoat* CBoat::ctor(int, uint8) { EAXJMP(0x53E3E0); } - -STARTPATCHES -InjectHook(0x53E790, &CBoat::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/Boat.h b/src/entities/Boat.h deleted file mode 100644 index 6d6482a4..00000000 --- a/src/entities/Boat.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Vehicle.h" - -class CBoat : public CVehicle -{ -public: - // 0x288 - uint8 stuff1[57]; - bool m_bIsAnchored; - uint8 stuff[450]; - - CBoat(int, uint8); - CBoat* ctor(int, uint8); - void dtor() { this->CBoat::~CBoat(); }; -}; -static_assert(sizeof(CBoat) == 0x484, "CBoat: error"); diff --git a/src/entities/CivilianPed.cpp b/src/entities/CivilianPed.cpp deleted file mode 100644 index a4881e71..00000000 --- a/src/entities/CivilianPed.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "CivilianPed.h" - -WRAPPER void CCivilianPed::ProcessControl(void) { EAXJMP(0x4BFFE0); } - -CCivilianPed::CCivilianPed(int pedtype, int mi) : CPed(pedtype) -{ - CPed::SetModelIndex(mi); - for (int i = 0; i < 10; i++) - { - m_nearPeds[i] = nil; - } -} - -STARTPATCHES - InjectHook(0x4BFF30, &CCivilianPed::ctor, PATCH_JUMP); - InjectHook(0x4BFFC0, &CCivilianPed::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/CivilianPed.h b/src/entities/CivilianPed.h deleted file mode 100644 index 8d004ad7..00000000 --- a/src/entities/CivilianPed.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Ped.h" - -class CCivilianPed : public CPed -{ -public: - CCivilianPed(int, int); - virtual ~CCivilianPed(void) { } - - virtual void ProcessControl(void); - - CCivilianPed *ctor(int pedtype, int mi) { return ::new (this) CCivilianPed(pedtype, mi); }; - void dtor(void) { this->CCivilianPed::~CCivilianPed(); } -}; -static_assert(sizeof(CCivilianPed) == 0x53C, "CCivilianPed: error"); diff --git a/src/entities/CopPed.cpp b/src/entities/CopPed.cpp deleted file mode 100644 index 041185ee..00000000 --- a/src/entities/CopPed.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "CopPed.h" - -CCopPed::~CCopPed() -{ - ClearPursuit(); -} - -WRAPPER void CCopPed::ClearPursuit(void) { EAXJMP(0x4C28C0); } - -STARTPATCHES - InjectHook(0x4C13E0, &CCopPed::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/CopPed.h b/src/entities/CopPed.h deleted file mode 100644 index b938dfc2..00000000 --- a/src/entities/CopPed.h +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once -#include "Ped.h" - -enum eCrimeType -{ - CRIME_NONE, - CRIME_POSSESSION_GUN, - CRIME_HIT_PED, - CRIME_HIT_COP, - CRIME_SHOOT_PED, - CRIME_SHOOT_COP, - CRIME_STEAL_CAR, - CRIME_RUN_REDLIGHT, - CRIME_RECKLESS_DRIVING, - CRIME_SPEEDING, - CRIME_RUNOVER_PED, - CRIME_RUNOVER_COP, - CRIME_SHOOT_HELI, - CRIME_PED_BURNED, - CRIME_COP_BURNED, - CRIME_VEHICLE_BURNED, - CRIME_DESTROYED_CESSNA, -}; - -enum eCopType -{ - COP_STREET = 0, - COP_FBI = 1, - COP_SWAT = 2, - COP_ARMY = 3, -}; - -class CCrime -{ -public: - eCrimeType m_eCrimeType; - CEntity *m_pVictim; - int32 m_nCrimeTime; - CVector m_vecCrimePos; - int8 m_bReported; - int8 m_bMultiplier; - int8 pad_20[2]; -}; - -class CCopPed : public CPed -{ -public: - int16 m_wRoadblockNode; - int8 field_1342; - int8 field_1343; - float m_fDistanceToTarget; - int8 m_bIsInPursuit; - int8 m_bIsDisabledCop; - int8 field_1350; - int8 field_1351; - int8 m_bZoneDisabledButClose; - int8 m_bZoneDisabled; - int8 field_1354; - int8 field_1355; - int32 field_1356; - eCopType m_nCopType; - int8 field_1364; - int8 field_1365; - int8 field_1366; - int8 field_1367; - - ~CCopPed(); - void dtor(void) { this->CCopPed::~CCopPed(); } - - void ClearPursuit(void); -}; - -static_assert(sizeof(CCopPed) == 0x558, "CCopPed: error"); diff --git a/src/entities/CutsceneHead.cpp b/src/entities/CutsceneHead.cpp deleted file mode 100644 index a9c47777..00000000 --- a/src/entities/CutsceneHead.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "common.h" -#include <rpskin.h> -#include "patcher.h" -#include "main.h" -#include "RwHelper.h" -#include "RpAnimBlend.h" -#include "AnimBlendClumpData.h" -#include "Directory.h" -#include "CutsceneMgr.h" -#include "Streaming.h" -#include "CutsceneHead.h" - - -CCutsceneHead::CCutsceneHead(CObject *obj) -{ - RpAtomic *atm; - - assert(RwObjectGetType(obj->m_rwObject) == rpCLUMP); - m_pHeadNode = RpAnimBlendClumpFindFrame((RpClump*)obj->m_rwObject, "Shead")->frame; - atm = (RpAtomic*)GetFirstObject(m_pHeadNode); - if(atm){ - assert(RwObjectGetType(atm) == rpATOMIC); - RpAtomicSetFlags(atm, RpAtomicGetFlags(atm) & ~rpATOMICRENDER); - } -} - -void -CCutsceneHead::CreateRwObject(void) -{ - RpAtomic *atm; - - CEntity::CreateRwObject(); - assert(RwObjectGetType(m_rwObject) == rpCLUMP); - atm = GetFirstAtomic((RpClump*)m_rwObject); - RpSkinAtomicSetHAnimHierarchy(atm, RpHAnimFrameGetHierarchy(GetFirstChild(RpClumpGetFrame((RpClump*)m_rwObject)))); -} - -void -CCutsceneHead::DeleteRwObject(void) -{ - CEntity::DeleteRwObject(); -} - -void -CCutsceneHead::ProcessControl(void) -{ - RpAtomic *atm; - RpHAnimHierarchy *hier; - - CPhysical::ProcessControl(); - - m_matrix.SetRotateY(PI/2); - m_matrix = CMatrix(RwFrameGetLTM(m_pHeadNode)) * m_matrix; - UpdateRwFrame(); - - assert(RwObjectGetType(m_rwObject) == rpCLUMP); - atm = GetFirstAtomic((RpClump*)m_rwObject); - hier = RpSkinAtomicGetHAnimHierarchy(atm); - RpHAnimHierarchyAddAnimTime(hier, CTimer::GetTimeStepNonClipped()/50.0f); -} - -void -CCutsceneHead::Render(void) -{ - RpAtomic *atm; - - m_matrix.SetRotateY(PI/2); - m_matrix = CMatrix(RwFrameGetLTM(m_pHeadNode)) * m_matrix; - UpdateRwFrame(); - - assert(RwObjectGetType(m_rwObject) == rpCLUMP); - atm = GetFirstAtomic((RpClump*)m_rwObject); - RpHAnimHierarchyUpdateMatrices(RpSkinAtomicGetHAnimHierarchy(atm)); - - CObject::Render(); -} - -void -CCutsceneHead::PlayAnimation(const char *animName) -{ - RpAtomic *atm; - RpHAnimHierarchy *hier; - RpHAnimAnimation *anim; - uint32 offset, size; - RwStream *stream; - - assert(RwObjectGetType(m_rwObject) == rpCLUMP); - atm = GetFirstAtomic((RpClump*)m_rwObject); - hier = RpSkinAtomicGetHAnimHierarchy(atm); - - sprintf(gString, "%s.anm", animName); - - if(CCutsceneMgr::ms_pCutsceneDir->FindItem(gString, offset, size)){ - stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, "ANIM\\CUTS.IMG"); - assert(stream); - - CStreaming::MakeSpaceFor(size*2048); - CStreaming::ImGonnaUseStreamingMemory(); - - RwStreamSkip(stream, offset*2048); - if(RwStreamFindChunk(stream, rwID_HANIMANIMATION, nil, nil)){ - anim = RpHAnimAnimationStreamRead(stream); - RpHAnimHierarchySetCurrentAnim(hier, anim); - } - - CStreaming::IHaveUsedStreamingMemory(); - - RwStreamClose(stream, nil); - } -} - -STARTPATCHES - InjectHook(0x4BA650, &CCutsceneHead::CreateRwObject_, PATCH_JUMP); - InjectHook(0x4BA690, &CCutsceneHead::DeleteRwObject_, PATCH_JUMP); - InjectHook(0x4BA760, &CCutsceneHead::ProcessControl_, PATCH_JUMP); - InjectHook(0x4BA800, &CCutsceneHead::Render_, PATCH_JUMP); - InjectHook(0x4BA6A0, &CCutsceneHead::PlayAnimation, PATCH_JUMP); -ENDPATCHES diff --git a/src/entities/CutsceneHead.h b/src/entities/CutsceneHead.h deleted file mode 100644 index de4f011f..00000000 --- a/src/entities/CutsceneHead.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "CutsceneObject.h" - -class CCutsceneHead : public CCutsceneObject -{ -public: - RwFrame *m_pHeadNode; - - CCutsceneHead(CObject *obj); - - void CreateRwObject(void); - void DeleteRwObject(void); - void ProcessControl(void); - void Render(void); - - void PlayAnimation(const char *animName); - - void CreateRwObject_(void) { CCutsceneHead::CreateRwObject(); } - void DeleteRwObject_(void) { CCutsceneHead::DeleteRwObject(); } - void ProcessControl_(void) { CCutsceneHead::ProcessControl(); } - void Render_(void) { CCutsceneHead::Render(); } -}; -static_assert(sizeof(CCutsceneHead) == 0x19C, "CCutsceneHead: error"); diff --git a/src/entities/CutsceneObject.cpp b/src/entities/CutsceneObject.cpp deleted file mode 100644 index ede5be5b..00000000 --- a/src/entities/CutsceneObject.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "main.h" -#include "Lights.h" -#include "PointLights.h" -#include "RpAnimBlend.h" -#include "AnimBlendClumpData.h" -#include "Renderer.h" -#include "ModelIndices.h" -#include "Shadows.h" -#include "Timecycle.h" -#include "CutsceneObject.h" - -CCutsceneObject::CCutsceneObject(void) -{ - m_status = STATUS_SIMPLE; - bUsesCollision = false; - bStreamingDontDelete = true; - ObjectCreatedBy = CUTSCENE_OBJECT; - m_fMass = 1.0f; - m_fTurnMass = 1.0f; -} - -void -CCutsceneObject::SetModelIndex(uint32 id) -{ - CEntity::SetModelIndex(id); - assert(RwObjectGetType(m_rwObject) == rpCLUMP); - RpAnimBlendClumpInit((RpClump*)m_rwObject); - (*RPANIMBLENDCLUMPDATA(m_rwObject))->velocity = &m_vecMoveSpeed; - (*RPANIMBLENDCLUMPDATA(m_rwObject))->frames[0].flag |= AnimBlendFrameData::VELOCITY_EXTRACTION_3D; -} - -void -CCutsceneObject::ProcessControl(void) -{ - CPhysical::ProcessControl(); - - if(CTimer::GetTimeStep() < 1/100.0f) - m_vecMoveSpeed *= 100.0f; - else - m_vecMoveSpeed *= 1.0f/CTimer::GetTimeStep(); - - ApplyMoveSpeed(); -} - -void -CCutsceneObject::PreRender(void) -{ - if(IsPedModel(GetModelIndex())) - CShadows::StoreShadowForPedObject(this, - CTimeCycle::m_fShadowDisplacementX[CTimeCycle::m_CurrentStoredValue], - CTimeCycle::m_fShadowDisplacementY[CTimeCycle::m_CurrentStoredValue], - CTimeCycle::m_fShadowFrontX[CTimeCycle::m_CurrentStoredValue], - CTimeCycle::m_fShadowFrontY[CTimeCycle::m_CurrentStoredValue], - CTimeCycle::m_fShadowSideX[CTimeCycle::m_CurrentStoredValue], - CTimeCycle::m_fShadowSideY[CTimeCycle::m_CurrentStoredValue]); -} - -void -CCutsceneObject::Render(void) -{ - CObject::Render(); -} - -bool -CCutsceneObject::SetupLighting(void) -{ - ActivateDirectional(); - SetAmbientColoursForPedsCarsAndObjects(); - - if(bRenderScorched){ - WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f); - }else{ - CVector coors = GetPosition(); - float lighting = CPointLights::GenerateLightsAffectingObject(&coors); - if(!bHasBlip && lighting != 1.0f){ - SetAmbientAndDirectionalColours(lighting); - return true; - } - } - - return false; -} - -void -CCutsceneObject::RemoveLighting(bool reset) -{ - CRenderer::RemoveVehiclePedLights(this, reset); -} - -STARTPATCHES - InjectHook(0x4BA960, &CCutsceneObject::dtor, PATCH_JUMP); - InjectHook(0x4BA980, &CCutsceneObject::SetModelIndex_, PATCH_JUMP); - InjectHook(0x4BA9C0, &CCutsceneObject::ProcessControl_, PATCH_JUMP); - InjectHook(0x4BAA40, &CCutsceneObject::PreRender_, PATCH_JUMP); - InjectHook(0x4BAAA0, &CCutsceneObject::Render_, PATCH_JUMP); - InjectHook(0x4A7E70, &CCutsceneObject::SetupLighting_, PATCH_JUMP); - InjectHook(0x4A7F00, &CCutsceneObject::RemoveLighting_, PATCH_JUMP); -ENDPATCHES diff --git a/src/entities/CutsceneObject.h b/src/entities/CutsceneObject.h deleted file mode 100644 index 9360651e..00000000 --- a/src/entities/CutsceneObject.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "Object.h" - -class CCutsceneObject : public CObject -{ -public: - CCutsceneObject(void); - - virtual void SetModelIndex(uint32 id); - virtual void ProcessControl(void); - virtual void PreRender(void); - virtual void Render(void); - virtual bool SetupLighting(void); - virtual void RemoveLighting(bool reset); - - void dtor(void) { this->CCutsceneObject::~CCutsceneObject(); } - void SetModelIndex_(uint32 id) { CCutsceneObject::SetModelIndex(id); } - void ProcessControl_(void) { CCutsceneObject::ProcessControl(); } - void PreRender_(void) { CCutsceneObject::PreRender(); } - void Render_(void) { CCutsceneObject::Render(); } - bool SetupLighting_(void) { return CCutsceneObject::SetupLighting(); } - void RemoveLighting_(bool reset) { CCutsceneObject::RemoveLighting(reset); } -}; -static_assert(sizeof(CCutsceneObject) == 0x198, "CCutsceneObject: error"); diff --git a/src/entities/DummyObject.cpp b/src/entities/DummyObject.cpp deleted file mode 100644 index 1e4b2ae0..00000000 --- a/src/entities/DummyObject.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "DummyObject.h" -#include "Pools.h" - -CDummyObject::CDummyObject(CObject *obj) -{ - SetModelIndexNoCreate(obj->GetModelIndex()); - if(obj->m_rwObject) - AttachToRwObject(obj->m_rwObject); - obj->DetachFromRwObject(); - m_level = obj->m_level; -} - -STARTPATCHES - InjectHook(0x4BAB70, &CDummyObject::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/DummyObject.h b/src/entities/DummyObject.h deleted file mode 100644 index 10554bdd..00000000 --- a/src/entities/DummyObject.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "Dummy.h" - -class CObject; - -class CDummyObject : public CDummy -{ -public: - CDummyObject(void) {} - CDummyObject(CObject *obj); - void dtor(void) { this->CDummyObject::~CDummyObject(); } -}; -static_assert(sizeof(CDummyObject) == 0x68, "CDummyObject: error"); diff --git a/src/entities/DummyPed.h b/src/entities/DummyPed.h deleted file mode 100644 index af633dc4..00000000 --- a/src/entities/DummyPed.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "Dummy.h" - -// actually unused -class CDummyPed : CDummy -{ - int32 pedType; - int32 unknown; -}; -static_assert(sizeof(CDummyPed) == 0x70, "CDummyPed: error"); diff --git a/src/entities/EmergencyPed.cpp b/src/entities/EmergencyPed.cpp deleted file mode 100644 index 7b847896..00000000 --- a/src/entities/EmergencyPed.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "EmergencyPed.h" - -STARTPATCHES -InjectHook(0x4C2EF0, &CEmergencyPed::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/EmergencyPed.h b/src/entities/EmergencyPed.h deleted file mode 100644 index fa07f3ee..00000000 --- a/src/entities/EmergencyPed.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Ped.h" - -class CEmergencyPed : public CPed -{ -public: - // 0x53C - uint8 stuff[24]; - - void dtor(void) { this->CEmergencyPed::~CEmergencyPed(); } -}; -static_assert(sizeof(CEmergencyPed) == 0x554, "CEmergencyPed: error"); diff --git a/src/entities/Heli.cpp b/src/entities/Heli.cpp deleted file mode 100644 index 01ee5375..00000000 --- a/src/entities/Heli.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "Heli.h" - -CHeli::CHeli(int mi, uint8 owner) -{ - ctor(mi, owner); -} - -WRAPPER CHeli* CHeli::ctor(int, uint8) { EAXJMP(0x547220); } -WRAPPER void CHeli::SpecialHeliPreRender(void) { EAXJMP(0x54AE10); } - -STARTPATCHES -InjectHook(0x5474A0, &CHeli::dtor, PATCH_JUMP); -ENDPATCHES diff --git a/src/entities/Heli.h b/src/entities/Heli.h deleted file mode 100644 index da7bb171..00000000 --- a/src/entities/Heli.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Vehicle.h" - -class CHeli : public CVehicle -{ -public: - // 0x288 - uint8 stuff[180]; - - CHeli(int, uint8); - CHeli* ctor(int, uint8); - void dtor(void) { this->CHeli::~CHeli(); } - - static void SpecialHeliPreRender(void); -}; -static_assert(sizeof(CHeli) == 0x33C, "CHeli: error"); diff --git a/src/entities/Object.cpp b/src/entities/Object.cpp deleted file mode 100644 index 6712d77b..00000000 --- a/src/entities/Object.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "main.h" -#include "Lights.h" -#include "Pools.h" -#include "Radar.h" -#include "Object.h" - -WRAPPER void CObject::ObjectDamage(float amount) { EAXJMP(0x4BB240); } - -int16 &CObject::nNoTempObjects = *(int16*)0x95CCA2; - -void *CObject::operator new(size_t sz) { return CPools::GetObjectPool()->New(); } -void CObject::operator delete(void *p, size_t sz) { CPools::GetObjectPool()->Delete((CObject*)p); } - -CObject::CObject(void) -{ - m_type = ENTITY_TYPE_OBJECT; - m_fUprootLimit = 0.0f; - m_nCollisionDamageEffect = 0; - m_nSpecialCollisionResponseCases = COLLRESPONSE_NONE; - m_bCameraToAvoidThisObject = false; - ObjectCreatedBy = 0; - m_nEndOfLifeTime = 0; -// m_nRefModelIndex = -1; // duplicate -// bUseVehicleColours = false; // duplicate - m_colour2 = 0; - m_colour1 = m_colour2; - field_172 = 0; - bIsPickup = false; - m_obj_flag2 = false; - m_obj_flag4 = false; - m_obj_flag8 = false; - m_obj_flag10 = false; - bHasBeenDamaged = false; - m_nRefModelIndex = -1; - bUseVehicleColours = false; - m_pCurSurface = nil; - m_pCollidingEntity = nil; -} - -CObject::~CObject(void) -{ - CRadar::ClearBlipForEntity(BLIP_OBJECT, CPools::GetObjectPool()->GetIndex(this)); - - if(m_nRefModelIndex != -1) - CModelInfo::GetModelInfo(m_nRefModelIndex)->RemoveRef(); - - if(ObjectCreatedBy == TEMP_OBJECT && nNoTempObjects != 0) - nNoTempObjects--; -} - -void -CObject::Render(void) -{ - if(m_flagD80) - return; - - if(m_nRefModelIndex != -1 && ObjectCreatedBy == TEMP_OBJECT && bUseVehicleColours){ - CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(m_nRefModelIndex); - assert(mi->m_type == MITYPE_VEHICLE); - mi->SetVehicleColour(m_colour1, m_colour2); - } - - CEntity::Render(); -} - -bool -CObject::SetupLighting(void) -{ - DeActivateDirectional(); - SetAmbientColours(); - - if(bRenderScorched){ - WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f); - return true; - } - return false; -} - -void -CObject::RemoveLighting(bool reset) -{ - if(reset) - WorldReplaceScorchedLightsWithNormal(Scene.world); -} - -WRAPPER void CObject::DeleteAllTempObjectInArea(CVector, float) { EAXJMP(0x4BBED0); } - -STARTPATCHES - InjectHook(0x4BAE00, &CObject::dtor, PATCH_JUMP); - InjectHook(0x4BB1E0, &CObject::Render_, PATCH_JUMP); -ENDPATCHES diff --git a/src/entities/Object.h b/src/entities/Object.h deleted file mode 100644 index de4c8e05..00000000 --- a/src/entities/Object.h +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include "Physical.h" - -enum { - GAME_OBJECT = 1, - MISSION_OBJECT = 2, - TEMP_OBJECT = 3, - CUTSCENE_OBJECT = 4, -}; - -enum { - COLLRESPONSE_NONE, - COLLRESPONSE_CHANGE_MODEL, - COLLRESPONSE_SPLIT_MODEL, - COLLRESPONSE_SMASH_COMPLETELY, - COLLRESPONSE_CHANGE_THEN_SMASH, - COLLRESPONSE_UNKNOWN5, - - COLLRESPONSE_SMASH_CARDBOARD_COMPLETELY = 50, - COLLRESPONSE_SMASH_WOODENBOX_COMPLETELY = 60, - COLLRESPONSE_SMASH_TRAFFICCONE_COMPLETELY = 70, - COLLRESPONSE_SMASH_BARPOST_COMPLETELY = 80, - -}; - -class CVehicle; - -class CObject : public CPhysical -{ -public: - CMatrix m_objectMatrix; - float m_fUprootLimit; - int8 ObjectCreatedBy; - int8 bIsPickup : 1; - int8 m_obj_flag2 : 1; - int8 m_obj_flag4 : 1; - int8 m_obj_flag8 : 1; - int8 m_obj_flag10 : 1; - int8 bHasBeenDamaged : 1; - int8 bUseVehicleColours : 1; - int8 m_obj_flag80 : 1; - int8 field_172; - int8 field_173; - float m_fCollisionDamageMultiplier; - uint8 m_nCollisionDamageEffect; - uint8 m_nSpecialCollisionResponseCases; - bool m_bCameraToAvoidThisObject; - int8 field_17B; - int8 field_17C; - int8 field_17D; - int8 field_17E; - int8 field_17F; - int32 m_nEndOfLifeTime; - int16 m_nRefModelIndex; - int8 field_186; - int8 field_187; - CEntity *m_pCurSurface; - CEntity *m_pCollidingEntity; - int8 m_colour1, m_colour2; - - static int16 &nNoTempObjects; - - static void *operator new(size_t); - static void operator delete(void*, size_t); - - CObject(void); - ~CObject(void); - - void Render(void); - bool SetupLighting(void); - void RemoveLighting(bool reset); - - void ObjectDamage(float amount); - - static void DeleteAllTempObjectInArea(CVector, float); - - void dtor(void) { this->CObject::~CObject(); } - void Render_(void) { CObject::Render(); } -}; -static_assert(sizeof(CObject) == 0x198, "CObject: error"); diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp deleted file mode 100644 index 055ea3fb..00000000 --- a/src/entities/Ped.cpp +++ /dev/null @@ -1,2949 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "main.h" -#include "Pools.h" -#include "Particle.h" -#include "Stats.h" -#include "World.h" -#include "DMAudio.h" -#include "RpAnimBlend.h" -#include "Ped.h" -#include "PlayerPed.h" -#include "General.h" -#include "VisibilityPlugins.h" -#include "AudioManager.h" -#include "HandlingMgr.h" -#include "Replay.h" -#include "PedPlacement.h" -#include "Shadows.h" -#include "Weather.h" -#include "CullZones.h" -#include "Population.h" -#include "Renderer.h" -#include "Lights.h" -#include "PointLights.h" -#include "Pad.h" - -WRAPPER void CPed::KillPedWithCar(CVehicle *veh, float impulse) { EAXJMP(0x4EC430); } -WRAPPER void CPed::Say(uint16 audio) { EAXJMP(0x4E5A10); } -WRAPPER void CPed::SetDie(AnimationId anim, float arg1, float arg2) { EAXJMP(0x4D37D0); } -WRAPPER void CPed::SpawnFlyingComponent(int, int8) { EAXJMP(0x4EB060); } -WRAPPER void CPed::RestorePreviousState(void) { EAXJMP(0x4C5E30); } -WRAPPER void CPed::ClearAttack(void) { EAXJMP(0x4E6790); } -WRAPPER void CPed::PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *dragAssoc, void *arg) { EAXJMP(0x4E2480); } -WRAPPER void CPed::PedSetDraggedOutCarPositionCB(CAnimBlendAssociation *dragAssoc, void *arg) { EAXJMP(0x4E2920); } -WRAPPER void CPed::SetPedPositionInCar(void) { EAXJMP(0x4D4970); } -WRAPPER void CPed::ProcessControl(void) { EAXJMP(0x4C8910); } -WRAPPER void CPed::PreRender(void) { EAXJMP(0x4CFDD0); } -WRAPPER void CPed::Render(void) { EAXJMP(0x4D03F0); } -WRAPPER int32 CPed::ProcessEntityCollision(CEntity*, CColPoint*) { EAXJMP(0x4CBB30); } -WRAPPER void CPed::SetMoveAnim(void) { EAXJMP(0x4C5A40); } -WRAPPER void CPed::SetFollowRoute(int16, int16) { EAXJMP(0x4DD690); } -WRAPPER void CPed::SetDuck(uint32) { EAXJMP(0x4E4920); } -WRAPPER void CPed::RegisterThreatWithGangPeds(CEntity*) { EAXJMP(0x4E3870); } - -bool &CPed::bNastyLimbsCheat = *(bool*)0x95CD44; -bool &CPed::bPedCheat2 = *(bool*)0x95CD5A; -bool &CPed::bPedCheat3 = *(bool*)0x95CD59; - -uint16 &CPed::distanceMultToCountPedNear = *(uint16*)0x5F8C98; - -CVector &CPed::offsetToOpenRegularCarDoor = *(CVector*)0x62E030; -CVector &CPed::offsetToOpenLowCarDoor = *(CVector*)0x62E03C; -CVector &CPed::offsetToOpenVanDoor = *(CVector*)0x62E048; - -void *CPed::operator new(size_t sz) { return CPools::GetPedPool()->New(); } -void *CPed::operator new(size_t sz, int handle) { return CPools::GetPedPool()->New(handle); } -void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); } -void CPed::operator delete(void *p, int handle) { CPools::GetPedPool()->Delete((CPed*)p); } - -CPed::~CPed(void) -{ - CWorld::Remove(this); - CRadar::ClearBlipForEntity(BLIP_CHAR, CPools::GetPedPool()->GetIndex(this)); - if (bInVehicle && m_pMyVehicle){ - uint8 door_flag = GetVehEnterExitFlag(m_vehEnterType); - if (m_pMyVehicle->pDriver == this) - m_pMyVehicle->pDriver = nil; - else { - for (int i = 0; i < m_pMyVehicle->m_nNumMaxPassengers; i++) { - if (m_pMyVehicle->pPassengers[i] == this) - m_pMyVehicle->pPassengers[i] = nil; - } - } - if (m_nPedState == PED_EXIT_CAR || m_nPedState == PED_DRAG_FROM_CAR) - m_pMyVehicle->m_nGettingOutFlags &= ~door_flag; - bInVehicle = false; - m_pMyVehicle = nil; - }else if (m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK){ - QuitEnteringCar(); - } - if (m_pFire) - m_pFire->Extinguish(); - CPopulation::UpdatePedCount(m_nPedType, true); - DMAudio.DestroyEntity(m_audioEntityId); -} - -void -CPed::FlagToDestroyWhenNextProcessed(void) -{ - bRemoveFromWorld = true; - if (!bInVehicle || !m_pMyVehicle) - return; - if (m_pMyVehicle->pDriver == this){ - m_pMyVehicle->pDriver = nil; - if (IsPlayer() && m_pMyVehicle->m_status != STATUS_WRECKED) - m_pMyVehicle->m_status = STATUS_ABANDONED; - }else{ - m_pMyVehicle->RemovePassenger(this); - } - bInVehicle = false; - m_pMyVehicle = nil; - if (CharCreatedBy == MISSION_CHAR) - m_nPedState = PED_DEAD; - else - m_nPedState = PED_NONE; - m_pVehicleAnim = nil; -} - -static char ObjectiveText[34][28] = { - "No Obj", - "Wait on Foot", - "Flee on Foot Till Safe", - "Guard Spot", - "Guard Area", - "Wait in Car", - "Wait in Car then Getout", - "Kill Char on Foot", - "Kill Char Any Means", - "Flee Char on Foot Till Safe", - "Flee Char on Foot Always", - "GoTo Char on Foot", - "Follow Char in Formation", - "Leave Car", - "Enter Car as Passenger", - "Enter Car as Driver", - "Follow Car in Car", - "Fire at Obj from Vehicle", - "Destroy Obj", - "Destroy Car", - "GoTo Area Any Means", - "GoTo Area on Foot", - "Run to Area", - "GoTo Area in Car", - "Follow Car on Foot Woffset", - "Guard Attack", - "Set Leader", - "Follow Route", - "Solicit", - "Take Taxi", - "Catch Train", - "Buy IceCream", - "Steal Any Car", - "Mug Char", -}; - -static char StateText[56][18] = { - "None", // 1 - "Idle", - "Look Entity", - "Look Heading", - "Wander Range", - "Wander Path", - "Seek Pos", - "Seek Entity", - "Flee Pos", - "Flee Entity", - "Pursue", - "Follow Path", - "Sniper Mode", - "Rocket Mode", - "Dummy", - "Pause", - "Attack", - "Fight", - "Face Phone", - "Make Call", - "Chat", - "Mug", - "AimGun", - "AI Control", - "Seek Car", - "Seek InBoat", - "Follow Route", - "C.P.R.", - "Solicit", - "Buy IceCream", - "Investigate", - "Step away", - "STATES_NO_AI", - "On Fire", - "Jump", - "Fall", - "GetUp", - "Stagger", - "Dive away", - "STATES_NO_ST", - "Enter Train", - "Exit Train", - "Arrest Plyr", - "Driving", - "Passenger", - "Taxi Passngr", - "Open Door", - "Die", - "Dead", - "CarJack", - "Drag fm Car", - "Enter Car", - "Steal Car", - "Exit Car", - "Hands Up", - "Arrested", -}; - -static char PersonalityTypeText[32][18] = { - "Player", - "Cop", - "Medic", - "Fireman", - "Gang 1", - "Gang 2", - "Gang 3", - "Gang 4", - "Gang 5", - "Gang 6", - "Gang 7", - "Street Guy", - "Suit Guy", - "Sensible Guy", - "Geek Guy", - "Old Guy", - "Tough Guy", - "Street Girl", - "Suit Girl", - "Sensible Girl", - "Geek Girl", - "Old Girl", - "Tough Girl", - "Tramp", - "Tourist", - "Prostitute", - "Criminal", - "Busker", - "Taxi Driver", - "Psycho", - "Steward", - "Sports Fan", -}; - -static char WaitStateText[21][16] = { - "No Wait", - "Traffic Lights", - "Pause CrossRoad", - "Look CrossRoad", - "Look Ped", - "Look Shop", - "Look Accident", - "FaceOff Gang", - "Double Back", - "Hit Wall", - "Turn 180deg", - "Surprised", - "Ped Stuck", - "Look About", - "Play Duck", - "Play Cower", - "Play Taxi", - "Play HandsUp", - "Play HandsCower", - "Play Chat", - "Finish Flee", -}; - -CPed::CPed(uint32 pedType) : m_pedIK(this) -{ - m_type = ENTITY_TYPE_PED; - bPedPhysics = true; - bUseCollisionRecords = true; - - m_vecAnimMoveDelta.x = 0.0; - m_vecAnimMoveDelta.y = 0.0; - m_fHealth = 100.0f; - m_fArmour = 0.0f; - m_nPedType = pedType; - field_520 = 0; - m_talkTimer = 0; - m_talkTypeLast = 167; - m_talkType = 167; - m_objective = OBJECTIVE_NONE; - m_prevObjective = OBJECTIVE_NONE; - CharCreatedBy = RANDOM_CHAR; - m_leader = nil; - m_pedInObjective = nil; - m_carInObjective = nil; - bInVehicle = 0; - m_pMyVehicle = nil; - m_pVehicleAnim = nil; - m_vecOffsetSeek.x = 0.0; - m_vecOffsetSeek.y = 0.0; - m_vecOffsetSeek.z = 0.0; - m_pedFormation = 0; - m_lastThreatTimer = 0; - m_nPedStateTimer = 0; - m_actionX = 0; - m_actionY = 0; - m_phoneTalkTimer = 0; - m_stateUnused = 0; - m_leaveCarTimer = 0; - m_getUpTimer = 0; - m_attackTimer = 0; - m_timerUnused = 0; - m_lookTimer = 0; - m_standardTimer = 0; - m_lastHitTime = 0; - m_hitRecoverTimer = 0; - field_4E8 = 0; - m_moved = CVector2D(0.0f, 0.0f); - m_fRotationCur = 0.0f; - m_headingRate = 15.0f; - m_fRotationDest = 0.0f; - m_vehEnterType = VEHICLE_ENTER_FRONT_LEFT; - m_walkAroundType = 0; - m_pCurrentPhysSurface = nil; - m_vecOffsetFromPhysSurface = CVector(0.0f, 0.0f, 0.0f); - m_pSeekTarget = nil; - m_vecSeekVehicle = CVector(0.0f, 0.0f, 0.0f); - m_wepSkills = 0; - field_318 = 1.0f; - field_31C = 0; - m_phoneId = -1; - m_lastAccident = 0; - m_fleeFrom = nil; - m_fleeFromPosX = 0; - m_fleeFromPosY = 0; - m_fleeTimer = 0; - m_vecSeekPosEx = CVector(0.0f, 0.0f, 0.0f); - m_seekExAngle = 0.0f; - m_nWaitState = WAITSTATE_FALSE; - m_nWaitTimer = 0; - m_pCollidingEntity = nil; - m_nPedState = PED_IDLE; - m_nLastPedState = PED_NONE; - m_nMoveState = PEDMOVE_STILL; - m_nStoredActionState = 0; - m_pFire = nil; - m_pPointGunAt = nil; - m_pLookTarget = nil; - m_fLookDirection = 0.0f; - m_pCurSurface = nil; - m_targetUnused = nil; - m_nPathNodes = 0; - m_nCurPathNode = 0; - m_nPathState = 0; - m_pNextPathNode = nil; - m_pLastPathNode = nil; - m_routeLastPoint = -1; - m_routePoints = 0; - m_routePos = 0; - m_routeType = 0; - m_bodyPartBleeding = -1; - - m_fMass = 70.0f; - m_fTurnMass = 100.0f; - m_fAirResistance = 0.4f / m_fMass; - m_fElasticity = 0.05f; - - bIsStanding = false; - m_ped_flagA2 = false; - m_ped_flagA4 = false; - bIsPointingGunAt = false; - bIsLooking = false; - m_ped_flagA20 = false; - bIsRestoringLook = false; - bIsAimingGun = false; - - bIsRestoringGun = false; - bCanPointGunAtTarget = false; - bIsTalking = false; - bIsInTheAir = false; - bIsLanding = false; - m_ped_flagB20 = false; - m_ped_flagB40 = false; - m_ped_flagB80 = false; - - m_ped_flagC1 = false; - bRespondsToThreats = true; - m_ped_flagC4 = true; - m_ped_flagC8 = false; - m_ped_flagC10 = false; - m_ped_flagC20 = false; - m_ped_flagC40 = false; - m_ped_flagC80 = false; - - m_ped_flagD1 = false; - m_ped_flagD2 = false; - m_ped_flagD4 = false; - m_ped_flagD8 = false; - m_ped_flagD10 = false; - m_ped_flagD20 = false; - m_ped_flagD40 = false; - m_ped_flagD80 = false; - - m_ped_flagE1 = false; - m_ped_flagE2 = false; - bNotAllowedToDuck = false; - bCrouchWhenShooting = false; - bIsDucking = false; - m_ped_flagE20 = false; - bDoBloodyFootprints = false; - m_ped_flagE80 = false; - - m_ped_flagF1 = false; - m_ped_flagF2 = false; - m_ped_flagF4 = false; - m_ped_flagF8 = false; - m_ped_flagF10 = false; - m_ped_flagF20 = false; - m_ped_flagF40 = false; - m_ped_flagF80 = false; - - m_ped_flagG1 = false; - m_ped_flagG2 = true; - m_ped_flagG4 = false; - m_ped_flagG8 = false; - m_ped_flagG10 = false; - m_ped_flagG20 = false; - m_ped_flagG40 = false; - m_ped_flagG80 = false; - - m_ped_flagH1 = false; - m_ped_flagH2 = false; - m_ped_flagH4 = false; - m_ped_flagH8 = false; - m_ped_flagH10 = false; - m_ped_flagH20 = false; - m_ped_flagH40 = false; - m_ped_flagH80 = false; - - m_ped_flagI1 = false; - m_ped_flagI2 = false; - m_ped_flagI4 = false; - bRecordedForReplay = false; - m_ped_flagI10 = false; -#ifdef KANGAROO_CHEAT - m_ped_flagI80 = false; -#endif - - if ((CGeneral::GetRandomNumber() & 3) == 0) - m_ped_flagD1 = true; - - m_audioEntityId = DMAudio.CreateEntity(0, this); - DMAudio.SetEntityStatus(m_audioEntityId, 1); - m_fearFlags = CPedType::GetThreats(m_nPedType); - m_threatEntity = nil; - m_eventOrThread = CVector2D(0.0f, 0.0f); - m_pEventEntity = nil; - m_fAngleToEvent = 0.0f; - m_numNearPeds = 0; - - for (int i = 0; i < 10; i++) - { - m_nearPeds[i] = nil; - if (i < 8) { - m_pPathNodesStates[i] = nil; - } - } - m_maxWeaponTypeAllowed = 0; - m_currentWeapon = 0; - m_storedWeapon = NO_STORED_WEAPON; - - for(int i = 0; i < NUM_PED_WEAPONTYPES; i++) - { - CWeapon &weapon = GetWeapon(i); - weapon.m_eWeaponType = WEAPONTYPE_UNARMED; - weapon.m_eWeaponState = WEAPONSTATE_READY; - weapon.m_nAmmoInClip = 0; - weapon.m_nAmmoTotal = 0; - weapon.m_nTimer = 0; - } - - m_lastHitState = 0; - GiveWeapon(WEAPONTYPE_UNARMED, 0); - m_wepAccuracy = 60; - m_lastWepDam = -1; - m_collPoly.valid = false; - m_fCollisionSpeed = 0.0f; - m_wepModelID = -1; - CPopulation::UpdatePedCount(m_nPedType, false); -} - -uint32 -CPed::GiveWeapon(eWeaponType weaponType, uint32 ammo) -{ - CWeapon &weapon = GetWeapon(weaponType); - - if (HasWeapon(weaponType)) { - if (weapon.m_nAmmoTotal + ammo > 99999) - weapon.m_nAmmoTotal = 99999; - else - weapon.m_nAmmoTotal += ammo; - - weapon.Reload(); - } else { - weapon.Initialise(weaponType, ammo); - // TODO: It seems game uses this as both weapon count and max WeaponType we have, which is ofcourse erroneous. - m_maxWeaponTypeAllowed++; - } - if (weapon.m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO) - weapon.m_eWeaponState = WEAPONSTATE_READY; - - return weaponType; -} - -static RwObject* -RemoveAllModelCB(RwObject *object, void *data) -{ - RpAtomic *atomic = (RpAtomic*)object; - if (CVisibilityPlugins::GetAtomicModelInfo(atomic)) { - RpClumpRemoveAtomic(atomic->clump, atomic); - RpAtomicDestroy(atomic); - } - return object; -} - -static PedOnGroundState -CheckForPedsOnGroundToAttack(CPlayerPed *player, CPed **pedOnGround) -{ - PedOnGroundState stateToReturn; - float angleToFace; - CPed *currentPed = nil; - PedState currentPedState; - CPed *pedOnTheFloor = nil; - CPed *deadPed = nil; - CPed *pedBelow = nil; - bool foundDead = false; - bool foundOnTheFloor = false; - bool foundBelow = false; - float angleDiff; - float distance; - - if (!CGame::nastyGame) - return NO_PED; - - for (int currentPedId = 0; currentPedId < player->m_numNearPeds; currentPedId++) { - - currentPed = player->m_nearPeds[currentPedId]; - - CVector posDifference = currentPed->GetPosition() - player->GetPosition(); - distance = posDifference.Magnitude(); - - if (distance < 2.0f) { - angleToFace = CGeneral::GetRadianAngleBetweenPoints( - currentPed->GetPosition().x, currentPed->GetPosition().y, - player->GetPosition().x, player->GetPosition().y); - - angleToFace = CGeneral::LimitRadianAngle(angleToFace); - player->m_fRotationCur = CGeneral::LimitRadianAngle(player->m_fRotationCur); - - angleDiff = fabs(angleToFace - player->m_fRotationCur); - - if (angleDiff > PI) - angleDiff = 2 * PI - angleDiff; - - currentPedState = currentPed->m_nPedState; - - if (currentPedState == PED_FALL || currentPedState == PED_GETUP || currentPedState == PED_DIE || currentPedState == PED_DEAD) { - if (distance < 2.0f && angleDiff < DEGTORAD(65.0f)) { - if (currentPedState == PED_DEAD) { - foundDead = 1; - if (!deadPed) - deadPed = currentPed; - } else if (!currentPed->IsPedHeadAbovePos(-0.6f)) { - foundOnTheFloor = 1; - if (!pedOnTheFloor) - pedOnTheFloor = currentPed; - } - } - } else if ((distance >= 0.8f || angleDiff >= DEGTORAD(75.0f)) - && (distance >= 1.3f || angleDiff >= DEGTORAD(55.0f)) - && (distance >= 1.7f || angleDiff >= DEGTORAD(35.0f)) - && (distance >= 2.0f || angleDiff >= DEGTORAD(30.0f))) { - - if (angleDiff < DEGTORAD(75.0f)) { - foundBelow = 1; - if (!pedBelow) - pedBelow = currentPed; - } - } else { - foundBelow = 1; - pedBelow = currentPed; - break; - } - } - } - - if (foundOnTheFloor) { - currentPed = pedOnTheFloor; - stateToReturn = PED_ON_THE_FLOOR; - } else if (foundDead) { - currentPed = deadPed; - stateToReturn = PED_DEAD_ON_THE_FLOOR; - } else if (foundBelow) { - currentPed = pedBelow; - stateToReturn = PED_BELOW_PLAYER; - } else { - currentPed = nil; - stateToReturn = NO_PED; - } - - if (pedOnGround) - * pedOnGround = currentPed; - - return stateToReturn; -} - -bool -CPed::IsPlayer(void) -{ - return m_nPedType == PEDTYPE_PLAYER1 || m_nPedType== PEDTYPE_PLAYER2 || - m_nPedType == PEDTYPE_PLAYER3 || m_nPedType == PEDTYPE_PLAYER4; -} - -bool -CPed::UseGroundColModel(void) -{ - return m_nPedState == PED_FALL || - m_nPedState == PED_DIVE_AWAY || - m_nPedState == PED_DIE || - m_nPedState == PED_DEAD; -} - -bool -CPed::CanSetPedState(void) -{ - return m_nPedState != PED_DIE && m_nPedState != PED_ARRESTED && - m_nPedState != PED_ENTER_CAR && m_nPedState != PED_DEAD && m_nPedState != PED_CARJACK && m_nPedState != PED_STEAL_CAR; -} - -bool -CPed::IsPedInControl(void) -{ - return m_nPedState <= PED_STATES_NO_AI - && !bIsInTheAir && !bIsLanding - && m_fHealth > 0.0f; -} - -bool -CPed::CanStrafeOrMouseControl(void) -{ - return m_nPedState == PED_NONE || m_nPedState == PED_IDLE || m_nPedState == PED_FLEE_POS || m_nPedState == PED_FLEE_ENTITY || - m_nPedState == PED_ATTACK || m_nPedState == PED_FIGHT || m_nPedState == PED_AIM_GUN || m_nPedState == PED_JUMP; -} - -void -CPed::AddWeaponModel(int id) -{ - RpAtomic *atm; - - if (id != -1) { - atm = (RpAtomic*)CModelInfo::GetModelInfo(id)->CreateInstance(); - RwFrameDestroy(RpAtomicGetFrame(atm)); - RpAtomicSetFrame(atm, GetNodeFrame(PED_HANDR)); - RpClumpAddAtomic((RpClump*)m_rwObject, atm); - m_wepModelID = id; - } -} - -void -CPed::AimGun(void) -{ - RwV3d pos; - CVector vector; - - if (m_pSeekTarget) { - if (m_pSeekTarget->IsPed()) { - ((CPed*)m_pSeekTarget)->m_pedIK.GetComponentPosition(&pos, PED_TORSO); - vector.x = pos.x; - vector.y = pos.y; - vector.z = pos.z; - } else { - vector = *(m_pSeekTarget->GetPosition()); - } - Say(SOUND_PED_ATTACK); - - bCanPointGunAtTarget = m_pedIK.PointGunAtPosition(&vector); - if (m_pLookTarget != m_pSeekTarget) { - SetLookFlag(m_pSeekTarget, 1); - } - - } else { - if (IsPlayer()) { - bCanPointGunAtTarget = m_pedIK.PointGunInDirection(m_fLookDirection, ((CPlayerPed*)this)->m_fFPSMoveHeading); - } else { - bCanPointGunAtTarget = m_pedIK.PointGunInDirection(m_fLookDirection, 0.0f); - } - } -} - -void -CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer) -{ - CVector pos2 = CVector( - pos.x, - pos.y, - pos.z + 0.1f - ); - - if (!CPed::IsPlayer() || evenOnPlayer) { - ++CStats::HeadShots; - - // BUG: This condition will always return true. - if (m_nPedState != PED_PASSENGER || m_nPedState != PED_TAXI_PASSENGER) { - CPed::SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); - } - - m_ped_flagC20 = true; - m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 150; - - CParticle::AddParticle(PARTICLE_TEST, pos2, - CVector(0.0f, 0.0f, 0.0f), nil, 0.2f, 0, 0, 0, 0); - - if (CEntity::GetIsOnScreen()) { - for(int i=0; i < 32; i++) { - CParticle::AddParticle(PARTICLE_BLOOD_SMALL, - pos2, CVector(0.0f, 0.0f, 0.03f), - nil, 0.0f, 0, 0, 0, 0); - } - - for (int i = 0; i < 16; i++) { - CParticle::AddParticle(PARTICLE_DEBRIS2, - pos2, - CVector(0.0f, 0.0f, 0.01f), - nil, 0.0f, 0, 0, 0, 0); - } - } - } -} - -void -CPed::RemoveBodyPart(PedNode nodeId, int8 unk) -{ - RwFrame *frame; - RwV3d pos; - - frame = GetNodeFrame(nodeId); - if (frame) { - if (CGame::nastyGame) { - if (nodeId != PED_HEAD) - CPed::SpawnFlyingComponent(nodeId, unk); - - RecurseFrameChildrenVisibilityCB(frame, nil); - pos.x = 0.0f; - pos.y = 0.0f; - pos.z = 0.0f; - - for (frame = RwFrameGetParent(frame); frame; frame = RwFrameGetParent(frame)) - RwV3dTransformPoints(&pos, &pos, 1, RwFrameGetMatrix(frame)); - - if (CEntity::GetIsOnScreen()) { - CParticle::AddParticle(PARTICLE_TEST, pos, - CVector(0.0f, 0.0f, 0.0f), - nil, 0.2f, 0, 0, 0, 0); - - for (int i = 0; i < 16; i++) { - CParticle::AddParticle(PARTICLE_BLOOD_SMALL, - pos, - CVector(0.0f, 0.0f, 0.03f), - nil, 0.0f, 0, 0, 0, 0); - } - } - m_ped_flagC20 = true; - m_bodyPartBleeding = nodeId; - } - } else { - printf("Trying to remove ped component"); - } -} - -RwObject* -CPed::SetPedAtomicVisibilityCB(RwObject *object, void *data) -{ - if (data == nil) - RpAtomicSetFlags(object, 0); - return object; -} - -RwFrame* -CPed::RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data) -{ - RwFrameForAllObjects(frame, SetPedAtomicVisibilityCB, data); - RwFrameForAllChildren(frame, RecurseFrameChildrenVisibilityCB, nil); - return frame; -} - -void -CPed::SetLookFlag(CEntity *target, bool unknown) -{ - if (m_lookTimer < CTimer::GetTimeInMilliseconds()) { - bIsLooking = true; - bIsRestoringLook = false; - m_pLookTarget = target; - m_pLookTarget->RegisterReference((CEntity**)&m_pLookTarget); - m_fLookDirection = 999999.0f; - m_lookTimer = 0; - m_ped_flagA20 = unknown; - if (m_nPedState != PED_DRIVING) { - m_pedIK.m_flags &= ~CPedIK::FLAG_2; - } - } -} - -void -CPed::SetLookFlag(float direction, bool unknown) -{ - if (m_lookTimer < CTimer::GetTimeInMilliseconds()) { - bIsLooking = true; - bIsRestoringLook = false; - m_pLookTarget = nil; - m_fLookDirection = direction; - m_lookTimer = 0; - m_ped_flagA20 = unknown; - if (m_nPedState != PED_DRIVING) { - m_pedIK.m_flags &= ~CPedIK::FLAG_2; - } - } -} - -void -CPed::SetLookTimer(int time) -{ - if (CTimer::GetTimeInMilliseconds() > m_lookTimer) { - m_lookTimer = CTimer::GetTimeInMilliseconds() + time; - } -} - -bool -CPed::OurPedCanSeeThisOne(CEntity *target) -{ - CColPoint colpoint; - CEntity *ent; - - CVector2D dist = CVector2D(target->GetPosition()) - CVector2D(this->GetPosition()); - - // Check if target is behind ped - if (DotProduct2D(dist, CVector2D(this->GetForward())) < 0.0f) - return false; - - // Check if target is too far away - if (dist.Magnitude() >= 40.0f) - return false; - - // Check line of sight from head - CVector headPos = this->GetPosition(); - headPos.z += 1.0f; - return !CWorld::ProcessLineOfSight(headPos, target->GetPosition(), colpoint, ent, true, false, false, false, false, false); -} - -void -CPed::Avoid(void) -{ - CPed *nearestPed; - - if(m_pedStats->m_temper > m_pedStats->m_fear && m_pedStats->m_temper > 50) - return; - - if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer) { - - if (m_nMoveState != PEDMOVE_NONE && m_nMoveState != PEDMOVE_STILL) { - nearestPed = m_nearPeds[0]; - - if (nearestPed && nearestPed->m_nPedState != PED_DEAD && nearestPed != m_pSeekTarget && nearestPed != m_pedInObjective) { - - // Check if this ped wants to avoid the nearest one - if (CPedType::GetAvoid(this->m_nPedType) & CPedType::GetFlag(nearestPed->m_nPedType)) { - - // Further codes checks whether the distance between us and ped will be equal or below 1.0, if we walk up to him by 1.25 meters. - // If so, we want to avoid it, so we turn our body 45 degree and look to somewhere else. - - // Game converts from radians to degress and back again here, doesn't make much sense - CVector2D forward(-sin(m_fRotationCur), cos(m_fRotationCur)); - forward.Normalise(); // this is kinda pointless - - // Move forward 1.25 meters - CVector2D testPosition = CVector2D(GetPosition()) + forward*1.25f; - - // Get distance to ped we want to avoid - CVector2D distToPed = CVector2D(nearestPed->GetPosition()) - testPosition; - - if (distToPed.Magnitude() <= 1.0f && CPed::OurPedCanSeeThisOne((CEntity*)nearestPed)) { - m_nPedStateTimer = CTimer::GetTimeInMilliseconds() - + 500 + (m_randomSeed + 3 * CTimer::GetFrameCounter()) - % 1000 / 5; - - m_fRotationDest += DEGTORAD(45.0f); - if (!bIsLooking) { - CPed::SetLookFlag(nearestPed, 0); - CPed::SetLookTimer(CGeneral::GetRandomNumberInRange(500, 800)); - } - } - } - } - } - } -} - -void -CPed::ClearAimFlag(void) -{ - if (bIsAimingGun) { - bIsAimingGun = false; - bIsRestoringGun = true; - m_pedIK.m_flags &= ~CPedIK:: FLAG_4; - } - - if (CPed::IsPlayer()) - ((CPlayerPed*)this)->m_fFPSMoveHeading = 0.0; -} - -void -CPed::ClearLookFlag(void) { - if (bIsLooking) { - bIsLooking = false; - bIsRestoringLook = true; - m_ped_flagI1 = false; - - m_pedIK.m_flags &= ~CPedIK::FLAG_2; - if (CPed::IsPlayer()) - m_lookTimer = CTimer::GetTimeInMilliseconds() + 2000; - else - m_lookTimer = CTimer::GetTimeInMilliseconds() + 4000; - - if (m_nPedState == PED_LOOK_HEADING || m_nPedState == PED_LOOK_ENTITY) { - CPed::RestorePreviousState(); - CPed::ClearLookFlag(); - } - } -} - -bool -CPed::IsPedHeadAbovePos(float zOffset) -{ - RwMatrix mat; - - CPedIK::GetWorldMatrix(GetNodeFrame(PED_HEAD), &mat); - return zOffset + GetPosition().z < RwMatrixGetPos(&mat)->z; -} - -void -CPed::FinishedAttackCB(CAnimBlendAssociation *attackAssoc, void *arg) -{ - CWeaponInfo *currentWeapon; - CAnimBlendAssociation *newAnim; - CPed *ped = (CPed*)arg; - - if (attackAssoc) { - switch (attackAssoc->animId) { - case ANIM_WEAPON_START_THROW: - if ((!ped->IsPlayer() || ((CPlayerPed*)ped)->field_1380) && ped->IsPlayer()) { - attackAssoc->blendDelta = -1000.0f; - newAnim = CAnimManager::AddAnimation((RpClump*)ped->m_rwObject, ASSOCGRP_STD, ANIM_WEAPON_THROWU); - } else { - attackAssoc->blendDelta = -1000.0f; - newAnim = CAnimManager::AddAnimation((RpClump*)ped->m_rwObject, ASSOCGRP_STD, ANIM_WEAPON_THROW); - } - - newAnim->SetFinishCallback(FinishedAttackCB, ped); - return; - - case ANIM_FIGHT_PPUNCH: - attackAssoc->blendDelta = -8.0f; - attackAssoc->flags |= ASSOC_DELETEFADEDOUT; - ped->ClearAttack(); - return; - - case ANIM_WEAPON_THROW: - case ANIM_WEAPON_THROWU: - if (ped->GetWeapon()->m_nAmmoTotal > 0) { - currentWeapon = CWeaponInfo::GetWeaponInfo(ped->GetWeapon()->m_eWeaponType); - ped->AddWeaponModel(currentWeapon->m_nModelId); - } - break; - default: - break; - } - } - - if (!ped->m_ped_flagA4) - ped->ClearAttack(); -} - -void -CPed::Attack(void) -{ - CAnimBlendAssociation *weaponAnimAssoc; - int32 weaponAnim; - float animStart; - RwFrame *frame; - eWeaponType ourWeaponType; - float weaponAnimTime; - eWeaponFire ourWeaponFire; - float animLoopEnd; - CWeaponInfo *ourWeapon; - bool lastReloadWasInFuture; - AnimationId reloadAnim; - CAnimBlendAssociation *reloadAnimAssoc; - float delayBetweenAnimAndFire; - CVector firePos; - - ourWeaponType = GetWeapon()->m_eWeaponType; - ourWeapon = CWeaponInfo::GetWeaponInfo(ourWeaponType); - ourWeaponFire = ourWeapon->m_eWeaponFire; - weaponAnimAssoc = RpAnimBlendClumpGetAssociation((RpClump*)m_rwObject, ourWeapon->m_AnimToPlay); - lastReloadWasInFuture = m_ped_flagA4; - reloadAnimAssoc = nil; - reloadAnim = NUM_ANIMS; - delayBetweenAnimAndFire = ourWeapon->m_fAnimFrameFire; - weaponAnim = ourWeapon->m_AnimToPlay; - - if (weaponAnim == ANIM_WEAPON_HGUN_BODY) - reloadAnim = ANIM_HGUN_RELOAD; - else if (weaponAnim == ANIM_WEAPON_AK_BODY) - reloadAnim = ANIM_AK_RELOAD; - - if (reloadAnim != NUM_ANIMS) - reloadAnimAssoc = RpAnimBlendClumpGetAssociation((RpClump*)m_rwObject, reloadAnim); - - if (bIsDucking) - return; - - if (reloadAnimAssoc) { - if (!CPed::IsPlayer() || ((CPlayerPed*)this)->field_1380) - ClearAttack(); - - return; - } - - // BUG: We currently don't know any situation this cond. could be true. - if (CTimer::GetTimeInMilliseconds() < m_lastHitTime) - lastReloadWasInFuture = true; - - if (!weaponAnimAssoc) { - weaponAnimAssoc = RpAnimBlendClumpGetAssociation((RpClump*)m_rwObject, ourWeapon->m_Anim2ToPlay); - delayBetweenAnimAndFire = ourWeapon->m_fAnim2FrameFire; - - // Long throw granade, molotov - if (!weaponAnimAssoc && ourWeapon->m_bThrow) { - weaponAnimAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_WEAPON_THROWU); - delayBetweenAnimAndFire = 0.2f; - } - } - if (weaponAnimAssoc) { - animStart = ourWeapon->m_fAnimLoopStart; - weaponAnimTime = weaponAnimAssoc->currentTime; - if (weaponAnimTime > animStart && weaponAnimTime - weaponAnimAssoc->timeStep <= animStart) { - if (ourWeapon->m_bCanAimWithArm) - m_pedIK.m_flags |= CPedIK::FLAG_4; - else - m_pedIK.m_flags &= ~CPedIK::FLAG_4; - } - - if (weaponAnimTime <= delayBetweenAnimAndFire || weaponAnimTime - weaponAnimAssoc->timeStep > delayBetweenAnimAndFire || !weaponAnimAssoc->IsRunning()) { - if (weaponAnimAssoc->speed < 1.0f) - weaponAnimAssoc->speed = 1.0f; - - } else { - firePos = ourWeapon->m_vecFireOffset; - if (ourWeaponType == WEAPONTYPE_BASEBALLBAT) { - if (weaponAnimAssoc->animId == ourWeapon->m_Anim2ToPlay) - firePos.z = 0.7f * ourWeapon->m_fRadius - 1.0f; - - firePos = GetMatrix() * firePos; - } else if (ourWeaponType != WEAPONTYPE_UNARMED) { - if (weaponAnimAssoc->animId == ANIM_KICK_FLOOR) - frame = GetNodeFrame(PED_FOOTR); - else - frame = GetNodeFrame(PED_HANDR); - - for (; frame; frame = RwFrameGetParent(frame)) - RwV3dTransformPoints((RwV3d*)firePos, (RwV3d*)firePos, 1, RwFrameGetMatrix(frame)); - } else { - firePos = GetMatrix() * firePos; - } - - GetWeapon()->Fire(this, &firePos); - - if (ourWeaponType == WEAPONTYPE_MOLOTOV || ourWeaponType == WEAPONTYPE_GRENADE) { - RemoveWeaponModel(ourWeapon->m_nModelId); - } - if (!GetWeapon()->m_nAmmoTotal && ourWeaponFire != WEAPON_FIRE_MELEE && FindPlayerPed() != this) { - SelectGunIfArmed(); - } - - if (GetWeapon()->m_eWeaponState != WEAPONSTATE_MELEE_MADECONTACT) { - // If reloading just began, start the animation - if (GetWeapon()->m_eWeaponState == WEAPONSTATE_RELOADING && reloadAnim != NUM_ANIMS && !reloadAnimAssoc) { - CAnimManager::BlendAnimation((RpClump*) m_rwObject, ASSOCGRP_STD, reloadAnim, 8.0f); - ClearLookFlag(); - ClearAimFlag(); - m_ped_flagA4 = false; - bIsPointingGunAt = false; - m_lastHitTime = CTimer::GetTimeInMilliseconds(); - return; - } - } else { - if (weaponAnimAssoc->animId == ANIM_WEAPON_BAT_V || weaponAnimAssoc->animId == ANIM_WEAPON_BAT_H) { - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_BAT_ATTACK, 1.0f); - } else if (weaponAnimAssoc->animId == ANIM_FIGHT_PPUNCH) { - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_PUNCH_ATTACK, 0.0f); - } - - weaponAnimAssoc->speed = 0.5f; - - // BUG: We currently don't know any situation this cond. could be true. - if (m_ped_flagA4 || CTimer::GetTimeInMilliseconds() < m_lastHitTime) { - weaponAnimAssoc->callbackType = 0; - } - } - - lastReloadWasInFuture = false; - } - - if (ourWeaponType == WEAPONTYPE_SHOTGUN) { - weaponAnimTime = weaponAnimAssoc->currentTime; - firePos = ourWeapon->m_vecFireOffset; - - if (weaponAnimTime > 1.0f && weaponAnimTime - weaponAnimAssoc->timeStep <= 1.0f && weaponAnimAssoc->IsRunning()) { - for (frame = GetNodeFrame(PED_HANDR); frame; frame = RwFrameGetParent(frame)) - RwV3dTransformPoints((RwV3d*)firePos, (RwV3d*)firePos, 1, RwFrameGetMatrix(frame)); - - CVector gunshellPos( - firePos.x - 0.6f * GetForward().x, - firePos.y - 0.6f * GetForward().y, - firePos.z - 0.15f * GetUp().z - ); - - CVector2D gunshellRot( - GetRight().x, - GetRight().y - ); - - gunshellRot.Normalise(); - GetWeapon()->AddGunshell(this, gunshellPos, gunshellRot, 0.025f); - } - } - animLoopEnd = ourWeapon->m_fAnimLoopEnd; - if (ourWeaponFire == WEAPON_FIRE_MELEE && weaponAnimAssoc->animId == ourWeapon->m_Anim2ToPlay) - animLoopEnd = 3.4f/6.0f; - - weaponAnimTime = weaponAnimAssoc->currentTime; - - // Anim loop end, either start the loop again or finish the attack - if (weaponAnimTime > animLoopEnd || !weaponAnimAssoc->IsRunning() && ourWeaponFire != WEAPON_FIRE_PROJECTILE) { - - if (weaponAnimTime - 2.0f * weaponAnimAssoc->timeStep <= animLoopEnd - && (m_ped_flagA4 || CTimer::GetTimeInMilliseconds() < m_lastHitTime) - && GetWeapon()->m_eWeaponState != WEAPONSTATE_RELOADING) { - - weaponAnim = weaponAnimAssoc->animId; - if (ourWeaponFire != WEAPON_FIRE_MELEE || CheckForPedsOnGroundToAttack(((CPlayerPed*)this), nil) < PED_ON_THE_FLOOR) { - if (weaponAnim != ourWeapon->m_Anim2ToPlay || weaponAnim == ANIM_RBLOCK_CSHOOT) { - weaponAnimAssoc->Start(ourWeapon->m_fAnimLoopStart); - } else { - CAnimManager::BlendAnimation((RpClump*) m_rwObject, ASSOCGRP_STD, ourWeapon->m_AnimToPlay, 8.0f); - } - } else { - if (weaponAnim == ourWeapon->m_Anim2ToPlay) - weaponAnimAssoc->SetCurrentTime(0.1f); - else - CAnimManager::BlendAnimation((RpClump*) m_rwObject, ASSOCGRP_STD, ourWeapon->m_Anim2ToPlay, 8.0f); - } - } else { - ClearAimFlag(); - - // Echoes of bullets, at the end of the attack. (Bug: doesn't play while reloading) - if (weaponAnimAssoc->currentTime - weaponAnimAssoc->timeStep <= ourWeapon->m_fAnimLoopEnd) { - switch (ourWeaponType) { - case WEAPONTYPE_UZI: - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_UZI_BULLET_ECHO, 0.0f); - break; - case WEAPONTYPE_AK47: - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_AK47_BULLET_ECHO, 0.0f); - break; - case WEAPONTYPE_M16: - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_M16_BULLET_ECHO, 0.0f); - break; - default: - break; - } - } - - // Fun fact: removing this part leds to reloading flamethrower - if (ourWeaponType == WEAPONTYPE_FLAMETHROWER && weaponAnimAssoc->IsRunning()) { - weaponAnimAssoc->flags |= ASSOC_DELETEFADEDOUT; - weaponAnimAssoc->flags &= ~ASSOC_RUNNING; - weaponAnimAssoc->blendDelta = -4.0f; - } - } - } - if (weaponAnimAssoc->currentTime > delayBetweenAnimAndFire) - lastReloadWasInFuture = false; - - m_ped_flagA4 = lastReloadWasInFuture; - return; - } - - if (lastReloadWasInFuture) { - if (ourWeaponFire != WEAPON_FIRE_PROJECTILE || !CPed::IsPlayer() || ((CPlayerPed*)this)->field_1380) { - if (!CGame::nastyGame || ourWeaponFire != WEAPON_FIRE_MELEE || CheckForPedsOnGroundToAttack(((CPlayerPed*)this), nil) < PED_ON_THE_FLOOR) { - weaponAnimAssoc = CAnimManager::BlendAnimation((RpClump*)m_rwObject, ASSOCGRP_STD, ourWeapon->m_AnimToPlay, 8.0f); - } else { - weaponAnimAssoc = CAnimManager::BlendAnimation((RpClump*)m_rwObject, ASSOCGRP_STD, ourWeapon->m_Anim2ToPlay, 8.0f); - } - - weaponAnimAssoc->SetFinishCallback(CPed::FinishedAttackCB, this); - weaponAnimAssoc->flags |= ASSOC_RUNNING; - - if (weaponAnimAssoc->currentTime == weaponAnimAssoc->hierarchy->totalLength) - weaponAnimAssoc->SetCurrentTime(0.0f); - - if (CPed::IsPlayer()) { - ((CPlayerPed*)this)->field_1376 = 0.0f; - ((CPlayerPed*)this)->field_1380 = false; - } - } - } - else - CPed::FinishedAttackCB(nil, this); -} - -void -CPed::RemoveWeaponModel(int modelId) -{ - // modelId is not used!! This function just removes the current weapon. - RwFrameForAllObjects(GetNodeFrame(PED_HANDR),RemoveAllModelCB,nil); - m_wepModelID = -1; -} - -void -CPed::SetCurrentWeapon(uint32 weaponType) -{ - CWeaponInfo *weaponInfo; - if (HasWeapon(weaponType)) { - weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - RemoveWeaponModel(weaponInfo->m_nModelId); - - m_currentWeapon = weaponType; - - weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - AddWeaponModel(weaponInfo->m_nModelId); - } -} - -// Only used while deciding which gun ped should switch to, if no ammo left. -bool -CPed::SelectGunIfArmed(void) -{ - for (int i = 0; i < m_maxWeaponTypeAllowed; i++) { - if (GetWeapon(i).m_nAmmoTotal > 0) { - eWeaponType weaponType = GetWeapon(i).m_eWeaponType; - if (weaponType >= WEAPONTYPE_COLT45 && weaponType != WEAPONTYPE_M16 && weaponType <= WEAPONTYPE_FLAMETHROWER) { - SetCurrentWeapon(i); - return true; - } - } - } - SetCurrentWeapon(WEAPONTYPE_UNARMED); - return false; -} - -void -CPed::Duck(void) -{ - if (CTimer::GetTimeInMilliseconds() > m_duckTimer) - ClearDuck(); -} - -void -CPed::ClearDuck(void) -{ - CAnimBlendAssociation *animAssoc; - - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_DUCK_DOWN); - if (!animAssoc) - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_DUCK_LOW); - - if (animAssoc) { - - if (bCrouchWhenShooting) { - - if (m_nPedState == PED_ATTACK || m_nPedState == PED_AIM_GUN) { - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_RBLOCK_CSHOOT); - if (!animAssoc || animAssoc->blendDelta < 0.0f) { - CAnimManager::BlendAnimation((RpClump*) m_rwObject, ASSOCGRP_STD, ANIM_RBLOCK_CSHOOT, 4.0f); - } - } - } - } else - bIsDucking = false; -} - -void -CPed::ClearPointGunAt(void) -{ - CAnimBlendAssociation *animAssoc; - CWeaponInfo *weaponInfo; - - ClearLookFlag(); - ClearAimFlag(); - bIsPointingGunAt = false; - if (m_nPedState == PED_AIM_GUN) { - RestorePreviousState(); - weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, weaponInfo->m_AnimToPlay); - if (!animAssoc || animAssoc->blendDelta < 0.0f) { - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, weaponInfo->m_Anim2ToPlay); - } - if (animAssoc) { - animAssoc->flags |= ASSOC_DELETEFADEDOUT; - animAssoc->blendDelta = -4.0; - } - } -} - -void -CPed::BeingDraggedFromCar(void) -{ - CAnimBlendAssociation *animAssoc; - AnimationId enterAnim; - bool dontRunAnim = false; - PedLineUpPhase lineUpType; - - if (!m_pVehicleAnim) { - CAnimManager::BlendAnimation((RpClump*) m_rwObject, m_animGroup, ANIM_IDLE_STANCE, 100.0f); - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_CAR_SIT); - if (!animAssoc) { - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_CAR_LSIT); - if (!animAssoc) { - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_CAR_SITP); - if (!animAssoc) - animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_CAR_SITPLO); - } - } - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - - if (m_vehEnterType == VEHICLE_ENTER_FRONT_LEFT || m_vehEnterType == VEHICLE_ENTER_REAR_LEFT) { - if (m_ped_flagF10) { - enterAnim = ANIM_CAR_QJACKED; - } else if (m_pMyVehicle->bLowVehicle) { - enterAnim = ANIM_CAR_LJACKED_LHS; - } else { - enterAnim = ANIM_CAR_JACKED_LHS; - } - } else if (m_vehEnterType == VEHICLE_ENTER_FRONT_RIGHT || m_vehEnterType == VEHICLE_ENTER_REAR_RIGHT) { - if (m_pMyVehicle->bLowVehicle) - enterAnim = ANIM_CAR_LJACKED_RHS; - else - enterAnim = ANIM_CAR_JACKED_RHS; - } else - dontRunAnim = true; - - - if (!dontRunAnim) - m_pVehicleAnim = CAnimManager::AddAnimation((RpClump*) m_rwObject, ASSOCGRP_STD, enterAnim); - - m_pVehicleAnim->SetFinishCallback(PedSetDraggedOutCarCB, this); - lineUpType = LINE_UP_TO_CAR_START; - } else if (m_pVehicleAnim->currentTime <= 1.4f) { - m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - lineUpType = LINE_UP_TO_CAR_START; - } else { - lineUpType = LINE_UP_TO_CAR_2; - } - - LineUpPedWithCar(lineUpType); -} - -void -CPed::RestartNonPartialAnims(void) -{ - CAnimBlendAssociation *assoc; - - for (assoc = RpAnimBlendClumpGetFirstAssociation((RpClump*)m_rwObject); assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) { - if (!assoc->IsPartial()) - assoc->flags |= ASSOC_RUNNING; - } -} - -void -CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg) -{ - CAnimBlendAssociation *quickJackedAssoc; - CVehicle *vehicle; - CPed *ped = (CPed*)arg; - eWeaponType weaponType = ped->GetWeapon()->m_eWeaponType; - - quickJackedAssoc = RpAnimBlendClumpGetAssociation((RpClump*) ped->m_rwObject, ANIM_CAR_QJACKED); - if (ped->m_nPedState != PED_ARRESTED) { - ped->m_nLastPedState = PED_NONE; - if (dragAssoc) - dragAssoc->blendDelta = -1000.0; - } - ped->RestartNonPartialAnims(); - ped->m_pVehicleAnim = nil; - ped->m_pSeekTarget = nil; - vehicle = ped->m_pMyVehicle; - - vehicle->m_nGettingOutFlags &= ~GetVehEnterExitFlag(ped->m_vehEnterType); - - if (vehicle->pDriver == ped) { - vehicle->RemoveDriver(); - if (vehicle->m_nDoorLock == CARLOCK_COP_CAR) - vehicle->m_nDoorLock = CARLOCK_UNLOCKED; - - if (ped->m_nPedType == PEDTYPE_COP && vehicle->IsLawEnforcementVehicle()) - vehicle->ChangeLawEnforcerState(false); - } else { - for (int i = 0; i < vehicle->m_nNumMaxPassengers; i++) { - if (vehicle->pPassengers[i] == ped) { - vehicle->pPassengers[i] = nil; - vehicle->m_nNumPassengers--; - } - } - } - - ped->bInVehicle = false; - if (ped->IsPlayer()) - AudioManager.PlayerJustLeftCar(); - - if (quickJackedAssoc) { - dragAssoc->SetDeleteCallback(PedSetQuickDraggedOutCarPositionCB, ped); - } else { - dragAssoc->SetDeleteCallback(PedSetDraggedOutCarPositionCB, ped); - if (ped->CanSetPedState()) - CAnimManager::BlendAnimation((RpClump*) ped->m_rwObject, ASSOCGRP_STD, ANIM_GETUP1, 1000.0f); - } - - // Only uzi can be used on cars, so previous weapon was stored - if (ped->IsPlayer() && weaponType == WEAPONTYPE_UZI) { - if (ped->m_storedWeapon != NO_STORED_WEAPON) { - ped->SetCurrentWeapon(ped->m_storedWeapon); - ped->m_storedWeapon = NO_STORED_WEAPON; - } - } else { - ped->AddWeaponModel(CWeaponInfo::GetWeaponInfo(weaponType)->m_nModelId); - } - ped->m_nStoredActionState = 0; - ped->m_ped_flagI4 = false; -} - -void -CPed::GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float seatPosMult) -{ - CVehicleModelInfo *vehModel; - CVector vehDoorPos; - CVector vehDoorOffset; - float seatOffset; - - vehModel = (CVehicleModelInfo*) CModelInfo::GetModelInfo(veh->m_modelIndex); - if (veh->bIsVan && (enterType == VEHICLE_ENTER_REAR_LEFT || enterType == VEHICLE_ENTER_REAR_RIGHT)) { - seatOffset = 0.0f; - vehDoorOffset = offsetToOpenVanDoor; - } else { - seatOffset = veh->m_handling->fSeatOffsetDistance * seatPosMult; - if (veh->bLowVehicle) { - vehDoorOffset = offsetToOpenLowCarDoor; - } else { - vehDoorOffset = offsetToOpenRegularCarDoor; - } - } - - switch (enterType) { - case VEHICLE_ENTER_FRONT_RIGHT: - if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) - vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_BOAT_RUDDER]; - else - vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_FRONT_SEATS]; - - vehDoorPos.x += seatOffset; - vehDoorOffset.x = -vehDoorOffset.x; - break; - - case VEHICLE_ENTER_REAR_RIGHT: - vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_REAR_SEATS]; - vehDoorPos.x += seatOffset; - vehDoorOffset.x = -vehDoorOffset.x; - break; - - case VEHICLE_ENTER_FRONT_LEFT: - if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) - vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_BOAT_RUDDER]; - else - vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_FRONT_SEATS]; - - vehDoorPos.x = -(vehDoorPos.x + seatOffset); - break; - - case VEHICLE_ENTER_REAR_LEFT: - vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_REAR_SEATS]; - vehDoorPos.x = -(vehDoorPos.x + seatOffset); - break; - - default: - if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) - vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_BOAT_RUDDER]; - else - vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_FRONT_SEATS]; - - vehDoorOffset = CVector(0.0f, 0.0f, 0.0f); - } - *output = vehDoorPos - vehDoorOffset; -} - -// This function was mostly duplicate of GetLocalPositionToOpenCarDoor, so I've used it. -void -CPed::GetPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType) -{ - CVector localPos; - CVector vehDoorPos; - - GetLocalPositionToOpenCarDoor(&localPos, veh, enterType, 1.0f); - vehDoorPos = Multiply3x3(veh->GetMatrix(), localPos) + veh->GetPosition(); - -/* - // Not used. - CVector localVehDoorOffset; - - if (veh->bIsVan && (enterType == VEHICLE_ENTER_REAR_LEFT || enterType == VEHICLE_ENTER_REAR_RIGHT)) { - localVehDoorOffset = offsetToOpenVanDoor; - } else { - if (veh->bIsLow) { - localVehDoorOffset = offsetToOpenLowCarDoor; - } else { - localVehDoorOffset = offsetToOpenRegularCarDoor; - } - } - - vehDoorPosWithoutOffset = Multiply3x3(veh->GetMatrix(), localPos + localVehDoorOffset) + veh->GetPosition(); -*/ - *output = vehDoorPos; -} - -void -CPed::GetPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float offset) -{ - CVector doorPos; - CMatrix vehMat(veh->GetMatrix()); - - GetLocalPositionToOpenCarDoor(output, veh, enterType, offset); - doorPos = Multiply3x3(vehMat, *output); - - *output = *veh->GetPosition() + doorPos; -} - -void -CPed::LineUpPedWithCar(PedLineUpPhase phase) -{ - bool vehIsUpsideDown = false; - int vehAnim; - float seatPosMult = 0.0f; - float currentZ; - float adjustedTimeStep; - - if (CReplay::IsPlayingBack()) - return; - - if (!m_ped_flagC8 && phase != LINE_UP_TO_CAR_2) { - if (RpAnimBlendClumpGetAssociation((RpClump*)m_rwObject, ANIM_CAR_SIT)) { - SetPedPositionInCar(); - return; - } - if (RpAnimBlendClumpGetAssociation((RpClump*)m_rwObject, ANIM_CAR_LSIT)) { - SetPedPositionInCar(); - return; - } - if (RpAnimBlendClumpGetAssociation((RpClump*)m_rwObject, ANIM_CAR_SITP)) { - SetPedPositionInCar(); - return; - } - if (RpAnimBlendClumpGetAssociation((RpClump*)m_rwObject, ANIM_CAR_SITPLO)) { - SetPedPositionInCar(); - return; - } - m_ped_flagC8 = 1; - } - if (phase == LINE_UP_TO_CAR_START) { - m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - } - CVehicle *veh = m_pMyVehicle; - - // Not quite right, IsUpsideDown func. checks for <= -0.9f. - // Since that function is also used in this file, doesn't this variable indicate upsidedownness?! - if (veh->GetUp().z <= -0.8f) - vehIsUpsideDown = true; - - if (m_vehEnterType == VEHICLE_ENTER_FRONT_RIGHT || m_vehEnterType == VEHICLE_ENTER_REAR_RIGHT) { - if (vehIsUpsideDown) { - m_fRotationDest = -PI + veh->GetForward().Heading(); - } else if (veh->bIsBus) { - m_fRotationDest = 0.5 * PI + veh->GetForward().Heading(); - } else { - m_fRotationDest = veh->GetForward().Heading(); - } - } else if (m_vehEnterType == VEHICLE_ENTER_FRONT_LEFT || m_vehEnterType == VEHICLE_ENTER_REAR_LEFT) { - if (vehIsUpsideDown) { - m_fRotationDest = veh->GetForward().Heading(); - } else if (veh->bIsBus) { - m_fRotationDest = -0.5 * PI + veh->GetForward().Heading(); - } else { - m_fRotationDest = veh->GetForward().Heading(); - } - } - - if (!bInVehicle) - seatPosMult = 1.0f; - - if (m_pVehicleAnim) { - vehAnim = m_pVehicleAnim->animId; - - switch (vehAnim) { - case ANIM_CAR_JACKED_RHS: - case ANIM_CAR_LJACKED_RHS: - case ANIM_CAR_JACKED_LHS: - case ANIM_CAR_LJACKED_LHS: - case ANIM_CAR_QJACKED: - case ANIM_CAR_GETOUT_LHS: - case ANIM_CAR_GETOUT_LOW_LHS: - case ANIM_CAR_GETOUT_RHS: - case ANIM_CAR_GETOUT_LOW_RHS: - case ANIM_CAR_CRAWLOUT_RHS: - case ANIM_CAR_CRAWLOUT_RHS2: - case ANIM_VAN_GETIN_L: - case ANIM_VAN_GETOUT_L: - case ANIM_VAN_GETIN: - case ANIM_VAN_GETOUT: - seatPosMult = m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength; - break; - case ANIM_CAR_QJACK: - case ANIM_CAR_GETIN_LHS: - case ANIM_CAR_GETIN_LOW_LHS: - case ANIM_CAR_GETIN_RHS: - case ANIM_CAR_GETIN_LOW_RHS: - case ANIM_DRIVE_BOAT: - seatPosMult = m_pVehicleAnim->GetTimeLeft() / m_pVehicleAnim->hierarchy->totalLength; - break; - case ANIM_CAR_CLOSEDOOR_LHS: - case ANIM_CAR_CLOSEDOOR_LOW_LHS: - case ANIM_CAR_CLOSEDOOR_RHS: - case ANIM_CAR_CLOSEDOOR_LOW_RHS: - case ANIM_CAR_SHUFFLE_RHS: - case ANIM_CAR_LSHUFFLE_RHS: - seatPosMult = 0.0f; - break; - case ANIM_CAR_CLOSE_LHS: - case ANIM_CAR_CLOSE_RHS: - case ANIM_COACH_OPEN_L: - case ANIM_COACH_OPEN_R: - case ANIM_COACH_IN_L: - case ANIM_COACH_IN_R: - case ANIM_COACH_OUT_L: - seatPosMult = 1.0f; - break; - default: - break; - } - } - - CVector neededPos; - - if (phase == LINE_UP_TO_CAR_2) { - neededPos = *GetPosition(); - } else { - GetPositionToOpenCarDoor(&neededPos, veh, m_vehEnterType, seatPosMult); - } - - CVector autoZPos = neededPos; - - if (veh->bIsInWater) { - if (veh->m_vehType == VEHICLE_TYPE_BOAT && veh->IsUpsideDown()) - autoZPos.z += 1.0f; - } else { - CPedPlacement::FindZCoorForPed(&autoZPos); - } - - if (phase == LINE_UP_TO_CAR_END || phase == LINE_UP_TO_CAR_2) { - neededPos.z = GetPosition().z; - - // Getting out - if (!veh->bIsBus || (veh->bIsBus && vehIsUpsideDown)) { - float pedZSpeedOnExit = m_vecMoveSpeed.z - 0.008f * CTimer::GetTimeStep(); - - // If we're not in ground at next step, apply animation - if (neededPos.z + pedZSpeedOnExit >= autoZPos.z) { - m_vecMoveSpeed.z = pedZSpeedOnExit; - ApplyMoveSpeed(); - // Removing below line breaks the animation - neededPos.z = GetPosition().z; - } else { - neededPos.z = autoZPos.z; - m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - } - } - } - - if (autoZPos.z > neededPos.z) { - currentZ = GetPosition().z; - if (m_pVehicleAnim && vehAnim != ANIM_VAN_GETIN_L && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE && vehAnim != ANIM_VAN_GETIN) { - neededPos.z = autoZPos.z; - m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - } else if (neededPos.z <= currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) { - adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); - - // Smoothly change ped position - neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep); - } - } else { - // We may need to raise up the ped - if (phase == LINE_UP_TO_CAR_START) { - currentZ = GetPosition().z; - - if (neededPos.z > currentZ) { - - if (m_pVehicleAnim && - (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS - || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) { - adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f); - - // Smoothly change ped position - neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ; - } else if (m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK) { - neededPos.z = max(currentZ, autoZPos.z); - } - } - } - } - - bool stillGettingInOut = false; - if (CTimer::GetTimeInMilliseconds() < m_nPedStateTimer) - stillGettingInOut = veh->m_vehType != VEHICLE_TYPE_BOAT || m_ped_flagG10; - - if (!stillGettingInOut) { - m_fRotationCur = m_fRotationDest; - } else { - float limitedAngle = CGeneral::LimitRadianAngle(m_fRotationDest); - float timeUntilStateChange = (m_nPedStateTimer - CTimer::GetTimeInMilliseconds())/600.0f; - - m_vecOffsetSeek.z = 0.0; - if (timeUntilStateChange <= 0.0f) { - m_vecOffsetSeek.x = 0.0; - m_vecOffsetSeek.y = 0.0; - } else { - neededPos -= timeUntilStateChange * m_vecOffsetSeek; - } - - if (limitedAngle > PI + m_fRotationCur) { - limitedAngle -= 2 * PI; - } else if (limitedAngle < m_fRotationCur - PI) { - limitedAngle += 2 * PI; - } - m_fRotationCur -= (m_fRotationCur - limitedAngle) * (1.0f - timeUntilStateChange); - } - - if (seatPosMult > 0.2f || vehIsUpsideDown) { - GetPosition() = neededPos; - - GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur); - - // It will be all 0 after rotate. - GetPosition() = neededPos; - } else { - CVector output; - CMatrix vehDoorMat(veh->GetMatrix()); - - GetLocalPositionToOpenCarDoor(&output, veh, m_vehEnterType, 0.0f); - *vehDoorMat.GetPosition() += Multiply3x3(vehDoorMat, output); - GetMatrix() = vehDoorMat; - } - -} - -static void -particleProduceFootDust(CPed *ped, CVector *pos, float size, int times) -{ - switch (ped->m_nLastCollType) - { - case 1: // somewhere hard - case 3: // soft dirt - case 5: // pavement - case 18:// sand - for (int i = 0; i < times; ++i) { - CVector adjustedPos = *pos; - adjustedPos.x += CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); - adjustedPos.y += CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); - CParticle::AddParticle(PARTICLE_PEDFOOT_DUST, adjustedPos, CVector(0.0f, 0.0f, 0.0f), nil, size, CRGBA(0, 0, 0, 0), 0, 0, 0, 0); - } - break; - default: - break; - } -} - -static void -particleProduceFootSplash(CPed *ped, CVector *pos, float size, int times) -{ - for (int i = 0; i < times; i++) { - CVector adjustedPos = *pos; - adjustedPos.x += CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); - adjustedPos.y += CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); - - CVector direction = ped->GetForward() * -0.05f; - CParticle::AddParticle(PARTICLE_RAIN_SPLASHUP, adjustedPos, direction, nil, size, CRGBA(32, 32, 32, 32), 0, 0, CGeneral::GetRandomNumberInRange(0, 1), 200); - } -} - -void -CPed::PlayFootSteps(void) -{ - if (bDoBloodyFootprints) { - if (m_bloodyFootprintCount > 0 && m_bloodyFootprintCount < 300) { - m_bloodyFootprintCount--; - - if (m_bloodyFootprintCount == 0) - bDoBloodyFootprints = false; - } - } - - if (!bIsStanding) - return; - - CAnimBlendAssociation *assoc = RpAnimBlendClumpGetFirstAssociation((RpClump*)m_rwObject); - CAnimBlendAssociation *walkRunAssoc = nil; - float walkRunAssocBlend = 0.0f, idleAssocBlend = 0.0f; - - for (; assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) { - if (assoc->flags & ASSOC_FLAG80) { - walkRunAssoc = assoc; - walkRunAssocBlend += assoc->blendAmount; - } else if ((assoc->flags & ASSOC_FLAG200) == 0) { - idleAssocBlend += assoc->blendAmount; - } - } - - if (walkRunAssoc && walkRunAssocBlend > 0.5f && idleAssocBlend < 1.0f) { - float stepStart = 1 / 15.0f; - float stepEnd = walkRunAssoc->hierarchy->totalLength / 2.0f + stepStart; - float currentTime = walkRunAssoc->currentTime; - int stepPart = 0; - - if (currentTime >= stepStart && currentTime - walkRunAssoc->timeStep < stepStart) - stepPart = 1; - else if (currentTime >= stepEnd && currentTime - walkRunAssoc->timeStep < stepEnd) - stepPart = 2; - - if (stepPart != 0) { - DMAudio.PlayOneShot(m_audioEntityId, stepPart == 1 ? SOUND_STEP_START : SOUND_STEP_END, 1.0f); - CVector footPos(0.0f, 0.0f, 0.0f); - - for (RwFrame *frame = GetNodeFrame(stepPart == 1 ? PED_FOOTL : PED_FOOTR); frame; frame = RwFrameGetParent(frame)) - RwV3dTransformPoints(footPos, footPos, 1, RwFrameGetMatrix(frame)); - - CVector forward = GetForward(); - - footPos.z -= 0.1f; - footPos += 0.2f * forward; - - if (bDoBloodyFootprints) { - CVector2D top(forward * 0.26f); - CVector2D right(GetRight() * 0.14f); - - CShadows::AddPermanentShadow(1, gpBloodPoolTex, &footPos, - top.x, top.y, - right.x, right.y, - 255, 255, 0, 0, 4.0f, 3000.0f, 1.0f); - - if (m_bloodyFootprintCount <= 20) { - m_bloodyFootprintCount = 0; - bDoBloodyFootprints = false; - } else { - m_bloodyFootprintCount -= 20; - } - } - if (CWeather::Rain <= 0.1f || CCullZones::CamNoRain() || CCullZones::PlayerNoRain()) { - if(IsPlayer()) - particleProduceFootDust(this, &footPos, 0.0f, 4); - } else if(stepPart == 2) { - particleProduceFootSplash(this, &footPos, 0.15f, 4); - } - } - } - - if (m_nLastCollType == 19) { // Water - float pedSpeed = CVector2D(m_vecMoveSpeed).Magnitude(); - if (pedSpeed > 0.03f && CTimer::GetFrameCounter() % 2 == 0 && pedSpeed > 0.13f) { - float particleSize = pedSpeed * 2.0f; - - if (particleSize < 0.25f) - particleSize = 0.25f; - - if (particleSize > 0.75f) - particleSize = 0.75f; - - CVector particlePos = GetPosition() + GetForward() * 0.3f; - particlePos.z -= 1.2f; - - CVector particleDir = m_vecMoveSpeed * 0.75f; - - particleDir.z = CGeneral::GetRandomNumberInRange(0.01f, 0.03f); - CParticle::AddParticle(PARTICLE_PED_SPLASH, particlePos, particleDir, nil, 0.8f * particleSize, CRGBA(155,155,185,128), 0, 0, 0, 0); - - particleDir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.05f); - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, particlePos, particleDir, nil, particleSize, CRGBA(255,255,255,255), 0, 0, 0, 0); - } - } -} - -bool -CPed::IsPointerValid(void) -{ - int8 pedIndex = CPools::GetPedPool()->GetIndex(this) >> 8; - if (pedIndex < 0 || pedIndex >= NUMPEDS) - return false; - - if (m_entryInfoList.first || FindPlayerPed() == this) - return true; - - return false; -} - -// Some kind of binary sort -void -CPed::SortPeds(CPed **list, int min, int max) -{ - if (min >= max) - return; - - CVector leftDiff, rightDiff; - CVector middleDiff = GetPosition() - list[(max + min) / 2]->GetPosition(); - float middleDist = middleDiff.Magnitude(); - - int left = max; - int right; - for(right = min; right <= left; ){ - // Those 1.0s are to make sure loop always run for first time. - for (float rightDist = middleDist-1.0f; middleDist > rightDist; right++) { - rightDiff = GetPosition() - list[right]->GetPosition(); - rightDist = rightDiff.Magnitude(); - } - right--; - - for (float leftDist = middleDist+1.0f; middleDist < leftDist; left--) { - leftDiff = GetPosition() - list[left]->GetPosition(); - leftDist = leftDiff.Magnitude(); - } - left++; - - if (right <= left) { - CPed *ped = list[right]; - list[right] = list[left]; - list[left] = ped; - right++; - left--; - } - } - SortPeds(list, min, left); - SortPeds(list, right, max); -} - -void -CPed::BuildPedLists(void) -{ - static CPed *unsortedNearPeds[10]; - uint16 nextNearPedSlot = 0; - - if ((CTimer::GetFrameCounter() + m_randomSeed) & 15) { - - for(int i = 0; i < 10; ) { - if (m_nearPeds[i]) { - if (m_nearPeds[i]->IsPointerValid()) { - float distSqr = (GetPosition() - m_nearPeds[i]->GetPosition()).MagnitudeSqr2D(); - if (distSqr < 900.0f) { - i++; - continue; - } - } - - // If we arrive here, the ped we're checking isn't "near", so we should remove it. - for (int j = i; j < 9; j++) { - m_nearPeds[j] = m_nearPeds[j + 1]; - m_nearPeds[j + 1] = nil; - } - // Above loop won't work when it's 9, so we need to empty slot 9. - m_nearPeds[9] = nil; - m_numNearPeds--; - } else - i++; - } - } else { - CVector centre = CEntity::GetBoundCentre(); - CRect rect( - (centre.x - 20.0f) * 0.025f + 50.0f, - (centre.y - 20.0f) * 0.025f + 50.0f, - (centre.x + 20.0f) * 0.025f + 50.0f, - (centre.y + 20.0f) * 0.025f + 50.0f); - - for(int y = rect.top; y <= rect.bottom; y++) { - for(int x = rect.left; x <= rect.right; x++) { - for (CPtrNode *pedPtrNode = CWorld::GetSector(x,y)->m_lists[ENTITYLIST_PEDS].first; pedPtrNode; pedPtrNode = pedPtrNode->next) { - CPed *ped = (CPed*)pedPtrNode->item; - if (ped != this && !ped->bInVehicle) { - float dist = (ped->GetPosition() - GetPosition()).Magnitude2D(); - if (distanceMultToCountPedNear * 30.0f > dist) - { - unsortedNearPeds[nextNearPedSlot] = ped; - nextNearPedSlot++; - } - } - } - } - } - unsortedNearPeds[nextNearPedSlot] = nil; - SortPeds(unsortedNearPeds, 0, nextNearPedSlot - 1); - for (m_numNearPeds = 0; m_numNearPeds < 10; m_numNearPeds++) { - CPed *ped = unsortedNearPeds[m_numNearPeds]; - if (!ped) - break; - - m_nearPeds[m_numNearPeds] = ped; - } - for (int pedToClear = m_numNearPeds; pedToClear < 10; pedToClear++) - m_nearPeds[pedToClear] = nil; - } -} - -void -CPed::SetPedStats(ePedStats pedStat) -{ - m_pedStats = CPedStats::ms_apPedStats[pedStat]; -} - -void -CPed::SetModelIndex(uint32 mi) -{ - CEntity::SetModelIndex(mi); - RpAnimBlendClumpInit((RpClump*) m_rwObject); - RpAnimBlendClumpFillFrameArray((RpClump*) m_rwObject, m_pFrames); - CPedModelInfo *modelInfo = (CPedModelInfo*)CModelInfo::GetModelInfo(m_modelIndex); - SetPedStats((ePedStats) modelInfo->m_pedStatType); - m_headingRate = m_pedStats->m_headingChangeRate; - m_animGroup = (AssocGroupId) modelInfo->m_animGroup; - CAnimManager::AddAnimation((RpClump*) m_rwObject, m_animGroup, ANIM_IDLE_STANCE); - - // This is a mistake by R*, velocity is CVector, whereas m_vecAnimMoveDelta is CVector2D. - (*RPANIMBLENDCLUMPDATA(m_rwObject))->velocity = (CVector*) &m_vecAnimMoveDelta; -} - -void -CPed::RemoveLighting(bool reset) -{ - CRenderer::RemoveVehiclePedLights(this, reset); -} - -bool -CPed::SetupLighting(void) -{ - ActivateDirectional(); - SetAmbientColoursForPedsCarsAndObjects(); - if (bRenderScorched) { - WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f); - } else { - // Note that this lightMult is only affected by LIGHT_DARKEN. If there's no LIGHT_DARKEN, it will be 1.0. - float lightMult = CPointLights::GenerateLightsAffectingObject(&GetPosition()); - if (!bHasBlip && lightMult != 1.0f) { - SetAmbientAndDirectionalColours(lightMult); - return true; - } - } - return false; -} - -void -CPed::Teleport(CVector pos) -{ - CWorld::Remove(this); - GetPosition() = pos; - bIsStanding = false; - m_nPedStateTimer = 0; - m_actionX = 0.0f; - m_actionY = 0.0f; - m_pDamageEntity = nil; - CWorld::Add(this); -} - -void -CPed::CalculateNewOrientation(void) -{ - if (CReplay::IsPlayingBack() || !IsPedInControl()) - return; - - CVector pos = *GetPosition(); - - GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur); - - // Because SetRotate makes pos. all 0 - GetPosition() = pos; -} - -float -CPed::WorkOutHeadingForMovingFirstPerson(float offset) -{ - if (!IsPlayer()) - return 0.0f; - - CPad *pad0 = CPad::GetPad(0); - float leftRight = pad0->GetPedWalkLeftRight(); - float upDown = pad0->GetPedWalkUpDown(); - float &angle = ((CPlayerPed*)this)->m_fWalkAngle; - - if (upDown != 0.0f) { - angle = CGeneral::GetRadianAngleBetweenPoints(0.0f, 0.0f, -leftRight, upDown); - } else { - if (leftRight < 0.0f) - angle = 0.5 * PI; - else if (leftRight > 0.0f) - angle = -0.5 * PI; - } - - return CGeneral::LimitRadianAngle(offset + angle); -} - -void -CPed::CalculateNewVelocity(void) -{ - if (IsPedInControl()) { - float headAmount = DEGTORAD(m_headingRate) * CTimer::GetTimeStep(); - m_fRotationCur = CGeneral::LimitRadianAngle(m_fRotationCur); - float limitedRotDest = CGeneral::LimitRadianAngle(m_fRotationDest); - - if (m_fRotationCur - PI > limitedRotDest) { - limitedRotDest += 2 * PI; - } else if(PI + m_fRotationCur < limitedRotDest) { - limitedRotDest -= 2 * PI; - } - - if (IsPlayer() && m_nPedState == PED_ATTACK) - headAmount /= 4.0f; - - float neededTurn = limitedRotDest - m_fRotationCur; - if (neededTurn <= headAmount) { - if (neededTurn > (-headAmount)) - m_fRotationCur += neededTurn; - else - m_fRotationCur -= headAmount; - } else { - m_fRotationCur += headAmount; - } - } - - CVector2D forward(sin(m_fRotationCur), cos(m_fRotationCur)); - - m_moved.x = CrossProduct2D(m_vecAnimMoveDelta, forward); // (m_vecAnimMoveDelta.x * cos(m_fRotationCur)) + -sin(m_fRotationCur) * m_vecAnimMoveDelta.y; - m_moved.y = DotProduct2D(m_vecAnimMoveDelta, forward); // m_vecAnimMoveDelta.y* cos(m_fRotationCur) + (m_vecAnimMoveDelta.x * sin(m_fRotationCur)); - - if (CTimer::GetTimeStep() >= 0.01f) { - m_moved = m_moved * (1 / CTimer::GetTimeStep()); - } else { - m_moved = m_moved * (1 / 100.0f); - } - - if ((!TheCamera.Cams[TheCamera.ActiveCam].GetWeaponFirstPersonOn() && !TheCamera.Cams[0].Using3rdPersonMouseCam()) - || FindPlayerPed() != this || !CanStrafeOrMouseControl()) - return; - - float walkAngle = WorkOutHeadingForMovingFirstPerson(m_fRotationCur); - float pedSpeed = m_moved.Magnitude(); - float localWalkAngle = CGeneral::LimitRadianAngle(walkAngle - m_fRotationCur); - - if (localWalkAngle < -0.5 * PI) { - localWalkAngle += PI; - } else if (localWalkAngle > 0.5 * PI) { - localWalkAngle -= PI; - } - - // Interestingly this part is responsible for diagonal walking. - if (localWalkAngle > -DEGTORAD(50.0f) && localWalkAngle < DEGTORAD(50.0f)) { - TheCamera.Cams[TheCamera.ActiveCam].m_fPlayerVelocity = pedSpeed; - m_moved = CVector2D(-sin(walkAngle), cos(walkAngle)) * pedSpeed; - } - - CAnimBlendAssociation *idleAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_IDLE_STANCE); - CAnimBlendAssociation* fightAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_FIGHT_IDLE); - - if ((!idleAssoc || idleAssoc->blendAmount < 0.5f) && !fightAssoc) { - LimbOrientation newUpperLegs; - newUpperLegs.phi = localWalkAngle; - - if (newUpperLegs.phi < -DEGTORAD(100.0f)) { - newUpperLegs.phi += PI; - } else if (newUpperLegs.phi > DEGTORAD(100.0f)) { - newUpperLegs.phi -= PI; - } - - if (newUpperLegs.phi > -DEGTORAD(50.0f) && newUpperLegs.phi < DEGTORAD(50.0f)) { - newUpperLegs.theta = 0.0f; - m_pedIK.RotateTorso(m_pFrames[PED_UPPERLEGL], &newUpperLegs, false); - m_pedIK.RotateTorso(m_pFrames[PED_UPPERLEGR], &newUpperLegs, false); - } - } -} - -bool -CPed::CanBeDeleted(void) -{ - if (this->bInVehicle) - return false; - - switch (CharCreatedBy) { - case RANDOM_CHAR: - return true; - case MISSION_CHAR: - return false; - default: - return true; - } -} - -bool -CPed::CanPedDriveOff(void) -{ - if (m_nPedState != PED_DRIVING || m_lookTimer > CTimer::GetTimeInMilliseconds()) - return false; - - for (int i = 0; i < m_numNearPeds; i++) { - CPed *ped = m_nearPeds[i]; - if (ped->m_nPedType == m_nPedType && ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER && ped->m_carInObjective == m_carInObjective) { - m_lookTimer = CTimer::GetTimeInMilliseconds() + 1000; - return false; - } - } - return true; -} - -// I couldn't find where it is used. -bool -CPed::CanPedJumpThis(int32 unused) -{ - CVector2D forward(-sin(m_fRotationCur), cos(m_fRotationCur)); - CVector pos = GetPosition(); - // wat? - CVector forwardPos( - forward.x + pos.x, - forward.y + pos.y, - pos.z); - return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false); -} - -bool -CPed::CanPedReturnToState(void) -{ - return m_nPedState <= PED_STATES_NO_AI && m_nPedState != PED_AIM_GUN && m_nPedState != PED_ATTACK && - m_nPedState != PED_FIGHT && m_nPedState != PED_STEP_AWAY && m_nPedState != PED_SNIPER_MODE && m_nPedState != PED_LOOK_ENTITY; -} - -bool -CPed::CanSeeEntity(CEntity *entity, float threshold) -{ - float neededAngle = CGeneral::GetRadianAngleBetweenPoints( - entity->GetPosition().x, - entity->GetPosition().x, - GetPosition().x, - GetPosition().y); - - if (neededAngle < 0.0f) - neededAngle += 2 * PI; - else if (neededAngle > 2 * PI) - neededAngle -= 2 * PI; - - float ourAngle = m_fRotationCur; - if (ourAngle < 0.0f) - ourAngle += 2 * PI; - else if (ourAngle > 2 * PI) - ourAngle -= 2 * PI; - - float neededTurn = fabs(neededAngle - ourAngle); - - return neededTurn < threshold || 2 * PI - threshold < neededTurn; -} - -bool -CPed::IsTemporaryObjective(eObjective objective) -{ - return objective == OBJECTIVE_LEAVE_VEHICLE || objective == OBJECTIVE_SET_LEADER || - objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER; -} - -void -CPed::SetMoveState(eMoveState state) -{ - m_nMoveState = state; -} - -void -CPed::SetObjectiveTimer(int time) -{ - if (time == 0) { - m_objectiveTimer = 0; - } else if (CTimer::GetTimeInMilliseconds() > m_objectiveTimer) { - m_objectiveTimer = CTimer::GetTimeInMilliseconds() + time; - } -} - -void -CPed::ForceStoredObjective(eObjective objective) -{ - if (objective != OBJECTIVE_ENTER_CAR_AS_DRIVER && objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER) { - m_prevObjective = m_objective; - return; - } - - switch (m_objective) - { - case OBJECTIVE_FLEE_TILL_SAFE: - case OBJECTIVE_KILL_CHAR_ON_FOOT: - case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: - case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: - case OBJECTIVE_GOTO_CHAR_ON_FOOT: - case OBJECTIVE_ENTER_CAR_AS_PASSENGER: - case OBJECTIVE_ENTER_CAR_AS_DRIVER: - case OBJECTIVE_GOTO_AREA_ON_FOOT: - case OBJECTIVE_RUN_TO_AREA: - return; - default: - m_prevObjective = m_objective; - } -} - -void -CPed::SetStoredObjective(void) -{ - if (m_objective == m_prevObjective) - return; - - switch (m_objective) - { - case OBJECTIVE_FLEE_TILL_SAFE: - case OBJECTIVE_KILL_CHAR_ON_FOOT: - case OBJECTIVE_KILL_CHAR_ANY_MEANS: - case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: - case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: - case OBJECTIVE_GOTO_CHAR_ON_FOOT: - case OBJECTIVE_FOLLOW_PED_IN_FORMATION: - case OBJECTIVE_LEAVE_VEHICLE: - case OBJECTIVE_ENTER_CAR_AS_PASSENGER: - case OBJECTIVE_ENTER_CAR_AS_DRIVER: - case OBJECTIVE_GOTO_AREA_ON_FOOT: - case OBJECTIVE_RUN_TO_AREA: - return; - default: - m_prevObjective = m_objective; - } -} - -void -CPed::RestorePreviousObjective(void) -{ - if (m_objective == OBJECTIVE_NONE) - return; - - if (m_objective != OBJECTIVE_LEAVE_VEHICLE && m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER) - m_pedInObjective = nil; - - if (m_objective == OBJECTIVE_WAIT_IN_CAR_THEN_GETOUT) { - m_objective = OBJECTIVE_NONE; - if (m_pMyVehicle) - SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle); - - } else { - m_objective = m_prevObjective; - m_prevObjective = OBJECTIVE_NONE; - } - m_ped_flagD40 = false; -} - -void -CPed::SetLeader(CEntity *leader) -{ - m_leader = (CPed*)leader; - - if(m_leader) - m_leader->RegisterReference((CEntity **)&m_leader); -} - -void -CPed::SetObjective(eObjective newObj, void *entity) -{ - if (m_nPedState == PED_DIE || m_nPedState == PED_DEAD) - return; - - if (m_prevObjective == newObj) { - // Why? - if (m_prevObjective != OBJECTIVE_NONE) - return; - } - - if (entity == this) - return; - - SetObjectiveTimer(0); - if (m_objective == newObj) { - switch (newObj) { - case OBJECTIVE_KILL_CHAR_ON_FOOT: - case OBJECTIVE_KILL_CHAR_ANY_MEANS: - case OBJECTIVE_GOTO_CHAR_ON_FOOT: - case OBJECTIVE_FOLLOW_PED_IN_FORMATION: - case OBJECTIVE_GOTO_AREA_ANY_MEANS: - case OBJECTIVE_FIGHT_CHAR: - if (m_pedInObjective == entity) - return; - - break; - case OBJECTIVE_LEAVE_VEHICLE: - case OBJECTIVE_FLEE_CAR: - return; - case OBJECTIVE_ENTER_CAR_AS_PASSENGER: - case OBJECTIVE_ENTER_CAR_AS_DRIVER: - case OBJECTIVE_DESTROY_CAR: - case OBJECTIVE_SOLICIT: - case OBJECTIVE_BUY_ICE_CREAM: - if (m_carInObjective == entity) - return; - - break; - case OBJECTIVE_SET_LEADER: - if (m_leader == entity) - return; - - break; - default: - break; - } - } else { - if (newObj == OBJECTIVE_LEAVE_VEHICLE && !bInVehicle) - return; - } - - m_ped_flagD40 = false; - if (!IsTemporaryObjective(m_objective) || IsTemporaryObjective(newObj)) { - if (m_objective != newObj) { - if (IsTemporaryObjective(newObj)) - ForceStoredObjective(newObj); - else - SetStoredObjective(); - } - m_objective = newObj; - } else { - m_prevObjective = newObj; - } - - switch (newObj) { - case OBJECTIVE_WAIT_IN_CAR_THEN_GETOUT: - - // In this special case, entity parameter isn't CEntity, but int. - SetObjectiveTimer((int)entity); - return; - case OBJECTIVE_KILL_CHAR_ON_FOOT: - case OBJECTIVE_KILL_CHAR_ANY_MEANS: - case OBJECTIVE_MUG_CHAR: - m_pLastPathNode = nil; - m_ped_flagD20 = false; - m_vecSeekVehicle = CVector(0.0f, 0.0f, 0.0f); - m_pedInObjective = (CPed*)entity; - m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); - m_pLookTarget = (CEntity*)entity; - m_pLookTarget->RegisterReference((CEntity**)&m_pLookTarget); - return; - case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: - case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: - case OBJECTIVE_GOTO_CHAR_ON_FOOT: - case OBJECTIVE_FIGHT_CHAR: - m_vecSeekVehicle = CVector(0.0f, 0.0f, 0.0f); - m_pedInObjective = (CPed*)entity; - m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); - return; - case OBJECTIVE_FOLLOW_PED_IN_FORMATION: - m_pedInObjective = (CPed*)entity; - m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); - m_pedFormation = 1; - return; - case OBJECTIVE_LEAVE_VEHICLE: - case OBJECTIVE_FLEE_CAR: - m_carInObjective = (CVehicle*)entity; - m_carInObjective->RegisterReference((CEntity **)&m_carInObjective); - if (!m_carInObjective->bIsBus || m_leaveCarTimer) - return; - break; - case OBJECTIVE_ENTER_CAR_AS_PASSENGER: - case OBJECTIVE_ENTER_CAR_AS_DRIVER: - if (m_nMoveState == PEDMOVE_STILL) - SetMoveState(PEDMOVE_RUN); - - if (((CVehicle*)entity)->m_vehType == VEHICLE_TYPE_BOAT && !IsPlayer()) { - RestorePreviousObjective(); - return; - } - // fall through - case OBJECTIVE_DESTROY_CAR: - case OBJECTIVE_SOLICIT: - case OBJECTIVE_BUY_ICE_CREAM: - m_carInObjective = (CVehicle*)entity; - m_carInObjective->RegisterReference((CEntity**)&m_carInObjective); - m_pSeekTarget = m_carInObjective; - m_pSeekTarget->RegisterReference((CEntity**)&m_pSeekTarget); - m_vecSeekVehicle = CVector(0.0f, 0.0f, 0.0f); - if (newObj == OBJECTIVE_SOLICIT) { - m_objectiveTimer = CTimer::GetTimeInMilliseconds() + 10000; - } else if (m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER && CharCreatedBy == MISSION_CHAR && - (m_carInObjective->m_status == STATUS_PLAYER_DISABLED || CPad::GetPad(CWorld::PlayerInFocus)->DisablePlayerControls)) { - SetObjectiveTimer(14000); - } else { - m_objectiveTimer = 0; - } - return; - case OBJECTIVE_SET_LEADER: - SetLeader((CEntity*)entity); - RestorePreviousObjective(); - return; - default: - return; - } - for (int i=0; i < m_carInObjective->m_nNumMaxPassengers; i++) { - if (m_carInObjective->pPassengers[i] == this) { - m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 1200 * i; - return; - } - } -} - -void -CPed::SetIdle(void) -{ - if (m_nPedState != PED_IDLE && m_nPedState != PED_MUG && m_nPedState != PED_FLEE_ENTITY) { - m_nPedState = PED_IDLE; - SetMoveState(PEDMOVE_STILL); - } - if (m_nWaitState == WAITSTATE_FALSE) { - m_nWaitTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(2000, 4000); - } -} - -void -CPed::SetObjective(eObjective newObj) -{ - if (m_nPedState == PED_DIE || m_nPedState == PED_DEAD) - return; - - if (newObj == OBJECTIVE_NONE) { - if ((m_objective == OBJECTIVE_LEAVE_VEHICLE || m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) - && IsPedInControl()) { - - m_ped_flagG8 = true; - return; - } - // Unused code from assembly... - /* - else if(m_objective == OBJECTIVE_FLEE_CAR) { - - } else { - - } - */ - m_objective = newObj; - m_prevObjective = OBJECTIVE_NONE; - } else if (m_prevObjective != newObj || m_prevObjective == OBJECTIVE_NONE) { - SetObjectiveTimer(0); - - if (m_objective == newObj) - return; - - if (IsTemporaryObjective(m_objective)) { - m_prevObjective = newObj; - } else { - if (m_objective != newObj) - SetStoredObjective(); - - m_objective = newObj; - } - m_ped_flagD40 = false; - - switch (newObj) { - case OBJECTIVE_NONE: - m_prevObjective = OBJECTIVE_NONE; - break; - case OBJECTIVE_HAIL_TAXI: - m_nWaitTimer = 0; - SetIdle(); - SetMoveState(PEDMOVE_STILL); - break; - default: - break; - } - } -} - -// Only used in 01E1: SET_CHAR_OBJ_FOLLOW_ROUTE opcode -// IDA fails very badly in here, puts a fake loop and ignores SetFollowRoute call... -void -CPed::SetObjective(eObjective newObj, int16 routePoint, int16 routeType) -{ - if (m_nPedState == PED_DIE || m_nPedState == PED_DEAD) - return; - - if (m_prevObjective == newObj && m_prevObjective != OBJECTIVE_NONE) - return; - - SetObjectiveTimer(0); - - if (m_objective == newObj && newObj == OBJECTIVE_FOLLOW_ROUTE && m_routeLastPoint == routePoint && m_routeType == routeType) - return; - - m_ped_flagD40 = false; - if (IsTemporaryObjective(m_objective)) { - m_prevObjective = newObj; - } else { - if (m_objective != newObj) - SetStoredObjective(); - - m_objective = newObj; - } - - if (newObj == OBJECTIVE_FOLLOW_ROUTE) { - SetFollowRoute(routePoint, routeType); - } -} - -void -CPed::ClearChat(void) -{ - CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_IDLE_CHAT); - if (animAssoc) { - animAssoc->blendDelta = -8.0f; - animAssoc->flags |= ASSOC_DELETEFADEDOUT; - } - bIsTalking = false; - ClearLookFlag(); - RestorePreviousState(); -} - -bool -CPed::IsGangMember(void) -{ - return m_nPedType >= PEDTYPE_GANG1 && m_nPedType <= PEDTYPE_GANG9; -} - -void -CPed::InformMyGangOfAttack(CEntity *attacker) -{ - CPed *attackerPed; - - if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS) - return; - - if (attacker->IsPed()) { - attackerPed = (CPed*)attacker; - } else { - if (!attacker->IsVehicle()) - return; - - attackerPed = ((CVehicle*)attacker)->pDriver; - if (!attackerPed) - return; - } - - if (attackerPed->m_nPedType == PEDTYPE_COP) - return; - - for (int i = 0; i < m_numNearPeds; i++) { - CPed *nearPed = m_nearPeds[i]; - if (nearPed && nearPed != this) { - CPed *leader = nearPed->m_leader; - if (leader && leader == this && nearPed->m_pedStats->m_fear < nearPed->m_pedStats->m_temper) - { - nearPed->SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, attackerPed); - nearPed->SetObjectiveTimer(30000); - } - } - } -} - -void -CPed::QuitEnteringCar(void) -{ - CAnimBlendAssociation *animAssoc = m_pVehicleAnim; - CVehicle *veh = m_pMyVehicle; - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - - RestartNonPartialAnims(); - - if (!RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_IDLE_STANCE)) - CAnimManager::BlendAnimation((RpClump*) m_rwObject, m_animGroup, ANIM_IDLE_STANCE, 100.0f); - - if (veh) { - if (m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || m_nPedState == PED_CARJACK) - veh->m_veh_flagC10 = false; - - if (veh->m_nNumGettingIn != 0) - veh->m_nNumGettingIn--; - - veh->m_nGettingInFlags = GetVehEnterExitFlag(m_vehEnterType); - } - - bUsesCollision = true; - - if (IsPlayer() && GetWeapon()->m_eWeaponType == WEAPONTYPE_UZI) { - if (IsPlayer() && m_storedWeapon != NO_STORED_WEAPON) { - SetCurrentWeapon(m_storedWeapon); - m_storedWeapon = NO_STORED_WEAPON; - } - } else { - CWeaponInfo *curWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - AddWeaponModel(curWeapon->m_nModelId); - } - if (m_nPedState == PED_DIE || m_nPedState == PED_DEAD) { - animAssoc = m_pVehicleAnim; - if (animAssoc) { - animAssoc->blendDelta = -4.0; - animAssoc->flags |= ASSOC_FADEOUTWHENDONE; - animAssoc = m_pVehicleAnim; - animAssoc->flags &= ~ASSOC_RUNNING; - } - } else - SetIdle(); - - m_pVehicleAnim = nil; - - if (veh) { - if (veh->m_autoPilot.m_nCruiseSpeed == 0) - veh->m_autoPilot.m_nCruiseSpeed = 17; - } -} - -void -CPed::ReactToAttack(CEntity *attacker) -{ - if (IsPlayer() && attacker->IsPed()) { - InformMyGangOfAttack(attacker); - SetLookFlag(attacker, 1); - SetLookTimer(700); - return; - } - - if (IsPedInControl() && (CharCreatedBy != MISSION_CHAR || bRespondsToThreats)) { - CPed *ourLeader = m_leader; - if (ourLeader != attacker && (!ourLeader || FindPlayerPed() != ourLeader) - && attacker->IsPed()) { - - CPed *attackerPed = (CPed*)attacker; - if (bNotAllowedToDuck) { - if (!attackerPed->GetWeapon()->IsTypeMelee()) { - field_4E8 = CTimer::GetTimeInMilliseconds(); - return; - } - } else if (bCrouchWhenShooting || m_ped_flagE1) { - SetDuck(CGeneral::GetRandomNumberInRange(1000,3000)); - return; - } - - if (m_pedStats->m_fear <= 100 - attackerPed->m_pedStats->m_temper) { - if (m_pedStats != attackerPed->m_pedStats) { - if (IsGangMember() || m_nPedType == PEDTYPE_EMERGENCY || m_nPedType == PEDTYPE_FIREMAN) { - RegisterThreatWithGangPeds(attackerPed); - } - if (!attackerPed->GetWeapon()->IsTypeMelee() && GetWeapon()->IsTypeMelee()) { - SetObjective(OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, attacker); - SetMoveState(PEDMOVE_RUN); - } else { - SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, attacker); - SetObjectiveTimer(20000); - } - } - } else { - SetObjective(OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, attackerPed); - SetMoveState(PEDMOVE_RUN); - if (attackerPed->GetWeapon()->IsTypeMelee()) - Say(SOUND_PED_FLEE_RUN); - } - } - } -} - -bool -CPed::TurnBody(void) -{ - float lookDir; - bool doneSmoothly = true; - - if (m_pLookTarget) { - CVector &lookPos = m_pLookTarget->GetPosition(); - - lookDir = CGeneral::GetRadianAngleBetweenPoints( - lookPos.x, - lookPos.y, - GetPosition().x, - GetPosition().y); - } else - lookDir = m_fLookDirection; - - float limitedLookDir = CGeneral::LimitRadianAngle(lookDir); - float currentRot = m_fRotationCur; - - if (currentRot - PI > limitedLookDir) - limitedLookDir += 2 * PI; - else if (PI + currentRot < limitedLookDir) - limitedLookDir -= 2 * PI; - - float neededTurn = currentRot - limitedLookDir; - m_fRotationDest = limitedLookDir; - - if (fabs(neededTurn) > 0.05f) { - doneSmoothly = false; - currentRot -= neededTurn * 0.2f; - } - - m_fRotationCur = currentRot; - m_fLookDirection = limitedLookDir; - return doneSmoothly; -} - -void -CPed::Chat(void) -{ - if (bIsLooking && TurnBody()) - ClearLookFlag(); - - if (!m_pLookTarget || !m_pLookTarget->IsPed()) { - ClearChat(); - return; - } - - CPed *partner = (CPed*) m_pLookTarget; - - if (partner->m_nPedState != PED_CHAT) { - ClearChat(); - if (partner->m_pedInObjective) { - if (partner->m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || - partner->m_objective == OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE) - ReactToAttack(partner->m_pedInObjective); - } - return; - } - if (bIsTalking) { - if (CGeneral::GetRandomNumber() < 512) { - CAnimBlendAssociation *chatAssoc = RpAnimBlendClumpGetAssociation((RpClump*) m_rwObject, ANIM_IDLE_CHAT); - if (chatAssoc) { - chatAssoc->blendDelta = -4.0f; - chatAssoc->flags |= ASSOC_FADEOUTWHENDONE; - } - bIsTalking = false; - } else - Say(SOUND_PED_CHAT); - - } else if (!RpAnimBlendClumpGetFirstAssociation((RpClump*)m_rwObject, ASSOC_FLAG100)) { - - if (CGeneral::GetRandomNumber() < 20) { - CAnimManager::BlendAnimation((RpClump*) m_rwObject, ASSOCGRP_STD, ANIM_XPRESS_SCRATCH, 4.0f); - } - if (!bIsTalking) { - CAnimBlendAssociation *chatAssoc = CAnimManager::BlendAnimation((RpClump*) m_rwObject, ASSOCGRP_STD, ANIM_IDLE_CHAT, 4.0f); - float chatTime = CGeneral::GetRandomNumberInRange(0.0f, 3.0f); - chatAssoc->SetCurrentTime(chatTime); - - bIsTalking = true; - Say(SOUND_PED_CHAT); - } - } - if (m_standardTimer && CTimer::GetTimeInMilliseconds() > m_standardTimer) { - ClearChat(); - m_standardTimer = CTimer::GetTimeInMilliseconds() + 30000; - } -} - -WRAPPER void CPed::PedGetupCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE810); } -WRAPPER void CPed::PedStaggerCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE8D0); } -WRAPPER void CPed::PedEvadeCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D36E0); } -WRAPPER void CPed::FinishDieAnimCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D3950); } -WRAPPER void CPed::FinishedWaitCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D6520); } -WRAPPER void CPed::FinishLaunchCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D7490); } -WRAPPER void CPed::FinishHitHeadCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D7A80); } -WRAPPER void CPed::PedAnimGetInCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4DEC80); } -WRAPPER void CPed::PedAnimDoorOpenCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4DE500); } -WRAPPER void CPed::PedAnimPullPedOutCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4DEAF0); } -WRAPPER void CPed::PedAnimDoorCloseCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4DF1B0); } -WRAPPER void CPed::SetInCarCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CF220); } -WRAPPER void CPed::PedSetOutCarCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE8F0); } -WRAPPER void CPed::PedAnimAlignCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4DE130); } -WRAPPER void CPed::PedAnimStepOutCarCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4DF5C0); } -WRAPPER void CPed::PedSetInTrainCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4E3290); } -WRAPPER void CPed::PedSetOutTrainCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4E36E0); } -WRAPPER void CPed::FinishFightMoveCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4E9830); } -WRAPPER void CPed::PedAnimDoorCloseRollingCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4E4B90); } -WRAPPER void CPed::FinishJumpCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D7A50); } -WRAPPER void CPed::PedLandCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE8A0); } -WRAPPER void FinishFuckUCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4C6580); } -WRAPPER void CPed::RestoreHeadingRateCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4D6550); } - -STARTPATCHES - InjectHook(0x4C41C0, &CPed::ctor, PATCH_JUMP); - InjectHook(0x4C50D0, &CPed::dtor, PATCH_JUMP); - InjectHook(0x4CF8F0, &CPed::AddWeaponModel, PATCH_JUMP); - InjectHook(0x4C6AA0, &CPed::AimGun, PATCH_JUMP); - InjectHook(0x4EB470, &CPed::ApplyHeadShot, PATCH_JUMP); - InjectHook(0x4EAEE0, &CPed::RemoveBodyPart, PATCH_JUMP); - InjectHook(0x4C6460, (void (CPed::*)(CEntity*, bool)) &CPed::SetLookFlag, PATCH_JUMP); - InjectHook(0x4C63E0, (void (CPed::*)(float, bool)) &CPed::SetLookFlag, PATCH_JUMP); - InjectHook(0x4D12E0, &CPed::SetLookTimer, PATCH_JUMP); - InjectHook(0x4C5700, &CPed::OurPedCanSeeThisOne, PATCH_JUMP); - InjectHook(0x4D2BB0, &CPed::Avoid, PATCH_JUMP); - InjectHook(0x4C6A50, &CPed::ClearAimFlag, PATCH_JUMP); - InjectHook(0x4C64F0, &CPed::ClearLookFlag, PATCH_JUMP); - InjectHook(0x4EB670, &CPed::IsPedHeadAbovePos, PATCH_JUMP); - InjectHook(0x4E68A0, &CPed::FinishedAttackCB, PATCH_JUMP); - InjectHook(0x4E5BD0, &CheckForPedsOnGroundToAttack, PATCH_JUMP); - InjectHook(0x4E6BA0, &CPed::Attack, PATCH_JUMP); - InjectHook(0x4CF980, &CPed::RemoveWeaponModel, PATCH_JUMP); - InjectHook(0x4CFA60, &CPed::SetCurrentWeapon, PATCH_JUMP); - InjectHook(0x4E4A10, &CPed::Duck, PATCH_JUMP); - InjectHook(0x4E4A30, &CPed::ClearDuck, PATCH_JUMP); - InjectHook(0x4E6180, &CPed::ClearPointGunAt, PATCH_JUMP); - InjectHook(0x4E07D0, &CPed::BeingDraggedFromCar, PATCH_JUMP); - InjectHook(0x4CF000, &CPed::PedSetDraggedOutCarCB, PATCH_JUMP); - InjectHook(0x4C5D80, &CPed::RestartNonPartialAnims, PATCH_JUMP); - InjectHook(0x4E4730, &CPed::GetLocalPositionToOpenCarDoor, PATCH_JUMP); - InjectHook(0x4E4660, (void (*)(CVector*, CVehicle*, uint32, float)) CPed::GetPositionToOpenCarDoor, PATCH_JUMP); - InjectHook(0x4E1A30, (void (*)(CVector*, CVehicle*, uint32)) CPed::GetPositionToOpenCarDoor, PATCH_JUMP); - InjectHook(0x4DF940, &CPed::LineUpPedWithCar, PATCH_JUMP); - InjectHook(0x4CC6C0, &CPed::PlayFootSteps, PATCH_JUMP); - InjectHook(0x4C5350, &CPed::BuildPedLists, PATCH_JUMP); - InjectHook(0x4CF9B0, &CPed::GiveWeapon, PATCH_JUMP); - InjectHook(0x4C52A0, &CPed::SetModelIndex_, PATCH_JUMP); - InjectHook(0x4D6570, &CPed::FlagToDestroyWhenNextProcessed_, PATCH_JUMP); - InjectHook(0x4A7D30, &CPed::SetupLighting_, PATCH_JUMP); - InjectHook(0x4A7DC0, &CPed::RemoveLighting_, PATCH_JUMP); - InjectHook(0x4D3E70, &CPed::Teleport_, PATCH_JUMP); - InjectHook(0x4C7EA0, &CPed::CalculateNewOrientation, PATCH_JUMP); - InjectHook(0x4C78F0, &CPed::WorkOutHeadingForMovingFirstPerson, PATCH_JUMP); - InjectHook(0x4C73F0, &CPed::CalculateNewVelocity, PATCH_JUMP); - InjectHook(0x4D72F0, &CPed::CanPedJumpThis, PATCH_JUMP); - InjectHook(0x4DD820, &CPed::CanSeeEntity, PATCH_JUMP); - InjectHook(0x4D9460, &CPed::RestorePreviousObjective, PATCH_JUMP); - InjectHook(0x4D82C0, (void (CPed::*)(eObjective)) &CPed::SetObjective, PATCH_JUMP); - InjectHook(0x4D83E0, (void (CPed::*)(eObjective, void*)) &CPed::SetObjective, PATCH_JUMP); - InjectHook(0x4D89A0, (void (CPed::*)(eObjective, int16, int16)) &CPed::SetObjective, PATCH_JUMP); - InjectHook(0x4DDEC0, &CPed::ReactToAttack, PATCH_JUMP); - InjectHook(0x4D0600, &CPed::SetIdle, PATCH_JUMP); - InjectHook(0x4E0E00, &CPed::QuitEnteringCar, PATCH_JUMP); - InjectHook(0x4E4AD0, &CPed::InformMyGangOfAttack, PATCH_JUMP); - InjectHook(0x4D3C80, &CPed::ClearChat, PATCH_JUMP); - InjectHook(0x4D1390, &CPed::TurnBody, PATCH_JUMP); - InjectHook(0x4D3AC0, &CPed::Chat, PATCH_JUMP); -ENDPATCHES diff --git a/src/entities/Ped.h b/src/entities/Ped.h deleted file mode 100644 index 95731e15..00000000 --- a/src/entities/Ped.h +++ /dev/null @@ -1,577 +0,0 @@ -#pragma once - -#include "Physical.h" -#include "Weapon.h" -#include "PedStats.h" -#include "PedType.h" -#include "PedIK.h" -#include "AnimManager.h" -#include "AnimBlendClumpData.h" -#include "AnimBlendAssociation.h" -#include "WeaponInfo.h" -#include "Fire.h" - -struct CPathNode; - -enum eWaitState : uint32 { - WAITSTATE_FALSE, - WAITSTATE_TRAFFIC_LIGHTS, - WAITSTATE_CROSS_ROAD, - WAITSTATE_CROSS_ROAD_LOOK, - WAITSTATE_LOOK_PED, - WAITSTATE_LOOK_SHOP, - WAITSTATE_LOOK_ACCIDENT, - WAITSTATE_FACEOFF_GANG, - WAITSTATE_DOUBLEBACK, - WAITSTATE_HITWALL, - WAITSTATE_TURN180, - WAITSTATE_SURPRISE, - WAITSTATE_STUCK, - WAITSTATE_LOOK_ABOUT, - WAITSTATE_PLAYANIM_DUCK, - WAITSTATE_PLAYANIM_COWER, - WAITSTATE_PLAYANIM_TAXI, - WAITSTATE_PLAYANIM_HANDSUP, - WAITSTATE_PLAYANIM_HANDSCOWER, - WAITSTATE_PLAYANIM_CHAT, - WAITSTATE_FINISH_FLEE -}; - -enum eObjective : uint32 { - OBJECTIVE_NONE, - OBJECTIVE_IDLE, - OBJECTIVE_FLEE_TILL_SAFE, - OBJECTIVE_GUARD_SPOT, - OBJECTIVE_GUARD_AREA, - OBJECTIVE_WAIT_IN_CAR, - OBJECTIVE_WAIT_IN_CAR_THEN_GETOUT, - OBJECTIVE_KILL_CHAR_ON_FOOT, - OBJECTIVE_KILL_CHAR_ANY_MEANS, - OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, - OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS, - OBJECTIVE_GOTO_CHAR_ON_FOOT, - OBJECTIVE_FOLLOW_PED_IN_FORMATION, - OBJECTIVE_LEAVE_VEHICLE, - OBJECTIVE_ENTER_CAR_AS_PASSENGER, - OBJECTIVE_ENTER_CAR_AS_DRIVER, - OBJECTIVE_FOLLOW_CAR_IN_CAR, - OBJECTIVE_FIRE_AT_OBJ_FROM_VEHICLE, - OBJECTIVE_DESTROY_OBJ, - OBJECTIVE_DESTROY_CAR, - OBJECTIVE_GOTO_AREA_ANY_MEANS, - OBJECTIVE_GOTO_AREA_ON_FOOT, - OBJECTIVE_RUN_TO_AREA, - OBJECTIVE_23, - OBJECTIVE_24, - OBJECTIVE_FIGHT_CHAR, - OBJECTIVE_SET_LEADER, - OBJECTIVE_FOLLOW_ROUTE, - OBJECTIVE_SOLICIT, - OBJECTIVE_HAIL_TAXI, - OBJECTIVE_CATCH_TRAIN, - OBJECTIVE_BUY_ICE_CREAM, - OBJECTIVE_STEAL_ANY_CAR, - OBJECTIVE_MUG_CHAR, - OBJECTIVE_FLEE_CAR, - OBJECTIVE_35 -}; - -enum eVehEnter : uint16 { - VEHICLE_ENTER_FRONT_RIGHT = 11, - VEHICLE_ENTER_REAR_RIGHT = 12, - VEHICLE_ENTER_FRONT_LEFT = 15, - VEHICLE_ENTER_REAR_LEFT = 16, -}; - -enum { - RANDOM_CHAR = 1, - MISSION_CHAR, -}; - -enum PedLineUpPhase { - LINE_UP_TO_CAR_START, - LINE_UP_TO_CAR_END, - LINE_UP_TO_CAR_2 -}; - -enum PedOnGroundState { - NO_PED, - PED_BELOW_PLAYER, - PED_ON_THE_FLOOR, - PED_DEAD_ON_THE_FLOOR -}; - -enum PedState -{ - PED_NONE, - PED_IDLE, - PED_LOOK_ENTITY, - PED_LOOK_HEADING, - PED_WANDER_RANGE, - PED_WANDER_PATH, - PED_SEEK_POS, - PED_SEEK_ENTITY, - PED_FLEE_POS, - PED_FLEE_ENTITY, - PED_PURSUE, - PED_FOLLOW_PATH, - PED_SNIPER_MODE, - PED_ROCKET_ODE, - PED_DUMMY, - PED_PAUSE, - PED_ATTACK, - PED_FIGHT, - PED_FACE_PHONE, - PED_MAKE_CALL, - PED_CHAT, - PED_MUG, - PED_AIM_GUN, - PED_AI_CONTROL, - PED_SEEK_CAR, - PED_SEEK_IN_BOAT, - PED_FOLLOW_ROUTE, - PED_CPR, - PED_SOLICIT, - PED_BUY_ICECREAM, - PED_INVESTIGATE, - PED_STEP_AWAY, - PED_ON_FIRE, - - PED_UNKNOWN, // HANG_OUT in Fire_Head's idb - - PED_STATES_NO_AI, - PED_JUMP, - PED_FALL, - PED_GETUP, - PED_STAGGER, - PED_DIVE_AWAY, - - PED_STATES_NO_ST, - PED_ENTER_TRAIN, - PED_EXIT_TRAIN, - PED_ARREST_PLAYER, - PED_DRIVING, - PED_PASSENGER, - PED_TAXI_PASSENGER, - PED_OPEN_DOOR, - PED_DIE, - PED_DEAD, - PED_CARJACK, - PED_DRAG_FROM_CAR, - PED_ENTER_CAR, - PED_STEAL_CAR, - PED_EXIT_CAR, - PED_HANDS_UP, - PED_ARRESTED, -}; - -enum eMoveState { - PEDMOVE_NONE, - PEDMOVE_STILL, - PEDMOVE_WALK, - PEDMOVE_RUN, - PEDMOVE_SPRINT, -}; - -class CVehicle; - -class CPed : public CPhysical -{ -public: - // 0x128 - CStoredCollPoly m_collPoly; - float m_fCollisionSpeed; - - // cf. https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/CPed.h from R* - uint8 bIsStanding : 1; - uint8 m_ped_flagA2 : 1; - uint8 m_ped_flagA4 : 1; // stores (CTimer::GetTimeInMilliseconds() < m_lastHitTime) - uint8 bIsPointingGunAt : 1; - uint8 bIsLooking : 1; - uint8 m_ped_flagA20 : 1; // "look" method? - probably missing in SA - uint8 bIsRestoringLook : 1; - uint8 bIsAimingGun : 1; - - uint8 bIsRestoringGun : 1; - uint8 bCanPointGunAtTarget : 1; - uint8 bIsTalking : 1; - uint8 bIsInTheAir : 1; - uint8 bIsLanding : 1; - uint8 m_ped_flagB20 : 1; - uint8 m_ped_flagB40 : 1; - uint8 m_ped_flagB80 : 1; - - uint8 m_ped_flagC1 : 1; - uint8 bRespondsToThreats : 1; - uint8 m_ped_flagC4 : 1; // false when in bus, bRenderPedInCar? - uint8 m_ped_flagC8 : 1; - uint8 m_ped_flagC10 : 1; - uint8 m_ped_flagC20 : 1; // just left some body part? - uint8 m_ped_flagC40 : 1; - uint8 m_ped_flagC80 : 1; - - uint8 m_ped_flagD1 : 1; - uint8 m_ped_flagD2 : 1; - uint8 m_ped_flagD4 : 1; - uint8 m_ped_flagD8 : 1; - uint8 m_ped_flagD10 : 1; - uint8 m_ped_flagD20 : 1; - uint8 m_ped_flagD40 : 1; // reset when objective changes - uint8 m_ped_flagD80 : 1; - - uint8 m_ped_flagE1 : 1; - uint8 m_ped_flagE2 : 1; - uint8 bNotAllowedToDuck : 1; - uint8 bCrouchWhenShooting : 1; - uint8 bIsDucking : 1; // set if you don't want ped to attack - uint8 m_ped_flagE20 : 1; - uint8 bDoBloodyFootprints : 1; - uint8 m_ped_flagE80 : 1; - - uint8 m_ped_flagF1 : 1; - uint8 m_ped_flagF2 : 1; - uint8 m_ped_flagF4 : 1; - uint8 m_ped_flagF8 : 1; - uint8 m_ped_flagF10 : 1; - uint8 m_ped_flagF20 : 1; - uint8 m_ped_flagF40 : 1; - uint8 m_ped_flagF80 : 1; - - uint8 m_ped_flagG1 : 1; - uint8 m_ped_flagG2 : 1; - uint8 m_ped_flagG4 : 1; - uint8 m_ped_flagG8 : 1; - uint8 m_ped_flagG10 : 1; - uint8 m_ped_flagG20 : 1; - uint8 m_ped_flagG40 : 1; - uint8 m_ped_flagG80 : 1; - - uint8 m_ped_flagH1 : 1; - uint8 m_ped_flagH2 : 1; - uint8 m_ped_flagH4 : 1; - uint8 m_ped_flagH8 : 1; - uint8 m_ped_flagH10 : 1; - uint8 m_ped_flagH20 : 1; - uint8 m_ped_flagH40 : 1; - uint8 m_ped_flagH80 : 1; - - uint8 m_ped_flagI1 : 1; - uint8 m_ped_flagI2 : 1; - uint8 m_ped_flagI4 : 1; - uint8 bRecordedForReplay : 1; - uint8 m_ped_flagI10 : 1; - uint8 m_ped_flagI20 : 1; - uint8 m_ped_flagI40 : 1; - uint8 m_ped_flagI80 : 1; - - uint8 stuff10[3]; - uint8 CharCreatedBy; - uint8 field_161; - uint8 pad_162[2]; - eObjective m_objective; - eObjective m_prevObjective; - CPed *m_pedInObjective; - CVehicle *m_carInObjective; - uint32 field_174; - uint32 field_178; - uint32 field_17C; - CPed *m_leader; - uint32 m_pedFormation; - uint32 m_fearFlags; - CEntity *m_threatEntity; - CVector2D m_eventOrThread; - uint32 m_eventType; - CEntity* m_pEventEntity; - float m_fAngleToEvent; - AnimBlendFrameData *m_pFrames[PED_NODE_MAX]; - AssocGroupId m_animGroup; - CAnimBlendAssociation *m_pVehicleAnim; - CVector2D m_vecAnimMoveDelta; - CVector m_vecOffsetSeek; - CPedIK m_pedIK; - float m_actionX; - float m_actionY; - uint32 m_nPedStateTimer; - PedState m_nPedState; - PedState m_nLastPedState; - eMoveState m_nMoveState; - int32 m_nStoredActionState; - int32 m_nPrevActionState; - eWaitState m_nWaitState; - uint32 m_nWaitTimer; - void *m_pPathNodesStates[8]; - CVector2D m_stPathNodeStates[10]; - uint16 m_nPathNodes; - uint8 m_nCurPathNode; - int8 m_nPathState; -private: - int8 _pad2B5[3]; -public: - CPathNode *m_pNextPathNode; - CPathNode *m_pLastPathNode; - float m_fHealth; - float m_fArmour; - int16 m_routeLastPoint; - uint16 m_routePoints; - int16 m_routePos; - int16 m_routeType; - int16 m_routeCurDir; - uint16 field_2D2; - CVector2D m_moved; - float m_fRotationCur; - float m_fRotationDest; - float m_headingRate; - eVehEnter m_vehEnterType; - uint16 m_walkAroundType; - CEntity *m_pCurrentPhysSurface; - CVector m_vecOffsetFromPhysSurface; - CEntity *m_pCurSurface; - CVector m_vecSeekVehicle; - CEntity *m_pSeekTarget; - CVehicle *m_pMyVehicle; - bool bInVehicle; - uint8 pad_315[3]; - uint32 field_318; - uint8 field_31C; - uint8 field_31D; - int16 m_phoneId; - uint32 m_lookingForPhone; - uint32 m_phoneTalkTimer; - void *m_lastAccident; - int32 m_nPedType; - CPedStats *m_pedStats; - float m_fleeFromPosX; - float m_fleeFromPosY; - CEntity *m_fleeFrom; - uint32 m_fleeTimer; - uint32 field_344; - uint32 m_lastThreatTimer; - CEntity *m_pCollidingEntity; - uint8 m_stateUnused; - uint8 pad_351[3]; - uint32 m_timerUnused; - CEntity *m_targetUnused; - CWeapon m_weapons[NUM_PED_WEAPONTYPES]; - eWeaponType m_storedWeapon; - uint8 m_currentWeapon; // eWeaponType - uint8 m_maxWeaponTypeAllowed; // eWeaponType - uint8 m_wepSkills; - uint8 m_wepAccuracy; - CEntity *m_pPointGunAt; - CVector m_vecHitLastPos; - uint32 m_lastHitState; - uint8 m_fightFlags1; - uint8 m_fightFlags2; - uint8 pad_4B2[2]; - CFire* m_pFire; - CEntity *m_pLookTarget; - float m_fLookDirection; - int32 m_wepModelID; - uint32 m_leaveCarTimer; - uint32 m_getUpTimer; - uint32 m_lookTimer; - uint32 m_standardTimer; - uint32 m_attackTimer; - uint32 m_lastHitTime; - uint32 m_hitRecoverTimer; - uint32 m_objectiveTimer; - uint32 m_duckTimer; - uint32 field_4E8; - int32 m_bloodyFootprintCount; - uint8 stuff9[2]; - int8 m_bodyPartBleeding; // PedNode - uint8 m_field_4F3; - CPed *m_nearPeds[10]; - uint16 m_numNearPeds; - int8 m_lastWepDam; - uint8 pad_51F; - uint8 field_520; - uint8 pad_521[3]; - uint32 m_talkTimer; - uint16 m_talkTypeLast; - uint16 m_talkType; - CVector m_vecSeekPosEx; - float m_seekExAngle; - - static void *operator new(size_t); - static void *operator new(size_t, int); - static void operator delete(void*, size_t); - static void operator delete(void*, int); - - CPed(uint32 pedType); - virtual ~CPed(void); - - virtual void SetModelIndex(uint32 mi); - virtual void ProcessControl(void); - virtual void Teleport(CVector); - virtual void PreRender(void); - virtual void Render(void); - virtual bool SetupLighting(void); - virtual void RemoveLighting(bool); - virtual void FlagToDestroyWhenNextProcessed(void); - virtual int32 ProcessEntityCollision(CEntity*, CColPoint*); - virtual void SetMoveAnim(void); - - CPed* ctor(uint32 pedType) { return ::new (this) CPed(pedType); } - void dtor(void) { this->CPed::~CPed(); } - - void AddWeaponModel(int id); - void AimGun(void); - void KillPedWithCar(CVehicle *veh, float impulse); - void Say(uint16 audio); - void SetLookFlag(CEntity *target, bool unknown); - void SetLookFlag(float direction, bool unknown); - void SetLookTimer(int time); - void SetDie(AnimationId anim, float arg1, float arg2); - void ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer); - void RemoveBodyPart(PedNode nodeId, int8 unknown); - void SpawnFlyingComponent(int, int8 unknown); - bool OurPedCanSeeThisOne(CEntity *target); - void Avoid(void); - void Attack(void); - void ClearAimFlag(void); - void ClearLookFlag(void); - void RestorePreviousState(void); - void ClearAttack(void); - bool IsPedHeadAbovePos(float zOffset); - void RemoveWeaponModel(int modelId); - void SetCurrentWeapon(uint32 weaponType); - void Duck(void); - void ClearDuck(void); - void ClearPointGunAt(void); - void BeingDraggedFromCar(void); - void RestartNonPartialAnims(void); - void LineUpPedWithCar(PedLineUpPhase phase); - void SetPedPositionInCar(void); - void PlayFootSteps(void); - void QuitEnteringCar(void); - void BuildPedLists(void); - uint32 GiveWeapon(eWeaponType weaponType, uint32 ammo); - void CalculateNewOrientation(void); - float WorkOutHeadingForMovingFirstPerson(float); - void CalculateNewVelocity(void); - bool CanPedJumpThis(int32); - bool CanSeeEntity(CEntity*, float); - void RestorePreviousObjective(void); - void SetIdle(void); - void SetObjective(eObjective, void*); - void SetObjective(eObjective); - void SetObjective(eObjective, int16, int16); - void ClearChat(void); - void InformMyGangOfAttack(CEntity*); - void SetFollowRoute(int16, int16); - void ReactToAttack(CEntity*); - void SetDuck(uint32); - void RegisterThreatWithGangPeds(CEntity*); - bool TurnBody(void); - void Chat(void); - - // Static methods - static void GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float offset); - static void GetPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float seatPosMult); - static void GetPositionToOpenCarDoor(CVector* output, CVehicle* veh, uint32 enterType); - - // Callbacks - static RwObject *SetPedAtomicVisibilityCB(RwObject *object, void *data); - static RwFrame *RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data); - static void PedGetupCB(CAnimBlendAssociation *assoc, void *arg); - static void PedStaggerCB(CAnimBlendAssociation *assoc, void *arg); - static void PedEvadeCB(CAnimBlendAssociation *assoc, void *arg); - static void FinishDieAnimCB(CAnimBlendAssociation *assoc, void *arg); - static void FinishedWaitCB(CAnimBlendAssociation *assoc, void *arg); - static void FinishLaunchCB(CAnimBlendAssociation *assoc, void *arg); - static void FinishHitHeadCB(CAnimBlendAssociation *assoc, void *arg); - static void PedAnimGetInCB(CAnimBlendAssociation *assoc, void *arg); - static void PedAnimDoorOpenCB(CAnimBlendAssociation *assoc, void *arg); - static void PedAnimPullPedOutCB(CAnimBlendAssociation *assoc, void *arg); - static void PedAnimDoorCloseCB(CAnimBlendAssociation *assoc, void *arg); - static void SetInCarCB(CAnimBlendAssociation *assoc, void *arg); - static void PedSetOutCarCB(CAnimBlendAssociation *assoc, void *arg); - static void PedAnimAlignCB(CAnimBlendAssociation *assoc, void *arg); - static void PedSetDraggedOutCarCB(CAnimBlendAssociation *assoc, void *arg); - static void PedAnimStepOutCarCB(CAnimBlendAssociation *assoc, void *arg); - static void PedSetInTrainCB(CAnimBlendAssociation *assoc, void *arg); - static void PedSetOutTrainCB(CAnimBlendAssociation *assoc, void *arg); - static void FinishedAttackCB(CAnimBlendAssociation *assoc, void *arg); - static void FinishFightMoveCB(CAnimBlendAssociation *assoc, void *arg); - static void PedAnimDoorCloseRollingCB(CAnimBlendAssociation *assoc, void *arg); - static void FinishJumpCB(CAnimBlendAssociation *assoc, void *arg); - static void PedLandCB(CAnimBlendAssociation *assoc, void *arg); - static void RestoreHeadingRateCB(CAnimBlendAssociation *assoc, void *arg); - static void PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *assoc, void *arg); - static void PedSetDraggedOutCarPositionCB(CAnimBlendAssociation *assoc, void *arg); - - // functions that I see unnecessary to hook - bool IsPlayer(void); - bool UseGroundColModel(void); - bool CanSetPedState(void); - bool IsPedInControl(void); - bool CanPedDriveOff(void); - bool CanBeDeleted(void); - bool CanStrafeOrMouseControl(void); - bool CanPedReturnToState(void); - void SetMoveState(eMoveState); - bool IsTemporaryObjective(eObjective objective); - void SetObjectiveTimer(int); - bool SelectGunIfArmed(void); - bool IsPointerValid(void); - void SortPeds(CPed**, int, int); - void ForceStoredObjective(eObjective); - void SetStoredObjective(void); - void SetLeader(CEntity* leader); - void SetPedStats(ePedStats); - bool IsGangMember(void); - - bool HasWeapon(uint8 weaponType) { return m_weapons[weaponType].m_eWeaponType == weaponType; } - CWeapon &GetWeapon(uint8 weaponType) { return m_weapons[weaponType]; } - CWeapon *GetWeapon(void) { return &m_weapons[m_currentWeapon]; } - RwFrame *GetNodeFrame(int nodeId) { return m_pFrames[nodeId]->frame; } - static uint8 GetVehEnterExitFlag(eVehEnter vehEnter) { - switch (vehEnter) { - case VEHICLE_ENTER_FRONT_RIGHT: - return 4; - case VEHICLE_ENTER_REAR_RIGHT: - return 8; - case VEHICLE_ENTER_FRONT_LEFT: - return 1; - case VEHICLE_ENTER_REAR_LEFT: - return 2; - default: - return 0; - } - } - PedState GetPedState(void) { return m_nPedState; } - void SetPedState(PedState state) { m_nPedState = state; } - - // to make patching virtual functions possible - void SetModelIndex_(uint32 mi) { CPed::SetModelIndex(mi); } - void FlagToDestroyWhenNextProcessed_(void) { CPed::FlagToDestroyWhenNextProcessed(); } - bool SetupLighting_(void) { return CPed::SetupLighting(); } - void RemoveLighting_(bool reset) { CPed::RemoveLighting(reset); } - void Teleport_(CVector pos) { CPed::Teleport(pos); } - - // set by 0482:set_threat_reaction_range_multiplier opcode - static uint16 &distanceMultToCountPedNear; - - static CVector &offsetToOpenRegularCarDoor; - static CVector &offsetToOpenLowCarDoor; - static CVector &offsetToOpenVanDoor; - static bool &bNastyLimbsCheat; - static bool &bPedCheat2; - static bool &bPedCheat3; -}; - -void FinishFuckUCB(CAnimBlendAssociation *assoc, void *arg); - -static_assert(offsetof(CPed, m_nPedState) == 0x224, "CPed: error"); -static_assert(offsetof(CPed, m_pCurSurface) == 0x2FC, "CPed: error"); -static_assert(offsetof(CPed, m_pMyVehicle) == 0x310, "CPed: error"); -static_assert(offsetof(CPed, m_nPedType) == 0x32C, "CPed: error"); -static_assert(offsetof(CPed, m_pCollidingEntity) == 0x34C, "CPed: error"); -static_assert(offsetof(CPed, m_weapons) == 0x35C, "CPed: error"); -static_assert(offsetof(CPed, m_currentWeapon) == 0x498, "CPed: error"); -static_assert(offsetof(CPed, m_lookTimer) == 0x4CC, "CPed: error"); -static_assert(offsetof(CPed, m_bodyPartBleeding) == 0x4F2, "CPed: error"); -static_assert(offsetof(CPed, m_pedInObjective) == 0x16C, "CPed: error"); -static_assert(offsetof(CPed, m_pEventEntity) == 0x19C, "CPed: error"); -static_assert(sizeof(CPed) == 0x53C, "CPed: error"); diff --git a/src/entities/PedIK.cpp b/src/entities/PedIK.cpp deleted file mode 100644 index b9baf49c..00000000 --- a/src/entities/PedIK.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "PedIK.h" -#include "Ped.h" - -WRAPPER bool CPedIK::PointGunInDirection(float phi, float theta) { EAXJMP(0x4ED9B0); } -WRAPPER bool CPedIK::PointGunAtPosition(CVector *position) { EAXJMP(0x4ED920); } -WRAPPER void CPedIK::ExtractYawAndPitchLocal(RwMatrixTag*, float*, float*) { EAXJMP(0x4ED2C0); } -WRAPPER void CPedIK::ExtractYawAndPitchWorld(RwMatrixTag*, float*, float*) { EAXJMP(0x4ED140); } - -CPedIK::CPedIK(CPed *ped) -{ - m_ped = ped; - m_flags = 0; - m_headOrient.phi = 0.0f; - m_headOrient.theta = 0.0f; - m_torsoOrient.phi = 0.0f; - m_torsoOrient.theta = 0.0f; - m_upperArmOrient.phi = 0.0f; - m_upperArmOrient.theta = 0.0f; - m_lowerArmOrient.phi = 0.0f; - m_lowerArmOrient.theta = 0.0f; -} - -void -CPedIK::RotateTorso(AnimBlendFrameData *animBlend, LimbOrientation *limb, bool changeRoll) -{ - RwFrame *f = animBlend->frame; - RwMatrix *mat = CPedIK::GetWorldMatrix(RwFrameGetParent(f), RwMatrixCreate()); - - RwV3d upVector = { mat->right.z, mat->up.z, mat->at.z }; - RwV3d rightVector; - RwV3d pos = RwFrameGetMatrix(f)->pos; - - // rotation == 0 -> looking in y direction - // left? vector - float c = cos(m_ped->m_fRotationCur); - float s = sin(m_ped->m_fRotationCur); - rightVector.x = -(c*mat->right.x + s*mat->right.y); - rightVector.y = -(c*mat->up.x + s*mat->up.y); - rightVector.z = -(c*mat->at.x + s*mat->at.y); - - if(changeRoll){ - // Used when aiming only involves over the legs.(canAimWithArm) - // Automatically changes roll(forward rotation) axis of the parts above upper legs while moving, based on position of upper legs. - // Not noticeable in normal conditions... - - RwV3d forwardVector; - CVector inversedForward = CrossProduct(CVector(0.0f, 0.0f, 1.0f), mat->up); - inversedForward.Normalise(); - float dotProduct = DotProduct(mat->at, inversedForward); - if(dotProduct > 1.0f) dotProduct = 1.0f; - if(dotProduct < -1.0f) dotProduct = -1.0f; - float alpha = acos(dotProduct); - - if(mat->at.z < 0.0f) - alpha = -alpha; - - forwardVector.x = s * mat->right.x - c * mat->right.y; - forwardVector.y = s * mat->up.x - c * mat->up.y; - forwardVector.z = s * mat->at.x - c * mat->at.y; - - float curYaw, curPitch; - CPedIK::ExtractYawAndPitchWorld(mat, &curYaw, &curPitch); - RwMatrixRotate(RwFrameGetMatrix(f), &rightVector, RADTODEG(limb->theta), rwCOMBINEPOSTCONCAT); - RwMatrixRotate(RwFrameGetMatrix(f), &upVector, RADTODEG(limb->phi - (curYaw - m_ped->m_fRotationCur)), rwCOMBINEPOSTCONCAT); - RwMatrixRotate(RwFrameGetMatrix(f), &forwardVector, RADTODEG(alpha), rwCOMBINEPOSTCONCAT); - }else{ - // pitch - RwMatrixRotate(RwFrameGetMatrix(f), &rightVector, RADTODEG(limb->theta), rwCOMBINEPOSTCONCAT); - // yaw - RwMatrixRotate(RwFrameGetMatrix(f), &upVector, RADTODEG(limb->phi), rwCOMBINEPOSTCONCAT); - } - RwFrameGetMatrix(f)->pos = pos; - RwMatrixDestroy(mat); -} - -void -CPedIK::GetComponentPosition(RwV3d *pos, PedNode node) -{ - RwFrame *f; - RwMatrix *mat; - - f = m_ped->GetNodeFrame(node); - mat = RwFrameGetMatrix(f); - *pos = mat->pos; - - for (f = RwFrameGetParent(f); f; f = RwFrameGetParent(f)) - RwV3dTransformPoints(pos, pos, 1, RwFrameGetMatrix(f)); -} - -RwMatrix* -CPedIK::GetWorldMatrix(RwFrame *source, RwMatrix *destination) -{ - RwFrame *i; - - *destination = *RwFrameGetMatrix(source); - - for (i = RwFrameGetParent(source); i; i = RwFrameGetParent(i)) - RwMatrixTransform(destination, RwFrameGetMatrix(i), rwCOMBINEPOSTCONCAT); - - return destination; -} - -STARTPATCHES - InjectHook(0x4ED0F0, &CPedIK::GetComponentPosition, PATCH_JUMP); - InjectHook(0x4ED060, &CPedIK::GetWorldMatrix, PATCH_JUMP); - InjectHook(0x4EDDB0, &CPedIK::RotateTorso, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/PedIK.h b/src/entities/PedIK.h deleted file mode 100644 index e17d52eb..00000000 --- a/src/entities/PedIK.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include "common.h" -#include "PedModelInfo.h" -#include "AnimBlendClumpData.h" - -struct LimbOrientation -{ - float phi; - float theta; -}; - -class CPed; - -class CPedIK -{ -public: - // TODO - enum { - FLAG_1 = 1, - FLAG_2 = 2, // related to looking somewhere - FLAG_4 = 4, // aims with arm - }; - - CPed *m_ped; - LimbOrientation m_headOrient; - LimbOrientation m_torsoOrient; - LimbOrientation m_upperArmOrient; - LimbOrientation m_lowerArmOrient; - int32 m_flags; - - CPedIK(CPed *ped); - bool PointGunInDirection(float phi, float theta); - bool PointGunAtPosition(CVector *position); - void GetComponentPosition(RwV3d *pos, PedNode node); - static RwMatrix *GetWorldMatrix(RwFrame *source, RwMatrix *destination); - void RotateTorso(AnimBlendFrameData* animBlend, LimbOrientation* limb, bool changeRoll); - void ExtractYawAndPitchLocal(RwMatrixTag*, float*, float*); - void ExtractYawAndPitchWorld(RwMatrixTag*, float*, float*); -}; -static_assert(sizeof(CPedIK) == 0x28, "CPedIK: error"); diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index 600e5dca..d6a82658 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -1897,10 +1897,10 @@ CPhysical::ProcessCollision(void) CVehicle *veh = (CVehicle*)this; if(veh->m_vehType == VEHICLE_TYPE_CAR){ CAutomobile *car = (CAutomobile*)this; - car->m_aWheelDist[0] = 1.0f; - car->m_aWheelDist[1] = 1.0f; - car->m_aWheelDist[2] = 1.0f; - car->m_aWheelDist[3] = 1.0f; + car->m_aSuspensionSpringRatio[0] = 1.0f; + car->m_aSuspensionSpringRatio[1] = 1.0f; + car->m_aSuspensionSpringRatio[2] = 1.0f; + car->m_aSuspensionSpringRatio[3] = 1.0f; }else if(veh->m_vehType == VEHICLE_TYPE_BIKE){ assert(0 && "TODO - but unused"); } diff --git a/src/entities/Plane.cpp b/src/entities/Plane.cpp deleted file mode 100644 index 6e30bced..00000000 --- a/src/entities/Plane.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "Plane.h" - -CPlane::CPlane(int mi, uint8 owner) -{ - ctor(mi, owner); -} - -WRAPPER CPlane* CPlane::ctor(int, uint8) { EAXJMP(0x54B170); } - -CPlane::~CPlane() -{ - DeleteRwObject(); -} - -STARTPATCHES -InjectHook(0x54B270, &CPlane::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/Plane.h b/src/entities/Plane.h deleted file mode 100644 index e26008f6..00000000 --- a/src/entities/Plane.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "common.h" -#include "Vehicle.h" - -class CPlane : public CVehicle -{ -public: - // 0x288 - uint8 stuff[20]; - - CPlane(int, uint8); - ~CPlane(void); - CPlane* ctor(int, uint8); - void dtor(void) { this->CPlane::~CPlane(); } - void FlagToDestroyWhenNextProcessed() { bRemoveFromWorld = true; } -}; -static_assert(sizeof(CPlane) == 0x29C, "CPlane: error"); diff --git a/src/entities/PlayerInfo.cpp b/src/entities/PlayerInfo.cpp deleted file mode 100644 index 59efe2ae..00000000 --- a/src/entities/PlayerInfo.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "PlayerInfo.h" - -WRAPPER void CPlayerInfo::MakePlayerSafe(bool) { EAXJMP(0x4A1400); }
\ No newline at end of file diff --git a/src/entities/PlayerInfo.h b/src/entities/PlayerInfo.h deleted file mode 100644 index e2b42fe7..00000000 --- a/src/entities/PlayerInfo.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include "Collision.h" - -enum eWastedBustedState -{ - WBSTATE_PLAYING, - WBSTATE_WASTED, - WBSTATE_BUSTED, - WBSTATE_FAILED_CRITICAL_MISSION, -}; - -class CVehicle; -class CPlayerPed; -class CCivilianPed; - -class CPlayerInfo -{ -public: - CPlayerPed *m_pPed; - CVehicle *m_pRemoteVehicle; - CColModel m_ColModel; - CVehicle *m_pVehicleEx; - char m_aPlayerName[70]; - int32 m_nMoney; - int32 m_nVisibleMoney; - int32 m_nCollectedPackages; - int32 m_nTotalPackages; - int32 field_188; - int32 m_nSwitchTaxiTime; - bool m_bSwitchTaxi; - int8 field_197; - int8 field_198; - int8 field_199; - int32 m_nNextSexFrequencyUpdateTime; - int32 m_nNextSexMoneyUpdateTime; - int32 m_nSexFrequency; - CCivilianPed *m_pHooker; - int8 m_WBState; // eWastedBustedState - int8 field_217; - int8 field_218; - int8 field_219; - int32 m_nWBTime; - bool m_bInRemoteMode; - int8 field_225; - int8 field_226; - int8 field_227; - int32 m_nTimeLostRemoteCar; - int32 m_nTimeLastHealthLoss; - int32 m_nTimeLastArmourLoss; - int32 field_240; - int32 m_nUpsideDownCounter; - int32 field_248; - int16 m_nTrafficMultiplier; - int8 field_254; - int8 field_255; - float m_fRoadDensity; - int32 m_nPreviousTimeRewardedForExplosion; - int32 m_nExplosionsSinceLastReward; - int32 field_268; - int32 field_272; - bool m_bInfiniteSprint; - bool m_bFastReload; - bool m_bGetOutOfJailFree; - bool m_bGetOutOfHospitalFree; - uint8 m_aSkinName[32]; - RwTexture *m_pSkinTexture; - - void MakePlayerSafe(bool); -}; - -static_assert(sizeof(CPlayerInfo) == 0x13C, "CPlayerInfo: error"); diff --git a/src/entities/PlayerPed.cpp b/src/entities/PlayerPed.cpp deleted file mode 100644 index 2d67d5b2..00000000 --- a/src/entities/PlayerPed.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "PlayerPed.h" - -CPlayerPed::~CPlayerPed() -{ - delete m_pWanted; -} - -WRAPPER void CPlayerPed::ReApplyMoveAnims(void) { EAXJMP(0x4F07C0); } - -STARTPATCHES - InjectHook(0x4EFB30, &CPlayerPed::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/PlayerPed.h b/src/entities/PlayerPed.h deleted file mode 100644 index 15ad74a6..00000000 --- a/src/entities/PlayerPed.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "Ped.h" -#include "Wanted.h" - -class CPlayerPed : public CPed -{ -public: - CWanted *m_pWanted; - CCopPed *m_pArrestingCop; - float m_fMoveSpeed; - float m_fCurrentStamina; - float m_fMaxStamina; - float m_fStaminaProgress; - bool m_bWeaponSlot; - bool m_bSpeedTimerFlag; - bool m_bShouldEvade; - int8 field_1367; - int32 m_nSpeedTimer; - int32 m_nShotDelay; - float field_1376; - int8 field_1380; // set if can't attack, why? - int8 field_1381; - int8 field_1382; - int8 field_1383; - CEntity *m_pEvadingFrom; - int32 m_nTargettableObjects[4]; - bool m_bAdrenalineActive; - bool m_bHasLockOnTarget; - int8 field_1406; - int8 field_1407; - bool m_bAdrenalineTime; - bool m_bCanBeDamaged; - int8 field_1413; - int8 field_1414; - int8 field_1415; - CVector field_1416[6]; - int32 field_1488[6]; - float m_fWalkAngle; - float m_fFPSMoveHeading; - - ~CPlayerPed(); - - void dtor(void) { this->CPlayerPed::~CPlayerPed(); } - void ReApplyMoveAnims(void); -}; - -static_assert(sizeof(CPlayerPed) == 0x5F0, "CPlayerPed: error"); diff --git a/src/entities/PlayerSkin.cpp b/src/entities/PlayerSkin.cpp deleted file mode 100644 index 1c9ca2c6..00000000 --- a/src/entities/PlayerSkin.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "PlayerSkin.h" - -WRAPPER void CPlayerSkin::BeginFrontEndSkinEdit() { EAXJMP(0x59BC70); } diff --git a/src/entities/PlayerSkin.h b/src/entities/PlayerSkin.h deleted file mode 100644 index 61e09cdf..00000000 --- a/src/entities/PlayerSkin.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -class CPlayerSkin -{ -public: - static void BeginFrontEndSkinEdit(); -};
\ No newline at end of file diff --git a/src/entities/Projectile.cpp b/src/entities/Projectile.cpp deleted file mode 100644 index e21323de..00000000 --- a/src/entities/Projectile.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "Projectile.h" - -STARTPATCHES - InjectHook(0x4BFED0, &CProjectile::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/Projectile.h b/src/entities/Projectile.h deleted file mode 100644 index a8e826b6..00000000 --- a/src/entities/Projectile.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#pragma once - -#include "Object.h" - -class CProjectile : public CObject -{ -public: - void dtor(void) { this->CProjectile::~CProjectile(); } -}; diff --git a/src/entities/Train.cpp b/src/entities/Train.cpp deleted file mode 100644 index 62fd53ec..00000000 --- a/src/entities/Train.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "Train.h" - -CTrain::CTrain(int mi, uint8 owner) -{ - ctor(mi, owner); -} - -WRAPPER CTrain* CTrain::ctor(int, uint8) { EAXJMP(0x54E2A0); } - -STARTPATCHES -InjectHook(0x54E450, &CTrain::dtor, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/entities/Train.h b/src/entities/Train.h deleted file mode 100644 index 84b6faf5..00000000 --- a/src/entities/Train.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "common.h" -#include "patcher.h" -#include "Vehicle.h" - -enum -{ - TRAIN_DOOR_STATE2 = 2 -}; - -class CTrain : public CVehicle -{ -public: - // 0x288 - uint8 stuff1[20]; - uint8 m_trackId; - uint8 stuff2[7]; - int16 m_doorState; - uint8 stuff3[62]; - - CTrain(int, uint8); - CTrain* ctor(int, uint8); - void dtor(void) { this->CTrain::~CTrain(); } -}; -static_assert(sizeof(CTrain) == 0x2E4, "CTrain: error"); diff --git a/src/entities/Vehicle.cpp b/src/entities/Vehicle.cpp deleted file mode 100644 index dccd9195..00000000 --- a/src/entities/Vehicle.cpp +++ /dev/null @@ -1,489 +0,0 @@ -#include "common.h" -#include "main.h" -#include "patcher.h" -#include "Timer.h" -#include "Vehicle.h" -#include "Pools.h" -#include "HandlingMgr.h" -#include "CarCtrl.h" -#include "Population.h" -#include "ModelIndices.h" -#include "World.h" -#include "Lights.h" -#include "PointLights.h" -#include "Renderer.h" -#include "DMAudio.h" -#include "Radar.h" - -bool &CVehicle::bWheelsOnlyCheat = *(bool *)0x95CD78; -bool &CVehicle::bAllDodosCheat = *(bool *)0x95CD75; -bool &CVehicle::bCheat3 = *(bool *)0x95CD66; -bool &CVehicle::bCheat4 = *(bool *)0x95CD65; -bool &CVehicle::bCheat5 = *(bool *)0x95CD64; -bool &CVehicle::m_bDisableMouseSteering = *(bool *)0x60252C; - -void *CVehicle::operator new(size_t sz) { return CPools::GetVehiclePool()->New(); } -void *CVehicle::operator new(size_t sz, int handle) { return CPools::GetVehiclePool()->New(handle); } -void CVehicle::operator delete(void *p, size_t sz) { CPools::GetVehiclePool()->Delete((CVehicle*)p); } -void CVehicle::operator delete(void *p, int handle) { CPools::GetVehiclePool()->Delete((CVehicle*)p); } - -CVehicle::~CVehicle() -{ - m_nAlarmState = 0; - if (m_audioEntityId >= 0){ - DMAudio.DestroyEntity(m_audioEntityId); - m_audioEntityId = -5; - } - CRadar::ClearBlipForEntity(BLIP_CAR, CPools::GetVehiclePool()->GetIndex(this)); - if (pDriver) - pDriver->FlagToDestroyWhenNextProcessed(); - for (int i = 0; i < m_nNumMaxPassengers; i++){ - if (pPassengers[i]) - pPassengers[i]->FlagToDestroyWhenNextProcessed(); - } - if (m_pCarFire) - m_pCarFire->Extinguish(); - CCarCtrl::UpdateCarCount(this, true); - if (bIsAmbulanceOnDuty){ - CCarCtrl::NumAmbulancesOnDuty--; - bIsAmbulanceOnDuty = false; - } - if (bIsFireTruckOnDuty){ - CCarCtrl::NumFiretrucksOnDuty--; - bIsFireTruckOnDuty = false; - } -} - -void -CVehicle::SetModelIndex(uint32 id) -{ - CEntity::SetModelIndex(id); - m_aExtras[0] = CVehicleModelInfo::ms_compsUsed[0]; - m_aExtras[1] = CVehicleModelInfo::ms_compsUsed[1]; - m_nNumMaxPassengers = CVehicleModelInfo::GetMaximumNumberOfPassengersFromNumberOfDoors(id); -} - -bool -CVehicle::SetupLighting(void) -{ - ActivateDirectional(); - SetAmbientColoursForPedsCarsAndObjects(); - - if(bRenderScorched){ - WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f); - }else{ - CVector coors = GetPosition(); - float lighting = CPointLights::GenerateLightsAffectingObject(&coors); - if(!bHasBlip && lighting != 1.0f){ - SetAmbientAndDirectionalColours(lighting); - return true; - } - } - - return false; -} - -void -CVehicle::RemoveLighting(bool reset) -{ - CRenderer::RemoveVehiclePedLights(this, reset); -} - -float -CVehicle::GetHeightAboveRoad(void) -{ - return -1.0f * CModelInfo::GetModelInfo(GetModelIndex())->GetColModel()->boundingBox.min.z; -} - - -bool -CVehicle::IsLawEnforcementVehicle(void) -{ - switch(GetModelIndex()){ - case MI_FBICAR: - case MI_POLICE: - case MI_ENFORCER: - case MI_PREDATOR: - case MI_RHINO: - case MI_BARRACKS: - return true; - default: - return false; - } -} - -bool -CVehicle::UsesSiren(uint32 id) -{ - switch(id){ - case MI_FIRETRUCK: - case MI_AMBULAN: - case MI_FBICAR: - case MI_MRWHOOP: - case MI_POLICE: - case MI_ENFORCER: - case MI_PREDATOR: - return true; - default: - return false; - } -} - -bool -CVehicle::IsVehicleNormal(void) -{ - if(pDriver && m_nNumPassengers == 0 && m_status != STATUS_WRECKED){ - switch(GetModelIndex()) - case MI_FIRETRUCK: - case MI_AMBULAN: - case MI_TAXI: - case MI_POLICE: - case MI_ENFORCER: - case MI_BUS: - case MI_RHINO: - case MI_BARRACKS: - case MI_DODO: - case MI_COACH: - case MI_CABBIE: - case MI_RCBANDIT: - case MI_BORGNINE: - return false; - } - return false; -} - -bool -CVehicle::CarHasRoof(void) -{ - if((m_handling->Flags & HANDLING_HAS_NO_ROOF) == 0) - return true; - if(m_aExtras[0] && m_aExtras[1]) - return false; - return true; -} - -bool -CVehicle::IsUpsideDown(void) -{ - if(GetUp().z > -0.9f) - return false; - return true; -} - -bool -CVehicle::IsOnItsSide(void) -{ - if(GetRight().z < 0.8f && GetRight().z > -0.8f) - return false; - return true; -} - -bool -CVehicle::CanBeDeleted(void) -{ - int i; - - if(m_nNumGettingIn || m_nGettingOutFlags) - return false; - - if(pDriver){ - // This looks like it was inlined - if(pDriver->CharCreatedBy == MISSION_CHAR) - return false; - if(pDriver->GetPedState() != PED_DRIVING && - pDriver->GetPedState() != PED_DEAD) - return false; - } - - for(i = 0; i < 8; i++){ - // Same check as above - if(pPassengers[i]){ - if(pPassengers[i]->CharCreatedBy == MISSION_CHAR) - return false; - if(pPassengers[i]->GetPedState() != PED_DRIVING && - pPassengers[i]->GetPedState() != PED_DEAD) - return false; - } - // and then again... probably because something was inlined - if(pPassengers[i]){ - if(pPassengers[i]->GetPedState() != PED_DRIVING && - pPassengers[i]->GetPedState() != PED_DEAD) - return false; - } - } - - switch(VehicleCreatedBy){ - case RANDOM_VEHICLE: return true; - case MISSION_VEHICLE: return false; - case PARKED_VEHICLE: return true; - case PERMANENT_VEHICLE: return false; - } - return true; -} - -bool -CVehicle::CanPedOpenLocks(CPed *ped) -{ - if(m_nDoorLock == CARLOCK_LOCKED || - m_nDoorLock == CARLOCK_COP_CAR || - m_nDoorLock == CARLOCK_LOCKED_PLAYER_INSIDE) - return false; - if(ped->IsPlayer() && m_nDoorLock == CARLOCK_LOCKOUT_PLAYER_ONLY) - return false; - return true; -} - -bool -CVehicle::CanPedEnterCar(void) -{ - CVector up = GetUp(); - // can't enter when car is on side - if(up.z > 0.1f || up.z < -0.1f){ - // also when car is moving too fast - if(m_vecMoveSpeed.MagnitudeSqr() > sq(0.2f)) - return false; - if(m_vecTurnSpeed.MagnitudeSqr() > sq(0.2f)) - return false; - return true; - } - return false; -} - -bool -CVehicle::CanPedExitCar(void) -{ - CVector up = GetUp(); - if(up.z > 0.1f || up.z < -0.1f){ - // can't exit when car is moving too fast - if(m_vecMoveSpeed.MagnitudeSqr() > 0.005f) - return false; - // if car is slow enough, check turn speed - if(fabs(m_vecTurnSpeed.x) > 0.01f || - fabs(m_vecTurnSpeed.y) > 0.01f || - fabs(m_vecTurnSpeed.z) > 0.01f) - return false; - return true; - }else{ - // What is this? just > replaced by >= ?? - - // can't exit when car is moving too fast - if(m_vecMoveSpeed.MagnitudeSqr() >= 0.005f) - return false; - // if car is slow enough, check turn speed - if(fabs(m_vecTurnSpeed.x) >= 0.01f || - fabs(m_vecTurnSpeed.y) >= 0.01f || - fabs(m_vecTurnSpeed.z) >= 0.01f) - return false; - return true; - } -} - -void -CVehicle::ChangeLawEnforcerState(uint8 enable) -{ - if (enable) { - if (!bIsLawEnforcer) { - bIsLawEnforcer = true; - CCarCtrl::NumLawEnforcerCars++; - } - } else { - if (bIsLawEnforcer) { - bIsLawEnforcer = false; - CCarCtrl::NumLawEnforcerCars--; - } - } -} - -CPed* -CVehicle::SetUpDriver(void) -{ - if(pDriver) - return pDriver; - if(VehicleCreatedBy != RANDOM_VEHICLE) - return nil; - - pDriver = CPopulation::AddPedInCar(this); - pDriver->m_pMyVehicle = this; - pDriver->m_pMyVehicle->RegisterReference((CEntity**)&pDriver->m_pMyVehicle); - pDriver->bInVehicle = true; - pDriver->SetPedState(PED_DRIVING); - if(bIsBus) - pDriver->m_ped_flagC4 = false; - return pDriver; -} - -CPed* -CVehicle::SetupPassenger(int n) -{ - if(pPassengers[n]) - return pPassengers[n]; - - pPassengers[n] = CPopulation::AddPedInCar(this); - pPassengers[n]->m_pMyVehicle = this; - pPassengers[n]->m_pMyVehicle->RegisterReference((CEntity**)&pPassengers[n]->m_pMyVehicle); - pPassengers[n]->bInVehicle = true; - pPassengers[n]->SetPedState(PED_DRIVING); - if(bIsBus) - pPassengers[n]->m_ped_flagC4 = false; - return pPassengers[n]; -} - -void -CVehicle::SetDriver(CPed *driver) -{ - pDriver = driver; - pDriver->RegisterReference((CEntity**)&pDriver); - - if(bFreebies && driver == FindPlayerPed()){ - if(GetModelIndex() == MI_AMBULAN) - FindPlayerPed()->m_fHealth = min(FindPlayerPed()->m_fHealth + 20.0f, 100.0f); - else if(GetModelIndex() == MI_TAXI) - CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; - else if(GetModelIndex() == MI_POLICE) - driver->GiveWeapon(WEAPONTYPE_SHOTGUN, 5); - else if(GetModelIndex() == MI_ENFORCER) - driver->m_fArmour = max(driver->m_fArmour, 100.0f); - else if(GetModelIndex() == MI_CABBIE || GetModelIndex() == MI_BORGNINE) - CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 25; - bFreebies = false; - } - - ApplyTurnForce(0.0f, 0.0f, -0.2f*driver->m_fMass, - driver->GetPosition().x - GetPosition().x, - driver->GetPosition().y - GetPosition().y, - 0.0f); -} - -bool -CVehicle::AddPassenger(CPed *passenger) -{ - int i; - - ApplyTurnForce(0.0f, 0.0f, -0.2f*passenger->m_fMass, - passenger->GetPosition().x - GetPosition().x, - passenger->GetPosition().y - GetPosition().y, - 0.0f); - - for(i = 0; i < m_nNumMaxPassengers; i++) - if(pPassengers[i] == nil){ - pPassengers[i] = passenger; - m_nNumPassengers++; - return true; - } - return false; -} - -bool -CVehicle::AddPassenger(CPed *passenger, uint8 n) -{ - if(bIsBus) - return AddPassenger(passenger); - - ApplyTurnForce(0.0f, 0.0f, -0.2f*passenger->m_fMass, - passenger->GetPosition().x - GetPosition().x, - passenger->GetPosition().y - GetPosition().y, - 0.0f); - - if(n < m_nNumMaxPassengers && pPassengers[n] == nil){ - pPassengers[n] = passenger; - m_nNumPassengers++; - return true; - } - return false; -} - -void -CVehicle::RemoveDriver(void) -{ - m_status = STATUS_ABANDONED; - pDriver = nil; -} - -void -CVehicle::RemovePassenger(CPed *p) -{ - if (IsTrain()){ - for (int i = 0; i < 8; i++){ - if (pPassengers[i] == p) { - pPassengers[i] = nil; - m_nNumPassengers--; - return; - } - } - return; - } - for (int i = 0; i < m_nNumMaxPassengers; i++){ - if (pPassengers[i] == p){ - pPassengers[i] = nil; - m_nNumPassengers--; - return; - } - } -} - -void -CVehicle::ProcessCarAlarm(void) -{ - uint32 step; - - if(m_nAlarmState == 0 || m_nAlarmState == -1) - return; - - step = CTimer::GetTimeStepInMilliseconds(); - if((uint16)m_nAlarmState < step) - m_nAlarmState = 0; - else - m_nAlarmState -= step; -} - -bool -CVehicle::IsSphereTouchingVehicle(float sx, float sy, float sz, float radius) -{ - float x, y, z; - // sphere relative to vehicle - CVector sph = CVector(sx, sy, sz) - GetPosition(); - CColModel *colmodel = CModelInfo::GetModelInfo(GetModelIndex())->GetColModel(); - - x = DotProduct(sph, GetRight()); - if(colmodel->boundingBox.min.x - radius > x || - colmodel->boundingBox.max.x + radius < x) - return false; - y = DotProduct(sph, GetForward()); - if(colmodel->boundingBox.min.y - radius > y || - colmodel->boundingBox.max.y + radius < y) - return false; - z = DotProduct(sph, GetUp()); - if(colmodel->boundingBox.min.z - radius > z || - colmodel->boundingBox.max.z + radius < z) - return false; - - return true; -} - -STARTPATCHES - InjectHook(0x551170, &CVehicle::SetModelIndex_, PATCH_JUMP); - InjectHook(0x4A7DD0, &CVehicle::SetupLighting_, PATCH_JUMP); - InjectHook(0x4A7E60, &CVehicle::RemoveLighting_, PATCH_JUMP); - InjectHook(0x417E60, &CVehicle::GetHeightAboveRoad_, PATCH_JUMP); - - InjectHook(0x552880, &CVehicle::IsLawEnforcementVehicle, PATCH_JUMP); - InjectHook(0x552820, &CVehicle::ChangeLawEnforcerState, PATCH_JUMP); - InjectHook(0x552200, &CVehicle::UsesSiren, PATCH_JUMP); - InjectHook(0x5527E0, &CVehicle::IsVehicleNormal, PATCH_JUMP); - InjectHook(0x552B70, &CVehicle::CarHasRoof, PATCH_JUMP); - InjectHook(0x552230, &CVehicle::IsUpsideDown, PATCH_JUMP); - InjectHook(0x552260, &CVehicle::IsOnItsSide, PATCH_JUMP); - InjectHook(0x5511B0, &CVehicle::CanBeDeleted, PATCH_JUMP); - InjectHook(0x5522A0, &CVehicle::CanPedOpenLocks, PATCH_JUMP); - InjectHook(0x5522F0, &CVehicle::CanPedEnterCar, PATCH_JUMP); - InjectHook(0x5523C0, &CVehicle::CanPedExitCar, PATCH_JUMP); - InjectHook(0x5520C0, &CVehicle::SetUpDriver, PATCH_JUMP); - InjectHook(0x552160, &CVehicle::SetupPassenger, PATCH_JUMP); - InjectHook(0x551F20, &CVehicle::SetDriver, PATCH_JUMP); - InjectHook(0x551D90, (bool (CVehicle::*)(CPed*))&CVehicle::AddPassenger, PATCH_JUMP); - InjectHook(0x551E10, (bool (CVehicle::*)(CPed*,uint8))&CVehicle::AddPassenger, PATCH_JUMP); - InjectHook(0x5520A0, &CVehicle::RemoveDriver, PATCH_JUMP); - InjectHook(0x551EB0, &CVehicle::RemovePassenger, PATCH_JUMP); - InjectHook(0x5525A0, &CVehicle::ProcessCarAlarm, PATCH_JUMP); - InjectHook(0x552620, &CVehicle::IsSphereTouchingVehicle, PATCH_JUMP); -ENDPATCHES diff --git a/src/entities/Vehicle.h b/src/entities/Vehicle.h deleted file mode 100644 index 39a56fe0..00000000 --- a/src/entities/Vehicle.h +++ /dev/null @@ -1,240 +0,0 @@ -#pragma once - -#include "Physical.h" -#include "AutoPilot.h" - -class CPed; -class CFire; -struct tHandlingData; - -enum { - RANDOM_VEHICLE = 1, - MISSION_VEHICLE = 2, - PARKED_VEHICLE = 3, - PERMANENT_VEHICLE = 4, -}; - -enum eCarLock { - CARLOCK_NOT_USED, - CARLOCK_UNLOCKED, - CARLOCK_LOCKED, - CARLOCK_LOCKOUT_PLAYER_ONLY, - CARLOCK_LOCKED_PLAYER_INSIDE, - CARLOCK_COP_CAR, - CARLOCK_FORCE_SHUT_DOORS, - CARLOCK_SKIP_SHUT_DOORS -}; - - -enum eCarNodes -{ - CAR_WHEEL_RF = 1, - CAR_WHEEL_RM, - CAR_WHEEL_RB, - CAR_WHEEL_LF, - CAR_WHEEL_LM, - CAR_WHEEL_LB, - CAR_BUMP_FRONT, - CAR_BUMP_REAR, - CAR_WING_RF, - CAR_WING_RR, - CAR_DOOR_RF, - CAR_DOOR_RR, - CAR_WING_LF, - CAR_WING_LR, - CAR_DOOR_LF, - CAR_DOOR_LR, - CAR_BONNET, - CAR_BOOT, - CAR_WINDSCREEN, - NUM_CAR_NODES, -}; - -enum -{ - CAR_POS_HEADLIGHTS, - CAR_POS_TAILLIGHTS, - CAR_POS_FRONTSEAT, - CAR_POS_BACKSEAT, - CAR_POS_EXHAUST = 9, -}; - -enum eDoors -{ - DOOR_BONNET = 0, - DOOR_BOOT, - DOOR_FRONT_LEFT, - DOOR_FRONT_RIGHT, - DOOR_REAR_LEFT, - DOOR_REAR_RIGHT -}; - -class CVehicle : public CPhysical -{ -public: - // 0x128 - tHandlingData *m_handling; - CAutoPilot m_autoPilot; - uint8 m_currentColour1; - uint8 m_currentColour2; - uint8 m_aExtras[2]; - int16 m_nAlarmState; // m_nWantedStarsOnEnter on DK22 - int16 m_nMissionValue; - CPed *pDriver; - CPed *pPassengers[8]; - uint8 m_nNumPassengers; - int8 m_nNumGettingIn; - int8 m_nGettingInFlags; - int8 m_nGettingOutFlags; - uint8 m_nNumMaxPassengers; - char field_1CD[19]; - CEntity *m_pCurSurface; - CFire *m_pCarFire; - float m_fSteerAngle; - float m_fGasPedal; - float m_fBreakPedal; - uint8 VehicleCreatedBy; - - // cf. https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/CVehicle.h from R* - uint8 bIsLawEnforcer: 1; // Is this guy chasing the player at the moment - uint8 bIsAmbulanceOnDuty: 1; // Ambulance trying to get to an accident - uint8 bIsFireTruckOnDuty: 1; // Firetruck trying to get to a fire - uint8 bIsLocked: 1; // Is this guy locked by the script (cannot be removed) - uint8 bEngineOn: 1; // For sound purposes. Parked cars have their engines switched off (so do destroyed cars) - uint8 bIsHandbrakeOn: 1; // How's the handbrake doing ? - uint8 bLightsOn: 1; // Are the lights switched on ? - uint8 bFreebies: 1; // Any freebies left in this vehicle ? - - uint8 bIsVan: 1; // Is this vehicle a van (doors at back of vehicle) - uint8 bIsBus: 1; // Is this vehicle a bus - uint8 bIsBig: 1; // Is this vehicle a bus - uint8 bLowVehicle: 1; // Need this for sporty type cars to use low getting-in/out anims - uint8 m_veh_flagB10 : 1; - uint8 m_veh_flagB20 : 1; - uint8 m_veh_flagB40 : 1; - uint8 m_veh_flagB80 : 1; - - uint8 m_veh_flagC1 : 1; - uint8 m_veh_flagC2 : 1; - uint8 m_veh_flagC4 : 1; - uint8 m_veh_flagC8 : 1; - uint8 m_veh_flagC10 : 1; - uint8 m_veh_flagC20 : 1; - uint8 m_veh_flagC40 : 1; - uint8 m_veh_flagC80 : 1; - - uint8 m_veh_flagD1 : 1; - uint8 m_veh_flagD2 : 1; - uint8 m_veh_flagD4 : 1; - uint8 m_veh_flagD8 : 1; - uint8 bRecordedForReplay : 1; - uint8 m_veh_flagD20 : 1; - uint8 m_veh_flagD40 : 1; - uint8 m_veh_flagD80 : 1; - - int8 field_1F9; - uint8 m_nAmmoInClip; // Used to make the guns on boat do a reload (20 by default) - int8 field_1FB; - int8 field_1FC[4]; - float m_fHealth; // 1000.0f = full health. 0 -> explode - uint8 m_nCurrentGear; - int8 field_205[3]; - int field_208; - uint32 m_nGunFiringTime; // last time when gun on vehicle was fired (used on boats) - uint32 m_nTimeOfDeath; - int16 field_214; - int16 m_nBombTimer; // goes down with each frame - CPed *m_pWhoDetonatedMe; - float field_21C; - float field_220; - eCarLock m_nDoorLock; - int8 m_nLastWeaponDamage; // see eWeaponType, -1 if no damage - int8 m_nRadioStation; - int8 field_22A; - int8 field_22B; - uint8 m_nCarHornTimer; - int8 field_22D; - uint8 m_nSirenOrAlarm; - int8 field_22F; - // TODO: this is an array - CStoredCollPoly m_frontCollPoly; // poly which is under front part of car - CStoredCollPoly m_rearCollPoly; // poly which is under rear part of car - float m_fSteerRatio; - eVehicleType m_vehType; - - static void *operator new(size_t); - static void *operator new(size_t sz, int slot); - static void operator delete(void*, size_t); - static void operator delete(void*, int); - - ~CVehicle(void); - // from CEntity - void SetModelIndex(uint32 i); - bool SetupLighting(void); - void RemoveLighting(bool); - void FlagToDestroyWhenNextProcessed(void) {} - - virtual void ProcessControlInputs(uint8) {} - virtual void GetComponentWorldPosition(int32 component, CVector &pos) {} - virtual bool IsComponentPresent(int32 component) { return false; } - virtual void SetComponentRotation(int32 component, CVector rotation) {} - virtual void OpenDoor(int32, eDoors door, float) {} - virtual void ProcessOpenDoor(uint32, uint32, float) {} - virtual bool IsDoorReady(eDoors door) { return false; } - virtual bool IsDoorFullyOpen(eDoors door) { return false; } - virtual bool IsDoorClosed(eDoors door) { return false; } - virtual bool IsDoorMissing(eDoors door) { return false; } - virtual void RemoveRefsToVehicle(CEntity *ent) {} - virtual void BlowUpCar(CEntity *ent) {} - virtual bool SetUpWheelColModel(CColModel *colModel) { return false; } - virtual void BurstTyre(uint8 tyre) {} - virtual bool IsRoomForPedToLeaveCar(uint32, CVector *) { return false;} - virtual float GetHeightAboveRoad(void); - virtual void PlayCarHorn(void) {} - - bool IsCar(void) { return m_vehType == VEHICLE_TYPE_CAR; } - bool IsBoat(void) { return m_vehType == VEHICLE_TYPE_BOAT; } - bool IsTrain(void) { return m_vehType == VEHICLE_TYPE_TRAIN; } - bool IsHeli(void) { return m_vehType == VEHICLE_TYPE_HELI; } - bool IsPlane(void) { return m_vehType == VEHICLE_TYPE_PLANE; } - bool IsLawEnforcementVehicle(void); - void ChangeLawEnforcerState(uint8 enable); - bool UsesSiren(uint32 id); - bool IsVehicleNormal(void); - bool CarHasRoof(void); - bool IsUpsideDown(void); - bool IsOnItsSide(void); - bool CanBeDeleted(void); - bool CanPedOpenLocks(CPed *ped); - bool CanPedEnterCar(void); - bool CanPedExitCar(void); - // do these two actually return something? - CPed *SetUpDriver(void); - CPed *SetupPassenger(int n); - void SetDriver(CPed *driver); - bool AddPassenger(CPed *passenger); - bool AddPassenger(CPed *passenger, uint8 n); - void RemovePassenger(CPed *passenger); - void RemoveDriver(void); - void ProcessCarAlarm(void); - bool IsSphereTouchingVehicle(float sx, float sy, float sz, float radius); - - static bool &bWheelsOnlyCheat; - static bool &bAllDodosCheat; - static bool &bCheat3; - static bool &bCheat4; - static bool &bCheat5; - static bool &m_bDisableMouseSteering; - - - void dtor(void) { CVehicle::~CVehicle(); } - void SetModelIndex_(uint32 id) { CVehicle::SetModelIndex(id); } - bool SetupLighting_(void) { return CVehicle::SetupLighting(); } - void RemoveLighting_(bool reset) { CVehicle::RemoveLighting(reset); } - float GetHeightAboveRoad_(void) { return CVehicle::GetHeightAboveRoad(); } -}; - -static_assert(sizeof(CVehicle) == 0x288, "CVehicle: error"); -static_assert(offsetof(CVehicle, m_pCurSurface) == 0x1E0, "CVehicle: error"); -static_assert(offsetof(CVehicle, m_nAlarmState) == 0x1A0, "CVehicle: error"); -static_assert(offsetof(CVehicle, m_nLastWeaponDamage) == 0x228, "CVehicle: error"); |