Weapons: remove useless weapon return values and implementations
[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, message, 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 void spawnfunc_weapon_crylink(void) { weapon_defaultspawnfunc(WEP_CRYLINK.m_id); }
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(void)
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(void)
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(void)
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(void)
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, 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 = spawn();
370                 proj.reset = W_Crylink_Reset;
371                 proj.realowner = proj.owner = self;
372                 proj.classname = "spike";
373                 proj.bot_dodge = true;
374                 proj.bot_dodgerating = WEP_CVAR_PRI(crylink, damage);
375                 if(shots == 1) {
376                         proj.queuenext = proj;
377                         proj.queueprev = proj;
378                 }
379                 else if(counter == 0) { // first projectile, store in firstproj for now
380                         firstproj = proj;
381                 }
382                 else if(counter == shots - 1) { // last projectile, link up with first projectile
383                         prevproj.queuenext = proj;
384                         firstproj.queueprev = proj;
385                         proj.queuenext = firstproj;
386                         proj.queueprev = prevproj;
387                 }
388                 else { // else link up with previous projectile
389                         prevproj.queuenext = proj;
390                         proj.queueprev = prevproj;
391                 }
392
393                 prevproj = proj;
394
395                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
396                 PROJECTILE_MAKETRIGGER(proj);
397                 proj.projectiledeathtype = WEP_CRYLINK.m_id;
398                 //proj.gravity = 0.001;
399
400                 setorigin(proj, w_shotorg);
401                 setsize(proj, '0 0 0', '0 0 0');
402
403
404                 s = '0 0 0';
405                 if(counter == 0)
406                         s = '0 0 0';
407                 else
408                 {
409                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
410                         s.y = v_forward.x;
411                         s.z = v_forward.y;
412                 }
413                 s = s * WEP_CVAR_PRI(crylink, spread) * g_weaponspreadfactor;
414                 W_SetupProjVelocity_Explicit(proj, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_PRI(crylink, speed), 0, 0, 0, false);
415                 proj.touch = W_Crylink_Touch;
416
417                 proj.think = W_Crylink_Fadethink;
418                 if(counter == 0)
419                 {
420                         proj.fade_time = time + WEP_CVAR_PRI(crylink, middle_lifetime);
421                         proj.fade_rate = 1 / WEP_CVAR_PRI(crylink, middle_fadetime);
422                         proj.nextthink = time + WEP_CVAR_PRI(crylink, middle_lifetime) + WEP_CVAR_PRI(crylink, middle_fadetime);
423                 }
424                 else
425                 {
426                         proj.fade_time = time + WEP_CVAR_PRI(crylink, other_lifetime);
427                         proj.fade_rate = 1 / WEP_CVAR_PRI(crylink, other_fadetime);
428                         proj.nextthink = time + WEP_CVAR_PRI(crylink, other_lifetime) + WEP_CVAR_PRI(crylink, other_fadetime);
429                 }
430                 proj.teleport_time = time + WEP_CVAR_PRI(crylink, joindelay);
431                 proj.cnt = WEP_CVAR_PRI(crylink, bounces);
432                 //proj.scale = 1 + 1 * proj.cnt;
433
434                 proj.angles = vectoangles(proj.velocity);
435
436                 //proj.glow_size = 20;
437
438                 proj.flags = FL_PROJECTILE;
439                 proj.missile_flags = MIF_SPLASH;
440
441                 CSQCProjectile(proj, true, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), true);
442
443                 MUTATOR_CALLHOOK(EditProjectile, self, proj);
444         }
445         if(WEP_CVAR_PRI(crylink, joinspread) != 0)
446         {
447                 self.crylink_lastgroup = proj;
448                 W_Crylink_CheckLinks(proj);
449                 self.crylink_waitrelease = 1;
450         }
451 }
452
453 void W_Crylink_Attack2(Weapon thiswep)
454 {SELFPARAM();
455         float counter, shots;
456         entity proj, prevproj, firstproj;
457         vector s;
458         vector forward, right, up;
459         float maxdmg;
460
461         W_DecreaseAmmo(thiswep, WEP_CVAR_SEC(crylink, ammo));
462
463         maxdmg = WEP_CVAR_SEC(crylink, damage) * WEP_CVAR_SEC(crylink, shots);
464         maxdmg *= 1 + WEP_CVAR_SEC(crylink, bouncedamagefactor) * WEP_CVAR_SEC(crylink, bounces);
465         if(WEP_CVAR_SEC(crylink, joinexplode))
466                 maxdmg += WEP_CVAR_SEC(crylink, joinexplode_damage);
467
468         W_SetupShot(self, false, 2, SND(CRYLINK_FIRE2), CH_WEAPON_A, maxdmg);
469         forward = v_forward;
470         right = v_right;
471         up = v_up;
472
473         shots = WEP_CVAR_SEC(crylink, shots);
474         Send_Effect(EFFECT_CRYLINK_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, shots);
475         proj = prevproj = firstproj = world;
476         for(counter = 0; counter < shots; ++counter)
477         {
478                 proj = spawn();
479                 proj.reset = W_Crylink_Reset;
480                 proj.realowner = proj.owner = self;
481                 proj.classname = "spike";
482                 proj.bot_dodge = true;
483                 proj.bot_dodgerating = WEP_CVAR_SEC(crylink, damage);
484                 if(shots == 1) {
485                         proj.queuenext = proj;
486                         proj.queueprev = proj;
487                 }
488                 else if(counter == 0) { // first projectile, store in firstproj for now
489                         firstproj = proj;
490                 }
491                 else if(counter == shots - 1) { // last projectile, link up with first projectile
492                         prevproj.queuenext = proj;
493                         firstproj.queueprev = proj;
494                         proj.queuenext = firstproj;
495                         proj.queueprev = prevproj;
496                 }
497                 else { // else link up with previous projectile
498                         prevproj.queuenext = proj;
499                         proj.queueprev = prevproj;
500                 }
501
502                 prevproj = proj;
503
504                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
505                 PROJECTILE_MAKETRIGGER(proj);
506                 proj.projectiledeathtype = WEP_CRYLINK.m_id | HITTYPE_SECONDARY;
507                 //proj.gravity = 0.001;
508
509                 setorigin(proj, w_shotorg);
510                 setsize(proj, '0 0 0', '0 0 0');
511
512                 if(WEP_CVAR_SEC(crylink, spreadtype) == 1)
513                 {
514                         s = '0 0 0';
515                         if(counter == 0)
516                                 s = '0 0 0';
517                         else
518                         {
519                                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
520                                 s.y = v_forward.x;
521                                 s.z = v_forward.y;
522                         }
523                         s = s * WEP_CVAR_SEC(crylink, spread) * g_weaponspreadfactor;
524                         s = w_shotdir + right * s.y + up * s.z;
525                 }
526                 else
527                 {
528                         s = (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * WEP_CVAR_SEC(crylink, spread) * g_weaponspreadfactor);
529                 }
530
531                 W_SetupProjVelocity_Explicit(proj, s, v_up, WEP_CVAR_SEC(crylink, speed), 0, 0, 0, false);
532                 proj.touch = W_Crylink_Touch;
533                 proj.think = W_Crylink_Fadethink;
534                 if(counter == (shots - 1) / 2)
535                 {
536                         proj.fade_time = time + WEP_CVAR_SEC(crylink, middle_lifetime);
537                         proj.fade_rate = 1 / WEP_CVAR_SEC(crylink, middle_fadetime);
538                         proj.nextthink = time + WEP_CVAR_SEC(crylink, middle_lifetime) + WEP_CVAR_SEC(crylink, middle_fadetime);
539                 }
540                 else
541                 {
542                         proj.fade_time = time + WEP_CVAR_SEC(crylink, other_lifetime);
543                         proj.fade_rate = 1 / WEP_CVAR_SEC(crylink, other_fadetime);
544                         proj.nextthink = time + WEP_CVAR_SEC(crylink, other_lifetime) + WEP_CVAR_SEC(crylink, other_fadetime);
545                 }
546                 proj.teleport_time = time + WEP_CVAR_SEC(crylink, joindelay);
547                 proj.cnt = WEP_CVAR_SEC(crylink, bounces);
548                 //proj.scale = 1 + 1 * proj.cnt;
549
550                 proj.angles = vectoangles(proj.velocity);
551
552                 //proj.glow_size = 20;
553
554                 proj.flags = FL_PROJECTILE;
555         proj.missile_flags = MIF_SPLASH;
556
557                 CSQCProjectile(proj, true, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), true);
558
559                 MUTATOR_CALLHOOK(EditProjectile, self, proj);
560         }
561         if(WEP_CVAR_SEC(crylink, joinspread) != 0)
562         {
563                 self.crylink_lastgroup = proj;
564                 W_Crylink_CheckLinks(proj);
565                 self.crylink_waitrelease = 2;
566         }
567 }
568
569                 METHOD(Crylink, wr_aim, void(entity thiswep))
570                 {
571                         SELFPARAM();
572                         if(random() < 0.10)
573                                 self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(crylink, speed), 0, WEP_CVAR_PRI(crylink, middle_lifetime), false);
574                         else
575                                 self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_SEC(crylink, speed), 0, WEP_CVAR_SEC(crylink, middle_lifetime), false);
576                 }
577                 METHOD(Crylink, wr_think, void(entity thiswep, bool fire1, bool fire2))
578                 {
579                         SELFPARAM();
580                         if(autocvar_g_balance_crylink_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(crylink, ammo), WEP_CVAR_SEC(crylink, ammo))) { // forced reload
581                                 Weapon w = get_weaponinfo(self.weapon);
582                                 w.wr_reload(w);
583                         }
584
585                         if(fire1)
586                         {
587                                 if(self.crylink_waitrelease != 1)
588                                 if(weapon_prepareattack(false, WEP_CVAR_PRI(crylink, refire)))
589                                 {
590                                         W_Crylink_Attack(thiswep);
591                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(crylink, animtime), w_ready);
592                                 }
593                         }
594
595                         if(fire2 && autocvar_g_balance_crylink_secondary)
596                         {
597                                 if(self.crylink_waitrelease != 2)
598                                 if(weapon_prepareattack(true, WEP_CVAR_SEC(crylink, refire)))
599                                 {
600                                         W_Crylink_Attack2(thiswep);
601                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(crylink, animtime), w_ready);
602                                 }
603                         }
604
605                         if((self.crylink_waitrelease == 1 && !fire1) || (self.crylink_waitrelease == 2 && !fire2))
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(!thiswep.wr_checkammo1(thiswep) && !thiswep.wr_checkammo2(thiswep))
627                                         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
628                                         {
629                                                 // ran out of ammo!
630                                                 self.cnt = WEP_CRYLINK.m_id;
631                                                 self.switchweapon = w_getbestweapon(self);
632                                         }
633                                 }
634                         }
635                 }
636                 METHOD(Crylink, wr_init, void(entity thiswep))
637                 {
638                         CRYLINK_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
639                 }
640                 METHOD(Crylink, wr_checkammo1, bool(entity thiswep))
641                 {
642                         SELFPARAM();
643                         // don't "run out of ammo" and switch weapons while waiting for release
644                         if(self.crylink_lastgroup && self.crylink_waitrelease)
645                                 return true;
646
647                         float ammo_amount = self.WEP_AMMO(CRYLINK) >= WEP_CVAR_PRI(crylink, ammo);
648                         ammo_amount += self.(weapon_load[WEP_CRYLINK.m_id]) >= WEP_CVAR_PRI(crylink, ammo);
649                         return ammo_amount;
650                 }
651                 METHOD(Crylink, wr_checkammo2, bool(entity thiswep))
652                 {
653                         SELFPARAM();
654                         // don't "run out of ammo" and switch weapons while waiting for release
655                         if(self.crylink_lastgroup && self.crylink_waitrelease)
656                                 return true;
657
658                         float ammo_amount = self.WEP_AMMO(CRYLINK) >= WEP_CVAR_SEC(crylink, ammo);
659                         ammo_amount += self.(weapon_load[WEP_CRYLINK.m_id]) >= WEP_CVAR_SEC(crylink, ammo);
660                         return ammo_amount;
661                 }
662                 METHOD(Crylink, wr_config, void(entity thiswep))
663                 {
664                         CRYLINK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
665                 }
666                 METHOD(Crylink, wr_reload, void(entity thiswep))
667                 {
668                         W_Reload(min(WEP_CVAR_PRI(crylink, ammo), WEP_CVAR_SEC(crylink, ammo)), SND(RELOAD));
669                 }
670                 METHOD(Crylink, wr_suicidemessage, int(entity thiswep))
671                 {
672                         return WEAPON_CRYLINK_SUICIDE;
673                 }
674                 METHOD(Crylink, wr_killmessage, int(entity thiswep))
675                 {
676                         return WEAPON_CRYLINK_MURDER;
677                 }
678 #endif
679 #ifdef CSQC
680                 METHOD(Crylink, wr_impacteffect, void(entity thiswep))
681                 {
682                         SELFPARAM();
683                         vector org2;
684                         org2 = w_org + w_backoff * 2;
685                         if(w_deathtype & HITTYPE_SECONDARY)
686                         {
687                                 pointparticles(particleeffectnum(EFFECT_CRYLINK_IMPACT2), org2, '0 0 0', 1);
688                                 if(!w_issilent)
689                                         sound(self, CH_SHOTS, SND_CRYLINK_IMPACT2, VOL_BASE, ATTN_NORM);
690                         }
691                         else
692                         {
693                                 pointparticles(particleeffectnum(EFFECT_CRYLINK_IMPACT), org2, '0 0 0', 1);
694                                 if(!w_issilent)
695                                         sound(self, CH_SHOTS, SND_CRYLINK_IMPACT, VOL_BASE, ATTN_NORM);
696                         }
697                 }
698 #endif
699 #endif