Weapon fixes

This commit is contained in:
eray orçunus 2020-05-16 15:07:09 +03:00
parent 793a6a6d7e
commit 40ee29fb99
7 changed files with 59 additions and 31 deletions

View File

@ -679,7 +679,7 @@ CPed::GiveWeapon(eWeaponType weaponType, uint32 ammo, bool unused)
if (weaponType < WEAPONTYPE_LAST_WEAPONTYPE && 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], (int32) GetWeapon(slot).m_nAmmoTotal);
GetWeapon(slot).m_nAmmoTotal = Min(CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType], GetWeapon(slot).m_nAmmoTotal);
} else {
GetWeapon(slot).m_nAmmoTotal = Min(99999, GetWeapon(slot).m_nAmmoTotal);
}
@ -1187,7 +1187,7 @@ CPed::FinishedReloadCB(CAnimBlendAssociation *reloadAssoc, void *arg)
}
} else if (weapon->m_bReloadLoop2Start && ped->bIsAttacking) {
CAnimBlendAssociation *fireAssoc =
CAnimManager::BlendAnimation(ped->GetClump(), weapon->m_AnimToPlay, weapon->m_bAnimDetonate ? ANIM_BOMBER : ANIM_WEAPON_FIRE, 8.0f);
CAnimManager::BlendAnimation(ped->GetClump(), weapon->m_AnimToPlay, GetPrimaryFireAnim(weapon), 8.0f);
fireAssoc->SetFinishCallback(FinishedAttackCB, ped);
fireAssoc->SetRun();
if (fireAssoc->currentTime != reloadAssoc->hierarchy->totalLength) {
@ -1302,6 +1302,7 @@ CPed::FinishedAttackCB(CAnimBlendAssociation *attackAssoc, void *arg)
}
}
// --MIAMI: Done
void
CPed::Attack(void)
{
@ -3874,12 +3875,7 @@ CPed::ClearAttackByRemovingAnim(void)
return;
CWeaponInfo *weapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
CAnimBlendAssociation *weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), weapon->m_bAnimDetonate ? ANIM_BOMBER : ANIM_WEAPON_FIRE);
// TODO(Miami): Remove when fighting got ported
if (!weaponAssoc) {
weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_PPUNCH);
}
CAnimBlendAssociation *weaponAssoc = RpAnimBlendClumpGetAssociation(GetClump(), GetPrimaryFireAnim(weapon));
if (!weaponAssoc) {
if (!!weapon->m_bCrouchFire)
@ -4882,15 +4878,15 @@ CPed::SetAmmo(eWeaponType weaponType, uint32 ammo)
if (slot == -1)
return;
GetWeapon(slot).m_nAmmoTotal += ammo;
GetWeapon(slot).m_nAmmoTotal = ammo;
if (weaponType < WEAPONTYPE_LAST_WEAPONTYPE && 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], (int32)GetWeapon(slot).m_nAmmoTotal);
GetWeapon(slot).m_nAmmoTotal = Min(CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType], GetWeapon(slot).m_nAmmoTotal);
} else {
GetWeapon(slot).m_nAmmoTotal = Min(99999, GetWeapon(slot).m_nAmmoTotal);
}
uint32 newClip = 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;
@ -4911,7 +4907,7 @@ CPed::GrantAmmo(eWeaponType weaponType, uint32 ammo)
if (weaponType < WEAPONTYPE_LAST_WEAPONTYPE && 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], (int32)GetWeapon(slot).m_nAmmoTotal);
GetWeapon(slot).m_nAmmoTotal = Min(CWeaponInfo::ms_aMaxAmmoForWeapon[weaponType], GetWeapon(slot).m_nAmmoTotal);
} else {
GetWeapon(slot).m_nAmmoTotal = Min(99999, GetWeapon(slot).m_nAmmoTotal);
}
@ -6341,7 +6337,7 @@ CPed::CreateDeadPedWeaponPickups(void)
eWeaponType weapon = GetWeapon(i).m_eWeaponType;
int weaponAmmo = GetWeapon(i).m_nAmmoTotal;
if (weapon == WEAPONTYPE_UNARMED || weapon == WEAPONTYPE_DETONATOR || weaponAmmo == 0)
if (weapon == WEAPONTYPE_UNARMED || weapon == WEAPONTYPE_DETONATOR || (weaponAmmo == 0 && !GetWeapon(i).IsTypeMelee()))
continue;
angleToPed = i * 1.75f;

