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