]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/wepent.qc
Move some weapon stats into wepent fields, and make spectating weapons a bit more...
[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 * 16); }, \
27         { (viewmodels[this.m_wepent_slot]).vortex_charge = ReadByte() / 16; }) \
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         /**/
62
63 #ifdef SVQC
64
65         int WEPENT_PUBLICMASK = 0;
66         STATIC_INIT(WEPENT_PUBLICMASK)
67         {
68                 int i = 0;
69                 #define X(public, fld, set, sv, cl) { \
70                         if (public) { \
71                                 WEPENT_PUBLICMASK |= BIT(i); \
72                         } \
73                         i += 1; \
74                 }
75                 WEPENT_NETPROPS(X);
76         #undef X
77                 if (i >= BITS(16 - 1)) LOG_FATAL("Exceeded WEPENT_NETPROPS limit");
78         }
79
80         bool _wepent_send(entity this, entity to, int sf, int chan)
81         {
82                 sf |= this.m_forceupdate;
83                 this.m_forceupdate = 0;
84                 if (chan == MSG_ENTITY)
85                         WriteHeader(chan, ENT_CLIENT_WEPENT);
86                 else
87                         WriteHeader(chan, CLIENT_WEPENT);
88                 .entity weaponentity = this.owner.weaponentity_fld;
89                 WriteByte(chan, weaponslot(weaponentity));
90                 WriteShort(chan, sf);
91                 int i = 0;
92                 #define X(public, fld, set, sv, cl) { \
93                         if (sf & BIT(i)) { \
94                                 sv; \
95                         } \
96                         i += 1; \
97                 }
98                 WEPENT_NETPROPS(X);
99         #undef X
100                 return true;
101         }
102
103         bool wepent_send(entity this, entity to, int sf)
104         {
105                 return _wepent_send(this, to, sf, MSG_ENTITY);
106         }
107
108         void wepent_think(entity this)
109         {
110                 if(wasfreed(this.owner) || !this.owner)
111                 {
112                         delete(this);
113                         return;
114                 }
115
116                 this.nextthink = time;
117
118                 entity o = this.owner;
119
120                 int i = 0;
121                 #define X(public, fld, set, sv, cl) { \
122                         if (this.fld != o.fld) { \
123                                 set(this.fld, o.fld); \
124                                 this.SendFlags |= BIT(i); \
125                         } \
126                         i += 1; \
127                 }
128                 WEPENT_NETPROPS(X);
129         #undef X
130         }
131
132         bool wepent_customize(entity this, entity client)
133         {
134                 entity e = WaypointSprite_getviewentity(client);
135                 .entity weaponentity = this.owner.weaponentity_fld;
136                 return e.(weaponentity) == this.owner;
137         }
138
139         void wepent_link(entity wep)
140         {
141                 entity e = new(wepent_sender);
142                 e.owner = wep;
143                 setthink(e, wepent_think);
144                 e.nextthink = time;
145                 //e.drawonlytoclient = wep.owner;
146                 setcefc(e, wepent_customize);
147                 Net_LinkEntity(e, false, 0, wepent_send);
148         }
149
150 #endif
151
152 #ifdef CSQC
153
154         bool ReadWepent(entity this)
155         {
156                 int slot = ReadByte();
157                 this.m_wepent_slot = slot;
158                 viewmodels[slot].m_wepent_slot = slot;
159                 int sf = ReadShort();
160                 int i = 0;
161                 #define X(public, fld, set, sv, cl) { \
162                         if (sf & BIT(i)) { \
163                                 cl; \
164                         } \
165                         i += 1; \
166                 }
167                 WEPENT_NETPROPS(X);
168         #undef X
169                 return true;
170         }
171
172         NET_HANDLE(ENT_CLIENT_WEPENT, bool isnew)
173         {
174                 if (isnew)
175                         this.classname = "wepent_receiver";
176                 return ReadWepent(this);
177         }
178
179         NET_HANDLE(CLIENT_WEPENT, bool isnew)
180         {
181                 return ReadWepent(NULL);
182         }
183
184 #endif