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