diff options
Diffstat (limited to 'src/weapons/Explosion.cpp')
-rw-r--r-- | src/weapons/Explosion.cpp | 191 |
1 files changed, 120 insertions, 71 deletions
diff --git a/src/weapons/Explosion.cpp b/src/weapons/Explosion.cpp index f79c0278..7683ed97 100644 --- a/src/weapons/Explosion.cpp +++ b/src/weapons/Explosion.cpp @@ -25,12 +25,25 @@ CExplosion gaExplosion[NUM_EXPLOSIONS]; RwRGBA colMedExpl = { 0, 0, 0, 0 }; RwRGBA colUpdate = { 0, 0, 0, 0 }; +const RwRGBA colAddExplosion = { 160, 160, 160, 255 }; +const RwRGBA colGrenade = { 96, 96, 96, 255 }; + int AudioHandle = AEHANDLE_NONE; void CExplosion::Initialise() { debug("Initialising CExplosion...\n"); + ClearAllExplosions(); + AudioHandle = DMAudio.CreateEntity(AUDIOTYPE_EXPLOSION, (void*)1); + if (AudioHandle >= 0) + DMAudio.SetEntityStatus(AudioHandle, TRUE); + debug("CExplosion ready\n"); +} + +void +CExplosion::ClearAllExplosions() +{ for (int i = 0; i < ARRAY_SIZE(gaExplosion); i++) { gaExplosion[i].m_ExplosionType = EXPLOSION_GRENADE; gaExplosion[i].m_vecPosition = CVector(0.0f, 0.0f, 0.0f); @@ -43,11 +56,8 @@ CExplosion::Initialise() gaExplosion[i].m_nIteration = 0; gaExplosion[i].m_fStartTime = 0.0f; gaExplosion[i].m_bIsBoat = false; + gaExplosion[i].m_bMakeSound = true; } - AudioHandle = DMAudio.CreateEntity(AUDIOTYPE_EXPLOSION, (void*)1); - if (AudioHandle >= 0) - DMAudio.SetEntityStatus(AudioHandle, TRUE); - debug("CExplosion ready\n"); } void @@ -79,6 +89,12 @@ CExplosion::GetExplosionType(uint8 id) return gaExplosion[id].m_ExplosionType; } +bool +CExplosion::DoesExplosionMakeSound(uint8 id) +{ + return gaExplosion[id].m_bMakeSound; +}; + CVector * CExplosion::GetExplosionPosition(uint8 id) { @@ -86,14 +102,19 @@ CExplosion::GetExplosionPosition(uint8 id) } bool -CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionType type, const CVector &pos, uint32 lifetime) +#ifdef SIMPLER_MISSIONS +CExplosion::AddExplosion(CEntity* explodingEntity, CEntity* culprit, eExplosionType type, const CVector& pos, uint32 lifetime, bool makeSound, float radius) +#else +CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionType type, const CVector &pos, uint32 lifetime, bool makeSound) +#endif { CVector pPosn; CVector posGround; RwRGBA colorMedium = colMedExpl; + RwRGBA color = colAddExplosion; + RwRGBA colorGrenade = colGrenade; bool bDontExplode = false; - const RwRGBA color = { 160, 160, 160, 255 }; pPosn = pos; pPosn.z += 5.0f; #ifdef FIX_BUGS @@ -128,19 +149,28 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT explosion.m_nIteration = 1; explosion.m_nActiveCounter = 1; explosion.m_bIsBoat = false; + explosion.m_bMakeSound = makeSound; explosion.m_nParticlesExpireTime = lifetime != 0 ? CTimer::GetTimeInMilliseconds() + lifetime : 0; switch (type) { case EXPLOSION_GRENADE: +#ifdef SIMPLER_MISSIONS + explosion.m_fRadius = (radius == -1.0f ? 9.0f : radius); +#else explosion.m_fRadius = 9.0f; +#endif explosion.m_fPower = 300.0f; explosion.m_fStopTime = lifetime + CTimer::GetTimeInMilliseconds() + 750; explosion.m_fPropagationRate = 0.5f; posGround = pos; posGround.z = CWorld::FindGroundZFor3DCoord(posGround.x, posGround.y, posGround.z + 3.0f, nil); CEventList::RegisterEvent(EVENT_EXPLOSION, posGround, 250); - if (Distance(explosion.m_vecPosition, TheCamera.GetPosition()) < 40.0f) - CParticle::AddParticle(PARTICLE_EXPLOSION_LFAST, explosion.m_vecPosition, CVector(0.0f, 0.0f, 0.0f), nil, 5.5f, color); + if (Distance(explosion.m_vecPosition, TheCamera.GetPosition()) < 40.0f) { + uint8 tmp = CGeneral::GetRandomNumberInRange(0, 64) - 64; + colorGrenade.green += tmp; + colorGrenade.blue += tmp; + CParticle::AddParticle(PARTICLE_EXPLOSION_LFAST, explosion.m_vecPosition, CVector(0.0f, 0.0f, 0.0f), nil, 4.5f, colorGrenade); + } break; case EXPLOSION_MOLOTOV: { @@ -150,18 +180,17 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT explosion.m_fPropagationRate = 0.5f; posGround = pos; bool found; - posGround.z = CWorld::FindGroundZFor3DCoord(posGround.x, posGround.y, posGround.z + 3.0f, &found); - if (found) { - float waterLevel; - if (CWaterLevel::GetWaterLevelNoWaves(posGround.x, posGround.y, posGround.z, &waterLevel) - && posGround.z < waterLevel - && waterLevel - 6.0f < posGround.z) // some subway/tunnels check? - bDontExplode = true; - else - gFireManager.StartFire(posGround, 1.8f, false); - } - else + float tmp = CWorld::FindGroundZFor3DCoord(posGround.x, posGround.y, posGround.z + 3.0f, &found); + if (found) + posGround.z = tmp; + + float waterLevel; + if (CWaterLevel::GetWaterLevelNoWaves(posGround.x, posGround.y, posGround.z, &waterLevel) + && posGround.z < waterLevel && waterLevel - 6.0f < posGround.z) { // some subway/tunnels check? bDontExplode = true; + } else if (found) { + gFireManager.StartFire(posGround, 1.8f, false); + } break; } case EXPLOSION_ROCKET: @@ -175,6 +204,7 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT break; case EXPLOSION_CAR: case EXPLOSION_CAR_QUICK: + case EXPLOSION_BOAT: explosion.m_fRadius = 9.0f; explosion.m_fPower = 300.0f; explosion.m_fStopTime = lifetime + CTimer::GetTimeInMilliseconds() + 4250; @@ -184,59 +214,71 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT if (explosion.m_pVictimEntity->IsVehicle() && ((CVehicle*)explosion.m_pVictimEntity)->IsBoat()) explosion.m_bIsBoat = true; CEventList::RegisterEvent(EVENT_EXPLOSION, EVENT_ENTITY_VEHICLE, explosion.m_pVictimEntity, nil, 1000); - } else + } else { CEventList::RegisterEvent(EVENT_EXPLOSION, pos, 1000); + } if (explosion.m_pVictimEntity != nil && !explosion.m_bIsBoat) { - int rn = (CGeneral::GetRandomNumber() & 1) + 2; - for (int i = 0; i < rn; i++) { - CParticle::AddParticle(PARTICLE_EXPLOSION_MEDIUM, explosion.m_pVictimEntity->GetPosition(), CVector(0.0f, 0.0f, 0.0f), nil, 3.5f, colMedExpl); - CParticle::AddParticle(PARTICLE_EXPLOSION_LFAST, explosion.m_pVictimEntity->GetPosition(), CVector(0.0f, 0.0f, 0.0f), nil, 5.5f, color); - } CVehicle *veh = (CVehicle*)explosion.m_pVictimEntity; - int32 component = CAR_WING_LR; - - // miami leftover - if (veh->IsBike()) - component = BIKE_FORKS_REAR; - - if (veh->IsComponentPresent(component)) { - CVector componentPos; - veh->GetComponentWorldPosition(component, componentPos); - rn = (CGeneral::GetRandomNumber() & 1) + 1; + CVector componentPos; + + if (veh->IsBike()) { + veh->GetComponentWorldPosition(BIKE_FORKS_REAR, componentPos); + } else if (veh->IsComponentPresent(CAR_BUMP_REAR) && veh->IsComponentPresent(CAR_WHEEL_LB)) { //mb it's another enum + CVector tmpVec; + veh->GetComponentWorldPosition(CAR_BUMP_REAR, componentPos); + veh->GetComponentWorldPosition(CAR_WHEEL_LB, tmpVec); + componentPos += tmpVec; + componentPos /= 2.0f; + } else if (veh->IsComponentPresent(CAR_BOOT)) { + veh->GetComponentWorldPosition(CAR_BOOT, componentPos); + } + if (componentPos.x != 0.0f) { + int rn = (CGeneral::GetRandomNumber() & 1) + 1; for (int i = 0; i < rn; i++) - CParticle::AddJetExplosion(componentPos, 1.4f, 0.0f); + CParticle::AddJetExplosion(componentPos, (CGeneral::GetRandomNumber() & 7) / 7.0f + 1.5f, 0.5f); } } break; case EXPLOSION_HELI: - explosion.m_fRadius = 6.0f; - explosion.m_fPower = 300.0f; + case EXPLOSION_HELI2: + if (type == EXPLOSION_HELI2) { + explosion.m_fRadius = 12.0f; + explosion.m_fPower = 500.0f; + } else { + explosion.m_fRadius = 6.0f; + explosion.m_fPower = 300.0f; + } explosion.m_fStopTime = lifetime + CTimer::GetTimeInMilliseconds() + 750; explosion.m_fPropagationRate = 0.5f; explosion.m_fStartTime = CTimer::GetTimeInMilliseconds(); for (int i = 0; i < 10; i++) { CVector randpos; - uint8 x, y, z; - x = CGeneral::GetRandomNumber(); - y = CGeneral::GetRandomNumber(); - z = CGeneral::GetRandomNumber(); - randpos = pos + CVector(x - 128, y - 128, z - 128) / 20.0f; + randpos.x = CGeneral::GetRandomNumber(); + randpos.y = CGeneral::GetRandomNumber(); + randpos.z = CGeneral::GetRandomNumber(); + randpos -= CVector(128, 128, 128); + randpos /= 20.0f; + randpos += pos; CParticle::AddParticle(PARTICLE_EXPLOSION_MFAST, randpos, CVector(0.0f, 0.0f, 0.0f), nil, 2.5f, color); - x = CGeneral::GetRandomNumber(); - y = CGeneral::GetRandomNumber(); - z = CGeneral::GetRandomNumber(); - randpos = pos + CVector(x - 128, y - 128, z - 128) / 20.0f; + randpos.x = CGeneral::GetRandomNumber(); + randpos.y = CGeneral::GetRandomNumber(); + randpos.z = CGeneral::GetRandomNumber(); + randpos -= CVector(128, 128, 128); + randpos /= 20.0f; + randpos += pos; CParticle::AddParticle(PARTICLE_EXPLOSION_LFAST, randpos, CVector(0.0f, 0.0f, 0.0f), nil, 5.0f, color); - x = CGeneral::GetRandomNumber(); - y = CGeneral::GetRandomNumber(); - z = CGeneral::GetRandomNumber(); - randpos = pos + CVector(x - 128, y - 128, z - 128) / 20.0f; + randpos.x = CGeneral::GetRandomNumber(); + randpos.y = CGeneral::GetRandomNumber(); + randpos.z = CGeneral::GetRandomNumber(); + randpos -= CVector(128, 128, 128); + randpos /= 20.0f; + randpos += pos; CParticle::AddJetExplosion(randpos, 1.4f, 3.0f); } @@ -259,13 +301,10 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT explosion.m_fPropagationRate = 0.5f; for (int i = 0; i < 6; i++) { CVector randpos; - uint8 x, y, z; - - x = CGeneral::GetRandomNumber(); - y = CGeneral::GetRandomNumber(); - z = CGeneral::GetRandomNumber(); - randpos = CVector(x - 128, y - 128, z - 128); - + randpos.x = CGeneral::GetRandomNumber(); + randpos.y = CGeneral::GetRandomNumber(); + randpos.z = CGeneral::GetRandomNumber(); + randpos -= CVector(128, 128, 128); randpos.x /= 50.0f; randpos.y /= 50.0f; randpos.z /= 25.0f; @@ -297,7 +336,11 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z + 4.0f, nil); // BUG? result is unused CEventList::RegisterEvent(EVENT_EXPLOSION, posGround, 250); break; + default: + debug("Undefined explosion type, AddExplosion, Explosion.cpp"); + break; } + if (bDontExplode) { explosion.m_nIteration = 0; return false; @@ -306,8 +349,12 @@ CExplosion::AddExplosion(CEntity *explodingEntity, CEntity *culprit, eExplosionT if (explosion.m_fPower != 0.0f && explosion.m_nParticlesExpireTime == 0) CWorld::TriggerExplosion(pos, explosion.m_fRadius, explosion.m_fPower, culprit, (type == EXPLOSION_ROCKET || type == EXPLOSION_CAR_QUICK || type == EXPLOSION_MINE || type == EXPLOSION_BARREL || type == EXPLOSION_TANK_GRENADE || type == EXPLOSION_HELI_BOMB)); - TheCamera.CamShake(0.6f, pos.x, pos.y, pos.z); - CPad::GetPad(0)->StartShake_Distance(300, 128, pos.x, pos.y, pos.z); + if (type == EXPLOSION_MOLOTOV) { + TheCamera.CamShake(0.2f, pos.x, pos.y, pos.z); + } else { + TheCamera.CamShake(0.6f, pos.x, pos.y, pos.z); + CPad::GetPad(0)->StartShake_Distance(300, 128, pos.x, pos.y, pos.z); + } return true; } @@ -333,6 +380,7 @@ CExplosion::Update() case EXPLOSION_GRENADE: case EXPLOSION_ROCKET: case EXPLOSION_HELI: + case EXPLOSION_HELI2: case EXPLOSION_MINE: case EXPLOSION_BARREL: if (CTimer::GetFrameCounter() & 1) { @@ -351,8 +399,10 @@ CExplosion::Update() point1.z += 5.0f; CColPoint colPoint; CEntity *pEntity; - CWorld::ProcessVerticalLine(point1, -1000.0f, colPoint, pEntity, true, false, false, false, true, false, nil); - explosion.m_fZshift = colPoint.point.z; + if (CWorld::ProcessVerticalLine(point1, -1000.0f, colPoint, pEntity, true, false, false, false, true, false, nil)) + explosion.m_fZshift = colPoint.point.z; + else + explosion.m_fZshift = explosion.m_vecPosition.z; } float ff = ((float)explosion.m_nIteration * 0.55f); for (int i = 0; i < 5 * ff; i++) { @@ -361,8 +411,6 @@ CExplosion::Update() CVector pos = explosion.m_vecPosition; pos.x += ff * Sin(angle); pos.y += ff * Cos(angle); - pos.z += 5.0f; // what is the point of this? - pos.z = explosion.m_fZshift + 0.5f; CParticle::AddParticle(PARTICLE_EXPLOSION_MEDIUM, pos, CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, color, CGeneral::GetRandomNumberInRange(-3.0f, 3.0f), CGeneral::GetRandomNumberInRange(-180.0f, 180.0f)); } @@ -370,9 +418,10 @@ CExplosion::Update() break; case EXPLOSION_CAR: case EXPLOSION_CAR_QUICK: + case EXPLOSION_BOAT: if (someTime >= 3500) { - if (explosion.m_pVictimEntity != nil && !explosion.m_bIsBoat) { - if ((CGeneral::GetRandomNumber() & 0xF) == 0) { + if (explosion.m_pVictimEntity != nil) { + if ((CGeneral::GetRandomNumber() & 0xF) == 0 && !explosion.m_bIsBoat) { CVehicle *veh = (CVehicle*)explosion.m_pVictimEntity; uint8 component = CAR_WING_LR; @@ -383,16 +432,14 @@ CExplosion::Update() if (veh->IsComponentPresent(component)) { CVector componentPos; veh->GetComponentWorldPosition(component, componentPos); - CParticle::AddJetExplosion(componentPos, 1.5f, 0.0f); + CParticle::AddJetExplosion(componentPos, 0.5f, 0.0f); } } if (CTimer::GetTimeInMilliseconds() > explosion.m_fStartTime) { explosion.m_fStartTime = CTimer::GetTimeInMilliseconds() + 125 + (CGeneral::GetRandomNumber() & 0x7F); CVector pos = explosion.m_pVictimEntity->GetPosition(); - for (int i = 0; i < (CGeneral::GetRandomNumber() & 1) + 1; i++) { + for (int i = 0; i < (CGeneral::GetRandomNumber() & 1) + 1; i++) CParticle::AddParticle(PARTICLE_EXPLOSION_MEDIUM, pos, CVector(0.0f, 0.0f, 0.0f), nil, 3.5f, color); - CParticle::AddParticle(PARTICLE_EXPLOSION_LARGE, pos, CVector(0.0f, 0.0f, 0.0f), nil, 5.5f, color); - } } } if (CTimer::GetFrameCounter() & 1) { @@ -419,13 +466,15 @@ CExplosion::Update() CVector pos(x - 128, y - 128, (z % 128) + 1); pos.Normalise(); - pos *= ff / 5.0f; + pos *= (explosion.m_nIteration + 1) * ff / 5.0f; pos += explosion.m_vecPosition; pos.z += 0.5f; CParticle::AddParticle(PARTICLE_EXPLOSION_LARGE, pos, CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, color, CGeneral::GetRandomNumberInRange(-3.0f, 3.0f), CGeneral::GetRandomNumberInRange(-180.0f, 180.0f)); } } break; + default: + break; } if (someTime > 0) explosion.m_nIteration++; |