]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_tuba.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_tuba.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(TUBA, w_tuba, 0, 1, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "tuba", "tuba", _("@!#%'n Tuba"))
3 #else
4 #ifdef SVQC
5 //#define TUBA_NOTE(n) strcat("weapons/tuba_note", ftos(n), ".wav")
6 .float tuba_notecount;
7 .entity tuba_note;
8 .float tuba_smoketime;
9
10 void W_Tuba_SetAmmoCounter()
11 {
12         // this weapon doesn't have a reload system, so always set the clip to 0 when switching to it
13         self.clip_load = self.clip_size = 0; // also keeps crosshair ammo from displaying
14 }
15
16 float Tuba_GetNote(entity pl, float hittype)
17 {
18         float note;
19         float movestate;
20         movestate = 5;
21         if(pl.movement_x < 0) movestate -= 3;
22         if(pl.movement_x > 0) movestate += 3;
23         if(pl.movement_y < 0) movestate -= 1;
24         if(pl.movement_y > 0) movestate += 1;
25         switch(movestate)
26         {
27         // layout: originally I wanted
28         //   eb e  e#=f
29         //   B  c  d
30         //   Gb G  G#
31         // but then you only use forward and right key. So to make things more
32         // interesting, I swapped B with e#. Har har har...
33         //   eb e  B
34         // f=e# c  d
35         //   Gb G  G#
36                 case 1: note = -6; break; // Gb
37                 case 2: note = -5; break; // G
38                 case 3: note = -4; break; // G#
39                 case 4: note = +5; break; // e#
40                 case 5: note =  0; break; // c
41                 case 6: note = +2; break; // d
42                 case 7: note = +3; break; // eb
43                 case 8: note = +4; break; // e
44                 case 9: note = -1; break; // B
45         }
46         if(pl.BUTTON_CROUCH)
47                 note -= 12;
48         if(pl.BUTTON_JUMP)
49                 note += 12;
50         if(hittype & HITTYPE_SECONDARY)
51                 note += 7;
52         
53         // we support two kinds of tubas, those tuned in Eb and those tuned in C
54         // kind of tuba currently is player slot number, or team number if in
55         // teamplay
56         // that way, holes in the range of notes are "plugged"
57         if(teams_matter)
58         {
59                 if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4)
60                         note += 3;
61         }
62         else
63         {
64                 if(pl.clientcolors & 1)
65                         note += 3;
66         }
67         
68         // total range of notes:
69         //                       0
70         //                 ***  ** ****
71         //                        ***  ** ****
72         //     ***  ** ****
73         //            ***  ** ****
74         //     ***  ********************* ****
75         //     -18.........................+12
76         //        ***  ********************* ****
77         //     -18............................+15
78         //     with jump: ... +24
79         //     ... +27
80         return note;
81 }
82
83 float W_Tuba_NoteSendEntity(entity to, float sf)
84 {
85         WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
86         WriteByte(MSG_ENTITY, (sf & 1) | ((self.cnt + 42) * 2));
87         if(sf & 1)
88         {
89                 WriteCoord(MSG_ENTITY, self.origin_x);
90                 WriteCoord(MSG_ENTITY, self.origin_y);
91                 WriteCoord(MSG_ENTITY, self.origin_z);
92                 WriteByte(MSG_ENTITY, self.owner != to);
93         }
94         return TRUE;
95 }
96
97 void W_Tuba_NoteThink()
98 {
99         float dist_mult;
100         float vol0, vol1;
101         vector dir0, dir1;
102         vector v;
103         entity e;
104         if(time > self.teleport_time)
105         {
106                 self.owner.tuba_note = world;
107                 remove(self);
108                 return;
109         }
110         self.nextthink = time;
111         dist_mult = autocvar_g_balance_tuba_attenuation / autocvar_snd_soundradius;
112         FOR_EACH_REALCLIENT(e)
113         if(e != self.owner)
114         {
115                 v = self.origin - (e.origin + e.view_ofs);
116                 vol0 = max(0, 1 - vlen(v) * dist_mult);
117                 dir0 = normalize(v);
118                 v = self.owner.origin - (e.origin + e.view_ofs);
119                 vol1 = max(0, 1 - vlen(v) * dist_mult);
120                 dir1 = normalize(v);
121                 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
122                 {
123                         setorigin(self, self.owner.origin);
124                         self.SendFlags |= 1;
125                         break;
126                 }
127                 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
128                 {
129                         setorigin(self, self.owner.origin);
130                         self.SendFlags |= 1;
131                         break;
132                 }
133         }
134 }
135
136 void W_Tuba_Attack(float hittype)
137 {
138         vector o;
139         float c, n;
140         W_SetupShot(self, FALSE, 2, "", 0, autocvar_g_balance_tuba_damage);
141         if(self.tuba_notecount)
142         {
143                 self.tuba_notecount = FALSE;
144                 c = CHAN_WEAPON;
145         }
146         else
147         {
148                 self.tuba_notecount = TRUE;
149                 c = CHAN_WEAPON2;
150         }
151
152         n = Tuba_GetNote(self, hittype);
153
154         if(self.tuba_note)
155         {
156                 if(self.tuba_note.cnt != n)
157                 {
158                         /*
159                         self.tuba_note.cnt = n;
160                         self.tuba_note.SendFlags |= 2;
161                         */
162                         remove(self.tuba_note);
163                         self.tuba_note = world;
164                 }
165         }
166
167         if not(self.tuba_note)
168         {
169                 self.tuba_note = spawn();
170                 self.tuba_note.owner = self;
171                 self.tuba_note.cnt = n;
172                 self.tuba_note.think = W_Tuba_NoteThink;
173                 self.tuba_note.nextthink = time;
174                 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
175         }
176
177         self.tuba_note.teleport_time = time + autocvar_g_balance_tuba_refire * 2; // so it can get prolonged safely
178
179         //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
180         RadiusDamage(self, self, autocvar_g_balance_tuba_damage, autocvar_g_balance_tuba_edgedamage, autocvar_g_balance_tuba_radius, world, autocvar_g_balance_tuba_force, hittype | WEP_TUBA, world);
181
182         o = gettaginfo(self.exteriorweaponentity, 0);
183         if(time > self.tuba_smoketime)
184         {
185                 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
186                 self.tuba_smoketime = time + 0.25;
187         }
188 }
189
190 void spawnfunc_weapon_tuba (void)
191 {
192         weapon_defaultspawnfunc(WEP_TUBA);
193 }
194
195 float w_tuba(float req)
196 {
197         if (req == WR_AIM)
198         {
199                 // bots cannot play the Tuba well yet
200                 // I think they should start with the recorder first
201                 if(vlen(self.origin - self.enemy.origin) < autocvar_g_balance_tuba_radius)
202                 {
203                         if(random() > 0.5)
204                                 self.BUTTON_ATCK = 1;
205                         else
206                                 self.BUTTON_ATCK2 = 1;
207                 }
208         }
209         else if (req == WR_THINK)
210         {
211                 if (self.BUTTON_ATCK)
212                 if (weapon_prepareattack(0, autocvar_g_balance_tuba_refire))
213                 {
214                         W_Tuba_Attack(0);
215                         //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
216                         weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
217                 }
218                 if (self.BUTTON_ATCK2)
219                 if (weapon_prepareattack(1, autocvar_g_balance_tuba_refire))
220                 {
221                         W_Tuba_Attack(HITTYPE_SECONDARY);
222                         //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
223                         weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
224                 }
225                 if(self.tuba_note)
226                 {
227                         if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
228                         {
229                                 remove(self.tuba_note);
230                                 self.tuba_note = world;
231                         }
232                 }
233         }
234         else if (req == WR_PRECACHE)
235         {
236                 precache_model ("models/weapons/g_tuba.md3");
237                 precache_model ("models/weapons/v_tuba.md3");
238                 precache_model ("models/weapons/h_tuba.iqm");
239
240                 //float i;
241                 //for(i = -18; i <= +27; ++i)
242                 //      precache_sound(TUBA_NOTE(i));
243         }
244         else if (req == WR_SETUP)
245         {
246                 weapon_setup(WEP_TUBA);
247                 W_Porto_SetAmmoCounter();
248         }
249         else if (req == WR_CHECKAMMO1)
250                 return TRUE; // TODO use fuel?
251         else if (req == WR_CHECKAMMO2)
252                 return TRUE; // TODO use fuel?
253         return TRUE;
254 };
255 #endif
256 #ifdef CSQC
257 float w_tuba(float req)
258 {
259         if(req == WR_IMPACTEFFECT)
260         {
261                 // nothing to do here; particles of tuba are handled differently
262         }
263         else if(req == WR_PRECACHE)
264         {
265                 // nothing to do
266         }
267         else if (req == WR_SUICIDEMESSAGE)
268         {
269                 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Tuba");
270         }
271         else if (req == WR_KILLMESSAGE)
272         {
273                 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Tuba");
274         }
275         return TRUE;
276 }
277 #endif
278 #endif