]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/oo.qh
Put pure entities in the very center of the map (corner has issues on some of the...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / oo.qh
index d0c770ae3160a7f6f32612182929a6452493398e..fd6ca20365000cc0fa7553e57b560823452eec24 100644 (file)
@@ -6,6 +6,7 @@
 
 #ifdef MENUQC
        #define NULL (0, null_entity)
+       #define world NULL
 #else
        #define NULL (0, world)
 #endif
@@ -49,10 +50,10 @@ entity __spawn(string _classname, string _sourceLoc, bool pure)
        if (pure) {
                make_pure(this);
                #ifdef CSQC
-               setorigin(this, '0 0 10000');
+               setorigin(this, (world.mins + world.maxs) * 0.5);
                #endif
                #ifdef SVQC
-        setorigin(this, '0 0 -10000');
+        setorigin(this, (world.mins + world.maxs) * 0.5);
         #endif
        }
        return this;
@@ -112,8 +113,8 @@ void clearentity(entity e)
        #define NEW(cname, ...) \
                OVERLOAD_(spawn##cname, new_pure(cname) P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
 
-    #define TRANSMUTE(cname, this, ...) \
-        OVERLOAD_(spawn##cname, (this.transmute = true, this.classname = #cname, this) P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
+    #define _TRANSMUTE(cname, this, ...) \
+        OVERLOAD_(spawn##cname, this P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
 
        #define CONSTRUCT(cname, ...) \
                OVERLOAD_(spawn##cname, this P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
@@ -121,13 +122,22 @@ void clearentity(entity e)
        #define NEW(cname, ...) \
                OVERLOAD(spawn##cname, new_pure(cname),##__VA_ARGS__)
 
-    #define TRANSMUTE(cname, this, ...) \
-        OVERLOAD(spawn##cname, (this.transmute = true, this.classname = #cname, this),##__VA_ARGS__)
+    #define _TRANSMUTE(cname, this, ...) \
+        OVERLOAD(spawn##cname, this,##__VA_ARGS__)
 
        #define CONSTRUCT(cname, ...) \
                OVERLOAD(spawn##cname, this,##__VA_ARGS__)
 #endif
 
+#define TRANSMUTE(cname, this, ...) MACRO_BEGIN \
+    entity _e = (this); \
+    if (_e.vtblbase != cname##_vtbl) { \
+        _e.transmute = true; \
+        _e.classname = #cname; \
+        _TRANSMUTE(cname, _e, __VA_ARGS__); \
+    } \
+    MACRO_END
+
 #define CONSTRUCTOR(cname, ...) \
        cname OVERLOAD(spawn##cname, cname this, __VA_ARGS__) \
        { \
@@ -165,6 +175,7 @@ STATIC_INIT(RegisterClasses)
        entityclass(cname, base);               \
        class(cname).bool instanceOf##cname;    \
     bool is_##cname(entity e) { return e.instanceOf##cname; } \
+    void isnt_##cname(entity e) { eprint(e); } \
        VTBL(cname, base)                       \
        _INIT_STATIC(cname)                     \
        {                                       \
@@ -210,6 +221,7 @@ STATIC_INIT(RegisterClasses)
     METHOD(cname, dtor, void(cname this)) \
     { \
         METHOD_REFERENCE(cname, dtorimpl)(this); \
+        this.instanceOf##cname = false; \
         entity super = SUPER(cname); \
         if (super != cname##_vtbl) super.dtor(this); \
     } \