summaryrefslogtreecommitdiff
path: root/game/server/tf2/order_resourcepump.cpp
blob: bd247062cc8ab028b7ff7c21b10b6d6c6e7c6d02 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#include "cbase.h"
#include "order_resourcepump.h"
#include "tf_team.h"
#include "tf_obj_resourcepump.h"
#include "tf_func_resource.h"
#include "order_helpers.h"


IMPLEMENT_SERVERCLASS_ST( COrderResourcePump, DT_OrderResourcePump )
END_SEND_TABLE()


bool COrderResourcePump::CreateOrder( CPlayerClass *pClass )
{
	COrderResourcePump *pOrder = new COrderResourcePump;

	if ( OrderCreator_ResourceZoneObject( pClass->GetPlayer(), OBJ_RESOURCEPUMP, pOrder ) )
	{
		return true;
	}
	else
	{
		UTIL_RemoveImmediate( pOrder );
		return false;
	}
}


bool COrderResourcePump::Update()
{
	// Can they still build resource pumps?
	if ( !m_hOwningPlayer.Get() || m_hOwningPlayer->CanBuild( OBJ_RESOURCEPUMP ) != CB_CAN_BUILD )
		return true;

	// Lost our resource zone?
	if ( !GetTargetEntity() )
		return true;
	// Is our target zone now empty?
	if ( ((CResourceZone*)GetTargetEntity())->IsEmpty() )
		return true;

	// Have they built a pump on this zone?
	for( int i=0; i < m_hOwningPlayer->GetObjectCount(); i++ )
	{
		CBaseObject *pObj = m_hOwningPlayer->GetObject(i);

		if( pObj && pObj->GetType() == OBJ_RESOURCEPUMP )
		{
			CObjectResourcePump *pPump = (CObjectResourcePump*)pObj;
			CResourceZone *pZone = pPump->GetResourceZone();
			if( pZone && pZone->entindex() == m_iTargetEntIndex && !pZone->IsEmpty() )
				return true;
		}
	}

	return BaseClass::Update();
}