summaryrefslogtreecommitdiffstats
path: root/src/peds
diff options
context:
space:
mode:
Diffstat (limited to 'src/peds')
-rw-r--r--src/peds/Ped.cpp53
-rw-r--r--src/peds/Ped.h2
-rw-r--r--src/peds/PedFight.cpp2
-rw-r--r--src/peds/PedIK.cpp4
-rw-r--r--src/peds/PedIK.h2
-rw-r--r--src/peds/PlayerPed.cpp4
6 files changed, 47 insertions, 20 deletions
diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp
index 04e13c33..4d80cac2 100644
--- a/src/peds/Ped.cpp
+++ b/src/peds/Ped.cpp
@@ -308,6 +308,30 @@ CPed::~CPed(void)
m_pFire->Extinguish();
CPopulation::UpdatePedCount((ePedType)m_nPedType, true);
DMAudio.DestroyEntity(m_audioEntityId);
+
+ // Because of the nature of ped lists in GTA, it can sometimes be outdated.
+ // Remove ourself from nearPeds list of the Peds in our nearPeds list.
+#ifdef FIX_BUGS
+ for(int i = 0; i < m_numNearPeds; i++) {
+ CPed *nearPed = m_nearPeds[i];
+ assert(nearPed != nil);
+ if (!nearPed->IsPointerValid())
+ continue;
+
+ for(int j = 0; j < nearPed->m_numNearPeds;) {
+ assert(j == ARRAY_SIZE(m_nearPeds) - 1 || nearPed->m_nearPeds[j] || !nearPed->m_nearPeds[j+1]); // ensure nil comes after nil
+
+ if (nearPed->m_nearPeds[j] == this) {
+ for (int k = j; k < ARRAY_SIZE(m_nearPeds) - 1; k++) {
+ nearPed->m_nearPeds[k] = nearPed->m_nearPeds[k + 1];
+ nearPed->m_nearPeds[k + 1] = nil;
+ }
+ nearPed->m_numNearPeds--;
+ } else
+ j++;
+ }
+ }
+#endif
}
void
@@ -398,13 +422,15 @@ CPed::BuildPedLists(void)
} else
removePed = true;
}
+
+ assert(i == ARRAY_SIZE(m_nearPeds) - 1 || m_nearPeds[i] || !m_nearPeds[i+1]); // ensure nil comes after nil
+
if (removePed) {
// If we arrive here, the ped we're checking isn't "near", so we should remove it.
for (int j = i; j < ARRAY_SIZE(m_nearPeds) - 1; j++) {
m_nearPeds[j] = m_nearPeds[j + 1];
m_nearPeds[j + 1] = nil;
}
- // Above loop won't work on last slot, so we need to empty it.
m_nearPeds[ARRAY_SIZE(m_nearPeds) - 1] = nil;
m_numNearPeds--;
} else
@@ -3023,7 +3049,7 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints)
CColModel *hisCol = CModelInfo::GetModelInfo(collidingEnt->GetModelIndex())->GetColModel();
if (!bUsesCollision)
- return false;
+ return 0;
if (collidingEnt->IsVehicle() && ((CVehicle*)collidingEnt)->IsBoat())
collidedWithBoat = true;
@@ -6068,7 +6094,7 @@ CPed::FollowPath(void)
}
void
-CPed::SetEvasiveStep(CEntity *reason, uint8 animType)
+CPed::SetEvasiveStep(CPhysical *reason, uint8 animType)
{
AnimationId stepAnim;
@@ -6086,22 +6112,23 @@ CPed::SetEvasiveStep(CEntity *reason, uint8 animType)
if (neededTurn > PI)
neededTurn = TWOPI - neededTurn;
- CVehicle *veh = (CVehicle*)reason;
- if (reason->IsVehicle() && veh->m_vehType == VEHICLE_TYPE_CAR) {
+ if (reason->IsVehicle() && ((CVehicle*)reason)->IsCar()) {
+ CVehicle *veh = (CVehicle*)reason;
if (veh->m_nCarHornTimer != 0) {
vehPressedHorn = true;
if (!IsPlayer())
animType = 1;
}
}
- if (neededTurn <= DEGTORAD(90.0f) || veh->GetModelIndex() == MI_RCBANDIT || vehPressedHorn || animType != 0) {
- SetLookFlag(veh, true);
- if ((CGeneral::GetRandomNumber() & 1) && veh->GetModelIndex() != MI_RCBANDIT && animType == 0) {
+
+ if (neededTurn <= DEGTORAD(90.0f) || reason->GetModelIndex() == MI_RCBANDIT || vehPressedHorn || animType != 0) {
+ SetLookFlag(reason, true);
+ if ((CGeneral::GetRandomNumber() & 1) && reason->GetModelIndex() != MI_RCBANDIT && animType == 0) {
stepAnim = ANIM_STD_HAILTAXI;
} else {
- float vehDirection = CGeneral::GetRadianAngleBetweenPoints(
- veh->m_vecMoveSpeed.x, veh->m_vecMoveSpeed.y,
+ float dangerDirection = CGeneral::GetRadianAngleBetweenPoints(
+ reason->m_vecMoveSpeed.x, reason->m_vecMoveSpeed.y,
0.0f, 0.0f);
// Let's turn our back to the "reason"
@@ -6111,14 +6138,14 @@ CPed::SetEvasiveStep(CEntity *reason, uint8 animType)
angleToFace -= TWOPI;
// We don't want to run towards car's direction
- float dangerZone = angleToFace - vehDirection;
+ float dangerZone = angleToFace - dangerDirection;
dangerZone = CGeneral::LimitRadianAngle(dangerZone);
// So, add or subtract 90deg (jump to left/right) according to that
if (dangerZone > 0.0f)
- angleToFace = vehDirection - HALFPI;
+ angleToFace = dangerDirection - HALFPI;
else
- angleToFace = vehDirection + HALFPI;
+ angleToFace = dangerDirection + HALFPI;
stepAnim = ANIM_STD_NUM;
if (animType == 0 || animType == 1)
diff --git a/src/peds/Ped.h b/src/peds/Ped.h
index 6d32b65e..33839aa7 100644
--- a/src/peds/Ped.h
+++ b/src/peds/Ped.h
@@ -625,7 +625,7 @@ public:
void SetAimFlag(CEntity* to);
void SetAimFlag(float angle);
void SetAmmo(eWeaponType weaponType, uint32 ammo);
- void SetEvasiveStep(CEntity*, uint8);
+ void SetEvasiveStep(CPhysical*, uint8);
void GrantAmmo(eWeaponType, uint32);
void SetEvasiveDive(CPhysical*, uint8);
void SetAttack(CEntity*);
diff --git a/src/peds/PedFight.cpp b/src/peds/PedFight.cpp
index c03d492a..46ac369c 100644
--- a/src/peds/PedFight.cpp
+++ b/src/peds/PedFight.cpp
@@ -1044,7 +1044,7 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk)
if (IsPlayer())
moveAssoc->speed = 1.3f;
- m_takeAStepAfterAttack = 0;
+ m_takeAStepAfterAttack = false;
m_fightButtonPressure = 0;
} else if (IsPlayer() && m_currentWeapon != WEAPONTYPE_UNARMED) {
CAnimBlendAssociation *moveAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, tFightMoves[m_curFightMove].animId, 4.0f);
diff --git a/src/peds/PedIK.cpp b/src/peds/PedIK.cpp
index de2c23ce..8358a196 100644
--- a/src/peds/PedIK.cpp
+++ b/src/peds/PedIK.cpp
@@ -17,9 +17,9 @@ const RwV3d XaxisIK = { 1.0f, 0.0f, 0.0f};
const RwV3d YaxisIK = { 0.0f, 1.0f, 0.0f};
const RwV3d ZaxisIK = { 0.0f, 0.0f, 1.0f};
-CPedIK::CPedIK(CPed *ped)
+CPedIK::CPedIK(CPed *ped) : m_ped(ped)
{
- m_ped = ped;
+ assert(ped != nil);
m_flags = 0;
m_headOrient.yaw = 0.0f;
m_headOrient.pitch = 0.0f;
diff --git a/src/peds/PedIK.h b/src/peds/PedIK.h
index 4eeef6f0..9077fbea 100644
--- a/src/peds/PedIK.h
+++ b/src/peds/PedIK.h
@@ -34,7 +34,7 @@ public:
AIMS_WITH_ARM = 4,
};
- CPed *m_ped;
+ CPed *Const m_ped;
LimbOrientation m_headOrient;
LimbOrientation m_torsoOrient;
LimbOrientation m_upperArmOrient;
diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp
index a67e2abc..93a403bd 100644
--- a/src/peds/PlayerPed.cpp
+++ b/src/peds/PlayerPed.cpp
@@ -682,8 +682,8 @@ CPlayerPed::PlayerControlFighter(CPad *padUsed)
if (padMove > 0.0f) {
m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(0.0f, 0.0f, -leftRight, upDown) - TheCamera.Orientation;
- m_takeAStepAfterAttack = padMove > 2 * PAD_MOVE_TO_GAME_WORLD_MOVE;
- if (padUsed->GetSprint() && padMove > 1 * PAD_MOVE_TO_GAME_WORLD_MOVE)
+ m_takeAStepAfterAttack = padMove > (2 * PAD_MOVE_TO_GAME_WORLD_MOVE);
+ if (padUsed->GetSprint() && padMove > (1 * PAD_MOVE_TO_GAME_WORLD_MOVE))
bIsAttacking = false;
}