summaryrefslogtreecommitdiffstats
path: root/src/weapons
diff options
context:
space:
mode:
Diffstat (limited to 'src/weapons')
-rw-r--r--src/weapons/BulletInfo.cpp6
-rw-r--r--src/weapons/Explosion.cpp5
-rw-r--r--src/weapons/ProjectileInfo.cpp6
-rw-r--r--src/weapons/ShotInfo.cpp6
-rw-r--r--src/weapons/Weapon.cpp24
-rw-r--r--src/weapons/WeaponEffects.cpp2
-rw-r--r--src/weapons/WeaponInfo.cpp73
-rw-r--r--src/weapons/WeaponInfo.h31
8 files changed, 75 insertions, 78 deletions
diff --git a/src/weapons/BulletInfo.cpp b/src/weapons/BulletInfo.cpp
index e87a7407..bfe27e18 100644
--- a/src/weapons/BulletInfo.cpp
+++ b/src/weapons/BulletInfo.cpp
@@ -121,7 +121,7 @@ void CBulletInfo::Update(void)
if (pPed->DoesLOSBulletHitPed(point)) {
if (pPed->IsPedInControl() && !pPed->bIsDucking) {
pPed->ClearAttackByRemovingAnim();
- CAnimBlendAssociation* pAnim = CAnimManager::AddAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_SHOT_FRONT_PARTIAL);
+ CAnimBlendAssociation* pAnim = CAnimManager::AddAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HITBYGUN_FRONT);
pAnim->SetBlend(0.0f, 8.0f);
}
pPed->InflictDamage(pBullet->m_pSource, pBullet->m_eWeaponType, pBullet->m_nDamage, (ePedPieceTypes)point.pieceB, pPed->GetLocalDirection(pPed->GetPosition() - point.point));
@@ -146,9 +146,9 @@ void CBulletInfo::Update(void)
if (pPed->GetPedState() == PED_DEAD) {
CAnimBlendAssociation* pAnim;
if (RpAnimBlendClumpGetFirstAssociation(pPed->GetClump(), ASSOC_FRONTAL))
- pAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_FLOOR_HIT_F, 8.0f);
+ pAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HIT_FLOOR_FRONT, 8.0f);
else
- pAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_FLOOR_HIT, 8.0f);
+ pAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HIT_FLOOR, 8.0f);
if (pAnim) {
pAnim->SetCurrentTime(0.0f);
pAnim->flags |= ASSOC_RUNNING;
diff --git a/src/weapons/Explosion.cpp b/src/weapons/Explosion.cpp
index d0a68279..8ab81748 100644
--- a/src/weapons/Explosion.cpp
+++ b/src/weapons/Explosion.cpp
@@ -104,7 +104,12 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT
#endif
int n = 0;
+#ifdef FIX_BUGS
+ while (n < ARRAY_SIZE(gaExplosion) && gaExplosion[n].m_nIteration != 0)
+#else
+ // array overrun is UB
while (gaExplosion[n].m_nIteration != 0 && n < ARRAY_SIZE(gaExplosion))
+#endif
n++;
if (n == ARRAY_SIZE(gaExplosion))
return false;
diff --git a/src/weapons/ProjectileInfo.cpp b/src/weapons/ProjectileInfo.cpp
index b56e3a29..da00b87a 100644
--- a/src/weapons/ProjectileInfo.cpp
+++ b/src/weapons/ProjectileInfo.cpp
@@ -128,8 +128,12 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos,
}
int i = 0;
+#ifdef FIX_BUGS
+ while (i < ARRAY_SIZE(gaProjectileInfo) && gaProjectileInfo[i].m_bInUse) i++;
+#else
+ // array overrun is UB
while (gaProjectileInfo[i].m_bInUse && i < ARRAY_SIZE(gaProjectileInfo)) i++;
-
+#endif
if (i == ARRAY_SIZE(gaProjectileInfo))
return false;
diff --git a/src/weapons/ShotInfo.cpp b/src/weapons/ShotInfo.cpp
index c0ab9ac1..e604093c 100644
--- a/src/weapons/ShotInfo.cpp
+++ b/src/weapons/ShotInfo.cpp
@@ -76,7 +76,7 @@ CShotInfo::AddShot(CEntity *sourceEntity, eWeaponType weapon, CVector startPos,
gaShotInfo[slot].m_areaAffected.z += CShotInfo::ms_afRandTable[CGeneral::GetRandomNumber() % ARRAY_SIZE(ms_afRandTable)];
}
gaShotInfo[slot].m_areaAffected.Normalise();
- if (weaponInfo->m_bRandSpeed)
+ if (weaponInfo->IsFlagSet(WEAPONFLAG_RAND_SPEED))
gaShotInfo[slot].m_areaAffected *= CShotInfo::ms_afRandTable[CGeneral::GetRandomNumber() % ARRAY_SIZE(ms_afRandTable)] + weaponInfo->m_fSpeed;
else
gaShotInfo[slot].m_areaAffected *= weaponInfo->m_fSpeed;
@@ -117,10 +117,10 @@ CShotInfo::Update()
shot.m_inUse = false;
}
- if (weaponInfo->m_bSlowsDown)
+ if (weaponInfo->IsFlagSet(WEAPONFLAG_SLOWS_DOWN))
shot.m_areaAffected *= pow(0.96, CTimer::GetTimeStep()); // FRAMERATE
- if (weaponInfo->m_bExpands)
+ if (weaponInfo->IsFlagSet(WEAPONFLAG_EXPANDS))
shot.m_radius += 0.075f * CTimer::GetTimeStep();
shot.m_startPos += CTimer::GetTimeStep() * shot.m_areaAffected;
diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp
index dc15485e..dab510be 100644
--- a/src/weapons/Weapon.cpp
+++ b/src/weapons/Weapon.cpp
@@ -385,7 +385,7 @@ CWeapon::FireMelee(CEntity *shooter, CVector &fireSource)
if ( victimPed->bUsesCollision || victimPed->Dead() || victimPed->Driving() )
{
CVector victimPedPos = victimPed->GetPosition();
- if ( SQR(victimPedRadius) > (victimPedPos-(*fireSource)).MagnitudeSqr() )
+ if ( SQR(victimPedRadius) > (victimPedPos-fireSource).MagnitudeSqr() )
{
CVector collisionDist;
@@ -393,7 +393,7 @@ CWeapon::FireMelee(CEntity *shooter, CVector &fireSource)
while ( s < victimPedCol->numSpheres )
{
CColSphere *sphere = &victimPedCol->spheres[s];
- collisionDist = victimPedPos+sphere->center-(*fireSource);
+ collisionDist = victimPedPos+sphere->center-fireSource;
if ( SQR(sphere->radius + info->m_fRadius) > collisionDist.MagnitudeSqr() )
{
@@ -473,9 +473,9 @@ CWeapon::FireMelee(CEntity *shooter, CVector &fireSource)
victimPed->ApplyMoveForce(posOffset.x*-5.0f, posOffset.y*-5.0f, 3.0f);
if ( isBat && victimPed->IsPlayer() )
- victimPed->SetFall(3000, AnimationId(ANIM_KO_SKID_FRONT + localDir), false);
+ victimPed->SetFall(3000, AnimationId(ANIM_STD_HIGHIMPACT_FRONT + localDir), false);
else
- victimPed->SetFall(1500, AnimationId(ANIM_KO_SKID_FRONT + localDir), false);
+ victimPed->SetFall(1500, AnimationId(ANIM_STD_HIGHIMPACT_FRONT + localDir), false);
shooterPed->m_pSeekTarget = victimPed;
shooterPed->m_pSeekTarget->RegisterReference(&shooterPed->m_pSeekTarget);
@@ -904,7 +904,7 @@ CWeapon::DoBulletImpact(CEntity *shooter, CEntity *victim,
victimPed->bIsStanding = false;
victimPed->ApplyMoveForce(posOffset.x*-5.0f, posOffset.y*-5.0f, 5.0f);
- victimPed->SetFall(1500, AnimationId(ANIM_KO_SKID_FRONT + localDir), false);
+ victimPed->SetFall(1500, AnimationId(ANIM_STD_HIGHIMPACT_FRONT + localDir), false);
victimPed->InflictDamage(shooter, m_eWeaponType, info->m_nDamage, (ePedPieceTypes)point->pieceB, localDir);
}
@@ -917,7 +917,7 @@ CWeapon::DoBulletImpact(CEntity *shooter, CEntity *victim,
{
victimPed->ClearAttackByRemovingAnim();
- CAnimBlendAssociation *asoc = CAnimManager::AddAnimation(victimPed->GetClump(), ASSOCGRP_STD, AnimationId(ANIM_SHOT_FRONT_PARTIAL + localDir));
+ CAnimBlendAssociation *asoc = CAnimManager::AddAnimation(victimPed->GetClump(), ASSOCGRP_STD, AnimationId(ANIM_STD_HITBYGUN_FRONT + localDir));
ASSERT(asoc!=nil);
asoc->blendAmount = 0.0f;
@@ -933,7 +933,7 @@ CWeapon::DoBulletImpact(CEntity *shooter, CEntity *victim,
{
victimPed->ClearAttackByRemovingAnim();
- CAnimBlendAssociation *asoc = CAnimManager::AddAnimation(victimPed->GetClump(), ASSOCGRP_STD, AnimationId(ANIM_SHOT_FRONT_PARTIAL + localDir));
+ CAnimBlendAssociation *asoc = CAnimManager::AddAnimation(victimPed->GetClump(), ASSOCGRP_STD, AnimationId(ANIM_STD_HITBYGUN_FRONT + localDir));
ASSERT(asoc!=nil);
asoc->blendAmount = 0.0f;
@@ -983,9 +983,9 @@ CWeapon::DoBulletImpact(CEntity *shooter, CEntity *victim,
{
CAnimBlendAssociation *asoc;
if ( RpAnimBlendClumpGetFirstAssociation(victimPed->GetClump(), ASSOC_FRONTAL) )
- asoc = CAnimManager::BlendAnimation(victimPed->GetClump(), ASSOCGRP_STD, ANIM_FLOOR_HIT_F, 8.0f);
+ asoc = CAnimManager::BlendAnimation(victimPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HIT_FLOOR_FRONT, 8.0f);
else
- asoc = CAnimManager::BlendAnimation(victimPed->GetClump(), ASSOCGRP_STD, ANIM_FLOOR_HIT, 8.0f);
+ asoc = CAnimManager::BlendAnimation(victimPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HIT_FLOOR, 8.0f);
if ( asoc )
{
@@ -1248,7 +1248,7 @@ CWeapon::FireShotgun(CEntity *shooter, CVector *fireSource)
victimPed->ApplyMoveForce(posOffset.x*-2.0f, posOffset.y*-2.0f, 0.0f);
if ( cantStandup )
- victimPed->SetFall(1500, AnimationId(ANIM_KO_SKID_FRONT + localDir), false);
+ victimPed->SetFall(1500, AnimationId(ANIM_STD_HIGHIMPACT_FRONT + localDir), false);
victimPed->InflictDamage(shooter, m_eWeaponType, info->m_nDamage, (ePedPieceTypes)point.pieceB, localDir);
@@ -1719,7 +1719,7 @@ CWeapon::FireInstantHitFromCar(CAutomobile *shooter, bool left)
victimPed->ReactToAttack(FindPlayerPed());
victimPed->ClearAttackByRemovingAnim();
- CAnimBlendAssociation *asoc = CAnimManager::AddAnimation(victimPed->GetClump(), ASSOCGRP_STD, AnimationId(ANIM_SHOT_FRONT_PARTIAL + localDir));
+ CAnimBlendAssociation *asoc = CAnimManager::AddAnimation(victimPed->GetClump(), ASSOCGRP_STD, AnimationId(ANIM_STD_HITBYGUN_FRONT + localDir));
ASSERT(asoc!=nil);
asoc->blendAmount = 0.0f;
asoc->blendDelta = 8.0f;
@@ -2089,7 +2089,7 @@ FireOneInstantHitRound(CVector *source, CVector *target, int32 damage)
victimPed->ClearAttackByRemovingAnim();
- CAnimBlendAssociation *asoc = CAnimManager::AddAnimation(victimPed->GetClump(), ASSOCGRP_STD, AnimationId(ANIM_SHOT_FRONT_PARTIAL + localDir));
+ CAnimBlendAssociation *asoc = CAnimManager::AddAnimation(victimPed->GetClump(), ASSOCGRP_STD, AnimationId(ANIM_STD_HITBYGUN_FRONT + localDir));
ASSERT(asoc!=nil);
asoc->blendAmount = 0.0f;
asoc->blendDelta = 8.0f;
diff --git a/src/weapons/WeaponEffects.cpp b/src/weapons/WeaponEffects.cpp
index 46195d2c..214ae9c7 100644
--- a/src/weapons/WeaponEffects.cpp
+++ b/src/weapons/WeaponEffects.cpp
@@ -46,7 +46,7 @@ void
CWeaponEffects::Shutdown(void)
{
RwTextureDestroy(gpCrossHairTex);
-#ifdef GTA3_1_1_PATCH
+#if GTA_VERSION >= GTA3_PC_11
gpCrossHairTex = nil;
#endif
}
diff --git a/src/weapons/WeaponInfo.cpp b/src/weapons/WeaponInfo.cpp
index 284a0c20..ba872454 100644
--- a/src/weapons/WeaponInfo.cpp
+++ b/src/weapons/WeaponInfo.cpp
@@ -7,7 +7,7 @@
#include "AnimBlendAssociation.h"
#include "Weapon.h"
-CWeaponInfo CWeaponInfo::ms_apWeaponInfos[WEAPONTYPE_TOTALWEAPONS];
+static CWeaponInfo aWeaponInfo[WEAPONTYPE_TOTALWEAPONS];
static char ms_aWeaponNames[][32] = {
"Unarmed",
@@ -28,7 +28,7 @@ static char ms_aWeaponNames[][32] = {
CWeaponInfo*
CWeaponInfo::GetWeaponInfo(eWeaponType weaponType) {
- return &CWeaponInfo::ms_apWeaponInfos[weaponType];
+ return &aWeaponInfo[weaponType];
}
void
@@ -36,14 +36,10 @@ CWeaponInfo::Initialise(void)
{
debug("Initialising CWeaponInfo...\n");
for (int i = 0; i < WEAPONTYPE_TOTALWEAPONS; i++) {
- ms_apWeaponInfos[i].m_eWeaponFire = WEAPON_FIRE_INSTANT_HIT;
- ms_apWeaponInfos[i].m_AnimToPlay = ANIM_PUNCH_R;
- ms_apWeaponInfos[i].m_Anim2ToPlay = NUM_ANIMS;
- ms_apWeaponInfos[i].m_bUseGravity = 1;
- ms_apWeaponInfos[i].m_bSlowsDown = 1;
- ms_apWeaponInfos[i].m_bRandSpeed = 1;
- ms_apWeaponInfos[i].m_bExpands = 1;
- ms_apWeaponInfos[i].m_bExplodes = 1;
+ aWeaponInfo[i].m_eWeaponFire = WEAPON_FIRE_INSTANT_HIT;
+ aWeaponInfo[i].m_AnimToPlay = ANIM_STD_PUNCH;
+ aWeaponInfo[i].m_Anim2ToPlay = ANIM_STD_NUM;
+ aWeaponInfo[i].m_Flags = WEAPONFLAG_USE_GRAVITY | WEAPONFLAG_SLOWS_DOWN | WEAPONFLAG_RAND_SPEED | WEAPONFLAG_EXPANDS | WEAPONFLAG_EXPLODES;
}
debug("Loading weapon data...\n");
LoadWeaponData();
@@ -80,10 +76,9 @@ CWeaponInfo::LoadWeaponData(void)
line[linelen] = '\0';
// skip white space
- for (lp = 0; line[lp] <= ' '; lp++);
+ for (lp = 0; line[lp] <= ' ' && line[lp] != '\0'; lp++);
- if (lp >= linelen || // FIX: game uses == here, but this is safer if we have empty lines
- line[lp] == '#')
+ if (line[lp] == '\0' || line[lp] == '#')
continue;
spread = 0.0f;
@@ -101,7 +96,7 @@ CWeaponInfo::LoadWeaponData(void)
fireType[0] = '\0';
fireOffsetY = 0.0f;
fireOffsetZ = 0.0f;
- animId = ANIM_WALK;
+ animId = ANIM_STD_WALK;
sscanf(
&line[lp],
"%s %s %f %d %d %d %d %f %f %f %f %f %f %f %s %s %f %f %f %f %d %d",
@@ -136,41 +131,31 @@ CWeaponInfo::LoadWeaponData(void)
animAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, animToPlay);
animId = static_cast<AnimationId>(animAssoc->animId);
- if (strncmp(anim2ToPlay, "null", 4) != 0) {
+ if (strcmp(anim2ToPlay, "null") != 0) {
animAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, anim2ToPlay);
- ms_apWeaponInfos[weaponType].m_Anim2ToPlay = (AnimationId) animAssoc->animId;
+ aWeaponInfo[weaponType].m_Anim2ToPlay = (AnimationId) animAssoc->animId;
}
CVector vecFireOffset(fireOffsetX, fireOffsetY, fireOffsetZ);
- ms_apWeaponInfos[weaponType].m_eWeaponFire = FindWeaponFireType(fireType);
- ms_apWeaponInfos[weaponType].m_fRange = range;
- ms_apWeaponInfos[weaponType].m_nFiringRate = firingRate;
- ms_apWeaponInfos[weaponType].m_nReload = reload;
- ms_apWeaponInfos[weaponType].m_nAmountofAmmunition = ammoAmount;
- ms_apWeaponInfos[weaponType].m_nDamage = damage;
- ms_apWeaponInfos[weaponType].m_fSpeed = speed;
- ms_apWeaponInfos[weaponType].m_fRadius = radius;
- ms_apWeaponInfos[weaponType].m_fLifespan = lifeSpan;
- ms_apWeaponInfos[weaponType].m_fSpread = spread;
- ms_apWeaponInfos[weaponType].m_vecFireOffset = vecFireOffset;
- ms_apWeaponInfos[weaponType].m_AnimToPlay = animId;
- ms_apWeaponInfos[weaponType].m_fAnimLoopStart = animLoopStart / 30.0f;
- ms_apWeaponInfos[weaponType].m_fAnimLoopEnd = animLoopEnd / 30.0f;
- ms_apWeaponInfos[weaponType].m_fAnimFrameFire = delayBetweenAnimAndFire / 30.0f;
- ms_apWeaponInfos[weaponType].m_fAnim2FrameFire = delayBetweenAnim2AndFire / 30.0f;
- ms_apWeaponInfos[weaponType].m_nModelId = modelId;
- ms_apWeaponInfos[weaponType].m_bUseGravity = flags & 1;
- ms_apWeaponInfos[weaponType].m_bSlowsDown = (flags >> 1) & 1;
- ms_apWeaponInfos[weaponType].m_bDissipates = (flags >> 2) & 1;
- ms_apWeaponInfos[weaponType].m_bRandSpeed = (flags >> 3) & 1;
- ms_apWeaponInfos[weaponType].m_bExpands = (flags >> 4) & 1;
- ms_apWeaponInfos[weaponType].m_bExplodes = (flags >> 5) & 1;
- ms_apWeaponInfos[weaponType].m_bCanAim = (flags >> 6) & 1;
- ms_apWeaponInfos[weaponType].m_bCanAimWithArm = (flags >> 7) & 1;
- ms_apWeaponInfos[weaponType].m_b1stPerson = (flags >> 8) & 1;
- ms_apWeaponInfos[weaponType].m_bHeavy = (flags >> 9) & 1;
- ms_apWeaponInfos[weaponType].m_bThrow = (flags >> 10) & 1;
+ aWeaponInfo[weaponType].m_eWeaponFire = FindWeaponFireType(fireType);
+ aWeaponInfo[weaponType].m_fRange = range;
+ aWeaponInfo[weaponType].m_nFiringRate = firingRate;
+ aWeaponInfo[weaponType].m_nReload = reload;
+ aWeaponInfo[weaponType].m_nAmountofAmmunition = ammoAmount;
+ aWeaponInfo[weaponType].m_nDamage = damage;
+ aWeaponInfo[weaponType].m_fSpeed = speed;
+ aWeaponInfo[weaponType].m_fRadius = radius;
+ aWeaponInfo[weaponType].m_fLifespan = lifeSpan;
+ aWeaponInfo[weaponType].m_fSpread = spread;
+ aWeaponInfo[weaponType].m_vecFireOffset = vecFireOffset;
+ aWeaponInfo[weaponType].m_AnimToPlay = animId;
+ aWeaponInfo[weaponType].m_fAnimLoopStart = animLoopStart / 30.0f;
+ aWeaponInfo[weaponType].m_fAnimLoopEnd = animLoopEnd / 30.0f;
+ aWeaponInfo[weaponType].m_fAnimFrameFire = delayBetweenAnimAndFire / 30.0f;
+ aWeaponInfo[weaponType].m_fAnim2FrameFire = delayBetweenAnim2AndFire / 30.0f;
+ aWeaponInfo[weaponType].m_nModelId = modelId;
+ aWeaponInfo[weaponType].m_Flags = flags;
}
}
diff --git a/src/weapons/WeaponInfo.h b/src/weapons/WeaponInfo.h
index c89dd482..96e2ecf4 100644
--- a/src/weapons/WeaponInfo.h
+++ b/src/weapons/WeaponInfo.h
@@ -3,9 +3,22 @@
#include "AnimationId.h"
#include "WeaponType.h"
+enum
+{
+ WEAPONFLAG_USE_GRAVITY = 1,
+ WEAPONFLAG_SLOWS_DOWN = 1 << 1,
+ WEAPONFLAG_DISSIPATES = 1 << 2,
+ WEAPONFLAG_RAND_SPEED = 1 << 3,
+ WEAPONFLAG_EXPANDS = 1 << 4,
+ WEAPONFLAG_EXPLODES = 1 << 5,
+ WEAPONFLAG_CANAIM = 1 << 6,
+ WEAPONFLAG_CANAIM_WITHARM = 1 << 7,
+ WEAPONFLAG_1ST_PERSON = 1 << 8,
+ WEAPONFLAG_HEAVY = 1 << 9,
+ WEAPONFLAG_THROW = 1 << 10,
+};
+
class CWeaponInfo {
-// static CWeaponInfo(&ms_apWeaponInfos)[14];
- static CWeaponInfo ms_apWeaponInfos[WEAPONTYPE_LAST_WEAPONTYPE];
public:
eWeaponFire m_eWeaponFire;
float m_fRange;
@@ -25,18 +38,7 @@ public:
float m_fAnimFrameFire;
float m_fAnim2FrameFire;
int32 m_nModelId;
- // flags
- uint8 m_bUseGravity : 1;
- uint8 m_bSlowsDown : 1;
- uint8 m_bDissipates : 1;
- uint8 m_bRandSpeed : 1;
- uint8 m_bExpands : 1;
- uint8 m_bExplodes : 1;
- uint8 m_bCanAim : 1;
- uint8 m_bCanAimWithArm : 1;
- uint8 m_b1stPerson : 1;
- uint8 m_bHeavy : 1;
- uint8 m_bThrow : 1;
+ uint32 m_Flags;
static void Initialise(void);
static void LoadWeaponData(void);
@@ -44,6 +46,7 @@ public:
static eWeaponFire FindWeaponFireType(char *name);
static eWeaponType FindWeaponType(char *name);
static void Shutdown(void);
+ bool IsFlagSet(uint32 flag) const { return (m_Flags & flag) != 0; }
};
VALIDATE_SIZE(CWeaponInfo, 0x54); \ No newline at end of file