summaryrefslogtreecommitdiffstats
path: root/src/entities
diff options
context:
space:
mode:
authoreray orçunus <erayorcunus@gmail.com>2019-06-17 11:48:42 +0200
committereray orçunus <erayorcunus@gmail.com>2019-06-17 14:20:15 +0200
commite45689373db75d47ee6a87aa5440de8d99d87c4d (patch)
tree97a274d5d0787c7e7b58b2f2337d10d29c15dc4e /src/entities
parentMerge pull request #20 from gennariarmando/master (diff)
downloadre3-e45689373db75d47ee6a87aa5440de8d99d87c4d.tar
re3-e45689373db75d47ee6a87aa5440de8d99d87c4d.tar.gz
re3-e45689373db75d47ee6a87aa5440de8d99d87c4d.tar.bz2
re3-e45689373db75d47ee6a87aa5440de8d99d87c4d.tar.lz
re3-e45689373db75d47ee6a87aa5440de8d99d87c4d.tar.xz
re3-e45689373db75d47ee6a87aa5440de8d99d87c4d.tar.zst
re3-e45689373db75d47ee6a87aa5440de8d99d87c4d.zip
Diffstat (limited to 'src/entities')
-rw-r--r--src/entities/Ped.cpp64
-rw-r--r--src/entities/Ped.h12
2 files changed, 70 insertions, 6 deletions
diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp
index ccb07d46..b8236ecc 100644
--- a/src/entities/Ped.cpp
+++ b/src/entities/Ped.cpp
@@ -7,6 +7,8 @@
#include "PedStat.h"
#include "DMaudio.h"
#include "Ped.h"
+#include "PedType.h"
+#include "General.h"
bool &CPed::bNastyLimbsCheat = *(bool*)0x95CD44;
bool &CPed::bPedCheat2 = *(bool*)0x95CD5A;
@@ -229,8 +231,6 @@ CPed::AimGun()
}
}
-
-// After I finished this I realized it's only for SCM opcode...
void
CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer)
{
@@ -397,6 +397,65 @@ 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 sinValue;
+ float cosValue;
+ float someRate;
+ float someY;
+ float someX;
+ float someDistance;
+ float simplifiedAngle;
+
+ 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)) {
+
+ simplifiedAngle = RADTODEG(m_fRotationCur) / RADTODEG(1);
+ sinValue = -sin(simplifiedAngle);
+ cosValue = cos(simplifiedAngle);
+
+ // sin^2 + cos^2 must always return 1, and it does return... so what's the point?
+ someRate = 1.0f / sqrt(cosValue * cosValue + sinValue * sinValue);
+
+ // 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.
+ someY = nearestPed->GetPosition().y
+ - (1.25 * (cosValue * someRate)
+ + GetPosition().y);
+ someX = nearestPed->GetPosition().x
+ - (1.25 * (sinValue * someRate)
+ + GetPosition().x);
+ someDistance = sqrt(someY * someY + someX * someX);
+
+ if (someDistance <= 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);
@@ -406,4 +465,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
diff --git a/src/entities/Ped.h b/src/entities/Ped.h
index 0b0a5562..0249c707 100644
--- a/src/entities/Ped.h
+++ b/src/entities/Ped.h
@@ -97,7 +97,7 @@ public:
uint8 m_ped_flagA2 : 1;
uint8 m_ped_flagA4 : 1;
uint8 m_ped_flagA8 : 1;
- uint8 m_ped_flagA10 : 1;
+ uint8 m_ped_flagA10 : 1; // set when A20 just changed?
uint8 m_ped_flagA20_look : 1;
uint8 m_ped_flagA40 : 1;
uint8 m_ped_flagA80 : 1;
@@ -114,7 +114,7 @@ public:
uint8 m_ped_flagC4 : 1;
uint8 m_ped_flagC8 : 1;
uint8 m_ped_flagC10 : 1;
- uint8 m_ped_flagC20 : 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;
@@ -166,7 +166,7 @@ public:
uint8 m_ped_flagI40 : 1;
uint8 m_ped_flagI80 : 1;
uint8 stuff10[15];
- int32 m_field_16C;
+ CPed *m_field_16C;
uint8 stuff12[44];
int32 m_pEventEntity;
float m_fAngleToEvent;
@@ -198,7 +198,10 @@ public:
CPathNode *m_pLastPathNode;
float m_fHealth;
float m_fArmour;
- uint8 stuff2[34];
+ uint8 stuff2[20];
+ float m_fRotationCur;
+ float m_fRotationDest;
+ uint8 stuff13[6];
CEntity *m_pCurrentPhysSurface;
CVector m_vecOffsetFromPhysSurface;
CEntity *m_pCurSurface;
@@ -249,6 +252,7 @@ public:
void RemoveBodyPart(PedNode nodeId, int8 unknown);
void SpawnFlyingComponent(int, int8 unknown);
bool OurPedCanSeeThisOne(CEntity* who);
+ void Avoid(void);
static RwObject *SetPedAtomicVisibilityCB(RwObject *object, void *data);
static RwFrame *RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data);