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