]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_client.qh
Transmute player entities
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_client.qh
index 55ef7114c35e8ccb2d84a60fee179159380f7efb..70df314ea034655c7e71a9afca71e7b4fe0b00ff 100644 (file)
@@ -1,5 +1,7 @@
 #pragma once
 
+void ClientState_attach(entity this);
+
 CLASS(Client, Object)
     /** Client name */
     ATTRIB(Client, netname, string, this.netname)
@@ -23,11 +25,67 @@ CLASS(Client, Object)
     ATTRIB(Client, crypto_encryptmethod, string, this.crypto_encryptmethod)
     /** the string "HMAC-SHA256" if signing, and string_null if plaintext */
     ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod)
+
+    // custom
+
+    ATTRIB(Client, flags, int, 0)
+    ATTRIB(Client, playerid, int, 0)
+
+    METHOD(Client, m_unwind, bool(Client this));
+
     INIT(Client) {
+        if (this.m_unwind(this)) return this;
+        this.classname = "player_joining";
         this.flags = FL_CLIENT;
+        static int playerid_last;
+        this.playerid = ++playerid_last;
+        ClientState_attach(this);
     }
 ENDCLASS(Client)
 
+CLASS(Observer, Client)
+    INIT(Observer) {
+        this.classname = STR_OBSERVER;
+    }
+    DESTRUCTOR(Observer) { }
+ENDCLASS(Observer)
+
+CLASS(Spectator, Client)
+    INIT(Spectator) {
+        this.classname = STR_SPECTATOR;
+    }
+    DESTRUCTOR(Spectator) { }
+ENDCLASS(Spectator)
+
+CLASS(Player, Client)
+    INIT(Player) {
+        this.classname = STR_PLAYER;
+    }
+    DESTRUCTOR(Player) { }
+ENDCLASS(Player)
+
+METHOD(Client, m_unwind, bool(Client this))
+{
+    TC(Client, this);
+    #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END
+    switch (this.classname) {
+        case "Observer":
+            UNWIND(Spectator);
+            UNWIND(Player);
+            return true;
+        case "Spectator":
+            UNWIND(Observer);
+            UNWIND(Player);
+            return true;
+        case "Player":
+            UNWIND(Observer);
+            UNWIND(Spectator);
+            return true;
+    }
+    #undef UNWIND
+    return false;
+}
+
 float c1, c2, c3, c4;
 
 void play_countdown(float finished, Sound samp);