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