summaryrefslogtreecommitdiff
path: root/game/shared/tf2/tf_tacticalmap.cpp
blob: 19e2d424104705ef21b448c31ea92c4e97c82fb5 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Shared stuff for the Tactical map
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"

// Unfortunate hack.
// Needed to cycle through the player & radar scanner entities in both the client and game dlls
#ifdef CLIENT_DLL

// Client DLL functions
#include "c_team.h"
#include "c_tfteam.h"
#include "c_basetfplayer.h"
#include "C_BaseObject.h"

static inline bool IsPlayerCamoed( int iEntIndex )
{
	C_BaseTFPlayer* pPlayer = (C_BaseTFPlayer*)ClientEntityList().GetClientEntity(iEntIndex);
	if (!pPlayer)
		return false;

	return pPlayer->IsCamouflaged();
}

static inline bool IsPlayerVisible( int iEntIndex )
{
	C_BaseTFPlayer* pPlayer = (C_BaseTFPlayer*)ClientEntityList().GetClientEntity(iEntIndex);
	if (!pPlayer)
		return false;

	return pPlayer->GetClass() != TFCLASS_UNDECIDED;
}

static inline bool IsEntityAnObject( int iEntIndex )
{
	IClientNetworkable *pEnt = ClientEntityList().GetClientEntity(iEntIndex);
	return dynamic_cast<C_BaseObject*>(pEnt) != 0;
}

#else

// Game DLL functions
#include "team.h"
#include "tf_team.h"
#include "tf_player.h"

static inline bool IsPlayerCamoed( int iEntIndex )
{
	CBaseTFPlayer* pPlayer = (CBaseTFPlayer *)CBaseEntity::Instance( engine->PEntityOfEntIndex( iEntIndex ) );
	if (!pPlayer)
		return false;
	return pPlayer->IsCamouflaged();
}

static inline bool IsPlayerVisible( int iEntIndex )
{
	CBaseTFPlayer* pPlayer = (CBaseTFPlayer *)CBaseEntity::Instance( engine->PEntityOfEntIndex( iEntIndex ) );
	if (!pPlayer)
		return false;
	return pPlayer->PlayerClass() != TFCLASS_UNDECIDED;
}

static inline bool IsEntityAnObject( int iEntIndex )
{
	CBaseEntity* pEnt = CBaseEntity::Instance( engine->PEntityOfEntIndex( iEntIndex ) );
	CBaseObject *pObject = dynamic_cast<CBaseObject*>(pEnt);
	if (!pObject)
		return false;

	// Don't bother with boring ones... they're boring!
	return ((pObject->GetObjectFlags( ) & OF_SUPPRESS_VISIBLE_TO_TACTICAL) == 0);
}

#endif

// Visibility defines
#define PLAYER_VISIBILITY_DISTANCE			2000		// Distance around a player that's exposed on the tactical map


//-----------------------------------------------------------------------------
// Purpose: Return true if the entity is visible on this player's tactical map
//-----------------------------------------------------------------------------
bool IsEntityVisibleToTactical( int iLocalTeamNumber, int iLocalTeamPlayers, 
	int iLocalTeamObjects, int entIndex, const char *pEntName, int iEntTeamNumber, const Vector &entOrigin )
{
	// Resource zones are always visible
	if ( !strcmp( pEntName, "trigger_resourcezone") )
		return true;

	// Tunnels are always visible
	if ( !strcmp( pEntName, "obj_tunnel") || !strcmp( pEntName, "obj_tunnel_prop") )
		return true;

	// Fixed shields are never visible
	if ( !strcmp( pEntName, "shield") )
		return false;

	// NOTE: If you're looking for various object types, fix the ugly hack
	// in mapdata.cpp!!
	if ( iLocalTeamNumber == iEntTeamNumber )
	{
		// Objects are always visible to their team
		if (IsEntityAnObject( entIndex ))
			return true;

		// Players are always visible to their team
		if (!Q_strncmp( pEntName, "player", 7) )
			return true;

		// Resource collectors are always visible to their team
		if ( !strcmp( pEntName, "npc_rescollector_aerial") )
			return true;
	}

	return false;
}