diff options
author | Nikolay Korolev <nickvnuk@gmail.com> | 2020-05-16 09:53:20 +0200 |
---|---|---|
committer | Nikolay Korolev <nickvnuk@gmail.com> | 2020-05-16 09:53:20 +0200 |
commit | 03c4a979c8e2755670818882273faa26e1de3e4f (patch) | |
tree | 0083ee65e96a5b70799b0fb6b88ac0f9b6d931ac /src | |
parent | Merge remote-tracking branch 'upstream/miami' into miami (diff) | |
download | re3-03c4a979c8e2755670818882273faa26e1de3e4f.tar re3-03c4a979c8e2755670818882273faa26e1de3e4f.tar.gz re3-03c4a979c8e2755670818882273faa26e1de3e4f.tar.bz2 re3-03c4a979c8e2755670818882273faa26e1de3e4f.tar.lz re3-03c4a979c8e2755670818882273faa26e1de3e4f.tar.xz re3-03c4a979c8e2755670818882273faa26e1de3e4f.tar.zst re3-03c4a979c8e2755670818882273faa26e1de3e4f.zip |
Diffstat (limited to '')
-rw-r--r-- | src/peds/CivilianPed.cpp | 76 | ||||
-rw-r--r-- | src/peds/CivilianPed.h | 1 |
2 files changed, 31 insertions, 46 deletions
diff --git a/src/peds/CivilianPed.cpp b/src/peds/CivilianPed.cpp index f4feacf7..50b04df3 100644 --- a/src/peds/CivilianPed.cpp +++ b/src/peds/CivilianPed.cpp @@ -386,6 +386,34 @@ const int32 gFrequencyOfAttractorAttempt = 11; const float gDistanceToSeekAttractors = 50.0f; const float gMaxDistanceToAttract = 10.0f; +/* Probably this was inlined */ +void CCivilianPed::FindNearbyAttractorsSectorList(CPtrList& list, float& minDistance, C2dEffect*& pClosestAttractor, CEntity*& pAttractorEntity) +{ + for (CPtrNode* pNode = list.first; pNode != nil; pNode = pNode->next) { + CEntity* pEntity = (CEntity*)pNode->item; + //if (pEntity->IsObject() && (CObject*)(pEntity)->IsBroken()) + //continue; + CBaseModelInfo* pModelInfo = CModelInfo::GetModelInfo(pEntity->GetModelIndex()); + for (int i = 0; i < pModelInfo->GetNum2dEffects(); i++) { + C2dEffect* pEffect = pModelInfo->Get2dEffect(i); + if (pEffect->type != EFFECT_PED_ATTRACTOR) + continue; + if (!IsAttractedTo(pEffect->pedattr.type)) + continue; + CVector pos; + CPedAttractorManager::ComputeEffectPos(pEffect, pEntity->GetMatrix(), pos); + if ((pos - GetPosition()).MagnitudeSqr() < minDistance) { + CPedAttractorManager* pManager = GetPedAttractorManager(); + if (pManager->HasEmptySlot(pEffect) && pManager->IsApproachable(pEffect, pEntity->GetMatrix(), 0, this)) { + pClosestAttractor = pEffect; + pAttractorEntity = pEntity; + minDistance = (pos - GetPosition()).MagnitudeSqr(); + } + } + } + } +} + void CCivilianPed::UseNearbyAttractors() { if (CWeather::Rain < 0.2f && !m_bAttractorUnk) @@ -420,52 +448,8 @@ void CCivilianPed::UseNearbyAttractors() for (int y = ystart; y <= yend; y++) { for (int x = xstart; x <= xend; x++) { CSector* s = CWorld::GetSector(x, y); - for (CPtrNode* pNode = s->m_lists[ENTITYLIST_BUILDINGS].first; pNode != nil; pNode = pNode->next) { - CEntity* pEntity = (CEntity*)pNode->item; - //if (pEntity->IsObject() && (CObject*)(pEntity)->IsBroken()) - //continue; - CBaseModelInfo* pModelInfo = CModelInfo::GetModelInfo(pEntity->GetModelIndex()); - for (int i = 0; i < pModelInfo->GetNum2dEffects(); i++) { - C2dEffect* pEffect = pModelInfo->Get2dEffect(i); - if (pEffect->type != EFFECT_PED_ATTRACTOR) - continue; - if (!IsAttractedTo(pEffect->pedattr.type)) - continue; - CVector pos; - CPedAttractorManager::ComputeEffectPos(pEffect, pEntity->GetMatrix(), pos); - if ((pos - GetPosition()).MagnitudeSqr() < minDistance) { - CPedAttractorManager* pManager = GetPedAttractorManager(); - if (pManager->HasEmptySlot(pEffect) && pManager->IsApproachable(pEffect, pEntity->GetMatrix(), 0, this)) { - pClosestAttractor = pEffect; - pAttractorEntity = pEntity; - minDistance = (pos - GetPosition()).MagnitudeSqr(); - } - } - } - } - for (CPtrNode* pNode = s->m_lists[ENTITYLIST_OBJECTS].first; pNode != nil; pNode = pNode->next) { - CEntity* pEntity = (CEntity*)pNode->item; - //if (pEntity->IsObject() && (CObject*)(pEntity)->IsBroken()) - //continue; - CBaseModelInfo* pModelInfo = CModelInfo::GetModelInfo(pEntity->GetModelIndex()); - for (int i = 0; i < pModelInfo->GetNum2dEffects(); i++) { - C2dEffect* pEffect = pModelInfo->Get2dEffect(i); - if (pEffect->type != EFFECT_PED_ATTRACTOR) - continue; - if (!IsAttractedTo(pEffect->pedattr.type)) - continue; - CVector pos; - CPedAttractorManager::ComputeEffectPos(pEffect, pEntity->GetMatrix(), pos); - if ((pos - GetPosition()).MagnitudeSqr() < minDistance) { - CPedAttractorManager* pManager = GetPedAttractorManager(); - if (pManager->HasEmptySlot(pEffect) && pManager->IsApproachable(pEffect, pEntity->GetMatrix(), 0, this)) { - pClosestAttractor = pEffect; - pAttractorEntity = pEntity; - minDistance = (pos - GetPosition()).MagnitudeSqr(); - } - } - } - } + FindNearbyAttractorsSectorList(s->m_lists[ENTITYLIST_BUILDINGS], minDistance, pClosestAttractor, pAttractorEntity); + FindNearbyAttractorsSectorList(s->m_lists[ENTITYLIST_OBJECTS], minDistance, pClosestAttractor, pAttractorEntity); } } if (pClosestAttractor) diff --git a/src/peds/CivilianPed.h b/src/peds/CivilianPed.h index 558380b7..27d458f7 100644 --- a/src/peds/CivilianPed.h +++ b/src/peds/CivilianPed.h @@ -13,6 +13,7 @@ public: void CivilianAI(void); void ProcessControl(void); void UseNearbyAttractors(void); + void FindNearbyAttractorsSectorList(CPtrList&, float&, C2dEffect*&, CEntity*&); bool IsAttractedTo(int8); }; #ifndef PED_SKIN |