]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_crylink.qc
Merge branch 'master' into terencehill/physics_panel_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_crylink.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(CRYLINK, w_crylink, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "crylink", "crylink", _("Crylink"));
3 #else
4 #ifdef SVQC
5 .float gravity;
6 .float crylink_waitrelease;
7 .entity crylink_lastgroup;
8
9 .entity queuenext;
10 .entity queueprev;
11
12 void W_Crylink_CheckLinks(entity e)
13 {
14         float i;
15         entity p;
16
17         if(e == world)
18                 error("W_Crylink_CheckLinks: entity is world");
19         if(e.classname != "spike" || wasfreed(e))
20                 error(sprintf("W_Crylink_CheckLinks: entity is not a spike but a %s (freed: %d)", e.classname, wasfreed(e)));
21
22         p = e;
23         for(i = 0; i < 1000; ++i)
24         {
25                 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
26                         error("W_Crylink_CheckLinks: queue is inconsistent");
27                 p = p.queuenext;
28                 if(p == e)
29                         break;
30         }
31         if(i >= 1000)
32                 error("W_Crylink_CheckLinks: infinite chain");
33 }
34
35 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
36 {
37         W_Crylink_CheckLinks(next);
38         if(me == own.crylink_lastgroup)
39                 own.crylink_lastgroup = ((me == next) ? world : next);
40         prev.queuenext = next;
41         next.queueprev = prev;
42         me.classname = "spike_oktoremove";
43         if(me != next)
44                 W_Crylink_CheckLinks(next);
45 }
46
47 void W_Crylink_Dequeue(entity e)
48 {
49         W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
50 }
51
52 void W_Crylink_Reset(void)
53 {
54         W_Crylink_Dequeue(self);
55         remove(self);
56 }
57
58 // force projectile to explode
59 void W_Crylink_LinkExplode (entity e, entity e2)
60 {
61         float a;
62
63         if(e == e2)
64                 return;
65
66         a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
67
68         if(e == e.realowner.crylink_lastgroup)
69                 e.realowner.crylink_lastgroup = world;
70
71         if(e.projectiledeathtype & HITTYPE_SECONDARY)
72                 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_damage * a, autocvar_g_balance_crylink_secondary_edgedamage * a, autocvar_g_balance_crylink_secondary_radius, world, autocvar_g_balance_crylink_secondary_force * a, e.projectiledeathtype, other);
73         else
74                 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_damage * a, autocvar_g_balance_crylink_primary_edgedamage * a, autocvar_g_balance_crylink_primary_radius, world, autocvar_g_balance_crylink_primary_force * a, e.projectiledeathtype, other);
75
76         W_Crylink_LinkExplode(e.queuenext, e2);
77
78         e.classname = "spike_oktoremove";
79         remove (e);
80 }
81
82 // adjust towards center
83 // returns the origin where they will meet... and the time till the meeting is
84 // stored in w_crylink_linkjoin_time.
85 // could possibly network this origin and time, and display a special particle
86 // effect when projectiles meet there :P
87 // jspeed: MINIMUM jing speed
88 // jtime: MAXIMUM jing time (0: none)
89 float w_crylink_linkjoin_time;
90 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
91 {
92         vector avg_origin, avg_velocity;
93         vector targ_origin;
94         float avg_dist, n;
95         entity p;
96
97         // FIXME remove this debug code
98         W_Crylink_CheckLinks(e);
99
100         w_crylink_linkjoin_time = 0;
101
102         avg_origin = e.origin;
103         avg_velocity = e.velocity;
104         n = 1;
105         for(p = e; (p = p.queuenext) != e; )
106         {
107                 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
108                 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
109                 ++n;
110         }
111         avg_origin *= (1.0 / n);
112         avg_velocity *= (1.0 / n);
113
114         if(n < 2)
115                 return avg_origin; // nothing to do
116
117         // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
118         avg_dist = pow(vlen(e.origin - avg_origin), 2);
119         for(p = e; (p = p.queuenext) != e; )
120                 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
121         avg_dist *= (1.0 / n);
122         avg_dist = sqrt(avg_dist);
123
124         if(avg_dist == 0)
125                 return avg_origin; // no change needed
126
127         if(jspeed == 0 && jtime == 0)
128         {
129                 e.velocity = avg_velocity;
130                 UpdateCSQCProjectile(e);
131                 for(p = e; (p = p.queuenext) != e; )
132                 {
133                         p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
134                         UpdateCSQCProjectile(p);
135                 }
136         }
137         else
138         {
139                 if(jtime)
140                 {
141                         if(jspeed)
142                                 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
143                         else
144                                 w_crylink_linkjoin_time = jtime;
145                 }
146                 else
147                         w_crylink_linkjoin_time = avg_dist / jspeed;
148                 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
149
150                 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
151                 UpdateCSQCProjectile(e);
152                 for(p = e; (p = p.queuenext) != e; )
153                 {
154                         p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
155                         UpdateCSQCProjectile(p);
156                 }
157
158                 // analysis:
159                 //   jspeed -> +infinity:
160                 //      w_crylink_linkjoin_time -> +0
161                 //      targ_origin -> avg_origin
162                 //      p->velocity -> HUEG towards center
163                 //   jspeed -> 0:
164                 //      w_crylink_linkjoin_time -> +/- infinity
165                 //      targ_origin -> avg_velocity * +/- infinity
166                 //      p->velocity -> avg_velocity
167                 //   jspeed -> -infinity:
168                 //      w_crylink_linkjoin_time -> -0
169                 //      targ_origin -> avg_origin
170                 //      p->velocity -> HUEG away from center
171         }
172
173         W_Crylink_CheckLinks(e);
174
175         return targ_origin;
176 }
177
178 void W_Crylink_LinkJoinEffect_Think()
179 {
180         // is there at least 2 projectiles very close?
181         entity e, p;
182         float n;
183         e = self.owner.crylink_lastgroup;
184         n = 0;
185         if(e)
186         {
187                 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
188                         ++n;
189                 for(p = e; (p = p.queuenext) != e; )
190                 {
191                         if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
192                                 ++n;
193                 }
194                 if(n >= 2)
195                 {
196                         if(e.projectiledeathtype & HITTYPE_SECONDARY)
197                         {
198                                 if(autocvar_g_balance_crylink_secondary_joinexplode)
199                                 {
200                                         n = n / autocvar_g_balance_crylink_secondary_shots;
201                                         RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
202                                                                         autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
203                                                                         autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
204                                                                         autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
205
206                                         pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
207                                 }
208                         }
209                         else
210                         {
211                                 if(autocvar_g_balance_crylink_primary_joinexplode)
212                                 {
213                                         n = n / autocvar_g_balance_crylink_primary_shots;
214                                         RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
215                                                                         autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
216                                                                         autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
217                                                                         autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
218
219                                         pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
220                                 }
221                         }
222                 }
223         }
224         remove(self);
225 }
226
227 // NO bounce protection, as bounces are limited!
228 void W_Crylink_Touch (void)
229 {
230         float finalhit;
231         float f;
232         PROJECTILE_TOUCH;
233
234         float a;
235         a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
236
237         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
238         if(finalhit)
239                 f = 1;
240         else
241                 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
242         if(a)
243                 f *= a;
244         if (RadiusDamage (self, self.realowner, autocvar_g_balance_crylink_primary_damage * f, autocvar_g_balance_crylink_primary_edgedamage * f, autocvar_g_balance_crylink_primary_radius, world, autocvar_g_balance_crylink_primary_force * f, self.projectiledeathtype, other) && autocvar_g_balance_crylink_primary_linkexplode)
245         {
246                 if(self == self.realowner.crylink_lastgroup)
247                         self.realowner.crylink_lastgroup = world;
248                 W_Crylink_LinkExplode(self.queuenext, self);
249                 self.classname = "spike_oktoremove";
250                 remove (self);
251                 return;
252         }
253         else if(finalhit)
254         {
255                 // just unlink
256                 W_Crylink_Dequeue(self);
257                 remove(self);
258                 return;
259         }
260         self.cnt = self.cnt - 1;
261         self.angles = vectoangles(self.velocity);
262         self.owner = world;
263         self.projectiledeathtype |= HITTYPE_BOUNCE;
264         // commented out as it causes a little hitch...
265         //if(proj.cnt == 0)
266         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
267 }
268
269 void W_Crylink_Touch2 (void)
270 {
271         float finalhit;
272         float f;
273         PROJECTILE_TOUCH;
274
275         float a;
276         a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
277
278         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
279         if(finalhit)
280                 f = 1;
281         else
282                 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
283         if(a)
284                 f *= a;
285         if (RadiusDamage (self, self.realowner, autocvar_g_balance_crylink_secondary_damage * f, autocvar_g_balance_crylink_secondary_edgedamage * f, autocvar_g_balance_crylink_secondary_radius, world, autocvar_g_balance_crylink_secondary_force * f, self.projectiledeathtype, other) && autocvar_g_balance_crylink_secondary_linkexplode)
286         {
287                 if(self == self.realowner.crylink_lastgroup)
288                         self.realowner.crylink_lastgroup = world;
289                 W_Crylink_LinkExplode(self.queuenext, self);
290                 self.classname = "spike_oktoremove";
291                 remove (self);
292                 return;
293         }
294         else if(finalhit)
295         {
296                 // just unlink
297                 W_Crylink_Dequeue(self);
298                 remove(self);
299                 return;
300         }
301         self.cnt = self.cnt - 1;
302         self.angles = vectoangles(self.velocity);
303         self.owner = world;
304         self.projectiledeathtype |= HITTYPE_BOUNCE;
305         // commented out as it causes a little hitch...
306         //if(proj.cnt == 0)
307         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
308 }
309
310 void W_Crylink_Fadethink (void)
311 {
312         W_Crylink_Dequeue(self);
313         remove(self);
314 }
315
316 void W_Crylink_Attack (void)
317 {
318         local float counter, shots;
319         local entity proj, prevproj, firstproj;
320         local vector s;
321         vector forward, right, up;
322         float maxdmg;
323
324         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_reload_ammo);
325
326         maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
327         maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
328         if(autocvar_g_balance_crylink_primary_joinexplode)
329                 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
330
331         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CH_WEAPON_A, maxdmg);
332         forward = v_forward;
333         right = v_right;
334         up = v_up;
335
336         shots = autocvar_g_balance_crylink_primary_shots;
337         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
338         proj = world;
339         while (counter < shots)
340         {
341                 proj = spawn ();
342                 proj.reset = W_Crylink_Reset;
343                 proj.realowner = proj.owner = self;
344                 proj.classname = "spike";
345                 proj.bot_dodge = TRUE;
346                 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
347                 if(shots == 1) {
348                         proj.queuenext = proj;
349                         proj.queueprev = proj;
350                 }
351                 else if(counter == 0) { // first projectile, store in firstproj for now
352                         firstproj = proj;
353                 }
354                 else if(counter == shots - 1) { // last projectile, link up with first projectile
355                         prevproj.queuenext = proj;
356                         firstproj.queueprev = proj;
357                         proj.queuenext = firstproj;
358                         proj.queueprev = prevproj;
359                 }
360                 else { // else link up with previous projectile
361                         prevproj.queuenext = proj;
362                         proj.queueprev = prevproj;
363                 }
364
365                 prevproj = proj;
366
367                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
368                 PROJECTILE_MAKETRIGGER(proj);
369                 proj.projectiledeathtype = WEP_CRYLINK;
370                 //proj.gravity = 0.001;
371
372                 setorigin (proj, w_shotorg);
373                 setsize(proj, '0 0 0', '0 0 0');
374
375
376                 s = '0 0 0';
377                 if (counter == 0)
378                         s = '0 0 0';
379                 else
380                 {
381                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
382                         s_y = v_forward_x;
383                         s_z = v_forward_y;
384                 }
385                 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
386                 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
387                 proj.touch = W_Crylink_Touch;
388
389                 proj.think = W_Crylink_Fadethink;
390                 if(counter == 0)
391                 {
392                         proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
393                         proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
394                         proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
395                 }
396                 else
397                 {
398                         proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
399                         proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
400                         proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
401                 }
402                 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
403                 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
404                 //proj.scale = 1 + 1 * proj.cnt;
405
406                 proj.angles = vectoangles (proj.velocity);
407
408                 //proj.glow_size = 20;
409
410                 proj.flags = FL_PROJECTILE;
411
412                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
413
414                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
415
416                 counter = counter + 1;
417         }
418         if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
419         {
420                 self.crylink_lastgroup = proj;
421                 W_Crylink_CheckLinks(proj);
422                 self.crylink_waitrelease = 1;
423         }
424 }
425
426 void W_Crylink_Attack2 (void)
427 {
428         local float counter, shots;
429         local entity proj, prevproj, firstproj;
430         float maxdmg;
431
432         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_crylink_secondary_ammo, autocvar_g_balance_crylink_reload_ammo);
433
434         maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
435         maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
436         if(autocvar_g_balance_crylink_secondary_joinexplode)
437                 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
438
439         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CH_WEAPON_A, maxdmg);
440
441         shots = autocvar_g_balance_crylink_secondary_shots;
442         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
443         proj = world;
444         while (counter < shots)
445         {
446                 proj = spawn ();
447                 proj.reset = W_Crylink_Reset;
448                 proj.realowner = proj.owner = self;
449                 proj.classname = "spike";
450                 proj.bot_dodge = TRUE;
451                 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
452                 if(shots == 1) {
453                         proj.queuenext = proj;
454                         proj.queueprev = proj;
455                 }
456                 else if(counter == 0) { // first projectile, store in firstproj for now
457                         firstproj = proj;
458                 }
459                 else if(counter == shots - 1) { // last projectile, link up with first projectile
460                         prevproj.queuenext = proj;
461                         firstproj.queueprev = proj;
462                         proj.queuenext = firstproj;
463                         proj.queueprev = prevproj;
464                 }
465                 else { // else link up with previous projectile
466                         prevproj.queuenext = proj;
467                         proj.queueprev = prevproj;
468                 }
469
470                 prevproj = proj;
471
472                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
473                 PROJECTILE_MAKETRIGGER(proj);
474                 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
475                 //proj.gravity = 0.001;
476
477                 setorigin (proj, w_shotorg);
478                 setsize(proj, '0 0 0', '0 0 0');
479
480                 W_SetupProjectileVelocityEx(proj, (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * autocvar_g_balance_crylink_secondary_spread * g_weaponspreadfactor), v_up, autocvar_g_balance_crylink_secondary_speed, 0, 0, 0, FALSE);
481                 proj.touch = W_Crylink_Touch2;
482                 proj.think = W_Crylink_Fadethink;
483                 if(counter == (shots - 1) / 2)
484                 {
485                         proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
486                         proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
487                         proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
488                 }
489                 else
490                 {
491                         proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
492                         proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
493                         proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
494                 }
495                 proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
496                 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
497                 //proj.scale = 1 + 1 * proj.cnt;
498
499                 proj.angles = vectoangles (proj.velocity);
500
501                 //proj.glow_size = 20;
502
503                 proj.flags = FL_PROJECTILE;
504
505                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
506
507                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
508
509                 counter = counter + 1;
510         }
511         if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
512         {
513                 self.crylink_lastgroup = proj;
514                 W_Crylink_CheckLinks(proj);
515                 self.crylink_waitrelease = 2;
516         }
517 }
518
519 void spawnfunc_weapon_crylink (void)
520 {
521         weapon_defaultspawnfunc(WEP_CRYLINK);
522 }
523
524 float w_crylink(float req)
525 {
526         float ammo_amount;
527         if (req == WR_AIM)
528         {
529                 if (random() < 0.10)
530                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
531                 else
532                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
533         }
534         else if (req == WR_THINK)
535         {
536                 if(autocvar_g_balance_crylink_reload_ammo && self.clip_load < min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo)) // forced reload
537                         weapon_action(self.weapon, WR_RELOAD);
538
539                 if (self.BUTTON_ATCK)
540                 {
541                         if (self.crylink_waitrelease != 1)
542                         if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
543                         {
544                                 W_Crylink_Attack();
545                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
546                         }
547                 }
548
549                 if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
550                 {
551                         if (self.crylink_waitrelease != 2)
552                         if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
553                         {
554                                 W_Crylink_Attack2();
555                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
556                         }
557                 }
558
559                 if ((self.crylink_waitrelease == 1 && !self.BUTTON_ATCK) || (self.crylink_waitrelease == 2 && !self.BUTTON_ATCK2))
560                 {
561                         if (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time)
562                         {
563                                 // fired and released now!
564                                 if(self.crylink_lastgroup)
565                                 {
566                                         vector pos;
567                                         entity linkjoineffect;
568
569                                         if(self.crylink_waitrelease == 1)
570                                         {
571                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, autocvar_g_balance_crylink_primary_joinspread * autocvar_g_balance_crylink_primary_speed, autocvar_g_balance_crylink_primary_jointime);
572
573                                         }
574                                         else
575                                         {
576                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, autocvar_g_balance_crylink_secondary_joinspread * autocvar_g_balance_crylink_secondary_speed, autocvar_g_balance_crylink_secondary_jointime);
577                                         }
578
579                                         linkjoineffect = spawn();
580                                         linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
581                                         linkjoineffect.classname = "linkjoineffect";
582                                         linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
583                                         linkjoineffect.owner = self;
584                                         setorigin(linkjoineffect, pos);
585                                 }
586                                 self.crylink_waitrelease = 0;
587                                 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
588                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
589                                 {
590                                         // ran out of ammo!
591                                         self.cnt = WEP_CRYLINK;
592                                         self.switchweapon = w_getbestweapon(self);
593                                 }
594                         }
595                 }
596         }
597         else if (req == WR_PRECACHE)
598         {
599                 precache_model ("models/weapons/g_crylink.md3");
600                 precache_model ("models/weapons/v_crylink.md3");
601                 precache_model ("models/weapons/h_crylink.iqm");
602                 precache_sound ("weapons/crylink_fire.wav");
603                 precache_sound ("weapons/crylink_fire2.wav");
604                 precache_sound ("weapons/crylink_linkjoin.wav");
605                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
606         }
607         else if (req == WR_SETUP)
608         {
609                 weapon_setup(WEP_CRYLINK);
610                 self.current_ammo = ammo_cells;
611         }
612         else if (req == WR_CHECKAMMO1)
613         {
614                 // don't "run out of ammo" and switch weapons while waiting for release
615                 if(self.crylink_lastgroup && self.crylink_waitrelease)
616                         return TRUE;
617
618                 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
619                 ammo_amount += self.(weapon_load[WEP_CRYLINK]) >= autocvar_g_balance_crylink_primary_ammo;
620                 return ammo_amount;
621         }
622         else if (req == WR_CHECKAMMO2)
623         {
624                 // don't "run out of ammo" and switch weapons while waiting for release
625                 if(self.crylink_lastgroup && self.crylink_waitrelease)
626                         return TRUE;
627
628                 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
629                 ammo_amount += self.(weapon_load[WEP_CRYLINK]) >= autocvar_g_balance_crylink_secondary_ammo;
630                 return ammo_amount;
631         }
632         else if (req == WR_RELOAD)
633         {
634                 W_Reload(min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo), autocvar_g_balance_crylink_reload_ammo, autocvar_g_balance_crylink_reload_time, "weapons/reload.wav");
635         }
636         return TRUE;
637 };
638 #endif
639 #ifdef CSQC
640 float w_crylink(float req)
641 {
642         if(req == WR_IMPACTEFFECT)
643         {
644                 vector org2;
645                 org2 = w_org + w_backoff * 2;
646                 if(w_deathtype & HITTYPE_SECONDARY)
647                 {
648                         pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
649                         if(!w_issilent)
650                                 sound(self, CH_SHOTS, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
651                 }
652                 else
653                 {
654                         pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
655                         if(!w_issilent)
656                                 sound(self, CH_SHOTS, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
657                 }
658         }
659         else if(req == WR_PRECACHE)
660         {
661                 precache_sound("weapons/crylink_impact2.wav");
662                 precache_sound("weapons/crylink_impact.wav");
663         }
664         else if (req == WR_SUICIDEMESSAGE)
665         {
666                 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
667         }
668         else if (req == WR_KILLMESSAGE)
669         {
670                 if(w_deathtype & HITTYPE_BOUNCE)
671                         w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
672                 else if(w_deathtype & HITTYPE_SPLASH)
673                         w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
674                 else
675                         w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY
676         }
677         return TRUE;
678 }
679 #endif
680 #endif