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