summaryrefslogtreecommitdiffstats
path: root/src/entities
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-06-19 14:06:13 +0200
committeraap <aap@papnet.eu>2019-06-19 14:06:13 +0200
commit78e33785ecfd176616b1a1b1588c771b978a4c19 (patch)
tree6abde4ca51c0f477ce63288215b510a462e52e50 /src/entities
parentMerge pull request #22 from erorcun/master (diff)
downloadre3-78e33785ecfd176616b1a1b1588c771b978a4c19.tar
re3-78e33785ecfd176616b1a1b1588c771b978a4c19.tar.gz
re3-78e33785ecfd176616b1a1b1588c771b978a4c19.tar.bz2
re3-78e33785ecfd176616b1a1b1588c771b978a4c19.tar.lz
re3-78e33785ecfd176616b1a1b1588c771b978a4c19.tar.xz
re3-78e33785ecfd176616b1a1b1588c771b978a4c19.tar.zst
re3-78e33785ecfd176616b1a1b1588c771b978a4c19.zip
Diffstat (limited to 'src/entities')
-rw-r--r--src/entities/Ped.cpp112
-rw-r--r--src/entities/Ped.h13
2 files changed, 60 insertions, 65 deletions
diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp
index 12528b20..9e986dd0 100644
--- a/src/entities/Ped.cpp
+++ b/src/entities/Ped.cpp
@@ -177,6 +177,13 @@ static char WaitStateText[21][16] = {
};
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 ||
@@ -217,7 +224,7 @@ CPed::AimGun()
CPed::Say(SOUND_PED_ATTACK);
m_ped_flagB2 = m_pedIK.PointGunAtPosition(&vector);
- if (m_pPedFight != m_pSeekTarget) {
+ if (m_pLookTarget != m_pSeekTarget) {
CPed::SetLookFlag(m_pSeekTarget, 1);
}
@@ -327,16 +334,16 @@ CPed::RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data)
}
void
-CPed::SetLookFlag(CPed *to, bool set)
+CPed::SetLookFlag(CPed *target, bool unknown)
{
if (m_lookTimer < CTimer::GetTimeInMilliseconds()) {
- m_ped_flagA10 = 1;
- m_ped_flagA40 = 0;
- m_pPedFight = to;
- m_pPedFight->RegisterReference((CEntity**)&m_pPedFight);
+ bIsLooking = true;
+ m_ped_flagA40 = false;
+ m_pLookTarget = target;
+ m_pLookTarget->RegisterReference((CEntity**)&m_pLookTarget);
m_fLookDirection = 999999.0f;
m_lookTimer = 0;
- m_ped_flagA20_look = set;
+ m_ped_flagA20_look = unknown;
if (m_nPedState != PED_DRIVING) {
m_pedIK.m_flags &= ~CPedIK::FLAG_2;
}
@@ -344,15 +351,15 @@ CPed::SetLookFlag(CPed *to, bool set)
}
void
-CPed::SetLookFlag(float angle, bool set)
+CPed::SetLookFlag(float direction, bool unknown)
{
if (m_lookTimer < CTimer::GetTimeInMilliseconds()) {
- m_ped_flagA10 = 1;
- m_ped_flagA40 = 0;
- m_pPedFight = 0;
- m_fLookDirection = angle;
+ bIsLooking = true;
+ m_ped_flagA40 = false;
+ m_pLookTarget = nil;
+ m_fLookDirection = direction;
m_lookTimer = 0;
- m_ped_flagA20_look = set;
+ m_ped_flagA20_look = unknown;
if (m_nPedState != PED_DRIVING) {
m_pedIK.m_flags &= ~CPedIK::FLAG_2;
}
@@ -368,76 +375,65 @@ CPed::SetLookTimer(int time)
}
bool
-CPed::OurPedCanSeeThisOne(CEntity* who)
+CPed::OurPedCanSeeThisOne(CEntity *target)
{
- float distance;
CColPoint colpoint;
- CEntity* ent;
- CVector ourPos;
- CVector itsPos;
+ CEntity *ent;
- ourPos = this->GetPosition();
- itsPos = who->GetPosition();
+ CVector2D dist = CVector2D(target->GetPosition()) - CVector2D(this->GetPosition());
- CVector2D posDiff(
- itsPos.x - ourPos.x,
- itsPos.y - ourPos.y
- );
-
- if ((posDiff.y * this->GetForward().y) + (posDiff.x * this->GetForward().x) < 0.0f)
+ // Check if target is behind ped
+ if (DotProduct2D(dist, CVector2D(this->GetForward())) < 0.0f)
return 0;
- distance = posDiff.Magnitude();
-
- if (distance < 40.0f)
+ // Check if target is too far away
+ if (dist.Magnitude() < 40.0f)
return 0;
- ourPos.z += 1.0f;
- return !CWorld::ProcessLineOfSight(ourPos, itsPos, colpoint, ent, 1, 0, 0, 0, 0, 0, 0);
+ // 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) {
- 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) {
+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) {
- 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)) {
+ if (nearestPed && nearestPed->m_nPedState != PED_DEAD && nearestPed != m_pSeekTarget && nearestPed != m_field_16C) {
+
+ // 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.
- 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);
+ // 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
- CVector2D walkedUpToPed(
- nearestPed->GetPosition().x - (1.25 * -sin(walkAngle) + GetPosition().x),
- nearestPed->GetPosition().y - (1.25 * cos(walkAngle) + GetPosition().y)
- );
+ // Move forward 1.25 meters
+ CVector2D testPosition = CVector2D(GetPosition()) + forward*1.25f;
- distance = walkedUpToPed.Magnitude();
+ // Get distance to ped we want to avoid
+ CVector2D distToPed = CVector2D(nearestPed->GetPosition()) - testPosition;
- if (distance <= 1.0f && CPed::OurPedCanSeeThisOne((CEntity*)nearestPed)) {
+ 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 (!m_ped_flagA10) {
+ if (!bIsLooking) {
CPed::SetLookFlag(nearestPed, 0);
CPed::SetLookTimer(CGeneral::GetRandomNumberInRange(0, 300) + 500);
}
diff --git a/src/entities/Ped.h b/src/entities/Ped.h
index f9e46dae..60b88765 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; // stores (CTimer::GetTimeInMilliseconds() < m_lastHitTime)
uint8 m_ped_flagA8 : 1;
- uint8 m_ped_flagA10 : 1; // set when A20 just changed?
+ uint8 bIsLooking : 1; // set when A20 just changed?
uint8 m_ped_flagA20_look : 1;
uint8 m_ped_flagA40 : 1;
uint8 m_ped_flagA80 : 1;
@@ -222,7 +222,7 @@ public:
int32 m_pPointGunAt;
CVector m_vecHitLastPos;
uint8 stuff8[12];
- CPed *m_pPedFight;
+ CEntity *m_pLookTarget;
float m_fLookDirection;
int32 m_wepModelID;
uint32 m_leaveCarTimer;
@@ -240,21 +240,20 @@ public:
static void *operator new(size_t);
static void operator delete(void*, size_t);
- // TODO: enum!
- bool IsPlayer(void) { return m_nPedType == 0 || m_nPedType== 1 || m_nPedType == 2 || m_nPedType == 3; }
+ bool IsPlayer(void);
bool UseGroundColModel(void);
void AddWeaponModel(int id);
void AimGun();
void KillPedWithCar(CVehicle *veh, float impulse);
void Say(uint16 audio);
- void SetLookFlag(CPed *to, bool set);
- void SetLookFlag(float angle, bool set);
+ void SetLookFlag(CPed *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* who);
+ bool OurPedCanSeeThisOne(CEntity *target);
void Avoid(void);
static RwObject *SetPedAtomicVisibilityCB(RwObject *object, void *data);
static RwFrame *RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data);