diff options
-rw-r--r-- | src/PedType.cpp | 31 | ||||
-rw-r--r-- | src/PedType.h | 61 | ||||
-rw-r--r-- | src/control/PedType.cpp | 29 | ||||
-rw-r--r-- | src/control/PedType.h | 61 | ||||
-rw-r--r-- | src/entities/Ped.cpp | 20 | ||||
-rw-r--r-- | src/entities/Ped.h | 2 |
6 files changed, 96 insertions, 108 deletions
diff --git a/src/PedType.cpp b/src/PedType.cpp deleted file mode 100644 index 904b4f97..00000000 --- a/src/PedType.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "common.h" -#include "patcher.h" -#include "PedType.h" - -CPedType* (&CPedType::ms_apPedType)[23] = *(CPedType * (*)[23]) * (int*)0x941594; - -WRAPPER void CPedType::LoadPedData(void) { EAXJMP(0x4EE8D0); } - -void -CPedType::Initialise() -{ - debug("Initialising CPedType...\n"); - for(int i = 0; i < 23; i++) { - ms_apPedType[i] = new CPedType; - ms_apPedType[i]->m_Type.IntValue = 1; - ms_apPedType[i]->field_4 = 0; - ms_apPedType[i]->field_8 = 0; - // Why field_C not initialized? - ms_apPedType[i]->field_10 = 0; - ms_apPedType[i]->field_14 = 0; - ms_apPedType[i]->m_Threat.IntValue = 0; - ms_apPedType[i]->m_Avoid.IntValue = 0; - } - debug("Loading ped data...\n"); - LoadPedData(); - debug("CPedType ready\n"); -} - -STARTPATCHES - InjectHook(0x4EE7E0, &CPedType::Initialise, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/PedType.h b/src/PedType.h deleted file mode 100644 index 7b9e3096..00000000 --- a/src/PedType.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include "common.h" -#include "templates.h" -#include "Lists.h" - -class CPedType { -public: - union tPedTypeFlags - { - uint32 IntValue; - struct - { - uint8 bPlayer1 : 1; - uint8 bPlayer2 : 1; - uint8 bPlayer3 : 1; - uint8 bPlayer4 : 1; - uint8 bCivmale : 1; - uint8 bCivfemale : 1; - uint8 bCop : 1; - uint8 bGang1 : 1; - - uint8 bGang2 : 1; - uint8 bGang3 : 1; - uint8 bGang4 : 1; - uint8 bGang5 : 1; - uint8 bGang6 : 1; - uint8 bGang7 : 1; - uint8 bGang8 : 1; - uint8 bGang9 : 1; - - uint8 bEmergency : 1; - uint8 bProstitute : 1; - uint8 bCriminal : 1; - uint8 bSpecial : 1; - uint8 bGun : 1; - uint8 bCop_car : 1; - uint8 bFast_car : 1; - uint8 bExplosion : 1; - - uint8 bFireman : 1; - uint8 bDeadpeds : 1; - }; - }; - - tPedTypeFlags m_Type; - float field_4; - float field_8; - float field_C; - float field_10; - float field_14; - tPedTypeFlags m_Threat; - tPedTypeFlags m_Avoid; - - static CPedType* (&ms_apPedType)[23]; - - static void Initialise(); - static void LoadPedData(); -}; - -static_assert(sizeof(CPedType) == 0x20, "CPedType: error");
\ No newline at end of file diff --git a/src/control/PedType.cpp b/src/control/PedType.cpp index 587aa815..b6d77cb0 100644 --- a/src/control/PedType.cpp +++ b/src/control/PedType.cpp @@ -2,4 +2,31 @@ #include "patcher.h" #include "PedType.h" -WRAPPER int32 CPedType::FindPedType(char *type) { EAXJMP(0x4EEC10); } +CPedType* (&CPedType::ms_apPedType)[23] = *(CPedType * (*)[23]) * (int*)0x941594; + +WRAPPER void CPedType::LoadPedData(void) { EAXJMP(0x4EE8D0); } +WRAPPER int32 CPedType::FindPedType(char* type) { EAXJMP(0x4EEC10); } + +void +CPedType::Initialise() +{ + debug("Initialising CPedType...\n"); + for (int i = 0; i < 23; i++) { + ms_apPedType[i] = new CPedType; + ms_apPedType[i]->m_Type.IntValue = 1; + ms_apPedType[i]->field_4 = 0; + ms_apPedType[i]->field_8 = 0; + // Why field_C not initialized? + ms_apPedType[i]->field_10 = 0; + ms_apPedType[i]->field_14 = 0; + ms_apPedType[i]->m_Threat.IntValue = 0; + ms_apPedType[i]->m_Avoid.IntValue = 0; + } + debug("Loading ped data...\n"); + LoadPedData(); + debug("CPedType ready\n"); +} + +STARTPATCHES + InjectHook(0x4EE7E0, &CPedType::Initialise, PATCH_JUMP); +ENDPATCHES
\ No newline at end of file diff --git a/src/control/PedType.h b/src/control/PedType.h index 563dc294..1d1057d7 100644 --- a/src/control/PedType.h +++ b/src/control/PedType.h @@ -1,7 +1,62 @@ #pragma once -class CPedType -{ +#include "common.h" +#include "templates.h" +#include "Lists.h" + +class CPedType { public: - static int32 FindPedType(char *type); + union tPedTypeFlags + { + uint32 IntValue; + struct + { + uint8 bPlayer1 : 1; + uint8 bPlayer2 : 1; + uint8 bPlayer3 : 1; + uint8 bPlayer4 : 1; + uint8 bCivmale : 1; + uint8 bCivfemale : 1; + uint8 bCop : 1; + uint8 bGang1 : 1; + + uint8 bGang2 : 1; + uint8 bGang3 : 1; + uint8 bGang4 : 1; + uint8 bGang5 : 1; + uint8 bGang6 : 1; + uint8 bGang7 : 1; + uint8 bGang8 : 1; + uint8 bGang9 : 1; + + uint8 bEmergency : 1; + uint8 bProstitute : 1; + uint8 bCriminal : 1; + uint8 bSpecial : 1; + uint8 bGun : 1; + uint8 bCop_car : 1; + uint8 bFast_car : 1; + uint8 bExplosion : 1; + + uint8 bFireman : 1; + uint8 bDeadpeds : 1; + }; + }; + + tPedTypeFlags m_Type; + float field_4; + float field_8; + float field_C; + float field_10; + float field_14; + tPedTypeFlags m_Threat; + tPedTypeFlags m_Avoid; + + static CPedType* (&ms_apPedType)[23]; + + static void Initialise(); + static void LoadPedData(); + static int32 FindPedType(char* type); }; + +static_assert(sizeof(CPedType) == 0x20, "CPedType: error");
\ No newline at end of file diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp index f6d9f4b2..12528b20 100644 --- a/src/entities/Ped.cpp +++ b/src/entities/Ped.cpp @@ -401,7 +401,7 @@ CPed::Avoid(void) { int8 temper; int moveState; CPed* nearestPed; - float rate; + float walkAngle; float distance; temper = m_pedStats->m_temper; @@ -416,19 +416,17 @@ CPed::Avoid(void) { && (CPedType::ms_apPedType[nearestPed->m_nPedType]->m_Type.IntValue & CPedType::ms_apPedType[this->m_nPedType]->m_Avoid.IntValue)) { - CVector2D pedAngleRatio( - cos(RADTODEG(m_fRotationCur) / RADTODEG(1)), - -sin(RADTODEG(m_fRotationCur) / RADTODEG(1)) - ); - - // sin^2 + cos^2 must always return 1, and it does return... so what's the point? - rate = 1.0f / pedAngleRatio.Magnitude(); - // 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. + + walkAngle = RADTODEG(m_fRotationCur) / RADTODEG(1); + + // Original code was multiplying sin/cos with the number below, which is pointless because it's always 1. + // ratio = 1.0f / sqrt(sin*sin + cos*cos); + CVector2D walkedUpToPed( - nearestPed->GetPosition().x - (1.25 * (pedAngleRatio.y * rate) + GetPosition().x), - nearestPed->GetPosition().y - (1.25 * (pedAngleRatio.x * rate) + GetPosition().y) + nearestPed->GetPosition().x - (1.25 * -sin(walkAngle) + GetPosition().x), + nearestPed->GetPosition().y - (1.25 * cos(walkAngle) + GetPosition().y) ); distance = walkedUpToPed.Magnitude(); diff --git a/src/entities/Ped.h b/src/entities/Ped.h index 7496ee67..f9e46dae 100644 --- a/src/entities/Ped.h +++ b/src/entities/Ped.h @@ -3,10 +3,10 @@ #include "Physical.h" #include "Weapon.h" #include "PedIK.h" +#include "PedStats.h" #include "AnimManager.h" #include "AnimBlendClumpData.h" -struct PedStat; struct CPathNode; enum { |