]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/wepent.qc
Begin reintroducing old gun alignment hack
[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
19 // #define PROP(public, fld, set, sv, cl)
20 #define WEPENT_NETPROPS(PROP) PROP(false, sv_entnum, WEPENT_SET_NORMAL, {}, {}) /* sentinel */ \
21         PROP(false, m_switchweapon, WEPENT_SET_NORMAL, \
22         { WriteByte(chan, this.m_switchweapon.m_id); }, \
23         { (viewmodels[this.m_wepent_slot]).switchweapon = Weapons_from(ReadByte()); }) \
24     \
25     PROP(false, m_switchingweapon, WEPENT_SET_NORMAL, \
26         { WriteByte(chan, this.m_switchingweapon.m_id); }, \
27         { (viewmodels[this.m_wepent_slot]).switchingweapon = Weapons_from(ReadByte()); }) \
28     \
29     PROP(false, m_weapon, WEPENT_SET_NORMAL, \
30         { WriteByte(chan, this.m_weapon.m_id); }, \
31         { (viewmodels[this.m_wepent_slot]).activeweapon = Weapons_from(ReadByte()); }) \
32     \
33         /**/
34
35 #ifdef SVQC
36
37         int WEPENT_PUBLICMASK = 0;
38         STATIC_INIT(WEPENT_PUBLICMASK)
39         {
40                 int i = 0;
41                 #define X(public, fld, set, sv, cl) { \
42                         if (public) { \
43                                 WEPENT_PUBLICMASK |= BIT(i); \
44                         } \
45                         i += 1; \
46                 }
47                 WEPENT_NETPROPS(X);
48         #undef X
49                 if (i >= BITS(16 - 1)) LOG_FATAL("Exceeded WEPENT_NETPROPS limit");
50         }
51
52         bool _wepent_send(entity this, entity to, int sf, int chan)
53         {
54                 sf |= this.m_forceupdate;
55                 this.m_forceupdate = 0;
56                 if (chan == MSG_ENTITY)
57                         WriteHeader(chan, ENT_CLIENT_WEPENT);
58                 else
59                         WriteHeader(chan, CLIENT_WEPENT);
60                 .entity weaponentity = this.weaponentity_fld;
61                 WriteByte(chan, weaponslot(weaponentity));
62                 WriteShort(chan, sf);
63                 int i = 0;
64                 #define X(public, fld, set, sv, cl) { \
65                         if (sf & BIT(i)) { \
66                                 sv; \
67                         } \
68                         i += 1; \
69                 }
70                 WEPENT_NETPROPS(X);
71         #undef X
72                 return true;
73         }
74
75         bool wepent_send(entity this, entity to, int sf)
76         {
77                 return _wepent_send(this, to, sf, MSG_ENTITY);
78         }
79
80         void wepent_update(entity this)
81         {
82                 int i = 0;
83                 #define X(public, fld, set, sv, cl) { \
84                         if (this.w_##fld != this.fld) { \
85                                 set(this.w_##fld, this.fld); \
86                                 this.SendFlags |= BIT(i); \
87                         } \
88                         i += 1; \
89                 }
90                 WEPENT_NETPROPS(X);
91         #undef X
92         }
93
94         void wepent_link(entity wep)
95         {
96                 Net_LinkEntity(wep, false, 0, wepent_send);
97         }
98
99 #endif
100
101 #ifdef CSQC
102
103         bool ReadWepent(entity this)
104         {
105                 this.m_wepent_slot = ReadByte();
106                 int sf = ReadShort();
107                 int i = 0;
108                 #define X(public, fld, set, sv, cl) { \
109                         if (sf & BIT(i)) { \
110                                 cl; \
111                         } \
112                         i += 1; \
113                 }
114                 WEPENT_NETPROPS(X);
115         #undef X
116                 return true;
117         }
118
119         NET_HANDLE(ENT_CLIENT_WEPENT, bool isnew)
120         {
121                 if (isnew)
122                 {
123                         make_pure(this);
124                         this.classname = "wepent_receiver";
125                 }
126                 return ReadWepent(this);
127         }
128
129         NET_HANDLE(CLIENT_WEPENT, bool isnew)
130         {
131                 return ReadWepent(NULL);
132         }
133
134 #endif