4 * Purpose: common player state, usable on client and server
5 * Client: singleton representing the viewed player
6 * Server: instance per client, clients decoupled from players
8 CLASS(PlayerState, Object)
9 ATTRIB(PlayerState, m_client, entity, NULL)
10 CONSTRUCTOR(PlayerState, entity client)
12 CONSTRUCT(PlayerState);
13 this.m_client = client;
15 ATTRIB(PlayerState, m_switchingweapon, Weapon, Weapons_from(-1))
16 ATTRIB(PlayerState, m_switchweapon, Weapon, Weapons_from(-1))
17 ATTRIB(PlayerState, m_weapon, Weapon, Weapons_from(-1))
18 METHOD(PlayerState, ps_push, void(PlayerState this, entity cl))
20 STAT(ACTIVEWEAPON, cl) = this.m_weapon.m_id;
21 STAT(SWITCHINGWEAPON, cl) = this.m_switchingweapon.m_id;
22 STAT(SWITCHWEAPON, cl) = this.m_switchweapon.m_id;
28 #define PS(this) (this._ps)
30 PlayerState PS(entity this) { assert(IS_CLIENT(this)); return this._ps; }
33 void Inventory_new(entity this);
34 void Inventory_delete(entity this);
36 // TODO: renew on death
38 void PlayerState_attach(entity this)
40 this._ps = NEW(PlayerState, this);
45 void PlayerState_detach(entity this)
47 if (!PS(this)) return; // initial connect
48 FOREACH_CLIENT(PS(it) == PS(this), { PS(it) = NULL; });
52 Inventory_delete(self);
56 * Purpose: common client state, usable on client and server
57 * Client: singleton representing the viewed player
58 * Server: instance per client
60 CLASS(ClientState, Object)
61 ATTRIB(ClientState, m_client, entity, NULL)
62 CONSTRUCTOR(ClientState, entity client)
64 CONSTRUCT(ClientState);
65 this.m_client = client;
72 #define CS(this) (this._cs)
74 ClientState CS(entity this) { assert(IS_CLIENT(this)); assert(this._cs); return this._cs; }
78 void DecodeLevelParms(entity this);
79 void PlayerScore_Attach(entity this);
80 void ClientData_Attach(entity this);
81 void accuracy_init(entity this);
82 void entcs_attach(entity this);
83 void playerdemo_init(entity this);
84 void anticheat_init(entity this);
85 void W_HitPlotOpen(entity this);
86 void bot_clientconnect(entity this);
88 void ClientState_attach(entity this)
90 this._cs = NEW(ClientState, this);
92 GetCvars(0); // get other cvars from player
94 // TODO: xonstat elo.txt support, until then just 404s
95 if (false && IS_REAL_CLIENT(this)) { PlayerStats_PlayerBasic_CheckUpdate(this); }
97 // TODO: fold all of these into ClientState
99 DecodeLevelParms(this);
101 PlayerScore_Attach(this);
102 ClientData_Attach(this);
105 playerdemo_init(this);
106 anticheat_init(this);
109 bot_clientconnect(this);
112 void bot_clientdisconnect();
113 void W_HitPlotClose(entity this);
114 void anticheat_report();
115 void playerdemo_shutdown();
116 void entcs_detach(entity this);
117 void accuracy_free(entity this);
118 void ClientData_Detach(entity this);
119 void PlayerScore_Detach(entity this);
121 void ClientState_detach(entity this)
126 GetCvars(-1); // free cvars
128 bot_clientdisconnect();
130 W_HitPlotClose(this);
132 playerdemo_shutdown();
135 ClientData_Detach(this);
136 PlayerScore_Detach(self);