summaryrefslogtreecommitdiffstats
path: root/source/Entity.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-12-21 13:21:20 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-12-21 13:21:20 +0100
commit033af999ba419afadfa1830d288b021e7d9bc1f5 (patch)
treefff5cd27b629a03d5161d872ca9e41ec2de1a80b /source/Entity.h
parentAdded TakeDamage logging to the Debuggers plugin. (diff)
downloadcuberite-033af999ba419afadfa1830d288b021e7d9bc1f5.tar
cuberite-033af999ba419afadfa1830d288b021e7d9bc1f5.tar.gz
cuberite-033af999ba419afadfa1830d288b021e7d9bc1f5.tar.bz2
cuberite-033af999ba419afadfa1830d288b021e7d9bc1f5.tar.lz
cuberite-033af999ba419afadfa1830d288b021e7d9bc1f5.tar.xz
cuberite-033af999ba419afadfa1830d288b021e7d9bc1f5.tar.zst
cuberite-033af999ba419afadfa1830d288b021e7d9bc1f5.zip
Diffstat (limited to '')
-rw-r--r--source/Entity.h56
1 files changed, 39 insertions, 17 deletions
diff --git a/source/Entity.h b/source/Entity.h
index 613032938..7cb168581 100644
--- a/source/Entity.h
+++ b/source/Entity.h
@@ -11,30 +11,45 @@
-#define CLASS_PROT_ISA() virtual bool IsA( const char* a_EntityType );
-#define CLASS_PROT_GETCLASS() virtual const char* GetClass();
+#define CLASS_PROT_ISA() virtual bool IsA(const char * a_EntityType) const override;
+#define CLASS_PROT_GETCLASS() virtual const char * GetClass (void) const override;
+#define CLASS_PROT_GETPARENT() virtual const char * GetParentClass(void) const override;
-/* Can't use this (yet) because of tolua */
#define CLASS_PROTOTYPE() \
CLASS_PROT_ISA(); \
- CLASS_PROT_GETCLASS();
+ CLASS_PROT_GETCLASS(); \
+ CLASS_PROT_GETPARENT();
-#define CLASS_DEF_ISA( classname, superclass ) \
- bool classname::IsA( const char* a_EntityType ) \
+#define CLASS_DEF_ISA(classname) \
+ bool classname::IsA(const char * a_ClassName) const \
{ \
- if( strcmp( a_EntityType, #classname ) == 0 ) return true; \
- return superclass::IsA( a_EntityType ); \
+ return ((strcmp(a_ClassName, #classname) == 0) || super::IsA(a_ClassName)); \
}
-#define CLASS_DEF_GETCLASS( classname ) \
- const char* classname::GetClass() \
+#define CLASS_DEF_GETCLASS(classname) \
+ const char * classname::GetClass(void) const \
{ \
- return #classname; \
+ return #classname; \
}
-#define CLASS_DEFINITION( classname, superclass ) \
- CLASS_DEF_ISA( classname, superclass ) \
- CLASS_DEF_GETCLASS( classname )
+#define CLASS_DEFINITION(classname) \
+ CLASS_DEF_ISA(classname) \
+ CLASS_DEF_GETCLASS(classname)
+
+// Place this macro in the header of each cEntity descendant class and you're done :)
+#define CLASS_PROTODEF(classname) \
+ virtual bool IsA(const char * a_ClassName) const override\
+ { \
+ return ((strcmp(a_ClassName, #classname) == 0) || super::IsA(a_ClassName)); \
+ } \
+ virtual const char * GetClass(void) const override \
+ { \
+ return #classname; \
+ } \
+ virtual const char * GetParentClass(void) const override \
+ { \
+ return super::GetClass(); \
+ }
@@ -74,9 +89,16 @@ public:
eEntityType_Pickup
};
- virtual unsigned int GetEntityType() { return m_EntityType; }
- virtual bool IsA( const char* a_EntityType );
- virtual const char* GetClass();
+ virtual unsigned int GetEntityType(void) const { return m_EntityType; }
+
+ /// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
+ virtual bool IsA(const char * a_ClassName) const;
+
+ /// Returns the topmost class name for the object
+ virtual const char * GetClass(void) const;
+
+ /// Returns the topmost class's parent class name for the object. cEntity returns an empty string (no parent).
+ virtual const char * GetParentClass(void) const;
cWorld * GetWorld(void) const { return m_World; }