-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTerrorNavArea.cpp.txt
351 lines (296 loc) · 13.2 KB
/
TerrorNavArea.cpp.txt
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
BEGIN_ENT_SCRIPTDESC_ROOT( TerrorNavArea, "Navigation areas class" )
DEFINE_SCRIPT_INSTANCE_HELPER( &g_NavAreaScriptInstanceHelper )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetID, "GetID", "Get area ID." )
DEFINE_SCRIPTFUNC( GetAttributes, "Get area attribute bits" )
DEFINE_SCRIPTFUNC( SetAttributes, "Set area attribute bits" )
DEFINE_SCRIPTFUNC( HasAttributes, "Has area attribute bits" )
DEFINE_SCRIPTFUNC( RemoveAttributes, "Removes area attribute bits" )
DEFINE_SCRIPTFUNC( GetCenter, "Get center origin of area" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetCorner, "GetCorner", "Get corner origin of area" )
DEFINE_SCRIPTFUNC( GetRandomPoint, "Get random origin within extent of area" )
DEFINE_SCRIPTFUNC_NAMED( ScriptConnectToArea, "ConnectTo", "Connect this area to given area in given direction" )
DEFINE_SCRIPTFUNC_NAMED( ScriptDisconnectArea, "Disconnect", "Disconnect this area from given area" )
DEFINE_SCRIPTFUNC_NAMED( ScriptIsConnectedArea, "IsConnected", "Return true if given area is connected in given direction" )
DEFINE_SCRIPTFUNC_NAMED( ScriptConnectToLadder, "ConnectToLadder", "Connect this area to given ladder" )
DEFINE_SCRIPTFUNC_NAMED( ScriptDisconnectLadder, "DisconnectLadder", "Disconnect this area from given ladder" )
DEFINE_SCRIPTFUNC_NAMED( ScriptIsConnectedLadder, "IsConnectedLadder", "Return true if given area is connected to ladder in given direction" )
DEFINE_SCRIPTFUNC( IsDamaging, "Return true if continuous damage (ie: fire) is in this area" )
DEFINE_SCRIPTFUNC( MarkAsDamaging, "Mark this area is damaging for the next 'duration' seconds" )
DEFINE_SCRIPTFUNC( IsBlocked, "Return true if team is blocked in this area" )
DEFINE_SCRIPTFUNC_NAMED( ScriptMarkAsBlocked, "MarkAsBlocked", "Mark this area as blocked for team" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAdjacentCount, "GetAdjacentCount", "Get the number of adjacent areas in the given direction" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAdjacentAreas, "GetAdjacentAreas", "Fills a passed in table with all adjacent areas in the given direction" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAdjacentArea, "GetAdjacentArea", "Return the i'th adjacent area in the given direction" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRandomAdjacentArea, "GetRandomAdjacentArea", "Return a random adjacent area in the given direction" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetIncomingConnections, "GetIncomingConnections", "Fills a passed in table with areas connected TO this area by a ONE-WAY link (ie: we have no connection back to them)" )
DEFINE_SCRIPTFUNC_NAMED( ScriptAddIncomingConnection, "AddIncomingConnection", "Add areas that connect TO this area by a ONE-WAY link" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetPlaceName, "GetPlaceName", "Get place name" )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetPlaceName, "SetPlaceName", "Set place name" )
DEFINE_SCRIPTFUNC_NAMED( ScriptComputeDirection, "ComputeDirection", "Return direction from this area to the given point" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetLadders, "GetLadders", "Fills a passed in table of ladders in direction" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetPlayerCount, "GetPlayerCount", "Return number of players of given team currently within this area (team of zero means any/all)" )
DEFINE_SCRIPTFUNC_NAMED( ScriptIsOverlapping, "IsOverlapping", "Return true if 'area' overlaps our 2D extents" )
DEFINE_SCRIPTFUNC_NAMED( ScriptIsOverlappingOrigin, "IsOverlappingOrigin", "Return true if 'pos' is within 2D extents of area" )
DEFINE_SCRIPTFUNC( IsPotentiallyVisibleToTeam, "Return true if any portion of this area is visible to anyone on the given team" )
DEFINE_SCRIPTFUNC( IsCompletelyVisibleToTeam, "Return true if given area is completely visible from somewhere in this area by someone on the team" )
DEFINE_SCRIPTFUNC_NAMED( ScriptIsEdge, "IsEdge", "Return true if there are no bi-directional links on the given side" )
DEFINE_SCRIPTFUNC( HasAvoidanceObstacle, "Returns true if there's a large, immobile object obstructing this area" )
DEFINE_SCRIPTFUNC( MarkObstacleToAvoid, "Marks the obstructed status of the nav area" )
DEFINE_SCRIPTFUNC_NAMED( ScriptContains, "Contains", "Return true if other area is on or above this area, but no others" )
DEFINE_SCRIPTFUNC_NAMED( ScriptContainsOrigin, "ContainsOrigin", "Return true if given point is on or above this area, but no others" )
DEFINE_SCRIPTFUNC_NAMED( ScriptComputeGroundHeightChange, "ComputeGroundHeightChange", "Compute change in actual ground height from this area to given area" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetParent, "GetParent", "Returns the area just prior to this one in the search path" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetParentHow, "GetParentHow", "Returns how we get from parent to us" )
DEFINE_SCRIPTFUNC_NAMED( DrawFilled, "DebugDrawFilled", "Draw area as a filled rect of the given color" )
DEFINE_SCRIPTFUNC_NAMED( ScriptUnblockArea, "UnblockArea", "Unblocks this area" )
DEFINE_SCRIPTFUNC( IsRoughlySquare, "Return true if this area is approximately square" )
DEFINE_SCRIPTFUNC( IsFlat, "Return true if this area is approximately flat" )
DEFINE_SCRIPTFUNC( IsDegenerate, "Return true if this area is badly formed" )
DEFINE_SCRIPTFUNC_NAMED( ScriptIsVisible, "IsVisible", "Return true if area is visible from the given eyepoint" )
DEFINE_SCRIPTFUNC( GetSizeX, "" )
DEFINE_SCRIPTFUNC( GetSizeY, "" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetZ, "GetZ", "Return Z of area at (x,y) of 'pos'" )
DEFINE_SCRIPTFUNC( GetDistanceSquaredToPoint, "Return shortest distance between point and this area" )
DEFINE_SCRIPTFUNC( GetSpawnAttributes, "Get spawn attribute bits" ) //Get m_spawnAttributes
DEFINE_SCRIPTFUNC( HasSpawnAttributes, "Has spawn attribute bits" ) //Has m_spawnAttributes
DEFINE_SCRIPTFUNC( IsUnderwater, "Return true if area is underwater" )
DEFINE_SCRIPTFUNC_NAMED( ScriptIsCoplanar, "IsCoplanar", "Return true if this area and given area are approximately co-planar" )
DEFINE_SCRIPTFUNC_NAMED( ScriptRemoveOrthogonalConnections, "RemoveOrthogonalConnections", "Removes all connections in directions to left and right of specified direction" )
DEFINE_SCRIPTFUNC( GetAvoidanceObstacleHeight, "Returns the maximum height of the obstruction above the ground" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetElevator, "GetElevator", "Returns the elevator if in an elevator's path" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetElevatorAreas, "GetElevatorAreas", "Fills a passed in table with a collection of areas reachable via elevator from this area" )
DEFINE_SCRIPTFUNC( IsSpawningAllowed, "Returns true if spawning is allowed" )
DEFINE_SCRIPTFUNC( MarkAreaNotCleared, "Mark this area as not cleared" )
DEFINE_SCRIPTFUNC_NAMED( ScriptRemoveSpawnAttributes, "RemoveSpawnAttributes", "Remove area attribute bits" )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetSpawnAttributes, "SetSpawnAttributes", "Set area attribute bits" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetDoor, "GetDoor", "Returns the door above the area" )
DEFINE_SCRIPTFUNC_NAMED( ScriptIsCleared, "IsCleared", "Returns true if this area has been cleared" )
DEFINE_SCRIPTFUNC_NAMED( ScriptMarkAreaCleared, "MarkAreaCleared", "Mark this area as cleared" )
DEFINE_SCRIPTFUNC( GetTimeSinceCleared, "Returns the time since the area was cleared" )
DEFINE_SCRIPTFUNC( IsBottleneck, "Returns true if area is a bottleneck" )
DEFINE_SCRIPTFUNC( IsTerrorMarked, "Returns true if area is terror marked" )
DEFINE_SCRIPTFUNC( IsValidForWanderingPopulation, "Returns true if area is valid for wandering population" )
END_SCRIPTDESC();
---------------------------------------------
// Add the following to the constructor
//TerrorNavArea::TerrorNavArea( void )
//
m_hScriptInstance = NULL;
----------------------------------------------
// Add the following to the destructor
//TerrorNavArea::~TerrorNavArea()
//
if ( m_hScriptInstance )
{
g_pScriptVM->RemoveInstance( m_hScriptInstance );
m_hScriptInstance = NULL;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
HSCRIPT TerrorNavArea::GetScriptInstance()
{
if ( !m_hScriptInstance )
{
m_hScriptInstance = g_pScriptVM->RegisterInstance( GetScriptDesc(), this );
}
return m_hScriptInstance;
}
void TerrorNavArea::ScriptGetAdjacentAreas( int dir, HSCRIPT hTable )
{
if ( !hTable )
return;
const NavConnectVector *pConnections = GetAdjacentAreas( (NavDirType) dir );
FOR_EACH_VEC( (*pConnections), it )
{
NavConnect connect = (*pConnections)[ it ];
TerrorNavArea *area = connect.area;
if ( area )
{
g_pScriptVM->SetValue( hTable, CFmtStr( "area%i", it ), ToHScript( area ) );
}
}
}
HSCRIPT TerrorNavArea::ScriptGetAdjacentArea( int dir, int i )
{
return ToHScript( GetAdjacentArea( (NavDirType) dir, i ) );
}
HSCRIPT TerrorNavArea::ScriptGetRandomAdjacentArea( int dir )
{
return ToHScript( GetRandomAdjacentArea( (NavDirType) dir ) );
}
void TerrorNavArea::ScriptGetIncomingConnections( int dir, HSCRIPT hTable )
{
if ( !hTable )
return;
const NavConnectVector *pConnections = GetIncomingConnections( (NavDirType) dir );
FOR_EACH_VEC( (*pConnections), it )
{
NavConnect connect = (*pConnections)[ it ];
TerrorNavArea *area = connect.area;
if ( area )
{
g_pScriptVM->SetValue( hTable, CFmtStr( "area%i", it ), ToHScript( area ) );
}
}
}
void TerrorNavArea::ScriptAddIncomingConnection( HSCRIPT hSource, int incomingEdgeDir )
{
TerrorNavArea *pArea = ToNavArea(hSource);
if ( !pArea )
return;
AddIncomingConnection( pArea, (NavDirType) incomingEdgeDir );
}
void TerrorNavArea::ScriptConnectToArea( HSCRIPT hArea, int dir )
{
TerrorNavArea *pArea = ToNavArea(hArea);
if ( !pArea )
return;
if ( dir == -1 )
{
Vector center;
float halfWidth;
NavDirType autoDir = ComputeLargestPortal( pArea, ¢er, &halfWidth );
if ( autoDir != NUM_DIRECTIONS )
ConnectTo( pArea, autoDir );
}
else
ConnectTo( pArea, (NavDirType) dir );
}
void TerrorNavArea::ScriptDisconnectArea( HSCRIPT hArea )
{
TerrorNavArea *pArea = ToNavArea(hArea);
if ( !pArea )
return;
Disconnect( pArea );
}
bool TerrorNavArea::ScriptIsConnectedArea( HSCRIPT hArea, int dir )
{
TerrorNavArea *pArea = ToNavArea(hArea);
if ( !pArea )
return false;
return IsConnected( pArea, (NavDirType) dir );
}
void TerrorNavArea::ScriptConnectToLadder( HSCRIPT hLadder )
{
CNavLadder *pLadder = ToNavLadder(hLadder);
if ( !pLadder )
return;
ConnectTo( pLadder );
}
void TerrorNavArea::ScriptDisconnectLadder( HSCRIPT hLadder )
{
CNavLadder *pLadder = ToNavLadder(hLadder);
if ( !pLadder )
return;
Disconnect( pLadder );
}
bool TerrorNavArea::ScriptIsConnectedLadder( HSCRIPT hLadder, int dir )
{
CNavLadder *pLadder = ToNavLadder(hLadder);
if ( !pLadder )
return false;
return IsConnected( pLadder, (CNavLadder::LadderDirectionType) dir );
}
void TerrorNavArea::ScriptMarkAsBlocked( int teamID )
{
MarkAsBlocked( teamID, NULL );
}
const char *TerrorNavArea::ScriptGetPlaceName()
{
return TheNavMesh->PlaceToName( GetPlace() );
}
void TerrorNavArea::ScriptSetPlaceName( const char *pszName )
{
Place place = TheNavMesh->PartialNameToPlace( pszName );
if ( place == UNDEFINED_PLACE )
return;
SetPlace( place );
}
void TerrorNavArea::ScriptGetLadders( int dir, HSCRIPT hTable )
{
if ( !hTable )
return;
const NavLadderConnectVector *ladders = GetLadders( (CNavLadder::LadderDirectionType) dir );
FOR_EACH_VEC( (*ladders), it )
{
CNavLadder *ladder = (*ladders)[ it ].ladder;
if ( ladder )
g_pScriptVM->SetValue( hTable, CFmtStr( "ladder%i", it ), ToHScript( ladder ) );
}
}
bool TerrorNavArea::ScriptIsOverlapping( HSCRIPT hArea ) const
{
TerrorNavArea *pArea = ToNavArea(hArea);
if ( !pArea )
return false;
return IsOverlapping( pArea );
}
bool TerrorNavArea::ScriptContains( HSCRIPT hArea ) const
{
TerrorNavArea *pArea = ToNavArea(hArea);
if ( !pArea )
return false;
return Contains( pArea );
}
float TerrorNavArea::ScriptComputeGroundHeightChange( HSCRIPT hArea )
{
TerrorNavArea *pArea = ToNavArea(hArea);
if ( !pArea )
return -1.0f;
return ComputeGroundHeightChange( pArea );
}
HSCRIPT TerrorNavArea::ScriptGetParent()
{
return ToHScript( GetParent() );
}
int TerrorNavArea::ScriptComputeDirection( const Vector &point ) const
{
Vector pos = point;
return ComputeDirection( &pos );
}
void TerrorNavArea::ScriptUnblockArea( void )
{
UnblockArea();
}
bool TerrorNavArea::ScriptIsCoplanar( HSCRIPT hArea ) const
{
TerrorNavArea *pArea = ToNavArea(hArea);
if ( !pArea )
return false;
return IsCoplanar( pArea );
}
void TerrorNavArea::ScriptGetElevatorAreas( HSCRIPT hTable )
{
if ( !hTable )
return;
const NavConnectVector &pElevatorAreas = GetElevatorAreas();
FOR_EACH_VEC( pElevatorAreas, it )
{
TerrorNavArea *area = pElevatorAreas[ it ].area;
if ( area )
{
g_pScriptVM->SetValue( hTable, CFmtStr( "area%i", it ), ToHScript( area ) );
}
}
}
void TerrorNavArea::ScriptRemoveOrthogonalConnections( int dir )
{
RemoveOrthogonalConnections( (NavDirType) dir );
}
bool ScriptIsCleared( HSCRIPT hPlayer )
{
CBaseEntity *pBaseEntity = ToEnt(hPlayer);
CTerrorPlayer *pPlayer = NULL;
if ( pBaseEntity )
pPlayer = dynamic_cast<CTerrorPlayer*>(pBaseEntity);
return IsCleared( pPlayer );
}
void ScriptMarkAreaCleared( HSCRIPT hPlayer )
{
CBaseEntity *pBaseEntity = ToEnt(hPlayer);
CTerrorPlayer *pPlayer = NULL;
if ( pBaseEntity )
pPlayer = dynamic_cast<CTerrorPlayer*>(pBaseEntity);
MarkAreaCleared( pPlayer );
}