forked from ReactiveDrop/reactivedrop_public_src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_asw_fade.cpp
More file actions
177 lines (149 loc) · 4.8 KB
/
Copy pathfunc_asw_fade.cpp
File metadata and controls
177 lines (149 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "cbase.h"
#include "func_asw_fade.h"
#include "asw_shareddefs.h"
#include "asw_fade_proxy_shared.h"
#include "asw_inhabitable_npc.h"
#include "asw_player.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
LINK_ENTITY_TO_CLASS( func_asw_fade, CFunc_ASW_Fade );
BEGIN_DATADESC( CFunc_ASW_Fade )
DEFINE_FIELD( m_bHasProxies, FIELD_BOOLEAN ),
DEFINE_KEYFIELD( m_nFadeOpacity, FIELD_CHARACTER, "fade_opacity" ),
DEFINE_KEYFIELD( m_iCollideWithGrenades, FIELD_CHARACTER, "CollideWithGrenades" ),
DEFINE_KEYFIELD( m_bCollideWithMarines, FIELD_BOOLEAN, "CollideWithMarines" ),
DEFINE_INPUT( m_bAllowFade, FIELD_BOOLEAN, "AllowFade" ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "SetCollideWithGrenades", SetGrenadeCollisionRules ),
DEFINE_INPUTFUNC( FIELD_BOOLEAN, "SetCollideWithMarines", SetMarineCollisionRules ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST( CFunc_ASW_Fade, DT_Func_ASW_Fade )
SendPropInt( SENDINFO( m_nFadeOpacity ), 8, SPROP_UNSIGNED ),
SendPropInt( SENDINFO( m_iCollideWithGrenades ), 2, SPROP_UNSIGNED ),
SendPropBool( SENDINFO( m_bCollideWithMarines ) ),
SendPropBool( SENDINFO( m_bAllowFade ) ),
SendPropBool( SENDINFO( m_bHasProxies ) ),
END_SEND_TABLE()
CFunc_ASW_Fade::CFunc_ASW_Fade()
{
m_bHasProxies = false;
m_iCollideWithGrenades = 0;
m_bCollideWithMarines = true;
m_nFadeOpacity = 0;
m_bAllowFade = true;
}
void CFunc_ASW_Fade::Spawn()
{
BaseClass::Spawn();
SetCollisionGroup( COLLISION_GROUP_NONE );
Assert( m_iCollideWithGrenades <= 2 );
}
void CFunc_ASW_Fade::ApplyGrenadeCollisionRules( CBaseEntity* pGrenade )
{
const float flGrenadeZ = pGrenade->GetAbsOrigin().z;
const string_t iszClassName = AllocPooledString( "func_asw_fade" );
CFunc_ASW_Fade* pCeiling = nullptr;
while ( ( pCeiling = assert_cast<CFunc_ASW_Fade*>(
gEntList.FindEntityByClassnameFast( pCeiling, iszClassName ) ) ) != nullptr )
{
const bool bShouldDisable =
( pCeiling->m_iCollideWithGrenades == 0 && pCeiling->GetAbsOrigin().z >= flGrenadeZ ) ||
( pCeiling->m_iCollideWithGrenades == 2 );
const bool bCurrentlyDisabled = PhysEntityCollisionsAreDisabled( pCeiling, pGrenade );
if ( bShouldDisable && !bCurrentlyDisabled )
{
PhysDisableEntityCollisions( pCeiling, pGrenade );
}
else if ( !bShouldDisable && bCurrentlyDisabled )
{
PhysEnableEntityCollisions( pCeiling, pGrenade );
}
}
}
void CFunc_ASW_Fade::ApplyMarineCollisionRules( CBaseEntity* pMarine )
{
const string_t iszClassName = AllocPooledString( "func_asw_fade" );
CFunc_ASW_Fade* pCeiling = nullptr;
while ( ( pCeiling = assert_cast<CFunc_ASW_Fade*>(
gEntList.FindEntityByClassnameFast( pCeiling, iszClassName ) ) ) != nullptr )
{
const bool bShouldDisable = !pCeiling->m_bCollideWithMarines;
const bool bCurrentlyDisabled = PhysEntityCollisionsAreDisabled( pCeiling, pMarine );
if ( bShouldDisable && !bCurrentlyDisabled )
{
PhysDisableEntityCollisions( pCeiling, pMarine );
}
else if ( !bShouldDisable && bCurrentlyDisabled )
{
PhysEnableEntityCollisions( pCeiling, pMarine );
}
}
}
void CFunc_ASW_Fade::SetGrenadeCollisionRules( inputdata_t& inputdata )
{
m_iCollideWithGrenades = clamp( inputdata.value.Int(), 0, 2 );
static const char* pszExplosiveClasses[] = {
"asw_mine",
"npc_grenade_frag",
"asw_rocket",
"grenadespit",
"asw_missile_round",
"asw_grenade_cluster",
"asw_flare_projectile",
"asw_laser_mine",
"asw_grenade_vindicator",
"asw_gas_grenade_projectile",
nullptr
};
for ( const char** pszClass = pszExplosiveClasses; *pszClass; ++pszClass )
{
CBaseEntity* pGrenade = NULL;
while ( ( pGrenade = gEntList.FindEntityByClassname( pGrenade, *pszClass ) ) != NULL )
{
ApplyGrenadeCollisionRules( pGrenade );
}
}
}
void CFunc_ASW_Fade::SetMarineCollisionRules( inputdata_t& inputdata )
{
m_bCollideWithMarines = !!inputdata.value.Int();
CBaseEntity* pMarine = NULL;
while ( ( pMarine = gEntList.FindEntityByClassname( pMarine, "asw_marine" ) ) != NULL )
{
ApplyMarineCollisionRules( pMarine );
}
}
bool CFunc_ASW_Fade::ShouldFade( CASW_Inhabitable_NPC *pNPC )
{
if ( !m_bAllowFade || !pNPC || !pNPC->IsInhabited() || !pNPC->GetCommander() )
{
return false;
}
if ( pNPC->GetCommander()->GetASWControls() == ASWC_TOPDOWN )
{
if ( m_bHasProxies )
{
Vector vecEyePosition = pNPC->EyePosition();
#ifdef DBGFLAG_ASSERT
bool bAtLeastOneProxy = false;
#endif
for ( CBaseEntity *pEnt = FirstMoveChild(); pEnt; pEnt = pEnt->NextMovePeer() )
{
CPoint_ASW_Fade_Proxy *pProxy = dynamic_cast< CPoint_ASW_Fade_Proxy * >( pEnt );
if ( pProxy )
{
if ( pProxy->ShouldFade( vecEyePosition ) )
{
return true;
}
#ifdef DBGFLAG_ASSERT
bAtLeastOneProxy = true;
#endif
}
}
Assert( bAtLeastOneProxy );
return false;
}
return pNPC->GetAbsOrigin().z < GetAbsOrigin().z;
}
return false;
}