| 434 | }; |
| 435 | |
| 436 | void CActor::Hit(SHit* pHDS) |
| 437 | { |
| 438 | pHDS->aim_bullet = false; |
| 439 | |
| 440 | SHit HDS = *pHDS; |
| 441 | if (HDS.hit_type < ALife::eHitTypeBurn || HDS.hit_type >= ALife::eHitTypeMax) |
| 442 | { |
| 443 | string256 err; |
| 444 | sprintf_s(err, "Unknown/unregistered hit type [%d]", HDS.hit_type); |
| 445 | R_ASSERT2(0, err); |
| 446 | } |
| 447 | #ifdef DEBUG |
| 448 | if (ph_dbg_draw_mask.test(phDbgCharacterControl)) |
| 449 | { |
| 450 | DBG_OpenCashedDraw(); |
| 451 | Fvector to; |
| 452 | to.add(Position(), Fvector().mul(HDS.dir, HDS.phys_impulse())); |
| 453 | DBG_DrawLine(Position(), to, D3DCOLOR_XRGB(124, 124, 0)); |
| 454 | DBG_ClosedCashedDraw(500); |
| 455 | } |
| 456 | #endif // DEBUG |
| 457 | |
| 458 | callback(GameObject::entity_alive_before_hit)(&HDS); |
| 459 | if (HDS.ignore_flag) |
| 460 | return; |
| 461 | |
| 462 | bool bPlaySound = true; |
| 463 | if (!g_Alive()) |
| 464 | bPlaySound = false; |
| 465 | |
| 466 | if (HDS.hit_type == ALife::eHitTypeRadiation) |
| 467 | HDS.power *= m_fDrugRadProtectionCoeff; |
| 468 | |
| 469 | if (HDS.hit_type == ALife::eHitTypeTelepatic) |
| 470 | HDS.power *= m_fDrugPsyProtectionCoeff; |
| 471 | |
| 472 | if (!sndHit[HDS.hit_type].empty() && (ALife::eHitTypeTelepatic != HDS.hit_type)) |
| 473 | { |
| 474 | ref_sound& S = sndHit[HDS.hit_type][Random.randI(sndHit[HDS.hit_type].size())]; |
| 475 | bool b_snd_hit_playing = sndHit[HDS.hit_type].end() != std::find_if(sndHit[HDS.hit_type].begin(), sndHit[HDS.hit_type].end(), playing_pred()); |
| 476 | |
| 477 | if (ALife::eHitTypeExplosion == HDS.hit_type) |
| 478 | { |
| 479 | if (this == Level().CurrentControlEntity()) |
| 480 | { |
| 481 | S.set_volume(10.0f); |
| 482 | if (!m_sndShockEffector) |
| 483 | { |
| 484 | m_sndShockEffector = xr_new<SndShockEffector>(); |
| 485 | m_sndShockEffector->Start(this, float(S.get_length_sec() * 1000.0f), HDS.damage()); |
| 486 | } |
| 487 | } |
| 488 | else |
| 489 | bPlaySound = false; |
| 490 | } |
| 491 | if (bPlaySound && !b_snd_hit_playing) |
| 492 | { |
| 493 | Fvector point = Position(); |
no test coverage detected