re3/src/peds/PlayerPed.cpp

2237 lines
70 KiB
C++
Raw Normal View History

2020-04-09 18:50:24 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
#include "RwHelper.h"
2020-04-09 18:50:24 +00:00
#include "PlayerPed.h"
#include "Wanted.h"
#include "Fire.h"
#include "DMAudio.h"
#include "Pad.h"
#include "Camera.h"
#include "WeaponEffects.h"
#include "ModelIndices.h"
#include "World.h"
#include "RpAnimBlend.h"
#include "AnimBlendAssociation.h"
#include "General.h"
#include "Pools.h"
#include "Darkel.h"
#include "CarCtrl.h"
2020-05-15 14:30:25 +00:00
#include "MBlur.h"
#include "Streaming.h"
#include "Population.h"
#include "Script.h"
#include "Replay.h"
#include "PedPlacement.h"
2020-04-09 18:50:24 +00:00
#define PAD_MOVE_TO_GAME_WORLD_MOVE 60.0f
bool CPlayerPed::bDontAllowWeaponChange;
2020-05-02 15:02:17 +00:00
const uint32 CPlayerPed::nSaveStructSize =
#ifdef COMPATIBLE_SAVES
2020-10-17 15:50:16 +00:00
1752;
2020-05-02 15:02:17 +00:00
#else
sizeof(CPlayerPed);
#endif
int32 idleAnimBlockIndex;
CPad*
GetPadFromPlayer(CPlayerPed*)
{
return CPad::GetPad(0);
}
2020-04-09 18:50:24 +00:00
CPlayerPed::~CPlayerPed()
{
delete m_pWanted;
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1)
{
m_fMoveSpeed = 0.0f;
SetModelIndex(MI_PLAYER);
2020-06-06 10:31:09 +00:00
#ifdef FIX_BUGS
m_fCurrentStamina = m_fMaxStamina = 150.0f;
#endif
2020-04-09 18:50:24 +00:00
SetInitialState();
m_pWanted = new CWanted();
m_pWanted->Initialise();
m_pArrestingCop = nil;
m_currentWeapon = WEAPONTYPE_UNARMED;
2020-06-03 13:16:31 +00:00
m_nSelectedWepSlot = 0;
2020-04-09 18:50:24 +00:00
m_nSpeedTimer = 0;
m_bSpeedTimerFlag = false;
SetWeaponLockOnTarget(nil);
2020-05-23 15:04:33 +00:00
SetPedState(PED_IDLE);
2020-06-06 10:31:09 +00:00
#ifndef FIX_BUGS
m_fCurrentStamina = m_fMaxStamina = 150.0f;
#endif
2020-04-09 18:50:24 +00:00
m_fStaminaProgress = 0.0f;
m_nEvadeAmount = 0;
2020-05-15 14:30:25 +00:00
m_pEvadingFrom = nil;
2020-04-15 05:03:53 +00:00
m_nHitAnimDelayTimer = 0;
m_fAttackButtonCounter = 0.0f;
2020-04-09 18:50:24 +00:00
m_bHaveTargetSelected = false;
m_bHasLockOnTarget = false;
m_bCanBeDamaged = true;
m_bNoPosForMeleeAttack = false;
2020-04-09 18:50:24 +00:00
m_fWalkAngle = 0.0f;
m_fFPSMoveHeading = 0.0f;
2020-05-15 14:30:25 +00:00
m_pMinigunTopAtomic = nil;
m_fGunSpinSpeed = 0.0;
m_fGunSpinAngle = 0.0;
m_nPadDownPressedInMilliseconds = 0;
2020-04-09 18:50:24 +00:00
m_nTargettableObjects[0] = m_nTargettableObjects[1] = m_nTargettableObjects[2] = m_nTargettableObjects[3] = -1;
unk1 = false;
2020-04-09 18:50:24 +00:00
for (int i = 0; i < 6; i++) {
m_vecSafePos[i] = CVector(0.0f, 0.0f, 0.0f);
m_pPedAtSafePos[i] = nil;
2020-06-15 20:43:20 +00:00
m_pMeleeList[i] = nil;
2020-04-09 18:50:24 +00:00
}
m_nAttackDirToCheck = 0;
2020-08-16 14:10:59 +00:00
m_nLastBusFareCollected = 0;
idleAnimBlockIndex = CAnimManager::GetAnimationBlockIndex("playidles");
2020-04-09 18:50:24 +00:00
}
// --MIAMI: Done
void
CPlayerPed::ClearWeaponTarget()
2020-04-09 18:50:24 +00:00
{
if (m_nPedType == PEDTYPE_PLAYER1) {
SetWeaponLockOnTarget(nil);
2020-04-09 18:50:24 +00:00
TheCamera.ClearPlayerWeaponMode();
CWeaponEffects::ClearCrossHair();
}
ClearPointGunAt();
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::SetWantedLevel(int32 level)
{
m_pWanted->SetWantedLevel(level);
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::SetWantedLevelNoDrop(int32 level)
{
m_pWanted->SetWantedLevelNoDrop(level);
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::MakeObjectTargettable(int32 handle)
{
for (int i = 0; i < ARRAY_SIZE(m_nTargettableObjects); i++) {
if (CPools::GetObjectPool()->GetAt(m_nTargettableObjects[i]) == nil) {
2020-04-09 18:50:24 +00:00
m_nTargettableObjects[i] = handle;
return;
}
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
// I don't know the actual purpose of parameter
void
CPlayerPed::AnnoyPlayerPed(bool annoyedByPassingEntity)
{
if (m_pedStats->m_temper < 52) {
m_pedStats->m_temper++;
} else if (annoyedByPassingEntity && m_pedStats->m_temper < 55) {
m_pedStats->m_temper++;
} else if (annoyedByPassingEntity) {
m_pedStats->m_temper = 46;
2020-04-09 18:50:24 +00:00
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::ClearAdrenaline(void)
{
if (m_bAdrenalineActive && m_nAdrenalineTime != 0) {
m_nAdrenalineTime = 0;
CTimer::SetTimeScale(1.0f);
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
CPlayerInfo *
CPlayerPed::GetPlayerInfoForThisPlayerPed()
{
if (CWorld::Players[0].m_pPed == this)
return &CWorld::Players[0];
return nil;
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::SetupPlayerPed(int32 index)
{
CPlayerPed *player = new CPlayerPed();
CWorld::Players[index].m_pPed = player;
2020-04-18 22:20:14 +00:00
#ifdef FIX_BUGS
2020-04-18 20:50:37 +00:00
player->RegisterReference((CEntity**)&CWorld::Players[index].m_pPed);
2020-04-18 22:20:14 +00:00
#endif
2020-04-09 18:50:24 +00:00
player->SetOrientation(0.0f, 0.0f, 0.0f);
CWorld::Add(player);
player->m_wepAccuracy = 100;
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::DeactivatePlayerPed(int32 index)
{
CWorld::Remove(CWorld::Players[index].m_pPed);
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::ReactivatePlayerPed(int32 index)
{
CWorld::Add(CWorld::Players[index].m_pPed);
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::UseSprintEnergy(void)
{
if (m_fCurrentStamina > -150.0f && !CWorld::Players[CWorld::PlayerInFocus].m_bInfiniteSprint
&& !m_bAdrenalineActive) {
m_fCurrentStamina = m_fCurrentStamina - CTimer::GetTimeStep();
m_fStaminaProgress = m_fStaminaProgress + CTimer::GetTimeStep();
}
if (m_fStaminaProgress >= 500.0f) {
m_fStaminaProgress = 0;
if (m_fMaxStamina < 1000.0f)
m_fMaxStamina += 10.0f;
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
2020-05-15 14:30:25 +00:00
CPlayerPed::MakeChangesForNewWeapon(eWeaponType weapon)
2020-04-09 18:50:24 +00:00
{
if (m_nPedState == PED_SNIPER_MODE) {
RestorePreviousState();
TheCamera.ClearPlayerWeaponMode();
}
SetCurrentWeapon(weapon);
2020-05-16 12:07:09 +00:00
m_nSelectedWepSlot = m_currentWeapon;
2020-04-09 18:50:24 +00:00
2020-04-19 16:34:08 +00:00
GetWeapon()->m_nAmmoInClip = Min(GetWeapon()->m_nAmmoTotal, CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nAmountofAmmunition);
2020-04-09 18:50:24 +00:00
if (!(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAim))
ClearWeaponTarget();
2020-05-16 12:07:09 +00:00
// WEAPONTYPE_SNIPERRIFLE? Wut?
CAnimBlendAssociation* weaponAnim = RpAnimBlendClumpGetAssociation(GetClump(), GetPrimaryFireAnim(CWeaponInfo::GetWeaponInfo(WEAPONTYPE_SNIPERRIFLE)));
2020-04-09 18:50:24 +00:00
if (weaponAnim) {
weaponAnim->SetRun();
weaponAnim->flags |= ASSOC_FADEOUTWHENDONE;
}
TheCamera.ClearPlayerWeaponMode();
}
// --MIAMI: Done
2020-05-15 14:30:25 +00:00
void
CPlayerPed::MakeChangesForNewWeapon(int32 slot)
{
if(slot != -1)
MakeChangesForNewWeapon(m_weapons[slot].m_eWeaponType);
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::ReApplyMoveAnims(void)
{
static AnimationId moveAnims[] = { ANIM_WALK, ANIM_RUN, ANIM_SPRINT, ANIM_IDLE_STANCE, ANIM_WALK_START };
for(int i = 0; i < ARRAY_SIZE(moveAnims); i++) {
CAnimBlendAssociation *curMoveAssoc = RpAnimBlendClumpGetAssociation(GetClump(), moveAnims[i]);
if (curMoveAssoc) {
if (CGeneral::faststrcmp(CAnimManager::GetAnimAssociation(m_animGroup, moveAnims[i])->hierarchy->name, curMoveAssoc->hierarchy->name)) {
2020-04-09 18:50:24 +00:00
CAnimBlendAssociation *newMoveAssoc = CAnimManager::AddAnimation(GetClump(), m_animGroup, moveAnims[i]);
newMoveAssoc->blendDelta = curMoveAssoc->blendDelta;
newMoveAssoc->blendAmount = curMoveAssoc->blendAmount;
curMoveAssoc->blendDelta = -1000.0f;
curMoveAssoc->flags |= ASSOC_DELETEFADEDOUT;
}
}
}
}
2020-05-15 14:30:25 +00:00
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::SetInitialState(void)
{
2020-05-15 14:30:25 +00:00
m_nDrunkenness = 0;
m_nFadeDrunkenness = 0;
CMBlur::ClearDrunkBlur();
m_nDrunkCountdown = 0;
2020-04-09 18:50:24 +00:00
m_bAdrenalineActive = false;
m_nAdrenalineTime = 0;
2020-05-15 14:30:25 +00:00
CTimer::SetTimeScale(1.0f);
2020-04-09 18:50:24 +00:00
m_pSeekTarget = nil;
2020-05-15 14:30:25 +00:00
m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f);
2020-11-13 12:14:22 +00:00
m_fleeFromPos = CVector2D(0.0f, 0.0f);
2020-04-09 18:50:24 +00:00
m_fleeFrom = nil;
m_fleeTimer = 0;
m_objective = OBJECTIVE_NONE;
m_prevObjective = OBJECTIVE_NONE;
bUsesCollision = true;
ClearAimFlag();
ClearLookFlag();
bIsPointingGunAt = false;
bRenderPedInCar = true;
if (m_pFire)
m_pFire->Extinguish();
2020-05-15 14:30:25 +00:00
2020-04-09 18:50:24 +00:00
RpAnimBlendClumpRemoveAllAssociations(GetClump());
2020-05-23 15:04:33 +00:00
SetPedState(PED_IDLE);
2020-04-09 18:50:24 +00:00
SetMoveState(PEDMOVE_STILL);
m_nLastPedState = PED_NONE;
m_animGroup = ASSOCGRP_PLAYER;
m_fMoveSpeed = 0.0f;
m_nSelectedWepSlot = WEAPONTYPE_UNARMED;
m_nEvadeAmount = 0;
m_pEvadingFrom = nil;
bIsPedDieAnimPlaying = false;
SetRealMoveAnim();
m_bCanBeDamaged = true;
m_pedStats->m_temper = 50;
m_fWalkAngle = 0.0f;
2020-05-15 14:30:25 +00:00
if (m_attachedTo && !bUsesCollision)
bUsesCollision = true;
m_attachedTo = nil;
m_attachWepAmmo = 0;
2020-04-09 18:50:24 +00:00
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::SetRealMoveAnim(void)
{
CAnimBlendAssociation *curWalkAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WALK);
CAnimBlendAssociation *curRunAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN);
CAnimBlendAssociation *curSprintAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_SPRINT);
CAnimBlendAssociation *curWalkStartAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WALK_START);
CAnimBlendAssociation *curIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_STANCE);
CAnimBlendAssociation *curRunStopAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN_STOP);
CAnimBlendAssociation *curRunStopRAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN_STOP_R);
if (bResetWalkAnims) {
if (curWalkAssoc)
curWalkAssoc->SetCurrentTime(0.0f);
if (curRunAssoc)
curRunAssoc->SetCurrentTime(0.0f);
if (curSprintAssoc)
curSprintAssoc->SetCurrentTime(0.0f);
bResetWalkAnims = false;
}
if (!curIdleAssoc)
curIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_TIRED);
if (!curIdleAssoc)
curIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE);
if (!curIdleAssoc)
2020-12-16 20:28:25 +00:00
curIdleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_MELEE_IDLE_FIGHTMODE);
2020-04-09 18:50:24 +00:00
if (!((curRunStopAssoc && curRunStopAssoc->IsRunning()) || (curRunStopRAssoc && curRunStopRAssoc->IsRunning()))) {
2020-04-09 18:50:24 +00:00
if (curRunStopAssoc && curRunStopAssoc->blendDelta >= 0.0f || curRunStopRAssoc && curRunStopRAssoc->blendDelta >= 0.0f) {
if (curRunStopAssoc) {
curRunStopAssoc->flags |= ASSOC_DELETEFADEDOUT;
curRunStopAssoc->blendAmount = 1.0f;
curRunStopAssoc->blendDelta = -8.0f;
} else if (curRunStopRAssoc) {
curRunStopRAssoc->flags |= ASSOC_DELETEFADEDOUT;
curRunStopRAssoc->blendAmount = 1.0f;
curRunStopRAssoc->blendDelta = -8.0f;
}
RestoreHeadingRate();
if (!curIdleAssoc) {
2020-06-20 17:26:27 +00:00
if (m_fCurrentStamina < 0.0f && !bIsAimingGun && !CWorld::TestSphereAgainstWorld(GetPosition(), 0.0f,
2020-04-09 18:50:24 +00:00
nil, true, false, false, false, false, false)) {
curIdleAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 8.0f);
} else {
curIdleAssoc = CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 8.0f);
}
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(2500, 4000);
}
curIdleAssoc->blendAmount = 0.0f;
curIdleAssoc->blendDelta = 8.0f;
} else if (m_fMoveSpeed == 0.0f && !curSprintAssoc) {
if (!curIdleAssoc) {
2020-06-20 17:26:27 +00:00
if (m_fCurrentStamina < 0.0f && !bIsAimingGun && !CWorld::TestSphereAgainstWorld(GetPosition(), 0.0f,
2020-04-09 18:50:24 +00:00
nil, true, false, false, false, false, false)) {
curIdleAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f);
} else {
curIdleAssoc = CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 4.0f);
}
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(2500, 4000);
}
2020-06-20 17:26:27 +00:00
if ((m_fCurrentStamina > 0.0f || bIsAimingGun) && curIdleAssoc->animId == ANIM_IDLE_TIRED) {
2020-04-09 18:50:24 +00:00
CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 4.0f);
} else if (m_nPedState != PED_FIGHT) {
2020-06-20 17:26:27 +00:00
if (m_fCurrentStamina < 0.0f && !bIsAimingGun && curIdleAssoc->animId != ANIM_IDLE_TIRED
2020-04-09 18:50:24 +00:00
&& !CWorld::TestSphereAgainstWorld(GetPosition(), 0.0f, nil, true, false, false, false, false, false)) {
CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f);
} else if (curIdleAssoc->animId != ANIM_IDLE_STANCE) {
CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 4.0f);
}
}
m_nMoveState = PEDMOVE_STILL;
2020-04-09 18:50:24 +00:00
} else {
if (curIdleAssoc) {
if (curWalkStartAssoc) {
curWalkStartAssoc->blendAmount = 1.0f;
curWalkStartAssoc->blendDelta = 0.0f;
} else {
curWalkStartAssoc = CAnimManager::AddAnimation(GetClump(), m_animGroup, ANIM_WALK_START);
}
if (curWalkAssoc)
curWalkAssoc->SetCurrentTime(0.0f);
if (curRunAssoc)
curRunAssoc->SetCurrentTime(0.0f);
delete curIdleAssoc;
delete RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_TIRED);
CAnimBlendAssociation *fightIdleAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE);
if (!fightIdleAnim)
2020-12-16 20:28:25 +00:00
fightIdleAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_MELEE_IDLE_FIGHTMODE);
delete fightIdleAnim;
2020-04-09 18:50:24 +00:00
delete curSprintAssoc;
curSprintAssoc = nil;
m_nMoveState = PEDMOVE_WALK;
}
if (curRunStopAssoc) {
delete curRunStopAssoc;
RestoreHeadingRate();
}
if (curRunStopRAssoc) {
delete curRunStopRAssoc;
RestoreHeadingRate();
}
if (!curWalkAssoc) {
curWalkAssoc = CAnimManager::AddAnimation(GetClump(), m_animGroup, ANIM_WALK);
curWalkAssoc->blendAmount = 0.0f;
}
if (!curRunAssoc) {
curRunAssoc = CAnimManager::AddAnimation(GetClump(), m_animGroup, ANIM_RUN);
curRunAssoc->blendAmount = 0.0f;
}
if (curWalkStartAssoc && !(curWalkStartAssoc->IsRunning())) {
delete curWalkStartAssoc;
curWalkStartAssoc = nil;
curWalkAssoc->SetRun();
curRunAssoc->SetRun();
}
if (m_nMoveState == PEDMOVE_SPRINT) {
if (m_fCurrentStamina < 0.0f && (m_fCurrentStamina <= -150.0f || !curSprintAssoc || curSprintAssoc->blendDelta < 0.0f))
m_nMoveState = PEDMOVE_STILL;
if (curWalkStartAssoc)
m_nMoveState = PEDMOVE_STILL;
}
if (curSprintAssoc && (m_nMoveState != PEDMOVE_SPRINT || m_fMoveSpeed < 0.4f)) {
// Stop sprinting in various conditions
2020-04-09 18:50:24 +00:00
if (curSprintAssoc->blendAmount == 0.0f) {
curSprintAssoc->blendDelta = -1000.0f;
curSprintAssoc->flags |= ASSOC_DELETEFADEDOUT;
} else if (curSprintAssoc->blendDelta >= 0.0f || curSprintAssoc->blendAmount >= 0.8f) {
if (m_fMoveSpeed < 0.4f) {
AnimationId runStopAnim;
2020-05-17 17:36:48 +00:00
if (curSprintAssoc->GetProgress() < 0.5) // double
2020-04-09 18:50:24 +00:00
runStopAnim = ANIM_RUN_STOP;
else
runStopAnim = ANIM_RUN_STOP_R;
CAnimBlendAssociation* newRunStopAssoc = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, runStopAnim);
newRunStopAssoc->blendAmount = 1.0f;
newRunStopAssoc->SetDeleteCallback(RestoreHeadingRateCB, this);
m_headingRate = 0.0f;
curSprintAssoc->flags |= ASSOC_DELETEFADEDOUT;
curSprintAssoc->blendDelta = -1000.0f;
curWalkAssoc->flags &= ~ASSOC_RUNNING;
curWalkAssoc->blendAmount = 0.0f;
curWalkAssoc->blendDelta = 0.0f;
curRunAssoc->flags &= ~ASSOC_RUNNING;
curRunAssoc->blendAmount = 0.0f;
curRunAssoc->blendDelta = 0.0f;
} else if (curSprintAssoc->blendDelta >= 0.0f) {
2020-04-09 18:50:24 +00:00
// Stop sprinting when tired
curSprintAssoc->flags |= ASSOC_DELETEFADEDOUT;
curSprintAssoc->blendDelta = -1.0f;
curRunAssoc->blendDelta = 1.0f;
}
} else if (m_fMoveSpeed < 1.0f) {
curSprintAssoc->blendDelta = -8.0f;
curRunAssoc->blendDelta = 8.0f;
}
2020-04-09 18:50:24 +00:00
} else if (curWalkStartAssoc) {
// Walk start and walk/run shouldn't run at the same time
2020-04-09 18:50:24 +00:00
curWalkAssoc->flags &= ~ASSOC_RUNNING;
curRunAssoc->flags &= ~ASSOC_RUNNING;
curWalkAssoc->blendAmount = 0.0f;
curRunAssoc->blendAmount = 0.0f;
} else if (m_nMoveState == PEDMOVE_SPRINT) {
if (curSprintAssoc) {
// We have anim, do it
2020-04-09 18:50:24 +00:00
if (curSprintAssoc->blendDelta < 0.0f) {
curSprintAssoc->blendDelta = 2.0f;
curRunAssoc->blendDelta = -2.0f;
}
} else {
// Transition between run-sprint
2020-04-09 18:50:24 +00:00
curWalkAssoc->blendAmount = 0.0f;
curRunAssoc->blendAmount = 1.0f;
curSprintAssoc = CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_SPRINT, 2.0f);
}
UseSprintEnergy();
} else {
if (m_fMoveSpeed < 1.0f) {
curWalkAssoc->blendAmount = 1.0f;
curRunAssoc->blendAmount = 0.0f;
m_nMoveState = PEDMOVE_WALK;
} else if (m_fMoveSpeed < 2.0f) {
curWalkAssoc->blendAmount = 2.0f - m_fMoveSpeed;
curRunAssoc->blendAmount = m_fMoveSpeed - 1.0f;
m_nMoveState = PEDMOVE_RUN;
} else {
curWalkAssoc->blendAmount = 0.0f;
curRunAssoc->blendAmount = 1.0f;
m_nMoveState = PEDMOVE_RUN;
}
curWalkAssoc->blendDelta = 0.0f;
curRunAssoc->blendDelta = 0.0f;
2020-04-09 18:50:24 +00:00
}
}
}
if (m_bAdrenalineActive) {
if (CTimer::GetTimeInMilliseconds() > m_nAdrenalineTime) {
m_bAdrenalineActive = false;
CTimer::SetTimeScale(1.0f);
if (curWalkStartAssoc)
curWalkStartAssoc->speed = 1.0f;
if (curWalkAssoc)
curWalkAssoc->speed = 1.0f;
if (curRunAssoc)
curRunAssoc->speed = 1.0f;
if (curSprintAssoc)
curSprintAssoc->speed = 1.0f;
} else {
CTimer::SetTimeScale(1.0f / 3);
if (curWalkStartAssoc)
curWalkStartAssoc->speed = 2.0f;
if (curWalkAssoc)
curWalkAssoc->speed = 2.0f;
if (curRunAssoc)
curRunAssoc->speed = 2.0f;
if (curSprintAssoc)
curSprintAssoc->speed = 2.0f;
}
} else if (curSprintAssoc) {
if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FIXED) {
curSprintAssoc->speed = 0.7f;
} else
curSprintAssoc->speed = 1.0f;
2020-04-09 18:50:24 +00:00
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::RestoreSprintEnergy(float restoreSpeed)
{
if (m_fCurrentStamina < m_fMaxStamina)
m_fCurrentStamina += restoreSpeed * CTimer::GetTimeStep() * 0.5f;
}
// --MIAMI: Done
float
2020-04-09 18:50:24 +00:00
CPlayerPed::DoWeaponSmoothSpray(void)
{
if (m_nPedState == PED_ATTACK && !m_pPointGunAt) {
CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
switch (GetWeapon()->m_eWeaponType) {
case WEAPONTYPE_GOLFCLUB:
case WEAPONTYPE_NIGHTSTICK:
case WEAPONTYPE_BASEBALLBAT:
if (GetFireAnimGround(weaponInfo, false) && RpAnimBlendClumpGetAssociation(GetClump(), GetFireAnimGround(weaponInfo, false)))
return PI / 176.f;
else
return -1.0f;
case WEAPONTYPE_CHAINSAW:
if (GetMeleeStartAnim(weaponInfo) && RpAnimBlendClumpGetAssociation(GetClump(), GetMeleeStartAnim(weaponInfo)))
return PI / 128.0f;
else if (GetFireAnimGround(weaponInfo, false) && RpAnimBlendClumpGetAssociation(GetClump(), GetFireAnimGround(weaponInfo, false)))
return PI / 176.f;
else
return PI / 80.f;
case WEAPONTYPE_PYTHON:
return PI / 112.f;
case WEAPONTYPE_SHOTGUN:
case WEAPONTYPE_SPAS12_SHOTGUN:
case WEAPONTYPE_STUBBY_SHOTGUN:
return PI / 112.f;
case WEAPONTYPE_UZI:
case WEAPONTYPE_MP5:
return PI / 112.f;
case WEAPONTYPE_M4:
case WEAPONTYPE_RUGER:
return PI / 112.f;
case WEAPONTYPE_FLAMETHROWER:
return PI / 80.f;
case WEAPONTYPE_M60:
case WEAPONTYPE_MINIGUN:
case WEAPONTYPE_HELICANNON:
return PI / 176.f;
default:
return -1.0f;
}
} else if (bIsDucking)
return PI / 112.f;
else
return -1.0f;
2020-04-09 18:50:24 +00:00
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::DoStuffToGoOnFire(void)
{
if (m_nPedState == PED_SNIPER_MODE)
TheCamera.ClearPlayerWeaponMode();
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
bool
CPlayerPed::DoesTargetHaveToBeBroken(CVector target, CWeapon *weaponUsed)
{
CVector distVec = target - GetPosition();
if (distVec.Magnitude() > CWeaponInfo::GetWeaponInfo(weaponUsed->m_eWeaponType)->m_fRange)
return true;
return false;
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
// Cancels landing anim while running & jumping? I think
void
CPlayerPed::RunningLand(CPad *padUsed)
{
CAnimBlendAssociation *landAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_LAND);
if (landAssoc && landAssoc->currentTime == 0.0f && m_fMoveSpeed > 1.5f
&& padUsed && (padUsed->GetPedWalkLeftRight() != 0.0f || padUsed->GetPedWalkUpDown() != 0.0f)) {
landAssoc->blendDelta = -1000.0f;
landAssoc->flags |= ASSOC_DELETEFADEDOUT;
CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_JUMP_LAND)->SetFinishCallback(FinishJumpCB, this);
if (m_nPedState == PED_JUMP)
RestorePreviousState();
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
bool
CPlayerPed::IsThisPedAnAimingPriority(CPed *suspect)
2020-04-09 18:50:24 +00:00
{
if (!suspect->bIsPlayerFriend)
return true;
2020-04-09 18:50:24 +00:00
if (suspect->m_pPointGunAt == this)
return true;
switch (suspect->m_objective) {
case OBJECTIVE_KILL_CHAR_ON_FOOT:
case OBJECTIVE_KILL_CHAR_ANY_MEANS:
if (suspect->m_pedInObjective == this)
return true;
break;
default:
break;
}
return suspect->m_nPedState == PED_ABSEIL;
2020-04-09 18:50:24 +00:00
}
2020-06-20 17:26:27 +00:00
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::PlayerControlSniper(CPad *padUsed)
{
ProcessWeaponSwitch(padUsed);
TheCamera.PlayerExhaustion = (1.0f - (m_fCurrentStamina - -150.0f) / 300.0f) * 0.9f + 0.1f;
if (padUsed->DuckJustDown() && !bIsDucking && m_nMoveState != PEDMOVE_SPRINT) {
bCrouchWhenShooting = true;
SetDuck(60000, true);
} else if (bIsDucking && (padUsed->DuckJustDown() || m_nMoveState == PEDMOVE_SPRINT)) {
ClearDuck(true);
bCrouchWhenShooting = false;
}
2020-06-20 17:26:27 +00:00
if (!padUsed->GetTarget() && !m_attachedTo) {
2020-04-09 18:50:24 +00:00
RestorePreviousState();
TheCamera.ClearPlayerWeaponMode();
return;
2020-04-09 18:50:24 +00:00
}
2020-06-20 17:26:27 +00:00
int firingRate = GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE ? 333 : 266;
if (padUsed->WeaponJustDown() && CTimer::GetTimeInMilliseconds() > GetWeapon()->m_nTimer) {
2020-04-09 18:50:24 +00:00
CVector firePos(0.0f, 0.0f, 0.6f);
firePos = GetMatrix() * firePos;
GetWeapon()->Fire(this, &firePos);
2020-06-20 17:26:27 +00:00
m_nPadDownPressedInMilliseconds = CTimer::GetTimeInMilliseconds();
} else if (CTimer::GetTimeInMilliseconds() > m_nPadDownPressedInMilliseconds + firingRate &&
CTimer::GetTimeInMilliseconds() - CTimer::GetTimeStepInMilliseconds() < m_nPadDownPressedInMilliseconds + firingRate && padUsed->GetWeapon()) {
if (GetWeapon()->m_nAmmoTotal > 0) {
DMAudio.PlayFrontEndSound(SOUND_WEAPON_AK47_BULLET_ECHO, GetWeapon()->m_eWeaponType);
}
2020-04-09 18:50:24 +00:00
}
2020-05-17 17:36:48 +00:00
GetWeapon()->Update(m_audioEntityId, nil);
2020-04-09 18:50:24 +00:00
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
// I think R* also used goto in here.
void
CPlayerPed::ProcessWeaponSwitch(CPad *padUsed)
{
2020-05-15 14:30:25 +00:00
if (CDarkel::FrenzyOnGoing() || m_attachedTo)
2020-04-09 18:50:24 +00:00
goto switchDetectDone;
if (!m_pPointGunAt && !bDontAllowWeaponChange && GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR) {
2020-05-15 14:30:25 +00:00
if (padUsed->CycleWeaponRightJustDown()) {
2020-04-09 18:50:24 +00:00
2020-05-15 14:30:25 +00:00
if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON_RUNABOUT
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER_RUNABOUT
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER_RUNABOUT
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_CAMERA) {
2020-04-09 18:50:24 +00:00
2020-05-15 14:30:25 +00:00
for (m_nSelectedWepSlot = m_currentWeapon + 1; m_nSelectedWepSlot < TOTAL_WEAPON_SLOTS; ++m_nSelectedWepSlot) {
if (HasWeaponSlot(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) {
goto spentAmmoCheck;
}
2020-04-09 18:50:24 +00:00
}
2020-05-15 14:30:25 +00:00
m_nSelectedWepSlot = 0;
2020-04-09 18:50:24 +00:00
}
2020-05-15 14:30:25 +00:00
} else if (padUsed->CycleWeaponLeftJustDown()) {
if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_CAMERA) {
2020-04-09 18:50:24 +00:00
2020-05-15 14:30:25 +00:00
for (m_nSelectedWepSlot = m_currentWeapon - 1; ; --m_nSelectedWepSlot) {
if (m_nSelectedWepSlot < 0)
2020-05-16 12:07:09 +00:00
m_nSelectedWepSlot = TOTAL_WEAPON_SLOTS - 1;
if (m_nSelectedWepSlot == 0)
break;
2020-04-09 18:50:24 +00:00
2020-05-15 14:30:25 +00:00
if (HasWeaponSlot(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) {
break;
}
2020-04-09 18:50:24 +00:00
}
}
}
2020-05-15 14:30:25 +00:00
}
spentAmmoCheck:
if (CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_eWeaponFire != WEAPON_FIRE_MELEE
2020-05-23 23:59:30 +00:00
&& (!padUsed->GetWeapon() || GetWeapon()->m_eWeaponType != WEAPONTYPE_MINIGUN)) {
2020-05-15 14:30:25 +00:00
if (GetWeapon()->m_nAmmoTotal <= 0) {
if (TheCamera.PlayerWeaponMode.Mode == CCam::MODE_M16_1STPERSON
|| TheCamera.PlayerWeaponMode.Mode == CCam::MODE_SNIPER
|| TheCamera.PlayerWeaponMode.Mode == CCam::MODE_ROCKETLAUNCHER)
return;
2020-04-09 18:50:24 +00:00
if (GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR
|| GetWeapon(2).m_eWeaponType != WEAPONTYPE_DETONATOR_GRENADE)
m_nSelectedWepSlot = m_currentWeapon - 1;
else
m_nSelectedWepSlot = 2;
2020-05-15 14:30:25 +00:00
for (; m_nSelectedWepSlot >= 0; --m_nSelectedWepSlot) {
2020-05-16 12:07:09 +00:00
// BUG: m_nSelectedWepSlot and GetWeapon(..) takes slot in VC but they compared them against weapon types in whole condition! jeez
2020-05-16 12:07:09 +00:00
#ifdef FIX_BUGS
if (m_nSelectedWepSlot == 1 || GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0 && m_nSelectedWepSlot != 2) {
2020-05-16 12:07:09 +00:00
#else
if (m_nSelectedWepSlot == WEAPONTYPE_BASEBALLBAT && GetWeapon(WEAPONTYPE_BASEBALLBAT).m_eWeaponType == WEAPONTYPE_BASEBALLBAT
|| GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0
&& m_nSelectedWepSlot != WEAPONTYPE_MOLOTOV && m_nSelectedWepSlot != WEAPONTYPE_GRENADE && m_nSelectedWepSlot != WEAPONTYPE_TEARGAS) {
2020-05-16 12:07:09 +00:00
#endif
goto switchDetectDone;
2020-04-09 18:50:24 +00:00
}
}
m_nSelectedWepSlot = 0;
2020-04-09 18:50:24 +00:00
}
}
switchDetectDone:
if (m_nSelectedWepSlot != m_currentWeapon) {
if (m_nPedState != PED_ATTACK && m_nPedState != PED_AIM_GUN && m_nPedState != PED_FIGHT)
2020-05-15 14:30:25 +00:00
RemoveWeaponAnims(m_currentWeapon, -1000.0f);
2020-04-09 18:50:24 +00:00
MakeChangesForNewWeapon(m_nSelectedWepSlot);
}
}
2020-06-20 14:30:28 +00:00
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::PlayerControlM16(CPad *padUsed)
{
ProcessWeaponSwitch(padUsed);
TheCamera.PlayerExhaustion = (1.0f - (m_fCurrentStamina - -150.0f) / 300.0f) * 0.9f + 0.1f;
if (padUsed->DuckJustDown() && !bIsDucking && m_nMoveState != PEDMOVE_SPRINT) {
bCrouchWhenShooting = true;
SetDuck(60000, true);
} else if (bIsDucking && (padUsed->DuckJustDown() || m_nMoveState == PEDMOVE_SPRINT)) {
ClearDuck(true);
bCrouchWhenShooting = false;
}
if (!padUsed->GetTarget() && !m_attachedTo) {
2020-04-09 18:50:24 +00:00
RestorePreviousState();
TheCamera.ClearPlayerWeaponMode();
}
2020-06-20 14:30:28 +00:00
if (padUsed->GetWeapon() && CTimer::GetTimeInMilliseconds() > GetWeapon()->m_nTimer) {
if (GetWeapon()->m_eWeaponState == WEAPONSTATE_OUT_OF_AMMO) {
DMAudio.PlayFrontEndSound(SOUND_WEAPON_SNIPER_SHOT_NO_ZOOM, 0.f);
GetWeapon()->m_nTimer = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nFiringRate + CTimer::GetTimeInMilliseconds();
} else {
CVector firePos(0.0f, 0.0f, 0.6f);
firePos = GetMatrix() * firePos;
GetWeapon()->Fire(this, &firePos);
m_nPadDownPressedInMilliseconds = CTimer::GetTimeInMilliseconds();
}
} else if (CTimer::GetTimeInMilliseconds() > GetWeapon()->m_nTimer &&
CTimer::GetTimeInMilliseconds() - CTimer::GetTimeStepInMilliseconds() < GetWeapon()->m_nTimer && GetWeapon()->m_eWeaponState != WEAPONSTATE_OUT_OF_AMMO) {
DMAudio.PlayFrontEndSound(SOUND_WEAPON_AK47_BULLET_ECHO, GetWeapon()->m_eWeaponType);
2020-04-09 18:50:24 +00:00
}
2020-05-17 17:36:48 +00:00
GetWeapon()->Update(m_audioEntityId, nil);
2020-04-09 18:50:24 +00:00
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::PlayerControlFighter(CPad *padUsed)
{
float leftRight = padUsed->GetPedWalkLeftRight();
float upDown = padUsed->GetPedWalkUpDown();
float padMove = CVector2D(leftRight, upDown).Magnitude();
if (padMove > 0.0f) {
m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(0.0f, 0.0f, -leftRight, upDown) - TheCamera.Orientation;
m_takeAStepAfterAttack = padMove > 2 * PAD_MOVE_TO_GAME_WORLD_MOVE;
if (padUsed->GetSprint() && padMove > 1 * PAD_MOVE_TO_GAME_WORLD_MOVE)
bIsAttacking = false;
}
if (!CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bHeavy && padUsed->JumpJustDown()) {
if (m_nEvadeAmount != 0 && m_pEvadingFrom) {
SetEvasiveDive((CPhysical*)m_pEvadingFrom, 1);
m_nEvadeAmount = 0;
m_pEvadingFrom = nil;
} else {
SetJump();
}
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::PlayerControl1stPersonRunAround(CPad *padUsed)
{
float leftRight = padUsed->GetPedWalkLeftRight();
float upDown = padUsed->GetPedWalkUpDown();
float padMove = CVector2D(leftRight, upDown).Magnitude();
float padMoveInGameUnit = padMove / PAD_MOVE_TO_GAME_WORLD_MOVE;
if (padMoveInGameUnit > 0.0f) {
m_fRotationDest = CGeneral::LimitRadianAngle(TheCamera.Orientation);
2020-04-19 16:34:08 +00:00
m_fMoveSpeed = Min(padMoveInGameUnit, 0.07f * CTimer::GetTimeStep() + m_fMoveSpeed);
2020-04-09 18:50:24 +00:00
} else {
m_fMoveSpeed = 0.0f;
}
if (m_nPedState == PED_JUMP) {
if (bIsInTheAir) {
if (bUsesCollision && !bHitSteepSlope && (!bHitSomethingLastFrame || m_vecDamageNormal.z > 0.6f)
2020-04-09 18:50:24 +00:00
&& m_fDistanceTravelled < CTimer::GetTimeStep() * 0.02 && m_vecMoveSpeed.MagnitudeSqr() < 0.01f) {
float angleSin = Sin(m_fRotationCur); // originally sin(DEGTORAD(RADTODEG(m_fRotationCur))) o_O
float angleCos = Cos(m_fRotationCur);
ApplyMoveForce(-angleSin * 3.0f, 3.0f * angleCos, 0.05f);
}
} else if (bIsLanding) {
m_fMoveSpeed = 0.0f;
}
}
if (m_nPedState == PED_ANSWER_MOBILE) {
SetRealMoveAnim();
return;
}
if (!(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bHeavy) && padUsed->GetSprint()) {
2020-04-09 18:50:24 +00:00
m_nMoveState = PEDMOVE_SPRINT;
}
if (m_nPedState != PED_FIGHT)
SetRealMoveAnim();
if (!bIsInTheAir && !(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bHeavy) &&
padUsed->JumpJustDown() && m_nPedState != PED_JUMP) {
2020-04-09 18:50:24 +00:00
ClearAttack();
ClearWeaponTarget();
if (m_nEvadeAmount != 0 && m_pEvadingFrom) {
SetEvasiveDive((CPhysical*)m_pEvadingFrom, 1);
m_nEvadeAmount = 0;
m_pEvadingFrom = nil;
} else {
SetJump();
}
}
// FIX: Fact that PlayIdleAnimations only called through PlayerControlZelda was making it visible to only Classic control players. This isn't fair!
#ifdef FIX_BUGS
if (m_nPedState != PED_FIGHT)
PlayIdleAnimations(padUsed);
#endif
2020-04-09 18:50:24 +00:00
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::KeepAreaAroundPlayerClear(void)
{
BuildPedLists();
for (int i = 0; i < m_numNearPeds; ++i) {
CPed *nearPed = m_nearPeds[i];
if (nearPed->CharCreatedBy == RANDOM_CHAR && nearPed->m_nPedState != PED_DRIVING && !nearPed->DyingOrDead()) {
2020-04-09 18:50:24 +00:00
if (nearPed->GetIsOnScreen()) {
if (nearPed->m_objective == OBJECTIVE_NONE) {
nearPed->SetFindPathAndFlee(this, 5000, true);
} else {
if (nearPed->EnteringCar())
nearPed->QuitEnteringCar();
nearPed->ClearObjective();
}
} else {
nearPed->FlagToDestroyWhenNextProcessed();
}
}
}
CVector playerPos = (InVehicle() ? m_pMyVehicle->GetPosition() : GetPosition());
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 < lastVehicle; i++) {
CVehicle *veh = (CVehicle*)vehicles[i];
if (veh->VehicleCreatedBy != MISSION_VEHICLE) {
if (veh->GetStatus() != STATUS_PLAYER && veh->GetStatus() != STATUS_PLAYER_DISABLED) {
2020-04-09 18:50:24 +00:00
if ((veh->GetPosition() - playerPos).MagnitudeSqr() > 25.0f) {
veh->AutoPilot.m_nTempAction = TEMPACT_WAIT;
veh->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 5000;
} else {
if (DotProduct2D(playerPos - veh->GetPosition(), veh->GetForward()) > 0.0f)
veh->AutoPilot.m_nTempAction = TEMPACT_REVERSE;
else
veh->AutoPilot.m_nTempAction = TEMPACT_GOFORWARD;
veh->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 2000;
}
CCarCtrl::PossiblyRemoveVehicle(veh);
}
}
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::EvaluateNeighbouringTarget(CEntity *candidate, CEntity **targetPtr, float *lastCloseness, float distLimit, float angleOffset, bool lookToLeft, bool priority)
2020-04-09 18:50:24 +00:00
{
// priority param is unused
2020-04-09 18:50:24 +00:00
CVector distVec = candidate->GetPosition() - GetPosition();
if (distVec.Magnitude2D() <= distLimit) {
if (!DoesTargetHaveToBeBroken(candidate->GetPosition(), GetWeapon())) {
float angleBetweenUs = CGeneral::GetATanOfXY(candidate->GetPosition().x - TheCamera.GetPosition().x,
candidate->GetPosition().y - TheCamera.GetPosition().y);
2020-04-09 18:50:24 +00:00
angleBetweenUs = CGeneral::LimitAngle(angleBetweenUs - angleOffset);
float closeness;
if (lookToLeft) {
closeness = angleBetweenUs > 0.0f ? -Abs(angleBetweenUs) : -100000.0f;
} else {
closeness = angleBetweenUs > 0.0f ? -100000.0f : -Abs(angleBetweenUs);
}
if (closeness > *lastCloseness) {
*targetPtr = candidate;
*lastCloseness = closeness;
}
}
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::EvaluateTarget(CEntity *candidate, CEntity **targetPtr, float *lastCloseness, float distLimit, float angleOffset, bool priority)
{
CVector distVec = candidate->GetPosition() - GetPosition();
float dist = distVec.Magnitude2D();
if (dist <= distLimit) {
if (!DoesTargetHaveToBeBroken(candidate->GetPosition(), GetWeapon())) {
float angleBetweenUs = CGeneral::GetATanOfXY(distVec.x, distVec.y);
angleBetweenUs = CGeneral::LimitAngle(angleBetweenUs - angleOffset);
float closeness = -dist - 5.0f * Abs(angleBetweenUs);
if (priority) {
closeness += 30.0f;
2020-04-09 18:50:24 +00:00
}
if (closeness > *lastCloseness) {
*targetPtr = candidate;
*lastCloseness = closeness;
}
}
}
}
bool
CPlayerPed::CanIKReachThisTarget(CVector target, CWeapon* weapon, bool zRotImportant)
{
float angleToFace = CGeneral::GetRadianAngleBetweenPoints(target.x, target.y, GetPosition().x, GetPosition().y);
float angleDiff = CGeneral::LimitRadianAngle(angleToFace - m_fRotationCur);
return (!zRotImportant || CWeaponInfo::GetWeaponInfo(weapon->m_eWeaponType)->m_bCanAimWithArm || Abs(angleDiff) <= HALFPI) &&
(CWeaponInfo::GetWeaponInfo(weapon->m_eWeaponType)->m_bCanAimWithArm || Abs(target.z - GetPosition().z) <= (target - GetPosition()).Magnitude2D());
}
void
CPlayerPed::RotatePlayerToTrackTarget(void)
{
if (CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAimWithArm)
return;
float angleToFace = CGeneral::GetRadianAngleBetweenPoints(
m_pPointGunAt->GetPosition().x, m_pPointGunAt->GetPosition().y,
GetPosition().x, GetPosition().y);
float angleDiff = CGeneral::LimitRadianAngle(m_fRotationCur - angleToFace);
if (angleDiff < -DEGTORAD(25.0f)) {
m_fRotationCur -= angleDiff + DEGTORAD(25.0f);
m_fRotationDest -= angleDiff + DEGTORAD(25.0f);
} else if (angleDiff > DEGTORAD(25.0f)) {
m_fRotationCur -= angleDiff - DEGTORAD(25.0f);
m_fRotationDest -= angleDiff - DEGTORAD(25.0f);
}
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
bool
CPlayerPed::FindNextWeaponLockOnTarget(CEntity *previousTarget, bool lookToLeft)
{
CEntity *nextTarget = nil;
float weaponRange = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_fRange;
// nextTarget = nil; // duplicate
2020-04-09 18:50:24 +00:00
float lastCloseness = -10000.0f;
// CGeneral::GetATanOfXY(GetForward().x, GetForward().y); // unused
2020-04-09 18:50:24 +00:00
CVector distVec = previousTarget->GetPosition() - GetPosition();
float referenceBeta = CGeneral::GetATanOfXY(distVec.x, distVec.y);
for (int h = CPools::GetPedPool()->GetSize() - 1; h >= 0; h--) {
CPed *pedToCheck = CPools::GetPedPool()->GetSlot(h);
if (pedToCheck) {
if (pedToCheck != this && pedToCheck != previousTarget) {
if (!pedToCheck->DyingOrDead()
#ifndef AIMING_VEHICLE_OCCUPANTS // Mobile thing
&& (!pedToCheck->bInVehicle || (pedToCheck->m_pMyVehicle && pedToCheck->m_pMyVehicle->IsBike()))
#endif
&& pedToCheck->m_leader != this && !pedToCheck->bNeverEverTargetThisPed
&& OurPedCanSeeThisOne(pedToCheck) && CanIKReachThisTarget(pedToCheck->GetPosition(), GetWeapon(), true)) {
2020-04-09 18:50:24 +00:00
EvaluateNeighbouringTarget(pedToCheck, &nextTarget, &lastCloseness,
weaponRange, referenceBeta, lookToLeft, IsThisPedAnAimingPriority(pedToCheck));
2020-04-09 18:50:24 +00:00
}
}
}
}
for (int i = 0; i < ARRAY_SIZE(m_nTargettableObjects); i++) {
CObject *obj = CPools::GetObjectPool()->GetAt(m_nTargettableObjects[i]);
if (obj && !obj->bHasBeenDamaged && CanIKReachThisTarget(obj->GetPosition(), GetWeapon(), true))
EvaluateNeighbouringTarget(obj, &nextTarget, &lastCloseness, weaponRange, referenceBeta, lookToLeft, true);
2020-04-09 18:50:24 +00:00
}
if (!nextTarget)
return false;
SetWeaponLockOnTarget(nextTarget);
bDontAllowWeaponChange = true;
2020-04-09 18:50:24 +00:00
SetPointGunAt(nextTarget);
return true;
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
bool
CPlayerPed::FindWeaponLockOnTarget(void)
{
CEntity *nextTarget = nil;
float weaponRange = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_fRange;
if (m_pPointGunAt) {
CVector distVec = m_pPointGunAt->GetPosition() - GetPosition();
if (distVec.Magnitude2D() > weaponRange) {
SetWeaponLockOnTarget(nil);
2020-04-09 18:50:24 +00:00
return false;
} else {
return true;
}
}
// nextTarget = nil; // duplicate
2020-04-09 18:50:24 +00:00
float lastCloseness = -10000.0f;
float referenceBeta = CGeneral::GetATanOfXY(GetForward().x, GetForward().y);
for (int h = CPools::GetPedPool()->GetSize() - 1; h >= 0; h--) {
CPed *pedToCheck = CPools::GetPedPool()->GetSlot(h);
if (pedToCheck) {
if (pedToCheck != this) {
if (!pedToCheck->DyingOrDead()
#ifndef AIMING_VEHICLE_OCCUPANTS // Mobile thing
&& (!pedToCheck->bInVehicle || (pedToCheck->m_pMyVehicle && pedToCheck->m_pMyVehicle->IsBike()))
#endif
&& pedToCheck->m_leader != this && !pedToCheck->bNeverEverTargetThisPed
&& OurPedCanSeeThisOne(pedToCheck) && CanIKReachThisTarget(pedToCheck->GetPosition(), GetWeapon(), true)) {
2020-04-09 18:50:24 +00:00
EvaluateTarget(pedToCheck, &nextTarget, &lastCloseness,
weaponRange, referenceBeta, IsThisPedAnAimingPriority(pedToCheck));
2020-04-09 18:50:24 +00:00
}
}
}
}
for (int i = 0; i < ARRAY_SIZE(m_nTargettableObjects); i++) {
CObject *obj = CPools::GetObjectPool()->GetAt(m_nTargettableObjects[i]);
if (obj && !obj->bHasBeenDamaged && CanIKReachThisTarget(obj->GetPosition(), GetWeapon(), true))
EvaluateTarget(obj, &nextTarget, &lastCloseness, weaponRange, referenceBeta, true);
2020-04-09 18:50:24 +00:00
}
if (!nextTarget)
return false;
SetWeaponLockOnTarget(nextTarget);
bDontAllowWeaponChange = true;
2020-04-09 18:50:24 +00:00
SetPointGunAt(nextTarget);
2020-11-08 13:00:54 +00:00
Say(SOUND_PED_AIMING);
2020-04-09 18:50:24 +00:00
return true;
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::ProcessAnimGroups(void)
{
AssocGroupId groupToSet;
if ((m_fWalkAngle <= -DEGTORAD(50.0f) || m_fWalkAngle >= DEGTORAD(50.0f))
&& TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam()
&& CanStrafeOrMouseControl()) {
if (m_fWalkAngle >= -DEGTORAD(130.0f) && m_fWalkAngle <= DEGTORAD(130.0f)) {
if (m_fWalkAngle > 0.0f) {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER)
groupToSet = ASSOCGRP_ROCKETLEFT;
2020-05-20 17:10:05 +00:00
else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW ||
2020-05-23 23:59:30 +00:00
GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER ||
GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN)
2020-05-15 14:30:25 +00:00
groupToSet = ASSOCGRP_CHAINSAWLEFT;
2020-04-09 18:50:24 +00:00
else
groupToSet = ASSOCGRP_PLAYERLEFT;
} else {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER)
groupToSet = ASSOCGRP_ROCKETRIGHT;
2020-05-20 17:10:05 +00:00
else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW ||
2020-05-23 23:59:30 +00:00
GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER ||
GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN)
2020-05-15 14:30:25 +00:00
groupToSet = ASSOCGRP_CHAINSAWRIGHT;
2020-04-09 18:50:24 +00:00
else
groupToSet = ASSOCGRP_PLAYERRIGHT;
}
} else {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER)
groupToSet = ASSOCGRP_ROCKETBACK;
2020-05-20 17:10:05 +00:00
else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW ||
2020-05-23 23:59:30 +00:00
GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER ||
GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN)
2020-05-15 14:30:25 +00:00
groupToSet = ASSOCGRP_CHAINSAWBACK;
2020-04-09 18:50:24 +00:00
else
groupToSet = ASSOCGRP_PLAYERBACK;
}
} else {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) {
groupToSet = ASSOCGRP_PLAYERROCKET;
} else {
2020-05-15 14:30:25 +00:00
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_BASEBALLBAT
2020-05-20 17:10:05 +00:00
|| GetWeapon()->m_eWeaponType == WEAPONTYPE_MACHETE)
2020-04-09 18:50:24 +00:00
groupToSet = ASSOCGRP_PLAYERBBBAT;
2020-05-20 17:10:05 +00:00
else if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW ||
2020-05-23 23:59:30 +00:00
GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER ||
GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN)
2020-05-15 14:30:25 +00:00
groupToSet = ASSOCGRP_PLAYERCHAINSAW;
else if (GetWeapon()->m_eWeaponType != WEAPONTYPE_COLT45 && GetWeapon()->m_eWeaponType != WEAPONTYPE_UZI
2020-05-23 23:59:30 +00:00
// I hope this is a inlined function...
&& GetWeapon()->m_eWeaponType != WEAPONTYPE_PYTHON && GetWeapon()->m_eWeaponType != WEAPONTYPE_TEC9
2020-05-20 17:10:05 +00:00
&& GetWeapon()->m_eWeaponType != WEAPONTYPE_SILENCED_INGRAM && GetWeapon()->m_eWeaponType != WEAPONTYPE_MP5
2020-05-15 14:30:25 +00:00
&& GetWeapon()->m_eWeaponType != WEAPONTYPE_GOLFCLUB && GetWeapon()->m_eWeaponType != WEAPONTYPE_KATANA
2020-05-23 23:59:30 +00:00
&& GetWeapon()->m_eWeaponType != WEAPONTYPE_CAMERA) {
2020-04-09 18:50:24 +00:00
if (!GetWeapon()->IsType2Handed()) {
groupToSet = ASSOCGRP_PLAYER;
} else {
groupToSet = ASSOCGRP_PLAYER2ARMED;
}
} else {
groupToSet = ASSOCGRP_PLAYER1ARMED;
}
}
}
if (m_animGroup != groupToSet) {
m_animGroup = groupToSet;
ReApplyMoveAnims();
}
}
void
CPlayerPed::ProcessPlayerWeapon(CPad *padUsed)
{
CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
if (m_bHasLockOnTarget && !m_pPointGunAt) {
TheCamera.ClearPlayerWeaponMode();
CWeaponEffects::ClearCrossHair();
ClearPointGunAt();
}
if (padUsed->DuckJustDown() && !bIsDucking && m_nMoveState != PEDMOVE_SPRINT) {
bCrouchWhenShooting = true;
SetDuck(60000, true);
} else if (bIsDucking && (padUsed->DuckJustDown() || m_nMoveState == PEDMOVE_SPRINT ||
padUsed->GetSprint() || padUsed->JumpJustDown() || padUsed->ExitVehicleJustDown())) {
ClearDuck(true);
bCrouchWhenShooting = false;
}
if(weaponInfo->m_bCanAim)
m_wepAccuracy = 95;
else
m_wepAccuracy = 100;
2020-04-09 18:50:24 +00:00
if (!m_pFire) {
eWeaponType weapon = GetWeapon()->m_eWeaponType;
if (weapon == WEAPONTYPE_ROCKETLAUNCHER || weapon == WEAPONTYPE_SNIPERRIFLE ||
weapon == WEAPONTYPE_LASERSCOPE || weapon == WEAPONTYPE_M4 ||
weapon == WEAPONTYPE_RUGER || weapon == WEAPONTYPE_M60 ||
weapon == WEAPONTYPE_CAMERA) {
if (padUsed->TargetJustDown() || TheCamera.m_bJustJumpedOutOf1stPersonBecauseOfTarget) {
2020-04-09 18:50:24 +00:00
#ifdef FREE_CAM
if (CCamera::bFreeCam && TheCamera.Cams[0].Using3rdPersonMouseCam()) {
m_fRotationCur = CGeneral::LimitRadianAngle(-TheCamera.Orientation);
SetHeading(m_fRotationCur);
}
#endif
if (weapon == WEAPONTYPE_ROCKETLAUNCHER)
2020-04-09 18:50:24 +00:00
TheCamera.SetNewPlayerWeaponMode(CCam::MODE_ROCKETLAUNCHER, 0, 0);
else if (weapon == WEAPONTYPE_SNIPERRIFLE || weapon == WEAPONTYPE_LASERSCOPE)
2020-04-09 18:50:24 +00:00
TheCamera.SetNewPlayerWeaponMode(CCam::MODE_SNIPER, 0, 0);
else if (weapon == WEAPONTYPE_CAMERA)
TheCamera.SetNewPlayerWeaponMode(CCam::MODE_CAMERA, 0, 0);
2020-04-09 18:50:24 +00:00
else
TheCamera.SetNewPlayerWeaponMode(CCam::MODE_M16_1STPERSON, 0, 0);
m_fMoveSpeed = 0.0f;
CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_STANCE, 1000.0f);
SetPedState(PED_SNIPER_MODE);
2020-04-09 18:50:24 +00:00
return;
}
if (!TheCamera.Using1stPersonWeaponMode())
if (weapon == WEAPONTYPE_ROCKETLAUNCHER || weapon == WEAPONTYPE_SNIPERRIFLE || weapon == WEAPONTYPE_LASERSCOPE || weapon == WEAPONTYPE_CAMERA)
return;
2020-04-09 18:50:24 +00:00
}
}
if (padUsed->GetWeapon() && m_nMoveState != PEDMOVE_SPRINT) {
if (m_nSelectedWepSlot == m_currentWeapon) {
if (m_pPointGunAt) {
if (m_nPedState == PED_ATTACK) {
m_fAttackButtonCounter *= Pow(0.94f, CTimer::GetTimeStep());
} else {
m_fAttackButtonCounter = 0.0f;
}
SetAttack(m_pPointGunAt);
} else {
2020-04-09 18:50:24 +00:00
if (m_nPedState == PED_ATTACK) {
if (padUsed->WeaponJustDown()) {
m_bHaveTargetSelected = true;
} else if (!m_bHaveTargetSelected) {
2020-04-15 05:03:53 +00:00
m_fAttackButtonCounter += CTimer::GetTimeStepNonClipped();
2020-04-09 18:50:24 +00:00
}
} else {
2020-04-15 05:03:53 +00:00
m_fAttackButtonCounter = 0.0f;
2020-04-09 18:50:24 +00:00
m_bHaveTargetSelected = false;
}
if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED && GetWeapon()->m_eWeaponType != WEAPONTYPE_BRASSKNUCKLE &&
!weaponInfo->m_bFightMode) {
if (GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR && GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR_GRENADE ||
padUsed->WeaponJustDown())
SetAttack(nil);
} else if (padUsed->WeaponJustDown()) {
if (m_fMoveSpeed < 1.0f || m_nPedState == PED_FIGHT)
StartFightAttack(padUsed->GetWeapon());
else
SetAttack(nil);
}
2020-04-09 18:50:24 +00:00
}
}
} else {
m_pedIK.m_flags &= ~CPedIK::LOOKAROUND_HEAD_ONLY;
if (m_nPedState == PED_ATTACK) {
m_bHaveTargetSelected = true;
bIsAttacking = false;
}
}
#ifdef FREE_CAM
2020-06-03 13:16:31 +00:00
static int8 changedHeadingRate = 0;
if (changedHeadingRate == 2) changedHeadingRate = 1;
2020-04-09 18:50:24 +00:00
// Rotate player/arm when shooting. We don't have auto-rotation anymore
if (CCamera::m_bUseMouse3rdPerson && CCamera::bFreeCam &&
m_nSelectedWepSlot == m_currentWeapon && m_nMoveState != PEDMOVE_SPRINT) {
2020-12-16 20:28:25 +00:00
#define CAN_AIM_WITH_ARM (weaponInfo->m_bCanAimWithArm && !bIsDucking && !bCrouchWhenShooting)
2020-04-09 18:50:24 +00:00
// Weapons except throwable and melee ones
2020-05-16 12:07:09 +00:00
if (weaponInfo->m_nWeaponSlot > 2) {
2020-12-16 20:28:25 +00:00
if ((padUsed->GetTarget() && CAN_AIM_WITH_ARM) || padUsed->GetWeapon()) {
2020-04-09 18:50:24 +00:00
float limitedCam = CGeneral::LimitRadianAngle(-TheCamera.Orientation);
// On this one we can rotate arm.
2020-12-16 20:28:25 +00:00
if (CAN_AIM_WITH_ARM) {
2020-04-09 18:50:24 +00:00
if (!padUsed->GetWeapon()) { // making this State != ATTACK still stops it after attack. Re-start it immediately!
SetWeaponLockOnTarget(nil);
2020-04-09 18:50:24 +00:00
bIsPointingGunAt = false; // to not stop after attack
}
SetLookFlag(limitedCam, true);
SetAimFlag(limitedCam);
2020-05-11 02:55:57 +00:00
SetLookTimer(INT32_MAX); // removing this makes head move for real, but I experinced some bugs.
2020-04-09 18:50:24 +00:00
} else {
m_fRotationDest = limitedCam;
2020-06-03 13:16:31 +00:00
changedHeadingRate = 2;
m_headingRate = 12.5f;
2020-04-09 18:50:24 +00:00
// Anim. fix for shotgun, ak47 and m16 (we must finish rot. it quickly)
if (weaponInfo->m_bCanAim && padUsed->WeaponJustDown()) {
m_fRotationCur = CGeneral::LimitRadianAngle(m_fRotationCur);
float limitedRotDest = m_fRotationDest;
if (m_fRotationCur - PI > m_fRotationDest) {
limitedRotDest += 2 * PI;
} else if (PI + m_fRotationCur < m_fRotationDest) {
limitedRotDest -= 2 * PI;
}
m_fRotationCur += (limitedRotDest - m_fRotationCur) / 2;
}
}
2020-12-16 20:28:25 +00:00
} else if (CAN_AIM_WITH_ARM && m_nPedState != PED_ATTACK)
2020-04-09 18:50:24 +00:00
ClearPointGunAt();
}
2020-12-16 20:28:25 +00:00
#undef CAN_AIM_WITH_ARM
2020-04-09 18:50:24 +00:00
}
2020-06-03 13:16:31 +00:00
if (changedHeadingRate == 1) {
changedHeadingRate = 0;
RestoreHeadingRate();
}
2020-04-09 18:50:24 +00:00
#endif
if (padUsed->GetTarget() && m_nSelectedWepSlot == m_currentWeapon && m_nMoveState != PEDMOVE_SPRINT && !TheCamera.Using1stPersonWeaponMode() && weaponInfo->m_bCanAim) {
2020-04-09 18:50:24 +00:00
if (m_pPointGunAt) {
// what??
if (!m_pPointGunAt
#ifdef FREE_CAM
|| (!CCamera::bFreeCam && CCamera::m_bUseMouse3rdPerson)
#else
|| CCamera::m_bUseMouse3rdPerson
#endif
) {
ClearWeaponTarget();
return;
}
if (m_pPointGunAt->IsPed() && (
#ifndef AIMING_VEHICLE_OCCUPANTS
(((CPed*)m_pPointGunAt)->bInVehicle && (!((CPed*)m_pPointGunAt)->m_pMyVehicle || !((CPed*)m_pPointGunAt)->m_pMyVehicle->IsBike())) ||
#endif
!CGame::nastyGame && ((CPed*)m_pPointGunAt)->DyingOrDead())) {
2020-04-09 18:50:24 +00:00
ClearWeaponTarget();
return;
}
if (CPlayerPed::DoesTargetHaveToBeBroken(m_pPointGunAt->GetPosition(), GetWeapon()) ||
(!bCanPointGunAtTarget && !weaponInfo->m_bCanAimWithArm)) { // this line isn't on Mobile, idk why
2020-04-09 18:50:24 +00:00
ClearWeaponTarget();
return;
}
if (m_pPointGunAt) {
RotatePlayerToTrackTarget();
}
2020-04-09 18:50:24 +00:00
if (m_pPointGunAt) {
if (padUsed->ShiftTargetLeftJustDown())
FindNextWeaponLockOnTarget(m_pPointGunAt, true);
if (padUsed->ShiftTargetRightJustDown())
FindNextWeaponLockOnTarget(m_pPointGunAt, false);
}
TheCamera.SetNewPlayerWeaponMode(CCam::MODE_SYPHON, 0, 0);
TheCamera.UpdateAimingCoors(m_pPointGunAt->GetPosition());
} else if (!CCamera::m_bUseMouse3rdPerson) {
if (padUsed->TargetJustDown() || TheCamera.m_bJustJumpedOutOf1stPersonBecauseOfTarget)
2020-04-09 18:50:24 +00:00
FindWeaponLockOnTarget();
}
} else if (m_pPointGunAt) {
ClearWeaponTarget();
}
if (m_pPointGunAt) {
CVector markPos;
if (m_pPointGunAt->IsPed()) {
2020-05-24 15:27:12 +00:00
((CPed*)m_pPointGunAt)->m_pedIK.GetComponentPosition(*(RwV3d *)&markPos, PED_MID);
2020-04-09 18:50:24 +00:00
} else {
markPos = m_pPointGunAt->GetPosition();
}
if (bCanPointGunAtTarget) {
CWeaponEffects::MarkTarget(markPos, 64, 0, 0, 255, 0.8f);
} else {
CWeaponEffects::MarkTarget(markPos, 64, 32, 0, 255, 0.8f);
}
}
m_bHasLockOnTarget = m_pPointGunAt != nil;
}
bool
CPlayerPed::MovementDisabledBecauseOfTargeting(void)
{
return m_pPointGunAt && !CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAimWithArm;
}
// --MIAMI: Done
2020-04-09 18:50:24 +00:00
void
CPlayerPed::PlayerControlZelda(CPad *padUsed)
{
float smoothSprayRate = DoWeaponSmoothSpray();
2020-04-09 18:50:24 +00:00
float camOrientation = TheCamera.Orientation;
float leftRight = padUsed->GetPedWalkLeftRight();
float upDown = padUsed->GetPedWalkUpDown();
float padMoveInGameUnit;
bool smoothSprayWithoutMove = false;
if (MovementDisabledBecauseOfTargeting()) {
upDown = 0.0f;
leftRight = 0.0f;
}
if (smoothSprayRate > 0.0f && upDown > 0.0f) {
2020-04-09 18:50:24 +00:00
padMoveInGameUnit = 0.0f;
smoothSprayWithoutMove = true;
} else {
padMoveInGameUnit = CVector2D(leftRight, upDown).Magnitude() / PAD_MOVE_TO_GAME_WORLD_MOVE;
}
if (padMoveInGameUnit > 0.0f || smoothSprayWithoutMove) {
float padHeading = CGeneral::GetRadianAngleBetweenPoints(0.0f, 0.0f, -leftRight, upDown);
float neededTurn = CGeneral::LimitRadianAngle(padHeading - camOrientation);
if (smoothSprayRate > 0.0f) {
m_fRotationDest = m_fRotationCur - leftRight / 128.0f * smoothSprayRate * CTimer::GetTimeStep();
2020-04-09 18:50:24 +00:00
} else {
m_fRotationDest = neededTurn;
}
float maxAcc = 0.07f * CTimer::GetTimeStep();
2020-04-19 16:34:08 +00:00
m_fMoveSpeed = Min(padMoveInGameUnit, m_fMoveSpeed + maxAcc);
2020-04-09 18:50:24 +00:00
} else {
m_fMoveSpeed = 0.0f;
}
if (m_nPedState == PED_JUMP) {
if (bIsInTheAir) {
if (bUsesCollision && !bHitSteepSlope &&
(!bHitSomethingLastFrame || m_vecDamageNormal.z > 0.6f)
&& m_fDistanceTravelled < CTimer::GetTimeStep() * 0.02 && m_vecMoveSpeed.MagnitudeSqr() < 0.01f) {
float angleSin = Sin(m_fRotationCur); // originally sin(DEGTORAD(RADTODEG(m_fRotationCur))) o_O
float angleCos = Cos(m_fRotationCur);
ApplyMoveForce(-angleSin * 3.0f, 3.0f * angleCos, 0.05f);
}
} else if (bIsLanding) {
m_fMoveSpeed = 0.0f;
}
}
2020-06-20 17:26:27 +00:00
if (m_nPedState == PED_ANSWER_MOBILE) {
SetRealMoveAnim();
return;
}
if (!(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bHeavy) && padUsed->GetSprint()) {
if (!m_pCurrentPhysSurface || (!m_pCurrentPhysSurface->bInfiniteMass || m_pCurrentPhysSurface->m_phy_flagA08))
2020-06-20 17:26:27 +00:00
m_nMoveState = PEDMOVE_SPRINT;
2020-04-09 18:50:24 +00:00
}
2020-04-09 18:50:24 +00:00
if (m_nPedState != PED_FIGHT)
SetRealMoveAnim();
if (!bIsInTheAir && !(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bHeavy)
&& padUsed->JumpJustDown() && m_nPedState != PED_JUMP) {
ClearAttack();
ClearWeaponTarget();
if (m_nEvadeAmount != 0 && m_pEvadingFrom) {
SetEvasiveDive((CPhysical*)m_pEvadingFrom, 1);
m_nEvadeAmount = 0;
m_pEvadingFrom = nil;
} else {
SetJump();
}
}
PlayIdleAnimations(padUsed);
2020-04-09 18:50:24 +00:00
}
// Finds nice positions for peds to duck and shoot player. And it's inside PlayerPed, this is treachery!
void
CPlayerPed::FindNewAttackPoints(void)
{
for (int i=0; i<ARRAY_SIZE(m_pPedAtSafePos); i++) {
CPed *safeNeighbour = m_pPedAtSafePos[i];
if (safeNeighbour) {
if (safeNeighbour->m_nPedState == PED_DEAD || safeNeighbour->m_pedInObjective != this) {
m_vecSafePos[i].x = 0.0f;
m_vecSafePos[i].y = 0.0f;
m_vecSafePos[i].z = 0.0f;
m_pPedAtSafePos[i] = nil;
}
} else {
m_vecSafePos[i].x = 0.0f;
m_vecSafePos[i].y = 0.0f;
m_vecSafePos[i].z = 0.0f;
}
}
CEntity *entities[6];
int16 numEnts;
float rightMult, fwdMult;
CWorld::FindObjectsInRange(GetPosition(), 18.0f, true, &numEnts, 6, entities, true, false, false, true, false);
for (int i = 0; i < numEnts; ++i) {
CEntity *ent = entities[i];
int16 mi = ent->GetModelIndex();
if (!ent->IsObject() || ((CObject*)ent)->m_nSpecialCollisionResponseCases == COLLRESPONSE_FENCEPART)
if (!IsTreeModel(mi))
continue;
if (mi == MI_TRAFFICLIGHTS) {
rightMult = 2.957f;
fwdMult = 0.147f;
} else if (mi == MI_SINGLESTREETLIGHTS1) {
rightMult = 0.744f;
fwdMult = 0.0f;
} else if (mi == MI_SINGLESTREETLIGHTS2) {
rightMult = 0.043f;
fwdMult = 0.0f;
} else if (mi == MI_SINGLESTREETLIGHTS3) {
rightMult = 1.143f;
fwdMult = 0.145f;
} else if (mi == MI_DOUBLESTREETLIGHTS) {
rightMult = 0.744f;
fwdMult = 0.0f;
} else if (mi == MI_LAMPPOST1) {
rightMult = 0.744f;
fwdMult = 0.0f;
} else if (mi == MI_TRAFFICLIGHT01) {
rightMult = 2.957f;
fwdMult = 0.147f;
} else if (mi == MI_LITTLEHA_POLICE) {
rightMult = 0.0f;
fwdMult = 0.0f;
} else if (mi == MI_PARKBENCH) {
rightMult = 0.0f;
fwdMult = 0.0f;
} else if (IsTreeModel(mi)) {
rightMult = 0.0f;
fwdMult = 0.0f;
} else
continue;
CVector entAttackPoint(rightMult * ent->GetRight().x + fwdMult * ent->GetForward().x + ent->GetPosition().x,
rightMult * ent->GetRight().y + fwdMult * ent->GetForward().y + ent->GetPosition().y,
ent->GetPosition().z);
CVector attackerPos = GetPosition() - entAttackPoint; // for now it's dist, not attackerPos
CVector dirTowardsUs = attackerPos;
dirTowardsUs.Normalise();
dirTowardsUs *= 2.0f;
attackerPos = entAttackPoint - dirTowardsUs; // to make cop farther from us
CPedPlacement::FindZCoorForPed(&attackerPos);
if (CPedPlacement::IsPositionClearForPed(attackerPos))
m_vecSafePos[i] = attackerPos;
}
}
2020-04-09 18:50:24 +00:00
void
CPlayerPed::ProcessControl(void)
{
// Mobile has some debug/abandoned cheat thing in here: "gbFrankenTommy"
2020-04-09 18:50:24 +00:00
if (m_nEvadeAmount != 0)
--m_nEvadeAmount;
if (m_nEvadeAmount == 0)
m_pEvadingFrom = nil;
if (m_pWanted->m_nWantedLevel > 0)
FindNewAttackPoints();
UpdateMeleeAttackers();
2020-04-09 18:50:24 +00:00
if (m_pCurrentPhysSurface && m_pCurrentPhysSurface->IsVehicle() && ((CVehicle*)m_pCurrentPhysSurface)->IsBoat()) {
bTryingToReachDryLand = true;
2020-04-09 18:50:24 +00:00
} else if (!(((uint8)CTimer::GetFrameCounter() + m_randomSeed) & 0xF)) {
CVehicle *nearVeh = (CVehicle*)CWorld::TestSphereAgainstWorld(GetPosition(), 7.0f, nil, false, true, false, false, false, false);
2020-04-09 18:50:24 +00:00
if (nearVeh && nearVeh->IsBoat())
bTryingToReachDryLand = true;
else
bTryingToReachDryLand = false;
}
if (m_nFadeDrunkenness) {
if (m_nDrunkenness - 1 > 0) {
--m_nDrunkenness;
} else {
m_nDrunkenness = 0;
CMBlur::ClearDrunkBlur();
m_nFadeDrunkenness = 0;
}
}
if (m_nDrunkenness != 0) {
CMBlur::SetDrunkBlur(m_nDrunkenness / 255.f);
}
2020-04-09 18:50:24 +00:00
CPed::ProcessControl();
SetNearbyPedsToInteractWithPlayer();
2020-04-09 18:50:24 +00:00
if (bWasPostponed)
return;
CPad *padUsed = GetPadFromPlayer(this);
2020-04-09 18:50:24 +00:00
m_pWanted->Update();
PruneReferences();
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN) {
CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
CAnimBlendAssociation *fireAnim = RpAnimBlendClumpGetAssociation(GetClump(), GetPrimaryFireAnim(weaponInfo));
if (fireAnim && fireAnim->currentTime - fireAnim->timeStep < weaponInfo->m_fAnimLoopEnd && m_nPedState == PED_ATTACK) {
if (m_fGunSpinSpeed < 0.45f) {
m_fGunSpinSpeed = Min(0.45f, m_fGunSpinSpeed + CTimer::GetTimeStep() * 0.013f);
}
if (padUsed->GetWeapon() && GetWeapon()->m_nAmmoTotal > 0 && fireAnim->currentTime >= weaponInfo->m_fAnimLoopStart) {
DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_MINIGUN_ATTACK, 0.0f);
} else {
DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_MINIGUN_2, m_fGunSpinSpeed * (20.f / 9));
}
} else {
if (m_fGunSpinSpeed > 0.0f) {
if (m_fGunSpinSpeed >= 0.45f) {
DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_MINIGUN_3, 0.0f);
}
m_fGunSpinSpeed = Max(0.0f, m_fGunSpinSpeed - CTimer::GetTimeStep() * 0.003f);
}
}
}
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW && m_nPedState != PED_ATTACK && !bInVehicle) {
DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_CHAINSAW_ATTACK, 0.0f);
}
2020-04-09 18:50:24 +00:00
if (m_nMoveState != PEDMOVE_RUN && m_nMoveState != PEDMOVE_SPRINT)
RestoreSprintEnergy(1.0f);
else if (m_nMoveState == PEDMOVE_RUN)
RestoreSprintEnergy(0.3f);
if (m_nPedState == PED_DEAD) {
ClearWeaponTarget();
return;
}
if (m_nPedState == PED_DIE) {
ClearWeaponTarget();
if (CTimer::GetTimeInMilliseconds() > m_bloodyFootprintCountOrDeathTime + 4000)
SetDead();
return;
}
if (m_nPedState == PED_DRIVING && m_objective != OBJECTIVE_LEAVE_CAR) {
if (!CReplay::IsPlayingBack() || m_pMyVehicle) {
if (m_pMyVehicle->IsCar() && ((CAutomobile*)m_pMyVehicle)->Damage.GetDoorStatus(DOOR_FRONT_LEFT) == DOOR_STATUS_SWINGING) {
CAnimBlendAssociation *rollDoorAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_ROLLDOOR);
2020-04-09 18:50:24 +00:00
if (m_pMyVehicle->m_nGettingOutFlags & CAR_DOOR_FLAG_LF || rollDoorAssoc || (rollDoorAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_CAR_ROLLDOOR_LOW))) {
if (rollDoorAssoc)
m_pMyVehicle->ProcessOpenDoor(CAR_DOOR_LF, ANIM_CAR_ROLLDOOR, rollDoorAssoc->currentTime);
2020-04-09 18:50:24 +00:00
} else {
// These comparisons are wrong, they return uint16
if (padUsed && (padUsed->GetAccelerate() != 0.0f || padUsed->GetSteeringLeftRight() != 0.0f || padUsed->GetBrake() != 0.0f)) {
if (rollDoorAssoc)
m_pMyVehicle->ProcessOpenDoor(CAR_DOOR_LF, ANIM_CAR_ROLLDOOR, rollDoorAssoc->currentTime);
} else {
m_pMyVehicle->m_nGettingOutFlags |= CAR_DOOR_FLAG_LF;
if (m_pMyVehicle->bLowVehicle)
rollDoorAssoc = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ROLLDOOR_LOW);
else
rollDoorAssoc = CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_ROLLDOOR);
2020-04-09 18:50:24 +00:00
rollDoorAssoc->SetFinishCallback(PedAnimDoorCloseRollingCB, this);
}
}
2020-04-09 18:50:24 +00:00
}
}
return;
}
if (m_objective == OBJECTIVE_NONE)
m_nMoveState = PEDMOVE_STILL;
if (bIsLanding)
RunningLand(padUsed);
if (padUsed && padUsed->WeaponJustDown() && !TheCamera.Using1stPersonWeaponMode()) {
2020-04-09 18:50:24 +00:00
// ...Really?
eWeaponType playerWeapon = FindPlayerPed()->GetWeapon()->m_eWeaponType;
2020-06-20 17:26:27 +00:00
if (playerWeapon == WEAPONTYPE_SNIPERRIFLE || playerWeapon == WEAPONTYPE_LASERSCOPE) {
2020-04-09 18:50:24 +00:00
DMAudio.PlayFrontEndSound(SOUND_WEAPON_SNIPER_SHOT_NO_ZOOM, 0);
} else if (playerWeapon == WEAPONTYPE_ROCKETLAUNCHER) {
DMAudio.PlayFrontEndSound(SOUND_WEAPON_ROCKET_SHOT_NO_ZOOM, 0);
}
}
switch (m_nPedState) {
case PED_NONE:
case PED_IDLE:
case PED_FLEE_POS:
case PED_FLEE_ENTITY:
case PED_ATTACK:
case PED_FIGHT:
case PED_AIM_GUN:
2020-06-20 17:26:27 +00:00
case PED_ANSWER_MOBILE:
if (!RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_BLOCK) && !m_attachedTo) {
if (TheCamera.Using1stPersonWeaponMode()) {
if (padUsed)
PlayerControlFighter(padUsed);
} else if (TheCamera.Cams[0].Using3rdPersonMouseCam()
#ifdef FREE_CAM
&& !CCamera::bFreeCam
#endif
) {
2020-04-09 18:50:24 +00:00
if (padUsed)
PlayerControl1stPersonRunAround(padUsed);
2020-04-09 18:50:24 +00:00
} else if (m_nPedState == PED_FIGHT) {
if (padUsed)
PlayerControlFighter(padUsed);
2020-04-09 18:50:24 +00:00
} else if (padUsed) {
PlayerControlZelda(padUsed);
}
}
2020-06-20 17:26:27 +00:00
if (IsPedInControl() && m_nPedState != PED_ANSWER_MOBILE && padUsed)
2020-04-09 18:50:24 +00:00
ProcessPlayerWeapon(padUsed);
break;
case PED_SEEK_ENTITY:
m_vecSeekPos = m_pSeekTarget->GetPosition();
// fall through
case PED_SEEK_POS:
switch (m_nMoveState) {
case PEDMOVE_WALK:
m_fMoveSpeed = 1.0f;
break;
case PEDMOVE_RUN:
m_fMoveSpeed = 1.8f;
break;
case PEDMOVE_SPRINT:
m_fMoveSpeed = 2.5f;
break;
default:
m_fMoveSpeed = 0.0f;
break;
}
SetRealMoveAnim();
if (Seek()) {
RestorePreviousState();
SetMoveState(PEDMOVE_STILL);
}
break;
case PED_SNIPER_MODE:
2020-06-20 14:30:28 +00:00
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_SNIPERRIFLE || GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE) {
2020-04-09 18:50:24 +00:00
if (padUsed)
2020-06-20 14:30:28 +00:00
PlayerControlSniper(padUsed);
2020-04-09 18:50:24 +00:00
} else if (padUsed) {
2020-06-20 14:30:28 +00:00
PlayerControlM16(padUsed);
2020-04-09 18:50:24 +00:00
}
break;
case PED_SEEK_CAR:
case PED_SEEK_IN_BOAT:
if (bVehEnterDoorIsBlocked || bKindaStayInSamePlace) {
m_fMoveSpeed = 0.0f;
} else {
2020-04-19 16:34:08 +00:00
m_fMoveSpeed = Min(2.0f, 2.0f * (m_vecSeekPos - GetPosition()).Magnitude2D());
2020-04-09 18:50:24 +00:00
}
if (padUsed && !padUsed->ArePlayerControlsDisabled()) {
if (padUsed->GetTarget() || padUsed->GetLeftStickXJustDown() || padUsed->GetLeftStickYJustDown() ||
padUsed->GetDPadUpJustDown() || padUsed->GetDPadDownJustDown() || padUsed->GetDPadLeftJustDown() ||
padUsed->GetDPadRightJustDown()) {
RestorePreviousState();
if (m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) {
RestorePreviousObjective();
}
}
}
if (padUsed && padUsed->GetSprint())
m_nMoveState = PEDMOVE_SPRINT;
SetRealMoveAnim();
break;
case PED_JUMP:
if (padUsed)
PlayerControlZelda(padUsed);
if (bIsLanding)
break;
// This has been added later it seems
return;
case PED_FALL:
case PED_GETUP:
case PED_ENTER_TRAIN:
case PED_EXIT_TRAIN:
case PED_CARJACK:
case PED_DRAG_FROM_CAR:
case PED_ENTER_CAR:
case PED_STEAL_CAR:
case PED_EXIT_CAR:
ClearWeaponTarget();
break;
case PED_ARRESTED:
if (m_nLastPedState == PED_DRAG_FROM_CAR && m_pVehicleAnim)
BeingDraggedFromCar();
break;
2020-12-15 02:16:29 +00:00
default:
break;
2020-04-09 18:50:24 +00:00
}
2020-06-20 17:26:27 +00:00
if (padUsed && IsPedShootable() && m_nPedState != PED_ANSWER_MOBILE && m_nLastPedState != PED_ANSWER_MOBILE) {
2020-04-09 18:50:24 +00:00
ProcessWeaponSwitch(padUsed);
2020-05-17 17:36:48 +00:00
GetWeapon()->Update(m_audioEntityId, this);
2020-04-09 18:50:24 +00:00
}
ProcessAnimGroups();
if (padUsed) {
if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FOLLOWPED
&& TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking == LOOKING_BEHIND) {
m_lookTimer = 0;
float camAngle = CGeneral::LimitRadianAngle(TheCamera.Cams[TheCamera.ActiveCam].Front.Heading());
float angleBetweenPlayerAndCam = Abs(camAngle - m_fRotationCur);
if (m_nPedState != PED_ATTACK && angleBetweenPlayerAndCam > DEGTORAD(30.0f) && angleBetweenPlayerAndCam < DEGTORAD(330.0f)) {
2020-04-09 18:50:24 +00:00
if (angleBetweenPlayerAndCam > DEGTORAD(150.0f) && angleBetweenPlayerAndCam < DEGTORAD(210.0f)) {
float rightTurnAngle = CGeneral::LimitRadianAngle(m_fRotationCur - DEGTORAD(150.0f));
float leftTurnAngle = CGeneral::LimitRadianAngle(DEGTORAD(150.0f) + m_fRotationCur);
if (m_fLookDirection == 999999.0f || bIsDucking)
2020-04-09 18:50:24 +00:00
camAngle = rightTurnAngle;
else if (Abs(rightTurnAngle - m_fLookDirection) < Abs(leftTurnAngle - m_fLookDirection))
camAngle = rightTurnAngle;
else
camAngle = leftTurnAngle;
2020-04-09 18:50:24 +00:00
}
SetLookFlag(camAngle, true);
SetLookTimer(CTimer::GetTimeStepInMilliseconds() * 5.0f);
} else {
ClearLookFlag();
}
}
}
if (m_nMoveState == PEDMOVE_SPRINT && bIsLooking) {
ClearLookFlag();
SetLookTimer(250);
}
if (m_vecMoveSpeed.Magnitude2D() < 0.1f) {
if (m_nSpeedTimer) {
if (CTimer::GetTimeInMilliseconds() > m_nSpeedTimer)
m_bSpeedTimerFlag = true;
} else {
m_nSpeedTimer = CTimer::GetTimeInMilliseconds() + 500;
}
} else {
m_nSpeedTimer = 0;
m_bSpeedTimerFlag = false;
}
if (bDontAllowWeaponChange && FindPlayerPed() == this) {
if (!CPad::GetPad(0)->GetTarget())
bDontAllowWeaponChange = false;
}
2020-06-20 17:26:27 +00:00
if (m_nPedState != PED_SNIPER_MODE && (GetWeapon()->m_eWeaponState == WEAPONSTATE_FIRING || m_nPedState == PED_ATTACK))
m_nPadDownPressedInMilliseconds = CTimer::GetTimeInMilliseconds();
if (!bIsVisible)
UpdateRpHAnim();
2020-04-09 18:50:24 +00:00
}
2020-05-02 15:02:17 +00:00
// --MIAMI: Done
2020-05-23 15:04:33 +00:00
bool
CPlayerPed::DoesPlayerWantNewWeapon(eWeaponType weapon, bool onlyIfSlotIsEmpty)
{
// GetPadFromPlayer(); // unused
2020-05-23 15:04:33 +00:00
uint32 slot = CWeaponInfo::GetWeaponInfo(weapon)->m_nWeaponSlot;
if (!HasWeaponSlot(slot) || GetWeapon(slot).m_eWeaponType == weapon)
return true;
if (onlyIfSlotIsEmpty)
return false;
// Check if he's using that slot right now.
return m_nPedState != PED_ATTACK && m_nPedState != PED_AIM_GUN || slot != m_currentWeapon;
}
void
CPlayerPed::PlayIdleAnimations(CPad *padUsed)
{
CAnimBlendAssociation* assoc;
if (TheCamera.m_WideScreenOn || bIsDucking)
return;
struct animAndGroup {
AnimationId animId;
AssocGroupId groupId;
};
const animAndGroup idleAnims[] = {
{ANIM_IDLE_STRETCH, ASSOCGRP_PLAYER_IDLE},
{ANIM_IDLE_TIME, ASSOCGRP_PLAYER_IDLE},
{ANIM_IDLE_SHOULDER, ASSOCGRP_PLAYER_IDLE},
{ANIM_IDLE_STRETCH_LEG, ASSOCGRP_PLAYER_IDLE},
{ANIM_XPRESS_SCRATCH, ASSOCGRP_STD},
};
static int32 lastTime = 0;
static int32 lastAnim = -1;
bool hasIdleAnim = false;
CAnimBlock *idleAnimBlock = CAnimManager::GetAnimationBlock(idleAnimBlockIndex);
uint32 sinceLastInput = padUsed->InputHowLongAgo();
if (sinceLastInput <= 30000) {
if (idleAnimBlock->isLoaded) {
for (assoc = RpAnimBlendClumpGetFirstAssociation(GetClump()); assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) {
if (assoc->flags & ASSOC_IDLE) {
hasIdleAnim = true;
assoc->blendDelta = -8.0f;
}
}
if (!hasIdleAnim)
CStreaming::RemoveAnim(idleAnimBlockIndex);
} else {
lastTime = 0;
}
} else {
CStreaming::RequestAnim(idleAnimBlockIndex, STREAMFLAGS_DONT_REMOVE);
if (idleAnimBlock->isLoaded) {
for(CAnimBlendAssociation *assoc = RpAnimBlendClumpGetFirstAssociation(GetClump()); assoc; assoc = RpAnimBlendGetNextAssociation(assoc)) {
int firstIdle = idleAnimBlock->firstIndex;
int index = assoc->hierarchy - CAnimManager::GetAnimation(0);
if (index >= firstIdle && index < firstIdle + idleAnimBlock->numAnims) {
hasIdleAnim = true;
break;
}
}
if (!hasIdleAnim && !bIsLooking && !bIsRestoringLook && sinceLastInput - lastTime > 25000) {
int anim;
do
anim = CGeneral::GetRandomNumberInRange(0, ARRAY_SIZE(idleAnims));
while (lastAnim == anim);
assoc = CAnimManager::BlendAnimation(GetClump(), idleAnims[anim].groupId, idleAnims[anim].animId, 8.0f);
assoc->flags |= ASSOC_IDLE;
lastAnim = anim;
lastTime = sinceLastInput;
}
}
}
}
// --MIAMI: Done
void
CPlayerPed::SetNearbyPedsToInteractWithPlayer(void)
{
if (CGame::noProstitutes)
return;
for (int i = 0; i < m_numNearPeds; ++i) {
CPed *nearPed = m_nearPeds[i];
if (nearPed && nearPed->m_objectiveTimer < CTimer::GetTimeInMilliseconds() && !CTheScripts::IsPlayerOnAMission()) {
int mi = nearPed->GetModelIndex();
if (CPopulation::CanSolicitPlayerOnFoot(mi)) {
CVector distToMe = nearPed->GetPosition() - GetPosition();
CVector dirToMe = GetPosition() - nearPed->GetPosition();
dirToMe.Normalise();
if (DotProduct(dirToMe, nearPed->GetForward()) > 0.707 && DotProduct(GetForward(), nearPed->GetForward()) < -0.707 // those are double
&& distToMe.MagnitudeSqr() < 9.0f && nearPed->m_objective == OBJECTIVE_NONE) {
nearPed->SetObjective(OBJECTIVE_SOLICIT_FOOT, this);
nearPed->m_objectiveTimer = CTimer::GetTimeInMilliseconds() + 10000;
nearPed->Say(SOUND_PED_SOLICIT);
}
} else if (CPopulation::CanSolicitPlayerInCar(mi)) {
if (InVehicle() && m_pMyVehicle->IsVehicleNormal()) {
if (m_pMyVehicle->IsCar()) {
CVector distToVeh = nearPed->GetPosition() - m_pMyVehicle->GetPosition();
if (distToVeh.MagnitudeSqr() < 25.0f && m_pMyVehicle->IsRoomForPedToLeaveCar(CAR_DOOR_LF, nil) && nearPed->m_objective == OBJECTIVE_NONE) {
nearPed->SetObjective(OBJECTIVE_SOLICIT_VEHICLE, m_pMyVehicle);
}
}
}
}
}
}
}
// --MIAMI: Done
void
CPlayerPed::UpdateMeleeAttackers(void)
{
CVector attackCoord;
if (((CTimer::GetFrameCounter() + m_randomSeed + 7) & 3) == 0) {
GetMeleeAttackCoords(attackCoord, m_nAttackDirToCheck, 2.0f);
// Check if there is any vehicle/building inbetween us and m_nAttackDirToCheck. Peds will be able to attack us from those available directions.
if (CWorld::GetIsLineOfSightClear(GetPosition(), attackCoord, true, true, false, true, false, false, false)
&& !CWorld::TestSphereAgainstWorld(attackCoord, 0.4f, m_pMeleeList[m_nAttackDirToCheck], true, true, false, true, false, false)) {
if (m_pMeleeList[m_nAttackDirToCheck] == this)
m_pMeleeList[m_nAttackDirToCheck] = nil; // mark it as available
} else {
m_pMeleeList[m_nAttackDirToCheck] = this; // slot not available. useful for m_bNoPosForMeleeAttack
}
if (++m_nAttackDirToCheck >= ARRAY_SIZE(m_pMeleeList))
m_nAttackDirToCheck = 0;
}
// 6 directions
for (int i = 0; i < ARRAY_SIZE(m_pMeleeList); ++i) {
CPed *victim = m_pMeleeList[i];
if (victim && victim != this) {
if (victim->m_nPedState != PED_DEAD && victim->m_pedInObjective == this) {
if (victim->m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT || victim->m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS || victim->m_objective == OBJECTIVE_KILL_CHAR_ON_BOAT) {
GetMeleeAttackCoords(attackCoord, i, 2.0f);
if ((attackCoord - GetPosition()).MagnitudeSqr() > 12.25f)
m_pMeleeList[i] = nil;
} else {
m_pMeleeList[i] = nil;
}
} else {
m_pMeleeList[i] = nil;
}
}
}
m_bNoPosForMeleeAttack = m_pMeleeList[0] == this && m_pMeleeList[1] == this && m_pMeleeList[2] == this
#ifdef FIX_BUGS
&& m_pMeleeList[3] == this
#endif
&& m_pMeleeList[4] == this && m_pMeleeList[5] == this;
}
// --MIAMI: Done
2020-06-15 20:43:20 +00:00
void
CPlayerPed::RemovePedFromMeleeList(CPed *ped)
{
int i = 0;
for (; m_pMeleeList[i] != ped; i++) {
if (i >= ARRAY_SIZE(m_pMeleeList))
return;
}
m_pMeleeList[i] = nil;
ped->m_attackTimer = 0;
}
// --MIAMI: Done
void
CPlayerPed::GetMeleeAttackCoords(CVector& coords, int8 dir, float dist)
{
coords = GetPosition();
switch (dir) {
case 0:
coords.y += dist;
break;
case 1:
coords.x += Sqrt(3.f / 4.f) * dist;
coords.y += 0.5f * dist;
break;
case 2:
coords.x += Sqrt(3.f / 4.f) * dist;
coords.y -= 0.5f * dist;
break;
case 3:
coords.y -= dist;
break;
case 4:
coords.x -= Sqrt(3.f / 4.f) * dist;
coords.y -= 0.5f * dist;
break;
case 5:
coords.x -= Sqrt(3.f / 4.f) * dist;
coords.y += 0.5f * dist;
break;
default:
break;
}
}
// --MIAMI: Done
int32
CPlayerPed::FindMeleeAttackPoint(CPed *victim, CVector &dist, uint32 &endOfAttackOut)
{
endOfAttackOut = 0;
bool thereIsAnEmptySlot = false;
int dirToAttack = -1;
for (int i = 0; i < ARRAY_SIZE(m_pMeleeList); i++) {
CPed* pedAtThisDir = m_pMeleeList[i];
if (pedAtThisDir) {
if (pedAtThisDir == victim) {
dirToAttack = i;
} else {
if (pedAtThisDir->m_attackTimer > endOfAttackOut)
endOfAttackOut = pedAtThisDir->m_attackTimer;
}
} else {
thereIsAnEmptySlot = true;
}
}
// We don't have victim ped in our melee list
if (dirToAttack == -1 && thereIsAnEmptySlot) {
float angle = Atan2(-dist.x, -dist.y);
float adjustedAngle = angle + DEGTORAD(30.0f);
if (adjustedAngle < 0.f)
adjustedAngle += TWOPI;
int wantedDir = Floor(adjustedAngle / DEGTORAD(60.0f));
// And we have another ped at the direction of victim ped, so store victim to next empty direction to it's real direction. (Bollocks)
if (m_pMeleeList[wantedDir]) {
int closestDirToPreferred = -99;
int preferredDir = wantedDir;
for (int i = 0; i < ARRAY_SIZE(m_pMeleeList); i++) {
if (!m_pMeleeList[i]) {
if (Abs(i - preferredDir) < Abs(closestDirToPreferred - preferredDir))
closestDirToPreferred = i;
}
}
if (closestDirToPreferred > 0)
dirToAttack = closestDirToPreferred;
} else {
// Luckily the direction of victim ped is already empty, good
dirToAttack = wantedDir;
}
if (dirToAttack != -1) {
m_pMeleeList[dirToAttack] = victim;
victim->RegisterReference((CEntity**) &m_pMeleeList[dirToAttack]);
if (endOfAttackOut > CTimer::GetTimeInMilliseconds())
victim->m_attackTimer = endOfAttackOut + CGeneral::GetRandomNumberInRange(1000, 2000);
else
victim->m_attackTimer = CTimer::GetTimeInMilliseconds() + CGeneral::GetRandomNumberInRange(500, 1000);
}
}
return dirToAttack;
}
2020-05-02 15:02:17 +00:00
#ifdef COMPATIBLE_SAVES
2020-05-13 13:24:00 +00:00
#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
2020-05-02 15:02:17 +00:00
void
CPlayerPed::Save(uint8*& buf)
{
CPed::Save(buf);
SkipSaveBuf(buf, 16);
2020-05-13 13:24:00 +00:00
CopyToBuf(buf, m_fMaxStamina);
2020-05-02 15:02:17 +00:00
SkipSaveBuf(buf, 28);
2020-05-13 13:24:00 +00:00
CopyToBuf(buf, m_nTargettableObjects[0]);
CopyToBuf(buf, m_nTargettableObjects[1]);
CopyToBuf(buf, m_nTargettableObjects[2]);
CopyToBuf(buf, m_nTargettableObjects[3]);
2020-10-17 17:45:07 +00:00
SkipSaveBuf(buf, 164);
2020-05-02 15:02:17 +00:00
}
void
CPlayerPed::Load(uint8*& buf)
{
CPed::Load(buf);
SkipSaveBuf(buf, 16);
2020-05-13 13:24:00 +00:00
CopyFromBuf(buf, m_fMaxStamina);
2020-05-02 15:02:17 +00:00
SkipSaveBuf(buf, 28);
2020-05-13 13:24:00 +00:00
CopyFromBuf(buf, m_nTargettableObjects[0]);
CopyFromBuf(buf, m_nTargettableObjects[1]);
CopyFromBuf(buf, m_nTargettableObjects[2]);
CopyFromBuf(buf, m_nTargettableObjects[3]);
2020-10-17 15:50:16 +00:00
SkipSaveBuf(buf, 164);
2020-05-02 15:02:17 +00:00
}
2020-05-13 13:24:00 +00:00
#undef CopyFromBuf
#undef CopyToBuf
2020-05-02 15:02:17 +00:00
#endif