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
178
179
180
181
182
183
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define SF_NAV_START_ON 0x0001
enum navproperties_t
{
NAV_IGNORE = 1<<0,
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CLogicNavigation : public CLogicalEntity,
public IEntityListener
{
DECLARE_CLASS( CLogicNavigation, CLogicalEntity );
bool KeyValue( const char *szKeyName, const char *szValue );
void Activate( void );
private:
void UpdateOnRemove();
void OnEntitySpawned( CBaseEntity *pEntity );
// Inputs
void InputTurnOn( inputdata_t &inputdata ) { TurnOn(); }
void InputTurnOff( inputdata_t &inputdata ) { TurnOff(); }
void InputToggle( inputdata_t &inputdata )
{
if ( m_isOn )
TurnOff();
else
TurnOn();
}
void TurnOn();
void TurnOff();
void UpdateProperty();
DECLARE_DATADESC();
bool m_isOn;
navproperties_t m_navProperty;
};
LINK_ENTITY_TO_CLASS(logic_navigation, CLogicNavigation);
BEGIN_DATADESC( CLogicNavigation )
DEFINE_FIELD( m_isOn, FIELD_BOOLEAN ),
DEFINE_FIELD( m_navProperty, FIELD_INTEGER ),
// Inputs
DEFINE_INPUTFUNC(FIELD_VOID, "TurnOn", InputTurnOn),
DEFINE_INPUTFUNC(FIELD_VOID, "TurnOff", InputTurnOff),
DEFINE_INPUTFUNC(FIELD_VOID, "Toggle", InputToggle),
END_DATADESC()
//-----------------------------------------------------------------------------
// Purpose:
// Input : *szKeyName -
// *szValue -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CLogicNavigation::KeyValue( const char *szKeyName, const char *szValue )
{
if ( FStrEq(szKeyName, "navprop") )
{
if ( FStrEq( szValue, "Ignore" ) )
{
m_navProperty = NAV_IGNORE;
}
else
{
DevMsg( 1, "Unknown nav property %s\n", szValue );
}
return true;
}
return BaseClass::KeyValue( szKeyName, szValue );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CLogicNavigation::Activate()
{
BaseClass::Activate();
if ( HasSpawnFlags( SF_NAV_START_ON ) )
{
TurnOn();
RemoveSpawnFlags( SF_NAV_START_ON );
}
else if ( m_isOn )
{
gEntList.AddListenerEntity( this );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CLogicNavigation::UpdateOnRemove()
{
if ( m_isOn )
{
gEntList.RemoveListenerEntity( this );
}
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CLogicNavigation::OnEntitySpawned( CBaseEntity *pEntity )
{
if ( m_isOn && ( m_navProperty & NAV_IGNORE ) && pEntity->NameMatches( m_target ) )
{
pEntity->SetNavIgnore();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CLogicNavigation::TurnOn()
{
if ( m_isOn )
return;
m_isOn = true;
gEntList.AddListenerEntity( this );
UpdateProperty();
}
void CLogicNavigation::UpdateProperty()
{
CBaseEntity *pEntity = NULL;
while ( ( pEntity = gEntList.FindEntityByName( pEntity, STRING(m_target) ) ) != NULL )
{
if ( m_isOn )
{
if ( m_navProperty & NAV_IGNORE )
pEntity->SetNavIgnore();
}
else
{
if ( m_navProperty & NAV_IGNORE )
pEntity->ClearNavIgnore();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CLogicNavigation::TurnOff()
{
if ( !m_isOn )
return;
m_isOn = false;
gEntList.RemoveListenerEntity( this );
UpdateProperty();
}
|