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