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