summaryrefslogtreecommitdiffstats
path: root/src/entities/Ped.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/Ped.cpp')
-rw-r--r--src/entities/Ped.cpp73
1 files changed, 63 insertions, 10 deletions
diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp
index df92dd26..12528b20 100644
--- a/src/entities/Ped.cpp
+++ b/src/entities/Ped.cpp
@@ -6,6 +6,8 @@
#include "World.h"
#include "DMaudio.h"
#include "Ped.h"
+#include "PedType.h"
+#include "General.h"
bool &CPed::bNastyLimbsCheat = *(bool*)0x95CD44;
bool &CPed::bPedCheat2 = *(bool*)0x95CD5A;
@@ -228,8 +230,6 @@ CPed::AimGun()
}
}
-
-// After I finished this I realized it's only for SCM opcode...
void
CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer)
{
@@ -338,7 +338,7 @@ CPed::SetLookFlag(CPed *to, bool set)
m_lookTimer = 0;
m_ped_flagA20_look = set;
if (m_nPedState != PED_DRIVING) {
- m_pedIK.m_flags &= ~CPedIK::FLAG_4;
+ m_pedIK.m_flags &= ~CPedIK::FLAG_2;
}
}
}
@@ -354,7 +354,7 @@ CPed::SetLookFlag(float angle, bool set)
m_lookTimer = 0;
m_ped_flagA20_look = set;
if (m_nPedState != PED_DRIVING) {
- m_pedIK.m_flags &= ~CPedIK::FLAG_4;
+ m_pedIK.m_flags &= ~CPedIK::FLAG_2;
}
}
}
@@ -370,8 +370,6 @@ CPed::SetLookTimer(int time)
bool
CPed::OurPedCanSeeThisOne(CEntity* who)
{
- float xDiff;
- float yDiff;
float distance;
CColPoint colpoint;
CEntity* ent;
@@ -381,13 +379,15 @@ CPed::OurPedCanSeeThisOne(CEntity* who)
ourPos = this->GetPosition();
itsPos = who->GetPosition();
- xDiff = itsPos.x - ourPos.x;
- yDiff = itsPos.y - ourPos.y;
+ CVector2D posDiff(
+ itsPos.x - ourPos.x,
+ itsPos.y - ourPos.y
+ );
- if ((yDiff * this->GetUp().y) + (xDiff * this->GetUp().x) < 0.0f)
+ if ((posDiff.y * this->GetForward().y) + (posDiff.x * this->GetForward().x) < 0.0f)
return 0;
- distance = sqrt(yDiff * yDiff + xDiff * xDiff);
+ distance = posDiff.Magnitude();
if (distance < 40.0f)
return 0;
@@ -396,6 +396,58 @@ CPed::OurPedCanSeeThisOne(CEntity* who)
return !CWorld::ProcessLineOfSight(ourPos, itsPos, colpoint, ent, 1, 0, 0, 0, 0, 0, 0);
}
+void
+CPed::Avoid(void) {
+ int8 temper;
+ int moveState;
+ CPed* nearestPed;
+ float walkAngle;
+ float distance;
+
+ temper = m_pedStats->m_temper;
+ if ((temper <= m_pedStats->m_fear || temper <= 50) && CTimer::GetTimeInMilliseconds() > m_nPedStateTimer) {
+ moveState = m_nMoveState;
+
+ if (moveState != PEDMOVE_NONE && moveState != PEDMOVE_STILL) {
+ nearestPed = m_nearPeds[0];
+
+ if (nearestPed) {
+ if (nearestPed->m_nPedState != PED_DEAD && nearestPed != m_pSeekTarget && nearestPed != m_field_16C
+ && (CPedType::ms_apPedType[nearestPed->m_nPedType]->m_Type.IntValue
+ & CPedType::ms_apPedType[this->m_nPedType]->m_Avoid.IntValue)) {
+
+ // 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 * -sin(walkAngle) + GetPosition().x),
+ nearestPed->GetPosition().y - (1.25 * cos(walkAngle) + GetPosition().y)
+ );
+
+ distance = walkedUpToPed.Magnitude();
+
+ if (distance <= 1.0f && CPed::OurPedCanSeeThisOne((CEntity*)nearestPed)) {
+ m_nPedStateTimer = CTimer::GetTimeInMilliseconds()
+ + 500 + (m_randomSeed + 3 * CTimer::GetFrameCounter())
+ % 1000 / 5;
+
+ m_fRotationDest += DEGTORAD(45.0f);
+ if (!m_ped_flagA10) {
+ CPed::SetLookFlag(nearestPed, 0);
+ CPed::SetLookTimer(CGeneral::GetRandomNumberInRange(0, 300) + 500);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
STARTPATCHES
InjectHook(0x4CF8F0, &CPed::AddWeaponModel, PATCH_JUMP);
InjectHook(0x4C6AA0, &CPed::AimGun, PATCH_JUMP);
@@ -405,4 +457,5 @@ STARTPATCHES
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);
ENDPATCHES