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