]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/state.qc
Merge branch 'martin-t/globals' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / state.qc
1 #include "state.qh"
2
3 void Inventory_new(PlayerState this);
4 void Inventory_delete(entity this);
5
6 void PlayerState_attach(entity this)
7 {
8         if (PS(this))
9                 return;
10
11         this._ps = NEW(PlayerState, this);
12
13         Inventory_new(PS(this));
14 }
15
16 void PlayerState_detach(entity this)
17 {
18     PlayerState ps = PS(this);
19         if (!ps) return;  // initial connect
20         PS(this) = NULL;
21
22         if (ps.m_client != this) return;  // don't own state, spectator
23         ps.ps_push(ps, this);
24     Inventory_delete(ps);
25
26         FOREACH_CLIENT(PS(it) == ps, { PS(it) = NULL; });
27         delete(ps);
28 }
29
30 void GetCvars(entity this, entity store, int);
31 void DecodeLevelParms(entity this);
32 void PlayerScore_Attach(entity this);
33 void ClientData_Attach(entity this);
34 void accuracy_init(entity this);
35 void entcs_attach(entity this);
36 void anticheat_init(entity this);
37 void W_HitPlotOpen(entity this);
38 void bot_clientconnect(entity this);
39
40 void ClientState_attach(entity this)
41 {
42         this._cs = NEW(ClientState, this);
43
44         // TODO: fold all of these into ClientState
45
46         DecodeLevelParms(this);
47
48         PlayerScore_Attach(this);
49         PlayerStats_PlayerBasic_CheckUpdate(this);
50         ClientData_Attach(this);
51         accuracy_init(this);
52         entcs_attach(this);
53         anticheat_init(this);
54         W_HitPlotOpen(this);
55 }
56
57 void bot_clientdisconnect(entity this);
58 void W_HitPlotClose(entity this);
59 void anticheat_report_to_eventlog(entity this);
60 void entcs_detach(entity this);
61 void accuracy_free(entity this);
62 void ClientData_Detach(entity this);
63 void PlayerScore_Detach(entity this);
64
65 void ClientState_detach(entity this)
66 {
67     GetCvars(this, CS(this), -1);  // free cvars TODO: is this still needed now that it's stored on the clientstate entity?
68     accuracy_free(this); // TODO: needs to be before CS() is deleted!
69     PlayerScore_Detach(this); // what ^they^ said
70     W_HitPlotClose(this);
71     ClientData_Detach(this);
72     entcs_detach(this);
73         delete(CS(this));
74         this._cs = NULL;
75
76     bot_clientdisconnect(this);
77
78     anticheat_report_to_eventlog(this);
79 }