CPed fixes

Signed-off-by: eray orçunus <erayorcunus@gmail.com>
This commit is contained in:
eray orçunus 2019-07-01 19:26:46 +03:00
parent 9564438647
commit 8b36718c0a
3 changed files with 39 additions and 55 deletions

View File

@ -461,11 +461,12 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
for(int i = 0; i < NUM_PED_WEAPONTYPES; i++) for(int i = 0; i < NUM_PED_WEAPONTYPES; i++)
{ {
GetWeapon(i)->m_eWeaponType = WEAPONTYPE_UNARMED; CWeapon *weapon = GetWeapon(i);
GetWeapon(i)->m_eWeaponState = WEAPONSTATE_READY; weapon->m_eWeaponType = WEAPONTYPE_UNARMED;
GetWeapon(i)->m_nAmmoInClip = 0; weapon->m_eWeaponState = WEAPONSTATE_READY;
GetWeapon(i)->m_nAmmoTotal = 0; weapon->m_nAmmoInClip = 0;
GetWeapon(i)->m_nTimer = 0; weapon->m_nAmmoTotal = 0;
weapon->m_nTimer = 0;
} }
m_lastHitState = 0; m_lastHitState = 0;
@ -479,26 +480,22 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
} }
void void
CPed::GiveWeapon(eWeaponType weaponType, int ammo) CPed::GiveWeapon(eWeaponType weaponType, uint32 ammo)
{ {
CWeapon *weapon = GetWeapon(weaponType); if (HasWeapon(weaponType)) {
if (HasWeapon(weaponType))
{
if (ammo > 99999) if (ammo > 99999)
weapon->m_nAmmoTotal = 99999; m_weapons[weaponType].m_nAmmoTotal = 99999;
else else
weapon->m_nAmmoTotal = ammo; m_weapons[weaponType].m_nAmmoTotal = ammo;
weapon->Reload(); m_weapons[weaponType].Reload();
} } else {
else m_weapons[weaponType].Initialise(weaponType, ammo);
{
weapon->Initialise(weaponType, ammo);
// TODO: It seems game uses this as both weapon count and max WeaponType we have, which is ofcourse erroneous. // TODO: It seems game uses this as both weapon count and max WeaponType we have, which is ofcourse erroneous.
m_maxWeaponTypeAllowed++; m_maxWeaponTypeAllowed++;
} }
if (weapon->m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO) if (m_weapons[weaponType].m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO)
weapon->m_eWeaponState = WEAPONSTATE_READY; m_weapons[weaponType].m_eWeaponState = WEAPONSTATE_READY;
} }
static RwObject* static RwObject*
@ -1211,10 +1208,9 @@ CPed::RemoveWeaponModel(int modelId)
} }
void void
CPed::SetCurrentWeapon(eWeaponType weaponType) CPed::SetCurrentWeapon(uint32 weaponType)
{ {
CWeaponInfo *weaponInfo; CWeaponInfo *weaponInfo;
if (HasWeapon(weaponType)) { if (HasWeapon(weaponType)) {
weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
RemoveWeaponModel(weaponInfo->m_nModelId); RemoveWeaponModel(weaponInfo->m_nModelId);
@ -1230,15 +1226,11 @@ CPed::SetCurrentWeapon(eWeaponType weaponType)
bool bool
CPed::SelectGunIfArmed(void) CPed::SelectGunIfArmed(void)
{ {
eWeaponType weaponType;
for (int i = 0; i < m_maxWeaponTypeAllowed; i++) { for (int i = 0; i < m_maxWeaponTypeAllowed; i++) {
if (GetWeapon(i)->m_nAmmoTotal > 0) { if (GetWeapon(i)->m_nAmmoTotal > 0) {
weaponType = GetWeapon(i)->m_eWeaponType; eWeaponType weaponType = GetWeapon(i)->m_eWeaponType;
if (weaponType >= WEAPONTYPE_COLT45 && weaponType != WEAPONTYPE_M16 && weaponType <= WEAPONTYPE_FLAMETHROWER) { if (weaponType >= WEAPONTYPE_COLT45 && weaponType != WEAPONTYPE_M16 && weaponType <= WEAPONTYPE_FLAMETHROWER) {
SetCurrentWeapon(weaponType); SetCurrentWeapon(i);
return true; return true;
} }
} }
@ -1920,7 +1912,7 @@ CPed::IsPointerValid(void)
return false; return false;
} }
// Binary insertion sort // Some kind of binary sort
void void
CPed::SortPeds(CPed** list, int min, int max) CPed::SortPeds(CPed** list, int min, int max)
{ {
@ -1933,25 +1925,21 @@ CPed::SortPeds(CPed** list, int min, int max)
int left = max; int left = max;
int right; int right;
for(right = min; right <= left; ) for(right = min; right <= left; ){
{
// Those 1.0s are to make sure loop always run for first time. // Those 1.0s are to make sure loop always run for first time.
for (float rightDist = middleDist-1.0f; middleDist > rightDist; right++) for (float rightDist = middleDist-1.0f; middleDist > rightDist; right++) {
{
rightDiff = GetPosition() - list[right]->GetPosition(); rightDiff = GetPosition() - list[right]->GetPosition();
rightDist = rightDiff.Magnitude(); rightDist = rightDiff.Magnitude();
} }
right--; right--;
for (float leftDist = middleDist+1.0f; middleDist < leftDist; left--) for (float leftDist = middleDist+1.0f; middleDist < leftDist; left--) {
{
leftDiff = GetPosition() - list[left]->GetPosition(); leftDiff = GetPosition() - list[left]->GetPosition();
leftDist = leftDiff.Magnitude(); leftDist = leftDiff.Magnitude();
} }
left++; left++;
if (right <= left) if (right <= left) {
{
CPed *ped = list[right]; CPed *ped = list[right];
list[right] = list[left]; list[right] = list[left];
list[left] = ped; list[left] = ped;
@ -1967,7 +1955,7 @@ void
CPed::BuildPedLists(void) CPed::BuildPedLists(void)
{ {
static CPed* unsortedNearPeds[10]; static CPed* unsortedNearPeds[10];
static uint16 nextNearPedSlot; uint16 nextNearPedSlot = 0;
if ((CTimer::GetFrameCounter() + m_randomSeed) & 15) { if ((CTimer::GetFrameCounter() + m_randomSeed) & 15) {
@ -2000,16 +1988,11 @@ CPed::BuildPedLists(void)
(centre.x + 20.0f) * 0.025f + 50.0f, (centre.x + 20.0f) * 0.025f + 50.0f,
(centre.y + 20.0f) * 0.025f + 50.0f); (centre.y + 20.0f) * 0.025f + 50.0f);
nextNearPedSlot = 0; for(int y = rect.top; y <= rect.bottom; y++) {
for(int y = rect.top; y <= rect.bottom; y++) for(int x = rect.left; x <= rect.right; x++) {
{ for (CPtrNode *pedPtrNode = CWorld::GetSector(x,y)->m_lists[ENTITYLIST_PEDS].first; pedPtrNode; pedPtrNode = pedPtrNode->next) {
for(int x = rect.left; x <= rect.right; x++)
{
for (CPtrNode *pedPtrNode = CWorld::GetSector(x,y)->m_lists[ENTITYLIST_PEDS].first; pedPtrNode; pedPtrNode = pedPtrNode->next)
{
CPed *ped = (CPed*)pedPtrNode->item; CPed *ped = (CPed*)pedPtrNode->item;
if (ped != this && !ped->bInVehicle) if (ped != this && !ped->bInVehicle) {
{
float dist = (ped->GetPosition() - GetPosition()).Magnitude2D(); float dist = (ped->GetPosition() - GetPosition()).Magnitude2D();
if (distanceMultToCountPedNear * 30.0f > dist) if (distanceMultToCountPedNear * 30.0f > dist)
{ {
@ -2022,8 +2005,7 @@ CPed::BuildPedLists(void)
} }
unsortedNearPeds[nextNearPedSlot] = nil; unsortedNearPeds[nextNearPedSlot] = nil;
SortPeds(unsortedNearPeds, 0, nextNearPedSlot - 1); SortPeds(unsortedNearPeds, 0, nextNearPedSlot - 1);
for (m_numNearPeds = 0; m_numNearPeds < 10; m_numNearPeds++) for (m_numNearPeds = 0; m_numNearPeds < 10; m_numNearPeds++) {
{
CPed *ped = unsortedNearPeds[m_numNearPeds]; CPed *ped = unsortedNearPeds[m_numNearPeds];
if (!ped) if (!ped)
break; break;
@ -2052,6 +2034,8 @@ CPed::SetModelIndex(uint32 mi)
m_headingRate = m_pedStats->m_headingChangeRate; m_headingRate = m_pedStats->m_headingChangeRate;
m_animGroup = static_cast<AssocGroupId>(modelInfo->m_animGroup); m_animGroup = static_cast<AssocGroupId>(modelInfo->m_animGroup);
CAnimManager::AddAnimation((RpClump*) m_rwObject, m_animGroup, ANIM_IDLE_STANCE); CAnimManager::AddAnimation((RpClump*) m_rwObject, m_animGroup, ANIM_IDLE_STANCE);
// This is a mistake by R*, velocity is CVector, whereas m_vecAnimMoveDelta is CVector2D.
(*RPANIMBLENDCLUMPDATA(m_rwObject))->velocity = (CVector*) &m_vecAnimMoveDelta; (*RPANIMBLENDCLUMPDATA(m_rwObject))->velocity = (CVector*) &m_vecAnimMoveDelta;
} }

View File

@ -250,7 +250,7 @@ public:
float m_movedY; float m_movedY;
float m_fRotationCur; float m_fRotationCur;
float m_fRotationDest; float m_fRotationDest;
uint32 m_headingRate; float m_headingRate;
uint16 m_vehEnterType; uint16 m_vehEnterType;
uint16 m_walkAroundType; uint16 m_walkAroundType;
CEntity *m_pCurrentPhysSurface; CEntity *m_pCurrentPhysSurface;
@ -368,7 +368,7 @@ public:
void ClearAttack(void); void ClearAttack(void);
bool IsPedHeadAbovePos(float zOffset); bool IsPedHeadAbovePos(float zOffset);
void RemoveWeaponModel(int modelId); void RemoveWeaponModel(int modelId);
void SetCurrentWeapon(eWeaponType weaponType); void SetCurrentWeapon(uint32 weaponType);
bool SelectGunIfArmed(void); bool SelectGunIfArmed(void);
void Duck(void); void Duck(void);
void ClearDuck(void); void ClearDuck(void);
@ -382,7 +382,7 @@ public:
bool IsPointerValid(void); bool IsPointerValid(void);
void SortPeds(CPed**, int, int); void SortPeds(CPed**, int, int);
void BuildPedLists(void); void BuildPedLists(void);
void GiveWeapon(eWeaponType weaponType, int ammo); void GiveWeapon(eWeaponType weaponType, uint32 ammo);
void SetPedStats(ePedStats); void SetPedStats(ePedStats);
static void GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float offset); static void GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float offset);
static void GetPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float seatPosMult); static void GetPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enterType, float seatPosMult);
@ -416,10 +416,10 @@ public:
static void PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *assoc, void *arg); static void PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *assoc, void *arg);
static void PedSetDraggedOutCarPositionCB(CAnimBlendAssociation *assoc, void *arg); static void PedSetDraggedOutCarPositionCB(CAnimBlendAssociation *assoc, void *arg);
bool HasWeapon(eWeaponType weaponType) { return m_weapons[weaponType].m_eWeaponType == weaponType; } inline bool HasWeapon(uint32 weaponType) { return m_weapons[weaponType].m_eWeaponType == weaponType; }
CWeapon *GetWeapon(void) { return &m_weapons[m_currentWeapon]; } inline CWeapon *GetWeapon(uint32 weaponType) { return &m_weapons[weaponType]; }
CWeapon* GetWeapon(uint32 weaponType) { return &m_weapons[weaponType]; } inline CWeapon *GetWeapon(void) { return &m_weapons[m_currentWeapon]; }
RwFrame *GetNodeFrame(int nodeId) { return m_pFrames[nodeId]->frame; } inline RwFrame *GetNodeFrame(int nodeId) { return m_pFrames[nodeId]->frame; }
// to make patching virtual functions possible // to make patching virtual functions possible
void SetModelIndex_(uint32 mi) { CPed::SetModelIndex(mi); } void SetModelIndex_(uint32 mi) { CPed::SetModelIndex(mi); }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "Entity.h" #include "Entity.h"
enum eWeaponType enum eWeaponType : uint32
{ {
WEAPONTYPE_UNARMED = 0, WEAPONTYPE_UNARMED = 0,
WEAPONTYPE_BASEBALLBAT, WEAPONTYPE_BASEBALLBAT,