Skip to content

Commit 3724022

Browse files
committed
CBulletManager::test_callback: move object verification to much earlier in method
1 parent f59215c commit 3724022

File tree

1 file changed

+78
-77
lines changed

1 file changed

+78
-77
lines changed

src/xrGame/Level_bullet_manager_firetrace.cpp

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ extern float gCheckHitK;
3636
//return TRUE-òåñòèðîâàòü îáúåêò / FALSE-ïðîïóñòèòü îáúåêò
3737
BOOL CBulletManager::test_callback(const collide::ray_defs& rd, IGameObject* object, LPVOID params)
3838
{
39+
if (!object)
40+
return TRUE;
41+
3942
bullet_test_callback_data* pData = (bullet_test_callback_data*)params;
4043
SBullet* bullet = pData->pBullet;
4144

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

4649
BOOL bRes = TRUE;
47-
if (object){
48-
CEntity* entity = smart_cast<CEntity*>(object);
49-
if (entity&&entity->g_Alive()&&(entity->ID()!=bullet->parent_id)){
50-
ICollisionForm* cform = entity->GetCForm();
51-
if ((NULL!=cform) && (cftObject==cform->Type())){
52-
CActor* actor = smart_cast<CActor*>(entity);
53-
CAI_Stalker* stalker= smart_cast<CAI_Stalker*>(entity);
54-
// â êîãî ïîïàëè?
55-
if (actor && IsGameTypeSingle()/**/||stalker/**/){
56-
// ïîïàëè â àêòåðà èëè ñòàëêåðà
57-
Fsphere S = cform->getSphere();
58-
entity->XFORM().transform_tiny (S.P) ;
59-
float dist = rd.range;
60-
// ïðîâåðèì ïîïàëè ëè ìû â îïèñûâàþùóþ ñôåðó
61-
if (Fsphere::rpNone!=S.intersect_full(bullet->bullet_pos, bullet->dir, dist))
62-
{
63-
// äà ïîïàëè, íàéäåì êòî ñòðåëÿë
64-
bool play_whine = true;
65-
IGameObject* initiator = Level().Objects.net_Find (bullet->parent_id);
66-
if (actor){
67-
// ïîïàëè â àêòåðà
68-
float hpf = 1.f;
69-
float ahp = actor->HitProbability();
50+
CEntity* entity = smart_cast<CEntity*>(object);
51+
if (entity&&entity->g_Alive()&&(entity->ID()!=bullet->parent_id)){
52+
ICollisionForm* cform = entity->GetCForm();
53+
if ((NULL!=cform) && (cftObject==cform->Type())){
54+
CActor* actor = smart_cast<CActor*>(entity);
55+
CAI_Stalker* stalker= smart_cast<CAI_Stalker*>(entity);
56+
// â êîãî ïîïàëè?
57+
if (actor && IsGameTypeSingle()/**/||stalker/**/){
58+
// ïîïàëè â àêòåðà èëè ñòàëêåðà
59+
Fsphere S = cform->getSphere();
60+
entity->XFORM().transform_tiny (S.P) ;
61+
float dist = rd.range;
62+
// ïðîâåðèì ïîïàëè ëè ìû â îïèñûâàþùóþ ñôåðó
63+
if (Fsphere::rpNone!=S.intersect_full(bullet->bullet_pos, bullet->dir, dist))
64+
{
65+
// äà ïîïàëè, íàéäåì êòî ñòðåëÿë
66+
bool play_whine = true;
67+
IGameObject* initiator = Level().Objects.net_Find (bullet->parent_id);
68+
if (actor){
69+
// ïîïàëè â àêòåðà
70+
float hpf = 1.f;
71+
float ahp = actor->HitProbability();
7072
#if 1
7173
# if 0
72-
IGameObject *weapon_object = Level().Objects.net_Find (bullet->weapon_id);
73-
if (weapon_object) {
74-
CWeapon *weapon = smart_cast<CWeapon*>(weapon_object);
75-
if (weapon) {
76-
float fly_dist = bullet->fly_dist+dist;
77-
float dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
78-
ahp = dist_factor*weapon->hit_probability() + (1.f-dist_factor)*1.f;
79-
}
74+
IGameObject *weapon_object = Level().Objects.net_Find (bullet->weapon_id);
75+
if (weapon_object) {
76+
CWeapon *weapon = smart_cast<CWeapon*>(weapon_object);
77+
if (weapon) {
78+
float fly_dist = bullet->fly_dist+dist;
79+
float dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
80+
ahp = dist_factor*weapon->hit_probability() + (1.f-dist_factor)*1.f;
8081
}
82+
}
8183
# else
82-
float game_difficulty_hit_probability = actor->HitProbability();
83-
CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(initiator);
84-
if (stalker)
85-
hpf = stalker->SpecificCharacter().hit_probability_factor();
86-
87-
float dist_factor = 1.f;
88-
IGameObject *weapon_object = Level().Objects.net_Find (bullet->weapon_id);
89-
if (weapon_object) {
90-
CWeapon *weapon = smart_cast<CWeapon*>(weapon_object);
91-
if (weapon) {
92-
game_difficulty_hit_probability = weapon->hit_probability();
93-
float fly_dist = bullet->fly_dist+dist;
94-
dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
95-
}
84+
float game_difficulty_hit_probability = actor->HitProbability();
85+
CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(initiator);
86+
if (stalker)
87+
hpf = stalker->SpecificCharacter().hit_probability_factor();
88+
89+
float dist_factor = 1.f;
90+
IGameObject *weapon_object = Level().Objects.net_Find (bullet->weapon_id);
91+
if (weapon_object) {
92+
CWeapon *weapon = smart_cast<CWeapon*>(weapon_object);
93+
if (weapon) {
94+
game_difficulty_hit_probability = weapon->hit_probability();
95+
float fly_dist = bullet->fly_dist+dist;
96+
dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
9697
}
98+
}
9799

98-
ahp = dist_factor*game_difficulty_hit_probability + (1.f-dist_factor)*1.f;
100+
ahp = dist_factor*game_difficulty_hit_probability + (1.f-dist_factor)*1.f;
99101
# endif
100102
#else
101-
CAI_Stalker* i_stalker = smart_cast<CAI_Stalker*>(initiator);
102-
// åñëè ñòðåëÿë ñòàëêåð, ó÷èòûâàåì - hit_probability_factor ñòàëêåða èíà÷å - 1.0
103-
if (i_stalker) {
104-
hpf = i_stalker->SpecificCharacter().hit_probability_factor();
105-
float fly_dist = bullet->fly_dist+dist;
106-
float dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
107-
ahp = dist_factor*actor->HitProbability() + (1.f-dist_factor)*1.f;
108-
}
103+
CAI_Stalker* i_stalker = smart_cast<CAI_Stalker*>(initiator);
104+
// åñëè ñòðåëÿë ñòàëêåð, ó÷èòûâàåì - hit_probability_factor ñòàëêåða èíà÷å - 1.0
105+
if (i_stalker) {
106+
hpf = i_stalker->SpecificCharacter().hit_probability_factor();
107+
float fly_dist = bullet->fly_dist+dist;
108+
float dist_factor = _min(1.f,fly_dist/Level().BulletManager().m_fHPMaxDist);
109+
ahp = dist_factor*actor->HitProbability() + (1.f-dist_factor)*1.f;
110+
}
109111
#endif
110-
if (Random.randF(0.f,1.f)>(ahp*hpf)){
111-
bRes = FALSE; // don't hit actor
112-
play_whine = true; // play whine sound
112+
if (Random.randF(0.f,1.f)>(ahp*hpf)){
113+
bRes = FALSE; // don't hit actor
114+
play_whine = true; // play whine sound
115+
}else{
116+
// real test actor CFORM
117+
Level().BulletManager().m_rq_results.r_clear();
118+
119+
if (cform->_RayQuery(rd,Level().BulletManager().m_rq_results)){
120+
bRes = TRUE; // hit actor
121+
play_whine = false; // don't play whine sound
113122
}else{
114-
// real test actor CFORM
115-
Level().BulletManager().m_rq_results.r_clear();
116-
117-
if (cform->_RayQuery(rd,Level().BulletManager().m_rq_results)){
118-
bRes = TRUE; // hit actor
119-
play_whine = false; // don't play whine sound
120-
}else{
121-
bRes = FALSE; // don't hit actor
122-
play_whine = true; // play whine sound
123-
}
123+
bRes = FALSE; // don't hit actor
124+
play_whine = true; // play whine sound
124125
}
125126
}
126-
// play whine sound
127-
if (play_whine){
128-
Fvector pt;
129-
pt.mad (bullet->bullet_pos, bullet->dir, dist);
130-
Level().BulletManager().PlayWhineSound (bullet,initiator,pt);
131-
}
132-
}else{
133-
// don't test this object again (return FALSE)
134-
bRes = FALSE;
135127
}
136-
128+
// play whine sound
129+
if (play_whine){
130+
Fvector pt;
131+
pt.mad (bullet->bullet_pos, bullet->dir, dist);
132+
Level().BulletManager().PlayWhineSound (bullet,initiator,pt);
133+
}
134+
}else{
135+
// don't test this object again (return FALSE)
136+
bRes = FALSE;
137137
}
138+
138139
}
139140
}
140141
}

0 commit comments

Comments
 (0)