summaryrefslogtreecommitdiffstats
path: root/src/Entities/Pickup.h
blob: e8184e8af9c6a64568a963ab7a63108441388033 (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

#pragma once

#include "Entity.h"
#include "../Item.h"





class cPawn;





// tolua_begin
class cPickup :
	public cEntity
{
	// tolua_end

	using Super = cEntity;

public:  // tolua_export

	CLASS_PROTODEF(cPickup)

	cPickup(Vector3d a_Position, cItem && a_Item, Vector3d a_Speed, cTickTime a_CollectionDelay, cTickTime a_Lifetime, bool a_CanCombine);

	cItem &       GetItem(void)       {return m_Item; }  // tolua_export
	const cItem & GetItem(void) const {return m_Item; }

	bool CollectedBy(cEntity & a_Dest);  // tolua_export

	static bool TryCombineWithQueuedEntity(cEntity & a_Entity, const cBoundingBox & a_CombineBounds, cItem & a_Item, const char a_MaxStackSize);

	/** Returns whether this pickup is allowed to combine with other similar pickups */
	bool CanCombine(void) const { return m_IsCombinable; }  // tolua_export

	/** Sets whether this pickup is allowed to combine with other similar pickups */
	void SetCanCombine(bool a_CanCombine) { m_IsCombinable = a_CanCombine; }  // tolua_export

	/** Returns the number of ticks that this entity has existed */
	int GetAge(void) const { LOGWARNING("GetAge is deprecated, use GetTicksAlive");  return m_TicksAlive; }     // tolua_export

	/** Set the number of ticks that this entity has existed */
	void SetAge(int a_Age) { LOGWARNING("SetAge is deprecated, use SetLifetime"); m_TicksAlive = a_Age; }  // tolua_export

	/** Returns the number of ticks that this pickup should live for */
	int GetLifetime(void) const { return std::chrono::duration_cast<cTickTime>(m_RemainingLifetime).count(); }  // tolua_export

	/** Set the number of ticks that this pickup should live for */
	void SetLifetime(int a_Lifetime) { m_RemainingLifetime = cTickTime(a_Lifetime); }  // tolua_export

	/** Returns true if the pickup has already been collected */
	bool IsCollected(void) const { return m_IsCollected; }  // tolua_export

	/** Returns true if created by player (i.e. vomiting), used for determining picking-up delay time */
	bool IsPlayerCreated(void) const { LOGWARNING("IsPlayerCreated is deprecated");  return false; }  // tolua_export

private:

	void OnCollectedBy(cPawn & a_Collector, char a_CollectionCount);

	void TryCombineWithPickupsInWorld();

	// cEntity overrides:
	virtual bool DoesPreventBlockPlacement(void) const override { return false; }
	virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
	virtual void OnAddToWorld(cWorld & a_World) override;
	virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
	virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;

	cItem m_Item;

	/** How much time left until the pickup can be picked up.
	Two seconds if player created the pickup (vomiting), half a second if anything else, but plugin-customisable. */
	std::chrono::milliseconds m_RemainingCollectionDelay;

	/** You have thirty seconds to live. - Medic TF2 */
	std::chrono::milliseconds m_RemainingLifetime;

	bool m_IsCollected;
	bool m_IsCombinable;
};  // tolua_export