Skip to content

Commit

Permalink
CBulletManager::test_callback: move object verification to much earli…
Browse files Browse the repository at this point in the history
…er in method
  • Loading branch information
revolucas committed Sep 10, 2016
1 parent f59215c commit 3724022
Showing 1 changed file with 78 additions and 77 deletions.
155 changes: 78 additions & 77 deletions src/xrGame/Level_bullet_manager_firetrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extern float gCheckHitK;
//return TRUE-òåñòèðîâàòü îáúåêò / FALSE-ïðîïóñòèòü îáúåêò
BOOL CBulletManager::test_callback(const collide::ray_defs& rd, IGameObject* object, LPVOID params)
{
if (!object)
return TRUE;

bullet_test_callback_data* pData = (bullet_test_callback_data*)params;
SBullet* bullet = pData->pBullet;

Expand All @@ -44,97 +47,95 @@ BOOL CBulletManager::test_callback(const collide::ray_defs& rd, IGameObject* obj
(!bullet->flags.ricochet_was)) return FALSE;

BOOL bRes = TRUE;
if (object){
CEntity* entity = smart_cast<CEntity*>(object);
if (entity&&entity->g_Alive()&&(entity->ID()!=bullet->parent_id)){
ICollisionForm* cform = entity->GetCForm();
if ((NULL!=cform) && (cftObject==cform->Type())){
CActor* actor = smart_cast<CActor*>(entity);
CAI_Stalker* stalker= smart_cast<CAI_Stalker*>(entity);
// â êîãî ïîïàëè?
if (actor && IsGameTypeSingle()/**/||stalker/**/){
// ïîïàëè â àêòåðà èëè ñòàëêåðà
Fsphere S = cform->getSphere();
entity->XFORM().transform_tiny (S.P) ;
float dist = rd.range;
// ïðîâåðèì ïîïàëè ëè ìû â îïèñûâàþùóþ ñôåðó
if (Fsphere::rpNone!=S.intersect_full(bullet->bullet_pos, bullet->dir, dist))
{
// äà ïîïàëè, íàéäåì êòî ñòðåëÿë
bool play_whine = true;
IGameObject* initiator = Level().Objects.net_Find (bullet->parent_id);
if (actor){
// ïîïàëè â àêòåðà
float hpf = 1.f;
float ahp = actor->HitProbability();
CEntity* entity = smart_cast<CEntity*>(object);
if (entity&&entity->g_Alive()&&(entity->ID()!=bullet->parent_id)){
ICollisionForm* cform = entity->GetCForm();
if ((NULL!=cform) && (cftObject==cform->Type())){
CActor* actor = smart_cast<CActor*>(entity);
CAI_Stalker* stalker= smart_cast<CAI_Stalker*>(entity);
// â êîãî ïîïàëè?
if (actor && IsGameTypeSingle()/**/||stalker/**/){
// ïîïàëè â àêòåðà èëè ñòàëêåðà
Fsphere S = cform->getSphere();
entity->XFORM().transform_tiny (S.P) ;
float dist = rd.range;
// ïðîâåðèì ïîïàëè ëè ìû â îïèñûâàþùóþ ñôåðó
if (Fsphere::rpNone!=S.intersect_full(bullet->bullet_pos, bullet->dir, dist))
{
// äà ïîïàëè, íàéäåì êòî ñòðåëÿë
bool play_whine = true;
IGameObject* initiator = Level().Objects.net_Find (bullet->parent_id);
if (actor){
// ïîïàëè â àêòåðà
float hpf = 1.f;
float ahp = actor->HitProbability();
#if 1
# if 0
IGameObject *weapon_object = Level().Objects.net_Find (bullet->weapon_id);
if (weapon_object) {
CWeapon *weapon = smart_cast<CWeapon*>(weapon_object);
if (weapon) {
float fly_dist = bullet->fly_dist+dist;
float dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
ahp = dist_factor*weapon->hit_probability() + (1.f-dist_factor)*1.f;
}
IGameObject *weapon_object = Level().Objects.net_Find (bullet->weapon_id);
if (weapon_object) {
CWeapon *weapon = smart_cast<CWeapon*>(weapon_object);
if (weapon) {
float fly_dist = bullet->fly_dist+dist;
float dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
ahp = dist_factor*weapon->hit_probability() + (1.f-dist_factor)*1.f;
}
}
# else
float game_difficulty_hit_probability = actor->HitProbability();
CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(initiator);
if (stalker)
hpf = stalker->SpecificCharacter().hit_probability_factor();

float dist_factor = 1.f;
IGameObject *weapon_object = Level().Objects.net_Find (bullet->weapon_id);
if (weapon_object) {
CWeapon *weapon = smart_cast<CWeapon*>(weapon_object);
if (weapon) {
game_difficulty_hit_probability = weapon->hit_probability();
float fly_dist = bullet->fly_dist+dist;
dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
}
float game_difficulty_hit_probability = actor->HitProbability();
CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(initiator);
if (stalker)
hpf = stalker->SpecificCharacter().hit_probability_factor();

float dist_factor = 1.f;
IGameObject *weapon_object = Level().Objects.net_Find (bullet->weapon_id);
if (weapon_object) {
CWeapon *weapon = smart_cast<CWeapon*>(weapon_object);
if (weapon) {
game_difficulty_hit_probability = weapon->hit_probability();
float fly_dist = bullet->fly_dist+dist;
dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
}
}

ahp = dist_factor*game_difficulty_hit_probability + (1.f-dist_factor)*1.f;
ahp = dist_factor*game_difficulty_hit_probability + (1.f-dist_factor)*1.f;
# endif
#else
CAI_Stalker* i_stalker = smart_cast<CAI_Stalker*>(initiator);
// åñëè ñòðåëÿë ñòàëêåð, ó÷èòûâàåì - hit_probability_factor ñòàëêåða èíà÷å - 1.0
if (i_stalker) {
hpf = i_stalker->SpecificCharacter().hit_probability_factor();
float fly_dist = bullet->fly_dist+dist;
float dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
ahp = dist_factor*actor->HitProbability() + (1.f-dist_factor)*1.f;
}
CAI_Stalker* i_stalker = smart_cast<CAI_Stalker*>(initiator);
// åñëè ñòðåëÿë ñòàëêåð, ó÷èòûâàåì - hit_probability_factor ñòàëêåða èíà÷å - 1.0
if (i_stalker) {
hpf = i_stalker->SpecificCharacter().hit_probability_factor();
float fly_dist = bullet->fly_dist+dist;
float dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
ahp = dist_factor*actor->HitProbability() + (1.f-dist_factor)*1.f;
}
#endif
if (Random.randF(0.f,1.f)>(ahp*hpf)){
bRes = FALSE; // don't hit actor
play_whine = true; // play whine sound
if (Random.randF(0.f,1.f)>(ahp*hpf)){
bRes = FALSE; // don't hit actor
play_whine = true; // play whine sound
}else{
// real test actor CFORM
Level().BulletManager().m_rq_results.r_clear();

if (cform->_RayQuery(rd,Level().BulletManager().m_rq_results)){
bRes = TRUE; // hit actor
play_whine = false; // don't play whine sound
}else{
// real test actor CFORM
Level().BulletManager().m_rq_results.r_clear();

if (cform->_RayQuery(rd,Level().BulletManager().m_rq_results)){
bRes = TRUE; // hit actor
play_whine = false; // don't play whine sound
}else{
bRes = FALSE; // don't hit actor
play_whine = true; // play whine sound
}
bRes = FALSE; // don't hit actor
play_whine = true; // play whine sound
}
}
// play whine sound
if (play_whine){
Fvector pt;
pt.mad (bullet->bullet_pos, bullet->dir, dist);
Level().BulletManager().PlayWhineSound (bullet,initiator,pt);
}
}else{
// don't test this object again (return FALSE)
bRes = FALSE;
}

// play whine sound
if (play_whine){
Fvector pt;
pt.mad (bullet->bullet_pos, bullet->dir, dist);
Level().BulletManager().PlayWhineSound (bullet,initiator,pt);
}
}else{
// don't test this object again (return FALSE)
bRes = FALSE;
}

}
}
}
Expand Down

0 comments on commit 3724022

Please sign in to comment.