]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_tuba.qc
Merge branch 'master' of ssh://git.xonotic.org/xonotic-data.pk3dir
[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 float Tuba_GetNote(entity pl, float hittype)
11 {
12         float note;
13         float movestate;
14         movestate = 5;
15         if(pl.movement_x < 0) movestate -= 3;
16         if(pl.movement_x > 0) movestate += 3;
17         if(pl.movement_y < 0) movestate -= 1;
18         if(pl.movement_y > 0) movestate += 1;
19         switch(movestate)
20         {
21         // layout: originally I wanted
22         //   eb e  e#=f
23         //   B  c  d
24         //   Gb G  G#
25         // but then you only use forward and right key. So to make things more
26         // interesting, I swapped B with e#. Har har har...
27         //   eb e  B
28         // f=e# c  d
29         //   Gb G  G#
30                 case 1: note = -6; break; // Gb
31                 case 2: note = -5; break; // G
32                 case 3: note = -4; break; // G#
33                 case 4: note = +5; break; // e#
34                 case 5: note =  0; break; // c
35                 case 6: note = +2; break; // d
36                 case 7: note = +3; break; // eb
37                 case 8: note = +4; break; // e
38                 case 9: note = -1; break; // B
39         }
40         if(pl.BUTTON_CROUCH)
41                 note -= 12;
42         if(pl.BUTTON_JUMP)
43                 note += 12;
44         if(hittype & HITTYPE_SECONDARY)
45                 note += 7;
46         
47         // we support two kinds of tubas, those tuned in Eb and those tuned in C
48         // kind of tuba currently is player slot number, or team number if in
49         // teamplay
50         // that way, holes in the range of notes are "plugged"
51         if(teamplay)
52         {
53                 if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4)
54                         note += 3;
55         }
56         else
57         {
58                 if(pl.clientcolors & 1)
59                         note += 3;
60         }
61         
62         // total range of notes:
63         //                       0
64         //                 ***  ** ****
65         //                        ***  ** ****
66         //     ***  ** ****
67         //            ***  ** ****
68         //     ***  ********************* ****
69         //     -18.........................+12
70         //        ***  ********************* ****
71         //     -18............................+15
72         //     with jump: ... +24
73         //     ... +27
74         return note;
75 }
76
77 float W_Tuba_NoteSendEntity(entity to, float sf)
78 {
79         float f;
80
81         WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
82         WriteByte(MSG_ENTITY, sf);
83         if(sf & 1)
84         {
85                 WriteChar(MSG_ENTITY, self.cnt);
86                 f = 0;
87                 if(self.realowner != to)
88                         f |= 1;
89                 f |= 2 * self.tuba_instrument;
90                 WriteByte(MSG_ENTITY, f);
91         }
92         if(sf & 2)
93         {
94                 WriteCoord(MSG_ENTITY, self.origin_x);
95                 WriteCoord(MSG_ENTITY, self.origin_y);
96                 WriteCoord(MSG_ENTITY, self.origin_z);
97         }
98         return TRUE;
99 }
100
101 void W_Tuba_NoteThink()
102 {
103         float dist_mult;
104         float vol0, vol1;
105         vector dir0, dir1;
106         vector v;
107         entity e;
108         if(time > self.teleport_time)
109         {
110                 self.realowner.tuba_note = world;
111                 remove(self);
112                 return;
113         }
114         self.nextthink = time;
115         dist_mult = autocvar_g_balance_tuba_attenuation / autocvar_snd_soundradius;
116         FOR_EACH_REALCLIENT(e)
117         if(e != self.realowner)
118         {
119                 v = self.origin - (e.origin + e.view_ofs);
120                 vol0 = max(0, 1 - vlen(v) * dist_mult);
121                 dir0 = normalize(v);
122                 v = self.realowner.origin - (e.origin + e.view_ofs);
123                 vol1 = max(0, 1 - vlen(v) * dist_mult);
124                 dir1 = normalize(v);
125                 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
126                 {
127                         setorigin(self, self.realowner.origin);
128                         self.SendFlags |= 2;
129                         break;
130                 }
131                 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
132                 {
133                         setorigin(self, self.realowner.origin);
134                         self.SendFlags |= 2;
135                         break;
136                 }
137         }
138 }
139
140 void W_Tuba_Attack(float hittype)
141 {
142         vector o;
143         float n;
144
145         W_SetupShot(self, FALSE, 2, "", 0, autocvar_g_balance_tuba_damage);
146
147         n = Tuba_GetNote(self, hittype);
148
149         hittype = 0;
150         if(self.tuba_instrument & 1)
151                 hittype |= HITTYPE_SECONDARY;
152         if(self.tuba_instrument & 2)
153                 hittype |= HITTYPE_BOUNCE;
154         if(self.tuba_instrument & 4)
155                 hittype |= HITTYPE_HEADSHOT;
156
157         if(self.tuba_note)
158         {
159                 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
160                 {
161                         remove(self.tuba_note);
162                         self.tuba_note = world;
163                 }
164         }
165
166         if not(self.tuba_note)
167         {
168                 self.tuba_note = spawn();
169                 self.tuba_note.owner = self.tuba_note.realowner = self;
170                 self.tuba_note.cnt = n;
171                 self.tuba_note.tuba_instrument = self.tuba_instrument;
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 * W_WeaponRateFactor(); // 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                 self.current_ammo = ammo_none;
248                 self.tuba_instrument = 0;
249         }
250         else if (req == WR_RELOAD)
251         {
252                 // switch to alternate instruments :)
253                 if(self.weaponentity.state == WS_READY)
254                 {
255                         switch(self.tuba_instrument)
256                         {
257                                 case 0:
258                                         self.tuba_instrument = 1;
259                                         self.weaponname = "akordeon";
260                                         break;
261                                 case 1:
262                                         self.tuba_instrument = 0;
263                                         self.weaponname = "tuba";
264                                         break;
265                         }
266                         W_SetupShot(self, FALSE, 0, "", 0, 0);
267                         pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1);
268                         self.weaponentity.state = WS_INUSE;
269                         weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
270                 }
271         }
272         else if (req == WR_CHECKAMMO1)
273                 return TRUE; // TODO use fuel?
274         else if (req == WR_CHECKAMMO2)
275                 return TRUE; // TODO use fuel?
276         return TRUE;
277 }
278 #endif
279 #ifdef CSQC
280 float w_tuba(float req)
281 {
282         if(req == WR_IMPACTEFFECT)
283         {
284                 // nothing to do here; particles of tuba are handled differently
285         }
286         else if(req == WR_PRECACHE)
287         {
288                 // nothing to do
289         }
290         else if (req == WR_SUICIDEMESSAGE)
291         {
292                 float instr;
293                 instr = 0;
294                 if(w_deathtype & HITTYPE_SECONDARY)
295                         instr |= 1;
296                 if(w_deathtype & HITTYPE_BOUNCE)
297                         instr |= 2;
298                 if(w_deathtype & HITTYPE_HEADSHOT)
299                         instr |= 4;
300                 switch(instr)
301                 {
302                         default:
303                         case 0: // Tuba
304                                 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Tuba");
305                                 break;
306                         case 1: // Accordeon
307                                 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Accordeon");
308                                 break;
309                 }
310         }
311         else if (req == WR_KILLMESSAGE)
312         {
313                 float instr;
314                 instr = 0;
315                 if(w_deathtype & HITTYPE_SECONDARY)
316                         instr |= 1;
317                 if(w_deathtype & HITTYPE_BOUNCE)
318                         instr |= 2;
319                 if(w_deathtype & HITTYPE_HEADSHOT)
320                         instr |= 4;
321                 switch(instr)
322                 {
323                         default:
324                         case 0: // Tuba
325                                 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Tuba");
326                                 break;
327                         case 1: // Accordeon
328                                 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Accordeon");
329                                 break;
330                 }
331         }
332         return TRUE;
333 }
334 #endif
335 #endif