]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/wepent.qc
Make sure offhand blaster is off by default on old servers
[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 // #define PROP(public, fld, set, sv, cl)
8 #define WEPENT_NETPROPS(PROP) PROP(false, sv_entnum, WEPENT_SET_NORMAL, {}, {}) /* sentinel */ \
9         PROP(false, m_switchweapon, WEPENT_SET_NORMAL, \
10         { WriteByte(chan, this.m_switchweapon.m_id); }, \
11         { (viewmodels[this.m_wepent_slot]).switchweapon = Weapons_from(ReadByte()); }) \
12     \
13     PROP(false, m_switchingweapon, WEPENT_SET_NORMAL, \
14         { WriteByte(chan, this.m_switchingweapon.m_id); }, \
15         { (viewmodels[this.m_wepent_slot]).switchingweapon = Weapons_from(ReadByte()); }) \
16     \
17     PROP(false, m_weapon, WEPENT_SET_NORMAL, \
18         { WriteByte(chan, this.m_weapon.m_id); }, \
19         { (viewmodels[this.m_wepent_slot]).activeweapon = Weapons_from(ReadByte()); }) \
20     \
21     PROP(false, m_alpha, WEPENT_SET_NORMAL, \
22         { WriteByte(chan, rint(bound(-1, 254 * this.m_alpha, 254) - -1)); }, \
23         { (viewmodels[this.m_wepent_slot]).alpha = (ReadByte() + -1) / 254; }) \
24     \
25     PROP(false, vortex_charge, WEPENT_SET_NORMAL, \
26         { WriteByte(chan, this.vortex_charge * 255); }, \
27         { (viewmodels[this.m_wepent_slot]).vortex_charge = ReadByte() / 255; }) \
28     \
29     PROP(false, m_gunalign, WEPENT_SET_NORMAL, \
30         { WriteByte(chan, this.m_gunalign); }, \
31         { (viewmodels[this.m_wepent_slot]).m_gunalign = ReadByte(); }) \
32     \
33     PROP(false, porto_v_angle_held, WEPENT_SET_NORMAL, \
34         { WriteByte(chan, this.porto_v_angle_held); if(this.porto_v_angle_held) { \
35                  WriteAngle(chan, this.porto_v_angle.x); WriteAngle(chan, this.porto_v_angle.y); \
36                 } }, \
37         { (viewmodels[this.m_wepent_slot]).angles_held_status = ReadByte(); if((viewmodels[this.m_wepent_slot]).angles_held_status) { \
38                 (viewmodels[this.m_wepent_slot]).angles_held_x = ReadAngle(); (viewmodels[this.m_wepent_slot]).angles_held_y = ReadAngle(); (viewmodels[this.m_wepent_slot]).angles_held_z = 0; } \
39                 else { (viewmodels[this.m_wepent_slot]).angles_held = '0 0 0'; } }) \
40     \
41     PROP(false, tuba_instrument, WEPENT_SET_NORMAL, \
42         { WriteByte(chan, this.tuba_instrument); }, \
43         { (viewmodels[this.m_wepent_slot]).tuba_instrument = ReadByte(); }) \
44     \
45     PROP(false, hagar_load, WEPENT_SET_NORMAL, \
46         { WriteByte(chan, this.hagar_load); }, \
47         { (viewmodels[this.m_wepent_slot]).hagar_load = ReadByte(); }) \
48     \
49     PROP(false, minelayer_mines, WEPENT_SET_NORMAL, \
50         { WriteByte(chan, this.minelayer_mines); }, \
51         { (viewmodels[this.m_wepent_slot]).minelayer_mines = ReadByte(); }) \
52     \
53     PROP(false, arc_heat_percent, WEPENT_SET_NORMAL, \
54         { WriteByte(chan, this.arc_heat_percent * 16); }, \
55         { (viewmodels[this.m_wepent_slot]).arc_heat_percent = ReadByte() / 16; }) \
56     \
57     PROP(false, vortex_chargepool_ammo, WEPENT_SET_NORMAL, \
58         { WriteByte(chan, this.vortex_chargepool_ammo * 16); }, \
59         { (viewmodels[this.m_wepent_slot]).vortex_chargepool_ammo = ReadByte() / 16; }) \
60     \
61     PROP(false, clip_load, WEPENT_SET_NORMAL, \
62         { WriteShort(chan, this.clip_load); }, \
63         { (viewmodels[this.m_wepent_slot]).clip_load = ReadShort(); }) \
64     \
65     PROP(false, clip_size, WEPENT_SET_NORMAL, \
66         { WriteShort(chan, this.clip_size); }, \
67         { (viewmodels[this.m_wepent_slot]).clip_size = ReadShort(); }) \
68     \
69         /**/
70
71 #ifdef SVQC
72
73         int WEPENT_PUBLICMASK = 0;
74         STATIC_INIT(WEPENT_PUBLICMASK)
75         {
76                 int i = 0;
77                 #define X(public, fld, set, sv, cl) { \
78                         if (public) { \
79                                 WEPENT_PUBLICMASK |= BIT(i); \
80                         } \
81                         i += 1; \
82                 }
83                 WEPENT_NETPROPS(X);
84         #undef X
85                 if (i >= BITS(24 - 1)) LOG_FATAL("Exceeded WEPENT_NETPROPS limit");
86         }
87
88         bool _wepent_send(entity this, entity to, int sf, int chan)
89         {
90                 sf |= this.m_forceupdate;
91                 this.m_forceupdate = 0;
92                 if (chan == MSG_ENTITY)
93                         WriteHeader(chan, ENT_CLIENT_WEPENT);
94                 else
95                         WriteHeader(chan, CLIENT_WEPENT);
96                 .entity weaponentity = this.owner.weaponentity_fld;
97                 WriteByte(chan, weaponslot(weaponentity));
98                 WriteInt24_t(chan, sf);
99                 int i = 0;
100                 #define X(public, fld, set, sv, cl) { \
101                         if (sf & BIT(i)) { \
102                                 sv; \
103                         } \
104                         i += 1; \
105                 }
106                 WEPENT_NETPROPS(X);
107         #undef X
108                 return true;
109         }
110
111         bool wepent_send(entity this, entity to, int sf)
112         {
113                 return _wepent_send(this, to, sf, MSG_ENTITY);
114         }
115
116         void wepent_think(entity this)
117         {
118                 if(wasfreed(this.owner) || !this.owner)
119                 {
120                         delete(this);
121                         return;
122                 }
123
124                 this.nextthink = time;
125
126                 entity o = this.owner;
127
128                 int i = 0;
129                 #define X(public, fld, set, sv, cl) { \
130                         if (this.fld != o.fld) { \
131                                 set(this.fld, o.fld); \
132                                 this.SendFlags |= BIT(i); \
133                         } \
134                         i += 1; \
135                 }
136                 WEPENT_NETPROPS(X);
137         #undef X
138         }
139
140         bool wepent_customize(entity this, entity client)
141         {
142                 entity e = WaypointSprite_getviewentity(client);
143                 .entity weaponentity = this.owner.weaponentity_fld;
144                 return e.(weaponentity) == this.owner;
145         }
146
147         void wepent_link(entity wep)
148         {
149                 entity e = new(wepent_sender);
150                 e.owner = wep;
151                 setthink(e, wepent_think);
152                 e.nextthink = time;
153                 //e.drawonlytoclient = wep.owner;
154                 setcefc(e, wepent_customize);
155                 Net_LinkEntity(e, false, 0, wepent_send);
156         }
157
158 #endif
159
160 #ifdef CSQC
161
162         bool ReadWepent(entity this)
163         {
164                 int slot = ReadByte();
165                 this.m_wepent_slot = slot;
166                 viewmodels[slot].m_wepent_slot = slot;
167                 int sf = ReadInt24_t();
168                 int i = 0;
169                 #define X(public, fld, set, sv, cl) { \
170                         if (sf & BIT(i)) { \
171                                 cl; \
172                         } \
173                         i += 1; \
174                 }
175                 WEPENT_NETPROPS(X);
176         #undef X
177                 return true;
178         }
179
180         NET_HANDLE(ENT_CLIENT_WEPENT, bool isnew)
181         {
182                 if (isnew)
183                         this.classname = "wepent_receiver";
184                 return ReadWepent(this);
185         }
186
187         NET_HANDLE(CLIENT_WEPENT, bool isnew)
188         {
189                 return ReadWepent(NULL);
190         }
191
192 #endif