]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/wepent.qc
Send alpha as part of weapon state, rather than when firing
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / wepent.qc
1 #include "wepent.qh"
2
3 #define WEPENT_SET_NORMAL(var, x) MACRO_BEGIN \
4         var = x; \
5 MACRO_END
6
7 /** the engine player name strings are mutable! */
8 #define WEPENT_SET_MUTABLE_STRING(var, x) MACRO_BEGIN \
9         if (var) strunzone(var); \
10         var = strzone(x); \
11 MACRO_END
12
13 .int w_sv_entnum;
14 .Weapon w_m_switchweapon;
15 .Weapon w_m_switchingweapon;
16 .Weapon w_m_weapon;
17 //.float w_weapon_nextthink;
18 .float w_m_alpha;
19
20 // #define PROP(public, fld, set, sv, cl)
21 #define WEPENT_NETPROPS(PROP) PROP(false, sv_entnum, WEPENT_SET_NORMAL, {}, {}) /* sentinel */ \
22         PROP(false, m_switchweapon, WEPENT_SET_NORMAL, \
23         { WriteByte(chan, this.m_switchweapon.m_id); }, \
24         { (viewmodels[this.m_wepent_slot]).switchweapon = Weapons_from(ReadByte()); }) \
25     \
26     PROP(false, m_switchingweapon, WEPENT_SET_NORMAL, \
27         { WriteByte(chan, this.m_switchingweapon.m_id); }, \
28         { (viewmodels[this.m_wepent_slot]).switchingweapon = Weapons_from(ReadByte()); }) \
29     \
30     PROP(false, m_weapon, WEPENT_SET_NORMAL, \
31         { WriteByte(chan, this.m_weapon.m_id); }, \
32         { (viewmodels[this.m_wepent_slot]).activeweapon = Weapons_from(ReadByte()); }) \
33     \
34     PROP(false, m_alpha, WEPENT_SET_NORMAL, \
35         { WriteByte(chan, this.m_alpha * 16); }, \
36         { (viewmodels[this.m_wepent_slot]).alpha = ReadByte() / 16; }) \
37     \
38         /**/
39
40 #ifdef SVQC
41
42         int WEPENT_PUBLICMASK = 0;
43         STATIC_INIT(WEPENT_PUBLICMASK)
44         {
45                 int i = 0;
46                 #define X(public, fld, set, sv, cl) { \
47                         if (public) { \
48                                 WEPENT_PUBLICMASK |= BIT(i); \
49                         } \
50                         i += 1; \
51                 }
52                 WEPENT_NETPROPS(X);
53         #undef X
54                 if (i >= BITS(16 - 1)) LOG_FATAL("Exceeded WEPENT_NETPROPS limit");
55         }
56
57         bool _wepent_send(entity this, entity to, int sf, int chan)
58         {
59                 sf |= this.m_forceupdate;
60                 this.m_forceupdate = 0;
61                 if (chan == MSG_ENTITY)
62                         WriteHeader(chan, ENT_CLIENT_WEPENT);
63                 else
64                         WriteHeader(chan, CLIENT_WEPENT);
65                 .entity weaponentity = this.weaponentity_fld;
66                 WriteByte(chan, weaponslot(weaponentity));
67                 WriteShort(chan, sf);
68                 int i = 0;
69                 #define X(public, fld, set, sv, cl) { \
70                         if (sf & BIT(i)) { \
71                                 sv; \
72                         } \
73                         i += 1; \
74                 }
75                 WEPENT_NETPROPS(X);
76         #undef X
77                 return true;
78         }
79
80         bool wepent_send(entity this, entity to, int sf)
81         {
82                 return _wepent_send(this, to, sf, MSG_ENTITY);
83         }
84
85         void wepent_update(entity this)
86         {
87                 int i = 0;
88                 #define X(public, fld, set, sv, cl) { \
89                         if (this.w_##fld != this.fld) { \
90                                 set(this.w_##fld, this.fld); \
91                                 this.SendFlags |= BIT(i); \
92                         } \
93                         i += 1; \
94                 }
95                 WEPENT_NETPROPS(X);
96         #undef X
97         }
98
99         void wepent_link(entity wep)
100         {
101                 Net_LinkEntity(wep, false, 0, wepent_send);
102         }
103
104 #endif
105
106 #ifdef CSQC
107
108         bool ReadWepent(entity this)
109         {
110                 this.m_wepent_slot = ReadByte();
111                 int sf = ReadShort();
112                 int i = 0;
113                 #define X(public, fld, set, sv, cl) { \
114                         if (sf & BIT(i)) { \
115                                 cl; \
116                         } \
117                         i += 1; \
118                 }
119                 WEPENT_NETPROPS(X);
120         #undef X
121                 return true;
122         }
123
124         NET_HANDLE(ENT_CLIENT_WEPENT, bool isnew)
125         {
126                 if (isnew)
127                 {
128                         make_pure(this);
129                         this.classname = "wepent_receiver";
130                 }
131                 return ReadWepent(this);
132         }
133
134         NET_HANDLE(CLIENT_WEPENT, bool isnew)
135         {
136                 return ReadWepent(NULL);
137         }
138
139 #endif