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