summaryrefslogtreecommitdiffstats
path: root/src/Mobs/MobPointer.h
blob: 77f4cd6cdbac5ffda0252dbd5af580e96151a3ff (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
#pragma once

/** This class allows mobs to hold pointers to other mobs/players in a safe manner.
When calling GetPointer(), it first checks if the Monster/Player being pointed to is still valid.
If not, it returns a nullptr. The returned raw pointer must be used locally and then discarded.
it MUST NOT be preserved across ticks.
*/

class cPawn;
class cWorld;
class cMobPointer
{
public:
	cMobPointer(cPawn * a_Pointer);                            // Constructor
	cMobPointer(const cMobPointer & a_MobPointer);             // Copy constructor
	cMobPointer(cMobPointer && a_MobPointer);                  // Move constructor
	cMobPointer& operator=(const cMobPointer& a_MobPointer);   // Copy assignment operator
	cMobPointer& operator=(cMobPointer&& a_MobPointer);        // Move assignment operator

	void operator=(cPawn * a_Pointer);   // set Pointer

	/** Returns the raw pointer. The returned raw pointer must
	be used locally and then discarded. it MUST NOT be preserved across ticks.
	Returns null if raw pointer is null. Returns null if mob is destroyed or moved worlds.
	Must be called at least once per tick, even if the raw pointer is not going to be used that tick. */
	cPawn * GetPointer(cWorld * a_CurrentWorld);


private:
	cPawn * m_Pointer;
} ;