#ifndef UTIL_POST_H
#define UTIL_POST_H
-#define spawn() new(entity)
+[[alias("self")]] entity __self;
+
+// Can't wrap with do-while as block may contain continue or break
+#define WITH(type, name, value, block) { \
+ type __with_save = (name); \
+ name = (value); \
+ LAMBDA(block) \
+ name = __with_save; \
+} do { } while (0)
+
+// Transition from global 'self' to local 'this'
+
+// Step 1: auto oldself
+#if 1
+#define SELFPARAM() noref entity this = __self
+#define setself(s) (__self = s)
+#define self __self
+#endif
+
+// Step 2: check SELFPARAM() is present for functions that use self
+#if 0
+#define SELFPARAM() [[alias("__self")]] noref entity this = __self
+#define setself(s) (__self = s)
+#define self this
+#endif
+
+// Step 3: const self
+#if 0
+#define SELFPARAM() noref const entity this = __self
+entity setself(entity e) { return self = e; }
+entity getself() { return self; }
+#define self getself()
+#endif
-#include "oo.qh"
+// Step 4: enable when possible
+// TODO: Remove SELFPARAM in favor of a parameter
+#if 0
+#define SELFPARAM() noref const entity this = __self
+#define self this
+#endif
+
+#define spawn() new(entity)
#endif