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