View File

@ -704,6 +704,7 @@ public:
void RemoveWeaponAnims(int, float);
void CreateDeadPedMoney(void);
void CreateDeadPedWeaponPickups(void);
// void CreateDeadPedPickupCoors(float *x, float *y, float *z);
void SetAttackTimer(uint32);
void SetBeingDraggedFromCar(CVehicle*, uint32, bool);
void SetRadioStation(void);
@ -899,7 +900,7 @@ public:
if (m_nPedType == PEDTYPE_COP && !!weapon->m_bCop3rd)
return ANIM_WEAPON_FIRE_3RD;
else
return weapon->m_bAnimDetonate ? ANIM_BOMBER : ANIM_WEAPON_FIRE;
return GetPrimaryFireAnim(weapon);
}
static AnimationId GetFireAnimGround(CWeaponInfo* weapon, bool kickFloorIfNone = true) {
@ -916,6 +917,17 @@ public:
else
return (AnimationId)0;
}
static AnimationId GetPrimaryFireAnim(CWeaponInfo* weapon) {
// TODO(Miami): Revert that when weapons got ported
if (weapon->m_AnimToPlay == ASSOCGRP_STD)
return ANIM_FIGHT_PPUNCH;
if (weapon->m_bAnimDetonate)
return ANIM_BOMBER;
else
return ANIM_WEAPON_FIRE;
}
// --
// My additions, because there were many, many instances of that.

View File

@ -293,9 +293,12 @@ bool
CPedIK::PointGunAtPosition(CVector const& position)
{
// TODO(MIAMI): special cases for some weapons
RwV3d armPos;
GetComponentPosition(&armPos, PED_UPPERARMR);
return PointGunInDirection(
CGeneral::GetRadianAngleBetweenPoints(position.x, position.y, m_ped->GetPosition().x, m_ped->GetPosition().y),
CGeneral::GetRadianAngleBetweenPoints(position.z, Distance2D(m_ped->GetPosition(), position.x, position.y), m_ped->GetPosition().z, 0.0f));
CGeneral::GetRadianAngleBetweenPoints(position.z, Distance2D(m_ped->GetPosition(), position.x, position.y), armPos.z, 0.0f));
}
bool

View File

