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