]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_tuba.qc
fb240bd369c0ff2b04e81f2ae4ff9dca81411eff
[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 .entity tuba_note;
7 .float tuba_smoketime;
8 .float tuba_instrument;
9
10 #define MAX_TUBANOTES 32
11 .float tuba_lastnotes_pos;
12 .vector tuba_lastnotes[MAX_TUBANOTES];
13
14 void W_Tuba_NoteOff()
15 {
16         // we have a note:
17         //   on: self.spawnshieldtime
18         //   off: time
19         //   note: self.cnt
20         if(self.owner.tuba_note == self)
21         {
22                 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_pos]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
23                 self.owner.tuba_lastnotes_pos = mod(self.owner.tuba_lastnotes_pos + 1, MAX_TUBANOTES);
24                 self.owner.tuba_note = world;
25         }
26         remove(self);
27 }
28
29 float Tuba_GetNote(entity pl, float hittype)
30 {
31         float note;
32         float movestate;
33         movestate = 5;
34         if(pl.movement_x < 0) movestate -= 3;
35         if(pl.movement_x > 0) movestate += 3;
36         if(pl.movement_y < 0) movestate -= 1;
37         if(pl.movement_y > 0) movestate += 1;
38         switch(movestate)
39         {
40         // layout: originally I wanted
41         //   eb e  e#=f
42         //   B  c  d
43         //   Gb G  G#
44         // but then you only use forward and right key. So to make things more
45         // interesting, I swapped B with e#. Har har har...
46         //   eb e  B
47         // f=e# c  d
48         //   Gb G  G#
49                 case 1: note = -6; break; // Gb
50                 case 2: note = -5; break; // G
51                 case 3: note = -4; break; // G#
52                 case 4: note = +5; break; // e#
53                 case 5: note =  0; break; // c
54                 case 6: note = +2; break; // d
55                 case 7: note = +3; break; // eb
56                 case 8: note = +4; break; // e
57                 case 9: note = -1; break; // B
58         }
59         if(pl.BUTTON_CROUCH)
60                 note -= 12;
61         if(pl.BUTTON_JUMP)
62                 note += 12;
63         if(hittype & HITTYPE_SECONDARY)
64                 note += 7;
65         
66         // we support two kinds of tubas, those tuned in Eb and those tuned in C
67         // kind of tuba currently is player slot number, or team number if in
68         // teamplay
69         // that way, holes in the range of notes are "plugged"
70         if(teamplay)
71         {
72                 if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4)
73                         note += 3;
74         }
75         else
76         {
77                 if(pl.clientcolors & 1)
78                         note += 3;
79         }
80         
81         // total range of notes:
82         //                       0
83         //                 ***  ** ****
84         //                        ***  ** ****
85         //     ***  ** ****
86         //            ***  ** ****
87         //     ***  ********************* ****
88         //     -18.........................+12
89         //        ***  ********************* ****
90         //     -18............................+15
91         //     with jump: ... +24
92         //     ... +27
93         return note;
94 }
95
96 float W_Tuba_NoteSendEntity(entity to, float sf)
97 {
98         float f;
99
100         msg_entity = to;
101         if(!sound_allowed(MSG_ONE, self.realowner))
102                 return FALSE;
103
104         WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
105         WriteByte(MSG_ENTITY, sf);
106         if(sf & 1)
107         {
108                 WriteChar(MSG_ENTITY, self.cnt);
109                 f = 0;
110                 if(self.realowner != to)
111                         f |= 1;
112                 f |= 2 * self.tuba_instrument;
113                 WriteByte(MSG_ENTITY, f);
114         }
115         if(sf & 2)
116         {
117                 WriteCoord(MSG_ENTITY, self.origin_x);
118                 WriteCoord(MSG_ENTITY, self.origin_y);
119                 WriteCoord(MSG_ENTITY, self.origin_z);
120         }
121         return TRUE;
122 }
123
124 void W_Tuba_NoteThink()
125 {
126         float dist_mult;
127         float vol0, vol1;
128         vector dir0, dir1;
129         vector v;
130         entity e;
131         if(time > self.teleport_time)
132         {
133                 W_Tuba_NoteOff();
134                 return;
135         }
136         self.nextthink = time;
137         dist_mult = autocvar_g_balance_tuba_attenuation / autocvar_snd_soundradius;
138         FOR_EACH_REALCLIENT(e)
139         if(e != self.realowner)
140         {
141                 v = self.origin - (e.origin + e.view_ofs);
142                 vol0 = max(0, 1 - vlen(v) * dist_mult);
143                 dir0 = normalize(v);
144                 v = self.realowner.origin - (e.origin + e.view_ofs);
145                 vol1 = max(0, 1 - vlen(v) * dist_mult);
146                 dir1 = normalize(v);
147                 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
148                 {
149                         setorigin(self, self.realowner.origin);
150                         self.SendFlags |= 2;
151                         break;
152                 }
153                 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
154                 {
155                         setorigin(self, self.realowner.origin);
156                         self.SendFlags |= 2;
157                         break;
158                 }
159         }
160 }
161
162 void W_Tuba_NoteOn(float hittype)
163 {
164         vector o;
165         float n;
166
167         W_SetupShot(self, FALSE, 2, "", 0, autocvar_g_balance_tuba_damage);
168
169         n = Tuba_GetNote(self, hittype);
170
171         hittype = 0;
172         if(self.tuba_instrument & 1)
173                 hittype |= HITTYPE_SECONDARY;
174         if(self.tuba_instrument & 2)
175                 hittype |= HITTYPE_BOUNCE;
176         if(self.tuba_instrument & 4)
177                 hittype |= HITTYPE_HEADSHOT;
178
179         if(self.tuba_note)
180         {
181                 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
182                 {
183                         entity oldself = self;
184                         self = self.tuba_note;
185                         W_Tuba_NoteOff();
186                         self = oldself;
187                 }
188         }
189
190         if not(self.tuba_note)
191         {
192                 self.tuba_note = spawn();
193                 self.tuba_note.owner = self.tuba_note.realowner = self;
194                 self.tuba_note.cnt = n;
195                 self.tuba_note.tuba_instrument = self.tuba_instrument;
196                 self.tuba_note.think = W_Tuba_NoteThink;
197                 self.tuba_note.nextthink = time;
198                 self.tuba_note.spawnshieldtime = time;
199                 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
200         }
201
202         self.tuba_note.teleport_time = time + autocvar_g_balance_tuba_refire * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
203
204         //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
205         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);
206
207         o = gettaginfo(self.exteriorweaponentity, 0);
208         if(time > self.tuba_smoketime)
209         {
210                 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
211                 self.tuba_smoketime = time + 0.25;
212         }
213 }
214
215 void spawnfunc_weapon_tuba (void)
216 {
217         weapon_defaultspawnfunc(WEP_TUBA);
218 }
219
220 float w_tuba(float req)
221 {
222         if (req == WR_AIM)
223         {
224                 // bots cannot play the Tuba well yet
225                 // I think they should start with the recorder first
226                 if(vlen(self.origin - self.enemy.origin) < autocvar_g_balance_tuba_radius)
227                 {
228                         if(random() > 0.5)
229                                 self.BUTTON_ATCK = 1;
230                         else
231                                 self.BUTTON_ATCK2 = 1;
232                 }
233         }
234         else if (req == WR_THINK)
235         {
236                 if (self.BUTTON_ATCK)
237                 if (weapon_prepareattack(0, autocvar_g_balance_tuba_refire))
238                 {
239                         W_Tuba_NoteOn(0);
240                         //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
241                         weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
242                 }
243                 if (self.BUTTON_ATCK2)
244                 if (weapon_prepareattack(1, autocvar_g_balance_tuba_refire))
245                 {
246                         W_Tuba_NoteOn(HITTYPE_SECONDARY);
247                         //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
248                         weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
249                 }
250                 if(self.tuba_note)
251                 {
252                         if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
253                         {
254                                 entity oldself = self;
255                                 self = self.tuba_note;
256                                 W_Tuba_NoteOff();
257                                 self = oldself;
258                         }
259                 }
260         }
261         else if (req == WR_PRECACHE)
262         {
263                 precache_model ("models/weapons/g_tuba.md3");
264                 precache_model ("models/weapons/v_tuba.md3");
265                 precache_model ("models/weapons/h_tuba.iqm");
266                 precache_model ("models/weapons/g_akordeon.md3");
267                 precache_model ("models/weapons/v_akordeon.md3");
268                 precache_model ("models/weapons/h_akordeon.iqm");
269
270                 //float i;
271                 //for(i = -18; i <= +27; ++i)
272                 //      precache_sound(TUBA_NOTE(i));
273         }
274         else if (req == WR_SETUP)
275         {
276                 weapon_setup(WEP_TUBA);
277                 self.current_ammo = ammo_none;
278                 self.tuba_instrument = 0;
279         }
280         else if (req == WR_RELOAD)
281         {
282                 // switch to alternate instruments :)
283                 if(self.weaponentity.state == WS_READY)
284                 {
285                         switch(self.tuba_instrument)
286                         {
287                                 case 0:
288                                         self.tuba_instrument = 1;
289                                         self.weaponname = "akordeon";
290                                         break;
291                                 case 1:
292                                         self.tuba_instrument = 0;
293                                         self.weaponname = "tuba";
294                                         break;
295                         }
296                         W_SetupShot(self, FALSE, 0, "", 0, 0);
297                         pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1);
298                         self.weaponentity.state = WS_INUSE;
299                         weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
300                 }
301         }
302         else if (req == WR_CHECKAMMO1)
303                 return TRUE; // TODO use fuel?
304         else if (req == WR_CHECKAMMO2)
305                 return TRUE; // TODO use fuel?
306         return TRUE;
307 }
308 #endif
309 #ifdef CSQC
310 float w_tuba(float req)
311 {
312         if(req == WR_IMPACTEFFECT)
313         {
314                 // nothing to do here; particles of tuba are handled differently
315         }
316         else if(req == WR_PRECACHE)
317         {
318                 // nothing to do
319         }
320         else if (req == WR_SUICIDEMESSAGE)
321         {
322                 float instr;
323                 instr = 0;
324                 if(w_deathtype & HITTYPE_SECONDARY)
325                         instr |= 1;
326                 if(w_deathtype & HITTYPE_BOUNCE)
327                         instr |= 2;
328                 if(w_deathtype & HITTYPE_HEADSHOT)
329                         instr |= 4;
330                 switch(instr)
331                 {
332                         default:
333                         case 0: // Tuba
334                                 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Tuba");
335                                 break;
336                         case 1: // Accordeon
337                                 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Accordeon");
338                                 break;
339                 }
340         }
341         else if (req == WR_KILLMESSAGE)
342         {
343                 float instr;
344                 instr = 0;
345                 if(w_deathtype & HITTYPE_SECONDARY)
346                         instr |= 1;
347                 if(w_deathtype & HITTYPE_BOUNCE)
348                         instr |= 2;
349                 if(w_deathtype & HITTYPE_HEADSHOT)
350                         instr |= 4;
351                 switch(instr)
352                 {
353                         default:
354                         case 0: // Tuba
355                                 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Tuba");
356                                 break;
357                         case 1: // Accordeon
358                                 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Accordeon");
359                                 break;
360                 }
361         }
362         return TRUE;
363 }
364 #endif
365 #endif