]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/state.qh
Weapons: store switchweapon as direct weapon reference
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / state.qh
1 /**
2  * Purpose: common client state, usable on client and server
3  * Client: singleton representing the viewed player
4  * Server: instance per client
5  */
6 CLASS(ClientState, Object)
7         ATTRIB(ClientState, m_client, entity, NULL)
8         CONSTRUCTOR(ClientState, entity client)
9         {
10                 CONSTRUCT(ClientState);
11                 this.m_client = client;
12         }
13 ENDCLASS(ClientState)
14
15 .ClientState _cs;
16
17 #if NDEBUG
18 #define CS(this) (this._cs)
19 #else
20 ClientState CS(entity this) { assert(IS_CLIENT(this)); assert(this._cs); return this._cs; }
21 #endif
22
23 void ClientState_attach(entity this)
24 {
25         this._cs = NEW(ClientState, this);
26 }
27
28 void ClientState_detach(entity this)
29 {
30         remove(CS(this));
31         this._cs = NULL;
32 }
33
34
35
36 /**
37  * Purpose: common player state, usable on client and server
38  * Client: singleton representing the viewed player
39  * Server: instance per client, clients decoupled from players
40  */
41 CLASS(PlayerState, Object)
42         ATTRIB(PlayerState, m_client, entity, NULL)
43         CONSTRUCTOR(PlayerState, entity client)
44         {
45                 CONSTRUCT(PlayerState);
46                 this.m_client = client;
47         }
48         ATTRIB(PlayerState, m_switchingweapon, Weapon, Weapons_from(-1))
49         ATTRIB(PlayerState, m_switchweapon, Weapon, Weapons_from(-1))
50         ATTRIB(PlayerState, m_weapon, Weapon, Weapons_from(-1))
51         METHOD(PlayerState, ps_push, void(PlayerState this))
52         {
53                 STAT(SWITCHWEAPON, this.m_client) = this.m_switchweapon.m_id;
54         }
55 ENDCLASS(PlayerState)
56
57 .PlayerState _ps;
58 #if NDEBUG
59 #define PS(this) (this._ps)
60 #else
61 PlayerState PS(entity this) { assert(IS_CLIENT(this)); return this._ps; }
62 #endif
63
64 void PlayerState_attach(entity this)
65 {
66         LOG_INFO("Attached\n");
67         this._ps = NEW(PlayerState, this);
68 }
69
70 void PlayerState_detach(entity this)
71 {
72         if (!PS(this)) return;  // initial connect
73         remove(PS(this));
74         this._ps = NULL;
75 }