From acd1ea9909da281acea6af8f0775e456a67d4a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Fri, 15 May 2020 17:30:25 +0300 Subject: Weapon layer in Peds --- src/weapons/ProjectileInfo.cpp | 82 +++++++++++++++++++------- src/weapons/ProjectileInfo.h | 1 + src/weapons/Weapon.cpp | 128 +++++++++++++++++++++++++++-------------- src/weapons/Weapon.h | 1 + src/weapons/WeaponInfo.cpp | 108 ++++++++++++++++++++++++++-------- src/weapons/WeaponInfo.h | 31 ++++++++-- src/weapons/WeaponType.h | 11 +++- 7 files changed, 269 insertions(+), 93 deletions(-) (limited to 'src/weapons') diff --git a/src/weapons/ProjectileInfo.cpp b/src/weapons/ProjectileInfo.cpp index 47bc65ac..35e55b36 100644 --- a/src/weapons/ProjectileInfo.cpp +++ b/src/weapons/ProjectileInfo.cpp @@ -45,6 +45,7 @@ CProjectileInfo::GetProjectileInfo(int32 id) return &gaProjectileInfo[id]; } +// --MIAMI: Mostly done bool CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, float speed) { @@ -58,32 +59,36 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, switch (weapon) { - case WEAPONTYPE_ROCKETLAUNCHER: + case WEAPONTYPE_ROCKET: { - float vy = 1.25f; - time = CTimer::GetTimeInMilliseconds() + 1400; - if (ped->IsPlayer()) { - matrix.GetForward() = TheCamera.Cams[TheCamera.ActiveCam].Front; - matrix.GetUp() = TheCamera.Cams[TheCamera.ActiveCam].Up; - matrix.GetRight() = CrossProduct(TheCamera.Cams[TheCamera.ActiveCam].Up, TheCamera.Cams[TheCamera.ActiveCam].Front); + float vy = 0.35f; + time = CTimer::GetTimeInMilliseconds() + 2000; + if (entity->GetModelIndex() == MI_SPARROW || entity->GetModelIndex() == MI_HUNTER || entity->GetModelIndex() == MI_SENTINEL) { + matrix = ped->GetMatrix(); matrix.GetPosition() = pos; - } else if (ped->m_pSeekTarget != nil) { + CVector vecSpeed = ((CPhysical*)entity)->m_vecMoveSpeed; + vy += Max(0.0f, DotProduct(vecSpeed, entity->GetForward())) + Max(0.0f, DotProduct(vecSpeed, entity->GetUp())); + } else { + if (ped->IsPlayer()) { + matrix.GetForward() = TheCamera.Cams[TheCamera.ActiveCam].Front; + matrix.GetUp() = TheCamera.Cams[TheCamera.ActiveCam].Up; + matrix.GetRight() = CrossProduct(TheCamera.Cams[TheCamera.ActiveCam].Up, TheCamera.Cams[TheCamera.ActiveCam].Front); + matrix.GetPosition() = pos; + } else if (ped->m_pSeekTarget != nil) { float ry = CGeneral::GetRadianAngleBetweenPoints(1.0f, ped->m_pSeekTarget->GetPosition().z, 1.0f, pos.z); float rz = Atan2(-ped->GetForward().x, ped->GetForward().y); vy = 0.35f * speed + 0.15f; matrix.SetTranslate(0.0f, 1.0f, 1.0f); matrix.Rotate(0.0f, ry, rz); matrix.GetPosition() += pos; - } else { - matrix = ped->GetMatrix(); + } else { + matrix = ped->GetMatrix(); + } } velocity = Multiply3x3(matrix, CVector(0.0f, vy, 0.0f)); gravity = false; break; } - case WEAPONTYPE_FLAMETHROWER: - Error("Undefined projectile type, AddProjectile, ProjectileInfo.cpp"); - break; case WEAPONTYPE_MOLOTOV: { time = CTimer::GetTimeInMilliseconds() + 2000; @@ -100,6 +105,7 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, break; } case WEAPONTYPE_GRENADE: + case WEAPONTYPE_DETONATOR_GRENADE: { time = CTimer::GetTimeInMilliseconds() + 2000; float scale = 0.0f; @@ -116,7 +122,9 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, elasticity = 0.5f; break; } - default: break; + default: + Error("Undefined projectile type, AddProjectile, ProjectileInfo.cpp"); + break; } int i = 0; @@ -127,7 +135,7 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, switch (weapon) { - case WEAPONTYPE_ROCKETLAUNCHER: + case WEAPONTYPE_ROCKET: ms_apProjectile[i] = new CProjectile(MI_MISSILE); break; case WEAPONTYPE_FLAMETHROWER: @@ -136,6 +144,7 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, ms_apProjectile[i] = new CProjectile(MI_MOLOTOV); break; case WEAPONTYPE_GRENADE: + case WEAPONTYPE_DETONATOR_GRENADE: ms_apProjectile[i] = new CProjectile(MI_GRENADE); break; default: break; @@ -158,6 +167,10 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, CWorld::Add(ms_apProjectile[i]); gaProjectileInfo[i].m_vecPos = ms_apProjectile[i]->GetPosition(); + + if (entity && entity->IsPed() && !ped->m_pCollidingEntity) { + ped->m_pCollidingEntity = ms_apProjectile[i]; + } return true; } @@ -182,7 +195,7 @@ CProjectileInfo::RemoveNotAdd(CEntity *entity, eWeaponType weaponType, CVector p case WEAPONTYPE_MOLOTOV: CExplosion::AddExplosion(nil, entity, EXPLOSION_MOLOTOV, pos, 0); break; - case WEAPONTYPE_ROCKETLAUNCHER: + case WEAPONTYPE_ROCKET: CExplosion::AddExplosion(nil, entity, EXPLOSION_ROCKET, pos, 0); break; default: break; @@ -204,17 +217,17 @@ CProjectileInfo::Update() continue; } - if (gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) { + if (gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKET) { CParticle::AddParticle(PARTICLE_SMOKE, ms_apProjectile[i]->GetPosition(), CVector(0.0f, 0.0f, 0.0f)); } if (CTimer::GetTimeInMilliseconds() <= gaProjectileInfo[i].m_nExplosionTime) { - if (gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) { + if (gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKET) { CVector pos = ms_apProjectile[i]->GetPosition(); CWorld::pIgnoreEntity = ms_apProjectile[i]; if (ms_apProjectile[i]->bHasCollided || !CWorld::GetIsLineOfSightClear(gaProjectileInfo[i].m_vecPos, pos, true, true, true, true, false, false) - || gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER && (CHeli::TestRocketCollision(&pos) || CPlane::TestRocketCollision(&pos))) { + || gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKET && (CHeli::TestRocketCollision(&pos) || CPlane::TestRocketCollision(&pos))) { RemoveProjectile(&gaProjectileInfo[i], ms_apProjectile[i]); } CWorld::pIgnoreEntity = nil; @@ -227,14 +240,25 @@ CProjectileInfo::Update() { if (ms_apProjectile[i]->bHasCollided || !CWorld::GetIsLineOfSightClear(gaProjectileInfo[i].m_vecPos, pos, true, true, true, true, false, false) - || gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER && (CHeli::TestRocketCollision(&pos) || CPlane::TestRocketCollision(&pos))) { + || gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKET && (CHeli::TestRocketCollision(&pos) || CPlane::TestRocketCollision(&pos))) { RemoveProjectile(&gaProjectileInfo[i], ms_apProjectile[i]); } } CWorld::pIgnoreEntity = nil; } } else { - RemoveProjectile(&gaProjectileInfo[i], ms_apProjectile[i]); + if (gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_DETONATOR_GRENADE) { + CEntity *ent = gaProjectileInfo[i].m_pSource; + if (ent->IsPed() && ((CPed*)ped)->IsPlayer()) { + CPed *ped = (CPed*)ent; + if (ped->GetWeapon(ped->GetWeaponSlot(WEAPONTYPE_DETONATOR)).m_eWeaponType != WEAPONTYPE_DETONATOR + || ped->GetWeapon(ped->GetWeaponSlot(WEAPONTYPE_DETONATOR)).m_nAmmoTotal == 0) { + gaProjectileInfo[i].m_nExplosionTime = 0; + } + } + } else { + RemoveProjectile(&gaProjectileInfo[i], ms_apProjectile[i]); + } } gaProjectileInfo[i].m_vecPos = ms_apProjectile[i]->GetPosition(); @@ -247,7 +271,7 @@ CProjectileInfo::IsProjectileInRange(float x1, float x2, float y1, float y2, flo bool result = false; for (int i = 0; i < ARRAY_SIZE(ms_apProjectile); i++) { if (gaProjectileInfo[i].m_bInUse) { - if (gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER || gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_MOLOTOV || gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_GRENADE) { + if (gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_ROCKET || gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_MOLOTOV || gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_GRENADE) { const CVector &pos = ms_apProjectile[i]->GetPosition(); if (pos.x >= x1 && pos.x <= x2 && pos.y >= y1 && pos.y <= y2 && pos.z >= z1 && pos.z <= z2) { result = true; @@ -263,6 +287,20 @@ CProjectileInfo::IsProjectileInRange(float x1, float x2, float y1, float y2, flo return result; } +// --MIAMI: Done +void +CProjectileInfo::RemoveDetonatorProjectiles() +{ + for (int i = 0; i < ARRAY_SIZE(ms_apProjectile); i++) { + if (gaProjectileInfo[i].m_bInUse && gaProjectileInfo[i].m_eWeaponType == WEAPONTYPE_DETONATOR_GRENADE) { + CExplosion::AddExplosion(nil, gaProjectileInfo[i].m_pSource, EXPLOSION_GRENADE, gaProjectileInfo[i].m_vecPos, 0); // TODO(Miami): New parameter (1) + gaProjectileInfo[i].m_bInUse = false; + CWorld::Remove(ms_apProjectile[i]); + delete ms_apProjectile[i]; + } + } +} + void CProjectileInfo::RemoveAllProjectiles() { diff --git a/src/weapons/ProjectileInfo.h b/src/weapons/ProjectileInfo.h index 3d8074c9..d1688948 100644 --- a/src/weapons/ProjectileInfo.h +++ b/src/weapons/ProjectileInfo.h @@ -26,6 +26,7 @@ public: static void RemoveNotAdd(CEntity *entity, eWeaponType weaponType, CVector pos); static bool RemoveIfThisIsAProjectile(CObject *pObject); static void RemoveAllProjectiles(); + static void RemoveDetonatorProjectiles(); static void Update(); static bool IsProjectileInRange(float x1, float x2, float y1, float y2, float z1, float z2, bool remove); }; diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp index 18c605bc..deb77cb9 100644 --- a/src/weapons/Weapon.cpp +++ b/src/weapons/Weapon.cpp @@ -35,7 +35,10 @@ uint16 gReloadSampleTime[WEAPONTYPE_LAST_WEAPONTYPE] = 0, // UNARMED 0, // BASEBALLBAT 250, // COLT45 - 400, // UZI + 400, // TEC9 + 400, // UZIhec + 400, // SILENCED_INGRAM + 400, // MP5 650, // SHOTGUN 300, // AK47 300, // M16 @@ -43,7 +46,9 @@ uint16 gReloadSampleTime[WEAPONTYPE_LAST_WEAPONTYPE] = 400, // ROCKETLAUNCHER 0, // FLAMETHROWER 0, // MOLOTOV + 0, // ROCKET 0, // GRENADE + 0, // DETONATEGRENADE 0, // DETONATOR 0 // HELICANNON }; @@ -85,6 +90,7 @@ CWeapon::UpdateWeapons(void) CBulletInfo::Update(); } +// --MIAMI: Done void CWeapon::Initialise(eWeaponType type, int32 ammo) { @@ -97,6 +103,32 @@ CWeapon::Initialise(eWeaponType type, int32 ammo) m_nAmmoInClip = 0; Reload(); m_nTimer = 0; + int modelId = CWeaponInfo::GetWeaponInfo(m_eWeaponType)->m_nModelId; + if (modelId != -1) + CModelInfo::GetModelInfo(modelId)->AddRef(); + + int model2Id = CWeaponInfo::GetWeaponInfo(m_eWeaponType)->m_nModel2Id; + if (model2Id != -1) + CModelInfo::GetModelInfo(model2Id)->AddRef(); +} + +// --MIAMI: Done +void +CWeapon::Shutdown() +{ + int modelId = CWeaponInfo::GetWeaponInfo(m_eWeaponType)->m_nModelId; + if (modelId != -1) + CModelInfo::GetModelInfo(modelId)->RemoveRef(); + + int model2Id = CWeaponInfo::GetWeaponInfo(m_eWeaponType)->m_nModel2Id; + if (model2Id != -1) + CModelInfo::GetModelInfo(model2Id)->RemoveRef(); + + m_eWeaponType = WEAPONTYPE_UNARMED; + m_eWeaponState = WEAPONSTATE_READY; + m_nAmmoInClip = 0; + m_nAmmoTotal = 0; + m_nTimer = 0; } bool @@ -141,9 +173,20 @@ CWeapon::Fire(CEntity *shooter, CVector *fireSource) case WEAPONTYPE_COLT45: case WEAPONTYPE_UZI: + case WEAPONTYPE_TEC9: + case WEAPONTYPE_SILENCED_INGRAM: + case WEAPONTYPE_MP5: case WEAPONTYPE_AK47: + case WEAPONTYPE_M16: + case WEAPONTYPE_HELICANNON: { - fired = FireInstantHit(shooter, source); + if ((TheCamera.PlayerWeaponMode.Mode == CCam::MODE_HELICANNON_1STPERSON || TheCamera.PlayerWeaponMode.Mode == CCam::MODE_M16_1STPERSON) + && shooter == FindPlayerPed()) + { + fired = FireM16_1stPerson(shooter); + } + else + fired = FireInstantHit(shooter, source); break; } @@ -155,16 +198,6 @@ CWeapon::Fire(CEntity *shooter, CVector *fireSource) break; } - case WEAPONTYPE_M16: - { - if ( TheCamera.PlayerWeaponMode.Mode == CCam::MODE_M16_1STPERSON && shooter == FindPlayerPed() ) - fired = FireM16_1stPerson(shooter); - else - fired = FireInstantHit(shooter, source); - - break; - } - case WEAPONTYPE_ROCKETLAUNCHER: { if ( shooter->IsPed() && ((CPed*)shooter)->m_pSeekTarget != nil ) @@ -184,6 +217,7 @@ CWeapon::Fire(CEntity *shooter, CVector *fireSource) case WEAPONTYPE_MOLOTOV: case WEAPONTYPE_GRENADE: + case WEAPONTYPE_DETONATOR_GRENADE: { if ( shooter == FindPlayerPed() ) { @@ -201,6 +235,11 @@ CWeapon::Fire(CEntity *shooter, CVector *fireSource) else fired = FireProjectile(shooter, source, 0.3f); + if (m_eWeaponType == WEAPONTYPE_DETONATOR_GRENADE) { + ((CPed*)shooter)->GiveWeapon(WEAPONTYPE_DETONATOR, 1, true); + ((CPed*)shooter)->GetWeapon(((CPed*)shooter)->GetWeaponSlot(WEAPONTYPE_DETONATOR)).m_eWeaponState = WEAPONSTATE_READY; + ((CPed*)shooter)->SetCurrentWeapon(WEAPONTYPE_DETONATOR); + } break; } @@ -221,19 +260,6 @@ CWeapon::Fire(CEntity *shooter, CVector *fireSource) break; } - case WEAPONTYPE_HELICANNON: - { - if ( (TheCamera.PlayerWeaponMode.Mode == CCam::MODE_HELICANNON_1STPERSON || TheCamera.PlayerWeaponMode.Mode == CCam::MODE_M16_1STPERSON ) - && shooter == FindPlayerPed() ) - { - fired = FireM16_1stPerson(shooter); - } - else - fired = FireInstantHit(shooter, source); - - break; - } - default: { debug("Unknown weapon type, Weapon.cpp"); @@ -343,6 +369,7 @@ CWeapon::FireFromCar(CAutomobile *shooter, bool left) return true; } +// --MIAMI: Just a few lines is done bool CWeapon::FireMelee(CEntity *shooter, CVector &fireSource) { @@ -350,9 +377,7 @@ CWeapon::FireMelee(CEntity *shooter, CVector &fireSource) CWeaponInfo *info = GetInfo(); - bool anim2Playing = false; - if ( RpAnimBlendClumpGetAssociation(shooter->GetClump(), info->m_Anim2ToPlay) ) - anim2Playing = true; + bool anim2Playing = RpAnimBlendClumpGetAssociation(shooter->GetClump(), CPed::GetFireAnimGround(info, false)); ASSERT(shooter->IsPed()); @@ -739,6 +764,9 @@ CWeapon::FireInstantHit(CEntity *shooter, CVector *fireSource) } case WEAPONTYPE_UZI: + case WEAPONTYPE_TEC9: + case WEAPONTYPE_SILENCED_INGRAM: + case WEAPONTYPE_MP5: { CPointLights::AddLight(CPointLights::LIGHT_POINT, *fireSource, CVector(0.0f, 0.0f, 0.0f), 5.0f, @@ -1387,10 +1415,12 @@ CWeapon::FireProjectile(CEntity *shooter, CVector *fireSource, float power) ASSERT(fireSource!=nil); CVector source, target; + eWeaponType projectileType = m_eWeaponType; if ( m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER ) { source = *fireSource; + projectileType = WEAPONTYPE_ROCKET; if ( shooter->IsPed() && ((CPed*)shooter)->IsPlayer() ) { @@ -1432,7 +1462,7 @@ CWeapon::FireProjectile(CEntity *shooter, CVector *fireSource, float power) if ( !CWorld::GetIsLineOfSightClear(source, target, true, true, false, true, false, false, false) ) { if ( m_eWeaponType != WEAPONTYPE_GRENADE ) - CProjectileInfo::RemoveNotAdd(shooter, m_eWeaponType, *fireSource); + CProjectileInfo::RemoveNotAdd(shooter, projectileType, *fireSource); else { if ( shooter->IsPed() ) @@ -1441,14 +1471,14 @@ CWeapon::FireProjectile(CEntity *shooter, CVector *fireSource, float power) source.z -= 0.4f; if ( !CWorld::TestSphereAgainstWorld(source, 0.5f, nil, false, false, true, false, false, false) ) - CProjectileInfo::AddProjectile(shooter, m_eWeaponType, source, 0.0f); + CProjectileInfo::AddProjectile(shooter, WEAPONTYPE_GRENADE, source, 0.0f); else - CProjectileInfo::RemoveNotAdd(shooter, m_eWeaponType, *fireSource); + CProjectileInfo::RemoveNotAdd(shooter, WEAPONTYPE_GRENADE, *fireSource); } } } else - CProjectileInfo::AddProjectile(shooter, m_eWeaponType, *fireSource, power); + CProjectileInfo::AddProjectile(shooter, projectileType, *fireSource, power); return true; } @@ -1555,6 +1585,7 @@ CWeapon::FireSniper(CEntity *shooter) return true; } +// --MIAMI: Heavily TODO bool CWeapon::FireM16_1stPerson(CEntity *shooter) { @@ -1599,7 +1630,9 @@ CWeapon::FireM16_1stPerson(CEntity *shooter) DoBulletImpact(shooter, victim, &source, &target, &point, front); CVector bulletPos; - if ( CHeli::TestBulletCollision(&source, &target, &bulletPos, 4) ) + + // TODO(Miami): M60 + if ( CHeli::TestBulletCollision(&source, &target, &bulletPos, (/*m_eWeaponType == WEAPONTYPE_M60 || */ m_eWeaponType == WEAPONTYPE_HELICANNON ? 20 : 4)) ) { for ( int32 i = 0; i < 16; i++ ) CParticle::AddParticle(PARTICLE_SPARK, bulletPos, CVector(0.0f, 0.0f, 0.0f)); @@ -1609,16 +1642,27 @@ CWeapon::FireM16_1stPerson(CEntity *shooter) { CPad::GetPad(0)->StartShake_Distance(240, 128, FindPlayerPed()->GetPosition().x, FindPlayerPed()->GetPosition().y, FindPlayerPed()->GetPosition().z); - if ( m_eWeaponType == WEAPONTYPE_M16 ) - { - TheCamera.Cams[TheCamera.ActiveCam].Beta += float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0003f; - TheCamera.Cams[TheCamera.ActiveCam].Alpha += float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0003f; - } - else if ( m_eWeaponType == WEAPONTYPE_HELICANNON ) - { - TheCamera.Cams[TheCamera.ActiveCam].Beta += float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0001f; - TheCamera.Cams[TheCamera.ActiveCam].Alpha += float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0001f; + // TODO(Miami) + float mult; + switch (m_eWeaponType) { + case WEAPONTYPE_M16: // case WEAPONTYPE_M4: + case WEAPONTYPE_HELICANNON: + // case WEAPONTYPE_M60: + mult = 0.0003f; + break; + case WEAPONTYPE_AK47: // case WEAPONTYPE_RUGER: + mult = 0.00015f; + break; + default: + mult = 0.0002f; + break; } + + if (FindPlayerPed()->bIsDucking || FindPlayerPed()->m_attachedTo) + mult *= 0.3f; + + TheCamera.Cams[TheCamera.ActiveCam].Beta += float((CGeneral::GetRandomNumber() & 127) - 64) * mult; + TheCamera.Cams[TheCamera.ActiveCam].Alpha += float((CGeneral::GetRandomNumber() & 127) - 64) * mult; } return true; diff --git a/src/weapons/Weapon.h b/src/weapons/Weapon.h index 1b2c0320..32322da0 100644 --- a/src/weapons/Weapon.h +++ b/src/weapons/Weapon.h @@ -32,6 +32,7 @@ public: static void UpdateWeapons (void); void Initialise(eWeaponType type, int32 ammo); + void Shutdown(); bool Fire (CEntity *shooter, CVector *fireSource); bool FireFromCar (CAutomobile *shooter, bool left); diff --git a/src/weapons/WeaponInfo.cpp b/src/weapons/WeaponInfo.cpp index c4ab75d2..7128a04f 100644 --- a/src/weapons/WeaponInfo.cpp +++ b/src/weapons/WeaponInfo.cpp @@ -6,14 +6,25 @@ #include "AnimManager.h" #include "AnimBlendAssociation.h" #include "Weapon.h" +#include "ModelInfo.h" +#include "ModelIndices.h" + +// Yeah... +int32 CWeaponInfo::ms_aMaxAmmoForWeapon[WEAPONTYPE_TOTALWEAPONS] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 +}; CWeaponInfo CWeaponInfo::ms_apWeaponInfos[WEAPONTYPE_TOTALWEAPONS]; +// --MIAMI: Todo static char ms_aWeaponNames[][32] = { "Unarmed", "BaseballBat", "Colt45", + "Tec9", "Uzi", + "SilencedIngram", + "Mp5", "Shotgun", "AK47", "M16", @@ -21,9 +32,11 @@ static char ms_aWeaponNames[][32] = { "RocketLauncher", "FlameThrower", "Molotov", + "Rocket", "Grenade", + "DetonateGrenade", "Detonator", - "HeliCannon" + "HeliCannon", }; CWeaponInfo* @@ -31,45 +44,62 @@ CWeaponInfo::GetWeaponInfo(eWeaponType weaponType) { return &CWeaponInfo::ms_apWeaponInfos[weaponType]; } +// --MIAMI: done except WEAPONTYPE_TOTALWEAPONS value void 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_fRange = 0.0f; + ms_apWeaponInfos[i].m_nFiringRate = 0; + ms_apWeaponInfos[i].m_nReload = 0; + ms_apWeaponInfos[i].m_nAmountofAmmunition = 0; + ms_apWeaponInfos[i].m_nDamage = 0; + ms_apWeaponInfos[i].m_fSpeed = 0.0f; + ms_apWeaponInfos[i].m_fRadius = 0.0f; + ms_apWeaponInfos[i].m_fLifespan = 0.0f; + ms_apWeaponInfos[i].m_fSpread = 0.0f; + ms_apWeaponInfos[i].m_vecFireOffset = CVector(0.0f, 0.0f, 0.0f); + // TODO(Miami): ASSOCGRP_UNARMED + ms_apWeaponInfos[i].m_AnimToPlay = ASSOCGRP_STD; + ms_apWeaponInfos[i].m_fAnimLoopStart = 0.0f; + ms_apWeaponInfos[i].m_fAnimLoopEnd = 0.0f; + ms_apWeaponInfos[i].m_fAnimFrameFire = 0.0f; + ms_apWeaponInfos[i].m_fAnim2LoopStart = 0.0f; + ms_apWeaponInfos[i].m_fAnim2LoopEnd = 0.0f; + ms_apWeaponInfos[i].m_fAnim2FrameFire = 0.0f; + ms_apWeaponInfos[i].m_fAnimBreakout = 0.0f; 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; + ms_apWeaponInfos[i].m_nWeaponSlot = 0; } debug("Loading weapon data...\n"); LoadWeaponData(); debug("CWeaponInfo ready\n"); } +// --MIAMI: Done, commented parts wait for weapons port void CWeaponInfo::LoadWeaponData(void) { float spread, speed, lifeSpan, radius; float range, fireOffsetX, fireOffsetY, fireOffsetZ; - float delayBetweenAnimAndFire, delayBetweenAnim2AndFire, animLoopStart, animLoopEnd; + float anim2LoopStart, anim2LoopEnd, delayBetweenAnim2AndFire, animBreakout; + float delayBetweenAnimAndFire, animLoopStart, animLoopEnd; int flags, ammoAmount, damage, reload, weaponType; - int firingRate, modelId; + int firingRate, modelId, modelId2, weaponSlot; char line[256], weaponName[32], fireType[32]; - char animToPlay[32], anim2ToPlay[32]; - - CAnimBlendAssociation *animAssoc; - AnimationId animId; + char animToPlay[32]; int bp, buflen; int lp, linelen; CFileMgr::SetDir("DATA"); buflen = CFileMgr::LoadFile("WEAPON.DAT", work_buff, sizeof(work_buff), "r"); - CFileMgr::SetDir(""); for (bp = 0; bp < buflen; ) { // read file line by line @@ -101,10 +131,9 @@ CWeaponInfo::LoadWeaponData(void) fireType[0] = '\0'; fireOffsetY = 0.0f; fireOffsetZ = 0.0f; - animId = ANIM_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", + "%s %s %f %d %d %d %d %f %f %f %f %f %f %f %s %f %f %f %f %f %f %f %d %d %x %d", weaponName, fireType, &range, @@ -120,27 +149,23 @@ CWeaponInfo::LoadWeaponData(void) &fireOffsetY, &fireOffsetZ, animToPlay, - anim2ToPlay, &animLoopStart, &animLoopEnd, &delayBetweenAnimAndFire, + &anim2LoopStart, + &anim2LoopEnd, &delayBetweenAnim2AndFire, + &animBreakout, &modelId, - &flags); + &modelId2, + &flags, + &weaponSlot); if (strncmp(weaponName, "ENDWEAPONDATA", 13) == 0) return; weaponType = FindWeaponType(weaponName); - animAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, animToPlay); - animId = static_cast(animAssoc->animId); - - if (strncmp(anim2ToPlay, "null", 4) != 0) { - animAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, anim2ToPlay); - ms_apWeaponInfos[weaponType].m_Anim2ToPlay = (AnimationId) animAssoc->animId; - } - CVector vecFireOffset(fireOffsetX, fireOffsetY, fireOffsetZ); ms_apWeaponInfos[weaponType].m_eWeaponFire = FindWeaponFireType(fireType); @@ -154,12 +179,16 @@ CWeaponInfo::LoadWeaponData(void) 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_fAnim2LoopStart = anim2LoopStart / 30.0f; + ms_apWeaponInfos[weaponType].m_fAnim2LoopEnd = anim2LoopEnd / 30.0f; ms_apWeaponInfos[weaponType].m_fAnimFrameFire = delayBetweenAnimAndFire / 30.0f; ms_apWeaponInfos[weaponType].m_fAnim2FrameFire = delayBetweenAnim2AndFire / 30.0f; + ms_apWeaponInfos[weaponType].m_fAnimBreakout = animBreakout / 30.0f; ms_apWeaponInfos[weaponType].m_nModelId = modelId; + ms_apWeaponInfos[weaponType].m_nModel2Id = modelId2; + ms_apWeaponInfos[weaponType].m_bUseGravity = flags; ms_apWeaponInfos[weaponType].m_bSlowsDown = flags >> 1; ms_apWeaponInfos[weaponType].m_bDissipates = flags >> 2; @@ -171,6 +200,39 @@ CWeaponInfo::LoadWeaponData(void) ms_apWeaponInfos[weaponType].m_b1stPerson = flags >> 8; ms_apWeaponInfos[weaponType].m_bHeavy = flags >> 9; ms_apWeaponInfos[weaponType].m_bThrow = flags >> 10; + ms_apWeaponInfos[weaponType].m_bReloadLoop2Start = flags >> 11; + ms_apWeaponInfos[weaponType].m_bUse2nd = flags >> 12; + ms_apWeaponInfos[weaponType].m_bGround2nd = flags >> 13; + ms_apWeaponInfos[weaponType].m_bFinish3rd = flags >> 14; + ms_apWeaponInfos[weaponType].m_bReload = flags >> 15; + ms_apWeaponInfos[weaponType].m_bFightMode = flags >> 16; + ms_apWeaponInfos[weaponType].m_bCrouchFire = flags >> 17; + ms_apWeaponInfos[weaponType].m_bCop3rd = flags >> 18; + ms_apWeaponInfos[weaponType].m_bGround3rd = flags >> 19; + ms_apWeaponInfos[weaponType].m_bPartialAttack = flags >> 20; + ms_apWeaponInfos[weaponType].m_bAnimDetonate = flags >> 21; + + ms_apWeaponInfos[weaponType].m_nWeaponSlot = weaponSlot; + + // TODO(Miami): Enable once weapons are done + if (animLoopEnd < 98.0f && weaponType != WEAPONTYPE_FLAMETHROWER && weaponType != WEAPONTYPE_SHOTGUN + /*&& weaponType != 20 && weaponType != 21*/) + ms_apWeaponInfos[weaponType].m_nFiringRate = ((ms_apWeaponInfos[weaponType].m_fAnimLoopEnd - ms_apWeaponInfos[weaponType].m_fAnimLoopStart) * 900.0f); + + if (weaponType == WEAPONTYPE_DETONATOR || weaponType == WEAPONTYPE_HELICANNON) + modelId = -1; + else if (weaponType == WEAPONTYPE_DETONATOR_GRENADE) + modelId = MI_BOMB; + + if (modelId != -1) + ((CWeaponModelInfo*)CModelInfo::GetModelInfo(modelId))->SetWeaponInfo(weaponType); + + for (int i = 0; i < NUM_ANIM_ASSOC_GROUPS; i++) { + if (!strcmp(animToPlay, CAnimManager::GetAnimGroupName((AssocGroupId)i))) { + ms_apWeaponInfos[weaponType].m_AnimToPlay = (AssocGroupId)i; + break; + } + } } } diff --git a/src/weapons/WeaponInfo.h b/src/weapons/WeaponInfo.h index b5882082..cb10f095 100644 --- a/src/weapons/WeaponInfo.h +++ b/src/weapons/WeaponInfo.h @@ -3,10 +3,13 @@ #include "AnimationId.h" #include "WeaponType.h" +enum AssocGroupId; + class CWeaponInfo { -// static CWeaponInfo(&ms_apWeaponInfos)[14]; - static CWeaponInfo ms_apWeaponInfos[14]; + static CWeaponInfo ms_apWeaponInfos[WEAPONTYPE_TOTALWEAPONS]; public: + static int32 ms_aMaxAmmoForWeapon[WEAPONTYPE_TOTALWEAPONS]; + eWeaponFire m_eWeaponFire; float m_fRange; uint32 m_nFiringRate; @@ -18,13 +21,16 @@ public: float m_fLifespan; float m_fSpread; CVector m_vecFireOffset; - AnimationId m_AnimToPlay; - AnimationId m_Anim2ToPlay; + AssocGroupId m_AnimToPlay; float m_fAnimLoopStart; float m_fAnimLoopEnd; float m_fAnimFrameFire; + float m_fAnim2LoopStart; + float m_fAnim2LoopEnd; float m_fAnim2FrameFire; + float m_fAnimBreakout; int32 m_nModelId; + int32 m_nModel2Id; // flags uint8 m_bUseGravity : 1; uint8 m_bSlowsDown : 1; @@ -34,9 +40,24 @@ public: uint8 m_bExplodes : 1; uint8 m_bCanAim : 1; uint8 m_bCanAimWithArm : 1; + uint8 m_b1stPerson : 1; uint8 m_bHeavy : 1; uint8 m_bThrow : 1; + uint8 m_bReloadLoop2Start : 1; + uint8 m_bUse2nd : 1; + uint8 m_bGround2nd : 1; + uint8 m_bFinish3rd : 1; + uint8 m_bReload : 1; + + uint8 m_bFightMode : 1; + uint8 m_bCrouchFire : 1; + uint8 m_bCop3rd : 1; + uint8 m_bGround3rd : 1; + uint8 m_bPartialAttack : 1; + uint8 m_bAnimDetonate : 1; + + uint32 m_nWeaponSlot; static void Initialise(void); static void LoadWeaponData(void); @@ -46,4 +67,4 @@ public: static void Shutdown(void); }; -VALIDATE_SIZE(CWeaponInfo, 0x54); \ No newline at end of file +VALIDATE_SIZE(CWeaponInfo, 0x64); diff --git a/src/weapons/WeaponType.h b/src/weapons/WeaponType.h index b45740b7..61d03ad3 100644 --- a/src/weapons/WeaponType.h +++ b/src/weapons/WeaponType.h @@ -1,11 +1,15 @@ #pragma once +// --MIAMI: TODO enum eWeaponType { WEAPONTYPE_UNARMED, WEAPONTYPE_BASEBALLBAT, WEAPONTYPE_COLT45, + WEAPONTYPE_TEC9, WEAPONTYPE_UZI, + WEAPONTYPE_SILENCED_INGRAM, + WEAPONTYPE_MP5, WEAPONTYPE_SHOTGUN, WEAPONTYPE_AK47, WEAPONTYPE_M16, @@ -13,7 +17,9 @@ enum eWeaponType WEAPONTYPE_ROCKETLAUNCHER, WEAPONTYPE_FLAMETHROWER, WEAPONTYPE_MOLOTOV, + WEAPONTYPE_ROCKET, WEAPONTYPE_GRENADE, + WEAPONTYPE_DETONATOR_GRENADE, WEAPONTYPE_DETONATOR, WEAPONTYPE_HELICANNON, WEAPONTYPE_LAST_WEAPONTYPE, @@ -27,7 +33,10 @@ enum eWeaponType WEAPONTYPE_UNIDENTIFIED, WEAPONTYPE_TOTALWEAPONS = WEAPONTYPE_LAST_WEAPONTYPE, - WEAPONTYPE_TOTAL_INVENTORY_WEAPONS = 13, +}; + +enum { + TOTAL_WEAPON_SLOTS = 10, }; enum eWeaponFire { -- cgit v1.2.3