diff options
Diffstat (limited to 'src/peds/Ped.cpp')
-rw-r--r-- | src/peds/Ped.cpp | 3811 |
1 files changed, 2534 insertions, 1277 deletions
diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 89c0b6af..e404463e 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -58,6 +58,11 @@ #include "ParticleObject.h" #include "Floater.h" #include "Range2D.h" +#include "Streaming.h" +#include "PedAttractor.h" +#include "Debug.h" +#include "GameLogic.h" +#include "Bike.h" #define CAN_SEE_ENTITY_ANGLE_THRESHOLD DEGTORAD(60.0f) @@ -66,36 +71,15 @@ 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}, + // TODO(Miami) }; uint16 CPed::nThreatReactionRangeMultiplier = 1; @@ -126,6 +110,8 @@ bool CPed::bMakePedsRunToPhonesToReportCrimes = false; CPed::~CPed(void) { 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); @@ -144,6 +130,12 @@ 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); } @@ -163,10 +155,11 @@ 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; } @@ -190,13 +183,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; @@ -225,6 +222,7 @@ 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; bRunningToPhone = false; m_phoneId = -1; m_lastAccident = 0; @@ -232,6 +230,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; @@ -263,6 +262,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; @@ -343,9 +344,33 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) #ifdef KANGAROO_CHEAT m_ped_flagI80 = false; #endif + + m_gangFlags = 0xFF; + + bReachedAttractorHeadingTarget = false; + bTurnedAroundOnAttractor = false; + bCarPassenger = false; + bMiamiViceCop = false; + bMoneyHasBeenGivenByScript = false; + bHasBeenPhotographed = false; + + bIsDrowning = false; + bDrownsInWater = true; #ifdef VC_PED_PORTS - bSomeVCflag1 = false; + bHeadStuckInCollision = false; #endif + bIsPlayerFriend = true; + bDeadPedInFrontOfCar = false; + bStayInCarOnJack = false; + + bDontFight = false; + bDoomAim = true; + bCanBeShotInVehicle = true; + bIgnoreThreatsBehindObjects = false; + + bNeverEverTargetThisPed = false; + + bBoughtIceCream = false; if ((CGeneral::GetRandomNumber() & 3) == 0) bHasACamera = true; @@ -368,8 +393,9 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) 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; @@ -379,39 +405,64 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) } m_lastFightMove = FIGHTMOVE_NULL; - GiveWeapon(WEAPONTYPE_UNARMED, 0); + 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 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* @@ -524,6 +575,7 @@ CPed::IsPlayer(void) m_nPedType == PEDTYPE_PLAYER3 || m_nPedType == PEDTYPE_PLAYER4; } +// --MIAMI: Done bool CPed::UseGroundColModel(void) { @@ -533,12 +585,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) { @@ -547,6 +601,7 @@ CPed::IsPedInControl(void) && m_fHealth > 0.0f; } +// --MIAMI: Done bool CPed::CanStrafeOrMouseControl(void) { @@ -555,9 +610,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) { @@ -565,8 +621,12 @@ CPed::AddWeaponModel(int id) if (id != -1) { #ifdef PED_SKIN - if(IsClumpSkinned(GetClump())) + if (IsClumpSkinned(GetClump())) { + if (m_pWeaponModel) + RemoveWeaponModel(-1); + m_pWeaponModel = (RpAtomic*)CModelInfo::GetModelInfo(id)->CreateInstance(); + } else #endif { @@ -575,7 +635,11 @@ 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(); } } @@ -587,7 +651,7 @@ CPed::AimGun(void) 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(); @@ -744,6 +808,7 @@ CPed::SetLookFlag(float direction, bool keepTryingToLook) } } +// --MIAMI: Done void CPed::SetLookTimer(int time) { @@ -822,6 +887,8 @@ CPed::Avoid(void) } } + +// --MIAMI: Done void CPed::ClearAimFlag(void) { @@ -829,6 +896,7 @@ CPed::ClearAimFlag(void) bIsAimingGun = false; bIsRestoringGun = true; m_pedIK.m_flags &= ~CPedIK::AIMS_WITH_ARM; + m_lookTimer = 0; } if (IsPlayer()) @@ -861,116 +929,273 @@ 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; 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; + } + + // Not for unarmed, it's for weapons using unarmed anims + if (currentWeapon->m_bUse2nd && ped->bIsAttacking && currentWeapon->m_AnimToPlay == ASSOCGRP_UNARMED) { + 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, ANIM_MELEE_ATTACK_2ND, 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(), ANIM_WEAPON_FIRE_2ND); + 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(!!ourWeapon->m_bUse2nd && CGeneral::GetRandomNumber() & 1){ + weaponAnimAssoc = CAnimManager::BlendAnimation(GetClump(), ourWeapon->m_AnimToPlay, ANIM_WEAPON_FIRE_2ND, 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); @@ -987,78 +1212,131 @@ 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_PUNCH_39, 0.0f); +#else + DMAudio.PlayOneShot(m_audioEntityId, SOUND_FIGHT_PUNCH_39, (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; + //TODO(Miami): Check if (weaponAnimTime > 1.0f && weaponAnimTime - weaponAnimAssoc->timeStep <= 1.0f && weaponAnimAssoc->IsRunning()) { TransformToNode(firePos, PED_HANDR); @@ -1077,85 +1355,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 == ANIM_WEAPON_FIRE_2ND) { + 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, ANIM_WEAPON_FIRE_2ND, 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) { @@ -1163,40 +1475,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; } @@ -1206,38 +1552,54 @@ 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 (!bCrouchWhenShooting) - return; + if (!animAssoc) { + animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCH); + } - 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) { @@ -1247,27 +1609,21 @@ 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; + } } void @@ -1325,7 +1681,7 @@ CPed::BeingDraggedFromCar(void) #ifdef VC_PED_PORTS 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 * 5.0f); } } #endif @@ -1580,7 +1936,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) 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: @@ -1591,7 +1947,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) #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 @@ -1599,14 +1955,14 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) case ANIM_CAR_CRAWLOUT_RHS2: case ANIM_VAN_GETOUT_L: case ANIM_VAN_GETOUT: - seatPosMult = m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength; + 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 @@ -2075,6 +2431,7 @@ CPed::SetPedStats(ePedStats pedStat) m_pedStats = CPedStats::ms_apPedStats[pedStat]; } +// --MIAMI: Done void CPed::SetModelIndex(uint32 mi) { @@ -2087,19 +2444,37 @@ CPed::SetModelIndex(uint32 mi) m_animGroup = (AssocGroupId) modelInfo->m_animGroup; CAnimManager::AddAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE); + // TODO(Miami): This is inlined CanUseTorsoWhenLooking + bool canUseMyBody = false; + if (m_nPedState != PED_DRIVING && m_nPedState != PED_DRAG_FROM_CAR && !bIsDucking) { + if (m_animGroup != ASSOCGRP_SEXYWOMAN && m_animGroup != ASSOCGRP_WOMAN) + canUseMyBody = true; + } + if (!canUseMyBody) + 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()); + + if (IsClumpSkinned(GetClump())) // condition isn't there in VC + UpdateRpHAnim(); #endif } void CPed::RemoveLighting(bool reset) { - CRenderer::RemoveVehiclePedLights(this, reset); + if (!bRenderScorched) { + CRenderer::RemoveVehiclePedLights(this, reset); + if (reset) + ReSetAmbientAndDirectionalColours(); + } + SetAmbientColours(); + DeActivateDirectional(); } bool @@ -2149,6 +2524,7 @@ CPed::CalculateNewOrientation(void) SetHeading(m_fRotationCur); } +// --MIAMI: Done float CPed::WorkOutHeadingForMovingFirstPerson(float offset) { @@ -2164,14 +2540,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) { @@ -2186,9 +2563,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)) @@ -2212,8 +2586,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(); @@ -2233,16 +2611,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); - // There is one more anim in VC. + 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; @@ -2253,35 +2628,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) { @@ -2293,11 +2652,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) { @@ -2314,7 +2676,7 @@ CPed::CanPedDriveOff(void) return true; } -#ifdef VC_PED_PORTS +// --MIAMI: Done bool CPed::CanPedJumpThis(CEntity *unused, CVector *damageNormal = nil) { @@ -2346,20 +2708,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) @@ -2368,6 +2716,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) { @@ -2664,18 +3013,17 @@ CPed::SetObjective(eObjective newObj, void *entity) } } +// --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); @@ -2983,6 +3331,7 @@ CPed::TurnBody(void) return turnDone; } +// --MIAMI: Done void CPed::Chat(void) { @@ -3017,7 +3366,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); @@ -3141,6 +3490,7 @@ CPed::FacePhone(void) #endif } +// --MIAMI: Done CPed * CPed::CheckForDeadPeds(void) { @@ -3156,6 +3506,7 @@ CPed::CheckForDeadPeds(void) return nil; } +// --MIAMI: Done bool CPed::CheckForExplosions(CVector2D &area) { @@ -3200,6 +3551,7 @@ CPed::CheckForExplosions(CVector2D &area) return false; } +// --MIAMI: Done CPed * CPed::CheckForGunShots(void) { @@ -3215,6 +3567,7 @@ CPed::CheckForGunShots(void) return nil; } +// --MIAMI: Done PointBlankNecessity CPed::CheckForPointBlankPeds(CPed *pedToVerify) { @@ -3258,6 +3611,7 @@ CPed::CheckForPointBlankPeds(CPed *pedToVerify) return NO_POINT_BLANK_PED; } +// --MIAMI: Done bool CPed::CheckIfInTheAir(void) { @@ -3279,13 +3633,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); @@ -3293,16 +3664,13 @@ 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; + b158_4 = false; m_pCollidingEntity = nil; } @@ -3331,29 +3699,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); + CAnimBlendAssociation *weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetPrimaryFireAnim(weapon)); - if (!weaponAssoc && weapon->m_bThrow) - weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_THROWU); - - if (!weaponAssoc) { - ClearAttack(); - return; - } + if (!weaponAssoc) { + if (!!weapon->m_bCrouchFire) + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetCrouchFireAnim(weapon)); + } + if (!weaponAssoc) { + if(!!weapon->m_bFinish3rd) + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_SPECIAL); + } + if (!weaponAssoc) { + if(!!weapon->m_bUse2nd) + weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCHFIRE); + } + 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 @@ -3367,6 +3746,7 @@ CPed::StopNonPartialAnims(void) } } +// --MIAMI: Done void CPed::SetStoredState(void) { @@ -3378,14 +3758,18 @@ CPed::SetStoredState(void) if (m_nMoveState == PEDMOVE_NONE || m_nMoveState == PEDMOVE_STILL) m_nMoveState = PEDMOVE_WALK; } - m_nLastPedState = m_nPedState; - if (m_nMoveState >= m_nPrevMoveState) - m_nPrevMoveState = m_nMoveState; + if (m_nPedState != PED_IDLE) { + m_nLastPedState = m_nPedState; + if (m_nMoveState >= m_nPrevMoveState) + m_nPrevMoveState = m_nMoveState; + } } 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) @@ -3413,7 +3797,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); @@ -3436,6 +3820,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) { @@ -3447,17 +3832,28 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi bool willLinger = false; int random; + // TODO(Miami): PlayerInfo thingies here + 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() && @@ -3470,8 +3866,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; @@ -3480,20 +3880,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; @@ -3521,19 +3937,28 @@ 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; -#ifdef VC_PED_PORTS - if (/*method != WEAPONTYPE_KATANA || */ + + if (method != WEAPONTYPE_KATANA || damagedBy != FindPlayerPed() || FindPlayerPed()->m_nPedState != PED_FIGHT - /*|| FindPlayerPed()->m_lastFightMove != 28 && FindPlayerPed()->m_lastFightMove != 29 */ + || FindPlayerPed()->m_lastFightMove != FIGHTMOVE_MELEE1 && FindPlayerPed()->m_lastFightMove != FIGHTMOVE_MELEE2 || CGeneral::GetRandomNumber() & 3) { 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; @@ -3542,8 +3967,8 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi dieDelta = dieDelta * 2.0f; dieSpeed = 0.5f; } - } else if (damagedBy != FindPlayerPed()) { // || FindPlayerPed()->m_lastFightMove != 29) - //if (damagedBy != FindPlayerPed() || FindPlayerPed()->m_lastFightMove != 30) { + } else if (damagedBy != FindPlayerPed() || FindPlayerPed()->m_lastFightMove != FIGHTMOVE_MELEE2) { + if (damagedBy != FindPlayerPed() || FindPlayerPed()->m_lastFightMove != FIGHTMOVE_MELEE3) { switch (direction) { case 0: dieAnim = ANIM_KO_SKID_FRONT; @@ -3560,79 +3985,49 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi default: break; } - //} else { - // dieAnim = ANIM_KO_SHOT_STOM; - //} + } else { + dieAnim = ANIM_KO_SHOT_STOM; + } } else { dieAnim = ANIM_KO_SHOT_FACE; } } else { dieAnim = ANIM_KO_SHOT_FACE; - // SpawnFlyingComponent in VC RemoveBodyPart(PED_HEAD, direction); headShot = true; willLinger = true; } -#else - if (m_nPedState == PED_FALL) { - if (IsPedHeadAbovePos(-0.3f)) { - dieAnim = NUM_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 { - 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; - } - } -#endif 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) { @@ -3697,8 +4092,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; @@ -3795,7 +4190,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(); @@ -3854,6 +4249,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) { @@ -3865,6 +4270,8 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi if (method != WEAPONTYPE_DROWNING) { #ifdef VC_PED_PORTS if (m_pMyVehicle) { + + // TODO(Miami): Bikes if (m_pMyVehicle->IsCar() && m_pMyVehicle->pDriver == this) { if (m_pMyVehicle->GetStatus() == STATUS_SIMPLE) { m_pMyVehicle->SetStatus(STATUS_PHYSICS); @@ -3875,7 +4282,8 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi m_pMyVehicle->AutoPilot.m_nTempAction = TEMPACT_HANDBRAKESTRAIGHT; m_pMyVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 2000; } - if (m_pMyVehicle->CanPedExitCar()) { +// TODO(MIAMI): argument + if (m_pMyVehicle->CanPedExitCar(false)) { SetObjective(OBJECTIVE_LEAVE_CAR_AND_DIE, m_pMyVehicle); } else { m_fHealth = 0.0f; @@ -3886,7 +4294,7 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi SetDie(dieAnim, dieDelta, dieSpeed); /* if (damagedBy == FindPlayerPed() && damagedBy != this) { - // PlayerInfo stuff + // TODO(Miami): PlayerInfo stuff } */ } @@ -3915,7 +4323,7 @@ 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; @@ -3923,7 +4331,7 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi if (damagedBy == player || damagedBy && damagedBy == FindPlayerVehicle()) { - // There are PlayerInfo stuff here in VC + // TODO(Miami): PlayerInfo stuff CDarkel::RegisterKillByPlayer(this, method, headShot); m_threatEntity = player; } else { @@ -3968,7 +4376,7 @@ CPed::SetGetUp(void) } if (m_nPedState != PED_GETUP) { SetStoredState(); - m_nPedState = PED_GETUP; + SetPedState(PED_GETUP); } CVehicle *collidingVeh = (CVehicle*)m_pCollidingEntity; @@ -3976,7 +4384,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; @@ -4011,7 +4419,7 @@ 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); } } @@ -4110,11 +4518,15 @@ CPed::ClearSeek(void) bRunningToPhone = false; } +// --MIAMI: Done bool CPed::SetWanderPath(int8 pathStateDest) { uint8 nextPathState; + if (IsPlayer()) + return false; + if (IsPedInControl()) { if (bKindaStayInSamePlace) { SetIdle(); @@ -4143,7 +4555,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; @@ -4155,25 +4567,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 @@ -4202,6 +4604,7 @@ CPed::RestoreHeadingRateCB(CAnimBlendAssociation *assoc, void *arg) ((CPed*)arg)->m_headingRate = ((CPed*)arg)->m_pedStats->m_headingChangeRate; } +// --MIAMI: Done void CPed::RestorePreviousState(void) { @@ -4212,7 +4615,7 @@ CPed::RestorePreviousState(void) return; if (InVehicle()) { - m_nPedState = PED_DRIVING; + SetPedState(PED_DRIVING); m_nLastPedState = PED_NONE; } else { if (m_nLastPedState == PED_NONE) { @@ -4229,21 +4632,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; } @@ -4278,68 +4683,97 @@ CPed::SetAimFlag(float angle) m_pedIK.m_flags &= ~CPedIK::AIMS_WITH_ARM; } +// --MIAMI: Done void CPed::SetPointGunAt(CEntity *to) { if (to) { SetLookFlag(to, 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) { + if (!!curWeapon->m_bCrouchFire) { + 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) { + if (!!curWeapon->m_bCrouchFire) { + 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 @@ -4400,7 +4834,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); @@ -4530,28 +4964,22 @@ CPed::SetEvasiveDive(CPhysical *reason, uint8 onlyRandomJump) } } +// --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 @@ -4560,20 +4988,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); @@ -4581,33 +5005,63 @@ 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; } + // TODO(Miami): Clean up old referene 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) { @@ -4615,7 +5069,7 @@ CPed::SetAttack(CEntity *victim) return; } - if (IsPlayer() || !victimPed || victimPed->IsPedInControl()) { + if (IsPlayer() || (!victimPed || victimPed->IsPedInControl())) { if (IsPlayer()) CPad::GetPad(0)->ResetAverageWeapon(); @@ -4629,7 +5083,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) @@ -4638,21 +5092,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(); @@ -4667,7 +5142,8 @@ CPed::SetAttack(CEntity *victim) if (GetWeapon()->m_eWeaponType == WEAPONTYPE_BASEBALLBAT && victimPed->m_nPedState == PED_GETUP) SetWaitState(WAITSTATE_SURPRISE, nil); - SetLookFlag(victim, false); + // TODO(Miami): New parameter + SetLookFlag(victim, true); //true); SetLookTimer(100); } @@ -4745,10 +5221,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; @@ -4777,12 +5254,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, @@ -4795,6 +5273,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; @@ -4818,11 +5297,14 @@ 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++; } @@ -4845,7 +5327,7 @@ CPed::GetLocalDirection(const CVector2D &posOffset) bool CPed::FightStrike(CVector &touchedNodePos) { - CColModel *ourCol; + CColModel *hisCol; CVector attackDistance; ePedPieceTypes closestPedPiece = PEDPIECE_TORSO; float maxDistanceToBeBeaten; @@ -4869,41 +5351,26 @@ CPed::FightStrike(CVector &touchedNodePos) if (nearPed->bUsesCollision || nearPed->m_nPedState == PED_DEAD) { 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()) { -#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->m_nPedState == PED_FALL - || nearPed->m_nPedState == PED_DEAD || nearPed->m_nPedState == PED_DIE - || !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_lastFightMove].strikeRadius; + CColSphere *hisPieces = hisCol->spheres; + float maxDistanceToBeat = hisPieces[j].radius + tFightMoves[m_lastFightMove].strikeRadius; // We can beat him too if (sq(maxDistanceToBeat) > attackDistance.MagnitudeSqr()) { pedFound = true; - closestPedPiece = (ePedPieceTypes) ourPieces[j].piece; + closestPedPiece = (ePedPieceTypes) hisPieces[j].piece; break; } } @@ -4930,6 +5397,7 @@ CPed::FightStrike(CVector &touchedNodePos) damageMult *= m_pedStats->m_attackStrength; } + /* // Change direction if we used kick. if (m_lastFightMove == FIGHTMOVE_KICK) { if (CGeneral::GetRandomNumber() & 1) { @@ -4937,7 +5405,7 @@ CPed::FightStrike(CVector &touchedNodePos) if (direction > 3) direction -= 4; } - } + } */ nearPed->ReactToAttack(this); // Mostly unused. if > 5, ANIM_HIT_WALK will be run, that's it. @@ -5008,34 +5476,57 @@ CPed::FightStrike(CVector &touchedNodePos) return false; } +// --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() @@ -5114,12 +5605,15 @@ CPed::SetFlee(CVector2D const &from, int time) 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); @@ -5145,11 +5639,16 @@ 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; m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 3500; - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 4.0f); + animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 4.0f); +#ifdef FIX_BUGS + animAssoc->SetFinishCallback(RestoreHeadingRateCB, this); +#endif break; case WAITSTATE_HITWALL: m_headingRate = 2.0f; @@ -5183,8 +5682,12 @@ CPed::SetWaitState(eWaitState state, void *time) SetMoveAnim(); m_headingRate = 0.0f; m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 5000; - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f); + animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f); +#ifdef FIX_BUGS + 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(); @@ -5196,15 +5699,18 @@ CPed::SetWaitState(eWaitState state, void *time) SetMoveAnim(); m_headingRate = 0.0f; m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 5000; - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 4.0f); + animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 4.0f); +#ifdef FIX_BUGS + animAssoc->SetFinishCallback(RestoreHeadingRateCB, this); +#endif break; 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) @@ -5218,10 +5724,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; @@ -5238,10 +5744,47 @@ CPed::SetWaitState(eWaitState state, void *time) SetMoveAnim(); m_headingRate = 0.0f; m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 2500; - CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f); + animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f); +#ifdef FIX_BUGS + 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_SUN_BATHE_PRE: + case WAITSTATE_SUN_BATHE_DOWN: + case WAITSTATE_SUN_BATHE_IDLE: + case WAITSTATE_FAST_FALL: + case WAITSTATE_BOMBER: + case WAITSTATE_GROUND_ATTACK: + case WAITSTATE_LANCESITTING: + case WAITSTATE_PLAYANIM_HANDSUP_SIMPLE: default: - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); RestoreHeadingRate(); return; } @@ -5568,6 +6111,7 @@ CPed::CollideWithPed(CPed *collideWith) } } +// --MIAMI: Done void CPed::CreateDeadPedMoney(void) { @@ -5575,54 +6119,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; +#define NUMBER_OF_ATTEMPTS 32 + for (int i = 0; i < NUMBER_OF_ATTEMPTS; i++) { - for(int i = 0; i < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; 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; @@ -5630,25 +6157,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) { @@ -5690,6 +6251,26 @@ CPed::SetBeingDraggedFromCar(CVehicle *veh, uint32 vehEnterType, bool quickJack) 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) { @@ -5699,55 +6280,73 @@ 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) SetStoredState(); - m_nPedState = PED_CHAT; + SetPedState(PED_CHAT); SetMoveState(PEDMOVE_STILL); + m_lookTimer = 0; 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) { -#ifdef VC_PED_PORTS if (!RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DROWN)) -#endif 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; @@ -5757,6 +6356,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(); } @@ -5797,11 +6397,7 @@ CPed::SetSeek(CVector pos, float distanceToCountDone) || (m_nPedState == PED_SEEK_POS && m_vecSeekPos.x == pos.x && m_vecSeekPos.y == pos.y)) 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(); } @@ -5862,6 +6458,7 @@ CPed::DoesLOSBulletHitPed(CColPoint &colPoint) return retVal; } +// --MIAMI: Done bool CPed::DuckAndCover(void) { @@ -5879,9 +6476,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); @@ -5890,25 +6489,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; @@ -5949,25 +6593,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; } } @@ -5975,8 +6619,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; @@ -5993,9 +6642,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) { @@ -6005,6 +6657,9 @@ CPed::EndFight(uint8 endType) m_lastFightMove = FIGHTMOVE_NULL; RestorePreviousState(); CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE); + if (!animAssoc) + animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WEAPON_CROUCHRELOAD); + if (animAssoc) animAssoc->flags |= ASSOC_DELETEFADEDOUT; @@ -6126,6 +6781,7 @@ CPed::GetNearestTrainDoor(CVehicle *train, CVector &doorPos) return 1; } +#ifdef GTA_TRAIN void CPed::LineUpPedWithTrain(void) { @@ -6177,6 +6833,7 @@ CPed::ExitTrain(void) { LineUpPedWithTrain(); } +#endif void CPed::ExitCar(void) @@ -6215,17 +6872,65 @@ CPed::ExitCar(void) } } +// --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 || b158_4) && !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 || b158_4) && bIsStanding && !bWasStanding) { + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_BACK); + + if (!fallAssoc) + fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FRONT); + + if (fallAssoc) { + bKnockedUpIntoAir = false; + b158_4 = false; + fallAssoc->speed = 3.0f; + if (IsPlayer()) + Say(SOUND_PED_LAND); + + } else { + firstPartialAssoc = RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_PARTIAL); + if (firstPartialAssoc && !firstPartialAssoc->IsRunning()) { + bKnockedUpIntoAir = false; + b158_4 = false; + } + } + } } void @@ -6282,13 +6987,9 @@ CPed::Fight(void) case FIGHTMOVE_KNEE: TransformToNode(touchingNodePos, PED_LOWERLEGR); break; - case FIGHTMOVE_HEADBUTT: - TransformToNode(touchingNodePos, PED_HEAD); - break; case FIGHTMOVE_PUNCHJAB: TransformToNode(touchingNodePos, PED_HANDL); break; - case FIGHTMOVE_KICK: case FIGHTMOVE_LONGKICK: case FIGHTMOVE_ROUNDHOUSE: case FIGHTMOVE_GROUNDKICK: @@ -6349,12 +7050,12 @@ CPed::Fight(void) canRoundhouse = false; punchOnly = false; canKick = true; - nextFightMove = (m_fightButtonPressure > 190 ? FIGHTMOVE_HEADBUTT : FIGHTMOVE_KNEE); + nextFightMove = (m_fightButtonPressure > 190 ? FIGHTMOVE_BODYBLOW : FIGHTMOVE_KNEE); hasShoppingBags = false; canKneeHead = true; nPlayerInComboMove = 0; } else { - nextFightMove = (m_fightButtonPressure > 120 ? FIGHTMOVE_HEADBUTT : FIGHTMOVE_KNEE); + nextFightMove = (m_fightButtonPressure > 120 ? FIGHTMOVE_BODYBLOW : FIGHTMOVE_KNEE); uint16 pedFeatures = m_pedStats->m_flags; punchOnly = pedFeatures & STAT_PUNCH_ONLY; canRoundhouse = pedFeatures & STAT_CAN_ROUNDHOUSE; @@ -6393,7 +7094,7 @@ CPed::Fight(void) && neededTurn < DEGTORAD(35.0f) && (canKick || hasShoppingBags)) { - nextFightMove = FIGHTMOVE_KICK; + nextFightMove = FIGHTMOVE_LONGKICK; if (hasShoppingBags) { nextFightMove = FIGHTMOVE_ROUNDHOUSE; } else if (canRoundhouse && CGeneral::GetRandomNumber() & 1) { @@ -6486,7 +7187,7 @@ CPed::Fight(void) if (fightingPedDist >= 1.3f) { if (fightingPedDist < 1.7f && canKick) { - nextFightMove = FIGHTMOVE_KICK; + nextFightMove = FIGHTMOVE_LONGKICK; if (canRoundhouse && CGeneral::GetRandomNumber() & 1) nextFightMove = FIGHTMOVE_ROUNDHOUSE; @@ -6713,9 +7414,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; @@ -6822,12 +7521,12 @@ CPed::FinishedWaitCB(CAnimBlendAssociation *animAssoc, void *arg) 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; } @@ -6837,7 +7536,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); } } @@ -6846,7 +7545,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); @@ -6860,7 +7559,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; @@ -6877,7 +7576,7 @@ CPed::Wait(void) CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_XPRESS_SCRATCH, 4.0f); } } else { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); SetMoveState(PEDMOVE_WALK); } break; @@ -6888,13 +7587,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) @@ -6913,7 +7612,7 @@ CPed::Wait(void) animAssoc->SetFinishCallback(FinishedWaitCB, this); m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 5000; } else { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); } } break; @@ -6942,7 +7641,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; @@ -6979,7 +7678,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; @@ -6992,7 +7691,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); @@ -7006,7 +7705,7 @@ CPed::Wait(void) TurnBody(); } else { - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); m_nWaitTimer = 0; if (m_pLookTarget && m_pLookTarget->IsPed()) { @@ -7064,15 +7763,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) { @@ -7081,7 +7780,7 @@ CPed::Wait(void) animAssoc->blendDelta = -4.0f; animAssoc->flags |= ASSOC_DELETEFADEDOUT; } - m_nWaitState = WAITSTATE_FALSE; + ClearWaitState(); } #ifdef VC_PED_PORTS else if (m_nWaitState == WAITSTATE_PLAYANIM_TAXI) { @@ -7105,13 +7804,59 @@ 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_SUN_BATHE_PRE: + case WAITSTATE_SUN_BATHE_DOWN: + case WAITSTATE_SUN_BATHE_IDLE: + case WAITSTATE_RIOT: + case WAITSTATE_FAST_FALL: + case WAITSTATE_BOMBER: + case WAITSTATE_STRIPPER: + case WAITSTATE_GROUND_ATTACK: + case WAITSTATE_LANCESITTING: + case WAITSTATE_PLAYANIM_HANDSUP_SIMPLE: + assert(0); default: break; } @@ -7686,93 +8431,18 @@ 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; } void @@ -7794,6 +8464,7 @@ CPed::HaveReachedNextPointOnRoute(float distToCountReached) return true; } +// --MIAMI: Done void CPed::Idle(void) { @@ -7815,42 +8486,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) { @@ -7864,17 +8506,11 @@ 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); } } } @@ -7889,14 +8525,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); @@ -7922,6 +8566,11 @@ CPed::SetAnimOffsetForEnterOrExitVehicle(void) { // FIX: If there were no translations on enter anims, there were overflows all over this function. + int vanBlock = CAnimManager::GetAnimationBlockIndex("van"); + CStreaming::RequestAnim(vanBlock, STREAMFLAGS_DEPENDENCY); + CStreaming::LoadAllRequestedModels(false); + CAnimManager::AddAnimBlockRef(vanBlock); + CAnimBlendHierarchy *enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, ANIM_CAR_JACKED_LHS)->hierarchy; CAnimBlendSequence *seq = enterAssoc->sequences; CAnimManager::UncompressAnimation(enterAssoc); @@ -7970,7 +8619,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) { @@ -7981,7 +8630,7 @@ CPed::SetAnimOffsetForEnterOrExitVehicle(void) vecPedVanRearDoorAnimOffset = lastFrame->translation; } } - +#ifdef GTA_TRAIN enterAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, ANIM_TRAIN_GETOUT)->hierarchy; seq = enterAssoc->sequences; CAnimManager::UncompressAnimation(enterAssoc); @@ -7993,6 +8642,7 @@ CPed::SetAnimOffsetForEnterOrExitVehicle(void) vecPedTrainDoorAnimOffset = lastFrame->translation; } } +#endif } void @@ -8198,7 +8848,11 @@ CPed::InvestigateEvent(void) 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; } @@ -8448,7 +9102,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) if ((m_nPedState == PED_FALL || m_nPedState == PED_DIE || m_nPedState == PED_DEAD) && !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; } @@ -8484,7 +9138,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) void CPed::Look(void) { - // UNUSED: This is a perfectly empty function. + TurnBody(); } bool @@ -8829,7 +9483,7 @@ CPed::MoveHeadToLook(void) } 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(); } @@ -8849,7 +9503,7 @@ CPed::MoveHeadToLook(void) bool notRocketLauncher = false; bool notTwoHanded = false; - AnimationId animToPlay = NUM_ANIMS; + AnimationId animToPlay = NUM_STD_ANIMS; if (!GetWeapon()->IsType2Handed()) notTwoHanded = true; @@ -8878,7 +9532,7 @@ 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) { @@ -8948,7 +9602,6 @@ CPed::PedAnimAlignCB(CAnimBlendAssociation *animAssoc, void *arg) bool itsLow = !!veh->bLowVehicle; #endif eDoors enterDoor; - AnimationId enterAnim; switch (ped->m_vehEnterType) { case CAR_DOOR_RF: @@ -8978,28 +9631,27 @@ CPed::PedAnimAlignCB(CAnimBlendAssociation *animAssoc, void *arg) } 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; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_IN_R); #ifdef FIX_BUGS } else if (itsLow) { - enterAnim = ANIM_CAR_GETIN_LOW_RHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_RHS); #endif } 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; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_IN_L); #ifdef FIX_BUGS } else if (itsLow) { - enterAnim = ANIM_CAR_GETIN_LOW_LHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_LHS); #endif } 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)) { @@ -9007,16 +9659,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) { @@ -9055,9 +9707,6 @@ CPed::ProcessControl(void) CColPoint foundCol; CEntity *foundEnt = nil; - if (m_nZoneLevel > LEVEL_NONE && m_nZoneLevel != CCollision::ms_collisionInMemory) - return; - int alpha = CVisibilityPlugins::GetClumpAlpha(GetClump()); if (!bFadeOut) { if (alpha < 255) { @@ -9075,6 +9724,7 @@ CPed::ProcessControl(void) bIsShooting = false; BuildPedLists(); bIsInWater = false; + bIsDrowning = false; ProcessBuoyancy(); if (m_nPedState != PED_ARRESTED) { @@ -9186,7 +9836,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 @@ -9236,17 +9886,13 @@ CPed::ProcessControl(void) float oldDestRot = CGeneral::LimitRadianAngle(m_fRotationDest); -#ifdef VC_PED_PORTS if (m_nPedState == PED_FOLLOW_PATH) { if (DotProduct(m_vecDamageNormal, GetForward()) < -0.866f && CanPedJumpThis(collidingEnt, &m_vecDamageNormal)) { SetJump(); - - // Moved break into here, for compatibility with III - break; } - // break; + break; } -#endif + if (m_pedInObjective && (m_objective == OBJECTIVE_GOTO_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT)) { @@ -9826,7 +10472,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(); @@ -9933,11 +10579,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; @@ -9997,24 +10643,27 @@ CPed::ProcessControl(void) 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(); @@ -10072,7 +10721,7 @@ CPed::ProcessControl(void) case PED_SEEK_ENTITY: case PED_PURSUE: case PED_SNIPER_MODE: - case PED_ROCKET_ODE: + case PED_ROCKET_MODE: case PED_DUMMY: case PED_FACE_PHONE: case PED_MAKE_CALL: @@ -10081,7 +10730,6 @@ CPed::ProcessControl(void) case PED_FOLLOW_ROUTE: case PED_CPR: case PED_SOLICIT: - case PED_BUY_ICECREAM: case PED_STEP_AWAY: case PED_UNKNOWN: case PED_STATES_NO_AI: @@ -10172,6 +10820,9 @@ CPed::ProcessControl(void) case PED_SEEK_IN_BOAT: SeekBoatPosition(); break; + case PED_BUY_ICECREAM: + BuyIceCream(); + break; case PED_INVESTIGATE: InvestigateEvent(); break; @@ -10192,18 +10843,23 @@ CPed::ProcessControl(void) 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) { @@ -10212,122 +10868,55 @@ 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(OBJ_50, FindPlayerPed()); + Say(SOUND_PED_CAR_JACKED); } + break; } case PED_DIE: @@ -10347,8 +10936,11 @@ CPed::ProcessControl(void) 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)) { @@ -10379,9 +10971,11 @@ CPed::ProcessControl(void) } m_pCurrentPhysSurface = nil; } - } + } else + ServiceTalking(); } +// --MIAMI: Done void CPed::SetInTheAir(void) { @@ -10400,26 +10994,52 @@ CPed::SetInTheAir(void) } +// --MIAMI: Done void CPed::RestoreHeadPosition(void) { + // TODO(Miami): This is inlined CanUseTorsoWhenLooking + bool canUseMyBody = false; + if (m_nPedState != PED_DRIVING && m_nPedState != PED_DRAG_FROM_CAR && !bIsDucking) { + if (m_animGroup != ASSOCGRP_SEXYWOMAN && m_animGroup != ASSOCGRP_WOMAN) + canUseMyBody = true; + } + if (!canUseMyBody) + m_pedIK.m_flags |= CPedIK::LOOKAROUND_HEAD_ONLY; + if (m_pedIK.RestoreLookAt()) { bIsRestoringLook = false; + canUseMyBody = false; + if (m_nPedState != PED_DRIVING && m_nPedState != PED_DRAG_FROM_CAR && !bIsDucking) { + if (m_animGroup != ASSOCGRP_SEXYWOMAN && m_animGroup != ASSOCGRP_WOMAN) + canUseMyBody = true; + } + if(canUseMyBody) + 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 @@ -10598,28 +11218,26 @@ 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; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_GETIN); } else if (isBus) { - animToPlay = ANIM_COACH_IN_R; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_IN_R); } else if (isLow) { - animToPlay = ANIM_CAR_GETIN_LOW_RHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_RHS); } else { - animToPlay = ANIM_CAR_GETIN_RHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_RHS); } } else if (isVan) { - animToPlay = ANIM_VAN_GETIN_L; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_VAN, ANIM_VAN_GETIN_L); } else if (isBus) { - animToPlay = ANIM_COACH_IN_L; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_COACH, ANIM_COACH_IN_L); } else if (isLow) { - animToPlay = ANIM_CAR_GETIN_LOW_LHS; + ped->m_pVehicleAnim = CAnimManager::AddAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_CAR_GETIN_LOW_LHS); } else { - animToPlay = 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, animToPlay); ped->m_pVehicleAnim->SetFinishCallback(PedAnimGetInCB, ped); } else { CPed *pedToDragOut = nil; @@ -10722,51 +11340,17 @@ CPed::SetJump(void) } } +// --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; } void @@ -10888,32 +11472,32 @@ CPed::PedAnimGetInCB(CAnimBlendAssociation *animAssoc, void *arg) if (veh->IsDoorMissing(enterDoor) || 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) @@ -11510,19 +12094,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) 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; @@ -11634,7 +12206,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); @@ -11910,14 +12482,14 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) } } -// 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() && GetWeaponSlot(weaponType) == 5) { if (m_storedWeapon != WEAPONTYPE_UNIDENTIFIED) { SetCurrentWeapon(m_storedWeapon); m_storedWeapon = WEAPONTYPE_UNIDENTIFIED; @@ -11927,14 +12499,14 @@ 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); @@ -12328,13 +12900,7 @@ CPed::Render(void) bRenderPedInCar && sq(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]; @@ -12343,50 +12909,8 @@ CPed::Render(void) RwFrameUpdateObjects(frame); RpAtomicRender(m_pWeaponModel); } -#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) @@ -12430,14 +12954,26 @@ CPed::ProcessObjective(void) case OBJECTIVE_FOLLOW_CAR_IN_CAR: case OBJECTIVE_FIRE_AT_OBJ_FROM_VEHICLE: case OBJECTIVE_DESTROY_OBJ: - case OBJECTIVE_23: - case OBJECTIVE_24: + case OBJECTIVE_26: + case OBJECTIVE_27: case OBJECTIVE_SET_LEADER: break; case OBJECTIVE_IDLE: - 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_TILL_SAFE: if (InVehicle()) { @@ -12515,7 +13051,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_VEHICLE, m_pMyVehicle); @@ -12567,8 +13104,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; @@ -12818,7 +13355,7 @@ CPed::ProcessObjective(void) 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); + m_pedInObjective->m_pedIK.GetComponentPosition(*(RwV3d *)&target, PED_MID); else target = m_pedInObjective->GetPosition(); @@ -13495,14 +14032,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; @@ -13532,7 +14069,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; } @@ -13565,23 +14102,21 @@ CPed::ProcessObjective(void) case OBJECTIVE_LEAVE_VEHICLE: if (CTimer::GetTimeInMilliseconds() > m_leaveCarTimer) { if (InVehicle() -#ifdef VC_PED_PORTS && (FindPlayerPed() != this || !CPad::GetPad(0)->GetAccelerate() || bBusJacked) -#endif ) { 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); } @@ -13618,6 +14153,187 @@ CPed::ProcessObjective(void) } break; } + case OBJECTIVE_USE_SEAT_ATTRACTOR: + case OBJECTIVE_USE_ATM_ATTRACTOR: + case OBJECTIVE_USE_STOP_ATTRACTOR: + case OBJECTIVE_USE_PIZZA_ATTRACTOR: + case OBJECTIVE_USE_SHELTER_ATTRACTOR: + case OBJECTIVE_USE_ICECREAM_ATTRACTOR: + 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_USE_SHELTER_ATTRACTOR) { + 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_USE_ICECREAM_ATTRACTOR) { + 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_USE_SEAT_ATTRACTOR: + if (!bTurnedAroundOnAttractor) { + ClearObjective(); + SetWaitState(WAITSTATE_SIT_DOWN, 0); + } + else { + ClearObjective(); + SetWaitState(WAITSTATE_SIT_DOWN_RVRS, 0); + } + break; + case OBJECTIVE_USE_ATM_ATTRACTOR: + ClearObjective(); + SetWaitState(WAITSTATE_USE_ATM, 0); + break; + case OBJECTIVE_USE_STOP_ATTRACTOR: + ClearObjective(); + SetObjective(OBJECTIVE_WAIT_FOR_BUS); + break; + case OBJECTIVE_USE_PIZZA_ATTRACTOR: + ClearObjective(); + m_prevObjective = OBJECTIVE_NONE; + SetObjective(OBJECTIVE_IDLE); + m_objectiveTimer = CTimer::GetTimeInMilliseconds() + m_attractor->GetHeadOfQueueWaitTime(); + break; + case OBJECTIVE_USE_SHELTER_ATTRACTOR: + m_prevObjective = OBJECTIVE_NONE; + SetObjective(OBJECTIVE_WAIT_FOR_RAIN_TO_END); + break; + case OBJECTIVE_USE_ICECREAM_ATTRACTOR: + m_prevObjective = OBJECTIVE_NONE; + SetObjective(OBJECTIVE_PURCHASE_ICECREAM); + break; + } + } + } + } + } + return; + case OBJECTIVE_WAIT_FOR_RAIN_TO_END: + SetIdle(); + if (m_attractor && CWeather::Rain < 0.2f) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + break; + case OBJECTIVE_WAIT_FOR_BUS: + 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_IDLE); + else { + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, pBus); + bDontDragMeOutCar = true; // TODO(MIAMI): check, add more flags + } + } + } + break; #endif } if (bObjectiveCompleted @@ -13685,6 +14401,7 @@ CPed::SetSeekBoatPosition(CVehicle *boat) m_nPedState = PED_SEEK_IN_BOAT; } +#ifdef GTA_TRAIN void CPed::SetExitTrain(CVehicle* train) { @@ -13702,6 +14419,7 @@ CPed::SetExitTrain(CVehicle* train) bUsesCollision = false; LineUpPedWithTrain(); } +#endif #ifdef NEW_WALK_AROUND_ALGORITHM CVector @@ -14346,10 +15064,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; @@ -14389,13 +15107,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 @@ -14424,13 +15142,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) { @@ -14438,8 +15156,7 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) m_vecDamageNormal = intersectionPoint.normal; } } - // VC code is working perfectly, but we don't want mega jumps to damage us significantly :shrug: -#if 0 // #ifdef VC_PED_PORTS + float upperSpeedLimit = 0.33f; float lowerSpeedLimit = -0.25f; float speed = m_vecMoveSpeed.Magnitude2D(); @@ -14447,7 +15164,7 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) upperSpeedLimit *= 2.0f; lowerSpeedLimit *= 1.5f; } - if (!m_ped_flagA2) { + if (!bWasStanding) { if ((speed <= upperSpeedLimit /* || (bfFlagsL >> 5) & 1 */) && m_vecMoveSpeed.z >= lowerSpeedLimit || m_pCollidingEntity == collidingEnt) { @@ -14470,27 +15187,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 @@ -14536,7 +15232,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(); @@ -14598,6 +15294,7 @@ CPed::WanderRange(void) } } +// --MIAMI: Done bool CPed::WillChat(CPed *stranger) { @@ -14614,11 +15311,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) { @@ -14644,20 +15346,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) { @@ -14732,17 +15438,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 @@ -14941,6 +15648,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()) { @@ -15053,8 +15761,9 @@ CPed::SetSolicit(uint32 time) } bool -CPed::SetFollowPath(CVector dest) +CPed::SetFollowPath(CVector dest, float radius, eMoveState state, CEntity* pFollowedPed, CEntity*, int time) { + // TODO(MIAMI): new follow if (m_nPedState == PED_FOLLOW_PATH) return false; @@ -15116,7 +15825,8 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) uint32 optedDoorNode = wantedDoorNode; bool teleportNeeded = false; bool isLow = !!veh->bLowVehicle; - if (!veh->CanPedExitCar()) { +// TODO(MIAMI): argument + if (!veh->CanPedExitCar(false)) { if (veh->pDriver && !veh->pDriver->IsPlayer()) { veh->AutoPilot.m_nCruiseSpeed = 0; veh->AutoPilot.m_nCarMission = MISSION_NONE; @@ -15189,6 +15899,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); @@ -15316,13 +16032,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); @@ -15335,7 +16051,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 { @@ -15344,7 +16060,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); @@ -15357,7 +16073,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 { @@ -15570,6 +16286,7 @@ CPed::ScanForInterestingStuff(void) } } +// --MIAMI: Done except comments uint32 CPed::ScanForThreats(void) { @@ -15582,18 +16299,25 @@ 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) { + + // TODO(Miami) + // if (m_threatEntity) + // m_threatEntity->CleanUpOldReference(&m_threatEntity); + + m_threatEntity = shooter; + m_threatEntity->RegisterReference((CEntity**)&m_threatEntity); + return CPedType::GetFlag(shooter->m_nPedType); + } } } @@ -15607,32 +16331,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; @@ -15649,7 +16347,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) { @@ -15676,8 +16374,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)) { @@ -15705,7 +16403,7 @@ CPed::ScanForThreats(void) } } } -#endif + int16 lastVehicle; CEntity* vehicles[8]; CWorld::FindObjectsInRange(ourPos, 20.0f, true, &lastVehicle, 6, vehicles, false, true, false, false, false); @@ -15719,6 +16417,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 @@ -15856,9 +16556,12 @@ CPed::SeekCar(void) if (Seek()) { if (!foundBetterPosToSeek) { if (1.5f + 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; @@ -16576,6 +17279,7 @@ CPed::SpawnFlyingComponent(int pedNode, int8 direction) return obj; } +// --MIAMI: Done void CPed::WarpPedIntoCar(CVehicle *car) { @@ -16584,7 +17288,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; @@ -16593,6 +17297,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; @@ -16628,33 +17336,11 @@ 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; @@ -16662,6 +17348,22 @@ CPed::WarpPedIntoCar(CVehicle *car) } void +CPed::SetObjective(eObjective newObj, float heading, const CVector& pos) +{ + switch (newObj) { + case OBJECTIVE_USE_SEAT_ATTRACTOR: + case OBJECTIVE_USE_ATM_ATTRACTOR: + case OBJECTIVE_USE_STOP_ATTRACTOR: + case OBJECTIVE_USE_PIZZA_ATTRACTOR: + case OBJECTIVE_USE_SHELTER_ATTRACTOR: + case OBJECTIVE_USE_ICECREAM_ATTRACTOR: + ClearPointGunAt(); + SetObjective(newObj, pos); + m_attractorHeading = heading; + } +} + +void CPed::SetObjective(eObjective newObj, CVector dest) { if (DyingOrDead()) @@ -16710,14 +17412,50 @@ CPed::SetObjective(eObjective newObj, CVector dest) break; case OBJECTIVE_GOTO_AREA_ANY_MEANS: case OBJECTIVE_GOTO_AREA_ON_FOOT: + case OBJECTIVE_USE_SEAT_ATTRACTOR: + case OBJECTIVE_USE_ATM_ATTRACTOR: + case OBJECTIVE_USE_STOP_ATTRACTOR: + case OBJECTIVE_USE_PIZZA_ATTRACTOR: + case OBJECTIVE_USE_SHELTER_ATTRACTOR: + case OBJECTIVE_USE_ICECREAM_ATTRACTOR: 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 (m_objective == OBJECTIVE_USE_ATM_ATTRACTOR) { + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (m_objective == OBJECTIVE_USE_SEAT_ATTRACTOR) { + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (m_objective == OBJECTIVE_USE_STOP_ATTRACTOR) { + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (m_objective == OBJECTIVE_USE_PIZZA_ATTRACTOR) { + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (m_objective == OBJECTIVE_USE_SHELTER_ATTRACTOR) { + bIsRunning = true; + m_distanceToCountSeekDone = m_attractor->GetDistanceToCountSeekDone(); + m_acceptableHeadingOffset = m_attractor->GetAcceptableHeading(); + } + if (m_objective == OBJECTIVE_USE_ICECREAM_ATTRACTOR) { + 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: bIsRunning = true; @@ -16742,10 +17480,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) { @@ -16761,12 +17500,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; @@ -16884,27 +17625,16 @@ 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 - - m_pVehicleAnim->SetFinishCallback(PedSetInCarCB, this); -#endif - if (IsPlayer()) - CWaterLevel::AllocateBoatWakeArray(); + // TODO(Miami): + //if (IsPlayer()) + // CWaterLevel::AllocateBoatWakeArray(); } else { if (zDiff > 4.4f) { if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) @@ -16923,6 +17653,7 @@ CPed::SetEnterCar_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) } } +// --MIAMI: Done void CPed::WanderPath(void) { @@ -16935,14 +17666,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 @@ -16955,6 +17686,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; @@ -16970,7 +17703,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) { @@ -16998,6 +17737,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; + } + } } } @@ -17213,7 +17959,7 @@ CPed::SetCarJack(CVehicle* car) 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))) @@ -17261,31 +18007,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(); @@ -17301,10 +18029,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; @@ -17315,7 +18043,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); @@ -17325,7 +18052,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 { @@ -17335,13 +18062,69 @@ CPed::SetExitBoat(CVehicle *boat) } return; } -*/ } + } SetPosition(newPos); SetMoveState(PEDMOVE_STILL); m_vecMoveSpeed = boat->m_vecMoveSpeed; -#endif - // Not there in VC. - CWaterLevel::FreeBoatWakeArray(); +} + +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_USE_ATM_ATTRACTOR, heading, pos); break; + case ATTRACTOR_SEAT: SetObjective(OBJECTIVE_USE_SEAT_ATTRACTOR, heading, pos); break; + case ATTRACTOR_STOP: SetObjective(OBJECTIVE_USE_STOP_ATTRACTOR, heading, pos); break; + case ATTRACTOR_PIZZA: SetObjective(OBJECTIVE_USE_PIZZA_ATTRACTOR, heading, pos); break; + case ATTRACTOR_SHELTER: SetObjective(OBJECTIVE_USE_SHELTER_ATTRACTOR, heading, pos); break; + case ATTRACTOR_ICECREAM: SetObjective(OBJECTIVE_USE_ICECREAM_ATTRACTOR, heading, pos); break; + default: return; + } + SetObjectiveTimer(time); + m_positionInQueue = qid; +} + +void +CPed::ClearWaitState(void) +{ + 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) { + AnimationId id; + switch (m_nWaitState) { // TODO(MIAMI): actual! + case WAITSTATE_PLAYANIM_CHAT: id = ANIM_IDLE_CHAT; break; + case WAITSTATE_SIT_DOWN: id = ANIM_SEAT_DOWN; break; + case WAITSTATE_SIT_DOWN_RVRS: id = ANIM_SEAT_DOWN2; break; + case WAITSTATE_SIT_UP: id = ANIM_SEAT_UP; break; + case WAITSTATE_SIT_IDLE: id = ANIM_SEAT_IDLE; break; + case WAITSTATE_USE_ATM: id = ANIM_ATM; break; + } + CAnimBlendAssociation* pAssoc = RpAnimBlendClumpGetAssociation(GetClump(), id); + if (pAssoc) + pAssoc->blendDelta = -8.0f; + if (m_attractor) + GetPedAttractorManager()->DeRegisterPed(this, m_attractor); + } + break; + case WAITSTATE_RIOT: + case WAITSTATE_FAST_FALL: + case WAITSTATE_BOMBER: + case WAITSTATE_STRIPPER: + case WAITSTATE_GROUND_ATTACK: + case WAITSTATE_LANCESITTING: + case WAITSTATE_PLAYANIM_HANDSUP_SIMPLE: + assert(0); + } + m_nWaitState = WAITSTATE_FALSE; } #ifdef COMPATIBLE_SAVES @@ -17380,8 +18163,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); @@ -17389,3 +18190,459 @@ 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_pPathNodesStates); i++) { + m_pPathNodesStates[i] = nil; + } + m_nPathNodes = 0; + m_nCurPathNode = 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); + StopNonPartialAnims(); + } else { + m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ((CBike*)car)->m_bikeAnimType, ANIM_BIKE_PASSENGER, 100.0f); + StopNonPartialAnims(); + } + } 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_attachRot = 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); + } + + // TODO(Miami) + // PositionAttachedPed(); +} + +// --MIAMI: Done +void +CPed::DettachPedFromEntity(void) +{ + m_attachedTo = nil; + if (m_nPedState == PED_DIE) { + m_pCollidingEntity = m_attachedTo; + ApplyMoveForce(m_attachedTo->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_VEHICLE) { + 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); + } + } +} + +void +CPed::DriveVehicle(void) +{ + if (bOffscreen) + return; + + CVehicle *veh = m_pMyVehicle; + if (veh->IsBike()) { + + // TODO(Miami): Bikes + 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); + } + } +} + +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(); +} |