Refactor CObject::ObjectDamage

This commit is contained in:
saml1er 2020-04-10 19:32:42 +05:00
parent bb21cff639
commit 5544325acb
2 changed files with 144 additions and 145 deletions

View File

@ -27,7 +27,7 @@ CObject::CObject(void)
m_nCollisionDamageEffect = 0; m_nCollisionDamageEffect = 0;
m_nSpecialCollisionResponseCases = COLLRESPONSE_NONE; m_nSpecialCollisionResponseCases = COLLRESPONSE_NONE;
m_bCameraToAvoidThisObject = false; m_bCameraToAvoidThisObject = false;
ObjectCreatedBy = 0; ObjectCreatedBy = UNKNOWN_OBJECT;
m_nEndOfLifeTime = 0; m_nEndOfLifeTime = 0;
// m_nRefModelIndex = -1; // duplicate // m_nRefModelIndex = -1; // duplicate
// bUseVehicleColours = false; // duplicate // bUseVehicleColours = false; // duplicate
@ -97,7 +97,7 @@ CObject::ProcessControl(void)
m_vecMoveSpeed *= fTimeStep; m_vecMoveSpeed *= fTimeStep;
m_vecTurnSpeed *= fTimeStep; m_vecTurnSpeed *= fTimeStep;
} }
if ((MI_EXPLODINGBARREL == m_modelIndex || MI_PETROLPUMP == m_modelIndex) && bHasBeenDamaged && bIsVisible if ((m_modelIndex == MI_EXPLODINGBARREL || m_modelIndex == MI_PETROLPUMP) && bHasBeenDamaged && bIsVisible
&& CGeneral::GetRandomNumberInRange(0, 31) == 10) { && CGeneral::GetRandomNumberInRange(0, 31) == 10) {
bExplosionProof = true; bExplosionProof = true;
bIsVisible = false; bIsVisible = false;
@ -155,12 +155,13 @@ CObject::RemoveLighting(bool reset)
void void
CObject::ObjectDamage(float amount) CObject::ObjectDamage(float amount)
{ {
if (m_nCollisionDamageEffect && bUsesCollision) { if (!m_nCollisionDamageEffect || !bUsesCollision)
return;
static int8 nFrameGen = 0; static int8 nFrameGen = 0;
bool bBodyCastDamageEffect = false; bool bBodyCastDamageEffect = false;
if (m_modelIndex == MI_BODYCAST){ if (m_modelIndex == MI_BODYCAST){
if (amount > 50.0f) if (amount > 50.0f)
nBodyCastHealth = static_cast<int16>(nBodyCastHealth - 0.5f * amount); nBodyCastHealth = int16(nBodyCastHealth - 0.5f * amount);
if (nBodyCastHealth < 0) if (nBodyCastHealth < 0)
nBodyCastHealth = 0; nBodyCastHealth = 0;
if (nBodyCastHealth < 200) if (nBodyCastHealth < 200)
@ -172,7 +173,8 @@ CObject::ObjectDamage(float amount)
bRenderDamaged = true; bRenderDamaged = true;
return; return;
} }
if (m_nCollisionDamageEffect != COLDAMAGE_EFFECT_SPLIT_MODEL) { if (m_nCollisionDamageEffect == COLDAMAGE_EFFECT_SPLIT_MODEL)
return;
if (m_nCollisionDamageEffect == COLDAMAGE_EFFECT_SMASH_COMPLETELY) { if (m_nCollisionDamageEffect == COLDAMAGE_EFFECT_SMASH_COMPLETELY) {
bIsVisible = false; bIsVisible = false;
bUsesCollision = false; bUsesCollision = false;
@ -183,7 +185,6 @@ CObject::ObjectDamage(float amount)
return; return;
} }
if (m_nCollisionDamageEffect != COLDAMAGE_EFFECT_CHANGE_THEN_SMASH) { if (m_nCollisionDamageEffect != COLDAMAGE_EFFECT_CHANGE_THEN_SMASH) {
uint8 audioId = 0;
const CVector& vecPos = m_matrix.GetPosition(); const CVector& vecPos = m_matrix.GetPosition();
const float fDirectionZ = 0.0002f * amount; const float fDirectionZ = 0.0002f * amount;
switch (m_nCollisionDamageEffect) switch (m_nCollisionDamageEffect)
@ -208,7 +209,7 @@ CObject::ObjectDamage(float amount)
int32 nRotationSpeed = CGeneral::GetRandomNumberInRange(-40, 80); int32 nRotationSpeed = CGeneral::GetRandomNumberInRange(-40, 80);
CParticle::AddParticle(PARTICLE_CAR_DEBRIS, vecPos, vecDir, nil, fSize, randomColor, nRotationSpeed, 0, currentFrame, 0); CParticle::AddParticle(PARTICLE_CAR_DEBRIS, vecPos, vecDir, nil, fSize, randomColor, nRotationSpeed, 0, currentFrame, 0);
} }
audioId = _SCRSOUND_CARDBOARD_BOX_SMASH; PlayOneShotScriptObject(_SCRSOUND_CARDBOARD_BOX_SMASH, vecPos);
break; break;
} }
case COLDAMAGE_EFFECT_SMASH_WOODENBOX_COMPLETELY: { case COLDAMAGE_EFFECT_SMASH_WOODENBOX_COMPLETELY: {
@ -231,7 +232,7 @@ CObject::ObjectDamage(float amount)
int32 nRotationSpeed = CGeneral::GetRandomNumberInRange(-40, 80); int32 nRotationSpeed = CGeneral::GetRandomNumberInRange(-40, 80);
CParticle::AddParticle(PARTICLE_CAR_DEBRIS, vecPos, vecDir, nil, fSize, randomColor, nRotationSpeed, 0, currentFrame, 0); CParticle::AddParticle(PARTICLE_CAR_DEBRIS, vecPos, vecDir, nil, fSize, randomColor, nRotationSpeed, 0, currentFrame, 0);
} }
audioId = _SCRSOUND_WOODEN_BOX_SMASH; PlayOneShotScriptObject(_SCRSOUND_WOODEN_BOX_SMASH, vecPos);
break; break;
} }
case COLDAMAGE_EFFECT_SMASH_TRAFFICCONE_COMPLETELY: { case COLDAMAGE_EFFECT_SMASH_TRAFFICCONE_COMPLETELY: {
@ -256,7 +257,7 @@ CObject::ObjectDamage(float amount)
int32 nRotationSpeed = CGeneral::GetRandomNumberInRange(-40, 80); int32 nRotationSpeed = CGeneral::GetRandomNumberInRange(-40, 80);
CParticle::AddParticle(PARTICLE_CAR_DEBRIS, vecPos, vecDir, nil, fSize, color, nRotationSpeed, 0, currentFrame, 0); CParticle::AddParticle(PARTICLE_CAR_DEBRIS, vecPos, vecDir, nil, fSize, color, nRotationSpeed, 0, currentFrame, 0);
} }
audioId = _SCRSOUND_TYRE_BUMP; PlayOneShotScriptObject(_SCRSOUND_TYRE_BUMP, vecPos);
break; break;
} }
case COLDAMAGE_EFFECT_SMASH_BARPOST_COMPLETELY: { case COLDAMAGE_EFFECT_SMASH_BARPOST_COMPLETELY: {
@ -281,13 +282,12 @@ CObject::ObjectDamage(float amount)
int32 nRotationSpeed = CGeneral::GetRandomNumberInRange(-40, 80); int32 nRotationSpeed = CGeneral::GetRandomNumberInRange(-40, 80);
CParticle::AddParticle(PARTICLE_CAR_DEBRIS, vecPos, vecDir, nil, fSize, color, nRotationSpeed, 0, currentFrame, 0); CParticle::AddParticle(PARTICLE_CAR_DEBRIS, vecPos, vecDir, nil, fSize, color, nRotationSpeed, 0, currentFrame, 0);
} }
audioId = _SCRSOUND_COL_CAR; PlayOneShotScriptObject(_SCRSOUND_COL_CAR, vecPos);
break; break;
} }
default: default:
return; return;
} }
PlayOneShotScriptObject(audioId, vecPos);
return; return;
} }
if (!bRenderDamaged) { if (!bRenderDamaged) {
@ -302,8 +302,6 @@ CObject::ObjectDamage(float amount)
} }
} }
} }
}
}
void void
CObject::RefModelInfo(int32 modelId) CObject::RefModelInfo(int32 modelId)

View File

@ -3,6 +3,7 @@
#include "Physical.h" #include "Physical.h"
enum { enum {
UNKNOWN_OBJECT = 0,
GAME_OBJECT = 1, GAME_OBJECT = 1,
MISSION_OBJECT = 2, MISSION_OBJECT = 2,
TEMP_OBJECT = 3, TEMP_OBJECT = 3,