summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_obj_mapdefined.cpp
blob: 56b1efa14445b1da108b8379b8945daff4700bfb (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
131
132
133
134
135
136
137
138
139
140
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_player.h"
#include "tf_team.h"
#include "tf_gamerules.h"
#include "tf_obj.h"
#include "tf_obj_mapdefined.h"
#include "ndebugoverlay.h"

extern ConVar obj_damage_factor;

// Map defined object spawnflags
#define SF_MAPDEFOBJ_SUPPRESS_MINIMAP		0x0001
#define SF_MAPDEFOBJ_SUPPRESS_ATTACKNOTIFY	0x0002
#define SF_MAPDEFOBJ_DOESNT_NEED_POWER		0x0004

BEGIN_DATADESC( CObjectMapDefined )
	// keys 
	DEFINE_KEYFIELD_NOT_SAVED( m_iszCustomName , FIELD_STRING, "CustomName" ),
END_DATADESC()

IMPLEMENT_SERVERCLASS_ST(CObjectMapDefined, DT_ObjectMapDefined)
	SendPropString( SENDINFO( m_szCustomName ) ),
END_SEND_TABLE();

LINK_ENTITY_TO_CLASS(obj_mapdefined, CObjectMapDefined);
LINK_ENTITY_TO_CLASS(func_obj_mapdefined, CObjectMapDefined);

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CObjectMapDefined::CObjectMapDefined()
{
	UseClientSideAnimation();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectMapDefined::Spawn()
{
	// Get the model from the map
	char *szModel = (char *)STRING( GetModelName() );
	if (!szModel || !*szModel)
	{
		Warning( "obj_mapdefined at %.0f %.0f %0.f missing modelname\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z );
		UTIL_Remove( this );
		return;
	}

	memset( m_szCustomName.GetForModify(), 0, sizeof(m_szCustomName) );
	if ( m_iszCustomName != NULL_STRING )
	{
		Q_strncpy( m_szCustomName.GetForModify(), STRING(m_iszCustomName), sizeof(m_szCustomName) );
	}

	Precache();

	// Get the bounding box from the model
	if ( szModel[0] != '*' )
	{
		SetModel( szModel );
		Vector vecMins, vecMaxs;
		const model_t *pModel = GetModel();
		modelinfo->GetModelBounds( pModel, vecMins, vecMaxs );
		UTIL_SetSize(this, vecMins, vecMaxs );
	}
	else
	{
		// Don't call our internal setmodel to avoid the error
		UTIL_SetModel( this, szModel );

		// No control panels / power on map geometry objects
		m_fObjectFlags |= OF_DOESNT_HAVE_A_MODEL;
		m_fObjectFlags |= OF_DOESNT_NEED_POWER;
	}

	SetSolid( SOLID_VPHYSICS );
	SetType( OBJ_MAPDEFINED );

	// Setup object flags
	if ( HasSpawnFlags( SF_MAPDEFOBJ_SUPPRESS_MINIMAP ) )
	{
		m_fObjectFlags |= OF_SUPPRESS_APPEAR_ON_MINIMAP;
	}
	if ( HasSpawnFlags( SF_MAPDEFOBJ_SUPPRESS_ATTACKNOTIFY ) )
	{
		m_fObjectFlags |= OF_SUPPRESS_NOTIFY_UNDER_ATTACK;
	}
	if ( HasSpawnFlags( SF_MAPDEFOBJ_DOESNT_NEED_POWER ) )
	{
		m_fObjectFlags |= OF_DOESNT_NEED_POWER;
	}

	// If I don't have health, make me invulnerable
	if ( !m_iHealth )
	{
		m_bInvulnerable = true;
	}

	BaseClass::Spawn();

	// Override base object settings
	SetCollisionGroup( COLLISION_GROUP_NONE );

	FinishedBuilding();
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectMapDefined::Precache()
{
	PrecacheModel( STRING( GetModelName() ) );
	BaseClass::Precache();
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
int CObjectMapDefined::OnTakeDamage( const CTakeDamageInfo &info )
{
	CTakeDamageInfo childInfo = info;

	// Hack around the damage factor applied to objects
	if ( obj_damage_factor.GetFloat() )
	{
		float flDamage = info.GetDamage() * (1 / obj_damage_factor.GetFloat());
		childInfo.SetDamage( flDamage );
	}

	return BaseClass::OnTakeDamage( childInfo );
}