aboutsummaryrefslogtreecommitdiff
path: root/sp/src/game/server/nav_entities.h
blob: 4d7576b23874afeeba76c59f115c5ddcad3de404 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//
// nav_entities.h
// Navigation entities
// Author: Michael S. Booth ([email protected]), January 2003

#ifndef NAV_ENTITIES_H
#define NAV_ENTITIES_H

//-----------------------------------------------------------------------------------------------------
/**
  * An entity that modifies pathfinding cost to all areas it overlaps, to allow map designers
  * to tell bots to avoid/prefer certain regions.
  */
class CFuncNavCost : public CBaseEntity
{
public:
	DECLARE_DATADESC();
	DECLARE_CLASS( CFuncNavCost, CBaseEntity );

	virtual void Spawn( void );
	virtual void UpdateOnRemove( void );

	void InputEnable( inputdata_t &inputdata );
	void InputDisable( inputdata_t &inputdata );

	bool IsEnabled( void ) const { return !m_isDisabled; }

	void CostThink( void );

	bool IsApplicableTo( CBaseCombatCharacter *who ) const;			// Return true if this cost applies to the given actor

	virtual float GetCostMultiplier( CBaseCombatCharacter *who ) const	{ return 1.0f; }

protected:
	int m_team;
	bool m_isDisabled;
	string_t m_iszTags;

	static CUtlVector< CHandle< CFuncNavCost > > gm_masterCostVector;
	static CountdownTimer gm_dirtyTimer;
	void UpdateAllNavCostDecoration( void );

	CUtlVector< CFmtStr > m_tags;
	bool HasTag( const char *groupname ) const;
};


//-----------------------------------------------------------------------------------------------------
class CFuncNavAvoid : public CFuncNavCost
{
public:
	DECLARE_CLASS( CFuncNavAvoid, CFuncNavCost );

	virtual float GetCostMultiplier( CBaseCombatCharacter *who ) const;		// return pathfind cost multiplier for the given actor
};


//-----------------------------------------------------------------------------------------------------
class CFuncNavPrefer : public CFuncNavCost
{
public:
	DECLARE_CLASS( CFuncNavPrefer, CFuncNavCost );

	virtual float GetCostMultiplier( CBaseCombatCharacter *who ) const;		// return pathfind cost multiplier for the given actor
};


//-----------------------------------------------------------------------------------------------------
/**
  * An entity that can block/unblock nav areas.  This is meant for semi-transient areas that block
  * pathfinding but can be ignored for longer-term queries like computing L4D flow distances and
  * escape routes.
  */
class CFuncNavBlocker : public CBaseEntity
{
	DECLARE_DATADESC();
	DECLARE_CLASS( CFuncNavBlocker, CBaseEntity );

public:
	void Spawn();
	virtual void UpdateOnRemove( void );

	void InputBlockNav( inputdata_t &inputdata );
	void InputUnblockNav( inputdata_t &inputdata );

	inline bool IsBlockingNav( int teamNumber ) const
	{
		if ( teamNumber == TEAM_ANY )
		{
			bool isBlocked = false;
			for ( int i=0; i<MAX_NAV_TEAMS; ++i )
			{
				isBlocked |= m_isBlockingNav[ i ];
			}

			return isBlocked;
		}

		teamNumber = teamNumber % MAX_NAV_TEAMS;
		return m_isBlockingNav[ teamNumber ];
	}

	int DrawDebugTextOverlays( void );

	bool operator()( CNavArea *area );	// functor that blocks areas in our extent

	static bool CalculateBlocked( bool *pResultByTeam, const Vector &vecMins, const Vector &vecMaxs );

private:

	void UpdateBlocked();

	static CUtlLinkedList<CFuncNavBlocker *> gm_NavBlockers;

	void BlockNav( void );
	void UnblockNav( void );
	bool m_isBlockingNav[MAX_NAV_TEAMS];
	int m_blockedTeamNumber;
	bool m_bDisabled;
	Vector m_CachedMins, m_CachedMaxs;

};

#endif // NAV_ENTITIES_H