diff options
Diffstat (limited to 'src/peds')
-rw-r--r-- | src/peds/CivilianPed.cpp | 210 | ||||
-rw-r--r-- | src/peds/CivilianPed.h | 5 | ||||
-rw-r--r-- | src/peds/CopPed.cpp | 386 | ||||
-rw-r--r-- | src/peds/CopPed.h | 20 | ||||
-rw-r--r-- | src/peds/DummyPed.h | 2 | ||||
-rw-r--r-- | src/peds/EmergencyPed.cpp | 25 | ||||
-rw-r--r-- | src/peds/Gangs.cpp | 69 | ||||
-rw-r--r-- | src/peds/Gangs.h | 31 | ||||
-rw-r--r-- | src/peds/Ped.cpp | 10091 | ||||
-rw-r--r-- | src/peds/Ped.h | 436 | ||||
-rw-r--r-- | src/peds/PedAttractor.cpp | 775 | ||||
-rw-r--r-- | src/peds/PedAttractor.h | 196 | ||||
-rw-r--r-- | src/peds/PedChat.cpp | 195 | ||||
-rw-r--r-- | src/peds/PedDebug.cpp | 19 | ||||
-rw-r--r-- | src/peds/PedIK.cpp | 493 | ||||
-rw-r--r-- | src/peds/PedIK.h | 5 | ||||
-rw-r--r-- | src/peds/PedPlacement.cpp | 16 | ||||
-rw-r--r-- | src/peds/PedPlacement.h | 4 | ||||
-rw-r--r-- | src/peds/PedStats.h | 5 | ||||
-rw-r--r-- | src/peds/PlayerPed.cpp | 613 | ||||
-rw-r--r-- | src/peds/PlayerPed.h | 30 | ||||
-rw-r--r-- | src/peds/Population.cpp | 357 | ||||
-rw-r--r-- | src/peds/Population.h | 11 |
23 files changed, 9593 insertions, 4401 deletions
diff --git a/src/peds/CivilianPed.cpp b/src/peds/CivilianPed.cpp index 2d782a73..51c11775 100644 --- a/src/peds/CivilianPed.cpp +++ b/src/peds/CivilianPed.cpp @@ -9,30 +9,9 @@ #include "World.h" #include "Vehicle.h" #include "SurfaceTable.h" - -#ifdef PEDS_REPORT_CRIMES_ON_PHONE -eCrimeType -EventTypeToCrimeType(eEventType event) -{ - eCrimeType crime; - switch (event) { - case EVENT_ASSAULT: crime = CRIME_HIT_PED; break; - case EVENT_RUN_REDLIGHT: crime = CRIME_RUN_REDLIGHT; break; - case EVENT_ASSAULT_POLICE: crime = CRIME_HIT_COP; break; - case EVENT_GUNSHOT: crime = CRIME_POSSESSION_GUN; break; - case EVENT_STEAL_CAR: crime = CRIME_STEAL_CAR; break; - case EVENT_HIT_AND_RUN: crime = CRIME_RUNOVER_PED; break; - case EVENT_HIT_AND_RUN_COP: crime = CRIME_RUNOVER_COP; break; - case EVENT_SHOOT_PED: crime = CRIME_SHOOT_PED; break; - case EVENT_SHOOT_COP: crime = CRIME_SHOOT_COP; break; - case EVENT_PED_SET_ON_FIRE: crime = CRIME_PED_BURNED; break; - case EVENT_COP_SET_ON_FIRE: crime = CRIME_COP_BURNED; break; - case EVENT_CAR_SET_ON_FIRE: crime = CRIME_VEHICLE_BURNED; break; - default: crime = CRIME_NONE; break; - } - return crime; -} -#endif +#include "Weather.h" +#include "PedAttractor.h" +#include "Object.h" CCivilianPed::CCivilianPed(ePedType pedtype, uint32 mi) : CPed(pedtype) { @@ -40,6 +19,8 @@ CCivilianPed::CCivilianPed(ePedType pedtype, uint32 mi) : CPed(pedtype) for (int i = 0; i < ARRAY_SIZE(m_nearPeds); i++) { m_nearPeds[i] = nil; } + m_nAttractorCycleState = 0; + m_bAttractorUnk = (CGeneral::GetRandomNumberInRange(0.0f, 1.0f) < 1.25f); } void @@ -122,7 +103,7 @@ CCivilianPed::CivilianAI(void) SetLookTimer(500); } else if (closestThreatFlag == PED_FLAG_DEADPEDS) { float eventDistSqr = (m_pEventEntity->GetPosition() - GetPosition()).MagnitudeSqr2D(); - if (IsGangMember() && m_nPedType == ((CPed*)m_pEventEntity)->m_nPedType) { + if (((CPed*)m_pEventEntity)->bIsDrowning || IsGangMember() && m_nPedType == ((CPed*)m_pEventEntity)->m_nPedType) { if (eventDistSqr < sq(5.0f)) { SetFindPathAndFlee(m_pEventEntity, 2000); SetMoveState(PEDMOVE_RUN); @@ -137,26 +118,12 @@ CCivilianPed::CivilianAI(void) investigateDeadPed = false; } -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - int32 eventId = CheckForPlayerCrimes((CPed*)m_pEventEntity); - eCrimeType crime = (eventId == -1 ? CRIME_NONE : EventTypeToCrimeType(gaEvent[eventId].type)); - bool eligibleToReport = crime != CRIME_NONE && m_pedStats->m_fear <= m_pedStats->m_lawfulness && m_pedStats->m_temper <= m_pedStats->m_fear; - if (IsGangMember() || !eligibleToReport || !RunToReportCrime(crime)) -#endif if (investigateDeadPed) SetInvestigateEvent(EVENT_DEAD_PED, CVector2D(m_pEventEntity->GetPosition()), 1.0f, 20000, 0.0f); } else { -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - int32 eventId = CheckForPlayerCrimes((CPed*)m_pEventEntity); - eCrimeType crime = (eventId == -1 ? CRIME_NONE : EventTypeToCrimeType(gaEvent[eventId].type)); - bool eligibleToReport = crime != CRIME_NONE && m_pedStats->m_fear <= m_pedStats->m_lawfulness && m_pedStats->m_temper <= m_pedStats->m_fear; - if(!eligibleToReport || !RunToReportCrime(crime)) -#endif - { - SetFindPathAndFlee(m_pEventEntity, 5000); - SetMoveState(PEDMOVE_RUN); - } + SetFindPathAndFlee(m_pEventEntity, 5000); + SetMoveState(PEDMOVE_RUN); } } else if (closestThreatFlag == PED_FLAG_EXPLOSION) { CVector2D eventDistVec = m_eventOrThreat - GetPosition(); @@ -184,55 +151,30 @@ CCivilianPed::CivilianAI(void) } } } else { -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - bool youShouldRunEventually = false; - bool dontGoToPhone = false; -#endif if (m_threatEntity && m_threatEntity->IsPed()) { CPed *threatPed = (CPed*)m_threatEntity; if (m_pedStats->m_fear <= 100 - threatPed->m_pedStats->m_temper && threatPed->m_nPedType != PEDTYPE_COP) { if (threatPed->GetWeapon(m_currentWeapon).IsTypeMelee() || !GetWeapon()->IsTypeMelee()) { if (threatPed->IsPlayer() && FindPlayerPed()->m_pWanted->m_CurrentCops != 0) { if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS) { -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - dontGoToPhone = true; -#endif SetFindPathAndFlee(m_threatEntity, 10000); } } else { -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - dontGoToPhone = true; -#endif SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, m_threatEntity); } } } else { -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - youShouldRunEventually = true; -#else - SetFindPathAndFlee(m_threatEntity, 10000, true); -#endif - } - } - -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - if (!dontGoToPhone) { - int32 eventId = CheckForPlayerCrimes(nil); - eCrimeType crime = (eventId == -1 ? CRIME_NONE : EventTypeToCrimeType(gaEvent[eventId].type)); - bool eligibleToReport = crime != CRIME_NONE && m_pedStats->m_fear <= m_pedStats->m_lawfulness; - - if ((!eligibleToReport || !RunToReportCrime(crime)) && youShouldRunEventually) { SetFindPathAndFlee(m_threatEntity, 10000, true); } } -#endif } } +// --MIAMI: Done except comments void CCivilianPed::ProcessControl(void) { - if (m_nZoneLevel > LEVEL_GENERIC && m_nZoneLevel != CCollision::ms_collisionInMemory) + if (CharCreatedBy == TODO_CHAR) return; CPed::ProcessControl(); @@ -243,7 +185,7 @@ CCivilianPed::ProcessControl(void) if (DyingOrDead()) return; - GetWeapon()->Update(m_audioEntityId); + GetWeapon()->Update(m_audioEntityId, nil); switch (m_nPedState) { case PED_WANDER_RANGE: case PED_WANDER_PATH: @@ -260,34 +202,20 @@ CCivilianPed::ProcessControl(void) // fall through case PED_SEEK_POS: if (Seek()) { - if ((m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA) && m_pNextPathNode) { + if ((m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA || m_objective == OBJECTIVE_SPRINT_TO_AREA || + IsUseAttractorObjective(m_objective)) && m_pNextPathNode) { m_pNextPathNode = nil; -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - } else if (bRunningToPhone && m_objective < OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE) { - if (!isPhoneAvailable(m_phoneId)) { - RestorePreviousState(); - if (crimeReporters[m_phoneId] == this) - crimeReporters[m_phoneId] = nil; - m_phoneId = -1; - bRunningToPhone = false; - } else { - crimeReporters[m_phoneId] = this; - m_facePhoneStart = true; - m_nPedState = PED_FACE_PHONE; - } -#else } else if (bRunningToPhone) { if (gPhoneInfo.m_aPhones[m_phoneId].m_nState != PHONE_STATE_FREE) { RestorePreviousState(); m_phoneId = -1; } else { gPhoneInfo.m_aPhones[m_phoneId].m_nState = PHONE_STATE_REPORTING_CRIME; - m_nPedState = PED_FACE_PHONE; + SetPedState(PED_FACE_PHONE); } -#endif } else if (m_objective != OBJECTIVE_KILL_CHAR_ANY_MEANS && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT) { - if (m_objective == OBJECTIVE_FOLLOW_CHAR_IN_FORMATION) { + if (m_pedInObjective && m_objective == OBJECTIVE_FOLLOW_CHAR_IN_FORMATION) { if (m_moved.Magnitude() == 0.0f) { if (m_pedInObjective->m_nMoveState == PEDMOVE_STILL) m_fRotationDest = m_pedInObjective->m_fRotationCur; @@ -295,7 +223,8 @@ CCivilianPed::ProcessControl(void) } else if (m_objective == OBJECTIVE_GOTO_CHAR_ON_FOOT && m_pedInObjective && m_pedInObjective->m_nMoveState != PEDMOVE_STILL) { SetMoveState(m_pedInObjective->m_nMoveState); - } else if (m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA) { + } else if (m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA || m_objective == OBJECTIVE_SPRINT_TO_AREA || + IsUseAttractorObjective(m_objective)) { SetIdle(); } else { RestorePreviousState(); @@ -305,7 +234,7 @@ CCivilianPed::ProcessControl(void) break; case PED_FACE_PHONE: if (FacePhone()) - m_nPedState = PED_MAKE_CALL; + SetPedState(PED_MAKE_CALL); break; case PED_MAKE_CALL: if (MakePhonecall()) @@ -361,6 +290,8 @@ CCivilianPed::ProcessControl(void) GetPosition().x - m_pMyVehicle->GetPosition().x, GetPosition().y - m_pMyVehicle->GetPosition().y, 0.0f); DMAudio.PlayOneShot(m_pMyVehicle->m_audioEntityId, SOUND_CAR_JERK, 0.0f); + m_pMyVehicle->pDriver->Say(SOUND_PED_PLAYER_BEFORESEX); + Say(SOUND_PED_PLAYER_BEFORESEX); int playerSexFrequency = CWorld::Players[CWorld::PlayerInFocus].m_nSexFrequency; if (CWorld::Players[CWorld::PlayerInFocus].m_nMoney >= 10 && playerSexFrequency > 250) { @@ -371,19 +302,23 @@ CCivilianPed::ProcessControl(void) CWorld::Players[CWorld::PlayerInFocus].m_nSexFrequency = Max(250, playerSexFrequency - 10); } - m_pMyVehicle->pDriver->m_fHealth = Min(125.0f, 1.0f + m_pMyVehicle->pDriver->m_fHealth); + m_pMyVehicle->pDriver->m_fHealth = Min(CWorld::Players[0].m_nMaxHealth + 25.0f, 1.0f + m_pMyVehicle->pDriver->m_fHealth); if (CWorld::Players[CWorld::PlayerInFocus].m_nSexFrequency == 250) CWorld::Players[CWorld::PlayerInFocus].m_nNextSexFrequencyUpdateTime = CTimer::GetTimeInMilliseconds() + 3000; } else { bWanderPathAfterExitingCar = true; CWorld::Players[CWorld::PlayerInFocus].m_pHooker = nil; + ClearLeader(); SetObjective(OBJECTIVE_LEAVE_CAR, m_pMyVehicle); + m_pMyVehicle->pDriver->Say(SOUND_PED_PLAYER_AFTERSEX); } } else { bWanderPathAfterExitingCar = true; CWorld::Players[CWorld::PlayerInFocus].m_pHooker = nil; - m_pMyVehicle->pDriver->m_fHealth = 125.0f; + m_pMyVehicle->pDriver->m_fHealth = CWorld::Players[0].m_nMaxHealth + 25.0f; + ClearLeader(); SetObjective(OBJECTIVE_LEAVE_CAR, m_pMyVehicle); + m_pMyVehicle->pDriver->Say(SOUND_PED_PLAYER_AFTERSEX); } } else { CWorld::Players[CWorld::PlayerInFocus].m_nNextSexFrequencyUpdateTime = CTimer::GetTimeInMilliseconds() + 3000; @@ -396,6 +331,7 @@ CCivilianPed::ProcessControl(void) } else { bWanderPathAfterExitingCar = true; CWorld::Players[CWorld::PlayerInFocus].m_pHooker = nil; + ClearLeader(); SetObjective(OBJECTIVE_LEAVE_CAR, m_pMyVehicle); } } @@ -416,6 +352,11 @@ CCivilianPed::ProcessControl(void) if (IsPedInControl()) CivilianAI(); + if (CharCreatedBy == RANDOM_CHAR) { + // TODO(Miami): EnterVacantNearbyCars(); + UseNearbyAttractors(); + } + if (CTimer::GetTimeInMilliseconds() > m_timerUnused) { m_stateUnused = 0; m_timerUnused = 0; @@ -424,3 +365,90 @@ CCivilianPed::ProcessControl(void) if (m_moved.Magnitude() > 0.0f) Avoid(); } + +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() && (!pEntity->IsStatic() || ((CObject*)pEntity)->bHasBeenDamaged)) + 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) + return; + if (HasAttractor()) + return; + if (m_nAttractorCycleState != gFrequencyOfAttractorAttempt) { + m_nAttractorCycleState++; + return; + } + m_nAttractorCycleState = 0; + if (!IsPedInControl()) + return; + if (m_nPedState == PED_FLEE_ENTITY) + return; + + float left = GetPosition().x - gDistanceToSeekAttractors; + float right = GetPosition().x + gDistanceToSeekAttractors; + float top = GetPosition().y - gDistanceToSeekAttractors; + float bottom = GetPosition().y + gDistanceToSeekAttractors; + int xstart = Max(0, CWorld::GetSectorIndexX(left)); + int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = Max(0, CWorld::GetSectorIndexY(top)); + int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + assert(xstart <= xend); + assert(ystart <= yend); + + float minDistance = SQR(gMaxDistanceToAttract); + C2dEffect* pClosestAttractor = nil; + CEntity* pAttractorEntity = nil; + + for (int y = ystart; y <= yend; y++) { + for (int x = xstart; x <= xend; x++) { + CSector* s = CWorld::GetSector(x, y); + FindNearbyAttractorsSectorList(s->m_lists[ENTITYLIST_BUILDINGS], minDistance, pClosestAttractor, pAttractorEntity); + FindNearbyAttractorsSectorList(s->m_lists[ENTITYLIST_OBJECTS], minDistance, pClosestAttractor, pAttractorEntity); + } + } + if (pClosestAttractor) + GetPedAttractorManager()->RegisterPedWithAttractor(this, pClosestAttractor, pAttractorEntity->GetMatrix()); +} + +bool CCivilianPed::IsAttractedTo(int8 type) +{ + switch (type) { + case ATTRACTOR_ATM: return true; + case ATTRACTOR_SEAT: return true; + case ATTRACTOR_STOP: return true; + case ATTRACTOR_PIZZA: return true; + case ATTRACTOR_SHELTER: return CWeather::Rain >= 0.2f; + case ATTRACTOR_ICECREAM: return false; + } + return false; +} diff --git a/src/peds/CivilianPed.h b/src/peds/CivilianPed.h index 8418a99f..27d458f7 100644 --- a/src/peds/CivilianPed.h +++ b/src/peds/CivilianPed.h @@ -4,12 +4,17 @@ class CCivilianPed : public CPed { + bool m_bAttractorUnk; + int32 m_nAttractorCycleState; public: CCivilianPed(ePedType, uint32); ~CCivilianPed(void) { } void CivilianAI(void); void ProcessControl(void); + void UseNearbyAttractors(void); + void FindNearbyAttractorsSectorList(CPtrList&, float&, C2dEffect*&, CEntity*&); + bool IsAttractedTo(int8); }; #ifndef PED_SKIN VALIDATE_SIZE(CCivilianPed, 0x53C); diff --git a/src/peds/CopPed.cpp b/src/peds/CopPed.cpp index f289697e..6c9eb276 100644 --- a/src/peds/CopPed.cpp +++ b/src/peds/CopPed.cpp @@ -16,14 +16,17 @@ #include "CarCtrl.h" #include "Renderer.h" #include "Camera.h" +#include "PedPlacement.h" +#include "Ropes.h" -CCopPed::CCopPed(eCopType copType) : CPed(PEDTYPE_COP) +CCopPed::CCopPed(eCopType copType, int32 modifier) : CPed(PEDTYPE_COP) { m_nCopType = copType; switch (copType) { case COP_STREET: SetModelIndex(MI_COP); - GiveWeapon(WEAPONTYPE_COLT45, 1000); + GiveWeapon(WEAPONTYPE_NIGHTSTICK, 1000, true); + GiveDelayedWeapon(WEAPONTYPE_COLT45, 1000); m_currentWeapon = WEAPONTYPE_UNARMED; m_fArmour = 0.0f; m_wepSkills = 208; /* TODO: what is this? seems unused */ @@ -31,17 +34,16 @@ CCopPed::CCopPed(eCopType copType) : CPed(PEDTYPE_COP) break; case COP_FBI: SetModelIndex(MI_FBI); - GiveWeapon(WEAPONTYPE_COLT45, 1000); - GiveWeapon(WEAPONTYPE_AK47, 1000); - SetCurrentWeapon(WEAPONTYPE_AK47); + GiveDelayedWeapon(WEAPONTYPE_MP5, 1000); + SetCurrentWeapon(WEAPONTYPE_MP5); m_fArmour = 100.0f; m_wepSkills = 176; /* TODO: what is this? seems unused */ m_wepAccuracy = 76; break; case COP_SWAT: + case COP_HELI_SWAT: SetModelIndex(MI_SWAT); - GiveWeapon(WEAPONTYPE_COLT45, 1000); - GiveWeapon(WEAPONTYPE_UZI, 1000); + GiveDelayedWeapon(WEAPONTYPE_UZI, 1000); SetCurrentWeapon(WEAPONTYPE_UZI); m_fArmour = 50.0f; m_wepSkills = 32; /* TODO: what is this? seems unused */ @@ -49,32 +51,50 @@ CCopPed::CCopPed(eCopType copType) : CPed(PEDTYPE_COP) break; case COP_ARMY: SetModelIndex(MI_ARMY); - GiveWeapon(WEAPONTYPE_COLT45, 1000); - GiveWeapon(WEAPONTYPE_M16, 1000); - GiveWeapon(WEAPONTYPE_GRENADE, 10); - SetCurrentWeapon(WEAPONTYPE_M16); + GiveDelayedWeapon(WEAPONTYPE_MP5, 1000); + SetCurrentWeapon(WEAPONTYPE_MP5); m_fArmour = 100.0f; m_wepSkills = 32; /* TODO: what is this? seems unused */ m_wepAccuracy = 84; break; - default: + case COP_MIAMIVICE: + switch (modifier) { + case 0: SetModelIndex(MI_VICE1); break; + case 1: SetModelIndex(MI_VICE2); break; + case 2: SetModelIndex(MI_VICE3); break; + case 3: SetModelIndex(MI_VICE4); break; + case 4: SetModelIndex(MI_VICE5); break; + case 5: SetModelIndex(MI_VICE6); break; + case 6: SetModelIndex(MI_VICE7); break; + case 7: SetModelIndex(MI_VICE8); break; + default: assert(0); break; + } + GiveDelayedWeapon(WEAPONTYPE_UZI, 1000); + SetCurrentWeapon(WEAPONTYPE_UZI); + m_fArmour = 100.0f; + m_wepSkills = 176; + m_wepAccuracy = 76; break; } m_bIsInPursuit = false; - field_1350 = 1; + field_5FE = 1; m_bIsDisabledCop = false; - m_fAbseilPos = 0.0f; m_attackTimer = 0; m_bBeatingSuspect = false; m_bStopAndShootDisabledZone = false; + field_601 = false; m_bZoneDisabled = false; - field_1364 = -1; + field_628 = -1; + m_nRoadblockNode = -1; // TODO(Miami): this will be nil + m_bThrowsSpikeTrap = false; + m_pRopeEntity = nil; + m_fAbseilPos = 0.0f; + m_nHassleTimer = 0; + field_61C = 0; + field_624 = 0; + if (m_pPointGunAt) + m_pPointGunAt->CleanUpOldReference((CEntity**)&m_pPointGunAt); m_pPointGunAt = nil; - - // VC also initializes in here, but as nil -#ifdef FIX_BUGS - m_nRoadblockNode = -1; -#endif } CCopPed::~CCopPed() @@ -82,6 +102,7 @@ CCopPed::~CCopPed() ClearPursuit(); } +// --MIAMI: Done // Parameter should always be CPlayerPed, but it seems they considered making civilians arrestable at some point void CCopPed::SetArrestPlayer(CPed *player) @@ -89,17 +110,9 @@ CCopPed::SetArrestPlayer(CPed *player) if (!IsPedInControl() || !player) return; - switch (m_nCopType) { - case COP_FBI: - Say(SOUND_PED_ARREST_FBI); - break; - case COP_SWAT: - Say(SOUND_PED_ARREST_SWAT); - break; - default: - Say(SOUND_PED_ARREST_COP); - break; - } + player->Say(SOUND_PED_PLAYER_REACTTOCOP); + Say(SOUND_PED_ARREST_COP); + if (player->EnteringCar()) { if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer) return; @@ -114,14 +127,14 @@ CCopPed::SetArrestPlayer(CPed *player) } else if (player->m_nPedState != PED_DIE && player->m_nPedState != PED_DEAD && player->m_nPedState != PED_ARRESTED) { player->m_nLastPedState = player->m_nPedState; - player->m_nPedState = PED_ARRESTED; + player->SetPedState(PED_ARRESTED); FindPlayerPed()->m_bCanBeDamaged = false; ((CPlayerPed*)player)->m_pArrestingCop = this; this->RegisterReference((CEntity**) &((CPlayerPed*)player)->m_pArrestingCop); } - m_nPedState = PED_ARREST_PLAYER; + SetPedState(PED_ARREST_PLAYER); SetObjective(OBJECTIVE_NONE); m_prevObjective = OBJECTIVE_NONE; bIsPointingGunAt = false; @@ -134,10 +147,11 @@ CCopPed::SetArrestPlayer(CPed *player) player->m_pMyVehicle->bIsHandbrakeOn = true; player->m_pMyVehicle->SetStatus(STATUS_PLAYER_DISABLED); } - if (GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED) + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED || GetWeapon()->m_eWeaponType == WEAPONTYPE_BRASSKNUCKLE) SetCurrentWeapon(WEAPONTYPE_COLT45); } +// --MIAMI: Done void CCopPed::ClearPursuit(void) { @@ -176,6 +190,7 @@ CCopPed::ClearPursuit(void) bNotAllowedToDuck = false; bKindaStayInSamePlace = false; m_bStopAndShootDisabledZone = false; + field_601 = false; m_bZoneDisabled = false; ClearObjective(); if (IsPedInControl()) { @@ -193,10 +208,14 @@ CCopPed::ClearPursuit(void) } } +// --MIAMI: Done // TODO: I don't know why they needed that parameter. void CCopPed::SetPursuit(bool ignoreCopLimit) { + if (CTimer::GetTimeInMilliseconds() < field_61C) + return; + CWanted *wanted = FindPlayerPed()->m_pWanted; if (m_bIsInPursuit || !IsPedInControl()) return; @@ -222,6 +241,7 @@ CCopPed::SetPursuit(bool ignoreCopLimit) } } +// --MIAMI: Done void CCopPed::ArrestPlayer(void) { @@ -244,7 +264,7 @@ CCopPed::ArrestPlayer(void) CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_ARREST_GUN, 4.0f); CVector suspMidPos; - suspect->m_pedIK.GetComponentPosition((RwV3d*)suspMidPos, PED_MID); + suspect->m_pedIK.GetComponentPosition(*(RwV3d *)&suspMidPos, PED_MID); m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(suspMidPos.x, suspMidPos.y, GetPosition().x, GetPosition().y); @@ -287,6 +307,7 @@ CCopPed::ScanForCrimes(void) } } +// --MIAMI: Done void CCopPed::CopAI(void) { @@ -304,11 +325,6 @@ CCopPed::CopAI(void) if (bHitSomethingLastFrame) { m_bZoneDisabled = true; m_bIsDisabledCop = true; -#ifdef FIX_BUGS - m_nRoadblockNode = -1; -#else - m_nRoadblockNode = 0; -#endif bKindaStayInSamePlace = true; bIsRunning = false; bNotAllowedToDuck = false; @@ -335,6 +351,27 @@ CCopPed::CopAI(void) } if (wantedLevel > 0) { if (!m_bIsDisabledCop) { + // Turn and shoot the player's vehicle, if possible + if (!m_bIsInPursuit && !GetWeapon()->IsTypeMelee() && FindPlayerVehicle() && m_fDistanceToTarget < CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_fRange) { + if (FindPlayerVehicle()->m_vecMoveSpeed.Magnitude2D() > 0.1f) { + CVector2D distToVeh = GetPosition() - FindPlayerVehicle()->GetPosition(); + distToVeh.Normalise(); + CVector2D vehSpeed = FindPlayerVehicle()->m_vecMoveSpeed; + vehSpeed.Normalise(); + + if (DotProduct2D(distToVeh, vehSpeed) > 0.8f) { + SetLookFlag(playerOrHisVeh, true); + SetMoveState(PEDMOVE_STILL); + if (TurnBody()) { + SetAttack(FindPlayerVehicle()); + SetShootTimer(CGeneral::GetRandomNumberInRange(500.0f, 1000.0f)); + SetAttackTimer(CGeneral::GetRandomNumberInRange(200.0f, 300.0f)); + } + } else if (m_nPedState == PED_ATTACK) + RestorePreviousState(); + } + } + if (!m_bIsInPursuit || wanted->m_CurrentCops > wanted->m_MaxCops) { CCopPed *copFarthestToTarget = nil; float copFarthestToTargetDist = m_fDistanceToTarget; @@ -377,11 +414,14 @@ CCopPed::CopAI(void) if (wantedLevel > 1 && GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED) SetCurrentWeapon(WEAPONTYPE_COLT45); - else if (wantedLevel == 1 && GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && !FindPlayerPed()->m_pCurrentPhysSurface) { + else if (wantedLevel == 1 && GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED && !FindPlayerPed()->m_pCurrentPhysSurface) { // i.e. if player is on top of car, cop will still use colt45. - SetCurrentWeapon(WEAPONTYPE_UNARMED); + SetCurrentWeapon(GetWeaponSlot(WEAPONTYPE_NIGHTSTICK) >= 0 ? WEAPONTYPE_NIGHTSTICK : WEAPONTYPE_UNARMED); } + if (m_bBeatingSuspect && GetWeapon()->m_eWeaponType == WEAPONTYPE_NIGHTSTICK) + Say(SOUND_PED_PULLOUTWEAPON); + if (FindPlayerVehicle()) { if (m_bBeatingSuspect) { --wanted->m_CopsBeatingSuspect; @@ -392,18 +432,18 @@ CCopPed::CopAI(void) } return; } - float weaponRange = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_fRange; + SetCurrentWeapon(WEAPONTYPE_COLT45); + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + float weaponRange = weaponInfo->m_fRange; SetLookFlag(playerOrHisVeh, true); TurnBody(); - SetCurrentWeapon(WEAPONTYPE_COLT45); - if (!bIsDucking) { + if (!bIsDucking || bCrouchWhenShooting && GetCrouchFireAnim(weaponInfo)) { if (m_attackTimer >= CTimer::GetTimeInMilliseconds()) { if (m_nPedState != PED_ATTACK && m_nPedState != PED_FIGHT && !m_bZoneDisabled) { CVector targetDist = playerOrHisVeh->GetPosition() - GetPosition(); if (m_fDistanceToTarget > 30.0f) { - CAnimBlendAssociation* crouchShootAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RBLOCK_CSHOOT); - if (crouchShootAssoc) - crouchShootAssoc->blendDelta = -1000.0f; + if (bIsDucking) + ClearDuck(); // Target is coming onto us if (DotProduct(playerOrHisVeh->m_vecMoveSpeed, targetDist) > 0.0f) { @@ -421,41 +461,23 @@ CCopPed::CopAI(void) bNotAllowedToDuck = false; bDuckAndCover = false; } else { - // VC checks for != nil compared to buggy behaviour of III. I check for != -1 here. -#ifdef VC_PED_PORTS + // TODO(Miami): Roadblock system is still III float dotProd; if (m_nRoadblockNode != -1) { - CTreadable *roadBlockRoad = ThePaths.m_mapObjects[CRoadBlocks::RoadBlockObjects[m_nRoadblockNode]]; - dotProd = DotProduct2D(playerOrHisVeh->GetPosition() - roadBlockRoad->GetPosition(), GetPosition() - roadBlockRoad->GetPosition()); + CPathNode *roadBlockNode = &ThePaths.m_pathNodes[CRoadBlocks::RoadBlockNodes[m_nRoadblockNode]]; + dotProd = DotProduct2D(playerOrHisVeh->GetPosition() - roadBlockNode->GetPosition(), GetPosition() - roadBlockNode->GetPosition()); } else dotProd = -1.0f; if(dotProd >= 0.0f) { -#else - -#ifndef FIX_BUGS - float copRoadDotProd, targetRoadDotProd; -#else - float copRoadDotProd = 1.0f, targetRoadDotProd = 1.0f; - if (m_nRoadblockNode != -1) -#endif - { - CTreadable* roadBlockRoad = ThePaths.m_mapObjects[CRoadBlocks::RoadBlockObjects[m_nRoadblockNode]]; - CVector2D roadFwd = roadBlockRoad->GetForward(); - copRoadDotProd = DotProduct2D(GetPosition() - roadBlockRoad->GetPosition(), roadFwd); - targetRoadDotProd = DotProduct2D(playerOrHisVeh->GetPosition() - roadBlockRoad->GetPosition(), roadFwd); - } - // Roadblock may be towards road's fwd or opposite, so check both - if ((copRoadDotProd >= 0.0f || targetRoadDotProd >= 0.0f) - && (copRoadDotProd <= 0.0f || targetRoadDotProd <= 0.0f)) { -#endif bIsPointingGunAt = true; } else { + if (bIsDucking) + ClearDuck(); m_bIsDisabledCop = false; bKindaStayInSamePlace = false; bNotAllowedToDuck = false; bCrouchWhenShooting = false; - bIsDucking = false; bDuckAndCover = false; SetPursuit(false); } @@ -463,7 +485,6 @@ CCopPed::CopAI(void) } } else { if (m_fDistanceToTarget < weaponRange) { - CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); CVector gunPos = weaponInfo->m_vecFireOffset; TransformToNode(gunPos, PED_HANDR); @@ -472,6 +493,9 @@ CCopPed::CopAI(void) if (!CWorld::ProcessLineOfSight(gunPos, playerOrHisVeh->GetPosition(), foundCol, foundEnt, false, true, false, false, true, false, false) || foundEnt && foundEnt == playerOrHisVeh) { + + if (m_pPointGunAt) + m_pPointGunAt->CleanUpOldReference((CEntity**) &m_pPointGunAt); m_pPointGunAt = playerOrHisVeh; if (playerOrHisVeh) playerOrHisVeh->RegisterReference((CEntity**) &m_pPointGunAt); @@ -509,10 +533,8 @@ CCopPed::CopAI(void) ClearObjective(); SetWanderPath(CGeneral::GetRandomNumber() & 7); } - } -#ifdef VC_PED_PORTS - else { - if (m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT && CharCreatedBy == RANDOM_CHAR) { + } else { + if (m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT && m_objective != OBJECTIVE_HASSLE_CHAR && CharCreatedBy == RANDOM_CHAR) { for (int i = 0; i < m_numNearPeds; i++) { CPed *nearPed = m_nearPeds[i]; if (nearPed->CharCreatedBy == RANDOM_CHAR) { @@ -532,12 +554,30 @@ CCopPed::CopAI(void) nearPed->bBeingChasedByPolice = true; return; } + } else { + if (nearPed->m_nPedType != PEDTYPE_COP && !nearPed->IsPlayer() + && nearPed->IsPedInControl() && m_nHassleTimer < CTimer::GetTimeInMilliseconds()) { + + if (nearPed->m_objective == OBJECTIVE_NONE && nearPed->m_nPedState == PED_WANDER_PATH + && !nearPed->m_pLookTarget && nearPed->m_lookTimer < CTimer::GetTimeInMilliseconds()) { + + if ((GetPosition() - nearPed->GetPosition()).MagnitudeSqr() < sq(5.0f)) { + + if (CWorld::GetIsLineOfSightClear(GetPosition(), nearPed->GetPosition(), + true, false, false, false, false, false, false)) { + Say(SOUND_PED_COP_REACTION); + SetObjective(OBJECTIVE_HASSLE_CHAR, nearPed); + nearPed->SetObjective(OBJECTIVE_WAIT_ON_FOOT_FOR_COP, this); + m_nHassleTimer = CTimer::GetTimeInMilliseconds() + 100000; + } + } + } + } } } } } } -#endif } } } else { @@ -548,21 +588,35 @@ CCopPed::CopAI(void) bKindaStayInSamePlace = false; bNotAllowedToDuck = false; bCrouchWhenShooting = false; - bIsDucking = false; bDuckAndCover = false; + if (bIsDucking) + ClearDuck(); if (m_pMyVehicle) SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, m_pMyVehicle); } } } +// --MIAMI: Done except commented things void CCopPed::ProcessControl(void) { - if (m_nZoneLevel > LEVEL_GENERIC && m_nZoneLevel != CCollision::ms_collisionInMemory) - return; + if (m_nCopType == COP_HELI_SWAT) + ProcessHeliSwat(); CPed::ProcessControl(); + + if (m_bThrowsSpikeTrap) { + // TODO(Miami) + /* + if (CGame::currArea != AREA_MALL) + ProcessStingerCop(); + */ + return; + } + + // TODO(Miami): CStinger::Process + if (bWasPostponed) return; @@ -578,7 +632,7 @@ CCopPed::ProcessControl(void) ArrestPlayer(); return; } - GetWeapon()->Update(m_audioEntityId); + GetWeapon()->Update(m_audioEntityId, nil); if (m_moved.Magnitude() > 0.0f) Avoid(); @@ -594,21 +648,33 @@ CCopPed::ProcessControl(void) if (IsPedInControl()) SetIdle(); } + if (m_bIsInPursuit) { if (player->m_nPedState != PED_ARRESTED && !player->DyingOrDead()) { - switch (m_nCopType) { - case COP_FBI: - Say(SOUND_PED_PURSUIT_FBI); - break; - case COP_SWAT: - Say(SOUND_PED_PURSUIT_SWAT); - break; - case COP_ARMY: - Say(SOUND_PED_PURSUIT_ARMY); - break; - default: - Say(SOUND_PED_PURSUIT_COP); - break; + if (player->m_pWanted->m_CurrentCops == 1) { + Say(SOUND_PED_COP_ALONE); + } else { + int numCopsNear = 0; + for (int i = 0; i < player->m_numNearPeds; ++i) { + CPed *nearPed = player->m_nearPeds[i]; + if (nearPed->m_nPedType == PEDTYPE_COP && nearPed->m_nPedState != PED_DEAD) + ++numCopsNear; + } + if (numCopsNear <= 3) { + Say(SOUND_PED_COP_LITTLECOPSAROUND); + if (!player->bInVehicle) { + CVector distToPlayer = player->GetPosition() - GetPosition(); + if (distToPlayer.MagnitudeSqr() < sq(20.0f)) { + player->Say(SOUND_PED_PLAYER_FARFROMCOPS); + if (player->m_nPedState != PED_ATTACK && player->m_nPedState != PED_AIM_GUN) { + player->SetLookFlag(this, false); + player->SetLookTimer(1000); + } + } + } + } else if ((CGeneral::GetRandomNumber() % 16) == 1) { + Say(SOUND_PED_COP_MANYCOPSAROUND); + } } } } @@ -658,23 +724,10 @@ CCopPed::ProcessControl(void) RestorePreviousObjective(); } else { if (player->m_pMyVehicle && player->m_pMyVehicle->m_nNumGettingIn != 0) { - // This is 1.3f when arresting in car without seeking first (in above) -#if defined(VC_PED_PORTS) || defined(FIX_BUGS) m_distanceToCountSeekDone = 1.3f; -#else - m_distanceToCountSeekDone = 2.0f; -#endif } - if (bDuckAndCover) { -#if !defined(GTA3_1_1_PATCH) && !defined(VC_PED_PORTS) - if (!bNotAllowedToDuck && Seek()) { - SetMoveState(PEDMOVE_STILL); - SetMoveAnim(); - SetPointGunAt(m_pedInObjective); - } -#endif - } else if (Seek()) { + if (!bDuckAndCover && Seek()) { CVehicle *playerVeh = FindPlayerVehicle(); if (!playerVeh && player && player->EnteringCar()) { SetArrestPlayer(player); @@ -705,35 +758,100 @@ CCopPed::ProcessControl(void) } } } - if (!m_bStopAndShootDisabledZone) - return; - bool dontShoot = false; - if (GetIsOnScreen() && CRenderer::IsEntityCullZoneVisible(this)) { - if (((CTimer::GetFrameCounter() + m_randomSeed) & 0x1F) == 17) { - CEntity *foundBuilding = nil; - CColPoint foundCol; - CVector lookPos = GetPosition() + CVector(0.0f, 0.0f, 0.7f); - CVector camPos = TheCamera.GetGameCamPosition(); - CWorld::ProcessLineOfSight(camPos, lookPos, foundCol, foundBuilding, - true, false, false, false, false, false, false); - - // He's at least 15.0 far, in disabled zone, collided into somewhere (that's why m_bStopAndShootDisabledZone set), - // and now has building on front of him. He's stupid, we don't need him. - if (foundBuilding) { - FlagToDestroyWhenNextProcessed(); - dontShoot = true; + if (m_pPointGunAt) + Say(SOUND_PED_COP_UNK_129); + + if (m_bStopAndShootDisabledZone) { + bool dontShoot = false; + if (GetIsOnScreen()) { + if (((CTimer::GetFrameCounter() + m_randomSeed) & 0x1F) == 17) { + CEntity* foundBuilding = nil; + CColPoint foundCol; + CVector lookPos = GetPosition() + CVector(0.0f, 0.0f, 0.7f); + CVector camPos = TheCamera.GetGameCamPosition(); + CWorld::ProcessLineOfSight(camPos, lookPos, foundCol, foundBuilding, + true, false, false, false, false, false, false); + + // He's at least 15.0 far, in disabled zone, collided into somewhere (that's why m_bStopAndShootDisabledZone set), + // and now has building on front of him. He's stupid, we don't need him. + if (foundBuilding) { + FlagToDestroyWhenNextProcessed(); + dontShoot = true; + } } + } else { + FlagToDestroyWhenNextProcessed(); + dontShoot = true; } - } else { - FlagToDestroyWhenNextProcessed(); - dontShoot = true; - } - if (!dontShoot) { - bStopAndShoot = true; - bKindaStayInSamePlace = true; - bIsPointingGunAt = true; - SetAttack(m_pedInObjective); + if (!dontShoot) { + bStopAndShoot = true; + bKindaStayInSamePlace = true; + bIsPointingGunAt = true; + SetAttack(m_pedInObjective); + } } + + if (field_624 >= 2 && m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT) { + CVector centre = GetPosition() + CVector(0.f, 0.f, 0.65f); + if (CWorld::TestSphereAgainstWorld(centre, 0.35f, this, true, false, false, false, false, false)) { + field_624 = 0; + m_bStopAndShootDisabledZone = true; + ClearPursuit(); + SetObjective(OBJECTIVE_NONE); + SetWanderPath(CGeneral::GetRandomNumberInRange(0,8)); + field_61C = CTimer::GetTimeInMilliseconds() + 30000; + } else { + field_624 = 0; + if (GetWeapon()->IsTypeMelee()) { + // TODO(Miami): enum + for (int i = 3; i < 7; i++) { + if (HasWeaponSlot(i)) { + SetCurrentWeapon(i); + break; + } + } + SetMoveState(PEDMOVE_STILL); + bStopAndShoot = true; + } + } + } else if (CTimer::GetTimeStep() / 100.f <= m_fDistanceTravelled) + field_624 = 0; } + +// --MIAMI: Done +void +CCopPed::ProcessHeliSwat(void) +{ + CVector bestPos = GetPosition(); + SetPedState(PED_ABSEIL); + CPedPlacement::FindZCoorForPed(&bestPos); + if (GetPosition().z - 2.0f >= bestPos.z && m_pRopeEntity) { + m_fAbseilPos += 0.003f * CTimer::GetTimeStep(); + m_vecMoveSpeed.z = -0.03f; + m_vecTurnSpeed = CVector(0.f, 0.f, (m_randomSeed % 32) * 0.003f - 0.05f); + CPhysical::ApplyTurnSpeed(); + GetMatrix().Reorthogonalise(); + CVector posOnRope; + + if (CRopes::FindCoorsAlongRope(m_nRopeID, m_fAbseilPos, &posOnRope)) { + SetPosition(posOnRope); + } else { + bUsesCollision = true; + m_vecMoveSpeed = CVector(0.f, 0.f, 0.f); + SetPedState(PED_IDLE); + m_nCopType = COP_SWAT; + SetInTheAir(); + bKnockedUpIntoAir = true; + } + Say(SOUND_PED_COP_HELIPILOTPHRASE); + } else { + bUsesCollision = true; + m_vecMoveSpeed = CVector(0.f, 0.f, 0.f); + SetPedState(PED_IDLE); + m_nCopType = COP_SWAT; + SetInTheAir(); + bKnockedUpIntoAir = true; + } +}
\ No newline at end of file diff --git a/src/peds/CopPed.h b/src/peds/CopPed.h index 5346d9a1..edec145e 100644 --- a/src/peds/CopPed.h +++ b/src/peds/CopPed.h @@ -6,7 +6,9 @@ enum eCopType COP_STREET = 0, COP_FBI = 1, COP_SWAT = 2, - COP_ARMY = 3, + COP_HELI_SWAT = 3, + COP_ARMY = 4, + COP_MIAMIVICE = 5 }; class CCopPed : public CPed @@ -16,15 +18,22 @@ public: float m_fDistanceToTarget; bool m_bIsInPursuit; bool m_bIsDisabledCop; - int8 field_1350; + int8 field_5FE; bool m_bBeatingSuspect; bool m_bStopAndShootDisabledZone; + bool field_601; // set when police dragging player from car bool m_bZoneDisabled; - float m_fAbseilPos; // VC leftover, unused + float m_fAbseilPos; eCopType m_nCopType; - int8 field_1364; + bool m_bThrowsSpikeTrap; + CEntity *m_pRopeEntity; // CHeli or 1 + uintptr m_nRopeID; + uint32 m_nHassleTimer; + uint32 field_61C; + int32 field_624; + int8 field_628; - CCopPed(eCopType); + CCopPed(eCopType, int32 modifier = 0); ~CCopPed(); void ClearPursuit(void); @@ -34,6 +43,7 @@ public: void ArrestPlayer(void); void ScanForCrimes(void); void CopAI(void); + void ProcessHeliSwat(void); }; #ifndef PED_SKIN diff --git a/src/peds/DummyPed.h b/src/peds/DummyPed.h index ea617c76..cace4ead 100644 --- a/src/peds/DummyPed.h +++ b/src/peds/DummyPed.h @@ -8,5 +8,3 @@ class CDummyPed : CDummy int32 pedType; int32 unknown; }; - -VALIDATE_SIZE(CDummyPed, 0x70); diff --git a/src/peds/EmergencyPed.cpp b/src/peds/EmergencyPed.cpp index 8d6999c3..a33e31f9 100644 --- a/src/peds/EmergencyPed.cpp +++ b/src/peds/EmergencyPed.cpp @@ -44,15 +44,12 @@ CEmergencyPed::InRange(CPed *victim) void CEmergencyPed::ProcessControl(void) { - if (m_nZoneLevel > LEVEL_GENERIC && m_nZoneLevel != CCollision::ms_collisionInMemory) - return; - CPed::ProcessControl(); if (bWasPostponed) return; if(!DyingOrDead()) { - GetWeapon()->Update(m_audioEntityId); + GetWeapon()->Update(m_audioEntityId, nil); if (IsPedInControl() && m_moved.Magnitude() > 0.0f) Avoid(); @@ -234,8 +231,8 @@ CEmergencyPed::MedicAI(void) if (nearestAccident) { m_pRevivedPed = nearestAccident->m_pVictim; m_pRevivedPed->RegisterReference((CEntity**)&m_pRevivedPed); - m_pRevivedPed->m_pedIK.GetComponentPosition((RwV3d*)&midPos, PED_MID); - m_pRevivedPed->m_pedIK.GetComponentPosition((RwV3d*)&headPos, PED_HEAD); + m_pRevivedPed->m_pedIK.GetComponentPosition(*(RwV3d *)&midPos, PED_MID); + m_pRevivedPed->m_pedIK.GetComponentPosition(*(RwV3d *)&headPos, PED_HEAD); SetSeek((headPos + midPos) * 0.5f, 1.0f); SetObjective(OBJECTIVE_NONE); bIsRunning = true; @@ -274,8 +271,8 @@ CEmergencyPed::MedicAI(void) m_nEmergencyPedState = EMERGENCY_PED_STOP; break; } - m_pRevivedPed->m_pedIK.GetComponentPosition((RwV3d*)&midPos, PED_MID); - m_pRevivedPed->m_pedIK.GetComponentPosition((RwV3d*)&headPos, PED_HEAD); + m_pRevivedPed->m_pedIK.GetComponentPosition(*(RwV3d *)&midPos, PED_MID); + m_pRevivedPed->m_pedIK.GetComponentPosition(*(RwV3d *)&headPos, PED_HEAD); SetSeek((headPos + midPos) * 0.5f, nearestAccident->m_nMedicsPerformingCPR * 0.5f + 1.0f); SetObjective(OBJECTIVE_NONE); bIsRunning = true; @@ -311,13 +308,13 @@ CEmergencyPed::MedicAI(void) m_nLastPedState = PED_CPR; SetLookFlag(m_pRevivedPed, 0); SetLookTimer(500); - Say(SOUND_PED_HEALING); + //Say(SOUND_PED_HEALING); if (m_pAttendedAccident->m_nMedicsPerformingCPR) { SetIdle(); m_nEmergencyPedState = EMERGENCY_PED_STAND_STILL; } else { m_nEmergencyPedState = EMERGENCY_PED_FACE_TO_PATIENT; - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CPR, 4.0f); + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_MEDIC, ANIM_CPR, 4.0f); bIsDucking = true; } SetLookTimer(2000); @@ -329,8 +326,8 @@ CEmergencyPed::MedicAI(void) if (!m_pRevivedPed || m_pRevivedPed->m_fHealth > 0.0f) m_nEmergencyPedState = EMERGENCY_PED_DETERMINE_NEXT_STATE; else { - m_pRevivedPed->m_pedIK.GetComponentPosition((RwV3d*)&midPos, PED_MID); - m_pRevivedPed->m_pedIK.GetComponentPosition((RwV3d*)&headPos, PED_HEAD); + m_pRevivedPed->m_pedIK.GetComponentPosition(*(RwV3d *)&midPos, PED_MID); + m_pRevivedPed->m_pedIK.GetComponentPosition(*(RwV3d *)&headPos, PED_HEAD); midPos = (headPos + midPos) * 0.5f; m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( midPos.x, midPos.y, @@ -351,8 +348,8 @@ CEmergencyPed::MedicAI(void) m_nEmergencyPedState = EMERGENCY_PED_DETERMINE_NEXT_STATE; break; } - m_pRevivedPed->m_pedIK.GetComponentPosition((RwV3d*)&midPos, PED_MID); - m_pRevivedPed->m_pedIK.GetComponentPosition((RwV3d*)&headPos, PED_HEAD); + m_pRevivedPed->m_pedIK.GetComponentPosition(*(RwV3d *)&midPos, PED_MID); + m_pRevivedPed->m_pedIK.GetComponentPosition(*(RwV3d *)&headPos, PED_HEAD); midPos = (headPos + midPos) * 0.5f; m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( midPos.x, midPos.y, diff --git a/src/peds/Gangs.cpp b/src/peds/Gangs.cpp index 8859e61e..2d6d1137 100644 --- a/src/peds/Gangs.cpp +++ b/src/peds/Gangs.cpp @@ -2,12 +2,17 @@ #include "ModelIndices.h" #include "Gangs.h" +#include "General.h" +#include "Streaming.h" #include "Weapon.h" CGangInfo CGangs::Gang[NUM_GANGS]; +bool CGangs::GangAttackWithCops[NUM_GANGS]; CGangInfo::CGangInfo() : - m_nVehicleMI(MI_BUS), + m_nVehicleMI(-1), + m_nPedModel1MI(-1), + m_nPedModel2MI(-1), m_nPedModelOverride(-1), m_Weapon1(WEAPONTYPE_UNARMED), m_Weapon2(WEAPONTYPE_UNARMED) @@ -15,21 +20,63 @@ CGangInfo::CGangInfo() : void CGangs::Initialise(void) { - Gang[GANG_MAFIA].m_nVehicleMI = MI_MAFIA; - Gang[GANG_TRIAD].m_nVehicleMI = MI_BELLYUP; - Gang[GANG_DIABLOS].m_nVehicleMI = MI_DIABLOS; - Gang[GANG_YAKUZA].m_nVehicleMI = MI_YAKUZA; - Gang[GANG_YARDIE].m_nVehicleMI = MI_YARDIE; - Gang[GANG_COLUMB].m_nVehicleMI = MI_COLUMB; - Gang[GANG_HOODS].m_nVehicleMI = MI_HOODS; - Gang[GANG_7].m_nVehicleMI = -1; - Gang[GANG_8].m_nVehicleMI = -1; + SetGangPedModels(GANG_CUBAN, MI_CBA, MI_CBB); + SetGangPedModels(GANG_HAITIAN, MI_HNA, MI_HNB); + SetGangPedModels(GANG_STREET, MI_SGA, MI_SGB); + SetGangPedModels(GANG_DIAZ, MI_CLA, MI_CLB); + SetGangPedModels(GANG_SECURITY, MI_GDA, MI_GDB); + SetGangPedModels(GANG_BIKER, MI_BKA, MI_BKB); + SetGangPedModels(GANG_PLAYER, MI_PGA, MI_PGB); + SetGangPedModels(GANG_GOLFER, MI_WFOGO, MI_WMOGO); + SetGangVehicleModel(GANG_CUBAN, MI_CUBAN); + SetGangVehicleModel(GANG_HAITIAN, MI_VOODOO); + SetGangVehicleModel(GANG_STREET, MI_GANGBUR); + SetGangVehicleModel(GANG_DIAZ, -1); + SetGangVehicleModel(GANG_SECURITY, -1); + SetGangVehicleModel(GANG_BIKER, MI_ANGEL); + SetGangVehicleModel(GANG_PLAYER, -1); + SetGangVehicleModel(GANG_GOLFER, MI_CADDY); + SetGangWeapons(GANG_GOLFER, WEAPONTYPE_GOLFCLUB, WEAPONTYPE_GOLFCLUB); #ifdef FIX_BUGS for (int i = 0; i < NUM_GANGS; i++) - Gang[i].m_nPedModelOverride = -1; + SetGangPedModelOverride(i, -1); #endif } +bool CGangs::HaveGangModelsLoaded(int16 gang) +{ + CGangInfo* pGangInfo = GetGangInfo(gang); + return CStreaming::HasModelLoaded(pGangInfo->m_nPedModel1MI) && CStreaming::HasModelLoaded(pGangInfo->m_nPedModel2MI); +} + +void CGangs::SetGangPedModels(int16 gang, int32 mi1, int32 mi2) +{ + GetGangInfo(gang)->m_nPedModel1MI = mi1; + GetGangInfo(gang)->m_nPedModel2MI = mi2; +} + +void CGangs::SetWillAttackPlayerWithCops(ePedType type, bool will) +{ + if (type >= PEDTYPE_GANG1 && type <= PEDTYPE_GANG9) + GangAttackWithCops[type - PEDTYPE_GANG1] = will; +} + +bool CGangs::GetWillAttackPlayerWithCops(ePedType type) +{ + if (type >= PEDTYPE_GANG1 && type <= PEDTYPE_GANG9) + return GangAttackWithCops[type - PEDTYPE_GANG1]; + return false; +} + +int32 CGangs::ChooseGangPedModel(int16 gang) +{ + CGangInfo* pGangInfo = GetGangInfo(gang); + if (pGangInfo->m_nPedModelOverride != -1 || CGeneral::GetRandomTrueFalse()) + return pGangInfo->m_nPedModel1MI; + else + return pGangInfo->m_nPedModel2MI; +} + void CGangs::SetGangVehicleModel(int16 gang, int32 model) { GetGangInfo(gang)->m_nVehicleMI = model; diff --git a/src/peds/Gangs.h b/src/peds/Gangs.h index c8ea2916..c6381343 100644 --- a/src/peds/Gangs.h +++ b/src/peds/Gangs.h @@ -1,8 +1,12 @@ #pragma once +#include "PedType.h" + struct CGangInfo { int32 m_nVehicleMI; + int32 m_nPedModel1MI; + int32 m_nPedModel2MI; int8 m_nPedModelOverride; int32 m_Weapon1; int32 m_Weapon2; @@ -13,15 +17,15 @@ struct CGangInfo VALIDATE_SIZE(CGangInfo, 0x10); enum { - GANG_MAFIA = 0, - GANG_TRIAD, - GANG_DIABLOS, - GANG_YAKUZA, - GANG_YARDIE, - GANG_COLUMB, - GANG_HOODS, - GANG_7, - GANG_8, + GANG_CUBAN = 0, + GANG_HAITIAN, + GANG_STREET, + GANG_DIAZ, + GANG_SECURITY, + GANG_BIKER, + GANG_PLAYER, + GANG_GOLFER, + GANG_9, NUM_GANGS }; @@ -36,9 +40,18 @@ public: static void SaveAllGangData(uint8 *, uint32 *); static void LoadAllGangData(uint8 *, uint32); + static void SetGangPedModels(int16, int32, int32); + static void SetWillAttackPlayerWithCops(ePedType type, bool will); + static bool GetWillAttackPlayerWithCops(ePedType type); + static int32 ChooseGangPedModel(int16); + + static bool HaveGangModelsLoaded(int16 gang); + static int32 GetGangPedModel1(int16 gang) { return Gang[gang].m_nPedModel1MI; } + static int32 GetGangPedModel2(int16 gang) { return Gang[gang].m_nPedModel2MI; } static int32 GetGangVehicleModel(int16 gang) { return Gang[gang].m_nVehicleMI; } static CGangInfo *GetGangInfo(int16 gang) { return &Gang[gang]; } private: static CGangInfo Gang[NUM_GANGS]; + static bool GangAttackWithCops[NUM_GANGS]; }; diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index f52b373e..26c91abb 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -58,6 +58,13 @@ #include "ParticleObject.h" #include "Floater.h" #include "Range2D.h" +#include "Streaming.h" +#include "PedAttractor.h" +#include "Debug.h" +#include "GameLogic.h" +#include "Bike.h" +#include "WindModifiers.h" +#include "CutsceneShadow.h" #define CAN_SEE_ENTITY_ANGLE_THRESHOLD DEGTORAD(60.0f) @@ -66,36 +73,47 @@ uint16 gnNumTempPedList; static CColPoint aTempPedColPts[MAX_COLLISION_POINTS]; +// TODO(Miami) +#define AUDIO_NOT_READY + uint16 nPlayerInComboMove; RpClump *flyingClumpTemp; -// This is beta fistfite.dat array. Not used anymore since they're being fetched from fistfite.dat. -FightMove tFightMoves[NUM_FIGHTMOVES] = { - {NUM_ANIMS, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_PUNCH_R, 0.2f, 8.0f / 30.0f, 0.0f, 0.3f, HITLEVEL_HIGH, 1, 0}, - {ANIM_FIGHT_IDLE, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_FIGHT_SH_F, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_FIGHT_KNEE, 4.0f / 30.0f, 0.2f, 0.0f, 0.6f, HITLEVEL_LOW, 2, 0}, - {ANIM_FIGHT_HEAD, 4.0f / 30.0f, 0.2f, 0.0f, 0.7f, HITLEVEL_HIGH, 3, 0}, - {ANIM_FIGHT_PUNCH, 4.0f / 30.0f, 7.0f / 30.0f, 10.0f / 30.0f, 0.4f, HITLEVEL_HIGH, 1, 0}, - {ANIM_FIGHT_LHOOK, 8.0f / 30.0f, 10.0f / 30.0f, 0.0f, 0.4f, HITLEVEL_HIGH, 3, 0}, - {ANIM_FIGHT_KICK, 8.0f / 30.0f, 10.0f / 30.0f, 0.0f, 0.5, HITLEVEL_MEDIUM, 2, 0}, - {ANIM_FIGHT_LONGKICK, 8.0f / 30.0f, 10.0f / 30.0f, 0.0f, 0.5, HITLEVEL_MEDIUM, 4, 0}, - {ANIM_FIGHT_ROUNDHOUSE, 8.0f / 30.0f, 10.0f / 30.0f, 0.0f, 0.6f, HITLEVEL_MEDIUM, 4, 0}, - {ANIM_FIGHT_BODYBLOW, 5.0f / 30.0f, 7.0f / 30.0f, 0.0f, 0.35f, HITLEVEL_LOW, 2, 0}, - {ANIM_KICK_FLOOR, 10.0f / 30.0f, 14.0f / 30.0f, 0.0f, 0.4f, HITLEVEL_GROUND, 1, 0}, - {ANIM_HIT_FRONT, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_HIT_BACK, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_HIT_RIGHT, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_HIT_LEFT, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_HIT_BODYBLOW, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_HIT_CHEST, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_HIT_HEAD, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_HIT_WALK, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_FLOOR_HIT, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_HIT_BEHIND, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, - {ANIM_FIGHT2_IDLE, 0.0f, 0.0f, 0.0f, 0.0f, HITLEVEL_NULL, 0, 0}, +FightMove tFightMoves[NUM_FIGHTMOVES] = +{ + { NUM_STD_ANIMS, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_PUNCH_R, 0.2f, 8.f/30.f, 0.0f, 0.3f, 1.0f, HITLEVEL_HIGH, 1, 0 }, + { ANIM_FIGHT_IDLE, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_FIGHT_SH_F, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_FIGHT_KNEE, 4.f/30.f, 0.2f, 0.0f, 0.6f, 1.0f, HITLEVEL_LOW, 2, 0 }, + { ANIM_FIGHT_LHOOK, 8.f/30.f, 10.f/30.f, 0.0f, 0.4f, 1.0f, HITLEVEL_HIGH, 3, 0 }, + { ANIM_FIGHT_JAB, 4.f/30.f, 0.2f, 0.0f, 0.7f, 1.0f, HITLEVEL_HIGH, 3, 0 }, + { ANIM_FIGHT_PUNCH, 4.f/30.f, 7.f/30.f, 10.f/30.f, 0.4f, 1.0f, HITLEVEL_HIGH, 1, 0 }, + { ANIM_FIGHT_LONGKICK, 8.f/30.f, 10.f/30.f, 0.0f, 0.5f, 1.0f, HITLEVEL_MEDIUM, 4, 0 }, + { ANIM_FIGHT_ROUNDHOUSE, 8.f/30.f, 10.f/30.f, 0.0f, 0.6f, 1.0f, HITLEVEL_MEDIUM, 4, 0 }, + { ANIM_FIGHT_KICK, 8.f/30.f, 10.f/30.f, 0.0f, 0.5f, 1.0f, HITLEVEL_HIGH, 2, 0 }, + { ANIM_FIGHT_HEAD, 8.f/30.f, 10.f/30.f, 0.0f, 0.5f, 1.0f, HITLEVEL_MEDIUM, 2, 0 }, + { ANIM_FIGHT_BKICK_L, 8.f/30.f, 10.f/30.f, 0.0f, 0.5f, 1.0f, HITLEVEL_LOW, 2, 0 }, + { ANIM_FIGHT_BKICK_L, 8.f/30.f, 10.f/30.f, 0.0f, 0.5f, 1.0f, HITLEVEL_LOW, 2, 0 }, + { ANIM_FIGHT_ELBOW_L, 8.f/30.f, 10.f/30.f, 0.0f, 0.5f, 1.0f, HITLEVEL_MEDIUM, 2, 0 }, + { ANIM_FIGHT_BKICK_R, 8.f/30.f, 10.f/30.f, 0.0f, 0.5f, 1.0f, HITLEVEL_MEDIUM, 2, 0 }, + { ANIM_FIGHT_ELBOW_R, 8.f/30.f, 10.f/30.f, 0.0f, 0.5f, 1.0f, HITLEVEL_HIGH, 2, 0 }, + { ANIM_KICK_FLOOR, 10.f/30.f, 14.f/30.f, 0.0f, 0.4f, 1.0f, HITLEVEL_GROUND, 1, 0 }, + { ANIM_HIT_FRONT, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_HIT_BACK, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_HIT_RIGHT, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_HIT_LEFT, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_HIT_BODYBLOW, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_HIT_CHEST, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_HIT_HEAD, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_HIT_WALK, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_FLOOR_HIT, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_HIT_BEHIND, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 }, + { ANIM_WEAPON_FIRE, 4.f/30.f, 7.f/30.f, 10.f/30.f, 0.4f, 1.0f, HITLEVEL_HIGH, 1, 0 }, + { ANIM_WEAPON_CROUCHFIRE, 4.f/30.f, 7.f/30.f, 10.f/30.f, 0.4f, 1.0f, HITLEVEL_HIGH, 1, 0 }, + { ANIM_WEAPON_SPECIAL, 4.f / 30.f, 7.f / 30.f, 10.f / 30.f, 0.4f, 1.0f, HITLEVEL_HIGH, 1, 0 }, + { ANIM_FIGHT2_IDLE, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, HITLEVEL_NULL, 0, 0 } }; uint16 CPed::nThreatReactionRangeMultiplier = 1; @@ -107,31 +125,42 @@ CVector vecPedVanRearDoorAnimOffset; CVector vecPedQuickDraggedOutCarAnimOffset; CVector vecPedDraggedOutCarAnimOffset; CVector vecPedTrainDoorAnimOffset; +CVector vecPedStdBikeJumpRhsAnimOffset; +CVector vecPedVespaBikeJumpRhsAnimOffset; +CVector vecPedHarleyBikeJumpRhsAnimOffset; +CVector vecPedDirtBikeJumpRhsAnimOffset; +CVector vecPedBikeKickAnimOffset; bool CPed::bNastyLimbsCheat; +bool CPed::bFannyMagnetCheat; bool CPed::bPedCheat2; bool CPed::bPedCheat3; CVector2D CPed::ms_vec2DFleePosition; +CVector vecNextPathNode; +bool vecNextPathNodeInitialized; + void *CPed::operator new(size_t sz) { return CPools::GetPedPool()->New(); } void *CPed::operator new(size_t sz, int handle) { return CPools::GetPedPool()->New(handle); } void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); } void CPed::operator delete(void *p, int handle) { CPools::GetPedPool()->Delete((CPed*)p); } -#ifdef DEBUGMENU -bool CPed::bPopHeadsOnHeadshot = false; -#endif - +// --MIAMI: Done CPed::~CPed(void) { +#ifdef USE_CUTSCENE_SHADOW_FOR_PED + if ( m_pRTShadow ) delete m_pRTShadow; +#endif CWorld::Remove(this); + if (m_attractor) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); CRadar::ClearBlipForEntity(BLIP_CHAR, CPools::GetPedPool()->GetIndex(this)); if (InVehicle()){ uint8 door_flag = GetCarDoorFlag(m_vehEnterType); if (m_pMyVehicle->pDriver == this) m_pMyVehicle->pDriver = nil; else { - // FIX: Passenger counter now decreasing after removing ourself from vehicle. + // FIX: Passenger counter now being decreased after removing ourself from vehicle. m_pMyVehicle->RemovePassenger(this); } if (m_nPedState == PED_EXIT_CAR || m_nPedState == PED_DRAG_FROM_CAR) @@ -143,10 +172,17 @@ CPed::~CPed(void) } if (m_pFire) m_pFire->Extinguish(); + + ClearWeapons(); + if (bCarPassenger) + CPopulation::ms_nTotalCarPassengerPeds--; + if (bMiamiViceCop) + CPopulation::NumMiamiViceCops--; CPopulation::UpdatePedCount((ePedType)m_nPedType, true); DMAudio.DestroyEntity(m_audioEntityId); } +// --MIAMI: Done void CPed::FlagToDestroyWhenNextProcessed(void) { @@ -162,15 +198,19 @@ CPed::FlagToDestroyWhenNextProcessed(void) } bInVehicle = false; m_pMyVehicle = nil; + if (CharCreatedBy == MISSION_CHAR) - m_nPedState = PED_DEAD; + SetPedState(PED_DEAD); else - m_nPedState = PED_NONE; + SetPedState(PED_NONE); m_pVehicleAnim = nil; } CPed::CPed(uint32 pedType) : m_pedIK(this) { +#ifdef USE_CUTSCENE_SHADOW_FOR_PED + m_pRTShadow = nil; +#endif m_type = ENTITY_TYPE_PED; bPedPhysics = true; bUseCollisionRecords = true; @@ -192,13 +232,17 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) CharCreatedBy = RANDOM_CHAR; m_leader = nil; m_pedInObjective = nil; + m_attractorHeading = 0.0f; m_carInObjective = nil; + m_attractorHeading = 0.0f; bInVehicle = false; m_pMyVehicle = nil; m_pVehicleAnim = nil; m_vecOffsetSeek.x = 0.0f; m_vecOffsetSeek.y = 0.0f; m_vecOffsetSeek.z = 0.0f; + m_attractor = nil; + m_positionInQueue = -1; m_pedFormation = FORMATION_UNDEFINED; m_collidingThingTimer = 0; m_nPedStateTimer = 0; @@ -227,6 +271,10 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); m_wepSkills = 0; m_distanceToCountSeekDone = 1.0f; + m_acceptableHeadingOffset = 0.1f; + m_followPathDestPos = CVector(0.f, 0.f, 0.f); + m_followPathAbortDist = 0.0f; + m_followPathMoveState = PEDMOVE_NONE; bRunningToPhone = false; m_phoneId = -1; m_lastAccident = 0; @@ -234,6 +282,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) m_fleeFromPosX = 0; m_fleeFromPosY = 0; m_fleeTimer = 0; + pThreatEx = nil; m_vecSeekPosEx = CVector(0.0f, 0.0f, 0.0f); m_distanceToCountSeekDoneEx = 0.0f; m_nWaitState = WAITSTATE_FALSE; @@ -252,11 +301,20 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) m_fLookDirection = 0.0f; m_pCurSurface = nil; m_wanderRangeBounds = nil; - m_nPathNodes = 0; - m_nCurPathNode = 0; + + for (int i = 0; i < ARRAY_SIZE(m_pathNodesToGo); i++) { + m_pathNodesToGo[i] = nil; + } + m_nNumPathNodes = 0; + m_nCurPathNodeId = 0; m_nPathDir = 0; m_pLastPathNode = nil; m_pNextPathNode = nil; + m_followPathWalkAroundEnt = nil; + m_followPathTargetEnt = nil; + m_pathNodeTimer = 0; + m_pCurPathNode = nil; + m_routeLastPoint = -1; m_routeStartPoint = 0; m_routePointsPassed = 0; @@ -268,6 +326,8 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) m_fAirResistance = 0.4f / m_fMass; m_fElasticity = 0.05f; + m_ceaseAttackTimer = 0; + bIsStanding = false; bWasStanding = false; bIsAttacking = false; @@ -348,9 +408,40 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) #ifdef KANGAROO_CHEAT m_ped_flagI80 = false; #endif -#ifdef VC_PED_PORTS - bSomeVCflag1 = false; -#endif + + bReachedAttractorHeadingTarget = false; + bTurnedAroundOnAttractor = false; + bHasAlreadyUsedAttractor = false; + bCarPassenger = false; + bMiamiViceCop = false; + bMoneyHasBeenGivenByScript = false; + bHasBeenPhotographed = false; + + bIsDrowning = false; + bDrownsInWater = true; + bHeadStuckInCollision = false; + bHeldHostageInCar = false; + bIsPlayerFriend = true; + bDeadPedInFrontOfCar = false; + + m_gangFlags = 0xFF; + + bStayInCarOnJack = false; + + bDontFight = false; + bDoomAim = true; + bCanBeShotInVehicle = true; + bPushedAlongByCar = false; + b157_40 = false; + bIgnoreThreatsBehindObjects = false; + + bNeverEverTargetThisPed = false; + bCrouchWhenScared = false; + bKnockedOffBike = false; + b158_8 = false; + b158_10 = false; + bBoughtIceCream = false; + b158_40 = false; if ((CGeneral::GetRandomNumber() & 3) == 0) bHasACamera = true; @@ -366,15 +457,13 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) for (int i = 0; i < ARRAY_SIZE(m_nearPeds); i++) { m_nearPeds[i] = nil; - if (i < ARRAY_SIZE(m_pPathNodesStates)) { - m_pPathNodesStates[i] = nil; - } } m_maxWeaponTypeAllowed = WEAPONTYPE_UNARMED; m_currentWeapon = WEAPONTYPE_UNARMED; m_storedWeapon = WEAPONTYPE_UNIDENTIFIED; + m_delayedWeapon = WEAPONTYPE_UNIDENTIFIED; - for(int i = 0; i < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; i++) { + for(int i = 0; i < TOTAL_WEAPON_SLOTS; i++) { CWeapon &weapon = GetWeapon(i); weapon.m_eWeaponType = WEAPONTYPE_UNARMED; weapon.m_eWeaponState = WEAPONSTATE_READY; @@ -383,40 +472,67 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) weapon.m_nTimer = 0; } - m_curFightMove = FIGHTMOVE_NULL; - GiveWeapon(WEAPONTYPE_UNARMED, 0); + m_curFightMove = m_lastFightMove = FIGHTMOVE_IDLE; + GiveWeapon(WEAPONTYPE_UNARMED, 0, true); m_wepAccuracy = 60; m_lastWepDam = -1; + m_lastDamEntity = nil; + m_attachedTo = nil; + m_attachWepAmmo = 0; m_collPoly.valid = false; m_fCollisionSpeed = 0.0f; m_wepModelID = -1; + uint16 random = CGeneral::GetRandomNumber(); + m_nPedMoney = random % 25; + if (m_nPedMoney == 23) + m_nPedMoney = 400; + m_nExtendedRangeTimer = 0; + m_bleedCounter = 0; #ifdef PED_SKIN m_pWeaponModel = nil; #endif + m_delayedSoundID = -1; + m_delayedSoundTimer = 0; CPopulation::UpdatePedCount((ePedType)m_nPedType, false); } -uint32 -CPed::GiveWeapon(eWeaponType weaponType, uint32 ammo) +// --MIAMI: Done +int32 +CPed::GiveWeapon(eWeaponType weaponType, uint32 ammo, bool unused) { - CWeapon &weapon = GetWeapon(weaponType); + int slot = GetWeaponSlot(weaponType); - if (HasWeapon(weaponType)) { - if (weapon.m_nAmmoTotal + ammo > 99999) - weapon.m_nAmmoTotal = 99999; - else - weapon.m_nAmmoTotal += ammo; + if (m_weapons[slot].m_eWeaponType == weaponType) { + GetWeapon(slot).m_nAmmoTotal += ammo; + if (weaponType < WEAPONTYPE_TOTALWEAPONS && weaponType > WEAPONTYPE_UNARMED && CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType] >= 0) { - weapon.Reload(); + // Looks like abandoned idea. This block never runs, ms_aMaxAmmoForWeapon is always -1. + GetWeapon(slot).m_nAmmoTotal = Min(CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType], GetWeapon(slot).m_nAmmoTotal); + } else { + GetWeapon(slot).m_nAmmoTotal = Min(99999, GetWeapon(slot).m_nAmmoTotal); + } + GetWeapon(slot).Reload(); + if (GetWeapon(slot).m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO && GetWeapon(slot).m_nAmmoTotal > 0) + GetWeapon(slot).m_eWeaponState = WEAPONSTATE_READY; } else { - weapon.Initialise(weaponType, ammo); - // TODO: It seems game uses this as both weapon count and max WeaponType we have, which is ofcourse erroneous. - m_maxWeaponTypeAllowed++; + if (HasWeaponSlot(slot)) { + + // TODO(Miami): Make an enum for that + if (slot == 4 || slot == 5 || slot == 6) + ammo += GetWeapon(slot).m_nAmmoTotal; + + RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(GetWeapon(slot).m_eWeaponType)->m_nModelId); + GetWeapon(slot).Shutdown(); + } + GetWeapon(slot).Initialise(weaponType, ammo); + if (slot == m_currentWeapon && !bInVehicle) { + AddWeaponModel(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nModelId); + } } - if (weapon.m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO) - weapon.m_eWeaponState = WEAPONSTATE_READY; + if (GetWeapon(slot).m_eWeaponState != WEAPONSTATE_OUT_OF_AMMO) + GetWeapon(slot).m_eWeaponState = WEAPONSTATE_READY; - return weaponType; + return slot; } static RwObject* @@ -522,13 +638,20 @@ CheckForPedsOnGroundToAttack(CPed *attacker, CPed **pedOnGround) return stateToReturn; } +// --MIAMI: Done bool CPed::IsPlayer(void) { +#if 0 + return m_nPedType == PEDTYPE_PLAYER1; // Original +#else + // We still have those in enum, so let's also check for them. return m_nPedType == PEDTYPE_PLAYER1 || m_nPedType == PEDTYPE_PLAYER2 || m_nPedType == PEDTYPE_PLAYER3 || m_nPedType == PEDTYPE_PLAYER4; +#endif } +// --MIAMI: Done bool CPed::UseGroundColModel(void) { @@ -538,12 +661,14 @@ CPed::UseGroundColModel(void) m_nPedState == PED_DEAD; } +// --MIAMI: Done bool CPed::CanSetPedState(void) { return !DyingOrDead() && m_nPedState != PED_ARRESTED && !EnteringCar() && m_nPedState != PED_STEAL_CAR; } +// --MIAMI: Done bool CPed::IsPedInControl(void) { @@ -552,6 +677,7 @@ CPed::IsPedInControl(void) && m_fHealth > 0.0f; } +// --MIAMI: Done bool CPed::CanStrafeOrMouseControl(void) { @@ -560,9 +686,10 @@ CPed::CanStrafeOrMouseControl(void) return false; #endif return m_nPedState == PED_NONE || m_nPedState == PED_IDLE || m_nPedState == PED_FLEE_POS || m_nPedState == PED_FLEE_ENTITY || - m_nPedState == PED_ATTACK || m_nPedState == PED_FIGHT || m_nPedState == PED_AIM_GUN || m_nPedState == PED_JUMP; + m_nPedState == PED_ATTACK || m_nPedState == PED_FIGHT || m_nPedState == PED_AIM_GUN || m_nPedState == PED_JUMP || m_nPedState == PED_ANSWER_MOBILE; } +// --MIAMI: Done void CPed::AddWeaponModel(int id) { @@ -575,7 +702,8 @@ CPed::AddWeaponModel(int id) RemoveWeaponModel(-1); m_pWeaponModel = (RpAtomic*)CModelInfo::GetModelInfo(id)->CreateInstance(); - } else + } + else #endif { atm = (RpAtomic*)CModelInfo::GetModelInfo(id)->CreateInstance(); @@ -583,28 +711,38 @@ CPed::AddWeaponModel(int id) RpAtomicSetFrame(atm, m_pFrames[PED_HANDR]->frame); RpClumpAddAtomic(GetClump(), atm); } + CModelInfo::GetModelInfo(id)->AddRef(); m_wepModelID = id; + + if (IsPlayer() && id == MI_MINIGUN) + ((CPlayerPed*)this)->m_pMinigunTopAtomic = (RpAtomic*)CModelInfo::GetModelInfo(MI_MINIGUN2)->CreateInstance(); } } +// --MIAMI: Done void CPed::AimGun(void) { RwV3d pos; CVector vector; + if (IsPlayer() && bIsDucking) + m_pedIK.m_flags &= ~CPedIK::AIMS_WITH_ARM; + if (m_pSeekTarget) { if (m_pSeekTarget->IsPed()) { - ((CPed*)m_pSeekTarget)->m_pedIK.GetComponentPosition(&pos, PED_MID); + ((CPed*)m_pSeekTarget)->m_pedIK.GetComponentPosition(pos, PED_MID); vector = pos; } else { vector = m_pSeekTarget->GetPosition(); } - Say(SOUND_PED_ATTACK); + + if (!IsPlayer()) + Say(SOUND_PED_ATTACK); bCanPointGunAtTarget = m_pedIK.PointGunAtPosition(vector); if (m_pLookTarget != m_pSeekTarget) { - SetLookFlag(m_pSeekTarget, true); + SetLookFlag(m_pSeekTarget, true, true); } } else { @@ -630,7 +768,7 @@ CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer) // BUG: This condition will always return true. Even fixing it won't work, because these states are unused. // if (m_nPedState != PED_PASSENGER || m_nPedState != PED_TAXI_PASSENGER) { - CPed::SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); + SetDie(); // } bBodyPartJustCameOff = true; @@ -685,11 +823,7 @@ CPed::RemoveBodyPart(PedNode nodeId, int8 direction) if(!IsClumpSkinned(GetClump())) #endif { -#ifdef DEBUGMENU - if (bPopHeadsOnHeadshot || nodeId != PED_HEAD) -#else if (nodeId != PED_HEAD) -#endif SpawnFlyingComponent(nodeId, direction); RecurseFrameChildrenVisibilityCB(frame, nil); @@ -719,10 +853,11 @@ CPed::RemoveBodyPart(PedNode nodeId, int8 direction) } } +// --MIAMI: Done void -CPed::SetLookFlag(CEntity *target, bool keepTryingToLook) +CPed::SetLookFlag(CEntity *target, bool keepTryingToLook, bool cancelPrevious) { - if (m_lookTimer < CTimer::GetTimeInMilliseconds()) { + if (m_lookTimer < CTimer::GetTimeInMilliseconds() || cancelPrevious) { bIsLooking = true; bIsRestoringLook = false; m_pLookTarget = target; @@ -730,28 +865,30 @@ CPed::SetLookFlag(CEntity *target, bool keepTryingToLook) m_fLookDirection = 999999.0f; m_lookTimer = 0; bKeepTryingToLook = keepTryingToLook; - if (m_nPedState != PED_DRIVING) { + if (CanUseTorsoWhenLooking()) { m_pedIK.m_flags &= ~CPedIK::LOOKAROUND_HEAD_ONLY; } } } +// --MIAMI: Done void -CPed::SetLookFlag(float direction, bool keepTryingToLook) +CPed::SetLookFlag(float direction, bool keepTryingToLook, bool cancelPrevious) { - if (m_lookTimer < CTimer::GetTimeInMilliseconds()) { + if (m_lookTimer < CTimer::GetTimeInMilliseconds() || cancelPrevious) { bIsLooking = true; bIsRestoringLook = false; - m_pLookTarget = nil; m_fLookDirection = direction; + m_pLookTarget = nil; m_lookTimer = 0; bKeepTryingToLook = keepTryingToLook; - if (m_nPedState != PED_DRIVING) { + if (CanUseTorsoWhenLooking()) { m_pedIK.m_flags &= ~CPedIK::LOOKAROUND_HEAD_ONLY; } } } +// --MIAMI: Done void CPed::SetLookTimer(int time) { @@ -760,8 +897,9 @@ CPed::SetLookTimer(int time) } } +// --MIAMI: Done bool -CPed::OurPedCanSeeThisOne(CEntity *target) +CPed::OurPedCanSeeThisOne(CEntity *target, bool shootablesDoBlock) { CColPoint colpoint; CEntity *ent; @@ -777,11 +915,11 @@ CPed::OurPedCanSeeThisOne(CEntity *target) return false; // 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); + return !CWorld::ProcessLineOfSight(GetPosition() + CVector(0.f, 0.f, 1.f), target->GetPosition() + CVector(0.f, 0.f, 1.f), + colpoint, ent, true, false, false, shootablesDoBlock, false, false, false, shootablesDoBlock); } +// --MIAMI: Done void CPed::Avoid(void) { @@ -830,6 +968,8 @@ CPed::Avoid(void) } } + +// --MIAMI: Done void CPed::ClearAimFlag(void) { @@ -837,15 +977,14 @@ CPed::ClearAimFlag(void) bIsAimingGun = false; bIsRestoringGun = true; m_pedIK.m_flags &= ~CPedIK::AIMS_WITH_ARM; -#if defined VC_PED_PORTS || defined FIX_BUGS m_lookTimer = 0; -#endif } if (IsPlayer()) ((CPlayerPed*)this)->m_fFPSMoveHeading = 0.0f; } +// --MIAMI: Done void CPed::ClearLookFlag(void) { if (bIsLooking) { @@ -853,7 +992,9 @@ CPed::ClearLookFlag(void) { bIsRestoringLook = true; bShakeFist = false; - m_pedIK.m_flags &= ~CPedIK::LOOKAROUND_HEAD_ONLY; + if (CanUseTorsoWhenLooking()) + m_pedIK.m_flags &= ~CPedIK::LOOKAROUND_HEAD_ONLY; + if (IsPlayer()) m_lookTimer = CTimer::GetTimeInMilliseconds() + 2000; else @@ -866,122 +1007,275 @@ CPed::ClearLookFlag(void) { } } +// --MIAMI: Done bool CPed::IsPedHeadAbovePos(float zOffset) { return zOffset + GetPosition().z < GetNodePosition(PED_HEAD).z; } +// --MIAMI: Done +void +CPed::FinishedReloadCB(CAnimBlendAssociation *reloadAssoc, void *arg) +{ + CPed *ped = (CPed*)arg; + CWeaponInfo *weapon = CWeaponInfo::GetWeaponInfo(ped->GetWeapon()->m_eWeaponType); + + if (ped->DyingOrDead()) + return; + + if (ped->bIsDucking && ped->bCrouchWhenShooting) { + CAnimBlendAssociation *crouchFireAssoc = nil; + if (!!weapon->m_bCrouchFire) { + crouchFireAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), GetCrouchFireAnim(weapon)); + } + if (!!weapon->m_bReload && reloadAssoc) { + if (reloadAssoc->animId == GetCrouchReloadAnim(weapon) && !crouchFireAssoc) { + CAnimBlendAssociation *crouchAssoc = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_WEAPON_CROUCH, 8.0f); + crouchAssoc->SetCurrentTime(crouchAssoc->hierarchy->totalLength); + crouchAssoc->flags &= ~ASSOC_RUNNING; + } + } + } else if (weapon->m_bReloadLoop2Start && ped->bIsAttacking) { + CAnimBlendAssociation *fireAssoc = + CAnimManager::BlendAnimation(ped->GetClump(), weapon->m_AnimToPlay, GetPrimaryFireAnim(weapon), 8.0f); + fireAssoc->SetFinishCallback(FinishedAttackCB, ped); + fireAssoc->SetRun(); + if (fireAssoc->currentTime != reloadAssoc->hierarchy->totalLength) { + if (fireAssoc->currentTime >= weapon->m_fAnimLoopStart) + return; + + fireAssoc->SetCurrentTime(Max(weapon->m_fAnimLoopStart - 0.04f, 0.0f)); + } else { + fireAssoc->SetCurrentTime(Max(weapon->m_fAnimLoopStart - 0.04f, 0.0f)); + } + } +} + +// --MIAMI: Done void CPed::FinishedAttackCB(CAnimBlendAssociation *attackAssoc, void *arg) { - CWeaponInfo *currentWeapon; - CAnimBlendAssociation *newAnim; + CAnimBlendAssociation *newAnim, *reloadAnimAssoc = nil; CPed *ped = (CPed*)arg; + CWeaponInfo *currentWeapon = CWeaponInfo::GetWeaponInfo(ped->GetWeapon()->m_eWeaponType); - if (attackAssoc) { - switch (attackAssoc->animId) { - case ANIM_WEAPON_START_THROW: - // what?! - if ((!ped->IsPlayer() || ((CPlayerPed*)ped)->m_bHaveTargetSelected) && ped->IsPlayer()) { - attackAssoc->blendDelta = -1000.0f; - newAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_WEAPON_THROWU); - } else { - attackAssoc->blendDelta = -1000.0f; - newAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_WEAPON_THROW); + if (ped->m_nPedState != PED_ATTACK) { + if (ped->bIsDucking && ped->IsPedInControl()) { + if (currentWeapon->m_bReload) { + reloadAnimAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), GetCrouchReloadAnim(currentWeapon)); + } + if (currentWeapon->m_bCrouchFire && attackAssoc) { + if (attackAssoc->animId == GetCrouchFireAnim(currentWeapon) && !reloadAnimAssoc) { + newAnim = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_WEAPON_CROUCH, 8.0f); + newAnim->SetCurrentTime(newAnim->hierarchy->totalLength); + newAnim->flags &= ~ASSOC_RUNNING; } + } + } + return; + } + if (attackAssoc && attackAssoc->animId == ANIM_THROWABLE_START_THROW && currentWeapon->m_AnimToPlay == ASSOCGRP_THROW) { + if ((!ped->IsPlayer() || ((CPlayerPed*)ped)->m_bHaveTargetSelected) && ped->IsPlayer()) { + attackAssoc->blendDelta = -1000.0f; + newAnim = CAnimManager::AddAnimation(ped->GetClump(), currentWeapon->m_AnimToPlay, ANIM_THROWABLE_THROWU); + } else { + attackAssoc->blendDelta = -1000.0; + newAnim = CAnimManager::AddAnimation(ped->GetClump(), currentWeapon->m_AnimToPlay, ANIM_THROWABLE_THROW); + } + newAnim->SetFinishCallback(FinishedAttackCB, ped); + return; + } - newAnim->SetFinishCallback(FinishedAttackCB, ped); - return; + if (ped->bIsDucking && ped->bCrouchWhenShooting) { + if (currentWeapon->m_bReload) { + reloadAnimAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), GetCrouchReloadAnim(currentWeapon)); + } + if (currentWeapon->m_bCrouchFire && attackAssoc) { + if (attackAssoc->animId == GetCrouchFireAnim(currentWeapon) && !reloadAnimAssoc) { + newAnim = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_WEAPON_CROUCH, 8.0f); + newAnim->SetCurrentTime(newAnim->hierarchy->totalLength); + newAnim->flags &= ~ASSOC_RUNNING; + } + } - case ANIM_FIGHT_PPUNCH: - attackAssoc->blendDelta = -8.0f; - attackAssoc->flags |= ASSOC_DELETEFADEDOUT; - ped->ClearAttack(); - return; + if (!ped->bIsAttacking) + ped->ClearAttack(); - case ANIM_WEAPON_THROW: - case ANIM_WEAPON_THROWU: - if (ped->GetWeapon()->m_nAmmoTotal > 0) { - currentWeapon = CWeaponInfo::GetWeaponInfo(ped->GetWeapon()->m_eWeaponType); + return; + } + + if (GetSecondFireAnim(currentWeapon) && ped->bIsAttacking && currentWeapon->m_AnimToPlay != ASSOCGRP_THROW) { + AnimationId groundAnim = GetFireAnimGround(currentWeapon); + CAnimBlendAssociation *groundAnimAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), groundAnim); + if (!groundAnimAssoc || groundAnimAssoc->blendAmount <= 0.95f && groundAnimAssoc->blendDelta <= 0.0f) { + if (attackAssoc && attackAssoc->animId == ANIM_MELEE_ATTACK) { + newAnim = CAnimManager::BlendAnimation( + ped->GetClump(), currentWeapon->m_AnimToPlay, GetSecondFireAnim(currentWeapon), 8.0f); + } else { + newAnim = CAnimManager::BlendAnimation( + ped->GetClump(), currentWeapon->m_AnimToPlay, ANIM_MELEE_ATTACK, 8.0f); + } + newAnim->SetFinishCallback(FinishedAttackCB, ped); + } + } else { + if (attackAssoc && attackAssoc->animId == ANIM_MELEE_ATTACK && currentWeapon->m_AnimToPlay == ASSOCGRP_UNARMED) { + attackAssoc->blendDelta = -8.0f; + attackAssoc->flags |= ASSOC_DELETEFADEDOUT; + ped->ClearAttack(); + return; + } + if (attackAssoc) { + if (currentWeapon->m_AnimToPlay == ASSOCGRP_THROW) { + if ((attackAssoc->animId == ANIM_THROWABLE_THROW || attackAssoc->animId == ANIM_THROWABLE_THROWU) && ped->GetWeapon()->m_nAmmoTotal > 0) { + ped->RemoveWeaponModel(currentWeapon->m_nModelId); ped->AddWeaponModel(currentWeapon->m_nModelId); } - break; - default: - break; + } } + + if (!ped->bIsAttacking) + ped->ClearAttack(); } - - if (!ped->bIsAttacking) - ped->ClearAttack(); } +// --MIAMI: Done except commented things void CPed::Attack(void) { CAnimBlendAssociation *weaponAnimAssoc; int32 weaponAnim; - float animStart; eWeaponType ourWeaponType; float weaponAnimTime; eWeaponFire ourWeaponFire; float animLoopEnd; CWeaponInfo *ourWeapon; bool attackShouldContinue; - AnimationId reloadAnim; CAnimBlendAssociation *reloadAnimAssoc; + CAnimBlendAssociation *throwAssoc; float delayBetweenAnimAndFire; + float animLoopStart; CVector firePos; ourWeaponType = GetWeapon()->m_eWeaponType; ourWeapon = CWeaponInfo::GetWeaponInfo(ourWeaponType); ourWeaponFire = ourWeapon->m_eWeaponFire; - weaponAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ourWeapon->m_AnimToPlay); + weaponAnimAssoc = nil; attackShouldContinue = bIsAttacking; reloadAnimAssoc = nil; - reloadAnim = NUM_ANIMS; + throwAssoc = nil; + animLoopStart = ourWeapon->m_fAnimLoopStart; + animLoopEnd = ourWeapon->m_fAnimLoopEnd; delayBetweenAnimAndFire = ourWeapon->m_fAnimFrameFire; weaponAnim = ourWeapon->m_AnimToPlay; - if (weaponAnim == ANIM_WEAPON_HGUN_BODY) - reloadAnim = ANIM_HGUN_RELOAD; - else if (weaponAnim == ANIM_WEAPON_AK_BODY) - reloadAnim = ANIM_AK_RELOAD; + if (bIsDucking) { + if (!!ourWeapon->m_bCrouchFire && bCrouchWhenShooting) { + weaponAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchFireAnim(ourWeapon)); + if (weaponAnimAssoc) { + animLoopStart = ourWeapon->m_fAnim2LoopStart; + animLoopEnd = ourWeapon->m_fAnim2LoopEnd; + delayBetweenAnimAndFire = ourWeapon->m_fAnim2FrameFire; + } + } + } else { + AnimationId anim = GetFireAnimNotDucking(ourWeapon); + weaponAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), anim); + if (anim == ANIM_WEAPON_FIRE_3RD && weaponAnimAssoc) { + animLoopStart = 11.f/30.f; + animLoopEnd = 19.f/30.f; + delayBetweenAnimAndFire = 14.f/30.f; + } + } - if (reloadAnim != NUM_ANIMS) - reloadAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), reloadAnim); + if (ourWeapon->m_bReload) { + reloadAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetReloadAnim(ourWeapon)); + } - if (bIsDucking) - return; + if (!!ourWeapon->m_bReload && !reloadAnimAssoc) { + reloadAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchReloadAnim(ourWeapon)); + } - if (reloadAnimAssoc) { + if ( reloadAnimAssoc && reloadAnimAssoc->IsRunning() ) { if (!IsPlayer() || ((CPlayerPed*)this)->m_bHaveTargetSelected) ClearAttack(); - return; } - if (CTimer::GetTimeInMilliseconds() < m_shootTimer) + if ( reloadAnimAssoc ) { + reloadAnimAssoc->flags |= ASSOC_DELETEFADEDOUT; + if ( reloadAnimAssoc->blendDelta >= 0.0f ) + reloadAnimAssoc->blendDelta = -8.0f; + } + + if (!!ourWeapon->m_bThrow) { + throwAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_THROWABLE_START_THROW); + } + + if ( CTimer::GetTimeInMilliseconds() < m_shootTimer ) attackShouldContinue = true; + bool meleeAttackStarted = false; + if ( !weaponAnimAssoc ) { + if (!!ourWeapon->m_bPartialAttack) { + weaponAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_MELEE_ATTACK_START); + if ( weaponAnimAssoc ) { + if ( IsPlayer() ) + meleeAttackStarted = true; + + switch ( ourWeapon->m_AnimToPlay ) { + case ASSOCGRP_UNARMED: + case ASSOCGRP_SCREWDRIVER: + case ASSOCGRP_KNIFE: + case ASSOCGRP_BASEBALLBAT: + case ASSOCGRP_GOLFCLUB: + case ASSOCGRP_CHAINSAW: + delayBetweenAnimAndFire = 0.2f; + animLoopStart = 0.1f; + break; + default: + break; + } + animLoopEnd = 99.9f; + } + } + } if (!weaponAnimAssoc) { - weaponAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ourWeapon->m_Anim2ToPlay); - delayBetweenAnimAndFire = ourWeapon->m_fAnim2FrameFire; - - // Long throw granade, molotov - if (!weaponAnimAssoc && ourWeapon->m_bThrow) { - weaponAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_THROWU); - delayBetweenAnimAndFire = 0.2f; + if (!!ourWeapon->m_bUse2nd) { + weaponAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetSecondFireAnim(ourWeapon)); + if (weaponAnimAssoc) { + animLoopStart = ourWeapon->m_fAnim2LoopStart; + animLoopEnd = ourWeapon->m_fAnim2LoopEnd; + delayBetweenAnimAndFire = ourWeapon->m_fAnim2FrameFire; + } } + } + if (!weaponAnimAssoc) { + weaponAnimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetFireAnimGround(ourWeapon)); + if (weaponAnimAssoc) { + animLoopStart = ourWeapon->m_fAnim2LoopStart; + animLoopEnd = ourWeapon->m_fAnim2LoopEnd; + delayBetweenAnimAndFire = ourWeapon->m_fAnim2FrameFire; + } + } - if (!weaponAnimAssoc) { + if (!weaponAnimAssoc) { + if (!throwAssoc) { if (attackShouldContinue) { if (ourWeaponFire != WEAPON_FIRE_PROJECTILE || !IsPlayer() || ((CPlayerPed*)this)->m_bHaveTargetSelected) { - if (!CGame::nastyGame || ourWeaponFire != WEAPON_FIRE_MELEE || CheckForPedsOnGroundToAttack(this, nil) < PED_ON_THE_FLOOR) { - weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ourWeapon->m_AnimToPlay, 8.0f); - } - else { - weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ourWeapon->m_Anim2ToPlay, 8.0f); + if (bCrouchWhenShooting && bIsDucking && !!ourWeapon->m_bCrouchFire) { + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ourWeapon->m_AnimToPlay, GetCrouchFireAnim(ourWeapon), 8.0f); + + } else if(GetSecondFireAnim(ourWeapon) && CGeneral::GetRandomNumber() & 1){ + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ourWeapon->m_AnimToPlay, GetSecondFireAnim(ourWeapon), 8.0f); + + } else if (!CGame::nastyGame || (!ourWeapon->m_bGround2nd && !ourWeapon->m_bGround3rd) || + ourWeaponFire != WEAPON_FIRE_MELEE || CheckForPedsOnGroundToAttack(this, nil) < PED_ON_THE_FLOOR) { + + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ourWeapon->m_AnimToPlay, GetFireAnimNotDucking(ourWeapon), 8.0f); + + } else { + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ourWeapon->m_AnimToPlay, GetFireAnimGround(ourWeapon, false), 8.0f); } weaponAnimAssoc->SetFinishCallback(CPed::FinishedAttackCB, this); @@ -998,75 +1292,127 @@ CPed::Attack(void) } else FinishedAttackCB(nil, this); - return; + } + return; + } + + if (meleeAttackStarted && IsPlayer()) { + if (((CPlayerPed*)this)->m_bHaveTargetSelected || ((CPlayerPed*)this)->m_fMoveSpeed < 0.5f) { + weaponAnimAssoc->SetRun(); + } else { + if (weaponAnimAssoc->currentTime > animLoopStart && weaponAnimAssoc->currentTime - weaponAnimAssoc->timeStep <= animLoopStart) + weaponAnimAssoc->flags &= ~ASSOC_RUNNING; } } - animStart = ourWeapon->m_fAnimLoopStart; + float animStart = ourWeapon->m_fAnimLoopStart * 0.4f; weaponAnimTime = weaponAnimAssoc->currentTime; if (weaponAnimTime > animStart && weaponAnimTime - weaponAnimAssoc->timeStep <= animStart) { - if (ourWeapon->m_bCanAimWithArm) + if (!bIsDucking && !(m_nPedType == PEDTYPE_COP && ourWeapon->m_bCop3rd && weaponAnimAssoc->animId == ANIM_WEAPON_FIRE_3RD) && ourWeapon->m_bCanAimWithArm) m_pedIK.m_flags |= CPedIK::AIMS_WITH_ARM; else m_pedIK.m_flags &= ~CPedIK::AIMS_WITH_ARM; } - if (weaponAnimTime <= delayBetweenAnimAndFire || weaponAnimTime - weaponAnimAssoc->timeStep > delayBetweenAnimAndFire || !weaponAnimAssoc->IsRunning()) { - if (weaponAnimAssoc->speed < 1.0f) - weaponAnimAssoc->speed = 1.0f; + if (ourWeaponType != WEAPONTYPE_CHAINSAW + || !meleeAttackStarted && delayBetweenAnimAndFire - 0.5f >= weaponAnimAssoc->currentTime + || weaponAnimAssoc->currentTime - weaponAnimAssoc->timeStep > delayBetweenAnimAndFire) { - } else { - firePos = ourWeapon->m_vecFireOffset; - if (ourWeaponType == WEAPONTYPE_BASEBALLBAT) { - if (weaponAnimAssoc->animId == ourWeapon->m_Anim2ToPlay) - firePos.z = 0.7f * ourWeapon->m_fRadius - 1.0f; + if (ourWeaponType == WEAPONTYPE_CHAINSAW) { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_CHAINSAW_ATTACK, 0.0f); + } else if (weaponAnimTime <= delayBetweenAnimAndFire || weaponAnimTime - weaponAnimAssoc->timeStep > delayBetweenAnimAndFire || !weaponAnimAssoc->IsRunning()) { + if (weaponAnimAssoc->speed < 1.0f) + weaponAnimAssoc->speed = 1.0f; - firePos = GetMatrix() * firePos; - } else if (ourWeaponType != WEAPONTYPE_UNARMED) { - TransformToNode(firePos, weaponAnimAssoc->animId == ANIM_KICK_FLOOR ? PED_FOOTR : PED_HANDR); } else { - firePos = GetMatrix() * firePos; - } - - GetWeapon()->Fire(this, &firePos); + firePos = ourWeapon->m_vecFireOffset; - if (ourWeaponType == WEAPONTYPE_MOLOTOV || ourWeaponType == WEAPONTYPE_GRENADE) { - RemoveWeaponModel(ourWeapon->m_nModelId); - } - if (!GetWeapon()->m_nAmmoTotal && ourWeaponFire != WEAPON_FIRE_MELEE && FindPlayerPed() != this) { - SelectGunIfArmed(); - } + if (ourWeaponType != WEAPONTYPE_KATANA && ourWeaponType != WEAPONTYPE_CHAINSAW) { + if (ourWeapon->m_eWeaponFire != WEAPON_FIRE_MELEE) { + TransformToNode(firePos, (weaponAnimAssoc->animId == ANIM_MELEE_ATTACK_2ND && ourWeapon->m_AnimToPlay == ASSOCGRP_UNARMED) ? PED_FOOTR : PED_HANDR); + } else { + firePos = GetMatrix() * firePos; + } + } else { + if (weaponAnimAssoc->animId == ANIM_MELEE_ATTACK_2ND) + firePos.z = 0.7f * ourWeapon->m_fRadius - 1.0f; - if (GetWeapon()->m_eWeaponState != WEAPONSTATE_MELEE_MADECONTACT) { - // If reloading just began, start the animation - // Last condition will always return true, even IDA hides it - if (GetWeapon()->m_eWeaponState == WEAPONSTATE_RELOADING && reloadAnim != NUM_ANIMS /* && !reloadAnimAssoc*/) { - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, reloadAnim, 8.0f); - ClearLookFlag(); - ClearAimFlag(); - bIsAttacking = false; - bIsPointingGunAt = false; - m_shootTimer = CTimer::GetTimeInMilliseconds(); - return; + firePos = GetMatrix() * firePos; } - } else { - if (weaponAnimAssoc->animId == ANIM_WEAPON_BAT_V || weaponAnimAssoc->animId == ANIM_WEAPON_BAT_H) { - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_BAT_ATTACK, 1.0f); - } else if (weaponAnimAssoc->animId == ANIM_FIGHT_PPUNCH) { - DMAudio.PlayOneShot(m_audioEntityId, SOUND_FIGHT_PUNCH_39, 0.0f); + + GetWeapon()->Fire(this, &firePos); + + if (ourWeaponType == WEAPONTYPE_MOLOTOV || ourWeaponType == WEAPONTYPE_GRENADE || ourWeaponType == WEAPONTYPE_DETONATOR_GRENADE || + ourWeaponType == WEAPONTYPE_TEARGAS) { + RemoveWeaponModel(ourWeapon->m_nModelId); + } + if (!GetWeapon()->m_nAmmoTotal && ourWeaponFire != WEAPON_FIRE_MELEE && FindPlayerPed() != this) { + SelectGunIfArmed(); } - weaponAnimAssoc->speed = 0.5f; + if (GetWeapon()->m_eWeaponState == WEAPONSTATE_MELEE_MADECONTACT) { + int damagerType = ENTITY_TYPE_NOTHING; + if (m_pDamageEntity && (m_fDamageImpulse == 0.0f || !m_pDamageEntity->IsBuilding())) { + damagerType = m_pDamageEntity->GetType(); + } + switch (ourWeapon->m_AnimToPlay) { + case ASSOCGRP_UNARMED: + if (weaponAnimAssoc->animId == ANIM_MELEE_ATTACK || weaponAnimAssoc->animId == ANIM_MELEE_ATTACK_START) { +#ifdef AUDIO_NOT_READY + DMAudio.PlayOneShot(m_audioEntityId, SOUND_FIGHT_46, 0.0f); +#else + DMAudio.PlayOneShot(m_audioEntityId, SOUND_FIGHT_46, (damagerType | (ourWeaponType << 8))); +#endif + } + break; + case ASSOCGRP_KNIFE: + case ASSOCGRP_BASEBALLBAT: + case ASSOCGRP_GOLFCLUB: + case ASSOCGRP_CHAINSAW: +#ifdef AUDIO_NOT_READY + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_BAT_ATTACK, 1.0f); +#else + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_BAT_ATTACK, (damagerType | (ourWeaponType << 8))); +#endif + break; + default: + break; + } - if (bIsAttacking || CTimer::GetTimeInMilliseconds() < m_shootTimer) { - weaponAnimAssoc->callbackType = 0; + if (bIsAttacking || CTimer::GetTimeInMilliseconds() < m_shootTimer) { + weaponAnimAssoc->callbackType = 0; + } } + + attackShouldContinue = false; } + } else { + CVector firePos = ourWeapon->m_vecFireOffset; + + if (weaponAnimAssoc->animId == ANIM_MELEE_ATTACK_2ND) + firePos.z = 0.7f * ourWeapon->m_fRadius - 1.0f; + firePos = GetMatrix() * firePos; + GetWeapon()->Fire(this, &firePos); + if (GetWeapon()->m_eWeaponState == WEAPONSTATE_MELEE_MADECONTACT) { + int damagerType = ENTITY_TYPE_PED; + if (m_pDamageEntity) + damagerType = m_pDamageEntity->GetType(); + + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_CHAINSAW_MADECONTACT, (float)damagerType); + if (IsPlayer()) { + CPad::GetPad(0)->StartShake(240, 180); + } + } else { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_CHAINSAW_IDLE, 0.0f); + if (IsPlayer()) { + CPad::GetPad(0)->StartShake(240, 90); + } + } attackShouldContinue = false; } - if (ourWeaponType == WEAPONTYPE_SHOTGUN) { + if (ourWeapon->m_eWeaponFire == WEAPON_FIRE_INSTANT_HIT && ourWeapon->m_AnimToPlay == ASSOCGRP_SHOTGUN) { weaponAnimTime = weaponAnimAssoc->currentTime; firePos = ourWeapon->m_vecFireOffset; @@ -1088,85 +1434,119 @@ CPed::Attack(void) GetWeapon()->AddGunshell(this, gunshellPos, gunshellRot, 0.025f); } } -#ifdef VC_PED_PORTS + + // TODO(Miami): CSpecialFX::AddWeaponStreak + + // Anim breakout on running if (IsPlayer()) { if (CPad::GetPad(0)->GetSprint()) { - // animBreakout is a member of WeaponInfo in VC, so it's me that added the below line. - float animBreakOut = ((ourWeaponType == WEAPONTYPE_FLAMETHROWER || ourWeaponType == WEAPONTYPE_UZI || ourWeaponType == WEAPONTYPE_SHOTGUN) ? 25 / 30.0f : 99 / 30.0f); - if (!attackShouldContinue && weaponAnimAssoc->currentTime > animBreakOut) { + if (!attackShouldContinue && weaponAnimAssoc->currentTime > ourWeapon->m_fAnimBreakout) { weaponAnimAssoc->blendDelta = -4.0f; FinishedAttackCB(nil, this); return; } } } -#endif - animLoopEnd = ourWeapon->m_fAnimLoopEnd; - if (ourWeaponFire == WEAPON_FIRE_MELEE && weaponAnimAssoc->animId == ourWeapon->m_Anim2ToPlay) - animLoopEnd = 3.4f/6.0f; weaponAnimTime = weaponAnimAssoc->currentTime; // Anim loop end, either start the loop again or finish the attack if (weaponAnimTime > animLoopEnd || !weaponAnimAssoc->IsRunning() && ourWeaponFire != WEAPON_FIRE_PROJECTILE) { - + if (GetWeapon()->m_eWeaponState == WEAPONSTATE_RELOADING) { + if (ourWeapon->m_bReload && !reloadAnimAssoc) { + if (!CWorld::Players[CWorld::PlayerInFocus].m_bFastReload) { + CAnimBlendAssociation *newReloadAssoc; + if (bIsDucking) { + newReloadAssoc = CAnimManager::BlendAnimation( + GetClump(), ourWeapon->m_AnimToPlay, + GetCrouchReloadAnim(ourWeapon), + 8.0f); + } else { + newReloadAssoc = CAnimManager::BlendAnimation( + GetClump(), ourWeapon->m_AnimToPlay, + GetReloadAnim(ourWeapon), + 8.0f); + } + newReloadAssoc->SetFinishCallback(FinishedReloadCB, this); + } + ClearLookFlag(); + ClearAimFlag(); + bIsAttacking = false; + bIsPointingGunAt = false; + m_shootTimer = CTimer::GetTimeInMilliseconds(); +#ifdef AUDIO_NOT_READY + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_AK47_BULLET_ECHO, 0.0f); +#else + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_AK47_BULLET_ECHO, GetWeapon()->m_eWeaponType); +#endif + return; + } + } if (weaponAnimTime - 2.0f * weaponAnimAssoc->timeStep <= animLoopEnd && (bIsAttacking || CTimer::GetTimeInMilliseconds() < m_shootTimer) - && GetWeapon()->m_eWeaponState != WEAPONSTATE_RELOADING) { + && (GetWeapon()->m_eWeaponState != WEAPONSTATE_RELOADING + || GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN)) { - weaponAnim = weaponAnimAssoc->animId; - if (ourWeaponFire != WEAPON_FIRE_MELEE || CheckForPedsOnGroundToAttack(this, nil) < PED_ON_THE_FLOOR) { - if (weaponAnim != ourWeapon->m_Anim2ToPlay || weaponAnim == ANIM_RBLOCK_CSHOOT) { - weaponAnimAssoc->Start(ourWeapon->m_fAnimLoopStart); + PedOnGroundState pedOnGroundState; + if (ourWeapon->m_eWeaponFire == WEAPON_FIRE_MELEE && + (CGame::nastyGame && ((pedOnGroundState = CheckForPedsOnGroundToAttack(this, nil)) > PED_IN_FRONT_OF_ATTACKER) + || ourWeaponType == WEAPONTYPE_BASEBALLBAT && pedOnGroundState == NO_PED && bIsStanding && m_pCurSurface && m_pCurSurface->IsVehicle())) { + + AnimationId fireAnim = GetFireAnimGround(ourWeapon, false); + if (weaponAnimAssoc->animId == fireAnim) + weaponAnimAssoc->SetCurrentTime(0.1f); + else { + if (fireAnim) { + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ourWeapon->m_AnimToPlay, fireAnim, 8.0f); + } else { + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_KICK_FLOOR, 8.0f); + } + } + weaponAnimAssoc->SetFinishCallback(FinishedAttackCB, this); + } else if (!!ourWeapon->m_bUse2nd) { + if (weaponAnimAssoc->animId == GetSecondFireAnim(ourWeapon)) { + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ourWeapon->m_AnimToPlay, ANIM_WEAPON_FIRE, 8.0f); } else { - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ourWeapon->m_AnimToPlay, 8.0f); + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ourWeapon->m_AnimToPlay, GetSecondFireAnim(ourWeapon), 8.0f); } + weaponAnimAssoc->SetFinishCallback(FinishedAttackCB, this); } else { - if (weaponAnim == ourWeapon->m_Anim2ToPlay) - weaponAnimAssoc->SetCurrentTime(0.1f); - else - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ourWeapon->m_Anim2ToPlay, 8.0f); + weaponAnimAssoc->SetCurrentTime(animLoopStart); + weaponAnimAssoc->SetRun(); } -#ifdef VC_PED_PORTS - } else if (IsPlayer() && m_pPointGunAt && bIsAimingGun && GetWeapon()->m_eWeaponState != WEAPONSTATE_RELOADING) { - weaponAnimAssoc->SetCurrentTime(ourWeapon->m_fAnimLoopEnd); - weaponAnimAssoc->flags &= ~ASSOC_RUNNING; - SetPointGunAt(m_pPointGunAt); -#endif - } else { - ClearAimFlag(); + } + } else if (IsPlayer() && m_pPointGunAt && bIsAimingGun && GetWeapon()->m_eWeaponState != WEAPONSTATE_RELOADING) { + weaponAnimAssoc->SetCurrentTime(animLoopEnd); + weaponAnimAssoc->flags &= ~ASSOC_RUNNING; + SetPointGunAt(m_pPointGunAt); + } else { + ClearAimFlag(); - // Echoes of bullets, at the end of the attack. (Bug: doesn't play while reloading) - if (weaponAnimAssoc->currentTime - weaponAnimAssoc->timeStep <= ourWeapon->m_fAnimLoopEnd) { - switch (ourWeaponType) { - case WEAPONTYPE_UZI: - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_UZI_BULLET_ECHO, 0.0f); - break; - case WEAPONTYPE_AK47: - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_AK47_BULLET_ECHO, 0.0f); - break; - case WEAPONTYPE_M16: - DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_M16_BULLET_ECHO, 0.0f); - break; - default: - break; - } - } + // Echoes of bullets, at the end of the attack. (Bug: doesn't play while reloading) + if (weaponAnimAssoc->currentTime - weaponAnimAssoc->timeStep < animLoopEnd) { - // Fun fact: removing this part leds to reloading flamethrower - if (ourWeaponType == WEAPONTYPE_FLAMETHROWER && weaponAnimAssoc->IsRunning()) { - weaponAnimAssoc->flags |= ASSOC_DELETEFADEDOUT; - weaponAnimAssoc->flags &= ~ASSOC_RUNNING; - weaponAnimAssoc->blendDelta = -4.0f; - } +#ifdef AUDIO_NOT_READY + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_AK47_BULLET_ECHO, 0.0f); +#else + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_AK47_BULLET_ECHO, ourWeaponType); +#endif + } + + // Fun fact: removing this part leds to reloading flamethrower + if (ourWeaponType == WEAPONTYPE_FLAMETHROWER && weaponAnimAssoc->IsRunning()) { + weaponAnimAssoc->flags |= ASSOC_DELETEFADEDOUT; + weaponAnimAssoc->flags &= ~ASSOC_RUNNING; + weaponAnimAssoc->blendDelta = -4.0f; } } + if (weaponAnimAssoc->currentTime > delayBetweenAnimAndFire) attackShouldContinue = false; bIsAttacking = attackShouldContinue; } +// --MIAMI: Done void CPed::RemoveWeaponModel(int modelId) { @@ -1174,40 +1554,74 @@ CPed::RemoveWeaponModel(int modelId) #ifdef PED_SKIN if(IsClumpSkinned(GetClump())){ if(m_pWeaponModel){ - RwFrame *frm = RpAtomicGetFrame(m_pWeaponModel); - RpAtomicDestroy(m_pWeaponModel); - RwFrameDestroy(frm); - m_pWeaponModel = nil; + if (modelId == -1 + || CVisibilityPlugins::GetAtomicModelInfo(m_pWeaponModel) == CModelInfo::GetModelInfo(modelId)) { + CVisibilityPlugins::GetAtomicModelInfo(m_pWeaponModel)->RemoveRef(); + RwFrame* frm = RpAtomicGetFrame(m_pWeaponModel); + RpAtomicDestroy(m_pWeaponModel); + RwFrameDestroy(frm); + m_pWeaponModel = nil; + } } }else #endif RwFrameForAllObjects(m_pFrames[PED_HANDR]->frame,RemoveAllModelCB,nil); + + if (IsPlayer() && (modelId == -1 || modelId == MI_MINIGUN)) { + RpAtomic* &atm = ((CPlayerPed*)this)->m_pMinigunTopAtomic; + if (atm) { + RwFrame *frm = RpAtomicGetFrame(atm); + RpAtomicDestroy(atm); + RwFrameDestroy(frm); + atm = nil; + } + } m_wepModelID = -1; } +// --MIAMI: Done void -CPed::SetCurrentWeapon(uint32 weaponType) +CPed::SetCurrentWeapon(eWeaponType weaponType) { - CWeaponInfo *weaponInfo; - if (HasWeapon(weaponType)) { + SetCurrentWeapon(CWeaponInfo::GetWeaponInfo(weaponType)->m_nWeaponSlot); +} + +// --MIAMI: Done +void +CPed::SetCurrentWeapon(int slot) +{ + if (slot == -1) + return; + + CWeaponInfo* weaponInfo; + if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED) { weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); RemoveWeaponModel(weaponInfo->m_nModelId); + } + m_currentWeapon = slot; - m_currentWeapon = weaponType; + if (FindPlayerPed() && IsPlayer()) + ((CPlayerPed*)this)->m_nSelectedWepSlot = m_currentWeapon; + if (HasWeaponSlot(slot)) { weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); AddWeaponModel(weaponInfo->m_nModelId); } } +// --MIAMI: Done // Only used while deciding which gun ped should switch to, if no ammo left. bool CPed::SelectGunIfArmed(void) { - for (int i = 0; i < m_maxWeaponTypeAllowed; i++) { + for (int i = 0; i < TOTAL_WEAPON_SLOTS; i++) { if (GetWeapon(i).m_nAmmoTotal > 0) { eWeaponType weaponType = GetWeapon(i).m_eWeaponType; - if (weaponType >= WEAPONTYPE_COLT45 && weaponType != WEAPONTYPE_M16 && weaponType <= WEAPONTYPE_FLAMETHROWER) { + + // First condition checks for Pistol, Python and Shotguns + if ((weaponType >= WEAPONTYPE_COLT45 && weaponType < WEAPONTYPE_TEC9) || + weaponType == WEAPONTYPE_UZI || weaponType == WEAPONTYPE_M4 || weaponType == WEAPONTYPE_MP5 || + weaponType == WEAPONTYPE_ROCKETLAUNCHER || weaponType == WEAPONTYPE_FLAMETHROWER || weaponType == WEAPONTYPE_SNIPERRIFLE) { SetCurrentWeapon(i); return true; } @@ -1217,38 +1631,53 @@ CPed::SelectGunIfArmed(void) return false; } +// --MIAMI: Done void CPed::Duck(void) { if (CTimer::GetTimeInMilliseconds() > m_duckTimer) ClearDuck(); + else if (bIsDucking && bCrouchWhenShooting) { + CWeaponInfo *weapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + CAnimBlendAssociation *attackAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCH); + if (!attackAssoc) { + if(!!weapon->m_bCrouchFire) + attackAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchFireAnim(weapon)); + } + if (!attackAssoc) { + if(!!weapon->m_bReload) + attackAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchReloadAnim(weapon)); + } + if (!attackAssoc) { + bIsDucking = false; + } + } } +// --MIAMI: Done void -CPed::ClearDuck(void) +CPed::ClearDuck(bool clearTimer) { CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN); if (!animAssoc) { animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_LOW); - - if (!animAssoc) { - bIsDucking = false; - return; - } + } + if (!animAssoc) { + animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCH); } - if (!bCrouchWhenShooting) - return; - - if (m_nPedState != PED_ATTACK && m_nPedState != PED_AIM_GUN) - return; + if (animAssoc) { + animAssoc->flags |= ASSOC_DELETEFADEDOUT; + animAssoc->blendDelta = -4.0f; + } + bIsDucking = false; - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RBLOCK_CSHOOT); - if (!animAssoc || animAssoc->blendDelta < 0.0f) { - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_RBLOCK_CSHOOT, 4.0f); + if (clearTimer) { + m_duckTimer = 0; } } +// --MIAMI: Done void CPed::ClearPointGunAt(void) { @@ -1258,88 +1687,87 @@ CPed::ClearPointGunAt(void) ClearLookFlag(); ClearAimFlag(); bIsPointingGunAt = false; -#ifndef VC_PED_PORTS - if (m_nPedState == PED_AIM_GUN) { - RestorePreviousState(); -#else if (m_nPedState == PED_AIM_GUN || m_nPedState == PED_ATTACK) { - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); RestorePreviousState(); } -#endif - weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), weaponInfo->m_AnimToPlay); - if (!animAssoc || animAssoc->blendDelta < 0.0f) { - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), weaponInfo->m_Anim2ToPlay); - } - if (animAssoc) { - animAssoc->flags |= ASSOC_DELETEFADEDOUT; - animAssoc->blendDelta = -4.0f; + weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_FIRE); + if (!animAssoc || animAssoc->blendDelta < 0.0f) { + if (!!weaponInfo->m_bCrouchFire) { + animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchFireAnim(weaponInfo)); } -#ifndef VC_PED_PORTS } -#endif + if (animAssoc) { + animAssoc->flags |= ASSOC_DELETEFADEDOUT; + animAssoc->blendDelta = -4.0f; + } } +// --MIAMI: Done void CPed::BeingDraggedFromCar(void) { - CAnimBlendAssociation *animAssoc; AnimationId enterAnim; bool dontRunAnim = false; - PedLineUpPhase lineUpType; if (!m_pVehicleAnim) { CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 100.0f); - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SIT); - if (!animAssoc) { - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LSIT); - if (!animAssoc) { - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SITP); - if (!animAssoc) - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SITPLO); - } - } - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - if (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR) { - if (bWillBeQuickJacked) { - enterAnim = ANIM_CAR_QJACKED; - } else if (m_pMyVehicle->bLowVehicle) { - enterAnim = ANIM_CAR_LJACKED_LHS; - } else { - enterAnim = ANIM_CAR_JACKED_LHS; - } - } else if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) { - if (m_pMyVehicle->bLowVehicle) - enterAnim = ANIM_CAR_LJACKED_RHS; - else - enterAnim = ANIM_CAR_JACKED_RHS; - } else - dontRunAnim = true; + AssocGroupId assocGroup; + if (m_pMyVehicle->IsBike()) { + enterAnim = ANIM_BIKE_HIT; + assocGroup = ((CBike*)m_pMyVehicle)->m_bikeAnimType; + + } else { + if (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR) { + if (bWillBeQuickJacked && m_vehEnterType == CAR_DOOR_LF) { + enterAnim = ANIM_CAR_QJACKED; + } else if (m_pMyVehicle->bLowVehicle) { + enterAnim = ANIM_CAR_LJACKED_LHS; + } else { + enterAnim = ANIM_CAR_JACKED_LHS; + } + } else if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) { + if (m_pMyVehicle->bLowVehicle) + enterAnim = ANIM_CAR_LJACKED_RHS; + else + enterAnim = ANIM_CAR_JACKED_RHS; + } else + dontRunAnim = true; + assocGroup = ASSOCGRP_STD; + } if (!dontRunAnim) - m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, enterAnim); + m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), assocGroup, enterAnim); m_pVehicleAnim->SetFinishCallback(PedSetDraggedOutCarCB, this); - lineUpType = LINE_UP_TO_CAR_START; + + if (m_pMyVehicle && m_pMyVehicle->IsBike()) { + LineUpPedWithCar(LINE_UP_TO_CAR_FALL); + } else { + LineUpPedWithCar(LINE_UP_TO_CAR_START); + } + return; + + } else if (m_pVehicleAnim->animId == ANIM_BIKE_HIT) { + LineUpPedWithCar(LINE_UP_TO_CAR_FALL); + } else if (m_pVehicleAnim->currentTime <= 1.4f) { m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - lineUpType = LINE_UP_TO_CAR_START; + LineUpPedWithCar(LINE_UP_TO_CAR_START); + } else { - lineUpType = LINE_UP_TO_CAR_2; + LineUpPedWithCar(LINE_UP_TO_CAR_2); } - - LineUpPedWithCar(lineUpType); -#ifdef VC_PED_PORTS + + static float mult = 5.f; if (m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) { if (m_pMyVehicle) { - m_pMyVehicle->ProcessOpenDoor(m_vehEnterType, NUM_ANIMS, m_pVehicleAnim->currentTime * 5.0f); + m_pMyVehicle->ProcessOpenDoor(m_vehEnterType, NUM_STD_ANIMS, m_pVehicleAnim->currentTime * mult); } } -#endif } void @@ -1372,7 +1800,10 @@ CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg) vehicle = ped->m_pMyVehicle; if (vehicle) { - vehicle->m_nGettingOutFlags &= ~GetCarDoorFlag(ped->m_vehEnterType); + if(vehicle->IsBike()) + vehicle->m_nGettingOutFlags &= ~GetBikeDoorFlag(ped->m_vehEnterType); + else + vehicle->m_nGettingOutFlags &= ~GetCarDoorFlag(ped->m_vehEnterType); if (vehicle->pDriver == ped) { vehicle->RemoveDriver(); @@ -1412,6 +1843,7 @@ CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg) ped->bVehExitWillBeInstant = false; } +// --MIAMI: Done CVector CPed::GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float seatPosMult) { @@ -1421,88 +1853,144 @@ CPed::GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float seatP float seatOffset; vehModel = (CVehicleModelInfo *)CModelInfo::GetModelInfo(veh->GetModelIndex()); - if (veh->bIsVan && (component == CAR_DOOR_LR || component == CAR_DOOR_RR)) { - seatOffset = 0.0f; - vehDoorOffset = vecPedVanRearDoorAnimOffset; + + if (veh->IsBike()) { + CBike *bike = (CBike*)veh; + vehDoorPos = vehModel->GetFrontSeatPosn(); + + if (component == CAR_WINDSCREEN) { + return bike->GetMatrix() * (vehDoorPos + vecPedBikeKickAnimOffset); + } else { + switch (bike->m_bikeAnimType) { + case ASSOCGRP_BIKE_VESPA: + vehDoorOffset = vecPedVespaBikeJumpRhsAnimOffset; + break; + case ASSOCGRP_BIKE_HARLEY: + vehDoorOffset = vecPedHarleyBikeJumpRhsAnimOffset; + break; + case ASSOCGRP_BIKE_DIRT: + vehDoorOffset = vecPedDirtBikeJumpRhsAnimOffset; + break; + default: + vehDoorOffset = vecPedStdBikeJumpRhsAnimOffset; + break; + } + float xOffsetFromAnim = vehDoorOffset.x + seatPosMult * bike->pHandling->fSeatOffsetDistance; + if (component == CAR_DOOR_LR || component == CAR_DOOR_RR) { + vehDoorPos = vehModel->m_positions[CAR_POS_BACKSEAT]; + } + + if (component == CAR_DOOR_LR || component == CAR_DOOR_LF) + xOffsetFromAnim *= -1.f; + + return bike->GetMatrix() * (vehDoorPos + CVector(xOffsetFromAnim, vehDoorOffset.y, vehDoorOffset.z)); + } } else { - seatOffset = veh->pHandling->fSeatOffsetDistance * seatPosMult; - if (veh->bLowVehicle) { - vehDoorOffset = vecPedCarDoorLoAnimOffset; + if (veh->bIsVan && (component == CAR_DOOR_LR || component == CAR_DOOR_RR)) { + seatOffset = 0.0f; + vehDoorOffset = vecPedVanRearDoorAnimOffset; } else { - vehDoorOffset = vecPedCarDoorAnimOffset; + seatOffset = veh->pHandling->fSeatOffsetDistance * seatPosMult; + if (veh->bLowVehicle) { + vehDoorOffset = vecPedCarDoorLoAnimOffset; + } else { + vehDoorOffset = vecPedCarDoorAnimOffset; + } } - } - switch (component) { - case CAR_DOOR_RF: - vehDoorPos = vehModel->GetFrontSeatPosn(); - vehDoorPos.x += seatOffset; - vehDoorOffset.x = -vehDoorOffset.x; - break; + switch (component) { + case CAR_DOOR_RF: + vehDoorPos = vehModel->GetFrontSeatPosn(); + vehDoorPos.x += seatOffset; + vehDoorOffset.x = -vehDoorOffset.x; + break; - case CAR_DOOR_RR: - vehDoorPos = vehModel->m_positions[CAR_POS_BACKSEAT]; - vehDoorPos.x += seatOffset; - vehDoorOffset.x = -vehDoorOffset.x; - break; + case CAR_DOOR_RR: + vehDoorPos = vehModel->m_positions[CAR_POS_BACKSEAT]; + vehDoorPos.x += seatOffset; + vehDoorOffset.x = -vehDoorOffset.x; + break; - case CAR_DOOR_LF: - vehDoorPos = vehModel->GetFrontSeatPosn(); - vehDoorPos.x = -(vehDoorPos.x + seatOffset); - break; + case CAR_DOOR_LF: + vehDoorPos = vehModel->GetFrontSeatPosn(); + vehDoorPos.x = -(vehDoorPos.x + seatOffset); + break; - case CAR_DOOR_LR: - vehDoorPos = vehModel->m_positions[CAR_POS_BACKSEAT]; - vehDoorPos.x = -(vehDoorPos.x + seatOffset); - break; + case CAR_DOOR_LR: + vehDoorPos = vehModel->m_positions[CAR_POS_BACKSEAT]; + vehDoorPos.x = -(vehDoorPos.x + seatOffset); + break; - default: - vehDoorPos = vehModel->GetFrontSeatPosn(); - vehDoorOffset = CVector(0.0f, 0.0f, 0.0f); + default: + vehDoorPos = vehModel->GetFrontSeatPosn(); + vehDoorOffset = CVector(0.0f, 0.0f, 0.0f); + } + return vehDoorPos - vehDoorOffset; } - return vehDoorPos - vehDoorOffset; } -// This function was mostly duplicate of GetLocalPositionToOpenCarDoor, so I've used it. +// --MIAMI: Done CVector CPed::GetPositionToOpenCarDoor(CVehicle *veh, uint32 component) { - CVector localPos; - CVector vehDoorPos; - - localPos = GetLocalPositionToOpenCarDoor(veh, component, 1.0f); - vehDoorPos = Multiply3x3(veh->GetMatrix(), localPos) + veh->GetPosition(); + CVector vehDoorPos = GetPositionToOpenCarDoor(veh, component, 1.0f); /* - // Not used. - CVector localVehDoorOffset; - - if (veh->bIsVan && (component == VEHICLE_ENTER_REAR_LEFT || component == VEHICLE_ENTER_REAR_RIGHT)) { - localVehDoorOffset = vecPedVanRearDoorAnimOffset; - } else { - if (veh->bIsLow) { - localVehDoorOffset = vecPedCarDoorLoAnimOffset; - } else { - localVehDoorOffset = vecPedCarDoorAnimOffset; - } - } - - vehDoorPosWithoutOffset = Multiply3x3(veh->GetMatrix(), localPos + localVehDoorOffset) + veh->GetPosition(); + // Unused + vehDoorPosWithoutOffset = veh->GetMatrix() * localVehDoorPos; */ return vehDoorPos; } +// --MIAMI: Done CVector CPed::GetPositionToOpenCarDoor(CVehicle *veh, uint32 component, float offset) { CVector doorPos; CMatrix vehMat(veh->GetMatrix()); + if (veh->IsBike()) { + CVehicleModelInfo* vehModel = (CVehicleModelInfo*)CModelInfo::GetModelInfo(veh->GetModelIndex()); + CVector vehDoorOffset; + CBike* bike = (CBike*)veh; + doorPos = vehModel->GetFrontSeatPosn(); + + if (component == CAR_WINDSCREEN) { + return bike->GetMatrix() * (doorPos + vecPedBikeKickAnimOffset); + } else { + switch (bike->m_bikeAnimType) { + case ASSOCGRP_BIKE_VESPA: + vehDoorOffset = vecPedVespaBikeJumpRhsAnimOffset; + break; + case ASSOCGRP_BIKE_HARLEY: + vehDoorOffset = vecPedHarleyBikeJumpRhsAnimOffset; + break; + case ASSOCGRP_BIKE_DIRT: + vehDoorOffset = vecPedDirtBikeJumpRhsAnimOffset; + break; + default: + vehDoorOffset = vecPedStdBikeJumpRhsAnimOffset; + break; + } + vehDoorOffset.x += offset * bike->pHandling->fSeatOffsetDistance; + if (component == CAR_DOOR_LR || component == CAR_DOOR_RR) { + doorPos = vehModel->m_positions[CAR_POS_BACKSEAT]; + } + + if (component == CAR_DOOR_LR || component == CAR_DOOR_LF) + vehDoorOffset.x *= -1.f; + + CVector correctedPos; + bike->GetCorrectedWorldDoorPosition(correctedPos, vehDoorOffset, doorPos); + return correctedPos; + } + } doorPos = Multiply3x3(vehMat, GetLocalPositionToOpenCarDoor(veh, component, offset)); return veh->GetPosition() + doorPos; } +// --MIAMI: Done void CPed::LineUpPedWithCar(PedLineUpPhase phase) { @@ -1511,29 +1999,59 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) float seatPosMult = 0.0f; float currentZ; float adjustedTimeStep; + CVector autoZPos; if (CReplay::IsPlayingBack()) return; if (!bChangedSeat && phase != LINE_UP_TO_CAR_2) { - if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SIT)) { - SetPedPositionInCar(); - return; - } - if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LSIT)) { - SetPedPositionInCar(); - return; - } - if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SITP)) { - SetPedPositionInCar(); - return; - } - if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SITPLO)) { - SetPedPositionInCar(); - return; + if (m_pMyVehicle->IsBike()) { + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_RIDE) || + RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_PASSENGER)) { + SetPedPositionInCar(); + return; + } + } else { + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SIT)) { + SetPedPositionInCar(); + return; + } + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LSIT)) { + SetPedPositionInCar(); + return; + } + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SITP)) { + SetPedPositionInCar(); + return; + } + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SITPLO)) { + SetPedPositionInCar(); + return; + } } bChangedSeat = true; } + if (phase == LINE_UP_TO_CAR_FALL) { + SetPedPositionInCar(); + autoZPos = GetPosition(); + CPedPlacement::FindZCoorForPed(&autoZPos); + if (m_pVehicleAnim && (m_pVehicleAnim->animId == ANIM_CAR_ROLLOUT_LHS || m_pVehicleAnim->animId == ANIM_CAR_ROLLOUT_RHS) + && autoZPos.z > GetPosition().z) { + m_matrix.GetPosition().z = autoZPos.z; + } + if (m_pVehicleAnim && m_pVehicleAnim->animId == ANIM_BIKE_HIT) { + if (autoZPos.z > GetPosition().z) + m_matrix.GetPosition().z += m_pVehicleAnim->GetProgress() * (autoZPos.z - GetPosition().z); + + } else if (m_pVehicleAnim) { + if (m_pVehicleAnim->animId == ANIM_BIKE_GETOFF_BACK) { + if (autoZPos.z > GetPosition().z) { + m_matrix.GetPosition().z += (m_pVehicleAnim->currentTime * (20.f / 7.f)) * (autoZPos.z - GetPosition().z); + } + } + } + return; + } if (phase == LINE_UP_TO_CAR_START) { m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); } @@ -1571,14 +2089,9 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) } } - if (!bInVehicle) - seatPosMult = 1.0f; - -#ifdef VC_PED_PORTS bool multExtractedFromAnim = false; bool multExtractedFromAnimBus = false; float zBlend; -#endif if (m_pVehicleAnim) { vehAnim = m_pVehicleAnim->animId; @@ -1589,38 +2102,38 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) case ANIM_CAR_LJACKED_LHS: case ANIM_VAN_GETIN_L: case ANIM_VAN_GETIN: -#ifdef VC_PED_PORTS multExtractedFromAnim = true; - zBlend = Max(m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength - 0.3f, 0.0f) / (1.0f - 0.3f); + zBlend = Max(m_pVehicleAnim->GetProgress() - 0.3f, 0.0f) / (1.0f - 0.3f); // fall through -#endif + case ANIM_CAR_QJACKED: case ANIM_CAR_GETOUT_LHS: case ANIM_CAR_GETOUT_LOW_LHS: case ANIM_CAR_GETOUT_RHS: case ANIM_CAR_GETOUT_LOW_RHS: -#ifdef VC_PED_PORTS + if (!multExtractedFromAnim) { multExtractedFromAnim = true; - zBlend = Max(m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength - 0.5f, 0.0f) / (1.0f - 0.5f); + zBlend = Max(m_pVehicleAnim->GetProgress() - 0.5f, 0.0f) / (1.0f - 0.5f); } // fall through -#endif + case ANIM_CAR_CRAWLOUT_RHS: case ANIM_CAR_CRAWLOUT_RHS2: case ANIM_VAN_GETOUT_L: case ANIM_VAN_GETOUT: - seatPosMult = m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength; + case ANIM_BIKE_GETOFF_RHS: + case ANIM_BIKE_GETOFF_LHS: + seatPosMult = m_pVehicleAnim->GetProgress(); break; case ANIM_CAR_GETIN_RHS: case ANIM_CAR_GETIN_LHS: -#ifdef VC_PED_PORTS if (veh && veh->IsCar() && veh->bIsBus) { multExtractedFromAnimBus = true; - zBlend = Min(m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength, 0.5f) / 0.5f; + zBlend = Min(m_pVehicleAnim->GetProgress(), 0.5f) / 0.5f; } // fall through -#endif + case ANIM_CAR_QJACK: case ANIM_CAR_GETIN_LOW_LHS: case ANIM_CAR_GETIN_LOW_RHS: @@ -1635,6 +2148,12 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) case ANIM_CAR_LSHUFFLE_RHS: seatPosMult = 0.0f; break; + case ANIM_CAR_JUMPIN_LHS: + { + float animLength = m_pVehicleAnim->hierarchy->totalLength; + seatPosMult = Max(0.0f, 0.5f * animLength - m_pVehicleAnim->currentTime) / animLength; + break; + } case ANIM_CAR_CLOSE_LHS: case ANIM_CAR_CLOSE_RHS: case ANIM_COACH_OPEN_L: @@ -1645,8 +2164,25 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) seatPosMult = 1.0f; break; default: + if (veh->IsBike()) { + seatPosMult = 0.0f; + } else { + if (bInVehicle) + seatPosMult = 0.0f; + else + seatPosMult = 1.0f; + } break; } + } else { + if (veh->IsBike()) { + seatPosMult = 0.0f; + } else { + if (bInVehicle) + seatPosMult = 0.0f; + else + seatPosMult = 1.0f; + } } CVector neededPos; @@ -1657,7 +2193,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) neededPos = GetPositionToOpenCarDoor(veh, m_vehEnterType, seatPosMult); } - CVector autoZPos = neededPos; + autoZPos = neededPos; if (veh->bIsInWater) { if (veh->m_vehType == VEHICLE_TYPE_BOAT && veh->IsUpsideDown()) @@ -1687,11 +2223,24 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) } if (autoZPos.z > neededPos.z) { -#ifdef VC_PED_PORTS - if (multExtractedFromAnim) { + vehAnim = m_pVehicleAnim->animId; + if (veh->IsBike() && (m_pVehicleAnim && vehAnim != ANIM_BIKE_KICK)) { + float zBlend; + if (vehAnim != ANIM_BIKE_GETOFF_RHS && vehAnim != ANIM_BIKE_GETOFF_LHS) { + if (vehAnim != ANIM_BIKE_JUMPON_R && vehAnim != ANIM_BIKE_JUMPON_L) { + zBlend = 0.0f; + } else { + float animLength = m_pVehicleAnim->hierarchy->totalLength; + zBlend = Min(1.0f, 2.0f * m_pVehicleAnim->currentTime / animLength); + } + } else { + zBlend = 1.0f - seatPosMult; + } + float curZ = veh->GetPosition().z + FEET_OFFSET; + neededPos.z = ((curZ - autoZPos.z) - veh->GetHeightAboveRoad()) * zBlend + autoZPos.z; + } else if (multExtractedFromAnim) { neededPos.z += (autoZPos.z - neededPos.z) * zBlend; } else { -#endif currentZ = GetPosition().z; if (m_pVehicleAnim && vehAnim != ANIM_VAN_GETIN_L && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE && vehAnim != ANIM_VAN_GETIN) { neededPos.z = autoZPos.z; @@ -1702,20 +2251,16 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) // Smoothly change ped position neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep); } -#ifdef VC_PED_PORTS } -#endif } else { // We may need to raise up the ped if (phase == LINE_UP_TO_CAR_START) { currentZ = GetPosition().z; if (neededPos.z > currentZ) { -#ifdef VC_PED_PORTS if (multExtractedFromAnimBus) { neededPos.z = (neededPos.z - currentZ) * zBlend + currentZ; } else { -#endif if (m_pVehicleAnim && (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) { @@ -1723,12 +2268,10 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) // Smoothly change ped position neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ; - } else if (EnteringCar()) { + } else if (EnteringCar() || m_nPedState == PED_DRIVING && veh->IsBike()) { neededPos.z = Max(currentZ, autoZPos.z); } -#ifdef VC_PED_PORTS } -#endif } } } @@ -1759,19 +2302,31 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) m_fRotationCur -= (m_fRotationCur - limitedDest) * (1.0f - timeUntilStateChange); } - if (seatPosMult > 0.2f || vehIsUpsideDown) { + if (seatPosMult > 0.2f || vehIsUpsideDown || veh->IsBike()) { SetPosition(neededPos); SetHeading(m_fRotationCur); } else { CMatrix vehDoorMat(veh->GetMatrix()); vehDoorMat.GetPosition() += Multiply3x3(vehDoorMat, GetLocalPositionToOpenCarDoor(veh, m_vehEnterType, 0.0f)); - // VC couch anims are inverted, so they're fixing it here. + + if (m_vehEnterType == CAR_WINDSCREEN || veh->bIsBus) { + CMatrix correctionMat; + if (veh->bIsBus && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) + correctionMat.SetRotateZ(-HALFPI); + else if (veh->bIsBus && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) + correctionMat.SetRotateZ(HALFPI); + else + correctionMat.SetRotateZ(PI); + + vehDoorMat = vehDoorMat * correctionMat; + } GetMatrix() = vehDoorMat; } } +// --MIAMI: Done static void particleProduceFootDust(CPed *ped, CVector const &pos, float size, int times) { @@ -1781,10 +2336,15 @@ particleProduceFootDust(CPed *ped, CVector const &pos, float size, int times) case SURFACE_GRAVEL: case SURFACE_PAVEMENT: case SURFACE_SAND: + case SURFACE_SAND_BEACH: + case SURFACE_CONCRETE_BEACH: for (int i = 0; i < times; ++i) { CVector adjustedPos = pos; adjustedPos.x += CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); adjustedPos.y += CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); + // ?? + CGeneral::GetRandomNumber(); + CGeneral::GetRandomNumber(); CParticle::AddParticle(PARTICLE_PEDFOOT_DUST, adjustedPos, CVector(0.0f, 0.0f, 0.0f), nil, size, CRGBA(0, 0, 0, 0), 0, 0, 0, 0); } break; @@ -1793,10 +2353,10 @@ particleProduceFootDust(CPed *ped, CVector const &pos, float size, int times) } } +// --MIAMI: Done static void particleProduceFootSplash(CPed *ped, CVector const &pos, float size, int times) { -#ifdef PC_PARTICLE for (int i = 0; i < times; i++) { CVector adjustedPos = pos; adjustedPos.x += CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); @@ -1805,21 +2365,20 @@ particleProduceFootSplash(CPed *ped, CVector const &pos, float size, int times) CVector direction = ped->GetForward() * -0.05f; CParticle::AddParticle(PARTICLE_RAIN_SPLASHUP, adjustedPos, direction, nil, size, CRGBA(32, 32, 32, 32), 0, 0, CGeneral::GetRandomNumber() & 1, 200); } -#else - for ( int32 i = 0; i < times; i++ ) - { - CVector adjustedPos = pos; - adjustedPos.x += CGeneral::GetRandomNumberInRange(-0.2f, 0.2f); - adjustedPos.y += CGeneral::GetRandomNumberInRange(-0.2f, 0.2f); - - CParticle::AddParticle(PARTICLE_RAIN_SPLASHUP, adjustedPos, CVector(0.0f, 0.0f, 0.0f), nil, size, CRGBA(0, 0, 0, 0), 0, 0, CGeneral::GetRandomNumber() & 1, 200); - } -#endif } +// --MIAMI: Done void CPed::PlayFootSteps(void) { + CAnimBlendAssociation *assoc = RpAnimBlendClumpGetFirstAssociation(GetClump()); + CAnimBlendAssociation *walkRunAssoc = nil; + float walkRunAssocBlend = 0.0f, idleAssocBlend = 0.0f; + bool isSkater = m_pedStats == CPedStats::ms_apPedStats[PEDSTAT_SKATER]; + + CVector footPosL(0.0f, 0.0f, 0.0f), footPosR(0.0f, 0.0f, 0.0f); + bool footPosLok = false, footPosRok = false; + if (bDoBloodyFootprints) { if (m_bloodyFootprintCountOrDeathTime > 0 && m_bloodyFootprintCountOrDeathTime < 300) { m_bloodyFootprintCountOrDeathTime--; @@ -1832,10 +2391,6 @@ CPed::PlayFootSteps(void) if (!bIsStanding) return; - CAnimBlendAssociation *assoc = RpAnimBlendClumpGetFirstAssociation(GetClump()); - CAnimBlendAssociation *walkRunAssoc = nil; - float walkRunAssocBlend = 0.0f, idleAssocBlend = 0.0f; - for (; assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) { if (assoc->flags & ASSOC_WALK) { walkRunAssoc = assoc; @@ -1845,96 +2400,200 @@ CPed::PlayFootSteps(void) } } -#ifdef GTA_PS2_STUFF - CAnimBlendAssociation *runStopAsoc = NULL; - - if ( IsPlayer() ) - { - runStopAsoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN_STOP); - - if ( runStopAsoc == NULL ) - runStopAsoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN_STOP_R); - } - - if ( runStopAsoc != NULL && runStopAsoc->blendAmount > 0.1f ) - { - { - CVector pos(0.0f, 0.0f, 0.0f); - TransformToNode(pos, PED_FOOTL); - - pos.z -= 0.1f; - pos += GetForward()*0.2f; - particleProduceFootDust(this, pos, 0.02f, 1); - } - - { - CVector pos(0.0f, 0.0f, 0.0f); - TransformToNode(pos, PED_FOOTR); - - pos.z -= 0.1f; - pos += GetForward()*0.2f; - particleProduceFootDust(this, pos, 0.02f, 1); - } - } -#endif - - if (walkRunAssoc && walkRunAssocBlend > 0.5f && idleAssocBlend < 1.0f) { - float stepStart = 1 / 15.0f; + + float stepStart = 1.f / 15.f; float stepEnd = walkRunAssoc->hierarchy->totalLength / 2.0f + stepStart; float currentTime = walkRunAssoc->currentTime; - int stepPart = 0; - if (currentTime >= stepStart && currentTime - walkRunAssoc->timeStep < stepStart) - stepPart = 1; - else if (currentTime >= stepEnd && currentTime - walkRunAssoc->timeStep < stepEnd) - stepPart = 2; + if (isSkater) { + // both are unused + static float stepStartSection = 1.0f; + static float animSections = 15.f; + + float moveStart, soundVolume, skateTime; + if (walkRunAssoc->animId == ANIM_WALK) { + moveStart = 0.0f; + skateTime = 8.f / 15.f; + } else { + moveStart = 0.0f; + skateTime = 5.f / 15.f; + } + switch (CSurfaceTable::GetAdhesionGroup(m_nSurfaceTouched)) { + case ADHESIVE_LOOSE: + if (CGeneral::GetRandomNumber() % 128) { + m_vecAnimMoveDelta *= 0.5f; + } else { + SetFall(0, ANIM_KO_SKID_BACK, false); + } + soundVolume = 0.5f; + break; + case ADHESIVE_SAND: + if (CGeneral::GetRandomNumber() % 64) { + m_vecAnimMoveDelta *= 0.2f; + } else { + SetFall(0, ANIM_KO_SKID_BACK, false); + } + soundVolume = 0.2f; + break; + case ADHESIVE_WET: + m_vecAnimMoveDelta *= 0.3f; + soundVolume = 0.2f; + break; + default: + soundVolume = 1.f; + break; + } + if (soundVolume > 0.2f && currentTime > moveStart && currentTime - walkRunAssoc->timeStep <= moveStart) { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_SKATING, ((int)(127.f * soundVolume) | (walkRunAssoc->animId << 8))); + } else if (soundVolume > 0.2f) { + if (currentTime > skateTime && currentTime - walkRunAssoc->timeStep <= skateTime) { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_SKATING, ((int)(127.f * soundVolume) | (walkRunAssoc->animId << 8))); + } + } + + } else { + int stepPart = 0; + + // This section is shortened/optimized for sanity. + + if (currentTime >= stepStart && currentTime - walkRunAssoc->timeStep < stepStart) + stepPart = 1; + else if (currentTime >= stepEnd && currentTime - walkRunAssoc->timeStep < stepEnd) + stepPart = 2; + + if (stepPart != 0) { + CVector adjustedFootPos; + if (stepPart == 1) { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_STEP_START, 1.0f); + TransformToNode(footPosL, PED_FOOTL); + footPosLok = true; + adjustedFootPos = footPosL; + } else { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_STEP_END, 1.0f); + TransformToNode(footPosR, PED_FOOTR); + footPosRok = true; + adjustedFootPos = footPosR; + } + + CVector forward = GetForward(); + + adjustedFootPos.z -= 0.1f; + adjustedFootPos += 0.2f * forward; + + if (bDoBloodyFootprints) { + CVector2D top(forward * 0.26f); + CVector2D right(GetRight() * (stepPart == 1 ? 0.14f : 0.1f)); + + CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &adjustedFootPos, + top.x, top.y, + right.x, right.y, + 255, 255, 0, 0, 4.0f, 3000.0f, 1.0f); + + if (m_bloodyFootprintCountOrDeathTime <= 20) { + m_bloodyFootprintCountOrDeathTime = 0; + bDoBloodyFootprints = false; + } else { + m_bloodyFootprintCountOrDeathTime -= 20; + } + } + if (m_nSurfaceTouched == SURFACE_SAND || m_nSurfaceTouched == SURFACE_SAND_BEACH) { + CVector2D top(forward * -0.26f); + CVector2D right(GetRight() * (stepPart == 1 ? 0.1f : 0.14f)); + + CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &adjustedFootPos, + top.x, top.y, + right.x, right.y, + 120, 250, 250, 50, 4.0f, 5000.0f, 1.0f); + } + if (CWeather::Rain <= 0.1f || CCullZones::CamNoRain() || CCullZones::PlayerNoRain()) { + if (IsPlayer()) + particleProduceFootDust(this, adjustedFootPos, 0.0f, 4); + + } else if (stepPart == 2) { + particleProduceFootSplash(this, adjustedFootPos, 0.15f, 4); + } + } + } + } + + if (IsPlayer() && !walkRunAssoc && bIsLanding) { + if (!footPosLok) + TransformToNode(footPosL, PED_FOOTL); - if (stepPart != 0) { - DMAudio.PlayOneShot(m_audioEntityId, stepPart == 1 ? SOUND_STEP_START : SOUND_STEP_END, 1.0f); - CVector footPos(0.0f, 0.0f, 0.0f); - TransformToNode(footPos, stepPart == 1 ? PED_FOOTL : PED_FOOTR); + CVector forward = GetForward(); - CVector forward = GetForward(); + CVector adjustedFootPosL = footPosL; + adjustedFootPosL.z -= 0.1f; + adjustedFootPosL += 0.2f * forward; + if (bDoBloodyFootprints) { + CVector2D top(forward * 0.26f); + CVector2D right(GetRight() * 0.14f); - footPos.z -= 0.1f; - footPos += 0.2f * forward; + CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &adjustedFootPosL, + top.x, top.y, + right.x, right.y, + 255, 255, 0, 0, 4.0f, 3000.0f, 1.0f); - if (bDoBloodyFootprints) { - CVector2D top(forward * 0.26f); + if (m_bloodyFootprintCountOrDeathTime <= 20) { + m_bloodyFootprintCountOrDeathTime = 0; + bDoBloodyFootprints = false; + } + else { + m_bloodyFootprintCountOrDeathTime -= 20; + } + } + if (!isSkater) { + if (m_nSurfaceTouched == SURFACE_SAND || m_nSurfaceTouched == SURFACE_SAND_BEACH) { + CVector2D top(forward * -0.26f); CVector2D right(GetRight() * 0.14f); - CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &footPos, + CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &adjustedFootPosL, top.x, top.y, right.x, right.y, - 255, 255, 0, 0, 4.0f, 3000.0f, 1.0f); - - if (m_bloodyFootprintCountOrDeathTime <= 20) { - m_bloodyFootprintCountOrDeathTime = 0; - bDoBloodyFootprints = false; - } else { - m_bloodyFootprintCountOrDeathTime -= 20; - } + 120, 250, 250, 50, 4.0f, 5000.0f, 1.0f); } - if (CWeather::Rain <= 0.1f || CCullZones::CamNoRain() || CCullZones::PlayerNoRain()) { - if(IsPlayer()) - particleProduceFootDust(this, footPos, 0.0f, 4); + } + if(!footPosRok) + TransformToNode(footPosR, PED_FOOTR); + + CVector adjustedFootPosR = footPosR; + adjustedFootPosR.z -= 0.1f; + adjustedFootPosR += 0.2f * forward; + + if (bDoBloodyFootprints) { + CVector2D top(forward * 0.26f); + CVector2D right(GetRight() * 0.1f); + + CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &adjustedFootPosR, + top.x, top.y, + right.x, right.y, + 255, 255, 0, 0, 4.0f, 3000.0f, 1.0f); + + if (m_bloodyFootprintCountOrDeathTime <= 20) { + m_bloodyFootprintCountOrDeathTime = 0; + bDoBloodyFootprints = false; + } else { + m_bloodyFootprintCountOrDeathTime -= 20; } -#ifdef PC_PARTICLE - else if(stepPart == 2) -#else - else -#endif - { - particleProduceFootSplash(this, footPos, 0.15f, 4); + } + if (!isSkater) { + if (m_nSurfaceTouched == SURFACE_SAND || m_nSurfaceTouched == SURFACE_SAND_BEACH) { + CVector2D top(forward * -0.26f); + CVector2D right(GetRight() * 0.14f); + + CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &adjustedFootPosR, + top.x, top.y, + right.x, right.y, + 120, 250, 250, 50, 4.0f, 5000.0f, 1.0f); } } } if (m_nSurfaceTouched == SURFACE_WATER) { + CRGBA rubberSmokeColor(255, 255, 255, 196); float pedSpeed = CVector2D(m_vecMoveSpeed).Magnitude(); if (pedSpeed > 0.03f && CTimer::GetFrameCounter() % 2 == 0 && pedSpeed > 0.13f) { -#ifdef PC_PARTICLE float particleSize = pedSpeed * 2.0f; if (particleSize < 0.25f) @@ -1949,16 +2608,20 @@ CPed::PlayFootSteps(void) CVector particleDir = m_vecMoveSpeed * -0.75f; particleDir.z = CGeneral::GetRandomNumberInRange(0.01f, 0.03f); - CParticle::AddParticle(PARTICLE_PED_SPLASH, particlePos, particleDir, nil, 0.8f * particleSize, CRGBA(155,155,185,128), 0, 0, 0, 0); + CParticle::AddParticle(PARTICLE_CAR_SPLASH, particlePos, particleDir, nil, 0.5f * particleSize, CRGBA(0,0,0,0), 0, 0, 0, 0); + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, particlePos, particleDir, nil, particleSize, rubberSmokeColor, 0, 0, 0, 0); + } - particleDir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.05f); - CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, particlePos, particleDir, nil, particleSize, CRGBA(255,255,255,255), 0, 0, 0, 0); -#else - CVector particlePos = (GetPosition() - 0.3f * GetUp()) + GetForward()*0.3f; - CVector particleDir = m_vecMoveSpeed * 0.45f; - particleDir.z = CGeneral::GetRandomNumberInRange(0.03f, 0.05f); - CParticle::AddParticle(PARTICLE_PED_SPLASH, particlePos-CVector(0.0f, 0.0f, 1.2f), particleDir, nil, 0.0f, CRGBA(155, 185, 155, 255)); -#endif + if (m_nPedState == PED_JUMP) { + CVector particlePos = GetPosition(); + particlePos.z -= 0.1f; + + CVector particleDir(0.0f, 0.075f, 0.0f); + CParticle::AddParticle(PARTICLE_CAR_SPLASH, particlePos, particleDir, nil, 0.005f, CRGBA(0, 0, 0, 0), 0, 0, 0, 0); + particleDir.x += CGeneral::GetRandomNumberInRange(-0.05f, 0.05f); + particleDir.y += CGeneral::GetRandomNumberInRange(-0.05f, 0.05f); + particleDir.z -= CGeneral::GetRandomNumberInRange(0.025f, 0.05f); + CParticle::AddParticle(PARTICLE_RUBBER_SMOKE, particlePos, particleDir, nil, 0.5f, rubberSmokeColor, 0, 0, 0, 0); } } } @@ -2013,6 +2676,7 @@ CPed::SortPeds(CPed **list, int min, int max) SortPeds(list, right, max); } +// --MIAMI: Done void CPed::BuildPedLists(void) { @@ -2023,10 +2687,12 @@ CPed::BuildPedLists(void) if (m_nearPeds[i]) { if (m_nearPeds[i]->IsPointerValid()) { float distSqr = (GetPosition() - m_nearPeds[i]->GetPosition()).MagnitudeSqr2D(); - if (distSqr > 900.0f) + if (distSqr > sq(nThreatReactionRangeMultiplier * 30.f)) { removePed = true; - } else + } + } else { removePed = true; + } } if (removePed) { // If we arrive here, the ped we're checking isn't "near", so we should remove it. @@ -2036,16 +2702,17 @@ CPed::BuildPedLists(void) } // Above loop won't work when it's 9, so we need to empty slot 9. m_nearPeds[9] = nil; - m_numNearPeds--; + m_numNearPeds--; } else i++; } } else { CVector centre = CEntity::GetBoundCentre(); - CRect rect(centre.x - 20.0f, - centre.y - 20.0f, - centre.x + 20.0f, - centre.y + 20.0f); + int deadsRegistered = 0; + CRect rect(centre.x - 20.f * nThreatReactionRangeMultiplier, + centre.y - 20.f * nThreatReactionRangeMultiplier, + centre.x + 20.f * nThreatReactionRangeMultiplier, + centre.y + 20.f * nThreatReactionRangeMultiplier); int xstart = CWorld::GetSectorIndexX(rect.left); int ystart = CWorld::GetSectorIndexY(rect.top); int xend = CWorld::GetSectorIndexX(rect.right); @@ -2056,9 +2723,14 @@ CPed::BuildPedLists(void) for(int x = xstart; x <= xend; x++) { for (CPtrNode *pedPtrNode = CWorld::GetSector(x,y)->m_lists[ENTITYLIST_PEDS].first; pedPtrNode; pedPtrNode = pedPtrNode->next) { CPed *ped = (CPed*)pedPtrNode->item; - if (ped != this && !ped->bInVehicle) { - float dist = (ped->GetPosition() - GetPosition()).Magnitude2D(); - if (nThreatReactionRangeMultiplier * 30.0f > dist) { + if (ped != this && (!ped->bInVehicle || (ped->m_pMyVehicle && ped->m_pMyVehicle->IsBike()))) { + + if (nThreatReactionRangeMultiplier * 30.0f > (ped->GetPosition() - GetPosition()).Magnitude2D()) { + if (ped->m_nPedState == PED_DEAD) { + if (deadsRegistered > 3) + continue; + deadsRegistered++; + } gapTempPedList[gnNumTempPedList] = ped; gnNumTempPedList++; assert(gnNumTempPedList < ARRAY_SIZE(gapTempPedList)); @@ -2087,6 +2759,18 @@ CPed::SetPedStats(ePedStats pedStat) m_pedStats = CPedStats::ms_apPedStats[pedStat]; } +// --MIAMI: Done +bool +CPed::CanUseTorsoWhenLooking(void) +{ + if (m_nPedState != PED_DRIVING && m_nPedState != PED_DRAG_FROM_CAR && !bIsDucking) { + if (m_animGroup != ASSOCGRP_SEXYWOMAN && m_animGroup != ASSOCGRP_WOMAN) + return true; + } + return false; +} + +// --MIAMI: Done void CPed::SetModelIndex(uint32 mi) { @@ -2099,21 +2783,40 @@ CPed::SetModelIndex(uint32 mi) m_animGroup = (AssocGroupId) modelInfo->m_animGroup; CAnimManager::AddAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE); + if (!CanUseTorsoWhenLooking()) + m_pedIK.m_flags |= CPedIK::LOOKAROUND_HEAD_ONLY; + // This is a mistake by R*, velocity is CVector, whereas m_vecAnimMoveDelta is CVector2D. (*RPANIMBLENDCLUMPDATA(m_rwObject))->velocity = (CVector*) &m_vecAnimMoveDelta; -#ifdef PED_SKIN if(modelInfo->GetHitColModel() == nil) modelInfo->CreateHitColModelSkinned(GetClump()); + + UpdateRpHAnim(); +#ifdef USE_CUTSCENE_SHADOW_FOR_PED + if (!m_pRTShadow) + { + m_pRTShadow = new CCutsceneShadow; + m_pRTShadow->Create(m_rwObject, 10, 1, 1, 1); + //m_pRTShadow->Create(m_rwObject, 8, 0, 0, 0); + } #endif } +// --MIAMI: Done void CPed::RemoveLighting(bool reset) { - CRenderer::RemoveVehiclePedLights(this, reset); + if (!bRenderScorched) { + CRenderer::RemoveVehiclePedLights(this, reset); + if (reset) + ReSetAmbientAndDirectionalColours(); + } + SetAmbientColours(); + DeActivateDirectional(); } +// --MIAMI: Done bool CPed::SetupLighting(void) { @@ -2131,7 +2834,7 @@ CPed::SetupLighting(void) } else { // Note that this lightMult is only affected by LIGHT_DARKEN. If there's no LIGHT_DARKEN, it will be 1.0. float lightMult = CPointLights::GenerateLightsAffectingObject(&GetPosition()); - if (!bHasBlip && lightMult != 1.0f) { + if (lightMult != 1.0f) { SetAmbientAndDirectionalColours(lightMult); return true; } @@ -2139,6 +2842,7 @@ CPed::SetupLighting(void) return false; } +// --MIAMI: Done void CPed::Teleport(CVector pos) { @@ -2152,6 +2856,7 @@ CPed::Teleport(CVector pos) CWorld::Add(this); } +// --MIAMI: Done void CPed::CalculateNewOrientation(void) { @@ -2161,6 +2866,7 @@ CPed::CalculateNewOrientation(void) SetHeading(m_fRotationCur); } +// --MIAMI: Done float CPed::WorkOutHeadingForMovingFirstPerson(float offset) { @@ -2176,14 +2882,15 @@ CPed::WorkOutHeadingForMovingFirstPerson(float offset) angle = CGeneral::GetRadianAngleBetweenPoints(0.0f, 0.0f, -leftRight, upDown); } else { if (leftRight < 0.0f) - angle = 0.5f * PI; + angle = HALFPI; else if (leftRight > 0.0f) - angle = -0.5f * PI; + angle = -HALFPI; } return CGeneral::LimitRadianAngle(offset + angle); } +// --MIAMI: Done void CPed::CalculateNewVelocity(void) { @@ -2198,9 +2905,6 @@ CPed::CalculateNewVelocity(void) limitedRotDest -= 2 * PI; } - if (IsPlayer() && m_nPedState == PED_ATTACK) - headAmount /= 4.0f; - float neededTurn = limitedRotDest - m_fRotationCur; if (neededTurn <= headAmount) { if (neededTurn > (-headAmount)) @@ -2224,8 +2928,12 @@ CPed::CalculateNewVelocity(void) } if ((!TheCamera.Cams[TheCamera.ActiveCam].GetWeaponFirstPersonOn() && !TheCamera.Cams[0].Using3rdPersonMouseCam()) - || FindPlayerPed() != this || !CanStrafeOrMouseControl()) + || FindPlayerPed() != this || !CanStrafeOrMouseControl()) { + + if (FindPlayerPed() == this) + FindPlayerPed()->m_fWalkAngle = 0.0f; return; + } float walkAngle = WorkOutHeadingForMovingFirstPerson(m_fRotationCur); float pedSpeed = m_moved.Magnitude(); @@ -2245,11 +2953,13 @@ CPed::CalculateNewVelocity(void) CAnimBlendAssociation *idleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_STANCE); CAnimBlendAssociation *fightAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE); -#ifdef VC_PED_PORTS + if(!fightAssoc) + fightAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_TIRED); + + if(!fightAssoc) + fightAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCHRELOAD); + if ((!idleAssoc || idleAssoc->blendAmount < 0.5f) && !fightAssoc && !bIsDucking) { -#else - if ((!idleAssoc || idleAssoc->blendAmount < 0.5f) && !fightAssoc) { -#endif LimbOrientation newUpperLegs; newUpperLegs.yaw = localWalkAngle; @@ -2260,35 +2970,19 @@ CPed::CalculateNewVelocity(void) } if (newUpperLegs.yaw > -DEGTORAD(50.0f) && newUpperLegs.yaw < DEGTORAD(50.0f)) { -#ifdef PED_SKIN - if(IsClumpSkinned(GetClump())){ -/* - // this looks shit - newUpperLegs.pitch = 0.0f; - RwV3d axis = { -1.0f, 0.0f, 0.0f }; - RtQuatRotate(&m_pFrames[PED_UPPERLEGL]->hanimFrame->q, &axis, RADTODEG(newUpperLegs.yaw), rwCOMBINEPRECONCAT); - RtQuatRotate(&m_pFrames[PED_UPPERLEGR]->hanimFrame->q, &axis, RADTODEG(newUpperLegs.yaw), rwCOMBINEPRECONCAT); -*/ - newUpperLegs.pitch = 0.1f; - RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; - RwV3d Zaxis = { 0.0f, 0.0f, 1.0f }; - RtQuatRotate(&m_pFrames[PED_UPPERLEGL]->hanimFrame->q, &Zaxis, RADTODEG(newUpperLegs.pitch), rwCOMBINEPOSTCONCAT); - RtQuatRotate(&m_pFrames[PED_UPPERLEGL]->hanimFrame->q, &Xaxis, RADTODEG(newUpperLegs.yaw), rwCOMBINEPOSTCONCAT); - RtQuatRotate(&m_pFrames[PED_UPPERLEGR]->hanimFrame->q, &Zaxis, RADTODEG(newUpperLegs.pitch), rwCOMBINEPOSTCONCAT); - RtQuatRotate(&m_pFrames[PED_UPPERLEGR]->hanimFrame->q, &Xaxis, RADTODEG(newUpperLegs.yaw), rwCOMBINEPOSTCONCAT); - - bDontAcceptIKLookAts = true; - }else -#endif - { - newUpperLegs.pitch = 0.0f; - m_pedIK.RotateTorso(m_pFrames[PED_UPPERLEGL], &newUpperLegs, false); - m_pedIK.RotateTorso(m_pFrames[PED_UPPERLEGR], &newUpperLegs, false); - } + newUpperLegs.pitch = 0.1f; + RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; + RwV3d Zaxis = { 0.0f, 0.0f, 1.0f }; + RtQuatRotate(&m_pFrames[PED_UPPERLEGL]->hanimFrame->q, &Zaxis, RADTODEG(newUpperLegs.pitch), rwCOMBINEPOSTCONCAT); + RtQuatRotate(&m_pFrames[PED_UPPERLEGL]->hanimFrame->q, &Xaxis, RADTODEG(newUpperLegs.yaw), rwCOMBINEPOSTCONCAT); + RtQuatRotate(&m_pFrames[PED_UPPERLEGR]->hanimFrame->q, &Zaxis, RADTODEG(newUpperLegs.pitch), rwCOMBINEPOSTCONCAT); + RtQuatRotate(&m_pFrames[PED_UPPERLEGR]->hanimFrame->q, &Xaxis, RADTODEG(newUpperLegs.yaw), rwCOMBINEPOSTCONCAT); + bDontAcceptIKLookAts = true; } } } +// --MIAMI: Done, but what is TODO_CHAR?? bool CPed::CanBeDeleted(void) { @@ -2300,11 +2994,14 @@ CPed::CanBeDeleted(void) return true; case MISSION_CHAR: return false; + case TODO_CHAR: + return false; default: return true; } } +// --MIAMI: Done bool CPed::CanPedDriveOff(void) { @@ -2321,7 +3018,7 @@ CPed::CanPedDriveOff(void) return true; } -#ifdef VC_PED_PORTS +// --MIAMI: Done bool CPed::CanPedJumpThis(CEntity *unused, CVector *damageNormal = nil) { @@ -2353,20 +3050,6 @@ CPed::CanPedJumpThis(CEntity *unused, CVector *damageNormal = nil) CVector forwardPos = pos + forwardOffset; return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false); } -#else -bool -CPed::CanPedJumpThis(CEntity *unused) -{ - CVector2D forward(-Sin(m_fRotationCur), Cos(m_fRotationCur)); - CVector pos = GetPosition(); - CVector forwardPos( - forward.x + pos.x, - forward.y + pos.y, - pos.z); - - return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false); -} -#endif bool CPed::CanPedReturnToState(void) @@ -2375,6 +3058,7 @@ CPed::CanPedReturnToState(void) m_nPedState != PED_FIGHT && m_nPedState != PED_STEP_AWAY && m_nPedState != PED_SNIPER_MODE && m_nPedState != PED_LOOK_ENTITY; } +// --MIAMI: Done bool CPed::CanSeeEntity(CEntity *entity, float threshold = CAN_SEE_ENTITY_ANGLE_THRESHOLD) { @@ -2400,14 +3084,13 @@ CPed::CanSeeEntity(CEntity *entity, float threshold = CAN_SEE_ENTITY_ANGLE_THRES return neededTurn < threshold || TWOPI - threshold < neededTurn; } +// --MIAMI: Done bool CPed::IsTemporaryObjective(eObjective objective) { return objective == OBJECTIVE_LEAVE_CAR || objective == OBJECTIVE_SET_LEADER || -#ifdef VC_PED_PORTS - objective == OBJECTIVE_LEAVE_CAR_AND_DIE || -#endif - objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER; + objective == OBJECTIVE_LEAVE_CAR_AND_DIE || objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || + objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER; } void @@ -2416,6 +3099,7 @@ CPed::SetMoveState(eMoveState state) m_nMoveState = state; } +// --MIAMI: Done void CPed::SetObjectiveTimer(int time) { @@ -2426,6 +3110,7 @@ CPed::SetObjectiveTimer(int time) } } +// --MIAMI: Done void CPed::ForceStoredObjective(eObjective objective) { @@ -2434,49 +3119,65 @@ CPed::ForceStoredObjective(eObjective objective) return; } - switch (m_objective) - { + switch (m_objective) { case OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE: case OBJECTIVE_KILL_CHAR_ON_FOOT: case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_ENTER_CAR_AS_PASSENGER: case OBJECTIVE_ENTER_CAR_AS_DRIVER: case OBJECTIVE_GOTO_AREA_ON_FOOT: case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_GOTO_SEAT_ON_FOOT: + case OBJECTIVE_GOTO_ATM_ON_FOOT: + case OBJECTIVE_GOTO_BUS_STOP_ON_FOOT: + case OBJECTIVE_GOTO_PIZZA_ON_FOOT: + case OBJECTIVE_GOTO_SHELTER_ON_FOOT: + case OBJECTIVE_SPRINT_TO_AREA: + case OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT: return; default: m_prevObjective = m_objective; } } +// --MIAMI: Done void CPed::SetStoredObjective(void) { if (m_objective == m_prevObjective) return; - switch (m_objective) - { + switch (m_objective) { case OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE: case OBJECTIVE_KILL_CHAR_ON_FOOT: case OBJECTIVE_KILL_CHAR_ANY_MEANS: case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: - case OBJECTIVE_FOLLOW_CHAR_IN_FORMATION: - case OBJECTIVE_LEAVE_CAR: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_ENTER_CAR_AS_PASSENGER: case OBJECTIVE_ENTER_CAR_AS_DRIVER: case OBJECTIVE_GOTO_AREA_ON_FOOT: case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_GOTO_SEAT_ON_FOOT: + case OBJECTIVE_GOTO_ATM_ON_FOOT: + case OBJECTIVE_GOTO_BUS_STOP_ON_FOOT: + case OBJECTIVE_GOTO_PIZZA_ON_FOOT: + case OBJECTIVE_GOTO_SHELTER_ON_FOOT: + case OBJECTIVE_SPRINT_TO_AREA: + case OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT: return; default: m_prevObjective = m_objective; } } +// --MIAMI: Done void CPed::RestorePreviousObjective(void) { @@ -2484,10 +3185,7 @@ CPed::RestorePreviousObjective(void) return; if (m_objective != OBJECTIVE_LEAVE_CAR && m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER -#if defined VC_PED_PORTS || defined FIX_BUGS - && m_nPedState != PED_CARJACK -#endif - ) + && m_nPedState != PED_CARJACK) m_pedInObjective = nil; if (m_objective == OBJECTIVE_WAIT_IN_CAR_THEN_GET_OUT) { @@ -2502,48 +3200,52 @@ CPed::RestorePreviousObjective(void) bObjectiveCompleted = false; } +// --MIAMI: Done void CPed::SetLeader(CEntity *leader) { m_leader = (CPed*)leader; - if(m_leader) - m_leader->RegisterReference((CEntity **)&m_leader); + if (m_leader) { + m_leader->bIsLeader = true; + m_leader->RegisterReference((CEntity**)&m_leader); + } } +// --MIAMI: Done except comments void CPed::SetObjective(eObjective newObj, void *entity) { if (DyingOrDead()) return; - if (m_prevObjective == newObj) { - // Why? - if (m_prevObjective != OBJECTIVE_NONE) - return; - } + if (m_prevObjective == newObj && m_prevObjective != OBJECTIVE_NONE) + return; if (entity == this) return; - SetObjectiveTimer(0); + if (m_attachedTo && newObj != OBJECTIVE_KILL_CHAR_ON_FOOT && newObj != OBJECTIVE_KILL_CHAR_ANY_MEANS && newObj != OBJECTIVE_DESTROY_OBJECT && newObj != OBJECTIVE_DESTROY_CAR) + return; + if (m_objective == newObj) { switch (newObj) { case OBJECTIVE_KILL_CHAR_ON_FOOT: case OBJECTIVE_KILL_CHAR_ANY_MEANS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_FOLLOW_CHAR_IN_FORMATION: case OBJECTIVE_GOTO_AREA_ANY_MEANS: case OBJECTIVE_GUARD_ATTACK: + case OBJECTIVE_KILL_CHAR_ON_BOAT: + case OBJECTIVE_SOLICIT_FOOT: if (m_pedInObjective == entity) return; - break; case OBJECTIVE_LEAVE_CAR: case OBJECTIVE_FLEE_CAR: -#ifdef VC_PED_PORTS case OBJECTIVE_LEAVE_CAR_AND_DIE: -#endif return; case OBJECTIVE_ENTER_CAR_AS_PASSENGER: case OBJECTIVE_ENTER_CAR_AS_DRIVER: @@ -2553,28 +3255,30 @@ CPed::SetObjective(eObjective newObj, void *entity) if (m_carInObjective == entity) return; + if (newObj == OBJECTIVE_BUY_ICE_CREAM && bBoughtIceCream) + return; + break; case OBJECTIVE_SET_LEADER: if (m_leader == entity) return; - + break; + case OBJECTIVE_AIM_GUN_AT: + if (m_pedInObjective == entity) + return; break; default: break; } } else { - if ((newObj == OBJECTIVE_LEAVE_CAR -#ifdef VC_PED_PORTS - || newObj == OBJECTIVE_LEAVE_CAR_AND_DIE -#endif - ) && !bInVehicle) + if (newObj != OBJECTIVE_WAIT_IN_CAR_THEN_GET_OUT && (newObj == OBJECTIVE_LEAVE_CAR || newObj == OBJECTIVE_LEAVE_CAR_AND_DIE) + && !bInVehicle) return; } -#ifdef VC_PED_PORTS - ClearPointGunAt(); -#endif bObjectiveCompleted = false; + ClearPointGunAt(); + m_objectiveTimer = 0; if (!IsTemporaryObjective(m_objective) || IsTemporaryObjective(newObj)) { if (m_objective != newObj) { if (IsTemporaryObjective(newObj)) @@ -2588,6 +3292,13 @@ CPed::SetObjective(eObjective newObj, void *entity) } switch (newObj) { + case OBJECTIVE_WAIT_ON_FOOT_FOR_COP: + m_pedInObjective = (CPed*)entity; + m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); + SetIdle(); + // TODO(Miami) + // SetLook(m_pedInObjective); + break; case OBJECTIVE_WAIT_IN_CAR_THEN_GET_OUT: // In this special case, entity parameter isn't CEntity, but int. @@ -2596,20 +3307,33 @@ CPed::SetObjective(eObjective newObj, void *entity) case OBJECTIVE_KILL_CHAR_ON_FOOT: case OBJECTIVE_KILL_CHAR_ANY_MEANS: case OBJECTIVE_MUG_CHAR: + case OBJECTIVE_KILL_CHAR_ON_BOAT: m_pNextPathNode = nil; bUsePedNodeSeek = false; - m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); + + if (m_pedInObjective) + m_pedInObjective->CleanUpOldReference((CEntity**)&m_pedInObjective); + if (m_pLookTarget) + m_pLookTarget->CleanUpOldReference(&m_pLookTarget); + + m_pLookTarget = (CEntity*)entity; m_pedInObjective = (CPed*)entity; + m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); - m_pLookTarget = (CEntity*)entity; + // m_pLookTarget = (CEntity*)entity; // duplicate m_pLookTarget->RegisterReference((CEntity**)&m_pLookTarget); break; case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_GUARD_ATTACK: - m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); + + if (m_pedInObjective) + m_pedInObjective->CleanUpOldReference((CEntity**)&m_pedInObjective); m_pedInObjective = (CPed*)entity; + m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); break; case OBJECTIVE_FOLLOW_CHAR_IN_FORMATION: @@ -2618,13 +3342,11 @@ CPed::SetObjective(eObjective newObj, void *entity) m_pedFormation = FORMATION_REAR; break; case OBJECTIVE_LEAVE_CAR: -#ifdef VC_PED_PORTS case OBJECTIVE_LEAVE_CAR_AND_DIE: -#endif case OBJECTIVE_FLEE_CAR: m_carInObjective = (CVehicle*)entity; m_carInObjective->RegisterReference((CEntity **)&m_carInObjective); - if (!m_carInObjective->bIsBus || m_leaveCarTimer) + if (!m_carInObjective->bIsBus || m_leaveCarTimer != 0) break; for (int i = 0; i < m_carInObjective->m_nNumMaxPassengers; i++) { @@ -2635,12 +3357,19 @@ CPed::SetObjective(eObjective newObj, void *entity) } break; + case OBJECTIVE_DESTROY_OBJECT: + if (m_pPointGunAt) + m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt); + m_pPointGunAt = (CPed*)entity; + if (entity) + ((CEntity*)entity)->RegisterReference((CEntity**) &m_pPointGunAt); + break; case OBJECTIVE_ENTER_CAR_AS_PASSENGER: case OBJECTIVE_ENTER_CAR_AS_DRIVER: if (m_nMoveState == PEDMOVE_STILL) SetMoveState(PEDMOVE_RUN); - if (((CVehicle*)entity)->m_vehType == VEHICLE_TYPE_BOAT && !IsPlayer()) { + if (((CVehicle*)entity)->m_vehType == VEHICLE_TYPE_BOAT && !IsPlayer() && m_pCurrentPhysSurface != entity) { RestorePreviousObjective(); break; } @@ -2666,44 +3395,46 @@ CPed::SetObjective(eObjective newObj, void *entity) SetLeader((CEntity*)entity); RestorePreviousObjective(); break; + case OBJECTIVE_AIM_GUN_AT: + m_pedInObjective = (CPed*)entity; + m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); + break; + case OBJECTIVE_SOLICIT_FOOT: + m_pedInObjective = (CPed*)entity; + m_pedInObjective->RegisterReference((CEntity**)&m_pedInObjective); + break; default: break; } } +// --MIAMI: Done void CPed::SetIdle(void) { if (m_nPedState != PED_IDLE && m_nPedState != PED_MUG && m_nPedState != PED_FLEE_ENTITY) { -#ifdef VC_PED_PORTS if (m_nPedState == PED_AIM_GUN) ClearPointGunAt(); - m_nLastPedState = PED_NONE; -#endif - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); SetMoveState(PEDMOVE_STILL); + m_nLastPedState = PED_NONE; } if (m_nWaitState == WAITSTATE_FALSE) { m_nWaitTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(2000, 4000); } } +// --MIAMI: Done void CPed::SetObjective(eObjective newObj) { - if (DyingOrDead()) + if (DyingOrDead() || m_attachedTo) return; if (newObj == OBJECTIVE_NONE) { if ((m_objective == OBJECTIVE_LEAVE_CAR || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER -#ifdef VC_PED_PORTS - || m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) - && !IsPlayer() -#else - ) -#endif - && !IsPedInControl()) { + || m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) && !IsPlayer() && !IsPedInControl()) { bStartWanderPathOnFoot = true; return; @@ -2780,6 +3511,7 @@ CPed::SetObjective(eObjective newObj, int16 routePoint, int16 routeType) } } +// --MIAMI: Done void CPed::ClearChat(void) { @@ -2791,14 +3523,21 @@ CPed::ClearChat(void) bIsTalking = false; ClearLookFlag(); RestorePreviousState(); + if (m_objective == OBJECTIVE_BUY_ICE_CREAM) { + bBoughtIceCream = true; + SetObjective(OBJECTIVE_NONE); + SetWanderPath(CGeneral::GetRandomNumberInRange(0, 8)); + } } +// --MIAMI: Done bool CPed::IsGangMember(void) { return m_nPedType >= PEDTYPE_GANG1 && m_nPedType <= PEDTYPE_GANG9; } +// --MIAMI: Done void CPed::InformMyGangOfAttack(CEntity *attacker) { @@ -2825,8 +3564,7 @@ CPed::InformMyGangOfAttack(CEntity *attacker) CPed *nearPed = m_nearPeds[i]; if (nearPed && nearPed != this) { CPed *leader = nearPed->m_leader; - if (leader && leader == this && nearPed->m_pedStats->m_fear < nearPed->m_pedStats->m_temper) - { + if (leader && leader == this && nearPed->m_pedStats->m_fear < nearPed->m_pedStats->m_temper) { nearPed->SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, attackerPed); nearPed->SetObjectiveTimer(30000); } @@ -2834,6 +3572,7 @@ CPed::InformMyGangOfAttack(CEntity *attacker) } } +// --MIAMI: Done void CPed::QuitEnteringCar(void) { @@ -2854,18 +3593,18 @@ CPed::QuitEnteringCar(void) if (veh->m_nNumGettingIn != 0) veh->m_nNumGettingIn--; -#ifdef VC_PED_PORTS if (m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER) RestorePreviousObjective(); -#endif - veh->m_nGettingInFlags &= ~GetCarDoorFlag(m_vehEnterType); + if (veh->IsBike()) { + veh->m_nGettingInFlags &= ~GetBikeDoorFlag(m_vehEnterType); + ((CBike*)veh)->bIsBeingPickedUp = false; + } else + veh->m_nGettingInFlags &= ~GetEnterCarDoorFlag(m_vehEnterType, veh->m_nNumMaxPassengers); } bUsesCollision = true; - ReplaceWeaponWhenExitingVehicle(); - if (DyingOrDead()) { animAssoc = m_pVehicleAnim; if (animAssoc) { @@ -2879,11 +3618,7 @@ CPed::QuitEnteringCar(void) m_pVehicleAnim = nil; if (veh) { -#ifdef VC_PED_PORTS if (veh->AutoPilot.m_nCruiseSpeed == 0 && veh->VehicleCreatedBy == RANDOM_VEHICLE) -#else - if (veh->AutoPilot.m_nCruiseSpeed == 0) -#endif veh->AutoPilot.m_nCruiseSpeed = 17; } } @@ -2952,6 +3687,8 @@ CPed::ReactToAttack(CEntity *attacker) } } + +// --MIAMI: Done bool CPed::TurnBody(void) { @@ -2990,6 +3727,7 @@ CPed::TurnBody(void) return turnDone; } +// --MIAMI: Done void CPed::Chat(void) { @@ -3024,7 +3762,7 @@ CPed::Chat(void) } else Say(SOUND_PED_CHAT); - } else if (!RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_FLAG_XPRESS)) { + } else if (!RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_IDLE)) { if (CGeneral::GetRandomNumber() < 20) { CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_XPRESS_SCRATCH, 4.0f); @@ -3044,6 +3782,7 @@ CPed::Chat(void) } } +// --MIAMI: Done void CPed::CheckAroundForPossibleCollisions(void) { @@ -3076,106 +3815,37 @@ CPed::CheckAroundForPossibleCollisions(void) } } -#ifdef PEDS_REPORT_CRIMES_ON_PHONE -void -ReportPhonePickUpCB(CAnimBlendAssociation* assoc, void* arg) -{ - CPed* ped = (CPed*)arg; - ped->m_nMoveState = PEDMOVE_STILL; - CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_IDLE_STANCE, 8.0f); - - if (assoc->blendAmount > 0.5f && ped) { - CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_PHONE_TALK, 8.0f); - } -} - -void -ReportPhonePutDownCB(CAnimBlendAssociation* assoc, void* arg) -{ - assoc->flags |= ASSOC_DELETEFADEDOUT; - assoc->blendDelta = -1000.0f; - CPed* ped = (CPed*)arg; - - if (ped->m_phoneId != -1 && crimeReporters[ped->m_phoneId] == ped) { - crimeReporters[ped->m_phoneId] = nil; - gPhoneInfo.m_aPhones[ped->m_phoneId].m_nState = PHONE_STATE_FREE; - ped->m_phoneId = -1; - } - - if (assoc->blendAmount > 0.5f) - ped->bUpdateAnimHeading = true; - - ped->SetWanderPath(CGeneral::GetRandomNumber() & 7); -} -#endif - +// --MIAMI: Done bool CPed::MakePhonecall(void) { -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - if (!IsPlayer() && CTimer::GetTimeInMilliseconds() > m_phoneTalkTimer - 7000 && bRunningToPhone) { - - FindPlayerPed()->m_pWanted->RegisterCrime_Immediately(m_crimeToReportOnPhone, GetPosition(), - (m_crimeToReportOnPhone == CRIME_POSSESSION_GUN ? (uintptr)m_threatEntity : (uintptr)m_victimOfPlayerCrime), false); - - if (m_crimeToReportOnPhone != CRIME_POSSESSION_GUN) - FindPlayerPed()->m_pWanted->SetWantedLevelNoDrop(1); - - bRunningToPhone = false; - } -#endif if (CTimer::GetTimeInMilliseconds() <= m_phoneTalkTimer) return false; -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - CAnimBlendAssociation* talkAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_PHONE_TALK); - if (talkAssoc && talkAssoc->blendAmount > 0.5f) { - CAnimBlendAssociation* endAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_PHONE_OUT, 8.0f); - endAssoc->flags &= ~ASSOC_DELETEFADEDOUT; - endAssoc->SetFinishCallback(ReportPhonePutDownCB, this); - } -#endif SetIdle(); - gPhoneInfo.m_aPhones[m_phoneId].m_nState = PHONE_STATE_FREE; -#ifndef PEDS_REPORT_CRIMES_ON_PHONE m_phoneId = -1; -#endif - - // Because SetWanderPath is now done async in ReportPhonePutDownCB -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - return false; -#else return true; -#endif } +// --MIAMI: Done bool CPed::FacePhone(void) { - // This function was broken since it's left unused early in development. -#ifdef PEDS_REPORT_CRIMES_ON_PHONE + // FIX: This function was broken since it's left unused early in development. +#ifdef FIX_BUGS float phoneDir = CGeneral::GetRadianAngleBetweenPoints( gPhoneInfo.m_aPhones[m_phoneId].m_vecPos.x, gPhoneInfo.m_aPhones[m_phoneId].m_vecPos.y, GetPosition().x, GetPosition().y); - if (m_facePhoneStart) { - m_lookTimer = 0; - SetLookFlag(phoneDir, true); - m_lookTimer = CTimer::GetTimeInMilliseconds() + 3000; - m_facePhoneStart = false; - } - - if (bIsLooking && TurnBody()) { - ClearLookFlag(); + SetLookFlag(phoneDir, false); + bool turnDone = TurnBody(); + if (turnDone) { SetIdle(); + ClearLookFlag(); m_phoneTalkTimer = CTimer::GetTimeInMilliseconds() + 10000; - CAnimBlendAssociation* assoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_PHONE_IN, 4.0f); - assoc->SetFinishCallback(ReportPhonePickUpCB, this); - return true; } - - return false; + return turnDone; #else float currentRot = RADTODEG(m_fRotationCur); float phoneDir = CGeneral::GetRadianAngleBetweenPoints( @@ -3207,6 +3877,7 @@ CPed::FacePhone(void) #endif } +// --MIAMI: Done CPed * CPed::CheckForDeadPeds(void) { @@ -3222,63 +3893,7 @@ CPed::CheckForDeadPeds(void) return nil; } -#ifdef PEDS_REPORT_CRIMES_ON_PHONE -// returns event id, parameter is optional -int32 -CPed::CheckForPlayerCrimes(CPed *victim) -{ - int i; - float dist; - float mindist = 60.0f; - CPlayerPed *player = FindPlayerPed(); - int32 victimRef = (victim ? CPools::GetPedRef(victim) : 0); - int event = -1; - - for (i = 0; i < NUMEVENTS; i++) { - if (gaEvent[i].type == EVENT_NULL || gaEvent[i].type > EVENT_CAR_SET_ON_FIRE) - continue; - - // those are already handled in game, also DEAD_PED isn't registered alone, most of the time there is SHOOT_PED etc. - if (gaEvent[i].type == EVENT_DEAD_PED || gaEvent[i].type == EVENT_GUNSHOT || gaEvent[i].type == EVENT_EXPLOSION) - continue; - - if (victim && gaEvent[i].entityRef != victimRef) - continue; - - if (gaEvent[i].criminal != player) - continue; - - dist = (GetPosition() - gaEvent[i].posn).Magnitude(); - if (dist < mindist) { - mindist = dist; - event = i; - } - } - - if (event != -1) { - if (victim) { - m_victimOfPlayerCrime = victim; - } else { - switch (gaEvent[event].entityType) { - case EVENT_ENTITY_PED: - m_victimOfPlayerCrime = CPools::GetPed(gaEvent[event].entityRef); - break; - case EVENT_ENTITY_VEHICLE: - m_victimOfPlayerCrime = CPools::GetVehicle(gaEvent[event].entityRef); - break; - case EVENT_ENTITY_OBJECT: - m_victimOfPlayerCrime = CPools::GetObject(gaEvent[event].entityRef); - break; - default: - break; - } - } - } - - return event; -} -#endif - +// --MIAMI: Done bool CPed::CheckForExplosions(CVector2D &area) { @@ -3323,6 +3938,7 @@ CPed::CheckForExplosions(CVector2D &area) return false; } +// --MIAMI: Done CPed * CPed::CheckForGunShots(void) { @@ -3338,6 +3954,7 @@ CPed::CheckForGunShots(void) return nil; } +// --MIAMI: Done PointBlankNecessity CPed::CheckForPointBlankPeds(CPed *pedToVerify) { @@ -3364,7 +3981,9 @@ CPed::CheckForPointBlankPeds(CPed *pedToVerify) if (neededTurn > PI) neededTurn = 2*PI - neededTurn; - if (nearPed->OnGroundOrGettingUp() || nearPed->m_nPedState == PED_DIVE_AWAY) + PedState nearPedState = nearPed->m_nPedState; + + if (nearPedState == PED_FALL || nearPedState == PED_GETUP || nearPedState == PED_DIE || nearPedState == PED_DEAD || nearPedState == PED_DIVE_AWAY) return NO_POINT_BLANK_PED; if (neededTurn < CAN_SEE_ENTITY_ANGLE_THRESHOLD) { @@ -3379,6 +3998,7 @@ CPed::CheckForPointBlankPeds(CPed *pedToVerify) return NO_POINT_BLANK_PED; } +// --MIAMI: Done bool CPed::CheckIfInTheAir(void) { @@ -3400,13 +4020,30 @@ CPed::CheckIfInTheAir(void) return !foundGround; } +// --MIAMI: Done +void +CPed::CheckThreatValidity(void) +{ + if (m_threatEntity && !IsEntityPointerValid(m_threatEntity)) { + m_threatFlags = 0; + m_threatEntity = 0; + } + if (m_pEventEntity && !IsEntityPointerValid(m_pEventEntity)) { + m_threatFlags = 0; + m_pEventEntity = 0; + } + if (!m_threatEntity && !m_pEventEntity) + m_threatFlags = 0; +} + +// --MIAMI: Done void CPed::ClearAll(void) { if (!IsPedInControl() && m_nPedState != PED_DEAD) return; - m_nPedState = PED_NONE; + SetPedState(PED_NONE); m_nMoveState = PEDMOVE_NONE; m_pSeekTarget = nil; m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); @@ -3414,33 +4051,27 @@ CPed::ClearAll(void) m_fleeFromPosY = 0.0f; m_fleeFrom = nil; m_fleeTimer = 0; + pThreatEx = nil; bUsesCollision = true; -#ifdef VC_PED_PORTS ClearPointGunAt(); -#else - ClearAimFlag(); - ClearLookFlag(); -#endif bIsPointingGunAt = false; bRenderPedInCar = true; bKnockedUpIntoAir = false; + bKnockedOffBike = false; m_pCollidingEntity = nil; } +// --MIAMI: Done void CPed::ClearAttack(void) { - if (m_nPedState != PED_ATTACK || bIsDucking || m_nWaitState == WAITSTATE_PLAYANIM_DUCK) + if (m_nPedState != PED_ATTACK || (bIsDucking && !IsPlayer()) || m_nWaitState == WAITSTATE_PLAYANIM_DUCK) return; -#ifdef VC_PED_PORTS // VC uses CCamera::Using1stPersonWeaponMode - if (FindPlayerPed() == this && (TheCamera.PlayerWeaponMode.Mode == CCam::MODE_SNIPER || - TheCamera.PlayerWeaponMode.Mode == CCam::MODE_M16_1STPERSON || TheCamera.PlayerWeaponMode.Mode == CCam::MODE_ROCKETLAUNCHER)) { + if (FindPlayerPed() == this && TheCamera.Using1stPersonWeaponMode()) { SetPointGunAt(nil); - } else -#endif - if (bIsPointingGunAt) { + } else if (bIsPointingGunAt) { if (m_pLookTarget) SetPointGunAt(m_pLookTarget); else @@ -3452,29 +4083,40 @@ CPed::ClearAttack(void) } } +// --MIAMI: Done void CPed::ClearAttackByRemovingAnim(void) { - if (m_nPedState != PED_ATTACK || bIsDucking) + if (m_nPedState != PED_ATTACK) return; CWeaponInfo *weapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - CAnimBlendAssociation *weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), weapon->m_AnimToPlay); - if (!weaponAssoc) { - weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), weapon->m_Anim2ToPlay); - - if (!weaponAssoc && weapon->m_bThrow) - weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_THROWU); + CAnimBlendAssociation *weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetPrimaryFireAnim(weapon)); - if (!weaponAssoc) { - ClearAttack(); - return; - } + if (!weaponAssoc) { + if (!!weapon->m_bCrouchFire) + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchFireAnim(weapon)); + } + if (!weaponAssoc) { + if(!!weapon->m_bFinish3rd) + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetFinishingAttackAnim(weapon)); + } + if (!weaponAssoc) { + if(!!weapon->m_bUse2nd) + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetSecondFireAnim(weapon)); + } + if (!weaponAssoc) { + if(!!weapon->m_bCop3rd) + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_SPECIAL); + } + if (weaponAssoc) { + weaponAssoc->blendDelta = -8.0f; + weaponAssoc->flags &= ~ASSOC_RUNNING; + weaponAssoc->flags |= ASSOC_DELETEFADEDOUT; + weaponAssoc->SetDeleteCallback(FinishedAttackCB, this); + } else { + ClearAttack(); } - weaponAssoc->blendDelta = -8.0f; - weaponAssoc->flags &= ~ASSOC_RUNNING; - weaponAssoc->flags |= ASSOC_DELETEFADEDOUT; - weaponAssoc->SetDeleteCallback(FinishedAttackCB, this); } void @@ -3488,6 +4130,7 @@ CPed::StopNonPartialAnims(void) } } +// --MIAMI: Done void CPed::SetStoredState(void) { @@ -3499,10 +4142,7 @@ CPed::SetStoredState(void) if (m_nMoveState == PEDMOVE_NONE || m_nMoveState == PEDMOVE_STILL) m_nMoveState = PEDMOVE_WALK; } -#ifdef VC_PED_PORTS - if (m_nPedState != PED_IDLE) -#endif - { + if (m_nPedState != PED_IDLE) { m_nLastPedState = m_nPedState; if (m_nMoveState >= m_nPrevMoveState) m_nPrevMoveState = m_nMoveState; @@ -3512,6 +4152,8 @@ CPed::SetStoredState(void) void CPed::SetDie(AnimationId animId, float delta, float speed) { + if (m_attractor) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); CPlayerPed *player = FindPlayerPed(); if (player == this) { if (!player->m_bCanBeDamaged) @@ -3539,7 +4181,7 @@ CPed::SetDie(AnimationId animId, float delta, float speed) } m_nPedState = PED_DIE; - if (animId == NUM_ANIMS) { + if (animId == NUM_STD_ANIMS) { bIsPedDieAnimPlaying = false; } else { CAnimBlendAssociation *dieAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, animId, delta); @@ -3562,6 +4204,7 @@ CPed::SetDie(AnimationId animId, float delta, float speed) m_bloodyFootprintCountOrDeathTime = CTimer::GetTimeInMilliseconds(); } +// --MIAMI: Done except commented things bool CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPieceTypes pedPiece, uint8 direction) { @@ -3573,17 +4216,29 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi bool willLinger = false; int random; + if (damagedBy == FindPlayerPed() && damagedBy != this && damage > 3.0f) + ++CWorld::Players[CWorld::PlayerInFocus].m_nHavocLevel; + if (player == this) { if (!player->m_bCanBeDamaged) return false; + if (damagedBy && damagedBy->IsPed() && ((CPed*)damagedBy)->m_nPedType == PEDTYPE_GANG7) + return false; + + if ((method == WEAPONTYPE_FLAMETHROWER || method == WEAPONTYPE_MOLOTOV) && CWorld::Players[CWorld::PlayerInFocus].m_bFireproof) + return false; + player->AnnoyPlayerPed(false); } if (DyingOrDead()) return false; - if (!bUsesCollision && method != WEAPONTYPE_DROWNING) + if (method == WEAPONTYPE_DROWNING && !bDrownsInWater) + return false; + + if (!bUsesCollision && (!bInVehicle || m_nPedState != PED_DRIVING) && method != WEAPONTYPE_DROWNING) return false; if (bOnlyDamagedByPlayer && damagedBy != player && damagedBy != FindPlayerVehicle() && @@ -3596,8 +4251,12 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi else healthImpact = damage * m_pedStats->m_defendWeakness; + if (!IsPlayer() && + (method == WEAPONTYPE_SCREWDRIVER || method == WEAPONTYPE_KNIFE || (method >= WEAPONTYPE_CLEAVER && method <= WEAPONTYPE_CHAINSAW))) + m_bleedCounter = 200; + bool detectDieAnim = true; - if (m_nPedState == PED_FALL || m_nPedState == PED_GETUP) { + if (m_nPedState == PED_GETUP) { if (!IsPedHeadAbovePos(-0.3f)) { if (RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_FRONTAL)) dieAnim = ANIM_FLOOR_HIT_F; @@ -3606,20 +4265,36 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi dieDelta *= 2.0f; dieSpeed = 0.5f; detectDieAnim = false; - } else if (m_nPedState == PED_FALL) { - dieAnim = NUM_ANIMS; - detectDieAnim = false; } + } else if (m_nPedState == PED_FALL) { + CAnimBlendAssociation *fallAssoc = RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_PARTIAL); + if (!fallAssoc || fallAssoc->IsRunning()) { + if (fallAssoc && fallAssoc->blendDelta >= 0.0f) + dieAnim = NUM_STD_ANIMS; + else + dieAnim = ANIM_KO_SHOT_FRONT1; + } else { + if (fallAssoc->flags & ASSOC_FRONTAL) + dieAnim = ANIM_FLOOR_HIT_F; + else + dieAnim = ANIM_FLOOR_HIT; + + dieDelta *= 2.0f; + dieSpeed = 0.5f; + } + detectDieAnim = false; } + if (detectDieAnim) { switch (method) { case WEAPONTYPE_UNARMED: + case WEAPONTYPE_BRASSKNUCKLE: if (bMeleeProof) return false; if (m_nPedState == PED_FALL) { if (IsPedHeadAbovePos(-0.3f)) { - dieAnim = NUM_ANIMS; + dieAnim = NUM_STD_ANIMS; } else { if (RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_FRONTAL)) dieAnim = ANIM_FLOOR_HIT_F; @@ -3647,68 +4322,97 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi } } break; + case WEAPONTYPE_SCREWDRIVER: + case WEAPONTYPE_GOLFCLUB: + case WEAPONTYPE_NIGHTSTICK: + case WEAPONTYPE_KNIFE: case WEAPONTYPE_BASEBALLBAT: + case WEAPONTYPE_HAMMER: + case WEAPONTYPE_CLEAVER: + case WEAPONTYPE_MACHETE: + case WEAPONTYPE_KATANA: + case WEAPONTYPE_CHAINSAW: if (bMeleeProof) return false; - if (m_nPedState == PED_FALL) { - if (IsPedHeadAbovePos(-0.3f)) { - dieAnim = NUM_ANIMS; + if (method != WEAPONTYPE_KATANA || + damagedBy != FindPlayerPed() + || FindPlayerPed()->m_nPedState != PED_FIGHT + || FindPlayerPed()->m_curFightMove != FIGHTMOVE_MELEE1 && FindPlayerPed()->m_curFightMove != FIGHTMOVE_MELEE2 + || CGeneral::GetRandomNumber() & 3) { + + if (m_nPedState == PED_FALL) { + if (IsPedHeadAbovePos(-0.3f)) { + dieAnim = NUM_STD_ANIMS; + } else { + if (RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_FRONTAL)) + dieAnim = ANIM_FLOOR_HIT_F; + else + dieAnim = ANIM_FLOOR_HIT; + dieDelta = dieDelta * 2.0f; + dieSpeed = 0.5f; + } + } else if (damagedBy != FindPlayerPed() || FindPlayerPed()->m_curFightMove != FIGHTMOVE_MELEE2) { + if (damagedBy != FindPlayerPed() || FindPlayerPed()->m_curFightMove != FIGHTMOVE_MELEE3) { + switch (direction) { + case 0: + dieAnim = ANIM_KO_SKID_FRONT; + break; + case 1: + dieAnim = ANIM_KO_SPIN_R; + break; + case 2: + dieAnim = ANIM_KO_SKID_BACK; + break; + case 3: + dieAnim = ANIM_KO_SPIN_L; + break; + default: + break; + } + } else { + dieAnim = ANIM_KO_SHOT_STOM; + } } else { - if (RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_FRONTAL)) - dieAnim = ANIM_FLOOR_HIT_F; - else - dieAnim = ANIM_FLOOR_HIT; - dieDelta = dieDelta * 2.0f; - dieSpeed = 0.5f; + dieAnim = ANIM_KO_SHOT_FACE; } } else { - switch (direction) { - case 0: - dieAnim = ANIM_KO_SKID_FRONT; - break; - case 1: - dieAnim = ANIM_KO_SPIN_R; - break; - case 2: - dieAnim = ANIM_KO_SKID_BACK; - break; - case 3: - dieAnim = ANIM_KO_SPIN_L; - break; - default: - break; - } + dieAnim = ANIM_KO_SHOT_FACE; + RemoveBodyPart(PED_HEAD, direction); + headShot = true; + willLinger = true; } break; case WEAPONTYPE_COLT45: - case WEAPONTYPE_UZI: case WEAPONTYPE_SHOTGUN: - case WEAPONTYPE_AK47: - case WEAPONTYPE_M16: + case WEAPONTYPE_STUBBY_SHOTGUN: + case WEAPONTYPE_SPAS12_SHOTGUN: + case WEAPONTYPE_TEC9: + case WEAPONTYPE_UZI: + case WEAPONTYPE_SILENCED_INGRAM: + case WEAPONTYPE_MP5: + case WEAPONTYPE_M4: + case WEAPONTYPE_RUGER: case WEAPONTYPE_SNIPERRIFLE: + case WEAPONTYPE_LASERSCOPE: + case WEAPONTYPE_M60: + case WEAPONTYPE_MINIGUN: + case WEAPONTYPE_UZI_DRIVEBY: + if (bBulletProof) return false; bool dontRemoveLimb; if (IsPlayer() || bNoCriticalHits) dontRemoveLimb = true; - else { - switch (method) { - case WEAPONTYPE_SNIPERRIFLE: - dontRemoveLimb = false; - break; - case WEAPONTYPE_M16: - dontRemoveLimb = false; - break; - case WEAPONTYPE_SHOTGUN: - dontRemoveLimb = CGeneral::GetRandomNumber() & 7; - break; - default: - dontRemoveLimb = CGeneral::GetRandomNumber() & 15; - break; - } - } + else if (method != WEAPONTYPE_M4 && method != WEAPONTYPE_RUGER && method != WEAPONTYPE_SNIPERRIFLE && + method != WEAPONTYPE_LASERSCOPE) { + if (method == WEAPONTYPE_SHOTGUN) + dontRemoveLimb = CGeneral::GetRandomNumber() & 7; + else + dontRemoveLimb = CGeneral::GetRandomNumber() & 15; + } else + dontRemoveLimb = false; if (dontRemoveLimb) { if (method == WEAPONTYPE_SHOTGUN) { @@ -3773,8 +4477,8 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi } } break; - case WEAPONTYPE_ROCKETLAUNCHER: case WEAPONTYPE_GRENADE: + case WEAPONTYPE_ROCKETLAUNCHER: case WEAPONTYPE_EXPLOSION: if (bExplosionProof) return false; @@ -3871,7 +4575,7 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi default: break; } - if (damagedBy) { + if (damagedBy && pedPiece != PEDPIECE_TORSO) { CVehicle *vehicle = (CVehicle*)damagedBy; if (method == WEAPONTYPE_RAMMEDBYCAR) { float vehSpeed = vehicle->m_vecMoveSpeed.Magnitude(); @@ -3930,6 +4634,16 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss = CTimer::GetTimeInMilliseconds(); m_lastWepDam = method; + m_lastDamEntity = damagedBy; + } + + if (method == WEAPONTYPE_FALL) { + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_ROLLOUT_LHS)) { + if (m_fHealth >= 1.0 && m_fHealth - healthImpact < 5.0f) { + m_fHealth = Min(m_fHealth, 5.0f); + return false; + } + } } if (m_fHealth - healthImpact >= 1.0f && !willLinger) { @@ -3939,40 +4653,50 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi if (bInVehicle) { if (method != WEAPONTYPE_DROWNING) { -#ifdef VC_PED_PORTS if (m_pMyVehicle) { - if (m_pMyVehicle->IsCar() && m_pMyVehicle->pDriver == this) { - if (m_pMyVehicle->GetStatus() == STATUS_SIMPLE) { - m_pMyVehicle->SetStatus(STATUS_PHYSICS); - CCarCtrl::SwitchVehicleToRealPhysics(m_pMyVehicle); - } - m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_NONE; - m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0; - m_pMyVehicle->AutoPilot.m_nTempAction = TEMPACT_HANDBRAKESTRAIGHT; - m_pMyVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 2000; - } - if (m_pMyVehicle->CanPedExitCar()) { - SetObjective(OBJECTIVE_LEAVE_CAR_AND_DIE, m_pMyVehicle); - } else { + CVehicle* pVehicle = m_pMyVehicle; + bool bDone = false; + if (m_pMyVehicle->IsBike()) { m_fHealth = 0.0f; - if (m_pMyVehicle && m_pMyVehicle->pDriver == this) { - SetRadioStation(); - m_pMyVehicle->SetStatus(STATUS_ABANDONED); + ((CBike*)m_pMyVehicle)->KnockOffRider(method, direction, this, false); + bDone = true; + } else { + if (m_pMyVehicle->GetVehicleAppearance() == VEHICLE_APPEARANCE_CAR) { + if (m_pMyVehicle->pDriver == this) { + if (m_pMyVehicle->GetStatus() == STATUS_SIMPLE) { + m_pMyVehicle->SetStatus(STATUS_PHYSICS); + CCarCtrl::SwitchVehicleToRealPhysics(m_pMyVehicle); + } + m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_NONE; + m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0; + m_pMyVehicle->AutoPilot.m_nTempAction = TEMPACT_HANDBRAKESTRAIGHT; + m_pMyVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 2000; + } } - SetDie(dieAnim, dieDelta, dieSpeed); - /* - if (damagedBy == FindPlayerPed() && damagedBy != this) { - // PlayerInfo stuff + // TODO(MIAMI): argument + if (m_pMyVehicle->CanPedExitCar(false)) { + SetObjective(OBJECTIVE_LEAVE_CAR_AND_DIE, m_pMyVehicle); + } else { + m_fHealth = 0.0f; + if (m_pMyVehicle && m_pMyVehicle->pDriver == this) { + SetRadioStation(); + m_pMyVehicle->SetStatus(STATUS_ABANDONED); + } + SetDie(dieAnim, dieDelta, dieSpeed); + + if (damagedBy == FindPlayerPed() && damagedBy != this) { + CWorld::Players[CWorld::PlayerInFocus].m_nHavocLevel += 10; + CWorld::Players[CWorld::PlayerInFocus].m_fMediaAttention += 5.f; + } } - */ } - for (int i = 0; i < ARRAY_SIZE(m_pMyVehicle->pPassengers); i++) { - CPed* passenger = m_pMyVehicle->pPassengers[i]; + for (int i = 0; i < ARRAY_SIZE(pVehicle->pPassengers); i++) { + CPed* passenger = pVehicle->pPassengers[i]; if (passenger && passenger != this && damagedBy) passenger->ReactToAttack(damagedBy); } - CPed *driverOfVeh = m_pMyVehicle->pDriver; + CPed *driverOfVeh = pVehicle->pDriver; if (driverOfVeh && driverOfVeh != this && damagedBy) driverOfVeh->ReactToAttack(damagedBy); @@ -3982,8 +4706,9 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi } else { CDarkel::RegisterKillNotByPlayer(this, method); } + if (bDone) + return true; } -#endif m_fHealth = 1.0f; return false; } @@ -3991,22 +4716,23 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi if (player == this) m_pMyVehicle->SetStatus(STATUS_PLAYER_DISABLED); - SetDie(NUM_ANIMS, 4.0f, 0.0f); + SetDie(NUM_STD_ANIMS, 4.0f, 0.0f); return true; } else { m_fHealth = 0.0f; SetDie(dieAnim, dieDelta, dieSpeed); if (damagedBy == player || damagedBy && damagedBy == FindPlayerVehicle()) { - - // There are PlayerInfo stuff here in VC CDarkel::RegisterKillByPlayer(this, method, headShot); + CWorld::Players[CWorld::PlayerInFocus].m_nHavocLevel += 10; + CWorld::Players[CWorld::PlayerInFocus].m_fMediaAttention += 5.f; m_threatEntity = player; } else { CDarkel::RegisterKillNotByPlayer(this, method); } if (method == WEAPONTYPE_DROWNING) bIsInTheAir = false; + // TODO(Miami): timesDrowned return true; } @@ -4044,7 +4770,7 @@ CPed::SetGetUp(void) } if (m_nPedState != PED_GETUP) { SetStoredState(); - m_nPedState = PED_GETUP; + SetPedState(PED_GETUP); } CVehicle *collidingVeh = (CVehicle*)m_pCollidingEntity; @@ -4052,7 +4778,7 @@ CPed::SetGetUp(void) if (veh && veh->m_vehType != VEHICLE_TYPE_BIKE || collidingVeh && collidingVeh->IsVehicle() && collidingVeh->m_vehType != VEHICLE_TYPE_BIKE && ((uint8)(CTimer::GetFrameCounter() + m_randomSeed + 5) % 8 || - CCollision::ProcessColModels(GetMatrix(), *GetColModel(), collidingVeh->GetMatrix(), *collidingVeh->GetColModel(), + CCollision::ProcessColModels(GetMatrix(), *GetColModel(), collidingVeh->GetMatrix(), *collidingVeh->GetColModel(), aTempPedColPts, nil, nil) > 0)) { bGetUpAnimStarted = false; @@ -4087,10 +4813,11 @@ CPed::SetGetUp(void) animAssoc->SetFinishCallback(PedGetupCB,this); } else { m_fHealth = 0.0f; - SetDie(NUM_ANIMS, 4.0f, 0.0f); + SetDie(NUM_STD_ANIMS, 4.0f, 0.0f); } } +// --MIAMI: Done void CPed::ClearInvestigateEvent(void) { @@ -4116,6 +4843,7 @@ CPed::ClearInvestigateEvent(void) SetMoveState(PEDMOVE_WALK); } +// --MIAMI: Done void CPed::ClearLeader(void) { @@ -4142,28 +4870,23 @@ CPed::ClearLook(void) ClearLookFlag(); } +// --MIAMI: Done void CPed::ClearObjective(void) { if (IsPedInControl() || m_nPedState == PED_DRIVING) { m_objective = OBJECTIVE_NONE; -#ifdef VC_PED_PORTS m_pedInObjective = nil; m_carInObjective = nil; -#endif - if (m_nPedState == PED_DRIVING && m_pMyVehicle) { + if (m_nPedState == PED_DRIVING && m_pMyVehicle) { if (m_pMyVehicle->pDriver != this) { -#if defined VC_PED_PORTS || defined FIX_BUGS if(!IsPlayer()) -#endif bWanderPathAfterExitingCar = true; SetObjective(OBJECTIVE_LEAVE_CAR, m_pMyVehicle); } -#ifdef VC_PED_PORTS m_nLastPedState = PED_NONE; -#endif } else { SetIdle(); SetMoveState(PEDMOVE_STILL); @@ -4173,12 +4896,14 @@ CPed::ClearObjective(void) } } +// --MIAMI: Done void CPed::ClearPause(void) { RestorePreviousState(); } +// --MIAMI: Done void CPed::ClearSeek(void) { @@ -4186,11 +4911,15 @@ CPed::ClearSeek(void) bRunningToPhone = false; } +// --MIAMI: Done bool CPed::SetWanderPath(int8 pathStateDest) { uint8 nextPathState; + if (IsPlayer()) + return false; + if (IsPedInControl()) { if (bKindaStayInSamePlace) { SetIdle(); @@ -4219,7 +4948,7 @@ CPed::SetWanderPath(int8 pathStateDest) // We did it, save next path state and return true m_nPathDir = nextPathState; - m_nPedState = PED_WANDER_PATH; + SetPedState(PED_WANDER_PATH); SetMoveState(PEDMOVE_WALK); bIsRunning = false; return true; @@ -4231,25 +4960,15 @@ CPed::SetWanderPath(int8 pathStateDest) } } +// --MIAMI: Done void CPed::ClearWeapons(void) { - CWeaponInfo *currentWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - RemoveWeaponModel(currentWeapon->m_nModelId); - - m_maxWeaponTypeAllowed = WEAPONTYPE_BASEBALLBAT; - m_currentWeapon = WEAPONTYPE_UNARMED; - - currentWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - AddWeaponModel(currentWeapon->m_nModelId); - for(int i = 0; i < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; i++) { - CWeapon &weapon = GetWeapon(i); - weapon.m_eWeaponType = WEAPONTYPE_UNARMED; - weapon.m_eWeaponState = WEAPONSTATE_READY; - weapon.m_nAmmoInClip = 0; - weapon.m_nAmmoTotal = 0; - weapon.m_nTimer = 0; + RemoveWeaponModel(-1); + for (int i = 0; i < ARRAY_SIZE(m_weapons); i++) { + GetWeapon(i).Shutdown(); } + SetCurrentWeapon(WEAPONTYPE_UNARMED); } void @@ -4278,17 +4997,18 @@ CPed::RestoreHeadingRateCB(CAnimBlendAssociation *assoc, void *arg) ((CPed*)arg)->m_headingRate = ((CPed*)arg)->m_pedStats->m_headingChangeRate; } +// --MIAMI: Done void CPed::RestorePreviousState(void) { - if(!CanSetPedState() || m_nPedState == PED_FALL) + if (!CanSetPedState() || m_nPedState == PED_FALL) return; if (m_nPedState == PED_GETUP && !bGetUpAnimStarted) return; if (InVehicle()) { - m_nPedState = PED_DRIVING; + SetPedState(PED_DRIVING); m_nLastPedState = PED_NONE; } else { if (m_nLastPedState == PED_NONE) { @@ -4305,21 +5025,23 @@ CPed::RestorePreviousState(void) SetIdle(); break; case PED_WANDER_PATH: - m_nPedState = PED_WANDER_PATH; + SetPedState(PED_WANDER_PATH); bIsRunning = false; if (bFindNewNodeAfterStateRestore) { if (m_pNextPathNode) { - CVector diff = m_pNextPathNode->GetPosition() - GetPosition(); + CVector nextNode = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); + CVector diff = nextNode - GetPosition(); if (diff.MagnitudeSqr() < sq(7.0f)) { SetMoveState(PEDMOVE_WALK); break; } } } - SetWanderPath(CGeneral::GetRandomNumber() & 7); + SetWanderPath(m_nPedState == PED_FOLLOW_PATH ? m_nPathDir : CGeneral::GetRandomNumber() & 7); break; default: - m_nPedState = m_nLastPedState; + PedState oldState = m_nLastPedState; + SetPedState(oldState); SetMoveState((eMoveState) m_nPrevMoveState); break; } @@ -4327,18 +5049,24 @@ CPed::RestorePreviousState(void) } } +// --MIAMI: Done void CPed::SetAimFlag(CEntity *to) { bIsAimingGun = true; bIsRestoringGun = false; + if (m_pLookTarget) + m_pLookTarget->CleanUpOldReference(&m_pLookTarget); m_pLookTarget = to; m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget); + if (m_pSeekTarget) + m_pSeekTarget->CleanUpOldReference(&m_pSeekTarget); m_pSeekTarget = to; m_pSeekTarget->RegisterReference((CEntity **) &m_pSeekTarget); m_lookTimer = 0; } +// --MIAMI: Done void CPed::SetAimFlag(float angle) { @@ -4348,74 +5076,103 @@ CPed::SetAimFlag(float angle) m_lookTimer = 0; m_pLookTarget = nil; m_pSeekTarget = nil; + + if (bIsDucking) + m_pedIK.m_flags &= ~CPedIK::AIMS_WITH_ARM; + if (CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAimWithArm) m_pedIK.m_flags |= CPedIK::AIMS_WITH_ARM; else m_pedIK.m_flags &= ~CPedIK::AIMS_WITH_ARM; } +// --MIAMI: Done void CPed::SetPointGunAt(CEntity *to) { if (to) { - SetLookFlag(to, true); + SetLookFlag(to, true, true); SetAimFlag(to); -#ifdef VC_PED_PORTS SetLookTimer(INT32_MAX); -#endif } - if (m_nPedState == PED_AIM_GUN || bIsDucking || m_nWaitState == WAITSTATE_PLAYANIM_DUCK) + CWeaponInfo* curWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + if (m_nPedState == PED_AIM_GUN || (bIsDucking && !IsPlayer()) || m_nWaitState == WAITSTATE_PLAYANIM_DUCK || curWeapon->m_AnimToPlay == ASSOCGRP_STD) return; if (m_nPedState != PED_ATTACK) SetStoredState(); - m_nPedState = PED_AIM_GUN; + SetPedState(PED_AIM_GUN); bIsPointingGunAt = true; - CWeaponInfo *curWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); SetMoveState(PEDMOVE_NONE); CAnimBlendAssociation *aimAssoc; - if (bCrouchWhenShooting) - aimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), curWeapon->m_Anim2ToPlay); - else - aimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), curWeapon->m_AnimToPlay); + if (bCrouchWhenShooting && bIsDucking && GetCrouchFireAnim(curWeapon)) { + aimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchFireAnim(curWeapon)); + } else { + aimAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_FIRE); + } if (!aimAssoc || aimAssoc->blendDelta < 0.0f) { - if (bCrouchWhenShooting) - aimAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, curWeapon->m_Anim2ToPlay, 4.0f); - else - aimAssoc = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, curWeapon->m_AnimToPlay); + if (bCrouchWhenShooting && bIsDucking && GetCrouchFireAnim(curWeapon)) { + aimAssoc = CAnimManager::BlendAnimation(GetClump(), curWeapon->m_AnimToPlay, GetCrouchFireAnim(curWeapon), 4.0f); + } else { + aimAssoc = CAnimManager::AddAnimation(GetClump(), curWeapon->m_AnimToPlay, ANIM_WEAPON_FIRE); + } aimAssoc->blendAmount = 0.0f; aimAssoc->blendDelta = 8.0f; } - if (to) + if (to && !IsPlayer()) Say(SOUND_PED_ATTACK); } +// --MIAMI: Done void CPed::SetAmmo(eWeaponType weaponType, uint32 ammo) { - if (HasWeapon(weaponType)) { - GetWeapon(weaponType).m_nAmmoTotal = ammo; + int slot = CWeaponInfo::GetWeaponInfo(weaponType)->m_nWeaponSlot; + if (slot == -1) + return; + + GetWeapon(slot).m_nAmmoTotal = ammo; + if (weaponType < WEAPONTYPE_TOTALWEAPONS && weaponType > WEAPONTYPE_UNARMED && CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType] >= 0) { + + // Looks like abandoned idea. This block never runs, ms_aMaxAmmoForWeapon is always -1. + GetWeapon(slot).m_nAmmoTotal = Min(CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType], GetWeapon(slot).m_nAmmoTotal); } else { - GetWeapon(weaponType).Initialise(weaponType, ammo); - m_maxWeaponTypeAllowed++; + GetWeapon(slot).m_nAmmoTotal = Min(99999, GetWeapon(slot).m_nAmmoTotal); } + int32 newClip = GetWeapon(slot).m_nAmmoTotal; + if (newClip >= GetWeapon(slot).m_nAmmoInClip) + newClip = GetWeapon(slot).m_nAmmoInClip; + GetWeapon(slot).m_nAmmoInClip = newClip; + + if (GetWeapon(slot).m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO && GetWeapon(slot).m_nAmmoTotal > 0) + GetWeapon(slot).m_eWeaponState = WEAPONSTATE_READY; } +// --MIAMI: Done void CPed::GrantAmmo(eWeaponType weaponType, uint32 ammo) { - if (HasWeapon(weaponType)) { - GetWeapon(weaponType).m_nAmmoTotal += ammo; + int slot = CWeaponInfo::GetWeaponInfo(weaponType)->m_nWeaponSlot; + if (slot == -1) + return; + + GetWeapon(slot).m_nAmmoTotal += ammo; + if (weaponType < WEAPONTYPE_TOTALWEAPONS && weaponType > WEAPONTYPE_UNARMED && CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType] >= 0) { + + // Looks like abandoned idea. This block never runs, ms_aMaxAmmoForWeapon is always -1. + GetWeapon(slot).m_nAmmoTotal = Min(CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType], GetWeapon(slot).m_nAmmoTotal); } else { - GetWeapon(weaponType).Initialise(weaponType, ammo); - m_maxWeaponTypeAllowed++; + GetWeapon(slot).m_nAmmoTotal = Min(99999, GetWeapon(slot).m_nAmmoTotal); } + + if (GetWeapon(slot).m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO && GetWeapon(slot).m_nAmmoTotal > 0) + GetWeapon(slot).m_eWeaponState = WEAPONSTATE_READY; } void @@ -4476,7 +5233,7 @@ CPed::SetEvasiveStep(CEntity *reason, uint8 animType) else if (animType < 2) stepAnim = ANIM_EV_STEP; else - stepAnim = NUM_ANIMS; + stepAnim = NUM_STD_ANIMS; } if (!RpAnimBlendClumpGetAssociation(GetClump(), stepAnim)) { CAnimBlendAssociation *stepAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, stepAnim, 8.0f); @@ -4604,38 +5361,24 @@ CPed::SetEvasiveDive(CPhysical *reason, uint8 onlyRandomJump) wanted->RegisterCrime_Immediately(CRIME_SPEEDING, GetPosition(), (uintptr)this, false); } } -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - else if (reason->IsVehicle()) { - if (veh->pDriver && veh->pDriver->IsPlayer()) { - CWanted* wanted = FindPlayerPed()->m_pWanted; - wanted->RegisterCrime(CRIME_RECKLESS_DRIVING, GetPosition(), (uintptr)this, false); - } - } -#endif } +// --MIAMI: Done void CPed::SetAttack(CEntity *victim) { CPed *victimPed = nil; + CWeaponInfo *curWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + CAnimBlendAssociation *animAssoc; + if (victim && victim->IsPed()) victimPed = (CPed*)victim; - CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_ARMED); - if (animAssoc) { - animAssoc->blendDelta = -1000.0f; - animAssoc->flags |= ASSOC_DELETEFADEDOUT; - } - - if (m_attackTimer > CTimer::GetTimeInMilliseconds() || m_nWaitState == WAITSTATE_SURPRISE) - return; - - if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_HGUN_RELOAD)) { - bIsAttacking = false; + if (m_attackTimer > CTimer::GetTimeInMilliseconds() || m_nWaitState == WAITSTATE_SURPRISE || (bIsDucking && !bCrouchWhenShooting)) return; - } - if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_AK_RELOAD)) { + if (curWeapon->m_bReload && + (RpAnimBlendClumpGetAssociation(GetClump(), GetReloadAnim(curWeapon)) || RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchReloadAnim(curWeapon)))) { if (!IsPlayer() || m_nPedState != PED_ATTACK || ((CPlayerPed*)this)->m_bHaveTargetSelected) bIsAttacking = false; else @@ -4644,20 +5387,16 @@ CPed::SetAttack(CEntity *victim) return; } - CWeaponInfo *curWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - if (curWeapon->m_eWeaponFire == WEAPON_FIRE_INSTANT_HIT && !IsPlayer()) { - if (GetWeapon()->HitsGround(this, nil, victim)) - return; - } - - if (GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED) { + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED || curWeapon->m_bFightMode || GetWeapon()->m_eWeaponType == WEAPONTYPE_BRASSKNUCKLE) { if (IsPlayer() || - (m_nPedState != PED_FIGHT && m_nMoveState != PEDMOVE_NONE && m_nMoveState != PEDMOVE_STILL && !(m_pedStats->m_flags & STAT_SHOPPING_BAGS))) { + (m_nPedState != PED_FIGHT && m_nMoveState != PEDMOVE_NONE && m_nMoveState != PEDMOVE_STILL + && !(m_pedStats->m_flags & STAT_SHOPPING_BAGS) && curWeapon->m_bPartialAttack)) { if (m_nPedState != PED_ATTACK) { - m_nPedState = PED_ATTACK; + SetPedState(PED_ATTACK); bIsAttacking = false; - animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, curWeapon->m_AnimToPlay, 8.0f); + + CAnimBlendAssociation *animAssoc = CAnimManager::BlendAnimation(GetClump(), curWeapon->m_AnimToPlay, ANIM_MELEE_ATTACK_START, 8.0f); animAssoc->SetRun(); if (animAssoc->currentTime == animAssoc->hierarchy->totalLength) animAssoc->SetCurrentTime(0.0f); @@ -4665,33 +5404,64 @@ CPed::SetAttack(CEntity *victim) animAssoc->SetFinishCallback(FinishedAttackCB, this); } } else { - StartFightAttack(CGeneral::GetRandomNumber() % 256); + StartFightAttack(CGeneral::GetRandomNumber()); + } + return; + } + + if (curWeapon->m_bPartialAttack && + (IsPlayer() && ((CPlayerPed*)this)->m_fMoveSpeed >= 1.0f || + m_nMoveState == PEDMOVE_WALK || m_nMoveState == PEDMOVE_RUN)) { + + if (m_nPedState != PED_ATTACK) { + SetPedState(PED_ATTACK); + bIsAttacking = false; + CAnimBlendAssociation* animAssoc = CAnimManager::BlendAnimation(GetClump(), curWeapon->m_AnimToPlay, ANIM_MELEE_ATTACK_START, 8.0f); + animAssoc->SetRun(); + if (animAssoc->currentTime == animAssoc->hierarchy->totalLength) + animAssoc->SetCurrentTime(0.0f); + + animAssoc->SetFinishCallback(FinishedAttackCB, this); } return; } + if (m_pSeekTarget) + m_pSeekTarget->CleanUpOldReference(&m_pSeekTarget); m_pSeekTarget = victim; if (m_pSeekTarget) m_pSeekTarget->RegisterReference((CEntity **) &m_pSeekTarget); if (curWeapon->m_bCanAim) { CVector aimPos = GetRight() * 0.1f + GetForward() * 0.2f + GetPosition(); + aimPos += GetUp() * 0.35f; CEntity *obstacle = CWorld::TestSphereAgainstWorld(aimPos, 0.2f, nil, true, false, false, true, false, false); - if (obstacle) - return; + if (obstacle) { + if(gaTempSphereColPoints[0].surfaceB != SURFACE_TRANSPARENT_CLOTH && gaTempSphereColPoints[0].surfaceB != SURFACE_METAL_CHAIN_FENCE && + gaTempSphereColPoints[0].surfaceB != SURFACE_WOOD_BENCH && gaTempSphereColPoints[0].surfaceB != SURFACE_SCAFFOLD_POLE) { + if (!IsPlayer()) { + bObstacleShowedUpDuringKillObjective = true; + m_shootTimer = 0; + SetAttackTimer(1500); + m_shotTime = CTimer::GetTimeInMilliseconds(); + } + return; + } + } m_pLookTarget = victim; if (victim) { m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget); m_pSeekTarget->RegisterReference((CEntity **) &m_pSeekTarget); } + if (m_pLookTarget) { SetAimFlag(m_pLookTarget); - } else { + } else if (this == FindPlayerPed() && TheCamera.Cams[0].Using3rdPersonMouseCam()) { + SetAimFlag(m_fRotationCur); + ((CPlayerPed*)this)->m_fFPSMoveHeading = TheCamera.Find3rdPersonQuickAimPitch(); + } else if (curWeapon->m_bCanAimWithArm) { SetAimFlag(m_fRotationCur); - - if (FindPlayerPed() == this && TheCamera.Cams[0].Using3rdPersonMouseCam()) - ((CPlayerPed*)this)->m_fFPSMoveHeading = TheCamera.Find3rdPersonQuickAimPitch(); } } if (m_nPedState == PED_ATTACK) { @@ -4699,7 +5469,7 @@ CPed::SetAttack(CEntity *victim) return; } - if (IsPlayer() || !victimPed || victimPed->IsPedInControl()) { + if (IsPlayer() || (!victimPed || victimPed->IsPedInControl())) { if (IsPlayer()) CPad::GetPad(0)->ResetAverageWeapon(); @@ -4713,7 +5483,7 @@ CPed::SetAttack(CEntity *victim) ClearAimFlag(); // This condition is pointless - if (pointBlankStatus == POINT_BLANK_FOR_WANTED_PED || !victimPed) + if (pointBlankStatus == POINT_BLANK_FOR_WANTED_PED || !victimPed && (IsPlayer() || !m_carInObjective)) StartFightAttack(200); } else { if (!curWeapon->m_bCanAim) @@ -4722,21 +5492,42 @@ CPed::SetAttack(CEntity *victim) if (m_nPedState != PED_AIM_GUN) SetStoredState(); - m_nPedState = PED_ATTACK; + SetPedState(PED_ATTACK); SetMoveState(PEDMOVE_NONE); - if (bCrouchWhenShooting) { - animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_RBLOCK_CSHOOT, 4.0f); + if (bCrouchWhenShooting && bIsDucking && !!curWeapon->m_bCrouchFire) { + CAnimBlendAssociation* curMoveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchFireAnim(curWeapon)); + if (curMoveAssoc) { + if (strcmp(CAnimManager::GetAnimAssociation(curWeapon->m_AnimToPlay, GetCrouchFireAnim(curWeapon))->hierarchy->name, curMoveAssoc->hierarchy->name) != 0) { + delete curMoveAssoc; + } + } + animAssoc = CAnimManager::BlendAnimation(GetClump(), curWeapon->m_AnimToPlay, GetCrouchFireAnim(curWeapon), 8.0f); } else { float animDelta = 8.0f; if (curWeapon->m_eWeaponFire == WEAPON_FIRE_MELEE) animDelta = 1000.0f; - if (GetWeapon()->m_eWeaponType != WEAPONTYPE_BASEBALLBAT - || CheckForPedsOnGroundToAttack(this, nil) < PED_ON_THE_FLOOR) { - animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, curWeapon->m_AnimToPlay, animDelta); + AnimationId fireAnim; + if (curWeapon->m_bThrow) + fireAnim = ANIM_THROWABLE_START_THROW; + else if (CGame::nastyGame && (curWeapon->m_bGround2nd || curWeapon->m_bGround3rd)) { + PedOnGroundState pedOnGround = CheckForPedsOnGroundToAttack(this, nil); + if (pedOnGround > PED_IN_FRONT_OF_ATTACKER || pedOnGround == NO_PED && bIsStanding && m_pCurSurface && m_pCurSurface->IsVehicle()) { + fireAnim = GetFireAnimGround(curWeapon, false); + } else { + fireAnim = GetFireAnimNotDucking(curWeapon); + } } else { - animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, curWeapon->m_Anim2ToPlay, animDelta); + fireAnim = GetFireAnimNotDucking(curWeapon); } + + CAnimBlendAssociation* curFireAssoc = RpAnimBlendClumpGetAssociation(GetClump(), fireAnim); + if (curFireAssoc) { + if (strcmp(CAnimManager::GetAnimAssociation(curWeapon->m_AnimToPlay, fireAnim)->hierarchy->name, curFireAssoc->hierarchy->name) != 0) { + delete curFireAssoc; + } + } + animAssoc = CAnimManager::BlendAnimation(GetClump(), curWeapon->m_AnimToPlay, fireAnim, animDelta); } animAssoc->SetRun(); @@ -4751,14 +5542,15 @@ CPed::SetAttack(CEntity *victim) if (GetWeapon()->m_eWeaponType == WEAPONTYPE_BASEBALLBAT && victimPed->m_nPedState == PED_GETUP) SetWaitState(WAITSTATE_SURPRISE, nil); - SetLookFlag(victim, false); + SetLookFlag(victim, true, true); SetLookTimer(100); } +// --MIAMI: Done void CPed::StartFightAttack(uint8 buttonPressure) { - if (!IsPedInControl() || m_attackTimer > CTimer::GetTimeInMilliseconds()) + if (!IsPedInControl() || (m_attackTimer > CTimer::GetTimeInMilliseconds() && buttonPressure != 0)) return; if (m_nPedState == PED_FIGHT) { @@ -4770,57 +5562,75 @@ CPed::StartFightAttack(uint8 buttonPressure) SetStoredState(); if (m_nWaitState != WAITSTATE_FALSE) { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); RestoreHeadingRate(); } - m_nPedState = PED_FIGHT; - m_fightButtonPressure = 0; - RpAnimBlendClumpRemoveAssociations(GetClump(), ASSOC_REPEAT); - CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WALK_START); - - if (animAssoc) { - animAssoc->flags |= ASSOC_DELETEFADEDOUT; - animAssoc->blendDelta = -1000.0f; - } - - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN_STOP); + CAnimBlendAssociation* animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN_STOP); if (!animAssoc) animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN_STOP_R); if (animAssoc) { - animAssoc->flags |= ASSOC_DELETEFADEDOUT; - animAssoc->blendDelta = -1000.0f; RestoreHeadingRate(); } - SetMoveState(PEDMOVE_NONE); m_nStoredMoveState = PEDMOVE_NONE; - - CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_IDLE)->blendAmount = 1.0f; - - CPed *pedOnGround = nil; - if (IsPlayer() && CheckForPedsOnGroundToAttack(this, &pedOnGround) > PED_IN_FRONT_OF_ATTACKER) { - m_curFightMove = FIGHTMOVE_GROUNDKICK; - } else if (m_pedStats->m_flags & STAT_SHOPPING_BAGS) { - m_curFightMove = FIGHTMOVE_ROUNDHOUSE; + bool fightWithWeapon = false; + CAnimBlendAssociation *fightIdleAssoc; + + CWeaponInfo* weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED) { + if (GetFightIdleWithMeleeAnim(weaponInfo)) { + fightIdleAssoc = CAnimManager::BlendAnimation(GetClump(), weaponInfo->m_AnimToPlay, GetFightIdleWithMeleeAnim(weaponInfo), 1000.0f); + fightWithWeapon = true; + } else { + fightIdleAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_IDLE, 1000.0f); + } } else { - m_curFightMove = FIGHTMOVE_STDPUNCH; + fightIdleAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_IDLE, 1000.0f); } + m_lastFightMove = FIGHTMOVE_IDLE; + m_curFightMove = IsPlayer() ? ChooseAttackPlayer(buttonPressure, fightWithWeapon) : ChooseAttackAI(buttonPressure, fightWithWeapon); - if (pedOnGround && IsPlayer()) { - m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( - pedOnGround->GetPosition().x, pedOnGround->GetPosition().y, - GetPosition().x, GetPosition().y); + SetPedState(PED_FIGHT); + m_fightButtonPressure = 0; - m_fRotationDest = CGeneral::LimitRadianAngle(m_fRotationDest); - m_fRotationCur = m_fRotationDest; - m_lookTimer = 0; - SetLookFlag(pedOnGround, true); - SetLookTimer(1500); + if (m_curFightMove > FIGHTMOVE_NULL && m_curFightMove != FIGHTMOVE_IDLE) { + animAssoc = CAnimManager::BlendAnimation(GetClump(), m_curFightMove < FIGHTMOVE_MELEE1 ? ASSOCGRP_STD : weaponInfo->m_AnimToPlay, + tFightMoves[m_curFightMove].animId, 8.0f); + + if (weaponInfo->m_AnimToPlay != ASSOCGRP_KNIFE || m_curFightMove < FIGHTMOVE_MELEE1) { + if (m_curFightMove == FIGHTMOVE_BACKKICK) + animAssoc->speed = 1.15f; + else + animAssoc->speed = 0.8f; + } else { + switch (GetWeapon()->m_eWeaponType) { + case WEAPONTYPE_SCREWDRIVER: + case WEAPONTYPE_KNIFE: + animAssoc->speed = 1.05f; + break; + case WEAPONTYPE_GOLFCLUB: + case WEAPONTYPE_NIGHTSTICK: + case WEAPONTYPE_BASEBALLBAT: + case WEAPONTYPE_HAMMER: + case WEAPONTYPE_KATANA: + animAssoc->speed = 0.8f; + break; + case WEAPONTYPE_CLEAVER: + case WEAPONTYPE_MACHETE: + animAssoc->speed = 0.9f; + break; + } + } + if (IsPlayer()) + animAssoc->SetCurrentTime(0.08f); + + animAssoc->SetFinishCallback(FinishFightMoveCB, this); + } else { + m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 2000; } - animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, tFightMoves[m_curFightMove].animId, 4.0f); - animAssoc->SetFinishCallback(FinishFightMoveCB, this); + m_fightState = FIGHTSTATE_NO_MOVE; m_takeAStepAfterAttack = false; bIsAttacking = true; @@ -4829,10 +5639,11 @@ CPed::StartFightAttack(uint8 buttonPressure) nPlayerInComboMove = 0; } +// --MIAMI: Done void CPed::LoadFightData(void) { - float startFireTime, endFireTime, comboFollowOnTime, strikeRadius; + float startFireTime, endFireTime, comboFollowOnTime, strikeRadius, extendReachMultiplier; int damage, flags; char line[256], moveName[32], animName[32], hitLevel; int moveId = 0; @@ -4861,12 +5672,13 @@ CPed::LoadFightData(void) sscanf( &line[lp], - "%s %f %f %f %f %c %s %d %d", + "%s %f %f %f %f %f %c %s %d %d", moveName, &startFireTime, &endFireTime, &comboFollowOnTime, &strikeRadius, + &extendReachMultiplier, &hitLevel, animName, &damage, @@ -4879,6 +5691,7 @@ CPed::LoadFightData(void) tFightMoves[moveId].endFireTime = endFireTime / 30.0f; tFightMoves[moveId].comboFollowOnTime = comboFollowOnTime / 30.0f; tFightMoves[moveId].strikeRadius = strikeRadius; + tFightMoves[moveId].extendReachMultiplier = extendReachMultiplier; tFightMoves[moveId].damage = damage; tFightMoves[moveId].flags = flags; @@ -4902,16 +5715,19 @@ CPed::LoadFightData(void) break; } - if (strncmp(animName, "null", 4) != 0) { - animAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, animName); - tFightMoves[moveId].animId = (AnimationId)animAssoc->animId; - } else { - tFightMoves[moveId].animId = ANIM_WALK; + if (strncmp(animName, "default", 8) != 0) { + if (strncmp(animName, "null", 5) != 0) { + animAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, animName); + tFightMoves[moveId].animId = (AnimationId)animAssoc->animId; + } else { + tFightMoves[moveId].animId = ANIM_WALK; + } } moveId++; } } +// --MIAMI: Done // Actually GetLocalDirectionTo(Turn/Look) int CPed::GetLocalDirection(const CVector2D &posOffset) @@ -4926,198 +5742,631 @@ CPed::GetLocalDirection(const CVector2D &posOffset) return direction; } +// --MIAMI: Done bool -CPed::FightStrike(CVector &touchedNodePos) +CPed::FightStrike(CVector &touchedNodePos, bool fightWithWeapon) { - CColModel *ourCol; + CColModel *hisCol; CVector attackDistance; - ePedPieceTypes closestPedPiece = PEDPIECE_TORSO; - float maxDistanceToBeBeaten; + float maxDistanceToBeat; CPed *nearPed; - int state = m_fightState; - bool pedFound = false; + CVector extendedTouchPoint; - if (state == FIGHTSTATE_JUST_ATTACKED) - return false; + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + float radius = tFightMoves[m_curFightMove].strikeRadius; + if (fightWithWeapon) + radius = weaponInfo->m_fRadius; - // Pointless code - if (state > FIGHTSTATE_NO_MOVE) - attackDistance = touchedNodePos - m_vecHitLastPos; + if (m_fightState == FIGHTSTATE_JUST_ATTACKED) + return false; + + // TODO(Miami): BreakGlassPhysically for (int i = 0; i < m_numNearPeds; i++) { + int8 pedFound = 0; nearPed = m_nearPeds[i]; - if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED) - maxDistanceToBeBeaten = nearPed->GetBoundRadius() + tFightMoves[m_curFightMove].strikeRadius + 0.1f; + if (!fightWithWeapon && GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && GetWeapon()->m_eWeaponType != WEAPONTYPE_BRASSKNUCKLE) + maxDistanceToBeat = nearPed->GetBoundRadius() + radius + 0.1f; else - maxDistanceToBeBeaten = nearPed->GetBoundRadius() + tFightMoves[m_curFightMove].strikeRadius; + maxDistanceToBeat = nearPed->GetBoundRadius() + radius; - if (nearPed->bUsesCollision || nearPed->m_nPedState == PED_DEAD) { + if ((nearPed->bUsesCollision || nearPed->m_nPedState == PED_DEAD) && (m_pedInObjective != FindPlayerPed() || nearPed == FindPlayerPed())) { CVector nearPedCentre; + + // Have to animate a skinned clump because the initial col model is useless + hisCol = ((CPedModelInfo*)CModelInfo::GetModelInfo(nearPed->GetModelIndex()))->AnimatePedColModelSkinnedWorld(nearPed->GetClump()); + nearPed->GetBoundCentre(nearPedCentre); CVector potentialAttackDistance = nearPedCentre - touchedNodePos; // He can beat us - if (sq(maxDistanceToBeBeaten) > potentialAttackDistance.MagnitudeSqr()) { + if (sq(maxDistanceToBeat) > potentialAttackDistance.MagnitudeSqr()) { -#ifdef PED_SKIN - // Have to animate a skinned clump because the initial col model is useless - if(IsClumpSkinned(GetClump())) - ourCol = ((CPedModelInfo *)CModelInfo::GetModelInfo(GetModelIndex()))->AnimatePedColModelSkinned(GetClump()); - else -#endif - if (nearPed->OnGround() || !nearPed->IsPedHeadAbovePos(-0.3f)) { - ourCol = &CTempColModels::ms_colModelPedGroundHit; - } else { -#ifdef ANIMATE_PED_COL_MODEL - ourCol = CPedModelInfo::AnimatePedColModel(((CPedModelInfo *)CModelInfo::GetModelInfo(GetModelIndex()))->GetHitColModel(), - RpClumpGetFrame(GetClump())); -#else - ourCol = ((CPedModelInfo*)CModelInfo::GetModelInfo(m_modelIndex))->GetHitColModel(); -#endif - } - - for (int j = 0; j < ourCol->numSpheres; j++) { - attackDistance = nearPed->GetPosition() + ourCol->spheres[j].center; + for (int j = 0; j < hisCol->numSpheres; j++) { + attackDistance = hisCol->spheres[j].center; attackDistance -= touchedNodePos; - CColSphere *ourPieces = ourCol->spheres; - float maxDistanceToBeat = ourPieces[j].radius + tFightMoves[m_curFightMove].strikeRadius; + CColSphere *hisPieces = hisCol->spheres; + maxDistanceToBeat = hisPieces[j].radius + radius; // We can beat him too if (sq(maxDistanceToBeat) > attackDistance.MagnitudeSqr()) { - pedFound = true; - closestPedPiece = (ePedPieceTypes) ourPieces[j].piece; + FightHitPed(nearPed, touchedNodePos, attackDistance, hisPieces[j].piece); + pedFound = 1; break; } } } + if (!pedFound && !fightWithWeapon) { + extendedTouchPoint = touchedNodePos - GetPosition(); + if (DotProduct(touchedNodePos - GetPosition(), nearPed->GetPosition() - GetPosition()) > 0.f) { + if (m_curFightMove == FIGHTMOVE_GROUNDKICK) { + extendedTouchPoint += tFightMoves[FIGHTMOVE_GROUNDKICK].extendReachMultiplier * GetForward(); + } else { + extendedTouchPoint.x *= tFightMoves[m_curFightMove].extendReachMultiplier; + extendedTouchPoint.y *= tFightMoves[m_curFightMove].extendReachMultiplier; + } + pedFound = -1; + extendedTouchPoint += GetPosition(); + } + } + if (pedFound == -1) { + CVector nearPedCentre = nearPed->GetBoundCentre(); + if (sq(maxDistanceToBeat) > (nearPedCentre - extendedTouchPoint).MagnitudeSqr()) { + + for (int j = 0; j < hisCol->numSpheres; j++) { + attackDistance = hisCol->spheres[j].center; + attackDistance -= extendedTouchPoint; + CColSphere* hisPieces = hisCol->spheres; + float maxDistanceToBeat2 = hisPieces[j].radius + tFightMoves[m_curFightMove].strikeRadius; + + // We can beat him too + if (sq(maxDistanceToBeat2) > attackDistance.MagnitudeSqr()) { + FightHitPed(nearPed, extendedTouchPoint, attackDistance, hisPieces[j].piece); + break; + } + } + } + } } - if (pedFound) - break; } - if (pedFound) { - if (nearPed->IsPlayer() && nearPed->m_nPedState == PED_GETUP) - return false; - float oldVictimHealth = nearPed->m_fHealth; - CVector bloodPos = 0.5f * attackDistance + touchedNodePos; - int damageMult = tFightMoves[m_curFightMove].damage * ((CGeneral::GetRandomNumber() & 1) + 2) + 1; + if (m_fightState == FIGHTSTATE_NO_MOVE) + m_fightState = FIGHTSTATE_1; + + m_vecHitLastPos = *touchedNodePos; + return false; +} - CVector2D diff (GetPosition() - nearPed->GetPosition()); - int direction = nearPed->GetLocalDirection(diff); - if (IsPlayer()) { - if (((CPlayerPed*)this)->m_bAdrenalineActive) - damageMult = 20; - } else { - damageMult *= m_pedStats->m_attackStrength; +// --MIAMI: Done +void +CPed::FightHitPed(CPed *victim, CVector &touchPoint, CVector &dir, int16 piece) +{ + if (victim->IsPlayer() && victim->m_nPedState == PED_GETUP) + return; + + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + bool fightingWithWeapon = false; + int damageMult = tFightMoves[m_curFightMove].damage * ((CGeneral::GetRandomNumber() & 1) + 2) + 1; + + if (weaponInfo->m_bFightMode) { + fightingWithWeapon = true; + if (m_curFightMove >= FIGHTMOVE_MELEE1) { + damageMult = weaponInfo->m_nDamage; + if (m_curFightMove == FIGHTMOVE_MELEE3 && GetWeapon()->m_eWeaponType != WEAPONTYPE_SCREWDRIVER) + damageMult *= 5; } + } - // Change direction if we used kick. - if (m_curFightMove == FIGHTMOVE_KICK) { - if (CGeneral::GetRandomNumber() & 1) { - direction++; - if (direction > 3) - direction -= 4; - } + if (IsPlayer()) { + if (((CPlayerPed*)this)->m_bAdrenalineActive) + damageMult = 20; + } else if (!fightingWithWeapon) { + damageMult *= m_pedStats->m_attackStrength; + } + + float oldVictimHealth = victim->m_fHealth; + CVector bloodPos = 0.5f * dir + touchPoint; + CVector2D diff(GetPosition() - victim->GetPosition()); + int direction = victim->GetLocalDirection(diff); + + bool brassKnucklePunch = false; + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_BRASSKNUCKLE) { + if (m_curFightMove == FIGHTMOVE_PUNCHHOOK || m_curFightMove == FIGHTMOVE_PUNCHJAB || m_curFightMove == FIGHTMOVE_BACKLEFT || + m_curFightMove == FIGHTMOVE_STDPUNCH || m_curFightMove == FIGHTMOVE_PUNCH) { + brassKnucklePunch = true; + damageMult *= 1.5f; } - nearPed->ReactToAttack(this); + } + victim->ReactToAttack(this); - // Mostly unused. if > 5, ANIM_HIT_WALK will be run, that's it. - int unk2; - if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && !nearPed->IsPlayer()) - unk2 = 101; + // Mostly unused. if > 5, ANIM_HIT_BIGSTEP will be run, that's it. + int unk2; + if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && GetWeapon()->m_eWeaponType != WEAPONTYPE_BRASSKNUCKLE && + !victim->IsPlayer() && !fightingWithWeapon) + unk2 = 101; + else + unk2 = damageMult; + + victim->StartFightDefend(direction, tFightMoves[m_curFightMove].hitLevel, unk2); + PlayHitSound(victim); + m_fightState = FIGHTSTATE_JUST_ATTACKED; + RpAnimBlendClumpGetAssociation(GetClump(), tFightMoves[m_curFightMove].animId)->speed = 0.6f; + + if (!victim->DyingOrDead()) { + if(fightingWithWeapon) + victim->InflictDamage(this, GetWeapon()->m_eWeaponType, damageMult, (ePedPieceTypes)piece, direction); else - unk2 = damageMult; + victim->InflictDamage(this, WEAPONTYPE_UNARMED, damageMult * 3.0f, (ePedPieceTypes)piece, direction); + } - nearPed->StartFightDefend(direction, tFightMoves[m_curFightMove].hitLevel, unk2); - PlayHitSound(nearPed); - m_fightState = FIGHTSTATE_JUST_ATTACKED; - RpAnimBlendClumpGetAssociation(GetClump(), tFightMoves[m_curFightMove].animId)->speed = 0.6f; - if (!nearPed->DyingOrDead()) { - nearPed->InflictDamage(this, WEAPONTYPE_UNARMED, damageMult * 3.0f, closestPedPiece, direction); - } + if (CGame::nastyGame && weaponInfo->m_AnimToPlay == ASSOCGRP_KNIFE && m_curFightMove >= FIGHTMOVE_MELEE1 + && victim->GetIsOnScreen()) { - if (CGame::nastyGame - && tFightMoves[m_curFightMove].hitLevel > HITLEVEL_MEDIUM - && nearPed->m_nPedState == PED_DIE - && nearPed->GetIsOnScreen()) { + static float particleRightLen = 0.05f; + static float particleUpLen = 0.05f; - // Just for blood particle. We will restore it below. - attackDistance /= (10.0f * attackDistance.Magnitude()); - for(int i=0; i<4; i++) { - CParticle::AddParticle(PARTICLE_BLOOD, bloodPos, attackDistance, nil, 0.0f, 0, 0, 0, 0); - } + // Just for particles. We will restore it below. + dir /= (20.0f * dir.Magnitude()); + if (m_curFightMove == FIGHTMOVE_MELEE1) { + float rightMult = -particleRightLen; + dir += particleUpLen * GetUp() + rightMult * GetRight(); + + } else if (m_curFightMove == FIGHTMOVE_MELEE2) { + float upMult = 2.0f * particleUpLen; + dir += particleRightLen * GetRight() + upMult * GetUp(); } - if (!nearPed->OnGround()) { - float curVictimHealth = nearPed->m_fHealth; + CParticle::AddParticle(PARTICLE_BLOOD_SPURT, bloodPos, dir, nil, 0.0f, 0, 0, 0, 0); + CParticle::AddParticle(PARTICLE_BLOOD_SPURT, bloodPos, dir, nil, 0.0f, 0, 0, 0, 0); + if (IsPlayer()) { + CParticle::AddParticle(PARTICLE_BLOOD_SPURT, bloodPos, dir, nil, 0.0f, 0, 0, 0, 0); + CParticle::AddParticle(PARTICLE_BLOOD_SPURT, bloodPos, dir, nil, 0.0f, 0, 0, 0, 0); + } + if (!(CGeneral::GetRandomNumber() & 3)) { + CParticle::AddParticle(PARTICLE_TEST, bloodPos, dir, nil, 0.0f, 0, 0, 0, 0); + } + } else if (CGame::nastyGame && (tFightMoves[m_curFightMove].hitLevel > HITLEVEL_MEDIUM || fightingWithWeapon) + && victim->GetIsOnScreen()) { + + // Just for particles. We will restore it below. + dir /= (10.0f * dir.Magnitude()); + for (int i = 0; i < 4; i++) { + CParticle::AddParticle(PARTICLE_BLOOD, bloodPos, dir, nil, 0.0f, 0, 0, 0, 0); + } + } + + eWeaponType weaponType = GetWeapon()->m_eWeaponType; + if (!fightingWithWeapon) { + if (!victim->OnGround()) { + float curVictimHealth = victim->m_fHealth; if (curVictimHealth > 0.0f - && (curVictimHealth < 40.0f && oldVictimHealth > 40.0f && !nearPed->IsPlayer() - || nearPed->m_fHealth < 20.0f && oldVictimHealth > 20.0f - || GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && IsPlayer() - || nearPed->m_pedStats->m_flags & STAT_ONE_HIT_KNOCKDOWN)) { + && (curVictimHealth < 30.0f && oldVictimHealth > 30.0f + || weaponType != WEAPONTYPE_UNARMED && weaponType != WEAPONTYPE_BRASSKNUCKLE && IsPlayer() + || victim->m_pedStats->m_flags & STAT_ONE_HIT_KNOCKDOWN || brassKnucklePunch)) { - nearPed->SetFall(0, (AnimationId)(direction + ANIM_KO_SKID_FRONT), 0); - if (nearPed->m_nPedState == PED_FALL) - nearPed->bIsStanding = false; + victim->SetFall(0, (AnimationId)(direction + ANIM_KO_SKID_FRONT), 0); + if (victim->m_nPedState == PED_FALL) + victim->bIsStanding = false; } } - if (nearPed->m_nPedState == PED_DIE || !nearPed->bIsStanding) { - attackDistance = nearPed->GetPosition() - GetPosition(); - attackDistance.Normalise(); - attackDistance.z = 1.0f; - nearPed->bIsStanding = false; + } + + if (victim->m_nPedState == PED_DIE || !victim->bIsStanding) { + dir = victim->GetPosition() - GetPosition(); + dir.Normalise(); + dir.z = 1.0f; + victim->bIsStanding = false; - float moveMult; - if (m_curFightMove == FIGHTMOVE_GROUNDKICK) { - moveMult = Min(damageMult * 0.6f, 4.0f); + float moveMult; + if (fightingWithWeapon) { + moveMult = Min(damageMult * 0.02f, 1.0f); + } else if (m_curFightMove == FIGHTMOVE_GROUNDKICK) { + moveMult = Min(damageMult * 0.6f, 4.0f); + } else { + if (victim->m_nPedState != PED_DIE || damageMult >= 20) { + moveMult = damageMult; } else { - if (nearPed->m_nPedState != PED_DIE || damageMult >= 20) { - moveMult = damageMult; + moveMult = Min(damageMult * 2.0f, 14.0f); + } + } + + victim->ApplyMoveForce(moveMult * 0.6 * dir); + } + + if (weaponType != WEAPONTYPE_KNIFE && weaponType != WEAPONTYPE_MACHETE + && weaponType != WEAPONTYPE_KATANA && weaponType != WEAPONTYPE_CHAINSAW) { + + if (victim->m_nPedType == PEDTYPE_COP) + CEventList::RegisterEvent(EVENT_ASSAULT_POLICE, EVENT_ENTITY_PED, victim, this, 2000); + else + CEventList::RegisterEvent(EVENT_ASSAULT, EVENT_ENTITY_PED, victim, this, 2000); + } else { + if (victim->m_nPedType == PEDTYPE_COP) + CEventList::RegisterEvent(EVENT_ASSAULT_NASTYWEAPON_POLICE, EVENT_ENTITY_PED, victim, this, 2000); + else + CEventList::RegisterEvent(EVENT_ASSAULT_NASTYWEAPON, EVENT_ENTITY_PED, victim, this, 2000); + } +} + +// --MIAMI: Done +int32 +CPed::ChooseAttackPlayer(uint8 buttonPressure, bool fightWithWeapon) +{ + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + const float maxAttackDist = 2.7f; + float weaponAttackDist = 2.0f; + CPed *victimPed = nil; + CPed *walkUpTo = nil; + CPed *groundAttackDeadPed = nil; + CPed *groundAttackAlivePed = nil; + if (fightWithWeapon) + weaponAttackDist = weaponInfo->m_fRange; + + bool willWalkUp = false; + PedFightMoves choosenMove = FIGHTMOVE_IDLE; + int numPedsWeCanReach = 0; + if (m_takeAStepAfterAttack) + willWalkUp = true; + + float groundAttackDeadAngle, groundAttackAliveAngle, walkAngle, victimAngle, distToVictim; + + for (int i = 0; i < m_numNearPeds; ++i) { + CPed *nearPed = m_nearPeds[i]; + CVector distVec(nearPed->GetPosition() - GetPosition()); + float dist = distVec.Magnitude(); + if (dist < maxAttackDist) { + float nearPedAngle = CGeneral::LimitRadianAngle(distVec.Heading()); + m_fRotationCur = CGeneral::LimitRadianAngle(m_fRotationCur); + float neededTurn = Abs(nearPedAngle - m_fRotationCur); + if (neededTurn > PI) + neededTurn = TWOPI - neededTurn; + + if (!nearPed->OnGroundOrGettingUp() && nearPed->m_nWaitState != WAITSTATE_SUN_BATHE_IDLE) { + if (!willWalkUp || neededTurn <= DEGTORAD(45.0f)) { + + if (neededTurn <= DEGTORAD(30.0f) || nearPed->m_pedInObjective == this + && (nearPed->m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || nearPed->m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS)) { + + if (dist < weaponAttackDist) { + if (!victimPed + || nearPed->m_attackTimer < victimPed->m_attackTimer && nearPed->m_attackTimer > CTimer::GetTimeInMilliseconds() - 100) { + victimPed = nearPed; + victimAngle = nearPedAngle; + distToVictim = dist; + } + ++numPedsWeCanReach; + + } else { + if (neededTurn < DEGTORAD(30.0f)) { + walkUpTo = nearPed; + walkAngle = nearPedAngle; + } + } + } + } + } else if (CGame::nastyGame && dist < 1.2f && neededTurn < DEGTORAD(55.0f)) { + if (!nearPed->DyingOrDead() || groundAttackDeadPed) { + if (!nearPed->IsPedHeadAbovePos(-0.3f)) { + groundAttackAlivePed = nearPed; + groundAttackAliveAngle = nearPedAngle; + } } else { - moveMult = Min(damageMult * 2.0f, 14.0f); + groundAttackDeadPed = nearPed; + groundAttackDeadAngle = nearPedAngle; } + ++numPedsWeCanReach; + + } else if (dist > 1.4f && dist < maxAttackDist && neededTurn < DEGTORAD(30.0f)) { + if (!walkUpTo) { + walkUpTo = nearPed; + walkAngle = nearPedAngle; + } +#ifdef FIX_BUGS + if(dist < 2.1f) +#endif + ++numPedsWeCanReach; } + } + } + + if (victimPed) { + float adjustedAngleDiff = victimAngle - m_fRotationCur + DEGTORAD(30.0f); + if (adjustedAngleDiff < 0.0f) + adjustedAngleDiff += TWOPI; + + int16 dir = Floor(adjustedAngleDiff / DEGTORAD(60.0f)); + + // Just focus on who we're fighting with, don't care peds on ground + if (numPedsWeCanReach < 2 || fightWithWeapon) { + float angleDiff = Abs(victimAngle - m_fRotationCur); + if (angleDiff > PI) + angleDiff = TWOPI - angleDiff; + + if (angleDiff < DEGTORAD(60.0f)) + dir = 0; // forward + } + int16 randVal = CGeneral::GetRandomNumber() & 3; + switch (dir) { + case 0: // forward + if (fightWithWeapon) { + if (distToVictim < 0.95f - 0.2f && m_nPedState == PED_FIGHT) { + choosenMove = FIGHTMOVE_KNEE; + } else { + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CLEAVER) { + if (distToVictim < 0.85f * weaponInfo->m_fRange) + choosenMove = FIGHTMOVE_MELEE1; + else + choosenMove = FIGHTMOVE_SHUFFLE_F; + } else { + float weaponRange = weaponInfo->m_fRange; + if (distToVictim < 0.75f * weaponRange && GetWeapon()->m_eWeaponType != WEAPONTYPE_SCREWDRIVER) { + if (m_lastFightMove == FIGHTMOVE_MELEE1 && GetFinishingAttackAnim(weaponInfo)) { + choosenMove = FIGHTMOVE_MELEE2; + } else if (m_lastFightMove == FIGHTMOVE_MELEE2 && GetFinishingAttackAnim(weaponInfo)) { + choosenMove = FIGHTMOVE_MELEE3; + } else { + choosenMove = FIGHTMOVE_MELEE1; + } + } else if (distToVictim < weaponRange && GetFinishingAttackAnim(weaponInfo)) { + choosenMove = FIGHTMOVE_MELEE3; + } else { + choosenMove = FIGHTMOVE_SHUFFLE_F; + } + } + } + } else if (distToVictim < 0.95f && m_nPedState == PED_FIGHT) { + choosenMove = FIGHTMOVE_KNEE; + + } else if (distToVictim < 1.4f) { + if (m_curFightMove == FIGHTMOVE_PUNCHJAB) { + choosenMove = FIGHTMOVE_PUNCH; + + } else if (m_curFightMove != FIGHTMOVE_PUNCH || randVal != 1) { + if (randVal == 2) + choosenMove = FIGHTMOVE_PUNCH; + else + choosenMove = FIGHTMOVE_PUNCHJAB; + } else { + choosenMove = FIGHTMOVE_LONGKICK; + } + } else { + choosenMove = FIGHTMOVE_LONGKICK; + } + break; + case 1: + choosenMove = FIGHTMOVE_FWDLEFT; + break; + case 2: + choosenMove = FIGHTMOVE_BACKLEFT; + break; + case 3: + choosenMove = FIGHTMOVE_BACKKICK; + break; + case 4: + choosenMove = FIGHTMOVE_BACKRIGHT; + break; + default: + choosenMove = FIGHTMOVE_FWDRIGHT; + break; + } + + // forward + if (dir == 0) { + m_fRotationDest = CGeneral::LimitRadianAngle(victimAngle); + } else { + m_fRotationDest = victimAngle - dir * DEGTORAD(60.0f); + m_fRotationDest = CGeneral::LimitRadianAngle(m_fRotationDest); + } + + m_fRotationCur = m_fRotationDest; + Say(SOUND_PED_ATTACK); + + } else if (groundAttackAlivePed || groundAttackDeadPed) { + if (fightWithWeapon && weaponInfo->m_bGround2nd) { + choosenMove = FIGHTMOVE_MELEE2; + } else if (fightWithWeapon && weaponInfo->m_bGround3rd) { + choosenMove = FIGHTMOVE_MELEE3; + } else { + choosenMove = FIGHTMOVE_GROUNDKICK; + } + if (groundAttackAlivePed) + m_fRotationDest = groundAttackAliveAngle; + else + m_fRotationDest = groundAttackDeadAngle; + + m_fRotationCur = m_fRotationDest; + m_lookTimer = 0; + if (groundAttackAlivePed) + SetLookFlag(groundAttackAlivePed, 1, 0); + else + SetLookFlag(groundAttackDeadPed, 1, 0); + + SetLookTimer(1500u); - nearPed->ApplyMoveForce(moveMult * 0.6f * attackDistance); + } else if (walkUpTo) { + choosenMove = FIGHTMOVE_SHUFFLE_F; + m_fRotationCur = m_fRotationDest = walkAngle; + m_lookTimer = 0; + SetLookFlag(walkUpTo, true); + SetLookTimer(1500); + + } else if (fightWithWeapon) { + // No enemy, fight with space + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_SCREWDRIVER) { + choosenMove = FIGHTMOVE_MELEE3; + } else { + if (m_lastFightMove == FIGHTMOVE_MELEE1 && GetFinishingAttackAnim(weaponInfo)) { + choosenMove = FIGHTMOVE_MELEE2; + } else if (m_lastFightMove == FIGHTMOVE_MELEE2 && GetFinishingAttackAnim(weaponInfo)) { + choosenMove = FIGHTMOVE_MELEE3; + } else { + choosenMove = FIGHTMOVE_MELEE1; + } + } + } else { + // Max number GetRandomNumberInRange returns is max-1 +#ifdef FIX_BUGS + switch (CGeneral::GetRandomNumberInRange(0,4)) { +#else + switch (CGeneral::GetRandomNumberInRange(0,3)) { +#endif + case 0: + choosenMove = FIGHTMOVE_PUNCHJAB; + break; + case 1: + choosenMove = FIGHTMOVE_PUNCH; + break; + case 2: + choosenMove = FIGHTMOVE_LONGKICK; + break; + case 3: + choosenMove = FIGHTMOVE_KNEE; + break; + default: + break; } - CEventList::RegisterEvent(nearPed->m_nPedType == PEDTYPE_COP ? EVENT_ASSAULT_POLICE : EVENT_ASSAULT, EVENT_ENTITY_PED, nearPed, this, 2000); } + return choosenMove; +} - if (m_fightState == FIGHTSTATE_NO_MOVE) - m_fightState = FIGHTSTATE_1; +// --MIAMI: Done +int32 +CPed::ChooseAttackAI(uint8 buttonPressure, bool fightWithWeapon) +{ + eWeaponType weapon = GetWeapon()->m_eWeaponType; + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(weapon); + if (!fightWithWeapon && weapon != WEAPONTYPE_UNARMED && weapon != WEAPONTYPE_BRASSKNUCKLE) { + return FIGHTMOVE_PUNCH; + } + + if (!m_pedInObjective) + return FIGHTMOVE_IDLE; + if (buttonPressure == 0) + return FIGHTMOVE_IDLE; + + uint16 pedFeatures = m_pedStats->m_flags; + bool punchOnly = !!(pedFeatures & STAT_PUNCH_ONLY); + bool canRoundhouse = !!(pedFeatures & STAT_CAN_ROUNDHOUSE); + bool canKneeHead = !!(pedFeatures & STAT_CAN_KNEE_HEAD); + bool canKick = !!(pedFeatures & STAT_CAN_KICK); + bool hasShoppingBags = !!(pedFeatures & STAT_SHOPPING_BAGS); + + CVector distVec(m_pedInObjective->GetPosition() - GetPosition()); + float dist = distVec.Magnitude(); + m_fRotationDest = CGeneral::LimitRadianAngle(distVec.Heading()); + m_fRotationCur = m_fRotationDest; + + if (fightWithWeapon) { + if (m_pedInObjective->OnGroundOrGettingUp()) { + if (!CGame::nastyGame || dist >= 1.2f || m_pedInObjective->IsPlayer() + || m_pedInObjective->m_nPedState != PED_DEAD && m_pedInObjective->IsPedHeadAbovePos(-0.3f)) { + return FIGHTMOVE_IDLE; + } - m_vecHitLastPos = *touchedNodePos; - return false; + if (weaponInfo->m_bGround2nd) + return FIGHTMOVE_MELEE2; + if (weaponInfo->m_bGround3rd) + return FIGHTMOVE_MELEE3; + + return FIGHTMOVE_GROUNDKICK; + } + if (dist < 2.f) { + if (m_curFightMove == FIGHTMOVE_MELEE1) { + if (GetSecondFireAnim(weaponInfo)) + return FIGHTMOVE_MELEE2; + } + if (m_curFightMove == FIGHTMOVE_MELEE2) { + if (GetFinishingAttackAnim(weaponInfo)) + return FIGHTMOVE_MELEE3; + } + return FIGHTMOVE_MELEE1; + } + return FIGHTMOVE_SHUFFLE_F; + } + if (!hasShoppingBags) { + if (punchOnly) { + if (dist < 1.4f) + return FIGHTMOVE_PUNCH; + } else { + if (m_pedInObjective->OnGroundOrGettingUp()) { + if (!CGame::nastyGame || dist >= 1.2f || m_pedInObjective->IsPlayer() + || m_pedInObjective->m_nPedState != PED_DEAD && m_pedInObjective->IsPedHeadAbovePos(-0.3f)) { + + return FIGHTMOVE_IDLE; + } else { + return FIGHTMOVE_GROUNDKICK; + } + } + if (dist < 0.95f && canKneeHead) + return FIGHTMOVE_KNEE; + if (dist < 1.4f) + return FIGHTMOVE_PUNCH; + if (dist < 2.f && canKick) { + int nextMove = FIGHTMOVE_LONGKICK; + if (canRoundhouse && CGeneral::GetRandomNumber() & 1) + nextMove = FIGHTMOVE_ROUNDHOUSE; + return nextMove; + } + } + return FIGHTMOVE_SHUFFLE_F; + } + if (dist < 2.f) + return FIGHTMOVE_ROUNDHOUSE; + else + return FIGHTMOVE_SHUFFLE_F; } +// --MIAMI: Done void CPed::SetFall(int extraTime, AnimationId animId, uint8 evenIfNotInControl) { + if (m_attachedTo) + return; + if (!IsPedInControl() && (!evenIfNotInControl || DyingOrDead())) return; ClearLookFlag(); ClearAimFlag(); SetStoredState(); - m_nPedState = PED_FALL; - CAnimBlendAssociation *fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), animId); - - if (fallAssoc) { - fallAssoc->SetCurrentTime(0.0f); - fallAssoc->blendAmount = 0.0f; - fallAssoc->blendDelta = 8.0f; - fallAssoc->SetRun(); + SetPedState(PED_FALL); + CAnimBlendAssociation *fallAssoc = nil; + if (animId == NUM_STD_ANIMS) { + if (IsPlayer()) { + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_ROLLOUT_LHS); + if (!fallAssoc) + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_ROLLOUT_RHS); + } } else { - fallAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, animId, 8.0f); + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), animId); + + if (fallAssoc) { + fallAssoc->SetCurrentTime(0.0f); + fallAssoc->blendAmount = 0.0f; + fallAssoc->blendDelta = 8.0f; + fallAssoc->SetRun(); + } + else { + fallAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, animId, 8.0f); + } + if (animId == ANIM_BIKE_FALL_R) + fallAssoc->SetCurrentTime(0.4f); } if (extraTime == -1) { m_getUpTimer = UINT32_MAX; } else if (fallAssoc) { if (IsPlayer()) { - m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength - + CTimer::GetTimeInMilliseconds() - + 500.0f; + if (fallAssoc->animId != ANIM_CAR_ROLLOUT_LHS && fallAssoc->animId != ANIM_CAR_ROLLOUT_RHS) { + m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength + + CTimer::GetTimeInMilliseconds() + + 500.0f; + } else { + m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength + + CTimer::GetTimeInMilliseconds() + - 1000.0f * fallAssoc->currentTime + + 100.0f; + } } else { m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength + CTimer::GetTimeInMilliseconds() @@ -5133,6 +6382,7 @@ CPed::SetFall(int extraTime, AnimationId animId, uint8 evenIfNotInControl) bFallenDown = true; } +// --MIAMI: Done void CPed::SetFlee(CEntity *fleeFrom, int time) { @@ -5140,7 +6390,7 @@ CPed::SetFlee(CEntity *fleeFrom, int time) return; SetStoredState(); - m_nPedState = PED_FLEE_ENTITY; + SetPedState(PED_FLEE_ENTITY); bUsePedNodeSeek = true; SetMoveState(PEDMOVE_RUN); m_fleeFrom = fleeFrom; @@ -5163,6 +6413,7 @@ CPed::SetFlee(CEntity *fleeFrom, int time) } } +// --MIAMI: Done void CPed::SetFlee(CVector2D const &from, int time) { @@ -5171,7 +6422,7 @@ CPed::SetFlee(CVector2D const &from, int time) if (m_nPedState != PED_FLEE_ENTITY) { SetStoredState(); - m_nPedState = PED_FLEE_POS; + SetPedState(PED_FLEE_POS); SetMoveState(PEDMOVE_RUN); m_fleeFromPosX = from.x; m_fleeFromPosY = from.y; @@ -5193,15 +6444,19 @@ CPed::SetFlee(CVector2D const &from, int time) } } +// --MIAMI: Only some part is done void CPed::SetWaitState(eWaitState state, void *time) { - AnimationId waitAnim = NUM_ANIMS; + AnimationId waitAnim = NUM_STD_ANIMS; CAnimBlendAssociation *animAssoc; if (!IsPedInControl()) return; + if (m_nWaitState == WAITSTATE_RIOT && state != WAITSTATE_FALSE) + return; + if (state != m_nWaitState) FinishedWaitCB(nil, this); @@ -5227,6 +6482,8 @@ CPed::SetWaitState(eWaitState state, void *time) case WAITSTATE_LOOK_SHOP: case WAITSTATE_LOOK_ACCIDENT: case WAITSTATE_FACEOFF_GANG: + case WAITSTATE_RIOT: + case WAITSTATE_STRIPPER: break; case WAITSTATE_DOUBLEBACK: m_headingRate = 0.0f; @@ -5273,6 +6530,7 @@ CPed::SetWaitState(eWaitState state, void *time) animAssoc->SetFinishCallback(RestoreHeadingRateCB, this); #endif + // Random char as passenger? Cop, medic etc.? if (m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER && CharCreatedBy == RANDOM_CHAR && m_nPedState == PED_SEEK_CAR) { ClearObjective(); RestorePreviousState(); @@ -5293,10 +6551,10 @@ CPed::SetWaitState(eWaitState state, void *time) case WAITSTATE_PLAYANIM_COWER: waitAnim = ANIM_HANDSCOWER; case WAITSTATE_PLAYANIM_HANDSUP: - if (waitAnim == NUM_ANIMS) + if (waitAnim == NUM_STD_ANIMS) waitAnim = ANIM_HANDSUP; case WAITSTATE_PLAYANIM_HANDSCOWER: - if (waitAnim == NUM_ANIMS) + if (waitAnim == NUM_STD_ANIMS) waitAnim = ANIM_HANDSCOWER; m_headingRate = 0.0f; if (time) @@ -5310,10 +6568,10 @@ CPed::SetWaitState(eWaitState state, void *time) case WAITSTATE_PLAYANIM_DUCK: waitAnim = ANIM_DUCK_DOWN; case WAITSTATE_PLAYANIM_TAXI: - if (waitAnim == NUM_ANIMS) + if (waitAnim == NUM_STD_ANIMS) waitAnim = ANIM_IDLE_TAXI; case WAITSTATE_PLAYANIM_CHAT: - if (waitAnim == NUM_ANIMS) + if (waitAnim == NUM_STD_ANIMS) waitAnim = ANIM_IDLE_CHAT; if (time) m_nWaitTimer = CTimer::GetTimeInMilliseconds() + *(int*)time; @@ -5335,57 +6593,116 @@ CPed::SetWaitState(eWaitState state, void *time) animAssoc->SetFinishCallback(RestoreHeadingRateCB, this); #endif break; + case WAITSTATE_SIT_DOWN: + animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_SEAT_DOWN, 4.0f); + animAssoc->SetFinishCallback(FinishedWaitCB, this); + m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 10000; + break; + case WAITSTATE_SIT_UP: + animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_SEAT_UP, 4.0f); + animAssoc->SetFinishCallback(FinishedWaitCB, this); + m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 100000; + break; + case WAITSTATE_SIT_IDLE: + animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_SEAT_IDLE, 5000.0f); + animAssoc->SetFinishCallback(FinishedWaitCB, this); + if (time) + m_nWaitTimer = CTimer::GetTimeInMilliseconds() + *(int*)time; + else + m_nWaitTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(25000, 30000); + break; + case WAITSTATE_USE_ATM: + animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_ATM, 5000.0f); + animAssoc->SetFinishCallback(FinishedWaitCB, this); + if (time) + m_nWaitTimer = CTimer::GetTimeInMilliseconds() + *(int*)time; + else + m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 100000; + break; + case WAITSTATE_FAST_FALL: + SetFall(-1, ANIM_KO_SKID_FRONT, true); + break; + case WAITSTATE_BOMBER: + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_BOMBER, 4.0f); + m_nWaitTimer = CTimer::GetTimeInMilliseconds() + *(int*)time; + break; + case WAITSTATE_LANCESITTING: + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_LANCE, ANIM_SUNBATHE, 4.0f); + break; + case WAITSTATE_SUN_BATHE_PRE: + case WAITSTATE_SUN_BATHE_DOWN: + case WAITSTATE_SUN_BATHE_IDLE: + case WAITSTATE_GROUND_ATTACK: + case WAITSTATE_PLAYANIM_HANDSUP_SIMPLE: default: - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); RestoreHeadingRate(); return; } m_nWaitState = state; } - +// --MIAMI: Done void CPed::PlayHitSound(CPed *hitTo) { // That was very complicated to reverse for me... - // First index is our fight move ID (from 1 to 12, total 12), second is the one of we fight with (from 13 to 22, total 10). + // First index is our fight move ID (from 1 to 17, total 17), second is the one of we fight with (from 18 to 27, total 10). enum { - S33 = SOUND_FIGHT_PUNCH_33, - S34 = SOUND_FIGHT_KICK_34, - S35 = SOUND_FIGHT_HEADBUTT_35, - S36 = SOUND_FIGHT_PUNCH_36, - S37 = SOUND_FIGHT_PUNCH_37, - S38 = SOUND_FIGHT_CLOSE_PUNCH_38, - S39 = SOUND_FIGHT_PUNCH_39, - S40 = SOUND_FIGHT_PUNCH_OR_KICK_BELOW_40 , - S41 = SOUND_FIGHT_PUNCH_41, - S42 = SOUND_FIGHT_PUNCH_FROM_BEHIND_42, - S43 = SOUND_FIGHT_KNEE_OR_KICK_43, - S44 = SOUND_FIGHT_KICK_44, + S37 = SOUND_FIGHT_37, + S38 = SOUND_FIGHT_38, + S39 = SOUND_FIGHT_39, + S40 = SOUND_FIGHT_40, + S41 = SOUND_FIGHT_41, + S42 = SOUND_FIGHT_42, + S43 = SOUND_FIGHT_43, + S44 = SOUND_FIGHT_44, + S45 = SOUND_FIGHT_45, + S46 = SOUND_FIGHT_46, + S47 = SOUND_FIGHT_47, + S48 = SOUND_FIGHT_48, NO_SND = SOUND_NO_SOUND }; - uint16 hitSoundsByFightMoves[12][10] = { - {S39,S42,S43,S43,S39,S39,S39,S39,S39,S42}, - {NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND}, - {NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND,NO_SND}, - {S39,S39,S39,S39,S33,S43,S39,S39,S39,S39}, - {S39,S39,S39,S39,S35,S39,S38,S38,S39,S39}, - {S39,S39,S39,S39,S33,S39,S41,S36,S39,S39}, - {S39,S39,S39,S39,S37,S40,S38,S38,S39,S39}, - {S39,S39,S39,S39,S34,S43,S44,S37,S39,S39}, - {S39,S39,S39,S39,S34,S43,S44,S37,S39,S39}, - {S39,S39,S39,S39,S34,S43,S44,S37,S39,S40}, - {S39,S39,S39,S39,S33,S39,S41,S37,S39,S40}, - {S39,S39,S39,S39,S39,S39,S39,S39,S33,S33} + const uint16 hitSoundsByFightMoves[17][10] = { + { S37, S46, S41, S41, S46, S46, S40, S41, S43, S40 }, + { NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND }, + { NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND, NO_SND }, + { S46, S46, S46, S46, S37, S47, S37, S38, S43, S38 }, + { S46, S46, S46, S46, S46, S46, S40, S41, S43, S46 }, + { S46, S46, S46, S46, S46, S46, S40, S41, S43, S40 }, + { S46, S46, S46, S46, S46, S46, S40, S41, S43, S40 }, + { S46, S46, S37, S46, S37, S47, S40, S47, S43, S37 }, + { S46, S46, S46, S46, S46, S46, S43, S44, S43, S43 }, + { S37, S46, S46, S46, S38, S47, S40, S38, S43, S46 }, + { S46, S37, S46, S37, S39, S46, S40, S39, S43, S37 }, + { S46, S37, S46, S46, S38, S47, S40, S38, S43, S46 }, + { S37, S37, S46, S46, S38, S47, S48, S38, S43, S37 }, + { S46, S46, S46, S46, S37, S46, S40, S38, S43, S46 }, + { S46, S46, S46, S37, S39, S46, S40, S39, S43, S46 }, + { S37, S46, S46, S46, S37, S46, S40, S37, S43, S46 }, + { S43, S43, S43, S43, S43, S43, S43, S43, S43, S43 } }; - // This is why first dimension is between FightMove 1 and 12. - if (m_curFightMove == FIGHTMOVE_NULL || m_curFightMove >= FIGHTMOVE_HITFRONT) + eWeaponType weapon = GetWeapon()->m_eWeaponType; + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(weapon); + if (weaponInfo->m_AnimToPlay == ASSOCGRP_KNIFE) { + if (m_curFightMove >= FIGHTMOVE_MELEE1) { + if (m_curFightMove == FIGHTMOVE_MELEE3) { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_BAT_ATTACK, (weapon << 8) | 3); + } else { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_KNIFE_ATTACK, (weapon << 8) | 3); + } + return; + } + } + + // This is why first dimension is between FightMove 1 and 17. + if (m_curFightMove <= FIGHTMOVE_NULL || m_curFightMove >= FIGHTMOVE_HITFRONT) return; uint16 soundId; - // And this is why second dimension is between 13 and 22. + // And this is why second dimension is between 18 and 27. if (hitTo->m_curFightMove > FIGHTMOVE_GROUNDKICK && hitTo->m_curFightMove < FIGHTMOVE_IDLE2NORM) { soundId = hitSoundsByFightMoves[m_curFightMove - FIGHTMOVE_STDPUNCH][hitTo->m_curFightMove - FIGHTMOVE_HITFRONT]; @@ -5398,9 +6715,10 @@ CPed::PlayHitSound(CPed *hitTo) } if (soundId != NO_SND) - DMAudio.PlayOneShot(m_audioEntityId, soundId, 0.0f); + DMAudio.PlayOneShot(m_audioEntityId, soundId, (weapon << 8) | 3); } +// --MIAMI: Done void CPed::CollideWithPed(CPed *collideWith) { @@ -5413,6 +6731,15 @@ CPed::CollideWithPed(CPed *collideWith) int waitTime = 0; if (weAreMissionChar || !collideWith->IsPlayer() || collideWith->m_nPedState != PED_MAKE_CALL) { + if (m_nWaitState == WAITSTATE_SUN_BATHE_IDLE) { + SetGetUp(); + return; + } + if (collideWith->m_nWaitState == WAITSTATE_SUN_BATHE_IDLE) { + collideWith->SetGetUp(); + return; + } + bool weDontLookToHim = DotProduct(posDiff, GetForward()) > 0.0f; bool heLooksToUs = DotProduct(posDiff, collideWith->GetForward()) < 0.0f; @@ -5420,10 +6747,8 @@ CPed::CollideWithPed(CPed *collideWith) if ((!IsPlayer() || ((CPlayerPed*)this)->m_fMoveSpeed <= 1.8f) && (IsPlayer() || heIsMissionChar && weAreMissionChar || m_nMoveState != PEDMOVE_RUN && m_nMoveState != PEDMOVE_SPRINT -#ifdef VC_PED_PORTS || m_objective == OBJECTIVE_FOLLOW_CHAR_IN_FORMATION && m_pedInObjective == collideWith - || collideWith->m_objective == OBJECTIVE_FOLLOW_CHAR_IN_FORMATION && collideWith->m_pedInObjective == this -#endif + || collideWith->m_objective == OBJECTIVE_FOLLOW_CHAR_IN_FORMATION && collideWith->m_pedInObjective == this )) { if (m_objective != OBJECTIVE_FOLLOW_CHAR_IN_FORMATION && m_objective != OBJECTIVE_GOTO_CHAR_ON_FOOT) { @@ -5452,14 +6777,55 @@ CPed::CollideWithPed(CPed *collideWith) SetDirectionToWalkAroundObject(collideWith); } } else { - if (weAreMissionChar || m_pedStats->m_fear <= 100 - collideWith->m_pedStats->m_temper - || (collideWith->IsPlayer() || collideWith->m_nMoveState == PEDMOVE_NONE || collideWith->m_nMoveState == PEDMOVE_STILL) && - (!collideWith->IsPlayer() || ((CPlayerPed*)collideWith)->m_fMoveSpeed <= 1.0f)) { - SetDirectionToWalkAroundObject(collideWith); - if (!weAreMissionChar) - Say(SOUND_PED_CHAT); + if (FindPlayerPed() != m_pedInObjective + || m_objective != OBJECTIVE_KILL_CHAR_ANY_MEANS && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT + || collideWith == m_pedInObjective) { + + if (weAreMissionChar || m_pedStats->m_fear <= 100 - collideWith->m_pedStats->m_temper + || (collideWith->IsPlayer() || collideWith->m_nMoveState == PEDMOVE_NONE || collideWith->m_nMoveState == PEDMOVE_STILL) && + (!collideWith->IsPlayer() || ((CPlayerPed*)collideWith)->m_fMoveSpeed <= 1.0f)) { + SetDirectionToWalkAroundObject(collideWith); + if (!weAreMissionChar) + Say(SOUND_PED_CHAT); + } else { + SetEvasiveStep(collideWith, 2); + } + } else if (collideWith->m_nMoveState != PEDMOVE_STILL && GetWeapon()->IsTypeMelee() + && collideWith->m_pedInObjective == m_pedInObjective) { + + int colliderIndexAtPlayersKillList = -1; + int ourIndexAtPlayersKillList = -1; + for (int i = 0; i < ARRAY_SIZE(((CPlayerPed*)m_pedInObjective)->m_pMeleeList); i++) { + CPed *pedInKillList = ((CPlayerPed*)m_pedInObjective)->m_pMeleeList[i]; + if (pedInKillList == this) { + ourIndexAtPlayersKillList = i; + } else if (pedInKillList == collideWith) { + colliderIndexAtPlayersKillList = i; + } + } + bool weAreCloserToTargetThenCollider = false; + if ((GetPosition() - m_vecSeekPos).MagnitudeSqr2D() < (collideWith->GetPosition() - m_vecSeekPos).MagnitudeSqr2D()) + weAreCloserToTargetThenCollider = true; + + if (ourIndexAtPlayersKillList > 0 && !weAreCloserToTargetThenCollider) { + if (colliderIndexAtPlayersKillList > 0) { + int time = 300; + SetWaitState(WAITSTATE_CROSS_ROAD_LOOK, &time); + m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + time; + + } else if (collideWith->m_pedInObjective == FindPlayerPed()) { + ((CPlayerPed*)m_pedInObjective)->RemovePedFromMeleeList(this); + int time = 500; + SetWaitState(WAITSTATE_CROSS_ROAD_LOOK, &time); + m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + time; + } + } else if (!weAreCloserToTargetThenCollider) { + int time = 300; + SetWaitState(WAITSTATE_CROSS_ROAD_LOOK, &time); + m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + time; + } } else { - SetEvasiveStep(collideWith, 2); + SetDirectionToWalkAroundObject(collideWith); } } } else { @@ -5474,20 +6840,14 @@ CPed::CollideWithPed(CPed *collideWith) } else { TurnBody(); SetAttack(collideWith); -#ifdef VC_PED_PORTS m_fRotationCur = 0.3f + m_fRotationCur; m_fRotationDest = m_fRotationCur; -#endif } m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(250, 450); } } } else { -#ifdef VC_PED_PORTS if (m_pedInObjective && (collideWith == m_pedInObjective || collideWith->m_pedInObjective == m_pedInObjective) && CTimer::GetTimeInMilliseconds() > m_nPedStateTimer) { -#else - if (m_pedInObjective && collideWith == m_pedInObjective && CTimer::GetTimeInMilliseconds() > m_nPedStateTimer) { -#endif if (heLooksToUs) { SetEvasiveStep(collideWith, 1); m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 3000; @@ -5496,11 +6856,8 @@ CPed::CollideWithPed(CPed *collideWith) if (m_pedStats != collideWith->m_pedStats) { - if (collideWith->m_pedStats->m_fear <= 100 - m_pedStats->m_temper -#ifdef VC_PED_PORTS - || collideWith->IsPlayer() || CTimer::GetTimeInMilliseconds() < m_nPedStateTimer -#endif - ) { + if (collideWith->m_pedStats->m_fear <= 100 - m_pedStats->m_temper || collideWith->IsPlayer() + || CTimer::GetTimeInMilliseconds() < m_nPedStateTimer) { if (collideWith->IsPlayer()) { // He's on our right side @@ -5520,9 +6877,7 @@ CPed::CollideWithPed(CPed *collideWith) TurnBody(); animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_PPUNCH, 8.0f); animAssoc->flags |= ASSOC_FADEOUTWHENDONE; -#ifdef VC_PED_PORTS m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 2000; -#endif if (!heIsMissionChar) { CVector2D posDiff2D(posDiff); int direction = collideWith->GetLocalDirection(posDiff2D); @@ -5532,11 +6887,9 @@ CPed::CollideWithPed(CPed *collideWith) } } } - } else if (collideWith->m_pedStats->m_defendWeakness <= 1.5f || heIsMissionChar -#ifdef VC_PED_PORTS - || m_pedStats->m_defendWeakness <= collideWith->m_pedStats->m_defendWeakness -#endif - ) { + } else if (collideWith->m_pedStats->m_defendWeakness <= 1.5f || heIsMissionChar || + m_pedStats->m_defendWeakness <= collideWith->m_pedStats->m_defendWeakness) { + // He looks us and we're not at his right side if (heLooksToUs && DotProduct(posDiff,collideWith->GetRight()) > 0.0f) { CVector moveForce = GetRight(); @@ -5566,7 +6919,7 @@ CPed::CollideWithPed(CPed *collideWith) animAssoc->flags |= ASSOC_FADEOUTWHENDONE; collideWith->m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 1000; if (m_nPedState == PED_ATTACK) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_FIGHT_PUNCH_39, 0.0f); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_FIGHT_46, 0.0f); } } else { // We're at his right side @@ -5589,7 +6942,7 @@ CPed::CollideWithPed(CPed *collideWith) } if (m_nPedState == PED_ATTACK && collideWith->IsPedInControl()) - DMAudio.PlayOneShot(m_audioEntityId, SOUND_FIGHT_PUNCH_39, 0.0f); + DMAudio.PlayOneShot(m_audioEntityId, SOUND_49, 0.0f); collideWith->SetFall(3000, animToPlay, 0); } @@ -5632,6 +6985,7 @@ CPed::CollideWithPed(CPed *collideWith) } } +// --MIAMI: Done void CPed::CreateDeadPedMoney(void) { @@ -5639,54 +6993,37 @@ CPed::CreateDeadPedMoney(void) return; int skin = GetModelIndex(); - if ((skin >= MI_COP && skin <= MI_FIREMAN) || CharCreatedBy == MISSION_CHAR || bInVehicle) + + if ((skin >= MI_COP && skin <= MI_FIREMAN) || (CharCreatedBy == MISSION_CHAR && !bMoneyHasBeenGivenByScript) || bInVehicle) return; - int money = CGeneral::GetRandomNumber() % 60; + int money = m_nPedMoney; if (money < 10) return; - if (money == 43) - money = 700; - - int pickupCount = money / 40 + 1; - int moneyPerPickup = money / pickupCount; - - for(int i = 0; i < pickupCount; i++) { - // (CGeneral::GetRandomNumber() % 256) * PI / 128 gives a float up to something TWOPI-ish. - float pickupX = 1.5f * Sin((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().x; - float pickupY = 1.5f * Cos((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().y; - bool found = false; - float groundZ = CWorld::FindGroundZFor3DCoord(pickupX, pickupY, GetPosition().z, &found) + 0.5f; - if (found) { - CPickups::GenerateNewOne(CVector(pickupX, pickupY, groundZ), MI_MONEY, PICKUP_MONEY, moneyPerPickup + (CGeneral::GetRandomNumber() & 7)); - } - } + CVector pickupPos = GetPosition(); + CPickups::CreateSomeMoney(pickupPos, money); + m_nPedMoney = 0; } +// --MIAMI: Done void -CPed::CreateDeadPedWeaponPickups(void) +CPed::CreateDeadPedPickupCoors(float *x, float *y, float *z) { bool found = false; - float angleToPed; CVector pickupPos; - if (bInVehicle) - return; - - for(int i = 0; i < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; i++) { +#define NUMBER_OF_ATTEMPTS 32 + for (int i = 0; i < NUMBER_OF_ATTEMPTS; i++) { - eWeaponType weapon = GetWeapon(i).m_eWeaponType; - int weaponAmmo = GetWeapon(i).m_nAmmoTotal; - if (weapon == WEAPONTYPE_UNARMED || weapon == WEAPONTYPE_DETONATOR || weaponAmmo == 0) - continue; - - angleToPed = i * 1.75f; pickupPos = GetPosition(); - pickupPos.x += 1.5f * Sin(angleToPed); - pickupPos.y += 1.5f * Cos(angleToPed); + pickupPos.x = 1.5f * Sin((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().x; + pickupPos.y = 1.5f * Cos((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().y; pickupPos.z = CWorld::FindGroundZFor3DCoord(pickupPos.x, pickupPos.y, pickupPos.z, &found) + 0.5f; + if (!found) + continue; + CVector pedPos = GetPosition(); pedPos.z += 0.3f; @@ -5694,25 +7031,59 @@ CPed::CreateDeadPedWeaponPickups(void) float distance = pedToPickup.Magnitude(); // outer edge of pickup - distance = (distance + 0.3f) / distance; + distance = (distance + 0.4f) / distance; CVector pickupPos2 = pedPos; pickupPos2 += distance * pedToPickup; - // pickup must be on ground and line to its edge must be clear - if (!found || CWorld::GetIsLineOfSightClear(pickupPos2, pedPos, true, false, false, false, false, false, false)) { - // otherwise try another position (but disregard second check apparently) - angleToPed += 3.14f; - pickupPos = GetPosition(); - pickupPos.x += 1.5f * Sin(angleToPed); - pickupPos.y += 1.5f * Cos(angleToPed); - pickupPos.z = CWorld::FindGroundZFor3DCoord(pickupPos.x, pickupPos.y, pickupPos.z, &found) + 0.5f; + if ((pickupPos - FindPlayerCoors()).Magnitude2D() > 2.0f || i > NUMBER_OF_ATTEMPTS / 2) { + + if (i > NUMBER_OF_ATTEMPTS / 2 || !CPickups::TestForPickupsInBubble(pickupPos, 1.3f)) { + + if (CWorld::GetIsLineOfSightClear(pickupPos2, pedPos, + true, i < NUMBER_OF_ATTEMPTS / 2, false, i < NUMBER_OF_ATTEMPTS / 2, false, false, false)) { + + if (i > NUMBER_OF_ATTEMPTS / 2 || !CWorld::TestSphereAgainstWorld(pickupPos, 1.2f, nil, false, true, false, false, false, false)) { + *x = pickupPos.x; + *y = pickupPos.y; + *z = pickupPos.z; + return; + } + } + } + } + } + *x = GetPosition().x; + *y = GetPosition().y; + *z = GetPosition().z + 0.4f; +#undef NUMBER_OF_ATTEMPTS +} + +// --MIAMI: Done +void +CPed::CreateDeadPedWeaponPickups(void) +{ + CVector pickupPos; + + if (bInVehicle) + return; + + for(int i = 0; i < TOTAL_WEAPON_SLOTS; i++) { + + eWeaponType weapon = GetWeapon(i).m_eWeaponType; + int weaponAmmo = GetWeapon(i).m_nAmmoTotal; + if (weapon == WEAPONTYPE_UNARMED || weapon == WEAPONTYPE_DETONATOR || (weaponAmmo == 0 && !GetWeapon(i).IsTypeMelee())) + continue; + + int quantity = Min(weaponAmmo, AmmoForWeapon_OnStreet[weapon] / 2); + CreateDeadPedPickupCoors(&pickupPos.x, &pickupPos.y, &pickupPos.z); + if (!CPickups::TryToMerge_WeaponType(pickupPos, weapon, PICKUP_ONCE_TIMEOUT, quantity, false)) { + CPickups::GenerateNewOne_WeaponType(pickupPos, weapon, PICKUP_ONCE_TIMEOUT, Min(weaponAmmo, quantity)); } - if (found) - CPickups::GenerateNewOne_WeaponType(pickupPos, weapon, PICKUP_ONCE_TIMEOUT, Min(weaponAmmo, AmmoForWeapon_OnStreet[weapon])); } ClearWeapons(); } +// --MIAMI: Done void CPed::SetAttackTimer(uint32 time) { @@ -5720,6 +7091,7 @@ CPed::SetAttackTimer(uint32 time) m_attackTimer = Max(m_shootTimer, CTimer::GetTimeInMilliseconds()) + time; } +// --MIAMI: Done void CPed::SetBeingDraggedFromCar(CVehicle *veh, uint32 vehEnterType, bool quickJack) { @@ -5732,7 +7104,17 @@ CPed::SetBeingDraggedFromCar(CVehicle *veh, uint32 vehEnterType, bool quickJack) SetMoveState(PEDMOVE_STILL); m_pSeekTarget = veh; m_pSeekTarget->RegisterReference((CEntity **) &m_pSeekTarget); - m_vehEnterType = vehEnterType; + + if (veh->IsBike()) { + ((CBike*)veh)->bIsBeingPickedUp = true; + if (veh->pPassengers[0] != this && (vehEnterType != CAR_WINDSCREEN || veh->pPassengers[0])) + m_vehEnterType = CAR_DOOR_LF; + else + m_vehEnterType = CAR_DOOR_LR; + } else { + m_vehEnterType = vehEnterType; + } + if (m_vehEnterType == CAR_DOOR_LF) { if (veh->pDriver && veh->pDriver->IsPlayer()) veh->SetStatus(STATUS_PLAYER_DISABLED); @@ -5741,9 +7123,9 @@ CPed::SetBeingDraggedFromCar(CVehicle *veh, uint32 vehEnterType, bool quickJack) } RemoveInCarAnims(); SetMoveState(PEDMOVE_NONE); - LineUpPedWithCar(LINE_UP_TO_CAR_START); + LineUpPedWithCar(veh->IsBike() ? LINE_UP_TO_CAR_FALL : LINE_UP_TO_CAR_START); m_pVehicleAnim = nil; - m_nPedState = PED_DRAG_FROM_CAR; + SetPedState(PED_DRAG_FROM_CAR); bChangedSeat = false; bWillBeQuickJacked = quickJack; @@ -5751,9 +7133,33 @@ CPed::SetBeingDraggedFromCar(CVehicle *veh, uint32 vehEnterType, bool quickJack) Say(SOUND_PED_CAR_JACKED); SetRadioStation(); - veh->m_nGettingOutFlags |= GetCarDoorFlag(m_vehEnterType); + + if(veh->IsBike()) + veh->m_nGettingOutFlags |= GetBikeDoorFlag(m_vehEnterType); + else + veh->m_nGettingOutFlags |= GetCarDoorFlag(m_vehEnterType); +} + +// --MIAMI: Done +void +CPed::BuyIceCream(void) +{ + if (m_carInObjective) { + CPed *driver = m_carInObjective->pDriver; + if (driver && CTimer::GetTimeInMilliseconds() > m_standardTimer) { + SetChat(driver, 8000); + driver->SetChat(this, 8000); + return; + } + SetObjective(OBJECTIVE_NONE); + SetWanderPath(CGeneral::GetRandomNumberInRange(0, 8)); + } else { + SetObjective(OBJECTIVE_NONE); + SetWanderPath(CGeneral::GetRandomNumberInRange(0, 8)); + } } +// --MIAMI: Done void CPed::SetBuyIceCream(void) { @@ -5763,55 +7169,75 @@ CPed::SetBuyIceCream(void) if (!m_carInObjective) return; -#ifdef FIX_ICECREAM - - // Simulating BuyIceCream - CPed* driver = m_carInObjective->pDriver; - if (driver) { - m_nPedState = PED_BUY_ICECREAM; - bFindNewNodeAfterStateRestore = true; - SetObjectiveTimer(8000); - SetChat(driver, 8000); - driver->SetChat(this, 8000); - return; - } -#endif - - // Side of the Ice Cream van - m_fRotationDest = m_carInObjective->GetForward().Heading() - HALFPI; - - if (Abs(m_fRotationDest - m_fRotationCur) < HALFPI) { - m_standardTimer = CTimer::GetTimeInMilliseconds() + 3000; - m_nPedState = PED_BUY_ICECREAM; - } + SetPedState(PED_BUY_ICECREAM); } +// --MIAMI: Done void CPed::SetChat(CEntity *chatWith, uint32 time) { - if(m_nPedState != PED_CHAT) + if (m_nPedState != PED_CHAT) { + m_nLastPedState = PED_NONE; SetStoredState(); + } - m_nPedState = PED_CHAT; + SetPedState(PED_CHAT); SetMoveState(PEDMOVE_STILL); -#if defined VC_PED_PORTS || defined FIX_BUGS m_lookTimer = 0; -#endif SetLookFlag(chatWith, true); m_standardTimer = CTimer::GetTimeInMilliseconds() + time; m_lookTimer = CTimer::GetTimeInMilliseconds() + 3000; } +// --MIAMI: Done +void +CPed::RemoveWeaponAnims(int unused, float animDelta) +{ + CAnimBlendAssociation *weaponAssoc; + //CWeaponInfo::GetWeaponInfo(unused); + + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_FIRE); + if (weaponAssoc) { + weaponAssoc->blendDelta = animDelta; + weaponAssoc->flags |= ASSOC_DELETEFADEDOUT; + } + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_FIRE_2ND); + if (weaponAssoc) { + weaponAssoc->blendDelta = animDelta; + weaponAssoc->flags |= ASSOC_DELETEFADEDOUT; + } + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_FIRE_3RD); + if (weaponAssoc) { + weaponAssoc->blendDelta = animDelta; + weaponAssoc->flags |= ASSOC_DELETEFADEDOUT; + } + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_RELOAD); + if (weaponAssoc) { + weaponAssoc->blendDelta = animDelta; + weaponAssoc->flags |= ASSOC_DELETEFADEDOUT; + } + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCHRELOAD); + if (weaponAssoc) { + weaponAssoc->flags |= ASSOC_DELETEFADEDOUT; + if (weaponAssoc->flags & ASSOC_PARTIAL) + weaponAssoc->blendDelta = animDelta; + else + CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, -animDelta); + } +} + +// --MIAMI: Done void CPed::SetDead(void) { - bUsesCollision = false; + if (!RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DROWN)) + bUsesCollision = false; m_fHealth = 0.0f; if (m_nPedState == PED_DRIVING) bIsVisible = false; - m_nPedState = PED_DEAD; + SetPedState(PED_DEAD); m_pVehicleAnim = nil; m_pCollidingEntity = nil; @@ -5821,6 +7247,7 @@ CPed::SetDead(void) m_currentWeapon = WEAPONTYPE_UNARMED; CEventList::RegisterEvent(EVENT_INJURED_PED, EVENT_ENTITY_PED, this, nil, 250); if (this != FindPlayerPed()) { + RemoveWeaponAnims(0, -1000.0f); CreateDeadPedWeaponPickups(); CreateDeadPedMoney(); } @@ -5832,6 +7259,7 @@ CPed::SetDead(void) CEventList::RegisterEvent(EVENT_DEAD_PED, EVENT_ENTITY_PED, this, nil, 1000); } +// --MIAMI: Done void CPed::SetSeek(CEntity *seeking, float distanceToCountDone) { @@ -5841,38 +7269,35 @@ CPed::SetSeek(CEntity *seeking, float distanceToCountDone) if (m_nPedState == PED_SEEK_ENTITY && m_pSeekTarget == seeking) return; - if (!seeking) + if (!seeking || m_nPedState == PED_FOLLOW_PATH) return; if (m_nPedState != PED_SEEK_ENTITY) SetStoredState(); - m_nPedState = PED_SEEK_ENTITY; + SetPedState(PED_SEEK_ENTITY); m_distanceToCountSeekDone = distanceToCountDone; m_pSeekTarget = seeking; m_pSeekTarget->RegisterReference((CEntity **) &m_pSeekTarget); SetMoveState(PEDMOVE_STILL); } +// --MIAMI: Done void CPed::SetSeek(CVector pos, float distanceToCountDone) { if (!IsPedInControl() - || (m_nPedState == PED_SEEK_POS && m_vecSeekPos.x == pos.x && m_vecSeekPos.y == pos.y)) + || (m_nPedState == PED_SEEK_POS && m_vecSeekPos.x == pos.x && m_vecSeekPos.y == pos.y) || m_nPedState == PED_FOLLOW_PATH) return; - if (GetWeapon()->m_eWeaponType == WEAPONTYPE_M16 - || GetWeapon()->m_eWeaponType == WEAPONTYPE_AK47 - || GetWeapon()->m_eWeaponType == WEAPONTYPE_SNIPERRIFLE - || GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER - || GetWeapon()->m_eWeaponType == WEAPONTYPE_SHOTGUN) { + if (!CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAimWithArm) { ClearPointGunAt(); } if (m_nPedState != PED_SEEK_POS) SetStoredState(); - m_nPedState = PED_SEEK_POS; + SetPedState(PED_SEEK_POS); m_distanceToCountSeekDone = distanceToCountDone; m_vecSeekPos = pos; } @@ -5906,30 +7331,7 @@ CPed::Die(void) // UNUSED: This is a perfectly empty function. } -uint8 -CPed::DoesLOSBulletHitPed(CColPoint &colPoint) -{ -#ifdef FIX_BUGS - return 1; -#else - uint8 retVal = 2; - - float headZ = GetNodePosition(PED_HEAD).z; - - if (m_nPedState == PED_FALL) - retVal = 1; - - float colZ = colPoint.point.z; - if (colZ < headZ) - retVal = 1; - - if (headZ + 0.2f <= colZ) - retVal = 0; - - return retVal; -#endif -} - +// --MIAMI: Done bool CPed::DuckAndCover(void) { @@ -5947,9 +7349,11 @@ CPed::DuckAndCover(void) SetAimFlag(m_pedInObjective); } else { - bCrouchWhenShooting = false; bKindaStayInSamePlace = false; - bIsDucking = false; + if (bIsDucking) + ClearDuck(true); + + bCrouchWhenShooting = false; bDuckAndCover = false; m_headingRate = 10.0f; m_duckAndCoverTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(20000,30000); @@ -5958,25 +7362,70 @@ CPed::DuckAndCover(void) } return false; } + + int16 lastVehicle = 0; + CEntity* vehicles[8]; bool justDucked = false; CVehicle *foundVeh = nil; float maxDist = 225.0f; - bIsDucking = false; + if (bIsDucking) + ClearDuck(true); + bCrouchWhenShooting = false; + bool duckingWithoutVeh = false; if (CTimer::GetTimeInMilliseconds() > m_leaveCarTimer) { - CVector pos = GetPosition(); - int16 lastVehicle; - CEntity *vehicles[8]; - CWorld::FindObjectsInRange(pos, CHECK_NEARBY_THINGS_MAX_DIST, true, &lastVehicle, 6, vehicles, false, true, false, false, false); + + for(int i = 0; i < 6; i++) { + CPlayerPed *player = (CPlayerPed*)m_pedInObjective; + + if (player->m_pPedAtSafePos[i] == this) { + duckingWithoutVeh = true; + CVector &safePos = player->m_vecSafePos[i]; + bool notRunningToSafePos = false; + + if (m_vecSeekPos.x != safePos.x && m_vecSeekPos.y != safePos.y && m_vecSeekPos.z != safePos.z) + notRunningToSafePos = true; + + if (!notRunningToSafePos) { + CVector target = player->m_vecSafePos[i]; + SetSeek(target, 1.0f); + duckingWithoutVeh = true; + m_attackTimer = CTimer::GetTimeInMilliseconds() + 6000; + bDuckAndCover = true; + } + break; + } + } + if (!duckingWithoutVeh) { + for (int i = 0; i < 6; i++) { + CPlayerPed* player = (CPlayerPed*)m_pedInObjective; + if (!player->m_pPedAtSafePos[i] && player->m_vecSafePos[i].x != 0.0f) { + player->m_pPedAtSafePos[i] = this; + CVector target = player->m_vecSafePos[i]; + SetSeek(target, 1.0f); + m_headingRate = 15.0f; + ClearPointGunAt(); + duckingWithoutVeh = 1; + bIsRunning = true; + bDuckAndCover = true; + justDucked = true; + m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 500; + break; + } + } + } + if (!duckingWithoutVeh) { + CVector pos = GetPosition(); + CWorld::FindObjectsInRange(pos, CHECK_NEARBY_THINGS_MAX_DIST, true, &lastVehicle, 6, vehicles, false, true, false, false, false); + } for (int i = 0; i < lastVehicle; i++) { CVehicle *veh = (CVehicle*) vehicles[i]; - if (veh->m_vecMoveSpeed.Magnitude() <= 0.02f - && !veh->bIsBus - && !veh->bIsVan - && !veh->bIsBig + if (veh->IsCar() && veh->m_vecMoveSpeed.Magnitude() <= 0.02f + && !veh->bIsBus && !veh->bIsVan && !veh->bIsBig && veh->m_numPedsUseItAsCover < 3) { + float dist = (GetPosition() - veh->GetPosition()).MagnitudeSqr(); if (dist < maxDist) { maxDist = dist; @@ -6017,25 +7466,25 @@ CPed::DuckAndCover(void) else duckPos = duckAtRightSide; - if (CWorld::TestSphereAgainstWorld(duckPos, 0.5f, nil, true, true, true, false, false, false) - && CWorld::GetIsLineOfSightClear(GetPosition(), duckPos, 1, 0, 0, 1, 0, 0, 0)) { + if (CWorld::TestSphereAgainstWorld(duckPos, 0.5f, nil, true, true, true, false, false, false)) { SetSeek(duckPos, 1.0f); m_headingRate = 15.0f; bIsRunning = true; bDuckAndCover = true; justDucked = true; m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 500; - if (foundVeh->bIsLawEnforcer) + if (foundVeh->bIsLawEnforcer) { m_carInObjective = foundVeh; - - // BUG? Shouldn't we register the reference? + m_carInObjective->RegisterReference((CEntity**)&m_carInObjective); + } m_pSeekTarget = foundVeh; + m_pSeekTarget->RegisterReference((CEntity**)&m_pSeekTarget); ClearPointGunAt(); } else { m_duckAndCoverTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(10000, 15000); bDuckAndCover = false; } - } else { + } else if (!duckingWithoutVeh) { bDuckAndCover = false; } } @@ -6043,8 +7492,13 @@ CPed::DuckAndCover(void) if (!justDucked && !bDuckAndCover) return false; - if (!Seek()) - return true; + if (!Seek()) { + if (m_nMoveState == PEDMOVE_STILL) { + bDuckAndCover = false; + return false; + } else + return true; + } bKindaStayInSamePlace = true; bDuckAndCover = false; @@ -6061,9 +7515,12 @@ CPed::DuckAndCover(void) } m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(3000, 6000); + bCrouchWhenShooting = true; + SetDuck(CGeneral::GetRandomNumberInRange(2000, 5000), true); return false; } +// --MIAMI: Done void CPed::EndFight(uint8 endType) { @@ -6073,6 +7530,9 @@ CPed::EndFight(uint8 endType) m_curFightMove = FIGHTMOVE_NULL; RestorePreviousState(); CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE); + if (!animAssoc) + animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCHRELOAD); + if (animAssoc) animAssoc->flags |= ASSOC_DELETEFADEDOUT; @@ -6095,11 +7555,12 @@ CPed::EndFight(uint8 endType) m_nWaitTimer = 0; } +// --MIAMI: Done void CPed::EnterCar(void) { if (IsNotInWreckedVehicle() && m_fHealth > 0.0f) { - CVehicle *veh = (CVehicle*)m_pSeekTarget; + CVehicle *veh = m_pMyVehicle; // Not used. // CVector posForDoor = GetPositionToOpenCarDoor(veh, m_vehEnterType); @@ -6113,9 +7574,32 @@ CPed::EnterCar(void) } bIsInTheAir = false; LineUpPedWithCar(LINE_UP_TO_CAR_START); + if (veh->IsBike()) { + CBike *bike = (CBike*)veh; + if (bike->GetStatus() != STATUS_ABANDONED || bike->bIsBeingPickedUp || !m_pVehicleAnim) { + if (m_nPedState == PED_CARJACK && m_pVehicleAnim) { + if (m_pVehicleAnim->currentTime > 0.4f && m_pVehicleAnim->currentTime - m_pVehicleAnim->timeStep <= 0.4f) { + int anim = m_pVehicleAnim->animId; + if (anim == ANIM_BIKE_KICK) { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_187, 3.0f); + } else if (anim == ANIM_BIKE_ELBOW_R || anim == ANIM_BIKE_ELBOW_L) { + DMAudio.PlayOneShot(m_audioEntityId, SOUND_186, 3.0f); + } + } + } + } else { + int anim = m_pVehicleAnim->animId; + + // One is pickup and other one is pullup, not same :p + if ((anim == ANIM_BIKE_PICKUP_R || anim == ANIM_BIKE_PICKUP_L) && m_pVehicleAnim->currentTime > 0.4667f) + bike->bIsBeingPickedUp = true; + else if ((anim == ANIM_BIKE_PULLUP_R || anim == ANIM_BIKE_PULLUP_L) && m_pVehicleAnim->currentTime > 0.4667f) + bike->bIsBeingPickedUp = true; + } + } } else { QuitEnteringCar(); - SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); + SetDie(); } } @@ -6194,6 +7678,7 @@ CPed::GetNearestTrainDoor(CVehicle *train, CVector &doorPos) return 1; } +#ifdef GTA_TRAIN void CPed::LineUpPedWithTrain(void) { @@ -6245,65 +7730,156 @@ CPed::ExitTrain(void) { LineUpPedWithTrain(); } +#endif +// --MIAMI: Done void CPed::ExitCar(void) { - if (!m_pVehicleAnim) + if (!m_pVehicleAnim) { + if (InVehicle()) { + if (m_pMyVehicle->IsBike()) { + if (m_vehEnterType == CAR_BOOT || m_vehEnterType == CAR_BUMP_REAR) { + ((CBike*)m_pMyVehicle)->KnockOffRider(WEAPONTYPE_UNARMED, 0, this, false); + } + } else if (m_pMyVehicle->IsCar()) { + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_ROLLOUT_LHS)) { + ((CAutomobile*)m_pMyVehicle)->KnockPedOutCar(WEAPONTYPE_UNIDENTIFIED, CAR_DOOR_LF, this); + } else if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_ROLLOUT_RHS)) { + ((CAutomobile*)m_pMyVehicle)->KnockPedOutCar(WEAPONTYPE_UNIDENTIFIED, CAR_DOOR_RF, this); + } + } + } return; + } AnimationId exitAnim = (AnimationId) m_pVehicleAnim->animId; float animTime = m_pVehicleAnim->currentTime; - m_pMyVehicle->ProcessOpenDoor(m_vehEnterType, exitAnim, animTime); + if (exitAnim == ANIM_BIKE_GETOFF_BACK) { + if (animTime > 0.35f && m_pMyVehicle && m_pMyVehicle->IsBike()) + ((CBike*)m_pMyVehicle)->KnockOffRider(WEAPONTYPE_UNARMED, 0, this, false); + else + LineUpPedWithCar(LINE_UP_TO_CAR_FALL); - if (m_pSeekTarget) { - // Car is upside down - if (m_pMyVehicle->GetUp().z > -0.8f) { - if (exitAnim != ANIM_CAR_CLOSE_RHS && exitAnim != ANIM_CAR_CLOSE_LHS && animTime <= 0.3f) - LineUpPedWithCar((m_pMyVehicle->GetModelIndex() == MI_DODO ? LINE_UP_TO_CAR_END : LINE_UP_TO_CAR_START)); - else + } else if (exitAnim != ANIM_CAR_ROLLOUT_LHS && exitAnim != ANIM_CAR_ROLLOUT_RHS) { + m_pMyVehicle->ProcessOpenDoor(m_vehEnterType, exitAnim, animTime); + + if (m_pSeekTarget) { + // Car is upside down + if (m_pMyVehicle->GetUp().z > -0.8f) { + if (exitAnim != ANIM_CAR_CLOSE_RHS && exitAnim != ANIM_CAR_CLOSE_LHS && animTime <= 0.3f) + LineUpPedWithCar((m_pMyVehicle->GetModelIndex() == MI_DODO ? LINE_UP_TO_CAR_END : LINE_UP_TO_CAR_START)); + else + LineUpPedWithCar(LINE_UP_TO_CAR_END); + } + else { LineUpPedWithCar(LINE_UP_TO_CAR_END); - } else { - LineUpPedWithCar(LINE_UP_TO_CAR_END); + } } - } - // If there is someone in front of the door, make him fall while we exit. - if (m_nPedState == PED_EXIT_CAR) { - CPed *foundPed = nil; - for (int i = 0; i < m_numNearPeds; i++) { - if ((m_nearPeds[i]->GetPosition() - GetPosition()).MagnitudeSqr2D() < 0.04f) { - foundPed = m_nearPeds[i]; - break; + // If there is someone in front of the door, make him fall while we exit. + if (m_nPedState == PED_EXIT_CAR) { + CPed* foundPed = nil; + for (int i = 0; i < m_numNearPeds; i++) { + if ((m_nearPeds[i]->GetPosition() - GetPosition()).MagnitudeSqr2D() < 0.04f) { + foundPed = m_nearPeds[i]; + break; + } } - } - if (foundPed && animTime > 0.4f && foundPed->IsPedInControl()) - foundPed->SetFall(1000, ANIM_KO_SKID_FRONT, 1); + if(foundPed && (!foundPed->IsPlayer() || m_nPedType == PEDTYPE_COP || m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS)) + if (animTime > 0.4f && foundPed->IsPedInControl()) + foundPed->SetFall(1000, ANIM_KO_SKID_FRONT, 1); + } + } else if (animTime <= 0.07f || !m_pMyVehicle || !m_pMyVehicle->IsCar()) { + LineUpPedWithCar(LINE_UP_TO_CAR_FALL); + } else if (exitAnim == ANIM_CAR_ROLLOUT_LHS) { + ((CAutomobile*)m_pMyVehicle)->KnockPedOutCar(WEAPONTYPE_UNIDENTIFIED, CAR_DOOR_LF, this); + } else { + ((CAutomobile*)m_pMyVehicle)->KnockPedOutCar(WEAPONTYPE_UNIDENTIFIED, CAR_DOOR_RF, this); } } +// --MIAMI: Done void CPed::Fall(void) { - if (m_getUpTimer != UINT32_MAX && CTimer::GetTimeInMilliseconds() > m_getUpTimer -#ifdef VC_PED_PORTS - && bIsStanding -#endif - ) + if (m_getUpTimer != UINT32_MAX && CTimer::GetTimeInMilliseconds() > m_getUpTimer && bIsStanding) ClearFall(); - // VC plays animations ANIM_STD_FALL_ONBACK and ANIM_STD_FALL_ONFRONT in here, which doesn't exist in III. + CAnimBlendAssociation *firstPartialAssoc; + CAnimBlendAssociation *fallAssoc; + + if (IsPlayer() && (bKnockedUpIntoAir || bKnockedOffBike) && !bIsStanding) { + firstPartialAssoc = RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_PARTIAL); + + // What??? + if (firstPartialAssoc && (firstPartialAssoc->animId == ANIM_FALL_BACK || firstPartialAssoc->animId == ANIM_FALL_FRONT)) + fallAssoc = firstPartialAssoc; + else + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_BACK); + + if (!fallAssoc) + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FRONT); + + if (fallAssoc || !firstPartialAssoc || 0.8f * firstPartialAssoc->hierarchy->totalLength >= firstPartialAssoc->currentTime) { + if (fallAssoc) { + if (fallAssoc->blendAmount > 0.3f && fallAssoc->blendDelta >= 0.0f) { + float time = fallAssoc->currentTime; + + if (time > 0.667f && time - fallAssoc->timeStep <= 0.667f) { + fallAssoc->SetCurrentTime(0.0f); + fallAssoc->SetRun(); + } + } + } + } else if (firstPartialAssoc->flags & ASSOC_FRONTAL) { + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FALL_FRONT, 8.0f); + } else { + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FALL_BACK, 8.0f); + } + } else if ((bKnockedUpIntoAir || bKnockedOffBike) && bIsStanding && !bWasStanding) { + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_BACK); + + if (!fallAssoc) + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FRONT); + + if (fallAssoc) { + bKnockedUpIntoAir = false; + bKnockedOffBike = false; + fallAssoc->speed = 3.0f; + if (IsPlayer()) + Say(SOUND_PED_LAND); + + } else { + firstPartialAssoc = RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_PARTIAL); + if (firstPartialAssoc && !firstPartialAssoc->IsRunning()) { + bKnockedUpIntoAir = false; + bKnockedOffBike = false; + } + } + } } +// --MIAMI: Done void CPed::Fight(void) { CAnimBlendAssociation *currentAssoc, *animAssoc; - bool hasShoppingBags, punchOnly, canKick, canKneeHead, canRoundhouse; - float angleToFace, nextAngle; - bool goForward = false; - int nextFightMove; + bool fightWithWeapon = false; + + eWeaponType weapon = GetWeapon()->m_eWeaponType; + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(weapon); + + if (weaponInfo->m_bFightMode && weapon != WEAPONTYPE_UNARMED) { + fightWithWeapon = true; + tFightMoves[FIGHTMOVE_MELEE1].startFireTime = weaponInfo->m_fAnimFrameFire; + tFightMoves[FIGHTMOVE_MELEE1].endFireTime = weaponInfo->m_fAnimLoopEnd; + tFightMoves[FIGHTMOVE_MELEE2].startFireTime = weaponInfo->m_fAnim2FrameFire; + tFightMoves[FIGHTMOVE_MELEE2].endFireTime = weaponInfo->m_fAnim2LoopEnd; + tFightMoves[FIGHTMOVE_MELEE3].startFireTime = weaponInfo->m_fAnim2FrameFire; + tFightMoves[FIGHTMOVE_MELEE3].endFireTime = weaponInfo->m_fAnim2LoopEnd; + } switch (m_curFightMove) { case FIGHTMOVE_NULL: @@ -6323,6 +7899,22 @@ CPed::Fight(void) break; } + if (m_curFightMove == FIGHTMOVE_SHUFFLE_F && !currentAssoc) + currentAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_SH_BACK); + + if (IsPlayer() && currentAssoc && weapon == WEAPONTYPE_KATANA) { + if (m_curFightMove == FIGHTMOVE_MELEE1 || m_curFightMove == FIGHTMOVE_MELEE2) { + static float streakDelay = 0.2f; + + if (tFightMoves[m_curFightMove].startFireTime - streakDelay < currentAssoc->currentTime && + streakDelay + tFightMoves[m_curFightMove].endFireTime > currentAssoc->currentTime) { + + // TODO(Miami): AddWeaponStreak + // CSpecialFX::AddWeaponStreak(v2->m_weapons[(char)v2->m_currentWeapon].nWeaponId); + } + } + } + if (!bIsAttacking && IsPlayer()) { if (currentAssoc) { currentAssoc->blendDelta = -1000.0f; @@ -6339,272 +7931,123 @@ CPed::Fight(void) FightMove &curMove = tFightMoves[m_curFightMove]; if (curMove.hitLevel != HITLEVEL_NULL && animTime > curMove.startFireTime && animTime <= curMove.endFireTime && m_fightState >= FIGHTSTATE_NO_MOVE) { + if (animTime > curMove.startFireTime && animTime - currentAssoc->timeStep < curMove.startFireTime && + (IsPlayer() || weapon != WEAPONTYPE_UNARMED)) { + + DMAudio.PlayOneShot(m_audioEntityId, SOUND_MELEE_ATTACK_START, weapon << 8); + } + CVector touchingNodePos(0.0f, 0.0f, 0.0f); switch (m_curFightMove) { - case FIGHTMOVE_STDPUNCH: - case FIGHTMOVE_PUNCHHOOK: - case FIGHTMOVE_BODYBLOW: - TransformToNode(touchingNodePos, PED_HANDR); - break; - case FIGHTMOVE_IDLE: - case FIGHTMOVE_SHUFFLE_F: - break; case FIGHTMOVE_KNEE: TransformToNode(touchingNodePos, PED_LOWERLEGR); break; - case FIGHTMOVE_HEADBUTT: - TransformToNode(touchingNodePos, PED_HEAD); - break; + case FIGHTMOVE_PUNCHHOOK: case FIGHTMOVE_PUNCHJAB: TransformToNode(touchingNodePos, PED_HANDL); break; - case FIGHTMOVE_KICK: case FIGHTMOVE_LONGKICK: case FIGHTMOVE_ROUNDHOUSE: + case FIGHTMOVE_FWDLEFT: + case FIGHTMOVE_BACKRIGHT: case FIGHTMOVE_GROUNDKICK: TransformToNode(touchingNodePos, PED_FOOTR); break; + case FIGHTMOVE_FWDRIGHT: + TransformToNode(touchingNodePos, PED_HEAD); + break; + case FIGHTMOVE_BACKKICK: + case FIGHTMOVE_BACKFLIP: + TransformToNode(touchingNodePos, PED_FOOTL); + break; + case FIGHTMOVE_BACKLEFT: + TransformToNode(touchingNodePos, PED_UPPERARML); + break; + default: + TransformToNode(touchingNodePos, PED_HANDR); + break; } - if (m_curFightMove == FIGHTMOVE_PUNCHJAB) { - touchingNodePos += 0.1f * GetForward(); - } else if (m_curFightMove == FIGHTMOVE_PUNCHHOOK) { - touchingNodePos += 0.22f * GetForward(); - } - FightStrike(touchingNodePos); + FightStrike(touchingNodePos, fightWithWeapon); m_fightButtonPressure = 0; return; } if (curMove.hitLevel != HITLEVEL_NULL) { - if (animTime > curMove.endFireTime) { + if (animTime > curMove.endFireTime && weaponInfo->m_AnimToPlay != ASSOCGRP_KNIFE) { if (IsPlayer()) currentAssoc->speed = 1.0f; else currentAssoc->speed = 0.8f; } - if (IsPlayer() && !nPlayerInComboMove) { + if (IsPlayer() && !nPlayerInComboMove && !fightWithWeapon) { if (curMove.comboFollowOnTime > 0.0f && m_fightButtonPressure != 0 && animTime > curMove.comboFollowOnTime) { + m_lastFightMove = m_curFightMove; // Notice that it increases fight move index, because we're in combo! animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, tFightMoves[++m_curFightMove].animId, 8.0f); animAssoc->SetFinishCallback(FinishFightMoveCB, this); animAssoc->SetCurrentTime(0.1f * animAssoc->hierarchy->totalLength); + animAssoc->speed = 0.8f; m_fightButtonPressure = 0; nPlayerInComboMove = 1; } } - } else { - if (curMove.startFireTime > 0.0f && m_curFightMove != FIGHTMOVE_SHUFFLE_F && animTime > curMove.startFireTime) { - if (IsPlayer()) - currentAssoc->speed = 1.3f; - else - currentAssoc->speed = 0.8f; - } } - } else if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED) { + + } else if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && GetWeapon()->m_eWeaponType != WEAPONTYPE_BRASSKNUCKLE && !fightWithWeapon) { EndFight(ENDFIGHT_FAST); } else if (m_fightButtonPressure != 0) { - bool canAffectMultiplePeople = true; - nextAngle = m_fRotationCur; - bool kickGround = false; - float angleForGroundKick = 0.0f; - CPed *pedOnGround = nil; - - Say(SOUND_PED_ATTACK); - - if (IsPlayer()) { - canRoundhouse = false; - punchOnly = false; - canKick = true; - nextFightMove = (m_fightButtonPressure > 190 ? FIGHTMOVE_HEADBUTT : FIGHTMOVE_KNEE); - hasShoppingBags = false; - canKneeHead = true; - nPlayerInComboMove = 0; - } else { - nextFightMove = (m_fightButtonPressure > 120 ? FIGHTMOVE_HEADBUTT : FIGHTMOVE_KNEE); - uint16 pedFeatures = m_pedStats->m_flags; - punchOnly = pedFeatures & STAT_PUNCH_ONLY; - canRoundhouse = pedFeatures & STAT_CAN_ROUNDHOUSE; - canKneeHead = pedFeatures & STAT_CAN_KNEE_HEAD; - canKick = pedFeatures & STAT_CAN_KICK; - hasShoppingBags = pedFeatures & STAT_SHOPPING_BAGS; - } - - // Attack isn't scripted, find the victim - if (IsPlayer() || !m_pedInObjective) { - - for (int i = 0; i < m_numNearPeds; i++) { - - CPed *nearPed = m_nearPeds[i]; - float nearPedDist = (nearPed->GetPosition() - GetPosition()).Magnitude(); - if (nearPedDist < 3.0f) { - float angleToFace = CGeneral::GetRadianAngleBetweenPoints( - nearPed->GetPosition().x, nearPed->GetPosition().y, - GetPosition().x, GetPosition().y); - - nextAngle = CGeneral::LimitRadianAngle(angleToFace); - m_fRotationCur = CGeneral::LimitRadianAngle(m_fRotationCur); - - float neededTurn = Abs(nextAngle - m_fRotationCur); - if (neededTurn > PI) - neededTurn = TWOPI - neededTurn; - - if (!nearPed->OnGroundOrGettingUp()) { - - if (nearPedDist < 0.8f && neededTurn < DEGTORAD(75.0f) && canKneeHead) { - canAffectMultiplePeople = false; - } else if (nearPedDist >= 1.3f || neededTurn >= DEGTORAD(55.0f) || hasShoppingBags) { - - if (nearPedDist < 1.7f - && neededTurn < DEGTORAD(35.0f) - && (canKick || hasShoppingBags)) { - - nextFightMove = FIGHTMOVE_KICK; - if (hasShoppingBags) { - nextFightMove = FIGHTMOVE_ROUNDHOUSE; - } else if (canRoundhouse && CGeneral::GetRandomNumber() & 1) { - nextFightMove = FIGHTMOVE_ROUNDHOUSE; - } - canAffectMultiplePeople = false; - } else if (nearPedDist < 2.0f && neededTurn < DEGTORAD(30.0f) && canKick) { - canAffectMultiplePeople = false; - nextFightMove = FIGHTMOVE_LONGKICK; - } else if (neededTurn < DEGTORAD(30.0f)) { - goForward = true; - } - } else { - nextFightMove += 2; // Makes it 6 or 7 - if (punchOnly) - nextFightMove = FIGHTMOVE_PUNCHJAB; + if (!IsPlayer()) + Say(SOUND_PED_ATTACK); - canAffectMultiplePeople = false; - } - } else if (!CGame::nastyGame - || nearPedDist >= 1.3f - || neededTurn >= DEGTORAD(55.0f) - || punchOnly) { - - if (nearPedDist > 0.8f - && nearPedDist < 3.0f - && neededTurn < DEGTORAD(30.0f)) { - goForward = true; - } + if (m_curFightMove != FIGHTMOVE_IDLE) + m_lastFightMove = m_curFightMove; - } else if (nearPed->m_nPedState != PED_DEAD || pedOnGround) { - if (!nearPed->IsPedHeadAbovePos(-0.3f)) { - canAffectMultiplePeople = false; - nextFightMove = FIGHTMOVE_GROUNDKICK; - } - - } else { - pedOnGround = nearPed; - kickGround = true; - angleForGroundKick = nextAngle; - } - } + m_curFightMove = IsPlayer() ? ChooseAttackPlayer(m_fightButtonPressure, fightWithWeapon) : ChooseAttackAI(m_fightButtonPressure, fightWithWeapon); - if (!canAffectMultiplePeople) { - m_fRotationDest = nextAngle; - if (IsPlayer()) { - m_fRotationCur = m_fRotationDest; - m_lookTimer = 0; - SetLookFlag(nearPed, true); - SetLookTimer(1500); - } - break; - } - } - } else { - // Because we're in a scripted fight with some particular ped. - canAffectMultiplePeople = false; + if (m_curFightMove != FIGHTMOVE_IDLE) { - float fightingPedDist = (m_pedInObjective->GetPosition() - GetPosition()).Magnitude(); - if (hasShoppingBags) { - if (fightingPedDist >= 1.7f) - nextFightMove = FIGHTMOVE_SHUFFLE_F; - else - nextFightMove = FIGHTMOVE_ROUNDHOUSE; + animAssoc = CAnimManager::BlendAnimation(GetClump(), m_curFightMove < FIGHTMOVE_MELEE1 ? ASSOCGRP_STD : weaponInfo->m_AnimToPlay, + tFightMoves[m_curFightMove].animId, 8.0f); - } else if (punchOnly) { - if (fightingPedDist >= 1.3f) - nextFightMove = FIGHTMOVE_SHUFFLE_F; + if (weaponInfo->m_AnimToPlay != ASSOCGRP_KNIFE || m_curFightMove < FIGHTMOVE_MELEE1) { + if (m_curFightMove == FIGHTMOVE_BACKKICK) + animAssoc->speed = 1.15f; else - nextFightMove = FIGHTMOVE_PUNCHJAB; - - } else if (fightingPedDist >= 3.0f) { - nextFightMove = FIGHTMOVE_STDPUNCH; - + animAssoc->speed = 0.8f; } else { - angleToFace = CGeneral::GetRadianAngleBetweenPoints( - m_pedInObjective->GetPosition().x, - m_pedInObjective->GetPosition().y, - GetPosition().x, - GetPosition().y); - - nextAngle = CGeneral::LimitRadianAngle(angleToFace); - m_fRotationDest = nextAngle; - m_fRotationCur = m_fRotationDest; - if (!m_pedInObjective->OnGroundOrGettingUp()) { - - if (fightingPedDist >= 0.8f || !canKneeHead) { - - if (fightingPedDist >= 1.3f) { - - if (fightingPedDist < 1.7f && canKick) { - nextFightMove = FIGHTMOVE_KICK; - if (canRoundhouse && CGeneral::GetRandomNumber() & 1) - nextFightMove = FIGHTMOVE_ROUNDHOUSE; - - } else if (fightingPedDist < 2.0f && canKick) { - nextFightMove += 5; // Makes it 9 or 10 - - } else { - nextFightMove = FIGHTMOVE_SHUFFLE_F; - - } - } else { - nextFightMove += 2; // Makes it 6 or 7 - } - } - } else if (!CGame::nastyGame - || fightingPedDist >= 1.3f - || m_pedInObjective->IsPlayer() - || m_pedInObjective->m_nPedState != PED_DEAD && m_pedInObjective->IsPedHeadAbovePos(-0.3f)) { - nextFightMove = FIGHTMOVE_IDLE; - } else { - nextFightMove = FIGHTMOVE_GROUNDKICK; + switch (GetWeapon()->m_eWeaponType) { + case WEAPONTYPE_SCREWDRIVER: + case WEAPONTYPE_KNIFE: + animAssoc->speed = 1.05f; + break; + case WEAPONTYPE_GOLFCLUB: + case WEAPONTYPE_NIGHTSTICK: + case WEAPONTYPE_BASEBALLBAT: + case WEAPONTYPE_HAMMER: + case WEAPONTYPE_KATANA: + animAssoc->speed = 0.8f; + break; + case WEAPONTYPE_CLEAVER: + case WEAPONTYPE_MACHETE: + animAssoc->speed = 0.9f; + break; } } - } - - if (canAffectMultiplePeople) { - if (kickGround && IsPlayer()) { - m_fRotationDest = angleForGroundKick; - nextFightMove = FIGHTMOVE_GROUNDKICK; - m_fRotationCur = m_fRotationDest; - m_lookTimer = 0; - SetLookFlag(pedOnGround, true); - SetLookTimer(1500); - } else if (goForward) { - nextFightMove = FIGHTMOVE_SHUFFLE_F; - } else { - nextFightMove = FIGHTMOVE_STDPUNCH; - } - } - - if (nextFightMove != FIGHTMOVE_IDLE) { - m_curFightMove = nextFightMove; - animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, tFightMoves[m_curFightMove].animId, 4.0f); - animAssoc->SetFinishCallback(FinishFightMoveCB, this); if (m_fightState == FIGHTSTATE_MOVE_FINISHED && animAssoc->currentTime != 0.0f) { - animAssoc->SetCurrentTime(0.0f); animAssoc->SetRun(); + if (!IsPlayer()) + animAssoc->SetCurrentTime(0.0f); } + if (IsPlayer()) + animAssoc->SetCurrentTime(0.08f); + + animAssoc->SetFinishCallback(FinishFightMoveCB, this); m_fightButtonPressure = 0; } m_fightState = FIGHTSTATE_NO_MOVE; @@ -6614,6 +8057,7 @@ CPed::Fight(void) #else && CheckForPedsOnGroundToAttack(this, nil) == PED_IN_FRONT_OF_ATTACKER) { #endif + m_lastFightMove = m_curFightMove; m_curFightMove = FIGHTMOVE_SHUFFLE_F; animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), tFightMoves[m_curFightMove].animId); @@ -6638,6 +8082,7 @@ CPed::Fight(void) } } else { + m_lastFightMove = m_curFightMove; m_curFightMove = FIGHTMOVE_IDLE; if (IsPlayer()) m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 500; @@ -6646,6 +8091,7 @@ CPed::Fight(void) } } +// --MIAMI: Done // Some helper function which doesn't exist in og game. inline void SelectClosestNodeForSeek(CPed *ped, CPathNode *node, CVector2D closeDist, CVector2D farDist, CPathNode *closeNode, CPathNode *closeNode2, int runCount = 3) @@ -6675,6 +8121,7 @@ SelectClosestNodeForSeek(CPed *ped, CPathNode *node, CVector2D closeDist, CVecto } } +// --MIAMI: Done bool CPed::FindBestCoordsFromNodes(CVector unused, CVector *bestCoords) { @@ -6700,12 +8147,14 @@ CPed::FindBestCoordsFromNodes(CVector unused, CVector *bestCoords) SelectClosestNodeForSeek(this, closestNode, closeDist, seekPosDist, closestNode, nil); - // Above function decided that going to the next node is more logical than seeking the object. if (m_pNextPathNode) { - CVector pathToNextNode = m_pNextPathNode->GetPosition() - ourPos; - if (pathToNextNode.MagnitudeSqr2D() < seekPosDist.MagnitudeSqr()) { - *bestCoords = m_pNextPathNode->GetPosition(); + // Function above decided that directly going to next node makes more sense then seeking the object. + CVector correctedCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); + + if ((correctedCoords - ourPos).MagnitudeSqr2D() < seekPosDist.MagnitudeSqr()) { + correctedCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); + *bestCoords = correctedCoords; return true; } m_pNextPathNode = nil; @@ -6714,6 +8163,7 @@ CPed::FindBestCoordsFromNodes(CVector unused, CVector *bestCoords) return false; } +// --MIAMI: Done void CPed::FinishDieAnimCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -6723,6 +8173,7 @@ CPed::FinishDieAnimCB(CAnimBlendAssociation *animAssoc, void *arg) ped->bIsPedDieAnimPlaying = false; } +// --MIAMI: Done void CPed::FinishFightMoveCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -6734,6 +8185,7 @@ CPed::FinishFightMoveCB(CAnimBlendAssociation *animAssoc, void *arg) } } +// --MIAMI: Done void CPed::FinishHitHeadCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -6750,6 +8202,7 @@ CPed::FinishHitHeadCB(CAnimBlendAssociation *animAssoc, void *arg) ped->bIsLanding = false; } +// --MIAMI: Done void CPed::FinishJumpCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -6782,9 +8235,7 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg) if (obstacle) { animAssoc->flags |= ASSOC_DELETEFADEDOUT; - - // ANIM_HIT_WALL in VC (which makes more sense) - CAnimBlendAssociation *handsCoverAssoc = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_HANDSCOWER, 8.0f); + CAnimBlendAssociation *handsCoverAssoc = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_HIT_WALL, 8.0f); handsCoverAssoc->flags &= ~ASSOC_FADEOUTWHENDONE; handsCoverAssoc->SetFinishCallback(FinishHitHeadCB, ped); ped->bIsLanding = true; @@ -6878,6 +8329,7 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg) } } +// --MIAMI: Done void CPed::FinishedWaitCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -6888,15 +8340,16 @@ CPed::FinishedWaitCB(CAnimBlendAssociation *animAssoc, void *arg) ped->Wait(); } +// --MIAMI: Some part is done void CPed::Wait(void) { - AnimationId mustHaveAnim = NUM_ANIMS; + AnimationId mustHaveAnim = NUM_STD_ANIMS; CAnimBlendAssociation *animAssoc; CPed *pedWeLook; if (DyingOrDead()) { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); RestoreHeadingRate(); return; } @@ -6906,7 +8359,7 @@ CPed::Wait(void) case WAITSTATE_TRAFFIC_LIGHTS: if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { if (CTrafficLights::LightForPeds() == PED_LIGHTS_WALK) { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); SetMoveState(PEDMOVE_WALK); } } @@ -6915,7 +8368,7 @@ CPed::Wait(void) case WAITSTATE_CROSS_ROAD: if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { if (CGeneral::GetRandomNumber() & 1 || !m_nWaitTimer) - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); else SetWaitState(WAITSTATE_CROSS_ROAD_LOOK, nil); @@ -6929,7 +8382,7 @@ CPed::Wait(void) case WAITSTATE_CROSS_ROAD_LOOK: if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_ROAD_CROSS); if (animAssoc) { animAssoc->blendDelta = -8.0f; @@ -6946,7 +8399,7 @@ CPed::Wait(void) CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_XPRESS_SCRATCH, 4.0f); } } else { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); SetMoveState(PEDMOVE_WALK); } break; @@ -6957,13 +8410,13 @@ CPed::Wait(void) m_collidingThingTimer = CTimer::GetTimeInMilliseconds() + 2500; } } else { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); } break; case WAITSTATE_TURN180: if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); SetMoveState(PEDMOVE_WALK); m_fRotationCur = m_fRotationCur + PI; if (m_nPedState == PED_INVESTIGATE) @@ -6982,7 +8435,7 @@ CPed::Wait(void) animAssoc->SetFinishCallback(FinishedWaitCB, this); m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 5000; } else { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); } } break; @@ -7011,7 +8464,7 @@ CPed::Wait(void) if (animAssoc->animId == ANIM_TURN_180) { m_fRotationCur = CGeneral::LimitRadianAngle(PI + m_fRotationCur); - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); SetMoveState(PEDMOVE_WALK); m_nStoredMoveState = PEDMOVE_NONE; m_panicCounter = 0; @@ -7048,7 +8501,7 @@ CPed::Wait(void) case WAITSTATE_LOOK_ABOUT: if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_HBHB); if (animAssoc) { animAssoc->blendDelta = -8.0f; @@ -7061,7 +8514,7 @@ CPed::Wait(void) mustHaveAnim = ANIM_HANDSUP; case WAITSTATE_PLAYANIM_HANDSCOWER: - if (mustHaveAnim == NUM_ANIMS) + if (mustHaveAnim == NUM_STD_ANIMS) mustHaveAnim = ANIM_HANDSCOWER; animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), mustHaveAnim); @@ -7075,7 +8528,7 @@ CPed::Wait(void) TurnBody(); } else { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); m_nWaitTimer = 0; if (m_pLookTarget && m_pLookTarget->IsPed()) { @@ -7133,15 +8586,15 @@ CPed::Wait(void) mustHaveAnim = ANIM_HANDSCOWER; case WAITSTATE_PLAYANIM_DUCK: - if (mustHaveAnim == NUM_ANIMS) + if (mustHaveAnim == NUM_STD_ANIMS) mustHaveAnim = ANIM_DUCK_DOWN; case WAITSTATE_PLAYANIM_TAXI: - if (mustHaveAnim == NUM_ANIMS) + if (mustHaveAnim == NUM_STD_ANIMS) mustHaveAnim = ANIM_IDLE_TAXI; case WAITSTATE_PLAYANIM_CHAT: - if (mustHaveAnim == NUM_ANIMS) + if (mustHaveAnim == NUM_STD_ANIMS) mustHaveAnim = ANIM_IDLE_CHAT; if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { @@ -7150,14 +8603,19 @@ CPed::Wait(void) animAssoc->blendDelta = -4.0f; animAssoc->flags |= ASSOC_DELETEFADEDOUT; } - m_nWaitState = WAITSTATE_FALSE; + if (m_attractor && m_objective == OBJECTIVE_WAIT_ON_FOOT_AT_ICE_CREAM_VAN) { + GetPedAttractorManager()->BroadcastDeparture(this, m_attractor); + bBoughtIceCream = true; + } + ClearWaitState(); } #ifdef VC_PED_PORTS else if (m_nWaitState == WAITSTATE_PLAYANIM_TAXI) { if (m_pedInObjective) { if (m_objective == OBJECTIVE_GOTO_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT) { - - // VC also calls CleanUpOldReference here for old LookTarget. + + if (m_pLookTarget) + m_pLookTarget->CleanUpOldReference(&m_pLookTarget); m_pLookTarget = m_pedInObjective; m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget); TurnBody(); @@ -7174,13 +8632,82 @@ CPed::Wait(void) animAssoc->flags |= ASSOC_DELETEFADEDOUT; CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 4.0f); int timer = 2000; - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); SetWaitState(WAITSTATE_CROSS_ROAD_LOOK, &timer); } } else { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); + } + break; + case WAITSTATE_SIT_DOWN: + if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { + ClearWaitState(); + SetWaitState(WAITSTATE_SIT_IDLE, 0); + } + break; + //case WAITSTATE_SIT_DOWN_RVRS: + case WAITSTATE_SIT_UP: + if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { + if (m_attractor) + GetPedAttractorManager()->BroadcastDeparture(this, m_attractor); + ClearWaitState(); + //TODO(MIAMI): scan for threats! + } + break; + case WAITSTATE_SIT_IDLE: + if (bTurnedAroundOnAttractor) { + m_fRotationCur += PI; + m_fRotationCur = CGeneral::LimitRadianAngle(m_fRotationCur); + m_fRotationDest = m_fRotationCur; + bTurnedAroundOnAttractor = false; + } + // TODO(MIAMI): scan for threats! + if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { + ClearWaitState(); + SetWaitState(WAITSTATE_SIT_UP, 0); + } + break; + case WAITSTATE_USE_ATM: + if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { + if (m_attractor) + GetPedAttractorManager()->BroadcastDeparture(this, m_attractor); + ClearWaitState(); + } + break; + case WAITSTATE_RIOT: + if (m_nPedState == PED_FLEE_ENTITY || m_nPedState == PED_ATTACK) { + ClearWaitState(); + break; + } + + PlayRandomAnimationsFromAnimBlock(this, ASSOCGRP_RIOT, ANIM_RIOT_ANGRY, ANIM_RIOT_FUKU - ANIM_RIOT_ANGRY + 1); + if (IsPedInControl() && CGeneral::GetRandomNumberInRange(0.f,1.f) < 0.25f + && CPopulation::CanJeerAtStripper(m_modelIndex)) { + for (int i = 0; i < m_numNearPeds; ++i) { + CPed *nearPed = m_nearPeds[i]; + if (nearPed) { + if ((GetPosition() - nearPed->GetPosition()).MagnitudeSqr() < sq(10.f)) { + for (int anim = ANIM_STRIP_A; anim <= ANIM_STRIP_G; anim++) { + if (RpAnimBlendClumpGetAssociation(nearPed->GetClump(), anim)) + Say(SOUND_PED_149); + } + } + } + } } break; + case WAITSTATE_BOMBER: + if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) + ClearWaitState(); + break; + case WAITSTATE_STRIPPER: + PlayRandomAnimationsFromAnimBlock(this, ASSOCGRP_STRIP, ANIM_STRIP_A, ANIM_STRIP_G - ANIM_STRIP_A + 1); + break; + case WAITSTATE_SUN_BATHE_PRE: + case WAITSTATE_SUN_BATHE_DOWN: + case WAITSTATE_SUN_BATHE_IDLE: + case WAITSTATE_PLAYANIM_HANDSUP_SIMPLE: + assert(0); default: break; } @@ -7189,6 +8716,7 @@ CPed::Wait(void) RestoreHeadingRate(); } +// --MIAMI: Done bool CPed::Seek(void) { @@ -7201,13 +8729,13 @@ CPed::Seek(void) m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_SOLICIT_VEHICLE && !bDuckAndCover) { if ((!m_pedInObjective || !m_pedInObjective->bInVehicle) - && !((CTimer::GetFrameCounter() + (m_randomSeed % 256) + 17) & 7)) { + && (CTimer::GetFrameCounter() + m_randomSeed + 60) % 32 == 0) { CEntity *obstacle = CWorld::TestSphereAgainstWorld(m_vecSeekPos, 0.4f, nil, false, true, false, false, false, false); if (obstacle) { - if (!obstacle->IsVehicle() || ((CVehicle*)obstacle)->m_vehType == VEHICLE_TYPE_CAR) { + if (!obstacle->IsVehicle() || ((CVehicle*)obstacle)->IsCar()) { distanceToCountItDone = 2.5f; } else { CVehicleModelInfo *vehModel = (CVehicleModelInfo *)CModelInfo::GetModelInfo(obstacle->GetModelIndex()); @@ -7223,6 +8751,13 @@ CPed::Seek(void) if (!m_pSeekTarget && m_nPedState == PED_SEEK_ENTITY) ClearSeek(); + if (m_objective == OBJECTIVE_FOLLOW_CHAR_IN_FORMATION && !m_pedInObjective) { + m_objective = OBJECTIVE_NONE; + ClearObjective(); + SetWanderPath(0); + return false; + } + float seekPosDist = (m_vecSeekPos - GetPosition()).Magnitude2D(); if (seekPosDist < 2.0f || m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT) { @@ -7235,7 +8770,9 @@ CPed::Seek(void) } else if (m_objective != OBJECTIVE_FOLLOW_CHAR_IN_FORMATION) { - if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS || m_objective == OBJECTIVE_RUN_TO_AREA || bIsRunning) + if (m_objective == OBJECTIVE_SPRINT_TO_AREA) + nextMove = PEDMOVE_SPRINT; + else if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS || m_objective == OBJECTIVE_RUN_TO_AREA || bIsRunning) nextMove = PEDMOVE_RUN; else nextMove = PEDMOVE_WALK; @@ -7256,8 +8793,10 @@ CPed::Seek(void) } } - if (seekPosDist >= distanceToCountItDone) { - if (bIsRunning) + CVector *nextNode = SeekFollowingPath(); + + if (nextNode || seekPosDist >= distanceToCountItDone) { + if (bIsRunning && nextMove != PEDMOVE_SPRINT) nextMove = PEDMOVE_RUN; if (CTimer::GetTimeInMilliseconds() <= m_nPedStateTimer) { @@ -7289,14 +8828,21 @@ CPed::Seek(void) CVector2D moveDist(GetPosition().x - m_actionX, GetPosition().y - m_actionY); if (moveDist.Magnitude() < 0.5f) { m_nPedStateTimer = 0; - m_actionX = 0; - m_actionY = 0; + m_actionX = 0.f; + m_actionY = 0.f; } } + } else { - m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( - m_vecSeekPos.x, m_vecSeekPos.y, - GetPosition().x, GetPosition().y); + if (nextNode) { + m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( + nextNode->x, nextNode->y, + GetPosition().x, GetPosition().y); + } else { + m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( + m_vecSeekPos.x, m_vecSeekPos.y, + GetPosition().x, GetPosition().y); + } float neededTurn = Abs(m_fRotationDest - m_fRotationCur); @@ -7304,7 +8850,7 @@ CPed::Seek(void) neededTurn = TWOPI - neededTurn; if (neededTurn > HALFPI) { - if (seekPosDist >= 1.0 && neededTurn <= DEGTORAD(135.0f)) { + if (seekPosDist >= 1.0f && neededTurn <= DEGTORAD(135.0f)) { if (seekPosDist < 2.0f) nextMove = PEDMOVE_WALK; } else { @@ -7314,7 +8860,7 @@ CPed::Seek(void) } if (((m_nPedState == PED_FLEE_POS || m_nPedState == PED_FLEE_ENTITY) && m_nMoveState < nextMove) - || (m_nPedState != PED_FLEE_POS && m_nPedState != PED_FLEE_ENTITY && m_objective != OBJECTIVE_GOTO_CHAR_ON_FOOT && m_nWaitState == WAITSTATE_FALSE)) { + || (m_nPedState != PED_FLEE_POS && m_nPedState != PED_FLEE_ENTITY && m_nPedState != PED_FOLLOW_PATH && m_objective != OBJECTIVE_GOTO_CHAR_ON_FOOT && m_nWaitState == WAITSTATE_FALSE)) { SetMoveState(nextMove); } @@ -7325,11 +8871,13 @@ CPed::Seek(void) if ((m_objective != OBJECTIVE_FOLLOW_CHAR_IN_FORMATION || m_pedInObjective->m_nMoveState == PEDMOVE_STILL) && m_nMoveState != PEDMOVE_STILL) { m_nPedStateTimer = 0; - m_actionX = 0; - m_actionY = 0; + m_actionX = 0.f; + m_actionY = 0.f; } - if (m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA || m_objective == OBJECTIVE_GOTO_AREA_ANY_MEANS) { + if (m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA || m_objective == OBJECTIVE_SPRINT_TO_AREA || + m_objective == OBJECTIVE_GOTO_AREA_ANY_MEANS || IsUseAttractorObjective(m_objective)) { + if (m_pNextPathNode) m_pNextPathNode = nil; else @@ -7338,18 +8886,34 @@ CPed::Seek(void) bUsePedNodeSeek = true; } - if (SeekFollowingPath(nil)) - m_nCurPathNode++; - return true; } -bool -CPed::SeekFollowingPath(CVector *unused) +// --MIAMI: Done +CVector* +CPed::SeekFollowingPath(void) { - return m_nCurPathNode <= m_nPathNodes && m_nPathNodes; + // unused + if (!vecNextPathNodeInitialized) + vecNextPathNodeInitialized = true; + + if (m_nCurPathNodeId >= m_nNumPathNodes || m_nNumPathNodes == 0) + return nil; + + vecNextPathNode = m_pathNodesToGo[m_nCurPathNodeId]->GetPosition(); + + if ((vecNextPathNode - GetPosition()).Magnitude2D() < m_distanceToCountSeekDone) { + m_nCurPathNodeId++; + if (m_nCurPathNodeId < m_nNumPathNodes) + m_pCurPathNode = m_pathNodesToGo[m_nCurPathNodeId]; + } + if (m_nCurPathNodeId == m_nNumPathNodes) + return nil; + else + return &vecNextPathNode; } +// --MIAMI: Done void CPed::Flee(void) { @@ -7361,11 +8925,14 @@ CPed::Flee(void) } if (mayFinishFleeing) { + bMakeFleeScream = false; eMoveState moveState = m_nMoveState; ClearFlee(); - if (m_objective == OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE || m_objective == OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS) + if (m_objective == OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE || m_objective == OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS) { + bBeingChasedByPolice = false; RestorePreviousObjective(); + } if ((m_nPedState == PED_IDLE || m_nPedState == PED_WANDER_PATH) && CGeneral::GetRandomNumber() & 1) { SetWaitState(moveState <= PEDMOVE_WALK ? WAITSTATE_CROSS_ROAD_LOOK : WAITSTATE_FINISH_FLEE, nil); @@ -7375,6 +8942,11 @@ CPed::Flee(void) m_fleeTimer = CTimer::GetTimeInMilliseconds() + 5000; } + if (bMakeFleeScream && !((CTimer::GetFrameCounter() + m_randomSeed) & 7)) { + Say(SOUND_PED_FLEE_SPRINT); + bMakeFleeScream = false; + } + if (bUsePedNodeSeek) { CPathNode *realLastNode = nil; uint8 nextDirection = 0; @@ -7398,7 +8970,7 @@ CPed::Flee(void) } if (m_pNextPathNode) { - m_vecSeekPos = m_pNextPathNode->GetPosition(); + m_vecSeekPos = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); if (m_nMoveState == PEDMOVE_RUN) bIsRunning = true; @@ -7452,22 +9024,6 @@ CPed::Flee(void) m_fRotationDest -= TWOPI; } - if (CTimer::GetTimeInMilliseconds() & 0x20) { - //CVector forwardPos = GetPosition(); - CMatrix forwardMat(GetMatrix()); - forwardMat.GetPosition() += Multiply3x3(forwardMat, CVector(0.0f, 4.0f, 0.0f)); - CVector forwardPos = forwardMat.GetPosition(); - - CEntity *foundEnt; - CColPoint foundCol; - bool found = CWorld::ProcessVerticalLine(forwardPos, forwardMat.GetPosition().z - 100.0f, foundCol, foundEnt, 1, 0, 0, 0, 1, 0, 0); - - if (!found || Abs(forwardPos.z - forwardMat.GetPosition().z) > 1.0f) { - m_fRotationDest += DEGTORAD(112.5f); - m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 2000; - } - } - if (CTimer::GetTimeInMilliseconds() >= m_collidingThingTimer) return; @@ -7477,7 +9033,6 @@ CPed::Flee(void) double collidingThingPriorityMult = (double)(m_collidingThingTimer - CTimer::GetTimeInMilliseconds()) * 2.0 / 2500; if (collidingThingPriorityMult <= 1.5) { - double angleToFleeEntity = CGeneral::GetRadianAngleBetweenPoints( GetPosition().x, GetPosition().y, @@ -7532,39 +9087,46 @@ CPed::Flee(void) } +// --MIAMI: Done void CPed::FollowPath(void) { - m_vecSeekPos.x = m_stPathNodeStates[m_nCurPathNode].x; - m_vecSeekPos.y = m_stPathNodeStates[m_nCurPathNode].y; - m_vecSeekPos.z = GetPosition().z; - - // Mysterious code -/* int v4 = 0; - int maxNodeIndex = m_nPathNodes - 1; - if (maxNodeIndex > 0) { - if (maxNodeIndex > 8) { - while (v4 < maxNodeIndex - 8) - v4 += 8; - } - - while (v4 < maxNodeIndex) - v4++; + m_pCurPathNode = m_pathNodesToGo[m_nCurPathNodeId]; + if (m_pathNodeTimer > 0 && CTimer::GetTimeInMilliseconds() > m_pathNodeTimer) { + RestorePreviousState(); + ClearFollowPath(); + m_pathNodeTimer = 0; + } else { + if (m_pathNodesToGo[m_nCurPathNodeId]) { + m_vecSeekPos.x = m_pathNodesToGo[m_nCurPathNodeId]->GetPosition().x; + m_vecSeekPos.y = m_pathNodesToGo[m_nCurPathNodeId]->GetPosition().y; + m_vecSeekPos.z = GetPosition().z; - } -*/ - if (Seek()) { - m_nCurPathNode++; - if (m_nCurPathNode == m_nPathNodes) + if (Seek()) { + if (m_nCurPathNodeId == m_nNumPathNodes) { + RestorePreviousState(); + ClearFollowPath(); + SetFollowPath(m_followPathDestPos, m_followPathAbortDist, m_followPathMoveState, m_followPathWalkAroundEnt, + m_followPathTargetEnt, m_pathNodeTimer - CTimer::GetTimeInMilliseconds()); + } + } + } else { RestorePreviousState(); + ClearFollowPath(); + m_pathNodeTimer = 0; + } } } +// --MIAMI: Done CVector CPed::GetFormationPosition(void) { CPed *referencePed = m_pedInObjective; + if (!referencePed) + return GetPosition(); + if (referencePed->m_nPedState == PED_DEAD) { CPed *referencePedOfReference = referencePed->m_pedInObjective; if (!referencePedOfReference) { @@ -7575,47 +9137,69 @@ CPed::GetFormationPosition(void) } CVector formationOffset; + float offset = CGeneral::GetRandomNumberInRange(1.f, 1.25f) * 1.75f; switch (m_pedFormation) { case FORMATION_REAR: - formationOffset = CVector(0.0f, -1.5f, 0.0f); + formationOffset = CVector(0.0f, -offset, 0.0f); break; case FORMATION_REAR_LEFT: - formationOffset = CVector(-1.5f, -1.5f, 0.0f); + formationOffset = CVector(-offset, -offset, 0.0f); break; case FORMATION_REAR_RIGHT: - formationOffset = CVector(1.5f, -1.5f, 0.0f); + formationOffset = CVector(offset, -offset, 0.0f); break; case FORMATION_FRONT_LEFT: - formationOffset = CVector(-1.5f, 1.5f, 0.0f); + formationOffset = CVector(-offset, offset, 0.0f); break; case FORMATION_FRONT_RIGHT: - formationOffset = CVector(1.5f, 1.5f, 0.0f); + formationOffset = CVector(offset, offset, 0.0f); break; case FORMATION_LEFT: - formationOffset = CVector(-1.5f, 0.0f, 0.0f); + formationOffset = CVector(-offset, 0.0f, 0.0f); break; case FORMATION_RIGHT: - formationOffset = CVector(1.5f, 0.0f, 0.0f); + formationOffset = CVector(offset, 0.0f, 0.0f); break; case FORMATION_FRONT: - formationOffset = CVector(0.0f, 1.5f, 0.0f); + formationOffset = CVector(0.0f, offset, 0.0f); break; default: formationOffset = CVector(0.0f, 0.0f, 0.0f); break; } - return formationOffset + referencePed->GetPosition(); + return m_pedInObjective->GetMatrix() * formationOffset; } +// --MIAMI: Done void CPed::GetNearestDoor(CVehicle *veh, CVector &posToOpen) { CVector *enterOffset = nil; - if (m_vehEnterType == CAR_DOOR_LF && veh->pDriver - || m_vehEnterType == CAR_DOOR_RF && veh->pPassengers[0] - || m_vehEnterType == CAR_DOOR_LR && veh->pPassengers[1] - || m_vehEnterType == CAR_DOOR_RR && veh->pPassengers[2]) - { + if (veh->IsBike()) { + if (m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER) { + + // If bike didn't fall to ground + if (Abs(veh->GetRight().z) < 0.1f) { + float angleDiff = (GetPosition() - veh->GetPosition()).Heading() - veh->GetForward().Heading(); + + if (angleDiff > PI) + angleDiff -= TWOPI; + else if (angleDiff < -PI) + angleDiff += TWOPI; + + if (Abs(angleDiff) < DEGTORAD(30.f) + && (IsPlayer() && ((CPlayerPed*)this)->m_fMoveSpeed > 1.5f && !m_vehEnterType || + !IsPlayer() && m_nPedType != PEDTYPE_COP && m_nMoveState == PEDMOVE_RUN + && m_pedStats->m_temper > 65 + && !m_vehEnterType || m_vehEnterType == CAR_WINDSCREEN)) { + m_vehEnterType = CAR_WINDSCREEN; + CVector windscreenPos = GetPositionToOpenCarDoor(veh, CAR_WINDSCREEN); + posToOpen = windscreenPos; + return; + } + } + } + } else if (m_vehEnterType == CAR_DOOR_LF && veh->pDriver && !veh->bLowVehicle && !veh->bIsBus) { enterOffset = &vecPedQuickDraggedOutCarAnimOffset; } @@ -7628,7 +9212,7 @@ CPed::GetNearestDoor(CVehicle *veh, CVector &posToOpen) if (veh->IsRoomForPedToLeaveCar(CAR_DOOR_RF, enterOffset)) { CPed *rfPassenger = veh->pPassengers[0]; - if (!rfPassenger + if (!rfPassenger || veh->IsBike() || rfPassenger->m_leader != this && !rfPassenger->bDontDragMeOutCar && (veh->VehicleCreatedBy != MISSION_VEHICLE || m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER) || veh->IsRoomForPedToLeaveCar(CAR_DOOR_LF, enterOffset) == 0) { @@ -7660,6 +9244,7 @@ CPed::GetNearestDoor(CVehicle *veh, CVector &posToOpen) } } +// --MIAMI: Done bool CPed::GetNearestPassengerDoor(CVehicle *veh, CVector &posToOpen) { @@ -7682,7 +9267,22 @@ CPed::GetNearestPassengerDoor(CVehicle *veh, CVector &posToOpen) CVector2D lrPosDist(999.0f, 999.0f); CVector2D rrPosDist(999.0f, 999.0f); - if (!veh->pPassengers[0] + if (veh->IsBike()) { + if (!veh->pPassengers[0] + && !(veh->m_nGettingInFlags & CAR_DOOR_FLAG_LR) + && veh->IsRoomForPedToLeaveCar(CAR_DOOR_LR, nil)) { + lrPos = GetPositionToOpenCarDoor(veh, CAR_DOOR_LR); + canEnter = true; + lrPosDist = lrPos - GetPosition(); + } + if (!veh->pPassengers[0] + && !(veh->m_nGettingInFlags & CAR_DOOR_FLAG_RR) + && veh->IsRoomForPedToLeaveCar(CAR_DOOR_RR, nil)) { + rrPos = GetPositionToOpenCarDoor(veh, CAR_DOOR_RR); + canEnter = true; + rrPosDist = rrPos - GetPosition(); + } + } else if (!veh->pPassengers[0] && !(veh->m_nGettingInFlags & CAR_DOOR_FLAG_RF) && veh->IsRoomForPedToLeaveCar(CAR_DOOR_RF, nil)) { @@ -7690,6 +9290,7 @@ CPed::GetNearestPassengerDoor(CVehicle *veh, CVector &posToOpen) canEnter = true; rfPosDist = rfPos - GetPosition(); } + if (vehModel->m_numDoors == 4) { if (!veh->pPassengers[1] && !(veh->m_nGettingInFlags & CAR_DOOR_FLAG_LR) @@ -7727,6 +9328,7 @@ CPed::GetNearestPassengerDoor(CVehicle *veh, CVector &posToOpen) return canEnter; } +// --MIAMI: Done int CPed::GetNextPointOnRoute(void) { @@ -7754,93 +9356,25 @@ CPed::GetNextPointOnRoute(void) return nextPoint; } -// These categories are purely random, most of ped models have no correlation. So I don't think making an enum. uint8 CPed::GetPedRadioCategory(uint32 modelIndex) { - switch (modelIndex) { - case MI_MALE01: - case MI_FEMALE03: - case MI_PROSTITUTE2: - case MI_WORKER1: - case MI_MOD_MAN: - case MI_MOD_WOM: - case MI_ST_WOM: - case MI_FAN_WOM: - return 3; - case MI_TAXI_D: - case MI_PIMP: - case MI_MALE02: - case MI_FEMALE02: - case MI_FATFEMALE01: - case MI_FATFEMALE02: - case MI_DOCKER1: - case MI_WORKER2: - case MI_FAN_MAN2: - return 9; - case MI_GANG01: - case MI_GANG02: - case MI_SCUM_MAN: - case MI_SCUM_WOM: - case MI_HOS_WOM: - case MI_CONST1: - return 1; - case MI_GANG03: - case MI_GANG04: - case MI_GANG07: - case MI_GANG08: - case MI_CT_MAN2: - case MI_CT_WOM2: - case MI_B_MAN3: - case MI_SHOPPER3: - return 4; - case MI_GANG05: - case MI_GANG06: - case MI_GANG11: - case MI_GANG12: - case MI_CRIMINAL02: - case MI_B_WOM2: - case MI_ST_MAN: - case MI_HOS_MAN: - return 5; - case MI_FATMALE01: - case MI_LI_MAN2: - case MI_SHOPPER1: - case MI_CAS_MAN: - return 6; - case MI_PROSTITUTE: - case MI_P_WOM2: - case MI_LI_WOM2: - case MI_B_WOM3: - case MI_CAS_WOM: - return 2; - case MI_P_WOM1: - case MI_DOCKER2: - case MI_STUD_MAN: - return 7; - case MI_CT_MAN1: - case MI_CT_WOM1: - case MI_LI_MAN1: - case MI_LI_WOM1: - case MI_B_MAN1: - case MI_B_MAN2: - case MI_B_WOM1: - case MI_SHOPPER2: - case MI_STUD_WOM: - return 8; - default: - return 0; - } + // TODO(MIAMI): remove this function and use modelinfo for radio + return 1; } -// Some kind of VC leftover I think +// --MIAMI: Done int CPed::GetWeaponSlot(eWeaponType weaponType) { - if (HasWeapon(weaponType)) - return weaponType; - else - return -1; + return CWeaponInfo::GetWeaponInfo(weaponType)->m_nWeaponSlot; +} + +// --MIAMI: Done +bool +CPed::CanWeRunAndFireWithWeapon(void) +{ + return CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAimWithArm; } void @@ -7862,6 +9396,7 @@ CPed::HaveReachedNextPointOnRoute(float distToCountReached) return true; } +// --MIAMI: Done void CPed::Idle(void) { @@ -7883,42 +9418,13 @@ CPed::Idle(void) } } - CAnimBlendAssociation *armedIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_ARMED); - CAnimBlendAssociation *unarmedIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_STANCE); - int waitTime; - - if (m_nMoveState == PEDMOVE_STILL) { - - eWeaponType curWeapon = GetWeapon()->m_eWeaponType; - if (!armedIdleAssoc || - CTimer::GetTimeInMilliseconds() <= m_nWaitTimer && curWeapon != WEAPONTYPE_UNARMED && curWeapon != WEAPONTYPE_MOLOTOV && curWeapon != WEAPONTYPE_GRENADE) { - - if ((!GetWeapon()->IsType2Handed() || curWeapon == WEAPONTYPE_SHOTGUN) && curWeapon != WEAPONTYPE_BASEBALLBAT - || !unarmedIdleAssoc || unarmedIdleAssoc->blendAmount <= 0.95f || m_nWaitState != WAITSTATE_FALSE || CTimer::GetTimeInMilliseconds() <= m_nWaitTimer) { + if (m_nMoveState != PEDMOVE_STILL && !IsPlayer()) + SetMoveState(PEDMOVE_STILL); - m_moved = CVector2D(0.0f, 0.0f); - return; - } - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_ARMED, 3.0f); - waitTime = CGeneral::GetRandomNumberInRange(4000, 7500); - } else { - armedIdleAssoc->blendDelta = -2.0f; - armedIdleAssoc->flags |= ASSOC_DELETEFADEDOUT; - waitTime = CGeneral::GetRandomNumberInRange(3000, 8500); - } - m_nWaitTimer = CTimer::GetTimeInMilliseconds() + waitTime; - } else { - if (armedIdleAssoc) { - armedIdleAssoc->blendDelta = -8.0f; - armedIdleAssoc->flags |= ASSOC_DELETEFADEDOUT; - m_nWaitTimer = 0; - } - if (!IsPlayer()) - SetMoveState(PEDMOVE_STILL); - } m_moved = CVector2D(0.0f, 0.0f); } +// --MIAMI: Done void CPed::InTheAir(void) { @@ -7932,22 +9438,17 @@ CPed::InTheAir(void) if (m_vecMoveSpeed.z < 0.0f && !bIsPedDieAnimPlaying) { if (!DyingOrDead()) { if (CWorld::ProcessLineOfSight(ourPos, bitBelow, foundCol, foundEnt, true, true, false, true, false, false, false)) { - if (GetPosition().z - foundCol.point.z < 1.3f -#ifdef VC_PED_PORTS - || bIsStanding -#endif - ) + if (GetPosition().z - foundCol.point.z < 1.3f || bIsStanding) SetLanding(); - } else { - if (!RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FALL)) { - if (m_vecMoveSpeed.z < -0.1f) - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FALL_FALL, 4.0f); - } + } else if (m_nPedState != PED_ABSEIL && !RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FALL)) { + if (m_vecMoveSpeed.z < -0.1f) + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FALL_FALL, 4.0f); } } } } +// --MIAMI: Done void CPed::SetLanding(void) { @@ -7957,14 +9458,22 @@ CPed::SetLanding(void) CAnimBlendAssociation *fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FALL); CAnimBlendAssociation *landAssoc; + if (fallAssoc && bIsDrowning) + return; + RpAnimBlendClumpSetBlendDeltas(GetClump(), ASSOC_PARTIAL, -1000.0f); - if (fallAssoc) { + if (fallAssoc || m_nPedType == PEDTYPE_COP && bKnockedUpIntoAir) { landAssoc = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_FALL_COLLAPSE); DMAudio.PlayOneShot(m_audioEntityId, SOUND_FALL_COLLAPSE, 1.0f); if (IsPlayer()) Say(SOUND_PED_LAND); + if (m_nPedType == PEDTYPE_COP) { + if (bKnockedUpIntoAir) + bKnockedUpIntoAir = false; + } + } else { landAssoc = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_FALL_LAND); DMAudio.PlayOneShot(m_audioEntityId, SOUND_FALL_LAND, 1.0f); @@ -7985,11 +9494,29 @@ CPed::Initialise(void) debug("CPed ready\n"); } +// --MIAMI: Done void CPed::SetAnimOffsetForEnterOrExitVehicle(void) { // FIX: If there were no translations on enter anims, there were overflows all over this function. + int vanBlock = CAnimManager::GetAnimationBlockIndex("van"); + int bikesBlock = CAnimManager::GetAnimationBlockIndex("bikes"); + int bikevBlock = CAnimManager::GetAnimationBlockIndex("bikev"); + int bikehBlock = CAnimManager::GetAnimationBlockIndex("bikeh"); + int bikedBlock = CAnimManager::GetAnimationBlockIndex("biked"); + CStreaming::RequestAnim(vanBlock, STREAMFLAGS_DEPENDENCY); + CStreaming::RequestAnim(bikesBlock, STREAMFLAGS_DEPENDENCY); + CStreaming::RequestAnim(bikevBlock, STREAMFLAGS_DEPENDENCY); + CStreaming::RequestAnim(bikehBlock, STREAMFLAGS_DEPENDENCY); + CStreaming::RequestAnim(bikedBlock, STREAMFLAGS_DEPENDENCY); + CStreaming::LoadAllRequestedModels(false); + CAnimManager::AddAnimBlockRef(vanBlock); + CAnimManager::AddAnimBlockRef(bikesBlock); + CAnimManager::AddAnimBlockRef(bikevBlock); + CAnimManager::AddAnimBlockRef(bikehBlock); + CAnimManager::AddAnimBlockRef(bikedBlock); + CAnimBlendHierarchy *enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, ANIM_CAR_JACKED_LHS)->hierarchy; CAnimBlendSequence *seq = enterAssoc->sequences; CAnimManager::UncompressAnimation(enterAssoc); @@ -8038,7 +9565,7 @@ CPed::SetAnimOffsetForEnterOrExitVehicle(void) } } - enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, ANIM_VAN_GETIN_L)->hierarchy; + enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_VAN, ANIM_VAN_GETIN_L)->hierarchy; seq = enterAssoc->sequences; CAnimManager::UncompressAnimation(enterAssoc); if (seq->numFrames > 0) { @@ -8049,8 +9576,8 @@ CPed::SetAnimOffsetForEnterOrExitVehicle(void) vecPedVanRearDoorAnimOffset = lastFrame->translation; } } - - enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, ANIM_TRAIN_GETOUT)->hierarchy; + // I think this is leftover and ANIM_TRAIN_GETOUT + enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, ANIM_IDLE_STANCE3)->hierarchy; seq = enterAssoc->sequences; CAnimManager::UncompressAnimation(enterAssoc); if (seq->numFrames > 0) { @@ -8061,6 +9588,72 @@ CPed::SetAnimOffsetForEnterOrExitVehicle(void) vecPedTrainDoorAnimOffset = lastFrame->translation; } } + + enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_BIKE_STANDARD, ANIM_BIKE_JUMPON_R)->hierarchy; + seq = enterAssoc->sequences; + CAnimManager::UncompressAnimation(enterAssoc); + if (seq->numFrames > 0) { + if (!seq->HasTranslation()) + vecPedStdBikeJumpRhsAnimOffset = CVector(0.0f, 0.0f, 0.0f); + else { + KeyFrameTrans* lastFrame = (KeyFrameTrans*)seq->GetKeyFrame(seq->numFrames - 1); + vecPedStdBikeJumpRhsAnimOffset = lastFrame->translation; + } + } + + enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_BIKE_VESPA, ANIM_BIKE_JUMPON_R)->hierarchy; + seq = enterAssoc->sequences; + CAnimManager::UncompressAnimation(enterAssoc); + if (seq->numFrames > 0) { + if (!seq->HasTranslation()) + vecPedVespaBikeJumpRhsAnimOffset = CVector(0.0f, 0.0f, 0.0f); + else { + KeyFrameTrans* lastFrame = (KeyFrameTrans*)seq->GetKeyFrame(seq->numFrames - 1); + vecPedVespaBikeJumpRhsAnimOffset = lastFrame->translation; + } + } + + enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_BIKE_HARLEY, ANIM_BIKE_JUMPON_R)->hierarchy; + seq = enterAssoc->sequences; + CAnimManager::UncompressAnimation(enterAssoc); + if (seq->numFrames > 0) { + if (!seq->HasTranslation()) + vecPedHarleyBikeJumpRhsAnimOffset = CVector(0.0f, 0.0f, 0.0f); + else { + KeyFrameTrans* lastFrame = (KeyFrameTrans*)seq->GetKeyFrame(seq->numFrames - 1); + vecPedHarleyBikeJumpRhsAnimOffset = lastFrame->translation; + } + } + + enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_BIKE_DIRT, ANIM_BIKE_JUMPON_R)->hierarchy; + seq = enterAssoc->sequences; + CAnimManager::UncompressAnimation(enterAssoc); + if (seq->numFrames > 0) { + if (!seq->HasTranslation()) + vecPedDirtBikeJumpRhsAnimOffset = CVector(0.0f, 0.0f, 0.0f); + else { + KeyFrameTrans* lastFrame = (KeyFrameTrans*)seq->GetKeyFrame(seq->numFrames - 1); + vecPedDirtBikeJumpRhsAnimOffset = lastFrame->translation; + } + } + + enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_BIKE_HARLEY, ANIM_BIKE_KICK)->hierarchy; + seq = enterAssoc->sequences; + CAnimManager::UncompressAnimation(enterAssoc); + if (seq->numFrames > 0) { + if (!seq->HasTranslation()) + vecPedBikeKickAnimOffset = CVector(0.0f, 0.0f, 0.0f); + else { + KeyFrameTrans* lastFrame = (KeyFrameTrans*)seq->GetKeyFrame(seq->numFrames - 1); + vecPedBikeKickAnimOffset = lastFrame->translation; + } + } + + CAnimManager::RemoveAnimBlockRef(vanBlock); + CAnimManager::RemoveAnimBlockRef(bikesBlock); + CAnimManager::RemoveAnimBlockRef(bikevBlock); + CAnimManager::RemoveAnimBlockRef(bikehBlock); + CAnimManager::RemoveAnimBlockRef(bikedBlock); } void @@ -8263,22 +9856,29 @@ CPed::InvestigateEvent(void) } } +// --MIAMI: Done bool CPed::IsPedDoingDriveByShooting(void) { +#ifdef FIX_BUGS + if (FindPlayerPed() == this && CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nWeaponSlot == 5) { +#else if (FindPlayerPed() == this && GetWeapon()->m_eWeaponType == WEAPONTYPE_UZI) { +#endif if (TheCamera.Cams[TheCamera.ActiveCam].LookingLeft || TheCamera.Cams[TheCamera.ActiveCam].LookingRight) return true; } return false; } +// --MIAMI: Done bool CPed::IsPedShootable(void) { return m_nPedState <= PED_STATES_NO_ST; } +// --MIAMI: Done bool CPed::IsRoomToBeCarJacked(void) { @@ -8286,7 +9886,9 @@ CPed::IsRoomToBeCarJacked(void) return false; CVector offset; - if (m_pMyVehicle->bLowVehicle || m_nPedType == PEDTYPE_COP) { + if (m_pMyVehicle->IsBike()) { + offset = vecPedStdBikeJumpRhsAnimOffset; + } else if (m_pMyVehicle->bLowVehicle || m_nPedType == PEDTYPE_COP) { offset = vecPedDraggedOutCarAnimOffset; } else { offset = vecPedQuickDraggedOutCarAnimOffset; @@ -8300,6 +9902,7 @@ CPed::IsRoomToBeCarJacked(void) return false; } +// --MIAMI: Done void CPed::KillPedWithCar(CVehicle *car, float impulse) { @@ -8310,8 +9913,8 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) eWeaponType killMethod; if (m_nPedState == PED_FALL || m_nPedState == PED_DIE) { - if (!this->m_pCollidingEntity || car->GetStatus() == STATUS_PLAYER) - this->m_pCollidingEntity = car; + if (!m_pCollidingEntity || car->GetStatus() == STATUS_PLAYER) + m_pCollidingEntity = car; return; } @@ -8319,7 +9922,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) return; if (m_pCurSurface) { - if (m_pCurSurface->IsVehicle() && (((CVehicle*)m_pCurSurface)->m_vehType == VEHICLE_TYPE_BOAT || IsPlayer())) + if (m_pCurSurface->IsVehicle() && (((CVehicle*)m_pCurSurface)->IsBoat()|| IsPlayer())) return; } @@ -8341,7 +9944,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) CPad::GetPad(0)->StartShake(40000 / shakeFreq, shakeFreq); } bIsStanding = false; - damageDir = CPed::GetLocalDirection(-m_vecMoveSpeed); + damageDir = GetLocalDirection(-m_vecMoveSpeed); vehModel = (CVehicleModelInfo *)CModelInfo::GetModelInfo(car->GetModelIndex()); vehColModel = vehModel->GetColModel(); float carRightAndDistDotProd = DotProduct(distVec, car->GetRight()); @@ -8381,7 +9984,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) float carFrontAndDistDotProd = DotProduct(distVec, car->GetForward()); // carFrontAndDistDotProd <= 0.0 car looks to us - if ((carFrontAndDistDotProd <= 0.1 || randVal == 1) && randVal != 0) { + if ((carFrontAndDistDotProd <= 0.1 || randVal <= 1) && randVal != 0) { killMethod = WEAPONTYPE_RUNOVERBYCAR; nodeToDamage = PED_HEAD; m_vecMoveSpeed = 0.9f * car->m_vecMoveSpeed; @@ -8426,7 +10029,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) // TODO: What are we doing down here? float unknown = ((CGeneral::GetRandomNumber() % 256) * 0.002 + 1.5) * pedJumpSpeedToReachHighestZ; - // After this point, distVec isn't distVec anymore. + // After this point distVec isn't really distVec. distVec = car->m_vecMoveSpeed; distVec.Normalise(); distVec *= 0.2 * unknown; @@ -8441,7 +10044,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) if (damageDir > 3) damageDir = damageDir - 4; - if (car->m_vehType == VEHICLE_TYPE_CAR) { + if (car->IsCar()) { CObject *bonnet = ((CAutomobile*)car)->RemoveBonnetInPedCollision(); if (bonnet) { @@ -8490,9 +10093,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) distVec.Normalise(); -#ifdef VC_PED_PORTS distVec *= Min(car->m_fMass / 1400.0f, 1.0f); -#endif car->ApplyMoveForce(distVec * -100.0f); Say(SOUND_PED_DEFEND); @@ -8511,7 +10112,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) CPed::SetFall(1000, (AnimationId)(fallDirection + ANIM_KO_SKID_FRONT), true); if (OnGround() && !m_pCollidingEntity && - (!IsPlayer() || bHasHitWall || car->GetModelIndex() == MI_TRAIN || m_vecDamageNormal.z < -0.8f)) { + (!IsPlayer() || bHasHitWall || car->GetModelIndex() == MI_TRAIN || m_vecDamageNormal.z < -0.8f)) { m_pCollidingEntity = car; } @@ -8522,15 +10123,11 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) } m_vecMoveSpeed.z = 0.0f; distVec.Normalise(); -#ifdef VC_PED_PORTS distVec *= Min(car->m_fMass / 1400.0f, 1.0f); -#endif car->ApplyMoveForce(distVec * -60.0f); Say(SOUND_PED_DEFEND); } -#ifdef VC_PED_PORTS - // Killing gang members with car wasn't triggering a fight, until now... Taken from VC. if (IsGangMember()) { CPed *driver = car->pDriver; if (driver && driver->IsPlayer() @@ -8541,13 +10138,12 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) RegisterThreatWithGangPeds(driver); } } -#endif } void CPed::Look(void) { - // UNUSED: This is a perfectly empty function. + TurnBody(); } bool @@ -8742,6 +10338,7 @@ CPed::LookForSexyCars(void) } } +// --MIAMI: Done void CPed::LookForSexyPeds(void) { @@ -8852,6 +10449,7 @@ CPed::Mug(void) } } +// --MIAMI: Done void CPed::MoveHeadToLook(void) { @@ -8859,40 +10457,15 @@ CPed::MoveHeadToLook(void) if (m_lookTimer && CTimer::GetTimeInMilliseconds() > m_lookTimer) { ClearLookFlag(); - } else if (m_nPedState == PED_DRIVING) { - m_pedIK.m_flags |= CPedIK::LOOKAROUND_HEAD_ONLY; - } - - if (m_pLookTarget) { - - if (!bShakeFist && GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED) { - - CAnimBlendAssociation *fuckUAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FUCKU); - if (fuckUAssoc) { + } - float animTime = fuckUAssoc->currentTime; - if (animTime > 4.0f / 30.0f && animTime - fuckUAssoc->timeStep > 4.0f / 30.0f) { - - bool lookingToCop = false; - if (m_pLookTarget->GetModelIndex() == MI_POLICE - || m_pLookTarget->IsPed() && ((CPed*)m_pLookTarget)->m_nPedType == PEDTYPE_COP) { - - lookingToCop = true; - } - - if (IsPlayer() && (m_pedStats->m_temper >= 52 || lookingToCop)) { - AddWeaponModel(MI_FINGERS); - ((CPlayerPed*)this)->AnnoyPlayerPed(true); - - } else if ((CGeneral::GetRandomNumber() & 3) == 0) { - AddWeaponModel(MI_FINGERS); - } - } - } - } + if (bIsLooking || bIsRestoringLook) + if (!CanUseTorsoWhenLooking()) + m_pedIK.m_flags |= CPedIK::LOOKAROUND_HEAD_ONLY; + if (m_pLookTarget) { if (m_pLookTarget->IsPed()) { - ((CPed*)m_pLookTarget)->m_pedIK.GetComponentPosition((RwV3d*) &lookPos, PED_MID); + ((CPed*)m_pLookTarget)->m_pedIK.GetComponentPosition(*(RwV3d *)&lookPos, PED_MID); } else { lookPos = m_pLookTarget->GetPosition(); } @@ -8907,12 +10480,15 @@ CPed::MoveHeadToLook(void) if (!bShakeFist || bIsAimingGun || bIsRestoringGun) return; + if (m_nPedState == PED_ANSWER_MOBILE) + return; + if (m_lookTimer - CTimer::GetTimeInMilliseconds() >= 1000) return; bool notRocketLauncher = false; bool notTwoHanded = false; - AnimationId animToPlay = NUM_ANIMS; + AnimationId animToPlay = NUM_STD_ANIMS; if (!GetWeapon()->IsType2Handed()) notTwoHanded = true; @@ -8941,14 +10517,12 @@ CPed::MoveHeadToLook(void) animToPlay = ANIM_FUCKU; } - if (animToPlay != NUM_ANIMS) { + if (animToPlay != NUM_STD_ANIMS) { CAnimBlendAssociation *newAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, animToPlay, 4.0f); if (newAssoc) { newAssoc->flags |= ASSOC_FADEOUTWHENDONE; newAssoc->flags |= ASSOC_DELETEFADEDOUT; - if (newAssoc->animId == ANIM_FUCKU) - newAssoc->SetDeleteCallback(FinishFuckUCB, this); } } bShakeFist = false; @@ -8968,15 +10542,7 @@ CPed::MoveHeadToLook(void) } } -void -FinishFuckUCB(CAnimBlendAssociation *animAssoc, void *arg) -{ - CPed *ped = (CPed*)arg; - - if (animAssoc->animId == ANIM_FUCKU && ped->GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED) - ped->RemoveWeaponModel(0); -} - +// --MIAMI: Done void CPed::Pause(void) { @@ -8985,6 +10551,7 @@ CPed::Pause(void) ClearPause(); } +// --MIAMI: Done void CPed::PedAnimAlignCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -8998,24 +10565,25 @@ CPed::PedAnimAlignCB(CAnimBlendAssociation *animAssoc, void *arg) return; if (!ped->EnteringCar()) { -#ifdef VC_PED_PORTS if (ped->m_nPedState != PED_DRIVING) -#endif ped->QuitEnteringCar(); return; } + + if (!ped->m_vehEnterType) { + ped->QuitEnteringCar(); + return; + } + if (ped->m_fHealth == 0.0f) { ped->QuitEnteringCar(); return; } bool itsVan = !!veh->bIsVan; bool itsBus = !!veh->bIsBus; -#ifdef FIX_BUGS bool itsLow = !!veh->bLowVehicle; -#endif eDoors enterDoor; - AnimationId enterAnim; switch (ped->m_vehEnterType) { case CAR_DOOR_RF: @@ -9036,37 +10604,135 @@ CPed::PedAnimAlignCB(CAnimBlendAssociation *animAssoc, void *arg) break; } + if (veh->IsBike()) { + CPed *pedToDragOut = nil; + if (veh->GetStatus() == STATUS_ABANDONED) { + if (ped->m_vehEnterType == CAR_WINDSCREEN) { + ped->m_pVehicleAnim = CAnimManager::BlendAnimation(ped->GetClump(), ((CBike*)veh)->m_bikeAnimType, ANIM_BIKE_KICK, 6.0f); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); + ((CBike*)veh)->bIsBeingPickedUp = true; + + } else if (veh->GetRight().z >= 0.5f || veh->GetRight().z <= -0.5f || veh->GetUp().z <= 0.0f) { + if (enterDoor == DOOR_FRONT_LEFT || enterDoor == DOOR_REAR_LEFT) { + if (veh->GetRight().z > 0.0f) + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_BIKE_PICKUP_R); + else + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_BIKE_PULLUP_R); + + } else { + if (veh->GetRight().z < 0.0f) + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_BIKE_PICKUP_L); + else + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_BIKE_PULLUP_L); + } + ped->m_pVehicleAnim->SetFinishCallback(PedAnimDoorOpenCB, ped); + + } else { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ((CBike*)veh)->m_bikeAnimType, + enterDoor == DOOR_FRONT_LEFT || enterDoor == DOOR_REAR_LEFT ? ANIM_BIKE_JUMPON_R : ANIM_BIKE_JUMPON_L); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); + ((CBike*)veh)->bIsBeingPickedUp = true; + } + } else if (ped->m_vehEnterType == CAR_WINDSCREEN) { + if (veh->pDriver->m_nPedState != PED_DRIVING || veh->pDriver->bDontDragMeOutCar) { + ped->QuitEnteringCar(); + } else { + ped->m_pVehicleAnim = CAnimManager::BlendAnimation(ped->GetClump(), ((CBike*)veh)->m_bikeAnimType, ANIM_BIKE_KICK, 6.0f); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); + pedToDragOut = veh->pDriver; + } + ((CBike*)veh)->bIsBeingPickedUp = true; + } else { + if (enterDoor == DOOR_FRONT_LEFT || enterDoor == DOOR_FRONT_RIGHT) { + if (veh->pDriver) { + if (veh->m_vecMoveSpeed.Magnitude() > 0.2f) { + ped->QuitEnteringCar(); + ped->SetFall(1000, ped->m_vehEnterType == CAR_DOOR_LF || ped->m_vehEnterType == CAR_DOOR_LR ? ANIM_KO_SPIN_L : ANIM_KO_SPIN_R, false); + return; + } + if (veh->pDriver->m_nPedState != PED_DRIVING || veh->pDriver->bDontDragMeOutCar) { + ped->QuitEnteringCar(); + } else { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, enterDoor == DOOR_FRONT_LEFT ? ANIM_BIKE_ELBOW_R : ANIM_BIKE_ELBOW_L); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimPullPedOutCB, ped); + pedToDragOut = veh->pDriver; + } + ((CBike*)veh)->bIsBeingPickedUp = true; + + } else { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ((CBike*)veh)->m_bikeAnimType, enterDoor == DOOR_FRONT_LEFT ? ANIM_BIKE_JUMPON_R : ANIM_BIKE_JUMPON_L); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); + ((CBike*)veh)->bIsBeingPickedUp = true; + } + } else { + if (veh->pPassengers[0]) { + if (veh->m_vecMoveSpeed.Magnitude() > 0.2f) { + ped->QuitEnteringCar(); + ped->SetFall(1000, ped->m_vehEnterType == CAR_DOOR_LF || ped->m_vehEnterType == CAR_DOOR_LR ? ANIM_KO_SPIN_L : ANIM_KO_SPIN_R, false); + return; + } + if (veh->pPassengers[0]->m_nPedState != PED_DRIVING || veh->pPassengers[0]->bDontDragMeOutCar) { + ped->QuitEnteringCar(); + } else { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, + enterDoor == DOOR_REAR_LEFT ? ANIM_BIKE_ELBOW_R : ANIM_BIKE_ELBOW_L); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimPullPedOutCB, ped); + pedToDragOut = veh->pPassengers[0]; + } + ((CBike*)veh)->bIsBeingPickedUp = true; + + } else { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), + ((CBike*)veh)->m_bikeAnimType, enterDoor == DOOR_REAR_LEFT ? ANIM_BIKE_JUMPON_R : ANIM_BIKE_JUMPON_L); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); + ((CBike*)veh)->bIsBeingPickedUp = true; + } + } + } + + // TODO(Miami): This looks like something inlined + if (pedToDragOut) { + pedToDragOut->SetBeingDraggedFromCar(veh, ped->m_vehEnterType, false); + if (pedToDragOut->IsGangMember()) + pedToDragOut->RegisterThreatWithGangPeds(ped); + + if (ped->m_nPedType == PEDTYPE_COP && pedToDragOut == FindPlayerPed() && veh->IsBike()) + ((CCopPed*)ped)->field_601 = 1; + + if (pedToDragOut == veh->pDriver) { + if (veh->pPassengers[0]) + veh->pPassengers[0]->SetBeingDraggedFromCar(veh, CAR_DOOR_LR, false); + } + } + return; + } + if (veh->IsDoorMissing(enterDoor) || veh->IsDoorFullyOpen(enterDoor)) { veh->AutoPilot.m_nCruiseSpeed = 0; - if (ped->m_nPedState == PED_CARJACK) { + if (ped->m_nPedState == PED_CARJACK || veh->m_nNumMaxPassengers == 0 && veh->pDriver && enterDoor == DOOR_FRONT_RIGHT) { ped->PedAnimDoorOpenCB(nil, ped); return; } if (enterDoor != DOOR_FRONT_LEFT && enterDoor != DOOR_REAR_LEFT) { if (itsVan) { - enterAnim = ANIM_VAN_GETIN; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_GETIN); } else if (itsBus) { - enterAnim = ANIM_COACH_IN_R; -#ifdef FIX_BUGS + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_IN_R); } else if (itsLow) { - enterAnim = ANIM_CAR_GETIN_LOW_RHS; -#endif + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_RHS); } else { - enterAnim = ANIM_CAR_GETIN_RHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_RHS); } } else if (itsVan) { - enterAnim = ANIM_VAN_GETIN_L; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_GETIN_L); } else if (itsBus) { - enterAnim = ANIM_COACH_IN_L; -#ifdef FIX_BUGS + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_IN_L); } else if (itsLow) { - enterAnim = ANIM_CAR_GETIN_LOW_LHS; -#endif + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_LHS); } else { - enterAnim = ANIM_CAR_GETIN_LHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LHS); } - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, enterAnim); ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); } else if (veh->CanPedOpenLocks(ped)) { @@ -9074,16 +10740,16 @@ CPed::PedAnimAlignCB(CAnimBlendAssociation *animAssoc, void *arg) veh->AutoPilot.m_nCruiseSpeed = 0; if (enterDoor != DOOR_FRONT_LEFT && enterDoor != DOOR_REAR_LEFT) { if (itsVan) { - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_VAN_OPEN); + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_OPEN); } else if (itsBus) { - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_COACH_OPEN_R); + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_OPEN_R); } else { ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_OPEN_RHS); } } else if (itsVan) { - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_VAN_OPEN_L); + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_OPEN_L); } else if (itsBus) { - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_COACH_OPEN_L); + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_OPEN_L); } else { if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER && veh->pDriver) { @@ -9094,13 +10760,29 @@ CPed::PedAnimAlignCB(CAnimBlendAssociation *animAssoc, void *arg) ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_QJACK); ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); - veh->pDriver->SetBeingDraggedFromCar(veh, ped->m_vehEnterType, true); - if (veh->pDriver->IsGangMember()) - veh->pDriver->RegisterThreatWithGangPeds(ped); + // TODO(Miami): This may be inlined + CPlayerPed *player = nil; + CCopPed *cop = nil; + veh->MakeNonDraggedPedsLeaveVehicle(veh->pDriver, ped, player, cop); + if (player && cop) { + cop->QuitEnteringCar(); + cop->SetArrestPlayer(player); + } + + if (player != veh->pDriver) { + veh->pDriver->SetBeingDraggedFromCar(veh, ped->m_vehEnterType, true); + if (veh->pDriver->IsGangMember()) + veh->pDriver->RegisterThreatWithGangPeds(ped); + } return; } } + if (veh->IsOpenTopCar() && !veh->pDriver && ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_JUMPIN_LHS); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); + return; + } ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_OPEN_LHS); } ped->m_pVehicleAnim->SetFinishCallback(PedAnimDoorOpenCB, ped); @@ -9116,14 +10798,15 @@ CPed::PedAnimAlignCB(CAnimBlendAssociation *animAssoc, void *arg) } } +// --MIAMI: Done? void CPed::ProcessControl(void) { CColPoint foundCol; CEntity *foundEnt = nil; - if (m_nZoneLevel > LEVEL_GENERIC && m_nZoneLevel != CCollision::ms_collisionInMemory) - return; + if (CTimer::GetFrameCounter() + m_randomSeed % 32 == 0) + PruneReferences(); int alpha = CVisibilityPlugins::GetClumpAlpha(GetClump()); if (!bFadeOut) { @@ -9140,8 +10823,10 @@ CPed::ProcessControl(void) CVisibilityPlugins::SetClumpAlpha(GetClump(), alpha); bIsShooting = false; + b158_40 = false; BuildPedLists(); bIsInWater = false; + bIsDrowning = false; ProcessBuoyancy(); if (m_nPedState != PED_ARRESTED) { @@ -9174,6 +10859,7 @@ CPed::ProcessControl(void) if (!nearPed->bIsLooking && nearPed->m_nPedState != PED_ATTACK) { int16 camMode = TheCamera.Cams[TheCamera.ActiveCam].Mode; if (camMode != CCam::MODE_SNIPER + && camMode != CCam::MODE_CAMERA && camMode != CCam::MODE_ROCKETLAUNCHER && camMode != CCam::MODE_M16_1STPERSON && camMode != CCam::MODE_1STPERSON @@ -9209,13 +10895,11 @@ CPed::ProcessControl(void) if (ServiceTalkingWhenDead()) ServiceTalking(); -#ifdef VC_PED_PORTS if (bIsInWater) { bIsStanding = false; bWasStanding = false; CPhysical::ProcessControl(); } -#endif return; } @@ -9236,16 +10920,15 @@ CPed::ProcessControl(void) ++m_panicCounter; if (m_fHealth <= 1.0f && m_nPedState <= PED_STATES_NO_AI && !bIsInTheAir && !bIsLanding) - SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); + SetDie(); + + if (bIsStanding) + bPushedAlongByCar = false; bCollidedWithMyVehicle = false; CEntity *collidingEnt = m_pDamageEntity; -#ifndef VC_PED_PORTS - if (!bUsesCollision || m_fDamageImpulse <= 0.0f || m_nPedState == PED_DIE || !collidingEnt) { -#else - if (!bUsesCollision || ((!collidingEnt || m_fDamageImpulse <= 0.0f) && (!IsPlayer() || !bIsStuck)) || m_nPedState == PED_DIE) { -#endif + if (!bUsesCollision || ((!collidingEnt || m_fDamageImpulse <= 0.0f) && (!IsPlayer() || !bIsStuck)) || m_nPedState == PED_DIE) { bHitSomethingLastFrame = false; if (m_nPedStateTimer <= 500 && bIsInTheAir) { if (m_nPedStateTimer) @@ -9253,7 +10936,7 @@ CPed::ProcessControl(void) } else if (m_nPedStateTimer < 1001) { m_nPedStateTimer = 0; } - } else { + } else if (!GetPedAttractorManager()->IsInQueue(this, m_attractor)) { if (m_panicCounter == 50 && IsPedInControl()) { SetWaitState(WAITSTATE_STUCK, nil); // Leftover @@ -9264,11 +10947,7 @@ CPed::ProcessControl(void) } */ -#ifndef VC_PED_PORTS - } else { -#else } else if (collidingEnt) { -#endif switch (collidingEnt->GetType()) { case ENTITY_TYPE_BUILDING: @@ -9303,6 +10982,13 @@ CPed::ProcessControl(void) float oldDestRot = CGeneral::LimitRadianAngle(m_fRotationDest); + if (m_nPedState == PED_FOLLOW_PATH) { + if (DotProduct(m_vecDamageNormal, GetForward()) < -0.866f && CanPedJumpThis(collidingEnt, &m_vecDamageNormal)) { + SetJump(); + } + break; + } + if (m_pedInObjective && (m_objective == OBJECTIVE_GOTO_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT)) { @@ -9311,6 +10997,9 @@ CPed::ProcessControl(void) if (CanPedJumpThis(collidingEnt)) { SetJump(); } else if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT) { + if (m_nPedType == PEDTYPE_COP && m_nWaitState != WAITSTATE_LOOK_ABOUT) + ((CCopPed*)this)->field_624++; + SetWaitState(WAITSTATE_LOOK_ABOUT, nil); } else { SetWaitState(WAITSTATE_PLAYANIM_TAXI, nil); @@ -9320,6 +11009,9 @@ CPed::ProcessControl(void) Say(SOUND_PED_TAXI_CALL); } } else { + if (m_pLookTarget) + m_pLookTarget->CleanUpOldReference(&m_pLookTarget); + m_pLookTarget = m_pedInObjective; m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget); TurnBody(); @@ -9349,10 +11041,10 @@ CPed::ProcessControl(void) m_collidingEntityWhileFleeing = collidingEnt; m_collidingEntityWhileFleeing->RegisterReference((CEntity **) &m_collidingEntityWhileFleeing); - uint8 currentDir = Floor((PI + m_fRotationCur) / DEGTORAD(45.0f)); - uint8 nextDir; - ThePaths.FindNextNodeWandering(PATH_PED, GetPosition(), &m_pLastPathNode, &m_pNextPathNode, currentDir, &nextDir); - + if (m_nWaitState != WAITSTATE_HITWALL) + SetWaitState(WAITSTATE_TURN180, nil); + m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 5000; + Flee(); } else { if (neededTurn < DEGTORAD(60.0f)) { CVector posToHead = m_vecDamageNormal * 4.0f; @@ -9366,9 +11058,17 @@ CPed::ProcessControl(void) if (m_nPedState != PED_SEEK_POS && m_nPedState != PED_SEEK_CAR) { if (m_nPedState == PED_WANDER_PATH) { m_pNextPathNode = &ThePaths.m_pathNodes[closestNodeId]; + CVector bestCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); + angleToFace = CGeneral::GetRadianAngleBetweenPoints( + bestCoords.x, bestCoords.y, + GetPosition().x, GetPosition().y); + + } else if (m_nPedState == PED_FOLLOW_PATH) { + CVector bestCoords = m_pathNodesToGo[m_nCurPathNodeId]->GetPosition(); angleToFace = CGeneral::GetRadianAngleBetweenPoints( - m_pNextPathNode->GetX(), m_pNextPathNode->GetY(), + bestCoords.x, bestCoords.y, GetPosition().x, GetPosition().y); + } else { if (ThePaths.m_pathNodes[closestNodeId].GetX() == 0.0f || ThePaths.m_pathNodes[closestNodeId].GetY() == 0.0f) { @@ -9378,6 +11078,7 @@ CPed::ProcessControl(void) } else { posToHead.x = ThePaths.m_pathNodes[closestNodeId].GetX(); posToHead.y = ThePaths.m_pathNodes[closestNodeId].GetY(); + posToHead.z = ThePaths.m_pathNodes[closestNodeId].GetZ(); } angleToFace = CGeneral::GetRadianAngleBetweenPoints( posToHead.x, posToHead.y, @@ -9474,7 +11175,7 @@ CPed::ProcessControl(void) if (collidingVeh == m_pMyVehicle) bCollidedWithMyVehicle = true; -#ifdef VC_PED_PORTS + float oldHealth = m_fHealth; bool playerSufferSound = false; @@ -9483,23 +11184,30 @@ CPed::ProcessControl(void) && (!IsPlayer() || m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA - || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER)) { + || m_objective == OBJECTIVE_SPRINT_TO_AREA + || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER + || IsUseAttractorObjective(m_objective))) { if (collidingVeh != m_pCurrentPhysSurface || IsPlayer()) { if (!bVehEnterDoorIsBlocked) { if (collidingVeh->GetStatus() != STATUS_PLAYER || CharCreatedBy == MISSION_CHAR) { - // VC calls SetDirectionToWalkAroundVehicle instead if ped is in PED_SEEK_CAR. - SetDirectionToWalkAroundObject(collidingVeh); - CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer = m_nPedStateTimer; + if (m_nPedState == PED_SEEK_CAR) { + SetDirectionToWalkAroundObject(collidingVeh); + CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer = m_nPedStateTimer; + } else { + SetDirectionToWalkAroundVehicle(collidingVeh); + } } else { if (CTimer::GetTimeInMilliseconds() >= CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer || m_nPedStateTimer >= CTimer::GetTimeInMilliseconds()) { - // VC calls SetDirectionToWalkAroundVehicle instead if ped is in PED_SEEK_CAR. - SetDirectionToWalkAroundObject(collidingVeh); - CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer = m_nPedStateTimer; - + if (m_nPedState == PED_SEEK_CAR) { + SetDirectionToWalkAroundObject(collidingVeh); + CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer = m_nPedStateTimer; + } else { + SetDirectionToWalkAroundVehicle(collidingVeh); + } } else if (m_fleeFrom != collidingVeh) { SetFlee(collidingVeh, 4000); bUsePedNodeSeek = false; @@ -9523,10 +11231,11 @@ CPed::ProcessControl(void) SetLookTimer(1300); eWeaponType weaponType = GetWeapon()->m_eWeaponType; + uint32 weaponSlot = CWeaponInfo::GetWeaponInfo(weaponType)->m_nWeaponSlot; if (weaponType == WEAPONTYPE_UNARMED - || weaponType == WEAPONTYPE_BASEBALLBAT - || weaponType == WEAPONTYPE_COLT45 - || weaponType == WEAPONTYPE_UZI) { + || weaponSlot == 3 + || weaponSlot == 5 + || weaponSlot == 1) { bShakeFist = true; } } else { @@ -9632,142 +11341,12 @@ CPed::ProcessControl(void) KillPedWithCar(collidingVeh, m_fDamageImpulse); } - /* VC specific if (m_pCollidingEntity != collidingEnt) bPushedAlongByCar = true; - */ } if (m_fHealth < oldHealth && playerSufferSound) Say(SOUND_PED_HIT); -#else - if (collidingVehSpeedSqr <= 1.0f / 400.0f) { - if (!IsPedInControl() - || IsPlayer() - && m_objective != OBJECTIVE_GOTO_AREA_ON_FOOT - && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER - && m_objective != OBJECTIVE_RUN_TO_AREA) { - - if (IsPlayer() && !bIsInTheAir) { - - if (IsPedInControl() - && ((CPlayerPed*)this)->m_fMoveSpeed == 0.0f - && !bIsLooking - && CTimer::GetTimeInMilliseconds() > m_lookTimer - && collidingVeh->pDriver) { - - ((CPlayerPed*)this)->AnnoyPlayerPed(false); - SetLookFlag(collidingVeh, true); - SetLookTimer(1300); - - eWeaponType weaponType = GetWeapon()->m_eWeaponType; - if (weaponType == WEAPONTYPE_UNARMED - || weaponType == WEAPONTYPE_BASEBALLBAT - || weaponType == WEAPONTYPE_COLT45 - || weaponType == WEAPONTYPE_UZI) { - bShakeFist = true; - } - } else { - SetLookFlag(collidingVeh, true); - SetLookTimer(500); - } - } - - } else if (!bVehEnterDoorIsBlocked) { - if (collidingVeh->GetStatus() != STATUS_PLAYER || CharCreatedBy == MISSION_CHAR) { - - SetDirectionToWalkAroundObject(collidingVeh); - - } else if (CTimer::GetTimeInMilliseconds() >= CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer - || m_nPedStateTimer >= CTimer::GetTimeInMilliseconds()) { - - CPed::SetDirectionToWalkAroundObject(collidingVeh); - CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer = m_nPedStateTimer; - - } else if (m_fleeFrom != collidingVeh) { - SetFlee(collidingVeh, 4000); - bUsePedNodeSeek = false; - SetMoveState(PEDMOVE_WALK); - } - } - } else { - DMAudio.PlayOneShot(collidingVeh->m_audioEntityId, SOUND_CAR_PED_COLLISION, m_fDamageImpulse); - if (IsPlayer()) { - CColModel *collidingCol = CModelInfo::GetModelInfo(collidingVeh->GetModelIndex())->GetColModel(); - CVector colMinVec = collidingCol->boundingBox.min; - CVector colMaxVec = collidingCol->boundingBox.max; - - CVector vehColCenterDist = collidingVeh->GetMatrix() * ((colMinVec + colMaxVec) * 0.5f) - GetPosition(); - - // TLVC = To look vehicle center - - float angleToVehFront = collidingVeh->GetForward().Heading(); - float angleDiffFromLookingFrontTLVC = angleToVehFront - vehColCenterDist.Heading(); - angleDiffFromLookingFrontTLVC = CGeneral::LimitRadianAngle(angleDiffFromLookingFrontTLVC); - - // I don't know why do we use that - float vehTopRightHeading = Atan2(colMaxVec.x - colMinVec.x, colMaxVec.y - colMinVec.y); - - CVector vehDist = GetPosition() - collidingVeh->GetPosition(); - vehDist.Normalise(); - - float vehRightVecAndSpeedDotProd; - - if (Abs(angleDiffFromLookingFrontTLVC) >= vehTopRightHeading && Abs(angleDiffFromLookingFrontTLVC) < PI - vehTopRightHeading) { - if (angleDiffFromLookingFrontTLVC <= 0.0f) { - vehRightVecAndSpeedDotProd = DotProduct(collidingVeh->GetRight(), collidingVeh->m_vecMoveSpeed); - - // vehRightVecAndSpeedDotProd < 0.1f = Vehicle being overturned or spinning to it's right? - if (collidingVehSpeedSqr > 1.0f / 100.0f && vehRightVecAndSpeedDotProd < 0.1f) { - - // Car's right faces towards us and isn't coming directly to us - if (DotProduct(collidingVeh->GetRight(), GetForward()) < 0.0f - && DotProduct(vehDist, collidingVeh->m_vecMoveSpeed) > 0.0f) { - SetEvasiveStep(collidingVeh, 1); - } - } - } else { - vehRightVecAndSpeedDotProd = DotProduct(-1.0f * collidingVeh->GetRight(), collidingVeh->m_vecMoveSpeed); - if (collidingVehSpeedSqr > 1.0f / 100.0f && vehRightVecAndSpeedDotProd < 0.1f) { - if (DotProduct(collidingVeh->GetRight(), GetForward()) > 0.0f - && DotProduct(vehDist, collidingVeh->m_vecMoveSpeed) > 0.0f) { - SetEvasiveStep(collidingVeh, 1); - } - } - } - } else { - vehRightVecAndSpeedDotProd = DotProduct(vehDist, collidingVeh->m_vecMoveSpeed); - } - - if (vehRightVecAndSpeedDotProd <= 0.1f) { - if (m_nPedState != PED_FIGHT) { - SetLookFlag(collidingVeh, true); - SetLookTimer(700); - } - } else { - bIsStanding = false; - CVector2D collidingEntMoveDir = -collidingVeh->m_vecMoveSpeed; - int dir = GetLocalDirection(collidingEntMoveDir); - SetFall(1000, (AnimationId)(dir + ANIM_KO_SKID_FRONT), false); - CPed *driver = collidingVeh->pDriver; - - float damage; - if (driver && driver->IsPlayer()) { - damage = vehRightVecAndSpeedDotProd * 1000.0f; - } else if (collidingVeh->GetModelIndex() == MI_TRAIN) { - damage = 50.0f; - } else { - damage = 20.0f; - } - - InflictDamage(collidingVeh, WEAPONTYPE_RAMMEDBYCAR, damage, PEDPIECE_TORSO, dir); - Say(SOUND_PED_DAMAGE); - } - } else { - KillPedWithCar(collidingVeh, m_fDamageImpulse); - } - } -#endif break; } case ENTITY_TYPE_PED: @@ -9783,11 +11362,12 @@ CPed::ProcessControl(void) player->AnnoyPlayerPed(false); player->SetLookFlag(this, true); player->SetLookTimer(1300); - eWeaponType weapon = player->GetWeapon()->m_eWeaponType; - if (weapon == WEAPONTYPE_UNARMED - || weapon == WEAPONTYPE_BASEBALLBAT - || weapon == WEAPONTYPE_COLT45 - || weapon == WEAPONTYPE_UZI) { + eWeaponType weaponType = player->GetWeapon()->m_eWeaponType; + uint32 weaponSlot = CWeaponInfo::GetWeaponInfo(weaponType)->m_nWeaponSlot; + if (weaponType == WEAPONTYPE_UNARMED + || weaponSlot == 3 + || weaponSlot == 5 + || weaponSlot == 1) { player->bShakeFist = true; } } @@ -9802,12 +11382,7 @@ CPed::ProcessControl(void) } } CVector forceDir; - if (!bIsInTheAir && m_nPedState != PED_JUMP -#ifdef VC_PED_PORTS - && m_fDamageImpulse > 0.0f -#endif - ) { - + if (!bIsInTheAir && m_nPedState != PED_JUMP && m_fDamageImpulse > 0.0f) { forceDir = m_vecDamageNormal; forceDir.z = 0.0f; if (!bIsStanding) { @@ -9882,7 +11457,7 @@ CPed::ProcessControl(void) flyDir = 1; } - if (flyDir != 0 && !bSomeVCflag1) { + if (flyDir != 0 && !bHeadStuckInCollision) { SetPosition((flyDir == 2 ? obstacleForFlyingOtherDir.point : obstacleForFlying.point)); GetMatrix().GetPosition().z += FEET_OFFSET; GetMatrix().UpdateRW(); @@ -9989,11 +11564,11 @@ CPed::ProcessControl(void) if (CWorld::ProcessVerticalLine(offsetToCheck, GetPosition().z - FEET_OFFSET, foundCol, foundEnt, true, true, false, true, false, false, nil)) { #ifdef VC_PED_PORTS - if (!bSomeVCflag1 || FEET_OFFSET + foundCol.point.z < GetPosition().z) { + if (!bHeadStuckInCollision || FEET_OFFSET + foundCol.point.z < GetPosition().z) { GetMatrix().GetPosition().z = FEET_OFFSET + foundCol.point.z; GetMatrix().UpdateRW(); - if (bSomeVCflag1) - bSomeVCflag1 = false; + if (bHeadStuckInCollision) + bHeadStuckInCollision = false; } #else GetMatrix().GetPosition().z = FEET_OFFSET + foundCol.point.z; @@ -10019,15 +11594,15 @@ CPed::ProcessControl(void) } else if (m_nPedState == PED_DRIVING) { bWanderPathAfterExitingCar = true; SetObjective(OBJECTIVE_LEAVE_CAR, m_pMyVehicle); + bStartWanderPathOnFoot = false; } } - if (!bIsStanding && m_vecMoveSpeed.z > 0.25f) { + if (!bIsStanding && m_vecMoveSpeed.z > 0.25) { float airResistance = Pow(0.95f, CTimer::GetTimeStep()); m_vecMoveSpeed *= airResistance; } -#ifdef VC_PED_PORTS if (IsPlayer() || !bIsStanding || m_vecMoveSpeed.x != 0.0f || m_vecMoveSpeed.y != 0.0f || m_vecMoveSpeed.z != 0.0f || (m_nMoveState != PEDMOVE_NONE && m_nMoveState != PEDMOVE_STILL) || m_vecAnimMoveDelta.x != 0.0f || m_vecAnimMoveDelta.y != 0.0f @@ -10049,30 +11624,29 @@ CPed::ProcessControl(void) m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f); } -#else - CPhysical::ProcessControl(); -#endif + if (m_nPedState != PED_DIE || bIsPedDieAnimPlaying) { + RequestDelayedWeapon(); + PlayFootSteps(); if (m_nPedState != PED_DEAD) { CalculateNewVelocity(); CalculateNewOrientation(); } UpdatePosition(); - PlayFootSteps(); - if (IsPedInControl() && !bIsStanding && !m_pDamageEntity && CheckIfInTheAir()) { - SetInTheAir(); -#ifdef VC_PED_PORTS - bSomeVCflag1 = false; -#endif + if (IsPedInControl() && !bIsStanding && !m_pDamageEntity) { + if (m_attachedTo) { + bIsInTheAir = false; + } else if (CheckIfInTheAir()) { + SetInTheAir(); + bHeadStuckInCollision = false; + } } -#ifdef VC_PED_PORTS - if (bSomeVCflag1) { + if (bHeadStuckInCollision) { CVector posToCheck = GetPosition(); posToCheck.z += 0.9f; if (!CWorld::TestSphereAgainstWorld(posToCheck, 0.2f, this, true, true, false, true, false, false)) - bSomeVCflag1 = false; + bHeadStuckInCollision = false; } -#endif ProcessObjective(); if (!bIsAimingGun) { if (bIsRestoringGun) @@ -10101,14 +11675,6 @@ CPed::ProcessControl(void) if (m_nWaitState != WAITSTATE_FALSE) Wait(); - if (m_nPedState != PED_IDLE) { - CAnimBlendAssociation *idleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_ARMED); - if(idleAssoc) { - idleAssoc->blendDelta = -8.0f; - idleAssoc->flags |= ASSOC_DELETEFADEDOUT; - } - } - switch (m_nPedState) { case PED_IDLE: Idle(); @@ -10118,8 +11684,11 @@ CPed::ProcessControl(void) Look(); break; case PED_WANDER_RANGE: + // III has these in here(and they were unused): + /* WanderRange(); CheckAroundForPossibleCollisions(); + */ break; case PED_WANDER_PATH: WanderPath(); @@ -10137,10 +11706,14 @@ CPed::ProcessControl(void) case PED_FOLLOW_ROUTE: case PED_CPR: case PED_SOLICIT: - case PED_BUY_ICECREAM: case PED_STEP_AWAY: + case PED_SUN_BATHE: + case PED_FLASH: + case PED_JOG: case PED_UNKNOWN: case PED_STATES_NO_AI: + case PED_ABSEIL: + case PED_SIT: case PED_JUMP: case PED_STAGGER: case PED_DIVE_AWAY: @@ -10151,8 +11724,8 @@ CPed::ProcessControl(void) case PED_OPEN_DOOR: case PED_DEAD: case PED_DRAG_FROM_CAR: - case PED_EXIT_CAR: case PED_STEAL_CAR: + case PED_EXIT_CAR: break; case PED_ENTER_CAR: case PED_CARJACK: @@ -10206,6 +11779,7 @@ CPed::ProcessControl(void) break; case PED_FLEE_ENTITY: if (!m_fleeFrom) { + bMakeFleeScream = false; SetIdle(); break; } @@ -10243,6 +11817,9 @@ CPed::ProcessControl(void) case PED_SEEK_IN_BOAT: SeekBoatPosition(); break; + case PED_BUY_ICECREAM: + BuyIceCream(); + break; case PED_INVESTIGATE: InvestigateEvent(); break; @@ -10251,30 +11828,41 @@ CPed::ProcessControl(void) break; if (CTimer::GetTimeInMilliseconds() <= m_fleeTimer) { - if (m_fleeFrom) { - ms_vec2DFleePosition = m_fleeFrom->GetPosition(); + if (m_pFire) { + if (m_fleeFrom) { + ms_vec2DFleePosition = m_fleeFrom->GetPosition(); + } else { + ms_vec2DFleePosition.x = m_fleeFromPosX; + ms_vec2DFleePosition.y = m_fleeFromPosY; + } + Flee(); } else { - ms_vec2DFleePosition.x = m_fleeFromPosX; - ms_vec2DFleePosition.y = m_fleeFromPosY; + m_nLastPedState = PED_NONE; + SetWanderPath(0); + SetWaitState(WAITSTATE_FINISH_FLEE, 0); } - Flee(); } else { if (m_pFire) m_pFire->Extinguish(); } break; + case PED_ANSWER_MOBILE: + AnswerMobile(); + break; case PED_FALL: Fall(); break; case PED_GETUP: SetGetUp(); break; +#ifdef GTA_TRAIN case PED_ENTER_TRAIN: EnterTrain(); break; case PED_EXIT_TRAIN: ExitTrain(); break; +#endif case PED_DRIVING: { if (!m_pMyVehicle) { @@ -10283,129 +11871,62 @@ CPed::ProcessControl(void) return; } - if (m_pMyVehicle->pDriver != this || m_pMyVehicle->IsBoat()) { - LookForSexyPeds(); - LookForSexyCars(); - break; - } - - if (m_pMyVehicle->m_vehType == VEHICLE_TYPE_BIKE || !m_pMyVehicle->pDriver->IsPlayer()) { - break; - } - - CPad* pad = CPad::GetPad(0); - #ifdef CAR_AIRBREAK - if (!pad->ArePlayerControlsDisabled()) { - if (pad->GetHorn()) { - float c = Cos(m_fRotationCur); - float s = Sin(m_fRotationCur); - m_pMyVehicle->GetRight() = CVector(1.0f, 0.0f, 0.0f); - m_pMyVehicle->GetForward() = CVector(0.0f, 1.0f, 0.0f); - m_pMyVehicle->GetUp() = CVector(0.0f, 0.0f, 1.0f); - if (pad->GetAccelerate()) { - m_pMyVehicle->ApplyMoveForce(GetForward() * 30.0f); - } else if (pad->GetBrake()) { - m_pMyVehicle->ApplyMoveForce(-GetForward() * 30.0f); - } else { - int16 lr = pad->GetSteeringLeftRight(); - if (lr < 0) { - //m_pMyVehicle->ApplyTurnForce(20.0f * -GetRight(), GetForward()); - m_pMyVehicle->ApplyMoveForce(-GetRight() * 30.0f); - } else if (lr > 0) { - m_pMyVehicle->ApplyMoveForce(GetRight() * 30.0f); - } else { - m_pMyVehicle->ApplyMoveForce(0.0f, 0.0f, 50.0f); + if (IsPlayer()) { + CPad* pad = CPad::GetPad(0); + if (!pad->ArePlayerControlsDisabled()) { + if (pad->GetHorn()) { + float c = Cos(m_fRotationCur); + float s = Sin(m_fRotationCur); + m_pMyVehicle->GetRight() = CVector(1.0f, 0.0f, 0.0f); + m_pMyVehicle->GetForward() = CVector(0.0f, 1.0f, 0.0f); + m_pMyVehicle->GetUp() = CVector(0.0f, 0.0f, 1.0f); + if (pad->GetAccelerate()) { + m_pMyVehicle->ApplyMoveForce(GetForward() * 30.0f); + } + else if (pad->GetBrake()) { + m_pMyVehicle->ApplyMoveForce(-GetForward() * 30.0f); + } + else { + int16 lr = pad->GetSteeringLeftRight(); + if (lr < 0) { + //m_pMyVehicle->ApplyTurnForce(20.0f * -GetRight(), GetForward()); + m_pMyVehicle->ApplyMoveForce(-GetRight() * 30.0f); + } + else if (lr > 0) { + m_pMyVehicle->ApplyMoveForce(GetRight() * 30.0f); + } + else { + m_pMyVehicle->ApplyMoveForce(0.0f, 0.0f, 50.0f); + } } } } } #endif - float steerAngle = m_pMyVehicle->m_fSteerAngle; - CAnimBlendAssociation *lDriveAssoc; - CAnimBlendAssociation *rDriveAssoc; - CAnimBlendAssociation *lbAssoc; - CAnimBlendAssociation *sitAssoc; - if (m_pMyVehicle->bLowVehicle) { - sitAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LSIT); - - if (!sitAssoc || sitAssoc->blendAmount < 1.0f) { - break; - } - lDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_LOW_L); - lbAssoc = nil; - rDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_LOW_R); + if (m_pMyVehicle->pDriver == this) { + DriveVehicle(); + if (!m_pMyVehicle) + return; } else { - sitAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SIT); - - if (!sitAssoc || sitAssoc->blendAmount < 1.0f) { - break; - } - - lDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_L); - rDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_R); - lbAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LB); - - if (lbAssoc && - TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_1STPERSON - && TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking == LOOKING_LEFT) { - lbAssoc->blendDelta = -1000.0f; - } + LookForSexyPeds(); + LookForSexyCars(); } - - CAnimBlendAssociation *driveByAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_L); - - if (!driveByAssoc) - driveByAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_R); - - if (m_pMyVehicle->bLowVehicle || m_pMyVehicle->m_fGasPedal >= 0.0f || driveByAssoc) { - if (steerAngle == 0.0f || driveByAssoc) { - if (lDriveAssoc) - lDriveAssoc->blendAmount = 0.0f; - if (rDriveAssoc) - rDriveAssoc->blendAmount = 0.0f; - - } else if (steerAngle <= 0.0f) { - if (lDriveAssoc) - lDriveAssoc->blendAmount = 0.0f; - - if (rDriveAssoc) - rDriveAssoc->blendAmount = clamp(steerAngle * -100.0f / 61.0f, 0.0f, 1.0f); - else if (m_pMyVehicle->bLowVehicle) - CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_LOW_R); - else - CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_R); - - } else { - if (rDriveAssoc) - rDriveAssoc->blendAmount = 0.0f; - - if (lDriveAssoc) - lDriveAssoc->blendAmount = clamp(steerAngle * 100.0f / 61.0f, 0.0f, 1.0f); - else if (m_pMyVehicle->bLowVehicle) - CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_LOW_L); - else - CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_L); - } - - if (lbAssoc) - lbAssoc->blendDelta = -4.0f; - } else { - - if ((TheCamera.Cams[TheCamera.ActiveCam].Mode != CCam::MODE_1STPERSON - || TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking != LOOKING_LEFT) - && (!lbAssoc || lbAssoc->blendAmount < 1.0f)) { - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_LB, 4.0f); - } + if (!IsPlayer() && m_pMyVehicle->IsBoat() + && FindPlayerPed()->m_pCurrentPhysSurface == m_pMyVehicle + && CharCreatedBy != MISSION_CHAR || !bIsPlayerFriend) { + SetObjective(OBJECTIVE_KILL_CHAR_ON_BOAT, FindPlayerPed()); + Say(SOUND_PED_CAR_JACKED); } + break; } case PED_DIE: Die(); break; case PED_HANDS_UP: - if (m_pedStats->m_temper <= 50) { + if (m_pedStats->m_flags & STAT_GUN_PANIC) { if (!RpAnimBlendClumpGetAssociation(GetClump(), ANIM_HANDSCOWER)) { CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_HANDSCOWER); Say(SOUND_PED_HANDS_COWER); @@ -10415,11 +11936,15 @@ CPed::ProcessControl(void) Say(SOUND_PED_HANDS_UP); } break; - default: break; + default: + break; } SetMoveAnim(); - if (bPedIsBleeding) { + if (bPedIsBleeding || m_bleedCounter != 0) { if (CGame::nastyGame) { + if (m_bleedCounter != 0) + m_bleedCounter--; + if (!(CTimer::GetFrameCounter() & 3)) { CVector cameraDist = GetPosition() - TheCamera.GetPosition(); if (cameraDist.MagnitudeSqr() < sq(50.0f)) { @@ -10440,9 +11965,24 @@ CPed::ProcessControl(void) ServiceTalking(); if (bInVehicle && !m_pMyVehicle) bInVehicle = false; -#ifndef VC_PED_PORTS - m_pCurrentPhysSurface = nil; -#endif + + if (bHeldHostageInCar) { + if (m_pMyVehicle && m_pMyVehicle->pDriver && m_pMyVehicle->pDriver->IsPlayer()) { + Say(SOUND_PED_FLEE_SPRINT); + } + } + + if (m_delayedSoundID >= 0 && CTimer::GetTimeInMilliseconds() > m_delayedSoundTimer) { + Say(m_delayedSoundID); + m_delayedSoundID = -1; + m_delayedSoundTimer = 0; + } + + if (bFannyMagnetCheat && m_nPedType == PEDTYPE_CIVFEMALE + && m_pedStats->m_sexiness > 40 && !m_leader) { + SetLeader(FindPlayerPed()); + } + } else { if (bIsStanding && (!m_pCurrentPhysSurface || IsPlayer()) || bIsInWater || !bUsesCollision) { @@ -10450,9 +11990,11 @@ CPed::ProcessControl(void) } m_pCurrentPhysSurface = nil; } - } + } else + ServiceTalking(); } +// --MIAMI: Done void CPed::SetInTheAir(void) { @@ -10471,26 +12013,41 @@ CPed::SetInTheAir(void) } +// --MIAMI: Done void CPed::RestoreHeadPosition(void) { + if(!CanUseTorsoWhenLooking()) + m_pedIK.m_flags |= CPedIK::LOOKAROUND_HEAD_ONLY; + if (m_pedIK.RestoreLookAt()) { bIsRestoringLook = false; + if(CanUseTorsoWhenLooking()) + m_pedIK.m_flags &= ~CPedIK::LOOKAROUND_HEAD_ONLY; } } +// --MIAMI: Done void CPed::PointGunAt(void) { CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - CAnimBlendAssociation *weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), weaponInfo->m_AnimToPlay); - if (!weaponAssoc || weaponAssoc->blendDelta < 0.0f) - weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), weaponInfo->m_Anim2ToPlay); + float animLoopStart = weaponInfo->m_fAnimLoopStart; + CAnimBlendAssociation *weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_FIRE); + if (!weaponAssoc || weaponAssoc->blendDelta < 0.0f) { + if (!!weaponInfo->m_bCrouchFire) { + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchFireAnim(weaponInfo)); + animLoopStart = weaponInfo->m_fAnim2LoopStart; + } + } - if (weaponAssoc && weaponAssoc->currentTime > weaponInfo->m_fAnimLoopStart) { - weaponAssoc->SetCurrentTime(weaponInfo->m_fAnimLoopStart); + if (weaponAssoc && weaponAssoc->currentTime > animLoopStart * 0.4f) { + weaponAssoc->SetCurrentTime(animLoopStart); weaponAssoc->flags &= ~ASSOC_RUNNING; + if (bIsDucking) + m_pedIK.m_flags &= ~CPedIK::AIMS_WITH_ARM; + if (weaponInfo->m_bCanAimWithArm) m_pedIK.m_flags |= CPedIK::AIMS_WITH_ARM; else @@ -10498,6 +12055,7 @@ CPed::PointGunAt(void) } } +// --MIAMI: Done void CPed::PedAnimDoorCloseCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -10526,22 +12084,16 @@ CPed::PedAnimDoorCloseCB(CAnimBlendAssociation *animAssoc, void *arg) if (veh->Damage.GetDoorStatus(door) == DOOR_STATUS_SMASHED) veh->Damage.SetDoorStatus(door, DOOR_STATUS_OK); - if (door == DOOR_FRONT_LEFT || ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER || veh->bIsBus) { + if (door == DOOR_FRONT_LEFT || ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER || veh->bIsBus || veh->m_nNumMaxPassengers == 0) { PedSetInCarCB(nil, ped); } else if (ped->m_vehEnterType == CAR_DOOR_RF && (veh->m_nGettingInFlags & CAR_DOOR_FLAG_LF || (veh->pDriver != nil && (veh->pDriver->m_objective != OBJECTIVE_LEAVE_CAR -#ifdef VC_PED_PORTS && veh->pDriver->m_objective != OBJECTIVE_LEAVE_CAR_AND_DIE -#endif || !veh->IsRoomForPedToLeaveCar(CAR_DOOR_LF, nil))))) { - if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER -#if defined VC_PED_PORTS || defined FIX_BUGS - || ped->m_nPedState == PED_CARJACK -#endif - ) + if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || ped->m_nPedState == PED_CARJACK) veh->bIsBeingCarJacked = false; ped->m_objective = OBJECTIVE_ENTER_CAR_AS_PASSENGER; @@ -10565,14 +12117,12 @@ CPed::PedAnimDoorCloseCB(CAnimBlendAssociation *animAssoc, void *arg) ped->m_pVehicleAnim->SetFinishCallback(PedSetInCarCB, ped); } - } else { -#ifdef VC_PED_PORTS - if (ped->m_nPedState != PED_DRIVING) -#endif - ped->QuitEnteringCar(); + } else if (ped->m_nPedState != PED_DRIVING) { + ped->QuitEnteringCar(); } } +// --MIAMI: Done void CPed::PedAnimDoorCloseRollingCB(CAnimBlendAssociation* animAssoc, void* arg) { @@ -10595,6 +12145,7 @@ CPed::PedAnimDoorCloseRollingCB(CAnimBlendAssociation* animAssoc, void* arg) veh->Damage.SetDoorStatus(DOOR_FRONT_LEFT, DOOR_STATUS_OK); } +// --MIAMI: Done void CPed::PedAnimDoorOpenCB(CAnimBlendAssociation* animAssoc, void* arg) { @@ -10609,9 +12160,7 @@ CPed::PedAnimDoorOpenCB(CAnimBlendAssociation* animAssoc, void* arg) return; if (!ped->EnteringCar()) { -#ifdef VC_PED_PORTS - if (ped->m_nPedState != PED_DRIVING) -#endif + if(ped->m_nPedState != PED_DRIVING) ped->QuitEnteringCar(); return; @@ -10620,10 +12169,26 @@ CPed::PedAnimDoorOpenCB(CAnimBlendAssociation* animAssoc, void* arg) eDoors door; CPed *pedInSeat = nil; switch (ped->m_vehEnterType) { - case CAR_DOOR_RF: door = DOOR_FRONT_RIGHT; pedInSeat = veh->pPassengers[0]; break; - case CAR_DOOR_RR: door = DOOR_REAR_RIGHT; pedInSeat = veh->pPassengers[2]; break; - case CAR_DOOR_LF: door = DOOR_FRONT_LEFT; pedInSeat = veh->pDriver; break; - case CAR_DOOR_LR: door = DOOR_REAR_LEFT; pedInSeat = veh->pPassengers[1]; break; + case CAR_DOOR_RF: + door = DOOR_FRONT_RIGHT; + pedInSeat = veh->pPassengers[0]; + if (!veh->pPassengers[0] && ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) + pedInSeat = veh->pDriver; + break; + case CAR_DOOR_RR: + door = DOOR_REAR_RIGHT; + pedInSeat = veh->pPassengers[2]; + break; + case CAR_DOOR_LF: + door = DOOR_FRONT_LEFT; + pedInSeat = veh->pDriver; + if (veh->bIsBus && ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER) + pedInSeat = nil; + break; + case CAR_DOOR_LR: + door = DOOR_REAR_LEFT; + pedInSeat = veh->pPassengers[1]; + break; default: assert(0); } @@ -10658,7 +12223,8 @@ CPed::PedAnimDoorOpenCB(CAnimBlendAssociation* animAssoc, void* arg) ((CAutomobile*)veh)->Damage.SetDoorStatus(door, DOOR_STATUS_SWINGING); } - if (veh->m_vecMoveSpeed.Magnitude() > 0.2f) { + if (veh->m_vecMoveSpeed.Magnitude() > 0.2f || + veh->IsCar() && veh->GetVehicleAppearance() == VEHICLE_APPEARANCE_HELI && ((CAutomobile*)veh)->m_nWheelsOnGround == 0) { ped->QuitEnteringCar(); if (ped->m_vehEnterType != CAR_DOOR_LF && ped->m_vehEnterType != CAR_DOOR_LR) ped->SetFall(1000, ANIM_KO_SPIN_R, false); @@ -10673,28 +12239,36 @@ CPed::PedAnimDoorOpenCB(CAnimBlendAssociation* animAssoc, void* arg) isVan = false; if (ped->m_nPedState != PED_CARJACK || isBus) { - AnimationId animToPlay; - if (ped->m_vehEnterType != CAR_DOOR_LF && ped->m_vehEnterType != CAR_DOOR_LR) { - if (isVan) { - animToPlay = ANIM_VAN_GETIN; + if (ped->m_vehEnterType == CAR_DOOR_LF || ped->m_vehEnterType == CAR_DOOR_LR) { + if (veh->IsBike()) { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ((CBike*)veh)->m_bikeAnimType, ANIM_BIKE_JUMPON_R); + } else if (isVan) { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_GETIN_L); } else if (isBus) { - animToPlay = ANIM_COACH_IN_R; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_IN_L); } else if (isLow) { - animToPlay = ANIM_CAR_GETIN_LOW_RHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_LHS); } else { - animToPlay = ANIM_CAR_GETIN_RHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LHS); } - } else if (isVan) { - animToPlay = ANIM_VAN_GETIN_L; - } else if (isBus) { - animToPlay = ANIM_COACH_IN_L; - } else if (isLow) { - animToPlay = ANIM_CAR_GETIN_LOW_LHS; } else { - animToPlay = ANIM_CAR_GETIN_LHS; + if (veh->IsBike()) { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ((CBike*)veh)->m_bikeAnimType, ANIM_BIKE_JUMPON_L); + } else if (isVan) { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_GETIN); + } else if (isBus) { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_IN_R); + } else if (isLow) { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_RHS); + } else { + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_RHS); + } + + if (ped->m_vehEnterType == CAR_DOOR_RF && pedInSeat && veh->IsCar()) + pedInSeat->SetObjective(OBJECTIVE_LEAVE_CAR, veh); } - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, animToPlay); + ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); } else { CPed *pedToDragOut = nil; @@ -10713,6 +12287,7 @@ CPed::PedAnimDoorOpenCB(CAnimBlendAssociation* animAssoc, void* arg) } if (ped->m_vehEnterType != CAR_DOOR_LF && ped->m_vehEnterType != CAR_DOOR_LR) { + if (pedToDragOut && !pedToDragOut->bDontDragMeOutCar) { if (pedToDragOut->m_nPedState != PED_DRIVING) { ped->QuitEnteringCar(); @@ -10729,121 +12304,95 @@ CPed::PedAnimDoorOpenCB(CAnimBlendAssociation* animAssoc, void* arg) ped->QuitEnteringCar(); if (ped->m_pedInObjective && ped->m_pedInObjective->m_nPedState == PED_DRIVING) { veh->SetStatus(STATUS_PLAYER_DISABLED); - ((CCopPed*)ped)->SetArrestPlayer(ped->m_pedInObjective); + + if (ped->m_pedInObjective->IsPlayer()) { + ((CCopPed*)ped)->SetArrestPlayer(ped->m_pedInObjective); + } else { + ped->ClearObjective(); + ped->SetWanderPath(CGeneral::GetRandomNumberInRange(0.f, 8.f)); + } + } else if (!veh->IsDoorMissing(DOOR_FRONT_RIGHT)) { ((CAutomobile*)veh)->Damage.SetDoorStatus(DOOR_FRONT_RIGHT, DOOR_STATUS_SWINGING); } } else { - // BUG: Probably we will sit on top of the passenger if his m_ped_flagF4 is true. if (isLow) - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_LHS); + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_RHS); else - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LHS); + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_RHS); ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); } - } else { - if (pedToDragOut) { - if (pedToDragOut->m_nPedState != PED_DRIVING || pedToDragOut->bDontDragMeOutCar) { + } else if (pedToDragOut) { - // BUG: Player freezes in that condition due to its objective isn't restored. It's an unfinished feature, used in VC. - ped->QuitEnteringCar(); - pedToDragOut = nil; - } else { - if (isLow) - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_PULLOUT_LOW_LHS); - else - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_PULLOUT_LHS); - - ped->m_pVehicleAnim->SetFinishCallback(PedAnimPullPedOutCB, ped); - } + if (pedToDragOut->m_nPedState != PED_DRIVING || pedToDragOut->bDontDragMeOutCar) { + ped->QuitEnteringCar(); + pedToDragOut = nil; } else { if (isLow) - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_LHS); + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_PULLOUT_LOW_LHS); else - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LHS); - - ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_PULLOUT_LHS); + + ped->m_pVehicleAnim->SetFinishCallback(PedAnimPullPedOutCB, ped); } + } else { + if (isLow) + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_LHS); + else + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LHS); + + ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); } if (pedToDragOut) { - pedToDragOut->SetBeingDraggedFromCar(veh, ped->m_vehEnterType, false); - if (pedToDragOut->IsGangMember()) - pedToDragOut->RegisterThreatWithGangPeds(ped); - } - } + CPlayerPed* player = nil; + CCopPed* cop = nil; + veh->MakeNonDraggedPedsLeaveVehicle(pedToDragOut, ped, player, cop); + if (player && cop) { + cop->QuitEnteringCar(); + cop->SetArrestPlayer(player); + } - if (veh->pDriver && ped) { - veh->pDriver->SetLookFlag(ped, true); - veh->pDriver->SetLookTimer(1000); + if (player != pedToDragOut) { + pedToDragOut->SetBeingDraggedFromCar(veh, ped->m_vehEnterType, true); + if (pedToDragOut->IsGangMember()) + pedToDragOut->RegisterThreatWithGangPeds(ped); + } + } } return; } +// --MIAMI: Done void CPed::SetJump(void) { - if (!bInVehicle && -#if defined VC_PED_PORTS || defined FIX_BUGS - m_nPedState != PED_JUMP && !RpAnimBlendClumpGetAssociation(GetClump(), ANIM_JUMP_LAUNCH) && -#endif + if (!bInVehicle && m_nPedState != PED_JUMP && !RpAnimBlendClumpGetAssociation(GetClump(), ANIM_JUMP_LAUNCH) && (m_nSurfaceTouched != SURFACE_STEEP_CLIFF || DotProduct(GetForward(), m_vecDamageNormal) >= 0.0f)) { + SetStoredState(); - m_nPedState = PED_JUMP; + SetPedState(PED_JUMP); CAnimBlendAssociation *jumpAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_JUMP_LAUNCH, 8.0f); jumpAssoc->SetFinishCallback(FinishLaunchCB, this); m_fRotationDest = m_fRotationCur; } } +// --MIAMI: Done void CPed::RemoveInCarAnims(void) { - if (!IsPlayer()) - return; - - CAnimBlendAssociation *animAssoc; + CAnimBlendAssociation* assoc; - if (m_pMyVehicle && m_pMyVehicle->bLowVehicle) { - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_LOW_L); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_LOW_R); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_L); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_R); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - } else { - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_L); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_R); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_L); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_R); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; + for (assoc = RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_DRIVING); assoc; + assoc = RpAnimBlendGetNextAssociation(assoc, ASSOC_DRIVING)) { + assoc->flags |= ASSOC_DELETEFADEDOUT; + assoc->blendDelta = -1000.0f; } - -#ifdef VC_PED_PORTS - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_BOAT); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; -#endif - - animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LB); - if (animAssoc) - animAssoc->blendDelta = -1000.0f; } +// --MIAMI: Done void CPed::PedAnimGetInCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -10857,17 +12406,16 @@ CPed::PedAnimGetInCB(CAnimBlendAssociation *animAssoc, void *arg) return; if (!ped->EnteringCar()) { -#ifdef VC_PED_PORTS if(ped->m_nPedState != PED_DRIVING) -#endif ped->QuitEnteringCar(); return; } + ped->RemoveWeaponWhenEnteringVehicle(); if (ped->IsPlayer() && ped->bGonnaKillTheCarJacker && ((CPlayerPed*)ped)->m_pArrestingCop) { PedSetInCarCB(nil, ped); ped->m_nLastPedState = ped->m_nPedState; - ped->m_nPedState = PED_ARRESTED; + ped->SetPedState(PED_ARRESTED); ped->bGonnaKillTheCarJacker = false; if (veh) { veh->m_nNumGettingIn = 0; @@ -10879,13 +12427,19 @@ CPed::PedAnimGetInCB(CAnimBlendAssociation *animAssoc, void *arg) } if (ped->IsPlayer() && ped->m_vehEnterType == CAR_DOOR_LF && (Pads[0].GetAccelerate() >= 255.0f || Pads[0].GetBrake() >= 255.0f) - && veh->IsCar()) { + && veh->IsCar() && !veh->pDriver) { + + if (!animAssoc || animAssoc->animId != ANIM_CAR_JUMPIN_LHS) if (((CAutomobile*)veh)->Damage.GetDoorStatus(DOOR_FRONT_LEFT) != DOOR_STATUS_MISSING) ((CAutomobile*)veh)->Damage.SetDoorStatus(DOOR_FRONT_LEFT, DOOR_STATUS_SWINGING); PedSetInCarCB(nil, ped); return; } + if (veh->IsBike()) { + ped->PedSetInCarCB(nil, ped); + return; + } bool isVan = !!veh->bIsVan; bool isBus = !!veh->bIsBus; bool isLow = !!veh->bLowVehicle; @@ -10908,10 +12462,15 @@ CPed::PedAnimGetInCB(CAnimBlendAssociation *animAssoc, void *arg) default: break; } - if (!veh->IsDoorMissing(enterDoor)) { + bool doorClosed = true; + if (veh->IsOpenTopCar() && enterDoor == DOOR_FRONT_LEFT && veh->IsDoorClosed(DOOR_FRONT_LEFT)) { + doorClosed = false; + + } else if (!veh->IsDoorMissing(enterDoor)) { if (veh->IsCar()) ((CAutomobile*)veh)->Damage.SetDoorStatus(enterDoor, DOOR_STATUS_SWINGING); } + CPed *driver = veh->pDriver; if (driver && (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || ped->m_nPedState == PED_CARJACK)) { if (veh->bIsBus) { @@ -10952,43 +12511,44 @@ CPed::PedAnimGetInCB(CAnimBlendAssociation *animAssoc, void *arg) && (ped->m_nPedType != PEDTYPE_COP || veh->pDriver->m_nPedType != PEDTYPE_COP)) { veh->pDriver->SetObjective(OBJECTIVE_LEAVE_CAR, veh); veh->pDriver->Say(SOUND_PED_CAR_JACKED); -#ifdef VC_PED_PORTS veh->pDriver->SetRadioStation(); -#endif + if (veh->m_nDoorLock == CARLOCK_UNLOCKED) + ped->Say(SOUND_PED_CAR_JACKING); + } else { ped->m_objective = OBJECTIVE_ENTER_CAR_AS_PASSENGER; } } } - if (veh->IsDoorMissing(enterDoor) || isBus) { + if (veh->IsDoorMissing(enterDoor) || !doorClosed || isBus) { PedAnimDoorCloseCB(nil, ped); } else { - AnimationId animToPlay; if (enterDoor != DOOR_FRONT_LEFT && enterDoor != DOOR_REAR_LEFT) { if (isVan) { - animToPlay = ANIM_VAN_CLOSE; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_CLOSE); } else if (isLow) { - animToPlay = ANIM_CAR_CLOSEDOOR_LOW_RHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_CLOSEDOOR_LOW_RHS); } else { - animToPlay = ANIM_CAR_CLOSEDOOR_RHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_CLOSEDOOR_RHS); } } else if (isVan) { - animToPlay = ANIM_VAN_CLOSE_L; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_CLOSE_L); } else if (isLow) { - animToPlay = ANIM_CAR_CLOSEDOOR_LOW_LHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_CLOSEDOOR_LOW_LHS); } else { - animToPlay = ANIM_CAR_CLOSEDOOR_LHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_CLOSEDOOR_LHS); } - ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, animToPlay); ped->m_pVehicleAnim->SetFinishCallback(PedAnimDoorCloseCB, ped); } } +#ifdef GTA_TRAIN void CPed::SetPedPositionInTrain(void) { LineUpPedWithTrain(); } +#endif void CPed::PedAnimPullPedOutCB(CAnimBlendAssociation* animAssoc, void* arg) @@ -11072,27 +12632,34 @@ CPed::PedAnimPullPedOutCB(CAnimBlendAssociation* animAssoc, void* arg) } } +// --MIAMI: Done void CPed::PedAnimStepOutCarCB(CAnimBlendAssociation* animAssoc, void* arg) { CPed* ped = (CPed*)arg; CVehicle* veh = ped->m_pMyVehicle; - if (animAssoc) + if (animAssoc) { + if ((animAssoc->animId == ANIM_CAR_ROLLOUT_LHS || animAssoc->animId == ANIM_CAR_ROLLOUT_RHS) && ped && ped->m_nPedState == PED_FALL) { + ped->RestoreHeadingRate(); + return; + } animAssoc->blendDelta = -1000.0f; + if (animAssoc->animId == ANIM_BIKE_GETOFF_BACK) + ped->RestoreHeadingRate(); + } if (!veh) { PedSetOutCarCB(nil, ped); return; } -#ifdef VC_PED_PORTS CVector posForZ = ped->GetPosition(); CPedPlacement::FindZCoorForPed(&posForZ); if (ped->GetPosition().z - 0.5f > posForZ.z) { PedSetOutCarCB(nil, ped); return; } -#endif + veh->m_nStaticFrames = 0; veh->m_vecMoveSpeed += CVector(0.001f, 0.001f, 0.001f); veh->m_vecTurnSpeed += CVector(0.001f, 0.001f, 0.001f); @@ -11165,10 +12732,8 @@ CPed::PedAnimStepOutCarCB(CAnimBlendAssociation* animAssoc, void* arg) } } -#ifdef VC_PED_PORTS if (ped->m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) closeDoor = false; -#endif if (!closeDoor) { if (!veh->IsDoorMissing(door) && !veh->bIsBus) { @@ -11267,6 +12832,7 @@ CPed::PedGetupCB(CAnimBlendAssociation* animAssoc, void* arg) ped->bGetUpAnimStarted = false; } +// --MIAMI: Done void CPed::PedLandCB(CAnimBlendAssociation* animAssoc, void* arg) { @@ -11370,6 +12936,7 @@ CPed::PedSetDraggedOutCarPositionCB(CAnimBlendAssociation* animAssoc, void* arg) ped->SetGetUp(); } +// --MIAMI: Done void CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -11381,7 +12948,6 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) if (!veh) return; -#ifdef VC_PED_PORTS // Situation of entering car as a driver while there is already a driver exiting atm. CPed *driver = veh->pDriver; if (driver && driver->m_nPedState == PED_DRIVING && !veh->bIsBus && driver->m_objective == OBJECTIVE_LEAVE_CAR @@ -11407,7 +12973,16 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) veh->pDriver = nil; } } -#endif + + if (ped->b157_40) { + ped->b157_40 = false; + ped->bRemoveFromWorld = true; + } + if (ped->b158_10) { + ped->b158_10 = false; + if (FindPlayerPed()) + FindPlayerPed()->m_nPadUpPressedInMilliseconds += 5; + } if (!ped->IsNotInWreckedVehicle() || ped->DyingOrDead()) return; @@ -11423,11 +12998,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) } } } - if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER -#if defined VC_PED_PORTS || defined FIX_BUGS - || ped->m_nPedState == PED_CARJACK -#endif - ) + if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || ped->m_nPedState == PED_CARJACK) veh->bIsBeingCarJacked = false; if (veh->m_nNumGettingIn) @@ -11438,9 +13009,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) if (veh->IsBoat()) { if (ped->IsPlayer()) { -#if defined VC_PED_PORTS || defined FIX_BUGS CCarCtrl::RegisterVehicleOfInterest(veh); -#endif if (veh->GetStatus() == STATUS_SIMPLE) { veh->m_vecMoveSpeed = CVector(0.0f, 0.0f, -0.00001f); veh->m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); @@ -11452,8 +13021,9 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) if (!veh->bEngineOn) veh->bEngineOn = true; - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); ped->StopNonPartialAnims(); + ped->RemoveWeaponWhenEnteringVehicle(); return; } @@ -11465,7 +13035,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) veh->m_nAlarmState = 15000; if (ped->IsPlayer()) { - if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) { + if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || veh->IsBike()) { if (veh->GetStatus() == STATUS_SIMPLE) { veh->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); veh->m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); @@ -11484,27 +13054,12 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) { for (int i = 0; i < veh->m_nNumMaxPassengers; ++i) { CPed *passenger = veh->pPassengers[i]; - if (passenger && passenger->CharCreatedBy == RANDOM_CHAR) { + if (passenger && !passenger->bStayInCarOnJack && !passenger->bHeldHostageInCar && (passenger->m_leader != ped || !ped->bIsLeader)) { passenger->SetObjective(OBJECTIVE_LEAVE_CAR, veh); -#ifdef VC_PED_PORTS passenger->m_leaveCarTimer = CTimer::GetTimeInMilliseconds(); -#endif } } } - // This shouldn't happen at all. Passengers can't enter with PED_CARJACK. Even though they did, we shouldn't call AddPassenger in here and SetDriver in below. -#if !defined VC_PED_PORTS && !defined FIX_BUGS - else if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER) { - if (ped->m_nPedState == PED_CARJACK) { - veh->AddPassenger(ped, 0); - ped->m_nPedState = PED_DRIVING; - ped->RestorePreviousObjective(); - ped->SetObjective(OBJECTIVE_LEAVE_CAR, veh); - } else if (veh->pDriver && ped->CharCreatedBy == RANDOM_CHAR) { - veh->AutoPilot.m_nCruiseSpeed = 17; - } - } -#endif if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || ped->m_nPedState == PED_CARJACK) { veh->SetDriver(ped); @@ -11537,17 +13092,27 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) veh->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS; veh->AutoPilot.m_nCruiseSpeed = 25; } - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) { - if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) + if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT + || ped->m_prevObjective == OBJECTIVE_SPRINT_TO_AREA || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) ped->m_prevObjective = OBJECTIVE_NONE; ped->RestorePreviousObjective(); } - } else if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER) { - if (veh->bIsBus) { + } else { + + bool slowDown = false; + if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER && veh->pDriver && ped->CharCreatedBy == RANDOM_CHAR) + slowDown = true; + + // VC also has a dead condition in here. + + if (veh->IsBike()) { + veh->AddPassenger(ped, 0); + } else if (veh->bIsBus) { veh->AddPassenger(ped); } else { switch (ped->m_vehEnterType) { @@ -11565,18 +13130,27 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) break; } } - ped->m_nPedState = PED_DRIVING; - if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) + ped->SetPedState(PED_DRIVING); + if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT + || ped->m_prevObjective == OBJECTIVE_SPRINT_TO_AREA || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) ped->m_prevObjective = OBJECTIVE_NONE; ped->RestorePreviousObjective(); -#ifdef VC_PED_PORTS - if(veh->pDriver && ped->CharCreatedBy == RANDOM_CHAR) + + // VC has conditional OBJECTIVE_LEAVE_CAR here, which runs if it entered the first dead condition. + + if(slowDown) veh->AutoPilot.m_nCruiseSpeed = 17; -#endif } - veh->m_nGettingInFlags &= ~GetCarDoorFlag(ped->m_vehEnterType); + int8 doorFlag; + if (veh->IsBike()) { + doorFlag = GetBikeDoorFlag(ped->m_vehEnterType); + } else { + doorFlag = GetEnterCarDoorFlag(ped->m_vehEnterType, veh->m_nNumMaxPassengers); + } + + veh->m_nGettingInFlags &= ~doorFlag; if (veh->bIsBus && !veh->m_nGettingInFlags) ((CAutomobile*)veh)->SetBusDoorTimer(1000, 1); @@ -11589,24 +13163,19 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) case OBJECTIVE_GOTO_AREA_ANY_MEANS: case OBJECTIVE_GOTO_AREA_ON_FOOT: case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_GOTO_SEAT_ON_FOOT: + case OBJECTIVE_GOTO_ATM_ON_FOOT: + case OBJECTIVE_GOTO_BUS_STOP_ON_FOOT: + case OBJECTIVE_GOTO_PIZZA_ON_FOOT: + case OBJECTIVE_GOTO_SHELTER_ON_FOOT: + case OBJECTIVE_SPRINT_TO_AREA: + case OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT: break; default: ped->SetObjective(OBJECTIVE_NONE); } - if (veh->pDriver == ped) { - if (veh->bLowVehicle) { - ped->m_pVehicleAnim = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_LSIT, 100.0f); - } else { - ped->m_pVehicleAnim = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_SIT, 100.0f); - } - } else if (veh->bLowVehicle) { - ped->m_pVehicleAnim = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_SITPLO, 100.0f); - } else { - ped->m_pVehicleAnim = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_SITP, 100.0f); - } - - ped->StopNonPartialAnims(); + ped->AddInCarAnims(veh, veh->pDriver == ped); if (veh->bIsBus) ped->bRenderPedInCar = false; @@ -11626,6 +13195,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) ped->bChangedSeat = true; } +// --MIAMI: Done :D void CPed::PedSetInTrainCB(CAnimBlendAssociation* animAssoc, void* arg) { @@ -11636,7 +13206,7 @@ CPed::PedSetInTrainCB(CAnimBlendAssociation* animAssoc, void* arg) return; ped->bInVehicle = true; - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); ped->RestorePreviousObjective(); ped->SetMoveState(PEDMOVE_STILL); veh->AddPassenger(ped); @@ -11653,26 +13223,13 @@ CPed::PedStaggerCB(CAnimBlendAssociation* animAssoc, void* arg) */ } -// It's "CPhoneInfo::ProcessNearestFreePhone" in PC IDB but that's not true, someone made it up. +// --MIAMI: Done bool CPed::RunToReportCrime(eCrimeType crimeToReport) { -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - if (bRunningToPhone) { - if (!isPhoneAvailable(m_phoneId)) { - m_phoneId = -1; - bIsRunning = false; - ClearSeek(); // clears bRunningToPhone - return false; - } - - return true; - } -#else // They changed true into false to make this function unusable. So running to phone actually starts but first frame after that cancels it. if (m_nPedState == PED_SEEK_POS) return false; -#endif CVector pos = GetPosition(); int phoneId = gPhoneInfo.FindNearestFreePhone(&pos); @@ -11681,15 +13238,12 @@ CPed::RunToReportCrime(eCrimeType crimeToReport) return false; CPhone *phone = &gPhoneInfo.m_aPhones[phoneId]; -#ifndef PEDS_REPORT_CRIMES_ON_PHONE if (phone->m_nState != PHONE_STATE_FREE) return false; -#endif bRunningToPhone = true; - SetSeek(phone->m_pEntity->GetMatrix() * -phone->m_pEntity->GetForward(), 1.0f); // original: phone.m_vecPos, 0.3f + SetSeek(phone->m_vecPos, 0.3f); SetMoveState(PEDMOVE_RUN); - bIsRunning = true; // not there in original m_phoneId = phoneId; m_crimeToReportOnPhone = crimeToReport; return true; @@ -11725,7 +13279,7 @@ CPed::RegisterThreatWithGangPeds(CEntity *attacker) } if (attackerPed && attackerPed->IsPlayer() && (attackerPed->m_nPedState == PED_CARJACK || attackerPed->bInVehicle)) { - if (!attackerPed->m_pMyVehicle || attackerPed->m_pMyVehicle->GetModelIndex() != MI_TOYZ) { + if (!attackerPed->m_pMyVehicle || attackerPed->m_pMyVehicle->GetModelIndex() != MI_TOPFUN) { int16 lastVehicle; CEntity *vehicles[8]; CWorld::FindObjectsInRange(GetPosition(), 30.0f, true, &lastVehicle, 6, vehicles, false, true, false, false, false); @@ -11855,22 +13409,23 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) if (ped->m_objective == OBJECTIVE_LEAVE_CAR) ped->RestorePreviousObjective(); -#ifdef VC_PED_PORTS else if (ped->m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) { ped->m_fHealth = 0.0f; ped->SetDie(ANIM_FLOOR_HIT, 4.0f, 0.5f); } -#endif ped->bInVehicle = false; - if (veh && veh->IsCar() && !veh->IsRoomForPedToLeaveCar(ped->m_vehEnterType, nil)) { + if (veh && (veh->IsCar() || veh->IsBike()) && !veh->IsRoomForPedToLeaveCar(ped->m_vehEnterType, nil)) { ped->PositionPedOutOfCollision(); } if (ped->m_nPedState == PED_EXIT_CAR) { - if (ped->m_nPedType == PEDTYPE_COP) + if (ped->m_nPedType == PEDTYPE_COP) { ped->SetIdle(); - else + if (((CCopPed*)ped)->m_nCopType == COP_MIAMIVICE && ped->m_pMyVehicle && ped->m_pMyVehicle->pDriver == ped) { + DMAudio.PlayOneShot(ped->m_audioEntityId, SOUND_PED_MIAMIVICE_EXITING_CAR, 0.f); + } + } else ped->RestorePreviousState(); veh = ped->m_pMyVehicle; @@ -11920,7 +13475,7 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) } } #ifdef VC_PED_PORTS - else { + else if (ped->m_nPedState == PED_DRIVING) { ped->m_nPedState = PED_IDLE; } #endif @@ -11930,10 +13485,7 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) ped->RestartNonPartialAnims(); ped->m_pVehicleAnim = nil; - CVector posFromZ = ped->GetPosition(); - CPedPlacement::FindZCoorForPed(&posFromZ); ped->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - ped->SetPosition(posFromZ); veh = ped->m_pMyVehicle; if (veh) { if (ped->m_nPedType == PEDTYPE_PROSTITUTE) { @@ -11948,7 +13500,11 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) } } } - veh->m_nGettingOutFlags &= ~GetCarDoorFlag(ped->m_vehEnterType); + if (veh && veh->IsBike()) + veh->m_nGettingOutFlags &= ~GetBikeDoorFlag(ped->m_vehEnterType); + else + veh->m_nGettingOutFlags &= ~GetCarDoorFlag(ped->m_vehEnterType); + if (veh->pDriver == ped) { veh->RemoveDriver(); veh->SetStatus(STATUS_ABANDONED); @@ -11999,17 +13555,18 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) if (createdBy == MISSION_CHAR && !startedToRun) ped->SetMoveState(PEDMOVE_WALK); } + ped->bHeldHostageInCar = false; } -// It was inlined in III but not in VC. -inline void +// --MIAMI: Done, but enumarate weapon slots +void CPed::ReplaceWeaponWhenExitingVehicle(void) { eWeaponType weaponType = GetWeapon()->m_eWeaponType; // If it's Uzi, we may have stored weapon. Uzi is the only gun we can use in car. - if (IsPlayer() && weaponType == WEAPONTYPE_UZI) { - if (/*IsPlayer() && */ m_storedWeapon != WEAPONTYPE_UNIDENTIFIED) { + if (IsPlayer() && GetWeaponSlot(weaponType) == 5) { + if (m_storedWeapon != WEAPONTYPE_UNIDENTIFIED) { SetCurrentWeapon(m_storedWeapon); m_storedWeapon = WEAPONTYPE_UNIDENTIFIED; } @@ -12018,20 +13575,21 @@ CPed::ReplaceWeaponWhenExitingVehicle(void) } } -// Same, it's inlined in III. -inline void +// --MIAMI: Done +void CPed::RemoveWeaponWhenEnteringVehicle(void) { - if (IsPlayer() && HasWeapon(WEAPONTYPE_UZI) && GetWeapon(WEAPONTYPE_UZI).m_nAmmoTotal > 0) { + if (IsPlayer() && HasWeaponSlot(5) && GetWeapon(5).m_nAmmoTotal > 0 && ((CPlayerPed*)this)->GetPlayerInfoForThisPlayerPed()->m_bDriveByAllowed) { if (m_storedWeapon == WEAPONTYPE_UNIDENTIFIED) m_storedWeapon = GetWeapon()->m_eWeaponType; - SetCurrentWeapon(WEAPONTYPE_UZI); + SetCurrentWeapon(GetWeapon(5).m_eWeaponType); } else { CWeaponInfo *ourWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); RemoveWeaponModel(ourWeapon->m_nModelId); } } +#ifdef GTA_TRAIN void CPed::PedSetOutTrainCB(CAnimBlendAssociation *animAssoc, void *arg) { @@ -12060,6 +13618,7 @@ CPed::PedSetOutTrainCB(CAnimBlendAssociation *animAssoc, void *arg) ped->SetHeading(ped->m_fRotationCur); veh->RemovePassenger(ped); } +#endif bool CPed::PlacePedOnDryLand(void) @@ -12412,20 +13971,19 @@ CPed::PossiblyFindBetterPosToSeekCar(CVector *pos, CVehicle *veh) return true; } +extern CVector vecTestTemp(-1.0f, -1.0f, -1.0f); + +// --MIAMI: Done except comment void CPed::Render(void) { - if (!bInVehicle || m_nPedState == PED_EXIT_CAR || m_nPedState == PED_DRAG_FROM_CAR || - bRenderPedInCar && sq(25.0f * TheCamera.LODDistMultiplier) >= (TheCamera.GetPosition() - GetPosition()).MagnitudeSqr()) { + if (!bInVehicle || !m_pMyVehicle || m_nPedState == PED_EXIT_CAR || m_nPedState == PED_DRAG_FROM_CAR || + bRenderPedInCar && (m_pMyVehicle->IsBike() || IsPlayer() || + sq((m_pMyVehicle->IsBoat() ? 40.0f : 25.0f) * TheCamera.LODDistMultiplier) >= (TheCamera.GetPosition() - GetPosition()).MagnitudeSqr())) { + CEntity::Render(); -#ifdef PED_SKIN - if(IsClumpSkinned(GetClump())){ - renderLimb(PED_HEAD); - renderLimb(PED_HANDL); - renderLimb(PED_HANDR); - } - if(m_pWeaponModel && IsClumpSkinned(GetClump())){ + if(m_pWeaponModel){ RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump()); int idx = RpHAnimIDGetIndex(hier, m_pFrames[PED_HANDR]->nodeID); RwMatrix *mat = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; @@ -12433,52 +13991,32 @@ CPed::Render(void) *RwFrameGetMatrix(frame) = *mat; RwFrameUpdateObjects(frame); RpAtomicRender(m_pWeaponModel); + if (IsPlayer()) { + CPlayerPed *player = (CPlayerPed*)this; + if (player->m_pMinigunTopAtomic) { + frame = RpAtomicGetFrame(player->m_pMinigunTopAtomic); + *RwFrameGetMatrix(frame) = *mat; + + player->m_fGunSpinAngle = player->m_fGunSpinSpeed * CTimer::GetTimeStep() + player->m_fGunSpinAngle; + if (player->m_fGunSpinAngle > TWOPI) + player->m_fGunSpinAngle -= TWOPI; + + CMatrix mgTopMat, localAdjMat; + mgTopMat.Attach(RwFrameGetMatrix(frame)); + localAdjMat.SetRotateX(player->m_fGunSpinAngle); + localAdjMat.Rotate(DEGTORAD(-4.477f)* vecTestTemp.x, DEGTORAD(29.731f) * vecTestTemp.y, DEGTORAD(1.064f) * vecTestTemp.z); + localAdjMat.GetPosition() += CVector(0.829f, -0.001f, 0.226f); + mgTopMat = mgTopMat * localAdjMat; + mgTopMat.UpdateRW(); + + RwFrameUpdateObjects(frame); + RpAtomicRender(player->m_pMinigunTopAtomic); + } + } } -#endif } } -#ifdef PED_SKIN -static RpMaterial* -SetLimbAlphaCB(RpMaterial *material, void *data) -{ - ((RwRGBA*)RpMaterialGetColor(material))->alpha = *(uint8*)data; - return material; -} - -void -CPed::renderLimb(int node) -{ - RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump()); - int idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID); - RwMatrix *mat = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; - CPedModelInfo *mi = (CPedModelInfo *)CModelInfo::GetModelInfo(GetModelIndex()); - RpAtomic *atomic; - switch(node){ - case PED_HEAD: - atomic = mi->getHead(); - break; - case PED_HANDL: - atomic = mi->getLeftHand(); - break; - case PED_HANDR: - atomic = mi->getRightHand(); - break; - default: - return; - } - if(atomic == nil) - return; - - RwFrame *frame = RpAtomicGetFrame(atomic); - *RwFrameGetMatrix(frame) = *mat; - RwFrameUpdateObjects(frame); - int alpha = CVisibilityPlugins::GetClumpAlpha(GetClump()); - RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), SetLimbAlphaCB, &alpha); - RpAtomicRender(atomic); -} -#endif - void CPed::ProcessObjective(void) { @@ -12526,9 +14064,21 @@ CPed::ProcessObjective(void) case OBJECTIVE_SET_LEADER: break; case OBJECTIVE_WAIT_ON_FOOT: - SetIdle(); - m_objective = OBJECTIVE_NONE; - SetMoveState(PEDMOVE_STILL); + if (GetPedState() == PED_DRIVING) + m_objective = OBJECTIVE_NONE; + else { + SetIdle(); + if (m_attractor) { + if (m_objectiveTimer && CTimer::GetTimeInMilliseconds() > m_nWaitTimer) { + GetPedAttractorManager()->BroadcastDeparture(this, m_attractor); + m_objectiveTimer = 0; + } + } + else { + m_objective = OBJECTIVE_NONE; + SetMoveState(PEDMOVE_STILL); + } + } break; case OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE: if (InVehicle()) { @@ -12606,7 +14156,8 @@ CPed::ProcessObjective(void) } else { bool targetHasVeh = m_pedInObjective->bInVehicle; if (!targetHasVeh - || targetHasVeh && m_pedInObjective->m_pMyVehicle->CanPedExitCar()) { +// TODO(MIAMI): argument + || targetHasVeh && m_pedInObjective->m_pMyVehicle->CanPedExitCar(false)) { m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0; m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_NONE; SetObjective(OBJECTIVE_LEAVE_CAR, m_pMyVehicle); @@ -12658,8 +14209,8 @@ CPed::ProcessObjective(void) int chosenModel = CCarCtrl::ChooseModel(&zoneInfo, &ourPos, &chosenCarClass); CAutomobile *newVeh = new CAutomobile(chosenModel, RANDOM_VEHICLE); if (newVeh) { - newVeh->GetMatrix().GetPosition() = ThePaths.m_pathNodes[closestNode].GetPosition(); - newVeh->GetMatrix().GetPosition().z += 4.0f; + newVeh->GetMatrix().GetPosition() = ThePaths.m_pathNodes[closestNode].GetPosition(); + newVeh->GetMatrix().GetPosition().z += 4.0f; newVeh->SetHeading(DEGTORAD(200.0f)); newVeh->SetStatus(STATUS_ABANDONED); newVeh->m_nDoorLock = CARLOCK_UNLOCKED; @@ -12684,356 +14235,29 @@ CPed::ProcessObjective(void) } case OBJECTIVE_KILL_CHAR_ON_FOOT: { - bool killPlayerInNoPoliceZone = false; if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT && InVehicle()) { SetObjective(OBJECTIVE_LEAVE_CAR, m_pMyVehicle); break; } if (!m_pedInObjective || m_pedInObjective->DyingOrDead()) { - ClearLookFlag(); - bObjectiveCompleted = true; - SetMoveAnim(); - break; - } - if (m_pedInObjective->IsPlayer() && CCullZones::NoPolice()) - killPlayerInNoPoliceZone = true; - - if (!bNotAllowedToDuck || killPlayerInNoPoliceZone) { - if (m_nPedType == PEDTYPE_COP && !m_pedInObjective->GetWeapon()->IsTypeMelee() && !GetWeapon()->IsTypeMelee()) - bNotAllowedToDuck = true; - } else { - if (!m_pedInObjective->bInVehicle) { - if (m_pedInObjective->GetWeapon()->IsTypeMelee() || GetWeapon()->IsTypeMelee()) { - bNotAllowedToDuck = false; - bCrouchWhenShooting = false; - } else if (DuckAndCover()) { - break; - } - } else { - bNotAllowedToDuck = false; - bCrouchWhenShooting = false; - } - } - if (m_leaveCarTimer > CTimer::GetTimeInMilliseconds() && !bKindaStayInSamePlace) { - SetMoveState(PEDMOVE_STILL); - break; - } - if (m_pedInObjective->IsPlayer()) { - CPlayerPed *player = FindPlayerPed(); - if (m_nPedType == PEDTYPE_COP && player->m_pWanted->m_bIgnoredByCops - || player->m_pWanted->m_bIgnoredByEveryone - || m_pedInObjective->bIsInWater - || m_pedInObjective->m_nPedState == PED_ARRESTED) { - - if (m_nPedState != PED_ARREST_PLAYER) - SetIdle(); - - break; - } - } - CWeaponInfo *wepInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - float wepRange = wepInfo->m_fRange; - float wepRangeAdjusted; - if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED) { - wepRangeAdjusted = wepRange / 3.0f; - } else { - if (m_nPedState == PED_FIGHT) { - if (!IsPlayer() && !(m_pedStats->m_flags & STAT_CAN_KICK)) - wepRange = 2.0f; - } else { - wepRange = 1.3f; - } - wepRangeAdjusted = wepRange; - } - if (m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds() && wepRangeAdjusted < 2.5f) { - wepRangeAdjusted = 2.5f; - } - if (m_pedInObjective->IsPlayer() && m_nPedType != PEDTYPE_COP - && CharCreatedBy != MISSION_CHAR && FindPlayerPed()->m_pWanted->m_CurrentCops) { - SetObjective(OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE); - break; - } - if (m_pedInObjective->m_fHealth <= 0.0f) { bObjectiveCompleted = true; - bScriptObjectiveCompleted = true; - SetMoveAnim(); - break; - } - float distWithTargetSc = distWithTarget.Magnitude(); - if (m_pedInObjective->bInVehicle && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR) { - CVehicle *vehOfTarget = m_pedInObjective->m_pMyVehicle; - if (vehOfTarget->bIsInWater || vehOfTarget->GetStatus() == STATUS_PLAYER_DISABLED - || m_pedInObjective->IsPlayer() && CPad::GetPad(0)->ArePlayerControlsDisabled()) { - SetIdle(); - return; - } - SetLookFlag(vehOfTarget, false); - if (m_nPedState != PED_CARJACK) { - if (m_pedInObjective->m_nPedState != PED_ARRESTED) { - if (m_attackTimer < CTimer::GetTimeInMilliseconds() && wepInfo->m_eWeaponFire != WEAPON_FIRE_MELEE - && distWithTargetSc < wepRange && distWithTargetSc > 3.0f) { - - // I hope so - CVector ourHead = GetMatrix() * CVector(0.5f, 0.0f, 0.6f); - CVector maxShotPos = vehOfTarget->GetPosition() - ourHead; - maxShotPos.Normalise(); - maxShotPos = maxShotPos * wepInfo->m_fRange + ourHead; - - CWorld::bIncludeDeadPeds = true; - CColPoint foundCol; - CEntity *foundEnt; - CWorld::ProcessLineOfSight(ourHead, maxShotPos, foundCol, foundEnt, - true, true, true, true, false, true, false); - CWorld::bIncludeDeadPeds = false; - if (foundEnt == vehOfTarget) { - SetAttack(vehOfTarget); - m_pPointGunAt = vehOfTarget; - if (vehOfTarget) - vehOfTarget->RegisterReference((CEntity **) &m_pPointGunAt); - - SetShootTimer(CGeneral::GetRandomNumberInRange(500, 2000)); - if (distWithTargetSc <= m_distanceToCountSeekDone) { - SetAttackTimer(CGeneral::GetRandomNumberInRange(200, 500)); - SetMoveState(PEDMOVE_STILL); - } else { - SetAttackTimer(CGeneral::GetRandomNumberInRange(2000, 5000)); - } - } - } - else if (m_nPedState != PED_ATTACK && !bKindaStayInSamePlace && !killPlayerInNoPoliceZone) { - if (vehOfTarget) { - if (m_nPedType == PEDTYPE_COP || vehOfTarget->bIsBus) { - GoToNearestDoor(vehOfTarget); - } else { - m_vehEnterType = 0; - if (m_pedInObjective == vehOfTarget->pDriver || vehOfTarget->bIsBus) { - m_vehEnterType = CAR_DOOR_LF; - } else if (m_pedInObjective == vehOfTarget->pPassengers[0]) { - m_vehEnterType = CAR_DOOR_RF; - } else if (m_pedInObjective == vehOfTarget->pPassengers[1]) { - m_vehEnterType = CAR_DOOR_LR; - } else if (m_pedInObjective == vehOfTarget->pPassengers[2]) { - m_vehEnterType = CAR_DOOR_RR; - } - // Unused - // GetPositionToOpenCarDoor(vehOfTarget, m_vehEnterType); - SetSeekCar(vehOfTarget, m_vehEnterType); - SetMoveState(PEDMOVE_RUN); - } - } - } - } - } + ClearLookFlag(); SetMoveAnim(); break; } - if (m_nMoveState == PEDMOVE_STILL && IsPedInControl()) { - SetLookFlag(m_pedInObjective, false); - TurnBody(); - } - if (m_nPedType == PEDTYPE_COP && distWithTargetSc < 1.5f && m_pedInObjective->IsPlayer()) { - if (m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds() - || m_pedInObjective->m_nPedState == PED_DRAG_FROM_CAR) { + if (m_pedInObjective) { + int status; + if (GetWeapon()->IsTypeMelee()) + status = KillCharOnFootMelee(carOrOurPos, targetCarOrHisPos, distWithTarget); + else + status = KillCharOnFootArmed(carOrOurPos, targetCarOrHisPos, distWithTarget); - ((CCopPed*)this)->SetArrestPlayer(m_pedInObjective); + if (status == WATCH_UNTIL_HE_DISAPPEARS) return; - } - } - if (!bKindaStayInSamePlace && !bStopAndShoot && m_nPedState != PED_ATTACK && !killPlayerInNoPoliceZone) { - if (distWithTargetSc > wepRange - || m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds() - || m_pedInObjective->m_nPedState == PED_ARRESTED - || m_pedInObjective->EnteringCar() && distWithTargetSc < 3.0f - || distWithTargetSc > m_distanceToCountSeekDone && !CanSeeEntity(m_pedInObjective)) { - - if (m_pedInObjective->EnteringCar()) - wepRangeAdjusted = 2.0f; - - if (bUsePedNodeSeek) { - CVector bestCoords(0.0f, 0.0f, 0.0f); - m_vecSeekPos = m_pedInObjective->GetPosition(); - - if (!m_pNextPathNode) - FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords); - - if (m_pNextPathNode) - m_vecSeekPos = m_pNextPathNode->GetPosition(); - - SetSeek(m_vecSeekPos, m_distanceToCountSeekDone); - } else { - SetSeek(m_pedInObjective, wepRangeAdjusted); - } - bCrouchWhenShooting = false; - if (m_pedInObjective->m_pCurrentPhysSurface && distWithTargetSc < 5.0f) { - if (wepRange <= 5.0f) { - if (m_pedInObjective->IsPlayer() - && FindPlayerPed()->m_bSpeedTimerFlag - && (IsGangMember() || m_nPedType == PEDTYPE_COP) - && GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED) { - GiveWeapon(WEAPONTYPE_COLT45, 1000); - SetCurrentWeapon(WEAPONTYPE_COLT45); - } - } else { - bStopAndShoot = true; - } - SetMoveState(PEDMOVE_STILL); - SetMoveAnim(); - break; - } - bStopAndShoot = false; - SetMoveAnim(); + if (status == CANT_ATTACK) break; - } } - if (m_attackTimer < CTimer::GetTimeInMilliseconds() - && distWithTargetSc < wepRange && m_pedInObjective->m_nPedState != PED_GETUP && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR) { - if (bIsDucking) { - CAnimBlendAssociation *duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN); - if (duckAnim) { - duckAnim->blendDelta = -2.0f; - break; - } - bIsDucking = false; - } else if (wepRange <= 5.0f) { - SetMoveState(PEDMOVE_STILL); - SetAttack(m_pedInObjective); - m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( - m_pedInObjective->GetPosition().x, m_pedInObjective->GetPosition().y, - GetPosition().x, GetPosition().y); - SetShootTimer(CGeneral::GetRandomNumberInRange(0.0f, 500.0f)); - SetAttackTimer(CGeneral::GetRandomNumberInRange(0.0f, 1500.0f)); - bObstacleShowedUpDuringKillObjective = false; - - } else { - CVector target; - CVector ourHead = GetMatrix() * CVector(0.5f, 0.0f, 0.6f); - if (m_pedInObjective->IsPed()) - m_pedInObjective->m_pedIK.GetComponentPosition((RwV3d*)&target, PED_MID); - else - target = m_pedInObjective->GetPosition(); - - target -= ourHead; - target.Normalise(); - target = target * wepInfo->m_fRange + ourHead; - - CWorld::bIncludeDeadPeds = true; - CEntity *foundEnt = nil; - CColPoint foundCol; - - CWorld::ProcessLineOfSight( - ourHead, target, foundCol, foundEnt, - true, true, true, false, true, false); - CWorld::bIncludeDeadPeds = 0; - if (foundEnt == m_pedInObjective) { - SetAttack(m_pedInObjective); - m_pPointGunAt = m_pedInObjective; - if (m_pedInObjective) - m_pedInObjective->RegisterReference((CEntity **) &m_pPointGunAt); - - SetShootTimer(CGeneral::GetRandomNumberInRange(500.0f, 2000.0f)); - - int time; - if (distWithTargetSc <= wepRangeAdjusted) - time = CGeneral::GetRandomNumberInRange(100.0f, 500.0f); - else - time = CGeneral::GetRandomNumberInRange(1500.0f, 3000.0f); - - SetAttackTimer(time); - bObstacleShowedUpDuringKillObjective = false; - - } else if (foundEnt) { - if (foundEnt->IsPed()) { - SetAttackTimer(CGeneral::GetRandomNumberInRange(500.0f, 1000.0f)); - bObstacleShowedUpDuringKillObjective = false; - } else { - if (foundEnt->IsObject()) { - SetAttackTimer(CGeneral::GetRandomNumberInRange(200.0f, 400.0f)); - bObstacleShowedUpDuringKillObjective = true; - } else if (foundEnt->IsVehicle()) { - SetAttackTimer(CGeneral::GetRandomNumberInRange(400.0f, 600.0f)); - bObstacleShowedUpDuringKillObjective = true; - } else { - SetAttackTimer(CGeneral::GetRandomNumberInRange(700.0f, 1200.0f)); - bObstacleShowedUpDuringKillObjective = true; - } - } - - m_fleeFrom = foundEnt; - m_fleeFrom->RegisterReference((CEntity**) &m_fleeFrom); - SetPointGunAt(m_pedInObjective); - } - } - } else { - if (!m_pedInObjective->m_pCurrentPhysSurface) - bStopAndShoot = false; - - if (m_nPedState != PED_ATTACK && m_nPedState != PED_FIGHT) { - - // This is weird... - if (bNotAllowedToDuck && bKindaStayInSamePlace) { - if (!bIsDucking) { - CAnimBlendAssociation* duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN); - if (!duckAnim || duckAnim->blendDelta < 0.0f) { - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_DUCK_DOWN, 4.0f); - bIsDucking = true; - } - break; - } else { - CAnimBlendAssociation* duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN); - if (!duckAnim || duckAnim->blendDelta < 0.0f) { - bIsDucking = false; - } else { - break; - } - } - } - if (bObstacleShowedUpDuringKillObjective) { - if (m_nPedType == PEDTYPE_COP) { - if (GetWeapon()->m_eWeaponType > WEAPONTYPE_COLT45 - || m_fleeFrom && m_fleeFrom->IsObject()) { - wepRangeAdjusted = 6.0f; - } else if (m_fleeFrom && m_fleeFrom->IsVehicle()) { - wepRangeAdjusted = 4.0f; - } else { - wepRangeAdjusted = 2.0f; - } - } else { - wepRangeAdjusted = 2.0f; - } - } - if (distWithTargetSc <= wepRangeAdjusted) { - SetMoveState(PEDMOVE_STILL); - bIsPointingGunAt = true; - if (m_nPedState != PED_AIM_GUN && !bDuckAndCover) { - m_attackTimer = CTimer::GetTimeInMilliseconds(); - SetIdle(); - } - } else { - if (m_nPedState != PED_SEEK_ENTITY && m_nPedState != PED_SEEK_POS - && !bStopAndShoot && !killPlayerInNoPoliceZone && !bKindaStayInSamePlace) { - Say(SOUND_PED_ATTACK); - SetSeek(m_pedInObjective, wepRangeAdjusted); - bIsRunning = true; - } - } - } - } - - if (distWithTargetSc < 2.5f && wepRange > 5.0f - && wepInfo->m_eWeaponFire != WEAPON_FIRE_MELEE) { - - SetAttack(m_pedInObjective); - if (m_attackTimer < CTimer::GetTimeInMilliseconds()) { - int time = CGeneral::GetRandomNumberInRange(500.0f, 1000.0f); - SetAttackTimer(time); - SetShootTimer(time - 500); - } - SetMoveState(PEDMOVE_STILL); - } - if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer) - m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(m_pedInObjective->GetPosition().x, m_pedInObjective->GetPosition().y, GetPosition().x, GetPosition().y); - SetMoveAnim(); break; } @@ -13055,11 +14279,15 @@ CPed::ProcessObjective(void) break; } case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: { if (m_pedInObjective) { float safeDistance = 2.0f; if (m_pedInObjective->bInVehicle) safeDistance = 3.0f; + if (m_objective == OBJECTIVE_HASSLE_CHAR) + safeDistance = 1.0f; float distWithTargetSc = distWithTarget.Magnitude(); if (m_nPedStateTimer < CTimer::GetTimeInMilliseconds()) { @@ -13067,6 +14295,8 @@ CPed::ProcessObjective(void) bScriptObjectiveCompleted = true; if (m_nPedState != PED_ATTACK) { SetIdle(); + if (m_pLookTarget) + m_pLookTarget->CleanUpOldReference(&m_pLookTarget); m_pLookTarget = m_pedInObjective; m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget); TurnBody(); @@ -13075,6 +14305,18 @@ CPed::ProcessObjective(void) SetMoveState(m_pedInObjective->m_nMoveState); else SetMoveState(PEDMOVE_STILL); + + if (m_objective == OBJECTIVE_HASSLE_CHAR) { + Say(SOUND_PED_COP_REACTION); + m_pedInObjective->Say(SOUND_PED_UNK_126); + m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 3000; + m_pedInObjective->m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 3000; + SetObjective(OBJECTIVE_WANDER); + m_pedInObjective->SetObjective(OBJECTIVE_WANDER); + CVector2D dist = GetPosition() - m_pedInObjective->GetPosition(); + m_nPathDir = CGeneral::GetNodeHeadingFromVector(dist.x, dist.y); + m_pedInObjective->m_nPathDir = CGeneral::GetNodeHeadingFromVector(-dist.x, -dist.y); + } } else { SetSeek(m_pedInObjective, safeDistance); if (distWithTargetSc >= 5.0f) { @@ -13100,6 +14342,8 @@ CPed::ProcessObjective(void) } } } + if (m_objective == OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING && m_nMoveState > PEDMOVE_STILL) + SetMoveState(PEDMOVE_WALK); } } else { SetObjective(OBJECTIVE_NONE); @@ -13392,8 +14636,9 @@ CPed::ProcessObjective(void) } case OBJECTIVE_GOTO_AREA_ON_FOOT: case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_SPRINT_TO_AREA: { - if ((m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA) + if ((m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA || m_objective == OBJECTIVE_SPRINT_TO_AREA) && InVehicle()) { SetObjective(OBJECTIVE_LEAVE_CAR, m_pMyVehicle); } else { @@ -13408,11 +14653,22 @@ CPed::ProcessObjective(void) CVector bestCoords(0.0f, 0.0f, 0.0f); m_vecSeekPos = m_nextRoutePointPos; - if (!m_pNextPathNode) - FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords); + if (!m_pNextPathNode) { + bool found = FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords); + if (m_pNextPathNode) { + // Because it already does that if it finds better coords. + if (!found) { + bestCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); + } + if ((bestCoords - GetPosition()).Magnitude2D() < m_distanceToCountSeekDone) { + m_pNextPathNode = nil; + bUsePedNodeSeek = false; + } + } + } if (m_pNextPathNode) - m_vecSeekPos = m_pNextPathNode->GetPosition(); + m_vecSeekPos = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); } SetSeek(m_vecSeekPos, m_distanceToCountSeekDone); } @@ -13586,14 +14842,14 @@ CPed::ProcessObjective(void) float distWithTargetScSqr = distWithTarget.MagnitudeSqr(); if (distWithTargetScSqr <= sq(10.0f)) { if (distWithTargetScSqr <= sq(1.4f)) { - CAnimBlendAssociation *reloadAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_AK_RELOAD); + CAnimBlendAssociation *reloadAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FUCKU); m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( m_pedInObjective->GetPosition().x, m_pedInObjective->GetPosition().y, GetPosition().x, GetPosition().y); if (reloadAssoc || !m_pedInObjective->IsPedShootable()) { if (reloadAssoc && - (!reloadAssoc->IsRunning() || reloadAssoc->currentTime / reloadAssoc->hierarchy->totalLength > 0.8f)) { + (!reloadAssoc->IsRunning() || reloadAssoc->GetProgress() > 0.8f)) { CAnimBlendAssociation *punchAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_PPUNCH, 8.0f); punchAssoc->flags |= ASSOC_DELETEFADEDOUT; punchAssoc->flags |= ASSOC_FADEOUTWHENDONE; @@ -13623,7 +14879,7 @@ CPed::ProcessObjective(void) if (weaponType != WEAPONTYPE_UNARMED && weaponType != WEAPONTYPE_BASEBALLBAT) SetCurrentWeapon(WEAPONTYPE_UNARMED); - CAnimBlendAssociation *newReloadAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_AK_RELOAD, 8.0f); + CAnimBlendAssociation *newReloadAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FUCKU, 8.0f); newReloadAssoc->flags |= ASSOC_DELETEFADEDOUT; newReloadAssoc->flags |= ASSOC_FADEOUTWHENDONE; } @@ -13639,13 +14895,18 @@ CPed::ProcessObjective(void) SetWanderPath(CGeneral::GetRandomNumber() & 7); } } else { -#ifdef VC_PED_PORTS m_objective = OBJECTIVE_NONE; -#endif ClearObjective(); } - break; } + // fall through + case OBJECTIVE_WANDER: + if (CTimer::GetTimeInMilliseconds() > m_leaveCarTimer && !bInVehicle) { + m_leaveCarTimer = 0; + m_objective = OBJECTIVE_NONE; + CPed::SetWanderPath(m_nPathDir); + } + break; case OBJECTIVE_FLEE_CAR: if (!bInVehicle && m_nPedState != PED_FLEE_ENTITY && m_pMyVehicle) { RestorePreviousObjective(); @@ -13655,24 +14916,20 @@ CPed::ProcessObjective(void) // fall through case OBJECTIVE_LEAVE_CAR: if (CTimer::GetTimeInMilliseconds() > m_leaveCarTimer) { - if (InVehicle() -#ifdef VC_PED_PORTS - && (FindPlayerPed() != this || !CPad::GetPad(0)->GetAccelerate() - || bBusJacked) -#endif - ) { + if (InVehicle() && + (FindPlayerPed() != this || !CPad::GetPad(0)->GetAccelerate() || bBusJacked)) { + if (m_nPedState != PED_EXIT_CAR && m_nPedState != PED_DRAG_FROM_CAR && m_nPedState != PED_EXIT_TRAIN && (m_nPedType != PEDTYPE_COP -#ifdef VC_PED_PORTS || m_pMyVehicle->IsBoat() -#endif || m_pMyVehicle->m_vecMoveSpeed.MagnitudeSqr2D() < sq(0.005f))) { +#ifdef GTA_TRAIN if (m_pMyVehicle->IsTrain()) SetExitTrain(m_pMyVehicle); -#ifdef VC_PED_PORTS - else if (m_pMyVehicle->IsBoat()) - SetExitBoat(m_pMyVehicle); + else #endif + if (m_pMyVehicle->IsBoat()) + SetExitBoat(m_pMyVehicle); else SetExitCar(m_pMyVehicle, 0); } @@ -13680,6 +14937,28 @@ CPed::ProcessObjective(void) RestorePreviousObjective(); } } + if (bHeldHostageInCar) { + if (CTheScripts::IsPlayerOnAMission()) { + CVehicle *playerVeh = FindPlayerVehicle(); + if (playerVeh && playerVeh->IsPassenger(this)) { + if (m_leaveCarTimer != 0) + m_leaveCarTimer = 0; + } + } + } + break; + case OBJECTIVE_AIM_GUN_AT: + if (m_pedInObjective) { + if (!bObstacleShowedUpDuringKillObjective) + SetPointGunAt(m_pedInObjective); + + if (m_nMoveState == PEDMOVE_STILL && IsPedInControl()) { + SetLookFlag(m_pedInObjective, false); + TurnBody(); + } + } else { + ClearObjective(); + } break; #ifdef VC_PED_PORTS case OBJECTIVE_LEAVE_CAR_AND_DIE: @@ -13709,6 +14988,224 @@ CPed::ProcessObjective(void) } break; } + case OBJECTIVE_GOTO_SEAT_ON_FOOT: + case OBJECTIVE_GOTO_ATM_ON_FOOT: + case OBJECTIVE_GOTO_BUS_STOP_ON_FOOT: + case OBJECTIVE_GOTO_PIZZA_ON_FOOT: + case OBJECTIVE_GOTO_SHELTER_ON_FOOT: + case OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT: + if (CTimer::GetTimeInMilliseconds() > m_objectiveTimer) { + m_objectiveTimer = 0; + if (m_attractor) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + } + else { + CVector distance = m_nextRoutePointPos - GetPosition(); + distance.z = 0.0f; + if (m_objective == OBJECTIVE_GOTO_SHELTER_ON_FOOT) { + if (m_nMoveState == PEDMOVE_SPRINT && distance.Magnitude() < SQR(2.0f)) { + SetMoveState(PEDMOVE_WALK); + bIsRunning = false; + } + else if (CWeather::Rain < 0.2f && m_attractor) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + return; + } + } + else if (m_objective == OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT) { + if (m_nMoveState == PEDMOVE_SPRINT && distance.Magnitude() < SQR(4.0f)) { + SetMoveState(PEDMOVE_WALK); + bIsRunning = false; + } + CVehicle* pIceCreamVan = GetPedAttractorManager()->GetIceCreamVanForEffect(m_attractor->GetEffect()); + if (0.01f * CTimer::GetTimeStep() * 5.0f < pIceCreamVan->m_fDistanceTravelled) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + return; + } + if (!pIceCreamVan->pDriver || + !pIceCreamVan->pDriver->IsPlayer() || + pIceCreamVan->pDriver->GetPedState() == PED_ARRESTED || + pIceCreamVan->pDriver->GetPedState() == PED_DEAD) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + return; + } + if (!pIceCreamVan->m_bSirenOrAlarm) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + return; + } + if (pIceCreamVan->GetStatus() == STATUS_WRECKED) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + return; + } + } + if (sq(m_distanceToCountSeekDone) < distance.MagnitudeSqr()) { + if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer || GetPedState() != PED_SEEK_POS) + SetSeek(m_vecSeekPos, m_distanceToCountSeekDone); + } + else { + if (!bReachedAttractorHeadingTarget) { + float fHeadingDistance = m_fRotationCur - m_attractorHeading; + float fSinHeading = Sin(fHeadingDistance); + float fCosHeading = Cos(fHeadingDistance); + if (fSinHeading > 0.0f) { + if (fCosHeading > 0.0f) + m_attractorHeading = m_fRotationCur - Asin(fSinHeading); + else + m_attractorHeading = m_fRotationCur - Acos(fCosHeading); + } + else { + if (fCosHeading > 0.0f) + m_attractorHeading = m_fRotationCur - Asin(fSinHeading); + else + m_attractorHeading = m_fRotationCur + Acos(fCosHeading); + } + m_fRotationDest = m_attractorHeading; + m_headingRate = 3.5f; + bReachedAttractorHeadingTarget = true; + bTurnedAroundOnAttractor = false; + } + if (Abs(m_fRotationCur - m_attractorHeading) >= m_acceptableHeadingOffset && + Abs(m_fRotationCur - m_attractorHeading + TWOPI) >= m_acceptableHeadingOffset && + Abs(m_fRotationCur - m_attractorHeading - TWOPI) >= m_acceptableHeadingOffset) + SetMoveState(PEDMOVE_STILL); + else { + m_fRotationDest = m_fRotationCur; + bReachedAttractorHeadingTarget = false; + bObjectiveCompleted = true; + bScriptObjectiveCompleted = true; + RestoreHeadingRate(); + GetPedAttractorManager()->BroadcastArrival(this, m_attractor); + if (GetPedAttractorManager()->IsAtHeadOfQueue(this, m_attractor)) { + switch (m_objective) { + case OBJECTIVE_GOTO_SEAT_ON_FOOT: + if (!bTurnedAroundOnAttractor) { + ClearObjective(); + SetWaitState(WAITSTATE_SIT_DOWN, 0); + } + else { + ClearObjective(); + SetWaitState(WAITSTATE_SIT_DOWN_RVRS, 0); + } + break; + case OBJECTIVE_GOTO_ATM_ON_FOOT: + ClearObjective(); + SetWaitState(WAITSTATE_USE_ATM, 0); + break; + case OBJECTIVE_GOTO_BUS_STOP_ON_FOOT: + ClearObjective(); + SetObjective(OBJECTIVE_WAIT_ON_FOOT_AT_BUS_STOP); + break; + case OBJECTIVE_GOTO_PIZZA_ON_FOOT: + ClearObjective(); + m_prevObjective = OBJECTIVE_NONE; + SetObjective(OBJECTIVE_WAIT_ON_FOOT); + m_objectiveTimer = CTimer::GetTimeInMilliseconds() + m_attractor->GetHeadOfQueueWaitTime(); + break; + case OBJECTIVE_GOTO_SHELTER_ON_FOOT: + m_prevObjective = OBJECTIVE_NONE; + SetObjective(OBJECTIVE_WAIT_ON_FOOT_AT_SHELTER); + break; + case OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT: + m_prevObjective = OBJECTIVE_NONE; + SetObjective(OBJECTIVE_WAIT_ON_FOOT_AT_ICE_CREAM_VAN); + break; + } + } + } + } + } + return; + case OBJECTIVE_WAIT_ON_FOOT_AT_SHELTER: + SetIdle(); + if (m_attractor && CWeather::Rain < 0.2f) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + break; + case OBJECTIVE_WAIT_ON_FOOT_AT_BUS_STOP: + SetIdle(); + if (m_attractor) { + float left = GetPosition().x - 10.0f; + float right = GetPosition().x + 10.0f; + float top = GetPosition().y - 10.0f; + float bottom = GetPosition().y + 10.0f; + int xstart = Max(0, CWorld::GetSectorIndexX(left)); + int xend = Min(NUMSECTORS_X - 1, CWorld::GetSectorIndexX(right)); + int ystart = Max(0, CWorld::GetSectorIndexY(top)); + int yend = Min(NUMSECTORS_Y - 1, CWorld::GetSectorIndexY(bottom)); + assert(xstart <= xend); + assert(ystart <= yend); + + float minDistance = SQR(10.0f); + CVehicle* pBus = nil; + + 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_VEHICLES].first; pNode != nil; pNode = pNode->next) { + CEntity* pEntity = (CEntity*)pNode->item; + if (!pEntity->IsVehicle()) + continue; + CVehicle* pVehicle = (CVehicle*)pEntity; + if (!pVehicle->bIsBus) + continue; + if (pVehicle->GetMoveSpeed().MagnitudeSqr() >= SQR(0.005f)) + continue; + float distanceSq = (GetPosition() - pVehicle->GetPosition()).MagnitudeSqr(); + if (distanceSq < minDistance) { + minDistance = distanceSq; + pBus = pVehicle; + } + } + } + } + + if (pBus) { + if (pBus->m_nNumPassengers >= pBus->m_nNumMaxPassengers - 1) + SetObjective(OBJECTIVE_WAIT_ON_FOOT); + else { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, pBus); + bDontDragMeOutCar = true; + b157_40 = true; + CPlayerPed *player = FindPlayerPed(); + if (pBus->IsPassenger(player) || pBus->IsDriver(player)) { + b158_10 = true; + } + } + } + } + break; + case OBJECTIVE_WAIT_ON_FOOT_AT_ICE_CREAM_VAN: + { + SetIdle(); + CVehicle* pIceCreamVan = GetPedAttractorManager()->GetIceCreamVanForEffect(m_attractor->GetEffect()); + if (m_attractor && m_nWaitState != WAITSTATE_PLAYANIM_CHAT && pIceCreamVan && pIceCreamVan->pDriver && pIceCreamVan->pDriver->IsPlayer()) { + int time = 5000; + SetWaitState(WAITSTATE_PLAYANIM_CHAT, &time); + break; + } + if (!m_attractor) + break; + CVehicle* pVan = GetPedAttractorManager()->GetIceCreamVanForEffect(m_attractor->GetEffect()); + if (!pVan) + break; + if (0.01f * CTimer::GetTimeStep() * 5.0f < pVan->m_fDistanceTravelled) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + break; + } + if (!pVan->pDriver || !pVan->pDriver->IsPlayer() || pVan->pDriver->GetPedState() == PED_ARRESTED || pVan->pDriver->GetPedState() == PED_DEAD) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + break; + } + if (!pVan->m_bSirenOrAlarm) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + return; // ??? + } + if (pVan->GetStatus() == STATUS_WRECKED) { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + return; // ??? + } + break; + } #endif } if (bObjectiveCompleted @@ -13737,16 +15234,15 @@ CPed::SetShootTimer(uint32 time) } } +// --MIAMI: Done void CPed::SetSeekCar(CVehicle *car, uint32 doorNode) { if (m_nPedState == PED_SEEK_CAR) return; -#ifdef VC_PED_PORTS if (!CanSetPedState() || m_nPedState == PED_DRIVING) return; -#endif SetStoredState(); m_pSeekTarget = car; @@ -13758,18 +15254,15 @@ CPed::SetSeekCar(CVehicle *car, uint32 doorNode) // m_pSeekTarget->RegisterReference((CEntity**) &m_pSeekTarget); m_vehEnterType = doorNode; m_distanceToCountSeekDone = 0.5f; - m_nPedState = PED_SEEK_CAR; + SetPedState(PED_SEEK_CAR); } +// --MIAMI: Done void CPed::SetSeekBoatPosition(CVehicle *boat) { - if (m_nPedState == PED_SEEK_IN_BOAT || boat->pDriver -#if defined VC_PED_PORTS || defined FIX_BUGS - || !IsPedInControl() -#endif - ) + if (m_nPedState == PED_SEEK_IN_BOAT || boat->pDriver || !IsPedInControl()) return; SetStoredState(); @@ -13778,9 +15271,10 @@ CPed::SetSeekBoatPosition(CVehicle *boat) m_pMyVehicle = boat; m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle); m_distanceToCountSeekDone = 0.5f; - m_nPedState = PED_SEEK_IN_BOAT; + SetPedState(PED_SEEK_IN_BOAT); } +#ifdef GTA_TRAIN void CPed::SetExitTrain(CVehicle* train) { @@ -13798,6 +15292,7 @@ CPed::SetExitTrain(CVehicle* train) bUsesCollision = false; LineUpPedWithTrain(); } +#endif #ifdef NEW_WALK_AROUND_ALGORITHM CVector @@ -13844,7 +15339,13 @@ CanWeSeeTheCorner(CVector2D dist, CVector2D fwdOffset) } #endif -// This function looks completely same on VC. +// --MIAMI: Done +bool +CPed::SetDirectionToWalkAroundVehicle(CVehicle* veh) +{ + return SetFollowPath(m_vecSeekPos, 0.0f, m_nMoveState, veh, m_pedInObjective, m_nMoveState == PEDMOVE_WALK ? 2000 : 250); +} + void CPed::SetDirectionToWalkAroundObject(CEntity *obj) { @@ -13865,13 +15366,11 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) if (m_nMoveState == PEDMOVE_NONE || m_nMoveState == PEDMOVE_STILL) return; -#ifndef PEDS_REPORT_CRIMES_ON_PHONE if (CharCreatedBy != MISSION_CHAR && obj->GetModelIndex() == MI_PHONEBOOTH1) { bool isRunning = m_nMoveState == PEDMOVE_RUN || m_nMoveState == PEDMOVE_SPRINT; SetFindPathAndFlee(obj, 5000, !isRunning); return; } -#endif CVector2D adjustedColMin(objColMin.x - 0.35f, objColMin.y - 0.35f); CVector2D adjustedColMax(objColMax.x + 0.35f, objColMax.y + 0.35f); @@ -14441,10 +15940,10 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) if (CCollision::IsStoredPolyStillValidVerticalLine(pos, potentialGroundZ, intersectionPoint, &m_collPoly)) { bStillOnValidPoly = true; #ifdef VC_PED_PORTS - if(!bSomeVCflag1 || FEET_OFFSET + intersectionPoint.point.z < GetPosition().z) { + if(!bHeadStuckInCollision || FEET_OFFSET + intersectionPoint.point.z < GetPosition().z) { GetMatrix().GetPosition().z = FEET_OFFSET + intersectionPoint.point.z; - if (bSomeVCflag1) - bSomeVCflag1 = false; + if (bHeadStuckInCollision) + bHeadStuckInCollision = false; } #else GetMatrix().GetPosition().z = FEET_OFFSET + intersectionPoint.point.z; @@ -14484,13 +15983,13 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) } float minDist = 1.0f; belowTorsoCollided = CCollision::ProcessVerticalLine(ourLine, collidingEnt->GetMatrix(), *hisCol, - intersectionPoint, minDist, false, &m_collPoly); + intersectionPoint, minDist, false, false, &m_collPoly); if (collidedWithBoat && bWasStanding && !belowTorsoCollided) { ourLine.p0.z = ourLine.p1.z; ourLine.p1.z = ourLine.p1.z + gravityEffect; belowTorsoCollided = CCollision::ProcessVerticalLine(ourLine, collidingEnt->GetMatrix(), *hisCol, - intersectionPoint, minDist, false, &m_collPoly); + intersectionPoint, minDist, false, false, &m_collPoly); } if (belowTorsoCollided) { #ifndef VC_PED_PORTS @@ -14519,13 +16018,13 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) } } #ifdef VC_PED_PORTS - if (!bSomeVCflag1 || FEET_OFFSET + intersectionPoint.point.z < GetPosition().z) { + if (!bHeadStuckInCollision || FEET_OFFSET + intersectionPoint.point.z < GetPosition().z) { GetMatrix().GetPosition().z = FEET_OFFSET + intersectionPoint.point.z; - if (bSomeVCflag1) - bSomeVCflag1 = false; + if (bHeadStuckInCollision) + bHeadStuckInCollision = false; } #else - GetMatrix().GetPosition().z = FEET_OFFSET + intersectionPoint.point.z; + GetMatrix().GetPosition().z = FEET_OFFSET + intersectionPoint.point.z; #endif m_nSurfaceTouched = intersectionPoint.surfaceB; if (m_nSurfaceTouched == SURFACE_STEEP_CLIFF) { @@ -14533,7 +16032,7 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) m_vecDamageNormal = intersectionPoint.normal; } } -#ifdef VC_PED_PORTS + float upperSpeedLimit = 0.33f; float lowerSpeedLimit = -0.25f; float speed = m_vecMoveSpeed.Magnitude2D(); @@ -14564,27 +16063,6 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) Say(SOUND_PED_LAND); } } -#else - float speedSqr = 0.0f; - if (!bWasStanding) { - if (m_vecMoveSpeed.z >= -0.25f && (speedSqr = m_vecMoveSpeed.MagnitudeSqr()) <= sq(0.5f)) { - - if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FALL) && -0.016f * CTimer::GetTimeStep() > m_vecMoveSpeed.z) { - InflictDamage(collidingEnt, WEAPONTYPE_FALL, 15.0f, PEDPIECE_TORSO, 2); - } - } else { - if (speedSqr == 0.0f) - speedSqr = sq(m_vecMoveSpeed.z); - - uint8 dir = 2; // from backward - if (m_vecMoveSpeed.x > 0.01f || m_vecMoveSpeed.x < -0.01f || m_vecMoveSpeed.y > 0.01f || m_vecMoveSpeed.y < -0.01f) { - CVector2D offset = -m_vecMoveSpeed; - dir = GetLocalDirection(offset); - } - InflictDamage(collidingEnt, WEAPONTYPE_FALL, 350.0f * sq(speedSqr), PEDPIECE_TORSO, dir); - } - } -#endif m_vecMoveSpeed.z = 0.0f; bIsStanding = true; #ifndef VC_PED_PORTS @@ -14630,7 +16108,7 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) sphereNormal.x = -m_vecMoveSpeed.x / Max(0.001f, speed); sphereNormal.y = -m_vecMoveSpeed.y / Max(0.001f, speed); GetMatrix().GetPosition().z -= 0.05f; - bSomeVCflag1 = true; + bHeadStuckInCollision = true; } #endif sphereNormal.Normalise(); @@ -14692,6 +16170,7 @@ CPed::WanderRange(void) } } +// --MIAMI: Done bool CPed::WillChat(CPed *stranger) { @@ -14708,11 +16187,16 @@ CPed::WillChat(CPed *stranger) return true; if (m_nPedType == PEDTYPE_CRIMINAL) return false; + if (stranger->m_nPedType == PEDTYPE_COP) + return false; + if (stranger->IsPlayer()) + return false; if ((IsGangMember() || stranger->IsGangMember()) && m_nPedType != stranger->m_nPedType) return false; return true; } +#ifdef GTA_TRAIN void CPed::SetEnterTrain(CVehicle *train, uint32 unused) { @@ -14738,20 +16222,24 @@ CPed::SetEnterTrain(CVehicle *train, uint32 unused) ((CPlayerPed*)this)->ClearAdrenaline(); } } +#endif +// --MIAMI: Done, but what is this parameter for? void -CPed::SetDuck(uint32 time) +CPed::SetDuck(uint32 time, bool sth) { - if (bIsDucking || CTimer::GetTimeInMilliseconds() <= m_duckTimer) + if (bIsDucking || CTimer::GetTimeInMilliseconds() <= m_duckTimer && !sth) { + if (sth && CTimer::GetTimeInMilliseconds() + time > m_duckTimer) + m_duckTimer = CTimer::GetTimeInMilliseconds() + time; return; + } - if (bCrouchWhenShooting && (m_nPedState == PED_ATTACK || m_nPedState == PED_AIM_GUN)) { - CAnimBlendAssociation *duckAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_LOW); - if (!duckAssoc || duckAssoc->blendDelta < 0.0f) { - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_DUCK_LOW, 4.0f); - bIsDucking = true; - m_duckTimer = CTimer::GetTimeInMilliseconds() + time; - } + CAnimBlendAssociation *duckAssoc; + if (bCrouchWhenShooting) { + duckAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_WEAPON_CROUCH, 4.0f); + duckAssoc->flags &= ~ASSOC_FADEOUTWHENDONE; + bIsDucking = true; + m_duckTimer = CTimer::GetTimeInMilliseconds() + time; } else { CAnimBlendAssociation *duckAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN); if (!duckAssoc || duckAssoc->blendDelta < 0.0f) { @@ -14762,6 +16250,7 @@ CPed::SetDuck(uint32 time) } } +// --MIAMI: Done void CPed::SeekBoatPosition(void) { @@ -14783,6 +16272,7 @@ CPed::SeekBoatPosition(void) RestorePreviousState(); } +// --MIAMI: Done void CPed::SetEnterCar(CVehicle *car, uint32 unused) { @@ -14792,26 +16282,62 @@ CPed::SetEnterCar(CVehicle *car, uint32 unused) } else { uint8 doorFlag; eDoors door; - switch (m_vehEnterType) { - case CAR_DOOR_RF: - doorFlag = CAR_DOOR_FLAG_RF; - door = DOOR_FRONT_RIGHT; - break; - case CAR_DOOR_RR: - doorFlag = CAR_DOOR_FLAG_RR; - door = DOOR_REAR_RIGHT; - break; - case CAR_DOOR_LF: - doorFlag = CAR_DOOR_FLAG_LF; - door = DOOR_FRONT_LEFT; - break; - case CAR_DOOR_LR: - doorFlag = CAR_DOOR_FLAG_LR; - door = DOOR_REAR_LEFT; - break; - default: - doorFlag = CAR_DOOR_FLAG_UNKNOWN; - break; + if (car->IsBike()) { + switch (m_vehEnterType) { + case CAR_DOOR_RF: + doorFlag = CAR_DOOR_FLAG_RF | CAR_DOOR_FLAG_LF; + door = DOOR_FRONT_RIGHT; + break; + case CAR_DOOR_RR: + doorFlag = CAR_DOOR_FLAG_RR | CAR_DOOR_FLAG_LR; + door = DOOR_REAR_RIGHT; + break; + case CAR_WING_LF: + case CAR_WING_LR: + case CAR_BONNET: + case CAR_BOOT: + doorFlag = CAR_DOOR_FLAG_UNKNOWN; + break; + case CAR_DOOR_LF: + case CAR_WINDSCREEN: + doorFlag = CAR_DOOR_FLAG_RF | CAR_DOOR_FLAG_LF; + door = DOOR_FRONT_LEFT; + break; + case CAR_DOOR_LR: + doorFlag = CAR_DOOR_FLAG_RR | CAR_DOOR_FLAG_LR; + door = DOOR_REAR_LEFT; + break; + } + } else { + switch (m_vehEnterType) { + case CAR_DOOR_RF: + doorFlag = CAR_DOOR_FLAG_RF; + door = DOOR_FRONT_RIGHT; + break; + case CAR_DOOR_RR: + doorFlag = CAR_DOOR_FLAG_RR; + door = DOOR_REAR_RIGHT; + break; + case CAR_DOOR_LF: + if(car->m_nNumMaxPassengers != 0) + doorFlag = CAR_DOOR_FLAG_LF; + else + doorFlag = CAR_DOOR_FLAG_LF | CAR_DOOR_FLAG_LR; + + door = DOOR_FRONT_LEFT; + break; + case CAR_DOOR_LR: + if (car->m_nNumMaxPassengers != 0) + doorFlag = CAR_DOOR_FLAG_LR; + else + doorFlag = CAR_DOOR_FLAG_LF | CAR_DOOR_FLAG_LR; + + door = DOOR_REAR_LEFT; + break; + default: + doorFlag = CAR_DOOR_FLAG_UNKNOWN; + break; + } } if (!IsPedInControl() || m_fHealth <= 0.0f || doorFlag & car->m_nGettingInFlags || doorFlag & car->m_nGettingOutFlags @@ -14826,17 +16352,18 @@ CPed::SetEnterCar(CVehicle *car, uint32 unused) void CPed::SetRadioStation(void) { + // TODO: this should be gone static const uint8 radiosPerRadioCategories[10][4] = { - {JAH_RADIO, RISE_FM, GAME_FM, MSX_FM}, - {HEAD_RADIO, DOUBLE_CLEF, LIPS_106, FLASHBACK}, - {RISE_FM, GAME_FM, MSX_FM, FLASHBACK}, - {HEAD_RADIO, RISE_FM, LIPS_106, MSX_FM}, - {HEAD_RADIO, RISE_FM, MSX_FM, FLASHBACK}, - {JAH_RADIO, RISE_FM, LIPS_106, FLASHBACK}, - {HEAD_RADIO, RISE_FM, LIPS_106, FLASHBACK}, - {HEAD_RADIO, JAH_RADIO, LIPS_106, FLASHBACK}, - {HEAD_RADIO, DOUBLE_CLEF, LIPS_106, FLASHBACK}, - {CHATTERBOX, HEAD_RADIO, LIPS_106, GAME_FM} + {KCHAT, FEVER, VCPR, RADIO_ESPANTOSO}, + {WILDSTYLE, FLASH_FM, V_ROCK, EMOTION}, + {FEVER, VCPR, RADIO_ESPANTOSO, EMOTION}, + {WILDSTYLE, FEVER, V_ROCK, RADIO_ESPANTOSO}, + {WILDSTYLE, FEVER, RADIO_ESPANTOSO, EMOTION}, + {KCHAT, FEVER, V_ROCK, EMOTION}, + {WILDSTYLE, FEVER, V_ROCK, EMOTION}, + {WILDSTYLE, KCHAT, V_ROCK, EMOTION}, + {WILDSTYLE, FLASH_FM, V_ROCK, EMOTION}, + {WAVE, WILDSTYLE, V_ROCK, VCPR} }; uint8 orderInCat = 0; // BUG: this wasn't initialized @@ -14900,6 +16427,77 @@ CPed::PreRender(void) } #endif + bool bIsWindModifierTurnedOn = false; + float fAnyDirectionShift = 1.0f; + if (IsPlayer() && CWindModifiers::FindWindModifier(GetPosition(), &fAnyDirectionShift, &fAnyDirectionShift) + && !CCullZones::PlayerNoRain() && GetPedState() != PED_DRIVING) + bIsWindModifierTurnedOn = true; + + bool bIsPedDrivingBikeOrOpenTopCar = false; + if (GetPedState() == PED_DRIVING && m_pMyVehicle) { + if (m_pMyVehicle->m_vehType == VEHICLE_TYPE_BIKE + || (m_pMyVehicle->m_vehType == VEHICLE_TYPE_CAR && m_pMyVehicle->IsOpenTopCar())) + bIsPedDrivingBikeOrOpenTopCar = true; + } + + if (bIsWindModifierTurnedOn || bIsPedDrivingBikeOrOpenTopCar) { + float fWindMult = 0.0f; + if (bIsPedDrivingBikeOrOpenTopCar) { + fWindMult = DotProduct(m_pMyVehicle->m_vecMoveSpeed, GetForward()); + if (fWindMult > 0.4f) { + float volume = (fWindMult - 0.4f) / 0.6f; + DMAudio.PlayOneShot(m_audioEntityId, SOUND_SET_202, volume); //TODO(MIAMI): revise when audio is done + } + } + + if (bIsWindModifierTurnedOn) + fWindMult = Min(fWindMult, Abs(fAnyDirectionShift - 1.0f)); + + RpHAnimHierarchy* hier = GetAnimHierarchyFromSkinClump(GetClump()); + int32 idx; + RwV3d scale; + float fScaleOffset; + + fScaleOffset = fWindMult * 0.2f; + scale.x = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + scale.y = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + scale.z = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + + idx = RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(PED_NECK)); + RwMatrix* neck = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; + RwMatrixScale(neck, &scale, rwCOMBINEPRECONCAT); + + fScaleOffset = fWindMult * 0.1f; + scale.x = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + scale.y = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + scale.z = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + + idx = RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(PED_CLAVICLEL)); + RwMatrix* clavicleL = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; + RwMatrixScale(clavicleL, &scale, rwCOMBINEPRECONCAT); + + idx = RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(PED_CLAVICLER)); + RwMatrix* clavicleR = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; + RwMatrixScale(clavicleR, &scale, rwCOMBINEPRECONCAT); + + idx = RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(PED_MID)); + RwMatrix* mid = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; + RwMatrixScale(mid, &scale, rwCOMBINEPRECONCAT); + + fScaleOffset = fWindMult * 0.2f; + scale.x = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + scale.y = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + scale.z = CGeneral::GetRandomNumberInRange(1.0f - fScaleOffset, 1.0f + fScaleOffset); + + idx = RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(PED_UPPERARML)); + RwMatrix* upperArmL = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; + RwMatrixScale(upperArmL, &scale, rwCOMBINEPRECONCAT); + + idx = RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(PED_UPPERARMR)); + RwMatrix* upperArmR = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; + RwMatrixScale(upperArmR, &scale, rwCOMBINEPRECONCAT); + } + if (bBodyPartJustCameOff && bIsPedDieAnimPlaying && m_bodyPartBleeding != -1 && (CTimer::GetFrameCounter() & 7) > 3) { CVector bloodDir(0.0f, 0.0f, 0.0f); CVector bloodPos(0.0f, 0.0f, 0.0f); @@ -15035,6 +16633,7 @@ CPed::ProcessBuoyancy(void) m_vecMoveSpeed.y *= speedMult; m_vecMoveSpeed.z *= speedMult; bIsStanding = false; + bIsDrowning = true; InflictDamage(nil, WEAPONTYPE_DROWNING, 3.0f * CTimer::GetTimeStep(), PEDPIECE_TORSO, 0); } if (buoyancyImpulse.z / m_fMass > 0.002f * CTimer::GetTimeStep()) { @@ -15146,35 +16745,519 @@ CPed::SetSolicit(uint32 time) } } +// --MIAMI: Done bool -CPed::SetFollowPath(CVector dest) +CPed::SetFollowPathStatic(void) { - if (m_nPedState == PED_FOLLOW_PATH) - return false; + ClearFollowPath(); + if (sq(m_followPathAbortDist) > (GetPosition() - m_followPathDestPos).MagnitudeSqr() + && CWorld::IsWanderPathClear(GetPosition(), m_followPathDestPos, 0.5f, 4)) { - if (FindPlayerPed() != this) - return false; + RestorePreviousState(); + if (m_objective == OBJECTIVE_NONE) { + if (m_followPathMoveState == PEDMOVE_RUN) + SetObjective(OBJECTIVE_RUN_TO_AREA, m_followPathDestPos); + else + SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, m_followPathDestPos); + } + SetPedState(PED_NONE); + return true; + } else { + ThePaths.DoPathSearch(PATH_PED, GetPosition(), -1, m_followPathDestPos, m_pathNodesToGo, &m_nNumPathNodes, + ARRAY_SIZE(m_pathNodesToGo), nil, nil, 999999.9f, -1); - if ((dest - GetPosition()).Magnitude() <= 2.0f) - return false; + if (m_nNumPathNodes != 0) { + if (m_nNumPathNodes > 0 && m_pathNodesToGo[0] != m_pCurPathNode) { + for (int i = 0; i < ARRAY_SIZE(m_pathNodesToGo) - 1; i++) { + m_pathNodesToGo[i] = m_pathNodesToGo[i+1]; + } + --m_nNumPathNodes; + } + for (int i = 0; i < m_nNumPathNodes; ++i) { + CVector nodePos = m_pathNodesToGo[i]->GetPosition(); + if (sq(m_followPathAbortDist) > (nodePos - m_followPathDestPos).MagnitudeSqr() + && CWorld::IsWanderPathClear(nodePos, m_followPathDestPos, 0.5f, 4)) { + + m_nNumPathNodes = i + 1; + break; + } + } + + m_nCurPathNodeId = 0; + if (m_pCurPathNode) { + for (int j = 0; j < m_nNumPathNodes; ++j) { + if (m_pathNodesToGo[j] == m_pCurPathNode) { + m_nCurPathNodeId = j; + break; + } + } + } + m_pCurPathNode = m_pathNodesToGo[m_nCurPathNodeId]; + PedState oldLastState = m_nLastPedState; + m_nLastPedState = PED_NONE; + SetStoredState(); + if (m_nLastPedState == PED_NONE) + m_nLastPedState = oldLastState; + + m_nPedState = PED_FOLLOW_PATH; + m_nMoveState = m_followPathMoveState; + return true; + } else { + RestorePreviousState(); + if (m_objective == OBJECTIVE_NONE) { + if (m_followPathMoveState == PEDMOVE_RUN) + SetObjective(OBJECTIVE_RUN_TO_AREA, m_followPathDestPos); + else + SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, m_followPathDestPos); + } + SetPedState(PED_NONE); + return true; + } + } +} + +// --MIAMI: Done +bool +CPed::SetFollowPath(CVector dest, float radius, eMoveState state, CEntity* walkAroundEnt, CEntity* targetEnt, int time) +{ + if (m_nPedState == PED_FOLLOW_PATH) { + bool stopFollow = false; + if (walkAroundEnt && walkAroundEnt != m_followPathWalkAroundEnt || !walkAroundEnt && m_followPathWalkAroundEnt + || targetEnt && targetEnt != m_followPathTargetEnt || !targetEnt && m_followPathTargetEnt) { + stopFollow = true; + + } else if (targetEnt) { + if ((targetEnt->GetPosition() - m_followPathDestPos).MagnitudeSqr() > 1.f) + stopFollow = true; + + } else if (!walkAroundEnt && !targetEnt) { + if ((dest - m_followPathDestPos).MagnitudeSqr() > 1.f) + stopFollow = true; + } - CVector pointPoses[7]; - int16 pointsFound; - CPedPath::CalcPedRoute(0, GetPosition(), dest, pointPoses, &pointsFound, 7); - for(int i = 0; i < pointsFound; i++) { - m_stPathNodeStates[i].x = pointPoses[i].x; - m_stPathNodeStates[i].y = pointPoses[i].y; + if (!stopFollow) + return false; } + m_pathNodeTimer = CTimer::GetTimeInMilliseconds() + time; + m_followPathWalkAroundEnt = walkAroundEnt; + m_followPathTargetEnt = targetEnt; + m_distanceToCountSeekDone = 0.5f; - m_nCurPathNode = 0; - m_nPathNodes = pointsFound; - if (m_nPathNodes < 1) - return false; + bool weHaveTargetPed = targetEnt && targetEnt->IsPed(); + bool useDestVec = !weHaveTargetPed; - SetStoredState(); - m_nPedState = PED_FOLLOW_PATH; - SetMoveState(PEDMOVE_WALK); - return true; + CVector targetPos; + if (useDestVec) + targetPos = dest; + else + targetPos = targetEnt->GetPosition(); + + m_followPathDestPos = targetPos; + if (targetEnt && m_nPedState == PED_SEEK_POS) { + m_followPathDestPos = m_vecSeekPos; + } + + float newRadius = radius > 0.f ? radius : 20.f; + bool useGivenPedMove = true; + + m_followPathAbortDist = newRadius; + + if (state != PEDMOVE_RUN && state != PEDMOVE_WALK) + useGivenPedMove = false; + + if (useGivenPedMove) + m_followPathMoveState = state; + else + m_followPathMoveState = PEDMOVE_WALK; + + if (m_followPathWalkAroundEnt) + return SetFollowPathDynamic(); + else + return SetFollowPathStatic(); +} + +// --MIAMI: Done +bool +CPed::SetFollowPathDynamic(void) +{ + CVector colBoxMin = m_followPathWalkAroundEnt->GetColModel()->boundingBox.min + CVector(-0.35f, -0.35f, 0.f); + CVector colBoxMax = m_followPathWalkAroundEnt->GetColModel()->boundingBox.max + CVector(0.35f, 0.35f, 0.f); + + CVector colCornerOffsets[4]; // BL, BR, TR, TL + colCornerOffsets[0] = CVector(colBoxMin.x, colBoxMin.y, 0.f); + colCornerOffsets[1] = CVector(colBoxMax.x, colBoxMin.y, 0.f); + colCornerOffsets[2] = CVector(colBoxMax.x, colBoxMax.y, 0.f); + colCornerOffsets[3] = CVector(colBoxMin.x, colBoxMax.y, 0.f); + + if (m_followPathWalkAroundEnt->IsVehicle() && ((CVehicle*)m_followPathWalkAroundEnt)->IsUpsideDown()) { + CVector old0 = colCornerOffsets[0]; + colCornerOffsets[0] = colCornerOffsets[1]; + colCornerOffsets[1] = old0; + CVector old2 = colCornerOffsets[2]; + colCornerOffsets[2] = colCornerOffsets[3]; + colCornerOffsets[3] = old2; + } + + CVector colCornerPos[4]; // global. again BL, BR, TR, TL + float dotProdCorrection[4]; + CVector colBoxPlaneNormal[4]; + + for (int i=0; i<4; i++) { + colCornerPos[i] = m_followPathWalkAroundEnt->GetMatrix() * colCornerOffsets[i]; + colCornerPos[i].z = GetPosition().z; + } + + CVector prevColCorner = colCornerPos[3]; // top left + CVector *curCornerPos; + CVector fwdToNextCorner; + + for (int i=0; i<4; i++) { + curCornerPos = &colCornerPos[i]; + fwdToNextCorner = *curCornerPos - prevColCorner; + fwdToNextCorner.Normalise(); + colBoxPlaneNormal[i] = CrossProduct(fwdToNextCorner, CVector(0.f, 0.f, 1.f)); + dotProdCorrection[i] = -DotProduct(prevColCorner, colBoxPlaneNormal[i]); // yes, dp with global coord, as if in distance to plane calculation + prevColCorner = *curCornerPos; + } + + bool weReGoingGreat = false; + CVector startVecCandidate = GetPosition(); + CVector targetVecCandidate = m_followPathDestPos; + CVector dirToGo = targetVecCandidate - startVecCandidate; + dirToGo.Normalise(); + CVector ourPos = startVecCandidate; + + for (int i=0; i<4; i++) { + CVector curPlaneNormal = colBoxPlaneNormal[i]; + float minusGlobalCornerPos = dotProdCorrection[i]; + float startVecDistToPlane = DotProduct(curPlaneNormal, startVecCandidate) + minusGlobalCornerPos; + +#define FRONT_OF_PLANE 1 +#define ON_THE_PLANE 0 +#define BEHIND_THE_PLANE -1 + + int8 startVecStatus; + int8 targetVecStatus; + + if (startVecDistToPlane > 0.1f) + startVecStatus = FRONT_OF_PLANE; + else if (startVecDistToPlane < -0.1f) + startVecStatus = BEHIND_THE_PLANE; + else + startVecStatus = ON_THE_PLANE; + + float targetVecDistToPlane = DotProduct(curPlaneNormal, targetVecCandidate) + minusGlobalCornerPos; + if (targetVecDistToPlane > 0.1f) + targetVecStatus = FRONT_OF_PLANE; + else if (targetVecDistToPlane < -0.1f) + targetVecStatus = BEHIND_THE_PLANE; + else + targetVecStatus = ON_THE_PLANE; + + + if (startVecStatus == BEHIND_THE_PLANE || targetVecStatus == BEHIND_THE_PLANE) { + if (startVecStatus == BEHIND_THE_PLANE && targetVecStatus == FRONT_OF_PLANE) { + targetVecCandidate = -(DotProduct(ourPos, curPlaneNormal) + minusGlobalCornerPos) / DotProduct(dirToGo, curPlaneNormal) * dirToGo + ourPos; + + } else if (startVecStatus == FRONT_OF_PLANE && targetVecStatus == BEHIND_THE_PLANE) { + startVecCandidate = -(DotProduct(ourPos, curPlaneNormal) + minusGlobalCornerPos) / DotProduct(dirToGo, curPlaneNormal) * dirToGo + ourPos; + } + } else { + weReGoingGreat = true; + if (startVecStatus == ON_THE_PLANE) + startVecCandidate += (0.1f - startVecDistToPlane) * curPlaneNormal; + + if (targetVecStatus == ON_THE_PLANE) + targetVecCandidate += (0.1f - targetVecDistToPlane) * curPlaneNormal; + } +#undef FRONT_OF_PLANE +#undef ON_THE_PLANE +#undef BEHIND_THE_PLANE + } + + if (!weReGoingGreat) { + CVector avgOfColPoints = (colCornerPos[0] + colCornerPos[1] + colCornerPos[2] + colCornerPos[3]) / 4.f; + float radius = 0.0f; + + // Find radius of col box of the entity we follow + for (int i=0; i<4; i++) { + float cornerDist = (colCornerPos[i] - avgOfColPoints).MagnitudeSqr(); + + if (cornerDist > radius) + radius = cornerDist; + } + CColSphere followedEntSphere; + followedEntSphere.Set(Sqrt(radius) * 1.1f, avgOfColPoints, 0, 0); + CVector distToDest = m_followPathDestPos - GetPosition(); + distToDest.z = 0.f; + + if (distToDest.Magnitude() == 0.0f) + return false; + + distToDest.Normalise(); + + // Entity we follow doesn't go toward destination anymore, abort the following. + if (!followedEntSphere.IntersectRay(GetPosition(), distToDest, startVecCandidate, targetVecCandidate)) { + m_pathNodeTimer = 0; + if (m_nPedState == PED_FOLLOW_PATH) + RestorePreviousState(); + + return false; + } + } + + int lastPlaneBehindUs = -1; + int lastPlaneInFrontOfUs = -1; + CVector oldstartVecCandidate = startVecCandidate; + CVector oldDirToGo = targetVecCandidate - startVecCandidate; + oldDirToGo.Normalise(); + + + // At least one plane should be between target and us. + for (int i=0; i<4; i++) { + CVector curPlaneNormal = colBoxPlaneNormal[i]; + float minusGlobalCornerPos = dotProdCorrection[i]; + float startVecDistToPlane = DotProduct(curPlaneNormal, startVecCandidate) + minusGlobalCornerPos; + float targetVecDistToPlane = DotProduct(curPlaneNormal, targetVecCandidate) + minusGlobalCornerPos; + + if (startVecDistToPlane > 0.0f && targetVecDistToPlane < 0.0f) { + lastPlaneInFrontOfUs = i; + startVecCandidate = -(DotProduct(oldstartVecCandidate, curPlaneNormal) + minusGlobalCornerPos) / DotProduct(oldDirToGo, curPlaneNormal) * oldDirToGo + oldstartVecCandidate; + + } else if (startVecDistToPlane < 0.0f && targetVecDistToPlane > 0.0f) { + lastPlaneBehindUs = i; + targetVecCandidate = -(DotProduct(oldstartVecCandidate, curPlaneNormal) + minusGlobalCornerPos) / DotProduct(oldDirToGo, curPlaneNormal) * oldDirToGo + oldstartVecCandidate; + } + } + + CVector destsVariant1[5]; + CVector destsVariant2[5]; + + // If not, followed entity diverged from route and we should abort the following. + if (lastPlaneBehindUs >= 0 && lastPlaneInFrontOfUs >= 0) { + + int planeInFrontCircular = (lastPlaneInFrontOfUs + 4) % -4; + int planeInFrontCircularMinusOne = (lastPlaneInFrontOfUs + 3) % -4; + int planeInBehindCircular = (lastPlaneBehindUs + 4) % -4; + int planeInBehindCircularMinusOne = (lastPlaneBehindUs + 3) % -4; + + destsVariant1[0] = GetPosition(); + destsVariant1[1] = colCornerPos[planeInFrontCircularMinusOne]; + + int destsVar1LastNode = 2; + for(; planeInFrontCircularMinusOne != planeInBehindCircular; destsVar1LastNode++) { + planeInFrontCircularMinusOne = (planeInFrontCircularMinusOne + 3) % -4; + destsVariant1[destsVar1LastNode] = colCornerPos[planeInFrontCircularMinusOne]; + } + destsVariant1[destsVar1LastNode] = m_followPathDestPos; + + destsVariant2[0] = GetPosition(); + destsVariant2[1] = colCornerPos[planeInFrontCircular]; + + int destsVar2LastNode = 2; + for (; planeInFrontCircular != planeInBehindCircularMinusOne; destsVar2LastNode++) { + planeInFrontCircular = (planeInFrontCircular + 5) % -4; + destsVariant2[destsVar2LastNode] = colCornerPos[planeInFrontCircular]; + } + destsVariant2[destsVar2LastNode] = m_followPathDestPos; + CEntity *foundEnt1 = nil; + int dests1isOk = true; + int nodeToStopDestsVar1 = destsVar1LastNode + 1; + CVector avgOfColPoints2 = (colCornerPos[0] + colCornerPos[1] + colCornerPos[2] + colCornerPos[3]) / 4.f; + + CVector prevDestVar1 = destsVariant1[0]; + + for (int i = 1; i < destsVar1LastNode + 1; i++) { + CVector *curDestVar1 = &destsVariant1[i]; + + CVector routeNormalHalf = *curDestVar1 - prevDestVar1; + routeNormalHalf.z = 0.f; + routeNormalHalf.Normalise(); + routeNormalHalf *= 0.5f; + + float oldX = -routeNormalHalf.x; + routeNormalHalf.z = 0.0f; + routeNormalHalf.x = routeNormalHalf.y; + routeNormalHalf.y = oldX; + + if (DotProduct(*curDestVar1 - avgOfColPoints2, routeNormalHalf) < 0.0f) + routeNormalHalf *= -1.f; + + CColPoint foundCol; + bool foundObstacle = CWorld::ProcessLineOfSight(prevDestVar1, *curDestVar1, foundCol, foundEnt1, + true, true, true, true, false, false, false, false); + + if (!foundObstacle) + foundObstacle = CWorld::ProcessLineOfSight(prevDestVar1 + routeNormalHalf, *curDestVar1 + routeNormalHalf, foundCol, foundEnt1, true, true, true, true, false, false, false, false); + + if (foundObstacle) { + if (foundEnt1 == m_followPathWalkAroundEnt || foundEnt1 == this || foundEnt1 == m_pSeekTarget) { + foundEnt1 = nil; + + } else { + if (!foundEnt1->IsPed()) { + dests1isOk = false; + nodeToStopDestsVar1 = i; + break; + } + if (((CPed*)foundEnt1)->m_nPedState == PED_IDLE) { + dests1isOk = false; + nodeToStopDestsVar1 = i; + break; + } + if (DotProduct(*curDestVar1 - prevDestVar1, foundEnt1->GetForward()) < 0.f) { + dests1isOk = false; + nodeToStopDestsVar1 = i; + break; + } + if (((CPed*)foundEnt1)->m_pedInObjective == this) { + dests1isOk = false; + nodeToStopDestsVar1 = i; + break; + } + } + } + prevDestVar1 = *curDestVar1; + } + CEntity *foundEnt2 = nil; + int dests2isOk = true; + int nodeToStopDestsVar2 = destsVar2LastNode + 1; + + CVector prevDestVar2 = destsVariant2[0]; + + for (int i = 1; i < destsVar2LastNode + 1; i++) { + CVector *curDestVar2 = &destsVariant2[i]; + + CVector routeNormalHalf = *curDestVar2 - prevDestVar2; + routeNormalHalf.z = 0.f; + routeNormalHalf.Normalise(); + routeNormalHalf *= 0.5f; + + float oldX = -routeNormalHalf.x; + routeNormalHalf.z = 0.0f; + routeNormalHalf.x = routeNormalHalf.y; + routeNormalHalf.y = oldX; + + if (DotProduct(*curDestVar2 - avgOfColPoints2, routeNormalHalf) < 0.0f) + routeNormalHalf *= -1.f; + + CColPoint foundCol; + bool foundObstacle = CWorld::ProcessLineOfSight(prevDestVar2, *curDestVar2, foundCol, foundEnt2, + true, true, true, true, false, false, false, false); + + if (!foundObstacle) + foundObstacle = CWorld::ProcessLineOfSight(prevDestVar2 + routeNormalHalf, *curDestVar2 + routeNormalHalf, foundCol, foundEnt2, true, true, true, true, false, false, false, false); + + if (foundObstacle) { + if (foundEnt2 == m_followPathWalkAroundEnt || foundEnt2 == this || foundEnt2 == m_pSeekTarget) { + foundEnt2 = 0; + } else { + if (!foundEnt2->IsPed()) { + dests2isOk = false; + nodeToStopDestsVar2 = i; + break; + } + if (((CPed*)foundEnt2)->m_nPedState == PED_IDLE) { + dests2isOk = false; + nodeToStopDestsVar2 = i; + break; + } + if (DotProduct(*curDestVar2 - prevDestVar2, foundEnt2->GetForward()) < 0.f) { + dests2isOk = false; + nodeToStopDestsVar2 = i; + break; + } + if (((CPed*)foundEnt2)->m_pedInObjective == this) { + dests2isOk = false; + nodeToStopDestsVar2 = i; + break; + } + } + } + prevDestVar2 = *curDestVar2; + } + + float destTotalLengthVar1 = 0.0f; + for(int i=0; i < destsVar1LastNode; i++){ + destTotalLengthVar1 += (destsVariant1[i + 1] - destsVariant1[i]).Magnitude(); + } + + float destTotalLengthVar2 = 0.0f; + for (int i = 0; i < destsVar2LastNode; i++) { + destTotalLengthVar2 += (destsVariant2[i + 1] - destsVariant2[i]).Magnitude(); + } + + int destVariantToUse; + if (dests1isOk && dests2isOk) { + if (destTotalLengthVar1 < destTotalLengthVar2) + destVariantToUse = 1; + else + destVariantToUse = 2; + + } else if (dests1isOk) { + destVariantToUse = 1; + + } else if (dests2isOk) { + destVariantToUse = 2; + + } else if (nodeToStopDestsVar1 == 1 && nodeToStopDestsVar2 > 1) { + destVariantToUse = 2; + + } else if (nodeToStopDestsVar1 > 1 && nodeToStopDestsVar2 == 1) { + destVariantToUse = 1; + + } else if (foundEnt1 == foundEnt2) { + if (destTotalLengthVar1 < destTotalLengthVar2) + destVariantToUse = 1; + else + destVariantToUse = 2; + + } else if (foundEnt1->GetColModel()->boundingSphere.radius >= foundEnt2->GetColModel()->boundingSphere.radius) { + destVariantToUse = 2; + } else { + destVariantToUse = 1; + } + + if (destVariantToUse == 1) { + ClearFollowPath(); + for (int i = 1; i < destsVar1LastNode; i++) { + CPathNode* nextNode = &m_pathNodeObjPool[m_nNumPathNodes]; + nextNode->SetPosition(destsVariant1[i]); + m_pathNodesToGo[m_nNumPathNodes++] = nextNode; + } + } else if (destVariantToUse == 2) { + ClearFollowPath(); + for (int i = 1; i < destsVar2LastNode; i++) { + CPathNode *nextNode = &m_pathNodeObjPool[m_nNumPathNodes]; + nextNode->SetPosition(destsVariant2[i]); + m_pathNodesToGo[m_nNumPathNodes++] = nextNode; + } + } + if (m_nNumPathNodes != 0) { + PedState oldLastState = m_nLastPedState; + m_nLastPedState = PED_NONE; + SetStoredState(); + if (m_nLastPedState == PED_NONE) + m_nLastPedState = oldLastState; + + m_nPedState = PED_FOLLOW_PATH; + m_nMoveState = m_followPathMoveState; + return true; + + } else { + m_pathNodeTimer = 0; + if (m_nPedState == PED_FOLLOW_PATH) + RestorePreviousState(); + + return false; + } + } else { + m_pathNodeTimer = 0; + if (m_nPedState == PED_FOLLOW_PATH) + RestorePreviousState(); + + return false; + } } void @@ -15210,12 +17293,27 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) uint32 optedDoorNode = wantedDoorNode; bool teleportNeeded = false; bool isLow = !!veh->bLowVehicle; - if (!veh->CanPedExitCar()) { - if (veh->pDriver && !veh->pDriver->IsPlayer()) { - veh->AutoPilot.m_nCruiseSpeed = 0; - veh->AutoPilot.m_nCarMission = MISSION_NONE; + + bool canJumpOut = false; + if (!veh->CanPedExitCar(false) && !bBusJacked) { + if (IsPlayer()) { + // TODO(Miami): Do jumping out of car + canJumpOut = false; + } + if (!canJumpOut) { + if (veh->pDriver) { + if (veh->pDriver->IsPlayer()) { + if (veh->pDriver != this) { + m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 5000; + bHeldHostageInCar = true; + } + } else { + veh->AutoPilot.m_nCruiseSpeed = 0; + veh->AutoPilot.m_nCarMission = MISSION_NONE; + } + } + return; } - return; } if (m_nPedState == PED_EXIT_CAR || m_nPedState == PED_DRAG_FROM_CAR) @@ -15283,6 +17381,12 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) return; } if (!someoneExitsFromOurExitDoor || m_nPedType == PEDTYPE_COP && veh->bIsBus) { +#if defined GTAVC_JP_PATCH || defined FIX_BUGS + if (veh->pDriver == this && !IsPlayer() && veh == CGameLogic::pShortCutTaxi) { + m_objective = OBJECTIVE_NONE; + return; + } +#endif // Again, unused... // CVector exitPos = GetPositionToOpenCarDoor(veh, optedDoorNode); bool thereIsRoom = veh->IsRoomForPedToLeaveCar(optedDoorNode, nil); @@ -15367,17 +17471,16 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) SetMoveState(PEDMOVE_STILL); } - ReplaceWeaponWhenExitingVehicle(); bUsesCollision = false; m_pSeekTarget = veh; m_pSeekTarget->RegisterReference((CEntity**) &m_pSeekTarget); m_vehEnterType = optedDoorNode; - m_nPedState = PED_EXIT_CAR; + SetPedState(PED_EXIT_CAR); if (m_pVehicleAnim && m_pVehicleAnim->flags & ASSOC_PARTIAL) m_pVehicleAnim->blendDelta = -1000.0f; + RemoveInCarAnims(); SetMoveState(PEDMOVE_NONE); CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 100.0f); - RemoveInCarAnims(); veh->AutoPilot.m_nCruiseSpeed = 0; if (teleportNeeded) { PedSetOutCarCB(nil, this); @@ -15410,13 +17513,13 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) } else { if (veh->GetUp().z > -0.8f) { bool addDoorSmoke = false; - if (veh->GetModelIndex() == MI_YARDIE) + if (veh->GetModelIndex() == MI_VOODOO) addDoorSmoke = true; switch (m_vehEnterType) { case CAR_DOOR_RF: if (veh->bIsBus) { - m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_COACH_OUT_L); + m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_COACH, ANIM_COACH_OUT_L); } else { if (isLow) m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_GETOUT_LOW_RHS); @@ -15429,7 +17532,7 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) break; case CAR_DOOR_RR: if (veh->bIsVan) { - m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_VAN_GETOUT); + m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_VAN, ANIM_VAN_GETOUT); } else if (isLow) { m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_GETOUT_LOW_RHS); } else { @@ -15438,7 +17541,7 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) break; case CAR_DOOR_LF: if (veh->bIsBus) { - m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_COACH_OUT_L); + m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_COACH, ANIM_COACH_OUT_L); } else { if (isLow) m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_GETOUT_LOW_LHS); @@ -15451,7 +17554,7 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) break; case CAR_DOOR_LR: if (veh->bIsVan) { - m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_VAN_GETOUT_L); + m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_VAN, ANIM_VAN_GETOUT_L); } else if (isLow) { m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_GETOUT_LOW_LHS); } else { @@ -15462,22 +17565,7 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) break; } if (!bBusJacked) { - switch (m_vehEnterType) { - case CAR_DOOR_RF: - veh->m_nGettingOutFlags |= CAR_DOOR_FLAG_RF; - break; - case CAR_DOOR_RR: - veh->m_nGettingOutFlags |= CAR_DOOR_FLAG_RR; - break; - case CAR_DOOR_LF: - veh->m_nGettingOutFlags |= CAR_DOOR_FLAG_LF; - break; - case CAR_DOOR_LR: - veh->m_nGettingOutFlags |= CAR_DOOR_FLAG_LR; - break; - default: - break; - } + veh->m_nGettingOutFlags |= GetCarDoorFlag(m_vehEnterType); } m_pVehicleAnim->SetFinishCallback(PedAnimStepOutCarCB, this); } else { @@ -15664,6 +17752,7 @@ CPed::ScanForInterestingStuff(void) } } +// --MIAMI: Done except comments uint32 CPed::ScanForThreats(void) { @@ -15676,18 +17765,22 @@ CPed::ScanForThreats(void) return PED_FLAG_EXPLOSION; } - CPed *shooter = nil; - if ((fearFlags & PED_FLAG_GUN) && (shooter = CheckForGunShots()) && (m_nPedType != shooter->m_nPedType || m_nPedType == PEDTYPE_CIVMALE || m_nPedType == PEDTYPE_CIVFEMALE)) { - if (!IsGangMember()) { - m_threatEntity = shooter; - m_threatEntity->RegisterReference((CEntity **) &m_threatEntity); - return PED_FLAG_GUN; - } + if (fearFlags & PED_FLAG_GUN) { + CPed *shooter = CheckForGunShots(); + if (shooter && (m_nPedType != shooter->m_nPedType || m_nPedType == PEDTYPE_CIVMALE || m_nPedType == PEDTYPE_CIVFEMALE)) { + if (!IsGangMember()) { + m_threatEntity = shooter; + m_threatEntity->RegisterReference((CEntity**)&m_threatEntity); + return PED_FLAG_GUN; + } - if (CPedType::GetFlag(shooter->m_nPedType) & fearFlags) { - m_threatEntity = shooter; - m_threatEntity->RegisterReference((CEntity **) &m_threatEntity); - return CPedType::GetFlag(shooter->m_nPedType); + if (CPedType::GetFlag(shooter->m_nPedType) & fearFlags || m_nPedType == PEDTYPE_GANG5) { + if (m_threatEntity) + m_threatEntity->CleanUpOldReference(&m_threatEntity); + m_threatEntity = shooter; + m_threatEntity->RegisterReference((CEntity**)&m_threatEntity); + return CPedType::GetFlag(shooter->m_nPedType); + } } } @@ -15701,32 +17794,6 @@ CPed::ScanForThreats(void) uint32 flagsOfSomePed = 0; CPed *pedToFearFrom = nil; -#ifndef VC_PED_PORTS - for (int i = 0; i < m_numNearPeds; i++) { - if (CharCreatedBy != RANDOM_CHAR || m_nearPeds[i]->CharCreatedBy != MISSION_CHAR || m_nearPeds[i]->IsPlayer()) { - CPed *nearPed = m_nearPeds[i]; - - // BUG: WTF Rockstar?! Putting this here will result in returning the flags of farthest ped to us, since m_nearPeds is sorted by distance. - // Fixed at the bottom of the function. - flagsOfSomePed = CPedType::GetFlag(nearPed->m_nPedType); - - if (CPedType::GetFlag(nearPed->m_nPedType) & fearFlags) { - if (nearPed->m_fHealth > 0.0f && OurPedCanSeeThisOne(m_nearPeds[i])) { - // FIX: Taken from VC -#ifdef FIX_BUGS - float nearPedDistSqr = (nearPed->GetPosition() - ourPos).MagnitudeSqr2D(); -#else - float nearPedDistSqr = (CVector2D(ourPos) - explosionPos).MagnitudeSqr(); -#endif - if (sq(closestPedDist) > nearPedDistSqr) { - closestPedDist = Sqrt(nearPedDistSqr); - pedToFearFrom = m_nearPeds[i]; - } - } - } - } - } -#else bool weSawOurEnemy = false; bool weMaySeeOurEnemy = false; float closestEnemyDist = 60.0f; @@ -15743,7 +17810,7 @@ CPed::ScanForThreats(void) if (flagsOfSomePed & fearFlags) { if (m_nearPeds[i]->m_fHealth > 0.0f) { - // VC also has ability to include objects to line of sight check here (via last bit of flagsL) + // TODO(Miami): include objects to line of sight check here (via last bit of flagsL) if (OurPedCanSeeThisOne(m_nearPeds[i])) { if (m_nearPeds[i]->m_nPedState == PED_ATTACK) { if (m_nearPeds[i]->m_pedInObjective == this) { @@ -15770,8 +17837,8 @@ CPed::ScanForThreats(void) CColPoint foundCol; CEntity *foundEnt; + // TODO(Miami): include objects to line of sight check here (via last bit of flagsL) // We don't see him yet but he's behind a ped, vehicle or object - // VC also has ability to include objects to line of sight check here (via last bit of flagsL) if (!CWorld::ProcessLineOfSight(ourPos, nearPed->GetPosition(), foundCol, foundEnt, true, false, false, false, false, false, false)) { @@ -15799,7 +17866,7 @@ CPed::ScanForThreats(void) } } } -#endif + int16 lastVehicle; CEntity* vehicles[8]; CWorld::FindObjectsInRange(ourPos, 20.0f, true, &lastVehicle, 6, vehicles, false, true, false, false, false); @@ -15813,6 +17880,8 @@ CPed::ScanForThreats(void) // BUG: Same bug as above. Fixed at the bottom of function. flagsOfSomePed = CPedType::GetFlag(driver->m_nPedType); if (CPedType::GetFlag(driver->m_nPedType) & fearFlags) { + + // TODO(Miami): Last param if (driver->m_fHealth > 0.0f && OurPedCanSeeThisOne(nearVeh->pDriver)) { // FIX: Taken from VC #ifdef FIX_BUGS @@ -15843,6 +17912,7 @@ CPed::ScanForThreats(void) } } +// --MIAMI: Done void CPed::SeekCar(void) { @@ -15854,7 +17924,7 @@ CPed::SeekCar(void) } if (m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER) { - if (m_vehEnterType && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER) { + if (!vehToSeek->IsBike() && m_vehEnterType && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER) { if (IsRoomToBeCarJacked()) { dest = GetPositionToOpenCarDoor(vehToSeek, m_vehEnterType); } else if (m_nPedType == PEDTYPE_COP) { @@ -15925,14 +17995,10 @@ CPed::SeekCar(void) bool foundBetterPosToSeek = PossiblyFindBetterPosToSeekCar(&dest, vehToSeek); m_vecSeekPos = dest; float distToDestSqr = (m_vecSeekPos - GetPosition()).MagnitudeSqr(); -#ifndef VC_PED_PORTS - if (bIsRunning) - SetMoveState(PEDMOVE_RUN); -#else + if (bIsRunning || vehToSeek->pDriver && distToDestSqr > sq(2.0f) && (Abs(vehToSeek->m_vecMoveSpeed.x) > 0.01f || Abs(vehToSeek->m_vecMoveSpeed.y) > 0.01f)) SetMoveState(PEDMOVE_RUN); -#endif else if (distToDestSqr < sq(2.0f)) SetMoveState(PEDMOVE_WALK); @@ -15949,10 +18015,13 @@ CPed::SeekCar(void) // Arrived to the car if (Seek()) { if (!foundBetterPosToSeek) { - if (1.5f + GetPosition().z > dest.z && GetPosition().z - 0.5f < dest.z) { + if (1.6f + GetPosition().z > dest.z && GetPosition().z - 0.5f < dest.z) { +#ifdef GTA_TRAIN if (vehToSeek->IsTrain()) { SetEnterTrain(vehToSeek, m_vehEnterType); - } else { + } else +#endif + { m_fRotationCur = m_fRotationDest; if (!bVehEnterDoorIsBlocked) { vehToSeek->bIsStatic = false; @@ -15968,7 +18037,15 @@ CPed::SeekCar(void) case STATUS_SIMPLE: case STATUS_PHYSICS: case STATUS_PLAYER_DISABLED: - if (!vehToSeek->bIsBus && (!m_leader || m_leader != vehToSeek->pDriver) && + if (vehToSeek->IsBike()) { + if ((!m_leader || m_leader != vehToSeek->pDriver) && + ((m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_WINDSCREEN) && vehToSeek->pDriver || + (m_vehEnterType == CAR_DOOR_LR || m_vehEnterType == CAR_DOOR_RR) && vehToSeek->pPassengers[0])) { + SetCarJack(vehToSeek); + } else { + SetEnterCar(vehToSeek, m_vehEnterType); + } + } else if (!vehToSeek->bIsBus && (!m_leader || m_leader != vehToSeek->pDriver) && (m_vehEnterType == CAR_DOOR_LF && vehToSeek->pDriver || m_vehEnterType == CAR_DOOR_RF && vehToSeek->pPassengers[0] || m_vehEnterType == CAR_DOOR_LR && vehToSeek->pPassengers[1] || m_vehEnterType == CAR_DOOR_RR && vehToSeek->pPassengers[2])) { SetCarJack(vehToSeek); if (m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER && m_vehEnterType != CAR_DOOR_LF) @@ -15978,7 +18055,18 @@ CPed::SeekCar(void) } break; case STATUS_ABANDONED: - if (m_vehEnterType == CAR_DOOR_RF && vehToSeek->pPassengers[0]) { + if (vehToSeek->IsBike()) { + if ((m_vehEnterType == CAR_DOOR_LR || m_vehEnterType == CAR_DOOR_RR) && vehToSeek->pPassengers[0]) { + if (vehToSeek->pPassengers[0]->bDontDragMeOutCar) { + if (IsPlayer()) + CPed::SetEnterCar(vehToSeek, m_vehEnterType); + } else { + SetCarJack(vehToSeek); + } + } else { + SetEnterCar(vehToSeek, m_vehEnterType); + } + } else if (m_vehEnterType == CAR_DOOR_RF && vehToSeek->pPassengers[0]) { if (vehToSeek->pPassengers[0]->bDontDragMeOutCar) { if (IsPlayer()) CPed::SetEnterCar(vehToSeek, m_vehEnterType); @@ -16007,6 +18095,7 @@ CPed::SeekCar(void) } } +// --MIAMI: Done void CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) { @@ -16047,13 +18136,9 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) } else if (IsPedInControl()) { if ((IsPlayer() && m_nPedState != PED_FIGHT && ((CPlayerPed*)this)->m_fMoveSpeed > 1.0f) || (!IsPlayer() && m_objective == OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE)) { -#ifndef VC_PED_PORTS - if (hitLevel != HITLEVEL_HIGH && hitLevel != HITLEVEL_LOW || (IsPlayer() || CGeneral::GetRandomNumber() & 3) && CGeneral::GetRandomNumber() & 7) { - if (IsPlayer() || CGeneral::GetRandomNumber() & 3) { -#else + if (hitLevel != HITLEVEL_HIGH && hitLevel != HITLEVEL_LOW || (IsPlayer() || CGeneral::GetRandomNumber() & 1) && CGeneral::GetRandomNumber() & 7) { if (IsPlayer() || CGeneral::GetRandomNumber() & 1) { -#endif AnimationId shotAnim; switch (direction) { case 1: @@ -16081,22 +18166,6 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) SetWaitState(WAITSTATE_PLAYANIM_DUCK, &time); } } else { -#ifndef VC_PED_PORTS - switch (direction) { - case 1: - SetFall(500, ANIM_KO_SPIN_R, false); - break; - case 2: - SetFall(500, ANIM_KO_SKID_BACK, false); - break; - case 3: - SetFall(500, ANIM_KO_SPIN_L, false); - break; - default: - SetFall(500, ANIM_KO_SHOT_STOM, false); - break; - } -#else bool fall = true; AnimationId hitAnim; switch (direction) { @@ -16139,7 +18208,6 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) hitAssoc->SetRun(); hitAssoc->flags |= ASSOC_FADEOUTWHENDONE; } -#endif } Say(SOUND_PED_DEFEND); } else { @@ -16149,20 +18217,15 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) m_curFightMove = FIGHTMOVE_HITONFLOOR; break; case HITLEVEL_LOW: -#ifndef VC_PED_PORTS - if (direction == 2) { - CPed::SetFall(1000, ANIM_KO_SKID_BACK, false); - return; - } -#else if (direction == 2 && (!IsPlayer() || ((CGeneral::GetRandomNumber() & 1) && m_fHealth < 30.0f))) { - CPed::SetFall(1000, ANIM_KO_SKID_BACK, false); + SetFall(1000, ANIM_KO_SKID_BACK, false); + Say(SOUND_PED_DEFEND); return; } else if (direction != 2 && !IsPlayer() && (CGeneral::GetRandomNumber() & 1) && m_fHealth < 30.0f) { - CPed::SetFall(1000, ANIM_KO_SHOT_STOM, false); + SetFall(1000, ANIM_KO_SHOT_STOM, false); + Say(SOUND_PED_DEFEND); return; } -#endif m_curFightMove = FIGHTMOVE_HITBODY; break; case HITLEVEL_HIGH: @@ -16212,24 +18275,28 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) moveAssoc->SetCurrentTime(0.0f); moveAssoc->SetFinishCallback(FinishFightMoveCB, this); if (IsPlayer()) - moveAssoc->speed = 1.3f; + moveAssoc->speed = 1.2f; m_takeAStepAfterAttack = 0; m_fightButtonPressure = 0; - } else if (IsPlayer() && m_currentWeapon != WEAPONTYPE_UNARMED) { + + } else if (IsPlayer() && GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && GetWeapon()->m_eWeaponType != WEAPONTYPE_BRASSKNUCKLE && + !CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bFightMode) { CAnimBlendAssociation *moveAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, tFightMoves[m_curFightMove].animId, 4.0f); moveAssoc->SetCurrentTime(0.0f); - moveAssoc->speed = 1.3f; + moveAssoc->speed = 1.2f; + } else { if (m_nPedState != PED_AIM_GUN && m_nPedState != PED_ATTACK) SetStoredState(); if (m_nWaitState != WAITSTATE_FALSE) { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); RestoreHeadingRate(); } - m_nPedState = PED_FIGHT; + SetPedState(PED_FIGHT); m_fightButtonPressure = 0; + m_lastFightMove = FIGHTMOVE_IDLE; RpAnimBlendClumpRemoveAssociations(GetClump(), ASSOC_REPEAT); CAnimBlendAssociation *walkStartAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WALK_START); if (walkStartAssoc) { @@ -16246,13 +18313,28 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) } SetMoveState(PEDMOVE_NONE); m_nStoredMoveState = PEDMOVE_NONE; - CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_IDLE)->blendAmount = 1.0f; + CAnimBlendAssociation *fightIdleAssoc; + + if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED) { + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + if (GetFightIdleWithMeleeAnim(weaponInfo)) { + fightIdleAssoc = CAnimManager::AddAnimation(GetClump(), weaponInfo->m_AnimToPlay, GetFightIdleWithMeleeAnim(weaponInfo)); + } else { + fightIdleAssoc = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_IDLE); + } + } else { + fightIdleAssoc = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_IDLE); + } + fightIdleAssoc->blendAmount = 1.0f; CAnimBlendAssociation *moveAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, tFightMoves[m_curFightMove].animId, 8.0f); moveAssoc->SetFinishCallback(FinishFightMoveCB, this); m_fightState = FIGHTSTATE_NO_MOVE; m_takeAStepAfterAttack = false; bIsAttacking = true; } + + if (m_pedInObjective && m_pedInObjective->IsPlayer() && !IsPlayer()) + ((CPlayerPed*)m_pedInObjective)->RemovePedFromMeleeList(this); } } } @@ -16384,6 +18466,8 @@ CPed::UpdateFromLeader(void) m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget); TurnBody(); if (m_attackTimer < CTimer::GetTimeInMilliseconds() && !GetWeapon()->IsTypeMelee()) { + if (m_pPointGunAt) + m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt); m_pPointGunAt = m_threatEntity; if (m_threatEntity) m_threatEntity->RegisterReference((CEntity **) &m_pPointGunAt); @@ -16423,10 +18507,11 @@ CPed::UpdateFromLeader(void) } } +// --MIAMI: Done void CPed::UpdatePosition(void) { - if (CReplay::IsPlayingBack() || !bIsStanding) + if (CReplay::IsPlayingBack() || !bIsStanding || m_attachedTo) return; CVector2D velocityChange; @@ -16473,7 +18558,7 @@ CPed::UpdatePosition(void) } // Take time step into account - if (m_pCurrentPhysSurface) { + if (m_pCurrentPhysSurface && (!m_pCurrentPhysSurface->bInfiniteMass || m_pCurrentPhysSurface->m_phy_flagA08)) { float speedChange = velocityChange.Magnitude(); float changeMult = speedChange; if (m_nPedState != PED_DIE || !m_pCurrentPhysSurface->IsVehicle()) { @@ -16491,27 +18576,39 @@ CPed::UpdatePosition(void) m_vecMoveSpeed.y += velocityChange.y; } +// --MIAMI: Done void CPed::SetPedPositionInCar(void) { + bool notYet = false; if (CReplay::IsPlayingBack()) return; if (bChangedSeat) { - bool notYet = false; - if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_GETIN_LHS) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_GETIN_LOW_LHS) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_CLOSEDOOR_LHS) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_CLOSEDOOR_LOW_LHS) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SHUFFLE_RHS) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LSHUFFLE_RHS) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_VAN_CLOSE_L) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_VAN_CLOSE) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_VAN_GETIN_L) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_VAN_GETIN) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_COACH_IN_L) - || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_COACH_IN_R)) { - notYet = true; + if (m_pMyVehicle->IsBike()) { + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_JUMPON_R) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_JUMPON_L) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_KICK)) { + LineUpPedWithCar(LINE_UP_TO_CAR_START); + return; + } + bChangedSeat = false; + } else { + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_GETIN_LHS) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_GETIN_LOW_LHS) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_CLOSEDOOR_LHS) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_CLOSEDOOR_LOW_LHS) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SHUFFLE_RHS) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LSHUFFLE_RHS) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_VAN_CLOSE_L) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_VAN_CLOSE) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_VAN_GETIN_L) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_VAN_GETIN) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_COACH_IN_L) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_COACH_IN_R) + || RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_JUMPIN_LHS)) { + notYet = true; + } } if (notYet) { LineUpPedWithCar(LINE_UP_TO_CAR_START); @@ -16524,14 +18621,16 @@ CPed::SetPedPositionInCar(void) CVector seatPos; if (m_pMyVehicle->pDriver == this) { seatPos = vehModel->GetFrontSeatPosn(); - if (!m_pMyVehicle->IsBoat() && m_pMyVehicle->m_vehType != VEHICLE_TYPE_BIKE) + if (!m_pMyVehicle->IsBoat() && !m_pMyVehicle->IsBike()) seatPos.x = -seatPos.x; } else if (m_pMyVehicle->pPassengers[0] == this) { - seatPos = vehModel->GetFrontSeatPosn(); + seatPos = m_pMyVehicle->IsBike() ? vehModel->m_positions[CAR_POS_BACKSEAT]: vehModel->GetFrontSeatPosn(); + } else if (m_pMyVehicle->pPassengers[1] == this) { seatPos = vehModel->m_positions[CAR_POS_BACKSEAT]; seatPos.x = -seatPos.x; + } else { if (m_pMyVehicle->pPassengers[2] == this) { seatPos = vehModel->m_positions[CAR_POS_BACKSEAT]; @@ -16539,6 +18638,10 @@ CPed::SetPedPositionInCar(void) seatPos = vehModel->GetFrontSeatPosn(); } } + if (m_pMyVehicle->IsBike()) { + ((CBike*)m_pMyVehicle)->CalculateLeanMatrix(); + newMat = ((CBike*)m_pMyVehicle)->m_leanMatrix; + } newMat.GetPosition() += Multiply3x3(newMat, seatPos); // Already done below (SetTranslate(0.0f, 0.0f, 0.0f)) // tempMat.SetUnity(); @@ -16670,6 +18773,7 @@ CPed::SpawnFlyingComponent(int pedNode, int8 direction) return obj; } +// --MIAMI: Done void CPed::WarpPedIntoCar(CVehicle *car) { @@ -16678,7 +18782,7 @@ CPed::WarpPedIntoCar(CVehicle *car) m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle); m_carInObjective = car; m_carInObjective->RegisterReference((CEntity **) &m_carInObjective); - m_nPedState = PED_DRIVING; + SetPedState(m_nPedState); bUsesCollision = false; bIsInTheAir = false; bVehExitWillBeInstant = true; @@ -16687,6 +18791,10 @@ CPed::WarpPedIntoCar(CVehicle *car) car->pDriver->RegisterReference((CEntity **) &car->pDriver); } else if (m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER) { + if (car->IsBike() && !car->pPassengers[0]) { + car->pPassengers[0] = this; + car->pPassengers[0]->RegisterReference((CEntity**) &car->pPassengers[0]); + } for (int i = 0; i < 4; i++) { if (!car->pPassengers[i]) { car->pPassengers[i] = this; @@ -16722,39 +18830,35 @@ CPed::WarpPedIntoCar(CVehicle *car) DMAudio.PlayOneShot(car->m_audioEntityId, SOUND_CAR_ENGINE_START, 1.0f); } -#ifdef VC_PED_PORTS RpAnimBlendClumpSetBlendDeltas(GetClump(), ASSOC_PARTIAL, -1000.0f); - // VC uses AddInCarAnims but we don't have that - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, car->GetDriverAnim(), 100.0f); + AddInCarAnims(car, car->pDriver == this); RemoveWeaponWhenEnteringVehicle(); -#else - if (car->IsBoat()) { -#ifndef FIX_BUGS - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_BOAT, 100.0f); -#else - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, car->GetDriverAnim(), 100.0f); -#endif - CWeaponInfo *ourWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); - RemoveWeaponModel(ourWeapon->m_nModelId); - } else { - // Because we can use Uzi for drive by - RemoveWeaponWhenEnteringVehicle(); - - if (car->bLowVehicle) - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_LSIT, 100.0f); - else - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_SIT, 100.0f); - } -#endif - StopNonPartialAnims(); if (car->bIsBus) bRenderPedInCar = false; bChangedSeat = true; } +// --MIAMI: Done +void +CPed::SetObjective(eObjective newObj, float heading, const CVector& pos) +{ + switch (newObj) { + case OBJECTIVE_GOTO_SEAT_ON_FOOT: + case OBJECTIVE_GOTO_ATM_ON_FOOT: + case OBJECTIVE_GOTO_BUS_STOP_ON_FOOT: + case OBJECTIVE_GOTO_PIZZA_ON_FOOT: + case OBJECTIVE_GOTO_SHELTER_ON_FOOT: + case OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT: + ClearPointGunAt(); + SetObjective(newObj, pos); + m_attractorHeading = heading; + } +} + +// --MIAMI: Done void CPed::SetObjective(eObjective newObj, CVector dest) { @@ -16764,9 +18868,8 @@ CPed::SetObjective(eObjective newObj, CVector dest) if (m_prevObjective != OBJECTIVE_NONE && m_prevObjective == newObj) return; - SetObjectiveTimer(0); if (m_objective == newObj) { - if (newObj == OBJECTIVE_GOTO_AREA_ANY_MEANS || newObj == OBJECTIVE_GOTO_AREA_ON_FOOT || newObj == OBJECTIVE_RUN_TO_AREA) { + if (newObj == OBJECTIVE_GOTO_AREA_ANY_MEANS || newObj == OBJECTIVE_GOTO_AREA_ON_FOOT || newObj == OBJECTIVE_RUN_TO_AREA || newObj == OBJECTIVE_SPRINT_TO_AREA) { if (m_nextRoutePointPos == dest) return; } else if (newObj == OBJECTIVE_GUARD_SPOT) { @@ -16775,9 +18878,8 @@ CPed::SetObjective(eObjective newObj, CVector dest) } } -#ifdef VC_PED_PORTS ClearPointGunAt(); -#endif + m_objectiveTimer = 0; bObjectiveCompleted = false; switch (newObj) { case OBJECTIVE_GUARD_SPOT: @@ -16793,6 +18895,8 @@ CPed::SetObjective(eObjective newObj, CVector dest) case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE: case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS: case OBJECTIVE_GOTO_CHAR_ON_FOOT: + case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING: + case OBJECTIVE_HASSLE_CHAR: case OBJECTIVE_FOLLOW_CHAR_IN_FORMATION: case OBJECTIVE_LEAVE_CAR: case OBJECTIVE_ENTER_CAR_AS_PASSENGER: @@ -16801,19 +18905,77 @@ CPed::SetObjective(eObjective newObj, CVector dest) case OBJECTIVE_FIRE_AT_OBJECT_FROM_VEHICLE: case OBJECTIVE_DESTROY_OBJECT: case OBJECTIVE_DESTROY_CAR: + case OBJECTIVE_GOTO_AREA_IN_CAR: + case OBJECTIVE_FOLLOW_CAR_ON_FOOT_WITH_OFFSET: + case OBJECTIVE_GUARD_ATTACK: + case OBJECTIVE_SET_LEADER: + case OBJECTIVE_FOLLOW_ROUTE: + case OBJECTIVE_SOLICIT_VEHICLE: + case OBJECTIVE_HAIL_TAXI: + case OBJECTIVE_CATCH_TRAIN: + case OBJECTIVE_BUY_ICE_CREAM: + case OBJECTIVE_STEAL_ANY_CAR: + case OBJECTIVE_STEAL_ANY_MISSION_CAR: + case OBJECTIVE_MUG_CHAR: + case OBJECTIVE_LEAVE_CAR_AND_DIE: + case OBJECTIVE_FLEE_CAR: + case OBJECTIVE_SUN_BATHE: + case OBJECTIVE_AIM_GUN_AT: + case OBJECTIVE_WANDER: + case OBJECTIVE_WAIT_ON_FOOT_AT_SHELTER: + case OBJECTIVE_KILL_CHAR_ON_BOAT: + case OBJECTIVE_SOLICIT_FOOT: + case OBJECTIVE_WAIT_ON_FOOT_AT_BUS_STOP: break; case OBJECTIVE_GOTO_AREA_ANY_MEANS: case OBJECTIVE_GOTO_AREA_ON_FOOT: + case OBJECTIVE_GOTO_SEAT_ON_FOOT: + case OBJECTIVE_GOTO_ATM_ON_FOOT: + case OBJECTIVE_GOTO_BUS_STOP_ON_FOOT: + case OBJECTIVE_GOTO_PIZZA_ON_FOOT: + case OBJECTIVE_GOTO_SHELTER_ON_FOOT: + case OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT: bIsRunning = false; m_pNextPathNode = nil; m_nextRoutePointPos = dest; m_vecSeekPos = m_nextRoutePointPos; m_distanceToCountSeekDone = 0.5f; - bUsePedNodeSeek = true; - if (sq(m_distanceToCountSeekDone) > (m_nextRoutePointPos - GetPosition()).MagnitudeSqr2D()) - return; + if (newObj == OBJECTIVE_GOTO_ATM_ON_FOOT) { + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (newObj == OBJECTIVE_GOTO_SEAT_ON_FOOT) { + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (newObj == OBJECTIVE_GOTO_BUS_STOP_ON_FOOT) { + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (newObj == OBJECTIVE_GOTO_PIZZA_ON_FOOT) { + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (newObj == OBJECTIVE_GOTO_SHELTER_ON_FOOT) { + bIsRunning = true; + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (newObj == OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT) { + bIsRunning = true; + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + bUsePedNodeSeek = false; + if (sq(m_distanceToCountSeekDone) > (m_nextRoutePointPos - GetPosition()).MagnitudeSqr2D()) { + if (!IsUseAttractorObjective(m_objective)) + return; + if (Abs(m_fRotationCur - m_attractorHeading) < m_acceptableHeadingOffset) + return; + } break; case OBJECTIVE_RUN_TO_AREA: + case OBJECTIVE_SPRINT_TO_AREA: bIsRunning = true; m_pNextPathNode = nil; m_nextRoutePointPos = dest; @@ -16836,10 +18998,11 @@ CPed::SetObjective(eObjective newObj, CVector dest) } } +// --MIAMI: Done void CPed::SetMoveAnim(void) { - if (m_nStoredMoveState == m_nMoveState || !IsPedInControl()) + if (m_nStoredMoveState == m_nMoveState || !IsPedInControl() || m_attachedTo) return; if (m_nMoveState == PEDMOVE_NONE) { @@ -16855,12 +19018,14 @@ CPed::SetMoveAnim(void) CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_BLOCK); if (!animAssoc) { - CAnimBlendAssociation *fightIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE); - animAssoc = fightIdleAssoc; - if (fightIdleAssoc && m_nPedState == PED_FIGHT) + animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE); + if (!animAssoc) + animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCHRELOAD); + + if (animAssoc && m_nPedState == PED_FIGHT) return; - if (fightIdleAssoc) { + if (animAssoc) { CAnimBlendAssociation *idleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_STANCE); if (!idleAssoc || idleAssoc->blendDelta <= 0.0f) { animAssoc->flags |= ASSOC_DELETEFADEDOUT; @@ -16947,11 +19112,12 @@ CPed::SetMoveAnim(void) } } + +// --MIAMI: Done void CPed::SetEnterCar_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) { float zDiff = 0.0f; - RemoveWeaponWhenEnteringVehicle(); car->m_nGettingInFlags |= doorFlag; bVehEnterDoorIsBlocked = false; if (m_nPedState != PED_SEEK_CAR && m_nPedState != PED_SEEK_IN_BOAT) @@ -16960,8 +19126,8 @@ CPed::SetEnterCar_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) m_pSeekTarget = car; m_pSeekTarget->RegisterReference((CEntity **) &m_pSeekTarget); m_vehEnterType = doorNode; - m_nPedState = PED_ENTER_CAR; - if (m_vehEnterType == CAR_DOOR_RF && m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER && car->m_vehType != VEHICLE_TYPE_BIKE) { + SetPedState(PED_ENTER_CAR); + if (m_vehEnterType == CAR_DOOR_RF && m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER && !car->IsBike()) { car->bIsBeingCarJacked = true; } @@ -16977,28 +19143,20 @@ CPed::SetEnterCar_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) m_vecOffsetSeek = doorOpenPos - GetPosition(); m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 600; + if (car->IsBoat()) { -#ifdef VC_PED_PORTS - // VC checks for handling flag, but we can't do that - if(car->GetModelIndex() == MI_SPEEDER) + if (car->pHandling->Flags & HANDLING_SIT_IN_BOAT) m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_SIT, 100.0f); else m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_BOAT, 100.0f); PedSetInCarCB(nil, this); bVehExitWillBeInstant = true; -#else -#ifndef FIX_BUGS - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_BOAT, 100.0f); -#else - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, car->GetDriverAnim(), 100.0f); -#endif + } else if (car->IsBike()) { + PedAnimAlignCB(0, this); + car->AutoPilot.m_nCruiseSpeed = 0; - m_pVehicleAnim->SetFinishCallback(PedSetInCarCB, this); -#endif - if (IsPlayer()) - CWaterLevel::AllocateBoatWakeArray(); } else { if (zDiff > 4.4f) { if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) @@ -17013,10 +19171,10 @@ CPed::SetEnterCar_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGN_LHS, 4.0f); } m_pVehicleAnim->SetFinishCallback(PedAnimAlignCB, this); - car->AutoPilot.m_nCruiseSpeed = 0; } } +// --MIAMI: Done void CPed::WanderPath(void) { @@ -17029,14 +19187,14 @@ CPed::WanderPath(void) if (m_nMoveState == PEDMOVE_STILL || m_nMoveState == PEDMOVE_NONE) SetMoveState(PEDMOVE_WALK); } - m_vecSeekPos = m_pNextPathNode->GetPosition(); + m_vecSeekPos = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); m_vecSeekPos.z += 1.0f; // Only returns true when ped is stuck(not stopped) I think, then we should assign new direction or wait state to him. if (!Seek()) return; - CPathNode *previousLastNode = m_pLastPathNode; + CPathNode *previousLastNode = m_pLastPathNode; uint8 randVal = (m_randomSeed + 3 * CTimer::GetFrameCounter()) % 100; // We don't prefer 180-degree turns in normal situations @@ -17049,6 +19207,8 @@ CPed::WanderPath(void) CPathNode *nodeWeWouldntPrefer = nil; uint8 dirToSet = 9; // means undefined uint8 dirWeWouldntPrefer2 = 9; // means undefined + uint8 tryCount = 0; + if (randVal <= 90) { if (randVal > 80) { m_nPathDir += 2; @@ -17064,7 +19224,13 @@ CPed::WanderPath(void) ThePaths.FindNextNodeWandering(PATH_PED, GetPosition(), &m_pLastPathNode, &m_pNextPathNode, m_nPathDir, &dirToSet); - uint8 tryCount = 0; + if (((CPedModelInfo*)CModelInfo::GetModelInfo(m_modelIndex))->m_pedStatType == PEDSTAT_SKATER) { + if (m_pNextPathNode) { + CVector unpacked(m_pNextPathNode->GetPosition() / 8.f); + if (!CPopulation::IsSkateable(unpacked)) + m_pNextPathNode = nil; + } + } // NB: SetWanderPath checks for m_nPathDir == dirToStartWith, this one checks for tryCount > 7 while (!m_pNextPathNode) { @@ -17092,6 +19258,13 @@ CPed::WanderPath(void) m_pNextPathNode = nil; } } + if (((CPedModelInfo*)CModelInfo::GetModelInfo(m_modelIndex))->m_pedStatType == PEDSTAT_SKATER) { + if (m_pNextPathNode) { + CVector unpacked(m_pNextPathNode->GetPosition() / 8.f); + if (!CPopulation::IsSkateable(unpacked)) + m_pNextPathNode = nil; + } + } } } @@ -17178,91 +19351,59 @@ CPed::WarpPedToNearLeaderOffScreen(void) return teleported; } +// --MIAMI: Done void -CPed::SetCarJack_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) +CPed::SetCarJack_AllClear(CVehicle* car, uint32 doorNode, uint32 doorFlag) { - RemoveWeaponWhenEnteringVehicle(); if (m_nPedState != PED_SEEK_CAR) SetStoredState(); m_pSeekTarget = car; m_pSeekTarget->RegisterReference((CEntity**)&m_pSeekTarget); - m_nPedState = PED_CARJACK; + SetPedState(PED_CARJACK); car->bIsBeingCarJacked = true; m_pMyVehicle = (CVehicle*)m_pSeekTarget; m_pMyVehicle->RegisterReference((CEntity**)&m_pMyVehicle); ((CVehicle*)m_pSeekTarget)->m_nNumGettingIn++; - Say(m_nPedType == PEDTYPE_COP ? SOUND_PED_ARREST_COP : SOUND_PED_CAR_JACKING); + if (m_nPedType == PEDTYPE_COP) + Say(SOUND_PED_ARREST_COP); + else if (car->m_nDoorLock == CARLOCK_UNLOCKED) + Say(SOUND_PED_CAR_JACKING, 1000); + CVector carEnterPos; carEnterPos = GetPositionToOpenCarDoor(car, m_vehEnterType); car->m_nGettingInFlags |= doorFlag; m_vecOffsetSeek = carEnterPos - GetPosition(); m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 600; - float zDiff = Max(0.0f, carEnterPos.z - GetPosition().z); - bUsesCollision = false; - - if (zDiff > 4.4f) { - if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGNHI_RHS, 4.0f); - else - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGNHI_LHS, 4.0f); + if(car->IsBike()){ + bUsesCollision = false; + PedAnimAlignCB(nil, this); } else { - if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGN_RHS, 4.0f); - else - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGN_LHS, 4.0f); - } - - m_pVehicleAnim->SetFinishCallback(PedAnimAlignCB, this); -} - -void -CPed::SetObjective(eObjective newObj, CVector dest, float safeDist) -{ - if (DyingOrDead()) - return; + float zDiff = Max(0.0f, carEnterPos.z - GetPosition().z); + bUsesCollision = false; - if (m_prevObjective != OBJECTIVE_NONE && m_prevObjective == newObj) - return; + if (zDiff > 4.4f) { + if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGNHI_RHS, 4.0f); + else + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGNHI_LHS, 4.0f); - SetObjectiveTimer(0); - if (m_objective == newObj) { - if (newObj == OBJECTIVE_GOTO_AREA_ANY_MEANS || newObj == OBJECTIVE_GOTO_AREA_ON_FOOT || newObj == OBJECTIVE_RUN_TO_AREA) { - if (m_nextRoutePointPos == dest && m_distanceToCountSeekDone == safeDist) - return; - } else if (newObj == OBJECTIVE_GUARD_SPOT) { - if (m_vecSeekPosEx == dest && m_distanceToCountSeekDoneEx == safeDist) - return; } - } - -#ifdef VC_PED_PORTS - ClearPointGunAt(); -#endif - bObjectiveCompleted = false; - if (IsTemporaryObjective(m_objective)) { - m_prevObjective = newObj; - } else { - if (m_objective != newObj) - SetStoredObjective(); + else { + if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGN_RHS, 4.0f); + else + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ALIGN_LHS, 4.0f); + } - m_objective = newObj; - } - - if (newObj == OBJECTIVE_GUARD_SPOT) { - m_vecSeekPosEx = dest; - m_distanceToCountSeekDoneEx = safeDist; - } else if (newObj == OBJECTIVE_GOTO_AREA_ANY_MEANS || newObj == OBJECTIVE_GOTO_AREA_ON_FOOT || newObj == OBJECTIVE_RUN_TO_AREA) { - m_pNextPathNode = nil; - m_nextRoutePointPos = dest; - m_vecSeekPos = m_nextRoutePointPos; - bUsePedNodeSeek = true; + m_pVehicleAnim->SetFinishCallback(PedAnimAlignCB, this); } } +// --MIAMI: Done void CPed::SetCarJack(CVehicle* car) { @@ -17273,41 +19414,71 @@ CPed::SetCarJack(CVehicle* car) if (car->IsBoat()) return; - switch (m_vehEnterType) { - case CAR_DOOR_RF: - doorFlag = CAR_DOOR_FLAG_RF; - door = DOOR_FRONT_RIGHT; - if (car->pPassengers[0]) { + if (car->IsBike()) { + switch (m_vehEnterType) { + case CAR_DOOR_RF: + doorFlag = CAR_DOOR_FLAG_LF | CAR_DOOR_FLAG_RF; + door = DOOR_FRONT_RIGHT; + pedInSeat = car->pDriver; + break; + case CAR_DOOR_RR: + doorFlag = CAR_DOOR_FLAG_LR | CAR_DOOR_FLAG_RR; + door = DOOR_REAR_RIGHT; pedInSeat = car->pPassengers[0]; - } else if (m_nPedType == PEDTYPE_COP) { + break; + case CAR_DOOR_LF: + case CAR_WINDSCREEN: + doorFlag = CAR_DOOR_FLAG_LF | CAR_DOOR_FLAG_RF; + door = DOOR_FRONT_LEFT; pedInSeat = car->pDriver; - } - break; - case CAR_DOOR_RR: - doorFlag = CAR_DOOR_FLAG_RR; - door = DOOR_REAR_RIGHT; - pedInSeat = car->pPassengers[2]; - break; - case CAR_DOOR_LF: - doorFlag = CAR_DOOR_FLAG_LF; - door = DOOR_FRONT_LEFT; - pedInSeat = car->pDriver; - break; - case CAR_DOOR_LR: - doorFlag = CAR_DOOR_FLAG_LR; - door = DOOR_REAR_LEFT; - pedInSeat = car->pPassengers[1]; - break; - default: - doorFlag = CAR_DOOR_FLAG_UNKNOWN; - break; + break; + case CAR_DOOR_LR: + doorFlag = CAR_DOOR_FLAG_LR | CAR_DOOR_FLAG_RR; + door = DOOR_REAR_LEFT; + pedInSeat = car->pPassengers[0]; + break; + default: + doorFlag = CAR_DOOR_FLAG_UNKNOWN; + break; + } + } else { + switch (m_vehEnterType) { + case CAR_DOOR_RF: + doorFlag = CAR_DOOR_FLAG_RF; + door = DOOR_FRONT_RIGHT; + if (car->pPassengers[0]) { + pedInSeat = car->pPassengers[0]; + } + else if (m_nPedType == PEDTYPE_COP) { + pedInSeat = car->pDriver; + } + break; + case CAR_DOOR_RR: + doorFlag = CAR_DOOR_FLAG_RR; + door = DOOR_REAR_RIGHT; + pedInSeat = car->pPassengers[2]; + break; + case CAR_DOOR_LF: + doorFlag = CAR_DOOR_FLAG_LF; + door = DOOR_FRONT_LEFT; + pedInSeat = car->pDriver; + break; + case CAR_DOOR_LR: + doorFlag = CAR_DOOR_FLAG_LR; + door = DOOR_REAR_LEFT; + pedInSeat = car->pPassengers[1]; + break; + default: + doorFlag = CAR_DOOR_FLAG_UNKNOWN; + break; + } } if(car->bIsBus) pedInSeat = car->pDriver; if (m_fHealth > 0.0f && (IsPlayer() || m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS || - (car->VehicleCreatedBy != MISSION_VEHICLE && car->GetModelIndex() != MI_DODO))) + (car->VehicleCreatedBy != MISSION_VEHICLE && car->GetModelIndex() != MI_DODO))) if (pedInSeat && !pedInSeat->IsPedDoingDriveByShooting() && pedInSeat->m_nPedState == PED_DRIVING) if (m_nPedState != PED_CARJACK && !m_pVehicleAnim) if ((car->IsDoorReady(door) || car->IsDoorFullyOpen(door))) @@ -17355,31 +19526,13 @@ CPed::Solicit(void) } } -// Seperate function in VC, more logical. Not sure is it inlined in III. +// --MIAMI: Done void CPed::SetExitBoat(CVehicle *boat) { -#ifndef VC_PED_PORTS - m_nPedState = PED_IDLE; - CVector firstPos = GetPosition(); - CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 100.0f); - if (boat->GetModelIndex() == MI_SPEEDER && boat->IsUpsideDown()) { - m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_CRAWLOUT_RHS, 8.0f); - m_pVehicleAnim->SetFinishCallback(CPed::PedSetOutCarCB, this); - m_vehEnterType = CAR_DOOR_RF; - m_nPedState = PED_EXIT_CAR; - } else { - m_vehEnterType = CAR_DOOR_RF; - CPed::PedSetOutCarCB(nil, this); - bIsStanding = true; - m_pCurSurface = boat; - m_pCurSurface->RegisterReference((CEntity**)&m_pCurSurface); + if (m_nPedState == PED_FOLLOW_PATH) { + ClearFollowPath(); } - SetPosition(firstPos); - SetMoveState(PEDMOVE_STILL); - m_vecMoveSpeed = boat->m_vecMoveSpeed; - bTryingToReachDryLand = true; -#else m_nPedState = PED_IDLE; CVector newPos = GetPosition(); RemoveInCarAnims(); @@ -17395,10 +19548,10 @@ CPed::SetExitBoat(CVehicle *boat) m_pCurSurface->RegisterReference((CEntity**)&m_pCurSurface); m_pCurrentPhysSurface = boat; } else { -/* if (boat->m_modelIndex != MI_SKIMMER || boat->bIsInWater) { + if (boat->m_modelIndex != MI_SKIMMER || boat->bIsInWater) { if (boat->m_modelIndex == MI_SKIMMER) - newPos.z += 2.0f -*/ + newPos.z += 2.0f; + m_vehEnterType = CAR_DOOR_RF; PedSetOutCarCB(nil, this); bIsStanding = true; @@ -17409,7 +19562,6 @@ CPed::SetExitBoat(CVehicle *boat) CEntity *foundEnt = nil; if (CWorld::ProcessVerticalLine(newPos, newPos.z - 1.4f, foundCol, foundEnt, false, true, false, false, false, false, nil)) newPos.z = FEET_OFFSET + foundCol.point.z; -/* // VC specific } else { m_vehEnterType = CAR_DOOR_RF; PedSetOutCarCB(nil, this); @@ -17419,7 +19571,7 @@ CPed::SetExitBoat(CVehicle *boat) float upMult = 1.04f + boatCol->boundingBox.min.z; float rightMult = 0.6f * boatCol->boundingBox.max.x; newPos = upMult * boat->GetUp() + rightMult * boat->GetRight() + boat->GetPosition(); - GetPosition() = newPos; + SetPosition(newPos); if (m_pMyVehicle) { PositionPedOutOfCollision(); } else { @@ -17429,13 +19581,135 @@ CPed::SetExitBoat(CVehicle *boat) } return; } -*/ } + } SetPosition(newPos); SetMoveState(PEDMOVE_STILL); m_vecMoveSpeed = boat->m_vecMoveSpeed; -#endif - // Not there in VC. - CWaterLevel::FreeBoatWakeArray(); +} + +// --MIAMI: Done +void +CPed::SetNewAttraction(CPedAttractor* pAttractor, const CVector& pos, float heading, float time, int32 qid) +{ + if (!m_attractor) + m_attractor = pAttractor; + if (m_attractor != pAttractor) + return; + switch (pAttractor->GetEffect()->pedattr.type) { + case ATTRACTOR_ATM: SetObjective(OBJECTIVE_GOTO_ATM_ON_FOOT, heading, pos); break; + case ATTRACTOR_SEAT: SetObjective(OBJECTIVE_GOTO_SEAT_ON_FOOT, heading, pos); break; + case ATTRACTOR_STOP: SetObjective(OBJECTIVE_GOTO_BUS_STOP_ON_FOOT, heading, pos); break; + case ATTRACTOR_PIZZA: SetObjective(OBJECTIVE_GOTO_PIZZA_ON_FOOT, heading, pos); break; + case ATTRACTOR_SHELTER: SetObjective(OBJECTIVE_GOTO_SHELTER_ON_FOOT, heading, pos); break; + case ATTRACTOR_ICECREAM: SetObjective(OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT, heading, pos); break; + default: return; + } + SetObjectiveTimer(time); + m_positionInQueue = qid; +} + +// --MIAMI: Done +void +CPed::ClearWaitState(void) +{ + CAnimBlendAssociation *assoc; + switch (m_nWaitState) { + case WAITSTATE_PLAYANIM_CHAT: + case WAITSTATE_SIT_DOWN: + case WAITSTATE_SIT_DOWN_RVRS: + case WAITSTATE_SIT_UP: + case WAITSTATE_SIT_IDLE: + case WAITSTATE_USE_ATM: + if (CTimer::GetTimeInMilliseconds() <= m_nWaitTimer) { + if (m_nWaitState == WAITSTATE_USE_ATM) { + assoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_ATM); + if (assoc) + assoc->blendDelta = -8.0f; + if (m_attractor) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + + } else if (m_nWaitState == WAITSTATE_PLAYANIM_CHAT) { + assoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_CHAT); + if (assoc) + assoc->blendDelta = -8.0f; + if (m_attractor) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + + } else if (m_nWaitState == WAITSTATE_SIT_DOWN || m_nWaitState == WAITSTATE_SIT_DOWN_RVRS || m_nWaitState == WAITSTATE_SIT_IDLE || m_nWaitState == WAITSTATE_SIT_UP) { + switch (m_nWaitState) { + case WAITSTATE_SIT_DOWN: + assoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_SEAT_DOWN); + if (assoc) + assoc->blendDelta = -8.0f; + break; + case WAITSTATE_SIT_IDLE: + assoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_SEAT_IDLE); + if (assoc) + assoc->blendDelta = -8.0f; + break; + case WAITSTATE_SIT_UP: + assoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_SEAT_UP); + if (assoc) + assoc->blendDelta = -8.0f; + break; + default: + break; + } + if (m_attractor) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + } + } + break; + case WAITSTATE_RIOT: + { + CAnimBlock* riotAnimBlock = CAnimManager::GetAnimationBlock("riot"); + + for (assoc = RpAnimBlendClumpGetFirstAssociation(GetClump()); assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) { + int first = riotAnimBlock->firstIndex; + int index = assoc->hierarchy - CAnimManager::GetAnimation(0); + if (index >= first && index < first + riotAnimBlock->numAnims) { + assoc->blendDelta = -1000.0f; + } + } + break; + } + case WAITSTATE_FAST_FALL: + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_KO_SKID_FRONT)) + SetGetUp(); + + break; + case WAITSTATE_BOMBER: + assoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BOMBER); + if (assoc) + assoc->blendDelta = -8.0f; + break; + case WAITSTATE_STRIPPER: + { + CAnimBlock* stripAnimBlock = CAnimManager::GetAnimationBlock("strip"); + + for (assoc = RpAnimBlendClumpGetFirstAssociation(GetClump()); assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) { + int first = stripAnimBlock->firstIndex; + int index = assoc->hierarchy - CAnimManager::GetAnimation(0); + if (index >= first && index < first + stripAnimBlock->numAnims) { + assoc->blendDelta = -1000.0f; + } + } + break; + } + case WAITSTATE_LANCESITTING: + assoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_SUNBATHE); + if (assoc) + assoc->blendDelta = -8.0f; + break; + case WAITSTATE_PLAYANIM_HANDSUP_SIMPLE: + assoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_HANDSUP); + if (assoc) + assoc->blendDelta = -8.0f; + break; + default: + break; + } + m_nWaitState = WAITSTATE_FALSE; } #ifdef COMPATIBLE_SAVES @@ -17474,8 +19748,26 @@ CPed::Load(uint8*& buf) CopyFromBuf(buf, m_fHealth); CopyFromBuf(buf, m_fArmour); SkipSaveBuf(buf, 148); - for (int i = 0; i < 13; i++) // has to be hardcoded - m_weapons[i].Load(buf); + + CWeapon bufWeapon; + for (int i = 0; i < 13; i++) { // has to be hardcoded + bufWeapon.Load(buf); + if (i >= 10) + continue; // tmp hack before we fix save/load + + if (bufWeapon.m_eWeaponType != WEAPONTYPE_UNARMED) { + int modelId = CWeaponInfo::GetWeaponInfo(bufWeapon.m_eWeaponType)->m_nModelId; + if (modelId != -1) { + CStreaming::RequestModel(modelId, STREAMFLAGS_DEPENDENCY); + int modelId2 = CWeaponInfo::GetWeaponInfo(bufWeapon.m_eWeaponType)->m_nModel2Id; + if (modelId2 != -1) + CStreaming::RequestModel(modelId2, STREAMFLAGS_DEPENDENCY); + + CStreaming::LoadAllRequestedModels(false); + } + GiveWeapon(bufWeapon.m_eWeaponType, bufWeapon.m_nAmmoTotal); + } + } SkipSaveBuf(buf, 5); CopyFromBuf(buf, m_maxWeaponTypeAllowed); SkipSaveBuf(buf, 162); @@ -17483,3 +19775,1262 @@ CPed::Load(uint8*& buf) #undef CopyFromBuf #undef CopyToBuf #endif + +// --MIAMI: Done +void +CPed::GiveDelayedWeapon(eWeaponType weapon, uint32 ammo) +{ + m_delayedWeapon = weapon; + m_delayedWeaponAmmo = ammo; + if (m_delayedWeapon != WEAPONTYPE_UNIDENTIFIED) { + int modelId1 = CWeaponInfo::GetWeaponInfo(m_delayedWeapon)->m_nModelId; + int modelId2 = CWeaponInfo::GetWeaponInfo(m_delayedWeapon)->m_nModel2Id; + if (modelId1 != -1) + CStreaming::RequestModel(modelId1, STREAMFLAGS_DEPENDENCY); + if (modelId2 != -1) + CStreaming::RequestModel(modelId2, STREAMFLAGS_DEPENDENCY); + + if ((modelId1 == -1 || CStreaming::HasModelLoaded(modelId1)) + && (modelId2 == -1 || CStreaming::HasModelLoaded(modelId2))) { + GiveWeapon(m_delayedWeapon, m_delayedWeaponAmmo, true); + m_delayedWeapon = WEAPONTYPE_UNIDENTIFIED; + } + } +} + +// --MIAMI: Done +void +CPed::RequestDelayedWeapon() +{ + if (m_delayedWeapon != WEAPONTYPE_UNIDENTIFIED) { + int modelId1 = CWeaponInfo::GetWeaponInfo(m_delayedWeapon)->m_nModelId; + int modelId2 = CWeaponInfo::GetWeaponInfo(m_delayedWeapon)->m_nModel2Id; + if (modelId1 != -1) + CStreaming::RequestModel(modelId1, STREAMFLAGS_DEPENDENCY); + if (modelId2 != -1) + CStreaming::RequestModel(modelId2, STREAMFLAGS_DEPENDENCY); + + if ((modelId1 == -1 || CStreaming::HasModelLoaded(modelId1)) + && (modelId2 == -1 || CStreaming::HasModelLoaded(modelId2))) { + GiveWeapon(m_delayedWeapon, m_delayedWeaponAmmo, 1); + m_delayedWeapon = WEAPONTYPE_UNIDENTIFIED; + } + } +} + +// --MIAMI: Done +void +CPed::ClearFollowPath() +{ + for (int i = 0; i < ARRAY_SIZE(m_pathNodesToGo); i++) { + m_pathNodesToGo[i] = nil; + } + m_nNumPathNodes = 0; + m_nCurPathNodeId = 0; +} + +// --MIAMI: Done +void +CPed::AddInCarAnims(CVehicle* car, bool isDriver) +{ + if (car->IsBoat()) { + if (car->pHandling->Flags & HANDLING_SIT_IN_BOAT) { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_SIT, 100.0f); + } else { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_BOAT, 100.0f); + } + } else if (car->IsBike()) { + if (isDriver) { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ((CBike*)car)->m_bikeAnimType, ANIM_BIKE_RIDE, 100.0f); + } else { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ((CBike*)car)->m_bikeAnimType, ANIM_BIKE_PASSENGER, 100.0f); + } + } else { + if (isDriver) { + if (car->bLowVehicle) { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_LSIT, 100.0f); + } else { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_SIT, 100.0f); + } + } else { + if (car->bLowVehicle) { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_SITPLO, 100.0f); + } else { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_SITP, 100.0f); + } + } + } + + StopNonPartialAnims(); +} + +// --MIAMI: Done +bool +CPed::CanBeDamagedByThisGangMember(CPed* who) +{ + return m_gangFlags & (1 << (uint8)(who->m_nPedType - PEDTYPE_GANG1)); +} + +// --MIAMI: Done +void +CPed::Undress(const char* name) +{ + int mi = GetModelIndex(); + CAnimBlendAssociation* pAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_PHONE_OUT); + if (pAnim) + FinishTalkingOnMobileCB(pAnim, this); + + DeleteRwObject(); + if (IsPlayer()) + mi = MI_PLAYER; + CStreaming::RequestSpecialModel(mi, name, STREAMFLAGS_DEPENDENCY | STREAMFLAGS_SCRIPTOWNED); + CWorld::Remove(this); +} + +// --MIAMI: Done +void +FinishTalkingOnMobileCB(CAnimBlendAssociation *assoc, void *arg) +{ + CPed *ped = (CPed*)arg; + if (ped->m_storedWeapon != WEAPONTYPE_UNIDENTIFIED) { + ped->RemoveWeaponModel(MI_MOBILE); + ped->SetCurrentWeapon(ped->m_storedWeapon); + ped->m_storedWeapon = WEAPONTYPE_UNIDENTIFIED; + } + ped->m_lookTimer = 0; +} + +// --MIAMI: Done +void +StartTalkingOnMobileCB(CAnimBlendAssociation* assoc, void* arg) +{ + CPed* ped = (CPed*)arg; + if (ped->m_nPedState == PED_ANSWER_MOBILE) + CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_PHONE_TALK, 4.0f); +} + +// --MIAMI: Done +void +CPed::SetAnswerMobile(void) +{ + if (m_nPedState != PED_ANSWER_MOBILE && !DyingOrDead()) { + SetPedState(PED_ANSWER_MOBILE); + RemoveWeaponAnims(GetWeapon()->m_eWeaponType, -4.0f); + CAnimBlendAssociation *assoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_PHONE_IN, 4.0f); + assoc->SetFinishCallback(StartTalkingOnMobileCB, this); + m_lookTimer = INT32_MAX; + if (m_storedWeapon == WEAPONTYPE_UNIDENTIFIED) + m_storedWeapon = GetWeapon()->m_eWeaponType; + + RemoveWeaponModel(-1); + } +} + +// --MIAMI: Done +void +CPed::ClearAnswerMobile(void) +{ + if (m_nLastPedState == PED_ANSWER_MOBILE) + m_nLastPedState = PED_NONE; + + if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_PHONE_TALK)) { + CAnimBlendAssociation *assoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_PHONE_OUT, 8.0f); + assoc->SetFinishCallback(FinishTalkingOnMobileCB, this); + } else + FinishTalkingOnMobileCB(nil, this); + + if (m_nPedState == PED_ANSWER_MOBILE) { + m_nPedState = PED_IDLE; + RestorePreviousState(); + m_pMyVehicle = nil; + } +} + +// --MIAMI: Done +void +CPed::Dress(void) +{ + int mi = GetModelIndex(); + m_modelIndex = -1; + SetModelIndex(mi); + m_nPedState = PED_IDLE; + m_nLastPedState = PED_NONE; + m_objective = OBJECTIVE_NONE; + m_prevObjective = OBJECTIVE_NONE; + m_nWaitState = WAITSTATE_FALSE; + CWorld::Add(this); + m_headingRate = m_pedStats->m_headingChangeRate; +} + +// --MIAMI: Done +void +CPed::AnswerMobile(void) +{ + if (!IsPedInControl()) + return; + + CAnimBlendAssociation *phoneInAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_PHONE_IN); + CAnimBlendAssociation *phoneOutAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_PHONE_OUT); + CAnimBlendAssociation *phoneTalkAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_PHONE_TALK); + if (phoneInAssoc || phoneTalkAssoc || phoneOutAssoc) { + if (phoneInAssoc) { + if (phoneInAssoc->currentTime >= 0.85f && !m_pWeaponModel) { + CBaseModelInfo *phoneModel = CModelInfo::GetModelInfo(MI_MOBILE); + m_pWeaponModel = (RpAtomic*)phoneModel->CreateInstance(); + phoneModel->AddRef(); + m_wepModelID = MI_MOBILE; + + // They copied AddWeaponModel and forgot that here + // bool unused = IsPlayer(); + } + } else if (phoneOutAssoc) { + if (phoneOutAssoc->currentTime >= 0.5f && phoneOutAssoc->currentTime - phoneOutAssoc->timeStep < 0.5f) { + RemoveWeaponModel(MI_MOBILE); + SetCurrentWeapon(m_storedWeapon); + m_storedWeapon = WEAPONTYPE_UNIDENTIFIED; + } + } + } else { + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_PHONE_TALK, 4.0f); + } +} + +// --MIAMI: Done except commented thing +void +CPed::AttachPedToEntity(CEntity *ent, CVector offset, uint16 type, float rot, eWeaponType weapon) +{ + if (!ent || bInVehicle) + return; + + m_attachedTo = ent; + m_attachedTo->RegisterReference(&m_attachedTo); + m_vecAttachOffset = offset; + m_attachType = type; + m_attachRotStep = rot; + if (IsPlayer()) { + bUsesCollision = false; + } else if (ent->IsVehicle()) { + m_pCollidingEntity = ent; + } + + if (IsPlayer()) { + m_objective = OBJECTIVE_NONE; + m_prevObjective = OBJECTIVE_NONE; + } + SetStoredState(); + SetPedState(PED_IDLE); + CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 1000.0f); + + if (m_storedWeapon == WEAPONTYPE_UNIDENTIFIED) { + m_storedWeapon = GetWeapon()->m_eWeaponType; + m_attachWepAmmo = GetWeapon()->m_nAmmoTotal; + } + if (IsPlayer()) { + GiveWeapon(weapon, 30000, 1); +#ifndef FIX_BUGS + ((CPlayerPed*)this)->m_nSelectedWepSlot = weapon; +#else + ((CPlayerPed*)this)->m_nSelectedWepSlot = GetWeaponSlot(weapon); +#endif + ((CPlayerPed*)this)->MakeChangesForNewWeapon(weapon); + TheCamera.SetNewPlayerWeaponMode(CCam::MODE_HELICANNON_1STPERSON, 0, 0); + SetPedState(PED_SNIPER_MODE); + } else { + GiveWeapon(weapon, 30000, true); + SetCurrentWeapon(weapon); + } + + PositionAttachedPed(); +} + +// --MIAMI: Done +void +CPed::DettachPedFromEntity(void) +{ + CEntity* pVehicleAttachedTo = m_attachedTo; + m_attachedTo = nil; + if (m_nPedState == PED_DIE) { + m_pCollidingEntity = pVehicleAttachedTo; + ApplyMoveForce(pVehicleAttachedTo->GetForward() * -4.0f); + bIsStanding = false; + } else if (m_nPedState != PED_DEAD) { + RestorePreviousState(); + CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 1000.0f); + bUsesCollision = true; + if (m_storedWeapon != WEAPONTYPE_UNIDENTIFIED) { + GetWeapon()->m_nAmmoInClip = 0; + GetWeapon()->m_nAmmoTotal = 0; + SetCurrentWeapon(m_storedWeapon); + GetWeapon()->m_nAmmoTotal = m_attachWepAmmo; + m_storedWeapon = WEAPONTYPE_UNIDENTIFIED; + } + } +} + +// --MIAMI: Done +void +CPed::PedShuffle(void) +{ + if (m_pMyVehicle->pPassengers[0] == this) { + CPed *driver = m_pMyVehicle->pDriver; + if (!driver || driver->m_objective == OBJECTIVE_LEAVE_CAR) { + m_pVehicleAnim = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, m_pMyVehicle->bLowVehicle ? ANIM_CAR_LSHUFFLE_RHS : ANIM_CAR_SHUFFLE_RHS); + m_objective = OBJECTIVE_ENTER_CAR_AS_DRIVER; + m_pMyVehicle->RemovePassenger(this); + bInVehicle = false; + m_pVehicleAnim->SetFinishCallback(PedSetInCarCB, this); + } + } +} + +// --MIAMI: Bike part is done +void +CPed::DriveVehicle(void) +{ + if (bOffscreen) + return; + + CVehicle *veh = m_pMyVehicle; + if (veh->IsBike()) { + CBike *bike = (CBike*)veh; + float blendDelta = 1.0f; + float targetUDLean = 0.0f; + CAnimBlendAssociation *leftAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_LEFT); + CAnimBlendAssociation *rightAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_RIGHT); + CAnimBlendAssociation *stillAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_STILL); + CAnimBlendAssociation *fwdAssoc, *backAssoc; + if (IsPlayer()) { + fwdAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_FWD); + backAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_BACK); + } + CAnimBlendAssociation *walkbackAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_PUSHES); + CAnimBlendAssociation *drivebyAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_DRIVEBY_RHS); + if (!drivebyAssoc) + drivebyAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_DRIVEBY_LHS); + if (!drivebyAssoc) + drivebyAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BIKE_DRIVEBY_FT); + + float velocityFwdDotProd = DotProduct(bike->m_vecMoveSpeed, bike->GetForward()); + if (m_vecTurnSpeed.MagnitudeSqr() > 0.09f) { + bike->KnockOffRider(WEAPONTYPE_FALL, 2, this, false); + if (bike->pPassengers[0]) + bike->KnockOffRider(WEAPONTYPE_FALL, 2, bike->pPassengers[0], false); + return; + } + if (!drivebyAssoc && Abs(velocityFwdDotProd) < 0.02f) { + if (!stillAssoc || stillAssoc->blendAmount < 1.0 && stillAssoc->blendDelta <= 0.0) { + stillAssoc = CAnimManager::BlendAnimation(GetClump(), bike->m_bikeAnimType, ANIM_BIKE_STILL, 2.0f); + } + } else { + if (velocityFwdDotProd >= 0.0f) { + if (stillAssoc && stillAssoc->blendDelta >= 0.0f) + stillAssoc->blendDelta = -4.0f; + if (walkbackAssoc && walkbackAssoc->blendDelta >= 0.0f) + walkbackAssoc->blendDelta = -4.0f; + } else { + float maxReverseSpeed = bike->pHandling->Transmission.fMaxReverseVelocity; + if (3.5f * maxReverseSpeed > velocityFwdDotProd && (bike->m_nWheelsOnGround || bike->GetUp().z < -0.5f)) { + bike->KnockOffRider(WEAPONTYPE_FALL, 2, this, false); + if (bike->pPassengers[0]) + bike->KnockOffRider(WEAPONTYPE_FALL, 2, bike->pPassengers[0], false); + return; + } + if (bike->m_fGasPedal >= 0.0 || velocityFwdDotProd <= maxReverseSpeed * 1.5) { + if (IsPlayer() && velocityFwdDotProd < maxReverseSpeed * 1.5) + targetUDLean = -1.0f; + + if (stillAssoc && stillAssoc->blendDelta >= 0.0f) + stillAssoc->blendDelta = -4.0f; + + if (walkbackAssoc && walkbackAssoc->blendDelta >= 0.0f) { + walkbackAssoc->blendDelta = -4.0f; + } + } else if (!walkbackAssoc || walkbackAssoc->blendAmount < 1.0f && walkbackAssoc->blendDelta <= 0.0f) { + walkbackAssoc = CAnimManager::BlendAnimation(GetClump(), bike->m_bikeAnimType, ANIM_BIKE_PUSHES, 4.0f); + } + } + } + if (stillAssoc) + blendDelta -= Min(1.0f, CTimer::GetTimeStepNonClipped() * 0.02f * stillAssoc->blendDelta + stillAssoc->blendAmount); + + if (drivebyAssoc) + blendDelta -= Min(blendDelta, CTimer::GetTimeStepNonClipped() * 0.02f * drivebyAssoc->blendDelta + drivebyAssoc->blendAmount); + + if (walkbackAssoc) + blendDelta -= Min(blendDelta, CTimer::GetTimeStepNonClipped() * 0.02f * walkbackAssoc->blendDelta + walkbackAssoc->blendAmount); + + float targetLRLean, timeBlend, neededAngForWheelie, stoppieAng; + + // Smooth the lean amount + if (targetUDLean == -1.0f) { + targetLRLean = 0.0f; + timeBlend = Pow(0.86f, CTimer::GetTimeStep()); + } else { + targetLRLean = clamp(bike->m_fLeanLRAngle / bike->pBikeHandling->fFullAnimLean, -1.0f, 1.0f); + timeBlend = Pow(0.86f, CTimer::GetTimeStep()); + } + + bike->m_fPedLeanAmountLR = bike->m_fPedLeanAmountLR * timeBlend + (1.0 - timeBlend) * targetLRLean; + + if (!IsPlayer()) { + targetUDLean = 0.0f; + + } else if (targetUDLean > -1.0f) { + targetUDLean = bike->m_fLeanInput; + bike->bWheelieCam = false; + neededAngForWheelie = 1.0f; + if (bike->m_aWheelTimer[0] != 0.0f || bike->m_aWheelTimer[1] != 0.0f || bike->GetForward().z <= 0.0f || + (0.0f == bike->m_aWheelTimer[2] && 0.0f == bike->m_aWheelTimer[3])) { + + if (0.0f == bike->m_aWheelTimer[2] && 0.0f == bike->m_aWheelTimer[3] && + (bike->GetForward().z < 0.0f && (bike->m_aWheelTimer[0] != 0.0f || bike->m_aWheelTimer[1] != 0.0f))) { + + stoppieAng = bike->pBikeHandling->fStoppieAng; + if (stoppieAng - bike->GetForward().z > 0.6f * stoppieAng) + bike->bWheelieCam = true; + } + } else { + float wheelieAng = bike->pBikeHandling->fWheelieAng; + neededAngForWheelie = wheelieAng - bike->GetForward().z; + if (neededAngForWheelie < wheelieAng / 2.f) + bike->bWheelieCam = true; + } + if (neededAngForWheelie >= 0.15f) { + if (bike->m_fBrakePedal <= 0.5f || velocityFwdDotProd <= 0.01f) { + if (bike->m_fGasPedal > 0.5f && targetUDLean <= 0.0f && 0.3f * bike->pHandling->Transmission.fUnkMaxVelocity > velocityFwdDotProd) { + targetUDLean = Min(0.1f, targetUDLean); + } + } else { + targetUDLean = Max(0.1f, targetUDLean); + } + } else { + targetUDLean = Max(0.25f, targetUDLean); + } + float targetLRLeanABS = Abs(targetLRLean); + if (targetLRLeanABS > 0.3f) { + // Yes, UD + targetUDLean *= Max(0.0f, 1.0f - (targetLRLeanABS - 0.3f) * 50.f / 13.f); + } + } + if (IsPlayer()) { + float timeBlend = Pow(0.89f, CTimer::GetTimeStep()); + bike->m_fPedLeanAmountUD = (timeBlend * bike->m_fPedLeanAmountUD) + ((1.0f - timeBlend) * targetUDLean); + } else { + bike->m_fPedLeanAmountUD = 0.0f; + } + + float fwdBackLeanAmount, leftRightLeanAmount; + if (Abs(bike->m_fPedLeanAmountLR) <= 0.56f && IsPlayer()) { + + if (Abs(bike->m_fPedLeanAmountUD) <= 0.56f) { + CVector2D smoothedLean(bike->m_fPedLeanAmountLR, bike->m_fPedLeanAmountUD); + float smoothLeanMag = smoothedLean.Magnitude(); + if (smoothLeanMag <= 0.01f) { + fwdBackLeanAmount = Abs(smoothedLean.y); + leftRightLeanAmount = Abs(smoothedLean.x); + } else { + fwdBackLeanAmount = Abs(smoothedLean.y / smoothLeanMag); + leftRightLeanAmount = Abs(smoothedLean.x / smoothLeanMag); + } + } else { + fwdBackLeanAmount = 1.0f; + leftRightLeanAmount = 0.0f; + } + } else { + fwdBackLeanAmount = 0.0f; + leftRightLeanAmount = 1.0f; + } + float fwdBackBlend = fwdBackLeanAmount * blendDelta; + float leftRightBlend = leftRightLeanAmount * blendDelta; + if (IsPlayer()) { + if (!fwdAssoc) + fwdAssoc = CAnimManager::AddAnimation(GetClump(), bike->m_bikeAnimType, ANIM_BIKE_FWD); + if (!backAssoc) + backAssoc = CAnimManager::AddAnimation(GetClump(), bike->m_bikeAnimType, ANIM_BIKE_BACK); + + if (bike->m_fPedLeanAmountUD < 0.0f) { + backAssoc->blendAmount = fwdBackBlend; + backAssoc->SetCurrentTime(-(bike->m_fPedLeanAmountUD * backAssoc->hierarchy->totalLength)); + backAssoc->flags &= ~ASSOC_RUNNING; + fwdAssoc->blendAmount = 0.0f; + } else { + fwdAssoc->blendAmount = fwdBackBlend; + fwdAssoc->SetCurrentTime(bike->m_fPedLeanAmountUD* fwdAssoc->hierarchy->totalLength); + fwdAssoc->flags &= ~ASSOC_RUNNING; + backAssoc->blendAmount = 0.0f; + } + } + if (!leftAssoc) + leftAssoc = CAnimManager::AddAnimation(GetClump(), bike->m_bikeAnimType, ANIM_BIKE_LEFT); + if (!rightAssoc) + rightAssoc = CAnimManager::AddAnimation(GetClump(), bike->m_bikeAnimType, ANIM_BIKE_RIGHT); + + if (bike->m_fPedLeanAmountLR < 0.0f) { + leftAssoc->blendAmount = leftRightBlend; + leftAssoc->SetCurrentTime(-(bike->m_fPedLeanAmountLR * leftAssoc->hierarchy->totalLength)); + leftAssoc->flags &= ~ASSOC_RUNNING; + rightAssoc->blendAmount = 0.0f; + } else { + rightAssoc->blendAmount = leftRightBlend; + rightAssoc->SetCurrentTime(bike->m_fPedLeanAmountLR* rightAssoc->hierarchy->totalLength); + rightAssoc->flags &= ~ASSOC_RUNNING; + leftAssoc->blendAmount = 0.0f; + } + if (velocityFwdDotProd > 0.3f) { + RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; + RwV3d Yaxis = { 0.0f, 1.0f, 0.0f }; + RtQuatRotate(&m_pFrames[PED_HEAD]->hanimFrame->q, &Xaxis, CGeneral::GetRandomNumberInRange(-6.0f * velocityFwdDotProd, 6.0f * velocityFwdDotProd), rwCOMBINEPOSTCONCAT); + RtQuatRotate(&m_pFrames[PED_HEAD]->hanimFrame->q, &Yaxis, CGeneral::GetRandomNumberInRange(-6.0f * velocityFwdDotProd, 6.0f * velocityFwdDotProd), rwCOMBINEPOSTCONCAT); + bDontAcceptIKLookAts = true; + } + return; + } + + if (!IsPlayer()) + return; + + float steerAngle = m_pMyVehicle->m_fSteerAngle; + CAnimBlendAssociation* lDriveAssoc; + CAnimBlendAssociation* rDriveAssoc; + CAnimBlendAssociation* lbAssoc; + CAnimBlendAssociation* sitAssoc; + if (m_pMyVehicle->IsBoat() && !(m_pMyVehicle->pHandling->Flags & HANDLING_SIT_IN_BOAT)) { + sitAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_BOAT); + + if (!sitAssoc || sitAssoc->blendAmount < 1.0f) { + return; + } + + lDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_BOAT_L); + rDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_BOAT_R); + lbAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_BOAT_LB); + } + else if (m_pMyVehicle->bLowVehicle) { + sitAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LSIT); + + if (!sitAssoc || sitAssoc->blendAmount < 1.0f) { + return; + } + + lDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_LOW_L); + lbAssoc = nil; + rDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_LOW_R); + } + else { + sitAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_SIT); + + if (!sitAssoc || sitAssoc->blendAmount < 1.0f) { + return; + } + + lDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_L); + rDriveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVE_R); + lbAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_LB); + } + + if (lbAssoc && + TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_1STPERSON + && TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking == LOOKING_LEFT) { + lbAssoc->blendDelta = -1000.0f; + } + + CAnimBlendAssociation* driveByAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_L); + if (!driveByAssoc) + driveByAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_R); + if (!driveByAssoc) + driveByAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_LOW_L); + if (!driveByAssoc) + driveByAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DRIVEBY_LOW_R); + + if (m_pMyVehicle->bLowVehicle || m_pMyVehicle->m_fGasPedal >= 0.0f || driveByAssoc) { + if (steerAngle == 0.0f || driveByAssoc) { + if (lDriveAssoc) + lDriveAssoc->blendAmount = 0.0f; + if (rDriveAssoc) + rDriveAssoc->blendAmount = 0.0f; + + } + else if (steerAngle <= 0.0f) { + if (lDriveAssoc) + lDriveAssoc->blendAmount = 0.0f; + + if (rDriveAssoc) + rDriveAssoc->blendAmount = clamp(steerAngle * -100.0f / 61.0f, 0.0f, 1.0f); + else if (m_pMyVehicle->IsBoat() && !(m_pMyVehicle->pHandling->Flags & HANDLING_SIT_IN_BOAT)) + CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_BOAT_R); + else if (m_pMyVehicle->bLowVehicle) + CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_LOW_R); + else + CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_R); + + } + else { + if (rDriveAssoc) + rDriveAssoc->blendAmount = 0.0f; + + if (lDriveAssoc) + lDriveAssoc->blendAmount = clamp(steerAngle * 100.0f / 61.0f, 0.0f, 1.0f); + else if (m_pMyVehicle->IsBoat() && !(m_pMyVehicle->pHandling->Flags & HANDLING_SIT_IN_BOAT)) + CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_BOAT_L); + else if (m_pMyVehicle->bLowVehicle) + CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_LOW_L); + else + CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_DRIVE_L); + } + + if (lbAssoc) + lbAssoc->blendDelta = -4.0f; + } + else { + + if ((TheCamera.Cams[TheCamera.ActiveCam].Mode != CCam::MODE_1STPERSON + || TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking != LOOKING_LEFT) + && (!lbAssoc || lbAssoc->blendAmount < 1.0f && lbAssoc->blendDelta <= 0.0f)) { + + if (m_pMyVehicle->IsBoat() && !(m_pMyVehicle->pHandling->Flags & HANDLING_SIT_IN_BOAT)) + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_BOAT_LB, 4.0f); + else + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_LB, 4.0f); + } + } +} + +// --MIAMI: Done +void +CPed::PositionAttachedPed() +{ + CMatrix rotMatrix, targetMat; + targetMat = m_attachedTo->GetMatrix(); + targetMat.GetPosition() += Multiply3x3(m_attachedTo->GetMatrix(), m_vecAttachOffset); + float objAngle = m_attachedTo->GetForward().Heading(); + + if (!IsPlayer()) { + float targetAngle = objAngle; + switch (m_attachType) { + case 1: + targetAngle += HALFPI; + break; + case 2: + targetAngle += PI; + break; + case 3: + targetAngle -= HALFPI; + break; + default: + break; + } + targetAngle = CGeneral::LimitRadianAngle(targetAngle); + m_fRotationCur = CGeneral::LimitRadianAngle(m_fRotationCur); + float neededTurn = m_fRotationCur - targetAngle; + + if (neededTurn > PI) + neededTurn -= TWOPI; + else if (neededTurn < -PI) + neededTurn += TWOPI; + + if (neededTurn > m_attachRotStep) + m_fRotationCur = CGeneral::LimitRadianAngle(targetAngle + m_attachRotStep); + else if (-m_attachRotStep > neededTurn) + m_fRotationCur = CGeneral::LimitRadianAngle(targetAngle - m_attachRotStep); + else + m_fRotationCur = CGeneral::LimitRadianAngle(m_fRotationCur); + } + rotMatrix.SetRotateZ(m_fRotationCur - objAngle); + targetMat = targetMat * rotMatrix; + GetMatrix() = targetMat; + if (m_attachedTo->IsVehicle() || m_attachedTo->IsObject()) { + m_vecMoveSpeed = ((CPhysical*)m_attachedTo)->m_vecMoveSpeed; + m_vecTurnSpeed = ((CPhysical*)m_attachedTo)->m_vecTurnSpeed; + } +} + +// --MIAMI: Done +int32 +CPed::KillCharOnFootMelee(CVector &ourPos, CVector &targetPos, CVector &distWithTarget) +{ + bool killPlayerInNoPoliceZone = false; + float distWithTargetSc = distWithTarget.Magnitude(); + CPlayerPed *victimPlayer = nil; + if (m_pedInObjective->IsPlayer()) + victimPlayer = (CPlayerPed*)m_pedInObjective; + + if (victimPlayer) { + if (CCullZones::NoPolice() + || m_pedInObjective->m_pCurrentPhysSurface + && m_pedInObjective->m_pCurrentPhysSurface != m_pCurrentPhysSurface + && distWithTargetSc < 5.f) { + + if (victimPlayer && victimPlayer->m_bSpeedTimerFlag && (IsGangMember() || m_nPedType == PEDTYPE_COP) + && CharCreatedBy != MISSION_CHAR) { + GiveWeapon(WEAPONTYPE_COLT45, 1000, 1); + SetCurrentWeapon(WEAPONTYPE_COLT45); + SetMoveState(PEDMOVE_STILL); + bStopAndShoot = true; + b158_8 = true; + return CANT_ATTACK; + } + killPlayerInNoPoliceZone = true; + } + } + bNotAllowedToDuck = false; + bStopAndShoot = false; + b158_8 = false; + if (m_leaveCarTimer > CTimer::GetTimeInMilliseconds() && !bKindaStayInSamePlace) { + SetMoveState(PEDMOVE_STILL); + return CANT_ATTACK; + } + if (victimPlayer) { + CPlayerPed *player = FindPlayerPed(); + if (m_nPedType == PEDTYPE_COP && player->m_pWanted->m_bIgnoredByCops + || player->m_pWanted->m_bIgnoredByEveryone + || m_pedInObjective->bIsInWater + || m_pedInObjective->m_nPedState == PED_ARRESTED) { + + if (m_nPedState != PED_ARREST_PLAYER) + SetIdle(); + + return CANT_ATTACK; + } + } + if (victimPlayer && m_nPedType != PEDTYPE_COP && CharCreatedBy != MISSION_CHAR + && FindPlayerPed()->m_pWanted->m_CurrentCops != 0) { + SetObjective(OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE); + + return CANT_ATTACK; + } + if (m_pedInObjective->m_fHealth <= 0.0f) { + bObjectiveCompleted = true; + bScriptObjectiveCompleted = true; + return ATTACK_IN_PROGRESS; + } + bool canReachVictim = false; + uint32 endOfAttack = 0; + CWeaponInfo *wepInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + + // Already calculated at the start + // float distWithTargetSc = distWithTarget.Magnitude(); + float wepRange = 0.3f; + float wepRangeAdjusted = wepInfo->m_fRange / 2.f; + + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED && !IsPlayer() && !(m_pedStats->m_flags & STAT_CAN_KICK)) + wepRangeAdjusted -= 0.3f; + + if (distWithTargetSc <= 5.f && victimPlayer && !victimPlayer->m_bDrunkVisualsWearOff) { + + if (m_pedInObjective->EnteringCar() && wepRangeAdjusted > 2.f) { + m_vecSeekPos = m_pedInObjective->GetPosition(); + wepRangeAdjusted = 1.0f; + wepRange = 0.5f; + } else { + int8 attackDir = victimPlayer->FindMeleeAttackPoint(this, distWithTarget, endOfAttack); + if (attackDir == -1) { + m_vecSeekPos = victimPlayer->GetPosition(); + wepRange = 4.0f; + } else { + victimPlayer->GetMeleeAttackCoords(m_vecSeekPos, attackDir, wepRangeAdjusted); + distWithTargetSc = (m_vecSeekPos - GetPosition()).Magnitude(); + canReachVictim = true; + } + } + } else { + m_vecSeekPos = m_pedInObjective->GetPosition(); + wepRange = Max(0.8f, 0.9f * wepRangeAdjusted); + wepRangeAdjusted = 1.1f * wepRangeAdjusted; + if (victimPlayer && victimPlayer->m_bDrunkVisualsWearOff) + victimPlayer = nil; + } + + if (m_pedInObjective->bInVehicle && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR) { + CVehicle *vehOfTarget = m_pedInObjective->m_pMyVehicle; + + if (vehOfTarget){ + if (vehOfTarget->bIsInWater || vehOfTarget->GetStatus() == STATUS_PLAYER_DISABLED + || m_pedInObjective->IsPlayer() && CPad::GetPad(0)->ArePlayerControlsDisabled()) { + SetIdle(); + return WATCH_UNTIL_HE_DISAPPEARS; + } + SetLookFlag(vehOfTarget, false); + + if (m_nPedState != PED_CARJACK) { + if (m_pedInObjective->m_nPedState != PED_ARRESTED) { + if (m_nPedState != PED_ATTACK && !bKindaStayInSamePlace && !killPlayerInNoPoliceZone) { + + if (m_nPedType == PEDTYPE_COP || vehOfTarget->bIsBus) { + GoToNearestDoor(vehOfTarget); + } else { + m_vehEnterType = 0; + if (m_pedInObjective == vehOfTarget->pDriver || vehOfTarget->bIsBus) { + m_vehEnterType = CAR_DOOR_LF; + } else if (m_pedInObjective == vehOfTarget->pPassengers[0]) { + m_vehEnterType = CAR_DOOR_RF; + } else if (m_pedInObjective == vehOfTarget->pPassengers[1]) { + m_vehEnterType = CAR_DOOR_LR; + } else if (m_pedInObjective == vehOfTarget->pPassengers[2]) { + m_vehEnterType = CAR_DOOR_RR; + } + // Unused + // GetPositionToOpenCarDoor(vehOfTarget, m_vehEnterType); + SetSeekCar(vehOfTarget, m_vehEnterType); + SetMoveState(PEDMOVE_RUN); + } + } + } + } + } + return ATTACK_IN_PROGRESS; + } + if (m_nMoveState == PEDMOVE_STILL && IsPedInControl()) { + SetLookFlag(m_pedInObjective, false); + if(m_nPedState == PED_IDLE || m_nPedState == PED_ATTACK || m_nPedState == PED_FIGHT) + TurnBody(); + } + if (m_nPedType == PEDTYPE_COP && m_pedInObjective->IsPlayer()) { + float maxArrestDist = 1.5f; + if (((CCopPed*)this)->field_601) { + if (m_nPedState == PED_FALL) { + maxArrestDist = 3.5f; + } else if (m_nPedState != PED_DRAG_FROM_CAR) { + ((CCopPed*)this)->field_601 = 0; + } + } + + if (distWithTargetSc < maxArrestDist) { + if (m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds() + || m_pedInObjective->m_nPedState == PED_DRAG_FROM_CAR) { + + ((CCopPed*)this)->SetArrestPlayer(m_pedInObjective); + return WATCH_UNTIL_HE_DISAPPEARS; + } + } + } + + if (distWithTargetSc > wepRange && !bKindaStayInSamePlace && m_nPedState != PED_ATTACK && + (m_nPedState != PED_FIGHT || m_curFightMove == FIGHTMOVE_IDLE) && !killPlayerInNoPoliceZone) { + + bool goForward = false; + + if (m_nPedState == PED_FIGHT) { + if (canReachVictim) { + CVector attackAndVictimDist = m_vecSeekPos - m_pedInObjective->GetPosition(); + CVector victimFarness = attackAndVictimDist / wepRangeAdjusted; + CVector distVec = GetPosition() - m_pedInObjective->GetPosition(); + float distSqr = distVec.MagnitudeSqr(); + if (sq(wepRangeAdjusted) > distSqr && distSqr > 0.05f) { + distVec.Normalise(); + if (DotProduct2D(victimFarness, distVec) > Cos(DEGTORAD(30.f))) + goForward = true; + } + } + } + if (goForward) { + m_curFightMove = FIGHTMOVE_SHUFFLE_F; + CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_SH_BACK, 16.f)->SetFinishCallback(FinishFightMoveCB,this); + m_fightState = FIGHTSTATE_NO_MOVE; + m_fightButtonPressure = 0; + m_takeAStepAfterAttack = false; + + } else if (bUsePedNodeSeek && !canReachVictim) { + CVector bestCoords(0.0f, 0.0f, 0.0f); + + if (!m_pNextPathNode) + FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords); + + if (m_pNextPathNode) + m_vecSeekPos = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); + + SetSeek(m_vecSeekPos, m_distanceToCountSeekDone); + } else { + if (canReachVictim) + SetSeek(m_vecSeekPos, wepRange); + else + SetSeek(m_pedInObjective, wepRange); + } + return ATTACK_IN_PROGRESS; + } + + if (m_attackTimer < CTimer::GetTimeInMilliseconds() + && distWithTargetSc < wepRangeAdjusted && m_pedInObjective->m_nPedState != PED_GETUP && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR) { + + if (bIsDucking) { + CAnimBlendAssociation* duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN); + if (!duckAnim) + duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_LOW); + if (!duckAnim) + duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCH); + + if (duckAnim) { + duckAnim->flags |= ASSOC_DELETEFADEDOUT; + duckAnim->blendDelta = -4.0f; + } + bIsDucking = false; + return CANT_ATTACK; + } + + if (canReachVictim || !victimPlayer) { + SetMoveState(PEDMOVE_STILL); + SetAttack(m_pedInObjective); + m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints( + m_pedInObjective->GetPosition().x, m_pedInObjective->GetPosition().y, + GetPosition().x, GetPosition().y); + SetShootTimer(CGeneral::GetRandomNumberInRange(0.f, 500.f)); + + int time; + if (endOfAttack <= CTimer::GetTimeInMilliseconds()) + time = CGeneral::GetRandomNumberInRange(100.0f, 1500.0f); + else + time = endOfAttack - CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(400.0f, 1500.0f); + + SetAttackTimer(time); + bObstacleShowedUpDuringKillObjective = false; + } + return ATTACK_IN_PROGRESS; + } else { + if (!m_pedInObjective->m_pCurrentPhysSurface && m_pCurrentPhysSurface && b158_8) { + b158_8 = false; + bStopAndShoot = false; + } + + if (m_nPedState != PED_ATTACK && m_nPedState != PED_FIGHT) { + SetMoveState(PEDMOVE_STILL); + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED) + StartFightAttack(0); + } + return ATTACK_IN_PROGRESS; + } +} + +// --MIAMI: Done +int32 +CPed::KillCharOnFootArmed(CVector &ourPos, CVector &targetPos, CVector &distWithTarget) +{ + bool killPlayerInNoPoliceZone = false; + if (m_pedInObjective->IsPlayer() && CCullZones::NoPolice()) + killPlayerInNoPoliceZone = true; + + if (!bNotAllowedToDuck || killPlayerInNoPoliceZone) { + if (m_nPedType == PEDTYPE_COP && !m_pedInObjective->GetWeapon()->IsTypeMelee()) + bNotAllowedToDuck = true; + } else { + if (!m_pedInObjective->bInVehicle) { + if (m_pedInObjective->GetWeapon()->IsTypeMelee()) { + bNotAllowedToDuck = false; + bCrouchWhenShooting = false; + } else if (DuckAndCover()) { + return CANT_ATTACK; + } + } else { + bNotAllowedToDuck = false; + bCrouchWhenShooting = false; + } + } + if (m_leaveCarTimer > CTimer::GetTimeInMilliseconds() && !bKindaStayInSamePlace) { + SetMoveState(PEDMOVE_STILL); + return CANT_ATTACK; + } + if (m_pedInObjective->IsPlayer()) { + CPlayerPed *player = FindPlayerPed(); + if (m_nPedType == PEDTYPE_COP && player->m_pWanted->m_bIgnoredByCops + || player->m_pWanted->m_bIgnoredByEveryone + || m_pedInObjective->bIsInWater + || m_pedInObjective->m_nPedState == PED_ARRESTED) { + + if (m_nPedState != PED_ARREST_PLAYER) + SetIdle(); + + return CANT_ATTACK; + } + } + if (m_pedInObjective->IsPlayer() && m_nPedType != PEDTYPE_COP + && CharCreatedBy != MISSION_CHAR && FindPlayerPed()->m_pWanted->m_CurrentCops != 0) { + SetObjective(OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE); + + return CANT_ATTACK; + } + if (m_pedInObjective->m_fHealth <= 0.0f) { + bObjectiveCompleted = true; + bScriptObjectiveCompleted = true; + return CANT_ATTACK; + } + CWeaponInfo *wepInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); + float wepRange = wepInfo->m_fRange; + float wepRangeAdjusted = wepRange / 3.f; + + float distWithTargetSc = distWithTarget.Magnitude(); + if (m_pedInObjective->bInVehicle && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR) { + CVehicle *vehOfTarget = m_pedInObjective->m_pMyVehicle; + if (vehOfTarget->bIsInWater || vehOfTarget->GetStatus() == STATUS_PLAYER_DISABLED + || m_pedInObjective->IsPlayer() && CPad::GetPad(0)->ArePlayerControlsDisabled()) { + SetIdle(); + return WATCH_UNTIL_HE_DISAPPEARS; + } + SetLookFlag(vehOfTarget, false); + if (m_nMoveState == PEDMOVE_STILL && IsPedInControl()) + TurnBody(); + + if (m_nPedState != PED_CARJACK) { + if (m_pedInObjective->m_nPedState != PED_ARRESTED) { + if (m_attackTimer < CTimer::GetTimeInMilliseconds() && distWithTargetSc < wepRange && distWithTargetSc > 3.0f) { + + SetAttack(vehOfTarget); + if (m_pPointGunAt) + m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt); + + m_pPointGunAt = vehOfTarget; + if (vehOfTarget) + vehOfTarget->RegisterReference((CEntity **) &m_pPointGunAt); + + SetShootTimer(CGeneral::GetRandomNumberInRange(500, 2000)); + if (distWithTargetSc <= m_distanceToCountSeekDone) { + SetAttackTimer(CGeneral::GetRandomNumberInRange(200, 500)); + SetMoveState(PEDMOVE_STILL); + } else { + SetAttackTimer(CGeneral::GetRandomNumberInRange(2000, 5000)); + } + return ATTACK_IN_PROGRESS; + } else if (m_nPedState != PED_ATTACK && !bKindaStayInSamePlace && !killPlayerInNoPoliceZone) { + if (vehOfTarget) { + if (m_nPedType == PEDTYPE_COP || vehOfTarget->bIsBus) { + GoToNearestDoor(vehOfTarget); + } else { + m_vehEnterType = 0; + if (m_pedInObjective == vehOfTarget->pDriver || vehOfTarget->bIsBus) { + m_vehEnterType = CAR_DOOR_LF; + } else if (m_pedInObjective == vehOfTarget->pPassengers[0]) { + m_vehEnterType = CAR_DOOR_RF; + } else if (m_pedInObjective == vehOfTarget->pPassengers[1]) { + m_vehEnterType = CAR_DOOR_LR; + } else if (m_pedInObjective == vehOfTarget->pPassengers[2]) { + m_vehEnterType = CAR_DOOR_RR; + } + // Unused + // GetPositionToOpenCarDoor(vehOfTarget, m_vehEnterType); + SetSeekCar(vehOfTarget, m_vehEnterType); + SetMoveState(PEDMOVE_RUN); + } + } + } + } + } + return ATTACK_IN_PROGRESS; + } + if (m_nMoveState == PEDMOVE_STILL && IsPedInControl()) { + SetLookFlag(m_pedInObjective, false); + TurnBody(); + } + if (m_nPedType == PEDTYPE_COP && m_pedInObjective->IsPlayer()) { + float maxArrestDist = 1.5f; + if (((CCopPed*)this)->field_601) { + if (m_nPedState == PED_FALL) { + maxArrestDist = 3.5f; + } else if (m_nPedState != PED_DRAG_FROM_CAR) { + ((CCopPed*)this)->field_601 = 0; + } + } + + if (distWithTargetSc < maxArrestDist) { + if (m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds() + || m_pedInObjective->m_nPedState == PED_DRAG_FROM_CAR) { + + ((CCopPed*)this)->SetArrestPlayer(m_pedInObjective); + return WATCH_UNTIL_HE_DISAPPEARS; + } + } + } + /* + if (distWithTargetSc > 0.1f) { + junk code + } */ + + if (m_shotTime != 0 && m_ceaseAttackTimer != 0) { + if (CTimer::GetTimeInMilliseconds() > m_ceaseAttackTimer + m_shotTime) { + ClearLookFlag(); + bObjectiveCompleted = true; + m_shotTime = 0; + return CANT_ATTACK; + } + } + + if (!bKindaStayInSamePlace && !bStopAndShoot && m_nPedState != PED_ATTACK && !bDuckAndCover && !killPlayerInNoPoliceZone) { + if (distWithTargetSc > wepRange + || m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds() + || m_pedInObjective->m_nPedState == PED_ARRESTED + || m_pedInObjective->EnteringCar() && distWithTargetSc < 3.0f) { + + if (m_pedInObjective->EnteringCar()) + wepRangeAdjusted = 2.0f; + + if (bUsePedNodeSeek) { + CVector bestCoords(0.0f, 0.0f, 0.0f); + m_vecSeekPos = m_pedInObjective->GetPosition(); + + if (!m_pNextPathNode) + FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords); + + if (m_pNextPathNode) + m_vecSeekPos = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); + + SetSeek(m_vecSeekPos, m_distanceToCountSeekDone); + } else { + SetSeek(m_pedInObjective, wepRangeAdjusted); + } + if (m_pedInObjective->m_pCurrentPhysSurface && distWithTargetSc < 5.0f) { + bStopAndShoot = true; + b158_8 = true; + SetMoveState(PEDMOVE_STILL); + } else if (b158_8) { + bStopAndShoot = false; + b158_8 = false; + } + return ATTACK_IN_PROGRESS; + } + } + if (m_attackTimer < CTimer::GetTimeInMilliseconds() + && distWithTargetSc < wepRange && m_pedInObjective->m_nPedState != PED_GETUP && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR) { + + if (bIsDucking && !bCrouchWhenShooting) { + CAnimBlendAssociation* duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN); + if (!duckAnim) + duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_LOW); + if (!duckAnim) + duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCH); + + if (duckAnim) { + duckAnim->flags |= ASSOC_DELETEFADEDOUT; + duckAnim->blendDelta = -4.0f; + } + bIsDucking = false; + return CANT_ATTACK; + } + bObstacleShowedUpDuringKillObjective = false; + SetAttack(m_pedInObjective); + if (m_pPointGunAt) + m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt); + + m_pPointGunAt = m_pedInObjective; + if (m_pedInObjective) + m_pedInObjective->RegisterReference((CEntity**)&m_pPointGunAt); + + SetShootTimer(CGeneral::GetRandomNumberInRange(900.0f, 1500.0f)); + + int time; + if (distWithTargetSc <= wepRangeAdjusted) + time = CGeneral::GetRandomNumberInRange(100.0f, 500.0f); + else + time = CGeneral::GetRandomNumberInRange(1500.0f, 3000.0f); + + SetAttackTimer(time); + } else { + if (!m_pedInObjective->m_pCurrentPhysSurface && b158_8) { + b158_8 = false; + bStopAndShoot = false; + } + + if (m_nPedState != PED_ATTACK && m_nPedState != PED_FIGHT) { + if (bNotAllowedToDuck && bKindaStayInSamePlace && !bIsDucking && bCrouchWhenShooting) { + SetDuck(CGeneral::GetRandomNumberInRange(4000, 5000), false); + return CANT_ATTACK; + } + if (bObstacleShowedUpDuringKillObjective) { + if (m_nPedType == PEDTYPE_COP) { + if (GetWeapon()->m_eWeaponType > WEAPONTYPE_COLT45 + || m_fleeFrom && m_fleeFrom->IsObject()) { + wepRangeAdjusted = 6.0f; + } else if (m_fleeFrom && m_fleeFrom->IsVehicle()) { + wepRangeAdjusted = 4.0f; + } else { + wepRangeAdjusted = 2.0f; + } + } else { + wepRangeAdjusted = 2.0f; + } + } + if (distWithTargetSc <= wepRangeAdjusted) { + SetMoveState(PEDMOVE_STILL); + bIsPointingGunAt = true; + if (m_nPedState != PED_AIM_GUN && !bDuckAndCover) { + m_attackTimer = CTimer::GetTimeInMilliseconds(); + SetIdle(); + } + } else { + if (m_nPedState != PED_SEEK_ENTITY && m_nPedState != PED_SEEK_POS + && !bStopAndShoot && !killPlayerInNoPoliceZone && !bKindaStayInSamePlace) { + Say(SOUND_PED_ATTACK); + SetSeek(m_pedInObjective, wepRangeAdjusted); + bIsRunning = true; + if (m_nPedType == PEDTYPE_COP && FindPlayerPed()->m_pWanted->m_CurrentCops > 1) { + if (CGeneral::GetRandomNumber() & 1) + Say(SOUND_PED_GUNAIMEDAT3); + else + Say(SOUND_PED_GUNAIMEDAT2); + } + } + } + } + } + + if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer) + m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(m_pedInObjective->GetPosition().x, m_pedInObjective->GetPosition().y, GetPosition().x, GetPosition().y); + + return ATTACK_IN_PROGRESS; +} + +void +PlayRandomAnimationsFromAnimBlock(CPed* ped, AssocGroupId animGroup, uint32 first, uint32 amount) +{ + if (!ped->IsPedInControl()) + return; + + const char *groupName = CAnimManager::GetAnimGroupName(animGroup); + CAnimBlock *animBlock = CAnimManager::GetAnimationBlock(groupName); + CAnimBlendAssociation *assoc; + for (assoc = RpAnimBlendClumpGetFirstAssociation(ped->GetClump()); assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) { + int first = animBlock->firstIndex; + int index = assoc->hierarchy - CAnimManager::GetAnimation(0); + if (index >= first && index < first + animBlock->numAnims) { + break; + } + } + + if (CTimer::GetTimeInMilliseconds() > ped->m_nWaitTimer && assoc) + assoc->flags &= ~ASSOC_REPEAT; + + if (!assoc || assoc->blendDelta < 0.0f) { + int selectedAnimOffset; + do + selectedAnimOffset = CGeneral::GetRandomNumberInRange(0, amount); + while (assoc && first + selectedAnimOffset == assoc->animId); + + assoc = CAnimManager::BlendAnimation(ped->GetClump(), animGroup, (AnimationId)(first + selectedAnimOffset), 3.0f); + + assoc->SetFinishCallback(CPed::FinishedWaitCB, ped); + if (assoc->flags & ASSOC_REPEAT) + ped->m_nWaitTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(3000, 8000); + else + ped->m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 8000; + } +} + +bool +IsPedPointerValid_NotInWorld(CPed* pPed) +{ + if (!pPed) + return false; + int index = CPools::GetPedPool()->GetJustIndex(pPed); +#ifdef FIX_BUGS + if (index < 0 || index >= NUMPEDS) +#else + if (index < 0 || index > NUMPEDS) +#endif + return false; + return true; +} + +bool +IsPedPointerValid(CPed* pPed) +{ + if (!IsPedPointerValid_NotInWorld(pPed)) + return false; + if (pPed->bInVehicle && pPed->m_pMyVehicle) + return IsEntityPointerValid(pPed->m_pMyVehicle); + return pPed->m_entryInfoList.first || pPed == FindPlayerPed(); +} diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 63d8e598..6b0cc5fb 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -9,16 +9,18 @@ #include "Physical.h" #include "Weapon.h" #include "WeaponInfo.h" +#include "AnimationId.h" +#include "PathFind.h" #define FEET_OFFSET 1.04f #define CHECK_NEARBY_THINGS_MAX_DIST 15.0f -struct CPathNode; class CAccident; class CObject; class CFire; struct AnimBlendFrameData; class CAnimBlendAssociation; +class CPedAttractor; struct PedAudioData { @@ -28,6 +30,13 @@ struct PedAudioData int m_nMaxRandomDelayTime; }; +enum +{ + ATTACK_IN_PROGRESS, + CANT_ATTACK, + WATCH_UNTIL_HE_DISAPPEARS, +}; + enum eFormation { FORMATION_UNDEFINED, @@ -78,11 +87,11 @@ struct FightMove float endFireTime; float comboFollowOnTime; float strikeRadius; + float extendReachMultiplier; uint8 hitLevel; // FightMoveHitLevel uint8 damage; uint8 flags; }; -VALIDATE_SIZE(FightMove, 0x18); // TODO: This is eFightState on mobile. enum PedFightMoves @@ -93,13 +102,20 @@ enum PedFightMoves FIGHTMOVE_IDLE, FIGHTMOVE_SHUFFLE_F, FIGHTMOVE_KNEE, - FIGHTMOVE_HEADBUTT, - FIGHTMOVE_PUNCHJAB, FIGHTMOVE_PUNCHHOOK, - FIGHTMOVE_KICK, + FIGHTMOVE_PUNCHJAB, + FIGHTMOVE_PUNCH, FIGHTMOVE_LONGKICK, FIGHTMOVE_ROUNDHOUSE, - FIGHTMOVE_BODYBLOW, + // Directionals + FIGHTMOVE_FWDLEFT, + FIGHTMOVE_FWDRIGHT, + FIGHTMOVE_BACKKICK, + FIGHTMOVE_BACKFLIP, + FIGHTMOVE_BACKLEFT, + FIGHTMOVE_BACKRIGHT, + FIGHTMOVE_RIGHTSWEEP, + // Special FIGHTMOVE_GROUNDKICK, // Opponent FIGHTMOVE_HITFRONT, @@ -112,6 +128,9 @@ enum PedFightMoves FIGHTMOVE_HITBIGSTEP, FIGHTMOVE_HITONFLOOR, FIGHTMOVE_HITBEHIND, + FIGHTMOVE_MELEE1, + FIGHTMOVE_MELEE2, + FIGHTMOVE_MELEE3, FIGHTMOVE_IDLE2NORM, NUM_FIGHTMOVES }; @@ -148,15 +167,31 @@ enum eWaitState { WAITSTATE_PLAYANIM_HANDSUP, WAITSTATE_PLAYANIM_HANDSCOWER, WAITSTATE_PLAYANIM_CHAT, - WAITSTATE_FINISH_FLEE + WAITSTATE_FINISH_FLEE, + WAITSTATE_SIT_DOWN, + WAITSTATE_SIT_DOWN_RVRS, + WAITSTATE_SIT_UP, + WAITSTATE_SIT_IDLE, + WAITSTATE_USE_ATM, + WAITSTATE_SUN_BATHE_PRE, + WAITSTATE_SUN_BATHE_DOWN, + WAITSTATE_SUN_BATHE_IDLE, + WAITSTATE_RIOT, + WAITSTATE_FAST_FALL, + WAITSTATE_BOMBER, + WAITSTATE_STRIPPER, + WAITSTATE_GROUND_ATTACK, + WAITSTATE_LANCESITTING, + WAITSTATE_PLAYANIM_HANDSUP_SIMPLE, }; enum eObjective : uint32 { OBJECTIVE_NONE, OBJECTIVE_WAIT_ON_FOOT, + OBJECTIVE_WAIT_ON_FOOT_FOR_COP, OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE, OBJECTIVE_GUARD_SPOT, - OBJECTIVE_GUARD_AREA, // not implemented + OBJECTIVE_GUARD_AREA, OBJECTIVE_WAIT_IN_CAR, OBJECTIVE_WAIT_IN_CAR_THEN_GET_OUT, OBJECTIVE_KILL_CHAR_ON_FOOT, @@ -164,19 +199,21 @@ enum eObjective : uint32 { OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS, OBJECTIVE_GOTO_CHAR_ON_FOOT, + OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING, + OBJECTIVE_HASSLE_CHAR, OBJECTIVE_FOLLOW_CHAR_IN_FORMATION, OBJECTIVE_LEAVE_CAR, OBJECTIVE_ENTER_CAR_AS_PASSENGER, OBJECTIVE_ENTER_CAR_AS_DRIVER, - OBJECTIVE_FOLLOW_CAR_IN_CAR, // not implemented - OBJECTIVE_FIRE_AT_OBJECT_FROM_VEHICLE, // not implemented - OBJECTIVE_DESTROY_OBJECT, // not implemented + OBJECTIVE_FOLLOW_CAR_IN_CAR, + OBJECTIVE_FIRE_AT_OBJECT_FROM_VEHICLE, + OBJECTIVE_DESTROY_OBJECT, OBJECTIVE_DESTROY_CAR, OBJECTIVE_GOTO_AREA_ANY_MEANS, OBJECTIVE_GOTO_AREA_ON_FOOT, OBJECTIVE_RUN_TO_AREA, - OBJECTIVE_GOTO_AREA_IN_CAR, // not implemented - OBJECTIVE_FOLLOW_CAR_ON_FOOT_WITH_OFFSET, // not implemented + OBJECTIVE_GOTO_AREA_IN_CAR, + OBJECTIVE_FOLLOW_CAR_ON_FOOT_WITH_OFFSET, OBJECTIVE_GUARD_ATTACK, OBJECTIVE_SET_LEADER, OBJECTIVE_FOLLOW_ROUTE, @@ -185,22 +222,44 @@ enum eObjective : uint32 { OBJECTIVE_CATCH_TRAIN, OBJECTIVE_BUY_ICE_CREAM, OBJECTIVE_STEAL_ANY_CAR, + OBJECTIVE_STEAL_ANY_MISSION_CAR, OBJECTIVE_MUG_CHAR, + OBJECTIVE_LEAVE_CAR_AND_DIE, + OBJECTIVE_GOTO_SEAT_ON_FOOT, + OBJECTIVE_GOTO_ATM_ON_FOOT, OBJECTIVE_FLEE_CAR, -#ifdef VC_PED_PORTS - OBJECTIVE_LEAVE_CAR_AND_DIE -#endif + OBJECTIVE_SUN_BATHE, + OBJECTIVE_GOTO_BUS_STOP_ON_FOOT, + OBJECTIVE_GOTO_PIZZA_ON_FOOT, + OBJECTIVE_GOTO_SHELTER_ON_FOOT, + OBJECTIVE_AIM_GUN_AT, + OBJECTIVE_WANDER, + OBJECTIVE_WAIT_ON_FOOT_AT_SHELTER, + OBJECTIVE_SPRINT_TO_AREA, + OBJECTIVE_KILL_CHAR_ON_BOAT, + OBJECTIVE_SOLICIT_FOOT, + OBJECTIVE_WAIT_ON_FOOT_AT_BUS_STOP, + OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT, + OBJECTIVE_WAIT_ON_FOOT_AT_ICE_CREAM_VAN, + OBJ_55, + OBJ_56, + OBJ_57, + OBJ_58, + OBJ_59 + }; enum { RANDOM_CHAR = 1, MISSION_CHAR, + TODO_CHAR, // TODO(Miami) }; enum PedLineUpPhase { LINE_UP_TO_CAR_START, LINE_UP_TO_CAR_END, - LINE_UP_TO_CAR_2 // Buggy. Used for cops arresting you from passenger door + LINE_UP_TO_CAR_2, // Buggy. Used for cops arresting you from passenger door + LINE_UP_TO_CAR_FALL }; enum PedOnGroundState { @@ -251,12 +310,17 @@ enum PedState PED_INVESTIGATE, PED_STEP_AWAY, PED_ON_FIRE, + PED_SUN_BATHE, + PED_FLASH, + PED_JOG, + PED_ANSWER_MOBILE, PED_UNKNOWN, // Same with IDLE, but also infects up to 5 peds with same pedType and WANDER_PATH, so they become stone too. HANG_OUT in Fire_Head's idb PED_STATES_NO_AI, - // One of these states isn't on PS2 - start + PED_ABSEIL, + PED_SIT, PED_JUMP, PED_FALL, PED_GETUP, @@ -267,7 +331,6 @@ enum PedState PED_ENTER_TRAIN, PED_EXIT_TRAIN, PED_ARREST_PLAYER, - // One of these states isn't on PS2 - end PED_DRIVING, PED_PASSENGER, @@ -282,14 +345,17 @@ enum PedState PED_EXIT_CAR, PED_HANDS_UP, PED_ARRESTED, + PED_DEPLOY_STINGER }; enum eMoveState { PEDMOVE_NONE, PEDMOVE_STILL, PEDMOVE_WALK, + PEDMOVE_JOG, PEDMOVE_RUN, PEDMOVE_SPRINT, + PEDMOVE_THROWN }; class CVehicle; @@ -297,6 +363,9 @@ class CVehicle; class CPed : public CPhysical { public: +#ifdef USE_CUTSCENE_SHADOW_FOR_PED + class CCutsceneShadow *m_pRTShadow; +#endif // 0x128 CStoredCollPoly m_collPoly; float m_fCollisionSpeed; @@ -339,7 +408,7 @@ public: uint32 bScriptObjectiveCompleted : 1; uint32 bKindaStayInSamePlace : 1; - uint32 bBeingChasedByPolice : 1; // Unused VC leftover. Should've been set for criminal/gang members + uint32 bBeingChasedByPolice : 1; uint32 bNotAllowedToDuck : 1; uint32 bCrouchWhenShooting : 1; uint32 bIsDucking : 1; @@ -379,21 +448,59 @@ public: uint32 bVehExitWillBeInstant : 1; uint32 bHasAlreadyBeenRecorded : 1; uint32 bFallenDown : 1; -#ifdef VC_PED_PORTS - uint32 bSomeVCflag1 : 1; -#endif #ifdef PED_SKIN uint32 bDontAcceptIKLookAts : 1; // TODO: find uses of this #endif - uint32 m_ped_flagI40 : 1; - uint32 m_ped_flagI80 : 1; // originally unused, KANGAROO_CHEAT define makes use of this as cheat toggle + uint32 bReachedAttractorHeadingTarget : 1; + uint32 bTurnedAroundOnAttractor : 1; + + uint32 bHasAlreadyUsedAttractor : 1; + //uint32 b155_2 + uint32 bCarPassenger : 1; + //uint32 b155_8 + //uint32 b155_10 + uint32 bMiamiViceCop : 1; + uint32 bMoneyHasBeenGivenByScript : 1; // + uint32 bHasBeenPhotographed : 1; // + + uint32 bIsDrowning : 1; + uint32 bDrownsInWater : 1; + //uint32 b156_4 + uint32 bHeldHostageInCar : 1; + uint32 bIsPlayerFriend : 1; + uint32 bHeadStuckInCollision : 1; + uint32 bDeadPedInFrontOfCar : 1; + uint32 bStayInCarOnJack : 1; + uint32 bDontFight : 1; + uint32 bDoomAim : 1; + uint32 bCanBeShotInVehicle : 1; + //uint32 b157_8 + uint32 bMakeFleeScream : 1; + uint32 bPushedAlongByCar : 1; + uint32 b157_40 : 1; + uint32 bIgnoreThreatsBehindObjects : 1; + + uint32 bNeverEverTargetThisPed : 1; + uint32 bCrouchWhenScared : 1; + uint32 bKnockedOffBike : 1; + uint32 b158_8 : 1; + uint32 b158_10 : 1; + uint32 bBoughtIceCream : 1; + uint32 b158_40 : 1; + //uint32 b158_80 + + // our own flags + uint32 m_ped_flagI80 : 1; // KANGAROO_CHEAT define makes use of this as cheat toggle + + uint8 m_gangFlags; uint8 CharCreatedBy; eObjective m_objective; eObjective m_prevObjective; CPed *m_pedInObjective; CVehicle *m_carInObjective; CVector m_nextRoutePointPos; + float m_attractorHeading; CPed *m_leader; eFormation m_pedFormation; uint32 m_fearFlags; @@ -422,16 +529,23 @@ public: int32 m_nPrevMoveState; eWaitState m_nWaitState; uint32 m_nWaitTimer; - void *m_pPathNodesStates[8]; // unused, probably leftover from VC - CVector2D m_stPathNodeStates[10]; - uint16 m_nPathNodes; - int16 m_nCurPathNode; - int8 m_nPathDir; -public: - CPathNode *m_pLastPathNode; - CPathNode *m_pNextPathNode; + CPathNode* m_pathNodesToGo[8]; + int16 m_nNumPathNodes; + int16 m_nCurPathNodeId; + CEntity* m_followPathWalkAroundEnt; + CEntity* m_followPathTargetEnt; + uint32 m_pathNodeTimer; + CPathNode m_pathNodeObjPool[8]; + CPathNode* m_pCurPathNode; + char m_nPathDir; + CPathNode* m_pLastPathNode; + CPathNode* m_pNextPathNode; + CVector m_followPathDestPos; + float m_followPathAbortDist; + eMoveState m_followPathMoveState; float m_fHealth; float m_fArmour; + uint32 m_nExtendedRangeTimer; int16 m_routeLastPoint; uint16 m_routeStartPoint; int16 m_routePointsPassed; @@ -451,12 +565,13 @@ public: CVehicle *m_pMyVehicle; bool bInVehicle; float m_distanceToCountSeekDone; + float m_acceptableHeadingOffset; + CPedAttractor* m_attractor; + int32 m_positionInQueue; + CVehicle* m_vehicleInAccident; + bool bRunningToPhone; int16 m_phoneId; -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - bool m_facePhoneStart; - CEntity *m_victimOfPlayerCrime; -#endif eCrimeType m_crimeToReportOnPhone; uint32 m_phoneTalkTimer; CAccident *m_lastAccident; @@ -466,14 +581,17 @@ public: float m_fleeFromPosY; CEntity *m_fleeFrom; uint32 m_fleeTimer; + CEntity* pThreatEx; // TODO(Miami): What is this? CEntity* m_collidingEntityWhileFleeing; uint32 m_collidingThingTimer; CEntity *m_pCollidingEntity; uint8 m_stateUnused; uint32 m_timerUnused; class CRange2D *m_wanderRangeBounds; - CWeapon m_weapons[WEAPONTYPE_TOTAL_INVENTORY_WEAPONS]; + CWeapon m_weapons[TOTAL_WEAPON_SLOTS]; eWeaponType m_storedWeapon; + eWeaponType m_delayedWeapon; + uint32 m_delayedWeaponAmmo; uint8 m_currentWeapon; // eWeaponType uint8 m_maxWeaponTypeAllowed; // eWeaponType uint8 m_wepSkills; @@ -481,9 +599,11 @@ public: CEntity *m_pPointGunAt; CVector m_vecHitLastPos; uint32 m_curFightMove; + uint32 m_lastFightMove; uint8 m_fightButtonPressure; FightState m_fightState; bool m_takeAStepAfterAttack; + uint8 m_bleedCounter; CFire *m_pFire; CEntity *m_pLookTarget; float m_fLookDirection; @@ -499,12 +619,26 @@ public: uint32 m_duckTimer; uint32 m_duckAndCoverTimer; uint32 m_bloodyFootprintCountOrDeathTime; // Death time when bDoBloodyFootprints is false. Weird decision + uint32 m_shotTime; + uint32 m_ceaseAttackTimer; uint8 m_panicCounter; bool m_deadBleeding; int8 m_bodyPartBleeding; // PedNode, but -1 if there isn't CPed *m_nearPeds[10]; uint16 m_numNearPeds; - int8 m_lastWepDam; + uint16 m_nPedMoney; + int8 m_lastWepDam; + CEntity *m_lastDamEntity; + CEntity *m_attachedTo; + CVector m_vecAttachOffset; + uint16 m_attachType; + float m_attachRotStep; + uint32 m_attachWepAmmo; + uint32 m_threatFlags; + uint32 m_threatCheck; + uint32 m_lastThreatCheck; + uint32 m_delayedSoundID; + uint32 m_delayedSoundTimer; uint32 m_lastSoundStart; uint32 m_soundStart; uint16 m_lastQueuedSound; @@ -536,14 +670,15 @@ public: void AimGun(void); void KillPedWithCar(CVehicle *veh, float impulse); void Say(uint16 audio); - void SetLookFlag(CEntity *target, bool keepTryingToLook); - void SetLookFlag(float direction, bool keepTryingToLook); + void Say(uint16 audio, int32 time); + void SetLookFlag(CEntity* target, bool keepTryingToLook, bool cancelPrevious = false); + void SetLookFlag(float direction, bool keepTryingToLook, bool cancelPrevious = false); void SetLookTimer(int time); - void SetDie(AnimationId anim, float arg1, float arg2); + void SetDie(AnimationId anim = ANIM_KO_SHOT_FRONT1, float arg1 = 4.0f, float arg2 = 0.0f); void SetDead(void); void ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer); void RemoveBodyPart(PedNode nodeId, int8 direction); - bool OurPedCanSeeThisOne(CEntity *target); + bool OurPedCanSeeThisOne(CEntity *target, bool shootablesDoBlock = false); void Avoid(void); void Attack(void); void ClearAimFlag(void); @@ -552,9 +687,10 @@ public: void ClearAttack(void); bool IsPedHeadAbovePos(float zOffset); void RemoveWeaponModel(int modelId); - void SetCurrentWeapon(uint32 weaponType); + void SetCurrentWeapon(eWeaponType weaponType); + void SetCurrentWeapon(int weapon); void Duck(void); - void ClearDuck(void); + void ClearDuck(bool = false); void ClearPointGunAt(void); void BeingDraggedFromCar(void); void RestartNonPartialAnims(void); @@ -563,7 +699,7 @@ public: void PlayFootSteps(void); void QuitEnteringCar(void); void BuildPedLists(void); - uint32 GiveWeapon(eWeaponType weaponType, uint32 ammo); + int32 GiveWeapon(eWeaponType weaponType, uint32 ammo, bool unused = false); void CalculateNewOrientation(void); float WorkOutHeadingForMovingFirstPerson(float); void CalculateNewVelocity(void); @@ -577,11 +713,11 @@ public: void SetObjective(eObjective); void SetObjective(eObjective, int16, int16); void SetObjective(eObjective, CVector); - void SetObjective(eObjective, CVector, float); + void SetObjective(eObjective, float, const CVector&); void ClearChat(void); void InformMyGangOfAttack(CEntity*); void ReactToAttack(CEntity*); - void SetDuck(uint32); + void SetDuck(uint32, bool = false); void RegisterThreatWithGangPeds(CEntity*); bool TurnBody(void); void Chat(void); @@ -591,9 +727,6 @@ public: bool MakePhonecall(void); bool FacePhone(void); CPed *CheckForDeadPeds(void); -#ifdef PEDS_REPORT_CRIMES_ON_PHONE - int32 CheckForPlayerCrimes(CPed *victim = nil); -#endif bool CheckForExplosions(CVector2D &area); CPed *CheckForGunShots(void); PointBlankNecessity CheckForPointBlankPeds(CPed*); @@ -602,7 +735,9 @@ public: void SetPointGunAt(CEntity*); bool Seek(void); bool SetWanderPath(int8); - bool SetFollowPath(CVector); + bool SetFollowPath(CVector dest, float radius, eMoveState state, CEntity*, CEntity*, int); + bool SetFollowPathStatic(void); + bool SetFollowPathDynamic(void); void ClearAttackByRemovingAnim(void); void SetStoredState(void); void StopNonPartialAnims(void); @@ -628,7 +763,10 @@ public: void SetAttack(CEntity*); void StartFightAttack(uint8); void SetWaitState(eWaitState, void*); - bool FightStrike(CVector&); + bool FightStrike(CVector&, bool); + void FightHitPed(CPed*, CVector&, CVector&, int16); + int32 ChooseAttackPlayer(uint8, bool); + int32 ChooseAttackAI(uint8, bool); int GetLocalDirection(const CVector2D &); void StartFightDefend(uint8, uint8, uint8); void PlayHitSound(CPed*); @@ -638,8 +776,11 @@ public: void RemoveInCarAnims(void); void CollideWithPed(CPed*); void SetDirectionToWalkAroundObject(CEntity*); + bool SetDirectionToWalkAroundVehicle(CVehicle*); + void RemoveWeaponAnims(int, float); void CreateDeadPedMoney(void); void CreateDeadPedWeaponPickups(void); + void CreateDeadPedPickupCoors(float *x, float *y, float *z); void SetAttackTimer(uint32); void SetBeingDraggedFromCar(CVehicle*, uint32, bool); void SetRadioStation(void); @@ -647,19 +788,17 @@ public: void SetChat(CEntity*, uint32); void DeadPedMakesTyresBloody(void); void MakeTyresMuddySectorList(CPtrList&); - uint8 DoesLOSBulletHitPed(CColPoint &point); bool DuckAndCover(void); void EndFight(uint8); void EnterCar(void); uint8 GetNearestTrainPedPosition(CVehicle*, CVector&); uint8 GetNearestTrainDoor(CVehicle*, CVector&); - void LineUpPedWithTrain(void); void ExitCar(void); void Fight(void); bool FindBestCoordsFromNodes(CVector, CVector*); void Wait(void); void ProcessObjective(void); - bool SeekFollowingPath(CVector*); + CVector *SeekFollowingPath(void); void Flee(void); void FollowPath(void); CVector GetFormationPosition(void); @@ -668,6 +807,7 @@ public: int GetNextPointOnRoute(void); uint8 GetPedRadioCategory(uint32); int GetWeaponSlot(eWeaponType); + bool CanWeRunAndFireWithWeapon(void); void GoToNearestDoor(CVehicle*); bool HaveReachedNextPointOnRoute(float); void Idle(void); @@ -700,7 +840,6 @@ public: void SetExitCar(CVehicle*, uint32); void SetFormation(eFormation); bool WillChat(CPed*); - void SetEnterTrain(CVehicle*, uint32); void SetEnterCar_AllClear(CVehicle*, uint32, uint32); void SetSolicit(uint32 time); void ScanForInterestingStuff(void); @@ -709,6 +848,22 @@ public: bool WarpPedToNearLeaderOffScreen(void); void Solicit(void); void SetExitBoat(CVehicle*); + void ClearFollowPath(); + void GiveDelayedWeapon(eWeaponType weapon, uint32 ammo); + void RequestDelayedWeapon(); + void AddInCarAnims(CVehicle* car, bool isDriver); + bool CanBeDamagedByThisGangMember(CPed*); + void AnswerMobile(void); + void BuyIceCream(void); + void CheckThreatValidity(void); + void ClearAnswerMobile(void); + void SetAnswerMobile(void); + void AttachPedToEntity(CEntity*, CVector, uint16, float, eWeaponType); + void DettachPedFromEntity(); + void PedShuffle(); + void DriveVehicle(); + void PositionAttachedPed(); + bool CanUseTorsoWhenLooking(); // Static methods static CVector GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float offset); @@ -736,8 +891,11 @@ public: static void PedSetDraggedOutCarCB(CAnimBlendAssociation *assoc, void *arg); static void PedAnimStepOutCarCB(CAnimBlendAssociation *assoc, void *arg); static void PedSetInTrainCB(CAnimBlendAssociation *assoc, void *arg); +#ifdef GTA_TRAIN static void PedSetOutTrainCB(CAnimBlendAssociation *assoc, void *arg); +#endif static void FinishedAttackCB(CAnimBlendAssociation *assoc, void *arg); + static void FinishedReloadCB(CAnimBlendAssociation *assoc, void *arg); static void FinishFightMoveCB(CAnimBlendAssociation *assoc, void *arg); static void PedAnimDoorCloseRollingCB(CAnimBlendAssociation *assoc, void *arg); static void FinishJumpCB(CAnimBlendAssociation *assoc, void *arg); @@ -747,6 +905,7 @@ public: static void PedSetDraggedOutCarPositionCB(CAnimBlendAssociation *assoc, void *arg); bool IsPlayer(void); + bool IsFemale(void) { return m_nPedType == PEDTYPE_CIVFEMALE || m_nPedType == PEDTYPE_PROSTITUTE; } bool UseGroundColModel(void); bool CanSetPedState(void); bool IsPedInControl(void); @@ -766,8 +925,14 @@ public: void SetPedStats(ePedStats); bool IsGangMember(void); void Die(void); +#ifdef GTA_TRAIN void EnterTrain(void); void ExitTrain(void); + void SetExitTrain(CVehicle*); + void SetPedPositionInTrain(void); + void LineUpPedWithTrain(void); + void SetEnterTrain(CVehicle*, uint32); +#endif void Fall(void); bool IsPedShootable(void); void Look(void); @@ -775,29 +940,34 @@ public: void RestoreHeadPosition(void); void PointGunAt(void); bool ServiceTalkingWhenDead(void); - void SetPedPositionInTrain(void); void SetShootTimer(uint32); void SetSeekCar(CVehicle*, uint32); void SetSeekBoatPosition(CVehicle*); - void SetExitTrain(CVehicle*); void WanderRange(void); void SetFollowRoute(int16, int16); void SeekBoatPosition(void); void UpdatePosition(void); CObject *SpawnFlyingComponent(int, int8); void SetCarJack_AllClear(CVehicle*, uint32, uint32); -#ifdef VC_PED_PORTS bool CanPedJumpThis(CEntity*, CVector*); -#else - bool CanPedJumpThis(CEntity*); -#endif + void SetNewAttraction(CPedAttractor* pAttractor, const CVector& pos, float, float, int); + void ClearWaitState(void); + void Undress(const char*); + void Dress(void); + int32 KillCharOnFootMelee(CVector&, CVector&, CVector&); + int32 KillCharOnFootArmed(CVector&, CVector&, CVector&); - bool HasWeapon(uint8 weaponType) { return m_weapons[weaponType].m_eWeaponType == weaponType; } - CWeapon &GetWeapon(uint8 weaponType) { return m_weapons[weaponType]; } + bool HasWeaponSlot(uint8 slot) { return m_weapons[slot].m_eWeaponType != WEAPONTYPE_UNARMED; } + CWeapon& GetWeapon(uint8 slot) { return m_weapons[slot]; } CWeapon *GetWeapon(void) { return &m_weapons[m_currentWeapon]; } PedState GetPedState(void) { return m_nPedState; } - void SetPedState(PedState state) { m_nPedState = state; } + void SetPedState(PedState state) + { + if (GetPedState() == PED_FOLLOW_PATH) + ClearFollowPath(); + m_nPedState = state; + } bool Dead(void) { return m_nPedState == PED_DEAD; } bool Dying(void) { return m_nPedState == PED_DIE; } bool DyingOrDead(void) { return m_nPedState == PED_DIE || m_nPedState == PED_DEAD; } @@ -807,10 +977,86 @@ public: bool Driving(void) { return m_nPedState == PED_DRIVING; } bool InVehicle(void) { return bInVehicle && m_pMyVehicle; } // True when ped is sitting/standing in vehicle, not in enter/exit state. bool EnteringCar(void) { return m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK; } + bool HasAttractor(void) { return m_attractor != nil; } + bool IsUseAttractorObjective(eObjective obj) { + return obj == OBJECTIVE_GOTO_ATM_ON_FOOT || obj == OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT || + obj == OBJECTIVE_GOTO_PIZZA_ON_FOOT || obj == OBJECTIVE_GOTO_SEAT_ON_FOOT || + obj == OBJECTIVE_GOTO_SHELTER_ON_FOOT || obj == OBJECTIVE_GOTO_BUS_STOP_ON_FOOT; + } void ReplaceWeaponWhenExitingVehicle(void); void RemoveWeaponWhenEnteringVehicle(void); bool IsNotInWreckedVehicle(); + + // My names. Inlined in VC + AnimationId GetFireAnimNotDucking(CWeaponInfo* weapon) { + if (m_nPedType == PEDTYPE_COP && !!weapon->m_bCop3rd) + return ANIM_WEAPON_FIRE_3RD; + else + return GetPrimaryFireAnim(weapon); + } + + static AnimationId GetFireAnimGround(CWeaponInfo* weapon, bool kickFloorIfNone = true) { + if (!!weapon->m_bGround2nd) + return ANIM_WEAPON_CROUCHFIRE; + else if (!!weapon->m_bGround3rd) + return ANIM_WEAPON_FIRE_3RD; + else if (kickFloorIfNone) + return ANIM_KICK_FLOOR; + else + return (AnimationId)0; + } + + static AnimationId GetPrimaryFireAnim(CWeaponInfo* weapon) { + if (weapon->m_bAnimDetonate) + return ANIM_BOMBER; + else + return ANIM_WEAPON_FIRE; + } + + static AnimationId GetCrouchReloadAnim(CWeaponInfo* weapon) { + if (!!weapon->m_bReload) + return ANIM_WEAPON_CROUCHRELOAD; + else + return (AnimationId)0; + } + + static AnimationId GetCrouchFireAnim(CWeaponInfo* weapon) { + if (!!weapon->m_bCrouchFire) + return ANIM_WEAPON_CROUCHFIRE; + else + return (AnimationId)0; + } + + static AnimationId GetReloadAnim(CWeaponInfo* weapon) { + if (!!weapon->m_bReload) + return ANIM_WEAPON_RELOAD; + else + return (AnimationId)0; + } + + static AnimationId GetFightIdleWithMeleeAnim(CWeaponInfo* weapon) { + if (!!weapon->m_bFightMode) + return ANIM_MELEE_IDLE_FIGHTMODE; + else + return (AnimationId)0; + } + + static AnimationId GetFinishingAttackAnim(CWeaponInfo* weapon) { + if (!!weapon->m_bFinish3rd) + return ANIM_MELEE_ATTACK_FINISH; + else + return (AnimationId)0; + } + + static AnimationId GetSecondFireAnim(CWeaponInfo* weapon) { + if (!!weapon->m_bUse2nd) + return ANIM_WEAPON_FIRE_2ND; // or ANIM_MELEE_ATTACK_2ND + else + return (AnimationId)0; + } + // -- + // My additions, because there were many, many instances of that. inline void SetFindPathAndFlee(CEntity *fleeFrom, int time, bool walk = false) { @@ -829,43 +1075,24 @@ public: if (walk) SetMoveState(PEDMOVE_WALK); } + // -- // Using this to abstract nodes of skinned and non-skinned meshes CVector GetNodePosition(int32 node) { -#ifdef PED_SKIN - if(IsClumpSkinned(GetClump())){ - RwV3d pos = { 0.0f, 0.0f, 0.0f }; - RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump()); - int32 idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID); - RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier); - // this is just stupid - //RwV3dTransformPoints(&pos, &pos, 1, &mats[idx]); - pos = mats[idx].pos; - return pos; - }else -#endif - { - RwMatrix mat; - CPedIK::GetWorldMatrix(m_pFrames[node]->frame, &mat); - return mat.pos; - } + RwV3d pos = { 0.0f, 0.0f, 0.0f }; + RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump()); + int32 idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID); + RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier); + pos = mats[idx].pos; + return pos; } void TransformToNode(CVector &pos, int32 node) { -#ifdef PED_SKIN - if(IsClumpSkinned(GetClump())){ - RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump()); - int32 idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID); - RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier); - RwV3dTransformPoints((RwV3d*)&pos, (RwV3d*)&pos, 1, &mats[idx]); - }else -#endif - { - RwFrame *frame; - for (frame = m_pFrames[node]->frame; frame; frame = RwFrameGetParent(frame)) - RwV3dTransformPoints((RwV3d*)&pos, (RwV3d*)&pos, 1, RwFrameGetMatrix(frame)); - } + RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump()); + int32 idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID); + RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier); + RwV3dTransformPoints((RwV3d*)&pos, (RwV3d*)&pos, 1, &mats[idx]); } // set by 0482:set_threat_reaction_range_multiplier opcode @@ -875,14 +1102,11 @@ public: static uint16 nEnterCarRangeMultiplier; static bool bNastyLimbsCheat; + static bool bFannyMagnetCheat; static bool bPedCheat2; static bool bPedCheat3; static CVector2D ms_vec2DFleePosition; -#ifdef DEBUGMENU - static bool bPopHeadsOnHeadshot; -#endif - #ifndef MASTER // Mobile things void DebugDrawPedDestination(CPed *, int, int); @@ -902,18 +1126,20 @@ public: void DebugRenderClosePedText(); #endif -#ifdef PED_SKIN - void renderLimb(int node); -#endif - #ifdef COMPATIBLE_SAVES virtual void Save(uint8*& buf); virtual void Load(uint8*& buf); #endif }; -void FinishFuckUCB(CAnimBlendAssociation *assoc, void *arg); +void FinishTalkingOnMobileCB(CAnimBlendAssociation* assoc, void* arg); +void StartTalkingOnMobileCB(CAnimBlendAssociation* assoc, void* arg); +void PlayRandomAnimationsFromAnimBlock(CPed* ped, AssocGroupId animGroup, uint32 first, uint32 amount); +// TODO(Miami): Change those when Ped struct is done #ifndef PED_SKIN VALIDATE_SIZE(CPed, 0x53C); #endif + +bool IsPedPointerValid(CPed*); +bool IsPedPointerValid_NotInWorld(CPed*); diff --git a/src/peds/PedAttractor.cpp b/src/peds/PedAttractor.cpp new file mode 100644 index 00000000..9f77f2a4 --- /dev/null +++ b/src/peds/PedAttractor.cpp @@ -0,0 +1,775 @@ +#include "common.h" +#include "PedAttractor.h" + +#include "General.h" +#include "Vehicle.h" +#include "World.h" + +const int gcMaxSizeOfAtmQueue = 1; +const int gcMaxSizeOfSeatQueue = 1; +const int gcMaxSizeOfStopQueue = 5; +const int gcMaxSizeOfPizzaQueue = 5; +const int gcMaxSizeOfShelterQueue = 5; +const int gcMaxSizeOfIceCreamQueue = 1; + +//--MIAMI: file done + +std::vector<CVector> CPedShelterAttractor::ms_displacements; + +CPedAttractorManager* GetPedAttractorManager() +{ + static CPedAttractorManager manager; + return &manager; +} + +CVehicleToEffect::CVehicleToEffect(CVehicle* pVehicle) : m_pVehicle(pVehicle) +{ + m_effects[1].col = CRGBA(0, 0, 0, 0); + m_effects[1].type = EFFECT_PED_ATTRACTOR; + m_effects[1].pos = CVector(2.0f, 1.0f, 0.0f); + m_effects[1].pedattr.useDir = CVector(-1.0f, 0.0f, 0.0f); + m_effects[1].pedattr.queueDir = CVector(-1.0f, 0.0f, 0.0f); + m_effects[1].pedattr.type = ATTRACTOR_ICECREAM; + + m_effects[3].col = CRGBA(0, 0, 0, 0); + m_effects[3].type = EFFECT_PED_ATTRACTOR; + m_effects[3].pos = CVector(2.0f, -0.5f, 0.0f); + m_effects[3].pedattr.useDir = CVector(-1.0f, 0.0f, 0.0f); + m_effects[3].pedattr.queueDir = CVector(-1.0f, 0.0f, 0.0f); + m_effects[3].pedattr.type = ATTRACTOR_ICECREAM; + + m_effects[0].col = CRGBA(0, 0, 0, 0); + m_effects[0].type = EFFECT_PED_ATTRACTOR; + m_effects[0].pos = CVector(-2.0f, 1.0f, 0.0f); + m_effects[0].pedattr.useDir = CVector(1.0f, 0.0f, 0.0f); + m_effects[0].pedattr.queueDir = CVector(1.0f, 0.0f, 0.0f); + m_effects[0].pedattr.type = ATTRACTOR_ICECREAM; + + m_effects[2].col = CRGBA(0, 0, 0, 0); + m_effects[2].type = EFFECT_PED_ATTRACTOR; + m_effects[2].pos = CVector(-2.0f, -0.5f, 0.0f); + m_effects[2].pedattr.useDir = CVector(1.0f, 0.0f, 0.0f); + m_effects[2].pedattr.queueDir = CVector(1.0f, 0.0f, 0.0f); + m_effects[2].pedattr.type = ATTRACTOR_ICECREAM; +} + +CVehicleToEffect& CVehicleToEffect::From(const CVehicleToEffect& other) +{ + m_pVehicle = other.m_pVehicle; + for (int i = 0; i < NUM_ATTRACTORS_FOR_ICECREAM_VAN; i++) { + m_effects[i].col = other.m_effects[i].col; + m_effects[i].type = other.m_effects[i].type; + m_effects[i].pos = other.m_effects[i].pos; + m_effects[i].pedattr = other.m_effects[i].pedattr; + } + return *this; +} + +const C2dEffect* CVehicleToEffect::ChooseEffect(const CVector& pos) const +{ + if (!m_pVehicle) + return nil; + if (DotProduct(pos - m_pVehicle->GetPosition(), m_pVehicle->GetRight()) > 0.0f) { + if (DotProduct(pos - m_pVehicle->GetPosition(), m_pVehicle->GetForward()) > 0.0f) + return &m_effects[1]; + else + return &m_effects[3]; + } + else { + if (DotProduct(pos - m_pVehicle->GetPosition(), m_pVehicle->GetForward()) > 0.0f) + return &m_effects[0]; + else + return &m_effects[2]; + } +} + +bool CVehicleToEffect::HasThisEffect(C2dEffect* pEffect) const +{ + for (int i = 0; i < NUM_ATTRACTORS_FOR_ICECREAM_VAN; i++) { + if (pEffect == &m_effects[i]) + return true; + } + return false; +} + +const C2dEffect* CPedAttractorManager::GetEffectForIceCreamVan(CVehicle* pVehicle, const CVector& pos) +{ + if (!vVehicleToEffect.empty()) { + for (std::vector<CVehicleToEffect>::const_iterator assoc = vVehicleToEffect.cbegin(); assoc != vVehicleToEffect.cend(); ++assoc) { + if (assoc->GetVehicle() == pVehicle) + return assoc->ChooseEffect(pos); + } + } + CVehicleToEffect effect(pVehicle); + vVehicleToEffect.push_back(effect); + return effect.ChooseEffect(pos); +} + +CVehicle* CPedAttractorManager::GetIceCreamVanForEffect(C2dEffect* pEffect) +{ + if (vVehicleToEffect.empty()) + return nil; + for (std::vector<CVehicleToEffect>::const_iterator assoc = vVehicleToEffect.cbegin(); assoc != vVehicleToEffect.cend(); ++assoc) { + if (assoc->HasThisEffect(pEffect)) + return assoc->GetVehicle(); + } + return nil; +} + +const CPedAttractor* CPedAttractorManager::FindAssociatedAttractor(const C2dEffect* pEffect, std::vector<CPedAttractor*>& vecAttractors) +{ + if (vecAttractors.empty()) + return nil; + for (std::vector<CPedAttractor*>::const_iterator attractor = vecAttractors.cbegin(); attractor != vecAttractors.cend(); ++attractor) { + if ((*attractor)->GetEffect() == pEffect) + return *attractor; + } + return nil; +} + +void CPedAttractorManager::RemoveIceCreamVanEffects(C2dEffect* pEffect) +{ + CVehicle* pVehicle = GetIceCreamVanForEffect(pEffect); + if (!pVehicle) + return; + if (vVehicleToEffect.empty()) + return; + for (std::vector<CVehicleToEffect>::const_iterator assoc = vVehicleToEffect.cbegin(); assoc != vVehicleToEffect.cend();) { + if (assoc->GetVehicle() != pVehicle) + return; + uint32 total = 0; + for (uint32 j = 0; j < NUM_ATTRACTORS_FOR_ICECREAM_VAN; j++) { + if (FindAssociatedAttractor(assoc->GetEffect(j), vIceCreamAttractors)) + total++; + } + if (total > 0) + assoc++; + else + assoc = vVehicleToEffect.erase(assoc); + } +} + +CPedAttractor::CPedAttractor(C2dEffect* pEffect, const CMatrix& matrix, int32 maxpeds, float qdist, float waitTime, float approachTime, float distance, float headingdiff, float posdisp, float headdisp) : + p2dEffect(pEffect), + m_nMaxPedsInAttractor(maxpeds), + m_fQueueDistance(qdist), + m_fTimeInWaitQueue(waitTime), + m_fTimeInApproachingQueue(approachTime), + m_fDistanceToUseAttractor(distance), + m_fAcceptableHeading(headingdiff), + m_fMaxPositionDisplacement(posdisp), + m_fMaxHeadingDisplacement(headdisp) +{ + CPedAttractorManager::ComputeEffectPos(pEffect, matrix, vecEffectPos); + CPedAttractorManager::ComputeEffectQueueDir(pEffect, matrix, vecQueueDir); + CPedAttractorManager::ComputeEffectUseDir(pEffect, matrix, vecUseDir); +} + +void CPedPizzaAttractor::UpdatePedStateOnDeparture(CPed* pPed) const +{ + if (pPed->m_nPedMoney > 10) + pPed->m_nPedMoney -= 10; + else + pPed->m_nPedMoney = 0; +} + +void CPedAtmAttractor::UpdatePedStateOnDeparture(CPed* pPed) const +{ + pPed->m_nPedMoney += 20 * CGeneral::GetRandomNumberInRange(1, 51); +}; + +float CPedAttractor::ComputeDeltaHeading() const +{ + return CGeneral::GetRandomNumberInRange(-m_fMaxHeadingDisplacement, m_fMaxHeadingDisplacement); +} + +float CPedAttractor::ComputeDeltaPos() const +{ + return CGeneral::GetRandomNumberInRange(-m_fMaxPositionDisplacement, m_fMaxPositionDisplacement); +} + +void CPedAttractor::ComputeAttractTime(int32 id, bool approacher, float& time) const +{ + if (approacher) + time = m_fTimeInApproachingQueue; + else + time = m_fTimeInWaitQueue; +} + +void CPedAttractor::ComputeAttractPos(int32 qid, CVector& pos) const +{ + if (!p2dEffect) + return; + pos = vecEffectPos - qid * vecQueueDir * m_fQueueDistance; + if (qid != 0) { + pos.x += ComputeDeltaPos(); + pos.y += ComputeDeltaPos(); + } +} + +CVector CPedShelterAttractor::GetDisplacement(int32 qid) const +{ + if (ms_displacements.empty()) { + int i = 0; + while (i < gcMaxSizeOfShelterQueue) { + float fRandomAngle = CGeneral::GetRandomNumberInRange(0.0f, TWOPI); + float fRandomOffset = CGeneral::GetRandomNumberInRange(0.0f, 2.0f); + CVector vecDisplacement(fRandomOffset * Sin(fRandomAngle), fRandomOffset * Cos(fRandomAngle), 0.0f); + bool close = false; + for (std::vector<CVector>::const_iterator v = ms_displacements.cbegin(); v != ms_displacements.cend(); ++v) { + if ((*v - vecDisplacement).Magnitude() < 1.0f) { + close = true; + break; + } + } + if (!close) { + ms_displacements.push_back(vecDisplacement); + i++; + } + } + } + return ms_displacements[qid]; +} + +void CPedShelterAttractor::ComputeAttractPos(int32 qid, CVector& pos) const +{ + if (!p2dEffect) + return; + pos = vecEffectPos + GetDisplacement(qid); +} + +void CPedAttractor::ComputeAttractHeading(int32 qid, float& heading) const +{ + heading = CGeneral::GetRadianAngleBetweenPoints(qid != 0 ? vecQueueDir.x : vecUseDir.x, qid != 0 ? vecQueueDir.y : vecUseDir.y, 0.0f, 0.0f); + if (qid != 0) + heading += ComputeDeltaHeading(); +} + +void CPedShelterAttractor::ComputeAttractHeading(int32 qid, float& heading) const +{ + heading = CGeneral::GetRandomNumberInRange(0.0f, TWOPI); +} + +bool CPedAttractor::RegisterPed(CPed* pPed) +{ + for (std::vector<CPed*>::const_iterator pPedIt = vApproachingQueue.cbegin(); pPedIt != vApproachingQueue.cend(); ++pPedIt) { + if (*pPedIt == pPed) { + vApproachingQueue.erase(pPedIt); + return false; + } + } + if (GetNoOfRegisteredPeds() >= m_nMaxPedsInAttractor) + return 0; + vApproachingQueue.push_back(pPed); + CVector pos; + float heading; + float time; + int32 slot = ComputeFreeSlot(); + ComputeAttractPos(slot, pos); + ComputeAttractHeading(slot, heading); + ComputeAttractTime(slot, false, time); + pPed->SetNewAttraction(this, pos, heading, time, slot); + return true; +} + +static bool IsPedUsingAttractorOfThisType(int8 type, CPed* pPed) +{ + switch (type) { + case ATTRACTOR_ATM: + if (pPed->m_objective == OBJECTIVE_GOTO_ATM_ON_FOOT) + return true; + break; + case ATTRACTOR_SEAT: + if (pPed->m_objective == OBJECTIVE_GOTO_SEAT_ON_FOOT) + return true; + break; + case ATTRACTOR_STOP: + if (pPed->m_objective == OBJECTIVE_GOTO_BUS_STOP_ON_FOOT || pPed->m_objective == OBJECTIVE_WAIT_ON_FOOT_AT_BUS_STOP || pPed->m_objective == OBJECTIVE_WAIT_ON_FOOT) + return true; + break; + case ATTRACTOR_PIZZA: + if (pPed->m_objective == OBJECTIVE_GOTO_PIZZA_ON_FOOT || pPed->m_objective == OBJECTIVE_WAIT_ON_FOOT) + return true; + break; + case ATTRACTOR_SHELTER: + if (pPed->m_objective == OBJECTIVE_GOTO_SHELTER_ON_FOOT || pPed->m_objective == OBJECTIVE_WAIT_ON_FOOT_AT_SHELTER) + return true; + break; + case ATTRACTOR_ICECREAM: + if (pPed->m_objective == OBJECTIVE_GOTO_ICE_CREAM_VAN_ON_FOOT || pPed->m_objective == OBJECTIVE_WAIT_ON_FOOT_AT_ICE_CREAM_VAN) + return true; + break; + } + return false; +} + +bool CPedAttractor::DeRegisterPed(CPed* pPed) +{ + for (std::vector<CPed*>::const_iterator pPedIt = vApproachingQueue.cbegin(); pPedIt != vApproachingQueue.cend(); ++pPedIt) { + if (*pPedIt != pPed) + continue; + pPed->m_attractor = nil; + pPed->m_positionInQueue = -1; + pPed->bHasAlreadyUsedAttractor = true; + + if (IsPedUsingAttractorOfThisType(p2dEffect->pedattr.type, pPed)) + pPed->SetObjective(OBJECTIVE_NONE); + else if (pPed->GetPedState() != PED_IDLE && pPed->GetPedState() != PED_NONE) { + vApproachingQueue.erase(pPedIt); + return true; + } + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(-vecQueueDir.x, -vecQueueDir.y)); + vApproachingQueue.erase(pPedIt); + return true; + } + return BroadcastDeparture(pPed); +} + +bool CPedAttractor::BroadcastArrival(CPed* pPed) +{ + for (std::vector<CPed*>::const_iterator pPedIt = vWaitingQueue.cbegin(); pPedIt != vWaitingQueue.cend(); ++pPedIt) { + if (*pPedIt == pPed) + return false; + } + vWaitingQueue.push_back(pPed); + for (std::vector<CPed*>::const_iterator pPedIt = vApproachingQueue.cbegin(); pPedIt != vApproachingQueue.cend(); ++pPedIt) { + if (*pPedIt == pPed) { + vApproachingQueue.erase(pPedIt); + break; + } + } + for (std::vector<CPed*>::iterator pPedIt = vApproachingQueue.begin(); pPedIt != vApproachingQueue.end(); ++pPedIt) { + CPed* pPed = *pPedIt; + CVector pos; + float heading; + float time; + int32 slot = ComputeFreeSlot(); + ComputeAttractPos(slot, pos); + ComputeAttractHeading(slot, heading); + ComputeAttractTime(slot, false, time); + pPed->SetNewAttraction(this, pos, heading, time, slot); + } + return true; +} + +bool CPedAttractor::BroadcastDeparture(CPed* pPed) +{ + int qid = -1; + for (uint32 i = 0; i < vWaitingQueue.size(); i++){ + if (vWaitingQueue[i] == pPed) + qid = i; + } + if (qid < 0) + return false; + for (uint32 i = qid + 1; i < vWaitingQueue.size(); i++) { + CVector pos; + float heading; + float time; + ComputeAttractPos(i - 1, pos); + ComputeAttractHeading(i - 1, heading); + ComputeAttractTime(i - 1, true, time); + pPed->SetNewAttraction(this, pos, heading, time, i - 1); + } + pPed->m_attractor = nil; + pPed->m_positionInQueue = -1; + pPed->bHasAlreadyUsedAttractor = true; + if (!IsPedUsingAttractorOfThisType(p2dEffect->pedattr.type, pPed)) { + if (pPed->GetPedState() == PED_IDLE || pPed->GetPedState() == PED_NONE) + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(-vecQueueDir.x, -vecQueueDir.y)); + } + else if (qid == 0) + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(vecQueueDir.x, vecQueueDir.y)); + else if (qid == vWaitingQueue.size() - 1) + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(-vecQueueDir.x, -vecQueueDir.y)); + else + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(-vecQueueDir.y, -vecQueueDir.z)); + vWaitingQueue.erase(vWaitingQueue.cbegin() + qid); + for (std::vector<CPed*>::iterator pPedIt = vApproachingQueue.begin(); pPedIt != vApproachingQueue.end(); ++pPedIt) { + CPed* pPed = *pPedIt; + CVector pos; + float heading; + float time; + int32 slot = ComputeFreeSlot(); + ComputeAttractPos(slot, pos); + ComputeAttractHeading(slot, heading); + ComputeAttractTime(slot, false, time); + pPed->SetNewAttraction(this, pos, heading, time, slot); + } + return true; +} + +bool CPedShelterAttractor::BroadcastDeparture(CPed* pPed) +{ + int qid = -1; + for (uint32 i = 0; i < vWaitingQueue.size(); i++) { + if (vWaitingQueue[i] == pPed) + qid = i; + } + if (qid < 0) + return false; + pPed->m_attractor = nil; + pPed->m_positionInQueue = -1; + pPed->bHasAlreadyUsedAttractor = true; + if (!IsPedUsingAttractorOfThisType(p2dEffect->pedattr.type, pPed)) { + if (pPed->GetPedState() == PED_IDLE || pPed->GetPedState() == PED_NONE) + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(-vecQueueDir.x, -vecQueueDir.y)); + } + else if (qid == 0) + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(vecQueueDir.x, vecQueueDir.y)); + else if (qid == vWaitingQueue.size() - 1) + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(-vecQueueDir.x, -vecQueueDir.y)); + else + pPed->SetWanderPath(CGeneral::GetNodeHeadingFromVector(-vecQueueDir.y, -vecQueueDir.z)); + vWaitingQueue.erase(vWaitingQueue.cbegin() + qid); + for (std::vector<CPed*>::iterator pPedIt = vApproachingQueue.begin(); pPedIt != vApproachingQueue.end(); ++pPedIt) { + CPed* pPed = *pPedIt; + CVector pos; + float heading; + float time; + int32 slot = ComputeFreeSlot(); + ComputeAttractPos(slot, pos); + ComputeAttractHeading(slot, heading); + ComputeAttractTime(slot, false, time); + pPed->SetNewAttraction(this, pos, heading, time, slot); + } + return true; +} + +bool CPedAttractor::IsRegisteredWithPed(CPed* pPed) const +{ + for (std::vector<CPed*>::const_iterator pPedIt = vWaitingQueue.cbegin(); pPedIt != vWaitingQueue.cend(); ++pPedIt) { + if (*pPedIt == pPed) + return true; + } + for (std::vector<CPed*>::const_iterator pPedIt = vApproachingQueue.cbegin(); pPedIt != vApproachingQueue.cend(); ++pPedIt) { + if (*pPedIt == pPed) { + return true; + } + } + return false; +} + +bool CPedAttractor::IsInQueue(CPed* pPed) const +{ + for (std::vector<CPed*>::const_iterator pPedIt = vWaitingQueue.cbegin(); pPedIt != vWaitingQueue.cend(); ++pPedIt) { + if (*pPedIt == pPed) + return true; + } + return false; +} + +CPedAttractor* CPedAttractorManager::RegisterPedWithAttractor(CPed* pPed, C2dEffect* pEffect, const CMatrix& matrix) +{ + if (pEffect->type != EFFECT_PED_ATTRACTOR) + return nil; + if (IsPedRegisteredWithEffect(pPed)) + return nil; + switch (pEffect->pedattr.type) { + case ATTRACTOR_ATM: return RegisterPed(pPed, pEffect, matrix, vAtmAttractors); + case ATTRACTOR_SEAT: return RegisterPed(pPed, pEffect, matrix, vSeatAttractors); + case ATTRACTOR_STOP: return RegisterPed(pPed, pEffect, matrix, vStopAttractors); + case ATTRACTOR_PIZZA: return RegisterPed(pPed, pEffect, matrix, vPizzaAttractors); + case ATTRACTOR_SHELTER: return RegisterPed(pPed, pEffect, matrix, vShelterAttractors); + case ATTRACTOR_ICECREAM: return RegisterPed(pPed, pEffect, matrix, vIceCreamAttractors); + } + return nil; +} + +bool CPedAttractorManager::DeRegisterPed(CPed* pPed, CPedAttractor* pAttractor) +{ + if (!pAttractor) + return false; + if (pAttractor->GetEffect()->type != EFFECT_PED_ATTRACTOR) + return nil; + if (!IsPedRegisteredWithEffect(pPed)) + return nil; + switch (pAttractor->GetEffect()->pedattr.type) { + case ATTRACTOR_ATM: return DeRegisterPed(pPed, pAttractor, vAtmAttractors); + case ATTRACTOR_SEAT: return DeRegisterPed(pPed, pAttractor, vSeatAttractors); + case ATTRACTOR_STOP: return DeRegisterPed(pPed, pAttractor, vStopAttractors); + case ATTRACTOR_PIZZA: return DeRegisterPed(pPed, pAttractor, vPizzaAttractors); + case ATTRACTOR_SHELTER: return DeRegisterPed(pPed, pAttractor, vShelterAttractors); + case ATTRACTOR_ICECREAM: return DeRegisterPed(pPed, pAttractor, vIceCreamAttractors); + } + return nil; +} + +bool CPedAttractorManager::BroadcastArrival(CPed* pPed, CPedAttractor* pAttractor) +{ + if (!pAttractor) + return false; + if (pAttractor->GetEffect()->type != EFFECT_PED_ATTRACTOR) + return nil; + if (!IsPedRegisteredWithEffect(pPed)) + return nil; + switch (pAttractor->GetEffect()->pedattr.type) { + case ATTRACTOR_ATM: return BroadcastArrival(pPed, pAttractor, vAtmAttractors); + case ATTRACTOR_SEAT: return BroadcastArrival(pPed, pAttractor, vSeatAttractors); + case ATTRACTOR_STOP: return BroadcastArrival(pPed, pAttractor, vStopAttractors); + case ATTRACTOR_PIZZA: return BroadcastArrival(pPed, pAttractor, vPizzaAttractors); + case ATTRACTOR_SHELTER: return BroadcastArrival(pPed, pAttractor, vShelterAttractors); + case ATTRACTOR_ICECREAM: return BroadcastArrival(pPed, pAttractor, vIceCreamAttractors); + } + return nil; +} + +bool CPedAttractorManager::BroadcastDeparture(CPed* pPed, CPedAttractor* pAttractor) +{ + if (!pAttractor) + return false; + if (pAttractor->GetEffect()->type != EFFECT_PED_ATTRACTOR) + return nil; + if (!IsPedRegisteredWithEffect(pPed)) + return nil; + switch (pAttractor->GetEffect()->pedattr.type) { + case ATTRACTOR_ATM: return BroadcastDeparture(pPed, pAttractor, vAtmAttractors); + case ATTRACTOR_SEAT: return BroadcastDeparture(pPed, pAttractor, vSeatAttractors); + case ATTRACTOR_STOP: return BroadcastDeparture(pPed, pAttractor, vStopAttractors); + case ATTRACTOR_PIZZA: return BroadcastDeparture(pPed, pAttractor, vPizzaAttractors); + case ATTRACTOR_SHELTER: return BroadcastDeparture(pPed, pAttractor, vShelterAttractors); + case ATTRACTOR_ICECREAM: return BroadcastDeparture(pPed, pAttractor, vIceCreamAttractors); + } + return nil; +} + +bool CPedAttractorManager::IsAtHeadOfQueue(CPed* pPed, CPedAttractor* pAttractor) +{ + if (!pAttractor) + return false; + if (pAttractor->GetEffect()->type != EFFECT_PED_ATTRACTOR) + return nil; + if (!IsPedRegisteredWithEffect(pPed)) + return nil; + switch (pAttractor->GetEffect()->pedattr.type) { + case ATTRACTOR_ATM: return IsAtHeadOfQueue(pPed, pAttractor, vAtmAttractors); + case ATTRACTOR_SEAT: return IsAtHeadOfQueue(pPed, pAttractor, vSeatAttractors); + case ATTRACTOR_STOP: return IsAtHeadOfQueue(pPed, pAttractor, vStopAttractors); + case ATTRACTOR_PIZZA: return IsAtHeadOfQueue(pPed, pAttractor, vPizzaAttractors); + case ATTRACTOR_SHELTER: return IsAtHeadOfQueue(pPed, pAttractor, vShelterAttractors); + case ATTRACTOR_ICECREAM: return IsAtHeadOfQueue(pPed, pAttractor, vIceCreamAttractors); + } + return nil; +} + +bool CPedAttractorManager::IsInQueue(CPed* pPed, CPedAttractor* pAttractor) +{ + if (!pAttractor) + return false; + if (pAttractor->GetEffect()->type != EFFECT_PED_ATTRACTOR) + return nil; + if (!IsPedRegisteredWithEffect(pPed)) + return nil; + switch (pAttractor->GetEffect()->pedattr.type) { + case ATTRACTOR_ATM: return IsInQueue(pPed, pAttractor, vAtmAttractors); + case ATTRACTOR_SEAT: return IsInQueue(pPed, pAttractor, vSeatAttractors); + case ATTRACTOR_STOP: return IsInQueue(pPed, pAttractor, vStopAttractors); + case ATTRACTOR_PIZZA: return IsInQueue(pPed, pAttractor, vPizzaAttractors); + case ATTRACTOR_SHELTER: return IsInQueue(pPed, pAttractor, vShelterAttractors); + case ATTRACTOR_ICECREAM: return IsInQueue(pPed, pAttractor, vIceCreamAttractors); + } + return nil; +} + +bool CPedAttractorManager::HasEmptySlot(const C2dEffect* pEffect) +{ + if (!pEffect) + return false; + if (pEffect->type != EFFECT_PED_ATTRACTOR) + return nil; + const CPedAttractor* pAttractor; + switch (pEffect->pedattr.type) { + case ATTRACTOR_ATM: pAttractor = FindAssociatedAttractor(pEffect, vAtmAttractors); break; + case ATTRACTOR_SEAT: pAttractor = FindAssociatedAttractor(pEffect, vSeatAttractors); break; + case ATTRACTOR_STOP: pAttractor = FindAssociatedAttractor(pEffect, vStopAttractors); break; + case ATTRACTOR_PIZZA: pAttractor = FindAssociatedAttractor(pEffect, vPizzaAttractors); break; + case ATTRACTOR_SHELTER: pAttractor = FindAssociatedAttractor(pEffect, vShelterAttractors); break; + case ATTRACTOR_ICECREAM: pAttractor = FindAssociatedAttractor(pEffect, vIceCreamAttractors); break; + default: return true; + } + if (!pAttractor) + return true; + return pAttractor->GetNoOfRegisteredPeds() < pAttractor->GetMaxPedsInAttractor(); +} + +bool CPedAttractorManager::IsPedRegisteredWithEffect(CPed* pPed) +{ + return IsPedRegistered(pPed, vAtmAttractors) || + IsPedRegistered(pPed, vSeatAttractors) || + IsPedRegistered(pPed, vStopAttractors) || + IsPedRegistered(pPed, vPizzaAttractors) || + IsPedRegistered(pPed, vShelterAttractors) || + IsPedRegistered(pPed, vIceCreamAttractors); +} + +void CPedAttractorManager::ComputeEffectPos(const C2dEffect* pEffect, const CMatrix& matrix, CVector& pos) +{ + pos = matrix.GetPosition() + Multiply3x3(matrix, pEffect->pos); +} + +void CPedAttractorManager::ComputeEffectQueueDir(const C2dEffect* pEffect, const CMatrix& matrix, CVector& pos) +{ + pos = Multiply3x3(matrix, pEffect->pedattr.queueDir); +} + +void CPedAttractorManager::ComputeEffectUseDir(const C2dEffect* pEffect, const CMatrix& matrix, CVector& pos) +{ + pos = Multiply3x3(matrix, pEffect->pedattr.useDir); +} + +CPedAttractor* CPedAttractorManager::RegisterPed(CPed* pPed, C2dEffect* pEffect, const CMatrix& matrix, std::vector<CPedAttractor*>& vecAttractors) +{ + CPedAttractor* pRegisteredAttractor = nil; + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + CPedAttractor* pAttractor = *pAttractorIt; + CVector vEffectPos; + ComputeEffectPos(pAttractor->GetEffect(), matrix, vEffectPos); + if (pAttractor->GetEffect() == pEffect && vEffectPos == pAttractor->GetEffectPos()) { + if (!IsApproachable(pEffect, matrix, pAttractor->ComputeFreeSlot(), pPed)) + return nil; + pRegisteredAttractor = pAttractor; + break; + } + } + if (pRegisteredAttractor || !IsApproachable(pEffect, matrix, 0, pPed)) { + if (pRegisteredAttractor) + pRegisteredAttractor->RegisterPed(pPed); + return pRegisteredAttractor; + } + switch (pEffect->pedattr.type) { + case ATTRACTOR_ATM: vecAttractors.push_back(new CPedAtmAttractor(pEffect, matrix, gcMaxSizeOfAtmQueue, 1.0f, 30000.0f, 3000.0f, 0.2f, 0.15f, 0.1f, 0.1f)); break; + case ATTRACTOR_SEAT: vecAttractors.push_back(new CPedSeatAttractor(pEffect, matrix, gcMaxSizeOfSeatQueue, 1.0f, 30000.0f, 3000.0f, 0.125f, 0.1f, 0.1f, 0.1f)); break; + case ATTRACTOR_STOP: vecAttractors.push_back(new CPedStopAttractor(pEffect, matrix, gcMaxSizeOfStopQueue, 1.0f, 30000.0f, 3000.0f, 0.2f, 0.1f, 0.1f, 0.1f)); break; + case ATTRACTOR_PIZZA: vecAttractors.push_back(new CPedPizzaAttractor(pEffect, matrix, gcMaxSizeOfPizzaQueue, 1.0f, 30000.0f, 3000.0f, 0.2f, 0.1f, 0.1f, 0.1f)); break; + case ATTRACTOR_SHELTER: vecAttractors.push_back(new CPedShelterAttractor(pEffect, matrix, gcMaxSizeOfShelterQueue, 1.0f, 30000.0f, 3000.0f, 0.5f, 6.28f, 0.1f, 0.1f)); break; + case ATTRACTOR_ICECREAM: vecAttractors.push_back(new CPedIceCreamAttractor(pEffect, matrix, gcMaxSizeOfIceCreamQueue, 1.0f, 30000.0f, 3000.0f, 0.2f, 0.3f, 0.1f, 0.1f)); break; + } + if (pRegisteredAttractor) + pRegisteredAttractor->RegisterPed(pPed); + return pRegisteredAttractor; +} + +bool CPedAttractorManager::DeRegisterPed(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors) +{ + if (!pAttractor) + return false; + CPedAttractor* pFound = nil; + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + if (*pAttractorIt == pAttractor) { + pFound = *pAttractorIt; + break; + } + } + if (!pFound) + return false; + pFound->DeRegisterPed(pPed); + if (pFound->GetNoOfRegisteredPeds() != 0) + return true; + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + if (*pAttractorIt == pAttractor) { + vecAttractors.erase(pAttractorIt); + break; + } + } + delete pAttractor; + return true; +} + +bool CPedAttractorManager::BroadcastArrival(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors) +{ + if (!pAttractor) + return false; + CPedAttractor* pFound = nil; + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + if (*pAttractorIt == pAttractor) { + pFound = *pAttractorIt; + break; + } + } + if (!pFound) + return false; + pFound->BroadcastArrival(pPed); + return true; +} + +bool CPedAttractorManager::BroadcastDeparture(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors) +{ + if (!pAttractor) + return false; + CPedAttractor* pFound = nil; + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + if (*pAttractorIt == pAttractor) { + pFound = *pAttractorIt; + break; + } + } + if (!pFound) + return false; + pFound->DeRegisterPed(pPed); + if (pFound->GetNoOfRegisteredPeds() != 0) + return true; + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + if (*pAttractorIt == pAttractor) { + vecAttractors.erase(pAttractorIt); + break; + } + } + delete pAttractor; + return true; +} + +bool CPedAttractorManager::IsInQueue(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors) +{ + if (!pAttractor) + return false; + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + if (*pAttractorIt == pAttractor) { + return (*pAttractorIt)->IsInQueue(pPed); + } + } + return false; +} + +bool CPedAttractorManager::IsAtHeadOfQueue(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors) +{ + if (!pAttractor) + return false; + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + if (*pAttractorIt == pAttractor) { + return (*pAttractorIt)->IsAtHeadOfQueue(pPed); + } + } + return false; +} + +bool CPedAttractorManager::IsPedRegistered(CPed* pPed, std::vector<CPedAttractor*>& vecAttractors) +{ + for (std::vector<CPedAttractor*>::const_iterator pAttractorIt = vecAttractors.cbegin(); pAttractorIt != vecAttractors.cend(); ++pAttractorIt) { + if ((*pAttractorIt)->IsRegisteredWithPed(pPed)) + return true; + } + return false; +} + +bool CPedAttractorManager::IsApproachable(C2dEffect* pEffect, const CMatrix& matrix, int32, CPed* pPed) +{ + if (pEffect->pedattr.type == ATTRACTOR_SHELTER) { + CVector pos; + ComputeEffectPos(pEffect, matrix, pos); + return CWorld::GetIsLineOfSightClear(pPed->GetPosition(), pos, true, false, false, false, false, false); + } + CVector vecUseDir, vecEffectPos; + ComputeEffectUseDir(pEffect, matrix, vecUseDir); + ComputeEffectPos(pEffect, matrix, vecEffectPos); + float dp = -DotProduct(vecUseDir, vecEffectPos); + if (pEffect->pedattr.type == ATTRACTOR_ATM || pEffect->pedattr.type == ATTRACTOR_PIZZA || pEffect->pedattr.type == ATTRACTOR_ICECREAM) { + vecUseDir = -vecUseDir; + dp = -dp; + } + if (dp + DotProduct(vecEffectPos, pPed->GetPosition()) > 0.0f) { + CVector vecPedToAttractor = pPed->GetPosition() - vecEffectPos; + vecPedToAttractor.Normalise(); + if (DotProduct(vecPedToAttractor, vecUseDir) > 0.25f && CWorld::IsWanderPathClear(pPed->GetPosition(), vecEffectPos, 2.0f, 0)) + return true; + } + return false; +} diff --git a/src/peds/PedAttractor.h b/src/peds/PedAttractor.h new file mode 100644 index 00000000..85b4327b --- /dev/null +++ b/src/peds/PedAttractor.h @@ -0,0 +1,196 @@ +#pragma once +#include "common.h" +#include <vector> + +#include "2dEffect.h" +#include "Ped.h" + +#define NUM_ATTRACTORS_FOR_ICECREAM_VAN 4 + +class CPedAttractor; + +class CVehicleToEffect +{ + CVehicle* m_pVehicle; + C2dEffect m_effects[NUM_ATTRACTORS_FOR_ICECREAM_VAN]; + +public: + CVehicleToEffect(CVehicle* pVehicle); + const C2dEffect* ChooseEffect(const CVector& pos) const; + CVehicleToEffect& From(const CVehicleToEffect& other); + CVehicleToEffect& operator=(const CVehicleToEffect& other) { return From(other); } + ~CVehicleToEffect() { m_pVehicle = nil; } + CVehicle* GetVehicle() const { return m_pVehicle; } + bool HasThisEffect(C2dEffect* pEffect) const; + const C2dEffect* GetEffect(int32 i) const { return &m_effects[i]; } +}; + +class CPedAttractorManager +{ + std::vector<CPedAttractor*> vAtmAttractors; + std::vector<CPedAttractor*> vSeatAttractors; + std::vector<CPedAttractor*> vStopAttractors; + std::vector<CPedAttractor*> vPizzaAttractors; + std::vector<CPedAttractor*> vShelterAttractors; + std::vector<CPedAttractor*> vIceCreamAttractors; + std::vector<CVehicleToEffect> vVehicleToEffect; + +public: + CPedAttractor* RegisterPedWithAttractor(CPed* pPed, C2dEffect* pEffect, const CMatrix& matrix); + CPedAttractor* RegisterPed(CPed* pPed, C2dEffect* pEffect, const CMatrix& matrix, std::vector<CPedAttractor*>& vecAttractors); + bool BroadcastArrival(CPed* pPed, CPedAttractor* pAttractor); + bool BroadcastArrival(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors); + const C2dEffect* GetEffectForIceCreamVan(CVehicle* pVehicle, const CVector& pos); + bool IsApproachable(C2dEffect* pEffect, const CMatrix& matrix, int32, CPed* pPed); + void RemoveIceCreamVanEffects(C2dEffect* pEffect); + bool HasEmptySlot(const C2dEffect* pEffect); + const CPedAttractor* FindAssociatedAttractor(const C2dEffect* pEffect, std::vector<CPedAttractor*>& vecAttractors); + bool IsInQueue(CPed* pPed, CPedAttractor* pAttractor); + bool IsInQueue(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors); + bool IsAtHeadOfQueue(CPed* pPed, CPedAttractor* pAttractor); + bool IsAtHeadOfQueue(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors); + bool BroadcastDeparture(CPed* pPed, CPedAttractor* pAttractor); + bool BroadcastDeparture(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors); + bool DeRegisterPed(CPed* pPed, CPedAttractor* pAttractor); + bool DeRegisterPed(CPed* pPed, CPedAttractor* pAttractor, std::vector<CPedAttractor*>& vecAttractors); + bool IsPedRegisteredWithEffect(CPed* pPed); + bool IsPedRegistered(CPed* pPed, std::vector<CPedAttractor*>& vecAttractors); + CVehicle* GetIceCreamVanForEffect(C2dEffect* pEffect); + + static void ComputeEffectPos(const C2dEffect* pEffect, const CMatrix& matrix, CVector& pos); + static void ComputeEffectQueueDir(const C2dEffect* pEffect, const CMatrix& matrix, CVector& pos); + static void ComputeEffectUseDir(const C2dEffect* pEffect, const CMatrix& matrix, CVector& pos); + +}; + +CPedAttractorManager* GetPedAttractorManager(); + +enum ePedAttractorType +{ + ATTRACTOR_ATM = 0, + ATTRACTOR_SEAT, + ATTRACTOR_STOP, + ATTRACTOR_PIZZA, + ATTRACTOR_SHELTER, + ATTRACTOR_ICECREAM +}; + +class CPedAttractor +{ +protected: + C2dEffect* p2dEffect; + std::vector<CPed*> vApproachingQueue; + std::vector<CPed*> vWaitingQueue; + int32 m_nMaxPedsInAttractor; + float m_fQueueDistance; + float m_fTimeInWaitQueue; + float m_fTimeInApproachingQueue; + float m_fDistanceToUseAttractor; + float m_fAcceptableHeading; + float m_fMaxPositionDisplacement; + float m_fMaxHeadingDisplacement; + CVector vecEffectPos; + CVector vecQueueDir; + CVector vecUseDir; + +public: + virtual float GetHeadOfQueueWaitTime() { return 0.0f; } + virtual ~CPedAttractor() {}; + virtual ePedAttractorType GetType() const = 0; + virtual void UpdatePedStateOnDeparture(CPed* pPed) const = 0; + virtual bool IsAtHeadOfQueue(CPed* pPed) const { return vWaitingQueue.front() == pPed; } + virtual void ComputeAttractPos(int32 id, CVector& pos) const; + virtual void ComputeAttractHeading(int32 id, float& pHeading) const; + virtual bool BroadcastDeparture(CPed* pPed); + + bool IsRegisteredWithPed(CPed* pPed) const; + bool DeRegisterPed(CPed* pPed); + float ComputeDeltaHeading() const; + float ComputeDeltaPos() const; + void ComputeAttractTime(int32 id, bool, float& time) const; + int32 GetNoOfRegisteredPeds() const { return (int32)(vWaitingQueue.size() + vApproachingQueue.size()); } + int32 ComputeFreeSlot() const { return (int32)vWaitingQueue.size(); } + bool IsInQueue(CPed*) const; + bool RegisterPed(CPed*); + bool BroadcastArrival(CPed*); + + CPedAttractor(C2dEffect* pEffect, const CMatrix& matrix, int32 maxpeds, float qdist, float waitTime, float approachTime, float distance, float headingdiff, float posdisp, float headdisp); + + C2dEffect* GetEffect() const { return p2dEffect; } + const CVector& GetEffectPos() const { return vecEffectPos; } + int32 GetMaxPedsInAttractor() const { return m_nMaxPedsInAttractor; } + float GetDistanceToCountSeekDone() const { return m_fDistanceToUseAttractor; } + float GetAcceptableHeading() const { return m_fAcceptableHeading; } +}; + +class CPedAtmAttractor : public CPedAttractor +{ +public: + virtual ePedAttractorType GetType() const override { return ATTRACTOR_ATM; }; + virtual void UpdatePedStateOnDeparture(CPed* pPed) const override; + CPedAtmAttractor(C2dEffect* pEffect, const CMatrix& matrix, int32 maxpeds, float qdist, float waitTime, float approachTime, float distance, float headingdiff, float posdisp, float headdisp) : + CPedAttractor(pEffect, matrix, maxpeds, qdist, waitTime, approachTime, distance, headingdiff, posdisp, headdisp) + {}; +}; + +class CPedIceCreamAttractor : public CPedAttractor +{ +public: + virtual ~CPedIceCreamAttractor() override { GetPedAttractorManager()->RemoveIceCreamVanEffects(p2dEffect); } + virtual ePedAttractorType GetType() const override { return ATTRACTOR_ICECREAM; } + virtual void UpdatePedStateOnDeparture(CPed* pPed) const override {}; + CPedIceCreamAttractor(C2dEffect* pEffect, const CMatrix& matrix, int32 maxpeds, float qdist, float waitTime, float approachTime, float distance, float headingdiff, float posdisp, float headdisp) : + CPedAttractor(pEffect, matrix, maxpeds, qdist, waitTime, approachTime, distance, headingdiff, posdisp, headdisp) + {}; +}; + +class CPedPizzaAttractor : public CPedAttractor +{ +public: + virtual float GetHeadOfQueueWaitTime() override { return 2000.0f; } + virtual ePedAttractorType GetType() const override { return ATTRACTOR_PIZZA; } + virtual void UpdatePedStateOnDeparture(CPed* pPed) const override; + CPedPizzaAttractor(C2dEffect* pEffect, const CMatrix& matrix, int32 maxpeds, float qdist, float waitTime, float approachTime, float distance, float headingdiff, float posdisp, float headdisp) : + CPedAttractor(pEffect, matrix, maxpeds, qdist, waitTime, approachTime, distance, headingdiff, posdisp, headdisp) + {}; +}; + +class CPedSeatAttractor : public CPedAttractor +{ +public: + virtual ePedAttractorType GetType() const override { return ATTRACTOR_SEAT; } + virtual void UpdatePedStateOnDeparture(CPed* pPed) const override {}; + CPedSeatAttractor(C2dEffect* pEffect, const CMatrix& matrix, int32 maxpeds, float qdist, float waitTime, float approachTime, float distance, float headingdiff, float posdisp, float headdisp) : + CPedAttractor(pEffect, matrix, maxpeds, qdist, waitTime, approachTime, distance, headingdiff, posdisp, headdisp) + {}; +}; + +class CPedShelterAttractor : public CPedAttractor +{ + static std::vector<CVector> ms_displacements; +public: + virtual ePedAttractorType GetType() const override { return ATTRACTOR_SHELTER; } + virtual bool BroadcastDeparture(CPed*) override; + virtual void UpdatePedStateOnDeparture(CPed* pPed) const override {}; + virtual bool IsAtHeadOfQueue(CPed* pPed) const override { return true; } + virtual void ComputeAttractPos(int qid, CVector& pos) const override; + virtual void ComputeAttractHeading(int qid, float& heading) const override; + + CPedShelterAttractor(C2dEffect* pEffect, const CMatrix& matrix, int32 maxpeds, float qdist, float waitTime, float approachTime, float distance, float headingdiff, float posdisp, float headdisp) : + CPedAttractor(pEffect, matrix, maxpeds, qdist, waitTime, approachTime, distance, headingdiff, posdisp, headdisp) + {}; + + + CVector GetDisplacement(int32 qid) const; +}; + +class CPedStopAttractor : public CPedAttractor +{ +public: + virtual ePedAttractorType GetType() const override { return ATTRACTOR_STOP; } + virtual void UpdatePedStateOnDeparture(CPed* pPed) const override {}; + + CPedStopAttractor(C2dEffect* pEffect, const CMatrix& matrix, int32 maxpeds, float qdist, float waitTime, float approachTime, float distance, float headingdiff, float posdisp, float headdisp) : + CPedAttractor(pEffect, matrix, maxpeds, qdist, waitTime, approachTime, distance, headingdiff, posdisp, headdisp) + {}; +};
\ No newline at end of file diff --git a/src/peds/PedChat.cpp b/src/peds/PedChat.cpp index 9045a2e0..4480a8cd 100644 --- a/src/peds/PedChat.cpp +++ b/src/peds/PedChat.cpp @@ -4,62 +4,80 @@ #include "General.h" #include "Ped.h" +// --MIAMI: Done // Corresponds to ped sounds (from SOUND_PED_DEATH to SOUND_PED_TAXI_CALL) -PedAudioData CommentWaitTime[39] = { - {500, 800, 500, 2}, - {500, 800, 500, 2}, - {500, 800, 500, 2}, - {500, 800, 500, 2}, - {100, 2, 100, 2}, - {700, 500, 1000, 500}, - {700, 500, 1000, 500}, - {5000, 2000, 15000, 3000}, - {5000, 2000, 15000, 3000}, - {5000, 2000, 15000, 3000}, - {6000, 6000, 6000, 6000}, - {1000, 1000, 2000, 2000}, - {1000, 500, 2000, 1500}, - {1000, 500, 2000, 1500}, - {800, 200, 1000, 500}, - {800, 200, 1000, 500}, - {800, 400, 2000, 1000}, - {800, 400, 2000, 1000}, - {400, 300, 2000, 1000}, - {2000, 1000, 2500, 1500}, - {200, 200, 200, 200}, - {6000, 3000, 5000, 6000}, - {6000, 3000, 9000, 5000}, - {6000, 3000, 9000, 5000}, - {6000, 3000, 9000, 5000}, - {400, 300, 4000, 1000}, - {400, 300, 4000, 1000}, - {400, 300, 4000, 1000}, - {1000, 500, 3000, 1000}, - {1000, 500, 1000, 1000}, - {3000, 2000, 3000, 2000}, - {1000, 500, 3000, 6000}, - {1000, 500, 2000, 4000}, - {1000, 500, 2000, 5000}, - {1000, 500, 3000, 2000}, - {1600, 1000, 2000, 2000}, - {3000, 2000, 5000, 3000}, - {1000, 1000, 1000, 1000}, - {1000, 1000, 5000, 5000}, +PedAudioData CommentWaitTime[56] = { + { 500, 800, 500, 2 }, + { 500, 800, 500, 2 }, + { 500, 800, 500, 2 }, + { 500, 800, 500, 2 }, + { 100, 2, 100, 2 }, + { 500, 500, 2000, 1000 }, + { 2000, 50, 2050, 1000 }, + { 5000, 2000, 7000, 3000 }, + { 5000, 2000, 7000, 3000 }, + { 300, 200, 500, 200 }, + { 3000, 1000, 4000, 1000 }, + { 6000, 6000, 6000, 6000 }, + { 4000, 1000, 5000, 1000 }, + { 3000, 1000, 4000, 1000 }, + { 1000, 1000, 2000, 2000 }, + { 1000, 500, 2000, 1500 }, + { 1700, 1000, 3000, 1000 }, + { 800, 200, 1000, 500 }, + { 800, 200, 1000, 500 }, + { 800, 400, 2000, 1000 }, + { 800, 400, 2000, 1000 }, + { 2000, 2000, 4000, 4000 }, + { 2000, 2000, 4000, 1000 }, + { 4000, 1000, 5000, 1000 }, + { 800, 400, 1200, 500 }, + { 5000, 1000, 6000, 2000 }, + { 5000, 1000, 6000, 2000 }, + { 5000, 1000, 6000, 2000 }, + { 5000, 1000, 6000, 2000 }, + { 5000, 1000, 6000, 2000 }, + { 5000, 1000, 6000, 2000 }, + { 5000, 1000, 6000, 2000 }, + { 4000, 2000, 7000, 2000 }, + { 1000, 300, 2000, 1000 }, + { 1500, 1000, 2500, 1000 }, + { 200, 200, 200, 200 }, + { 2000, 1000, 4000, 1000 }, + { 2000, 1000, 4000, 1000 }, + { 1000, 500, 3000, 1000 }, + { 1000, 500, 1000, 1000 }, + { 3000, 2000, 5000, 1000 }, + { 3000, 2000, 5000, 1000 }, + { 3000, 2000, 3000, 2000 }, + { 2000, 1000, 3000, 1000 }, + { 2500, 1000, 5000, 5000 }, + { 2000, 1000, 3000, 2000 }, + { 4000, 1000, 5000, 1000 }, + { 1000, 500, 2000, 4000 }, + { 1000, 500, 2000, 5000 }, + { 2000, 500, 2500, 500 }, + { 1000, 500, 3000, 2000 }, + { 1600, 1000, 2000, 2000 }, + { 2000, 1000, 4000, 2000 }, + { 1500, 1000, 2500, 1000 }, + { 1000, 1000, 5000, 5000 }, + { 0, 0, 0, 0 } }; +// --MIAMI: Done bool CPed::ServiceTalkingWhenDead(void) { return m_queuedSound == SOUND_PED_DEATH; } +// --MIAMI: Done void CPed::ServiceTalking(void) { if (!bBodyPartJustCameOff || m_bodyPartBleeding != PED_HEAD) { - if (!CGeneral::faststricmp(CModelInfo::GetModelInfo(GetModelIndex())->GetName(), "bomber")) - m_queuedSound = SOUND_PED_BOMBER; - else if (m_nPedState == PED_ON_FIRE) + if (!CGame::germanGame && m_pFire) m_queuedSound = SOUND_PED_BURNING; if (m_queuedSound != SOUND_NO_SOUND) { @@ -73,6 +91,10 @@ CPed::ServiceTalking(void) CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nFixedDelayTime + CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(0, CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nOverrideFixedDelayTime); + + if (m_queuedSound == SOUND_PED_PLAYER_BEFORESEX && IsPlayer()) + m_soundStart += 2000; + m_lastQueuedSound = m_queuedSound; m_queuedSound = SOUND_NO_SOUND; } @@ -80,74 +102,67 @@ CPed::ServiceTalking(void) } } +// --MIAMI: Done void CPed::Say(uint16 audio) { uint16 audioToPlay = audio; - if (IsPlayer()) { + if (3.0f + TheCamera.GetPosition().z < GetPosition().z) + return; + + if (TheCamera.m_CameraAverageSpeed > 1.65f) { + if (audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND) + return; - // Ofc this part isn't in VC. + } else if (TheCamera.m_CameraAverageSpeed > 1.25f) { + if (audio != SOUND_PED_DEATH && + audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND && + audio != SOUND_PED_TAXI_WAIT && audio != SOUND_PED_EVADE) + return; + + } else if (TheCamera.m_CameraAverageSpeed > 0.9f) { switch (audio) { case SOUND_PED_DEATH: - audioToPlay = SOUND_PED_DAMAGE; - break; case SOUND_PED_DAMAGE: case SOUND_PED_HIT: case SOUND_PED_LAND: - break; - case SOUND_PED_BULLET_HIT: - case SOUND_PED_CAR_JACKED: - case SOUND_PED_DEFEND: - audioToPlay = SOUND_PED_HIT; + case SOUND_PED_BURNING: + case SOUND_PED_FLEE_SPRINT: + case SOUND_PED_TAXI_WAIT: + case SOUND_PED_EVADE: + case SOUND_PED_CAR_COLLISION: + case SOUND_PED_BOAT_COLLISION: + case SOUND_PED_HORN_ACTIVE: break; default: return; } - } else { - if (TheCamera.GetPosition().z + 3.0f < GetPosition().z) - return; - - if (TheCamera.m_CameraAverageSpeed > 1.65f) { -#ifdef VC_PED_PORTS - if (audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND) -#endif - return; - - } else if (TheCamera.m_CameraAverageSpeed > 1.25f) { - if (audio != SOUND_PED_DEATH && -#ifdef VC_PED_PORTS - audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND && -#endif - audio != SOUND_PED_TAXI_WAIT && audio != SOUND_PED_EVADE) - return; - - } else if (TheCamera.m_CameraAverageSpeed > 0.9f) { - switch (audio) { - case SOUND_PED_DEATH: -#ifdef VC_PED_PORTS - case SOUND_PED_DAMAGE: - case SOUND_PED_HIT: - case SOUND_PED_LAND: -#endif - case SOUND_PED_BURNING: - case SOUND_PED_FLEE_SPRINT: - case SOUND_PED_TAXI_WAIT: - case SOUND_PED_EVADE: - case SOUND_PED_CAR_COLLISION: - break; - default: - return; - } - } } if (audioToPlay < m_queuedSound) { if (audioToPlay != m_lastQueuedSound || audioToPlay == SOUND_PED_DEATH + + // See VC Ped Speech patch +#ifdef FIX_BUGS || CommentWaitTime[audioToPlay - SOUND_PED_DEATH].m_nOverrideMaxRandomDelayTime - + m_lastSoundStart - + (uint32) CGeneral::GetRandomNumberInRange(0, CommentWaitTime[audioToPlay - SOUND_PED_DEATH].m_nMaxRandomDelayTime) <= CTimer::GetTimeInMilliseconds()) { + + (uint32)CGeneral::GetRandomNumberInRange(0, CommentWaitTime[audioToPlay - SOUND_PED_DEATH].m_nMaxRandomDelayTime) +#else + || CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nOverrideMaxRandomDelayTime + + (uint32)CGeneral::GetRandomNumberInRange(0, CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nMaxRandomDelayTime) +#endif + + m_lastSoundStart <= CTimer::GetTimeInMilliseconds()) { m_queuedSound = audioToPlay; } } +} + +// --MIAMI: Done +void +CPed::Say(uint16 audio, int32 time) +{ + if (m_delayedSoundID == -1) { + m_delayedSoundID = audio; + m_delayedSoundTimer = CTimer::GetTimeInMilliseconds() + time; + } }
\ No newline at end of file diff --git a/src/peds/PedDebug.cpp b/src/peds/PedDebug.cpp index 1c22963e..0809581b 100644 --- a/src/peds/PedDebug.cpp +++ b/src/peds/PedDebug.cpp @@ -7,10 +7,11 @@ #include "Sprite.h" #include "Text.h" - +// TODO(Miami) static char ObjectiveText[][28] = { "No Obj", "Wait on Foot", + "Wait on Foot For Cop", "Flee on Foot Till Safe", "Guard Spot", "Guard Area", @@ -21,6 +22,8 @@ static char ObjectiveText[][28] = { "Flee Char on Foot Till Safe", "Flee Char on Foot Always", "GoTo Char on Foot", + "GoTo Char on Foot Walking", + "Hassle Char", "Follow Char in Formation", "Leave Car", "Enter Car as Passenger", @@ -42,10 +45,9 @@ static char ObjectiveText[][28] = { "Catch Train", "Buy IceCream", "Steal Any Car", + "Steal Any Mission Car", "Mug Char", -#ifdef VC_PED_PORTS - "Leave Car and Die" -#endif + "Leave Car and Die", }; static char StateText[][18] = { @@ -82,8 +84,14 @@ static char StateText[][18] = { "Investigate", "Step away", "On Fire", + "Sun Bathe", + "Flash", + "Jog", + "Answer Mobile", "Unknown", "STATES_NO_AI", + "Abseil", + "Sit", "Jump", "Fall", "GetUp", @@ -106,6 +114,7 @@ static char StateText[][18] = { "Exit Car", "Hands Up", "Arrested", + "Deploying Stinger" }; static char PersonalityTypeText[][18] = { @@ -283,7 +292,7 @@ CPed::DebugRenderOnePedText(void) CFont::SetJustifyOff(); CFont::SetColor(CRGBA(255, 255, 0, 255)); CFont::SetBackGroundOnlyTextOn(); - CFont::SetFontStyle(0); + CFont::SetFontStyle(1); AsciiToUnicode(StateText[m_nPedState], gUString); CFont::PrintString(screenCoords.x, screenCoords.y, gUString); AsciiToUnicode(ObjectiveText[m_objective], gUString); diff --git a/src/peds/PedIK.cpp b/src/peds/PedIK.cpp index ebd41296..2925667a 100644 --- a/src/peds/PedIK.cpp +++ b/src/peds/PedIK.cpp @@ -7,11 +7,13 @@ #include "General.h" #include "RwHelper.h" -LimbMovementInfo CPedIK::ms_torsoInfo = { DEGTORAD(50.0f), DEGTORAD(-50.0f), DEGTORAD(15.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(7.0f) }; -LimbMovementInfo CPedIK::ms_headInfo = { DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(10.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(5.0f) }; +//--MIAMI: file done + +LimbMovementInfo CPedIK::ms_torsoInfo = { DEGTORAD(50.0f), DEGTORAD(-50.0f), DEGTORAD(8.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(5.0f) }; +LimbMovementInfo CPedIK::ms_headInfo = { DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(15.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(8.0f) }; LimbMovementInfo CPedIK::ms_headRestoreInfo = { DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(10.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(5.0f) }; -LimbMovementInfo CPedIK::ms_upperArmInfo = { DEGTORAD(20.0f), DEGTORAD(-100.0f), DEGTORAD(20.0f), DEGTORAD(70.0f), DEGTORAD(-70.0f), DEGTORAD(10.0f) }; -LimbMovementInfo CPedIK::ms_lowerArmInfo = { DEGTORAD(80.0f), DEGTORAD(0.0f), DEGTORAD(20.0f), DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(5.0f) }; +LimbMovementInfo CPedIK::ms_upperArmInfo = { DEGTORAD(5.0f), DEGTORAD(-120.0f), DEGTORAD(20.0f), DEGTORAD(70.0f), DEGTORAD(-70.0f), DEGTORAD(20.0f) }; +LimbMovementInfo CPedIK::ms_lowerArmInfo = { DEGTORAD(60.0f), DEGTORAD(0.0f), DEGTORAD(15.0f), DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(10.0f) }; const RwV3d XaxisIK = { 1.0f, 0.0f, 0.0f}; const RwV3d YaxisIK = { 0.0f, 1.0f, 0.0f}; @@ -31,7 +33,6 @@ CPedIK::CPedIK(CPed *ped) m_lowerArmOrient.pitch = 0.0f; } -#ifdef PED_SKIN inline RwMatrix* GetBoneMatrix(CPed *ped, int32 bone) { @@ -45,134 +46,20 @@ GetComponentMatrix(CPed *ped, int32 node) { return GetBoneMatrix(ped, ped->m_pFrames[node]->nodeID); } -#endif void CPedIK::RotateTorso(AnimBlendFrameData *node, LimbOrientation *limb, bool changeRoll) { -#ifdef PED_SKIN - if(IsClumpSkinned(m_ped->GetClump())){ - RtQuat *q = &node->hanimFrame->q; -#ifndef FIX_BUGS - // this is what the game does (also VC), but it does not look great - RtQuatRotate(q, &XaxisIK, RADTODEG(limb->yaw), rwCOMBINEPRECONCAT); - RtQuatRotate(q, &ZaxisIK, RADTODEG(limb->pitch), rwCOMBINEPRECONCAT); // pitch -#else - // copied the code from the non-skinned case - // this seems to work ok - - // We can't get the parent matrix of an hanim frame but - // this function is always called with PED_MID, so we know the parent frame. - // Trouble is that PED_MID is "Smid" on PS2/PC but BONE_torso on mobile/xbox... - // Assuming BONE_torso, the parent is BONE_mid, so let's use that: - RwMatrix *mat = GetBoneMatrix(m_ped, BONE_mid); - - RwV3d vec1, vec2; - vec1.x = mat->right.z; - vec1.y = mat->up.z; - vec1.z = mat->at.z; - float c = Cos(m_ped->m_fRotationCur); - float s = Sin(m_ped->m_fRotationCur); - vec2.x = -(c*mat->right.x + s*mat->right.y); - vec2.y = -(c*mat->up.x + s*mat->up.y); - vec2.z = -(c*mat->at.x + s*mat->at.y); - - // Not sure what exactly to do here - RtQuatRotate(q, &vec1, RADTODEG(limb->yaw), rwCOMBINEPRECONCAT); - RtQuatRotate(q, &vec2, RADTODEG(limb->pitch), rwCOMBINEPRECONCAT); -#endif - m_ped->bDontAcceptIKLookAts = true; - }else -#endif - { - RwFrame *f = node->frame; - RwMatrix *mat = GetWorldMatrix(RwFrameGetParent(f), RwMatrixCreate()); - - RwV3d upVector = { mat->right.z, mat->up.z, mat->at.z }; - RwV3d rightVector; - RwV3d pos = RwFrameGetMatrix(f)->pos; - - // rotation == 0 -> looking in y direction - // left? vector - float c = Cos(m_ped->m_fRotationCur); - float s = Sin(m_ped->m_fRotationCur); - rightVector.x = -(c*mat->right.x + s*mat->right.y); - rightVector.y = -(c*mat->up.x + s*mat->up.y); - rightVector.z = -(c*mat->at.x + s*mat->at.y); - - if(changeRoll){ - // Used when aiming only involves over the legs.(canAimWithArm) - // Automatically changes roll(forward rotation) axis of the parts above upper legs while moving, based on position of upper legs. - // Not noticeable in normal conditions... - - RwV3d forwardVector; - CVector inversedForward = CrossProduct(CVector(0.0f, 0.0f, 1.0f), mat->up); - inversedForward.Normalise(); - float dotProduct = DotProduct(mat->at, inversedForward); - if(dotProduct > 1.0f) dotProduct = 1.0f; - if(dotProduct < -1.0f) dotProduct = -1.0f; - float alpha = Acos(dotProduct); - - if(mat->at.z < 0.0f) - alpha = -alpha; - - forwardVector.x = s * mat->right.x - c * mat->right.y; - forwardVector.y = s * mat->up.x - c * mat->up.y; - forwardVector.z = s * mat->at.x - c * mat->at.y; - - float curYaw, curPitch; - ExtractYawAndPitchWorld(mat, &curYaw, &curPitch); - RwMatrixRotate(RwFrameGetMatrix(f), &rightVector, RADTODEG(limb->pitch), rwCOMBINEPOSTCONCAT); - RwMatrixRotate(RwFrameGetMatrix(f), &upVector, RADTODEG(limb->yaw - (curYaw - m_ped->m_fRotationCur)), rwCOMBINEPOSTCONCAT); - RwMatrixRotate(RwFrameGetMatrix(f), &forwardVector, RADTODEG(alpha), rwCOMBINEPOSTCONCAT); - }else{ - // pitch - RwMatrixRotate(RwFrameGetMatrix(f), &rightVector, RADTODEG(limb->pitch), rwCOMBINEPOSTCONCAT); - // yaw - RwMatrixRotate(RwFrameGetMatrix(f), &upVector, RADTODEG(limb->yaw), rwCOMBINEPOSTCONCAT); - } - RwFrameGetMatrix(f)->pos = pos; - RwMatrixDestroy(mat); - } + RtQuat *q = &node->hanimFrame->q; + RtQuatRotate(q, &XaxisIK, RADTODEG(limb->yaw), rwCOMBINEREPLACE); + RtQuatRotate(q, &ZaxisIK, RADTODEG(limb->pitch), rwCOMBINEPRECONCAT); + m_ped->bDontAcceptIKLookAts = true; } void -CPedIK::GetComponentPosition(RwV3d *pos, uint32 node) +CPedIK::GetComponentPosition(RwV3d &pos, uint32 node) { - RwFrame *f; - RwMatrix *mat; - -#ifdef PED_SKIN - if(IsClumpSkinned(m_ped->GetClump())){ - pos->x = 0.0f; - pos->y = 0.0f; - pos->z = 0.0f; - mat = GetComponentMatrix(m_ped, node); - // could just copy the position out of the matrix... - RwV3dTransformPoints(pos, pos, 1, mat); - }else -#endif - { - f = m_ped->m_pFrames[node]->frame; - mat = RwFrameGetMatrix(f); - *pos = mat->pos; - - for (f = RwFrameGetParent(f); f; f = RwFrameGetParent(f)) - RwV3dTransformPoints(pos, pos, 1, RwFrameGetMatrix(f)); - } -} - -RwMatrix* -CPedIK::GetWorldMatrix(RwFrame *source, RwMatrix *destination) -{ - RwFrame *i; - - *destination = *RwFrameGetMatrix(source); - - for (i = RwFrameGetParent(source); i; i = RwFrameGetParent(i)) - RwMatrixTransform(destination, RwFrameGetMatrix(i), rwCOMBINEPOSTCONCAT); - - return destination; + pos = GetComponentMatrix(m_ped, node)->pos; } LimbMoveStatus @@ -182,15 +69,15 @@ CPedIK::MoveLimb(LimbOrientation &limb, float targetYaw, float targetPitch, Limb // yaw - if (limb.yaw > targetYaw) { - limb.yaw -= moveInfo.yawD; - } else if (limb.yaw < targetYaw) { - limb.yaw += moveInfo.yawD; - } - - if (Abs(limb.yaw - targetYaw) < moveInfo.yawD) { + if(Abs(limb.yaw-targetYaw) < moveInfo.yawD){ limb.yaw = targetYaw; result = ANGLES_SET_EXACTLY; + }else{ + if (limb.yaw > targetYaw) { + limb.yaw -= moveInfo.yawD; + } else if (limb.yaw < targetYaw) { + limb.yaw += moveInfo.yawD; + } } if (limb.yaw > moveInfo.maxYaw || limb.yaw < moveInfo.minYaw) { @@ -200,16 +87,16 @@ CPedIK::MoveLimb(LimbOrientation &limb, float targetYaw, float targetPitch, Limb // pitch - if (limb.pitch > targetPitch) { - limb.pitch -= moveInfo.pitchD; - } else if (limb.pitch < targetPitch) { - limb.pitch += moveInfo.pitchD; - } - - if (Abs(limb.pitch - targetPitch) < moveInfo.pitchD) + if (Abs(limb.pitch - targetPitch) < moveInfo.pitchD){ limb.pitch = targetPitch; - else + }else{ + if (limb.pitch > targetPitch) { + limb.pitch -= moveInfo.pitchD; + } else if (limb.pitch < targetPitch) { + limb.pitch += moveInfo.pitchD; + } result = ONE_ANGLE_COULDNT_BE_SET_EXACTLY; + } if (limb.pitch > moveInfo.maxPitch || limb.pitch < moveInfo.minPitch) { limb.pitch = clamp(limb.pitch, moveInfo.minPitch, moveInfo.maxPitch); @@ -226,107 +113,60 @@ CPedIK::RestoreGunPosn(void) return limbStatus == ANGLES_SET_EXACTLY; } -#ifdef PED_SKIN -void -CPedIK::RotateHead(void) -{ - RtQuat *q = &m_ped->m_pFrames[PED_HEAD]->hanimFrame->q; - RtQuatRotate(q, &XaxisIK, RADTODEG(m_headOrient.yaw), rwCOMBINEREPLACE); - RtQuatRotate(q, &ZaxisIK, RADTODEG(m_headOrient.pitch), rwCOMBINEPOSTCONCAT); - m_ped->bDontAcceptIKLookAts = true; -} -#endif - bool CPedIK::LookInDirection(float targetYaw, float targetPitch) { bool success = true; float yaw, pitch; -#ifdef PED_SKIN - if(IsClumpSkinned(m_ped->GetClump())){ - if (!(m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION)) { - m_ped->m_pFrames[PED_HEAD]->flag |= AnimBlendFrameData::IGNORE_ROTATION; - ExtractYawAndPitchLocalSkinned(m_ped->m_pFrames[PED_HEAD], &m_headOrient.yaw, &m_headOrient.pitch); - } - - // parent of head is torso - RwMatrix worldMat = *GetBoneMatrix(m_ped, BONE_torso); - ExtractYawAndPitchWorld(&worldMat, &yaw, &pitch); - - LimbMoveStatus headStatus = MoveLimb(m_headOrient, CGeneral::LimitRadianAngle(targetYaw - yaw), - CGeneral::LimitRadianAngle(DEGTORAD(10.0f)), ms_headInfo); - if (headStatus == ANGLES_SET_TO_MAX) - success = false; - - if (headStatus != ANGLES_SET_EXACTLY){ - if (!(m_flags & LOOKAROUND_HEAD_ONLY)){ - if (MoveLimb(m_torsoOrient, CGeneral::LimitRadianAngle(targetYaw), targetPitch, ms_torsoInfo)) - success = true; - }else{ - RotateHead(); - return success; - } - } - - if (!(m_flags & LOOKAROUND_HEAD_ONLY)) - RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false); - RotateHead(); - }else -#endif - { - RwFrame *frame = m_ped->m_pFrames[PED_HEAD]->frame; - RwMatrix *frameMat = RwFrameGetMatrix(frame); - - if (!(m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION)) { - m_ped->m_pFrames[PED_HEAD]->flag |= AnimBlendFrameData::IGNORE_ROTATION; - ExtractYawAndPitchLocal(frameMat, &m_headOrient.yaw, &m_headOrient.pitch); - } - - RwMatrix *worldMat = RwMatrixCreate(); - worldMat = GetWorldMatrix(RwFrameGetParent(frame), worldMat); - - ExtractYawAndPitchWorld(worldMat, &yaw, &pitch); - RwMatrixDestroy(worldMat); - - yaw += m_torsoOrient.yaw; - float neededYawTurn = CGeneral::LimitRadianAngle(targetYaw - yaw); - pitch *= Cos(neededYawTurn); + if (!(m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION)) { + m_ped->m_pFrames[PED_HEAD]->flag |= AnimBlendFrameData::IGNORE_ROTATION; + RwMatrix *m = GetComponentMatrix(m_ped, PED_NECK); + m_headOrient.yaw = Atan2(-m->at.y, -m->at.x); + m_headOrient.yaw -= m_ped->m_fRotationCur; + m_headOrient.yaw = CGeneral::LimitRadianAngle(m_headOrient.yaw); + float up = clamp(m->up.z, -1.0f, 1.0f); + m_headOrient.pitch = Atan2(-up, Sqrt(1.0f - SQR(-up))); + } - float neededPitchTurn = CGeneral::LimitRadianAngle(targetPitch - pitch); - LimbMoveStatus headStatus = MoveLimb(m_headOrient, neededYawTurn, neededPitchTurn, ms_headInfo); - if (headStatus == ANGLES_SET_TO_MAX) - success = false; + // parent of head is neck + RwMatrix *m = GetComponentMatrix(m_ped, PED_NECK); + yaw = CGeneral::LimitRadianAngle(Atan2(-m->at.y, -m->at.x)); + float up = clamp(m->up.z, -1.0f, 1.0f); + pitch = Atan2(-up, Sqrt(1.0f - SQR(-up))); + float headYaw = CGeneral::LimitRadianAngle(targetYaw - (yaw + m_torsoOrient.yaw)); + float headPitch = CGeneral::LimitRadianAngle(targetPitch - pitch) * Cos(Min(Abs(headYaw), HALFPI)); - if (headStatus != ANGLES_SET_EXACTLY && !(m_flags & LOOKAROUND_HEAD_ONLY)) { - float remainingTurn = CGeneral::LimitRadianAngle(targetYaw - m_ped->m_fRotationCur); - if (MoveLimb(m_torsoOrient, remainingTurn, targetPitch, ms_torsoInfo)) - success = true; - } - CMatrix nextFrame = CMatrix(frameMat); - CVector framePos = nextFrame.GetPosition(); + LimbMoveStatus headStatus = MoveLimb(m_headOrient, headYaw, headPitch, ms_headInfo); + if (headStatus == ANGLES_SET_TO_MAX) + success = false; - nextFrame.SetRotateZ(m_headOrient.pitch); - nextFrame.RotateX(m_headOrient.yaw); - nextFrame.GetPosition() += framePos; - nextFrame.UpdateRW(); + if (headStatus != ANGLES_SET_EXACTLY && !(m_flags & LOOKAROUND_HEAD_ONLY)) + if (MoveLimb(m_torsoOrient, CGeneral::LimitRadianAngle(targetYaw-m_ped->m_fRotationCur), targetPitch, ms_torsoInfo)) + success = true; - if (!(m_flags & LOOKAROUND_HEAD_ONLY)) - RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false); + // This was RotateHead + RtQuat *q = &m_ped->m_pFrames[PED_HEAD]->hanimFrame->q; + RtQuatRotate(q, &ZaxisIK, RADTODEG(m_headOrient.pitch), rwCOMBINEREPLACE); + RtQuatRotate(q, &XaxisIK, RADTODEG(m_headOrient.yaw), rwCOMBINEPRECONCAT); + m_ped->bDontAcceptIKLookAts = true; - } + if (!(m_flags & LOOKAROUND_HEAD_ONLY)) + RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false); return success; } bool CPedIK::LookAtPosition(CVector const &pos) { + RwV3d *pedpos = &GetComponentMatrix(m_ped, PED_MID)->pos; float yawToFace = CGeneral::GetRadianAngleBetweenPoints( pos.x, pos.y, - m_ped->GetPosition().x, m_ped->GetPosition().y); + pedpos->x, pedpos->y); float pitchToFace = CGeneral::GetRadianAngleBetweenPoints( + // BUG? not using pedpos here pos.z, (m_ped->GetPosition() - pos).Magnitude2D(), - m_ped->GetPosition().z, 0.0f); + pedpos->z, 0.0f); return LookInDirection(yawToFace, pitchToFace); } @@ -336,12 +176,12 @@ CPedIK::PointGunInDirection(float targetYaw, float targetPitch) { bool result = true; bool armPointedToGun = false; - float angle = CGeneral::LimitRadianAngle(targetYaw - m_ped->m_fRotationCur); - m_flags &= (~GUN_POINTED_SUCCESSFULLY); + targetYaw = CGeneral::LimitRadianAngle(targetYaw - m_ped->GetForward().Heading()); + m_flags &= ~GUN_POINTED_SUCCESSFULLY; m_flags |= LOOKAROUND_HEAD_ONLY; if (m_flags & AIMS_WITH_ARM) { - armPointedToGun = PointGunInDirectionUsingArm(angle, targetPitch); - angle = CGeneral::LimitRadianAngle(angle - m_upperArmOrient.yaw); + armPointedToGun = PointGunInDirectionUsingArm(targetYaw, targetPitch); + targetYaw = CGeneral::LimitRadianAngle(targetYaw - (m_upperArmOrient.yaw + m_lowerArmOrient.yaw)); } if (armPointedToGun) { if (m_flags & AIMS_WITH_ARM && m_torsoOrient.yaw * m_upperArmOrient.yaw < 0.0f) @@ -350,31 +190,35 @@ CPedIK::PointGunInDirection(float targetYaw, float targetPitch) // Unused code RwMatrix *matrix; float yaw, pitch; -#ifdef PED_SKIN - if(IsClumpSkinned(m_ped->GetClump())){ - matrix = RwMatrixCreate(); - *matrix = *GetComponentMatrix(m_ped, PED_UPPERARMR); - ExtractYawAndPitchWorld(matrix, &yaw, &pitch); - RwMatrixDestroy(matrix); - }else -#endif - { - matrix = GetWorldMatrix(RwFrameGetParent(m_ped->m_pFrames[PED_UPPERARMR]->frame), RwMatrixCreate()); - ExtractYawAndPitchWorld(matrix, &yaw, &pitch); - RwMatrixDestroy(matrix); - } - // + matrix = RwMatrixCreate(); + *matrix = *GetComponentMatrix(m_ped, PED_CLAVICLER); + ExtractYawAndPitchWorld(matrix, &yaw, &pitch); + RwMatrixDestroy(matrix); - LimbMoveStatus status = MoveLimb(m_torsoOrient, angle, targetPitch, ms_torsoInfo); + if(m_flags & AIMS_WITH_ARM){ + if(targetPitch > 0.0f) + targetPitch = Max(targetPitch - Abs(targetYaw), 0.0f); + else + targetPitch = Min(targetPitch + Abs(targetYaw), 0.0f); + } + LimbMoveStatus status = MoveLimb(m_torsoOrient, targetYaw, targetPitch, ms_torsoInfo); if (status == ANGLES_SET_TO_MAX) result = false; else if (status == ANGLES_SET_EXACTLY) m_flags |= GUN_POINTED_SUCCESSFULLY; } - if (TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam() && m_flags & AIMS_WITH_ARM) - RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, true); - else - RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false); + RwMatrix *m = GetBoneMatrix(m_ped, BONE_spine); // BUG: game uses index 2 directly, which happens to be identical to BONE_spine + RwV3d axis = { 0.0f, 0.0f, 0.0f }; + float axisangle = -CGeneral::LimitRadianAngle(Atan2(-m->at.y, -m->at.x) - m_ped->m_fRotationCur); + axis.y = -Sin(axisangle); + axis.z = Cos(axisangle); + + // this was RotateTorso + RtQuat *q = &m_ped->m_pFrames[PED_MID]->hanimFrame->q; + RtQuatRotate(q, &axis, RADTODEG(m_torsoOrient.pitch), rwCOMBINEPOSTCONCAT); + RtQuatRotate(q, &XaxisIK, RADTODEG(m_torsoOrient.yaw), rwCOMBINEPOSTCONCAT); + m_ped->bDontAcceptIKLookAts = true; + return result; } @@ -382,103 +226,86 @@ bool CPedIK::PointGunInDirectionUsingArm(float targetYaw, float targetPitch) { bool result = false; - - RwV3d upVector; // only for non-skinned RwMatrix *matrix; float yaw, pitch; -#ifdef PED_SKIN - if(IsClumpSkinned(m_ped->GetClump())){ - matrix = RwMatrixCreate(); - *matrix = *GetComponentMatrix(m_ped, PED_UPPERARMR); - ExtractYawAndPitchWorld(matrix, &yaw, &pitch); - RwMatrixDestroy(matrix); - }else -#endif - { - RwFrame *frame = m_ped->m_pFrames[PED_UPPERARMR]->frame; - matrix = GetWorldMatrix(RwFrameGetParent(frame), RwMatrixCreate()); - - // with PED_SKIN this is actually done below (with a memory leak) - upVector.x = matrix->right.z; - upVector.y = matrix->up.z; - upVector.z = matrix->at.z; - ExtractYawAndPitchWorld(matrix, &yaw, &pitch); - RwMatrixDestroy(matrix); - } + float uaRoll = 45.0f; + float handRoll = 30.0f; - RwV3d rightVector = { 0.0f, 0.0f, 1.0f }; - RwV3d forwardVector = { 1.0f, 0.0f, 0.0f }; + matrix = GetComponentMatrix(m_ped, PED_CLAVICLER); + yaw = CGeneral::LimitRadianAngle(Atan2(matrix->right.y, matrix->right.x) - m_ped->m_fRotationCur); + pitch = Atan2(matrix->up.z, Sqrt(1.0f - SQR(matrix->up.z))); float uaYaw, uaPitch; -#ifdef PED_SKIN - if(IsClumpSkinned(m_ped->GetClump())){ - uaYaw = targetYaw; - uaPitch = targetPitch + DEGTORAD(10.0f); - }else -#endif - { - uaYaw = targetYaw - m_torsoOrient.yaw - DEGTORAD(15.0f); - uaPitch = CGeneral::LimitRadianAngle(targetPitch - pitch); - } + uaYaw = CGeneral::LimitRadianAngle(targetYaw - yaw - DEGTORAD(15.0f)); + uaPitch = CGeneral::LimitRadianAngle(targetPitch - pitch + DEGTORAD(10.0f)); LimbMoveStatus uaStatus = MoveLimb(m_upperArmOrient, uaYaw, uaPitch, ms_upperArmInfo); if (uaStatus == ANGLES_SET_EXACTLY) { m_flags |= GUN_POINTED_SUCCESSFULLY; result = true; } -#ifdef PED_SKIN - // this code is completely missing on xbox & android, but we can keep it with the check - // TODO? implement it for skinned geometry? - if(!IsClumpSkinned(m_ped->GetClump())) -#endif if (uaStatus == ANGLES_SET_TO_MAX) { float laYaw = uaYaw - m_upperArmOrient.yaw; LimbMoveStatus laStatus; - if (laYaw > 0.0f) - laStatus = MoveLimb(m_lowerArmOrient, laYaw, -DEGTORAD(45.0f), ms_lowerArmInfo); - else + if (laYaw > 0.0f){ + float rollReduce = laYaw/DEGTORAD(30.0f); + uaRoll *= 1.0f - Min(rollReduce, 1.0f); + handRoll *= 1.0f - Min(rollReduce, 1.0f); + + laYaw *= 1.9f; + laStatus = MoveLimb(m_lowerArmOrient, laYaw, 0.0f, ms_lowerArmInfo); + + // some unused statics here + float uaPitchAmount = 1.0f - (m_lowerArmOrient.yaw + m_upperArmOrient.yaw) * 0.34f; + float f1 = ms_upperArmInfo.maxPitch * Max(uaPitchAmount, 0.0f); + float f2 = 0.2f*m_lowerArmOrient.yaw + m_upperArmOrient.pitch; + m_upperArmOrient.pitch = Min(f1, f2); + }else laStatus = MoveLimb(m_lowerArmOrient, laYaw, 0.0f, ms_lowerArmInfo); if (laStatus == ANGLES_SET_EXACTLY) { m_flags |= GUN_POINTED_SUCCESSFULLY; result = true; } - RwFrame *child = GetFirstChild(m_ped->m_pFrames[PED_UPPERARMR]->frame); - RwV3d pos = RwFrameGetMatrix(child)->pos; - RwMatrixRotate(RwFrameGetMatrix(child), &forwardVector, RADTODEG(m_lowerArmOrient.pitch), rwCOMBINEPOSTCONCAT); - RwMatrixRotate(RwFrameGetMatrix(child), &rightVector, RADTODEG(-m_lowerArmOrient.yaw), rwCOMBINEPOSTCONCAT); - RwFrameGetMatrix(child)->pos = pos; - } -#ifdef PED_SKIN - if(IsClumpSkinned(m_ped->GetClump())){ - RtQuat *q = &m_ped->m_pFrames[PED_UPPERARMR]->hanimFrame->q; - RtQuatRotate(q, &XaxisIK, RADTODEG(m_upperArmOrient.yaw), rwCOMBINEPOSTCONCAT); - RtQuatRotate(q, &ZaxisIK, RADTODEG(m_upperArmOrient.pitch), rwCOMBINEPOSTCONCAT); + // game does this stupidly by going through the clump extension... + RtQuat *q = &m_ped->m_pFrames[PED_FOREARMR]->hanimFrame->q; + RtQuatRotate(q, &ZaxisIK, -RADTODEG(m_lowerArmOrient.yaw), rwCOMBINEREPLACE); + RtQuatRotate(q, &XaxisIK, -RADTODEG(m_lowerArmOrient.pitch), rwCOMBINEPOSTCONCAT); m_ped->bDontAcceptIKLookAts = true; - }else -#endif - { - RwFrame *frame = m_ped->m_pFrames[PED_UPPERARMR]->frame; - // with PED_SKIN we're also getting upVector here - RwV3d pos = RwFrameGetMatrix(frame)->pos; - RwMatrixRotate(RwFrameGetMatrix(frame), &rightVector, RADTODEG(m_upperArmOrient.pitch), rwCOMBINEPOSTCONCAT); - RwMatrixRotate(RwFrameGetMatrix(frame), &upVector, RADTODEG(m_upperArmOrient.yaw), rwCOMBINEPOSTCONCAT); - RwFrameGetMatrix(frame)->pos = pos; } + + RtQuat *q = &m_ped->m_pFrames[PED_UPPERARMR]->hanimFrame->q; + RtQuatRotate(q, &XaxisIK, uaRoll, rwCOMBINEREPLACE); + RtQuatRotate(q, &YaxisIK, -RADTODEG(m_upperArmOrient.pitch), rwCOMBINEPOSTCONCAT); + RtQuatRotate(q, &ZaxisIK, -RADTODEG(m_upperArmOrient.yaw+HALFPI), rwCOMBINEPOSTCONCAT); + m_ped->bDontAcceptIKLookAts = true; + + q = &m_ped->m_pFrames[PED_HANDR]->hanimFrame->q; + RtQuatRotate(q, &XaxisIK, handRoll, rwCOMBINEPRECONCAT); + return result; } bool CPedIK::PointGunAtPosition(CVector const& position) { + CVector startPoint; + if (m_ped->GetWeapon()->m_eWeaponType == WEAPONTYPE_SPAS12_SHOTGUN || m_ped->GetWeapon()->m_eWeaponType == WEAPONTYPE_STUBBY_SHOTGUN) + startPoint = m_ped->GetPosition(); + else { + RwV3d armPos; + GetComponentPosition(armPos, PED_UPPERARMR); + startPoint.x = m_ped->GetPosition().x; + startPoint.y = m_ped->GetPosition().y; + startPoint.z = armPos.z; + } + return PointGunInDirection( - CGeneral::GetRadianAngleBetweenPoints(position.x, position.y, m_ped->GetPosition().x, m_ped->GetPosition().y), - CGeneral::GetRadianAngleBetweenPoints(position.z, Distance2D(m_ped->GetPosition(), position.x, position.y), - m_ped->GetPosition().z, - 0.0f)); + CGeneral::GetRadianAngleBetweenPoints(position.x, position.y, startPoint.x, startPoint.y), + CGeneral::GetRadianAngleBetweenPoints(position.z, Distance2D(m_ped->GetPosition(), position.x, position.y), startPoint.z, 0.0f)); } bool @@ -487,40 +314,24 @@ CPedIK::RestoreLookAt(void) bool result = false; float yaw, pitch; -#ifdef PED_SKIN - if(IsClumpSkinned(m_ped->GetClump())){ - if (m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION) { - m_ped->m_pFrames[PED_HEAD]->flag &= (~AnimBlendFrameData::IGNORE_ROTATION); - } else { - ExtractYawAndPitchLocalSkinned(m_ped->m_pFrames[PED_HEAD], &yaw, &pitch); - if (MoveLimb(m_headOrient, yaw, pitch, ms_headRestoreInfo) == ANGLES_SET_EXACTLY) - result = true; - } - RotateHead(); - }else -#endif - { - RwMatrix *mat = RwFrameGetMatrix(m_ped->m_pFrames[PED_HEAD]->frame); - if (m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION) { - m_ped->m_pFrames[PED_HEAD]->flag &= (~AnimBlendFrameData::IGNORE_ROTATION); - } else { - ExtractYawAndPitchLocal(mat, &yaw, &pitch); - if (MoveLimb(m_headOrient, yaw, pitch, ms_headRestoreInfo) == ANGLES_SET_EXACTLY) - result = true; - } - - CMatrix matrix(mat); - CVector pos = matrix.GetPosition(); - matrix.SetRotateZ(m_headOrient.pitch); - matrix.RotateX(m_headOrient.yaw); - matrix.Translate(pos); - matrix.UpdateRW(); + if (m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION) { + m_ped->m_pFrames[PED_HEAD]->flag &= (~AnimBlendFrameData::IGNORE_ROTATION); + } else { + ExtractYawAndPitchLocalSkinned(m_ped->m_pFrames[PED_HEAD], &yaw, &pitch); + if (MoveLimb(m_headOrient, yaw, pitch, ms_headRestoreInfo) == ANGLES_SET_EXACTLY) + result = true; } - if (!(m_flags & LOOKAROUND_HEAD_ONLY)){ + + // This was RotateHead + RtQuat *q = &m_ped->m_pFrames[PED_HEAD]->hanimFrame->q; + RtQuatRotate(q, &XaxisIK, RADTODEG(m_headOrient.yaw), rwCOMBINEREPLACE); + RtQuatRotate(q, &ZaxisIK, RADTODEG(m_headOrient.pitch), rwCOMBINEPRECONCAT); + m_ped->bDontAcceptIKLookAts = true; + + if (!(m_flags & LOOKAROUND_HEAD_ONLY)) MoveLimb(m_torsoOrient, 0.0f, 0.0f, ms_torsoInfo); - if (!(m_flags & LOOKAROUND_HEAD_ONLY)) - RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false); - } + if (!(m_flags & LOOKAROUND_HEAD_ONLY)) + RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false); return result; } @@ -548,7 +359,6 @@ CPedIK::ExtractYawAndPitchLocal(RwMatrix *mat, float *yaw, float *pitch) if (mat->up.x > 0.0f) *pitch = -*pitch; } -#ifdef PED_SKIN void CPedIK::ExtractYawAndPitchLocalSkinned(AnimBlendFrameData *node, float *yaw, float *pitch) { @@ -557,4 +367,3 @@ CPedIK::ExtractYawAndPitchLocalSkinned(AnimBlendFrameData *node, float *yaw, flo ExtractYawAndPitchLocal(mat, yaw, pitch); RwMatrixDestroy(mat); } -#endif diff --git a/src/peds/PedIK.h b/src/peds/PedIK.h index e91d7c06..7dcf0ef3 100644 --- a/src/peds/PedIK.h +++ b/src/peds/PedIK.h @@ -51,15 +51,14 @@ public: bool PointGunInDirection(float targetYaw, float targetPitch); bool PointGunInDirectionUsingArm(float targetYaw, float targetPitch); bool PointGunAtPosition(CVector const& position); - void GetComponentPosition(RwV3d *pos, uint32 node); - static RwMatrix *GetWorldMatrix(RwFrame *source, RwMatrix *destination); + void GetComponentPosition(RwV3d &pos, uint32 node); + void GetComponentPosition(CVector &pos, uint32 node) { GetComponentPosition(*(RwV3d*)pos, node); } void RotateTorso(AnimBlendFrameData* animBlend, LimbOrientation* limb, bool changeRoll); void ExtractYawAndPitchLocal(RwMatrix *mat, float *yaw, float *pitch); void ExtractYawAndPitchLocalSkinned(AnimBlendFrameData *node, float *yaw, float *pitch); void ExtractYawAndPitchWorld(RwMatrix *mat, float *yaw, float *pitch); LimbMoveStatus MoveLimb(LimbOrientation &limb, float targetYaw, float targetPitch, LimbMovementInfo &moveInfo); bool RestoreGunPosn(void); - void RotateHead(void); bool LookInDirection(float targetYaw, float targetPitch); bool LookAtPosition(CVector const& pos); bool RestoreLookAt(void); diff --git a/src/peds/PedPlacement.cpp b/src/peds/PedPlacement.cpp index 2d4a92fa..8012650a 100644 --- a/src/peds/PedPlacement.cpp +++ b/src/peds/PedPlacement.cpp @@ -4,7 +4,8 @@ #include "PedPlacement.h" #include "World.h" -void +// --MIAMI: Done +bool CPedPlacement::FindZCoorForPed(CVector* pos) { float zForPed; @@ -32,8 +33,11 @@ CPedPlacement::FindZCoorForPed(CVector* pos) zForPed = Max(foundColZ, foundColZ2); - if (zForPed > -99.0f) + if (zForPed > -99.0f) { pos->z = FEET_OFFSET + zForPed; + return true; + } + return false; } CEntity* @@ -43,9 +47,13 @@ CPedPlacement::IsPositionClearOfCars(Const CVector *pos) } bool -CPedPlacement::IsPositionClearForPed(CVector* pos) +CPedPlacement::IsPositionClearForPed(const CVector& pos, float radius, int total, CEntity** entities) { int16 count; - CWorld::FindObjectsKindaColliding(*pos, 0.75f, true, &count, 2, nil, false, true, true, false, false); + if (radius == -1.0f) + radius = 0.75f; + if (total == -1) + total = 2; + CWorld::FindObjectsKindaColliding(pos, radius, true, &count, total, entities, false, true, true, false, false); return count == 0; } diff --git a/src/peds/PedPlacement.h b/src/peds/PedPlacement.h index b51e2aad..d1b0cd16 100644 --- a/src/peds/PedPlacement.h +++ b/src/peds/PedPlacement.h @@ -2,7 +2,7 @@ class CPedPlacement { public: - static void FindZCoorForPed(CVector* pos); + static bool FindZCoorForPed(CVector* pos); static CEntity* IsPositionClearOfCars(Const CVector*); - static bool IsPositionClearForPed(CVector*); + static bool IsPositionClearForPed(const CVector& pos, float radius = -1.0f, int total = -1, CEntity** entities = nil); };
\ No newline at end of file diff --git a/src/peds/PedStats.h b/src/peds/PedStats.h index df97bdb8..7fc8cdbf 100644 --- a/src/peds/PedStats.h +++ b/src/peds/PedStats.h @@ -37,6 +37,11 @@ enum ePedStats PEDSTAT_SPORTSFAN, PEDSTAT_SHOPPER, PEDSTAT_OLDSHOPPER, + PEDSTAT_BEACH_GUY, + PEDSTAT_BEACH_GIRL, + PEDSTAT_SKATER, + PEDSTAT_STD_MISSION, + PEDSTAT_COWARD, NUM_PEDSTATS }; diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index fa865aec..cba01e31 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -16,6 +16,8 @@ #include "Pools.h" #include "Darkel.h" #include "CarCtrl.h" +#include "MBlur.h" +#include "Streaming.h" #define PAD_MOVE_TO_GAME_WORLD_MOVE 60.0f @@ -26,11 +28,14 @@ const uint32 CPlayerPed::nSaveStructSize = sizeof(CPlayerPed); #endif +int32 idleAnimBlockIndex; + CPlayerPed::~CPlayerPed() { delete m_pWanted; } +// --MIAMI: Done CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1) { m_fMoveSpeed = 0.0f; @@ -44,35 +49,52 @@ CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1) m_pWanted->Initialise(); m_pArrestingCop = nil; m_currentWeapon = WEAPONTYPE_UNARMED; - m_nSelectedWepSlot = WEAPONTYPE_UNARMED; + m_nSelectedWepSlot = 0; m_nSpeedTimer = 0; m_bSpeedTimerFlag = false; + + if (m_pPointGunAt) + m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt); m_pPointGunAt = nil; - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); #ifndef FIX_BUGS m_fCurrentStamina = m_fMaxStamina = 150.0f; #endif m_fStaminaProgress = 0.0f; m_nEvadeAmount = 0; - field_1367 = 0; + m_pEvadingFrom = nil; m_nHitAnimDelayTimer = 0; m_fAttackButtonCounter = 0.0f; m_bHaveTargetSelected = false; m_bHasLockOnTarget = false; m_bCanBeDamaged = true; + m_bDrunkVisualsWearOff = false; m_fWalkAngle = 0.0f; m_fFPSMoveHeading = 0.0f; + m_pMinigunTopAtomic = nil; + m_fGunSpinSpeed = 0.0; + m_fGunSpinAngle = 0.0; + m_nPadDownPressedInMilliseconds = 0; m_nTargettableObjects[0] = m_nTargettableObjects[1] = m_nTargettableObjects[2] = m_nTargettableObjects[3] = -1; - field_1413 = 0; + unused1 = false; for (int i = 0; i < 6; i++) { m_vecSafePos[i] = CVector(0.0f, 0.0f, 0.0f); m_pPedAtSafePos[i] = nil; + m_pMeleeList[i] = nil; } + m_nCheckPlayersIndex = 0; + m_nPadUpPressedInMilliseconds = 0; + idleAnimBlockIndex = CAnimManager::GetAnimationBlockIndex("playidles"); } -void CPlayerPed::ClearWeaponTarget() +// --MIAMI: Done +void +CPlayerPed::ClearWeaponTarget() { if (m_nPedType == PEDTYPE_PLAYER1) { + if (m_pPointGunAt) + m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt); + m_pPointGunAt = nil; TheCamera.ClearPlayerWeaponMode(); CWeaponEffects::ClearCrossHair(); @@ -96,11 +118,7 @@ void CPlayerPed::MakeObjectTargettable(int32 handle) { for (int i = 0; i < ARRAY_SIZE(m_nTargettableObjects); i++) { - if ( -#ifdef FIX_BUGS - m_nTargettableObjects[i] == -1 || -#endif - CPools::GetObjectPool()->GetAt(m_nTargettableObjects[i]) == nil) { + if (CPools::GetObjectPool()->GetAt(m_nTargettableObjects[i]) == nil) { m_nTargettableObjects[i] = handle; return; } @@ -185,21 +203,24 @@ CPlayerPed::UseSprintEnergy(void) } } +// --MIAMI: Use that on everywhere except ProcessPlayerWeapon void -CPlayerPed::MakeChangesForNewWeapon(int8 weapon) +CPlayerPed::MakeChangesForNewWeapon(eWeaponType weapon) { if (m_nPedState == PED_SNIPER_MODE) { RestorePreviousState(); TheCamera.ClearPlayerWeaponMode(); } SetCurrentWeapon(weapon); + m_nSelectedWepSlot = m_currentWeapon; GetWeapon()->m_nAmmoInClip = Min(GetWeapon()->m_nAmmoTotal, CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nAmountofAmmunition); if (!(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAim)) ClearWeaponTarget(); - CAnimBlendAssociation *weaponAnim = RpAnimBlendClumpGetAssociation(GetClump(), CWeaponInfo::GetWeaponInfo(WEAPONTYPE_SNIPERRIFLE)->m_AnimToPlay); + // WEAPONTYPE_SNIPERRIFLE? Wut? + CAnimBlendAssociation* weaponAnim = RpAnimBlendClumpGetAssociation(GetClump(), GetPrimaryFireAnim(CWeaponInfo::GetWeaponInfo(WEAPONTYPE_SNIPERRIFLE))); if (weaponAnim) { weaponAnim->SetRun(); weaponAnim->flags |= ASSOC_FADEOUTWHENDONE; @@ -207,6 +228,14 @@ CPlayerPed::MakeChangesForNewWeapon(int8 weapon) TheCamera.ClearPlayerWeaponMode(); } +// --MIAMI: Done, but this should be only called from ProcessPlayerWeapon +void +CPlayerPed::MakeChangesForNewWeapon(int32 slot) +{ + if(slot != -1) + MakeChangesForNewWeapon(m_weapons[slot].m_eWeaponType); +} + void CPlayerPed::ReApplyMoveAnims(void) { @@ -226,14 +255,19 @@ CPlayerPed::ReApplyMoveAnims(void) } } +// --MIAMI: Done void CPlayerPed::SetInitialState(void) { + m_nDrunkenness = 0; + m_nFadeDrunkenness = 0; + CMBlur::ClearDrunkBlur(); + m_nDrunkCountdown = 0; m_bAdrenalineActive = false; m_nAdrenalineTime = 0; CTimer::SetTimeScale(1.0f); m_pSeekTarget = nil; - m_vecSeekPos = { 0.0f, 0.0f, 0.0f }; + m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); m_fleeFromPosX = 0.0f; m_fleeFromPosY = 0.0f; m_fleeFrom = nil; @@ -245,10 +279,12 @@ CPlayerPed::SetInitialState(void) ClearLookFlag(); bIsPointingGunAt = false; bRenderPedInCar = true; + if (m_pFire) m_pFire->Extinguish(); + RpAnimBlendClumpRemoveAllAssociations(GetClump()); - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); SetMoveState(PEDMOVE_STILL); m_nLastPedState = PED_NONE; m_animGroup = ASSOCGRP_PLAYER; @@ -261,6 +297,11 @@ CPlayerPed::SetInitialState(void) m_bCanBeDamaged = true; m_pedStats->m_temper = 50; m_fWalkAngle = 0.0f; + if (m_attachedTo && !bUsesCollision) + bUsesCollision = true; + + m_attachedTo = nil; + m_attachWepAmmo = 0; } void @@ -287,6 +328,8 @@ CPlayerPed::SetRealMoveAnim(void) curIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_TIRED); if (!curIdleAssoc) curIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE); + if (!curIdleAssoc) + curIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCHRELOAD); if ((!curRunStopAssoc || !(curRunStopAssoc->IsRunning())) && (!curRunStopRAssoc || !(curRunStopRAssoc->IsRunning()))) { @@ -303,7 +346,7 @@ CPlayerPed::SetRealMoveAnim(void) RestoreHeadingRate(); if (!curIdleAssoc) { - if (m_fCurrentStamina < 0.0f && !CWorld::TestSphereAgainstWorld(GetPosition(), 0.0f, + if (m_fCurrentStamina < 0.0f && !bIsAimingGun && !CWorld::TestSphereAgainstWorld(GetPosition(), 0.0f, nil, true, false, false, false, false, false)) { curIdleAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 8.0f); @@ -317,7 +360,7 @@ CPlayerPed::SetRealMoveAnim(void) } else if (m_fMoveSpeed == 0.0f && !curSprintAssoc) { if (!curIdleAssoc) { - if (m_fCurrentStamina < 0.0f && !CWorld::TestSphereAgainstWorld(GetPosition(), 0.0f, + if (m_fCurrentStamina < 0.0f && !bIsAimingGun && !CWorld::TestSphereAgainstWorld(GetPosition(), 0.0f, nil, true, false, false, false, false, false)) { curIdleAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f); @@ -328,11 +371,11 @@ CPlayerPed::SetRealMoveAnim(void) m_nWaitTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(2500, 4000); } - if (m_fCurrentStamina > 0.0f && curIdleAssoc->animId == ANIM_IDLE_TIRED) { + if ((m_fCurrentStamina > 0.0f || bIsAimingGun) && curIdleAssoc->animId == ANIM_IDLE_TIRED) { CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 4.0f); } else if (m_nPedState != PED_FIGHT) { - if (m_fCurrentStamina < 0.0f && curIdleAssoc->animId != ANIM_IDLE_TIRED + if (m_fCurrentStamina < 0.0f && !bIsAimingGun && curIdleAssoc->animId != ANIM_IDLE_TIRED && !CWorld::TestSphereAgainstWorld(GetPosition(), 0.0f, nil, true, false, false, false, false, false)) { CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f); @@ -357,7 +400,10 @@ CPlayerPed::SetRealMoveAnim(void) delete curIdleAssoc; delete RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_TIRED); - delete RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE); + CAnimBlendAssociation *fightIdleAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE); + if (!fightIdleAnim) + fightIdleAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCHRELOAD); + delete fightIdleAnim; delete curSprintAssoc; curSprintAssoc = nil; @@ -401,7 +447,7 @@ CPlayerPed::SetRealMoveAnim(void) } else if (curSprintAssoc->blendDelta >= 0.0f || curSprintAssoc->blendAmount >= 0.8f) { if (m_fMoveSpeed < 0.4f) { AnimationId runStopAnim; - if (curSprintAssoc->currentTime / curSprintAssoc->hierarchy->totalLength < 0.5) // double + if (curSprintAssoc->GetProgress() < 0.5) // double runStopAnim = ANIM_RUN_STOP; else runStopAnim = ANIM_RUN_STOP_R; @@ -496,13 +542,16 @@ CPlayerPed::RestoreSprintEnergy(float restoreSpeed) m_fCurrentStamina += restoreSpeed * CTimer::GetTimeStep() * 0.5f; } + +// TODO(Miami) bool CPlayerPed::DoWeaponSmoothSpray(void) { if (m_nPedState == PED_ATTACK && !m_pPointGunAt) { eWeaponType weapon = GetWeapon()->m_eWeaponType; - if (weapon == WEAPONTYPE_FLAMETHROWER || weapon == WEAPONTYPE_COLT45 || weapon == WEAPONTYPE_UZI || weapon == WEAPONTYPE_SHOTGUN || - weapon == WEAPONTYPE_AK47 || weapon == WEAPONTYPE_M16 || weapon == WEAPONTYPE_HELICANNON) + if (weapon == WEAPONTYPE_FLAMETHROWER || weapon == WEAPONTYPE_COLT45 || weapon == WEAPONTYPE_UZI || + weapon == WEAPONTYPE_TEC9 || weapon == WEAPONTYPE_SILENCED_INGRAM || weapon == WEAPONTYPE_MP5 || + weapon == WEAPONTYPE_SHOTGUN || weapon == WEAPONTYPE_RUGER || weapon == WEAPONTYPE_M4 || weapon == WEAPONTYPE_HELICANNON) return true; } return false; @@ -523,14 +572,15 @@ CPlayerPed::DoesTargetHaveToBeBroken(CVector target, CWeapon *weaponUsed) if (distVec.Magnitude() > CWeaponInfo::GetWeaponInfo(weaponUsed->m_eWeaponType)->m_fRange) return true; - if (weaponUsed->m_eWeaponType != WEAPONTYPE_SHOTGUN && weaponUsed->m_eWeaponType != WEAPONTYPE_AK47) +/* + if (weaponUsed->m_eWeaponType != WEAPONTYPE_SHOTGUN && weaponUsed->m_eWeaponType != WEAPONTYPE_RUGER) return false; distVec.Normalise(); if (DotProduct(distVec,GetForward()) < 0.4f) return true; - +*/ return false; } @@ -571,105 +621,168 @@ CPlayerPed::IsThisPedAttackingPlayer(CPed *suspect) return false; } +// --MIAMI: Done void CPlayerPed::PlayerControlSniper(CPad *padUsed) { ProcessWeaponSwitch(padUsed); TheCamera.PlayerExhaustion = (1.0f - (m_fCurrentStamina - -150.0f) / 300.0f) * 0.9f + 0.1f; - if (!padUsed->GetTarget()) { + if (padUsed->DuckJustDown() && !bIsDucking && m_nMoveState != PEDMOVE_SPRINT) { + bCrouchWhenShooting = true; + SetDuck(60000, true); + } else if (bIsDucking && (padUsed->DuckJustDown() || m_nMoveState == PEDMOVE_SPRINT)) { + ClearDuck(true); + bCrouchWhenShooting = false; + } + + if (!padUsed->GetTarget() && !m_attachedTo) { RestorePreviousState(); TheCamera.ClearPlayerWeaponMode(); } - if (padUsed->WeaponJustDown()) { + int firingRate = GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE ? 333 : 266; + if (padUsed->WeaponJustDown() && CTimer::GetTimeInMilliseconds() > GetWeapon()->m_nTimer) { CVector firePos(0.0f, 0.0f, 0.6f); firePos = GetMatrix() * firePos; GetWeapon()->Fire(this, &firePos); + m_nPadDownPressedInMilliseconds = CTimer::GetTimeInMilliseconds(); + } else if (CTimer::GetTimeInMilliseconds() > m_nPadDownPressedInMilliseconds + firingRate && + CTimer::GetTimeInMilliseconds() - CTimer::GetTimeStepInMilliseconds() < m_nPadDownPressedInMilliseconds + firingRate && padUsed->GetWeapon()) { + + if (GetWeapon()->m_nAmmoTotal > 0) { + DMAudio.PlayFrontEndSound(SOUND_WEAPON_AK47_BULLET_ECHO, GetWeapon()->m_eWeaponType); + } } - GetWeapon()->Update(m_audioEntityId); + GetWeapon()->Update(m_audioEntityId, nil); } +// --MIAMI: Done except commented thing // I think R* also used goto in here. void CPlayerPed::ProcessWeaponSwitch(CPad *padUsed) { - if (CDarkel::FrenzyOnGoing()) + if (CDarkel::FrenzyOnGoing() || m_attachedTo) goto switchDetectDone; - if (padUsed->CycleWeaponRightJustDown() && !m_pPointGunAt) { - - if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON_RUNABOUT - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER_RUNABOUT - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER_RUNABOUT) { + // TODO(Miami): byte_A10B57 + if (!m_pPointGunAt && /* !byte_A10B57 && */ GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR) { + if (padUsed->CycleWeaponRightJustDown()) { - for (m_nSelectedWepSlot = m_currentWeapon + 1; m_nSelectedWepSlot < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; ++m_nSelectedWepSlot) { - if (HasWeapon(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) { - goto switchDetectDone; + if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON_RUNABOUT + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER_RUNABOUT + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER_RUNABOUT + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_CAMERA) { + + for (m_nSelectedWepSlot = m_currentWeapon + 1; m_nSelectedWepSlot < TOTAL_WEAPON_SLOTS; ++m_nSelectedWepSlot) { + if (HasWeaponSlot(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) { + goto spentAmmoCheck; + } } + m_nSelectedWepSlot = 0; } - m_nSelectedWepSlot = WEAPONTYPE_UNARMED; - } - } else if (padUsed->CycleWeaponLeftJustDown() && !m_pPointGunAt) { - if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER) { + } else if (padUsed->CycleWeaponLeftJustDown()) { + if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER + && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_CAMERA) { - for (m_nSelectedWepSlot = m_currentWeapon - 1; ; --m_nSelectedWepSlot) { - if (m_nSelectedWepSlot < WEAPONTYPE_UNARMED) - m_nSelectedWepSlot = WEAPONTYPE_DETONATOR; + for (m_nSelectedWepSlot = m_currentWeapon - 1; ; --m_nSelectedWepSlot) { + if (m_nSelectedWepSlot < 0) + m_nSelectedWepSlot = TOTAL_WEAPON_SLOTS - 1; - if (HasWeapon(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) { - goto switchDetectDone; + if (m_nSelectedWepSlot == 0) + break; + + if (HasWeaponSlot(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) { + break; + } } } } - } else if (CWeaponInfo::GetWeaponInfo((eWeaponType)m_currentWeapon)->m_eWeaponFire != WEAPON_FIRE_MELEE) { - if (GetWeapon(m_currentWeapon).m_nAmmoTotal <= 0) { - if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER - && TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER) { + } + +spentAmmoCheck: + if (CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_eWeaponFire != WEAPON_FIRE_MELEE + && (!padUsed->GetWeapon() || GetWeapon()->m_eWeaponType != WEAPONTYPE_MINIGUN)) { + if (GetWeapon()->m_nAmmoTotal <= 0) { + if (TheCamera.PlayerWeaponMode.Mode == CCam::MODE_M16_1STPERSON + || TheCamera.PlayerWeaponMode.Mode == CCam::MODE_SNIPER + || TheCamera.PlayerWeaponMode.Mode == CCam::MODE_ROCKETLAUNCHER) + return; - for (m_nSelectedWepSlot = m_currentWeapon - 1; m_nSelectedWepSlot >= 0; --m_nSelectedWepSlot) { - if (m_nSelectedWepSlot == WEAPONTYPE_BASEBALLBAT && HasWeapon(WEAPONTYPE_BASEBALLBAT) - || GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0 && m_nSelectedWepSlot != WEAPONTYPE_MOLOTOV && m_nSelectedWepSlot != WEAPONTYPE_GRENADE) { - goto switchDetectDone; - } + if (GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR + || GetWeapon(2).m_eWeaponType != WEAPONTYPE_DETONATOR_GRENADE) + m_nSelectedWepSlot = m_currentWeapon - 1; + else + m_nSelectedWepSlot = 2; + + for (; m_nSelectedWepSlot >= 0; --m_nSelectedWepSlot) { + + // BUG: m_nSelectedWepSlot and GetWeapon(..) takes slot in VC but they compared them against weapon types in whole condition! jeez +#ifdef FIX_BUGS + if (m_nSelectedWepSlot == 1 || GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0 && m_nSelectedWepSlot != 2) { +#else + if (m_nSelectedWepSlot == WEAPONTYPE_BASEBALLBAT && GetWeapon(WEAPONTYPE_BASEBALLBAT).m_eWeaponType == WEAPONTYPE_BASEBALLBAT + || GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0 + && m_nSelectedWepSlot != WEAPONTYPE_MOLOTOV && m_nSelectedWepSlot != WEAPONTYPE_GRENADE && m_nSelectedWepSlot != WEAPONTYPE_TEARGAS) { +#endif + goto switchDetectDone; } - m_nSelectedWepSlot = WEAPONTYPE_UNARMED; } + m_nSelectedWepSlot = 0; } } switchDetectDone: if (m_nSelectedWepSlot != m_currentWeapon) { if (m_nPedState != PED_ATTACK && m_nPedState != PED_AIM_GUN && m_nPedState != PED_FIGHT) + RemoveWeaponAnims(m_currentWeapon, -1000.0f); MakeChangesForNewWeapon(m_nSelectedWepSlot); } } +// --MIAMI: Done void CPlayerPed::PlayerControlM16(CPad *padUsed) { ProcessWeaponSwitch(padUsed); TheCamera.PlayerExhaustion = (1.0f - (m_fCurrentStamina - -150.0f) / 300.0f) * 0.9f + 0.1f; + if (padUsed->DuckJustDown() && !bIsDucking && m_nMoveState != PEDMOVE_SPRINT) { + bCrouchWhenShooting = true; + SetDuck(60000, true); + } else if (bIsDucking && (padUsed->DuckJustDown() || m_nMoveState == PEDMOVE_SPRINT)) { + ClearDuck(true); + bCrouchWhenShooting = false; + } + if (!padUsed->GetTarget()) { RestorePreviousState(); TheCamera.ClearPlayerWeaponMode(); } - if (padUsed->GetWeapon()) { - CVector firePos(0.0f, 0.0f, 0.6f); - firePos = GetMatrix() * firePos; - GetWeapon()->Fire(this, &firePos); + if (padUsed->GetWeapon() && CTimer::GetTimeInMilliseconds() > GetWeapon()->m_nTimer) { + if (GetWeapon()->m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO) { + DMAudio.PlayFrontEndSound(SOUND_WEAPON_SNIPER_SHOT_NO_ZOOM, 0.f); + GetWeapon()->m_nTimer = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nFiringRate + CTimer::GetTimeInMilliseconds(); + } else { + CVector firePos(0.0f, 0.0f, 0.6f); + firePos = GetMatrix() * firePos; + GetWeapon()->Fire(this, &firePos); + m_nPadDownPressedInMilliseconds = CTimer::GetTimeInMilliseconds(); + } + } else if (CTimer::GetTimeInMilliseconds() > GetWeapon()->m_nTimer && + CTimer::GetTimeInMilliseconds() - CTimer::GetTimeStepInMilliseconds() < GetWeapon()->m_nTimer && GetWeapon()->m_eWeaponState != WEAPONSTATE_OUT_OF_AMMO) { + DMAudio.PlayFrontEndSound(SOUND_WEAPON_AK47_BULLET_ECHO, GetWeapon()->m_eWeaponType); } - GetWeapon()->Update(m_audioEntityId); + GetWeapon()->Update(m_audioEntityId, nil); } +// --MIAMI: Done void CPlayerPed::PlayerControlFighter(CPad *padUsed) { @@ -695,6 +808,7 @@ CPlayerPed::PlayerControlFighter(CPad *padUsed) } } +// --MIAMI: Done void CPlayerPed::PlayerControl1stPersonRunAround(CPad *padUsed) { @@ -730,6 +844,12 @@ CPlayerPed::PlayerControl1stPersonRunAround(CPad *padUsed) m_fMoveSpeed = 0.0f; } } + + if (m_nPedState == PED_ANSWER_MOBILE) { + SetRealMoveAnim(); + return; + } + if (!(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bHeavy) && padUsed->GetSprint()) { m_nMoveState = PEDMOVE_SPRINT; @@ -938,6 +1058,7 @@ CPlayerPed::FindWeaponLockOnTarget(void) return true; } +// --MIAMI: Done void CPlayerPed::ProcessAnimGroups(void) { @@ -950,17 +1071,29 @@ CPlayerPed::ProcessAnimGroups(void) if (m_fWalkAngle > 0.0f) { if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) groupToSet = ASSOCGRP_ROCKETLEFT; + else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW || + GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER || + GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN) + groupToSet = ASSOCGRP_CHAINSAWLEFT; else groupToSet = ASSOCGRP_PLAYERLEFT; } else { if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) groupToSet = ASSOCGRP_ROCKETRIGHT; + else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW || + GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER || + GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN) + groupToSet = ASSOCGRP_CHAINSAWRIGHT; else groupToSet = ASSOCGRP_PLAYERRIGHT; } } else { if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) groupToSet = ASSOCGRP_ROCKETBACK; + else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW || + GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER || + GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN) + groupToSet = ASSOCGRP_CHAINSAWBACK; else groupToSet = ASSOCGRP_PLAYERBACK; } @@ -968,9 +1101,19 @@ CPlayerPed::ProcessAnimGroups(void) if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) { groupToSet = ASSOCGRP_PLAYERROCKET; } else { - if (GetWeapon()->m_eWeaponType == WEAPONTYPE_BASEBALLBAT) { + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_BASEBALLBAT + || GetWeapon()->m_eWeaponType == WEAPONTYPE_MACHETE) groupToSet = ASSOCGRP_PLAYERBBBAT; - } else if (GetWeapon()->m_eWeaponType != WEAPONTYPE_COLT45 && GetWeapon()->m_eWeaponType != WEAPONTYPE_UZI) { + else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW || + GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER || + GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN) + groupToSet = ASSOCGRP_PLAYERCHAINSAW; + else if (GetWeapon()->m_eWeaponType != WEAPONTYPE_COLT45 && GetWeapon()->m_eWeaponType != WEAPONTYPE_UZI + // I hope this is a inlined function... + && GetWeapon()->m_eWeaponType != WEAPONTYPE_PYTHON && GetWeapon()->m_eWeaponType != WEAPONTYPE_TEC9 + && GetWeapon()->m_eWeaponType != WEAPONTYPE_SILENCED_INGRAM && GetWeapon()->m_eWeaponType != WEAPONTYPE_MP5 + && GetWeapon()->m_eWeaponType != WEAPONTYPE_GOLFCLUB && GetWeapon()->m_eWeaponType != WEAPONTYPE_KATANA + && GetWeapon()->m_eWeaponType != WEAPONTYPE_CAMERA) { if (!GetWeapon()->IsType2Handed()) { groupToSet = ASSOCGRP_PLAYER; } else { @@ -988,6 +1131,7 @@ CPlayerPed::ProcessAnimGroups(void) } } +// TODO(Miami) void CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) { @@ -997,44 +1141,71 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) CWeaponEffects::ClearCrossHair(); ClearPointGunAt(); } + + if (padUsed->DuckJustDown() && !bIsDucking && m_nMoveState != PEDMOVE_SPRINT) { + bCrouchWhenShooting = true; + SetDuck(60000, true); + } else if (bIsDucking && (padUsed->DuckJustDown() || m_nMoveState == PEDMOVE_SPRINT || + padUsed->GetSprint() || padUsed->JumpJustDown() || padUsed->ExitVehicleJustDown())) { + + ClearDuck(true); + bCrouchWhenShooting = false; + } + + if(weaponInfo->m_bCanAim) + m_wepAccuracy = 95; + else + m_wepAccuracy = 100; + if (!m_pFire) { - if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER || - GetWeapon()->m_eWeaponType == WEAPONTYPE_SNIPERRIFLE || GetWeapon()->m_eWeaponType == WEAPONTYPE_M16) { - if (padUsed->TargetJustDown()) { - SetStoredState(); - m_nPedState = PED_SNIPER_MODE; + eWeaponType weapon = GetWeapon()->m_eWeaponType; + if (weapon == WEAPONTYPE_ROCKETLAUNCHER || weapon == WEAPONTYPE_SNIPERRIFLE || + weapon == WEAPONTYPE_LASERSCOPE || weapon == WEAPONTYPE_M4 || + weapon == WEAPONTYPE_RUGER || weapon == WEAPONTYPE_M60 || + weapon == WEAPONTYPE_CAMERA) { + + if (padUsed->TargetJustDown() || TheCamera.m_bJustJumpedOutOf1stPersonBecauseOfTarget) { #ifdef FREE_CAM if (CCamera::bFreeCam && TheCamera.Cams[0].Using3rdPersonMouseCam()) { m_fRotationCur = CGeneral::LimitRadianAngle(-TheCamera.Orientation); SetHeading(m_fRotationCur); } #endif - if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) + if (weapon == WEAPONTYPE_ROCKETLAUNCHER) TheCamera.SetNewPlayerWeaponMode(CCam::MODE_ROCKETLAUNCHER, 0, 0); - else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_SNIPERRIFLE) + else if (weapon == WEAPONTYPE_SNIPERRIFLE || weapon == WEAPONTYPE_LASERSCOPE) TheCamera.SetNewPlayerWeaponMode(CCam::MODE_SNIPER, 0, 0); + else if (weapon == WEAPONTYPE_CAMERA) + TheCamera.SetNewPlayerWeaponMode(CCam::MODE_CAMERA, 0, 0); else TheCamera.SetNewPlayerWeaponMode(CCam::MODE_M16_1STPERSON, 0, 0); m_fMoveSpeed = 0.0f; CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_STANCE, 1000.0f); - } - if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER || GetWeapon()->m_eWeaponType == WEAPONTYPE_SNIPERRIFLE - || TheCamera.PlayerWeaponMode.Mode == CCam::MODE_M16_1STPERSON) + SetPedState(PED_SNIPER_MODE); return; + } + if (!TheCamera.Using1stPersonWeaponMode()) + if (weapon == WEAPONTYPE_ROCKETLAUNCHER || weapon == WEAPONTYPE_SNIPERRIFLE || weapon == WEAPONTYPE_LASERSCOPE || weapon == WEAPONTYPE_CAMERA) + return; } } if (padUsed->GetWeapon() && m_nMoveState != PEDMOVE_SPRINT) { if (m_nSelectedWepSlot == m_currentWeapon) { if (m_pPointGunAt) { + if (m_nPedState == PED_ATTACK) { + m_fAttackButtonCounter *= Pow(0.94f, CTimer::GetTimeStep()); + } else { + m_fAttackButtonCounter = 0.0f; + } #ifdef FREE_CAM if (CCamera::bFreeCam && weaponInfo->m_eWeaponFire == WEAPON_FIRE_MELEE && m_fMoveSpeed < 1.0f) StartFightAttack(padUsed->GetWeapon()); else #endif SetAttack(m_pPointGunAt); - } else if (m_currentWeapon != WEAPONTYPE_UNARMED) { + } else { if (m_nPedState == PED_ATTACK) { if (padUsed->WeaponJustDown()) { m_bHaveTargetSelected = true; @@ -1045,12 +1216,19 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) m_fAttackButtonCounter = 0.0f; m_bHaveTargetSelected = false; } - SetAttack(nil); - } else if (padUsed->WeaponJustDown()) { - if (m_fMoveSpeed < 1.0f) - StartFightAttack(padUsed->GetWeapon()); - else - SetAttack(nil); + if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && GetWeapon()->m_eWeaponType != WEAPONTYPE_BRASSKNUCKLE && + !weaponInfo->m_bFightMode) { + + if (GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR && GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR_GRENADE || + padUsed->WeaponJustDown()) + + SetAttack(nil); + } else if (padUsed->WeaponJustDown()) { + if (m_fMoveSpeed < 1.0f || m_nPedState == PED_FIGHT) + StartFightAttack(padUsed->GetWeapon()); + else + SetAttack(nil); + } } } } else { @@ -1070,7 +1248,7 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) m_nSelectedWepSlot == m_currentWeapon && m_nMoveState != PEDMOVE_SPRINT) { // Weapons except throwable and melee ones - if (weaponInfo->m_bCanAim || weaponInfo->m_b1stPerson || weaponInfo->m_bExpands) { + if (weaponInfo->m_nWeaponSlot > 2) { if ((padUsed->GetTarget() && weaponInfo->m_bCanAimWithArm) || padUsed->GetWeapon()) { float limitedCam = CGeneral::LimitRadianAngle(-TheCamera.Orientation); @@ -1089,7 +1267,7 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) } else { m_fRotationDest = limitedCam; changedHeadingRate = 2; - m_headingRate = 50.0f; + m_headingRate = 12.5f; // Anim. fix for shotgun, ak47 and m16 (we must finish rot. it quickly) if (weaponInfo->m_bCanAim && padUsed->WeaponJustDown()) { @@ -1115,7 +1293,7 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) } #endif - if (padUsed->GetTarget() && m_nSelectedWepSlot == m_currentWeapon && m_nMoveState != PEDMOVE_SPRINT) { + if (padUsed->GetTarget() && m_nSelectedWepSlot == m_currentWeapon && m_nMoveState != PEDMOVE_SPRINT && !TheCamera.Using1stPersonWeaponMode() && weaponInfo->m_bCanAim) { if (m_pPointGunAt) { // what?? if (!m_pPointGunAt @@ -1123,15 +1301,26 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) || (!CCamera::bFreeCam && CCamera::m_bUseMouse3rdPerson) #else || CCamera::m_bUseMouse3rdPerson -#endif - || m_pPointGunAt->IsPed() && ((CPed*)m_pPointGunAt)->bInVehicle) { +#endif + ) { ClearWeaponTarget(); return; } - if (CPlayerPed::DoesTargetHaveToBeBroken(m_pPointGunAt->GetPosition(), GetWeapon())) { + + CPed *gunPointed = (CPed*)m_pPointGunAt; + if (gunPointed && gunPointed->IsPed() && + ((gunPointed->bInVehicle && (!gunPointed->m_pMyVehicle || !gunPointed->m_pMyVehicle->IsBike())) || !CGame::nastyGame && gunPointed->DyingOrDead())) { ClearWeaponTarget(); return; } + if (CPlayerPed::DoesTargetHaveToBeBroken(m_pPointGunAt->GetPosition(), GetWeapon()) || + (!bCanPointGunAtTarget && !weaponInfo->m_bCanAimWithArm)) { + ClearWeaponTarget(); + return; + } + + // TODO(Miami): RotatePlayerToTrackTarget + if (m_pPointGunAt) { if (padUsed->ShiftTargetLeftJustDown()) FindNextWeaponLockOnTarget(m_pPointGunAt, true); @@ -1142,11 +1331,11 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) TheCamera.UpdateAimingCoors(m_pPointGunAt->GetPosition()); } #ifdef FREE_CAM - else if ((CCamera::bFreeCam && weaponInfo->m_eWeaponFire == WEAPON_FIRE_MELEE) || (weaponInfo->m_bCanAim && !CCamera::m_bUseMouse3rdPerson)) { + else if ((CCamera::bFreeCam && weaponInfo->m_eWeaponFire == WEAPON_FIRE_MELEE) || !CCamera::m_bUseMouse3rdPerson) { #else - else if (weaponInfo->m_bCanAim && !CCamera::m_bUseMouse3rdPerson) { + else if (!CCamera::m_bUseMouse3rdPerson) { #endif - if (padUsed->TargetJustDown()) + if (padUsed->TargetJustDown() || TheCamera.m_bJustJumpedOutOf1stPersonBecauseOfTarget) FindWeaponLockOnTarget(); } } else if (m_pPointGunAt) { @@ -1159,7 +1348,7 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) #else CVector markPos; if (m_pPointGunAt->IsPed()) { - ((CPed*)m_pPointGunAt)->m_pedIK.GetComponentPosition((RwV3d*)markPos, PED_MID); + ((CPed*)m_pPointGunAt)->m_pedIK.GetComponentPosition(*(RwV3d *)&markPos, PED_MID); } else { markPos = m_pPointGunAt->GetPosition(); } @@ -1195,7 +1384,7 @@ CPlayerPed::PlayerControlZelda(CPad *padUsed) float neededTurn = CGeneral::LimitRadianAngle(padHeading - camOrientation); if (doSmoothSpray) { if (GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER || GetWeapon()->m_eWeaponType == WEAPONTYPE_COLT45 - || GetWeapon()->m_eWeaponType == WEAPONTYPE_UZI) + || CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nWeaponSlot == 5) m_fRotationDest = m_fRotationCur - leftRight / 128.0f * (PI / 80.0f) * CTimer::GetTimeStep(); else m_fRotationDest = m_fRotationCur - leftRight / 128.0f * (PI / 128.0f) * CTimer::GetTimeStep(); @@ -1225,9 +1414,16 @@ CPlayerPed::PlayerControlZelda(CPad *padUsed) } } + if (m_nPedState == PED_ANSWER_MOBILE) { + SetRealMoveAnim(); + return; + } + if (!(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bHeavy) && padUsed->GetSprint()) { - m_nMoveState = PEDMOVE_SPRINT; + + if (!m_pCurrentPhysSurface || !m_pCurrentPhysSurface->bInfiniteMass || m_pCurrentPhysSurface->m_phy_flagA08) + m_nMoveState = PEDMOVE_SPRINT; } if (m_nPedState != PED_FIGHT) SetRealMoveAnim(); @@ -1244,6 +1440,7 @@ CPlayerPed::PlayerControlZelda(CPad *padUsed) SetJump(); } } + PlayIdleAnimations(padUsed); } void @@ -1318,11 +1515,11 @@ CPlayerPed::ProcessControl(void) m_nMoveState = PEDMOVE_STILL; if (bIsLanding) RunningLand(padUsed); - if (padUsed && padUsed->WeaponJustDown() && m_nPedState != PED_SNIPER_MODE) { + if (padUsed && padUsed->WeaponJustDown() && !TheCamera.Using1stPersonWeaponMode()) { // ...Really? eWeaponType playerWeapon = FindPlayerPed()->GetWeapon()->m_eWeaponType; - if (playerWeapon == WEAPONTYPE_SNIPERRIFLE) { + if (playerWeapon == WEAPONTYPE_SNIPERRIFLE || playerWeapon == WEAPONTYPE_LASERSCOPE) { DMAudio.PlayFrontEndSound(SOUND_WEAPON_SNIPER_SHOT_NO_ZOOM, 0); } else if (playerWeapon == WEAPONTYPE_ROCKETLAUNCHER) { DMAudio.PlayFrontEndSound(SOUND_WEAPON_ROCKET_SHOT_NO_ZOOM, 0); @@ -1337,8 +1534,12 @@ CPlayerPed::ProcessControl(void) case PED_ATTACK: case PED_FIGHT: case PED_AIM_GUN: - if (!RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_BLOCK)) { - if (TheCamera.Cams[0].Using3rdPersonMouseCam()) { + case PED_ANSWER_MOBILE: + if (!RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_BLOCK) && !m_attachedTo) { + if (TheCamera.Using1stPersonWeaponMode()) { + if (padUsed) + PlayerControlFighter(padUsed); + } else if (TheCamera.Cams[0].Using3rdPersonMouseCam()) { if (padUsed) PlayerControl1stPersonRunAround(padUsed); } else if (m_nPedState == PED_FIGHT) { @@ -1348,7 +1549,7 @@ CPlayerPed::ProcessControl(void) PlayerControlZelda(padUsed); } } - if (IsPedInControl() && padUsed) + if (IsPedInControl() && m_nPedState != PED_ANSWER_MOBILE && padUsed) ProcessPlayerWeapon(padUsed); break; case PED_LOOK_ENTITY: @@ -1372,8 +1573,13 @@ CPlayerPed::ProcessControl(void) case PED_INVESTIGATE: case PED_STEP_AWAY: case PED_ON_FIRE: + case PED_SUN_BATHE: + case PED_FLASH: + case PED_JOG: case PED_UNKNOWN: case PED_STATES_NO_AI: + case PED_ABSEIL: + case PED_SIT: case PED_STAGGER: case PED_DIVE_AWAY: case PED_STATES_NO_ST: @@ -1412,11 +1618,11 @@ CPlayerPed::ProcessControl(void) } break; case PED_SNIPER_MODE: - if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_M16) { + if (GetWeapon()->m_eWeaponType == WEAPONTYPE_SNIPERRIFLE || GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE) { if (padUsed) - PlayerControlM16(padUsed); + PlayerControlSniper(padUsed); } else if (padUsed) { - PlayerControlSniper(padUsed); + PlayerControlM16(padUsed); } break; case PED_SEEK_CAR: @@ -1465,9 +1671,9 @@ CPlayerPed::ProcessControl(void) BeingDraggedFromCar(); break; } - if (padUsed && IsPedShootable()) { + if (padUsed && IsPedShootable() && m_nPedState != PED_ANSWER_MOBILE && m_nLastPedState != PED_ANSWER_MOBILE) { ProcessWeaponSwitch(padUsed); - GetWeapon()->Update(m_audioEntityId); + GetWeapon()->Update(m_audioEntityId, this); } ProcessAnimGroups(); if (padUsed) { @@ -1516,12 +1722,205 @@ CPlayerPed::ProcessControl(void) m_bSpeedTimerFlag = false; } + if (m_nPedState != PED_SNIPER_MODE && (GetWeapon()->m_eWeaponState == WEAPONSTATE_FIRING || m_nPedState == PED_ATTACK)) + m_nPadDownPressedInMilliseconds = CTimer::GetTimeInMilliseconds(); + #ifdef PED_SKIN if (!bIsVisible && IsClumpSkinned(GetClump())) UpdateRpHAnim(); #endif } +bool +CPlayerPed::DoesPlayerWantNewWeapon(eWeaponType weapon, bool onlyIfSlotIsEmpty) +{ + uint32 slot = CWeaponInfo::GetWeaponInfo(weapon)->m_nWeaponSlot; + + if (!HasWeaponSlot(slot) || GetWeapon(slot).m_eWeaponType == weapon) + return true; + + if (onlyIfSlotIsEmpty) + return false; + + // Check if he's using that slot right now. + return m_nPedState != PED_ATTACK && m_nPedState != PED_AIM_GUN || slot != m_currentWeapon; +} + +// TODO(Miami): This only works on gamepad cam! This isn't fair +void +CPlayerPed::PlayIdleAnimations(CPad *padUsed) +{ + CAnimBlendAssociation* assoc; + + if (TheCamera.m_WideScreenOn || bIsDucking) + return; + + struct animAndGroup { + AnimationId animId; + AssocGroupId groupId; + }; + + const animAndGroup idleAnims[] = { + {ANIM_IDLE_STRETCH, ASSOCGRP_PLAYER_IDLE}, + {ANIM_IDLE_TIME, ASSOCGRP_PLAYER_IDLE}, + {ANIM_IDLE_SHOULDER, ASSOCGRP_PLAYER_IDLE}, + {ANIM_IDLE_STRETCH_LEG, ASSOCGRP_PLAYER_IDLE}, + {ANIM_XPRESS_SCRATCH, ASSOCGRP_STD}, + }; + + static int32 lastTime = 0; + static int32 lastAnim = -1; + + bool hasIdleAnim = false; + CAnimBlock *idleAnimBlock = CAnimManager::GetAnimationBlock(idleAnimBlockIndex); + uint32 sinceLastInput = padUsed->InputHowLongAgo(); + if (sinceLastInput <= 30000) { + if (idleAnimBlock->isLoaded) { + for (assoc = RpAnimBlendClumpGetFirstAssociation(GetClump()); assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) { + if (assoc->flags & ASSOC_IDLE) { + hasIdleAnim = true; + assoc->blendDelta = -8.0f; + } + } + if (!hasIdleAnim) + CStreaming::RemoveAnim(idleAnimBlockIndex); + } else { + lastTime = 0; + } + } else { + CStreaming::RequestAnim(idleAnimBlockIndex, STREAMFLAGS_DONT_REMOVE); + if (idleAnimBlock->isLoaded) { + for(CAnimBlendAssociation *assoc = RpAnimBlendClumpGetFirstAssociation(GetClump()); assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) { + int firstIdle = idleAnimBlock->firstIndex; + int index = assoc->hierarchy - CAnimManager::GetAnimation(0); + if (index >= firstIdle && index < firstIdle + idleAnimBlock->numAnims) { + hasIdleAnim = true; + break; + } + } + + if (!hasIdleAnim && !bIsLooking && !bIsRestoringLook && sinceLastInput - lastTime > 25000) { + int anim; + do + anim = CGeneral::GetRandomNumberInRange(0, ARRAY_SIZE(idleAnims)); + while (lastAnim == anim); + + assoc = CAnimManager::BlendAnimation(GetClump(), idleAnims[anim].groupId, idleAnims[anim].animId, 8.0f); + assoc->flags |= ASSOC_IDLE; + lastAnim = anim; + lastTime = sinceLastInput; + } + } + } +} + +// --MIAMI: Done +void +CPlayerPed::RemovePedFromMeleeList(CPed *ped) +{ + int i = 0; + for (; m_pMeleeList[i] != ped; i++) { + if (i >= ARRAY_SIZE(m_pMeleeList)) + return; + } + m_pMeleeList[i] = nil; + ped->m_attackTimer = 0; +} + +// --MIAMI: Done +void +CPlayerPed::GetMeleeAttackCoords(CVector& coords, int8 dir, float dist) +{ + coords = GetPosition(); + switch (dir) { + case 0: + coords.y += dist; + break; + case 1: + coords.x += Sqrt(3.f / 4.f) * dist; + coords.y += 0.5f * dist; + break; + case 2: + coords.x += Sqrt(3.f / 4.f) * dist; + coords.y -= 0.5f * dist; + break; + case 3: + coords.y -= dist; + break; + case 4: + coords.x -= Sqrt(3.f / 4.f) * dist; + coords.y -= 0.5f * dist; + break; + case 5: + coords.x -= Sqrt(3.f / 4.f) * dist; + coords.y += 0.5f * dist; + break; + default: + break; + } +} + +// --MIAMI: Done +int32 +CPlayerPed::FindMeleeAttackPoint(CPed *victim, CVector &dist, uint32 &endOfAttackOut) +{ + endOfAttackOut = 0; + bool thereIsAnEmptySlot = false; + int dirToAttack = -1; + for (int i = 0; i < ARRAY_SIZE(m_pMeleeList); i++) { + CPed* pedAtThisDir = m_pMeleeList[i]; + if (pedAtThisDir) { + if (pedAtThisDir == victim) { + dirToAttack = i; + } else { + if (pedAtThisDir->m_attackTimer > endOfAttackOut) + endOfAttackOut = pedAtThisDir->m_attackTimer; + } + } else { + thereIsAnEmptySlot = true; + } + } + + // We don't have victim ped in our melee list + if (dirToAttack == -1 && thereIsAnEmptySlot) { + float angle = Atan2(-dist.x, -dist.y); + float adjustedAngle = angle + DEGTORAD(30.0f); + if (adjustedAngle < 0.f) + adjustedAngle += TWOPI; + + int wantedDir = Floor(adjustedAngle / DEGTORAD(60.0f)); + + // And we have another ped at the direction of victim ped, so store victim to next empty direction to it's real direction. (Bollocks) + if (m_pMeleeList[wantedDir]) { + int closestDirToPreferred = -99; + int preferredDir = wantedDir; + + for (int i = 0; i < ARRAY_SIZE(m_pMeleeList); i++) { + if (!m_pMeleeList[i]) { + if (Abs(i - preferredDir) < Abs(closestDirToPreferred - preferredDir)) + closestDirToPreferred = i; + } + } + if (closestDirToPreferred > 0) + dirToAttack = closestDirToPreferred; + } else { + + // Luckily the direction of victim ped is already empty, good + dirToAttack = wantedDir; + } + + if (dirToAttack != -1) { + m_pMeleeList[dirToAttack] = victim; + victim->RegisterReference((CEntity**) &m_pMeleeList[dirToAttack]); + if (endOfAttackOut > CTimer::GetTimeInMilliseconds()) + victim->m_attackTimer = endOfAttackOut + CGeneral::GetRandomNumberInRange(1000, 2000); + else + victim->m_attackTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(500, 1000); + } + } + return dirToAttack; +} + #ifdef COMPATIBLE_SAVES #define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data)); #define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data)); diff --git a/src/peds/PlayerPed.h b/src/peds/PlayerPed.h index e8173c8c..3b8d8fcb 100644 --- a/src/peds/PlayerPed.h +++ b/src/peds/PlayerPed.h @@ -18,22 +18,32 @@ public: int8 m_nSelectedWepSlot; // eWeaponType bool m_bSpeedTimerFlag; uint8 m_nEvadeAmount; - int8 field_1367; - uint32 m_nSpeedTimer; - uint32 m_nHitAnimDelayTimer; + uint32 m_nSpeedTimer; // m_nStandStillTimer? + uint32 m_nHitAnimDelayTimer; // m_nShotDelay? float m_fAttackButtonCounter; bool m_bHaveTargetSelected; // may have better name CEntity *m_pEvadingFrom; // is this CPhysical? int32 m_nTargettableObjects[4]; + uint32 m_nAdrenalineTime; + uint8 m_nDrunkenness; // Needed to work out whether we lost target this frame + uint8 m_nFadeDrunkenness; + uint8 m_nDrunkCountdown; //countdown in frames when the drunk effect ends bool m_bAdrenalineActive; bool m_bHasLockOnTarget; - uint32 m_nAdrenalineTime; bool m_bCanBeDamaged; - int8 field_1413; + bool m_bDrunkVisualsWearOff; // TODO(Miami): That may be something else CVector m_vecSafePos[6]; // safe places from the player, for example behind a tree CPed *m_pPedAtSafePos[6]; - float m_fWalkAngle; + CPed *m_pMeleeList[6]; // reachable peds at each direction(6) + char unused1; + int16 m_nCheckPlayersIndex; + float m_fWalkAngle; //angle between heading and walking direction float m_fFPSMoveHeading; + RpAtomic* m_pMinigunTopAtomic; //atomic for the spinning part of the minigun model + float m_fGunSpinSpeed; // for minigun + float m_fGunSpinAngle; + unsigned int m_nPadDownPressedInMilliseconds; + unsigned int m_nPadUpPressedInMilliseconds; CPlayerPed(); ~CPlayerPed(); @@ -45,7 +55,8 @@ public: void SetWantedLevelNoDrop(int32 level); void KeepAreaAroundPlayerClear(void); void AnnoyPlayerPed(bool); - void MakeChangesForNewWeapon(int8); + void MakeChangesForNewWeapon(int32); + void MakeChangesForNewWeapon(eWeaponType); void SetInitialState(void); void ProcessControl(void); void ClearAdrenaline(void); @@ -71,6 +82,11 @@ public: void ProcessAnimGroups(void); void ProcessPlayerWeapon(CPad*); void PlayerControlZelda(CPad*); + bool DoesPlayerWantNewWeapon(eWeaponType, bool); + void PlayIdleAnimations(CPad*); + void RemovePedFromMeleeList(CPed*); + void GetMeleeAttackCoords(CVector&, int8, float); + int32 FindMeleeAttackPoint(CPed*, CVector&, uint32&); static void SetupPlayerPed(int32); static void DeactivatePlayerPed(int32); diff --git a/src/peds/Population.cpp b/src/peds/Population.cpp index 0756df38..f7e0973f 100644 --- a/src/peds/Population.cpp +++ b/src/peds/Population.cpp @@ -22,6 +22,7 @@ #include "DummyObject.h" #include "Script.h" #include "Shadows.h" +#include "SurfaceTable.h" #define MIN_CREATION_DIST 40.0f // not for start of the game (look at the GeneratePedsAtStartOfGame) #define CREATION_RANGE 10.0f // added over the MIN_CREATION_DIST. @@ -31,6 +32,10 @@ // Transition areas between zones const RegenerationPoint aSafeZones[] = { +// TODO(MIAMI): this is totally bogus + { LEVEL_BEACH, LEVEL_MAINLAND, 400.0f, 814.0f, -954.0f, -903.0f, 30.0f, 100.0f, + CVector(790.0f, -917.0f, 39.0f), CVector(775.0f, -921.0f, 39.0f), CVector(424.0f, -942.0f, 38.0f), CVector(439.0f, -938.0f, 38.0f) }, +#ifndef MIAMI { LEVEL_INDUSTRIAL, LEVEL_COMMERCIAL, 400.0f, 814.0f, -954.0f, -903.0f, 30.0f, 100.0f, CVector(790.0f, -917.0f, 39.0f), CVector(775.0f, -921.0f, 39.0f), CVector(424.0f, -942.0f, 38.0f), CVector(439.0f, -938.0f, 38.0f) }, { LEVEL_INDUSTRIAL, LEVEL_COMMERCIAL, 555.0f, 711.0f, 118.0f, 186.0f, -30.0f, -10.0f, @@ -47,6 +52,7 @@ const RegenerationPoint aSafeZones[] = { CVector(-321.0f, -1043.0f, -13.2f), CVector(-328.0f, -1045.0f, -13.2f), CVector(-398.0f, -1044.0f, -13.5f), CVector(-390.0f, -1040.5f, -13.5f) }, { LEVEL_COMMERCIAL, LEVEL_SUBURBAN, -425.0f, -280.0f, -471.0f, -447.0f, -20.0f, -5.0f, CVector(-292.0f, -457.0f, -11.6f), CVector(-310.0f, -461.0f, -11.6f), CVector(-413.0f, -461.0f, -11.5f), CVector(-399.0f, -457.0f, -11.3f) } +#endif }; PedGroup CPopulation::ms_pPedGroups[NUMPEDGROUPS]; @@ -78,6 +84,9 @@ CVector CPopulation::RegenerationPoint_a; CVector CPopulation::RegenerationPoint_b; CVector CPopulation::RegenerationForward; +uint32 CPopulation::ms_nTotalCarPassengerPeds; +uint32 CPopulation::NumMiamiViceCops; + void CPopulation::Initialise() { @@ -98,6 +107,8 @@ CPopulation::Initialise() ms_nNumGang9 = 0; ms_nNumDummy = 0; + ms_nTotalCarPassengerPeds = 0; + m_AllRandomPedsThisType = -1; PedDensityMultiplier = 1.0f; bZoneChangeHasHappened = false; @@ -109,7 +120,6 @@ CPopulation::Initialise() ms_nTotalCivPeds = 0; LoadPedGroups(); - DealWithZoneChange(LEVEL_COMMERCIAL, LEVEL_INDUSTRIAL, true); debug("CPopulation ready\n"); } @@ -320,64 +330,13 @@ CPopulation::UpdatePedCount(ePedType pedType, bool decrease) int CPopulation::ChooseGangOccupation(int gangId) { - int8 modelOverride = CGangs::GetGangPedModelOverride(gangId); - - // All gangs have 2 models - int firstGangModel = 2 * gangId + MI_GANG01; - - // GetRandomNumberInRange never returns max. value - if (modelOverride == -1) - return CGeneral::GetRandomNumberInRange(firstGangModel, firstGangModel + 2); - - if (modelOverride != 0) - return firstGangModel + 1; - else - return firstGangModel; + return CGangs::ChooseGangPedModel(gangId); } +//--MIAMI: done void CPopulation::DealWithZoneChange(eLevelName oldLevel, eLevelName newLevel, bool forceIndustrialZone) { - bZoneChangeHasHappened = true; - - CVector findSafeZoneAround; - int safeZone; - - if (forceIndustrialZone) { - // Commercial to industrial transition area on Callahan Bridge - findSafeZoneAround.x = 690.0f; - findSafeZoneAround.y = -920.0f; - findSafeZoneAround.z = 42.0f; - } else { - findSafeZoneAround = FindPlayerCoors(); - } - eLevelName level; - FindCollisionZoneForCoors(&findSafeZoneAround, &safeZone, &level); - - // We aren't in a "safe zone", find closest one - if (safeZone < 0) - FindClosestZoneForCoors(&findSafeZoneAround, &safeZone, oldLevel, newLevel); - - // No, there should be one! - if (safeZone < 0) { - if (newLevel == LEVEL_INDUSTRIAL) { - safeZone = 0; - } else if (newLevel == LEVEL_SUBURBAN) { - safeZone = 4; - } - } - - if (aSafeZones[safeZone].srcLevel == newLevel) { - CPopulation::RegenerationPoint_a = aSafeZones[safeZone].srcPosA; - CPopulation::RegenerationPoint_b = aSafeZones[safeZone].srcPosB; - CPopulation::RegenerationForward = aSafeZones[safeZone].destPosA - aSafeZones[safeZone].srcPosA; - RegenerationForward.Normalise(); - } else if (aSafeZones[safeZone].destLevel == newLevel) { - CPopulation::RegenerationPoint_a = aSafeZones[safeZone].destPosA; - CPopulation::RegenerationPoint_b = aSafeZones[safeZone].destPosB; - CPopulation::RegenerationForward = aSafeZones[safeZone].srcPosA - aSafeZones[safeZone].destPosA; - RegenerationForward.Normalise(); - } } void @@ -433,6 +392,7 @@ CPopulation::Update() + ms_nNumGang2 + ms_nNumGang1; ms_nTotalPeds = ms_nNumDummy + ms_nNumEmergency + ms_nNumCop + ms_nTotalGangPeds + ms_nNumCivFemale + ms_nNumCivMale; + ms_nTotalPeds -= ms_nTotalCarPassengerPeds; if (!CCutsceneMgr::IsRunning()) { float pcdm = PedCreationDistMultiplier(); AddToPopulation(pcdm * (MIN_CREATION_DIST * TheCamera.GenerationDistMultiplier), @@ -454,6 +414,7 @@ CPopulation::GeneratePedsAtStartOfGame() + ms_nNumGang3 + ms_nNumGang2 + ms_nNumGang1; ms_nTotalPeds = ms_nNumDummy + ms_nNumEmergency + ms_nNumCop + ms_nTotalGangPeds + ms_nNumCivFemale + ms_nNumCivMale; + ms_nTotalPeds -= ms_nTotalCarPassengerPeds; // Min dist is 10.0f only for start of the game (naturally) AddToPopulation(10.0f, PedCreationDistMultiplier() * (MIN_CREATION_DIST + CREATION_RANGE), @@ -488,7 +449,7 @@ CPopulation::PedCreationDistMultiplier() } CPed* -CPopulation::AddPed(ePedType pedType, uint32 miOrCopType, CVector const &coors) +CPopulation::AddPed(ePedType pedType, uint32 miOrCopType, CVector const &coors, int32 modifier) { switch (pedType) { case PEDTYPE_CIVMALE: @@ -499,16 +460,34 @@ CPopulation::AddPed(ePedType pedType, uint32 miOrCopType, CVector const &coors) ped->SetOrientation(0.0f, 0.0f, 0.0f); CWorld::Add(ped); if (ms_bGivePedsWeapons) { - eWeaponType weapon = (eWeaponType)CGeneral::GetRandomNumberInRange(WEAPONTYPE_UNARMED, WEAPONTYPE_DETONATOR); + eWeaponType weapon; + + switch (CGeneral::GetRandomNumber() & 3) { + case 0: + weapon = WEAPONTYPE_COLT45; + break; + case 1: + weapon = WEAPONTYPE_NIGHTSTICK; + break; + case 2: + weapon = WEAPONTYPE_GOLFCLUB; + break; + case 3: + weapon = WEAPONTYPE_TEC9; + break; + default: + break; + } if (weapon != WEAPONTYPE_UNARMED) { - ped->SetCurrentWeapon(ped->GiveWeapon(weapon, 25001)); + ped->GiveDelayedWeapon(weapon, 25001); + ped->SetCurrentWeapon(CWeaponInfo::GetWeaponInfo(weapon)->m_nWeaponSlot); } } return ped; } case PEDTYPE_COP: { - CCopPed *ped = new CCopPed((eCopType)miOrCopType); + CCopPed *ped = new CCopPed((eCopType)miOrCopType, modifier); ped->SetPosition(coors); ped->SetOrientation(0.0f, 0.0f, 0.0f); CWorld::Add(ped); @@ -529,12 +508,14 @@ CPopulation::AddPed(ePedType pedType, uint32 miOrCopType, CVector const &coors) ped->SetOrientation(0.0f, 0.0f, 0.0f); CWorld::Add(ped); - uint32 weapon; + eWeaponType weapon; if (CGeneral::GetRandomNumberInRange(0, 100) >= 50) - weapon = ped->GiveWeapon((eWeaponType)CGangs::GetGangInfo(pedType - PEDTYPE_GANG1)->m_Weapon2, 25001); + weapon = (eWeaponType)CGangs::GetGangInfo(pedType - PEDTYPE_GANG1)->m_Weapon2; else - weapon = ped->GiveWeapon((eWeaponType)CGangs::GetGangInfo(pedType - PEDTYPE_GANG1)->m_Weapon1, 25001); - ped->SetCurrentWeapon(weapon); + weapon = (eWeaponType)CGangs::GetGangInfo(pedType - PEDTYPE_GANG1)->m_Weapon1; + + ped->GiveDelayedWeapon(weapon, 25001); + ped->SetCurrentWeapon(CWeaponInfo::GetWeaponInfo(weapon)->m_nWeaponSlot); return ped; } case PEDTYPE_EMERGENCY: @@ -578,16 +559,23 @@ CPopulation::AddToPopulation(float minDist, float maxDist, float minDistOffScree CZoneInfo zoneInfo; CPed *gangLeader = nil; bool addCop = false; + bool forceAddingCop = false; CPlayerInfo *playerInfo = &CWorld::Players[CWorld::PlayerInFocus]; CVector playerCentreOfWorld = FindPlayerCentreOfWorld(CWorld::PlayerInFocus); CTheZones::GetZoneInfoForTimeOfDay(&playerCentreOfWorld, &zoneInfo); CWanted *wantedInfo = playerInfo->m_pPed->m_pWanted; + if (wantedInfo->m_nWantedLevel > 2) { - if (ms_nNumCop < wantedInfo->m_MaxCops && !playerInfo->m_pPed->bInVehicle - && (CCarCtrl::NumLawEnforcerCars >= wantedInfo->m_MaximumLawEnforcerVehicles + if (!CGame::IsInInterior() && (CGeneral::GetRandomNumber() % 32 == 0) && FindPlayerVehicle()) + forceAddingCop = true; + + uint32 maxCops = CGame::IsInInterior() ? wantedInfo->m_MaxCops * 1.6f : wantedInfo->m_MaxCops; + if ((ms_nNumCop < maxCops || forceAddingCop) && + (!playerInfo->m_pPed->bInVehicle && + (CCarCtrl::NumLawEnforcerCars >= wantedInfo->m_MaximumLawEnforcerVehicles || CCarCtrl::NumRandomCars >= playerInfo->m_nTrafficMultiplier * CCarCtrl::CarDensityMultiplier || CCarCtrl::NumFiretrucksOnDuty + CCarCtrl::NumAmbulancesOnDuty + CCarCtrl::NumParkedCars - + CCarCtrl::NumMissionCars + CCarCtrl::NumLawEnforcerCars + CCarCtrl::NumRandomCars >= CCarCtrl::MaxNumberOfCarsInUse)) { + + CCarCtrl::NumMissionCars + CCarCtrl::NumLawEnforcerCars + CCarCtrl::NumRandomCars >= CCarCtrl::MaxNumberOfCarsInUse) || forceAddingCop)) { addCop = true; minDist = PedCreationDistMultiplier() * MIN_CREATION_DIST; maxDist = PedCreationDistMultiplier() * (MIN_CREATION_DIST + CREATION_RANGE); @@ -599,14 +587,12 @@ CPopulation::AddToPopulation(float minDist, float maxDist, float minDistOffScree if (ms_nTotalPeds < maxPossiblePedsForArea || addCop) { int decisionThreshold = CGeneral::GetRandomNumberInRange(0, 1000); - if (decisionThreshold < zoneInfo.copDensity || addCop) { + if (decisionThreshold < zoneInfo.copPedThreshold || addCop) { pedTypeToAdd = PEDTYPE_COP; modelToAdd = ChoosePolicePedOccupation(); } else { - int16 density = zoneInfo.copDensity; for (int i = 0; i < NUM_GANGS; i++) { - density += zoneInfo.gangDensity[i]; - if (decisionThreshold < density) { + if (decisionThreshold < zoneInfo.gangPedThreshold[i]) { pedTypeToAdd = PEDTYPE_GANG1 + i; break; } @@ -693,7 +679,7 @@ CPopulation::AddToPopulation(float minDist, float maxDist, float minDistOffScree generatedCoors.y = yOffset + gangLeader->GetPosition().y; } } - if (!CPedPlacement::IsPositionClearForPed(&generatedCoors)) + if (!CPedPlacement::IsPositionClearForPed(generatedCoors)) break; // Why no love for last gang member?! @@ -714,6 +700,9 @@ CPopulation::AddToPopulation(float minDist, float maxDist, float minDistOffScree if (!farEnoughToAdd) break; CPed *newPed = AddPed((ePedType)pedTypeToAdd, modelToAdd, generatedCoors); + if (forceAddingCop && newPed->m_nPedType == PEDTYPE_COP) + ((CCopPed*)newPed)->m_bThrowsSpikeTrap = true; + newPed->SetWanderPath(CGeneral::GetRandomNumberInRange(0, 8)); if (i != 0) { @@ -742,10 +731,12 @@ CPopulation::AddToPopulation(float minDist, float maxDist, float minDistOffScree } } +// TODO(Miami) CPed* -CPopulation::AddPedInCar(CVehicle* car) +CPopulation::AddPedInCar(CVehicle* car, bool isDriver) { - int defaultModel = MI_MALE01; + const int defaultModel = MI_MALE01; + int miamiViceIndex = 0; bool imSureThatModelIsLoaded = true; CVector coors = FindPlayerCoors(); CZoneInfo zoneInfo; @@ -764,11 +755,8 @@ CPopulation::AddPedInCar(CVehicle* car) preferredModel = 0; pedType = PEDTYPE_EMERGENCY; break; - case MI_FBICAR: - preferredModel = COP_FBI; - pedType = PEDTYPE_COP; - break; case MI_POLICE: + case MI_PREDATOR: preferredModel = COP_STREET; pedType = PEDTYPE_COP; break; @@ -781,18 +769,24 @@ CPopulation::AddPedInCar(CVehicle* car) preferredModel = COP_ARMY; pedType = PEDTYPE_COP; break; - case MI_TAXI: - case MI_CABBIE: - case MI_BORGNINE: - if (CGeneral::GetRandomTrueFalse()) { - pedType = PEDTYPE_CIVMALE; - preferredModel = MI_TAXI_D; + case MI_FBIRANCH: + preferredModel = COP_FBI; + pedType = PEDTYPE_COP; + break; + default: + if (car->GetModelIndex() == MI_TAXI || car->GetModelIndex() == MI_CABBIE || car->GetModelIndex() == MI_ZEBRA || car->GetModelIndex() == MI_KAUFMAN) { + if (isDriver) { + pedType = PEDTYPE_CIVMALE; + preferredModel = MI_TAXI_D; + break; + } + } else if (car->GetModelIndex() == MI_VICECHEE && car->bIsLawEnforcer) { + preferredModel = COP_MIAMIVICE; + pedType = PEDTYPE_COP; + miamiViceIndex = (isDriver ? 2 * CCarCtrl::MiamiViceCycle : 2 * CCarCtrl::MiamiViceCycle + 1); break; } - defaultModel = MI_TAXI_D; - // fall through - default: int gangOfPed = 0; imSureThatModelIsLoaded = false; @@ -811,8 +805,12 @@ CPopulation::AddPedInCar(CVehicle* car) if (preferredModel == -1) preferredModel = defaultModel; - if (((CPedModelInfo*)CModelInfo::GetModelInfo(preferredModel))->m_carsCanDrive & (1 << carModelInfo->m_vehicleClass)) - break; + if (((CPedModelInfo*)CModelInfo::GetModelInfo(preferredModel))->GetRwObject()) { + if (!car->IsPassenger(preferredModel) && !car->IsDriver(preferredModel)) { + if (((CPedModelInfo*)CModelInfo::GetModelInfo(preferredModel))->m_carsCanDrive & (1 << carModelInfo->m_vehicleClass)) + break; + } + } } if (i == -1) preferredModel = defaultModel; @@ -826,120 +824,20 @@ CPopulation::AddPedInCar(CVehicle* car) pedType = ((CPedModelInfo*)CModelInfo::GetModelInfo(defaultModel))->m_pedType; } - CPed *newPed = CPopulation::AddPed((ePedType)pedType, preferredModel, car->GetPosition()); + CPed *newPed = CPopulation::AddPed((ePedType)pedType, preferredModel, car->GetPosition(), miamiViceIndex); newPed->bUsesCollision = false; - // what?? - if (pedType != PEDTYPE_COP) { - newPed->SetCurrentWeapon(WEAPONTYPE_COLT45); + if (newPed->GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED) { newPed->RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(newPed->GetWeapon()->m_eWeaponType)->m_nModelId); } - /* - // Miami leftover - if (car->m_vehType == VEHICLE_TYPE_BIKE) { - newPed->m_pVehicleAnim = CAnimManager::BlendAnimation(newPed->GetClump(), ASSOCGRP_STD, *((CBike*)car + 308h), 100.0f); - } else */ - // FIX: Make peds comfortable while driving car/boat -#ifdef FIX_BUGS - { - newPed->m_pVehicleAnim = CAnimManager::BlendAnimation(newPed->GetClump(), ASSOCGRP_STD, car->GetDriverAnim(), 100.0f); - } -#else - { - newPed->m_pVehicleAnim = CAnimManager::BlendAnimation(newPed->GetClump(), ASSOCGRP_STD, ANIM_CAR_SIT, 100.0f); - } -#endif - - newPed->StopNonPartialAnims(); + newPed->AddInCarAnims(car, isDriver); return newPed; } void CPopulation::MoveCarsAndPedsOutOfAbandonedZones() { - eLevelName level; - int zone; - int frame = CTimer::GetFrameCounter() & 7; - if (frame == 1) { - int movedVehicleCount = 0; - int poolSize = CPools::GetVehiclePool()->GetSize(); - for (int poolIndex = poolSize - 1; poolIndex >= 0; poolIndex--) { - - CVehicle* veh = CPools::GetVehiclePool()->GetSlot(poolIndex); - if (veh && veh->m_nZoneLevel == LEVEL_GENERIC && veh->IsCar()) { - - if(veh->GetStatus() != STATUS_ABANDONED && veh->GetStatus() != STATUS_WRECKED && veh->GetStatus() != STATUS_PLAYER && - veh->GetStatus() != STATUS_PLAYER_REMOTE) { - - CVector vehPos(veh->GetPosition()); - CPopulation::FindCollisionZoneForCoors(&vehPos, &zone, &level); - - // Level 0 is transition zones, and we don't wanna touch cars on transition zones. - if (level != LEVEL_GENERIC && level != CCollision::ms_collisionInMemory && vehPos.z > -4.0f) { - if (veh->bIsLocked || !veh->CanBeDeleted()) { - switch (movedVehicleCount & 3) { - case 0: - veh->SetPosition(RegenerationPoint_a); - break; - case 1: - veh->SetPosition(RegenerationPoint_b); - break; - case 2: - veh->SetPosition(RegenerationPoint_a.x, RegenerationPoint_b.y, RegenerationPoint_a.z); - break; - case 3: - veh->SetPosition(RegenerationPoint_b.x, RegenerationPoint_a.y, RegenerationPoint_a.z); - break; - default: - break; - } - veh->GetMatrix().GetPosition().z += (movedVehicleCount / 4) * 7.0f; - veh->GetMatrix().GetForward() = RegenerationForward; - ((CAutomobile*)veh)->PlaceOnRoadProperly(); - CCarCtrl::JoinCarWithRoadSystem(veh); - CTheScripts::ClearSpaceForMissionEntity(veh->GetPosition(), veh); - ++movedVehicleCount; - } else { - CWorld::Remove(veh); - delete veh; - } - } - } - } - } - } else if (frame == 5) { - int poolSize = CPools::GetPedPool()->GetSize(); - for (int poolIndex = poolSize - 1; poolIndex >= 0; poolIndex--) { - - CPed *ped = CPools::GetPedPool()->GetSlot(poolIndex); - if (ped && ped->m_nZoneLevel == LEVEL_GENERIC && !ped->bInVehicle) { - - CVector pedPos(ped->GetPosition()); - CPopulation::FindCollisionZoneForCoors(&pedPos, &zone, &level); - - // Level 0 is transition zones, and we don't wanna touch peds on transition zones. - if (level != LEVEL_GENERIC && level != CCollision::ms_collisionInMemory && pedPos.z > -4.0f) { - if (ped->CanBeDeleted()) { - CWorld::Remove(ped); - delete ped; - } else if (ped->m_nPedType != PEDTYPE_PLAYER1 && ped->m_nPedType != PEDTYPE_PLAYER2) { - ped->SetPosition(RegenerationPoint_a); - - bool foundGround; - float groundZ = CWorld::FindGroundZFor3DCoord(ped->GetPosition().x, ped->GetPosition().y, - ped->GetPosition().z + 2.0f, &foundGround); - - if (foundGround) { - ped->GetMatrix().GetPosition().z = 1.0f + groundZ; - //ped->GetPosition().z += 0.0f; - CTheScripts::ClearSpaceForMissionEntity(ped->GetPosition(), ped); - } - } - } - } - } - } } void @@ -970,7 +868,8 @@ CPopulation::ConvertToRealObject(CDummyObject *dummy) delete dummy; CWorld::Add(obj); - if (IsGlass(obj->GetModelIndex())) { + CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(obj->GetModelIndex()); + if (IsGlass(obj->GetModelIndex()) && !mi->m_isArtistGlass) { obj->bIsVisible = false; } else if (obj->GetModelIndex() == MI_BUOY) { obj->bIsStatic = false; @@ -989,7 +888,8 @@ CPopulation::ConvertToDummyObject(CObject *obj) dummy->GetMatrix().UpdateRW(); dummy->UpdateRwFrame(); - if (IsGlass(obj->GetModelIndex())) + CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(obj->GetModelIndex()); + if (IsGlass(obj->GetModelIndex()) && !mi->m_isArtistGlass) dummy->bIsVisible = false; CWorld::Remove(obj); @@ -1121,12 +1021,9 @@ CPopulation::ManagePopulation(void) } float dist = (ped->GetPosition() - playerPos).Magnitude2D(); -#ifdef SQUEEZE_PERFORMANCE - if (dist > 50.f) - ped->bUsesCollision = false; - else - ped->bUsesCollision = true; -#endif + + if (ped->IsGangMember() || (ped->bDeadPedInFrontOfCar && ped->m_vehicleInAccident)) + dist -= 30.0f; bool pedIsFarAway = false; if (PedCreationDistMultiplier() * (PED_REMOVE_DIST_SPECIAL * TheCamera.GenerationDistMultiplier) < dist @@ -1174,3 +1071,67 @@ CPopulation::ManagePopulation(void) } } } + +CPed* +CPopulation::AddDeadPedInFrontOfCar(const CVector& pos, CVehicle* pCulprit) +{ + if (TheCamera.IsSphereVisible(pos, 2.0f)) { + float fDistanceToPlayer = (pos - FindPlayerPed()->GetPosition()).Magnitude2D(); + float fDistanceMultiplier; + if (FindPlayerVehicle()) + fDistanceMultiplier = clamp(FindPlayerVehicle()->GetMoveSpeed().Magnitude2D() - 0.1f + 1.0f, 1.0f, 1.5f); + else + fDistanceMultiplier = 1.0f; + if (40.0f * fDistanceMultiplier > fDistanceToPlayer) + return nil; + } + bool found; + float z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z, &found) + 1.0f; + if (!found) + return nil; + z = Max(z, pos.z); + if (!CModelInfo::GetModelInfo(MI_MALE01)->GetRwObject()) // strange way to check it + return nil; + CPed* pPed = CPopulation::AddPed(PEDTYPE_CIVMALE, MI_MALE01, pos); // TODO(MIAMI): 4th parameter + pPed->SetDie(); + pPed->m_nPedMoney = 0; + pPed->bDeadPedInFrontOfCar = true; + pPed->m_vehicleInAccident = pCulprit; + pCulprit->RegisterReference((CEntity**)&pPed->m_vehicleInAccident); + CEntity* pEntities[3] = { 0 }; + if (!CPedPlacement::IsPositionClearForPed(pos, 2.0f, 3, pEntities)) { + for (int i = 0; i < 3; i++) { + if (pEntities[i] && pEntities[i] != pCulprit && pEntities[i] != pPed) { + CWorld::Remove(pPed); + delete pPed; + return nil; + } + } + } + CColPoint colpts[MAX_COLLISION_POINTS]; + if (CCollision::ProcessColModels(pCulprit->GetMatrix(), *pCulprit->GetColModel(), pPed->GetMatrix(), *pPed->GetColModel(), colpts, nil, nil)) { + CWorld::Remove(pPed); + delete pPed; + return nil; + } + CVisibilityPlugins::SetClumpAlpha(pPed->GetClump(), 0); + return pPed; +} + +bool +CPopulation::IsSkateable(CVector const& pos) +{ + CColPoint foundCol; + CEntity* foundEnt = nil; + CWorld::ProcessVerticalLine(pos + CVector(0.f, 0.f, 2.f), pos.z - 2.0f, foundCol, foundEnt, true, false, false, false, false, false, nil); + if (!foundEnt) + return false; + + return foundCol.surfaceB == SURFACE_TARMAC || foundCol.surfaceB == SURFACE_PAVEMENT; +} + +bool +CPopulation::CanJeerAtStripper(int32 model) +{ + return model == MI_WMOBE || model == MI_WMYBE || model == MI_WMOST || model == MI_BMYBB; +}
\ No newline at end of file diff --git a/src/peds/Population.h b/src/peds/Population.h index aa8129c0..eaf3eade 100644 --- a/src/peds/Population.h +++ b/src/peds/Population.h @@ -62,12 +62,15 @@ public: static CVector RegenerationPoint_b; static CVector RegenerationForward; + static uint32 ms_nTotalCarPassengerPeds; + static uint32 NumMiamiViceCops; + static void Initialise(); static void Update(void); static void LoadPedGroups(); static void UpdatePedCount(ePedType, bool); static void DealWithZoneChange(eLevelName oldLevel, eLevelName newLevel, bool); - static CPed *AddPedInCar(CVehicle *car); + static CPed *AddPedInCar(CVehicle *car, bool isDriver); static bool IsPointInSafeZone(CVector *coors); static void RemovePed(CPed *ent); static int32 ChooseCivilianOccupation(int32); @@ -77,7 +80,7 @@ public: static void FindClosestZoneForCoors(CVector*, int*, eLevelName, eLevelName); static void GeneratePedsAtStartOfGame(); static float PedCreationDistMultiplier(); - static CPed *AddPed(ePedType pedType, uint32 mi, CVector const &coors); + static CPed *AddPed(ePedType pedType, uint32 mi, CVector const &coors, int32 modifier = 0); static void AddToPopulation(float, float, float, float); static void ManagePopulation(void); static void MoveCarsAndPedsOutOfAbandonedZones(void); @@ -86,4 +89,8 @@ public: static void ConvertAllObjectsToDummyObjects(void); static bool TestRoomForDummyObject(CObject*); static bool TestSafeForRealObject(CDummyObject*); + static bool IsSkateable(CVector const&); + static bool CanJeerAtStripper(int32 model); + + static CPed* AddDeadPedInFrontOfCar(const CVector& pos, CVehicle* pCulprit); }; |