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