@ -92,6 +92,11 @@ CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1)
void CPlayerPed::ClearWeaponTarget()
{
if (m_nPedType == PEDTYPE_PLAYER1) {
// TODO(Miami)
// if (m_pPointGunAt)
// m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt);
m_pPointGunAt = nil;
TheCamera.ClearPlayerWeaponMode();
CWeaponEffects::ClearCrossHair();
@ -213,13 +218,15 @@ CPlayerPed::MakeChangesForNewWeapon(eWeaponType weapon)
TheCamera.ClearPlayerWeaponMode();
}
SetCurrentWeapon(weapon);
m_nSelectedWepSlot = m_currentWeapon;
GetWeapon()->m_nAmmoInClip = Min(GetWeapon()->m_nAmmoTotal, CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nAmountofAmmunition);
if (!(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAim))
ClearWeaponTarget();
CAnimBlendAssociation* weaponAnim = RpAnimBlendClumpGetAssociation(GetClump(), CWeaponInfo::GetWeaponInfo(WEAPONTYPE_SNIPERRIFLE)->m_bAnimDetonate ? 62 : 205);
// WEAPONTYPE_SNIPERRIFLE? Wut?
CAnimBlendAssociation* weaponAnim = RpAnimBlendClumpGetAssociation(GetClump(), GetPrimaryFireAnim(CWeaponInfo::GetWeaponInfo(WEAPONTYPE_SNIPERRIFLE)));
if (weaponAnim) {
weaponAnim->SetRun();
weaponAnim->flags |= ASSOC_FADEOUTWHENDONE;
@ -666,7 +673,10 @@ CPlayerPed::ProcessWeaponSwitch(CPad *padUsed)
for (m_nSelectedWepSlot = m_currentWeapon - 1; ; --m_nSelectedWepSlot) {
if (m_nSelectedWepSlot < 0)
m_nSelectedWepSlot = 9;
m_nSelectedWepSlot = TOTAL_WEAPON_SLOTS - 1;
if (m_nSelectedWepSlot == 0)
break;
if (HasWeaponSlot(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) {
break;
@ -690,11 +700,16 @@ spentAmmoCheck:
else
m_nSelectedWepSlot = 2;
// BUG: m_nSelectedWepSlot is slot in VC but they compared against weapon types, lol.
for (; m_nSelectedWepSlot >= 0; --m_nSelectedWepSlot) {
if (m_nSelectedWepSlot == WEAPONTYPE_BASEBALLBAT && GetWeapon(6).m_eWeaponType == WEAPONTYPE_BASEBALLBAT
// BUG: m_nSelectedWepSlot and GetWeapon(..) takes slot in VC but they compared them against weapon types in whole condition! jeez
#ifdef FIX_BUGS
if (m_nSelectedWepSlot == 1 || GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0 && m_nSelectedWepSlot != 2) {
#else
if (m_nSelectedWepSlot == WEAPONTYPE_BASEBALLBAT && GetWeapon(WEAPONTYPE_BASEBALLBAT).m_eWeaponType == WEAPONTYPE_BASEBALLBAT
|| GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0
/*&& m_nSelectedWepSlot != WEAPONTYPE_MOLOTOV && m_nSelectedWepSlot != WEAPONTYPE_GRENADE && m_nSelectedWepSlot != WEAPONTYPE_TEARGAS */) {
&& m_nSelectedWepSlot != WEAPONTYPE_MOLOTOV && m_nSelectedWepSlot != WEAPONTYPE_GRENADE && m_nSelectedWepSlot != WEAPONTYPE_TEARGAS) {
#endif
goto switchDetectDone;
}
}
@ -1152,7 +1167,7 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed)
m_nSelectedWepSlot == m_currentWeapon && m_nMoveState != PEDMOVE_SPRINT) {
// Weapons except throwable and melee ones
if (weaponInfo->m_bCanAim || weaponInfo->m_b1stPerson || weaponInfo->m_bExpands) {
if (weaponInfo->m_nWeaponSlot > 2) {
if ((padUsed->GetTarget() && weaponInfo->m_bCanAimWithArm) || padUsed->GetWeapon()) {
float limitedCam = CGeneral::LimitRadianAngle(-TheCamera.Orientation);

View File

@ -2312,13 +2312,15 @@ CWeapon::BlowUpExplosiveThings(CEntity *thing)
bool
CWeapon::HasWeaponAmmoToBeUsed(void)
{
switch (m_eWeaponType) {
case WEAPONTYPE_UNARMED:
case WEAPONTYPE_BASEBALLBAT:
return true;
default:
return m_nAmmoTotal != 0;
}
// FIX: This is better (not bug tho)
#if 0
if (m_eWeaponType <= WEAPONTYPE_CHAINSAW)
#else
if (CWeaponInfo::GetWeaponInfo(m_eWeaponType)->m_eWeaponFire == WEAPON_FIRE_MELEE)
#endif
return true;
else
return m_nAmmoTotal != 0;
}
bool

View File

@ -16,8 +16,8 @@ class CWeapon
public:
eWeaponType m_eWeaponType;
eWeaponState m_eWeaponState;
uint32 m_nAmmoInClip;
uint32 m_nAmmoTotal;
int32 m_nAmmoInClip;
int32 m_nAmmoTotal;
uint32 m_nTimer;
bool m_bAddRotOffset;

View File

@ -14,7 +14,7 @@ public:
float m_fRange;
uint32 m_nFiringRate;
uint32 m_nReload;
uint32 m_nAmountofAmmunition;
int32 m_nAmountofAmmunition;
uint32 m_nDamage;
float m_fSpeed;
float m_fRadius;